aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2016-08-22 04:34:13 -0400
committerThomas Gleixner <tglx@linutronix.de>2016-08-22 04:34:13 -0400
commitd16c995fe43021c765186bf8b9f7e1cc4b043232 (patch)
tree67eed481534bc6c7102110e65ab4c6ee9e0b786a
parentf3b0946d629c8bfbd3e5f038e30cb9c711a35f10 (diff)
parent7611da865c1060b2a7c87a15de663a59035747f8 (diff)
Merge tag 'irqchip-for-4.8-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms into irq/urgent
Pull genirq/irqchip fixes for 4.8-rc4 from Marc Zygnier - A critical fix for chained irqchip where we failed to configure the cascade interrupt trigger - A GIC fix for self-IPI in SMP-on-UP configurations - A PM fix for GICv3 - A initialization fix the the GICv3 ITS, triggered by kexec
-rw-r--r--Documentation/block/queue-sysfs.txt18
-rw-r--r--MAINTAINERS1
-rw-r--r--Makefile9
-rw-r--r--arch/arm/Makefile2
-rw-r--r--arch/arm/boot/dts/arm-realview-pbx-a9.dts9
-rw-r--r--arch/arm/boot/dts/integratorap.dts2
-rw-r--r--arch/arm/boot/dts/integratorcp.dts2
-rw-r--r--arch/arm/boot/dts/keystone.dtsi8
-rw-r--r--arch/arm/boot/dts/tegra124-jetson-tk1.dts4
-rw-r--r--arch/arm/configs/aspeed_g4_defconfig2
-rw-r--r--arch/arm/configs/aspeed_g5_defconfig2
-rw-r--r--arch/arm/kernel/sys_oabi-compat.c8
-rw-r--r--arch/arm/kvm/arm.c6
-rw-r--r--arch/arm/mach-clps711x/Kconfig2
-rw-r--r--arch/arm/mach-mvebu/Makefile3
-rw-r--r--arch/arm/mach-oxnas/Kconfig2
-rw-r--r--arch/arm/mach-pxa/corgi.c1
-rw-r--r--arch/arm/mach-pxa/spitz.c1
-rw-r--r--arch/arm/mach-realview/Makefile3
-rw-r--r--arch/arm/mach-s5pv210/Makefile2
-rw-r--r--arch/arm/mach-shmobile/platsmp.c3
-rw-r--r--arch/arm64/Kconfig.platforms4
-rw-r--r--arch/arm64/boot/dts/exynos/exynos7-espresso.dts3
-rw-r--r--arch/arm64/configs/defconfig53
-rw-r--r--arch/arm64/include/asm/kprobes.h2
-rw-r--r--arch/arm64/kernel/entry.S7
-rw-r--r--arch/arm64/kernel/hibernate.c82
-rw-r--r--arch/arm64/kernel/probes/kprobes.c31
-rw-r--r--arch/arm64/kernel/smp.c8
-rw-r--r--arch/arm64/mm/fault.c14
-rw-r--r--arch/h8300/include/asm/io.h2
-rw-r--r--arch/m68k/kernel/signal.c1
-rw-r--r--arch/metag/mm/init.c1
-rw-r--r--arch/mips/kvm/emulate.c35
-rw-r--r--arch/mips/kvm/mmu.c68
-rw-r--r--arch/powerpc/Makefile22
-rw-r--r--arch/powerpc/crypto/crc32c-vpmsum_glue.c3
-rw-r--r--arch/powerpc/include/asm/cpuidle.h13
-rw-r--r--arch/powerpc/include/asm/feature-fixups.h1
-rw-r--r--arch/powerpc/include/asm/switch_to.h8
-rw-r--r--arch/powerpc/include/asm/xics.h2
-rw-r--r--arch/powerpc/kernel/eeh.c4
-rw-r--r--arch/powerpc/kernel/exceptions-64s.S69
-rw-r--r--arch/powerpc/kernel/idle_book3s.S17
-rw-r--r--arch/powerpc/kernel/mce.c3
-rw-r--r--arch/powerpc/kernel/pci-common.c7
-rw-r--r--arch/powerpc/kernel/process.c20
-rw-r--r--arch/powerpc/kernel/prom_init.c2
-rw-r--r--arch/powerpc/kernel/ptrace.c19
-rw-r--r--arch/powerpc/kernel/setup_32.c9
-rw-r--r--arch/powerpc/kernel/setup_64.c1
-rw-r--r--arch/powerpc/kernel/vdso.c1
-rw-r--r--arch/powerpc/kernel/vdso32/Makefile6
-rw-r--r--arch/powerpc/kernel/vdso64/Makefile6
-rw-r--r--arch/powerpc/kvm/book3s_xics.c12
-rw-r--r--arch/powerpc/lib/checksum_32.S7
-rw-r--r--arch/powerpc/lib/feature-fixups.c3
-rw-r--r--arch/powerpc/platforms/cell/spufs/inode.c4
-rw-r--r--arch/powerpc/platforms/pasemi/iommu.c5
-rw-r--r--arch/powerpc/platforms/powernv/opal-irqchip.c3
-rw-r--r--arch/powerpc/platforms/powernv/opal.c1
-rw-r--r--arch/powerpc/platforms/powernv/pci-ioda.c32
-rw-r--r--arch/powerpc/platforms/pseries/hotplug-memory.c26
-rw-r--r--arch/powerpc/sysdev/xics/Kconfig1
-rw-r--r--arch/powerpc/sysdev/xics/ics-opal.c4
-rw-r--r--arch/powerpc/sysdev/xics/ics-rtas.c4
-rw-r--r--arch/powerpc/sysdev/xics/xics-common.c59
-rw-r--r--arch/s390/Kconfig13
-rw-r--r--arch/s390/kvm/kvm-s390.c5
-rw-r--r--arch/unicore32/include/asm/mmu_context.h2
-rw-r--r--arch/x86/entry/Makefile2
-rw-r--r--arch/x86/entry/entry_64.S25
-rw-r--r--arch/x86/events/intel/uncore_snb.c14
-rw-r--r--arch/x86/events/intel/uncore_snbep.c10
-rw-r--r--arch/x86/include/asm/apic.h2
-rw-r--r--arch/x86/include/asm/hardirq.h4
-rw-r--r--arch/x86/include/asm/init.h4
-rw-r--r--arch/x86/include/asm/pgtable_64.h4
-rw-r--r--arch/x86/include/asm/realmode.h10
-rw-r--r--arch/x86/include/asm/tlbflush.h7
-rw-r--r--arch/x86/include/asm/uv/bios.h5
-rw-r--r--arch/x86/kernel/apic/apic.c28
-rw-r--r--arch/x86/kernel/apic/x2apic_cluster.c13
-rw-r--r--arch/x86/kernel/apic/x2apic_uv_x.c42
-rw-r--r--arch/x86/kernel/fpu/xstate.c138
-rw-r--r--arch/x86/kernel/head32.c2
-rw-r--r--arch/x86/kernel/head64.c1
-rw-r--r--arch/x86/kernel/hpet.c2
-rw-r--r--arch/x86/kernel/irq.c3
-rw-r--r--arch/x86/kernel/setup.c27
-rw-r--r--arch/x86/kernel/tsc.c4
-rw-r--r--arch/x86/kernel/uprobes.c22
-rw-r--r--arch/x86/lib/kaslr.c2
-rw-r--r--arch/x86/mm/ident_map.c19
-rw-r--r--arch/x86/mm/init.c14
-rw-r--r--arch/x86/mm/kaslr.c2
-rw-r--r--arch/x86/platform/efi/quirks.c21
-rw-r--r--arch/x86/platform/uv/bios_uv.c11
-rw-r--r--arch/x86/power/hibernate_64.c2
-rw-r--r--arch/x86/realmode/init.c47
-rw-r--r--drivers/acpi/nfit/core.c3
-rw-r--r--drivers/block/rbd.c10
-rw-r--r--drivers/block/virtio_blk.c26
-rw-r--r--drivers/clocksource/arm_arch_timer.c26
-rw-r--r--drivers/cpufreq/powernv-cpufreq.c21
-rw-r--r--drivers/firmware/efi/capsule-loader.c8
-rw-r--r--drivers/firmware/efi/capsule.c6
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c7
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c4
-rw-r--r--drivers/gpu/drm/amd/amdgpu/ci_dpm.c1
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c12
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c1
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c8
-rw-r--r--drivers/gpu/drm/cirrus/cirrus_main.c13
-rw-r--r--drivers/gpu/drm/drm_crtc.c8
-rw-r--r--drivers/gpu/drm/drm_edid.c22
-rw-r--r--drivers/gpu/drm/i915/intel_display.c30
-rw-r--r--drivers/gpu/drm/i915/intel_fbdev.c25
-rw-r--r--drivers/gpu/drm/i915/intel_pm.c3
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bo.c4
-rw-r--r--drivers/gpu/drm/radeon/radeon_ttm.c4
-rw-r--r--drivers/gpu/drm/rcar-du/rcar_du_hdmienc.c1
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo.c3
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo_util.c10
-rw-r--r--drivers/irqchip/irq-gic-v3-its.c7
-rw-r--r--drivers/irqchip/irq-gic-v3.c11
-rw-r--r--drivers/irqchip/irq-gic.c7
-rw-r--r--drivers/misc/cxl/context.c3
-rw-r--r--drivers/misc/cxl/cxl.h2
-rw-r--r--drivers/misc/cxl/native.c2
-rw-r--r--drivers/misc/cxl/pci.c12
-rw-r--r--drivers/misc/cxl/vphb.c2
-rw-r--r--drivers/nvdimm/btt.c1
-rw-r--r--drivers/nvdimm/btt_devs.c20
-rw-r--r--drivers/nvdimm/nd.h1
-rw-r--r--drivers/nvme/host/pci.c20
-rw-r--r--drivers/nvme/host/rdma.c83
-rw-r--r--drivers/nvme/target/admin-cmd.c6
-rw-r--r--drivers/nvme/target/core.c4
-rw-r--r--drivers/nvme/target/loop.c4
-rw-r--r--drivers/nvme/target/nvmet.h1
-rw-r--r--drivers/nvme/target/rdma.c100
-rw-r--r--drivers/perf/arm_pmu.c25
-rw-r--r--drivers/platform/x86/dell-wmi.c4
-rw-r--r--drivers/rapidio/rio_cm.c24
-rw-r--r--drivers/s390/virtio/Makefile6
-rw-r--r--drivers/s390/virtio/kvm_virtio.c4
-rw-r--r--drivers/scsi/ipr.c11
-rw-r--r--drivers/thermal/clock_cooling.c1
-rw-r--r--drivers/thermal/fair_share.c2
-rw-r--r--drivers/thermal/gov_bang_bang.c2
-rw-r--r--drivers/thermal/intel_pch_thermal.c60
-rw-r--r--drivers/thermal/intel_powerclamp.c11
-rw-r--r--drivers/thermal/power_allocator.c2
-rw-r--r--drivers/thermal/step_wise.c2
-rw-r--r--drivers/thermal/thermal_core.c10
-rw-r--r--drivers/thermal/thermal_hwmon.c2
-rw-r--r--drivers/vfio/pci/vfio_pci_intrs.c85
-rw-r--r--drivers/vhost/vsock.c6
-rw-r--r--drivers/virtio/virtio_ring.c3
-rw-r--r--fs/btrfs/delayed-ref.c27
-rw-r--r--fs/btrfs/delayed-ref.h3
-rw-r--r--fs/btrfs/file.c8
-rw-r--r--fs/btrfs/inode.c46
-rw-r--r--fs/btrfs/send.c173
-rw-r--r--fs/btrfs/tree-log.c85
-rw-r--r--fs/ceph/caps.c5
-rw-r--r--fs/ceph/mds_client.c1
-rw-r--r--fs/fs-writeback.c6
-rw-r--r--fs/nfs/nfs42proc.c2
-rw-r--r--fs/nfs/nfs4_fs.h4
-rw-r--r--fs/nfs/nfs4proc.c9
-rw-r--r--fs/nfs/nfs4renewd.c20
-rw-r--r--fs/nfs/nfs4state.c9
-rw-r--r--fs/nfsd/nfs4state.c65
-rw-r--r--fs/nfsd/vfs.c9
-rw-r--r--fs/pipe.c4
-rw-r--r--fs/proc/meminfo.c2
-rw-r--r--include/asm-generic/qrwlock.h27
-rw-r--r--include/drm/ttm/ttm_bo_driver.h3
-rw-r--r--include/linux/bvec.h3
-rw-r--r--include/linux/kvm_host.h12
-rw-r--r--include/linux/perf_event.h4
-rw-r--r--include/linux/printk.h48
-rw-r--r--include/linux/sunrpc/clnt.h2
-rw-r--r--include/linux/sunrpc/xprt.h3
-rw-r--r--include/trace/events/timer.h14
-rw-r--r--include/uapi/linux/virtio_vsock.h2
-rw-r--r--include/uapi/misc/cxl.h4
-rw-r--r--kernel/events/core.c77
-rw-r--r--kernel/futex.c23
-rw-r--r--kernel/irq/chip.c11
-rw-r--r--kernel/locking/qspinlock_paravirt.h2
-rw-r--r--kernel/locking/qspinlock_stat.h1
-rw-r--r--kernel/power/hibernate.c4
-rw-r--r--kernel/printk/internal.h16
-rw-r--r--kernel/printk/nmi.c13
-rw-r--r--kernel/printk/printk.c25
-rw-r--r--kernel/sched/core.c19
-rw-r--r--kernel/sched/cpudeadline.c2
-rw-r--r--kernel/sched/cputime.c10
-rw-r--r--kernel/sched/deadline.c5
-rw-r--r--kernel/sched/fair.c2
-rw-r--r--kernel/time/timer.c5
-rw-r--r--mm/hugetlb.c1
-rw-r--r--mm/kasan/quarantine.c7
-rw-r--r--mm/memcontrol.c82
-rw-r--r--mm/memory_hotplug.c2
-rw-r--r--mm/oom_kill.c2
-rw-r--r--mm/page_alloc.c66
-rw-r--r--mm/rmap.c7
-rw-r--r--mm/shmem.c4
-rw-r--r--mm/slub.c6
-rw-r--r--net/9p/trans_virtio.c4
-rw-r--r--net/ceph/mon_client.c2
-rw-r--r--net/ceph/osd_client.c2
-rw-r--r--net/ceph/string_table.c8
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c8
-rw-r--r--net/sunrpc/clnt.c24
-rw-r--r--net/sunrpc/xprt.c26
-rw-r--r--net/sunrpc/xprtsock.c60
-rw-r--r--scripts/Kbuild.include10
-rw-r--r--scripts/Makefile.gcc-plugins39
-rwxr-xr-xscripts/gcc-plugin.sh14
-rw-r--r--scripts/gcc-plugins/Makefile12
-rwxr-xr-xscripts/get_maintainer.pl2
-rw-r--r--sound/pci/hda/hda_intel.c32
-rw-r--r--sound/usb/quirks.c2
-rw-r--r--tools/arch/x86/include/asm/cpufeatures.h9
-rw-r--r--tools/arch/x86/include/asm/disabled-features.h2
-rw-r--r--tools/arch/x86/include/asm/required-features.h2
-rw-r--r--tools/arch/x86/include/uapi/asm/vmx.h4
-rw-r--r--tools/include/uapi/linux/bpf.h86
-rw-r--r--tools/perf/Documentation/perf-probe.txt10
-rw-r--r--tools/perf/Documentation/perf-script.txt4
-rw-r--r--tools/perf/arch/powerpc/util/sym-handling.c27
-rw-r--r--tools/perf/builtin-script.c2
-rw-r--r--tools/perf/builtin-stat.c31
-rw-r--r--tools/perf/util/probe-event.c60
-rw-r--r--tools/perf/util/probe-event.h6
-rw-r--r--tools/perf/util/probe-finder.c15
-rw-r--r--tools/perf/util/sort.c6
-rw-r--r--tools/testing/nvdimm/test/nfit.c2
-rw-r--r--tools/testing/selftests/powerpc/Makefile2
-rw-r--r--virt/kvm/arm/vgic/vgic-init.c17
-rw-r--r--virt/kvm/kvm_main.c16
246 files changed, 2433 insertions, 1189 deletions
diff --git a/Documentation/block/queue-sysfs.txt b/Documentation/block/queue-sysfs.txt
index d515d58962b9..2a3904030dea 100644
--- a/Documentation/block/queue-sysfs.txt
+++ b/Documentation/block/queue-sysfs.txt
@@ -14,6 +14,12 @@ add_random (RW)
14This file allows to turn off the disk entropy contribution. Default 14This file allows to turn off the disk entropy contribution. Default
15value of this file is '1'(on). 15value of this file is '1'(on).
16 16
17dax (RO)
18--------
19This file indicates whether the device supports Direct Access (DAX),
20used by CPU-addressable storage to bypass the pagecache. It shows '1'
21if true, '0' if not.
22
17discard_granularity (RO) 23discard_granularity (RO)
18----------------------- 24-----------------------
19This shows the size of internal allocation of the device in bytes, if 25This shows the size of internal allocation of the device in bytes, if
@@ -46,6 +52,12 @@ hw_sector_size (RO)
46------------------- 52-------------------
47This is the hardware sector size of the device, in bytes. 53This is the hardware sector size of the device, in bytes.
48 54
55io_poll (RW)
56------------
57When read, this file shows the total number of block IO polls and how
58many returned success. Writing '0' to this file will disable polling
59for this device. Writing any non-zero value will enable this feature.
60
49iostats (RW) 61iostats (RW)
50------------- 62-------------
51This file is used to control (on/off) the iostats accounting of the 63This file is used to control (on/off) the iostats accounting of the
@@ -151,5 +163,11 @@ device state. This means that it might not be safe to toggle the
151setting from "write back" to "write through", since that will also 163setting from "write back" to "write through", since that will also
152eliminate cache flushes issued by the kernel. 164eliminate cache flushes issued by the kernel.
153 165
166write_same_max_bytes (RO)
167-------------------------
168This is the number of bytes the device can write in a single write-same
169command. A value of '0' means write-same is not supported by this
170device.
171
154 172
155Jens Axboe <jens.axboe@oracle.com>, February 2009 173Jens Axboe <jens.axboe@oracle.com>, February 2009
diff --git a/MAINTAINERS b/MAINTAINERS
index 20bb1d00098c..a306795a7450 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1004,6 +1004,7 @@ N: meson
1004ARM/Annapurna Labs ALPINE ARCHITECTURE 1004ARM/Annapurna Labs ALPINE ARCHITECTURE
1005M: Tsahee Zidenberg <tsahee@annapurnalabs.com> 1005M: Tsahee Zidenberg <tsahee@annapurnalabs.com>
1006M: Antoine Tenart <antoine.tenart@free-electrons.com> 1006M: Antoine Tenart <antoine.tenart@free-electrons.com>
1007L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1007S: Maintained 1008S: Maintained
1008F: arch/arm/mach-alpine/ 1009F: arch/arm/mach-alpine/
1009F: arch/arm/boot/dts/alpine* 1010F: arch/arm/boot/dts/alpine*
diff --git a/Makefile b/Makefile
index 70de1448c571..5c18baad7218 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 4 1VERSION = 4
2PATCHLEVEL = 8 2PATCHLEVEL = 8
3SUBLEVEL = 0 3SUBLEVEL = 0
4EXTRAVERSION = -rc1 4EXTRAVERSION = -rc2
5NAME = Psychotic Stoned Sheep 5NAME = Psychotic Stoned Sheep
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
@@ -635,13 +635,6 @@ endif
635# Tell gcc to never replace conditional load with a non-conditional one 635# Tell gcc to never replace conditional load with a non-conditional one
636KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) 636KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
637 637
638PHONY += gcc-plugins
639gcc-plugins: scripts_basic
640ifdef CONFIG_GCC_PLUGINS
641 $(Q)$(MAKE) $(build)=scripts/gcc-plugins
642endif
643 @:
644
645include scripts/Makefile.gcc-plugins 638include scripts/Makefile.gcc-plugins
646 639
647ifdef CONFIG_READABLE_ASM 640ifdef CONFIG_READABLE_ASM
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 56ea5c60b318..61f6ccc19cfa 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -260,12 +260,14 @@ machdirs := $(patsubst %,arch/arm/mach-%/,$(machine-y))
260platdirs := $(patsubst %,arch/arm/plat-%/,$(sort $(plat-y))) 260platdirs := $(patsubst %,arch/arm/plat-%/,$(sort $(plat-y)))
261 261
262ifneq ($(CONFIG_ARCH_MULTIPLATFORM),y) 262ifneq ($(CONFIG_ARCH_MULTIPLATFORM),y)
263ifneq ($(CONFIG_ARM_SINGLE_ARMV7M),y)
263ifeq ($(KBUILD_SRC),) 264ifeq ($(KBUILD_SRC),)
264KBUILD_CPPFLAGS += $(patsubst %,-I%include,$(machdirs) $(platdirs)) 265KBUILD_CPPFLAGS += $(patsubst %,-I%include,$(machdirs) $(platdirs))
265else 266else
266KBUILD_CPPFLAGS += $(patsubst %,-I$(srctree)/%include,$(machdirs) $(platdirs)) 267KBUILD_CPPFLAGS += $(patsubst %,-I$(srctree)/%include,$(machdirs) $(platdirs))
267endif 268endif
268endif 269endif
270endif
269 271
270export TEXT_OFFSET GZFLAGS MMUEXT 272export TEXT_OFFSET GZFLAGS MMUEXT
271 273
diff --git a/arch/arm/boot/dts/arm-realview-pbx-a9.dts b/arch/arm/boot/dts/arm-realview-pbx-a9.dts
index db808f92dd79..90d00b407f85 100644
--- a/arch/arm/boot/dts/arm-realview-pbx-a9.dts
+++ b/arch/arm/boot/dts/arm-realview-pbx-a9.dts
@@ -70,13 +70,12 @@
70 * associativity as these may be erroneously set 70 * associativity as these may be erroneously set
71 * up by boot loader(s). 71 * up by boot loader(s).
72 */ 72 */
73 cache-size = <1048576>; // 1MB 73 cache-size = <131072>; // 128KB
74 cache-sets = <4096>; 74 cache-sets = <512>;
75 cache-line-size = <32>; 75 cache-line-size = <32>;
76 arm,parity-disable; 76 arm,parity-disable;
77 arm,tag-latency = <1>; 77 arm,tag-latency = <1 1 1>;
78 arm,data-latency = <1 1>; 78 arm,data-latency = <1 1 1>;
79 arm,dirty-latency = <1>;
80 }; 79 };
81 80
82 scu: scu@1f000000 { 81 scu: scu@1f000000 {
diff --git a/arch/arm/boot/dts/integratorap.dts b/arch/arm/boot/dts/integratorap.dts
index cf06e32ee108..4b34b54e09a1 100644
--- a/arch/arm/boot/dts/integratorap.dts
+++ b/arch/arm/boot/dts/integratorap.dts
@@ -42,7 +42,7 @@
42 }; 42 };
43 43
44 syscon { 44 syscon {
45 compatible = "arm,integrator-ap-syscon"; 45 compatible = "arm,integrator-ap-syscon", "syscon";
46 reg = <0x11000000 0x100>; 46 reg = <0x11000000 0x100>;
47 interrupt-parent = <&pic>; 47 interrupt-parent = <&pic>;
48 /* These are the logical module IRQs */ 48 /* These are the logical module IRQs */
diff --git a/arch/arm/boot/dts/integratorcp.dts b/arch/arm/boot/dts/integratorcp.dts
index d43f15b4f79a..79430fbfec3b 100644
--- a/arch/arm/boot/dts/integratorcp.dts
+++ b/arch/arm/boot/dts/integratorcp.dts
@@ -94,7 +94,7 @@
94 }; 94 };
95 95
96 syscon { 96 syscon {
97 compatible = "arm,integrator-cp-syscon"; 97 compatible = "arm,integrator-cp-syscon", "syscon";
98 reg = <0xcb000000 0x100>; 98 reg = <0xcb000000 0x100>;
99 }; 99 };
100 100
diff --git a/arch/arm/boot/dts/keystone.dtsi b/arch/arm/boot/dts/keystone.dtsi
index 00cb314d5e4d..e23f46d15c80 100644
--- a/arch/arm/boot/dts/keystone.dtsi
+++ b/arch/arm/boot/dts/keystone.dtsi
@@ -70,14 +70,6 @@
70 cpu_on = <0x84000003>; 70 cpu_on = <0x84000003>;
71 }; 71 };
72 72
73 psci {
74 compatible = "arm,psci";
75 method = "smc";
76 cpu_suspend = <0x84000001>;
77 cpu_off = <0x84000002>;
78 cpu_on = <0x84000003>;
79 };
80
81 soc { 73 soc {
82 #address-cells = <1>; 74 #address-cells = <1>;
83 #size-cells = <1>; 75 #size-cells = <1>;
diff --git a/arch/arm/boot/dts/tegra124-jetson-tk1.dts b/arch/arm/boot/dts/tegra124-jetson-tk1.dts
index e52b82449a79..6403e0de540e 100644
--- a/arch/arm/boot/dts/tegra124-jetson-tk1.dts
+++ b/arch/arm/boot/dts/tegra124-jetson-tk1.dts
@@ -1382,7 +1382,7 @@
1382 * Pin 41: BR_UART1_TXD 1382 * Pin 41: BR_UART1_TXD
1383 * Pin 44: BR_UART1_RXD 1383 * Pin 44: BR_UART1_RXD
1384 */ 1384 */
1385 serial@70006000 { 1385 serial@0,70006000 {
1386 compatible = "nvidia,tegra124-hsuart", "nvidia,tegra30-hsuart"; 1386 compatible = "nvidia,tegra124-hsuart", "nvidia,tegra30-hsuart";
1387 status = "okay"; 1387 status = "okay";
1388 }; 1388 };
@@ -1394,7 +1394,7 @@
1394 * Pin 71: UART2_CTS_L 1394 * Pin 71: UART2_CTS_L
1395 * Pin 74: UART2_RTS_L 1395 * Pin 74: UART2_RTS_L
1396 */ 1396 */
1397 serial@70006040 { 1397 serial@0,70006040 {
1398 compatible = "nvidia,tegra124-hsuart", "nvidia,tegra30-hsuart"; 1398 compatible = "nvidia,tegra124-hsuart", "nvidia,tegra30-hsuart";
1399 status = "okay"; 1399 status = "okay";
1400 }; 1400 };
diff --git a/arch/arm/configs/aspeed_g4_defconfig b/arch/arm/configs/aspeed_g4_defconfig
index b6e54ee9bdbd..ca39c04fec6b 100644
--- a/arch/arm/configs/aspeed_g4_defconfig
+++ b/arch/arm/configs/aspeed_g4_defconfig
@@ -58,7 +58,7 @@ CONFIG_SERIAL_OF_PLATFORM=y
58# CONFIG_IOMMU_SUPPORT is not set 58# CONFIG_IOMMU_SUPPORT is not set
59CONFIG_FIRMWARE_MEMMAP=y 59CONFIG_FIRMWARE_MEMMAP=y
60CONFIG_FANOTIFY=y 60CONFIG_FANOTIFY=y
61CONFIG_PRINTK_TIME=1 61CONFIG_PRINTK_TIME=y
62CONFIG_DYNAMIC_DEBUG=y 62CONFIG_DYNAMIC_DEBUG=y
63CONFIG_STRIP_ASM_SYMS=y 63CONFIG_STRIP_ASM_SYMS=y
64CONFIG_PAGE_POISONING=y 64CONFIG_PAGE_POISONING=y
diff --git a/arch/arm/configs/aspeed_g5_defconfig b/arch/arm/configs/aspeed_g5_defconfig
index 892605167357..4f366b0370e9 100644
--- a/arch/arm/configs/aspeed_g5_defconfig
+++ b/arch/arm/configs/aspeed_g5_defconfig
@@ -59,7 +59,7 @@ CONFIG_SERIAL_OF_PLATFORM=y
59# CONFIG_IOMMU_SUPPORT is not set 59# CONFIG_IOMMU_SUPPORT is not set
60CONFIG_FIRMWARE_MEMMAP=y 60CONFIG_FIRMWARE_MEMMAP=y
61CONFIG_FANOTIFY=y 61CONFIG_FANOTIFY=y
62CONFIG_PRINTK_TIME=1 62CONFIG_PRINTK_TIME=y
63CONFIG_DYNAMIC_DEBUG=y 63CONFIG_DYNAMIC_DEBUG=y
64CONFIG_STRIP_ASM_SYMS=y 64CONFIG_STRIP_ASM_SYMS=y
65CONFIG_PAGE_POISONING=y 65CONFIG_PAGE_POISONING=y
diff --git a/arch/arm/kernel/sys_oabi-compat.c b/arch/arm/kernel/sys_oabi-compat.c
index 087acb569b63..5f221acd21ae 100644
--- a/arch/arm/kernel/sys_oabi-compat.c
+++ b/arch/arm/kernel/sys_oabi-compat.c
@@ -279,8 +279,12 @@ asmlinkage long sys_oabi_epoll_wait(int epfd,
279 mm_segment_t fs; 279 mm_segment_t fs;
280 long ret, err, i; 280 long ret, err, i;
281 281
282 if (maxevents <= 0 || maxevents > (INT_MAX/sizeof(struct epoll_event))) 282 if (maxevents <= 0 ||
283 maxevents > (INT_MAX/sizeof(*kbuf)) ||
284 maxevents > (INT_MAX/sizeof(*events)))
283 return -EINVAL; 285 return -EINVAL;
286 if (!access_ok(VERIFY_WRITE, events, sizeof(*events) * maxevents))
287 return -EFAULT;
284 kbuf = kmalloc(sizeof(*kbuf) * maxevents, GFP_KERNEL); 288 kbuf = kmalloc(sizeof(*kbuf) * maxevents, GFP_KERNEL);
285 if (!kbuf) 289 if (!kbuf)
286 return -ENOMEM; 290 return -ENOMEM;
@@ -317,6 +321,8 @@ asmlinkage long sys_oabi_semtimedop(int semid,
317 321
318 if (nsops < 1 || nsops > SEMOPM) 322 if (nsops < 1 || nsops > SEMOPM)
319 return -EINVAL; 323 return -EINVAL;
324 if (!access_ok(VERIFY_READ, tsops, sizeof(*tsops) * nsops))
325 return -EFAULT;
320 sops = kmalloc(sizeof(*sops) * nsops, GFP_KERNEL); 326 sops = kmalloc(sizeof(*sops) * nsops, GFP_KERNEL);
321 if (!sops) 327 if (!sops)
322 return -ENOMEM; 328 return -ENOMEM;
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index d94bb9093ead..75f130ef6504 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -1009,9 +1009,13 @@ long kvm_arch_vm_ioctl(struct file *filp,
1009 1009
1010 switch (ioctl) { 1010 switch (ioctl) {
1011 case KVM_CREATE_IRQCHIP: { 1011 case KVM_CREATE_IRQCHIP: {
1012 int ret;
1012 if (!vgic_present) 1013 if (!vgic_present)
1013 return -ENXIO; 1014 return -ENXIO;
1014 return kvm_vgic_create(kvm, KVM_DEV_TYPE_ARM_VGIC_V2); 1015 mutex_lock(&kvm->lock);
1016 ret = kvm_vgic_create(kvm, KVM_DEV_TYPE_ARM_VGIC_V2);
1017 mutex_unlock(&kvm->lock);
1018 return ret;
1015 } 1019 }
1016 case KVM_ARM_SET_DEVICE_ADDR: { 1020 case KVM_ARM_SET_DEVICE_ADDR: {
1017 struct kvm_arm_device_addr dev_addr; 1021 struct kvm_arm_device_addr dev_addr;
diff --git a/arch/arm/mach-clps711x/Kconfig b/arch/arm/mach-clps711x/Kconfig
index dc7c6edeab39..61284b9389cf 100644
--- a/arch/arm/mach-clps711x/Kconfig
+++ b/arch/arm/mach-clps711x/Kconfig
@@ -1,13 +1,13 @@
1menuconfig ARCH_CLPS711X 1menuconfig ARCH_CLPS711X
2 bool "Cirrus Logic EP721x/EP731x-based" 2 bool "Cirrus Logic EP721x/EP731x-based"
3 depends on ARCH_MULTI_V4T 3 depends on ARCH_MULTI_V4T
4 select ARCH_REQUIRE_GPIOLIB
5 select AUTO_ZRELADDR 4 select AUTO_ZRELADDR
6 select CLKSRC_OF 5 select CLKSRC_OF
7 select CLPS711X_TIMER 6 select CLPS711X_TIMER
8 select COMMON_CLK 7 select COMMON_CLK
9 select CPU_ARM720T 8 select CPU_ARM720T
10 select GENERIC_CLOCKEVENTS 9 select GENERIC_CLOCKEVENTS
10 select GPIOLIB
11 select MFD_SYSCON 11 select MFD_SYSCON
12 select OF_IRQ 12 select OF_IRQ
13 select USE_OF 13 select USE_OF
diff --git a/arch/arm/mach-mvebu/Makefile b/arch/arm/mach-mvebu/Makefile
index e53c6cfcab51..6c6497e80a7b 100644
--- a/arch/arm/mach-mvebu/Makefile
+++ b/arch/arm/mach-mvebu/Makefile
@@ -1,5 +1,4 @@
1ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/$(src)/include \ 1ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/arch/arm/plat-orion/include
2 -I$(srctree)/arch/arm/plat-orion/include
3 2
4AFLAGS_coherency_ll.o := -Wa,-march=armv7-a 3AFLAGS_coherency_ll.o := -Wa,-march=armv7-a
5CFLAGS_pmsu.o := -march=armv7-a 4CFLAGS_pmsu.o := -march=armv7-a
diff --git a/arch/arm/mach-oxnas/Kconfig b/arch/arm/mach-oxnas/Kconfig
index 567496bd250a..29100beb2e7f 100644
--- a/arch/arm/mach-oxnas/Kconfig
+++ b/arch/arm/mach-oxnas/Kconfig
@@ -11,11 +11,13 @@ if ARCH_OXNAS
11 11
12config MACH_OX810SE 12config MACH_OX810SE
13 bool "Support OX810SE Based Products" 13 bool "Support OX810SE Based Products"
14 select ARCH_HAS_RESET_CONTROLLER
14 select COMMON_CLK_OXNAS 15 select COMMON_CLK_OXNAS
15 select CPU_ARM926T 16 select CPU_ARM926T
16 select MFD_SYSCON 17 select MFD_SYSCON
17 select OXNAS_RPS_TIMER 18 select OXNAS_RPS_TIMER
18 select PINCTRL_OXNAS 19 select PINCTRL_OXNAS
20 select RESET_CONTROLLER
19 select RESET_OXNAS 21 select RESET_OXNAS
20 select VERSATILE_FPGA_IRQ 22 select VERSATILE_FPGA_IRQ
21 help 23 help
diff --git a/arch/arm/mach-pxa/corgi.c b/arch/arm/mach-pxa/corgi.c
index dc109dc3a622..10bfdb169366 100644
--- a/arch/arm/mach-pxa/corgi.c
+++ b/arch/arm/mach-pxa/corgi.c
@@ -13,6 +13,7 @@
13 */ 13 */
14 14
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/module.h> /* symbol_get ; symbol_put */
16#include <linux/init.h> 17#include <linux/init.h>
17#include <linux/platform_device.h> 18#include <linux/platform_device.h>
18#include <linux/major.h> 19#include <linux/major.h>
diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c
index 1080580b1343..2c150bfc0cd5 100644
--- a/arch/arm/mach-pxa/spitz.c
+++ b/arch/arm/mach-pxa/spitz.c
@@ -13,6 +13,7 @@
13 */ 13 */
14 14
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/module.h> /* symbol_get ; symbol_put */
16#include <linux/platform_device.h> 17#include <linux/platform_device.h>
17#include <linux/delay.h> 18#include <linux/delay.h>
18#include <linux/gpio_keys.h> 19#include <linux/gpio_keys.h>
diff --git a/arch/arm/mach-realview/Makefile b/arch/arm/mach-realview/Makefile
index dae8d86ef4cc..404882130956 100644
--- a/arch/arm/mach-realview/Makefile
+++ b/arch/arm/mach-realview/Makefile
@@ -1,8 +1,7 @@
1# 1#
2# Makefile for the linux kernel. 2# Makefile for the linux kernel.
3# 3#
4ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/$(src)/include \ 4ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/arch/arm/plat-versatile/include
5 -I$(srctree)/arch/arm/plat-versatile/include
6 5
7obj-y := core.o 6obj-y := core.o
8obj-$(CONFIG_REALVIEW_DT) += realview-dt.o 7obj-$(CONFIG_REALVIEW_DT) += realview-dt.o
diff --git a/arch/arm/mach-s5pv210/Makefile b/arch/arm/mach-s5pv210/Makefile
index 72b9e9671507..fa7fb716e388 100644
--- a/arch/arm/mach-s5pv210/Makefile
+++ b/arch/arm/mach-s5pv210/Makefile
@@ -5,7 +5,7 @@
5# 5#
6# Licensed under GPLv2 6# Licensed under GPLv2
7 7
8ccflags-$(CONFIG_ARCH_MULTIPLATFORM) += -I$(srctree)/$(src)/include -I$(srctree)/arch/arm/plat-samsung/include 8ccflags-$(CONFIG_ARCH_MULTIPLATFORM) += -I$(srctree)/arch/arm/plat-samsung/include
9 9
10# Core 10# Core
11 11
diff --git a/arch/arm/mach-shmobile/platsmp.c b/arch/arm/mach-shmobile/platsmp.c
index f3dba6f356e2..02e21bceb085 100644
--- a/arch/arm/mach-shmobile/platsmp.c
+++ b/arch/arm/mach-shmobile/platsmp.c
@@ -40,5 +40,8 @@ bool shmobile_smp_cpu_can_disable(unsigned int cpu)
40bool __init shmobile_smp_init_fallback_ops(void) 40bool __init shmobile_smp_init_fallback_ops(void)
41{ 41{
42 /* fallback on PSCI/smp_ops if no other DT based method is detected */ 42 /* fallback on PSCI/smp_ops if no other DT based method is detected */
43 if (!IS_ENABLED(CONFIG_SMP))
44 return false;
45
43 return platform_can_secondary_boot() ? true : false; 46 return platform_can_secondary_boot() ? true : false;
44} 47}
diff --git a/arch/arm64/Kconfig.platforms b/arch/arm64/Kconfig.platforms
index bb2616b16157..be5d824ebdba 100644
--- a/arch/arm64/Kconfig.platforms
+++ b/arch/arm64/Kconfig.platforms
@@ -8,7 +8,7 @@ config ARCH_SUNXI
8 8
9config ARCH_ALPINE 9config ARCH_ALPINE
10 bool "Annapurna Labs Alpine platform" 10 bool "Annapurna Labs Alpine platform"
11 select ALPINE_MSI 11 select ALPINE_MSI if PCI
12 help 12 help
13 This enables support for the Annapurna Labs Alpine 13 This enables support for the Annapurna Labs Alpine
14 Soc family. 14 Soc family.
@@ -66,7 +66,7 @@ config ARCH_LG1K
66config ARCH_HISI 66config ARCH_HISI
67 bool "Hisilicon SoC Family" 67 bool "Hisilicon SoC Family"
68 select ARM_TIMER_SP804 68 select ARM_TIMER_SP804
69 select HISILICON_IRQ_MBIGEN 69 select HISILICON_IRQ_MBIGEN if PCI
70 help 70 help
71 This enables support for Hisilicon ARMv8 SoC family 71 This enables support for Hisilicon ARMv8 SoC family
72 72
diff --git a/arch/arm64/boot/dts/exynos/exynos7-espresso.dts b/arch/arm64/boot/dts/exynos/exynos7-espresso.dts
index 299f3ce969ab..c528dd52ba2d 100644
--- a/arch/arm64/boot/dts/exynos/exynos7-espresso.dts
+++ b/arch/arm64/boot/dts/exynos/exynos7-espresso.dts
@@ -12,6 +12,7 @@
12/dts-v1/; 12/dts-v1/;
13#include "exynos7.dtsi" 13#include "exynos7.dtsi"
14#include <dt-bindings/interrupt-controller/irq.h> 14#include <dt-bindings/interrupt-controller/irq.h>
15#include <dt-bindings/clock/samsung,s2mps11.h>
15 16
16/ { 17/ {
17 model = "Samsung Exynos7 Espresso board based on EXYNOS7"; 18 model = "Samsung Exynos7 Espresso board based on EXYNOS7";
@@ -43,6 +44,8 @@
43 44
44&rtc { 45&rtc {
45 status = "okay"; 46 status = "okay";
47 clocks = <&clock_ccore PCLK_RTC>, <&s2mps15_osc S2MPS11_CLK_AP>;
48 clock-names = "rtc", "rtc_src";
46}; 49};
47 50
48&watchdog { 51&watchdog {
diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
index 0555b7caaf2c..eadf4855ad2d 100644
--- a/arch/arm64/configs/defconfig
+++ b/arch/arm64/configs/defconfig
@@ -1,4 +1,3 @@
1# CONFIG_LOCALVERSION_AUTO is not set
2CONFIG_SYSVIPC=y 1CONFIG_SYSVIPC=y
3CONFIG_POSIX_MQUEUE=y 2CONFIG_POSIX_MQUEUE=y
4CONFIG_AUDIT=y 3CONFIG_AUDIT=y
@@ -15,10 +14,14 @@ CONFIG_IKCONFIG_PROC=y
15CONFIG_LOG_BUF_SHIFT=14 14CONFIG_LOG_BUF_SHIFT=14
16CONFIG_MEMCG=y 15CONFIG_MEMCG=y
17CONFIG_MEMCG_SWAP=y 16CONFIG_MEMCG_SWAP=y
17CONFIG_BLK_CGROUP=y
18CONFIG_CGROUP_PIDS=y
18CONFIG_CGROUP_HUGETLB=y 19CONFIG_CGROUP_HUGETLB=y
19# CONFIG_UTS_NS is not set 20CONFIG_CPUSETS=y
20# CONFIG_IPC_NS is not set 21CONFIG_CGROUP_DEVICE=y
21# CONFIG_NET_NS is not set 22CONFIG_CGROUP_CPUACCT=y
23CONFIG_CGROUP_PERF=y
24CONFIG_USER_NS=y
22CONFIG_SCHED_AUTOGROUP=y 25CONFIG_SCHED_AUTOGROUP=y
23CONFIG_BLK_DEV_INITRD=y 26CONFIG_BLK_DEV_INITRD=y
24CONFIG_KALLSYMS_ALL=y 27CONFIG_KALLSYMS_ALL=y
@@ -71,6 +74,7 @@ CONFIG_PREEMPT=y
71CONFIG_KSM=y 74CONFIG_KSM=y
72CONFIG_TRANSPARENT_HUGEPAGE=y 75CONFIG_TRANSPARENT_HUGEPAGE=y
73CONFIG_CMA=y 76CONFIG_CMA=y
77CONFIG_SECCOMP=y
74CONFIG_XEN=y 78CONFIG_XEN=y
75CONFIG_KEXEC=y 79CONFIG_KEXEC=y
76# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set 80# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
@@ -84,10 +88,37 @@ CONFIG_NET=y
84CONFIG_PACKET=y 88CONFIG_PACKET=y
85CONFIG_UNIX=y 89CONFIG_UNIX=y
86CONFIG_INET=y 90CONFIG_INET=y
91CONFIG_IP_MULTICAST=y
87CONFIG_IP_PNP=y 92CONFIG_IP_PNP=y
88CONFIG_IP_PNP_DHCP=y 93CONFIG_IP_PNP_DHCP=y
89CONFIG_IP_PNP_BOOTP=y 94CONFIG_IP_PNP_BOOTP=y
90# CONFIG_IPV6 is not set 95CONFIG_IPV6=m
96CONFIG_NETFILTER=y
97CONFIG_NF_CONNTRACK=m
98CONFIG_NF_CONNTRACK_EVENTS=y
99CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
100CONFIG_NETFILTER_XT_TARGET_LOG=m
101CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=m
102CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
103CONFIG_NF_CONNTRACK_IPV4=m
104CONFIG_IP_NF_IPTABLES=m
105CONFIG_IP_NF_FILTER=m
106CONFIG_IP_NF_TARGET_REJECT=m
107CONFIG_IP_NF_NAT=m
108CONFIG_IP_NF_TARGET_MASQUERADE=m
109CONFIG_IP_NF_MANGLE=m
110CONFIG_NF_CONNTRACK_IPV6=m
111CONFIG_IP6_NF_IPTABLES=m
112CONFIG_IP6_NF_FILTER=m
113CONFIG_IP6_NF_TARGET_REJECT=m
114CONFIG_IP6_NF_MANGLE=m
115CONFIG_IP6_NF_NAT=m
116CONFIG_IP6_NF_TARGET_MASQUERADE=m
117CONFIG_BRIDGE=m
118CONFIG_BRIDGE_VLAN_FILTERING=y
119CONFIG_VLAN_8021Q=m
120CONFIG_VLAN_8021Q_GVRP=y
121CONFIG_VLAN_8021Q_MVRP=y
91CONFIG_BPF_JIT=y 122CONFIG_BPF_JIT=y
92CONFIG_CFG80211=m 123CONFIG_CFG80211=m
93CONFIG_MAC80211=m 124CONFIG_MAC80211=m
@@ -103,6 +134,7 @@ CONFIG_MTD=y
103CONFIG_MTD_M25P80=y 134CONFIG_MTD_M25P80=y
104CONFIG_MTD_SPI_NOR=y 135CONFIG_MTD_SPI_NOR=y
105CONFIG_BLK_DEV_LOOP=y 136CONFIG_BLK_DEV_LOOP=y
137CONFIG_BLK_DEV_NBD=m
106CONFIG_VIRTIO_BLK=y 138CONFIG_VIRTIO_BLK=y
107CONFIG_SRAM=y 139CONFIG_SRAM=y
108# CONFIG_SCSI_PROC_FS is not set 140# CONFIG_SCSI_PROC_FS is not set
@@ -120,7 +152,10 @@ CONFIG_SATA_SIL24=y
120CONFIG_PATA_PLATFORM=y 152CONFIG_PATA_PLATFORM=y
121CONFIG_PATA_OF_PLATFORM=y 153CONFIG_PATA_OF_PLATFORM=y
122CONFIG_NETDEVICES=y 154CONFIG_NETDEVICES=y
155CONFIG_MACVLAN=m
156CONFIG_MACVTAP=m
123CONFIG_TUN=y 157CONFIG_TUN=y
158CONFIG_VETH=m
124CONFIG_VIRTIO_NET=y 159CONFIG_VIRTIO_NET=y
125CONFIG_AMD_XGBE=y 160CONFIG_AMD_XGBE=y
126CONFIG_NET_XGENE=y 161CONFIG_NET_XGENE=y
@@ -350,12 +385,16 @@ CONFIG_EXYNOS_ADC=y
350CONFIG_PWM_SAMSUNG=y 385CONFIG_PWM_SAMSUNG=y
351CONFIG_EXT2_FS=y 386CONFIG_EXT2_FS=y
352CONFIG_EXT3_FS=y 387CONFIG_EXT3_FS=y
388CONFIG_EXT4_FS_POSIX_ACL=y
389CONFIG_BTRFS_FS=m
390CONFIG_BTRFS_FS_POSIX_ACL=y
353CONFIG_FANOTIFY=y 391CONFIG_FANOTIFY=y
354CONFIG_FANOTIFY_ACCESS_PERMISSIONS=y 392CONFIG_FANOTIFY_ACCESS_PERMISSIONS=y
355CONFIG_QUOTA=y 393CONFIG_QUOTA=y
356CONFIG_AUTOFS4_FS=y 394CONFIG_AUTOFS4_FS=y
357CONFIG_FUSE_FS=y 395CONFIG_FUSE_FS=m
358CONFIG_CUSE=y 396CONFIG_CUSE=m
397CONFIG_OVERLAY_FS=m
359CONFIG_VFAT_FS=y 398CONFIG_VFAT_FS=y
360CONFIG_TMPFS=y 399CONFIG_TMPFS=y
361CONFIG_HUGETLBFS=y 400CONFIG_HUGETLBFS=y
diff --git a/arch/arm64/include/asm/kprobes.h b/arch/arm64/include/asm/kprobes.h
index 61b49150dfa3..1737aecfcc5e 100644
--- a/arch/arm64/include/asm/kprobes.h
+++ b/arch/arm64/include/asm/kprobes.h
@@ -22,7 +22,6 @@
22 22
23#define __ARCH_WANT_KPROBES_INSN_SLOT 23#define __ARCH_WANT_KPROBES_INSN_SLOT
24#define MAX_INSN_SIZE 1 24#define MAX_INSN_SIZE 1
25#define MAX_STACK_SIZE 128
26 25
27#define flush_insn_slot(p) do { } while (0) 26#define flush_insn_slot(p) do { } while (0)
28#define kretprobe_blacklist_size 0 27#define kretprobe_blacklist_size 0
@@ -47,7 +46,6 @@ struct kprobe_ctlblk {
47 struct prev_kprobe prev_kprobe; 46 struct prev_kprobe prev_kprobe;
48 struct kprobe_step_ctx ss_ctx; 47 struct kprobe_step_ctx ss_ctx;
49 struct pt_regs jprobe_saved_regs; 48 struct pt_regs jprobe_saved_regs;
50 char jprobes_stack[MAX_STACK_SIZE];
51}; 49};
52 50
53void arch_remove_kprobe(struct kprobe *); 51void arch_remove_kprobe(struct kprobe *);
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index 96e4a2b64cc1..441420ca7d08 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -353,6 +353,8 @@ el1_sync:
353 lsr x24, x1, #ESR_ELx_EC_SHIFT // exception class 353 lsr x24, x1, #ESR_ELx_EC_SHIFT // exception class
354 cmp x24, #ESR_ELx_EC_DABT_CUR // data abort in EL1 354 cmp x24, #ESR_ELx_EC_DABT_CUR // data abort in EL1
355 b.eq el1_da 355 b.eq el1_da
356 cmp x24, #ESR_ELx_EC_IABT_CUR // instruction abort in EL1
357 b.eq el1_ia
356 cmp x24, #ESR_ELx_EC_SYS64 // configurable trap 358 cmp x24, #ESR_ELx_EC_SYS64 // configurable trap
357 b.eq el1_undef 359 b.eq el1_undef
358 cmp x24, #ESR_ELx_EC_SP_ALIGN // stack alignment exception 360 cmp x24, #ESR_ELx_EC_SP_ALIGN // stack alignment exception
@@ -364,6 +366,11 @@ el1_sync:
364 cmp x24, #ESR_ELx_EC_BREAKPT_CUR // debug exception in EL1 366 cmp x24, #ESR_ELx_EC_BREAKPT_CUR // debug exception in EL1
365 b.ge el1_dbg 367 b.ge el1_dbg
366 b el1_inv 368 b el1_inv
369
370el1_ia:
371 /*
372 * Fall through to the Data abort case
373 */
367el1_da: 374el1_da:
368 /* 375 /*
369 * Data abort handling 376 * Data abort handling
diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c
index 21ab5df9fa76..65d81f965e74 100644
--- a/arch/arm64/kernel/hibernate.c
+++ b/arch/arm64/kernel/hibernate.c
@@ -35,6 +35,7 @@
35#include <asm/sections.h> 35#include <asm/sections.h>
36#include <asm/smp.h> 36#include <asm/smp.h>
37#include <asm/suspend.h> 37#include <asm/suspend.h>
38#include <asm/sysreg.h>
38#include <asm/virt.h> 39#include <asm/virt.h>
39 40
40/* 41/*
@@ -217,12 +218,22 @@ static int create_safe_exec_page(void *src_start, size_t length,
217 set_pte(pte, __pte(virt_to_phys((void *)dst) | 218 set_pte(pte, __pte(virt_to_phys((void *)dst) |
218 pgprot_val(PAGE_KERNEL_EXEC))); 219 pgprot_val(PAGE_KERNEL_EXEC)));
219 220
220 /* Load our new page tables */ 221 /*
221 asm volatile("msr ttbr0_el1, %0;" 222 * Load our new page tables. A strict BBM approach requires that we
222 "isb;" 223 * ensure that TLBs are free of any entries that may overlap with the
223 "tlbi vmalle1is;" 224 * global mappings we are about to install.
224 "dsb ish;" 225 *
225 "isb" : : "r"(virt_to_phys(pgd))); 226 * For a real hibernate/resume cycle TTBR0 currently points to a zero
227 * page, but TLBs may contain stale ASID-tagged entries (e.g. for EFI
228 * runtime services), while for a userspace-driven test_resume cycle it
229 * points to userspace page tables (and we must point it at a zero page
230 * ourselves). Elsewhere we only (un)install the idmap with preemption
231 * disabled, so T0SZ should be as required regardless.
232 */
233 cpu_set_reserved_ttbr0();
234 local_flush_tlb_all();
235 write_sysreg(virt_to_phys(pgd), ttbr0_el1);
236 isb();
226 237
227 *phys_dst_addr = virt_to_phys((void *)dst); 238 *phys_dst_addr = virt_to_phys((void *)dst);
228 239
@@ -394,6 +405,38 @@ int swsusp_arch_resume(void)
394 void *, phys_addr_t, phys_addr_t); 405 void *, phys_addr_t, phys_addr_t);
395 406
396 /* 407 /*
408 * Restoring the memory image will overwrite the ttbr1 page tables.
409 * Create a second copy of just the linear map, and use this when
410 * restoring.
411 */
412 tmp_pg_dir = (pgd_t *)get_safe_page(GFP_ATOMIC);
413 if (!tmp_pg_dir) {
414 pr_err("Failed to allocate memory for temporary page tables.");
415 rc = -ENOMEM;
416 goto out;
417 }
418 rc = copy_page_tables(tmp_pg_dir, PAGE_OFFSET, 0);
419 if (rc)
420 goto out;
421
422 /*
423 * Since we only copied the linear map, we need to find restore_pblist's
424 * linear map address.
425 */
426 lm_restore_pblist = LMADDR(restore_pblist);
427
428 /*
429 * We need a zero page that is zero before & after resume in order to
430 * to break before make on the ttbr1 page tables.
431 */
432 zero_page = (void *)get_safe_page(GFP_ATOMIC);
433 if (!zero_page) {
434 pr_err("Failed to allocate zero page.");
435 rc = -ENOMEM;
436 goto out;
437 }
438
439 /*
397 * Locate the exit code in the bottom-but-one page, so that *NULL 440 * Locate the exit code in the bottom-but-one page, so that *NULL
398 * still has disastrous affects. 441 * still has disastrous affects.
399 */ 442 */
@@ -419,27 +462,6 @@ int swsusp_arch_resume(void)
419 __flush_dcache_area(hibernate_exit, exit_size); 462 __flush_dcache_area(hibernate_exit, exit_size);
420 463
421 /* 464 /*
422 * Restoring the memory image will overwrite the ttbr1 page tables.
423 * Create a second copy of just the linear map, and use this when
424 * restoring.
425 */
426 tmp_pg_dir = (pgd_t *)get_safe_page(GFP_ATOMIC);
427 if (!tmp_pg_dir) {
428 pr_err("Failed to allocate memory for temporary page tables.");
429 rc = -ENOMEM;
430 goto out;
431 }
432 rc = copy_page_tables(tmp_pg_dir, PAGE_OFFSET, 0);
433 if (rc)
434 goto out;
435
436 /*
437 * Since we only copied the linear map, we need to find restore_pblist's
438 * linear map address.
439 */
440 lm_restore_pblist = LMADDR(restore_pblist);
441
442 /*
443 * KASLR will cause the el2 vectors to be in a different location in 465 * KASLR will cause the el2 vectors to be in a different location in
444 * the resumed kernel. Load hibernate's temporary copy into el2. 466 * the resumed kernel. Load hibernate's temporary copy into el2.
445 * 467 *
@@ -453,12 +475,6 @@ int swsusp_arch_resume(void)
453 __hyp_set_vectors(el2_vectors); 475 __hyp_set_vectors(el2_vectors);
454 } 476 }
455 477
456 /*
457 * We need a zero page that is zero before & after resume in order to
458 * to break before make on the ttbr1 page tables.
459 */
460 zero_page = (void *)get_safe_page(GFP_ATOMIC);
461
462 hibernate_exit(virt_to_phys(tmp_pg_dir), resume_hdr.ttbr1_el1, 478 hibernate_exit(virt_to_phys(tmp_pg_dir), resume_hdr.ttbr1_el1,
463 resume_hdr.reenter_kernel, lm_restore_pblist, 479 resume_hdr.reenter_kernel, lm_restore_pblist,
464 resume_hdr.__hyp_stub_vectors, virt_to_phys(zero_page)); 480 resume_hdr.__hyp_stub_vectors, virt_to_phys(zero_page));
diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
index bf9768588288..c6b0f40620d8 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -41,18 +41,6 @@ DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
41static void __kprobes 41static void __kprobes
42post_kprobe_handler(struct kprobe_ctlblk *, struct pt_regs *); 42post_kprobe_handler(struct kprobe_ctlblk *, struct pt_regs *);
43 43
44static inline unsigned long min_stack_size(unsigned long addr)
45{
46 unsigned long size;
47
48 if (on_irq_stack(addr, raw_smp_processor_id()))
49 size = IRQ_STACK_PTR(raw_smp_processor_id()) - addr;
50 else
51 size = (unsigned long)current_thread_info() + THREAD_START_SP - addr;
52
53 return min(size, FIELD_SIZEOF(struct kprobe_ctlblk, jprobes_stack));
54}
55
56static void __kprobes arch_prepare_ss_slot(struct kprobe *p) 44static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
57{ 45{
58 /* prepare insn slot */ 46 /* prepare insn slot */
@@ -489,20 +477,15 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
489{ 477{
490 struct jprobe *jp = container_of(p, struct jprobe, kp); 478 struct jprobe *jp = container_of(p, struct jprobe, kp);
491 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); 479 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
492 long stack_ptr = kernel_stack_pointer(regs);
493 480
494 kcb->jprobe_saved_regs = *regs; 481 kcb->jprobe_saved_regs = *regs;
495 /* 482 /*
496 * As Linus pointed out, gcc assumes that the callee 483 * Since we can't be sure where in the stack frame "stacked"
497 * owns the argument space and could overwrite it, e.g. 484 * pass-by-value arguments are stored we just don't try to
498 * tailcall optimization. So, to be absolutely safe 485 * duplicate any of the stack. Do not use jprobes on functions that
499 * we also save and restore enough stack bytes to cover 486 * use more than 64 bytes (after padding each to an 8 byte boundary)
500 * the argument area. 487 * of arguments, or pass individual arguments larger than 16 bytes.
501 */ 488 */
502 kasan_disable_current();
503 memcpy(kcb->jprobes_stack, (void *)stack_ptr,
504 min_stack_size(stack_ptr));
505 kasan_enable_current();
506 489
507 instruction_pointer_set(regs, (unsigned long) jp->entry); 490 instruction_pointer_set(regs, (unsigned long) jp->entry);
508 preempt_disable(); 491 preempt_disable();
@@ -554,10 +537,6 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
554 } 537 }
555 unpause_graph_tracing(); 538 unpause_graph_tracing();
556 *regs = kcb->jprobe_saved_regs; 539 *regs = kcb->jprobe_saved_regs;
557 kasan_disable_current();
558 memcpy((void *)stack_addr, kcb->jprobes_stack,
559 min_stack_size(stack_addr));
560 kasan_enable_current();
561 preempt_enable_no_resched(); 540 preempt_enable_no_resched();
562 return 1; 541 return 1;
563} 542}
diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
index 76a6d9263908..d93d43352504 100644
--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -661,9 +661,9 @@ void __init smp_init_cpus(void)
661 acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT, 661 acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT,
662 acpi_parse_gic_cpu_interface, 0); 662 acpi_parse_gic_cpu_interface, 0);
663 663
664 if (cpu_count > NR_CPUS) 664 if (cpu_count > nr_cpu_ids)
665 pr_warn("no. of cores (%d) greater than configured maximum of %d - clipping\n", 665 pr_warn("Number of cores (%d) exceeds configured maximum of %d - clipping\n",
666 cpu_count, NR_CPUS); 666 cpu_count, nr_cpu_ids);
667 667
668 if (!bootcpu_valid) { 668 if (!bootcpu_valid) {
669 pr_err("missing boot CPU MPIDR, not enabling secondaries\n"); 669 pr_err("missing boot CPU MPIDR, not enabling secondaries\n");
@@ -677,7 +677,7 @@ void __init smp_init_cpus(void)
677 * with entries in cpu_logical_map while initializing the cpus. 677 * with entries in cpu_logical_map while initializing the cpus.
678 * If the cpu set-up fails, invalidate the cpu_logical_map entry. 678 * If the cpu set-up fails, invalidate the cpu_logical_map entry.
679 */ 679 */
680 for (i = 1; i < NR_CPUS; i++) { 680 for (i = 1; i < nr_cpu_ids; i++) {
681 if (cpu_logical_map(i) != INVALID_HWID) { 681 if (cpu_logical_map(i) != INVALID_HWID) {
682 if (smp_cpu_setup(i)) 682 if (smp_cpu_setup(i))
683 cpu_logical_map(i) = INVALID_HWID; 683 cpu_logical_map(i) = INVALID_HWID;
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index c8beaa0da7df..05d2bd776c69 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -153,6 +153,11 @@ int ptep_set_access_flags(struct vm_area_struct *vma,
153} 153}
154#endif 154#endif
155 155
156static bool is_el1_instruction_abort(unsigned int esr)
157{
158 return ESR_ELx_EC(esr) == ESR_ELx_EC_IABT_CUR;
159}
160
156/* 161/*
157 * The kernel tried to access some page that wasn't present. 162 * The kernel tried to access some page that wasn't present.
158 */ 163 */
@@ -161,8 +166,9 @@ static void __do_kernel_fault(struct mm_struct *mm, unsigned long addr,
161{ 166{
162 /* 167 /*
163 * Are we prepared to handle this kernel fault? 168 * Are we prepared to handle this kernel fault?
169 * We are almost certainly not prepared to handle instruction faults.
164 */ 170 */
165 if (fixup_exception(regs)) 171 if (!is_el1_instruction_abort(esr) && fixup_exception(regs))
166 return; 172 return;
167 173
168 /* 174 /*
@@ -267,7 +273,8 @@ static inline bool is_permission_fault(unsigned int esr)
267 unsigned int ec = ESR_ELx_EC(esr); 273 unsigned int ec = ESR_ELx_EC(esr);
268 unsigned int fsc_type = esr & ESR_ELx_FSC_TYPE; 274 unsigned int fsc_type = esr & ESR_ELx_FSC_TYPE;
269 275
270 return (ec == ESR_ELx_EC_DABT_CUR && fsc_type == ESR_ELx_FSC_PERM); 276 return (ec == ESR_ELx_EC_DABT_CUR && fsc_type == ESR_ELx_FSC_PERM) ||
277 (ec == ESR_ELx_EC_IABT_CUR && fsc_type == ESR_ELx_FSC_PERM);
271} 278}
272 279
273static bool is_el0_instruction_abort(unsigned int esr) 280static bool is_el0_instruction_abort(unsigned int esr)
@@ -312,6 +319,9 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,
312 if (regs->orig_addr_limit == KERNEL_DS) 319 if (regs->orig_addr_limit == KERNEL_DS)
313 die("Accessing user space memory with fs=KERNEL_DS", regs, esr); 320 die("Accessing user space memory with fs=KERNEL_DS", regs, esr);
314 321
322 if (is_el1_instruction_abort(esr))
323 die("Attempting to execute userspace memory", regs, esr);
324
315 if (!search_exception_tables(regs->pc)) 325 if (!search_exception_tables(regs->pc))
316 die("Accessing user space memory outside uaccess.h routines", regs, esr); 326 die("Accessing user space memory outside uaccess.h routines", regs, esr);
317 } 327 }
diff --git a/arch/h8300/include/asm/io.h b/arch/h8300/include/asm/io.h
index 2e221c5f0203..f86918aed9e1 100644
--- a/arch/h8300/include/asm/io.h
+++ b/arch/h8300/include/asm/io.h
@@ -3,6 +3,8 @@
3 3
4#ifdef __KERNEL__ 4#ifdef __KERNEL__
5 5
6#include <linux/types.h>
7
6/* H8/300 internal I/O functions */ 8/* H8/300 internal I/O functions */
7 9
8#define __raw_readb __raw_readb 10#define __raw_readb __raw_readb
diff --git a/arch/m68k/kernel/signal.c b/arch/m68k/kernel/signal.c
index 2dcee3a88867..9202f82dfce6 100644
--- a/arch/m68k/kernel/signal.c
+++ b/arch/m68k/kernel/signal.c
@@ -213,7 +213,6 @@ static inline int frame_extra_sizes(int f)
213 213
214static inline void adjustformat(struct pt_regs *regs) 214static inline void adjustformat(struct pt_regs *regs)
215{ 215{
216 ((struct switch_stack *)regs - 1)->a5 = current->mm->start_data;
217 /* 216 /*
218 * set format byte to make stack appear modulo 4, which it will 217 * set format byte to make stack appear modulo 4, which it will
219 * be when doing the rte 218 * be when doing the rte
diff --git a/arch/metag/mm/init.c b/arch/metag/mm/init.c
index 11fa51c89617..c0ec116b3993 100644
--- a/arch/metag/mm/init.c
+++ b/arch/metag/mm/init.c
@@ -390,7 +390,6 @@ void __init mem_init(void)
390 390
391 free_all_bootmem(); 391 free_all_bootmem();
392 mem_init_print_info(NULL); 392 mem_init_print_info(NULL);
393 show_mem(0);
394} 393}
395 394
396void free_initmem(void) 395void free_initmem(void)
diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
index 6eb52b9c9818..e788515f766b 100644
--- a/arch/mips/kvm/emulate.c
+++ b/arch/mips/kvm/emulate.c
@@ -1642,8 +1642,14 @@ enum emulation_result kvm_mips_emulate_cache(union mips_instruction inst,
1642 1642
1643 preempt_disable(); 1643 preempt_disable();
1644 if (KVM_GUEST_KSEGX(va) == KVM_GUEST_KSEG0) { 1644 if (KVM_GUEST_KSEGX(va) == KVM_GUEST_KSEG0) {
1645 if (kvm_mips_host_tlb_lookup(vcpu, va) < 0) 1645 if (kvm_mips_host_tlb_lookup(vcpu, va) < 0 &&
1646 kvm_mips_handle_kseg0_tlb_fault(va, vcpu); 1646 kvm_mips_handle_kseg0_tlb_fault(va, vcpu)) {
1647 kvm_err("%s: handling mapped kseg0 tlb fault for %lx, vcpu: %p, ASID: %#lx\n",
1648 __func__, va, vcpu, read_c0_entryhi());
1649 er = EMULATE_FAIL;
1650 preempt_enable();
1651 goto done;
1652 }
1647 } else if ((KVM_GUEST_KSEGX(va) < KVM_GUEST_KSEG0) || 1653 } else if ((KVM_GUEST_KSEGX(va) < KVM_GUEST_KSEG0) ||
1648 KVM_GUEST_KSEGX(va) == KVM_GUEST_KSEG23) { 1654 KVM_GUEST_KSEGX(va) == KVM_GUEST_KSEG23) {
1649 int index; 1655 int index;
@@ -1680,12 +1686,18 @@ enum emulation_result kvm_mips_emulate_cache(union mips_instruction inst,
1680 run, vcpu); 1686 run, vcpu);
1681 preempt_enable(); 1687 preempt_enable();
1682 goto dont_update_pc; 1688 goto dont_update_pc;
1683 } else { 1689 }
1684 /* 1690 /*
1685 * We fault an entry from the guest tlb to the 1691 * We fault an entry from the guest tlb to the
1686 * shadow host TLB 1692 * shadow host TLB
1687 */ 1693 */
1688 kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb); 1694 if (kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb)) {
1695 kvm_err("%s: handling mapped seg tlb fault for %lx, index: %u, vcpu: %p, ASID: %#lx\n",
1696 __func__, va, index, vcpu,
1697 read_c0_entryhi());
1698 er = EMULATE_FAIL;
1699 preempt_enable();
1700 goto done;
1689 } 1701 }
1690 } 1702 }
1691 } else { 1703 } else {
@@ -2659,7 +2671,12 @@ enum emulation_result kvm_mips_handle_tlbmiss(u32 cause,
2659 * OK we have a Guest TLB entry, now inject it into the 2671 * OK we have a Guest TLB entry, now inject it into the
2660 * shadow host TLB 2672 * shadow host TLB
2661 */ 2673 */
2662 kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb); 2674 if (kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb)) {
2675 kvm_err("%s: handling mapped seg tlb fault for %lx, index: %u, vcpu: %p, ASID: %#lx\n",
2676 __func__, va, index, vcpu,
2677 read_c0_entryhi());
2678 er = EMULATE_FAIL;
2679 }
2663 } 2680 }
2664 } 2681 }
2665 2682
diff --git a/arch/mips/kvm/mmu.c b/arch/mips/kvm/mmu.c
index 57319ee57c4f..6cfdcf55572d 100644
--- a/arch/mips/kvm/mmu.c
+++ b/arch/mips/kvm/mmu.c
@@ -99,7 +99,7 @@ int kvm_mips_handle_kseg0_tlb_fault(unsigned long badvaddr,
99 } 99 }
100 100
101 gfn = (KVM_GUEST_CPHYSADDR(badvaddr) >> PAGE_SHIFT); 101 gfn = (KVM_GUEST_CPHYSADDR(badvaddr) >> PAGE_SHIFT);
102 if (gfn >= kvm->arch.guest_pmap_npages) { 102 if ((gfn | 1) >= kvm->arch.guest_pmap_npages) {
103 kvm_err("%s: Invalid gfn: %#llx, BadVaddr: %#lx\n", __func__, 103 kvm_err("%s: Invalid gfn: %#llx, BadVaddr: %#lx\n", __func__,
104 gfn, badvaddr); 104 gfn, badvaddr);
105 kvm_mips_dump_host_tlbs(); 105 kvm_mips_dump_host_tlbs();
@@ -138,35 +138,49 @@ int kvm_mips_handle_mapped_seg_tlb_fault(struct kvm_vcpu *vcpu,
138 unsigned long entryhi = 0, entrylo0 = 0, entrylo1 = 0; 138 unsigned long entryhi = 0, entrylo0 = 0, entrylo1 = 0;
139 struct kvm *kvm = vcpu->kvm; 139 struct kvm *kvm = vcpu->kvm;
140 kvm_pfn_t pfn0, pfn1; 140 kvm_pfn_t pfn0, pfn1;
141 gfn_t gfn0, gfn1;
142 long tlb_lo[2];
141 int ret; 143 int ret;
142 144
143 if ((tlb->tlb_hi & VPN2_MASK) == 0) { 145 tlb_lo[0] = tlb->tlb_lo[0];
144 pfn0 = 0; 146 tlb_lo[1] = tlb->tlb_lo[1];
145 pfn1 = 0; 147
146 } else { 148 /*
147 if (kvm_mips_map_page(kvm, mips3_tlbpfn_to_paddr(tlb->tlb_lo[0]) 149 * The commpage address must not be mapped to anything else if the guest
148 >> PAGE_SHIFT) < 0) 150 * TLB contains entries nearby, or commpage accesses will break.
149 return -1; 151 */
150 152 if (!((tlb->tlb_hi ^ KVM_GUEST_COMMPAGE_ADDR) &
151 if (kvm_mips_map_page(kvm, mips3_tlbpfn_to_paddr(tlb->tlb_lo[1]) 153 VPN2_MASK & (PAGE_MASK << 1)))
152 >> PAGE_SHIFT) < 0) 154 tlb_lo[(KVM_GUEST_COMMPAGE_ADDR >> PAGE_SHIFT) & 1] = 0;
153 return -1; 155
154 156 gfn0 = mips3_tlbpfn_to_paddr(tlb_lo[0]) >> PAGE_SHIFT;
155 pfn0 = kvm->arch.guest_pmap[ 157 gfn1 = mips3_tlbpfn_to_paddr(tlb_lo[1]) >> PAGE_SHIFT;
156 mips3_tlbpfn_to_paddr(tlb->tlb_lo[0]) >> PAGE_SHIFT]; 158 if (gfn0 >= kvm->arch.guest_pmap_npages ||
157 pfn1 = kvm->arch.guest_pmap[ 159 gfn1 >= kvm->arch.guest_pmap_npages) {
158 mips3_tlbpfn_to_paddr(tlb->tlb_lo[1]) >> PAGE_SHIFT]; 160 kvm_err("%s: Invalid gfn: [%#llx, %#llx], EHi: %#lx\n",
161 __func__, gfn0, gfn1, tlb->tlb_hi);
162 kvm_mips_dump_guest_tlbs(vcpu);
163 return -1;
159 } 164 }
160 165
166 if (kvm_mips_map_page(kvm, gfn0) < 0)
167 return -1;
168
169 if (kvm_mips_map_page(kvm, gfn1) < 0)
170 return -1;
171
172 pfn0 = kvm->arch.guest_pmap[gfn0];
173 pfn1 = kvm->arch.guest_pmap[gfn1];
174
161 /* Get attributes from the Guest TLB */ 175 /* Get attributes from the Guest TLB */
162 entrylo0 = mips3_paddr_to_tlbpfn(pfn0 << PAGE_SHIFT) | 176 entrylo0 = mips3_paddr_to_tlbpfn(pfn0 << PAGE_SHIFT) |
163 ((_page_cachable_default >> _CACHE_SHIFT) << ENTRYLO_C_SHIFT) | 177 ((_page_cachable_default >> _CACHE_SHIFT) << ENTRYLO_C_SHIFT) |
164 (tlb->tlb_lo[0] & ENTRYLO_D) | 178 (tlb_lo[0] & ENTRYLO_D) |
165 (tlb->tlb_lo[0] & ENTRYLO_V); 179 (tlb_lo[0] & ENTRYLO_V);
166 entrylo1 = mips3_paddr_to_tlbpfn(pfn1 << PAGE_SHIFT) | 180 entrylo1 = mips3_paddr_to_tlbpfn(pfn1 << PAGE_SHIFT) |
167 ((_page_cachable_default >> _CACHE_SHIFT) << ENTRYLO_C_SHIFT) | 181 ((_page_cachable_default >> _CACHE_SHIFT) << ENTRYLO_C_SHIFT) |
168 (tlb->tlb_lo[1] & ENTRYLO_D) | 182 (tlb_lo[1] & ENTRYLO_D) |
169 (tlb->tlb_lo[1] & ENTRYLO_V); 183 (tlb_lo[1] & ENTRYLO_V);
170 184
171 kvm_debug("@ %#lx tlb_lo0: 0x%08lx tlb_lo1: 0x%08lx\n", vcpu->arch.pc, 185 kvm_debug("@ %#lx tlb_lo0: 0x%08lx tlb_lo1: 0x%08lx\n", vcpu->arch.pc,
172 tlb->tlb_lo[0], tlb->tlb_lo[1]); 186 tlb->tlb_lo[0], tlb->tlb_lo[1]);
@@ -354,9 +368,15 @@ u32 kvm_get_inst(u32 *opc, struct kvm_vcpu *vcpu)
354 local_irq_restore(flags); 368 local_irq_restore(flags);
355 return KVM_INVALID_INST; 369 return KVM_INVALID_INST;
356 } 370 }
357 kvm_mips_handle_mapped_seg_tlb_fault(vcpu, 371 if (kvm_mips_handle_mapped_seg_tlb_fault(vcpu,
358 &vcpu->arch. 372 &vcpu->arch.guest_tlb[index])) {
359 guest_tlb[index]); 373 kvm_err("%s: handling mapped seg tlb fault failed for %p, index: %u, vcpu: %p, ASID: %#lx\n",
374 __func__, opc, index, vcpu,
375 read_c0_entryhi());
376 kvm_mips_dump_guest_tlbs(vcpu);
377 local_irq_restore(flags);
378 return KVM_INVALID_INST;
379 }
360 inst = *(opc); 380 inst = *(opc);
361 } 381 }
362 local_irq_restore(flags); 382 local_irq_restore(flags);
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index ca254546cd05..1934707bf321 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -66,29 +66,28 @@ endif
66UTS_MACHINE := $(OLDARCH) 66UTS_MACHINE := $(OLDARCH)
67 67
68ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y) 68ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y)
69override CC += -mlittle-endian
70ifneq ($(cc-name),clang)
71override CC += -mno-strict-align
72endif
73override AS += -mlittle-endian
74override LD += -EL 69override LD += -EL
75override CROSS32CC += -mlittle-endian
76override CROSS32AS += -mlittle-endian 70override CROSS32AS += -mlittle-endian
77LDEMULATION := lppc 71LDEMULATION := lppc
78GNUTARGET := powerpcle 72GNUTARGET := powerpcle
79MULTIPLEWORD := -mno-multiple 73MULTIPLEWORD := -mno-multiple
80KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-save-toc-indirect) 74KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-save-toc-indirect)
81else 75else
82ifeq ($(call cc-option-yn,-mbig-endian),y)
83override CC += -mbig-endian
84override AS += -mbig-endian
85endif
86override LD += -EB 76override LD += -EB
87LDEMULATION := ppc 77LDEMULATION := ppc
88GNUTARGET := powerpc 78GNUTARGET := powerpc
89MULTIPLEWORD := -mmultiple 79MULTIPLEWORD := -mmultiple
90endif 80endif
91 81
82cflags-$(CONFIG_CPU_BIG_ENDIAN) += $(call cc-option,-mbig-endian)
83cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mlittle-endian
84ifneq ($(cc-name),clang)
85 cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mno-strict-align
86endif
87
88aflags-$(CONFIG_CPU_BIG_ENDIAN) += $(call cc-option,-mbig-endian)
89aflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mlittle-endian
90
92ifeq ($(HAS_BIARCH),y) 91ifeq ($(HAS_BIARCH),y)
93override AS += -a$(CONFIG_WORD_SIZE) 92override AS += -a$(CONFIG_WORD_SIZE)
94override LD += -m elf$(CONFIG_WORD_SIZE)$(LDEMULATION) 93override LD += -m elf$(CONFIG_WORD_SIZE)$(LDEMULATION)
@@ -232,6 +231,9 @@ cpu-as-$(CONFIG_E200) += -Wa,-me200
232KBUILD_AFLAGS += $(cpu-as-y) 231KBUILD_AFLAGS += $(cpu-as-y)
233KBUILD_CFLAGS += $(cpu-as-y) 232KBUILD_CFLAGS += $(cpu-as-y)
234 233
234KBUILD_AFLAGS += $(aflags-y)
235KBUILD_CFLAGS += $(cflags-y)
236
235head-y := arch/powerpc/kernel/head_$(CONFIG_WORD_SIZE).o 237head-y := arch/powerpc/kernel/head_$(CONFIG_WORD_SIZE).o
236head-$(CONFIG_8xx) := arch/powerpc/kernel/head_8xx.o 238head-$(CONFIG_8xx) := arch/powerpc/kernel/head_8xx.o
237head-$(CONFIG_40x) := arch/powerpc/kernel/head_40x.o 239head-$(CONFIG_40x) := arch/powerpc/kernel/head_40x.o
diff --git a/arch/powerpc/crypto/crc32c-vpmsum_glue.c b/arch/powerpc/crypto/crc32c-vpmsum_glue.c
index bfe3d37a24ef..9fa046d56eba 100644
--- a/arch/powerpc/crypto/crc32c-vpmsum_glue.c
+++ b/arch/powerpc/crypto/crc32c-vpmsum_glue.c
@@ -4,6 +4,7 @@
4#include <linux/module.h> 4#include <linux/module.h>
5#include <linux/string.h> 5#include <linux/string.h>
6#include <linux/kernel.h> 6#include <linux/kernel.h>
7#include <linux/cpufeature.h>
7#include <asm/switch_to.h> 8#include <asm/switch_to.h>
8 9
9#define CHKSUM_BLOCK_SIZE 1 10#define CHKSUM_BLOCK_SIZE 1
@@ -157,7 +158,7 @@ static void __exit crc32c_vpmsum_mod_fini(void)
157 crypto_unregister_shash(&alg); 158 crypto_unregister_shash(&alg);
158} 159}
159 160
160module_init(crc32c_vpmsum_mod_init); 161module_cpu_feature_match(PPC_MODULE_FEATURE_VEC_CRYPTO, crc32c_vpmsum_mod_init);
161module_exit(crc32c_vpmsum_mod_fini); 162module_exit(crc32c_vpmsum_mod_fini);
162 163
163MODULE_AUTHOR("Anton Blanchard <anton@samba.org>"); 164MODULE_AUTHOR("Anton Blanchard <anton@samba.org>");
diff --git a/arch/powerpc/include/asm/cpuidle.h b/arch/powerpc/include/asm/cpuidle.h
index 3d7fc06532a1..01b8a13f0224 100644
--- a/arch/powerpc/include/asm/cpuidle.h
+++ b/arch/powerpc/include/asm/cpuidle.h
@@ -19,4 +19,17 @@ extern u64 pnv_first_deep_stop_state;
19 19
20#endif 20#endif
21 21
22/* Idle state entry routines */
23#ifdef CONFIG_PPC_P7_NAP
24#define IDLE_STATE_ENTER_SEQ(IDLE_INST) \
25 /* Magic NAP/SLEEP/WINKLE mode enter sequence */ \
26 std r0,0(r1); \
27 ptesync; \
28 ld r0,0(r1); \
291: cmp cr0,r0,r0; \
30 bne 1b; \
31 IDLE_INST; \
32 b .
33#endif /* CONFIG_PPC_P7_NAP */
34
22#endif 35#endif
diff --git a/arch/powerpc/include/asm/feature-fixups.h b/arch/powerpc/include/asm/feature-fixups.h
index 57fec8ac7b92..ddf54f5bbdd1 100644
--- a/arch/powerpc/include/asm/feature-fixups.h
+++ b/arch/powerpc/include/asm/feature-fixups.h
@@ -186,6 +186,7 @@ label##3: \
186 186
187#ifndef __ASSEMBLY__ 187#ifndef __ASSEMBLY__
188void apply_feature_fixups(void); 188void apply_feature_fixups(void);
189void setup_feature_keys(void);
189#endif 190#endif
190 191
191#endif /* __ASM_POWERPC_FEATURE_FIXUPS_H */ 192#endif /* __ASM_POWERPC_FEATURE_FIXUPS_H */
diff --git a/arch/powerpc/include/asm/switch_to.h b/arch/powerpc/include/asm/switch_to.h
index 0a74ebe934e1..17c8380673a6 100644
--- a/arch/powerpc/include/asm/switch_to.h
+++ b/arch/powerpc/include/asm/switch_to.h
@@ -75,14 +75,6 @@ static inline void disable_kernel_spe(void)
75static inline void __giveup_spe(struct task_struct *t) { } 75static inline void __giveup_spe(struct task_struct *t) { }
76#endif 76#endif
77 77
78#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
79extern void flush_tmregs_to_thread(struct task_struct *);
80#else
81static inline void flush_tmregs_to_thread(struct task_struct *t)
82{
83}
84#endif
85
86static inline void clear_task_ebb(struct task_struct *t) 78static inline void clear_task_ebb(struct task_struct *t)
87{ 79{
88#ifdef CONFIG_PPC_BOOK3S_64 80#ifdef CONFIG_PPC_BOOK3S_64
diff --git a/arch/powerpc/include/asm/xics.h b/arch/powerpc/include/asm/xics.h
index f5f729c11578..f0b238516e9b 100644
--- a/arch/powerpc/include/asm/xics.h
+++ b/arch/powerpc/include/asm/xics.h
@@ -159,6 +159,8 @@ extern void xics_teardown_cpu(void);
159extern void xics_kexec_teardown_cpu(int secondary); 159extern void xics_kexec_teardown_cpu(int secondary);
160extern void xics_migrate_irqs_away(void); 160extern void xics_migrate_irqs_away(void);
161extern void icp_native_eoi(struct irq_data *d); 161extern void icp_native_eoi(struct irq_data *d);
162extern int xics_set_irq_type(struct irq_data *d, unsigned int flow_type);
163extern int xics_retrigger(struct irq_data *data);
162#ifdef CONFIG_SMP 164#ifdef CONFIG_SMP
163extern int xics_get_irq_server(unsigned int virq, const struct cpumask *cpumask, 165extern int xics_get_irq_server(unsigned int virq, const struct cpumask *cpumask,
164 unsigned int strict_check); 166 unsigned int strict_check);
diff --git a/arch/powerpc/kernel/eeh.c b/arch/powerpc/kernel/eeh.c
index c9bc78e9c610..7429556eb8df 100644
--- a/arch/powerpc/kernel/eeh.c
+++ b/arch/powerpc/kernel/eeh.c
@@ -168,10 +168,10 @@ static size_t eeh_dump_dev_log(struct eeh_dev *edev, char *buf, size_t len)
168 int n = 0, l = 0; 168 int n = 0, l = 0;
169 char buffer[128]; 169 char buffer[128];
170 170
171 n += scnprintf(buf+n, len-n, "%04x:%02x:%02x:%01x\n", 171 n += scnprintf(buf+n, len-n, "%04x:%02x:%02x.%01x\n",
172 edev->phb->global_number, pdn->busno, 172 edev->phb->global_number, pdn->busno,
173 PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn)); 173 PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
174 pr_warn("EEH: of node=%04x:%02x:%02x:%01x\n", 174 pr_warn("EEH: of node=%04x:%02x:%02x.%01x\n",
175 edev->phb->global_number, pdn->busno, 175 edev->phb->global_number, pdn->busno,
176 PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn)); 176 PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
177 177
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 41091fdf9bd8..df6d45eb4115 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -144,29 +144,14 @@ machine_check_pSeries_1:
144 * vector 144 * vector
145 */ 145 */
146 SET_SCRATCH0(r13) /* save r13 */ 146 SET_SCRATCH0(r13) /* save r13 */
147#ifdef CONFIG_PPC_P7_NAP 147 /*
148BEGIN_FTR_SECTION 148 * Running native on arch 2.06 or later, we may wakeup from winkle
149 /* Running native on arch 2.06 or later, check if we are 149 * inside machine check. If yes, then last bit of HSPGR0 would be set
150 * waking up from nap. We only handle no state loss and 150 * to 1. Hence clear it unconditionally.
151 * supervisor state loss. We do -not- handle hypervisor
152 * state loss at this time.
153 */ 151 */
154 mfspr r13,SPRN_SRR1 152 GET_PACA(r13)
155 rlwinm. r13,r13,47-31,30,31 153 clrrdi r13,r13,1
156 OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR) 154 SET_PACA(r13)
157 beq 9f
158
159 mfspr r13,SPRN_SRR1
160 rlwinm. r13,r13,47-31,30,31
161 /* waking up from powersave (nap) state */
162 cmpwi cr1,r13,2
163 /* Total loss of HV state is fatal. let's just stay stuck here */
164 OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
165 bgt cr1,.
1669:
167 OPT_SET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
168END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
169#endif /* CONFIG_PPC_P7_NAP */
170 EXCEPTION_PROLOG_0(PACA_EXMC) 155 EXCEPTION_PROLOG_0(PACA_EXMC)
171BEGIN_FTR_SECTION 156BEGIN_FTR_SECTION
172 b machine_check_powernv_early 157 b machine_check_powernv_early
@@ -1273,25 +1258,51 @@ machine_check_handle_early:
1273 * Check if thread was in power saving mode. We come here when any 1258 * Check if thread was in power saving mode. We come here when any
1274 * of the following is true: 1259 * of the following is true:
1275 * a. thread wasn't in power saving mode 1260 * a. thread wasn't in power saving mode
1276 * b. thread was in power saving mode with no state loss or 1261 * b. thread was in power saving mode with no state loss,
1277 * supervisor state loss 1262 * supervisor state loss or hypervisor state loss.
1278 * 1263 *
1279 * Go back to nap again if (b) is true. 1264 * Go back to nap/sleep/winkle mode again if (b) is true.
1280 */ 1265 */
1281 rlwinm. r11,r12,47-31,30,31 /* Was it in power saving mode? */ 1266 rlwinm. r11,r12,47-31,30,31 /* Was it in power saving mode? */
1282 beq 4f /* No, it wasn;t */ 1267 beq 4f /* No, it wasn;t */
1283 /* Thread was in power saving mode. Go back to nap again. */ 1268 /* Thread was in power saving mode. Go back to nap again. */
1284 cmpwi r11,2 1269 cmpwi r11,2
1285 bne 3f 1270 blt 3f
1286 /* Supervisor state loss */ 1271 /* Supervisor/Hypervisor state loss */
1287 li r0,1 1272 li r0,1
1288 stb r0,PACA_NAPSTATELOST(r13) 1273 stb r0,PACA_NAPSTATELOST(r13)
12893: bl machine_check_queue_event 12743: bl machine_check_queue_event
1290 MACHINE_CHECK_HANDLER_WINDUP 1275 MACHINE_CHECK_HANDLER_WINDUP
1291 GET_PACA(r13) 1276 GET_PACA(r13)
1292 ld r1,PACAR1(r13) 1277 ld r1,PACAR1(r13)
1293 li r3,PNV_THREAD_NAP 1278 /*
1294 b pnv_enter_arch207_idle_mode 1279 * Check what idle state this CPU was in and go back to same mode
1280 * again.
1281 */
1282 lbz r3,PACA_THREAD_IDLE_STATE(r13)
1283 cmpwi r3,PNV_THREAD_NAP
1284 bgt 10f
1285 IDLE_STATE_ENTER_SEQ(PPC_NAP)
1286 /* No return */
128710:
1288 cmpwi r3,PNV_THREAD_SLEEP
1289 bgt 2f
1290 IDLE_STATE_ENTER_SEQ(PPC_SLEEP)
1291 /* No return */
1292
12932:
1294 /*
1295 * Go back to winkle. Please note that this thread was woken up in
1296 * machine check from winkle and have not restored the per-subcore
1297 * state. Hence before going back to winkle, set last bit of HSPGR0
1298 * to 1. This will make sure that if this thread gets woken up
1299 * again at reset vector 0x100 then it will get chance to restore
1300 * the subcore state.
1301 */
1302 ori r13,r13,1
1303 SET_PACA(r13)
1304 IDLE_STATE_ENTER_SEQ(PPC_WINKLE)
1305 /* No return */
12954: 13064:
1296#endif 1307#endif
1297 /* 1308 /*
diff --git a/arch/powerpc/kernel/idle_book3s.S b/arch/powerpc/kernel/idle_book3s.S
index ba79d15f4ddd..2265c6398a17 100644
--- a/arch/powerpc/kernel/idle_book3s.S
+++ b/arch/powerpc/kernel/idle_book3s.S
@@ -44,18 +44,6 @@
44 PSSCR_PSLL_MASK | PSSCR_TR_MASK | \ 44 PSSCR_PSLL_MASK | PSSCR_TR_MASK | \
45 PSSCR_MTL_MASK 45 PSSCR_MTL_MASK
46 46
47/* Idle state entry routines */
48
49#define IDLE_STATE_ENTER_SEQ(IDLE_INST) \
50 /* Magic NAP/SLEEP/WINKLE mode enter sequence */ \
51 std r0,0(r1); \
52 ptesync; \
53 ld r0,0(r1); \
541: cmp cr0,r0,r0; \
55 bne 1b; \
56 IDLE_INST; \
57 b .
58
59 .text 47 .text
60 48
61/* 49/*
@@ -363,8 +351,8 @@ _GLOBAL(power9_idle_stop)
363 * cr3 - set to gt if waking up with partial/complete hypervisor state loss 351 * cr3 - set to gt if waking up with partial/complete hypervisor state loss
364 */ 352 */
365_GLOBAL(pnv_restore_hyp_resource) 353_GLOBAL(pnv_restore_hyp_resource)
366 ld r2,PACATOC(r13);
367BEGIN_FTR_SECTION 354BEGIN_FTR_SECTION
355 ld r2,PACATOC(r13);
368 /* 356 /*
369 * POWER ISA 3. Use PSSCR to determine if we 357 * POWER ISA 3. Use PSSCR to determine if we
370 * are waking up from deep idle state 358 * are waking up from deep idle state
@@ -395,6 +383,9 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
395 */ 383 */
396 clrldi r5,r13,63 384 clrldi r5,r13,63
397 clrrdi r13,r13,1 385 clrrdi r13,r13,1
386
387 /* Now that we are sure r13 is corrected, load TOC */
388 ld r2,PACATOC(r13);
398 cmpwi cr4,r5,1 389 cmpwi cr4,r5,1
399 mtspr SPRN_HSPRG0,r13 390 mtspr SPRN_HSPRG0,r13
400 391
diff --git a/arch/powerpc/kernel/mce.c b/arch/powerpc/kernel/mce.c
index ef267fd9dd22..5e7ece0fda9f 100644
--- a/arch/powerpc/kernel/mce.c
+++ b/arch/powerpc/kernel/mce.c
@@ -92,7 +92,8 @@ void save_mce_event(struct pt_regs *regs, long handled,
92 mce->in_use = 1; 92 mce->in_use = 1;
93 93
94 mce->initiator = MCE_INITIATOR_CPU; 94 mce->initiator = MCE_INITIATOR_CPU;
95 if (handled) 95 /* Mark it recovered if we have handled it and MSR(RI=1). */
96 if (handled && (regs->msr & MSR_RI))
96 mce->disposition = MCE_DISPOSITION_RECOVERED; 97 mce->disposition = MCE_DISPOSITION_RECOVERED;
97 else 98 else
98 mce->disposition = MCE_DISPOSITION_NOT_RECOVERED; 99 mce->disposition = MCE_DISPOSITION_NOT_RECOVERED;
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index a5c0153ede37..7fdf324d5b51 100644
--- a/arch/powerpc/kernel/pci-common.c
+++ b/arch/powerpc/kernel/pci-common.c
@@ -78,6 +78,7 @@ EXPORT_SYMBOL(get_pci_dma_ops);
78static int get_phb_number(struct device_node *dn) 78static int get_phb_number(struct device_node *dn)
79{ 79{
80 int ret, phb_id = -1; 80 int ret, phb_id = -1;
81 u32 prop_32;
81 u64 prop; 82 u64 prop;
82 83
83 /* 84 /*
@@ -86,8 +87,10 @@ static int get_phb_number(struct device_node *dn)
86 * reading "ibm,opal-phbid", only present in OPAL environment. 87 * reading "ibm,opal-phbid", only present in OPAL environment.
87 */ 88 */
88 ret = of_property_read_u64(dn, "ibm,opal-phbid", &prop); 89 ret = of_property_read_u64(dn, "ibm,opal-phbid", &prop);
89 if (ret) 90 if (ret) {
90 ret = of_property_read_u32_index(dn, "reg", 1, (u32 *)&prop); 91 ret = of_property_read_u32_index(dn, "reg", 1, &prop_32);
92 prop = prop_32;
93 }
91 94
92 if (!ret) 95 if (!ret)
93 phb_id = (int)(prop & (MAX_PHBS - 1)); 96 phb_id = (int)(prop & (MAX_PHBS - 1));
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 58ccf86415b4..9ee2623e0f67 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1074,26 +1074,6 @@ static inline void restore_sprs(struct thread_struct *old_thread,
1074#endif 1074#endif
1075} 1075}
1076 1076
1077#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1078void flush_tmregs_to_thread(struct task_struct *tsk)
1079{
1080 /*
1081 * Process self tracing is not yet supported through
1082 * ptrace interface. Ptrace generic code should have
1083 * prevented this from happening in the first place.
1084 * Warn once here with the message, if some how it
1085 * is attempted.
1086 */
1087 WARN_ONCE(tsk == current,
1088 "Not expecting ptrace on self: TM regs may be incorrect\n");
1089
1090 /*
1091 * If task is not current, it should have been flushed
1092 * already to it's thread_struct during __switch_to().
1093 */
1094}
1095#endif
1096
1097struct task_struct *__switch_to(struct task_struct *prev, 1077struct task_struct *__switch_to(struct task_struct *prev,
1098 struct task_struct *new) 1078 struct task_struct *new)
1099{ 1079{
diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index 6ee4b72cda42..4e74fc588a3f 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -2940,7 +2940,7 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,
2940 2940
2941 /* Don't print anything after quiesce under OPAL, it crashes OFW */ 2941 /* Don't print anything after quiesce under OPAL, it crashes OFW */
2942 if (of_platform != PLATFORM_OPAL) { 2942 if (of_platform != PLATFORM_OPAL) {
2943 prom_printf("Booting Linux via __start() ...\n"); 2943 prom_printf("Booting Linux via __start() @ 0x%lx ...\n", kbase);
2944 prom_debug("->dt_header_start=0x%x\n", hdr); 2944 prom_debug("->dt_header_start=0x%x\n", hdr);
2945 } 2945 }
2946 2946
diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index 4f3c5756cc09..bf91658a8a40 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -38,6 +38,7 @@
38#include <asm/page.h> 38#include <asm/page.h>
39#include <asm/pgtable.h> 39#include <asm/pgtable.h>
40#include <asm/switch_to.h> 40#include <asm/switch_to.h>
41#include <asm/tm.h>
41 42
42#define CREATE_TRACE_POINTS 43#define CREATE_TRACE_POINTS
43#include <trace/events/syscalls.h> 44#include <trace/events/syscalls.h>
@@ -118,6 +119,24 @@ static const struct pt_regs_offset regoffset_table[] = {
118 REG_OFFSET_END, 119 REG_OFFSET_END,
119}; 120};
120 121
122#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
123static void flush_tmregs_to_thread(struct task_struct *tsk)
124{
125 /*
126 * If task is not current, it will have been flushed already to
127 * it's thread_struct during __switch_to().
128 *
129 * A reclaim flushes ALL the state.
130 */
131
132 if (tsk == current && MSR_TM_SUSPENDED(mfmsr()))
133 tm_reclaim_current(TM_CAUSE_SIGNAL);
134
135}
136#else
137static inline void flush_tmregs_to_thread(struct task_struct *tsk) { }
138#endif
139
121/** 140/**
122 * regs_query_register_offset() - query register offset from its name 141 * regs_query_register_offset() - query register offset from its name
123 * @name: the name of a register 142 * @name: the name of a register
diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c
index c3e861df4b20..24ec3ea4b3a2 100644
--- a/arch/powerpc/kernel/setup_32.c
+++ b/arch/powerpc/kernel/setup_32.c
@@ -93,15 +93,16 @@ notrace unsigned long __init early_init(unsigned long dt_ptr)
93 * and we are running with enough of the MMU enabled to have our 93 * and we are running with enough of the MMU enabled to have our
94 * proper kernel virtual addresses 94 * proper kernel virtual addresses
95 * 95 *
96 * Find out what kind of machine we're on and save any data we need 96 * We do the initial parsing of the flat device-tree and prepares
97 * from the early boot process (devtree is copied on pmac by prom_init()). 97 * for the MMU to be fully initialized.
98 * This is called very early on the boot process, after a minimal
99 * MMU environment has been set up but before MMU_init is called.
100 */ 98 */
101extern unsigned int memset_nocache_branch; /* Insn to be replaced by NOP */ 99extern unsigned int memset_nocache_branch; /* Insn to be replaced by NOP */
102 100
103notrace void __init machine_init(u64 dt_ptr) 101notrace void __init machine_init(u64 dt_ptr)
104{ 102{
103 /* Configure static keys first, now that we're relocated. */
104 setup_feature_keys();
105
105 /* Enable early debugging if any specified (see udbg.h) */ 106 /* Enable early debugging if any specified (see udbg.h) */
106 udbg_early_init(); 107 udbg_early_init();
107 108
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index eafb9a79e011..7ac8e6eaab5b 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -300,6 +300,7 @@ void __init early_setup(unsigned long dt_ptr)
300 300
301 /* Apply all the dynamic patching */ 301 /* Apply all the dynamic patching */
302 apply_feature_fixups(); 302 apply_feature_fixups();
303 setup_feature_keys();
303 304
304 /* Initialize the hash table or TLB handling */ 305 /* Initialize the hash table or TLB handling */
305 early_init_mmu(); 306 early_init_mmu();
diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
index 6767605ea8da..4111d30badfa 100644
--- a/arch/powerpc/kernel/vdso.c
+++ b/arch/powerpc/kernel/vdso.c
@@ -22,6 +22,7 @@
22#include <linux/security.h> 22#include <linux/security.h>
23#include <linux/memblock.h> 23#include <linux/memblock.h>
24 24
25#include <asm/cpu_has_feature.h>
25#include <asm/pgtable.h> 26#include <asm/pgtable.h>
26#include <asm/processor.h> 27#include <asm/processor.h>
27#include <asm/mmu.h> 28#include <asm/mmu.h>
diff --git a/arch/powerpc/kernel/vdso32/Makefile b/arch/powerpc/kernel/vdso32/Makefile
index cbabd143acae..78a7449bf489 100644
--- a/arch/powerpc/kernel/vdso32/Makefile
+++ b/arch/powerpc/kernel/vdso32/Makefile
@@ -30,7 +30,7 @@ CPPFLAGS_vdso32.lds += -P -C -Upowerpc
30$(obj)/vdso32_wrapper.o : $(obj)/vdso32.so 30$(obj)/vdso32_wrapper.o : $(obj)/vdso32.so
31 31
32# link rule for the .so file, .lds has to be first 32# link rule for the .so file, .lds has to be first
33$(obj)/vdso32.so.dbg: $(src)/vdso32.lds $(obj-vdso32) 33$(obj)/vdso32.so.dbg: $(src)/vdso32.lds $(obj-vdso32) FORCE
34 $(call if_changed,vdso32ld) 34 $(call if_changed,vdso32ld)
35 35
36# strip rule for the .so file 36# strip rule for the .so file
@@ -39,12 +39,12 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE
39 $(call if_changed,objcopy) 39 $(call if_changed,objcopy)
40 40
41# assembly rules for the .S files 41# assembly rules for the .S files
42$(obj-vdso32): %.o: %.S 42$(obj-vdso32): %.o: %.S FORCE
43 $(call if_changed_dep,vdso32as) 43 $(call if_changed_dep,vdso32as)
44 44
45# actual build commands 45# actual build commands
46quiet_cmd_vdso32ld = VDSO32L $@ 46quiet_cmd_vdso32ld = VDSO32L $@
47 cmd_vdso32ld = $(CROSS32CC) $(c_flags) -Wl,-T $^ -o $@ 47 cmd_vdso32ld = $(CROSS32CC) $(c_flags) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^)
48quiet_cmd_vdso32as = VDSO32A $@ 48quiet_cmd_vdso32as = VDSO32A $@
49 cmd_vdso32as = $(CROSS32CC) $(a_flags) -c -o $@ $< 49 cmd_vdso32as = $(CROSS32CC) $(a_flags) -c -o $@ $<
50 50
diff --git a/arch/powerpc/kernel/vdso64/Makefile b/arch/powerpc/kernel/vdso64/Makefile
index c710802b8fb6..366ae09b14c1 100644
--- a/arch/powerpc/kernel/vdso64/Makefile
+++ b/arch/powerpc/kernel/vdso64/Makefile
@@ -23,7 +23,7 @@ CPPFLAGS_vdso64.lds += -P -C -U$(ARCH)
23$(obj)/vdso64_wrapper.o : $(obj)/vdso64.so 23$(obj)/vdso64_wrapper.o : $(obj)/vdso64.so
24 24
25# link rule for the .so file, .lds has to be first 25# link rule for the .so file, .lds has to be first
26$(obj)/vdso64.so.dbg: $(src)/vdso64.lds $(obj-vdso64) 26$(obj)/vdso64.so.dbg: $(src)/vdso64.lds $(obj-vdso64) FORCE
27 $(call if_changed,vdso64ld) 27 $(call if_changed,vdso64ld)
28 28
29# strip rule for the .so file 29# strip rule for the .so file
@@ -32,12 +32,12 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE
32 $(call if_changed,objcopy) 32 $(call if_changed,objcopy)
33 33
34# assembly rules for the .S files 34# assembly rules for the .S files
35$(obj-vdso64): %.o: %.S 35$(obj-vdso64): %.o: %.S FORCE
36 $(call if_changed_dep,vdso64as) 36 $(call if_changed_dep,vdso64as)
37 37
38# actual build commands 38# actual build commands
39quiet_cmd_vdso64ld = VDSO64L $@ 39quiet_cmd_vdso64ld = VDSO64L $@
40 cmd_vdso64ld = $(CC) $(c_flags) -Wl,-T $^ -o $@ 40 cmd_vdso64ld = $(CC) $(c_flags) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^)
41quiet_cmd_vdso64as = VDSO64A $@ 41quiet_cmd_vdso64as = VDSO64A $@
42 cmd_vdso64as = $(CC) $(a_flags) -c -o $@ $< 42 cmd_vdso64as = $(CC) $(a_flags) -c -o $@ $<
43 43
diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c
index a75ba38a2d81..05aa11399a78 100644
--- a/arch/powerpc/kvm/book3s_xics.c
+++ b/arch/powerpc/kvm/book3s_xics.c
@@ -1329,20 +1329,16 @@ static int kvmppc_xics_create(struct kvm_device *dev, u32 type)
1329 xics->kvm = kvm; 1329 xics->kvm = kvm;
1330 1330
1331 /* Already there ? */ 1331 /* Already there ? */
1332 mutex_lock(&kvm->lock);
1333 if (kvm->arch.xics) 1332 if (kvm->arch.xics)
1334 ret = -EEXIST; 1333 ret = -EEXIST;
1335 else 1334 else
1336 kvm->arch.xics = xics; 1335 kvm->arch.xics = xics;
1337 mutex_unlock(&kvm->lock);
1338 1336
1339 if (ret) { 1337 if (ret) {
1340 kfree(xics); 1338 kfree(xics);
1341 return ret; 1339 return ret;
1342 } 1340 }
1343 1341
1344 xics_debugfs_init(xics);
1345
1346#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 1342#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
1347 if (cpu_has_feature(CPU_FTR_ARCH_206)) { 1343 if (cpu_has_feature(CPU_FTR_ARCH_206)) {
1348 /* Enable real mode support */ 1344 /* Enable real mode support */
@@ -1354,9 +1350,17 @@ static int kvmppc_xics_create(struct kvm_device *dev, u32 type)
1354 return 0; 1350 return 0;
1355} 1351}
1356 1352
1353static void kvmppc_xics_init(struct kvm_device *dev)
1354{
1355 struct kvmppc_xics *xics = (struct kvmppc_xics *)dev->private;
1356
1357 xics_debugfs_init(xics);
1358}
1359
1357struct kvm_device_ops kvm_xics_ops = { 1360struct kvm_device_ops kvm_xics_ops = {
1358 .name = "kvm-xics", 1361 .name = "kvm-xics",
1359 .create = kvmppc_xics_create, 1362 .create = kvmppc_xics_create,
1363 .init = kvmppc_xics_init,
1360 .destroy = kvmppc_xics_free, 1364 .destroy = kvmppc_xics_free,
1361 .set_attr = xics_set_attr, 1365 .set_attr = xics_set_attr,
1362 .get_attr = xics_get_attr, 1366 .get_attr = xics_get_attr,
diff --git a/arch/powerpc/lib/checksum_32.S b/arch/powerpc/lib/checksum_32.S
index d90870a66b60..0a57fe6d49cc 100644
--- a/arch/powerpc/lib/checksum_32.S
+++ b/arch/powerpc/lib/checksum_32.S
@@ -127,8 +127,9 @@ _GLOBAL(csum_partial_copy_generic)
127 stw r7,12(r1) 127 stw r7,12(r1)
128 stw r8,8(r1) 128 stw r8,8(r1)
129 129
130 andi. r0,r4,1 /* is destination address even ? */ 130 rlwinm r0,r4,3,0x8
131 cmplwi cr7,r0,0 131 rlwnm r6,r6,r0,0,31 /* odd destination address: rotate one byte */
132 cmplwi cr7,r0,0 /* is destination address even ? */
132 addic r12,r6,0 133 addic r12,r6,0
133 addi r6,r4,-4 134 addi r6,r4,-4
134 neg r0,r4 135 neg r0,r4
@@ -237,7 +238,7 @@ _GLOBAL(csum_partial_copy_generic)
23766: addze r3,r12 23866: addze r3,r12
238 addi r1,r1,16 239 addi r1,r1,16
239 beqlr+ cr7 240 beqlr+ cr7
240 rlwinm r3,r3,8,0,31 /* swap bytes for odd destination */ 241 rlwinm r3,r3,8,0,31 /* odd destination address: rotate one byte */
241 blr 242 blr
242 243
243/* read fault */ 244/* read fault */
diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-fixups.c
index 74145f02ad41..043415f0bdb1 100644
--- a/arch/powerpc/lib/feature-fixups.c
+++ b/arch/powerpc/lib/feature-fixups.c
@@ -188,7 +188,10 @@ void __init apply_feature_fixups(void)
188 &__start___fw_ftr_fixup, &__stop___fw_ftr_fixup); 188 &__start___fw_ftr_fixup, &__stop___fw_ftr_fixup);
189#endif 189#endif
190 do_final_fixups(); 190 do_final_fixups();
191}
191 192
193void __init setup_feature_keys(void)
194{
192 /* 195 /*
193 * Initialise jump label. This causes all the cpu/mmu_has_feature() 196 * Initialise jump label. This causes all the cpu/mmu_has_feature()
194 * checks to take on their correct polarity based on the current set of 197 * checks to take on their correct polarity based on the current set of
diff --git a/arch/powerpc/platforms/cell/spufs/inode.c b/arch/powerpc/platforms/cell/spufs/inode.c
index 5be15cff758d..2975754c65ea 100644
--- a/arch/powerpc/platforms/cell/spufs/inode.c
+++ b/arch/powerpc/platforms/cell/spufs/inode.c
@@ -496,8 +496,10 @@ spufs_mkgang(struct inode *dir, struct dentry *dentry, umode_t mode)
496 gang = alloc_spu_gang(); 496 gang = alloc_spu_gang();
497 SPUFS_I(inode)->i_ctx = NULL; 497 SPUFS_I(inode)->i_ctx = NULL;
498 SPUFS_I(inode)->i_gang = gang; 498 SPUFS_I(inode)->i_gang = gang;
499 if (!gang) 499 if (!gang) {
500 ret = -ENOMEM;
500 goto out_iput; 501 goto out_iput;
502 }
501 503
502 inode->i_op = &simple_dir_inode_operations; 504 inode->i_op = &simple_dir_inode_operations;
503 inode->i_fop = &simple_dir_operations; 505 inode->i_fop = &simple_dir_operations;
diff --git a/arch/powerpc/platforms/pasemi/iommu.c b/arch/powerpc/platforms/pasemi/iommu.c
index 309d9ccccd50..c61667e8bb06 100644
--- a/arch/powerpc/platforms/pasemi/iommu.c
+++ b/arch/powerpc/platforms/pasemi/iommu.c
@@ -187,6 +187,11 @@ static void pci_dma_dev_setup_pasemi(struct pci_dev *dev)
187 if (dev->vendor == 0x1959 && dev->device == 0xa007 && 187 if (dev->vendor == 0x1959 && dev->device == 0xa007 &&
188 !firmware_has_feature(FW_FEATURE_LPAR)) { 188 !firmware_has_feature(FW_FEATURE_LPAR)) {
189 dev->dev.archdata.dma_ops = &dma_direct_ops; 189 dev->dev.archdata.dma_ops = &dma_direct_ops;
190 /*
191 * Set the coherent DMA mask to prevent the iommu
192 * being used unnecessarily
193 */
194 dev->dev.coherent_dma_mask = DMA_BIT_MASK(44);
190 return; 195 return;
191 } 196 }
192#endif 197#endif
diff --git a/arch/powerpc/platforms/powernv/opal-irqchip.c b/arch/powerpc/platforms/powernv/opal-irqchip.c
index e505223b4ec5..ed8bba68a162 100644
--- a/arch/powerpc/platforms/powernv/opal-irqchip.c
+++ b/arch/powerpc/platforms/powernv/opal-irqchip.c
@@ -228,7 +228,8 @@ int __init opal_event_init(void)
228 } 228 }
229 229
230 /* Install interrupt handler */ 230 /* Install interrupt handler */
231 rc = request_irq(virq, opal_interrupt, 0, "opal", NULL); 231 rc = request_irq(virq, opal_interrupt, IRQF_TRIGGER_LOW,
232 "opal", NULL);
232 if (rc) { 233 if (rc) {
233 irq_dispose_mapping(virq); 234 irq_dispose_mapping(virq);
234 pr_warn("Error %d requesting irq %d (0x%x)\n", 235 pr_warn("Error %d requesting irq %d (0x%x)\n",
diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c
index 8b4fc68cebcb..6c9a65b52e63 100644
--- a/arch/powerpc/platforms/powernv/opal.c
+++ b/arch/powerpc/platforms/powernv/opal.c
@@ -399,6 +399,7 @@ static int opal_recover_mce(struct pt_regs *regs,
399 399
400 if (!(regs->msr & MSR_RI)) { 400 if (!(regs->msr & MSR_RI)) {
401 /* If MSR_RI isn't set, we cannot recover */ 401 /* If MSR_RI isn't set, we cannot recover */
402 pr_err("Machine check interrupt unrecoverable: MSR(RI=0)\n");
402 recovered = 0; 403 recovered = 0;
403 } else if (evt->disposition == MCE_DISPOSITION_RECOVERED) { 404 } else if (evt->disposition == MCE_DISPOSITION_RECOVERED) {
404 /* Platform corrected itself */ 405 /* Platform corrected itself */
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 6b9528307f62..fd9444f9fb0c 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -111,10 +111,17 @@ static int __init iommu_setup(char *str)
111} 111}
112early_param("iommu", iommu_setup); 112early_param("iommu", iommu_setup);
113 113
114static inline bool pnv_pci_is_mem_pref_64(unsigned long flags) 114static inline bool pnv_pci_is_m64(struct pnv_phb *phb, struct resource *r)
115{ 115{
116 return ((flags & (IORESOURCE_MEM_64 | IORESOURCE_PREFETCH)) == 116 /*
117 (IORESOURCE_MEM_64 | IORESOURCE_PREFETCH)); 117 * WARNING: We cannot rely on the resource flags. The Linux PCI
118 * allocation code sometimes decides to put a 64-bit prefetchable
119 * BAR in the 32-bit window, so we have to compare the addresses.
120 *
121 * For simplicity we only test resource start.
122 */
123 return (r->start >= phb->ioda.m64_base &&
124 r->start < (phb->ioda.m64_base + phb->ioda.m64_size));
118} 125}
119 126
120static struct pnv_ioda_pe *pnv_ioda_init_pe(struct pnv_phb *phb, int pe_no) 127static struct pnv_ioda_pe *pnv_ioda_init_pe(struct pnv_phb *phb, int pe_no)
@@ -229,7 +236,7 @@ static void pnv_ioda_reserve_dev_m64_pe(struct pci_dev *pdev,
229 sgsz = phb->ioda.m64_segsize; 236 sgsz = phb->ioda.m64_segsize;
230 for (i = 0; i <= PCI_ROM_RESOURCE; i++) { 237 for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
231 r = &pdev->resource[i]; 238 r = &pdev->resource[i];
232 if (!r->parent || !pnv_pci_is_mem_pref_64(r->flags)) 239 if (!r->parent || !pnv_pci_is_m64(phb, r))
233 continue; 240 continue;
234 241
235 start = _ALIGN_DOWN(r->start - base, sgsz); 242 start = _ALIGN_DOWN(r->start - base, sgsz);
@@ -1877,7 +1884,7 @@ static void pnv_pci_phb3_tce_invalidate(struct pnv_ioda_pe *pe, bool rm,
1877 unsigned shift, unsigned long index, 1884 unsigned shift, unsigned long index,
1878 unsigned long npages) 1885 unsigned long npages)
1879{ 1886{
1880 __be64 __iomem *invalidate = pnv_ioda_get_inval_reg(pe->phb, false); 1887 __be64 __iomem *invalidate = pnv_ioda_get_inval_reg(pe->phb, rm);
1881 unsigned long start, end, inc; 1888 unsigned long start, end, inc;
1882 1889
1883 /* We'll invalidate DMA address in PE scope */ 1890 /* We'll invalidate DMA address in PE scope */
@@ -2863,7 +2870,7 @@ static void pnv_pci_ioda_fixup_iov_resources(struct pci_dev *pdev)
2863 res = &pdev->resource[i + PCI_IOV_RESOURCES]; 2870 res = &pdev->resource[i + PCI_IOV_RESOURCES];
2864 if (!res->flags || res->parent) 2871 if (!res->flags || res->parent)
2865 continue; 2872 continue;
2866 if (!pnv_pci_is_mem_pref_64(res->flags)) { 2873 if (!pnv_pci_is_m64(phb, res)) {
2867 dev_warn(&pdev->dev, "Don't support SR-IOV with" 2874 dev_warn(&pdev->dev, "Don't support SR-IOV with"
2868 " non M64 VF BAR%d: %pR. \n", 2875 " non M64 VF BAR%d: %pR. \n",
2869 i, res); 2876 i, res);
@@ -2958,7 +2965,7 @@ static void pnv_ioda_setup_pe_res(struct pnv_ioda_pe *pe,
2958 index++; 2965 index++;
2959 } 2966 }
2960 } else if ((res->flags & IORESOURCE_MEM) && 2967 } else if ((res->flags & IORESOURCE_MEM) &&
2961 !pnv_pci_is_mem_pref_64(res->flags)) { 2968 !pnv_pci_is_m64(phb, res)) {
2962 region.start = res->start - 2969 region.start = res->start -
2963 phb->hose->mem_offset[0] - 2970 phb->hose->mem_offset[0] -
2964 phb->ioda.m32_pci_base; 2971 phb->ioda.m32_pci_base;
@@ -3083,9 +3090,12 @@ static resource_size_t pnv_pci_window_alignment(struct pci_bus *bus,
3083 bridge = bridge->bus->self; 3090 bridge = bridge->bus->self;
3084 } 3091 }
3085 3092
3086 /* We fail back to M32 if M64 isn't supported */ 3093 /*
3087 if (phb->ioda.m64_segsize && 3094 * We fall back to M32 if M64 isn't supported. We enforce the M64
3088 pnv_pci_is_mem_pref_64(type)) 3095 * alignment for any 64-bit resource, PCIe doesn't care and
3096 * bridges only do 64-bit prefetchable anyway.
3097 */
3098 if (phb->ioda.m64_segsize && (type & IORESOURCE_MEM_64))
3089 return phb->ioda.m64_segsize; 3099 return phb->ioda.m64_segsize;
3090 if (type & IORESOURCE_MEM) 3100 if (type & IORESOURCE_MEM)
3091 return phb->ioda.m32_segsize; 3101 return phb->ioda.m32_segsize;
@@ -3125,7 +3135,7 @@ static void pnv_pci_fixup_bridge_resources(struct pci_bus *bus,
3125 w = NULL; 3135 w = NULL;
3126 if (r->flags & type & IORESOURCE_IO) 3136 if (r->flags & type & IORESOURCE_IO)
3127 w = &hose->io_resource; 3137 w = &hose->io_resource;
3128 else if (pnv_pci_is_mem_pref_64(r->flags) && 3138 else if (pnv_pci_is_m64(phb, r) &&
3129 (type & IORESOURCE_PREFETCH) && 3139 (type & IORESOURCE_PREFETCH) &&
3130 phb->ioda.m64_segsize) 3140 phb->ioda.m64_segsize)
3131 w = &hose->mem_resources[1]; 3141 w = &hose->mem_resources[1];
diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
index 43f7beb2902d..76ec104e88be 100644
--- a/arch/powerpc/platforms/pseries/hotplug-memory.c
+++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
@@ -320,19 +320,6 @@ static int dlpar_remove_device_tree_lmb(struct of_drconf_cell *lmb)
320 return dlpar_update_device_tree_lmb(lmb); 320 return dlpar_update_device_tree_lmb(lmb);
321} 321}
322 322
323static struct memory_block *lmb_to_memblock(struct of_drconf_cell *lmb)
324{
325 unsigned long section_nr;
326 struct mem_section *mem_sect;
327 struct memory_block *mem_block;
328
329 section_nr = pfn_to_section_nr(PFN_DOWN(lmb->base_addr));
330 mem_sect = __nr_to_section(section_nr);
331
332 mem_block = find_memory_block(mem_sect);
333 return mem_block;
334}
335
336#ifdef CONFIG_MEMORY_HOTREMOVE 323#ifdef CONFIG_MEMORY_HOTREMOVE
337static int pseries_remove_memblock(unsigned long base, unsigned int memblock_size) 324static int pseries_remove_memblock(unsigned long base, unsigned int memblock_size)
338{ 325{
@@ -420,6 +407,19 @@ static bool lmb_is_removable(struct of_drconf_cell *lmb)
420 407
421static int dlpar_add_lmb(struct of_drconf_cell *); 408static int dlpar_add_lmb(struct of_drconf_cell *);
422 409
410static struct memory_block *lmb_to_memblock(struct of_drconf_cell *lmb)
411{
412 unsigned long section_nr;
413 struct mem_section *mem_sect;
414 struct memory_block *mem_block;
415
416 section_nr = pfn_to_section_nr(PFN_DOWN(lmb->base_addr));
417 mem_sect = __nr_to_section(section_nr);
418
419 mem_block = find_memory_block(mem_sect);
420 return mem_block;
421}
422
423static int dlpar_remove_lmb(struct of_drconf_cell *lmb) 423static int dlpar_remove_lmb(struct of_drconf_cell *lmb)
424{ 424{
425 struct memory_block *mem_block; 425 struct memory_block *mem_block;
diff --git a/arch/powerpc/sysdev/xics/Kconfig b/arch/powerpc/sysdev/xics/Kconfig
index 0031eda320c3..385e7aa9e273 100644
--- a/arch/powerpc/sysdev/xics/Kconfig
+++ b/arch/powerpc/sysdev/xics/Kconfig
@@ -1,6 +1,7 @@
1config PPC_XICS 1config PPC_XICS
2 def_bool n 2 def_bool n
3 select PPC_SMP_MUXED_IPI 3 select PPC_SMP_MUXED_IPI
4 select HARDIRQS_SW_RESEND
4 5
5config PPC_ICP_NATIVE 6config PPC_ICP_NATIVE
6 def_bool n 7 def_bool n
diff --git a/arch/powerpc/sysdev/xics/ics-opal.c b/arch/powerpc/sysdev/xics/ics-opal.c
index 27c936c080a6..1c6bf4b66f56 100644
--- a/arch/powerpc/sysdev/xics/ics-opal.c
+++ b/arch/powerpc/sysdev/xics/ics-opal.c
@@ -156,7 +156,9 @@ static struct irq_chip ics_opal_irq_chip = {
156 .irq_mask = ics_opal_mask_irq, 156 .irq_mask = ics_opal_mask_irq,
157 .irq_unmask = ics_opal_unmask_irq, 157 .irq_unmask = ics_opal_unmask_irq,
158 .irq_eoi = NULL, /* Patched at init time */ 158 .irq_eoi = NULL, /* Patched at init time */
159 .irq_set_affinity = ics_opal_set_affinity 159 .irq_set_affinity = ics_opal_set_affinity,
160 .irq_set_type = xics_set_irq_type,
161 .irq_retrigger = xics_retrigger,
160}; 162};
161 163
162static int ics_opal_map(struct ics *ics, unsigned int virq); 164static int ics_opal_map(struct ics *ics, unsigned int virq);
diff --git a/arch/powerpc/sysdev/xics/ics-rtas.c b/arch/powerpc/sysdev/xics/ics-rtas.c
index 3854dd41558d..78ee5c778ef8 100644
--- a/arch/powerpc/sysdev/xics/ics-rtas.c
+++ b/arch/powerpc/sysdev/xics/ics-rtas.c
@@ -163,7 +163,9 @@ static struct irq_chip ics_rtas_irq_chip = {
163 .irq_mask = ics_rtas_mask_irq, 163 .irq_mask = ics_rtas_mask_irq,
164 .irq_unmask = ics_rtas_unmask_irq, 164 .irq_unmask = ics_rtas_unmask_irq,
165 .irq_eoi = NULL, /* Patched at init time */ 165 .irq_eoi = NULL, /* Patched at init time */
166 .irq_set_affinity = ics_rtas_set_affinity 166 .irq_set_affinity = ics_rtas_set_affinity,
167 .irq_set_type = xics_set_irq_type,
168 .irq_retrigger = xics_retrigger,
167}; 169};
168 170
169static int ics_rtas_map(struct ics *ics, unsigned int virq) 171static int ics_rtas_map(struct ics *ics, unsigned int virq)
diff --git a/arch/powerpc/sysdev/xics/xics-common.c b/arch/powerpc/sysdev/xics/xics-common.c
index a795a5f0301c..9d530f479588 100644
--- a/arch/powerpc/sysdev/xics/xics-common.c
+++ b/arch/powerpc/sysdev/xics/xics-common.c
@@ -328,8 +328,12 @@ static int xics_host_map(struct irq_domain *h, unsigned int virq,
328 328
329 pr_devel("xics: map virq %d, hwirq 0x%lx\n", virq, hw); 329 pr_devel("xics: map virq %d, hwirq 0x%lx\n", virq, hw);
330 330
331 /* They aren't all level sensitive but we just don't really know */ 331 /*
332 irq_set_status_flags(virq, IRQ_LEVEL); 332 * Mark interrupts as edge sensitive by default so that resend
333 * actually works. The device-tree parsing will turn the LSIs
334 * back to level.
335 */
336 irq_clear_status_flags(virq, IRQ_LEVEL);
333 337
334 /* Don't call into ICS for IPIs */ 338 /* Don't call into ICS for IPIs */
335 if (hw == XICS_IPI) { 339 if (hw == XICS_IPI) {
@@ -351,13 +355,54 @@ static int xics_host_xlate(struct irq_domain *h, struct device_node *ct,
351 irq_hw_number_t *out_hwirq, unsigned int *out_flags) 355 irq_hw_number_t *out_hwirq, unsigned int *out_flags)
352 356
353{ 357{
354 /* Current xics implementation translates everything
355 * to level. It is not technically right for MSIs but this
356 * is irrelevant at this point. We might get smarter in the future
357 */
358 *out_hwirq = intspec[0]; 358 *out_hwirq = intspec[0];
359 *out_flags = IRQ_TYPE_LEVEL_LOW;
360 359
360 /*
361 * If intsize is at least 2, we look for the type in the second cell,
362 * we assume the LSB indicates a level interrupt.
363 */
364 if (intsize > 1) {
365 if (intspec[1] & 1)
366 *out_flags = IRQ_TYPE_LEVEL_LOW;
367 else
368 *out_flags = IRQ_TYPE_EDGE_RISING;
369 } else
370 *out_flags = IRQ_TYPE_LEVEL_LOW;
371
372 return 0;
373}
374
375int xics_set_irq_type(struct irq_data *d, unsigned int flow_type)
376{
377 /*
378 * We only support these. This has really no effect other than setting
379 * the corresponding descriptor bits mind you but those will in turn
380 * affect the resend function when re-enabling an edge interrupt.
381 *
382 * Set set the default to edge as explained in map().
383 */
384 if (flow_type == IRQ_TYPE_DEFAULT || flow_type == IRQ_TYPE_NONE)
385 flow_type = IRQ_TYPE_EDGE_RISING;
386
387 if (flow_type != IRQ_TYPE_EDGE_RISING &&
388 flow_type != IRQ_TYPE_LEVEL_LOW)
389 return -EINVAL;
390
391 irqd_set_trigger_type(d, flow_type);
392
393 return IRQ_SET_MASK_OK_NOCOPY;
394}
395
396int xics_retrigger(struct irq_data *data)
397{
398 /*
399 * We need to push a dummy CPPR when retriggering, since the subsequent
400 * EOI will try to pop it. Passing 0 works, as the function hard codes
401 * the priority value anyway.
402 */
403 xics_push_cppr(0);
404
405 /* Tell the core to do a soft retrigger */
361 return 0; 406 return 0;
362} 407}
363 408
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 0e348781327b..e751fe25d6ab 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -872,4 +872,17 @@ config S390_GUEST
872 Select this option if you want to run the kernel as a guest under 872 Select this option if you want to run the kernel as a guest under
873 the KVM hypervisor. 873 the KVM hypervisor.
874 874
875config S390_GUEST_OLD_TRANSPORT
876 def_bool y
877 prompt "Guest support for old s390 virtio transport (DEPRECATED)"
878 depends on S390_GUEST
879 help
880 Enable this option to add support for the old s390-virtio
881 transport (i.e. virtio devices NOT based on virtio-ccw). This
882 type of virtio devices is only available on the experimental
883 kuli userspace or with old (< 2.6) qemu. If you are running
884 with a modern version of qemu (which supports virtio-ccw since
885 1.4 and uses it by default since version 2.4), you probably won't
886 need this.
887
875endmenu 888endmenu
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 3f3ae4865d57..f142215ed30d 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -1672,6 +1672,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
1672 KVM_SYNC_CRS | 1672 KVM_SYNC_CRS |
1673 KVM_SYNC_ARCH0 | 1673 KVM_SYNC_ARCH0 |
1674 KVM_SYNC_PFAULT; 1674 KVM_SYNC_PFAULT;
1675 kvm_s390_set_prefix(vcpu, 0);
1675 if (test_kvm_facility(vcpu->kvm, 64)) 1676 if (test_kvm_facility(vcpu->kvm, 64))
1676 vcpu->run->kvm_valid_regs |= KVM_SYNC_RICCB; 1677 vcpu->run->kvm_valid_regs |= KVM_SYNC_RICCB;
1677 /* fprs can be synchronized via vrs, even if the guest has no vx. With 1678 /* fprs can be synchronized via vrs, even if the guest has no vx. With
@@ -2361,8 +2362,10 @@ retry:
2361 rc = gmap_mprotect_notify(vcpu->arch.gmap, 2362 rc = gmap_mprotect_notify(vcpu->arch.gmap,
2362 kvm_s390_get_prefix(vcpu), 2363 kvm_s390_get_prefix(vcpu),
2363 PAGE_SIZE * 2, PROT_WRITE); 2364 PAGE_SIZE * 2, PROT_WRITE);
2364 if (rc) 2365 if (rc) {
2366 kvm_make_request(KVM_REQ_MMU_RELOAD, vcpu);
2365 return rc; 2367 return rc;
2368 }
2366 goto retry; 2369 goto retry;
2367 } 2370 }
2368 2371
diff --git a/arch/unicore32/include/asm/mmu_context.h b/arch/unicore32/include/asm/mmu_context.h
index e35632ef23c7..62dfc644c908 100644
--- a/arch/unicore32/include/asm/mmu_context.h
+++ b/arch/unicore32/include/asm/mmu_context.h
@@ -98,7 +98,7 @@ static inline void arch_bprm_mm_init(struct mm_struct *mm,
98} 98}
99 99
100static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, 100static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,
101 bool write, bool foreign) 101 bool write, bool execute, bool foreign)
102{ 102{
103 /* by default, allow everything */ 103 /* by default, allow everything */
104 return true; 104 return true;
diff --git a/arch/x86/entry/Makefile b/arch/x86/entry/Makefile
index fe91c25092da..77f28ce9c646 100644
--- a/arch/x86/entry/Makefile
+++ b/arch/x86/entry/Makefile
@@ -5,6 +5,8 @@
5OBJECT_FILES_NON_STANDARD_entry_$(BITS).o := y 5OBJECT_FILES_NON_STANDARD_entry_$(BITS).o := y
6OBJECT_FILES_NON_STANDARD_entry_64_compat.o := y 6OBJECT_FILES_NON_STANDARD_entry_64_compat.o := y
7 7
8CFLAGS_syscall_64.o += -Wno-override-init
9CFLAGS_syscall_32.o += -Wno-override-init
8obj-y := entry_$(BITS).o thunk_$(BITS).o syscall_$(BITS).o 10obj-y := entry_$(BITS).o thunk_$(BITS).o syscall_$(BITS).o
9obj-y += common.o 11obj-y += common.o
10 12
diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index b846875aeea6..d172c619c449 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -288,11 +288,15 @@ return_from_SYSCALL_64:
288 jne opportunistic_sysret_failed 288 jne opportunistic_sysret_failed
289 289
290 /* 290 /*
291 * SYSRET can't restore RF. SYSRET can restore TF, but unlike IRET, 291 * SYSCALL clears RF when it saves RFLAGS in R11 and SYSRET cannot
292 * restoring TF results in a trap from userspace immediately after 292 * restore RF properly. If the slowpath sets it for whatever reason, we
293 * SYSRET. This would cause an infinite loop whenever #DB happens 293 * need to restore it correctly.
294 * with register state that satisfies the opportunistic SYSRET 294 *
295 * conditions. For example, single-stepping this user code: 295 * SYSRET can restore TF, but unlike IRET, restoring TF results in a
296 * trap from userspace immediately after SYSRET. This would cause an
297 * infinite loop whenever #DB happens with register state that satisfies
298 * the opportunistic SYSRET conditions. For example, single-stepping
299 * this user code:
296 * 300 *
297 * movq $stuck_here, %rcx 301 * movq $stuck_here, %rcx
298 * pushfq 302 * pushfq
@@ -601,9 +605,20 @@ apicinterrupt3 \num trace(\sym) smp_trace(\sym)
601.endm 605.endm
602#endif 606#endif
603 607
608/* Make sure APIC interrupt handlers end up in the irqentry section: */
609#if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
610# define PUSH_SECTION_IRQENTRY .pushsection .irqentry.text, "ax"
611# define POP_SECTION_IRQENTRY .popsection
612#else
613# define PUSH_SECTION_IRQENTRY
614# define POP_SECTION_IRQENTRY
615#endif
616
604.macro apicinterrupt num sym do_sym 617.macro apicinterrupt num sym do_sym
618PUSH_SECTION_IRQENTRY
605apicinterrupt3 \num \sym \do_sym 619apicinterrupt3 \num \sym \do_sym
606trace_apicinterrupt \num \sym 620trace_apicinterrupt \num \sym
621POP_SECTION_IRQENTRY
607.endm 622.endm
608 623
609#ifdef CONFIG_SMP 624#ifdef CONFIG_SMP
diff --git a/arch/x86/events/intel/uncore_snb.c b/arch/x86/events/intel/uncore_snb.c
index 97a69dbba649..9d35ec0cb8fc 100644
--- a/arch/x86/events/intel/uncore_snb.c
+++ b/arch/x86/events/intel/uncore_snb.c
@@ -100,6 +100,12 @@ static void snb_uncore_msr_init_box(struct intel_uncore_box *box)
100 } 100 }
101} 101}
102 102
103static void snb_uncore_msr_enable_box(struct intel_uncore_box *box)
104{
105 wrmsrl(SNB_UNC_PERF_GLOBAL_CTL,
106 SNB_UNC_GLOBAL_CTL_EN | SNB_UNC_GLOBAL_CTL_CORE_ALL);
107}
108
103static void snb_uncore_msr_exit_box(struct intel_uncore_box *box) 109static void snb_uncore_msr_exit_box(struct intel_uncore_box *box)
104{ 110{
105 if (box->pmu->pmu_idx == 0) 111 if (box->pmu->pmu_idx == 0)
@@ -127,6 +133,7 @@ static struct attribute_group snb_uncore_format_group = {
127 133
128static struct intel_uncore_ops snb_uncore_msr_ops = { 134static struct intel_uncore_ops snb_uncore_msr_ops = {
129 .init_box = snb_uncore_msr_init_box, 135 .init_box = snb_uncore_msr_init_box,
136 .enable_box = snb_uncore_msr_enable_box,
130 .exit_box = snb_uncore_msr_exit_box, 137 .exit_box = snb_uncore_msr_exit_box,
131 .disable_event = snb_uncore_msr_disable_event, 138 .disable_event = snb_uncore_msr_disable_event,
132 .enable_event = snb_uncore_msr_enable_event, 139 .enable_event = snb_uncore_msr_enable_event,
@@ -192,6 +199,12 @@ static void skl_uncore_msr_init_box(struct intel_uncore_box *box)
192 } 199 }
193} 200}
194 201
202static void skl_uncore_msr_enable_box(struct intel_uncore_box *box)
203{
204 wrmsrl(SKL_UNC_PERF_GLOBAL_CTL,
205 SNB_UNC_GLOBAL_CTL_EN | SKL_UNC_GLOBAL_CTL_CORE_ALL);
206}
207
195static void skl_uncore_msr_exit_box(struct intel_uncore_box *box) 208static void skl_uncore_msr_exit_box(struct intel_uncore_box *box)
196{ 209{
197 if (box->pmu->pmu_idx == 0) 210 if (box->pmu->pmu_idx == 0)
@@ -200,6 +213,7 @@ static void skl_uncore_msr_exit_box(struct intel_uncore_box *box)
200 213
201static struct intel_uncore_ops skl_uncore_msr_ops = { 214static struct intel_uncore_ops skl_uncore_msr_ops = {
202 .init_box = skl_uncore_msr_init_box, 215 .init_box = skl_uncore_msr_init_box,
216 .enable_box = skl_uncore_msr_enable_box,
203 .exit_box = skl_uncore_msr_exit_box, 217 .exit_box = skl_uncore_msr_exit_box,
204 .disable_event = snb_uncore_msr_disable_event, 218 .disable_event = snb_uncore_msr_disable_event,
205 .enable_event = snb_uncore_msr_enable_event, 219 .enable_event = snb_uncore_msr_enable_event,
diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c
index 824e54086e07..8aee83bcf71f 100644
--- a/arch/x86/events/intel/uncore_snbep.c
+++ b/arch/x86/events/intel/uncore_snbep.c
@@ -2626,7 +2626,7 @@ void hswep_uncore_cpu_init(void)
2626 2626
2627static struct intel_uncore_type hswep_uncore_ha = { 2627static struct intel_uncore_type hswep_uncore_ha = {
2628 .name = "ha", 2628 .name = "ha",
2629 .num_counters = 5, 2629 .num_counters = 4,
2630 .num_boxes = 2, 2630 .num_boxes = 2,
2631 .perf_ctr_bits = 48, 2631 .perf_ctr_bits = 48,
2632 SNBEP_UNCORE_PCI_COMMON_INIT(), 2632 SNBEP_UNCORE_PCI_COMMON_INIT(),
@@ -2645,7 +2645,7 @@ static struct uncore_event_desc hswep_uncore_imc_events[] = {
2645 2645
2646static struct intel_uncore_type hswep_uncore_imc = { 2646static struct intel_uncore_type hswep_uncore_imc = {
2647 .name = "imc", 2647 .name = "imc",
2648 .num_counters = 5, 2648 .num_counters = 4,
2649 .num_boxes = 8, 2649 .num_boxes = 8,
2650 .perf_ctr_bits = 48, 2650 .perf_ctr_bits = 48,
2651 .fixed_ctr_bits = 48, 2651 .fixed_ctr_bits = 48,
@@ -2691,7 +2691,7 @@ static struct intel_uncore_type hswep_uncore_irp = {
2691 2691
2692static struct intel_uncore_type hswep_uncore_qpi = { 2692static struct intel_uncore_type hswep_uncore_qpi = {
2693 .name = "qpi", 2693 .name = "qpi",
2694 .num_counters = 5, 2694 .num_counters = 4,
2695 .num_boxes = 3, 2695 .num_boxes = 3,
2696 .perf_ctr_bits = 48, 2696 .perf_ctr_bits = 48,
2697 .perf_ctr = SNBEP_PCI_PMON_CTR0, 2697 .perf_ctr = SNBEP_PCI_PMON_CTR0,
@@ -2773,7 +2773,7 @@ static struct event_constraint hswep_uncore_r3qpi_constraints[] = {
2773 2773
2774static struct intel_uncore_type hswep_uncore_r3qpi = { 2774static struct intel_uncore_type hswep_uncore_r3qpi = {
2775 .name = "r3qpi", 2775 .name = "r3qpi",
2776 .num_counters = 4, 2776 .num_counters = 3,
2777 .num_boxes = 3, 2777 .num_boxes = 3,
2778 .perf_ctr_bits = 44, 2778 .perf_ctr_bits = 44,
2779 .constraints = hswep_uncore_r3qpi_constraints, 2779 .constraints = hswep_uncore_r3qpi_constraints,
@@ -2972,7 +2972,7 @@ static struct intel_uncore_type bdx_uncore_ha = {
2972 2972
2973static struct intel_uncore_type bdx_uncore_imc = { 2973static struct intel_uncore_type bdx_uncore_imc = {
2974 .name = "imc", 2974 .name = "imc",
2975 .num_counters = 5, 2975 .num_counters = 4,
2976 .num_boxes = 8, 2976 .num_boxes = 8,
2977 .perf_ctr_bits = 48, 2977 .perf_ctr_bits = 48,
2978 .fixed_ctr_bits = 48, 2978 .fixed_ctr_bits = 48,
diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
index f5befd4945f2..124357773ffa 100644
--- a/arch/x86/include/asm/apic.h
+++ b/arch/x86/include/asm/apic.h
@@ -135,6 +135,7 @@ extern void init_apic_mappings(void);
135void register_lapic_address(unsigned long address); 135void register_lapic_address(unsigned long address);
136extern void setup_boot_APIC_clock(void); 136extern void setup_boot_APIC_clock(void);
137extern void setup_secondary_APIC_clock(void); 137extern void setup_secondary_APIC_clock(void);
138extern void lapic_update_tsc_freq(void);
138extern int APIC_init_uniprocessor(void); 139extern int APIC_init_uniprocessor(void);
139 140
140#ifdef CONFIG_X86_64 141#ifdef CONFIG_X86_64
@@ -170,6 +171,7 @@ static inline void init_apic_mappings(void) { }
170static inline void disable_local_APIC(void) { } 171static inline void disable_local_APIC(void) { }
171# define setup_boot_APIC_clock x86_init_noop 172# define setup_boot_APIC_clock x86_init_noop
172# define setup_secondary_APIC_clock x86_init_noop 173# define setup_secondary_APIC_clock x86_init_noop
174static inline void lapic_update_tsc_freq(void) { }
173#endif /* !CONFIG_X86_LOCAL_APIC */ 175#endif /* !CONFIG_X86_LOCAL_APIC */
174 176
175#ifdef CONFIG_X86_X2APIC 177#ifdef CONFIG_X86_X2APIC
diff --git a/arch/x86/include/asm/hardirq.h b/arch/x86/include/asm/hardirq.h
index 7178043b0e1d..59405a248fc2 100644
--- a/arch/x86/include/asm/hardirq.h
+++ b/arch/x86/include/asm/hardirq.h
@@ -22,10 +22,6 @@ typedef struct {
22#ifdef CONFIG_SMP 22#ifdef CONFIG_SMP
23 unsigned int irq_resched_count; 23 unsigned int irq_resched_count;
24 unsigned int irq_call_count; 24 unsigned int irq_call_count;
25 /*
26 * irq_tlb_count is double-counted in irq_call_count, so it must be
27 * subtracted from irq_call_count when displaying irq_call_count
28 */
29 unsigned int irq_tlb_count; 25 unsigned int irq_tlb_count;
30#endif 26#endif
31#ifdef CONFIG_X86_THERMAL_VECTOR 27#ifdef CONFIG_X86_THERMAL_VECTOR
diff --git a/arch/x86/include/asm/init.h b/arch/x86/include/asm/init.h
index 223042086f4e..737da62bfeb0 100644
--- a/arch/x86/include/asm/init.h
+++ b/arch/x86/include/asm/init.h
@@ -5,10 +5,10 @@ struct x86_mapping_info {
5 void *(*alloc_pgt_page)(void *); /* allocate buf for page table */ 5 void *(*alloc_pgt_page)(void *); /* allocate buf for page table */
6 void *context; /* context for alloc_pgt_page */ 6 void *context; /* context for alloc_pgt_page */
7 unsigned long pmd_flag; /* page flag for PMD entry */ 7 unsigned long pmd_flag; /* page flag for PMD entry */
8 bool kernel_mapping; /* kernel mapping or ident mapping */ 8 unsigned long offset; /* ident mapping offset */
9}; 9};
10 10
11int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_page, 11int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_page,
12 unsigned long addr, unsigned long end); 12 unsigned long pstart, unsigned long pend);
13 13
14#endif /* _ASM_X86_INIT_H */ 14#endif /* _ASM_X86_INIT_H */
diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
index 7e8ec7ae10fa..1cc82ece9ac1 100644
--- a/arch/x86/include/asm/pgtable_64.h
+++ b/arch/x86/include/asm/pgtable_64.h
@@ -145,7 +145,7 @@ static inline int pgd_large(pgd_t pgd) { return 0; }
145 * 145 *
146 * | ... | 11| 10| 9|8|7|6|5| 4| 3|2|1|0| <- bit number 146 * | ... | 11| 10| 9|8|7|6|5| 4| 3|2|1|0| <- bit number
147 * | ... |SW3|SW2|SW1|G|L|D|A|CD|WT|U|W|P| <- bit names 147 * | ... |SW3|SW2|SW1|G|L|D|A|CD|WT|U|W|P| <- bit names
148 * | OFFSET (14->63) | TYPE (10-13) |0|X|X|X| X| X|X|X|0| <- swp entry 148 * | OFFSET (14->63) | TYPE (9-13) |0|X|X|X| X| X|X|X|0| <- swp entry
149 * 149 *
150 * G (8) is aliased and used as a PROT_NONE indicator for 150 * G (8) is aliased and used as a PROT_NONE indicator for
151 * !present ptes. We need to start storing swap entries above 151 * !present ptes. We need to start storing swap entries above
@@ -156,7 +156,7 @@ static inline int pgd_large(pgd_t pgd) { return 0; }
156#define SWP_TYPE_FIRST_BIT (_PAGE_BIT_PROTNONE + 1) 156#define SWP_TYPE_FIRST_BIT (_PAGE_BIT_PROTNONE + 1)
157#define SWP_TYPE_BITS 5 157#define SWP_TYPE_BITS 5
158/* Place the offset above the type: */ 158/* Place the offset above the type: */
159#define SWP_OFFSET_FIRST_BIT (SWP_TYPE_FIRST_BIT + SWP_TYPE_BITS + 1) 159#define SWP_OFFSET_FIRST_BIT (SWP_TYPE_FIRST_BIT + SWP_TYPE_BITS)
160 160
161#define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS) 161#define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS)
162 162
diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
index 9c6b890d5e7a..b2988c0ed829 100644
--- a/arch/x86/include/asm/realmode.h
+++ b/arch/x86/include/asm/realmode.h
@@ -58,7 +58,15 @@ extern unsigned char boot_gdt[];
58extern unsigned char secondary_startup_64[]; 58extern unsigned char secondary_startup_64[];
59#endif 59#endif
60 60
61static inline size_t real_mode_size_needed(void)
62{
63 if (real_mode_header)
64 return 0; /* already allocated. */
65
66 return ALIGN(real_mode_blob_end - real_mode_blob, PAGE_SIZE);
67}
68
69void set_real_mode_mem(phys_addr_t mem, size_t size);
61void reserve_real_mode(void); 70void reserve_real_mode(void);
62void setup_real_mode(void);
63 71
64#endif /* _ARCH_X86_REALMODE_H */ 72#endif /* _ARCH_X86_REALMODE_H */
diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
index 4e5be94e079a..6fa85944af83 100644
--- a/arch/x86/include/asm/tlbflush.h
+++ b/arch/x86/include/asm/tlbflush.h
@@ -135,7 +135,14 @@ static inline void cr4_set_bits_and_update_boot(unsigned long mask)
135 135
136static inline void __native_flush_tlb(void) 136static inline void __native_flush_tlb(void)
137{ 137{
138 /*
139 * If current->mm == NULL then we borrow a mm which may change during a
140 * task switch and therefore we must not be preempted while we write CR3
141 * back:
142 */
143 preempt_disable();
138 native_write_cr3(native_read_cr3()); 144 native_write_cr3(native_read_cr3());
145 preempt_enable();
139} 146}
140 147
141static inline void __native_flush_tlb_global_irq_disabled(void) 148static inline void __native_flush_tlb_global_irq_disabled(void)
diff --git a/arch/x86/include/asm/uv/bios.h b/arch/x86/include/asm/uv/bios.h
index c852590254d5..e652a7cc6186 100644
--- a/arch/x86/include/asm/uv/bios.h
+++ b/arch/x86/include/asm/uv/bios.h
@@ -79,7 +79,7 @@ struct uv_gam_range_entry {
79 u16 nasid; /* HNasid */ 79 u16 nasid; /* HNasid */
80 u16 sockid; /* Socket ID, high bits of APIC ID */ 80 u16 sockid; /* Socket ID, high bits of APIC ID */
81 u16 pnode; /* Index to MMR and GRU spaces */ 81 u16 pnode; /* Index to MMR and GRU spaces */
82 u32 pxm; /* ACPI proximity domain number */ 82 u32 unused2;
83 u32 limit; /* PA bits 56:26 (UV_GAM_RANGE_SHFT) */ 83 u32 limit; /* PA bits 56:26 (UV_GAM_RANGE_SHFT) */
84}; 84};
85 85
@@ -88,7 +88,8 @@ struct uv_gam_range_entry {
88#define UV_SYSTAB_VERSION_UV4 0x400 /* UV4 BIOS base version */ 88#define UV_SYSTAB_VERSION_UV4 0x400 /* UV4 BIOS base version */
89#define UV_SYSTAB_VERSION_UV4_1 0x401 /* + gpa_shift */ 89#define UV_SYSTAB_VERSION_UV4_1 0x401 /* + gpa_shift */
90#define UV_SYSTAB_VERSION_UV4_2 0x402 /* + TYPE_NVRAM/WINDOW/MBOX */ 90#define UV_SYSTAB_VERSION_UV4_2 0x402 /* + TYPE_NVRAM/WINDOW/MBOX */
91#define UV_SYSTAB_VERSION_UV4_LATEST UV_SYSTAB_VERSION_UV4_2 91#define UV_SYSTAB_VERSION_UV4_3 0x403 /* - GAM Range PXM Value */
92#define UV_SYSTAB_VERSION_UV4_LATEST UV_SYSTAB_VERSION_UV4_3
92 93
93#define UV_SYSTAB_TYPE_UNUSED 0 /* End of table (offset == 0) */ 94#define UV_SYSTAB_TYPE_UNUSED 0 /* End of table (offset == 0) */
94#define UV_SYSTAB_TYPE_GAM_PARAMS 1 /* GAM PARAM conversions */ 95#define UV_SYSTAB_TYPE_GAM_PARAMS 1 /* GAM PARAM conversions */
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 20abd912f0e4..cea4fc19e844 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -313,7 +313,7 @@ int lapic_get_maxlvt(void)
313 313
314/* Clock divisor */ 314/* Clock divisor */
315#define APIC_DIVISOR 16 315#define APIC_DIVISOR 16
316#define TSC_DIVISOR 32 316#define TSC_DIVISOR 8
317 317
318/* 318/*
319 * This function sets up the local APIC timer, with a timeout of 319 * This function sets up the local APIC timer, with a timeout of
@@ -565,13 +565,37 @@ static void setup_APIC_timer(void)
565 CLOCK_EVT_FEAT_DUMMY); 565 CLOCK_EVT_FEAT_DUMMY);
566 levt->set_next_event = lapic_next_deadline; 566 levt->set_next_event = lapic_next_deadline;
567 clockevents_config_and_register(levt, 567 clockevents_config_and_register(levt,
568 (tsc_khz / TSC_DIVISOR) * 1000, 568 tsc_khz * (1000 / TSC_DIVISOR),
569 0xF, ~0UL); 569 0xF, ~0UL);
570 } else 570 } else
571 clockevents_register_device(levt); 571 clockevents_register_device(levt);
572} 572}
573 573
574/* 574/*
575 * Install the updated TSC frequency from recalibration at the TSC
576 * deadline clockevent devices.
577 */
578static void __lapic_update_tsc_freq(void *info)
579{
580 struct clock_event_device *levt = this_cpu_ptr(&lapic_events);
581
582 if (!this_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER))
583 return;
584
585 clockevents_update_freq(levt, tsc_khz * (1000 / TSC_DIVISOR));
586}
587
588void lapic_update_tsc_freq(void)
589{
590 /*
591 * The clockevent device's ->mult and ->shift can both be
592 * changed. In order to avoid races, schedule the frequency
593 * update code on each CPU.
594 */
595 on_each_cpu(__lapic_update_tsc_freq, NULL, 0);
596}
597
598/*
575 * In this functions we calibrate APIC bus clocks to the external timer. 599 * In this functions we calibrate APIC bus clocks to the external timer.
576 * 600 *
577 * We want to do the calibration only once since we want to have local timer 601 * We want to do the calibration only once since we want to have local timer
diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
index 6368fa69d2af..54f35d988025 100644
--- a/arch/x86/kernel/apic/x2apic_cluster.c
+++ b/arch/x86/kernel/apic/x2apic_cluster.c
@@ -155,7 +155,7 @@ static void init_x2apic_ldr(void)
155/* 155/*
156 * At CPU state changes, update the x2apic cluster sibling info. 156 * At CPU state changes, update the x2apic cluster sibling info.
157 */ 157 */
158int x2apic_prepare_cpu(unsigned int cpu) 158static int x2apic_prepare_cpu(unsigned int cpu)
159{ 159{
160 if (!zalloc_cpumask_var(&per_cpu(cpus_in_cluster, cpu), GFP_KERNEL)) 160 if (!zalloc_cpumask_var(&per_cpu(cpus_in_cluster, cpu), GFP_KERNEL))
161 return -ENOMEM; 161 return -ENOMEM;
@@ -168,7 +168,7 @@ int x2apic_prepare_cpu(unsigned int cpu)
168 return 0; 168 return 0;
169} 169}
170 170
171int x2apic_dead_cpu(unsigned int this_cpu) 171static int x2apic_dead_cpu(unsigned int this_cpu)
172{ 172{
173 int cpu; 173 int cpu;
174 174
@@ -186,13 +186,18 @@ int x2apic_dead_cpu(unsigned int this_cpu)
186static int x2apic_cluster_probe(void) 186static int x2apic_cluster_probe(void)
187{ 187{
188 int cpu = smp_processor_id(); 188 int cpu = smp_processor_id();
189 int ret;
189 190
190 if (!x2apic_mode) 191 if (!x2apic_mode)
191 return 0; 192 return 0;
192 193
194 ret = cpuhp_setup_state(CPUHP_X2APIC_PREPARE, "X2APIC_PREPARE",
195 x2apic_prepare_cpu, x2apic_dead_cpu);
196 if (ret < 0) {
197 pr_err("Failed to register X2APIC_PREPARE\n");
198 return 0;
199 }
193 cpumask_set_cpu(cpu, per_cpu(cpus_in_cluster, cpu)); 200 cpumask_set_cpu(cpu, per_cpu(cpus_in_cluster, cpu));
194 cpuhp_setup_state(CPUHP_X2APIC_PREPARE, "X2APIC_PREPARE",
195 x2apic_prepare_cpu, x2apic_dead_cpu);
196 return 1; 201 return 1;
197} 202}
198 203
diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
index 09b59adaea3f..cb0673c1e940 100644
--- a/arch/x86/kernel/apic/x2apic_uv_x.c
+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
@@ -223,6 +223,11 @@ static int __init uv_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
223 if (strncmp(oem_id, "SGI", 3) != 0) 223 if (strncmp(oem_id, "SGI", 3) != 0)
224 return 0; 224 return 0;
225 225
226 if (numa_off) {
227 pr_err("UV: NUMA is off, disabling UV support\n");
228 return 0;
229 }
230
226 /* Setup early hub type field in uv_hub_info for Node 0 */ 231 /* Setup early hub type field in uv_hub_info for Node 0 */
227 uv_cpu_info->p_uv_hub_info = &uv_hub_info_node0; 232 uv_cpu_info->p_uv_hub_info = &uv_hub_info_node0;
228 233
@@ -325,7 +330,7 @@ static __init void build_uv_gr_table(void)
325 struct uv_gam_range_entry *gre = uv_gre_table; 330 struct uv_gam_range_entry *gre = uv_gre_table;
326 struct uv_gam_range_s *grt; 331 struct uv_gam_range_s *grt;
327 unsigned long last_limit = 0, ram_limit = 0; 332 unsigned long last_limit = 0, ram_limit = 0;
328 int bytes, i, sid, lsid = -1; 333 int bytes, i, sid, lsid = -1, indx = 0, lindx = -1;
329 334
330 if (!gre) 335 if (!gre)
331 return; 336 return;
@@ -356,11 +361,12 @@ static __init void build_uv_gr_table(void)
356 } 361 }
357 sid = gre->sockid - _min_socket; 362 sid = gre->sockid - _min_socket;
358 if (lsid < sid) { /* new range */ 363 if (lsid < sid) { /* new range */
359 grt = &_gr_table[sid]; 364 grt = &_gr_table[indx];
360 grt->base = lsid; 365 grt->base = lindx;
361 grt->nasid = gre->nasid; 366 grt->nasid = gre->nasid;
362 grt->limit = last_limit = gre->limit; 367 grt->limit = last_limit = gre->limit;
363 lsid = sid; 368 lsid = sid;
369 lindx = indx++;
364 continue; 370 continue;
365 } 371 }
366 if (lsid == sid && !ram_limit) { /* update range */ 372 if (lsid == sid && !ram_limit) { /* update range */
@@ -371,7 +377,7 @@ static __init void build_uv_gr_table(void)
371 } 377 }
372 if (!ram_limit) { /* non-contiguous ram range */ 378 if (!ram_limit) { /* non-contiguous ram range */
373 grt++; 379 grt++;
374 grt->base = sid - 1; 380 grt->base = lindx;
375 grt->nasid = gre->nasid; 381 grt->nasid = gre->nasid;
376 grt->limit = last_limit = gre->limit; 382 grt->limit = last_limit = gre->limit;
377 continue; 383 continue;
@@ -1155,19 +1161,18 @@ static void __init decode_gam_rng_tbl(unsigned long ptr)
1155 for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) { 1161 for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) {
1156 if (!index) { 1162 if (!index) {
1157 pr_info("UV: GAM Range Table...\n"); 1163 pr_info("UV: GAM Range Table...\n");
1158 pr_info("UV: # %20s %14s %5s %4s %5s %3s %2s %3s\n", 1164 pr_info("UV: # %20s %14s %5s %4s %5s %3s %2s\n",
1159 "Range", "", "Size", "Type", "NASID", 1165 "Range", "", "Size", "Type", "NASID",
1160 "SID", "PN", "PXM"); 1166 "SID", "PN");
1161 } 1167 }
1162 pr_info( 1168 pr_info(
1163 "UV: %2d: 0x%014lx-0x%014lx %5luG %3d %04x %02x %02x %3d\n", 1169 "UV: %2d: 0x%014lx-0x%014lx %5luG %3d %04x %02x %02x\n",
1164 index++, 1170 index++,
1165 (unsigned long)lgre << UV_GAM_RANGE_SHFT, 1171 (unsigned long)lgre << UV_GAM_RANGE_SHFT,
1166 (unsigned long)gre->limit << UV_GAM_RANGE_SHFT, 1172 (unsigned long)gre->limit << UV_GAM_RANGE_SHFT,
1167 ((unsigned long)(gre->limit - lgre)) >> 1173 ((unsigned long)(gre->limit - lgre)) >>
1168 (30 - UV_GAM_RANGE_SHFT), /* 64M -> 1G */ 1174 (30 - UV_GAM_RANGE_SHFT), /* 64M -> 1G */
1169 gre->type, gre->nasid, gre->sockid, 1175 gre->type, gre->nasid, gre->sockid, gre->pnode);
1170 gre->pnode, gre->pxm);
1171 1176
1172 lgre = gre->limit; 1177 lgre = gre->limit;
1173 if (sock_min > gre->sockid) 1178 if (sock_min > gre->sockid)
@@ -1286,7 +1291,7 @@ static void __init build_socket_tables(void)
1286 _pnode_to_socket[i] = SOCK_EMPTY; 1291 _pnode_to_socket[i] = SOCK_EMPTY;
1287 1292
1288 /* fill in pnode/node/addr conversion list values */ 1293 /* fill in pnode/node/addr conversion list values */
1289 pr_info("UV: GAM Building socket/pnode/pxm conversion tables\n"); 1294 pr_info("UV: GAM Building socket/pnode conversion tables\n");
1290 for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) { 1295 for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) {
1291 if (gre->type == UV_GAM_RANGE_TYPE_HOLE) 1296 if (gre->type == UV_GAM_RANGE_TYPE_HOLE)
1292 continue; 1297 continue;
@@ -1294,20 +1299,18 @@ static void __init build_socket_tables(void)
1294 if (_socket_to_pnode[i] != SOCK_EMPTY) 1299 if (_socket_to_pnode[i] != SOCK_EMPTY)
1295 continue; /* duplicate */ 1300 continue; /* duplicate */
1296 _socket_to_pnode[i] = gre->pnode; 1301 _socket_to_pnode[i] = gre->pnode;
1297 _socket_to_node[i] = gre->pxm;
1298 1302
1299 i = gre->pnode - minpnode; 1303 i = gre->pnode - minpnode;
1300 _pnode_to_socket[i] = gre->sockid; 1304 _pnode_to_socket[i] = gre->sockid;
1301 1305
1302 pr_info( 1306 pr_info(
1303 "UV: sid:%02x type:%d nasid:%04x pn:%02x pxm:%2d pn2s:%2x\n", 1307 "UV: sid:%02x type:%d nasid:%04x pn:%02x pn2s:%2x\n",
1304 gre->sockid, gre->type, gre->nasid, 1308 gre->sockid, gre->type, gre->nasid,
1305 _socket_to_pnode[gre->sockid - minsock], 1309 _socket_to_pnode[gre->sockid - minsock],
1306 _socket_to_node[gre->sockid - minsock],
1307 _pnode_to_socket[gre->pnode - minpnode]); 1310 _pnode_to_socket[gre->pnode - minpnode]);
1308 } 1311 }
1309 1312
1310 /* check socket -> node values */ 1313 /* Set socket -> node values */
1311 lnid = -1; 1314 lnid = -1;
1312 for_each_present_cpu(cpu) { 1315 for_each_present_cpu(cpu) {
1313 int nid = cpu_to_node(cpu); 1316 int nid = cpu_to_node(cpu);
@@ -1318,14 +1321,9 @@ static void __init build_socket_tables(void)
1318 lnid = nid; 1321 lnid = nid;
1319 apicid = per_cpu(x86_cpu_to_apicid, cpu); 1322 apicid = per_cpu(x86_cpu_to_apicid, cpu);
1320 sockid = apicid >> uv_cpuid.socketid_shift; 1323 sockid = apicid >> uv_cpuid.socketid_shift;
1321 i = sockid - minsock; 1324 _socket_to_node[sockid - minsock] = nid;
1322 1325 pr_info("UV: sid:%02x: apicid:%04x node:%2d\n",
1323 if (nid != _socket_to_node[i]) { 1326 sockid, apicid, nid);
1324 pr_warn(
1325 "UV: %02x: type:%d socket:%02x PXM:%02x != node:%2d\n",
1326 i, sockid, gre->type, _socket_to_node[i], nid);
1327 _socket_to_node[i] = nid;
1328 }
1329 } 1327 }
1330 1328
1331 /* Setup physical blade to pnode translation from GAM Range Table */ 1329 /* Setup physical blade to pnode translation from GAM Range Table */
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 680049aa4593..01567aa87503 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -866,105 +866,17 @@ const void *get_xsave_field_ptr(int xsave_state)
866 return get_xsave_addr(&fpu->state.xsave, xsave_state); 866 return get_xsave_addr(&fpu->state.xsave, xsave_state);
867} 867}
868 868
869
870/*
871 * Set xfeatures (aka XSTATE_BV) bit for a feature that we want
872 * to take out of its "init state". This will ensure that an
873 * XRSTOR actually restores the state.
874 */
875static void fpu__xfeature_set_non_init(struct xregs_state *xsave,
876 int xstate_feature_mask)
877{
878 xsave->header.xfeatures |= xstate_feature_mask;
879}
880
881/*
882 * This function is safe to call whether the FPU is in use or not.
883 *
884 * Note that this only works on the current task.
885 *
886 * Inputs:
887 * @xsave_state: state which is defined in xsave.h (e.g. XFEATURE_MASK_FP,
888 * XFEATURE_MASK_SSE, etc...)
889 * @xsave_state_ptr: a pointer to a copy of the state that you would
890 * like written in to the current task's FPU xsave state. This pointer
891 * must not be located in the current tasks's xsave area.
892 * Output:
893 * address of the state in the xsave area or NULL if the state
894 * is not present or is in its 'init state'.
895 */
896static void fpu__xfeature_set_state(int xstate_feature_mask,
897 void *xstate_feature_src, size_t len)
898{
899 struct xregs_state *xsave = &current->thread.fpu.state.xsave;
900 struct fpu *fpu = &current->thread.fpu;
901 void *dst;
902
903 if (!boot_cpu_has(X86_FEATURE_XSAVE)) {
904 WARN_ONCE(1, "%s() attempted with no xsave support", __func__);
905 return;
906 }
907
908 /*
909 * Tell the FPU code that we need the FPU state to be in
910 * 'fpu' (not in the registers), and that we need it to
911 * be stable while we write to it.
912 */
913 fpu__current_fpstate_write_begin();
914
915 /*
916 * This method *WILL* *NOT* work for compact-format
917 * buffers. If the 'xstate_feature_mask' is unset in
918 * xcomp_bv then we may need to move other feature state
919 * "up" in the buffer.
920 */
921 if (xsave->header.xcomp_bv & xstate_feature_mask) {
922 WARN_ON_ONCE(1);
923 goto out;
924 }
925
926 /* find the location in the xsave buffer of the desired state */
927 dst = __raw_xsave_addr(&fpu->state.xsave, xstate_feature_mask);
928
929 /*
930 * Make sure that the pointer being passed in did not
931 * come from the xsave buffer itself.
932 */
933 WARN_ONCE(xstate_feature_src == dst, "set from xsave buffer itself");
934
935 /* put the caller-provided data in the location */
936 memcpy(dst, xstate_feature_src, len);
937
938 /*
939 * Mark the xfeature so that the CPU knows there is state
940 * in the buffer now.
941 */
942 fpu__xfeature_set_non_init(xsave, xstate_feature_mask);
943out:
944 /*
945 * We are done writing to the 'fpu'. Reenable preeption
946 * and (possibly) move the fpstate back in to the fpregs.
947 */
948 fpu__current_fpstate_write_end();
949}
950
951#define NR_VALID_PKRU_BITS (CONFIG_NR_PROTECTION_KEYS * 2) 869#define NR_VALID_PKRU_BITS (CONFIG_NR_PROTECTION_KEYS * 2)
952#define PKRU_VALID_MASK (NR_VALID_PKRU_BITS - 1) 870#define PKRU_VALID_MASK (NR_VALID_PKRU_BITS - 1)
953 871
954/* 872/*
955 * This will go out and modify the XSAVE buffer so that PKRU is 873 * This will go out and modify PKRU register to set the access
956 * set to a particular state for access to 'pkey'. 874 * rights for @pkey to @init_val.
957 *
958 * PKRU state does affect kernel access to user memory. We do
959 * not modfiy PKRU *itself* here, only the XSAVE state that will
960 * be restored in to PKRU when we return back to userspace.
961 */ 875 */
962int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, 876int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
963 unsigned long init_val) 877 unsigned long init_val)
964{ 878{
965 struct xregs_state *xsave = &tsk->thread.fpu.state.xsave; 879 u32 old_pkru;
966 struct pkru_state *old_pkru_state;
967 struct pkru_state new_pkru_state;
968 int pkey_shift = (pkey * PKRU_BITS_PER_PKEY); 880 int pkey_shift = (pkey * PKRU_BITS_PER_PKEY);
969 u32 new_pkru_bits = 0; 881 u32 new_pkru_bits = 0;
970 882
@@ -974,6 +886,15 @@ int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
974 */ 886 */
975 if (!boot_cpu_has(X86_FEATURE_OSPKE)) 887 if (!boot_cpu_has(X86_FEATURE_OSPKE))
976 return -EINVAL; 888 return -EINVAL;
889 /*
890 * For most XSAVE components, this would be an arduous task:
891 * brining fpstate up to date with fpregs, updating fpstate,
892 * then re-populating fpregs. But, for components that are
893 * never lazily managed, we can just access the fpregs
894 * directly. PKRU is never managed lazily, so we can just
895 * manipulate it directly. Make sure it stays that way.
896 */
897 WARN_ON_ONCE(!use_eager_fpu());
977 898
978 /* Set the bits we need in PKRU: */ 899 /* Set the bits we need in PKRU: */
979 if (init_val & PKEY_DISABLE_ACCESS) 900 if (init_val & PKEY_DISABLE_ACCESS)
@@ -984,37 +905,12 @@ int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
984 /* Shift the bits in to the correct place in PKRU for pkey: */ 905 /* Shift the bits in to the correct place in PKRU for pkey: */
985 new_pkru_bits <<= pkey_shift; 906 new_pkru_bits <<= pkey_shift;
986 907
987 /* Locate old copy of the state in the xsave buffer: */ 908 /* Get old PKRU and mask off any old bits in place: */
988 old_pkru_state = get_xsave_addr(xsave, XFEATURE_MASK_PKRU); 909 old_pkru = read_pkru();
989 910 old_pkru &= ~((PKRU_AD_BIT|PKRU_WD_BIT) << pkey_shift);
990 /*
991 * When state is not in the buffer, it is in the init
992 * state, set it manually. Otherwise, copy out the old
993 * state.
994 */
995 if (!old_pkru_state)
996 new_pkru_state.pkru = 0;
997 else
998 new_pkru_state.pkru = old_pkru_state->pkru;
999
1000 /* Mask off any old bits in place: */
1001 new_pkru_state.pkru &= ~((PKRU_AD_BIT|PKRU_WD_BIT) << pkey_shift);
1002
1003 /* Set the newly-requested bits: */
1004 new_pkru_state.pkru |= new_pkru_bits;
1005
1006 /*
1007 * We could theoretically live without zeroing pkru.pad.
1008 * The current XSAVE feature state definition says that
1009 * only bytes 0->3 are used. But we do not want to
1010 * chance leaking kernel stack out to userspace in case a
1011 * memcpy() of the whole xsave buffer was done.
1012 *
1013 * They're in the same cacheline anyway.
1014 */
1015 new_pkru_state.pad = 0;
1016 911
1017 fpu__xfeature_set_state(XFEATURE_MASK_PKRU, &new_pkru_state, sizeof(new_pkru_state)); 912 /* Write old part along with new part: */
913 write_pkru(old_pkru | new_pkru_bits);
1018 914
1019 return 0; 915 return 0;
1020} 916}
diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
index 2dda0bc4576e..f16c55bfc090 100644
--- a/arch/x86/kernel/head32.c
+++ b/arch/x86/kernel/head32.c
@@ -25,8 +25,6 @@ static void __init i386_default_early_setup(void)
25 /* Initialize 32bit specific setup functions */ 25 /* Initialize 32bit specific setup functions */
26 x86_init.resources.reserve_resources = i386_reserve_resources; 26 x86_init.resources.reserve_resources = i386_reserve_resources;
27 x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc; 27 x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
28
29 reserve_bios_regions();
30} 28}
31 29
32asmlinkage __visible void __init i386_start_kernel(void) 30asmlinkage __visible void __init i386_start_kernel(void)
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index 99d48e7d2974..54a2372f5dbb 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -183,7 +183,6 @@ void __init x86_64_start_reservations(char *real_mode_data)
183 copy_bootdata(__va(real_mode_data)); 183 copy_bootdata(__va(real_mode_data));
184 184
185 x86_early_init_platform_quirks(); 185 x86_early_init_platform_quirks();
186 reserve_bios_regions();
187 186
188 switch (boot_params.hdr.hardware_subarch) { 187 switch (boot_params.hdr.hardware_subarch) {
189 case X86_SUBARCH_INTEL_MID: 188 case X86_SUBARCH_INTEL_MID:
diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c
index ed16e58658a4..c6dfd801df97 100644
--- a/arch/x86/kernel/hpet.c
+++ b/arch/x86/kernel/hpet.c
@@ -1242,7 +1242,7 @@ irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id)
1242 memset(&curr_time, 0, sizeof(struct rtc_time)); 1242 memset(&curr_time, 0, sizeof(struct rtc_time));
1243 1243
1244 if (hpet_rtc_flags & (RTC_UIE | RTC_AIE)) 1244 if (hpet_rtc_flags & (RTC_UIE | RTC_AIE))
1245 mc146818_set_time(&curr_time); 1245 mc146818_get_time(&curr_time);
1246 1246
1247 if (hpet_rtc_flags & RTC_UIE && 1247 if (hpet_rtc_flags & RTC_UIE &&
1248 curr_time.tm_sec != hpet_prev_update_sec) { 1248 curr_time.tm_sec != hpet_prev_update_sec) {
diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
index 61521dc19c10..9f669fdd2010 100644
--- a/arch/x86/kernel/irq.c
+++ b/arch/x86/kernel/irq.c
@@ -102,8 +102,7 @@ int arch_show_interrupts(struct seq_file *p, int prec)
102 seq_puts(p, " Rescheduling interrupts\n"); 102 seq_puts(p, " Rescheduling interrupts\n");
103 seq_printf(p, "%*s: ", prec, "CAL"); 103 seq_printf(p, "%*s: ", prec, "CAL");
104 for_each_online_cpu(j) 104 for_each_online_cpu(j)
105 seq_printf(p, "%10u ", irq_stats(j)->irq_call_count - 105 seq_printf(p, "%10u ", irq_stats(j)->irq_call_count);
106 irq_stats(j)->irq_tlb_count);
107 seq_puts(p, " Function call interrupts\n"); 106 seq_puts(p, " Function call interrupts\n");
108 seq_printf(p, "%*s: ", prec, "TLB"); 107 seq_printf(p, "%*s: ", prec, "TLB");
109 for_each_online_cpu(j) 108 for_each_online_cpu(j)
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 991b77986d57..0fa60f5f5a16 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -936,8 +936,6 @@ void __init setup_arch(char **cmdline_p)
936 936
937 x86_init.oem.arch_setup(); 937 x86_init.oem.arch_setup();
938 938
939 kernel_randomize_memory();
940
941 iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1; 939 iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
942 setup_memory_map(); 940 setup_memory_map();
943 parse_setup_data(); 941 parse_setup_data();
@@ -1055,6 +1053,12 @@ void __init setup_arch(char **cmdline_p)
1055 1053
1056 max_possible_pfn = max_pfn; 1054 max_possible_pfn = max_pfn;
1057 1055
1056 /*
1057 * Define random base addresses for memory sections after max_pfn is
1058 * defined and before each memory section base is used.
1059 */
1060 kernel_randomize_memory();
1061
1058#ifdef CONFIG_X86_32 1062#ifdef CONFIG_X86_32
1059 /* max_low_pfn get updated here */ 1063 /* max_low_pfn get updated here */
1060 find_low_pfn_range(); 1064 find_low_pfn_range();
@@ -1097,6 +1101,8 @@ void __init setup_arch(char **cmdline_p)
1097 efi_find_mirror(); 1101 efi_find_mirror();
1098 } 1102 }
1099 1103
1104 reserve_bios_regions();
1105
1100 /* 1106 /*
1101 * The EFI specification says that boot service code won't be called 1107 * The EFI specification says that boot service code won't be called
1102 * after ExitBootServices(). This is, in fact, a lie. 1108 * after ExitBootServices(). This is, in fact, a lie.
@@ -1125,7 +1131,15 @@ void __init setup_arch(char **cmdline_p)
1125 1131
1126 early_trap_pf_init(); 1132 early_trap_pf_init();
1127 1133
1128 setup_real_mode(); 1134 /*
1135 * Update mmu_cr4_features (and, indirectly, trampoline_cr4_features)
1136 * with the current CR4 value. This may not be necessary, but
1137 * auditing all the early-boot CR4 manipulation would be needed to
1138 * rule it out.
1139 */
1140 if (boot_cpu_data.cpuid_level >= 0)
1141 /* A CPU has %cr4 if and only if it has CPUID. */
1142 mmu_cr4_features = __read_cr4();
1129 1143
1130 memblock_set_current_limit(get_max_mapped()); 1144 memblock_set_current_limit(get_max_mapped());
1131 1145
@@ -1174,13 +1188,6 @@ void __init setup_arch(char **cmdline_p)
1174 1188
1175 kasan_init(); 1189 kasan_init();
1176 1190
1177 if (boot_cpu_data.cpuid_level >= 0) {
1178 /* A CPU has %cr4 if and only if it has CPUID */
1179 mmu_cr4_features = __read_cr4();
1180 if (trampoline_cr4_features)
1181 *trampoline_cr4_features = mmu_cr4_features;
1182 }
1183
1184#ifdef CONFIG_X86_32 1191#ifdef CONFIG_X86_32
1185 /* sync back kernel address range */ 1192 /* sync back kernel address range */
1186 clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY, 1193 clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY,
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 1ef87e887051..78b9cb5a26af 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -22,6 +22,7 @@
22#include <asm/nmi.h> 22#include <asm/nmi.h>
23#include <asm/x86_init.h> 23#include <asm/x86_init.h>
24#include <asm/geode.h> 24#include <asm/geode.h>
25#include <asm/apic.h>
25 26
26unsigned int __read_mostly cpu_khz; /* TSC clocks / usec, not used here */ 27unsigned int __read_mostly cpu_khz; /* TSC clocks / usec, not used here */
27EXPORT_SYMBOL(cpu_khz); 28EXPORT_SYMBOL(cpu_khz);
@@ -1249,6 +1250,9 @@ static void tsc_refine_calibration_work(struct work_struct *work)
1249 (unsigned long)tsc_khz / 1000, 1250 (unsigned long)tsc_khz / 1000,
1250 (unsigned long)tsc_khz % 1000); 1251 (unsigned long)tsc_khz % 1000);
1251 1252
1253 /* Inform the TSC deadline clockevent devices about the recalibration */
1254 lapic_update_tsc_freq();
1255
1252out: 1256out:
1253 if (boot_cpu_has(X86_FEATURE_ART)) 1257 if (boot_cpu_has(X86_FEATURE_ART))
1254 art_related_clocksource = &clocksource_tsc; 1258 art_related_clocksource = &clocksource_tsc;
diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
index 6c1ff31d99ff..495c776de4b4 100644
--- a/arch/x86/kernel/uprobes.c
+++ b/arch/x86/kernel/uprobes.c
@@ -357,20 +357,22 @@ static void riprel_analyze(struct arch_uprobe *auprobe, struct insn *insn)
357 *cursor &= 0xfe; 357 *cursor &= 0xfe;
358 } 358 }
359 /* 359 /*
360 * Similar treatment for VEX3 prefix. 360 * Similar treatment for VEX3/EVEX prefix.
361 * TODO: add XOP/EVEX treatment when insn decoder supports them 361 * TODO: add XOP treatment when insn decoder supports them
362 */ 362 */
363 if (insn->vex_prefix.nbytes == 3) { 363 if (insn->vex_prefix.nbytes >= 3) {
364 /* 364 /*
365 * vex2: c5 rvvvvLpp (has no b bit) 365 * vex2: c5 rvvvvLpp (has no b bit)
366 * vex3/xop: c4/8f rxbmmmmm wvvvvLpp 366 * vex3/xop: c4/8f rxbmmmmm wvvvvLpp
367 * evex: 62 rxbR00mm wvvvv1pp zllBVaaa 367 * evex: 62 rxbR00mm wvvvv1pp zllBVaaa
368 * (evex will need setting of both b and x since 368 * Setting VEX3.b (setting because it has inverted meaning).
369 * in non-sib encoding evex.x is 4th bit of MODRM.rm) 369 * Setting EVEX.x since (in non-SIB encoding) EVEX.x
370 * Setting VEX3.b (setting because it has inverted meaning): 370 * is the 4th bit of MODRM.rm, and needs the same treatment.
371 * For VEX3-encoded insns, VEX3.x value has no effect in
372 * non-SIB encoding, the change is superfluous but harmless.
371 */ 373 */
372 cursor = auprobe->insn + insn_offset_vex_prefix(insn) + 1; 374 cursor = auprobe->insn + insn_offset_vex_prefix(insn) + 1;
373 *cursor |= 0x20; 375 *cursor |= 0x60;
374 } 376 }
375 377
376 /* 378 /*
@@ -415,12 +417,10 @@ static void riprel_analyze(struct arch_uprobe *auprobe, struct insn *insn)
415 417
416 reg = MODRM_REG(insn); /* Fetch modrm.reg */ 418 reg = MODRM_REG(insn); /* Fetch modrm.reg */
417 reg2 = 0xff; /* Fetch vex.vvvv */ 419 reg2 = 0xff; /* Fetch vex.vvvv */
418 if (insn->vex_prefix.nbytes == 2) 420 if (insn->vex_prefix.nbytes)
419 reg2 = insn->vex_prefix.bytes[1];
420 else if (insn->vex_prefix.nbytes == 3)
421 reg2 = insn->vex_prefix.bytes[2]; 421 reg2 = insn->vex_prefix.bytes[2];
422 /* 422 /*
423 * TODO: add XOP, EXEV vvvv reading. 423 * TODO: add XOP vvvv reading.
424 * 424 *
425 * vex.vvvv field is in bits 6-3, bits are inverted. 425 * vex.vvvv field is in bits 6-3, bits are inverted.
426 * But in 32-bit mode, high-order bit may be ignored. 426 * But in 32-bit mode, high-order bit may be ignored.
diff --git a/arch/x86/lib/kaslr.c b/arch/x86/lib/kaslr.c
index f7dfeda83e5c..121f59c6ee54 100644
--- a/arch/x86/lib/kaslr.c
+++ b/arch/x86/lib/kaslr.c
@@ -19,7 +19,7 @@
19#include <asm/cpufeature.h> 19#include <asm/cpufeature.h>
20#include <asm/setup.h> 20#include <asm/setup.h>
21 21
22#define debug_putstr(v) early_printk(v) 22#define debug_putstr(v) early_printk("%s", v)
23#define has_cpuflag(f) boot_cpu_has(f) 23#define has_cpuflag(f) boot_cpu_has(f)
24#define get_boot_seed() kaslr_offset() 24#define get_boot_seed() kaslr_offset()
25#endif 25#endif
diff --git a/arch/x86/mm/ident_map.c b/arch/x86/mm/ident_map.c
index ec21796ac5fd..4473cb4f8b90 100644
--- a/arch/x86/mm/ident_map.c
+++ b/arch/x86/mm/ident_map.c
@@ -3,15 +3,17 @@
3 * included by both the compressed kernel and the regular kernel. 3 * included by both the compressed kernel and the regular kernel.
4 */ 4 */
5 5
6static void ident_pmd_init(unsigned long pmd_flag, pmd_t *pmd_page, 6static void ident_pmd_init(struct x86_mapping_info *info, pmd_t *pmd_page,
7 unsigned long addr, unsigned long end) 7 unsigned long addr, unsigned long end)
8{ 8{
9 addr &= PMD_MASK; 9 addr &= PMD_MASK;
10 for (; addr < end; addr += PMD_SIZE) { 10 for (; addr < end; addr += PMD_SIZE) {
11 pmd_t *pmd = pmd_page + pmd_index(addr); 11 pmd_t *pmd = pmd_page + pmd_index(addr);
12 12
13 if (!pmd_present(*pmd)) 13 if (pmd_present(*pmd))
14 set_pmd(pmd, __pmd(addr | pmd_flag)); 14 continue;
15
16 set_pmd(pmd, __pmd((addr - info->offset) | info->pmd_flag));
15 } 17 }
16} 18}
17 19
@@ -30,13 +32,13 @@ static int ident_pud_init(struct x86_mapping_info *info, pud_t *pud_page,
30 32
31 if (pud_present(*pud)) { 33 if (pud_present(*pud)) {
32 pmd = pmd_offset(pud, 0); 34 pmd = pmd_offset(pud, 0);
33 ident_pmd_init(info->pmd_flag, pmd, addr, next); 35 ident_pmd_init(info, pmd, addr, next);
34 continue; 36 continue;
35 } 37 }
36 pmd = (pmd_t *)info->alloc_pgt_page(info->context); 38 pmd = (pmd_t *)info->alloc_pgt_page(info->context);
37 if (!pmd) 39 if (!pmd)
38 return -ENOMEM; 40 return -ENOMEM;
39 ident_pmd_init(info->pmd_flag, pmd, addr, next); 41 ident_pmd_init(info, pmd, addr, next);
40 set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE)); 42 set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE));
41 } 43 }
42 44
@@ -44,14 +46,15 @@ static int ident_pud_init(struct x86_mapping_info *info, pud_t *pud_page,
44} 46}
45 47
46int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_page, 48int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_page,
47 unsigned long addr, unsigned long end) 49 unsigned long pstart, unsigned long pend)
48{ 50{
51 unsigned long addr = pstart + info->offset;
52 unsigned long end = pend + info->offset;
49 unsigned long next; 53 unsigned long next;
50 int result; 54 int result;
51 int off = info->kernel_mapping ? pgd_index(__PAGE_OFFSET) : 0;
52 55
53 for (; addr < end; addr = next) { 56 for (; addr < end; addr = next) {
54 pgd_t *pgd = pgd_page + pgd_index(addr) + off; 57 pgd_t *pgd = pgd_page + pgd_index(addr);
55 pud_t *pud; 58 pud_t *pud;
56 59
57 next = (addr & PGDIR_MASK) + PGDIR_SIZE; 60 next = (addr & PGDIR_MASK) + PGDIR_SIZE;
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 620928903be3..d28a2d741f9e 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -122,8 +122,18 @@ __ref void *alloc_low_pages(unsigned int num)
122 return __va(pfn << PAGE_SHIFT); 122 return __va(pfn << PAGE_SHIFT);
123} 123}
124 124
125/* need 3 4k for initial PMD_SIZE, 3 4k for 0-ISA_END_ADDRESS */ 125/*
126#define INIT_PGT_BUF_SIZE (6 * PAGE_SIZE) 126 * By default need 3 4k for initial PMD_SIZE, 3 4k for 0-ISA_END_ADDRESS.
127 * With KASLR memory randomization, depending on the machine e820 memory
128 * and the PUD alignment. We may need twice more pages when KASLR memory
129 * randomization is enabled.
130 */
131#ifndef CONFIG_RANDOMIZE_MEMORY
132#define INIT_PGD_PAGE_COUNT 6
133#else
134#define INIT_PGD_PAGE_COUNT 12
135#endif
136#define INIT_PGT_BUF_SIZE (INIT_PGD_PAGE_COUNT * PAGE_SIZE)
127RESERVE_BRK(early_pgt_alloc, INIT_PGT_BUF_SIZE); 137RESERVE_BRK(early_pgt_alloc, INIT_PGT_BUF_SIZE);
128void __init early_alloc_pgt_buf(void) 138void __init early_alloc_pgt_buf(void)
129{ 139{
diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c
index 26dccd6c0df1..ec8654f117d8 100644
--- a/arch/x86/mm/kaslr.c
+++ b/arch/x86/mm/kaslr.c
@@ -97,7 +97,7 @@ void __init kernel_randomize_memory(void)
97 * add padding if needed (especially for memory hotplug support). 97 * add padding if needed (especially for memory hotplug support).
98 */ 98 */
99 BUG_ON(kaslr_regions[0].base != &page_offset_base); 99 BUG_ON(kaslr_regions[0].base != &page_offset_base);
100 memory_tb = ((max_pfn << PAGE_SHIFT) >> TB_SHIFT) + 100 memory_tb = DIV_ROUND_UP(max_pfn << PAGE_SHIFT, 1UL << TB_SHIFT) +
101 CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING; 101 CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING;
102 102
103 /* Adapt phyiscal memory region size based on available memory */ 103 /* Adapt phyiscal memory region size based on available memory */
diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index 4480c06cade7..89d1146f5a6f 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -254,6 +254,7 @@ void __init efi_free_boot_services(void)
254 for_each_efi_memory_desc(md) { 254 for_each_efi_memory_desc(md) {
255 unsigned long long start = md->phys_addr; 255 unsigned long long start = md->phys_addr;
256 unsigned long long size = md->num_pages << EFI_PAGE_SHIFT; 256 unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
257 size_t rm_size;
257 258
258 if (md->type != EFI_BOOT_SERVICES_CODE && 259 if (md->type != EFI_BOOT_SERVICES_CODE &&
259 md->type != EFI_BOOT_SERVICES_DATA) 260 md->type != EFI_BOOT_SERVICES_DATA)
@@ -263,6 +264,26 @@ void __init efi_free_boot_services(void)
263 if (md->attribute & EFI_MEMORY_RUNTIME) 264 if (md->attribute & EFI_MEMORY_RUNTIME)
264 continue; 265 continue;
265 266
267 /*
268 * Nasty quirk: if all sub-1MB memory is used for boot
269 * services, we can get here without having allocated the
270 * real mode trampoline. It's too late to hand boot services
271 * memory back to the memblock allocator, so instead
272 * try to manually allocate the trampoline if needed.
273 *
274 * I've seen this on a Dell XPS 13 9350 with firmware
275 * 1.4.4 with SGX enabled booting Linux via Fedora 24's
276 * grub2-efi on a hard disk. (And no, I don't know why
277 * this happened, but Linux should still try to boot rather
278 * panicing early.)
279 */
280 rm_size = real_mode_size_needed();
281 if (rm_size && (start + rm_size) < (1<<20) && size >= rm_size) {
282 set_real_mode_mem(start, rm_size);
283 start += rm_size;
284 size -= rm_size;
285 }
286
266 free_bootmem_late(start, size); 287 free_bootmem_late(start, size);
267 } 288 }
268 289
diff --git a/arch/x86/platform/uv/bios_uv.c b/arch/x86/platform/uv/bios_uv.c
index 66b2166ea4a1..23f2f3e41c7f 100644
--- a/arch/x86/platform/uv/bios_uv.c
+++ b/arch/x86/platform/uv/bios_uv.c
@@ -187,7 +187,8 @@ EXPORT_SYMBOL_GPL(uv_bios_set_legacy_vga_target);
187void uv_bios_init(void) 187void uv_bios_init(void)
188{ 188{
189 uv_systab = NULL; 189 uv_systab = NULL;
190 if ((efi.uv_systab == EFI_INVALID_TABLE_ADDR) || !efi.uv_systab) { 190 if ((efi.uv_systab == EFI_INVALID_TABLE_ADDR) ||
191 !efi.uv_systab || efi_runtime_disabled()) {
191 pr_crit("UV: UVsystab: missing\n"); 192 pr_crit("UV: UVsystab: missing\n");
192 return; 193 return;
193 } 194 }
@@ -199,12 +200,14 @@ void uv_bios_init(void)
199 return; 200 return;
200 } 201 }
201 202
203 /* Starting with UV4 the UV systab size is variable */
202 if (uv_systab->revision >= UV_SYSTAB_VERSION_UV4) { 204 if (uv_systab->revision >= UV_SYSTAB_VERSION_UV4) {
205 int size = uv_systab->size;
206
203 iounmap(uv_systab); 207 iounmap(uv_systab);
204 uv_systab = ioremap(efi.uv_systab, uv_systab->size); 208 uv_systab = ioremap(efi.uv_systab, size);
205 if (!uv_systab) { 209 if (!uv_systab) {
206 pr_err("UV: UVsystab: ioremap(%d) failed!\n", 210 pr_err("UV: UVsystab: ioremap(%d) failed!\n", size);
207 uv_systab->size);
208 return; 211 return;
209 } 212 }
210 } 213 }
diff --git a/arch/x86/power/hibernate_64.c b/arch/x86/power/hibernate_64.c
index f0b5f2d402af..a3e3ccc87138 100644
--- a/arch/x86/power/hibernate_64.c
+++ b/arch/x86/power/hibernate_64.c
@@ -87,7 +87,7 @@ static int set_up_temporary_mappings(void)
87 struct x86_mapping_info info = { 87 struct x86_mapping_info info = {
88 .alloc_pgt_page = alloc_pgt_page, 88 .alloc_pgt_page = alloc_pgt_page,
89 .pmd_flag = __PAGE_KERNEL_LARGE_EXEC, 89 .pmd_flag = __PAGE_KERNEL_LARGE_EXEC,
90 .kernel_mapping = true, 90 .offset = __PAGE_OFFSET,
91 }; 91 };
92 unsigned long mstart, mend; 92 unsigned long mstart, mend;
93 pgd_t *pgd; 93 pgd_t *pgd;
diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
index 705e3fffb4a1..5db706f14111 100644
--- a/arch/x86/realmode/init.c
+++ b/arch/x86/realmode/init.c
@@ -1,9 +1,11 @@
1#include <linux/io.h> 1#include <linux/io.h>
2#include <linux/slab.h>
2#include <linux/memblock.h> 3#include <linux/memblock.h>
3 4
4#include <asm/cacheflush.h> 5#include <asm/cacheflush.h>
5#include <asm/pgtable.h> 6#include <asm/pgtable.h>
6#include <asm/realmode.h> 7#include <asm/realmode.h>
8#include <asm/tlbflush.h>
7 9
8struct real_mode_header *real_mode_header; 10struct real_mode_header *real_mode_header;
9u32 *trampoline_cr4_features; 11u32 *trampoline_cr4_features;
@@ -11,25 +13,37 @@ u32 *trampoline_cr4_features;
11/* Hold the pgd entry used on booting additional CPUs */ 13/* Hold the pgd entry used on booting additional CPUs */
12pgd_t trampoline_pgd_entry; 14pgd_t trampoline_pgd_entry;
13 15
16void __init set_real_mode_mem(phys_addr_t mem, size_t size)
17{
18 void *base = __va(mem);
19
20 real_mode_header = (struct real_mode_header *) base;
21 printk(KERN_DEBUG "Base memory trampoline at [%p] %llx size %zu\n",
22 base, (unsigned long long)mem, size);
23}
24
14void __init reserve_real_mode(void) 25void __init reserve_real_mode(void)
15{ 26{
16 phys_addr_t mem; 27 phys_addr_t mem;
17 unsigned char *base; 28 size_t size = real_mode_size_needed();
18 size_t size = PAGE_ALIGN(real_mode_blob_end - real_mode_blob); 29
30 if (!size)
31 return;
32
33 WARN_ON(slab_is_available());
19 34
20 /* Has to be under 1M so we can execute real-mode AP code. */ 35 /* Has to be under 1M so we can execute real-mode AP code. */
21 mem = memblock_find_in_range(0, 1<<20, size, PAGE_SIZE); 36 mem = memblock_find_in_range(0, 1<<20, size, PAGE_SIZE);
22 if (!mem) 37 if (!mem) {
23 panic("Cannot allocate trampoline\n"); 38 pr_info("No sub-1M memory is available for the trampoline\n");
39 return;
40 }
24 41
25 base = __va(mem);
26 memblock_reserve(mem, size); 42 memblock_reserve(mem, size);
27 real_mode_header = (struct real_mode_header *) base; 43 set_real_mode_mem(mem, size);
28 printk(KERN_DEBUG "Base memory trampoline at [%p] %llx size %zu\n",
29 base, (unsigned long long)mem, size);
30} 44}
31 45
32void __init setup_real_mode(void) 46static void __init setup_real_mode(void)
33{ 47{
34 u16 real_mode_seg; 48 u16 real_mode_seg;
35 const u32 *rel; 49 const u32 *rel;
@@ -84,7 +98,7 @@ void __init setup_real_mode(void)
84 98
85 trampoline_header->start = (u64) secondary_startup_64; 99 trampoline_header->start = (u64) secondary_startup_64;
86 trampoline_cr4_features = &trampoline_header->cr4; 100 trampoline_cr4_features = &trampoline_header->cr4;
87 *trampoline_cr4_features = __read_cr4(); 101 *trampoline_cr4_features = mmu_cr4_features;
88 102
89 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd); 103 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
90 trampoline_pgd[0] = trampoline_pgd_entry.pgd; 104 trampoline_pgd[0] = trampoline_pgd_entry.pgd;
@@ -100,7 +114,7 @@ void __init setup_real_mode(void)
100 * need to mark it executable at do_pre_smp_initcalls() at least, 114 * need to mark it executable at do_pre_smp_initcalls() at least,
101 * thus run it as a early_initcall(). 115 * thus run it as a early_initcall().
102 */ 116 */
103static int __init set_real_mode_permissions(void) 117static void __init set_real_mode_permissions(void)
104{ 118{
105 unsigned char *base = (unsigned char *) real_mode_header; 119 unsigned char *base = (unsigned char *) real_mode_header;
106 size_t size = PAGE_ALIGN(real_mode_blob_end - real_mode_blob); 120 size_t size = PAGE_ALIGN(real_mode_blob_end - real_mode_blob);
@@ -119,7 +133,16 @@ static int __init set_real_mode_permissions(void)
119 set_memory_nx((unsigned long) base, size >> PAGE_SHIFT); 133 set_memory_nx((unsigned long) base, size >> PAGE_SHIFT);
120 set_memory_ro((unsigned long) base, ro_size >> PAGE_SHIFT); 134 set_memory_ro((unsigned long) base, ro_size >> PAGE_SHIFT);
121 set_memory_x((unsigned long) text_start, text_size >> PAGE_SHIFT); 135 set_memory_x((unsigned long) text_start, text_size >> PAGE_SHIFT);
136}
137
138static int __init init_real_mode(void)
139{
140 if (!real_mode_header)
141 panic("Real mode trampoline was not allocated");
142
143 setup_real_mode();
144 set_real_mode_permissions();
122 145
123 return 0; 146 return 0;
124} 147}
125early_initcall(set_real_mode_permissions); 148early_initcall(init_real_mode);
diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
index 8c234dd9b8bc..80cc7c089a15 100644
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -1527,11 +1527,12 @@ static u32 read_blk_stat(struct nfit_blk *nfit_blk, unsigned int bw)
1527{ 1527{
1528 struct nfit_blk_mmio *mmio = &nfit_blk->mmio[DCR]; 1528 struct nfit_blk_mmio *mmio = &nfit_blk->mmio[DCR];
1529 u64 offset = nfit_blk->stat_offset + mmio->size * bw; 1529 u64 offset = nfit_blk->stat_offset + mmio->size * bw;
1530 const u32 STATUS_MASK = 0x80000037;
1530 1531
1531 if (mmio->num_lines) 1532 if (mmio->num_lines)
1532 offset = to_interleave_offset(offset, mmio); 1533 offset = to_interleave_offset(offset, mmio);
1533 1534
1534 return readl(mmio->addr.base + offset); 1535 return readl(mmio->addr.base + offset) & STATUS_MASK;
1535} 1536}
1536 1537
1537static void write_blk_ctl(struct nfit_blk *nfit_blk, unsigned int bw, 1538static void write_blk_ctl(struct nfit_blk *nfit_blk, unsigned int bw,
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 1a04af6d2421..6c6519f6492a 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -3950,6 +3950,7 @@ static void rbd_dev_release(struct device *dev)
3950 bool need_put = !!rbd_dev->opts; 3950 bool need_put = !!rbd_dev->opts;
3951 3951
3952 ceph_oid_destroy(&rbd_dev->header_oid); 3952 ceph_oid_destroy(&rbd_dev->header_oid);
3953 ceph_oloc_destroy(&rbd_dev->header_oloc);
3953 3954
3954 rbd_put_client(rbd_dev->rbd_client); 3955 rbd_put_client(rbd_dev->rbd_client);
3955 rbd_spec_put(rbd_dev->spec); 3956 rbd_spec_put(rbd_dev->spec);
@@ -5336,15 +5337,6 @@ static ssize_t do_rbd_add(struct bus_type *bus,
5336 } 5337 }
5337 spec->pool_id = (u64)rc; 5338 spec->pool_id = (u64)rc;
5338 5339
5339 /* The ceph file layout needs to fit pool id in 32 bits */
5340
5341 if (spec->pool_id > (u64)U32_MAX) {
5342 rbd_warn(NULL, "pool id too large (%llu > %u)",
5343 (unsigned long long)spec->pool_id, U32_MAX);
5344 rc = -EIO;
5345 goto err_out_client;
5346 }
5347
5348 rbd_dev = rbd_dev_create(rbdc, spec, rbd_opts); 5340 rbd_dev = rbd_dev_create(rbdc, spec, rbd_opts);
5349 if (!rbd_dev) { 5341 if (!rbd_dev) {
5350 rc = -ENOMEM; 5342 rc = -ENOMEM;
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 1523e05c46fc..93b1aaa5ba3b 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -391,22 +391,16 @@ static int init_vq(struct virtio_blk *vblk)
391 num_vqs = 1; 391 num_vqs = 1;
392 392
393 vblk->vqs = kmalloc(sizeof(*vblk->vqs) * num_vqs, GFP_KERNEL); 393 vblk->vqs = kmalloc(sizeof(*vblk->vqs) * num_vqs, GFP_KERNEL);
394 if (!vblk->vqs) { 394 if (!vblk->vqs)
395 err = -ENOMEM; 395 return -ENOMEM;
396 goto out;
397 }
398 396
399 names = kmalloc(sizeof(*names) * num_vqs, GFP_KERNEL); 397 names = kmalloc(sizeof(*names) * num_vqs, GFP_KERNEL);
400 if (!names)
401 goto err_names;
402
403 callbacks = kmalloc(sizeof(*callbacks) * num_vqs, GFP_KERNEL); 398 callbacks = kmalloc(sizeof(*callbacks) * num_vqs, GFP_KERNEL);
404 if (!callbacks)
405 goto err_callbacks;
406
407 vqs = kmalloc(sizeof(*vqs) * num_vqs, GFP_KERNEL); 399 vqs = kmalloc(sizeof(*vqs) * num_vqs, GFP_KERNEL);
408 if (!vqs) 400 if (!names || !callbacks || !vqs) {
409 goto err_vqs; 401 err = -ENOMEM;
402 goto out;
403 }
410 404
411 for (i = 0; i < num_vqs; i++) { 405 for (i = 0; i < num_vqs; i++) {
412 callbacks[i] = virtblk_done; 406 callbacks[i] = virtblk_done;
@@ -417,7 +411,7 @@ static int init_vq(struct virtio_blk *vblk)
417 /* Discover virtqueues and write information to configuration. */ 411 /* Discover virtqueues and write information to configuration. */
418 err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names); 412 err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names);
419 if (err) 413 if (err)
420 goto err_find_vqs; 414 goto out;
421 415
422 for (i = 0; i < num_vqs; i++) { 416 for (i = 0; i < num_vqs; i++) {
423 spin_lock_init(&vblk->vqs[i].lock); 417 spin_lock_init(&vblk->vqs[i].lock);
@@ -425,16 +419,12 @@ static int init_vq(struct virtio_blk *vblk)
425 } 419 }
426 vblk->num_vqs = num_vqs; 420 vblk->num_vqs = num_vqs;
427 421
428 err_find_vqs: 422out:
429 kfree(vqs); 423 kfree(vqs);
430 err_vqs:
431 kfree(callbacks); 424 kfree(callbacks);
432 err_callbacks:
433 kfree(names); 425 kfree(names);
434 err_names:
435 if (err) 426 if (err)
436 kfree(vblk->vqs); 427 kfree(vblk->vqs);
437 out:
438 return err; 428 return err;
439} 429}
440 430
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 28bce3f4f81d..57700541f951 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -8,6 +8,9 @@
8 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11
12#define pr_fmt(fmt) "arm_arch_timer: " fmt
13
11#include <linux/init.h> 14#include <linux/init.h>
12#include <linux/kernel.h> 15#include <linux/kernel.h>
13#include <linux/device.h> 16#include <linux/device.h>
@@ -370,16 +373,33 @@ static bool arch_timer_has_nonsecure_ppi(void)
370 arch_timer_ppi[PHYS_NONSECURE_PPI]); 373 arch_timer_ppi[PHYS_NONSECURE_PPI]);
371} 374}
372 375
376static u32 check_ppi_trigger(int irq)
377{
378 u32 flags = irq_get_trigger_type(irq);
379
380 if (flags != IRQF_TRIGGER_HIGH && flags != IRQF_TRIGGER_LOW) {
381 pr_warn("WARNING: Invalid trigger for IRQ%d, assuming level low\n", irq);
382 pr_warn("WARNING: Please fix your firmware\n");
383 flags = IRQF_TRIGGER_LOW;
384 }
385
386 return flags;
387}
388
373static int arch_timer_starting_cpu(unsigned int cpu) 389static int arch_timer_starting_cpu(unsigned int cpu)
374{ 390{
375 struct clock_event_device *clk = this_cpu_ptr(arch_timer_evt); 391 struct clock_event_device *clk = this_cpu_ptr(arch_timer_evt);
392 u32 flags;
376 393
377 __arch_timer_setup(ARCH_CP15_TIMER, clk); 394 __arch_timer_setup(ARCH_CP15_TIMER, clk);
378 395
379 enable_percpu_irq(arch_timer_ppi[arch_timer_uses_ppi], 0); 396 flags = check_ppi_trigger(arch_timer_ppi[arch_timer_uses_ppi]);
397 enable_percpu_irq(arch_timer_ppi[arch_timer_uses_ppi], flags);
380 398
381 if (arch_timer_has_nonsecure_ppi()) 399 if (arch_timer_has_nonsecure_ppi()) {
382 enable_percpu_irq(arch_timer_ppi[PHYS_NONSECURE_PPI], 0); 400 flags = check_ppi_trigger(arch_timer_ppi[PHYS_NONSECURE_PPI]);
401 enable_percpu_irq(arch_timer_ppi[PHYS_NONSECURE_PPI], flags);
402 }
383 403
384 arch_counter_set_user_access(); 404 arch_counter_set_user_access();
385 if (evtstrm_enable) 405 if (evtstrm_enable)
diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
index 87796e0864e9..d3ffde806629 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -145,11 +145,30 @@ static struct powernv_pstate_info {
145/* Use following macros for conversions between pstate_id and index */ 145/* Use following macros for conversions between pstate_id and index */
146static inline int idx_to_pstate(unsigned int i) 146static inline int idx_to_pstate(unsigned int i)
147{ 147{
148 if (unlikely(i >= powernv_pstate_info.nr_pstates)) {
149 pr_warn_once("index %u is out of bound\n", i);
150 return powernv_freqs[powernv_pstate_info.nominal].driver_data;
151 }
152
148 return powernv_freqs[i].driver_data; 153 return powernv_freqs[i].driver_data;
149} 154}
150 155
151static inline unsigned int pstate_to_idx(int pstate) 156static inline unsigned int pstate_to_idx(int pstate)
152{ 157{
158 int min = powernv_freqs[powernv_pstate_info.min].driver_data;
159 int max = powernv_freqs[powernv_pstate_info.max].driver_data;
160
161 if (min > 0) {
162 if (unlikely((pstate < max) || (pstate > min))) {
163 pr_warn_once("pstate %d is out of bound\n", pstate);
164 return powernv_pstate_info.nominal;
165 }
166 } else {
167 if (unlikely((pstate > max) || (pstate < min))) {
168 pr_warn_once("pstate %d is out of bound\n", pstate);
169 return powernv_pstate_info.nominal;
170 }
171 }
153 /* 172 /*
154 * abs() is deliberately used so that is works with 173 * abs() is deliberately used so that is works with
155 * both monotonically increasing and decreasing 174 * both monotonically increasing and decreasing
@@ -593,7 +612,7 @@ void gpstate_timer_handler(unsigned long data)
593 } else { 612 } else {
594 gpstate_idx = calc_global_pstate(gpstates->elapsed_time, 613 gpstate_idx = calc_global_pstate(gpstates->elapsed_time,
595 gpstates->highest_lpstate_idx, 614 gpstates->highest_lpstate_idx,
596 freq_data.pstate_id); 615 gpstates->last_lpstate_idx);
597 } 616 }
598 617
599 /* 618 /*
diff --git a/drivers/firmware/efi/capsule-loader.c b/drivers/firmware/efi/capsule-loader.c
index c99c24bc79b0..9ae6c116c474 100644
--- a/drivers/firmware/efi/capsule-loader.c
+++ b/drivers/firmware/efi/capsule-loader.c
@@ -16,6 +16,7 @@
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/mutex.h> 17#include <linux/mutex.h>
18#include <linux/efi.h> 18#include <linux/efi.h>
19#include <linux/vmalloc.h>
19 20
20#define NO_FURTHER_WRITE_ACTION -1 21#define NO_FURTHER_WRITE_ACTION -1
21 22
@@ -108,14 +109,15 @@ static ssize_t efi_capsule_submit_update(struct capsule_info *cap_info)
108 int ret; 109 int ret;
109 void *cap_hdr_temp; 110 void *cap_hdr_temp;
110 111
111 cap_hdr_temp = kmap(cap_info->pages[0]); 112 cap_hdr_temp = vmap(cap_info->pages, cap_info->index,
113 VM_MAP, PAGE_KERNEL);
112 if (!cap_hdr_temp) { 114 if (!cap_hdr_temp) {
113 pr_debug("%s: kmap() failed\n", __func__); 115 pr_debug("%s: vmap() failed\n", __func__);
114 return -EFAULT; 116 return -EFAULT;
115 } 117 }
116 118
117 ret = efi_capsule_update(cap_hdr_temp, cap_info->pages); 119 ret = efi_capsule_update(cap_hdr_temp, cap_info->pages);
118 kunmap(cap_info->pages[0]); 120 vunmap(cap_hdr_temp);
119 if (ret) { 121 if (ret) {
120 pr_err("%s: efi_capsule_update() failed\n", __func__); 122 pr_err("%s: efi_capsule_update() failed\n", __func__);
121 return ret; 123 return ret;
diff --git a/drivers/firmware/efi/capsule.c b/drivers/firmware/efi/capsule.c
index 53b9fd2293ee..6eedff45e6d7 100644
--- a/drivers/firmware/efi/capsule.c
+++ b/drivers/firmware/efi/capsule.c
@@ -190,9 +190,9 @@ efi_capsule_update_locked(efi_capsule_header_t *capsule,
190 * map the capsule described by @capsule with its data in @pages and 190 * map the capsule described by @capsule with its data in @pages and
191 * send it to the firmware via the UpdateCapsule() runtime service. 191 * send it to the firmware via the UpdateCapsule() runtime service.
192 * 192 *
193 * @capsule must be a virtual mapping of the first page in @pages 193 * @capsule must be a virtual mapping of the complete capsule update in the
194 * (@pages[0]) in the kernel address space. That is, a 194 * kernel address space, as the capsule can be consumed immediately.
195 * capsule_header_t that describes the entire contents of the capsule 195 * A capsule_header_t that describes the entire contents of the capsule
196 * must be at the start of the first data page. 196 * must be at the start of the first data page.
197 * 197 *
198 * Even though this function will validate that the firmware supports 198 * Even though this function will validate that the firmware supports
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index ff63b88b0ffa..5cc7052e391d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -305,7 +305,7 @@ static ssize_t amdgpu_get_pp_table(struct device *dev,
305 struct drm_device *ddev = dev_get_drvdata(dev); 305 struct drm_device *ddev = dev_get_drvdata(dev);
306 struct amdgpu_device *adev = ddev->dev_private; 306 struct amdgpu_device *adev = ddev->dev_private;
307 char *table = NULL; 307 char *table = NULL;
308 int size, i; 308 int size;
309 309
310 if (adev->pp_enabled) 310 if (adev->pp_enabled)
311 size = amdgpu_dpm_get_pp_table(adev, &table); 311 size = amdgpu_dpm_get_pp_table(adev, &table);
@@ -315,10 +315,7 @@ static ssize_t amdgpu_get_pp_table(struct device *dev,
315 if (size >= PAGE_SIZE) 315 if (size >= PAGE_SIZE)
316 size = PAGE_SIZE - 1; 316 size = PAGE_SIZE - 1;
317 317
318 for (i = 0; i < size; i++) { 318 memcpy(buf, table, size);
319 sprintf(buf + i, "%02x", table[i]);
320 }
321 sprintf(buf + i, "\n");
322 319
323 return size; 320 return size;
324} 321}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index b7742e62972a..9b61c8ba7aaf 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -335,7 +335,7 @@ static int amdgpu_move_vram_ram(struct ttm_buffer_object *bo,
335 if (unlikely(r)) { 335 if (unlikely(r)) {
336 goto out_cleanup; 336 goto out_cleanup;
337 } 337 }
338 r = ttm_bo_move_ttm(bo, true, no_wait_gpu, new_mem); 338 r = ttm_bo_move_ttm(bo, true, interruptible, no_wait_gpu, new_mem);
339out_cleanup: 339out_cleanup:
340 ttm_bo_mem_put(bo, &tmp_mem); 340 ttm_bo_mem_put(bo, &tmp_mem);
341 return r; 341 return r;
@@ -368,7 +368,7 @@ static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo,
368 if (unlikely(r)) { 368 if (unlikely(r)) {
369 return r; 369 return r;
370 } 370 }
371 r = ttm_bo_move_ttm(bo, true, no_wait_gpu, &tmp_mem); 371 r = ttm_bo_move_ttm(bo, true, interruptible, no_wait_gpu, &tmp_mem);
372 if (unlikely(r)) { 372 if (unlikely(r)) {
373 goto out_cleanup; 373 goto out_cleanup;
374 } 374 }
diff --git a/drivers/gpu/drm/amd/amdgpu/ci_dpm.c b/drivers/gpu/drm/amd/amdgpu/ci_dpm.c
index e2f0e5d58d5c..a5c94b482459 100644
--- a/drivers/gpu/drm/amd/amdgpu/ci_dpm.c
+++ b/drivers/gpu/drm/amd/amdgpu/ci_dpm.c
@@ -5779,6 +5779,7 @@ static int ci_dpm_init_microcode(struct amdgpu_device *adev)
5779 break; 5779 break;
5780 case CHIP_KAVERI: 5780 case CHIP_KAVERI:
5781 case CHIP_KABINI: 5781 case CHIP_KABINI:
5782 case CHIP_MULLINS:
5782 default: BUG(); 5783 default: BUG();
5783 } 5784 }
5784 5785
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index bff8668e9e6d..b8184617ca25 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
@@ -270,7 +270,8 @@ static const u32 tonga_mgcg_cgcg_init[] =
270 270
271static const u32 golden_settings_polaris11_a11[] = 271static const u32 golden_settings_polaris11_a11[] =
272{ 272{
273 mmCB_HW_CONTROL, 0xfffdf3cf, 0x00006208, 273 mmCB_HW_CONTROL, 0x0000f3cf, 0x00007208,
274 mmCB_HW_CONTROL_2, 0x0f000000, 0x0f000000,
274 mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040, 275 mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
275 mmDB_DEBUG2, 0xf00fffff, 0x00000400, 276 mmDB_DEBUG2, 0xf00fffff, 0x00000400,
276 mmPA_SC_ENHANCE, 0xffffffff, 0x20000001, 277 mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
@@ -279,7 +280,7 @@ static const u32 golden_settings_polaris11_a11[] =
279 mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x00000000, 280 mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x00000000,
280 mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c, 281 mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
281 mmRLC_CGCG_CGLS_CTRL_3D, 0xffffffff, 0x0001003c, 282 mmRLC_CGCG_CGLS_CTRL_3D, 0xffffffff, 0x0001003c,
282 mmSQ_CONFIG, 0x07f80000, 0x07180000, 283 mmSQ_CONFIG, 0x07f80000, 0x01180000,
283 mmTA_CNTL_AUX, 0x000f000f, 0x000b0000, 284 mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
284 mmTCC_CTRL, 0x00100000, 0xf31fff7f, 285 mmTCC_CTRL, 0x00100000, 0xf31fff7f,
285 mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f3, 286 mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f3,
@@ -301,8 +302,8 @@ static const u32 polaris11_golden_common_all[] =
301static const u32 golden_settings_polaris10_a11[] = 302static const u32 golden_settings_polaris10_a11[] =
302{ 303{
303 mmATC_MISC_CG, 0x000c0fc0, 0x000c0200, 304 mmATC_MISC_CG, 0x000c0fc0, 0x000c0200,
304 mmCB_HW_CONTROL, 0xfffdf3cf, 0x00007208, 305 mmCB_HW_CONTROL, 0x0001f3cf, 0x00007208,
305 mmCB_HW_CONTROL_2, 0, 0x0f000000, 306 mmCB_HW_CONTROL_2, 0x0f000000, 0x0f000000,
306 mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040, 307 mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
307 mmDB_DEBUG2, 0xf00fffff, 0x00000400, 308 mmDB_DEBUG2, 0xf00fffff, 0x00000400,
308 mmPA_SC_ENHANCE, 0xffffffff, 0x20000001, 309 mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
@@ -409,6 +410,7 @@ static const u32 golden_settings_iceland_a11[] =
409 mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000, 410 mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
410 mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x00000002, 411 mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x00000002,
411 mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x00000000, 412 mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x00000000,
413 mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0000003c,
412 mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd, 414 mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
413 mmTA_CNTL_AUX, 0x000f000f, 0x000b0000, 415 mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
414 mmTCC_CTRL, 0x00100000, 0xf31fff7f, 416 mmTCC_CTRL, 0x00100000, 0xf31fff7f,
@@ -505,8 +507,10 @@ static const u32 cz_golden_settings_a11[] =
505 mmGB_GPU_ID, 0x0000000f, 0x00000000, 507 mmGB_GPU_ID, 0x0000000f, 0x00000000,
506 mmPA_SC_ENHANCE, 0xffffffff, 0x00000001, 508 mmPA_SC_ENHANCE, 0xffffffff, 0x00000001,
507 mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000, 509 mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
510 mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0000003c,
508 mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd, 511 mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
509 mmTA_CNTL_AUX, 0x000f000f, 0x00010000, 512 mmTA_CNTL_AUX, 0x000f000f, 0x00010000,
513 mmTCC_CTRL, 0x00100000, 0xf31fff7f,
510 mmTCC_EXE_DISABLE, 0x00000002, 0x00000002, 514 mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
511 mmTCP_ADDR_CONFIG, 0x0000000f, 0x000000f3, 515 mmTCP_ADDR_CONFIG, 0x0000000f, 0x000000f3,
512 mmTCP_CHAN_STEER_LO, 0xffffffff, 0x00001302 516 mmTCP_CHAN_STEER_LO, 0xffffffff, 0x00001302
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
index d24a82bd0c7a..0b0f08641eed 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
@@ -144,6 +144,7 @@ static int gmc_v7_0_init_microcode(struct amdgpu_device *adev)
144 break; 144 break;
145 case CHIP_KAVERI: 145 case CHIP_KAVERI:
146 case CHIP_KABINI: 146 case CHIP_KABINI:
147 case CHIP_MULLINS:
147 return 0; 148 return 0;
148 default: BUG(); 149 default: BUG();
149 } 150 }
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
index 717359d3ba8c..2aee2c6f3cd5 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
@@ -103,6 +103,11 @@ static const u32 stoney_mgcg_cgcg_init[] =
103 mmMC_MEM_POWER_LS, 0xffffffff, 0x00000104 103 mmMC_MEM_POWER_LS, 0xffffffff, 0x00000104
104}; 104};
105 105
106static const u32 golden_settings_stoney_common[] =
107{
108 mmMC_HUB_RDREQ_UVD, MC_HUB_RDREQ_UVD__PRESCALE_MASK, 0x00000004,
109 mmMC_RD_GRP_OTH, MC_RD_GRP_OTH__UVD_MASK, 0x00600000
110};
106 111
107static void gmc_v8_0_init_golden_registers(struct amdgpu_device *adev) 112static void gmc_v8_0_init_golden_registers(struct amdgpu_device *adev)
108{ 113{
@@ -142,6 +147,9 @@ static void gmc_v8_0_init_golden_registers(struct amdgpu_device *adev)
142 amdgpu_program_register_sequence(adev, 147 amdgpu_program_register_sequence(adev,
143 stoney_mgcg_cgcg_init, 148 stoney_mgcg_cgcg_init,
144 (const u32)ARRAY_SIZE(stoney_mgcg_cgcg_init)); 149 (const u32)ARRAY_SIZE(stoney_mgcg_cgcg_init));
150 amdgpu_program_register_sequence(adev,
151 golden_settings_stoney_common,
152 (const u32)ARRAY_SIZE(golden_settings_stoney_common));
145 break; 153 break;
146 default: 154 default:
147 break; 155 break;
diff --git a/drivers/gpu/drm/cirrus/cirrus_main.c b/drivers/gpu/drm/cirrus/cirrus_main.c
index 80446e2d3ab6..76bcb43e7c06 100644
--- a/drivers/gpu/drm/cirrus/cirrus_main.c
+++ b/drivers/gpu/drm/cirrus/cirrus_main.c
@@ -185,14 +185,23 @@ int cirrus_driver_load(struct drm_device *dev, unsigned long flags)
185 goto out; 185 goto out;
186 } 186 }
187 187
188 /*
189 * cirrus_modeset_init() is initializing/registering the emulated fbdev
190 * and DRM internals can access/test some of the fields in
191 * mode_config->funcs as part of the fbdev registration process.
192 * Make sure dev->mode_config.funcs is properly set to avoid
193 * dereferencing a NULL pointer.
194 * FIXME: mode_config.funcs assignment should probably be done in
195 * cirrus_modeset_init() (that's a common pattern seen in other DRM
196 * drivers).
197 */
198 dev->mode_config.funcs = &cirrus_mode_funcs;
188 r = cirrus_modeset_init(cdev); 199 r = cirrus_modeset_init(cdev);
189 if (r) { 200 if (r) {
190 dev_err(&dev->pdev->dev, "Fatal error during modeset init: %d\n", r); 201 dev_err(&dev->pdev->dev, "Fatal error during modeset init: %d\n", r);
191 goto out; 202 goto out;
192 } 203 }
193 204
194 dev->mode_config.funcs = (void *)&cirrus_mode_funcs;
195
196 return 0; 205 return 0;
197out: 206out:
198 cirrus_driver_unload(dev); 207 cirrus_driver_unload(dev);
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index f1d9f0569d7f..b1dbb60af99f 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -1121,16 +1121,14 @@ static int drm_connector_register_all(struct drm_device *dev)
1121 struct drm_connector *connector; 1121 struct drm_connector *connector;
1122 int ret; 1122 int ret;
1123 1123
1124 mutex_lock(&dev->mode_config.mutex); 1124 /* FIXME: taking the mode config mutex ends up in a clash with
1125 1125 * fbcon/backlight registration */
1126 drm_for_each_connector(connector, dev) { 1126 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1127 ret = drm_connector_register(connector); 1127 ret = drm_connector_register(connector);
1128 if (ret) 1128 if (ret)
1129 goto err; 1129 goto err;
1130 } 1130 }
1131 1131
1132 mutex_unlock(&dev->mode_config.mutex);
1133
1134 return 0; 1132 return 0;
1135 1133
1136err: 1134err:
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 7df26d4b7ad8..637a0aa4d3a0 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -74,6 +74,8 @@
74#define EDID_QUIRK_FORCE_8BPC (1 << 8) 74#define EDID_QUIRK_FORCE_8BPC (1 << 8)
75/* Force 12bpc */ 75/* Force 12bpc */
76#define EDID_QUIRK_FORCE_12BPC (1 << 9) 76#define EDID_QUIRK_FORCE_12BPC (1 << 9)
77/* Force 6bpc */
78#define EDID_QUIRK_FORCE_6BPC (1 << 10)
77 79
78struct detailed_mode_closure { 80struct detailed_mode_closure {
79 struct drm_connector *connector; 81 struct drm_connector *connector;
@@ -100,6 +102,9 @@ static struct edid_quirk {
100 /* Unknown Acer */ 102 /* Unknown Acer */
101 { "ACR", 2423, EDID_QUIRK_FIRST_DETAILED_PREFERRED }, 103 { "ACR", 2423, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
102 104
105 /* AEO model 0 reports 8 bpc, but is a 6 bpc panel */
106 { "AEO", 0, EDID_QUIRK_FORCE_6BPC },
107
103 /* Belinea 10 15 55 */ 108 /* Belinea 10 15 55 */
104 { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 }, 109 { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 },
105 { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 }, 110 { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 },
@@ -3862,6 +3867,20 @@ static void drm_add_display_info(struct edid *edid,
3862 /* HDMI deep color modes supported? Assign to info, if so */ 3867 /* HDMI deep color modes supported? Assign to info, if so */
3863 drm_assign_hdmi_deep_color_info(edid, info, connector); 3868 drm_assign_hdmi_deep_color_info(edid, info, connector);
3864 3869
3870 /*
3871 * Digital sink with "DFP 1.x compliant TMDS" according to EDID 1.3?
3872 *
3873 * For such displays, the DFP spec 1.0, section 3.10 "EDID support"
3874 * tells us to assume 8 bpc color depth if the EDID doesn't have
3875 * extensions which tell otherwise.
3876 */
3877 if ((info->bpc == 0) && (edid->revision < 4) &&
3878 (edid->input & DRM_EDID_DIGITAL_TYPE_DVI)) {
3879 info->bpc = 8;
3880 DRM_DEBUG("%s: Assigning DFP sink color depth as %d bpc.\n",
3881 connector->name, info->bpc);
3882 }
3883
3865 /* Only defined for 1.4 with digital displays */ 3884 /* Only defined for 1.4 with digital displays */
3866 if (edid->revision < 4) 3885 if (edid->revision < 4)
3867 return; 3886 return;
@@ -4082,6 +4101,9 @@ int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
4082 4101
4083 drm_add_display_info(edid, &connector->display_info, connector); 4102 drm_add_display_info(edid, &connector->display_info, connector);
4084 4103
4104 if (quirks & EDID_QUIRK_FORCE_6BPC)
4105 connector->display_info.bpc = 6;
4106
4085 if (quirks & EDID_QUIRK_FORCE_8BPC) 4107 if (quirks & EDID_QUIRK_FORCE_8BPC)
4086 connector->display_info.bpc = 8; 4108 connector->display_info.bpc = 8;
4087 4109
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index c457eed76f1f..dcf93b3d4fb6 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -5691,15 +5691,7 @@ static bool skl_cdclk_pcu_ready(struct drm_i915_private *dev_priv)
5691 5691
5692static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv) 5692static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv)
5693{ 5693{
5694 unsigned int i; 5694 return _wait_for(skl_cdclk_pcu_ready(dev_priv), 3000, 10) == 0;
5695
5696 for (i = 0; i < 15; i++) {
5697 if (skl_cdclk_pcu_ready(dev_priv))
5698 return true;
5699 udelay(10);
5700 }
5701
5702 return false;
5703} 5695}
5704 5696
5705static void skl_set_cdclk(struct drm_i915_private *dev_priv, int cdclk, int vco) 5697static void skl_set_cdclk(struct drm_i915_private *dev_priv, int cdclk, int vco)
@@ -12114,21 +12106,11 @@ connected_sink_compute_bpp(struct intel_connector *connector,
12114 pipe_config->pipe_bpp = connector->base.display_info.bpc*3; 12106 pipe_config->pipe_bpp = connector->base.display_info.bpc*3;
12115 } 12107 }
12116 12108
12117 /* Clamp bpp to default limit on screens without EDID 1.4 */ 12109 /* Clamp bpp to 8 on screens without EDID 1.4 */
12118 if (connector->base.display_info.bpc == 0) { 12110 if (connector->base.display_info.bpc == 0 && bpp > 24) {
12119 int type = connector->base.connector_type; 12111 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
12120 int clamp_bpp = 24; 12112 bpp);
12121 12113 pipe_config->pipe_bpp = 24;
12122 /* Fall back to 18 bpp when DP sink capability is unknown. */
12123 if (type == DRM_MODE_CONNECTOR_DisplayPort ||
12124 type == DRM_MODE_CONNECTOR_eDP)
12125 clamp_bpp = 18;
12126
12127 if (bpp > clamp_bpp) {
12128 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of %d\n",
12129 bpp, clamp_bpp);
12130 pipe_config->pipe_bpp = clamp_bpp;
12131 }
12132 } 12114 }
12133} 12115}
12134 12116
diff --git a/drivers/gpu/drm/i915/intel_fbdev.c b/drivers/gpu/drm/i915/intel_fbdev.c
index 86b00c6db1a6..3e3632c18733 100644
--- a/drivers/gpu/drm/i915/intel_fbdev.c
+++ b/drivers/gpu/drm/i915/intel_fbdev.c
@@ -782,7 +782,7 @@ void intel_fbdev_set_suspend(struct drm_device *dev, int state, bool synchronous
782 struct intel_fbdev *ifbdev = dev_priv->fbdev; 782 struct intel_fbdev *ifbdev = dev_priv->fbdev;
783 struct fb_info *info; 783 struct fb_info *info;
784 784
785 if (!ifbdev) 785 if (!ifbdev || !ifbdev->fb)
786 return; 786 return;
787 787
788 info = ifbdev->helper.fbdev; 788 info = ifbdev->helper.fbdev;
@@ -827,31 +827,28 @@ void intel_fbdev_set_suspend(struct drm_device *dev, int state, bool synchronous
827 827
828void intel_fbdev_output_poll_changed(struct drm_device *dev) 828void intel_fbdev_output_poll_changed(struct drm_device *dev)
829{ 829{
830 struct drm_i915_private *dev_priv = to_i915(dev); 830 struct intel_fbdev *ifbdev = to_i915(dev)->fbdev;
831 if (dev_priv->fbdev) 831
832 drm_fb_helper_hotplug_event(&dev_priv->fbdev->helper); 832 if (ifbdev && ifbdev->fb)
833 drm_fb_helper_hotplug_event(&ifbdev->helper);
833} 834}
834 835
835void intel_fbdev_restore_mode(struct drm_device *dev) 836void intel_fbdev_restore_mode(struct drm_device *dev)
836{ 837{
837 int ret; 838 struct intel_fbdev *ifbdev = to_i915(dev)->fbdev;
838 struct drm_i915_private *dev_priv = to_i915(dev);
839 struct intel_fbdev *ifbdev = dev_priv->fbdev;
840 struct drm_fb_helper *fb_helper;
841 839
842 if (!ifbdev) 840 if (!ifbdev)
843 return; 841 return;
844 842
845 intel_fbdev_sync(ifbdev); 843 intel_fbdev_sync(ifbdev);
844 if (!ifbdev->fb)
845 return;
846 846
847 fb_helper = &ifbdev->helper; 847 if (drm_fb_helper_restore_fbdev_mode_unlocked(&ifbdev->helper)) {
848
849 ret = drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper);
850 if (ret) {
851 DRM_DEBUG("failed to restore crtc mode\n"); 848 DRM_DEBUG("failed to restore crtc mode\n");
852 } else { 849 } else {
853 mutex_lock(&fb_helper->dev->struct_mutex); 850 mutex_lock(&dev->struct_mutex);
854 intel_fb_obj_invalidate(ifbdev->fb->obj, ORIGIN_GTT); 851 intel_fb_obj_invalidate(ifbdev->fb->obj, ORIGIN_GTT);
855 mutex_unlock(&fb_helper->dev->struct_mutex); 852 mutex_unlock(&dev->struct_mutex);
856 } 853 }
857} 854}
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index f4f3fcc8b3be..97ba6c8cf907 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -4892,7 +4892,8 @@ void gen6_rps_idle(struct drm_i915_private *dev_priv)
4892 else 4892 else
4893 gen6_set_rps(dev_priv, dev_priv->rps.idle_freq); 4893 gen6_set_rps(dev_priv, dev_priv->rps.idle_freq);
4894 dev_priv->rps.last_adj = 0; 4894 dev_priv->rps.last_adj = 0;
4895 I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); 4895 I915_WRITE(GEN6_PMINTRMSK,
4896 gen6_sanitize_rps_pm_mask(dev_priv, ~0));
4896 } 4897 }
4897 mutex_unlock(&dev_priv->rps.hw_lock); 4898 mutex_unlock(&dev_priv->rps.hw_lock);
4898 4899
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 528bdeffb339..6190035edfea 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -1151,7 +1151,7 @@ nouveau_bo_move_flipd(struct ttm_buffer_object *bo, bool evict, bool intr,
1151 if (ret) 1151 if (ret)
1152 goto out; 1152 goto out;
1153 1153
1154 ret = ttm_bo_move_ttm(bo, true, no_wait_gpu, new_mem); 1154 ret = ttm_bo_move_ttm(bo, true, intr, no_wait_gpu, new_mem);
1155out: 1155out:
1156 ttm_bo_mem_put(bo, &tmp_mem); 1156 ttm_bo_mem_put(bo, &tmp_mem);
1157 return ret; 1157 return ret;
@@ -1179,7 +1179,7 @@ nouveau_bo_move_flips(struct ttm_buffer_object *bo, bool evict, bool intr,
1179 if (ret) 1179 if (ret)
1180 return ret; 1180 return ret;
1181 1181
1182 ret = ttm_bo_move_ttm(bo, true, no_wait_gpu, &tmp_mem); 1182 ret = ttm_bo_move_ttm(bo, true, intr, no_wait_gpu, &tmp_mem);
1183 if (ret) 1183 if (ret)
1184 goto out; 1184 goto out;
1185 1185
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index ffdad81ef964..0c00e192c845 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -346,7 +346,7 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,
346 if (unlikely(r)) { 346 if (unlikely(r)) {
347 goto out_cleanup; 347 goto out_cleanup;
348 } 348 }
349 r = ttm_bo_move_ttm(bo, true, no_wait_gpu, new_mem); 349 r = ttm_bo_move_ttm(bo, true, interruptible, no_wait_gpu, new_mem);
350out_cleanup: 350out_cleanup:
351 ttm_bo_mem_put(bo, &tmp_mem); 351 ttm_bo_mem_put(bo, &tmp_mem);
352 return r; 352 return r;
@@ -379,7 +379,7 @@ static int radeon_move_ram_vram(struct ttm_buffer_object *bo,
379 if (unlikely(r)) { 379 if (unlikely(r)) {
380 return r; 380 return r;
381 } 381 }
382 r = ttm_bo_move_ttm(bo, true, no_wait_gpu, &tmp_mem); 382 r = ttm_bo_move_ttm(bo, true, interruptible, no_wait_gpu, &tmp_mem);
383 if (unlikely(r)) { 383 if (unlikely(r)) {
384 goto out_cleanup; 384 goto out_cleanup;
385 } 385 }
diff --git a/drivers/gpu/drm/rcar-du/rcar_du_hdmienc.c b/drivers/gpu/drm/rcar-du/rcar_du_hdmienc.c
index 4de3ff0dbebd..e03004f4588d 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_hdmienc.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_hdmienc.c
@@ -125,6 +125,7 @@ int rcar_du_hdmienc_init(struct rcar_du_device *rcdu,
125 125
126 /* Link drm_bridge to encoder */ 126 /* Link drm_bridge to encoder */
127 bridge->encoder = encoder; 127 bridge->encoder = encoder;
128 encoder->bridge = bridge;
128 129
129 ret = drm_bridge_attach(rcdu->ddev, bridge); 130 ret = drm_bridge_attach(rcdu->ddev, bridge);
130 if (ret) { 131 if (ret) {
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 4054d804fe06..42c074a9c955 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -354,7 +354,8 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
354 354
355 if (!(old_man->flags & TTM_MEMTYPE_FLAG_FIXED) && 355 if (!(old_man->flags & TTM_MEMTYPE_FLAG_FIXED) &&
356 !(new_man->flags & TTM_MEMTYPE_FLAG_FIXED)) 356 !(new_man->flags & TTM_MEMTYPE_FLAG_FIXED))
357 ret = ttm_bo_move_ttm(bo, evict, no_wait_gpu, mem); 357 ret = ttm_bo_move_ttm(bo, evict, interruptible, no_wait_gpu,
358 mem);
358 else if (bdev->driver->move) 359 else if (bdev->driver->move)
359 ret = bdev->driver->move(bo, evict, interruptible, 360 ret = bdev->driver->move(bo, evict, interruptible,
360 no_wait_gpu, mem); 361 no_wait_gpu, mem);
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 2df602a35f92..f157a9efd220 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -45,7 +45,7 @@ void ttm_bo_free_old_node(struct ttm_buffer_object *bo)
45} 45}
46 46
47int ttm_bo_move_ttm(struct ttm_buffer_object *bo, 47int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
48 bool evict, 48 bool evict, bool interruptible,
49 bool no_wait_gpu, struct ttm_mem_reg *new_mem) 49 bool no_wait_gpu, struct ttm_mem_reg *new_mem)
50{ 50{
51 struct ttm_tt *ttm = bo->ttm; 51 struct ttm_tt *ttm = bo->ttm;
@@ -53,6 +53,14 @@ int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
53 int ret; 53 int ret;
54 54
55 if (old_mem->mem_type != TTM_PL_SYSTEM) { 55 if (old_mem->mem_type != TTM_PL_SYSTEM) {
56 ret = ttm_bo_wait(bo, interruptible, no_wait_gpu);
57
58 if (unlikely(ret != 0)) {
59 if (ret != -ERESTARTSYS)
60 pr_err("Failed to expire sync object before unbinding TTM\n");
61 return ret;
62 }
63
56 ttm_tt_unbind(ttm); 64 ttm_tt_unbind(ttm);
57 ttm_bo_free_old_node(bo); 65 ttm_bo_free_old_node(bo);
58 ttm_flag_masked(&old_mem->placement, TTM_PL_FLAG_SYSTEM, 66 ttm_flag_masked(&old_mem->placement, TTM_PL_FLAG_SYSTEM,
diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 7ceaba81efb4..36b9c28a5c91 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -1545,7 +1545,12 @@ static int its_force_quiescent(void __iomem *base)
1545 u32 val; 1545 u32 val;
1546 1546
1547 val = readl_relaxed(base + GITS_CTLR); 1547 val = readl_relaxed(base + GITS_CTLR);
1548 if (val & GITS_CTLR_QUIESCENT) 1548 /*
1549 * GIC architecture specification requires the ITS to be both
1550 * disabled and quiescent for writes to GITS_BASER<n> or
1551 * GITS_CBASER to not have UNPREDICTABLE results.
1552 */
1553 if ((val & GITS_CTLR_QUIESCENT) && !(val & GITS_CTLR_ENABLE))
1549 return 0; 1554 return 0;
1550 1555
1551 /* Disable the generation of all interrupts to this ITS */ 1556 /* Disable the generation of all interrupts to this ITS */
diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c
index 6fc56c3466b0..ede5672ab34d 100644
--- a/drivers/irqchip/irq-gic-v3.c
+++ b/drivers/irqchip/irq-gic-v3.c
@@ -667,13 +667,20 @@ static int gic_set_affinity(struct irq_data *d, const struct cpumask *mask_val,
667#endif 667#endif
668 668
669#ifdef CONFIG_CPU_PM 669#ifdef CONFIG_CPU_PM
670/* Check whether it's single security state view */
671static bool gic_dist_security_disabled(void)
672{
673 return readl_relaxed(gic_data.dist_base + GICD_CTLR) & GICD_CTLR_DS;
674}
675
670static int gic_cpu_pm_notifier(struct notifier_block *self, 676static int gic_cpu_pm_notifier(struct notifier_block *self,
671 unsigned long cmd, void *v) 677 unsigned long cmd, void *v)
672{ 678{
673 if (cmd == CPU_PM_EXIT) { 679 if (cmd == CPU_PM_EXIT) {
674 gic_enable_redist(true); 680 if (gic_dist_security_disabled())
681 gic_enable_redist(true);
675 gic_cpu_sys_reg_init(); 682 gic_cpu_sys_reg_init();
676 } else if (cmd == CPU_PM_ENTER) { 683 } else if (cmd == CPU_PM_ENTER && gic_dist_security_disabled()) {
677 gic_write_grpen1(0); 684 gic_write_grpen1(0);
678 gic_enable_redist(false); 685 gic_enable_redist(false);
679 } 686 }
diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
index c2cab572c511..390fac59c6bc 100644
--- a/drivers/irqchip/irq-gic.c
+++ b/drivers/irqchip/irq-gic.c
@@ -769,6 +769,13 @@ static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq)
769 int cpu; 769 int cpu;
770 unsigned long flags, map = 0; 770 unsigned long flags, map = 0;
771 771
772 if (unlikely(nr_cpu_ids == 1)) {
773 /* Only one CPU? let's do a self-IPI... */
774 writel_relaxed(2 << 24 | irq,
775 gic_data_dist_base(&gic_data[0]) + GIC_DIST_SOFTINT);
776 return;
777 }
778
772 raw_spin_lock_irqsave(&irq_controller_lock, flags); 779 raw_spin_lock_irqsave(&irq_controller_lock, flags);
773 780
774 /* Convert our logical CPU mask into a physical one. */ 781 /* Convert our logical CPU mask into a physical one. */
diff --git a/drivers/misc/cxl/context.c b/drivers/misc/cxl/context.c
index bdee9a01ef35..c466ee2b0c97 100644
--- a/drivers/misc/cxl/context.c
+++ b/drivers/misc/cxl/context.c
@@ -90,8 +90,7 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master,
90 */ 90 */
91 mutex_lock(&afu->contexts_lock); 91 mutex_lock(&afu->contexts_lock);
92 idr_preload(GFP_KERNEL); 92 idr_preload(GFP_KERNEL);
93 i = idr_alloc(&ctx->afu->contexts_idr, ctx, 93 i = idr_alloc(&ctx->afu->contexts_idr, ctx, ctx->afu->adapter->min_pe,
94 ctx->afu->adapter->native->sl_ops->min_pe,
95 ctx->afu->num_procs, GFP_NOWAIT); 94 ctx->afu->num_procs, GFP_NOWAIT);
96 idr_preload_end(); 95 idr_preload_end();
97 mutex_unlock(&afu->contexts_lock); 96 mutex_unlock(&afu->contexts_lock);
diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h
index de090533f18c..344a0ff8f8c7 100644
--- a/drivers/misc/cxl/cxl.h
+++ b/drivers/misc/cxl/cxl.h
@@ -561,7 +561,6 @@ struct cxl_service_layer_ops {
561 u64 (*timebase_read)(struct cxl *adapter); 561 u64 (*timebase_read)(struct cxl *adapter);
562 int capi_mode; 562 int capi_mode;
563 bool needs_reset_before_disable; 563 bool needs_reset_before_disable;
564 int min_pe;
565}; 564};
566 565
567struct cxl_native { 566struct cxl_native {
@@ -603,6 +602,7 @@ struct cxl {
603 struct bin_attribute cxl_attr; 602 struct bin_attribute cxl_attr;
604 int adapter_num; 603 int adapter_num;
605 int user_irqs; 604 int user_irqs;
605 int min_pe;
606 u64 ps_size; 606 u64 ps_size;
607 u16 psl_rev; 607 u16 psl_rev;
608 u16 base_image; 608 u16 base_image;
diff --git a/drivers/misc/cxl/native.c b/drivers/misc/cxl/native.c
index 3bcdaee11ba1..e606fdc4bc9c 100644
--- a/drivers/misc/cxl/native.c
+++ b/drivers/misc/cxl/native.c
@@ -924,7 +924,7 @@ static irqreturn_t native_irq_multiplexed(int irq, void *data)
924 return fail_psl_irq(afu, &irq_info); 924 return fail_psl_irq(afu, &irq_info);
925} 925}
926 926
927void native_irq_wait(struct cxl_context *ctx) 927static void native_irq_wait(struct cxl_context *ctx)
928{ 928{
929 u64 dsisr; 929 u64 dsisr;
930 int timeout = 1000; 930 int timeout = 1000;
diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
index d152e2de8c93..6f0c4ac4b649 100644
--- a/drivers/misc/cxl/pci.c
+++ b/drivers/misc/cxl/pci.c
@@ -379,7 +379,7 @@ static int calc_capp_routing(struct pci_dev *dev, u64 *chipid, u64 *capp_unit_id
379 379
380static int init_implementation_adapter_psl_regs(struct cxl *adapter, struct pci_dev *dev) 380static int init_implementation_adapter_psl_regs(struct cxl *adapter, struct pci_dev *dev)
381{ 381{
382 u64 psl_dsnctl; 382 u64 psl_dsnctl, psl_fircntl;
383 u64 chipid; 383 u64 chipid;
384 u64 capp_unit_id; 384 u64 capp_unit_id;
385 int rc; 385 int rc;
@@ -398,8 +398,11 @@ static int init_implementation_adapter_psl_regs(struct cxl *adapter, struct pci_
398 cxl_p1_write(adapter, CXL_PSL_RESLCKTO, 0x20000000200ULL); 398 cxl_p1_write(adapter, CXL_PSL_RESLCKTO, 0x20000000200ULL);
399 /* snoop write mask */ 399 /* snoop write mask */
400 cxl_p1_write(adapter, CXL_PSL_SNWRALLOC, 0x00000000FFFFFFFFULL); 400 cxl_p1_write(adapter, CXL_PSL_SNWRALLOC, 0x00000000FFFFFFFFULL);
401 /* set fir_accum */ 401 /* set fir_cntl to recommended value for production env */
402 cxl_p1_write(adapter, CXL_PSL_FIR_CNTL, 0x0800000000000000ULL); 402 psl_fircntl = (0x2ULL << (63-3)); /* ce_report */
403 psl_fircntl |= (0x1ULL << (63-6)); /* FIR_report */
404 psl_fircntl |= 0x1ULL; /* ce_thresh */
405 cxl_p1_write(adapter, CXL_PSL_FIR_CNTL, psl_fircntl);
403 /* for debugging with trace arrays */ 406 /* for debugging with trace arrays */
404 cxl_p1_write(adapter, CXL_PSL_TRACE, 0x0000FF7C00000000ULL); 407 cxl_p1_write(adapter, CXL_PSL_TRACE, 0x0000FF7C00000000ULL);
405 408
@@ -1521,14 +1524,15 @@ static const struct cxl_service_layer_ops xsl_ops = {
1521 .write_timebase_ctrl = write_timebase_ctrl_xsl, 1524 .write_timebase_ctrl = write_timebase_ctrl_xsl,
1522 .timebase_read = timebase_read_xsl, 1525 .timebase_read = timebase_read_xsl,
1523 .capi_mode = OPAL_PHB_CAPI_MODE_DMA, 1526 .capi_mode = OPAL_PHB_CAPI_MODE_DMA,
1524 .min_pe = 1, /* Workaround for Mellanox CX4 HW bug */
1525}; 1527};
1526 1528
1527static void set_sl_ops(struct cxl *adapter, struct pci_dev *dev) 1529static void set_sl_ops(struct cxl *adapter, struct pci_dev *dev)
1528{ 1530{
1529 if (dev->vendor == PCI_VENDOR_ID_MELLANOX && dev->device == 0x1013) { 1531 if (dev->vendor == PCI_VENDOR_ID_MELLANOX && dev->device == 0x1013) {
1532 /* Mellanox CX-4 */
1530 dev_info(&adapter->dev, "Device uses an XSL\n"); 1533 dev_info(&adapter->dev, "Device uses an XSL\n");
1531 adapter->native->sl_ops = &xsl_ops; 1534 adapter->native->sl_ops = &xsl_ops;
1535 adapter->min_pe = 1; /* Workaround for CX-4 hardware bug */
1532 } else { 1536 } else {
1533 dev_info(&adapter->dev, "Device uses a PSL\n"); 1537 dev_info(&adapter->dev, "Device uses a PSL\n");
1534 adapter->native->sl_ops = &psl_ops; 1538 adapter->native->sl_ops = &psl_ops;
diff --git a/drivers/misc/cxl/vphb.c b/drivers/misc/cxl/vphb.c
index dee8def1c193..7ada5f1b7bb6 100644
--- a/drivers/misc/cxl/vphb.c
+++ b/drivers/misc/cxl/vphb.c
@@ -221,7 +221,7 @@ int cxl_pci_vphb_add(struct cxl_afu *afu)
221 /* Setup the PHB using arch provided callback */ 221 /* Setup the PHB using arch provided callback */
222 phb->ops = &cxl_pcie_pci_ops; 222 phb->ops = &cxl_pcie_pci_ops;
223 phb->cfg_addr = NULL; 223 phb->cfg_addr = NULL;
224 phb->cfg_data = 0; 224 phb->cfg_data = NULL;
225 phb->private_data = afu; 225 phb->private_data = afu;
226 phb->controller_ops = cxl_pci_controller_ops; 226 phb->controller_ops = cxl_pci_controller_ops;
227 227
diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c
index 88e91666f145..368795aad5c9 100644
--- a/drivers/nvdimm/btt.c
+++ b/drivers/nvdimm/btt.c
@@ -1269,6 +1269,7 @@ static int btt_blk_init(struct btt *btt)
1269 } 1269 }
1270 } 1270 }
1271 set_capacity(btt->btt_disk, btt->nlba * btt->sector_size >> 9); 1271 set_capacity(btt->btt_disk, btt->nlba * btt->sector_size >> 9);
1272 btt->nd_btt->size = btt->nlba * (u64)btt->sector_size;
1272 revalidate_disk(btt->btt_disk); 1273 revalidate_disk(btt->btt_disk);
1273 1274
1274 return 0; 1275 return 0;
diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
index 3fa7919f94a8..97dd2925ed6e 100644
--- a/drivers/nvdimm/btt_devs.c
+++ b/drivers/nvdimm/btt_devs.c
@@ -140,10 +140,30 @@ static ssize_t namespace_store(struct device *dev,
140} 140}
141static DEVICE_ATTR_RW(namespace); 141static DEVICE_ATTR_RW(namespace);
142 142
143static ssize_t size_show(struct device *dev,
144 struct device_attribute *attr, char *buf)
145{
146 struct nd_btt *nd_btt = to_nd_btt(dev);
147 ssize_t rc;
148
149 device_lock(dev);
150 if (dev->driver)
151 rc = sprintf(buf, "%llu\n", nd_btt->size);
152 else {
153 /* no size to convey if the btt instance is disabled */
154 rc = -ENXIO;
155 }
156 device_unlock(dev);
157
158 return rc;
159}
160static DEVICE_ATTR_RO(size);
161
143static struct attribute *nd_btt_attributes[] = { 162static struct attribute *nd_btt_attributes[] = {
144 &dev_attr_sector_size.attr, 163 &dev_attr_sector_size.attr,
145 &dev_attr_namespace.attr, 164 &dev_attr_namespace.attr,
146 &dev_attr_uuid.attr, 165 &dev_attr_uuid.attr,
166 &dev_attr_size.attr,
147 NULL, 167 NULL,
148}; 168};
149 169
diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h
index 40476399d227..8024a0ef86d3 100644
--- a/drivers/nvdimm/nd.h
+++ b/drivers/nvdimm/nd.h
@@ -143,6 +143,7 @@ struct nd_btt {
143 struct nd_namespace_common *ndns; 143 struct nd_namespace_common *ndns;
144 struct btt *btt; 144 struct btt *btt;
145 unsigned long lbasize; 145 unsigned long lbasize;
146 u64 size;
146 u8 *uuid; 147 u8 *uuid;
147 int id; 148 int id;
148}; 149};
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index d7c33f9361aa..8dcf5a960951 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1543,15 +1543,10 @@ static void nvme_disable_io_queues(struct nvme_dev *dev)
1543 reinit_completion(&dev->ioq_wait); 1543 reinit_completion(&dev->ioq_wait);
1544 retry: 1544 retry:
1545 timeout = ADMIN_TIMEOUT; 1545 timeout = ADMIN_TIMEOUT;
1546 for (; i > 0; i--) { 1546 for (; i > 0; i--, sent++)
1547 struct nvme_queue *nvmeq = dev->queues[i]; 1547 if (nvme_delete_queue(dev->queues[i], opcode))
1548
1549 if (!pass)
1550 nvme_suspend_queue(nvmeq);
1551 if (nvme_delete_queue(nvmeq, opcode))
1552 break; 1548 break;
1553 ++sent; 1549
1554 }
1555 while (sent--) { 1550 while (sent--) {
1556 timeout = wait_for_completion_io_timeout(&dev->ioq_wait, timeout); 1551 timeout = wait_for_completion_io_timeout(&dev->ioq_wait, timeout);
1557 if (timeout == 0) 1552 if (timeout == 0)
@@ -1693,11 +1688,12 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)
1693 nvme_stop_queues(&dev->ctrl); 1688 nvme_stop_queues(&dev->ctrl);
1694 csts = readl(dev->bar + NVME_REG_CSTS); 1689 csts = readl(dev->bar + NVME_REG_CSTS);
1695 } 1690 }
1691
1692 for (i = dev->queue_count - 1; i > 0; i--)
1693 nvme_suspend_queue(dev->queues[i]);
1694
1696 if (csts & NVME_CSTS_CFS || !(csts & NVME_CSTS_RDY)) { 1695 if (csts & NVME_CSTS_CFS || !(csts & NVME_CSTS_RDY)) {
1697 for (i = dev->queue_count - 1; i >= 0; i--) { 1696 nvme_suspend_queue(dev->queues[0]);
1698 struct nvme_queue *nvmeq = dev->queues[i];
1699 nvme_suspend_queue(nvmeq);
1700 }
1701 } else { 1697 } else {
1702 nvme_disable_io_queues(dev); 1698 nvme_disable_io_queues(dev);
1703 nvme_disable_admin_queue(dev, shutdown); 1699 nvme_disable_admin_queue(dev, shutdown);
diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
index 3e3ce2b0424e..8d2875b4c56d 100644
--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c
@@ -12,13 +12,11 @@
12 * more details. 12 * more details.
13 */ 13 */
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15#include <linux/delay.h>
16#include <linux/module.h> 15#include <linux/module.h>
17#include <linux/init.h> 16#include <linux/init.h>
18#include <linux/slab.h> 17#include <linux/slab.h>
19#include <linux/err.h> 18#include <linux/err.h>
20#include <linux/string.h> 19#include <linux/string.h>
21#include <linux/jiffies.h>
22#include <linux/atomic.h> 20#include <linux/atomic.h>
23#include <linux/blk-mq.h> 21#include <linux/blk-mq.h>
24#include <linux/types.h> 22#include <linux/types.h>
@@ -26,7 +24,6 @@
26#include <linux/mutex.h> 24#include <linux/mutex.h>
27#include <linux/scatterlist.h> 25#include <linux/scatterlist.h>
28#include <linux/nvme.h> 26#include <linux/nvme.h>
29#include <linux/t10-pi.h>
30#include <asm/unaligned.h> 27#include <asm/unaligned.h>
31 28
32#include <rdma/ib_verbs.h> 29#include <rdma/ib_verbs.h>
@@ -169,7 +166,6 @@ MODULE_PARM_DESC(register_always,
169static int nvme_rdma_cm_handler(struct rdma_cm_id *cm_id, 166static int nvme_rdma_cm_handler(struct rdma_cm_id *cm_id,
170 struct rdma_cm_event *event); 167 struct rdma_cm_event *event);
171static void nvme_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc); 168static void nvme_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc);
172static int __nvme_rdma_del_ctrl(struct nvme_rdma_ctrl *ctrl);
173 169
174/* XXX: really should move to a generic header sooner or later.. */ 170/* XXX: really should move to a generic header sooner or later.. */
175static inline void put_unaligned_le24(u32 val, u8 *p) 171static inline void put_unaligned_le24(u32 val, u8 *p)
@@ -687,11 +683,6 @@ static void nvme_rdma_free_ctrl(struct nvme_ctrl *nctrl)
687 list_del(&ctrl->list); 683 list_del(&ctrl->list);
688 mutex_unlock(&nvme_rdma_ctrl_mutex); 684 mutex_unlock(&nvme_rdma_ctrl_mutex);
689 685
690 if (ctrl->ctrl.tagset) {
691 blk_cleanup_queue(ctrl->ctrl.connect_q);
692 blk_mq_free_tag_set(&ctrl->tag_set);
693 nvme_rdma_dev_put(ctrl->device);
694 }
695 kfree(ctrl->queues); 686 kfree(ctrl->queues);
696 nvmf_free_options(nctrl->opts); 687 nvmf_free_options(nctrl->opts);
697free_ctrl: 688free_ctrl:
@@ -748,8 +739,11 @@ static void nvme_rdma_reconnect_ctrl_work(struct work_struct *work)
748 changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE); 739 changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE);
749 WARN_ON_ONCE(!changed); 740 WARN_ON_ONCE(!changed);
750 741
751 if (ctrl->queue_count > 1) 742 if (ctrl->queue_count > 1) {
752 nvme_start_queues(&ctrl->ctrl); 743 nvme_start_queues(&ctrl->ctrl);
744 nvme_queue_scan(&ctrl->ctrl);
745 nvme_queue_async_events(&ctrl->ctrl);
746 }
753 747
754 dev_info(ctrl->ctrl.device, "Successfully reconnected\n"); 748 dev_info(ctrl->ctrl.device, "Successfully reconnected\n");
755 749
@@ -1269,7 +1263,7 @@ static int nvme_rdma_route_resolved(struct nvme_rdma_queue *queue)
1269{ 1263{
1270 struct nvme_rdma_ctrl *ctrl = queue->ctrl; 1264 struct nvme_rdma_ctrl *ctrl = queue->ctrl;
1271 struct rdma_conn_param param = { }; 1265 struct rdma_conn_param param = { };
1272 struct nvme_rdma_cm_req priv; 1266 struct nvme_rdma_cm_req priv = { };
1273 int ret; 1267 int ret;
1274 1268
1275 param.qp_num = queue->qp->qp_num; 1269 param.qp_num = queue->qp->qp_num;
@@ -1318,37 +1312,39 @@ out_destroy_queue_ib:
1318 * that caught the event. Since we hold the callout until the controller 1312 * that caught the event. Since we hold the callout until the controller
1319 * deletion is completed, we'll deadlock if the controller deletion will 1313 * deletion is completed, we'll deadlock if the controller deletion will
1320 * call rdma_destroy_id on this queue's cm_id. Thus, we claim ownership 1314 * call rdma_destroy_id on this queue's cm_id. Thus, we claim ownership
1321 * of destroying this queue before-hand, destroy the queue resources 1315 * of destroying this queue before-hand, destroy the queue resources,
1322 * after the controller deletion completed with the exception of destroying 1316 * then queue the controller deletion which won't destroy this queue and
1323 * the cm_id implicitely by returning a non-zero rc to the callout. 1317 * we destroy the cm_id implicitely by returning a non-zero rc to the callout.
1324 */ 1318 */
1325static int nvme_rdma_device_unplug(struct nvme_rdma_queue *queue) 1319static int nvme_rdma_device_unplug(struct nvme_rdma_queue *queue)
1326{ 1320{
1327 struct nvme_rdma_ctrl *ctrl = queue->ctrl; 1321 struct nvme_rdma_ctrl *ctrl = queue->ctrl;
1328 int ret, ctrl_deleted = 0; 1322 int ret;
1329 1323
1330 /* First disable the queue so ctrl delete won't free it */ 1324 /* Own the controller deletion */
1331 if (!test_and_clear_bit(NVME_RDMA_Q_CONNECTED, &queue->flags)) 1325 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_DELETING))
1332 goto out; 1326 return 0;
1333 1327
1334 /* delete the controller */ 1328 dev_warn(ctrl->ctrl.device,
1335 ret = __nvme_rdma_del_ctrl(ctrl); 1329 "Got rdma device removal event, deleting ctrl\n");
1336 if (!ret) {
1337 dev_warn(ctrl->ctrl.device,
1338 "Got rdma device removal event, deleting ctrl\n");
1339 flush_work(&ctrl->delete_work);
1340 1330
1341 /* Return non-zero so the cm_id will destroy implicitly */ 1331 /* Get rid of reconnect work if its running */
1342 ctrl_deleted = 1; 1332 cancel_delayed_work_sync(&ctrl->reconnect_work);
1343 1333
1334 /* Disable the queue so ctrl delete won't free it */
1335 if (test_and_clear_bit(NVME_RDMA_Q_CONNECTED, &queue->flags)) {
1344 /* Free this queue ourselves */ 1336 /* Free this queue ourselves */
1345 rdma_disconnect(queue->cm_id); 1337 nvme_rdma_stop_queue(queue);
1346 ib_drain_qp(queue->qp);
1347 nvme_rdma_destroy_queue_ib(queue); 1338 nvme_rdma_destroy_queue_ib(queue);
1339
1340 /* Return non-zero so the cm_id will destroy implicitly */
1341 ret = 1;
1348 } 1342 }
1349 1343
1350out: 1344 /* Queue controller deletion */
1351 return ctrl_deleted; 1345 queue_work(nvme_rdma_wq, &ctrl->delete_work);
1346 flush_work(&ctrl->delete_work);
1347 return ret;
1352} 1348}
1353 1349
1354static int nvme_rdma_cm_handler(struct rdma_cm_id *cm_id, 1350static int nvme_rdma_cm_handler(struct rdma_cm_id *cm_id,
@@ -1648,7 +1644,7 @@ static void nvme_rdma_shutdown_ctrl(struct nvme_rdma_ctrl *ctrl)
1648 nvme_rdma_free_io_queues(ctrl); 1644 nvme_rdma_free_io_queues(ctrl);
1649 } 1645 }
1650 1646
1651 if (ctrl->ctrl.state == NVME_CTRL_LIVE) 1647 if (test_bit(NVME_RDMA_Q_CONNECTED, &ctrl->queues[0].flags))
1652 nvme_shutdown_ctrl(&ctrl->ctrl); 1648 nvme_shutdown_ctrl(&ctrl->ctrl);
1653 1649
1654 blk_mq_stop_hw_queues(ctrl->ctrl.admin_q); 1650 blk_mq_stop_hw_queues(ctrl->ctrl.admin_q);
@@ -1657,15 +1653,27 @@ static void nvme_rdma_shutdown_ctrl(struct nvme_rdma_ctrl *ctrl)
1657 nvme_rdma_destroy_admin_queue(ctrl); 1653 nvme_rdma_destroy_admin_queue(ctrl);
1658} 1654}
1659 1655
1656static void __nvme_rdma_remove_ctrl(struct nvme_rdma_ctrl *ctrl, bool shutdown)
1657{
1658 nvme_uninit_ctrl(&ctrl->ctrl);
1659 if (shutdown)
1660 nvme_rdma_shutdown_ctrl(ctrl);
1661
1662 if (ctrl->ctrl.tagset) {
1663 blk_cleanup_queue(ctrl->ctrl.connect_q);
1664 blk_mq_free_tag_set(&ctrl->tag_set);
1665 nvme_rdma_dev_put(ctrl->device);
1666 }
1667
1668 nvme_put_ctrl(&ctrl->ctrl);
1669}
1670
1660static void nvme_rdma_del_ctrl_work(struct work_struct *work) 1671static void nvme_rdma_del_ctrl_work(struct work_struct *work)
1661{ 1672{
1662 struct nvme_rdma_ctrl *ctrl = container_of(work, 1673 struct nvme_rdma_ctrl *ctrl = container_of(work,
1663 struct nvme_rdma_ctrl, delete_work); 1674 struct nvme_rdma_ctrl, delete_work);
1664 1675
1665 nvme_remove_namespaces(&ctrl->ctrl); 1676 __nvme_rdma_remove_ctrl(ctrl, true);
1666 nvme_rdma_shutdown_ctrl(ctrl);
1667 nvme_uninit_ctrl(&ctrl->ctrl);
1668 nvme_put_ctrl(&ctrl->ctrl);
1669} 1677}
1670 1678
1671static int __nvme_rdma_del_ctrl(struct nvme_rdma_ctrl *ctrl) 1679static int __nvme_rdma_del_ctrl(struct nvme_rdma_ctrl *ctrl)
@@ -1698,9 +1706,7 @@ static void nvme_rdma_remove_ctrl_work(struct work_struct *work)
1698 struct nvme_rdma_ctrl *ctrl = container_of(work, 1706 struct nvme_rdma_ctrl *ctrl = container_of(work,
1699 struct nvme_rdma_ctrl, delete_work); 1707 struct nvme_rdma_ctrl, delete_work);
1700 1708
1701 nvme_remove_namespaces(&ctrl->ctrl); 1709 __nvme_rdma_remove_ctrl(ctrl, false);
1702 nvme_uninit_ctrl(&ctrl->ctrl);
1703 nvme_put_ctrl(&ctrl->ctrl);
1704} 1710}
1705 1711
1706static void nvme_rdma_reset_ctrl_work(struct work_struct *work) 1712static void nvme_rdma_reset_ctrl_work(struct work_struct *work)
@@ -1739,6 +1745,7 @@ static void nvme_rdma_reset_ctrl_work(struct work_struct *work)
1739 if (ctrl->queue_count > 1) { 1745 if (ctrl->queue_count > 1) {
1740 nvme_start_queues(&ctrl->ctrl); 1746 nvme_start_queues(&ctrl->ctrl);
1741 nvme_queue_scan(&ctrl->ctrl); 1747 nvme_queue_scan(&ctrl->ctrl);
1748 nvme_queue_async_events(&ctrl->ctrl);
1742 } 1749 }
1743 1750
1744 return; 1751 return;
diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index 2fac17a5ad53..47c564b5a289 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -13,7 +13,6 @@
13 */ 13 */
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/random.h>
17#include <generated/utsrelease.h> 16#include <generated/utsrelease.h>
18#include "nvmet.h" 17#include "nvmet.h"
19 18
@@ -83,7 +82,6 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
83{ 82{
84 struct nvmet_ctrl *ctrl = req->sq->ctrl; 83 struct nvmet_ctrl *ctrl = req->sq->ctrl;
85 struct nvme_id_ctrl *id; 84 struct nvme_id_ctrl *id;
86 u64 serial;
87 u16 status = 0; 85 u16 status = 0;
88 86
89 id = kzalloc(sizeof(*id), GFP_KERNEL); 87 id = kzalloc(sizeof(*id), GFP_KERNEL);
@@ -96,10 +94,8 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
96 id->vid = 0; 94 id->vid = 0;
97 id->ssvid = 0; 95 id->ssvid = 0;
98 96
99 /* generate a random serial number as our controllers are ephemeral: */
100 get_random_bytes(&serial, sizeof(serial));
101 memset(id->sn, ' ', sizeof(id->sn)); 97 memset(id->sn, ' ', sizeof(id->sn));
102 snprintf(id->sn, sizeof(id->sn), "%llx", serial); 98 snprintf(id->sn, sizeof(id->sn), "%llx", ctrl->serial);
103 99
104 memset(id->mn, ' ', sizeof(id->mn)); 100 memset(id->mn, ' ', sizeof(id->mn));
105 strncpy((char *)id->mn, "Linux", sizeof(id->mn)); 101 strncpy((char *)id->mn, "Linux", sizeof(id->mn));
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 8a891ca53367..6559d5afa7bf 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -13,6 +13,7 @@
13 */ 13 */
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/random.h>
16#include "nvmet.h" 17#include "nvmet.h"
17 18
18static struct nvmet_fabrics_ops *nvmet_transports[NVMF_TRTYPE_MAX]; 19static struct nvmet_fabrics_ops *nvmet_transports[NVMF_TRTYPE_MAX];
@@ -728,6 +729,9 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,
728 memcpy(ctrl->subsysnqn, subsysnqn, NVMF_NQN_SIZE); 729 memcpy(ctrl->subsysnqn, subsysnqn, NVMF_NQN_SIZE);
729 memcpy(ctrl->hostnqn, hostnqn, NVMF_NQN_SIZE); 730 memcpy(ctrl->hostnqn, hostnqn, NVMF_NQN_SIZE);
730 731
732 /* generate a random serial number as our controllers are ephemeral: */
733 get_random_bytes(&ctrl->serial, sizeof(ctrl->serial));
734
731 kref_init(&ctrl->ref); 735 kref_init(&ctrl->ref);
732 ctrl->subsys = subsys; 736 ctrl->subsys = subsys;
733 737
diff --git a/drivers/nvme/target/loop.c b/drivers/nvme/target/loop.c
index 94e782987cc9..7affd40a6b33 100644
--- a/drivers/nvme/target/loop.c
+++ b/drivers/nvme/target/loop.c
@@ -414,9 +414,8 @@ static void nvme_loop_del_ctrl_work(struct work_struct *work)
414 struct nvme_loop_ctrl *ctrl = container_of(work, 414 struct nvme_loop_ctrl *ctrl = container_of(work,
415 struct nvme_loop_ctrl, delete_work); 415 struct nvme_loop_ctrl, delete_work);
416 416
417 nvme_remove_namespaces(&ctrl->ctrl);
418 nvme_loop_shutdown_ctrl(ctrl);
419 nvme_uninit_ctrl(&ctrl->ctrl); 417 nvme_uninit_ctrl(&ctrl->ctrl);
418 nvme_loop_shutdown_ctrl(ctrl);
420 nvme_put_ctrl(&ctrl->ctrl); 419 nvme_put_ctrl(&ctrl->ctrl);
421} 420}
422 421
@@ -501,7 +500,6 @@ out_free_queues:
501 nvme_loop_destroy_admin_queue(ctrl); 500 nvme_loop_destroy_admin_queue(ctrl);
502out_disable: 501out_disable:
503 dev_warn(ctrl->ctrl.device, "Removing after reset failure\n"); 502 dev_warn(ctrl->ctrl.device, "Removing after reset failure\n");
504 nvme_remove_namespaces(&ctrl->ctrl);
505 nvme_uninit_ctrl(&ctrl->ctrl); 503 nvme_uninit_ctrl(&ctrl->ctrl);
506 nvme_put_ctrl(&ctrl->ctrl); 504 nvme_put_ctrl(&ctrl->ctrl);
507} 505}
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 57dd6d834c28..76b6eedccaf9 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -113,6 +113,7 @@ struct nvmet_ctrl {
113 113
114 struct mutex lock; 114 struct mutex lock;
115 u64 cap; 115 u64 cap;
116 u64 serial;
116 u32 cc; 117 u32 cc;
117 u32 csts; 118 u32 csts;
118 119
diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c
index e06d504bdf0c..b4d648536c3e 100644
--- a/drivers/nvme/target/rdma.c
+++ b/drivers/nvme/target/rdma.c
@@ -77,6 +77,7 @@ enum nvmet_rdma_queue_state {
77 NVMET_RDMA_Q_CONNECTING, 77 NVMET_RDMA_Q_CONNECTING,
78 NVMET_RDMA_Q_LIVE, 78 NVMET_RDMA_Q_LIVE,
79 NVMET_RDMA_Q_DISCONNECTING, 79 NVMET_RDMA_Q_DISCONNECTING,
80 NVMET_RDMA_IN_DEVICE_REMOVAL,
80}; 81};
81 82
82struct nvmet_rdma_queue { 83struct nvmet_rdma_queue {
@@ -615,15 +616,10 @@ static u16 nvmet_rdma_map_sgl_keyed(struct nvmet_rdma_rsp *rsp,
615 if (!len) 616 if (!len)
616 return 0; 617 return 0;
617 618
618 /* use the already allocated data buffer if possible */ 619 status = nvmet_rdma_alloc_sgl(&rsp->req.sg, &rsp->req.sg_cnt,
619 if (len <= NVMET_RDMA_INLINE_DATA_SIZE && rsp->queue->host_qid) { 620 len);
620 nvmet_rdma_use_inline_sg(rsp, len, 0); 621 if (status)
621 } else { 622 return status;
622 status = nvmet_rdma_alloc_sgl(&rsp->req.sg, &rsp->req.sg_cnt,
623 len);
624 if (status)
625 return status;
626 }
627 623
628 ret = rdma_rw_ctx_init(&rsp->rw, cm_id->qp, cm_id->port_num, 624 ret = rdma_rw_ctx_init(&rsp->rw, cm_id->qp, cm_id->port_num,
629 rsp->req.sg, rsp->req.sg_cnt, 0, addr, key, 625 rsp->req.sg, rsp->req.sg_cnt, 0, addr, key,
@@ -984,7 +980,10 @@ static void nvmet_rdma_release_queue_work(struct work_struct *w)
984 struct nvmet_rdma_device *dev = queue->dev; 980 struct nvmet_rdma_device *dev = queue->dev;
985 981
986 nvmet_rdma_free_queue(queue); 982 nvmet_rdma_free_queue(queue);
987 rdma_destroy_id(cm_id); 983
984 if (queue->state != NVMET_RDMA_IN_DEVICE_REMOVAL)
985 rdma_destroy_id(cm_id);
986
988 kref_put(&dev->ref, nvmet_rdma_free_dev); 987 kref_put(&dev->ref, nvmet_rdma_free_dev);
989} 988}
990 989
@@ -1233,8 +1232,9 @@ static void __nvmet_rdma_queue_disconnect(struct nvmet_rdma_queue *queue)
1233 switch (queue->state) { 1232 switch (queue->state) {
1234 case NVMET_RDMA_Q_CONNECTING: 1233 case NVMET_RDMA_Q_CONNECTING:
1235 case NVMET_RDMA_Q_LIVE: 1234 case NVMET_RDMA_Q_LIVE:
1236 disconnect = true;
1237 queue->state = NVMET_RDMA_Q_DISCONNECTING; 1235 queue->state = NVMET_RDMA_Q_DISCONNECTING;
1236 case NVMET_RDMA_IN_DEVICE_REMOVAL:
1237 disconnect = true;
1238 break; 1238 break;
1239 case NVMET_RDMA_Q_DISCONNECTING: 1239 case NVMET_RDMA_Q_DISCONNECTING:
1240 break; 1240 break;
@@ -1272,6 +1272,62 @@ static void nvmet_rdma_queue_connect_fail(struct rdma_cm_id *cm_id,
1272 schedule_work(&queue->release_work); 1272 schedule_work(&queue->release_work);
1273} 1273}
1274 1274
1275/**
1276 * nvme_rdma_device_removal() - Handle RDMA device removal
1277 * @queue: nvmet rdma queue (cm id qp_context)
1278 * @addr: nvmet address (cm_id context)
1279 *
1280 * DEVICE_REMOVAL event notifies us that the RDMA device is about
1281 * to unplug so we should take care of destroying our RDMA resources.
1282 * This event will be generated for each allocated cm_id.
1283 *
1284 * Note that this event can be generated on a normal queue cm_id
1285 * and/or a device bound listener cm_id (where in this case
1286 * queue will be null).
1287 *
1288 * we claim ownership on destroying the cm_id. For queues we move
1289 * the queue state to NVMET_RDMA_IN_DEVICE_REMOVAL and for port
1290 * we nullify the priv to prevent double cm_id destruction and destroying
1291 * the cm_id implicitely by returning a non-zero rc to the callout.
1292 */
1293static int nvmet_rdma_device_removal(struct rdma_cm_id *cm_id,
1294 struct nvmet_rdma_queue *queue)
1295{
1296 unsigned long flags;
1297
1298 if (!queue) {
1299 struct nvmet_port *port = cm_id->context;
1300
1301 /*
1302 * This is a listener cm_id. Make sure that
1303 * future remove_port won't invoke a double
1304 * cm_id destroy. use atomic xchg to make sure
1305 * we don't compete with remove_port.
1306 */
1307 if (xchg(&port->priv, NULL) != cm_id)
1308 return 0;
1309 } else {
1310 /*
1311 * This is a queue cm_id. Make sure that
1312 * release queue will not destroy the cm_id
1313 * and schedule all ctrl queues removal (only
1314 * if the queue is not disconnecting already).
1315 */
1316 spin_lock_irqsave(&queue->state_lock, flags);
1317 if (queue->state != NVMET_RDMA_Q_DISCONNECTING)
1318 queue->state = NVMET_RDMA_IN_DEVICE_REMOVAL;
1319 spin_unlock_irqrestore(&queue->state_lock, flags);
1320 nvmet_rdma_queue_disconnect(queue);
1321 flush_scheduled_work();
1322 }
1323
1324 /*
1325 * We need to return 1 so that the core will destroy
1326 * it's own ID. What a great API design..
1327 */
1328 return 1;
1329}
1330
1275static int nvmet_rdma_cm_handler(struct rdma_cm_id *cm_id, 1331static int nvmet_rdma_cm_handler(struct rdma_cm_id *cm_id,
1276 struct rdma_cm_event *event) 1332 struct rdma_cm_event *event)
1277{ 1333{
@@ -1294,20 +1350,11 @@ static int nvmet_rdma_cm_handler(struct rdma_cm_id *cm_id,
1294 break; 1350 break;
1295 case RDMA_CM_EVENT_ADDR_CHANGE: 1351 case RDMA_CM_EVENT_ADDR_CHANGE:
1296 case RDMA_CM_EVENT_DISCONNECTED: 1352 case RDMA_CM_EVENT_DISCONNECTED:
1297 case RDMA_CM_EVENT_DEVICE_REMOVAL:
1298 case RDMA_CM_EVENT_TIMEWAIT_EXIT: 1353 case RDMA_CM_EVENT_TIMEWAIT_EXIT:
1299 /* 1354 nvmet_rdma_queue_disconnect(queue);
1300 * We can get the device removal callback even for a 1355 break;
1301 * CM ID that we aren't actually using. In that case 1356 case RDMA_CM_EVENT_DEVICE_REMOVAL:
1302 * the context pointer is NULL, so we shouldn't try 1357 ret = nvmet_rdma_device_removal(cm_id, queue);
1303 * to disconnect a non-existing queue. But we also
1304 * need to return 1 so that the core will destroy
1305 * it's own ID. What a great API design..
1306 */
1307 if (queue)
1308 nvmet_rdma_queue_disconnect(queue);
1309 else
1310 ret = 1;
1311 break; 1358 break;
1312 case RDMA_CM_EVENT_REJECTED: 1359 case RDMA_CM_EVENT_REJECTED:
1313 case RDMA_CM_EVENT_UNREACHABLE: 1360 case RDMA_CM_EVENT_UNREACHABLE:
@@ -1396,9 +1443,10 @@ out_destroy_id:
1396 1443
1397static void nvmet_rdma_remove_port(struct nvmet_port *port) 1444static void nvmet_rdma_remove_port(struct nvmet_port *port)
1398{ 1445{
1399 struct rdma_cm_id *cm_id = port->priv; 1446 struct rdma_cm_id *cm_id = xchg(&port->priv, NULL);
1400 1447
1401 rdma_destroy_id(cm_id); 1448 if (cm_id)
1449 rdma_destroy_id(cm_id);
1402} 1450}
1403 1451
1404static struct nvmet_fabrics_ops nvmet_rdma_ops = { 1452static struct nvmet_fabrics_ops nvmet_rdma_ops = {
diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c
index 6ccb994bdfcb..c494613c1909 100644
--- a/drivers/perf/arm_pmu.c
+++ b/drivers/perf/arm_pmu.c
@@ -688,7 +688,7 @@ static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler)
688 return 0; 688 return 0;
689} 689}
690 690
691static DEFINE_MUTEX(arm_pmu_mutex); 691static DEFINE_SPINLOCK(arm_pmu_lock);
692static LIST_HEAD(arm_pmu_list); 692static LIST_HEAD(arm_pmu_list);
693 693
694/* 694/*
@@ -701,7 +701,7 @@ static int arm_perf_starting_cpu(unsigned int cpu)
701{ 701{
702 struct arm_pmu *pmu; 702 struct arm_pmu *pmu;
703 703
704 mutex_lock(&arm_pmu_mutex); 704 spin_lock(&arm_pmu_lock);
705 list_for_each_entry(pmu, &arm_pmu_list, entry) { 705 list_for_each_entry(pmu, &arm_pmu_list, entry) {
706 706
707 if (!cpumask_test_cpu(cpu, &pmu->supported_cpus)) 707 if (!cpumask_test_cpu(cpu, &pmu->supported_cpus))
@@ -709,7 +709,7 @@ static int arm_perf_starting_cpu(unsigned int cpu)
709 if (pmu->reset) 709 if (pmu->reset)
710 pmu->reset(pmu); 710 pmu->reset(pmu);
711 } 711 }
712 mutex_unlock(&arm_pmu_mutex); 712 spin_unlock(&arm_pmu_lock);
713 return 0; 713 return 0;
714} 714}
715 715
@@ -821,9 +821,9 @@ static int cpu_pmu_init(struct arm_pmu *cpu_pmu)
821 if (!cpu_hw_events) 821 if (!cpu_hw_events)
822 return -ENOMEM; 822 return -ENOMEM;
823 823
824 mutex_lock(&arm_pmu_mutex); 824 spin_lock(&arm_pmu_lock);
825 list_add_tail(&cpu_pmu->entry, &arm_pmu_list); 825 list_add_tail(&cpu_pmu->entry, &arm_pmu_list);
826 mutex_unlock(&arm_pmu_mutex); 826 spin_unlock(&arm_pmu_lock);
827 827
828 err = cpu_pm_pmu_register(cpu_pmu); 828 err = cpu_pm_pmu_register(cpu_pmu);
829 if (err) 829 if (err)
@@ -859,9 +859,9 @@ static int cpu_pmu_init(struct arm_pmu *cpu_pmu)
859 return 0; 859 return 0;
860 860
861out_unregister: 861out_unregister:
862 mutex_lock(&arm_pmu_mutex); 862 spin_lock(&arm_pmu_lock);
863 list_del(&cpu_pmu->entry); 863 list_del(&cpu_pmu->entry);
864 mutex_unlock(&arm_pmu_mutex); 864 spin_unlock(&arm_pmu_lock);
865 free_percpu(cpu_hw_events); 865 free_percpu(cpu_hw_events);
866 return err; 866 return err;
867} 867}
@@ -869,9 +869,9 @@ out_unregister:
869static void cpu_pmu_destroy(struct arm_pmu *cpu_pmu) 869static void cpu_pmu_destroy(struct arm_pmu *cpu_pmu)
870{ 870{
871 cpu_pm_pmu_unregister(cpu_pmu); 871 cpu_pm_pmu_unregister(cpu_pmu);
872 mutex_lock(&arm_pmu_mutex); 872 spin_lock(&arm_pmu_lock);
873 list_del(&cpu_pmu->entry); 873 list_del(&cpu_pmu->entry);
874 mutex_unlock(&arm_pmu_mutex); 874 spin_unlock(&arm_pmu_lock);
875 free_percpu(cpu_pmu->hw_events); 875 free_percpu(cpu_pmu->hw_events);
876} 876}
877 877
@@ -967,11 +967,12 @@ static int of_pmu_irq_cfg(struct arm_pmu *pmu)
967 967
968 /* If we didn't manage to parse anything, try the interrupt affinity */ 968 /* If we didn't manage to parse anything, try the interrupt affinity */
969 if (cpumask_weight(&pmu->supported_cpus) == 0) { 969 if (cpumask_weight(&pmu->supported_cpus) == 0) {
970 if (!using_spi) { 970 int irq = platform_get_irq(pdev, 0);
971
972 if (irq_is_percpu(irq)) {
971 /* If using PPIs, check the affinity of the partition */ 973 /* If using PPIs, check the affinity of the partition */
972 int ret, irq; 974 int ret;
973 975
974 irq = platform_get_irq(pdev, 0);
975 ret = irq_get_percpu_devid_partition(irq, &pmu->supported_cpus); 976 ret = irq_get_percpu_devid_partition(irq, &pmu->supported_cpus);
976 if (ret) { 977 if (ret) {
977 kfree(irqs); 978 kfree(irqs);
diff --git a/drivers/platform/x86/dell-wmi.c b/drivers/platform/x86/dell-wmi.c
index d2bc092defd7..da2fe18162e1 100644
--- a/drivers/platform/x86/dell-wmi.c
+++ b/drivers/platform/x86/dell-wmi.c
@@ -110,8 +110,8 @@ static const struct key_entry dell_wmi_keymap_type_0000[] __initconst = {
110 /* BIOS error detected */ 110 /* BIOS error detected */
111 { KE_IGNORE, 0xe00d, { KEY_RESERVED } }, 111 { KE_IGNORE, 0xe00d, { KEY_RESERVED } },
112 112
113 /* Unknown, defined in ACPI DSDT */ 113 /* Battery was removed or inserted */
114 /* { KE_IGNORE, 0xe00e, { KEY_RESERVED } }, */ 114 { KE_IGNORE, 0xe00e, { KEY_RESERVED } },
115 115
116 /* Wifi Catcher */ 116 /* Wifi Catcher */
117 { KE_KEY, 0xe011, { KEY_PROG2 } }, 117 { KE_KEY, 0xe011, { KEY_PROG2 } },
diff --git a/drivers/rapidio/rio_cm.c b/drivers/rapidio/rio_cm.c
index cecc15a880de..3fa17ac8df54 100644
--- a/drivers/rapidio/rio_cm.c
+++ b/drivers/rapidio/rio_cm.c
@@ -1080,8 +1080,8 @@ static int riocm_send_ack(struct rio_channel *ch)
1080static struct rio_channel *riocm_ch_accept(u16 ch_id, u16 *new_ch_id, 1080static struct rio_channel *riocm_ch_accept(u16 ch_id, u16 *new_ch_id,
1081 long timeout) 1081 long timeout)
1082{ 1082{
1083 struct rio_channel *ch = NULL; 1083 struct rio_channel *ch;
1084 struct rio_channel *new_ch = NULL; 1084 struct rio_channel *new_ch;
1085 struct conn_req *req; 1085 struct conn_req *req;
1086 struct cm_peer *peer; 1086 struct cm_peer *peer;
1087 int found = 0; 1087 int found = 0;
@@ -1155,6 +1155,7 @@ static struct rio_channel *riocm_ch_accept(u16 ch_id, u16 *new_ch_id,
1155 1155
1156 spin_unlock_bh(&ch->lock); 1156 spin_unlock_bh(&ch->lock);
1157 riocm_put_channel(ch); 1157 riocm_put_channel(ch);
1158 ch = NULL;
1158 kfree(req); 1159 kfree(req);
1159 1160
1160 down_read(&rdev_sem); 1161 down_read(&rdev_sem);
@@ -1172,7 +1173,7 @@ static struct rio_channel *riocm_ch_accept(u16 ch_id, u16 *new_ch_id,
1172 if (!found) { 1173 if (!found) {
1173 /* If peer device object not found, simply ignore the request */ 1174 /* If peer device object not found, simply ignore the request */
1174 err = -ENODEV; 1175 err = -ENODEV;
1175 goto err_nodev; 1176 goto err_put_new_ch;
1176 } 1177 }
1177 1178
1178 new_ch->rdev = peer->rdev; 1179 new_ch->rdev = peer->rdev;
@@ -1184,15 +1185,16 @@ static struct rio_channel *riocm_ch_accept(u16 ch_id, u16 *new_ch_id,
1184 1185
1185 *new_ch_id = new_ch->id; 1186 *new_ch_id = new_ch->id;
1186 return new_ch; 1187 return new_ch;
1188
1189err_put_new_ch:
1190 spin_lock_bh(&idr_lock);
1191 idr_remove(&ch_idr, new_ch->id);
1192 spin_unlock_bh(&idr_lock);
1193 riocm_put_channel(new_ch);
1194
1187err_put: 1195err_put:
1188 riocm_put_channel(ch); 1196 if (ch)
1189err_nodev: 1197 riocm_put_channel(ch);
1190 if (new_ch) {
1191 spin_lock_bh(&idr_lock);
1192 idr_remove(&ch_idr, new_ch->id);
1193 spin_unlock_bh(&idr_lock);
1194 riocm_put_channel(new_ch);
1195 }
1196 *new_ch_id = 0; 1198 *new_ch_id = 0;
1197 return ERR_PTR(err); 1199 return ERR_PTR(err);
1198} 1200}
diff --git a/drivers/s390/virtio/Makefile b/drivers/s390/virtio/Makefile
index 241891a57caf..df40692a9011 100644
--- a/drivers/s390/virtio/Makefile
+++ b/drivers/s390/virtio/Makefile
@@ -6,4 +6,8 @@
6# it under the terms of the GNU General Public License (version 2 only) 6# it under the terms of the GNU General Public License (version 2 only)
7# as published by the Free Software Foundation. 7# as published by the Free Software Foundation.
8 8
9obj-$(CONFIG_S390_GUEST) += kvm_virtio.o virtio_ccw.o 9s390-virtio-objs := virtio_ccw.o
10ifdef CONFIG_S390_GUEST_OLD_TRANSPORT
11s390-virtio-objs += kvm_virtio.o
12endif
13obj-$(CONFIG_S390_GUEST) += $(s390-virtio-objs)
diff --git a/drivers/s390/virtio/kvm_virtio.c b/drivers/s390/virtio/kvm_virtio.c
index 1d060fd293a3..5e5c11f37b24 100644
--- a/drivers/s390/virtio/kvm_virtio.c
+++ b/drivers/s390/virtio/kvm_virtio.c
@@ -458,6 +458,8 @@ static int __init kvm_devices_init(void)
458 if (test_devices_support(total_memory_size) < 0) 458 if (test_devices_support(total_memory_size) < 0)
459 return -ENODEV; 459 return -ENODEV;
460 460
461 pr_warn("The s390-virtio transport is deprecated. Please switch to a modern host providing virtio-ccw.\n");
462
461 rc = vmem_add_mapping(total_memory_size, PAGE_SIZE); 463 rc = vmem_add_mapping(total_memory_size, PAGE_SIZE);
462 if (rc) 464 if (rc)
463 return rc; 465 return rc;
@@ -482,7 +484,7 @@ static int __init kvm_devices_init(void)
482} 484}
483 485
484/* code for early console output with virtio_console */ 486/* code for early console output with virtio_console */
485static __init int early_put_chars(u32 vtermno, const char *buf, int count) 487static int early_put_chars(u32 vtermno, const char *buf, int count)
486{ 488{
487 char scratch[17]; 489 char scratch[17];
488 unsigned int len = count; 490 unsigned int len = count;
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index bf85974be862..17d04c702e1b 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -10410,8 +10410,11 @@ static int ipr_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
10410 __ipr_remove(pdev); 10410 __ipr_remove(pdev);
10411 return rc; 10411 return rc;
10412 } 10412 }
10413 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
10414 ioa_cfg->scan_enabled = 1;
10415 schedule_work(&ioa_cfg->work_q);
10416 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
10413 10417
10414 scsi_scan_host(ioa_cfg->host);
10415 ioa_cfg->iopoll_weight = ioa_cfg->chip_cfg->iopoll_weight; 10418 ioa_cfg->iopoll_weight = ioa_cfg->chip_cfg->iopoll_weight;
10416 10419
10417 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) { 10420 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
@@ -10421,10 +10424,8 @@ static int ipr_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
10421 } 10424 }
10422 } 10425 }
10423 10426
10424 spin_lock_irqsave(ioa_cfg->host->host_lock, flags); 10427 scsi_scan_host(ioa_cfg->host);
10425 ioa_cfg->scan_enabled = 1; 10428
10426 schedule_work(&ioa_cfg->work_q);
10427 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
10428 return 0; 10429 return 0;
10429} 10430}
10430 10431
diff --git a/drivers/thermal/clock_cooling.c b/drivers/thermal/clock_cooling.c
index 1b4ff0f4c716..ed5dd0e88657 100644
--- a/drivers/thermal/clock_cooling.c
+++ b/drivers/thermal/clock_cooling.c
@@ -426,6 +426,7 @@ clock_cooling_register(struct device *dev, const char *clock_name)
426 if (!ccdev) 426 if (!ccdev)
427 return ERR_PTR(-ENOMEM); 427 return ERR_PTR(-ENOMEM);
428 428
429 mutex_init(&ccdev->lock);
429 ccdev->dev = dev; 430 ccdev->dev = dev;
430 ccdev->clk = devm_clk_get(dev, clock_name); 431 ccdev->clk = devm_clk_get(dev, clock_name);
431 if (IS_ERR(ccdev->clk)) 432 if (IS_ERR(ccdev->clk))
diff --git a/drivers/thermal/fair_share.c b/drivers/thermal/fair_share.c
index 34fe36504a55..68bd1b569118 100644
--- a/drivers/thermal/fair_share.c
+++ b/drivers/thermal/fair_share.c
@@ -116,7 +116,9 @@ static int fair_share_throttle(struct thermal_zone_device *tz, int trip)
116 instance->target = get_target_state(tz, cdev, percentage, 116 instance->target = get_target_state(tz, cdev, percentage,
117 cur_trip_level); 117 cur_trip_level);
118 118
119 mutex_lock(&instance->cdev->lock);
119 instance->cdev->updated = false; 120 instance->cdev->updated = false;
121 mutex_unlock(&instance->cdev->lock);
120 thermal_cdev_update(cdev); 122 thermal_cdev_update(cdev);
121 } 123 }
122 return 0; 124 return 0;
diff --git a/drivers/thermal/gov_bang_bang.c b/drivers/thermal/gov_bang_bang.c
index fc52016d4e85..bb118a152cbb 100644
--- a/drivers/thermal/gov_bang_bang.c
+++ b/drivers/thermal/gov_bang_bang.c
@@ -71,7 +71,9 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
71 dev_dbg(&instance->cdev->device, "target=%d\n", 71 dev_dbg(&instance->cdev->device, "target=%d\n",
72 (int)instance->target); 72 (int)instance->target);
73 73
74 mutex_lock(&instance->cdev->lock);
74 instance->cdev->updated = false; /* cdev needs update */ 75 instance->cdev->updated = false; /* cdev needs update */
76 mutex_unlock(&instance->cdev->lock);
75 } 77 }
76 78
77 mutex_unlock(&tz->lock); 79 mutex_unlock(&tz->lock);
diff --git a/drivers/thermal/intel_pch_thermal.c b/drivers/thermal/intel_pch_thermal.c
index 6a6ec1c95a7a..9b4815e81b0d 100644
--- a/drivers/thermal/intel_pch_thermal.c
+++ b/drivers/thermal/intel_pch_thermal.c
@@ -21,6 +21,7 @@
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/pci.h> 22#include <linux/pci.h>
23#include <linux/thermal.h> 23#include <linux/thermal.h>
24#include <linux/pm.h>
24 25
25/* Intel PCH thermal Device IDs */ 26/* Intel PCH thermal Device IDs */
26#define PCH_THERMAL_DID_WPT 0x9CA4 /* Wildcat Point */ 27#define PCH_THERMAL_DID_WPT 0x9CA4 /* Wildcat Point */
@@ -65,6 +66,7 @@ struct pch_thermal_device {
65 unsigned long crt_temp; 66 unsigned long crt_temp;
66 int hot_trip_id; 67 int hot_trip_id;
67 unsigned long hot_temp; 68 unsigned long hot_temp;
69 bool bios_enabled;
68}; 70};
69 71
70static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips) 72static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips)
@@ -75,8 +77,10 @@ static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips)
75 *nr_trips = 0; 77 *nr_trips = 0;
76 78
77 /* Check if BIOS has already enabled thermal sensor */ 79 /* Check if BIOS has already enabled thermal sensor */
78 if (WPT_TSS_TSDSS & readb(ptd->hw_base + WPT_TSS)) 80 if (WPT_TSS_TSDSS & readb(ptd->hw_base + WPT_TSS)) {
81 ptd->bios_enabled = true;
79 goto read_trips; 82 goto read_trips;
83 }
80 84
81 tsel = readb(ptd->hw_base + WPT_TSEL); 85 tsel = readb(ptd->hw_base + WPT_TSEL);
82 /* 86 /*
@@ -130,9 +134,39 @@ static int pch_wpt_get_temp(struct pch_thermal_device *ptd, int *temp)
130 return 0; 134 return 0;
131} 135}
132 136
137static int pch_wpt_suspend(struct pch_thermal_device *ptd)
138{
139 u8 tsel;
140
141 if (ptd->bios_enabled)
142 return 0;
143
144 tsel = readb(ptd->hw_base + WPT_TSEL);
145
146 writeb(tsel & 0xFE, ptd->hw_base + WPT_TSEL);
147
148 return 0;
149}
150
151static int pch_wpt_resume(struct pch_thermal_device *ptd)
152{
153 u8 tsel;
154
155 if (ptd->bios_enabled)
156 return 0;
157
158 tsel = readb(ptd->hw_base + WPT_TSEL);
159
160 writeb(tsel | WPT_TSEL_ETS, ptd->hw_base + WPT_TSEL);
161
162 return 0;
163}
164
133struct pch_dev_ops { 165struct pch_dev_ops {
134 int (*hw_init)(struct pch_thermal_device *ptd, int *nr_trips); 166 int (*hw_init)(struct pch_thermal_device *ptd, int *nr_trips);
135 int (*get_temp)(struct pch_thermal_device *ptd, int *temp); 167 int (*get_temp)(struct pch_thermal_device *ptd, int *temp);
168 int (*suspend)(struct pch_thermal_device *ptd);
169 int (*resume)(struct pch_thermal_device *ptd);
136}; 170};
137 171
138 172
@@ -140,6 +174,8 @@ struct pch_dev_ops {
140static const struct pch_dev_ops pch_dev_ops_wpt = { 174static const struct pch_dev_ops pch_dev_ops_wpt = {
141 .hw_init = pch_wpt_init, 175 .hw_init = pch_wpt_init,
142 .get_temp = pch_wpt_get_temp, 176 .get_temp = pch_wpt_get_temp,
177 .suspend = pch_wpt_suspend,
178 .resume = pch_wpt_resume,
143}; 179};
144 180
145static int pch_thermal_get_temp(struct thermal_zone_device *tzd, int *temp) 181static int pch_thermal_get_temp(struct thermal_zone_device *tzd, int *temp)
@@ -269,6 +305,22 @@ static void intel_pch_thermal_remove(struct pci_dev *pdev)
269 pci_disable_device(pdev); 305 pci_disable_device(pdev);
270} 306}
271 307
308static int intel_pch_thermal_suspend(struct device *device)
309{
310 struct pci_dev *pdev = to_pci_dev(device);
311 struct pch_thermal_device *ptd = pci_get_drvdata(pdev);
312
313 return ptd->ops->suspend(ptd);
314}
315
316static int intel_pch_thermal_resume(struct device *device)
317{
318 struct pci_dev *pdev = to_pci_dev(device);
319 struct pch_thermal_device *ptd = pci_get_drvdata(pdev);
320
321 return ptd->ops->resume(ptd);
322}
323
272static struct pci_device_id intel_pch_thermal_id[] = { 324static struct pci_device_id intel_pch_thermal_id[] = {
273 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_WPT) }, 325 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_WPT) },
274 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_SKL) }, 326 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_SKL) },
@@ -276,11 +328,17 @@ static struct pci_device_id intel_pch_thermal_id[] = {
276}; 328};
277MODULE_DEVICE_TABLE(pci, intel_pch_thermal_id); 329MODULE_DEVICE_TABLE(pci, intel_pch_thermal_id);
278 330
331static const struct dev_pm_ops intel_pch_pm_ops = {
332 .suspend = intel_pch_thermal_suspend,
333 .resume = intel_pch_thermal_resume,
334};
335
279static struct pci_driver intel_pch_thermal_driver = { 336static struct pci_driver intel_pch_thermal_driver = {
280 .name = "intel_pch_thermal", 337 .name = "intel_pch_thermal",
281 .id_table = intel_pch_thermal_id, 338 .id_table = intel_pch_thermal_id,
282 .probe = intel_pch_thermal_probe, 339 .probe = intel_pch_thermal_probe,
283 .remove = intel_pch_thermal_remove, 340 .remove = intel_pch_thermal_remove,
341 .driver.pm = &intel_pch_pm_ops,
284}; 342};
285 343
286module_pci_driver(intel_pch_thermal_driver); 344module_pci_driver(intel_pch_thermal_driver);
diff --git a/drivers/thermal/intel_powerclamp.c b/drivers/thermal/intel_powerclamp.c
index 015ce2eb6eb7..0e4dc0afcfd2 100644
--- a/drivers/thermal/intel_powerclamp.c
+++ b/drivers/thermal/intel_powerclamp.c
@@ -388,7 +388,7 @@ static int clamp_thread(void *arg)
388 int sleeptime; 388 int sleeptime;
389 unsigned long target_jiffies; 389 unsigned long target_jiffies;
390 unsigned int guard; 390 unsigned int guard;
391 unsigned int compensation = 0; 391 unsigned int compensated_ratio;
392 int interval; /* jiffies to sleep for each attempt */ 392 int interval; /* jiffies to sleep for each attempt */
393 unsigned int duration_jiffies = msecs_to_jiffies(duration); 393 unsigned int duration_jiffies = msecs_to_jiffies(duration);
394 unsigned int window_size_now; 394 unsigned int window_size_now;
@@ -409,8 +409,11 @@ static int clamp_thread(void *arg)
409 * c-states, thus we need to compensate the injected idle ratio 409 * c-states, thus we need to compensate the injected idle ratio
410 * to achieve the actual target reported by the HW. 410 * to achieve the actual target reported by the HW.
411 */ 411 */
412 compensation = get_compensation(target_ratio); 412 compensated_ratio = target_ratio +
413 interval = duration_jiffies*100/(target_ratio+compensation); 413 get_compensation(target_ratio);
414 if (compensated_ratio <= 0)
415 compensated_ratio = 1;
416 interval = duration_jiffies * 100 / compensated_ratio;
414 417
415 /* align idle time */ 418 /* align idle time */
416 target_jiffies = roundup(jiffies, interval); 419 target_jiffies = roundup(jiffies, interval);
@@ -647,8 +650,8 @@ static int powerclamp_set_cur_state(struct thermal_cooling_device *cdev,
647 goto exit_set; 650 goto exit_set;
648 } else if (set_target_ratio > 0 && new_target_ratio == 0) { 651 } else if (set_target_ratio > 0 && new_target_ratio == 0) {
649 pr_info("Stop forced idle injection\n"); 652 pr_info("Stop forced idle injection\n");
650 set_target_ratio = 0;
651 end_power_clamp(); 653 end_power_clamp();
654 set_target_ratio = 0;
652 } else /* adjust currently running */ { 655 } else /* adjust currently running */ {
653 set_target_ratio = new_target_ratio; 656 set_target_ratio = new_target_ratio;
654 /* make new set_target_ratio visible to other cpus */ 657 /* make new set_target_ratio visible to other cpus */
diff --git a/drivers/thermal/power_allocator.c b/drivers/thermal/power_allocator.c
index 2f1a863a8e15..b4d3116cfdaf 100644
--- a/drivers/thermal/power_allocator.c
+++ b/drivers/thermal/power_allocator.c
@@ -529,7 +529,9 @@ static void allow_maximum_power(struct thermal_zone_device *tz)
529 continue; 529 continue;
530 530
531 instance->target = 0; 531 instance->target = 0;
532 mutex_lock(&instance->cdev->lock);
532 instance->cdev->updated = false; 533 instance->cdev->updated = false;
534 mutex_unlock(&instance->cdev->lock);
533 thermal_cdev_update(instance->cdev); 535 thermal_cdev_update(instance->cdev);
534 } 536 }
535} 537}
diff --git a/drivers/thermal/step_wise.c b/drivers/thermal/step_wise.c
index ea9366ad3e6b..bcef2e7c4ec9 100644
--- a/drivers/thermal/step_wise.c
+++ b/drivers/thermal/step_wise.c
@@ -175,7 +175,9 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
175 update_passive_instance(tz, trip_type, -1); 175 update_passive_instance(tz, trip_type, -1);
176 176
177 instance->initialized = true; 177 instance->initialized = true;
178 mutex_lock(&instance->cdev->lock);
178 instance->cdev->updated = false; /* cdev needs update */ 179 instance->cdev->updated = false; /* cdev needs update */
180 mutex_unlock(&instance->cdev->lock);
179 } 181 }
180 182
181 mutex_unlock(&tz->lock); 183 mutex_unlock(&tz->lock);
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 5133cd1e10b7..e2fc6161dded 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1093,7 +1093,9 @@ int power_actor_set_power(struct thermal_cooling_device *cdev,
1093 return ret; 1093 return ret;
1094 1094
1095 instance->target = state; 1095 instance->target = state;
1096 mutex_lock(&cdev->lock);
1096 cdev->updated = false; 1097 cdev->updated = false;
1098 mutex_unlock(&cdev->lock);
1097 thermal_cdev_update(cdev); 1099 thermal_cdev_update(cdev);
1098 1100
1099 return 0; 1101 return 0;
@@ -1623,11 +1625,13 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev)
1623 struct thermal_instance *instance; 1625 struct thermal_instance *instance;
1624 unsigned long target = 0; 1626 unsigned long target = 0;
1625 1627
1628 mutex_lock(&cdev->lock);
1626 /* cooling device is updated*/ 1629 /* cooling device is updated*/
1627 if (cdev->updated) 1630 if (cdev->updated) {
1631 mutex_unlock(&cdev->lock);
1628 return; 1632 return;
1633 }
1629 1634
1630 mutex_lock(&cdev->lock);
1631 /* Make sure cdev enters the deepest cooling state */ 1635 /* Make sure cdev enters the deepest cooling state */
1632 list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) { 1636 list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) {
1633 dev_dbg(&cdev->device, "zone%d->target=%lu\n", 1637 dev_dbg(&cdev->device, "zone%d->target=%lu\n",
@@ -1637,9 +1641,9 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev)
1637 if (instance->target > target) 1641 if (instance->target > target)
1638 target = instance->target; 1642 target = instance->target;
1639 } 1643 }
1640 mutex_unlock(&cdev->lock);
1641 cdev->ops->set_cur_state(cdev, target); 1644 cdev->ops->set_cur_state(cdev, target);
1642 cdev->updated = true; 1645 cdev->updated = true;
1646 mutex_unlock(&cdev->lock);
1643 trace_cdev_update(cdev, target); 1647 trace_cdev_update(cdev, target);
1644 dev_dbg(&cdev->device, "set to state %lu\n", target); 1648 dev_dbg(&cdev->device, "set to state %lu\n", target);
1645} 1649}
diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
index 06fd2ed9ef9d..c41c7742903a 100644
--- a/drivers/thermal/thermal_hwmon.c
+++ b/drivers/thermal/thermal_hwmon.c
@@ -232,6 +232,7 @@ int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
232 232
233 return result; 233 return result;
234} 234}
235EXPORT_SYMBOL_GPL(thermal_add_hwmon_sysfs);
235 236
236void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) 237void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
237{ 238{
@@ -270,3 +271,4 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
270 hwmon_device_unregister(hwmon->device); 271 hwmon_device_unregister(hwmon->device);
271 kfree(hwmon); 272 kfree(hwmon);
272} 273}
274EXPORT_SYMBOL_GPL(thermal_remove_hwmon_sysfs);
diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
index 15ecfc9c5f6c..152b43822ef1 100644
--- a/drivers/vfio/pci/vfio_pci_intrs.c
+++ b/drivers/vfio/pci/vfio_pci_intrs.c
@@ -564,67 +564,80 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_device *vdev,
564} 564}
565 565
566static int vfio_pci_set_ctx_trigger_single(struct eventfd_ctx **ctx, 566static int vfio_pci_set_ctx_trigger_single(struct eventfd_ctx **ctx,
567 uint32_t flags, void *data) 567 unsigned int count, uint32_t flags,
568 void *data)
568{ 569{
569 int32_t fd = *(int32_t *)data;
570
571 if (!(flags & VFIO_IRQ_SET_DATA_TYPE_MASK))
572 return -EINVAL;
573
574 /* DATA_NONE/DATA_BOOL enables loopback testing */ 570 /* DATA_NONE/DATA_BOOL enables loopback testing */
575 if (flags & VFIO_IRQ_SET_DATA_NONE) { 571 if (flags & VFIO_IRQ_SET_DATA_NONE) {
576 if (*ctx) 572 if (*ctx) {
577 eventfd_signal(*ctx, 1); 573 if (count) {
578 return 0; 574 eventfd_signal(*ctx, 1);
575 } else {
576 eventfd_ctx_put(*ctx);
577 *ctx = NULL;
578 }
579 return 0;
580 }
579 } else if (flags & VFIO_IRQ_SET_DATA_BOOL) { 581 } else if (flags & VFIO_IRQ_SET_DATA_BOOL) {
580 uint8_t trigger = *(uint8_t *)data; 582 uint8_t trigger;
583
584 if (!count)
585 return -EINVAL;
586
587 trigger = *(uint8_t *)data;
581 if (trigger && *ctx) 588 if (trigger && *ctx)
582 eventfd_signal(*ctx, 1); 589 eventfd_signal(*ctx, 1);
583 return 0;
584 }
585 590
586 /* Handle SET_DATA_EVENTFD */
587 if (fd == -1) {
588 if (*ctx)
589 eventfd_ctx_put(*ctx);
590 *ctx = NULL;
591 return 0; 591 return 0;
592 } else if (fd >= 0) { 592 } else if (flags & VFIO_IRQ_SET_DATA_EVENTFD) {
593 struct eventfd_ctx *efdctx; 593 int32_t fd;
594 efdctx = eventfd_ctx_fdget(fd); 594
595 if (IS_ERR(efdctx)) 595 if (!count)
596 return PTR_ERR(efdctx); 596 return -EINVAL;
597 if (*ctx) 597
598 eventfd_ctx_put(*ctx); 598 fd = *(int32_t *)data;
599 *ctx = efdctx; 599 if (fd == -1) {
600 if (*ctx)
601 eventfd_ctx_put(*ctx);
602 *ctx = NULL;
603 } else if (fd >= 0) {
604 struct eventfd_ctx *efdctx;
605
606 efdctx = eventfd_ctx_fdget(fd);
607 if (IS_ERR(efdctx))
608 return PTR_ERR(efdctx);
609
610 if (*ctx)
611 eventfd_ctx_put(*ctx);
612
613 *ctx = efdctx;
614 }
600 return 0; 615 return 0;
601 } else 616 }
602 return -EINVAL; 617
618 return -EINVAL;
603} 619}
604 620
605static int vfio_pci_set_err_trigger(struct vfio_pci_device *vdev, 621static int vfio_pci_set_err_trigger(struct vfio_pci_device *vdev,
606 unsigned index, unsigned start, 622 unsigned index, unsigned start,
607 unsigned count, uint32_t flags, void *data) 623 unsigned count, uint32_t flags, void *data)
608{ 624{
609 if (index != VFIO_PCI_ERR_IRQ_INDEX) 625 if (index != VFIO_PCI_ERR_IRQ_INDEX || start != 0 || count > 1)
610 return -EINVAL; 626 return -EINVAL;
611 627
612 /* 628 return vfio_pci_set_ctx_trigger_single(&vdev->err_trigger,
613 * We should sanitize start & count, but that wasn't caught 629 count, flags, data);
614 * originally, so this IRQ index must forever ignore them :-(
615 */
616
617 return vfio_pci_set_ctx_trigger_single(&vdev->err_trigger, flags, data);
618} 630}
619 631
620static int vfio_pci_set_req_trigger(struct vfio_pci_device *vdev, 632static int vfio_pci_set_req_trigger(struct vfio_pci_device *vdev,
621 unsigned index, unsigned start, 633 unsigned index, unsigned start,
622 unsigned count, uint32_t flags, void *data) 634 unsigned count, uint32_t flags, void *data)
623{ 635{
624 if (index != VFIO_PCI_REQ_IRQ_INDEX || start != 0 || count != 1) 636 if (index != VFIO_PCI_REQ_IRQ_INDEX || start != 0 || count > 1)
625 return -EINVAL; 637 return -EINVAL;
626 638
627 return vfio_pci_set_ctx_trigger_single(&vdev->req_trigger, flags, data); 639 return vfio_pci_set_ctx_trigger_single(&vdev->req_trigger,
640 count, flags, data);
628} 641}
629 642
630int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev, uint32_t flags, 643int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev, uint32_t flags,
diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index 0ddf3a2dbfc4..e3b30ea9ece5 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -307,6 +307,8 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
307 307
308 vhost_disable_notify(&vsock->dev, vq); 308 vhost_disable_notify(&vsock->dev, vq);
309 for (;;) { 309 for (;;) {
310 u32 len;
311
310 if (!vhost_vsock_more_replies(vsock)) { 312 if (!vhost_vsock_more_replies(vsock)) {
311 /* Stop tx until the device processes already 313 /* Stop tx until the device processes already
312 * pending replies. Leave tx virtqueue 314 * pending replies. Leave tx virtqueue
@@ -334,13 +336,15 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
334 continue; 336 continue;
335 } 337 }
336 338
339 len = pkt->len;
340
337 /* Only accept correctly addressed packets */ 341 /* Only accept correctly addressed packets */
338 if (le64_to_cpu(pkt->hdr.src_cid) == vsock->guest_cid) 342 if (le64_to_cpu(pkt->hdr.src_cid) == vsock->guest_cid)
339 virtio_transport_recv_pkt(pkt); 343 virtio_transport_recv_pkt(pkt);
340 else 344 else
341 virtio_transport_free_pkt(pkt); 345 virtio_transport_free_pkt(pkt);
342 346
343 vhost_add_used(vq, head, sizeof(pkt->hdr) + pkt->len); 347 vhost_add_used(vq, head, sizeof(pkt->hdr) + len);
344 added = true; 348 added = true;
345 } 349 }
346 350
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 114a0c88afb8..e383ecdaca59 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -327,6 +327,8 @@ static inline int virtqueue_add(struct virtqueue *_vq,
327 * host should service the ring ASAP. */ 327 * host should service the ring ASAP. */
328 if (out_sgs) 328 if (out_sgs)
329 vq->notify(&vq->vq); 329 vq->notify(&vq->vq);
330 if (indirect)
331 kfree(desc);
330 END_USE(vq); 332 END_USE(vq);
331 return -ENOSPC; 333 return -ENOSPC;
332 } 334 }
@@ -426,6 +428,7 @@ unmap_release:
426 if (indirect) 428 if (indirect)
427 kfree(desc); 429 kfree(desc);
428 430
431 END_USE(vq);
429 return -EIO; 432 return -EIO;
430} 433}
431 434
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index b6d210e7a993..d9ddcfc18c91 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -862,33 +862,6 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info,
862 return 0; 862 return 0;
863} 863}
864 864
865int btrfs_add_delayed_qgroup_reserve(struct btrfs_fs_info *fs_info,
866 struct btrfs_trans_handle *trans,
867 u64 ref_root, u64 bytenr, u64 num_bytes)
868{
869 struct btrfs_delayed_ref_root *delayed_refs;
870 struct btrfs_delayed_ref_head *ref_head;
871 int ret = 0;
872
873 if (!fs_info->quota_enabled || !is_fstree(ref_root))
874 return 0;
875
876 delayed_refs = &trans->transaction->delayed_refs;
877
878 spin_lock(&delayed_refs->lock);
879 ref_head = find_ref_head(&delayed_refs->href_root, bytenr, 0);
880 if (!ref_head) {
881 ret = -ENOENT;
882 goto out;
883 }
884 WARN_ON(ref_head->qgroup_reserved || ref_head->qgroup_ref_root);
885 ref_head->qgroup_ref_root = ref_root;
886 ref_head->qgroup_reserved = num_bytes;
887out:
888 spin_unlock(&delayed_refs->lock);
889 return ret;
890}
891
892int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info, 865int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info,
893 struct btrfs_trans_handle *trans, 866 struct btrfs_trans_handle *trans,
894 u64 bytenr, u64 num_bytes, 867 u64 bytenr, u64 num_bytes,
diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h
index 5fca9534a271..43f3629760e9 100644
--- a/fs/btrfs/delayed-ref.h
+++ b/fs/btrfs/delayed-ref.h
@@ -250,9 +250,6 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info,
250 u64 parent, u64 ref_root, 250 u64 parent, u64 ref_root,
251 u64 owner, u64 offset, u64 reserved, int action, 251 u64 owner, u64 offset, u64 reserved, int action,
252 struct btrfs_delayed_extent_op *extent_op); 252 struct btrfs_delayed_extent_op *extent_op);
253int btrfs_add_delayed_qgroup_reserve(struct btrfs_fs_info *fs_info,
254 struct btrfs_trans_handle *trans,
255 u64 ref_root, u64 bytenr, u64 num_bytes);
256int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info, 253int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info,
257 struct btrfs_trans_handle *trans, 254 struct btrfs_trans_handle *trans,
258 u64 bytenr, u64 num_bytes, 255 u64 bytenr, u64 num_bytes,
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 9404121fd5f7..5842423f8f47 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2033,6 +2033,14 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
2033 */ 2033 */
2034 clear_bit(BTRFS_INODE_NEEDS_FULL_SYNC, 2034 clear_bit(BTRFS_INODE_NEEDS_FULL_SYNC,
2035 &BTRFS_I(inode)->runtime_flags); 2035 &BTRFS_I(inode)->runtime_flags);
2036 /*
2037 * An ordered extent might have started before and completed
2038 * already with io errors, in which case the inode was not
2039 * updated and we end up here. So check the inode's mapping
2040 * flags for any errors that might have happened while doing
2041 * writeback of file data.
2042 */
2043 ret = btrfs_inode_check_errors(inode);
2036 inode_unlock(inode); 2044 inode_unlock(inode);
2037 goto out; 2045 goto out;
2038 } 2046 }
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 2f5975954ccf..08dfc57e2270 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3435,10 +3435,10 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
3435 found_key.offset = 0; 3435 found_key.offset = 0;
3436 inode = btrfs_iget(root->fs_info->sb, &found_key, root, NULL); 3436 inode = btrfs_iget(root->fs_info->sb, &found_key, root, NULL);
3437 ret = PTR_ERR_OR_ZERO(inode); 3437 ret = PTR_ERR_OR_ZERO(inode);
3438 if (ret && ret != -ESTALE) 3438 if (ret && ret != -ENOENT)
3439 goto out; 3439 goto out;
3440 3440
3441 if (ret == -ESTALE && root == root->fs_info->tree_root) { 3441 if (ret == -ENOENT && root == root->fs_info->tree_root) {
3442 struct btrfs_root *dead_root; 3442 struct btrfs_root *dead_root;
3443 struct btrfs_fs_info *fs_info = root->fs_info; 3443 struct btrfs_fs_info *fs_info = root->fs_info;
3444 int is_dead_root = 0; 3444 int is_dead_root = 0;
@@ -3474,7 +3474,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
3474 * Inode is already gone but the orphan item is still there, 3474 * Inode is already gone but the orphan item is still there,
3475 * kill the orphan item. 3475 * kill the orphan item.
3476 */ 3476 */
3477 if (ret == -ESTALE) { 3477 if (ret == -ENOENT) {
3478 trans = btrfs_start_transaction(root, 1); 3478 trans = btrfs_start_transaction(root, 1);
3479 if (IS_ERR(trans)) { 3479 if (IS_ERR(trans)) {
3480 ret = PTR_ERR(trans); 3480 ret = PTR_ERR(trans);
@@ -3633,7 +3633,7 @@ static noinline int acls_after_inode_item(struct extent_buffer *leaf,
3633/* 3633/*
3634 * read an inode from the btree into the in-memory inode 3634 * read an inode from the btree into the in-memory inode
3635 */ 3635 */
3636static void btrfs_read_locked_inode(struct inode *inode) 3636static int btrfs_read_locked_inode(struct inode *inode)
3637{ 3637{
3638 struct btrfs_path *path; 3638 struct btrfs_path *path;
3639 struct extent_buffer *leaf; 3639 struct extent_buffer *leaf;
@@ -3652,14 +3652,19 @@ static void btrfs_read_locked_inode(struct inode *inode)
3652 filled = true; 3652 filled = true;
3653 3653
3654 path = btrfs_alloc_path(); 3654 path = btrfs_alloc_path();
3655 if (!path) 3655 if (!path) {
3656 ret = -ENOMEM;
3656 goto make_bad; 3657 goto make_bad;
3658 }
3657 3659
3658 memcpy(&location, &BTRFS_I(inode)->location, sizeof(location)); 3660 memcpy(&location, &BTRFS_I(inode)->location, sizeof(location));
3659 3661
3660 ret = btrfs_lookup_inode(NULL, root, path, &location, 0); 3662 ret = btrfs_lookup_inode(NULL, root, path, &location, 0);
3661 if (ret) 3663 if (ret) {
3664 if (ret > 0)
3665 ret = -ENOENT;
3662 goto make_bad; 3666 goto make_bad;
3667 }
3663 3668
3664 leaf = path->nodes[0]; 3669 leaf = path->nodes[0];
3665 3670
@@ -3812,11 +3817,12 @@ cache_acl:
3812 } 3817 }
3813 3818
3814 btrfs_update_iflags(inode); 3819 btrfs_update_iflags(inode);
3815 return; 3820 return 0;
3816 3821
3817make_bad: 3822make_bad:
3818 btrfs_free_path(path); 3823 btrfs_free_path(path);
3819 make_bad_inode(inode); 3824 make_bad_inode(inode);
3825 return ret;
3820} 3826}
3821 3827
3822/* 3828/*
@@ -4204,6 +4210,7 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
4204 int err = 0; 4210 int err = 0;
4205 struct btrfs_root *root = BTRFS_I(dir)->root; 4211 struct btrfs_root *root = BTRFS_I(dir)->root;
4206 struct btrfs_trans_handle *trans; 4212 struct btrfs_trans_handle *trans;
4213 u64 last_unlink_trans;
4207 4214
4208 if (inode->i_size > BTRFS_EMPTY_DIR_SIZE) 4215 if (inode->i_size > BTRFS_EMPTY_DIR_SIZE)
4209 return -ENOTEMPTY; 4216 return -ENOTEMPTY;
@@ -4226,11 +4233,27 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
4226 if (err) 4233 if (err)
4227 goto out; 4234 goto out;
4228 4235
4236 last_unlink_trans = BTRFS_I(inode)->last_unlink_trans;
4237
4229 /* now the directory is empty */ 4238 /* now the directory is empty */
4230 err = btrfs_unlink_inode(trans, root, dir, d_inode(dentry), 4239 err = btrfs_unlink_inode(trans, root, dir, d_inode(dentry),
4231 dentry->d_name.name, dentry->d_name.len); 4240 dentry->d_name.name, dentry->d_name.len);
4232 if (!err) 4241 if (!err) {
4233 btrfs_i_size_write(inode, 0); 4242 btrfs_i_size_write(inode, 0);
4243 /*
4244 * Propagate the last_unlink_trans value of the deleted dir to
4245 * its parent directory. This is to prevent an unrecoverable
4246 * log tree in the case we do something like this:
4247 * 1) create dir foo
4248 * 2) create snapshot under dir foo
4249 * 3) delete the snapshot
4250 * 4) rmdir foo
4251 * 5) mkdir foo
4252 * 6) fsync foo or some file inside foo
4253 */
4254 if (last_unlink_trans >= trans->transid)
4255 BTRFS_I(dir)->last_unlink_trans = last_unlink_trans;
4256 }
4234out: 4257out:
4235 btrfs_end_transaction(trans, root); 4258 btrfs_end_transaction(trans, root);
4236 btrfs_btree_balance_dirty(root); 4259 btrfs_btree_balance_dirty(root);
@@ -5606,7 +5629,9 @@ struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
5606 return ERR_PTR(-ENOMEM); 5629 return ERR_PTR(-ENOMEM);
5607 5630
5608 if (inode->i_state & I_NEW) { 5631 if (inode->i_state & I_NEW) {
5609 btrfs_read_locked_inode(inode); 5632 int ret;
5633
5634 ret = btrfs_read_locked_inode(inode);
5610 if (!is_bad_inode(inode)) { 5635 if (!is_bad_inode(inode)) {
5611 inode_tree_add(inode); 5636 inode_tree_add(inode);
5612 unlock_new_inode(inode); 5637 unlock_new_inode(inode);
@@ -5615,7 +5640,8 @@ struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
5615 } else { 5640 } else {
5616 unlock_new_inode(inode); 5641 unlock_new_inode(inode);
5617 iput(inode); 5642 iput(inode);
5618 inode = ERR_PTR(-ESTALE); 5643 ASSERT(ret < 0);
5644 inode = ERR_PTR(ret < 0 ? ret : -ESTALE);
5619 } 5645 }
5620 } 5646 }
5621 5647
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index b71dd298385c..efe129fe2678 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -231,7 +231,6 @@ struct pending_dir_move {
231 u64 parent_ino; 231 u64 parent_ino;
232 u64 ino; 232 u64 ino;
233 u64 gen; 233 u64 gen;
234 bool is_orphan;
235 struct list_head update_refs; 234 struct list_head update_refs;
236}; 235};
237 236
@@ -274,6 +273,39 @@ struct name_cache_entry {
274 char name[]; 273 char name[];
275}; 274};
276 275
276static void inconsistent_snapshot_error(struct send_ctx *sctx,
277 enum btrfs_compare_tree_result result,
278 const char *what)
279{
280 const char *result_string;
281
282 switch (result) {
283 case BTRFS_COMPARE_TREE_NEW:
284 result_string = "new";
285 break;
286 case BTRFS_COMPARE_TREE_DELETED:
287 result_string = "deleted";
288 break;
289 case BTRFS_COMPARE_TREE_CHANGED:
290 result_string = "updated";
291 break;
292 case BTRFS_COMPARE_TREE_SAME:
293 ASSERT(0);
294 result_string = "unchanged";
295 break;
296 default:
297 ASSERT(0);
298 result_string = "unexpected";
299 }
300
301 btrfs_err(sctx->send_root->fs_info,
302 "Send: inconsistent snapshot, found %s %s for inode %llu without updated inode item, send root is %llu, parent root is %llu",
303 result_string, what, sctx->cmp_key->objectid,
304 sctx->send_root->root_key.objectid,
305 (sctx->parent_root ?
306 sctx->parent_root->root_key.objectid : 0));
307}
308
277static int is_waiting_for_move(struct send_ctx *sctx, u64 ino); 309static int is_waiting_for_move(struct send_ctx *sctx, u64 ino);
278 310
279static struct waiting_dir_move * 311static struct waiting_dir_move *
@@ -1861,7 +1893,8 @@ static int will_overwrite_ref(struct send_ctx *sctx, u64 dir, u64 dir_gen,
1861 * was already unlinked/moved, so we can safely assume that we will not 1893 * was already unlinked/moved, so we can safely assume that we will not
1862 * overwrite anything at this point in time. 1894 * overwrite anything at this point in time.
1863 */ 1895 */
1864 if (other_inode > sctx->send_progress) { 1896 if (other_inode > sctx->send_progress ||
1897 is_waiting_for_move(sctx, other_inode)) {
1865 ret = get_inode_info(sctx->parent_root, other_inode, NULL, 1898 ret = get_inode_info(sctx->parent_root, other_inode, NULL,
1866 who_gen, NULL, NULL, NULL, NULL); 1899 who_gen, NULL, NULL, NULL, NULL);
1867 if (ret < 0) 1900 if (ret < 0)
@@ -2502,6 +2535,8 @@ verbose_printk("btrfs: send_utimes %llu\n", ino);
2502 key.type = BTRFS_INODE_ITEM_KEY; 2535 key.type = BTRFS_INODE_ITEM_KEY;
2503 key.offset = 0; 2536 key.offset = 0;
2504 ret = btrfs_search_slot(NULL, sctx->send_root, &key, path, 0, 0); 2537 ret = btrfs_search_slot(NULL, sctx->send_root, &key, path, 0, 0);
2538 if (ret > 0)
2539 ret = -ENOENT;
2505 if (ret < 0) 2540 if (ret < 0)
2506 goto out; 2541 goto out;
2507 2542
@@ -2947,6 +2982,10 @@ static int can_rmdir(struct send_ctx *sctx, u64 dir, u64 dir_gen,
2947 } 2982 }
2948 2983
2949 if (loc.objectid > send_progress) { 2984 if (loc.objectid > send_progress) {
2985 struct orphan_dir_info *odi;
2986
2987 odi = get_orphan_dir_info(sctx, dir);
2988 free_orphan_dir_info(sctx, odi);
2950 ret = 0; 2989 ret = 0;
2951 goto out; 2990 goto out;
2952 } 2991 }
@@ -3047,7 +3086,6 @@ static int add_pending_dir_move(struct send_ctx *sctx,
3047 pm->parent_ino = parent_ino; 3086 pm->parent_ino = parent_ino;
3048 pm->ino = ino; 3087 pm->ino = ino;
3049 pm->gen = ino_gen; 3088 pm->gen = ino_gen;
3050 pm->is_orphan = is_orphan;
3051 INIT_LIST_HEAD(&pm->list); 3089 INIT_LIST_HEAD(&pm->list);
3052 INIT_LIST_HEAD(&pm->update_refs); 3090 INIT_LIST_HEAD(&pm->update_refs);
3053 RB_CLEAR_NODE(&pm->node); 3091 RB_CLEAR_NODE(&pm->node);
@@ -3113,6 +3151,48 @@ static struct pending_dir_move *get_pending_dir_moves(struct send_ctx *sctx,
3113 return NULL; 3151 return NULL;
3114} 3152}
3115 3153
3154static int path_loop(struct send_ctx *sctx, struct fs_path *name,
3155 u64 ino, u64 gen, u64 *ancestor_ino)
3156{
3157 int ret = 0;
3158 u64 parent_inode = 0;
3159 u64 parent_gen = 0;
3160 u64 start_ino = ino;
3161
3162 *ancestor_ino = 0;
3163 while (ino != BTRFS_FIRST_FREE_OBJECTID) {
3164 fs_path_reset(name);
3165
3166 if (is_waiting_for_rm(sctx, ino))
3167 break;
3168 if (is_waiting_for_move(sctx, ino)) {
3169 if (*ancestor_ino == 0)
3170 *ancestor_ino = ino;
3171 ret = get_first_ref(sctx->parent_root, ino,
3172 &parent_inode, &parent_gen, name);
3173 } else {
3174 ret = __get_cur_name_and_parent(sctx, ino, gen,
3175 &parent_inode,
3176 &parent_gen, name);
3177 if (ret > 0) {
3178 ret = 0;
3179 break;
3180 }
3181 }
3182 if (ret < 0)
3183 break;
3184 if (parent_inode == start_ino) {
3185 ret = 1;
3186 if (*ancestor_ino == 0)
3187 *ancestor_ino = ino;
3188 break;
3189 }
3190 ino = parent_inode;
3191 gen = parent_gen;
3192 }
3193 return ret;
3194}
3195
3116static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm) 3196static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm)
3117{ 3197{
3118 struct fs_path *from_path = NULL; 3198 struct fs_path *from_path = NULL;
@@ -3123,6 +3203,8 @@ static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm)
3123 u64 parent_ino, parent_gen; 3203 u64 parent_ino, parent_gen;
3124 struct waiting_dir_move *dm = NULL; 3204 struct waiting_dir_move *dm = NULL;
3125 u64 rmdir_ino = 0; 3205 u64 rmdir_ino = 0;
3206 u64 ancestor;
3207 bool is_orphan;
3126 int ret; 3208 int ret;
3127 3209
3128 name = fs_path_alloc(); 3210 name = fs_path_alloc();
@@ -3135,9 +3217,10 @@ static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm)
3135 dm = get_waiting_dir_move(sctx, pm->ino); 3217 dm = get_waiting_dir_move(sctx, pm->ino);
3136 ASSERT(dm); 3218 ASSERT(dm);
3137 rmdir_ino = dm->rmdir_ino; 3219 rmdir_ino = dm->rmdir_ino;
3220 is_orphan = dm->orphanized;
3138 free_waiting_dir_move(sctx, dm); 3221 free_waiting_dir_move(sctx, dm);
3139 3222
3140 if (pm->is_orphan) { 3223 if (is_orphan) {
3141 ret = gen_unique_name(sctx, pm->ino, 3224 ret = gen_unique_name(sctx, pm->ino,
3142 pm->gen, from_path); 3225 pm->gen, from_path);
3143 } else { 3226 } else {
@@ -3155,6 +3238,24 @@ static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm)
3155 goto out; 3238 goto out;
3156 3239
3157 sctx->send_progress = sctx->cur_ino + 1; 3240 sctx->send_progress = sctx->cur_ino + 1;
3241 ret = path_loop(sctx, name, pm->ino, pm->gen, &ancestor);
3242 if (ret < 0)
3243 goto out;
3244 if (ret) {
3245 LIST_HEAD(deleted_refs);
3246 ASSERT(ancestor > BTRFS_FIRST_FREE_OBJECTID);
3247 ret = add_pending_dir_move(sctx, pm->ino, pm->gen, ancestor,
3248 &pm->update_refs, &deleted_refs,
3249 is_orphan);
3250 if (ret < 0)
3251 goto out;
3252 if (rmdir_ino) {
3253 dm = get_waiting_dir_move(sctx, pm->ino);
3254 ASSERT(dm);
3255 dm->rmdir_ino = rmdir_ino;
3256 }
3257 goto out;
3258 }
3158 fs_path_reset(name); 3259 fs_path_reset(name);
3159 to_path = name; 3260 to_path = name;
3160 name = NULL; 3261 name = NULL;
@@ -3174,7 +3275,7 @@ static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm)
3174 /* already deleted */ 3275 /* already deleted */
3175 goto finish; 3276 goto finish;
3176 } 3277 }
3177 ret = can_rmdir(sctx, rmdir_ino, odi->gen, sctx->cur_ino + 1); 3278 ret = can_rmdir(sctx, rmdir_ino, odi->gen, sctx->cur_ino);
3178 if (ret < 0) 3279 if (ret < 0)
3179 goto out; 3280 goto out;
3180 if (!ret) 3281 if (!ret)
@@ -3204,8 +3305,18 @@ finish:
3204 * and old parent(s). 3305 * and old parent(s).
3205 */ 3306 */
3206 list_for_each_entry(cur, &pm->update_refs, list) { 3307 list_for_each_entry(cur, &pm->update_refs, list) {
3207 if (cur->dir == rmdir_ino) 3308 /*
3309 * The parent inode might have been deleted in the send snapshot
3310 */
3311 ret = get_inode_info(sctx->send_root, cur->dir, NULL,
3312 NULL, NULL, NULL, NULL, NULL);
3313 if (ret == -ENOENT) {
3314 ret = 0;
3208 continue; 3315 continue;
3316 }
3317 if (ret < 0)
3318 goto out;
3319
3209 ret = send_utimes(sctx, cur->dir, cur->dir_gen); 3320 ret = send_utimes(sctx, cur->dir, cur->dir_gen);
3210 if (ret < 0) 3321 if (ret < 0)
3211 goto out; 3322 goto out;
@@ -3325,6 +3436,7 @@ static int wait_for_dest_dir_move(struct send_ctx *sctx,
3325 u64 left_gen; 3436 u64 left_gen;
3326 u64 right_gen; 3437 u64 right_gen;
3327 int ret = 0; 3438 int ret = 0;
3439 struct waiting_dir_move *wdm;
3328 3440
3329 if (RB_EMPTY_ROOT(&sctx->waiting_dir_moves)) 3441 if (RB_EMPTY_ROOT(&sctx->waiting_dir_moves))
3330 return 0; 3442 return 0;
@@ -3383,7 +3495,8 @@ static int wait_for_dest_dir_move(struct send_ctx *sctx,
3383 goto out; 3495 goto out;
3384 } 3496 }
3385 3497
3386 if (is_waiting_for_move(sctx, di_key.objectid)) { 3498 wdm = get_waiting_dir_move(sctx, di_key.objectid);
3499 if (wdm && !wdm->orphanized) {
3387 ret = add_pending_dir_move(sctx, 3500 ret = add_pending_dir_move(sctx,
3388 sctx->cur_ino, 3501 sctx->cur_ino,
3389 sctx->cur_inode_gen, 3502 sctx->cur_inode_gen,
@@ -3470,7 +3583,8 @@ static int wait_for_parent_move(struct send_ctx *sctx,
3470 ret = is_ancestor(sctx->parent_root, 3583 ret = is_ancestor(sctx->parent_root,
3471 sctx->cur_ino, sctx->cur_inode_gen, 3584 sctx->cur_ino, sctx->cur_inode_gen,
3472 ino, path_before); 3585 ino, path_before);
3473 break; 3586 if (ret)
3587 break;
3474 } 3588 }
3475 3589
3476 fs_path_reset(path_before); 3590 fs_path_reset(path_before);
@@ -3643,11 +3757,26 @@ verbose_printk("btrfs: process_recorded_refs %llu\n", sctx->cur_ino);
3643 goto out; 3757 goto out;
3644 if (ret) { 3758 if (ret) {
3645 struct name_cache_entry *nce; 3759 struct name_cache_entry *nce;
3760 struct waiting_dir_move *wdm;
3646 3761
3647 ret = orphanize_inode(sctx, ow_inode, ow_gen, 3762 ret = orphanize_inode(sctx, ow_inode, ow_gen,
3648 cur->full_path); 3763 cur->full_path);
3649 if (ret < 0) 3764 if (ret < 0)
3650 goto out; 3765 goto out;
3766
3767 /*
3768 * If ow_inode has its rename operation delayed
3769 * make sure that its orphanized name is used in
3770 * the source path when performing its rename
3771 * operation.
3772 */
3773 if (is_waiting_for_move(sctx, ow_inode)) {
3774 wdm = get_waiting_dir_move(sctx,
3775 ow_inode);
3776 ASSERT(wdm);
3777 wdm->orphanized = true;
3778 }
3779
3651 /* 3780 /*
3652 * Make sure we clear our orphanized inode's 3781 * Make sure we clear our orphanized inode's
3653 * name from the name cache. This is because the 3782 * name from the name cache. This is because the
@@ -3663,6 +3792,19 @@ verbose_printk("btrfs: process_recorded_refs %llu\n", sctx->cur_ino);
3663 name_cache_delete(sctx, nce); 3792 name_cache_delete(sctx, nce);
3664 kfree(nce); 3793 kfree(nce);
3665 } 3794 }
3795
3796 /*
3797 * ow_inode might currently be an ancestor of
3798 * cur_ino, therefore compute valid_path (the
3799 * current path of cur_ino) again because it
3800 * might contain the pre-orphanization name of
3801 * ow_inode, which is no longer valid.
3802 */
3803 fs_path_reset(valid_path);
3804 ret = get_cur_path(sctx, sctx->cur_ino,
3805 sctx->cur_inode_gen, valid_path);
3806 if (ret < 0)
3807 goto out;
3666 } else { 3808 } else {
3667 ret = send_unlink(sctx, cur->full_path); 3809 ret = send_unlink(sctx, cur->full_path);
3668 if (ret < 0) 3810 if (ret < 0)
@@ -5602,7 +5744,10 @@ static int changed_ref(struct send_ctx *sctx,
5602{ 5744{
5603 int ret = 0; 5745 int ret = 0;
5604 5746
5605 BUG_ON(sctx->cur_ino != sctx->cmp_key->objectid); 5747 if (sctx->cur_ino != sctx->cmp_key->objectid) {
5748 inconsistent_snapshot_error(sctx, result, "reference");
5749 return -EIO;
5750 }
5606 5751
5607 if (!sctx->cur_inode_new_gen && 5752 if (!sctx->cur_inode_new_gen &&
5608 sctx->cur_ino != BTRFS_FIRST_FREE_OBJECTID) { 5753 sctx->cur_ino != BTRFS_FIRST_FREE_OBJECTID) {
@@ -5627,7 +5772,10 @@ static int changed_xattr(struct send_ctx *sctx,
5627{ 5772{
5628 int ret = 0; 5773 int ret = 0;
5629 5774
5630 BUG_ON(sctx->cur_ino != sctx->cmp_key->objectid); 5775 if (sctx->cur_ino != sctx->cmp_key->objectid) {
5776 inconsistent_snapshot_error(sctx, result, "xattr");
5777 return -EIO;
5778 }
5631 5779
5632 if (!sctx->cur_inode_new_gen && !sctx->cur_inode_deleted) { 5780 if (!sctx->cur_inode_new_gen && !sctx->cur_inode_deleted) {
5633 if (result == BTRFS_COMPARE_TREE_NEW) 5781 if (result == BTRFS_COMPARE_TREE_NEW)
@@ -5651,7 +5799,10 @@ static int changed_extent(struct send_ctx *sctx,
5651{ 5799{
5652 int ret = 0; 5800 int ret = 0;
5653 5801
5654 BUG_ON(sctx->cur_ino != sctx->cmp_key->objectid); 5802 if (sctx->cur_ino != sctx->cmp_key->objectid) {
5803 inconsistent_snapshot_error(sctx, result, "extent");
5804 return -EIO;
5805 }
5655 5806
5656 if (!sctx->cur_inode_new_gen && !sctx->cur_inode_deleted) { 5807 if (!sctx->cur_inode_new_gen && !sctx->cur_inode_deleted) {
5657 if (result != BTRFS_COMPARE_TREE_DELETED) 5808 if (result != BTRFS_COMPARE_TREE_DELETED)
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index d31a0c4f56be..fff3f3efa436 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -4469,7 +4469,8 @@ static int btrfs_log_trailing_hole(struct btrfs_trans_handle *trans,
4469static int btrfs_check_ref_name_override(struct extent_buffer *eb, 4469static int btrfs_check_ref_name_override(struct extent_buffer *eb,
4470 const int slot, 4470 const int slot,
4471 const struct btrfs_key *key, 4471 const struct btrfs_key *key,
4472 struct inode *inode) 4472 struct inode *inode,
4473 u64 *other_ino)
4473{ 4474{
4474 int ret; 4475 int ret;
4475 struct btrfs_path *search_path; 4476 struct btrfs_path *search_path;
@@ -4528,7 +4529,16 @@ static int btrfs_check_ref_name_override(struct extent_buffer *eb,
4528 search_path, parent, 4529 search_path, parent,
4529 name, this_name_len, 0); 4530 name, this_name_len, 0);
4530 if (di && !IS_ERR(di)) { 4531 if (di && !IS_ERR(di)) {
4531 ret = 1; 4532 struct btrfs_key di_key;
4533
4534 btrfs_dir_item_key_to_cpu(search_path->nodes[0],
4535 di, &di_key);
4536 if (di_key.type == BTRFS_INODE_ITEM_KEY) {
4537 ret = 1;
4538 *other_ino = di_key.objectid;
4539 } else {
4540 ret = -EAGAIN;
4541 }
4532 goto out; 4542 goto out;
4533 } else if (IS_ERR(di)) { 4543 } else if (IS_ERR(di)) {
4534 ret = PTR_ERR(di); 4544 ret = PTR_ERR(di);
@@ -4722,16 +4732,71 @@ again:
4722 if ((min_key.type == BTRFS_INODE_REF_KEY || 4732 if ((min_key.type == BTRFS_INODE_REF_KEY ||
4723 min_key.type == BTRFS_INODE_EXTREF_KEY) && 4733 min_key.type == BTRFS_INODE_EXTREF_KEY) &&
4724 BTRFS_I(inode)->generation == trans->transid) { 4734 BTRFS_I(inode)->generation == trans->transid) {
4735 u64 other_ino = 0;
4736
4725 ret = btrfs_check_ref_name_override(path->nodes[0], 4737 ret = btrfs_check_ref_name_override(path->nodes[0],
4726 path->slots[0], 4738 path->slots[0],
4727 &min_key, inode); 4739 &min_key, inode,
4740 &other_ino);
4728 if (ret < 0) { 4741 if (ret < 0) {
4729 err = ret; 4742 err = ret;
4730 goto out_unlock; 4743 goto out_unlock;
4731 } else if (ret > 0) { 4744 } else if (ret > 0) {
4732 err = 1; 4745 struct btrfs_key inode_key;
4733 btrfs_set_log_full_commit(root->fs_info, trans); 4746 struct inode *other_inode;
4734 goto out_unlock; 4747
4748 if (ins_nr > 0) {
4749 ins_nr++;
4750 } else {
4751 ins_nr = 1;
4752 ins_start_slot = path->slots[0];
4753 }
4754 ret = copy_items(trans, inode, dst_path, path,
4755 &last_extent, ins_start_slot,
4756 ins_nr, inode_only,
4757 logged_isize);
4758 if (ret < 0) {
4759 err = ret;
4760 goto out_unlock;
4761 }
4762 ins_nr = 0;
4763 btrfs_release_path(path);
4764 inode_key.objectid = other_ino;
4765 inode_key.type = BTRFS_INODE_ITEM_KEY;
4766 inode_key.offset = 0;
4767 other_inode = btrfs_iget(root->fs_info->sb,
4768 &inode_key, root,
4769 NULL);
4770 /*
4771 * If the other inode that had a conflicting dir
4772 * entry was deleted in the current transaction,
4773 * we don't need to do more work nor fallback to
4774 * a transaction commit.
4775 */
4776 if (IS_ERR(other_inode) &&
4777 PTR_ERR(other_inode) == -ENOENT) {
4778 goto next_key;
4779 } else if (IS_ERR(other_inode)) {
4780 err = PTR_ERR(other_inode);
4781 goto out_unlock;
4782 }
4783 /*
4784 * We are safe logging the other inode without
4785 * acquiring its i_mutex as long as we log with
4786 * the LOG_INODE_EXISTS mode. We're safe against
4787 * concurrent renames of the other inode as well
4788 * because during a rename we pin the log and
4789 * update the log with the new name before we
4790 * unpin it.
4791 */
4792 err = btrfs_log_inode(trans, root, other_inode,
4793 LOG_INODE_EXISTS,
4794 0, LLONG_MAX, ctx);
4795 iput(other_inode);
4796 if (err)
4797 goto out_unlock;
4798 else
4799 goto next_key;
4735 } 4800 }
4736 } 4801 }
4737 4802
@@ -4799,7 +4864,7 @@ next_slot:
4799 ins_nr = 0; 4864 ins_nr = 0;
4800 } 4865 }
4801 btrfs_release_path(path); 4866 btrfs_release_path(path);
4802 4867next_key:
4803 if (min_key.offset < (u64)-1) { 4868 if (min_key.offset < (u64)-1) {
4804 min_key.offset++; 4869 min_key.offset++;
4805 } else if (min_key.type < max_key.type) { 4870 } else if (min_key.type < max_key.type) {
@@ -4993,8 +5058,12 @@ static noinline int check_parent_dirs_for_sync(struct btrfs_trans_handle *trans,
4993 if (!parent || d_really_is_negative(parent) || sb != parent->d_sb) 5058 if (!parent || d_really_is_negative(parent) || sb != parent->d_sb)
4994 break; 5059 break;
4995 5060
4996 if (IS_ROOT(parent)) 5061 if (IS_ROOT(parent)) {
5062 inode = d_inode(parent);
5063 if (btrfs_must_commit_transaction(trans, inode))
5064 ret = 1;
4997 break; 5065 break;
5066 }
4998 5067
4999 parent = dget_parent(parent); 5068 parent = dget_parent(parent);
5000 dput(old_parent); 5069 dput(old_parent);
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 99115cae1652..16e6ded0b7f2 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -1347,9 +1347,12 @@ void ceph_flush_snaps(struct ceph_inode_info *ci,
1347{ 1347{
1348 struct inode *inode = &ci->vfs_inode; 1348 struct inode *inode = &ci->vfs_inode;
1349 struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc; 1349 struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc;
1350 struct ceph_mds_session *session = *psession; 1350 struct ceph_mds_session *session = NULL;
1351 int mds; 1351 int mds;
1352
1352 dout("ceph_flush_snaps %p\n", inode); 1353 dout("ceph_flush_snaps %p\n", inode);
1354 if (psession)
1355 session = *psession;
1353retry: 1356retry:
1354 spin_lock(&ci->i_ceph_lock); 1357 spin_lock(&ci->i_ceph_lock);
1355 if (!(ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS)) { 1358 if (!(ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS)) {
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index fa59a85226b2..f72d4ae303b2 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -2759,6 +2759,7 @@ static int encode_caps_cb(struct inode *inode, struct ceph_cap *cap,
2759 } else { 2759 } else {
2760 path = NULL; 2760 path = NULL;
2761 pathlen = 0; 2761 pathlen = 0;
2762 pathbase = 0;
2762 } 2763 }
2763 2764
2764 spin_lock(&ci->i_ceph_lock); 2765 spin_lock(&ci->i_ceph_lock);
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 4d09d4441e3e..05713a5da083 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -1949,6 +1949,12 @@ void wakeup_flusher_threads(long nr_pages, enum wb_reason reason)
1949{ 1949{
1950 struct backing_dev_info *bdi; 1950 struct backing_dev_info *bdi;
1951 1951
1952 /*
1953 * If we are expecting writeback progress we must submit plugged IO.
1954 */
1955 if (blk_needs_flush_plug(current))
1956 blk_schedule_flush_plug(current);
1957
1952 if (!nr_pages) 1958 if (!nr_pages)
1953 nr_pages = get_nr_dirty_pages(); 1959 nr_pages = get_nr_dirty_pages();
1954 1960
diff --git a/fs/nfs/nfs42proc.c b/fs/nfs/nfs42proc.c
index 33da841a21bb..6f4752734804 100644
--- a/fs/nfs/nfs42proc.c
+++ b/fs/nfs/nfs42proc.c
@@ -338,6 +338,8 @@ nfs42_layoutstat_done(struct rpc_task *task, void *calldata)
338 case 0: 338 case 0:
339 break; 339 break;
340 case -NFS4ERR_EXPIRED: 340 case -NFS4ERR_EXPIRED:
341 case -NFS4ERR_ADMIN_REVOKED:
342 case -NFS4ERR_DELEG_REVOKED:
341 case -NFS4ERR_STALE_STATEID: 343 case -NFS4ERR_STALE_STATEID:
342 case -NFS4ERR_OLD_STATEID: 344 case -NFS4ERR_OLD_STATEID:
343 case -NFS4ERR_BAD_STATEID: 345 case -NFS4ERR_BAD_STATEID:
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index 324bfdc21250..9bf64eacba5b 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -396,6 +396,10 @@ extern void nfs4_schedule_state_renewal(struct nfs_client *);
396extern void nfs4_renewd_prepare_shutdown(struct nfs_server *); 396extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
397extern void nfs4_kill_renewd(struct nfs_client *); 397extern void nfs4_kill_renewd(struct nfs_client *);
398extern void nfs4_renew_state(struct work_struct *); 398extern void nfs4_renew_state(struct work_struct *);
399extern void nfs4_set_lease_period(struct nfs_client *clp,
400 unsigned long lease,
401 unsigned long lastrenewed);
402
399 403
400/* nfs4state.c */ 404/* nfs4state.c */
401struct rpc_cred *nfs4_get_clid_cred(struct nfs_client *clp); 405struct rpc_cred *nfs4_get_clid_cred(struct nfs_client *clp);
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index a036e93bdf96..1949bbd806eb 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -4237,12 +4237,9 @@ static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, str
4237 err = _nfs4_do_fsinfo(server, fhandle, fsinfo); 4237 err = _nfs4_do_fsinfo(server, fhandle, fsinfo);
4238 trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); 4238 trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err);
4239 if (err == 0) { 4239 if (err == 0) {
4240 struct nfs_client *clp = server->nfs_client; 4240 nfs4_set_lease_period(server->nfs_client,
4241 4241 fsinfo->lease_time * HZ,
4242 spin_lock(&clp->cl_lock); 4242 now);
4243 clp->cl_lease_time = fsinfo->lease_time * HZ;
4244 clp->cl_last_renewal = now;
4245 spin_unlock(&clp->cl_lock);
4246 break; 4243 break;
4247 } 4244 }
4248 err = nfs4_handle_exception(server, err, &exception); 4245 err = nfs4_handle_exception(server, err, &exception);
diff --git a/fs/nfs/nfs4renewd.c b/fs/nfs/nfs4renewd.c
index e1ba58c3d1ad..82e77198d17e 100644
--- a/fs/nfs/nfs4renewd.c
+++ b/fs/nfs/nfs4renewd.c
@@ -136,6 +136,26 @@ nfs4_kill_renewd(struct nfs_client *clp)
136 cancel_delayed_work_sync(&clp->cl_renewd); 136 cancel_delayed_work_sync(&clp->cl_renewd);
137} 137}
138 138
139/**
140 * nfs4_set_lease_period - Sets the lease period on a nfs_client
141 *
142 * @clp: pointer to nfs_client
143 * @lease: new value for lease period
144 * @lastrenewed: time at which lease was last renewed
145 */
146void nfs4_set_lease_period(struct nfs_client *clp,
147 unsigned long lease,
148 unsigned long lastrenewed)
149{
150 spin_lock(&clp->cl_lock);
151 clp->cl_lease_time = lease;
152 clp->cl_last_renewal = lastrenewed;
153 spin_unlock(&clp->cl_lock);
154
155 /* Cap maximum reconnect timeout at 1/2 lease period */
156 rpc_cap_max_reconnect_timeout(clp->cl_rpcclient, lease >> 1);
157}
158
139/* 159/*
140 * Local variables: 160 * Local variables:
141 * c-basic-offset: 8 161 * c-basic-offset: 8
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 834b875900d6..cada00aa5096 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -277,20 +277,17 @@ static int nfs41_setup_state_renewal(struct nfs_client *clp)
277{ 277{
278 int status; 278 int status;
279 struct nfs_fsinfo fsinfo; 279 struct nfs_fsinfo fsinfo;
280 unsigned long now;
280 281
281 if (!test_bit(NFS_CS_CHECK_LEASE_TIME, &clp->cl_res_state)) { 282 if (!test_bit(NFS_CS_CHECK_LEASE_TIME, &clp->cl_res_state)) {
282 nfs4_schedule_state_renewal(clp); 283 nfs4_schedule_state_renewal(clp);
283 return 0; 284 return 0;
284 } 285 }
285 286
287 now = jiffies;
286 status = nfs4_proc_get_lease_time(clp, &fsinfo); 288 status = nfs4_proc_get_lease_time(clp, &fsinfo);
287 if (status == 0) { 289 if (status == 0) {
288 /* Update lease time and schedule renewal */ 290 nfs4_set_lease_period(clp, fsinfo.lease_time * HZ, now);
289 spin_lock(&clp->cl_lock);
290 clp->cl_lease_time = fsinfo.lease_time * HZ;
291 clp->cl_last_renewal = jiffies;
292 spin_unlock(&clp->cl_lock);
293
294 nfs4_schedule_state_renewal(clp); 291 nfs4_schedule_state_renewal(clp);
295 } 292 }
296 293
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 8410ca275db1..a204d7e109d4 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -4903,6 +4903,32 @@ nfsd4_test_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4903 return nfs_ok; 4903 return nfs_ok;
4904} 4904}
4905 4905
4906static __be32
4907nfsd4_free_lock_stateid(stateid_t *stateid, struct nfs4_stid *s)
4908{
4909 struct nfs4_ol_stateid *stp = openlockstateid(s);
4910 __be32 ret;
4911
4912 mutex_lock(&stp->st_mutex);
4913
4914 ret = check_stateid_generation(stateid, &s->sc_stateid, 1);
4915 if (ret)
4916 goto out;
4917
4918 ret = nfserr_locks_held;
4919 if (check_for_locks(stp->st_stid.sc_file,
4920 lockowner(stp->st_stateowner)))
4921 goto out;
4922
4923 release_lock_stateid(stp);
4924 ret = nfs_ok;
4925
4926out:
4927 mutex_unlock(&stp->st_mutex);
4928 nfs4_put_stid(s);
4929 return ret;
4930}
4931
4906__be32 4932__be32
4907nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 4933nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4908 struct nfsd4_free_stateid *free_stateid) 4934 struct nfsd4_free_stateid *free_stateid)
@@ -4910,7 +4936,6 @@ nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4910 stateid_t *stateid = &free_stateid->fr_stateid; 4936 stateid_t *stateid = &free_stateid->fr_stateid;
4911 struct nfs4_stid *s; 4937 struct nfs4_stid *s;
4912 struct nfs4_delegation *dp; 4938 struct nfs4_delegation *dp;
4913 struct nfs4_ol_stateid *stp;
4914 struct nfs4_client *cl = cstate->session->se_client; 4939 struct nfs4_client *cl = cstate->session->se_client;
4915 __be32 ret = nfserr_bad_stateid; 4940 __be32 ret = nfserr_bad_stateid;
4916 4941
@@ -4929,18 +4954,9 @@ nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4929 ret = nfserr_locks_held; 4954 ret = nfserr_locks_held;
4930 break; 4955 break;
4931 case NFS4_LOCK_STID: 4956 case NFS4_LOCK_STID:
4932 ret = check_stateid_generation(stateid, &s->sc_stateid, 1); 4957 atomic_inc(&s->sc_count);
4933 if (ret)
4934 break;
4935 stp = openlockstateid(s);
4936 ret = nfserr_locks_held;
4937 if (check_for_locks(stp->st_stid.sc_file,
4938 lockowner(stp->st_stateowner)))
4939 break;
4940 WARN_ON(!unhash_lock_stateid(stp));
4941 spin_unlock(&cl->cl_lock); 4958 spin_unlock(&cl->cl_lock);
4942 nfs4_put_stid(s); 4959 ret = nfsd4_free_lock_stateid(stateid, s);
4943 ret = nfs_ok;
4944 goto out; 4960 goto out;
4945 case NFS4_REVOKED_DELEG_STID: 4961 case NFS4_REVOKED_DELEG_STID:
4946 dp = delegstateid(s); 4962 dp = delegstateid(s);
@@ -5507,7 +5523,7 @@ static __be32
5507lookup_or_create_lock_state(struct nfsd4_compound_state *cstate, 5523lookup_or_create_lock_state(struct nfsd4_compound_state *cstate,
5508 struct nfs4_ol_stateid *ost, 5524 struct nfs4_ol_stateid *ost,
5509 struct nfsd4_lock *lock, 5525 struct nfsd4_lock *lock,
5510 struct nfs4_ol_stateid **lst, bool *new) 5526 struct nfs4_ol_stateid **plst, bool *new)
5511{ 5527{
5512 __be32 status; 5528 __be32 status;
5513 struct nfs4_file *fi = ost->st_stid.sc_file; 5529 struct nfs4_file *fi = ost->st_stid.sc_file;
@@ -5515,7 +5531,9 @@ lookup_or_create_lock_state(struct nfsd4_compound_state *cstate,
5515 struct nfs4_client *cl = oo->oo_owner.so_client; 5531 struct nfs4_client *cl = oo->oo_owner.so_client;
5516 struct inode *inode = d_inode(cstate->current_fh.fh_dentry); 5532 struct inode *inode = d_inode(cstate->current_fh.fh_dentry);
5517 struct nfs4_lockowner *lo; 5533 struct nfs4_lockowner *lo;
5534 struct nfs4_ol_stateid *lst;
5518 unsigned int strhashval; 5535 unsigned int strhashval;
5536 bool hashed;
5519 5537
5520 lo = find_lockowner_str(cl, &lock->lk_new_owner); 5538 lo = find_lockowner_str(cl, &lock->lk_new_owner);
5521 if (!lo) { 5539 if (!lo) {
@@ -5531,12 +5549,27 @@ lookup_or_create_lock_state(struct nfsd4_compound_state *cstate,
5531 goto out; 5549 goto out;
5532 } 5550 }
5533 5551
5534 *lst = find_or_create_lock_stateid(lo, fi, inode, ost, new); 5552retry:
5535 if (*lst == NULL) { 5553 lst = find_or_create_lock_stateid(lo, fi, inode, ost, new);
5554 if (lst == NULL) {
5536 status = nfserr_jukebox; 5555 status = nfserr_jukebox;
5537 goto out; 5556 goto out;
5538 } 5557 }
5558
5559 mutex_lock(&lst->st_mutex);
5560
5561 /* See if it's still hashed to avoid race with FREE_STATEID */
5562 spin_lock(&cl->cl_lock);
5563 hashed = !list_empty(&lst->st_perfile);
5564 spin_unlock(&cl->cl_lock);
5565
5566 if (!hashed) {
5567 mutex_unlock(&lst->st_mutex);
5568 nfs4_put_stid(&lst->st_stid);
5569 goto retry;
5570 }
5539 status = nfs_ok; 5571 status = nfs_ok;
5572 *plst = lst;
5540out: 5573out:
5541 nfs4_put_stateowner(&lo->lo_owner); 5574 nfs4_put_stateowner(&lo->lo_owner);
5542 return status; 5575 return status;
@@ -5603,8 +5636,6 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
5603 goto out; 5636 goto out;
5604 status = lookup_or_create_lock_state(cstate, open_stp, lock, 5637 status = lookup_or_create_lock_state(cstate, open_stp, lock,
5605 &lock_stp, &new); 5638 &lock_stp, &new);
5606 if (status == nfs_ok)
5607 mutex_lock(&lock_stp->st_mutex);
5608 } else { 5639 } else {
5609 status = nfs4_preprocess_seqid_op(cstate, 5640 status = nfs4_preprocess_seqid_op(cstate,
5610 lock->lk_old_lock_seqid, 5641 lock->lk_old_lock_seqid,
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index ba944123167b..ff476e654b8f 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -1252,10 +1252,13 @@ nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
1252 if (IS_ERR(dchild)) 1252 if (IS_ERR(dchild))
1253 return nfserrno(host_err); 1253 return nfserrno(host_err);
1254 err = fh_compose(resfhp, fhp->fh_export, dchild, fhp); 1254 err = fh_compose(resfhp, fhp->fh_export, dchild, fhp);
1255 if (err) { 1255 /*
1256 dput(dchild); 1256 * We unconditionally drop our ref to dchild as fh_compose will have
1257 * already grabbed its own ref for it.
1258 */
1259 dput(dchild);
1260 if (err)
1257 return err; 1261 return err;
1258 }
1259 return nfsd_create_locked(rqstp, fhp, fname, flen, iap, type, 1262 return nfsd_create_locked(rqstp, fhp, fname, flen, iap, type,
1260 rdev, resfhp); 1263 rdev, resfhp);
1261} 1264}
diff --git a/fs/pipe.c b/fs/pipe.c
index 4b32928f5426..4ebe6b2e5217 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -144,10 +144,8 @@ static int anon_pipe_buf_steal(struct pipe_inode_info *pipe,
144 struct page *page = buf->page; 144 struct page *page = buf->page;
145 145
146 if (page_count(page) == 1) { 146 if (page_count(page) == 1) {
147 if (memcg_kmem_enabled()) { 147 if (memcg_kmem_enabled())
148 memcg_kmem_uncharge(page, 0); 148 memcg_kmem_uncharge(page, 0);
149 __ClearPageKmemcg(page);
150 }
151 __SetPageLocked(page); 149 __SetPageLocked(page);
152 return 0; 150 return 0;
153 } 151 }
diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index 09e18fdf61e5..b9a8c813e5e6 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -46,7 +46,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
46 cached = 0; 46 cached = 0;
47 47
48 for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++) 48 for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
49 pages[lru] = global_page_state(NR_LRU_BASE + lru); 49 pages[lru] = global_node_page_state(NR_LRU_BASE + lru);
50 50
51 available = si_mem_available(); 51 available = si_mem_available();
52 52
diff --git a/include/asm-generic/qrwlock.h b/include/asm-generic/qrwlock.h
index 54a8e65e18b6..7d026bf27713 100644
--- a/include/asm-generic/qrwlock.h
+++ b/include/asm-generic/qrwlock.h
@@ -25,7 +25,20 @@
25#include <asm-generic/qrwlock_types.h> 25#include <asm-generic/qrwlock_types.h>
26 26
27/* 27/*
28 * Writer states & reader shift and bias 28 * Writer states & reader shift and bias.
29 *
30 * | +0 | +1 | +2 | +3 |
31 * ----+----+----+----+----+
32 * LE | 78 | 56 | 34 | 12 | 0x12345678
33 * ----+----+----+----+----+
34 * | wr | rd |
35 * +----+----+----+----+
36 *
37 * ----+----+----+----+----+
38 * BE | 12 | 34 | 56 | 78 | 0x12345678
39 * ----+----+----+----+----+
40 * | rd | wr |
41 * +----+----+----+----+
29 */ 42 */
30#define _QW_WAITING 1 /* A writer is waiting */ 43#define _QW_WAITING 1 /* A writer is waiting */
31#define _QW_LOCKED 0xff /* A writer holds the lock */ 44#define _QW_LOCKED 0xff /* A writer holds the lock */
@@ -134,12 +147,22 @@ static inline void queued_read_unlock(struct qrwlock *lock)
134} 147}
135 148
136/** 149/**
150 * __qrwlock_write_byte - retrieve the write byte address of a queue rwlock
151 * @lock : Pointer to queue rwlock structure
152 * Return: the write byte address of a queue rwlock
153 */
154static inline u8 *__qrwlock_write_byte(struct qrwlock *lock)
155{
156 return (u8 *)lock + 3 * IS_BUILTIN(CONFIG_CPU_BIG_ENDIAN);
157}
158
159/**
137 * queued_write_unlock - release write lock of a queue rwlock 160 * queued_write_unlock - release write lock of a queue rwlock
138 * @lock : Pointer to queue rwlock structure 161 * @lock : Pointer to queue rwlock structure
139 */ 162 */
140static inline void queued_write_unlock(struct qrwlock *lock) 163static inline void queued_write_unlock(struct qrwlock *lock)
141{ 164{
142 smp_store_release((u8 *)&lock->cnts, 0); 165 smp_store_release(__qrwlock_write_byte(lock), 0);
143} 166}
144 167
145/* 168/*
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 4348d6d5877a..99c6d01d24f2 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -962,6 +962,7 @@ void ttm_mem_io_free(struct ttm_bo_device *bdev,
962 * 962 *
963 * @bo: A pointer to a struct ttm_buffer_object. 963 * @bo: A pointer to a struct ttm_buffer_object.
964 * @evict: 1: This is an eviction. Don't try to pipeline. 964 * @evict: 1: This is an eviction. Don't try to pipeline.
965 * @interruptible: Sleep interruptible if waiting.
965 * @no_wait_gpu: Return immediately if the GPU is busy. 966 * @no_wait_gpu: Return immediately if the GPU is busy.
966 * @new_mem: struct ttm_mem_reg indicating where to move. 967 * @new_mem: struct ttm_mem_reg indicating where to move.
967 * 968 *
@@ -976,7 +977,7 @@ void ttm_mem_io_free(struct ttm_bo_device *bdev,
976 */ 977 */
977 978
978extern int ttm_bo_move_ttm(struct ttm_buffer_object *bo, 979extern int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
979 bool evict, bool no_wait_gpu, 980 bool evict, bool interruptible, bool no_wait_gpu,
980 struct ttm_mem_reg *new_mem); 981 struct ttm_mem_reg *new_mem);
981 982
982/** 983/**
diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index 701b64a3b7c5..89b65b82d98f 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -74,7 +74,8 @@ static inline void bvec_iter_advance(const struct bio_vec *bv,
74 "Attempted to advance past end of bvec iter\n"); 74 "Attempted to advance past end of bvec iter\n");
75 75
76 while (bytes) { 76 while (bytes) {
77 unsigned len = min(bytes, bvec_iter_len(bv, *iter)); 77 unsigned iter_len = bvec_iter_len(bv, *iter);
78 unsigned len = min(bytes, iter_len);
78 79
79 bytes -= len; 80 bytes -= len;
80 iter->bi_size -= len; 81 iter->bi_size -= len;
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 01e908ac4a39..9c28b4d4c90b 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -1113,9 +1113,21 @@ struct kvm_device {
1113/* create, destroy, and name are mandatory */ 1113/* create, destroy, and name are mandatory */
1114struct kvm_device_ops { 1114struct kvm_device_ops {
1115 const char *name; 1115 const char *name;
1116
1117 /*
1118 * create is called holding kvm->lock and any operations not suitable
1119 * to do while holding the lock should be deferred to init (see
1120 * below).
1121 */
1116 int (*create)(struct kvm_device *dev, u32 type); 1122 int (*create)(struct kvm_device *dev, u32 type);
1117 1123
1118 /* 1124 /*
1125 * init is called after create if create is successful and is called
1126 * outside of holding kvm->lock.
1127 */
1128 void (*init)(struct kvm_device *dev);
1129
1130 /*
1119 * Destroy is responsible for freeing dev. 1131 * Destroy is responsible for freeing dev.
1120 * 1132 *
1121 * Destroy may be called before or after destructors are called 1133 * Destroy may be called before or after destructors are called
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 8ed4326164cc..2b6b43cc0dd5 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -743,7 +743,9 @@ struct perf_event_context {
743 u64 parent_gen; 743 u64 parent_gen;
744 u64 generation; 744 u64 generation;
745 int pin_count; 745 int pin_count;
746#ifdef CONFIG_CGROUP_PERF
746 int nr_cgroups; /* cgroup evts */ 747 int nr_cgroups; /* cgroup evts */
748#endif
747 void *task_ctx_data; /* pmu specific data */ 749 void *task_ctx_data; /* pmu specific data */
748 struct rcu_head rcu_head; 750 struct rcu_head rcu_head;
749}; 751};
@@ -769,7 +771,9 @@ struct perf_cpu_context {
769 unsigned int hrtimer_active; 771 unsigned int hrtimer_active;
770 772
771 struct pmu *unique_pmu; 773 struct pmu *unique_pmu;
774#ifdef CONFIG_CGROUP_PERF
772 struct perf_cgroup *cgrp; 775 struct perf_cgroup *cgrp;
776#endif
773}; 777};
774 778
775struct perf_output_handle { 779struct perf_output_handle {
diff --git a/include/linux/printk.h b/include/linux/printk.h
index 8dc155dab3ed..696a56be7d3e 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -266,39 +266,21 @@ extern asmlinkage void dump_stack(void) __cold;
266 * and other debug macros are compiled out unless either DEBUG is defined 266 * and other debug macros are compiled out unless either DEBUG is defined
267 * or CONFIG_DYNAMIC_DEBUG is set. 267 * or CONFIG_DYNAMIC_DEBUG is set.
268 */ 268 */
269 269#define pr_emerg(fmt, ...) \
270#ifdef CONFIG_PRINTK 270 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
271 271#define pr_alert(fmt, ...) \
272asmlinkage __printf(1, 2) __cold void __pr_emerg(const char *fmt, ...); 272 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
273asmlinkage __printf(1, 2) __cold void __pr_alert(const char *fmt, ...); 273#define pr_crit(fmt, ...) \
274asmlinkage __printf(1, 2) __cold void __pr_crit(const char *fmt, ...); 274 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
275asmlinkage __printf(1, 2) __cold void __pr_err(const char *fmt, ...); 275#define pr_err(fmt, ...) \
276asmlinkage __printf(1, 2) __cold void __pr_warn(const char *fmt, ...); 276 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
277asmlinkage __printf(1, 2) __cold void __pr_notice(const char *fmt, ...); 277#define pr_warning(fmt, ...) \
278asmlinkage __printf(1, 2) __cold void __pr_info(const char *fmt, ...); 278 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
279 279#define pr_warn pr_warning
280#define pr_emerg(fmt, ...) __pr_emerg(pr_fmt(fmt), ##__VA_ARGS__) 280#define pr_notice(fmt, ...) \
281#define pr_alert(fmt, ...) __pr_alert(pr_fmt(fmt), ##__VA_ARGS__) 281 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
282#define pr_crit(fmt, ...) __pr_crit(pr_fmt(fmt), ##__VA_ARGS__) 282#define pr_info(fmt, ...) \
283#define pr_err(fmt, ...) __pr_err(pr_fmt(fmt), ##__VA_ARGS__) 283 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
284#define pr_warn(fmt, ...) __pr_warn(pr_fmt(fmt), ##__VA_ARGS__)
285#define pr_notice(fmt, ...) __pr_notice(pr_fmt(fmt), ##__VA_ARGS__)
286#define pr_info(fmt, ...) __pr_info(pr_fmt(fmt), ##__VA_ARGS__)
287
288#else
289
290#define pr_emerg(fmt, ...) printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
291#define pr_alert(fmt, ...) printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
292#define pr_crit(fmt, ...) printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
293#define pr_err(fmt, ...) printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
294#define pr_warn(fmt, ...) printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
295#define pr_notice(fmt, ...) printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
296#define pr_info(fmt, ...) printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
297
298#endif
299
300#define pr_warning pr_warn
301
302/* 284/*
303 * Like KERN_CONT, pr_cont() should only be used when continuing 285 * Like KERN_CONT, pr_cont() should only be used when continuing
304 * a line with no newline ('\n') enclosed. Otherwise it defaults 286 * a line with no newline ('\n') enclosed. Otherwise it defaults
diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
index b6810c92b8bb..5c02b0691587 100644
--- a/include/linux/sunrpc/clnt.h
+++ b/include/linux/sunrpc/clnt.h
@@ -195,6 +195,8 @@ int rpc_clnt_add_xprt(struct rpc_clnt *, struct xprt_create *,
195 struct rpc_xprt *, 195 struct rpc_xprt *,
196 void *), 196 void *),
197 void *data); 197 void *data);
198void rpc_cap_max_reconnect_timeout(struct rpc_clnt *clnt,
199 unsigned long timeo);
198 200
199const char *rpc_proc_name(const struct rpc_task *task); 201const char *rpc_proc_name(const struct rpc_task *task);
200#endif /* __KERNEL__ */ 202#endif /* __KERNEL__ */
diff --git a/include/linux/sunrpc/xprt.h b/include/linux/sunrpc/xprt.h
index 5e3e1b63dbb3..a16070dd03ee 100644
--- a/include/linux/sunrpc/xprt.h
+++ b/include/linux/sunrpc/xprt.h
@@ -218,7 +218,8 @@ struct rpc_xprt {
218 struct work_struct task_cleanup; 218 struct work_struct task_cleanup;
219 struct timer_list timer; 219 struct timer_list timer;
220 unsigned long last_used, 220 unsigned long last_used,
221 idle_timeout; 221 idle_timeout,
222 max_reconnect_timeout;
222 223
223 /* 224 /*
224 * Send stuff 225 * Send stuff
diff --git a/include/trace/events/timer.h b/include/trace/events/timer.h
index 51440131d337..28c5da6fdfac 100644
--- a/include/trace/events/timer.h
+++ b/include/trace/events/timer.h
@@ -330,24 +330,32 @@ TRACE_EVENT(itimer_expire,
330#ifdef CONFIG_NO_HZ_COMMON 330#ifdef CONFIG_NO_HZ_COMMON
331 331
332#define TICK_DEP_NAMES \ 332#define TICK_DEP_NAMES \
333 tick_dep_name(NONE) \ 333 tick_dep_mask_name(NONE) \
334 tick_dep_name(POSIX_TIMER) \ 334 tick_dep_name(POSIX_TIMER) \
335 tick_dep_name(PERF_EVENTS) \ 335 tick_dep_name(PERF_EVENTS) \
336 tick_dep_name(SCHED) \ 336 tick_dep_name(SCHED) \
337 tick_dep_name_end(CLOCK_UNSTABLE) 337 tick_dep_name_end(CLOCK_UNSTABLE)
338 338
339#undef tick_dep_name 339#undef tick_dep_name
340#undef tick_dep_mask_name
340#undef tick_dep_name_end 341#undef tick_dep_name_end
341 342
342#define tick_dep_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep); 343/* The MASK will convert to their bits and they need to be processed too */
343#define tick_dep_name_end(sdep) TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep); 344#define tick_dep_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \
345 TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
346#define tick_dep_name_end(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \
347 TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
348/* NONE only has a mask defined for it */
349#define tick_dep_mask_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
344 350
345TICK_DEP_NAMES 351TICK_DEP_NAMES
346 352
347#undef tick_dep_name 353#undef tick_dep_name
354#undef tick_dep_mask_name
348#undef tick_dep_name_end 355#undef tick_dep_name_end
349 356
350#define tick_dep_name(sdep) { TICK_DEP_MASK_##sdep, #sdep }, 357#define tick_dep_name(sdep) { TICK_DEP_MASK_##sdep, #sdep },
358#define tick_dep_mask_name(sdep) { TICK_DEP_MASK_##sdep, #sdep },
351#define tick_dep_name_end(sdep) { TICK_DEP_MASK_##sdep, #sdep } 359#define tick_dep_name_end(sdep) { TICK_DEP_MASK_##sdep, #sdep }
352 360
353#define show_tick_dep_name(val) \ 361#define show_tick_dep_name(val) \
diff --git a/include/uapi/linux/virtio_vsock.h b/include/uapi/linux/virtio_vsock.h
index 6b011c19b50f..1d57ed3d84d2 100644
--- a/include/uapi/linux/virtio_vsock.h
+++ b/include/uapi/linux/virtio_vsock.h
@@ -32,7 +32,7 @@
32 */ 32 */
33 33
34#ifndef _UAPI_LINUX_VIRTIO_VSOCK_H 34#ifndef _UAPI_LINUX_VIRTIO_VSOCK_H
35#define _UAPI_LINUX_VIRTIO_VOSCK_H 35#define _UAPI_LINUX_VIRTIO_VSOCK_H
36 36
37#include <linux/types.h> 37#include <linux/types.h>
38#include <linux/virtio_ids.h> 38#include <linux/virtio_ids.h>
diff --git a/include/uapi/misc/cxl.h b/include/uapi/misc/cxl.h
index cbae529b7ce0..180d526a55c3 100644
--- a/include/uapi/misc/cxl.h
+++ b/include/uapi/misc/cxl.h
@@ -136,8 +136,8 @@ struct cxl_event_afu_driver_reserved {
136 * 136 *
137 * Of course the contents will be ABI, but that's up the AFU driver. 137 * Of course the contents will be ABI, but that's up the AFU driver.
138 */ 138 */
139 size_t data_size; 139 __u32 data_size;
140 u8 data[]; 140 __u8 data[];
141}; 141};
142 142
143struct cxl_event { 143struct cxl_event {
diff --git a/kernel/events/core.c b/kernel/events/core.c
index a19550d80ab1..1903b8f3a705 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -843,6 +843,32 @@ perf_cgroup_mark_enabled(struct perf_event *event,
843 } 843 }
844 } 844 }
845} 845}
846
847/*
848 * Update cpuctx->cgrp so that it is set when first cgroup event is added and
849 * cleared when last cgroup event is removed.
850 */
851static inline void
852list_update_cgroup_event(struct perf_event *event,
853 struct perf_event_context *ctx, bool add)
854{
855 struct perf_cpu_context *cpuctx;
856
857 if (!is_cgroup_event(event))
858 return;
859
860 if (add && ctx->nr_cgroups++)
861 return;
862 else if (!add && --ctx->nr_cgroups)
863 return;
864 /*
865 * Because cgroup events are always per-cpu events,
866 * this will always be called from the right CPU.
867 */
868 cpuctx = __get_cpu_context(ctx);
869 cpuctx->cgrp = add ? event->cgrp : NULL;
870}
871
846#else /* !CONFIG_CGROUP_PERF */ 872#else /* !CONFIG_CGROUP_PERF */
847 873
848static inline bool 874static inline bool
@@ -920,6 +946,13 @@ perf_cgroup_mark_enabled(struct perf_event *event,
920 struct perf_event_context *ctx) 946 struct perf_event_context *ctx)
921{ 947{
922} 948}
949
950static inline void
951list_update_cgroup_event(struct perf_event *event,
952 struct perf_event_context *ctx, bool add)
953{
954}
955
923#endif 956#endif
924 957
925/* 958/*
@@ -1392,6 +1425,7 @@ ctx_group_list(struct perf_event *event, struct perf_event_context *ctx)
1392static void 1425static void
1393list_add_event(struct perf_event *event, struct perf_event_context *ctx) 1426list_add_event(struct perf_event *event, struct perf_event_context *ctx)
1394{ 1427{
1428
1395 lockdep_assert_held(&ctx->lock); 1429 lockdep_assert_held(&ctx->lock);
1396 1430
1397 WARN_ON_ONCE(event->attach_state & PERF_ATTACH_CONTEXT); 1431 WARN_ON_ONCE(event->attach_state & PERF_ATTACH_CONTEXT);
@@ -1412,8 +1446,7 @@ list_add_event(struct perf_event *event, struct perf_event_context *ctx)
1412 list_add_tail(&event->group_entry, list); 1446 list_add_tail(&event->group_entry, list);
1413 } 1447 }
1414 1448
1415 if (is_cgroup_event(event)) 1449 list_update_cgroup_event(event, ctx, true);
1416 ctx->nr_cgroups++;
1417 1450
1418 list_add_rcu(&event->event_entry, &ctx->event_list); 1451 list_add_rcu(&event->event_entry, &ctx->event_list);
1419 ctx->nr_events++; 1452 ctx->nr_events++;
@@ -1581,8 +1614,6 @@ static void perf_group_attach(struct perf_event *event)
1581static void 1614static void
1582list_del_event(struct perf_event *event, struct perf_event_context *ctx) 1615list_del_event(struct perf_event *event, struct perf_event_context *ctx)
1583{ 1616{
1584 struct perf_cpu_context *cpuctx;
1585
1586 WARN_ON_ONCE(event->ctx != ctx); 1617 WARN_ON_ONCE(event->ctx != ctx);
1587 lockdep_assert_held(&ctx->lock); 1618 lockdep_assert_held(&ctx->lock);
1588 1619
@@ -1594,20 +1625,7 @@ list_del_event(struct perf_event *event, struct perf_event_context *ctx)
1594 1625
1595 event->attach_state &= ~PERF_ATTACH_CONTEXT; 1626 event->attach_state &= ~PERF_ATTACH_CONTEXT;
1596 1627
1597 if (is_cgroup_event(event)) { 1628 list_update_cgroup_event(event, ctx, false);
1598 ctx->nr_cgroups--;
1599 /*
1600 * Because cgroup events are always per-cpu events, this will
1601 * always be called from the right CPU.
1602 */
1603 cpuctx = __get_cpu_context(ctx);
1604 /*
1605 * If there are no more cgroup events then clear cgrp to avoid
1606 * stale pointer in update_cgrp_time_from_cpuctx().
1607 */
1608 if (!ctx->nr_cgroups)
1609 cpuctx->cgrp = NULL;
1610 }
1611 1629
1612 ctx->nr_events--; 1630 ctx->nr_events--;
1613 if (event->attr.inherit_stat) 1631 if (event->attr.inherit_stat)
@@ -1716,8 +1734,8 @@ static inline int pmu_filter_match(struct perf_event *event)
1716static inline int 1734static inline int
1717event_filter_match(struct perf_event *event) 1735event_filter_match(struct perf_event *event)
1718{ 1736{
1719 return (event->cpu == -1 || event->cpu == smp_processor_id()) 1737 return (event->cpu == -1 || event->cpu == smp_processor_id()) &&
1720 && perf_cgroup_match(event) && pmu_filter_match(event); 1738 perf_cgroup_match(event) && pmu_filter_match(event);
1721} 1739}
1722 1740
1723static void 1741static void
@@ -1737,8 +1755,8 @@ event_sched_out(struct perf_event *event,
1737 * maintained, otherwise bogus information is return 1755 * maintained, otherwise bogus information is return
1738 * via read() for time_enabled, time_running: 1756 * via read() for time_enabled, time_running:
1739 */ 1757 */
1740 if (event->state == PERF_EVENT_STATE_INACTIVE 1758 if (event->state == PERF_EVENT_STATE_INACTIVE &&
1741 && !event_filter_match(event)) { 1759 !event_filter_match(event)) {
1742 delta = tstamp - event->tstamp_stopped; 1760 delta = tstamp - event->tstamp_stopped;
1743 event->tstamp_running += delta; 1761 event->tstamp_running += delta;
1744 event->tstamp_stopped = tstamp; 1762 event->tstamp_stopped = tstamp;
@@ -2236,10 +2254,15 @@ perf_install_in_context(struct perf_event_context *ctx,
2236 2254
2237 lockdep_assert_held(&ctx->mutex); 2255 lockdep_assert_held(&ctx->mutex);
2238 2256
2239 event->ctx = ctx;
2240 if (event->cpu != -1) 2257 if (event->cpu != -1)
2241 event->cpu = cpu; 2258 event->cpu = cpu;
2242 2259
2260 /*
2261 * Ensures that if we can observe event->ctx, both the event and ctx
2262 * will be 'complete'. See perf_iterate_sb_cpu().
2263 */
2264 smp_store_release(&event->ctx, ctx);
2265
2243 if (!task) { 2266 if (!task) {
2244 cpu_function_call(cpu, __perf_install_in_context, event); 2267 cpu_function_call(cpu, __perf_install_in_context, event);
2245 return; 2268 return;
@@ -5969,6 +5992,14 @@ static void perf_iterate_sb_cpu(perf_iterate_f output, void *data)
5969 struct perf_event *event; 5992 struct perf_event *event;
5970 5993
5971 list_for_each_entry_rcu(event, &pel->list, sb_list) { 5994 list_for_each_entry_rcu(event, &pel->list, sb_list) {
5995 /*
5996 * Skip events that are not fully formed yet; ensure that
5997 * if we observe event->ctx, both event and ctx will be
5998 * complete enough. See perf_install_in_context().
5999 */
6000 if (!smp_load_acquire(&event->ctx))
6001 continue;
6002
5972 if (event->state < PERF_EVENT_STATE_INACTIVE) 6003 if (event->state < PERF_EVENT_STATE_INACTIVE)
5973 continue; 6004 continue;
5974 if (!event_filter_match(event)) 6005 if (!event_filter_match(event))
diff --git a/kernel/futex.c b/kernel/futex.c
index 33664f70e2d2..46cb3a301bc1 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -179,7 +179,15 @@ int __read_mostly futex_cmpxchg_enabled;
179 * Futex flags used to encode options to functions and preserve them across 179 * Futex flags used to encode options to functions and preserve them across
180 * restarts. 180 * restarts.
181 */ 181 */
182#define FLAGS_SHARED 0x01 182#ifdef CONFIG_MMU
183# define FLAGS_SHARED 0x01
184#else
185/*
186 * NOMMU does not have per process address space. Let the compiler optimize
187 * code away.
188 */
189# define FLAGS_SHARED 0x00
190#endif
183#define FLAGS_CLOCKRT 0x02 191#define FLAGS_CLOCKRT 0x02
184#define FLAGS_HAS_TIMEOUT 0x04 192#define FLAGS_HAS_TIMEOUT 0x04
185 193
@@ -405,6 +413,16 @@ static void get_futex_key_refs(union futex_key *key)
405 if (!key->both.ptr) 413 if (!key->both.ptr)
406 return; 414 return;
407 415
416 /*
417 * On MMU less systems futexes are always "private" as there is no per
418 * process address space. We need the smp wmb nevertheless - yes,
419 * arch/blackfin has MMU less SMP ...
420 */
421 if (!IS_ENABLED(CONFIG_MMU)) {
422 smp_mb(); /* explicit smp_mb(); (B) */
423 return;
424 }
425
408 switch (key->both.offset & (FUT_OFF_INODE|FUT_OFF_MMSHARED)) { 426 switch (key->both.offset & (FUT_OFF_INODE|FUT_OFF_MMSHARED)) {
409 case FUT_OFF_INODE: 427 case FUT_OFF_INODE:
410 ihold(key->shared.inode); /* implies smp_mb(); (B) */ 428 ihold(key->shared.inode); /* implies smp_mb(); (B) */
@@ -436,6 +454,9 @@ static void drop_futex_key_refs(union futex_key *key)
436 return; 454 return;
437 } 455 }
438 456
457 if (!IS_ENABLED(CONFIG_MMU))
458 return;
459
439 switch (key->both.offset & (FUT_OFF_INODE|FUT_OFF_MMSHARED)) { 460 switch (key->both.offset & (FUT_OFF_INODE|FUT_OFF_MMSHARED)) {
440 case FUT_OFF_INODE: 461 case FUT_OFF_INODE:
441 iput(key->shared.inode); 462 iput(key->shared.inode);
diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c
index b4c1bc7c9ca2..637389088b3f 100644
--- a/kernel/irq/chip.c
+++ b/kernel/irq/chip.c
@@ -820,6 +820,17 @@ __irq_do_set_handler(struct irq_desc *desc, irq_flow_handler_t handle,
820 desc->name = name; 820 desc->name = name;
821 821
822 if (handle != handle_bad_irq && is_chained) { 822 if (handle != handle_bad_irq && is_chained) {
823 /*
824 * We're about to start this interrupt immediately,
825 * hence the need to set the trigger configuration.
826 * But the .set_type callback may have overridden the
827 * flow handler, ignoring that we're dealing with a
828 * chained interrupt. Reset it immediately because we
829 * do know better.
830 */
831 __irq_set_trigger(desc, irqd_get_trigger_type(&desc->irq_data));
832 desc->handle_irq = handle;
833
823 irq_settings_set_noprobe(desc); 834 irq_settings_set_noprobe(desc);
824 irq_settings_set_norequest(desc); 835 irq_settings_set_norequest(desc);
825 irq_settings_set_nothread(desc); 836 irq_settings_set_nothread(desc);
diff --git a/kernel/locking/qspinlock_paravirt.h b/kernel/locking/qspinlock_paravirt.h
index 37649e69056c..8a99abf58080 100644
--- a/kernel/locking/qspinlock_paravirt.h
+++ b/kernel/locking/qspinlock_paravirt.h
@@ -450,7 +450,7 @@ pv_wait_head_or_lock(struct qspinlock *lock, struct mcs_spinlock *node)
450 goto gotlock; 450 goto gotlock;
451 } 451 }
452 } 452 }
453 WRITE_ONCE(pn->state, vcpu_halted); 453 WRITE_ONCE(pn->state, vcpu_hashed);
454 qstat_inc(qstat_pv_wait_head, true); 454 qstat_inc(qstat_pv_wait_head, true);
455 qstat_inc(qstat_pv_wait_again, waitcnt); 455 qstat_inc(qstat_pv_wait_again, waitcnt);
456 pv_wait(&l->locked, _Q_SLOW_VAL); 456 pv_wait(&l->locked, _Q_SLOW_VAL);
diff --git a/kernel/locking/qspinlock_stat.h b/kernel/locking/qspinlock_stat.h
index 22e025309845..b9d031516254 100644
--- a/kernel/locking/qspinlock_stat.h
+++ b/kernel/locking/qspinlock_stat.h
@@ -153,7 +153,6 @@ static ssize_t qstat_read(struct file *file, char __user *user_buf,
153 */ 153 */
154 if ((counter == qstat_pv_latency_kick) || 154 if ((counter == qstat_pv_latency_kick) ||
155 (counter == qstat_pv_latency_wake)) { 155 (counter == qstat_pv_latency_wake)) {
156 stat = 0;
157 if (kicks) 156 if (kicks)
158 stat = DIV_ROUND_CLOSEST_ULL(stat, kicks); 157 stat = DIV_ROUND_CLOSEST_ULL(stat, kicks);
159 } 158 }
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index a881c6a7ba74..33c79b6105c5 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -300,12 +300,12 @@ static int create_image(int platform_mode)
300 save_processor_state(); 300 save_processor_state();
301 trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, true); 301 trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, true);
302 error = swsusp_arch_suspend(); 302 error = swsusp_arch_suspend();
303 /* Restore control flow magically appears here */
304 restore_processor_state();
303 trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, false); 305 trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, false);
304 if (error) 306 if (error)
305 printk(KERN_ERR "PM: Error %d creating hibernation image\n", 307 printk(KERN_ERR "PM: Error %d creating hibernation image\n",
306 error); 308 error);
307 /* Restore control flow magically appears here */
308 restore_processor_state();
309 if (!in_suspend) 309 if (!in_suspend)
310 events_check_enabled = false; 310 events_check_enabled = false;
311 311
diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h
index 5d4505f30083..7fd2838fa417 100644
--- a/kernel/printk/internal.h
+++ b/kernel/printk/internal.h
@@ -16,11 +16,9 @@
16 */ 16 */
17#include <linux/percpu.h> 17#include <linux/percpu.h>
18 18
19typedef __printf(2, 0) int (*printk_func_t)(int level, const char *fmt, 19typedef __printf(1, 0) int (*printk_func_t)(const char *fmt, va_list args);
20 va_list args);
21 20
22__printf(2, 0) 21int __printf(1, 0) vprintk_default(const char *fmt, va_list args);
23int vprintk_default(int level, const char *fmt, va_list args);
24 22
25#ifdef CONFIG_PRINTK_NMI 23#ifdef CONFIG_PRINTK_NMI
26 24
@@ -33,10 +31,9 @@ extern raw_spinlock_t logbuf_lock;
33 * via per-CPU variable. 31 * via per-CPU variable.
34 */ 32 */
35DECLARE_PER_CPU(printk_func_t, printk_func); 33DECLARE_PER_CPU(printk_func_t, printk_func);
36__printf(2, 0) 34static inline __printf(1, 0) int vprintk_func(const char *fmt, va_list args)
37static inline int vprintk_func(int level, const char *fmt, va_list args)
38{ 35{
39 return this_cpu_read(printk_func)(level, fmt, args); 36 return this_cpu_read(printk_func)(fmt, args);
40} 37}
41 38
42extern atomic_t nmi_message_lost; 39extern atomic_t nmi_message_lost;
@@ -47,10 +44,9 @@ static inline int get_nmi_message_lost(void)
47 44
48#else /* CONFIG_PRINTK_NMI */ 45#else /* CONFIG_PRINTK_NMI */
49 46
50__printf(2, 0) 47static inline __printf(1, 0) int vprintk_func(const char *fmt, va_list args)
51static inline int vprintk_func(int level, const char *fmt, va_list args)
52{ 48{
53 return vprintk_default(level, fmt, args); 49 return vprintk_default(fmt, args);
54} 50}
55 51
56static inline int get_nmi_message_lost(void) 52static inline int get_nmi_message_lost(void)
diff --git a/kernel/printk/nmi.c b/kernel/printk/nmi.c
index bc3eeb1ae6da..b69eb8a2876f 100644
--- a/kernel/printk/nmi.c
+++ b/kernel/printk/nmi.c
@@ -58,7 +58,7 @@ static DEFINE_PER_CPU(struct nmi_seq_buf, nmi_print_seq);
58 * one writer running. But the buffer might get flushed from another 58 * one writer running. But the buffer might get flushed from another
59 * CPU, so we need to be careful. 59 * CPU, so we need to be careful.
60 */ 60 */
61static int vprintk_nmi(int level, const char *fmt, va_list args) 61static int vprintk_nmi(const char *fmt, va_list args)
62{ 62{
63 struct nmi_seq_buf *s = this_cpu_ptr(&nmi_print_seq); 63 struct nmi_seq_buf *s = this_cpu_ptr(&nmi_print_seq);
64 int add = 0; 64 int add = 0;
@@ -79,16 +79,7 @@ again:
79 if (!len) 79 if (!len)
80 smp_rmb(); 80 smp_rmb();
81 81
82 if (level != LOGLEVEL_DEFAULT) { 82 add = vsnprintf(s->buffer + len, sizeof(s->buffer) - len, fmt, args);
83 add = snprintf(s->buffer + len, sizeof(s->buffer) - len,
84 KERN_SOH "%c", '0' + level);
85 add += vsnprintf(s->buffer + len + add,
86 sizeof(s->buffer) - len - add,
87 fmt, args);
88 } else {
89 add = vsnprintf(s->buffer + len, sizeof(s->buffer) - len,
90 fmt, args);
91 }
92 83
93 /* 84 /*
94 * Do it once again if the buffer has been flushed in the meantime. 85 * Do it once again if the buffer has been flushed in the meantime.
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index a37fc8cf8e84..eea6dbc2d8cf 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1930,26 +1930,7 @@ asmlinkage int printk_emit(int facility, int level,
1930} 1930}
1931EXPORT_SYMBOL(printk_emit); 1931EXPORT_SYMBOL(printk_emit);
1932 1932
1933#define define_pr_level(func, loglevel) \ 1933int vprintk_default(const char *fmt, va_list args)
1934asmlinkage __visible void func(const char *fmt, ...) \
1935{ \
1936 va_list args; \
1937 \
1938 va_start(args, fmt); \
1939 vprintk_default(loglevel, fmt, args); \
1940 va_end(args); \
1941} \
1942EXPORT_SYMBOL(func)
1943
1944define_pr_level(__pr_emerg, LOGLEVEL_EMERG);
1945define_pr_level(__pr_alert, LOGLEVEL_ALERT);
1946define_pr_level(__pr_crit, LOGLEVEL_CRIT);
1947define_pr_level(__pr_err, LOGLEVEL_ERR);
1948define_pr_level(__pr_warn, LOGLEVEL_WARNING);
1949define_pr_level(__pr_notice, LOGLEVEL_NOTICE);
1950define_pr_level(__pr_info, LOGLEVEL_INFO);
1951
1952int vprintk_default(int level, const char *fmt, va_list args)
1953{ 1934{
1954 int r; 1935 int r;
1955 1936
@@ -1959,7 +1940,7 @@ int vprintk_default(int level, const char *fmt, va_list args)
1959 return r; 1940 return r;
1960 } 1941 }
1961#endif 1942#endif
1962 r = vprintk_emit(0, level, NULL, 0, fmt, args); 1943 r = vprintk_emit(0, LOGLEVEL_DEFAULT, NULL, 0, fmt, args);
1963 1944
1964 return r; 1945 return r;
1965} 1946}
@@ -1992,7 +1973,7 @@ asmlinkage __visible int printk(const char *fmt, ...)
1992 int r; 1973 int r;
1993 1974
1994 va_start(args, fmt); 1975 va_start(args, fmt);
1995 r = vprintk_func(LOGLEVEL_DEFAULT, fmt, args); 1976 r = vprintk_func(fmt, args);
1996 va_end(args); 1977 va_end(args);
1997 1978
1998 return r; 1979 return r;
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 5c883fe8e440..2a906f20fba7 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -74,6 +74,7 @@
74#include <linux/context_tracking.h> 74#include <linux/context_tracking.h>
75#include <linux/compiler.h> 75#include <linux/compiler.h>
76#include <linux/frame.h> 76#include <linux/frame.h>
77#include <linux/prefetch.h>
77 78
78#include <asm/switch_to.h> 79#include <asm/switch_to.h>
79#include <asm/tlb.h> 80#include <asm/tlb.h>
@@ -2972,6 +2973,23 @@ EXPORT_PER_CPU_SYMBOL(kstat);
2972EXPORT_PER_CPU_SYMBOL(kernel_cpustat); 2973EXPORT_PER_CPU_SYMBOL(kernel_cpustat);
2973 2974
2974/* 2975/*
2976 * The function fair_sched_class.update_curr accesses the struct curr
2977 * and its field curr->exec_start; when called from task_sched_runtime(),
2978 * we observe a high rate of cache misses in practice.
2979 * Prefetching this data results in improved performance.
2980 */
2981static inline void prefetch_curr_exec_start(struct task_struct *p)
2982{
2983#ifdef CONFIG_FAIR_GROUP_SCHED
2984 struct sched_entity *curr = (&p->se)->cfs_rq->curr;
2985#else
2986 struct sched_entity *curr = (&task_rq(p)->cfs)->curr;
2987#endif
2988 prefetch(curr);
2989 prefetch(&curr->exec_start);
2990}
2991
2992/*
2975 * Return accounted runtime for the task. 2993 * Return accounted runtime for the task.
2976 * In case the task is currently running, return the runtime plus current's 2994 * In case the task is currently running, return the runtime plus current's
2977 * pending runtime that have not been accounted yet. 2995 * pending runtime that have not been accounted yet.
@@ -3005,6 +3023,7 @@ unsigned long long task_sched_runtime(struct task_struct *p)
3005 * thread, breaking clock_gettime(). 3023 * thread, breaking clock_gettime().
3006 */ 3024 */
3007 if (task_current(rq, p) && task_on_rq_queued(p)) { 3025 if (task_current(rq, p) && task_on_rq_queued(p)) {
3026 prefetch_curr_exec_start(p);
3008 update_rq_clock(rq); 3027 update_rq_clock(rq);
3009 p->sched_class->update_curr(rq); 3028 p->sched_class->update_curr(rq);
3010 } 3029 }
diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c
index 5be58820465c..d4184498c9f5 100644
--- a/kernel/sched/cpudeadline.c
+++ b/kernel/sched/cpudeadline.c
@@ -168,7 +168,7 @@ void cpudl_set(struct cpudl *cp, int cpu, u64 dl, int is_valid)
168 168
169 if (old_idx == IDX_INVALID) { 169 if (old_idx == IDX_INVALID) {
170 cp->size++; 170 cp->size++;
171 cp->elements[cp->size - 1].dl = 0; 171 cp->elements[cp->size - 1].dl = dl;
172 cp->elements[cp->size - 1].cpu = cpu; 172 cp->elements[cp->size - 1].cpu = cpu;
173 cp->elements[cpu].idx = cp->size - 1; 173 cp->elements[cpu].idx = cp->size - 1;
174 cpudl_change_key(cp, cp->size - 1, dl); 174 cpudl_change_key(cp, cp->size - 1, dl);
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 1934f658c036..9858266fb0b3 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -508,13 +508,21 @@ void account_process_tick(struct task_struct *p, int user_tick)
508 */ 508 */
509void account_idle_ticks(unsigned long ticks) 509void account_idle_ticks(unsigned long ticks)
510{ 510{
511 cputime_t cputime, steal;
511 512
512 if (sched_clock_irqtime) { 513 if (sched_clock_irqtime) {
513 irqtime_account_idle_ticks(ticks); 514 irqtime_account_idle_ticks(ticks);
514 return; 515 return;
515 } 516 }
516 517
517 account_idle_time(jiffies_to_cputime(ticks)); 518 cputime = jiffies_to_cputime(ticks);
519 steal = steal_account_process_time(cputime);
520
521 if (steal >= cputime)
522 return;
523
524 cputime -= steal;
525 account_idle_time(cputime);
518} 526}
519 527
520/* 528/*
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index fcb7f0217ff4..1ce8867283dc 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -658,8 +658,11 @@ static enum hrtimer_restart dl_task_timer(struct hrtimer *timer)
658 * 658 *
659 * XXX figure out if select_task_rq_dl() deals with offline cpus. 659 * XXX figure out if select_task_rq_dl() deals with offline cpus.
660 */ 660 */
661 if (unlikely(!rq->online)) 661 if (unlikely(!rq->online)) {
662 lockdep_unpin_lock(&rq->lock, rf.cookie);
662 rq = dl_task_offline_migration(rq, p); 663 rq = dl_task_offline_migration(rq, p);
664 rf.cookie = lockdep_pin_lock(&rq->lock);
665 }
663 666
664 /* 667 /*
665 * Queueing this task back might have overloaded rq, check if we need 668 * Queueing this task back might have overloaded rq, check if we need
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 4088eedea763..039de34f1521 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4269,7 +4269,7 @@ static void sync_throttle(struct task_group *tg, int cpu)
4269 pcfs_rq = tg->parent->cfs_rq[cpu]; 4269 pcfs_rq = tg->parent->cfs_rq[cpu];
4270 4270
4271 cfs_rq->throttle_count = pcfs_rq->throttle_count; 4271 cfs_rq->throttle_count = pcfs_rq->throttle_count;
4272 pcfs_rq->throttled_clock_task = rq_clock_task(cpu_rq(cpu)); 4272 cfs_rq->throttled_clock_task = rq_clock_task(cpu_rq(cpu));
4273} 4273}
4274 4274
4275/* conditionally throttle active cfs_rq's from put_prev_entity() */ 4275/* conditionally throttle active cfs_rq's from put_prev_entity() */
diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 555670a5143c..32bf6f75a8fe 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1496,6 +1496,7 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
1496 struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]); 1496 struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
1497 u64 expires = KTIME_MAX; 1497 u64 expires = KTIME_MAX;
1498 unsigned long nextevt; 1498 unsigned long nextevt;
1499 bool is_max_delta;
1499 1500
1500 /* 1501 /*
1501 * Pretend that there is no timer pending if the cpu is offline. 1502 * Pretend that there is no timer pending if the cpu is offline.
@@ -1506,6 +1507,7 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
1506 1507
1507 spin_lock(&base->lock); 1508 spin_lock(&base->lock);
1508 nextevt = __next_timer_interrupt(base); 1509 nextevt = __next_timer_interrupt(base);
1510 is_max_delta = (nextevt == base->clk + NEXT_TIMER_MAX_DELTA);
1509 base->next_expiry = nextevt; 1511 base->next_expiry = nextevt;
1510 /* 1512 /*
1511 * We have a fresh next event. Check whether we can forward the base: 1513 * We have a fresh next event. Check whether we can forward the base:
@@ -1519,7 +1521,8 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
1519 expires = basem; 1521 expires = basem;
1520 base->is_idle = false; 1522 base->is_idle = false;
1521 } else { 1523 } else {
1522 expires = basem + (nextevt - basej) * TICK_NSEC; 1524 if (!is_max_delta)
1525 expires = basem + (nextevt - basej) * TICK_NSEC;
1523 /* 1526 /*
1524 * If we expect to sleep more than a tick, mark the base idle: 1527 * If we expect to sleep more than a tick, mark the base idle:
1525 */ 1528 */
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index b9aa1b0b38b0..87e11d8ad536 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1448,6 +1448,7 @@ static void dissolve_free_huge_page(struct page *page)
1448 list_del(&page->lru); 1448 list_del(&page->lru);
1449 h->free_huge_pages--; 1449 h->free_huge_pages--;
1450 h->free_huge_pages_node[nid]--; 1450 h->free_huge_pages_node[nid]--;
1451 h->max_huge_pages--;
1451 update_and_free_page(h, page); 1452 update_and_free_page(h, page);
1452 } 1453 }
1453 spin_unlock(&hugetlb_lock); 1454 spin_unlock(&hugetlb_lock);
diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c
index b6728a33a4ac..baabaad4a4aa 100644
--- a/mm/kasan/quarantine.c
+++ b/mm/kasan/quarantine.c
@@ -217,11 +217,8 @@ void quarantine_reduce(void)
217 new_quarantine_size = (READ_ONCE(totalram_pages) << PAGE_SHIFT) / 217 new_quarantine_size = (READ_ONCE(totalram_pages) << PAGE_SHIFT) /
218 QUARANTINE_FRACTION; 218 QUARANTINE_FRACTION;
219 percpu_quarantines = QUARANTINE_PERCPU_SIZE * num_online_cpus(); 219 percpu_quarantines = QUARANTINE_PERCPU_SIZE * num_online_cpus();
220 if (WARN_ONCE(new_quarantine_size < percpu_quarantines, 220 new_quarantine_size = (new_quarantine_size < percpu_quarantines) ?
221 "Too little memory, disabling global KASAN quarantine.\n")) 221 0 : new_quarantine_size - percpu_quarantines;
222 new_quarantine_size = 0;
223 else
224 new_quarantine_size -= percpu_quarantines;
225 WRITE_ONCE(quarantine_size, new_quarantine_size); 222 WRITE_ONCE(quarantine_size, new_quarantine_size);
226 223
227 last = global_quarantine.head; 224 last = global_quarantine.head;
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 66beca1ad92f..2ff0289ad061 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2337,8 +2337,11 @@ int memcg_kmem_charge(struct page *page, gfp_t gfp, int order)
2337 return 0; 2337 return 0;
2338 2338
2339 memcg = get_mem_cgroup_from_mm(current->mm); 2339 memcg = get_mem_cgroup_from_mm(current->mm);
2340 if (!mem_cgroup_is_root(memcg)) 2340 if (!mem_cgroup_is_root(memcg)) {
2341 ret = memcg_kmem_charge_memcg(page, gfp, order, memcg); 2341 ret = memcg_kmem_charge_memcg(page, gfp, order, memcg);
2342 if (!ret)
2343 __SetPageKmemcg(page);
2344 }
2342 css_put(&memcg->css); 2345 css_put(&memcg->css);
2343 return ret; 2346 return ret;
2344} 2347}
@@ -2365,6 +2368,11 @@ void memcg_kmem_uncharge(struct page *page, int order)
2365 page_counter_uncharge(&memcg->memsw, nr_pages); 2368 page_counter_uncharge(&memcg->memsw, nr_pages);
2366 2369
2367 page->mem_cgroup = NULL; 2370 page->mem_cgroup = NULL;
2371
2372 /* slab pages do not have PageKmemcg flag set */
2373 if (PageKmemcg(page))
2374 __ClearPageKmemcg(page);
2375
2368 css_put_many(&memcg->css, nr_pages); 2376 css_put_many(&memcg->css, nr_pages);
2369} 2377}
2370#endif /* !CONFIG_SLOB */ 2378#endif /* !CONFIG_SLOB */
@@ -4069,14 +4077,32 @@ static struct cftype mem_cgroup_legacy_files[] = {
4069 4077
4070static DEFINE_IDR(mem_cgroup_idr); 4078static DEFINE_IDR(mem_cgroup_idr);
4071 4079
4072static void mem_cgroup_id_get(struct mem_cgroup *memcg) 4080static void mem_cgroup_id_get_many(struct mem_cgroup *memcg, unsigned int n)
4073{ 4081{
4074 atomic_inc(&memcg->id.ref); 4082 atomic_add(n, &memcg->id.ref);
4075} 4083}
4076 4084
4077static void mem_cgroup_id_put(struct mem_cgroup *memcg) 4085static struct mem_cgroup *mem_cgroup_id_get_online(struct mem_cgroup *memcg)
4078{ 4086{
4079 if (atomic_dec_and_test(&memcg->id.ref)) { 4087 while (!atomic_inc_not_zero(&memcg->id.ref)) {
4088 /*
4089 * The root cgroup cannot be destroyed, so it's refcount must
4090 * always be >= 1.
4091 */
4092 if (WARN_ON_ONCE(memcg == root_mem_cgroup)) {
4093 VM_BUG_ON(1);
4094 break;
4095 }
4096 memcg = parent_mem_cgroup(memcg);
4097 if (!memcg)
4098 memcg = root_mem_cgroup;
4099 }
4100 return memcg;
4101}
4102
4103static void mem_cgroup_id_put_many(struct mem_cgroup *memcg, unsigned int n)
4104{
4105 if (atomic_sub_and_test(n, &memcg->id.ref)) {
4080 idr_remove(&mem_cgroup_idr, memcg->id.id); 4106 idr_remove(&mem_cgroup_idr, memcg->id.id);
4081 memcg->id.id = 0; 4107 memcg->id.id = 0;
4082 4108
@@ -4085,6 +4111,16 @@ static void mem_cgroup_id_put(struct mem_cgroup *memcg)
4085 } 4111 }
4086} 4112}
4087 4113
4114static inline void mem_cgroup_id_get(struct mem_cgroup *memcg)
4115{
4116 mem_cgroup_id_get_many(memcg, 1);
4117}
4118
4119static inline void mem_cgroup_id_put(struct mem_cgroup *memcg)
4120{
4121 mem_cgroup_id_put_many(memcg, 1);
4122}
4123
4088/** 4124/**
4089 * mem_cgroup_from_id - look up a memcg from a memcg id 4125 * mem_cgroup_from_id - look up a memcg from a memcg id
4090 * @id: the memcg id to look up 4126 * @id: the memcg id to look up
@@ -4719,6 +4755,8 @@ static void __mem_cgroup_clear_mc(void)
4719 if (!mem_cgroup_is_root(mc.from)) 4755 if (!mem_cgroup_is_root(mc.from))
4720 page_counter_uncharge(&mc.from->memsw, mc.moved_swap); 4756 page_counter_uncharge(&mc.from->memsw, mc.moved_swap);
4721 4757
4758 mem_cgroup_id_put_many(mc.from, mc.moved_swap);
4759
4722 /* 4760 /*
4723 * we charged both to->memory and to->memsw, so we 4761 * we charged both to->memory and to->memsw, so we
4724 * should uncharge to->memory. 4762 * should uncharge to->memory.
@@ -4726,9 +4764,9 @@ static void __mem_cgroup_clear_mc(void)
4726 if (!mem_cgroup_is_root(mc.to)) 4764 if (!mem_cgroup_is_root(mc.to))
4727 page_counter_uncharge(&mc.to->memory, mc.moved_swap); 4765 page_counter_uncharge(&mc.to->memory, mc.moved_swap);
4728 4766
4729 css_put_many(&mc.from->css, mc.moved_swap); 4767 mem_cgroup_id_get_many(mc.to, mc.moved_swap);
4768 css_put_many(&mc.to->css, mc.moved_swap);
4730 4769
4731 /* we've already done css_get(mc.to) */
4732 mc.moved_swap = 0; 4770 mc.moved_swap = 0;
4733 } 4771 }
4734 memcg_oom_recover(from); 4772 memcg_oom_recover(from);
@@ -5537,8 +5575,10 @@ static void uncharge_list(struct list_head *page_list)
5537 else 5575 else
5538 nr_file += nr_pages; 5576 nr_file += nr_pages;
5539 pgpgout++; 5577 pgpgout++;
5540 } else 5578 } else {
5541 nr_kmem += 1 << compound_order(page); 5579 nr_kmem += 1 << compound_order(page);
5580 __ClearPageKmemcg(page);
5581 }
5542 5582
5543 page->mem_cgroup = NULL; 5583 page->mem_cgroup = NULL;
5544 } while (next != page_list); 5584 } while (next != page_list);
@@ -5790,7 +5830,7 @@ subsys_initcall(mem_cgroup_init);
5790 */ 5830 */
5791void mem_cgroup_swapout(struct page *page, swp_entry_t entry) 5831void mem_cgroup_swapout(struct page *page, swp_entry_t entry)
5792{ 5832{
5793 struct mem_cgroup *memcg; 5833 struct mem_cgroup *memcg, *swap_memcg;
5794 unsigned short oldid; 5834 unsigned short oldid;
5795 5835
5796 VM_BUG_ON_PAGE(PageLRU(page), page); 5836 VM_BUG_ON_PAGE(PageLRU(page), page);
@@ -5805,16 +5845,27 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry)
5805 if (!memcg) 5845 if (!memcg)
5806 return; 5846 return;
5807 5847
5808 mem_cgroup_id_get(memcg); 5848 /*
5809 oldid = swap_cgroup_record(entry, mem_cgroup_id(memcg)); 5849 * In case the memcg owning these pages has been offlined and doesn't
5850 * have an ID allocated to it anymore, charge the closest online
5851 * ancestor for the swap instead and transfer the memory+swap charge.
5852 */
5853 swap_memcg = mem_cgroup_id_get_online(memcg);
5854 oldid = swap_cgroup_record(entry, mem_cgroup_id(swap_memcg));
5810 VM_BUG_ON_PAGE(oldid, page); 5855 VM_BUG_ON_PAGE(oldid, page);
5811 mem_cgroup_swap_statistics(memcg, true); 5856 mem_cgroup_swap_statistics(swap_memcg, true);
5812 5857
5813 page->mem_cgroup = NULL; 5858 page->mem_cgroup = NULL;
5814 5859
5815 if (!mem_cgroup_is_root(memcg)) 5860 if (!mem_cgroup_is_root(memcg))
5816 page_counter_uncharge(&memcg->memory, 1); 5861 page_counter_uncharge(&memcg->memory, 1);
5817 5862
5863 if (memcg != swap_memcg) {
5864 if (!mem_cgroup_is_root(swap_memcg))
5865 page_counter_charge(&swap_memcg->memsw, 1);
5866 page_counter_uncharge(&memcg->memsw, 1);
5867 }
5868
5818 /* 5869 /*
5819 * Interrupts should be disabled here because the caller holds the 5870 * Interrupts should be disabled here because the caller holds the
5820 * mapping->tree_lock lock which is taken with interrupts-off. It is 5871 * mapping->tree_lock lock which is taken with interrupts-off. It is
@@ -5853,11 +5904,14 @@ int mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry)
5853 if (!memcg) 5904 if (!memcg)
5854 return 0; 5905 return 0;
5855 5906
5907 memcg = mem_cgroup_id_get_online(memcg);
5908
5856 if (!mem_cgroup_is_root(memcg) && 5909 if (!mem_cgroup_is_root(memcg) &&
5857 !page_counter_try_charge(&memcg->swap, 1, &counter)) 5910 !page_counter_try_charge(&memcg->swap, 1, &counter)) {
5911 mem_cgroup_id_put(memcg);
5858 return -ENOMEM; 5912 return -ENOMEM;
5913 }
5859 5914
5860 mem_cgroup_id_get(memcg);
5861 oldid = swap_cgroup_record(entry, mem_cgroup_id(memcg)); 5915 oldid = swap_cgroup_record(entry, mem_cgroup_id(memcg));
5862 VM_BUG_ON_PAGE(oldid, page); 5916 VM_BUG_ON_PAGE(oldid, page);
5863 mem_cgroup_swap_statistics(memcg, true); 5917 mem_cgroup_swap_statistics(memcg, true);
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 3894b65b1555..41266dc29f33 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1219,6 +1219,7 @@ static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start)
1219 1219
1220 /* init node's zones as empty zones, we don't have any present pages.*/ 1220 /* init node's zones as empty zones, we don't have any present pages.*/
1221 free_area_init_node(nid, zones_size, start_pfn, zholes_size); 1221 free_area_init_node(nid, zones_size, start_pfn, zholes_size);
1222 pgdat->per_cpu_nodestats = alloc_percpu(struct per_cpu_nodestat);
1222 1223
1223 /* 1224 /*
1224 * The node we allocated has no zone fallback lists. For avoiding 1225 * The node we allocated has no zone fallback lists. For avoiding
@@ -1249,6 +1250,7 @@ static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start)
1249static void rollback_node_hotadd(int nid, pg_data_t *pgdat) 1250static void rollback_node_hotadd(int nid, pg_data_t *pgdat)
1250{ 1251{
1251 arch_refresh_nodedata(nid, NULL); 1252 arch_refresh_nodedata(nid, NULL);
1253 free_percpu(pgdat->per_cpu_nodestats);
1252 arch_free_nodedata(pgdat); 1254 arch_free_nodedata(pgdat);
1253 return; 1255 return;
1254} 1256}
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 7d0a275df822..d53a9aa00977 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -764,7 +764,7 @@ bool task_will_free_mem(struct task_struct *task)
764{ 764{
765 struct mm_struct *mm = task->mm; 765 struct mm_struct *mm = task->mm;
766 struct task_struct *p; 766 struct task_struct *p;
767 bool ret; 767 bool ret = true;
768 768
769 /* 769 /*
770 * Skip tasks without mm because it might have passed its exit_mm and 770 * Skip tasks without mm because it might have passed its exit_mm and
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index fb975cec3518..3fbe73a6fe4b 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1008,10 +1008,8 @@ static __always_inline bool free_pages_prepare(struct page *page,
1008 } 1008 }
1009 if (PageMappingFlags(page)) 1009 if (PageMappingFlags(page))
1010 page->mapping = NULL; 1010 page->mapping = NULL;
1011 if (memcg_kmem_enabled() && PageKmemcg(page)) { 1011 if (memcg_kmem_enabled() && PageKmemcg(page))
1012 memcg_kmem_uncharge(page, order); 1012 memcg_kmem_uncharge(page, order);
1013 __ClearPageKmemcg(page);
1014 }
1015 if (check_free) 1013 if (check_free)
1016 bad += free_pages_check(page); 1014 bad += free_pages_check(page);
1017 if (bad) 1015 if (bad)
@@ -3756,12 +3754,10 @@ no_zone:
3756 } 3754 }
3757 3755
3758out: 3756out:
3759 if (memcg_kmem_enabled() && (gfp_mask & __GFP_ACCOUNT) && page) { 3757 if (memcg_kmem_enabled() && (gfp_mask & __GFP_ACCOUNT) && page &&
3760 if (unlikely(memcg_kmem_charge(page, gfp_mask, order))) { 3758 unlikely(memcg_kmem_charge(page, gfp_mask, order) != 0)) {
3761 __free_pages(page, order); 3759 __free_pages(page, order);
3762 page = NULL; 3760 page = NULL;
3763 } else
3764 __SetPageKmemcg(page);
3765 } 3761 }
3766 3762
3767 if (kmemcheck_enabled && page) 3763 if (kmemcheck_enabled && page)
@@ -4064,7 +4060,7 @@ long si_mem_available(void)
4064 int lru; 4060 int lru;
4065 4061
4066 for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++) 4062 for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
4067 pages[lru] = global_page_state(NR_LRU_BASE + lru); 4063 pages[lru] = global_node_page_state(NR_LRU_BASE + lru);
4068 4064
4069 for_each_zone(zone) 4065 for_each_zone(zone)
4070 wmark_low += zone->watermark[WMARK_LOW]; 4066 wmark_low += zone->watermark[WMARK_LOW];
@@ -4761,6 +4757,8 @@ int local_memory_node(int node)
4761} 4757}
4762#endif 4758#endif
4763 4759
4760static void setup_min_unmapped_ratio(void);
4761static void setup_min_slab_ratio(void);
4764#else /* CONFIG_NUMA */ 4762#else /* CONFIG_NUMA */
4765 4763
4766static void set_zonelist_order(void) 4764static void set_zonelist_order(void)
@@ -5882,9 +5880,6 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat)
5882 zone->managed_pages = is_highmem_idx(j) ? realsize : freesize; 5880 zone->managed_pages = is_highmem_idx(j) ? realsize : freesize;
5883#ifdef CONFIG_NUMA 5881#ifdef CONFIG_NUMA
5884 zone->node = nid; 5882 zone->node = nid;
5885 pgdat->min_unmapped_pages += (freesize*sysctl_min_unmapped_ratio)
5886 / 100;
5887 pgdat->min_slab_pages += (freesize * sysctl_min_slab_ratio) / 100;
5888#endif 5883#endif
5889 zone->name = zone_names[j]; 5884 zone->name = zone_names[j];
5890 zone->zone_pgdat = pgdat; 5885 zone->zone_pgdat = pgdat;
@@ -6805,6 +6800,12 @@ int __meminit init_per_zone_wmark_min(void)
6805 setup_per_zone_wmarks(); 6800 setup_per_zone_wmarks();
6806 refresh_zone_stat_thresholds(); 6801 refresh_zone_stat_thresholds();
6807 setup_per_zone_lowmem_reserve(); 6802 setup_per_zone_lowmem_reserve();
6803
6804#ifdef CONFIG_NUMA
6805 setup_min_unmapped_ratio();
6806 setup_min_slab_ratio();
6807#endif
6808
6808 return 0; 6809 return 0;
6809} 6810}
6810core_initcall(init_per_zone_wmark_min) 6811core_initcall(init_per_zone_wmark_min)
@@ -6846,43 +6847,58 @@ int watermark_scale_factor_sysctl_handler(struct ctl_table *table, int write,
6846} 6847}
6847 6848
6848#ifdef CONFIG_NUMA 6849#ifdef CONFIG_NUMA
6850static void setup_min_unmapped_ratio(void)
6851{
6852 pg_data_t *pgdat;
6853 struct zone *zone;
6854
6855 for_each_online_pgdat(pgdat)
6856 pgdat->min_unmapped_pages = 0;
6857
6858 for_each_zone(zone)
6859 zone->zone_pgdat->min_unmapped_pages += (zone->managed_pages *
6860 sysctl_min_unmapped_ratio) / 100;
6861}
6862
6863
6849int sysctl_min_unmapped_ratio_sysctl_handler(struct ctl_table *table, int write, 6864int sysctl_min_unmapped_ratio_sysctl_handler(struct ctl_table *table, int write,
6850 void __user *buffer, size_t *length, loff_t *ppos) 6865 void __user *buffer, size_t *length, loff_t *ppos)
6851{ 6866{
6852 struct pglist_data *pgdat;
6853 struct zone *zone;
6854 int rc; 6867 int rc;
6855 6868
6856 rc = proc_dointvec_minmax(table, write, buffer, length, ppos); 6869 rc = proc_dointvec_minmax(table, write, buffer, length, ppos);
6857 if (rc) 6870 if (rc)
6858 return rc; 6871 return rc;
6859 6872
6873 setup_min_unmapped_ratio();
6874
6875 return 0;
6876}
6877
6878static void setup_min_slab_ratio(void)
6879{
6880 pg_data_t *pgdat;
6881 struct zone *zone;
6882
6860 for_each_online_pgdat(pgdat) 6883 for_each_online_pgdat(pgdat)
6861 pgdat->min_slab_pages = 0; 6884 pgdat->min_slab_pages = 0;
6862 6885
6863 for_each_zone(zone) 6886 for_each_zone(zone)
6864 zone->zone_pgdat->min_unmapped_pages += (zone->managed_pages * 6887 zone->zone_pgdat->min_slab_pages += (zone->managed_pages *
6865 sysctl_min_unmapped_ratio) / 100; 6888 sysctl_min_slab_ratio) / 100;
6866 return 0;
6867} 6889}
6868 6890
6869int sysctl_min_slab_ratio_sysctl_handler(struct ctl_table *table, int write, 6891int sysctl_min_slab_ratio_sysctl_handler(struct ctl_table *table, int write,
6870 void __user *buffer, size_t *length, loff_t *ppos) 6892 void __user *buffer, size_t *length, loff_t *ppos)
6871{ 6893{
6872 struct pglist_data *pgdat;
6873 struct zone *zone;
6874 int rc; 6894 int rc;
6875 6895
6876 rc = proc_dointvec_minmax(table, write, buffer, length, ppos); 6896 rc = proc_dointvec_minmax(table, write, buffer, length, ppos);
6877 if (rc) 6897 if (rc)
6878 return rc; 6898 return rc;
6879 6899
6880 for_each_online_pgdat(pgdat) 6900 setup_min_slab_ratio();
6881 pgdat->min_slab_pages = 0;
6882 6901
6883 for_each_zone(zone)
6884 zone->zone_pgdat->min_slab_pages += (zone->managed_pages *
6885 sysctl_min_slab_ratio) / 100;
6886 return 0; 6902 return 0;
6887} 6903}
6888#endif 6904#endif
diff --git a/mm/rmap.c b/mm/rmap.c
index 709bc83703b1..1ef36404e7b2 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1284,8 +1284,9 @@ void page_add_file_rmap(struct page *page, bool compound)
1284 VM_BUG_ON_PAGE(!PageSwapBacked(page), page); 1284 VM_BUG_ON_PAGE(!PageSwapBacked(page), page);
1285 __inc_node_page_state(page, NR_SHMEM_PMDMAPPED); 1285 __inc_node_page_state(page, NR_SHMEM_PMDMAPPED);
1286 } else { 1286 } else {
1287 if (PageTransCompound(page)) { 1287 if (PageTransCompound(page) && page_mapping(page)) {
1288 VM_BUG_ON_PAGE(!PageLocked(page), page); 1288 VM_WARN_ON_ONCE(!PageLocked(page));
1289
1289 SetPageDoubleMap(compound_head(page)); 1290 SetPageDoubleMap(compound_head(page));
1290 if (PageMlocked(page)) 1291 if (PageMlocked(page))
1291 clear_page_mlock(compound_head(page)); 1292 clear_page_mlock(compound_head(page));
@@ -1303,7 +1304,7 @@ static void page_remove_file_rmap(struct page *page, bool compound)
1303{ 1304{
1304 int i, nr = 1; 1305 int i, nr = 1;
1305 1306
1306 VM_BUG_ON_PAGE(compound && !PageTransHuge(page), page); 1307 VM_BUG_ON_PAGE(compound && !PageHead(page), page);
1307 lock_page_memcg(page); 1308 lock_page_memcg(page);
1308 1309
1309 /* Hugepages are not counted in NR_FILE_MAPPED for now. */ 1310 /* Hugepages are not counted in NR_FILE_MAPPED for now. */
diff --git a/mm/shmem.c b/mm/shmem.c
index 7f7748a0f9e1..fd8b2b5741b1 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -3975,7 +3975,9 @@ static ssize_t shmem_enabled_store(struct kobject *kobj,
3975 3975
3976struct kobj_attribute shmem_enabled_attr = 3976struct kobj_attribute shmem_enabled_attr =
3977 __ATTR(shmem_enabled, 0644, shmem_enabled_show, shmem_enabled_store); 3977 __ATTR(shmem_enabled, 0644, shmem_enabled_show, shmem_enabled_store);
3978#endif /* CONFIG_TRANSPARENT_HUGE_PAGECACHE && CONFIG_SYSFS */
3978 3979
3980#ifdef CONFIG_TRANSPARENT_HUGE_PAGECACHE
3979bool shmem_huge_enabled(struct vm_area_struct *vma) 3981bool shmem_huge_enabled(struct vm_area_struct *vma)
3980{ 3982{
3981 struct inode *inode = file_inode(vma->vm_file); 3983 struct inode *inode = file_inode(vma->vm_file);
@@ -4006,7 +4008,7 @@ bool shmem_huge_enabled(struct vm_area_struct *vma)
4006 return false; 4008 return false;
4007 } 4009 }
4008} 4010}
4009#endif /* CONFIG_TRANSPARENT_HUGE_PAGECACHE && CONFIG_SYSFS */ 4011#endif /* CONFIG_TRANSPARENT_HUGE_PAGECACHE */
4010 4012
4011#else /* !CONFIG_SHMEM */ 4013#else /* !CONFIG_SHMEM */
4012 4014
diff --git a/mm/slub.c b/mm/slub.c
index cead06394e9e..9adae58462f8 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3629,6 +3629,7 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page,
3629 */ 3629 */
3630static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n) 3630static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n)
3631{ 3631{
3632 LIST_HEAD(discard);
3632 struct page *page, *h; 3633 struct page *page, *h;
3633 3634
3634 BUG_ON(irqs_disabled()); 3635 BUG_ON(irqs_disabled());
@@ -3636,13 +3637,16 @@ static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n)
3636 list_for_each_entry_safe(page, h, &n->partial, lru) { 3637 list_for_each_entry_safe(page, h, &n->partial, lru) {
3637 if (!page->inuse) { 3638 if (!page->inuse) {
3638 remove_partial(n, page); 3639 remove_partial(n, page);
3639 discard_slab(s, page); 3640 list_add(&page->lru, &discard);
3640 } else { 3641 } else {
3641 list_slab_objects(s, page, 3642 list_slab_objects(s, page,
3642 "Objects remaining in %s on __kmem_cache_shutdown()"); 3643 "Objects remaining in %s on __kmem_cache_shutdown()");
3643 } 3644 }
3644 } 3645 }
3645 spin_unlock_irq(&n->list_lock); 3646 spin_unlock_irq(&n->list_lock);
3647
3648 list_for_each_entry_safe(page, h, &discard, lru)
3649 discard_slab(s, page);
3646} 3650}
3647 3651
3648/* 3652/*
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
index 4acb1d5417aa..f24b25c25106 100644
--- a/net/9p/trans_virtio.c
+++ b/net/9p/trans_virtio.c
@@ -507,8 +507,8 @@ err_out:
507 /* wakeup anybody waiting for slots to pin pages */ 507 /* wakeup anybody waiting for slots to pin pages */
508 wake_up(&vp_wq); 508 wake_up(&vp_wq);
509 } 509 }
510 kfree(in_pages); 510 kvfree(in_pages);
511 kfree(out_pages); 511 kvfree(out_pages);
512 return err; 512 return err;
513} 513}
514 514
diff --git a/net/ceph/mon_client.c b/net/ceph/mon_client.c
index c83326c5ba58..ef34a02719d7 100644
--- a/net/ceph/mon_client.c
+++ b/net/ceph/mon_client.c
@@ -574,7 +574,7 @@ static void complete_generic_request(struct ceph_mon_generic_request *req)
574 put_generic_request(req); 574 put_generic_request(req);
575} 575}
576 576
577void cancel_generic_request(struct ceph_mon_generic_request *req) 577static void cancel_generic_request(struct ceph_mon_generic_request *req)
578{ 578{
579 struct ceph_mon_client *monc = req->monc; 579 struct ceph_mon_client *monc = req->monc;
580 struct ceph_mon_generic_request *lookup_req; 580 struct ceph_mon_generic_request *lookup_req;
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index b5ec09612ff7..a97e7b506612 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -4220,7 +4220,7 @@ static struct ceph_msg *alloc_msg_with_page_vector(struct ceph_msg_header *hdr)
4220 4220
4221 pages = ceph_alloc_page_vector(calc_pages_for(0, data_len), 4221 pages = ceph_alloc_page_vector(calc_pages_for(0, data_len),
4222 GFP_NOIO); 4222 GFP_NOIO);
4223 if (!pages) { 4223 if (IS_ERR(pages)) {
4224 ceph_msg_put(m); 4224 ceph_msg_put(m);
4225 return NULL; 4225 return NULL;
4226 } 4226 }
diff --git a/net/ceph/string_table.c b/net/ceph/string_table.c
index ca53c8319209..22fb96efcf34 100644
--- a/net/ceph/string_table.c
+++ b/net/ceph/string_table.c
@@ -84,12 +84,6 @@ retry:
84} 84}
85EXPORT_SYMBOL(ceph_find_or_create_string); 85EXPORT_SYMBOL(ceph_find_or_create_string);
86 86
87static void ceph_free_string(struct rcu_head *head)
88{
89 struct ceph_string *cs = container_of(head, struct ceph_string, rcu);
90 kfree(cs);
91}
92
93void ceph_release_string(struct kref *ref) 87void ceph_release_string(struct kref *ref)
94{ 88{
95 struct ceph_string *cs = container_of(ref, struct ceph_string, kref); 89 struct ceph_string *cs = container_of(ref, struct ceph_string, kref);
@@ -101,7 +95,7 @@ void ceph_release_string(struct kref *ref)
101 } 95 }
102 spin_unlock(&string_tree_lock); 96 spin_unlock(&string_tree_lock);
103 97
104 call_rcu(&cs->rcu, ceph_free_string); 98 kfree_rcu(cs, rcu);
105} 99}
106EXPORT_SYMBOL(ceph_release_string); 100EXPORT_SYMBOL(ceph_release_string);
107 101
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index 23c8e7c39656..976c7812bbd5 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -340,12 +340,14 @@ gss_release_msg(struct gss_upcall_msg *gss_msg)
340} 340}
341 341
342static struct gss_upcall_msg * 342static struct gss_upcall_msg *
343__gss_find_upcall(struct rpc_pipe *pipe, kuid_t uid) 343__gss_find_upcall(struct rpc_pipe *pipe, kuid_t uid, const struct gss_auth *auth)
344{ 344{
345 struct gss_upcall_msg *pos; 345 struct gss_upcall_msg *pos;
346 list_for_each_entry(pos, &pipe->in_downcall, list) { 346 list_for_each_entry(pos, &pipe->in_downcall, list) {
347 if (!uid_eq(pos->uid, uid)) 347 if (!uid_eq(pos->uid, uid))
348 continue; 348 continue;
349 if (auth && pos->auth->service != auth->service)
350 continue;
349 atomic_inc(&pos->count); 351 atomic_inc(&pos->count);
350 dprintk("RPC: %s found msg %p\n", __func__, pos); 352 dprintk("RPC: %s found msg %p\n", __func__, pos);
351 return pos; 353 return pos;
@@ -365,7 +367,7 @@ gss_add_msg(struct gss_upcall_msg *gss_msg)
365 struct gss_upcall_msg *old; 367 struct gss_upcall_msg *old;
366 368
367 spin_lock(&pipe->lock); 369 spin_lock(&pipe->lock);
368 old = __gss_find_upcall(pipe, gss_msg->uid); 370 old = __gss_find_upcall(pipe, gss_msg->uid, gss_msg->auth);
369 if (old == NULL) { 371 if (old == NULL) {
370 atomic_inc(&gss_msg->count); 372 atomic_inc(&gss_msg->count);
371 list_add(&gss_msg->list, &pipe->in_downcall); 373 list_add(&gss_msg->list, &pipe->in_downcall);
@@ -714,7 +716,7 @@ gss_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
714 err = -ENOENT; 716 err = -ENOENT;
715 /* Find a matching upcall */ 717 /* Find a matching upcall */
716 spin_lock(&pipe->lock); 718 spin_lock(&pipe->lock);
717 gss_msg = __gss_find_upcall(pipe, uid); 719 gss_msg = __gss_find_upcall(pipe, uid, NULL);
718 if (gss_msg == NULL) { 720 if (gss_msg == NULL) {
719 spin_unlock(&pipe->lock); 721 spin_unlock(&pipe->lock);
720 goto err_put_ctx; 722 goto err_put_ctx;
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index cb49898a5a58..7f79fb7dc6a0 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -2638,6 +2638,7 @@ int rpc_clnt_add_xprt(struct rpc_clnt *clnt,
2638{ 2638{
2639 struct rpc_xprt_switch *xps; 2639 struct rpc_xprt_switch *xps;
2640 struct rpc_xprt *xprt; 2640 struct rpc_xprt *xprt;
2641 unsigned long reconnect_timeout;
2641 unsigned char resvport; 2642 unsigned char resvport;
2642 int ret = 0; 2643 int ret = 0;
2643 2644
@@ -2649,6 +2650,7 @@ int rpc_clnt_add_xprt(struct rpc_clnt *clnt,
2649 return -EAGAIN; 2650 return -EAGAIN;
2650 } 2651 }
2651 resvport = xprt->resvport; 2652 resvport = xprt->resvport;
2653 reconnect_timeout = xprt->max_reconnect_timeout;
2652 rcu_read_unlock(); 2654 rcu_read_unlock();
2653 2655
2654 xprt = xprt_create_transport(xprtargs); 2656 xprt = xprt_create_transport(xprtargs);
@@ -2657,6 +2659,7 @@ int rpc_clnt_add_xprt(struct rpc_clnt *clnt,
2657 goto out_put_switch; 2659 goto out_put_switch;
2658 } 2660 }
2659 xprt->resvport = resvport; 2661 xprt->resvport = resvport;
2662 xprt->max_reconnect_timeout = reconnect_timeout;
2660 2663
2661 rpc_xprt_switch_set_roundrobin(xps); 2664 rpc_xprt_switch_set_roundrobin(xps);
2662 if (setup) { 2665 if (setup) {
@@ -2673,6 +2676,27 @@ out_put_switch:
2673} 2676}
2674EXPORT_SYMBOL_GPL(rpc_clnt_add_xprt); 2677EXPORT_SYMBOL_GPL(rpc_clnt_add_xprt);
2675 2678
2679static int
2680rpc_xprt_cap_max_reconnect_timeout(struct rpc_clnt *clnt,
2681 struct rpc_xprt *xprt,
2682 void *data)
2683{
2684 unsigned long timeout = *((unsigned long *)data);
2685
2686 if (timeout < xprt->max_reconnect_timeout)
2687 xprt->max_reconnect_timeout = timeout;
2688 return 0;
2689}
2690
2691void
2692rpc_cap_max_reconnect_timeout(struct rpc_clnt *clnt, unsigned long timeo)
2693{
2694 rpc_clnt_iterate_for_each_xprt(clnt,
2695 rpc_xprt_cap_max_reconnect_timeout,
2696 &timeo);
2697}
2698EXPORT_SYMBOL_GPL(rpc_cap_max_reconnect_timeout);
2699
2676#if IS_ENABLED(CONFIG_SUNRPC_DEBUG) 2700#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
2677static void rpc_show_header(void) 2701static void rpc_show_header(void)
2678{ 2702{
diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
index 8313960cac52..ea244b29138b 100644
--- a/net/sunrpc/xprt.c
+++ b/net/sunrpc/xprt.c
@@ -680,6 +680,20 @@ out:
680 spin_unlock_bh(&xprt->transport_lock); 680 spin_unlock_bh(&xprt->transport_lock);
681} 681}
682 682
683static bool
684xprt_has_timer(const struct rpc_xprt *xprt)
685{
686 return xprt->idle_timeout != 0;
687}
688
689static void
690xprt_schedule_autodisconnect(struct rpc_xprt *xprt)
691 __must_hold(&xprt->transport_lock)
692{
693 if (list_empty(&xprt->recv) && xprt_has_timer(xprt))
694 mod_timer(&xprt->timer, xprt->last_used + xprt->idle_timeout);
695}
696
683static void 697static void
684xprt_init_autodisconnect(unsigned long data) 698xprt_init_autodisconnect(unsigned long data)
685{ 699{
@@ -688,6 +702,8 @@ xprt_init_autodisconnect(unsigned long data)
688 spin_lock(&xprt->transport_lock); 702 spin_lock(&xprt->transport_lock);
689 if (!list_empty(&xprt->recv)) 703 if (!list_empty(&xprt->recv))
690 goto out_abort; 704 goto out_abort;
705 /* Reset xprt->last_used to avoid connect/autodisconnect cycling */
706 xprt->last_used = jiffies;
691 if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) 707 if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
692 goto out_abort; 708 goto out_abort;
693 spin_unlock(&xprt->transport_lock); 709 spin_unlock(&xprt->transport_lock);
@@ -725,6 +741,7 @@ void xprt_unlock_connect(struct rpc_xprt *xprt, void *cookie)
725 goto out; 741 goto out;
726 xprt->snd_task =NULL; 742 xprt->snd_task =NULL;
727 xprt->ops->release_xprt(xprt, NULL); 743 xprt->ops->release_xprt(xprt, NULL);
744 xprt_schedule_autodisconnect(xprt);
728out: 745out:
729 spin_unlock_bh(&xprt->transport_lock); 746 spin_unlock_bh(&xprt->transport_lock);
730 wake_up_bit(&xprt->state, XPRT_LOCKED); 747 wake_up_bit(&xprt->state, XPRT_LOCKED);
@@ -888,11 +905,6 @@ static void xprt_timer(struct rpc_task *task)
888 spin_unlock_bh(&xprt->transport_lock); 905 spin_unlock_bh(&xprt->transport_lock);
889} 906}
890 907
891static inline int xprt_has_timer(struct rpc_xprt *xprt)
892{
893 return xprt->idle_timeout != 0;
894}
895
896/** 908/**
897 * xprt_prepare_transmit - reserve the transport before sending a request 909 * xprt_prepare_transmit - reserve the transport before sending a request
898 * @task: RPC task about to send a request 910 * @task: RPC task about to send a request
@@ -1280,9 +1292,7 @@ void xprt_release(struct rpc_task *task)
1280 if (!list_empty(&req->rq_list)) 1292 if (!list_empty(&req->rq_list))
1281 list_del(&req->rq_list); 1293 list_del(&req->rq_list);
1282 xprt->last_used = jiffies; 1294 xprt->last_used = jiffies;
1283 if (list_empty(&xprt->recv) && xprt_has_timer(xprt)) 1295 xprt_schedule_autodisconnect(xprt);
1284 mod_timer(&xprt->timer,
1285 xprt->last_used + xprt->idle_timeout);
1286 spin_unlock_bh(&xprt->transport_lock); 1296 spin_unlock_bh(&xprt->transport_lock);
1287 if (req->rq_buffer) 1297 if (req->rq_buffer)
1288 xprt->ops->buf_free(req->rq_buffer); 1298 xprt->ops->buf_free(req->rq_buffer);
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 111767ab124a..8ede3bc52481 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -177,7 +177,6 @@ static struct ctl_table sunrpc_table[] = {
177 * increase over time if the server is down or not responding. 177 * increase over time if the server is down or not responding.
178 */ 178 */
179#define XS_TCP_INIT_REEST_TO (3U * HZ) 179#define XS_TCP_INIT_REEST_TO (3U * HZ)
180#define XS_TCP_MAX_REEST_TO (5U * 60 * HZ)
181 180
182/* 181/*
183 * TCP idle timeout; client drops the transport socket if it is idle 182 * TCP idle timeout; client drops the transport socket if it is idle
@@ -2173,6 +2172,8 @@ static void xs_udp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
2173 write_unlock_bh(&sk->sk_callback_lock); 2172 write_unlock_bh(&sk->sk_callback_lock);
2174 } 2173 }
2175 xs_udp_do_set_buffer_size(xprt); 2174 xs_udp_do_set_buffer_size(xprt);
2175
2176 xprt->stat.connect_start = jiffies;
2176} 2177}
2177 2178
2178static void xs_udp_setup_socket(struct work_struct *work) 2179static void xs_udp_setup_socket(struct work_struct *work)
@@ -2236,6 +2237,7 @@ static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
2236 unsigned int keepcnt = xprt->timeout->to_retries + 1; 2237 unsigned int keepcnt = xprt->timeout->to_retries + 1;
2237 unsigned int opt_on = 1; 2238 unsigned int opt_on = 1;
2238 unsigned int timeo; 2239 unsigned int timeo;
2240 unsigned int addr_pref = IPV6_PREFER_SRC_PUBLIC;
2239 2241
2240 /* TCP Keepalive options */ 2242 /* TCP Keepalive options */
2241 kernel_setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, 2243 kernel_setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
@@ -2247,6 +2249,16 @@ static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
2247 kernel_setsockopt(sock, SOL_TCP, TCP_KEEPCNT, 2249 kernel_setsockopt(sock, SOL_TCP, TCP_KEEPCNT,
2248 (char *)&keepcnt, sizeof(keepcnt)); 2250 (char *)&keepcnt, sizeof(keepcnt));
2249 2251
2252 /* Avoid temporary address, they are bad for long-lived
2253 * connections such as NFS mounts.
2254 * RFC4941, section 3.6 suggests that:
2255 * Individual applications, which have specific
2256 * knowledge about the normal duration of connections,
2257 * MAY override this as appropriate.
2258 */
2259 kernel_setsockopt(sock, SOL_IPV6, IPV6_ADDR_PREFERENCES,
2260 (char *)&addr_pref, sizeof(addr_pref));
2261
2250 /* TCP user timeout (see RFC5482) */ 2262 /* TCP user timeout (see RFC5482) */
2251 timeo = jiffies_to_msecs(xprt->timeout->to_initval) * 2263 timeo = jiffies_to_msecs(xprt->timeout->to_initval) *
2252 (xprt->timeout->to_retries + 1); 2264 (xprt->timeout->to_retries + 1);
@@ -2295,6 +2307,10 @@ static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
2295 /* SYN_SENT! */ 2307 /* SYN_SENT! */
2296 if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO) 2308 if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO)
2297 xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO; 2309 xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
2310 break;
2311 case -EADDRNOTAVAIL:
2312 /* Source port number is unavailable. Try a new one! */
2313 transport->srcport = 0;
2298 } 2314 }
2299out: 2315out:
2300 return ret; 2316 return ret;
@@ -2369,6 +2385,25 @@ out:
2369 xprt_wake_pending_tasks(xprt, status); 2385 xprt_wake_pending_tasks(xprt, status);
2370} 2386}
2371 2387
2388static unsigned long xs_reconnect_delay(const struct rpc_xprt *xprt)
2389{
2390 unsigned long start, now = jiffies;
2391
2392 start = xprt->stat.connect_start + xprt->reestablish_timeout;
2393 if (time_after(start, now))
2394 return start - now;
2395 return 0;
2396}
2397
2398static void xs_reconnect_backoff(struct rpc_xprt *xprt)
2399{
2400 xprt->reestablish_timeout <<= 1;
2401 if (xprt->reestablish_timeout > xprt->max_reconnect_timeout)
2402 xprt->reestablish_timeout = xprt->max_reconnect_timeout;
2403 if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO)
2404 xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
2405}
2406
2372/** 2407/**
2373 * xs_connect - connect a socket to a remote endpoint 2408 * xs_connect - connect a socket to a remote endpoint
2374 * @xprt: pointer to transport structure 2409 * @xprt: pointer to transport structure
@@ -2386,6 +2421,7 @@ out:
2386static void xs_connect(struct rpc_xprt *xprt, struct rpc_task *task) 2421static void xs_connect(struct rpc_xprt *xprt, struct rpc_task *task)
2387{ 2422{
2388 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); 2423 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2424 unsigned long delay = 0;
2389 2425
2390 WARN_ON_ONCE(!xprt_lock_connect(xprt, task, transport)); 2426 WARN_ON_ONCE(!xprt_lock_connect(xprt, task, transport));
2391 2427
@@ -2397,19 +2433,15 @@ static void xs_connect(struct rpc_xprt *xprt, struct rpc_task *task)
2397 /* Start by resetting any existing state */ 2433 /* Start by resetting any existing state */
2398 xs_reset_transport(transport); 2434 xs_reset_transport(transport);
2399 2435
2400 queue_delayed_work(xprtiod_workqueue, 2436 delay = xs_reconnect_delay(xprt);
2401 &transport->connect_worker, 2437 xs_reconnect_backoff(xprt);
2402 xprt->reestablish_timeout); 2438
2403 xprt->reestablish_timeout <<= 1; 2439 } else
2404 if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO)
2405 xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
2406 if (xprt->reestablish_timeout > XS_TCP_MAX_REEST_TO)
2407 xprt->reestablish_timeout = XS_TCP_MAX_REEST_TO;
2408 } else {
2409 dprintk("RPC: xs_connect scheduled xprt %p\n", xprt); 2440 dprintk("RPC: xs_connect scheduled xprt %p\n", xprt);
2410 queue_delayed_work(xprtiod_workqueue, 2441
2411 &transport->connect_worker, 0); 2442 queue_delayed_work(xprtiod_workqueue,
2412 } 2443 &transport->connect_worker,
2444 delay);
2413} 2445}
2414 2446
2415/** 2447/**
@@ -2961,6 +2993,8 @@ static struct rpc_xprt *xs_setup_tcp(struct xprt_create *args)
2961 xprt->ops = &xs_tcp_ops; 2993 xprt->ops = &xs_tcp_ops;
2962 xprt->timeout = &xs_tcp_default_timeout; 2994 xprt->timeout = &xs_tcp_default_timeout;
2963 2995
2996 xprt->max_reconnect_timeout = xprt->timeout->to_maxval;
2997
2964 INIT_WORK(&transport->recv_worker, xs_tcp_data_receive_workfn); 2998 INIT_WORK(&transport->recv_worker, xs_tcp_data_receive_workfn);
2965 INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_setup_socket); 2999 INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_setup_socket);
2966 3000
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 15b196fc2f49..179219845dfc 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -108,16 +108,20 @@ as-option = $(call try-run,\
108as-instr = $(call try-run,\ 108as-instr = $(call try-run,\
109 printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3)) 109 printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
110 110
111# Do not attempt to build with gcc plugins during cc-option tests.
112# (And this uses delayed resolution so the flags will be up to date.)
113CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
114
111# cc-option 115# cc-option
112# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) 116# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
113 117
114cc-option = $(call try-run,\ 118cc-option = $(call try-run,\
115 $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2)) 119 $(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
116 120
117# cc-option-yn 121# cc-option-yn
118# Usage: flag := $(call cc-option-yn,-march=winchip-c6) 122# Usage: flag := $(call cc-option-yn,-march=winchip-c6)
119cc-option-yn = $(call try-run,\ 123cc-option-yn = $(call try-run,\
120 $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n) 124 $(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
121 125
122# cc-option-align 126# cc-option-align
123# Prefix align with either -falign or -malign 127# Prefix align with either -falign or -malign
@@ -127,7 +131,7 @@ cc-option-align = $(subst -functions=0,,\
127# cc-disable-warning 131# cc-disable-warning
128# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable) 132# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable)
129cc-disable-warning = $(call try-run,\ 133cc-disable-warning = $(call try-run,\
130 $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) 134 $(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
131 135
132# cc-name 136# cc-name
133# Expands to either gcc or clang 137# Expands to either gcc or clang
diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
index 5e22b60589c1..61f0e6db909b 100644
--- a/scripts/Makefile.gcc-plugins
+++ b/scripts/Makefile.gcc-plugins
@@ -19,25 +19,42 @@ ifdef CONFIG_GCC_PLUGINS
19 endif 19 endif
20 endif 20 endif
21 21
22 GCC_PLUGINS_CFLAGS := $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) 22 GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y))
23 23
24 export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGIN SANCOV_PLUGIN 24 export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGIN GCC_PLUGIN_SUBDIR SANCOV_PLUGIN
25 25
26 ifneq ($(PLUGINCC),)
27 # SANCOV_PLUGIN can be only in CFLAGS_KCOV because avoid duplication.
28 GCC_PLUGINS_CFLAGS := $(filter-out $(SANCOV_PLUGIN), $(GCC_PLUGINS_CFLAGS))
29 endif
30
31 KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
32 GCC_PLUGIN := $(gcc-plugin-y)
33 GCC_PLUGIN_SUBDIR := $(gcc-plugin-subdir-y)
34endif
35
36# If plugins aren't supported, abort the build before hard-to-read compiler
37# errors start getting spewed by the main build.
38PHONY += gcc-plugins-check
39gcc-plugins-check: FORCE
40ifdef CONFIG_GCC_PLUGINS
26 ifeq ($(PLUGINCC),) 41 ifeq ($(PLUGINCC),)
27 ifneq ($(GCC_PLUGINS_CFLAGS),) 42 ifneq ($(GCC_PLUGINS_CFLAGS),)
28 ifeq ($(call cc-ifversion, -ge, 0405, y), y) 43 ifeq ($(call cc-ifversion, -ge, 0405, y), y)
29 PLUGINCC := $(shell $(CONFIG_SHELL) -x $(srctree)/scripts/gcc-plugin.sh "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)") 44 $(Q)$(srctree)/scripts/gcc-plugin.sh --show-error "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)" || true
30 $(warning warning: your gcc installation does not support plugins, perhaps the necessary headers are missing?) 45 @echo "Cannot use CONFIG_GCC_PLUGINS: your gcc installation does not support plugins, perhaps the necessary headers are missing?" >&2 && exit 1
31 else 46 else
32 $(warning warning: your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least) 47 @echo "Cannot use CONFIG_GCC_PLUGINS: your gcc version does not support plugins, you should upgrade it to at least gcc 4.5" >&2 && exit 1
33 endif 48 endif
34 endif 49 endif
35 else
36 # SANCOV_PLUGIN can be only in CFLAGS_KCOV because avoid duplication.
37 GCC_PLUGINS_CFLAGS := $(filter-out $(SANCOV_PLUGIN), $(GCC_PLUGINS_CFLAGS))
38 endif 50 endif
51endif
52 @:
39 53
40 KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) 54# Actually do the build, if requested.
41 GCC_PLUGIN := $(gcc-plugin-y) 55PHONY += gcc-plugins
42 56gcc-plugins: scripts_basic gcc-plugins-check
57ifdef CONFIG_GCC_PLUGINS
58 $(Q)$(MAKE) $(build)=scripts/gcc-plugins
43endif 59endif
60 @:
diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
index fb9207565471..b65224bfb847 100755
--- a/scripts/gcc-plugin.sh
+++ b/scripts/gcc-plugin.sh
@@ -1,5 +1,12 @@
1#!/bin/sh 1#!/bin/sh
2srctree=$(dirname "$0") 2srctree=$(dirname "$0")
3
4SHOW_ERROR=
5if [ "$1" = "--show-error" ] ; then
6 SHOW_ERROR=1
7 shift || true
8fi
9
3gccplugins_dir=$($3 -print-file-name=plugin) 10gccplugins_dir=$($3 -print-file-name=plugin)
4plugincc=$($1 -E -x c++ - -o /dev/null -I"${srctree}"/gcc-plugins -I"${gccplugins_dir}"/include 2>&1 <<EOF 11plugincc=$($1 -E -x c++ - -o /dev/null -I"${srctree}"/gcc-plugins -I"${gccplugins_dir}"/include 2>&1 <<EOF
5#include "gcc-common.h" 12#include "gcc-common.h"
@@ -13,6 +20,9 @@ EOF
13 20
14if [ $? -ne 0 ] 21if [ $? -ne 0 ]
15then 22then
23 if [ -n "$SHOW_ERROR" ] ; then
24 echo "${plugincc}" >&2
25 fi
16 exit 1 26 exit 1
17fi 27fi
18 28
@@ -48,4 +58,8 @@ then
48 echo "$2" 58 echo "$2"
49 exit 0 59 exit 0
50fi 60fi
61
62if [ -n "$SHOW_ERROR" ] ; then
63 echo "${plugincc}" >&2
64fi
51exit 1 65exit 1
diff --git a/scripts/gcc-plugins/Makefile b/scripts/gcc-plugins/Makefile
index 88c8ec47232b..8b29dc17c73c 100644
--- a/scripts/gcc-plugins/Makefile
+++ b/scripts/gcc-plugins/Makefile
@@ -12,16 +12,18 @@ else
12 export HOST_EXTRACXXFLAGS 12 export HOST_EXTRACXXFLAGS
13endif 13endif
14 14
15export GCCPLUGINS_DIR HOSTLIBS
16
17ifneq ($(CFLAGS_KCOV), $(SANCOV_PLUGIN)) 15ifneq ($(CFLAGS_KCOV), $(SANCOV_PLUGIN))
18 GCC_PLUGIN := $(filter-out $(SANCOV_PLUGIN), $(GCC_PLUGIN)) 16 GCC_PLUGIN := $(filter-out $(SANCOV_PLUGIN), $(GCC_PLUGIN))
19endif 17endif
20 18
21$(HOSTLIBS)-y := $(GCC_PLUGIN) 19export HOSTLIBS
20
21$(HOSTLIBS)-y := $(foreach p,$(GCC_PLUGIN),$(if $(findstring /,$(p)),,$(p)))
22always := $($(HOSTLIBS)-y) 22always := $($(HOSTLIBS)-y)
23 23
24cyc_complexity_plugin-objs := cyc_complexity_plugin.o 24$(foreach p,$($(HOSTLIBS)-y:%.so=%),$(eval $(p)-objs := $(p).o))
25sancov_plugin-objs := sancov_plugin.o 25
26subdir-y := $(GCC_PLUGIN_SUBDIR)
27subdir- += $(GCC_PLUGIN_SUBDIR)
26 28
27clean-files += *.so 29clean-files += *.so
diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index 122fcdaf42c8..49a00d54b835 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -432,7 +432,7 @@ foreach my $file (@ARGV) {
432 die "$P: file '${file}' not found\n"; 432 die "$P: file '${file}' not found\n";
433 } 433 }
434 } 434 }
435 if ($from_filename || vcs_file_exists($file)) { 435 if ($from_filename || ($file ne "&STDIN" && vcs_file_exists($file))) {
436 $file =~ s/^\Q${cur_path}\E//; #strip any absolute path 436 $file =~ s/^\Q${cur_path}\E//; #strip any absolute path
437 $file =~ s/^\Q${lk_path}\E//; #or the path to the lk tree 437 $file =~ s/^\Q${lk_path}\E//; #or the path to the lk tree
438 push(@files, $file); 438 push(@files, $file);
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 89dacf9b4e6c..160c7f713722 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -906,20 +906,23 @@ static int azx_resume(struct device *dev)
906 struct snd_card *card = dev_get_drvdata(dev); 906 struct snd_card *card = dev_get_drvdata(dev);
907 struct azx *chip; 907 struct azx *chip;
908 struct hda_intel *hda; 908 struct hda_intel *hda;
909 struct hdac_bus *bus;
909 910
910 if (!card) 911 if (!card)
911 return 0; 912 return 0;
912 913
913 chip = card->private_data; 914 chip = card->private_data;
914 hda = container_of(chip, struct hda_intel, chip); 915 hda = container_of(chip, struct hda_intel, chip);
916 bus = azx_bus(chip);
915 if (chip->disabled || hda->init_failed || !chip->running) 917 if (chip->disabled || hda->init_failed || !chip->running)
916 return 0; 918 return 0;
917 919
918 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL 920 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
919 && hda->need_i915_power) { 921 snd_hdac_display_power(bus, true);
920 snd_hdac_display_power(azx_bus(chip), true); 922 if (hda->need_i915_power)
921 snd_hdac_i915_set_bclk(azx_bus(chip)); 923 snd_hdac_i915_set_bclk(bus);
922 } 924 }
925
923 if (chip->msi) 926 if (chip->msi)
924 if (pci_enable_msi(pci) < 0) 927 if (pci_enable_msi(pci) < 0)
925 chip->msi = 0; 928 chip->msi = 0;
@@ -929,6 +932,11 @@ static int azx_resume(struct device *dev)
929 932
930 hda_intel_init_chip(chip, true); 933 hda_intel_init_chip(chip, true);
931 934
935 /* power down again for link-controlled chips */
936 if ((chip->driver_caps & AZX_DCAPS_I915_POWERWELL) &&
937 !hda->need_i915_power)
938 snd_hdac_display_power(bus, false);
939
932 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 940 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
933 941
934 trace_azx_resume(chip); 942 trace_azx_resume(chip);
@@ -1008,6 +1016,7 @@ static int azx_runtime_resume(struct device *dev)
1008 1016
1009 chip = card->private_data; 1017 chip = card->private_data;
1010 hda = container_of(chip, struct hda_intel, chip); 1018 hda = container_of(chip, struct hda_intel, chip);
1019 bus = azx_bus(chip);
1011 if (chip->disabled || hda->init_failed) 1020 if (chip->disabled || hda->init_failed)
1012 return 0; 1021 return 0;
1013 1022
@@ -1015,15 +1024,9 @@ static int azx_runtime_resume(struct device *dev)
1015 return 0; 1024 return 0;
1016 1025
1017 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { 1026 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
1018 bus = azx_bus(chip); 1027 snd_hdac_display_power(bus, true);
1019 if (hda->need_i915_power) { 1028 if (hda->need_i915_power)
1020 snd_hdac_display_power(bus, true);
1021 snd_hdac_i915_set_bclk(bus); 1029 snd_hdac_i915_set_bclk(bus);
1022 } else {
1023 /* toggle codec wakeup bit for STATESTS read */
1024 snd_hdac_set_codec_wakeup(bus, true);
1025 snd_hdac_set_codec_wakeup(bus, false);
1026 }
1027 } 1030 }
1028 1031
1029 /* Read STATESTS before controller reset */ 1032 /* Read STATESTS before controller reset */
@@ -1043,6 +1046,11 @@ static int azx_runtime_resume(struct device *dev)
1043 azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) & 1046 azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) &
1044 ~STATESTS_INT_MASK); 1047 ~STATESTS_INT_MASK);
1045 1048
1049 /* power down again for link-controlled chips */
1050 if ((chip->driver_caps & AZX_DCAPS_I915_POWERWELL) &&
1051 !hda->need_i915_power)
1052 snd_hdac_display_power(bus, false);
1053
1046 trace_azx_runtime_resume(chip); 1054 trace_azx_runtime_resume(chip);
1047 return 0; 1055 return 0;
1048} 1056}
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 6adde457b602..6cf1f3597455 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -1128,6 +1128,7 @@ bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip)
1128{ 1128{
1129 /* devices which do not support reading the sample rate. */ 1129 /* devices which do not support reading the sample rate. */
1130 switch (chip->usb_id) { 1130 switch (chip->usb_id) {
1131 case USB_ID(0x041E, 0x4080): /* Creative Live Cam VF0610 */
1131 case USB_ID(0x045E, 0x075D): /* MS Lifecam Cinema */ 1132 case USB_ID(0x045E, 0x075D): /* MS Lifecam Cinema */
1132 case USB_ID(0x045E, 0x076D): /* MS Lifecam HD-5000 */ 1133 case USB_ID(0x045E, 0x076D): /* MS Lifecam HD-5000 */
1133 case USB_ID(0x045E, 0x076E): /* MS Lifecam HD-5001 */ 1134 case USB_ID(0x045E, 0x076E): /* MS Lifecam HD-5001 */
@@ -1138,6 +1139,7 @@ bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip)
1138 case USB_ID(0x047F, 0xAA05): /* Plantronics DA45 */ 1139 case USB_ID(0x047F, 0xAA05): /* Plantronics DA45 */
1139 case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */ 1140 case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */
1140 case USB_ID(0x0556, 0x0014): /* Phoenix Audio TMX320VC */ 1141 case USB_ID(0x0556, 0x0014): /* Phoenix Audio TMX320VC */
1142 case USB_ID(0x05A3, 0x9420): /* ELP HD USB Camera */
1141 case USB_ID(0x074D, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */ 1143 case USB_ID(0x074D, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */
1142 case USB_ID(0x1de7, 0x0013): /* Phoenix Audio MT202exe */ 1144 case USB_ID(0x1de7, 0x0013): /* Phoenix Audio MT202exe */
1143 case USB_ID(0x1de7, 0x0014): /* Phoenix Audio TMX320 */ 1145 case USB_ID(0x1de7, 0x0014): /* Phoenix Audio TMX320 */
diff --git a/tools/arch/x86/include/asm/cpufeatures.h b/tools/arch/x86/include/asm/cpufeatures.h
index 4a413485f9eb..92a8308b96f6 100644
--- a/tools/arch/x86/include/asm/cpufeatures.h
+++ b/tools/arch/x86/include/asm/cpufeatures.h
@@ -225,7 +225,6 @@
225#define X86_FEATURE_RDSEED ( 9*32+18) /* The RDSEED instruction */ 225#define X86_FEATURE_RDSEED ( 9*32+18) /* The RDSEED instruction */
226#define X86_FEATURE_ADX ( 9*32+19) /* The ADCX and ADOX instructions */ 226#define X86_FEATURE_ADX ( 9*32+19) /* The ADCX and ADOX instructions */
227#define X86_FEATURE_SMAP ( 9*32+20) /* Supervisor Mode Access Prevention */ 227#define X86_FEATURE_SMAP ( 9*32+20) /* Supervisor Mode Access Prevention */
228#define X86_FEATURE_PCOMMIT ( 9*32+22) /* PCOMMIT instruction */
229#define X86_FEATURE_CLFLUSHOPT ( 9*32+23) /* CLFLUSHOPT instruction */ 228#define X86_FEATURE_CLFLUSHOPT ( 9*32+23) /* CLFLUSHOPT instruction */
230#define X86_FEATURE_CLWB ( 9*32+24) /* CLWB instruction */ 229#define X86_FEATURE_CLWB ( 9*32+24) /* CLWB instruction */
231#define X86_FEATURE_AVX512PF ( 9*32+26) /* AVX-512 Prefetch */ 230#define X86_FEATURE_AVX512PF ( 9*32+26) /* AVX-512 Prefetch */
@@ -301,10 +300,6 @@
301#define X86_BUG_FXSAVE_LEAK X86_BUG(6) /* FXSAVE leaks FOP/FIP/FOP */ 300#define X86_BUG_FXSAVE_LEAK X86_BUG(6) /* FXSAVE leaks FOP/FIP/FOP */
302#define X86_BUG_CLFLUSH_MONITOR X86_BUG(7) /* AAI65, CLFLUSH required before MONITOR */ 301#define X86_BUG_CLFLUSH_MONITOR X86_BUG(7) /* AAI65, CLFLUSH required before MONITOR */
303#define X86_BUG_SYSRET_SS_ATTRS X86_BUG(8) /* SYSRET doesn't fix up SS attrs */ 302#define X86_BUG_SYSRET_SS_ATTRS X86_BUG(8) /* SYSRET doesn't fix up SS attrs */
304#define X86_BUG_NULL_SEG X86_BUG(9) /* Nulling a selector preserves the base */
305#define X86_BUG_SWAPGS_FENCE X86_BUG(10) /* SWAPGS without input dep on GS */
306
307
308#ifdef CONFIG_X86_32 303#ifdef CONFIG_X86_32
309/* 304/*
310 * 64-bit kernels don't use X86_BUG_ESPFIX. Make the define conditional 305 * 64-bit kernels don't use X86_BUG_ESPFIX. Make the define conditional
@@ -312,5 +307,7 @@
312 */ 307 */
313#define X86_BUG_ESPFIX X86_BUG(9) /* "" IRET to 16-bit SS corrupts ESP/RSP high bits */ 308#define X86_BUG_ESPFIX X86_BUG(9) /* "" IRET to 16-bit SS corrupts ESP/RSP high bits */
314#endif 309#endif
315 310#define X86_BUG_NULL_SEG X86_BUG(10) /* Nulling a selector preserves the base */
311#define X86_BUG_SWAPGS_FENCE X86_BUG(11) /* SWAPGS without input dep on GS */
312#define X86_BUG_MONITOR X86_BUG(12) /* IPI required to wake up remote CPU */
316#endif /* _ASM_X86_CPUFEATURES_H */ 313#endif /* _ASM_X86_CPUFEATURES_H */
diff --git a/tools/arch/x86/include/asm/disabled-features.h b/tools/arch/x86/include/asm/disabled-features.h
index 911e9358ceb1..85599ad4d024 100644
--- a/tools/arch/x86/include/asm/disabled-features.h
+++ b/tools/arch/x86/include/asm/disabled-features.h
@@ -56,5 +56,7 @@
56#define DISABLED_MASK14 0 56#define DISABLED_MASK14 0
57#define DISABLED_MASK15 0 57#define DISABLED_MASK15 0
58#define DISABLED_MASK16 (DISABLE_PKU|DISABLE_OSPKE) 58#define DISABLED_MASK16 (DISABLE_PKU|DISABLE_OSPKE)
59#define DISABLED_MASK17 0
60#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 18)
59 61
60#endif /* _ASM_X86_DISABLED_FEATURES_H */ 62#endif /* _ASM_X86_DISABLED_FEATURES_H */
diff --git a/tools/arch/x86/include/asm/required-features.h b/tools/arch/x86/include/asm/required-features.h
index 4916144e3c42..fac9a5c0abe9 100644
--- a/tools/arch/x86/include/asm/required-features.h
+++ b/tools/arch/x86/include/asm/required-features.h
@@ -99,5 +99,7 @@
99#define REQUIRED_MASK14 0 99#define REQUIRED_MASK14 0
100#define REQUIRED_MASK15 0 100#define REQUIRED_MASK15 0
101#define REQUIRED_MASK16 0 101#define REQUIRED_MASK16 0
102#define REQUIRED_MASK17 0
103#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 18)
102 104
103#endif /* _ASM_X86_REQUIRED_FEATURES_H */ 105#endif /* _ASM_X86_REQUIRED_FEATURES_H */
diff --git a/tools/arch/x86/include/uapi/asm/vmx.h b/tools/arch/x86/include/uapi/asm/vmx.h
index 5b15d94a33f8..37fee272618f 100644
--- a/tools/arch/x86/include/uapi/asm/vmx.h
+++ b/tools/arch/x86/include/uapi/asm/vmx.h
@@ -78,7 +78,6 @@
78#define EXIT_REASON_PML_FULL 62 78#define EXIT_REASON_PML_FULL 62
79#define EXIT_REASON_XSAVES 63 79#define EXIT_REASON_XSAVES 63
80#define EXIT_REASON_XRSTORS 64 80#define EXIT_REASON_XRSTORS 64
81#define EXIT_REASON_PCOMMIT 65
82 81
83#define VMX_EXIT_REASONS \ 82#define VMX_EXIT_REASONS \
84 { EXIT_REASON_EXCEPTION_NMI, "EXCEPTION_NMI" }, \ 83 { EXIT_REASON_EXCEPTION_NMI, "EXCEPTION_NMI" }, \
@@ -127,8 +126,7 @@
127 { EXIT_REASON_INVVPID, "INVVPID" }, \ 126 { EXIT_REASON_INVVPID, "INVVPID" }, \
128 { EXIT_REASON_INVPCID, "INVPCID" }, \ 127 { EXIT_REASON_INVPCID, "INVPCID" }, \
129 { EXIT_REASON_XSAVES, "XSAVES" }, \ 128 { EXIT_REASON_XSAVES, "XSAVES" }, \
130 { EXIT_REASON_XRSTORS, "XRSTORS" }, \ 129 { EXIT_REASON_XRSTORS, "XRSTORS" }
131 { EXIT_REASON_PCOMMIT, "PCOMMIT" }
132 130
133#define VMX_ABORT_SAVE_GUEST_MSR_FAIL 1 131#define VMX_ABORT_SAVE_GUEST_MSR_FAIL 1
134#define VMX_ABORT_LOAD_HOST_MSR_FAIL 4 132#define VMX_ABORT_LOAD_HOST_MSR_FAIL 4
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 406459b935a2..da218fec6056 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -84,6 +84,7 @@ enum bpf_map_type {
84 BPF_MAP_TYPE_PERCPU_HASH, 84 BPF_MAP_TYPE_PERCPU_HASH,
85 BPF_MAP_TYPE_PERCPU_ARRAY, 85 BPF_MAP_TYPE_PERCPU_ARRAY,
86 BPF_MAP_TYPE_STACK_TRACE, 86 BPF_MAP_TYPE_STACK_TRACE,
87 BPF_MAP_TYPE_CGROUP_ARRAY,
87}; 88};
88 89
89enum bpf_prog_type { 90enum bpf_prog_type {
@@ -93,6 +94,7 @@ enum bpf_prog_type {
93 BPF_PROG_TYPE_SCHED_CLS, 94 BPF_PROG_TYPE_SCHED_CLS,
94 BPF_PROG_TYPE_SCHED_ACT, 95 BPF_PROG_TYPE_SCHED_ACT,
95 BPF_PROG_TYPE_TRACEPOINT, 96 BPF_PROG_TYPE_TRACEPOINT,
97 BPF_PROG_TYPE_XDP,
96}; 98};
97 99
98#define BPF_PSEUDO_MAP_FD 1 100#define BPF_PSEUDO_MAP_FD 1
@@ -313,6 +315,66 @@ enum bpf_func_id {
313 */ 315 */
314 BPF_FUNC_skb_get_tunnel_opt, 316 BPF_FUNC_skb_get_tunnel_opt,
315 BPF_FUNC_skb_set_tunnel_opt, 317 BPF_FUNC_skb_set_tunnel_opt,
318
319 /**
320 * bpf_skb_change_proto(skb, proto, flags)
321 * Change protocol of the skb. Currently supported is
322 * v4 -> v6, v6 -> v4 transitions. The helper will also
323 * resize the skb. eBPF program is expected to fill the
324 * new headers via skb_store_bytes and lX_csum_replace.
325 * @skb: pointer to skb
326 * @proto: new skb->protocol type
327 * @flags: reserved
328 * Return: 0 on success or negative error
329 */
330 BPF_FUNC_skb_change_proto,
331
332 /**
333 * bpf_skb_change_type(skb, type)
334 * Change packet type of skb.
335 * @skb: pointer to skb
336 * @type: new skb->pkt_type type
337 * Return: 0 on success or negative error
338 */
339 BPF_FUNC_skb_change_type,
340
341 /**
342 * bpf_skb_in_cgroup(skb, map, index) - Check cgroup2 membership of skb
343 * @skb: pointer to skb
344 * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
345 * @index: index of the cgroup in the bpf_map
346 * Return:
347 * == 0 skb failed the cgroup2 descendant test
348 * == 1 skb succeeded the cgroup2 descendant test
349 * < 0 error
350 */
351 BPF_FUNC_skb_in_cgroup,
352
353 /**
354 * bpf_get_hash_recalc(skb)
355 * Retrieve and possibly recalculate skb->hash.
356 * @skb: pointer to skb
357 * Return: hash
358 */
359 BPF_FUNC_get_hash_recalc,
360
361 /**
362 * u64 bpf_get_current_task(void)
363 * Returns current task_struct
364 * Return: current
365 */
366 BPF_FUNC_get_current_task,
367
368 /**
369 * bpf_probe_write_user(void *dst, void *src, int len)
370 * safely attempt to write to a location
371 * @dst: destination address in userspace
372 * @src: source address on stack
373 * @len: number of bytes to copy
374 * Return: 0 on success or negative error
375 */
376 BPF_FUNC_probe_write_user,
377
316 __BPF_FUNC_MAX_ID, 378 __BPF_FUNC_MAX_ID,
317}; 379};
318 380
@@ -347,9 +409,11 @@ enum bpf_func_id {
347#define BPF_F_ZERO_CSUM_TX (1ULL << 1) 409#define BPF_F_ZERO_CSUM_TX (1ULL << 1)
348#define BPF_F_DONT_FRAGMENT (1ULL << 2) 410#define BPF_F_DONT_FRAGMENT (1ULL << 2)
349 411
350/* BPF_FUNC_perf_event_output flags. */ 412/* BPF_FUNC_perf_event_output and BPF_FUNC_perf_event_read flags. */
351#define BPF_F_INDEX_MASK 0xffffffffULL 413#define BPF_F_INDEX_MASK 0xffffffffULL
352#define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK 414#define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK
415/* BPF_FUNC_perf_event_output for sk_buff input context. */
416#define BPF_F_CTXLEN_MASK (0xfffffULL << 32)
353 417
354/* user accessible mirror of in-kernel sk_buff. 418/* user accessible mirror of in-kernel sk_buff.
355 * new fields can only be added to the end of this structure 419 * new fields can only be added to the end of this structure
@@ -386,4 +450,24 @@ struct bpf_tunnel_key {
386 __u32 tunnel_label; 450 __u32 tunnel_label;
387}; 451};
388 452
453/* User return codes for XDP prog type.
454 * A valid XDP program must return one of these defined values. All other
455 * return codes are reserved for future use. Unknown return codes will result
456 * in packet drop.
457 */
458enum xdp_action {
459 XDP_ABORTED = 0,
460 XDP_DROP,
461 XDP_PASS,
462 XDP_TX,
463};
464
465/* user accessible metadata for XDP packet hook
466 * new fields must be added to the end of this structure
467 */
468struct xdp_md {
469 __u32 data;
470 __u32 data_end;
471};
472
389#endif /* _UAPI__LINUX_BPF_H__ */ 473#endif /* _UAPI__LINUX_BPF_H__ */
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index 736da44596e4..b303bcdd8ed1 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -176,10 +176,18 @@ Each probe argument follows below syntax.
176 176
177'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.) 177'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.)
178'$vars' and '$params' special arguments are also available for NAME, '$vars' is expanded to the local variables (including function parameters) which can access at given probe point. '$params' is expanded to only the function parameters. 178'$vars' and '$params' special arguments are also available for NAME, '$vars' is expanded to the local variables (including function parameters) which can access at given probe point. '$params' is expanded to only the function parameters.
179'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type. 179'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail)
180 180
181On x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid. 181On x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid.
182 182
183TYPES
184-----
185Basic types (u8/u16/u32/u64/s8/s16/s32/s64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively. Traced arguments are shown in decimal (signed) or hex (unsigned). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe.
186String type is a special type, which fetches a "null-terminated" string from kernel space. This means it will fail and store NULL if the string container has been paged out. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type.
187Bitfield is another special type, which takes 3 parameters, bit-width, bit-offset, and container-size (usually 32). The syntax is;
188
189 b<bit-width>@<bit-offset>/<container-size>
190
183LINE SYNTAX 191LINE SYNTAX
184----------- 192-----------
185Line range is described by following syntax. 193Line range is described by following syntax.
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 1f6c70594f0f..053bbbd84ece 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -116,8 +116,8 @@ OPTIONS
116--fields:: 116--fields::
117 Comma separated list of fields to print. Options are: 117 Comma separated list of fields to print. Options are:
118 comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, 118 comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
119 srcline, period, iregs, brstack, brstacksym, flags. 119 srcline, period, iregs, brstack, brstacksym, flags, bpf-output,
120 Field list can be prepended with the type, trace, sw or hw, 120 callindent. Field list can be prepended with the type, trace, sw or hw,
121 to indicate to which event type the field list applies. 121 to indicate to which event type the field list applies.
122 e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace 122 e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace
123 123
diff --git a/tools/perf/arch/powerpc/util/sym-handling.c b/tools/perf/arch/powerpc/util/sym-handling.c
index c6d0f91731a1..8d4dc97d80ba 100644
--- a/tools/perf/arch/powerpc/util/sym-handling.c
+++ b/tools/perf/arch/powerpc/util/sym-handling.c
@@ -54,10 +54,6 @@ int arch__compare_symbol_names(const char *namea, const char *nameb)
54#endif 54#endif
55 55
56#if defined(_CALL_ELF) && _CALL_ELF == 2 56#if defined(_CALL_ELF) && _CALL_ELF == 2
57bool arch__prefers_symtab(void)
58{
59 return true;
60}
61 57
62#ifdef HAVE_LIBELF_SUPPORT 58#ifdef HAVE_LIBELF_SUPPORT
63void arch__sym_update(struct symbol *s, GElf_Sym *sym) 59void arch__sym_update(struct symbol *s, GElf_Sym *sym)
@@ -100,4 +96,27 @@ void arch__fix_tev_from_maps(struct perf_probe_event *pev,
100 tev->point.offset += lep_offset; 96 tev->point.offset += lep_offset;
101 } 97 }
102} 98}
99
100void arch__post_process_probe_trace_events(struct perf_probe_event *pev,
101 int ntevs)
102{
103 struct probe_trace_event *tev;
104 struct map *map;
105 struct symbol *sym = NULL;
106 struct rb_node *tmp;
107 int i = 0;
108
109 map = get_target_map(pev->target, pev->uprobes);
110 if (!map || map__load(map, NULL) < 0)
111 return;
112
113 for (i = 0; i < ntevs; i++) {
114 tev = &pev->tevs[i];
115 map__for_each_symbol(map, sym, tmp) {
116 if (map->unmap_ip(map, sym->start) == tev->point.address)
117 arch__fix_tev_from_maps(pev, tev, map, sym);
118 }
119 }
120}
121
103#endif 122#endif
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 971ff91b16cb..9c640a8081c7 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2116,7 +2116,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
2116 "Valid types: hw,sw,trace,raw. " 2116 "Valid types: hw,sw,trace,raw. "
2117 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," 2117 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
2118 "addr,symoff,period,iregs,brstack,brstacksym,flags," 2118 "addr,symoff,period,iregs,brstack,brstacksym,flags,"
2119 "callindent", parse_output_fields), 2119 "bpf-output,callindent", parse_output_fields),
2120 OPT_BOOLEAN('a', "all-cpus", &system_wide, 2120 OPT_BOOLEAN('a', "all-cpus", &system_wide,
2121 "system-wide collection from all CPUs"), 2121 "system-wide collection from all CPUs"),
2122 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]", 2122 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 0c16d20d7e32..3c7452b39f57 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -331,7 +331,7 @@ static int read_counter(struct perf_evsel *counter)
331 return 0; 331 return 0;
332} 332}
333 333
334static void read_counters(bool close_counters) 334static void read_counters(void)
335{ 335{
336 struct perf_evsel *counter; 336 struct perf_evsel *counter;
337 337
@@ -341,11 +341,6 @@ static void read_counters(bool close_counters)
341 341
342 if (perf_stat_process_counter(&stat_config, counter)) 342 if (perf_stat_process_counter(&stat_config, counter))
343 pr_warning("failed to process counter %s\n", counter->name); 343 pr_warning("failed to process counter %s\n", counter->name);
344
345 if (close_counters) {
346 perf_evsel__close_fd(counter, perf_evsel__nr_cpus(counter),
347 thread_map__nr(evsel_list->threads));
348 }
349 } 344 }
350} 345}
351 346
@@ -353,7 +348,7 @@ static void process_interval(void)
353{ 348{
354 struct timespec ts, rs; 349 struct timespec ts, rs;
355 350
356 read_counters(false); 351 read_counters();
357 352
358 clock_gettime(CLOCK_MONOTONIC, &ts); 353 clock_gettime(CLOCK_MONOTONIC, &ts);
359 diff_timespec(&rs, &ts, &ref_time); 354 diff_timespec(&rs, &ts, &ref_time);
@@ -380,6 +375,17 @@ static void enable_counters(void)
380 perf_evlist__enable(evsel_list); 375 perf_evlist__enable(evsel_list);
381} 376}
382 377
378static void disable_counters(void)
379{
380 /*
381 * If we don't have tracee (attaching to task or cpu), counters may
382 * still be running. To get accurate group ratios, we must stop groups
383 * from counting before reading their constituent counters.
384 */
385 if (!target__none(&target))
386 perf_evlist__disable(evsel_list);
387}
388
383static volatile int workload_exec_errno; 389static volatile int workload_exec_errno;
384 390
385/* 391/*
@@ -657,11 +663,20 @@ try_again:
657 } 663 }
658 } 664 }
659 665
666 disable_counters();
667
660 t1 = rdclock(); 668 t1 = rdclock();
661 669
662 update_stats(&walltime_nsecs_stats, t1 - t0); 670 update_stats(&walltime_nsecs_stats, t1 - t0);
663 671
664 read_counters(true); 672 /*
673 * Closing a group leader splits the group, and as we only disable
674 * group leaders, results in remaining events becoming enabled. To
675 * avoid arbitrary skew, we must read all counters before closing any
676 * group leaders.
677 */
678 read_counters();
679 perf_evlist__close(evsel_list);
665 680
666 return WEXITSTATUS(status); 681 return WEXITSTATUS(status);
667} 682}
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 953dc1ab2ed7..28733962cd80 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -170,15 +170,17 @@ static struct map *kernel_get_module_map(const char *module)
170 module = "kernel"; 170 module = "kernel";
171 171
172 for (pos = maps__first(maps); pos; pos = map__next(pos)) { 172 for (pos = maps__first(maps); pos; pos = map__next(pos)) {
173 /* short_name is "[module]" */
173 if (strncmp(pos->dso->short_name + 1, module, 174 if (strncmp(pos->dso->short_name + 1, module,
174 pos->dso->short_name_len - 2) == 0) { 175 pos->dso->short_name_len - 2) == 0 &&
176 module[pos->dso->short_name_len - 2] == '\0') {
175 return pos; 177 return pos;
176 } 178 }
177 } 179 }
178 return NULL; 180 return NULL;
179} 181}
180 182
181static struct map *get_target_map(const char *target, bool user) 183struct map *get_target_map(const char *target, bool user)
182{ 184{
183 /* Init maps of given executable or kernel */ 185 /* Init maps of given executable or kernel */
184 if (user) 186 if (user)
@@ -385,7 +387,7 @@ static int find_alternative_probe_point(struct debuginfo *dinfo,
385 if (uprobes) 387 if (uprobes)
386 address = sym->start; 388 address = sym->start;
387 else 389 else
388 address = map->unmap_ip(map, sym->start); 390 address = map->unmap_ip(map, sym->start) - map->reloc;
389 break; 391 break;
390 } 392 }
391 if (!address) { 393 if (!address) {
@@ -664,22 +666,14 @@ static int add_module_to_probe_trace_events(struct probe_trace_event *tevs,
664 return ret; 666 return ret;
665} 667}
666 668
667/* Post processing the probe events */ 669static int
668static int post_process_probe_trace_events(struct probe_trace_event *tevs, 670post_process_kernel_probe_trace_events(struct probe_trace_event *tevs,
669 int ntevs, const char *module, 671 int ntevs)
670 bool uprobe)
671{ 672{
672 struct ref_reloc_sym *reloc_sym; 673 struct ref_reloc_sym *reloc_sym;
673 char *tmp; 674 char *tmp;
674 int i, skipped = 0; 675 int i, skipped = 0;
675 676
676 if (uprobe)
677 return add_exec_to_probe_trace_events(tevs, ntevs, module);
678
679 /* Note that currently ref_reloc_sym based probe is not for drivers */
680 if (module)
681 return add_module_to_probe_trace_events(tevs, ntevs, module);
682
683 reloc_sym = kernel_get_ref_reloc_sym(); 677 reloc_sym = kernel_get_ref_reloc_sym();
684 if (!reloc_sym) { 678 if (!reloc_sym) {
685 pr_warning("Relocated base symbol is not found!\n"); 679 pr_warning("Relocated base symbol is not found!\n");
@@ -711,6 +705,34 @@ static int post_process_probe_trace_events(struct probe_trace_event *tevs,
711 return skipped; 705 return skipped;
712} 706}
713 707
708void __weak
709arch__post_process_probe_trace_events(struct perf_probe_event *pev __maybe_unused,
710 int ntevs __maybe_unused)
711{
712}
713
714/* Post processing the probe events */
715static int post_process_probe_trace_events(struct perf_probe_event *pev,
716 struct probe_trace_event *tevs,
717 int ntevs, const char *module,
718 bool uprobe)
719{
720 int ret;
721
722 if (uprobe)
723 ret = add_exec_to_probe_trace_events(tevs, ntevs, module);
724 else if (module)
725 /* Currently ref_reloc_sym based probe is not for drivers */
726 ret = add_module_to_probe_trace_events(tevs, ntevs, module);
727 else
728 ret = post_process_kernel_probe_trace_events(tevs, ntevs);
729
730 if (ret >= 0)
731 arch__post_process_probe_trace_events(pev, ntevs);
732
733 return ret;
734}
735
714/* Try to find perf_probe_event with debuginfo */ 736/* Try to find perf_probe_event with debuginfo */
715static int try_to_find_probe_trace_events(struct perf_probe_event *pev, 737static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
716 struct probe_trace_event **tevs) 738 struct probe_trace_event **tevs)
@@ -749,7 +771,7 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
749 771
750 if (ntevs > 0) { /* Succeeded to find trace events */ 772 if (ntevs > 0) { /* Succeeded to find trace events */
751 pr_debug("Found %d probe_trace_events.\n", ntevs); 773 pr_debug("Found %d probe_trace_events.\n", ntevs);
752 ret = post_process_probe_trace_events(*tevs, ntevs, 774 ret = post_process_probe_trace_events(pev, *tevs, ntevs,
753 pev->target, pev->uprobes); 775 pev->target, pev->uprobes);
754 if (ret < 0 || ret == ntevs) { 776 if (ret < 0 || ret == ntevs) {
755 clear_probe_trace_events(*tevs, ntevs); 777 clear_probe_trace_events(*tevs, ntevs);
@@ -2936,8 +2958,6 @@ errout:
2936 return err; 2958 return err;
2937} 2959}
2938 2960
2939bool __weak arch__prefers_symtab(void) { return false; }
2940
2941/* Concatinate two arrays */ 2961/* Concatinate two arrays */
2942static void *memcat(void *a, size_t sz_a, void *b, size_t sz_b) 2962static void *memcat(void *a, size_t sz_a, void *b, size_t sz_b)
2943{ 2963{
@@ -3158,12 +3178,6 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev,
3158 if (ret > 0 || pev->sdt) /* SDT can be found only in the cache */ 3178 if (ret > 0 || pev->sdt) /* SDT can be found only in the cache */
3159 return ret == 0 ? -ENOENT : ret; /* Found in probe cache */ 3179 return ret == 0 ? -ENOENT : ret; /* Found in probe cache */
3160 3180
3161 if (arch__prefers_symtab() && !perf_probe_event_need_dwarf(pev)) {
3162 ret = find_probe_trace_events_from_map(pev, tevs);
3163 if (ret > 0)
3164 return ret; /* Found in symbol table */
3165 }
3166
3167 /* Convert perf_probe_event with debuginfo */ 3181 /* Convert perf_probe_event with debuginfo */
3168 ret = try_to_find_probe_trace_events(pev, tevs); 3182 ret = try_to_find_probe_trace_events(pev, tevs);
3169 if (ret != 0) 3183 if (ret != 0)
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index e18ea9fe6385..f4f45db77c1c 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -158,7 +158,6 @@ int show_line_range(struct line_range *lr, const char *module, bool user);
158int show_available_vars(struct perf_probe_event *pevs, int npevs, 158int show_available_vars(struct perf_probe_event *pevs, int npevs,
159 struct strfilter *filter); 159 struct strfilter *filter);
160int show_available_funcs(const char *module, struct strfilter *filter, bool user); 160int show_available_funcs(const char *module, struct strfilter *filter, bool user);
161bool arch__prefers_symtab(void);
162void arch__fix_tev_from_maps(struct perf_probe_event *pev, 161void arch__fix_tev_from_maps(struct perf_probe_event *pev,
163 struct probe_trace_event *tev, struct map *map, 162 struct probe_trace_event *tev, struct map *map,
164 struct symbol *sym); 163 struct symbol *sym);
@@ -173,4 +172,9 @@ int e_snprintf(char *str, size_t size, const char *format, ...)
173int copy_to_probe_trace_arg(struct probe_trace_arg *tvar, 172int copy_to_probe_trace_arg(struct probe_trace_arg *tvar,
174 struct perf_probe_arg *pvar); 173 struct perf_probe_arg *pvar);
175 174
175struct map *get_target_map(const char *target, bool user);
176
177void arch__post_process_probe_trace_events(struct perf_probe_event *pev,
178 int ntevs);
179
176#endif /*_PROBE_EVENT_H */ 180#endif /*_PROBE_EVENT_H */
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index f2d9ff064e2d..5c290c682afe 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -297,10 +297,13 @@ static int convert_variable_type(Dwarf_Die *vr_die,
297 char sbuf[STRERR_BUFSIZE]; 297 char sbuf[STRERR_BUFSIZE];
298 int bsize, boffs, total; 298 int bsize, boffs, total;
299 int ret; 299 int ret;
300 char sign;
300 301
301 /* TODO: check all types */ 302 /* TODO: check all types */
302 if (cast && strcmp(cast, "string") != 0) { 303 if (cast && strcmp(cast, "string") != 0 &&
304 strcmp(cast, "s") != 0 && strcmp(cast, "u") != 0) {
303 /* Non string type is OK */ 305 /* Non string type is OK */
306 /* and respect signedness cast */
304 tvar->type = strdup(cast); 307 tvar->type = strdup(cast);
305 return (tvar->type == NULL) ? -ENOMEM : 0; 308 return (tvar->type == NULL) ? -ENOMEM : 0;
306 } 309 }
@@ -361,6 +364,13 @@ static int convert_variable_type(Dwarf_Die *vr_die,
361 return (tvar->type == NULL) ? -ENOMEM : 0; 364 return (tvar->type == NULL) ? -ENOMEM : 0;
362 } 365 }
363 366
367 if (cast && (strcmp(cast, "u") == 0))
368 sign = 'u';
369 else if (cast && (strcmp(cast, "s") == 0))
370 sign = 's';
371 else
372 sign = die_is_signed_type(&type) ? 's' : 'u';
373
364 ret = dwarf_bytesize(&type); 374 ret = dwarf_bytesize(&type);
365 if (ret <= 0) 375 if (ret <= 0)
366 /* No size ... try to use default type */ 376 /* No size ... try to use default type */
@@ -373,8 +383,7 @@ static int convert_variable_type(Dwarf_Die *vr_die,
373 dwarf_diename(&type), MAX_BASIC_TYPE_BITS); 383 dwarf_diename(&type), MAX_BASIC_TYPE_BITS);
374 ret = MAX_BASIC_TYPE_BITS; 384 ret = MAX_BASIC_TYPE_BITS;
375 } 385 }
376 ret = snprintf(buf, 16, "%c%d", 386 ret = snprintf(buf, 16, "%c%d", sign, ret);
377 die_is_signed_type(&type) ? 's' : 'u', ret);
378 387
379formatted: 388formatted:
380 if (ret < 0 || ret >= 16) { 389 if (ret < 0 || ret >= 16) {
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 947d21f38398..3d3cb8392c86 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -588,7 +588,11 @@ static char *get_trace_output(struct hist_entry *he)
588 } else { 588 } else {
589 pevent_event_info(&seq, evsel->tp_format, &rec); 589 pevent_event_info(&seq, evsel->tp_format, &rec);
590 } 590 }
591 return seq.buffer; 591 /*
592 * Trim the buffer, it starts at 4KB and we're not going to
593 * add anything more to this buffer.
594 */
595 return realloc(seq.buffer, seq.len + 1);
592} 596}
593 597
594static int64_t 598static int64_t
diff --git a/tools/testing/nvdimm/test/nfit.c b/tools/testing/nvdimm/test/nfit.c
index 5404efa578a3..dd48f421844c 100644
--- a/tools/testing/nvdimm/test/nfit.c
+++ b/tools/testing/nvdimm/test/nfit.c
@@ -13,6 +13,7 @@
13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/dma-mapping.h> 15#include <linux/dma-mapping.h>
16#include <linux/workqueue.h>
16#include <linux/libnvdimm.h> 17#include <linux/libnvdimm.h>
17#include <linux/vmalloc.h> 18#include <linux/vmalloc.h>
18#include <linux/device.h> 19#include <linux/device.h>
@@ -1474,6 +1475,7 @@ static int nfit_test_probe(struct platform_device *pdev)
1474 if (nfit_test->setup != nfit_test0_setup) 1475 if (nfit_test->setup != nfit_test0_setup)
1475 return 0; 1476 return 0;
1476 1477
1478 flush_work(&acpi_desc->work);
1477 nfit_test->setup_hotplug = 1; 1479 nfit_test->setup_hotplug = 1;
1478 nfit_test->setup(nfit_test); 1480 nfit_test->setup(nfit_test);
1479 1481
diff --git a/tools/testing/selftests/powerpc/Makefile b/tools/testing/selftests/powerpc/Makefile
index 3c40c9d0e6c7..1cc6d64c39b7 100644
--- a/tools/testing/selftests/powerpc/Makefile
+++ b/tools/testing/selftests/powerpc/Makefile
@@ -8,7 +8,7 @@ ifeq ($(ARCH),powerpc)
8 8
9GIT_VERSION = $(shell git describe --always --long --dirty || echo "unknown") 9GIT_VERSION = $(shell git describe --always --long --dirty || echo "unknown")
10 10
11CFLAGS := -Wall -O2 -Wall -Werror -DGIT_VERSION='"$(GIT_VERSION)"' -I$(CURDIR) $(CFLAGS) 11CFLAGS := -std=gnu99 -Wall -O2 -Wall -Werror -DGIT_VERSION='"$(GIT_VERSION)"' -I$(CURDIR) $(CFLAGS)
12 12
13export CFLAGS 13export CFLAGS
14 14
diff --git a/virt/kvm/arm/vgic/vgic-init.c b/virt/kvm/arm/vgic/vgic-init.c
index fb4b0a79a950..83777c1cbae0 100644
--- a/virt/kvm/arm/vgic/vgic-init.c
+++ b/virt/kvm/arm/vgic/vgic-init.c
@@ -73,12 +73,8 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
73 int i, vcpu_lock_idx = -1, ret; 73 int i, vcpu_lock_idx = -1, ret;
74 struct kvm_vcpu *vcpu; 74 struct kvm_vcpu *vcpu;
75 75
76 mutex_lock(&kvm->lock); 76 if (irqchip_in_kernel(kvm))
77 77 return -EEXIST;
78 if (irqchip_in_kernel(kvm)) {
79 ret = -EEXIST;
80 goto out;
81 }
82 78
83 /* 79 /*
84 * This function is also called by the KVM_CREATE_IRQCHIP handler, 80 * This function is also called by the KVM_CREATE_IRQCHIP handler,
@@ -87,10 +83,8 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
87 * the proper checks already. 83 * the proper checks already.
88 */ 84 */
89 if (type == KVM_DEV_TYPE_ARM_VGIC_V2 && 85 if (type == KVM_DEV_TYPE_ARM_VGIC_V2 &&
90 !kvm_vgic_global_state.can_emulate_gicv2) { 86 !kvm_vgic_global_state.can_emulate_gicv2)
91 ret = -ENODEV; 87 return -ENODEV;
92 goto out;
93 }
94 88
95 /* 89 /*
96 * Any time a vcpu is run, vcpu_load is called which tries to grab the 90 * Any time a vcpu is run, vcpu_load is called which tries to grab the
@@ -138,9 +132,6 @@ out_unlock:
138 vcpu = kvm_get_vcpu(kvm, vcpu_lock_idx); 132 vcpu = kvm_get_vcpu(kvm, vcpu_lock_idx);
139 mutex_unlock(&vcpu->mutex); 133 mutex_unlock(&vcpu->mutex);
140 } 134 }
141
142out:
143 mutex_unlock(&kvm->lock);
144 return ret; 135 return ret;
145} 136}
146 137
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index cc081ccfcaa3..195078225aa5 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -696,6 +696,11 @@ static void kvm_destroy_devices(struct kvm *kvm)
696{ 696{
697 struct kvm_device *dev, *tmp; 697 struct kvm_device *dev, *tmp;
698 698
699 /*
700 * We do not need to take the kvm->lock here, because nobody else
701 * has a reference to the struct kvm at this point and therefore
702 * cannot access the devices list anyhow.
703 */
699 list_for_each_entry_safe(dev, tmp, &kvm->devices, vm_node) { 704 list_for_each_entry_safe(dev, tmp, &kvm->devices, vm_node) {
700 list_del(&dev->vm_node); 705 list_del(&dev->vm_node);
701 dev->ops->destroy(dev); 706 dev->ops->destroy(dev);
@@ -2832,19 +2837,28 @@ static int kvm_ioctl_create_device(struct kvm *kvm,
2832 dev->ops = ops; 2837 dev->ops = ops;
2833 dev->kvm = kvm; 2838 dev->kvm = kvm;
2834 2839
2840 mutex_lock(&kvm->lock);
2835 ret = ops->create(dev, cd->type); 2841 ret = ops->create(dev, cd->type);
2836 if (ret < 0) { 2842 if (ret < 0) {
2843 mutex_unlock(&kvm->lock);
2837 kfree(dev); 2844 kfree(dev);
2838 return ret; 2845 return ret;
2839 } 2846 }
2847 list_add(&dev->vm_node, &kvm->devices);
2848 mutex_unlock(&kvm->lock);
2849
2850 if (ops->init)
2851 ops->init(dev);
2840 2852
2841 ret = anon_inode_getfd(ops->name, &kvm_device_fops, dev, O_RDWR | O_CLOEXEC); 2853 ret = anon_inode_getfd(ops->name, &kvm_device_fops, dev, O_RDWR | O_CLOEXEC);
2842 if (ret < 0) { 2854 if (ret < 0) {
2843 ops->destroy(dev); 2855 ops->destroy(dev);
2856 mutex_lock(&kvm->lock);
2857 list_del(&dev->vm_node);
2858 mutex_unlock(&kvm->lock);
2844 return ret; 2859 return ret;
2845 } 2860 }
2846 2861
2847 list_add(&dev->vm_node, &kvm->devices);
2848 kvm_get_kvm(kvm); 2862 kvm_get_kvm(kvm);
2849 cd->fd = ret; 2863 cd->fd = ret;
2850 return 0; 2864 return 0;