aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ. Bruce Fields <bfields@redhat.com>2015-02-02 11:29:29 -0500
committerJ. Bruce Fields <bfields@redhat.com>2015-02-02 11:29:29 -0500
commita584143b01ce69803116ae8d0a4db382acc728d7 (patch)
tree002733709647fa1e17683a9d21dbc23ae99e3d2d
parent4c94e13e9caed09103419c087f436d79f9d2faba (diff)
parent8116bf4cb62d337c953cfa5369ef4cf83e73140c (diff)
Merge branch 'locks-3.20' of git://git.samba.org/jlayton/linux into for-3.20
Christoph's block pnfs patches have some minor dependencies on these lock patches.
-rw-r--r--.mailmap1
-rw-r--r--Documentation/networking/ip-sysctl.txt2
-rwxr-xr-xDocumentation/target/tcm_mod_builder.py49
-rw-r--r--Documentation/thermal/cpu-cooling-api.txt15
-rw-r--r--MAINTAINERS27
-rw-r--r--Makefile3
-rw-r--r--arch/arm/boot/dts/imx6sx-sdb.dts15
-rw-r--r--arch/arm/boot/dts/vf610-twr.dts15
-rw-r--r--arch/arm/include/uapi/asm/unistd.h1
-rw-r--r--arch/arm/kernel/calls.S1
-rw-r--r--arch/arm/kernel/perf_regs.c8
-rw-r--r--arch/arm/mm/dump.c9
-rw-r--r--arch/arm/mm/init.c4
-rw-r--r--arch/arm/mm/mmu.c4
-rw-r--r--arch/arm64/include/asm/arch_timer.h1
-rw-r--r--arch/arm64/include/asm/cpu.h5
-rw-r--r--arch/arm64/include/asm/kvm_emulate.h2
-rw-r--r--arch/arm64/include/asm/processor.h4
-rw-r--r--arch/arm64/include/asm/unistd.h2
-rw-r--r--arch/arm64/kernel/cpuinfo.c10
-rw-r--r--arch/arm64/kernel/efi.c2
-rw-r--r--arch/arm64/kernel/module.c1
-rw-r--r--arch/arm64/kernel/perf_regs.c8
-rw-r--r--arch/arm64/kernel/setup.c1
-rw-r--r--arch/arm64/kernel/smp_spin_table.c1
-rw-r--r--arch/arm64/kvm/hyp.S1
-rw-r--r--arch/arm64/kvm/reset.c1
-rw-r--r--arch/blackfin/mach-bf533/boards/stamp.c1
-rw-r--r--arch/ia64/kernel/acpi.c9
-rw-r--r--arch/m68k/include/asm/unistd.h2
-rw-r--r--arch/m68k/include/uapi/asm/unistd.h1
-rw-r--r--arch/m68k/kernel/syscalltable.S1
-rw-r--r--arch/powerpc/include/asm/thread_info.h13
-rw-r--r--arch/powerpc/platforms/powernv/opal-wrappers.S1
-rw-r--r--arch/s390/hypfs/hypfs_vm.c2
-rw-r--r--arch/s390/include/asm/irqflags.h2
-rw-r--r--arch/s390/include/asm/timex.h10
-rw-r--r--arch/s390/include/uapi/asm/unistd.h3
-rw-r--r--arch/s390/kernel/syscalls.S1
-rw-r--r--arch/s390/kernel/uprobes.c69
-rw-r--r--arch/s390/kernel/vtime.c2
-rw-r--r--arch/s390/mm/pgtable.c5
-rw-r--r--arch/s390/net/bpf_jit_comp.c8
-rw-r--r--arch/x86/boot/Makefile1
-rw-r--r--arch/x86/crypto/Makefile2
-rw-r--r--arch/x86/crypto/aes_ctrby8_avx-x86_64.S46
-rw-r--r--arch/x86/include/asm/vgtod.h6
-rw-r--r--arch/x86/kernel/acpi/boot.c9
-rw-r--r--arch/x86/kernel/cpu/Makefile1
-rw-r--r--arch/x86/kernel/cpu/mkcapflags.sh2
-rw-r--r--arch/x86/kernel/cpu/perf_event_intel_uncore.h2
-rw-r--r--arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c17
-rw-r--r--arch/x86/kernel/perf_regs.c90
-rw-r--r--arch/x86/lib/insn.c2
-rw-r--r--arch/x86/mm/init.c37
-rw-r--r--arch/x86/vdso/vma.c45
-rw-r--r--arch/x86/xen/enlighten.c22
-rw-r--r--arch/x86/xen/p2m.c20
-rw-r--r--arch/x86/xen/setup.c42
-rw-r--r--arch/x86/xen/time.c18
-rw-r--r--block/blk-core.c21
-rw-r--r--block/blk-mq-tag.c14
-rw-r--r--block/blk-mq-tag.h1
-rw-r--r--block/blk-mq.c75
-rw-r--r--block/blk-mq.h1
-rw-r--r--block/blk-timeout.c3
-rw-r--r--drivers/Makefile6
-rw-r--r--drivers/acpi/acpi_processor.c25
-rw-r--r--drivers/acpi/device_pm.c2
-rw-r--r--drivers/acpi/int340x_thermal.c11
-rw-r--r--drivers/acpi/processor_core.c56
-rw-r--r--drivers/acpi/scan.c13
-rw-r--r--drivers/acpi/video.c10
-rw-r--r--drivers/block/null_blk.c2
-rw-r--r--drivers/block/nvme-core.c175
-rw-r--r--drivers/block/virtio_blk.c2
-rw-r--r--drivers/char/ipmi/ipmi_ssif.c3
-rw-r--r--drivers/gpio/gpio-dln2.c156
-rw-r--r--drivers/gpio/gpio-grgpio.c3
-rw-r--r--drivers/gpu/drm/Makefile2
-rw-r--r--drivers/gpu/drm/amd/amdkfd/kfd_chardev.c316
-rw-r--r--drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c28
-rw-r--r--drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c2
-rw-r--r--drivers/gpu/drm/amd/amdkfd/kfd_pasid.c2
-rw-r--r--drivers/gpu/drm/amd/amdkfd/kfd_priv.h18
-rw-r--r--drivers/gpu/drm/amd/amdkfd/kfd_topology.c2
-rw-r--r--drivers/gpu/drm/amd/include/kgd_kfd_interface.h2
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h2
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c8
-rw-r--r--drivers/gpu/drm/i915/i915_irq.c6
-rw-r--r--drivers/gpu/drm/i915/intel_display.c8
-rw-r--r--drivers/gpu/drm/i915/intel_runtime_pm.c27
-rw-r--r--drivers/gpu/drm/nouveau/core/core/event.c4
-rw-r--r--drivers/gpu/drm/nouveau/core/core/notify.c2
-rw-r--r--drivers/gpu/drm/nouveau/core/engine/device/nve0.c33
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/bios/shadowramin.c6
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/fb/ramnvaa.c65
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/mc/nv4c.c8
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bo.c4
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_gem.c35
-rw-r--r--drivers/gpu/drm/radeon/atombios_crtc.c8
-rw-r--r--drivers/gpu/drm/radeon/atombios_dp.c4
-rw-r--r--drivers/gpu/drm/radeon/cikd.h2
-rw-r--r--drivers/gpu/drm/radeon/dce3_1_afmt.c2
-rw-r--r--drivers/gpu/drm/radeon/kv_dpm.c10
-rw-r--r--drivers/gpu/drm/radeon/radeon_kfd.c23
-rw-r--r--drivers/gpu/drm/radeon/radeon_state.c2
-rw-r--r--drivers/hid/Kconfig3
-rw-r--r--drivers/hid/hid-core.c1
-rw-r--r--drivers/hid/hid-ids.h1
-rw-r--r--drivers/hid/hid-input.c3
-rw-r--r--drivers/hid/hid-kye.c4
-rw-r--r--drivers/hid/hid-logitech-dj.c16
-rw-r--r--drivers/hid/hid-logitech-hidpp.c41
-rw-r--r--drivers/hid/hid-roccat-pyra.c8
-rw-r--r--drivers/hid/i2c-hid/i2c-hid.c5
-rw-r--r--drivers/hid/usbhid/hid-quirks.c1
-rw-r--r--drivers/iommu/intel-iommu.c12
-rw-r--r--drivers/iommu/ipmmu-vmsa.c6
-rw-r--r--drivers/iommu/rockchip-iommu.c1
-rw-r--r--drivers/isdn/hardware/eicon/message.c2
-rw-r--r--drivers/leds/leds-netxbig.c12
-rw-r--r--drivers/misc/cxl/context.c82
-rw-r--r--drivers/misc/cxl/file.c14
-rw-r--r--drivers/mmc/host/sdhci-acpi.c2
-rw-r--r--drivers/mmc/host/sdhci-pci.c25
-rw-r--r--drivers/mmc/host/sdhci-pci.h3
-rw-r--r--drivers/mmc/host/sdhci-pxav3.c15
-rw-r--r--drivers/mmc/host/sdhci.c80
-rw-r--r--drivers/net/ethernet/allwinner/sun4i-emac.c4
-rw-r--r--drivers/net/ethernet/altera/altera_tse_main.c15
-rw-r--r--drivers/net/ethernet/atheros/alx/main.c24
-rw-r--r--drivers/net/ethernet/broadcom/tg3.c23
-rw-r--r--drivers/net/ethernet/cadence/at91_ether.c10
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c2
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4vf/t4vf_hw.c2
-rw-r--r--drivers/net/ethernet/cisco/enic/enic_main.c6
-rw-r--r--drivers/net/ethernet/dnet.c18
-rw-r--r--drivers/net/ethernet/freescale/fec.h2
-rw-r--r--drivers/net/ethernet/freescale/fec_main.c10
-rw-r--r--drivers/net/ethernet/intel/Kconfig11
-rw-r--r--drivers/net/ethernet/intel/e100.c2
-rw-r--r--drivers/net/ethernet/intel/i40e/Makefile2
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_debugfs.c4
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_osdep.h4
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_txrx.c104
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_txrx.h1
-rw-r--r--drivers/net/ethernet/intel/igb/e1000_82575.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/main.c13
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/mr.c9
-rw-r--r--drivers/net/ethernet/myricom/myri10ge/myri10ge.c4
-rw-r--r--drivers/net/ethernet/qlogic/qla3xxx.c8
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c1
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.c9
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.h5
-rw-r--r--drivers/net/ethernet/ti/cpsw.c30
-rw-r--r--drivers/net/ethernet/ti/cpsw_ale.c10
-rw-r--r--drivers/net/ethernet/ti/cpsw_ale.h2
-rw-r--r--drivers/net/ethernet/xilinx/ll_temac_main.c2
-rw-r--r--drivers/net/ethernet/xilinx/xilinx_axienet_main.c2
-rw-r--r--drivers/net/ethernet/xilinx/xilinx_emaclite.c1
-rw-r--r--drivers/net/team/team.c16
-rw-r--r--drivers/net/usb/kaweth.c2
-rw-r--r--drivers/net/usb/qmi_wwan.c10
-rw-r--r--drivers/net/usb/r8152.c17
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-7000.c6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-8000.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-fw-file.h4
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/fw-api-scan.h2
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/scan.c19
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/tx.c8
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/utils.c2
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/drv.c4
-rw-r--r--drivers/net/wireless/rtlwifi/pci.c32
-rw-r--r--drivers/net/xen-netback/xenbus.c1
-rw-r--r--drivers/net/xen-netfront.c71
-rw-r--r--drivers/pinctrl/pinctrl-rockchip.c57
-rw-r--r--drivers/pinctrl/pinctrl-st.c5
-rw-r--r--drivers/s390/crypto/ap_bus.c10
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c4
-rw-r--r--drivers/target/iscsi/iscsi_target.c12
-rw-r--r--drivers/target/iscsi/iscsi_target_core.h4
-rw-r--r--drivers/target/target_core_device.c54
-rw-r--r--drivers/target/target_core_file.c12
-rw-r--r--drivers/target/target_core_iblock.c3
-rw-r--r--drivers/target/target_core_pr.c12
-rw-r--r--drivers/target/target_core_rd.c1
-rw-r--r--drivers/target/target_core_sbc.c15
-rw-r--r--drivers/target/target_core_spc.c5
-rw-r--r--drivers/target/target_core_user.c1
-rw-r--r--drivers/thermal/imx_thermal.c2
-rw-r--r--drivers/thermal/int340x_thermal/acpi_thermal_rel.c16
-rw-r--r--drivers/thermal/int340x_thermal/processor_thermal_device.c2
-rw-r--r--drivers/thermal/of-thermal.c2
-rw-r--r--drivers/thermal/rcar_thermal.c17
-rw-r--r--drivers/thermal/thermal_core.h4
-rw-r--r--drivers/vfio/pci/vfio_pci.c4
-rw-r--r--drivers/vhost/net.c2
-rw-r--r--drivers/vhost/scsi.c24
-rw-r--r--drivers/video/fbdev/broadsheetfb.c8
-rw-r--r--drivers/video/fbdev/simplefb.c2
-rw-r--r--drivers/virtio/virtio_pci_common.c10
-rw-r--r--drivers/virtio/virtio_pci_common.h1
-rw-r--r--drivers/virtio/virtio_pci_legacy.c12
-rw-r--r--fs/btrfs/backref.c13
-rw-r--r--fs/btrfs/delayed-inode.c8
-rw-r--r--fs/btrfs/extent-tree.c12
-rw-r--r--fs/btrfs/inode.c4
-rw-r--r--fs/btrfs/scrub.c2
-rw-r--r--fs/ceph/addr.c2
-rw-r--r--fs/ceph/locks.c64
-rw-r--r--fs/ceph/mds_client.c4
-rw-r--r--fs/cifs/file.c34
-rw-r--r--fs/ext4/extents.c4
-rw-r--r--fs/ext4/file.c220
-rw-r--r--fs/ext4/resize.c24
-rw-r--r--fs/ext4/super.c2
-rw-r--r--fs/fcntl.c5
-rw-r--r--fs/fuse/dev.c51
-rw-r--r--fs/fuse/dir.c31
-rw-r--r--fs/fuse/fuse_i.h2
-rw-r--r--fs/fuse/inode.c5
-rw-r--r--fs/inode.c3
-rw-r--r--fs/lockd/svcsubs.c26
-rw-r--r--fs/locks.c569
-rw-r--r--fs/nfs/delegation.c23
-rw-r--r--fs/nfs/nfs4state.c70
-rw-r--r--fs/nfs/pagelist.c6
-rw-r--r--fs/nfs/write.c41
-rw-r--r--fs/nfsd/nfs4state.c21
-rw-r--r--fs/notify/fanotify/fanotify_user.c10
-rw-r--r--fs/ocfs2/dlm/dlmrecovery.c5
-rw-r--r--fs/ocfs2/namei.c43
-rw-r--r--fs/read_write.c2
-rw-r--r--include/acpi/processor.h8
-rw-r--r--include/asm-generic/tlb.h8
-rw-r--r--include/linux/acpi.h4
-rw-r--r--include/linux/blk-mq.h8
-rw-r--r--include/linux/blk_types.h2
-rw-r--r--include/linux/ceph/osd_client.h4
-rw-r--r--include/linux/compiler.h12
-rw-r--r--include/linux/fs.h54
-rw-r--r--include/linux/kdb.h62
-rw-r--r--include/linux/mm.h2
-rw-r--r--include/linux/mmc/sdhci.h1
-rw-r--r--include/linux/netdevice.h6
-rw-r--r--include/linux/perf_event.h12
-rw-r--r--include/linux/perf_regs.h16
-rw-r--r--include/linux/rmap.h10
-rw-r--r--include/linux/writeback.h1
-rw-r--r--include/net/mac80211.h7
-rw-r--r--include/target/target_core_backend.h1
-rw-r--r--include/target/target_core_backend_configfs.h2
-rw-r--r--include/target/target_core_base.h3
-rw-r--r--include/uapi/asm-generic/fcntl.h2
-rw-r--r--include/uapi/linux/kfd_ioctl.h37
-rw-r--r--include/uapi/linux/openvswitch.h4
-rw-r--r--include/xen/interface/nmi.h51
-rw-r--r--kernel/debug/debug_core.c52
-rw-r--r--kernel/debug/kdb/kdb_bp.c37
-rw-r--r--kernel/debug/kdb/kdb_debugger.c4
-rw-r--r--kernel/debug/kdb/kdb_main.c267
-rw-r--r--kernel/debug/kdb/kdb_private.h3
-rw-r--r--kernel/events/core.c19
-rw-r--r--kernel/exit.c12
-rw-r--r--kernel/locking/mutex-debug.c2
-rw-r--r--kernel/sched/core.c13
-rw-r--r--kernel/sched/deadline.c25
-rw-r--r--kernel/sched/fair.c6
-rw-r--r--kernel/trace/trace_kdb.c4
-rw-r--r--lib/Kconfig.kgdb25
-rw-r--r--lib/assoc_array.c1
-rw-r--r--mm/Kconfig.debug9
-rw-r--r--mm/memcontrol.c17
-rw-r--r--mm/memory.c39
-rw-r--r--mm/mmap.c13
-rw-r--r--mm/page-writeback.c43
-rw-r--r--mm/rmap.c42
-rw-r--r--mm/vmscan.c24
-rw-r--r--net/batman-adv/multicast.c11
-rw-r--r--net/batman-adv/network-coding.c2
-rw-r--r--net/batman-adv/originator.c7
-rw-r--r--net/batman-adv/routing.c6
-rw-r--r--net/bridge/br_input.c3
-rw-r--r--net/ceph/auth_x.c2
-rw-r--r--net/ceph/mon_client.c2
-rw-r--r--net/core/neighbour.c44
-rw-r--r--net/ipv4/netfilter/nft_redir_ipv4.c8
-rw-r--r--net/ipv4/tcp_output.c4
-rw-r--r--net/ipv6/netfilter/nft_redir_ipv6.c8
-rw-r--r--net/mac80211/key.c12
-rw-r--r--net/netfilter/ipvs/ip_vs_ftp.c10
-rw-r--r--net/netfilter/nf_conntrack_core.c20
-rw-r--r--net/netfilter/nf_tables_api.c14
-rw-r--r--net/netfilter/nfnetlink.c5
-rw-r--r--net/netfilter/nft_nat.c8
-rw-r--r--net/openvswitch/datapath.c3
-rw-r--r--net/openvswitch/flow.c5
-rw-r--r--net/openvswitch/vport.c2
-rw-r--r--net/packet/af_packet.c2
-rw-r--r--net/tipc/bcast.c5
-rw-r--r--scripts/Makefile.clean16
-rw-r--r--security/keys/gc.c4
-rw-r--r--sound/firewire/fireworks/fireworks_transaction.c2
-rw-r--r--sound/pci/hda/patch_hdmi.c2
-rw-r--r--sound/pci/hda/patch_sigmatel.c4
-rw-r--r--sound/usb/caiaq/audio.c2
-rw-r--r--tools/lib/lockdep/preload.c4
-rw-r--r--tools/perf/builtin-annotate.c2
-rw-r--r--tools/perf/builtin-diff.c46
-rw-r--r--tools/perf/builtin-list.c13
-rw-r--r--tools/perf/builtin-report.c24
-rw-r--r--tools/perf/builtin-top.c4
-rw-r--r--tools/perf/tests/hists_cumulate.c66
-rw-r--r--tools/perf/tests/hists_filter.c2
-rw-r--r--tools/perf/tests/hists_output.c10
-rw-r--r--tools/perf/ui/browsers/hists.c2
-rw-r--r--tools/perf/ui/hist.c3
-rw-r--r--tools/perf/ui/tui/setup.c26
-rw-r--r--tools/perf/util/callchain.c30
-rw-r--r--tools/perf/util/callchain.h2
-rw-r--r--tools/perf/util/hist.c18
-rw-r--r--tools/perf/util/hist.h2
-rw-r--r--tools/perf/util/probe-event.c6
-rw-r--r--tools/perf/util/probe-finder.c18
-rw-r--r--tools/testing/selftests/exec/execveat.c19
-rw-r--r--tools/testing/selftests/mqueue/mq_perf_tests.c3
-rw-r--r--tools/testing/selftests/vm/Makefile2
328 files changed, 3749 insertions, 2117 deletions
diff --git a/.mailmap b/.mailmap
index ada8ad696b2e..d357e1bd2a43 100644
--- a/.mailmap
+++ b/.mailmap
@@ -51,6 +51,7 @@ Greg Kroah-Hartman <gregkh@suse.de>
51Greg Kroah-Hartman <greg@kroah.com> 51Greg Kroah-Hartman <greg@kroah.com>
52Henk Vergonet <Henk.Vergonet@gmail.com> 52Henk Vergonet <Henk.Vergonet@gmail.com>
53Henrik Kretzschmar <henne@nachtwindheim.de> 53Henrik Kretzschmar <henne@nachtwindheim.de>
54Henrik Rydberg <rydberg@bitmath.org>
54Herbert Xu <herbert@gondor.apana.org.au> 55Herbert Xu <herbert@gondor.apana.org.au>
55Jacob Shin <Jacob.Shin@amd.com> 56Jacob Shin <Jacob.Shin@amd.com>
56James Bottomley <jejb@mulgrave.(none)> 57James Bottomley <jejb@mulgrave.(none)>
diff --git a/Documentation/networking/ip-sysctl.txt b/Documentation/networking/ip-sysctl.txt
index 9bffdfc648dc..85b022179104 100644
--- a/Documentation/networking/ip-sysctl.txt
+++ b/Documentation/networking/ip-sysctl.txt
@@ -66,6 +66,8 @@ fwmark_reflect - BOOLEAN
66route/max_size - INTEGER 66route/max_size - INTEGER
67 Maximum number of routes allowed in the kernel. Increase 67 Maximum number of routes allowed in the kernel. Increase
68 this when using large numbers of interfaces and/or routes. 68 this when using large numbers of interfaces and/or routes.
69 From linux kernel 3.6 onwards, this is deprecated for ipv4
70 as route cache is no longer used.
69 71
70neigh/default/gc_thresh1 - INTEGER 72neigh/default/gc_thresh1 - INTEGER
71 Minimum number of entries to keep. Garbage collector will not 73 Minimum number of entries to keep. Garbage collector will not
diff --git a/Documentation/target/tcm_mod_builder.py b/Documentation/target/tcm_mod_builder.py
index 230ce71f4d75..2b47704f75cb 100755
--- a/Documentation/target/tcm_mod_builder.py
+++ b/Documentation/target/tcm_mod_builder.py
@@ -389,9 +389,6 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
389 buf += " .release_cmd = " + fabric_mod_name + "_release_cmd,\n" 389 buf += " .release_cmd = " + fabric_mod_name + "_release_cmd,\n"
390 buf += " .shutdown_session = " + fabric_mod_name + "_shutdown_session,\n" 390 buf += " .shutdown_session = " + fabric_mod_name + "_shutdown_session,\n"
391 buf += " .close_session = " + fabric_mod_name + "_close_session,\n" 391 buf += " .close_session = " + fabric_mod_name + "_close_session,\n"
392 buf += " .stop_session = " + fabric_mod_name + "_stop_session,\n"
393 buf += " .fall_back_to_erl0 = " + fabric_mod_name + "_reset_nexus,\n"
394 buf += " .sess_logged_in = " + fabric_mod_name + "_sess_logged_in,\n"
395 buf += " .sess_get_index = " + fabric_mod_name + "_sess_get_index,\n" 392 buf += " .sess_get_index = " + fabric_mod_name + "_sess_get_index,\n"
396 buf += " .sess_get_initiator_sid = NULL,\n" 393 buf += " .sess_get_initiator_sid = NULL,\n"
397 buf += " .write_pending = " + fabric_mod_name + "_write_pending,\n" 394 buf += " .write_pending = " + fabric_mod_name + "_write_pending,\n"
@@ -402,7 +399,7 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
402 buf += " .queue_data_in = " + fabric_mod_name + "_queue_data_in,\n" 399 buf += " .queue_data_in = " + fabric_mod_name + "_queue_data_in,\n"
403 buf += " .queue_status = " + fabric_mod_name + "_queue_status,\n" 400 buf += " .queue_status = " + fabric_mod_name + "_queue_status,\n"
404 buf += " .queue_tm_rsp = " + fabric_mod_name + "_queue_tm_rsp,\n" 401 buf += " .queue_tm_rsp = " + fabric_mod_name + "_queue_tm_rsp,\n"
405 buf += " .is_state_remove = " + fabric_mod_name + "_is_state_remove,\n" 402 buf += " .aborted_task = " + fabric_mod_name + "_aborted_task,\n"
406 buf += " /*\n" 403 buf += " /*\n"
407 buf += " * Setup function pointers for generic logic in target_core_fabric_configfs.c\n" 404 buf += " * Setup function pointers for generic logic in target_core_fabric_configfs.c\n"
408 buf += " */\n" 405 buf += " */\n"
@@ -428,7 +425,7 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
428 buf += " /*\n" 425 buf += " /*\n"
429 buf += " * Register the top level struct config_item_type with TCM core\n" 426 buf += " * Register the top level struct config_item_type with TCM core\n"
430 buf += " */\n" 427 buf += " */\n"
431 buf += " fabric = target_fabric_configfs_init(THIS_MODULE, \"" + fabric_mod_name[4:] + "\");\n" 428 buf += " fabric = target_fabric_configfs_init(THIS_MODULE, \"" + fabric_mod_name + "\");\n"
432 buf += " if (IS_ERR(fabric)) {\n" 429 buf += " if (IS_ERR(fabric)) {\n"
433 buf += " printk(KERN_ERR \"target_fabric_configfs_init() failed\\n\");\n" 430 buf += " printk(KERN_ERR \"target_fabric_configfs_init() failed\\n\");\n"
434 buf += " return PTR_ERR(fabric);\n" 431 buf += " return PTR_ERR(fabric);\n"
@@ -595,7 +592,7 @@ def tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir_var, fabric_mod_name):
595 if re.search('get_fabric_name', fo): 592 if re.search('get_fabric_name', fo):
596 buf += "char *" + fabric_mod_name + "_get_fabric_name(void)\n" 593 buf += "char *" + fabric_mod_name + "_get_fabric_name(void)\n"
597 buf += "{\n" 594 buf += "{\n"
598 buf += " return \"" + fabric_mod_name[4:] + "\";\n" 595 buf += " return \"" + fabric_mod_name + "\";\n"
599 buf += "}\n\n" 596 buf += "}\n\n"
600 bufi += "char *" + fabric_mod_name + "_get_fabric_name(void);\n" 597 bufi += "char *" + fabric_mod_name + "_get_fabric_name(void);\n"
601 continue 598 continue
@@ -820,27 +817,6 @@ def tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir_var, fabric_mod_name):
820 buf += "}\n\n" 817 buf += "}\n\n"
821 bufi += "void " + fabric_mod_name + "_close_session(struct se_session *);\n" 818 bufi += "void " + fabric_mod_name + "_close_session(struct se_session *);\n"
822 819
823 if re.search('stop_session\)\(', fo):
824 buf += "void " + fabric_mod_name + "_stop_session(struct se_session *se_sess, int sess_sleep , int conn_sleep)\n"
825 buf += "{\n"
826 buf += " return;\n"
827 buf += "}\n\n"
828 bufi += "void " + fabric_mod_name + "_stop_session(struct se_session *, int, int);\n"
829
830 if re.search('fall_back_to_erl0\)\(', fo):
831 buf += "void " + fabric_mod_name + "_reset_nexus(struct se_session *se_sess)\n"
832 buf += "{\n"
833 buf += " return;\n"
834 buf += "}\n\n"
835 bufi += "void " + fabric_mod_name + "_reset_nexus(struct se_session *);\n"
836
837 if re.search('sess_logged_in\)\(', fo):
838 buf += "int " + fabric_mod_name + "_sess_logged_in(struct se_session *se_sess)\n"
839 buf += "{\n"
840 buf += " return 0;\n"
841 buf += "}\n\n"
842 bufi += "int " + fabric_mod_name + "_sess_logged_in(struct se_session *);\n"
843
844 if re.search('sess_get_index\)\(', fo): 820 if re.search('sess_get_index\)\(', fo):
845 buf += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *se_sess)\n" 821 buf += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *se_sess)\n"
846 buf += "{\n" 822 buf += "{\n"
@@ -898,19 +874,18 @@ def tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir_var, fabric_mod_name):
898 bufi += "int " + fabric_mod_name + "_queue_status(struct se_cmd *);\n" 874 bufi += "int " + fabric_mod_name + "_queue_status(struct se_cmd *);\n"
899 875
900 if re.search('queue_tm_rsp\)\(', fo): 876 if re.search('queue_tm_rsp\)\(', fo):
901 buf += "int " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *se_cmd)\n" 877 buf += "void " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *se_cmd)\n"
902 buf += "{\n" 878 buf += "{\n"
903 buf += " return 0;\n" 879 buf += " return;\n"
904 buf += "}\n\n" 880 buf += "}\n\n"
905 bufi += "int " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *);\n" 881 bufi += "void " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *);\n"
906 882
907 if re.search('is_state_remove\)\(', fo): 883 if re.search('aborted_task\)\(', fo):
908 buf += "int " + fabric_mod_name + "_is_state_remove(struct se_cmd *se_cmd)\n" 884 buf += "void " + fabric_mod_name + "_aborted_task(struct se_cmd *se_cmd)\n"
909 buf += "{\n" 885 buf += "{\n"
910 buf += " return 0;\n" 886 buf += " return;\n"
911 buf += "}\n\n" 887 buf += "}\n\n"
912 bufi += "int " + fabric_mod_name + "_is_state_remove(struct se_cmd *);\n" 888 bufi += "void " + fabric_mod_name + "_aborted_task(struct se_cmd *);\n"
913
914 889
915 ret = p.write(buf) 890 ret = p.write(buf)
916 if ret: 891 if ret:
@@ -1018,11 +993,11 @@ def main(modname, proto_ident):
1018 tcm_mod_build_kbuild(fabric_mod_dir, fabric_mod_name) 993 tcm_mod_build_kbuild(fabric_mod_dir, fabric_mod_name)
1019 tcm_mod_build_kconfig(fabric_mod_dir, fabric_mod_name) 994 tcm_mod_build_kconfig(fabric_mod_dir, fabric_mod_name)
1020 995
1021 input = raw_input("Would you like to add " + fabric_mod_name + "to drivers/target/Makefile..? [yes,no]: ") 996 input = raw_input("Would you like to add " + fabric_mod_name + " to drivers/target/Makefile..? [yes,no]: ")
1022 if input == "yes" or input == "y": 997 if input == "yes" or input == "y":
1023 tcm_mod_add_kbuild(tcm_dir, fabric_mod_name) 998 tcm_mod_add_kbuild(tcm_dir, fabric_mod_name)
1024 999
1025 input = raw_input("Would you like to add " + fabric_mod_name + "to drivers/target/Kconfig..? [yes,no]: ") 1000 input = raw_input("Would you like to add " + fabric_mod_name + " to drivers/target/Kconfig..? [yes,no]: ")
1026 if input == "yes" or input == "y": 1001 if input == "yes" or input == "y":
1027 tcm_mod_add_kconfig(tcm_dir, fabric_mod_name) 1002 tcm_mod_add_kconfig(tcm_dir, fabric_mod_name)
1028 1003
diff --git a/Documentation/thermal/cpu-cooling-api.txt b/Documentation/thermal/cpu-cooling-api.txt
index fca24c931ec8..753e47cc2e20 100644
--- a/Documentation/thermal/cpu-cooling-api.txt
+++ b/Documentation/thermal/cpu-cooling-api.txt
@@ -3,7 +3,7 @@ CPU cooling APIs How To
3 3
4Written by Amit Daniel Kachhap <amit.kachhap@linaro.org> 4Written by Amit Daniel Kachhap <amit.kachhap@linaro.org>
5 5
6Updated: 12 May 2012 6Updated: 6 Jan 2015
7 7
8Copyright (c) 2012 Samsung Electronics Co., Ltd(http://www.samsung.com) 8Copyright (c) 2012 Samsung Electronics Co., Ltd(http://www.samsung.com)
9 9
@@ -25,7 +25,18 @@ the user. The registration APIs returns the cooling device pointer.
25 25
26 clip_cpus: cpumask of cpus where the frequency constraints will happen. 26 clip_cpus: cpumask of cpus where the frequency constraints will happen.
27 27
281.1.2 void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) 281.1.2 struct thermal_cooling_device *of_cpufreq_cooling_register(
29 struct device_node *np, const struct cpumask *clip_cpus)
30
31 This interface function registers the cpufreq cooling device with
32 the name "thermal-cpufreq-%x" linking it with a device tree node, in
33 order to bind it via the thermal DT code. This api can support multiple
34 instances of cpufreq cooling devices.
35
36 np: pointer to the cooling device device tree node
37 clip_cpus: cpumask of cpus where the frequency constraints will happen.
38
391.1.3 void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
29 40
30 This interface function unregisters the "thermal-cpufreq-%x" cooling device. 41 This interface function unregisters the "thermal-cpufreq-%x" cooling device.
31 42
diff --git a/MAINTAINERS b/MAINTAINERS
index ddb9ac8d32b3..ab6610e6c610 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -724,15 +724,15 @@ F: include/uapi/linux/apm_bios.h
724F: drivers/char/apm-emulation.c 724F: drivers/char/apm-emulation.c
725 725
726APPLE BCM5974 MULTITOUCH DRIVER 726APPLE BCM5974 MULTITOUCH DRIVER
727M: Henrik Rydberg <rydberg@euromail.se> 727M: Henrik Rydberg <rydberg@bitmath.org>
728L: linux-input@vger.kernel.org 728L: linux-input@vger.kernel.org
729S: Maintained 729S: Odd fixes
730F: drivers/input/mouse/bcm5974.c 730F: drivers/input/mouse/bcm5974.c
731 731
732APPLE SMC DRIVER 732APPLE SMC DRIVER
733M: Henrik Rydberg <rydberg@euromail.se> 733M: Henrik Rydberg <rydberg@bitmath.org>
734L: lm-sensors@lm-sensors.org 734L: lm-sensors@lm-sensors.org
735S: Maintained 735S: Odd fixes
736F: drivers/hwmon/applesmc.c 736F: drivers/hwmon/applesmc.c
737 737
738APPLETALK NETWORK LAYER 738APPLETALK NETWORK LAYER
@@ -2259,6 +2259,7 @@ F: drivers/gpio/gpio-bt8xx.c
2259BTRFS FILE SYSTEM 2259BTRFS FILE SYSTEM
2260M: Chris Mason <clm@fb.com> 2260M: Chris Mason <clm@fb.com>
2261M: Josef Bacik <jbacik@fb.com> 2261M: Josef Bacik <jbacik@fb.com>
2262M: David Sterba <dsterba@suse.cz>
2262L: linux-btrfs@vger.kernel.org 2263L: linux-btrfs@vger.kernel.org
2263W: http://btrfs.wiki.kernel.org/ 2264W: http://btrfs.wiki.kernel.org/
2264Q: http://patchwork.kernel.org/project/linux-btrfs/list/ 2265Q: http://patchwork.kernel.org/project/linux-btrfs/list/
@@ -4748,7 +4749,7 @@ S: Supported
4748F: drivers/scsi/ipr.* 4749F: drivers/scsi/ipr.*
4749 4750
4750IBM Power Virtual Ethernet Device Driver 4751IBM Power Virtual Ethernet Device Driver
4751M: Santiago Leon <santil@linux.vnet.ibm.com> 4752M: Thomas Falcon <tlfalcon@linux.vnet.ibm.com>
4752L: netdev@vger.kernel.org 4753L: netdev@vger.kernel.org
4753S: Supported 4754S: Supported
4754F: drivers/net/ethernet/ibm/ibmveth.* 4755F: drivers/net/ethernet/ibm/ibmveth.*
@@ -4940,10 +4941,10 @@ F: include/uapi/linux/input.h
4940F: include/linux/input/ 4941F: include/linux/input/
4941 4942
4942INPUT MULTITOUCH (MT) PROTOCOL 4943INPUT MULTITOUCH (MT) PROTOCOL
4943M: Henrik Rydberg <rydberg@euromail.se> 4944M: Henrik Rydberg <rydberg@bitmath.org>
4944L: linux-input@vger.kernel.org 4945L: linux-input@vger.kernel.org
4945T: git git://git.kernel.org/pub/scm/linux/kernel/git/rydberg/input-mt.git 4946T: git git://git.kernel.org/pub/scm/linux/kernel/git/rydberg/input-mt.git
4946S: Maintained 4947S: Odd fixes
4947F: Documentation/input/multi-touch-protocol.txt 4948F: Documentation/input/multi-touch-protocol.txt
4948F: drivers/input/input-mt.c 4949F: drivers/input/input-mt.c
4949K: \b(ABS|SYN)_MT_ 4950K: \b(ABS|SYN)_MT_
@@ -5279,6 +5280,15 @@ W: www.open-iscsi.org
5279Q: http://patchwork.kernel.org/project/linux-rdma/list/ 5280Q: http://patchwork.kernel.org/project/linux-rdma/list/
5280F: drivers/infiniband/ulp/iser/ 5281F: drivers/infiniband/ulp/iser/
5281 5282
5283ISCSI EXTENSIONS FOR RDMA (ISER) TARGET
5284M: Sagi Grimberg <sagig@mellanox.com>
5285T: git git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending.git master
5286L: linux-rdma@vger.kernel.org
5287L: target-devel@vger.kernel.org
5288S: Supported
5289W: http://www.linux-iscsi.org
5290F: drivers/infiniband/ulp/isert
5291
5282ISDN SUBSYSTEM 5292ISDN SUBSYSTEM
5283M: Karsten Keil <isdn@linux-pingi.de> 5293M: Karsten Keil <isdn@linux-pingi.de>
5284L: isdn4linux@listserv.isdn4linux.de (subscribers-only) 5294L: isdn4linux@listserv.isdn4linux.de (subscribers-only)
@@ -9533,7 +9543,8 @@ F: drivers/platform/x86/thinkpad_acpi.c
9533TI BANDGAP AND THERMAL DRIVER 9543TI BANDGAP AND THERMAL DRIVER
9534M: Eduardo Valentin <edubezval@gmail.com> 9544M: Eduardo Valentin <edubezval@gmail.com>
9535L: linux-pm@vger.kernel.org 9545L: linux-pm@vger.kernel.org
9536S: Supported 9546L: linux-omap@vger.kernel.org
9547S: Maintained
9537F: drivers/thermal/ti-soc-thermal/ 9548F: drivers/thermal/ti-soc-thermal/
9538 9549
9539TI CLOCK DRIVER 9550TI CLOCK DRIVER
diff --git a/Makefile b/Makefile
index eb4eca56843a..e41a3356abee 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 3 1VERSION = 3
2PATCHLEVEL = 19 2PATCHLEVEL = 19
3SUBLEVEL = 0 3SUBLEVEL = 0
4EXTRAVERSION = -rc3 4EXTRAVERSION = -rc4
5NAME = Diseased Newt 5NAME = Diseased Newt
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
@@ -391,6 +391,7 @@ USERINCLUDE := \
391# Needed to be compatible with the O= option 391# Needed to be compatible with the O= option
392LINUXINCLUDE := \ 392LINUXINCLUDE := \
393 -I$(srctree)/arch/$(hdr-arch)/include \ 393 -I$(srctree)/arch/$(hdr-arch)/include \
394 -Iarch/$(hdr-arch)/include/generated/uapi \
394 -Iarch/$(hdr-arch)/include/generated \ 395 -Iarch/$(hdr-arch)/include/generated \
395 $(if $(KBUILD_SRC), -I$(srctree)/include) \ 396 $(if $(KBUILD_SRC), -I$(srctree)/include) \
396 -Iinclude \ 397 -Iinclude \
diff --git a/arch/arm/boot/dts/imx6sx-sdb.dts b/arch/arm/boot/dts/imx6sx-sdb.dts
index 1e6e5cc1c14c..8c1febd7e3f2 100644
--- a/arch/arm/boot/dts/imx6sx-sdb.dts
+++ b/arch/arm/boot/dts/imx6sx-sdb.dts
@@ -159,13 +159,28 @@
159 pinctrl-0 = <&pinctrl_enet1>; 159 pinctrl-0 = <&pinctrl_enet1>;
160 phy-supply = <&reg_enet_3v3>; 160 phy-supply = <&reg_enet_3v3>;
161 phy-mode = "rgmii"; 161 phy-mode = "rgmii";
162 phy-handle = <&ethphy1>;
162 status = "okay"; 163 status = "okay";
164
165 mdio {
166 #address-cells = <1>;
167 #size-cells = <0>;
168
169 ethphy1: ethernet-phy@0 {
170 reg = <0>;
171 };
172
173 ethphy2: ethernet-phy@1 {
174 reg = <1>;
175 };
176 };
163}; 177};
164 178
165&fec2 { 179&fec2 {
166 pinctrl-names = "default"; 180 pinctrl-names = "default";
167 pinctrl-0 = <&pinctrl_enet2>; 181 pinctrl-0 = <&pinctrl_enet2>;
168 phy-mode = "rgmii"; 182 phy-mode = "rgmii";
183 phy-handle = <&ethphy2>;
169 status = "okay"; 184 status = "okay";
170}; 185};
171 186
diff --git a/arch/arm/boot/dts/vf610-twr.dts b/arch/arm/boot/dts/vf610-twr.dts
index a0f762159cb2..f2b64b1b00fa 100644
--- a/arch/arm/boot/dts/vf610-twr.dts
+++ b/arch/arm/boot/dts/vf610-twr.dts
@@ -129,13 +129,28 @@
129 129
130&fec0 { 130&fec0 {
131 phy-mode = "rmii"; 131 phy-mode = "rmii";
132 phy-handle = <&ethphy0>;
132 pinctrl-names = "default"; 133 pinctrl-names = "default";
133 pinctrl-0 = <&pinctrl_fec0>; 134 pinctrl-0 = <&pinctrl_fec0>;
134 status = "okay"; 135 status = "okay";
136
137 mdio {
138 #address-cells = <1>;
139 #size-cells = <0>;
140
141 ethphy0: ethernet-phy@0 {
142 reg = <0>;
143 };
144
145 ethphy1: ethernet-phy@1 {
146 reg = <1>;
147 };
148 };
135}; 149};
136 150
137&fec1 { 151&fec1 {
138 phy-mode = "rmii"; 152 phy-mode = "rmii";
153 phy-handle = <&ethphy1>;
139 pinctrl-names = "default"; 154 pinctrl-names = "default";
140 pinctrl-0 = <&pinctrl_fec1>; 155 pinctrl-0 = <&pinctrl_fec1>;
141 status = "okay"; 156 status = "okay";
diff --git a/arch/arm/include/uapi/asm/unistd.h b/arch/arm/include/uapi/asm/unistd.h
index 705bb7620673..0c3f5a0dafd3 100644
--- a/arch/arm/include/uapi/asm/unistd.h
+++ b/arch/arm/include/uapi/asm/unistd.h
@@ -413,6 +413,7 @@
413#define __NR_getrandom (__NR_SYSCALL_BASE+384) 413#define __NR_getrandom (__NR_SYSCALL_BASE+384)
414#define __NR_memfd_create (__NR_SYSCALL_BASE+385) 414#define __NR_memfd_create (__NR_SYSCALL_BASE+385)
415#define __NR_bpf (__NR_SYSCALL_BASE+386) 415#define __NR_bpf (__NR_SYSCALL_BASE+386)
416#define __NR_execveat (__NR_SYSCALL_BASE+387)
416 417
417/* 418/*
418 * The following SWIs are ARM private. 419 * The following SWIs are ARM private.
diff --git a/arch/arm/kernel/calls.S b/arch/arm/kernel/calls.S
index e51833f8cc38..05745eb838c5 100644
--- a/arch/arm/kernel/calls.S
+++ b/arch/arm/kernel/calls.S
@@ -396,6 +396,7 @@
396 CALL(sys_getrandom) 396 CALL(sys_getrandom)
397/* 385 */ CALL(sys_memfd_create) 397/* 385 */ CALL(sys_memfd_create)
398 CALL(sys_bpf) 398 CALL(sys_bpf)
399 CALL(sys_execveat)
399#ifndef syscalls_counted 400#ifndef syscalls_counted
400.equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls 401.equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls
401#define syscalls_counted 402#define syscalls_counted
diff --git a/arch/arm/kernel/perf_regs.c b/arch/arm/kernel/perf_regs.c
index 6e4379c67cbc..592dda3f21ff 100644
--- a/arch/arm/kernel/perf_regs.c
+++ b/arch/arm/kernel/perf_regs.c
@@ -28,3 +28,11 @@ u64 perf_reg_abi(struct task_struct *task)
28{ 28{
29 return PERF_SAMPLE_REGS_ABI_32; 29 return PERF_SAMPLE_REGS_ABI_32;
30} 30}
31
32void perf_get_regs_user(struct perf_regs *regs_user,
33 struct pt_regs *regs,
34 struct pt_regs *regs_user_copy)
35{
36 regs_user->regs = task_pt_regs(current);
37 regs_user->abi = perf_reg_abi(current);
38}
diff --git a/arch/arm/mm/dump.c b/arch/arm/mm/dump.c
index 59424937e52b..9fe8e241335c 100644
--- a/arch/arm/mm/dump.c
+++ b/arch/arm/mm/dump.c
@@ -220,9 +220,6 @@ static void note_page(struct pg_state *st, unsigned long addr, unsigned level, u
220 static const char units[] = "KMGTPE"; 220 static const char units[] = "KMGTPE";
221 u64 prot = val & pg_level[level].mask; 221 u64 prot = val & pg_level[level].mask;
222 222
223 if (addr < USER_PGTABLES_CEILING)
224 return;
225
226 if (!st->level) { 223 if (!st->level) {
227 st->level = level; 224 st->level = level;
228 st->current_prot = prot; 225 st->current_prot = prot;
@@ -308,15 +305,13 @@ static void walk_pgd(struct seq_file *m)
308 pgd_t *pgd = swapper_pg_dir; 305 pgd_t *pgd = swapper_pg_dir;
309 struct pg_state st; 306 struct pg_state st;
310 unsigned long addr; 307 unsigned long addr;
311 unsigned i, pgdoff = USER_PGTABLES_CEILING / PGDIR_SIZE; 308 unsigned i;
312 309
313 memset(&st, 0, sizeof(st)); 310 memset(&st, 0, sizeof(st));
314 st.seq = m; 311 st.seq = m;
315 st.marker = address_markers; 312 st.marker = address_markers;
316 313
317 pgd += pgdoff; 314 for (i = 0; i < PTRS_PER_PGD; i++, pgd++) {
318
319 for (i = pgdoff; i < PTRS_PER_PGD; i++, pgd++) {
320 addr = i * PGDIR_SIZE; 315 addr = i * PGDIR_SIZE;
321 if (!pgd_none(*pgd)) { 316 if (!pgd_none(*pgd)) {
322 walk_pud(&st, pgd, addr); 317 walk_pud(&st, pgd, addr);
diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 98ad9c79ea0e..2495c8cb47ba 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -658,8 +658,8 @@ static struct section_perm ro_perms[] = {
658 .start = (unsigned long)_stext, 658 .start = (unsigned long)_stext,
659 .end = (unsigned long)__init_begin, 659 .end = (unsigned long)__init_begin,
660#ifdef CONFIG_ARM_LPAE 660#ifdef CONFIG_ARM_LPAE
661 .mask = ~PMD_SECT_RDONLY, 661 .mask = ~L_PMD_SECT_RDONLY,
662 .prot = PMD_SECT_RDONLY, 662 .prot = L_PMD_SECT_RDONLY,
663#else 663#else
664 .mask = ~(PMD_SECT_APX | PMD_SECT_AP_WRITE), 664 .mask = ~(PMD_SECT_APX | PMD_SECT_AP_WRITE),
665 .prot = PMD_SECT_APX | PMD_SECT_AP_WRITE, 665 .prot = PMD_SECT_APX | PMD_SECT_AP_WRITE,
diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
index cda7c40999b6..4e6ef896c619 100644
--- a/arch/arm/mm/mmu.c
+++ b/arch/arm/mm/mmu.c
@@ -1329,8 +1329,8 @@ static void __init kmap_init(void)
1329static void __init map_lowmem(void) 1329static void __init map_lowmem(void)
1330{ 1330{
1331 struct memblock_region *reg; 1331 struct memblock_region *reg;
1332 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE); 1332 phys_addr_t kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
1333 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE); 1333 phys_addr_t kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
1334 1334
1335 /* Map all the lowmem memory banks. */ 1335 /* Map all the lowmem memory banks. */
1336 for_each_memblock(memory, reg) { 1336 for_each_memblock(memory, reg) {
diff --git a/arch/arm64/include/asm/arch_timer.h b/arch/arm64/include/asm/arch_timer.h
index b1fa4e614718..fbe0ca31a99c 100644
--- a/arch/arm64/include/asm/arch_timer.h
+++ b/arch/arm64/include/asm/arch_timer.h
@@ -21,6 +21,7 @@
21 21
22#include <asm/barrier.h> 22#include <asm/barrier.h>
23 23
24#include <linux/bug.h>
24#include <linux/init.h> 25#include <linux/init.h>
25#include <linux/types.h> 26#include <linux/types.h>
26 27
diff --git a/arch/arm64/include/asm/cpu.h b/arch/arm64/include/asm/cpu.h
index ace70682499b..8e797b2fcc01 100644
--- a/arch/arm64/include/asm/cpu.h
+++ b/arch/arm64/include/asm/cpu.h
@@ -39,6 +39,7 @@ struct cpuinfo_arm64 {
39 u64 reg_id_aa64pfr0; 39 u64 reg_id_aa64pfr0;
40 u64 reg_id_aa64pfr1; 40 u64 reg_id_aa64pfr1;
41 41
42 u32 reg_id_dfr0;
42 u32 reg_id_isar0; 43 u32 reg_id_isar0;
43 u32 reg_id_isar1; 44 u32 reg_id_isar1;
44 u32 reg_id_isar2; 45 u32 reg_id_isar2;
@@ -51,6 +52,10 @@ struct cpuinfo_arm64 {
51 u32 reg_id_mmfr3; 52 u32 reg_id_mmfr3;
52 u32 reg_id_pfr0; 53 u32 reg_id_pfr0;
53 u32 reg_id_pfr1; 54 u32 reg_id_pfr1;
55
56 u32 reg_mvfr0;
57 u32 reg_mvfr1;
58 u32 reg_mvfr2;
54}; 59};
55 60
56DECLARE_PER_CPU(struct cpuinfo_arm64, cpu_data); 61DECLARE_PER_CPU(struct cpuinfo_arm64, cpu_data);
diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
index 8127e45e2637..865a7e28ea2d 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -41,6 +41,8 @@ void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr);
41static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu) 41static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu)
42{ 42{
43 vcpu->arch.hcr_el2 = HCR_GUEST_FLAGS; 43 vcpu->arch.hcr_el2 = HCR_GUEST_FLAGS;
44 if (test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features))
45 vcpu->arch.hcr_el2 &= ~HCR_RW;
44} 46}
45 47
46static inline unsigned long *vcpu_pc(const struct kvm_vcpu *vcpu) 48static inline unsigned long *vcpu_pc(const struct kvm_vcpu *vcpu)
diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h
index 286b1bec547c..f9be30ea1cbd 100644
--- a/arch/arm64/include/asm/processor.h
+++ b/arch/arm64/include/asm/processor.h
@@ -31,6 +31,7 @@
31 31
32#include <asm/fpsimd.h> 32#include <asm/fpsimd.h>
33#include <asm/hw_breakpoint.h> 33#include <asm/hw_breakpoint.h>
34#include <asm/pgtable-hwdef.h>
34#include <asm/ptrace.h> 35#include <asm/ptrace.h>
35#include <asm/types.h> 36#include <asm/types.h>
36 37
@@ -123,9 +124,6 @@ struct task_struct;
123/* Free all resources held by a thread. */ 124/* Free all resources held by a thread. */
124extern void release_thread(struct task_struct *); 125extern void release_thread(struct task_struct *);
125 126
126/* Prepare to copy thread state - unlazy all lazy status */
127#define prepare_to_copy(tsk) do { } while (0)
128
129unsigned long get_wchan(struct task_struct *p); 127unsigned long get_wchan(struct task_struct *p);
130 128
131#define cpu_relax() barrier() 129#define cpu_relax() barrier()
diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index 49c9aefd24a5..b780c6c76eec 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -44,7 +44,7 @@
44#define __ARM_NR_compat_cacheflush (__ARM_NR_COMPAT_BASE+2) 44#define __ARM_NR_compat_cacheflush (__ARM_NR_COMPAT_BASE+2)
45#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE+5) 45#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE+5)
46 46
47#define __NR_compat_syscalls 386 47#define __NR_compat_syscalls 387
48#endif 48#endif
49 49
50#define __ARCH_WANT_SYS_CLONE 50#define __ARCH_WANT_SYS_CLONE
diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c
index 57b641747534..07d435cf2eea 100644
--- a/arch/arm64/kernel/cpuinfo.c
+++ b/arch/arm64/kernel/cpuinfo.c
@@ -147,6 +147,7 @@ static void cpuinfo_sanity_check(struct cpuinfo_arm64 *cur)
147 * If we have AArch32, we care about 32-bit features for compat. These 147 * If we have AArch32, we care about 32-bit features for compat. These
148 * registers should be RES0 otherwise. 148 * registers should be RES0 otherwise.
149 */ 149 */
150 diff |= CHECK(id_dfr0, boot, cur, cpu);
150 diff |= CHECK(id_isar0, boot, cur, cpu); 151 diff |= CHECK(id_isar0, boot, cur, cpu);
151 diff |= CHECK(id_isar1, boot, cur, cpu); 152 diff |= CHECK(id_isar1, boot, cur, cpu);
152 diff |= CHECK(id_isar2, boot, cur, cpu); 153 diff |= CHECK(id_isar2, boot, cur, cpu);
@@ -165,6 +166,10 @@ static void cpuinfo_sanity_check(struct cpuinfo_arm64 *cur)
165 diff |= CHECK(id_pfr0, boot, cur, cpu); 166 diff |= CHECK(id_pfr0, boot, cur, cpu);
166 diff |= CHECK(id_pfr1, boot, cur, cpu); 167 diff |= CHECK(id_pfr1, boot, cur, cpu);
167 168
169 diff |= CHECK(mvfr0, boot, cur, cpu);
170 diff |= CHECK(mvfr1, boot, cur, cpu);
171 diff |= CHECK(mvfr2, boot, cur, cpu);
172
168 /* 173 /*
169 * Mismatched CPU features are a recipe for disaster. Don't even 174 * Mismatched CPU features are a recipe for disaster. Don't even
170 * pretend to support them. 175 * pretend to support them.
@@ -189,6 +194,7 @@ static void __cpuinfo_store_cpu(struct cpuinfo_arm64 *info)
189 info->reg_id_aa64pfr0 = read_cpuid(ID_AA64PFR0_EL1); 194 info->reg_id_aa64pfr0 = read_cpuid(ID_AA64PFR0_EL1);
190 info->reg_id_aa64pfr1 = read_cpuid(ID_AA64PFR1_EL1); 195 info->reg_id_aa64pfr1 = read_cpuid(ID_AA64PFR1_EL1);
191 196
197 info->reg_id_dfr0 = read_cpuid(ID_DFR0_EL1);
192 info->reg_id_isar0 = read_cpuid(ID_ISAR0_EL1); 198 info->reg_id_isar0 = read_cpuid(ID_ISAR0_EL1);
193 info->reg_id_isar1 = read_cpuid(ID_ISAR1_EL1); 199 info->reg_id_isar1 = read_cpuid(ID_ISAR1_EL1);
194 info->reg_id_isar2 = read_cpuid(ID_ISAR2_EL1); 200 info->reg_id_isar2 = read_cpuid(ID_ISAR2_EL1);
@@ -202,6 +208,10 @@ static void __cpuinfo_store_cpu(struct cpuinfo_arm64 *info)
202 info->reg_id_pfr0 = read_cpuid(ID_PFR0_EL1); 208 info->reg_id_pfr0 = read_cpuid(ID_PFR0_EL1);
203 info->reg_id_pfr1 = read_cpuid(ID_PFR1_EL1); 209 info->reg_id_pfr1 = read_cpuid(ID_PFR1_EL1);
204 210
211 info->reg_mvfr0 = read_cpuid(MVFR0_EL1);
212 info->reg_mvfr1 = read_cpuid(MVFR1_EL1);
213 info->reg_mvfr2 = read_cpuid(MVFR2_EL1);
214
205 cpuinfo_detect_icache_policy(info); 215 cpuinfo_detect_icache_policy(info);
206 216
207 check_local_cpu_errata(); 217 check_local_cpu_errata();
diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c
index 6fac253bc783..2bb4347d0edf 100644
--- a/arch/arm64/kernel/efi.c
+++ b/arch/arm64/kernel/efi.c
@@ -326,6 +326,7 @@ void __init efi_idmap_init(void)
326 326
327 /* boot time idmap_pg_dir is incomplete, so fill in missing parts */ 327 /* boot time idmap_pg_dir is incomplete, so fill in missing parts */
328 efi_setup_idmap(); 328 efi_setup_idmap();
329 early_memunmap(memmap.map, memmap.map_end - memmap.map);
329} 330}
330 331
331static int __init remap_region(efi_memory_desc_t *md, void **new) 332static int __init remap_region(efi_memory_desc_t *md, void **new)
@@ -380,7 +381,6 @@ static int __init arm64_enter_virtual_mode(void)
380 } 381 }
381 382
382 mapsize = memmap.map_end - memmap.map; 383 mapsize = memmap.map_end - memmap.map;
383 early_memunmap(memmap.map, mapsize);
384 384
385 if (efi_runtime_disabled()) { 385 if (efi_runtime_disabled()) {
386 pr_info("EFI runtime services will be disabled.\n"); 386 pr_info("EFI runtime services will be disabled.\n");
diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c
index fd027b101de5..9b6f71db2709 100644
--- a/arch/arm64/kernel/module.c
+++ b/arch/arm64/kernel/module.c
@@ -25,6 +25,7 @@
25#include <linux/mm.h> 25#include <linux/mm.h>
26#include <linux/moduleloader.h> 26#include <linux/moduleloader.h>
27#include <linux/vmalloc.h> 27#include <linux/vmalloc.h>
28#include <asm/alternative.h>
28#include <asm/insn.h> 29#include <asm/insn.h>
29#include <asm/sections.h> 30#include <asm/sections.h>
30 31
diff --git a/arch/arm64/kernel/perf_regs.c b/arch/arm64/kernel/perf_regs.c
index 6762ad705587..3f62b35fb6f1 100644
--- a/arch/arm64/kernel/perf_regs.c
+++ b/arch/arm64/kernel/perf_regs.c
@@ -50,3 +50,11 @@ u64 perf_reg_abi(struct task_struct *task)
50 else 50 else
51 return PERF_SAMPLE_REGS_ABI_64; 51 return PERF_SAMPLE_REGS_ABI_64;
52} 52}
53
54void perf_get_regs_user(struct perf_regs *regs_user,
55 struct pt_regs *regs,
56 struct pt_regs *regs_user_copy)
57{
58 regs_user->regs = task_pt_regs(current);
59 regs_user->abi = perf_reg_abi(current);
60}
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index b80991166754..20fe2932ad0c 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -402,6 +402,7 @@ void __init setup_arch(char **cmdline_p)
402 request_standard_resources(); 402 request_standard_resources();
403 403
404 efi_idmap_init(); 404 efi_idmap_init();
405 early_ioremap_reset();
405 406
406 unflatten_device_tree(); 407 unflatten_device_tree();
407 408
diff --git a/arch/arm64/kernel/smp_spin_table.c b/arch/arm64/kernel/smp_spin_table.c
index 4f93c67e63de..14944e5b28da 100644
--- a/arch/arm64/kernel/smp_spin_table.c
+++ b/arch/arm64/kernel/smp_spin_table.c
@@ -25,6 +25,7 @@
25#include <asm/cacheflush.h> 25#include <asm/cacheflush.h>
26#include <asm/cpu_ops.h> 26#include <asm/cpu_ops.h>
27#include <asm/cputype.h> 27#include <asm/cputype.h>
28#include <asm/io.h>
28#include <asm/smp_plat.h> 29#include <asm/smp_plat.h>
29 30
30extern void secondary_holding_pen(void); 31extern void secondary_holding_pen(void);
diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
index fbe909fb0a1a..c3ca89c27c6b 100644
--- a/arch/arm64/kvm/hyp.S
+++ b/arch/arm64/kvm/hyp.S
@@ -1014,6 +1014,7 @@ ENTRY(__kvm_tlb_flush_vmid_ipa)
1014 * Instead, we invalidate Stage-2 for this IPA, and the 1014 * Instead, we invalidate Stage-2 for this IPA, and the
1015 * whole of Stage-1. Weep... 1015 * whole of Stage-1. Weep...
1016 */ 1016 */
1017 lsr x1, x1, #12
1017 tlbi ipas2e1is, x1 1018 tlbi ipas2e1is, x1
1018 /* 1019 /*
1019 * We have to ensure completion of the invalidation at Stage-2, 1020 * We have to ensure completion of the invalidation at Stage-2,
diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c
index 70a7816535cd..0b4326578985 100644
--- a/arch/arm64/kvm/reset.c
+++ b/arch/arm64/kvm/reset.c
@@ -90,7 +90,6 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
90 if (!cpu_has_32bit_el1()) 90 if (!cpu_has_32bit_el1())
91 return -EINVAL; 91 return -EINVAL;
92 cpu_reset = &default_regs_reset32; 92 cpu_reset = &default_regs_reset32;
93 vcpu->arch.hcr_el2 &= ~HCR_RW;
94 } else { 93 } else {
95 cpu_reset = &default_regs_reset; 94 cpu_reset = &default_regs_reset;
96 } 95 }
diff --git a/arch/blackfin/mach-bf533/boards/stamp.c b/arch/blackfin/mach-bf533/boards/stamp.c
index 6f4bac969bf7..23eada79439c 100644
--- a/arch/blackfin/mach-bf533/boards/stamp.c
+++ b/arch/blackfin/mach-bf533/boards/stamp.c
@@ -7,6 +7,7 @@
7 */ 7 */
8 8
9#include <linux/device.h> 9#include <linux/device.h>
10#include <linux/delay.h>
10#include <linux/platform_device.h> 11#include <linux/platform_device.h>
11#include <linux/mtd/mtd.h> 12#include <linux/mtd/mtd.h>
12#include <linux/mtd/partitions.h> 13#include <linux/mtd/partitions.h>
diff --git a/arch/ia64/kernel/acpi.c b/arch/ia64/kernel/acpi.c
index 615ef81def49..e795cb848154 100644
--- a/arch/ia64/kernel/acpi.c
+++ b/arch/ia64/kernel/acpi.c
@@ -893,13 +893,13 @@ static int _acpi_map_lsapic(acpi_handle handle, int physid, int *pcpu)
893} 893}
894 894
895/* wrapper to silence section mismatch warning */ 895/* wrapper to silence section mismatch warning */
896int __ref acpi_map_lsapic(acpi_handle handle, int physid, int *pcpu) 896int __ref acpi_map_cpu(acpi_handle handle, int physid, int *pcpu)
897{ 897{
898 return _acpi_map_lsapic(handle, physid, pcpu); 898 return _acpi_map_lsapic(handle, physid, pcpu);
899} 899}
900EXPORT_SYMBOL(acpi_map_lsapic); 900EXPORT_SYMBOL(acpi_map_cpu);
901 901
902int acpi_unmap_lsapic(int cpu) 902int acpi_unmap_cpu(int cpu)
903{ 903{
904 ia64_cpu_to_sapicid[cpu] = -1; 904 ia64_cpu_to_sapicid[cpu] = -1;
905 set_cpu_present(cpu, false); 905 set_cpu_present(cpu, false);
@@ -910,8 +910,7 @@ int acpi_unmap_lsapic(int cpu)
910 910
911 return (0); 911 return (0);
912} 912}
913 913EXPORT_SYMBOL(acpi_unmap_cpu);
914EXPORT_SYMBOL(acpi_unmap_lsapic);
915#endif /* CONFIG_ACPI_HOTPLUG_CPU */ 914#endif /* CONFIG_ACPI_HOTPLUG_CPU */
916 915
917#ifdef CONFIG_ACPI_NUMA 916#ifdef CONFIG_ACPI_NUMA
diff --git a/arch/m68k/include/asm/unistd.h b/arch/m68k/include/asm/unistd.h
index 75e75d7b1702..244e0dbe45db 100644
--- a/arch/m68k/include/asm/unistd.h
+++ b/arch/m68k/include/asm/unistd.h
@@ -4,7 +4,7 @@
4#include <uapi/asm/unistd.h> 4#include <uapi/asm/unistd.h>
5 5
6 6
7#define NR_syscalls 355 7#define NR_syscalls 356
8 8
9#define __ARCH_WANT_OLD_READDIR 9#define __ARCH_WANT_OLD_READDIR
10#define __ARCH_WANT_OLD_STAT 10#define __ARCH_WANT_OLD_STAT
diff --git a/arch/m68k/include/uapi/asm/unistd.h b/arch/m68k/include/uapi/asm/unistd.h
index 2c1bec9a14b6..61fb6cb9d2ae 100644
--- a/arch/m68k/include/uapi/asm/unistd.h
+++ b/arch/m68k/include/uapi/asm/unistd.h
@@ -360,5 +360,6 @@
360#define __NR_getrandom 352 360#define __NR_getrandom 352
361#define __NR_memfd_create 353 361#define __NR_memfd_create 353
362#define __NR_bpf 354 362#define __NR_bpf 354
363#define __NR_execveat 355
363 364
364#endif /* _UAPI_ASM_M68K_UNISTD_H_ */ 365#endif /* _UAPI_ASM_M68K_UNISTD_H_ */
diff --git a/arch/m68k/kernel/syscalltable.S b/arch/m68k/kernel/syscalltable.S
index 2ca219e184cd..a0ec4303f2c8 100644
--- a/arch/m68k/kernel/syscalltable.S
+++ b/arch/m68k/kernel/syscalltable.S
@@ -375,4 +375,5 @@ ENTRY(sys_call_table)
375 .long sys_getrandom 375 .long sys_getrandom
376 .long sys_memfd_create 376 .long sys_memfd_create
377 .long sys_bpf 377 .long sys_bpf
378 .long sys_execveat /* 355 */
378 379
diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
index ebc4f165690a..0be6c681cab1 100644
--- a/arch/powerpc/include/asm/thread_info.h
+++ b/arch/powerpc/include/asm/thread_info.h
@@ -23,9 +23,9 @@
23#define THREAD_SIZE (1 << THREAD_SHIFT) 23#define THREAD_SIZE (1 << THREAD_SHIFT)
24 24
25#ifdef CONFIG_PPC64 25#ifdef CONFIG_PPC64
26#define CURRENT_THREAD_INFO(dest, sp) clrrdi dest, sp, THREAD_SHIFT 26#define CURRENT_THREAD_INFO(dest, sp) stringify_in_c(clrrdi dest, sp, THREAD_SHIFT)
27#else 27#else
28#define CURRENT_THREAD_INFO(dest, sp) rlwinm dest, sp, 0, 0, 31-THREAD_SHIFT 28#define CURRENT_THREAD_INFO(dest, sp) stringify_in_c(rlwinm dest, sp, 0, 0, 31-THREAD_SHIFT)
29#endif 29#endif
30 30
31#ifndef __ASSEMBLY__ 31#ifndef __ASSEMBLY__
@@ -71,12 +71,13 @@ struct thread_info {
71#define THREAD_SIZE_ORDER (THREAD_SHIFT - PAGE_SHIFT) 71#define THREAD_SIZE_ORDER (THREAD_SHIFT - PAGE_SHIFT)
72 72
73/* how to get the thread information struct from C */ 73/* how to get the thread information struct from C */
74register unsigned long __current_r1 asm("r1");
75static inline struct thread_info *current_thread_info(void) 74static inline struct thread_info *current_thread_info(void)
76{ 75{
77 /* gcc4, at least, is smart enough to turn this into a single 76 unsigned long val;
78 * rlwinm for ppc32 and clrrdi for ppc64 */ 77
79 return (struct thread_info *)(__current_r1 & ~(THREAD_SIZE-1)); 78 asm (CURRENT_THREAD_INFO(%0,1) : "=r" (val));
79
80 return (struct thread_info *)val;
80} 81}
81 82
82#endif /* __ASSEMBLY__ */ 83#endif /* __ASSEMBLY__ */
diff --git a/arch/powerpc/platforms/powernv/opal-wrappers.S b/arch/powerpc/platforms/powernv/opal-wrappers.S
index 54eca8b3b288..0509bca5e830 100644
--- a/arch/powerpc/platforms/powernv/opal-wrappers.S
+++ b/arch/powerpc/platforms/powernv/opal-wrappers.S
@@ -40,7 +40,6 @@ BEGIN_FTR_SECTION; \
40 b 1f; \ 40 b 1f; \
41END_FTR_SECTION(0, 1); \ 41END_FTR_SECTION(0, 1); \
42 ld r12,opal_tracepoint_refcount@toc(r2); \ 42 ld r12,opal_tracepoint_refcount@toc(r2); \
43 std r12,32(r1); \
44 cmpdi r12,0; \ 43 cmpdi r12,0; \
45 bne- LABEL; \ 44 bne- LABEL; \
461: 451:
diff --git a/arch/s390/hypfs/hypfs_vm.c b/arch/s390/hypfs/hypfs_vm.c
index 32040ace00ea..afbe07907c10 100644
--- a/arch/s390/hypfs/hypfs_vm.c
+++ b/arch/s390/hypfs/hypfs_vm.c
@@ -231,7 +231,7 @@ failed:
231struct dbfs_d2fc_hdr { 231struct dbfs_d2fc_hdr {
232 u64 len; /* Length of d2fc buffer without header */ 232 u64 len; /* Length of d2fc buffer without header */
233 u16 version; /* Version of header */ 233 u16 version; /* Version of header */
234 char tod_ext[16]; /* TOD clock for d2fc */ 234 char tod_ext[STORE_CLOCK_EXT_SIZE]; /* TOD clock for d2fc */
235 u64 count; /* Number of VM guests in d2fc buffer */ 235 u64 count; /* Number of VM guests in d2fc buffer */
236 char reserved[30]; 236 char reserved[30];
237} __attribute__ ((packed)); 237} __attribute__ ((packed));
diff --git a/arch/s390/include/asm/irqflags.h b/arch/s390/include/asm/irqflags.h
index 37b9091ab8c0..16aa0c779e07 100644
--- a/arch/s390/include/asm/irqflags.h
+++ b/arch/s390/include/asm/irqflags.h
@@ -36,7 +36,7 @@ static inline notrace void __arch_local_irq_ssm(unsigned long flags)
36 36
37static inline notrace unsigned long arch_local_save_flags(void) 37static inline notrace unsigned long arch_local_save_flags(void)
38{ 38{
39 return __arch_local_irq_stosm(0x00); 39 return __arch_local_irq_stnsm(0xff);
40} 40}
41 41
42static inline notrace unsigned long arch_local_irq_save(void) 42static inline notrace unsigned long arch_local_irq_save(void)
diff --git a/arch/s390/include/asm/timex.h b/arch/s390/include/asm/timex.h
index 8beee1cceba4..98eb2a579223 100644
--- a/arch/s390/include/asm/timex.h
+++ b/arch/s390/include/asm/timex.h
@@ -67,20 +67,22 @@ static inline void local_tick_enable(unsigned long long comp)
67 set_clock_comparator(S390_lowcore.clock_comparator); 67 set_clock_comparator(S390_lowcore.clock_comparator);
68} 68}
69 69
70#define CLOCK_TICK_RATE 1193180 /* Underlying HZ */ 70#define CLOCK_TICK_RATE 1193180 /* Underlying HZ */
71#define STORE_CLOCK_EXT_SIZE 16 /* stcke writes 16 bytes */
71 72
72typedef unsigned long long cycles_t; 73typedef unsigned long long cycles_t;
73 74
74static inline void get_tod_clock_ext(char clk[16]) 75static inline void get_tod_clock_ext(char *clk)
75{ 76{
76 typedef struct { char _[sizeof(clk)]; } addrtype; 77 typedef struct { char _[STORE_CLOCK_EXT_SIZE]; } addrtype;
77 78
78 asm volatile("stcke %0" : "=Q" (*(addrtype *) clk) : : "cc"); 79 asm volatile("stcke %0" : "=Q" (*(addrtype *) clk) : : "cc");
79} 80}
80 81
81static inline unsigned long long get_tod_clock(void) 82static inline unsigned long long get_tod_clock(void)
82{ 83{
83 unsigned char clk[16]; 84 unsigned char clk[STORE_CLOCK_EXT_SIZE];
85
84 get_tod_clock_ext(clk); 86 get_tod_clock_ext(clk);
85 return *((unsigned long long *)&clk[1]); 87 return *((unsigned long long *)&clk[1]);
86} 88}
diff --git a/arch/s390/include/uapi/asm/unistd.h b/arch/s390/include/uapi/asm/unistd.h
index 2b446cf0cc65..67878af257a0 100644
--- a/arch/s390/include/uapi/asm/unistd.h
+++ b/arch/s390/include/uapi/asm/unistd.h
@@ -289,7 +289,8 @@
289#define __NR_bpf 351 289#define __NR_bpf 351
290#define __NR_s390_pci_mmio_write 352 290#define __NR_s390_pci_mmio_write 352
291#define __NR_s390_pci_mmio_read 353 291#define __NR_s390_pci_mmio_read 353
292#define NR_syscalls 354 292#define __NR_execveat 354
293#define NR_syscalls 355
293 294
294/* 295/*
295 * There are some system calls that are not present on 64 bit, some 296 * There are some system calls that are not present on 64 bit, some
diff --git a/arch/s390/kernel/syscalls.S b/arch/s390/kernel/syscalls.S
index a2987243bc76..939ec474b1dd 100644
--- a/arch/s390/kernel/syscalls.S
+++ b/arch/s390/kernel/syscalls.S
@@ -362,3 +362,4 @@ SYSCALL(sys_memfd_create,sys_memfd_create,compat_sys_memfd_create) /* 350 */
362SYSCALL(sys_bpf,sys_bpf,compat_sys_bpf) 362SYSCALL(sys_bpf,sys_bpf,compat_sys_bpf)
363SYSCALL(sys_ni_syscall,sys_s390_pci_mmio_write,compat_sys_s390_pci_mmio_write) 363SYSCALL(sys_ni_syscall,sys_s390_pci_mmio_write,compat_sys_s390_pci_mmio_write)
364SYSCALL(sys_ni_syscall,sys_s390_pci_mmio_read,compat_sys_s390_pci_mmio_read) 364SYSCALL(sys_ni_syscall,sys_s390_pci_mmio_read,compat_sys_s390_pci_mmio_read)
365SYSCALL(sys_execveat,sys_execveat,compat_sys_execveat)
diff --git a/arch/s390/kernel/uprobes.c b/arch/s390/kernel/uprobes.c
index f6b3cd056ec2..cc7328080b60 100644
--- a/arch/s390/kernel/uprobes.c
+++ b/arch/s390/kernel/uprobes.c
@@ -48,6 +48,30 @@ bool arch_uprobe_xol_was_trapped(struct task_struct *tsk)
48 return false; 48 return false;
49} 49}
50 50
51static int check_per_event(unsigned short cause, unsigned long control,
52 struct pt_regs *regs)
53{
54 if (!(regs->psw.mask & PSW_MASK_PER))
55 return 0;
56 /* user space single step */
57 if (control == 0)
58 return 1;
59 /* over indication for storage alteration */
60 if ((control & 0x20200000) && (cause & 0x2000))
61 return 1;
62 if (cause & 0x8000) {
63 /* all branches */
64 if ((control & 0x80800000) == 0x80000000)
65 return 1;
66 /* branch into selected range */
67 if (((control & 0x80800000) == 0x80800000) &&
68 regs->psw.addr >= current->thread.per_user.start &&
69 regs->psw.addr <= current->thread.per_user.end)
70 return 1;
71 }
72 return 0;
73}
74
51int arch_uprobe_post_xol(struct arch_uprobe *auprobe, struct pt_regs *regs) 75int arch_uprobe_post_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
52{ 76{
53 int fixup = probe_get_fixup_type(auprobe->insn); 77 int fixup = probe_get_fixup_type(auprobe->insn);
@@ -71,9 +95,13 @@ int arch_uprobe_post_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
71 if (regs->psw.addr - utask->xol_vaddr == ilen) 95 if (regs->psw.addr - utask->xol_vaddr == ilen)
72 regs->psw.addr = utask->vaddr + ilen; 96 regs->psw.addr = utask->vaddr + ilen;
73 } 97 }
74 /* If per tracing was active generate trap */ 98 if (check_per_event(current->thread.per_event.cause,
75 if (regs->psw.mask & PSW_MASK_PER) 99 current->thread.per_user.control, regs)) {
76 do_per_trap(regs); 100 /* fix per address */
101 current->thread.per_event.address = utask->vaddr;
102 /* trigger per event */
103 set_pt_regs_flag(regs, PIF_PER_TRAP);
104 }
77 return 0; 105 return 0;
78} 106}
79 107
@@ -106,6 +134,7 @@ void arch_uprobe_abort_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
106 clear_thread_flag(TIF_UPROBE_SINGLESTEP); 134 clear_thread_flag(TIF_UPROBE_SINGLESTEP);
107 regs->int_code = auprobe->saved_int_code; 135 regs->int_code = auprobe->saved_int_code;
108 regs->psw.addr = current->utask->vaddr; 136 regs->psw.addr = current->utask->vaddr;
137 current->thread.per_event.address = current->utask->vaddr;
109} 138}
110 139
111unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline, 140unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline,
@@ -146,17 +175,20 @@ static void adjust_psw_addr(psw_t *psw, unsigned long len)
146 __rc; \ 175 __rc; \
147}) 176})
148 177
149#define emu_store_ril(ptr, input) \ 178#define emu_store_ril(regs, ptr, input) \
150({ \ 179({ \
151 unsigned int mask = sizeof(*(ptr)) - 1; \ 180 unsigned int mask = sizeof(*(ptr)) - 1; \
181 __typeof__(ptr) __ptr = (ptr); \
152 int __rc = 0; \ 182 int __rc = 0; \
153 \ 183 \
154 if (!test_facility(34)) \ 184 if (!test_facility(34)) \
155 __rc = EMU_ILLEGAL_OP; \ 185 __rc = EMU_ILLEGAL_OP; \
156 else if ((u64 __force)ptr & mask) \ 186 else if ((u64 __force)__ptr & mask) \
157 __rc = EMU_SPECIFICATION; \ 187 __rc = EMU_SPECIFICATION; \
158 else if (put_user(*(input), ptr)) \ 188 else if (put_user(*(input), __ptr)) \
159 __rc = EMU_ADDRESSING; \ 189 __rc = EMU_ADDRESSING; \
190 if (__rc == 0) \
191 sim_stor_event(regs, __ptr, mask + 1); \
160 __rc; \ 192 __rc; \
161}) 193})
162 194
@@ -198,6 +230,25 @@ union split_register {
198}; 230};
199 231
200/* 232/*
233 * If user per registers are setup to trace storage alterations and an
234 * emulated store took place on a fitting address a user trap is generated.
235 */
236static void sim_stor_event(struct pt_regs *regs, void *addr, int len)
237{
238 if (!(regs->psw.mask & PSW_MASK_PER))
239 return;
240 if (!(current->thread.per_user.control & PER_EVENT_STORE))
241 return;
242 if ((void *)current->thread.per_user.start > (addr + len))
243 return;
244 if ((void *)current->thread.per_user.end < addr)
245 return;
246 current->thread.per_event.address = regs->psw.addr;
247 current->thread.per_event.cause = PER_EVENT_STORE >> 16;
248 set_pt_regs_flag(regs, PIF_PER_TRAP);
249}
250
251/*
201 * pc relative instructions are emulated, since parameters may not be 252 * pc relative instructions are emulated, since parameters may not be
202 * accessible from the xol area due to range limitations. 253 * accessible from the xol area due to range limitations.
203 */ 254 */
@@ -249,13 +300,13 @@ static void handle_insn_ril(struct arch_uprobe *auprobe, struct pt_regs *regs)
249 rc = emu_load_ril((u32 __user *)uptr, &rx->u64); 300 rc = emu_load_ril((u32 __user *)uptr, &rx->u64);
250 break; 301 break;
251 case 0x07: /* sthrl */ 302 case 0x07: /* sthrl */
252 rc = emu_store_ril((u16 __user *)uptr, &rx->u16[3]); 303 rc = emu_store_ril(regs, (u16 __user *)uptr, &rx->u16[3]);
253 break; 304 break;
254 case 0x0b: /* stgrl */ 305 case 0x0b: /* stgrl */
255 rc = emu_store_ril((u64 __user *)uptr, &rx->u64); 306 rc = emu_store_ril(regs, (u64 __user *)uptr, &rx->u64);
256 break; 307 break;
257 case 0x0f: /* strl */ 308 case 0x0f: /* strl */
258 rc = emu_store_ril((u32 __user *)uptr, &rx->u32[1]); 309 rc = emu_store_ril(regs, (u32 __user *)uptr, &rx->u32[1]);
259 break; 310 break;
260 } 311 }
261 break; 312 break;
diff --git a/arch/s390/kernel/vtime.c b/arch/s390/kernel/vtime.c
index 7f0089d9a4aa..e34122e539a1 100644
--- a/arch/s390/kernel/vtime.c
+++ b/arch/s390/kernel/vtime.c
@@ -128,8 +128,6 @@ void vtime_account_irq_enter(struct task_struct *tsk)
128 struct thread_info *ti = task_thread_info(tsk); 128 struct thread_info *ti = task_thread_info(tsk);
129 u64 timer, system; 129 u64 timer, system;
130 130
131 WARN_ON_ONCE(!irqs_disabled());
132
133 timer = S390_lowcore.last_update_timer; 131 timer = S390_lowcore.last_update_timer;
134 S390_lowcore.last_update_timer = get_vtimer(); 132 S390_lowcore.last_update_timer = get_vtimer();
135 S390_lowcore.system_timer += timer - S390_lowcore.last_update_timer; 133 S390_lowcore.system_timer += timer - S390_lowcore.last_update_timer;
diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c
index be99357d238c..3cf8cc03fff6 100644
--- a/arch/s390/mm/pgtable.c
+++ b/arch/s390/mm/pgtable.c
@@ -322,11 +322,12 @@ static int gmap_alloc_table(struct gmap *gmap, unsigned long *table,
322static unsigned long __gmap_segment_gaddr(unsigned long *entry) 322static unsigned long __gmap_segment_gaddr(unsigned long *entry)
323{ 323{
324 struct page *page; 324 struct page *page;
325 unsigned long offset; 325 unsigned long offset, mask;
326 326
327 offset = (unsigned long) entry / sizeof(unsigned long); 327 offset = (unsigned long) entry / sizeof(unsigned long);
328 offset = (offset & (PTRS_PER_PMD - 1)) * PMD_SIZE; 328 offset = (offset & (PTRS_PER_PMD - 1)) * PMD_SIZE;
329 page = pmd_to_page((pmd_t *) entry); 329 mask = ~(PTRS_PER_PMD * sizeof(pmd_t) - 1);
330 page = virt_to_page((void *)((unsigned long) entry & mask));
330 return page->index + offset; 331 return page->index + offset;
331} 332}
332 333
diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
index c52ac77408ca..524496d47ef5 100644
--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -431,8 +431,8 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter,
431 EMIT4_DISP(0x88500000, K); 431 EMIT4_DISP(0x88500000, K);
432 break; 432 break;
433 case BPF_ALU | BPF_NEG: /* A = -A */ 433 case BPF_ALU | BPF_NEG: /* A = -A */
434 /* lnr %r5,%r5 */ 434 /* lcr %r5,%r5 */
435 EMIT2(0x1155); 435 EMIT2(0x1355);
436 break; 436 break;
437 case BPF_JMP | BPF_JA: /* ip += K */ 437 case BPF_JMP | BPF_JA: /* ip += K */
438 offset = addrs[i + K] + jit->start - jit->prg; 438 offset = addrs[i + K] + jit->start - jit->prg;
@@ -502,8 +502,8 @@ branch: if (filter->jt == filter->jf) {
502xbranch: /* Emit compare if the branch targets are different */ 502xbranch: /* Emit compare if the branch targets are different */
503 if (filter->jt != filter->jf) { 503 if (filter->jt != filter->jf) {
504 jit->seen |= SEEN_XREG; 504 jit->seen |= SEEN_XREG;
505 /* cr %r5,%r12 */ 505 /* clr %r5,%r12 */
506 EMIT2(0x195c); 506 EMIT2(0x155c);
507 } 507 }
508 goto branch; 508 goto branch;
509 case BPF_JMP | BPF_JSET | BPF_X: /* ip += (A & X) ? jt : jf */ 509 case BPF_JMP | BPF_JSET | BPF_X: /* ip += (A & X) ? jt : jf */
diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index 5b016e2498f3..3db07f30636f 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -51,6 +51,7 @@ targets += cpustr.h
51$(obj)/cpustr.h: $(obj)/mkcpustr FORCE 51$(obj)/cpustr.h: $(obj)/mkcpustr FORCE
52 $(call if_changed,cpustr) 52 $(call if_changed,cpustr)
53endif 53endif
54clean-files += cpustr.h
54 55
55# --------------------------------------------------------------------------- 56# ---------------------------------------------------------------------------
56 57
diff --git a/arch/x86/crypto/Makefile b/arch/x86/crypto/Makefile
index fd0f848938cc..5a4a089e8b1f 100644
--- a/arch/x86/crypto/Makefile
+++ b/arch/x86/crypto/Makefile
@@ -26,7 +26,6 @@ obj-$(CONFIG_CRYPTO_GHASH_CLMUL_NI_INTEL) += ghash-clmulni-intel.o
26 26
27obj-$(CONFIG_CRYPTO_CRC32C_INTEL) += crc32c-intel.o 27obj-$(CONFIG_CRYPTO_CRC32C_INTEL) += crc32c-intel.o
28obj-$(CONFIG_CRYPTO_SHA1_SSSE3) += sha1-ssse3.o 28obj-$(CONFIG_CRYPTO_SHA1_SSSE3) += sha1-ssse3.o
29obj-$(CONFIG_CRYPTO_SHA1_MB) += sha-mb/
30obj-$(CONFIG_CRYPTO_CRC32_PCLMUL) += crc32-pclmul.o 29obj-$(CONFIG_CRYPTO_CRC32_PCLMUL) += crc32-pclmul.o
31obj-$(CONFIG_CRYPTO_SHA256_SSSE3) += sha256-ssse3.o 30obj-$(CONFIG_CRYPTO_SHA256_SSSE3) += sha256-ssse3.o
32obj-$(CONFIG_CRYPTO_SHA512_SSSE3) += sha512-ssse3.o 31obj-$(CONFIG_CRYPTO_SHA512_SSSE3) += sha512-ssse3.o
@@ -46,6 +45,7 @@ endif
46ifeq ($(avx2_supported),yes) 45ifeq ($(avx2_supported),yes)
47 obj-$(CONFIG_CRYPTO_CAMELLIA_AESNI_AVX2_X86_64) += camellia-aesni-avx2.o 46 obj-$(CONFIG_CRYPTO_CAMELLIA_AESNI_AVX2_X86_64) += camellia-aesni-avx2.o
48 obj-$(CONFIG_CRYPTO_SERPENT_AVX2_X86_64) += serpent-avx2.o 47 obj-$(CONFIG_CRYPTO_SERPENT_AVX2_X86_64) += serpent-avx2.o
48 obj-$(CONFIG_CRYPTO_SHA1_MB) += sha-mb/
49endif 49endif
50 50
51aes-i586-y := aes-i586-asm_32.o aes_glue.o 51aes-i586-y := aes-i586-asm_32.o aes_glue.o
diff --git a/arch/x86/crypto/aes_ctrby8_avx-x86_64.S b/arch/x86/crypto/aes_ctrby8_avx-x86_64.S
index 2df2a0298f5a..a916c4a61165 100644
--- a/arch/x86/crypto/aes_ctrby8_avx-x86_64.S
+++ b/arch/x86/crypto/aes_ctrby8_avx-x86_64.S
@@ -208,7 +208,7 @@ ddq_add_8:
208 208
209 .if (klen == KEY_128) 209 .if (klen == KEY_128)
210 .if (load_keys) 210 .if (load_keys)
211 vmovdqa 3*16(p_keys), xkeyA 211 vmovdqa 3*16(p_keys), xkey4
212 .endif 212 .endif
213 .else 213 .else
214 vmovdqa 3*16(p_keys), xkeyA 214 vmovdqa 3*16(p_keys), xkeyA
@@ -224,7 +224,7 @@ ddq_add_8:
224 add $(16*by), p_in 224 add $(16*by), p_in
225 225
226 .if (klen == KEY_128) 226 .if (klen == KEY_128)
227 vmovdqa 4*16(p_keys), xkey4 227 vmovdqa 4*16(p_keys), xkeyB
228 .else 228 .else
229 .if (load_keys) 229 .if (load_keys)
230 vmovdqa 4*16(p_keys), xkey4 230 vmovdqa 4*16(p_keys), xkey4
@@ -234,7 +234,12 @@ ddq_add_8:
234 .set i, 0 234 .set i, 0
235 .rept by 235 .rept by
236 club XDATA, i 236 club XDATA, i
237 vaesenc xkeyA, var_xdata, var_xdata /* key 3 */ 237 /* key 3 */
238 .if (klen == KEY_128)
239 vaesenc xkey4, var_xdata, var_xdata
240 .else
241 vaesenc xkeyA, var_xdata, var_xdata
242 .endif
238 .set i, (i +1) 243 .set i, (i +1)
239 .endr 244 .endr
240 245
@@ -243,13 +248,18 @@ ddq_add_8:
243 .set i, 0 248 .set i, 0
244 .rept by 249 .rept by
245 club XDATA, i 250 club XDATA, i
246 vaesenc xkey4, var_xdata, var_xdata /* key 4 */ 251 /* key 4 */
252 .if (klen == KEY_128)
253 vaesenc xkeyB, var_xdata, var_xdata
254 .else
255 vaesenc xkey4, var_xdata, var_xdata
256 .endif
247 .set i, (i +1) 257 .set i, (i +1)
248 .endr 258 .endr
249 259
250 .if (klen == KEY_128) 260 .if (klen == KEY_128)
251 .if (load_keys) 261 .if (load_keys)
252 vmovdqa 6*16(p_keys), xkeyB 262 vmovdqa 6*16(p_keys), xkey8
253 .endif 263 .endif
254 .else 264 .else
255 vmovdqa 6*16(p_keys), xkeyB 265 vmovdqa 6*16(p_keys), xkeyB
@@ -267,12 +277,17 @@ ddq_add_8:
267 .set i, 0 277 .set i, 0
268 .rept by 278 .rept by
269 club XDATA, i 279 club XDATA, i
270 vaesenc xkeyB, var_xdata, var_xdata /* key 6 */ 280 /* key 6 */
281 .if (klen == KEY_128)
282 vaesenc xkey8, var_xdata, var_xdata
283 .else
284 vaesenc xkeyB, var_xdata, var_xdata
285 .endif
271 .set i, (i +1) 286 .set i, (i +1)
272 .endr 287 .endr
273 288
274 .if (klen == KEY_128) 289 .if (klen == KEY_128)
275 vmovdqa 8*16(p_keys), xkey8 290 vmovdqa 8*16(p_keys), xkeyB
276 .else 291 .else
277 .if (load_keys) 292 .if (load_keys)
278 vmovdqa 8*16(p_keys), xkey8 293 vmovdqa 8*16(p_keys), xkey8
@@ -288,7 +303,7 @@ ddq_add_8:
288 303
289 .if (klen == KEY_128) 304 .if (klen == KEY_128)
290 .if (load_keys) 305 .if (load_keys)
291 vmovdqa 9*16(p_keys), xkeyA 306 vmovdqa 9*16(p_keys), xkey12
292 .endif 307 .endif
293 .else 308 .else
294 vmovdqa 9*16(p_keys), xkeyA 309 vmovdqa 9*16(p_keys), xkeyA
@@ -297,7 +312,12 @@ ddq_add_8:
297 .set i, 0 312 .set i, 0
298 .rept by 313 .rept by
299 club XDATA, i 314 club XDATA, i
300 vaesenc xkey8, var_xdata, var_xdata /* key 8 */ 315 /* key 8 */
316 .if (klen == KEY_128)
317 vaesenc xkeyB, var_xdata, var_xdata
318 .else
319 vaesenc xkey8, var_xdata, var_xdata
320 .endif
301 .set i, (i +1) 321 .set i, (i +1)
302 .endr 322 .endr
303 323
@@ -306,7 +326,12 @@ ddq_add_8:
306 .set i, 0 326 .set i, 0
307 .rept by 327 .rept by
308 club XDATA, i 328 club XDATA, i
309 vaesenc xkeyA, var_xdata, var_xdata /* key 9 */ 329 /* key 9 */
330 .if (klen == KEY_128)
331 vaesenc xkey12, var_xdata, var_xdata
332 .else
333 vaesenc xkeyA, var_xdata, var_xdata
334 .endif
310 .set i, (i +1) 335 .set i, (i +1)
311 .endr 336 .endr
312 337
@@ -412,7 +437,6 @@ ddq_add_8:
412/* main body of aes ctr load */ 437/* main body of aes ctr load */
413 438
414.macro do_aes_ctrmain key_len 439.macro do_aes_ctrmain key_len
415
416 cmp $16, num_bytes 440 cmp $16, num_bytes
417 jb .Ldo_return2\key_len 441 jb .Ldo_return2\key_len
418 442
diff --git a/arch/x86/include/asm/vgtod.h b/arch/x86/include/asm/vgtod.h
index e7e9682a33e9..f556c4843aa1 100644
--- a/arch/x86/include/asm/vgtod.h
+++ b/arch/x86/include/asm/vgtod.h
@@ -80,9 +80,11 @@ static inline unsigned int __getcpu(void)
80 80
81 /* 81 /*
82 * Load per CPU data from GDT. LSL is faster than RDTSCP and 82 * Load per CPU data from GDT. LSL is faster than RDTSCP and
83 * works on all CPUs. 83 * works on all CPUs. This is volatile so that it orders
84 * correctly wrt barrier() and to keep gcc from cleverly
85 * hoisting it out of the calling function.
84 */ 86 */
85 asm("lsl %1,%0" : "=r" (p) : "r" (__PER_CPU_SEG)); 87 asm volatile ("lsl %1,%0" : "=r" (p) : "r" (__PER_CPU_SEG));
86 88
87 return p; 89 return p;
88} 90}
diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
index 4433a4be8171..d1626364a28a 100644
--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -750,13 +750,13 @@ static int _acpi_map_lsapic(acpi_handle handle, int physid, int *pcpu)
750} 750}
751 751
752/* wrapper to silence section mismatch warning */ 752/* wrapper to silence section mismatch warning */
753int __ref acpi_map_lsapic(acpi_handle handle, int physid, int *pcpu) 753int __ref acpi_map_cpu(acpi_handle handle, int physid, int *pcpu)
754{ 754{
755 return _acpi_map_lsapic(handle, physid, pcpu); 755 return _acpi_map_lsapic(handle, physid, pcpu);
756} 756}
757EXPORT_SYMBOL(acpi_map_lsapic); 757EXPORT_SYMBOL(acpi_map_cpu);
758 758
759int acpi_unmap_lsapic(int cpu) 759int acpi_unmap_cpu(int cpu)
760{ 760{
761#ifdef CONFIG_ACPI_NUMA 761#ifdef CONFIG_ACPI_NUMA
762 set_apicid_to_node(per_cpu(x86_cpu_to_apicid, cpu), NUMA_NO_NODE); 762 set_apicid_to_node(per_cpu(x86_cpu_to_apicid, cpu), NUMA_NO_NODE);
@@ -768,8 +768,7 @@ int acpi_unmap_lsapic(int cpu)
768 768
769 return (0); 769 return (0);
770} 770}
771 771EXPORT_SYMBOL(acpi_unmap_cpu);
772EXPORT_SYMBOL(acpi_unmap_lsapic);
773#endif /* CONFIG_ACPI_HOTPLUG_CPU */ 772#endif /* CONFIG_ACPI_HOTPLUG_CPU */
774 773
775int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base) 774int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
index e27b49d7c922..80091ae54c2b 100644
--- a/arch/x86/kernel/cpu/Makefile
+++ b/arch/x86/kernel/cpu/Makefile
@@ -66,3 +66,4 @@ targets += capflags.c
66$(obj)/capflags.c: $(cpufeature) $(src)/mkcapflags.sh FORCE 66$(obj)/capflags.c: $(cpufeature) $(src)/mkcapflags.sh FORCE
67 $(call if_changed,mkcapflags) 67 $(call if_changed,mkcapflags)
68endif 68endif
69clean-files += capflags.c
diff --git a/arch/x86/kernel/cpu/mkcapflags.sh b/arch/x86/kernel/cpu/mkcapflags.sh
index e2b22df964cd..36d99a337b49 100644
--- a/arch/x86/kernel/cpu/mkcapflags.sh
+++ b/arch/x86/kernel/cpu/mkcapflags.sh
@@ -28,7 +28,7 @@ function dump_array()
28 # If the /* comment */ starts with a quote string, grab that. 28 # If the /* comment */ starts with a quote string, grab that.
29 VALUE="$(echo "$i" | sed -n 's@.*/\* *\("[^"]*"\).*\*/@\1@p')" 29 VALUE="$(echo "$i" | sed -n 's@.*/\* *\("[^"]*"\).*\*/@\1@p')"
30 [ -z "$VALUE" ] && VALUE="\"$NAME\"" 30 [ -z "$VALUE" ] && VALUE="\"$NAME\""
31 [ "$VALUE" == '""' ] && continue 31 [ "$VALUE" = '""' ] && continue
32 32
33 # Name is uppercase, VALUE is all lowercase 33 # Name is uppercase, VALUE is all lowercase
34 VALUE="$(echo "$VALUE" | tr A-Z a-z)" 34 VALUE="$(echo "$VALUE" | tr A-Z a-z)"
diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
index 18eb78bbdd10..863d9b02563e 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
@@ -17,7 +17,7 @@
17#define UNCORE_PCI_DEV_TYPE(data) ((data >> 8) & 0xff) 17#define UNCORE_PCI_DEV_TYPE(data) ((data >> 8) & 0xff)
18#define UNCORE_PCI_DEV_IDX(data) (data & 0xff) 18#define UNCORE_PCI_DEV_IDX(data) (data & 0xff)
19#define UNCORE_EXTRA_PCI_DEV 0xff 19#define UNCORE_EXTRA_PCI_DEV 0xff
20#define UNCORE_EXTRA_PCI_DEV_MAX 2 20#define UNCORE_EXTRA_PCI_DEV_MAX 3
21 21
22/* support up to 8 sockets */ 22/* support up to 8 sockets */
23#define UNCORE_SOCKET_MAX 8 23#define UNCORE_SOCKET_MAX 8
diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c b/arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c
index 745b158e9a65..21af6149edf2 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c
@@ -891,6 +891,7 @@ void snbep_uncore_cpu_init(void)
891enum { 891enum {
892 SNBEP_PCI_QPI_PORT0_FILTER, 892 SNBEP_PCI_QPI_PORT0_FILTER,
893 SNBEP_PCI_QPI_PORT1_FILTER, 893 SNBEP_PCI_QPI_PORT1_FILTER,
894 HSWEP_PCI_PCU_3,
894}; 895};
895 896
896static int snbep_qpi_hw_config(struct intel_uncore_box *box, struct perf_event *event) 897static int snbep_qpi_hw_config(struct intel_uncore_box *box, struct perf_event *event)
@@ -2026,6 +2027,17 @@ void hswep_uncore_cpu_init(void)
2026{ 2027{
2027 if (hswep_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores) 2028 if (hswep_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores)
2028 hswep_uncore_cbox.num_boxes = boot_cpu_data.x86_max_cores; 2029 hswep_uncore_cbox.num_boxes = boot_cpu_data.x86_max_cores;
2030
2031 /* Detect 6-8 core systems with only two SBOXes */
2032 if (uncore_extra_pci_dev[0][HSWEP_PCI_PCU_3]) {
2033 u32 capid4;
2034
2035 pci_read_config_dword(uncore_extra_pci_dev[0][HSWEP_PCI_PCU_3],
2036 0x94, &capid4);
2037 if (((capid4 >> 6) & 0x3) == 0)
2038 hswep_uncore_sbox.num_boxes = 2;
2039 }
2040
2029 uncore_msr_uncores = hswep_msr_uncores; 2041 uncore_msr_uncores = hswep_msr_uncores;
2030} 2042}
2031 2043
@@ -2287,6 +2299,11 @@ static DEFINE_PCI_DEVICE_TABLE(hswep_uncore_pci_ids) = {
2287 .driver_data = UNCORE_PCI_DEV_DATA(UNCORE_EXTRA_PCI_DEV, 2299 .driver_data = UNCORE_PCI_DEV_DATA(UNCORE_EXTRA_PCI_DEV,
2288 SNBEP_PCI_QPI_PORT1_FILTER), 2300 SNBEP_PCI_QPI_PORT1_FILTER),
2289 }, 2301 },
2302 { /* PCU.3 (for Capability registers) */
2303 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2fc0),
2304 .driver_data = UNCORE_PCI_DEV_DATA(UNCORE_EXTRA_PCI_DEV,
2305 HSWEP_PCI_PCU_3),
2306 },
2290 { /* end: all zeroes */ } 2307 { /* end: all zeroes */ }
2291}; 2308};
2292 2309
diff --git a/arch/x86/kernel/perf_regs.c b/arch/x86/kernel/perf_regs.c
index e309cc5c276e..781861cc5ee8 100644
--- a/arch/x86/kernel/perf_regs.c
+++ b/arch/x86/kernel/perf_regs.c
@@ -78,6 +78,14 @@ u64 perf_reg_abi(struct task_struct *task)
78{ 78{
79 return PERF_SAMPLE_REGS_ABI_32; 79 return PERF_SAMPLE_REGS_ABI_32;
80} 80}
81
82void perf_get_regs_user(struct perf_regs *regs_user,
83 struct pt_regs *regs,
84 struct pt_regs *regs_user_copy)
85{
86 regs_user->regs = task_pt_regs(current);
87 regs_user->abi = perf_reg_abi(current);
88}
81#else /* CONFIG_X86_64 */ 89#else /* CONFIG_X86_64 */
82#define REG_NOSUPPORT ((1ULL << PERF_REG_X86_DS) | \ 90#define REG_NOSUPPORT ((1ULL << PERF_REG_X86_DS) | \
83 (1ULL << PERF_REG_X86_ES) | \ 91 (1ULL << PERF_REG_X86_ES) | \
@@ -102,4 +110,86 @@ u64 perf_reg_abi(struct task_struct *task)
102 else 110 else
103 return PERF_SAMPLE_REGS_ABI_64; 111 return PERF_SAMPLE_REGS_ABI_64;
104} 112}
113
114void perf_get_regs_user(struct perf_regs *regs_user,
115 struct pt_regs *regs,
116 struct pt_regs *regs_user_copy)
117{
118 struct pt_regs *user_regs = task_pt_regs(current);
119
120 /*
121 * If we're in an NMI that interrupted task_pt_regs setup, then
122 * we can't sample user regs at all. This check isn't really
123 * sufficient, though, as we could be in an NMI inside an interrupt
124 * that happened during task_pt_regs setup.
125 */
126 if (regs->sp > (unsigned long)&user_regs->r11 &&
127 regs->sp <= (unsigned long)(user_regs + 1)) {
128 regs_user->abi = PERF_SAMPLE_REGS_ABI_NONE;
129 regs_user->regs = NULL;
130 return;
131 }
132
133 /*
134 * RIP, flags, and the argument registers are usually saved.
135 * orig_ax is probably okay, too.
136 */
137 regs_user_copy->ip = user_regs->ip;
138 regs_user_copy->cx = user_regs->cx;
139 regs_user_copy->dx = user_regs->dx;
140 regs_user_copy->si = user_regs->si;
141 regs_user_copy->di = user_regs->di;
142 regs_user_copy->r8 = user_regs->r8;
143 regs_user_copy->r9 = user_regs->r9;
144 regs_user_copy->r10 = user_regs->r10;
145 regs_user_copy->r11 = user_regs->r11;
146 regs_user_copy->orig_ax = user_regs->orig_ax;
147 regs_user_copy->flags = user_regs->flags;
148
149 /*
150 * Don't even try to report the "rest" regs.
151 */
152 regs_user_copy->bx = -1;
153 regs_user_copy->bp = -1;
154 regs_user_copy->r12 = -1;
155 regs_user_copy->r13 = -1;
156 regs_user_copy->r14 = -1;
157 regs_user_copy->r15 = -1;
158
159 /*
160 * For this to be at all useful, we need a reasonable guess for
161 * sp and the ABI. Be careful: we're in NMI context, and we're
162 * considering current to be the current task, so we should
163 * be careful not to look at any other percpu variables that might
164 * change during context switches.
165 */
166 if (IS_ENABLED(CONFIG_IA32_EMULATION) &&
167 task_thread_info(current)->status & TS_COMPAT) {
168 /* Easy case: we're in a compat syscall. */
169 regs_user->abi = PERF_SAMPLE_REGS_ABI_32;
170 regs_user_copy->sp = user_regs->sp;
171 regs_user_copy->cs = user_regs->cs;
172 regs_user_copy->ss = user_regs->ss;
173 } else if (user_regs->orig_ax != -1) {
174 /*
175 * We're probably in a 64-bit syscall.
176 * Warning: this code is severely racy. At least it's better
177 * than just blindly copying user_regs.
178 */
179 regs_user->abi = PERF_SAMPLE_REGS_ABI_64;
180 regs_user_copy->sp = this_cpu_read(old_rsp);
181 regs_user_copy->cs = __USER_CS;
182 regs_user_copy->ss = __USER_DS;
183 regs_user_copy->cx = -1; /* usually contains garbage */
184 } else {
185 /* We're probably in an interrupt or exception. */
186 regs_user->abi = user_64bit_mode(user_regs) ?
187 PERF_SAMPLE_REGS_ABI_64 : PERF_SAMPLE_REGS_ABI_32;
188 regs_user_copy->sp = user_regs->sp;
189 regs_user_copy->cs = user_regs->cs;
190 regs_user_copy->ss = user_regs->ss;
191 }
192
193 regs_user->regs = regs_user_copy;
194}
105#endif /* CONFIG_X86_32 */ 195#endif /* CONFIG_X86_32 */
diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
index 2480978b31cc..1313ae6b478b 100644
--- a/arch/x86/lib/insn.c
+++ b/arch/x86/lib/insn.c
@@ -28,7 +28,7 @@
28 28
29/* Verify next sizeof(t) bytes can be on the same instruction */ 29/* Verify next sizeof(t) bytes can be on the same instruction */
30#define validate_next(t, insn, n) \ 30#define validate_next(t, insn, n) \
31 ((insn)->next_byte + sizeof(t) + n < (insn)->end_kaddr) 31 ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)
32 32
33#define __get_next(t, insn) \ 33#define __get_next(t, insn) \
34 ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; }) 34 ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; })
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index a97ee0801475..08a7d313538a 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -438,20 +438,20 @@ static unsigned long __init init_range_memory_mapping(
438static unsigned long __init get_new_step_size(unsigned long step_size) 438static unsigned long __init get_new_step_size(unsigned long step_size)
439{ 439{
440 /* 440 /*
441 * Explain why we shift by 5 and why we don't have to worry about 441 * Initial mapped size is PMD_SIZE (2M).
442 * 'step_size << 5' overflowing:
443 *
444 * initial mapped size is PMD_SIZE (2M).
445 * We can not set step_size to be PUD_SIZE (1G) yet. 442 * We can not set step_size to be PUD_SIZE (1G) yet.
446 * In worse case, when we cross the 1G boundary, and 443 * In worse case, when we cross the 1G boundary, and
447 * PG_LEVEL_2M is not set, we will need 1+1+512 pages (2M + 8k) 444 * PG_LEVEL_2M is not set, we will need 1+1+512 pages (2M + 8k)
448 * to map 1G range with PTE. Use 5 as shift for now. 445 * to map 1G range with PTE. Hence we use one less than the
446 * difference of page table level shifts.
449 * 447 *
450 * Don't need to worry about overflow, on 32bit, when step_size 448 * Don't need to worry about overflow in the top-down case, on 32bit,
451 * is 0, round_down() returns 0 for start, and that turns it 449 * when step_size is 0, round_down() returns 0 for start, and that
452 * into 0x100000000ULL. 450 * turns it into 0x100000000ULL.
451 * In the bottom-up case, round_up(x, 0) returns 0 though too, which
452 * needs to be taken into consideration by the code below.
453 */ 453 */
454 return step_size << 5; 454 return step_size << (PMD_SHIFT - PAGE_SHIFT - 1);
455} 455}
456 456
457/** 457/**
@@ -471,7 +471,6 @@ static void __init memory_map_top_down(unsigned long map_start,
471 unsigned long step_size; 471 unsigned long step_size;
472 unsigned long addr; 472 unsigned long addr;
473 unsigned long mapped_ram_size = 0; 473 unsigned long mapped_ram_size = 0;
474 unsigned long new_mapped_ram_size;
475 474
476 /* xen has big range in reserved near end of ram, skip it at first.*/ 475 /* xen has big range in reserved near end of ram, skip it at first.*/
477 addr = memblock_find_in_range(map_start, map_end, PMD_SIZE, PMD_SIZE); 476 addr = memblock_find_in_range(map_start, map_end, PMD_SIZE, PMD_SIZE);
@@ -496,14 +495,12 @@ static void __init memory_map_top_down(unsigned long map_start,
496 start = map_start; 495 start = map_start;
497 } else 496 } else
498 start = map_start; 497 start = map_start;
499 new_mapped_ram_size = init_range_memory_mapping(start, 498 mapped_ram_size += init_range_memory_mapping(start,
500 last_start); 499 last_start);
501 last_start = start; 500 last_start = start;
502 min_pfn_mapped = last_start >> PAGE_SHIFT; 501 min_pfn_mapped = last_start >> PAGE_SHIFT;
503 /* only increase step_size after big range get mapped */ 502 if (mapped_ram_size >= step_size)
504 if (new_mapped_ram_size > mapped_ram_size)
505 step_size = get_new_step_size(step_size); 503 step_size = get_new_step_size(step_size);
506 mapped_ram_size += new_mapped_ram_size;
507 } 504 }
508 505
509 if (real_end < map_end) 506 if (real_end < map_end)
@@ -524,7 +521,7 @@ static void __init memory_map_top_down(unsigned long map_start,
524static void __init memory_map_bottom_up(unsigned long map_start, 521static void __init memory_map_bottom_up(unsigned long map_start,
525 unsigned long map_end) 522 unsigned long map_end)
526{ 523{
527 unsigned long next, new_mapped_ram_size, start; 524 unsigned long next, start;
528 unsigned long mapped_ram_size = 0; 525 unsigned long mapped_ram_size = 0;
529 /* step_size need to be small so pgt_buf from BRK could cover it */ 526 /* step_size need to be small so pgt_buf from BRK could cover it */
530 unsigned long step_size = PMD_SIZE; 527 unsigned long step_size = PMD_SIZE;
@@ -539,19 +536,19 @@ static void __init memory_map_bottom_up(unsigned long map_start,
539 * for page table. 536 * for page table.
540 */ 537 */
541 while (start < map_end) { 538 while (start < map_end) {
542 if (map_end - start > step_size) { 539 if (step_size && map_end - start > step_size) {
543 next = round_up(start + 1, step_size); 540 next = round_up(start + 1, step_size);
544 if (next > map_end) 541 if (next > map_end)
545 next = map_end; 542 next = map_end;
546 } else 543 } else {
547 next = map_end; 544 next = map_end;
545 }
548 546
549 new_mapped_ram_size = init_range_memory_mapping(start, next); 547 mapped_ram_size += init_range_memory_mapping(start, next);
550 start = next; 548 start = next;
551 549
552 if (new_mapped_ram_size > mapped_ram_size) 550 if (mapped_ram_size >= step_size)
553 step_size = get_new_step_size(step_size); 551 step_size = get_new_step_size(step_size);
554 mapped_ram_size += new_mapped_ram_size;
555 } 552 }
556} 553}
557 554
diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
index 009495b9ab4b..1c9f750c3859 100644
--- a/arch/x86/vdso/vma.c
+++ b/arch/x86/vdso/vma.c
@@ -41,12 +41,17 @@ void __init init_vdso_image(const struct vdso_image *image)
41 41
42struct linux_binprm; 42struct linux_binprm;
43 43
44/* Put the vdso above the (randomized) stack with another randomized offset. 44/*
45 This way there is no hole in the middle of address space. 45 * Put the vdso above the (randomized) stack with another randomized
46 To save memory make sure it is still in the same PTE as the stack top. 46 * offset. This way there is no hole in the middle of address space.
47 This doesn't give that many random bits. 47 * To save memory make sure it is still in the same PTE as the stack
48 48 * top. This doesn't give that many random bits.
49 Only used for the 64-bit and x32 vdsos. */ 49 *
50 * Note that this algorithm is imperfect: the distribution of the vdso
51 * start address within a PMD is biased toward the end.
52 *
53 * Only used for the 64-bit and x32 vdsos.
54 */
50static unsigned long vdso_addr(unsigned long start, unsigned len) 55static unsigned long vdso_addr(unsigned long start, unsigned len)
51{ 56{
52#ifdef CONFIG_X86_32 57#ifdef CONFIG_X86_32
@@ -54,22 +59,30 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
54#else 59#else
55 unsigned long addr, end; 60 unsigned long addr, end;
56 unsigned offset; 61 unsigned offset;
57 end = (start + PMD_SIZE - 1) & PMD_MASK; 62
63 /*
64 * Round up the start address. It can start out unaligned as a result
65 * of stack start randomization.
66 */
67 start = PAGE_ALIGN(start);
68
69 /* Round the lowest possible end address up to a PMD boundary. */
70 end = (start + len + PMD_SIZE - 1) & PMD_MASK;
58 if (end >= TASK_SIZE_MAX) 71 if (end >= TASK_SIZE_MAX)
59 end = TASK_SIZE_MAX; 72 end = TASK_SIZE_MAX;
60 end -= len; 73 end -= len;
61 /* This loses some more bits than a modulo, but is cheaper */ 74
62 offset = get_random_int() & (PTRS_PER_PTE - 1); 75 if (end > start) {
63 addr = start + (offset << PAGE_SHIFT); 76 offset = get_random_int() % (((end - start) >> PAGE_SHIFT) + 1);
64 if (addr >= end) 77 addr = start + (offset << PAGE_SHIFT);
65 addr = end; 78 } else {
79 addr = start;
80 }
66 81
67 /* 82 /*
68 * page-align it here so that get_unmapped_area doesn't 83 * Forcibly align the final address in case we have a hardware
69 * align it wrongfully again to the next page. addr can come in 4K 84 * issue that requires alignment for performance reasons.
70 * unaligned here as a result of stack start randomization.
71 */ 85 */
72 addr = PAGE_ALIGN(addr);
73 addr = align_vdso_addr(addr); 86 addr = align_vdso_addr(addr);
74 87
75 return addr; 88 return addr;
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index 6bf3a13e3e0f..78a881b7fc41 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -40,6 +40,7 @@
40#include <xen/interface/physdev.h> 40#include <xen/interface/physdev.h>
41#include <xen/interface/vcpu.h> 41#include <xen/interface/vcpu.h>
42#include <xen/interface/memory.h> 42#include <xen/interface/memory.h>
43#include <xen/interface/nmi.h>
43#include <xen/interface/xen-mca.h> 44#include <xen/interface/xen-mca.h>
44#include <xen/features.h> 45#include <xen/features.h>
45#include <xen/page.h> 46#include <xen/page.h>
@@ -66,6 +67,7 @@
66#include <asm/reboot.h> 67#include <asm/reboot.h>
67#include <asm/stackprotector.h> 68#include <asm/stackprotector.h>
68#include <asm/hypervisor.h> 69#include <asm/hypervisor.h>
70#include <asm/mach_traps.h>
69#include <asm/mwait.h> 71#include <asm/mwait.h>
70#include <asm/pci_x86.h> 72#include <asm/pci_x86.h>
71#include <asm/pat.h> 73#include <asm/pat.h>
@@ -1351,6 +1353,21 @@ static const struct machine_ops xen_machine_ops __initconst = {
1351 .emergency_restart = xen_emergency_restart, 1353 .emergency_restart = xen_emergency_restart,
1352}; 1354};
1353 1355
1356static unsigned char xen_get_nmi_reason(void)
1357{
1358 unsigned char reason = 0;
1359
1360 /* Construct a value which looks like it came from port 0x61. */
1361 if (test_bit(_XEN_NMIREASON_io_error,
1362 &HYPERVISOR_shared_info->arch.nmi_reason))
1363 reason |= NMI_REASON_IOCHK;
1364 if (test_bit(_XEN_NMIREASON_pci_serr,
1365 &HYPERVISOR_shared_info->arch.nmi_reason))
1366 reason |= NMI_REASON_SERR;
1367
1368 return reason;
1369}
1370
1354static void __init xen_boot_params_init_edd(void) 1371static void __init xen_boot_params_init_edd(void)
1355{ 1372{
1356#if IS_ENABLED(CONFIG_EDD) 1373#if IS_ENABLED(CONFIG_EDD)
@@ -1535,9 +1552,12 @@ asmlinkage __visible void __init xen_start_kernel(void)
1535 pv_info = xen_info; 1552 pv_info = xen_info;
1536 pv_init_ops = xen_init_ops; 1553 pv_init_ops = xen_init_ops;
1537 pv_apic_ops = xen_apic_ops; 1554 pv_apic_ops = xen_apic_ops;
1538 if (!xen_pvh_domain()) 1555 if (!xen_pvh_domain()) {
1539 pv_cpu_ops = xen_cpu_ops; 1556 pv_cpu_ops = xen_cpu_ops;
1540 1557
1558 x86_platform.get_nmi_reason = xen_get_nmi_reason;
1559 }
1560
1541 if (xen_feature(XENFEAT_auto_translated_physmap)) 1561 if (xen_feature(XENFEAT_auto_translated_physmap))
1542 x86_init.resources.memory_setup = xen_auto_xlated_memory_setup; 1562 x86_init.resources.memory_setup = xen_auto_xlated_memory_setup;
1543 else 1563 else
diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c
index edbc7a63fd73..70fb5075c901 100644
--- a/arch/x86/xen/p2m.c
+++ b/arch/x86/xen/p2m.c
@@ -167,10 +167,13 @@ static void * __ref alloc_p2m_page(void)
167 return (void *)__get_free_page(GFP_KERNEL | __GFP_REPEAT); 167 return (void *)__get_free_page(GFP_KERNEL | __GFP_REPEAT);
168} 168}
169 169
170/* Only to be called in case of a race for a page just allocated! */ 170static void __ref free_p2m_page(void *p)
171static void free_p2m_page(void *p)
172{ 171{
173 BUG_ON(!slab_is_available()); 172 if (unlikely(!slab_is_available())) {
173 free_bootmem((unsigned long)p, PAGE_SIZE);
174 return;
175 }
176
174 free_page((unsigned long)p); 177 free_page((unsigned long)p);
175} 178}
176 179
@@ -375,7 +378,7 @@ static void __init xen_rebuild_p2m_list(unsigned long *p2m)
375 p2m_missing_pte : p2m_identity_pte; 378 p2m_missing_pte : p2m_identity_pte;
376 for (i = 0; i < PMDS_PER_MID_PAGE; i++) { 379 for (i = 0; i < PMDS_PER_MID_PAGE; i++) {
377 pmdp = populate_extra_pmd( 380 pmdp = populate_extra_pmd(
378 (unsigned long)(p2m + pfn + i * PTRS_PER_PTE)); 381 (unsigned long)(p2m + pfn) + i * PMD_SIZE);
379 set_pmd(pmdp, __pmd(__pa(ptep) | _KERNPG_TABLE)); 382 set_pmd(pmdp, __pmd(__pa(ptep) | _KERNPG_TABLE));
380 } 383 }
381 } 384 }
@@ -436,10 +439,9 @@ EXPORT_SYMBOL_GPL(get_phys_to_machine);
436 * a new pmd is to replace p2m_missing_pte or p2m_identity_pte by a individual 439 * a new pmd is to replace p2m_missing_pte or p2m_identity_pte by a individual
437 * pmd. In case of PAE/x86-32 there are multiple pmds to allocate! 440 * pmd. In case of PAE/x86-32 there are multiple pmds to allocate!
438 */ 441 */
439static pte_t *alloc_p2m_pmd(unsigned long addr, pte_t *ptep, pte_t *pte_pg) 442static pte_t *alloc_p2m_pmd(unsigned long addr, pte_t *pte_pg)
440{ 443{
441 pte_t *ptechk; 444 pte_t *ptechk;
442 pte_t *pteret = ptep;
443 pte_t *pte_newpg[PMDS_PER_MID_PAGE]; 445 pte_t *pte_newpg[PMDS_PER_MID_PAGE];
444 pmd_t *pmdp; 446 pmd_t *pmdp;
445 unsigned int level; 447 unsigned int level;
@@ -473,8 +475,6 @@ static pte_t *alloc_p2m_pmd(unsigned long addr, pte_t *ptep, pte_t *pte_pg)
473 if (ptechk == pte_pg) { 475 if (ptechk == pte_pg) {
474 set_pmd(pmdp, 476 set_pmd(pmdp,
475 __pmd(__pa(pte_newpg[i]) | _KERNPG_TABLE)); 477 __pmd(__pa(pte_newpg[i]) | _KERNPG_TABLE));
476 if (vaddr == (addr & ~(PMD_SIZE - 1)))
477 pteret = pte_offset_kernel(pmdp, addr);
478 pte_newpg[i] = NULL; 478 pte_newpg[i] = NULL;
479 } 479 }
480 480
@@ -488,7 +488,7 @@ static pte_t *alloc_p2m_pmd(unsigned long addr, pte_t *ptep, pte_t *pte_pg)
488 vaddr += PMD_SIZE; 488 vaddr += PMD_SIZE;
489 } 489 }
490 490
491 return pteret; 491 return lookup_address(addr, &level);
492} 492}
493 493
494/* 494/*
@@ -517,7 +517,7 @@ static bool alloc_p2m(unsigned long pfn)
517 517
518 if (pte_pg == p2m_missing_pte || pte_pg == p2m_identity_pte) { 518 if (pte_pg == p2m_missing_pte || pte_pg == p2m_identity_pte) {
519 /* PMD level is missing, allocate a new one */ 519 /* PMD level is missing, allocate a new one */
520 ptep = alloc_p2m_pmd(addr, ptep, pte_pg); 520 ptep = alloc_p2m_pmd(addr, pte_pg);
521 if (!ptep) 521 if (!ptep)
522 return false; 522 return false;
523 } 523 }
diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c
index dfd77dec8e2b..865e56cea7a0 100644
--- a/arch/x86/xen/setup.c
+++ b/arch/x86/xen/setup.c
@@ -140,7 +140,7 @@ static void __init xen_del_extra_mem(u64 start, u64 size)
140unsigned long __ref xen_chk_extra_mem(unsigned long pfn) 140unsigned long __ref xen_chk_extra_mem(unsigned long pfn)
141{ 141{
142 int i; 142 int i;
143 unsigned long addr = PFN_PHYS(pfn); 143 phys_addr_t addr = PFN_PHYS(pfn);
144 144
145 for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++) { 145 for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++) {
146 if (addr >= xen_extra_mem[i].start && 146 if (addr >= xen_extra_mem[i].start &&
@@ -160,6 +160,8 @@ void __init xen_inv_extra_mem(void)
160 int i; 160 int i;
161 161
162 for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++) { 162 for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++) {
163 if (!xen_extra_mem[i].size)
164 continue;
163 pfn_s = PFN_DOWN(xen_extra_mem[i].start); 165 pfn_s = PFN_DOWN(xen_extra_mem[i].start);
164 pfn_e = PFN_UP(xen_extra_mem[i].start + xen_extra_mem[i].size); 166 pfn_e = PFN_UP(xen_extra_mem[i].start + xen_extra_mem[i].size);
165 for (pfn = pfn_s; pfn < pfn_e; pfn++) 167 for (pfn = pfn_s; pfn < pfn_e; pfn++)
@@ -229,15 +231,14 @@ static int __init xen_free_mfn(unsigned long mfn)
229 * as a fallback if the remapping fails. 231 * as a fallback if the remapping fails.
230 */ 232 */
231static void __init xen_set_identity_and_release_chunk(unsigned long start_pfn, 233static void __init xen_set_identity_and_release_chunk(unsigned long start_pfn,
232 unsigned long end_pfn, unsigned long nr_pages, unsigned long *identity, 234 unsigned long end_pfn, unsigned long nr_pages, unsigned long *released)
233 unsigned long *released)
234{ 235{
235 unsigned long len = 0;
236 unsigned long pfn, end; 236 unsigned long pfn, end;
237 int ret; 237 int ret;
238 238
239 WARN_ON(start_pfn > end_pfn); 239 WARN_ON(start_pfn > end_pfn);
240 240
241 /* Release pages first. */
241 end = min(end_pfn, nr_pages); 242 end = min(end_pfn, nr_pages);
242 for (pfn = start_pfn; pfn < end; pfn++) { 243 for (pfn = start_pfn; pfn < end; pfn++) {
243 unsigned long mfn = pfn_to_mfn(pfn); 244 unsigned long mfn = pfn_to_mfn(pfn);
@@ -250,16 +251,14 @@ static void __init xen_set_identity_and_release_chunk(unsigned long start_pfn,
250 WARN(ret != 1, "Failed to release pfn %lx err=%d\n", pfn, ret); 251 WARN(ret != 1, "Failed to release pfn %lx err=%d\n", pfn, ret);
251 252
252 if (ret == 1) { 253 if (ret == 1) {
254 (*released)++;
253 if (!__set_phys_to_machine(pfn, INVALID_P2M_ENTRY)) 255 if (!__set_phys_to_machine(pfn, INVALID_P2M_ENTRY))
254 break; 256 break;
255 len++;
256 } else 257 } else
257 break; 258 break;
258 } 259 }
259 260
260 /* Need to release pages first */ 261 set_phys_range_identity(start_pfn, end_pfn);
261 *released += len;
262 *identity += set_phys_range_identity(start_pfn, end_pfn);
263} 262}
264 263
265/* 264/*
@@ -287,7 +286,7 @@ static void __init xen_update_mem_tables(unsigned long pfn, unsigned long mfn)
287 } 286 }
288 287
289 /* Update kernel mapping, but not for highmem. */ 288 /* Update kernel mapping, but not for highmem. */
290 if ((pfn << PAGE_SHIFT) >= __pa(high_memory)) 289 if (pfn >= PFN_UP(__pa(high_memory - 1)))
291 return; 290 return;
292 291
293 if (HYPERVISOR_update_va_mapping((unsigned long)__va(pfn << PAGE_SHIFT), 292 if (HYPERVISOR_update_va_mapping((unsigned long)__va(pfn << PAGE_SHIFT),
@@ -318,7 +317,6 @@ static void __init xen_do_set_identity_and_remap_chunk(
318 unsigned long ident_pfn_iter, remap_pfn_iter; 317 unsigned long ident_pfn_iter, remap_pfn_iter;
319 unsigned long ident_end_pfn = start_pfn + size; 318 unsigned long ident_end_pfn = start_pfn + size;
320 unsigned long left = size; 319 unsigned long left = size;
321 unsigned long ident_cnt = 0;
322 unsigned int i, chunk; 320 unsigned int i, chunk;
323 321
324 WARN_ON(size == 0); 322 WARN_ON(size == 0);
@@ -347,8 +345,7 @@ static void __init xen_do_set_identity_and_remap_chunk(
347 xen_remap_mfn = mfn; 345 xen_remap_mfn = mfn;
348 346
349 /* Set identity map */ 347 /* Set identity map */
350 ident_cnt += set_phys_range_identity(ident_pfn_iter, 348 set_phys_range_identity(ident_pfn_iter, ident_pfn_iter + chunk);
351 ident_pfn_iter + chunk);
352 349
353 left -= chunk; 350 left -= chunk;
354 } 351 }
@@ -371,7 +368,7 @@ static void __init xen_do_set_identity_and_remap_chunk(
371static unsigned long __init xen_set_identity_and_remap_chunk( 368static unsigned long __init xen_set_identity_and_remap_chunk(
372 const struct e820entry *list, size_t map_size, unsigned long start_pfn, 369 const struct e820entry *list, size_t map_size, unsigned long start_pfn,
373 unsigned long end_pfn, unsigned long nr_pages, unsigned long remap_pfn, 370 unsigned long end_pfn, unsigned long nr_pages, unsigned long remap_pfn,
374 unsigned long *identity, unsigned long *released) 371 unsigned long *released, unsigned long *remapped)
375{ 372{
376 unsigned long pfn; 373 unsigned long pfn;
377 unsigned long i = 0; 374 unsigned long i = 0;
@@ -386,8 +383,7 @@ static unsigned long __init xen_set_identity_and_remap_chunk(
386 /* Do not remap pages beyond the current allocation */ 383 /* Do not remap pages beyond the current allocation */
387 if (cur_pfn >= nr_pages) { 384 if (cur_pfn >= nr_pages) {
388 /* Identity map remaining pages */ 385 /* Identity map remaining pages */
389 *identity += set_phys_range_identity(cur_pfn, 386 set_phys_range_identity(cur_pfn, cur_pfn + size);
390 cur_pfn + size);
391 break; 387 break;
392 } 388 }
393 if (cur_pfn + size > nr_pages) 389 if (cur_pfn + size > nr_pages)
@@ -398,7 +394,7 @@ static unsigned long __init xen_set_identity_and_remap_chunk(
398 if (!remap_range_size) { 394 if (!remap_range_size) {
399 pr_warning("Unable to find available pfn range, not remapping identity pages\n"); 395 pr_warning("Unable to find available pfn range, not remapping identity pages\n");
400 xen_set_identity_and_release_chunk(cur_pfn, 396 xen_set_identity_and_release_chunk(cur_pfn,
401 cur_pfn + left, nr_pages, identity, released); 397 cur_pfn + left, nr_pages, released);
402 break; 398 break;
403 } 399 }
404 /* Adjust size to fit in current e820 RAM region */ 400 /* Adjust size to fit in current e820 RAM region */
@@ -410,7 +406,7 @@ static unsigned long __init xen_set_identity_and_remap_chunk(
410 /* Update variables to reflect new mappings. */ 406 /* Update variables to reflect new mappings. */
411 i += size; 407 i += size;
412 remap_pfn += size; 408 remap_pfn += size;
413 *identity += size; 409 *remapped += size;
414 } 410 }
415 411
416 /* 412 /*
@@ -427,13 +423,13 @@ static unsigned long __init xen_set_identity_and_remap_chunk(
427 423
428static void __init xen_set_identity_and_remap( 424static void __init xen_set_identity_and_remap(
429 const struct e820entry *list, size_t map_size, unsigned long nr_pages, 425 const struct e820entry *list, size_t map_size, unsigned long nr_pages,
430 unsigned long *released) 426 unsigned long *released, unsigned long *remapped)
431{ 427{
432 phys_addr_t start = 0; 428 phys_addr_t start = 0;
433 unsigned long identity = 0;
434 unsigned long last_pfn = nr_pages; 429 unsigned long last_pfn = nr_pages;
435 const struct e820entry *entry; 430 const struct e820entry *entry;
436 unsigned long num_released = 0; 431 unsigned long num_released = 0;
432 unsigned long num_remapped = 0;
437 int i; 433 int i;
438 434
439 /* 435 /*
@@ -460,14 +456,14 @@ static void __init xen_set_identity_and_remap(
460 last_pfn = xen_set_identity_and_remap_chunk( 456 last_pfn = xen_set_identity_and_remap_chunk(
461 list, map_size, start_pfn, 457 list, map_size, start_pfn,
462 end_pfn, nr_pages, last_pfn, 458 end_pfn, nr_pages, last_pfn,
463 &identity, &num_released); 459 &num_released, &num_remapped);
464 start = end; 460 start = end;
465 } 461 }
466 } 462 }
467 463
468 *released = num_released; 464 *released = num_released;
465 *remapped = num_remapped;
469 466
470 pr_info("Set %ld page(s) to 1-1 mapping\n", identity);
471 pr_info("Released %ld page(s)\n", num_released); 467 pr_info("Released %ld page(s)\n", num_released);
472} 468}
473 469
@@ -586,6 +582,7 @@ char * __init xen_memory_setup(void)
586 struct xen_memory_map memmap; 582 struct xen_memory_map memmap;
587 unsigned long max_pages; 583 unsigned long max_pages;
588 unsigned long extra_pages = 0; 584 unsigned long extra_pages = 0;
585 unsigned long remapped_pages;
589 int i; 586 int i;
590 int op; 587 int op;
591 588
@@ -635,9 +632,10 @@ char * __init xen_memory_setup(void)
635 * underlying RAM. 632 * underlying RAM.
636 */ 633 */
637 xen_set_identity_and_remap(map, memmap.nr_entries, max_pfn, 634 xen_set_identity_and_remap(map, memmap.nr_entries, max_pfn,
638 &xen_released_pages); 635 &xen_released_pages, &remapped_pages);
639 636
640 extra_pages += xen_released_pages; 637 extra_pages += xen_released_pages;
638 extra_pages += remapped_pages;
641 639
642 /* 640 /*
643 * Clamp the amount of extra memory to a EXTRA_MEM_RATIO 641 * Clamp the amount of extra memory to a EXTRA_MEM_RATIO
diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
index f473d268d387..69087341d9ae 100644
--- a/arch/x86/xen/time.c
+++ b/arch/x86/xen/time.c
@@ -391,7 +391,7 @@ static const struct clock_event_device *xen_clockevent =
391 391
392struct xen_clock_event_device { 392struct xen_clock_event_device {
393 struct clock_event_device evt; 393 struct clock_event_device evt;
394 char *name; 394 char name[16];
395}; 395};
396static DEFINE_PER_CPU(struct xen_clock_event_device, xen_clock_events) = { .evt.irq = -1 }; 396static DEFINE_PER_CPU(struct xen_clock_event_device, xen_clock_events) = { .evt.irq = -1 };
397 397
@@ -420,46 +420,38 @@ void xen_teardown_timer(int cpu)
420 if (evt->irq >= 0) { 420 if (evt->irq >= 0) {
421 unbind_from_irqhandler(evt->irq, NULL); 421 unbind_from_irqhandler(evt->irq, NULL);
422 evt->irq = -1; 422 evt->irq = -1;
423 kfree(per_cpu(xen_clock_events, cpu).name);
424 per_cpu(xen_clock_events, cpu).name = NULL;
425 } 423 }
426} 424}
427 425
428void xen_setup_timer(int cpu) 426void xen_setup_timer(int cpu)
429{ 427{
430 char *name; 428 struct xen_clock_event_device *xevt = &per_cpu(xen_clock_events, cpu);
431 struct clock_event_device *evt; 429 struct clock_event_device *evt = &xevt->evt;
432 int irq; 430 int irq;
433 431
434 evt = &per_cpu(xen_clock_events, cpu).evt;
435 WARN(evt->irq >= 0, "IRQ%d for CPU%d is already allocated\n", evt->irq, cpu); 432 WARN(evt->irq >= 0, "IRQ%d for CPU%d is already allocated\n", evt->irq, cpu);
436 if (evt->irq >= 0) 433 if (evt->irq >= 0)
437 xen_teardown_timer(cpu); 434 xen_teardown_timer(cpu);
438 435
439 printk(KERN_INFO "installing Xen timer for CPU %d\n", cpu); 436 printk(KERN_INFO "installing Xen timer for CPU %d\n", cpu);
440 437
441 name = kasprintf(GFP_KERNEL, "timer%d", cpu); 438 snprintf(xevt->name, sizeof(xevt->name), "timer%d", cpu);
442 if (!name)
443 name = "<timer kasprintf failed>";
444 439
445 irq = bind_virq_to_irqhandler(VIRQ_TIMER, cpu, xen_timer_interrupt, 440 irq = bind_virq_to_irqhandler(VIRQ_TIMER, cpu, xen_timer_interrupt,
446 IRQF_PERCPU|IRQF_NOBALANCING|IRQF_TIMER| 441 IRQF_PERCPU|IRQF_NOBALANCING|IRQF_TIMER|
447 IRQF_FORCE_RESUME|IRQF_EARLY_RESUME, 442 IRQF_FORCE_RESUME|IRQF_EARLY_RESUME,
448 name, NULL); 443 xevt->name, NULL);
449 (void)xen_set_irq_priority(irq, XEN_IRQ_PRIORITY_MAX); 444 (void)xen_set_irq_priority(irq, XEN_IRQ_PRIORITY_MAX);
450 445
451 memcpy(evt, xen_clockevent, sizeof(*evt)); 446 memcpy(evt, xen_clockevent, sizeof(*evt));
452 447
453 evt->cpumask = cpumask_of(cpu); 448 evt->cpumask = cpumask_of(cpu);
454 evt->irq = irq; 449 evt->irq = irq;
455 per_cpu(xen_clock_events, cpu).name = name;
456} 450}
457 451
458 452
459void xen_setup_cpu_clockevents(void) 453void xen_setup_cpu_clockevents(void)
460{ 454{
461 BUG_ON(preemptible());
462
463 clockevents_register_device(this_cpu_ptr(&xen_clock_events.evt)); 455 clockevents_register_device(this_cpu_ptr(&xen_clock_events.evt));
464} 456}
465 457
diff --git a/block/blk-core.c b/block/blk-core.c
index 30f6153a40c2..3ad405571dcc 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -473,6 +473,25 @@ void blk_queue_bypass_end(struct request_queue *q)
473} 473}
474EXPORT_SYMBOL_GPL(blk_queue_bypass_end); 474EXPORT_SYMBOL_GPL(blk_queue_bypass_end);
475 475
476void blk_set_queue_dying(struct request_queue *q)
477{
478 queue_flag_set_unlocked(QUEUE_FLAG_DYING, q);
479
480 if (q->mq_ops)
481 blk_mq_wake_waiters(q);
482 else {
483 struct request_list *rl;
484
485 blk_queue_for_each_rl(rl, q) {
486 if (rl->rq_pool) {
487 wake_up(&rl->wait[BLK_RW_SYNC]);
488 wake_up(&rl->wait[BLK_RW_ASYNC]);
489 }
490 }
491 }
492}
493EXPORT_SYMBOL_GPL(blk_set_queue_dying);
494
476/** 495/**
477 * blk_cleanup_queue - shutdown a request queue 496 * blk_cleanup_queue - shutdown a request queue
478 * @q: request queue to shutdown 497 * @q: request queue to shutdown
@@ -486,7 +505,7 @@ void blk_cleanup_queue(struct request_queue *q)
486 505
487 /* mark @q DYING, no new request or merges will be allowed afterwards */ 506 /* mark @q DYING, no new request or merges will be allowed afterwards */
488 mutex_lock(&q->sysfs_lock); 507 mutex_lock(&q->sysfs_lock);
489 queue_flag_set_unlocked(QUEUE_FLAG_DYING, q); 508 blk_set_queue_dying(q);
490 spin_lock_irq(lock); 509 spin_lock_irq(lock);
491 510
492 /* 511 /*
diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c
index 32e8dbb9ad1c..60c9d4a93fe4 100644
--- a/block/blk-mq-tag.c
+++ b/block/blk-mq-tag.c
@@ -68,9 +68,9 @@ bool __blk_mq_tag_busy(struct blk_mq_hw_ctx *hctx)
68} 68}
69 69
70/* 70/*
71 * Wakeup all potentially sleeping on normal (non-reserved) tags 71 * Wakeup all potentially sleeping on tags
72 */ 72 */
73static void blk_mq_tag_wakeup_all(struct blk_mq_tags *tags) 73void blk_mq_tag_wakeup_all(struct blk_mq_tags *tags, bool include_reserve)
74{ 74{
75 struct blk_mq_bitmap_tags *bt; 75 struct blk_mq_bitmap_tags *bt;
76 int i, wake_index; 76 int i, wake_index;
@@ -85,6 +85,12 @@ static void blk_mq_tag_wakeup_all(struct blk_mq_tags *tags)
85 85
86 wake_index = bt_index_inc(wake_index); 86 wake_index = bt_index_inc(wake_index);
87 } 87 }
88
89 if (include_reserve) {
90 bt = &tags->breserved_tags;
91 if (waitqueue_active(&bt->bs[0].wait))
92 wake_up(&bt->bs[0].wait);
93 }
88} 94}
89 95
90/* 96/*
@@ -100,7 +106,7 @@ void __blk_mq_tag_idle(struct blk_mq_hw_ctx *hctx)
100 106
101 atomic_dec(&tags->active_queues); 107 atomic_dec(&tags->active_queues);
102 108
103 blk_mq_tag_wakeup_all(tags); 109 blk_mq_tag_wakeup_all(tags, false);
104} 110}
105 111
106/* 112/*
@@ -584,7 +590,7 @@ int blk_mq_tag_update_depth(struct blk_mq_tags *tags, unsigned int tdepth)
584 * static and should never need resizing. 590 * static and should never need resizing.
585 */ 591 */
586 bt_update_count(&tags->bitmap_tags, tdepth); 592 bt_update_count(&tags->bitmap_tags, tdepth);
587 blk_mq_tag_wakeup_all(tags); 593 blk_mq_tag_wakeup_all(tags, false);
588 return 0; 594 return 0;
589} 595}
590 596
diff --git a/block/blk-mq-tag.h b/block/blk-mq-tag.h
index 6206ed17ef76..a6fa0fc9d41a 100644
--- a/block/blk-mq-tag.h
+++ b/block/blk-mq-tag.h
@@ -54,6 +54,7 @@ extern bool blk_mq_has_free_tags(struct blk_mq_tags *tags);
54extern ssize_t blk_mq_tag_sysfs_show(struct blk_mq_tags *tags, char *page); 54extern ssize_t blk_mq_tag_sysfs_show(struct blk_mq_tags *tags, char *page);
55extern void blk_mq_tag_init_last_tag(struct blk_mq_tags *tags, unsigned int *last_tag); 55extern void blk_mq_tag_init_last_tag(struct blk_mq_tags *tags, unsigned int *last_tag);
56extern int blk_mq_tag_update_depth(struct blk_mq_tags *tags, unsigned int depth); 56extern int blk_mq_tag_update_depth(struct blk_mq_tags *tags, unsigned int depth);
57extern void blk_mq_tag_wakeup_all(struct blk_mq_tags *tags, bool);
57 58
58enum { 59enum {
59 BLK_MQ_TAG_CACHE_MIN = 1, 60 BLK_MQ_TAG_CACHE_MIN = 1,
diff --git a/block/blk-mq.c b/block/blk-mq.c
index da1ab5641227..2f95747c287e 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -107,7 +107,7 @@ static void blk_mq_usage_counter_release(struct percpu_ref *ref)
107 wake_up_all(&q->mq_freeze_wq); 107 wake_up_all(&q->mq_freeze_wq);
108} 108}
109 109
110static void blk_mq_freeze_queue_start(struct request_queue *q) 110void blk_mq_freeze_queue_start(struct request_queue *q)
111{ 111{
112 bool freeze; 112 bool freeze;
113 113
@@ -120,6 +120,7 @@ static void blk_mq_freeze_queue_start(struct request_queue *q)
120 blk_mq_run_queues(q, false); 120 blk_mq_run_queues(q, false);
121 } 121 }
122} 122}
123EXPORT_SYMBOL_GPL(blk_mq_freeze_queue_start);
123 124
124static void blk_mq_freeze_queue_wait(struct request_queue *q) 125static void blk_mq_freeze_queue_wait(struct request_queue *q)
125{ 126{
@@ -136,7 +137,7 @@ void blk_mq_freeze_queue(struct request_queue *q)
136 blk_mq_freeze_queue_wait(q); 137 blk_mq_freeze_queue_wait(q);
137} 138}
138 139
139static void blk_mq_unfreeze_queue(struct request_queue *q) 140void blk_mq_unfreeze_queue(struct request_queue *q)
140{ 141{
141 bool wake; 142 bool wake;
142 143
@@ -149,6 +150,24 @@ static void blk_mq_unfreeze_queue(struct request_queue *q)
149 wake_up_all(&q->mq_freeze_wq); 150 wake_up_all(&q->mq_freeze_wq);
150 } 151 }
151} 152}
153EXPORT_SYMBOL_GPL(blk_mq_unfreeze_queue);
154
155void blk_mq_wake_waiters(struct request_queue *q)
156{
157 struct blk_mq_hw_ctx *hctx;
158 unsigned int i;
159
160 queue_for_each_hw_ctx(q, hctx, i)
161 if (blk_mq_hw_queue_mapped(hctx))
162 blk_mq_tag_wakeup_all(hctx->tags, true);
163
164 /*
165 * If we are called because the queue has now been marked as
166 * dying, we need to ensure that processes currently waiting on
167 * the queue are notified as well.
168 */
169 wake_up_all(&q->mq_freeze_wq);
170}
152 171
153bool blk_mq_can_queue(struct blk_mq_hw_ctx *hctx) 172bool blk_mq_can_queue(struct blk_mq_hw_ctx *hctx)
154{ 173{
@@ -258,8 +277,10 @@ struct request *blk_mq_alloc_request(struct request_queue *q, int rw, gfp_t gfp,
258 ctx = alloc_data.ctx; 277 ctx = alloc_data.ctx;
259 } 278 }
260 blk_mq_put_ctx(ctx); 279 blk_mq_put_ctx(ctx);
261 if (!rq) 280 if (!rq) {
281 blk_mq_queue_exit(q);
262 return ERR_PTR(-EWOULDBLOCK); 282 return ERR_PTR(-EWOULDBLOCK);
283 }
263 return rq; 284 return rq;
264} 285}
265EXPORT_SYMBOL(blk_mq_alloc_request); 286EXPORT_SYMBOL(blk_mq_alloc_request);
@@ -383,6 +404,12 @@ void blk_mq_complete_request(struct request *rq)
383} 404}
384EXPORT_SYMBOL(blk_mq_complete_request); 405EXPORT_SYMBOL(blk_mq_complete_request);
385 406
407int blk_mq_request_started(struct request *rq)
408{
409 return test_bit(REQ_ATOM_STARTED, &rq->atomic_flags);
410}
411EXPORT_SYMBOL_GPL(blk_mq_request_started);
412
386void blk_mq_start_request(struct request *rq) 413void blk_mq_start_request(struct request *rq)
387{ 414{
388 struct request_queue *q = rq->q; 415 struct request_queue *q = rq->q;
@@ -500,12 +527,38 @@ void blk_mq_add_to_requeue_list(struct request *rq, bool at_head)
500} 527}
501EXPORT_SYMBOL(blk_mq_add_to_requeue_list); 528EXPORT_SYMBOL(blk_mq_add_to_requeue_list);
502 529
530void blk_mq_cancel_requeue_work(struct request_queue *q)
531{
532 cancel_work_sync(&q->requeue_work);
533}
534EXPORT_SYMBOL_GPL(blk_mq_cancel_requeue_work);
535
503void blk_mq_kick_requeue_list(struct request_queue *q) 536void blk_mq_kick_requeue_list(struct request_queue *q)
504{ 537{
505 kblockd_schedule_work(&q->requeue_work); 538 kblockd_schedule_work(&q->requeue_work);
506} 539}
507EXPORT_SYMBOL(blk_mq_kick_requeue_list); 540EXPORT_SYMBOL(blk_mq_kick_requeue_list);
508 541
542void blk_mq_abort_requeue_list(struct request_queue *q)
543{
544 unsigned long flags;
545 LIST_HEAD(rq_list);
546
547 spin_lock_irqsave(&q->requeue_lock, flags);
548 list_splice_init(&q->requeue_list, &rq_list);
549 spin_unlock_irqrestore(&q->requeue_lock, flags);
550
551 while (!list_empty(&rq_list)) {
552 struct request *rq;
553
554 rq = list_first_entry(&rq_list, struct request, queuelist);
555 list_del_init(&rq->queuelist);
556 rq->errors = -EIO;
557 blk_mq_end_request(rq, rq->errors);
558 }
559}
560EXPORT_SYMBOL(blk_mq_abort_requeue_list);
561
509static inline bool is_flush_request(struct request *rq, 562static inline bool is_flush_request(struct request *rq,
510 struct blk_flush_queue *fq, unsigned int tag) 563 struct blk_flush_queue *fq, unsigned int tag)
511{ 564{
@@ -566,13 +619,24 @@ void blk_mq_rq_timed_out(struct request *req, bool reserved)
566 break; 619 break;
567 } 620 }
568} 621}
569 622
570static void blk_mq_check_expired(struct blk_mq_hw_ctx *hctx, 623static void blk_mq_check_expired(struct blk_mq_hw_ctx *hctx,
571 struct request *rq, void *priv, bool reserved) 624 struct request *rq, void *priv, bool reserved)
572{ 625{
573 struct blk_mq_timeout_data *data = priv; 626 struct blk_mq_timeout_data *data = priv;
574 627
575 if (!test_bit(REQ_ATOM_STARTED, &rq->atomic_flags)) 628 if (!test_bit(REQ_ATOM_STARTED, &rq->atomic_flags)) {
629 /*
630 * If a request wasn't started before the queue was
631 * marked dying, kill it here or it'll go unnoticed.
632 */
633 if (unlikely(blk_queue_dying(rq->q))) {
634 rq->errors = -EIO;
635 blk_mq_complete_request(rq);
636 }
637 return;
638 }
639 if (rq->cmd_flags & REQ_NO_TIMEOUT)
576 return; 640 return;
577 641
578 if (time_after_eq(jiffies, rq->deadline)) { 642 if (time_after_eq(jiffies, rq->deadline)) {
@@ -1601,7 +1665,6 @@ static int blk_mq_init_hctx(struct request_queue *q,
1601 hctx->queue = q; 1665 hctx->queue = q;
1602 hctx->queue_num = hctx_idx; 1666 hctx->queue_num = hctx_idx;
1603 hctx->flags = set->flags; 1667 hctx->flags = set->flags;
1604 hctx->cmd_size = set->cmd_size;
1605 1668
1606 blk_mq_init_cpu_notifier(&hctx->cpu_notifier, 1669 blk_mq_init_cpu_notifier(&hctx->cpu_notifier,
1607 blk_mq_hctx_notify, hctx); 1670 blk_mq_hctx_notify, hctx);
diff --git a/block/blk-mq.h b/block/blk-mq.h
index 206230e64f79..4f4f943c22c3 100644
--- a/block/blk-mq.h
+++ b/block/blk-mq.h
@@ -32,6 +32,7 @@ void blk_mq_free_queue(struct request_queue *q);
32void blk_mq_clone_flush_request(struct request *flush_rq, 32void blk_mq_clone_flush_request(struct request *flush_rq,
33 struct request *orig_rq); 33 struct request *orig_rq);
34int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr); 34int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr);
35void blk_mq_wake_waiters(struct request_queue *q);
35 36
36/* 37/*
37 * CPU hotplug helpers 38 * CPU hotplug helpers
diff --git a/block/blk-timeout.c b/block/blk-timeout.c
index 56c025894cdf..246dfb16c3d9 100644
--- a/block/blk-timeout.c
+++ b/block/blk-timeout.c
@@ -190,6 +190,9 @@ void blk_add_timer(struct request *req)
190 struct request_queue *q = req->q; 190 struct request_queue *q = req->q;
191 unsigned long expiry; 191 unsigned long expiry;
192 192
193 if (req->cmd_flags & REQ_NO_TIMEOUT)
194 return;
195
193 /* blk-mq has its own handler, so we don't need ->rq_timed_out_fn */ 196 /* blk-mq has its own handler, so we don't need ->rq_timed_out_fn */
194 if (!q->mq_ops && !q->rq_timed_out_fn) 197 if (!q->mq_ops && !q->rq_timed_out_fn)
195 return; 198 return;
diff --git a/drivers/Makefile b/drivers/Makefile
index 67d2334dc41e..527a6da8d539 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -50,7 +50,10 @@ obj-$(CONFIG_RESET_CONTROLLER) += reset/
50obj-y += tty/ 50obj-y += tty/
51obj-y += char/ 51obj-y += char/
52 52
53# gpu/ comes after char for AGP vs DRM startup 53# iommu/ comes before gpu as gpu are using iommu controllers
54obj-$(CONFIG_IOMMU_SUPPORT) += iommu/
55
56# gpu/ comes after char for AGP vs DRM startup and after iommu
54obj-y += gpu/ 57obj-y += gpu/
55 58
56obj-$(CONFIG_CONNECTOR) += connector/ 59obj-$(CONFIG_CONNECTOR) += connector/
@@ -141,7 +144,6 @@ obj-y += clk/
141 144
142obj-$(CONFIG_MAILBOX) += mailbox/ 145obj-$(CONFIG_MAILBOX) += mailbox/
143obj-$(CONFIG_HWSPINLOCK) += hwspinlock/ 146obj-$(CONFIG_HWSPINLOCK) += hwspinlock/
144obj-$(CONFIG_IOMMU_SUPPORT) += iommu/
145obj-$(CONFIG_REMOTEPROC) += remoteproc/ 147obj-$(CONFIG_REMOTEPROC) += remoteproc/
146obj-$(CONFIG_RPMSG) += rpmsg/ 148obj-$(CONFIG_RPMSG) += rpmsg/
147 149
diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c
index 1fdf5e07a1c7..1020b1b53a17 100644
--- a/drivers/acpi/acpi_processor.c
+++ b/drivers/acpi/acpi_processor.c
@@ -170,7 +170,7 @@ static int acpi_processor_hotadd_init(struct acpi_processor *pr)
170 acpi_status status; 170 acpi_status status;
171 int ret; 171 int ret;
172 172
173 if (pr->apic_id == -1) 173 if (pr->phys_id == -1)
174 return -ENODEV; 174 return -ENODEV;
175 175
176 status = acpi_evaluate_integer(pr->handle, "_STA", NULL, &sta); 176 status = acpi_evaluate_integer(pr->handle, "_STA", NULL, &sta);
@@ -180,13 +180,13 @@ static int acpi_processor_hotadd_init(struct acpi_processor *pr)
180 cpu_maps_update_begin(); 180 cpu_maps_update_begin();
181 cpu_hotplug_begin(); 181 cpu_hotplug_begin();
182 182
183 ret = acpi_map_lsapic(pr->handle, pr->apic_id, &pr->id); 183 ret = acpi_map_cpu(pr->handle, pr->phys_id, &pr->id);
184 if (ret) 184 if (ret)
185 goto out; 185 goto out;
186 186
187 ret = arch_register_cpu(pr->id); 187 ret = arch_register_cpu(pr->id);
188 if (ret) { 188 if (ret) {
189 acpi_unmap_lsapic(pr->id); 189 acpi_unmap_cpu(pr->id);
190 goto out; 190 goto out;
191 } 191 }
192 192
@@ -215,7 +215,7 @@ static int acpi_processor_get_info(struct acpi_device *device)
215 union acpi_object object = { 0 }; 215 union acpi_object object = { 0 };
216 struct acpi_buffer buffer = { sizeof(union acpi_object), &object }; 216 struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
217 struct acpi_processor *pr = acpi_driver_data(device); 217 struct acpi_processor *pr = acpi_driver_data(device);
218 int apic_id, cpu_index, device_declaration = 0; 218 int phys_id, cpu_index, device_declaration = 0;
219 acpi_status status = AE_OK; 219 acpi_status status = AE_OK;
220 static int cpu0_initialized; 220 static int cpu0_initialized;
221 unsigned long long value; 221 unsigned long long value;
@@ -262,15 +262,18 @@ static int acpi_processor_get_info(struct acpi_device *device)
262 pr->acpi_id = value; 262 pr->acpi_id = value;
263 } 263 }
264 264
265 apic_id = acpi_get_apicid(pr->handle, device_declaration, pr->acpi_id); 265 phys_id = acpi_get_phys_id(pr->handle, device_declaration, pr->acpi_id);
266 if (apic_id < 0) 266 if (phys_id < 0)
267 acpi_handle_debug(pr->handle, "failed to get CPU APIC ID.\n"); 267 acpi_handle_debug(pr->handle, "failed to get CPU physical ID.\n");
268 pr->apic_id = apic_id; 268 pr->phys_id = phys_id;
269 269
270 cpu_index = acpi_map_cpuid(pr->apic_id, pr->acpi_id); 270 cpu_index = acpi_map_cpuid(pr->phys_id, pr->acpi_id);
271 if (!cpu0_initialized && !acpi_has_cpu_in_madt()) { 271 if (!cpu0_initialized && !acpi_has_cpu_in_madt()) {
272 cpu0_initialized = 1; 272 cpu0_initialized = 1;
273 /* Handle UP system running SMP kernel, with no LAPIC in MADT */ 273 /*
274 * Handle UP system running SMP kernel, with no CPU
275 * entry in MADT
276 */
274 if ((cpu_index == -1) && (num_online_cpus() == 1)) 277 if ((cpu_index == -1) && (num_online_cpus() == 1))
275 cpu_index = 0; 278 cpu_index = 0;
276 } 279 }
@@ -458,7 +461,7 @@ static void acpi_processor_remove(struct acpi_device *device)
458 461
459 /* Remove the CPU. */ 462 /* Remove the CPU. */
460 arch_unregister_cpu(pr->id); 463 arch_unregister_cpu(pr->id);
461 acpi_unmap_lsapic(pr->id); 464 acpi_unmap_cpu(pr->id);
462 465
463 cpu_hotplug_done(); 466 cpu_hotplug_done();
464 cpu_maps_update_done(); 467 cpu_maps_update_done();
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index c2daa85fc9f7..c0d44d394ca3 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -257,7 +257,7 @@ int acpi_bus_init_power(struct acpi_device *device)
257 257
258 device->power.state = ACPI_STATE_UNKNOWN; 258 device->power.state = ACPI_STATE_UNKNOWN;
259 if (!acpi_device_is_present(device)) 259 if (!acpi_device_is_present(device))
260 return 0; 260 return -ENXIO;
261 261
262 result = acpi_device_get_power(device, &state); 262 result = acpi_device_get_power(device, &state);
263 if (result) 263 if (result)
diff --git a/drivers/acpi/int340x_thermal.c b/drivers/acpi/int340x_thermal.c
index a27d31d1ba24..9dcf83682e36 100644
--- a/drivers/acpi/int340x_thermal.c
+++ b/drivers/acpi/int340x_thermal.c
@@ -14,10 +14,10 @@
14 14
15#include "internal.h" 15#include "internal.h"
16 16
17#define DO_ENUMERATION 0x01 17#define INT3401_DEVICE 0X01
18static const struct acpi_device_id int340x_thermal_device_ids[] = { 18static const struct acpi_device_id int340x_thermal_device_ids[] = {
19 {"INT3400", DO_ENUMERATION }, 19 {"INT3400"},
20 {"INT3401"}, 20 {"INT3401", INT3401_DEVICE},
21 {"INT3402"}, 21 {"INT3402"},
22 {"INT3403"}, 22 {"INT3403"},
23 {"INT3404"}, 23 {"INT3404"},
@@ -34,7 +34,10 @@ static int int340x_thermal_handler_attach(struct acpi_device *adev,
34 const struct acpi_device_id *id) 34 const struct acpi_device_id *id)
35{ 35{
36#if defined(CONFIG_INT340X_THERMAL) || defined(CONFIG_INT340X_THERMAL_MODULE) 36#if defined(CONFIG_INT340X_THERMAL) || defined(CONFIG_INT340X_THERMAL_MODULE)
37 if (id->driver_data == DO_ENUMERATION) 37 acpi_create_platform_device(adev);
38#elif defined(INTEL_SOC_DTS_THERMAL) || defined(INTEL_SOC_DTS_THERMAL_MODULE)
39 /* Intel SoC DTS thermal driver needs INT3401 to set IRQ descriptor */
40 if (id->driver_data == INT3401_DEVICE)
38 acpi_create_platform_device(adev); 41 acpi_create_platform_device(adev);
39#endif 42#endif
40 return 1; 43 return 1;
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index 342942f90a10..02e48394276c 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -69,7 +69,7 @@ static int map_madt_entry(int type, u32 acpi_id)
69 unsigned long madt_end, entry; 69 unsigned long madt_end, entry;
70 static struct acpi_table_madt *madt; 70 static struct acpi_table_madt *madt;
71 static int read_madt; 71 static int read_madt;
72 int apic_id = -1; 72 int phys_id = -1; /* CPU hardware ID */
73 73
74 if (!read_madt) { 74 if (!read_madt) {
75 if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_MADT, 0, 75 if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_MADT, 0,
@@ -79,7 +79,7 @@ static int map_madt_entry(int type, u32 acpi_id)
79 } 79 }
80 80
81 if (!madt) 81 if (!madt)
82 return apic_id; 82 return phys_id;
83 83
84 entry = (unsigned long)madt; 84 entry = (unsigned long)madt;
85 madt_end = entry + madt->header.length; 85 madt_end = entry + madt->header.length;
@@ -91,18 +91,18 @@ static int map_madt_entry(int type, u32 acpi_id)
91 struct acpi_subtable_header *header = 91 struct acpi_subtable_header *header =
92 (struct acpi_subtable_header *)entry; 92 (struct acpi_subtable_header *)entry;
93 if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) { 93 if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
94 if (!map_lapic_id(header, acpi_id, &apic_id)) 94 if (!map_lapic_id(header, acpi_id, &phys_id))
95 break; 95 break;
96 } else if (header->type == ACPI_MADT_TYPE_LOCAL_X2APIC) { 96 } else if (header->type == ACPI_MADT_TYPE_LOCAL_X2APIC) {
97 if (!map_x2apic_id(header, type, acpi_id, &apic_id)) 97 if (!map_x2apic_id(header, type, acpi_id, &phys_id))
98 break; 98 break;
99 } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) { 99 } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
100 if (!map_lsapic_id(header, type, acpi_id, &apic_id)) 100 if (!map_lsapic_id(header, type, acpi_id, &phys_id))
101 break; 101 break;
102 } 102 }
103 entry += header->length; 103 entry += header->length;
104 } 104 }
105 return apic_id; 105 return phys_id;
106} 106}
107 107
108static int map_mat_entry(acpi_handle handle, int type, u32 acpi_id) 108static int map_mat_entry(acpi_handle handle, int type, u32 acpi_id)
@@ -110,7 +110,7 @@ static int map_mat_entry(acpi_handle handle, int type, u32 acpi_id)
110 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 110 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
111 union acpi_object *obj; 111 union acpi_object *obj;
112 struct acpi_subtable_header *header; 112 struct acpi_subtable_header *header;
113 int apic_id = -1; 113 int phys_id = -1;
114 114
115 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer))) 115 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
116 goto exit; 116 goto exit;
@@ -126,38 +126,38 @@ static int map_mat_entry(acpi_handle handle, int type, u32 acpi_id)
126 126
127 header = (struct acpi_subtable_header *)obj->buffer.pointer; 127 header = (struct acpi_subtable_header *)obj->buffer.pointer;
128 if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) 128 if (header->type == ACPI_MADT_TYPE_LOCAL_APIC)
129 map_lapic_id(header, acpi_id, &apic_id); 129 map_lapic_id(header, acpi_id, &phys_id);
130 else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) 130 else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC)
131 map_lsapic_id(header, type, acpi_id, &apic_id); 131 map_lsapic_id(header, type, acpi_id, &phys_id);
132 else if (header->type == ACPI_MADT_TYPE_LOCAL_X2APIC) 132 else if (header->type == ACPI_MADT_TYPE_LOCAL_X2APIC)
133 map_x2apic_id(header, type, acpi_id, &apic_id); 133 map_x2apic_id(header, type, acpi_id, &phys_id);
134 134
135exit: 135exit:
136 kfree(buffer.pointer); 136 kfree(buffer.pointer);
137 return apic_id; 137 return phys_id;
138} 138}
139 139
140int acpi_get_apicid(acpi_handle handle, int type, u32 acpi_id) 140int acpi_get_phys_id(acpi_handle handle, int type, u32 acpi_id)
141{ 141{
142 int apic_id; 142 int phys_id;
143 143
144 apic_id = map_mat_entry(handle, type, acpi_id); 144 phys_id = map_mat_entry(handle, type, acpi_id);
145 if (apic_id == -1) 145 if (phys_id == -1)
146 apic_id = map_madt_entry(type, acpi_id); 146 phys_id = map_madt_entry(type, acpi_id);
147 147
148 return apic_id; 148 return phys_id;
149} 149}
150 150
151int acpi_map_cpuid(int apic_id, u32 acpi_id) 151int acpi_map_cpuid(int phys_id, u32 acpi_id)
152{ 152{
153#ifdef CONFIG_SMP 153#ifdef CONFIG_SMP
154 int i; 154 int i;
155#endif 155#endif
156 156
157 if (apic_id == -1) { 157 if (phys_id == -1) {
158 /* 158 /*
159 * On UP processor, there is no _MAT or MADT table. 159 * On UP processor, there is no _MAT or MADT table.
160 * So above apic_id is always set to -1. 160 * So above phys_id is always set to -1.
161 * 161 *
162 * BIOS may define multiple CPU handles even for UP processor. 162 * BIOS may define multiple CPU handles even for UP processor.
163 * For example, 163 * For example,
@@ -170,7 +170,7 @@ int acpi_map_cpuid(int apic_id, u32 acpi_id)
170 * Processor (CPU3, 0x03, 0x00000410, 0x06) {} 170 * Processor (CPU3, 0x03, 0x00000410, 0x06) {}
171 * } 171 * }
172 * 172 *
173 * Ignores apic_id and always returns 0 for the processor 173 * Ignores phys_id and always returns 0 for the processor
174 * handle with acpi id 0 if nr_cpu_ids is 1. 174 * handle with acpi id 0 if nr_cpu_ids is 1.
175 * This should be the case if SMP tables are not found. 175 * This should be the case if SMP tables are not found.
176 * Return -1 for other CPU's handle. 176 * Return -1 for other CPU's handle.
@@ -178,28 +178,28 @@ int acpi_map_cpuid(int apic_id, u32 acpi_id)
178 if (nr_cpu_ids <= 1 && acpi_id == 0) 178 if (nr_cpu_ids <= 1 && acpi_id == 0)
179 return acpi_id; 179 return acpi_id;
180 else 180 else
181 return apic_id; 181 return phys_id;
182 } 182 }
183 183
184#ifdef CONFIG_SMP 184#ifdef CONFIG_SMP
185 for_each_possible_cpu(i) { 185 for_each_possible_cpu(i) {
186 if (cpu_physical_id(i) == apic_id) 186 if (cpu_physical_id(i) == phys_id)
187 return i; 187 return i;
188 } 188 }
189#else 189#else
190 /* In UP kernel, only processor 0 is valid */ 190 /* In UP kernel, only processor 0 is valid */
191 if (apic_id == 0) 191 if (phys_id == 0)
192 return apic_id; 192 return phys_id;
193#endif 193#endif
194 return -1; 194 return -1;
195} 195}
196 196
197int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id) 197int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id)
198{ 198{
199 int apic_id; 199 int phys_id;
200 200
201 apic_id = acpi_get_apicid(handle, type, acpi_id); 201 phys_id = acpi_get_phys_id(handle, type, acpi_id);
202 202
203 return acpi_map_cpuid(apic_id, acpi_id); 203 return acpi_map_cpuid(phys_id, acpi_id);
204} 204}
205EXPORT_SYMBOL_GPL(acpi_get_cpuid); 205EXPORT_SYMBOL_GPL(acpi_get_cpuid);
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 16914cc30882..dc4d8960684a 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1001,7 +1001,7 @@ static void acpi_free_power_resources_lists(struct acpi_device *device)
1001 if (device->wakeup.flags.valid) 1001 if (device->wakeup.flags.valid)
1002 acpi_power_resources_list_free(&device->wakeup.resources); 1002 acpi_power_resources_list_free(&device->wakeup.resources);
1003 1003
1004 if (!device->flags.power_manageable) 1004 if (!device->power.flags.power_resources)
1005 return; 1005 return;
1006 1006
1007 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) { 1007 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) {
@@ -1744,10 +1744,8 @@ static void acpi_bus_get_power_flags(struct acpi_device *device)
1744 device->power.flags.power_resources) 1744 device->power.flags.power_resources)
1745 device->power.states[ACPI_STATE_D3_COLD].flags.os_accessible = 1; 1745 device->power.states[ACPI_STATE_D3_COLD].flags.os_accessible = 1;
1746 1746
1747 if (acpi_bus_init_power(device)) { 1747 if (acpi_bus_init_power(device))
1748 acpi_free_power_resources_lists(device);
1749 device->flags.power_manageable = 0; 1748 device->flags.power_manageable = 0;
1750 }
1751} 1749}
1752 1750
1753static void acpi_bus_get_flags(struct acpi_device *device) 1751static void acpi_bus_get_flags(struct acpi_device *device)
@@ -2371,13 +2369,18 @@ static void acpi_bus_attach(struct acpi_device *device)
2371 /* Skip devices that are not present. */ 2369 /* Skip devices that are not present. */
2372 if (!acpi_device_is_present(device)) { 2370 if (!acpi_device_is_present(device)) {
2373 device->flags.visited = false; 2371 device->flags.visited = false;
2372 device->flags.power_manageable = 0;
2374 return; 2373 return;
2375 } 2374 }
2376 if (device->handler) 2375 if (device->handler)
2377 goto ok; 2376 goto ok;
2378 2377
2379 if (!device->flags.initialized) { 2378 if (!device->flags.initialized) {
2380 acpi_bus_update_power(device, NULL); 2379 device->flags.power_manageable =
2380 device->power.states[ACPI_STATE_D0].flags.valid;
2381 if (acpi_bus_init_power(device))
2382 device->flags.power_manageable = 0;
2383
2381 device->flags.initialized = true; 2384 device->flags.initialized = true;
2382 } 2385 }
2383 device->flags.visited = false; 2386 device->flags.visited = false;
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index c72e79d2c5ad..032db459370f 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -522,6 +522,16 @@ static struct dmi_system_id video_dmi_table[] __initdata = {
522 DMI_MATCH(DMI_PRODUCT_NAME, "370R4E/370R4V/370R5E/3570RE/370R5V"), 522 DMI_MATCH(DMI_PRODUCT_NAME, "370R4E/370R4V/370R5E/3570RE/370R5V"),
523 }, 523 },
524 }, 524 },
525
526 {
527 /* https://bugzilla.redhat.com/show_bug.cgi?id=1163574 */
528 .callback = video_disable_native_backlight,
529 .ident = "Dell XPS15 L521X",
530 .matches = {
531 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
532 DMI_MATCH(DMI_PRODUCT_NAME, "XPS L521X"),
533 },
534 },
525 {} 535 {}
526}; 536};
527 537
diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
index ae9f615382f6..aa2224aa7caa 100644
--- a/drivers/block/null_blk.c
+++ b/drivers/block/null_blk.c
@@ -530,7 +530,7 @@ static int null_add_dev(void)
530 goto out_cleanup_queues; 530 goto out_cleanup_queues;
531 531
532 nullb->q = blk_mq_init_queue(&nullb->tag_set); 532 nullb->q = blk_mq_init_queue(&nullb->tag_set);
533 if (!nullb->q) { 533 if (IS_ERR(nullb->q)) {
534 rv = -ENOMEM; 534 rv = -ENOMEM;
535 goto out_cleanup_tags; 535 goto out_cleanup_tags;
536 } 536 }
diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
index b1d5d8797315..cb529e9a82dd 100644
--- a/drivers/block/nvme-core.c
+++ b/drivers/block/nvme-core.c
@@ -215,6 +215,7 @@ static void nvme_set_info(struct nvme_cmd_info *cmd, void *ctx,
215 cmd->fn = handler; 215 cmd->fn = handler;
216 cmd->ctx = ctx; 216 cmd->ctx = ctx;
217 cmd->aborted = 0; 217 cmd->aborted = 0;
218 blk_mq_start_request(blk_mq_rq_from_pdu(cmd));
218} 219}
219 220
220/* Special values must be less than 0x1000 */ 221/* Special values must be less than 0x1000 */
@@ -431,8 +432,13 @@ static void req_completion(struct nvme_queue *nvmeq, void *ctx,
431 if (unlikely(status)) { 432 if (unlikely(status)) {
432 if (!(status & NVME_SC_DNR || blk_noretry_request(req)) 433 if (!(status & NVME_SC_DNR || blk_noretry_request(req))
433 && (jiffies - req->start_time) < req->timeout) { 434 && (jiffies - req->start_time) < req->timeout) {
435 unsigned long flags;
436
434 blk_mq_requeue_request(req); 437 blk_mq_requeue_request(req);
435 blk_mq_kick_requeue_list(req->q); 438 spin_lock_irqsave(req->q->queue_lock, flags);
439 if (!blk_queue_stopped(req->q))
440 blk_mq_kick_requeue_list(req->q);
441 spin_unlock_irqrestore(req->q->queue_lock, flags);
436 return; 442 return;
437 } 443 }
438 req->errors = nvme_error_status(status); 444 req->errors = nvme_error_status(status);
@@ -664,8 +670,6 @@ static int nvme_queue_rq(struct blk_mq_hw_ctx *hctx,
664 } 670 }
665 } 671 }
666 672
667 blk_mq_start_request(req);
668
669 nvme_set_info(cmd, iod, req_completion); 673 nvme_set_info(cmd, iod, req_completion);
670 spin_lock_irq(&nvmeq->q_lock); 674 spin_lock_irq(&nvmeq->q_lock);
671 if (req->cmd_flags & REQ_DISCARD) 675 if (req->cmd_flags & REQ_DISCARD)
@@ -835,6 +839,7 @@ static int nvme_submit_async_admin_req(struct nvme_dev *dev)
835 if (IS_ERR(req)) 839 if (IS_ERR(req))
836 return PTR_ERR(req); 840 return PTR_ERR(req);
837 841
842 req->cmd_flags |= REQ_NO_TIMEOUT;
838 cmd_info = blk_mq_rq_to_pdu(req); 843 cmd_info = blk_mq_rq_to_pdu(req);
839 nvme_set_info(cmd_info, req, async_req_completion); 844 nvme_set_info(cmd_info, req, async_req_completion);
840 845
@@ -1016,14 +1021,19 @@ static void nvme_abort_req(struct request *req)
1016 struct nvme_command cmd; 1021 struct nvme_command cmd;
1017 1022
1018 if (!nvmeq->qid || cmd_rq->aborted) { 1023 if (!nvmeq->qid || cmd_rq->aborted) {
1024 unsigned long flags;
1025
1026 spin_lock_irqsave(&dev_list_lock, flags);
1019 if (work_busy(&dev->reset_work)) 1027 if (work_busy(&dev->reset_work))
1020 return; 1028 goto out;
1021 list_del_init(&dev->node); 1029 list_del_init(&dev->node);
1022 dev_warn(&dev->pci_dev->dev, 1030 dev_warn(&dev->pci_dev->dev,
1023 "I/O %d QID %d timeout, reset controller\n", 1031 "I/O %d QID %d timeout, reset controller\n",
1024 req->tag, nvmeq->qid); 1032 req->tag, nvmeq->qid);
1025 dev->reset_workfn = nvme_reset_failed_dev; 1033 dev->reset_workfn = nvme_reset_failed_dev;
1026 queue_work(nvme_workq, &dev->reset_work); 1034 queue_work(nvme_workq, &dev->reset_work);
1035 out:
1036 spin_unlock_irqrestore(&dev_list_lock, flags);
1027 return; 1037 return;
1028 } 1038 }
1029 1039
@@ -1064,15 +1074,22 @@ static void nvme_cancel_queue_ios(struct blk_mq_hw_ctx *hctx,
1064 void *ctx; 1074 void *ctx;
1065 nvme_completion_fn fn; 1075 nvme_completion_fn fn;
1066 struct nvme_cmd_info *cmd; 1076 struct nvme_cmd_info *cmd;
1067 static struct nvme_completion cqe = { 1077 struct nvme_completion cqe;
1068 .status = cpu_to_le16(NVME_SC_ABORT_REQ << 1), 1078
1069 }; 1079 if (!blk_mq_request_started(req))
1080 return;
1070 1081
1071 cmd = blk_mq_rq_to_pdu(req); 1082 cmd = blk_mq_rq_to_pdu(req);
1072 1083
1073 if (cmd->ctx == CMD_CTX_CANCELLED) 1084 if (cmd->ctx == CMD_CTX_CANCELLED)
1074 return; 1085 return;
1075 1086
1087 if (blk_queue_dying(req->q))
1088 cqe.status = cpu_to_le16((NVME_SC_ABORT_REQ | NVME_SC_DNR) << 1);
1089 else
1090 cqe.status = cpu_to_le16(NVME_SC_ABORT_REQ << 1);
1091
1092
1076 dev_warn(nvmeq->q_dmadev, "Cancelling I/O %d QID %d\n", 1093 dev_warn(nvmeq->q_dmadev, "Cancelling I/O %d QID %d\n",
1077 req->tag, nvmeq->qid); 1094 req->tag, nvmeq->qid);
1078 ctx = cancel_cmd_info(cmd, &fn); 1095 ctx = cancel_cmd_info(cmd, &fn);
@@ -1084,17 +1101,29 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
1084 struct nvme_cmd_info *cmd = blk_mq_rq_to_pdu(req); 1101 struct nvme_cmd_info *cmd = blk_mq_rq_to_pdu(req);
1085 struct nvme_queue *nvmeq = cmd->nvmeq; 1102 struct nvme_queue *nvmeq = cmd->nvmeq;
1086 1103
1087 dev_warn(nvmeq->q_dmadev, "Timeout I/O %d QID %d\n", req->tag,
1088 nvmeq->qid);
1089 if (nvmeq->dev->initialized)
1090 nvme_abort_req(req);
1091
1092 /* 1104 /*
1093 * The aborted req will be completed on receiving the abort req. 1105 * The aborted req will be completed on receiving the abort req.
1094 * We enable the timer again. If hit twice, it'll cause a device reset, 1106 * We enable the timer again. If hit twice, it'll cause a device reset,
1095 * as the device then is in a faulty state. 1107 * as the device then is in a faulty state.
1096 */ 1108 */
1097 return BLK_EH_RESET_TIMER; 1109 int ret = BLK_EH_RESET_TIMER;
1110
1111 dev_warn(nvmeq->q_dmadev, "Timeout I/O %d QID %d\n", req->tag,
1112 nvmeq->qid);
1113
1114 spin_lock_irq(&nvmeq->q_lock);
1115 if (!nvmeq->dev->initialized) {
1116 /*
1117 * Force cancelled command frees the request, which requires we
1118 * return BLK_EH_NOT_HANDLED.
1119 */
1120 nvme_cancel_queue_ios(nvmeq->hctx, req, nvmeq, reserved);
1121 ret = BLK_EH_NOT_HANDLED;
1122 } else
1123 nvme_abort_req(req);
1124 spin_unlock_irq(&nvmeq->q_lock);
1125
1126 return ret;
1098} 1127}
1099 1128
1100static void nvme_free_queue(struct nvme_queue *nvmeq) 1129static void nvme_free_queue(struct nvme_queue *nvmeq)
@@ -1131,10 +1160,16 @@ static void nvme_free_queues(struct nvme_dev *dev, int lowest)
1131 */ 1160 */
1132static int nvme_suspend_queue(struct nvme_queue *nvmeq) 1161static int nvme_suspend_queue(struct nvme_queue *nvmeq)
1133{ 1162{
1134 int vector = nvmeq->dev->entry[nvmeq->cq_vector].vector; 1163 int vector;
1135 1164
1136 spin_lock_irq(&nvmeq->q_lock); 1165 spin_lock_irq(&nvmeq->q_lock);
1166 if (nvmeq->cq_vector == -1) {
1167 spin_unlock_irq(&nvmeq->q_lock);
1168 return 1;
1169 }
1170 vector = nvmeq->dev->entry[nvmeq->cq_vector].vector;
1137 nvmeq->dev->online_queues--; 1171 nvmeq->dev->online_queues--;
1172 nvmeq->cq_vector = -1;
1138 spin_unlock_irq(&nvmeq->q_lock); 1173 spin_unlock_irq(&nvmeq->q_lock);
1139 1174
1140 irq_set_affinity_hint(vector, NULL); 1175 irq_set_affinity_hint(vector, NULL);
@@ -1169,11 +1204,13 @@ static void nvme_disable_queue(struct nvme_dev *dev, int qid)
1169 adapter_delete_sq(dev, qid); 1204 adapter_delete_sq(dev, qid);
1170 adapter_delete_cq(dev, qid); 1205 adapter_delete_cq(dev, qid);
1171 } 1206 }
1207 if (!qid && dev->admin_q)
1208 blk_mq_freeze_queue_start(dev->admin_q);
1172 nvme_clear_queue(nvmeq); 1209 nvme_clear_queue(nvmeq);
1173} 1210}
1174 1211
1175static struct nvme_queue *nvme_alloc_queue(struct nvme_dev *dev, int qid, 1212static struct nvme_queue *nvme_alloc_queue(struct nvme_dev *dev, int qid,
1176 int depth, int vector) 1213 int depth)
1177{ 1214{
1178 struct device *dmadev = &dev->pci_dev->dev; 1215 struct device *dmadev = &dev->pci_dev->dev;
1179 struct nvme_queue *nvmeq = kzalloc(sizeof(*nvmeq), GFP_KERNEL); 1216 struct nvme_queue *nvmeq = kzalloc(sizeof(*nvmeq), GFP_KERNEL);
@@ -1199,7 +1236,6 @@ static struct nvme_queue *nvme_alloc_queue(struct nvme_dev *dev, int qid,
1199 nvmeq->cq_phase = 1; 1236 nvmeq->cq_phase = 1;
1200 nvmeq->q_db = &dev->dbs[qid * 2 * dev->db_stride]; 1237 nvmeq->q_db = &dev->dbs[qid * 2 * dev->db_stride];
1201 nvmeq->q_depth = depth; 1238 nvmeq->q_depth = depth;
1202 nvmeq->cq_vector = vector;
1203 nvmeq->qid = qid; 1239 nvmeq->qid = qid;
1204 dev->queue_count++; 1240 dev->queue_count++;
1205 dev->queues[qid] = nvmeq; 1241 dev->queues[qid] = nvmeq;
@@ -1244,6 +1280,7 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)
1244 struct nvme_dev *dev = nvmeq->dev; 1280 struct nvme_dev *dev = nvmeq->dev;
1245 int result; 1281 int result;
1246 1282
1283 nvmeq->cq_vector = qid - 1;
1247 result = adapter_alloc_cq(dev, qid, nvmeq); 1284 result = adapter_alloc_cq(dev, qid, nvmeq);
1248 if (result < 0) 1285 if (result < 0)
1249 return result; 1286 return result;
@@ -1355,6 +1392,14 @@ static struct blk_mq_ops nvme_mq_ops = {
1355 .timeout = nvme_timeout, 1392 .timeout = nvme_timeout,
1356}; 1393};
1357 1394
1395static void nvme_dev_remove_admin(struct nvme_dev *dev)
1396{
1397 if (dev->admin_q && !blk_queue_dying(dev->admin_q)) {
1398 blk_cleanup_queue(dev->admin_q);
1399 blk_mq_free_tag_set(&dev->admin_tagset);
1400 }
1401}
1402
1358static int nvme_alloc_admin_tags(struct nvme_dev *dev) 1403static int nvme_alloc_admin_tags(struct nvme_dev *dev)
1359{ 1404{
1360 if (!dev->admin_q) { 1405 if (!dev->admin_q) {
@@ -1370,21 +1415,20 @@ static int nvme_alloc_admin_tags(struct nvme_dev *dev)
1370 return -ENOMEM; 1415 return -ENOMEM;
1371 1416
1372 dev->admin_q = blk_mq_init_queue(&dev->admin_tagset); 1417 dev->admin_q = blk_mq_init_queue(&dev->admin_tagset);
1373 if (!dev->admin_q) { 1418 if (IS_ERR(dev->admin_q)) {
1374 blk_mq_free_tag_set(&dev->admin_tagset); 1419 blk_mq_free_tag_set(&dev->admin_tagset);
1375 return -ENOMEM; 1420 return -ENOMEM;
1376 } 1421 }
1377 } 1422 if (!blk_get_queue(dev->admin_q)) {
1423 nvme_dev_remove_admin(dev);
1424 return -ENODEV;
1425 }
1426 } else
1427 blk_mq_unfreeze_queue(dev->admin_q);
1378 1428
1379 return 0; 1429 return 0;
1380} 1430}
1381 1431
1382static void nvme_free_admin_tags(struct nvme_dev *dev)
1383{
1384 if (dev->admin_q)
1385 blk_mq_free_tag_set(&dev->admin_tagset);
1386}
1387
1388static int nvme_configure_admin_queue(struct nvme_dev *dev) 1432static int nvme_configure_admin_queue(struct nvme_dev *dev)
1389{ 1433{
1390 int result; 1434 int result;
@@ -1416,7 +1460,7 @@ static int nvme_configure_admin_queue(struct nvme_dev *dev)
1416 1460
1417 nvmeq = dev->queues[0]; 1461 nvmeq = dev->queues[0];
1418 if (!nvmeq) { 1462 if (!nvmeq) {
1419 nvmeq = nvme_alloc_queue(dev, 0, NVME_AQ_DEPTH, 0); 1463 nvmeq = nvme_alloc_queue(dev, 0, NVME_AQ_DEPTH);
1420 if (!nvmeq) 1464 if (!nvmeq)
1421 return -ENOMEM; 1465 return -ENOMEM;
1422 } 1466 }
@@ -1439,18 +1483,13 @@ static int nvme_configure_admin_queue(struct nvme_dev *dev)
1439 if (result) 1483 if (result)
1440 goto free_nvmeq; 1484 goto free_nvmeq;
1441 1485
1442 result = nvme_alloc_admin_tags(dev); 1486 nvmeq->cq_vector = 0;
1443 if (result)
1444 goto free_nvmeq;
1445
1446 result = queue_request_irq(dev, nvmeq, nvmeq->irqname); 1487 result = queue_request_irq(dev, nvmeq, nvmeq->irqname);
1447 if (result) 1488 if (result)
1448 goto free_tags; 1489 goto free_nvmeq;
1449 1490
1450 return result; 1491 return result;
1451 1492
1452 free_tags:
1453 nvme_free_admin_tags(dev);
1454 free_nvmeq: 1493 free_nvmeq:
1455 nvme_free_queues(dev, 0); 1494 nvme_free_queues(dev, 0);
1456 return result; 1495 return result;
@@ -1944,7 +1983,7 @@ static void nvme_create_io_queues(struct nvme_dev *dev)
1944 unsigned i; 1983 unsigned i;
1945 1984
1946 for (i = dev->queue_count; i <= dev->max_qid; i++) 1985 for (i = dev->queue_count; i <= dev->max_qid; i++)
1947 if (!nvme_alloc_queue(dev, i, dev->q_depth, i - 1)) 1986 if (!nvme_alloc_queue(dev, i, dev->q_depth))
1948 break; 1987 break;
1949 1988
1950 for (i = dev->online_queues; i <= dev->queue_count - 1; i++) 1989 for (i = dev->online_queues; i <= dev->queue_count - 1; i++)
@@ -2235,13 +2274,18 @@ static void nvme_wait_dq(struct nvme_delq_ctx *dq, struct nvme_dev *dev)
2235 break; 2274 break;
2236 if (!schedule_timeout(ADMIN_TIMEOUT) || 2275 if (!schedule_timeout(ADMIN_TIMEOUT) ||
2237 fatal_signal_pending(current)) { 2276 fatal_signal_pending(current)) {
2277 /*
2278 * Disable the controller first since we can't trust it
2279 * at this point, but leave the admin queue enabled
2280 * until all queue deletion requests are flushed.
2281 * FIXME: This may take a while if there are more h/w
2282 * queues than admin tags.
2283 */
2238 set_current_state(TASK_RUNNING); 2284 set_current_state(TASK_RUNNING);
2239
2240 nvme_disable_ctrl(dev, readq(&dev->bar->cap)); 2285 nvme_disable_ctrl(dev, readq(&dev->bar->cap));
2241 nvme_disable_queue(dev, 0); 2286 nvme_clear_queue(dev->queues[0]);
2242
2243 send_sig(SIGKILL, dq->worker->task, 1);
2244 flush_kthread_worker(dq->worker); 2287 flush_kthread_worker(dq->worker);
2288 nvme_disable_queue(dev, 0);
2245 return; 2289 return;
2246 } 2290 }
2247 } 2291 }
@@ -2318,7 +2362,6 @@ static void nvme_del_queue_start(struct kthread_work *work)
2318{ 2362{
2319 struct nvme_queue *nvmeq = container_of(work, struct nvme_queue, 2363 struct nvme_queue *nvmeq = container_of(work, struct nvme_queue,
2320 cmdinfo.work); 2364 cmdinfo.work);
2321 allow_signal(SIGKILL);
2322 if (nvme_delete_sq(nvmeq)) 2365 if (nvme_delete_sq(nvmeq))
2323 nvme_del_queue_end(nvmeq); 2366 nvme_del_queue_end(nvmeq);
2324} 2367}
@@ -2376,6 +2419,34 @@ static void nvme_dev_list_remove(struct nvme_dev *dev)
2376 kthread_stop(tmp); 2419 kthread_stop(tmp);
2377} 2420}
2378 2421
2422static void nvme_freeze_queues(struct nvme_dev *dev)
2423{
2424 struct nvme_ns *ns;
2425
2426 list_for_each_entry(ns, &dev->namespaces, list) {
2427 blk_mq_freeze_queue_start(ns->queue);
2428
2429 spin_lock(ns->queue->queue_lock);
2430 queue_flag_set(QUEUE_FLAG_STOPPED, ns->queue);
2431 spin_unlock(ns->queue->queue_lock);
2432
2433 blk_mq_cancel_requeue_work(ns->queue);
2434 blk_mq_stop_hw_queues(ns->queue);
2435 }
2436}
2437
2438static void nvme_unfreeze_queues(struct nvme_dev *dev)
2439{
2440 struct nvme_ns *ns;
2441
2442 list_for_each_entry(ns, &dev->namespaces, list) {
2443 queue_flag_clear_unlocked(QUEUE_FLAG_STOPPED, ns->queue);
2444 blk_mq_unfreeze_queue(ns->queue);
2445 blk_mq_start_stopped_hw_queues(ns->queue, true);
2446 blk_mq_kick_requeue_list(ns->queue);
2447 }
2448}
2449
2379static void nvme_dev_shutdown(struct nvme_dev *dev) 2450static void nvme_dev_shutdown(struct nvme_dev *dev)
2380{ 2451{
2381 int i; 2452 int i;
@@ -2384,8 +2455,10 @@ static void nvme_dev_shutdown(struct nvme_dev *dev)
2384 dev->initialized = 0; 2455 dev->initialized = 0;
2385 nvme_dev_list_remove(dev); 2456 nvme_dev_list_remove(dev);
2386 2457
2387 if (dev->bar) 2458 if (dev->bar) {
2459 nvme_freeze_queues(dev);
2388 csts = readl(&dev->bar->csts); 2460 csts = readl(&dev->bar->csts);
2461 }
2389 if (csts & NVME_CSTS_CFS || !(csts & NVME_CSTS_RDY)) { 2462 if (csts & NVME_CSTS_CFS || !(csts & NVME_CSTS_RDY)) {
2390 for (i = dev->queue_count - 1; i >= 0; i--) { 2463 for (i = dev->queue_count - 1; i >= 0; i--) {
2391 struct nvme_queue *nvmeq = dev->queues[i]; 2464 struct nvme_queue *nvmeq = dev->queues[i];
@@ -2400,12 +2473,6 @@ static void nvme_dev_shutdown(struct nvme_dev *dev)
2400 nvme_dev_unmap(dev); 2473 nvme_dev_unmap(dev);
2401} 2474}
2402 2475
2403static void nvme_dev_remove_admin(struct nvme_dev *dev)
2404{
2405 if (dev->admin_q && !blk_queue_dying(dev->admin_q))
2406 blk_cleanup_queue(dev->admin_q);
2407}
2408
2409static void nvme_dev_remove(struct nvme_dev *dev) 2476static void nvme_dev_remove(struct nvme_dev *dev)
2410{ 2477{
2411 struct nvme_ns *ns; 2478 struct nvme_ns *ns;
@@ -2413,8 +2480,10 @@ static void nvme_dev_remove(struct nvme_dev *dev)
2413 list_for_each_entry(ns, &dev->namespaces, list) { 2480 list_for_each_entry(ns, &dev->namespaces, list) {
2414 if (ns->disk->flags & GENHD_FL_UP) 2481 if (ns->disk->flags & GENHD_FL_UP)
2415 del_gendisk(ns->disk); 2482 del_gendisk(ns->disk);
2416 if (!blk_queue_dying(ns->queue)) 2483 if (!blk_queue_dying(ns->queue)) {
2484 blk_mq_abort_requeue_list(ns->queue);
2417 blk_cleanup_queue(ns->queue); 2485 blk_cleanup_queue(ns->queue);
2486 }
2418 } 2487 }
2419} 2488}
2420 2489
@@ -2495,6 +2564,7 @@ static void nvme_free_dev(struct kref *kref)
2495 nvme_free_namespaces(dev); 2564 nvme_free_namespaces(dev);
2496 nvme_release_instance(dev); 2565 nvme_release_instance(dev);
2497 blk_mq_free_tag_set(&dev->tagset); 2566 blk_mq_free_tag_set(&dev->tagset);
2567 blk_put_queue(dev->admin_q);
2498 kfree(dev->queues); 2568 kfree(dev->queues);
2499 kfree(dev->entry); 2569 kfree(dev->entry);
2500 kfree(dev); 2570 kfree(dev);
@@ -2591,15 +2661,20 @@ static int nvme_dev_start(struct nvme_dev *dev)
2591 } 2661 }
2592 2662
2593 nvme_init_queue(dev->queues[0], 0); 2663 nvme_init_queue(dev->queues[0], 0);
2664 result = nvme_alloc_admin_tags(dev);
2665 if (result)
2666 goto disable;
2594 2667
2595 result = nvme_setup_io_queues(dev); 2668 result = nvme_setup_io_queues(dev);
2596 if (result) 2669 if (result)
2597 goto disable; 2670 goto free_tags;
2598 2671
2599 nvme_set_irq_hints(dev); 2672 nvme_set_irq_hints(dev);
2600 2673
2601 return result; 2674 return result;
2602 2675
2676 free_tags:
2677 nvme_dev_remove_admin(dev);
2603 disable: 2678 disable:
2604 nvme_disable_queue(dev, 0); 2679 nvme_disable_queue(dev, 0);
2605 nvme_dev_list_remove(dev); 2680 nvme_dev_list_remove(dev);
@@ -2639,6 +2714,9 @@ static int nvme_dev_resume(struct nvme_dev *dev)
2639 dev->reset_workfn = nvme_remove_disks; 2714 dev->reset_workfn = nvme_remove_disks;
2640 queue_work(nvme_workq, &dev->reset_work); 2715 queue_work(nvme_workq, &dev->reset_work);
2641 spin_unlock(&dev_list_lock); 2716 spin_unlock(&dev_list_lock);
2717 } else {
2718 nvme_unfreeze_queues(dev);
2719 nvme_set_irq_hints(dev);
2642 } 2720 }
2643 dev->initialized = 1; 2721 dev->initialized = 1;
2644 return 0; 2722 return 0;
@@ -2776,11 +2854,10 @@ static void nvme_remove(struct pci_dev *pdev)
2776 pci_set_drvdata(pdev, NULL); 2854 pci_set_drvdata(pdev, NULL);
2777 flush_work(&dev->reset_work); 2855 flush_work(&dev->reset_work);
2778 misc_deregister(&dev->miscdev); 2856 misc_deregister(&dev->miscdev);
2779 nvme_dev_remove(dev);
2780 nvme_dev_shutdown(dev); 2857 nvme_dev_shutdown(dev);
2858 nvme_dev_remove(dev);
2781 nvme_dev_remove_admin(dev); 2859 nvme_dev_remove_admin(dev);
2782 nvme_free_queues(dev, 0); 2860 nvme_free_queues(dev, 0);
2783 nvme_free_admin_tags(dev);
2784 nvme_release_prp_pools(dev); 2861 nvme_release_prp_pools(dev);
2785 kref_put(&dev->kref, nvme_free_dev); 2862 kref_put(&dev->kref, nvme_free_dev);
2786} 2863}
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 7ef7c098708f..cdfbd21e3597 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -638,7 +638,7 @@ static int virtblk_probe(struct virtio_device *vdev)
638 goto out_put_disk; 638 goto out_put_disk;
639 639
640 q = vblk->disk->queue = blk_mq_init_queue(&vblk->tag_set); 640 q = vblk->disk->queue = blk_mq_init_queue(&vblk->tag_set);
641 if (!q) { 641 if (IS_ERR(q)) {
642 err = -ENOMEM; 642 err = -ENOMEM;
643 goto out_free_tags; 643 goto out_free_tags;
644 } 644 }
diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index fd5a5e85d7dc..982b96323f82 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -969,7 +969,8 @@ static void sender(void *send_info,
969 969
970 do_gettimeofday(&t); 970 do_gettimeofday(&t);
971 pr_info("**Enqueue %02x %02x: %ld.%6.6ld\n", 971 pr_info("**Enqueue %02x %02x: %ld.%6.6ld\n",
972 msg->data[0], msg->data[1], t.tv_sec, t.tv_usec); 972 msg->data[0], msg->data[1],
973 (long) t.tv_sec, (long) t.tv_usec);
973 } 974 }
974} 975}
975 976
diff --git a/drivers/gpio/gpio-dln2.c b/drivers/gpio/gpio-dln2.c
index 978b51eae2ec..ce3c1558cb0a 100644
--- a/drivers/gpio/gpio-dln2.c
+++ b/drivers/gpio/gpio-dln2.c
@@ -47,13 +47,6 @@
47 47
48#define DLN2_GPIO_MAX_PINS 32 48#define DLN2_GPIO_MAX_PINS 32
49 49
50struct dln2_irq_work {
51 struct work_struct work;
52 struct dln2_gpio *dln2;
53 int pin;
54 int type;
55};
56
57struct dln2_gpio { 50struct dln2_gpio {
58 struct platform_device *pdev; 51 struct platform_device *pdev;
59 struct gpio_chip gpio; 52 struct gpio_chip gpio;
@@ -64,10 +57,12 @@ struct dln2_gpio {
64 */ 57 */
65 DECLARE_BITMAP(output_enabled, DLN2_GPIO_MAX_PINS); 58 DECLARE_BITMAP(output_enabled, DLN2_GPIO_MAX_PINS);
66 59
67 DECLARE_BITMAP(irqs_masked, DLN2_GPIO_MAX_PINS); 60 /* active IRQs - not synced to hardware */
68 DECLARE_BITMAP(irqs_enabled, DLN2_GPIO_MAX_PINS); 61 DECLARE_BITMAP(unmasked_irqs, DLN2_GPIO_MAX_PINS);
69 DECLARE_BITMAP(irqs_pending, DLN2_GPIO_MAX_PINS); 62 /* active IRQS - synced to hardware */
70 struct dln2_irq_work *irq_work; 63 DECLARE_BITMAP(enabled_irqs, DLN2_GPIO_MAX_PINS);
64 int irq_type[DLN2_GPIO_MAX_PINS];
65 struct mutex irq_lock;
71}; 66};
72 67
73struct dln2_gpio_pin { 68struct dln2_gpio_pin {
@@ -141,16 +136,16 @@ static int dln2_gpio_pin_get_out_val(struct dln2_gpio *dln2, unsigned int pin)
141 return !!ret; 136 return !!ret;
142} 137}
143 138
144static void dln2_gpio_pin_set_out_val(struct dln2_gpio *dln2, 139static int dln2_gpio_pin_set_out_val(struct dln2_gpio *dln2,
145 unsigned int pin, int value) 140 unsigned int pin, int value)
146{ 141{
147 struct dln2_gpio_pin_val req = { 142 struct dln2_gpio_pin_val req = {
148 .pin = cpu_to_le16(pin), 143 .pin = cpu_to_le16(pin),
149 .value = value, 144 .value = value,
150 }; 145 };
151 146
152 dln2_transfer_tx(dln2->pdev, DLN2_GPIO_PIN_SET_OUT_VAL, &req, 147 return dln2_transfer_tx(dln2->pdev, DLN2_GPIO_PIN_SET_OUT_VAL, &req,
153 sizeof(req)); 148 sizeof(req));
154} 149}
155 150
156#define DLN2_GPIO_DIRECTION_IN 0 151#define DLN2_GPIO_DIRECTION_IN 0
@@ -267,6 +262,13 @@ static int dln2_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
267static int dln2_gpio_direction_output(struct gpio_chip *chip, unsigned offset, 262static int dln2_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
268 int value) 263 int value)
269{ 264{
265 struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio);
266 int ret;
267
268 ret = dln2_gpio_pin_set_out_val(dln2, offset, value);
269 if (ret < 0)
270 return ret;
271
270 return dln2_gpio_set_direction(chip, offset, DLN2_GPIO_DIRECTION_OUT); 272 return dln2_gpio_set_direction(chip, offset, DLN2_GPIO_DIRECTION_OUT);
271} 273}
272 274
@@ -297,36 +299,13 @@ static int dln2_gpio_set_event_cfg(struct dln2_gpio *dln2, unsigned pin,
297 &req, sizeof(req)); 299 &req, sizeof(req));
298} 300}
299 301
300static void dln2_irq_work(struct work_struct *w) 302static void dln2_irq_unmask(struct irq_data *irqd)
301{
302 struct dln2_irq_work *iw = container_of(w, struct dln2_irq_work, work);
303 struct dln2_gpio *dln2 = iw->dln2;
304 u8 type = iw->type & DLN2_GPIO_EVENT_MASK;
305
306 if (test_bit(iw->pin, dln2->irqs_enabled))
307 dln2_gpio_set_event_cfg(dln2, iw->pin, type, 0);
308 else
309 dln2_gpio_set_event_cfg(dln2, iw->pin, DLN2_GPIO_EVENT_NONE, 0);
310}
311
312static void dln2_irq_enable(struct irq_data *irqd)
313{
314 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
315 struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio);
316 int pin = irqd_to_hwirq(irqd);
317
318 set_bit(pin, dln2->irqs_enabled);
319 schedule_work(&dln2->irq_work[pin].work);
320}
321
322static void dln2_irq_disable(struct irq_data *irqd)
323{ 303{
324 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 304 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
325 struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio); 305 struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio);
326 int pin = irqd_to_hwirq(irqd); 306 int pin = irqd_to_hwirq(irqd);
327 307
328 clear_bit(pin, dln2->irqs_enabled); 308 set_bit(pin, dln2->unmasked_irqs);
329 schedule_work(&dln2->irq_work[pin].work);
330} 309}
331 310
332static void dln2_irq_mask(struct irq_data *irqd) 311static void dln2_irq_mask(struct irq_data *irqd)
@@ -335,27 +314,7 @@ static void dln2_irq_mask(struct irq_data *irqd)
335 struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio); 314 struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio);
336 int pin = irqd_to_hwirq(irqd); 315 int pin = irqd_to_hwirq(irqd);
337 316
338 set_bit(pin, dln2->irqs_masked); 317 clear_bit(pin, dln2->unmasked_irqs);
339}
340
341static void dln2_irq_unmask(struct irq_data *irqd)
342{
343 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
344 struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio);
345 struct device *dev = dln2->gpio.dev;
346 int pin = irqd_to_hwirq(irqd);
347
348 if (test_and_clear_bit(pin, dln2->irqs_pending)) {
349 int irq;
350
351 irq = irq_find_mapping(dln2->gpio.irqdomain, pin);
352 if (!irq) {
353 dev_err(dev, "pin %d not mapped to IRQ\n", pin);
354 return;
355 }
356
357 generic_handle_irq(irq);
358 }
359} 318}
360 319
361static int dln2_irq_set_type(struct irq_data *irqd, unsigned type) 320static int dln2_irq_set_type(struct irq_data *irqd, unsigned type)
@@ -366,19 +325,19 @@ static int dln2_irq_set_type(struct irq_data *irqd, unsigned type)
366 325
367 switch (type) { 326 switch (type) {
368 case IRQ_TYPE_LEVEL_HIGH: 327 case IRQ_TYPE_LEVEL_HIGH:
369 dln2->irq_work[pin].type = DLN2_GPIO_EVENT_LVL_HIGH; 328 dln2->irq_type[pin] = DLN2_GPIO_EVENT_LVL_HIGH;
370 break; 329 break;
371 case IRQ_TYPE_LEVEL_LOW: 330 case IRQ_TYPE_LEVEL_LOW:
372 dln2->irq_work[pin].type = DLN2_GPIO_EVENT_LVL_LOW; 331 dln2->irq_type[pin] = DLN2_GPIO_EVENT_LVL_LOW;
373 break; 332 break;
374 case IRQ_TYPE_EDGE_BOTH: 333 case IRQ_TYPE_EDGE_BOTH:
375 dln2->irq_work[pin].type = DLN2_GPIO_EVENT_CHANGE; 334 dln2->irq_type[pin] = DLN2_GPIO_EVENT_CHANGE;
376 break; 335 break;
377 case IRQ_TYPE_EDGE_RISING: 336 case IRQ_TYPE_EDGE_RISING:
378 dln2->irq_work[pin].type = DLN2_GPIO_EVENT_CHANGE_RISING; 337 dln2->irq_type[pin] = DLN2_GPIO_EVENT_CHANGE_RISING;
379 break; 338 break;
380 case IRQ_TYPE_EDGE_FALLING: 339 case IRQ_TYPE_EDGE_FALLING:
381 dln2->irq_work[pin].type = DLN2_GPIO_EVENT_CHANGE_FALLING; 340 dln2->irq_type[pin] = DLN2_GPIO_EVENT_CHANGE_FALLING;
382 break; 341 break;
383 default: 342 default:
384 return -EINVAL; 343 return -EINVAL;
@@ -387,13 +346,50 @@ static int dln2_irq_set_type(struct irq_data *irqd, unsigned type)
387 return 0; 346 return 0;
388} 347}
389 348
349static void dln2_irq_bus_lock(struct irq_data *irqd)
350{
351 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
352 struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio);
353
354 mutex_lock(&dln2->irq_lock);
355}
356
357static void dln2_irq_bus_unlock(struct irq_data *irqd)
358{
359 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
360 struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio);
361 int pin = irqd_to_hwirq(irqd);
362 int enabled, unmasked;
363 unsigned type;
364 int ret;
365
366 enabled = test_bit(pin, dln2->enabled_irqs);
367 unmasked = test_bit(pin, dln2->unmasked_irqs);
368
369 if (enabled != unmasked) {
370 if (unmasked) {
371 type = dln2->irq_type[pin] & DLN2_GPIO_EVENT_MASK;
372 set_bit(pin, dln2->enabled_irqs);
373 } else {
374 type = DLN2_GPIO_EVENT_NONE;
375 clear_bit(pin, dln2->enabled_irqs);
376 }
377
378 ret = dln2_gpio_set_event_cfg(dln2, pin, type, 0);
379 if (ret)
380 dev_err(dln2->gpio.dev, "failed to set event\n");
381 }
382
383 mutex_unlock(&dln2->irq_lock);
384}
385
390static struct irq_chip dln2_gpio_irqchip = { 386static struct irq_chip dln2_gpio_irqchip = {
391 .name = "dln2-irq", 387 .name = "dln2-irq",
392 .irq_enable = dln2_irq_enable,
393 .irq_disable = dln2_irq_disable,
394 .irq_mask = dln2_irq_mask, 388 .irq_mask = dln2_irq_mask,
395 .irq_unmask = dln2_irq_unmask, 389 .irq_unmask = dln2_irq_unmask,
396 .irq_set_type = dln2_irq_set_type, 390 .irq_set_type = dln2_irq_set_type,
391 .irq_bus_lock = dln2_irq_bus_lock,
392 .irq_bus_sync_unlock = dln2_irq_bus_unlock,
397}; 393};
398 394
399static void dln2_gpio_event(struct platform_device *pdev, u16 echo, 395static void dln2_gpio_event(struct platform_device *pdev, u16 echo,
@@ -425,14 +421,7 @@ static void dln2_gpio_event(struct platform_device *pdev, u16 echo,
425 return; 421 return;
426 } 422 }
427 423
428 if (!test_bit(pin, dln2->irqs_enabled)) 424 switch (dln2->irq_type[pin]) {
429 return;
430 if (test_bit(pin, dln2->irqs_masked)) {
431 set_bit(pin, dln2->irqs_pending);
432 return;
433 }
434
435 switch (dln2->irq_work[pin].type) {
436 case DLN2_GPIO_EVENT_CHANGE_RISING: 425 case DLN2_GPIO_EVENT_CHANGE_RISING:
437 if (event->value) 426 if (event->value)
438 generic_handle_irq(irq); 427 generic_handle_irq(irq);
@@ -451,7 +440,7 @@ static int dln2_gpio_probe(struct platform_device *pdev)
451 struct dln2_gpio *dln2; 440 struct dln2_gpio *dln2;
452 struct device *dev = &pdev->dev; 441 struct device *dev = &pdev->dev;
453 int pins; 442 int pins;
454 int i, ret; 443 int ret;
455 444
456 pins = dln2_gpio_get_pin_count(pdev); 445 pins = dln2_gpio_get_pin_count(pdev);
457 if (pins < 0) { 446 if (pins < 0) {
@@ -467,15 +456,7 @@ static int dln2_gpio_probe(struct platform_device *pdev)
467 if (!dln2) 456 if (!dln2)
468 return -ENOMEM; 457 return -ENOMEM;
469 458
470 dln2->irq_work = devm_kcalloc(&pdev->dev, pins, 459 mutex_init(&dln2->irq_lock);
471 sizeof(struct dln2_irq_work), GFP_KERNEL);
472 if (!dln2->irq_work)
473 return -ENOMEM;
474 for (i = 0; i < pins; i++) {
475 INIT_WORK(&dln2->irq_work[i].work, dln2_irq_work);
476 dln2->irq_work[i].pin = i;
477 dln2->irq_work[i].dln2 = dln2;
478 }
479 460
480 dln2->pdev = pdev; 461 dln2->pdev = pdev;
481 462
@@ -529,11 +510,8 @@ out:
529static int dln2_gpio_remove(struct platform_device *pdev) 510static int dln2_gpio_remove(struct platform_device *pdev)
530{ 511{
531 struct dln2_gpio *dln2 = platform_get_drvdata(pdev); 512 struct dln2_gpio *dln2 = platform_get_drvdata(pdev);
532 int i;
533 513
534 dln2_unregister_event_cb(pdev, DLN2_GPIO_CONDITION_MET_EV); 514 dln2_unregister_event_cb(pdev, DLN2_GPIO_CONDITION_MET_EV);
535 for (i = 0; i < dln2->gpio.ngpio; i++)
536 flush_work(&dln2->irq_work[i].work);
537 gpiochip_remove(&dln2->gpio); 515 gpiochip_remove(&dln2->gpio);
538 516
539 return 0; 517 return 0;
diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c
index 09daaf2aeb56..3a5a71050559 100644
--- a/drivers/gpio/gpio-grgpio.c
+++ b/drivers/gpio/gpio-grgpio.c
@@ -441,7 +441,8 @@ static int grgpio_probe(struct platform_device *ofdev)
441 err = gpiochip_add(gc); 441 err = gpiochip_add(gc);
442 if (err) { 442 if (err) {
443 dev_err(&ofdev->dev, "Could not add gpiochip\n"); 443 dev_err(&ofdev->dev, "Could not add gpiochip\n");
444 irq_domain_remove(priv->domain); 444 if (priv->domain)
445 irq_domain_remove(priv->domain);
445 return err; 446 return err;
446 } 447 }
447 448
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 66e40398b3d3..e620807418ea 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -37,6 +37,7 @@ obj-$(CONFIG_DRM_MIPI_DSI) += drm_mipi_dsi.o
37obj-$(CONFIG_DRM_TTM) += ttm/ 37obj-$(CONFIG_DRM_TTM) += ttm/
38obj-$(CONFIG_DRM_TDFX) += tdfx/ 38obj-$(CONFIG_DRM_TDFX) += tdfx/
39obj-$(CONFIG_DRM_R128) += r128/ 39obj-$(CONFIG_DRM_R128) += r128/
40obj-$(CONFIG_HSA_AMD) += amd/amdkfd/
40obj-$(CONFIG_DRM_RADEON)+= radeon/ 41obj-$(CONFIG_DRM_RADEON)+= radeon/
41obj-$(CONFIG_DRM_MGA) += mga/ 42obj-$(CONFIG_DRM_MGA) += mga/
42obj-$(CONFIG_DRM_I810) += i810/ 43obj-$(CONFIG_DRM_I810) += i810/
@@ -67,4 +68,3 @@ obj-$(CONFIG_DRM_IMX) += imx/
67obj-y += i2c/ 68obj-y += i2c/
68obj-y += panel/ 69obj-y += panel/
69obj-y += bridge/ 70obj-y += bridge/
70obj-$(CONFIG_HSA_AMD) += amd/amdkfd/
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 7d4974b83af7..fcfdf23e1913 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -31,7 +31,6 @@
31#include <uapi/linux/kfd_ioctl.h> 31#include <uapi/linux/kfd_ioctl.h>
32#include <linux/time.h> 32#include <linux/time.h>
33#include <linux/mm.h> 33#include <linux/mm.h>
34#include <linux/uaccess.h>
35#include <uapi/asm-generic/mman-common.h> 34#include <uapi/asm-generic/mman-common.h>
36#include <asm/processor.h> 35#include <asm/processor.h>
37#include "kfd_priv.h" 36#include "kfd_priv.h"
@@ -127,17 +126,14 @@ static int kfd_open(struct inode *inode, struct file *filep)
127 return 0; 126 return 0;
128} 127}
129 128
130static long kfd_ioctl_get_version(struct file *filep, struct kfd_process *p, 129static int kfd_ioctl_get_version(struct file *filep, struct kfd_process *p,
131 void __user *arg) 130 void *data)
132{ 131{
133 struct kfd_ioctl_get_version_args args; 132 struct kfd_ioctl_get_version_args *args = data;
134 int err = 0; 133 int err = 0;
135 134
136 args.major_version = KFD_IOCTL_MAJOR_VERSION; 135 args->major_version = KFD_IOCTL_MAJOR_VERSION;
137 args.minor_version = KFD_IOCTL_MINOR_VERSION; 136 args->minor_version = KFD_IOCTL_MINOR_VERSION;
138
139 if (copy_to_user(arg, &args, sizeof(args)))
140 err = -EFAULT;
141 137
142 return err; 138 return err;
143} 139}
@@ -221,10 +217,10 @@ static int set_queue_properties_from_user(struct queue_properties *q_properties,
221 return 0; 217 return 0;
222} 218}
223 219
224static long kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, 220static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
225 void __user *arg) 221 void *data)
226{ 222{
227 struct kfd_ioctl_create_queue_args args; 223 struct kfd_ioctl_create_queue_args *args = data;
228 struct kfd_dev *dev; 224 struct kfd_dev *dev;
229 int err = 0; 225 int err = 0;
230 unsigned int queue_id; 226 unsigned int queue_id;
@@ -233,16 +229,13 @@ static long kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
233 229
234 memset(&q_properties, 0, sizeof(struct queue_properties)); 230 memset(&q_properties, 0, sizeof(struct queue_properties));
235 231
236 if (copy_from_user(&args, arg, sizeof(args)))
237 return -EFAULT;
238
239 pr_debug("kfd: creating queue ioctl\n"); 232 pr_debug("kfd: creating queue ioctl\n");
240 233
241 err = set_queue_properties_from_user(&q_properties, &args); 234 err = set_queue_properties_from_user(&q_properties, args);
242 if (err) 235 if (err)
243 return err; 236 return err;
244 237
245 dev = kfd_device_by_id(args.gpu_id); 238 dev = kfd_device_by_id(args->gpu_id);
246 if (dev == NULL) 239 if (dev == NULL)
247 return -EINVAL; 240 return -EINVAL;
248 241
@@ -250,7 +243,7 @@ static long kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
250 243
251 pdd = kfd_bind_process_to_device(dev, p); 244 pdd = kfd_bind_process_to_device(dev, p);
252 if (IS_ERR(pdd)) { 245 if (IS_ERR(pdd)) {
253 err = PTR_ERR(pdd); 246 err = -ESRCH;
254 goto err_bind_process; 247 goto err_bind_process;
255 } 248 }
256 249
@@ -263,33 +256,26 @@ static long kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
263 if (err != 0) 256 if (err != 0)
264 goto err_create_queue; 257 goto err_create_queue;
265 258
266 args.queue_id = queue_id; 259 args->queue_id = queue_id;
267 260
268 /* Return gpu_id as doorbell offset for mmap usage */ 261 /* Return gpu_id as doorbell offset for mmap usage */
269 args.doorbell_offset = args.gpu_id << PAGE_SHIFT; 262 args->doorbell_offset = args->gpu_id << PAGE_SHIFT;
270
271 if (copy_to_user(arg, &args, sizeof(args))) {
272 err = -EFAULT;
273 goto err_copy_args_out;
274 }
275 263
276 mutex_unlock(&p->mutex); 264 mutex_unlock(&p->mutex);
277 265
278 pr_debug("kfd: queue id %d was created successfully\n", args.queue_id); 266 pr_debug("kfd: queue id %d was created successfully\n", args->queue_id);
279 267
280 pr_debug("ring buffer address == 0x%016llX\n", 268 pr_debug("ring buffer address == 0x%016llX\n",
281 args.ring_base_address); 269 args->ring_base_address);
282 270
283 pr_debug("read ptr address == 0x%016llX\n", 271 pr_debug("read ptr address == 0x%016llX\n",
284 args.read_pointer_address); 272 args->read_pointer_address);
285 273
286 pr_debug("write ptr address == 0x%016llX\n", 274 pr_debug("write ptr address == 0x%016llX\n",
287 args.write_pointer_address); 275 args->write_pointer_address);
288 276
289 return 0; 277 return 0;
290 278
291err_copy_args_out:
292 pqm_destroy_queue(&p->pqm, queue_id);
293err_create_queue: 279err_create_queue:
294err_bind_process: 280err_bind_process:
295 mutex_unlock(&p->mutex); 281 mutex_unlock(&p->mutex);
@@ -297,99 +283,90 @@ err_bind_process:
297} 283}
298 284
299static int kfd_ioctl_destroy_queue(struct file *filp, struct kfd_process *p, 285static int kfd_ioctl_destroy_queue(struct file *filp, struct kfd_process *p,
300 void __user *arg) 286 void *data)
301{ 287{
302 int retval; 288 int retval;
303 struct kfd_ioctl_destroy_queue_args args; 289 struct kfd_ioctl_destroy_queue_args *args = data;
304
305 if (copy_from_user(&args, arg, sizeof(args)))
306 return -EFAULT;
307 290
308 pr_debug("kfd: destroying queue id %d for PASID %d\n", 291 pr_debug("kfd: destroying queue id %d for PASID %d\n",
309 args.queue_id, 292 args->queue_id,
310 p->pasid); 293 p->pasid);
311 294
312 mutex_lock(&p->mutex); 295 mutex_lock(&p->mutex);
313 296
314 retval = pqm_destroy_queue(&p->pqm, args.queue_id); 297 retval = pqm_destroy_queue(&p->pqm, args->queue_id);
315 298
316 mutex_unlock(&p->mutex); 299 mutex_unlock(&p->mutex);
317 return retval; 300 return retval;
318} 301}
319 302
320static int kfd_ioctl_update_queue(struct file *filp, struct kfd_process *p, 303static int kfd_ioctl_update_queue(struct file *filp, struct kfd_process *p,
321 void __user *arg) 304 void *data)
322{ 305{
323 int retval; 306 int retval;
324 struct kfd_ioctl_update_queue_args args; 307 struct kfd_ioctl_update_queue_args *args = data;
325 struct queue_properties properties; 308 struct queue_properties properties;
326 309
327 if (copy_from_user(&args, arg, sizeof(args))) 310 if (args->queue_percentage > KFD_MAX_QUEUE_PERCENTAGE) {
328 return -EFAULT;
329
330 if (args.queue_percentage > KFD_MAX_QUEUE_PERCENTAGE) {
331 pr_err("kfd: queue percentage must be between 0 to KFD_MAX_QUEUE_PERCENTAGE\n"); 311 pr_err("kfd: queue percentage must be between 0 to KFD_MAX_QUEUE_PERCENTAGE\n");
332 return -EINVAL; 312 return -EINVAL;
333 } 313 }
334 314
335 if (args.queue_priority > KFD_MAX_QUEUE_PRIORITY) { 315 if (args->queue_priority > KFD_MAX_QUEUE_PRIORITY) {
336 pr_err("kfd: queue priority must be between 0 to KFD_MAX_QUEUE_PRIORITY\n"); 316 pr_err("kfd: queue priority must be between 0 to KFD_MAX_QUEUE_PRIORITY\n");
337 return -EINVAL; 317 return -EINVAL;
338 } 318 }
339 319
340 if ((args.ring_base_address) && 320 if ((args->ring_base_address) &&
341 (!access_ok(VERIFY_WRITE, 321 (!access_ok(VERIFY_WRITE,
342 (const void __user *) args.ring_base_address, 322 (const void __user *) args->ring_base_address,
343 sizeof(uint64_t)))) { 323 sizeof(uint64_t)))) {
344 pr_err("kfd: can't access ring base address\n"); 324 pr_err("kfd: can't access ring base address\n");
345 return -EFAULT; 325 return -EFAULT;
346 } 326 }
347 327
348 if (!is_power_of_2(args.ring_size) && (args.ring_size != 0)) { 328 if (!is_power_of_2(args->ring_size) && (args->ring_size != 0)) {
349 pr_err("kfd: ring size must be a power of 2 or 0\n"); 329 pr_err("kfd: ring size must be a power of 2 or 0\n");
350 return -EINVAL; 330 return -EINVAL;
351 } 331 }
352 332
353 properties.queue_address = args.ring_base_address; 333 properties.queue_address = args->ring_base_address;
354 properties.queue_size = args.ring_size; 334 properties.queue_size = args->ring_size;
355 properties.queue_percent = args.queue_percentage; 335 properties.queue_percent = args->queue_percentage;
356 properties.priority = args.queue_priority; 336 properties.priority = args->queue_priority;
357 337
358 pr_debug("kfd: updating queue id %d for PASID %d\n", 338 pr_debug("kfd: updating queue id %d for PASID %d\n",
359 args.queue_id, p->pasid); 339 args->queue_id, p->pasid);
360 340
361 mutex_lock(&p->mutex); 341 mutex_lock(&p->mutex);
362 342
363 retval = pqm_update_queue(&p->pqm, args.queue_id, &properties); 343 retval = pqm_update_queue(&p->pqm, args->queue_id, &properties);
364 344
365 mutex_unlock(&p->mutex); 345 mutex_unlock(&p->mutex);
366 346
367 return retval; 347 return retval;
368} 348}
369 349
370static long kfd_ioctl_set_memory_policy(struct file *filep, 350static int kfd_ioctl_set_memory_policy(struct file *filep,
371 struct kfd_process *p, void __user *arg) 351 struct kfd_process *p, void *data)
372{ 352{
373 struct kfd_ioctl_set_memory_policy_args args; 353 struct kfd_ioctl_set_memory_policy_args *args = data;
374 struct kfd_dev *dev; 354 struct kfd_dev *dev;
375 int err = 0; 355 int err = 0;
376 struct kfd_process_device *pdd; 356 struct kfd_process_device *pdd;
377 enum cache_policy default_policy, alternate_policy; 357 enum cache_policy default_policy, alternate_policy;
378 358
379 if (copy_from_user(&args, arg, sizeof(args))) 359 if (args->default_policy != KFD_IOC_CACHE_POLICY_COHERENT
380 return -EFAULT; 360 && args->default_policy != KFD_IOC_CACHE_POLICY_NONCOHERENT) {
381
382 if (args.default_policy != KFD_IOC_CACHE_POLICY_COHERENT
383 && args.default_policy != KFD_IOC_CACHE_POLICY_NONCOHERENT) {
384 return -EINVAL; 361 return -EINVAL;
385 } 362 }
386 363
387 if (args.alternate_policy != KFD_IOC_CACHE_POLICY_COHERENT 364 if (args->alternate_policy != KFD_IOC_CACHE_POLICY_COHERENT
388 && args.alternate_policy != KFD_IOC_CACHE_POLICY_NONCOHERENT) { 365 && args->alternate_policy != KFD_IOC_CACHE_POLICY_NONCOHERENT) {
389 return -EINVAL; 366 return -EINVAL;
390 } 367 }
391 368
392 dev = kfd_device_by_id(args.gpu_id); 369 dev = kfd_device_by_id(args->gpu_id);
393 if (dev == NULL) 370 if (dev == NULL)
394 return -EINVAL; 371 return -EINVAL;
395 372
@@ -397,23 +374,23 @@ static long kfd_ioctl_set_memory_policy(struct file *filep,
397 374
398 pdd = kfd_bind_process_to_device(dev, p); 375 pdd = kfd_bind_process_to_device(dev, p);
399 if (IS_ERR(pdd)) { 376 if (IS_ERR(pdd)) {
400 err = PTR_ERR(pdd); 377 err = -ESRCH;
401 goto out; 378 goto out;
402 } 379 }
403 380
404 default_policy = (args.default_policy == KFD_IOC_CACHE_POLICY_COHERENT) 381 default_policy = (args->default_policy == KFD_IOC_CACHE_POLICY_COHERENT)
405 ? cache_policy_coherent : cache_policy_noncoherent; 382 ? cache_policy_coherent : cache_policy_noncoherent;
406 383
407 alternate_policy = 384 alternate_policy =
408 (args.alternate_policy == KFD_IOC_CACHE_POLICY_COHERENT) 385 (args->alternate_policy == KFD_IOC_CACHE_POLICY_COHERENT)
409 ? cache_policy_coherent : cache_policy_noncoherent; 386 ? cache_policy_coherent : cache_policy_noncoherent;
410 387
411 if (!dev->dqm->set_cache_memory_policy(dev->dqm, 388 if (!dev->dqm->set_cache_memory_policy(dev->dqm,
412 &pdd->qpd, 389 &pdd->qpd,
413 default_policy, 390 default_policy,
414 alternate_policy, 391 alternate_policy,
415 (void __user *)args.alternate_aperture_base, 392 (void __user *)args->alternate_aperture_base,
416 args.alternate_aperture_size)) 393 args->alternate_aperture_size))
417 err = -EINVAL; 394 err = -EINVAL;
418 395
419out: 396out:
@@ -422,53 +399,44 @@ out:
422 return err; 399 return err;
423} 400}
424 401
425static long kfd_ioctl_get_clock_counters(struct file *filep, 402static int kfd_ioctl_get_clock_counters(struct file *filep,
426 struct kfd_process *p, void __user *arg) 403 struct kfd_process *p, void *data)
427{ 404{
428 struct kfd_ioctl_get_clock_counters_args args; 405 struct kfd_ioctl_get_clock_counters_args *args = data;
429 struct kfd_dev *dev; 406 struct kfd_dev *dev;
430 struct timespec time; 407 struct timespec time;
431 408
432 if (copy_from_user(&args, arg, sizeof(args))) 409 dev = kfd_device_by_id(args->gpu_id);
433 return -EFAULT;
434
435 dev = kfd_device_by_id(args.gpu_id);
436 if (dev == NULL) 410 if (dev == NULL)
437 return -EINVAL; 411 return -EINVAL;
438 412
439 /* Reading GPU clock counter from KGD */ 413 /* Reading GPU clock counter from KGD */
440 args.gpu_clock_counter = kfd2kgd->get_gpu_clock_counter(dev->kgd); 414 args->gpu_clock_counter = kfd2kgd->get_gpu_clock_counter(dev->kgd);
441 415
442 /* No access to rdtsc. Using raw monotonic time */ 416 /* No access to rdtsc. Using raw monotonic time */
443 getrawmonotonic(&time); 417 getrawmonotonic(&time);
444 args.cpu_clock_counter = (uint64_t)timespec_to_ns(&time); 418 args->cpu_clock_counter = (uint64_t)timespec_to_ns(&time);
445 419
446 get_monotonic_boottime(&time); 420 get_monotonic_boottime(&time);
447 args.system_clock_counter = (uint64_t)timespec_to_ns(&time); 421 args->system_clock_counter = (uint64_t)timespec_to_ns(&time);
448 422
449 /* Since the counter is in nano-seconds we use 1GHz frequency */ 423 /* Since the counter is in nano-seconds we use 1GHz frequency */
450 args.system_clock_freq = 1000000000; 424 args->system_clock_freq = 1000000000;
451
452 if (copy_to_user(arg, &args, sizeof(args)))
453 return -EFAULT;
454 425
455 return 0; 426 return 0;
456} 427}
457 428
458 429
459static int kfd_ioctl_get_process_apertures(struct file *filp, 430static int kfd_ioctl_get_process_apertures(struct file *filp,
460 struct kfd_process *p, void __user *arg) 431 struct kfd_process *p, void *data)
461{ 432{
462 struct kfd_ioctl_get_process_apertures_args args; 433 struct kfd_ioctl_get_process_apertures_args *args = data;
463 struct kfd_process_device_apertures *pAperture; 434 struct kfd_process_device_apertures *pAperture;
464 struct kfd_process_device *pdd; 435 struct kfd_process_device *pdd;
465 436
466 dev_dbg(kfd_device, "get apertures for PASID %d", p->pasid); 437 dev_dbg(kfd_device, "get apertures for PASID %d", p->pasid);
467 438
468 if (copy_from_user(&args, arg, sizeof(args))) 439 args->num_of_nodes = 0;
469 return -EFAULT;
470
471 args.num_of_nodes = 0;
472 440
473 mutex_lock(&p->mutex); 441 mutex_lock(&p->mutex);
474 442
@@ -477,7 +445,8 @@ static int kfd_ioctl_get_process_apertures(struct file *filp,
477 /* Run over all pdd of the process */ 445 /* Run over all pdd of the process */
478 pdd = kfd_get_first_process_device_data(p); 446 pdd = kfd_get_first_process_device_data(p);
479 do { 447 do {
480 pAperture = &args.process_apertures[args.num_of_nodes]; 448 pAperture =
449 &args->process_apertures[args->num_of_nodes];
481 pAperture->gpu_id = pdd->dev->id; 450 pAperture->gpu_id = pdd->dev->id;
482 pAperture->lds_base = pdd->lds_base; 451 pAperture->lds_base = pdd->lds_base;
483 pAperture->lds_limit = pdd->lds_limit; 452 pAperture->lds_limit = pdd->lds_limit;
@@ -487,7 +456,7 @@ static int kfd_ioctl_get_process_apertures(struct file *filp,
487 pAperture->scratch_limit = pdd->scratch_limit; 456 pAperture->scratch_limit = pdd->scratch_limit;
488 457
489 dev_dbg(kfd_device, 458 dev_dbg(kfd_device,
490 "node id %u\n", args.num_of_nodes); 459 "node id %u\n", args->num_of_nodes);
491 dev_dbg(kfd_device, 460 dev_dbg(kfd_device,
492 "gpu id %u\n", pdd->dev->id); 461 "gpu id %u\n", pdd->dev->id);
493 dev_dbg(kfd_device, 462 dev_dbg(kfd_device,
@@ -503,80 +472,131 @@ static int kfd_ioctl_get_process_apertures(struct file *filp,
503 dev_dbg(kfd_device, 472 dev_dbg(kfd_device,
504 "scratch_limit %llX\n", pdd->scratch_limit); 473 "scratch_limit %llX\n", pdd->scratch_limit);
505 474
506 args.num_of_nodes++; 475 args->num_of_nodes++;
507 } while ((pdd = kfd_get_next_process_device_data(p, pdd)) != NULL && 476 } while ((pdd = kfd_get_next_process_device_data(p, pdd)) != NULL &&
508 (args.num_of_nodes < NUM_OF_SUPPORTED_GPUS)); 477 (args->num_of_nodes < NUM_OF_SUPPORTED_GPUS));
509 } 478 }
510 479
511 mutex_unlock(&p->mutex); 480 mutex_unlock(&p->mutex);
512 481
513 if (copy_to_user(arg, &args, sizeof(args)))
514 return -EFAULT;
515
516 return 0; 482 return 0;
517} 483}
518 484
485#define AMDKFD_IOCTL_DEF(ioctl, _func, _flags) \
486 [_IOC_NR(ioctl)] = {.cmd = ioctl, .func = _func, .flags = _flags, .cmd_drv = 0, .name = #ioctl}
487
488/** Ioctl table */
489static const struct amdkfd_ioctl_desc amdkfd_ioctls[] = {
490 AMDKFD_IOCTL_DEF(AMDKFD_IOC_GET_VERSION,
491 kfd_ioctl_get_version, 0),
492
493 AMDKFD_IOCTL_DEF(AMDKFD_IOC_CREATE_QUEUE,
494 kfd_ioctl_create_queue, 0),
495
496 AMDKFD_IOCTL_DEF(AMDKFD_IOC_DESTROY_QUEUE,
497 kfd_ioctl_destroy_queue, 0),
498
499 AMDKFD_IOCTL_DEF(AMDKFD_IOC_SET_MEMORY_POLICY,
500 kfd_ioctl_set_memory_policy, 0),
501
502 AMDKFD_IOCTL_DEF(AMDKFD_IOC_GET_CLOCK_COUNTERS,
503 kfd_ioctl_get_clock_counters, 0),
504
505 AMDKFD_IOCTL_DEF(AMDKFD_IOC_GET_PROCESS_APERTURES,
506 kfd_ioctl_get_process_apertures, 0),
507
508 AMDKFD_IOCTL_DEF(AMDKFD_IOC_UPDATE_QUEUE,
509 kfd_ioctl_update_queue, 0),
510};
511
512#define AMDKFD_CORE_IOCTL_COUNT ARRAY_SIZE(amdkfd_ioctls)
513
519static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) 514static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
520{ 515{
521 struct kfd_process *process; 516 struct kfd_process *process;
522 long err = -EINVAL; 517 amdkfd_ioctl_t *func;
518 const struct amdkfd_ioctl_desc *ioctl = NULL;
519 unsigned int nr = _IOC_NR(cmd);
520 char stack_kdata[128];
521 char *kdata = NULL;
522 unsigned int usize, asize;
523 int retcode = -EINVAL;
523 524
524 dev_dbg(kfd_device, 525 if (nr >= AMDKFD_CORE_IOCTL_COUNT)
525 "ioctl cmd 0x%x (#%d), arg 0x%lx\n", 526 goto err_i1;
526 cmd, _IOC_NR(cmd), arg); 527
528 if ((nr >= AMDKFD_COMMAND_START) && (nr < AMDKFD_COMMAND_END)) {
529 u32 amdkfd_size;
530
531 ioctl = &amdkfd_ioctls[nr];
532
533 amdkfd_size = _IOC_SIZE(ioctl->cmd);
534 usize = asize = _IOC_SIZE(cmd);
535 if (amdkfd_size > asize)
536 asize = amdkfd_size;
537
538 cmd = ioctl->cmd;
539 } else
540 goto err_i1;
541
542 dev_dbg(kfd_device, "ioctl cmd 0x%x (#%d), arg 0x%lx\n", cmd, nr, arg);
527 543
528 process = kfd_get_process(current); 544 process = kfd_get_process(current);
529 if (IS_ERR(process)) 545 if (IS_ERR(process)) {
530 return PTR_ERR(process); 546 dev_dbg(kfd_device, "no process\n");
547 goto err_i1;
548 }
531 549
532 switch (cmd) { 550 /* Do not trust userspace, use our own definition */
533 case KFD_IOC_GET_VERSION: 551 func = ioctl->func;
534 err = kfd_ioctl_get_version(filep, process, (void __user *)arg); 552
535 break; 553 if (unlikely(!func)) {
536 case KFD_IOC_CREATE_QUEUE: 554 dev_dbg(kfd_device, "no function\n");
537 err = kfd_ioctl_create_queue(filep, process, 555 retcode = -EINVAL;
538 (void __user *)arg); 556 goto err_i1;
539 break;
540
541 case KFD_IOC_DESTROY_QUEUE:
542 err = kfd_ioctl_destroy_queue(filep, process,
543 (void __user *)arg);
544 break;
545
546 case KFD_IOC_SET_MEMORY_POLICY:
547 err = kfd_ioctl_set_memory_policy(filep, process,
548 (void __user *)arg);
549 break;
550
551 case KFD_IOC_GET_CLOCK_COUNTERS:
552 err = kfd_ioctl_get_clock_counters(filep, process,
553 (void __user *)arg);
554 break;
555
556 case KFD_IOC_GET_PROCESS_APERTURES:
557 err = kfd_ioctl_get_process_apertures(filep, process,
558 (void __user *)arg);
559 break;
560
561 case KFD_IOC_UPDATE_QUEUE:
562 err = kfd_ioctl_update_queue(filep, process,
563 (void __user *)arg);
564 break;
565
566 default:
567 dev_err(kfd_device,
568 "unknown ioctl cmd 0x%x, arg 0x%lx)\n",
569 cmd, arg);
570 err = -EINVAL;
571 break;
572 } 557 }
573 558
574 if (err < 0) 559 if (cmd & (IOC_IN | IOC_OUT)) {
575 dev_err(kfd_device, 560 if (asize <= sizeof(stack_kdata)) {
576 "ioctl error %ld for ioctl cmd 0x%x (#%d)\n", 561 kdata = stack_kdata;
577 err, cmd, _IOC_NR(cmd)); 562 } else {
563 kdata = kmalloc(asize, GFP_KERNEL);
564 if (!kdata) {
565 retcode = -ENOMEM;
566 goto err_i1;
567 }
568 }
569 if (asize > usize)
570 memset(kdata + usize, 0, asize - usize);
571 }
578 572
579 return err; 573 if (cmd & IOC_IN) {
574 if (copy_from_user(kdata, (void __user *)arg, usize) != 0) {
575 retcode = -EFAULT;
576 goto err_i1;
577 }
578 } else if (cmd & IOC_OUT) {
579 memset(kdata, 0, usize);
580 }
581
582 retcode = func(filep, process, kdata);
583
584 if (cmd & IOC_OUT)
585 if (copy_to_user((void __user *)arg, kdata, usize) != 0)
586 retcode = -EFAULT;
587
588err_i1:
589 if (!ioctl)
590 dev_dbg(kfd_device, "invalid ioctl: pid=%d, cmd=0x%02x, nr=0x%02x\n",
591 task_pid_nr(current), cmd, nr);
592
593 if (kdata != stack_kdata)
594 kfree(kdata);
595
596 if (retcode)
597 dev_dbg(kfd_device, "ret = %d\n", retcode);
598
599 return retcode;
580} 600}
581 601
582static int kfd_mmap(struct file *filp, struct vm_area_struct *vma) 602static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
index 924e90c072e5..9c8961d22360 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -161,6 +161,9 @@ static void deallocate_vmid(struct device_queue_manager *dqm,
161{ 161{
162 int bit = qpd->vmid - KFD_VMID_START_OFFSET; 162 int bit = qpd->vmid - KFD_VMID_START_OFFSET;
163 163
164 /* Release the vmid mapping */
165 set_pasid_vmid_mapping(dqm, 0, qpd->vmid);
166
164 set_bit(bit, (unsigned long *)&dqm->vmid_bitmap); 167 set_bit(bit, (unsigned long *)&dqm->vmid_bitmap);
165 qpd->vmid = 0; 168 qpd->vmid = 0;
166 q->properties.vmid = 0; 169 q->properties.vmid = 0;
@@ -272,6 +275,18 @@ static int create_compute_queue_nocpsch(struct device_queue_manager *dqm,
272 return retval; 275 return retval;
273 } 276 }
274 277
278 pr_debug("kfd: loading mqd to hqd on pipe (%d) queue (%d)\n",
279 q->pipe,
280 q->queue);
281
282 retval = mqd->load_mqd(mqd, q->mqd, q->pipe,
283 q->queue, q->properties.write_ptr);
284 if (retval != 0) {
285 deallocate_hqd(dqm, q);
286 mqd->uninit_mqd(mqd, q->mqd, q->mqd_mem_obj);
287 return retval;
288 }
289
275 return 0; 290 return 0;
276} 291}
277 292
@@ -320,6 +335,7 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q)
320{ 335{
321 int retval; 336 int retval;
322 struct mqd_manager *mqd; 337 struct mqd_manager *mqd;
338 bool prev_active = false;
323 339
324 BUG_ON(!dqm || !q || !q->mqd); 340 BUG_ON(!dqm || !q || !q->mqd);
325 341
@@ -330,10 +346,18 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q)
330 return -ENOMEM; 346 return -ENOMEM;
331 } 347 }
332 348
333 retval = mqd->update_mqd(mqd, q->mqd, &q->properties);
334 if (q->properties.is_active == true) 349 if (q->properties.is_active == true)
350 prev_active = true;
351
352 /*
353 *
354 * check active state vs. the previous state
355 * and modify counter accordingly
356 */
357 retval = mqd->update_mqd(mqd, q->mqd, &q->properties);
358 if ((q->properties.is_active == true) && (prev_active == false))
335 dqm->queue_count++; 359 dqm->queue_count++;
336 else 360 else if ((q->properties.is_active == false) && (prev_active == true))
337 dqm->queue_count--; 361 dqm->queue_count--;
338 362
339 if (sched_policy != KFD_SCHED_POLICY_NO_HWS) 363 if (sched_policy != KFD_SCHED_POLICY_NO_HWS)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
index adc31474e786..4c3828cf45bf 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
@@ -184,7 +184,7 @@ static bool is_occupied(struct mqd_manager *mm, void *mqd,
184 uint32_t queue_id) 184 uint32_t queue_id)
185{ 185{
186 186
187 return kfd2kgd->hqd_is_occupies(mm->dev->kgd, queue_address, 187 return kfd2kgd->hqd_is_occupied(mm->dev->kgd, queue_address,
188 pipe_id, queue_id); 188 pipe_id, queue_id);
189 189
190} 190}
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_pasid.c b/drivers/gpu/drm/amd/amdkfd/kfd_pasid.c
index 71699ad97d74..4c25ef504f79 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_pasid.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_pasid.c
@@ -32,7 +32,7 @@ int kfd_pasid_init(void)
32{ 32{
33 pasid_limit = max_num_of_processes; 33 pasid_limit = max_num_of_processes;
34 34
35 pasid_bitmap = kzalloc(BITS_TO_LONGS(pasid_limit), GFP_KERNEL); 35 pasid_bitmap = kcalloc(BITS_TO_LONGS(pasid_limit), sizeof(long), GFP_KERNEL);
36 if (!pasid_bitmap) 36 if (!pasid_bitmap)
37 return -ENOMEM; 37 return -ENOMEM;
38 38
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
index f9fb81e3bb09..a5edb29507e3 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
@@ -463,6 +463,24 @@ struct kfd_process {
463 bool is_32bit_user_mode; 463 bool is_32bit_user_mode;
464}; 464};
465 465
466/**
467 * Ioctl function type.
468 *
469 * \param filep pointer to file structure.
470 * \param p amdkfd process pointer.
471 * \param data pointer to arg that was copied from user.
472 */
473typedef int amdkfd_ioctl_t(struct file *filep, struct kfd_process *p,
474 void *data);
475
476struct amdkfd_ioctl_desc {
477 unsigned int cmd;
478 int flags;
479 amdkfd_ioctl_t *func;
480 unsigned int cmd_drv;
481 const char *name;
482};
483
466void kfd_process_create_wq(void); 484void kfd_process_create_wq(void);
467void kfd_process_destroy_wq(void); 485void kfd_process_destroy_wq(void);
468struct kfd_process *kfd_create_process(const struct task_struct *); 486struct kfd_process *kfd_create_process(const struct task_struct *);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
index b11792d7e70e..cca1708fd811 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
@@ -921,7 +921,7 @@ static int kfd_build_sysfs_node_tree(void)
921 uint32_t i = 0; 921 uint32_t i = 0;
922 922
923 list_for_each_entry(dev, &topology_device_list, list) { 923 list_for_each_entry(dev, &topology_device_list, list) {
924 ret = kfd_build_sysfs_node_entry(dev, 0); 924 ret = kfd_build_sysfs_node_entry(dev, i);
925 if (ret < 0) 925 if (ret < 0)
926 return ret; 926 return ret;
927 i++; 927 i++;
diff --git a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
index 47b551970a14..96a512208fad 100644
--- a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
@@ -183,7 +183,7 @@ struct kfd2kgd_calls {
183 int (*hqd_load)(struct kgd_dev *kgd, void *mqd, uint32_t pipe_id, 183 int (*hqd_load)(struct kgd_dev *kgd, void *mqd, uint32_t pipe_id,
184 uint32_t queue_id, uint32_t __user *wptr); 184 uint32_t queue_id, uint32_t __user *wptr);
185 185
186 bool (*hqd_is_occupies)(struct kgd_dev *kgd, uint64_t queue_address, 186 bool (*hqd_is_occupied)(struct kgd_dev *kgd, uint64_t queue_address,
187 uint32_t pipe_id, uint32_t queue_id); 187 uint32_t pipe_id, uint32_t queue_id);
188 188
189 int (*hqd_destroy)(struct kgd_dev *kgd, uint32_t reset_type, 189 int (*hqd_destroy)(struct kgd_dev *kgd, uint32_t reset_type,
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 70d0f0f06f1a..e9f891c432f8 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1756,8 +1756,6 @@ struct drm_i915_private {
1756 */ 1756 */
1757 struct workqueue_struct *dp_wq; 1757 struct workqueue_struct *dp_wq;
1758 1758
1759 uint32_t bios_vgacntr;
1760
1761 /* Abstract the submission mechanism (legacy ringbuffer or execlists) away */ 1759 /* Abstract the submission mechanism (legacy ringbuffer or execlists) away */
1762 struct { 1760 struct {
1763 int (*do_execbuf)(struct drm_device *dev, struct drm_file *file, 1761 int (*do_execbuf)(struct drm_device *dev, struct drm_file *file,
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 52adcb680be3..c11603b4cf1d 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1048,6 +1048,7 @@ int
1048i915_gem_pwrite_ioctl(struct drm_device *dev, void *data, 1048i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
1049 struct drm_file *file) 1049 struct drm_file *file)
1050{ 1050{
1051 struct drm_i915_private *dev_priv = dev->dev_private;
1051 struct drm_i915_gem_pwrite *args = data; 1052 struct drm_i915_gem_pwrite *args = data;
1052 struct drm_i915_gem_object *obj; 1053 struct drm_i915_gem_object *obj;
1053 int ret; 1054 int ret;
@@ -1067,9 +1068,11 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
1067 return -EFAULT; 1068 return -EFAULT;
1068 } 1069 }
1069 1070
1071 intel_runtime_pm_get(dev_priv);
1072
1070 ret = i915_mutex_lock_interruptible(dev); 1073 ret = i915_mutex_lock_interruptible(dev);
1071 if (ret) 1074 if (ret)
1072 return ret; 1075 goto put_rpm;
1073 1076
1074 obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle)); 1077 obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle));
1075 if (&obj->base == NULL) { 1078 if (&obj->base == NULL) {
@@ -1121,6 +1124,9 @@ out:
1121 drm_gem_object_unreference(&obj->base); 1124 drm_gem_object_unreference(&obj->base);
1122unlock: 1125unlock:
1123 mutex_unlock(&dev->struct_mutex); 1126 mutex_unlock(&dev->struct_mutex);
1127put_rpm:
1128 intel_runtime_pm_put(dev_priv);
1129
1124 return ret; 1130 return ret;
1125} 1131}
1126 1132
diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
index 996c2931c499..d0d3dfbe6d2a 100644
--- a/drivers/gpu/drm/i915/i915_irq.c
+++ b/drivers/gpu/drm/i915/i915_irq.c
@@ -3725,8 +3725,6 @@ static bool i8xx_handle_vblank(struct drm_device *dev,
3725 if ((iir & flip_pending) == 0) 3725 if ((iir & flip_pending) == 0)
3726 goto check_page_flip; 3726 goto check_page_flip;
3727 3727
3728 intel_prepare_page_flip(dev, plane);
3729
3730 /* We detect FlipDone by looking for the change in PendingFlip from '1' 3728 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3731 * to '0' on the following vblank, i.e. IIR has the Pendingflip 3729 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3732 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence 3730 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
@@ -3736,6 +3734,7 @@ static bool i8xx_handle_vblank(struct drm_device *dev,
3736 if (I915_READ16(ISR) & flip_pending) 3734 if (I915_READ16(ISR) & flip_pending)
3737 goto check_page_flip; 3735 goto check_page_flip;
3738 3736
3737 intel_prepare_page_flip(dev, plane);
3739 intel_finish_page_flip(dev, pipe); 3738 intel_finish_page_flip(dev, pipe);
3740 return true; 3739 return true;
3741 3740
@@ -3907,8 +3906,6 @@ static bool i915_handle_vblank(struct drm_device *dev,
3907 if ((iir & flip_pending) == 0) 3906 if ((iir & flip_pending) == 0)
3908 goto check_page_flip; 3907 goto check_page_flip;
3909 3908
3910 intel_prepare_page_flip(dev, plane);
3911
3912 /* We detect FlipDone by looking for the change in PendingFlip from '1' 3909 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3913 * to '0' on the following vblank, i.e. IIR has the Pendingflip 3910 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3914 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence 3911 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
@@ -3918,6 +3915,7 @@ static bool i915_handle_vblank(struct drm_device *dev,
3918 if (I915_READ(ISR) & flip_pending) 3915 if (I915_READ(ISR) & flip_pending)
3919 goto check_page_flip; 3916 goto check_page_flip;
3920 3917
3918 intel_prepare_page_flip(dev, plane);
3921 intel_finish_page_flip(dev, pipe); 3919 intel_finish_page_flip(dev, pipe);
3922 return true; 3920 return true;
3923 3921
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index fb3e3d429191..e2af1383b179 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -13057,11 +13057,7 @@ static void i915_disable_vga(struct drm_device *dev)
13057 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); 13057 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
13058 udelay(300); 13058 udelay(300);
13059 13059
13060 /* 13060 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
13061 * Fujitsu-Siemens Lifebook S6010 (830) has problems resuming
13062 * from S3 without preserving (some of?) the other bits.
13063 */
13064 I915_WRITE(vga_reg, dev_priv->bios_vgacntr | VGA_DISP_DISABLE);
13065 POSTING_READ(vga_reg); 13061 POSTING_READ(vga_reg);
13066} 13062}
13067 13063
@@ -13146,8 +13142,6 @@ void intel_modeset_init(struct drm_device *dev)
13146 13142
13147 intel_shared_dpll_init(dev); 13143 intel_shared_dpll_init(dev);
13148 13144
13149 /* save the BIOS value before clobbering it */
13150 dev_priv->bios_vgacntr = I915_READ(i915_vgacntrl_reg(dev));
13151 /* Just disable it once at startup */ 13145 /* Just disable it once at startup */
13152 i915_disable_vga(dev); 13146 i915_disable_vga(dev);
13153 intel_setup_outputs(dev); 13147 intel_setup_outputs(dev);
diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.c b/drivers/gpu/drm/i915/intel_runtime_pm.c
index f5a78d53e297..ac6da7102fbb 100644
--- a/drivers/gpu/drm/i915/intel_runtime_pm.c
+++ b/drivers/gpu/drm/i915/intel_runtime_pm.c
@@ -615,29 +615,6 @@ static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
615 vlv_power_sequencer_reset(dev_priv); 615 vlv_power_sequencer_reset(dev_priv);
616} 616}
617 617
618static void check_power_well_state(struct drm_i915_private *dev_priv,
619 struct i915_power_well *power_well)
620{
621 bool enabled = power_well->ops->is_enabled(dev_priv, power_well);
622
623 if (power_well->always_on || !i915.disable_power_well) {
624 if (!enabled)
625 goto mismatch;
626
627 return;
628 }
629
630 if (enabled != (power_well->count > 0))
631 goto mismatch;
632
633 return;
634
635mismatch:
636 WARN(1, "state mismatch for '%s' (always_on %d hw state %d use-count %d disable_power_well %d\n",
637 power_well->name, power_well->always_on, enabled,
638 power_well->count, i915.disable_power_well);
639}
640
641/** 618/**
642 * intel_display_power_get - grab a power domain reference 619 * intel_display_power_get - grab a power domain reference
643 * @dev_priv: i915 device instance 620 * @dev_priv: i915 device instance
@@ -669,8 +646,6 @@ void intel_display_power_get(struct drm_i915_private *dev_priv,
669 power_well->ops->enable(dev_priv, power_well); 646 power_well->ops->enable(dev_priv, power_well);
670 power_well->hw_enabled = true; 647 power_well->hw_enabled = true;
671 } 648 }
672
673 check_power_well_state(dev_priv, power_well);
674 } 649 }
675 650
676 power_domains->domain_use_count[domain]++; 651 power_domains->domain_use_count[domain]++;
@@ -709,8 +684,6 @@ void intel_display_power_put(struct drm_i915_private *dev_priv,
709 power_well->hw_enabled = false; 684 power_well->hw_enabled = false;
710 power_well->ops->disable(dev_priv, power_well); 685 power_well->ops->disable(dev_priv, power_well);
711 } 686 }
712
713 check_power_well_state(dev_priv, power_well);
714 } 687 }
715 688
716 mutex_unlock(&power_domains->lock); 689 mutex_unlock(&power_domains->lock);
diff --git a/drivers/gpu/drm/nouveau/core/core/event.c b/drivers/gpu/drm/nouveau/core/core/event.c
index ff2b434b3db4..760947e380c9 100644
--- a/drivers/gpu/drm/nouveau/core/core/event.c
+++ b/drivers/gpu/drm/nouveau/core/core/event.c
@@ -26,7 +26,7 @@
26void 26void
27nvkm_event_put(struct nvkm_event *event, u32 types, int index) 27nvkm_event_put(struct nvkm_event *event, u32 types, int index)
28{ 28{
29 BUG_ON(!spin_is_locked(&event->refs_lock)); 29 assert_spin_locked(&event->refs_lock);
30 while (types) { 30 while (types) {
31 int type = __ffs(types); types &= ~(1 << type); 31 int type = __ffs(types); types &= ~(1 << type);
32 if (--event->refs[index * event->types_nr + type] == 0) { 32 if (--event->refs[index * event->types_nr + type] == 0) {
@@ -39,7 +39,7 @@ nvkm_event_put(struct nvkm_event *event, u32 types, int index)
39void 39void
40nvkm_event_get(struct nvkm_event *event, u32 types, int index) 40nvkm_event_get(struct nvkm_event *event, u32 types, int index)
41{ 41{
42 BUG_ON(!spin_is_locked(&event->refs_lock)); 42 assert_spin_locked(&event->refs_lock);
43 while (types) { 43 while (types) {
44 int type = __ffs(types); types &= ~(1 << type); 44 int type = __ffs(types); types &= ~(1 << type);
45 if (++event->refs[index * event->types_nr + type] == 1) { 45 if (++event->refs[index * event->types_nr + type] == 1) {
diff --git a/drivers/gpu/drm/nouveau/core/core/notify.c b/drivers/gpu/drm/nouveau/core/core/notify.c
index d1bcde55e9d7..839a32577680 100644
--- a/drivers/gpu/drm/nouveau/core/core/notify.c
+++ b/drivers/gpu/drm/nouveau/core/core/notify.c
@@ -98,7 +98,7 @@ nvkm_notify_send(struct nvkm_notify *notify, void *data, u32 size)
98 struct nvkm_event *event = notify->event; 98 struct nvkm_event *event = notify->event;
99 unsigned long flags; 99 unsigned long flags;
100 100
101 BUG_ON(!spin_is_locked(&event->list_lock)); 101 assert_spin_locked(&event->list_lock);
102 BUG_ON(size != notify->size); 102 BUG_ON(size != notify->size);
103 103
104 spin_lock_irqsave(&event->refs_lock, flags); 104 spin_lock_irqsave(&event->refs_lock, flags);
diff --git a/drivers/gpu/drm/nouveau/core/engine/device/nve0.c b/drivers/gpu/drm/nouveau/core/engine/device/nve0.c
index 674da1f095b2..732922690653 100644
--- a/drivers/gpu/drm/nouveau/core/engine/device/nve0.c
+++ b/drivers/gpu/drm/nouveau/core/engine/device/nve0.c
@@ -249,6 +249,39 @@ nve0_identify(struct nouveau_device *device)
249 device->oclass[NVDEV_ENGINE_PPP ] = &nvc0_ppp_oclass; 249 device->oclass[NVDEV_ENGINE_PPP ] = &nvc0_ppp_oclass;
250 device->oclass[NVDEV_ENGINE_PERFMON] = &nvf0_perfmon_oclass; 250 device->oclass[NVDEV_ENGINE_PERFMON] = &nvf0_perfmon_oclass;
251 break; 251 break;
252 case 0x106:
253 device->cname = "GK208B";
254 device->oclass[NVDEV_SUBDEV_VBIOS ] = &nouveau_bios_oclass;
255 device->oclass[NVDEV_SUBDEV_GPIO ] = nve0_gpio_oclass;
256 device->oclass[NVDEV_SUBDEV_I2C ] = nve0_i2c_oclass;
257 device->oclass[NVDEV_SUBDEV_FUSE ] = &gf100_fuse_oclass;
258 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nve0_clock_oclass;
259 device->oclass[NVDEV_SUBDEV_THERM ] = &nvd0_therm_oclass;
260 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass;
261 device->oclass[NVDEV_SUBDEV_DEVINIT] = nvc0_devinit_oclass;
262 device->oclass[NVDEV_SUBDEV_MC ] = gk20a_mc_oclass;
263 device->oclass[NVDEV_SUBDEV_BUS ] = nvc0_bus_oclass;
264 device->oclass[NVDEV_SUBDEV_TIMER ] = &nv04_timer_oclass;
265 device->oclass[NVDEV_SUBDEV_FB ] = nve0_fb_oclass;
266 device->oclass[NVDEV_SUBDEV_LTC ] = gk104_ltc_oclass;
267 device->oclass[NVDEV_SUBDEV_IBUS ] = &nve0_ibus_oclass;
268 device->oclass[NVDEV_SUBDEV_INSTMEM] = nv50_instmem_oclass;
269 device->oclass[NVDEV_SUBDEV_VM ] = &nvc0_vmmgr_oclass;
270 device->oclass[NVDEV_SUBDEV_BAR ] = &nvc0_bar_oclass;
271 device->oclass[NVDEV_SUBDEV_PWR ] = nv108_pwr_oclass;
272 device->oclass[NVDEV_SUBDEV_VOLT ] = &nv40_volt_oclass;
273 device->oclass[NVDEV_ENGINE_DMAOBJ ] = nvd0_dmaeng_oclass;
274 device->oclass[NVDEV_ENGINE_FIFO ] = nv108_fifo_oclass;
275 device->oclass[NVDEV_ENGINE_SW ] = nvc0_software_oclass;
276 device->oclass[NVDEV_ENGINE_GR ] = nv108_graph_oclass;
277 device->oclass[NVDEV_ENGINE_DISP ] = nvf0_disp_oclass;
278 device->oclass[NVDEV_ENGINE_COPY0 ] = &nve0_copy0_oclass;
279 device->oclass[NVDEV_ENGINE_COPY1 ] = &nve0_copy1_oclass;
280 device->oclass[NVDEV_ENGINE_COPY2 ] = &nve0_copy2_oclass;
281 device->oclass[NVDEV_ENGINE_BSP ] = &nve0_bsp_oclass;
282 device->oclass[NVDEV_ENGINE_VP ] = &nve0_vp_oclass;
283 device->oclass[NVDEV_ENGINE_PPP ] = &nvc0_ppp_oclass;
284 break;
252 case 0x108: 285 case 0x108:
253 device->cname = "GK208"; 286 device->cname = "GK208";
254 device->oclass[NVDEV_SUBDEV_VBIOS ] = &nouveau_bios_oclass; 287 device->oclass[NVDEV_SUBDEV_VBIOS ] = &nouveau_bios_oclass;
diff --git a/drivers/gpu/drm/nouveau/core/subdev/bios/shadowramin.c b/drivers/gpu/drm/nouveau/core/subdev/bios/shadowramin.c
index 5e58bba0dd5c..a7a890fad1e5 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/bios/shadowramin.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/bios/shadowramin.c
@@ -44,8 +44,10 @@ static void
44pramin_fini(void *data) 44pramin_fini(void *data)
45{ 45{
46 struct priv *priv = data; 46 struct priv *priv = data;
47 nv_wr32(priv->bios, 0x001700, priv->bar0); 47 if (priv) {
48 kfree(priv); 48 nv_wr32(priv->bios, 0x001700, priv->bar0);
49 kfree(priv);
50 }
49} 51}
50 52
51static void * 53static void *
diff --git a/drivers/gpu/drm/nouveau/core/subdev/fb/ramnvaa.c b/drivers/gpu/drm/nouveau/core/subdev/fb/ramnvaa.c
index 00f2ca7e44a5..033a8e999497 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/fb/ramnvaa.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/fb/ramnvaa.c
@@ -24,34 +24,71 @@
24 24
25#include "nv50.h" 25#include "nv50.h"
26 26
27struct nvaa_ram_priv {
28 struct nouveau_ram base;
29 u64 poller_base;
30};
31
27static int 32static int
28nvaa_ram_ctor(struct nouveau_object *parent, struct nouveau_object *engine, 33nvaa_ram_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
29 struct nouveau_oclass *oclass, void *data, u32 datasize, 34 struct nouveau_oclass *oclass, void *data, u32 datasize,
30 struct nouveau_object **pobject) 35 struct nouveau_object **pobject)
31{ 36{
32 const u32 rsvd_head = ( 256 * 1024) >> 12; /* vga memory */ 37 u32 rsvd_head = ( 256 * 1024); /* vga memory */
33 const u32 rsvd_tail = (1024 * 1024) >> 12; /* vbios etc */ 38 u32 rsvd_tail = (1024 * 1024); /* vbios etc */
34 struct nouveau_fb *pfb = nouveau_fb(parent); 39 struct nouveau_fb *pfb = nouveau_fb(parent);
35 struct nouveau_ram *ram; 40 struct nvaa_ram_priv *priv;
36 int ret; 41 int ret;
37 42
38 ret = nouveau_ram_create(parent, engine, oclass, &ram); 43 ret = nouveau_ram_create(parent, engine, oclass, &priv);
39 *pobject = nv_object(ram); 44 *pobject = nv_object(priv);
40 if (ret) 45 if (ret)
41 return ret; 46 return ret;
42 47
43 ram->size = nv_rd32(pfb, 0x10020c); 48 priv->base.type = NV_MEM_TYPE_STOLEN;
44 ram->size = (ram->size & 0xffffff00) | ((ram->size & 0x000000ff) << 32); 49 priv->base.stolen = (u64)nv_rd32(pfb, 0x100e10) << 12;
50 priv->base.size = (u64)nv_rd32(pfb, 0x100e14) << 12;
45 51
46 ret = nouveau_mm_init(&pfb->vram, rsvd_head, (ram->size >> 12) - 52 rsvd_tail += 0x1000;
47 (rsvd_head + rsvd_tail), 1); 53 priv->poller_base = priv->base.size - rsvd_tail;
54
55 ret = nouveau_mm_init(&pfb->vram, rsvd_head >> 12,
56 (priv->base.size - (rsvd_head + rsvd_tail)) >> 12,
57 1);
48 if (ret) 58 if (ret)
49 return ret; 59 return ret;
50 60
51 ram->type = NV_MEM_TYPE_STOLEN; 61 priv->base.get = nv50_ram_get;
52 ram->stolen = (u64)nv_rd32(pfb, 0x100e10) << 12; 62 priv->base.put = nv50_ram_put;
53 ram->get = nv50_ram_get; 63 return 0;
54 ram->put = nv50_ram_put; 64}
65
66static int
67nvaa_ram_init(struct nouveau_object *object)
68{
69 struct nouveau_fb *pfb = nouveau_fb(object);
70 struct nvaa_ram_priv *priv = (void *)object;
71 int ret;
72 u64 dniso, hostnb, flush;
73
74 ret = nouveau_ram_init(&priv->base);
75 if (ret)
76 return ret;
77
78 dniso = ((priv->base.size - (priv->poller_base + 0x00)) >> 5) - 1;
79 hostnb = ((priv->base.size - (priv->poller_base + 0x20)) >> 5) - 1;
80 flush = ((priv->base.size - (priv->poller_base + 0x40)) >> 5) - 1;
81
82 /* Enable NISO poller for various clients and set their associated
83 * read address, only for MCP77/78 and MCP79/7A. (fd#25701)
84 */
85 nv_wr32(pfb, 0x100c18, dniso);
86 nv_mask(pfb, 0x100c14, 0x00000000, 0x00000001);
87 nv_wr32(pfb, 0x100c1c, hostnb);
88 nv_mask(pfb, 0x100c14, 0x00000000, 0x00000002);
89 nv_wr32(pfb, 0x100c24, flush);
90 nv_mask(pfb, 0x100c14, 0x00000000, 0x00010000);
91
55 return 0; 92 return 0;
56} 93}
57 94
@@ -60,7 +97,7 @@ nvaa_ram_oclass = {
60 .ofuncs = &(struct nouveau_ofuncs) { 97 .ofuncs = &(struct nouveau_ofuncs) {
61 .ctor = nvaa_ram_ctor, 98 .ctor = nvaa_ram_ctor,
62 .dtor = _nouveau_ram_dtor, 99 .dtor = _nouveau_ram_dtor,
63 .init = _nouveau_ram_init, 100 .init = nvaa_ram_init,
64 .fini = _nouveau_ram_fini, 101 .fini = _nouveau_ram_fini,
65 }, 102 },
66}; 103};
diff --git a/drivers/gpu/drm/nouveau/core/subdev/mc/nv4c.c b/drivers/gpu/drm/nouveau/core/subdev/mc/nv4c.c
index a75c35ccf25c..165401c4045c 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/mc/nv4c.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/mc/nv4c.c
@@ -24,13 +24,6 @@
24 24
25#include "nv04.h" 25#include "nv04.h"
26 26
27static void
28nv4c_mc_msi_rearm(struct nouveau_mc *pmc)
29{
30 struct nv04_mc_priv *priv = (void *)pmc;
31 nv_wr08(priv, 0x088050, 0xff);
32}
33
34struct nouveau_oclass * 27struct nouveau_oclass *
35nv4c_mc_oclass = &(struct nouveau_mc_oclass) { 28nv4c_mc_oclass = &(struct nouveau_mc_oclass) {
36 .base.handle = NV_SUBDEV(MC, 0x4c), 29 .base.handle = NV_SUBDEV(MC, 0x4c),
@@ -41,5 +34,4 @@ nv4c_mc_oclass = &(struct nouveau_mc_oclass) {
41 .fini = _nouveau_mc_fini, 34 .fini = _nouveau_mc_fini,
42 }, 35 },
43 .intr = nv04_mc_intr, 36 .intr = nv04_mc_intr,
44 .msi_rearm = nv4c_mc_msi_rearm,
45}.base; 37}.base;
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 21ec561edc99..bba2960d3dfb 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -1572,8 +1572,10 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
1572 * so use the DMA API for them. 1572 * so use the DMA API for them.
1573 */ 1573 */
1574 if (!nv_device_is_cpu_coherent(device) && 1574 if (!nv_device_is_cpu_coherent(device) &&
1575 ttm->caching_state == tt_uncached) 1575 ttm->caching_state == tt_uncached) {
1576 ttm_dma_unpopulate(ttm_dma, dev->dev); 1576 ttm_dma_unpopulate(ttm_dma, dev->dev);
1577 return;
1578 }
1577 1579
1578#if __OS_HAS_AGP 1580#if __OS_HAS_AGP
1579 if (drm->agp.stat == ENABLED) { 1581 if (drm->agp.stat == ENABLED) {
diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
index 42c34babc2e5..bf0f9e21d714 100644
--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
@@ -36,7 +36,14 @@ void
36nouveau_gem_object_del(struct drm_gem_object *gem) 36nouveau_gem_object_del(struct drm_gem_object *gem)
37{ 37{
38 struct nouveau_bo *nvbo = nouveau_gem_object(gem); 38 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
39 struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
39 struct ttm_buffer_object *bo = &nvbo->bo; 40 struct ttm_buffer_object *bo = &nvbo->bo;
41 struct device *dev = drm->dev->dev;
42 int ret;
43
44 ret = pm_runtime_get_sync(dev);
45 if (WARN_ON(ret < 0 && ret != -EACCES))
46 return;
40 47
41 if (gem->import_attach) 48 if (gem->import_attach)
42 drm_prime_gem_destroy(gem, nvbo->bo.sg); 49 drm_prime_gem_destroy(gem, nvbo->bo.sg);
@@ -46,6 +53,9 @@ nouveau_gem_object_del(struct drm_gem_object *gem)
46 /* reset filp so nouveau_bo_del_ttm() can test for it */ 53 /* reset filp so nouveau_bo_del_ttm() can test for it */
47 gem->filp = NULL; 54 gem->filp = NULL;
48 ttm_bo_unref(&bo); 55 ttm_bo_unref(&bo);
56
57 pm_runtime_mark_last_busy(dev);
58 pm_runtime_put_autosuspend(dev);
49} 59}
50 60
51int 61int
@@ -53,7 +63,9 @@ nouveau_gem_object_open(struct drm_gem_object *gem, struct drm_file *file_priv)
53{ 63{
54 struct nouveau_cli *cli = nouveau_cli(file_priv); 64 struct nouveau_cli *cli = nouveau_cli(file_priv);
55 struct nouveau_bo *nvbo = nouveau_gem_object(gem); 65 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
66 struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
56 struct nouveau_vma *vma; 67 struct nouveau_vma *vma;
68 struct device *dev = drm->dev->dev;
57 int ret; 69 int ret;
58 70
59 if (!cli->vm) 71 if (!cli->vm)
@@ -71,11 +83,16 @@ nouveau_gem_object_open(struct drm_gem_object *gem, struct drm_file *file_priv)
71 goto out; 83 goto out;
72 } 84 }
73 85
86 ret = pm_runtime_get_sync(dev);
87 if (ret < 0 && ret != -EACCES)
88 goto out;
89
74 ret = nouveau_bo_vma_add(nvbo, cli->vm, vma); 90 ret = nouveau_bo_vma_add(nvbo, cli->vm, vma);
75 if (ret) { 91 if (ret)
76 kfree(vma); 92 kfree(vma);
77 goto out; 93
78 } 94 pm_runtime_mark_last_busy(dev);
95 pm_runtime_put_autosuspend(dev);
79 } else { 96 } else {
80 vma->refcount++; 97 vma->refcount++;
81 } 98 }
@@ -129,6 +146,8 @@ nouveau_gem_object_close(struct drm_gem_object *gem, struct drm_file *file_priv)
129{ 146{
130 struct nouveau_cli *cli = nouveau_cli(file_priv); 147 struct nouveau_cli *cli = nouveau_cli(file_priv);
131 struct nouveau_bo *nvbo = nouveau_gem_object(gem); 148 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
149 struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
150 struct device *dev = drm->dev->dev;
132 struct nouveau_vma *vma; 151 struct nouveau_vma *vma;
133 int ret; 152 int ret;
134 153
@@ -141,8 +160,14 @@ nouveau_gem_object_close(struct drm_gem_object *gem, struct drm_file *file_priv)
141 160
142 vma = nouveau_bo_vma_find(nvbo, cli->vm); 161 vma = nouveau_bo_vma_find(nvbo, cli->vm);
143 if (vma) { 162 if (vma) {
144 if (--vma->refcount == 0) 163 if (--vma->refcount == 0) {
145 nouveau_gem_object_unmap(nvbo, vma); 164 ret = pm_runtime_get_sync(dev);
165 if (!WARN_ON(ret < 0 && ret != -EACCES)) {
166 nouveau_gem_object_unmap(nvbo, vma);
167 pm_runtime_mark_last_busy(dev);
168 pm_runtime_put_autosuspend(dev);
169 }
170 }
146 } 171 }
147 ttm_bo_unreserve(&nvbo->bo); 172 ttm_bo_unreserve(&nvbo->bo);
148} 173}
diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
index d59ec491dbb9..ed644a4f6f57 100644
--- a/drivers/gpu/drm/radeon/atombios_crtc.c
+++ b/drivers/gpu/drm/radeon/atombios_crtc.c
@@ -1851,10 +1851,9 @@ static int radeon_atom_pick_pll(struct drm_crtc *crtc)
1851 return pll; 1851 return pll;
1852 } 1852 }
1853 /* otherwise, pick one of the plls */ 1853 /* otherwise, pick one of the plls */
1854 if ((rdev->family == CHIP_KAVERI) || 1854 if ((rdev->family == CHIP_KABINI) ||
1855 (rdev->family == CHIP_KABINI) ||
1856 (rdev->family == CHIP_MULLINS)) { 1855 (rdev->family == CHIP_MULLINS)) {
1857 /* KB/KV/ML has PPLL1 and PPLL2 */ 1856 /* KB/ML has PPLL1 and PPLL2 */
1858 pll_in_use = radeon_get_pll_use_mask(crtc); 1857 pll_in_use = radeon_get_pll_use_mask(crtc);
1859 if (!(pll_in_use & (1 << ATOM_PPLL2))) 1858 if (!(pll_in_use & (1 << ATOM_PPLL2)))
1860 return ATOM_PPLL2; 1859 return ATOM_PPLL2;
@@ -1863,7 +1862,7 @@ static int radeon_atom_pick_pll(struct drm_crtc *crtc)
1863 DRM_ERROR("unable to allocate a PPLL\n"); 1862 DRM_ERROR("unable to allocate a PPLL\n");
1864 return ATOM_PPLL_INVALID; 1863 return ATOM_PPLL_INVALID;
1865 } else { 1864 } else {
1866 /* CI has PPLL0, PPLL1, and PPLL2 */ 1865 /* CI/KV has PPLL0, PPLL1, and PPLL2 */
1867 pll_in_use = radeon_get_pll_use_mask(crtc); 1866 pll_in_use = radeon_get_pll_use_mask(crtc);
1868 if (!(pll_in_use & (1 << ATOM_PPLL2))) 1867 if (!(pll_in_use & (1 << ATOM_PPLL2)))
1869 return ATOM_PPLL2; 1868 return ATOM_PPLL2;
@@ -2155,6 +2154,7 @@ static void atombios_crtc_disable(struct drm_crtc *crtc)
2155 case ATOM_PPLL0: 2154 case ATOM_PPLL0:
2156 /* disable the ppll */ 2155 /* disable the ppll */
2157 if ((rdev->family == CHIP_ARUBA) || 2156 if ((rdev->family == CHIP_ARUBA) ||
2157 (rdev->family == CHIP_KAVERI) ||
2158 (rdev->family == CHIP_BONAIRE) || 2158 (rdev->family == CHIP_BONAIRE) ||
2159 (rdev->family == CHIP_HAWAII)) 2159 (rdev->family == CHIP_HAWAII))
2160 atombios_crtc_program_pll(crtc, radeon_crtc->crtc_id, radeon_crtc->pll_id, 2160 atombios_crtc_program_pll(crtc, radeon_crtc->crtc_id, radeon_crtc->pll_id,
diff --git a/drivers/gpu/drm/radeon/atombios_dp.c b/drivers/gpu/drm/radeon/atombios_dp.c
index 11ba9d21b89b..db42a670f995 100644
--- a/drivers/gpu/drm/radeon/atombios_dp.c
+++ b/drivers/gpu/drm/radeon/atombios_dp.c
@@ -492,6 +492,10 @@ int radeon_dp_mode_valid_helper(struct drm_connector *connector,
492 struct radeon_connector_atom_dig *dig_connector; 492 struct radeon_connector_atom_dig *dig_connector;
493 int dp_clock; 493 int dp_clock;
494 494
495 if ((mode->clock > 340000) &&
496 (!radeon_connector_is_dp12_capable(connector)))
497 return MODE_CLOCK_HIGH;
498
495 if (!radeon_connector->con_priv) 499 if (!radeon_connector->con_priv)
496 return MODE_CLOCK_HIGH; 500 return MODE_CLOCK_HIGH;
497 dig_connector = radeon_connector->con_priv; 501 dig_connector = radeon_connector->con_priv;
diff --git a/drivers/gpu/drm/radeon/cikd.h b/drivers/gpu/drm/radeon/cikd.h
index ba85986febea..03003f8a6de6 100644
--- a/drivers/gpu/drm/radeon/cikd.h
+++ b/drivers/gpu/drm/radeon/cikd.h
@@ -2156,4 +2156,6 @@
2156#define ATC_VM_APERTURE1_HIGH_ADDR 0x330Cu 2156#define ATC_VM_APERTURE1_HIGH_ADDR 0x330Cu
2157#define ATC_VM_APERTURE1_LOW_ADDR 0x3304u 2157#define ATC_VM_APERTURE1_LOW_ADDR 0x3304u
2158 2158
2159#define IH_VMID_0_LUT 0x3D40u
2160
2159#endif 2161#endif
diff --git a/drivers/gpu/drm/radeon/dce3_1_afmt.c b/drivers/gpu/drm/radeon/dce3_1_afmt.c
index 2fe8cfc966d9..bafdf92a5732 100644
--- a/drivers/gpu/drm/radeon/dce3_1_afmt.c
+++ b/drivers/gpu/drm/radeon/dce3_1_afmt.c
@@ -103,7 +103,7 @@ static void dce3_2_afmt_write_sad_regs(struct drm_encoder *encoder)
103 } 103 }
104 104
105 sad_count = drm_edid_to_sad(radeon_connector->edid, &sads); 105 sad_count = drm_edid_to_sad(radeon_connector->edid, &sads);
106 if (sad_count < 0) { 106 if (sad_count <= 0) {
107 DRM_ERROR("Couldn't read SADs: %d\n", sad_count); 107 DRM_ERROR("Couldn't read SADs: %d\n", sad_count);
108 return; 108 return;
109 } 109 }
diff --git a/drivers/gpu/drm/radeon/kv_dpm.c b/drivers/gpu/drm/radeon/kv_dpm.c
index 9b42001295ba..e3e9c10cfba9 100644
--- a/drivers/gpu/drm/radeon/kv_dpm.c
+++ b/drivers/gpu/drm/radeon/kv_dpm.c
@@ -2745,13 +2745,11 @@ int kv_dpm_init(struct radeon_device *rdev)
2745 pi->enable_auto_thermal_throttling = true; 2745 pi->enable_auto_thermal_throttling = true;
2746 pi->disable_nb_ps3_in_battery = false; 2746 pi->disable_nb_ps3_in_battery = false;
2747 if (radeon_bapm == -1) { 2747 if (radeon_bapm == -1) {
2748 /* There are stability issues reported on with 2748 /* only enable bapm on KB, ML by default */
2749 * bapm enabled on an asrock system. 2749 if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS)
2750 */
2751 if (rdev->pdev->subsystem_vendor == 0x1849)
2752 pi->bapm_enable = false;
2753 else
2754 pi->bapm_enable = true; 2750 pi->bapm_enable = true;
2751 else
2752 pi->bapm_enable = false;
2755 } else if (radeon_bapm == 0) { 2753 } else if (radeon_bapm == 0) {
2756 pi->bapm_enable = false; 2754 pi->bapm_enable = false;
2757 } else { 2755 } else {
diff --git a/drivers/gpu/drm/radeon/radeon_kfd.c b/drivers/gpu/drm/radeon/radeon_kfd.c
index 242fd8b1b221..8bf87f1203cc 100644
--- a/drivers/gpu/drm/radeon/radeon_kfd.c
+++ b/drivers/gpu/drm/radeon/radeon_kfd.c
@@ -72,7 +72,7 @@ static int kgd_init_pipeline(struct kgd_dev *kgd, uint32_t pipe_id,
72static int kgd_hqd_load(struct kgd_dev *kgd, void *mqd, uint32_t pipe_id, 72static int kgd_hqd_load(struct kgd_dev *kgd, void *mqd, uint32_t pipe_id,
73 uint32_t queue_id, uint32_t __user *wptr); 73 uint32_t queue_id, uint32_t __user *wptr);
74 74
75static bool kgd_hqd_is_occupies(struct kgd_dev *kgd, uint64_t queue_address, 75static bool kgd_hqd_is_occupied(struct kgd_dev *kgd, uint64_t queue_address,
76 uint32_t pipe_id, uint32_t queue_id); 76 uint32_t pipe_id, uint32_t queue_id);
77 77
78static int kgd_hqd_destroy(struct kgd_dev *kgd, uint32_t reset_type, 78static int kgd_hqd_destroy(struct kgd_dev *kgd, uint32_t reset_type,
@@ -92,7 +92,7 @@ static const struct kfd2kgd_calls kfd2kgd = {
92 .init_memory = kgd_init_memory, 92 .init_memory = kgd_init_memory,
93 .init_pipeline = kgd_init_pipeline, 93 .init_pipeline = kgd_init_pipeline,
94 .hqd_load = kgd_hqd_load, 94 .hqd_load = kgd_hqd_load,
95 .hqd_is_occupies = kgd_hqd_is_occupies, 95 .hqd_is_occupied = kgd_hqd_is_occupied,
96 .hqd_destroy = kgd_hqd_destroy, 96 .hqd_destroy = kgd_hqd_destroy,
97 .get_fw_version = get_fw_version 97 .get_fw_version = get_fw_version
98}; 98};
@@ -101,6 +101,7 @@ static const struct kgd2kfd_calls *kgd2kfd;
101 101
102bool radeon_kfd_init(void) 102bool radeon_kfd_init(void)
103{ 103{
104#if defined(CONFIG_HSA_AMD_MODULE)
104 bool (*kgd2kfd_init_p)(unsigned, const struct kfd2kgd_calls*, 105 bool (*kgd2kfd_init_p)(unsigned, const struct kfd2kgd_calls*,
105 const struct kgd2kfd_calls**); 106 const struct kgd2kfd_calls**);
106 107
@@ -117,6 +118,17 @@ bool radeon_kfd_init(void)
117 } 118 }
118 119
119 return true; 120 return true;
121#elif defined(CONFIG_HSA_AMD)
122 if (!kgd2kfd_init(KFD_INTERFACE_VERSION, &kfd2kgd, &kgd2kfd)) {
123 kgd2kfd = NULL;
124
125 return false;
126 }
127
128 return true;
129#else
130 return false;
131#endif
120} 132}
121 133
122void radeon_kfd_fini(void) 134void radeon_kfd_fini(void)
@@ -378,6 +390,10 @@ static int kgd_set_pasid_vmid_mapping(struct kgd_dev *kgd, unsigned int pasid,
378 cpu_relax(); 390 cpu_relax();
379 write_register(kgd, ATC_VMID_PASID_MAPPING_UPDATE_STATUS, 1U << vmid); 391 write_register(kgd, ATC_VMID_PASID_MAPPING_UPDATE_STATUS, 1U << vmid);
380 392
393 /* Mapping vmid to pasid also for IH block */
394 write_register(kgd, IH_VMID_0_LUT + vmid * sizeof(uint32_t),
395 pasid_mapping);
396
381 return 0; 397 return 0;
382} 398}
383 399
@@ -517,7 +533,7 @@ static int kgd_hqd_load(struct kgd_dev *kgd, void *mqd, uint32_t pipe_id,
517 return 0; 533 return 0;
518} 534}
519 535
520static bool kgd_hqd_is_occupies(struct kgd_dev *kgd, uint64_t queue_address, 536static bool kgd_hqd_is_occupied(struct kgd_dev *kgd, uint64_t queue_address,
521 uint32_t pipe_id, uint32_t queue_id) 537 uint32_t pipe_id, uint32_t queue_id)
522{ 538{
523 uint32_t act; 539 uint32_t act;
@@ -556,6 +572,7 @@ static int kgd_hqd_destroy(struct kgd_dev *kgd, uint32_t reset_type,
556 if (timeout == 0) { 572 if (timeout == 0) {
557 pr_err("kfd: cp queue preemption time out (%dms)\n", 573 pr_err("kfd: cp queue preemption time out (%dms)\n",
558 temp); 574 temp);
575 release_queue(kgd);
559 return -ETIME; 576 return -ETIME;
560 } 577 }
561 msleep(20); 578 msleep(20);
diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
index 535403e0c8a2..15aee723db77 100644
--- a/drivers/gpu/drm/radeon/radeon_state.c
+++ b/drivers/gpu/drm/radeon/radeon_state.c
@@ -1703,7 +1703,7 @@ static int radeon_cp_dispatch_texture(struct drm_device * dev,
1703 u32 format; 1703 u32 format;
1704 u32 *buffer; 1704 u32 *buffer;
1705 const u8 __user *data; 1705 const u8 __user *data;
1706 int size, dwords, tex_width, blit_width, spitch; 1706 unsigned int size, dwords, tex_width, blit_width, spitch;
1707 u32 height; 1707 u32 height;
1708 int i; 1708 int i;
1709 u32 texpitch, microtile; 1709 u32 texpitch, microtile;
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 230b6f887cd8..dfdc26970022 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -27,7 +27,8 @@ if HID
27 27
28config HID_BATTERY_STRENGTH 28config HID_BATTERY_STRENGTH
29 bool "Battery level reporting for HID devices" 29 bool "Battery level reporting for HID devices"
30 depends on HID && POWER_SUPPLY && HID = POWER_SUPPLY 30 depends on HID
31 select POWER_SUPPLY
31 default n 32 default n
32 ---help--- 33 ---help---
33 This option adds support of reporting battery strength (for HID devices 34 This option adds support of reporting battery strength (for HID devices
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index c3d0ac1a0988..8b638792cb43 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1805,6 +1805,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
1805 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) }, 1805 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
1806 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_I405X) }, 1806 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_I405X) },
1807 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) }, 1807 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
1808 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2) },
1808 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X) }, 1809 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X) },
1809 { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) }, 1810 { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
1810 { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) }, 1811 { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 7460f3402298..9243359c1821 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -526,6 +526,7 @@
526#define USB_DEVICE_ID_KYE_GPEN_560 0x5003 526#define USB_DEVICE_ID_KYE_GPEN_560 0x5003
527#define USB_DEVICE_ID_KYE_EASYPEN_I405X 0x5010 527#define USB_DEVICE_ID_KYE_EASYPEN_I405X 0x5010
528#define USB_DEVICE_ID_KYE_MOUSEPEN_I608X 0x5011 528#define USB_DEVICE_ID_KYE_MOUSEPEN_I608X 0x5011
529#define USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2 0x501a
529#define USB_DEVICE_ID_KYE_EASYPEN_M610X 0x5013 530#define USB_DEVICE_ID_KYE_EASYPEN_M610X 0x5013
530 531
531#define USB_VENDOR_ID_LABTEC 0x1020 532#define USB_VENDOR_ID_LABTEC 0x1020
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index e0a0f06ac5ef..9505605b6e22 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -312,6 +312,9 @@ static const struct hid_device_id hid_battery_quirks[] = {
312 USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI), 312 USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI),
313 HID_BATTERY_QUIRK_PERCENT | HID_BATTERY_QUIRK_FEATURE }, 313 HID_BATTERY_QUIRK_PERCENT | HID_BATTERY_QUIRK_FEATURE },
314 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 314 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
315 USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO),
316 HID_BATTERY_QUIRK_PERCENT | HID_BATTERY_QUIRK_FEATURE },
317 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
315 USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI), 318 USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI),
316 HID_BATTERY_QUIRK_PERCENT | HID_BATTERY_QUIRK_FEATURE }, 319 HID_BATTERY_QUIRK_PERCENT | HID_BATTERY_QUIRK_FEATURE },
317 {} 320 {}
diff --git a/drivers/hid/hid-kye.c b/drivers/hid/hid-kye.c
index b92bf01a1ae8..158fcf577fae 100644
--- a/drivers/hid/hid-kye.c
+++ b/drivers/hid/hid-kye.c
@@ -323,6 +323,7 @@ static __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
323 } 323 }
324 break; 324 break;
325 case USB_DEVICE_ID_KYE_MOUSEPEN_I608X: 325 case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
326 case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2:
326 if (*rsize == MOUSEPEN_I608X_RDESC_ORIG_SIZE) { 327 if (*rsize == MOUSEPEN_I608X_RDESC_ORIG_SIZE) {
327 rdesc = mousepen_i608x_rdesc_fixed; 328 rdesc = mousepen_i608x_rdesc_fixed;
328 *rsize = sizeof(mousepen_i608x_rdesc_fixed); 329 *rsize = sizeof(mousepen_i608x_rdesc_fixed);
@@ -415,6 +416,7 @@ static int kye_probe(struct hid_device *hdev, const struct hid_device_id *id)
415 switch (id->product) { 416 switch (id->product) {
416 case USB_DEVICE_ID_KYE_EASYPEN_I405X: 417 case USB_DEVICE_ID_KYE_EASYPEN_I405X:
417 case USB_DEVICE_ID_KYE_MOUSEPEN_I608X: 418 case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
419 case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2:
418 case USB_DEVICE_ID_KYE_EASYPEN_M610X: 420 case USB_DEVICE_ID_KYE_EASYPEN_M610X:
419 ret = kye_tablet_enable(hdev); 421 ret = kye_tablet_enable(hdev);
420 if (ret) { 422 if (ret) {
@@ -446,6 +448,8 @@ static const struct hid_device_id kye_devices[] = {
446 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, 448 { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
447 USB_DEVICE_ID_KYE_MOUSEPEN_I608X) }, 449 USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
448 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, 450 { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
451 USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2) },
452 { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
449 USB_DEVICE_ID_KYE_EASYPEN_M610X) }, 453 USB_DEVICE_ID_KYE_EASYPEN_M610X) },
450 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, 454 { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
451 USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) }, 455 USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) },
diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
index c917ab61aafa..5bc6d80d5be7 100644
--- a/drivers/hid/hid-logitech-dj.c
+++ b/drivers/hid/hid-logitech-dj.c
@@ -962,10 +962,24 @@ static int logi_dj_raw_event(struct hid_device *hdev,
962 962
963 switch (data[0]) { 963 switch (data[0]) {
964 case REPORT_ID_DJ_SHORT: 964 case REPORT_ID_DJ_SHORT:
965 if (size != DJREPORT_SHORT_LENGTH) {
966 dev_err(&hdev->dev, "DJ report of bad size (%d)", size);
967 return false;
968 }
965 return logi_dj_dj_event(hdev, report, data, size); 969 return logi_dj_dj_event(hdev, report, data, size);
966 case REPORT_ID_HIDPP_SHORT: 970 case REPORT_ID_HIDPP_SHORT:
967 /* intentional fallthrough */ 971 if (size != HIDPP_REPORT_SHORT_LENGTH) {
972 dev_err(&hdev->dev,
973 "Short HID++ report of bad size (%d)", size);
974 return false;
975 }
976 return logi_dj_hidpp_event(hdev, report, data, size);
968 case REPORT_ID_HIDPP_LONG: 977 case REPORT_ID_HIDPP_LONG:
978 if (size != HIDPP_REPORT_LONG_LENGTH) {
979 dev_err(&hdev->dev,
980 "Long HID++ report of bad size (%d)", size);
981 return false;
982 }
969 return logi_dj_hidpp_event(hdev, report, data, size); 983 return logi_dj_hidpp_event(hdev, report, data, size);
970 } 984 }
971 985
diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index 2f420c0b6609..a93cefe0e522 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -282,6 +282,33 @@ static inline bool hidpp_report_is_connect_event(struct hidpp_report *report)
282 (report->rap.sub_id == 0x41); 282 (report->rap.sub_id == 0x41);
283} 283}
284 284
285/**
286 * hidpp_prefix_name() prefixes the current given name with "Logitech ".
287 */
288static void hidpp_prefix_name(char **name, int name_length)
289{
290#define PREFIX_LENGTH 9 /* "Logitech " */
291
292 int new_length;
293 char *new_name;
294
295 if (name_length > PREFIX_LENGTH &&
296 strncmp(*name, "Logitech ", PREFIX_LENGTH) == 0)
297 /* The prefix has is already in the name */
298 return;
299
300 new_length = PREFIX_LENGTH + name_length;
301 new_name = kzalloc(new_length, GFP_KERNEL);
302 if (!new_name)
303 return;
304
305 snprintf(new_name, new_length, "Logitech %s", *name);
306
307 kfree(*name);
308
309 *name = new_name;
310}
311
285/* -------------------------------------------------------------------------- */ 312/* -------------------------------------------------------------------------- */
286/* HIDP++ 1.0 commands */ 313/* HIDP++ 1.0 commands */
287/* -------------------------------------------------------------------------- */ 314/* -------------------------------------------------------------------------- */
@@ -321,6 +348,10 @@ static char *hidpp_get_unifying_name(struct hidpp_device *hidpp_dev)
321 return NULL; 348 return NULL;
322 349
323 memcpy(name, &response.rap.params[2], len); 350 memcpy(name, &response.rap.params[2], len);
351
352 /* include the terminating '\0' */
353 hidpp_prefix_name(&name, len + 1);
354
324 return name; 355 return name;
325} 356}
326 357
@@ -498,6 +529,9 @@ static char *hidpp_get_device_name(struct hidpp_device *hidpp)
498 index += ret; 529 index += ret;
499 } 530 }
500 531
532 /* include the terminating '\0' */
533 hidpp_prefix_name(&name, __name_length + 1);
534
501 return name; 535 return name;
502} 536}
503 537
@@ -794,18 +828,25 @@ static int wtp_raw_event(struct hid_device *hdev, u8 *data, int size)
794 828
795 switch (data[0]) { 829 switch (data[0]) {
796 case 0x02: 830 case 0x02:
831 if (size < 2) {
832 hid_err(hdev, "Received HID report of bad size (%d)",
833 size);
834 return 1;
835 }
797 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) { 836 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) {
798 input_event(wd->input, EV_KEY, BTN_LEFT, 837 input_event(wd->input, EV_KEY, BTN_LEFT,
799 !!(data[1] & 0x01)); 838 !!(data[1] & 0x01));
800 input_event(wd->input, EV_KEY, BTN_RIGHT, 839 input_event(wd->input, EV_KEY, BTN_RIGHT,
801 !!(data[1] & 0x02)); 840 !!(data[1] & 0x02));
802 input_sync(wd->input); 841 input_sync(wd->input);
842 return 0;
803 } else { 843 } else {
804 if (size < 21) 844 if (size < 21)
805 return 1; 845 return 1;
806 return wtp_mouse_raw_xy_event(hidpp, &data[7]); 846 return wtp_mouse_raw_xy_event(hidpp, &data[7]);
807 } 847 }
808 case REPORT_ID_HIDPP_LONG: 848 case REPORT_ID_HIDPP_LONG:
849 /* size is already checked in hidpp_raw_event. */
809 if ((report->fap.feature_index != wd->mt_feature_index) || 850 if ((report->fap.feature_index != wd->mt_feature_index) ||
810 (report->fap.funcindex_clientid != EVENT_TOUCHPAD_RAW_XY)) 851 (report->fap.funcindex_clientid != EVENT_TOUCHPAD_RAW_XY))
811 return 1; 852 return 1;
diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c
index 1a07e07d99a0..47d7e74231e5 100644
--- a/drivers/hid/hid-roccat-pyra.c
+++ b/drivers/hid/hid-roccat-pyra.c
@@ -35,6 +35,8 @@ static struct class *pyra_class;
35static void profile_activated(struct pyra_device *pyra, 35static void profile_activated(struct pyra_device *pyra,
36 unsigned int new_profile) 36 unsigned int new_profile)
37{ 37{
38 if (new_profile >= ARRAY_SIZE(pyra->profile_settings))
39 return;
38 pyra->actual_profile = new_profile; 40 pyra->actual_profile = new_profile;
39 pyra->actual_cpi = pyra->profile_settings[pyra->actual_profile].y_cpi; 41 pyra->actual_cpi = pyra->profile_settings[pyra->actual_profile].y_cpi;
40} 42}
@@ -257,9 +259,11 @@ static ssize_t pyra_sysfs_write_settings(struct file *fp,
257 if (off != 0 || count != PYRA_SIZE_SETTINGS) 259 if (off != 0 || count != PYRA_SIZE_SETTINGS)
258 return -EINVAL; 260 return -EINVAL;
259 261
260 mutex_lock(&pyra->pyra_lock);
261
262 settings = (struct pyra_settings const *)buf; 262 settings = (struct pyra_settings const *)buf;
263 if (settings->startup_profile >= ARRAY_SIZE(pyra->profile_settings))
264 return -EINVAL;
265
266 mutex_lock(&pyra->pyra_lock);
263 267
264 retval = pyra_set_settings(usb_dev, settings); 268 retval = pyra_set_settings(usb_dev, settings);
265 if (retval) { 269 if (retval) {
diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
index d32037cbf9db..d43e967e7533 100644
--- a/drivers/hid/i2c-hid/i2c-hid.c
+++ b/drivers/hid/i2c-hid/i2c-hid.c
@@ -706,12 +706,7 @@ static int i2c_hid_start(struct hid_device *hid)
706 706
707static void i2c_hid_stop(struct hid_device *hid) 707static void i2c_hid_stop(struct hid_device *hid)
708{ 708{
709 struct i2c_client *client = hid->driver_data;
710 struct i2c_hid *ihid = i2c_get_clientdata(client);
711
712 hid->claimed = 0; 709 hid->claimed = 0;
713
714 i2c_hid_free_buffers(ihid);
715} 710}
716 711
717static int i2c_hid_open(struct hid_device *hid) 712static int i2c_hid_open(struct hid_device *hid)
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index dc89be90b35e..b27b3d33ebab 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -124,6 +124,7 @@ static const struct hid_blacklist {
124 { USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS, HID_QUIRK_MULTI_INPUT }, 124 { USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS, HID_QUIRK_MULTI_INPUT },
125 { USB_VENDOR_ID_SIGMA_MICRO, USB_DEVICE_ID_SIGMA_MICRO_KEYBOARD, HID_QUIRK_NO_INIT_REPORTS }, 125 { USB_VENDOR_ID_SIGMA_MICRO, USB_DEVICE_ID_SIGMA_MICRO_KEYBOARD, HID_QUIRK_NO_INIT_REPORTS },
126 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X, HID_QUIRK_MULTI_INPUT }, 126 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X, HID_QUIRK_MULTI_INPUT },
127 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2, HID_QUIRK_MULTI_INPUT },
127 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X, HID_QUIRK_MULTI_INPUT }, 128 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X, HID_QUIRK_MULTI_INPUT },
128 { USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_DUOSENSE, HID_QUIRK_NO_INIT_REPORTS }, 129 { USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_DUOSENSE, HID_QUIRK_NO_INIT_REPORTS },
129 { USB_VENDOR_ID_SEMICO, USB_DEVICE_ID_SEMICO_USB_KEYKOARD, HID_QUIRK_NO_INIT_REPORTS }, 130 { USB_VENDOR_ID_SEMICO, USB_DEVICE_ID_SEMICO_USB_KEYKOARD, HID_QUIRK_NO_INIT_REPORTS },
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 1232336b960e..40dfbc0444c0 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -4029,14 +4029,6 @@ static int device_notifier(struct notifier_block *nb,
4029 if (action != BUS_NOTIFY_REMOVED_DEVICE) 4029 if (action != BUS_NOTIFY_REMOVED_DEVICE)
4030 return 0; 4030 return 0;
4031 4031
4032 /*
4033 * If the device is still attached to a device driver we can't
4034 * tear down the domain yet as DMA mappings may still be in use.
4035 * Wait for the BUS_NOTIFY_UNBOUND_DRIVER event to do that.
4036 */
4037 if (action == BUS_NOTIFY_DEL_DEVICE && dev->driver != NULL)
4038 return 0;
4039
4040 domain = find_domain(dev); 4032 domain = find_domain(dev);
4041 if (!domain) 4033 if (!domain)
4042 return 0; 4034 return 0;
@@ -4428,6 +4420,10 @@ static int intel_iommu_attach_device(struct iommu_domain *domain,
4428 domain_remove_one_dev_info(old_domain, dev); 4420 domain_remove_one_dev_info(old_domain, dev);
4429 else 4421 else
4430 domain_remove_dev_info(old_domain); 4422 domain_remove_dev_info(old_domain);
4423
4424 if (!domain_type_is_vm_or_si(old_domain) &&
4425 list_empty(&old_domain->devices))
4426 domain_exit(old_domain);
4431 } 4427 }
4432 } 4428 }
4433 4429
diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c
index 68dfb0fd5ee9..748693192c20 100644
--- a/drivers/iommu/ipmmu-vmsa.c
+++ b/drivers/iommu/ipmmu-vmsa.c
@@ -558,7 +558,7 @@ static pmd_t *ipmmu_alloc_pmd(struct ipmmu_vmsa_device *mmu, pgd_t *pgd,
558 558
559static u64 ipmmu_page_prot(unsigned int prot, u64 type) 559static u64 ipmmu_page_prot(unsigned int prot, u64 type)
560{ 560{
561 u64 pgprot = ARM_VMSA_PTE_XN | ARM_VMSA_PTE_nG | ARM_VMSA_PTE_AF 561 u64 pgprot = ARM_VMSA_PTE_nG | ARM_VMSA_PTE_AF
562 | ARM_VMSA_PTE_SH_IS | ARM_VMSA_PTE_AP_UNPRIV 562 | ARM_VMSA_PTE_SH_IS | ARM_VMSA_PTE_AP_UNPRIV
563 | ARM_VMSA_PTE_NS | type; 563 | ARM_VMSA_PTE_NS | type;
564 564
@@ -568,8 +568,8 @@ static u64 ipmmu_page_prot(unsigned int prot, u64 type)
568 if (prot & IOMMU_CACHE) 568 if (prot & IOMMU_CACHE)
569 pgprot |= IMMAIR_ATTR_IDX_WBRWA << ARM_VMSA_PTE_ATTRINDX_SHIFT; 569 pgprot |= IMMAIR_ATTR_IDX_WBRWA << ARM_VMSA_PTE_ATTRINDX_SHIFT;
570 570
571 if (prot & IOMMU_EXEC) 571 if (prot & IOMMU_NOEXEC)
572 pgprot &= ~ARM_VMSA_PTE_XN; 572 pgprot |= ARM_VMSA_PTE_XN;
573 else if (!(prot & (IOMMU_READ | IOMMU_WRITE))) 573 else if (!(prot & (IOMMU_READ | IOMMU_WRITE)))
574 /* If no access create a faulting entry to avoid TLB fills. */ 574 /* If no access create a faulting entry to avoid TLB fills. */
575 pgprot &= ~ARM_VMSA_PTE_PAGE; 575 pgprot &= ~ARM_VMSA_PTE_PAGE;
diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index b2023af384b9..6a8b1ec4a48a 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -1009,7 +1009,6 @@ static struct platform_driver rk_iommu_driver = {
1009 .remove = rk_iommu_remove, 1009 .remove = rk_iommu_remove,
1010 .driver = { 1010 .driver = {
1011 .name = "rk_iommu", 1011 .name = "rk_iommu",
1012 .owner = THIS_MODULE,
1013 .of_match_table = of_match_ptr(rk_iommu_dt_ids), 1012 .of_match_table = of_match_ptr(rk_iommu_dt_ids),
1014 }, 1013 },
1015}; 1014};
diff --git a/drivers/isdn/hardware/eicon/message.c b/drivers/isdn/hardware/eicon/message.c
index a82e542ffc21..0b380603a578 100644
--- a/drivers/isdn/hardware/eicon/message.c
+++ b/drivers/isdn/hardware/eicon/message.c
@@ -4880,7 +4880,7 @@ static void sig_ind(PLCI *plci)
4880 byte SS_Ind[] = "\x05\x02\x00\x02\x00\x00"; /* Hold_Ind struct*/ 4880 byte SS_Ind[] = "\x05\x02\x00\x02\x00\x00"; /* Hold_Ind struct*/
4881 byte CF_Ind[] = "\x09\x02\x00\x06\x00\x00\x00\x00\x00\x00"; 4881 byte CF_Ind[] = "\x09\x02\x00\x06\x00\x00\x00\x00\x00\x00";
4882 byte Interr_Err_Ind[] = "\x0a\x02\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; 4882 byte Interr_Err_Ind[] = "\x0a\x02\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
4883 byte CONF_Ind[] = "\x09\x16\x00\x06\x00\x00\0x00\0x00\0x00\0x00"; 4883 byte CONF_Ind[] = "\x09\x16\x00\x06\x00\x00\x00\x00\x00\x00";
4884 byte force_mt_info = false; 4884 byte force_mt_info = false;
4885 byte dir; 4885 byte dir;
4886 dword d; 4886 dword d;
diff --git a/drivers/leds/leds-netxbig.c b/drivers/leds/leds-netxbig.c
index 26515c27ea8c..25e419752a7b 100644
--- a/drivers/leds/leds-netxbig.c
+++ b/drivers/leds/leds-netxbig.c
@@ -330,18 +330,18 @@ create_netxbig_led(struct platform_device *pdev,
330 led_dat->sata = 0; 330 led_dat->sata = 0;
331 led_dat->cdev.brightness = LED_OFF; 331 led_dat->cdev.brightness = LED_OFF;
332 led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME; 332 led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
333 /*
334 * If available, expose the SATA activity blink capability through
335 * a "sata" sysfs attribute.
336 */
337 if (led_dat->mode_val[NETXBIG_LED_SATA] != NETXBIG_LED_INVALID_MODE)
338 led_dat->cdev.groups = netxbig_led_groups;
339 led_dat->mode_addr = template->mode_addr; 333 led_dat->mode_addr = template->mode_addr;
340 led_dat->mode_val = template->mode_val; 334 led_dat->mode_val = template->mode_val;
341 led_dat->bright_addr = template->bright_addr; 335 led_dat->bright_addr = template->bright_addr;
342 led_dat->bright_max = (1 << pdata->gpio_ext->num_data) - 1; 336 led_dat->bright_max = (1 << pdata->gpio_ext->num_data) - 1;
343 led_dat->timer = pdata->timer; 337 led_dat->timer = pdata->timer;
344 led_dat->num_timer = pdata->num_timer; 338 led_dat->num_timer = pdata->num_timer;
339 /*
340 * If available, expose the SATA activity blink capability through
341 * a "sata" sysfs attribute.
342 */
343 if (led_dat->mode_val[NETXBIG_LED_SATA] != NETXBIG_LED_INVALID_MODE)
344 led_dat->cdev.groups = netxbig_led_groups;
345 345
346 return led_classdev_register(&pdev->dev, &led_dat->cdev); 346 return led_classdev_register(&pdev->dev, &led_dat->cdev);
347} 347}
diff --git a/drivers/misc/cxl/context.c b/drivers/misc/cxl/context.c
index 51fd6b524371..d1b55fe62817 100644
--- a/drivers/misc/cxl/context.c
+++ b/drivers/misc/cxl/context.c
@@ -100,6 +100,46 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master,
100 return 0; 100 return 0;
101} 101}
102 102
103static int cxl_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
104{
105 struct cxl_context *ctx = vma->vm_file->private_data;
106 unsigned long address = (unsigned long)vmf->virtual_address;
107 u64 area, offset;
108
109 offset = vmf->pgoff << PAGE_SHIFT;
110
111 pr_devel("%s: pe: %i address: 0x%lx offset: 0x%llx\n",
112 __func__, ctx->pe, address, offset);
113
114 if (ctx->afu->current_mode == CXL_MODE_DEDICATED) {
115 area = ctx->afu->psn_phys;
116 if (offset > ctx->afu->adapter->ps_size)
117 return VM_FAULT_SIGBUS;
118 } else {
119 area = ctx->psn_phys;
120 if (offset > ctx->psn_size)
121 return VM_FAULT_SIGBUS;
122 }
123
124 mutex_lock(&ctx->status_mutex);
125
126 if (ctx->status != STARTED) {
127 mutex_unlock(&ctx->status_mutex);
128 pr_devel("%s: Context not started, failing problem state access\n", __func__);
129 return VM_FAULT_SIGBUS;
130 }
131
132 vm_insert_pfn(vma, address, (area + offset) >> PAGE_SHIFT);
133
134 mutex_unlock(&ctx->status_mutex);
135
136 return VM_FAULT_NOPAGE;
137}
138
139static const struct vm_operations_struct cxl_mmap_vmops = {
140 .fault = cxl_mmap_fault,
141};
142
103/* 143/*
104 * Map a per-context mmio space into the given vma. 144 * Map a per-context mmio space into the given vma.
105 */ 145 */
@@ -108,26 +148,25 @@ int cxl_context_iomap(struct cxl_context *ctx, struct vm_area_struct *vma)
108 u64 len = vma->vm_end - vma->vm_start; 148 u64 len = vma->vm_end - vma->vm_start;
109 len = min(len, ctx->psn_size); 149 len = min(len, ctx->psn_size);
110 150
111 if (ctx->afu->current_mode == CXL_MODE_DEDICATED) { 151 if (ctx->afu->current_mode != CXL_MODE_DEDICATED) {
112 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 152 /* make sure there is a valid per process space for this AFU */
113 return vm_iomap_memory(vma, ctx->afu->psn_phys, ctx->afu->adapter->ps_size); 153 if ((ctx->master && !ctx->afu->psa) || (!ctx->afu->pp_psa)) {
114 } 154 pr_devel("AFU doesn't support mmio space\n");
155 return -EINVAL;
156 }
115 157
116 /* make sure there is a valid per process space for this AFU */ 158 /* Can't mmap until the AFU is enabled */
117 if ((ctx->master && !ctx->afu->psa) || (!ctx->afu->pp_psa)) { 159 if (!ctx->afu->enabled)
118 pr_devel("AFU doesn't support mmio space\n"); 160 return -EBUSY;
119 return -EINVAL;
120 } 161 }
121 162
122 /* Can't mmap until the AFU is enabled */
123 if (!ctx->afu->enabled)
124 return -EBUSY;
125
126 pr_devel("%s: mmio physical: %llx pe: %i master:%i\n", __func__, 163 pr_devel("%s: mmio physical: %llx pe: %i master:%i\n", __func__,
127 ctx->psn_phys, ctx->pe , ctx->master); 164 ctx->psn_phys, ctx->pe , ctx->master);
128 165
166 vma->vm_flags |= VM_IO | VM_PFNMAP;
129 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 167 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
130 return vm_iomap_memory(vma, ctx->psn_phys, len); 168 vma->vm_ops = &cxl_mmap_vmops;
169 return 0;
131} 170}
132 171
133/* 172/*
@@ -150,12 +189,6 @@ static void __detach_context(struct cxl_context *ctx)
150 afu_release_irqs(ctx); 189 afu_release_irqs(ctx);
151 flush_work(&ctx->fault_work); /* Only needed for dedicated process */ 190 flush_work(&ctx->fault_work); /* Only needed for dedicated process */
152 wake_up_all(&ctx->wq); 191 wake_up_all(&ctx->wq);
153
154 /* Release Problem State Area mapping */
155 mutex_lock(&ctx->mapping_lock);
156 if (ctx->mapping)
157 unmap_mapping_range(ctx->mapping, 0, 0, 1);
158 mutex_unlock(&ctx->mapping_lock);
159} 192}
160 193
161/* 194/*
@@ -184,6 +217,17 @@ void cxl_context_detach_all(struct cxl_afu *afu)
184 * created and torn down after the IDR removed 217 * created and torn down after the IDR removed
185 */ 218 */
186 __detach_context(ctx); 219 __detach_context(ctx);
220
221 /*
222 * We are force detaching - remove any active PSA mappings so
223 * userspace cannot interfere with the card if it comes back.
224 * Easiest way to exercise this is to unbind and rebind the
225 * driver via sysfs while it is in use.
226 */
227 mutex_lock(&ctx->mapping_lock);
228 if (ctx->mapping)
229 unmap_mapping_range(ctx->mapping, 0, 0, 1);
230 mutex_unlock(&ctx->mapping_lock);
187 } 231 }
188 mutex_unlock(&afu->contexts_lock); 232 mutex_unlock(&afu->contexts_lock);
189} 233}
diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c
index e9f2f10dbb37..b15d8113877c 100644
--- a/drivers/misc/cxl/file.c
+++ b/drivers/misc/cxl/file.c
@@ -140,18 +140,20 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
140 140
141 pr_devel("%s: pe: %i\n", __func__, ctx->pe); 141 pr_devel("%s: pe: %i\n", __func__, ctx->pe);
142 142
143 mutex_lock(&ctx->status_mutex); 143 /* Do this outside the status_mutex to avoid a circular dependency with
144 if (ctx->status != OPENED) { 144 * the locking in cxl_mmap_fault() */
145 rc = -EIO;
146 goto out;
147 }
148
149 if (copy_from_user(&work, uwork, 145 if (copy_from_user(&work, uwork,
150 sizeof(struct cxl_ioctl_start_work))) { 146 sizeof(struct cxl_ioctl_start_work))) {
151 rc = -EFAULT; 147 rc = -EFAULT;
152 goto out; 148 goto out;
153 } 149 }
154 150
151 mutex_lock(&ctx->status_mutex);
152 if (ctx->status != OPENED) {
153 rc = -EIO;
154 goto out;
155 }
156
155 /* 157 /*
156 * if any of the reserved fields are set or any of the unused 158 * if any of the reserved fields are set or any of the unused
157 * flags are set it's invalid 159 * flags are set it's invalid
diff --git a/drivers/mmc/host/sdhci-acpi.c b/drivers/mmc/host/sdhci-acpi.c
index e3e56d35f0ee..970314e0aac8 100644
--- a/drivers/mmc/host/sdhci-acpi.c
+++ b/drivers/mmc/host/sdhci-acpi.c
@@ -247,6 +247,7 @@ static const struct sdhci_acpi_uid_slot sdhci_acpi_uids[] = {
247 { "INT33BB" , "3" , &sdhci_acpi_slot_int_sd }, 247 { "INT33BB" , "3" , &sdhci_acpi_slot_int_sd },
248 { "INT33C6" , NULL, &sdhci_acpi_slot_int_sdio }, 248 { "INT33C6" , NULL, &sdhci_acpi_slot_int_sdio },
249 { "INT3436" , NULL, &sdhci_acpi_slot_int_sdio }, 249 { "INT3436" , NULL, &sdhci_acpi_slot_int_sdio },
250 { "INT344D" , NULL, &sdhci_acpi_slot_int_sdio },
250 { "PNP0D40" }, 251 { "PNP0D40" },
251 { }, 252 { },
252}; 253};
@@ -257,6 +258,7 @@ static const struct acpi_device_id sdhci_acpi_ids[] = {
257 { "INT33BB" }, 258 { "INT33BB" },
258 { "INT33C6" }, 259 { "INT33C6" },
259 { "INT3436" }, 260 { "INT3436" },
261 { "INT344D" },
260 { "PNP0D40" }, 262 { "PNP0D40" },
261 { }, 263 { },
262}; 264};
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
index 03427755b902..4f38554ce679 100644
--- a/drivers/mmc/host/sdhci-pci.c
+++ b/drivers/mmc/host/sdhci-pci.c
@@ -993,6 +993,31 @@ static const struct pci_device_id pci_ids[] = {
993 .subdevice = PCI_ANY_ID, 993 .subdevice = PCI_ANY_ID,
994 .driver_data = (kernel_ulong_t)&sdhci_intel_mrfl_mmc, 994 .driver_data = (kernel_ulong_t)&sdhci_intel_mrfl_mmc,
995 }, 995 },
996
997 {
998 .vendor = PCI_VENDOR_ID_INTEL,
999 .device = PCI_DEVICE_ID_INTEL_SPT_EMMC,
1000 .subvendor = PCI_ANY_ID,
1001 .subdevice = PCI_ANY_ID,
1002 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
1003 },
1004
1005 {
1006 .vendor = PCI_VENDOR_ID_INTEL,
1007 .device = PCI_DEVICE_ID_INTEL_SPT_SDIO,
1008 .subvendor = PCI_ANY_ID,
1009 .subdevice = PCI_ANY_ID,
1010 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
1011 },
1012
1013 {
1014 .vendor = PCI_VENDOR_ID_INTEL,
1015 .device = PCI_DEVICE_ID_INTEL_SPT_SD,
1016 .subvendor = PCI_ANY_ID,
1017 .subdevice = PCI_ANY_ID,
1018 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
1019 },
1020
996 { 1021 {
997 .vendor = PCI_VENDOR_ID_O2, 1022 .vendor = PCI_VENDOR_ID_O2,
998 .device = PCI_DEVICE_ID_O2_8120, 1023 .device = PCI_DEVICE_ID_O2_8120,
diff --git a/drivers/mmc/host/sdhci-pci.h b/drivers/mmc/host/sdhci-pci.h
index d57c3d169914..1ec684d06d54 100644
--- a/drivers/mmc/host/sdhci-pci.h
+++ b/drivers/mmc/host/sdhci-pci.h
@@ -21,6 +21,9 @@
21#define PCI_DEVICE_ID_INTEL_CLV_EMMC0 0x08e5 21#define PCI_DEVICE_ID_INTEL_CLV_EMMC0 0x08e5
22#define PCI_DEVICE_ID_INTEL_CLV_EMMC1 0x08e6 22#define PCI_DEVICE_ID_INTEL_CLV_EMMC1 0x08e6
23#define PCI_DEVICE_ID_INTEL_QRK_SD 0x08A7 23#define PCI_DEVICE_ID_INTEL_QRK_SD 0x08A7
24#define PCI_DEVICE_ID_INTEL_SPT_EMMC 0x9d2b
25#define PCI_DEVICE_ID_INTEL_SPT_SDIO 0x9d2c
26#define PCI_DEVICE_ID_INTEL_SPT_SD 0x9d2d
24 27
25/* 28/*
26 * PCI registers 29 * PCI registers
diff --git a/drivers/mmc/host/sdhci-pxav3.c b/drivers/mmc/host/sdhci-pxav3.c
index 45238871192d..ca3424e7ef71 100644
--- a/drivers/mmc/host/sdhci-pxav3.c
+++ b/drivers/mmc/host/sdhci-pxav3.c
@@ -300,13 +300,6 @@ static int sdhci_pxav3_probe(struct platform_device *pdev)
300 if (IS_ERR(host)) 300 if (IS_ERR(host))
301 return PTR_ERR(host); 301 return PTR_ERR(host);
302 302
303 if (of_device_is_compatible(np, "marvell,armada-380-sdhci")) {
304 ret = mv_conf_mbus_windows(pdev, mv_mbus_dram_info());
305 if (ret < 0)
306 goto err_mbus_win;
307 }
308
309
310 pltfm_host = sdhci_priv(host); 303 pltfm_host = sdhci_priv(host);
311 pltfm_host->priv = pxa; 304 pltfm_host->priv = pxa;
312 305
@@ -325,6 +318,12 @@ static int sdhci_pxav3_probe(struct platform_device *pdev)
325 if (!IS_ERR(pxa->clk_core)) 318 if (!IS_ERR(pxa->clk_core))
326 clk_prepare_enable(pxa->clk_core); 319 clk_prepare_enable(pxa->clk_core);
327 320
321 if (of_device_is_compatible(np, "marvell,armada-380-sdhci")) {
322 ret = mv_conf_mbus_windows(pdev, mv_mbus_dram_info());
323 if (ret < 0)
324 goto err_mbus_win;
325 }
326
328 /* enable 1/8V DDR capable */ 327 /* enable 1/8V DDR capable */
329 host->mmc->caps |= MMC_CAP_1_8V_DDR; 328 host->mmc->caps |= MMC_CAP_1_8V_DDR;
330 329
@@ -396,11 +395,11 @@ err_add_host:
396 pm_runtime_disable(&pdev->dev); 395 pm_runtime_disable(&pdev->dev);
397err_of_parse: 396err_of_parse:
398err_cd_req: 397err_cd_req:
398err_mbus_win:
399 clk_disable_unprepare(pxa->clk_io); 399 clk_disable_unprepare(pxa->clk_io);
400 if (!IS_ERR(pxa->clk_core)) 400 if (!IS_ERR(pxa->clk_core))
401 clk_disable_unprepare(pxa->clk_core); 401 clk_disable_unprepare(pxa->clk_core);
402err_clk_get: 402err_clk_get:
403err_mbus_win:
404 sdhci_pltfm_free(pdev); 403 sdhci_pltfm_free(pdev);
405 return ret; 404 return ret;
406} 405}
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index cbb245b58538..f1a488ee432f 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -259,8 +259,6 @@ static void sdhci_reinit(struct sdhci_host *host)
259 259
260 del_timer_sync(&host->tuning_timer); 260 del_timer_sync(&host->tuning_timer);
261 host->flags &= ~SDHCI_NEEDS_RETUNING; 261 host->flags &= ~SDHCI_NEEDS_RETUNING;
262 host->mmc->max_blk_count =
263 (host->quirks & SDHCI_QUIRK_NO_MULTIBLOCK) ? 1 : 65535;
264 } 262 }
265 sdhci_enable_card_detection(host); 263 sdhci_enable_card_detection(host);
266} 264}
@@ -1273,6 +1271,12 @@ static void sdhci_set_power(struct sdhci_host *host, unsigned char mode,
1273 spin_unlock_irq(&host->lock); 1271 spin_unlock_irq(&host->lock);
1274 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, vdd); 1272 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, vdd);
1275 spin_lock_irq(&host->lock); 1273 spin_lock_irq(&host->lock);
1274
1275 if (mode != MMC_POWER_OFF)
1276 sdhci_writeb(host, SDHCI_POWER_ON, SDHCI_POWER_CONTROL);
1277 else
1278 sdhci_writeb(host, 0, SDHCI_POWER_CONTROL);
1279
1276 return; 1280 return;
1277 } 1281 }
1278 1282
@@ -1353,6 +1357,8 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1353 1357
1354 sdhci_runtime_pm_get(host); 1358 sdhci_runtime_pm_get(host);
1355 1359
1360 present = mmc_gpio_get_cd(host->mmc);
1361
1356 spin_lock_irqsave(&host->lock, flags); 1362 spin_lock_irqsave(&host->lock, flags);
1357 1363
1358 WARN_ON(host->mrq != NULL); 1364 WARN_ON(host->mrq != NULL);
@@ -1381,7 +1387,6 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1381 * zero: cd-gpio is used, and card is removed 1387 * zero: cd-gpio is used, and card is removed
1382 * one: cd-gpio is used, and card is present 1388 * one: cd-gpio is used, and card is present
1383 */ 1389 */
1384 present = mmc_gpio_get_cd(host->mmc);
1385 if (present < 0) { 1390 if (present < 0) {
1386 /* If polling, assume that the card is always present. */ 1391 /* If polling, assume that the card is always present. */
1387 if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) 1392 if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
@@ -1880,6 +1885,18 @@ static int sdhci_card_busy(struct mmc_host *mmc)
1880 return !(present_state & SDHCI_DATA_LVL_MASK); 1885 return !(present_state & SDHCI_DATA_LVL_MASK);
1881} 1886}
1882 1887
1888static int sdhci_prepare_hs400_tuning(struct mmc_host *mmc, struct mmc_ios *ios)
1889{
1890 struct sdhci_host *host = mmc_priv(mmc);
1891 unsigned long flags;
1892
1893 spin_lock_irqsave(&host->lock, flags);
1894 host->flags |= SDHCI_HS400_TUNING;
1895 spin_unlock_irqrestore(&host->lock, flags);
1896
1897 return 0;
1898}
1899
1883static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) 1900static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1884{ 1901{
1885 struct sdhci_host *host = mmc_priv(mmc); 1902 struct sdhci_host *host = mmc_priv(mmc);
@@ -1887,10 +1904,18 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1887 int tuning_loop_counter = MAX_TUNING_LOOP; 1904 int tuning_loop_counter = MAX_TUNING_LOOP;
1888 int err = 0; 1905 int err = 0;
1889 unsigned long flags; 1906 unsigned long flags;
1907 unsigned int tuning_count = 0;
1908 bool hs400_tuning;
1890 1909
1891 sdhci_runtime_pm_get(host); 1910 sdhci_runtime_pm_get(host);
1892 spin_lock_irqsave(&host->lock, flags); 1911 spin_lock_irqsave(&host->lock, flags);
1893 1912
1913 hs400_tuning = host->flags & SDHCI_HS400_TUNING;
1914 host->flags &= ~SDHCI_HS400_TUNING;
1915
1916 if (host->tuning_mode == SDHCI_TUNING_MODE_1)
1917 tuning_count = host->tuning_count;
1918
1894 /* 1919 /*
1895 * The Host Controller needs tuning only in case of SDR104 mode 1920 * The Host Controller needs tuning only in case of SDR104 mode
1896 * and for SDR50 mode when Use Tuning for SDR50 is set in the 1921 * and for SDR50 mode when Use Tuning for SDR50 is set in the
@@ -1899,8 +1924,20 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1899 * tuning function has to be executed. 1924 * tuning function has to be executed.
1900 */ 1925 */
1901 switch (host->timing) { 1926 switch (host->timing) {
1927 /* HS400 tuning is done in HS200 mode */
1902 case MMC_TIMING_MMC_HS400: 1928 case MMC_TIMING_MMC_HS400:
1929 err = -EINVAL;
1930 goto out_unlock;
1931
1903 case MMC_TIMING_MMC_HS200: 1932 case MMC_TIMING_MMC_HS200:
1933 /*
1934 * Periodic re-tuning for HS400 is not expected to be needed, so
1935 * disable it here.
1936 */
1937 if (hs400_tuning)
1938 tuning_count = 0;
1939 break;
1940
1904 case MMC_TIMING_UHS_SDR104: 1941 case MMC_TIMING_UHS_SDR104:
1905 break; 1942 break;
1906 1943
@@ -1911,9 +1948,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1911 /* FALLTHROUGH */ 1948 /* FALLTHROUGH */
1912 1949
1913 default: 1950 default:
1914 spin_unlock_irqrestore(&host->lock, flags); 1951 goto out_unlock;
1915 sdhci_runtime_pm_put(host);
1916 return 0;
1917 } 1952 }
1918 1953
1919 if (host->ops->platform_execute_tuning) { 1954 if (host->ops->platform_execute_tuning) {
@@ -2037,24 +2072,11 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
2037 } 2072 }
2038 2073
2039out: 2074out:
2040 /* 2075 host->flags &= ~SDHCI_NEEDS_RETUNING;
2041 * If this is the very first time we are here, we start the retuning 2076
2042 * timer. Since only during the first time, SDHCI_NEEDS_RETUNING 2077 if (tuning_count) {
2043 * flag won't be set, we check this condition before actually starting
2044 * the timer.
2045 */
2046 if (!(host->flags & SDHCI_NEEDS_RETUNING) && host->tuning_count &&
2047 (host->tuning_mode == SDHCI_TUNING_MODE_1)) {
2048 host->flags |= SDHCI_USING_RETUNING_TIMER; 2078 host->flags |= SDHCI_USING_RETUNING_TIMER;
2049 mod_timer(&host->tuning_timer, jiffies + 2079 mod_timer(&host->tuning_timer, jiffies + tuning_count * HZ);
2050 host->tuning_count * HZ);
2051 /* Tuning mode 1 limits the maximum data length to 4MB */
2052 mmc->max_blk_count = (4 * 1024 * 1024) / mmc->max_blk_size;
2053 } else if (host->flags & SDHCI_USING_RETUNING_TIMER) {
2054 host->flags &= ~SDHCI_NEEDS_RETUNING;
2055 /* Reload the new initial value for timer */
2056 mod_timer(&host->tuning_timer, jiffies +
2057 host->tuning_count * HZ);
2058 } 2080 }
2059 2081
2060 /* 2082 /*
@@ -2070,6 +2092,7 @@ out:
2070 2092
2071 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); 2093 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE);
2072 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); 2094 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
2095out_unlock:
2073 spin_unlock_irqrestore(&host->lock, flags); 2096 spin_unlock_irqrestore(&host->lock, flags);
2074 sdhci_runtime_pm_put(host); 2097 sdhci_runtime_pm_put(host);
2075 2098
@@ -2110,15 +2133,18 @@ static void sdhci_card_event(struct mmc_host *mmc)
2110{ 2133{
2111 struct sdhci_host *host = mmc_priv(mmc); 2134 struct sdhci_host *host = mmc_priv(mmc);
2112 unsigned long flags; 2135 unsigned long flags;
2136 int present;
2113 2137
2114 /* First check if client has provided their own card event */ 2138 /* First check if client has provided their own card event */
2115 if (host->ops->card_event) 2139 if (host->ops->card_event)
2116 host->ops->card_event(host); 2140 host->ops->card_event(host);
2117 2141
2142 present = sdhci_do_get_cd(host);
2143
2118 spin_lock_irqsave(&host->lock, flags); 2144 spin_lock_irqsave(&host->lock, flags);
2119 2145
2120 /* Check host->mrq first in case we are runtime suspended */ 2146 /* Check host->mrq first in case we are runtime suspended */
2121 if (host->mrq && !sdhci_do_get_cd(host)) { 2147 if (host->mrq && !present) {
2122 pr_err("%s: Card removed during transfer!\n", 2148 pr_err("%s: Card removed during transfer!\n",
2123 mmc_hostname(host->mmc)); 2149 mmc_hostname(host->mmc));
2124 pr_err("%s: Resetting controller.\n", 2150 pr_err("%s: Resetting controller.\n",
@@ -2142,6 +2168,7 @@ static const struct mmc_host_ops sdhci_ops = {
2142 .hw_reset = sdhci_hw_reset, 2168 .hw_reset = sdhci_hw_reset,
2143 .enable_sdio_irq = sdhci_enable_sdio_irq, 2169 .enable_sdio_irq = sdhci_enable_sdio_irq,
2144 .start_signal_voltage_switch = sdhci_start_signal_voltage_switch, 2170 .start_signal_voltage_switch = sdhci_start_signal_voltage_switch,
2171 .prepare_hs400_tuning = sdhci_prepare_hs400_tuning,
2145 .execute_tuning = sdhci_execute_tuning, 2172 .execute_tuning = sdhci_execute_tuning,
2146 .card_event = sdhci_card_event, 2173 .card_event = sdhci_card_event,
2147 .card_busy = sdhci_card_busy, 2174 .card_busy = sdhci_card_busy,
@@ -3260,8 +3287,9 @@ int sdhci_add_host(struct sdhci_host *host)
3260 mmc->max_segs = SDHCI_MAX_SEGS; 3287 mmc->max_segs = SDHCI_MAX_SEGS;
3261 3288
3262 /* 3289 /*
3263 * Maximum number of sectors in one transfer. Limited by DMA boundary 3290 * Maximum number of sectors in one transfer. Limited by SDMA boundary
3264 * size (512KiB). 3291 * size (512KiB). Note some tuning modes impose a 4MiB limit, but this
3292 * is less anyway.
3265 */ 3293 */
3266 mmc->max_req_size = 524288; 3294 mmc->max_req_size = 524288;
3267 3295
diff --git a/drivers/net/ethernet/allwinner/sun4i-emac.c b/drivers/net/ethernet/allwinner/sun4i-emac.c
index 1fcd5568a352..f3470d96837a 100644
--- a/drivers/net/ethernet/allwinner/sun4i-emac.c
+++ b/drivers/net/ethernet/allwinner/sun4i-emac.c
@@ -850,8 +850,10 @@ static int emac_probe(struct platform_device *pdev)
850 } 850 }
851 851
852 db->clk = devm_clk_get(&pdev->dev, NULL); 852 db->clk = devm_clk_get(&pdev->dev, NULL);
853 if (IS_ERR(db->clk)) 853 if (IS_ERR(db->clk)) {
854 ret = PTR_ERR(db->clk);
854 goto out; 855 goto out;
856 }
855 857
856 clk_prepare_enable(db->clk); 858 clk_prepare_enable(db->clk);
857 859
diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
index 3498760dc22a..760c72c6e2ac 100644
--- a/drivers/net/ethernet/altera/altera_tse_main.c
+++ b/drivers/net/ethernet/altera/altera_tse_main.c
@@ -1170,10 +1170,6 @@ tx_request_irq_error:
1170init_error: 1170init_error:
1171 free_skbufs(dev); 1171 free_skbufs(dev);
1172alloc_skbuf_error: 1172alloc_skbuf_error:
1173 if (priv->phydev) {
1174 phy_disconnect(priv->phydev);
1175 priv->phydev = NULL;
1176 }
1177phy_error: 1173phy_error:
1178 return ret; 1174 return ret;
1179} 1175}
@@ -1186,12 +1182,9 @@ static int tse_shutdown(struct net_device *dev)
1186 int ret; 1182 int ret;
1187 unsigned long int flags; 1183 unsigned long int flags;
1188 1184
1189 /* Stop and disconnect the PHY */ 1185 /* Stop the PHY */
1190 if (priv->phydev) { 1186 if (priv->phydev)
1191 phy_stop(priv->phydev); 1187 phy_stop(priv->phydev);
1192 phy_disconnect(priv->phydev);
1193 priv->phydev = NULL;
1194 }
1195 1188
1196 netif_stop_queue(dev); 1189 netif_stop_queue(dev);
1197 napi_disable(&priv->napi); 1190 napi_disable(&priv->napi);
@@ -1525,6 +1518,10 @@ err_free_netdev:
1525static int altera_tse_remove(struct platform_device *pdev) 1518static int altera_tse_remove(struct platform_device *pdev)
1526{ 1519{
1527 struct net_device *ndev = platform_get_drvdata(pdev); 1520 struct net_device *ndev = platform_get_drvdata(pdev);
1521 struct altera_tse_private *priv = netdev_priv(ndev);
1522
1523 if (priv->phydev)
1524 phy_disconnect(priv->phydev);
1528 1525
1529 platform_set_drvdata(pdev, NULL); 1526 platform_set_drvdata(pdev, NULL);
1530 altera_tse_mdio_destroy(ndev); 1527 altera_tse_mdio_destroy(ndev);
diff --git a/drivers/net/ethernet/atheros/alx/main.c b/drivers/net/ethernet/atheros/alx/main.c
index e398eda07298..c8af3ce3ea38 100644
--- a/drivers/net/ethernet/atheros/alx/main.c
+++ b/drivers/net/ethernet/atheros/alx/main.c
@@ -184,15 +184,16 @@ static void alx_schedule_reset(struct alx_priv *alx)
184 schedule_work(&alx->reset_wk); 184 schedule_work(&alx->reset_wk);
185} 185}
186 186
187static bool alx_clean_rx_irq(struct alx_priv *alx, int budget) 187static int alx_clean_rx_irq(struct alx_priv *alx, int budget)
188{ 188{
189 struct alx_rx_queue *rxq = &alx->rxq; 189 struct alx_rx_queue *rxq = &alx->rxq;
190 struct alx_rrd *rrd; 190 struct alx_rrd *rrd;
191 struct alx_buffer *rxb; 191 struct alx_buffer *rxb;
192 struct sk_buff *skb; 192 struct sk_buff *skb;
193 u16 length, rfd_cleaned = 0; 193 u16 length, rfd_cleaned = 0;
194 int work = 0;
194 195
195 while (budget > 0) { 196 while (work < budget) {
196 rrd = &rxq->rrd[rxq->rrd_read_idx]; 197 rrd = &rxq->rrd[rxq->rrd_read_idx];
197 if (!(rrd->word3 & cpu_to_le32(1 << RRD_UPDATED_SHIFT))) 198 if (!(rrd->word3 & cpu_to_le32(1 << RRD_UPDATED_SHIFT)))
198 break; 199 break;
@@ -203,7 +204,7 @@ static bool alx_clean_rx_irq(struct alx_priv *alx, int budget)
203 ALX_GET_FIELD(le32_to_cpu(rrd->word0), 204 ALX_GET_FIELD(le32_to_cpu(rrd->word0),
204 RRD_NOR) != 1) { 205 RRD_NOR) != 1) {
205 alx_schedule_reset(alx); 206 alx_schedule_reset(alx);
206 return 0; 207 return work;
207 } 208 }
208 209
209 rxb = &rxq->bufs[rxq->read_idx]; 210 rxb = &rxq->bufs[rxq->read_idx];
@@ -243,7 +244,7 @@ static bool alx_clean_rx_irq(struct alx_priv *alx, int budget)
243 } 244 }
244 245
245 napi_gro_receive(&alx->napi, skb); 246 napi_gro_receive(&alx->napi, skb);
246 budget--; 247 work++;
247 248
248next_pkt: 249next_pkt:
249 if (++rxq->read_idx == alx->rx_ringsz) 250 if (++rxq->read_idx == alx->rx_ringsz)
@@ -258,21 +259,22 @@ next_pkt:
258 if (rfd_cleaned) 259 if (rfd_cleaned)
259 alx_refill_rx_ring(alx, GFP_ATOMIC); 260 alx_refill_rx_ring(alx, GFP_ATOMIC);
260 261
261 return budget > 0; 262 return work;
262} 263}
263 264
264static int alx_poll(struct napi_struct *napi, int budget) 265static int alx_poll(struct napi_struct *napi, int budget)
265{ 266{
266 struct alx_priv *alx = container_of(napi, struct alx_priv, napi); 267 struct alx_priv *alx = container_of(napi, struct alx_priv, napi);
267 struct alx_hw *hw = &alx->hw; 268 struct alx_hw *hw = &alx->hw;
268 bool complete = true;
269 unsigned long flags; 269 unsigned long flags;
270 bool tx_complete;
271 int work;
270 272
271 complete = alx_clean_tx_irq(alx) && 273 tx_complete = alx_clean_tx_irq(alx);
272 alx_clean_rx_irq(alx, budget); 274 work = alx_clean_rx_irq(alx, budget);
273 275
274 if (!complete) 276 if (!tx_complete || work == budget)
275 return 1; 277 return budget;
276 278
277 napi_complete(&alx->napi); 279 napi_complete(&alx->napi);
278 280
@@ -284,7 +286,7 @@ static int alx_poll(struct napi_struct *napi, int budget)
284 286
285 alx_post_write(hw); 287 alx_post_write(hw);
286 288
287 return 0; 289 return work;
288} 290}
289 291
290static irqreturn_t alx_intr_handle(struct alx_priv *alx, u32 intr) 292static irqreturn_t alx_intr_handle(struct alx_priv *alx, u32 intr)
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 553dcd8a9df2..96bf01ba32dd 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -7413,6 +7413,8 @@ static inline void tg3_netif_start(struct tg3 *tp)
7413} 7413}
7414 7414
7415static void tg3_irq_quiesce(struct tg3 *tp) 7415static void tg3_irq_quiesce(struct tg3 *tp)
7416 __releases(tp->lock)
7417 __acquires(tp->lock)
7416{ 7418{
7417 int i; 7419 int i;
7418 7420
@@ -7421,8 +7423,12 @@ static void tg3_irq_quiesce(struct tg3 *tp)
7421 tp->irq_sync = 1; 7423 tp->irq_sync = 1;
7422 smp_mb(); 7424 smp_mb();
7423 7425
7426 spin_unlock_bh(&tp->lock);
7427
7424 for (i = 0; i < tp->irq_cnt; i++) 7428 for (i = 0; i < tp->irq_cnt; i++)
7425 synchronize_irq(tp->napi[i].irq_vec); 7429 synchronize_irq(tp->napi[i].irq_vec);
7430
7431 spin_lock_bh(&tp->lock);
7426} 7432}
7427 7433
7428/* Fully shutdown all tg3 driver activity elsewhere in the system. 7434/* Fully shutdown all tg3 driver activity elsewhere in the system.
@@ -9018,6 +9024,8 @@ static void tg3_restore_clk(struct tg3 *tp)
9018 9024
9019/* tp->lock is held. */ 9025/* tp->lock is held. */
9020static int tg3_chip_reset(struct tg3 *tp) 9026static int tg3_chip_reset(struct tg3 *tp)
9027 __releases(tp->lock)
9028 __acquires(tp->lock)
9021{ 9029{
9022 u32 val; 9030 u32 val;
9023 void (*write_op)(struct tg3 *, u32, u32); 9031 void (*write_op)(struct tg3 *, u32, u32);
@@ -9073,9 +9081,13 @@ static int tg3_chip_reset(struct tg3 *tp)
9073 } 9081 }
9074 smp_mb(); 9082 smp_mb();
9075 9083
9084 tg3_full_unlock(tp);
9085
9076 for (i = 0; i < tp->irq_cnt; i++) 9086 for (i = 0; i < tp->irq_cnt; i++)
9077 synchronize_irq(tp->napi[i].irq_vec); 9087 synchronize_irq(tp->napi[i].irq_vec);
9078 9088
9089 tg3_full_lock(tp, 0);
9090
9079 if (tg3_asic_rev(tp) == ASIC_REV_57780) { 9091 if (tg3_asic_rev(tp) == ASIC_REV_57780) {
9080 val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; 9092 val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN;
9081 tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); 9093 tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS);
@@ -10903,11 +10915,13 @@ static void tg3_timer(unsigned long __opaque)
10903{ 10915{
10904 struct tg3 *tp = (struct tg3 *) __opaque; 10916 struct tg3 *tp = (struct tg3 *) __opaque;
10905 10917
10906 if (tp->irq_sync || tg3_flag(tp, RESET_TASK_PENDING))
10907 goto restart_timer;
10908
10909 spin_lock(&tp->lock); 10918 spin_lock(&tp->lock);
10910 10919
10920 if (tp->irq_sync || tg3_flag(tp, RESET_TASK_PENDING)) {
10921 spin_unlock(&tp->lock);
10922 goto restart_timer;
10923 }
10924
10911 if (tg3_asic_rev(tp) == ASIC_REV_5717 || 10925 if (tg3_asic_rev(tp) == ASIC_REV_5717 ||
10912 tg3_flag(tp, 57765_CLASS)) 10926 tg3_flag(tp, 57765_CLASS))
10913 tg3_chk_missed_msi(tp); 10927 tg3_chk_missed_msi(tp);
@@ -11101,11 +11115,13 @@ static void tg3_reset_task(struct work_struct *work)
11101 struct tg3 *tp = container_of(work, struct tg3, reset_task); 11115 struct tg3 *tp = container_of(work, struct tg3, reset_task);
11102 int err; 11116 int err;
11103 11117
11118 rtnl_lock();
11104 tg3_full_lock(tp, 0); 11119 tg3_full_lock(tp, 0);
11105 11120
11106 if (!netif_running(tp->dev)) { 11121 if (!netif_running(tp->dev)) {
11107 tg3_flag_clear(tp, RESET_TASK_PENDING); 11122 tg3_flag_clear(tp, RESET_TASK_PENDING);
11108 tg3_full_unlock(tp); 11123 tg3_full_unlock(tp);
11124 rtnl_unlock();
11109 return; 11125 return;
11110 } 11126 }
11111 11127
@@ -11138,6 +11154,7 @@ out:
11138 tg3_phy_start(tp); 11154 tg3_phy_start(tp);
11139 11155
11140 tg3_flag_clear(tp, RESET_TASK_PENDING); 11156 tg3_flag_clear(tp, RESET_TASK_PENDING);
11157 rtnl_unlock();
11141} 11158}
11142 11159
11143static int tg3_request_irq(struct tg3 *tp, int irq_num) 11160static int tg3_request_irq(struct tg3 *tp, int irq_num)
diff --git a/drivers/net/ethernet/cadence/at91_ether.c b/drivers/net/ethernet/cadence/at91_ether.c
index 55eb7f2af2b4..7ef55f5fa664 100644
--- a/drivers/net/ethernet/cadence/at91_ether.c
+++ b/drivers/net/ethernet/cadence/at91_ether.c
@@ -340,7 +340,7 @@ static int __init at91ether_probe(struct platform_device *pdev)
340 res = PTR_ERR(lp->pclk); 340 res = PTR_ERR(lp->pclk);
341 goto err_free_dev; 341 goto err_free_dev;
342 } 342 }
343 clk_enable(lp->pclk); 343 clk_prepare_enable(lp->pclk);
344 344
345 lp->hclk = ERR_PTR(-ENOENT); 345 lp->hclk = ERR_PTR(-ENOENT);
346 lp->tx_clk = ERR_PTR(-ENOENT); 346 lp->tx_clk = ERR_PTR(-ENOENT);
@@ -406,7 +406,7 @@ static int __init at91ether_probe(struct platform_device *pdev)
406err_out_unregister_netdev: 406err_out_unregister_netdev:
407 unregister_netdev(dev); 407 unregister_netdev(dev);
408err_disable_clock: 408err_disable_clock:
409 clk_disable(lp->pclk); 409 clk_disable_unprepare(lp->pclk);
410err_free_dev: 410err_free_dev:
411 free_netdev(dev); 411 free_netdev(dev);
412 return res; 412 return res;
@@ -424,7 +424,7 @@ static int at91ether_remove(struct platform_device *pdev)
424 kfree(lp->mii_bus->irq); 424 kfree(lp->mii_bus->irq);
425 mdiobus_free(lp->mii_bus); 425 mdiobus_free(lp->mii_bus);
426 unregister_netdev(dev); 426 unregister_netdev(dev);
427 clk_disable(lp->pclk); 427 clk_disable_unprepare(lp->pclk);
428 free_netdev(dev); 428 free_netdev(dev);
429 429
430 return 0; 430 return 0;
@@ -440,7 +440,7 @@ static int at91ether_suspend(struct platform_device *pdev, pm_message_t mesg)
440 netif_stop_queue(net_dev); 440 netif_stop_queue(net_dev);
441 netif_device_detach(net_dev); 441 netif_device_detach(net_dev);
442 442
443 clk_disable(lp->pclk); 443 clk_disable_unprepare(lp->pclk);
444 } 444 }
445 return 0; 445 return 0;
446} 446}
@@ -451,7 +451,7 @@ static int at91ether_resume(struct platform_device *pdev)
451 struct macb *lp = netdev_priv(net_dev); 451 struct macb *lp = netdev_priv(net_dev);
452 452
453 if (netif_running(net_dev)) { 453 if (netif_running(net_dev)) {
454 clk_enable(lp->pclk); 454 clk_prepare_enable(lp->pclk);
455 455
456 netif_device_attach(net_dev); 456 netif_device_attach(net_dev);
457 netif_start_queue(net_dev); 457 netif_start_queue(net_dev);
diff --git a/drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c b/drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c
index 2215d432a059..a936ee8958c7 100644
--- a/drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c
@@ -2430,7 +2430,7 @@ static void cfg_queues(struct adapter *adapter)
2430 */ 2430 */
2431 n10g = 0; 2431 n10g = 0;
2432 for_each_port(adapter, pidx) 2432 for_each_port(adapter, pidx)
2433 n10g += is_10g_port(&adap2pinfo(adapter, pidx)->link_cfg); 2433 n10g += is_x_10g_port(&adap2pinfo(adapter, pidx)->link_cfg);
2434 2434
2435 /* 2435 /*
2436 * We default to 1 queue per non-10G port and up to # of cores queues 2436 * We default to 1 queue per non-10G port and up to # of cores queues
diff --git a/drivers/net/ethernet/chelsio/cxgb4vf/t4vf_hw.c b/drivers/net/ethernet/chelsio/cxgb4vf/t4vf_hw.c
index 21dc9a20308c..60426cf890a7 100644
--- a/drivers/net/ethernet/chelsio/cxgb4vf/t4vf_hw.c
+++ b/drivers/net/ethernet/chelsio/cxgb4vf/t4vf_hw.c
@@ -323,6 +323,8 @@ int t4vf_port_init(struct adapter *adapter, int pidx)
323 return v; 323 return v;
324 324
325 v = be32_to_cpu(port_rpl.u.info.lstatus_to_modtype); 325 v = be32_to_cpu(port_rpl.u.info.lstatus_to_modtype);
326 pi->mdio_addr = (v & FW_PORT_CMD_MDIOCAP_F) ?
327 FW_PORT_CMD_MDIOADDR_G(v) : -1;
326 pi->port_type = FW_PORT_CMD_PTYPE_G(v); 328 pi->port_type = FW_PORT_CMD_PTYPE_G(v);
327 pi->mod_type = FW_PORT_MOD_TYPE_NA; 329 pi->mod_type = FW_PORT_MOD_TYPE_NA;
328 330
diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
index 705f334ebb85..b29e027c476e 100644
--- a/drivers/net/ethernet/cisco/enic/enic_main.c
+++ b/drivers/net/ethernet/cisco/enic/enic_main.c
@@ -1616,7 +1616,7 @@ static int enic_open(struct net_device *netdev)
1616 if (vnic_rq_desc_used(&enic->rq[i]) == 0) { 1616 if (vnic_rq_desc_used(&enic->rq[i]) == 0) {
1617 netdev_err(netdev, "Unable to alloc receive buffers\n"); 1617 netdev_err(netdev, "Unable to alloc receive buffers\n");
1618 err = -ENOMEM; 1618 err = -ENOMEM;
1619 goto err_out_notify_unset; 1619 goto err_out_free_rq;
1620 } 1620 }
1621 } 1621 }
1622 1622
@@ -1649,7 +1649,9 @@ static int enic_open(struct net_device *netdev)
1649 1649
1650 return 0; 1650 return 0;
1651 1651
1652err_out_notify_unset: 1652err_out_free_rq:
1653 for (i = 0; i < enic->rq_count; i++)
1654 vnic_rq_clean(&enic->rq[i], enic_free_rq_buf);
1653 enic_dev_notify_unset(enic); 1655 enic_dev_notify_unset(enic);
1654err_out_free_intr: 1656err_out_free_intr:
1655 enic_free_intr(enic); 1657 enic_free_intr(enic);
diff --git a/drivers/net/ethernet/dnet.c b/drivers/net/ethernet/dnet.c
index a379c3e4b57f..13d00a38a5bd 100644
--- a/drivers/net/ethernet/dnet.c
+++ b/drivers/net/ethernet/dnet.c
@@ -398,13 +398,8 @@ static int dnet_poll(struct napi_struct *napi, int budget)
398 * break out of while loop if there are no more 398 * break out of while loop if there are no more
399 * packets waiting 399 * packets waiting
400 */ 400 */
401 if (!(dnet_readl(bp, RX_FIFO_WCNT) >> 16)) { 401 if (!(dnet_readl(bp, RX_FIFO_WCNT) >> 16))
402 napi_complete(napi); 402 break;
403 int_enable = dnet_readl(bp, INTR_ENB);
404 int_enable |= DNET_INTR_SRC_RX_CMDFIFOAF;
405 dnet_writel(bp, int_enable, INTR_ENB);
406 return 0;
407 }
408 403
409 cmd_word = dnet_readl(bp, RX_LEN_FIFO); 404 cmd_word = dnet_readl(bp, RX_LEN_FIFO);
410 pkt_len = cmd_word & 0xFFFF; 405 pkt_len = cmd_word & 0xFFFF;
@@ -433,20 +428,17 @@ static int dnet_poll(struct napi_struct *napi, int budget)
433 "size %u.\n", dev->name, pkt_len); 428 "size %u.\n", dev->name, pkt_len);
434 } 429 }
435 430
436 budget -= npackets;
437
438 if (npackets < budget) { 431 if (npackets < budget) {
439 /* We processed all packets available. Tell NAPI it can 432 /* We processed all packets available. Tell NAPI it can
440 * stop polling then re-enable rx interrupts */ 433 * stop polling then re-enable rx interrupts.
434 */
441 napi_complete(napi); 435 napi_complete(napi);
442 int_enable = dnet_readl(bp, INTR_ENB); 436 int_enable = dnet_readl(bp, INTR_ENB);
443 int_enable |= DNET_INTR_SRC_RX_CMDFIFOAF; 437 int_enable |= DNET_INTR_SRC_RX_CMDFIFOAF;
444 dnet_writel(bp, int_enable, INTR_ENB); 438 dnet_writel(bp, int_enable, INTR_ENB);
445 return 0;
446 } 439 }
447 440
448 /* There are still packets waiting */ 441 return npackets;
449 return 1;
450} 442}
451 443
452static irqreturn_t dnet_interrupt(int irq, void *dev_id) 444static irqreturn_t dnet_interrupt(int irq, void *dev_id)
diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h
index 469691ad4a1e..40132929daf7 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -424,6 +424,8 @@ struct bufdesc_ex {
424 * (40ns * 6). 424 * (40ns * 6).
425 */ 425 */
426#define FEC_QUIRK_BUG_CAPTURE (1 << 10) 426#define FEC_QUIRK_BUG_CAPTURE (1 << 10)
427/* Controller has only one MDIO bus */
428#define FEC_QUIRK_SINGLE_MDIO (1 << 11)
427 429
428struct fec_enet_priv_tx_q { 430struct fec_enet_priv_tx_q {
429 int index; 431 int index;
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 5ebdf8dc8a31..bba87775419d 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -91,7 +91,8 @@ static struct platform_device_id fec_devtype[] = {
91 .driver_data = 0, 91 .driver_data = 0,
92 }, { 92 }, {
93 .name = "imx28-fec", 93 .name = "imx28-fec",
94 .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_SWAP_FRAME, 94 .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_SWAP_FRAME |
95 FEC_QUIRK_SINGLE_MDIO,
95 }, { 96 }, {
96 .name = "imx6q-fec", 97 .name = "imx6q-fec",
97 .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT | 98 .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT |
@@ -1937,7 +1938,7 @@ static int fec_enet_mii_init(struct platform_device *pdev)
1937 int err = -ENXIO, i; 1938 int err = -ENXIO, i;
1938 1939
1939 /* 1940 /*
1940 * The dual fec interfaces are not equivalent with enet-mac. 1941 * The i.MX28 dual fec interfaces are not equal.
1941 * Here are the differences: 1942 * Here are the differences:
1942 * 1943 *
1943 * - fec0 supports MII & RMII modes while fec1 only supports RMII 1944 * - fec0 supports MII & RMII modes while fec1 only supports RMII
@@ -1952,7 +1953,7 @@ static int fec_enet_mii_init(struct platform_device *pdev)
1952 * mdio interface in board design, and need to be configured by 1953 * mdio interface in board design, and need to be configured by
1953 * fec0 mii_bus. 1954 * fec0 mii_bus.
1954 */ 1955 */
1955 if ((fep->quirks & FEC_QUIRK_ENET_MAC) && fep->dev_id > 0) { 1956 if ((fep->quirks & FEC_QUIRK_SINGLE_MDIO) && fep->dev_id > 0) {
1956 /* fec1 uses fec0 mii_bus */ 1957 /* fec1 uses fec0 mii_bus */
1957 if (mii_cnt && fec0_mii_bus) { 1958 if (mii_cnt && fec0_mii_bus) {
1958 fep->mii_bus = fec0_mii_bus; 1959 fep->mii_bus = fec0_mii_bus;
@@ -2015,7 +2016,7 @@ static int fec_enet_mii_init(struct platform_device *pdev)
2015 mii_cnt++; 2016 mii_cnt++;
2016 2017
2017 /* save fec0 mii_bus */ 2018 /* save fec0 mii_bus */
2018 if (fep->quirks & FEC_QUIRK_ENET_MAC) 2019 if (fep->quirks & FEC_QUIRK_SINGLE_MDIO)
2019 fec0_mii_bus = fep->mii_bus; 2020 fec0_mii_bus = fep->mii_bus;
2020 2021
2021 return 0; 2022 return 0;
@@ -3129,6 +3130,7 @@ fec_probe(struct platform_device *pdev)
3129 pdev->id_entry = of_id->data; 3130 pdev->id_entry = of_id->data;
3130 fep->quirks = pdev->id_entry->driver_data; 3131 fep->quirks = pdev->id_entry->driver_data;
3131 3132
3133 fep->netdev = ndev;
3132 fep->num_rx_queues = num_rx_qs; 3134 fep->num_rx_queues = num_rx_qs;
3133 fep->num_tx_queues = num_tx_qs; 3135 fep->num_tx_queues = num_tx_qs;
3134 3136
diff --git a/drivers/net/ethernet/intel/Kconfig b/drivers/net/ethernet/intel/Kconfig
index 5b8300a32bf5..4d61ef50b465 100644
--- a/drivers/net/ethernet/intel/Kconfig
+++ b/drivers/net/ethernet/intel/Kconfig
@@ -281,6 +281,17 @@ config I40E_DCB
281 281
282 If unsure, say N. 282 If unsure, say N.
283 283
284config I40E_FCOE
285 bool "Fibre Channel over Ethernet (FCoE)"
286 default n
287 depends on I40E && DCB && FCOE
288 ---help---
289 Say Y here if you want to use Fibre Channel over Ethernet (FCoE)
290 in the driver. This will create new netdev for exclusive FCoE
291 use with XL710 FCoE offloads enabled.
292
293 If unsure, say N.
294
284config I40EVF 295config I40EVF
285 tristate "Intel(R) XL710 X710 Virtual Function Ethernet support" 296 tristate "Intel(R) XL710 X710 Virtual Function Ethernet support"
286 depends on PCI_MSI 297 depends on PCI_MSI
diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c
index 781065eb5431..e9c3a87e5b11 100644
--- a/drivers/net/ethernet/intel/e100.c
+++ b/drivers/net/ethernet/intel/e100.c
@@ -1543,7 +1543,7 @@ static int e100_phy_init(struct nic *nic)
1543 mdio_write(netdev, nic->mii.phy_id, MII_BMCR, bmcr); 1543 mdio_write(netdev, nic->mii.phy_id, MII_BMCR, bmcr);
1544 } else if ((nic->mac >= mac_82550_D102) || ((nic->flags & ich) && 1544 } else if ((nic->mac >= mac_82550_D102) || ((nic->flags & ich) &&
1545 (mdio_read(netdev, nic->mii.phy_id, MII_TPISTATUS) & 0x8000) && 1545 (mdio_read(netdev, nic->mii.phy_id, MII_TPISTATUS) & 0x8000) &&
1546 !(nic->eeprom[eeprom_cnfg_mdix] & eeprom_mdix_enabled))) { 1546 (nic->eeprom[eeprom_cnfg_mdix] & eeprom_mdix_enabled))) {
1547 /* enable/disable MDI/MDI-X auto-switching. */ 1547 /* enable/disable MDI/MDI-X auto-switching. */
1548 mdio_write(netdev, nic->mii.phy_id, MII_NCONFIG, 1548 mdio_write(netdev, nic->mii.phy_id, MII_NCONFIG,
1549 nic->mii.force_media ? 0 : NCONFIG_AUTO_SWITCH); 1549 nic->mii.force_media ? 0 : NCONFIG_AUTO_SWITCH);
diff --git a/drivers/net/ethernet/intel/i40e/Makefile b/drivers/net/ethernet/intel/i40e/Makefile
index 4b94ddb29c24..c40581999121 100644
--- a/drivers/net/ethernet/intel/i40e/Makefile
+++ b/drivers/net/ethernet/intel/i40e/Makefile
@@ -44,4 +44,4 @@ i40e-objs := i40e_main.o \
44 i40e_virtchnl_pf.o 44 i40e_virtchnl_pf.o
45 45
46i40e-$(CONFIG_I40E_DCB) += i40e_dcb.o i40e_dcb_nl.o 46i40e-$(CONFIG_I40E_DCB) += i40e_dcb.o i40e_dcb_nl.o
47i40e-$(CONFIG_FCOE:m=y) += i40e_fcoe.o 47i40e-$(CONFIG_I40E_FCOE) += i40e_fcoe.o
diff --git a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c b/drivers/net/ethernet/intel/i40e/i40e_debugfs.c
index 433a55886ad2..cb0de455683e 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_debugfs.c
@@ -829,7 +829,7 @@ static void i40e_dbg_dump_desc(int cnt, int vsi_seid, int ring_id, int desc_n,
829 if (desc_n >= ring->count || desc_n < 0) { 829 if (desc_n >= ring->count || desc_n < 0) {
830 dev_info(&pf->pdev->dev, 830 dev_info(&pf->pdev->dev,
831 "descriptor %d not found\n", desc_n); 831 "descriptor %d not found\n", desc_n);
832 return; 832 goto out;
833 } 833 }
834 if (!is_rx_ring) { 834 if (!is_rx_ring) {
835 txd = I40E_TX_DESC(ring, desc_n); 835 txd = I40E_TX_DESC(ring, desc_n);
@@ -855,6 +855,8 @@ static void i40e_dbg_dump_desc(int cnt, int vsi_seid, int ring_id, int desc_n,
855 } else { 855 } else {
856 dev_info(&pf->pdev->dev, "dump desc rx/tx <vsi_seid> <ring_id> [<desc_n>]\n"); 856 dev_info(&pf->pdev->dev, "dump desc rx/tx <vsi_seid> <ring_id> [<desc_n>]\n");
857 } 857 }
858
859out:
858 kfree(ring); 860 kfree(ring);
859} 861}
860 862
diff --git a/drivers/net/ethernet/intel/i40e/i40e_osdep.h b/drivers/net/ethernet/intel/i40e/i40e_osdep.h
index 045b5c4b98b3..ad802dd0f67a 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_osdep.h
+++ b/drivers/net/ethernet/intel/i40e/i40e_osdep.h
@@ -78,7 +78,7 @@ do { \
78} while (0) 78} while (0)
79 79
80typedef enum i40e_status_code i40e_status; 80typedef enum i40e_status_code i40e_status;
81#if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE) 81#ifdef CONFIG_I40E_FCOE
82#define I40E_FCOE 82#define I40E_FCOE
83#endif /* CONFIG_FCOE or CONFIG_FCOE_MODULE */ 83#endif
84#endif /* _I40E_OSDEP_H_ */ 84#endif /* _I40E_OSDEP_H_ */
diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.c b/drivers/net/ethernet/intel/i40e/i40e_txrx.c
index 04b441460bbd..cecb340898fe 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_txrx.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.c
@@ -658,6 +658,8 @@ static inline u32 i40e_get_head(struct i40e_ring *tx_ring)
658 return le32_to_cpu(*(volatile __le32 *)head); 658 return le32_to_cpu(*(volatile __le32 *)head);
659} 659}
660 660
661#define WB_STRIDE 0x3
662
661/** 663/**
662 * i40e_clean_tx_irq - Reclaim resources after transmit completes 664 * i40e_clean_tx_irq - Reclaim resources after transmit completes
663 * @tx_ring: tx ring to clean 665 * @tx_ring: tx ring to clean
@@ -759,6 +761,18 @@ static bool i40e_clean_tx_irq(struct i40e_ring *tx_ring, int budget)
759 tx_ring->q_vector->tx.total_bytes += total_bytes; 761 tx_ring->q_vector->tx.total_bytes += total_bytes;
760 tx_ring->q_vector->tx.total_packets += total_packets; 762 tx_ring->q_vector->tx.total_packets += total_packets;
761 763
764 /* check to see if there are any non-cache aligned descriptors
765 * waiting to be written back, and kick the hardware to force
766 * them to be written back in case of napi polling
767 */
768 if (budget &&
769 !((i & WB_STRIDE) == WB_STRIDE) &&
770 !test_bit(__I40E_DOWN, &tx_ring->vsi->state) &&
771 (I40E_DESC_UNUSED(tx_ring) != tx_ring->count))
772 tx_ring->arm_wb = true;
773 else
774 tx_ring->arm_wb = false;
775
762 if (check_for_tx_hang(tx_ring) && i40e_check_tx_hang(tx_ring)) { 776 if (check_for_tx_hang(tx_ring) && i40e_check_tx_hang(tx_ring)) {
763 /* schedule immediate reset if we believe we hung */ 777 /* schedule immediate reset if we believe we hung */
764 dev_info(tx_ring->dev, "Detected Tx Unit Hang\n" 778 dev_info(tx_ring->dev, "Detected Tx Unit Hang\n"
@@ -777,13 +791,16 @@ static bool i40e_clean_tx_irq(struct i40e_ring *tx_ring, int budget)
777 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); 791 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
778 792
779 dev_info(tx_ring->dev, 793 dev_info(tx_ring->dev,
780 "tx hang detected on queue %d, resetting adapter\n", 794 "tx hang detected on queue %d, reset requested\n",
781 tx_ring->queue_index); 795 tx_ring->queue_index);
782 796
783 tx_ring->netdev->netdev_ops->ndo_tx_timeout(tx_ring->netdev); 797 /* do not fire the reset immediately, wait for the stack to
798 * decide we are truly stuck, also prevents every queue from
799 * simultaneously requesting a reset
800 */
784 801
785 /* the adapter is about to reset, no point in enabling stuff */ 802 /* the adapter is about to reset, no point in enabling polling */
786 return true; 803 budget = 1;
787 } 804 }
788 805
789 netdev_tx_completed_queue(netdev_get_tx_queue(tx_ring->netdev, 806 netdev_tx_completed_queue(netdev_get_tx_queue(tx_ring->netdev,
@@ -806,7 +823,25 @@ static bool i40e_clean_tx_irq(struct i40e_ring *tx_ring, int budget)
806 } 823 }
807 } 824 }
808 825
809 return budget > 0; 826 return !!budget;
827}
828
829/**
830 * i40e_force_wb - Arm hardware to do a wb on noncache aligned descriptors
831 * @vsi: the VSI we care about
832 * @q_vector: the vector on which to force writeback
833 *
834 **/
835static void i40e_force_wb(struct i40e_vsi *vsi, struct i40e_q_vector *q_vector)
836{
837 u32 val = I40E_PFINT_DYN_CTLN_INTENA_MASK |
838 I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK |
839 I40E_PFINT_DYN_CTLN_SW_ITR_INDX_ENA_MASK
840 /* allow 00 to be written to the index */;
841
842 wr32(&vsi->back->hw,
843 I40E_PFINT_DYN_CTLN(q_vector->v_idx + vsi->base_vector - 1),
844 val);
810} 845}
811 846
812/** 847/**
@@ -1290,9 +1325,7 @@ static inline void i40e_rx_checksum(struct i40e_vsi *vsi,
1290 * so the total length of IPv4 header is IHL*4 bytes 1325 * so the total length of IPv4 header is IHL*4 bytes
1291 * The UDP_0 bit *may* bet set if the *inner* header is UDP 1326 * The UDP_0 bit *may* bet set if the *inner* header is UDP
1292 */ 1327 */
1293 if (ipv4_tunnel && 1328 if (ipv4_tunnel) {
1294 (decoded.inner_prot != I40E_RX_PTYPE_INNER_PROT_UDP) &&
1295 !(rx_status & (1 << I40E_RX_DESC_STATUS_UDP_0_SHIFT))) {
1296 skb->transport_header = skb->mac_header + 1329 skb->transport_header = skb->mac_header +
1297 sizeof(struct ethhdr) + 1330 sizeof(struct ethhdr) +
1298 (ip_hdr(skb)->ihl * 4); 1331 (ip_hdr(skb)->ihl * 4);
@@ -1302,15 +1335,19 @@ static inline void i40e_rx_checksum(struct i40e_vsi *vsi,
1302 skb->protocol == htons(ETH_P_8021AD)) 1335 skb->protocol == htons(ETH_P_8021AD))
1303 ? VLAN_HLEN : 0; 1336 ? VLAN_HLEN : 0;
1304 1337
1305 rx_udp_csum = udp_csum(skb); 1338 if ((ip_hdr(skb)->protocol == IPPROTO_UDP) &&
1306 iph = ip_hdr(skb); 1339 (udp_hdr(skb)->check != 0)) {
1307 csum = csum_tcpudp_magic( 1340 rx_udp_csum = udp_csum(skb);
1308 iph->saddr, iph->daddr, 1341 iph = ip_hdr(skb);
1309 (skb->len - skb_transport_offset(skb)), 1342 csum = csum_tcpudp_magic(
1310 IPPROTO_UDP, rx_udp_csum); 1343 iph->saddr, iph->daddr,
1344 (skb->len - skb_transport_offset(skb)),
1345 IPPROTO_UDP, rx_udp_csum);
1311 1346
1312 if (udp_hdr(skb)->check != csum) 1347 if (udp_hdr(skb)->check != csum)
1313 goto checksum_fail; 1348 goto checksum_fail;
1349
1350 } /* else its GRE and so no outer UDP header */
1314 } 1351 }
1315 1352
1316 skb->ip_summed = CHECKSUM_UNNECESSARY; 1353 skb->ip_summed = CHECKSUM_UNNECESSARY;
@@ -1581,6 +1618,7 @@ int i40e_napi_poll(struct napi_struct *napi, int budget)
1581 struct i40e_vsi *vsi = q_vector->vsi; 1618 struct i40e_vsi *vsi = q_vector->vsi;
1582 struct i40e_ring *ring; 1619 struct i40e_ring *ring;
1583 bool clean_complete = true; 1620 bool clean_complete = true;
1621 bool arm_wb = false;
1584 int budget_per_ring; 1622 int budget_per_ring;
1585 1623
1586 if (test_bit(__I40E_DOWN, &vsi->state)) { 1624 if (test_bit(__I40E_DOWN, &vsi->state)) {
@@ -1591,8 +1629,10 @@ int i40e_napi_poll(struct napi_struct *napi, int budget)
1591 /* Since the actual Tx work is minimal, we can give the Tx a larger 1629 /* Since the actual Tx work is minimal, we can give the Tx a larger
1592 * budget and be more aggressive about cleaning up the Tx descriptors. 1630 * budget and be more aggressive about cleaning up the Tx descriptors.
1593 */ 1631 */
1594 i40e_for_each_ring(ring, q_vector->tx) 1632 i40e_for_each_ring(ring, q_vector->tx) {
1595 clean_complete &= i40e_clean_tx_irq(ring, vsi->work_limit); 1633 clean_complete &= i40e_clean_tx_irq(ring, vsi->work_limit);
1634 arm_wb |= ring->arm_wb;
1635 }
1596 1636
1597 /* We attempt to distribute budget to each Rx queue fairly, but don't 1637 /* We attempt to distribute budget to each Rx queue fairly, but don't
1598 * allow the budget to go below 1 because that would exit polling early. 1638 * allow the budget to go below 1 because that would exit polling early.
@@ -1603,8 +1643,11 @@ int i40e_napi_poll(struct napi_struct *napi, int budget)
1603 clean_complete &= i40e_clean_rx_irq(ring, budget_per_ring); 1643 clean_complete &= i40e_clean_rx_irq(ring, budget_per_ring);
1604 1644
1605 /* If work not completed, return budget and polling will return */ 1645 /* If work not completed, return budget and polling will return */
1606 if (!clean_complete) 1646 if (!clean_complete) {
1647 if (arm_wb)
1648 i40e_force_wb(vsi, q_vector);
1607 return budget; 1649 return budget;
1650 }
1608 1651
1609 /* Work is done so exit the polling mode and re-enable the interrupt */ 1652 /* Work is done so exit the polling mode and re-enable the interrupt */
1610 napi_complete(napi); 1653 napi_complete(napi);
@@ -1840,17 +1883,16 @@ static int i40e_tso(struct i40e_ring *tx_ring, struct sk_buff *skb,
1840 if (err < 0) 1883 if (err < 0)
1841 return err; 1884 return err;
1842 1885
1843 if (protocol == htons(ETH_P_IP)) { 1886 iph = skb->encapsulation ? inner_ip_hdr(skb) : ip_hdr(skb);
1844 iph = skb->encapsulation ? inner_ip_hdr(skb) : ip_hdr(skb); 1887 ipv6h = skb->encapsulation ? inner_ipv6_hdr(skb) : ipv6_hdr(skb);
1888
1889 if (iph->version == 4) {
1845 tcph = skb->encapsulation ? inner_tcp_hdr(skb) : tcp_hdr(skb); 1890 tcph = skb->encapsulation ? inner_tcp_hdr(skb) : tcp_hdr(skb);
1846 iph->tot_len = 0; 1891 iph->tot_len = 0;
1847 iph->check = 0; 1892 iph->check = 0;
1848 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, 1893 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
1849 0, IPPROTO_TCP, 0); 1894 0, IPPROTO_TCP, 0);
1850 } else if (skb_is_gso_v6(skb)) { 1895 } else if (ipv6h->version == 6) {
1851
1852 ipv6h = skb->encapsulation ? inner_ipv6_hdr(skb)
1853 : ipv6_hdr(skb);
1854 tcph = skb->encapsulation ? inner_tcp_hdr(skb) : tcp_hdr(skb); 1896 tcph = skb->encapsulation ? inner_tcp_hdr(skb) : tcp_hdr(skb);
1855 ipv6h->payload_len = 0; 1897 ipv6h->payload_len = 0;
1856 tcph->check = ~csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr, 1898 tcph->check = ~csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr,
@@ -1946,13 +1988,9 @@ static void i40e_tx_enable_csum(struct sk_buff *skb, u32 tx_flags,
1946 I40E_TX_CTX_EXT_IP_IPV4_NO_CSUM; 1988 I40E_TX_CTX_EXT_IP_IPV4_NO_CSUM;
1947 } 1989 }
1948 } else if (tx_flags & I40E_TX_FLAGS_IPV6) { 1990 } else if (tx_flags & I40E_TX_FLAGS_IPV6) {
1949 if (tx_flags & I40E_TX_FLAGS_TSO) { 1991 *cd_tunneling |= I40E_TX_CTX_EXT_IP_IPV6;
1950 *cd_tunneling |= I40E_TX_CTX_EXT_IP_IPV6; 1992 if (tx_flags & I40E_TX_FLAGS_TSO)
1951 ip_hdr(skb)->check = 0; 1993 ip_hdr(skb)->check = 0;
1952 } else {
1953 *cd_tunneling |=
1954 I40E_TX_CTX_EXT_IP_IPV4_NO_CSUM;
1955 }
1956 } 1994 }
1957 1995
1958 /* Now set the ctx descriptor fields */ 1996 /* Now set the ctx descriptor fields */
@@ -1962,7 +2000,10 @@ static void i40e_tx_enable_csum(struct sk_buff *skb, u32 tx_flags,
1962 ((skb_inner_network_offset(skb) - 2000 ((skb_inner_network_offset(skb) -
1963 skb_transport_offset(skb)) >> 1) << 2001 skb_transport_offset(skb)) >> 1) <<
1964 I40E_TXD_CTX_QW0_NATLEN_SHIFT; 2002 I40E_TXD_CTX_QW0_NATLEN_SHIFT;
1965 2003 if (this_ip_hdr->version == 6) {
2004 tx_flags &= ~I40E_TX_FLAGS_IPV4;
2005 tx_flags |= I40E_TX_FLAGS_IPV6;
2006 }
1966 } else { 2007 } else {
1967 network_hdr_len = skb_network_header_len(skb); 2008 network_hdr_len = skb_network_header_len(skb);
1968 this_ip_hdr = ip_hdr(skb); 2009 this_ip_hdr = ip_hdr(skb);
@@ -2198,7 +2239,6 @@ static void i40e_tx_map(struct i40e_ring *tx_ring, struct sk_buff *skb,
2198 /* Place RS bit on last descriptor of any packet that spans across the 2239 /* Place RS bit on last descriptor of any packet that spans across the
2199 * 4th descriptor (WB_STRIDE aka 0x3) in a 64B cacheline. 2240 * 4th descriptor (WB_STRIDE aka 0x3) in a 64B cacheline.
2200 */ 2241 */
2201#define WB_STRIDE 0x3
2202 if (((i & WB_STRIDE) != WB_STRIDE) && 2242 if (((i & WB_STRIDE) != WB_STRIDE) &&
2203 (first <= &tx_ring->tx_bi[i]) && 2243 (first <= &tx_ring->tx_bi[i]) &&
2204 (first >= &tx_ring->tx_bi[i & ~WB_STRIDE])) { 2244 (first >= &tx_ring->tx_bi[i & ~WB_STRIDE])) {
diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.h b/drivers/net/ethernet/intel/i40e/i40e_txrx.h
index e60d3accb2e2..18b00231d2f1 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_txrx.h
+++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.h
@@ -241,6 +241,7 @@ struct i40e_ring {
241 unsigned long last_rx_timestamp; 241 unsigned long last_rx_timestamp;
242 242
243 bool ring_active; /* is ring online or not */ 243 bool ring_active; /* is ring online or not */
244 bool arm_wb; /* do something to arm write back */
244 245
245 /* stats structs */ 246 /* stats structs */
246 struct i40e_queue_stats stats; 247 struct i40e_queue_stats stats;
diff --git a/drivers/net/ethernet/intel/igb/e1000_82575.c b/drivers/net/ethernet/intel/igb/e1000_82575.c
index 051ea94bdcd3..0f69ef81751a 100644
--- a/drivers/net/ethernet/intel/igb/e1000_82575.c
+++ b/drivers/net/ethernet/intel/igb/e1000_82575.c
@@ -1125,7 +1125,7 @@ static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
1125 u32 swmask = mask; 1125 u32 swmask = mask;
1126 u32 fwmask = mask << 16; 1126 u32 fwmask = mask << 16;
1127 s32 ret_val = 0; 1127 s32 ret_val = 0;
1128 s32 i = 0, timeout = 200; /* FIXME: find real value to use here */ 1128 s32 i = 0, timeout = 200;
1129 1129
1130 while (i < timeout) { 1130 while (i < timeout) {
1131 if (igb_get_hw_semaphore(hw)) { 1131 if (igb_get_hw_semaphore(hw)) {
diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
index 943cbd47d832..03e9eb0dc761 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -1829,7 +1829,7 @@ static int mlx4_init_hca(struct mlx4_dev *dev)
1829 err = mlx4_dev_cap(dev, &dev_cap); 1829 err = mlx4_dev_cap(dev, &dev_cap);
1830 if (err) { 1830 if (err) {
1831 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting\n"); 1831 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting\n");
1832 goto err_stop_fw; 1832 return err;
1833 } 1833 }
1834 1834
1835 choose_steering_mode(dev, &dev_cap); 1835 choose_steering_mode(dev, &dev_cap);
@@ -1860,7 +1860,7 @@ static int mlx4_init_hca(struct mlx4_dev *dev)
1860 &init_hca); 1860 &init_hca);
1861 if ((long long) icm_size < 0) { 1861 if ((long long) icm_size < 0) {
1862 err = icm_size; 1862 err = icm_size;
1863 goto err_stop_fw; 1863 return err;
1864 } 1864 }
1865 1865
1866 dev->caps.max_fmr_maps = (1 << (32 - ilog2(dev->caps.num_mpts))) - 1; 1866 dev->caps.max_fmr_maps = (1 << (32 - ilog2(dev->caps.num_mpts))) - 1;
@@ -1874,7 +1874,7 @@ static int mlx4_init_hca(struct mlx4_dev *dev)
1874 1874
1875 err = mlx4_init_icm(dev, &dev_cap, &init_hca, icm_size); 1875 err = mlx4_init_icm(dev, &dev_cap, &init_hca, icm_size);
1876 if (err) 1876 if (err)
1877 goto err_stop_fw; 1877 return err;
1878 1878
1879 err = mlx4_INIT_HCA(dev, &init_hca); 1879 err = mlx4_INIT_HCA(dev, &init_hca);
1880 if (err) { 1880 if (err) {
@@ -1886,7 +1886,7 @@ static int mlx4_init_hca(struct mlx4_dev *dev)
1886 err = mlx4_query_func(dev, &dev_cap); 1886 err = mlx4_query_func(dev, &dev_cap);
1887 if (err < 0) { 1887 if (err < 0) {
1888 mlx4_err(dev, "QUERY_FUNC command failed, aborting.\n"); 1888 mlx4_err(dev, "QUERY_FUNC command failed, aborting.\n");
1889 goto err_stop_fw; 1889 goto err_close;
1890 } else if (err & MLX4_QUERY_FUNC_NUM_SYS_EQS) { 1890 } else if (err & MLX4_QUERY_FUNC_NUM_SYS_EQS) {
1891 dev->caps.num_eqs = dev_cap.max_eqs; 1891 dev->caps.num_eqs = dev_cap.max_eqs;
1892 dev->caps.reserved_eqs = dev_cap.reserved_eqs; 1892 dev->caps.reserved_eqs = dev_cap.reserved_eqs;
@@ -2006,11 +2006,6 @@ err_free_icm:
2006 if (!mlx4_is_slave(dev)) 2006 if (!mlx4_is_slave(dev))
2007 mlx4_free_icms(dev); 2007 mlx4_free_icms(dev);
2008 2008
2009err_stop_fw:
2010 if (!mlx4_is_slave(dev)) {
2011 mlx4_UNMAP_FA(dev);
2012 mlx4_free_icm(dev, priv->fw.fw_icm, 0);
2013 }
2014 return err; 2009 return err;
2015} 2010}
2016 2011
diff --git a/drivers/net/ethernet/mellanox/mlx4/mr.c b/drivers/net/ethernet/mellanox/mlx4/mr.c
index d6f549685c0f..7094a9c70fd5 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mr.c
+++ b/drivers/net/ethernet/mellanox/mlx4/mr.c
@@ -584,6 +584,7 @@ EXPORT_SYMBOL_GPL(mlx4_mr_free);
584void mlx4_mr_rereg_mem_cleanup(struct mlx4_dev *dev, struct mlx4_mr *mr) 584void mlx4_mr_rereg_mem_cleanup(struct mlx4_dev *dev, struct mlx4_mr *mr)
585{ 585{
586 mlx4_mtt_cleanup(dev, &mr->mtt); 586 mlx4_mtt_cleanup(dev, &mr->mtt);
587 mr->mtt.order = -1;
587} 588}
588EXPORT_SYMBOL_GPL(mlx4_mr_rereg_mem_cleanup); 589EXPORT_SYMBOL_GPL(mlx4_mr_rereg_mem_cleanup);
589 590
@@ -593,14 +594,14 @@ int mlx4_mr_rereg_mem_write(struct mlx4_dev *dev, struct mlx4_mr *mr,
593{ 594{
594 int err; 595 int err;
595 596
596 mpt_entry->start = cpu_to_be64(iova);
597 mpt_entry->length = cpu_to_be64(size);
598 mpt_entry->entity_size = cpu_to_be32(page_shift);
599
600 err = mlx4_mtt_init(dev, npages, page_shift, &mr->mtt); 597 err = mlx4_mtt_init(dev, npages, page_shift, &mr->mtt);
601 if (err) 598 if (err)
602 return err; 599 return err;
603 600
601 mpt_entry->start = cpu_to_be64(mr->iova);
602 mpt_entry->length = cpu_to_be64(mr->size);
603 mpt_entry->entity_size = cpu_to_be32(mr->mtt.page_shift);
604
604 mpt_entry->pd_flags &= cpu_to_be32(MLX4_MPT_PD_MASK | 605 mpt_entry->pd_flags &= cpu_to_be32(MLX4_MPT_PD_MASK |
605 MLX4_MPT_PD_FLAG_EN_INV); 606 MLX4_MPT_PD_FLAG_EN_INV);
606 mpt_entry->flags &= cpu_to_be32(MLX4_MPT_FLAG_FREE | 607 mpt_entry->flags &= cpu_to_be32(MLX4_MPT_FLAG_FREE |
diff --git a/drivers/net/ethernet/myricom/myri10ge/myri10ge.c b/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
index af099057f0e9..71af98bb72cb 100644
--- a/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
+++ b/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
@@ -4033,8 +4033,10 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
4033 (void)pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); 4033 (void)pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
4034 mgp->cmd = dma_alloc_coherent(&pdev->dev, sizeof(*mgp->cmd), 4034 mgp->cmd = dma_alloc_coherent(&pdev->dev, sizeof(*mgp->cmd),
4035 &mgp->cmd_bus, GFP_KERNEL); 4035 &mgp->cmd_bus, GFP_KERNEL);
4036 if (mgp->cmd == NULL) 4036 if (!mgp->cmd) {
4037 status = -ENOMEM;
4037 goto abort_with_enabled; 4038 goto abort_with_enabled;
4039 }
4038 4040
4039 mgp->board_span = pci_resource_len(pdev, 0); 4041 mgp->board_span = pci_resource_len(pdev, 0);
4040 mgp->iomem_base = pci_resource_start(pdev, 0); 4042 mgp->iomem_base = pci_resource_start(pdev, 0);
diff --git a/drivers/net/ethernet/qlogic/qla3xxx.c b/drivers/net/ethernet/qlogic/qla3xxx.c
index c2f09af5c25b..4847713211ca 100644
--- a/drivers/net/ethernet/qlogic/qla3xxx.c
+++ b/drivers/net/ethernet/qlogic/qla3xxx.c
@@ -146,10 +146,7 @@ static int ql_wait_for_drvr_lock(struct ql3_adapter *qdev)
146{ 146{
147 int i = 0; 147 int i = 0;
148 148
149 while (i < 10) { 149 do {
150 if (i)
151 ssleep(1);
152
153 if (ql_sem_lock(qdev, 150 if (ql_sem_lock(qdev,
154 QL_DRVR_SEM_MASK, 151 QL_DRVR_SEM_MASK,
155 (QL_RESOURCE_BITS_BASE_CODE | (qdev->mac_index) 152 (QL_RESOURCE_BITS_BASE_CODE | (qdev->mac_index)
@@ -158,7 +155,8 @@ static int ql_wait_for_drvr_lock(struct ql3_adapter *qdev)
158 "driver lock acquired\n"); 155 "driver lock acquired\n");
159 return 1; 156 return 1;
160 } 157 }
161 } 158 ssleep(1);
159 } while (++i < 10);
162 160
163 netdev_err(qdev->ndev, "Timed out waiting for driver lock...\n"); 161 netdev_err(qdev->ndev, "Timed out waiting for driver lock...\n");
164 return 0; 162 return 0;
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
index 9929b97cfb36..2528c3fb6b90 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
@@ -2605,6 +2605,7 @@ qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2605 } else { 2605 } else {
2606 dev_err(&pdev->dev, 2606 dev_err(&pdev->dev,
2607 "%s: failed. Please Reboot\n", __func__); 2607 "%s: failed. Please Reboot\n", __func__);
2608 err = -ENODEV;
2608 goto err_out_free_hw; 2609 goto err_out_free_hw;
2609 } 2610 }
2610 2611
diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index c29ba80ae02b..37583a9d8853 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -473,6 +473,7 @@ static struct sh_eth_cpu_data r8a777x_data = {
473 .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE | 473 .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE |
474 EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE | 474 EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE |
475 EESR_ECI, 475 EESR_ECI,
476 .fdr_value = 0x00000f0f,
476 477
477 .apr = 1, 478 .apr = 1,
478 .mpr = 1, 479 .mpr = 1,
@@ -495,6 +496,7 @@ static struct sh_eth_cpu_data r8a779x_data = {
495 .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE | 496 .eesr_err_check = EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE |
496 EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE | 497 EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE |
497 EESR_ECI, 498 EESR_ECI,
499 .fdr_value = 0x00000f0f,
498 500
499 .apr = 1, 501 .apr = 1,
500 .mpr = 1, 502 .mpr = 1,
@@ -536,6 +538,8 @@ static struct sh_eth_cpu_data sh7724_data = {
536 EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE | 538 EESR_RDE | EESR_RFRMER | EESR_TFE | EESR_TDE |
537 EESR_ECI, 539 EESR_ECI,
538 540
541 .trscer_err_mask = DESC_I_RINT8,
542
539 .apr = 1, 543 .apr = 1,
540 .mpr = 1, 544 .mpr = 1,
541 .tpauser = 1, 545 .tpauser = 1,
@@ -856,6 +860,9 @@ static void sh_eth_set_default_cpu_data(struct sh_eth_cpu_data *cd)
856 860
857 if (!cd->eesr_err_check) 861 if (!cd->eesr_err_check)
858 cd->eesr_err_check = DEFAULT_EESR_ERR_CHECK; 862 cd->eesr_err_check = DEFAULT_EESR_ERR_CHECK;
863
864 if (!cd->trscer_err_mask)
865 cd->trscer_err_mask = DEFAULT_TRSCER_ERR_MASK;
859} 866}
860 867
861static int sh_eth_check_reset(struct net_device *ndev) 868static int sh_eth_check_reset(struct net_device *ndev)
@@ -1294,7 +1301,7 @@ static int sh_eth_dev_init(struct net_device *ndev, bool start)
1294 /* Frame recv control (enable multiple-packets per rx irq) */ 1301 /* Frame recv control (enable multiple-packets per rx irq) */
1295 sh_eth_write(ndev, RMCR_RNC, RMCR); 1302 sh_eth_write(ndev, RMCR_RNC, RMCR);
1296 1303
1297 sh_eth_write(ndev, DESC_I_RINT8 | DESC_I_RINT5 | DESC_I_TINT2, TRSCER); 1304 sh_eth_write(ndev, mdp->cd->trscer_err_mask, TRSCER);
1298 1305
1299 if (mdp->cd->bculr) 1306 if (mdp->cd->bculr)
1300 sh_eth_write(ndev, 0x800, BCULR); /* Burst sycle set */ 1307 sh_eth_write(ndev, 0x800, BCULR); /* Burst sycle set */
diff --git a/drivers/net/ethernet/renesas/sh_eth.h b/drivers/net/ethernet/renesas/sh_eth.h
index 22301bf9c21d..71f5de1171bd 100644
--- a/drivers/net/ethernet/renesas/sh_eth.h
+++ b/drivers/net/ethernet/renesas/sh_eth.h
@@ -369,6 +369,8 @@ enum DESC_I_BIT {
369 DESC_I_RINT1 = 0x0001, 369 DESC_I_RINT1 = 0x0001,
370}; 370};
371 371
372#define DEFAULT_TRSCER_ERR_MASK (DESC_I_RINT8 | DESC_I_RINT5 | DESC_I_TINT2)
373
372/* RPADIR */ 374/* RPADIR */
373enum RPADIR_BIT { 375enum RPADIR_BIT {
374 RPADIR_PADS1 = 0x20000, RPADIR_PADS0 = 0x10000, 376 RPADIR_PADS1 = 0x20000, RPADIR_PADS0 = 0x10000,
@@ -470,6 +472,9 @@ struct sh_eth_cpu_data {
470 unsigned long tx_check; 472 unsigned long tx_check;
471 unsigned long eesr_err_check; 473 unsigned long eesr_err_check;
472 474
475 /* Error mask */
476 unsigned long trscer_err_mask;
477
473 /* hardware features */ 478 /* hardware features */
474 unsigned long irq_flags; /* IRQ configuration flags */ 479 unsigned long irq_flags; /* IRQ configuration flags */
475 unsigned no_psr:1; /* EtherC DO NOT have PSR */ 480 unsigned no_psr:1; /* EtherC DO NOT have PSR */
diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index c560f9aeb55d..64d1cef4cda1 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -610,7 +610,7 @@ static void cpsw_set_promiscious(struct net_device *ndev, bool enable)
610 610
611 /* Clear all mcast from ALE */ 611 /* Clear all mcast from ALE */
612 cpsw_ale_flush_multicast(ale, ALE_ALL_PORTS << 612 cpsw_ale_flush_multicast(ale, ALE_ALL_PORTS <<
613 priv->host_port); 613 priv->host_port, -1);
614 614
615 /* Flood All Unicast Packets to Host port */ 615 /* Flood All Unicast Packets to Host port */
616 cpsw_ale_control_set(ale, 0, ALE_P0_UNI_FLOOD, 1); 616 cpsw_ale_control_set(ale, 0, ALE_P0_UNI_FLOOD, 1);
@@ -634,6 +634,12 @@ static void cpsw_set_promiscious(struct net_device *ndev, bool enable)
634static void cpsw_ndo_set_rx_mode(struct net_device *ndev) 634static void cpsw_ndo_set_rx_mode(struct net_device *ndev)
635{ 635{
636 struct cpsw_priv *priv = netdev_priv(ndev); 636 struct cpsw_priv *priv = netdev_priv(ndev);
637 int vid;
638
639 if (priv->data.dual_emac)
640 vid = priv->slaves[priv->emac_port].port_vlan;
641 else
642 vid = priv->data.default_vlan;
637 643
638 if (ndev->flags & IFF_PROMISC) { 644 if (ndev->flags & IFF_PROMISC) {
639 /* Enable promiscuous mode */ 645 /* Enable promiscuous mode */
@@ -649,7 +655,8 @@ static void cpsw_ndo_set_rx_mode(struct net_device *ndev)
649 cpsw_ale_set_allmulti(priv->ale, priv->ndev->flags & IFF_ALLMULTI); 655 cpsw_ale_set_allmulti(priv->ale, priv->ndev->flags & IFF_ALLMULTI);
650 656
651 /* Clear all mcast from ALE */ 657 /* Clear all mcast from ALE */
652 cpsw_ale_flush_multicast(priv->ale, ALE_ALL_PORTS << priv->host_port); 658 cpsw_ale_flush_multicast(priv->ale, ALE_ALL_PORTS << priv->host_port,
659 vid);
653 660
654 if (!netdev_mc_empty(ndev)) { 661 if (!netdev_mc_empty(ndev)) {
655 struct netdev_hw_addr *ha; 662 struct netdev_hw_addr *ha;
@@ -757,6 +764,14 @@ requeue:
757static irqreturn_t cpsw_interrupt(int irq, void *dev_id) 764static irqreturn_t cpsw_interrupt(int irq, void *dev_id)
758{ 765{
759 struct cpsw_priv *priv = dev_id; 766 struct cpsw_priv *priv = dev_id;
767 int value = irq - priv->irqs_table[0];
768
769 /* NOTICE: Ending IRQ here. The trick with the 'value' variable above
770 * is to make sure we will always write the correct value to the EOI
771 * register. Namely 0 for RX_THRESH Interrupt, 1 for RX Interrupt, 2
772 * for TX Interrupt and 3 for MISC Interrupt.
773 */
774 cpdma_ctlr_eoi(priv->dma, value);
760 775
761 cpsw_intr_disable(priv); 776 cpsw_intr_disable(priv);
762 if (priv->irq_enabled == true) { 777 if (priv->irq_enabled == true) {
@@ -786,8 +801,6 @@ static int cpsw_poll(struct napi_struct *napi, int budget)
786 int num_tx, num_rx; 801 int num_tx, num_rx;
787 802
788 num_tx = cpdma_chan_process(priv->txch, 128); 803 num_tx = cpdma_chan_process(priv->txch, 128);
789 if (num_tx)
790 cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_TX);
791 804
792 num_rx = cpdma_chan_process(priv->rxch, budget); 805 num_rx = cpdma_chan_process(priv->rxch, budget);
793 if (num_rx < budget) { 806 if (num_rx < budget) {
@@ -795,7 +808,6 @@ static int cpsw_poll(struct napi_struct *napi, int budget)
795 808
796 napi_complete(napi); 809 napi_complete(napi);
797 cpsw_intr_enable(priv); 810 cpsw_intr_enable(priv);
798 cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_RX);
799 prim_cpsw = cpsw_get_slave_priv(priv, 0); 811 prim_cpsw = cpsw_get_slave_priv(priv, 0);
800 if (prim_cpsw->irq_enabled == false) { 812 if (prim_cpsw->irq_enabled == false) {
801 prim_cpsw->irq_enabled = true; 813 prim_cpsw->irq_enabled = true;
@@ -1310,8 +1322,6 @@ static int cpsw_ndo_open(struct net_device *ndev)
1310 napi_enable(&priv->napi); 1322 napi_enable(&priv->napi);
1311 cpdma_ctlr_start(priv->dma); 1323 cpdma_ctlr_start(priv->dma);
1312 cpsw_intr_enable(priv); 1324 cpsw_intr_enable(priv);
1313 cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_RX);
1314 cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_TX);
1315 1325
1316 prim_cpsw = cpsw_get_slave_priv(priv, 0); 1326 prim_cpsw = cpsw_get_slave_priv(priv, 0);
1317 if (prim_cpsw->irq_enabled == false) { 1327 if (prim_cpsw->irq_enabled == false) {
@@ -1578,9 +1588,6 @@ static void cpsw_ndo_tx_timeout(struct net_device *ndev)
1578 cpdma_chan_start(priv->txch); 1588 cpdma_chan_start(priv->txch);
1579 cpdma_ctlr_int_ctrl(priv->dma, true); 1589 cpdma_ctlr_int_ctrl(priv->dma, true);
1580 cpsw_intr_enable(priv); 1590 cpsw_intr_enable(priv);
1581 cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_RX);
1582 cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_TX);
1583
1584} 1591}
1585 1592
1586static int cpsw_ndo_set_mac_address(struct net_device *ndev, void *p) 1593static int cpsw_ndo_set_mac_address(struct net_device *ndev, void *p)
@@ -1620,9 +1627,6 @@ static void cpsw_ndo_poll_controller(struct net_device *ndev)
1620 cpsw_interrupt(ndev->irq, priv); 1627 cpsw_interrupt(ndev->irq, priv);
1621 cpdma_ctlr_int_ctrl(priv->dma, true); 1628 cpdma_ctlr_int_ctrl(priv->dma, true);
1622 cpsw_intr_enable(priv); 1629 cpsw_intr_enable(priv);
1623 cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_RX);
1624 cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_TX);
1625
1626} 1630}
1627#endif 1631#endif
1628 1632
diff --git a/drivers/net/ethernet/ti/cpsw_ale.c b/drivers/net/ethernet/ti/cpsw_ale.c
index 097ebe7077ac..5246b3a18ff8 100644
--- a/drivers/net/ethernet/ti/cpsw_ale.c
+++ b/drivers/net/ethernet/ti/cpsw_ale.c
@@ -234,7 +234,7 @@ static void cpsw_ale_flush_mcast(struct cpsw_ale *ale, u32 *ale_entry,
234 cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_FREE); 234 cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_FREE);
235} 235}
236 236
237int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask) 237int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask, int vid)
238{ 238{
239 u32 ale_entry[ALE_ENTRY_WORDS]; 239 u32 ale_entry[ALE_ENTRY_WORDS];
240 int ret, idx; 240 int ret, idx;
@@ -245,6 +245,14 @@ int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask)
245 if (ret != ALE_TYPE_ADDR && ret != ALE_TYPE_VLAN_ADDR) 245 if (ret != ALE_TYPE_ADDR && ret != ALE_TYPE_VLAN_ADDR)
246 continue; 246 continue;
247 247
248 /* if vid passed is -1 then remove all multicast entry from
249 * the table irrespective of vlan id, if a valid vlan id is
250 * passed then remove only multicast added to that vlan id.
251 * if vlan id doesn't match then move on to next entry.
252 */
253 if (vid != -1 && cpsw_ale_get_vlan_id(ale_entry) != vid)
254 continue;
255
248 if (cpsw_ale_get_mcast(ale_entry)) { 256 if (cpsw_ale_get_mcast(ale_entry)) {
249 u8 addr[6]; 257 u8 addr[6];
250 258
diff --git a/drivers/net/ethernet/ti/cpsw_ale.h b/drivers/net/ethernet/ti/cpsw_ale.h
index c0d4127aa549..af1e7ecd87c6 100644
--- a/drivers/net/ethernet/ti/cpsw_ale.h
+++ b/drivers/net/ethernet/ti/cpsw_ale.h
@@ -92,7 +92,7 @@ void cpsw_ale_stop(struct cpsw_ale *ale);
92 92
93int cpsw_ale_set_ageout(struct cpsw_ale *ale, int ageout); 93int cpsw_ale_set_ageout(struct cpsw_ale *ale, int ageout);
94int cpsw_ale_flush(struct cpsw_ale *ale, int port_mask); 94int cpsw_ale_flush(struct cpsw_ale *ale, int port_mask);
95int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask); 95int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask, int vid);
96int cpsw_ale_add_ucast(struct cpsw_ale *ale, u8 *addr, int port, 96int cpsw_ale_add_ucast(struct cpsw_ale *ale, u8 *addr, int port,
97 int flags, u16 vid); 97 int flags, u16 vid);
98int cpsw_ale_del_ucast(struct cpsw_ale *ale, u8 *addr, int port, 98int cpsw_ale_del_ucast(struct cpsw_ale *ale, u8 *addr, int port,
diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c
index 9c2d91ea0af4..dbcbf0c5bcfa 100644
--- a/drivers/net/ethernet/xilinx/ll_temac_main.c
+++ b/drivers/net/ethernet/xilinx/ll_temac_main.c
@@ -1043,6 +1043,7 @@ static int temac_of_probe(struct platform_device *op)
1043 lp->regs = of_iomap(op->dev.of_node, 0); 1043 lp->regs = of_iomap(op->dev.of_node, 0);
1044 if (!lp->regs) { 1044 if (!lp->regs) {
1045 dev_err(&op->dev, "could not map temac regs.\n"); 1045 dev_err(&op->dev, "could not map temac regs.\n");
1046 rc = -ENOMEM;
1046 goto nodev; 1047 goto nodev;
1047 } 1048 }
1048 1049
@@ -1062,6 +1063,7 @@ static int temac_of_probe(struct platform_device *op)
1062 np = of_parse_phandle(op->dev.of_node, "llink-connected", 0); 1063 np = of_parse_phandle(op->dev.of_node, "llink-connected", 0);
1063 if (!np) { 1064 if (!np) {
1064 dev_err(&op->dev, "could not find DMA node\n"); 1065 dev_err(&op->dev, "could not find DMA node\n");
1066 rc = -ENODEV;
1065 goto err_iounmap; 1067 goto err_iounmap;
1066 } 1068 }
1067 1069
diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
index c18a0c637c44..a6d2860b712c 100644
--- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
+++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
@@ -1501,6 +1501,7 @@ static int axienet_of_probe(struct platform_device *op)
1501 lp->regs = of_iomap(op->dev.of_node, 0); 1501 lp->regs = of_iomap(op->dev.of_node, 0);
1502 if (!lp->regs) { 1502 if (!lp->regs) {
1503 dev_err(&op->dev, "could not map Axi Ethernet regs.\n"); 1503 dev_err(&op->dev, "could not map Axi Ethernet regs.\n");
1504 ret = -ENOMEM;
1504 goto nodev; 1505 goto nodev;
1505 } 1506 }
1506 /* Setup checksum offload, but default to off if not specified */ 1507 /* Setup checksum offload, but default to off if not specified */
@@ -1563,6 +1564,7 @@ static int axienet_of_probe(struct platform_device *op)
1563 np = of_parse_phandle(op->dev.of_node, "axistream-connected", 0); 1564 np = of_parse_phandle(op->dev.of_node, "axistream-connected", 0);
1564 if (!np) { 1565 if (!np) {
1565 dev_err(&op->dev, "could not find DMA node\n"); 1566 dev_err(&op->dev, "could not find DMA node\n");
1567 ret = -ENODEV;
1566 goto err_iounmap; 1568 goto err_iounmap;
1567 } 1569 }
1568 lp->dma_regs = of_iomap(np, 0); 1570 lp->dma_regs = of_iomap(np, 0);
diff --git a/drivers/net/ethernet/xilinx/xilinx_emaclite.c b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
index 24858799c204..9d4ce388510a 100644
--- a/drivers/net/ethernet/xilinx/xilinx_emaclite.c
+++ b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
@@ -1109,6 +1109,7 @@ static int xemaclite_of_probe(struct platform_device *ofdev)
1109 res = platform_get_resource(ofdev, IORESOURCE_IRQ, 0); 1109 res = platform_get_resource(ofdev, IORESOURCE_IRQ, 0);
1110 if (!res) { 1110 if (!res) {
1111 dev_err(dev, "no IRQ found\n"); 1111 dev_err(dev, "no IRQ found\n");
1112 rc = -ENXIO;
1112 goto error; 1113 goto error;
1113 } 1114 }
1114 1115
diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
index 93e224217e24..f7ff493f1e73 100644
--- a/drivers/net/team/team.c
+++ b/drivers/net/team/team.c
@@ -629,6 +629,7 @@ static int team_change_mode(struct team *team, const char *kind)
629static void team_notify_peers_work(struct work_struct *work) 629static void team_notify_peers_work(struct work_struct *work)
630{ 630{
631 struct team *team; 631 struct team *team;
632 int val;
632 633
633 team = container_of(work, struct team, notify_peers.dw.work); 634 team = container_of(work, struct team, notify_peers.dw.work);
634 635
@@ -636,9 +637,14 @@ static void team_notify_peers_work(struct work_struct *work)
636 schedule_delayed_work(&team->notify_peers.dw, 0); 637 schedule_delayed_work(&team->notify_peers.dw, 0);
637 return; 638 return;
638 } 639 }
640 val = atomic_dec_if_positive(&team->notify_peers.count_pending);
641 if (val < 0) {
642 rtnl_unlock();
643 return;
644 }
639 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, team->dev); 645 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, team->dev);
640 rtnl_unlock(); 646 rtnl_unlock();
641 if (!atomic_dec_and_test(&team->notify_peers.count_pending)) 647 if (val)
642 schedule_delayed_work(&team->notify_peers.dw, 648 schedule_delayed_work(&team->notify_peers.dw,
643 msecs_to_jiffies(team->notify_peers.interval)); 649 msecs_to_jiffies(team->notify_peers.interval));
644} 650}
@@ -669,6 +675,7 @@ static void team_notify_peers_fini(struct team *team)
669static void team_mcast_rejoin_work(struct work_struct *work) 675static void team_mcast_rejoin_work(struct work_struct *work)
670{ 676{
671 struct team *team; 677 struct team *team;
678 int val;
672 679
673 team = container_of(work, struct team, mcast_rejoin.dw.work); 680 team = container_of(work, struct team, mcast_rejoin.dw.work);
674 681
@@ -676,9 +683,14 @@ static void team_mcast_rejoin_work(struct work_struct *work)
676 schedule_delayed_work(&team->mcast_rejoin.dw, 0); 683 schedule_delayed_work(&team->mcast_rejoin.dw, 0);
677 return; 684 return;
678 } 685 }
686 val = atomic_dec_if_positive(&team->mcast_rejoin.count_pending);
687 if (val < 0) {
688 rtnl_unlock();
689 return;
690 }
679 call_netdevice_notifiers(NETDEV_RESEND_IGMP, team->dev); 691 call_netdevice_notifiers(NETDEV_RESEND_IGMP, team->dev);
680 rtnl_unlock(); 692 rtnl_unlock();
681 if (!atomic_dec_and_test(&team->mcast_rejoin.count_pending)) 693 if (val)
682 schedule_delayed_work(&team->mcast_rejoin.dw, 694 schedule_delayed_work(&team->mcast_rejoin.dw,
683 msecs_to_jiffies(team->mcast_rejoin.interval)); 695 msecs_to_jiffies(team->mcast_rejoin.interval));
684} 696}
diff --git a/drivers/net/usb/kaweth.c b/drivers/net/usb/kaweth.c
index dcb6d33141e0..1e9cdca37014 100644
--- a/drivers/net/usb/kaweth.c
+++ b/drivers/net/usb/kaweth.c
@@ -1276,7 +1276,7 @@ static int usb_start_wait_urb(struct urb *urb, int timeout, int* actual_length)
1276 awd.done = 0; 1276 awd.done = 0;
1277 1277
1278 urb->context = &awd; 1278 urb->context = &awd;
1279 status = usb_submit_urb(urb, GFP_NOIO); 1279 status = usb_submit_urb(urb, GFP_ATOMIC);
1280 if (status) { 1280 if (status) {
1281 // something went wrong 1281 // something went wrong
1282 usb_free_urb(urb); 1282 usb_free_urb(urb);
diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index b8a82b86f909..602dc6668c3a 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -56,6 +56,8 @@ struct qmi_wwan_state {
56/* default ethernet address used by the modem */ 56/* default ethernet address used by the modem */
57static const u8 default_modem_addr[ETH_ALEN] = {0x02, 0x50, 0xf3}; 57static const u8 default_modem_addr[ETH_ALEN] = {0x02, 0x50, 0xf3};
58 58
59static const u8 buggy_fw_addr[ETH_ALEN] = {0x00, 0xa0, 0xc6, 0x00, 0x00, 0x00};
60
59/* Make up an ethernet header if the packet doesn't have one. 61/* Make up an ethernet header if the packet doesn't have one.
60 * 62 *
61 * A firmware bug common among several devices cause them to send raw 63 * A firmware bug common among several devices cause them to send raw
@@ -332,10 +334,12 @@ next_desc:
332 usb_driver_release_interface(driver, info->data); 334 usb_driver_release_interface(driver, info->data);
333 } 335 }
334 336
335 /* Never use the same address on both ends of the link, even 337 /* Never use the same address on both ends of the link, even if the
336 * if the buggy firmware told us to. 338 * buggy firmware told us to. Or, if device is assigned the well-known
339 * buggy firmware MAC address, replace it with a random address,
337 */ 340 */
338 if (ether_addr_equal(dev->net->dev_addr, default_modem_addr)) 341 if (ether_addr_equal(dev->net->dev_addr, default_modem_addr) ||
342 ether_addr_equal(dev->net->dev_addr, buggy_fw_addr))
339 eth_hw_addr_random(dev->net); 343 eth_hw_addr_random(dev->net);
340 344
341 /* make MAC addr easily distinguishable from an IP header */ 345 /* make MAC addr easily distinguishable from an IP header */
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 2d1c77e81836..57ec23e8ccfa 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -1897,6 +1897,22 @@ static void _rtl8152_set_rx_mode(struct net_device *netdev)
1897 netif_wake_queue(netdev); 1897 netif_wake_queue(netdev);
1898} 1898}
1899 1899
1900static netdev_features_t
1901rtl8152_features_check(struct sk_buff *skb, struct net_device *dev,
1902 netdev_features_t features)
1903{
1904 u32 mss = skb_shinfo(skb)->gso_size;
1905 int max_offset = mss ? GTTCPHO_MAX : TCPHO_MAX;
1906 int offset = skb_transport_offset(skb);
1907
1908 if ((mss || skb->ip_summed == CHECKSUM_PARTIAL) && offset > max_offset)
1909 features &= ~(NETIF_F_ALL_CSUM | NETIF_F_GSO_MASK);
1910 else if ((skb->len + sizeof(struct tx_desc)) > agg_buf_sz)
1911 features &= ~NETIF_F_GSO_MASK;
1912
1913 return features;
1914}
1915
1900static netdev_tx_t rtl8152_start_xmit(struct sk_buff *skb, 1916static netdev_tx_t rtl8152_start_xmit(struct sk_buff *skb,
1901 struct net_device *netdev) 1917 struct net_device *netdev)
1902{ 1918{
@@ -3706,6 +3722,7 @@ static const struct net_device_ops rtl8152_netdev_ops = {
3706 .ndo_set_mac_address = rtl8152_set_mac_address, 3722 .ndo_set_mac_address = rtl8152_set_mac_address,
3707 .ndo_change_mtu = rtl8152_change_mtu, 3723 .ndo_change_mtu = rtl8152_change_mtu,
3708 .ndo_validate_addr = eth_validate_addr, 3724 .ndo_validate_addr = eth_validate_addr,
3725 .ndo_features_check = rtl8152_features_check,
3709}; 3726};
3710 3727
3711static void r8152b_get_version(struct r8152 *tp) 3728static void r8152b_get_version(struct r8152 *tp)
diff --git a/drivers/net/wireless/iwlwifi/iwl-7000.c b/drivers/net/wireless/iwlwifi/iwl-7000.c
index e5be2d21868f..a5f9198d5747 100644
--- a/drivers/net/wireless/iwlwifi/iwl-7000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-7000.c
@@ -69,8 +69,8 @@
69#include "iwl-agn-hw.h" 69#include "iwl-agn-hw.h"
70 70
71/* Highest firmware API version supported */ 71/* Highest firmware API version supported */
72#define IWL7260_UCODE_API_MAX 10 72#define IWL7260_UCODE_API_MAX 12
73#define IWL3160_UCODE_API_MAX 10 73#define IWL3160_UCODE_API_MAX 12
74 74
75/* Oldest version we won't warn about */ 75/* Oldest version we won't warn about */
76#define IWL7260_UCODE_API_OK 10 76#define IWL7260_UCODE_API_OK 10
@@ -105,7 +105,7 @@
105#define IWL7265_MODULE_FIRMWARE(api) IWL7265_FW_PRE __stringify(api) ".ucode" 105#define IWL7265_MODULE_FIRMWARE(api) IWL7265_FW_PRE __stringify(api) ".ucode"
106 106
107#define IWL7265D_FW_PRE "iwlwifi-7265D-" 107#define IWL7265D_FW_PRE "iwlwifi-7265D-"
108#define IWL7265D_MODULE_FIRMWARE(api) IWL7265_FW_PRE __stringify(api) ".ucode" 108#define IWL7265D_MODULE_FIRMWARE(api) IWL7265D_FW_PRE __stringify(api) ".ucode"
109 109
110#define NVM_HW_SECTION_NUM_FAMILY_7000 0 110#define NVM_HW_SECTION_NUM_FAMILY_7000 0
111 111
diff --git a/drivers/net/wireless/iwlwifi/iwl-8000.c b/drivers/net/wireless/iwlwifi/iwl-8000.c
index bf0a95cb7153..3668fc57e770 100644
--- a/drivers/net/wireless/iwlwifi/iwl-8000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-8000.c
@@ -69,7 +69,7 @@
69#include "iwl-agn-hw.h" 69#include "iwl-agn-hw.h"
70 70
71/* Highest firmware API version supported */ 71/* Highest firmware API version supported */
72#define IWL8000_UCODE_API_MAX 10 72#define IWL8000_UCODE_API_MAX 12
73 73
74/* Oldest version we won't warn about */ 74/* Oldest version we won't warn about */
75#define IWL8000_UCODE_API_OK 10 75#define IWL8000_UCODE_API_OK 10
diff --git a/drivers/net/wireless/iwlwifi/iwl-fw-file.h b/drivers/net/wireless/iwlwifi/iwl-fw-file.h
index f2a047f6bb3e..1bbe4fc47b97 100644
--- a/drivers/net/wireless/iwlwifi/iwl-fw-file.h
+++ b/drivers/net/wireless/iwlwifi/iwl-fw-file.h
@@ -243,6 +243,9 @@ enum iwl_ucode_tlv_flag {
243 * @IWL_UCODE_TLV_API_SF_NO_DUMMY_NOTIF: ucode supports disabling dummy notif. 243 * @IWL_UCODE_TLV_API_SF_NO_DUMMY_NOTIF: ucode supports disabling dummy notif.
244 * @IWL_UCODE_TLV_API_FRAGMENTED_SCAN: This ucode supports active dwell time 244 * @IWL_UCODE_TLV_API_FRAGMENTED_SCAN: This ucode supports active dwell time
245 * longer than the passive one, which is essential for fragmented scan. 245 * longer than the passive one, which is essential for fragmented scan.
246 * @IWL_UCODE_TLV_API_BASIC_DWELL: use only basic dwell time in scan command,
247 * regardless of the band or the number of the probes. FW will calculate
248 * the actual dwell time.
246 */ 249 */
247enum iwl_ucode_tlv_api { 250enum iwl_ucode_tlv_api {
248 IWL_UCODE_TLV_API_WOWLAN_CONFIG_TID = BIT(0), 251 IWL_UCODE_TLV_API_WOWLAN_CONFIG_TID = BIT(0),
@@ -253,6 +256,7 @@ enum iwl_ucode_tlv_api {
253 IWL_UCODE_TLV_API_LMAC_SCAN = BIT(6), 256 IWL_UCODE_TLV_API_LMAC_SCAN = BIT(6),
254 IWL_UCODE_TLV_API_SF_NO_DUMMY_NOTIF = BIT(7), 257 IWL_UCODE_TLV_API_SF_NO_DUMMY_NOTIF = BIT(7),
255 IWL_UCODE_TLV_API_FRAGMENTED_SCAN = BIT(8), 258 IWL_UCODE_TLV_API_FRAGMENTED_SCAN = BIT(8),
259 IWL_UCODE_TLV_API_BASIC_DWELL = BIT(13),
256}; 260};
257 261
258/** 262/**
diff --git a/drivers/net/wireless/iwlwifi/mvm/fw-api-scan.h b/drivers/net/wireless/iwlwifi/mvm/fw-api-scan.h
index 1f2acf47bfb2..201846de94e7 100644
--- a/drivers/net/wireless/iwlwifi/mvm/fw-api-scan.h
+++ b/drivers/net/wireless/iwlwifi/mvm/fw-api-scan.h
@@ -672,6 +672,7 @@ struct iwl_scan_channel_opt {
672 * @IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED: all passive scans will be fragmented 672 * @IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED: all passive scans will be fragmented
673 * @IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED: insert WFA vendor-specific TPC report 673 * @IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED: insert WFA vendor-specific TPC report
674 * and DS parameter set IEs into probe requests. 674 * and DS parameter set IEs into probe requests.
675 * @IWL_MVM_LMAC_SCAN_FLAG_MATCH: Send match found notification on matches
675 */ 676 */
676enum iwl_mvm_lmac_scan_flags { 677enum iwl_mvm_lmac_scan_flags {
677 IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL = BIT(0), 678 IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL = BIT(0),
@@ -681,6 +682,7 @@ enum iwl_mvm_lmac_scan_flags {
681 IWL_MVM_LMAC_SCAN_FLAG_MULTIPLE_SSIDS = BIT(4), 682 IWL_MVM_LMAC_SCAN_FLAG_MULTIPLE_SSIDS = BIT(4),
682 IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED = BIT(5), 683 IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED = BIT(5),
683 IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED = BIT(6), 684 IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED = BIT(6),
685 IWL_MVM_LMAC_SCAN_FLAG_MATCH = BIT(9),
684}; 686};
685 687
686enum iwl_scan_priority { 688enum iwl_scan_priority {
diff --git a/drivers/net/wireless/iwlwifi/mvm/scan.c b/drivers/net/wireless/iwlwifi/mvm/scan.c
index e5294d01181e..ec9a8e7bae1d 100644
--- a/drivers/net/wireless/iwlwifi/mvm/scan.c
+++ b/drivers/net/wireless/iwlwifi/mvm/scan.c
@@ -171,15 +171,21 @@ static void iwl_mvm_scan_fill_ssids(struct iwl_ssid_ie *cmd_ssid,
171 * already included in the probe template, so we need to set only 171 * already included in the probe template, so we need to set only
172 * req->n_ssids - 1 bits in addition to the first bit. 172 * req->n_ssids - 1 bits in addition to the first bit.
173 */ 173 */
174static u16 iwl_mvm_get_active_dwell(enum ieee80211_band band, int n_ssids) 174static u16 iwl_mvm_get_active_dwell(struct iwl_mvm *mvm,
175 enum ieee80211_band band, int n_ssids)
175{ 176{
177 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BASIC_DWELL)
178 return 10;
176 if (band == IEEE80211_BAND_2GHZ) 179 if (band == IEEE80211_BAND_2GHZ)
177 return 20 + 3 * (n_ssids + 1); 180 return 20 + 3 * (n_ssids + 1);
178 return 10 + 2 * (n_ssids + 1); 181 return 10 + 2 * (n_ssids + 1);
179} 182}
180 183
181static u16 iwl_mvm_get_passive_dwell(enum ieee80211_band band) 184static u16 iwl_mvm_get_passive_dwell(struct iwl_mvm *mvm,
185 enum ieee80211_band band)
182{ 186{
187 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BASIC_DWELL)
188 return 110;
183 return band == IEEE80211_BAND_2GHZ ? 100 + 20 : 100 + 10; 189 return band == IEEE80211_BAND_2GHZ ? 100 + 20 : 100 + 10;
184} 190}
185 191
@@ -331,7 +337,8 @@ static void iwl_mvm_scan_calc_params(struct iwl_mvm *mvm,
331 */ 337 */
332 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 338 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
333 u32 passive_dwell = 339 u32 passive_dwell =
334 iwl_mvm_get_passive_dwell(IEEE80211_BAND_2GHZ); 340 iwl_mvm_get_passive_dwell(mvm,
341 IEEE80211_BAND_2GHZ);
335 params->max_out_time = passive_dwell; 342 params->max_out_time = passive_dwell;
336 } else { 343 } else {
337 params->passive_fragmented = true; 344 params->passive_fragmented = true;
@@ -348,8 +355,8 @@ not_bound:
348 params->dwell[band].passive = frag_passive_dwell; 355 params->dwell[band].passive = frag_passive_dwell;
349 else 356 else
350 params->dwell[band].passive = 357 params->dwell[band].passive =
351 iwl_mvm_get_passive_dwell(band); 358 iwl_mvm_get_passive_dwell(mvm, band);
352 params->dwell[band].active = iwl_mvm_get_active_dwell(band, 359 params->dwell[band].active = iwl_mvm_get_active_dwell(mvm, band,
353 n_ssids); 360 n_ssids);
354 } 361 }
355} 362}
@@ -1448,6 +1455,8 @@ int iwl_mvm_unified_sched_scan_lmac(struct iwl_mvm *mvm,
1448 1455
1449 if (iwl_mvm_scan_pass_all(mvm, req)) 1456 if (iwl_mvm_scan_pass_all(mvm, req))
1450 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL; 1457 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL;
1458 else
1459 flags |= IWL_MVM_LMAC_SCAN_FLAG_MATCH;
1451 1460
1452 if (req->n_ssids == 1 && req->ssids[0].ssid_len != 0) 1461 if (req->n_ssids == 1 && req->ssids[0].ssid_len != 0)
1453 flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION; 1462 flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION;
diff --git a/drivers/net/wireless/iwlwifi/mvm/tx.c b/drivers/net/wireless/iwlwifi/mvm/tx.c
index 4f15d9decc81..4333306ccdee 100644
--- a/drivers/net/wireless/iwlwifi/mvm/tx.c
+++ b/drivers/net/wireless/iwlwifi/mvm/tx.c
@@ -108,8 +108,12 @@ void iwl_mvm_set_tx_cmd(struct iwl_mvm *mvm, struct sk_buff *skb,
108 tx_flags &= ~TX_CMD_FLG_SEQ_CTL; 108 tx_flags &= ~TX_CMD_FLG_SEQ_CTL;
109 } 109 }
110 110
111 /* tid_tspec will default to 0 = BE when QOS isn't enabled */ 111 /* Default to 0 (BE) when tid_spec is set to IWL_TID_NON_QOS */
112 ac = tid_to_mac80211_ac[tx_cmd->tid_tspec]; 112 if (tx_cmd->tid_tspec < IWL_MAX_TID_COUNT)
113 ac = tid_to_mac80211_ac[tx_cmd->tid_tspec];
114 else
115 ac = tid_to_mac80211_ac[0];
116
113 tx_flags |= iwl_mvm_bt_coex_tx_prio(mvm, hdr, info, ac) << 117 tx_flags |= iwl_mvm_bt_coex_tx_prio(mvm, hdr, info, ac) <<
114 TX_CMD_FLG_BT_PRIO_POS; 118 TX_CMD_FLG_BT_PRIO_POS;
115 119
diff --git a/drivers/net/wireless/iwlwifi/mvm/utils.c b/drivers/net/wireless/iwlwifi/mvm/utils.c
index e56e77ef5d2e..917431e30f74 100644
--- a/drivers/net/wireless/iwlwifi/mvm/utils.c
+++ b/drivers/net/wireless/iwlwifi/mvm/utils.c
@@ -665,7 +665,7 @@ bool iwl_mvm_rx_diversity_allowed(struct iwl_mvm *mvm)
665 if (num_of_ant(mvm->fw->valid_rx_ant) == 1) 665 if (num_of_ant(mvm->fw->valid_rx_ant) == 1)
666 return false; 666 return false;
667 667
668 if (!mvm->cfg->rx_with_siso_diversity) 668 if (mvm->cfg->rx_with_siso_diversity)
669 return false; 669 return false;
670 670
671 ieee80211_iterate_active_interfaces_atomic( 671 ieee80211_iterate_active_interfaces_atomic(
diff --git a/drivers/net/wireless/iwlwifi/pcie/drv.c b/drivers/net/wireless/iwlwifi/pcie/drv.c
index 2f0c4b170344..d5aadb00dd9e 100644
--- a/drivers/net/wireless/iwlwifi/pcie/drv.c
+++ b/drivers/net/wireless/iwlwifi/pcie/drv.c
@@ -527,8 +527,10 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
527 else if (cfg == &iwl7265_n_cfg) 527 else if (cfg == &iwl7265_n_cfg)
528 cfg_7265d = &iwl7265d_n_cfg; 528 cfg_7265d = &iwl7265d_n_cfg;
529 if (cfg_7265d && 529 if (cfg_7265d &&
530 (iwl_trans->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_7265D) 530 (iwl_trans->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_7265D) {
531 cfg = cfg_7265d; 531 cfg = cfg_7265d;
532 iwl_trans->cfg = cfg_7265d;
533 }
532#endif 534#endif
533 535
534 pci_set_drvdata(pdev, iwl_trans); 536 pci_set_drvdata(pdev, iwl_trans);
diff --git a/drivers/net/wireless/rtlwifi/pci.c b/drivers/net/wireless/rtlwifi/pci.c
index 846a2e6e34d8..c70efb9a6e78 100644
--- a/drivers/net/wireless/rtlwifi/pci.c
+++ b/drivers/net/wireless/rtlwifi/pci.c
@@ -666,7 +666,8 @@ tx_status_ok:
666} 666}
667 667
668static int _rtl_pci_init_one_rxdesc(struct ieee80211_hw *hw, 668static int _rtl_pci_init_one_rxdesc(struct ieee80211_hw *hw,
669 u8 *entry, int rxring_idx, int desc_idx) 669 struct sk_buff *new_skb, u8 *entry,
670 int rxring_idx, int desc_idx)
670{ 671{
671 struct rtl_priv *rtlpriv = rtl_priv(hw); 672 struct rtl_priv *rtlpriv = rtl_priv(hw);
672 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 673 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
@@ -674,11 +675,15 @@ static int _rtl_pci_init_one_rxdesc(struct ieee80211_hw *hw,
674 u8 tmp_one = 1; 675 u8 tmp_one = 1;
675 struct sk_buff *skb; 676 struct sk_buff *skb;
676 677
678 if (likely(new_skb)) {
679 skb = new_skb;
680 goto remap;
681 }
677 skb = dev_alloc_skb(rtlpci->rxbuffersize); 682 skb = dev_alloc_skb(rtlpci->rxbuffersize);
678 if (!skb) 683 if (!skb)
679 return 0; 684 return 0;
680 rtlpci->rx_ring[rxring_idx].rx_buf[desc_idx] = skb;
681 685
686remap:
682 /* just set skb->cb to mapping addr for pci_unmap_single use */ 687 /* just set skb->cb to mapping addr for pci_unmap_single use */
683 *((dma_addr_t *)skb->cb) = 688 *((dma_addr_t *)skb->cb) =
684 pci_map_single(rtlpci->pdev, skb_tail_pointer(skb), 689 pci_map_single(rtlpci->pdev, skb_tail_pointer(skb),
@@ -686,6 +691,7 @@ static int _rtl_pci_init_one_rxdesc(struct ieee80211_hw *hw,
686 bufferaddress = *((dma_addr_t *)skb->cb); 691 bufferaddress = *((dma_addr_t *)skb->cb);
687 if (pci_dma_mapping_error(rtlpci->pdev, bufferaddress)) 692 if (pci_dma_mapping_error(rtlpci->pdev, bufferaddress))
688 return 0; 693 return 0;
694 rtlpci->rx_ring[rxring_idx].rx_buf[desc_idx] = skb;
689 if (rtlpriv->use_new_trx_flow) { 695 if (rtlpriv->use_new_trx_flow) {
690 rtlpriv->cfg->ops->set_desc(hw, (u8 *)entry, false, 696 rtlpriv->cfg->ops->set_desc(hw, (u8 *)entry, false,
691 HW_DESC_RX_PREPARE, 697 HW_DESC_RX_PREPARE,
@@ -781,6 +787,7 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
781 /*rx pkt */ 787 /*rx pkt */
782 struct sk_buff *skb = rtlpci->rx_ring[rxring_idx].rx_buf[ 788 struct sk_buff *skb = rtlpci->rx_ring[rxring_idx].rx_buf[
783 rtlpci->rx_ring[rxring_idx].idx]; 789 rtlpci->rx_ring[rxring_idx].idx];
790 struct sk_buff *new_skb;
784 791
785 if (rtlpriv->use_new_trx_flow) { 792 if (rtlpriv->use_new_trx_flow) {
786 rx_remained_cnt = 793 rx_remained_cnt =
@@ -807,6 +814,13 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
807 pci_unmap_single(rtlpci->pdev, *((dma_addr_t *)skb->cb), 814 pci_unmap_single(rtlpci->pdev, *((dma_addr_t *)skb->cb),
808 rtlpci->rxbuffersize, PCI_DMA_FROMDEVICE); 815 rtlpci->rxbuffersize, PCI_DMA_FROMDEVICE);
809 816
817 /* get a new skb - if fail, old one will be reused */
818 new_skb = dev_alloc_skb(rtlpci->rxbuffersize);
819 if (unlikely(!new_skb)) {
820 pr_err("Allocation of new skb failed in %s\n",
821 __func__);
822 goto no_new;
823 }
810 if (rtlpriv->use_new_trx_flow) { 824 if (rtlpriv->use_new_trx_flow) {
811 buffer_desc = 825 buffer_desc =
812 &rtlpci->rx_ring[rxring_idx].buffer_desc 826 &rtlpci->rx_ring[rxring_idx].buffer_desc
@@ -911,14 +925,16 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
911 schedule_work(&rtlpriv->works.lps_change_work); 925 schedule_work(&rtlpriv->works.lps_change_work);
912 } 926 }
913end: 927end:
928 skb = new_skb;
929no_new:
914 if (rtlpriv->use_new_trx_flow) { 930 if (rtlpriv->use_new_trx_flow) {
915 _rtl_pci_init_one_rxdesc(hw, (u8 *)buffer_desc, 931 _rtl_pci_init_one_rxdesc(hw, skb, (u8 *)buffer_desc,
916 rxring_idx, 932 rxring_idx,
917 rtlpci->rx_ring[rxring_idx].idx); 933 rtlpci->rx_ring[rxring_idx].idx);
918 } else { 934 } else {
919 _rtl_pci_init_one_rxdesc(hw, (u8 *)pdesc, rxring_idx, 935 _rtl_pci_init_one_rxdesc(hw, skb, (u8 *)pdesc,
936 rxring_idx,
920 rtlpci->rx_ring[rxring_idx].idx); 937 rtlpci->rx_ring[rxring_idx].idx);
921
922 if (rtlpci->rx_ring[rxring_idx].idx == 938 if (rtlpci->rx_ring[rxring_idx].idx ==
923 rtlpci->rxringcount - 1) 939 rtlpci->rxringcount - 1)
924 rtlpriv->cfg->ops->set_desc(hw, (u8 *)pdesc, 940 rtlpriv->cfg->ops->set_desc(hw, (u8 *)pdesc,
@@ -1307,7 +1323,7 @@ static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw, int rxring_idx)
1307 rtlpci->rx_ring[rxring_idx].idx = 0; 1323 rtlpci->rx_ring[rxring_idx].idx = 0;
1308 for (i = 0; i < rtlpci->rxringcount; i++) { 1324 for (i = 0; i < rtlpci->rxringcount; i++) {
1309 entry = &rtlpci->rx_ring[rxring_idx].buffer_desc[i]; 1325 entry = &rtlpci->rx_ring[rxring_idx].buffer_desc[i];
1310 if (!_rtl_pci_init_one_rxdesc(hw, (u8 *)entry, 1326 if (!_rtl_pci_init_one_rxdesc(hw, NULL, (u8 *)entry,
1311 rxring_idx, i)) 1327 rxring_idx, i))
1312 return -ENOMEM; 1328 return -ENOMEM;
1313 } 1329 }
@@ -1332,7 +1348,7 @@ static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw, int rxring_idx)
1332 1348
1333 for (i = 0; i < rtlpci->rxringcount; i++) { 1349 for (i = 0; i < rtlpci->rxringcount; i++) {
1334 entry = &rtlpci->rx_ring[rxring_idx].desc[i]; 1350 entry = &rtlpci->rx_ring[rxring_idx].desc[i];
1335 if (!_rtl_pci_init_one_rxdesc(hw, (u8 *)entry, 1351 if (!_rtl_pci_init_one_rxdesc(hw, NULL, (u8 *)entry,
1336 rxring_idx, i)) 1352 rxring_idx, i))
1337 return -ENOMEM; 1353 return -ENOMEM;
1338 } 1354 }
diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c
index efbaf2ae1999..794204e34fba 100644
--- a/drivers/net/xen-netback/xenbus.c
+++ b/drivers/net/xen-netback/xenbus.c
@@ -737,6 +737,7 @@ static void connect(struct backend_info *be)
737 } 737 }
738 738
739 queue->remaining_credit = credit_bytes; 739 queue->remaining_credit = credit_bytes;
740 queue->credit_usec = credit_usec;
740 741
741 err = connect_rings(be, queue); 742 err = connect_rings(be, queue);
742 if (err) { 743 if (err) {
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 22bcb4e12e2a..d8c10764f130 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -88,10 +88,8 @@ struct netfront_cb {
88#define IRQ_NAME_SIZE (QUEUE_NAME_SIZE + 3) 88#define IRQ_NAME_SIZE (QUEUE_NAME_SIZE + 3)
89 89
90struct netfront_stats { 90struct netfront_stats {
91 u64 rx_packets; 91 u64 packets;
92 u64 tx_packets; 92 u64 bytes;
93 u64 rx_bytes;
94 u64 tx_bytes;
95 struct u64_stats_sync syncp; 93 struct u64_stats_sync syncp;
96}; 94};
97 95
@@ -160,7 +158,8 @@ struct netfront_info {
160 struct netfront_queue *queues; 158 struct netfront_queue *queues;
161 159
162 /* Statistics */ 160 /* Statistics */
163 struct netfront_stats __percpu *stats; 161 struct netfront_stats __percpu *rx_stats;
162 struct netfront_stats __percpu *tx_stats;
164 163
165 atomic_t rx_gso_checksum_fixup; 164 atomic_t rx_gso_checksum_fixup;
166}; 165};
@@ -565,7 +564,7 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
565{ 564{
566 unsigned short id; 565 unsigned short id;
567 struct netfront_info *np = netdev_priv(dev); 566 struct netfront_info *np = netdev_priv(dev);
568 struct netfront_stats *stats = this_cpu_ptr(np->stats); 567 struct netfront_stats *tx_stats = this_cpu_ptr(np->tx_stats);
569 struct xen_netif_tx_request *tx; 568 struct xen_netif_tx_request *tx;
570 char *data = skb->data; 569 char *data = skb->data;
571 RING_IDX i; 570 RING_IDX i;
@@ -672,10 +671,10 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
672 if (notify) 671 if (notify)
673 notify_remote_via_irq(queue->tx_irq); 672 notify_remote_via_irq(queue->tx_irq);
674 673
675 u64_stats_update_begin(&stats->syncp); 674 u64_stats_update_begin(&tx_stats->syncp);
676 stats->tx_bytes += skb->len; 675 tx_stats->bytes += skb->len;
677 stats->tx_packets++; 676 tx_stats->packets++;
678 u64_stats_update_end(&stats->syncp); 677 u64_stats_update_end(&tx_stats->syncp);
679 678
680 /* Note: It is not safe to access skb after xennet_tx_buf_gc()! */ 679 /* Note: It is not safe to access skb after xennet_tx_buf_gc()! */
681 xennet_tx_buf_gc(queue); 680 xennet_tx_buf_gc(queue);
@@ -931,7 +930,7 @@ static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
931static int handle_incoming_queue(struct netfront_queue *queue, 930static int handle_incoming_queue(struct netfront_queue *queue,
932 struct sk_buff_head *rxq) 931 struct sk_buff_head *rxq)
933{ 932{
934 struct netfront_stats *stats = this_cpu_ptr(queue->info->stats); 933 struct netfront_stats *rx_stats = this_cpu_ptr(queue->info->rx_stats);
935 int packets_dropped = 0; 934 int packets_dropped = 0;
936 struct sk_buff *skb; 935 struct sk_buff *skb;
937 936
@@ -952,10 +951,10 @@ static int handle_incoming_queue(struct netfront_queue *queue,
952 continue; 951 continue;
953 } 952 }
954 953
955 u64_stats_update_begin(&stats->syncp); 954 u64_stats_update_begin(&rx_stats->syncp);
956 stats->rx_packets++; 955 rx_stats->packets++;
957 stats->rx_bytes += skb->len; 956 rx_stats->bytes += skb->len;
958 u64_stats_update_end(&stats->syncp); 957 u64_stats_update_end(&rx_stats->syncp);
959 958
960 /* Pass it up. */ 959 /* Pass it up. */
961 napi_gro_receive(&queue->napi, skb); 960 napi_gro_receive(&queue->napi, skb);
@@ -1079,18 +1078,22 @@ static struct rtnl_link_stats64 *xennet_get_stats64(struct net_device *dev,
1079 int cpu; 1078 int cpu;
1080 1079
1081 for_each_possible_cpu(cpu) { 1080 for_each_possible_cpu(cpu) {
1082 struct netfront_stats *stats = per_cpu_ptr(np->stats, cpu); 1081 struct netfront_stats *rx_stats = per_cpu_ptr(np->rx_stats, cpu);
1082 struct netfront_stats *tx_stats = per_cpu_ptr(np->tx_stats, cpu);
1083 u64 rx_packets, rx_bytes, tx_packets, tx_bytes; 1083 u64 rx_packets, rx_bytes, tx_packets, tx_bytes;
1084 unsigned int start; 1084 unsigned int start;
1085 1085
1086 do { 1086 do {
1087 start = u64_stats_fetch_begin_irq(&stats->syncp); 1087 start = u64_stats_fetch_begin_irq(&tx_stats->syncp);
1088 tx_packets = tx_stats->packets;
1089 tx_bytes = tx_stats->bytes;
1090 } while (u64_stats_fetch_retry_irq(&tx_stats->syncp, start));
1088 1091
1089 rx_packets = stats->rx_packets; 1092 do {
1090 tx_packets = stats->tx_packets; 1093 start = u64_stats_fetch_begin_irq(&rx_stats->syncp);
1091 rx_bytes = stats->rx_bytes; 1094 rx_packets = rx_stats->packets;
1092 tx_bytes = stats->tx_bytes; 1095 rx_bytes = rx_stats->bytes;
1093 } while (u64_stats_fetch_retry_irq(&stats->syncp, start)); 1096 } while (u64_stats_fetch_retry_irq(&rx_stats->syncp, start));
1094 1097
1095 tot->rx_packets += rx_packets; 1098 tot->rx_packets += rx_packets;
1096 tot->tx_packets += tx_packets; 1099 tot->tx_packets += tx_packets;
@@ -1275,6 +1278,15 @@ static const struct net_device_ops xennet_netdev_ops = {
1275#endif 1278#endif
1276}; 1279};
1277 1280
1281static void xennet_free_netdev(struct net_device *netdev)
1282{
1283 struct netfront_info *np = netdev_priv(netdev);
1284
1285 free_percpu(np->rx_stats);
1286 free_percpu(np->tx_stats);
1287 free_netdev(netdev);
1288}
1289
1278static struct net_device *xennet_create_dev(struct xenbus_device *dev) 1290static struct net_device *xennet_create_dev(struct xenbus_device *dev)
1279{ 1291{
1280 int err; 1292 int err;
@@ -1295,8 +1307,11 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev)
1295 np->queues = NULL; 1307 np->queues = NULL;
1296 1308
1297 err = -ENOMEM; 1309 err = -ENOMEM;
1298 np->stats = netdev_alloc_pcpu_stats(struct netfront_stats); 1310 np->rx_stats = netdev_alloc_pcpu_stats(struct netfront_stats);
1299 if (np->stats == NULL) 1311 if (np->rx_stats == NULL)
1312 goto exit;
1313 np->tx_stats = netdev_alloc_pcpu_stats(struct netfront_stats);
1314 if (np->tx_stats == NULL)
1300 goto exit; 1315 goto exit;
1301 1316
1302 netdev->netdev_ops = &xennet_netdev_ops; 1317 netdev->netdev_ops = &xennet_netdev_ops;
@@ -1327,7 +1342,7 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev)
1327 return netdev; 1342 return netdev;
1328 1343
1329 exit: 1344 exit:
1330 free_netdev(netdev); 1345 xennet_free_netdev(netdev);
1331 return ERR_PTR(err); 1346 return ERR_PTR(err);
1332} 1347}
1333 1348
@@ -1369,7 +1384,7 @@ static int netfront_probe(struct xenbus_device *dev,
1369 return 0; 1384 return 0;
1370 1385
1371 fail: 1386 fail:
1372 free_netdev(netdev); 1387 xennet_free_netdev(netdev);
1373 dev_set_drvdata(&dev->dev, NULL); 1388 dev_set_drvdata(&dev->dev, NULL);
1374 return err; 1389 return err;
1375} 1390}
@@ -2189,9 +2204,7 @@ static int xennet_remove(struct xenbus_device *dev)
2189 info->queues = NULL; 2204 info->queues = NULL;
2190 } 2205 }
2191 2206
2192 free_percpu(info->stats); 2207 xennet_free_netdev(info->netdev);
2193
2194 free_netdev(info->netdev);
2195 2208
2196 return 0; 2209 return 0;
2197} 2210}
diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c
index ba74f0aa60c7..3c22dbebc80f 100644
--- a/drivers/pinctrl/pinctrl-rockchip.c
+++ b/drivers/pinctrl/pinctrl-rockchip.c
@@ -89,6 +89,7 @@ struct rockchip_iomux {
89 * @reg_pull: optional separate register for additional pull settings 89 * @reg_pull: optional separate register for additional pull settings
90 * @clk: clock of the gpio bank 90 * @clk: clock of the gpio bank
91 * @irq: interrupt of the gpio bank 91 * @irq: interrupt of the gpio bank
92 * @saved_enables: Saved content of GPIO_INTEN at suspend time.
92 * @pin_base: first pin number 93 * @pin_base: first pin number
93 * @nr_pins: number of pins in this bank 94 * @nr_pins: number of pins in this bank
94 * @name: name of the bank 95 * @name: name of the bank
@@ -107,6 +108,7 @@ struct rockchip_pin_bank {
107 struct regmap *regmap_pull; 108 struct regmap *regmap_pull;
108 struct clk *clk; 109 struct clk *clk;
109 int irq; 110 int irq;
111 u32 saved_enables;
110 u32 pin_base; 112 u32 pin_base;
111 u8 nr_pins; 113 u8 nr_pins;
112 char *name; 114 char *name;
@@ -1543,6 +1545,51 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type)
1543 return 0; 1545 return 0;
1544} 1546}
1545 1547
1548static void rockchip_irq_suspend(struct irq_data *d)
1549{
1550 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
1551 struct rockchip_pin_bank *bank = gc->private;
1552
1553 bank->saved_enables = irq_reg_readl(gc, GPIO_INTEN);
1554 irq_reg_writel(gc, gc->wake_active, GPIO_INTEN);
1555}
1556
1557static void rockchip_irq_resume(struct irq_data *d)
1558{
1559 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
1560 struct rockchip_pin_bank *bank = gc->private;
1561
1562 irq_reg_writel(gc, bank->saved_enables, GPIO_INTEN);
1563}
1564
1565static void rockchip_irq_disable(struct irq_data *d)
1566{
1567 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
1568 u32 val;
1569
1570 irq_gc_lock(gc);
1571
1572 val = irq_reg_readl(gc, GPIO_INTEN);
1573 val &= ~d->mask;
1574 irq_reg_writel(gc, val, GPIO_INTEN);
1575
1576 irq_gc_unlock(gc);
1577}
1578
1579static void rockchip_irq_enable(struct irq_data *d)
1580{
1581 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
1582 u32 val;
1583
1584 irq_gc_lock(gc);
1585
1586 val = irq_reg_readl(gc, GPIO_INTEN);
1587 val |= d->mask;
1588 irq_reg_writel(gc, val, GPIO_INTEN);
1589
1590 irq_gc_unlock(gc);
1591}
1592
1546static int rockchip_interrupts_register(struct platform_device *pdev, 1593static int rockchip_interrupts_register(struct platform_device *pdev,
1547 struct rockchip_pinctrl *info) 1594 struct rockchip_pinctrl *info)
1548{ 1595{
@@ -1581,12 +1628,16 @@ static int rockchip_interrupts_register(struct platform_device *pdev,
1581 gc = irq_get_domain_generic_chip(bank->domain, 0); 1628 gc = irq_get_domain_generic_chip(bank->domain, 0);
1582 gc->reg_base = bank->reg_base; 1629 gc->reg_base = bank->reg_base;
1583 gc->private = bank; 1630 gc->private = bank;
1584 gc->chip_types[0].regs.mask = GPIO_INTEN; 1631 gc->chip_types[0].regs.mask = GPIO_INTMASK;
1585 gc->chip_types[0].regs.ack = GPIO_PORTS_EOI; 1632 gc->chip_types[0].regs.ack = GPIO_PORTS_EOI;
1586 gc->chip_types[0].chip.irq_ack = irq_gc_ack_set_bit; 1633 gc->chip_types[0].chip.irq_ack = irq_gc_ack_set_bit;
1587 gc->chip_types[0].chip.irq_mask = irq_gc_mask_clr_bit; 1634 gc->chip_types[0].chip.irq_mask = irq_gc_mask_set_bit;
1588 gc->chip_types[0].chip.irq_unmask = irq_gc_mask_set_bit; 1635 gc->chip_types[0].chip.irq_unmask = irq_gc_mask_clr_bit;
1636 gc->chip_types[0].chip.irq_enable = rockchip_irq_enable;
1637 gc->chip_types[0].chip.irq_disable = rockchip_irq_disable;
1589 gc->chip_types[0].chip.irq_set_wake = irq_gc_set_wake; 1638 gc->chip_types[0].chip.irq_set_wake = irq_gc_set_wake;
1639 gc->chip_types[0].chip.irq_suspend = rockchip_irq_suspend;
1640 gc->chip_types[0].chip.irq_resume = rockchip_irq_resume;
1590 gc->chip_types[0].chip.irq_set_type = rockchip_irq_set_type; 1641 gc->chip_types[0].chip.irq_set_type = rockchip_irq_set_type;
1591 gc->wake_enabled = IRQ_MSK(bank->nr_pins); 1642 gc->wake_enabled = IRQ_MSK(bank->nr_pins);
1592 1643
diff --git a/drivers/pinctrl/pinctrl-st.c b/drivers/pinctrl/pinctrl-st.c
index 7c9d51382248..9e5ec00084bb 100644
--- a/drivers/pinctrl/pinctrl-st.c
+++ b/drivers/pinctrl/pinctrl-st.c
@@ -1012,8 +1012,10 @@ static void st_pinconf_dbg_show(struct pinctrl_dev *pctldev,
1012 struct seq_file *s, unsigned pin_id) 1012 struct seq_file *s, unsigned pin_id)
1013{ 1013{
1014 unsigned long config; 1014 unsigned long config;
1015 st_pinconf_get(pctldev, pin_id, &config);
1016 1015
1016 mutex_unlock(&pctldev->mutex);
1017 st_pinconf_get(pctldev, pin_id, &config);
1018 mutex_lock(&pctldev->mutex);
1017 seq_printf(s, "[OE:%ld,PU:%ld,OD:%ld]\n" 1019 seq_printf(s, "[OE:%ld,PU:%ld,OD:%ld]\n"
1018 "\t\t[retime:%ld,invclk:%ld,clknotdat:%ld," 1020 "\t\t[retime:%ld,invclk:%ld,clknotdat:%ld,"
1019 "de:%ld,rt-clk:%ld,rt-delay:%ld]", 1021 "de:%ld,rt-clk:%ld,rt-delay:%ld]",
@@ -1443,6 +1445,7 @@ static struct gpio_chip st_gpio_template = {
1443 1445
1444static struct irq_chip st_gpio_irqchip = { 1446static struct irq_chip st_gpio_irqchip = {
1445 .name = "GPIO", 1447 .name = "GPIO",
1448 .irq_disable = st_gpio_irq_mask,
1446 .irq_mask = st_gpio_irq_mask, 1449 .irq_mask = st_gpio_irq_mask,
1447 .irq_unmask = st_gpio_irq_unmask, 1450 .irq_unmask = st_gpio_irq_unmask,
1448 .irq_set_type = st_gpio_irq_set_type, 1451 .irq_set_type = st_gpio_irq_set_type,
diff --git a/drivers/s390/crypto/ap_bus.c b/drivers/s390/crypto/ap_bus.c
index 91e97ec01418..4d41bf75c233 100644
--- a/drivers/s390/crypto/ap_bus.c
+++ b/drivers/s390/crypto/ap_bus.c
@@ -1163,9 +1163,13 @@ static inline int ap_test_config_card_id(unsigned int id)
1163 */ 1163 */
1164static inline int ap_test_config_domain(unsigned int domain) 1164static inline int ap_test_config_domain(unsigned int domain)
1165{ 1165{
1166 if (!ap_configuration) 1166 if (!ap_configuration) /* QCI not supported */
1167 return 1; 1167 if (domain < 16)
1168 return ap_test_config(ap_configuration->aqm, domain); 1168 return 1; /* then domains 0...15 are configured */
1169 else
1170 return 0;
1171 else
1172 return ap_test_config(ap_configuration->aqm, domain);
1169} 1173}
1170 1174
1171/** 1175/**
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 12ca291c1380..cce1cbc1a927 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -734,7 +734,9 @@ qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
734 * Return target busy if we've received a non-zero retry_delay_timer 734 * Return target busy if we've received a non-zero retry_delay_timer
735 * in a FCP_RSP. 735 * in a FCP_RSP.
736 */ 736 */
737 if (time_after(jiffies, fcport->retry_delay_timestamp)) 737 if (fcport->retry_delay_timestamp == 0) {
738 /* retry delay not set */
739 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
738 fcport->retry_delay_timestamp = 0; 740 fcport->retry_delay_timestamp = 0;
739 else 741 else
740 goto qc24_target_busy; 742 goto qc24_target_busy;
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index 55f6774f706f..aebde3289c50 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -2027,10 +2027,10 @@ iscsit_process_text_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
2027 goto reject; 2027 goto reject;
2028 } 2028 }
2029 if (!strncmp("=All", text_ptr, 4)) { 2029 if (!strncmp("=All", text_ptr, 4)) {
2030 cmd->cmd_flags |= IFC_SENDTARGETS_ALL; 2030 cmd->cmd_flags |= ICF_SENDTARGETS_ALL;
2031 } else if (!strncmp("=iqn.", text_ptr, 5) || 2031 } else if (!strncmp("=iqn.", text_ptr, 5) ||
2032 !strncmp("=eui.", text_ptr, 5)) { 2032 !strncmp("=eui.", text_ptr, 5)) {
2033 cmd->cmd_flags |= IFC_SENDTARGETS_SINGLE; 2033 cmd->cmd_flags |= ICF_SENDTARGETS_SINGLE;
2034 } else { 2034 } else {
2035 pr_err("Unable to locate valid SendTargets=%s value\n", text_ptr); 2035 pr_err("Unable to locate valid SendTargets=%s value\n", text_ptr);
2036 goto reject; 2036 goto reject;
@@ -3415,10 +3415,10 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd,
3415 return -ENOMEM; 3415 return -ENOMEM;
3416 } 3416 }
3417 /* 3417 /*
3418 * Locate pointer to iqn./eui. string for IFC_SENDTARGETS_SINGLE 3418 * Locate pointer to iqn./eui. string for ICF_SENDTARGETS_SINGLE
3419 * explicit case.. 3419 * explicit case..
3420 */ 3420 */
3421 if (cmd->cmd_flags & IFC_SENDTARGETS_SINGLE) { 3421 if (cmd->cmd_flags & ICF_SENDTARGETS_SINGLE) {
3422 text_ptr = strchr(text_in, '='); 3422 text_ptr = strchr(text_in, '=');
3423 if (!text_ptr) { 3423 if (!text_ptr) {
3424 pr_err("Unable to locate '=' string in text_in:" 3424 pr_err("Unable to locate '=' string in text_in:"
@@ -3434,7 +3434,7 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd,
3434 3434
3435 spin_lock(&tiqn_lock); 3435 spin_lock(&tiqn_lock);
3436 list_for_each_entry(tiqn, &g_tiqn_list, tiqn_list) { 3436 list_for_each_entry(tiqn, &g_tiqn_list, tiqn_list) {
3437 if ((cmd->cmd_flags & IFC_SENDTARGETS_SINGLE) && 3437 if ((cmd->cmd_flags & ICF_SENDTARGETS_SINGLE) &&
3438 strcmp(tiqn->tiqn, text_ptr)) { 3438 strcmp(tiqn->tiqn, text_ptr)) {
3439 continue; 3439 continue;
3440 } 3440 }
@@ -3512,7 +3512,7 @@ eob:
3512 if (end_of_buf) 3512 if (end_of_buf)
3513 break; 3513 break;
3514 3514
3515 if (cmd->cmd_flags & IFC_SENDTARGETS_SINGLE) 3515 if (cmd->cmd_flags & ICF_SENDTARGETS_SINGLE)
3516 break; 3516 break;
3517 } 3517 }
3518 spin_unlock(&tiqn_lock); 3518 spin_unlock(&tiqn_lock);
diff --git a/drivers/target/iscsi/iscsi_target_core.h b/drivers/target/iscsi/iscsi_target_core.h
index 09a522bae222..cbcff38ac9b7 100644
--- a/drivers/target/iscsi/iscsi_target_core.h
+++ b/drivers/target/iscsi/iscsi_target_core.h
@@ -135,8 +135,8 @@ enum cmd_flags_table {
135 ICF_CONTIG_MEMORY = 0x00000020, 135 ICF_CONTIG_MEMORY = 0x00000020,
136 ICF_ATTACHED_TO_RQUEUE = 0x00000040, 136 ICF_ATTACHED_TO_RQUEUE = 0x00000040,
137 ICF_OOO_CMDSN = 0x00000080, 137 ICF_OOO_CMDSN = 0x00000080,
138 IFC_SENDTARGETS_ALL = 0x00000100, 138 ICF_SENDTARGETS_ALL = 0x00000100,
139 IFC_SENDTARGETS_SINGLE = 0x00000200, 139 ICF_SENDTARGETS_SINGLE = 0x00000200,
140}; 140};
141 141
142/* struct iscsi_cmd->i_state */ 142/* struct iscsi_cmd->i_state */
diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
index 7653cfb027a2..58f49ff69b14 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -1103,51 +1103,6 @@ int se_dev_set_queue_depth(struct se_device *dev, u32 queue_depth)
1103} 1103}
1104EXPORT_SYMBOL(se_dev_set_queue_depth); 1104EXPORT_SYMBOL(se_dev_set_queue_depth);
1105 1105
1106int se_dev_set_fabric_max_sectors(struct se_device *dev, u32 fabric_max_sectors)
1107{
1108 int block_size = dev->dev_attrib.block_size;
1109
1110 if (dev->export_count) {
1111 pr_err("dev[%p]: Unable to change SE Device"
1112 " fabric_max_sectors while export_count is %d\n",
1113 dev, dev->export_count);
1114 return -EINVAL;
1115 }
1116 if (!fabric_max_sectors) {
1117 pr_err("dev[%p]: Illegal ZERO value for"
1118 " fabric_max_sectors\n", dev);
1119 return -EINVAL;
1120 }
1121 if (fabric_max_sectors < DA_STATUS_MAX_SECTORS_MIN) {
1122 pr_err("dev[%p]: Passed fabric_max_sectors: %u less than"
1123 " DA_STATUS_MAX_SECTORS_MIN: %u\n", dev, fabric_max_sectors,
1124 DA_STATUS_MAX_SECTORS_MIN);
1125 return -EINVAL;
1126 }
1127 if (fabric_max_sectors > DA_STATUS_MAX_SECTORS_MAX) {
1128 pr_err("dev[%p]: Passed fabric_max_sectors: %u"
1129 " greater than DA_STATUS_MAX_SECTORS_MAX:"
1130 " %u\n", dev, fabric_max_sectors,
1131 DA_STATUS_MAX_SECTORS_MAX);
1132 return -EINVAL;
1133 }
1134 /*
1135 * Align max_sectors down to PAGE_SIZE to follow transport_allocate_data_tasks()
1136 */
1137 if (!block_size) {
1138 block_size = 512;
1139 pr_warn("Defaulting to 512 for zero block_size\n");
1140 }
1141 fabric_max_sectors = se_dev_align_max_sectors(fabric_max_sectors,
1142 block_size);
1143
1144 dev->dev_attrib.fabric_max_sectors = fabric_max_sectors;
1145 pr_debug("dev[%p]: SE Device max_sectors changed to %u\n",
1146 dev, fabric_max_sectors);
1147 return 0;
1148}
1149EXPORT_SYMBOL(se_dev_set_fabric_max_sectors);
1150
1151int se_dev_set_optimal_sectors(struct se_device *dev, u32 optimal_sectors) 1106int se_dev_set_optimal_sectors(struct se_device *dev, u32 optimal_sectors)
1152{ 1107{
1153 if (dev->export_count) { 1108 if (dev->export_count) {
@@ -1156,10 +1111,10 @@ int se_dev_set_optimal_sectors(struct se_device *dev, u32 optimal_sectors)
1156 dev, dev->export_count); 1111 dev, dev->export_count);
1157 return -EINVAL; 1112 return -EINVAL;
1158 } 1113 }
1159 if (optimal_sectors > dev->dev_attrib.fabric_max_sectors) { 1114 if (optimal_sectors > dev->dev_attrib.hw_max_sectors) {
1160 pr_err("dev[%p]: Passed optimal_sectors %u cannot be" 1115 pr_err("dev[%p]: Passed optimal_sectors %u cannot be"
1161 " greater than fabric_max_sectors: %u\n", dev, 1116 " greater than hw_max_sectors: %u\n", dev,
1162 optimal_sectors, dev->dev_attrib.fabric_max_sectors); 1117 optimal_sectors, dev->dev_attrib.hw_max_sectors);
1163 return -EINVAL; 1118 return -EINVAL;
1164 } 1119 }
1165 1120
@@ -1553,8 +1508,6 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
1553 dev->dev_attrib.unmap_granularity_alignment = 1508 dev->dev_attrib.unmap_granularity_alignment =
1554 DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT; 1509 DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT;
1555 dev->dev_attrib.max_write_same_len = DA_MAX_WRITE_SAME_LEN; 1510 dev->dev_attrib.max_write_same_len = DA_MAX_WRITE_SAME_LEN;
1556 dev->dev_attrib.fabric_max_sectors = DA_FABRIC_MAX_SECTORS;
1557 dev->dev_attrib.optimal_sectors = DA_FABRIC_MAX_SECTORS;
1558 1511
1559 xcopy_lun = &dev->xcopy_lun; 1512 xcopy_lun = &dev->xcopy_lun;
1560 xcopy_lun->lun_se_dev = dev; 1513 xcopy_lun->lun_se_dev = dev;
@@ -1595,6 +1548,7 @@ int target_configure_device(struct se_device *dev)
1595 dev->dev_attrib.hw_max_sectors = 1548 dev->dev_attrib.hw_max_sectors =
1596 se_dev_align_max_sectors(dev->dev_attrib.hw_max_sectors, 1549 se_dev_align_max_sectors(dev->dev_attrib.hw_max_sectors,
1597 dev->dev_attrib.hw_block_size); 1550 dev->dev_attrib.hw_block_size);
1551 dev->dev_attrib.optimal_sectors = dev->dev_attrib.hw_max_sectors;
1598 1552
1599 dev->dev_index = scsi_get_new_index(SCSI_DEVICE_INDEX); 1553 dev->dev_index = scsi_get_new_index(SCSI_DEVICE_INDEX);
1600 dev->creation_time = get_jiffies_64(); 1554 dev->creation_time = get_jiffies_64();
diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c
index c2aea099ea4a..d836de200a03 100644
--- a/drivers/target/target_core_file.c
+++ b/drivers/target/target_core_file.c
@@ -621,7 +621,16 @@ fd_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
621 struct fd_prot fd_prot; 621 struct fd_prot fd_prot;
622 sense_reason_t rc; 622 sense_reason_t rc;
623 int ret = 0; 623 int ret = 0;
624 624 /*
625 * We are currently limited by the number of iovecs (2048) per
626 * single vfs_[writev,readv] call.
627 */
628 if (cmd->data_length > FD_MAX_BYTES) {
629 pr_err("FILEIO: Not able to process I/O of %u bytes due to"
630 "FD_MAX_BYTES: %u iovec count limitiation\n",
631 cmd->data_length, FD_MAX_BYTES);
632 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
633 }
625 /* 634 /*
626 * Call vectorized fileio functions to map struct scatterlist 635 * Call vectorized fileio functions to map struct scatterlist
627 * physical memory addresses to struct iovec virtual memory. 636 * physical memory addresses to struct iovec virtual memory.
@@ -959,7 +968,6 @@ static struct configfs_attribute *fileio_backend_dev_attrs[] = {
959 &fileio_dev_attrib_hw_block_size.attr, 968 &fileio_dev_attrib_hw_block_size.attr,
960 &fileio_dev_attrib_block_size.attr, 969 &fileio_dev_attrib_block_size.attr,
961 &fileio_dev_attrib_hw_max_sectors.attr, 970 &fileio_dev_attrib_hw_max_sectors.attr,
962 &fileio_dev_attrib_fabric_max_sectors.attr,
963 &fileio_dev_attrib_optimal_sectors.attr, 971 &fileio_dev_attrib_optimal_sectors.attr,
964 &fileio_dev_attrib_hw_queue_depth.attr, 972 &fileio_dev_attrib_hw_queue_depth.attr,
965 &fileio_dev_attrib_queue_depth.attr, 973 &fileio_dev_attrib_queue_depth.attr,
diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c
index 3efff94fbd97..78346b850968 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -124,7 +124,7 @@ static int iblock_configure_device(struct se_device *dev)
124 q = bdev_get_queue(bd); 124 q = bdev_get_queue(bd);
125 125
126 dev->dev_attrib.hw_block_size = bdev_logical_block_size(bd); 126 dev->dev_attrib.hw_block_size = bdev_logical_block_size(bd);
127 dev->dev_attrib.hw_max_sectors = UINT_MAX; 127 dev->dev_attrib.hw_max_sectors = queue_max_hw_sectors(q);
128 dev->dev_attrib.hw_queue_depth = q->nr_requests; 128 dev->dev_attrib.hw_queue_depth = q->nr_requests;
129 129
130 /* 130 /*
@@ -883,7 +883,6 @@ static struct configfs_attribute *iblock_backend_dev_attrs[] = {
883 &iblock_dev_attrib_hw_block_size.attr, 883 &iblock_dev_attrib_hw_block_size.attr,
884 &iblock_dev_attrib_block_size.attr, 884 &iblock_dev_attrib_block_size.attr,
885 &iblock_dev_attrib_hw_max_sectors.attr, 885 &iblock_dev_attrib_hw_max_sectors.attr,
886 &iblock_dev_attrib_fabric_max_sectors.attr,
887 &iblock_dev_attrib_optimal_sectors.attr, 886 &iblock_dev_attrib_optimal_sectors.attr,
888 &iblock_dev_attrib_hw_queue_depth.attr, 887 &iblock_dev_attrib_hw_queue_depth.attr,
889 &iblock_dev_attrib_queue_depth.attr, 888 &iblock_dev_attrib_queue_depth.attr,
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index d56f2aaba9af..283cf786ef98 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -528,6 +528,18 @@ static int core_scsi3_pr_seq_non_holder(
528 528
529 return 0; 529 return 0;
530 } 530 }
531 } else if (we && registered_nexus) {
532 /*
533 * Reads are allowed for Write Exclusive locks
534 * from all registrants.
535 */
536 if (cmd->data_direction == DMA_FROM_DEVICE) {
537 pr_debug("Allowing READ CDB: 0x%02x for %s"
538 " reservation\n", cdb[0],
539 core_scsi3_pr_dump_type(pr_reg_type));
540
541 return 0;
542 }
531 } 543 }
532 pr_debug("%s Conflict for %sregistered nexus %s CDB: 0x%2x" 544 pr_debug("%s Conflict for %sregistered nexus %s CDB: 0x%2x"
533 " for %s reservation\n", transport_dump_cmd_direction(cmd), 545 " for %s reservation\n", transport_dump_cmd_direction(cmd),
diff --git a/drivers/target/target_core_rd.c b/drivers/target/target_core_rd.c
index 60ebd170a561..98e83ac5661b 100644
--- a/drivers/target/target_core_rd.c
+++ b/drivers/target/target_core_rd.c
@@ -657,7 +657,6 @@ static struct configfs_attribute *rd_mcp_backend_dev_attrs[] = {
657 &rd_mcp_dev_attrib_hw_block_size.attr, 657 &rd_mcp_dev_attrib_hw_block_size.attr,
658 &rd_mcp_dev_attrib_block_size.attr, 658 &rd_mcp_dev_attrib_block_size.attr,
659 &rd_mcp_dev_attrib_hw_max_sectors.attr, 659 &rd_mcp_dev_attrib_hw_max_sectors.attr,
660 &rd_mcp_dev_attrib_fabric_max_sectors.attr,
661 &rd_mcp_dev_attrib_optimal_sectors.attr, 660 &rd_mcp_dev_attrib_optimal_sectors.attr,
662 &rd_mcp_dev_attrib_hw_queue_depth.attr, 661 &rd_mcp_dev_attrib_hw_queue_depth.attr,
663 &rd_mcp_dev_attrib_queue_depth.attr, 662 &rd_mcp_dev_attrib_queue_depth.attr,
diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index 11bea1952435..cd4bed7b2757 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -953,21 +953,6 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops)
953 953
954 if (cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) { 954 if (cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) {
955 unsigned long long end_lba; 955 unsigned long long end_lba;
956
957 if (sectors > dev->dev_attrib.fabric_max_sectors) {
958 printk_ratelimited(KERN_ERR "SCSI OP %02xh with too"
959 " big sectors %u exceeds fabric_max_sectors:"
960 " %u\n", cdb[0], sectors,
961 dev->dev_attrib.fabric_max_sectors);
962 return TCM_INVALID_CDB_FIELD;
963 }
964 if (sectors > dev->dev_attrib.hw_max_sectors) {
965 printk_ratelimited(KERN_ERR "SCSI OP %02xh with too"
966 " big sectors %u exceeds backend hw_max_sectors:"
967 " %u\n", cdb[0], sectors,
968 dev->dev_attrib.hw_max_sectors);
969 return TCM_INVALID_CDB_FIELD;
970 }
971check_lba: 956check_lba:
972 end_lba = dev->transport->get_blocks(dev) + 1; 957 end_lba = dev->transport->get_blocks(dev) + 1;
973 if (cmd->t_task_lba + sectors > end_lba) { 958 if (cmd->t_task_lba + sectors > end_lba) {
diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c
index 1307600fe726..4c71657da56a 100644
--- a/drivers/target/target_core_spc.c
+++ b/drivers/target/target_core_spc.c
@@ -505,7 +505,6 @@ static sense_reason_t
505spc_emulate_evpd_b0(struct se_cmd *cmd, unsigned char *buf) 505spc_emulate_evpd_b0(struct se_cmd *cmd, unsigned char *buf)
506{ 506{
507 struct se_device *dev = cmd->se_dev; 507 struct se_device *dev = cmd->se_dev;
508 u32 max_sectors;
509 int have_tp = 0; 508 int have_tp = 0;
510 int opt, min; 509 int opt, min;
511 510
@@ -539,9 +538,7 @@ spc_emulate_evpd_b0(struct se_cmd *cmd, unsigned char *buf)
539 /* 538 /*
540 * Set MAXIMUM TRANSFER LENGTH 539 * Set MAXIMUM TRANSFER LENGTH
541 */ 540 */
542 max_sectors = min(dev->dev_attrib.fabric_max_sectors, 541 put_unaligned_be32(dev->dev_attrib.hw_max_sectors, &buf[8]);
543 dev->dev_attrib.hw_max_sectors);
544 put_unaligned_be32(max_sectors, &buf[8]);
545 542
546 /* 543 /*
547 * Set OPTIMAL TRANSFER LENGTH 544 * Set OPTIMAL TRANSFER LENGTH
diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
index 8bfa61c9693d..1157b559683b 100644
--- a/drivers/target/target_core_user.c
+++ b/drivers/target/target_core_user.c
@@ -1118,7 +1118,6 @@ static struct configfs_attribute *tcmu_backend_dev_attrs[] = {
1118 &tcmu_dev_attrib_hw_block_size.attr, 1118 &tcmu_dev_attrib_hw_block_size.attr,
1119 &tcmu_dev_attrib_block_size.attr, 1119 &tcmu_dev_attrib_block_size.attr,
1120 &tcmu_dev_attrib_hw_max_sectors.attr, 1120 &tcmu_dev_attrib_hw_max_sectors.attr,
1121 &tcmu_dev_attrib_fabric_max_sectors.attr,
1122 &tcmu_dev_attrib_optimal_sectors.attr, 1121 &tcmu_dev_attrib_optimal_sectors.attr,
1123 &tcmu_dev_attrib_hw_queue_depth.attr, 1122 &tcmu_dev_attrib_hw_queue_depth.attr,
1124 &tcmu_dev_attrib_queue_depth.attr, 1123 &tcmu_dev_attrib_queue_depth.attr,
diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
index c1188ac053c9..2ccbc0788353 100644
--- a/drivers/thermal/imx_thermal.c
+++ b/drivers/thermal/imx_thermal.c
@@ -608,6 +608,7 @@ static int imx_thermal_suspend(struct device *dev)
608 regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_MEASURE_TEMP); 608 regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_MEASURE_TEMP);
609 regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_POWER_DOWN); 609 regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_POWER_DOWN);
610 data->mode = THERMAL_DEVICE_DISABLED; 610 data->mode = THERMAL_DEVICE_DISABLED;
611 clk_disable_unprepare(data->thermal_clk);
611 612
612 return 0; 613 return 0;
613} 614}
@@ -617,6 +618,7 @@ static int imx_thermal_resume(struct device *dev)
617 struct imx_thermal_data *data = dev_get_drvdata(dev); 618 struct imx_thermal_data *data = dev_get_drvdata(dev);
618 struct regmap *map = data->tempmon; 619 struct regmap *map = data->tempmon;
619 620
621 clk_prepare_enable(data->thermal_clk);
620 /* Enabled thermal sensor after resume */ 622 /* Enabled thermal sensor after resume */
621 regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN); 623 regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN);
622 regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP); 624 regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP);
diff --git a/drivers/thermal/int340x_thermal/acpi_thermal_rel.c b/drivers/thermal/int340x_thermal/acpi_thermal_rel.c
index 231cabc16e16..2c2ec7666eb1 100644
--- a/drivers/thermal/int340x_thermal/acpi_thermal_rel.c
+++ b/drivers/thermal/int340x_thermal/acpi_thermal_rel.c
@@ -119,15 +119,11 @@ int acpi_parse_trt(acpi_handle handle, int *trt_count, struct trt **trtp,
119 continue; 119 continue;
120 120
121 result = acpi_bus_get_device(trt->source, &adev); 121 result = acpi_bus_get_device(trt->source, &adev);
122 if (!result) 122 if (result)
123 acpi_create_platform_device(adev);
124 else
125 pr_warn("Failed to get source ACPI device\n"); 123 pr_warn("Failed to get source ACPI device\n");
126 124
127 result = acpi_bus_get_device(trt->target, &adev); 125 result = acpi_bus_get_device(trt->target, &adev);
128 if (!result) 126 if (result)
129 acpi_create_platform_device(adev);
130 else
131 pr_warn("Failed to get target ACPI device\n"); 127 pr_warn("Failed to get target ACPI device\n");
132 } 128 }
133 129
@@ -206,16 +202,12 @@ int acpi_parse_art(acpi_handle handle, int *art_count, struct art **artp,
206 202
207 if (art->source) { 203 if (art->source) {
208 result = acpi_bus_get_device(art->source, &adev); 204 result = acpi_bus_get_device(art->source, &adev);
209 if (!result) 205 if (result)
210 acpi_create_platform_device(adev);
211 else
212 pr_warn("Failed to get source ACPI device\n"); 206 pr_warn("Failed to get source ACPI device\n");
213 } 207 }
214 if (art->target) { 208 if (art->target) {
215 result = acpi_bus_get_device(art->target, &adev); 209 result = acpi_bus_get_device(art->target, &adev);
216 if (!result) 210 if (result)
217 acpi_create_platform_device(adev);
218 else
219 pr_warn("Failed to get source ACPI device\n"); 211 pr_warn("Failed to get source ACPI device\n");
220 } 212 }
221 } 213 }
diff --git a/drivers/thermal/int340x_thermal/processor_thermal_device.c b/drivers/thermal/int340x_thermal/processor_thermal_device.c
index 31bb553aac26..0fe5dbbea968 100644
--- a/drivers/thermal/int340x_thermal/processor_thermal_device.c
+++ b/drivers/thermal/int340x_thermal/processor_thermal_device.c
@@ -130,6 +130,8 @@ static int proc_thermal_add(struct device *dev,
130 int ret; 130 int ret;
131 131
132 adev = ACPI_COMPANION(dev); 132 adev = ACPI_COMPANION(dev);
133 if (!adev)
134 return -ENODEV;
133 135
134 status = acpi_evaluate_object(adev->handle, "PPCC", NULL, &buf); 136 status = acpi_evaluate_object(adev->handle, "PPCC", NULL, &buf);
135 if (ACPI_FAILURE(status)) 137 if (ACPI_FAILURE(status))
diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
index e145b66df444..d717f3dab6f1 100644
--- a/drivers/thermal/of-thermal.c
+++ b/drivers/thermal/of-thermal.c
@@ -149,7 +149,7 @@ EXPORT_SYMBOL_GPL(of_thermal_is_trip_valid);
149 * 149 *
150 * Return: pointer to trip points table, NULL otherwise 150 * Return: pointer to trip points table, NULL otherwise
151 */ 151 */
152const struct thermal_trip * const 152const struct thermal_trip *
153of_thermal_get_trip_points(struct thermal_zone_device *tz) 153of_thermal_get_trip_points(struct thermal_zone_device *tz)
154{ 154{
155 struct __thermal_zone *data = tz->devdata; 155 struct __thermal_zone *data = tz->devdata;
diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c
index 8803e693fe68..2580a4872f90 100644
--- a/drivers/thermal/rcar_thermal.c
+++ b/drivers/thermal/rcar_thermal.c
@@ -63,7 +63,7 @@ struct rcar_thermal_priv {
63 struct mutex lock; 63 struct mutex lock;
64 struct list_head list; 64 struct list_head list;
65 int id; 65 int id;
66 int ctemp; 66 u32 ctemp;
67}; 67};
68 68
69#define rcar_thermal_for_each_priv(pos, common) \ 69#define rcar_thermal_for_each_priv(pos, common) \
@@ -145,7 +145,7 @@ static int rcar_thermal_update_temp(struct rcar_thermal_priv *priv)
145{ 145{
146 struct device *dev = rcar_priv_to_dev(priv); 146 struct device *dev = rcar_priv_to_dev(priv);
147 int i; 147 int i;
148 int ctemp, old, new; 148 u32 ctemp, old, new;
149 int ret = -EINVAL; 149 int ret = -EINVAL;
150 150
151 mutex_lock(&priv->lock); 151 mutex_lock(&priv->lock);
@@ -372,6 +372,7 @@ static int rcar_thermal_probe(struct platform_device *pdev)
372 int i; 372 int i;
373 int ret = -ENODEV; 373 int ret = -ENODEV;
374 int idle = IDLE_INTERVAL; 374 int idle = IDLE_INTERVAL;
375 u32 enr_bits = 0;
375 376
376 common = devm_kzalloc(dev, sizeof(*common), GFP_KERNEL); 377 common = devm_kzalloc(dev, sizeof(*common), GFP_KERNEL);
377 if (!common) 378 if (!common)
@@ -390,7 +391,7 @@ static int rcar_thermal_probe(struct platform_device *pdev)
390 391
391 /* 392 /*
392 * platform has IRQ support. 393 * platform has IRQ support.
393 * Then, drier use common register 394 * Then, driver uses common registers
394 */ 395 */
395 396
396 ret = devm_request_irq(dev, irq->start, rcar_thermal_irq, 0, 397 ret = devm_request_irq(dev, irq->start, rcar_thermal_irq, 0,
@@ -408,9 +409,6 @@ static int rcar_thermal_probe(struct platform_device *pdev)
408 if (IS_ERR(common->base)) 409 if (IS_ERR(common->base))
409 return PTR_ERR(common->base); 410 return PTR_ERR(common->base);
410 411
411 /* enable temperature comparation */
412 rcar_thermal_common_write(common, ENR, 0x00030303);
413
414 idle = 0; /* polling delay is not needed */ 412 idle = 0; /* polling delay is not needed */
415 } 413 }
416 414
@@ -452,8 +450,15 @@ static int rcar_thermal_probe(struct platform_device *pdev)
452 rcar_thermal_irq_enable(priv); 450 rcar_thermal_irq_enable(priv);
453 451
454 list_move_tail(&priv->list, &common->head); 452 list_move_tail(&priv->list, &common->head);
453
454 /* update ENR bits */
455 enr_bits |= 3 << (i * 8);
455 } 456 }
456 457
458 /* enable temperature comparation */
459 if (irq)
460 rcar_thermal_common_write(common, ENR, enr_bits);
461
457 platform_set_drvdata(pdev, common); 462 platform_set_drvdata(pdev, common);
458 463
459 dev_info(dev, "%d sensor probed\n", i); 464 dev_info(dev, "%d sensor probed\n", i);
diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h
index 9083e7520623..0531c752fbbb 100644
--- a/drivers/thermal/thermal_core.h
+++ b/drivers/thermal/thermal_core.h
@@ -91,7 +91,7 @@ int of_parse_thermal_zones(void);
91void of_thermal_destroy_zones(void); 91void of_thermal_destroy_zones(void);
92int of_thermal_get_ntrips(struct thermal_zone_device *); 92int of_thermal_get_ntrips(struct thermal_zone_device *);
93bool of_thermal_is_trip_valid(struct thermal_zone_device *, int); 93bool of_thermal_is_trip_valid(struct thermal_zone_device *, int);
94const struct thermal_trip * const 94const struct thermal_trip *
95of_thermal_get_trip_points(struct thermal_zone_device *); 95of_thermal_get_trip_points(struct thermal_zone_device *);
96#else 96#else
97static inline int of_parse_thermal_zones(void) { return 0; } 97static inline int of_parse_thermal_zones(void) { return 0; }
@@ -105,7 +105,7 @@ static inline bool of_thermal_is_trip_valid(struct thermal_zone_device *tz,
105{ 105{
106 return 0; 106 return 0;
107} 107}
108static inline const struct thermal_trip * const 108static inline const struct thermal_trip *
109of_thermal_get_trip_points(struct thermal_zone_device *tz) 109of_thermal_get_trip_points(struct thermal_zone_device *tz)
110{ 110{
111 return NULL; 111 return NULL;
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index 255201f22126..7cc0122a18ce 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -840,13 +840,11 @@ static const struct vfio_device_ops vfio_pci_ops = {
840 840
841static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) 841static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
842{ 842{
843 u8 type;
844 struct vfio_pci_device *vdev; 843 struct vfio_pci_device *vdev;
845 struct iommu_group *group; 844 struct iommu_group *group;
846 int ret; 845 int ret;
847 846
848 pci_read_config_byte(pdev, PCI_HEADER_TYPE, &type); 847 if (pdev->hdr_type != PCI_HEADER_TYPE_NORMAL)
849 if ((type & PCI_HEADER_TYPE) != PCI_HEADER_TYPE_NORMAL)
850 return -EINVAL; 848 return -EINVAL;
851 849
852 group = iommu_group_get(&pdev->dev); 850 group = iommu_group_get(&pdev->dev);
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 14419a8ccbb6..d415d69dc237 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -538,7 +538,7 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
538 ++headcount; 538 ++headcount;
539 seg += in; 539 seg += in;
540 } 540 }
541 heads[headcount - 1].len = cpu_to_vhost32(vq, len - datalen); 541 heads[headcount - 1].len = cpu_to_vhost32(vq, len + datalen);
542 *iovcount = seg; 542 *iovcount = seg;
543 if (unlikely(log)) 543 if (unlikely(log))
544 *log_num = nlogs; 544 *log_num = nlogs;
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 01c01cb3933f..d695b1673ae5 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -911,6 +911,23 @@ vhost_scsi_map_iov_to_prot(struct tcm_vhost_cmd *cmd,
911 return 0; 911 return 0;
912} 912}
913 913
914static int vhost_scsi_to_tcm_attr(int attr)
915{
916 switch (attr) {
917 case VIRTIO_SCSI_S_SIMPLE:
918 return TCM_SIMPLE_TAG;
919 case VIRTIO_SCSI_S_ORDERED:
920 return TCM_ORDERED_TAG;
921 case VIRTIO_SCSI_S_HEAD:
922 return TCM_HEAD_TAG;
923 case VIRTIO_SCSI_S_ACA:
924 return TCM_ACA_TAG;
925 default:
926 break;
927 }
928 return TCM_SIMPLE_TAG;
929}
930
914static void tcm_vhost_submission_work(struct work_struct *work) 931static void tcm_vhost_submission_work(struct work_struct *work)
915{ 932{
916 struct tcm_vhost_cmd *cmd = 933 struct tcm_vhost_cmd *cmd =
@@ -936,9 +953,10 @@ static void tcm_vhost_submission_work(struct work_struct *work)
936 rc = target_submit_cmd_map_sgls(se_cmd, tv_nexus->tvn_se_sess, 953 rc = target_submit_cmd_map_sgls(se_cmd, tv_nexus->tvn_se_sess,
937 cmd->tvc_cdb, &cmd->tvc_sense_buf[0], 954 cmd->tvc_cdb, &cmd->tvc_sense_buf[0],
938 cmd->tvc_lun, cmd->tvc_exp_data_len, 955 cmd->tvc_lun, cmd->tvc_exp_data_len,
939 cmd->tvc_task_attr, cmd->tvc_data_direction, 956 vhost_scsi_to_tcm_attr(cmd->tvc_task_attr),
940 TARGET_SCF_ACK_KREF, sg_ptr, cmd->tvc_sgl_count, 957 cmd->tvc_data_direction, TARGET_SCF_ACK_KREF,
941 NULL, 0, sg_prot_ptr, cmd->tvc_prot_sgl_count); 958 sg_ptr, cmd->tvc_sgl_count, NULL, 0, sg_prot_ptr,
959 cmd->tvc_prot_sgl_count);
942 if (rc < 0) { 960 if (rc < 0) {
943 transport_send_check_condition_and_sense(se_cmd, 961 transport_send_check_condition_and_sense(se_cmd,
944 TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE, 0); 962 TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE, 0);
diff --git a/drivers/video/fbdev/broadsheetfb.c b/drivers/video/fbdev/broadsheetfb.c
index 1c29bd19e3d5..0e5fde1d3ffb 100644
--- a/drivers/video/fbdev/broadsheetfb.c
+++ b/drivers/video/fbdev/broadsheetfb.c
@@ -636,7 +636,7 @@ static int broadsheet_spiflash_rewrite_sector(struct broadsheetfb_par *par,
636 err = broadsheet_spiflash_read_range(par, start_sector_addr, 636 err = broadsheet_spiflash_read_range(par, start_sector_addr,
637 data_start_addr, sector_buffer); 637 data_start_addr, sector_buffer);
638 if (err) 638 if (err)
639 return err; 639 goto out;
640 } 640 }
641 641
642 /* now we copy our data into the right place in the sector buffer */ 642 /* now we copy our data into the right place in the sector buffer */
@@ -657,7 +657,7 @@ static int broadsheet_spiflash_rewrite_sector(struct broadsheetfb_par *par,
657 err = broadsheet_spiflash_read_range(par, tail_start_addr, 657 err = broadsheet_spiflash_read_range(par, tail_start_addr,
658 tail_len, sector_buffer + tail_start_addr); 658 tail_len, sector_buffer + tail_start_addr);
659 if (err) 659 if (err)
660 return err; 660 goto out;
661 } 661 }
662 662
663 /* if we got here we have the full sector that we want to rewrite. */ 663 /* if we got here we have the full sector that we want to rewrite. */
@@ -665,11 +665,13 @@ static int broadsheet_spiflash_rewrite_sector(struct broadsheetfb_par *par,
665 /* first erase the sector */ 665 /* first erase the sector */
666 err = broadsheet_spiflash_erase_sector(par, start_sector_addr); 666 err = broadsheet_spiflash_erase_sector(par, start_sector_addr);
667 if (err) 667 if (err)
668 return err; 668 goto out;
669 669
670 /* now write it */ 670 /* now write it */
671 err = broadsheet_spiflash_write_sector(par, start_sector_addr, 671 err = broadsheet_spiflash_write_sector(par, start_sector_addr,
672 sector_buffer, sector_size); 672 sector_buffer, sector_size);
673out:
674 kfree(sector_buffer);
673 return err; 675 return err;
674} 676}
675 677
diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c
index 92cac803dee3..1085c0432158 100644
--- a/drivers/video/fbdev/simplefb.c
+++ b/drivers/video/fbdev/simplefb.c
@@ -402,7 +402,7 @@ static int __init simplefb_init(void)
402 if (ret) 402 if (ret)
403 return ret; 403 return ret;
404 404
405 if (IS_ENABLED(CONFIG_OF) && of_chosen) { 405 if (IS_ENABLED(CONFIG_OF_ADDRESS) && of_chosen) {
406 for_each_child_of_node(of_chosen, np) { 406 for_each_child_of_node(of_chosen, np) {
407 if (of_device_is_compatible(np, "simple-framebuffer")) 407 if (of_device_is_compatible(np, "simple-framebuffer"))
408 of_platform_device_create(np, NULL, NULL); 408 of_platform_device_create(np, NULL, NULL);
diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
index 2ef9529809d8..9756f21b809e 100644
--- a/drivers/virtio/virtio_pci_common.c
+++ b/drivers/virtio/virtio_pci_common.c
@@ -282,6 +282,7 @@ void vp_del_vqs(struct virtio_device *vdev)
282 282
283 vp_free_vectors(vdev); 283 vp_free_vectors(vdev);
284 kfree(vp_dev->vqs); 284 kfree(vp_dev->vqs);
285 vp_dev->vqs = NULL;
285} 286}
286 287
287static int vp_try_to_find_vqs(struct virtio_device *vdev, unsigned nvqs, 288static int vp_try_to_find_vqs(struct virtio_device *vdev, unsigned nvqs,
@@ -421,15 +422,6 @@ int vp_set_vq_affinity(struct virtqueue *vq, int cpu)
421 return 0; 422 return 0;
422} 423}
423 424
424void virtio_pci_release_dev(struct device *_d)
425{
426 /*
427 * No need for a release method as we allocate/free
428 * all devices together with the pci devices.
429 * Provide an empty one to avoid getting a warning from core.
430 */
431}
432
433#ifdef CONFIG_PM_SLEEP 425#ifdef CONFIG_PM_SLEEP
434static int virtio_pci_freeze(struct device *dev) 426static int virtio_pci_freeze(struct device *dev)
435{ 427{
diff --git a/drivers/virtio/virtio_pci_common.h b/drivers/virtio/virtio_pci_common.h
index adddb647b21d..5a497289b7e9 100644
--- a/drivers/virtio/virtio_pci_common.h
+++ b/drivers/virtio/virtio_pci_common.h
@@ -126,7 +126,6 @@ const char *vp_bus_name(struct virtio_device *vdev);
126 * - ignore the affinity request if we're using INTX 126 * - ignore the affinity request if we're using INTX
127 */ 127 */
128int vp_set_vq_affinity(struct virtqueue *vq, int cpu); 128int vp_set_vq_affinity(struct virtqueue *vq, int cpu);
129void virtio_pci_release_dev(struct device *);
130 129
131int virtio_pci_legacy_probe(struct pci_dev *pci_dev, 130int virtio_pci_legacy_probe(struct pci_dev *pci_dev,
132 const struct pci_device_id *id); 131 const struct pci_device_id *id);
diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
index 6c76f0f5658c..a5486e65e04b 100644
--- a/drivers/virtio/virtio_pci_legacy.c
+++ b/drivers/virtio/virtio_pci_legacy.c
@@ -211,6 +211,17 @@ static const struct virtio_config_ops virtio_pci_config_ops = {
211 .set_vq_affinity = vp_set_vq_affinity, 211 .set_vq_affinity = vp_set_vq_affinity,
212}; 212};
213 213
214static void virtio_pci_release_dev(struct device *_d)
215{
216 struct virtio_device *vdev = dev_to_virtio(_d);
217 struct virtio_pci_device *vp_dev = to_vp_device(vdev);
218
219 /* As struct device is a kobject, it's not safe to
220 * free the memory (including the reference counter itself)
221 * until it's release callback. */
222 kfree(vp_dev);
223}
224
214/* the PCI probing function */ 225/* the PCI probing function */
215int virtio_pci_legacy_probe(struct pci_dev *pci_dev, 226int virtio_pci_legacy_probe(struct pci_dev *pci_dev,
216 const struct pci_device_id *id) 227 const struct pci_device_id *id)
@@ -302,5 +313,4 @@ void virtio_pci_legacy_remove(struct pci_dev *pci_dev)
302 pci_iounmap(pci_dev, vp_dev->ioaddr); 313 pci_iounmap(pci_dev, vp_dev->ioaddr);
303 pci_release_regions(pci_dev); 314 pci_release_regions(pci_dev);
304 pci_disable_device(pci_dev); 315 pci_disable_device(pci_dev);
305 kfree(vp_dev);
306} 316}
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 2d3e32ebfd15..8729cf68d2fe 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -1552,7 +1552,6 @@ int tree_backref_for_extent(unsigned long *ptr, struct extent_buffer *eb,
1552{ 1552{
1553 int ret; 1553 int ret;
1554 int type; 1554 int type;
1555 struct btrfs_tree_block_info *info;
1556 struct btrfs_extent_inline_ref *eiref; 1555 struct btrfs_extent_inline_ref *eiref;
1557 1556
1558 if (*ptr == (unsigned long)-1) 1557 if (*ptr == (unsigned long)-1)
@@ -1573,9 +1572,17 @@ int tree_backref_for_extent(unsigned long *ptr, struct extent_buffer *eb,
1573 } 1572 }
1574 1573
1575 /* we can treat both ref types equally here */ 1574 /* we can treat both ref types equally here */
1576 info = (struct btrfs_tree_block_info *)(ei + 1);
1577 *out_root = btrfs_extent_inline_ref_offset(eb, eiref); 1575 *out_root = btrfs_extent_inline_ref_offset(eb, eiref);
1578 *out_level = btrfs_tree_block_level(eb, info); 1576
1577 if (key->type == BTRFS_EXTENT_ITEM_KEY) {
1578 struct btrfs_tree_block_info *info;
1579
1580 info = (struct btrfs_tree_block_info *)(ei + 1);
1581 *out_level = btrfs_tree_block_level(eb, info);
1582 } else {
1583 ASSERT(key->type == BTRFS_METADATA_ITEM_KEY);
1584 *out_level = (u8)key->offset;
1585 }
1579 1586
1580 if (ret == 1) 1587 if (ret == 1)
1581 *ptr = (unsigned long)-1; 1588 *ptr = (unsigned long)-1;
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 054577bddaf2..de4e70fb3cbb 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -1857,6 +1857,14 @@ int btrfs_delayed_delete_inode_ref(struct inode *inode)
1857{ 1857{
1858 struct btrfs_delayed_node *delayed_node; 1858 struct btrfs_delayed_node *delayed_node;
1859 1859
1860 /*
1861 * we don't do delayed inode updates during log recovery because it
1862 * leads to enospc problems. This means we also can't do
1863 * delayed inode refs
1864 */
1865 if (BTRFS_I(inode)->root->fs_info->log_root_recovering)
1866 return -EAGAIN;
1867
1860 delayed_node = btrfs_get_or_create_delayed_node(inode); 1868 delayed_node = btrfs_get_or_create_delayed_node(inode);
1861 if (IS_ERR(delayed_node)) 1869 if (IS_ERR(delayed_node))
1862 return PTR_ERR(delayed_node); 1870 return PTR_ERR(delayed_node);
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index a80b97100d90..15116585e714 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3139,9 +3139,11 @@ static int write_one_cache_group(struct btrfs_trans_handle *trans,
3139 struct extent_buffer *leaf; 3139 struct extent_buffer *leaf;
3140 3140
3141 ret = btrfs_search_slot(trans, extent_root, &cache->key, path, 0, 1); 3141 ret = btrfs_search_slot(trans, extent_root, &cache->key, path, 0, 1);
3142 if (ret < 0) 3142 if (ret) {
3143 if (ret > 0)
3144 ret = -ENOENT;
3143 goto fail; 3145 goto fail;
3144 BUG_ON(ret); /* Corruption */ 3146 }
3145 3147
3146 leaf = path->nodes[0]; 3148 leaf = path->nodes[0];
3147 bi = btrfs_item_ptr_offset(leaf, path->slots[0]); 3149 bi = btrfs_item_ptr_offset(leaf, path->slots[0]);
@@ -3149,11 +3151,9 @@ static int write_one_cache_group(struct btrfs_trans_handle *trans,
3149 btrfs_mark_buffer_dirty(leaf); 3151 btrfs_mark_buffer_dirty(leaf);
3150 btrfs_release_path(path); 3152 btrfs_release_path(path);
3151fail: 3153fail:
3152 if (ret) { 3154 if (ret)
3153 btrfs_abort_transaction(trans, root, ret); 3155 btrfs_abort_transaction(trans, root, ret);
3154 return ret; 3156 return ret;
3155 }
3156 return 0;
3157 3157
3158} 3158}
3159 3159
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index e687bb0dc73a..8bf326affb94 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -6255,8 +6255,10 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
6255 6255
6256out_fail: 6256out_fail:
6257 btrfs_end_transaction(trans, root); 6257 btrfs_end_transaction(trans, root);
6258 if (drop_on_err) 6258 if (drop_on_err) {
6259 inode_dec_link_count(inode);
6259 iput(inode); 6260 iput(inode);
6261 }
6260 btrfs_balance_delayed_items(root); 6262 btrfs_balance_delayed_items(root);
6261 btrfs_btree_balance_dirty(root); 6263 btrfs_btree_balance_dirty(root);
6262 return err; 6264 return err;
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index f2bb13a23f86..9e1569ffbf6e 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -2607,9 +2607,9 @@ static int scrub_extent_for_parity(struct scrub_parity *sparity,
2607 ret = scrub_pages_for_parity(sparity, logical, l, physical, dev, 2607 ret = scrub_pages_for_parity(sparity, logical, l, physical, dev,
2608 flags, gen, mirror_num, 2608 flags, gen, mirror_num,
2609 have_csum ? csum : NULL); 2609 have_csum ? csum : NULL);
2610skip:
2611 if (ret) 2610 if (ret)
2612 return ret; 2611 return ret;
2612skip:
2613 len -= l; 2613 len -= l;
2614 logical += l; 2614 logical += l;
2615 physical += l; 2615 physical += l;
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index f5013d92a7e6..c81c0e004588 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -1416,7 +1416,7 @@ void ceph_fill_inline_data(struct inode *inode, struct page *locked_page,
1416 } 1416 }
1417 } 1417 }
1418 1418
1419 dout("fill_inline_data %p %llx.%llx len %lu locked_page %p\n", 1419 dout("fill_inline_data %p %llx.%llx len %zu locked_page %p\n",
1420 inode, ceph_vinop(inode), len, locked_page); 1420 inode, ceph_vinop(inode), len, locked_page);
1421 1421
1422 if (len > 0) { 1422 if (len > 0) {
diff --git a/fs/ceph/locks.c b/fs/ceph/locks.c
index c35c5c614e38..06ea5cd05cd9 100644
--- a/fs/ceph/locks.c
+++ b/fs/ceph/locks.c
@@ -239,23 +239,21 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)
239 return err; 239 return err;
240} 240}
241 241
242/** 242/*
243 * Must be called with lock_flocks() already held. Fills in the passed 243 * Fills in the passed counter variables, so you can prepare pagelist metadata
244 * counter variables, so you can prepare pagelist metadata before calling 244 * before calling ceph_encode_locks.
245 * ceph_encode_locks.
246 */ 245 */
247void ceph_count_locks(struct inode *inode, int *fcntl_count, int *flock_count) 246void ceph_count_locks(struct inode *inode, int *fcntl_count, int *flock_count)
248{ 247{
249 struct file_lock *lock; 248 struct file_lock_context *ctx;
250 249
251 *fcntl_count = 0; 250 *fcntl_count = 0;
252 *flock_count = 0; 251 *flock_count = 0;
253 252
254 for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) { 253 ctx = inode->i_flctx;
255 if (lock->fl_flags & FL_POSIX) 254 if (ctx) {
256 ++(*fcntl_count); 255 *fcntl_count = ctx->flc_posix_cnt;
257 else if (lock->fl_flags & FL_FLOCK) 256 *flock_count = ctx->flc_flock_cnt;
258 ++(*flock_count);
259 } 257 }
260 dout("counted %d flock locks and %d fcntl locks", 258 dout("counted %d flock locks and %d fcntl locks",
261 *flock_count, *fcntl_count); 259 *flock_count, *fcntl_count);
@@ -271,6 +269,7 @@ int ceph_encode_locks_to_buffer(struct inode *inode,
271 int num_fcntl_locks, int num_flock_locks) 269 int num_fcntl_locks, int num_flock_locks)
272{ 270{
273 struct file_lock *lock; 271 struct file_lock *lock;
272 struct file_lock_context *ctx = inode->i_flctx;
274 int err = 0; 273 int err = 0;
275 int seen_fcntl = 0; 274 int seen_fcntl = 0;
276 int seen_flock = 0; 275 int seen_flock = 0;
@@ -279,33 +278,34 @@ int ceph_encode_locks_to_buffer(struct inode *inode,
279 dout("encoding %d flock and %d fcntl locks", num_flock_locks, 278 dout("encoding %d flock and %d fcntl locks", num_flock_locks,
280 num_fcntl_locks); 279 num_fcntl_locks);
281 280
282 for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) { 281 if (!ctx)
283 if (lock->fl_flags & FL_POSIX) { 282 return 0;
284 ++seen_fcntl; 283
285 if (seen_fcntl > num_fcntl_locks) { 284 spin_lock(&ctx->flc_lock);
286 err = -ENOSPC; 285 list_for_each_entry(lock, &ctx->flc_flock, fl_list) {
287 goto fail; 286 ++seen_fcntl;
288 } 287 if (seen_fcntl > num_fcntl_locks) {
289 err = lock_to_ceph_filelock(lock, &flocks[l]); 288 err = -ENOSPC;
290 if (err) 289 goto fail;
291 goto fail;
292 ++l;
293 } 290 }
291 err = lock_to_ceph_filelock(lock, &flocks[l]);
292 if (err)
293 goto fail;
294 ++l;
294 } 295 }
295 for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) { 296 list_for_each_entry(lock, &ctx->flc_flock, fl_list) {
296 if (lock->fl_flags & FL_FLOCK) { 297 ++seen_flock;
297 ++seen_flock; 298 if (seen_flock > num_flock_locks) {
298 if (seen_flock > num_flock_locks) { 299 err = -ENOSPC;
299 err = -ENOSPC; 300 goto fail;
300 goto fail;
301 }
302 err = lock_to_ceph_filelock(lock, &flocks[l]);
303 if (err)
304 goto fail;
305 ++l;
306 } 301 }
302 err = lock_to_ceph_filelock(lock, &flocks[l]);
303 if (err)
304 goto fail;
305 ++l;
307 } 306 }
308fail: 307fail:
308 spin_unlock(&ctx->flc_lock);
309 return err; 309 return err;
310} 310}
311 311
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index d2171f4a6980..5f62fb7a5d0a 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -2700,20 +2700,16 @@ static int encode_caps_cb(struct inode *inode, struct ceph_cap *cap,
2700 struct ceph_filelock *flocks; 2700 struct ceph_filelock *flocks;
2701 2701
2702encode_again: 2702encode_again:
2703 spin_lock(&inode->i_lock);
2704 ceph_count_locks(inode, &num_fcntl_locks, &num_flock_locks); 2703 ceph_count_locks(inode, &num_fcntl_locks, &num_flock_locks);
2705 spin_unlock(&inode->i_lock);
2706 flocks = kmalloc((num_fcntl_locks+num_flock_locks) * 2704 flocks = kmalloc((num_fcntl_locks+num_flock_locks) *
2707 sizeof(struct ceph_filelock), GFP_NOFS); 2705 sizeof(struct ceph_filelock), GFP_NOFS);
2708 if (!flocks) { 2706 if (!flocks) {
2709 err = -ENOMEM; 2707 err = -ENOMEM;
2710 goto out_free; 2708 goto out_free;
2711 } 2709 }
2712 spin_lock(&inode->i_lock);
2713 err = ceph_encode_locks_to_buffer(inode, flocks, 2710 err = ceph_encode_locks_to_buffer(inode, flocks,
2714 num_fcntl_locks, 2711 num_fcntl_locks,
2715 num_flock_locks); 2712 num_flock_locks);
2716 spin_unlock(&inode->i_lock);
2717 if (err) { 2713 if (err) {
2718 kfree(flocks); 2714 kfree(flocks);
2719 if (err == -ENOSPC) 2715 if (err == -ENOSPC)
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 96b7e9b7706d..8c2ca6f62bad 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -1109,11 +1109,6 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
1109 return rc; 1109 return rc;
1110} 1110}
1111 1111
1112/* copied from fs/locks.c with a name change */
1113#define cifs_for_each_lock(inode, lockp) \
1114 for (lockp = &inode->i_flock; *lockp != NULL; \
1115 lockp = &(*lockp)->fl_next)
1116
1117struct lock_to_push { 1112struct lock_to_push {
1118 struct list_head llist; 1113 struct list_head llist;
1119 __u64 offset; 1114 __u64 offset;
@@ -1128,8 +1123,9 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
1128{ 1123{
1129 struct inode *inode = cfile->dentry->d_inode; 1124 struct inode *inode = cfile->dentry->d_inode;
1130 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); 1125 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
1131 struct file_lock *flock, **before; 1126 struct file_lock *flock;
1132 unsigned int count = 0, i = 0; 1127 struct file_lock_context *flctx = inode->i_flctx;
1128 unsigned int i;
1133 int rc = 0, xid, type; 1129 int rc = 0, xid, type;
1134 struct list_head locks_to_send, *el; 1130 struct list_head locks_to_send, *el;
1135 struct lock_to_push *lck, *tmp; 1131 struct lock_to_push *lck, *tmp;
@@ -1137,21 +1133,17 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
1137 1133
1138 xid = get_xid(); 1134 xid = get_xid();
1139 1135
1140 spin_lock(&inode->i_lock); 1136 if (!flctx)
1141 cifs_for_each_lock(inode, before) { 1137 goto out;
1142 if ((*before)->fl_flags & FL_POSIX)
1143 count++;
1144 }
1145 spin_unlock(&inode->i_lock);
1146 1138
1147 INIT_LIST_HEAD(&locks_to_send); 1139 INIT_LIST_HEAD(&locks_to_send);
1148 1140
1149 /* 1141 /*
1150 * Allocating count locks is enough because no FL_POSIX locks can be 1142 * Allocating flc_posix_cnt locks is enough because no FL_POSIX locks
1151 * added to the list while we are holding cinode->lock_sem that 1143 * can be added to the list while we are holding cinode->lock_sem that
1152 * protects locking operations of this inode. 1144 * protects locking operations of this inode.
1153 */ 1145 */
1154 for (; i < count; i++) { 1146 for (i = 0; i < flctx->flc_posix_cnt; i++) {
1155 lck = kmalloc(sizeof(struct lock_to_push), GFP_KERNEL); 1147 lck = kmalloc(sizeof(struct lock_to_push), GFP_KERNEL);
1156 if (!lck) { 1148 if (!lck) {
1157 rc = -ENOMEM; 1149 rc = -ENOMEM;
@@ -1161,11 +1153,8 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
1161 } 1153 }
1162 1154
1163 el = locks_to_send.next; 1155 el = locks_to_send.next;
1164 spin_lock(&inode->i_lock); 1156 spin_lock(&flctx->flc_lock);
1165 cifs_for_each_lock(inode, before) { 1157 list_for_each_entry(flock, &flctx->flc_posix, fl_list) {
1166 flock = *before;
1167 if ((flock->fl_flags & FL_POSIX) == 0)
1168 continue;
1169 if (el == &locks_to_send) { 1158 if (el == &locks_to_send) {
1170 /* 1159 /*
1171 * The list ended. We don't have enough allocated 1160 * The list ended. We don't have enough allocated
@@ -1185,9 +1174,8 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
1185 lck->length = length; 1174 lck->length = length;
1186 lck->type = type; 1175 lck->type = type;
1187 lck->offset = flock->fl_start; 1176 lck->offset = flock->fl_start;
1188 el = el->next;
1189 } 1177 }
1190 spin_unlock(&inode->i_lock); 1178 spin_unlock(&flctx->flc_lock);
1191 1179
1192 list_for_each_entry_safe(lck, tmp, &locks_to_send, llist) { 1180 list_for_each_entry_safe(lck, tmp, &locks_to_send, llist) {
1193 int stored_rc; 1181 int stored_rc;
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index e5d3eadf47b1..bed43081720f 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -5166,8 +5166,8 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
5166 5166
5167 /* fallback to generic here if not in extents fmt */ 5167 /* fallback to generic here if not in extents fmt */
5168 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) 5168 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
5169 return __generic_block_fiemap(inode, fieinfo, start, len, 5169 return generic_block_fiemap(inode, fieinfo, start, len,
5170 ext4_get_block); 5170 ext4_get_block);
5171 5171
5172 if (fiemap_check_flags(fieinfo, EXT4_FIEMAP_FLAGS)) 5172 if (fiemap_check_flags(fieinfo, EXT4_FIEMAP_FLAGS))
5173 return -EBADR; 5173 return -EBADR;
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 513c12cf444c..8131be8c0af3 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -273,19 +273,24 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
273 * we determine this extent as a data or a hole according to whether the 273 * we determine this extent as a data or a hole according to whether the
274 * page cache has data or not. 274 * page cache has data or not.
275 */ 275 */
276static int ext4_find_unwritten_pgoff(struct inode *inode, int whence, 276static int ext4_find_unwritten_pgoff(struct inode *inode,
277 loff_t endoff, loff_t *offset) 277 int whence,
278 struct ext4_map_blocks *map,
279 loff_t *offset)
278{ 280{
279 struct pagevec pvec; 281 struct pagevec pvec;
282 unsigned int blkbits;
280 pgoff_t index; 283 pgoff_t index;
281 pgoff_t end; 284 pgoff_t end;
285 loff_t endoff;
282 loff_t startoff; 286 loff_t startoff;
283 loff_t lastoff; 287 loff_t lastoff;
284 int found = 0; 288 int found = 0;
285 289
290 blkbits = inode->i_sb->s_blocksize_bits;
286 startoff = *offset; 291 startoff = *offset;
287 lastoff = startoff; 292 lastoff = startoff;
288 293 endoff = (loff_t)(map->m_lblk + map->m_len) << blkbits;
289 294
290 index = startoff >> PAGE_CACHE_SHIFT; 295 index = startoff >> PAGE_CACHE_SHIFT;
291 end = endoff >> PAGE_CACHE_SHIFT; 296 end = endoff >> PAGE_CACHE_SHIFT;
@@ -403,144 +408,147 @@ out:
403static loff_t ext4_seek_data(struct file *file, loff_t offset, loff_t maxsize) 408static loff_t ext4_seek_data(struct file *file, loff_t offset, loff_t maxsize)
404{ 409{
405 struct inode *inode = file->f_mapping->host; 410 struct inode *inode = file->f_mapping->host;
406 struct fiemap_extent_info fie; 411 struct ext4_map_blocks map;
407 struct fiemap_extent ext[2]; 412 struct extent_status es;
408 loff_t next; 413 ext4_lblk_t start, last, end;
409 int i, ret = 0; 414 loff_t dataoff, isize;
415 int blkbits;
416 int ret = 0;
410 417
411 mutex_lock(&inode->i_mutex); 418 mutex_lock(&inode->i_mutex);
412 if (offset >= inode->i_size) { 419
420 isize = i_size_read(inode);
421 if (offset >= isize) {
413 mutex_unlock(&inode->i_mutex); 422 mutex_unlock(&inode->i_mutex);
414 return -ENXIO; 423 return -ENXIO;
415 } 424 }
416 fie.fi_flags = 0; 425
417 fie.fi_extents_max = 2; 426 blkbits = inode->i_sb->s_blocksize_bits;
418 fie.fi_extents_start = (struct fiemap_extent __user *) &ext; 427 start = offset >> blkbits;
419 while (1) { 428 last = start;
420 mm_segment_t old_fs = get_fs(); 429 end = isize >> blkbits;
421 430 dataoff = offset;
422 fie.fi_extents_mapped = 0; 431
423 memset(ext, 0, sizeof(*ext) * fie.fi_extents_max); 432 do {
424 433 map.m_lblk = last;
425 set_fs(get_ds()); 434 map.m_len = end - last + 1;
426 ret = ext4_fiemap(inode, &fie, offset, maxsize - offset); 435 ret = ext4_map_blocks(NULL, inode, &map, 0);
427 set_fs(old_fs); 436 if (ret > 0 && !(map.m_flags & EXT4_MAP_UNWRITTEN)) {
428 if (ret) 437 if (last != start)
438 dataoff = (loff_t)last << blkbits;
429 break; 439 break;
440 }
430 441
431 /* No extents found, EOF */ 442 /*
432 if (!fie.fi_extents_mapped) { 443 * If there is a delay extent at this offset,
433 ret = -ENXIO; 444 * it will be as a data.
445 */
446 ext4_es_find_delayed_extent_range(inode, last, last, &es);
447 if (es.es_len != 0 && in_range(last, es.es_lblk, es.es_len)) {
448 if (last != start)
449 dataoff = (loff_t)last << blkbits;
434 break; 450 break;
435 } 451 }
436 for (i = 0; i < fie.fi_extents_mapped; i++) {
437 next = (loff_t)(ext[i].fe_length + ext[i].fe_logical);
438 452
439 if (offset < (loff_t)ext[i].fe_logical) 453 /*
440 offset = (loff_t)ext[i].fe_logical; 454 * If there is a unwritten extent at this offset,
441 /* 455 * it will be as a data or a hole according to page
442 * If extent is not unwritten, then it contains valid 456 * cache that has data or not.
443 * data, mapped or delayed. 457 */
444 */ 458 if (map.m_flags & EXT4_MAP_UNWRITTEN) {
445 if (!(ext[i].fe_flags & FIEMAP_EXTENT_UNWRITTEN)) 459 int unwritten;
446 goto out; 460 unwritten = ext4_find_unwritten_pgoff(inode, SEEK_DATA,
461 &map, &dataoff);
462 if (unwritten)
463 break;
464 }
447 465
448 /* 466 last++;
449 * If there is a unwritten extent at this offset, 467 dataoff = (loff_t)last << blkbits;
450 * it will be as a data or a hole according to page 468 } while (last <= end);
451 * cache that has data or not.
452 */
453 if (ext4_find_unwritten_pgoff(inode, SEEK_DATA,
454 next, &offset))
455 goto out;
456 469
457 if (ext[i].fe_flags & FIEMAP_EXTENT_LAST) {
458 ret = -ENXIO;
459 goto out;
460 }
461 offset = next;
462 }
463 }
464 if (offset > inode->i_size)
465 offset = inode->i_size;
466out:
467 mutex_unlock(&inode->i_mutex); 470 mutex_unlock(&inode->i_mutex);
468 if (ret)
469 return ret;
470 471
471 return vfs_setpos(file, offset, maxsize); 472 if (dataoff > isize)
473 return -ENXIO;
474
475 return vfs_setpos(file, dataoff, maxsize);
472} 476}
473 477
474/* 478/*
475 * ext4_seek_hole() retrieves the offset for SEEK_HOLE 479 * ext4_seek_hole() retrieves the offset for SEEK_HOLE.
476 */ 480 */
477static loff_t ext4_seek_hole(struct file *file, loff_t offset, loff_t maxsize) 481static loff_t ext4_seek_hole(struct file *file, loff_t offset, loff_t maxsize)
478{ 482{
479 struct inode *inode = file->f_mapping->host; 483 struct inode *inode = file->f_mapping->host;
480 struct fiemap_extent_info fie; 484 struct ext4_map_blocks map;
481 struct fiemap_extent ext[2]; 485 struct extent_status es;
482 loff_t next; 486 ext4_lblk_t start, last, end;
483 int i, ret = 0; 487 loff_t holeoff, isize;
488 int blkbits;
489 int ret = 0;
484 490
485 mutex_lock(&inode->i_mutex); 491 mutex_lock(&inode->i_mutex);
486 if (offset >= inode->i_size) { 492
493 isize = i_size_read(inode);
494 if (offset >= isize) {
487 mutex_unlock(&inode->i_mutex); 495 mutex_unlock(&inode->i_mutex);
488 return -ENXIO; 496 return -ENXIO;
489 } 497 }
490 498
491 fie.fi_flags = 0; 499 blkbits = inode->i_sb->s_blocksize_bits;
492 fie.fi_extents_max = 2; 500 start = offset >> blkbits;
493 fie.fi_extents_start = (struct fiemap_extent __user *)&ext; 501 last = start;
494 while (1) { 502 end = isize >> blkbits;
495 mm_segment_t old_fs = get_fs(); 503 holeoff = offset;
496
497 fie.fi_extents_mapped = 0;
498 memset(ext, 0, sizeof(*ext));
499 504
500 set_fs(get_ds()); 505 do {
501 ret = ext4_fiemap(inode, &fie, offset, maxsize - offset); 506 map.m_lblk = last;
502 set_fs(old_fs); 507 map.m_len = end - last + 1;
503 if (ret) 508 ret = ext4_map_blocks(NULL, inode, &map, 0);
504 break; 509 if (ret > 0 && !(map.m_flags & EXT4_MAP_UNWRITTEN)) {
510 last += ret;
511 holeoff = (loff_t)last << blkbits;
512 continue;
513 }
505 514
506 /* No extents found */ 515 /*
507 if (!fie.fi_extents_mapped) 516 * If there is a delay extent at this offset,
508 break; 517 * we will skip this extent.
518 */
519 ext4_es_find_delayed_extent_range(inode, last, last, &es);
520 if (es.es_len != 0 && in_range(last, es.es_lblk, es.es_len)) {
521 last = es.es_lblk + es.es_len;
522 holeoff = (loff_t)last << blkbits;
523 continue;
524 }
509 525
510 for (i = 0; i < fie.fi_extents_mapped; i++) { 526 /*
511 next = (loff_t)(ext[i].fe_logical + ext[i].fe_length); 527 * If there is a unwritten extent at this offset,
512 /* 528 * it will be as a data or a hole according to page
513 * If extent is not unwritten, then it contains valid 529 * cache that has data or not.
514 * data, mapped or delayed. 530 */
515 */ 531 if (map.m_flags & EXT4_MAP_UNWRITTEN) {
516 if (!(ext[i].fe_flags & FIEMAP_EXTENT_UNWRITTEN)) { 532 int unwritten;
517 if (offset < (loff_t)ext[i].fe_logical) 533 unwritten = ext4_find_unwritten_pgoff(inode, SEEK_HOLE,
518 goto out; 534 &map, &holeoff);
519 offset = next; 535 if (!unwritten) {
536 last += ret;
537 holeoff = (loff_t)last << blkbits;
520 continue; 538 continue;
521 } 539 }
522 /*
523 * If there is a unwritten extent at this offset,
524 * it will be as a data or a hole according to page
525 * cache that has data or not.
526 */
527 if (ext4_find_unwritten_pgoff(inode, SEEK_HOLE,
528 next, &offset))
529 goto out;
530
531 offset = next;
532 if (ext[i].fe_flags & FIEMAP_EXTENT_LAST)
533 goto out;
534 } 540 }
535 } 541
536 if (offset > inode->i_size) 542 /* find a hole */
537 offset = inode->i_size; 543 break;
538out: 544 } while (last <= end);
545
539 mutex_unlock(&inode->i_mutex); 546 mutex_unlock(&inode->i_mutex);
540 if (ret)
541 return ret;
542 547
543 return vfs_setpos(file, offset, maxsize); 548 if (holeoff > isize)
549 holeoff = isize;
550
551 return vfs_setpos(file, holeoff, maxsize);
544} 552}
545 553
546/* 554/*
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index bf76f405a5f9..8a8ec6293b19 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -24,6 +24,18 @@ int ext4_resize_begin(struct super_block *sb)
24 return -EPERM; 24 return -EPERM;
25 25
26 /* 26 /*
27 * If we are not using the primary superblock/GDT copy don't resize,
28 * because the user tools have no way of handling this. Probably a
29 * bad time to do it anyways.
30 */
31 if (EXT4_SB(sb)->s_sbh->b_blocknr !=
32 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block)) {
33 ext4_warning(sb, "won't resize using backup superblock at %llu",
34 (unsigned long long)EXT4_SB(sb)->s_sbh->b_blocknr);
35 return -EPERM;
36 }
37
38 /*
27 * We are not allowed to do online-resizing on a filesystem mounted 39 * We are not allowed to do online-resizing on a filesystem mounted
28 * with error, because it can destroy the filesystem easily. 40 * with error, because it can destroy the filesystem easily.
29 */ 41 */
@@ -758,18 +770,6 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
758 "EXT4-fs: ext4_add_new_gdb: adding group block %lu\n", 770 "EXT4-fs: ext4_add_new_gdb: adding group block %lu\n",
759 gdb_num); 771 gdb_num);
760 772
761 /*
762 * If we are not using the primary superblock/GDT copy don't resize,
763 * because the user tools have no way of handling this. Probably a
764 * bad time to do it anyways.
765 */
766 if (EXT4_SB(sb)->s_sbh->b_blocknr !=
767 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block)) {
768 ext4_warning(sb, "won't resize using backup superblock at %llu",
769 (unsigned long long)EXT4_SB(sb)->s_sbh->b_blocknr);
770 return -EPERM;
771 }
772
773 gdb_bh = sb_bread(sb, gdblock); 773 gdb_bh = sb_bread(sb, gdblock);
774 if (!gdb_bh) 774 if (!gdb_bh)
775 return -EIO; 775 return -EIO;
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 43c92b1685cb..74c5f53595fb 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -3482,7 +3482,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
3482 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 3482 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
3483 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) && 3483 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
3484 EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) 3484 EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
3485 ext4_warning(sb, KERN_INFO "metadata_csum and uninit_bg are " 3485 ext4_warning(sb, "metadata_csum and uninit_bg are "
3486 "redundant flags; please run fsck."); 3486 "redundant flags; please run fsck.");
3487 3487
3488 /* Check for a known checksum algorithm */ 3488 /* Check for a known checksum algorithm */
diff --git a/fs/fcntl.c b/fs/fcntl.c
index 99d440a4a6ba..ee85cd4e136a 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -740,14 +740,15 @@ static int __init fcntl_init(void)
740 * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY 740 * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY
741 * is defined as O_NONBLOCK on some platforms and not on others. 741 * is defined as O_NONBLOCK on some platforms and not on others.
742 */ 742 */
743 BUILD_BUG_ON(20 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32( 743 BUILD_BUG_ON(21 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
744 O_RDONLY | O_WRONLY | O_RDWR | 744 O_RDONLY | O_WRONLY | O_RDWR |
745 O_CREAT | O_EXCL | O_NOCTTY | 745 O_CREAT | O_EXCL | O_NOCTTY |
746 O_TRUNC | O_APPEND | /* O_NONBLOCK | */ 746 O_TRUNC | O_APPEND | /* O_NONBLOCK | */
747 __O_SYNC | O_DSYNC | FASYNC | 747 __O_SYNC | O_DSYNC | FASYNC |
748 O_DIRECT | O_LARGEFILE | O_DIRECTORY | 748 O_DIRECT | O_LARGEFILE | O_DIRECTORY |
749 O_NOFOLLOW | O_NOATIME | O_CLOEXEC | 749 O_NOFOLLOW | O_NOATIME | O_CLOEXEC |
750 __FMODE_EXEC | O_PATH | __O_TMPFILE 750 __FMODE_EXEC | O_PATH | __O_TMPFILE |
751 __FMODE_NONOTIFY
751 )); 752 ));
752 753
753 fasync_cache = kmem_cache_create("fasync_cache", 754 fasync_cache = kmem_cache_create("fasync_cache",
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index ba1107977f2e..ed19a7d622fa 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -131,6 +131,13 @@ static void fuse_req_init_context(struct fuse_req *req)
131 req->in.h.pid = current->pid; 131 req->in.h.pid = current->pid;
132} 132}
133 133
134void fuse_set_initialized(struct fuse_conn *fc)
135{
136 /* Make sure stores before this are seen on another CPU */
137 smp_wmb();
138 fc->initialized = 1;
139}
140
134static bool fuse_block_alloc(struct fuse_conn *fc, bool for_background) 141static bool fuse_block_alloc(struct fuse_conn *fc, bool for_background)
135{ 142{
136 return !fc->initialized || (for_background && fc->blocked); 143 return !fc->initialized || (for_background && fc->blocked);
@@ -155,6 +162,8 @@ static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages,
155 if (intr) 162 if (intr)
156 goto out; 163 goto out;
157 } 164 }
165 /* Matches smp_wmb() in fuse_set_initialized() */
166 smp_rmb();
158 167
159 err = -ENOTCONN; 168 err = -ENOTCONN;
160 if (!fc->connected) 169 if (!fc->connected)
@@ -253,6 +262,8 @@ struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc,
253 262
254 atomic_inc(&fc->num_waiting); 263 atomic_inc(&fc->num_waiting);
255 wait_event(fc->blocked_waitq, fc->initialized); 264 wait_event(fc->blocked_waitq, fc->initialized);
265 /* Matches smp_wmb() in fuse_set_initialized() */
266 smp_rmb();
256 req = fuse_request_alloc(0); 267 req = fuse_request_alloc(0);
257 if (!req) 268 if (!req)
258 req = get_reserved_req(fc, file); 269 req = get_reserved_req(fc, file);
@@ -511,6 +522,39 @@ void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req)
511} 522}
512EXPORT_SYMBOL_GPL(fuse_request_send); 523EXPORT_SYMBOL_GPL(fuse_request_send);
513 524
525static void fuse_adjust_compat(struct fuse_conn *fc, struct fuse_args *args)
526{
527 if (fc->minor < 4 && args->in.h.opcode == FUSE_STATFS)
528 args->out.args[0].size = FUSE_COMPAT_STATFS_SIZE;
529
530 if (fc->minor < 9) {
531 switch (args->in.h.opcode) {
532 case FUSE_LOOKUP:
533 case FUSE_CREATE:
534 case FUSE_MKNOD:
535 case FUSE_MKDIR:
536 case FUSE_SYMLINK:
537 case FUSE_LINK:
538 args->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE;
539 break;
540 case FUSE_GETATTR:
541 case FUSE_SETATTR:
542 args->out.args[0].size = FUSE_COMPAT_ATTR_OUT_SIZE;
543 break;
544 }
545 }
546 if (fc->minor < 12) {
547 switch (args->in.h.opcode) {
548 case FUSE_CREATE:
549 args->in.args[0].size = sizeof(struct fuse_open_in);
550 break;
551 case FUSE_MKNOD:
552 args->in.args[0].size = FUSE_COMPAT_MKNOD_IN_SIZE;
553 break;
554 }
555 }
556}
557
514ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args) 558ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args)
515{ 559{
516 struct fuse_req *req; 560 struct fuse_req *req;
@@ -520,6 +564,9 @@ ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args)
520 if (IS_ERR(req)) 564 if (IS_ERR(req))
521 return PTR_ERR(req); 565 return PTR_ERR(req);
522 566
567 /* Needs to be done after fuse_get_req() so that fc->minor is valid */
568 fuse_adjust_compat(fc, args);
569
523 req->in.h.opcode = args->in.h.opcode; 570 req->in.h.opcode = args->in.h.opcode;
524 req->in.h.nodeid = args->in.h.nodeid; 571 req->in.h.nodeid = args->in.h.nodeid;
525 req->in.numargs = args->in.numargs; 572 req->in.numargs = args->in.numargs;
@@ -2127,7 +2174,7 @@ void fuse_abort_conn(struct fuse_conn *fc)
2127 if (fc->connected) { 2174 if (fc->connected) {
2128 fc->connected = 0; 2175 fc->connected = 0;
2129 fc->blocked = 0; 2176 fc->blocked = 0;
2130 fc->initialized = 1; 2177 fuse_set_initialized(fc);
2131 end_io_requests(fc); 2178 end_io_requests(fc);
2132 end_queued_requests(fc); 2179 end_queued_requests(fc);
2133 end_polls(fc); 2180 end_polls(fc);
@@ -2146,7 +2193,7 @@ int fuse_dev_release(struct inode *inode, struct file *file)
2146 spin_lock(&fc->lock); 2193 spin_lock(&fc->lock);
2147 fc->connected = 0; 2194 fc->connected = 0;
2148 fc->blocked = 0; 2195 fc->blocked = 0;
2149 fc->initialized = 1; 2196 fuse_set_initialized(fc);
2150 end_queued_requests(fc); 2197 end_queued_requests(fc);
2151 end_polls(fc); 2198 end_polls(fc);
2152 wake_up_all(&fc->blocked_waitq); 2199 wake_up_all(&fc->blocked_waitq);
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 252b8a5de8b5..08e7b1a9d5d0 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -156,10 +156,7 @@ static void fuse_lookup_init(struct fuse_conn *fc, struct fuse_args *args,
156 args->in.args[0].size = name->len + 1; 156 args->in.args[0].size = name->len + 1;
157 args->in.args[0].value = name->name; 157 args->in.args[0].value = name->name;
158 args->out.numargs = 1; 158 args->out.numargs = 1;
159 if (fc->minor < 9) 159 args->out.args[0].size = sizeof(struct fuse_entry_out);
160 args->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE;
161 else
162 args->out.args[0].size = sizeof(struct fuse_entry_out);
163 args->out.args[0].value = outarg; 160 args->out.args[0].value = outarg;
164} 161}
165 162
@@ -422,16 +419,12 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry,
422 args.in.h.opcode = FUSE_CREATE; 419 args.in.h.opcode = FUSE_CREATE;
423 args.in.h.nodeid = get_node_id(dir); 420 args.in.h.nodeid = get_node_id(dir);
424 args.in.numargs = 2; 421 args.in.numargs = 2;
425 args.in.args[0].size = fc->minor < 12 ? sizeof(struct fuse_open_in) : 422 args.in.args[0].size = sizeof(inarg);
426 sizeof(inarg);
427 args.in.args[0].value = &inarg; 423 args.in.args[0].value = &inarg;
428 args.in.args[1].size = entry->d_name.len + 1; 424 args.in.args[1].size = entry->d_name.len + 1;
429 args.in.args[1].value = entry->d_name.name; 425 args.in.args[1].value = entry->d_name.name;
430 args.out.numargs = 2; 426 args.out.numargs = 2;
431 if (fc->minor < 9) 427 args.out.args[0].size = sizeof(outentry);
432 args.out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE;
433 else
434 args.out.args[0].size = sizeof(outentry);
435 args.out.args[0].value = &outentry; 428 args.out.args[0].value = &outentry;
436 args.out.args[1].size = sizeof(outopen); 429 args.out.args[1].size = sizeof(outopen);
437 args.out.args[1].value = &outopen; 430 args.out.args[1].value = &outopen;
@@ -539,10 +532,7 @@ static int create_new_entry(struct fuse_conn *fc, struct fuse_args *args,
539 memset(&outarg, 0, sizeof(outarg)); 532 memset(&outarg, 0, sizeof(outarg));
540 args->in.h.nodeid = get_node_id(dir); 533 args->in.h.nodeid = get_node_id(dir);
541 args->out.numargs = 1; 534 args->out.numargs = 1;
542 if (fc->minor < 9) 535 args->out.args[0].size = sizeof(outarg);
543 args->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE;
544 else
545 args->out.args[0].size = sizeof(outarg);
546 args->out.args[0].value = &outarg; 536 args->out.args[0].value = &outarg;
547 err = fuse_simple_request(fc, args); 537 err = fuse_simple_request(fc, args);
548 if (err) 538 if (err)
@@ -592,8 +582,7 @@ static int fuse_mknod(struct inode *dir, struct dentry *entry, umode_t mode,
592 inarg.umask = current_umask(); 582 inarg.umask = current_umask();
593 args.in.h.opcode = FUSE_MKNOD; 583 args.in.h.opcode = FUSE_MKNOD;
594 args.in.numargs = 2; 584 args.in.numargs = 2;
595 args.in.args[0].size = fc->minor < 12 ? FUSE_COMPAT_MKNOD_IN_SIZE : 585 args.in.args[0].size = sizeof(inarg);
596 sizeof(inarg);
597 args.in.args[0].value = &inarg; 586 args.in.args[0].value = &inarg;
598 args.in.args[1].size = entry->d_name.len + 1; 587 args.in.args[1].size = entry->d_name.len + 1;
599 args.in.args[1].value = entry->d_name.name; 588 args.in.args[1].value = entry->d_name.name;
@@ -899,10 +888,7 @@ static int fuse_do_getattr(struct inode *inode, struct kstat *stat,
899 args.in.args[0].size = sizeof(inarg); 888 args.in.args[0].size = sizeof(inarg);
900 args.in.args[0].value = &inarg; 889 args.in.args[0].value = &inarg;
901 args.out.numargs = 1; 890 args.out.numargs = 1;
902 if (fc->minor < 9) 891 args.out.args[0].size = sizeof(outarg);
903 args.out.args[0].size = FUSE_COMPAT_ATTR_OUT_SIZE;
904 else
905 args.out.args[0].size = sizeof(outarg);
906 args.out.args[0].value = &outarg; 892 args.out.args[0].value = &outarg;
907 err = fuse_simple_request(fc, &args); 893 err = fuse_simple_request(fc, &args);
908 if (!err) { 894 if (!err) {
@@ -1574,10 +1560,7 @@ static void fuse_setattr_fill(struct fuse_conn *fc, struct fuse_args *args,
1574 args->in.args[0].size = sizeof(*inarg_p); 1560 args->in.args[0].size = sizeof(*inarg_p);
1575 args->in.args[0].value = inarg_p; 1561 args->in.args[0].value = inarg_p;
1576 args->out.numargs = 1; 1562 args->out.numargs = 1;
1577 if (fc->minor < 9) 1563 args->out.args[0].size = sizeof(*outarg_p);
1578 args->out.args[0].size = FUSE_COMPAT_ATTR_OUT_SIZE;
1579 else
1580 args->out.args[0].size = sizeof(*outarg_p);
1581 args->out.args[0].value = outarg_p; 1564 args->out.args[0].value = outarg_p;
1582} 1565}
1583 1566
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index e0fc6725d1d0..1cdfb07c1376 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -906,4 +906,6 @@ int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
906int fuse_do_setattr(struct inode *inode, struct iattr *attr, 906int fuse_do_setattr(struct inode *inode, struct iattr *attr,
907 struct file *file); 907 struct file *file);
908 908
909void fuse_set_initialized(struct fuse_conn *fc);
910
909#endif /* _FS_FUSE_I_H */ 911#endif /* _FS_FUSE_I_H */
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 6749109f255d..f38256e4476e 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -424,8 +424,7 @@ static int fuse_statfs(struct dentry *dentry, struct kstatfs *buf)
424 args.in.h.opcode = FUSE_STATFS; 424 args.in.h.opcode = FUSE_STATFS;
425 args.in.h.nodeid = get_node_id(dentry->d_inode); 425 args.in.h.nodeid = get_node_id(dentry->d_inode);
426 args.out.numargs = 1; 426 args.out.numargs = 1;
427 args.out.args[0].size = 427 args.out.args[0].size = sizeof(outarg);
428 fc->minor < 4 ? FUSE_COMPAT_STATFS_SIZE : sizeof(outarg);
429 args.out.args[0].value = &outarg; 428 args.out.args[0].value = &outarg;
430 err = fuse_simple_request(fc, &args); 429 err = fuse_simple_request(fc, &args);
431 if (!err) 430 if (!err)
@@ -898,7 +897,7 @@ static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req)
898 fc->max_write = max_t(unsigned, 4096, fc->max_write); 897 fc->max_write = max_t(unsigned, 4096, fc->max_write);
899 fc->conn_init = 1; 898 fc->conn_init = 1;
900 } 899 }
901 fc->initialized = 1; 900 fuse_set_initialized(fc);
902 wake_up_all(&fc->blocked_waitq); 901 wake_up_all(&fc->blocked_waitq);
903} 902}
904 903
diff --git a/fs/inode.c b/fs/inode.c
index aa149e7262ac..f30872ade6d7 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -194,7 +194,7 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
194#ifdef CONFIG_FSNOTIFY 194#ifdef CONFIG_FSNOTIFY
195 inode->i_fsnotify_mask = 0; 195 inode->i_fsnotify_mask = 0;
196#endif 196#endif
197 197 inode->i_flctx = NULL;
198 this_cpu_inc(nr_inodes); 198 this_cpu_inc(nr_inodes);
199 199
200 return 0; 200 return 0;
@@ -237,6 +237,7 @@ void __destroy_inode(struct inode *inode)
237 BUG_ON(inode_has_buffers(inode)); 237 BUG_ON(inode_has_buffers(inode));
238 security_inode_free(inode); 238 security_inode_free(inode);
239 fsnotify_inode_delete(inode); 239 fsnotify_inode_delete(inode);
240 locks_free_lock_context(inode->i_flctx);
240 if (!inode->i_nlink) { 241 if (!inode->i_nlink) {
241 WARN_ON(atomic_long_read(&inode->i_sb->s_remove_count) == 0); 242 WARN_ON(atomic_long_read(&inode->i_sb->s_remove_count) == 0);
242 atomic_long_dec(&inode->i_sb->s_remove_count); 243 atomic_long_dec(&inode->i_sb->s_remove_count);
diff --git a/fs/lockd/svcsubs.c b/fs/lockd/svcsubs.c
index d12ff4e2dbe7..665ef5a05183 100644
--- a/fs/lockd/svcsubs.c
+++ b/fs/lockd/svcsubs.c
@@ -164,12 +164,15 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file,
164{ 164{
165 struct inode *inode = nlmsvc_file_inode(file); 165 struct inode *inode = nlmsvc_file_inode(file);
166 struct file_lock *fl; 166 struct file_lock *fl;
167 struct file_lock_context *flctx = inode->i_flctx;
167 struct nlm_host *lockhost; 168 struct nlm_host *lockhost;
168 169
170 if (!flctx || list_empty_careful(&flctx->flc_posix))
171 return 0;
169again: 172again:
170 file->f_locks = 0; 173 file->f_locks = 0;
171 spin_lock(&inode->i_lock); 174 spin_lock(&flctx->flc_lock);
172 for (fl = inode->i_flock; fl; fl = fl->fl_next) { 175 list_for_each_entry(fl, &flctx->flc_posix, fl_list) {
173 if (fl->fl_lmops != &nlmsvc_lock_operations) 176 if (fl->fl_lmops != &nlmsvc_lock_operations)
174 continue; 177 continue;
175 178
@@ -180,7 +183,7 @@ again:
180 if (match(lockhost, host)) { 183 if (match(lockhost, host)) {
181 struct file_lock lock = *fl; 184 struct file_lock lock = *fl;
182 185
183 spin_unlock(&inode->i_lock); 186 spin_unlock(&flctx->flc_lock);
184 lock.fl_type = F_UNLCK; 187 lock.fl_type = F_UNLCK;
185 lock.fl_start = 0; 188 lock.fl_start = 0;
186 lock.fl_end = OFFSET_MAX; 189 lock.fl_end = OFFSET_MAX;
@@ -192,7 +195,7 @@ again:
192 goto again; 195 goto again;
193 } 196 }
194 } 197 }
195 spin_unlock(&inode->i_lock); 198 spin_unlock(&flctx->flc_lock);
196 199
197 return 0; 200 return 0;
198} 201}
@@ -223,18 +226,21 @@ nlm_file_inuse(struct nlm_file *file)
223{ 226{
224 struct inode *inode = nlmsvc_file_inode(file); 227 struct inode *inode = nlmsvc_file_inode(file);
225 struct file_lock *fl; 228 struct file_lock *fl;
229 struct file_lock_context *flctx = inode->i_flctx;
226 230
227 if (file->f_count || !list_empty(&file->f_blocks) || file->f_shares) 231 if (file->f_count || !list_empty(&file->f_blocks) || file->f_shares)
228 return 1; 232 return 1;
229 233
230 spin_lock(&inode->i_lock); 234 if (flctx && !list_empty_careful(&flctx->flc_posix)) {
231 for (fl = inode->i_flock; fl; fl = fl->fl_next) { 235 spin_lock(&flctx->flc_lock);
232 if (fl->fl_lmops == &nlmsvc_lock_operations) { 236 list_for_each_entry(fl, &flctx->flc_posix, fl_list) {
233 spin_unlock(&inode->i_lock); 237 if (fl->fl_lmops == &nlmsvc_lock_operations) {
234 return 1; 238 spin_unlock(&flctx->flc_lock);
239 return 1;
240 }
235 } 241 }
242 spin_unlock(&flctx->flc_lock);
236 } 243 }
237 spin_unlock(&inode->i_lock);
238 file->f_locks = 0; 244 file->f_locks = 0;
239 return 0; 245 return 0;
240} 246}
diff --git a/fs/locks.c b/fs/locks.c
index 735b8d3fa78c..4d0d41163a50 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -157,14 +157,11 @@ static int target_leasetype(struct file_lock *fl)
157int leases_enable = 1; 157int leases_enable = 1;
158int lease_break_time = 45; 158int lease_break_time = 45;
159 159
160#define for_each_lock(inode, lockp) \
161 for (lockp = &inode->i_flock; *lockp != NULL; lockp = &(*lockp)->fl_next)
162
163/* 160/*
164 * The global file_lock_list is only used for displaying /proc/locks, so we 161 * The global file_lock_list is only used for displaying /proc/locks, so we
165 * keep a list on each CPU, with each list protected by its own spinlock via 162 * keep a list on each CPU, with each list protected by its own spinlock via
166 * the file_lock_lglock. Note that alterations to the list also require that 163 * the file_lock_lglock. Note that alterations to the list also require that
167 * the relevant i_lock is held. 164 * the relevant flc_lock is held.
168 */ 165 */
169DEFINE_STATIC_LGLOCK(file_lock_lglock); 166DEFINE_STATIC_LGLOCK(file_lock_lglock);
170static DEFINE_PER_CPU(struct hlist_head, file_lock_list); 167static DEFINE_PER_CPU(struct hlist_head, file_lock_list);
@@ -192,21 +189,68 @@ static DEFINE_HASHTABLE(blocked_hash, BLOCKED_HASH_BITS);
192 * contrast to those that are acting as records of acquired locks). 189 * contrast to those that are acting as records of acquired locks).
193 * 190 *
194 * Note that when we acquire this lock in order to change the above fields, 191 * Note that when we acquire this lock in order to change the above fields,
195 * we often hold the i_lock as well. In certain cases, when reading the fields 192 * we often hold the flc_lock as well. In certain cases, when reading the fields
196 * protected by this lock, we can skip acquiring it iff we already hold the 193 * protected by this lock, we can skip acquiring it iff we already hold the
197 * i_lock. 194 * flc_lock.
198 * 195 *
199 * In particular, adding an entry to the fl_block list requires that you hold 196 * In particular, adding an entry to the fl_block list requires that you hold
200 * both the i_lock and the blocked_lock_lock (acquired in that order). Deleting 197 * both the flc_lock and the blocked_lock_lock (acquired in that order).
201 * an entry from the list however only requires the file_lock_lock. 198 * Deleting an entry from the list however only requires the file_lock_lock.
202 */ 199 */
203static DEFINE_SPINLOCK(blocked_lock_lock); 200static DEFINE_SPINLOCK(blocked_lock_lock);
204 201
202static struct kmem_cache *flctx_cache __read_mostly;
205static struct kmem_cache *filelock_cache __read_mostly; 203static struct kmem_cache *filelock_cache __read_mostly;
206 204
205static struct file_lock_context *
206locks_get_lock_context(struct inode *inode)
207{
208 struct file_lock_context *new;
209
210 if (likely(inode->i_flctx))
211 goto out;
212
213 new = kmem_cache_alloc(flctx_cache, GFP_KERNEL);
214 if (!new)
215 goto out;
216
217 spin_lock_init(&new->flc_lock);
218 INIT_LIST_HEAD(&new->flc_flock);
219 INIT_LIST_HEAD(&new->flc_posix);
220 INIT_LIST_HEAD(&new->flc_lease);
221
222 /*
223 * Assign the pointer if it's not already assigned. If it is, then
224 * free the context we just allocated.
225 */
226 spin_lock(&inode->i_lock);
227 if (likely(!inode->i_flctx)) {
228 inode->i_flctx = new;
229 new = NULL;
230 }
231 spin_unlock(&inode->i_lock);
232
233 if (new)
234 kmem_cache_free(flctx_cache, new);
235out:
236 return inode->i_flctx;
237}
238
239void
240locks_free_lock_context(struct file_lock_context *ctx)
241{
242 if (ctx) {
243 WARN_ON_ONCE(!list_empty(&ctx->flc_flock));
244 WARN_ON_ONCE(!list_empty(&ctx->flc_posix));
245 WARN_ON_ONCE(!list_empty(&ctx->flc_lease));
246 kmem_cache_free(flctx_cache, ctx);
247 }
248}
249
207static void locks_init_lock_heads(struct file_lock *fl) 250static void locks_init_lock_heads(struct file_lock *fl)
208{ 251{
209 INIT_HLIST_NODE(&fl->fl_link); 252 INIT_HLIST_NODE(&fl->fl_link);
253 INIT_LIST_HEAD(&fl->fl_list);
210 INIT_LIST_HEAD(&fl->fl_block); 254 INIT_LIST_HEAD(&fl->fl_block);
211 init_waitqueue_head(&fl->fl_wait); 255 init_waitqueue_head(&fl->fl_wait);
212} 256}
@@ -243,6 +287,7 @@ EXPORT_SYMBOL_GPL(locks_release_private);
243void locks_free_lock(struct file_lock *fl) 287void locks_free_lock(struct file_lock *fl)
244{ 288{
245 BUG_ON(waitqueue_active(&fl->fl_wait)); 289 BUG_ON(waitqueue_active(&fl->fl_wait));
290 BUG_ON(!list_empty(&fl->fl_list));
246 BUG_ON(!list_empty(&fl->fl_block)); 291 BUG_ON(!list_empty(&fl->fl_block));
247 BUG_ON(!hlist_unhashed(&fl->fl_link)); 292 BUG_ON(!hlist_unhashed(&fl->fl_link));
248 293
@@ -257,8 +302,8 @@ locks_dispose_list(struct list_head *dispose)
257 struct file_lock *fl; 302 struct file_lock *fl;
258 303
259 while (!list_empty(dispose)) { 304 while (!list_empty(dispose)) {
260 fl = list_first_entry(dispose, struct file_lock, fl_block); 305 fl = list_first_entry(dispose, struct file_lock, fl_list);
261 list_del_init(&fl->fl_block); 306 list_del_init(&fl->fl_list);
262 locks_free_lock(fl); 307 locks_free_lock(fl);
263 } 308 }
264} 309}
@@ -513,7 +558,7 @@ static int posix_same_owner(struct file_lock *fl1, struct file_lock *fl2)
513 return fl1->fl_owner == fl2->fl_owner; 558 return fl1->fl_owner == fl2->fl_owner;
514} 559}
515 560
516/* Must be called with the i_lock held! */ 561/* Must be called with the flc_lock held! */
517static void locks_insert_global_locks(struct file_lock *fl) 562static void locks_insert_global_locks(struct file_lock *fl)
518{ 563{
519 lg_local_lock(&file_lock_lglock); 564 lg_local_lock(&file_lock_lglock);
@@ -522,12 +567,12 @@ static void locks_insert_global_locks(struct file_lock *fl)
522 lg_local_unlock(&file_lock_lglock); 567 lg_local_unlock(&file_lock_lglock);
523} 568}
524 569
525/* Must be called with the i_lock held! */ 570/* Must be called with the flc_lock held! */
526static void locks_delete_global_locks(struct file_lock *fl) 571static void locks_delete_global_locks(struct file_lock *fl)
527{ 572{
528 /* 573 /*
529 * Avoid taking lock if already unhashed. This is safe since this check 574 * Avoid taking lock if already unhashed. This is safe since this check
530 * is done while holding the i_lock, and new insertions into the list 575 * is done while holding the flc_lock, and new insertions into the list
531 * also require that it be held. 576 * also require that it be held.
532 */ 577 */
533 if (hlist_unhashed(&fl->fl_link)) 578 if (hlist_unhashed(&fl->fl_link))
@@ -579,10 +624,10 @@ static void locks_delete_block(struct file_lock *waiter)
579 * the order they blocked. The documentation doesn't require this but 624 * the order they blocked. The documentation doesn't require this but
580 * it seems like the reasonable thing to do. 625 * it seems like the reasonable thing to do.
581 * 626 *
582 * Must be called with both the i_lock and blocked_lock_lock held. The fl_block 627 * Must be called with both the flc_lock and blocked_lock_lock held. The
583 * list itself is protected by the blocked_lock_lock, but by ensuring that the 628 * fl_block list itself is protected by the blocked_lock_lock, but by ensuring
584 * i_lock is also held on insertions we can avoid taking the blocked_lock_lock 629 * that the flc_lock is also held on insertions we can avoid taking the
585 * in some cases when we see that the fl_block list is empty. 630 * blocked_lock_lock in some cases when we see that the fl_block list is empty.
586 */ 631 */
587static void __locks_insert_block(struct file_lock *blocker, 632static void __locks_insert_block(struct file_lock *blocker,
588 struct file_lock *waiter) 633 struct file_lock *waiter)
@@ -594,7 +639,7 @@ static void __locks_insert_block(struct file_lock *blocker,
594 locks_insert_global_blocked(waiter); 639 locks_insert_global_blocked(waiter);
595} 640}
596 641
597/* Must be called with i_lock held. */ 642/* Must be called with flc_lock held. */
598static void locks_insert_block(struct file_lock *blocker, 643static void locks_insert_block(struct file_lock *blocker,
599 struct file_lock *waiter) 644 struct file_lock *waiter)
600{ 645{
@@ -606,15 +651,15 @@ static void locks_insert_block(struct file_lock *blocker,
606/* 651/*
607 * Wake up processes blocked waiting for blocker. 652 * Wake up processes blocked waiting for blocker.
608 * 653 *
609 * Must be called with the inode->i_lock held! 654 * Must be called with the inode->flc_lock held!
610 */ 655 */
611static void locks_wake_up_blocks(struct file_lock *blocker) 656static void locks_wake_up_blocks(struct file_lock *blocker)
612{ 657{
613 /* 658 /*
614 * Avoid taking global lock if list is empty. This is safe since new 659 * Avoid taking global lock if list is empty. This is safe since new
615 * blocked requests are only added to the list under the i_lock, and 660 * blocked requests are only added to the list under the flc_lock, and
616 * the i_lock is always held here. Note that removal from the fl_block 661 * the flc_lock is always held here. Note that removal from the fl_block
617 * list does not require the i_lock, so we must recheck list_empty() 662 * list does not require the flc_lock, so we must recheck list_empty()
618 * after acquiring the blocked_lock_lock. 663 * after acquiring the blocked_lock_lock.
619 */ 664 */
620 if (list_empty(&blocker->fl_block)) 665 if (list_empty(&blocker->fl_block))
@@ -635,63 +680,36 @@ static void locks_wake_up_blocks(struct file_lock *blocker)
635 spin_unlock(&blocked_lock_lock); 680 spin_unlock(&blocked_lock_lock);
636} 681}
637 682
638/* Insert file lock fl into an inode's lock list at the position indicated 683static void
639 * by pos. At the same time add the lock to the global file lock list. 684locks_insert_lock_ctx(struct file_lock *fl, int *counter,
640 * 685 struct list_head *before)
641 * Must be called with the i_lock held!
642 */
643static void locks_insert_lock(struct file_lock **pos, struct file_lock *fl)
644{ 686{
645 fl->fl_nspid = get_pid(task_tgid(current)); 687 fl->fl_nspid = get_pid(task_tgid(current));
646 688 list_add_tail(&fl->fl_list, before);
647 /* insert into file's list */ 689 ++*counter;
648 fl->fl_next = *pos;
649 *pos = fl;
650
651 locks_insert_global_locks(fl); 690 locks_insert_global_locks(fl);
652} 691}
653 692
654/** 693static void
655 * locks_delete_lock - Delete a lock and then free it. 694locks_unlink_lock_ctx(struct file_lock *fl, int *counter)
656 * @thisfl_p: pointer that points to the fl_next field of the previous
657 * inode->i_flock list entry
658 *
659 * Unlink a lock from all lists and free the namespace reference, but don't
660 * free it yet. Wake up processes that are blocked waiting for this lock and
661 * notify the FS that the lock has been cleared.
662 *
663 * Must be called with the i_lock held!
664 */
665static void locks_unlink_lock(struct file_lock **thisfl_p)
666{ 695{
667 struct file_lock *fl = *thisfl_p;
668
669 locks_delete_global_locks(fl); 696 locks_delete_global_locks(fl);
670 697 list_del_init(&fl->fl_list);
671 *thisfl_p = fl->fl_next; 698 --*counter;
672 fl->fl_next = NULL;
673
674 if (fl->fl_nspid) { 699 if (fl->fl_nspid) {
675 put_pid(fl->fl_nspid); 700 put_pid(fl->fl_nspid);
676 fl->fl_nspid = NULL; 701 fl->fl_nspid = NULL;
677 } 702 }
678
679 locks_wake_up_blocks(fl); 703 locks_wake_up_blocks(fl);
680} 704}
681 705
682/* 706static void
683 * Unlink a lock from all lists and free it. 707locks_delete_lock_ctx(struct file_lock *fl, int *counter,
684 * 708 struct list_head *dispose)
685 * Must be called with i_lock held!
686 */
687static void locks_delete_lock(struct file_lock **thisfl_p,
688 struct list_head *dispose)
689{ 709{
690 struct file_lock *fl = *thisfl_p; 710 locks_unlink_lock_ctx(fl, counter);
691
692 locks_unlink_lock(thisfl_p);
693 if (dispose) 711 if (dispose)
694 list_add(&fl->fl_block, dispose); 712 list_add(&fl->fl_list, dispose);
695 else 713 else
696 locks_free_lock(fl); 714 locks_free_lock(fl);
697} 715}
@@ -746,22 +764,27 @@ void
746posix_test_lock(struct file *filp, struct file_lock *fl) 764posix_test_lock(struct file *filp, struct file_lock *fl)
747{ 765{
748 struct file_lock *cfl; 766 struct file_lock *cfl;
767 struct file_lock_context *ctx;
749 struct inode *inode = file_inode(filp); 768 struct inode *inode = file_inode(filp);
750 769
751 spin_lock(&inode->i_lock); 770 ctx = inode->i_flctx;
752 for (cfl = file_inode(filp)->i_flock; cfl; cfl = cfl->fl_next) { 771 if (!ctx || list_empty_careful(&ctx->flc_posix)) {
753 if (!IS_POSIX(cfl))
754 continue;
755 if (posix_locks_conflict(fl, cfl))
756 break;
757 }
758 if (cfl) {
759 locks_copy_conflock(fl, cfl);
760 if (cfl->fl_nspid)
761 fl->fl_pid = pid_vnr(cfl->fl_nspid);
762 } else
763 fl->fl_type = F_UNLCK; 772 fl->fl_type = F_UNLCK;
764 spin_unlock(&inode->i_lock); 773 return;
774 }
775
776 spin_lock(&ctx->flc_lock);
777 list_for_each_entry(cfl, &ctx->flc_posix, fl_list) {
778 if (posix_locks_conflict(fl, cfl)) {
779 locks_copy_conflock(fl, cfl);
780 if (cfl->fl_nspid)
781 fl->fl_pid = pid_vnr(cfl->fl_nspid);
782 goto out;
783 }
784 }
785 fl->fl_type = F_UNLCK;
786out:
787 spin_unlock(&ctx->flc_lock);
765 return; 788 return;
766} 789}
767EXPORT_SYMBOL(posix_test_lock); 790EXPORT_SYMBOL(posix_test_lock);
@@ -845,34 +868,34 @@ static int posix_locks_deadlock(struct file_lock *caller_fl,
845static int flock_lock_file(struct file *filp, struct file_lock *request) 868static int flock_lock_file(struct file *filp, struct file_lock *request)
846{ 869{
847 struct file_lock *new_fl = NULL; 870 struct file_lock *new_fl = NULL;
848 struct file_lock **before; 871 struct file_lock *fl;
849 struct inode * inode = file_inode(filp); 872 struct file_lock_context *ctx;
873 struct inode *inode = file_inode(filp);
850 int error = 0; 874 int error = 0;
851 int found = 0; 875 bool found = false;
852 LIST_HEAD(dispose); 876 LIST_HEAD(dispose);
853 877
878 ctx = locks_get_lock_context(inode);
879 if (!ctx)
880 return -ENOMEM;
881
854 if (!(request->fl_flags & FL_ACCESS) && (request->fl_type != F_UNLCK)) { 882 if (!(request->fl_flags & FL_ACCESS) && (request->fl_type != F_UNLCK)) {
855 new_fl = locks_alloc_lock(); 883 new_fl = locks_alloc_lock();
856 if (!new_fl) 884 if (!new_fl)
857 return -ENOMEM; 885 return -ENOMEM;
858 } 886 }
859 887
860 spin_lock(&inode->i_lock); 888 spin_lock(&ctx->flc_lock);
861 if (request->fl_flags & FL_ACCESS) 889 if (request->fl_flags & FL_ACCESS)
862 goto find_conflict; 890 goto find_conflict;
863 891
864 for_each_lock(inode, before) { 892 list_for_each_entry(fl, &ctx->flc_flock, fl_list) {
865 struct file_lock *fl = *before;
866 if (IS_POSIX(fl))
867 break;
868 if (IS_LEASE(fl))
869 continue;
870 if (filp != fl->fl_file) 893 if (filp != fl->fl_file)
871 continue; 894 continue;
872 if (request->fl_type == fl->fl_type) 895 if (request->fl_type == fl->fl_type)
873 goto out; 896 goto out;
874 found = 1; 897 found = true;
875 locks_delete_lock(before, &dispose); 898 locks_delete_lock_ctx(fl, &ctx->flc_flock_cnt, &dispose);
876 break; 899 break;
877 } 900 }
878 901
@@ -887,18 +910,13 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
887 * give it the opportunity to lock the file. 910 * give it the opportunity to lock the file.
888 */ 911 */
889 if (found) { 912 if (found) {
890 spin_unlock(&inode->i_lock); 913 spin_unlock(&ctx->flc_lock);
891 cond_resched(); 914 cond_resched();
892 spin_lock(&inode->i_lock); 915 spin_lock(&ctx->flc_lock);
893 } 916 }
894 917
895find_conflict: 918find_conflict:
896 for_each_lock(inode, before) { 919 list_for_each_entry(fl, &ctx->flc_flock, fl_list) {
897 struct file_lock *fl = *before;
898 if (IS_POSIX(fl))
899 break;
900 if (IS_LEASE(fl))
901 continue;
902 if (!flock_locks_conflict(request, fl)) 920 if (!flock_locks_conflict(request, fl))
903 continue; 921 continue;
904 error = -EAGAIN; 922 error = -EAGAIN;
@@ -911,12 +929,12 @@ find_conflict:
911 if (request->fl_flags & FL_ACCESS) 929 if (request->fl_flags & FL_ACCESS)
912 goto out; 930 goto out;
913 locks_copy_lock(new_fl, request); 931 locks_copy_lock(new_fl, request);
914 locks_insert_lock(before, new_fl); 932 locks_insert_lock_ctx(new_fl, &ctx->flc_flock_cnt, &ctx->flc_flock);
915 new_fl = NULL; 933 new_fl = NULL;
916 error = 0; 934 error = 0;
917 935
918out: 936out:
919 spin_unlock(&inode->i_lock); 937 spin_unlock(&ctx->flc_lock);
920 if (new_fl) 938 if (new_fl)
921 locks_free_lock(new_fl); 939 locks_free_lock(new_fl);
922 locks_dispose_list(&dispose); 940 locks_dispose_list(&dispose);
@@ -925,16 +943,20 @@ out:
925 943
926static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock) 944static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
927{ 945{
928 struct file_lock *fl; 946 struct file_lock *fl, *tmp;
929 struct file_lock *new_fl = NULL; 947 struct file_lock *new_fl = NULL;
930 struct file_lock *new_fl2 = NULL; 948 struct file_lock *new_fl2 = NULL;
931 struct file_lock *left = NULL; 949 struct file_lock *left = NULL;
932 struct file_lock *right = NULL; 950 struct file_lock *right = NULL;
933 struct file_lock **before; 951 struct file_lock_context *ctx;
934 int error; 952 int error;
935 bool added = false; 953 bool added = false;
936 LIST_HEAD(dispose); 954 LIST_HEAD(dispose);
937 955
956 ctx = locks_get_lock_context(inode);
957 if (!ctx)
958 return -ENOMEM;
959
938 /* 960 /*
939 * We may need two file_lock structures for this operation, 961 * We may need two file_lock structures for this operation,
940 * so we get them in advance to avoid races. 962 * so we get them in advance to avoid races.
@@ -948,15 +970,14 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
948 new_fl2 = locks_alloc_lock(); 970 new_fl2 = locks_alloc_lock();
949 } 971 }
950 972
951 spin_lock(&inode->i_lock); 973 spin_lock(&ctx->flc_lock);
952 /* 974 /*
953 * New lock request. Walk all POSIX locks and look for conflicts. If 975 * New lock request. Walk all POSIX locks and look for conflicts. If
954 * there are any, either return error or put the request on the 976 * there are any, either return error or put the request on the
955 * blocker's list of waiters and the global blocked_hash. 977 * blocker's list of waiters and the global blocked_hash.
956 */ 978 */
957 if (request->fl_type != F_UNLCK) { 979 if (request->fl_type != F_UNLCK) {
958 for_each_lock(inode, before) { 980 list_for_each_entry(fl, &ctx->flc_posix, fl_list) {
959 fl = *before;
960 if (!IS_POSIX(fl)) 981 if (!IS_POSIX(fl))
961 continue; 982 continue;
962 if (!posix_locks_conflict(request, fl)) 983 if (!posix_locks_conflict(request, fl))
@@ -986,29 +1007,25 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
986 if (request->fl_flags & FL_ACCESS) 1007 if (request->fl_flags & FL_ACCESS)
987 goto out; 1008 goto out;
988 1009
989 /* 1010 /* Find the first old lock with the same owner as the new lock */
990 * Find the first old lock with the same owner as the new lock. 1011 list_for_each_entry(fl, &ctx->flc_posix, fl_list) {
991 */ 1012 if (posix_same_owner(request, fl))
992 1013 break;
993 before = &inode->i_flock;
994
995 /* First skip locks owned by other processes. */
996 while ((fl = *before) && (!IS_POSIX(fl) ||
997 !posix_same_owner(request, fl))) {
998 before = &fl->fl_next;
999 } 1014 }
1000 1015
1001 /* Process locks with this owner. */ 1016 /* Process locks with this owner. */
1002 while ((fl = *before) && posix_same_owner(request, fl)) { 1017 list_for_each_entry_safe_from(fl, tmp, &ctx->flc_posix, fl_list) {
1003 /* Detect adjacent or overlapping regions (if same lock type) 1018 if (!posix_same_owner(request, fl))
1004 */ 1019 break;
1020
1021 /* Detect adjacent or overlapping regions (if same lock type) */
1005 if (request->fl_type == fl->fl_type) { 1022 if (request->fl_type == fl->fl_type) {
1006 /* In all comparisons of start vs end, use 1023 /* In all comparisons of start vs end, use
1007 * "start - 1" rather than "end + 1". If end 1024 * "start - 1" rather than "end + 1". If end
1008 * is OFFSET_MAX, end + 1 will become negative. 1025 * is OFFSET_MAX, end + 1 will become negative.
1009 */ 1026 */
1010 if (fl->fl_end < request->fl_start - 1) 1027 if (fl->fl_end < request->fl_start - 1)
1011 goto next_lock; 1028 continue;
1012 /* If the next lock in the list has entirely bigger 1029 /* If the next lock in the list has entirely bigger
1013 * addresses than the new one, insert the lock here. 1030 * addresses than the new one, insert the lock here.
1014 */ 1031 */
@@ -1029,18 +1046,18 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
1029 else 1046 else
1030 request->fl_end = fl->fl_end; 1047 request->fl_end = fl->fl_end;
1031 if (added) { 1048 if (added) {
1032 locks_delete_lock(before, &dispose); 1049 locks_delete_lock_ctx(fl, &ctx->flc_posix_cnt,
1050 &dispose);
1033 continue; 1051 continue;
1034 } 1052 }
1035 request = fl; 1053 request = fl;
1036 added = true; 1054 added = true;
1037 } 1055 } else {
1038 else {
1039 /* Processing for different lock types is a bit 1056 /* Processing for different lock types is a bit
1040 * more complex. 1057 * more complex.
1041 */ 1058 */
1042 if (fl->fl_end < request->fl_start) 1059 if (fl->fl_end < request->fl_start)
1043 goto next_lock; 1060 continue;
1044 if (fl->fl_start > request->fl_end) 1061 if (fl->fl_start > request->fl_end)
1045 break; 1062 break;
1046 if (request->fl_type == F_UNLCK) 1063 if (request->fl_type == F_UNLCK)
@@ -1059,7 +1076,8 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
1059 * one (This may happen several times). 1076 * one (This may happen several times).
1060 */ 1077 */
1061 if (added) { 1078 if (added) {
1062 locks_delete_lock(before, &dispose); 1079 locks_delete_lock_ctx(fl,
1080 &ctx->flc_posix_cnt, &dispose);
1063 continue; 1081 continue;
1064 } 1082 }
1065 /* 1083 /*
@@ -1075,15 +1093,13 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
1075 locks_copy_lock(new_fl, request); 1093 locks_copy_lock(new_fl, request);
1076 request = new_fl; 1094 request = new_fl;
1077 new_fl = NULL; 1095 new_fl = NULL;
1078 locks_delete_lock(before, &dispose); 1096 locks_insert_lock_ctx(request,
1079 locks_insert_lock(before, request); 1097 &ctx->flc_posix_cnt, &fl->fl_list);
1098 locks_delete_lock_ctx(fl,
1099 &ctx->flc_posix_cnt, &dispose);
1080 added = true; 1100 added = true;
1081 } 1101 }
1082 } 1102 }
1083 /* Go on to next lock.
1084 */
1085 next_lock:
1086 before = &fl->fl_next;
1087 } 1103 }
1088 1104
1089 /* 1105 /*
@@ -1108,7 +1124,8 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
1108 goto out; 1124 goto out;
1109 } 1125 }
1110 locks_copy_lock(new_fl, request); 1126 locks_copy_lock(new_fl, request);
1111 locks_insert_lock(before, new_fl); 1127 locks_insert_lock_ctx(new_fl, &ctx->flc_posix_cnt,
1128 &fl->fl_list);
1112 new_fl = NULL; 1129 new_fl = NULL;
1113 } 1130 }
1114 if (right) { 1131 if (right) {
@@ -1119,7 +1136,8 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
1119 left = new_fl2; 1136 left = new_fl2;
1120 new_fl2 = NULL; 1137 new_fl2 = NULL;
1121 locks_copy_lock(left, right); 1138 locks_copy_lock(left, right);
1122 locks_insert_lock(before, left); 1139 locks_insert_lock_ctx(left, &ctx->flc_posix_cnt,
1140 &fl->fl_list);
1123 } 1141 }
1124 right->fl_start = request->fl_end + 1; 1142 right->fl_start = request->fl_end + 1;
1125 locks_wake_up_blocks(right); 1143 locks_wake_up_blocks(right);
@@ -1129,7 +1147,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
1129 locks_wake_up_blocks(left); 1147 locks_wake_up_blocks(left);
1130 } 1148 }
1131 out: 1149 out:
1132 spin_unlock(&inode->i_lock); 1150 spin_unlock(&ctx->flc_lock);
1133 /* 1151 /*
1134 * Free any unused locks. 1152 * Free any unused locks.
1135 */ 1153 */
@@ -1199,22 +1217,29 @@ EXPORT_SYMBOL(posix_lock_file_wait);
1199 */ 1217 */
1200int locks_mandatory_locked(struct file *file) 1218int locks_mandatory_locked(struct file *file)
1201{ 1219{
1220 int ret;
1202 struct inode *inode = file_inode(file); 1221 struct inode *inode = file_inode(file);
1222 struct file_lock_context *ctx;
1203 struct file_lock *fl; 1223 struct file_lock *fl;
1204 1224
1225 ctx = inode->i_flctx;
1226 if (!ctx || list_empty_careful(&ctx->flc_posix))
1227 return 0;
1228
1205 /* 1229 /*
1206 * Search the lock list for this inode for any POSIX locks. 1230 * Search the lock list for this inode for any POSIX locks.
1207 */ 1231 */
1208 spin_lock(&inode->i_lock); 1232 spin_lock(&ctx->flc_lock);
1209 for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { 1233 ret = 0;
1210 if (!IS_POSIX(fl)) 1234 list_for_each_entry(fl, &ctx->flc_posix, fl_list) {
1211 continue;
1212 if (fl->fl_owner != current->files && 1235 if (fl->fl_owner != current->files &&
1213 fl->fl_owner != file) 1236 fl->fl_owner != file) {
1237 ret = -EAGAIN;
1214 break; 1238 break;
1239 }
1215 } 1240 }
1216 spin_unlock(&inode->i_lock); 1241 spin_unlock(&ctx->flc_lock);
1217 return fl ? -EAGAIN : 0; 1242 return ret;
1218} 1243}
1219 1244
1220/** 1245/**
@@ -1294,9 +1319,9 @@ static void lease_clear_pending(struct file_lock *fl, int arg)
1294} 1319}
1295 1320
1296/* We already had a lease on this file; just change its type */ 1321/* We already had a lease on this file; just change its type */
1297int lease_modify(struct file_lock **before, int arg, struct list_head *dispose) 1322int lease_modify(struct file_lock *fl, int arg, struct list_head *dispose)
1298{ 1323{
1299 struct file_lock *fl = *before; 1324 struct file_lock_context *flctx;
1300 int error = assign_type(fl, arg); 1325 int error = assign_type(fl, arg);
1301 1326
1302 if (error) 1327 if (error)
@@ -1306,6 +1331,7 @@ int lease_modify(struct file_lock **before, int arg, struct list_head *dispose)
1306 if (arg == F_UNLCK) { 1331 if (arg == F_UNLCK) {
1307 struct file *filp = fl->fl_file; 1332 struct file *filp = fl->fl_file;
1308 1333
1334 flctx = file_inode(filp)->i_flctx;
1309 f_delown(filp); 1335 f_delown(filp);
1310 filp->f_owner.signum = 0; 1336 filp->f_owner.signum = 0;
1311 fasync_helper(0, fl->fl_file, 0, &fl->fl_fasync); 1337 fasync_helper(0, fl->fl_file, 0, &fl->fl_fasync);
@@ -1313,7 +1339,7 @@ int lease_modify(struct file_lock **before, int arg, struct list_head *dispose)
1313 printk(KERN_ERR "locks_delete_lock: fasync == %p\n", fl->fl_fasync); 1339 printk(KERN_ERR "locks_delete_lock: fasync == %p\n", fl->fl_fasync);
1314 fl->fl_fasync = NULL; 1340 fl->fl_fasync = NULL;
1315 } 1341 }
1316 locks_delete_lock(before, dispose); 1342 locks_delete_lock_ctx(fl, &flctx->flc_lease_cnt, dispose);
1317 } 1343 }
1318 return 0; 1344 return 0;
1319} 1345}
@@ -1329,20 +1355,17 @@ static bool past_time(unsigned long then)
1329 1355
1330static void time_out_leases(struct inode *inode, struct list_head *dispose) 1356static void time_out_leases(struct inode *inode, struct list_head *dispose)
1331{ 1357{
1332 struct file_lock **before; 1358 struct file_lock_context *ctx = inode->i_flctx;
1333 struct file_lock *fl; 1359 struct file_lock *fl, *tmp;
1334 1360
1335 lockdep_assert_held(&inode->i_lock); 1361 lockdep_assert_held(&ctx->flc_lock);
1336 1362
1337 before = &inode->i_flock; 1363 list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list) {
1338 while ((fl = *before) && IS_LEASE(fl) && lease_breaking(fl)) {
1339 trace_time_out_leases(inode, fl); 1364 trace_time_out_leases(inode, fl);
1340 if (past_time(fl->fl_downgrade_time)) 1365 if (past_time(fl->fl_downgrade_time))
1341 lease_modify(before, F_RDLCK, dispose); 1366 lease_modify(fl, F_RDLCK, dispose);
1342 if (past_time(fl->fl_break_time)) 1367 if (past_time(fl->fl_break_time))
1343 lease_modify(before, F_UNLCK, dispose); 1368 lease_modify(fl, F_UNLCK, dispose);
1344 if (fl == *before) /* lease_modify may have freed fl */
1345 before = &fl->fl_next;
1346 } 1369 }
1347} 1370}
1348 1371
@@ -1356,11 +1379,12 @@ static bool leases_conflict(struct file_lock *lease, struct file_lock *breaker)
1356static bool 1379static bool
1357any_leases_conflict(struct inode *inode, struct file_lock *breaker) 1380any_leases_conflict(struct inode *inode, struct file_lock *breaker)
1358{ 1381{
1382 struct file_lock_context *ctx = inode->i_flctx;
1359 struct file_lock *fl; 1383 struct file_lock *fl;
1360 1384
1361 lockdep_assert_held(&inode->i_lock); 1385 lockdep_assert_held(&ctx->flc_lock);
1362 1386
1363 for (fl = inode->i_flock ; fl && IS_LEASE(fl); fl = fl->fl_next) { 1387 list_for_each_entry(fl, &ctx->flc_lease, fl_list) {
1364 if (leases_conflict(fl, breaker)) 1388 if (leases_conflict(fl, breaker))
1365 return true; 1389 return true;
1366 } 1390 }
@@ -1384,7 +1408,8 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
1384{ 1408{
1385 int error = 0; 1409 int error = 0;
1386 struct file_lock *new_fl; 1410 struct file_lock *new_fl;
1387 struct file_lock *fl, **before; 1411 struct file_lock_context *ctx = inode->i_flctx;
1412 struct file_lock *fl;
1388 unsigned long break_time; 1413 unsigned long break_time;
1389 int want_write = (mode & O_ACCMODE) != O_RDONLY; 1414 int want_write = (mode & O_ACCMODE) != O_RDONLY;
1390 LIST_HEAD(dispose); 1415 LIST_HEAD(dispose);
@@ -1394,7 +1419,13 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
1394 return PTR_ERR(new_fl); 1419 return PTR_ERR(new_fl);
1395 new_fl->fl_flags = type; 1420 new_fl->fl_flags = type;
1396 1421
1397 spin_lock(&inode->i_lock); 1422 /* typically we will check that ctx is non-NULL before calling */
1423 if (!ctx) {
1424 WARN_ON_ONCE(1);
1425 return error;
1426 }
1427
1428 spin_lock(&ctx->flc_lock);
1398 1429
1399 time_out_leases(inode, &dispose); 1430 time_out_leases(inode, &dispose);
1400 1431
@@ -1408,9 +1439,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
1408 break_time++; /* so that 0 means no break time */ 1439 break_time++; /* so that 0 means no break time */
1409 } 1440 }
1410 1441
1411 for (before = &inode->i_flock; 1442 list_for_each_entry(fl, &ctx->flc_lease, fl_list) {
1412 ((fl = *before) != NULL) && IS_LEASE(fl);
1413 before = &fl->fl_next) {
1414 if (!leases_conflict(fl, new_fl)) 1443 if (!leases_conflict(fl, new_fl))
1415 continue; 1444 continue;
1416 if (want_write) { 1445 if (want_write) {
@@ -1419,17 +1448,17 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
1419 fl->fl_flags |= FL_UNLOCK_PENDING; 1448 fl->fl_flags |= FL_UNLOCK_PENDING;
1420 fl->fl_break_time = break_time; 1449 fl->fl_break_time = break_time;
1421 } else { 1450 } else {
1422 if (lease_breaking(inode->i_flock)) 1451 if (lease_breaking(fl))
1423 continue; 1452 continue;
1424 fl->fl_flags |= FL_DOWNGRADE_PENDING; 1453 fl->fl_flags |= FL_DOWNGRADE_PENDING;
1425 fl->fl_downgrade_time = break_time; 1454 fl->fl_downgrade_time = break_time;
1426 } 1455 }
1427 if (fl->fl_lmops->lm_break(fl)) 1456 if (fl->fl_lmops->lm_break(fl))
1428 locks_delete_lock(before, &dispose); 1457 locks_delete_lock_ctx(fl, &ctx->flc_lease_cnt,
1458 &dispose);
1429 } 1459 }
1430 1460
1431 fl = inode->i_flock; 1461 if (list_empty(&ctx->flc_lease))
1432 if (!fl || !IS_LEASE(fl))
1433 goto out; 1462 goto out;
1434 1463
1435 if (mode & O_NONBLOCK) { 1464 if (mode & O_NONBLOCK) {
@@ -1439,18 +1468,19 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
1439 } 1468 }
1440 1469
1441restart: 1470restart:
1442 break_time = inode->i_flock->fl_break_time; 1471 fl = list_first_entry(&ctx->flc_lease, struct file_lock, fl_list);
1472 break_time = fl->fl_break_time;
1443 if (break_time != 0) 1473 if (break_time != 0)
1444 break_time -= jiffies; 1474 break_time -= jiffies;
1445 if (break_time == 0) 1475 if (break_time == 0)
1446 break_time++; 1476 break_time++;
1447 locks_insert_block(inode->i_flock, new_fl); 1477 locks_insert_block(fl, new_fl);
1448 trace_break_lease_block(inode, new_fl); 1478 trace_break_lease_block(inode, new_fl);
1449 spin_unlock(&inode->i_lock); 1479 spin_unlock(&ctx->flc_lock);
1450 locks_dispose_list(&dispose); 1480 locks_dispose_list(&dispose);
1451 error = wait_event_interruptible_timeout(new_fl->fl_wait, 1481 error = wait_event_interruptible_timeout(new_fl->fl_wait,
1452 !new_fl->fl_next, break_time); 1482 !new_fl->fl_next, break_time);
1453 spin_lock(&inode->i_lock); 1483 spin_lock(&ctx->flc_lock);
1454 trace_break_lease_unblock(inode, new_fl); 1484 trace_break_lease_unblock(inode, new_fl);
1455 locks_delete_block(new_fl); 1485 locks_delete_block(new_fl);
1456 if (error >= 0) { 1486 if (error >= 0) {
@@ -1462,12 +1492,10 @@ restart:
1462 time_out_leases(inode, &dispose); 1492 time_out_leases(inode, &dispose);
1463 if (any_leases_conflict(inode, new_fl)) 1493 if (any_leases_conflict(inode, new_fl))
1464 goto restart; 1494 goto restart;
1465
1466 error = 0; 1495 error = 0;
1467 } 1496 }
1468
1469out: 1497out:
1470 spin_unlock(&inode->i_lock); 1498 spin_unlock(&ctx->flc_lock);
1471 locks_dispose_list(&dispose); 1499 locks_dispose_list(&dispose);
1472 locks_free_lock(new_fl); 1500 locks_free_lock(new_fl);
1473 return error; 1501 return error;
@@ -1487,14 +1515,18 @@ EXPORT_SYMBOL(__break_lease);
1487void lease_get_mtime(struct inode *inode, struct timespec *time) 1515void lease_get_mtime(struct inode *inode, struct timespec *time)
1488{ 1516{
1489 bool has_lease = false; 1517 bool has_lease = false;
1490 struct file_lock *flock; 1518 struct file_lock_context *ctx = inode->i_flctx;
1519 struct file_lock *fl;
1491 1520
1492 if (inode->i_flock) { 1521 if (ctx && !list_empty_careful(&ctx->flc_lease)) {
1493 spin_lock(&inode->i_lock); 1522 spin_lock(&ctx->flc_lock);
1494 flock = inode->i_flock; 1523 if (!list_empty(&ctx->flc_lease)) {
1495 if (flock && IS_LEASE(flock) && (flock->fl_type == F_WRLCK)) 1524 fl = list_first_entry(&ctx->flc_lease,
1496 has_lease = true; 1525 struct file_lock, fl_list);
1497 spin_unlock(&inode->i_lock); 1526 if (fl->fl_type == F_WRLCK)
1527 has_lease = true;
1528 }
1529 spin_unlock(&ctx->flc_lock);
1498 } 1530 }
1499 1531
1500 if (has_lease) 1532 if (has_lease)
@@ -1532,20 +1564,22 @@ int fcntl_getlease(struct file *filp)
1532{ 1564{
1533 struct file_lock *fl; 1565 struct file_lock *fl;
1534 struct inode *inode = file_inode(filp); 1566 struct inode *inode = file_inode(filp);
1567 struct file_lock_context *ctx = inode->i_flctx;
1535 int type = F_UNLCK; 1568 int type = F_UNLCK;
1536 LIST_HEAD(dispose); 1569 LIST_HEAD(dispose);
1537 1570
1538 spin_lock(&inode->i_lock); 1571 if (ctx && !list_empty_careful(&ctx->flc_lease)) {
1539 time_out_leases(file_inode(filp), &dispose); 1572 spin_lock(&ctx->flc_lock);
1540 for (fl = file_inode(filp)->i_flock; fl && IS_LEASE(fl); 1573 time_out_leases(file_inode(filp), &dispose);
1541 fl = fl->fl_next) { 1574 list_for_each_entry(fl, &ctx->flc_lease, fl_list) {
1542 if (fl->fl_file == filp) { 1575 if (fl->fl_file != filp)
1576 continue;
1543 type = target_leasetype(fl); 1577 type = target_leasetype(fl);
1544 break; 1578 break;
1545 } 1579 }
1580 spin_unlock(&ctx->flc_lock);
1581 locks_dispose_list(&dispose);
1546 } 1582 }
1547 spin_unlock(&inode->i_lock);
1548 locks_dispose_list(&dispose);
1549 return type; 1583 return type;
1550} 1584}
1551 1585
@@ -1578,9 +1612,10 @@ check_conflicting_open(const struct dentry *dentry, const long arg)
1578static int 1612static int
1579generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **priv) 1613generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **priv)
1580{ 1614{
1581 struct file_lock *fl, **before, **my_before = NULL, *lease; 1615 struct file_lock *fl, *my_fl = NULL, *lease;
1582 struct dentry *dentry = filp->f_path.dentry; 1616 struct dentry *dentry = filp->f_path.dentry;
1583 struct inode *inode = dentry->d_inode; 1617 struct inode *inode = dentry->d_inode;
1618 struct file_lock_context *ctx;
1584 bool is_deleg = (*flp)->fl_flags & FL_DELEG; 1619 bool is_deleg = (*flp)->fl_flags & FL_DELEG;
1585 int error; 1620 int error;
1586 LIST_HEAD(dispose); 1621 LIST_HEAD(dispose);
@@ -1588,6 +1623,10 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
1588 lease = *flp; 1623 lease = *flp;
1589 trace_generic_add_lease(inode, lease); 1624 trace_generic_add_lease(inode, lease);
1590 1625
1626 ctx = locks_get_lock_context(inode);
1627 if (!ctx)
1628 return -ENOMEM;
1629
1591 /* 1630 /*
1592 * In the delegation case we need mutual exclusion with 1631 * In the delegation case we need mutual exclusion with
1593 * a number of operations that take the i_mutex. We trylock 1632 * a number of operations that take the i_mutex. We trylock
@@ -1606,7 +1645,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
1606 return -EINVAL; 1645 return -EINVAL;
1607 } 1646 }
1608 1647
1609 spin_lock(&inode->i_lock); 1648 spin_lock(&ctx->flc_lock);
1610 time_out_leases(inode, &dispose); 1649 time_out_leases(inode, &dispose);
1611 error = check_conflicting_open(dentry, arg); 1650 error = check_conflicting_open(dentry, arg);
1612 if (error) 1651 if (error)
@@ -1621,13 +1660,12 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
1621 * except for this filp. 1660 * except for this filp.
1622 */ 1661 */
1623 error = -EAGAIN; 1662 error = -EAGAIN;
1624 for (before = &inode->i_flock; 1663 list_for_each_entry(fl, &ctx->flc_lease, fl_list) {
1625 ((fl = *before) != NULL) && IS_LEASE(fl);
1626 before = &fl->fl_next) {
1627 if (fl->fl_file == filp) { 1664 if (fl->fl_file == filp) {
1628 my_before = before; 1665 my_fl = fl;
1629 continue; 1666 continue;
1630 } 1667 }
1668
1631 /* 1669 /*
1632 * No exclusive leases if someone else has a lease on 1670 * No exclusive leases if someone else has a lease on
1633 * this file: 1671 * this file:
@@ -1642,9 +1680,8 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
1642 goto out; 1680 goto out;
1643 } 1681 }
1644 1682
1645 if (my_before != NULL) { 1683 if (my_fl != NULL) {
1646 lease = *my_before; 1684 error = lease->fl_lmops->lm_change(my_fl, arg, &dispose);
1647 error = lease->fl_lmops->lm_change(my_before, arg, &dispose);
1648 if (error) 1685 if (error)
1649 goto out; 1686 goto out;
1650 goto out_setup; 1687 goto out_setup;
@@ -1654,7 +1691,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
1654 if (!leases_enable) 1691 if (!leases_enable)
1655 goto out; 1692 goto out;
1656 1693
1657 locks_insert_lock(before, lease); 1694 locks_insert_lock_ctx(lease, &ctx->flc_lease_cnt, &ctx->flc_lease);
1658 /* 1695 /*
1659 * The check in break_lease() is lockless. It's possible for another 1696 * The check in break_lease() is lockless. It's possible for another
1660 * open to race in after we did the earlier check for a conflicting 1697 * open to race in after we did the earlier check for a conflicting
@@ -1666,45 +1703,49 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
1666 */ 1703 */
1667 smp_mb(); 1704 smp_mb();
1668 error = check_conflicting_open(dentry, arg); 1705 error = check_conflicting_open(dentry, arg);
1669 if (error) 1706 if (error) {
1670 goto out_unlink; 1707 locks_unlink_lock_ctx(lease, &ctx->flc_lease_cnt);
1708 goto out;
1709 }
1671 1710
1672out_setup: 1711out_setup:
1673 if (lease->fl_lmops->lm_setup) 1712 if (lease->fl_lmops->lm_setup)
1674 lease->fl_lmops->lm_setup(lease, priv); 1713 lease->fl_lmops->lm_setup(lease, priv);
1675out: 1714out:
1676 spin_unlock(&inode->i_lock); 1715 spin_unlock(&ctx->flc_lock);
1677 locks_dispose_list(&dispose); 1716 locks_dispose_list(&dispose);
1678 if (is_deleg) 1717 if (is_deleg)
1679 mutex_unlock(&inode->i_mutex); 1718 mutex_unlock(&inode->i_mutex);
1680 if (!error && !my_before) 1719 if (!error && !my_fl)
1681 *flp = NULL; 1720 *flp = NULL;
1682 return error; 1721 return error;
1683out_unlink:
1684 locks_unlink_lock(before);
1685 goto out;
1686} 1722}
1687 1723
1688static int generic_delete_lease(struct file *filp) 1724static int generic_delete_lease(struct file *filp)
1689{ 1725{
1690 int error = -EAGAIN; 1726 int error = -EAGAIN;
1691 struct file_lock *fl, **before; 1727 struct file_lock *fl, *victim = NULL;
1692 struct dentry *dentry = filp->f_path.dentry; 1728 struct dentry *dentry = filp->f_path.dentry;
1693 struct inode *inode = dentry->d_inode; 1729 struct inode *inode = dentry->d_inode;
1730 struct file_lock_context *ctx = inode->i_flctx;
1694 LIST_HEAD(dispose); 1731 LIST_HEAD(dispose);
1695 1732
1696 spin_lock(&inode->i_lock); 1733 if (!ctx) {
1697 time_out_leases(inode, &dispose); 1734 trace_generic_delete_lease(inode, NULL);
1698 for (before = &inode->i_flock; 1735 return error;
1699 ((fl = *before) != NULL) && IS_LEASE(fl); 1736 }
1700 before = &fl->fl_next) { 1737
1701 if (fl->fl_file == filp) 1738 spin_lock(&ctx->flc_lock);
1739 list_for_each_entry(fl, &ctx->flc_lease, fl_list) {
1740 if (fl->fl_file == filp) {
1741 victim = fl;
1702 break; 1742 break;
1743 }
1703 } 1744 }
1704 trace_generic_delete_lease(inode, fl); 1745 trace_generic_delete_lease(inode, fl);
1705 if (fl) 1746 if (victim)
1706 error = fl->fl_lmops->lm_change(before, F_UNLCK, &dispose); 1747 error = fl->fl_lmops->lm_change(victim, F_UNLCK, &dispose);
1707 spin_unlock(&inode->i_lock); 1748 spin_unlock(&ctx->flc_lock);
1708 locks_dispose_list(&dispose); 1749 locks_dispose_list(&dispose);
1709 return error; 1750 return error;
1710} 1751}
@@ -2171,7 +2212,7 @@ again:
2171 */ 2212 */
2172 /* 2213 /*
2173 * we need that spin_lock here - it prevents reordering between 2214 * we need that spin_lock here - it prevents reordering between
2174 * update of inode->i_flock and check for it done in close(). 2215 * update of i_flctx->flc_posix and check for it done in close().
2175 * rcu_read_lock() wouldn't do. 2216 * rcu_read_lock() wouldn't do.
2176 */ 2217 */
2177 spin_lock(&current->files->file_lock); 2218 spin_lock(&current->files->file_lock);
@@ -2331,13 +2372,14 @@ out:
2331void locks_remove_posix(struct file *filp, fl_owner_t owner) 2372void locks_remove_posix(struct file *filp, fl_owner_t owner)
2332{ 2373{
2333 struct file_lock lock; 2374 struct file_lock lock;
2375 struct file_lock_context *ctx = file_inode(filp)->i_flctx;
2334 2376
2335 /* 2377 /*
2336 * If there are no locks held on this file, we don't need to call 2378 * If there are no locks held on this file, we don't need to call
2337 * posix_lock_file(). Another process could be setting a lock on this 2379 * posix_lock_file(). Another process could be setting a lock on this
2338 * file at the same time, but we wouldn't remove that lock anyway. 2380 * file at the same time, but we wouldn't remove that lock anyway.
2339 */ 2381 */
2340 if (!file_inode(filp)->i_flock) 2382 if (!ctx || list_empty(&ctx->flc_posix))
2341 return; 2383 return;
2342 2384
2343 lock.fl_type = F_UNLCK; 2385 lock.fl_type = F_UNLCK;
@@ -2358,67 +2400,67 @@ void locks_remove_posix(struct file *filp, fl_owner_t owner)
2358 2400
2359EXPORT_SYMBOL(locks_remove_posix); 2401EXPORT_SYMBOL(locks_remove_posix);
2360 2402
2403/* The i_flctx must be valid when calling into here */
2404static void
2405locks_remove_flock(struct file *filp)
2406{
2407 struct file_lock fl = {
2408 .fl_owner = filp,
2409 .fl_pid = current->tgid,
2410 .fl_file = filp,
2411 .fl_flags = FL_FLOCK,
2412 .fl_type = F_UNLCK,
2413 .fl_end = OFFSET_MAX,
2414 };
2415 struct file_lock_context *flctx = file_inode(filp)->i_flctx;
2416
2417 if (list_empty(&flctx->flc_flock))
2418 return;
2419
2420 if (filp->f_op->flock)
2421 filp->f_op->flock(filp, F_SETLKW, &fl);
2422 else
2423 flock_lock_file(filp, &fl);
2424
2425 if (fl.fl_ops && fl.fl_ops->fl_release_private)
2426 fl.fl_ops->fl_release_private(&fl);
2427}
2428
2429/* The i_flctx must be valid when calling into here */
2430static void
2431locks_remove_lease(struct file *filp)
2432{
2433 struct inode *inode = file_inode(filp);
2434 struct file_lock_context *ctx = inode->i_flctx;
2435 struct file_lock *fl, *tmp;
2436 LIST_HEAD(dispose);
2437
2438 if (list_empty(&ctx->flc_lease))
2439 return;
2440
2441 spin_lock(&ctx->flc_lock);
2442 list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list)
2443 lease_modify(fl, F_UNLCK, &dispose);
2444 spin_unlock(&ctx->flc_lock);
2445 locks_dispose_list(&dispose);
2446}
2447
2361/* 2448/*
2362 * This function is called on the last close of an open file. 2449 * This function is called on the last close of an open file.
2363 */ 2450 */
2364void locks_remove_file(struct file *filp) 2451void locks_remove_file(struct file *filp)
2365{ 2452{
2366 struct inode * inode = file_inode(filp); 2453 if (!file_inode(filp)->i_flctx)
2367 struct file_lock *fl;
2368 struct file_lock **before;
2369 LIST_HEAD(dispose);
2370
2371 if (!inode->i_flock)
2372 return; 2454 return;
2373 2455
2456 /* remove any OFD locks */
2374 locks_remove_posix(filp, filp); 2457 locks_remove_posix(filp, filp);
2375 2458
2376 if (filp->f_op->flock) { 2459 /* remove flock locks */
2377 struct file_lock fl = { 2460 locks_remove_flock(filp);
2378 .fl_owner = filp,
2379 .fl_pid = current->tgid,
2380 .fl_file = filp,
2381 .fl_flags = FL_FLOCK,
2382 .fl_type = F_UNLCK,
2383 .fl_end = OFFSET_MAX,
2384 };
2385 filp->f_op->flock(filp, F_SETLKW, &fl);
2386 if (fl.fl_ops && fl.fl_ops->fl_release_private)
2387 fl.fl_ops->fl_release_private(&fl);
2388 }
2389
2390 spin_lock(&inode->i_lock);
2391 before = &inode->i_flock;
2392
2393 while ((fl = *before) != NULL) {
2394 if (fl->fl_file == filp) {
2395 if (IS_LEASE(fl)) {
2396 lease_modify(before, F_UNLCK, &dispose);
2397 continue;
2398 }
2399
2400 /*
2401 * There's a leftover lock on the list of a type that
2402 * we didn't expect to see. Most likely a classic
2403 * POSIX lock that ended up not getting released
2404 * properly, or that raced onto the list somehow. Log
2405 * some info about it and then just remove it from
2406 * the list.
2407 */
2408 WARN(!IS_FLOCK(fl),
2409 "leftover lock: dev=%u:%u ino=%lu type=%hhd flags=0x%x start=%lld end=%lld\n",
2410 MAJOR(inode->i_sb->s_dev),
2411 MINOR(inode->i_sb->s_dev), inode->i_ino,
2412 fl->fl_type, fl->fl_flags,
2413 fl->fl_start, fl->fl_end);
2414 2461
2415 locks_delete_lock(before, &dispose); 2462 /* remove any leases */
2416 continue; 2463 locks_remove_lease(filp);
2417 }
2418 before = &fl->fl_next;
2419 }
2420 spin_unlock(&inode->i_lock);
2421 locks_dispose_list(&dispose);
2422} 2464}
2423 2465
2424/** 2466/**
@@ -2621,6 +2663,9 @@ static int __init filelock_init(void)
2621{ 2663{
2622 int i; 2664 int i;
2623 2665
2666 flctx_cache = kmem_cache_create("file_lock_ctx",
2667 sizeof(struct file_lock_context), 0, SLAB_PANIC, NULL);
2668
2624 filelock_cache = kmem_cache_create("file_lock_cache", 2669 filelock_cache = kmem_cache_create("file_lock_cache",
2625 sizeof(struct file_lock), 0, SLAB_PANIC, NULL); 2670 sizeof(struct file_lock), 0, SLAB_PANIC, NULL);
2626 2671
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index 7f3f60641344..8cdb2b28a104 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -85,25 +85,30 @@ static int nfs_delegation_claim_locks(struct nfs_open_context *ctx, struct nfs4_
85{ 85{
86 struct inode *inode = state->inode; 86 struct inode *inode = state->inode;
87 struct file_lock *fl; 87 struct file_lock *fl;
88 struct file_lock_context *flctx = inode->i_flctx;
89 struct list_head *list;
88 int status = 0; 90 int status = 0;
89 91
90 if (inode->i_flock == NULL) 92 if (flctx == NULL)
91 goto out; 93 goto out;
92 94
93 /* Protect inode->i_flock using the i_lock */ 95 list = &flctx->flc_posix;
94 spin_lock(&inode->i_lock); 96 spin_lock(&flctx->flc_lock);
95 for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { 97restart:
96 if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK))) 98 list_for_each_entry(fl, list, fl_list) {
97 continue;
98 if (nfs_file_open_context(fl->fl_file) != ctx) 99 if (nfs_file_open_context(fl->fl_file) != ctx)
99 continue; 100 continue;
100 spin_unlock(&inode->i_lock); 101 spin_unlock(&flctx->flc_lock);
101 status = nfs4_lock_delegation_recall(fl, state, stateid); 102 status = nfs4_lock_delegation_recall(fl, state, stateid);
102 if (status < 0) 103 if (status < 0)
103 goto out; 104 goto out;
104 spin_lock(&inode->i_lock); 105 spin_lock(&flctx->flc_lock);
105 } 106 }
106 spin_unlock(&inode->i_lock); 107 if (list == &flctx->flc_posix) {
108 list = &flctx->flc_flock;
109 goto restart;
110 }
111 spin_unlock(&flctx->flc_lock);
107out: 112out:
108 return status; 113 return status;
109} 114}
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 5194933ed419..a3bb22ab68c5 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -1366,49 +1366,55 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_
1366 struct nfs_inode *nfsi = NFS_I(inode); 1366 struct nfs_inode *nfsi = NFS_I(inode);
1367 struct file_lock *fl; 1367 struct file_lock *fl;
1368 int status = 0; 1368 int status = 0;
1369 struct file_lock_context *flctx = inode->i_flctx;
1370 struct list_head *list;
1369 1371
1370 if (inode->i_flock == NULL) 1372 if (flctx == NULL)
1371 return 0; 1373 return 0;
1372 1374
1375 list = &flctx->flc_posix;
1376
1373 /* Guard against delegation returns and new lock/unlock calls */ 1377 /* Guard against delegation returns and new lock/unlock calls */
1374 down_write(&nfsi->rwsem); 1378 down_write(&nfsi->rwsem);
1375 /* Protect inode->i_flock using the BKL */ 1379 spin_lock(&flctx->flc_lock);
1376 spin_lock(&inode->i_lock); 1380restart:
1377 for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { 1381 list_for_each_entry(fl, list, fl_list) {
1378 if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK)))
1379 continue;
1380 if (nfs_file_open_context(fl->fl_file)->state != state) 1382 if (nfs_file_open_context(fl->fl_file)->state != state)
1381 continue; 1383 continue;
1382 spin_unlock(&inode->i_lock); 1384 spin_unlock(&flctx->flc_lock);
1383 status = ops->recover_lock(state, fl); 1385 status = ops->recover_lock(state, fl);
1384 switch (status) { 1386 switch (status) {
1385 case 0: 1387 case 0:
1386 break; 1388 break;
1387 case -ESTALE: 1389 case -ESTALE:
1388 case -NFS4ERR_ADMIN_REVOKED: 1390 case -NFS4ERR_ADMIN_REVOKED:
1389 case -NFS4ERR_STALE_STATEID: 1391 case -NFS4ERR_STALE_STATEID:
1390 case -NFS4ERR_BAD_STATEID: 1392 case -NFS4ERR_BAD_STATEID:
1391 case -NFS4ERR_EXPIRED: 1393 case -NFS4ERR_EXPIRED:
1392 case -NFS4ERR_NO_GRACE: 1394 case -NFS4ERR_NO_GRACE:
1393 case -NFS4ERR_STALE_CLIENTID: 1395 case -NFS4ERR_STALE_CLIENTID:
1394 case -NFS4ERR_BADSESSION: 1396 case -NFS4ERR_BADSESSION:
1395 case -NFS4ERR_BADSLOT: 1397 case -NFS4ERR_BADSLOT:
1396 case -NFS4ERR_BAD_HIGH_SLOT: 1398 case -NFS4ERR_BAD_HIGH_SLOT:
1397 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: 1399 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1398 goto out; 1400 goto out;
1399 default: 1401 default:
1400 printk(KERN_ERR "NFS: %s: unhandled error %d\n", 1402 pr_err("NFS: %s: unhandled error %d\n",
1401 __func__, status); 1403 __func__, status);
1402 case -ENOMEM: 1404 case -ENOMEM:
1403 case -NFS4ERR_DENIED: 1405 case -NFS4ERR_DENIED:
1404 case -NFS4ERR_RECLAIM_BAD: 1406 case -NFS4ERR_RECLAIM_BAD:
1405 case -NFS4ERR_RECLAIM_CONFLICT: 1407 case -NFS4ERR_RECLAIM_CONFLICT:
1406 /* kill_proc(fl->fl_pid, SIGLOST, 1); */ 1408 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
1407 status = 0; 1409 status = 0;
1408 } 1410 }
1409 spin_lock(&inode->i_lock); 1411 spin_lock(&flctx->flc_lock);
1410 } 1412 }
1411 spin_unlock(&inode->i_lock); 1413 if (list == &flctx->flc_posix) {
1414 list = &flctx->flc_flock;
1415 goto restart;
1416 }
1417 spin_unlock(&flctx->flc_lock);
1412out: 1418out:
1413 up_write(&nfsi->rwsem); 1419 up_write(&nfsi->rwsem);
1414 return status; 1420 return status;
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index 2b5e769beb16..29c7f33c9cf1 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -826,11 +826,15 @@ static bool nfs_can_coalesce_requests(struct nfs_page *prev,
826 struct nfs_pageio_descriptor *pgio) 826 struct nfs_pageio_descriptor *pgio)
827{ 827{
828 size_t size; 828 size_t size;
829 struct file_lock_context *flctx;
829 830
830 if (prev) { 831 if (prev) {
831 if (!nfs_match_open_context(req->wb_context, prev->wb_context)) 832 if (!nfs_match_open_context(req->wb_context, prev->wb_context))
832 return false; 833 return false;
833 if (req->wb_context->dentry->d_inode->i_flock != NULL && 834 flctx = req->wb_context->dentry->d_inode->i_flctx;
835 if (flctx != NULL &&
836 !(list_empty_careful(&flctx->flc_posix) &&
837 list_empty_careful(&flctx->flc_flock)) &&
834 !nfs_match_lock_context(req->wb_lock_context, 838 !nfs_match_lock_context(req->wb_lock_context,
835 prev->wb_lock_context)) 839 prev->wb_lock_context))
836 return false; 840 return false;
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index af3af685a9e3..4ae66f416eb9 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -1091,6 +1091,7 @@ int nfs_flush_incompatible(struct file *file, struct page *page)
1091{ 1091{
1092 struct nfs_open_context *ctx = nfs_file_open_context(file); 1092 struct nfs_open_context *ctx = nfs_file_open_context(file);
1093 struct nfs_lock_context *l_ctx; 1093 struct nfs_lock_context *l_ctx;
1094 struct file_lock_context *flctx = file_inode(file)->i_flctx;
1094 struct nfs_page *req; 1095 struct nfs_page *req;
1095 int do_flush, status; 1096 int do_flush, status;
1096 /* 1097 /*
@@ -1109,7 +1110,9 @@ int nfs_flush_incompatible(struct file *file, struct page *page)
1109 do_flush = req->wb_page != page || req->wb_context != ctx; 1110 do_flush = req->wb_page != page || req->wb_context != ctx;
1110 /* for now, flush if more than 1 request in page_group */ 1111 /* for now, flush if more than 1 request in page_group */
1111 do_flush |= req->wb_this_page != req; 1112 do_flush |= req->wb_this_page != req;
1112 if (l_ctx && ctx->dentry->d_inode->i_flock != NULL) { 1113 if (l_ctx && flctx &&
1114 !(list_empty_careful(&flctx->flc_posix) &&
1115 list_empty_careful(&flctx->flc_flock))) {
1113 do_flush |= l_ctx->lockowner.l_owner != current->files 1116 do_flush |= l_ctx->lockowner.l_owner != current->files
1114 || l_ctx->lockowner.l_pid != current->tgid; 1117 || l_ctx->lockowner.l_pid != current->tgid;
1115 } 1118 }
@@ -1170,6 +1173,13 @@ out:
1170 return PageUptodate(page) != 0; 1173 return PageUptodate(page) != 0;
1171} 1174}
1172 1175
1176static bool
1177is_whole_file_wrlock(struct file_lock *fl)
1178{
1179 return fl->fl_start == 0 && fl->fl_end == OFFSET_MAX &&
1180 fl->fl_type == F_WRLCK;
1181}
1182
1173/* If we know the page is up to date, and we're not using byte range locks (or 1183/* If we know the page is up to date, and we're not using byte range locks (or
1174 * if we have the whole file locked for writing), it may be more efficient to 1184 * if we have the whole file locked for writing), it may be more efficient to
1175 * extend the write to cover the entire page in order to avoid fragmentation 1185 * extend the write to cover the entire page in order to avoid fragmentation
@@ -1180,17 +1190,36 @@ out:
1180 */ 1190 */
1181static int nfs_can_extend_write(struct file *file, struct page *page, struct inode *inode) 1191static int nfs_can_extend_write(struct file *file, struct page *page, struct inode *inode)
1182{ 1192{
1193 int ret;
1194 struct file_lock_context *flctx = inode->i_flctx;
1195 struct file_lock *fl;
1196
1183 if (file->f_flags & O_DSYNC) 1197 if (file->f_flags & O_DSYNC)
1184 return 0; 1198 return 0;
1185 if (!nfs_write_pageuptodate(page, inode)) 1199 if (!nfs_write_pageuptodate(page, inode))
1186 return 0; 1200 return 0;
1187 if (NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE)) 1201 if (NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE))
1188 return 1; 1202 return 1;
1189 if (inode->i_flock == NULL || (inode->i_flock->fl_start == 0 && 1203 if (!flctx || (list_empty_careful(&flctx->flc_flock) &&
1190 inode->i_flock->fl_end == OFFSET_MAX && 1204 list_empty_careful(&flctx->flc_posix)))
1191 inode->i_flock->fl_type != F_RDLCK)) 1205 return 0;
1192 return 1; 1206
1193 return 0; 1207 /* Check to see if there are whole file write locks */
1208 ret = 0;
1209 spin_lock(&flctx->flc_lock);
1210 if (!list_empty(&flctx->flc_posix)) {
1211 fl = list_first_entry(&flctx->flc_posix, struct file_lock,
1212 fl_list);
1213 if (is_whole_file_wrlock(fl))
1214 ret = 1;
1215 } else if (!list_empty(&flctx->flc_flock)) {
1216 fl = list_first_entry(&flctx->flc_flock, struct file_lock,
1217 fl_list);
1218 if (fl->fl_type == F_WRLCK)
1219 ret = 1;
1220 }
1221 spin_unlock(&flctx->flc_lock);
1222 return ret;
1194} 1223}
1195 1224
1196/* 1225/*
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 1f4b85b15125..370a53a5da13 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -3472,7 +3472,8 @@ nfsd_break_deleg_cb(struct file_lock *fl)
3472} 3472}
3473 3473
3474static int 3474static int
3475nfsd_change_deleg_cb(struct file_lock **onlist, int arg, struct list_head *dispose) 3475nfsd_change_deleg_cb(struct file_lock *onlist, int arg,
3476 struct list_head *dispose)
3476{ 3477{
3477 if (arg & F_UNLCK) 3478 if (arg & F_UNLCK)
3478 return lease_modify(onlist, arg, dispose); 3479 return lease_modify(onlist, arg, dispose);
@@ -5551,10 +5552,11 @@ out_nfserr:
5551static bool 5552static bool
5552check_for_locks(struct nfs4_file *fp, struct nfs4_lockowner *lowner) 5553check_for_locks(struct nfs4_file *fp, struct nfs4_lockowner *lowner)
5553{ 5554{
5554 struct file_lock **flpp; 5555 struct file_lock *fl;
5555 int status = false; 5556 int status = false;
5556 struct file *filp = find_any_file(fp); 5557 struct file *filp = find_any_file(fp);
5557 struct inode *inode; 5558 struct inode *inode;
5559 struct file_lock_context *flctx;
5558 5560
5559 if (!filp) { 5561 if (!filp) {
5560 /* Any valid lock stateid should have some sort of access */ 5562 /* Any valid lock stateid should have some sort of access */
@@ -5563,15 +5565,18 @@ check_for_locks(struct nfs4_file *fp, struct nfs4_lockowner *lowner)
5563 } 5565 }
5564 5566
5565 inode = file_inode(filp); 5567 inode = file_inode(filp);
5568 flctx = inode->i_flctx;
5566 5569
5567 spin_lock(&inode->i_lock); 5570 if (flctx && !list_empty_careful(&flctx->flc_posix)) {
5568 for (flpp = &inode->i_flock; *flpp != NULL; flpp = &(*flpp)->fl_next) { 5571 spin_lock(&flctx->flc_lock);
5569 if ((*flpp)->fl_owner == (fl_owner_t)lowner) { 5572 list_for_each_entry(fl, &flctx->flc_posix, fl_list) {
5570 status = true; 5573 if (fl->fl_owner == (fl_owner_t)lowner) {
5571 break; 5574 status = true;
5575 break;
5576 }
5572 } 5577 }
5578 spin_unlock(&flctx->flc_lock);
5573 } 5579 }
5574 spin_unlock(&inode->i_lock);
5575 fput(filp); 5580 fput(filp);
5576 return status; 5581 return status;
5577} 5582}
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index c991616acca9..bff8567aa42d 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -259,16 +259,15 @@ static ssize_t fanotify_read(struct file *file, char __user *buf,
259 struct fsnotify_event *kevent; 259 struct fsnotify_event *kevent;
260 char __user *start; 260 char __user *start;
261 int ret; 261 int ret;
262 DEFINE_WAIT(wait); 262 DEFINE_WAIT_FUNC(wait, woken_wake_function);
263 263
264 start = buf; 264 start = buf;
265 group = file->private_data; 265 group = file->private_data;
266 266
267 pr_debug("%s: group=%p\n", __func__, group); 267 pr_debug("%s: group=%p\n", __func__, group);
268 268
269 add_wait_queue(&group->notification_waitq, &wait);
269 while (1) { 270 while (1) {
270 prepare_to_wait(&group->notification_waitq, &wait, TASK_INTERRUPTIBLE);
271
272 mutex_lock(&group->notification_mutex); 271 mutex_lock(&group->notification_mutex);
273 kevent = get_one_event(group, count); 272 kevent = get_one_event(group, count);
274 mutex_unlock(&group->notification_mutex); 273 mutex_unlock(&group->notification_mutex);
@@ -289,7 +288,8 @@ static ssize_t fanotify_read(struct file *file, char __user *buf,
289 288
290 if (start != buf) 289 if (start != buf)
291 break; 290 break;
292 schedule(); 291
292 wait_woken(&wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
293 continue; 293 continue;
294 } 294 }
295 295
@@ -318,8 +318,8 @@ static ssize_t fanotify_read(struct file *file, char __user *buf,
318 buf += ret; 318 buf += ret;
319 count -= ret; 319 count -= ret;
320 } 320 }
321 remove_wait_queue(&group->notification_waitq, &wait);
321 322
322 finish_wait(&group->notification_waitq, &wait);
323 if (start != buf && ret != -EFAULT) 323 if (start != buf && ret != -EFAULT)
324 ret = buf - start; 324 ret = buf - start;
325 return ret; 325 return ret;
diff --git a/fs/ocfs2/dlm/dlmrecovery.c b/fs/ocfs2/dlm/dlmrecovery.c
index 79b5af5e6a7b..cecd875653e4 100644
--- a/fs/ocfs2/dlm/dlmrecovery.c
+++ b/fs/ocfs2/dlm/dlmrecovery.c
@@ -2023,11 +2023,8 @@ leave:
2023 dlm_lockres_drop_inflight_ref(dlm, res); 2023 dlm_lockres_drop_inflight_ref(dlm, res);
2024 spin_unlock(&res->spinlock); 2024 spin_unlock(&res->spinlock);
2025 2025
2026 if (ret < 0) { 2026 if (ret < 0)
2027 mlog_errno(ret); 2027 mlog_errno(ret);
2028 if (newlock)
2029 dlm_lock_put(newlock);
2030 }
2031 2028
2032 return ret; 2029 return ret;
2033} 2030}
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index b931e04e3388..914c121ec890 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -94,6 +94,14 @@ static int ocfs2_create_symlink_data(struct ocfs2_super *osb,
94 struct inode *inode, 94 struct inode *inode,
95 const char *symname); 95 const char *symname);
96 96
97static int ocfs2_double_lock(struct ocfs2_super *osb,
98 struct buffer_head **bh1,
99 struct inode *inode1,
100 struct buffer_head **bh2,
101 struct inode *inode2,
102 int rename);
103
104static void ocfs2_double_unlock(struct inode *inode1, struct inode *inode2);
97/* An orphan dir name is an 8 byte value, printed as a hex string */ 105/* An orphan dir name is an 8 byte value, printed as a hex string */
98#define OCFS2_ORPHAN_NAMELEN ((int)(2 * sizeof(u64))) 106#define OCFS2_ORPHAN_NAMELEN ((int)(2 * sizeof(u64)))
99 107
@@ -678,8 +686,10 @@ static int ocfs2_link(struct dentry *old_dentry,
678{ 686{
679 handle_t *handle; 687 handle_t *handle;
680 struct inode *inode = old_dentry->d_inode; 688 struct inode *inode = old_dentry->d_inode;
689 struct inode *old_dir = old_dentry->d_parent->d_inode;
681 int err; 690 int err;
682 struct buffer_head *fe_bh = NULL; 691 struct buffer_head *fe_bh = NULL;
692 struct buffer_head *old_dir_bh = NULL;
683 struct buffer_head *parent_fe_bh = NULL; 693 struct buffer_head *parent_fe_bh = NULL;
684 struct ocfs2_dinode *fe = NULL; 694 struct ocfs2_dinode *fe = NULL;
685 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); 695 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
@@ -696,19 +706,33 @@ static int ocfs2_link(struct dentry *old_dentry,
696 706
697 dquot_initialize(dir); 707 dquot_initialize(dir);
698 708
699 err = ocfs2_inode_lock_nested(dir, &parent_fe_bh, 1, OI_LS_PARENT); 709 err = ocfs2_double_lock(osb, &old_dir_bh, old_dir,
710 &parent_fe_bh, dir, 0);
700 if (err < 0) { 711 if (err < 0) {
701 if (err != -ENOENT) 712 if (err != -ENOENT)
702 mlog_errno(err); 713 mlog_errno(err);
703 return err; 714 return err;
704 } 715 }
705 716
717 /* make sure both dirs have bhs
718 * get an extra ref on old_dir_bh if old==new */
719 if (!parent_fe_bh) {
720 if (old_dir_bh) {
721 parent_fe_bh = old_dir_bh;
722 get_bh(parent_fe_bh);
723 } else {
724 mlog(ML_ERROR, "%s: no old_dir_bh!\n", osb->uuid_str);
725 err = -EIO;
726 goto out;
727 }
728 }
729
706 if (!dir->i_nlink) { 730 if (!dir->i_nlink) {
707 err = -ENOENT; 731 err = -ENOENT;
708 goto out; 732 goto out;
709 } 733 }
710 734
711 err = ocfs2_lookup_ino_from_name(dir, old_dentry->d_name.name, 735 err = ocfs2_lookup_ino_from_name(old_dir, old_dentry->d_name.name,
712 old_dentry->d_name.len, &old_de_ino); 736 old_dentry->d_name.len, &old_de_ino);
713 if (err) { 737 if (err) {
714 err = -ENOENT; 738 err = -ENOENT;
@@ -801,10 +825,11 @@ out_unlock_inode:
801 ocfs2_inode_unlock(inode, 1); 825 ocfs2_inode_unlock(inode, 1);
802 826
803out: 827out:
804 ocfs2_inode_unlock(dir, 1); 828 ocfs2_double_unlock(old_dir, dir);
805 829
806 brelse(fe_bh); 830 brelse(fe_bh);
807 brelse(parent_fe_bh); 831 brelse(parent_fe_bh);
832 brelse(old_dir_bh);
808 833
809 ocfs2_free_dir_lookup_result(&lookup); 834 ocfs2_free_dir_lookup_result(&lookup);
810 835
@@ -1072,14 +1097,15 @@ static int ocfs2_check_if_ancestor(struct ocfs2_super *osb,
1072} 1097}
1073 1098
1074/* 1099/*
1075 * The only place this should be used is rename! 1100 * The only place this should be used is rename and link!
1076 * if they have the same id, then the 1st one is the only one locked. 1101 * if they have the same id, then the 1st one is the only one locked.
1077 */ 1102 */
1078static int ocfs2_double_lock(struct ocfs2_super *osb, 1103static int ocfs2_double_lock(struct ocfs2_super *osb,
1079 struct buffer_head **bh1, 1104 struct buffer_head **bh1,
1080 struct inode *inode1, 1105 struct inode *inode1,
1081 struct buffer_head **bh2, 1106 struct buffer_head **bh2,
1082 struct inode *inode2) 1107 struct inode *inode2,
1108 int rename)
1083{ 1109{
1084 int status; 1110 int status;
1085 int inode1_is_ancestor, inode2_is_ancestor; 1111 int inode1_is_ancestor, inode2_is_ancestor;
@@ -1127,7 +1153,7 @@ static int ocfs2_double_lock(struct ocfs2_super *osb,
1127 } 1153 }
1128 /* lock id2 */ 1154 /* lock id2 */
1129 status = ocfs2_inode_lock_nested(inode2, bh2, 1, 1155 status = ocfs2_inode_lock_nested(inode2, bh2, 1,
1130 OI_LS_RENAME1); 1156 rename == 1 ? OI_LS_RENAME1 : OI_LS_PARENT);
1131 if (status < 0) { 1157 if (status < 0) {
1132 if (status != -ENOENT) 1158 if (status != -ENOENT)
1133 mlog_errno(status); 1159 mlog_errno(status);
@@ -1136,7 +1162,8 @@ static int ocfs2_double_lock(struct ocfs2_super *osb,
1136 } 1162 }
1137 1163
1138 /* lock id1 */ 1164 /* lock id1 */
1139 status = ocfs2_inode_lock_nested(inode1, bh1, 1, OI_LS_RENAME2); 1165 status = ocfs2_inode_lock_nested(inode1, bh1, 1,
1166 rename == 1 ? OI_LS_RENAME2 : OI_LS_PARENT);
1140 if (status < 0) { 1167 if (status < 0) {
1141 /* 1168 /*
1142 * An error return must mean that no cluster locks 1169 * An error return must mean that no cluster locks
@@ -1252,7 +1279,7 @@ static int ocfs2_rename(struct inode *old_dir,
1252 1279
1253 /* if old and new are the same, this'll just do one lock. */ 1280 /* if old and new are the same, this'll just do one lock. */
1254 status = ocfs2_double_lock(osb, &old_dir_bh, old_dir, 1281 status = ocfs2_double_lock(osb, &old_dir_bh, old_dir,
1255 &new_dir_bh, new_dir); 1282 &new_dir_bh, new_dir, 1);
1256 if (status < 0) { 1283 if (status < 0) {
1257 mlog_errno(status); 1284 mlog_errno(status);
1258 goto bail; 1285 goto bail;
diff --git a/fs/read_write.c b/fs/read_write.c
index c0805c93b6fa..4060691e78f7 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -358,7 +358,7 @@ int rw_verify_area(int read_write, struct file *file, const loff_t *ppos, size_t
358 return retval; 358 return retval;
359 } 359 }
360 360
361 if (unlikely(inode->i_flock && mandatory_lock(inode))) { 361 if (unlikely(inode->i_flctx && mandatory_lock(inode))) {
362 retval = locks_mandatory_area( 362 retval = locks_mandatory_area(
363 read_write == READ ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE, 363 read_write == READ ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE,
364 inode, file, pos, count); 364 inode, file, pos, count);
diff --git a/include/acpi/processor.h b/include/acpi/processor.h
index 3ca9b751f122..b95dc32a6e6b 100644
--- a/include/acpi/processor.h
+++ b/include/acpi/processor.h
@@ -196,8 +196,8 @@ struct acpi_processor_flags {
196struct acpi_processor { 196struct acpi_processor {
197 acpi_handle handle; 197 acpi_handle handle;
198 u32 acpi_id; 198 u32 acpi_id;
199 u32 apic_id; 199 u32 phys_id; /* CPU hardware ID such as APIC ID for x86 */
200 u32 id; 200 u32 id; /* CPU logical ID allocated by OS */
201 u32 pblk; 201 u32 pblk;
202 int performance_platform_limit; 202 int performance_platform_limit;
203 int throttling_platform_limit; 203 int throttling_platform_limit;
@@ -310,8 +310,8 @@ static inline int acpi_processor_get_bios_limit(int cpu, unsigned int *limit)
310#endif /* CONFIG_CPU_FREQ */ 310#endif /* CONFIG_CPU_FREQ */
311 311
312/* in processor_core.c */ 312/* in processor_core.c */
313int acpi_get_apicid(acpi_handle, int type, u32 acpi_id); 313int acpi_get_phys_id(acpi_handle, int type, u32 acpi_id);
314int acpi_map_cpuid(int apic_id, u32 acpi_id); 314int acpi_map_cpuid(int phys_id, u32 acpi_id);
315int acpi_get_cpuid(acpi_handle, int type, u32 acpi_id); 315int acpi_get_cpuid(acpi_handle, int type, u32 acpi_id);
316 316
317/* in processor_pdc.c */ 317/* in processor_pdc.c */
diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h
index 08848050922e..db284bff29dc 100644
--- a/include/asm-generic/tlb.h
+++ b/include/asm-generic/tlb.h
@@ -136,8 +136,12 @@ static inline void __tlb_adjust_range(struct mmu_gather *tlb,
136 136
137static inline void __tlb_reset_range(struct mmu_gather *tlb) 137static inline void __tlb_reset_range(struct mmu_gather *tlb)
138{ 138{
139 tlb->start = TASK_SIZE; 139 if (tlb->fullmm) {
140 tlb->end = 0; 140 tlb->start = tlb->end = ~0;
141 } else {
142 tlb->start = TASK_SIZE;
143 tlb->end = 0;
144 }
141} 145}
142 146
143/* 147/*
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 856d381b1d5b..d459cd17b477 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -147,8 +147,8 @@ void acpi_numa_arch_fixup(void);
147 147
148#ifdef CONFIG_ACPI_HOTPLUG_CPU 148#ifdef CONFIG_ACPI_HOTPLUG_CPU
149/* Arch dependent functions for cpu hotplug support */ 149/* Arch dependent functions for cpu hotplug support */
150int acpi_map_lsapic(acpi_handle handle, int physid, int *pcpu); 150int acpi_map_cpu(acpi_handle handle, int physid, int *pcpu);
151int acpi_unmap_lsapic(int cpu); 151int acpi_unmap_cpu(int cpu);
152#endif /* CONFIG_ACPI_HOTPLUG_CPU */ 152#endif /* CONFIG_ACPI_HOTPLUG_CPU */
153 153
154int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base); 154int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base);
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 8aded9ab2e4e..5735e7130d63 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -34,7 +34,6 @@ struct blk_mq_hw_ctx {
34 unsigned long flags; /* BLK_MQ_F_* flags */ 34 unsigned long flags; /* BLK_MQ_F_* flags */
35 35
36 struct request_queue *queue; 36 struct request_queue *queue;
37 unsigned int queue_num;
38 struct blk_flush_queue *fq; 37 struct blk_flush_queue *fq;
39 38
40 void *driver_data; 39 void *driver_data;
@@ -54,7 +53,7 @@ struct blk_mq_hw_ctx {
54 unsigned long dispatched[BLK_MQ_MAX_DISPATCH_ORDER]; 53 unsigned long dispatched[BLK_MQ_MAX_DISPATCH_ORDER];
55 54
56 unsigned int numa_node; 55 unsigned int numa_node;
57 unsigned int cmd_size; /* per-request extra data */ 56 unsigned int queue_num;
58 57
59 atomic_t nr_active; 58 atomic_t nr_active;
60 59
@@ -195,13 +194,16 @@ static inline u16 blk_mq_unique_tag_to_tag(u32 unique_tag)
195struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *, const int ctx_index); 194struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *, const int ctx_index);
196struct blk_mq_hw_ctx *blk_mq_alloc_single_hw_queue(struct blk_mq_tag_set *, unsigned int, int); 195struct blk_mq_hw_ctx *blk_mq_alloc_single_hw_queue(struct blk_mq_tag_set *, unsigned int, int);
197 196
197int blk_mq_request_started(struct request *rq);
198void blk_mq_start_request(struct request *rq); 198void blk_mq_start_request(struct request *rq);
199void blk_mq_end_request(struct request *rq, int error); 199void blk_mq_end_request(struct request *rq, int error);
200void __blk_mq_end_request(struct request *rq, int error); 200void __blk_mq_end_request(struct request *rq, int error);
201 201
202void blk_mq_requeue_request(struct request *rq); 202void blk_mq_requeue_request(struct request *rq);
203void blk_mq_add_to_requeue_list(struct request *rq, bool at_head); 203void blk_mq_add_to_requeue_list(struct request *rq, bool at_head);
204void blk_mq_cancel_requeue_work(struct request_queue *q);
204void blk_mq_kick_requeue_list(struct request_queue *q); 205void blk_mq_kick_requeue_list(struct request_queue *q);
206void blk_mq_abort_requeue_list(struct request_queue *q);
205void blk_mq_complete_request(struct request *rq); 207void blk_mq_complete_request(struct request *rq);
206 208
207void blk_mq_stop_hw_queue(struct blk_mq_hw_ctx *hctx); 209void blk_mq_stop_hw_queue(struct blk_mq_hw_ctx *hctx);
@@ -212,6 +214,8 @@ void blk_mq_start_stopped_hw_queues(struct request_queue *q, bool async);
212void blk_mq_delay_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs); 214void blk_mq_delay_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs);
213void blk_mq_tag_busy_iter(struct blk_mq_hw_ctx *hctx, busy_iter_fn *fn, 215void blk_mq_tag_busy_iter(struct blk_mq_hw_ctx *hctx, busy_iter_fn *fn,
214 void *priv); 216 void *priv);
217void blk_mq_unfreeze_queue(struct request_queue *q);
218void blk_mq_freeze_queue_start(struct request_queue *q);
215 219
216/* 220/*
217 * Driver command data is immediately after the request. So subtract request 221 * Driver command data is immediately after the request. So subtract request
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index 445d59231bc4..c294e3e25e37 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -190,6 +190,7 @@ enum rq_flag_bits {
190 __REQ_PM, /* runtime pm request */ 190 __REQ_PM, /* runtime pm request */
191 __REQ_HASHED, /* on IO scheduler merge hash */ 191 __REQ_HASHED, /* on IO scheduler merge hash */
192 __REQ_MQ_INFLIGHT, /* track inflight for MQ */ 192 __REQ_MQ_INFLIGHT, /* track inflight for MQ */
193 __REQ_NO_TIMEOUT, /* requests may never expire */
193 __REQ_NR_BITS, /* stops here */ 194 __REQ_NR_BITS, /* stops here */
194}; 195};
195 196
@@ -243,5 +244,6 @@ enum rq_flag_bits {
243#define REQ_PM (1ULL << __REQ_PM) 244#define REQ_PM (1ULL << __REQ_PM)
244#define REQ_HASHED (1ULL << __REQ_HASHED) 245#define REQ_HASHED (1ULL << __REQ_HASHED)
245#define REQ_MQ_INFLIGHT (1ULL << __REQ_MQ_INFLIGHT) 246#define REQ_MQ_INFLIGHT (1ULL << __REQ_MQ_INFLIGHT)
247#define REQ_NO_TIMEOUT (1ULL << __REQ_NO_TIMEOUT)
246 248
247#endif /* __LINUX_BLK_TYPES_H */ 249#endif /* __LINUX_BLK_TYPES_H */
diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h
index 5d86416d35f2..61b19c46bdb3 100644
--- a/include/linux/ceph/osd_client.h
+++ b/include/linux/ceph/osd_client.h
@@ -87,8 +87,8 @@ struct ceph_osd_req_op {
87 struct ceph_osd_data osd_data; 87 struct ceph_osd_data osd_data;
88 } extent; 88 } extent;
89 struct { 89 struct {
90 __le32 name_len; 90 u32 name_len;
91 __le32 value_len; 91 u32 value_len;
92 __u8 cmp_op; /* CEPH_OSD_CMPXATTR_OP_* */ 92 __u8 cmp_op; /* CEPH_OSD_CMPXATTR_OP_* */
93 __u8 cmp_mode; /* CEPH_OSD_CMPXATTR_MODE_* */ 93 __u8 cmp_mode; /* CEPH_OSD_CMPXATTR_MODE_* */
94 struct ceph_osd_data osd_data; 94 struct ceph_osd_data osd_data;
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index a1c81f80978e..33063f872ee3 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -215,7 +215,7 @@ static __always_inline void __read_once_size(volatile void *p, void *res, int si
215 } 215 }
216} 216}
217 217
218static __always_inline void __assign_once_size(volatile void *p, void *res, int size) 218static __always_inline void __write_once_size(volatile void *p, void *res, int size)
219{ 219{
220 switch (size) { 220 switch (size) {
221 case 1: *(volatile __u8 *)p = *(__u8 *)res; break; 221 case 1: *(volatile __u8 *)p = *(__u8 *)res; break;
@@ -235,15 +235,15 @@ static __always_inline void __assign_once_size(volatile void *p, void *res, int
235/* 235/*
236 * Prevent the compiler from merging or refetching reads or writes. The 236 * Prevent the compiler from merging or refetching reads or writes. The
237 * compiler is also forbidden from reordering successive instances of 237 * compiler is also forbidden from reordering successive instances of
238 * READ_ONCE, ASSIGN_ONCE and ACCESS_ONCE (see below), but only when the 238 * READ_ONCE, WRITE_ONCE and ACCESS_ONCE (see below), but only when the
239 * compiler is aware of some particular ordering. One way to make the 239 * compiler is aware of some particular ordering. One way to make the
240 * compiler aware of ordering is to put the two invocations of READ_ONCE, 240 * compiler aware of ordering is to put the two invocations of READ_ONCE,
241 * ASSIGN_ONCE or ACCESS_ONCE() in different C statements. 241 * WRITE_ONCE or ACCESS_ONCE() in different C statements.
242 * 242 *
243 * In contrast to ACCESS_ONCE these two macros will also work on aggregate 243 * In contrast to ACCESS_ONCE these two macros will also work on aggregate
244 * data types like structs or unions. If the size of the accessed data 244 * data types like structs or unions. If the size of the accessed data
245 * type exceeds the word size of the machine (e.g., 32 bits or 64 bits) 245 * type exceeds the word size of the machine (e.g., 32 bits or 64 bits)
246 * READ_ONCE() and ASSIGN_ONCE() will fall back to memcpy and print a 246 * READ_ONCE() and WRITE_ONCE() will fall back to memcpy and print a
247 * compile-time warning. 247 * compile-time warning.
248 * 248 *
249 * Their two major use cases are: (1) Mediating communication between 249 * Their two major use cases are: (1) Mediating communication between
@@ -257,8 +257,8 @@ static __always_inline void __assign_once_size(volatile void *p, void *res, int
257#define READ_ONCE(x) \ 257#define READ_ONCE(x) \
258 ({ typeof(x) __val; __read_once_size(&x, &__val, sizeof(__val)); __val; }) 258 ({ typeof(x) __val; __read_once_size(&x, &__val, sizeof(__val)); __val; })
259 259
260#define ASSIGN_ONCE(val, x) \ 260#define WRITE_ONCE(x, val) \
261 ({ typeof(x) __val; __val = val; __assign_once_size(&x, &__val, sizeof(__val)); __val; }) 261 ({ typeof(x) __val; __val = val; __write_once_size(&x, &__val, sizeof(__val)); __val; })
262 262
263#endif /* __KERNEL__ */ 263#endif /* __KERNEL__ */
264 264
diff --git a/include/linux/fs.h b/include/linux/fs.h
index f90c0282c114..ddd2fa7cefd3 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -135,7 +135,7 @@ typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
135#define FMODE_CAN_WRITE ((__force fmode_t)0x40000) 135#define FMODE_CAN_WRITE ((__force fmode_t)0x40000)
136 136
137/* File was opened by fanotify and shouldn't generate fanotify events */ 137/* File was opened by fanotify and shouldn't generate fanotify events */
138#define FMODE_NONOTIFY ((__force fmode_t)0x1000000) 138#define FMODE_NONOTIFY ((__force fmode_t)0x4000000)
139 139
140/* 140/*
141 * Flag for rw_copy_check_uvector and compat_rw_copy_check_uvector 141 * Flag for rw_copy_check_uvector and compat_rw_copy_check_uvector
@@ -625,7 +625,7 @@ struct inode {
625 atomic_t i_readcount; /* struct files open RO */ 625 atomic_t i_readcount; /* struct files open RO */
626#endif 626#endif
627 const struct file_operations *i_fop; /* former ->i_op->default_file_ops */ 627 const struct file_operations *i_fop; /* former ->i_op->default_file_ops */
628 struct file_lock *i_flock; 628 struct file_lock_context *i_flctx;
629 struct address_space i_data; 629 struct address_space i_data;
630 struct list_head i_devices; 630 struct list_head i_devices;
631 union { 631 union {
@@ -885,6 +885,8 @@ static inline struct file *get_file(struct file *f)
885/* legacy typedef, should eventually be removed */ 885/* legacy typedef, should eventually be removed */
886typedef void *fl_owner_t; 886typedef void *fl_owner_t;
887 887
888struct file_lock;
889
888struct file_lock_operations { 890struct file_lock_operations {
889 void (*fl_copy_lock)(struct file_lock *, struct file_lock *); 891 void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
890 void (*fl_release_private)(struct file_lock *); 892 void (*fl_release_private)(struct file_lock *);
@@ -898,7 +900,7 @@ struct lock_manager_operations {
898 void (*lm_notify)(struct file_lock *); /* unblock callback */ 900 void (*lm_notify)(struct file_lock *); /* unblock callback */
899 int (*lm_grant)(struct file_lock *, int); 901 int (*lm_grant)(struct file_lock *, int);
900 bool (*lm_break)(struct file_lock *); 902 bool (*lm_break)(struct file_lock *);
901 int (*lm_change)(struct file_lock **, int, struct list_head *); 903 int (*lm_change)(struct file_lock *, int, struct list_head *);
902 void (*lm_setup)(struct file_lock *, void **); 904 void (*lm_setup)(struct file_lock *, void **);
903}; 905};
904 906
@@ -923,17 +925,17 @@ int locks_in_grace(struct net *);
923 * FIXME: should we create a separate "struct lock_request" to help distinguish 925 * FIXME: should we create a separate "struct lock_request" to help distinguish
924 * these two uses? 926 * these two uses?
925 * 927 *
926 * The i_flock list is ordered by: 928 * The varous i_flctx lists are ordered by:
927 * 929 *
928 * 1) lock type -- FL_LEASEs first, then FL_FLOCK, and finally FL_POSIX 930 * 1) lock owner
929 * 2) lock owner 931 * 2) lock range start
930 * 3) lock range start 932 * 3) lock range end
931 * 4) lock range end
932 * 933 *
933 * Obviously, the last two criteria only matter for POSIX locks. 934 * Obviously, the last two criteria only matter for POSIX locks.
934 */ 935 */
935struct file_lock { 936struct file_lock {
936 struct file_lock *fl_next; /* singly linked list for this inode */ 937 struct file_lock *fl_next; /* singly linked list for this inode */
938 struct list_head fl_list; /* link into file_lock_context */
937 struct hlist_node fl_link; /* node in global lists */ 939 struct hlist_node fl_link; /* node in global lists */
938 struct list_head fl_block; /* circular list of blocked processes */ 940 struct list_head fl_block; /* circular list of blocked processes */
939 fl_owner_t fl_owner; 941 fl_owner_t fl_owner;
@@ -964,6 +966,16 @@ struct file_lock {
964 } fl_u; 966 } fl_u;
965}; 967};
966 968
969struct file_lock_context {
970 spinlock_t flc_lock;
971 struct list_head flc_flock;
972 struct list_head flc_posix;
973 struct list_head flc_lease;
974 int flc_flock_cnt;
975 int flc_posix_cnt;
976 int flc_lease_cnt;
977};
978
967/* The following constant reflects the upper bound of the file/locking space */ 979/* The following constant reflects the upper bound of the file/locking space */
968#ifndef OFFSET_MAX 980#ifndef OFFSET_MAX
969#define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1))) 981#define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))
@@ -990,6 +1002,7 @@ extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
990extern int fcntl_getlease(struct file *filp); 1002extern int fcntl_getlease(struct file *filp);
991 1003
992/* fs/locks.c */ 1004/* fs/locks.c */
1005void locks_free_lock_context(struct file_lock_context *ctx);
993void locks_free_lock(struct file_lock *fl); 1006void locks_free_lock(struct file_lock *fl);
994extern void locks_init_lock(struct file_lock *); 1007extern void locks_init_lock(struct file_lock *);
995extern struct file_lock * locks_alloc_lock(void); 1008extern struct file_lock * locks_alloc_lock(void);
@@ -1010,7 +1023,7 @@ extern int __break_lease(struct inode *inode, unsigned int flags, unsigned int t
1010extern void lease_get_mtime(struct inode *, struct timespec *time); 1023extern void lease_get_mtime(struct inode *, struct timespec *time);
1011extern int generic_setlease(struct file *, long, struct file_lock **, void **priv); 1024extern int generic_setlease(struct file *, long, struct file_lock **, void **priv);
1012extern int vfs_setlease(struct file *, long, struct file_lock **, void **); 1025extern int vfs_setlease(struct file *, long, struct file_lock **, void **);
1013extern int lease_modify(struct file_lock **, int, struct list_head *); 1026extern int lease_modify(struct file_lock *, int, struct list_head *);
1014#else /* !CONFIG_FILE_LOCKING */ 1027#else /* !CONFIG_FILE_LOCKING */
1015static inline int fcntl_getlk(struct file *file, unsigned int cmd, 1028static inline int fcntl_getlk(struct file *file, unsigned int cmd,
1016 struct flock __user *user) 1029 struct flock __user *user)
@@ -1047,6 +1060,11 @@ static inline int fcntl_getlease(struct file *filp)
1047 return F_UNLCK; 1060 return F_UNLCK;
1048} 1061}
1049 1062
1063static inline void
1064locks_free_lock_context(struct file_lock_context *ctx)
1065{
1066}
1067
1050static inline void locks_init_lock(struct file_lock *fl) 1068static inline void locks_init_lock(struct file_lock *fl)
1051{ 1069{
1052 return; 1070 return;
@@ -1137,7 +1155,7 @@ static inline int vfs_setlease(struct file *filp, long arg,
1137 return -EINVAL; 1155 return -EINVAL;
1138} 1156}
1139 1157
1140static inline int lease_modify(struct file_lock **before, int arg, 1158static inline int lease_modify(struct file_lock *fl, int arg,
1141 struct list_head *dispose) 1159 struct list_head *dispose)
1142{ 1160{
1143 return -EINVAL; 1161 return -EINVAL;
@@ -1959,7 +1977,7 @@ static inline int locks_verify_truncate(struct inode *inode,
1959 struct file *filp, 1977 struct file *filp,
1960 loff_t size) 1978 loff_t size)
1961{ 1979{
1962 if (inode->i_flock && mandatory_lock(inode)) 1980 if (inode->i_flctx && mandatory_lock(inode))
1963 return locks_mandatory_area( 1981 return locks_mandatory_area(
1964 FLOCK_VERIFY_WRITE, inode, filp, 1982 FLOCK_VERIFY_WRITE, inode, filp,
1965 size < inode->i_size ? size : inode->i_size, 1983 size < inode->i_size ? size : inode->i_size,
@@ -1973,11 +1991,12 @@ static inline int break_lease(struct inode *inode, unsigned int mode)
1973{ 1991{
1974 /* 1992 /*
1975 * Since this check is lockless, we must ensure that any refcounts 1993 * Since this check is lockless, we must ensure that any refcounts
1976 * taken are done before checking inode->i_flock. Otherwise, we could 1994 * taken are done before checking i_flctx->flc_lease. Otherwise, we
1977 * end up racing with tasks trying to set a new lease on this file. 1995 * could end up racing with tasks trying to set a new lease on this
1996 * file.
1978 */ 1997 */
1979 smp_mb(); 1998 smp_mb();
1980 if (inode->i_flock) 1999 if (inode->i_flctx && !list_empty_careful(&inode->i_flctx->flc_lease))
1981 return __break_lease(inode, mode, FL_LEASE); 2000 return __break_lease(inode, mode, FL_LEASE);
1982 return 0; 2001 return 0;
1983} 2002}
@@ -1986,11 +2005,12 @@ static inline int break_deleg(struct inode *inode, unsigned int mode)
1986{ 2005{
1987 /* 2006 /*
1988 * Since this check is lockless, we must ensure that any refcounts 2007 * Since this check is lockless, we must ensure that any refcounts
1989 * taken are done before checking inode->i_flock. Otherwise, we could 2008 * taken are done before checking i_flctx->flc_lease. Otherwise, we
1990 * end up racing with tasks trying to set a new lease on this file. 2009 * could end up racing with tasks trying to set a new lease on this
2010 * file.
1991 */ 2011 */
1992 smp_mb(); 2012 smp_mb();
1993 if (inode->i_flock) 2013 if (inode->i_flctx && !list_empty_careful(&inode->i_flctx->flc_lease))
1994 return __break_lease(inode, mode, FL_DELEG); 2014 return __break_lease(inode, mode, FL_DELEG);
1995 return 0; 2015 return 0;
1996} 2016}
diff --git a/include/linux/kdb.h b/include/linux/kdb.h
index 290db1269c4c..75ae2e2631fc 100644
--- a/include/linux/kdb.h
+++ b/include/linux/kdb.h
@@ -13,11 +13,54 @@
13 * Copyright (C) 2009 Jason Wessel <jason.wessel@windriver.com> 13 * Copyright (C) 2009 Jason Wessel <jason.wessel@windriver.com>
14 */ 14 */
15 15
16/* Shifted versions of the command enable bits are be used if the command
17 * has no arguments (see kdb_check_flags). This allows commands, such as
18 * go, to have different permissions depending upon whether it is called
19 * with an argument.
20 */
21#define KDB_ENABLE_NO_ARGS_SHIFT 10
22
16typedef enum { 23typedef enum {
17 KDB_REPEAT_NONE = 0, /* Do not repeat this command */ 24 KDB_ENABLE_ALL = (1 << 0), /* Enable everything */
18 KDB_REPEAT_NO_ARGS, /* Repeat the command without arguments */ 25 KDB_ENABLE_MEM_READ = (1 << 1),
19 KDB_REPEAT_WITH_ARGS, /* Repeat the command including its arguments */ 26 KDB_ENABLE_MEM_WRITE = (1 << 2),
20} kdb_repeat_t; 27 KDB_ENABLE_REG_READ = (1 << 3),
28 KDB_ENABLE_REG_WRITE = (1 << 4),
29 KDB_ENABLE_INSPECT = (1 << 5),
30 KDB_ENABLE_FLOW_CTRL = (1 << 6),
31 KDB_ENABLE_SIGNAL = (1 << 7),
32 KDB_ENABLE_REBOOT = (1 << 8),
33 /* User exposed values stop here, all remaining flags are
34 * exclusively used to describe a commands behaviour.
35 */
36
37 KDB_ENABLE_ALWAYS_SAFE = (1 << 9),
38 KDB_ENABLE_MASK = (1 << KDB_ENABLE_NO_ARGS_SHIFT) - 1,
39
40 KDB_ENABLE_ALL_NO_ARGS = KDB_ENABLE_ALL << KDB_ENABLE_NO_ARGS_SHIFT,
41 KDB_ENABLE_MEM_READ_NO_ARGS = KDB_ENABLE_MEM_READ
42 << KDB_ENABLE_NO_ARGS_SHIFT,
43 KDB_ENABLE_MEM_WRITE_NO_ARGS = KDB_ENABLE_MEM_WRITE
44 << KDB_ENABLE_NO_ARGS_SHIFT,
45 KDB_ENABLE_REG_READ_NO_ARGS = KDB_ENABLE_REG_READ
46 << KDB_ENABLE_NO_ARGS_SHIFT,
47 KDB_ENABLE_REG_WRITE_NO_ARGS = KDB_ENABLE_REG_WRITE
48 << KDB_ENABLE_NO_ARGS_SHIFT,
49 KDB_ENABLE_INSPECT_NO_ARGS = KDB_ENABLE_INSPECT
50 << KDB_ENABLE_NO_ARGS_SHIFT,
51 KDB_ENABLE_FLOW_CTRL_NO_ARGS = KDB_ENABLE_FLOW_CTRL
52 << KDB_ENABLE_NO_ARGS_SHIFT,
53 KDB_ENABLE_SIGNAL_NO_ARGS = KDB_ENABLE_SIGNAL
54 << KDB_ENABLE_NO_ARGS_SHIFT,
55 KDB_ENABLE_REBOOT_NO_ARGS = KDB_ENABLE_REBOOT
56 << KDB_ENABLE_NO_ARGS_SHIFT,
57 KDB_ENABLE_ALWAYS_SAFE_NO_ARGS = KDB_ENABLE_ALWAYS_SAFE
58 << KDB_ENABLE_NO_ARGS_SHIFT,
59 KDB_ENABLE_MASK_NO_ARGS = KDB_ENABLE_MASK << KDB_ENABLE_NO_ARGS_SHIFT,
60
61 KDB_REPEAT_NO_ARGS = 0x40000000, /* Repeat the command w/o arguments */
62 KDB_REPEAT_WITH_ARGS = 0x80000000, /* Repeat the command with args */
63} kdb_cmdflags_t;
21 64
22typedef int (*kdb_func_t)(int, const char **); 65typedef int (*kdb_func_t)(int, const char **);
23 66
@@ -62,6 +105,7 @@ extern atomic_t kdb_event;
62#define KDB_BADLENGTH (-19) 105#define KDB_BADLENGTH (-19)
63#define KDB_NOBP (-20) 106#define KDB_NOBP (-20)
64#define KDB_BADADDR (-21) 107#define KDB_BADADDR (-21)
108#define KDB_NOPERM (-22)
65 109
66/* 110/*
67 * kdb_diemsg 111 * kdb_diemsg
@@ -146,17 +190,17 @@ static inline const char *kdb_walk_kallsyms(loff_t *pos)
146 190
147/* Dynamic kdb shell command registration */ 191/* Dynamic kdb shell command registration */
148extern int kdb_register(char *, kdb_func_t, char *, char *, short); 192extern int kdb_register(char *, kdb_func_t, char *, char *, short);
149extern int kdb_register_repeat(char *, kdb_func_t, char *, char *, 193extern int kdb_register_flags(char *, kdb_func_t, char *, char *,
150 short, kdb_repeat_t); 194 short, kdb_cmdflags_t);
151extern int kdb_unregister(char *); 195extern int kdb_unregister(char *);
152#else /* ! CONFIG_KGDB_KDB */ 196#else /* ! CONFIG_KGDB_KDB */
153static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; } 197static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; }
154static inline void kdb_init(int level) {} 198static inline void kdb_init(int level) {}
155static inline int kdb_register(char *cmd, kdb_func_t func, char *usage, 199static inline int kdb_register(char *cmd, kdb_func_t func, char *usage,
156 char *help, short minlen) { return 0; } 200 char *help, short minlen) { return 0; }
157static inline int kdb_register_repeat(char *cmd, kdb_func_t func, char *usage, 201static inline int kdb_register_flags(char *cmd, kdb_func_t func, char *usage,
158 char *help, short minlen, 202 char *help, short minlen,
159 kdb_repeat_t repeat) { return 0; } 203 kdb_cmdflags_t flags) { return 0; }
160static inline int kdb_unregister(char *cmd) { return 0; } 204static inline int kdb_unregister(char *cmd) { return 0; }
161#endif /* CONFIG_KGDB_KDB */ 205#endif /* CONFIG_KGDB_KDB */
162enum { 206enum {
diff --git a/include/linux/mm.h b/include/linux/mm.h
index f80d0194c9bc..80fc92a49649 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1952,7 +1952,7 @@ extern int expand_downwards(struct vm_area_struct *vma,
1952#if VM_GROWSUP 1952#if VM_GROWSUP
1953extern int expand_upwards(struct vm_area_struct *vma, unsigned long address); 1953extern int expand_upwards(struct vm_area_struct *vma, unsigned long address);
1954#else 1954#else
1955 #define expand_upwards(vma, address) do { } while (0) 1955 #define expand_upwards(vma, address) (0)
1956#endif 1956#endif
1957 1957
1958/* Look up the first VMA which satisfies addr < vm_end, NULL if none. */ 1958/* Look up the first VMA which satisfies addr < vm_end, NULL if none. */
diff --git a/include/linux/mmc/sdhci.h b/include/linux/mmc/sdhci.h
index 375af80bde7d..f767a0de611f 100644
--- a/include/linux/mmc/sdhci.h
+++ b/include/linux/mmc/sdhci.h
@@ -137,6 +137,7 @@ struct sdhci_host {
137#define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */ 137#define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */
138#define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */ 138#define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */
139#define SDHCI_USE_64_BIT_DMA (1<<12) /* Use 64-bit DMA */ 139#define SDHCI_USE_64_BIT_DMA (1<<12) /* Use 64-bit DMA */
140#define SDHCI_HS400_TUNING (1<<13) /* Tuning for HS400 */
140 141
141 unsigned int version; /* SDHCI spec. version */ 142 unsigned int version; /* SDHCI spec. version */
142 143
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 679e6e90aa4c..52fd8e8694cf 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -852,11 +852,11 @@ typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
852 * 3. Update dev->stats asynchronously and atomically, and define 852 * 3. Update dev->stats asynchronously and atomically, and define
853 * neither operation. 853 * neither operation.
854 * 854 *
855 * int (*ndo_vlan_rx_add_vid)(struct net_device *dev, __be16 proto, u16t vid); 855 * int (*ndo_vlan_rx_add_vid)(struct net_device *dev, __be16 proto, u16 vid);
856 * If device support VLAN filtering this function is called when a 856 * If device support VLAN filtering this function is called when a
857 * VLAN id is registered. 857 * VLAN id is registered.
858 * 858 *
859 * int (*ndo_vlan_rx_kill_vid)(struct net_device *dev, unsigned short vid); 859 * int (*ndo_vlan_rx_kill_vid)(struct net_device *dev, __be16 proto, u16 vid);
860 * If device support VLAN filtering this function is called when a 860 * If device support VLAN filtering this function is called when a
861 * VLAN id is unregistered. 861 * VLAN id is unregistered.
862 * 862 *
@@ -2085,7 +2085,7 @@ extern rwlock_t dev_base_lock; /* Device list lock */
2085 list_for_each_entry_continue_rcu(d, &(net)->dev_base_head, dev_list) 2085 list_for_each_entry_continue_rcu(d, &(net)->dev_base_head, dev_list)
2086#define for_each_netdev_in_bond_rcu(bond, slave) \ 2086#define for_each_netdev_in_bond_rcu(bond, slave) \
2087 for_each_netdev_rcu(&init_net, slave) \ 2087 for_each_netdev_rcu(&init_net, slave) \
2088 if (netdev_master_upper_dev_get_rcu(slave) == bond) 2088 if (netdev_master_upper_dev_get_rcu(slave) == (bond))
2089#define net_device_entry(lh) list_entry(lh, struct net_device, dev_list) 2089#define net_device_entry(lh) list_entry(lh, struct net_device, dev_list)
2090 2090
2091static inline struct net_device *next_net_device(struct net_device *dev) 2091static inline struct net_device *next_net_device(struct net_device *dev)
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 486e84ccb1f9..4f7a61ca4b39 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -79,11 +79,6 @@ struct perf_branch_stack {
79 struct perf_branch_entry entries[0]; 79 struct perf_branch_entry entries[0];
80}; 80};
81 81
82struct perf_regs {
83 __u64 abi;
84 struct pt_regs *regs;
85};
86
87struct task_struct; 82struct task_struct;
88 83
89/* 84/*
@@ -610,7 +605,14 @@ struct perf_sample_data {
610 u32 reserved; 605 u32 reserved;
611 } cpu_entry; 606 } cpu_entry;
612 struct perf_callchain_entry *callchain; 607 struct perf_callchain_entry *callchain;
608
609 /*
610 * regs_user may point to task_pt_regs or to regs_user_copy, depending
611 * on arch details.
612 */
613 struct perf_regs regs_user; 613 struct perf_regs regs_user;
614 struct pt_regs regs_user_copy;
615
614 struct perf_regs regs_intr; 616 struct perf_regs regs_intr;
615 u64 stack_user_size; 617 u64 stack_user_size;
616} ____cacheline_aligned; 618} ____cacheline_aligned;
diff --git a/include/linux/perf_regs.h b/include/linux/perf_regs.h
index 3c73d5fe18be..a5f98d53d732 100644
--- a/include/linux/perf_regs.h
+++ b/include/linux/perf_regs.h
@@ -1,11 +1,19 @@
1#ifndef _LINUX_PERF_REGS_H 1#ifndef _LINUX_PERF_REGS_H
2#define _LINUX_PERF_REGS_H 2#define _LINUX_PERF_REGS_H
3 3
4struct perf_regs {
5 __u64 abi;
6 struct pt_regs *regs;
7};
8
4#ifdef CONFIG_HAVE_PERF_REGS 9#ifdef CONFIG_HAVE_PERF_REGS
5#include <asm/perf_regs.h> 10#include <asm/perf_regs.h>
6u64 perf_reg_value(struct pt_regs *regs, int idx); 11u64 perf_reg_value(struct pt_regs *regs, int idx);
7int perf_reg_validate(u64 mask); 12int perf_reg_validate(u64 mask);
8u64 perf_reg_abi(struct task_struct *task); 13u64 perf_reg_abi(struct task_struct *task);
14void perf_get_regs_user(struct perf_regs *regs_user,
15 struct pt_regs *regs,
16 struct pt_regs *regs_user_copy);
9#else 17#else
10static inline u64 perf_reg_value(struct pt_regs *regs, int idx) 18static inline u64 perf_reg_value(struct pt_regs *regs, int idx)
11{ 19{
@@ -21,5 +29,13 @@ static inline u64 perf_reg_abi(struct task_struct *task)
21{ 29{
22 return PERF_SAMPLE_REGS_ABI_NONE; 30 return PERF_SAMPLE_REGS_ABI_NONE;
23} 31}
32
33static inline void perf_get_regs_user(struct perf_regs *regs_user,
34 struct pt_regs *regs,
35 struct pt_regs *regs_user_copy)
36{
37 regs_user->regs = task_pt_regs(current);
38 regs_user->abi = perf_reg_abi(current);
39}
24#endif /* CONFIG_HAVE_PERF_REGS */ 40#endif /* CONFIG_HAVE_PERF_REGS */
25#endif /* _LINUX_PERF_REGS_H */ 41#endif /* _LINUX_PERF_REGS_H */
diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index c0c2bce6b0b7..d9d7e7e56352 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -37,6 +37,16 @@ struct anon_vma {
37 atomic_t refcount; 37 atomic_t refcount;
38 38
39 /* 39 /*
40 * Count of child anon_vmas and VMAs which points to this anon_vma.
41 *
42 * This counter is used for making decision about reusing anon_vma
43 * instead of forking new one. See comments in function anon_vma_clone.
44 */
45 unsigned degree;
46
47 struct anon_vma *parent; /* Parent of this anon_vma */
48
49 /*
40 * NOTE: the LSB of the rb_root.rb_node is set by 50 * NOTE: the LSB of the rb_root.rb_node is set by
41 * mm_take_all_locks() _after_ taking the above lock. So the 51 * mm_take_all_locks() _after_ taking the above lock. So the
42 * rb_root must only be read/written after taking the above lock 52 * rb_root must only be read/written after taking the above lock
diff --git a/include/linux/writeback.h b/include/linux/writeback.h
index a219be961c0a..00048339c23e 100644
--- a/include/linux/writeback.h
+++ b/include/linux/writeback.h
@@ -177,7 +177,6 @@ int write_cache_pages(struct address_space *mapping,
177 struct writeback_control *wbc, writepage_t writepage, 177 struct writeback_control *wbc, writepage_t writepage,
178 void *data); 178 void *data);
179int do_writepages(struct address_space *mapping, struct writeback_control *wbc); 179int do_writepages(struct address_space *mapping, struct writeback_control *wbc);
180void set_page_dirty_balance(struct page *page);
181void writeback_set_ratelimit(void); 180void writeback_set_ratelimit(void);
182void tag_pages_for_writeback(struct address_space *mapping, 181void tag_pages_for_writeback(struct address_space *mapping,
183 pgoff_t start, pgoff_t end); 182 pgoff_t start, pgoff_t end);
diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index 58d719ddaa60..29c7be8808d5 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -1270,8 +1270,7 @@ struct ieee80211_vif *wdev_to_ieee80211_vif(struct wireless_dev *wdev);
1270 * 1270 *
1271 * @IEEE80211_KEY_FLAG_GENERATE_IV: This flag should be set by the 1271 * @IEEE80211_KEY_FLAG_GENERATE_IV: This flag should be set by the
1272 * driver to indicate that it requires IV generation for this 1272 * driver to indicate that it requires IV generation for this
1273 * particular key. Setting this flag does not necessarily mean that SKBs 1273 * particular key.
1274 * will have sufficient tailroom for ICV or MIC.
1275 * @IEEE80211_KEY_FLAG_GENERATE_MMIC: This flag should be set by 1274 * @IEEE80211_KEY_FLAG_GENERATE_MMIC: This flag should be set by
1276 * the driver for a TKIP key if it requires Michael MIC 1275 * the driver for a TKIP key if it requires Michael MIC
1277 * generation in software. 1276 * generation in software.
@@ -1283,9 +1282,7 @@ struct ieee80211_vif *wdev_to_ieee80211_vif(struct wireless_dev *wdev);
1283 * @IEEE80211_KEY_FLAG_PUT_IV_SPACE: This flag should be set by the driver 1282 * @IEEE80211_KEY_FLAG_PUT_IV_SPACE: This flag should be set by the driver
1284 * if space should be prepared for the IV, but the IV 1283 * if space should be prepared for the IV, but the IV
1285 * itself should not be generated. Do not set together with 1284 * itself should not be generated. Do not set together with
1286 * @IEEE80211_KEY_FLAG_GENERATE_IV on the same key. Setting this flag does 1285 * @IEEE80211_KEY_FLAG_GENERATE_IV on the same key.
1287 * not necessarily mean that SKBs will have sufficient tailroom for ICV or
1288 * MIC.
1289 * @IEEE80211_KEY_FLAG_RX_MGMT: This key will be used to decrypt received 1286 * @IEEE80211_KEY_FLAG_RX_MGMT: This key will be used to decrypt received
1290 * management frames. The flag can help drivers that have a hardware 1287 * management frames. The flag can help drivers that have a hardware
1291 * crypto implementation that doesn't deal with management frames 1288 * crypto implementation that doesn't deal with management frames
diff --git a/include/target/target_core_backend.h b/include/target/target_core_backend.h
index 430cfaf92285..db81c65b8f48 100644
--- a/include/target/target_core_backend.h
+++ b/include/target/target_core_backend.h
@@ -135,7 +135,6 @@ int se_dev_set_is_nonrot(struct se_device *, int);
135int se_dev_set_emulate_rest_reord(struct se_device *dev, int); 135int se_dev_set_emulate_rest_reord(struct se_device *dev, int);
136int se_dev_set_queue_depth(struct se_device *, u32); 136int se_dev_set_queue_depth(struct se_device *, u32);
137int se_dev_set_max_sectors(struct se_device *, u32); 137int se_dev_set_max_sectors(struct se_device *, u32);
138int se_dev_set_fabric_max_sectors(struct se_device *, u32);
139int se_dev_set_optimal_sectors(struct se_device *, u32); 138int se_dev_set_optimal_sectors(struct se_device *, u32);
140int se_dev_set_block_size(struct se_device *, u32); 139int se_dev_set_block_size(struct se_device *, u32);
141 140
diff --git a/include/target/target_core_backend_configfs.h b/include/target/target_core_backend_configfs.h
index 3247d7530107..186f7a923570 100644
--- a/include/target/target_core_backend_configfs.h
+++ b/include/target/target_core_backend_configfs.h
@@ -98,8 +98,6 @@ static struct target_backend_dev_attrib_attribute _backend##_dev_attrib_##_name
98 TB_DEV_ATTR(_backend, block_size, S_IRUGO | S_IWUSR); \ 98 TB_DEV_ATTR(_backend, block_size, S_IRUGO | S_IWUSR); \
99 DEF_TB_DEV_ATTRIB_RO(_backend, hw_max_sectors); \ 99 DEF_TB_DEV_ATTRIB_RO(_backend, hw_max_sectors); \
100 TB_DEV_ATTR_RO(_backend, hw_max_sectors); \ 100 TB_DEV_ATTR_RO(_backend, hw_max_sectors); \
101 DEF_TB_DEV_ATTRIB(_backend, fabric_max_sectors); \
102 TB_DEV_ATTR(_backend, fabric_max_sectors, S_IRUGO | S_IWUSR); \
103 DEF_TB_DEV_ATTRIB(_backend, optimal_sectors); \ 101 DEF_TB_DEV_ATTRIB(_backend, optimal_sectors); \
104 TB_DEV_ATTR(_backend, optimal_sectors, S_IRUGO | S_IWUSR); \ 102 TB_DEV_ATTR(_backend, optimal_sectors, S_IRUGO | S_IWUSR); \
105 DEF_TB_DEV_ATTRIB_RO(_backend, hw_queue_depth); \ 103 DEF_TB_DEV_ATTRIB_RO(_backend, hw_queue_depth); \
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index 397fb635766a..4a8795a87b9e 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -77,8 +77,6 @@
77#define DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT 0 77#define DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT 0
78/* Default max_write_same_len, disabled by default */ 78/* Default max_write_same_len, disabled by default */
79#define DA_MAX_WRITE_SAME_LEN 0 79#define DA_MAX_WRITE_SAME_LEN 0
80/* Default max transfer length */
81#define DA_FABRIC_MAX_SECTORS 8192
82/* Use a model alias based on the configfs backend device name */ 80/* Use a model alias based on the configfs backend device name */
83#define DA_EMULATE_MODEL_ALIAS 0 81#define DA_EMULATE_MODEL_ALIAS 0
84/* Emulation for Direct Page Out */ 82/* Emulation for Direct Page Out */
@@ -694,7 +692,6 @@ struct se_dev_attrib {
694 u32 hw_block_size; 692 u32 hw_block_size;
695 u32 block_size; 693 u32 block_size;
696 u32 hw_max_sectors; 694 u32 hw_max_sectors;
697 u32 fabric_max_sectors;
698 u32 optimal_sectors; 695 u32 optimal_sectors;
699 u32 hw_queue_depth; 696 u32 hw_queue_depth;
700 u32 queue_depth; 697 u32 queue_depth;
diff --git a/include/uapi/asm-generic/fcntl.h b/include/uapi/asm-generic/fcntl.h
index 7543b3e51331..e063effe0cc1 100644
--- a/include/uapi/asm-generic/fcntl.h
+++ b/include/uapi/asm-generic/fcntl.h
@@ -5,7 +5,7 @@
5 5
6/* 6/*
7 * FMODE_EXEC is 0x20 7 * FMODE_EXEC is 0x20
8 * FMODE_NONOTIFY is 0x1000000 8 * FMODE_NONOTIFY is 0x4000000
9 * These cannot be used by userspace O_* until internal and external open 9 * These cannot be used by userspace O_* until internal and external open
10 * flags are split. 10 * flags are split.
11 * -Eric Paris 11 * -Eric Paris
diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
index 7acef41fc209..af94f31e33ac 100644
--- a/include/uapi/linux/kfd_ioctl.h
+++ b/include/uapi/linux/kfd_ioctl.h
@@ -128,27 +128,34 @@ struct kfd_ioctl_get_process_apertures_args {
128 uint32_t pad; 128 uint32_t pad;
129}; 129};
130 130
131#define KFD_IOC_MAGIC 'K' 131#define AMDKFD_IOCTL_BASE 'K'
132#define AMDKFD_IO(nr) _IO(AMDKFD_IOCTL_BASE, nr)
133#define AMDKFD_IOR(nr, type) _IOR(AMDKFD_IOCTL_BASE, nr, type)
134#define AMDKFD_IOW(nr, type) _IOW(AMDKFD_IOCTL_BASE, nr, type)
135#define AMDKFD_IOWR(nr, type) _IOWR(AMDKFD_IOCTL_BASE, nr, type)
132 136
133#define KFD_IOC_GET_VERSION \ 137#define AMDKFD_IOC_GET_VERSION \
134 _IOR(KFD_IOC_MAGIC, 1, struct kfd_ioctl_get_version_args) 138 AMDKFD_IOR(0x01, struct kfd_ioctl_get_version_args)
135 139
136#define KFD_IOC_CREATE_QUEUE \ 140#define AMDKFD_IOC_CREATE_QUEUE \
137 _IOWR(KFD_IOC_MAGIC, 2, struct kfd_ioctl_create_queue_args) 141 AMDKFD_IOWR(0x02, struct kfd_ioctl_create_queue_args)
138 142
139#define KFD_IOC_DESTROY_QUEUE \ 143#define AMDKFD_IOC_DESTROY_QUEUE \
140 _IOWR(KFD_IOC_MAGIC, 3, struct kfd_ioctl_destroy_queue_args) 144 AMDKFD_IOWR(0x03, struct kfd_ioctl_destroy_queue_args)
141 145
142#define KFD_IOC_SET_MEMORY_POLICY \ 146#define AMDKFD_IOC_SET_MEMORY_POLICY \
143 _IOW(KFD_IOC_MAGIC, 4, struct kfd_ioctl_set_memory_policy_args) 147 AMDKFD_IOW(0x04, struct kfd_ioctl_set_memory_policy_args)
144 148
145#define KFD_IOC_GET_CLOCK_COUNTERS \ 149#define AMDKFD_IOC_GET_CLOCK_COUNTERS \
146 _IOWR(KFD_IOC_MAGIC, 5, struct kfd_ioctl_get_clock_counters_args) 150 AMDKFD_IOWR(0x05, struct kfd_ioctl_get_clock_counters_args)
147 151
148#define KFD_IOC_GET_PROCESS_APERTURES \ 152#define AMDKFD_IOC_GET_PROCESS_APERTURES \
149 _IOR(KFD_IOC_MAGIC, 6, struct kfd_ioctl_get_process_apertures_args) 153 AMDKFD_IOR(0x06, struct kfd_ioctl_get_process_apertures_args)
150 154
151#define KFD_IOC_UPDATE_QUEUE \ 155#define AMDKFD_IOC_UPDATE_QUEUE \
152 _IOW(KFD_IOC_MAGIC, 7, struct kfd_ioctl_update_queue_args) 156 AMDKFD_IOW(0x07, struct kfd_ioctl_update_queue_args)
157
158#define AMDKFD_COMMAND_START 0x01
159#define AMDKFD_COMMAND_END 0x08
153 160
154#endif 161#endif
diff --git a/include/uapi/linux/openvswitch.h b/include/uapi/linux/openvswitch.h
index 3a6dcaa359b7..f714e8633352 100644
--- a/include/uapi/linux/openvswitch.h
+++ b/include/uapi/linux/openvswitch.h
@@ -174,6 +174,10 @@ enum ovs_packet_attr {
174 OVS_PACKET_ATTR_USERDATA, /* OVS_ACTION_ATTR_USERSPACE arg. */ 174 OVS_PACKET_ATTR_USERDATA, /* OVS_ACTION_ATTR_USERSPACE arg. */
175 OVS_PACKET_ATTR_EGRESS_TUN_KEY, /* Nested OVS_TUNNEL_KEY_ATTR_* 175 OVS_PACKET_ATTR_EGRESS_TUN_KEY, /* Nested OVS_TUNNEL_KEY_ATTR_*
176 attributes. */ 176 attributes. */
177 OVS_PACKET_ATTR_UNUSED1,
178 OVS_PACKET_ATTR_UNUSED2,
179 OVS_PACKET_ATTR_PROBE, /* Packet operation is a feature probe,
180 error logging should be suppressed. */
177 __OVS_PACKET_ATTR_MAX 181 __OVS_PACKET_ATTR_MAX
178}; 182};
179 183
diff --git a/include/xen/interface/nmi.h b/include/xen/interface/nmi.h
new file mode 100644
index 000000000000..b47d9d06fade
--- /dev/null
+++ b/include/xen/interface/nmi.h
@@ -0,0 +1,51 @@
1/******************************************************************************
2 * nmi.h
3 *
4 * NMI callback registration and reason codes.
5 *
6 * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
7 */
8
9#ifndef __XEN_PUBLIC_NMI_H__
10#define __XEN_PUBLIC_NMI_H__
11
12#include <xen/interface/xen.h>
13
14/*
15 * NMI reason codes:
16 * Currently these are x86-specific, stored in arch_shared_info.nmi_reason.
17 */
18 /* I/O-check error reported via ISA port 0x61, bit 6. */
19#define _XEN_NMIREASON_io_error 0
20#define XEN_NMIREASON_io_error (1UL << _XEN_NMIREASON_io_error)
21 /* PCI SERR reported via ISA port 0x61, bit 7. */
22#define _XEN_NMIREASON_pci_serr 1
23#define XEN_NMIREASON_pci_serr (1UL << _XEN_NMIREASON_pci_serr)
24 /* Unknown hardware-generated NMI. */
25#define _XEN_NMIREASON_unknown 2
26#define XEN_NMIREASON_unknown (1UL << _XEN_NMIREASON_unknown)
27
28/*
29 * long nmi_op(unsigned int cmd, void *arg)
30 * NB. All ops return zero on success, else a negative error code.
31 */
32
33/*
34 * Register NMI callback for this (calling) VCPU. Currently this only makes
35 * sense for domain 0, vcpu 0. All other callers will be returned EINVAL.
36 * arg == pointer to xennmi_callback structure.
37 */
38#define XENNMI_register_callback 0
39struct xennmi_callback {
40 unsigned long handler_address;
41 unsigned long pad;
42};
43DEFINE_GUEST_HANDLE_STRUCT(xennmi_callback);
44
45/*
46 * Deregister NMI callback for this (calling) VCPU.
47 * arg == NULL.
48 */
49#define XENNMI_unregister_callback 1
50
51#endif /* __XEN_PUBLIC_NMI_H__ */
diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
index 1adf62b39b96..07ce18ca71e0 100644
--- a/kernel/debug/debug_core.c
+++ b/kernel/debug/debug_core.c
@@ -27,6 +27,9 @@
27 * version 2. This program is licensed "as is" without any warranty of any 27 * version 2. This program is licensed "as is" without any warranty of any
28 * kind, whether express or implied. 28 * kind, whether express or implied.
29 */ 29 */
30
31#define pr_fmt(fmt) "KGDB: " fmt
32
30#include <linux/pid_namespace.h> 33#include <linux/pid_namespace.h>
31#include <linux/clocksource.h> 34#include <linux/clocksource.h>
32#include <linux/serial_core.h> 35#include <linux/serial_core.h>
@@ -196,8 +199,8 @@ int __weak kgdb_validate_break_address(unsigned long addr)
196 return err; 199 return err;
197 err = kgdb_arch_remove_breakpoint(&tmp); 200 err = kgdb_arch_remove_breakpoint(&tmp);
198 if (err) 201 if (err)
199 printk(KERN_ERR "KGDB: Critical breakpoint error, kernel " 202 pr_err("Critical breakpoint error, kernel memory destroyed at: %lx\n",
200 "memory destroyed at: %lx", addr); 203 addr);
201 return err; 204 return err;
202} 205}
203 206
@@ -256,8 +259,8 @@ int dbg_activate_sw_breakpoints(void)
256 error = kgdb_arch_set_breakpoint(&kgdb_break[i]); 259 error = kgdb_arch_set_breakpoint(&kgdb_break[i]);
257 if (error) { 260 if (error) {
258 ret = error; 261 ret = error;
259 printk(KERN_INFO "KGDB: BP install failed: %lx", 262 pr_info("BP install failed: %lx\n",
260 kgdb_break[i].bpt_addr); 263 kgdb_break[i].bpt_addr);
261 continue; 264 continue;
262 } 265 }
263 266
@@ -319,8 +322,8 @@ int dbg_deactivate_sw_breakpoints(void)
319 continue; 322 continue;
320 error = kgdb_arch_remove_breakpoint(&kgdb_break[i]); 323 error = kgdb_arch_remove_breakpoint(&kgdb_break[i]);
321 if (error) { 324 if (error) {
322 printk(KERN_INFO "KGDB: BP remove failed: %lx\n", 325 pr_info("BP remove failed: %lx\n",
323 kgdb_break[i].bpt_addr); 326 kgdb_break[i].bpt_addr);
324 ret = error; 327 ret = error;
325 } 328 }
326 329
@@ -367,7 +370,7 @@ int dbg_remove_all_break(void)
367 goto setundefined; 370 goto setundefined;
368 error = kgdb_arch_remove_breakpoint(&kgdb_break[i]); 371 error = kgdb_arch_remove_breakpoint(&kgdb_break[i]);
369 if (error) 372 if (error)
370 printk(KERN_ERR "KGDB: breakpoint remove failed: %lx\n", 373 pr_err("breakpoint remove failed: %lx\n",
371 kgdb_break[i].bpt_addr); 374 kgdb_break[i].bpt_addr);
372setundefined: 375setundefined:
373 kgdb_break[i].state = BP_UNDEFINED; 376 kgdb_break[i].state = BP_UNDEFINED;
@@ -400,9 +403,9 @@ static int kgdb_io_ready(int print_wait)
400 if (print_wait) { 403 if (print_wait) {
401#ifdef CONFIG_KGDB_KDB 404#ifdef CONFIG_KGDB_KDB
402 if (!dbg_kdb_mode) 405 if (!dbg_kdb_mode)
403 printk(KERN_CRIT "KGDB: waiting... or $3#33 for KDB\n"); 406 pr_crit("waiting... or $3#33 for KDB\n");
404#else 407#else
405 printk(KERN_CRIT "KGDB: Waiting for remote debugger\n"); 408 pr_crit("Waiting for remote debugger\n");
406#endif 409#endif
407 } 410 }
408 return 1; 411 return 1;
@@ -430,8 +433,7 @@ static int kgdb_reenter_check(struct kgdb_state *ks)
430 exception_level = 0; 433 exception_level = 0;
431 kgdb_skipexception(ks->ex_vector, ks->linux_regs); 434 kgdb_skipexception(ks->ex_vector, ks->linux_regs);
432 dbg_activate_sw_breakpoints(); 435 dbg_activate_sw_breakpoints();
433 printk(KERN_CRIT "KGDB: re-enter error: breakpoint removed %lx\n", 436 pr_crit("re-enter error: breakpoint removed %lx\n", addr);
434 addr);
435 WARN_ON_ONCE(1); 437 WARN_ON_ONCE(1);
436 438
437 return 1; 439 return 1;
@@ -444,7 +446,7 @@ static int kgdb_reenter_check(struct kgdb_state *ks)
444 panic("Recursive entry to debugger"); 446 panic("Recursive entry to debugger");
445 } 447 }
446 448
447 printk(KERN_CRIT "KGDB: re-enter exception: ALL breakpoints killed\n"); 449 pr_crit("re-enter exception: ALL breakpoints killed\n");
448#ifdef CONFIG_KGDB_KDB 450#ifdef CONFIG_KGDB_KDB
449 /* Allow kdb to debug itself one level */ 451 /* Allow kdb to debug itself one level */
450 return 0; 452 return 0;
@@ -471,6 +473,7 @@ static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs,
471 int cpu; 473 int cpu;
472 int trace_on = 0; 474 int trace_on = 0;
473 int online_cpus = num_online_cpus(); 475 int online_cpus = num_online_cpus();
476 u64 time_left;
474 477
475 kgdb_info[ks->cpu].enter_kgdb++; 478 kgdb_info[ks->cpu].enter_kgdb++;
476 kgdb_info[ks->cpu].exception_state |= exception_state; 479 kgdb_info[ks->cpu].exception_state |= exception_state;
@@ -595,9 +598,13 @@ return_normal:
595 /* 598 /*
596 * Wait for the other CPUs to be notified and be waiting for us: 599 * Wait for the other CPUs to be notified and be waiting for us:
597 */ 600 */
598 while (kgdb_do_roundup && (atomic_read(&masters_in_kgdb) + 601 time_left = loops_per_jiffy * HZ;
599 atomic_read(&slaves_in_kgdb)) != online_cpus) 602 while (kgdb_do_roundup && --time_left &&
603 (atomic_read(&masters_in_kgdb) + atomic_read(&slaves_in_kgdb)) !=
604 online_cpus)
600 cpu_relax(); 605 cpu_relax();
606 if (!time_left)
607 pr_crit("KGDB: Timed out waiting for secondary CPUs.\n");
601 608
602 /* 609 /*
603 * At this point the primary processor is completely 610 * At this point the primary processor is completely
@@ -795,15 +802,15 @@ static struct console kgdbcons = {
795static void sysrq_handle_dbg(int key) 802static void sysrq_handle_dbg(int key)
796{ 803{
797 if (!dbg_io_ops) { 804 if (!dbg_io_ops) {
798 printk(KERN_CRIT "ERROR: No KGDB I/O module available\n"); 805 pr_crit("ERROR: No KGDB I/O module available\n");
799 return; 806 return;
800 } 807 }
801 if (!kgdb_connected) { 808 if (!kgdb_connected) {
802#ifdef CONFIG_KGDB_KDB 809#ifdef CONFIG_KGDB_KDB
803 if (!dbg_kdb_mode) 810 if (!dbg_kdb_mode)
804 printk(KERN_CRIT "KGDB or $3#33 for KDB\n"); 811 pr_crit("KGDB or $3#33 for KDB\n");
805#else 812#else
806 printk(KERN_CRIT "Entering KGDB\n"); 813 pr_crit("Entering KGDB\n");
807#endif 814#endif
808 } 815 }
809 816
@@ -945,7 +952,7 @@ static void kgdb_initial_breakpoint(void)
945{ 952{
946 kgdb_break_asap = 0; 953 kgdb_break_asap = 0;
947 954
948 printk(KERN_CRIT "kgdb: Waiting for connection from remote gdb...\n"); 955 pr_crit("Waiting for connection from remote gdb...\n");
949 kgdb_breakpoint(); 956 kgdb_breakpoint();
950} 957}
951 958
@@ -964,8 +971,7 @@ int kgdb_register_io_module(struct kgdb_io *new_dbg_io_ops)
964 if (dbg_io_ops) { 971 if (dbg_io_ops) {
965 spin_unlock(&kgdb_registration_lock); 972 spin_unlock(&kgdb_registration_lock);
966 973
967 printk(KERN_ERR "kgdb: Another I/O driver is already " 974 pr_err("Another I/O driver is already registered with KGDB\n");
968 "registered with KGDB.\n");
969 return -EBUSY; 975 return -EBUSY;
970 } 976 }
971 977
@@ -981,8 +987,7 @@ int kgdb_register_io_module(struct kgdb_io *new_dbg_io_ops)
981 987
982 spin_unlock(&kgdb_registration_lock); 988 spin_unlock(&kgdb_registration_lock);
983 989
984 printk(KERN_INFO "kgdb: Registered I/O driver %s.\n", 990 pr_info("Registered I/O driver %s\n", new_dbg_io_ops->name);
985 new_dbg_io_ops->name);
986 991
987 /* Arm KGDB now. */ 992 /* Arm KGDB now. */
988 kgdb_register_callbacks(); 993 kgdb_register_callbacks();
@@ -1017,8 +1022,7 @@ void kgdb_unregister_io_module(struct kgdb_io *old_dbg_io_ops)
1017 1022
1018 spin_unlock(&kgdb_registration_lock); 1023 spin_unlock(&kgdb_registration_lock);
1019 1024
1020 printk(KERN_INFO 1025 pr_info("Unregistered I/O driver %s, debugger disabled\n",
1021 "kgdb: Unregistered I/O driver %s, debugger disabled.\n",
1022 old_dbg_io_ops->name); 1026 old_dbg_io_ops->name);
1023} 1027}
1024EXPORT_SYMBOL_GPL(kgdb_unregister_io_module); 1028EXPORT_SYMBOL_GPL(kgdb_unregister_io_module);
diff --git a/kernel/debug/kdb/kdb_bp.c b/kernel/debug/kdb/kdb_bp.c
index b20d544f20c2..e1dbf4a2c69e 100644
--- a/kernel/debug/kdb/kdb_bp.c
+++ b/kernel/debug/kdb/kdb_bp.c
@@ -531,22 +531,29 @@ void __init kdb_initbptab(void)
531 for (i = 0, bp = kdb_breakpoints; i < KDB_MAXBPT; i++, bp++) 531 for (i = 0, bp = kdb_breakpoints; i < KDB_MAXBPT; i++, bp++)
532 bp->bp_free = 1; 532 bp->bp_free = 1;
533 533
534 kdb_register_repeat("bp", kdb_bp, "[<vaddr>]", 534 kdb_register_flags("bp", kdb_bp, "[<vaddr>]",
535 "Set/Display breakpoints", 0, KDB_REPEAT_NO_ARGS); 535 "Set/Display breakpoints", 0,
536 kdb_register_repeat("bl", kdb_bp, "[<vaddr>]", 536 KDB_ENABLE_FLOW_CTRL | KDB_REPEAT_NO_ARGS);
537 "Display breakpoints", 0, KDB_REPEAT_NO_ARGS); 537 kdb_register_flags("bl", kdb_bp, "[<vaddr>]",
538 "Display breakpoints", 0,
539 KDB_ENABLE_FLOW_CTRL | KDB_REPEAT_NO_ARGS);
538 if (arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT) 540 if (arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT)
539 kdb_register_repeat("bph", kdb_bp, "[<vaddr>]", 541 kdb_register_flags("bph", kdb_bp, "[<vaddr>]",
540 "[datar [length]|dataw [length]] Set hw brk", 0, KDB_REPEAT_NO_ARGS); 542 "[datar [length]|dataw [length]] Set hw brk", 0,
541 kdb_register_repeat("bc", kdb_bc, "<bpnum>", 543 KDB_ENABLE_FLOW_CTRL | KDB_REPEAT_NO_ARGS);
542 "Clear Breakpoint", 0, KDB_REPEAT_NONE); 544 kdb_register_flags("bc", kdb_bc, "<bpnum>",
543 kdb_register_repeat("be", kdb_bc, "<bpnum>", 545 "Clear Breakpoint", 0,
544 "Enable Breakpoint", 0, KDB_REPEAT_NONE); 546 KDB_ENABLE_FLOW_CTRL);
545 kdb_register_repeat("bd", kdb_bc, "<bpnum>", 547 kdb_register_flags("be", kdb_bc, "<bpnum>",
546 "Disable Breakpoint", 0, KDB_REPEAT_NONE); 548 "Enable Breakpoint", 0,
547 549 KDB_ENABLE_FLOW_CTRL);
548 kdb_register_repeat("ss", kdb_ss, "", 550 kdb_register_flags("bd", kdb_bc, "<bpnum>",
549 "Single Step", 1, KDB_REPEAT_NO_ARGS); 551 "Disable Breakpoint", 0,
552 KDB_ENABLE_FLOW_CTRL);
553
554 kdb_register_flags("ss", kdb_ss, "",
555 "Single Step", 1,
556 KDB_ENABLE_FLOW_CTRL | KDB_REPEAT_NO_ARGS);
550 /* 557 /*
551 * Architecture dependent initialization. 558 * Architecture dependent initialization.
552 */ 559 */
diff --git a/kernel/debug/kdb/kdb_debugger.c b/kernel/debug/kdb/kdb_debugger.c
index 8859ca34dcfe..15e1a7af5dd0 100644
--- a/kernel/debug/kdb/kdb_debugger.c
+++ b/kernel/debug/kdb/kdb_debugger.c
@@ -129,6 +129,10 @@ int kdb_stub(struct kgdb_state *ks)
129 ks->pass_exception = 1; 129 ks->pass_exception = 1;
130 KDB_FLAG_SET(CATASTROPHIC); 130 KDB_FLAG_SET(CATASTROPHIC);
131 } 131 }
132 /* set CATASTROPHIC if the system contains unresponsive processors */
133 for_each_online_cpu(i)
134 if (!kgdb_info[i].enter_kgdb)
135 KDB_FLAG_SET(CATASTROPHIC);
132 if (KDB_STATE(SSBPT) && reason == KDB_REASON_SSTEP) { 136 if (KDB_STATE(SSBPT) && reason == KDB_REASON_SSTEP) {
133 KDB_STATE_CLEAR(SSBPT); 137 KDB_STATE_CLEAR(SSBPT);
134 KDB_STATE_CLEAR(DOING_SS); 138 KDB_STATE_CLEAR(DOING_SS);
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index 379650b984f8..f191bddf64b8 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -12,6 +12,7 @@
12 */ 12 */
13 13
14#include <linux/ctype.h> 14#include <linux/ctype.h>
15#include <linux/types.h>
15#include <linux/string.h> 16#include <linux/string.h>
16#include <linux/kernel.h> 17#include <linux/kernel.h>
17#include <linux/kmsg_dump.h> 18#include <linux/kmsg_dump.h>
@@ -23,6 +24,7 @@
23#include <linux/vmalloc.h> 24#include <linux/vmalloc.h>
24#include <linux/atomic.h> 25#include <linux/atomic.h>
25#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/moduleparam.h>
26#include <linux/mm.h> 28#include <linux/mm.h>
27#include <linux/init.h> 29#include <linux/init.h>
28#include <linux/kallsyms.h> 30#include <linux/kallsyms.h>
@@ -42,6 +44,12 @@
42#include <linux/slab.h> 44#include <linux/slab.h>
43#include "kdb_private.h" 45#include "kdb_private.h"
44 46
47#undef MODULE_PARAM_PREFIX
48#define MODULE_PARAM_PREFIX "kdb."
49
50static int kdb_cmd_enabled = CONFIG_KDB_DEFAULT_ENABLE;
51module_param_named(cmd_enable, kdb_cmd_enabled, int, 0600);
52
45#define GREP_LEN 256 53#define GREP_LEN 256
46char kdb_grep_string[GREP_LEN]; 54char kdb_grep_string[GREP_LEN];
47int kdb_grepping_flag; 55int kdb_grepping_flag;
@@ -121,6 +129,7 @@ static kdbmsg_t kdbmsgs[] = {
121 KDBMSG(BADLENGTH, "Invalid length field"), 129 KDBMSG(BADLENGTH, "Invalid length field"),
122 KDBMSG(NOBP, "No Breakpoint exists"), 130 KDBMSG(NOBP, "No Breakpoint exists"),
123 KDBMSG(BADADDR, "Invalid address"), 131 KDBMSG(BADADDR, "Invalid address"),
132 KDBMSG(NOPERM, "Permission denied"),
124}; 133};
125#undef KDBMSG 134#undef KDBMSG
126 135
@@ -188,6 +197,26 @@ struct task_struct *kdb_curr_task(int cpu)
188} 197}
189 198
190/* 199/*
200 * Check whether the flags of the current command and the permissions
201 * of the kdb console has allow a command to be run.
202 */
203static inline bool kdb_check_flags(kdb_cmdflags_t flags, int permissions,
204 bool no_args)
205{
206 /* permissions comes from userspace so needs massaging slightly */
207 permissions &= KDB_ENABLE_MASK;
208 permissions |= KDB_ENABLE_ALWAYS_SAFE;
209
210 /* some commands change group when launched with no arguments */
211 if (no_args)
212 permissions |= permissions << KDB_ENABLE_NO_ARGS_SHIFT;
213
214 flags |= KDB_ENABLE_ALL;
215
216 return permissions & flags;
217}
218
219/*
191 * kdbgetenv - This function will return the character string value of 220 * kdbgetenv - This function will return the character string value of
192 * an environment variable. 221 * an environment variable.
193 * Parameters: 222 * Parameters:
@@ -476,6 +505,15 @@ int kdbgetaddrarg(int argc, const char **argv, int *nextarg,
476 kdb_symtab_t symtab; 505 kdb_symtab_t symtab;
477 506
478 /* 507 /*
508 * If the enable flags prohibit both arbitrary memory access
509 * and flow control then there are no reasonable grounds to
510 * provide symbol lookup.
511 */
512 if (!kdb_check_flags(KDB_ENABLE_MEM_READ | KDB_ENABLE_FLOW_CTRL,
513 kdb_cmd_enabled, false))
514 return KDB_NOPERM;
515
516 /*
479 * Process arguments which follow the following syntax: 517 * Process arguments which follow the following syntax:
480 * 518 *
481 * symbol | numeric-address [+/- numeric-offset] 519 * symbol | numeric-address [+/- numeric-offset]
@@ -641,8 +679,13 @@ static int kdb_defcmd2(const char *cmdstr, const char *argv0)
641 if (!s->count) 679 if (!s->count)
642 s->usable = 0; 680 s->usable = 0;
643 if (s->usable) 681 if (s->usable)
644 kdb_register(s->name, kdb_exec_defcmd, 682 /* macros are always safe because when executed each
645 s->usage, s->help, 0); 683 * internal command re-enters kdb_parse() and is
684 * safety checked individually.
685 */
686 kdb_register_flags(s->name, kdb_exec_defcmd, s->usage,
687 s->help, 0,
688 KDB_ENABLE_ALWAYS_SAFE);
646 return 0; 689 return 0;
647 } 690 }
648 if (!s->usable) 691 if (!s->usable)
@@ -1003,25 +1046,22 @@ int kdb_parse(const char *cmdstr)
1003 1046
1004 if (i < kdb_max_commands) { 1047 if (i < kdb_max_commands) {
1005 int result; 1048 int result;
1049
1050 if (!kdb_check_flags(tp->cmd_flags, kdb_cmd_enabled, argc <= 1))
1051 return KDB_NOPERM;
1052
1006 KDB_STATE_SET(CMD); 1053 KDB_STATE_SET(CMD);
1007 result = (*tp->cmd_func)(argc-1, (const char **)argv); 1054 result = (*tp->cmd_func)(argc-1, (const char **)argv);
1008 if (result && ignore_errors && result > KDB_CMD_GO) 1055 if (result && ignore_errors && result > KDB_CMD_GO)
1009 result = 0; 1056 result = 0;
1010 KDB_STATE_CLEAR(CMD); 1057 KDB_STATE_CLEAR(CMD);
1011 switch (tp->cmd_repeat) { 1058
1012 case KDB_REPEAT_NONE: 1059 if (tp->cmd_flags & KDB_REPEAT_WITH_ARGS)
1013 argc = 0; 1060 return result;
1014 if (argv[0]) 1061
1015 *(argv[0]) = '\0'; 1062 argc = tp->cmd_flags & KDB_REPEAT_NO_ARGS ? 1 : 0;
1016 break; 1063 if (argv[argc])
1017 case KDB_REPEAT_NO_ARGS: 1064 *(argv[argc]) = '\0';
1018 argc = 1;
1019 if (argv[1])
1020 *(argv[1]) = '\0';
1021 break;
1022 case KDB_REPEAT_WITH_ARGS:
1023 break;
1024 }
1025 return result; 1065 return result;
1026 } 1066 }
1027 1067
@@ -1921,10 +1961,14 @@ static int kdb_rm(int argc, const char **argv)
1921 */ 1961 */
1922static int kdb_sr(int argc, const char **argv) 1962static int kdb_sr(int argc, const char **argv)
1923{ 1963{
1964 bool check_mask =
1965 !kdb_check_flags(KDB_ENABLE_ALL, kdb_cmd_enabled, false);
1966
1924 if (argc != 1) 1967 if (argc != 1)
1925 return KDB_ARGCOUNT; 1968 return KDB_ARGCOUNT;
1969
1926 kdb_trap_printk++; 1970 kdb_trap_printk++;
1927 __handle_sysrq(*argv[1], false); 1971 __handle_sysrq(*argv[1], check_mask);
1928 kdb_trap_printk--; 1972 kdb_trap_printk--;
1929 1973
1930 return 0; 1974 return 0;
@@ -2157,6 +2201,8 @@ static void kdb_cpu_status(void)
2157 for (start_cpu = -1, i = 0; i < NR_CPUS; i++) { 2201 for (start_cpu = -1, i = 0; i < NR_CPUS; i++) {
2158 if (!cpu_online(i)) { 2202 if (!cpu_online(i)) {
2159 state = 'F'; /* cpu is offline */ 2203 state = 'F'; /* cpu is offline */
2204 } else if (!kgdb_info[i].enter_kgdb) {
2205 state = 'D'; /* cpu is online but unresponsive */
2160 } else { 2206 } else {
2161 state = ' '; /* cpu is responding to kdb */ 2207 state = ' '; /* cpu is responding to kdb */
2162 if (kdb_task_state_char(KDB_TSK(i)) == 'I') 2208 if (kdb_task_state_char(KDB_TSK(i)) == 'I')
@@ -2210,7 +2256,7 @@ static int kdb_cpu(int argc, const char **argv)
2210 /* 2256 /*
2211 * Validate cpunum 2257 * Validate cpunum
2212 */ 2258 */
2213 if ((cpunum > NR_CPUS) || !cpu_online(cpunum)) 2259 if ((cpunum > NR_CPUS) || !kgdb_info[cpunum].enter_kgdb)
2214 return KDB_BADCPUNUM; 2260 return KDB_BADCPUNUM;
2215 2261
2216 dbg_switch_cpu = cpunum; 2262 dbg_switch_cpu = cpunum;
@@ -2375,6 +2421,8 @@ static int kdb_help(int argc, const char **argv)
2375 return 0; 2421 return 0;
2376 if (!kt->cmd_name) 2422 if (!kt->cmd_name)
2377 continue; 2423 continue;
2424 if (!kdb_check_flags(kt->cmd_flags, kdb_cmd_enabled, true))
2425 continue;
2378 if (strlen(kt->cmd_usage) > 20) 2426 if (strlen(kt->cmd_usage) > 20)
2379 space = "\n "; 2427 space = "\n ";
2380 kdb_printf("%-15.15s %-20s%s%s\n", kt->cmd_name, 2428 kdb_printf("%-15.15s %-20s%s%s\n", kt->cmd_name,
@@ -2629,7 +2677,7 @@ static int kdb_grep_help(int argc, const char **argv)
2629} 2677}
2630 2678
2631/* 2679/*
2632 * kdb_register_repeat - This function is used to register a kernel 2680 * kdb_register_flags - This function is used to register a kernel
2633 * debugger command. 2681 * debugger command.
2634 * Inputs: 2682 * Inputs:
2635 * cmd Command name 2683 * cmd Command name
@@ -2641,12 +2689,12 @@ static int kdb_grep_help(int argc, const char **argv)
2641 * zero for success, one if a duplicate command. 2689 * zero for success, one if a duplicate command.
2642 */ 2690 */
2643#define kdb_command_extend 50 /* arbitrary */ 2691#define kdb_command_extend 50 /* arbitrary */
2644int kdb_register_repeat(char *cmd, 2692int kdb_register_flags(char *cmd,
2645 kdb_func_t func, 2693 kdb_func_t func,
2646 char *usage, 2694 char *usage,
2647 char *help, 2695 char *help,
2648 short minlen, 2696 short minlen,
2649 kdb_repeat_t repeat) 2697 kdb_cmdflags_t flags)
2650{ 2698{
2651 int i; 2699 int i;
2652 kdbtab_t *kp; 2700 kdbtab_t *kp;
@@ -2694,19 +2742,18 @@ int kdb_register_repeat(char *cmd,
2694 kp->cmd_func = func; 2742 kp->cmd_func = func;
2695 kp->cmd_usage = usage; 2743 kp->cmd_usage = usage;
2696 kp->cmd_help = help; 2744 kp->cmd_help = help;
2697 kp->cmd_flags = 0;
2698 kp->cmd_minlen = minlen; 2745 kp->cmd_minlen = minlen;
2699 kp->cmd_repeat = repeat; 2746 kp->cmd_flags = flags;
2700 2747
2701 return 0; 2748 return 0;
2702} 2749}
2703EXPORT_SYMBOL_GPL(kdb_register_repeat); 2750EXPORT_SYMBOL_GPL(kdb_register_flags);
2704 2751
2705 2752
2706/* 2753/*
2707 * kdb_register - Compatibility register function for commands that do 2754 * kdb_register - Compatibility register function for commands that do
2708 * not need to specify a repeat state. Equivalent to 2755 * not need to specify a repeat state. Equivalent to
2709 * kdb_register_repeat with KDB_REPEAT_NONE. 2756 * kdb_register_flags with flags set to 0.
2710 * Inputs: 2757 * Inputs:
2711 * cmd Command name 2758 * cmd Command name
2712 * func Function to execute the command 2759 * func Function to execute the command
@@ -2721,8 +2768,7 @@ int kdb_register(char *cmd,
2721 char *help, 2768 char *help,
2722 short minlen) 2769 short minlen)
2723{ 2770{
2724 return kdb_register_repeat(cmd, func, usage, help, minlen, 2771 return kdb_register_flags(cmd, func, usage, help, minlen, 0);
2725 KDB_REPEAT_NONE);
2726} 2772}
2727EXPORT_SYMBOL_GPL(kdb_register); 2773EXPORT_SYMBOL_GPL(kdb_register);
2728 2774
@@ -2764,80 +2810,109 @@ static void __init kdb_inittab(void)
2764 for_each_kdbcmd(kp, i) 2810 for_each_kdbcmd(kp, i)
2765 kp->cmd_name = NULL; 2811 kp->cmd_name = NULL;
2766 2812
2767 kdb_register_repeat("md", kdb_md, "<vaddr>", 2813 kdb_register_flags("md", kdb_md, "<vaddr>",
2768 "Display Memory Contents, also mdWcN, e.g. md8c1", 1, 2814 "Display Memory Contents, also mdWcN, e.g. md8c1", 1,
2769 KDB_REPEAT_NO_ARGS); 2815 KDB_ENABLE_MEM_READ | KDB_REPEAT_NO_ARGS);
2770 kdb_register_repeat("mdr", kdb_md, "<vaddr> <bytes>", 2816 kdb_register_flags("mdr", kdb_md, "<vaddr> <bytes>",
2771 "Display Raw Memory", 0, KDB_REPEAT_NO_ARGS); 2817 "Display Raw Memory", 0,
2772 kdb_register_repeat("mdp", kdb_md, "<paddr> <bytes>", 2818 KDB_ENABLE_MEM_READ | KDB_REPEAT_NO_ARGS);
2773 "Display Physical Memory", 0, KDB_REPEAT_NO_ARGS); 2819 kdb_register_flags("mdp", kdb_md, "<paddr> <bytes>",
2774 kdb_register_repeat("mds", kdb_md, "<vaddr>", 2820 "Display Physical Memory", 0,
2775 "Display Memory Symbolically", 0, KDB_REPEAT_NO_ARGS); 2821 KDB_ENABLE_MEM_READ | KDB_REPEAT_NO_ARGS);
2776 kdb_register_repeat("mm", kdb_mm, "<vaddr> <contents>", 2822 kdb_register_flags("mds", kdb_md, "<vaddr>",
2777 "Modify Memory Contents", 0, KDB_REPEAT_NO_ARGS); 2823 "Display Memory Symbolically", 0,
2778 kdb_register_repeat("go", kdb_go, "[<vaddr>]", 2824 KDB_ENABLE_MEM_READ | KDB_REPEAT_NO_ARGS);
2779 "Continue Execution", 1, KDB_REPEAT_NONE); 2825 kdb_register_flags("mm", kdb_mm, "<vaddr> <contents>",
2780 kdb_register_repeat("rd", kdb_rd, "", 2826 "Modify Memory Contents", 0,
2781 "Display Registers", 0, KDB_REPEAT_NONE); 2827 KDB_ENABLE_MEM_WRITE | KDB_REPEAT_NO_ARGS);
2782 kdb_register_repeat("rm", kdb_rm, "<reg> <contents>", 2828 kdb_register_flags("go", kdb_go, "[<vaddr>]",
2783 "Modify Registers", 0, KDB_REPEAT_NONE); 2829 "Continue Execution", 1,
2784 kdb_register_repeat("ef", kdb_ef, "<vaddr>", 2830 KDB_ENABLE_REG_WRITE | KDB_ENABLE_ALWAYS_SAFE_NO_ARGS);
2785 "Display exception frame", 0, KDB_REPEAT_NONE); 2831 kdb_register_flags("rd", kdb_rd, "",
2786 kdb_register_repeat("bt", kdb_bt, "[<vaddr>]", 2832 "Display Registers", 0,
2787 "Stack traceback", 1, KDB_REPEAT_NONE); 2833 KDB_ENABLE_REG_READ);
2788 kdb_register_repeat("btp", kdb_bt, "<pid>", 2834 kdb_register_flags("rm", kdb_rm, "<reg> <contents>",
2789 "Display stack for process <pid>", 0, KDB_REPEAT_NONE); 2835 "Modify Registers", 0,
2790 kdb_register_repeat("bta", kdb_bt, "[D|R|S|T|C|Z|E|U|I|M|A]", 2836 KDB_ENABLE_REG_WRITE);
2791 "Backtrace all processes matching state flag", 0, KDB_REPEAT_NONE); 2837 kdb_register_flags("ef", kdb_ef, "<vaddr>",
2792 kdb_register_repeat("btc", kdb_bt, "", 2838 "Display exception frame", 0,
2793 "Backtrace current process on each cpu", 0, KDB_REPEAT_NONE); 2839 KDB_ENABLE_MEM_READ);
2794 kdb_register_repeat("btt", kdb_bt, "<vaddr>", 2840 kdb_register_flags("bt", kdb_bt, "[<vaddr>]",
2841 "Stack traceback", 1,
2842 KDB_ENABLE_MEM_READ | KDB_ENABLE_INSPECT_NO_ARGS);
2843 kdb_register_flags("btp", kdb_bt, "<pid>",
2844 "Display stack for process <pid>", 0,
2845 KDB_ENABLE_INSPECT);
2846 kdb_register_flags("bta", kdb_bt, "[D|R|S|T|C|Z|E|U|I|M|A]",
2847 "Backtrace all processes matching state flag", 0,
2848 KDB_ENABLE_INSPECT);
2849 kdb_register_flags("btc", kdb_bt, "",
2850 "Backtrace current process on each cpu", 0,
2851 KDB_ENABLE_INSPECT);
2852 kdb_register_flags("btt", kdb_bt, "<vaddr>",
2795 "Backtrace process given its struct task address", 0, 2853 "Backtrace process given its struct task address", 0,
2796 KDB_REPEAT_NONE); 2854 KDB_ENABLE_MEM_READ | KDB_ENABLE_INSPECT_NO_ARGS);
2797 kdb_register_repeat("env", kdb_env, "", 2855 kdb_register_flags("env", kdb_env, "",
2798 "Show environment variables", 0, KDB_REPEAT_NONE); 2856 "Show environment variables", 0,
2799 kdb_register_repeat("set", kdb_set, "", 2857 KDB_ENABLE_ALWAYS_SAFE);
2800 "Set environment variables", 0, KDB_REPEAT_NONE); 2858 kdb_register_flags("set", kdb_set, "",
2801 kdb_register_repeat("help", kdb_help, "", 2859 "Set environment variables", 0,
2802 "Display Help Message", 1, KDB_REPEAT_NONE); 2860 KDB_ENABLE_ALWAYS_SAFE);
2803 kdb_register_repeat("?", kdb_help, "", 2861 kdb_register_flags("help", kdb_help, "",
2804 "Display Help Message", 0, KDB_REPEAT_NONE); 2862 "Display Help Message", 1,
2805 kdb_register_repeat("cpu", kdb_cpu, "<cpunum>", 2863 KDB_ENABLE_ALWAYS_SAFE);
2806 "Switch to new cpu", 0, KDB_REPEAT_NONE); 2864 kdb_register_flags("?", kdb_help, "",
2807 kdb_register_repeat("kgdb", kdb_kgdb, "", 2865 "Display Help Message", 0,
2808 "Enter kgdb mode", 0, KDB_REPEAT_NONE); 2866 KDB_ENABLE_ALWAYS_SAFE);
2809 kdb_register_repeat("ps", kdb_ps, "[<flags>|A]", 2867 kdb_register_flags("cpu", kdb_cpu, "<cpunum>",
2810 "Display active task list", 0, KDB_REPEAT_NONE); 2868 "Switch to new cpu", 0,
2811 kdb_register_repeat("pid", kdb_pid, "<pidnum>", 2869 KDB_ENABLE_ALWAYS_SAFE_NO_ARGS);
2812 "Switch to another task", 0, KDB_REPEAT_NONE); 2870 kdb_register_flags("kgdb", kdb_kgdb, "",
2813 kdb_register_repeat("reboot", kdb_reboot, "", 2871 "Enter kgdb mode", 0, 0);
2814 "Reboot the machine immediately", 0, KDB_REPEAT_NONE); 2872 kdb_register_flags("ps", kdb_ps, "[<flags>|A]",
2873 "Display active task list", 0,
2874 KDB_ENABLE_INSPECT);
2875 kdb_register_flags("pid", kdb_pid, "<pidnum>",
2876 "Switch to another task", 0,
2877 KDB_ENABLE_INSPECT);
2878 kdb_register_flags("reboot", kdb_reboot, "",
2879 "Reboot the machine immediately", 0,
2880 KDB_ENABLE_REBOOT);
2815#if defined(CONFIG_MODULES) 2881#if defined(CONFIG_MODULES)
2816 kdb_register_repeat("lsmod", kdb_lsmod, "", 2882 kdb_register_flags("lsmod", kdb_lsmod, "",
2817 "List loaded kernel modules", 0, KDB_REPEAT_NONE); 2883 "List loaded kernel modules", 0,
2884 KDB_ENABLE_INSPECT);
2818#endif 2885#endif
2819#if defined(CONFIG_MAGIC_SYSRQ) 2886#if defined(CONFIG_MAGIC_SYSRQ)
2820 kdb_register_repeat("sr", kdb_sr, "<key>", 2887 kdb_register_flags("sr", kdb_sr, "<key>",
2821 "Magic SysRq key", 0, KDB_REPEAT_NONE); 2888 "Magic SysRq key", 0,
2889 KDB_ENABLE_ALWAYS_SAFE);
2822#endif 2890#endif
2823#if defined(CONFIG_PRINTK) 2891#if defined(CONFIG_PRINTK)
2824 kdb_register_repeat("dmesg", kdb_dmesg, "[lines]", 2892 kdb_register_flags("dmesg", kdb_dmesg, "[lines]",
2825 "Display syslog buffer", 0, KDB_REPEAT_NONE); 2893 "Display syslog buffer", 0,
2894 KDB_ENABLE_ALWAYS_SAFE);
2826#endif 2895#endif
2827 if (arch_kgdb_ops.enable_nmi) { 2896 if (arch_kgdb_ops.enable_nmi) {
2828 kdb_register_repeat("disable_nmi", kdb_disable_nmi, "", 2897 kdb_register_flags("disable_nmi", kdb_disable_nmi, "",
2829 "Disable NMI entry to KDB", 0, KDB_REPEAT_NONE); 2898 "Disable NMI entry to KDB", 0,
2830 } 2899 KDB_ENABLE_ALWAYS_SAFE);
2831 kdb_register_repeat("defcmd", kdb_defcmd, "name \"usage\" \"help\"", 2900 }
2832 "Define a set of commands, down to endefcmd", 0, KDB_REPEAT_NONE); 2901 kdb_register_flags("defcmd", kdb_defcmd, "name \"usage\" \"help\"",
2833 kdb_register_repeat("kill", kdb_kill, "<-signal> <pid>", 2902 "Define a set of commands, down to endefcmd", 0,
2834 "Send a signal to a process", 0, KDB_REPEAT_NONE); 2903 KDB_ENABLE_ALWAYS_SAFE);
2835 kdb_register_repeat("summary", kdb_summary, "", 2904 kdb_register_flags("kill", kdb_kill, "<-signal> <pid>",
2836 "Summarize the system", 4, KDB_REPEAT_NONE); 2905 "Send a signal to a process", 0,
2837 kdb_register_repeat("per_cpu", kdb_per_cpu, "<sym> [<bytes>] [<cpu>]", 2906 KDB_ENABLE_SIGNAL);
2838 "Display per_cpu variables", 3, KDB_REPEAT_NONE); 2907 kdb_register_flags("summary", kdb_summary, "",
2839 kdb_register_repeat("grephelp", kdb_grep_help, "", 2908 "Summarize the system", 4,
2840 "Display help on | grep", 0, KDB_REPEAT_NONE); 2909 KDB_ENABLE_ALWAYS_SAFE);
2910 kdb_register_flags("per_cpu", kdb_per_cpu, "<sym> [<bytes>] [<cpu>]",
2911 "Display per_cpu variables", 3,
2912 KDB_ENABLE_MEM_READ);
2913 kdb_register_flags("grephelp", kdb_grep_help, "",
2914 "Display help on | grep", 0,
2915 KDB_ENABLE_ALWAYS_SAFE);
2841} 2916}
2842 2917
2843/* Execute any commands defined in kdb_cmds. */ 2918/* Execute any commands defined in kdb_cmds. */
diff --git a/kernel/debug/kdb/kdb_private.h b/kernel/debug/kdb/kdb_private.h
index 7afd3c8c41d5..eaacd1693954 100644
--- a/kernel/debug/kdb/kdb_private.h
+++ b/kernel/debug/kdb/kdb_private.h
@@ -172,10 +172,9 @@ typedef struct _kdbtab {
172 kdb_func_t cmd_func; /* Function to execute command */ 172 kdb_func_t cmd_func; /* Function to execute command */
173 char *cmd_usage; /* Usage String for this command */ 173 char *cmd_usage; /* Usage String for this command */
174 char *cmd_help; /* Help message for this command */ 174 char *cmd_help; /* Help message for this command */
175 short cmd_flags; /* Parsing flags */
176 short cmd_minlen; /* Minimum legal # command 175 short cmd_minlen; /* Minimum legal # command
177 * chars required */ 176 * chars required */
178 kdb_repeat_t cmd_repeat; /* Does command auto repeat on enter? */ 177 kdb_cmdflags_t cmd_flags; /* Command behaviour flags */
179} kdbtab_t; 178} kdbtab_t;
180 179
181extern int kdb_bt(int, const char **); /* KDB display back trace */ 180extern int kdb_bt(int, const char **); /* KDB display back trace */
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4c1ee7f2bebc..882f835a0d85 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -4461,18 +4461,14 @@ perf_output_sample_regs(struct perf_output_handle *handle,
4461} 4461}
4462 4462
4463static void perf_sample_regs_user(struct perf_regs *regs_user, 4463static void perf_sample_regs_user(struct perf_regs *regs_user,
4464 struct pt_regs *regs) 4464 struct pt_regs *regs,
4465 struct pt_regs *regs_user_copy)
4465{ 4466{
4466 if (!user_mode(regs)) { 4467 if (user_mode(regs)) {
4467 if (current->mm) 4468 regs_user->abi = perf_reg_abi(current);
4468 regs = task_pt_regs(current);
4469 else
4470 regs = NULL;
4471 }
4472
4473 if (regs) {
4474 regs_user->abi = perf_reg_abi(current);
4475 regs_user->regs = regs; 4469 regs_user->regs = regs;
4470 } else if (current->mm) {
4471 perf_get_regs_user(regs_user, regs, regs_user_copy);
4476 } else { 4472 } else {
4477 regs_user->abi = PERF_SAMPLE_REGS_ABI_NONE; 4473 regs_user->abi = PERF_SAMPLE_REGS_ABI_NONE;
4478 regs_user->regs = NULL; 4474 regs_user->regs = NULL;
@@ -4951,7 +4947,8 @@ void perf_prepare_sample(struct perf_event_header *header,
4951 } 4947 }
4952 4948
4953 if (sample_type & (PERF_SAMPLE_REGS_USER | PERF_SAMPLE_STACK_USER)) 4949 if (sample_type & (PERF_SAMPLE_REGS_USER | PERF_SAMPLE_STACK_USER))
4954 perf_sample_regs_user(&data->regs_user, regs); 4950 perf_sample_regs_user(&data->regs_user, regs,
4951 &data->regs_user_copy);
4955 4952
4956 if (sample_type & PERF_SAMPLE_REGS_USER) { 4953 if (sample_type & PERF_SAMPLE_REGS_USER) {
4957 /* regs dump ABI info */ 4954 /* regs dump ABI info */
diff --git a/kernel/exit.c b/kernel/exit.c
index 1ea4369890a3..6806c55475ee 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -1287,9 +1287,15 @@ static int wait_task_continued(struct wait_opts *wo, struct task_struct *p)
1287static int wait_consider_task(struct wait_opts *wo, int ptrace, 1287static int wait_consider_task(struct wait_opts *wo, int ptrace,
1288 struct task_struct *p) 1288 struct task_struct *p)
1289{ 1289{
1290 /*
1291 * We can race with wait_task_zombie() from another thread.
1292 * Ensure that EXIT_ZOMBIE -> EXIT_DEAD/EXIT_TRACE transition
1293 * can't confuse the checks below.
1294 */
1295 int exit_state = ACCESS_ONCE(p->exit_state);
1290 int ret; 1296 int ret;
1291 1297
1292 if (unlikely(p->exit_state == EXIT_DEAD)) 1298 if (unlikely(exit_state == EXIT_DEAD))
1293 return 0; 1299 return 0;
1294 1300
1295 ret = eligible_child(wo, p); 1301 ret = eligible_child(wo, p);
@@ -1310,7 +1316,7 @@ static int wait_consider_task(struct wait_opts *wo, int ptrace,
1310 return 0; 1316 return 0;
1311 } 1317 }
1312 1318
1313 if (unlikely(p->exit_state == EXIT_TRACE)) { 1319 if (unlikely(exit_state == EXIT_TRACE)) {
1314 /* 1320 /*
1315 * ptrace == 0 means we are the natural parent. In this case 1321 * ptrace == 0 means we are the natural parent. In this case
1316 * we should clear notask_error, debugger will notify us. 1322 * we should clear notask_error, debugger will notify us.
@@ -1337,7 +1343,7 @@ static int wait_consider_task(struct wait_opts *wo, int ptrace,
1337 } 1343 }
1338 1344
1339 /* slay zombie? */ 1345 /* slay zombie? */
1340 if (p->exit_state == EXIT_ZOMBIE) { 1346 if (exit_state == EXIT_ZOMBIE) {
1341 /* we don't reap group leaders with subthreads */ 1347 /* we don't reap group leaders with subthreads */
1342 if (!delay_group_leader(p)) { 1348 if (!delay_group_leader(p)) {
1343 /* 1349 /*
diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
index 5cf6731b98e9..3ef3736002d8 100644
--- a/kernel/locking/mutex-debug.c
+++ b/kernel/locking/mutex-debug.c
@@ -80,13 +80,13 @@ void debug_mutex_unlock(struct mutex *lock)
80 DEBUG_LOCKS_WARN_ON(lock->owner != current); 80 DEBUG_LOCKS_WARN_ON(lock->owner != current);
81 81
82 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next); 82 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
83 mutex_clear_owner(lock);
84 } 83 }
85 84
86 /* 85 /*
87 * __mutex_slowpath_needs_to_unlock() is explicitly 0 for debug 86 * __mutex_slowpath_needs_to_unlock() is explicitly 0 for debug
88 * mutexes so that we can do it here after we've verified state. 87 * mutexes so that we can do it here after we've verified state.
89 */ 88 */
89 mutex_clear_owner(lock);
90 atomic_set(&lock->count, 1); 90 atomic_set(&lock->count, 1);
91} 91}
92 92
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index b5797b78add6..c0accc00566e 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7113,9 +7113,6 @@ void __init sched_init(void)
7113#ifdef CONFIG_RT_GROUP_SCHED 7113#ifdef CONFIG_RT_GROUP_SCHED
7114 alloc_size += 2 * nr_cpu_ids * sizeof(void **); 7114 alloc_size += 2 * nr_cpu_ids * sizeof(void **);
7115#endif 7115#endif
7116#ifdef CONFIG_CPUMASK_OFFSTACK
7117 alloc_size += num_possible_cpus() * cpumask_size();
7118#endif
7119 if (alloc_size) { 7116 if (alloc_size) {
7120 ptr = (unsigned long)kzalloc(alloc_size, GFP_NOWAIT); 7117 ptr = (unsigned long)kzalloc(alloc_size, GFP_NOWAIT);
7121 7118
@@ -7135,13 +7132,13 @@ void __init sched_init(void)
7135 ptr += nr_cpu_ids * sizeof(void **); 7132 ptr += nr_cpu_ids * sizeof(void **);
7136 7133
7137#endif /* CONFIG_RT_GROUP_SCHED */ 7134#endif /* CONFIG_RT_GROUP_SCHED */
7135 }
7138#ifdef CONFIG_CPUMASK_OFFSTACK 7136#ifdef CONFIG_CPUMASK_OFFSTACK
7139 for_each_possible_cpu(i) { 7137 for_each_possible_cpu(i) {
7140 per_cpu(load_balance_mask, i) = (void *)ptr; 7138 per_cpu(load_balance_mask, i) = (cpumask_var_t)kzalloc_node(
7141 ptr += cpumask_size(); 7139 cpumask_size(), GFP_KERNEL, cpu_to_node(i));
7142 }
7143#endif /* CONFIG_CPUMASK_OFFSTACK */
7144 } 7140 }
7141#endif /* CONFIG_CPUMASK_OFFSTACK */
7145 7142
7146 init_rt_bandwidth(&def_rt_bandwidth, 7143 init_rt_bandwidth(&def_rt_bandwidth,
7147 global_rt_period(), global_rt_runtime()); 7144 global_rt_period(), global_rt_runtime());
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index e5db8c6feebd..b52092f2636d 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -570,24 +570,7 @@ void init_dl_task_timer(struct sched_dl_entity *dl_se)
570static 570static
571int dl_runtime_exceeded(struct rq *rq, struct sched_dl_entity *dl_se) 571int dl_runtime_exceeded(struct rq *rq, struct sched_dl_entity *dl_se)
572{ 572{
573 int dmiss = dl_time_before(dl_se->deadline, rq_clock(rq)); 573 return (dl_se->runtime <= 0);
574 int rorun = dl_se->runtime <= 0;
575
576 if (!rorun && !dmiss)
577 return 0;
578
579 /*
580 * If we are beyond our current deadline and we are still
581 * executing, then we have already used some of the runtime of
582 * the next instance. Thus, if we do not account that, we are
583 * stealing bandwidth from the system at each deadline miss!
584 */
585 if (dmiss) {
586 dl_se->runtime = rorun ? dl_se->runtime : 0;
587 dl_se->runtime -= rq_clock(rq) - dl_se->deadline;
588 }
589
590 return 1;
591} 574}
592 575
593extern bool sched_rt_bandwidth_account(struct rt_rq *rt_rq); 576extern bool sched_rt_bandwidth_account(struct rt_rq *rt_rq);
@@ -826,10 +809,10 @@ enqueue_dl_entity(struct sched_dl_entity *dl_se,
826 * parameters of the task might need updating. Otherwise, 809 * parameters of the task might need updating. Otherwise,
827 * we want a replenishment of its runtime. 810 * we want a replenishment of its runtime.
828 */ 811 */
829 if (!dl_se->dl_new && flags & ENQUEUE_REPLENISH) 812 if (dl_se->dl_new || flags & ENQUEUE_WAKEUP)
830 replenish_dl_entity(dl_se, pi_se);
831 else
832 update_dl_entity(dl_se, pi_se); 813 update_dl_entity(dl_se, pi_se);
814 else if (flags & ENQUEUE_REPLENISH)
815 replenish_dl_entity(dl_se, pi_se);
833 816
834 __enqueue_dl_entity(dl_se); 817 __enqueue_dl_entity(dl_se);
835} 818}
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index df2cdf77f899..40667cbf371b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4005,6 +4005,10 @@ void __start_cfs_bandwidth(struct cfs_bandwidth *cfs_b, bool force)
4005 4005
4006static void destroy_cfs_bandwidth(struct cfs_bandwidth *cfs_b) 4006static void destroy_cfs_bandwidth(struct cfs_bandwidth *cfs_b)
4007{ 4007{
4008 /* init_cfs_bandwidth() was not called */
4009 if (!cfs_b->throttled_cfs_rq.next)
4010 return;
4011
4008 hrtimer_cancel(&cfs_b->period_timer); 4012 hrtimer_cancel(&cfs_b->period_timer);
4009 hrtimer_cancel(&cfs_b->slack_timer); 4013 hrtimer_cancel(&cfs_b->slack_timer);
4010} 4014}
@@ -4424,7 +4428,7 @@ static long effective_load(struct task_group *tg, int cpu, long wl, long wg)
4424 * wl = S * s'_i; see (2) 4428 * wl = S * s'_i; see (2)
4425 */ 4429 */
4426 if (W > 0 && w < W) 4430 if (W > 0 && w < W)
4427 wl = (w * tg->shares) / W; 4431 wl = (w * (long)tg->shares) / W;
4428 else 4432 else
4429 wl = tg->shares; 4433 wl = tg->shares;
4430 4434
diff --git a/kernel/trace/trace_kdb.c b/kernel/trace/trace_kdb.c
index b0b1c44e923a..3ccf5c2c1320 100644
--- a/kernel/trace/trace_kdb.c
+++ b/kernel/trace/trace_kdb.c
@@ -132,8 +132,8 @@ static int kdb_ftdump(int argc, const char **argv)
132 132
133static __init int kdb_ftrace_register(void) 133static __init int kdb_ftrace_register(void)
134{ 134{
135 kdb_register_repeat("ftdump", kdb_ftdump, "[skip_#lines] [cpu]", 135 kdb_register_flags("ftdump", kdb_ftdump, "[skip_#lines] [cpu]",
136 "Dump ftrace log", 0, KDB_REPEAT_NONE); 136 "Dump ftrace log", 0, KDB_ENABLE_ALWAYS_SAFE);
137 return 0; 137 return 0;
138} 138}
139 139
diff --git a/lib/Kconfig.kgdb b/lib/Kconfig.kgdb
index 358eb81fa28d..c635a107a7de 100644
--- a/lib/Kconfig.kgdb
+++ b/lib/Kconfig.kgdb
@@ -73,6 +73,31 @@ config KGDB_KDB
73 help 73 help
74 KDB frontend for kernel 74 KDB frontend for kernel
75 75
76config KDB_DEFAULT_ENABLE
77 hex "KDB: Select kdb command functions to be enabled by default"
78 depends on KGDB_KDB
79 default 0x1
80 help
81 Specifiers which kdb commands are enabled by default. This may
82 be set to 1 or 0 to enable all commands or disable almost all
83 commands.
84
85 Alternatively the following bitmask applies:
86
87 0x0002 - allow arbitrary reads from memory and symbol lookup
88 0x0004 - allow arbitrary writes to memory
89 0x0008 - allow current register state to be inspected
90 0x0010 - allow current register state to be modified
91 0x0020 - allow passive inspection (backtrace, process list, lsmod)
92 0x0040 - allow flow control management (breakpoint, single step)
93 0x0080 - enable signalling of processes
94 0x0100 - allow machine to be rebooted
95
96 The config option merely sets the default at boot time. Both
97 issuing 'echo X > /sys/module/kdb/parameters/cmd_enable' or
98 setting with kdb.cmd_enable=X kernel command line option will
99 override the default settings.
100
76config KDB_KEYBOARD 101config KDB_KEYBOARD
77 bool "KGDB_KDB: keyboard as input device" 102 bool "KGDB_KDB: keyboard as input device"
78 depends on VT && KGDB_KDB 103 depends on VT && KGDB_KDB
diff --git a/lib/assoc_array.c b/lib/assoc_array.c
index 2404d03e251a..03dd576e6773 100644
--- a/lib/assoc_array.c
+++ b/lib/assoc_array.c
@@ -11,6 +11,7 @@
11 * 2 of the Licence, or (at your option) any later version. 11 * 2 of the Licence, or (at your option) any later version.
12 */ 12 */
13//#define DEBUG 13//#define DEBUG
14#include <linux/rcupdate.h>
14#include <linux/slab.h> 15#include <linux/slab.h>
15#include <linux/err.h> 16#include <linux/err.h>
16#include <linux/assoc_array_priv.h> 17#include <linux/assoc_array_priv.h>
diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug
index 56badfc4810a..957d3da53ddd 100644
--- a/mm/Kconfig.debug
+++ b/mm/Kconfig.debug
@@ -14,7 +14,6 @@ config DEBUG_PAGEALLOC
14 depends on !KMEMCHECK 14 depends on !KMEMCHECK
15 select PAGE_EXTENSION 15 select PAGE_EXTENSION
16 select PAGE_POISONING if !ARCH_SUPPORTS_DEBUG_PAGEALLOC 16 select PAGE_POISONING if !ARCH_SUPPORTS_DEBUG_PAGEALLOC
17 select PAGE_GUARD if ARCH_SUPPORTS_DEBUG_PAGEALLOC
18 ---help--- 17 ---help---
19 Unmap pages from the kernel linear mapping after free_pages(). 18 Unmap pages from the kernel linear mapping after free_pages().
20 This results in a large slowdown, but helps to find certain types 19 This results in a large slowdown, but helps to find certain types
@@ -27,13 +26,5 @@ config DEBUG_PAGEALLOC
27 that would result in incorrect warnings of memory corruption after 26 that would result in incorrect warnings of memory corruption after
28 a resume because free pages are not saved to the suspend image. 27 a resume because free pages are not saved to the suspend image.
29 28
30config WANT_PAGE_DEBUG_FLAGS
31 bool
32
33config PAGE_POISONING 29config PAGE_POISONING
34 bool 30 bool
35 select WANT_PAGE_DEBUG_FLAGS
36
37config PAGE_GUARD
38 bool
39 select WANT_PAGE_DEBUG_FLAGS
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index ef91e856c7e4..851924fa5170 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3043,18 +3043,6 @@ static int mem_cgroup_move_swap_account(swp_entry_t entry,
3043 if (swap_cgroup_cmpxchg(entry, old_id, new_id) == old_id) { 3043 if (swap_cgroup_cmpxchg(entry, old_id, new_id) == old_id) {
3044 mem_cgroup_swap_statistics(from, false); 3044 mem_cgroup_swap_statistics(from, false);
3045 mem_cgroup_swap_statistics(to, true); 3045 mem_cgroup_swap_statistics(to, true);
3046 /*
3047 * This function is only called from task migration context now.
3048 * It postpones page_counter and refcount handling till the end
3049 * of task migration(mem_cgroup_clear_mc()) for performance
3050 * improvement. But we cannot postpone css_get(to) because if
3051 * the process that has been moved to @to does swap-in, the
3052 * refcount of @to might be decreased to 0.
3053 *
3054 * We are in attach() phase, so the cgroup is guaranteed to be
3055 * alive, so we can just call css_get().
3056 */
3057 css_get(&to->css);
3058 return 0; 3046 return 0;
3059 } 3047 }
3060 return -EINVAL; 3048 return -EINVAL;
@@ -4679,6 +4667,7 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
4679 if (parent_css == NULL) { 4667 if (parent_css == NULL) {
4680 root_mem_cgroup = memcg; 4668 root_mem_cgroup = memcg;
4681 page_counter_init(&memcg->memory, NULL); 4669 page_counter_init(&memcg->memory, NULL);
4670 memcg->soft_limit = PAGE_COUNTER_MAX;
4682 page_counter_init(&memcg->memsw, NULL); 4671 page_counter_init(&memcg->memsw, NULL);
4683 page_counter_init(&memcg->kmem, NULL); 4672 page_counter_init(&memcg->kmem, NULL);
4684 } 4673 }
@@ -4724,6 +4713,7 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)
4724 4713
4725 if (parent->use_hierarchy) { 4714 if (parent->use_hierarchy) {
4726 page_counter_init(&memcg->memory, &parent->memory); 4715 page_counter_init(&memcg->memory, &parent->memory);
4716 memcg->soft_limit = PAGE_COUNTER_MAX;
4727 page_counter_init(&memcg->memsw, &parent->memsw); 4717 page_counter_init(&memcg->memsw, &parent->memsw);
4728 page_counter_init(&memcg->kmem, &parent->kmem); 4718 page_counter_init(&memcg->kmem, &parent->kmem);
4729 4719
@@ -4733,6 +4723,7 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)
4733 */ 4723 */
4734 } else { 4724 } else {
4735 page_counter_init(&memcg->memory, NULL); 4725 page_counter_init(&memcg->memory, NULL);
4726 memcg->soft_limit = PAGE_COUNTER_MAX;
4736 page_counter_init(&memcg->memsw, NULL); 4727 page_counter_init(&memcg->memsw, NULL);
4737 page_counter_init(&memcg->kmem, NULL); 4728 page_counter_init(&memcg->kmem, NULL);
4738 /* 4729 /*
@@ -4807,7 +4798,7 @@ static void mem_cgroup_css_reset(struct cgroup_subsys_state *css)
4807 mem_cgroup_resize_limit(memcg, PAGE_COUNTER_MAX); 4798 mem_cgroup_resize_limit(memcg, PAGE_COUNTER_MAX);
4808 mem_cgroup_resize_memsw_limit(memcg, PAGE_COUNTER_MAX); 4799 mem_cgroup_resize_memsw_limit(memcg, PAGE_COUNTER_MAX);
4809 memcg_update_kmem_limit(memcg, PAGE_COUNTER_MAX); 4800 memcg_update_kmem_limit(memcg, PAGE_COUNTER_MAX);
4810 memcg->soft_limit = 0; 4801 memcg->soft_limit = PAGE_COUNTER_MAX;
4811} 4802}
4812 4803
4813#ifdef CONFIG_MMU 4804#ifdef CONFIG_MMU
diff --git a/mm/memory.c b/mm/memory.c
index ca920d1fd314..54f3a9b00956 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -235,6 +235,9 @@ void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long
235 235
236static void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb) 236static void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb)
237{ 237{
238 if (!tlb->end)
239 return;
240
238 tlb_flush(tlb); 241 tlb_flush(tlb);
239 mmu_notifier_invalidate_range(tlb->mm, tlb->start, tlb->end); 242 mmu_notifier_invalidate_range(tlb->mm, tlb->start, tlb->end);
240#ifdef CONFIG_HAVE_RCU_TABLE_FREE 243#ifdef CONFIG_HAVE_RCU_TABLE_FREE
@@ -247,7 +250,7 @@ static void tlb_flush_mmu_free(struct mmu_gather *tlb)
247{ 250{
248 struct mmu_gather_batch *batch; 251 struct mmu_gather_batch *batch;
249 252
250 for (batch = &tlb->local; batch; batch = batch->next) { 253 for (batch = &tlb->local; batch && batch->nr; batch = batch->next) {
251 free_pages_and_swap_cache(batch->pages, batch->nr); 254 free_pages_and_swap_cache(batch->pages, batch->nr);
252 batch->nr = 0; 255 batch->nr = 0;
253 } 256 }
@@ -256,9 +259,6 @@ static void tlb_flush_mmu_free(struct mmu_gather *tlb)
256 259
257void tlb_flush_mmu(struct mmu_gather *tlb) 260void tlb_flush_mmu(struct mmu_gather *tlb)
258{ 261{
259 if (!tlb->end)
260 return;
261
262 tlb_flush_mmu_tlbonly(tlb); 262 tlb_flush_mmu_tlbonly(tlb);
263 tlb_flush_mmu_free(tlb); 263 tlb_flush_mmu_free(tlb);
264} 264}
@@ -2137,17 +2137,24 @@ reuse:
2137 if (!dirty_page) 2137 if (!dirty_page)
2138 return ret; 2138 return ret;
2139 2139
2140 /*
2141 * Yes, Virginia, this is actually required to prevent a race
2142 * with clear_page_dirty_for_io() from clearing the page dirty
2143 * bit after it clear all dirty ptes, but before a racing
2144 * do_wp_page installs a dirty pte.
2145 *
2146 * do_shared_fault is protected similarly.
2147 */
2148 if (!page_mkwrite) { 2140 if (!page_mkwrite) {
2149 wait_on_page_locked(dirty_page); 2141 struct address_space *mapping;
2150 set_page_dirty_balance(dirty_page); 2142 int dirtied;
2143
2144 lock_page(dirty_page);
2145 dirtied = set_page_dirty(dirty_page);
2146 VM_BUG_ON_PAGE(PageAnon(dirty_page), dirty_page);
2147 mapping = dirty_page->mapping;
2148 unlock_page(dirty_page);
2149
2150 if (dirtied && mapping) {
2151 /*
2152 * Some device drivers do not set page.mapping
2153 * but still dirty their pages
2154 */
2155 balance_dirty_pages_ratelimited(mapping);
2156 }
2157
2151 /* file_update_time outside page_lock */ 2158 /* file_update_time outside page_lock */
2152 if (vma->vm_file) 2159 if (vma->vm_file)
2153 file_update_time(vma->vm_file); 2160 file_update_time(vma->vm_file);
@@ -2593,7 +2600,7 @@ static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned lo
2593 if (prev && prev->vm_end == address) 2600 if (prev && prev->vm_end == address)
2594 return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM; 2601 return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
2595 2602
2596 expand_downwards(vma, address - PAGE_SIZE); 2603 return expand_downwards(vma, address - PAGE_SIZE);
2597 } 2604 }
2598 if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) { 2605 if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
2599 struct vm_area_struct *next = vma->vm_next; 2606 struct vm_area_struct *next = vma->vm_next;
@@ -2602,7 +2609,7 @@ static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned lo
2602 if (next && next->vm_start == address + PAGE_SIZE) 2609 if (next && next->vm_start == address + PAGE_SIZE)
2603 return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM; 2610 return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
2604 2611
2605 expand_upwards(vma, address + PAGE_SIZE); 2612 return expand_upwards(vma, address + PAGE_SIZE);
2606 } 2613 }
2607 return 0; 2614 return 0;
2608} 2615}
diff --git a/mm/mmap.c b/mm/mmap.c
index 7b36aa7cc89a..7f684d5a8087 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -778,10 +778,12 @@ again: remove_next = 1 + (end > next->vm_end);
778 if (exporter && exporter->anon_vma && !importer->anon_vma) { 778 if (exporter && exporter->anon_vma && !importer->anon_vma) {
779 int error; 779 int error;
780 780
781 importer->anon_vma = exporter->anon_vma;
781 error = anon_vma_clone(importer, exporter); 782 error = anon_vma_clone(importer, exporter);
782 if (error) 783 if (error) {
784 importer->anon_vma = NULL;
783 return error; 785 return error;
784 importer->anon_vma = exporter->anon_vma; 786 }
785 } 787 }
786 } 788 }
787 789
@@ -2099,14 +2101,17 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
2099{ 2101{
2100 struct mm_struct *mm = vma->vm_mm; 2102 struct mm_struct *mm = vma->vm_mm;
2101 struct rlimit *rlim = current->signal->rlim; 2103 struct rlimit *rlim = current->signal->rlim;
2102 unsigned long new_start; 2104 unsigned long new_start, actual_size;
2103 2105
2104 /* address space limit tests */ 2106 /* address space limit tests */
2105 if (!may_expand_vm(mm, grow)) 2107 if (!may_expand_vm(mm, grow))
2106 return -ENOMEM; 2108 return -ENOMEM;
2107 2109
2108 /* Stack limit test */ 2110 /* Stack limit test */
2109 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur)) 2111 actual_size = size;
2112 if (size && (vma->vm_flags & (VM_GROWSUP | VM_GROWSDOWN)))
2113 actual_size -= PAGE_SIZE;
2114 if (actual_size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
2110 return -ENOMEM; 2115 return -ENOMEM;
2111 2116
2112 /* mlock limit tests */ 2117 /* mlock limit tests */
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index d5d81f5384d1..6f4335238e33 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -1541,16 +1541,6 @@ pause:
1541 bdi_start_background_writeback(bdi); 1541 bdi_start_background_writeback(bdi);
1542} 1542}
1543 1543
1544void set_page_dirty_balance(struct page *page)
1545{
1546 if (set_page_dirty(page)) {
1547 struct address_space *mapping = page_mapping(page);
1548
1549 if (mapping)
1550 balance_dirty_pages_ratelimited(mapping);
1551 }
1552}
1553
1554static DEFINE_PER_CPU(int, bdp_ratelimits); 1544static DEFINE_PER_CPU(int, bdp_ratelimits);
1555 1545
1556/* 1546/*
@@ -2123,32 +2113,25 @@ EXPORT_SYMBOL(account_page_dirtied);
2123 * page dirty in that case, but not all the buffers. This is a "bottom-up" 2113 * page dirty in that case, but not all the buffers. This is a "bottom-up"
2124 * dirtying, whereas __set_page_dirty_buffers() is a "top-down" dirtying. 2114 * dirtying, whereas __set_page_dirty_buffers() is a "top-down" dirtying.
2125 * 2115 *
2126 * Most callers have locked the page, which pins the address_space in memory. 2116 * The caller must ensure this doesn't race with truncation. Most will simply
2127 * But zap_pte_range() does not lock the page, however in that case the 2117 * hold the page lock, but e.g. zap_pte_range() calls with the page mapped and
2128 * mapping is pinned by the vma's ->vm_file reference. 2118 * the pte lock held, which also locks out truncation.
2129 *
2130 * We take care to handle the case where the page was truncated from the
2131 * mapping by re-checking page_mapping() inside tree_lock.
2132 */ 2119 */
2133int __set_page_dirty_nobuffers(struct page *page) 2120int __set_page_dirty_nobuffers(struct page *page)
2134{ 2121{
2135 if (!TestSetPageDirty(page)) { 2122 if (!TestSetPageDirty(page)) {
2136 struct address_space *mapping = page_mapping(page); 2123 struct address_space *mapping = page_mapping(page);
2137 struct address_space *mapping2;
2138 unsigned long flags; 2124 unsigned long flags;
2139 2125
2140 if (!mapping) 2126 if (!mapping)
2141 return 1; 2127 return 1;
2142 2128
2143 spin_lock_irqsave(&mapping->tree_lock, flags); 2129 spin_lock_irqsave(&mapping->tree_lock, flags);
2144 mapping2 = page_mapping(page); 2130 BUG_ON(page_mapping(page) != mapping);
2145 if (mapping2) { /* Race with truncate? */ 2131 WARN_ON_ONCE(!PagePrivate(page) && !PageUptodate(page));
2146 BUG_ON(mapping2 != mapping); 2132 account_page_dirtied(page, mapping);
2147 WARN_ON_ONCE(!PagePrivate(page) && !PageUptodate(page)); 2133 radix_tree_tag_set(&mapping->page_tree, page_index(page),
2148 account_page_dirtied(page, mapping); 2134 PAGECACHE_TAG_DIRTY);
2149 radix_tree_tag_set(&mapping->page_tree,
2150 page_index(page), PAGECACHE_TAG_DIRTY);
2151 }
2152 spin_unlock_irqrestore(&mapping->tree_lock, flags); 2135 spin_unlock_irqrestore(&mapping->tree_lock, flags);
2153 if (mapping->host) { 2136 if (mapping->host) {
2154 /* !PageAnon && !swapper_space */ 2137 /* !PageAnon && !swapper_space */
@@ -2305,12 +2288,10 @@ int clear_page_dirty_for_io(struct page *page)
2305 /* 2288 /*
2306 * We carefully synchronise fault handlers against 2289 * We carefully synchronise fault handlers against
2307 * installing a dirty pte and marking the page dirty 2290 * installing a dirty pte and marking the page dirty
2308 * at this point. We do this by having them hold the 2291 * at this point. We do this by having them hold the
2309 * page lock at some point after installing their 2292 * page lock while dirtying the page, and pages are
2310 * pte, but before marking the page dirty. 2293 * always locked coming in here, so we get the desired
2311 * Pages are always locked coming in here, so we get 2294 * exclusion.
2312 * the desired exclusion. See mm/memory.c:do_wp_page()
2313 * for more comments.
2314 */ 2295 */
2315 if (TestClearPageDirty(page)) { 2296 if (TestClearPageDirty(page)) {
2316 dec_zone_page_state(page, NR_FILE_DIRTY); 2297 dec_zone_page_state(page, NR_FILE_DIRTY);
diff --git a/mm/rmap.c b/mm/rmap.c
index c5bc241127b2..71cd5bd0c17d 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -72,6 +72,8 @@ static inline struct anon_vma *anon_vma_alloc(void)
72 anon_vma = kmem_cache_alloc(anon_vma_cachep, GFP_KERNEL); 72 anon_vma = kmem_cache_alloc(anon_vma_cachep, GFP_KERNEL);
73 if (anon_vma) { 73 if (anon_vma) {
74 atomic_set(&anon_vma->refcount, 1); 74 atomic_set(&anon_vma->refcount, 1);
75 anon_vma->degree = 1; /* Reference for first vma */
76 anon_vma->parent = anon_vma;
75 /* 77 /*
76 * Initialise the anon_vma root to point to itself. If called 78 * Initialise the anon_vma root to point to itself. If called
77 * from fork, the root will be reset to the parents anon_vma. 79 * from fork, the root will be reset to the parents anon_vma.
@@ -188,6 +190,8 @@ int anon_vma_prepare(struct vm_area_struct *vma)
188 if (likely(!vma->anon_vma)) { 190 if (likely(!vma->anon_vma)) {
189 vma->anon_vma = anon_vma; 191 vma->anon_vma = anon_vma;
190 anon_vma_chain_link(vma, avc, anon_vma); 192 anon_vma_chain_link(vma, avc, anon_vma);
193 /* vma reference or self-parent link for new root */
194 anon_vma->degree++;
191 allocated = NULL; 195 allocated = NULL;
192 avc = NULL; 196 avc = NULL;
193 } 197 }
@@ -236,6 +240,14 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
236/* 240/*
237 * Attach the anon_vmas from src to dst. 241 * Attach the anon_vmas from src to dst.
238 * Returns 0 on success, -ENOMEM on failure. 242 * Returns 0 on success, -ENOMEM on failure.
243 *
244 * If dst->anon_vma is NULL this function tries to find and reuse existing
245 * anon_vma which has no vmas and only one child anon_vma. This prevents
246 * degradation of anon_vma hierarchy to endless linear chain in case of
247 * constantly forking task. On the other hand, an anon_vma with more than one
248 * child isn't reused even if there was no alive vma, thus rmap walker has a
249 * good chance of avoiding scanning the whole hierarchy when it searches where
250 * page is mapped.
239 */ 251 */
240int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src) 252int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
241{ 253{
@@ -256,7 +268,21 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
256 anon_vma = pavc->anon_vma; 268 anon_vma = pavc->anon_vma;
257 root = lock_anon_vma_root(root, anon_vma); 269 root = lock_anon_vma_root(root, anon_vma);
258 anon_vma_chain_link(dst, avc, anon_vma); 270 anon_vma_chain_link(dst, avc, anon_vma);
271
272 /*
273 * Reuse existing anon_vma if its degree lower than two,
274 * that means it has no vma and only one anon_vma child.
275 *
276 * Do not chose parent anon_vma, otherwise first child
277 * will always reuse it. Root anon_vma is never reused:
278 * it has self-parent reference and at least one child.
279 */
280 if (!dst->anon_vma && anon_vma != src->anon_vma &&
281 anon_vma->degree < 2)
282 dst->anon_vma = anon_vma;
259 } 283 }
284 if (dst->anon_vma)
285 dst->anon_vma->degree++;
260 unlock_anon_vma_root(root); 286 unlock_anon_vma_root(root);
261 return 0; 287 return 0;
262 288
@@ -280,6 +306,9 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
280 if (!pvma->anon_vma) 306 if (!pvma->anon_vma)
281 return 0; 307 return 0;
282 308
309 /* Drop inherited anon_vma, we'll reuse existing or allocate new. */
310 vma->anon_vma = NULL;
311
283 /* 312 /*
284 * First, attach the new VMA to the parent VMA's anon_vmas, 313 * First, attach the new VMA to the parent VMA's anon_vmas,
285 * so rmap can find non-COWed pages in child processes. 314 * so rmap can find non-COWed pages in child processes.
@@ -288,6 +317,10 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
288 if (error) 317 if (error)
289 return error; 318 return error;
290 319
320 /* An existing anon_vma has been reused, all done then. */
321 if (vma->anon_vma)
322 return 0;
323
291 /* Then add our own anon_vma. */ 324 /* Then add our own anon_vma. */
292 anon_vma = anon_vma_alloc(); 325 anon_vma = anon_vma_alloc();
293 if (!anon_vma) 326 if (!anon_vma)
@@ -301,6 +334,7 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
301 * lock any of the anon_vmas in this anon_vma tree. 334 * lock any of the anon_vmas in this anon_vma tree.
302 */ 335 */
303 anon_vma->root = pvma->anon_vma->root; 336 anon_vma->root = pvma->anon_vma->root;
337 anon_vma->parent = pvma->anon_vma;
304 /* 338 /*
305 * With refcounts, an anon_vma can stay around longer than the 339 * With refcounts, an anon_vma can stay around longer than the
306 * process it belongs to. The root anon_vma needs to be pinned until 340 * process it belongs to. The root anon_vma needs to be pinned until
@@ -311,6 +345,7 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
311 vma->anon_vma = anon_vma; 345 vma->anon_vma = anon_vma;
312 anon_vma_lock_write(anon_vma); 346 anon_vma_lock_write(anon_vma);
313 anon_vma_chain_link(vma, avc, anon_vma); 347 anon_vma_chain_link(vma, avc, anon_vma);
348 anon_vma->parent->degree++;
314 anon_vma_unlock_write(anon_vma); 349 anon_vma_unlock_write(anon_vma);
315 350
316 return 0; 351 return 0;
@@ -341,12 +376,16 @@ void unlink_anon_vmas(struct vm_area_struct *vma)
341 * Leave empty anon_vmas on the list - we'll need 376 * Leave empty anon_vmas on the list - we'll need
342 * to free them outside the lock. 377 * to free them outside the lock.
343 */ 378 */
344 if (RB_EMPTY_ROOT(&anon_vma->rb_root)) 379 if (RB_EMPTY_ROOT(&anon_vma->rb_root)) {
380 anon_vma->parent->degree--;
345 continue; 381 continue;
382 }
346 383
347 list_del(&avc->same_vma); 384 list_del(&avc->same_vma);
348 anon_vma_chain_free(avc); 385 anon_vma_chain_free(avc);
349 } 386 }
387 if (vma->anon_vma)
388 vma->anon_vma->degree--;
350 unlock_anon_vma_root(root); 389 unlock_anon_vma_root(root);
351 390
352 /* 391 /*
@@ -357,6 +396,7 @@ void unlink_anon_vmas(struct vm_area_struct *vma)
357 list_for_each_entry_safe(avc, next, &vma->anon_vma_chain, same_vma) { 396 list_for_each_entry_safe(avc, next, &vma->anon_vma_chain, same_vma) {
358 struct anon_vma *anon_vma = avc->anon_vma; 397 struct anon_vma *anon_vma = avc->anon_vma;
359 398
399 BUG_ON(anon_vma->degree);
360 put_anon_vma(anon_vma); 400 put_anon_vma(anon_vma);
361 401
362 list_del(&avc->same_vma); 402 list_del(&avc->same_vma);
diff --git a/mm/vmscan.c b/mm/vmscan.c
index bd9a72bc4a1b..ab2505c3ef54 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2921,18 +2921,20 @@ static bool prepare_kswapd_sleep(pg_data_t *pgdat, int order, long remaining,
2921 return false; 2921 return false;
2922 2922
2923 /* 2923 /*
2924 * There is a potential race between when kswapd checks its watermarks 2924 * The throttled processes are normally woken up in balance_pgdat() as
2925 * and a process gets throttled. There is also a potential race if 2925 * soon as pfmemalloc_watermark_ok() is true. But there is a potential
2926 * processes get throttled, kswapd wakes, a large process exits therby 2926 * race between when kswapd checks the watermarks and a process gets
2927 * balancing the zones that causes kswapd to miss a wakeup. If kswapd 2927 * throttled. There is also a potential race if processes get
2928 * is going to sleep, no process should be sleeping on pfmemalloc_wait 2928 * throttled, kswapd wakes, a large process exits thereby balancing the
2929 * so wake them now if necessary. If necessary, processes will wake 2929 * zones, which causes kswapd to exit balance_pgdat() before reaching
2930 * kswapd and get throttled again 2930 * the wake up checks. If kswapd is going to sleep, no process should
2931 * be sleeping on pfmemalloc_wait, so wake them now if necessary. If
2932 * the wake up is premature, processes will wake kswapd and get
2933 * throttled again. The difference from wake ups in balance_pgdat() is
2934 * that here we are under prepare_to_wait().
2931 */ 2935 */
2932 if (waitqueue_active(&pgdat->pfmemalloc_wait)) { 2936 if (waitqueue_active(&pgdat->pfmemalloc_wait))
2933 wake_up(&pgdat->pfmemalloc_wait); 2937 wake_up_all(&pgdat->pfmemalloc_wait);
2934 return false;
2935 }
2936 2938
2937 return pgdat_balanced(pgdat, order, classzone_idx); 2939 return pgdat_balanced(pgdat, order, classzone_idx);
2938} 2940}
diff --git a/net/batman-adv/multicast.c b/net/batman-adv/multicast.c
index ab6bb2af1d45..b24e4bb64fb5 100644
--- a/net/batman-adv/multicast.c
+++ b/net/batman-adv/multicast.c
@@ -685,11 +685,13 @@ static void batadv_mcast_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
685 if (orig_initialized) 685 if (orig_initialized)
686 atomic_dec(&bat_priv->mcast.num_disabled); 686 atomic_dec(&bat_priv->mcast.num_disabled);
687 orig->capabilities |= BATADV_ORIG_CAPA_HAS_MCAST; 687 orig->capabilities |= BATADV_ORIG_CAPA_HAS_MCAST;
688 /* If mcast support is being switched off increase the disabled 688 /* If mcast support is being switched off or if this is an initial
689 * mcast node counter. 689 * OGM without mcast support then increase the disabled mcast
690 * node counter.
690 */ 691 */
691 } else if (!orig_mcast_enabled && 692 } else if (!orig_mcast_enabled &&
692 orig->capabilities & BATADV_ORIG_CAPA_HAS_MCAST) { 693 (orig->capabilities & BATADV_ORIG_CAPA_HAS_MCAST ||
694 !orig_initialized)) {
693 atomic_inc(&bat_priv->mcast.num_disabled); 695 atomic_inc(&bat_priv->mcast.num_disabled);
694 orig->capabilities &= ~BATADV_ORIG_CAPA_HAS_MCAST; 696 orig->capabilities &= ~BATADV_ORIG_CAPA_HAS_MCAST;
695 } 697 }
@@ -738,7 +740,8 @@ void batadv_mcast_purge_orig(struct batadv_orig_node *orig)
738{ 740{
739 struct batadv_priv *bat_priv = orig->bat_priv; 741 struct batadv_priv *bat_priv = orig->bat_priv;
740 742
741 if (!(orig->capabilities & BATADV_ORIG_CAPA_HAS_MCAST)) 743 if (!(orig->capabilities & BATADV_ORIG_CAPA_HAS_MCAST) &&
744 orig->capa_initialized & BATADV_ORIG_CAPA_HAS_MCAST)
742 atomic_dec(&bat_priv->mcast.num_disabled); 745 atomic_dec(&bat_priv->mcast.num_disabled);
743 746
744 batadv_mcast_want_unsnoop_update(bat_priv, orig, BATADV_NO_FLAGS); 747 batadv_mcast_want_unsnoop_update(bat_priv, orig, BATADV_NO_FLAGS);
diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c
index 8d04d174669e..fab47f1f3ef9 100644
--- a/net/batman-adv/network-coding.c
+++ b/net/batman-adv/network-coding.c
@@ -133,7 +133,7 @@ int batadv_nc_mesh_init(struct batadv_priv *bat_priv)
133 if (!bat_priv->nc.decoding_hash) 133 if (!bat_priv->nc.decoding_hash)
134 goto err; 134 goto err;
135 135
136 batadv_hash_set_lock_class(bat_priv->nc.coding_hash, 136 batadv_hash_set_lock_class(bat_priv->nc.decoding_hash,
137 &batadv_nc_decoding_hash_lock_class_key); 137 &batadv_nc_decoding_hash_lock_class_key);
138 138
139 INIT_DELAYED_WORK(&bat_priv->nc.work, batadv_nc_worker); 139 INIT_DELAYED_WORK(&bat_priv->nc.work, batadv_nc_worker);
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 6a484514cd3e..bea8198d0198 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -570,9 +570,6 @@ static void batadv_orig_node_free_rcu(struct rcu_head *rcu)
570 570
571 batadv_frag_purge_orig(orig_node, NULL); 571 batadv_frag_purge_orig(orig_node, NULL);
572 572
573 batadv_tt_global_del_orig(orig_node->bat_priv, orig_node, -1,
574 "originator timed out");
575
576 if (orig_node->bat_priv->bat_algo_ops->bat_orig_free) 573 if (orig_node->bat_priv->bat_algo_ops->bat_orig_free)
577 orig_node->bat_priv->bat_algo_ops->bat_orig_free(orig_node); 574 orig_node->bat_priv->bat_algo_ops->bat_orig_free(orig_node);
578 575
@@ -678,6 +675,7 @@ struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv,
678 atomic_set(&orig_node->last_ttvn, 0); 675 atomic_set(&orig_node->last_ttvn, 0);
679 orig_node->tt_buff = NULL; 676 orig_node->tt_buff = NULL;
680 orig_node->tt_buff_len = 0; 677 orig_node->tt_buff_len = 0;
678 orig_node->last_seen = jiffies;
681 reset_time = jiffies - 1 - msecs_to_jiffies(BATADV_RESET_PROTECTION_MS); 679 reset_time = jiffies - 1 - msecs_to_jiffies(BATADV_RESET_PROTECTION_MS);
682 orig_node->bcast_seqno_reset = reset_time; 680 orig_node->bcast_seqno_reset = reset_time;
683#ifdef CONFIG_BATMAN_ADV_MCAST 681#ifdef CONFIG_BATMAN_ADV_MCAST
@@ -977,6 +975,9 @@ static void _batadv_purge_orig(struct batadv_priv *bat_priv)
977 if (batadv_purge_orig_node(bat_priv, orig_node)) { 975 if (batadv_purge_orig_node(bat_priv, orig_node)) {
978 batadv_gw_node_delete(bat_priv, orig_node); 976 batadv_gw_node_delete(bat_priv, orig_node);
979 hlist_del_rcu(&orig_node->hash_entry); 977 hlist_del_rcu(&orig_node->hash_entry);
978 batadv_tt_global_del_orig(orig_node->bat_priv,
979 orig_node, -1,
980 "originator timed out");
980 batadv_orig_node_free_ref(orig_node); 981 batadv_orig_node_free_ref(orig_node);
981 continue; 982 continue;
982 } 983 }
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 35f76f2f7824..6648f321864d 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -443,11 +443,13 @@ batadv_find_router(struct batadv_priv *bat_priv,
443 443
444 router = batadv_orig_router_get(orig_node, recv_if); 444 router = batadv_orig_router_get(orig_node, recv_if);
445 445
446 if (!router)
447 return router;
448
446 /* only consider bonding for recv_if == BATADV_IF_DEFAULT (first hop) 449 /* only consider bonding for recv_if == BATADV_IF_DEFAULT (first hop)
447 * and if activated. 450 * and if activated.
448 */ 451 */
449 if (recv_if == BATADV_IF_DEFAULT || !atomic_read(&bat_priv->bonding) || 452 if (!(recv_if == BATADV_IF_DEFAULT && atomic_read(&bat_priv->bonding)))
450 !router)
451 return router; 453 return router;
452 454
453 /* bonding: loop through the list of possible routers found 455 /* bonding: loop through the list of possible routers found
diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c
index 1f1de715197c..e2aa7be3a847 100644
--- a/net/bridge/br_input.c
+++ b/net/bridge/br_input.c
@@ -154,7 +154,8 @@ int br_handle_frame_finish(struct sk_buff *skb)
154 dst = NULL; 154 dst = NULL;
155 155
156 if (is_broadcast_ether_addr(dest)) { 156 if (is_broadcast_ether_addr(dest)) {
157 if (p->flags & BR_PROXYARP && 157 if (IS_ENABLED(CONFIG_INET) &&
158 p->flags & BR_PROXYARP &&
158 skb->protocol == htons(ETH_P_ARP)) 159 skb->protocol == htons(ETH_P_ARP))
159 br_do_proxy_arp(skb, br, vid); 160 br_do_proxy_arp(skb, br, vid);
160 161
diff --git a/net/ceph/auth_x.c b/net/ceph/auth_x.c
index 15845814a0f2..ba6eb17226da 100644
--- a/net/ceph/auth_x.c
+++ b/net/ceph/auth_x.c
@@ -676,7 +676,7 @@ static int calcu_signature(struct ceph_x_authorizer *au,
676 int ret; 676 int ret;
677 char tmp_enc[40]; 677 char tmp_enc[40];
678 __le32 tmp[5] = { 678 __le32 tmp[5] = {
679 16u, msg->hdr.crc, msg->footer.front_crc, 679 cpu_to_le32(16), msg->hdr.crc, msg->footer.front_crc,
680 msg->footer.middle_crc, msg->footer.data_crc, 680 msg->footer.middle_crc, msg->footer.data_crc,
681 }; 681 };
682 ret = ceph_x_encrypt(&au->session_key, &tmp, sizeof(tmp), 682 ret = ceph_x_encrypt(&au->session_key, &tmp, sizeof(tmp),
diff --git a/net/ceph/mon_client.c b/net/ceph/mon_client.c
index a83062ceeec9..f2148e22b148 100644
--- a/net/ceph/mon_client.c
+++ b/net/ceph/mon_client.c
@@ -717,7 +717,7 @@ static int get_poolop_reply_buf(const char *src, size_t src_len,
717 if (src_len != sizeof(u32) + dst_len) 717 if (src_len != sizeof(u32) + dst_len)
718 return -EINVAL; 718 return -EINVAL;
719 719
720 buf_len = le32_to_cpu(*(u32 *)src); 720 buf_len = le32_to_cpu(*(__le32 *)src);
721 if (buf_len != dst_len) 721 if (buf_len != dst_len)
722 return -EINVAL; 722 return -EINVAL;
723 723
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 8e38f17288d3..8d614c93f86a 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -2043,6 +2043,12 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh)
2043 case NDTPA_BASE_REACHABLE_TIME: 2043 case NDTPA_BASE_REACHABLE_TIME:
2044 NEIGH_VAR_SET(p, BASE_REACHABLE_TIME, 2044 NEIGH_VAR_SET(p, BASE_REACHABLE_TIME,
2045 nla_get_msecs(tbp[i])); 2045 nla_get_msecs(tbp[i]));
2046 /* update reachable_time as well, otherwise, the change will
2047 * only be effective after the next time neigh_periodic_work
2048 * decides to recompute it (can be multiple minutes)
2049 */
2050 p->reachable_time =
2051 neigh_rand_reach_time(NEIGH_VAR(p, BASE_REACHABLE_TIME));
2046 break; 2052 break;
2047 case NDTPA_GC_STALETIME: 2053 case NDTPA_GC_STALETIME:
2048 NEIGH_VAR_SET(p, GC_STALETIME, 2054 NEIGH_VAR_SET(p, GC_STALETIME,
@@ -2921,6 +2927,31 @@ static int neigh_proc_dointvec_unres_qlen(struct ctl_table *ctl, int write,
2921 return ret; 2927 return ret;
2922} 2928}
2923 2929
2930static int neigh_proc_base_reachable_time(struct ctl_table *ctl, int write,
2931 void __user *buffer,
2932 size_t *lenp, loff_t *ppos)
2933{
2934 struct neigh_parms *p = ctl->extra2;
2935 int ret;
2936
2937 if (strcmp(ctl->procname, "base_reachable_time") == 0)
2938 ret = neigh_proc_dointvec_jiffies(ctl, write, buffer, lenp, ppos);
2939 else if (strcmp(ctl->procname, "base_reachable_time_ms") == 0)
2940 ret = neigh_proc_dointvec_ms_jiffies(ctl, write, buffer, lenp, ppos);
2941 else
2942 ret = -1;
2943
2944 if (write && ret == 0) {
2945 /* update reachable_time as well, otherwise, the change will
2946 * only be effective after the next time neigh_periodic_work
2947 * decides to recompute it
2948 */
2949 p->reachable_time =
2950 neigh_rand_reach_time(NEIGH_VAR(p, BASE_REACHABLE_TIME));
2951 }
2952 return ret;
2953}
2954
2924#define NEIGH_PARMS_DATA_OFFSET(index) \ 2955#define NEIGH_PARMS_DATA_OFFSET(index) \
2925 (&((struct neigh_parms *) 0)->data[index]) 2956 (&((struct neigh_parms *) 0)->data[index])
2926 2957
@@ -3047,6 +3078,19 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
3047 t->neigh_vars[NEIGH_VAR_RETRANS_TIME_MS].proc_handler = handler; 3078 t->neigh_vars[NEIGH_VAR_RETRANS_TIME_MS].proc_handler = handler;
3048 /* ReachableTime (in milliseconds) */ 3079 /* ReachableTime (in milliseconds) */
3049 t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME_MS].proc_handler = handler; 3080 t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME_MS].proc_handler = handler;
3081 } else {
3082 /* Those handlers will update p->reachable_time after
3083 * base_reachable_time(_ms) is set to ensure the new timer starts being
3084 * applied after the next neighbour update instead of waiting for
3085 * neigh_periodic_work to update its value (can be multiple minutes)
3086 * So any handler that replaces them should do this as well
3087 */
3088 /* ReachableTime */
3089 t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME].proc_handler =
3090 neigh_proc_base_reachable_time;
3091 /* ReachableTime (in milliseconds) */
3092 t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME_MS].proc_handler =
3093 neigh_proc_base_reachable_time;
3050 } 3094 }
3051 3095
3052 /* Don't export sysctls to unprivileged users */ 3096 /* Don't export sysctls to unprivileged users */
diff --git a/net/ipv4/netfilter/nft_redir_ipv4.c b/net/ipv4/netfilter/nft_redir_ipv4.c
index ff2d23d8c87a..6ecfce63201a 100644
--- a/net/ipv4/netfilter/nft_redir_ipv4.c
+++ b/net/ipv4/netfilter/nft_redir_ipv4.c
@@ -27,10 +27,10 @@ static void nft_redir_ipv4_eval(const struct nft_expr *expr,
27 27
28 memset(&mr, 0, sizeof(mr)); 28 memset(&mr, 0, sizeof(mr));
29 if (priv->sreg_proto_min) { 29 if (priv->sreg_proto_min) {
30 mr.range[0].min.all = (__force __be16) 30 mr.range[0].min.all =
31 data[priv->sreg_proto_min].data[0]; 31 *(__be16 *)&data[priv->sreg_proto_min].data[0];
32 mr.range[0].max.all = (__force __be16) 32 mr.range[0].max.all =
33 data[priv->sreg_proto_max].data[0]; 33 *(__be16 *)&data[priv->sreg_proto_max].data[0];
34 mr.range[0].flags |= NF_NAT_RANGE_PROTO_SPECIFIED; 34 mr.range[0].flags |= NF_NAT_RANGE_PROTO_SPECIFIED;
35 } 35 }
36 36
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 7f18262e2326..65caf8b95e17 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -2019,7 +2019,7 @@ static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
2019 if (unlikely(!tcp_snd_wnd_test(tp, skb, mss_now))) 2019 if (unlikely(!tcp_snd_wnd_test(tp, skb, mss_now)))
2020 break; 2020 break;
2021 2021
2022 if (tso_segs == 1) { 2022 if (tso_segs == 1 || !max_segs) {
2023 if (unlikely(!tcp_nagle_test(tp, skb, mss_now, 2023 if (unlikely(!tcp_nagle_test(tp, skb, mss_now,
2024 (tcp_skb_is_last(sk, skb) ? 2024 (tcp_skb_is_last(sk, skb) ?
2025 nonagle : TCP_NAGLE_PUSH)))) 2025 nonagle : TCP_NAGLE_PUSH))))
@@ -2032,7 +2032,7 @@ static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
2032 } 2032 }
2033 2033
2034 limit = mss_now; 2034 limit = mss_now;
2035 if (tso_segs > 1 && !tcp_urg_mode(tp)) 2035 if (tso_segs > 1 && max_segs && !tcp_urg_mode(tp))
2036 limit = tcp_mss_split_point(sk, skb, mss_now, 2036 limit = tcp_mss_split_point(sk, skb, mss_now,
2037 min_t(unsigned int, 2037 min_t(unsigned int,
2038 cwnd_quota, 2038 cwnd_quota,
diff --git a/net/ipv6/netfilter/nft_redir_ipv6.c b/net/ipv6/netfilter/nft_redir_ipv6.c
index 2433a6bfb191..11820b6b3613 100644
--- a/net/ipv6/netfilter/nft_redir_ipv6.c
+++ b/net/ipv6/netfilter/nft_redir_ipv6.c
@@ -27,10 +27,10 @@ static void nft_redir_ipv6_eval(const struct nft_expr *expr,
27 27
28 memset(&range, 0, sizeof(range)); 28 memset(&range, 0, sizeof(range));
29 if (priv->sreg_proto_min) { 29 if (priv->sreg_proto_min) {
30 range.min_proto.all = (__force __be16) 30 range.min_proto.all =
31 data[priv->sreg_proto_min].data[0]; 31 *(__be16 *)&data[priv->sreg_proto_min].data[0];
32 range.max_proto.all = (__force __be16) 32 range.max_proto.all =
33 data[priv->sreg_proto_max].data[0]; 33 *(__be16 *)&data[priv->sreg_proto_max].data[0];
34 range.flags |= NF_NAT_RANGE_PROTO_SPECIFIED; 34 range.flags |= NF_NAT_RANGE_PROTO_SPECIFIED;
35 } 35 }
36 36
diff --git a/net/mac80211/key.c b/net/mac80211/key.c
index 0bb7038121ac..bd4e46ec32bd 100644
--- a/net/mac80211/key.c
+++ b/net/mac80211/key.c
@@ -140,7 +140,9 @@ static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
140 if (!ret) { 140 if (!ret) {
141 key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE; 141 key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE;
142 142
143 if (!(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC)) 143 if (!((key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) ||
144 (key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) ||
145 (key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE)))
144 sdata->crypto_tx_tailroom_needed_cnt--; 146 sdata->crypto_tx_tailroom_needed_cnt--;
145 147
146 WARN_ON((key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) && 148 WARN_ON((key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) &&
@@ -188,7 +190,9 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
188 sta = key->sta; 190 sta = key->sta;
189 sdata = key->sdata; 191 sdata = key->sdata;
190 192
191 if (!(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC)) 193 if (!((key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) ||
194 (key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) ||
195 (key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE)))
192 increment_tailroom_need_count(sdata); 196 increment_tailroom_need_count(sdata);
193 197
194 ret = drv_set_key(key->local, DISABLE_KEY, sdata, 198 ret = drv_set_key(key->local, DISABLE_KEY, sdata,
@@ -884,7 +888,9 @@ void ieee80211_remove_key(struct ieee80211_key_conf *keyconf)
884 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { 888 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) {
885 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE; 889 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
886 890
887 if (!(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC)) 891 if (!((key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) ||
892 (key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) ||
893 (key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE)))
888 increment_tailroom_need_count(key->sdata); 894 increment_tailroom_need_count(key->sdata);
889 } 895 }
890 896
diff --git a/net/netfilter/ipvs/ip_vs_ftp.c b/net/netfilter/ipvs/ip_vs_ftp.c
index 1d5341f3761d..5d3daae98bf0 100644
--- a/net/netfilter/ipvs/ip_vs_ftp.c
+++ b/net/netfilter/ipvs/ip_vs_ftp.c
@@ -183,6 +183,8 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,
183 struct nf_conn *ct; 183 struct nf_conn *ct;
184 struct net *net; 184 struct net *net;
185 185
186 *diff = 0;
187
186#ifdef CONFIG_IP_VS_IPV6 188#ifdef CONFIG_IP_VS_IPV6
187 /* This application helper doesn't work with IPv6 yet, 189 /* This application helper doesn't work with IPv6 yet,
188 * so turn this into a no-op for IPv6 packets 190 * so turn this into a no-op for IPv6 packets
@@ -191,8 +193,6 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,
191 return 1; 193 return 1;
192#endif 194#endif
193 195
194 *diff = 0;
195
196 /* Only useful for established sessions */ 196 /* Only useful for established sessions */
197 if (cp->state != IP_VS_TCP_S_ESTABLISHED) 197 if (cp->state != IP_VS_TCP_S_ESTABLISHED)
198 return 1; 198 return 1;
@@ -322,6 +322,9 @@ static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp,
322 struct ip_vs_conn *n_cp; 322 struct ip_vs_conn *n_cp;
323 struct net *net; 323 struct net *net;
324 324
325 /* no diff required for incoming packets */
326 *diff = 0;
327
325#ifdef CONFIG_IP_VS_IPV6 328#ifdef CONFIG_IP_VS_IPV6
326 /* This application helper doesn't work with IPv6 yet, 329 /* This application helper doesn't work with IPv6 yet,
327 * so turn this into a no-op for IPv6 packets 330 * so turn this into a no-op for IPv6 packets
@@ -330,9 +333,6 @@ static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp,
330 return 1; 333 return 1;
331#endif 334#endif
332 335
333 /* no diff required for incoming packets */
334 *diff = 0;
335
336 /* Only useful for established sessions */ 336 /* Only useful for established sessions */
337 if (cp->state != IP_VS_TCP_S_ESTABLISHED) 337 if (cp->state != IP_VS_TCP_S_ESTABLISHED)
338 return 1; 338 return 1;
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index a11674806707..46d1b26a468e 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -611,16 +611,15 @@ __nf_conntrack_confirm(struct sk_buff *skb)
611 */ 611 */
612 NF_CT_ASSERT(!nf_ct_is_confirmed(ct)); 612 NF_CT_ASSERT(!nf_ct_is_confirmed(ct));
613 pr_debug("Confirming conntrack %p\n", ct); 613 pr_debug("Confirming conntrack %p\n", ct);
614 /* We have to check the DYING flag inside the lock to prevent 614 /* We have to check the DYING flag after unlink to prevent
615 a race against nf_ct_get_next_corpse() possibly called from 615 * a race against nf_ct_get_next_corpse() possibly called from
616 user context, else we insert an already 'dead' hash, blocking 616 * user context, else we insert an already 'dead' hash, blocking
617 further use of that particular connection -JM */ 617 * further use of that particular connection -JM.
618 */
619 nf_ct_del_from_dying_or_unconfirmed_list(ct);
618 620
619 if (unlikely(nf_ct_is_dying(ct))) { 621 if (unlikely(nf_ct_is_dying(ct)))
620 nf_conntrack_double_unlock(hash, reply_hash); 622 goto out;
621 local_bh_enable();
622 return NF_ACCEPT;
623 }
624 623
625 /* See if there's one in the list already, including reverse: 624 /* See if there's one in the list already, including reverse:
626 NAT could have grabbed it without realizing, since we're 625 NAT could have grabbed it without realizing, since we're
@@ -636,8 +635,6 @@ __nf_conntrack_confirm(struct sk_buff *skb)
636 zone == nf_ct_zone(nf_ct_tuplehash_to_ctrack(h))) 635 zone == nf_ct_zone(nf_ct_tuplehash_to_ctrack(h)))
637 goto out; 636 goto out;
638 637
639 nf_ct_del_from_dying_or_unconfirmed_list(ct);
640
641 /* Timer relative to confirmation time, not original 638 /* Timer relative to confirmation time, not original
642 setting time, otherwise we'd get timer wrap in 639 setting time, otherwise we'd get timer wrap in
643 weird delay cases. */ 640 weird delay cases. */
@@ -673,6 +670,7 @@ __nf_conntrack_confirm(struct sk_buff *skb)
673 return NF_ACCEPT; 670 return NF_ACCEPT;
674 671
675out: 672out:
673 nf_ct_add_to_dying_list(ct);
676 nf_conntrack_double_unlock(hash, reply_hash); 674 nf_conntrack_double_unlock(hash, reply_hash);
677 NF_CT_STAT_INC(net, insert_failed); 675 NF_CT_STAT_INC(net, insert_failed);
678 local_bh_enable(); 676 local_bh_enable();
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 129a8daa4abf..3b3ddb4fb9ee 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -713,16 +713,12 @@ static int nft_flush_table(struct nft_ctx *ctx)
713 struct nft_chain *chain, *nc; 713 struct nft_chain *chain, *nc;
714 struct nft_set *set, *ns; 714 struct nft_set *set, *ns;
715 715
716 list_for_each_entry_safe(chain, nc, &ctx->table->chains, list) { 716 list_for_each_entry(chain, &ctx->table->chains, list) {
717 ctx->chain = chain; 717 ctx->chain = chain;
718 718
719 err = nft_delrule_by_chain(ctx); 719 err = nft_delrule_by_chain(ctx);
720 if (err < 0) 720 if (err < 0)
721 goto out; 721 goto out;
722
723 err = nft_delchain(ctx);
724 if (err < 0)
725 goto out;
726 } 722 }
727 723
728 list_for_each_entry_safe(set, ns, &ctx->table->sets, list) { 724 list_for_each_entry_safe(set, ns, &ctx->table->sets, list) {
@@ -735,6 +731,14 @@ static int nft_flush_table(struct nft_ctx *ctx)
735 goto out; 731 goto out;
736 } 732 }
737 733
734 list_for_each_entry_safe(chain, nc, &ctx->table->chains, list) {
735 ctx->chain = chain;
736
737 err = nft_delchain(ctx);
738 if (err < 0)
739 goto out;
740 }
741
738 err = nft_deltable(ctx); 742 err = nft_deltable(ctx);
739out: 743out:
740 return err; 744 return err;
diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
index cde4a6702fa3..c421d94c4652 100644
--- a/net/netfilter/nfnetlink.c
+++ b/net/netfilter/nfnetlink.c
@@ -321,7 +321,8 @@ replay:
321 nlh = nlmsg_hdr(skb); 321 nlh = nlmsg_hdr(skb);
322 err = 0; 322 err = 0;
323 323
324 if (nlh->nlmsg_len < NLMSG_HDRLEN) { 324 if (nlmsg_len(nlh) < sizeof(struct nfgenmsg) ||
325 skb->len < nlh->nlmsg_len) {
325 err = -EINVAL; 326 err = -EINVAL;
326 goto ack; 327 goto ack;
327 } 328 }
@@ -469,7 +470,7 @@ static int nfnetlink_bind(struct net *net, int group)
469 int type; 470 int type;
470 471
471 if (group <= NFNLGRP_NONE || group > NFNLGRP_MAX) 472 if (group <= NFNLGRP_NONE || group > NFNLGRP_MAX)
472 return -EINVAL; 473 return 0;
473 474
474 type = nfnl_group2type[group]; 475 type = nfnl_group2type[group];
475 476
diff --git a/net/netfilter/nft_nat.c b/net/netfilter/nft_nat.c
index afe2b0b45ec4..aff54fb1c8a0 100644
--- a/net/netfilter/nft_nat.c
+++ b/net/netfilter/nft_nat.c
@@ -65,10 +65,10 @@ static void nft_nat_eval(const struct nft_expr *expr,
65 } 65 }
66 66
67 if (priv->sreg_proto_min) { 67 if (priv->sreg_proto_min) {
68 range.min_proto.all = (__force __be16) 68 range.min_proto.all =
69 data[priv->sreg_proto_min].data[0]; 69 *(__be16 *)&data[priv->sreg_proto_min].data[0];
70 range.max_proto.all = (__force __be16) 70 range.max_proto.all =
71 data[priv->sreg_proto_max].data[0]; 71 *(__be16 *)&data[priv->sreg_proto_max].data[0];
72 range.flags |= NF_NAT_RANGE_PROTO_SPECIFIED; 72 range.flags |= NF_NAT_RANGE_PROTO_SPECIFIED;
73 } 73 }
74 74
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index 4e9a5f035cbc..b07349e82d78 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -524,7 +524,7 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
524 struct vport *input_vport; 524 struct vport *input_vport;
525 int len; 525 int len;
526 int err; 526 int err;
527 bool log = !a[OVS_FLOW_ATTR_PROBE]; 527 bool log = !a[OVS_PACKET_ATTR_PROBE];
528 528
529 err = -EINVAL; 529 err = -EINVAL;
530 if (!a[OVS_PACKET_ATTR_PACKET] || !a[OVS_PACKET_ATTR_KEY] || 530 if (!a[OVS_PACKET_ATTR_PACKET] || !a[OVS_PACKET_ATTR_KEY] ||
@@ -610,6 +610,7 @@ static const struct nla_policy packet_policy[OVS_PACKET_ATTR_MAX + 1] = {
610 [OVS_PACKET_ATTR_PACKET] = { .len = ETH_HLEN }, 610 [OVS_PACKET_ATTR_PACKET] = { .len = ETH_HLEN },
611 [OVS_PACKET_ATTR_KEY] = { .type = NLA_NESTED }, 611 [OVS_PACKET_ATTR_KEY] = { .type = NLA_NESTED },
612 [OVS_PACKET_ATTR_ACTIONS] = { .type = NLA_NESTED }, 612 [OVS_PACKET_ATTR_ACTIONS] = { .type = NLA_NESTED },
613 [OVS_PACKET_ATTR_PROBE] = { .type = NLA_FLAG },
613}; 614};
614 615
615static const struct genl_ops dp_packet_genl_ops[] = { 616static const struct genl_ops dp_packet_genl_ops[] = {
diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c
index 70bef2ab7f2b..da2fae0873a5 100644
--- a/net/openvswitch/flow.c
+++ b/net/openvswitch/flow.c
@@ -70,6 +70,7 @@ void ovs_flow_stats_update(struct sw_flow *flow, __be16 tcp_flags,
70{ 70{
71 struct flow_stats *stats; 71 struct flow_stats *stats;
72 int node = numa_node_id(); 72 int node = numa_node_id();
73 int len = skb->len + (vlan_tx_tag_present(skb) ? VLAN_HLEN : 0);
73 74
74 stats = rcu_dereference(flow->stats[node]); 75 stats = rcu_dereference(flow->stats[node]);
75 76
@@ -105,7 +106,7 @@ void ovs_flow_stats_update(struct sw_flow *flow, __be16 tcp_flags,
105 if (likely(new_stats)) { 106 if (likely(new_stats)) {
106 new_stats->used = jiffies; 107 new_stats->used = jiffies;
107 new_stats->packet_count = 1; 108 new_stats->packet_count = 1;
108 new_stats->byte_count = skb->len; 109 new_stats->byte_count = len;
109 new_stats->tcp_flags = tcp_flags; 110 new_stats->tcp_flags = tcp_flags;
110 spin_lock_init(&new_stats->lock); 111 spin_lock_init(&new_stats->lock);
111 112
@@ -120,7 +121,7 @@ void ovs_flow_stats_update(struct sw_flow *flow, __be16 tcp_flags,
120 121
121 stats->used = jiffies; 122 stats->used = jiffies;
122 stats->packet_count++; 123 stats->packet_count++;
123 stats->byte_count += skb->len; 124 stats->byte_count += len;
124 stats->tcp_flags |= tcp_flags; 125 stats->tcp_flags |= tcp_flags;
125unlock: 126unlock:
126 spin_unlock(&stats->lock); 127 spin_unlock(&stats->lock);
diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
index 53f3ebbfceab..2034c6d9cb5a 100644
--- a/net/openvswitch/vport.c
+++ b/net/openvswitch/vport.c
@@ -480,7 +480,7 @@ void ovs_vport_receive(struct vport *vport, struct sk_buff *skb,
480 stats = this_cpu_ptr(vport->percpu_stats); 480 stats = this_cpu_ptr(vport->percpu_stats);
481 u64_stats_update_begin(&stats->syncp); 481 u64_stats_update_begin(&stats->syncp);
482 stats->rx_packets++; 482 stats->rx_packets++;
483 stats->rx_bytes += skb->len; 483 stats->rx_bytes += skb->len + (vlan_tx_tag_present(skb) ? VLAN_HLEN : 0);
484 u64_stats_update_end(&stats->syncp); 484 u64_stats_update_end(&stats->syncp);
485 485
486 OVS_CB(skb)->input_vport = vport; 486 OVS_CB(skb)->input_vport = vport;
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 6880f34a529a..9cfe2e1dd8b5 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2517,7 +2517,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
2517 err = -EINVAL; 2517 err = -EINVAL;
2518 if (sock->type == SOCK_DGRAM) { 2518 if (sock->type == SOCK_DGRAM) {
2519 offset = dev_hard_header(skb, dev, ntohs(proto), addr, NULL, len); 2519 offset = dev_hard_header(skb, dev, ntohs(proto), addr, NULL, len);
2520 if (unlikely(offset) < 0) 2520 if (unlikely(offset < 0))
2521 goto out_free; 2521 goto out_free;
2522 } else { 2522 } else {
2523 if (ll_header_truncated(dev, len)) 2523 if (ll_header_truncated(dev, len))
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c
index 96ceefeb9daf..a9e174fc0f91 100644
--- a/net/tipc/bcast.c
+++ b/net/tipc/bcast.c
@@ -220,10 +220,11 @@ static void bclink_retransmit_pkt(u32 after, u32 to)
220 struct sk_buff *skb; 220 struct sk_buff *skb;
221 221
222 skb_queue_walk(&bcl->outqueue, skb) { 222 skb_queue_walk(&bcl->outqueue, skb) {
223 if (more(buf_seqno(skb), after)) 223 if (more(buf_seqno(skb), after)) {
224 tipc_link_retransmit(bcl, skb, mod(to - after));
224 break; 225 break;
226 }
225 } 227 }
226 tipc_link_retransmit(bcl, skb, mod(to - after));
227} 228}
228 229
229/** 230/**
diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
index 1bca180db8ad..627f8cbbedb8 100644
--- a/scripts/Makefile.clean
+++ b/scripts/Makefile.clean
@@ -42,19 +42,19 @@ __clean-files := $(extra-y) $(extra-m) $(extra-) \
42 42
43__clean-files := $(filter-out $(no-clean-files), $(__clean-files)) 43__clean-files := $(filter-out $(no-clean-files), $(__clean-files))
44 44
45# as clean-files is given relative to the current directory, this adds 45# clean-files is given relative to the current directory, unless it
46# a $(obj) prefix, except for absolute paths 46# starts with $(objtree)/ (which means "./", so do not add "./" unless
47# you want to delete a file from the toplevel object directory).
47 48
48__clean-files := $(wildcard \ 49__clean-files := $(wildcard \
49 $(addprefix $(obj)/, $(filter-out /%, $(__clean-files))) \ 50 $(addprefix $(obj)/, $(filter-out $(objtree)/%, $(__clean-files))) \
50 $(filter /%, $(__clean-files))) 51 $(filter $(objtree)/%, $(__clean-files)))
51 52
52# as clean-dirs is given relative to the current directory, this adds 53# same as clean-files
53# a $(obj) prefix, except for absolute paths
54 54
55__clean-dirs := $(wildcard \ 55__clean-dirs := $(wildcard \
56 $(addprefix $(obj)/, $(filter-out /%, $(clean-dirs))) \ 56 $(addprefix $(obj)/, $(filter-out $(objtree)/%, $(clean-dirs))) \
57 $(filter /%, $(clean-dirs))) 57 $(filter $(objtree)/%, $(clean-dirs)))
58 58
59# ========================================================================== 59# ==========================================================================
60 60
diff --git a/security/keys/gc.c b/security/keys/gc.c
index 9609a7f0faea..c7952375ac53 100644
--- a/security/keys/gc.c
+++ b/security/keys/gc.c
@@ -148,12 +148,12 @@ static noinline void key_gc_unused_keys(struct list_head *keys)
148 if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags)) 148 if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags))
149 atomic_dec(&key->user->nikeys); 149 atomic_dec(&key->user->nikeys);
150 150
151 key_user_put(key->user);
152
153 /* now throw away the key memory */ 151 /* now throw away the key memory */
154 if (key->type->destroy) 152 if (key->type->destroy)
155 key->type->destroy(key); 153 key->type->destroy(key);
156 154
155 key_user_put(key->user);
156
157 kfree(key->description); 157 kfree(key->description);
158 158
159#ifdef KEY_DEBUGGING 159#ifdef KEY_DEBUGGING
diff --git a/sound/firewire/fireworks/fireworks_transaction.c b/sound/firewire/fireworks/fireworks_transaction.c
index 255dabc6fc33..2a85e4209f0b 100644
--- a/sound/firewire/fireworks/fireworks_transaction.c
+++ b/sound/firewire/fireworks/fireworks_transaction.c
@@ -124,7 +124,7 @@ copy_resp_to_buf(struct snd_efw *efw, void *data, size_t length, int *rcode)
124 spin_lock_irq(&efw->lock); 124 spin_lock_irq(&efw->lock);
125 125
126 t = (struct snd_efw_transaction *)data; 126 t = (struct snd_efw_transaction *)data;
127 length = min_t(size_t, t->length * sizeof(t->length), length); 127 length = min_t(size_t, be32_to_cpu(t->length) * sizeof(u32), length);
128 128
129 if (efw->push_ptr < efw->pull_ptr) 129 if (efw->push_ptr < efw->pull_ptr)
130 capacity = (unsigned int)(efw->pull_ptr - efw->push_ptr); 130 capacity = (unsigned int)(efw->pull_ptr - efw->push_ptr);
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index 5f13d2d18079..b422e406a9cb 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -3353,6 +3353,7 @@ static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
3353{ .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch }, 3353{ .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch },
3354{ .id = 0x10de0070, .name = "GPU 70 HDMI/DP", .patch = patch_nvhdmi }, 3354{ .id = 0x10de0070, .name = "GPU 70 HDMI/DP", .patch = patch_nvhdmi },
3355{ .id = 0x10de0071, .name = "GPU 71 HDMI/DP", .patch = patch_nvhdmi }, 3355{ .id = 0x10de0071, .name = "GPU 71 HDMI/DP", .patch = patch_nvhdmi },
3356{ .id = 0x10de0072, .name = "GPU 72 HDMI/DP", .patch = patch_nvhdmi },
3356{ .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch }, 3357{ .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch },
3357{ .id = 0x11069f80, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi }, 3358{ .id = 0x11069f80, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi },
3358{ .id = 0x11069f81, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi }, 3359{ .id = 0x11069f81, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi },
@@ -3413,6 +3414,7 @@ MODULE_ALIAS("snd-hda-codec-id:10de0060");
3413MODULE_ALIAS("snd-hda-codec-id:10de0067"); 3414MODULE_ALIAS("snd-hda-codec-id:10de0067");
3414MODULE_ALIAS("snd-hda-codec-id:10de0070"); 3415MODULE_ALIAS("snd-hda-codec-id:10de0070");
3415MODULE_ALIAS("snd-hda-codec-id:10de0071"); 3416MODULE_ALIAS("snd-hda-codec-id:10de0071");
3417MODULE_ALIAS("snd-hda-codec-id:10de0072");
3416MODULE_ALIAS("snd-hda-codec-id:10de8001"); 3418MODULE_ALIAS("snd-hda-codec-id:10de8001");
3417MODULE_ALIAS("snd-hda-codec-id:11069f80"); 3419MODULE_ALIAS("snd-hda-codec-id:11069f80");
3418MODULE_ALIAS("snd-hda-codec-id:11069f81"); 3420MODULE_ALIAS("snd-hda-codec-id:11069f81");
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 4f6413e01c13..605d14003d25 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -568,9 +568,9 @@ static void stac_store_hints(struct hda_codec *codec)
568 spec->gpio_mask; 568 spec->gpio_mask;
569 } 569 }
570 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir)) 570 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
571 spec->gpio_mask &= spec->gpio_mask;
572 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
573 spec->gpio_dir &= spec->gpio_mask; 571 spec->gpio_dir &= spec->gpio_mask;
572 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
573 spec->gpio_data &= spec->gpio_mask;
574 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask)) 574 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
575 spec->eapd_mask &= spec->gpio_mask; 575 spec->eapd_mask &= spec->gpio_mask;
576 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute)) 576 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c
index 272844746135..327f8642ca80 100644
--- a/sound/usb/caiaq/audio.c
+++ b/sound/usb/caiaq/audio.c
@@ -816,7 +816,7 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *cdev)
816 return -EINVAL; 816 return -EINVAL;
817 } 817 }
818 818
819 if (cdev->n_streams < 2) { 819 if (cdev->n_streams < 1) {
820 dev_err(dev, "bogus number of streams: %d\n", cdev->n_streams); 820 dev_err(dev, "bogus number of streams: %d\n", cdev->n_streams);
821 return -EINVAL; 821 return -EINVAL;
822 } 822 }
diff --git a/tools/lib/lockdep/preload.c b/tools/lib/lockdep/preload.c
index 6f803609e498..0b0112c80f22 100644
--- a/tools/lib/lockdep/preload.c
+++ b/tools/lib/lockdep/preload.c
@@ -317,7 +317,7 @@ int pthread_mutex_destroy(pthread_mutex_t *mutex)
317 * 317 *
318 * TODO: Hook into free() and add that check there as well. 318 * TODO: Hook into free() and add that check there as well.
319 */ 319 */
320 debug_check_no_locks_freed(mutex, mutex + sizeof(*mutex)); 320 debug_check_no_locks_freed(mutex, sizeof(*mutex));
321 __del_lock(__get_lock(mutex)); 321 __del_lock(__get_lock(mutex));
322 return ll_pthread_mutex_destroy(mutex); 322 return ll_pthread_mutex_destroy(mutex);
323} 323}
@@ -341,7 +341,7 @@ int pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
341{ 341{
342 try_init_preload(); 342 try_init_preload();
343 343
344 debug_check_no_locks_freed(rwlock, rwlock + sizeof(*rwlock)); 344 debug_check_no_locks_freed(rwlock, sizeof(*rwlock));
345 __del_lock(__get_lock(rwlock)); 345 __del_lock(__get_lock(rwlock));
346 return ll_pthread_rwlock_destroy(rwlock); 346 return ll_pthread_rwlock_destroy(rwlock);
347} 347}
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index e7417fe97a97..747f86103599 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -232,7 +232,7 @@ static int __cmd_annotate(struct perf_annotate *ann)
232 if (nr_samples > 0) { 232 if (nr_samples > 0) {
233 total_nr_samples += nr_samples; 233 total_nr_samples += nr_samples;
234 hists__collapse_resort(hists, NULL); 234 hists__collapse_resort(hists, NULL);
235 hists__output_resort(hists); 235 hists__output_resort(hists, NULL);
236 236
237 if (symbol_conf.event_group && 237 if (symbol_conf.event_group &&
238 !perf_evsel__is_group_leader(pos)) 238 !perf_evsel__is_group_leader(pos))
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 1ce425d101a9..1fd96c13f199 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -545,6 +545,42 @@ hist_entry__cmp_compute(struct hist_entry *left, struct hist_entry *right,
545 return __hist_entry__cmp_compute(p_left, p_right, c); 545 return __hist_entry__cmp_compute(p_left, p_right, c);
546} 546}
547 547
548static int64_t
549hist_entry__cmp_nop(struct hist_entry *left __maybe_unused,
550 struct hist_entry *right __maybe_unused)
551{
552 return 0;
553}
554
555static int64_t
556hist_entry__cmp_baseline(struct hist_entry *left, struct hist_entry *right)
557{
558 if (sort_compute)
559 return 0;
560
561 if (left->stat.period == right->stat.period)
562 return 0;
563 return left->stat.period > right->stat.period ? 1 : -1;
564}
565
566static int64_t
567hist_entry__cmp_delta(struct hist_entry *left, struct hist_entry *right)
568{
569 return hist_entry__cmp_compute(right, left, COMPUTE_DELTA);
570}
571
572static int64_t
573hist_entry__cmp_ratio(struct hist_entry *left, struct hist_entry *right)
574{
575 return hist_entry__cmp_compute(right, left, COMPUTE_RATIO);
576}
577
578static int64_t
579hist_entry__cmp_wdiff(struct hist_entry *left, struct hist_entry *right)
580{
581 return hist_entry__cmp_compute(right, left, COMPUTE_WEIGHTED_DIFF);
582}
583
548static void insert_hist_entry_by_compute(struct rb_root *root, 584static void insert_hist_entry_by_compute(struct rb_root *root,
549 struct hist_entry *he, 585 struct hist_entry *he,
550 int c) 586 int c)
@@ -605,7 +641,7 @@ static void hists__process(struct hists *hists)
605 hists__precompute(hists); 641 hists__precompute(hists);
606 hists__compute_resort(hists); 642 hists__compute_resort(hists);
607 } else { 643 } else {
608 hists__output_resort(hists); 644 hists__output_resort(hists, NULL);
609 } 645 }
610 646
611 hists__fprintf(hists, true, 0, 0, 0, stdout); 647 hists__fprintf(hists, true, 0, 0, 0, stdout);
@@ -1038,27 +1074,35 @@ static void data__hpp_register(struct data__file *d, int idx)
1038 fmt->header = hpp__header; 1074 fmt->header = hpp__header;
1039 fmt->width = hpp__width; 1075 fmt->width = hpp__width;
1040 fmt->entry = hpp__entry_global; 1076 fmt->entry = hpp__entry_global;
1077 fmt->cmp = hist_entry__cmp_nop;
1078 fmt->collapse = hist_entry__cmp_nop;
1041 1079
1042 /* TODO more colors */ 1080 /* TODO more colors */
1043 switch (idx) { 1081 switch (idx) {
1044 case PERF_HPP_DIFF__BASELINE: 1082 case PERF_HPP_DIFF__BASELINE:
1045 fmt->color = hpp__color_baseline; 1083 fmt->color = hpp__color_baseline;
1084 fmt->sort = hist_entry__cmp_baseline;
1046 break; 1085 break;
1047 case PERF_HPP_DIFF__DELTA: 1086 case PERF_HPP_DIFF__DELTA:
1048 fmt->color = hpp__color_delta; 1087 fmt->color = hpp__color_delta;
1088 fmt->sort = hist_entry__cmp_delta;
1049 break; 1089 break;
1050 case PERF_HPP_DIFF__RATIO: 1090 case PERF_HPP_DIFF__RATIO:
1051 fmt->color = hpp__color_ratio; 1091 fmt->color = hpp__color_ratio;
1092 fmt->sort = hist_entry__cmp_ratio;
1052 break; 1093 break;
1053 case PERF_HPP_DIFF__WEIGHTED_DIFF: 1094 case PERF_HPP_DIFF__WEIGHTED_DIFF:
1054 fmt->color = hpp__color_wdiff; 1095 fmt->color = hpp__color_wdiff;
1096 fmt->sort = hist_entry__cmp_wdiff;
1055 break; 1097 break;
1056 default: 1098 default:
1099 fmt->sort = hist_entry__cmp_nop;
1057 break; 1100 break;
1058 } 1101 }
1059 1102
1060 init_header(d, dfmt); 1103 init_header(d, dfmt);
1061 perf_hpp__column_register(fmt); 1104 perf_hpp__column_register(fmt);
1105 perf_hpp__register_sort_field(fmt);
1062} 1106}
1063 1107
1064static void ui_init(void) 1108static void ui_init(void)
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 011195e38f21..198f3c3aff95 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -19,7 +19,9 @@
19int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) 19int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
20{ 20{
21 int i; 21 int i;
22 const struct option list_options[] = { 22 bool raw_dump = false;
23 struct option list_options[] = {
24 OPT_BOOLEAN(0, "raw-dump", &raw_dump, "Dump raw events"),
23 OPT_END() 25 OPT_END()
24 }; 26 };
25 const char * const list_usage[] = { 27 const char * const list_usage[] = {
@@ -27,11 +29,18 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
27 NULL 29 NULL
28 }; 30 };
29 31
32 set_option_flag(list_options, 0, "raw-dump", PARSE_OPT_HIDDEN);
33
30 argc = parse_options(argc, argv, list_options, list_usage, 34 argc = parse_options(argc, argv, list_options, list_usage,
31 PARSE_OPT_STOP_AT_NON_OPTION); 35 PARSE_OPT_STOP_AT_NON_OPTION);
32 36
33 setup_pager(); 37 setup_pager();
34 38
39 if (raw_dump) {
40 print_events(NULL, true);
41 return 0;
42 }
43
35 if (argc == 0) { 44 if (argc == 0) {
36 print_events(NULL, false); 45 print_events(NULL, false);
37 return 0; 46 return 0;
@@ -53,8 +62,6 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
53 print_hwcache_events(NULL, false); 62 print_hwcache_events(NULL, false);
54 else if (strcmp(argv[i], "pmu") == 0) 63 else if (strcmp(argv[i], "pmu") == 0)
55 print_pmu_events(NULL, false); 64 print_pmu_events(NULL, false);
56 else if (strcmp(argv[i], "--raw-dump") == 0)
57 print_events(NULL, true);
58 else { 65 else {
59 char *sep = strchr(argv[i], ':'), *s; 66 char *sep = strchr(argv[i], ':'), *s;
60 int sep_idx; 67 int sep_idx;
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 39367609c707..072ae8ad67fc 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -457,6 +457,19 @@ static void report__collapse_hists(struct report *rep)
457 ui_progress__finish(); 457 ui_progress__finish();
458} 458}
459 459
460static void report__output_resort(struct report *rep)
461{
462 struct ui_progress prog;
463 struct perf_evsel *pos;
464
465 ui_progress__init(&prog, rep->nr_entries, "Sorting events for output...");
466
467 evlist__for_each(rep->session->evlist, pos)
468 hists__output_resort(evsel__hists(pos), &prog);
469
470 ui_progress__finish();
471}
472
460static int __cmd_report(struct report *rep) 473static int __cmd_report(struct report *rep)
461{ 474{
462 int ret; 475 int ret;
@@ -505,13 +518,20 @@ static int __cmd_report(struct report *rep)
505 if (session_done()) 518 if (session_done())
506 return 0; 519 return 0;
507 520
521 /*
522 * recalculate number of entries after collapsing since it
523 * might be changed during the collapse phase.
524 */
525 rep->nr_entries = 0;
526 evlist__for_each(session->evlist, pos)
527 rep->nr_entries += evsel__hists(pos)->nr_entries;
528
508 if (rep->nr_entries == 0) { 529 if (rep->nr_entries == 0) {
509 ui__error("The %s file has no samples!\n", file->path); 530 ui__error("The %s file has no samples!\n", file->path);
510 return 0; 531 return 0;
511 } 532 }
512 533
513 evlist__for_each(session->evlist, pos) 534 report__output_resort(rep);
514 hists__output_resort(evsel__hists(pos));
515 535
516 return report__browse_hists(rep); 536 return report__browse_hists(rep);
517} 537}
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 0aa7747ff139..961cea183a83 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -285,7 +285,7 @@ static void perf_top__print_sym_table(struct perf_top *top)
285 } 285 }
286 286
287 hists__collapse_resort(hists, NULL); 287 hists__collapse_resort(hists, NULL);
288 hists__output_resort(hists); 288 hists__output_resort(hists, NULL);
289 289
290 hists__output_recalc_col_len(hists, top->print_entries - printed); 290 hists__output_recalc_col_len(hists, top->print_entries - printed);
291 putchar('\n'); 291 putchar('\n');
@@ -554,7 +554,7 @@ static void perf_top__sort_new_samples(void *arg)
554 } 554 }
555 555
556 hists__collapse_resort(hists, NULL); 556 hists__collapse_resort(hists, NULL);
557 hists__output_resort(hists); 557 hists__output_resort(hists, NULL);
558} 558}
559 559
560static void *display_thread_tui(void *arg) 560static void *display_thread_tui(void *arg)
diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c
index 614d5c4978ab..8d110dec393e 100644
--- a/tools/perf/tests/hists_cumulate.c
+++ b/tools/perf/tests/hists_cumulate.c
@@ -187,7 +187,7 @@ static int do_test(struct hists *hists, struct result *expected, size_t nr_expec
187 * function since TEST_ASSERT_VAL() returns in case of failure. 187 * function since TEST_ASSERT_VAL() returns in case of failure.
188 */ 188 */
189 hists__collapse_resort(hists, NULL); 189 hists__collapse_resort(hists, NULL);
190 hists__output_resort(hists); 190 hists__output_resort(hists, NULL);
191 191
192 if (verbose > 2) { 192 if (verbose > 2) {
193 pr_info("use callchain: %d, cumulate callchain: %d\n", 193 pr_info("use callchain: %d, cumulate callchain: %d\n",
@@ -454,12 +454,12 @@ static int test3(struct perf_evsel *evsel, struct machine *machine)
454 * 30.00% 10.00% perf perf [.] cmd_record 454 * 30.00% 10.00% perf perf [.] cmd_record
455 * 20.00% 0.00% bash libc [.] malloc 455 * 20.00% 0.00% bash libc [.] malloc
456 * 10.00% 10.00% bash [kernel] [k] page_fault 456 * 10.00% 10.00% bash [kernel] [k] page_fault
457 * 10.00% 10.00% perf [kernel] [k] schedule 457 * 10.00% 10.00% bash bash [.] xmalloc
458 * 10.00% 0.00% perf [kernel] [k] sys_perf_event_open
459 * 10.00% 10.00% perf [kernel] [k] page_fault 458 * 10.00% 10.00% perf [kernel] [k] page_fault
460 * 10.00% 10.00% perf libc [.] free
461 * 10.00% 10.00% perf libc [.] malloc 459 * 10.00% 10.00% perf libc [.] malloc
462 * 10.00% 10.00% bash bash [.] xmalloc 460 * 10.00% 10.00% perf [kernel] [k] schedule
461 * 10.00% 10.00% perf libc [.] free
462 * 10.00% 0.00% perf [kernel] [k] sys_perf_event_open
463 */ 463 */
464 struct result expected[] = { 464 struct result expected[] = {
465 { 7000, 2000, "perf", "perf", "main" }, 465 { 7000, 2000, "perf", "perf", "main" },
@@ -468,12 +468,12 @@ static int test3(struct perf_evsel *evsel, struct machine *machine)
468 { 3000, 1000, "perf", "perf", "cmd_record" }, 468 { 3000, 1000, "perf", "perf", "cmd_record" },
469 { 2000, 0, "bash", "libc", "malloc" }, 469 { 2000, 0, "bash", "libc", "malloc" },
470 { 1000, 1000, "bash", "[kernel]", "page_fault" }, 470 { 1000, 1000, "bash", "[kernel]", "page_fault" },
471 { 1000, 1000, "perf", "[kernel]", "schedule" }, 471 { 1000, 1000, "bash", "bash", "xmalloc" },
472 { 1000, 0, "perf", "[kernel]", "sys_perf_event_open" },
473 { 1000, 1000, "perf", "[kernel]", "page_fault" }, 472 { 1000, 1000, "perf", "[kernel]", "page_fault" },
473 { 1000, 1000, "perf", "[kernel]", "schedule" },
474 { 1000, 1000, "perf", "libc", "free" }, 474 { 1000, 1000, "perf", "libc", "free" },
475 { 1000, 1000, "perf", "libc", "malloc" }, 475 { 1000, 1000, "perf", "libc", "malloc" },
476 { 1000, 1000, "bash", "bash", "xmalloc" }, 476 { 1000, 0, "perf", "[kernel]", "sys_perf_event_open" },
477 }; 477 };
478 478
479 symbol_conf.use_callchain = false; 479 symbol_conf.use_callchain = false;
@@ -537,10 +537,13 @@ static int test4(struct perf_evsel *evsel, struct machine *machine)
537 * malloc 537 * malloc
538 * main 538 * main
539 * 539 *
540 * 10.00% 10.00% perf [kernel] [k] schedule 540 * 10.00% 10.00% bash bash [.] xmalloc
541 * | 541 * |
542 * --- schedule 542 * --- xmalloc
543 * run_command 543 * malloc
544 * xmalloc <--- NOTE: there's a cycle
545 * malloc
546 * xmalloc
544 * main 547 * main
545 * 548 *
546 * 10.00% 0.00% perf [kernel] [k] sys_perf_event_open 549 * 10.00% 0.00% perf [kernel] [k] sys_perf_event_open
@@ -556,6 +559,12 @@ static int test4(struct perf_evsel *evsel, struct machine *machine)
556 * run_command 559 * run_command
557 * main 560 * main
558 * 561 *
562 * 10.00% 10.00% perf [kernel] [k] schedule
563 * |
564 * --- schedule
565 * run_command
566 * main
567 *
559 * 10.00% 10.00% perf libc [.] free 568 * 10.00% 10.00% perf libc [.] free
560 * | 569 * |
561 * --- free 570 * --- free
@@ -570,15 +579,6 @@ static int test4(struct perf_evsel *evsel, struct machine *machine)
570 * run_command 579 * run_command
571 * main 580 * main
572 * 581 *
573 * 10.00% 10.00% bash bash [.] xmalloc
574 * |
575 * --- xmalloc
576 * malloc
577 * xmalloc <--- NOTE: there's a cycle
578 * malloc
579 * xmalloc
580 * main
581 *
582 */ 582 */
583 struct result expected[] = { 583 struct result expected[] = {
584 { 7000, 2000, "perf", "perf", "main" }, 584 { 7000, 2000, "perf", "perf", "main" },
@@ -587,12 +587,12 @@ static int test4(struct perf_evsel *evsel, struct machine *machine)
587 { 3000, 1000, "perf", "perf", "cmd_record" }, 587 { 3000, 1000, "perf", "perf", "cmd_record" },
588 { 2000, 0, "bash", "libc", "malloc" }, 588 { 2000, 0, "bash", "libc", "malloc" },
589 { 1000, 1000, "bash", "[kernel]", "page_fault" }, 589 { 1000, 1000, "bash", "[kernel]", "page_fault" },
590 { 1000, 1000, "perf", "[kernel]", "schedule" }, 590 { 1000, 1000, "bash", "bash", "xmalloc" },
591 { 1000, 0, "perf", "[kernel]", "sys_perf_event_open" }, 591 { 1000, 0, "perf", "[kernel]", "sys_perf_event_open" },
592 { 1000, 1000, "perf", "[kernel]", "page_fault" }, 592 { 1000, 1000, "perf", "[kernel]", "page_fault" },
593 { 1000, 1000, "perf", "[kernel]", "schedule" },
593 { 1000, 1000, "perf", "libc", "free" }, 594 { 1000, 1000, "perf", "libc", "free" },
594 { 1000, 1000, "perf", "libc", "malloc" }, 595 { 1000, 1000, "perf", "libc", "malloc" },
595 { 1000, 1000, "bash", "bash", "xmalloc" },
596 }; 596 };
597 struct callchain_result expected_callchain[] = { 597 struct callchain_result expected_callchain[] = {
598 { 598 {
@@ -622,9 +622,12 @@ static int test4(struct perf_evsel *evsel, struct machine *machine)
622 { "bash", "main" }, }, 622 { "bash", "main" }, },
623 }, 623 },
624 { 624 {
625 3, { { "[kernel]", "schedule" }, 625 6, { { "bash", "xmalloc" },
626 { "perf", "run_command" }, 626 { "libc", "malloc" },
627 { "perf", "main" }, }, 627 { "bash", "xmalloc" },
628 { "libc", "malloc" },
629 { "bash", "xmalloc" },
630 { "bash", "main" }, },
628 }, 631 },
629 { 632 {
630 3, { { "[kernel]", "sys_perf_event_open" }, 633 3, { { "[kernel]", "sys_perf_event_open" },
@@ -638,6 +641,11 @@ static int test4(struct perf_evsel *evsel, struct machine *machine)
638 { "perf", "main" }, }, 641 { "perf", "main" }, },
639 }, 642 },
640 { 643 {
644 3, { { "[kernel]", "schedule" },
645 { "perf", "run_command" },
646 { "perf", "main" }, },
647 },
648 {
641 4, { { "libc", "free" }, 649 4, { { "libc", "free" },
642 { "perf", "cmd_record" }, 650 { "perf", "cmd_record" },
643 { "perf", "run_command" }, 651 { "perf", "run_command" },
@@ -649,14 +657,6 @@ static int test4(struct perf_evsel *evsel, struct machine *machine)
649 { "perf", "run_command" }, 657 { "perf", "run_command" },
650 { "perf", "main" }, }, 658 { "perf", "main" }, },
651 }, 659 },
652 {
653 6, { { "bash", "xmalloc" },
654 { "libc", "malloc" },
655 { "bash", "xmalloc" },
656 { "libc", "malloc" },
657 { "bash", "xmalloc" },
658 { "bash", "main" }, },
659 },
660 }; 660 };
661 661
662 symbol_conf.use_callchain = true; 662 symbol_conf.use_callchain = true;
diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filter.c
index 74f257a81265..59e53db7914c 100644
--- a/tools/perf/tests/hists_filter.c
+++ b/tools/perf/tests/hists_filter.c
@@ -138,7 +138,7 @@ int test__hists_filter(void)
138 struct hists *hists = evsel__hists(evsel); 138 struct hists *hists = evsel__hists(evsel);
139 139
140 hists__collapse_resort(hists, NULL); 140 hists__collapse_resort(hists, NULL);
141 hists__output_resort(hists); 141 hists__output_resort(hists, NULL);
142 142
143 if (verbose > 2) { 143 if (verbose > 2) {
144 pr_info("Normal histogram\n"); 144 pr_info("Normal histogram\n");
diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c
index a748f2be1222..f5547610da02 100644
--- a/tools/perf/tests/hists_output.c
+++ b/tools/perf/tests/hists_output.c
@@ -152,7 +152,7 @@ static int test1(struct perf_evsel *evsel, struct machine *machine)
152 goto out; 152 goto out;
153 153
154 hists__collapse_resort(hists, NULL); 154 hists__collapse_resort(hists, NULL);
155 hists__output_resort(hists); 155 hists__output_resort(hists, NULL);
156 156
157 if (verbose > 2) { 157 if (verbose > 2) {
158 pr_info("[fields = %s, sort = %s]\n", field_order, sort_order); 158 pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
@@ -252,7 +252,7 @@ static int test2(struct perf_evsel *evsel, struct machine *machine)
252 goto out; 252 goto out;
253 253
254 hists__collapse_resort(hists, NULL); 254 hists__collapse_resort(hists, NULL);
255 hists__output_resort(hists); 255 hists__output_resort(hists, NULL);
256 256
257 if (verbose > 2) { 257 if (verbose > 2) {
258 pr_info("[fields = %s, sort = %s]\n", field_order, sort_order); 258 pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
@@ -306,7 +306,7 @@ static int test3(struct perf_evsel *evsel, struct machine *machine)
306 goto out; 306 goto out;
307 307
308 hists__collapse_resort(hists, NULL); 308 hists__collapse_resort(hists, NULL);
309 hists__output_resort(hists); 309 hists__output_resort(hists, NULL);
310 310
311 if (verbose > 2) { 311 if (verbose > 2) {
312 pr_info("[fields = %s, sort = %s]\n", field_order, sort_order); 312 pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
@@ -384,7 +384,7 @@ static int test4(struct perf_evsel *evsel, struct machine *machine)
384 goto out; 384 goto out;
385 385
386 hists__collapse_resort(hists, NULL); 386 hists__collapse_resort(hists, NULL);
387 hists__output_resort(hists); 387 hists__output_resort(hists, NULL);
388 388
389 if (verbose > 2) { 389 if (verbose > 2) {
390 pr_info("[fields = %s, sort = %s]\n", field_order, sort_order); 390 pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
@@ -487,7 +487,7 @@ static int test5(struct perf_evsel *evsel, struct machine *machine)
487 goto out; 487 goto out;
488 488
489 hists__collapse_resort(hists, NULL); 489 hists__collapse_resort(hists, NULL);
490 hists__output_resort(hists); 490 hists__output_resort(hists, NULL);
491 491
492 if (verbose > 2) { 492 if (verbose > 2) {
493 pr_info("[fields = %s, sort = %s]\n", field_order, sort_order); 493 pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index e6bb04b5b09b..788506eef567 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -550,7 +550,7 @@ static int hist_browser__show_callchain(struct hist_browser *browser,
550 bool need_percent; 550 bool need_percent;
551 551
552 node = rb_first(root); 552 node = rb_first(root);
553 need_percent = !!rb_next(node); 553 need_percent = node && rb_next(node);
554 554
555 while (node) { 555 while (node) {
556 struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); 556 struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node);
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index dc0d095f318c..482adae3cc44 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -204,6 +204,9 @@ static int __hpp__sort_acc(struct hist_entry *a, struct hist_entry *b,
204 if (ret) 204 if (ret)
205 return ret; 205 return ret;
206 206
207 if (a->thread != b->thread || !symbol_conf.use_callchain)
208 return 0;
209
207 ret = b->callchain->max_depth - a->callchain->max_depth; 210 ret = b->callchain->max_depth - a->callchain->max_depth;
208 } 211 }
209 return ret; 212 return ret;
diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c
index 2f612562978c..3c38f25b1695 100644
--- a/tools/perf/ui/tui/setup.c
+++ b/tools/perf/ui/tui/setup.c
@@ -1,5 +1,8 @@
1#include <signal.h> 1#include <signal.h>
2#include <stdbool.h> 2#include <stdbool.h>
3#ifdef HAVE_BACKTRACE_SUPPORT
4#include <execinfo.h>
5#endif
3 6
4#include "../../util/cache.h" 7#include "../../util/cache.h"
5#include "../../util/debug.h" 8#include "../../util/debug.h"
@@ -88,6 +91,25 @@ int ui__getch(int delay_secs)
88 return SLkp_getkey(); 91 return SLkp_getkey();
89} 92}
90 93
94#ifdef HAVE_BACKTRACE_SUPPORT
95static void ui__signal_backtrace(int sig)
96{
97 void *stackdump[32];
98 size_t size;
99
100 ui__exit(false);
101 psignal(sig, "perf");
102
103 printf("-------- backtrace --------\n");
104 size = backtrace(stackdump, ARRAY_SIZE(stackdump));
105 backtrace_symbols_fd(stackdump, size, STDOUT_FILENO);
106
107 exit(0);
108}
109#else
110# define ui__signal_backtrace ui__signal
111#endif
112
91static void ui__signal(int sig) 113static void ui__signal(int sig)
92{ 114{
93 ui__exit(false); 115 ui__exit(false);
@@ -122,8 +144,8 @@ int ui__init(void)
122 ui_browser__init(); 144 ui_browser__init();
123 tui_progress__init(); 145 tui_progress__init();
124 146
125 signal(SIGSEGV, ui__signal); 147 signal(SIGSEGV, ui__signal_backtrace);
126 signal(SIGFPE, ui__signal); 148 signal(SIGFPE, ui__signal_backtrace);
127 signal(SIGINT, ui__signal); 149 signal(SIGINT, ui__signal);
128 signal(SIGQUIT, ui__signal); 150 signal(SIGQUIT, ui__signal);
129 signal(SIGTERM, ui__signal); 151 signal(SIGTERM, ui__signal);
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 64b377e591e4..14e7a123d43b 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -841,3 +841,33 @@ char *callchain_list__sym_name(struct callchain_list *cl,
841 841
842 return bf; 842 return bf;
843} 843}
844
845static void free_callchain_node(struct callchain_node *node)
846{
847 struct callchain_list *list, *tmp;
848 struct callchain_node *child;
849 struct rb_node *n;
850
851 list_for_each_entry_safe(list, tmp, &node->val, list) {
852 list_del(&list->list);
853 free(list);
854 }
855
856 n = rb_first(&node->rb_root_in);
857 while (n) {
858 child = container_of(n, struct callchain_node, rb_node_in);
859 n = rb_next(n);
860 rb_erase(&child->rb_node_in, &node->rb_root_in);
861
862 free_callchain_node(child);
863 free(child);
864 }
865}
866
867void free_callchain(struct callchain_root *root)
868{
869 if (!symbol_conf.use_callchain)
870 return;
871
872 free_callchain_node(&root->node);
873}
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index dbc08cf5f970..c0ec1acc38e4 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -198,4 +198,6 @@ static inline int arch_skip_callchain_idx(struct thread *thread __maybe_unused,
198char *callchain_list__sym_name(struct callchain_list *cl, 198char *callchain_list__sym_name(struct callchain_list *cl,
199 char *bf, size_t bfsize, bool show_dso); 199 char *bf, size_t bfsize, bool show_dso);
200 200
201void free_callchain(struct callchain_root *root);
202
201#endif /* __PERF_CALLCHAIN_H */ 203#endif /* __PERF_CALLCHAIN_H */
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 6e88b9e395df..182395546ddc 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -6,6 +6,7 @@
6#include "evlist.h" 6#include "evlist.h"
7#include "evsel.h" 7#include "evsel.h"
8#include "annotate.h" 8#include "annotate.h"
9#include "ui/progress.h"
9#include <math.h> 10#include <math.h>
10 11
11static bool hists__filter_entry_by_dso(struct hists *hists, 12static bool hists__filter_entry_by_dso(struct hists *hists,
@@ -303,7 +304,7 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template,
303 size_t callchain_size = 0; 304 size_t callchain_size = 0;
304 struct hist_entry *he; 305 struct hist_entry *he;
305 306
306 if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain) 307 if (symbol_conf.use_callchain)
307 callchain_size = sizeof(struct callchain_root); 308 callchain_size = sizeof(struct callchain_root);
308 309
309 he = zalloc(sizeof(*he) + callchain_size); 310 he = zalloc(sizeof(*he) + callchain_size);
@@ -736,7 +737,7 @@ iter_add_single_cumulative_entry(struct hist_entry_iter *iter,
736 iter->he = he; 737 iter->he = he;
737 he_cache[iter->curr++] = he; 738 he_cache[iter->curr++] = he;
738 739
739 callchain_append(he->callchain, &callchain_cursor, sample->period); 740 hist_entry__append_callchain(he, sample);
740 741
741 /* 742 /*
742 * We need to re-initialize the cursor since callchain_append() 743 * We need to re-initialize the cursor since callchain_append()
@@ -809,7 +810,8 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter,
809 iter->he = he; 810 iter->he = he;
810 he_cache[iter->curr++] = he; 811 he_cache[iter->curr++] = he;
811 812
812 callchain_append(he->callchain, &cursor, sample->period); 813 if (symbol_conf.use_callchain)
814 callchain_append(he->callchain, &cursor, sample->period);
813 return 0; 815 return 0;
814} 816}
815 817
@@ -945,6 +947,7 @@ void hist_entry__free(struct hist_entry *he)
945 zfree(&he->mem_info); 947 zfree(&he->mem_info);
946 zfree(&he->stat_acc); 948 zfree(&he->stat_acc);
947 free_srcline(he->srcline); 949 free_srcline(he->srcline);
950 free_callchain(he->callchain);
948 free(he); 951 free(he);
949} 952}
950 953
@@ -987,6 +990,7 @@ static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused,
987 else 990 else
988 p = &(*p)->rb_right; 991 p = &(*p)->rb_right;
989 } 992 }
993 hists->nr_entries++;
990 994
991 rb_link_node(&he->rb_node_in, parent, p); 995 rb_link_node(&he->rb_node_in, parent, p);
992 rb_insert_color(&he->rb_node_in, root); 996 rb_insert_color(&he->rb_node_in, root);
@@ -1024,7 +1028,10 @@ void hists__collapse_resort(struct hists *hists, struct ui_progress *prog)
1024 if (!sort__need_collapse) 1028 if (!sort__need_collapse)
1025 return; 1029 return;
1026 1030
1031 hists->nr_entries = 0;
1032
1027 root = hists__get_rotate_entries_in(hists); 1033 root = hists__get_rotate_entries_in(hists);
1034
1028 next = rb_first(root); 1035 next = rb_first(root);
1029 1036
1030 while (next) { 1037 while (next) {
@@ -1119,7 +1126,7 @@ static void __hists__insert_output_entry(struct rb_root *entries,
1119 rb_insert_color(&he->rb_node, entries); 1126 rb_insert_color(&he->rb_node, entries);
1120} 1127}
1121 1128
1122void hists__output_resort(struct hists *hists) 1129void hists__output_resort(struct hists *hists, struct ui_progress *prog)
1123{ 1130{
1124 struct rb_root *root; 1131 struct rb_root *root;
1125 struct rb_node *next; 1132 struct rb_node *next;
@@ -1148,6 +1155,9 @@ void hists__output_resort(struct hists *hists)
1148 1155
1149 if (!n->filtered) 1156 if (!n->filtered)
1150 hists__calc_col_len(hists, n); 1157 hists__calc_col_len(hists, n);
1158
1159 if (prog)
1160 ui_progress__update(prog, 1);
1151 } 1161 }
1152} 1162}
1153 1163
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index d0ef9a19a744..46bd50344f85 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -121,7 +121,7 @@ int hist_entry__sort_snprintf(struct hist_entry *he, char *bf, size_t size,
121 struct hists *hists); 121 struct hists *hists);
122void hist_entry__free(struct hist_entry *); 122void hist_entry__free(struct hist_entry *);
123 123
124void hists__output_resort(struct hists *hists); 124void hists__output_resort(struct hists *hists, struct ui_progress *prog);
125void hists__collapse_resort(struct hists *hists, struct ui_progress *prog); 125void hists__collapse_resort(struct hists *hists, struct ui_progress *prog);
126 126
127void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel); 127void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel);
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 28eb1417cb2a..7f9b8632e433 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -495,9 +495,11 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
495 } 495 }
496 496
497 if (ntevs == 0) { /* No error but failed to find probe point. */ 497 if (ntevs == 0) { /* No error but failed to find probe point. */
498 pr_warning("Probe point '%s' not found.\n", 498 pr_warning("Probe point '%s' not found in debuginfo.\n",
499 synthesize_perf_probe_point(&pev->point)); 499 synthesize_perf_probe_point(&pev->point));
500 return -ENOENT; 500 if (need_dwarf)
501 return -ENOENT;
502 return 0;
501 } 503 }
502 /* Error path : ntevs < 0 */ 504 /* Error path : ntevs < 0 */
503 pr_debug("An error occurred in debuginfo analysis (%d).\n", ntevs); 505 pr_debug("An error occurred in debuginfo analysis (%d).\n", ntevs);
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index c7918f83b300..b5247d777f0e 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -989,8 +989,24 @@ static int debuginfo__find_probes(struct debuginfo *dbg,
989 int ret = 0; 989 int ret = 0;
990 990
991#if _ELFUTILS_PREREQ(0, 142) 991#if _ELFUTILS_PREREQ(0, 142)
992 Elf *elf;
993 GElf_Ehdr ehdr;
994 GElf_Shdr shdr;
995
992 /* Get the call frame information from this dwarf */ 996 /* Get the call frame information from this dwarf */
993 pf->cfi = dwarf_getcfi_elf(dwarf_getelf(dbg->dbg)); 997 elf = dwarf_getelf(dbg->dbg);
998 if (elf == NULL)
999 return -EINVAL;
1000
1001 if (gelf_getehdr(elf, &ehdr) == NULL)
1002 return -EINVAL;
1003
1004 if (elf_section_by_name(elf, &ehdr, &shdr, ".eh_frame", NULL) &&
1005 shdr.sh_type == SHT_PROGBITS) {
1006 pf->cfi = dwarf_getcfi_elf(elf);
1007 } else {
1008 pf->cfi = dwarf_getcfi(dbg->dbg);
1009 }
994#endif 1010#endif
995 1011
996 off = 0; 1012 off = 0;
diff --git a/tools/testing/selftests/exec/execveat.c b/tools/testing/selftests/exec/execveat.c
index d273624c93a6..e238c9559caf 100644
--- a/tools/testing/selftests/exec/execveat.c
+++ b/tools/testing/selftests/exec/execveat.c
@@ -62,7 +62,7 @@ static int _check_execveat_fail(int fd, const char *path, int flags,
62} 62}
63 63
64static int check_execveat_invoked_rc(int fd, const char *path, int flags, 64static int check_execveat_invoked_rc(int fd, const char *path, int flags,
65 int expected_rc) 65 int expected_rc, int expected_rc2)
66{ 66{
67 int status; 67 int status;
68 int rc; 68 int rc;
@@ -98,9 +98,10 @@ static int check_execveat_invoked_rc(int fd, const char *path, int flags,
98 child, status); 98 child, status);
99 return 1; 99 return 1;
100 } 100 }
101 if (WEXITSTATUS(status) != expected_rc) { 101 if ((WEXITSTATUS(status) != expected_rc) &&
102 printf("[FAIL] (child %d exited with %d not %d)\n", 102 (WEXITSTATUS(status) != expected_rc2)) {
103 child, WEXITSTATUS(status), expected_rc); 103 printf("[FAIL] (child %d exited with %d not %d nor %d)\n",
104 child, WEXITSTATUS(status), expected_rc, expected_rc2);
104 return 1; 105 return 1;
105 } 106 }
106 printf("[OK]\n"); 107 printf("[OK]\n");
@@ -109,7 +110,7 @@ static int check_execveat_invoked_rc(int fd, const char *path, int flags,
109 110
110static int check_execveat(int fd, const char *path, int flags) 111static int check_execveat(int fd, const char *path, int flags)
111{ 112{
112 return check_execveat_invoked_rc(fd, path, flags, 99); 113 return check_execveat_invoked_rc(fd, path, flags, 99, 99);
113} 114}
114 115
115static char *concat(const char *left, const char *right) 116static char *concat(const char *left, const char *right)
@@ -192,9 +193,15 @@ static int check_execveat_pathmax(int dot_dfd, const char *src, int is_script)
192 * Execute as a long pathname relative to ".". If this is a script, 193 * Execute as a long pathname relative to ".". If this is a script,
193 * the interpreter will launch but fail to open the script because its 194 * the interpreter will launch but fail to open the script because its
194 * name ("/dev/fd/5/xxx....") is bigger than PATH_MAX. 195 * name ("/dev/fd/5/xxx....") is bigger than PATH_MAX.
196 *
197 * The failure code is usually 127 (POSIX: "If a command is not found,
198 * the exit status shall be 127."), but some systems give 126 (POSIX:
199 * "If the command name is found, but it is not an executable utility,
200 * the exit status shall be 126."), so allow either.
195 */ 201 */
196 if (is_script) 202 if (is_script)
197 fail += check_execveat_invoked_rc(dot_dfd, longpath, 0, 127); 203 fail += check_execveat_invoked_rc(dot_dfd, longpath, 0,
204 127, 126);
198 else 205 else
199 fail += check_execveat(dot_dfd, longpath, 0); 206 fail += check_execveat(dot_dfd, longpath, 0);
200 207
diff --git a/tools/testing/selftests/mqueue/mq_perf_tests.c b/tools/testing/selftests/mqueue/mq_perf_tests.c
index 94dae65eea41..8519e9ee97e3 100644
--- a/tools/testing/selftests/mqueue/mq_perf_tests.c
+++ b/tools/testing/selftests/mqueue/mq_perf_tests.c
@@ -536,10 +536,9 @@ int main(int argc, char *argv[])
536{ 536{
537 struct mq_attr attr; 537 struct mq_attr attr;
538 char *option, *next_option; 538 char *option, *next_option;
539 int i, cpu; 539 int i, cpu, rc;
540 struct sigaction sa; 540 struct sigaction sa;
541 poptContext popt_context; 541 poptContext popt_context;
542 char rc;
543 void *retval; 542 void *retval;
544 543
545 main_thread = pthread_self(); 544 main_thread = pthread_self();
diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile
index 4c4b1f631ecf..077828c889f1 100644
--- a/tools/testing/selftests/vm/Makefile
+++ b/tools/testing/selftests/vm/Makefile
@@ -7,7 +7,7 @@ BINARIES += transhuge-stress
7 7
8all: $(BINARIES) 8all: $(BINARIES)
9%: %.c 9%: %.c
10 $(CC) $(CFLAGS) -o $@ $^ 10 $(CC) $(CFLAGS) -o $@ $^ -lrt
11 11
12run_tests: all 12run_tests: all
13 @/bin/sh ./run_vmtests || (echo "vmtests: [FAIL]"; exit 1) 13 @/bin/sh ./run_vmtests || (echo "vmtests: [FAIL]"; exit 1)