aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/testing/sysfs-devices-system-cpu1
-rw-r--r--Documentation/admin-guide/kernel-parameters.txt45
-rw-r--r--Documentation/devicetree/bindings/net/micrel-ksz90x1.txt7
-rw-r--r--Documentation/networking/ppp_generic.txt6
-rw-r--r--Documentation/userspace-api/index.rst1
-rw-r--r--Documentation/userspace-api/spec_ctrl.rst94
-rw-r--r--MAINTAINERS22
-rw-r--r--Makefile11
-rw-r--r--arch/alpha/Kconfig1
-rw-r--r--arch/alpha/include/asm/dma-mapping.h8
-rw-r--r--arch/alpha/kernel/io.c14
-rw-r--r--arch/alpha/kernel/pci-noop.c33
-rw-r--r--arch/alpha/kernel/pci_iommu.c4
-rw-r--r--arch/arm/boot/dts/sun4i-a10.dtsi6
-rw-r--r--arch/arm/boot/dts/sun8i-h3-orangepi-one.dts1
-rw-r--r--arch/arm/boot/dts/sun8i-v3s-licheepi-zero-dock.dts2
-rw-r--r--arch/arm/mach-ep93xx/core.c2
-rw-r--r--arch/arm/mach-ixp4xx/avila-setup.c2
-rw-r--r--arch/arm/mach-ixp4xx/dsmg600-setup.c2
-rw-r--r--arch/arm/mach-ixp4xx/fsg-setup.c2
-rw-r--r--arch/arm/mach-ixp4xx/ixdp425-setup.c2
-rw-r--r--arch/arm/mach-ixp4xx/nas100d-setup.c2
-rw-r--r--arch/arm/mach-ixp4xx/nslu2-setup.c2
-rw-r--r--arch/arm/mach-pxa/palmz72.c2
-rw-r--r--arch/arm/mach-pxa/viper.c4
-rw-r--r--arch/arm/mach-sa1100/simpad.c2
-rw-r--r--arch/arm/mm/dma-mapping.c16
-rw-r--r--arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts1
-rw-r--r--arch/arm64/include/asm/atomic_lse.h24
-rw-r--r--arch/arm64/kernel/arm64ksyms.c8
-rw-r--r--arch/arm64/lib/tishift.S15
-rw-r--r--arch/arm64/mm/fault.c51
-rw-r--r--arch/arm64/mm/mmu.c16
-rw-r--r--arch/mips/boot/compressed/uart-16550.c6
-rw-r--r--arch/mips/boot/dts/xilfpga/Makefile2
-rw-r--r--arch/mips/generic/Platform1
-rw-r--r--arch/mips/kernel/ptrace.c22
-rw-r--r--arch/mips/kernel/ptrace32.c4
-rw-r--r--arch/mips/kvm/mips.c2
-rw-r--r--arch/mips/mm/c-r4k.c9
-rw-r--r--arch/powerpc/include/asm/exception-64s.h29
-rw-r--r--arch/powerpc/include/asm/feature-fixups.h19
-rw-r--r--arch/powerpc/include/asm/kvm_book3s.h1
-rw-r--r--arch/powerpc/include/asm/security_features.h11
-rw-r--r--arch/powerpc/kernel/asm-offsets.c1
-rw-r--r--arch/powerpc/kernel/cpu_setup_power.S6
-rw-r--r--arch/powerpc/kernel/dt_cpu_ftrs.c1
-rw-r--r--arch/powerpc/kernel/exceptions-64s.S19
-rw-r--r--arch/powerpc/kernel/security.c149
-rw-r--r--arch/powerpc/kernel/vmlinux.lds.S14
-rw-r--r--arch/powerpc/kvm/book3s_64_mmu_radix.c6
-rw-r--r--arch/powerpc/kvm/book3s_hv.c1
-rw-r--r--arch/powerpc/kvm/book3s_hv_rmhandlers.S97
-rw-r--r--arch/powerpc/kvm/book3s_xive_template.c108
-rw-r--r--arch/powerpc/lib/feature-fixups.c115
-rw-r--r--arch/powerpc/platforms/powernv/setup.c1
-rw-r--r--arch/powerpc/platforms/pseries/setup.c1
-rw-r--r--arch/s390/kvm/vsie.c2
-rw-r--r--arch/x86/include/asm/cpufeatures.h20
-rw-r--r--arch/x86/include/asm/kvm_host.h2
-rw-r--r--arch/x86/include/asm/msr-index.h9
-rw-r--r--arch/x86/include/asm/nospec-branch.h43
-rw-r--r--arch/x86/include/asm/spec-ctrl.h80
-rw-r--r--arch/x86/include/asm/thread_info.h4
-rw-r--r--arch/x86/kernel/cpu/amd.c22
-rw-r--r--arch/x86/kernel/cpu/bugs.c397
-rw-r--r--arch/x86/kernel/cpu/common.c67
-rw-r--r--arch/x86/kernel/cpu/cpu.h2
-rw-r--r--arch/x86/kernel/cpu/intel.c3
-rw-r--r--arch/x86/kernel/process.c146
-rw-r--r--arch/x86/kernel/smpboot.c5
-rw-r--r--arch/x86/kvm/cpuid.c26
-rw-r--r--arch/x86/kvm/hyperv.c19
-rw-r--r--arch/x86/kvm/lapic.c16
-rw-r--r--arch/x86/kvm/svm.c66
-rw-r--r--arch/x86/kvm/vmx.c31
-rw-r--r--arch/x86/kvm/x86.c30
-rw-r--r--drivers/ata/ahci.c1
-rw-r--r--drivers/ata/libata-core.c9
-rw-r--r--drivers/base/cpu.c8
-rw-r--r--drivers/base/node.c5
-rw-r--r--drivers/base/power/main.c7
-rw-r--r--drivers/bcma/driver_mips.c2
-rw-r--r--drivers/block/loop.c1
-rw-r--r--drivers/firmware/qcom_scm-32.c8
-rw-r--r--drivers/gpu/drm/rcar-du/rcar_lvds.c3
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.c5
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.h1
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_fb.c22
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_msg.c48
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_msg.h25
-rw-r--r--drivers/infiniband/core/umem.c7
-rw-r--r--drivers/infiniband/hw/cxgb4/mem.c4
-rw-r--r--drivers/infiniband/hw/hfi1/chip.c4
-rw-r--r--drivers/infiniband/hw/hns/hns_roce_cq.c1
-rw-r--r--drivers/infiniband/hw/hns/hns_roce_hw_v1.c3
-rw-r--r--drivers/infiniband/hw/hns/hns_roce_hw_v2.c32
-rw-r--r--drivers/infiniband/hw/hns/hns_roce_main.c2
-rw-r--r--drivers/infiniband/hw/hns/hns_roce_qp.c10
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw.h1
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_cm.c2
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_hw.c4
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_main.c7
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_verbs.c13
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_verbs.h1
-rw-r--r--drivers/infiniband/hw/mlx5/main.c2
-rw-r--r--drivers/infiniband/hw/mlx5/qp.c18
-rw-r--r--drivers/infiniband/hw/qedr/verbs.c60
-rw-r--r--drivers/infiniband/sw/rxe/rxe_verbs.c10
-rw-r--r--drivers/infiniband/ulp/srpt/Kconfig2
-rw-r--r--drivers/isdn/hardware/eicon/diva.c22
-rw-r--r--drivers/isdn/hardware/eicon/diva.h5
-rw-r--r--drivers/isdn/hardware/eicon/divasmain.c18
-rw-r--r--drivers/mfd/cros_ec_spi.c24
-rw-r--r--drivers/mmc/core/block.c2
-rw-r--r--drivers/mmc/host/sdhci-iproc.c33
-rw-r--r--drivers/net/dsa/bcm_sf2_cfp.c36
-rw-r--r--drivers/net/ethernet/3com/3c59x.c104
-rw-r--r--drivers/net/ethernet/8390/ne.c4
-rw-r--r--drivers/net/ethernet/amd/pcnet32.c10
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cudbg_entity.h28
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c88
-rw-r--r--drivers/net/ethernet/cisco/enic/enic_main.c8
-rw-r--r--drivers/net/ethernet/freescale/fec_main.c1
-rw-r--r--drivers/net/ethernet/freescale/fec_ptp.c14
-rw-r--r--drivers/net/ethernet/ibm/ibmvnic.c50
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/icm.c16
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/intf.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/main.c4
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/qp.c4
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_rx.c42
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c12
-rw-r--r--drivers/net/ethernet/netronome/nfp/bpf/main.c2
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_cxt.c2
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_ll2.c61
-rw-r--r--drivers/net/ethernet/qlogic/qede/qede_main.c3
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.h2
-rw-r--r--drivers/net/ipvlan/ipvlan_main.c4
-rw-r--r--drivers/net/phy/bcm-cygnus.c6
-rw-r--r--drivers/net/phy/bcm-phy-lib.c2
-rw-r--r--drivers/net/phy/bcm-phy-lib.h7
-rw-r--r--drivers/net/phy/bcm7xxx.c4
-rw-r--r--drivers/net/phy/micrel.c31
-rw-r--r--drivers/net/ppp/ppp_generic.c27
-rw-r--r--drivers/net/tun.c46
-rw-r--r--drivers/net/virtio_net.c21
-rw-r--r--drivers/net/vmxnet3/vmxnet3_drv.c72
-rw-r--r--drivers/net/vmxnet3/vmxnet3_int.h8
-rw-r--r--drivers/net/wireless/mac80211_hwsim.c4
-rw-r--r--drivers/nvme/host/Kconfig2
-rw-r--r--drivers/nvme/target/Kconfig2
-rw-r--r--drivers/platform/chrome/cros_ec_proto.c2
-rw-r--r--drivers/s390/scsi/zfcp_dbf.c23
-rw-r--r--drivers/s390/scsi/zfcp_ext.h5
-rw-r--r--drivers/s390/scsi/zfcp_scsi.c14
-rw-r--r--drivers/scsi/Makefile2
-rw-r--r--drivers/scsi/sg.c2
-rw-r--r--drivers/scsi/sr_ioctl.c10
-rw-r--r--drivers/ssb/Kconfig4
-rw-r--r--drivers/staging/lustre/lnet/Kconfig2
-rw-r--r--drivers/target/target_core_user.c2
-rw-r--r--drivers/vhost/vhost.c3
-rw-r--r--drivers/xen/swiotlb-xen.c2
-rw-r--r--fs/affs/namei.c15
-rw-r--r--fs/aio.c4
-rw-r--r--fs/befs/linuxvfs.c17
-rw-r--r--fs/btrfs/inode.c19
-rw-r--r--fs/cachefiles/namei.c10
-rw-r--r--fs/cifs/Kconfig2
-rw-r--r--fs/cramfs/inode.c2
-rw-r--r--fs/dcache.c22
-rw-r--r--fs/ecryptfs/inode.c3
-rw-r--r--fs/ext2/inode.c10
-rw-r--r--fs/ext2/namei.c6
-rw-r--r--fs/ext4/namei.c6
-rw-r--r--fs/f2fs/namei.c12
-rw-r--r--fs/jffs2/dir.c12
-rw-r--r--fs/jfs/namei.c12
-rw-r--r--fs/kernfs/mount.c1
-rw-r--r--fs/nfsd/vfs.c22
-rw-r--r--fs/nilfs2/namei.c6
-rw-r--r--fs/ocfs2/cluster/heartbeat.c11
-rw-r--r--fs/orangefs/namei.c9
-rw-r--r--fs/proc/array.c25
-rw-r--r--fs/reiserfs/namei.c12
-rw-r--r--fs/seq_file.c5
-rw-r--r--fs/super.c30
-rw-r--r--fs/sysfs/mount.c6
-rw-r--r--fs/udf/namei.c6
-rw-r--r--fs/ufs/namei.c6
-rw-r--r--include/linux/bpf_verifier.h3
-rw-r--r--include/linux/cpu.h2
-rw-r--r--include/linux/dcache.h1
-rw-r--r--include/linux/gfp.h2
-rw-r--r--include/linux/memory_hotplug.h3
-rw-r--r--include/linux/mlx5/driver.h12
-rw-r--r--include/linux/mm.h1
-rw-r--r--include/linux/node.h8
-rw-r--r--include/linux/nospec.h10
-rw-r--r--include/linux/sched.h10
-rw-r--r--include/linux/seccomp.h5
-rw-r--r--include/net/netfilter/nf_tables.h5
-rw-r--r--include/net/sctp/sctp.h2
-rw-r--r--include/net/tls.h3
-rw-r--r--include/rdma/ib_umem.h1
-rw-r--r--include/rdma/uverbs_ioctl.h10
-rw-r--r--include/trace/events/sched.h4
-rw-r--r--include/uapi/linux/netfilter/nf_conntrack_tcp.h3
-rw-r--r--include/uapi/linux/nl80211.h2
-rw-r--r--include/uapi/linux/ppp-ioctl.h2
-rw-r--r--include/uapi/linux/prctl.h12
-rw-r--r--include/uapi/linux/seccomp.h5
-rw-r--r--init/main.c1
-rw-r--r--ipc/shm.c19
-rw-r--r--kernel/bpf/core.c100
-rw-r--r--kernel/bpf/sockmap.c18
-rw-r--r--kernel/bpf/verifier.c145
-rw-r--r--kernel/kthread.c6
-rw-r--r--kernel/sched/topology.c2
-rw-r--r--kernel/seccomp.c21
-rw-r--r--kernel/sys.c28
-rw-r--r--lib/iov_iter.c4
-rw-r--r--lib/radix-tree.c4
-rw-r--r--mm/cma.c83
-rw-r--r--mm/compaction.c4
-rw-r--r--mm/internal.h4
-rw-r--r--mm/kasan/kasan.c66
-rw-r--r--mm/memory_hotplug.c2
-rw-r--r--mm/page_alloc.c99
-rw-r--r--mm/swapfile.c7
-rw-r--r--net/9p/Kconfig2
-rw-r--r--net/batman-adv/multicast.c2
-rw-r--r--net/batman-adv/translation-table.c84
-rw-r--r--net/bridge/netfilter/ebt_stp.c4
-rw-r--r--net/core/dev.c2
-rw-r--r--net/core/filter.c11
-rw-r--r--net/core/sock.c2
-rw-r--r--net/dccp/proto.c2
-rw-r--r--net/dsa/dsa2.c9
-rw-r--r--net/ipv4/fib_frontend.c9
-rw-r--r--net/ipv4/ip_gre.c4
-rw-r--r--net/ipv4/ip_output.c3
-rw-r--r--net/ipv4/ip_sockglue.c2
-rw-r--r--net/ipv4/ipmr_base.c5
-rw-r--r--net/ipv4/netfilter/ip_tables.c1
-rw-r--r--net/ipv4/netfilter/ipt_rpfilter.c2
-rw-r--r--net/ipv4/route.c7
-rw-r--r--net/ipv4/tcp_output.c7
-rw-r--r--net/ipv6/ip6_gre.c286
-rw-r--r--net/ipv6/ip6_output.c3
-rw-r--r--net/ipv6/netfilter/ip6_tables.c1
-rw-r--r--net/mac80211/mesh_plink.c8
-rw-r--r--net/netfilter/core.c3
-rw-r--r--net/netfilter/ipvs/ip_vs_conn.c17
-rw-r--r--net/netfilter/ipvs/ip_vs_core.c12
-rw-r--r--net/netfilter/nf_conntrack_proto_tcp.c11
-rw-r--r--net/netfilter/nf_tables_api.c77
-rw-r--r--net/netfilter/nf_tables_core.c21
-rw-r--r--net/netfilter/nfnetlink_acct.c2
-rw-r--r--net/netfilter/nfnetlink_cthelper.c7
-rw-r--r--net/netfilter/nft_compat.c201
-rw-r--r--net/netfilter/nft_immediate.c15
-rw-r--r--net/netfilter/x_tables.c6
-rw-r--r--net/packet/af_packet.c4
-rw-r--r--net/rds/Kconfig2
-rw-r--r--net/sched/act_vlan.c2
-rw-r--r--net/sched/cls_api.c2
-rw-r--r--net/sched/sch_red.c5
-rw-r--r--net/sched/sch_tbf.c5
-rw-r--r--net/sctp/ipv6.c2
-rw-r--r--net/sctp/protocol.c2
-rw-r--r--net/sctp/socket.c51
-rw-r--r--net/smc/smc_pnet.c71
-rw-r--r--net/sunrpc/Kconfig2
-rw-r--r--net/tls/tls_sw.c9
-rw-r--r--net/wireless/nl80211.c3
-rw-r--r--net/wireless/reg.c3
-rwxr-xr-xscripts/checkpatch.pl2
-rw-r--r--security/selinux/hooks.c20
-rw-r--r--sound/core/timer.c4
-rw-r--r--sound/pci/hda/hda_local.h6
-rw-r--r--tools/lib/bpf/libbpf.c2
-rw-r--r--tools/testing/radix-tree/idr-test.c7
-rw-r--r--tools/testing/selftests/bpf/config2
-rw-r--r--tools/testing/selftests/bpf/test_verifier.c5
-rw-r--r--tools/testing/selftests/net/config5
-rw-r--r--tools/testing/selftests/net/reuseport_bpf_numa.c4
-rw-r--r--tools/testing/selftests/seccomp/seccomp_bpf.c22
288 files changed, 3877 insertions, 1459 deletions
diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
index 025b7cf3768d..bd4975e132d3 100644
--- a/Documentation/ABI/testing/sysfs-devices-system-cpu
+++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
@@ -478,6 +478,7 @@ What: /sys/devices/system/cpu/vulnerabilities
478 /sys/devices/system/cpu/vulnerabilities/meltdown 478 /sys/devices/system/cpu/vulnerabilities/meltdown
479 /sys/devices/system/cpu/vulnerabilities/spectre_v1 479 /sys/devices/system/cpu/vulnerabilities/spectre_v1
480 /sys/devices/system/cpu/vulnerabilities/spectre_v2 480 /sys/devices/system/cpu/vulnerabilities/spectre_v2
481 /sys/devices/system/cpu/vulnerabilities/spec_store_bypass
481Date: January 2018 482Date: January 2018
482Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org> 483Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org>
483Description: Information about CPU vulnerabilities 484Description: Information about CPU vulnerabilities
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 11fc28ecdb6d..f2040d46f095 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -2680,6 +2680,9 @@
2680 allow data leaks with this option, which is equivalent 2680 allow data leaks with this option, which is equivalent
2681 to spectre_v2=off. 2681 to spectre_v2=off.
2682 2682
2683 nospec_store_bypass_disable
2684 [HW] Disable all mitigations for the Speculative Store Bypass vulnerability
2685
2683 noxsave [BUGS=X86] Disables x86 extended register state save 2686 noxsave [BUGS=X86] Disables x86 extended register state save
2684 and restore using xsave. The kernel will fallback to 2687 and restore using xsave. The kernel will fallback to
2685 enabling legacy floating-point and sse state. 2688 enabling legacy floating-point and sse state.
@@ -4025,6 +4028,48 @@
4025 Not specifying this option is equivalent to 4028 Not specifying this option is equivalent to
4026 spectre_v2=auto. 4029 spectre_v2=auto.
4027 4030
4031 spec_store_bypass_disable=
4032 [HW] Control Speculative Store Bypass (SSB) Disable mitigation
4033 (Speculative Store Bypass vulnerability)
4034
4035 Certain CPUs are vulnerable to an exploit against a
4036 a common industry wide performance optimization known
4037 as "Speculative Store Bypass" in which recent stores
4038 to the same memory location may not be observed by
4039 later loads during speculative execution. The idea
4040 is that such stores are unlikely and that they can
4041 be detected prior to instruction retirement at the
4042 end of a particular speculation execution window.
4043
4044 In vulnerable processors, the speculatively forwarded
4045 store can be used in a cache side channel attack, for
4046 example to read memory to which the attacker does not
4047 directly have access (e.g. inside sandboxed code).
4048
4049 This parameter controls whether the Speculative Store
4050 Bypass optimization is used.
4051
4052 on - Unconditionally disable Speculative Store Bypass
4053 off - Unconditionally enable Speculative Store Bypass
4054 auto - Kernel detects whether the CPU model contains an
4055 implementation of Speculative Store Bypass and
4056 picks the most appropriate mitigation. If the
4057 CPU is not vulnerable, "off" is selected. If the
4058 CPU is vulnerable the default mitigation is
4059 architecture and Kconfig dependent. See below.
4060 prctl - Control Speculative Store Bypass per thread
4061 via prctl. Speculative Store Bypass is enabled
4062 for a process by default. The state of the control
4063 is inherited on fork.
4064 seccomp - Same as "prctl" above, but all seccomp threads
4065 will disable SSB unless they explicitly opt out.
4066
4067 Not specifying this option is equivalent to
4068 spec_store_bypass_disable=auto.
4069
4070 Default mitigations:
4071 X86: If CONFIG_SECCOMP=y "seccomp", otherwise "prctl"
4072
4028 spia_io_base= [HW,MTD] 4073 spia_io_base= [HW,MTD]
4029 spia_fio_base= 4074 spia_fio_base=
4030 spia_pedr= 4075 spia_pedr=
diff --git a/Documentation/devicetree/bindings/net/micrel-ksz90x1.txt b/Documentation/devicetree/bindings/net/micrel-ksz90x1.txt
index 42a248301615..e22d8cfea687 100644
--- a/Documentation/devicetree/bindings/net/micrel-ksz90x1.txt
+++ b/Documentation/devicetree/bindings/net/micrel-ksz90x1.txt
@@ -57,6 +57,13 @@ KSZ9031:
57 - txd2-skew-ps : Skew control of TX data 2 pad 57 - txd2-skew-ps : Skew control of TX data 2 pad
58 - txd3-skew-ps : Skew control of TX data 3 pad 58 - txd3-skew-ps : Skew control of TX data 3 pad
59 59
60 - micrel,force-master:
61 Boolean, force phy to master mode. Only set this option if the phy
62 reference clock provided at CLK125_NDO pin is used as MAC reference
63 clock because the clock jitter in slave mode is to high (errata#2).
64 Attention: The link partner must be configurable as slave otherwise
65 no link will be established.
66
60Examples: 67Examples:
61 68
62 mdio { 69 mdio {
diff --git a/Documentation/networking/ppp_generic.txt b/Documentation/networking/ppp_generic.txt
index 091d20273dcb..61daf4b39600 100644
--- a/Documentation/networking/ppp_generic.txt
+++ b/Documentation/networking/ppp_generic.txt
@@ -300,12 +300,6 @@ unattached instance are:
300The ioctl calls available on an instance of /dev/ppp attached to a 300The ioctl calls available on an instance of /dev/ppp attached to a
301channel are: 301channel are:
302 302
303* PPPIOCDETACH detaches the instance from the channel. This ioctl is
304 deprecated since the same effect can be achieved by closing the
305 instance. In order to prevent possible races this ioctl will fail
306 with an EINVAL error if more than one file descriptor refers to this
307 instance (i.e. as a result of dup(), dup2() or fork()).
308
309* PPPIOCCONNECT connects this channel to a PPP interface. The 303* PPPIOCCONNECT connects this channel to a PPP interface. The
310 argument should point to an int containing the interface unit 304 argument should point to an int containing the interface unit
311 number. It will return an EINVAL error if the channel is already 305 number. It will return an EINVAL error if the channel is already
diff --git a/Documentation/userspace-api/index.rst b/Documentation/userspace-api/index.rst
index 7b2eb1b7d4ca..a3233da7fa88 100644
--- a/Documentation/userspace-api/index.rst
+++ b/Documentation/userspace-api/index.rst
@@ -19,6 +19,7 @@ place where this information is gathered.
19 no_new_privs 19 no_new_privs
20 seccomp_filter 20 seccomp_filter
21 unshare 21 unshare
22 spec_ctrl
22 23
23.. only:: subproject and html 24.. only:: subproject and html
24 25
diff --git a/Documentation/userspace-api/spec_ctrl.rst b/Documentation/userspace-api/spec_ctrl.rst
new file mode 100644
index 000000000000..32f3d55c54b7
--- /dev/null
+++ b/Documentation/userspace-api/spec_ctrl.rst
@@ -0,0 +1,94 @@
1===================
2Speculation Control
3===================
4
5Quite some CPUs have speculation-related misfeatures which are in
6fact vulnerabilities causing data leaks in various forms even across
7privilege domains.
8
9The kernel provides mitigation for such vulnerabilities in various
10forms. Some of these mitigations are compile-time configurable and some
11can be supplied on the kernel command line.
12
13There is also a class of mitigations which are very expensive, but they can
14be restricted to a certain set of processes or tasks in controlled
15environments. The mechanism to control these mitigations is via
16:manpage:`prctl(2)`.
17
18There are two prctl options which are related to this:
19
20 * PR_GET_SPECULATION_CTRL
21
22 * PR_SET_SPECULATION_CTRL
23
24PR_GET_SPECULATION_CTRL
25-----------------------
26
27PR_GET_SPECULATION_CTRL returns the state of the speculation misfeature
28which is selected with arg2 of prctl(2). The return value uses bits 0-3 with
29the following meaning:
30
31==== ===================== ===================================================
32Bit Define Description
33==== ===================== ===================================================
340 PR_SPEC_PRCTL Mitigation can be controlled per task by
35 PR_SET_SPECULATION_CTRL.
361 PR_SPEC_ENABLE The speculation feature is enabled, mitigation is
37 disabled.
382 PR_SPEC_DISABLE The speculation feature is disabled, mitigation is
39 enabled.
403 PR_SPEC_FORCE_DISABLE Same as PR_SPEC_DISABLE, but cannot be undone. A
41 subsequent prctl(..., PR_SPEC_ENABLE) will fail.
42==== ===================== ===================================================
43
44If all bits are 0 the CPU is not affected by the speculation misfeature.
45
46If PR_SPEC_PRCTL is set, then the per-task control of the mitigation is
47available. If not set, prctl(PR_SET_SPECULATION_CTRL) for the speculation
48misfeature will fail.
49
50PR_SET_SPECULATION_CTRL
51-----------------------
52
53PR_SET_SPECULATION_CTRL allows to control the speculation misfeature, which
54is selected by arg2 of :manpage:`prctl(2)` per task. arg3 is used to hand
55in the control value, i.e. either PR_SPEC_ENABLE or PR_SPEC_DISABLE or
56PR_SPEC_FORCE_DISABLE.
57
58Common error codes
59------------------
60======= =================================================================
61Value Meaning
62======= =================================================================
63EINVAL The prctl is not implemented by the architecture or unused
64 prctl(2) arguments are not 0.
65
66ENODEV arg2 is selecting a not supported speculation misfeature.
67======= =================================================================
68
69PR_SET_SPECULATION_CTRL error codes
70-----------------------------------
71======= =================================================================
72Value Meaning
73======= =================================================================
740 Success
75
76ERANGE arg3 is incorrect, i.e. it's neither PR_SPEC_ENABLE nor
77 PR_SPEC_DISABLE nor PR_SPEC_FORCE_DISABLE.
78
79ENXIO Control of the selected speculation misfeature is not possible.
80 See PR_GET_SPECULATION_CTRL.
81
82EPERM Speculation was disabled with PR_SPEC_FORCE_DISABLE and caller
83 tried to enable it again.
84======= =================================================================
85
86Speculation misfeature controls
87-------------------------------
88- PR_SPEC_STORE_BYPASS: Speculative Store Bypass
89
90 Invocations:
91 * prctl(PR_GET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, 0, 0, 0);
92 * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_ENABLE, 0, 0);
93 * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_DISABLE, 0, 0);
94 * prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_FORCE_DISABLE, 0, 0);
diff --git a/MAINTAINERS b/MAINTAINERS
index 078fd80f664f..ca4afd68530c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2332,7 +2332,7 @@ F: drivers/gpio/gpio-ath79.c
2332F: Documentation/devicetree/bindings/gpio/gpio-ath79.txt 2332F: Documentation/devicetree/bindings/gpio/gpio-ath79.txt
2333 2333
2334ATHEROS ATH GENERIC UTILITIES 2334ATHEROS ATH GENERIC UTILITIES
2335M: "Luis R. Rodriguez" <mcgrof@do-not-panic.com> 2335M: Kalle Valo <kvalo@codeaurora.org>
2336L: linux-wireless@vger.kernel.org 2336L: linux-wireless@vger.kernel.org
2337S: Supported 2337S: Supported
2338F: drivers/net/wireless/ath/* 2338F: drivers/net/wireless/ath/*
@@ -2347,7 +2347,7 @@ S: Maintained
2347F: drivers/net/wireless/ath/ath5k/ 2347F: drivers/net/wireless/ath/ath5k/
2348 2348
2349ATHEROS ATH6KL WIRELESS DRIVER 2349ATHEROS ATH6KL WIRELESS DRIVER
2350M: Kalle Valo <kvalo@qca.qualcomm.com> 2350M: Kalle Valo <kvalo@codeaurora.org>
2351L: linux-wireless@vger.kernel.org 2351L: linux-wireless@vger.kernel.org
2352W: http://wireless.kernel.org/en/users/Drivers/ath6kl 2352W: http://wireless.kernel.org/en/users/Drivers/ath6kl
2353T: git git://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git 2353T: git git://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git
@@ -5388,7 +5388,6 @@ S: Maintained
5388F: drivers/iommu/exynos-iommu.c 5388F: drivers/iommu/exynos-iommu.c
5389 5389
5390EZchip NPS platform support 5390EZchip NPS platform support
5391M: Elad Kanfi <eladkan@mellanox.com>
5392M: Vineet Gupta <vgupta@synopsys.com> 5391M: Vineet Gupta <vgupta@synopsys.com>
5393S: Supported 5392S: Supported
5394F: arch/arc/plat-eznps 5393F: arch/arc/plat-eznps
@@ -6504,9 +6503,15 @@ F: Documentation/networking/hinic.txt
6504F: drivers/net/ethernet/huawei/hinic/ 6503F: drivers/net/ethernet/huawei/hinic/
6505 6504
6506HUGETLB FILESYSTEM 6505HUGETLB FILESYSTEM
6507M: Nadia Yvette Chambers <nyc@holomorphy.com> 6506M: Mike Kravetz <mike.kravetz@oracle.com>
6507L: linux-mm@kvack.org
6508S: Maintained 6508S: Maintained
6509F: fs/hugetlbfs/ 6509F: fs/hugetlbfs/
6510F: mm/hugetlb.c
6511F: include/linux/hugetlb.h
6512F: Documentation/admin-guide/mm/hugetlbpage.rst
6513F: Documentation/vm/hugetlbfs_reserv.rst
6514F: Documentation/ABI/testing/sysfs-kernel-mm-hugepages
6510 6515
6511HVA ST MEDIA DRIVER 6516HVA ST MEDIA DRIVER
6512M: Jean-Christophe Trotin <jean-christophe.trotin@st.com> 6517M: Jean-Christophe Trotin <jean-christophe.trotin@st.com>
@@ -9021,7 +9026,6 @@ Q: http://patchwork.ozlabs.org/project/netdev/list/
9021F: drivers/net/ethernet/mellanox/mlx5/core/en_* 9026F: drivers/net/ethernet/mellanox/mlx5/core/en_*
9022 9027
9023MELLANOX ETHERNET INNOVA DRIVER 9028MELLANOX ETHERNET INNOVA DRIVER
9024M: Ilan Tayari <ilant@mellanox.com>
9025R: Boris Pismenny <borisp@mellanox.com> 9029R: Boris Pismenny <borisp@mellanox.com>
9026L: netdev@vger.kernel.org 9030L: netdev@vger.kernel.org
9027S: Supported 9031S: Supported
@@ -9031,7 +9035,6 @@ F: drivers/net/ethernet/mellanox/mlx5/core/fpga/*
9031F: include/linux/mlx5/mlx5_ifc_fpga.h 9035F: include/linux/mlx5/mlx5_ifc_fpga.h
9032 9036
9033MELLANOX ETHERNET INNOVA IPSEC DRIVER 9037MELLANOX ETHERNET INNOVA IPSEC DRIVER
9034M: Ilan Tayari <ilant@mellanox.com>
9035R: Boris Pismenny <borisp@mellanox.com> 9038R: Boris Pismenny <borisp@mellanox.com>
9036L: netdev@vger.kernel.org 9039L: netdev@vger.kernel.org
9037S: Supported 9040S: Supported
@@ -9087,7 +9090,6 @@ F: include/uapi/rdma/mlx4-abi.h
9087 9090
9088MELLANOX MLX5 core VPI driver 9091MELLANOX MLX5 core VPI driver
9089M: Saeed Mahameed <saeedm@mellanox.com> 9092M: Saeed Mahameed <saeedm@mellanox.com>
9090M: Matan Barak <matanb@mellanox.com>
9091M: Leon Romanovsky <leonro@mellanox.com> 9093M: Leon Romanovsky <leonro@mellanox.com>
9092L: netdev@vger.kernel.org 9094L: netdev@vger.kernel.org
9093L: linux-rdma@vger.kernel.org 9095L: linux-rdma@vger.kernel.org
@@ -9098,7 +9100,6 @@ F: drivers/net/ethernet/mellanox/mlx5/core/
9098F: include/linux/mlx5/ 9100F: include/linux/mlx5/
9099 9101
9100MELLANOX MLX5 IB driver 9102MELLANOX MLX5 IB driver
9101M: Matan Barak <matanb@mellanox.com>
9102M: Leon Romanovsky <leonro@mellanox.com> 9103M: Leon Romanovsky <leonro@mellanox.com>
9103L: linux-rdma@vger.kernel.org 9104L: linux-rdma@vger.kernel.org
9104W: http://www.mellanox.com 9105W: http://www.mellanox.com
@@ -9832,7 +9833,6 @@ F: net/netfilter/xt_CONNSECMARK.c
9832F: net/netfilter/xt_SECMARK.c 9833F: net/netfilter/xt_SECMARK.c
9833 9834
9834NETWORKING [TLS] 9835NETWORKING [TLS]
9835M: Ilya Lesokhin <ilyal@mellanox.com>
9836M: Aviad Yehezkel <aviadye@mellanox.com> 9836M: Aviad Yehezkel <aviadye@mellanox.com>
9837M: Dave Watson <davejwatson@fb.com> 9837M: Dave Watson <davejwatson@fb.com>
9838L: netdev@vger.kernel.org 9838L: netdev@vger.kernel.org
@@ -11632,7 +11632,7 @@ S: Maintained
11632F: drivers/media/tuners/qt1010* 11632F: drivers/media/tuners/qt1010*
11633 11633
11634QUALCOMM ATHEROS ATH10K WIRELESS DRIVER 11634QUALCOMM ATHEROS ATH10K WIRELESS DRIVER
11635M: Kalle Valo <kvalo@qca.qualcomm.com> 11635M: Kalle Valo <kvalo@codeaurora.org>
11636L: ath10k@lists.infradead.org 11636L: ath10k@lists.infradead.org
11637W: http://wireless.kernel.org/en/users/Drivers/ath10k 11637W: http://wireless.kernel.org/en/users/Drivers/ath10k
11638T: git git://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git 11638T: git git://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git
@@ -11683,7 +11683,7 @@ S: Maintained
11683F: drivers/media/platform/qcom/venus/ 11683F: drivers/media/platform/qcom/venus/
11684 11684
11685QUALCOMM WCN36XX WIRELESS DRIVER 11685QUALCOMM WCN36XX WIRELESS DRIVER
11686M: Eugene Krasnikov <k.eugene.e@gmail.com> 11686M: Kalle Valo <kvalo@codeaurora.org>
11687L: wcn36xx@lists.infradead.org 11687L: wcn36xx@lists.infradead.org
11688W: http://wireless.kernel.org/en/users/Drivers/wcn36xx 11688W: http://wireless.kernel.org/en/users/Drivers/wcn36xx
11689T: git git://github.com/KrasnikovEugene/wcn36xx.git 11689T: git git://github.com/KrasnikovEugene/wcn36xx.git
diff --git a/Makefile b/Makefile
index ec6f45928fd4..56ba070dfa09 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
2VERSION = 4 2VERSION = 4
3PATCHLEVEL = 17 3PATCHLEVEL = 17
4SUBLEVEL = 0 4SUBLEVEL = 0
5EXTRAVERSION = -rc6 5EXTRAVERSION = -rc7
6NAME = Merciless Moray 6NAME = Merciless Moray
7 7
8# *DOCUMENTATION* 8# *DOCUMENTATION*
@@ -500,6 +500,9 @@ RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk
500RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG))) 500RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
501export RETPOLINE_CFLAGS 501export RETPOLINE_CFLAGS
502 502
503KBUILD_CFLAGS += $(call cc-option,-fno-PIE)
504KBUILD_AFLAGS += $(call cc-option,-fno-PIE)
505
503# check for 'asm goto' 506# check for 'asm goto'
504ifeq ($(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y) 507ifeq ($(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)
505 CC_HAVE_ASM_GOTO := 1 508 CC_HAVE_ASM_GOTO := 1
@@ -621,9 +624,9 @@ endif # $(dot-config)
621# Defaults to vmlinux, but the arch makefile usually adds further targets 624# Defaults to vmlinux, but the arch makefile usually adds further targets
622all: vmlinux 625all: vmlinux
623 626
624KBUILD_CFLAGS += $(call cc-option,-fno-PIE) 627CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \
625KBUILD_AFLAGS += $(call cc-option,-fno-PIE) 628 $(call cc-option,-fno-tree-loop-im) \
626CFLAGS_GCOV := -fprofile-arcs -ftest-coverage -fno-tree-loop-im $(call cc-disable-warning,maybe-uninitialized,) 629 $(call cc-disable-warning,maybe-uninitialized,)
627export CFLAGS_GCOV CFLAGS_KCOV 630export CFLAGS_GCOV CFLAGS_KCOV
628 631
629# The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default 632# The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default
diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
index b2022885ced8..f19dc31288c8 100644
--- a/arch/alpha/Kconfig
+++ b/arch/alpha/Kconfig
@@ -211,6 +211,7 @@ config ALPHA_EIGER
211config ALPHA_JENSEN 211config ALPHA_JENSEN
212 bool "Jensen" 212 bool "Jensen"
213 depends on BROKEN 213 depends on BROKEN
214 select DMA_DIRECT_OPS
214 help 215 help
215 DEC PC 150 AXP (aka Jensen): This is a very old Digital system - one 216 DEC PC 150 AXP (aka Jensen): This is a very old Digital system - one
216 of the first-generation Alpha systems. A number of these systems 217 of the first-generation Alpha systems. A number of these systems
diff --git a/arch/alpha/include/asm/dma-mapping.h b/arch/alpha/include/asm/dma-mapping.h
index b78f61f20796..8beeafd4f68e 100644
--- a/arch/alpha/include/asm/dma-mapping.h
+++ b/arch/alpha/include/asm/dma-mapping.h
@@ -2,11 +2,15 @@
2#ifndef _ALPHA_DMA_MAPPING_H 2#ifndef _ALPHA_DMA_MAPPING_H
3#define _ALPHA_DMA_MAPPING_H 3#define _ALPHA_DMA_MAPPING_H
4 4
5extern const struct dma_map_ops *dma_ops; 5extern const struct dma_map_ops alpha_pci_ops;
6 6
7static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) 7static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
8{ 8{
9 return dma_ops; 9#ifdef CONFIG_ALPHA_JENSEN
10 return &dma_direct_ops;
11#else
12 return &alpha_pci_ops;
13#endif
10} 14}
11 15
12#endif /* _ALPHA_DMA_MAPPING_H */ 16#endif /* _ALPHA_DMA_MAPPING_H */
diff --git a/arch/alpha/kernel/io.c b/arch/alpha/kernel/io.c
index 3e3d49c254c5..c025a3e5e357 100644
--- a/arch/alpha/kernel/io.c
+++ b/arch/alpha/kernel/io.c
@@ -37,20 +37,20 @@ unsigned int ioread32(void __iomem *addr)
37 37
38void iowrite8(u8 b, void __iomem *addr) 38void iowrite8(u8 b, void __iomem *addr)
39{ 39{
40 IO_CONCAT(__IO_PREFIX,iowrite8)(b, addr);
41 mb(); 40 mb();
41 IO_CONCAT(__IO_PREFIX,iowrite8)(b, addr);
42} 42}
43 43
44void iowrite16(u16 b, void __iomem *addr) 44void iowrite16(u16 b, void __iomem *addr)
45{ 45{
46 IO_CONCAT(__IO_PREFIX,iowrite16)(b, addr);
47 mb(); 46 mb();
47 IO_CONCAT(__IO_PREFIX,iowrite16)(b, addr);
48} 48}
49 49
50void iowrite32(u32 b, void __iomem *addr) 50void iowrite32(u32 b, void __iomem *addr)
51{ 51{
52 IO_CONCAT(__IO_PREFIX,iowrite32)(b, addr);
53 mb(); 52 mb();
53 IO_CONCAT(__IO_PREFIX,iowrite32)(b, addr);
54} 54}
55 55
56EXPORT_SYMBOL(ioread8); 56EXPORT_SYMBOL(ioread8);
@@ -176,26 +176,26 @@ u64 readq(const volatile void __iomem *addr)
176 176
177void writeb(u8 b, volatile void __iomem *addr) 177void writeb(u8 b, volatile void __iomem *addr)
178{ 178{
179 __raw_writeb(b, addr);
180 mb(); 179 mb();
180 __raw_writeb(b, addr);
181} 181}
182 182
183void writew(u16 b, volatile void __iomem *addr) 183void writew(u16 b, volatile void __iomem *addr)
184{ 184{
185 __raw_writew(b, addr);
186 mb(); 185 mb();
186 __raw_writew(b, addr);
187} 187}
188 188
189void writel(u32 b, volatile void __iomem *addr) 189void writel(u32 b, volatile void __iomem *addr)
190{ 190{
191 __raw_writel(b, addr);
192 mb(); 191 mb();
192 __raw_writel(b, addr);
193} 193}
194 194
195void writeq(u64 b, volatile void __iomem *addr) 195void writeq(u64 b, volatile void __iomem *addr)
196{ 196{
197 __raw_writeq(b, addr);
198 mb(); 197 mb();
198 __raw_writeq(b, addr);
199} 199}
200 200
201EXPORT_SYMBOL(readb); 201EXPORT_SYMBOL(readb);
diff --git a/arch/alpha/kernel/pci-noop.c b/arch/alpha/kernel/pci-noop.c
index b6ebb65127a8..c7c5879869d3 100644
--- a/arch/alpha/kernel/pci-noop.c
+++ b/arch/alpha/kernel/pci-noop.c
@@ -102,36 +102,3 @@ SYSCALL_DEFINE5(pciconfig_write, unsigned long, bus, unsigned long, dfn,
102 else 102 else
103 return -ENODEV; 103 return -ENODEV;
104} 104}
105
106static void *alpha_noop_alloc_coherent(struct device *dev, size_t size,
107 dma_addr_t *dma_handle, gfp_t gfp,
108 unsigned long attrs)
109{
110 void *ret;
111
112 if (!dev || *dev->dma_mask >= 0xffffffffUL)
113 gfp &= ~GFP_DMA;
114 ret = (void *)__get_free_pages(gfp, get_order(size));
115 if (ret) {
116 memset(ret, 0, size);
117 *dma_handle = virt_to_phys(ret);
118 }
119 return ret;
120}
121
122static int alpha_noop_supported(struct device *dev, u64 mask)
123{
124 return mask < 0x00ffffffUL ? 0 : 1;
125}
126
127const struct dma_map_ops alpha_noop_ops = {
128 .alloc = alpha_noop_alloc_coherent,
129 .free = dma_noop_free_coherent,
130 .map_page = dma_noop_map_page,
131 .map_sg = dma_noop_map_sg,
132 .mapping_error = dma_noop_mapping_error,
133 .dma_supported = alpha_noop_supported,
134};
135
136const struct dma_map_ops *dma_ops = &alpha_noop_ops;
137EXPORT_SYMBOL(dma_ops);
diff --git a/arch/alpha/kernel/pci_iommu.c b/arch/alpha/kernel/pci_iommu.c
index 83b34b9188ea..6923b0d9c1e1 100644
--- a/arch/alpha/kernel/pci_iommu.c
+++ b/arch/alpha/kernel/pci_iommu.c
@@ -950,6 +950,4 @@ const struct dma_map_ops alpha_pci_ops = {
950 .mapping_error = alpha_pci_mapping_error, 950 .mapping_error = alpha_pci_mapping_error,
951 .dma_supported = alpha_pci_supported, 951 .dma_supported = alpha_pci_supported,
952}; 952};
953 953EXPORT_SYMBOL(alpha_pci_ops);
954const struct dma_map_ops *dma_ops = &alpha_pci_ops;
955EXPORT_SYMBOL(dma_ops);
diff --git a/arch/arm/boot/dts/sun4i-a10.dtsi b/arch/arm/boot/dts/sun4i-a10.dtsi
index 77e8436beed4..3a1c6b45c9a1 100644
--- a/arch/arm/boot/dts/sun4i-a10.dtsi
+++ b/arch/arm/boot/dts/sun4i-a10.dtsi
@@ -76,7 +76,7 @@
76 allwinner,pipeline = "de_fe0-de_be0-lcd0-hdmi"; 76 allwinner,pipeline = "de_fe0-de_be0-lcd0-hdmi";
77 clocks = <&ccu CLK_AHB_LCD0>, <&ccu CLK_AHB_HDMI0>, 77 clocks = <&ccu CLK_AHB_LCD0>, <&ccu CLK_AHB_HDMI0>,
78 <&ccu CLK_AHB_DE_BE0>, <&ccu CLK_AHB_DE_FE0>, 78 <&ccu CLK_AHB_DE_BE0>, <&ccu CLK_AHB_DE_FE0>,
79 <&ccu CLK_DE_BE0>, <&ccu CLK_AHB_DE_FE0>, 79 <&ccu CLK_DE_BE0>, <&ccu CLK_DE_FE0>,
80 <&ccu CLK_TCON0_CH1>, <&ccu CLK_HDMI>, 80 <&ccu CLK_TCON0_CH1>, <&ccu CLK_HDMI>,
81 <&ccu CLK_DRAM_DE_FE0>, <&ccu CLK_DRAM_DE_BE0>; 81 <&ccu CLK_DRAM_DE_FE0>, <&ccu CLK_DRAM_DE_BE0>;
82 status = "disabled"; 82 status = "disabled";
@@ -88,7 +88,7 @@
88 allwinner,pipeline = "de_fe0-de_be0-lcd0"; 88 allwinner,pipeline = "de_fe0-de_be0-lcd0";
89 clocks = <&ccu CLK_AHB_LCD0>, <&ccu CLK_AHB_DE_BE0>, 89 clocks = <&ccu CLK_AHB_LCD0>, <&ccu CLK_AHB_DE_BE0>,
90 <&ccu CLK_AHB_DE_FE0>, <&ccu CLK_DE_BE0>, 90 <&ccu CLK_AHB_DE_FE0>, <&ccu CLK_DE_BE0>,
91 <&ccu CLK_AHB_DE_FE0>, <&ccu CLK_TCON0_CH0>, 91 <&ccu CLK_DE_FE0>, <&ccu CLK_TCON0_CH0>,
92 <&ccu CLK_DRAM_DE_FE0>, <&ccu CLK_DRAM_DE_BE0>; 92 <&ccu CLK_DRAM_DE_FE0>, <&ccu CLK_DRAM_DE_BE0>;
93 status = "disabled"; 93 status = "disabled";
94 }; 94 };
@@ -99,7 +99,7 @@
99 allwinner,pipeline = "de_fe0-de_be0-lcd0-tve0"; 99 allwinner,pipeline = "de_fe0-de_be0-lcd0-tve0";
100 clocks = <&ccu CLK_AHB_TVE0>, <&ccu CLK_AHB_LCD0>, 100 clocks = <&ccu CLK_AHB_TVE0>, <&ccu CLK_AHB_LCD0>,
101 <&ccu CLK_AHB_DE_BE0>, <&ccu CLK_AHB_DE_FE0>, 101 <&ccu CLK_AHB_DE_BE0>, <&ccu CLK_AHB_DE_FE0>,
102 <&ccu CLK_DE_BE0>, <&ccu CLK_AHB_DE_FE0>, 102 <&ccu CLK_DE_BE0>, <&ccu CLK_DE_FE0>,
103 <&ccu CLK_TCON0_CH1>, <&ccu CLK_DRAM_TVE0>, 103 <&ccu CLK_TCON0_CH1>, <&ccu CLK_DRAM_TVE0>,
104 <&ccu CLK_DRAM_DE_FE0>, <&ccu CLK_DRAM_DE_BE0>; 104 <&ccu CLK_DRAM_DE_FE0>, <&ccu CLK_DRAM_DE_BE0>;
105 status = "disabled"; 105 status = "disabled";
diff --git a/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts b/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
index 3328fe583c9b..232f124ce62c 100644
--- a/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
+++ b/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
@@ -117,6 +117,7 @@
117 phy-handle = <&int_mii_phy>; 117 phy-handle = <&int_mii_phy>;
118 phy-mode = "mii"; 118 phy-mode = "mii";
119 allwinner,leds-active-low; 119 allwinner,leds-active-low;
120 status = "okay";
120}; 121};
121 122
122&hdmi { 123&hdmi {
diff --git a/arch/arm/boot/dts/sun8i-v3s-licheepi-zero-dock.dts b/arch/arm/boot/dts/sun8i-v3s-licheepi-zero-dock.dts
index d1311098ea45..ad173605b1b8 100644
--- a/arch/arm/boot/dts/sun8i-v3s-licheepi-zero-dock.dts
+++ b/arch/arm/boot/dts/sun8i-v3s-licheepi-zero-dock.dts
@@ -51,7 +51,7 @@
51 51
52 leds { 52 leds {
53 /* The LEDs use PG0~2 pins, which conflict with MMC1 */ 53 /* The LEDs use PG0~2 pins, which conflict with MMC1 */
54 status = "disbaled"; 54 status = "disabled";
55 }; 55 };
56}; 56};
57 57
diff --git a/arch/arm/mach-ep93xx/core.c b/arch/arm/mach-ep93xx/core.c
index e70feec6fad5..0581ffbedddd 100644
--- a/arch/arm/mach-ep93xx/core.c
+++ b/arch/arm/mach-ep93xx/core.c
@@ -323,7 +323,7 @@ void __init ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr)
323 323
324/* All EP93xx devices use the same two GPIO pins for I2C bit-banging */ 324/* All EP93xx devices use the same two GPIO pins for I2C bit-banging */
325static struct gpiod_lookup_table ep93xx_i2c_gpiod_table = { 325static struct gpiod_lookup_table ep93xx_i2c_gpiod_table = {
326 .dev_id = "i2c-gpio", 326 .dev_id = "i2c-gpio.0",
327 .table = { 327 .table = {
328 /* Use local offsets on gpiochip/port "G" */ 328 /* Use local offsets on gpiochip/port "G" */
329 GPIO_LOOKUP_IDX("G", 1, NULL, 0, 329 GPIO_LOOKUP_IDX("G", 1, NULL, 0,
diff --git a/arch/arm/mach-ixp4xx/avila-setup.c b/arch/arm/mach-ixp4xx/avila-setup.c
index 77def6169f50..44cbbce6bda6 100644
--- a/arch/arm/mach-ixp4xx/avila-setup.c
+++ b/arch/arm/mach-ixp4xx/avila-setup.c
@@ -51,7 +51,7 @@ static struct platform_device avila_flash = {
51}; 51};
52 52
53static struct gpiod_lookup_table avila_i2c_gpiod_table = { 53static struct gpiod_lookup_table avila_i2c_gpiod_table = {
54 .dev_id = "i2c-gpio", 54 .dev_id = "i2c-gpio.0",
55 .table = { 55 .table = {
56 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", AVILA_SDA_PIN, 56 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", AVILA_SDA_PIN,
57 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 57 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
diff --git a/arch/arm/mach-ixp4xx/dsmg600-setup.c b/arch/arm/mach-ixp4xx/dsmg600-setup.c
index 0f5c99941a7d..397190f3a8da 100644
--- a/arch/arm/mach-ixp4xx/dsmg600-setup.c
+++ b/arch/arm/mach-ixp4xx/dsmg600-setup.c
@@ -70,7 +70,7 @@ static struct platform_device dsmg600_flash = {
70}; 70};
71 71
72static struct gpiod_lookup_table dsmg600_i2c_gpiod_table = { 72static struct gpiod_lookup_table dsmg600_i2c_gpiod_table = {
73 .dev_id = "i2c-gpio", 73 .dev_id = "i2c-gpio.0",
74 .table = { 74 .table = {
75 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", DSMG600_SDA_PIN, 75 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", DSMG600_SDA_PIN,
76 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 76 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
diff --git a/arch/arm/mach-ixp4xx/fsg-setup.c b/arch/arm/mach-ixp4xx/fsg-setup.c
index 033f79b35d51..f0a152e365b1 100644
--- a/arch/arm/mach-ixp4xx/fsg-setup.c
+++ b/arch/arm/mach-ixp4xx/fsg-setup.c
@@ -56,7 +56,7 @@ static struct platform_device fsg_flash = {
56}; 56};
57 57
58static struct gpiod_lookup_table fsg_i2c_gpiod_table = { 58static struct gpiod_lookup_table fsg_i2c_gpiod_table = {
59 .dev_id = "i2c-gpio", 59 .dev_id = "i2c-gpio.0",
60 .table = { 60 .table = {
61 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", FSG_SDA_PIN, 61 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", FSG_SDA_PIN,
62 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 62 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
diff --git a/arch/arm/mach-ixp4xx/ixdp425-setup.c b/arch/arm/mach-ixp4xx/ixdp425-setup.c
index b168e2fbdbeb..3ec829d52cdd 100644
--- a/arch/arm/mach-ixp4xx/ixdp425-setup.c
+++ b/arch/arm/mach-ixp4xx/ixdp425-setup.c
@@ -124,7 +124,7 @@ static struct platform_device ixdp425_flash_nand = {
124#endif /* CONFIG_MTD_NAND_PLATFORM */ 124#endif /* CONFIG_MTD_NAND_PLATFORM */
125 125
126static struct gpiod_lookup_table ixdp425_i2c_gpiod_table = { 126static struct gpiod_lookup_table ixdp425_i2c_gpiod_table = {
127 .dev_id = "i2c-gpio", 127 .dev_id = "i2c-gpio.0",
128 .table = { 128 .table = {
129 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", IXDP425_SDA_PIN, 129 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", IXDP425_SDA_PIN,
130 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 130 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
diff --git a/arch/arm/mach-ixp4xx/nas100d-setup.c b/arch/arm/mach-ixp4xx/nas100d-setup.c
index 76dfff03cb71..4138d6aa4c52 100644
--- a/arch/arm/mach-ixp4xx/nas100d-setup.c
+++ b/arch/arm/mach-ixp4xx/nas100d-setup.c
@@ -102,7 +102,7 @@ static struct platform_device nas100d_leds = {
102}; 102};
103 103
104static struct gpiod_lookup_table nas100d_i2c_gpiod_table = { 104static struct gpiod_lookup_table nas100d_i2c_gpiod_table = {
105 .dev_id = "i2c-gpio", 105 .dev_id = "i2c-gpio.0",
106 .table = { 106 .table = {
107 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NAS100D_SDA_PIN, 107 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NAS100D_SDA_PIN,
108 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 108 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
diff --git a/arch/arm/mach-ixp4xx/nslu2-setup.c b/arch/arm/mach-ixp4xx/nslu2-setup.c
index 91da63a7d7b5..341b263482ef 100644
--- a/arch/arm/mach-ixp4xx/nslu2-setup.c
+++ b/arch/arm/mach-ixp4xx/nslu2-setup.c
@@ -70,7 +70,7 @@ static struct platform_device nslu2_flash = {
70}; 70};
71 71
72static struct gpiod_lookup_table nslu2_i2c_gpiod_table = { 72static struct gpiod_lookup_table nslu2_i2c_gpiod_table = {
73 .dev_id = "i2c-gpio", 73 .dev_id = "i2c-gpio.0",
74 .table = { 74 .table = {
75 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NSLU2_SDA_PIN, 75 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NSLU2_SDA_PIN,
76 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 76 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
diff --git a/arch/arm/mach-pxa/palmz72.c b/arch/arm/mach-pxa/palmz72.c
index 5877e547cecd..0adb1bd6208e 100644
--- a/arch/arm/mach-pxa/palmz72.c
+++ b/arch/arm/mach-pxa/palmz72.c
@@ -322,7 +322,7 @@ static struct soc_camera_link palmz72_iclink = {
322}; 322};
323 323
324static struct gpiod_lookup_table palmz72_i2c_gpiod_table = { 324static struct gpiod_lookup_table palmz72_i2c_gpiod_table = {
325 .dev_id = "i2c-gpio", 325 .dev_id = "i2c-gpio.0",
326 .table = { 326 .table = {
327 GPIO_LOOKUP_IDX("gpio-pxa", 118, NULL, 0, 327 GPIO_LOOKUP_IDX("gpio-pxa", 118, NULL, 0,
328 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 328 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
diff --git a/arch/arm/mach-pxa/viper.c b/arch/arm/mach-pxa/viper.c
index 90d0f277de55..207dcc2e94e7 100644
--- a/arch/arm/mach-pxa/viper.c
+++ b/arch/arm/mach-pxa/viper.c
@@ -460,7 +460,7 @@ static struct platform_device smc91x_device = {
460 460
461/* i2c */ 461/* i2c */
462static struct gpiod_lookup_table viper_i2c_gpiod_table = { 462static struct gpiod_lookup_table viper_i2c_gpiod_table = {
463 .dev_id = "i2c-gpio", 463 .dev_id = "i2c-gpio.1",
464 .table = { 464 .table = {
465 GPIO_LOOKUP_IDX("gpio-pxa", VIPER_RTC_I2C_SDA_GPIO, 465 GPIO_LOOKUP_IDX("gpio-pxa", VIPER_RTC_I2C_SDA_GPIO,
466 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 466 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
@@ -789,7 +789,7 @@ static int __init viper_tpm_setup(char *str)
789__setup("tpm=", viper_tpm_setup); 789__setup("tpm=", viper_tpm_setup);
790 790
791struct gpiod_lookup_table viper_tpm_i2c_gpiod_table = { 791struct gpiod_lookup_table viper_tpm_i2c_gpiod_table = {
792 .dev_id = "i2c-gpio", 792 .dev_id = "i2c-gpio.2",
793 .table = { 793 .table = {
794 GPIO_LOOKUP_IDX("gpio-pxa", VIPER_TPM_I2C_SDA_GPIO, 794 GPIO_LOOKUP_IDX("gpio-pxa", VIPER_TPM_I2C_SDA_GPIO,
795 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 795 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
diff --git a/arch/arm/mach-sa1100/simpad.c b/arch/arm/mach-sa1100/simpad.c
index ace010479eb6..f45aed2519ba 100644
--- a/arch/arm/mach-sa1100/simpad.c
+++ b/arch/arm/mach-sa1100/simpad.c
@@ -327,7 +327,7 @@ static struct platform_device simpad_gpio_leds = {
327 * i2c 327 * i2c
328 */ 328 */
329static struct gpiod_lookup_table simpad_i2c_gpiod_table = { 329static struct gpiod_lookup_table simpad_i2c_gpiod_table = {
330 .dev_id = "i2c-gpio", 330 .dev_id = "i2c-gpio.0",
331 .table = { 331 .table = {
332 GPIO_LOOKUP_IDX("gpio", 21, NULL, 0, 332 GPIO_LOOKUP_IDX("gpio", 21, NULL, 0,
333 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 333 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 8c398fedbbb6..ada8eb206a90 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -466,12 +466,6 @@ void __init dma_contiguous_early_fixup(phys_addr_t base, unsigned long size)
466void __init dma_contiguous_remap(void) 466void __init dma_contiguous_remap(void)
467{ 467{
468 int i; 468 int i;
469
470 if (!dma_mmu_remap_num)
471 return;
472
473 /* call flush_cache_all() since CMA area would be large enough */
474 flush_cache_all();
475 for (i = 0; i < dma_mmu_remap_num; i++) { 469 for (i = 0; i < dma_mmu_remap_num; i++) {
476 phys_addr_t start = dma_mmu_remap[i].base; 470 phys_addr_t start = dma_mmu_remap[i].base;
477 phys_addr_t end = start + dma_mmu_remap[i].size; 471 phys_addr_t end = start + dma_mmu_remap[i].size;
@@ -504,15 +498,7 @@ void __init dma_contiguous_remap(void)
504 flush_tlb_kernel_range(__phys_to_virt(start), 498 flush_tlb_kernel_range(__phys_to_virt(start),
505 __phys_to_virt(end)); 499 __phys_to_virt(end));
506 500
507 /* 501 iotable_init(&map, 1);
508 * All the memory in CMA region will be on ZONE_MOVABLE.
509 * If that zone is considered as highmem, the memory in CMA
510 * region is also considered as highmem even if it's
511 * physical address belong to lowmem. In this case,
512 * re-mapping isn't required.
513 */
514 if (!is_highmem_idx(ZONE_MOVABLE))
515 iotable_init(&map, 1);
516 } 502 }
517} 503}
518 504
diff --git a/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts b/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts
index 724a0d3b7683..edb4ee0b8896 100644
--- a/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts
+++ b/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts
@@ -299,7 +299,6 @@
299 /* GPIO blocks 16 thru 19 do not appear to be routed to pins */ 299 /* GPIO blocks 16 thru 19 do not appear to be routed to pins */
300 300
301 dwmmc_0: dwmmc0@f723d000 { 301 dwmmc_0: dwmmc0@f723d000 {
302 max-frequency = <150000000>;
303 cap-mmc-highspeed; 302 cap-mmc-highspeed;
304 mmc-hs200-1_8v; 303 mmc-hs200-1_8v;
305 non-removable; 304 non-removable;
diff --git a/arch/arm64/include/asm/atomic_lse.h b/arch/arm64/include/asm/atomic_lse.h
index 9ef0797380cb..f9b0b09153e0 100644
--- a/arch/arm64/include/asm/atomic_lse.h
+++ b/arch/arm64/include/asm/atomic_lse.h
@@ -117,7 +117,7 @@ static inline void atomic_and(int i, atomic_t *v)
117 /* LSE atomics */ 117 /* LSE atomics */
118 " mvn %w[i], %w[i]\n" 118 " mvn %w[i], %w[i]\n"
119 " stclr %w[i], %[v]") 119 " stclr %w[i], %[v]")
120 : [i] "+r" (w0), [v] "+Q" (v->counter) 120 : [i] "+&r" (w0), [v] "+Q" (v->counter)
121 : "r" (x1) 121 : "r" (x1)
122 : __LL_SC_CLOBBERS); 122 : __LL_SC_CLOBBERS);
123} 123}
@@ -135,7 +135,7 @@ static inline int atomic_fetch_and##name(int i, atomic_t *v) \
135 /* LSE atomics */ \ 135 /* LSE atomics */ \
136 " mvn %w[i], %w[i]\n" \ 136 " mvn %w[i], %w[i]\n" \
137 " ldclr" #mb " %w[i], %w[i], %[v]") \ 137 " ldclr" #mb " %w[i], %w[i], %[v]") \
138 : [i] "+r" (w0), [v] "+Q" (v->counter) \ 138 : [i] "+&r" (w0), [v] "+Q" (v->counter) \
139 : "r" (x1) \ 139 : "r" (x1) \
140 : __LL_SC_CLOBBERS, ##cl); \ 140 : __LL_SC_CLOBBERS, ##cl); \
141 \ 141 \
@@ -161,7 +161,7 @@ static inline void atomic_sub(int i, atomic_t *v)
161 /* LSE atomics */ 161 /* LSE atomics */
162 " neg %w[i], %w[i]\n" 162 " neg %w[i], %w[i]\n"
163 " stadd %w[i], %[v]") 163 " stadd %w[i], %[v]")
164 : [i] "+r" (w0), [v] "+Q" (v->counter) 164 : [i] "+&r" (w0), [v] "+Q" (v->counter)
165 : "r" (x1) 165 : "r" (x1)
166 : __LL_SC_CLOBBERS); 166 : __LL_SC_CLOBBERS);
167} 167}
@@ -180,7 +180,7 @@ static inline int atomic_sub_return##name(int i, atomic_t *v) \
180 " neg %w[i], %w[i]\n" \ 180 " neg %w[i], %w[i]\n" \
181 " ldadd" #mb " %w[i], w30, %[v]\n" \ 181 " ldadd" #mb " %w[i], w30, %[v]\n" \
182 " add %w[i], %w[i], w30") \ 182 " add %w[i], %w[i], w30") \
183 : [i] "+r" (w0), [v] "+Q" (v->counter) \ 183 : [i] "+&r" (w0), [v] "+Q" (v->counter) \
184 : "r" (x1) \ 184 : "r" (x1) \
185 : __LL_SC_CLOBBERS , ##cl); \ 185 : __LL_SC_CLOBBERS , ##cl); \
186 \ 186 \
@@ -207,7 +207,7 @@ static inline int atomic_fetch_sub##name(int i, atomic_t *v) \
207 /* LSE atomics */ \ 207 /* LSE atomics */ \
208 " neg %w[i], %w[i]\n" \ 208 " neg %w[i], %w[i]\n" \
209 " ldadd" #mb " %w[i], %w[i], %[v]") \ 209 " ldadd" #mb " %w[i], %w[i], %[v]") \
210 : [i] "+r" (w0), [v] "+Q" (v->counter) \ 210 : [i] "+&r" (w0), [v] "+Q" (v->counter) \
211 : "r" (x1) \ 211 : "r" (x1) \
212 : __LL_SC_CLOBBERS, ##cl); \ 212 : __LL_SC_CLOBBERS, ##cl); \
213 \ 213 \
@@ -314,7 +314,7 @@ static inline void atomic64_and(long i, atomic64_t *v)
314 /* LSE atomics */ 314 /* LSE atomics */
315 " mvn %[i], %[i]\n" 315 " mvn %[i], %[i]\n"
316 " stclr %[i], %[v]") 316 " stclr %[i], %[v]")
317 : [i] "+r" (x0), [v] "+Q" (v->counter) 317 : [i] "+&r" (x0), [v] "+Q" (v->counter)
318 : "r" (x1) 318 : "r" (x1)
319 : __LL_SC_CLOBBERS); 319 : __LL_SC_CLOBBERS);
320} 320}
@@ -332,7 +332,7 @@ static inline long atomic64_fetch_and##name(long i, atomic64_t *v) \
332 /* LSE atomics */ \ 332 /* LSE atomics */ \
333 " mvn %[i], %[i]\n" \ 333 " mvn %[i], %[i]\n" \
334 " ldclr" #mb " %[i], %[i], %[v]") \ 334 " ldclr" #mb " %[i], %[i], %[v]") \
335 : [i] "+r" (x0), [v] "+Q" (v->counter) \ 335 : [i] "+&r" (x0), [v] "+Q" (v->counter) \
336 : "r" (x1) \ 336 : "r" (x1) \
337 : __LL_SC_CLOBBERS, ##cl); \ 337 : __LL_SC_CLOBBERS, ##cl); \
338 \ 338 \
@@ -358,7 +358,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
358 /* LSE atomics */ 358 /* LSE atomics */
359 " neg %[i], %[i]\n" 359 " neg %[i], %[i]\n"
360 " stadd %[i], %[v]") 360 " stadd %[i], %[v]")
361 : [i] "+r" (x0), [v] "+Q" (v->counter) 361 : [i] "+&r" (x0), [v] "+Q" (v->counter)
362 : "r" (x1) 362 : "r" (x1)
363 : __LL_SC_CLOBBERS); 363 : __LL_SC_CLOBBERS);
364} 364}
@@ -377,7 +377,7 @@ static inline long atomic64_sub_return##name(long i, atomic64_t *v) \
377 " neg %[i], %[i]\n" \ 377 " neg %[i], %[i]\n" \
378 " ldadd" #mb " %[i], x30, %[v]\n" \ 378 " ldadd" #mb " %[i], x30, %[v]\n" \
379 " add %[i], %[i], x30") \ 379 " add %[i], %[i], x30") \
380 : [i] "+r" (x0), [v] "+Q" (v->counter) \ 380 : [i] "+&r" (x0), [v] "+Q" (v->counter) \
381 : "r" (x1) \ 381 : "r" (x1) \
382 : __LL_SC_CLOBBERS, ##cl); \ 382 : __LL_SC_CLOBBERS, ##cl); \
383 \ 383 \
@@ -404,7 +404,7 @@ static inline long atomic64_fetch_sub##name(long i, atomic64_t *v) \
404 /* LSE atomics */ \ 404 /* LSE atomics */ \
405 " neg %[i], %[i]\n" \ 405 " neg %[i], %[i]\n" \
406 " ldadd" #mb " %[i], %[i], %[v]") \ 406 " ldadd" #mb " %[i], %[i], %[v]") \
407 : [i] "+r" (x0), [v] "+Q" (v->counter) \ 407 : [i] "+&r" (x0), [v] "+Q" (v->counter) \
408 : "r" (x1) \ 408 : "r" (x1) \
409 : __LL_SC_CLOBBERS, ##cl); \ 409 : __LL_SC_CLOBBERS, ##cl); \
410 \ 410 \
@@ -435,7 +435,7 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
435 " sub x30, x30, %[ret]\n" 435 " sub x30, x30, %[ret]\n"
436 " cbnz x30, 1b\n" 436 " cbnz x30, 1b\n"
437 "2:") 437 "2:")
438 : [ret] "+r" (x0), [v] "+Q" (v->counter) 438 : [ret] "+&r" (x0), [v] "+Q" (v->counter)
439 : 439 :
440 : __LL_SC_CLOBBERS, "cc", "memory"); 440 : __LL_SC_CLOBBERS, "cc", "memory");
441 441
@@ -516,7 +516,7 @@ static inline long __cmpxchg_double##name(unsigned long old1, \
516 " eor %[old1], %[old1], %[oldval1]\n" \ 516 " eor %[old1], %[old1], %[oldval1]\n" \
517 " eor %[old2], %[old2], %[oldval2]\n" \ 517 " eor %[old2], %[old2], %[oldval2]\n" \
518 " orr %[old1], %[old1], %[old2]") \ 518 " orr %[old1], %[old1], %[old2]") \
519 : [old1] "+r" (x0), [old2] "+r" (x1), \ 519 : [old1] "+&r" (x0), [old2] "+&r" (x1), \
520 [v] "+Q" (*(unsigned long *)ptr) \ 520 [v] "+Q" (*(unsigned long *)ptr) \
521 : [new1] "r" (x2), [new2] "r" (x3), [ptr] "r" (x4), \ 521 : [new1] "r" (x2), [new2] "r" (x3), [ptr] "r" (x4), \
522 [oldval1] "r" (oldval1), [oldval2] "r" (oldval2) \ 522 [oldval1] "r" (oldval1), [oldval2] "r" (oldval2) \
diff --git a/arch/arm64/kernel/arm64ksyms.c b/arch/arm64/kernel/arm64ksyms.c
index 66be504edb6c..d894a20b70b2 100644
--- a/arch/arm64/kernel/arm64ksyms.c
+++ b/arch/arm64/kernel/arm64ksyms.c
@@ -75,3 +75,11 @@ NOKPROBE_SYMBOL(_mcount);
75 /* arm-smccc */ 75 /* arm-smccc */
76EXPORT_SYMBOL(__arm_smccc_smc); 76EXPORT_SYMBOL(__arm_smccc_smc);
77EXPORT_SYMBOL(__arm_smccc_hvc); 77EXPORT_SYMBOL(__arm_smccc_hvc);
78
79 /* tishift.S */
80extern long long __ashlti3(long long a, int b);
81EXPORT_SYMBOL(__ashlti3);
82extern long long __ashrti3(long long a, int b);
83EXPORT_SYMBOL(__ashrti3);
84extern long long __lshrti3(long long a, int b);
85EXPORT_SYMBOL(__lshrti3);
diff --git a/arch/arm64/lib/tishift.S b/arch/arm64/lib/tishift.S
index d3db9b2cd479..0fdff97794de 100644
--- a/arch/arm64/lib/tishift.S
+++ b/arch/arm64/lib/tishift.S
@@ -1,17 +1,6 @@
1/* 1/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2 * Copyright (C) 2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
3 * 2 *
4 * This program is free software; you can redistribute it and/or modify 3 * Copyright (C) 2017-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */ 4 */
16 5
17#include <linux/linkage.h> 6#include <linux/linkage.h>
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index 4165485e8b6e..2af3dd89bcdb 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -293,6 +293,57 @@ static void __do_kernel_fault(unsigned long addr, unsigned int esr,
293static void __do_user_fault(struct siginfo *info, unsigned int esr) 293static void __do_user_fault(struct siginfo *info, unsigned int esr)
294{ 294{
295 current->thread.fault_address = (unsigned long)info->si_addr; 295 current->thread.fault_address = (unsigned long)info->si_addr;
296
297 /*
298 * If the faulting address is in the kernel, we must sanitize the ESR.
299 * From userspace's point of view, kernel-only mappings don't exist
300 * at all, so we report them as level 0 translation faults.
301 * (This is not quite the way that "no mapping there at all" behaves:
302 * an alignment fault not caused by the memory type would take
303 * precedence over translation fault for a real access to empty
304 * space. Unfortunately we can't easily distinguish "alignment fault
305 * not caused by memory type" from "alignment fault caused by memory
306 * type", so we ignore this wrinkle and just return the translation
307 * fault.)
308 */
309 if (current->thread.fault_address >= TASK_SIZE) {
310 switch (ESR_ELx_EC(esr)) {
311 case ESR_ELx_EC_DABT_LOW:
312 /*
313 * These bits provide only information about the
314 * faulting instruction, which userspace knows already.
315 * We explicitly clear bits which are architecturally
316 * RES0 in case they are given meanings in future.
317 * We always report the ESR as if the fault was taken
318 * to EL1 and so ISV and the bits in ISS[23:14] are
319 * clear. (In fact it always will be a fault to EL1.)
320 */
321 esr &= ESR_ELx_EC_MASK | ESR_ELx_IL |
322 ESR_ELx_CM | ESR_ELx_WNR;
323 esr |= ESR_ELx_FSC_FAULT;
324 break;
325 case ESR_ELx_EC_IABT_LOW:
326 /*
327 * Claim a level 0 translation fault.
328 * All other bits are architecturally RES0 for faults
329 * reported with that DFSC value, so we clear them.
330 */
331 esr &= ESR_ELx_EC_MASK | ESR_ELx_IL;
332 esr |= ESR_ELx_FSC_FAULT;
333 break;
334 default:
335 /*
336 * This should never happen (entry.S only brings us
337 * into this code for insn and data aborts from a lower
338 * exception level). Fail safe by not providing an ESR
339 * context record at all.
340 */
341 WARN(1, "ESR 0x%x is not DABT or IABT from EL0\n", esr);
342 esr = 0;
343 break;
344 }
345 }
346
296 current->thread.fault_code = esr; 347 current->thread.fault_code = esr;
297 arm64_force_sig_info(info, esr_to_fault_info(esr)->name, current); 348 arm64_force_sig_info(info, esr_to_fault_info(esr)->name, current);
298} 349}
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 2dbb2c9f1ec1..493ff75670ff 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -933,13 +933,15 @@ int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot)
933{ 933{
934 pgprot_t sect_prot = __pgprot(PUD_TYPE_SECT | 934 pgprot_t sect_prot = __pgprot(PUD_TYPE_SECT |
935 pgprot_val(mk_sect_prot(prot))); 935 pgprot_val(mk_sect_prot(prot)));
936 pud_t new_pud = pfn_pud(__phys_to_pfn(phys), sect_prot);
936 937
937 /* ioremap_page_range doesn't honour BBM */ 938 /* Only allow permission changes for now */
938 if (pud_present(READ_ONCE(*pudp))) 939 if (!pgattr_change_is_safe(READ_ONCE(pud_val(*pudp)),
940 pud_val(new_pud)))
939 return 0; 941 return 0;
940 942
941 BUG_ON(phys & ~PUD_MASK); 943 BUG_ON(phys & ~PUD_MASK);
942 set_pud(pudp, pfn_pud(__phys_to_pfn(phys), sect_prot)); 944 set_pud(pudp, new_pud);
943 return 1; 945 return 1;
944} 946}
945 947
@@ -947,13 +949,15 @@ int pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot)
947{ 949{
948 pgprot_t sect_prot = __pgprot(PMD_TYPE_SECT | 950 pgprot_t sect_prot = __pgprot(PMD_TYPE_SECT |
949 pgprot_val(mk_sect_prot(prot))); 951 pgprot_val(mk_sect_prot(prot)));
952 pmd_t new_pmd = pfn_pmd(__phys_to_pfn(phys), sect_prot);
950 953
951 /* ioremap_page_range doesn't honour BBM */ 954 /* Only allow permission changes for now */
952 if (pmd_present(READ_ONCE(*pmdp))) 955 if (!pgattr_change_is_safe(READ_ONCE(pmd_val(*pmdp)),
956 pmd_val(new_pmd)))
953 return 0; 957 return 0;
954 958
955 BUG_ON(phys & ~PMD_MASK); 959 BUG_ON(phys & ~PMD_MASK);
956 set_pmd(pmdp, pfn_pmd(__phys_to_pfn(phys), sect_prot)); 960 set_pmd(pmdp, new_pmd);
957 return 1; 961 return 1;
958} 962}
959 963
diff --git a/arch/mips/boot/compressed/uart-16550.c b/arch/mips/boot/compressed/uart-16550.c
index b3043c08f769..aee8d7b8f091 100644
--- a/arch/mips/boot/compressed/uart-16550.c
+++ b/arch/mips/boot/compressed/uart-16550.c
@@ -18,9 +18,9 @@
18#define PORT(offset) (CKSEG1ADDR(AR7_REGS_UART0) + (4 * offset)) 18#define PORT(offset) (CKSEG1ADDR(AR7_REGS_UART0) + (4 * offset))
19#endif 19#endif
20 20
21#if defined(CONFIG_MACH_JZ4740) || defined(CONFIG_MACH_JZ4780) 21#ifdef CONFIG_MACH_INGENIC
22#include <asm/mach-jz4740/base.h> 22#define INGENIC_UART0_BASE_ADDR 0x10030000
23#define PORT(offset) (CKSEG1ADDR(JZ4740_UART0_BASE_ADDR) + (4 * offset)) 23#define PORT(offset) (CKSEG1ADDR(INGENIC_UART0_BASE_ADDR) + (4 * offset))
24#endif 24#endif
25 25
26#ifdef CONFIG_CPU_XLR 26#ifdef CONFIG_CPU_XLR
diff --git a/arch/mips/boot/dts/xilfpga/Makefile b/arch/mips/boot/dts/xilfpga/Makefile
index 9987e0e378c5..69ca00590b8d 100644
--- a/arch/mips/boot/dts/xilfpga/Makefile
+++ b/arch/mips/boot/dts/xilfpga/Makefile
@@ -1,4 +1,2 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2dtb-$(CONFIG_FIT_IMAGE_FDT_XILFPGA) += nexys4ddr.dtb 2dtb-$(CONFIG_FIT_IMAGE_FDT_XILFPGA) += nexys4ddr.dtb
3
4obj-y += $(patsubst %.dtb, %.dtb.o, $(dtb-y))
diff --git a/arch/mips/generic/Platform b/arch/mips/generic/Platform
index b51432dd10b6..0dd0d5d460a5 100644
--- a/arch/mips/generic/Platform
+++ b/arch/mips/generic/Platform
@@ -16,3 +16,4 @@ all-$(CONFIG_MIPS_GENERIC) := vmlinux.gz.itb
16its-y := vmlinux.its.S 16its-y := vmlinux.its.S
17its-$(CONFIG_FIT_IMAGE_FDT_BOSTON) += board-boston.its.S 17its-$(CONFIG_FIT_IMAGE_FDT_BOSTON) += board-boston.its.S
18its-$(CONFIG_FIT_IMAGE_FDT_NI169445) += board-ni169445.its.S 18its-$(CONFIG_FIT_IMAGE_FDT_NI169445) += board-ni169445.its.S
19its-$(CONFIG_FIT_IMAGE_FDT_XILFPGA) += board-xilfpga.its.S
diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
index 0b23b1ad99e6..8d098b9f395c 100644
--- a/arch/mips/kernel/ptrace.c
+++ b/arch/mips/kernel/ptrace.c
@@ -463,7 +463,7 @@ static int fpr_get_msa(struct task_struct *target,
463/* 463/*
464 * Copy the floating-point context to the supplied NT_PRFPREG buffer. 464 * Copy the floating-point context to the supplied NT_PRFPREG buffer.
465 * Choose the appropriate helper for general registers, and then copy 465 * Choose the appropriate helper for general registers, and then copy
466 * the FCSR register separately. 466 * the FCSR and FIR registers separately.
467 */ 467 */
468static int fpr_get(struct task_struct *target, 468static int fpr_get(struct task_struct *target,
469 const struct user_regset *regset, 469 const struct user_regset *regset,
@@ -471,6 +471,7 @@ static int fpr_get(struct task_struct *target,
471 void *kbuf, void __user *ubuf) 471 void *kbuf, void __user *ubuf)
472{ 472{
473 const int fcr31_pos = NUM_FPU_REGS * sizeof(elf_fpreg_t); 473 const int fcr31_pos = NUM_FPU_REGS * sizeof(elf_fpreg_t);
474 const int fir_pos = fcr31_pos + sizeof(u32);
474 int err; 475 int err;
475 476
476 if (sizeof(target->thread.fpu.fpr[0]) == sizeof(elf_fpreg_t)) 477 if (sizeof(target->thread.fpu.fpr[0]) == sizeof(elf_fpreg_t))
@@ -483,6 +484,12 @@ static int fpr_get(struct task_struct *target,
483 err = user_regset_copyout(&pos, &count, &kbuf, &ubuf, 484 err = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
484 &target->thread.fpu.fcr31, 485 &target->thread.fpu.fcr31,
485 fcr31_pos, fcr31_pos + sizeof(u32)); 486 fcr31_pos, fcr31_pos + sizeof(u32));
487 if (err)
488 return err;
489
490 err = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
491 &boot_cpu_data.fpu_id,
492 fir_pos, fir_pos + sizeof(u32));
486 493
487 return err; 494 return err;
488} 495}
@@ -531,7 +538,8 @@ static int fpr_set_msa(struct task_struct *target,
531/* 538/*
532 * Copy the supplied NT_PRFPREG buffer to the floating-point context. 539 * Copy the supplied NT_PRFPREG buffer to the floating-point context.
533 * Choose the appropriate helper for general registers, and then copy 540 * Choose the appropriate helper for general registers, and then copy
534 * the FCSR register separately. 541 * the FCSR register separately. Ignore the incoming FIR register
542 * contents though, as the register is read-only.
535 * 543 *
536 * We optimize for the case where `count % sizeof(elf_fpreg_t) == 0', 544 * We optimize for the case where `count % sizeof(elf_fpreg_t) == 0',
537 * which is supposed to have been guaranteed by the kernel before 545 * which is supposed to have been guaranteed by the kernel before
@@ -545,6 +553,7 @@ static int fpr_set(struct task_struct *target,
545 const void *kbuf, const void __user *ubuf) 553 const void *kbuf, const void __user *ubuf)
546{ 554{
547 const int fcr31_pos = NUM_FPU_REGS * sizeof(elf_fpreg_t); 555 const int fcr31_pos = NUM_FPU_REGS * sizeof(elf_fpreg_t);
556 const int fir_pos = fcr31_pos + sizeof(u32);
548 u32 fcr31; 557 u32 fcr31;
549 int err; 558 int err;
550 559
@@ -572,6 +581,11 @@ static int fpr_set(struct task_struct *target,
572 ptrace_setfcr31(target, fcr31); 581 ptrace_setfcr31(target, fcr31);
573 } 582 }
574 583
584 if (count > 0)
585 err = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
586 fir_pos,
587 fir_pos + sizeof(u32));
588
575 return err; 589 return err;
576} 590}
577 591
@@ -793,7 +807,7 @@ long arch_ptrace(struct task_struct *child, long request,
793 fregs = get_fpu_regs(child); 807 fregs = get_fpu_regs(child);
794 808
795#ifdef CONFIG_32BIT 809#ifdef CONFIG_32BIT
796 if (test_thread_flag(TIF_32BIT_FPREGS)) { 810 if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) {
797 /* 811 /*
798 * The odd registers are actually the high 812 * The odd registers are actually the high
799 * order bits of the values stored in the even 813 * order bits of the values stored in the even
@@ -888,7 +902,7 @@ long arch_ptrace(struct task_struct *child, long request,
888 902
889 init_fp_ctx(child); 903 init_fp_ctx(child);
890#ifdef CONFIG_32BIT 904#ifdef CONFIG_32BIT
891 if (test_thread_flag(TIF_32BIT_FPREGS)) { 905 if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) {
892 /* 906 /*
893 * The odd registers are actually the high 907 * The odd registers are actually the high
894 * order bits of the values stored in the even 908 * order bits of the values stored in the even
diff --git a/arch/mips/kernel/ptrace32.c b/arch/mips/kernel/ptrace32.c
index 2b9260f92ccd..656a137c1fe2 100644
--- a/arch/mips/kernel/ptrace32.c
+++ b/arch/mips/kernel/ptrace32.c
@@ -99,7 +99,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
99 break; 99 break;
100 } 100 }
101 fregs = get_fpu_regs(child); 101 fregs = get_fpu_regs(child);
102 if (test_thread_flag(TIF_32BIT_FPREGS)) { 102 if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) {
103 /* 103 /*
104 * The odd registers are actually the high 104 * The odd registers are actually the high
105 * order bits of the values stored in the even 105 * order bits of the values stored in the even
@@ -212,7 +212,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
212 sizeof(child->thread.fpu)); 212 sizeof(child->thread.fpu));
213 child->thread.fpu.fcr31 = 0; 213 child->thread.fpu.fcr31 = 0;
214 } 214 }
215 if (test_thread_flag(TIF_32BIT_FPREGS)) { 215 if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) {
216 /* 216 /*
217 * The odd registers are actually the high 217 * The odd registers are actually the high
218 * order bits of the values stored in the even 218 * order bits of the values stored in the even
diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
index 2549fdd27ee1..0f725e9cee8f 100644
--- a/arch/mips/kvm/mips.c
+++ b/arch/mips/kvm/mips.c
@@ -45,7 +45,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
45 { "cache", VCPU_STAT(cache_exits), KVM_STAT_VCPU }, 45 { "cache", VCPU_STAT(cache_exits), KVM_STAT_VCPU },
46 { "signal", VCPU_STAT(signal_exits), KVM_STAT_VCPU }, 46 { "signal", VCPU_STAT(signal_exits), KVM_STAT_VCPU },
47 { "interrupt", VCPU_STAT(int_exits), KVM_STAT_VCPU }, 47 { "interrupt", VCPU_STAT(int_exits), KVM_STAT_VCPU },
48 { "cop_unsuable", VCPU_STAT(cop_unusable_exits), KVM_STAT_VCPU }, 48 { "cop_unusable", VCPU_STAT(cop_unusable_exits), KVM_STAT_VCPU },
49 { "tlbmod", VCPU_STAT(tlbmod_exits), KVM_STAT_VCPU }, 49 { "tlbmod", VCPU_STAT(tlbmod_exits), KVM_STAT_VCPU },
50 { "tlbmiss_ld", VCPU_STAT(tlbmiss_ld_exits), KVM_STAT_VCPU }, 50 { "tlbmiss_ld", VCPU_STAT(tlbmiss_ld_exits), KVM_STAT_VCPU },
51 { "tlbmiss_st", VCPU_STAT(tlbmiss_st_exits), KVM_STAT_VCPU }, 51 { "tlbmiss_st", VCPU_STAT(tlbmiss_st_exits), KVM_STAT_VCPU },
diff --git a/arch/mips/mm/c-r4k.c b/arch/mips/mm/c-r4k.c
index 6f534b209971..e12dfa48b478 100644
--- a/arch/mips/mm/c-r4k.c
+++ b/arch/mips/mm/c-r4k.c
@@ -851,9 +851,12 @@ static void r4k_dma_cache_wback_inv(unsigned long addr, unsigned long size)
851 /* 851 /*
852 * Either no secondary cache or the available caches don't have the 852 * Either no secondary cache or the available caches don't have the
853 * subset property so we have to flush the primary caches 853 * subset property so we have to flush the primary caches
854 * explicitly 854 * explicitly.
855 * If we would need IPI to perform an INDEX-type operation, then
856 * we have to use the HIT-type alternative as IPI cannot be used
857 * here due to interrupts possibly being disabled.
855 */ 858 */
856 if (size >= dcache_size) { 859 if (!r4k_op_needs_ipi(R4K_INDEX) && size >= dcache_size) {
857 r4k_blast_dcache(); 860 r4k_blast_dcache();
858 } else { 861 } else {
859 R4600_HIT_CACHEOP_WAR_IMPL; 862 R4600_HIT_CACHEOP_WAR_IMPL;
@@ -890,7 +893,7 @@ static void r4k_dma_cache_inv(unsigned long addr, unsigned long size)
890 return; 893 return;
891 } 894 }
892 895
893 if (size >= dcache_size) { 896 if (!r4k_op_needs_ipi(R4K_INDEX) && size >= dcache_size) {
894 r4k_blast_dcache(); 897 r4k_blast_dcache();
895 } else { 898 } else {
896 R4600_HIT_CACHEOP_WAR_IMPL; 899 R4600_HIT_CACHEOP_WAR_IMPL;
diff --git a/arch/powerpc/include/asm/exception-64s.h b/arch/powerpc/include/asm/exception-64s.h
index 471b2274fbeb..c40b4380951c 100644
--- a/arch/powerpc/include/asm/exception-64s.h
+++ b/arch/powerpc/include/asm/exception-64s.h
@@ -74,6 +74,27 @@
74 */ 74 */
75#define EX_R3 EX_DAR 75#define EX_R3 EX_DAR
76 76
77#define STF_ENTRY_BARRIER_SLOT \
78 STF_ENTRY_BARRIER_FIXUP_SECTION; \
79 nop; \
80 nop; \
81 nop
82
83#define STF_EXIT_BARRIER_SLOT \
84 STF_EXIT_BARRIER_FIXUP_SECTION; \
85 nop; \
86 nop; \
87 nop; \
88 nop; \
89 nop; \
90 nop
91
92/*
93 * r10 must be free to use, r13 must be paca
94 */
95#define INTERRUPT_TO_KERNEL \
96 STF_ENTRY_BARRIER_SLOT
97
77/* 98/*
78 * Macros for annotating the expected destination of (h)rfid 99 * Macros for annotating the expected destination of (h)rfid
79 * 100 *
@@ -90,16 +111,19 @@
90 rfid 111 rfid
91 112
92#define RFI_TO_USER \ 113#define RFI_TO_USER \
114 STF_EXIT_BARRIER_SLOT; \
93 RFI_FLUSH_SLOT; \ 115 RFI_FLUSH_SLOT; \
94 rfid; \ 116 rfid; \
95 b rfi_flush_fallback 117 b rfi_flush_fallback
96 118
97#define RFI_TO_USER_OR_KERNEL \ 119#define RFI_TO_USER_OR_KERNEL \
120 STF_EXIT_BARRIER_SLOT; \
98 RFI_FLUSH_SLOT; \ 121 RFI_FLUSH_SLOT; \
99 rfid; \ 122 rfid; \
100 b rfi_flush_fallback 123 b rfi_flush_fallback
101 124
102#define RFI_TO_GUEST \ 125#define RFI_TO_GUEST \
126 STF_EXIT_BARRIER_SLOT; \
103 RFI_FLUSH_SLOT; \ 127 RFI_FLUSH_SLOT; \
104 rfid; \ 128 rfid; \
105 b rfi_flush_fallback 129 b rfi_flush_fallback
@@ -108,21 +132,25 @@
108 hrfid 132 hrfid
109 133
110#define HRFI_TO_USER \ 134#define HRFI_TO_USER \
135 STF_EXIT_BARRIER_SLOT; \
111 RFI_FLUSH_SLOT; \ 136 RFI_FLUSH_SLOT; \
112 hrfid; \ 137 hrfid; \
113 b hrfi_flush_fallback 138 b hrfi_flush_fallback
114 139
115#define HRFI_TO_USER_OR_KERNEL \ 140#define HRFI_TO_USER_OR_KERNEL \
141 STF_EXIT_BARRIER_SLOT; \
116 RFI_FLUSH_SLOT; \ 142 RFI_FLUSH_SLOT; \
117 hrfid; \ 143 hrfid; \
118 b hrfi_flush_fallback 144 b hrfi_flush_fallback
119 145
120#define HRFI_TO_GUEST \ 146#define HRFI_TO_GUEST \
147 STF_EXIT_BARRIER_SLOT; \
121 RFI_FLUSH_SLOT; \ 148 RFI_FLUSH_SLOT; \
122 hrfid; \ 149 hrfid; \
123 b hrfi_flush_fallback 150 b hrfi_flush_fallback
124 151
125#define HRFI_TO_UNKNOWN \ 152#define HRFI_TO_UNKNOWN \
153 STF_EXIT_BARRIER_SLOT; \
126 RFI_FLUSH_SLOT; \ 154 RFI_FLUSH_SLOT; \
127 hrfid; \ 155 hrfid; \
128 b hrfi_flush_fallback 156 b hrfi_flush_fallback
@@ -254,6 +282,7 @@ END_FTR_SECTION_NESTED(ftr,ftr,943)
254#define __EXCEPTION_PROLOG_1_PRE(area) \ 282#define __EXCEPTION_PROLOG_1_PRE(area) \
255 OPT_SAVE_REG_TO_PACA(area+EX_PPR, r9, CPU_FTR_HAS_PPR); \ 283 OPT_SAVE_REG_TO_PACA(area+EX_PPR, r9, CPU_FTR_HAS_PPR); \
256 OPT_SAVE_REG_TO_PACA(area+EX_CFAR, r10, CPU_FTR_CFAR); \ 284 OPT_SAVE_REG_TO_PACA(area+EX_CFAR, r10, CPU_FTR_CFAR); \
285 INTERRUPT_TO_KERNEL; \
257 SAVE_CTR(r10, area); \ 286 SAVE_CTR(r10, area); \
258 mfcr r9; 287 mfcr r9;
259 288
diff --git a/arch/powerpc/include/asm/feature-fixups.h b/arch/powerpc/include/asm/feature-fixups.h
index 1e82eb3caabd..a9b64df34e2a 100644
--- a/arch/powerpc/include/asm/feature-fixups.h
+++ b/arch/powerpc/include/asm/feature-fixups.h
@@ -187,6 +187,22 @@ label##3: \
187 FTR_ENTRY_OFFSET label##1b-label##3b; \ 187 FTR_ENTRY_OFFSET label##1b-label##3b; \
188 .popsection; 188 .popsection;
189 189
190#define STF_ENTRY_BARRIER_FIXUP_SECTION \
191953: \
192 .pushsection __stf_entry_barrier_fixup,"a"; \
193 .align 2; \
194954: \
195 FTR_ENTRY_OFFSET 953b-954b; \
196 .popsection;
197
198#define STF_EXIT_BARRIER_FIXUP_SECTION \
199955: \
200 .pushsection __stf_exit_barrier_fixup,"a"; \
201 .align 2; \
202956: \
203 FTR_ENTRY_OFFSET 955b-956b; \
204 .popsection;
205
190#define RFI_FLUSH_FIXUP_SECTION \ 206#define RFI_FLUSH_FIXUP_SECTION \
191951: \ 207951: \
192 .pushsection __rfi_flush_fixup,"a"; \ 208 .pushsection __rfi_flush_fixup,"a"; \
@@ -199,6 +215,9 @@ label##3: \
199#ifndef __ASSEMBLY__ 215#ifndef __ASSEMBLY__
200#include <linux/types.h> 216#include <linux/types.h>
201 217
218extern long stf_barrier_fallback;
219extern long __start___stf_entry_barrier_fixup, __stop___stf_entry_barrier_fixup;
220extern long __start___stf_exit_barrier_fixup, __stop___stf_exit_barrier_fixup;
202extern long __start___rfi_flush_fixup, __stop___rfi_flush_fixup; 221extern long __start___rfi_flush_fixup, __stop___rfi_flush_fixup;
203 222
204void apply_feature_fixups(void); 223void apply_feature_fixups(void);
diff --git a/arch/powerpc/include/asm/kvm_book3s.h b/arch/powerpc/include/asm/kvm_book3s.h
index 4c02a7378d06..e7377b73cfec 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -96,6 +96,7 @@ struct kvmppc_vcore {
96 struct kvm_vcpu *runner; 96 struct kvm_vcpu *runner;
97 struct kvm *kvm; 97 struct kvm *kvm;
98 u64 tb_offset; /* guest timebase - host timebase */ 98 u64 tb_offset; /* guest timebase - host timebase */
99 u64 tb_offset_applied; /* timebase offset currently in force */
99 ulong lpcr; 100 ulong lpcr;
100 u32 arch_compat; 101 u32 arch_compat;
101 ulong pcr; 102 ulong pcr;
diff --git a/arch/powerpc/include/asm/security_features.h b/arch/powerpc/include/asm/security_features.h
index fa4d2e1cf772..44989b22383c 100644
--- a/arch/powerpc/include/asm/security_features.h
+++ b/arch/powerpc/include/asm/security_features.h
@@ -12,6 +12,17 @@
12extern unsigned long powerpc_security_features; 12extern unsigned long powerpc_security_features;
13extern bool rfi_flush; 13extern bool rfi_flush;
14 14
15/* These are bit flags */
16enum stf_barrier_type {
17 STF_BARRIER_NONE = 0x1,
18 STF_BARRIER_FALLBACK = 0x2,
19 STF_BARRIER_EIEIO = 0x4,
20 STF_BARRIER_SYNC_ORI = 0x8,
21};
22
23void setup_stf_barrier(void);
24void do_stf_barrier_fixups(enum stf_barrier_type types);
25
15static inline void security_ftr_set(unsigned long feature) 26static inline void security_ftr_set(unsigned long feature)
16{ 27{
17 powerpc_security_features |= feature; 28 powerpc_security_features |= feature;
diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
index 6bee65f3cfd3..373dc1d6ef44 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -562,6 +562,7 @@ int main(void)
562 OFFSET(VCORE_NAPPING_THREADS, kvmppc_vcore, napping_threads); 562 OFFSET(VCORE_NAPPING_THREADS, kvmppc_vcore, napping_threads);
563 OFFSET(VCORE_KVM, kvmppc_vcore, kvm); 563 OFFSET(VCORE_KVM, kvmppc_vcore, kvm);
564 OFFSET(VCORE_TB_OFFSET, kvmppc_vcore, tb_offset); 564 OFFSET(VCORE_TB_OFFSET, kvmppc_vcore, tb_offset);
565 OFFSET(VCORE_TB_OFFSET_APPL, kvmppc_vcore, tb_offset_applied);
565 OFFSET(VCORE_LPCR, kvmppc_vcore, lpcr); 566 OFFSET(VCORE_LPCR, kvmppc_vcore, lpcr);
566 OFFSET(VCORE_PCR, kvmppc_vcore, pcr); 567 OFFSET(VCORE_PCR, kvmppc_vcore, pcr);
567 OFFSET(VCORE_DPDES, kvmppc_vcore, dpdes); 568 OFFSET(VCORE_DPDES, kvmppc_vcore, dpdes);
diff --git a/arch/powerpc/kernel/cpu_setup_power.S b/arch/powerpc/kernel/cpu_setup_power.S
index 3f30c994e931..458b928dbd84 100644
--- a/arch/powerpc/kernel/cpu_setup_power.S
+++ b/arch/powerpc/kernel/cpu_setup_power.S
@@ -28,6 +28,7 @@ _GLOBAL(__setup_cpu_power7)
28 beqlr 28 beqlr
29 li r0,0 29 li r0,0
30 mtspr SPRN_LPID,r0 30 mtspr SPRN_LPID,r0
31 mtspr SPRN_PCR,r0
31 mfspr r3,SPRN_LPCR 32 mfspr r3,SPRN_LPCR
32 li r4,(LPCR_LPES1 >> LPCR_LPES_SH) 33 li r4,(LPCR_LPES1 >> LPCR_LPES_SH)
33 bl __init_LPCR_ISA206 34 bl __init_LPCR_ISA206
@@ -41,6 +42,7 @@ _GLOBAL(__restore_cpu_power7)
41 beqlr 42 beqlr
42 li r0,0 43 li r0,0
43 mtspr SPRN_LPID,r0 44 mtspr SPRN_LPID,r0
45 mtspr SPRN_PCR,r0
44 mfspr r3,SPRN_LPCR 46 mfspr r3,SPRN_LPCR
45 li r4,(LPCR_LPES1 >> LPCR_LPES_SH) 47 li r4,(LPCR_LPES1 >> LPCR_LPES_SH)
46 bl __init_LPCR_ISA206 48 bl __init_LPCR_ISA206
@@ -57,6 +59,7 @@ _GLOBAL(__setup_cpu_power8)
57 beqlr 59 beqlr
58 li r0,0 60 li r0,0
59 mtspr SPRN_LPID,r0 61 mtspr SPRN_LPID,r0
62 mtspr SPRN_PCR,r0
60 mfspr r3,SPRN_LPCR 63 mfspr r3,SPRN_LPCR
61 ori r3, r3, LPCR_PECEDH 64 ori r3, r3, LPCR_PECEDH
62 li r4,0 /* LPES = 0 */ 65 li r4,0 /* LPES = 0 */
@@ -78,6 +81,7 @@ _GLOBAL(__restore_cpu_power8)
78 beqlr 81 beqlr
79 li r0,0 82 li r0,0
80 mtspr SPRN_LPID,r0 83 mtspr SPRN_LPID,r0
84 mtspr SPRN_PCR,r0
81 mfspr r3,SPRN_LPCR 85 mfspr r3,SPRN_LPCR
82 ori r3, r3, LPCR_PECEDH 86 ori r3, r3, LPCR_PECEDH
83 li r4,0 /* LPES = 0 */ 87 li r4,0 /* LPES = 0 */
@@ -99,6 +103,7 @@ _GLOBAL(__setup_cpu_power9)
99 mtspr SPRN_PSSCR,r0 103 mtspr SPRN_PSSCR,r0
100 mtspr SPRN_LPID,r0 104 mtspr SPRN_LPID,r0
101 mtspr SPRN_PID,r0 105 mtspr SPRN_PID,r0
106 mtspr SPRN_PCR,r0
102 mfspr r3,SPRN_LPCR 107 mfspr r3,SPRN_LPCR
103 LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE | LPCR_HEIC) 108 LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE | LPCR_HEIC)
104 or r3, r3, r4 109 or r3, r3, r4
@@ -123,6 +128,7 @@ _GLOBAL(__restore_cpu_power9)
123 mtspr SPRN_PSSCR,r0 128 mtspr SPRN_PSSCR,r0
124 mtspr SPRN_LPID,r0 129 mtspr SPRN_LPID,r0
125 mtspr SPRN_PID,r0 130 mtspr SPRN_PID,r0
131 mtspr SPRN_PCR,r0
126 mfspr r3,SPRN_LPCR 132 mfspr r3,SPRN_LPCR
127 LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE | LPCR_HEIC) 133 LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE | LPCR_HEIC)
128 or r3, r3, r4 134 or r3, r3, r4
diff --git a/arch/powerpc/kernel/dt_cpu_ftrs.c b/arch/powerpc/kernel/dt_cpu_ftrs.c
index 8ab51f6ca03a..c904477abaf3 100644
--- a/arch/powerpc/kernel/dt_cpu_ftrs.c
+++ b/arch/powerpc/kernel/dt_cpu_ftrs.c
@@ -101,6 +101,7 @@ static void __restore_cpu_cpufeatures(void)
101 if (hv_mode) { 101 if (hv_mode) {
102 mtspr(SPRN_LPID, 0); 102 mtspr(SPRN_LPID, 0);
103 mtspr(SPRN_HFSCR, system_registers.hfscr); 103 mtspr(SPRN_HFSCR, system_registers.hfscr);
104 mtspr(SPRN_PCR, 0);
104 } 105 }
105 mtspr(SPRN_FSCR, system_registers.fscr); 106 mtspr(SPRN_FSCR, system_registers.fscr);
106 107
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index ae6a849db60b..f283958129f2 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -885,7 +885,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_TM)
885#endif 885#endif
886 886
887 887
888EXC_REAL_MASKABLE(decrementer, 0x900, 0x80, IRQS_DISABLED) 888EXC_REAL_OOL_MASKABLE(decrementer, 0x900, 0x80, IRQS_DISABLED)
889EXC_VIRT_MASKABLE(decrementer, 0x4900, 0x80, 0x900, IRQS_DISABLED) 889EXC_VIRT_MASKABLE(decrementer, 0x4900, 0x80, 0x900, IRQS_DISABLED)
890TRAMP_KVM(PACA_EXGEN, 0x900) 890TRAMP_KVM(PACA_EXGEN, 0x900)
891EXC_COMMON_ASYNC(decrementer_common, 0x900, timer_interrupt) 891EXC_COMMON_ASYNC(decrementer_common, 0x900, timer_interrupt)
@@ -961,6 +961,7 @@ EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
961 mtctr r13; \ 961 mtctr r13; \
962 GET_PACA(r13); \ 962 GET_PACA(r13); \
963 std r10,PACA_EXGEN+EX_R10(r13); \ 963 std r10,PACA_EXGEN+EX_R10(r13); \
964 INTERRUPT_TO_KERNEL; \
964 KVMTEST_PR(0xc00); /* uses r10, branch to do_kvm_0xc00_system_call */ \ 965 KVMTEST_PR(0xc00); /* uses r10, branch to do_kvm_0xc00_system_call */ \
965 HMT_MEDIUM; \ 966 HMT_MEDIUM; \
966 mfctr r9; 967 mfctr r9;
@@ -969,7 +970,8 @@ EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
969#define SYSCALL_KVMTEST \ 970#define SYSCALL_KVMTEST \
970 HMT_MEDIUM; \ 971 HMT_MEDIUM; \
971 mr r9,r13; \ 972 mr r9,r13; \
972 GET_PACA(r13); 973 GET_PACA(r13); \
974 INTERRUPT_TO_KERNEL;
973#endif 975#endif
974 976
975#define LOAD_SYSCALL_HANDLER(reg) \ 977#define LOAD_SYSCALL_HANDLER(reg) \
@@ -1507,6 +1509,19 @@ masked_##_H##interrupt: \
1507 b .; \ 1509 b .; \
1508 MASKED_DEC_HANDLER(_H) 1510 MASKED_DEC_HANDLER(_H)
1509 1511
1512TRAMP_REAL_BEGIN(stf_barrier_fallback)
1513 std r9,PACA_EXRFI+EX_R9(r13)
1514 std r10,PACA_EXRFI+EX_R10(r13)
1515 sync
1516 ld r9,PACA_EXRFI+EX_R9(r13)
1517 ld r10,PACA_EXRFI+EX_R10(r13)
1518 ori 31,31,0
1519 .rept 14
1520 b 1f
15211:
1522 .endr
1523 blr
1524
1510TRAMP_REAL_BEGIN(rfi_flush_fallback) 1525TRAMP_REAL_BEGIN(rfi_flush_fallback)
1511 SET_SCRATCH0(r13); 1526 SET_SCRATCH0(r13);
1512 GET_PACA(r13); 1527 GET_PACA(r13);
diff --git a/arch/powerpc/kernel/security.c b/arch/powerpc/kernel/security.c
index bab5a27ea805..b98a722da915 100644
--- a/arch/powerpc/kernel/security.c
+++ b/arch/powerpc/kernel/security.c
@@ -8,6 +8,7 @@
8#include <linux/device.h> 8#include <linux/device.h>
9#include <linux/seq_buf.h> 9#include <linux/seq_buf.h>
10 10
11#include <asm/debugfs.h>
11#include <asm/security_features.h> 12#include <asm/security_features.h>
12 13
13 14
@@ -86,3 +87,151 @@ ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, c
86 87
87 return s.len; 88 return s.len;
88} 89}
90
91/*
92 * Store-forwarding barrier support.
93 */
94
95static enum stf_barrier_type stf_enabled_flush_types;
96static bool no_stf_barrier;
97bool stf_barrier;
98
99static int __init handle_no_stf_barrier(char *p)
100{
101 pr_info("stf-barrier: disabled on command line.");
102 no_stf_barrier = true;
103 return 0;
104}
105
106early_param("no_stf_barrier", handle_no_stf_barrier);
107
108/* This is the generic flag used by other architectures */
109static int __init handle_ssbd(char *p)
110{
111 if (!p || strncmp(p, "auto", 5) == 0 || strncmp(p, "on", 2) == 0 ) {
112 /* Until firmware tells us, we have the barrier with auto */
113 return 0;
114 } else if (strncmp(p, "off", 3) == 0) {
115 handle_no_stf_barrier(NULL);
116 return 0;
117 } else
118 return 1;
119
120 return 0;
121}
122early_param("spec_store_bypass_disable", handle_ssbd);
123
124/* This is the generic flag used by other architectures */
125static int __init handle_no_ssbd(char *p)
126{
127 handle_no_stf_barrier(NULL);
128 return 0;
129}
130early_param("nospec_store_bypass_disable", handle_no_ssbd);
131
132static void stf_barrier_enable(bool enable)
133{
134 if (enable)
135 do_stf_barrier_fixups(stf_enabled_flush_types);
136 else
137 do_stf_barrier_fixups(STF_BARRIER_NONE);
138
139 stf_barrier = enable;
140}
141
142void setup_stf_barrier(void)
143{
144 enum stf_barrier_type type;
145 bool enable, hv;
146
147 hv = cpu_has_feature(CPU_FTR_HVMODE);
148
149 /* Default to fallback in case fw-features are not available */
150 if (cpu_has_feature(CPU_FTR_ARCH_300))
151 type = STF_BARRIER_EIEIO;
152 else if (cpu_has_feature(CPU_FTR_ARCH_207S))
153 type = STF_BARRIER_SYNC_ORI;
154 else if (cpu_has_feature(CPU_FTR_ARCH_206))
155 type = STF_BARRIER_FALLBACK;
156 else
157 type = STF_BARRIER_NONE;
158
159 enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) &&
160 (security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR) ||
161 (security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV) && hv));
162
163 if (type == STF_BARRIER_FALLBACK) {
164 pr_info("stf-barrier: fallback barrier available\n");
165 } else if (type == STF_BARRIER_SYNC_ORI) {
166 pr_info("stf-barrier: hwsync barrier available\n");
167 } else if (type == STF_BARRIER_EIEIO) {
168 pr_info("stf-barrier: eieio barrier available\n");
169 }
170
171 stf_enabled_flush_types = type;
172
173 if (!no_stf_barrier)
174 stf_barrier_enable(enable);
175}
176
177ssize_t cpu_show_spec_store_bypass(struct device *dev, struct device_attribute *attr, char *buf)
178{
179 if (stf_barrier && stf_enabled_flush_types != STF_BARRIER_NONE) {
180 const char *type;
181 switch (stf_enabled_flush_types) {
182 case STF_BARRIER_EIEIO:
183 type = "eieio";
184 break;
185 case STF_BARRIER_SYNC_ORI:
186 type = "hwsync";
187 break;
188 case STF_BARRIER_FALLBACK:
189 type = "fallback";
190 break;
191 default:
192 type = "unknown";
193 }
194 return sprintf(buf, "Mitigation: Kernel entry/exit barrier (%s)\n", type);
195 }
196
197 if (!security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV) &&
198 !security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR))
199 return sprintf(buf, "Not affected\n");
200
201 return sprintf(buf, "Vulnerable\n");
202}
203
204#ifdef CONFIG_DEBUG_FS
205static int stf_barrier_set(void *data, u64 val)
206{
207 bool enable;
208
209 if (val == 1)
210 enable = true;
211 else if (val == 0)
212 enable = false;
213 else
214 return -EINVAL;
215
216 /* Only do anything if we're changing state */
217 if (enable != stf_barrier)
218 stf_barrier_enable(enable);
219
220 return 0;
221}
222
223static int stf_barrier_get(void *data, u64 *val)
224{
225 *val = stf_barrier ? 1 : 0;
226 return 0;
227}
228
229DEFINE_SIMPLE_ATTRIBUTE(fops_stf_barrier, stf_barrier_get, stf_barrier_set, "%llu\n");
230
231static __init int stf_barrier_debugfs_init(void)
232{
233 debugfs_create_file("stf_barrier", 0600, powerpc_debugfs_root, NULL, &fops_stf_barrier);
234 return 0;
235}
236device_initcall(stf_barrier_debugfs_init);
237#endif /* CONFIG_DEBUG_FS */
diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index c8af90ff49f0..b8d82678f8b4 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -134,6 +134,20 @@ SECTIONS
134 134
135#ifdef CONFIG_PPC64 135#ifdef CONFIG_PPC64
136 . = ALIGN(8); 136 . = ALIGN(8);
137 __stf_entry_barrier_fixup : AT(ADDR(__stf_entry_barrier_fixup) - LOAD_OFFSET) {
138 __start___stf_entry_barrier_fixup = .;
139 *(__stf_entry_barrier_fixup)
140 __stop___stf_entry_barrier_fixup = .;
141 }
142
143 . = ALIGN(8);
144 __stf_exit_barrier_fixup : AT(ADDR(__stf_exit_barrier_fixup) - LOAD_OFFSET) {
145 __start___stf_exit_barrier_fixup = .;
146 *(__stf_exit_barrier_fixup)
147 __stop___stf_exit_barrier_fixup = .;
148 }
149
150 . = ALIGN(8);
137 __rfi_flush_fixup : AT(ADDR(__rfi_flush_fixup) - LOAD_OFFSET) { 151 __rfi_flush_fixup : AT(ADDR(__rfi_flush_fixup) - LOAD_OFFSET) {
138 __start___rfi_flush_fixup = .; 152 __start___rfi_flush_fixup = .;
139 *(__rfi_flush_fixup) 153 *(__rfi_flush_fixup)
diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c b/arch/powerpc/kvm/book3s_64_mmu_radix.c
index a57eafec4dc2..361f42c8c73e 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_radix.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c
@@ -162,7 +162,7 @@ static void kvmppc_radix_tlbie_page(struct kvm *kvm, unsigned long addr,
162 if (cpu_has_feature(CPU_FTR_P9_TLBIE_BUG)) 162 if (cpu_has_feature(CPU_FTR_P9_TLBIE_BUG))
163 asm volatile(PPC_TLBIE_5(%0, %1, 0, 0, 1) 163 asm volatile(PPC_TLBIE_5(%0, %1, 0, 0, 1)
164 : : "r" (addr), "r" (kvm->arch.lpid) : "memory"); 164 : : "r" (addr), "r" (kvm->arch.lpid) : "memory");
165 asm volatile("ptesync": : :"memory"); 165 asm volatile("eieio ; tlbsync ; ptesync": : :"memory");
166} 166}
167 167
168static void kvmppc_radix_flush_pwc(struct kvm *kvm, unsigned long addr) 168static void kvmppc_radix_flush_pwc(struct kvm *kvm, unsigned long addr)
@@ -173,7 +173,7 @@ static void kvmppc_radix_flush_pwc(struct kvm *kvm, unsigned long addr)
173 /* RIC=1 PRS=0 R=1 IS=2 */ 173 /* RIC=1 PRS=0 R=1 IS=2 */
174 asm volatile(PPC_TLBIE_5(%0, %1, 1, 0, 1) 174 asm volatile(PPC_TLBIE_5(%0, %1, 1, 0, 1)
175 : : "r" (rb), "r" (kvm->arch.lpid) : "memory"); 175 : : "r" (rb), "r" (kvm->arch.lpid) : "memory");
176 asm volatile("ptesync": : :"memory"); 176 asm volatile("eieio ; tlbsync ; ptesync": : :"memory");
177} 177}
178 178
179unsigned long kvmppc_radix_update_pte(struct kvm *kvm, pte_t *ptep, 179unsigned long kvmppc_radix_update_pte(struct kvm *kvm, pte_t *ptep,
@@ -584,7 +584,7 @@ int kvm_unmap_radix(struct kvm *kvm, struct kvm_memory_slot *memslot,
584 584
585 ptep = __find_linux_pte(kvm->arch.pgtable, gpa, NULL, &shift); 585 ptep = __find_linux_pte(kvm->arch.pgtable, gpa, NULL, &shift);
586 if (ptep && pte_present(*ptep)) { 586 if (ptep && pte_present(*ptep)) {
587 old = kvmppc_radix_update_pte(kvm, ptep, _PAGE_PRESENT, 0, 587 old = kvmppc_radix_update_pte(kvm, ptep, ~0UL, 0,
588 gpa, shift); 588 gpa, shift);
589 kvmppc_radix_tlbie_page(kvm, gpa, shift); 589 kvmppc_radix_tlbie_page(kvm, gpa, shift);
590 if ((old & _PAGE_DIRTY) && memslot->dirty_bitmap) { 590 if ((old & _PAGE_DIRTY) && memslot->dirty_bitmap) {
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 4d07fca5121c..9963f65c212b 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -2441,6 +2441,7 @@ static void init_vcore_to_run(struct kvmppc_vcore *vc)
2441 vc->in_guest = 0; 2441 vc->in_guest = 0;
2442 vc->napping_threads = 0; 2442 vc->napping_threads = 0;
2443 vc->conferring_threads = 0; 2443 vc->conferring_threads = 0;
2444 vc->tb_offset_applied = 0;
2444} 2445}
2445 2446
2446static bool can_dynamic_split(struct kvmppc_vcore *vc, struct core_info *cip) 2447static bool can_dynamic_split(struct kvmppc_vcore *vc, struct core_info *cip)
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index bd63fa8a08b5..07ca1b2a7966 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -692,6 +692,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
69222: ld r8,VCORE_TB_OFFSET(r5) 69222: ld r8,VCORE_TB_OFFSET(r5)
693 cmpdi r8,0 693 cmpdi r8,0
694 beq 37f 694 beq 37f
695 std r8, VCORE_TB_OFFSET_APPL(r5)
695 mftb r6 /* current host timebase */ 696 mftb r6 /* current host timebase */
696 add r8,r8,r6 697 add r8,r8,r6
697 mtspr SPRN_TBU40,r8 /* update upper 40 bits */ 698 mtspr SPRN_TBU40,r8 /* update upper 40 bits */
@@ -940,18 +941,6 @@ FTR_SECTION_ELSE
940ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_300) 941ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_300)
9418: 9428:
942 943
943 /*
944 * Set the decrementer to the guest decrementer.
945 */
946 ld r8,VCPU_DEC_EXPIRES(r4)
947 /* r8 is a host timebase value here, convert to guest TB */
948 ld r5,HSTATE_KVM_VCORE(r13)
949 ld r6,VCORE_TB_OFFSET(r5)
950 add r8,r8,r6
951 mftb r7
952 subf r3,r7,r8
953 mtspr SPRN_DEC,r3
954
955 ld r5, VCPU_SPRG0(r4) 944 ld r5, VCPU_SPRG0(r4)
956 ld r6, VCPU_SPRG1(r4) 945 ld r6, VCPU_SPRG1(r4)
957 ld r7, VCPU_SPRG2(r4) 946 ld r7, VCPU_SPRG2(r4)
@@ -1005,6 +994,18 @@ ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_300)
1005 mtspr SPRN_LPCR,r8 994 mtspr SPRN_LPCR,r8
1006 isync 995 isync
1007 996
997 /*
998 * Set the decrementer to the guest decrementer.
999 */
1000 ld r8,VCPU_DEC_EXPIRES(r4)
1001 /* r8 is a host timebase value here, convert to guest TB */
1002 ld r5,HSTATE_KVM_VCORE(r13)
1003 ld r6,VCORE_TB_OFFSET_APPL(r5)
1004 add r8,r8,r6
1005 mftb r7
1006 subf r3,r7,r8
1007 mtspr SPRN_DEC,r3
1008
1008 /* Check if HDEC expires soon */ 1009 /* Check if HDEC expires soon */
1009 mfspr r3, SPRN_HDEC 1010 mfspr r3, SPRN_HDEC
1010 EXTEND_HDEC(r3) 1011 EXTEND_HDEC(r3)
@@ -1597,8 +1598,27 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX)
1597 1598
1598guest_bypass: 1599guest_bypass:
1599 stw r12, STACK_SLOT_TRAP(r1) 1600 stw r12, STACK_SLOT_TRAP(r1)
1600 mr r3, r12 1601
1602 /* Save DEC */
1603 /* Do this before kvmhv_commence_exit so we know TB is guest TB */
1604 ld r3, HSTATE_KVM_VCORE(r13)
1605 mfspr r5,SPRN_DEC
1606 mftb r6
1607 /* On P9, if the guest has large decr enabled, don't sign extend */
1608BEGIN_FTR_SECTION
1609 ld r4, VCORE_LPCR(r3)
1610 andis. r4, r4, LPCR_LD@h
1611 bne 16f
1612END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
1613 extsw r5,r5
161416: add r5,r5,r6
1615 /* r5 is a guest timebase value here, convert to host TB */
1616 ld r4,VCORE_TB_OFFSET_APPL(r3)
1617 subf r5,r4,r5
1618 std r5,VCPU_DEC_EXPIRES(r9)
1619
1601 /* Increment exit count, poke other threads to exit */ 1620 /* Increment exit count, poke other threads to exit */
1621 mr r3, r12
1602 bl kvmhv_commence_exit 1622 bl kvmhv_commence_exit
1603 nop 1623 nop
1604 ld r9, HSTATE_KVM_VCPU(r13) 1624 ld r9, HSTATE_KVM_VCPU(r13)
@@ -1639,23 +1659,6 @@ guest_bypass:
1639 mtspr SPRN_PURR,r3 1659 mtspr SPRN_PURR,r3
1640 mtspr SPRN_SPURR,r4 1660 mtspr SPRN_SPURR,r4
1641 1661
1642 /* Save DEC */
1643 ld r3, HSTATE_KVM_VCORE(r13)
1644 mfspr r5,SPRN_DEC
1645 mftb r6
1646 /* On P9, if the guest has large decr enabled, don't sign extend */
1647BEGIN_FTR_SECTION
1648 ld r4, VCORE_LPCR(r3)
1649 andis. r4, r4, LPCR_LD@h
1650 bne 16f
1651END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
1652 extsw r5,r5
165316: add r5,r5,r6
1654 /* r5 is a guest timebase value here, convert to host TB */
1655 ld r4,VCORE_TB_OFFSET(r3)
1656 subf r5,r4,r5
1657 std r5,VCPU_DEC_EXPIRES(r9)
1658
1659BEGIN_FTR_SECTION 1662BEGIN_FTR_SECTION
1660 b 8f 1663 b 8f
1661END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) 1664END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
@@ -1905,6 +1908,14 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
1905 cmpwi cr2, r0, 0 1908 cmpwi cr2, r0, 0
1906 beq cr2, 4f 1909 beq cr2, 4f
1907 1910
1911 /*
1912 * Radix: do eieio; tlbsync; ptesync sequence in case we
1913 * interrupted the guest between a tlbie and a ptesync.
1914 */
1915 eieio
1916 tlbsync
1917 ptesync
1918
1908 /* Radix: Handle the case where the guest used an illegal PID */ 1919 /* Radix: Handle the case where the guest used an illegal PID */
1909 LOAD_REG_ADDR(r4, mmu_base_pid) 1920 LOAD_REG_ADDR(r4, mmu_base_pid)
1910 lwz r3, VCPU_GUEST_PID(r9) 1921 lwz r3, VCPU_GUEST_PID(r9)
@@ -2017,9 +2028,11 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
2017 2028
201827: 202927:
2019 /* Subtract timebase offset from timebase */ 2030 /* Subtract timebase offset from timebase */
2020 ld r8,VCORE_TB_OFFSET(r5) 2031 ld r8, VCORE_TB_OFFSET_APPL(r5)
2021 cmpdi r8,0 2032 cmpdi r8,0
2022 beq 17f 2033 beq 17f
2034 li r0, 0
2035 std r0, VCORE_TB_OFFSET_APPL(r5)
2023 mftb r6 /* current guest timebase */ 2036 mftb r6 /* current guest timebase */
2024 subf r8,r8,r6 2037 subf r8,r8,r6
2025 mtspr SPRN_TBU40,r8 /* update upper 40 bits */ 2038 mtspr SPRN_TBU40,r8 /* update upper 40 bits */
@@ -2700,7 +2713,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
2700 add r3, r3, r5 2713 add r3, r3, r5
2701 ld r4, HSTATE_KVM_VCPU(r13) 2714 ld r4, HSTATE_KVM_VCPU(r13)
2702 ld r5, HSTATE_KVM_VCORE(r13) 2715 ld r5, HSTATE_KVM_VCORE(r13)
2703 ld r6, VCORE_TB_OFFSET(r5) 2716 ld r6, VCORE_TB_OFFSET_APPL(r5)
2704 subf r3, r6, r3 /* convert to host TB value */ 2717 subf r3, r6, r3 /* convert to host TB value */
2705 std r3, VCPU_DEC_EXPIRES(r4) 2718 std r3, VCPU_DEC_EXPIRES(r4)
2706 2719
@@ -2799,7 +2812,7 @@ END_FTR_SECTION(CPU_FTR_TM | CPU_FTR_P9_TM_HV_ASSIST, 0)
2799 /* Restore guest decrementer */ 2812 /* Restore guest decrementer */
2800 ld r3, VCPU_DEC_EXPIRES(r4) 2813 ld r3, VCPU_DEC_EXPIRES(r4)
2801 ld r5, HSTATE_KVM_VCORE(r13) 2814 ld r5, HSTATE_KVM_VCORE(r13)
2802 ld r6, VCORE_TB_OFFSET(r5) 2815 ld r6, VCORE_TB_OFFSET_APPL(r5)
2803 add r3, r3, r6 /* convert host TB to guest TB value */ 2816 add r3, r3, r6 /* convert host TB to guest TB value */
2804 mftb r7 2817 mftb r7
2805 subf r3, r7, r3 2818 subf r3, r7, r3
@@ -3606,12 +3619,9 @@ kvmppc_fix_pmao:
3606 */ 3619 */
3607kvmhv_start_timing: 3620kvmhv_start_timing:
3608 ld r5, HSTATE_KVM_VCORE(r13) 3621 ld r5, HSTATE_KVM_VCORE(r13)
3609 lbz r6, VCORE_IN_GUEST(r5) 3622 ld r6, VCORE_TB_OFFSET_APPL(r5)
3610 cmpwi r6, 0 3623 mftb r5
3611 beq 5f /* if in guest, need to */ 3624 subf r5, r6, r5 /* subtract current timebase offset */
3612 ld r6, VCORE_TB_OFFSET(r5) /* subtract timebase offset */
36135: mftb r5
3614 subf r5, r6, r5
3615 std r3, VCPU_CUR_ACTIVITY(r4) 3625 std r3, VCPU_CUR_ACTIVITY(r4)
3616 std r5, VCPU_ACTIVITY_START(r4) 3626 std r5, VCPU_ACTIVITY_START(r4)
3617 blr 3627 blr
@@ -3622,15 +3632,12 @@ kvmhv_start_timing:
3622 */ 3632 */
3623kvmhv_accumulate_time: 3633kvmhv_accumulate_time:
3624 ld r5, HSTATE_KVM_VCORE(r13) 3634 ld r5, HSTATE_KVM_VCORE(r13)
3625 lbz r8, VCORE_IN_GUEST(r5) 3635 ld r8, VCORE_TB_OFFSET_APPL(r5)
3626 cmpwi r8, 0 3636 ld r5, VCPU_CUR_ACTIVITY(r4)
3627 beq 4f /* if in guest, need to */
3628 ld r8, VCORE_TB_OFFSET(r5) /* subtract timebase offset */
36294: ld r5, VCPU_CUR_ACTIVITY(r4)
3630 ld r6, VCPU_ACTIVITY_START(r4) 3637 ld r6, VCPU_ACTIVITY_START(r4)
3631 std r3, VCPU_CUR_ACTIVITY(r4) 3638 std r3, VCPU_CUR_ACTIVITY(r4)
3632 mftb r7 3639 mftb r7
3633 subf r7, r8, r7 3640 subf r7, r8, r7 /* subtract current timebase offset */
3634 std r7, VCPU_ACTIVITY_START(r4) 3641 std r7, VCPU_ACTIVITY_START(r4)
3635 cmpdi r5, 0 3642 cmpdi r5, 0
3636 beqlr 3643 beqlr
diff --git a/arch/powerpc/kvm/book3s_xive_template.c b/arch/powerpc/kvm/book3s_xive_template.c
index c7a5deadd1cc..99c3620b40d9 100644
--- a/arch/powerpc/kvm/book3s_xive_template.c
+++ b/arch/powerpc/kvm/book3s_xive_template.c
@@ -11,6 +11,9 @@
11#define XGLUE(a,b) a##b 11#define XGLUE(a,b) a##b
12#define GLUE(a,b) XGLUE(a,b) 12#define GLUE(a,b) XGLUE(a,b)
13 13
14/* Dummy interrupt used when taking interrupts out of a queue in H_CPPR */
15#define XICS_DUMMY 1
16
14static void GLUE(X_PFX,ack_pending)(struct kvmppc_xive_vcpu *xc) 17static void GLUE(X_PFX,ack_pending)(struct kvmppc_xive_vcpu *xc)
15{ 18{
16 u8 cppr; 19 u8 cppr;
@@ -205,6 +208,10 @@ skip_ipi:
205 goto skip_ipi; 208 goto skip_ipi;
206 } 209 }
207 210
211 /* If it's the dummy interrupt, continue searching */
212 if (hirq == XICS_DUMMY)
213 goto skip_ipi;
214
208 /* If fetching, update queue pointers */ 215 /* If fetching, update queue pointers */
209 if (scan_type == scan_fetch) { 216 if (scan_type == scan_fetch) {
210 q->idx = idx; 217 q->idx = idx;
@@ -385,9 +392,76 @@ static void GLUE(X_PFX,push_pending_to_hw)(struct kvmppc_xive_vcpu *xc)
385 __x_writeb(prio, __x_tima + TM_SPC_SET_OS_PENDING); 392 __x_writeb(prio, __x_tima + TM_SPC_SET_OS_PENDING);
386} 393}
387 394
395static void GLUE(X_PFX,scan_for_rerouted_irqs)(struct kvmppc_xive *xive,
396 struct kvmppc_xive_vcpu *xc)
397{
398 unsigned int prio;
399
400 /* For each priority that is now masked */
401 for (prio = xc->cppr; prio < KVMPPC_XIVE_Q_COUNT; prio++) {
402 struct xive_q *q = &xc->queues[prio];
403 struct kvmppc_xive_irq_state *state;
404 struct kvmppc_xive_src_block *sb;
405 u32 idx, toggle, entry, irq, hw_num;
406 struct xive_irq_data *xd;
407 __be32 *qpage;
408 u16 src;
409
410 idx = q->idx;
411 toggle = q->toggle;
412 qpage = READ_ONCE(q->qpage);
413 if (!qpage)
414 continue;
415
416 /* For each interrupt in the queue */
417 for (;;) {
418 entry = be32_to_cpup(qpage + idx);
419
420 /* No more ? */
421 if ((entry >> 31) == toggle)
422 break;
423 irq = entry & 0x7fffffff;
424
425 /* Skip dummies and IPIs */
426 if (irq == XICS_DUMMY || irq == XICS_IPI)
427 goto next;
428 sb = kvmppc_xive_find_source(xive, irq, &src);
429 if (!sb)
430 goto next;
431 state = &sb->irq_state[src];
432
433 /* Has it been rerouted ? */
434 if (xc->server_num == state->act_server)
435 goto next;
436
437 /*
438 * Allright, it *has* been re-routed, kill it from
439 * the queue.
440 */
441 qpage[idx] = cpu_to_be32((entry & 0x80000000) | XICS_DUMMY);
442
443 /* Find the HW interrupt */
444 kvmppc_xive_select_irq(state, &hw_num, &xd);
445
446 /* If it's not an LSI, set PQ to 11 the EOI will force a resend */
447 if (!(xd->flags & XIVE_IRQ_FLAG_LSI))
448 GLUE(X_PFX,esb_load)(xd, XIVE_ESB_SET_PQ_11);
449
450 /* EOI the source */
451 GLUE(X_PFX,source_eoi)(hw_num, xd);
452
453 next:
454 idx = (idx + 1) & q->msk;
455 if (idx == 0)
456 toggle ^= 1;
457 }
458 }
459}
460
388X_STATIC int GLUE(X_PFX,h_cppr)(struct kvm_vcpu *vcpu, unsigned long cppr) 461X_STATIC int GLUE(X_PFX,h_cppr)(struct kvm_vcpu *vcpu, unsigned long cppr)
389{ 462{
390 struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu; 463 struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu;
464 struct kvmppc_xive *xive = vcpu->kvm->arch.xive;
391 u8 old_cppr; 465 u8 old_cppr;
392 466
393 pr_devel("H_CPPR(cppr=%ld)\n", cppr); 467 pr_devel("H_CPPR(cppr=%ld)\n", cppr);
@@ -407,14 +481,34 @@ X_STATIC int GLUE(X_PFX,h_cppr)(struct kvm_vcpu *vcpu, unsigned long cppr)
407 */ 481 */
408 smp_mb(); 482 smp_mb();
409 483
410 /* 484 if (cppr > old_cppr) {
411 * We are masking less, we need to look for pending things 485 /*
412 * to deliver and set VP pending bits accordingly to trigger 486 * We are masking less, we need to look for pending things
413 * a new interrupt otherwise we might miss MFRR changes for 487 * to deliver and set VP pending bits accordingly to trigger
414 * which we have optimized out sending an IPI signal. 488 * a new interrupt otherwise we might miss MFRR changes for
415 */ 489 * which we have optimized out sending an IPI signal.
416 if (cppr > old_cppr) 490 */
417 GLUE(X_PFX,push_pending_to_hw)(xc); 491 GLUE(X_PFX,push_pending_to_hw)(xc);
492 } else {
493 /*
494 * We are masking more, we need to check the queue for any
495 * interrupt that has been routed to another CPU, take
496 * it out (replace it with the dummy) and retrigger it.
497 *
498 * This is necessary since those interrupts may otherwise
499 * never be processed, at least not until this CPU restores
500 * its CPPR.
501 *
502 * This is in theory racy vs. HW adding new interrupts to
503 * the queue. In practice this works because the interesting
504 * cases are when the guest has done a set_xive() to move the
505 * interrupt away, which flushes the xive, followed by the
506 * target CPU doing a H_CPPR. So any new interrupt coming into
507 * the queue must still be routed to us and isn't a source
508 * of concern.
509 */
510 GLUE(X_PFX,scan_for_rerouted_irqs)(xive, xc);
511 }
418 512
419 /* Apply new CPPR */ 513 /* Apply new CPPR */
420 xc->hw_cppr = cppr; 514 xc->hw_cppr = cppr;
diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-fixups.c
index 288fe4f0db4e..e1bcdc32a851 100644
--- a/arch/powerpc/lib/feature-fixups.c
+++ b/arch/powerpc/lib/feature-fixups.c
@@ -23,6 +23,7 @@
23#include <asm/page.h> 23#include <asm/page.h>
24#include <asm/sections.h> 24#include <asm/sections.h>
25#include <asm/setup.h> 25#include <asm/setup.h>
26#include <asm/security_features.h>
26#include <asm/firmware.h> 27#include <asm/firmware.h>
27 28
28struct fixup_entry { 29struct fixup_entry {
@@ -117,6 +118,120 @@ void do_feature_fixups(unsigned long value, void *fixup_start, void *fixup_end)
117} 118}
118 119
119#ifdef CONFIG_PPC_BOOK3S_64 120#ifdef CONFIG_PPC_BOOK3S_64
121void do_stf_entry_barrier_fixups(enum stf_barrier_type types)
122{
123 unsigned int instrs[3], *dest;
124 long *start, *end;
125 int i;
126
127 start = PTRRELOC(&__start___stf_entry_barrier_fixup),
128 end = PTRRELOC(&__stop___stf_entry_barrier_fixup);
129
130 instrs[0] = 0x60000000; /* nop */
131 instrs[1] = 0x60000000; /* nop */
132 instrs[2] = 0x60000000; /* nop */
133
134 i = 0;
135 if (types & STF_BARRIER_FALLBACK) {
136 instrs[i++] = 0x7d4802a6; /* mflr r10 */
137 instrs[i++] = 0x60000000; /* branch patched below */
138 instrs[i++] = 0x7d4803a6; /* mtlr r10 */
139 } else if (types & STF_BARRIER_EIEIO) {
140 instrs[i++] = 0x7e0006ac; /* eieio + bit 6 hint */
141 } else if (types & STF_BARRIER_SYNC_ORI) {
142 instrs[i++] = 0x7c0004ac; /* hwsync */
143 instrs[i++] = 0xe94d0000; /* ld r10,0(r13) */
144 instrs[i++] = 0x63ff0000; /* ori 31,31,0 speculation barrier */
145 }
146
147 for (i = 0; start < end; start++, i++) {
148 dest = (void *)start + *start;
149
150 pr_devel("patching dest %lx\n", (unsigned long)dest);
151
152 patch_instruction(dest, instrs[0]);
153
154 if (types & STF_BARRIER_FALLBACK)
155 patch_branch(dest + 1, (unsigned long)&stf_barrier_fallback,
156 BRANCH_SET_LINK);
157 else
158 patch_instruction(dest + 1, instrs[1]);
159
160 patch_instruction(dest + 2, instrs[2]);
161 }
162
163 printk(KERN_DEBUG "stf-barrier: patched %d entry locations (%s barrier)\n", i,
164 (types == STF_BARRIER_NONE) ? "no" :
165 (types == STF_BARRIER_FALLBACK) ? "fallback" :
166 (types == STF_BARRIER_EIEIO) ? "eieio" :
167 (types == (STF_BARRIER_SYNC_ORI)) ? "hwsync"
168 : "unknown");
169}
170
171void do_stf_exit_barrier_fixups(enum stf_barrier_type types)
172{
173 unsigned int instrs[6], *dest;
174 long *start, *end;
175 int i;
176
177 start = PTRRELOC(&__start___stf_exit_barrier_fixup),
178 end = PTRRELOC(&__stop___stf_exit_barrier_fixup);
179
180 instrs[0] = 0x60000000; /* nop */
181 instrs[1] = 0x60000000; /* nop */
182 instrs[2] = 0x60000000; /* nop */
183 instrs[3] = 0x60000000; /* nop */
184 instrs[4] = 0x60000000; /* nop */
185 instrs[5] = 0x60000000; /* nop */
186
187 i = 0;
188 if (types & STF_BARRIER_FALLBACK || types & STF_BARRIER_SYNC_ORI) {
189 if (cpu_has_feature(CPU_FTR_HVMODE)) {
190 instrs[i++] = 0x7db14ba6; /* mtspr 0x131, r13 (HSPRG1) */
191 instrs[i++] = 0x7db04aa6; /* mfspr r13, 0x130 (HSPRG0) */
192 } else {
193 instrs[i++] = 0x7db243a6; /* mtsprg 2,r13 */
194 instrs[i++] = 0x7db142a6; /* mfsprg r13,1 */
195 }
196 instrs[i++] = 0x7c0004ac; /* hwsync */
197 instrs[i++] = 0xe9ad0000; /* ld r13,0(r13) */
198 instrs[i++] = 0x63ff0000; /* ori 31,31,0 speculation barrier */
199 if (cpu_has_feature(CPU_FTR_HVMODE)) {
200 instrs[i++] = 0x7db14aa6; /* mfspr r13, 0x131 (HSPRG1) */
201 } else {
202 instrs[i++] = 0x7db242a6; /* mfsprg r13,2 */
203 }
204 } else if (types & STF_BARRIER_EIEIO) {
205 instrs[i++] = 0x7e0006ac; /* eieio + bit 6 hint */
206 }
207
208 for (i = 0; start < end; start++, i++) {
209 dest = (void *)start + *start;
210
211 pr_devel("patching dest %lx\n", (unsigned long)dest);
212
213 patch_instruction(dest, instrs[0]);
214 patch_instruction(dest + 1, instrs[1]);
215 patch_instruction(dest + 2, instrs[2]);
216 patch_instruction(dest + 3, instrs[3]);
217 patch_instruction(dest + 4, instrs[4]);
218 patch_instruction(dest + 5, instrs[5]);
219 }
220 printk(KERN_DEBUG "stf-barrier: patched %d exit locations (%s barrier)\n", i,
221 (types == STF_BARRIER_NONE) ? "no" :
222 (types == STF_BARRIER_FALLBACK) ? "fallback" :
223 (types == STF_BARRIER_EIEIO) ? "eieio" :
224 (types == (STF_BARRIER_SYNC_ORI)) ? "hwsync"
225 : "unknown");
226}
227
228
229void do_stf_barrier_fixups(enum stf_barrier_type types)
230{
231 do_stf_entry_barrier_fixups(types);
232 do_stf_exit_barrier_fixups(types);
233}
234
120void do_rfi_flush_fixups(enum l1d_flush_type types) 235void do_rfi_flush_fixups(enum l1d_flush_type types)
121{ 236{
122 unsigned int instrs[3], *dest; 237 unsigned int instrs[3], *dest;
diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c
index ef8c9ce53a61..a6648ec99ca7 100644
--- a/arch/powerpc/platforms/powernv/setup.c
+++ b/arch/powerpc/platforms/powernv/setup.c
@@ -131,6 +131,7 @@ static void __init pnv_setup_arch(void)
131 set_arch_panic_timeout(10, ARCH_PANIC_TIMEOUT); 131 set_arch_panic_timeout(10, ARCH_PANIC_TIMEOUT);
132 132
133 pnv_setup_rfi_flush(); 133 pnv_setup_rfi_flush();
134 setup_stf_barrier();
134 135
135 /* Initialize SMP */ 136 /* Initialize SMP */
136 pnv_smp_init(); 137 pnv_smp_init();
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index b55ad4286dc7..fdb32e056ef4 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -710,6 +710,7 @@ static void __init pSeries_setup_arch(void)
710 fwnmi_init(); 710 fwnmi_init();
711 711
712 pseries_setup_rfi_flush(); 712 pseries_setup_rfi_flush();
713 setup_stf_barrier();
713 714
714 /* By default, only probe PCI (can be overridden by rtas_pci) */ 715 /* By default, only probe PCI (can be overridden by rtas_pci) */
715 pci_add_flags(PCI_PROBE_ONLY); 716 pci_add_flags(PCI_PROBE_ONLY);
diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
index 8961e3970901..969882b54266 100644
--- a/arch/s390/kvm/vsie.c
+++ b/arch/s390/kvm/vsie.c
@@ -578,7 +578,7 @@ static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
578 578
579 gpa = READ_ONCE(scb_o->itdba) & ~0xffUL; 579 gpa = READ_ONCE(scb_o->itdba) & ~0xffUL;
580 if (gpa && (scb_s->ecb & ECB_TE)) { 580 if (gpa && (scb_s->ecb & ECB_TE)) {
581 if (!(gpa & ~0x1fffU)) { 581 if (!(gpa & ~0x1fffUL)) {
582 rc = set_validity_icpt(scb_s, 0x0080U); 582 rc = set_validity_icpt(scb_s, 0x0080U);
583 goto unpin; 583 goto unpin;
584 } 584 }
diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
index 578793e97431..fb00a2fca990 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -198,7 +198,6 @@
198#define X86_FEATURE_CAT_L2 ( 7*32+ 5) /* Cache Allocation Technology L2 */ 198#define X86_FEATURE_CAT_L2 ( 7*32+ 5) /* Cache Allocation Technology L2 */
199#define X86_FEATURE_CDP_L3 ( 7*32+ 6) /* Code and Data Prioritization L3 */ 199#define X86_FEATURE_CDP_L3 ( 7*32+ 6) /* Code and Data Prioritization L3 */
200#define X86_FEATURE_INVPCID_SINGLE ( 7*32+ 7) /* Effectively INVPCID && CR4.PCIDE=1 */ 200#define X86_FEATURE_INVPCID_SINGLE ( 7*32+ 7) /* Effectively INVPCID && CR4.PCIDE=1 */
201
202#define X86_FEATURE_HW_PSTATE ( 7*32+ 8) /* AMD HW-PState */ 201#define X86_FEATURE_HW_PSTATE ( 7*32+ 8) /* AMD HW-PState */
203#define X86_FEATURE_PROC_FEEDBACK ( 7*32+ 9) /* AMD ProcFeedbackInterface */ 202#define X86_FEATURE_PROC_FEEDBACK ( 7*32+ 9) /* AMD ProcFeedbackInterface */
204#define X86_FEATURE_SME ( 7*32+10) /* AMD Secure Memory Encryption */ 203#define X86_FEATURE_SME ( 7*32+10) /* AMD Secure Memory Encryption */
@@ -207,13 +206,19 @@
207#define X86_FEATURE_RETPOLINE_AMD ( 7*32+13) /* "" AMD Retpoline mitigation for Spectre variant 2 */ 206#define X86_FEATURE_RETPOLINE_AMD ( 7*32+13) /* "" AMD Retpoline mitigation for Spectre variant 2 */
208#define X86_FEATURE_INTEL_PPIN ( 7*32+14) /* Intel Processor Inventory Number */ 207#define X86_FEATURE_INTEL_PPIN ( 7*32+14) /* Intel Processor Inventory Number */
209#define X86_FEATURE_CDP_L2 ( 7*32+15) /* Code and Data Prioritization L2 */ 208#define X86_FEATURE_CDP_L2 ( 7*32+15) /* Code and Data Prioritization L2 */
210 209#define X86_FEATURE_MSR_SPEC_CTRL ( 7*32+16) /* "" MSR SPEC_CTRL is implemented */
210#define X86_FEATURE_SSBD ( 7*32+17) /* Speculative Store Bypass Disable */
211#define X86_FEATURE_MBA ( 7*32+18) /* Memory Bandwidth Allocation */ 211#define X86_FEATURE_MBA ( 7*32+18) /* Memory Bandwidth Allocation */
212#define X86_FEATURE_RSB_CTXSW ( 7*32+19) /* "" Fill RSB on context switches */ 212#define X86_FEATURE_RSB_CTXSW ( 7*32+19) /* "" Fill RSB on context switches */
213#define X86_FEATURE_SEV ( 7*32+20) /* AMD Secure Encrypted Virtualization */ 213#define X86_FEATURE_SEV ( 7*32+20) /* AMD Secure Encrypted Virtualization */
214
215#define X86_FEATURE_USE_IBPB ( 7*32+21) /* "" Indirect Branch Prediction Barrier enabled */ 214#define X86_FEATURE_USE_IBPB ( 7*32+21) /* "" Indirect Branch Prediction Barrier enabled */
216#define X86_FEATURE_USE_IBRS_FW ( 7*32+22) /* "" Use IBRS during runtime firmware calls */ 215#define X86_FEATURE_USE_IBRS_FW ( 7*32+22) /* "" Use IBRS during runtime firmware calls */
216#define X86_FEATURE_SPEC_STORE_BYPASS_DISABLE ( 7*32+23) /* "" Disable Speculative Store Bypass. */
217#define X86_FEATURE_LS_CFG_SSBD ( 7*32+24) /* "" AMD SSBD implementation via LS_CFG MSR */
218#define X86_FEATURE_IBRS ( 7*32+25) /* Indirect Branch Restricted Speculation */
219#define X86_FEATURE_IBPB ( 7*32+26) /* Indirect Branch Prediction Barrier */
220#define X86_FEATURE_STIBP ( 7*32+27) /* Single Thread Indirect Branch Predictors */
221#define X86_FEATURE_ZEN ( 7*32+28) /* "" CPU is AMD family 0x17 (Zen) */
217 222
218/* Virtualization flags: Linux defined, word 8 */ 223/* Virtualization flags: Linux defined, word 8 */
219#define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */ 224#define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */
@@ -274,9 +279,10 @@
274#define X86_FEATURE_CLZERO (13*32+ 0) /* CLZERO instruction */ 279#define X86_FEATURE_CLZERO (13*32+ 0) /* CLZERO instruction */
275#define X86_FEATURE_IRPERF (13*32+ 1) /* Instructions Retired Count */ 280#define X86_FEATURE_IRPERF (13*32+ 1) /* Instructions Retired Count */
276#define X86_FEATURE_XSAVEERPTR (13*32+ 2) /* Always save/restore FP error pointers */ 281#define X86_FEATURE_XSAVEERPTR (13*32+ 2) /* Always save/restore FP error pointers */
277#define X86_FEATURE_IBPB (13*32+12) /* Indirect Branch Prediction Barrier */ 282#define X86_FEATURE_AMD_IBPB (13*32+12) /* "" Indirect Branch Prediction Barrier */
278#define X86_FEATURE_IBRS (13*32+14) /* Indirect Branch Restricted Speculation */ 283#define X86_FEATURE_AMD_IBRS (13*32+14) /* "" Indirect Branch Restricted Speculation */
279#define X86_FEATURE_STIBP (13*32+15) /* Single Thread Indirect Branch Predictors */ 284#define X86_FEATURE_AMD_STIBP (13*32+15) /* "" Single Thread Indirect Branch Predictors */
285#define X86_FEATURE_VIRT_SSBD (13*32+25) /* Virtualized Speculative Store Bypass Disable */
280 286
281/* Thermal and Power Management Leaf, CPUID level 0x00000006 (EAX), word 14 */ 287/* Thermal and Power Management Leaf, CPUID level 0x00000006 (EAX), word 14 */
282#define X86_FEATURE_DTHERM (14*32+ 0) /* Digital Thermal Sensor */ 288#define X86_FEATURE_DTHERM (14*32+ 0) /* Digital Thermal Sensor */
@@ -334,6 +340,7 @@
334#define X86_FEATURE_SPEC_CTRL (18*32+26) /* "" Speculation Control (IBRS + IBPB) */ 340#define X86_FEATURE_SPEC_CTRL (18*32+26) /* "" Speculation Control (IBRS + IBPB) */
335#define X86_FEATURE_INTEL_STIBP (18*32+27) /* "" Single Thread Indirect Branch Predictors */ 341#define X86_FEATURE_INTEL_STIBP (18*32+27) /* "" Single Thread Indirect Branch Predictors */
336#define X86_FEATURE_ARCH_CAPABILITIES (18*32+29) /* IA32_ARCH_CAPABILITIES MSR (Intel) */ 342#define X86_FEATURE_ARCH_CAPABILITIES (18*32+29) /* IA32_ARCH_CAPABILITIES MSR (Intel) */
343#define X86_FEATURE_SPEC_CTRL_SSBD (18*32+31) /* "" Speculative Store Bypass Disable */
337 344
338/* 345/*
339 * BUG word(s) 346 * BUG word(s)
@@ -363,5 +370,6 @@
363#define X86_BUG_CPU_MELTDOWN X86_BUG(14) /* CPU is affected by meltdown attack and needs kernel page table isolation */ 370#define X86_BUG_CPU_MELTDOWN X86_BUG(14) /* CPU is affected by meltdown attack and needs kernel page table isolation */
364#define X86_BUG_SPECTRE_V1 X86_BUG(15) /* CPU is affected by Spectre variant 1 attack with conditional branches */ 371#define X86_BUG_SPECTRE_V1 X86_BUG(15) /* CPU is affected by Spectre variant 1 attack with conditional branches */
365#define X86_BUG_SPECTRE_V2 X86_BUG(16) /* CPU is affected by Spectre variant 2 attack with indirect branches */ 372#define X86_BUG_SPECTRE_V2 X86_BUG(16) /* CPU is affected by Spectre variant 2 attack with indirect branches */
373#define X86_BUG_SPEC_STORE_BYPASS X86_BUG(17) /* CPU is affected by speculative store bypass attack */
366 374
367#endif /* _ASM_X86_CPUFEATURES_H */ 375#endif /* _ASM_X86_CPUFEATURES_H */
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index c25775fad4ed..f4b2588865e9 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -924,7 +924,7 @@ struct kvm_x86_ops {
924 int (*hardware_setup)(void); /* __init */ 924 int (*hardware_setup)(void); /* __init */
925 void (*hardware_unsetup)(void); /* __exit */ 925 void (*hardware_unsetup)(void); /* __exit */
926 bool (*cpu_has_accelerated_tpr)(void); 926 bool (*cpu_has_accelerated_tpr)(void);
927 bool (*cpu_has_high_real_mode_segbase)(void); 927 bool (*has_emulated_msr)(int index);
928 void (*cpuid_update)(struct kvm_vcpu *vcpu); 928 void (*cpuid_update)(struct kvm_vcpu *vcpu);
929 929
930 struct kvm *(*vm_alloc)(void); 930 struct kvm *(*vm_alloc)(void);
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index 53d5b1b9255e..fda2114197b3 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -42,6 +42,8 @@
42#define MSR_IA32_SPEC_CTRL 0x00000048 /* Speculation Control */ 42#define MSR_IA32_SPEC_CTRL 0x00000048 /* Speculation Control */
43#define SPEC_CTRL_IBRS (1 << 0) /* Indirect Branch Restricted Speculation */ 43#define SPEC_CTRL_IBRS (1 << 0) /* Indirect Branch Restricted Speculation */
44#define SPEC_CTRL_STIBP (1 << 1) /* Single Thread Indirect Branch Predictors */ 44#define SPEC_CTRL_STIBP (1 << 1) /* Single Thread Indirect Branch Predictors */
45#define SPEC_CTRL_SSBD_SHIFT 2 /* Speculative Store Bypass Disable bit */
46#define SPEC_CTRL_SSBD (1 << SPEC_CTRL_SSBD_SHIFT) /* Speculative Store Bypass Disable */
45 47
46#define MSR_IA32_PRED_CMD 0x00000049 /* Prediction Command */ 48#define MSR_IA32_PRED_CMD 0x00000049 /* Prediction Command */
47#define PRED_CMD_IBPB (1 << 0) /* Indirect Branch Prediction Barrier */ 49#define PRED_CMD_IBPB (1 << 0) /* Indirect Branch Prediction Barrier */
@@ -68,6 +70,11 @@
68#define MSR_IA32_ARCH_CAPABILITIES 0x0000010a 70#define MSR_IA32_ARCH_CAPABILITIES 0x0000010a
69#define ARCH_CAP_RDCL_NO (1 << 0) /* Not susceptible to Meltdown */ 71#define ARCH_CAP_RDCL_NO (1 << 0) /* Not susceptible to Meltdown */
70#define ARCH_CAP_IBRS_ALL (1 << 1) /* Enhanced IBRS support */ 72#define ARCH_CAP_IBRS_ALL (1 << 1) /* Enhanced IBRS support */
73#define ARCH_CAP_SSB_NO (1 << 4) /*
74 * Not susceptible to Speculative Store Bypass
75 * attack, so no Speculative Store Bypass
76 * control required.
77 */
71 78
72#define MSR_IA32_BBL_CR_CTL 0x00000119 79#define MSR_IA32_BBL_CR_CTL 0x00000119
73#define MSR_IA32_BBL_CR_CTL3 0x0000011e 80#define MSR_IA32_BBL_CR_CTL3 0x0000011e
@@ -340,6 +347,8 @@
340#define MSR_AMD64_SEV_ENABLED_BIT 0 347#define MSR_AMD64_SEV_ENABLED_BIT 0
341#define MSR_AMD64_SEV_ENABLED BIT_ULL(MSR_AMD64_SEV_ENABLED_BIT) 348#define MSR_AMD64_SEV_ENABLED BIT_ULL(MSR_AMD64_SEV_ENABLED_BIT)
342 349
350#define MSR_AMD64_VIRT_SPEC_CTRL 0xc001011f
351
343/* Fam 17h MSRs */ 352/* Fam 17h MSRs */
344#define MSR_F17H_IRPERF 0xc00000e9 353#define MSR_F17H_IRPERF 0xc00000e9
345 354
diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
index f928ad9b143f..8b38df98548e 100644
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -217,6 +217,14 @@ enum spectre_v2_mitigation {
217 SPECTRE_V2_IBRS, 217 SPECTRE_V2_IBRS,
218}; 218};
219 219
220/* The Speculative Store Bypass disable variants */
221enum ssb_mitigation {
222 SPEC_STORE_BYPASS_NONE,
223 SPEC_STORE_BYPASS_DISABLE,
224 SPEC_STORE_BYPASS_PRCTL,
225 SPEC_STORE_BYPASS_SECCOMP,
226};
227
220extern char __indirect_thunk_start[]; 228extern char __indirect_thunk_start[];
221extern char __indirect_thunk_end[]; 229extern char __indirect_thunk_end[];
222 230
@@ -241,22 +249,27 @@ static inline void vmexit_fill_RSB(void)
241#endif 249#endif
242} 250}
243 251
244#define alternative_msr_write(_msr, _val, _feature) \ 252static __always_inline
245 asm volatile(ALTERNATIVE("", \ 253void alternative_msr_write(unsigned int msr, u64 val, unsigned int feature)
246 "movl %[msr], %%ecx\n\t" \ 254{
247 "movl %[val], %%eax\n\t" \ 255 asm volatile(ALTERNATIVE("", "wrmsr", %c[feature])
248 "movl $0, %%edx\n\t" \ 256 : : "c" (msr),
249 "wrmsr", \ 257 "a" ((u32)val),
250 _feature) \ 258 "d" ((u32)(val >> 32)),
251 : : [msr] "i" (_msr), [val] "i" (_val) \ 259 [feature] "i" (feature)
252 : "eax", "ecx", "edx", "memory") 260 : "memory");
261}
253 262
254static inline void indirect_branch_prediction_barrier(void) 263static inline void indirect_branch_prediction_barrier(void)
255{ 264{
256 alternative_msr_write(MSR_IA32_PRED_CMD, PRED_CMD_IBPB, 265 u64 val = PRED_CMD_IBPB;
257 X86_FEATURE_USE_IBPB); 266
267 alternative_msr_write(MSR_IA32_PRED_CMD, val, X86_FEATURE_USE_IBPB);
258} 268}
259 269
270/* The Intel SPEC CTRL MSR base value cache */
271extern u64 x86_spec_ctrl_base;
272
260/* 273/*
261 * With retpoline, we must use IBRS to restrict branch prediction 274 * With retpoline, we must use IBRS to restrict branch prediction
262 * before calling into firmware. 275 * before calling into firmware.
@@ -265,14 +278,18 @@ static inline void indirect_branch_prediction_barrier(void)
265 */ 278 */
266#define firmware_restrict_branch_speculation_start() \ 279#define firmware_restrict_branch_speculation_start() \
267do { \ 280do { \
281 u64 val = x86_spec_ctrl_base | SPEC_CTRL_IBRS; \
282 \
268 preempt_disable(); \ 283 preempt_disable(); \
269 alternative_msr_write(MSR_IA32_SPEC_CTRL, SPEC_CTRL_IBRS, \ 284 alternative_msr_write(MSR_IA32_SPEC_CTRL, val, \
270 X86_FEATURE_USE_IBRS_FW); \ 285 X86_FEATURE_USE_IBRS_FW); \
271} while (0) 286} while (0)
272 287
273#define firmware_restrict_branch_speculation_end() \ 288#define firmware_restrict_branch_speculation_end() \
274do { \ 289do { \
275 alternative_msr_write(MSR_IA32_SPEC_CTRL, 0, \ 290 u64 val = x86_spec_ctrl_base; \
291 \
292 alternative_msr_write(MSR_IA32_SPEC_CTRL, val, \
276 X86_FEATURE_USE_IBRS_FW); \ 293 X86_FEATURE_USE_IBRS_FW); \
277 preempt_enable(); \ 294 preempt_enable(); \
278} while (0) 295} while (0)
diff --git a/arch/x86/include/asm/spec-ctrl.h b/arch/x86/include/asm/spec-ctrl.h
new file mode 100644
index 000000000000..ae7c2c5cd7f0
--- /dev/null
+++ b/arch/x86/include/asm/spec-ctrl.h
@@ -0,0 +1,80 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_X86_SPECCTRL_H_
3#define _ASM_X86_SPECCTRL_H_
4
5#include <linux/thread_info.h>
6#include <asm/nospec-branch.h>
7
8/*
9 * On VMENTER we must preserve whatever view of the SPEC_CTRL MSR
10 * the guest has, while on VMEXIT we restore the host view. This
11 * would be easier if SPEC_CTRL were architecturally maskable or
12 * shadowable for guests but this is not (currently) the case.
13 * Takes the guest view of SPEC_CTRL MSR as a parameter and also
14 * the guest's version of VIRT_SPEC_CTRL, if emulated.
15 */
16extern void x86_virt_spec_ctrl(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl, bool guest);
17
18/**
19 * x86_spec_ctrl_set_guest - Set speculation control registers for the guest
20 * @guest_spec_ctrl: The guest content of MSR_SPEC_CTRL
21 * @guest_virt_spec_ctrl: The guest controlled bits of MSR_VIRT_SPEC_CTRL
22 * (may get translated to MSR_AMD64_LS_CFG bits)
23 *
24 * Avoids writing to the MSR if the content/bits are the same
25 */
26static inline
27void x86_spec_ctrl_set_guest(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl)
28{
29 x86_virt_spec_ctrl(guest_spec_ctrl, guest_virt_spec_ctrl, true);
30}
31
32/**
33 * x86_spec_ctrl_restore_host - Restore host speculation control registers
34 * @guest_spec_ctrl: The guest content of MSR_SPEC_CTRL
35 * @guest_virt_spec_ctrl: The guest controlled bits of MSR_VIRT_SPEC_CTRL
36 * (may get translated to MSR_AMD64_LS_CFG bits)
37 *
38 * Avoids writing to the MSR if the content/bits are the same
39 */
40static inline
41void x86_spec_ctrl_restore_host(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl)
42{
43 x86_virt_spec_ctrl(guest_spec_ctrl, guest_virt_spec_ctrl, false);
44}
45
46/* AMD specific Speculative Store Bypass MSR data */
47extern u64 x86_amd_ls_cfg_base;
48extern u64 x86_amd_ls_cfg_ssbd_mask;
49
50static inline u64 ssbd_tif_to_spec_ctrl(u64 tifn)
51{
52 BUILD_BUG_ON(TIF_SSBD < SPEC_CTRL_SSBD_SHIFT);
53 return (tifn & _TIF_SSBD) >> (TIF_SSBD - SPEC_CTRL_SSBD_SHIFT);
54}
55
56static inline unsigned long ssbd_spec_ctrl_to_tif(u64 spec_ctrl)
57{
58 BUILD_BUG_ON(TIF_SSBD < SPEC_CTRL_SSBD_SHIFT);
59 return (spec_ctrl & SPEC_CTRL_SSBD) << (TIF_SSBD - SPEC_CTRL_SSBD_SHIFT);
60}
61
62static inline u64 ssbd_tif_to_amd_ls_cfg(u64 tifn)
63{
64 return (tifn & _TIF_SSBD) ? x86_amd_ls_cfg_ssbd_mask : 0ULL;
65}
66
67#ifdef CONFIG_SMP
68extern void speculative_store_bypass_ht_init(void);
69#else
70static inline void speculative_store_bypass_ht_init(void) { }
71#endif
72
73extern void speculative_store_bypass_update(unsigned long tif);
74
75static inline void speculative_store_bypass_update_current(void)
76{
77 speculative_store_bypass_update(current_thread_info()->flags);
78}
79
80#endif
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index a5d9521bb2cb..2ff2a30a264f 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -79,6 +79,7 @@ struct thread_info {
79#define TIF_SIGPENDING 2 /* signal pending */ 79#define TIF_SIGPENDING 2 /* signal pending */
80#define TIF_NEED_RESCHED 3 /* rescheduling necessary */ 80#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
81#define TIF_SINGLESTEP 4 /* reenable singlestep on user return*/ 81#define TIF_SINGLESTEP 4 /* reenable singlestep on user return*/
82#define TIF_SSBD 5 /* Reduced data speculation */
82#define TIF_SYSCALL_EMU 6 /* syscall emulation active */ 83#define TIF_SYSCALL_EMU 6 /* syscall emulation active */
83#define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */ 84#define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
84#define TIF_SECCOMP 8 /* secure computing */ 85#define TIF_SECCOMP 8 /* secure computing */
@@ -105,6 +106,7 @@ struct thread_info {
105#define _TIF_SIGPENDING (1 << TIF_SIGPENDING) 106#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
106#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED) 107#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
107#define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP) 108#define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP)
109#define _TIF_SSBD (1 << TIF_SSBD)
108#define _TIF_SYSCALL_EMU (1 << TIF_SYSCALL_EMU) 110#define _TIF_SYSCALL_EMU (1 << TIF_SYSCALL_EMU)
109#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT) 111#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
110#define _TIF_SECCOMP (1 << TIF_SECCOMP) 112#define _TIF_SECCOMP (1 << TIF_SECCOMP)
@@ -144,7 +146,7 @@ struct thread_info {
144 146
145/* flags to check in __switch_to() */ 147/* flags to check in __switch_to() */
146#define _TIF_WORK_CTXSW \ 148#define _TIF_WORK_CTXSW \
147 (_TIF_IO_BITMAP|_TIF_NOCPUID|_TIF_NOTSC|_TIF_BLOCKSTEP) 149 (_TIF_IO_BITMAP|_TIF_NOCPUID|_TIF_NOTSC|_TIF_BLOCKSTEP|_TIF_SSBD)
148 150
149#define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY) 151#define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
150#define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW) 152#define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index 12bc0a1139da..1b18be3f35a8 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -10,6 +10,7 @@
10#include <asm/processor.h> 10#include <asm/processor.h>
11#include <asm/apic.h> 11#include <asm/apic.h>
12#include <asm/cpu.h> 12#include <asm/cpu.h>
13#include <asm/spec-ctrl.h>
13#include <asm/smp.h> 14#include <asm/smp.h>
14#include <asm/pci-direct.h> 15#include <asm/pci-direct.h>
15#include <asm/delay.h> 16#include <asm/delay.h>
@@ -554,6 +555,26 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)
554 rdmsrl(MSR_FAM10H_NODE_ID, value); 555 rdmsrl(MSR_FAM10H_NODE_ID, value);
555 nodes_per_socket = ((value >> 3) & 7) + 1; 556 nodes_per_socket = ((value >> 3) & 7) + 1;
556 } 557 }
558
559 if (c->x86 >= 0x15 && c->x86 <= 0x17) {
560 unsigned int bit;
561
562 switch (c->x86) {
563 case 0x15: bit = 54; break;
564 case 0x16: bit = 33; break;
565 case 0x17: bit = 10; break;
566 default: return;
567 }
568 /*
569 * Try to cache the base value so further operations can
570 * avoid RMW. If that faults, do not enable SSBD.
571 */
572 if (!rdmsrl_safe(MSR_AMD64_LS_CFG, &x86_amd_ls_cfg_base)) {
573 setup_force_cpu_cap(X86_FEATURE_LS_CFG_SSBD);
574 setup_force_cpu_cap(X86_FEATURE_SSBD);
575 x86_amd_ls_cfg_ssbd_mask = 1ULL << bit;
576 }
577 }
557} 578}
558 579
559static void early_detect_mem_encrypt(struct cpuinfo_x86 *c) 580static void early_detect_mem_encrypt(struct cpuinfo_x86 *c)
@@ -791,6 +812,7 @@ static void init_amd_bd(struct cpuinfo_x86 *c)
791 812
792static void init_amd_zn(struct cpuinfo_x86 *c) 813static void init_amd_zn(struct cpuinfo_x86 *c)
793{ 814{
815 set_cpu_cap(c, X86_FEATURE_ZEN);
794 /* 816 /*
795 * Fix erratum 1076: CPB feature bit not being set in CPUID. It affects 817 * Fix erratum 1076: CPB feature bit not being set in CPUID. It affects
796 * all up to and including B1. 818 * all up to and including B1.
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index bfca937bdcc3..7416fc206b4a 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -12,8 +12,10 @@
12#include <linux/utsname.h> 12#include <linux/utsname.h>
13#include <linux/cpu.h> 13#include <linux/cpu.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/nospec.h>
16#include <linux/prctl.h>
15 17
16#include <asm/nospec-branch.h> 18#include <asm/spec-ctrl.h>
17#include <asm/cmdline.h> 19#include <asm/cmdline.h>
18#include <asm/bugs.h> 20#include <asm/bugs.h>
19#include <asm/processor.h> 21#include <asm/processor.h>
@@ -27,6 +29,27 @@
27#include <asm/intel-family.h> 29#include <asm/intel-family.h>
28 30
29static void __init spectre_v2_select_mitigation(void); 31static void __init spectre_v2_select_mitigation(void);
32static void __init ssb_select_mitigation(void);
33
34/*
35 * Our boot-time value of the SPEC_CTRL MSR. We read it once so that any
36 * writes to SPEC_CTRL contain whatever reserved bits have been set.
37 */
38u64 __ro_after_init x86_spec_ctrl_base;
39EXPORT_SYMBOL_GPL(x86_spec_ctrl_base);
40
41/*
42 * The vendor and possibly platform specific bits which can be modified in
43 * x86_spec_ctrl_base.
44 */
45static u64 __ro_after_init x86_spec_ctrl_mask = SPEC_CTRL_IBRS;
46
47/*
48 * AMD specific MSR info for Speculative Store Bypass control.
49 * x86_amd_ls_cfg_ssbd_mask is initialized in identify_boot_cpu().
50 */
51u64 __ro_after_init x86_amd_ls_cfg_base;
52u64 __ro_after_init x86_amd_ls_cfg_ssbd_mask;
30 53
31void __init check_bugs(void) 54void __init check_bugs(void)
32{ 55{
@@ -37,9 +60,27 @@ void __init check_bugs(void)
37 print_cpu_info(&boot_cpu_data); 60 print_cpu_info(&boot_cpu_data);
38 } 61 }
39 62
63 /*
64 * Read the SPEC_CTRL MSR to account for reserved bits which may
65 * have unknown values. AMD64_LS_CFG MSR is cached in the early AMD
66 * init code as it is not enumerated and depends on the family.
67 */
68 if (boot_cpu_has(X86_FEATURE_MSR_SPEC_CTRL))
69 rdmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);
70
71 /* Allow STIBP in MSR_SPEC_CTRL if supported */
72 if (boot_cpu_has(X86_FEATURE_STIBP))
73 x86_spec_ctrl_mask |= SPEC_CTRL_STIBP;
74
40 /* Select the proper spectre mitigation before patching alternatives */ 75 /* Select the proper spectre mitigation before patching alternatives */
41 spectre_v2_select_mitigation(); 76 spectre_v2_select_mitigation();
42 77
78 /*
79 * Select proper mitigation for any exposure to the Speculative Store
80 * Bypass vulnerability.
81 */
82 ssb_select_mitigation();
83
43#ifdef CONFIG_X86_32 84#ifdef CONFIG_X86_32
44 /* 85 /*
45 * Check whether we are able to run this kernel safely on SMP. 86 * Check whether we are able to run this kernel safely on SMP.
@@ -93,7 +134,76 @@ static const char *spectre_v2_strings[] = {
93#undef pr_fmt 134#undef pr_fmt
94#define pr_fmt(fmt) "Spectre V2 : " fmt 135#define pr_fmt(fmt) "Spectre V2 : " fmt
95 136
96static enum spectre_v2_mitigation spectre_v2_enabled = SPECTRE_V2_NONE; 137static enum spectre_v2_mitigation spectre_v2_enabled __ro_after_init =
138 SPECTRE_V2_NONE;
139
140void
141x86_virt_spec_ctrl(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl, bool setguest)
142{
143 u64 msrval, guestval, hostval = x86_spec_ctrl_base;
144 struct thread_info *ti = current_thread_info();
145
146 /* Is MSR_SPEC_CTRL implemented ? */
147 if (static_cpu_has(X86_FEATURE_MSR_SPEC_CTRL)) {
148 /*
149 * Restrict guest_spec_ctrl to supported values. Clear the
150 * modifiable bits in the host base value and or the
151 * modifiable bits from the guest value.
152 */
153 guestval = hostval & ~x86_spec_ctrl_mask;
154 guestval |= guest_spec_ctrl & x86_spec_ctrl_mask;
155
156 /* SSBD controlled in MSR_SPEC_CTRL */
157 if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD))
158 hostval |= ssbd_tif_to_spec_ctrl(ti->flags);
159
160 if (hostval != guestval) {
161 msrval = setguest ? guestval : hostval;
162 wrmsrl(MSR_IA32_SPEC_CTRL, msrval);
163 }
164 }
165
166 /*
167 * If SSBD is not handled in MSR_SPEC_CTRL on AMD, update
168 * MSR_AMD64_L2_CFG or MSR_VIRT_SPEC_CTRL if supported.
169 */
170 if (!static_cpu_has(X86_FEATURE_LS_CFG_SSBD) &&
171 !static_cpu_has(X86_FEATURE_VIRT_SSBD))
172 return;
173
174 /*
175 * If the host has SSBD mitigation enabled, force it in the host's
176 * virtual MSR value. If its not permanently enabled, evaluate
177 * current's TIF_SSBD thread flag.
178 */
179 if (static_cpu_has(X86_FEATURE_SPEC_STORE_BYPASS_DISABLE))
180 hostval = SPEC_CTRL_SSBD;
181 else
182 hostval = ssbd_tif_to_spec_ctrl(ti->flags);
183
184 /* Sanitize the guest value */
185 guestval = guest_virt_spec_ctrl & SPEC_CTRL_SSBD;
186
187 if (hostval != guestval) {
188 unsigned long tif;
189
190 tif = setguest ? ssbd_spec_ctrl_to_tif(guestval) :
191 ssbd_spec_ctrl_to_tif(hostval);
192
193 speculative_store_bypass_update(tif);
194 }
195}
196EXPORT_SYMBOL_GPL(x86_virt_spec_ctrl);
197
198static void x86_amd_ssb_disable(void)
199{
200 u64 msrval = x86_amd_ls_cfg_base | x86_amd_ls_cfg_ssbd_mask;
201
202 if (boot_cpu_has(X86_FEATURE_VIRT_SSBD))
203 wrmsrl(MSR_AMD64_VIRT_SPEC_CTRL, SPEC_CTRL_SSBD);
204 else if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD))
205 wrmsrl(MSR_AMD64_LS_CFG, msrval);
206}
97 207
98#ifdef RETPOLINE 208#ifdef RETPOLINE
99static bool spectre_v2_bad_module; 209static bool spectre_v2_bad_module;
@@ -312,32 +422,289 @@ retpoline_auto:
312} 422}
313 423
314#undef pr_fmt 424#undef pr_fmt
425#define pr_fmt(fmt) "Speculative Store Bypass: " fmt
426
427static enum ssb_mitigation ssb_mode __ro_after_init = SPEC_STORE_BYPASS_NONE;
428
429/* The kernel command line selection */
430enum ssb_mitigation_cmd {
431 SPEC_STORE_BYPASS_CMD_NONE,
432 SPEC_STORE_BYPASS_CMD_AUTO,
433 SPEC_STORE_BYPASS_CMD_ON,
434 SPEC_STORE_BYPASS_CMD_PRCTL,
435 SPEC_STORE_BYPASS_CMD_SECCOMP,
436};
437
438static const char *ssb_strings[] = {
439 [SPEC_STORE_BYPASS_NONE] = "Vulnerable",
440 [SPEC_STORE_BYPASS_DISABLE] = "Mitigation: Speculative Store Bypass disabled",
441 [SPEC_STORE_BYPASS_PRCTL] = "Mitigation: Speculative Store Bypass disabled via prctl",
442 [SPEC_STORE_BYPASS_SECCOMP] = "Mitigation: Speculative Store Bypass disabled via prctl and seccomp",
443};
444
445static const struct {
446 const char *option;
447 enum ssb_mitigation_cmd cmd;
448} ssb_mitigation_options[] = {
449 { "auto", SPEC_STORE_BYPASS_CMD_AUTO }, /* Platform decides */
450 { "on", SPEC_STORE_BYPASS_CMD_ON }, /* Disable Speculative Store Bypass */
451 { "off", SPEC_STORE_BYPASS_CMD_NONE }, /* Don't touch Speculative Store Bypass */
452 { "prctl", SPEC_STORE_BYPASS_CMD_PRCTL }, /* Disable Speculative Store Bypass via prctl */
453 { "seccomp", SPEC_STORE_BYPASS_CMD_SECCOMP }, /* Disable Speculative Store Bypass via prctl and seccomp */
454};
455
456static enum ssb_mitigation_cmd __init ssb_parse_cmdline(void)
457{
458 enum ssb_mitigation_cmd cmd = SPEC_STORE_BYPASS_CMD_AUTO;
459 char arg[20];
460 int ret, i;
461
462 if (cmdline_find_option_bool(boot_command_line, "nospec_store_bypass_disable")) {
463 return SPEC_STORE_BYPASS_CMD_NONE;
464 } else {
465 ret = cmdline_find_option(boot_command_line, "spec_store_bypass_disable",
466 arg, sizeof(arg));
467 if (ret < 0)
468 return SPEC_STORE_BYPASS_CMD_AUTO;
469
470 for (i = 0; i < ARRAY_SIZE(ssb_mitigation_options); i++) {
471 if (!match_option(arg, ret, ssb_mitigation_options[i].option))
472 continue;
473
474 cmd = ssb_mitigation_options[i].cmd;
475 break;
476 }
477
478 if (i >= ARRAY_SIZE(ssb_mitigation_options)) {
479 pr_err("unknown option (%s). Switching to AUTO select\n", arg);
480 return SPEC_STORE_BYPASS_CMD_AUTO;
481 }
482 }
483
484 return cmd;
485}
486
487static enum ssb_mitigation __init __ssb_select_mitigation(void)
488{
489 enum ssb_mitigation mode = SPEC_STORE_BYPASS_NONE;
490 enum ssb_mitigation_cmd cmd;
491
492 if (!boot_cpu_has(X86_FEATURE_SSBD))
493 return mode;
494
495 cmd = ssb_parse_cmdline();
496 if (!boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS) &&
497 (cmd == SPEC_STORE_BYPASS_CMD_NONE ||
498 cmd == SPEC_STORE_BYPASS_CMD_AUTO))
499 return mode;
500
501 switch (cmd) {
502 case SPEC_STORE_BYPASS_CMD_AUTO:
503 case SPEC_STORE_BYPASS_CMD_SECCOMP:
504 /*
505 * Choose prctl+seccomp as the default mode if seccomp is
506 * enabled.
507 */
508 if (IS_ENABLED(CONFIG_SECCOMP))
509 mode = SPEC_STORE_BYPASS_SECCOMP;
510 else
511 mode = SPEC_STORE_BYPASS_PRCTL;
512 break;
513 case SPEC_STORE_BYPASS_CMD_ON:
514 mode = SPEC_STORE_BYPASS_DISABLE;
515 break;
516 case SPEC_STORE_BYPASS_CMD_PRCTL:
517 mode = SPEC_STORE_BYPASS_PRCTL;
518 break;
519 case SPEC_STORE_BYPASS_CMD_NONE:
520 break;
521 }
522
523 /*
524 * We have three CPU feature flags that are in play here:
525 * - X86_BUG_SPEC_STORE_BYPASS - CPU is susceptible.
526 * - X86_FEATURE_SSBD - CPU is able to turn off speculative store bypass
527 * - X86_FEATURE_SPEC_STORE_BYPASS_DISABLE - engage the mitigation
528 */
529 if (mode == SPEC_STORE_BYPASS_DISABLE) {
530 setup_force_cpu_cap(X86_FEATURE_SPEC_STORE_BYPASS_DISABLE);
531 /*
532 * Intel uses the SPEC CTRL MSR Bit(2) for this, while AMD uses
533 * a completely different MSR and bit dependent on family.
534 */
535 switch (boot_cpu_data.x86_vendor) {
536 case X86_VENDOR_INTEL:
537 x86_spec_ctrl_base |= SPEC_CTRL_SSBD;
538 x86_spec_ctrl_mask |= SPEC_CTRL_SSBD;
539 wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);
540 break;
541 case X86_VENDOR_AMD:
542 x86_amd_ssb_disable();
543 break;
544 }
545 }
546
547 return mode;
548}
549
550static void ssb_select_mitigation(void)
551{
552 ssb_mode = __ssb_select_mitigation();
553
554 if (boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS))
555 pr_info("%s\n", ssb_strings[ssb_mode]);
556}
557
558#undef pr_fmt
559#define pr_fmt(fmt) "Speculation prctl: " fmt
560
561static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl)
562{
563 bool update;
564
565 if (ssb_mode != SPEC_STORE_BYPASS_PRCTL &&
566 ssb_mode != SPEC_STORE_BYPASS_SECCOMP)
567 return -ENXIO;
568
569 switch (ctrl) {
570 case PR_SPEC_ENABLE:
571 /* If speculation is force disabled, enable is not allowed */
572 if (task_spec_ssb_force_disable(task))
573 return -EPERM;
574 task_clear_spec_ssb_disable(task);
575 update = test_and_clear_tsk_thread_flag(task, TIF_SSBD);
576 break;
577 case PR_SPEC_DISABLE:
578 task_set_spec_ssb_disable(task);
579 update = !test_and_set_tsk_thread_flag(task, TIF_SSBD);
580 break;
581 case PR_SPEC_FORCE_DISABLE:
582 task_set_spec_ssb_disable(task);
583 task_set_spec_ssb_force_disable(task);
584 update = !test_and_set_tsk_thread_flag(task, TIF_SSBD);
585 break;
586 default:
587 return -ERANGE;
588 }
589
590 /*
591 * If being set on non-current task, delay setting the CPU
592 * mitigation until it is next scheduled.
593 */
594 if (task == current && update)
595 speculative_store_bypass_update_current();
596
597 return 0;
598}
599
600int arch_prctl_spec_ctrl_set(struct task_struct *task, unsigned long which,
601 unsigned long ctrl)
602{
603 switch (which) {
604 case PR_SPEC_STORE_BYPASS:
605 return ssb_prctl_set(task, ctrl);
606 default:
607 return -ENODEV;
608 }
609}
610
611#ifdef CONFIG_SECCOMP
612void arch_seccomp_spec_mitigate(struct task_struct *task)
613{
614 if (ssb_mode == SPEC_STORE_BYPASS_SECCOMP)
615 ssb_prctl_set(task, PR_SPEC_FORCE_DISABLE);
616}
617#endif
618
619static int ssb_prctl_get(struct task_struct *task)
620{
621 switch (ssb_mode) {
622 case SPEC_STORE_BYPASS_DISABLE:
623 return PR_SPEC_DISABLE;
624 case SPEC_STORE_BYPASS_SECCOMP:
625 case SPEC_STORE_BYPASS_PRCTL:
626 if (task_spec_ssb_force_disable(task))
627 return PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE;
628 if (task_spec_ssb_disable(task))
629 return PR_SPEC_PRCTL | PR_SPEC_DISABLE;
630 return PR_SPEC_PRCTL | PR_SPEC_ENABLE;
631 default:
632 if (boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS))
633 return PR_SPEC_ENABLE;
634 return PR_SPEC_NOT_AFFECTED;
635 }
636}
637
638int arch_prctl_spec_ctrl_get(struct task_struct *task, unsigned long which)
639{
640 switch (which) {
641 case PR_SPEC_STORE_BYPASS:
642 return ssb_prctl_get(task);
643 default:
644 return -ENODEV;
645 }
646}
647
648void x86_spec_ctrl_setup_ap(void)
649{
650 if (boot_cpu_has(X86_FEATURE_MSR_SPEC_CTRL))
651 wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);
652
653 if (ssb_mode == SPEC_STORE_BYPASS_DISABLE)
654 x86_amd_ssb_disable();
655}
315 656
316#ifdef CONFIG_SYSFS 657#ifdef CONFIG_SYSFS
317ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf) 658
659static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr,
660 char *buf, unsigned int bug)
318{ 661{
319 if (!boot_cpu_has_bug(X86_BUG_CPU_MELTDOWN)) 662 if (!boot_cpu_has_bug(bug))
320 return sprintf(buf, "Not affected\n"); 663 return sprintf(buf, "Not affected\n");
321 if (boot_cpu_has(X86_FEATURE_PTI)) 664
322 return sprintf(buf, "Mitigation: PTI\n"); 665 switch (bug) {
666 case X86_BUG_CPU_MELTDOWN:
667 if (boot_cpu_has(X86_FEATURE_PTI))
668 return sprintf(buf, "Mitigation: PTI\n");
669
670 break;
671
672 case X86_BUG_SPECTRE_V1:
673 return sprintf(buf, "Mitigation: __user pointer sanitization\n");
674
675 case X86_BUG_SPECTRE_V2:
676 return sprintf(buf, "%s%s%s%s\n", spectre_v2_strings[spectre_v2_enabled],
677 boot_cpu_has(X86_FEATURE_USE_IBPB) ? ", IBPB" : "",
678 boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ? ", IBRS_FW" : "",
679 spectre_v2_module_string());
680
681 case X86_BUG_SPEC_STORE_BYPASS:
682 return sprintf(buf, "%s\n", ssb_strings[ssb_mode]);
683
684 default:
685 break;
686 }
687
323 return sprintf(buf, "Vulnerable\n"); 688 return sprintf(buf, "Vulnerable\n");
324} 689}
325 690
691ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf)
692{
693 return cpu_show_common(dev, attr, buf, X86_BUG_CPU_MELTDOWN);
694}
695
326ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, char *buf) 696ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, char *buf)
327{ 697{
328 if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V1)) 698 return cpu_show_common(dev, attr, buf, X86_BUG_SPECTRE_V1);
329 return sprintf(buf, "Not affected\n");
330 return sprintf(buf, "Mitigation: __user pointer sanitization\n");
331} 699}
332 700
333ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, char *buf) 701ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, char *buf)
334{ 702{
335 if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2)) 703 return cpu_show_common(dev, attr, buf, X86_BUG_SPECTRE_V2);
336 return sprintf(buf, "Not affected\n"); 704}
337 705
338 return sprintf(buf, "%s%s%s%s\n", spectre_v2_strings[spectre_v2_enabled], 706ssize_t cpu_show_spec_store_bypass(struct device *dev, struct device_attribute *attr, char *buf)
339 boot_cpu_has(X86_FEATURE_USE_IBPB) ? ", IBPB" : "", 707{
340 boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ? ", IBRS_FW" : "", 708 return cpu_show_common(dev, attr, buf, X86_BUG_SPEC_STORE_BYPASS);
341 spectre_v2_module_string());
342} 709}
343#endif 710#endif
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index ce243f7d2d4e..38276f58d3bf 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -757,17 +757,32 @@ static void init_speculation_control(struct cpuinfo_x86 *c)
757 * and they also have a different bit for STIBP support. Also, 757 * and they also have a different bit for STIBP support. Also,
758 * a hypervisor might have set the individual AMD bits even on 758 * a hypervisor might have set the individual AMD bits even on
759 * Intel CPUs, for finer-grained selection of what's available. 759 * Intel CPUs, for finer-grained selection of what's available.
760 *
761 * We use the AMD bits in 0x8000_0008 EBX as the generic hardware
762 * features, which are visible in /proc/cpuinfo and used by the
763 * kernel. So set those accordingly from the Intel bits.
764 */ 760 */
765 if (cpu_has(c, X86_FEATURE_SPEC_CTRL)) { 761 if (cpu_has(c, X86_FEATURE_SPEC_CTRL)) {
766 set_cpu_cap(c, X86_FEATURE_IBRS); 762 set_cpu_cap(c, X86_FEATURE_IBRS);
767 set_cpu_cap(c, X86_FEATURE_IBPB); 763 set_cpu_cap(c, X86_FEATURE_IBPB);
764 set_cpu_cap(c, X86_FEATURE_MSR_SPEC_CTRL);
768 } 765 }
766
769 if (cpu_has(c, X86_FEATURE_INTEL_STIBP)) 767 if (cpu_has(c, X86_FEATURE_INTEL_STIBP))
770 set_cpu_cap(c, X86_FEATURE_STIBP); 768 set_cpu_cap(c, X86_FEATURE_STIBP);
769
770 if (cpu_has(c, X86_FEATURE_SPEC_CTRL_SSBD) ||
771 cpu_has(c, X86_FEATURE_VIRT_SSBD))
772 set_cpu_cap(c, X86_FEATURE_SSBD);
773
774 if (cpu_has(c, X86_FEATURE_AMD_IBRS)) {
775 set_cpu_cap(c, X86_FEATURE_IBRS);
776 set_cpu_cap(c, X86_FEATURE_MSR_SPEC_CTRL);
777 }
778
779 if (cpu_has(c, X86_FEATURE_AMD_IBPB))
780 set_cpu_cap(c, X86_FEATURE_IBPB);
781
782 if (cpu_has(c, X86_FEATURE_AMD_STIBP)) {
783 set_cpu_cap(c, X86_FEATURE_STIBP);
784 set_cpu_cap(c, X86_FEATURE_MSR_SPEC_CTRL);
785 }
771} 786}
772 787
773void get_cpu_cap(struct cpuinfo_x86 *c) 788void get_cpu_cap(struct cpuinfo_x86 *c)
@@ -927,21 +942,47 @@ static const __initconst struct x86_cpu_id cpu_no_meltdown[] = {
927 {} 942 {}
928}; 943};
929 944
930static bool __init cpu_vulnerable_to_meltdown(struct cpuinfo_x86 *c) 945/* Only list CPUs which speculate but are non susceptible to SSB */
946static const __initconst struct x86_cpu_id cpu_no_spec_store_bypass[] = {
947 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT1 },
948 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_AIRMONT },
949 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT2 },
950 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_MERRIFIELD },
951 { X86_VENDOR_INTEL, 6, INTEL_FAM6_CORE_YONAH },
952 { X86_VENDOR_INTEL, 6, INTEL_FAM6_XEON_PHI_KNL },
953 { X86_VENDOR_INTEL, 6, INTEL_FAM6_XEON_PHI_KNM },
954 { X86_VENDOR_AMD, 0x12, },
955 { X86_VENDOR_AMD, 0x11, },
956 { X86_VENDOR_AMD, 0x10, },
957 { X86_VENDOR_AMD, 0xf, },
958 {}
959};
960
961static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c)
931{ 962{
932 u64 ia32_cap = 0; 963 u64 ia32_cap = 0;
933 964
934 if (x86_match_cpu(cpu_no_meltdown)) 965 if (x86_match_cpu(cpu_no_speculation))
935 return false; 966 return;
967
968 setup_force_cpu_bug(X86_BUG_SPECTRE_V1);
969 setup_force_cpu_bug(X86_BUG_SPECTRE_V2);
936 970
937 if (cpu_has(c, X86_FEATURE_ARCH_CAPABILITIES)) 971 if (cpu_has(c, X86_FEATURE_ARCH_CAPABILITIES))
938 rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap); 972 rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap);
939 973
974 if (!x86_match_cpu(cpu_no_spec_store_bypass) &&
975 !(ia32_cap & ARCH_CAP_SSB_NO))
976 setup_force_cpu_bug(X86_BUG_SPEC_STORE_BYPASS);
977
978 if (x86_match_cpu(cpu_no_meltdown))
979 return;
980
940 /* Rogue Data Cache Load? No! */ 981 /* Rogue Data Cache Load? No! */
941 if (ia32_cap & ARCH_CAP_RDCL_NO) 982 if (ia32_cap & ARCH_CAP_RDCL_NO)
942 return false; 983 return;
943 984
944 return true; 985 setup_force_cpu_bug(X86_BUG_CPU_MELTDOWN);
945} 986}
946 987
947/* 988/*
@@ -992,12 +1033,7 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)
992 1033
993 setup_force_cpu_cap(X86_FEATURE_ALWAYS); 1034 setup_force_cpu_cap(X86_FEATURE_ALWAYS);
994 1035
995 if (!x86_match_cpu(cpu_no_speculation)) { 1036 cpu_set_bug_bits(c);
996 if (cpu_vulnerable_to_meltdown(c))
997 setup_force_cpu_bug(X86_BUG_CPU_MELTDOWN);
998 setup_force_cpu_bug(X86_BUG_SPECTRE_V1);
999 setup_force_cpu_bug(X86_BUG_SPECTRE_V2);
1000 }
1001 1037
1002 fpu__init_system(c); 1038 fpu__init_system(c);
1003 1039
@@ -1359,6 +1395,7 @@ void identify_secondary_cpu(struct cpuinfo_x86 *c)
1359#endif 1395#endif
1360 mtrr_ap_init(); 1396 mtrr_ap_init();
1361 validate_apic_and_package_id(c); 1397 validate_apic_and_package_id(c);
1398 x86_spec_ctrl_setup_ap();
1362} 1399}
1363 1400
1364static __init int setup_noclflush(char *arg) 1401static __init int setup_noclflush(char *arg)
diff --git a/arch/x86/kernel/cpu/cpu.h b/arch/x86/kernel/cpu/cpu.h
index e806b11a99af..37672d299e35 100644
--- a/arch/x86/kernel/cpu/cpu.h
+++ b/arch/x86/kernel/cpu/cpu.h
@@ -50,4 +50,6 @@ extern void cpu_detect_cache_sizes(struct cpuinfo_x86 *c);
50 50
51unsigned int aperfmperf_get_khz(int cpu); 51unsigned int aperfmperf_get_khz(int cpu);
52 52
53extern void x86_spec_ctrl_setup_ap(void);
54
53#endif /* ARCH_X86_CPU_H */ 55#endif /* ARCH_X86_CPU_H */
diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
index 60d1897041da..577e7f7ae273 100644
--- a/arch/x86/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
@@ -188,7 +188,10 @@ static void early_init_intel(struct cpuinfo_x86 *c)
188 setup_clear_cpu_cap(X86_FEATURE_IBPB); 188 setup_clear_cpu_cap(X86_FEATURE_IBPB);
189 setup_clear_cpu_cap(X86_FEATURE_STIBP); 189 setup_clear_cpu_cap(X86_FEATURE_STIBP);
190 setup_clear_cpu_cap(X86_FEATURE_SPEC_CTRL); 190 setup_clear_cpu_cap(X86_FEATURE_SPEC_CTRL);
191 setup_clear_cpu_cap(X86_FEATURE_MSR_SPEC_CTRL);
191 setup_clear_cpu_cap(X86_FEATURE_INTEL_STIBP); 192 setup_clear_cpu_cap(X86_FEATURE_INTEL_STIBP);
193 setup_clear_cpu_cap(X86_FEATURE_SSBD);
194 setup_clear_cpu_cap(X86_FEATURE_SPEC_CTRL_SSBD);
192 } 195 }
193 196
194 /* 197 /*
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 03408b942adb..30ca2d1a9231 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -38,6 +38,7 @@
38#include <asm/switch_to.h> 38#include <asm/switch_to.h>
39#include <asm/desc.h> 39#include <asm/desc.h>
40#include <asm/prctl.h> 40#include <asm/prctl.h>
41#include <asm/spec-ctrl.h>
41 42
42/* 43/*
43 * per-CPU TSS segments. Threads are completely 'soft' on Linux, 44 * per-CPU TSS segments. Threads are completely 'soft' on Linux,
@@ -278,6 +279,148 @@ static inline void switch_to_bitmap(struct tss_struct *tss,
278 } 279 }
279} 280}
280 281
282#ifdef CONFIG_SMP
283
284struct ssb_state {
285 struct ssb_state *shared_state;
286 raw_spinlock_t lock;
287 unsigned int disable_state;
288 unsigned long local_state;
289};
290
291#define LSTATE_SSB 0
292
293static DEFINE_PER_CPU(struct ssb_state, ssb_state);
294
295void speculative_store_bypass_ht_init(void)
296{
297 struct ssb_state *st = this_cpu_ptr(&ssb_state);
298 unsigned int this_cpu = smp_processor_id();
299 unsigned int cpu;
300
301 st->local_state = 0;
302
303 /*
304 * Shared state setup happens once on the first bringup
305 * of the CPU. It's not destroyed on CPU hotunplug.
306 */
307 if (st->shared_state)
308 return;
309
310 raw_spin_lock_init(&st->lock);
311
312 /*
313 * Go over HT siblings and check whether one of them has set up the
314 * shared state pointer already.
315 */
316 for_each_cpu(cpu, topology_sibling_cpumask(this_cpu)) {
317 if (cpu == this_cpu)
318 continue;
319
320 if (!per_cpu(ssb_state, cpu).shared_state)
321 continue;
322
323 /* Link it to the state of the sibling: */
324 st->shared_state = per_cpu(ssb_state, cpu).shared_state;
325 return;
326 }
327
328 /*
329 * First HT sibling to come up on the core. Link shared state of
330 * the first HT sibling to itself. The siblings on the same core
331 * which come up later will see the shared state pointer and link
332 * themself to the state of this CPU.
333 */
334 st->shared_state = st;
335}
336
337/*
338 * Logic is: First HT sibling enables SSBD for both siblings in the core
339 * and last sibling to disable it, disables it for the whole core. This how
340 * MSR_SPEC_CTRL works in "hardware":
341 *
342 * CORE_SPEC_CTRL = THREAD0_SPEC_CTRL | THREAD1_SPEC_CTRL
343 */
344static __always_inline void amd_set_core_ssb_state(unsigned long tifn)
345{
346 struct ssb_state *st = this_cpu_ptr(&ssb_state);
347 u64 msr = x86_amd_ls_cfg_base;
348
349 if (!static_cpu_has(X86_FEATURE_ZEN)) {
350 msr |= ssbd_tif_to_amd_ls_cfg(tifn);
351 wrmsrl(MSR_AMD64_LS_CFG, msr);
352 return;
353 }
354
355 if (tifn & _TIF_SSBD) {
356 /*
357 * Since this can race with prctl(), block reentry on the
358 * same CPU.
359 */
360 if (__test_and_set_bit(LSTATE_SSB, &st->local_state))
361 return;
362
363 msr |= x86_amd_ls_cfg_ssbd_mask;
364
365 raw_spin_lock(&st->shared_state->lock);
366 /* First sibling enables SSBD: */
367 if (!st->shared_state->disable_state)
368 wrmsrl(MSR_AMD64_LS_CFG, msr);
369 st->shared_state->disable_state++;
370 raw_spin_unlock(&st->shared_state->lock);
371 } else {
372 if (!__test_and_clear_bit(LSTATE_SSB, &st->local_state))
373 return;
374
375 raw_spin_lock(&st->shared_state->lock);
376 st->shared_state->disable_state--;
377 if (!st->shared_state->disable_state)
378 wrmsrl(MSR_AMD64_LS_CFG, msr);
379 raw_spin_unlock(&st->shared_state->lock);
380 }
381}
382#else
383static __always_inline void amd_set_core_ssb_state(unsigned long tifn)
384{
385 u64 msr = x86_amd_ls_cfg_base | ssbd_tif_to_amd_ls_cfg(tifn);
386
387 wrmsrl(MSR_AMD64_LS_CFG, msr);
388}
389#endif
390
391static __always_inline void amd_set_ssb_virt_state(unsigned long tifn)
392{
393 /*
394 * SSBD has the same definition in SPEC_CTRL and VIRT_SPEC_CTRL,
395 * so ssbd_tif_to_spec_ctrl() just works.
396 */
397 wrmsrl(MSR_AMD64_VIRT_SPEC_CTRL, ssbd_tif_to_spec_ctrl(tifn));
398}
399
400static __always_inline void intel_set_ssb_state(unsigned long tifn)
401{
402 u64 msr = x86_spec_ctrl_base | ssbd_tif_to_spec_ctrl(tifn);
403
404 wrmsrl(MSR_IA32_SPEC_CTRL, msr);
405}
406
407static __always_inline void __speculative_store_bypass_update(unsigned long tifn)
408{
409 if (static_cpu_has(X86_FEATURE_VIRT_SSBD))
410 amd_set_ssb_virt_state(tifn);
411 else if (static_cpu_has(X86_FEATURE_LS_CFG_SSBD))
412 amd_set_core_ssb_state(tifn);
413 else
414 intel_set_ssb_state(tifn);
415}
416
417void speculative_store_bypass_update(unsigned long tif)
418{
419 preempt_disable();
420 __speculative_store_bypass_update(tif);
421 preempt_enable();
422}
423
281void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p, 424void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,
282 struct tss_struct *tss) 425 struct tss_struct *tss)
283{ 426{
@@ -309,6 +452,9 @@ void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,
309 452
310 if ((tifp ^ tifn) & _TIF_NOCPUID) 453 if ((tifp ^ tifn) & _TIF_NOCPUID)
311 set_cpuid_faulting(!!(tifn & _TIF_NOCPUID)); 454 set_cpuid_faulting(!!(tifn & _TIF_NOCPUID));
455
456 if ((tifp ^ tifn) & _TIF_SSBD)
457 __speculative_store_bypass_update(tifn);
312} 458}
313 459
314/* 460/*
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 0f1cbb042f49..9dd324ae4832 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -79,6 +79,7 @@
79#include <asm/qspinlock.h> 79#include <asm/qspinlock.h>
80#include <asm/intel-family.h> 80#include <asm/intel-family.h>
81#include <asm/cpu_device_id.h> 81#include <asm/cpu_device_id.h>
82#include <asm/spec-ctrl.h>
82 83
83/* Number of siblings per CPU package */ 84/* Number of siblings per CPU package */
84int smp_num_siblings = 1; 85int smp_num_siblings = 1;
@@ -244,6 +245,8 @@ static void notrace start_secondary(void *unused)
244 */ 245 */
245 check_tsc_sync_target(); 246 check_tsc_sync_target();
246 247
248 speculative_store_bypass_ht_init();
249
247 /* 250 /*
248 * Lock vector_lock, set CPU online and bring the vector 251 * Lock vector_lock, set CPU online and bring the vector
249 * allocator online. Online must be set with vector_lock held 252 * allocator online. Online must be set with vector_lock held
@@ -1292,6 +1295,8 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
1292 set_mtrr_aps_delayed_init(); 1295 set_mtrr_aps_delayed_init();
1293 1296
1294 smp_quirk_init_udelay(); 1297 smp_quirk_init_udelay();
1298
1299 speculative_store_bypass_ht_init();
1295} 1300}
1296 1301
1297void arch_enable_nonboot_cpus_begin(void) 1302void arch_enable_nonboot_cpus_begin(void)
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 82055b90a8b3..92bf2f2e7cdd 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -379,7 +379,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
379 379
380 /* cpuid 0x80000008.ebx */ 380 /* cpuid 0x80000008.ebx */
381 const u32 kvm_cpuid_8000_0008_ebx_x86_features = 381 const u32 kvm_cpuid_8000_0008_ebx_x86_features =
382 F(IBPB) | F(IBRS); 382 F(AMD_IBPB) | F(AMD_IBRS) | F(VIRT_SSBD);
383 383
384 /* cpuid 0xC0000001.edx */ 384 /* cpuid 0xC0000001.edx */
385 const u32 kvm_cpuid_C000_0001_edx_x86_features = 385 const u32 kvm_cpuid_C000_0001_edx_x86_features =
@@ -408,7 +408,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
408 /* cpuid 7.0.edx*/ 408 /* cpuid 7.0.edx*/
409 const u32 kvm_cpuid_7_0_edx_x86_features = 409 const u32 kvm_cpuid_7_0_edx_x86_features =
410 F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) | 410 F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) |
411 F(ARCH_CAPABILITIES); 411 F(SPEC_CTRL_SSBD) | F(ARCH_CAPABILITIES);
412 412
413 /* all calls to cpuid_count() should be made on the same cpu */ 413 /* all calls to cpuid_count() should be made on the same cpu */
414 get_cpu(); 414 get_cpu();
@@ -495,6 +495,11 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
495 entry->ecx &= ~F(PKU); 495 entry->ecx &= ~F(PKU);
496 entry->edx &= kvm_cpuid_7_0_edx_x86_features; 496 entry->edx &= kvm_cpuid_7_0_edx_x86_features;
497 cpuid_mask(&entry->edx, CPUID_7_EDX); 497 cpuid_mask(&entry->edx, CPUID_7_EDX);
498 /*
499 * We emulate ARCH_CAPABILITIES in software even
500 * if the host doesn't support it.
501 */
502 entry->edx |= F(ARCH_CAPABILITIES);
498 } else { 503 } else {
499 entry->ebx = 0; 504 entry->ebx = 0;
500 entry->ecx = 0; 505 entry->ecx = 0;
@@ -647,13 +652,20 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
647 g_phys_as = phys_as; 652 g_phys_as = phys_as;
648 entry->eax = g_phys_as | (virt_as << 8); 653 entry->eax = g_phys_as | (virt_as << 8);
649 entry->edx = 0; 654 entry->edx = 0;
650 /* IBRS and IBPB aren't necessarily present in hardware cpuid */ 655 /*
651 if (boot_cpu_has(X86_FEATURE_IBPB)) 656 * IBRS, IBPB and VIRT_SSBD aren't necessarily present in
652 entry->ebx |= F(IBPB); 657 * hardware cpuid
653 if (boot_cpu_has(X86_FEATURE_IBRS)) 658 */
654 entry->ebx |= F(IBRS); 659 if (boot_cpu_has(X86_FEATURE_AMD_IBPB))
660 entry->ebx |= F(AMD_IBPB);
661 if (boot_cpu_has(X86_FEATURE_AMD_IBRS))
662 entry->ebx |= F(AMD_IBRS);
663 if (boot_cpu_has(X86_FEATURE_VIRT_SSBD))
664 entry->ebx |= F(VIRT_SSBD);
655 entry->ebx &= kvm_cpuid_8000_0008_ebx_x86_features; 665 entry->ebx &= kvm_cpuid_8000_0008_ebx_x86_features;
656 cpuid_mask(&entry->ebx, CPUID_8000_0008_EBX); 666 cpuid_mask(&entry->ebx, CPUID_8000_0008_EBX);
667 if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD))
668 entry->ebx |= F(VIRT_SSBD);
657 break; 669 break;
658 } 670 }
659 case 0x80000019: 671 case 0x80000019:
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 5708e951a5c6..46ff64da44ca 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -1260,14 +1260,18 @@ static void kvm_hv_hypercall_set_result(struct kvm_vcpu *vcpu, u64 result)
1260 } 1260 }
1261} 1261}
1262 1262
1263static int kvm_hv_hypercall_complete_userspace(struct kvm_vcpu *vcpu) 1263static int kvm_hv_hypercall_complete(struct kvm_vcpu *vcpu, u64 result)
1264{ 1264{
1265 struct kvm_run *run = vcpu->run; 1265 kvm_hv_hypercall_set_result(vcpu, result);
1266 1266 ++vcpu->stat.hypercalls;
1267 kvm_hv_hypercall_set_result(vcpu, run->hyperv.u.hcall.result);
1268 return kvm_skip_emulated_instruction(vcpu); 1267 return kvm_skip_emulated_instruction(vcpu);
1269} 1268}
1270 1269
1270static int kvm_hv_hypercall_complete_userspace(struct kvm_vcpu *vcpu)
1271{
1272 return kvm_hv_hypercall_complete(vcpu, vcpu->run->hyperv.u.hcall.result);
1273}
1274
1271static u16 kvm_hvcall_signal_event(struct kvm_vcpu *vcpu, bool fast, u64 param) 1275static u16 kvm_hvcall_signal_event(struct kvm_vcpu *vcpu, bool fast, u64 param)
1272{ 1276{
1273 struct eventfd_ctx *eventfd; 1277 struct eventfd_ctx *eventfd;
@@ -1350,7 +1354,7 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
1350 /* Hypercall continuation is not supported yet */ 1354 /* Hypercall continuation is not supported yet */
1351 if (rep_cnt || rep_idx) { 1355 if (rep_cnt || rep_idx) {
1352 ret = HV_STATUS_INVALID_HYPERCALL_CODE; 1356 ret = HV_STATUS_INVALID_HYPERCALL_CODE;
1353 goto set_result; 1357 goto out;
1354 } 1358 }
1355 1359
1356 switch (code) { 1360 switch (code) {
@@ -1381,9 +1385,8 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
1381 break; 1385 break;
1382 } 1386 }
1383 1387
1384set_result: 1388out:
1385 kvm_hv_hypercall_set_result(vcpu, ret); 1389 return kvm_hv_hypercall_complete(vcpu, ret);
1386 return 1;
1387} 1390}
1388 1391
1389void kvm_hv_init_vm(struct kvm *kvm) 1392void kvm_hv_init_vm(struct kvm *kvm)
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index b74c9c1405b9..3773c4625114 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1522,11 +1522,23 @@ static bool set_target_expiration(struct kvm_lapic *apic)
1522 1522
1523static void advance_periodic_target_expiration(struct kvm_lapic *apic) 1523static void advance_periodic_target_expiration(struct kvm_lapic *apic)
1524{ 1524{
1525 apic->lapic_timer.tscdeadline += 1525 ktime_t now = ktime_get();
1526 nsec_to_cycles(apic->vcpu, apic->lapic_timer.period); 1526 u64 tscl = rdtsc();
1527 ktime_t delta;
1528
1529 /*
1530 * Synchronize both deadlines to the same time source or
1531 * differences in the periods (caused by differences in the
1532 * underlying clocks or numerical approximation errors) will
1533 * cause the two to drift apart over time as the errors
1534 * accumulate.
1535 */
1527 apic->lapic_timer.target_expiration = 1536 apic->lapic_timer.target_expiration =
1528 ktime_add_ns(apic->lapic_timer.target_expiration, 1537 ktime_add_ns(apic->lapic_timer.target_expiration,
1529 apic->lapic_timer.period); 1538 apic->lapic_timer.period);
1539 delta = ktime_sub(apic->lapic_timer.target_expiration, now);
1540 apic->lapic_timer.tscdeadline = kvm_read_l1_tsc(apic->vcpu, tscl) +
1541 nsec_to_cycles(apic->vcpu, delta);
1530} 1542}
1531 1543
1532static void start_sw_period(struct kvm_lapic *apic) 1544static void start_sw_period(struct kvm_lapic *apic)
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 1fc05e428aba..26110c202b19 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -49,7 +49,7 @@
49#include <asm/debugreg.h> 49#include <asm/debugreg.h>
50#include <asm/kvm_para.h> 50#include <asm/kvm_para.h>
51#include <asm/irq_remapping.h> 51#include <asm/irq_remapping.h>
52#include <asm/nospec-branch.h> 52#include <asm/spec-ctrl.h>
53 53
54#include <asm/virtext.h> 54#include <asm/virtext.h>
55#include "trace.h" 55#include "trace.h"
@@ -213,6 +213,12 @@ struct vcpu_svm {
213 } host; 213 } host;
214 214
215 u64 spec_ctrl; 215 u64 spec_ctrl;
216 /*
217 * Contains guest-controlled bits of VIRT_SPEC_CTRL, which will be
218 * translated into the appropriate L2_CFG bits on the host to
219 * perform speculative control.
220 */
221 u64 virt_spec_ctrl;
216 222
217 u32 *msrpm; 223 u32 *msrpm;
218 224
@@ -2060,6 +2066,7 @@ static void svm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
2060 2066
2061 vcpu->arch.microcode_version = 0x01000065; 2067 vcpu->arch.microcode_version = 0x01000065;
2062 svm->spec_ctrl = 0; 2068 svm->spec_ctrl = 0;
2069 svm->virt_spec_ctrl = 0;
2063 2070
2064 if (!init_event) { 2071 if (!init_event) {
2065 svm->vcpu.arch.apic_base = APIC_DEFAULT_PHYS_BASE | 2072 svm->vcpu.arch.apic_base = APIC_DEFAULT_PHYS_BASE |
@@ -4108,11 +4115,18 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
4108 break; 4115 break;
4109 case MSR_IA32_SPEC_CTRL: 4116 case MSR_IA32_SPEC_CTRL:
4110 if (!msr_info->host_initiated && 4117 if (!msr_info->host_initiated &&
4111 !guest_cpuid_has(vcpu, X86_FEATURE_IBRS)) 4118 !guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBRS))
4112 return 1; 4119 return 1;
4113 4120
4114 msr_info->data = svm->spec_ctrl; 4121 msr_info->data = svm->spec_ctrl;
4115 break; 4122 break;
4123 case MSR_AMD64_VIRT_SPEC_CTRL:
4124 if (!msr_info->host_initiated &&
4125 !guest_cpuid_has(vcpu, X86_FEATURE_VIRT_SSBD))
4126 return 1;
4127
4128 msr_info->data = svm->virt_spec_ctrl;
4129 break;
4116 case MSR_F15H_IC_CFG: { 4130 case MSR_F15H_IC_CFG: {
4117 4131
4118 int family, model; 4132 int family, model;
@@ -4203,7 +4217,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
4203 break; 4217 break;
4204 case MSR_IA32_SPEC_CTRL: 4218 case MSR_IA32_SPEC_CTRL:
4205 if (!msr->host_initiated && 4219 if (!msr->host_initiated &&
4206 !guest_cpuid_has(vcpu, X86_FEATURE_IBRS)) 4220 !guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBRS))
4207 return 1; 4221 return 1;
4208 4222
4209 /* The STIBP bit doesn't fault even if it's not advertised */ 4223 /* The STIBP bit doesn't fault even if it's not advertised */
@@ -4230,7 +4244,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
4230 break; 4244 break;
4231 case MSR_IA32_PRED_CMD: 4245 case MSR_IA32_PRED_CMD:
4232 if (!msr->host_initiated && 4246 if (!msr->host_initiated &&
4233 !guest_cpuid_has(vcpu, X86_FEATURE_IBPB)) 4247 !guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBPB))
4234 return 1; 4248 return 1;
4235 4249
4236 if (data & ~PRED_CMD_IBPB) 4250 if (data & ~PRED_CMD_IBPB)
@@ -4244,6 +4258,16 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
4244 break; 4258 break;
4245 set_msr_interception(svm->msrpm, MSR_IA32_PRED_CMD, 0, 1); 4259 set_msr_interception(svm->msrpm, MSR_IA32_PRED_CMD, 0, 1);
4246 break; 4260 break;
4261 case MSR_AMD64_VIRT_SPEC_CTRL:
4262 if (!msr->host_initiated &&
4263 !guest_cpuid_has(vcpu, X86_FEATURE_VIRT_SSBD))
4264 return 1;
4265
4266 if (data & ~SPEC_CTRL_SSBD)
4267 return 1;
4268
4269 svm->virt_spec_ctrl = data;
4270 break;
4247 case MSR_STAR: 4271 case MSR_STAR:
4248 svm->vmcb->save.star = data; 4272 svm->vmcb->save.star = data;
4249 break; 4273 break;
@@ -5557,8 +5581,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
5557 * is no need to worry about the conditional branch over the wrmsr 5581 * is no need to worry about the conditional branch over the wrmsr
5558 * being speculatively taken. 5582 * being speculatively taken.
5559 */ 5583 */
5560 if (svm->spec_ctrl) 5584 x86_spec_ctrl_set_guest(svm->spec_ctrl, svm->virt_spec_ctrl);
5561 native_wrmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);
5562 5585
5563 asm volatile ( 5586 asm volatile (
5564 "push %%" _ASM_BP "; \n\t" 5587 "push %%" _ASM_BP "; \n\t"
@@ -5652,6 +5675,18 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
5652#endif 5675#endif
5653 ); 5676 );
5654 5677
5678 /* Eliminate branch target predictions from guest mode */
5679 vmexit_fill_RSB();
5680
5681#ifdef CONFIG_X86_64
5682 wrmsrl(MSR_GS_BASE, svm->host.gs_base);
5683#else
5684 loadsegment(fs, svm->host.fs);
5685#ifndef CONFIG_X86_32_LAZY_GS
5686 loadsegment(gs, svm->host.gs);
5687#endif
5688#endif
5689
5655 /* 5690 /*
5656 * We do not use IBRS in the kernel. If this vCPU has used the 5691 * We do not use IBRS in the kernel. If this vCPU has used the
5657 * SPEC_CTRL MSR it may have left it on; save the value and 5692 * SPEC_CTRL MSR it may have left it on; save the value and
@@ -5670,20 +5705,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
5670 if (unlikely(!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL))) 5705 if (unlikely(!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL)))
5671 svm->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL); 5706 svm->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL);
5672 5707
5673 if (svm->spec_ctrl) 5708 x86_spec_ctrl_restore_host(svm->spec_ctrl, svm->virt_spec_ctrl);
5674 native_wrmsrl(MSR_IA32_SPEC_CTRL, 0);
5675
5676 /* Eliminate branch target predictions from guest mode */
5677 vmexit_fill_RSB();
5678
5679#ifdef CONFIG_X86_64
5680 wrmsrl(MSR_GS_BASE, svm->host.gs_base);
5681#else
5682 loadsegment(fs, svm->host.fs);
5683#ifndef CONFIG_X86_32_LAZY_GS
5684 loadsegment(gs, svm->host.gs);
5685#endif
5686#endif
5687 5709
5688 reload_tss(vcpu); 5710 reload_tss(vcpu);
5689 5711
@@ -5786,7 +5808,7 @@ static bool svm_cpu_has_accelerated_tpr(void)
5786 return false; 5808 return false;
5787} 5809}
5788 5810
5789static bool svm_has_high_real_mode_segbase(void) 5811static bool svm_has_emulated_msr(int index)
5790{ 5812{
5791 return true; 5813 return true;
5792} 5814}
@@ -7012,7 +7034,7 @@ static struct kvm_x86_ops svm_x86_ops __ro_after_init = {
7012 .hardware_enable = svm_hardware_enable, 7034 .hardware_enable = svm_hardware_enable,
7013 .hardware_disable = svm_hardware_disable, 7035 .hardware_disable = svm_hardware_disable,
7014 .cpu_has_accelerated_tpr = svm_cpu_has_accelerated_tpr, 7036 .cpu_has_accelerated_tpr = svm_cpu_has_accelerated_tpr,
7015 .cpu_has_high_real_mode_segbase = svm_has_high_real_mode_segbase, 7037 .has_emulated_msr = svm_has_emulated_msr,
7016 7038
7017 .vcpu_create = svm_create_vcpu, 7039 .vcpu_create = svm_create_vcpu,
7018 .vcpu_free = svm_free_vcpu, 7040 .vcpu_free = svm_free_vcpu,
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 3f1696570b41..40aa29204baf 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -51,7 +51,7 @@
51#include <asm/apic.h> 51#include <asm/apic.h>
52#include <asm/irq_remapping.h> 52#include <asm/irq_remapping.h>
53#include <asm/mmu_context.h> 53#include <asm/mmu_context.h>
54#include <asm/nospec-branch.h> 54#include <asm/spec-ctrl.h>
55#include <asm/mshyperv.h> 55#include <asm/mshyperv.h>
56 56
57#include "trace.h" 57#include "trace.h"
@@ -3529,7 +3529,6 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
3529 return kvm_get_msr_common(vcpu, msr_info); 3529 return kvm_get_msr_common(vcpu, msr_info);
3530 case MSR_IA32_SPEC_CTRL: 3530 case MSR_IA32_SPEC_CTRL:
3531 if (!msr_info->host_initiated && 3531 if (!msr_info->host_initiated &&
3532 !guest_cpuid_has(vcpu, X86_FEATURE_IBRS) &&
3533 !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)) 3532 !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL))
3534 return 1; 3533 return 1;
3535 3534
@@ -3648,12 +3647,11 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
3648 break; 3647 break;
3649 case MSR_IA32_SPEC_CTRL: 3648 case MSR_IA32_SPEC_CTRL:
3650 if (!msr_info->host_initiated && 3649 if (!msr_info->host_initiated &&
3651 !guest_cpuid_has(vcpu, X86_FEATURE_IBRS) &&
3652 !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)) 3650 !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL))
3653 return 1; 3651 return 1;
3654 3652
3655 /* The STIBP bit doesn't fault even if it's not advertised */ 3653 /* The STIBP bit doesn't fault even if it's not advertised */
3656 if (data & ~(SPEC_CTRL_IBRS | SPEC_CTRL_STIBP)) 3654 if (data & ~(SPEC_CTRL_IBRS | SPEC_CTRL_STIBP | SPEC_CTRL_SSBD))
3657 return 1; 3655 return 1;
3658 3656
3659 vmx->spec_ctrl = data; 3657 vmx->spec_ctrl = data;
@@ -3679,7 +3677,6 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
3679 break; 3677 break;
3680 case MSR_IA32_PRED_CMD: 3678 case MSR_IA32_PRED_CMD:
3681 if (!msr_info->host_initiated && 3679 if (!msr_info->host_initiated &&
3682 !guest_cpuid_has(vcpu, X86_FEATURE_IBPB) &&
3683 !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)) 3680 !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL))
3684 return 1; 3681 return 1;
3685 3682
@@ -9488,9 +9485,21 @@ static void vmx_handle_external_intr(struct kvm_vcpu *vcpu)
9488} 9485}
9489STACK_FRAME_NON_STANDARD(vmx_handle_external_intr); 9486STACK_FRAME_NON_STANDARD(vmx_handle_external_intr);
9490 9487
9491static bool vmx_has_high_real_mode_segbase(void) 9488static bool vmx_has_emulated_msr(int index)
9492{ 9489{
9493 return enable_unrestricted_guest || emulate_invalid_guest_state; 9490 switch (index) {
9491 case MSR_IA32_SMBASE:
9492 /*
9493 * We cannot do SMM unless we can run the guest in big
9494 * real mode.
9495 */
9496 return enable_unrestricted_guest || emulate_invalid_guest_state;
9497 case MSR_AMD64_VIRT_SPEC_CTRL:
9498 /* This is AMD only. */
9499 return false;
9500 default:
9501 return true;
9502 }
9494} 9503}
9495 9504
9496static bool vmx_mpx_supported(void) 9505static bool vmx_mpx_supported(void)
@@ -9722,8 +9731,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
9722 * is no need to worry about the conditional branch over the wrmsr 9731 * is no need to worry about the conditional branch over the wrmsr
9723 * being speculatively taken. 9732 * being speculatively taken.
9724 */ 9733 */
9725 if (vmx->spec_ctrl) 9734 x86_spec_ctrl_set_guest(vmx->spec_ctrl, 0);
9726 native_wrmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl);
9727 9735
9728 vmx->__launched = vmx->loaded_vmcs->launched; 9736 vmx->__launched = vmx->loaded_vmcs->launched;
9729 9737
@@ -9871,8 +9879,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
9871 if (unlikely(!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL))) 9879 if (unlikely(!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL)))
9872 vmx->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL); 9880 vmx->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL);
9873 9881
9874 if (vmx->spec_ctrl) 9882 x86_spec_ctrl_restore_host(vmx->spec_ctrl, 0);
9875 native_wrmsrl(MSR_IA32_SPEC_CTRL, 0);
9876 9883
9877 /* Eliminate branch target predictions from guest mode */ 9884 /* Eliminate branch target predictions from guest mode */
9878 vmexit_fill_RSB(); 9885 vmexit_fill_RSB();
@@ -12632,7 +12639,7 @@ static struct kvm_x86_ops vmx_x86_ops __ro_after_init = {
12632 .hardware_enable = hardware_enable, 12639 .hardware_enable = hardware_enable,
12633 .hardware_disable = hardware_disable, 12640 .hardware_disable = hardware_disable,
12634 .cpu_has_accelerated_tpr = report_flexpriority, 12641 .cpu_has_accelerated_tpr = report_flexpriority,
12635 .cpu_has_high_real_mode_segbase = vmx_has_high_real_mode_segbase, 12642 .has_emulated_msr = vmx_has_emulated_msr,
12636 12643
12637 .vm_init = vmx_vm_init, 12644 .vm_init = vmx_vm_init,
12638 .vm_alloc = vmx_vm_alloc, 12645 .vm_alloc = vmx_vm_alloc,
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 59371de5d722..71e7cda6d014 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1061,6 +1061,7 @@ static u32 emulated_msrs[] = {
1061 MSR_SMI_COUNT, 1061 MSR_SMI_COUNT,
1062 MSR_PLATFORM_INFO, 1062 MSR_PLATFORM_INFO,
1063 MSR_MISC_FEATURES_ENABLES, 1063 MSR_MISC_FEATURES_ENABLES,
1064 MSR_AMD64_VIRT_SPEC_CTRL,
1064}; 1065};
1065 1066
1066static unsigned num_emulated_msrs; 1067static unsigned num_emulated_msrs;
@@ -2906,7 +2907,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
2906 * fringe case that is not enabled except via specific settings 2907 * fringe case that is not enabled except via specific settings
2907 * of the module parameters. 2908 * of the module parameters.
2908 */ 2909 */
2909 r = kvm_x86_ops->cpu_has_high_real_mode_segbase(); 2910 r = kvm_x86_ops->has_emulated_msr(MSR_IA32_SMBASE);
2910 break; 2911 break;
2911 case KVM_CAP_VAPIC: 2912 case KVM_CAP_VAPIC:
2912 r = !kvm_x86_ops->cpu_has_accelerated_tpr(); 2913 r = !kvm_x86_ops->cpu_has_accelerated_tpr();
@@ -4606,14 +4607,8 @@ static void kvm_init_msr_list(void)
4606 num_msrs_to_save = j; 4607 num_msrs_to_save = j;
4607 4608
4608 for (i = j = 0; i < ARRAY_SIZE(emulated_msrs); i++) { 4609 for (i = j = 0; i < ARRAY_SIZE(emulated_msrs); i++) {
4609 switch (emulated_msrs[i]) { 4610 if (!kvm_x86_ops->has_emulated_msr(emulated_msrs[i]))
4610 case MSR_IA32_SMBASE: 4611 continue;
4611 if (!kvm_x86_ops->cpu_has_high_real_mode_segbase())
4612 continue;
4613 break;
4614 default:
4615 break;
4616 }
4617 4612
4618 if (j < i) 4613 if (j < i)
4619 emulated_msrs[j] = emulated_msrs[i]; 4614 emulated_msrs[j] = emulated_msrs[i];
@@ -6676,11 +6671,8 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
6676 unsigned long nr, a0, a1, a2, a3, ret; 6671 unsigned long nr, a0, a1, a2, a3, ret;
6677 int op_64_bit; 6672 int op_64_bit;
6678 6673
6679 if (kvm_hv_hypercall_enabled(vcpu->kvm)) { 6674 if (kvm_hv_hypercall_enabled(vcpu->kvm))
6680 if (!kvm_hv_hypercall(vcpu)) 6675 return kvm_hv_hypercall(vcpu);
6681 return 0;
6682 goto out;
6683 }
6684 6676
6685 nr = kvm_register_read(vcpu, VCPU_REGS_RAX); 6677 nr = kvm_register_read(vcpu, VCPU_REGS_RAX);
6686 a0 = kvm_register_read(vcpu, VCPU_REGS_RBX); 6678 a0 = kvm_register_read(vcpu, VCPU_REGS_RBX);
@@ -6701,7 +6693,7 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
6701 6693
6702 if (kvm_x86_ops->get_cpl(vcpu) != 0) { 6694 if (kvm_x86_ops->get_cpl(vcpu) != 0) {
6703 ret = -KVM_EPERM; 6695 ret = -KVM_EPERM;
6704 goto out_error; 6696 goto out;
6705 } 6697 }
6706 6698
6707 switch (nr) { 6699 switch (nr) {
@@ -6721,12 +6713,11 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
6721 ret = -KVM_ENOSYS; 6713 ret = -KVM_ENOSYS;
6722 break; 6714 break;
6723 } 6715 }
6724out_error: 6716out:
6725 if (!op_64_bit) 6717 if (!op_64_bit)
6726 ret = (u32)ret; 6718 ret = (u32)ret;
6727 kvm_register_write(vcpu, VCPU_REGS_RAX, ret); 6719 kvm_register_write(vcpu, VCPU_REGS_RAX, ret);
6728 6720
6729out:
6730 ++vcpu->stat.hypercalls; 6721 ++vcpu->stat.hypercalls;
6731 return kvm_skip_emulated_instruction(vcpu); 6722 return kvm_skip_emulated_instruction(vcpu);
6732} 6723}
@@ -7985,6 +7976,7 @@ static int __set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
7985{ 7976{
7986 struct msr_data apic_base_msr; 7977 struct msr_data apic_base_msr;
7987 int mmu_reset_needed = 0; 7978 int mmu_reset_needed = 0;
7979 int cpuid_update_needed = 0;
7988 int pending_vec, max_bits, idx; 7980 int pending_vec, max_bits, idx;
7989 struct desc_ptr dt; 7981 struct desc_ptr dt;
7990 int ret = -EINVAL; 7982 int ret = -EINVAL;
@@ -8023,8 +8015,10 @@ static int __set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
8023 vcpu->arch.cr0 = sregs->cr0; 8015 vcpu->arch.cr0 = sregs->cr0;
8024 8016
8025 mmu_reset_needed |= kvm_read_cr4(vcpu) != sregs->cr4; 8017 mmu_reset_needed |= kvm_read_cr4(vcpu) != sregs->cr4;
8018 cpuid_update_needed |= ((kvm_read_cr4(vcpu) ^ sregs->cr4) &
8019 (X86_CR4_OSXSAVE | X86_CR4_PKE));
8026 kvm_x86_ops->set_cr4(vcpu, sregs->cr4); 8020 kvm_x86_ops->set_cr4(vcpu, sregs->cr4);
8027 if (sregs->cr4 & (X86_CR4_OSXSAVE | X86_CR4_PKE)) 8021 if (cpuid_update_needed)
8028 kvm_update_cpuid(vcpu); 8022 kvm_update_cpuid(vcpu);
8029 8023
8030 idx = srcu_read_lock(&vcpu->kvm->srcu); 8024 idx = srcu_read_lock(&vcpu->kvm->srcu);
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 6389c88b3500..738fb22978dd 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -334,6 +334,7 @@ static const struct pci_device_id ahci_pci_tbl[] = {
334 { PCI_VDEVICE(INTEL, 0x9c07), board_ahci_mobile }, /* Lynx LP RAID */ 334 { PCI_VDEVICE(INTEL, 0x9c07), board_ahci_mobile }, /* Lynx LP RAID */
335 { PCI_VDEVICE(INTEL, 0x9c0e), board_ahci_mobile }, /* Lynx LP RAID */ 335 { PCI_VDEVICE(INTEL, 0x9c0e), board_ahci_mobile }, /* Lynx LP RAID */
336 { PCI_VDEVICE(INTEL, 0x9c0f), board_ahci_mobile }, /* Lynx LP RAID */ 336 { PCI_VDEVICE(INTEL, 0x9c0f), board_ahci_mobile }, /* Lynx LP RAID */
337 { PCI_VDEVICE(INTEL, 0x9dd3), board_ahci_mobile }, /* Cannon Lake PCH-LP AHCI */
337 { PCI_VDEVICE(INTEL, 0x1f22), board_ahci }, /* Avoton AHCI */ 338 { PCI_VDEVICE(INTEL, 0x1f22), board_ahci }, /* Avoton AHCI */
338 { PCI_VDEVICE(INTEL, 0x1f23), board_ahci }, /* Avoton AHCI */ 339 { PCI_VDEVICE(INTEL, 0x1f23), board_ahci }, /* Avoton AHCI */
339 { PCI_VDEVICE(INTEL, 0x1f24), board_ahci }, /* Avoton RAID */ 340 { PCI_VDEVICE(INTEL, 0x1f24), board_ahci }, /* Avoton RAID */
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 68596bd4cf06..346b163f6e89 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -4493,6 +4493,10 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4493 /* https://bugzilla.kernel.org/show_bug.cgi?id=15573 */ 4493 /* https://bugzilla.kernel.org/show_bug.cgi?id=15573 */
4494 { "C300-CTFDDAC128MAG", "0001", ATA_HORKAGE_NONCQ, }, 4494 { "C300-CTFDDAC128MAG", "0001", ATA_HORKAGE_NONCQ, },
4495 4495
4496 /* Some Sandisk SSDs lock up hard with NCQ enabled. Reported on
4497 SD7SN6S256G and SD8SN8U256G */
4498 { "SanDisk SD[78]SN*G", NULL, ATA_HORKAGE_NONCQ, },
4499
4496 /* devices which puke on READ_NATIVE_MAX */ 4500 /* devices which puke on READ_NATIVE_MAX */
4497 { "HDS724040KLSA80", "KFAOA20N", ATA_HORKAGE_BROKEN_HPA, }, 4501 { "HDS724040KLSA80", "KFAOA20N", ATA_HORKAGE_BROKEN_HPA, },
4498 { "WDC WD3200JD-00KLB0", "WD-WCAMR1130137", ATA_HORKAGE_BROKEN_HPA }, 4502 { "WDC WD3200JD-00KLB0", "WD-WCAMR1130137", ATA_HORKAGE_BROKEN_HPA },
@@ -4549,13 +4553,16 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4549 ATA_HORKAGE_ZERO_AFTER_TRIM | 4553 ATA_HORKAGE_ZERO_AFTER_TRIM |
4550 ATA_HORKAGE_NOLPM, }, 4554 ATA_HORKAGE_NOLPM, },
4551 4555
4552 /* This specific Samsung model/firmware-rev does not handle LPM well */ 4556 /* These specific Samsung models/firmware-revs do not handle LPM well */
4553 { "SAMSUNG MZMPC128HBFU-000MV", "CXM14M1Q", ATA_HORKAGE_NOLPM, }, 4557 { "SAMSUNG MZMPC128HBFU-000MV", "CXM14M1Q", ATA_HORKAGE_NOLPM, },
4558 { "SAMSUNG SSD PM830 mSATA *", "CXM13D1Q", ATA_HORKAGE_NOLPM, },
4554 4559
4555 /* Sandisk devices which are known to not handle LPM well */ 4560 /* Sandisk devices which are known to not handle LPM well */
4556 { "SanDisk SD7UB3Q*G1001", NULL, ATA_HORKAGE_NOLPM, }, 4561 { "SanDisk SD7UB3Q*G1001", NULL, ATA_HORKAGE_NOLPM, },
4557 4562
4558 /* devices that don't properly handle queued TRIM commands */ 4563 /* devices that don't properly handle queued TRIM commands */
4564 { "Micron_M500IT_*", "MU01", ATA_HORKAGE_NO_NCQ_TRIM |
4565 ATA_HORKAGE_ZERO_AFTER_TRIM, },
4559 { "Micron_M500_*", NULL, ATA_HORKAGE_NO_NCQ_TRIM | 4566 { "Micron_M500_*", NULL, ATA_HORKAGE_NO_NCQ_TRIM |
4560 ATA_HORKAGE_ZERO_AFTER_TRIM, }, 4567 ATA_HORKAGE_ZERO_AFTER_TRIM, },
4561 { "Crucial_CT*M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM | 4568 { "Crucial_CT*M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM |
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 2da998baa75c..30cc9c877ebb 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -534,14 +534,22 @@ ssize_t __weak cpu_show_spectre_v2(struct device *dev,
534 return sprintf(buf, "Not affected\n"); 534 return sprintf(buf, "Not affected\n");
535} 535}
536 536
537ssize_t __weak cpu_show_spec_store_bypass(struct device *dev,
538 struct device_attribute *attr, char *buf)
539{
540 return sprintf(buf, "Not affected\n");
541}
542
537static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL); 543static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL);
538static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL); 544static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL);
539static DEVICE_ATTR(spectre_v2, 0444, cpu_show_spectre_v2, NULL); 545static DEVICE_ATTR(spectre_v2, 0444, cpu_show_spectre_v2, NULL);
546static DEVICE_ATTR(spec_store_bypass, 0444, cpu_show_spec_store_bypass, NULL);
540 547
541static struct attribute *cpu_root_vulnerabilities_attrs[] = { 548static struct attribute *cpu_root_vulnerabilities_attrs[] = {
542 &dev_attr_meltdown.attr, 549 &dev_attr_meltdown.attr,
543 &dev_attr_spectre_v1.attr, 550 &dev_attr_spectre_v1.attr,
544 &dev_attr_spectre_v2.attr, 551 &dev_attr_spectre_v2.attr,
552 &dev_attr_spec_store_bypass.attr,
545 NULL 553 NULL
546}; 554};
547 555
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 7a3a580821e0..a5e821d09656 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -490,7 +490,8 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
490 return 0; 490 return 0;
491} 491}
492 492
493int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages) 493int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages,
494 bool check_nid)
494{ 495{
495 unsigned long end_pfn = start_pfn + nr_pages; 496 unsigned long end_pfn = start_pfn + nr_pages;
496 unsigned long pfn; 497 unsigned long pfn;
@@ -514,7 +515,7 @@ int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages)
514 515
515 mem_blk = find_memory_block_hinted(mem_sect, mem_blk); 516 mem_blk = find_memory_block_hinted(mem_sect, mem_blk);
516 517
517 ret = register_mem_sect_under_node(mem_blk, nid, true); 518 ret = register_mem_sect_under_node(mem_blk, nid, check_nid);
518 if (!err) 519 if (!err)
519 err = ret; 520 err = ret;
520 521
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 02a497e7c785..e5e067091572 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1923,10 +1923,8 @@ static int device_prepare(struct device *dev, pm_message_t state)
1923 1923
1924 dev->power.wakeup_path = false; 1924 dev->power.wakeup_path = false;
1925 1925
1926 if (dev->power.no_pm_callbacks) { 1926 if (dev->power.no_pm_callbacks)
1927 ret = 1; /* Let device go direct_complete */
1928 goto unlock; 1927 goto unlock;
1929 }
1930 1928
1931 if (dev->pm_domain) 1929 if (dev->pm_domain)
1932 callback = dev->pm_domain->ops.prepare; 1930 callback = dev->pm_domain->ops.prepare;
@@ -1960,7 +1958,8 @@ unlock:
1960 */ 1958 */
1961 spin_lock_irq(&dev->power.lock); 1959 spin_lock_irq(&dev->power.lock);
1962 dev->power.direct_complete = state.event == PM_EVENT_SUSPEND && 1960 dev->power.direct_complete = state.event == PM_EVENT_SUSPEND &&
1963 pm_runtime_suspended(dev) && ret > 0 && 1961 ((pm_runtime_suspended(dev) && ret > 0) ||
1962 dev->power.no_pm_callbacks) &&
1964 !dev_pm_test_driver_flags(dev, DPM_FLAG_NEVER_SKIP); 1963 !dev_pm_test_driver_flags(dev, DPM_FLAG_NEVER_SKIP);
1965 spin_unlock_irq(&dev->power.lock); 1964 spin_unlock_irq(&dev->power.lock);
1966 return 0; 1965 return 0;
diff --git a/drivers/bcma/driver_mips.c b/drivers/bcma/driver_mips.c
index f040aba48d50..27e9686b6d3a 100644
--- a/drivers/bcma/driver_mips.c
+++ b/drivers/bcma/driver_mips.c
@@ -184,7 +184,7 @@ static void bcma_core_mips_print_irq(struct bcma_device *dev, unsigned int irq)
184{ 184{
185 int i; 185 int i;
186 static const char *irq_name[] = {"2(S)", "3", "4", "5", "6", "D", "I"}; 186 static const char *irq_name[] = {"2(S)", "3", "4", "5", "6", "D", "I"};
187 char interrupts[20]; 187 char interrupts[25];
188 char *ints = interrupts; 188 char *ints = interrupts;
189 189
190 for (i = 0; i < ARRAY_SIZE(irq_name); i++) 190 for (i = 0; i < ARRAY_SIZE(irq_name); i++)
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 5d4e31655d96..55cf554bc914 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1068,6 +1068,7 @@ static int loop_clr_fd(struct loop_device *lo)
1068 if (bdev) { 1068 if (bdev) {
1069 bdput(bdev); 1069 bdput(bdev);
1070 invalidate_bdev(bdev); 1070 invalidate_bdev(bdev);
1071 bdev->bd_inode->i_mapping->wb_err = 0;
1071 } 1072 }
1072 set_capacity(lo->lo_disk, 0); 1073 set_capacity(lo->lo_disk, 0);
1073 loop_sysfs_exit(lo); 1074 loop_sysfs_exit(lo);
diff --git a/drivers/firmware/qcom_scm-32.c b/drivers/firmware/qcom_scm-32.c
index dfbd894d5bb7..4e24e591ae74 100644
--- a/drivers/firmware/qcom_scm-32.c
+++ b/drivers/firmware/qcom_scm-32.c
@@ -147,7 +147,7 @@ static u32 smc(u32 cmd_addr)
147 "smc #0 @ switch to secure world\n" 147 "smc #0 @ switch to secure world\n"
148 : "=r" (r0) 148 : "=r" (r0)
149 : "r" (r0), "r" (r1), "r" (r2) 149 : "r" (r0), "r" (r1), "r" (r2)
150 : "r3"); 150 : "r3", "r12");
151 } while (r0 == QCOM_SCM_INTERRUPTED); 151 } while (r0 == QCOM_SCM_INTERRUPTED);
152 152
153 return r0; 153 return r0;
@@ -263,7 +263,7 @@ static s32 qcom_scm_call_atomic1(u32 svc, u32 cmd, u32 arg1)
263 "smc #0 @ switch to secure world\n" 263 "smc #0 @ switch to secure world\n"
264 : "=r" (r0) 264 : "=r" (r0)
265 : "r" (r0), "r" (r1), "r" (r2) 265 : "r" (r0), "r" (r1), "r" (r2)
266 : "r3"); 266 : "r3", "r12");
267 return r0; 267 return r0;
268} 268}
269 269
@@ -298,7 +298,7 @@ static s32 qcom_scm_call_atomic2(u32 svc, u32 cmd, u32 arg1, u32 arg2)
298 "smc #0 @ switch to secure world\n" 298 "smc #0 @ switch to secure world\n"
299 : "=r" (r0) 299 : "=r" (r0)
300 : "r" (r0), "r" (r1), "r" (r2), "r" (r3) 300 : "r" (r0), "r" (r1), "r" (r2), "r" (r3)
301 ); 301 : "r12");
302 return r0; 302 return r0;
303} 303}
304 304
@@ -328,7 +328,7 @@ u32 qcom_scm_get_version(void)
328 "smc #0 @ switch to secure world\n" 328 "smc #0 @ switch to secure world\n"
329 : "=r" (r0), "=r" (r1) 329 : "=r" (r0), "=r" (r1)
330 : "r" (r0), "r" (r1) 330 : "r" (r0), "r" (r1)
331 : "r2", "r3"); 331 : "r2", "r3", "r12");
332 } while (r0 == QCOM_SCM_INTERRUPTED); 332 } while (r0 == QCOM_SCM_INTERRUPTED);
333 333
334 version = r1; 334 version = r1;
diff --git a/drivers/gpu/drm/rcar-du/rcar_lvds.c b/drivers/gpu/drm/rcar-du/rcar_lvds.c
index 3d2d3bbd1342..155ad840f3c5 100644
--- a/drivers/gpu/drm/rcar-du/rcar_lvds.c
+++ b/drivers/gpu/drm/rcar-du/rcar_lvds.c
@@ -88,6 +88,9 @@ static int rcar_lvds_connector_atomic_check(struct drm_connector *connector,
88 const struct drm_display_mode *panel_mode; 88 const struct drm_display_mode *panel_mode;
89 struct drm_crtc_state *crtc_state; 89 struct drm_crtc_state *crtc_state;
90 90
91 if (!state->crtc)
92 return 0;
93
91 if (list_empty(&connector->modes)) { 94 if (list_empty(&connector->modes)) {
92 dev_dbg(lvds->dev, "connector: empty modes list\n"); 95 dev_dbg(lvds->dev, "connector: empty modes list\n");
93 return -EINVAL; 96 return -EINVAL;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 70e1a8820a7c..8b770a8e02cd 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -1278,8 +1278,6 @@ static void vmw_master_drop(struct drm_device *dev,
1278 dev_priv->active_master = &dev_priv->fbdev_master; 1278 dev_priv->active_master = &dev_priv->fbdev_master;
1279 ttm_lock_set_kill(&dev_priv->fbdev_master.lock, false, SIGTERM); 1279 ttm_lock_set_kill(&dev_priv->fbdev_master.lock, false, SIGTERM);
1280 ttm_vt_unlock(&dev_priv->fbdev_master.lock); 1280 ttm_vt_unlock(&dev_priv->fbdev_master.lock);
1281
1282 vmw_fb_refresh(dev_priv);
1283} 1281}
1284 1282
1285/** 1283/**
@@ -1483,7 +1481,6 @@ static int vmw_pm_freeze(struct device *kdev)
1483 vmw_kms_resume(dev); 1481 vmw_kms_resume(dev);
1484 if (dev_priv->enable_fb) 1482 if (dev_priv->enable_fb)
1485 vmw_fb_on(dev_priv); 1483 vmw_fb_on(dev_priv);
1486 vmw_fb_refresh(dev_priv);
1487 return -EBUSY; 1484 return -EBUSY;
1488 } 1485 }
1489 1486
@@ -1523,8 +1520,6 @@ static int vmw_pm_restore(struct device *kdev)
1523 if (dev_priv->enable_fb) 1520 if (dev_priv->enable_fb)
1524 vmw_fb_on(dev_priv); 1521 vmw_fb_on(dev_priv);
1525 1522
1526 vmw_fb_refresh(dev_priv);
1527
1528 return 0; 1523 return 0;
1529} 1524}
1530 1525
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index f34f368c1a2e..5fcbe1620d50 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -910,7 +910,6 @@ int vmw_fb_init(struct vmw_private *vmw_priv);
910int vmw_fb_close(struct vmw_private *dev_priv); 910int vmw_fb_close(struct vmw_private *dev_priv);
911int vmw_fb_off(struct vmw_private *vmw_priv); 911int vmw_fb_off(struct vmw_private *vmw_priv);
912int vmw_fb_on(struct vmw_private *vmw_priv); 912int vmw_fb_on(struct vmw_private *vmw_priv);
913void vmw_fb_refresh(struct vmw_private *vmw_priv);
914 913
915/** 914/**
916 * Kernel modesetting - vmwgfx_kms.c 915 * Kernel modesetting - vmwgfx_kms.c
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
index ba0cdb743c3e..54e300365a5c 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
@@ -866,21 +866,13 @@ int vmw_fb_on(struct vmw_private *vmw_priv)
866 spin_lock_irqsave(&par->dirty.lock, flags); 866 spin_lock_irqsave(&par->dirty.lock, flags);
867 par->dirty.active = true; 867 par->dirty.active = true;
868 spin_unlock_irqrestore(&par->dirty.lock, flags); 868 spin_unlock_irqrestore(&par->dirty.lock, flags);
869
870 return 0;
871}
872 869
873/** 870 /*
874 * vmw_fb_refresh - Refresh fb display 871 * Need to reschedule a dirty update, because otherwise that's
875 * 872 * only done in dirty_mark() if the previous coalesced
876 * @vmw_priv: Pointer to device private 873 * dirty region was empty.
877 * 874 */
878 * Call into kms to show the fbdev display(s). 875 schedule_delayed_work(&par->local_work, 0);
879 */
880void vmw_fb_refresh(struct vmw_private *vmw_priv)
881{
882 if (!vmw_priv->fb_info)
883 return;
884 876
885 vmw_fb_set_par(vmw_priv->fb_info); 877 return 0;
886} 878}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
index cdff99211602..21d746bdc922 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
@@ -329,8 +329,6 @@ int vmw_host_get_guestinfo(const char *guest_info_param,
329 struct rpc_channel channel; 329 struct rpc_channel channel;
330 char *msg, *reply = NULL; 330 char *msg, *reply = NULL;
331 size_t reply_len = 0; 331 size_t reply_len = 0;
332 int ret = 0;
333
334 332
335 if (!vmw_msg_enabled) 333 if (!vmw_msg_enabled)
336 return -ENODEV; 334 return -ENODEV;
@@ -344,15 +342,14 @@ int vmw_host_get_guestinfo(const char *guest_info_param,
344 return -ENOMEM; 342 return -ENOMEM;
345 } 343 }
346 344
347 if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM) || 345 if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM))
348 vmw_send_msg(&channel, msg) || 346 goto out_open;
349 vmw_recv_msg(&channel, (void *) &reply, &reply_len) ||
350 vmw_close_channel(&channel)) {
351 DRM_ERROR("Failed to get %s", guest_info_param);
352 347
353 ret = -EINVAL; 348 if (vmw_send_msg(&channel, msg) ||
354 } 349 vmw_recv_msg(&channel, (void *) &reply, &reply_len))
350 goto out_msg;
355 351
352 vmw_close_channel(&channel);
356 if (buffer && reply && reply_len > 0) { 353 if (buffer && reply && reply_len > 0) {
357 /* Remove reply code, which are the first 2 characters of 354 /* Remove reply code, which are the first 2 characters of
358 * the reply 355 * the reply
@@ -369,7 +366,17 @@ int vmw_host_get_guestinfo(const char *guest_info_param,
369 kfree(reply); 366 kfree(reply);
370 kfree(msg); 367 kfree(msg);
371 368
372 return ret; 369 return 0;
370
371out_msg:
372 vmw_close_channel(&channel);
373 kfree(reply);
374out_open:
375 *length = 0;
376 kfree(msg);
377 DRM_ERROR("Failed to get %s", guest_info_param);
378
379 return -EINVAL;
373} 380}
374 381
375 382
@@ -400,15 +407,22 @@ int vmw_host_log(const char *log)
400 return -ENOMEM; 407 return -ENOMEM;
401 } 408 }
402 409
403 if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM) || 410 if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM))
404 vmw_send_msg(&channel, msg) || 411 goto out_open;
405 vmw_close_channel(&channel)) {
406 DRM_ERROR("Failed to send log\n");
407 412
408 ret = -EINVAL; 413 if (vmw_send_msg(&channel, msg))
409 } 414 goto out_msg;
410 415
416 vmw_close_channel(&channel);
411 kfree(msg); 417 kfree(msg);
412 418
413 return ret; 419 return 0;
420
421out_msg:
422 vmw_close_channel(&channel);
423out_open:
424 kfree(msg);
425 DRM_ERROR("Failed to send log\n");
426
427 return -EINVAL;
414} 428}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.h b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.h
index 557a033fb610..8545488aa0cf 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.h
@@ -135,17 +135,24 @@
135 135
136#else 136#else
137 137
138/* In the 32-bit version of this macro, we use "m" because there is no 138/*
139 * more register left for bp 139 * In the 32-bit version of this macro, we store bp in a memory location
140 * because we've ran out of registers.
141 * Now we can't reference that memory location while we've modified
142 * %esp or %ebp, so we first push it on the stack, just before we push
143 * %ebp, and then when we need it we read it from the stack where we
144 * just pushed it.
140 */ 145 */
141#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \ 146#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \
142 port_num, magic, bp, \ 147 port_num, magic, bp, \
143 eax, ebx, ecx, edx, si, di) \ 148 eax, ebx, ecx, edx, si, di) \
144({ \ 149({ \
145 asm volatile ("push %%ebp;" \ 150 asm volatile ("push %12;" \
146 "mov %12, %%ebp;" \ 151 "push %%ebp;" \
152 "mov 0x04(%%esp), %%ebp;" \
147 "rep outsb;" \ 153 "rep outsb;" \
148 "pop %%ebp;" : \ 154 "pop %%ebp;" \
155 "add $0x04, %%esp;" : \
149 "=a"(eax), \ 156 "=a"(eax), \
150 "=b"(ebx), \ 157 "=b"(ebx), \
151 "=c"(ecx), \ 158 "=c"(ecx), \
@@ -167,10 +174,12 @@
167 port_num, magic, bp, \ 174 port_num, magic, bp, \
168 eax, ebx, ecx, edx, si, di) \ 175 eax, ebx, ecx, edx, si, di) \
169({ \ 176({ \
170 asm volatile ("push %%ebp;" \ 177 asm volatile ("push %12;" \
171 "mov %12, %%ebp;" \ 178 "push %%ebp;" \
179 "mov 0x04(%%esp), %%ebp;" \
172 "rep insb;" \ 180 "rep insb;" \
173 "pop %%ebp" : \ 181 "pop %%ebp;" \
182 "add $0x04, %%esp;" : \
174 "=a"(eax), \ 183 "=a"(eax), \
175 "=b"(ebx), \ 184 "=b"(ebx), \
176 "=c"(ecx), \ 185 "=c"(ecx), \
diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c
index 9a4e899d94b3..2b6c9b516070 100644
--- a/drivers/infiniband/core/umem.c
+++ b/drivers/infiniband/core/umem.c
@@ -119,7 +119,6 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
119 umem->length = size; 119 umem->length = size;
120 umem->address = addr; 120 umem->address = addr;
121 umem->page_shift = PAGE_SHIFT; 121 umem->page_shift = PAGE_SHIFT;
122 umem->pid = get_task_pid(current, PIDTYPE_PID);
123 /* 122 /*
124 * We ask for writable memory if any of the following 123 * We ask for writable memory if any of the following
125 * access flags are set. "Local write" and "remote write" 124 * access flags are set. "Local write" and "remote write"
@@ -132,7 +131,6 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
132 IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_MW_BIND)); 131 IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_MW_BIND));
133 132
134 if (access & IB_ACCESS_ON_DEMAND) { 133 if (access & IB_ACCESS_ON_DEMAND) {
135 put_pid(umem->pid);
136 ret = ib_umem_odp_get(context, umem, access); 134 ret = ib_umem_odp_get(context, umem, access);
137 if (ret) { 135 if (ret) {
138 kfree(umem); 136 kfree(umem);
@@ -148,7 +146,6 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
148 146
149 page_list = (struct page **) __get_free_page(GFP_KERNEL); 147 page_list = (struct page **) __get_free_page(GFP_KERNEL);
150 if (!page_list) { 148 if (!page_list) {
151 put_pid(umem->pid);
152 kfree(umem); 149 kfree(umem);
153 return ERR_PTR(-ENOMEM); 150 return ERR_PTR(-ENOMEM);
154 } 151 }
@@ -231,7 +228,6 @@ out:
231 if (ret < 0) { 228 if (ret < 0) {
232 if (need_release) 229 if (need_release)
233 __ib_umem_release(context->device, umem, 0); 230 __ib_umem_release(context->device, umem, 0);
234 put_pid(umem->pid);
235 kfree(umem); 231 kfree(umem);
236 } else 232 } else
237 current->mm->pinned_vm = locked; 233 current->mm->pinned_vm = locked;
@@ -274,8 +270,7 @@ void ib_umem_release(struct ib_umem *umem)
274 270
275 __ib_umem_release(umem->context->device, umem, 1); 271 __ib_umem_release(umem->context->device, umem, 1);
276 272
277 task = get_pid_task(umem->pid, PIDTYPE_PID); 273 task = get_pid_task(umem->context->tgid, PIDTYPE_PID);
278 put_pid(umem->pid);
279 if (!task) 274 if (!task)
280 goto out; 275 goto out;
281 mm = get_task_mm(task); 276 mm = get_task_mm(task);
diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
index e90f2fd8dc16..1445918e3239 100644
--- a/drivers/infiniband/hw/cxgb4/mem.c
+++ b/drivers/infiniband/hw/cxgb4/mem.c
@@ -489,10 +489,10 @@ struct ib_mr *c4iw_get_dma_mr(struct ib_pd *pd, int acc)
489err_dereg_mem: 489err_dereg_mem:
490 dereg_mem(&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size, 490 dereg_mem(&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size,
491 mhp->attr.pbl_addr, mhp->dereg_skb, mhp->wr_waitp); 491 mhp->attr.pbl_addr, mhp->dereg_skb, mhp->wr_waitp);
492err_free_wr_wait:
493 c4iw_put_wr_wait(mhp->wr_waitp);
494err_free_skb: 492err_free_skb:
495 kfree_skb(mhp->dereg_skb); 493 kfree_skb(mhp->dereg_skb);
494err_free_wr_wait:
495 c4iw_put_wr_wait(mhp->wr_waitp);
496err_free_mhp: 496err_free_mhp:
497 kfree(mhp); 497 kfree(mhp);
498 return ERR_PTR(ret); 498 return ERR_PTR(ret);
diff --git a/drivers/infiniband/hw/hfi1/chip.c b/drivers/infiniband/hw/hfi1/chip.c
index e6a60fa59f2b..e6bdd0c1e80a 100644
--- a/drivers/infiniband/hw/hfi1/chip.c
+++ b/drivers/infiniband/hw/hfi1/chip.c
@@ -5944,6 +5944,7 @@ static void is_sendctxt_err_int(struct hfi1_devdata *dd,
5944 u64 status; 5944 u64 status;
5945 u32 sw_index; 5945 u32 sw_index;
5946 int i = 0; 5946 int i = 0;
5947 unsigned long irq_flags;
5947 5948
5948 sw_index = dd->hw_to_sw[hw_context]; 5949 sw_index = dd->hw_to_sw[hw_context];
5949 if (sw_index >= dd->num_send_contexts) { 5950 if (sw_index >= dd->num_send_contexts) {
@@ -5953,10 +5954,12 @@ static void is_sendctxt_err_int(struct hfi1_devdata *dd,
5953 return; 5954 return;
5954 } 5955 }
5955 sci = &dd->send_contexts[sw_index]; 5956 sci = &dd->send_contexts[sw_index];
5957 spin_lock_irqsave(&dd->sc_lock, irq_flags);
5956 sc = sci->sc; 5958 sc = sci->sc;
5957 if (!sc) { 5959 if (!sc) {
5958 dd_dev_err(dd, "%s: context %u(%u): no sc?\n", __func__, 5960 dd_dev_err(dd, "%s: context %u(%u): no sc?\n", __func__,
5959 sw_index, hw_context); 5961 sw_index, hw_context);
5962 spin_unlock_irqrestore(&dd->sc_lock, irq_flags);
5960 return; 5963 return;
5961 } 5964 }
5962 5965
@@ -5978,6 +5981,7 @@ static void is_sendctxt_err_int(struct hfi1_devdata *dd,
5978 */ 5981 */
5979 if (sc->type != SC_USER) 5982 if (sc->type != SC_USER)
5980 queue_work(dd->pport->hfi1_wq, &sc->halt_work); 5983 queue_work(dd->pport->hfi1_wq, &sc->halt_work);
5984 spin_unlock_irqrestore(&dd->sc_lock, irq_flags);
5981 5985
5982 /* 5986 /*
5983 * Update the counters for the corresponding status bits. 5987 * Update the counters for the corresponding status bits.
diff --git a/drivers/infiniband/hw/hns/hns_roce_cq.c b/drivers/infiniband/hw/hns/hns_roce_cq.c
index 14734d0d0b76..3a485f50fede 100644
--- a/drivers/infiniband/hw/hns/hns_roce_cq.c
+++ b/drivers/infiniband/hw/hns/hns_roce_cq.c
@@ -377,6 +377,7 @@ struct ib_cq *hns_roce_ib_create_cq(struct ib_device *ib_dev,
377 377
378 hr_cq->set_ci_db = hr_cq->db.db_record; 378 hr_cq->set_ci_db = hr_cq->db.db_record;
379 *hr_cq->set_ci_db = 0; 379 *hr_cq->set_ci_db = 0;
380 hr_cq->db_en = 1;
380 } 381 }
381 382
382 /* Init mmt table and write buff address to mtt table */ 383 /* Init mmt table and write buff address to mtt table */
diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
index 47e1b6ac1e1a..8013d69c5ac4 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
@@ -722,6 +722,7 @@ static int hns_roce_v1_rsv_lp_qp(struct hns_roce_dev *hr_dev)
722 free_mr->mr_free_pd = to_hr_pd(pd); 722 free_mr->mr_free_pd = to_hr_pd(pd);
723 free_mr->mr_free_pd->ibpd.device = &hr_dev->ib_dev; 723 free_mr->mr_free_pd->ibpd.device = &hr_dev->ib_dev;
724 free_mr->mr_free_pd->ibpd.uobject = NULL; 724 free_mr->mr_free_pd->ibpd.uobject = NULL;
725 free_mr->mr_free_pd->ibpd.__internal_mr = NULL;
725 atomic_set(&free_mr->mr_free_pd->ibpd.usecnt, 0); 726 atomic_set(&free_mr->mr_free_pd->ibpd.usecnt, 0);
726 727
727 attr.qp_access_flags = IB_ACCESS_REMOTE_WRITE; 728 attr.qp_access_flags = IB_ACCESS_REMOTE_WRITE;
@@ -1036,7 +1037,7 @@ static void hns_roce_v1_mr_free_work_fn(struct work_struct *work)
1036 1037
1037 do { 1038 do {
1038 ret = hns_roce_v1_poll_cq(&mr_free_cq->ib_cq, ne, wc); 1039 ret = hns_roce_v1_poll_cq(&mr_free_cq->ib_cq, ne, wc);
1039 if (ret < 0) { 1040 if (ret < 0 && hr_qp) {
1040 dev_err(dev, 1041 dev_err(dev,
1041 "(qp:0x%lx) starts, Poll cqe failed(%d) for mr 0x%x free! Remain %d cqe\n", 1042 "(qp:0x%lx) starts, Poll cqe failed(%d) for mr 0x%x free! Remain %d cqe\n",
1042 hr_qp->qpn, ret, hr_mr->key, ne); 1043 hr_qp->qpn, ret, hr_mr->key, ne);
diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
index 25916e8522ed..1f0965bb64ee 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
@@ -142,8 +142,8 @@ static int hns_roce_v2_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
142 unsigned long flags; 142 unsigned long flags;
143 unsigned int ind; 143 unsigned int ind;
144 void *wqe = NULL; 144 void *wqe = NULL;
145 u32 tmp_len = 0;
146 bool loopback; 145 bool loopback;
146 u32 tmp_len;
147 int ret = 0; 147 int ret = 0;
148 u8 *smac; 148 u8 *smac;
149 int nreq; 149 int nreq;
@@ -189,6 +189,7 @@ static int hns_roce_v2_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
189 189
190 owner_bit = 190 owner_bit =
191 ~(((qp->sq.head + nreq) >> ilog2(qp->sq.wqe_cnt)) & 0x1); 191 ~(((qp->sq.head + nreq) >> ilog2(qp->sq.wqe_cnt)) & 0x1);
192 tmp_len = 0;
192 193
193 /* Corresponding to the QP type, wqe process separately */ 194 /* Corresponding to the QP type, wqe process separately */
194 if (ibqp->qp_type == IB_QPT_GSI) { 195 if (ibqp->qp_type == IB_QPT_GSI) {
@@ -547,16 +548,20 @@ static int hns_roce_v2_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr,
547 } 548 }
548 549
549 if (i < hr_qp->rq.max_gs) { 550 if (i < hr_qp->rq.max_gs) {
550 dseg[i].lkey = cpu_to_le32(HNS_ROCE_INVALID_LKEY); 551 dseg->lkey = cpu_to_le32(HNS_ROCE_INVALID_LKEY);
551 dseg[i].addr = 0; 552 dseg->addr = 0;
552 } 553 }
553 554
554 /* rq support inline data */ 555 /* rq support inline data */
555 sge_list = hr_qp->rq_inl_buf.wqe_list[ind].sg_list; 556 if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RQ_INLINE) {
556 hr_qp->rq_inl_buf.wqe_list[ind].sge_cnt = (u32)wr->num_sge; 557 sge_list = hr_qp->rq_inl_buf.wqe_list[ind].sg_list;
557 for (i = 0; i < wr->num_sge; i++) { 558 hr_qp->rq_inl_buf.wqe_list[ind].sge_cnt =
558 sge_list[i].addr = (void *)(u64)wr->sg_list[i].addr; 559 (u32)wr->num_sge;
559 sge_list[i].len = wr->sg_list[i].length; 560 for (i = 0; i < wr->num_sge; i++) {
561 sge_list[i].addr =
562 (void *)(u64)wr->sg_list[i].addr;
563 sge_list[i].len = wr->sg_list[i].length;
564 }
560 } 565 }
561 566
562 hr_qp->rq.wrid[ind] = wr->wr_id; 567 hr_qp->rq.wrid[ind] = wr->wr_id;
@@ -613,6 +618,8 @@ static void hns_roce_free_cmq_desc(struct hns_roce_dev *hr_dev,
613 dma_unmap_single(hr_dev->dev, ring->desc_dma_addr, 618 dma_unmap_single(hr_dev->dev, ring->desc_dma_addr,
614 ring->desc_num * sizeof(struct hns_roce_cmq_desc), 619 ring->desc_num * sizeof(struct hns_roce_cmq_desc),
615 DMA_BIDIRECTIONAL); 620 DMA_BIDIRECTIONAL);
621
622 ring->desc_dma_addr = 0;
616 kfree(ring->desc); 623 kfree(ring->desc);
617} 624}
618 625
@@ -1081,6 +1088,7 @@ static int hns_roce_v2_profile(struct hns_roce_dev *hr_dev)
1081 if (ret) { 1088 if (ret) {
1082 dev_err(hr_dev->dev, "Configure global param fail, ret = %d.\n", 1089 dev_err(hr_dev->dev, "Configure global param fail, ret = %d.\n",
1083 ret); 1090 ret);
1091 return ret;
1084 } 1092 }
1085 1093
1086 /* Get pf resource owned by every pf */ 1094 /* Get pf resource owned by every pf */
@@ -1372,6 +1380,8 @@ static int hns_roce_v2_write_mtpt(void *mb_buf, struct hns_roce_mr *mr,
1372 1380
1373 roce_set_bit(mpt_entry->byte_12_mw_pa, V2_MPT_BYTE_12_PA_S, 1381 roce_set_bit(mpt_entry->byte_12_mw_pa, V2_MPT_BYTE_12_PA_S,
1374 mr->type == MR_TYPE_MR ? 0 : 1); 1382 mr->type == MR_TYPE_MR ? 0 : 1);
1383 roce_set_bit(mpt_entry->byte_12_mw_pa, V2_MPT_BYTE_12_INNER_PA_VLD_S,
1384 1);
1375 mpt_entry->byte_12_mw_pa = cpu_to_le32(mpt_entry->byte_12_mw_pa); 1385 mpt_entry->byte_12_mw_pa = cpu_to_le32(mpt_entry->byte_12_mw_pa);
1376 1386
1377 mpt_entry->len_l = cpu_to_le32(lower_32_bits(mr->size)); 1387 mpt_entry->len_l = cpu_to_le32(lower_32_bits(mr->size));
@@ -2169,6 +2179,7 @@ static void modify_qp_reset_to_init(struct ib_qp *ibqp,
2169 struct hns_roce_v2_qp_context *context, 2179 struct hns_roce_v2_qp_context *context,
2170 struct hns_roce_v2_qp_context *qpc_mask) 2180 struct hns_roce_v2_qp_context *qpc_mask)
2171{ 2181{
2182 struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
2172 struct hns_roce_qp *hr_qp = to_hr_qp(ibqp); 2183 struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
2173 2184
2174 /* 2185 /*
@@ -2281,7 +2292,8 @@ static void modify_qp_reset_to_init(struct ib_qp *ibqp,
2281 context->rq_db_record_addr = hr_qp->rdb.dma >> 32; 2292 context->rq_db_record_addr = hr_qp->rdb.dma >> 32;
2282 qpc_mask->rq_db_record_addr = 0; 2293 qpc_mask->rq_db_record_addr = 0;
2283 2294
2284 roce_set_bit(context->byte_76_srqn_op_en, V2_QPC_BYTE_76_RQIE_S, 1); 2295 roce_set_bit(context->byte_76_srqn_op_en, V2_QPC_BYTE_76_RQIE_S,
2296 (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RQ_INLINE) ? 1 : 0);
2285 roce_set_bit(qpc_mask->byte_76_srqn_op_en, V2_QPC_BYTE_76_RQIE_S, 0); 2297 roce_set_bit(qpc_mask->byte_76_srqn_op_en, V2_QPC_BYTE_76_RQIE_S, 0);
2286 2298
2287 roce_set_field(context->byte_80_rnr_rx_cqn, V2_QPC_BYTE_80_RX_CQN_M, 2299 roce_set_field(context->byte_80_rnr_rx_cqn, V2_QPC_BYTE_80_RX_CQN_M,
@@ -4703,6 +4715,8 @@ static const struct pci_device_id hns_roce_hw_v2_pci_tbl[] = {
4703 {0, } 4715 {0, }
4704}; 4716};
4705 4717
4718MODULE_DEVICE_TABLE(pci, hns_roce_hw_v2_pci_tbl);
4719
4706static int hns_roce_hw_v2_get_cfg(struct hns_roce_dev *hr_dev, 4720static int hns_roce_hw_v2_get_cfg(struct hns_roce_dev *hr_dev,
4707 struct hnae3_handle *handle) 4721 struct hnae3_handle *handle)
4708{ 4722{
diff --git a/drivers/infiniband/hw/hns/hns_roce_main.c b/drivers/infiniband/hw/hns/hns_roce_main.c
index 9d48bc07a9e6..96fb6a9ed93c 100644
--- a/drivers/infiniband/hw/hns/hns_roce_main.c
+++ b/drivers/infiniband/hw/hns/hns_roce_main.c
@@ -199,7 +199,7 @@ static int hns_roce_query_device(struct ib_device *ib_dev,
199 199
200 memset(props, 0, sizeof(*props)); 200 memset(props, 0, sizeof(*props));
201 201
202 props->sys_image_guid = cpu_to_be32(hr_dev->sys_image_guid); 202 props->sys_image_guid = cpu_to_be64(hr_dev->sys_image_guid);
203 props->max_mr_size = (u64)(~(0ULL)); 203 props->max_mr_size = (u64)(~(0ULL));
204 props->page_size_cap = hr_dev->caps.page_size_cap; 204 props->page_size_cap = hr_dev->caps.page_size_cap;
205 props->vendor_id = hr_dev->vendor_id; 205 props->vendor_id = hr_dev->vendor_id;
diff --git a/drivers/infiniband/hw/hns/hns_roce_qp.c b/drivers/infiniband/hw/hns/hns_roce_qp.c
index d4aad34c21e2..baaf906f7c2e 100644
--- a/drivers/infiniband/hw/hns/hns_roce_qp.c
+++ b/drivers/infiniband/hw/hns/hns_roce_qp.c
@@ -660,6 +660,7 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev,
660 goto err_rq_sge_list; 660 goto err_rq_sge_list;
661 } 661 }
662 *hr_qp->rdb.db_record = 0; 662 *hr_qp->rdb.db_record = 0;
663 hr_qp->rdb_en = 1;
663 } 664 }
664 665
665 /* Allocate QP buf */ 666 /* Allocate QP buf */
@@ -955,7 +956,14 @@ int hns_roce_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
955 } 956 }
956 957
957 if (cur_state == new_state && cur_state == IB_QPS_RESET) { 958 if (cur_state == new_state && cur_state == IB_QPS_RESET) {
958 ret = 0; 959 if (hr_dev->caps.min_wqes) {
960 ret = -EPERM;
961 dev_err(dev, "cur_state=%d new_state=%d\n", cur_state,
962 new_state);
963 } else {
964 ret = 0;
965 }
966
959 goto out; 967 goto out;
960 } 968 }
961 969
diff --git a/drivers/infiniband/hw/i40iw/i40iw.h b/drivers/infiniband/hw/i40iw/i40iw.h
index d5d8c1be345a..2f2b4426ded7 100644
--- a/drivers/infiniband/hw/i40iw/i40iw.h
+++ b/drivers/infiniband/hw/i40iw/i40iw.h
@@ -207,6 +207,7 @@ struct i40iw_msix_vector {
207 u32 irq; 207 u32 irq;
208 u32 cpu_affinity; 208 u32 cpu_affinity;
209 u32 ceq_id; 209 u32 ceq_id;
210 cpumask_t mask;
210}; 211};
211 212
212struct l2params_work { 213struct l2params_work {
diff --git a/drivers/infiniband/hw/i40iw/i40iw_cm.c b/drivers/infiniband/hw/i40iw/i40iw_cm.c
index 4cfa8f4647e2..f7c6fd9ff6e2 100644
--- a/drivers/infiniband/hw/i40iw/i40iw_cm.c
+++ b/drivers/infiniband/hw/i40iw/i40iw_cm.c
@@ -2093,7 +2093,7 @@ static int i40iw_addr_resolve_neigh_ipv6(struct i40iw_device *iwdev,
2093 if (netif_is_bond_slave(netdev)) 2093 if (netif_is_bond_slave(netdev))
2094 netdev = netdev_master_upper_dev_get(netdev); 2094 netdev = netdev_master_upper_dev_get(netdev);
2095 2095
2096 neigh = dst_neigh_lookup(dst, &dst_addr); 2096 neigh = dst_neigh_lookup(dst, dst_addr.sin6_addr.in6_u.u6_addr32);
2097 2097
2098 rcu_read_lock(); 2098 rcu_read_lock();
2099 if (neigh) { 2099 if (neigh) {
diff --git a/drivers/infiniband/hw/i40iw/i40iw_hw.c b/drivers/infiniband/hw/i40iw/i40iw_hw.c
index 6139836fb533..c9f62ca7643c 100644
--- a/drivers/infiniband/hw/i40iw/i40iw_hw.c
+++ b/drivers/infiniband/hw/i40iw/i40iw_hw.c
@@ -331,7 +331,7 @@ void i40iw_process_aeq(struct i40iw_device *iwdev)
331 switch (info->ae_id) { 331 switch (info->ae_id) {
332 case I40IW_AE_LLP_FIN_RECEIVED: 332 case I40IW_AE_LLP_FIN_RECEIVED:
333 if (qp->term_flags) 333 if (qp->term_flags)
334 continue; 334 break;
335 if (atomic_inc_return(&iwqp->close_timer_started) == 1) { 335 if (atomic_inc_return(&iwqp->close_timer_started) == 1) {
336 iwqp->hw_tcp_state = I40IW_TCP_STATE_CLOSE_WAIT; 336 iwqp->hw_tcp_state = I40IW_TCP_STATE_CLOSE_WAIT;
337 if ((iwqp->hw_tcp_state == I40IW_TCP_STATE_CLOSE_WAIT) && 337 if ((iwqp->hw_tcp_state == I40IW_TCP_STATE_CLOSE_WAIT) &&
@@ -360,7 +360,7 @@ void i40iw_process_aeq(struct i40iw_device *iwdev)
360 break; 360 break;
361 case I40IW_AE_LLP_CONNECTION_RESET: 361 case I40IW_AE_LLP_CONNECTION_RESET:
362 if (atomic_read(&iwqp->close_timer_started)) 362 if (atomic_read(&iwqp->close_timer_started))
363 continue; 363 break;
364 i40iw_cm_disconn(iwqp); 364 i40iw_cm_disconn(iwqp);
365 break; 365 break;
366 case I40IW_AE_QP_SUSPEND_COMPLETE: 366 case I40IW_AE_QP_SUSPEND_COMPLETE:
diff --git a/drivers/infiniband/hw/i40iw/i40iw_main.c b/drivers/infiniband/hw/i40iw/i40iw_main.c
index 9cd0d3ef9057..05001e6da1f8 100644
--- a/drivers/infiniband/hw/i40iw/i40iw_main.c
+++ b/drivers/infiniband/hw/i40iw/i40iw_main.c
@@ -687,7 +687,6 @@ static enum i40iw_status_code i40iw_configure_ceq_vector(struct i40iw_device *iw
687 struct i40iw_msix_vector *msix_vec) 687 struct i40iw_msix_vector *msix_vec)
688{ 688{
689 enum i40iw_status_code status; 689 enum i40iw_status_code status;
690 cpumask_t mask;
691 690
692 if (iwdev->msix_shared && !ceq_id) { 691 if (iwdev->msix_shared && !ceq_id) {
693 tasklet_init(&iwdev->dpc_tasklet, i40iw_dpc, (unsigned long)iwdev); 692 tasklet_init(&iwdev->dpc_tasklet, i40iw_dpc, (unsigned long)iwdev);
@@ -697,9 +696,9 @@ static enum i40iw_status_code i40iw_configure_ceq_vector(struct i40iw_device *iw
697 status = request_irq(msix_vec->irq, i40iw_ceq_handler, 0, "CEQ", iwceq); 696 status = request_irq(msix_vec->irq, i40iw_ceq_handler, 0, "CEQ", iwceq);
698 } 697 }
699 698
700 cpumask_clear(&mask); 699 cpumask_clear(&msix_vec->mask);
701 cpumask_set_cpu(msix_vec->cpu_affinity, &mask); 700 cpumask_set_cpu(msix_vec->cpu_affinity, &msix_vec->mask);
702 irq_set_affinity_hint(msix_vec->irq, &mask); 701 irq_set_affinity_hint(msix_vec->irq, &msix_vec->mask);
703 702
704 if (status) { 703 if (status) {
705 i40iw_pr_err("ceq irq config fail\n"); 704 i40iw_pr_err("ceq irq config fail\n");
diff --git a/drivers/infiniband/hw/i40iw/i40iw_verbs.c b/drivers/infiniband/hw/i40iw/i40iw_verbs.c
index 40e4f5ab2b46..68679ad4c6da 100644
--- a/drivers/infiniband/hw/i40iw/i40iw_verbs.c
+++ b/drivers/infiniband/hw/i40iw/i40iw_verbs.c
@@ -394,6 +394,7 @@ static struct i40iw_pbl *i40iw_get_pbl(unsigned long va,
394 394
395 list_for_each_entry(iwpbl, pbl_list, list) { 395 list_for_each_entry(iwpbl, pbl_list, list) {
396 if (iwpbl->user_base == va) { 396 if (iwpbl->user_base == va) {
397 iwpbl->on_list = false;
397 list_del(&iwpbl->list); 398 list_del(&iwpbl->list);
398 return iwpbl; 399 return iwpbl;
399 } 400 }
@@ -614,6 +615,7 @@ static struct ib_qp *i40iw_create_qp(struct ib_pd *ibpd,
614 return ERR_PTR(-ENOMEM); 615 return ERR_PTR(-ENOMEM);
615 616
616 iwqp = (struct i40iw_qp *)mem; 617 iwqp = (struct i40iw_qp *)mem;
618 iwqp->allocated_buffer = mem;
617 qp = &iwqp->sc_qp; 619 qp = &iwqp->sc_qp;
618 qp->back_qp = (void *)iwqp; 620 qp->back_qp = (void *)iwqp;
619 qp->push_idx = I40IW_INVALID_PUSH_PAGE_INDEX; 621 qp->push_idx = I40IW_INVALID_PUSH_PAGE_INDEX;
@@ -642,7 +644,6 @@ static struct ib_qp *i40iw_create_qp(struct ib_pd *ibpd,
642 goto error; 644 goto error;
643 } 645 }
644 646
645 iwqp->allocated_buffer = mem;
646 iwqp->iwdev = iwdev; 647 iwqp->iwdev = iwdev;
647 iwqp->iwpd = iwpd; 648 iwqp->iwpd = iwpd;
648 iwqp->ibqp.qp_num = qp_num; 649 iwqp->ibqp.qp_num = qp_num;
@@ -1898,6 +1899,7 @@ static struct ib_mr *i40iw_reg_user_mr(struct ib_pd *pd,
1898 goto error; 1899 goto error;
1899 spin_lock_irqsave(&ucontext->qp_reg_mem_list_lock, flags); 1900 spin_lock_irqsave(&ucontext->qp_reg_mem_list_lock, flags);
1900 list_add_tail(&iwpbl->list, &ucontext->qp_reg_mem_list); 1901 list_add_tail(&iwpbl->list, &ucontext->qp_reg_mem_list);
1902 iwpbl->on_list = true;
1901 spin_unlock_irqrestore(&ucontext->qp_reg_mem_list_lock, flags); 1903 spin_unlock_irqrestore(&ucontext->qp_reg_mem_list_lock, flags);
1902 break; 1904 break;
1903 case IW_MEMREG_TYPE_CQ: 1905 case IW_MEMREG_TYPE_CQ:
@@ -1908,6 +1910,7 @@ static struct ib_mr *i40iw_reg_user_mr(struct ib_pd *pd,
1908 1910
1909 spin_lock_irqsave(&ucontext->cq_reg_mem_list_lock, flags); 1911 spin_lock_irqsave(&ucontext->cq_reg_mem_list_lock, flags);
1910 list_add_tail(&iwpbl->list, &ucontext->cq_reg_mem_list); 1912 list_add_tail(&iwpbl->list, &ucontext->cq_reg_mem_list);
1913 iwpbl->on_list = true;
1911 spin_unlock_irqrestore(&ucontext->cq_reg_mem_list_lock, flags); 1914 spin_unlock_irqrestore(&ucontext->cq_reg_mem_list_lock, flags);
1912 break; 1915 break;
1913 case IW_MEMREG_TYPE_MEM: 1916 case IW_MEMREG_TYPE_MEM:
@@ -2045,14 +2048,18 @@ static void i40iw_del_memlist(struct i40iw_mr *iwmr,
2045 switch (iwmr->type) { 2048 switch (iwmr->type) {
2046 case IW_MEMREG_TYPE_CQ: 2049 case IW_MEMREG_TYPE_CQ:
2047 spin_lock_irqsave(&ucontext->cq_reg_mem_list_lock, flags); 2050 spin_lock_irqsave(&ucontext->cq_reg_mem_list_lock, flags);
2048 if (!list_empty(&ucontext->cq_reg_mem_list)) 2051 if (iwpbl->on_list) {
2052 iwpbl->on_list = false;
2049 list_del(&iwpbl->list); 2053 list_del(&iwpbl->list);
2054 }
2050 spin_unlock_irqrestore(&ucontext->cq_reg_mem_list_lock, flags); 2055 spin_unlock_irqrestore(&ucontext->cq_reg_mem_list_lock, flags);
2051 break; 2056 break;
2052 case IW_MEMREG_TYPE_QP: 2057 case IW_MEMREG_TYPE_QP:
2053 spin_lock_irqsave(&ucontext->qp_reg_mem_list_lock, flags); 2058 spin_lock_irqsave(&ucontext->qp_reg_mem_list_lock, flags);
2054 if (!list_empty(&ucontext->qp_reg_mem_list)) 2059 if (iwpbl->on_list) {
2060 iwpbl->on_list = false;
2055 list_del(&iwpbl->list); 2061 list_del(&iwpbl->list);
2062 }
2056 spin_unlock_irqrestore(&ucontext->qp_reg_mem_list_lock, flags); 2063 spin_unlock_irqrestore(&ucontext->qp_reg_mem_list_lock, flags);
2057 break; 2064 break;
2058 default: 2065 default:
diff --git a/drivers/infiniband/hw/i40iw/i40iw_verbs.h b/drivers/infiniband/hw/i40iw/i40iw_verbs.h
index 9067443cd311..76cf173377ab 100644
--- a/drivers/infiniband/hw/i40iw/i40iw_verbs.h
+++ b/drivers/infiniband/hw/i40iw/i40iw_verbs.h
@@ -78,6 +78,7 @@ struct i40iw_pbl {
78 }; 78 };
79 79
80 bool pbl_allocated; 80 bool pbl_allocated;
81 bool on_list;
81 u64 user_base; 82 u64 user_base;
82 struct i40iw_pble_alloc pble_alloc; 83 struct i40iw_pble_alloc pble_alloc;
83 struct i40iw_mr *iwmr; 84 struct i40iw_mr *iwmr;
diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index b4d8ff8ab807..69716a7ea993 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -2416,7 +2416,7 @@ static void set_proto(void *outer_c, void *outer_v, u8 mask, u8 val)
2416 MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_protocol, val); 2416 MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_protocol, val);
2417} 2417}
2418 2418
2419static void set_flow_label(void *misc_c, void *misc_v, u8 mask, u8 val, 2419static void set_flow_label(void *misc_c, void *misc_v, u32 mask, u32 val,
2420 bool inner) 2420 bool inner)
2421{ 2421{
2422 if (inner) { 2422 if (inner) {
diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c
index 87b7c1be2a11..2193dc1765fb 100644
--- a/drivers/infiniband/hw/mlx5/qp.c
+++ b/drivers/infiniband/hw/mlx5/qp.c
@@ -484,11 +484,6 @@ static int qp_has_rq(struct ib_qp_init_attr *attr)
484 return 1; 484 return 1;
485} 485}
486 486
487static int first_med_bfreg(void)
488{
489 return 1;
490}
491
492enum { 487enum {
493 /* this is the first blue flame register in the array of bfregs assigned 488 /* this is the first blue flame register in the array of bfregs assigned
494 * to a processes. Since we do not use it for blue flame but rather 489 * to a processes. Since we do not use it for blue flame but rather
@@ -514,6 +509,12 @@ static int num_med_bfreg(struct mlx5_ib_dev *dev,
514 return n >= 0 ? n : 0; 509 return n >= 0 ? n : 0;
515} 510}
516 511
512static int first_med_bfreg(struct mlx5_ib_dev *dev,
513 struct mlx5_bfreg_info *bfregi)
514{
515 return num_med_bfreg(dev, bfregi) ? 1 : -ENOMEM;
516}
517
517static int first_hi_bfreg(struct mlx5_ib_dev *dev, 518static int first_hi_bfreg(struct mlx5_ib_dev *dev,
518 struct mlx5_bfreg_info *bfregi) 519 struct mlx5_bfreg_info *bfregi)
519{ 520{
@@ -541,10 +542,13 @@ static int alloc_high_class_bfreg(struct mlx5_ib_dev *dev,
541static int alloc_med_class_bfreg(struct mlx5_ib_dev *dev, 542static int alloc_med_class_bfreg(struct mlx5_ib_dev *dev,
542 struct mlx5_bfreg_info *bfregi) 543 struct mlx5_bfreg_info *bfregi)
543{ 544{
544 int minidx = first_med_bfreg(); 545 int minidx = first_med_bfreg(dev, bfregi);
545 int i; 546 int i;
546 547
547 for (i = first_med_bfreg(); i < first_hi_bfreg(dev, bfregi); i++) { 548 if (minidx < 0)
549 return minidx;
550
551 for (i = minidx; i < first_hi_bfreg(dev, bfregi); i++) {
548 if (bfregi->count[i] < bfregi->count[minidx]) 552 if (bfregi->count[i] < bfregi->count[minidx])
549 minidx = i; 553 minidx = i;
550 if (!bfregi->count[minidx]) 554 if (!bfregi->count[minidx])
diff --git a/drivers/infiniband/hw/qedr/verbs.c b/drivers/infiniband/hw/qedr/verbs.c
index 7d3763b2e01c..3f9afc02d166 100644
--- a/drivers/infiniband/hw/qedr/verbs.c
+++ b/drivers/infiniband/hw/qedr/verbs.c
@@ -401,49 +401,47 @@ int qedr_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
401{ 401{
402 struct qedr_ucontext *ucontext = get_qedr_ucontext(context); 402 struct qedr_ucontext *ucontext = get_qedr_ucontext(context);
403 struct qedr_dev *dev = get_qedr_dev(context->device); 403 struct qedr_dev *dev = get_qedr_dev(context->device);
404 unsigned long vm_page = vma->vm_pgoff << PAGE_SHIFT; 404 unsigned long phys_addr = vma->vm_pgoff << PAGE_SHIFT;
405 u64 unmapped_db = dev->db_phys_addr;
406 unsigned long len = (vma->vm_end - vma->vm_start); 405 unsigned long len = (vma->vm_end - vma->vm_start);
407 int rc = 0; 406 unsigned long dpi_start;
408 bool found; 407
408 dpi_start = dev->db_phys_addr + (ucontext->dpi * ucontext->dpi_size);
409 409
410 DP_DEBUG(dev, QEDR_MSG_INIT, 410 DP_DEBUG(dev, QEDR_MSG_INIT,
411 "qedr_mmap called vm_page=0x%lx vm_pgoff=0x%lx unmapped_db=0x%llx db_size=%x, len=%lx\n", 411 "mmap invoked with vm_start=0x%pK, vm_end=0x%pK,vm_pgoff=0x%pK; dpi_start=0x%pK dpi_size=0x%x\n",
412 vm_page, vma->vm_pgoff, unmapped_db, dev->db_size, len); 412 (void *)vma->vm_start, (void *)vma->vm_end,
413 if (vma->vm_start & (PAGE_SIZE - 1)) { 413 (void *)vma->vm_pgoff, (void *)dpi_start, ucontext->dpi_size);
414 DP_ERR(dev, "Vma_start not page aligned = %ld\n", 414
415 vma->vm_start); 415 if ((vma->vm_start & (PAGE_SIZE - 1)) || (len & (PAGE_SIZE - 1))) {
416 DP_ERR(dev,
417 "failed mmap, adrresses must be page aligned: start=0x%pK, end=0x%pK\n",
418 (void *)vma->vm_start, (void *)vma->vm_end);
416 return -EINVAL; 419 return -EINVAL;
417 } 420 }
418 421
419 found = qedr_search_mmap(ucontext, vm_page, len); 422 if (!qedr_search_mmap(ucontext, phys_addr, len)) {
420 if (!found) { 423 DP_ERR(dev, "failed mmap, vm_pgoff=0x%lx is not authorized\n",
421 DP_ERR(dev, "Vma_pgoff not found in mapped array = %ld\n",
422 vma->vm_pgoff); 424 vma->vm_pgoff);
423 return -EINVAL; 425 return -EINVAL;
424 } 426 }
425 427
426 DP_DEBUG(dev, QEDR_MSG_INIT, "Mapping doorbell bar\n"); 428 if (phys_addr < dpi_start ||
427 429 ((phys_addr + len) > (dpi_start + ucontext->dpi_size))) {
428 if ((vm_page >= unmapped_db) && (vm_page <= (unmapped_db + 430 DP_ERR(dev,
429 dev->db_size))) { 431 "failed mmap, pages are outside of dpi; page address=0x%pK, dpi_start=0x%pK, dpi_size=0x%x\n",
430 DP_DEBUG(dev, QEDR_MSG_INIT, "Mapping doorbell bar\n"); 432 (void *)phys_addr, (void *)dpi_start,
431 if (vma->vm_flags & VM_READ) { 433 ucontext->dpi_size);
432 DP_ERR(dev, "Trying to map doorbell bar for read\n"); 434 return -EINVAL;
433 return -EPERM; 435 }
434 }
435
436 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
437 436
438 rc = io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, 437 if (vma->vm_flags & VM_READ) {
439 PAGE_SIZE, vma->vm_page_prot); 438 DP_ERR(dev, "failed mmap, cannot map doorbell bar for read\n");
440 } else { 439 return -EINVAL;
441 DP_DEBUG(dev, QEDR_MSG_INIT, "Mapping chains\n");
442 rc = remap_pfn_range(vma, vma->vm_start,
443 vma->vm_pgoff, len, vma->vm_page_prot);
444 } 440 }
445 DP_DEBUG(dev, QEDR_MSG_INIT, "qedr_mmap return code: %d\n", rc); 441
446 return rc; 442 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
443 return io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, len,
444 vma->vm_page_prot);
447} 445}
448 446
449struct ib_pd *qedr_alloc_pd(struct ib_device *ibdev, 447struct ib_pd *qedr_alloc_pd(struct ib_device *ibdev,
diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c
index 2cb52fd48cf1..73a00a1c06f6 100644
--- a/drivers/infiniband/sw/rxe/rxe_verbs.c
+++ b/drivers/infiniband/sw/rxe/rxe_verbs.c
@@ -761,7 +761,6 @@ static int rxe_post_send_kernel(struct rxe_qp *qp, struct ib_send_wr *wr,
761 unsigned int mask; 761 unsigned int mask;
762 unsigned int length = 0; 762 unsigned int length = 0;
763 int i; 763 int i;
764 int must_sched;
765 764
766 while (wr) { 765 while (wr) {
767 mask = wr_opcode_mask(wr->opcode, qp); 766 mask = wr_opcode_mask(wr->opcode, qp);
@@ -791,14 +790,7 @@ static int rxe_post_send_kernel(struct rxe_qp *qp, struct ib_send_wr *wr,
791 wr = wr->next; 790 wr = wr->next;
792 } 791 }
793 792
794 /* 793 rxe_run_task(&qp->req.task, 1);
795 * Must sched in case of GSI QP because ib_send_mad() hold irq lock,
796 * and the requester call ip_local_out_sk() that takes spin_lock_bh.
797 */
798 must_sched = (qp_type(qp) == IB_QPT_GSI) ||
799 (queue_count(qp->sq.queue) > 1);
800
801 rxe_run_task(&qp->req.task, must_sched);
802 if (unlikely(qp->req.state == QP_STATE_ERROR)) 794 if (unlikely(qp->req.state == QP_STATE_ERROR))
803 rxe_run_task(&qp->comp.task, 1); 795 rxe_run_task(&qp->comp.task, 1);
804 796
diff --git a/drivers/infiniband/ulp/srpt/Kconfig b/drivers/infiniband/ulp/srpt/Kconfig
index fb8b7182f05e..25bf6955b6d0 100644
--- a/drivers/infiniband/ulp/srpt/Kconfig
+++ b/drivers/infiniband/ulp/srpt/Kconfig
@@ -1,6 +1,6 @@
1config INFINIBAND_SRPT 1config INFINIBAND_SRPT
2 tristate "InfiniBand SCSI RDMA Protocol target support" 2 tristate "InfiniBand SCSI RDMA Protocol target support"
3 depends on INFINIBAND && INFINIBAND_ADDR_TRANS && TARGET_CORE 3 depends on INFINIBAND_ADDR_TRANS && TARGET_CORE
4 ---help--- 4 ---help---
5 5
6 Support for the SCSI RDMA Protocol (SRP) Target driver. The 6 Support for the SCSI RDMA Protocol (SRP) Target driver. The
diff --git a/drivers/isdn/hardware/eicon/diva.c b/drivers/isdn/hardware/eicon/diva.c
index 944a7f338099..1b25d8bc153a 100644
--- a/drivers/isdn/hardware/eicon/diva.c
+++ b/drivers/isdn/hardware/eicon/diva.c
@@ -388,10 +388,10 @@ void divasa_xdi_driver_unload(void)
388** Receive and process command from user mode utility 388** Receive and process command from user mode utility
389*/ 389*/
390void *diva_xdi_open_adapter(void *os_handle, const void __user *src, 390void *diva_xdi_open_adapter(void *os_handle, const void __user *src,
391 int length, 391 int length, void *mptr,
392 divas_xdi_copy_from_user_fn_t cp_fn) 392 divas_xdi_copy_from_user_fn_t cp_fn)
393{ 393{
394 diva_xdi_um_cfg_cmd_t msg; 394 diva_xdi_um_cfg_cmd_t *msg = (diva_xdi_um_cfg_cmd_t *)mptr;
395 diva_os_xdi_adapter_t *a = NULL; 395 diva_os_xdi_adapter_t *a = NULL;
396 diva_os_spin_lock_magic_t old_irql; 396 diva_os_spin_lock_magic_t old_irql;
397 struct list_head *tmp; 397 struct list_head *tmp;
@@ -401,21 +401,21 @@ void *diva_xdi_open_adapter(void *os_handle, const void __user *src,
401 length, sizeof(diva_xdi_um_cfg_cmd_t))) 401 length, sizeof(diva_xdi_um_cfg_cmd_t)))
402 return NULL; 402 return NULL;
403 } 403 }
404 if ((*cp_fn) (os_handle, &msg, src, sizeof(msg)) <= 0) { 404 if ((*cp_fn) (os_handle, msg, src, sizeof(*msg)) <= 0) {
405 DBG_ERR(("A: A(?) open, write error")) 405 DBG_ERR(("A: A(?) open, write error"))
406 return NULL; 406 return NULL;
407 } 407 }
408 diva_os_enter_spin_lock(&adapter_lock, &old_irql, "open_adapter"); 408 diva_os_enter_spin_lock(&adapter_lock, &old_irql, "open_adapter");
409 list_for_each(tmp, &adapter_queue) { 409 list_for_each(tmp, &adapter_queue) {
410 a = list_entry(tmp, diva_os_xdi_adapter_t, link); 410 a = list_entry(tmp, diva_os_xdi_adapter_t, link);
411 if (a->controller == (int)msg.adapter) 411 if (a->controller == (int)msg->adapter)
412 break; 412 break;
413 a = NULL; 413 a = NULL;
414 } 414 }
415 diva_os_leave_spin_lock(&adapter_lock, &old_irql, "open_adapter"); 415 diva_os_leave_spin_lock(&adapter_lock, &old_irql, "open_adapter");
416 416
417 if (!a) { 417 if (!a) {
418 DBG_ERR(("A: A(%d) open, adapter not found", msg.adapter)) 418 DBG_ERR(("A: A(%d) open, adapter not found", msg->adapter))
419 } 419 }
420 420
421 return (a); 421 return (a);
@@ -437,8 +437,10 @@ void diva_xdi_close_adapter(void *adapter, void *os_handle)
437 437
438int 438int
439diva_xdi_write(void *adapter, void *os_handle, const void __user *src, 439diva_xdi_write(void *adapter, void *os_handle, const void __user *src,
440 int length, divas_xdi_copy_from_user_fn_t cp_fn) 440 int length, void *mptr,
441 divas_xdi_copy_from_user_fn_t cp_fn)
441{ 442{
443 diva_xdi_um_cfg_cmd_t *msg = (diva_xdi_um_cfg_cmd_t *)mptr;
442 diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) adapter; 444 diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) adapter;
443 void *data; 445 void *data;
444 446
@@ -459,7 +461,13 @@ diva_xdi_write(void *adapter, void *os_handle, const void __user *src,
459 return (-2); 461 return (-2);
460 } 462 }
461 463
462 length = (*cp_fn) (os_handle, data, src, length); 464 if (msg) {
465 *(diva_xdi_um_cfg_cmd_t *)data = *msg;
466 length = (*cp_fn) (os_handle, (char *)data + sizeof(*msg),
467 src + sizeof(*msg), length - sizeof(*msg));
468 } else {
469 length = (*cp_fn) (os_handle, data, src, length);
470 }
463 if (length > 0) { 471 if (length > 0) {
464 if ((*(a->interface.cmd_proc)) 472 if ((*(a->interface.cmd_proc))
465 (a, (diva_xdi_um_cfg_cmd_t *) data, length)) { 473 (a, (diva_xdi_um_cfg_cmd_t *) data, length)) {
diff --git a/drivers/isdn/hardware/eicon/diva.h b/drivers/isdn/hardware/eicon/diva.h
index b067032093a8..1ad76650fbf9 100644
--- a/drivers/isdn/hardware/eicon/diva.h
+++ b/drivers/isdn/hardware/eicon/diva.h
@@ -20,10 +20,11 @@ int diva_xdi_read(void *adapter, void *os_handle, void __user *dst,
20 int max_length, divas_xdi_copy_to_user_fn_t cp_fn); 20 int max_length, divas_xdi_copy_to_user_fn_t cp_fn);
21 21
22int diva_xdi_write(void *adapter, void *os_handle, const void __user *src, 22int diva_xdi_write(void *adapter, void *os_handle, const void __user *src,
23 int length, divas_xdi_copy_from_user_fn_t cp_fn); 23 int length, void *msg,
24 divas_xdi_copy_from_user_fn_t cp_fn);
24 25
25void *diva_xdi_open_adapter(void *os_handle, const void __user *src, 26void *diva_xdi_open_adapter(void *os_handle, const void __user *src,
26 int length, 27 int length, void *msg,
27 divas_xdi_copy_from_user_fn_t cp_fn); 28 divas_xdi_copy_from_user_fn_t cp_fn);
28 29
29void diva_xdi_close_adapter(void *adapter, void *os_handle); 30void diva_xdi_close_adapter(void *adapter, void *os_handle);
diff --git a/drivers/isdn/hardware/eicon/divasmain.c b/drivers/isdn/hardware/eicon/divasmain.c
index b9980e84f9db..b6a3950b2564 100644
--- a/drivers/isdn/hardware/eicon/divasmain.c
+++ b/drivers/isdn/hardware/eicon/divasmain.c
@@ -591,19 +591,22 @@ static int divas_release(struct inode *inode, struct file *file)
591static ssize_t divas_write(struct file *file, const char __user *buf, 591static ssize_t divas_write(struct file *file, const char __user *buf,
592 size_t count, loff_t *ppos) 592 size_t count, loff_t *ppos)
593{ 593{
594 diva_xdi_um_cfg_cmd_t msg;
594 int ret = -EINVAL; 595 int ret = -EINVAL;
595 596
596 if (!file->private_data) { 597 if (!file->private_data) {
597 file->private_data = diva_xdi_open_adapter(file, buf, 598 file->private_data = diva_xdi_open_adapter(file, buf,
598 count, 599 count, &msg,
599 xdi_copy_from_user); 600 xdi_copy_from_user);
600 } 601 if (!file->private_data)
601 if (!file->private_data) { 602 return (-ENODEV);
602 return (-ENODEV); 603 ret = diva_xdi_write(file->private_data, file,
604 buf, count, &msg, xdi_copy_from_user);
605 } else {
606 ret = diva_xdi_write(file->private_data, file,
607 buf, count, NULL, xdi_copy_from_user);
603 } 608 }
604 609
605 ret = diva_xdi_write(file->private_data, file,
606 buf, count, xdi_copy_from_user);
607 switch (ret) { 610 switch (ret) {
608 case -1: /* Message should be removed from rx mailbox first */ 611 case -1: /* Message should be removed from rx mailbox first */
609 ret = -EBUSY; 612 ret = -EBUSY;
@@ -622,11 +625,12 @@ static ssize_t divas_write(struct file *file, const char __user *buf,
622static ssize_t divas_read(struct file *file, char __user *buf, 625static ssize_t divas_read(struct file *file, char __user *buf,
623 size_t count, loff_t *ppos) 626 size_t count, loff_t *ppos)
624{ 627{
628 diva_xdi_um_cfg_cmd_t msg;
625 int ret = -EINVAL; 629 int ret = -EINVAL;
626 630
627 if (!file->private_data) { 631 if (!file->private_data) {
628 file->private_data = diva_xdi_open_adapter(file, buf, 632 file->private_data = diva_xdi_open_adapter(file, buf,
629 count, 633 count, &msg,
630 xdi_copy_from_user); 634 xdi_copy_from_user);
631 } 635 }
632 if (!file->private_data) { 636 if (!file->private_data) {
diff --git a/drivers/mfd/cros_ec_spi.c b/drivers/mfd/cros_ec_spi.c
index 1b52b8557034..2060d1483043 100644
--- a/drivers/mfd/cros_ec_spi.c
+++ b/drivers/mfd/cros_ec_spi.c
@@ -419,10 +419,25 @@ static int cros_ec_pkt_xfer_spi(struct cros_ec_device *ec_dev,
419 /* Verify that EC can process command */ 419 /* Verify that EC can process command */
420 for (i = 0; i < len; i++) { 420 for (i = 0; i < len; i++) {
421 rx_byte = rx_buf[i]; 421 rx_byte = rx_buf[i];
422 /*
423 * Seeing the PAST_END, RX_BAD_DATA, or NOT_READY
424 * markers are all signs that the EC didn't fully
425 * receive our command. e.g., if the EC is flashing
426 * itself, it can't respond to any commands and instead
427 * clocks out EC_SPI_PAST_END from its SPI hardware
428 * buffer. Similar occurrences can happen if the AP is
429 * too slow to clock out data after asserting CS -- the
430 * EC will abort and fill its buffer with
431 * EC_SPI_RX_BAD_DATA.
432 *
433 * In all cases, these errors should be safe to retry.
434 * Report -EAGAIN and let the caller decide what to do
435 * about that.
436 */
422 if (rx_byte == EC_SPI_PAST_END || 437 if (rx_byte == EC_SPI_PAST_END ||
423 rx_byte == EC_SPI_RX_BAD_DATA || 438 rx_byte == EC_SPI_RX_BAD_DATA ||
424 rx_byte == EC_SPI_NOT_READY) { 439 rx_byte == EC_SPI_NOT_READY) {
425 ret = -EREMOTEIO; 440 ret = -EAGAIN;
426 break; 441 break;
427 } 442 }
428 } 443 }
@@ -431,7 +446,7 @@ static int cros_ec_pkt_xfer_spi(struct cros_ec_device *ec_dev,
431 if (!ret) 446 if (!ret)
432 ret = cros_ec_spi_receive_packet(ec_dev, 447 ret = cros_ec_spi_receive_packet(ec_dev,
433 ec_msg->insize + sizeof(*response)); 448 ec_msg->insize + sizeof(*response));
434 else 449 else if (ret != -EAGAIN)
435 dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); 450 dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret);
436 451
437 final_ret = terminate_request(ec_dev); 452 final_ret = terminate_request(ec_dev);
@@ -537,10 +552,11 @@ static int cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev,
537 /* Verify that EC can process command */ 552 /* Verify that EC can process command */
538 for (i = 0; i < len; i++) { 553 for (i = 0; i < len; i++) {
539 rx_byte = rx_buf[i]; 554 rx_byte = rx_buf[i];
555 /* See comments in cros_ec_pkt_xfer_spi() */
540 if (rx_byte == EC_SPI_PAST_END || 556 if (rx_byte == EC_SPI_PAST_END ||
541 rx_byte == EC_SPI_RX_BAD_DATA || 557 rx_byte == EC_SPI_RX_BAD_DATA ||
542 rx_byte == EC_SPI_NOT_READY) { 558 rx_byte == EC_SPI_NOT_READY) {
543 ret = -EREMOTEIO; 559 ret = -EAGAIN;
544 break; 560 break;
545 } 561 }
546 } 562 }
@@ -549,7 +565,7 @@ static int cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev,
549 if (!ret) 565 if (!ret)
550 ret = cros_ec_spi_receive_response(ec_dev, 566 ret = cros_ec_spi_receive_response(ec_dev,
551 ec_msg->insize + EC_MSG_TX_PROTO_BYTES); 567 ec_msg->insize + EC_MSG_TX_PROTO_BYTES);
552 else 568 else if (ret != -EAGAIN)
553 dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); 569 dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret);
554 570
555 final_ret = terminate_request(ec_dev); 571 final_ret = terminate_request(ec_dev);
diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 9e923cd1d80e..38a7586b00cc 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -2485,7 +2485,7 @@ static long mmc_rpmb_ioctl(struct file *filp, unsigned int cmd,
2485 break; 2485 break;
2486 } 2486 }
2487 2487
2488 return 0; 2488 return ret;
2489} 2489}
2490 2490
2491#ifdef CONFIG_COMPAT 2491#ifdef CONFIG_COMPAT
diff --git a/drivers/mmc/host/sdhci-iproc.c b/drivers/mmc/host/sdhci-iproc.c
index 0ef741bc515d..d0e83db42ae5 100644
--- a/drivers/mmc/host/sdhci-iproc.c
+++ b/drivers/mmc/host/sdhci-iproc.c
@@ -33,6 +33,8 @@ struct sdhci_iproc_host {
33 const struct sdhci_iproc_data *data; 33 const struct sdhci_iproc_data *data;
34 u32 shadow_cmd; 34 u32 shadow_cmd;
35 u32 shadow_blk; 35 u32 shadow_blk;
36 bool is_cmd_shadowed;
37 bool is_blk_shadowed;
36}; 38};
37 39
38#define REG_OFFSET_IN_BITS(reg) ((reg) << 3 & 0x18) 40#define REG_OFFSET_IN_BITS(reg) ((reg) << 3 & 0x18)
@@ -48,8 +50,22 @@ static inline u32 sdhci_iproc_readl(struct sdhci_host *host, int reg)
48 50
49static u16 sdhci_iproc_readw(struct sdhci_host *host, int reg) 51static u16 sdhci_iproc_readw(struct sdhci_host *host, int reg)
50{ 52{
51 u32 val = sdhci_iproc_readl(host, (reg & ~3)); 53 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
52 u16 word = val >> REG_OFFSET_IN_BITS(reg) & 0xffff; 54 struct sdhci_iproc_host *iproc_host = sdhci_pltfm_priv(pltfm_host);
55 u32 val;
56 u16 word;
57
58 if ((reg == SDHCI_TRANSFER_MODE) && iproc_host->is_cmd_shadowed) {
59 /* Get the saved transfer mode */
60 val = iproc_host->shadow_cmd;
61 } else if ((reg == SDHCI_BLOCK_SIZE || reg == SDHCI_BLOCK_COUNT) &&
62 iproc_host->is_blk_shadowed) {
63 /* Get the saved block info */
64 val = iproc_host->shadow_blk;
65 } else {
66 val = sdhci_iproc_readl(host, (reg & ~3));
67 }
68 word = val >> REG_OFFSET_IN_BITS(reg) & 0xffff;
53 return word; 69 return word;
54} 70}
55 71
@@ -105,13 +121,15 @@ static void sdhci_iproc_writew(struct sdhci_host *host, u16 val, int reg)
105 121
106 if (reg == SDHCI_COMMAND) { 122 if (reg == SDHCI_COMMAND) {
107 /* Write the block now as we are issuing a command */ 123 /* Write the block now as we are issuing a command */
108 if (iproc_host->shadow_blk != 0) { 124 if (iproc_host->is_blk_shadowed) {
109 sdhci_iproc_writel(host, iproc_host->shadow_blk, 125 sdhci_iproc_writel(host, iproc_host->shadow_blk,
110 SDHCI_BLOCK_SIZE); 126 SDHCI_BLOCK_SIZE);
111 iproc_host->shadow_blk = 0; 127 iproc_host->is_blk_shadowed = false;
112 } 128 }
113 oldval = iproc_host->shadow_cmd; 129 oldval = iproc_host->shadow_cmd;
114 } else if (reg == SDHCI_BLOCK_SIZE || reg == SDHCI_BLOCK_COUNT) { 130 iproc_host->is_cmd_shadowed = false;
131 } else if ((reg == SDHCI_BLOCK_SIZE || reg == SDHCI_BLOCK_COUNT) &&
132 iproc_host->is_blk_shadowed) {
115 /* Block size and count are stored in shadow reg */ 133 /* Block size and count are stored in shadow reg */
116 oldval = iproc_host->shadow_blk; 134 oldval = iproc_host->shadow_blk;
117 } else { 135 } else {
@@ -123,9 +141,11 @@ static void sdhci_iproc_writew(struct sdhci_host *host, u16 val, int reg)
123 if (reg == SDHCI_TRANSFER_MODE) { 141 if (reg == SDHCI_TRANSFER_MODE) {
124 /* Save the transfer mode until the command is issued */ 142 /* Save the transfer mode until the command is issued */
125 iproc_host->shadow_cmd = newval; 143 iproc_host->shadow_cmd = newval;
144 iproc_host->is_cmd_shadowed = true;
126 } else if (reg == SDHCI_BLOCK_SIZE || reg == SDHCI_BLOCK_COUNT) { 145 } else if (reg == SDHCI_BLOCK_SIZE || reg == SDHCI_BLOCK_COUNT) {
127 /* Save the block info until the command is issued */ 146 /* Save the block info until the command is issued */
128 iproc_host->shadow_blk = newval; 147 iproc_host->shadow_blk = newval;
148 iproc_host->is_blk_shadowed = true;
129 } else { 149 } else {
130 /* Command or other regular 32-bit write */ 150 /* Command or other regular 32-bit write */
131 sdhci_iproc_writel(host, newval, reg & ~3); 151 sdhci_iproc_writel(host, newval, reg & ~3);
@@ -166,7 +186,7 @@ static const struct sdhci_ops sdhci_iproc_32only_ops = {
166 186
167static const struct sdhci_pltfm_data sdhci_iproc_cygnus_pltfm_data = { 187static const struct sdhci_pltfm_data sdhci_iproc_cygnus_pltfm_data = {
168 .quirks = SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK, 188 .quirks = SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK,
169 .quirks2 = SDHCI_QUIRK2_ACMD23_BROKEN, 189 .quirks2 = SDHCI_QUIRK2_ACMD23_BROKEN | SDHCI_QUIRK2_HOST_OFF_CARD_ON,
170 .ops = &sdhci_iproc_32only_ops, 190 .ops = &sdhci_iproc_32only_ops,
171}; 191};
172 192
@@ -206,7 +226,6 @@ static const struct sdhci_iproc_data iproc_data = {
206 .caps1 = SDHCI_DRIVER_TYPE_C | 226 .caps1 = SDHCI_DRIVER_TYPE_C |
207 SDHCI_DRIVER_TYPE_D | 227 SDHCI_DRIVER_TYPE_D |
208 SDHCI_SUPPORT_DDR50, 228 SDHCI_SUPPORT_DDR50,
209 .mmc_caps = MMC_CAP_1_8V_DDR,
210}; 229};
211 230
212static const struct sdhci_pltfm_data sdhci_bcm2835_pltfm_data = { 231static const struct sdhci_pltfm_data sdhci_bcm2835_pltfm_data = {
diff --git a/drivers/net/dsa/bcm_sf2_cfp.c b/drivers/net/dsa/bcm_sf2_cfp.c
index 23b45da784cb..b89acaee12d4 100644
--- a/drivers/net/dsa/bcm_sf2_cfp.c
+++ b/drivers/net/dsa/bcm_sf2_cfp.c
@@ -354,10 +354,13 @@ static int bcm_sf2_cfp_ipv4_rule_set(struct bcm_sf2_priv *priv, int port,
354 /* Locate the first rule available */ 354 /* Locate the first rule available */
355 if (fs->location == RX_CLS_LOC_ANY) 355 if (fs->location == RX_CLS_LOC_ANY)
356 rule_index = find_first_zero_bit(priv->cfp.used, 356 rule_index = find_first_zero_bit(priv->cfp.used,
357 bcm_sf2_cfp_rule_size(priv)); 357 priv->num_cfp_rules);
358 else 358 else
359 rule_index = fs->location; 359 rule_index = fs->location;
360 360
361 if (rule_index > bcm_sf2_cfp_rule_size(priv))
362 return -ENOSPC;
363
361 layout = &udf_tcpip4_layout; 364 layout = &udf_tcpip4_layout;
362 /* We only use one UDF slice for now */ 365 /* We only use one UDF slice for now */
363 slice_num = bcm_sf2_get_slice_number(layout, 0); 366 slice_num = bcm_sf2_get_slice_number(layout, 0);
@@ -562,19 +565,21 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,
562 * first half because the HW search is by incrementing addresses. 565 * first half because the HW search is by incrementing addresses.
563 */ 566 */
564 if (fs->location == RX_CLS_LOC_ANY) 567 if (fs->location == RX_CLS_LOC_ANY)
565 rule_index[0] = find_first_zero_bit(priv->cfp.used, 568 rule_index[1] = find_first_zero_bit(priv->cfp.used,
566 bcm_sf2_cfp_rule_size(priv)); 569 priv->num_cfp_rules);
567 else 570 else
568 rule_index[0] = fs->location; 571 rule_index[1] = fs->location;
572 if (rule_index[1] > bcm_sf2_cfp_rule_size(priv))
573 return -ENOSPC;
569 574
570 /* Flag it as used (cleared on error path) such that we can immediately 575 /* Flag it as used (cleared on error path) such that we can immediately
571 * obtain a second one to chain from. 576 * obtain a second one to chain from.
572 */ 577 */
573 set_bit(rule_index[0], priv->cfp.used); 578 set_bit(rule_index[1], priv->cfp.used);
574 579
575 rule_index[1] = find_first_zero_bit(priv->cfp.used, 580 rule_index[0] = find_first_zero_bit(priv->cfp.used,
576 bcm_sf2_cfp_rule_size(priv)); 581 priv->num_cfp_rules);
577 if (rule_index[1] > bcm_sf2_cfp_rule_size(priv)) { 582 if (rule_index[0] > bcm_sf2_cfp_rule_size(priv)) {
578 ret = -ENOSPC; 583 ret = -ENOSPC;
579 goto out_err; 584 goto out_err;
580 } 585 }
@@ -712,14 +717,14 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,
712 /* Flag the second half rule as being used now, return it as the 717 /* Flag the second half rule as being used now, return it as the
713 * location, and flag it as unique while dumping rules 718 * location, and flag it as unique while dumping rules
714 */ 719 */
715 set_bit(rule_index[1], priv->cfp.used); 720 set_bit(rule_index[0], priv->cfp.used);
716 set_bit(rule_index[1], priv->cfp.unique); 721 set_bit(rule_index[1], priv->cfp.unique);
717 fs->location = rule_index[1]; 722 fs->location = rule_index[1];
718 723
719 return ret; 724 return ret;
720 725
721out_err: 726out_err:
722 clear_bit(rule_index[0], priv->cfp.used); 727 clear_bit(rule_index[1], priv->cfp.used);
723 return ret; 728 return ret;
724} 729}
725 730
@@ -785,10 +790,6 @@ static int bcm_sf2_cfp_rule_del_one(struct bcm_sf2_priv *priv, int port,
785 int ret; 790 int ret;
786 u32 reg; 791 u32 reg;
787 792
788 /* Refuse deletion of unused rules, and the default reserved rule */
789 if (!test_bit(loc, priv->cfp.used) || loc == 0)
790 return -EINVAL;
791
792 /* Indicate which rule we want to read */ 793 /* Indicate which rule we want to read */
793 bcm_sf2_cfp_rule_addr_set(priv, loc); 794 bcm_sf2_cfp_rule_addr_set(priv, loc);
794 795
@@ -826,6 +827,13 @@ static int bcm_sf2_cfp_rule_del(struct bcm_sf2_priv *priv, int port,
826 u32 next_loc = 0; 827 u32 next_loc = 0;
827 int ret; 828 int ret;
828 829
830 /* Refuse deleting unused rules, and those that are not unique since
831 * that could leave IPv6 rules with one of the chained rule in the
832 * table.
833 */
834 if (!test_bit(loc, priv->cfp.unique) || loc == 0)
835 return -EINVAL;
836
829 ret = bcm_sf2_cfp_rule_del_one(priv, port, loc, &next_loc); 837 ret = bcm_sf2_cfp_rule_del_one(priv, port, loc, &next_loc);
830 if (ret) 838 if (ret)
831 return ret; 839 return ret;
diff --git a/drivers/net/ethernet/3com/3c59x.c b/drivers/net/ethernet/3com/3c59x.c
index 36c8950dbd2d..176861bd2252 100644
--- a/drivers/net/ethernet/3com/3c59x.c
+++ b/drivers/net/ethernet/3com/3c59x.c
@@ -1212,9 +1212,9 @@ static int vortex_probe1(struct device *gendev, void __iomem *ioaddr, int irq,
1212 vp->mii.reg_num_mask = 0x1f; 1212 vp->mii.reg_num_mask = 0x1f;
1213 1213
1214 /* Makes sure rings are at least 16 byte aligned. */ 1214 /* Makes sure rings are at least 16 byte aligned. */
1215 vp->rx_ring = pci_alloc_consistent(pdev, sizeof(struct boom_rx_desc) * RX_RING_SIZE 1215 vp->rx_ring = dma_alloc_coherent(gendev, sizeof(struct boom_rx_desc) * RX_RING_SIZE
1216 + sizeof(struct boom_tx_desc) * TX_RING_SIZE, 1216 + sizeof(struct boom_tx_desc) * TX_RING_SIZE,
1217 &vp->rx_ring_dma); 1217 &vp->rx_ring_dma, GFP_KERNEL);
1218 retval = -ENOMEM; 1218 retval = -ENOMEM;
1219 if (!vp->rx_ring) 1219 if (!vp->rx_ring)
1220 goto free_device; 1220 goto free_device;
@@ -1476,11 +1476,10 @@ static int vortex_probe1(struct device *gendev, void __iomem *ioaddr, int irq,
1476 return 0; 1476 return 0;
1477 1477
1478free_ring: 1478free_ring:
1479 pci_free_consistent(pdev, 1479 dma_free_coherent(&pdev->dev,
1480 sizeof(struct boom_rx_desc) * RX_RING_SIZE 1480 sizeof(struct boom_rx_desc) * RX_RING_SIZE +
1481 + sizeof(struct boom_tx_desc) * TX_RING_SIZE, 1481 sizeof(struct boom_tx_desc) * TX_RING_SIZE,
1482 vp->rx_ring, 1482 vp->rx_ring, vp->rx_ring_dma);
1483 vp->rx_ring_dma);
1484free_device: 1483free_device:
1485 free_netdev(dev); 1484 free_netdev(dev);
1486 pr_err(PFX "vortex_probe1 fails. Returns %d\n", retval); 1485 pr_err(PFX "vortex_probe1 fails. Returns %d\n", retval);
@@ -1751,9 +1750,9 @@ vortex_open(struct net_device *dev)
1751 break; /* Bad news! */ 1750 break; /* Bad news! */
1752 1751
1753 skb_reserve(skb, NET_IP_ALIGN); /* Align IP on 16 byte boundaries */ 1752 skb_reserve(skb, NET_IP_ALIGN); /* Align IP on 16 byte boundaries */
1754 dma = pci_map_single(VORTEX_PCI(vp), skb->data, 1753 dma = dma_map_single(vp->gendev, skb->data,
1755 PKT_BUF_SZ, PCI_DMA_FROMDEVICE); 1754 PKT_BUF_SZ, DMA_FROM_DEVICE);
1756 if (dma_mapping_error(&VORTEX_PCI(vp)->dev, dma)) 1755 if (dma_mapping_error(vp->gendev, dma))
1757 break; 1756 break;
1758 vp->rx_ring[i].addr = cpu_to_le32(dma); 1757 vp->rx_ring[i].addr = cpu_to_le32(dma);
1759 } 1758 }
@@ -2067,9 +2066,9 @@ vortex_start_xmit(struct sk_buff *skb, struct net_device *dev)
2067 if (vp->bus_master) { 2066 if (vp->bus_master) {
2068 /* Set the bus-master controller to transfer the packet. */ 2067 /* Set the bus-master controller to transfer the packet. */
2069 int len = (skb->len + 3) & ~3; 2068 int len = (skb->len + 3) & ~3;
2070 vp->tx_skb_dma = pci_map_single(VORTEX_PCI(vp), skb->data, len, 2069 vp->tx_skb_dma = dma_map_single(vp->gendev, skb->data, len,
2071 PCI_DMA_TODEVICE); 2070 DMA_TO_DEVICE);
2072 if (dma_mapping_error(&VORTEX_PCI(vp)->dev, vp->tx_skb_dma)) { 2071 if (dma_mapping_error(vp->gendev, vp->tx_skb_dma)) {
2073 dev_kfree_skb_any(skb); 2072 dev_kfree_skb_any(skb);
2074 dev->stats.tx_dropped++; 2073 dev->stats.tx_dropped++;
2075 return NETDEV_TX_OK; 2074 return NETDEV_TX_OK;
@@ -2168,9 +2167,9 @@ boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev)
2168 vp->tx_ring[entry].status = cpu_to_le32(skb->len | TxIntrUploaded | AddTCPChksum | AddUDPChksum); 2167 vp->tx_ring[entry].status = cpu_to_le32(skb->len | TxIntrUploaded | AddTCPChksum | AddUDPChksum);
2169 2168
2170 if (!skb_shinfo(skb)->nr_frags) { 2169 if (!skb_shinfo(skb)->nr_frags) {
2171 dma_addr = pci_map_single(VORTEX_PCI(vp), skb->data, skb->len, 2170 dma_addr = dma_map_single(vp->gendev, skb->data, skb->len,
2172 PCI_DMA_TODEVICE); 2171 DMA_TO_DEVICE);
2173 if (dma_mapping_error(&VORTEX_PCI(vp)->dev, dma_addr)) 2172 if (dma_mapping_error(vp->gendev, dma_addr))
2174 goto out_dma_err; 2173 goto out_dma_err;
2175 2174
2176 vp->tx_ring[entry].frag[0].addr = cpu_to_le32(dma_addr); 2175 vp->tx_ring[entry].frag[0].addr = cpu_to_le32(dma_addr);
@@ -2178,9 +2177,9 @@ boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev)
2178 } else { 2177 } else {
2179 int i; 2178 int i;
2180 2179
2181 dma_addr = pci_map_single(VORTEX_PCI(vp), skb->data, 2180 dma_addr = dma_map_single(vp->gendev, skb->data,
2182 skb_headlen(skb), PCI_DMA_TODEVICE); 2181 skb_headlen(skb), DMA_TO_DEVICE);
2183 if (dma_mapping_error(&VORTEX_PCI(vp)->dev, dma_addr)) 2182 if (dma_mapping_error(vp->gendev, dma_addr))
2184 goto out_dma_err; 2183 goto out_dma_err;
2185 2184
2186 vp->tx_ring[entry].frag[0].addr = cpu_to_le32(dma_addr); 2185 vp->tx_ring[entry].frag[0].addr = cpu_to_le32(dma_addr);
@@ -2189,21 +2188,21 @@ boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev)
2189 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { 2188 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
2190 skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 2189 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2191 2190
2192 dma_addr = skb_frag_dma_map(&VORTEX_PCI(vp)->dev, frag, 2191 dma_addr = skb_frag_dma_map(vp->gendev, frag,
2193 0, 2192 0,
2194 frag->size, 2193 frag->size,
2195 DMA_TO_DEVICE); 2194 DMA_TO_DEVICE);
2196 if (dma_mapping_error(&VORTEX_PCI(vp)->dev, dma_addr)) { 2195 if (dma_mapping_error(vp->gendev, dma_addr)) {
2197 for(i = i-1; i >= 0; i--) 2196 for(i = i-1; i >= 0; i--)
2198 dma_unmap_page(&VORTEX_PCI(vp)->dev, 2197 dma_unmap_page(vp->gendev,
2199 le32_to_cpu(vp->tx_ring[entry].frag[i+1].addr), 2198 le32_to_cpu(vp->tx_ring[entry].frag[i+1].addr),
2200 le32_to_cpu(vp->tx_ring[entry].frag[i+1].length), 2199 le32_to_cpu(vp->tx_ring[entry].frag[i+1].length),
2201 DMA_TO_DEVICE); 2200 DMA_TO_DEVICE);
2202 2201
2203 pci_unmap_single(VORTEX_PCI(vp), 2202 dma_unmap_single(vp->gendev,
2204 le32_to_cpu(vp->tx_ring[entry].frag[0].addr), 2203 le32_to_cpu(vp->tx_ring[entry].frag[0].addr),
2205 le32_to_cpu(vp->tx_ring[entry].frag[0].length), 2204 le32_to_cpu(vp->tx_ring[entry].frag[0].length),
2206 PCI_DMA_TODEVICE); 2205 DMA_TO_DEVICE);
2207 2206
2208 goto out_dma_err; 2207 goto out_dma_err;
2209 } 2208 }
@@ -2218,8 +2217,8 @@ boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev)
2218 } 2217 }
2219 } 2218 }
2220#else 2219#else
2221 dma_addr = pci_map_single(VORTEX_PCI(vp), skb->data, skb->len, PCI_DMA_TODEVICE); 2220 dma_addr = dma_map_single(vp->gendev, skb->data, skb->len, DMA_TO_DEVICE);
2222 if (dma_mapping_error(&VORTEX_PCI(vp)->dev, dma_addr)) 2221 if (dma_mapping_error(vp->gendev, dma_addr))
2223 goto out_dma_err; 2222 goto out_dma_err;
2224 vp->tx_ring[entry].addr = cpu_to_le32(dma_addr); 2223 vp->tx_ring[entry].addr = cpu_to_le32(dma_addr);
2225 vp->tx_ring[entry].length = cpu_to_le32(skb->len | LAST_FRAG); 2224 vp->tx_ring[entry].length = cpu_to_le32(skb->len | LAST_FRAG);
@@ -2254,7 +2253,7 @@ boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev)
2254out: 2253out:
2255 return NETDEV_TX_OK; 2254 return NETDEV_TX_OK;
2256out_dma_err: 2255out_dma_err:
2257 dev_err(&VORTEX_PCI(vp)->dev, "Error mapping dma buffer\n"); 2256 dev_err(vp->gendev, "Error mapping dma buffer\n");
2258 goto out; 2257 goto out;
2259} 2258}
2260 2259
@@ -2322,7 +2321,7 @@ vortex_interrupt(int irq, void *dev_id)
2322 if (status & DMADone) { 2321 if (status & DMADone) {
2323 if (ioread16(ioaddr + Wn7_MasterStatus) & 0x1000) { 2322 if (ioread16(ioaddr + Wn7_MasterStatus) & 0x1000) {
2324 iowrite16(0x1000, ioaddr + Wn7_MasterStatus); /* Ack the event. */ 2323 iowrite16(0x1000, ioaddr + Wn7_MasterStatus); /* Ack the event. */
2325 pci_unmap_single(VORTEX_PCI(vp), vp->tx_skb_dma, (vp->tx_skb->len + 3) & ~3, PCI_DMA_TODEVICE); 2324 dma_unmap_single(vp->gendev, vp->tx_skb_dma, (vp->tx_skb->len + 3) & ~3, DMA_TO_DEVICE);
2326 pkts_compl++; 2325 pkts_compl++;
2327 bytes_compl += vp->tx_skb->len; 2326 bytes_compl += vp->tx_skb->len;
2328 dev_kfree_skb_irq(vp->tx_skb); /* Release the transferred buffer */ 2327 dev_kfree_skb_irq(vp->tx_skb); /* Release the transferred buffer */
@@ -2459,19 +2458,19 @@ boomerang_interrupt(int irq, void *dev_id)
2459 struct sk_buff *skb = vp->tx_skbuff[entry]; 2458 struct sk_buff *skb = vp->tx_skbuff[entry];
2460#if DO_ZEROCOPY 2459#if DO_ZEROCOPY
2461 int i; 2460 int i;
2462 pci_unmap_single(VORTEX_PCI(vp), 2461 dma_unmap_single(vp->gendev,
2463 le32_to_cpu(vp->tx_ring[entry].frag[0].addr), 2462 le32_to_cpu(vp->tx_ring[entry].frag[0].addr),
2464 le32_to_cpu(vp->tx_ring[entry].frag[0].length)&0xFFF, 2463 le32_to_cpu(vp->tx_ring[entry].frag[0].length)&0xFFF,
2465 PCI_DMA_TODEVICE); 2464 DMA_TO_DEVICE);
2466 2465
2467 for (i=1; i<=skb_shinfo(skb)->nr_frags; i++) 2466 for (i=1; i<=skb_shinfo(skb)->nr_frags; i++)
2468 pci_unmap_page(VORTEX_PCI(vp), 2467 dma_unmap_page(vp->gendev,
2469 le32_to_cpu(vp->tx_ring[entry].frag[i].addr), 2468 le32_to_cpu(vp->tx_ring[entry].frag[i].addr),
2470 le32_to_cpu(vp->tx_ring[entry].frag[i].length)&0xFFF, 2469 le32_to_cpu(vp->tx_ring[entry].frag[i].length)&0xFFF,
2471 PCI_DMA_TODEVICE); 2470 DMA_TO_DEVICE);
2472#else 2471#else
2473 pci_unmap_single(VORTEX_PCI(vp), 2472 dma_unmap_single(vp->gendev,
2474 le32_to_cpu(vp->tx_ring[entry].addr), skb->len, PCI_DMA_TODEVICE); 2473 le32_to_cpu(vp->tx_ring[entry].addr), skb->len, DMA_TO_DEVICE);
2475#endif 2474#endif
2476 pkts_compl++; 2475 pkts_compl++;
2477 bytes_compl += skb->len; 2476 bytes_compl += skb->len;
@@ -2561,14 +2560,14 @@ static int vortex_rx(struct net_device *dev)
2561 /* 'skb_put()' points to the start of sk_buff data area. */ 2560 /* 'skb_put()' points to the start of sk_buff data area. */
2562 if (vp->bus_master && 2561 if (vp->bus_master &&
2563 ! (ioread16(ioaddr + Wn7_MasterStatus) & 0x8000)) { 2562 ! (ioread16(ioaddr + Wn7_MasterStatus) & 0x8000)) {
2564 dma_addr_t dma = pci_map_single(VORTEX_PCI(vp), skb_put(skb, pkt_len), 2563 dma_addr_t dma = dma_map_single(vp->gendev, skb_put(skb, pkt_len),
2565 pkt_len, PCI_DMA_FROMDEVICE); 2564 pkt_len, DMA_FROM_DEVICE);
2566 iowrite32(dma, ioaddr + Wn7_MasterAddr); 2565 iowrite32(dma, ioaddr + Wn7_MasterAddr);
2567 iowrite16((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen); 2566 iowrite16((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen);
2568 iowrite16(StartDMAUp, ioaddr + EL3_CMD); 2567 iowrite16(StartDMAUp, ioaddr + EL3_CMD);
2569 while (ioread16(ioaddr + Wn7_MasterStatus) & 0x8000) 2568 while (ioread16(ioaddr + Wn7_MasterStatus) & 0x8000)
2570 ; 2569 ;
2571 pci_unmap_single(VORTEX_PCI(vp), dma, pkt_len, PCI_DMA_FROMDEVICE); 2570 dma_unmap_single(vp->gendev, dma, pkt_len, DMA_FROM_DEVICE);
2572 } else { 2571 } else {
2573 ioread32_rep(ioaddr + RX_FIFO, 2572 ioread32_rep(ioaddr + RX_FIFO,
2574 skb_put(skb, pkt_len), 2573 skb_put(skb, pkt_len),
@@ -2635,11 +2634,11 @@ boomerang_rx(struct net_device *dev)
2635 if (pkt_len < rx_copybreak && 2634 if (pkt_len < rx_copybreak &&
2636 (skb = netdev_alloc_skb(dev, pkt_len + 2)) != NULL) { 2635 (skb = netdev_alloc_skb(dev, pkt_len + 2)) != NULL) {
2637 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 2636 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
2638 pci_dma_sync_single_for_cpu(VORTEX_PCI(vp), dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE); 2637 dma_sync_single_for_cpu(vp->gendev, dma, PKT_BUF_SZ, DMA_FROM_DEVICE);
2639 /* 'skb_put()' points to the start of sk_buff data area. */ 2638 /* 'skb_put()' points to the start of sk_buff data area. */
2640 skb_put_data(skb, vp->rx_skbuff[entry]->data, 2639 skb_put_data(skb, vp->rx_skbuff[entry]->data,
2641 pkt_len); 2640 pkt_len);
2642 pci_dma_sync_single_for_device(VORTEX_PCI(vp), dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE); 2641 dma_sync_single_for_device(vp->gendev, dma, PKT_BUF_SZ, DMA_FROM_DEVICE);
2643 vp->rx_copy++; 2642 vp->rx_copy++;
2644 } else { 2643 } else {
2645 /* Pre-allocate the replacement skb. If it or its 2644 /* Pre-allocate the replacement skb. If it or its
@@ -2651,9 +2650,9 @@ boomerang_rx(struct net_device *dev)
2651 dev->stats.rx_dropped++; 2650 dev->stats.rx_dropped++;
2652 goto clear_complete; 2651 goto clear_complete;
2653 } 2652 }
2654 newdma = pci_map_single(VORTEX_PCI(vp), newskb->data, 2653 newdma = dma_map_single(vp->gendev, newskb->data,
2655 PKT_BUF_SZ, PCI_DMA_FROMDEVICE); 2654 PKT_BUF_SZ, DMA_FROM_DEVICE);
2656 if (dma_mapping_error(&VORTEX_PCI(vp)->dev, newdma)) { 2655 if (dma_mapping_error(vp->gendev, newdma)) {
2657 dev->stats.rx_dropped++; 2656 dev->stats.rx_dropped++;
2658 consume_skb(newskb); 2657 consume_skb(newskb);
2659 goto clear_complete; 2658 goto clear_complete;
@@ -2664,7 +2663,7 @@ boomerang_rx(struct net_device *dev)
2664 vp->rx_skbuff[entry] = newskb; 2663 vp->rx_skbuff[entry] = newskb;
2665 vp->rx_ring[entry].addr = cpu_to_le32(newdma); 2664 vp->rx_ring[entry].addr = cpu_to_le32(newdma);
2666 skb_put(skb, pkt_len); 2665 skb_put(skb, pkt_len);
2667 pci_unmap_single(VORTEX_PCI(vp), dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE); 2666 dma_unmap_single(vp->gendev, dma, PKT_BUF_SZ, DMA_FROM_DEVICE);
2668 vp->rx_nocopy++; 2667 vp->rx_nocopy++;
2669 } 2668 }
2670 skb->protocol = eth_type_trans(skb, dev); 2669 skb->protocol = eth_type_trans(skb, dev);
@@ -2761,8 +2760,8 @@ vortex_close(struct net_device *dev)
2761 if (vp->full_bus_master_rx) { /* Free Boomerang bus master Rx buffers. */ 2760 if (vp->full_bus_master_rx) { /* Free Boomerang bus master Rx buffers. */
2762 for (i = 0; i < RX_RING_SIZE; i++) 2761 for (i = 0; i < RX_RING_SIZE; i++)
2763 if (vp->rx_skbuff[i]) { 2762 if (vp->rx_skbuff[i]) {
2764 pci_unmap_single( VORTEX_PCI(vp), le32_to_cpu(vp->rx_ring[i].addr), 2763 dma_unmap_single(vp->gendev, le32_to_cpu(vp->rx_ring[i].addr),
2765 PKT_BUF_SZ, PCI_DMA_FROMDEVICE); 2764 PKT_BUF_SZ, DMA_FROM_DEVICE);
2766 dev_kfree_skb(vp->rx_skbuff[i]); 2765 dev_kfree_skb(vp->rx_skbuff[i]);
2767 vp->rx_skbuff[i] = NULL; 2766 vp->rx_skbuff[i] = NULL;
2768 } 2767 }
@@ -2775,12 +2774,12 @@ vortex_close(struct net_device *dev)
2775 int k; 2774 int k;
2776 2775
2777 for (k=0; k<=skb_shinfo(skb)->nr_frags; k++) 2776 for (k=0; k<=skb_shinfo(skb)->nr_frags; k++)
2778 pci_unmap_single(VORTEX_PCI(vp), 2777 dma_unmap_single(vp->gendev,
2779 le32_to_cpu(vp->tx_ring[i].frag[k].addr), 2778 le32_to_cpu(vp->tx_ring[i].frag[k].addr),
2780 le32_to_cpu(vp->tx_ring[i].frag[k].length)&0xFFF, 2779 le32_to_cpu(vp->tx_ring[i].frag[k].length)&0xFFF,
2781 PCI_DMA_TODEVICE); 2780 DMA_TO_DEVICE);
2782#else 2781#else
2783 pci_unmap_single(VORTEX_PCI(vp), le32_to_cpu(vp->tx_ring[i].addr), skb->len, PCI_DMA_TODEVICE); 2782 dma_unmap_single(vp->gendev, le32_to_cpu(vp->tx_ring[i].addr), skb->len, DMA_TO_DEVICE);
2784#endif 2783#endif
2785 dev_kfree_skb(skb); 2784 dev_kfree_skb(skb);
2786 vp->tx_skbuff[i] = NULL; 2785 vp->tx_skbuff[i] = NULL;
@@ -3288,11 +3287,10 @@ static void vortex_remove_one(struct pci_dev *pdev)
3288 3287
3289 pci_iounmap(pdev, vp->ioaddr); 3288 pci_iounmap(pdev, vp->ioaddr);
3290 3289
3291 pci_free_consistent(pdev, 3290 dma_free_coherent(&pdev->dev,
3292 sizeof(struct boom_rx_desc) * RX_RING_SIZE 3291 sizeof(struct boom_rx_desc) * RX_RING_SIZE +
3293 + sizeof(struct boom_tx_desc) * TX_RING_SIZE, 3292 sizeof(struct boom_tx_desc) * TX_RING_SIZE,
3294 vp->rx_ring, 3293 vp->rx_ring, vp->rx_ring_dma);
3295 vp->rx_ring_dma);
3296 3294
3297 pci_release_regions(pdev); 3295 pci_release_regions(pdev);
3298 3296
diff --git a/drivers/net/ethernet/8390/ne.c b/drivers/net/ethernet/8390/ne.c
index ac99d089ac72..1c97e39b478e 100644
--- a/drivers/net/ethernet/8390/ne.c
+++ b/drivers/net/ethernet/8390/ne.c
@@ -164,7 +164,9 @@ bad_clone_list[] __initdata = {
164#define NESM_START_PG 0x40 /* First page of TX buffer */ 164#define NESM_START_PG 0x40 /* First page of TX buffer */
165#define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */ 165#define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
166 166
167#if defined(CONFIG_ATARI) /* 8-bit mode on Atari, normal on Q40 */ 167#if defined(CONFIG_MACH_TX49XX)
168# define DCR_VAL 0x48 /* 8-bit mode */
169#elif defined(CONFIG_ATARI) /* 8-bit mode on Atari, normal on Q40 */
168# define DCR_VAL (MACH_IS_ATARI ? 0x48 : 0x49) 170# define DCR_VAL (MACH_IS_ATARI ? 0x48 : 0x49)
169#else 171#else
170# define DCR_VAL 0x49 172# define DCR_VAL 0x49
diff --git a/drivers/net/ethernet/amd/pcnet32.c b/drivers/net/ethernet/amd/pcnet32.c
index a561705f232c..be198cc0b10c 100644
--- a/drivers/net/ethernet/amd/pcnet32.c
+++ b/drivers/net/ethernet/amd/pcnet32.c
@@ -1552,22 +1552,26 @@ pcnet32_probe_pci(struct pci_dev *pdev, const struct pci_device_id *ent)
1552 if (!ioaddr) { 1552 if (!ioaddr) {
1553 if (pcnet32_debug & NETIF_MSG_PROBE) 1553 if (pcnet32_debug & NETIF_MSG_PROBE)
1554 pr_err("card has no PCI IO resources, aborting\n"); 1554 pr_err("card has no PCI IO resources, aborting\n");
1555 return -ENODEV; 1555 err = -ENODEV;
1556 goto err_disable_dev;
1556 } 1557 }
1557 1558
1558 err = pci_set_dma_mask(pdev, PCNET32_DMA_MASK); 1559 err = pci_set_dma_mask(pdev, PCNET32_DMA_MASK);
1559 if (err) { 1560 if (err) {
1560 if (pcnet32_debug & NETIF_MSG_PROBE) 1561 if (pcnet32_debug & NETIF_MSG_PROBE)
1561 pr_err("architecture does not support 32bit PCI busmaster DMA\n"); 1562 pr_err("architecture does not support 32bit PCI busmaster DMA\n");
1562 return err; 1563 goto err_disable_dev;
1563 } 1564 }
1564 if (!request_region(ioaddr, PCNET32_TOTAL_SIZE, "pcnet32_probe_pci")) { 1565 if (!request_region(ioaddr, PCNET32_TOTAL_SIZE, "pcnet32_probe_pci")) {
1565 if (pcnet32_debug & NETIF_MSG_PROBE) 1566 if (pcnet32_debug & NETIF_MSG_PROBE)
1566 pr_err("io address range already allocated\n"); 1567 pr_err("io address range already allocated\n");
1567 return -EBUSY; 1568 err = -EBUSY;
1569 goto err_disable_dev;
1568 } 1570 }
1569 1571
1570 err = pcnet32_probe1(ioaddr, 1, pdev); 1572 err = pcnet32_probe1(ioaddr, 1, pdev);
1573
1574err_disable_dev:
1571 if (err < 0) 1575 if (err < 0)
1572 pci_disable_device(pdev); 1576 pci_disable_device(pdev);
1573 1577
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cudbg_entity.h b/drivers/net/ethernet/chelsio/cxgb4/cudbg_entity.h
index b57acb8dc35b..dc25066c59a1 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cudbg_entity.h
+++ b/drivers/net/ethernet/chelsio/cxgb4/cudbg_entity.h
@@ -419,15 +419,15 @@ static const u32 t6_up_cim_reg_array[][IREG_NUM_ELEM + 1] = {
419 {0x7b50, 0x7b54, 0x280, 0x20, 0}, /* up_cim_280_to_2fc */ 419 {0x7b50, 0x7b54, 0x280, 0x20, 0}, /* up_cim_280_to_2fc */
420 {0x7b50, 0x7b54, 0x300, 0x20, 0}, /* up_cim_300_to_37c */ 420 {0x7b50, 0x7b54, 0x300, 0x20, 0}, /* up_cim_300_to_37c */
421 {0x7b50, 0x7b54, 0x380, 0x14, 0}, /* up_cim_380_to_3cc */ 421 {0x7b50, 0x7b54, 0x380, 0x14, 0}, /* up_cim_380_to_3cc */
422 {0x7b50, 0x7b54, 0x2900, 0x4, 0x4}, /* up_cim_2900_to_3d40 */ 422 {0x7b50, 0x7b54, 0x4900, 0x4, 0x4}, /* up_cim_4900_to_4c60 */
423 {0x7b50, 0x7b54, 0x2904, 0x4, 0x4}, /* up_cim_2904_to_3d44 */ 423 {0x7b50, 0x7b54, 0x4904, 0x4, 0x4}, /* up_cim_4904_to_4c64 */
424 {0x7b50, 0x7b54, 0x2908, 0x4, 0x4}, /* up_cim_2908_to_3d48 */ 424 {0x7b50, 0x7b54, 0x4908, 0x4, 0x4}, /* up_cim_4908_to_4c68 */
425 {0x7b50, 0x7b54, 0x2910, 0x4, 0x4}, /* up_cim_2910_to_3d4c */ 425 {0x7b50, 0x7b54, 0x4910, 0x4, 0x4}, /* up_cim_4910_to_4c70 */
426 {0x7b50, 0x7b54, 0x2914, 0x4, 0x4}, /* up_cim_2914_to_3d50 */ 426 {0x7b50, 0x7b54, 0x4914, 0x4, 0x4}, /* up_cim_4914_to_4c74 */
427 {0x7b50, 0x7b54, 0x2920, 0x10, 0x10}, /* up_cim_2920_to_2a10 */ 427 {0x7b50, 0x7b54, 0x4920, 0x10, 0x10}, /* up_cim_4920_to_4a10 */
428 {0x7b50, 0x7b54, 0x2924, 0x10, 0x10}, /* up_cim_2924_to_2a14 */ 428 {0x7b50, 0x7b54, 0x4924, 0x10, 0x10}, /* up_cim_4924_to_4a14 */
429 {0x7b50, 0x7b54, 0x2928, 0x10, 0x10}, /* up_cim_2928_to_2a18 */ 429 {0x7b50, 0x7b54, 0x4928, 0x10, 0x10}, /* up_cim_4928_to_4a18 */
430 {0x7b50, 0x7b54, 0x292c, 0x10, 0x10}, /* up_cim_292c_to_2a1c */ 430 {0x7b50, 0x7b54, 0x492c, 0x10, 0x10}, /* up_cim_492c_to_4a1c */
431}; 431};
432 432
433static const u32 t5_up_cim_reg_array[][IREG_NUM_ELEM + 1] = { 433static const u32 t5_up_cim_reg_array[][IREG_NUM_ELEM + 1] = {
@@ -444,16 +444,6 @@ static const u32 t5_up_cim_reg_array[][IREG_NUM_ELEM + 1] = {
444 {0x7b50, 0x7b54, 0x280, 0x20, 0}, /* up_cim_280_to_2fc */ 444 {0x7b50, 0x7b54, 0x280, 0x20, 0}, /* up_cim_280_to_2fc */
445 {0x7b50, 0x7b54, 0x300, 0x20, 0}, /* up_cim_300_to_37c */ 445 {0x7b50, 0x7b54, 0x300, 0x20, 0}, /* up_cim_300_to_37c */
446 {0x7b50, 0x7b54, 0x380, 0x14, 0}, /* up_cim_380_to_3cc */ 446 {0x7b50, 0x7b54, 0x380, 0x14, 0}, /* up_cim_380_to_3cc */
447 {0x7b50, 0x7b54, 0x2900, 0x4, 0x4}, /* up_cim_2900_to_3d40 */
448 {0x7b50, 0x7b54, 0x2904, 0x4, 0x4}, /* up_cim_2904_to_3d44 */
449 {0x7b50, 0x7b54, 0x2908, 0x4, 0x4}, /* up_cim_2908_to_3d48 */
450 {0x7b50, 0x7b54, 0x2910, 0x4, 0x4}, /* up_cim_2910_to_3d4c */
451 {0x7b50, 0x7b54, 0x2914, 0x4, 0x4}, /* up_cim_2914_to_3d50 */
452 {0x7b50, 0x7b54, 0x2918, 0x4, 0x4}, /* up_cim_2918_to_3d54 */
453 {0x7b50, 0x7b54, 0x291c, 0x4, 0x4}, /* up_cim_291c_to_3d58 */
454 {0x7b50, 0x7b54, 0x2924, 0x10, 0x10}, /* up_cim_2924_to_2914 */
455 {0x7b50, 0x7b54, 0x2928, 0x10, 0x10}, /* up_cim_2928_to_2a18 */
456 {0x7b50, 0x7b54, 0x292c, 0x10, 0x10}, /* up_cim_292c_to_2a1c */
457}; 447};
458 448
459static const u32 t6_hma_ireg_array[][IREG_NUM_ELEM] = { 449static const u32 t6_hma_ireg_array[][IREG_NUM_ELEM] = {
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c
index db92f1858060..b76447baccaf 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c
@@ -836,7 +836,7 @@ bool is_filter_exact_match(struct adapter *adap,
836{ 836{
837 struct tp_params *tp = &adap->params.tp; 837 struct tp_params *tp = &adap->params.tp;
838 u64 hash_filter_mask = tp->hash_filter_mask; 838 u64 hash_filter_mask = tp->hash_filter_mask;
839 u32 mask; 839 u64 ntuple_mask = 0;
840 840
841 if (!is_hashfilter(adap)) 841 if (!is_hashfilter(adap))
842 return false; 842 return false;
@@ -865,73 +865,45 @@ bool is_filter_exact_match(struct adapter *adap,
865 if (!fs->val.fport || fs->mask.fport != 0xffff) 865 if (!fs->val.fport || fs->mask.fport != 0xffff)
866 return false; 866 return false;
867 867
868 if (tp->fcoe_shift >= 0) { 868 /* calculate tuple mask and compare with mask configured in hw */
869 mask = (hash_filter_mask >> tp->fcoe_shift) & FT_FCOE_W; 869 if (tp->fcoe_shift >= 0)
870 if (mask && !fs->mask.fcoe) 870 ntuple_mask |= (u64)fs->mask.fcoe << tp->fcoe_shift;
871 return false;
872 }
873 871
874 if (tp->port_shift >= 0) { 872 if (tp->port_shift >= 0)
875 mask = (hash_filter_mask >> tp->port_shift) & FT_PORT_W; 873 ntuple_mask |= (u64)fs->mask.iport << tp->port_shift;
876 if (mask && !fs->mask.iport)
877 return false;
878 }
879 874
880 if (tp->vnic_shift >= 0) { 875 if (tp->vnic_shift >= 0) {
881 mask = (hash_filter_mask >> tp->vnic_shift) & FT_VNIC_ID_W; 876 if ((adap->params.tp.ingress_config & VNIC_F))
882 877 ntuple_mask |= (u64)fs->mask.pfvf_vld << tp->vnic_shift;
883 if ((adap->params.tp.ingress_config & VNIC_F)) { 878 else
884 if (mask && !fs->mask.pfvf_vld) 879 ntuple_mask |= (u64)fs->mask.ovlan_vld <<
885 return false; 880 tp->vnic_shift;
886 } else {
887 if (mask && !fs->mask.ovlan_vld)
888 return false;
889 }
890 } 881 }
891 882
892 if (tp->vlan_shift >= 0) { 883 if (tp->vlan_shift >= 0)
893 mask = (hash_filter_mask >> tp->vlan_shift) & FT_VLAN_W; 884 ntuple_mask |= (u64)fs->mask.ivlan << tp->vlan_shift;
894 if (mask && !fs->mask.ivlan)
895 return false;
896 }
897 885
898 if (tp->tos_shift >= 0) { 886 if (tp->tos_shift >= 0)
899 mask = (hash_filter_mask >> tp->tos_shift) & FT_TOS_W; 887 ntuple_mask |= (u64)fs->mask.tos << tp->tos_shift;
900 if (mask && !fs->mask.tos)
901 return false;
902 }
903 888
904 if (tp->protocol_shift >= 0) { 889 if (tp->protocol_shift >= 0)
905 mask = (hash_filter_mask >> tp->protocol_shift) & FT_PROTOCOL_W; 890 ntuple_mask |= (u64)fs->mask.proto << tp->protocol_shift;
906 if (mask && !fs->mask.proto)
907 return false;
908 }
909 891
910 if (tp->ethertype_shift >= 0) { 892 if (tp->ethertype_shift >= 0)
911 mask = (hash_filter_mask >> tp->ethertype_shift) & 893 ntuple_mask |= (u64)fs->mask.ethtype << tp->ethertype_shift;
912 FT_ETHERTYPE_W;
913 if (mask && !fs->mask.ethtype)
914 return false;
915 }
916 894
917 if (tp->macmatch_shift >= 0) { 895 if (tp->macmatch_shift >= 0)
918 mask = (hash_filter_mask >> tp->macmatch_shift) & FT_MACMATCH_W; 896 ntuple_mask |= (u64)fs->mask.macidx << tp->macmatch_shift;
919 if (mask && !fs->mask.macidx) 897
920 return false; 898 if (tp->matchtype_shift >= 0)
921 } 899 ntuple_mask |= (u64)fs->mask.matchtype << tp->matchtype_shift;
900
901 if (tp->frag_shift >= 0)
902 ntuple_mask |= (u64)fs->mask.frag << tp->frag_shift;
903
904 if (ntuple_mask != hash_filter_mask)
905 return false;
922 906
923 if (tp->matchtype_shift >= 0) {
924 mask = (hash_filter_mask >> tp->matchtype_shift) &
925 FT_MPSHITTYPE_W;
926 if (mask && !fs->mask.matchtype)
927 return false;
928 }
929 if (tp->frag_shift >= 0) {
930 mask = (hash_filter_mask >> tp->frag_shift) &
931 FT_FRAGMENTATION_W;
932 if (mask && !fs->mask.frag)
933 return false;
934 }
935 return true; 907 return true;
936} 908}
937 909
diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
index 81684acf52af..8a8b12b720ef 100644
--- a/drivers/net/ethernet/cisco/enic/enic_main.c
+++ b/drivers/net/ethernet/cisco/enic/enic_main.c
@@ -2747,11 +2747,11 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2747 pci_set_master(pdev); 2747 pci_set_master(pdev);
2748 2748
2749 /* Query PCI controller on system for DMA addressing 2749 /* Query PCI controller on system for DMA addressing
2750 * limitation for the device. Try 64-bit first, and 2750 * limitation for the device. Try 47-bit first, and
2751 * fail to 32-bit. 2751 * fail to 32-bit.
2752 */ 2752 */
2753 2753
2754 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); 2754 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(47));
2755 if (err) { 2755 if (err) {
2756 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); 2756 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2757 if (err) { 2757 if (err) {
@@ -2765,10 +2765,10 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2765 goto err_out_release_regions; 2765 goto err_out_release_regions;
2766 } 2766 }
2767 } else { 2767 } else {
2768 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); 2768 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(47));
2769 if (err) { 2769 if (err) {
2770 dev_err(dev, "Unable to obtain %u-bit DMA " 2770 dev_err(dev, "Unable to obtain %u-bit DMA "
2771 "for consistent allocations, aborting\n", 64); 2771 "for consistent allocations, aborting\n", 47);
2772 goto err_out_release_regions; 2772 goto err_out_release_regions;
2773 } 2773 }
2774 using_dac = 1; 2774 using_dac = 1;
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index d4604bc8eb5b..9d3eed46830d 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx. 3 * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx.
3 * Copyright (c) 1997 Dan Malek (dmalek@jlc.net) 4 * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c
index f81439796ac7..43d973215040 100644
--- a/drivers/net/ethernet/freescale/fec_ptp.c
+++ b/drivers/net/ethernet/freescale/fec_ptp.c
@@ -1,20 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Fast Ethernet Controller (ENET) PTP driver for MX6x. 3 * Fast Ethernet Controller (ENET) PTP driver for MX6x.
3 * 4 *
4 * Copyright (C) 2012 Freescale Semiconductor, Inc. 5 * Copyright (C) 2012 Freescale Semiconductor, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 */ 6 */
19 7
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
index 6e8d6a6f6aaf..5ec1185808e5 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -192,6 +192,7 @@ static int alloc_long_term_buff(struct ibmvnic_adapter *adapter,
192 if (adapter->fw_done_rc) { 192 if (adapter->fw_done_rc) {
193 dev_err(dev, "Couldn't map long term buffer,rc = %d\n", 193 dev_err(dev, "Couldn't map long term buffer,rc = %d\n",
194 adapter->fw_done_rc); 194 adapter->fw_done_rc);
195 dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr);
195 return -1; 196 return -1;
196 } 197 }
197 return 0; 198 return 0;
@@ -795,9 +796,11 @@ static int ibmvnic_login(struct net_device *netdev)
795 struct ibmvnic_adapter *adapter = netdev_priv(netdev); 796 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
796 unsigned long timeout = msecs_to_jiffies(30000); 797 unsigned long timeout = msecs_to_jiffies(30000);
797 int retry_count = 0; 798 int retry_count = 0;
799 bool retry;
798 int rc; 800 int rc;
799 801
800 do { 802 do {
803 retry = false;
801 if (retry_count > IBMVNIC_MAX_QUEUES) { 804 if (retry_count > IBMVNIC_MAX_QUEUES) {
802 netdev_warn(netdev, "Login attempts exceeded\n"); 805 netdev_warn(netdev, "Login attempts exceeded\n");
803 return -1; 806 return -1;
@@ -821,6 +824,9 @@ static int ibmvnic_login(struct net_device *netdev)
821 retry_count++; 824 retry_count++;
822 release_sub_crqs(adapter, 1); 825 release_sub_crqs(adapter, 1);
823 826
827 retry = true;
828 netdev_dbg(netdev,
829 "Received partial success, retrying...\n");
824 adapter->init_done_rc = 0; 830 adapter->init_done_rc = 0;
825 reinit_completion(&adapter->init_done); 831 reinit_completion(&adapter->init_done);
826 send_cap_queries(adapter); 832 send_cap_queries(adapter);
@@ -848,7 +854,7 @@ static int ibmvnic_login(struct net_device *netdev)
848 netdev_warn(netdev, "Adapter login failed\n"); 854 netdev_warn(netdev, "Adapter login failed\n");
849 return -1; 855 return -1;
850 } 856 }
851 } while (adapter->init_done_rc == PARTIALSUCCESS); 857 } while (retry);
852 858
853 /* handle pending MAC address changes after successful login */ 859 /* handle pending MAC address changes after successful login */
854 if (adapter->mac_change_pending) { 860 if (adapter->mac_change_pending) {
@@ -1821,9 +1827,8 @@ static int do_reset(struct ibmvnic_adapter *adapter,
1821 if (rc) 1827 if (rc)
1822 return rc; 1828 return rc;
1823 } 1829 }
1830 ibmvnic_disable_irqs(adapter);
1824 } 1831 }
1825
1826 ibmvnic_disable_irqs(adapter);
1827 adapter->state = VNIC_CLOSED; 1832 adapter->state = VNIC_CLOSED;
1828 1833
1829 if (reset_state == VNIC_CLOSED) 1834 if (reset_state == VNIC_CLOSED)
@@ -2617,18 +2622,21 @@ static int enable_scrq_irq(struct ibmvnic_adapter *adapter,
2617{ 2622{
2618 struct device *dev = &adapter->vdev->dev; 2623 struct device *dev = &adapter->vdev->dev;
2619 unsigned long rc; 2624 unsigned long rc;
2620 u64 val;
2621 2625
2622 if (scrq->hw_irq > 0x100000000ULL) { 2626 if (scrq->hw_irq > 0x100000000ULL) {
2623 dev_err(dev, "bad hw_irq = %lx\n", scrq->hw_irq); 2627 dev_err(dev, "bad hw_irq = %lx\n", scrq->hw_irq);
2624 return 1; 2628 return 1;
2625 } 2629 }
2626 2630
2627 val = (0xff000000) | scrq->hw_irq; 2631 if (adapter->resetting &&
2628 rc = plpar_hcall_norets(H_EOI, val); 2632 adapter->reset_reason == VNIC_RESET_MOBILITY) {
2629 if (rc) 2633 u64 val = (0xff000000) | scrq->hw_irq;
2630 dev_err(dev, "H_EOI FAILED irq 0x%llx. rc=%ld\n", 2634
2631 val, rc); 2635 rc = plpar_hcall_norets(H_EOI, val);
2636 if (rc)
2637 dev_err(dev, "H_EOI FAILED irq 0x%llx. rc=%ld\n",
2638 val, rc);
2639 }
2632 2640
2633 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address, 2641 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
2634 H_ENABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0); 2642 H_ENABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);
@@ -4586,14 +4594,6 @@ static int ibmvnic_init(struct ibmvnic_adapter *adapter)
4586 release_crq_queue(adapter); 4594 release_crq_queue(adapter);
4587 } 4595 }
4588 4596
4589 rc = init_stats_buffers(adapter);
4590 if (rc)
4591 return rc;
4592
4593 rc = init_stats_token(adapter);
4594 if (rc)
4595 return rc;
4596
4597 return rc; 4597 return rc;
4598} 4598}
4599 4599
@@ -4662,13 +4662,21 @@ static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id)
4662 goto ibmvnic_init_fail; 4662 goto ibmvnic_init_fail;
4663 } while (rc == EAGAIN); 4663 } while (rc == EAGAIN);
4664 4664
4665 rc = init_stats_buffers(adapter);
4666 if (rc)
4667 goto ibmvnic_init_fail;
4668
4669 rc = init_stats_token(adapter);
4670 if (rc)
4671 goto ibmvnic_stats_fail;
4672
4665 netdev->mtu = adapter->req_mtu - ETH_HLEN; 4673 netdev->mtu = adapter->req_mtu - ETH_HLEN;
4666 netdev->min_mtu = adapter->min_mtu - ETH_HLEN; 4674 netdev->min_mtu = adapter->min_mtu - ETH_HLEN;
4667 netdev->max_mtu = adapter->max_mtu - ETH_HLEN; 4675 netdev->max_mtu = adapter->max_mtu - ETH_HLEN;
4668 4676
4669 rc = device_create_file(&dev->dev, &dev_attr_failover); 4677 rc = device_create_file(&dev->dev, &dev_attr_failover);
4670 if (rc) 4678 if (rc)
4671 goto ibmvnic_init_fail; 4679 goto ibmvnic_dev_file_err;
4672 4680
4673 netif_carrier_off(netdev); 4681 netif_carrier_off(netdev);
4674 rc = register_netdev(netdev); 4682 rc = register_netdev(netdev);
@@ -4687,6 +4695,12 @@ static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id)
4687ibmvnic_register_fail: 4695ibmvnic_register_fail:
4688 device_remove_file(&dev->dev, &dev_attr_failover); 4696 device_remove_file(&dev->dev, &dev_attr_failover);
4689 4697
4698ibmvnic_dev_file_err:
4699 release_stats_token(adapter);
4700
4701ibmvnic_stats_fail:
4702 release_stats_buffers(adapter);
4703
4690ibmvnic_init_fail: 4704ibmvnic_init_fail:
4691 release_sub_crqs(adapter, 1); 4705 release_sub_crqs(adapter, 1);
4692 release_crq_queue(adapter); 4706 release_crq_queue(adapter);
diff --git a/drivers/net/ethernet/mellanox/mlx4/icm.c b/drivers/net/ethernet/mellanox/mlx4/icm.c
index a822f7a56bc5..685337d58276 100644
--- a/drivers/net/ethernet/mellanox/mlx4/icm.c
+++ b/drivers/net/ethernet/mellanox/mlx4/icm.c
@@ -43,12 +43,12 @@
43#include "fw.h" 43#include "fw.h"
44 44
45/* 45/*
46 * We allocate in as big chunks as we can, up to a maximum of 256 KB 46 * We allocate in page size (default 4KB on many archs) chunks to avoid high
47 * per chunk. 47 * order memory allocations in fragmented/high usage memory situation.
48 */ 48 */
49enum { 49enum {
50 MLX4_ICM_ALLOC_SIZE = 1 << 18, 50 MLX4_ICM_ALLOC_SIZE = PAGE_SIZE,
51 MLX4_TABLE_CHUNK_SIZE = 1 << 18 51 MLX4_TABLE_CHUNK_SIZE = PAGE_SIZE,
52}; 52};
53 53
54static void mlx4_free_icm_pages(struct mlx4_dev *dev, struct mlx4_icm_chunk *chunk) 54static void mlx4_free_icm_pages(struct mlx4_dev *dev, struct mlx4_icm_chunk *chunk)
@@ -398,9 +398,11 @@ int mlx4_init_icm_table(struct mlx4_dev *dev, struct mlx4_icm_table *table,
398 u64 size; 398 u64 size;
399 399
400 obj_per_chunk = MLX4_TABLE_CHUNK_SIZE / obj_size; 400 obj_per_chunk = MLX4_TABLE_CHUNK_SIZE / obj_size;
401 if (WARN_ON(!obj_per_chunk))
402 return -EINVAL;
401 num_icm = (nobj + obj_per_chunk - 1) / obj_per_chunk; 403 num_icm = (nobj + obj_per_chunk - 1) / obj_per_chunk;
402 404
403 table->icm = kcalloc(num_icm, sizeof(*table->icm), GFP_KERNEL); 405 table->icm = kvzalloc(num_icm * sizeof(*table->icm), GFP_KERNEL);
404 if (!table->icm) 406 if (!table->icm)
405 return -ENOMEM; 407 return -ENOMEM;
406 table->virt = virt; 408 table->virt = virt;
@@ -446,7 +448,7 @@ err:
446 mlx4_free_icm(dev, table->icm[i], use_coherent); 448 mlx4_free_icm(dev, table->icm[i], use_coherent);
447 } 449 }
448 450
449 kfree(table->icm); 451 kvfree(table->icm);
450 452
451 return -ENOMEM; 453 return -ENOMEM;
452} 454}
@@ -462,5 +464,5 @@ void mlx4_cleanup_icm_table(struct mlx4_dev *dev, struct mlx4_icm_table *table)
462 mlx4_free_icm(dev, table->icm[i], table->coherent); 464 mlx4_free_icm(dev, table->icm[i], table->coherent);
463 } 465 }
464 466
465 kfree(table->icm); 467 kvfree(table->icm);
466} 468}
diff --git a/drivers/net/ethernet/mellanox/mlx4/intf.c b/drivers/net/ethernet/mellanox/mlx4/intf.c
index 2edcce98ab2d..65482f004e50 100644
--- a/drivers/net/ethernet/mellanox/mlx4/intf.c
+++ b/drivers/net/ethernet/mellanox/mlx4/intf.c
@@ -172,7 +172,7 @@ int mlx4_do_bond(struct mlx4_dev *dev, bool enable)
172 list_add_tail(&dev_ctx->list, &priv->ctx_list); 172 list_add_tail(&dev_ctx->list, &priv->ctx_list);
173 spin_unlock_irqrestore(&priv->ctx_lock, flags); 173 spin_unlock_irqrestore(&priv->ctx_lock, flags);
174 174
175 mlx4_dbg(dev, "Inrerface for protocol %d restarted with when bonded mode is %s\n", 175 mlx4_dbg(dev, "Interface for protocol %d restarted with bonded mode %s\n",
176 dev_ctx->intf->protocol, enable ? 176 dev_ctx->intf->protocol, enable ?
177 "enabled" : "disabled"); 177 "enabled" : "disabled");
178 } 178 }
diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
index 211578ffc70d..60172a38c4a4 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -2929,6 +2929,7 @@ static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
2929 mlx4_err(dev, "Failed to create file for port %d\n", port); 2929 mlx4_err(dev, "Failed to create file for port %d\n", port);
2930 devlink_port_unregister(&info->devlink_port); 2930 devlink_port_unregister(&info->devlink_port);
2931 info->port = -1; 2931 info->port = -1;
2932 return err;
2932 } 2933 }
2933 2934
2934 sprintf(info->dev_mtu_name, "mlx4_port%d_mtu", port); 2935 sprintf(info->dev_mtu_name, "mlx4_port%d_mtu", port);
@@ -2950,9 +2951,10 @@ static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
2950 &info->port_attr); 2951 &info->port_attr);
2951 devlink_port_unregister(&info->devlink_port); 2952 devlink_port_unregister(&info->devlink_port);
2952 info->port = -1; 2953 info->port = -1;
2954 return err;
2953 } 2955 }
2954 2956
2955 return err; 2957 return 0;
2956} 2958}
2957 2959
2958static void mlx4_cleanup_port_info(struct mlx4_port_info *info) 2960static void mlx4_cleanup_port_info(struct mlx4_port_info *info)
diff --git a/drivers/net/ethernet/mellanox/mlx4/qp.c b/drivers/net/ethernet/mellanox/mlx4/qp.c
index 3aaf4bad6c5a..427e7a31862c 100644
--- a/drivers/net/ethernet/mellanox/mlx4/qp.c
+++ b/drivers/net/ethernet/mellanox/mlx4/qp.c
@@ -393,11 +393,11 @@ struct mlx4_qp *mlx4_qp_lookup(struct mlx4_dev *dev, u32 qpn)
393 struct mlx4_qp_table *qp_table = &mlx4_priv(dev)->qp_table; 393 struct mlx4_qp_table *qp_table = &mlx4_priv(dev)->qp_table;
394 struct mlx4_qp *qp; 394 struct mlx4_qp *qp;
395 395
396 spin_lock(&qp_table->lock); 396 spin_lock_irq(&qp_table->lock);
397 397
398 qp = __mlx4_qp_lookup(dev, qpn); 398 qp = __mlx4_qp_lookup(dev, qpn);
399 399
400 spin_unlock(&qp_table->lock); 400 spin_unlock_irq(&qp_table->lock);
401 return qp; 401 return qp;
402} 402}
403 403
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
index 176645762e49..1ff0b0e93804 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
@@ -615,6 +615,45 @@ static inline bool is_last_ethertype_ip(struct sk_buff *skb, int *network_depth)
615 return (ethertype == htons(ETH_P_IP) || ethertype == htons(ETH_P_IPV6)); 615 return (ethertype == htons(ETH_P_IP) || ethertype == htons(ETH_P_IPV6));
616} 616}
617 617
618static __be32 mlx5e_get_fcs(struct sk_buff *skb)
619{
620 int last_frag_sz, bytes_in_prev, nr_frags;
621 u8 *fcs_p1, *fcs_p2;
622 skb_frag_t *last_frag;
623 __be32 fcs_bytes;
624
625 if (!skb_is_nonlinear(skb))
626 return *(__be32 *)(skb->data + skb->len - ETH_FCS_LEN);
627
628 nr_frags = skb_shinfo(skb)->nr_frags;
629 last_frag = &skb_shinfo(skb)->frags[nr_frags - 1];
630 last_frag_sz = skb_frag_size(last_frag);
631
632 /* If all FCS data is in last frag */
633 if (last_frag_sz >= ETH_FCS_LEN)
634 return *(__be32 *)(skb_frag_address(last_frag) +
635 last_frag_sz - ETH_FCS_LEN);
636
637 fcs_p2 = (u8 *)skb_frag_address(last_frag);
638 bytes_in_prev = ETH_FCS_LEN - last_frag_sz;
639
640 /* Find where the other part of the FCS is - Linear or another frag */
641 if (nr_frags == 1) {
642 fcs_p1 = skb_tail_pointer(skb);
643 } else {
644 skb_frag_t *prev_frag = &skb_shinfo(skb)->frags[nr_frags - 2];
645
646 fcs_p1 = skb_frag_address(prev_frag) +
647 skb_frag_size(prev_frag);
648 }
649 fcs_p1 -= bytes_in_prev;
650
651 memcpy(&fcs_bytes, fcs_p1, bytes_in_prev);
652 memcpy(((u8 *)&fcs_bytes) + bytes_in_prev, fcs_p2, last_frag_sz);
653
654 return fcs_bytes;
655}
656
618static inline void mlx5e_handle_csum(struct net_device *netdev, 657static inline void mlx5e_handle_csum(struct net_device *netdev,
619 struct mlx5_cqe64 *cqe, 658 struct mlx5_cqe64 *cqe,
620 struct mlx5e_rq *rq, 659 struct mlx5e_rq *rq,
@@ -643,6 +682,9 @@ static inline void mlx5e_handle_csum(struct net_device *netdev,
643 skb->csum = csum_partial(skb->data + ETH_HLEN, 682 skb->csum = csum_partial(skb->data + ETH_HLEN,
644 network_depth - ETH_HLEN, 683 network_depth - ETH_HLEN,
645 skb->csum); 684 skb->csum);
685 if (unlikely(netdev->features & NETIF_F_RXFCS))
686 skb->csum = csum_add(skb->csum,
687 (__force __wsum)mlx5e_get_fcs(skb));
646 rq->stats.csum_complete++; 688 rq->stats.csum_complete++;
647 return; 689 return;
648 } 690 }
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c b/drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c
index 0f5da499a223..fad8c2e3804e 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c
@@ -237,19 +237,17 @@ static void *mlx5_fpga_ipsec_cmd_exec(struct mlx5_core_dev *mdev,
237 context->buf.sg[0].data = &context->command; 237 context->buf.sg[0].data = &context->command;
238 238
239 spin_lock_irqsave(&fdev->ipsec->pending_cmds_lock, flags); 239 spin_lock_irqsave(&fdev->ipsec->pending_cmds_lock, flags);
240 list_add_tail(&context->list, &fdev->ipsec->pending_cmds); 240 res = mlx5_fpga_sbu_conn_sendmsg(fdev->ipsec->conn, &context->buf);
241 if (!res)
242 list_add_tail(&context->list, &fdev->ipsec->pending_cmds);
241 spin_unlock_irqrestore(&fdev->ipsec->pending_cmds_lock, flags); 243 spin_unlock_irqrestore(&fdev->ipsec->pending_cmds_lock, flags);
242 244
243 res = mlx5_fpga_sbu_conn_sendmsg(fdev->ipsec->conn, &context->buf);
244 if (res) { 245 if (res) {
245 mlx5_fpga_warn(fdev, "Failure sending IPSec command: %d\n", 246 mlx5_fpga_warn(fdev, "Failed to send IPSec command: %d\n", res);
246 res);
247 spin_lock_irqsave(&fdev->ipsec->pending_cmds_lock, flags);
248 list_del(&context->list);
249 spin_unlock_irqrestore(&fdev->ipsec->pending_cmds_lock, flags);
250 kfree(context); 247 kfree(context);
251 return ERR_PTR(res); 248 return ERR_PTR(res);
252 } 249 }
250
253 /* Context will be freed by wait func after completion */ 251 /* Context will be freed by wait func after completion */
254 return context; 252 return context;
255} 253}
diff --git a/drivers/net/ethernet/netronome/nfp/bpf/main.c b/drivers/net/ethernet/netronome/nfp/bpf/main.c
index 1dc424685f4e..35fb31f682af 100644
--- a/drivers/net/ethernet/netronome/nfp/bpf/main.c
+++ b/drivers/net/ethernet/netronome/nfp/bpf/main.c
@@ -335,7 +335,7 @@ static int nfp_bpf_parse_capabilities(struct nfp_app *app)
335 return PTR_ERR(mem) == -ENOENT ? 0 : PTR_ERR(mem); 335 return PTR_ERR(mem) == -ENOENT ? 0 : PTR_ERR(mem);
336 336
337 start = mem; 337 start = mem;
338 while (mem - start + 8 < nfp_cpp_area_size(area)) { 338 while (mem - start + 8 <= nfp_cpp_area_size(area)) {
339 u8 __iomem *value; 339 u8 __iomem *value;
340 u32 type, length; 340 u32 type, length;
341 341
diff --git a/drivers/net/ethernet/qlogic/qed/qed_cxt.c b/drivers/net/ethernet/qlogic/qed/qed_cxt.c
index 00f41c145d4d..820b226d6ff8 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_cxt.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_cxt.c
@@ -77,7 +77,7 @@
77#define ILT_CFG_REG(cli, reg) PSWRQ2_REG_ ## cli ## _ ## reg ## _RT_OFFSET 77#define ILT_CFG_REG(cli, reg) PSWRQ2_REG_ ## cli ## _ ## reg ## _RT_OFFSET
78 78
79/* ILT entry structure */ 79/* ILT entry structure */
80#define ILT_ENTRY_PHY_ADDR_MASK 0x000FFFFFFFFFFFULL 80#define ILT_ENTRY_PHY_ADDR_MASK (~0ULL >> 12)
81#define ILT_ENTRY_PHY_ADDR_SHIFT 0 81#define ILT_ENTRY_PHY_ADDR_SHIFT 0
82#define ILT_ENTRY_VALID_MASK 0x1ULL 82#define ILT_ENTRY_VALID_MASK 0x1ULL
83#define ILT_ENTRY_VALID_SHIFT 52 83#define ILT_ENTRY_VALID_SHIFT 52
diff --git a/drivers/net/ethernet/qlogic/qed/qed_ll2.c b/drivers/net/ethernet/qlogic/qed/qed_ll2.c
index 38502815d681..468c59d2e491 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_ll2.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_ll2.c
@@ -292,6 +292,7 @@ static void qed_ll2_txq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle)
292 struct qed_ll2_tx_packet *p_pkt = NULL; 292 struct qed_ll2_tx_packet *p_pkt = NULL;
293 struct qed_ll2_info *p_ll2_conn; 293 struct qed_ll2_info *p_ll2_conn;
294 struct qed_ll2_tx_queue *p_tx; 294 struct qed_ll2_tx_queue *p_tx;
295 unsigned long flags = 0;
295 dma_addr_t tx_frag; 296 dma_addr_t tx_frag;
296 297
297 p_ll2_conn = qed_ll2_handle_sanity_inactive(p_hwfn, connection_handle); 298 p_ll2_conn = qed_ll2_handle_sanity_inactive(p_hwfn, connection_handle);
@@ -300,6 +301,7 @@ static void qed_ll2_txq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle)
300 301
301 p_tx = &p_ll2_conn->tx_queue; 302 p_tx = &p_ll2_conn->tx_queue;
302 303
304 spin_lock_irqsave(&p_tx->lock, flags);
303 while (!list_empty(&p_tx->active_descq)) { 305 while (!list_empty(&p_tx->active_descq)) {
304 p_pkt = list_first_entry(&p_tx->active_descq, 306 p_pkt = list_first_entry(&p_tx->active_descq,
305 struct qed_ll2_tx_packet, list_entry); 307 struct qed_ll2_tx_packet, list_entry);
@@ -309,6 +311,7 @@ static void qed_ll2_txq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle)
309 list_del(&p_pkt->list_entry); 311 list_del(&p_pkt->list_entry);
310 b_last_packet = list_empty(&p_tx->active_descq); 312 b_last_packet = list_empty(&p_tx->active_descq);
311 list_add_tail(&p_pkt->list_entry, &p_tx->free_descq); 313 list_add_tail(&p_pkt->list_entry, &p_tx->free_descq);
314 spin_unlock_irqrestore(&p_tx->lock, flags);
312 if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO) { 315 if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO) {
313 struct qed_ooo_buffer *p_buffer; 316 struct qed_ooo_buffer *p_buffer;
314 317
@@ -328,7 +331,9 @@ static void qed_ll2_txq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle)
328 b_last_frag, 331 b_last_frag,
329 b_last_packet); 332 b_last_packet);
330 } 333 }
334 spin_lock_irqsave(&p_tx->lock, flags);
331 } 335 }
336 spin_unlock_irqrestore(&p_tx->lock, flags);
332} 337}
333 338
334static int qed_ll2_txq_completion(struct qed_hwfn *p_hwfn, void *p_cookie) 339static int qed_ll2_txq_completion(struct qed_hwfn *p_hwfn, void *p_cookie)
@@ -556,6 +561,7 @@ static void qed_ll2_rxq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle)
556 struct qed_ll2_info *p_ll2_conn = NULL; 561 struct qed_ll2_info *p_ll2_conn = NULL;
557 struct qed_ll2_rx_packet *p_pkt = NULL; 562 struct qed_ll2_rx_packet *p_pkt = NULL;
558 struct qed_ll2_rx_queue *p_rx; 563 struct qed_ll2_rx_queue *p_rx;
564 unsigned long flags = 0;
559 565
560 p_ll2_conn = qed_ll2_handle_sanity_inactive(p_hwfn, connection_handle); 566 p_ll2_conn = qed_ll2_handle_sanity_inactive(p_hwfn, connection_handle);
561 if (!p_ll2_conn) 567 if (!p_ll2_conn)
@@ -563,13 +569,14 @@ static void qed_ll2_rxq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle)
563 569
564 p_rx = &p_ll2_conn->rx_queue; 570 p_rx = &p_ll2_conn->rx_queue;
565 571
572 spin_lock_irqsave(&p_rx->lock, flags);
566 while (!list_empty(&p_rx->active_descq)) { 573 while (!list_empty(&p_rx->active_descq)) {
567 p_pkt = list_first_entry(&p_rx->active_descq, 574 p_pkt = list_first_entry(&p_rx->active_descq,
568 struct qed_ll2_rx_packet, list_entry); 575 struct qed_ll2_rx_packet, list_entry);
569 if (!p_pkt) 576 if (!p_pkt)
570 break; 577 break;
571
572 list_move_tail(&p_pkt->list_entry, &p_rx->free_descq); 578 list_move_tail(&p_pkt->list_entry, &p_rx->free_descq);
579 spin_unlock_irqrestore(&p_rx->lock, flags);
573 580
574 if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO) { 581 if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO) {
575 struct qed_ooo_buffer *p_buffer; 582 struct qed_ooo_buffer *p_buffer;
@@ -588,7 +595,30 @@ static void qed_ll2_rxq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle)
588 cookie, 595 cookie,
589 rx_buf_addr, b_last); 596 rx_buf_addr, b_last);
590 } 597 }
598 spin_lock_irqsave(&p_rx->lock, flags);
591 } 599 }
600 spin_unlock_irqrestore(&p_rx->lock, flags);
601}
602
603static bool
604qed_ll2_lb_rxq_handler_slowpath(struct qed_hwfn *p_hwfn,
605 struct core_rx_slow_path_cqe *p_cqe)
606{
607 struct ooo_opaque *iscsi_ooo;
608 u32 cid;
609
610 if (p_cqe->ramrod_cmd_id != CORE_RAMROD_RX_QUEUE_FLUSH)
611 return false;
612
613 iscsi_ooo = (struct ooo_opaque *)&p_cqe->opaque_data;
614 if (iscsi_ooo->ooo_opcode != TCP_EVENT_DELETE_ISLES)
615 return false;
616
617 /* Need to make a flush */
618 cid = le32_to_cpu(iscsi_ooo->cid);
619 qed_ooo_release_connection_isles(p_hwfn, p_hwfn->p_ooo_info, cid);
620
621 return true;
592} 622}
593 623
594static int qed_ll2_lb_rxq_handler(struct qed_hwfn *p_hwfn, 624static int qed_ll2_lb_rxq_handler(struct qed_hwfn *p_hwfn,
@@ -617,6 +647,11 @@ static int qed_ll2_lb_rxq_handler(struct qed_hwfn *p_hwfn,
617 cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain); 647 cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain);
618 cqe_type = cqe->rx_cqe_sp.type; 648 cqe_type = cqe->rx_cqe_sp.type;
619 649
650 if (cqe_type == CORE_RX_CQE_TYPE_SLOW_PATH)
651 if (qed_ll2_lb_rxq_handler_slowpath(p_hwfn,
652 &cqe->rx_cqe_sp))
653 continue;
654
620 if (cqe_type != CORE_RX_CQE_TYPE_REGULAR) { 655 if (cqe_type != CORE_RX_CQE_TYPE_REGULAR) {
621 DP_NOTICE(p_hwfn, 656 DP_NOTICE(p_hwfn,
622 "Got a non-regular LB LL2 completion [type 0x%02x]\n", 657 "Got a non-regular LB LL2 completion [type 0x%02x]\n",
@@ -794,6 +829,9 @@ static int qed_ll2_lb_rxq_completion(struct qed_hwfn *p_hwfn, void *p_cookie)
794 struct qed_ll2_info *p_ll2_conn = (struct qed_ll2_info *)p_cookie; 829 struct qed_ll2_info *p_ll2_conn = (struct qed_ll2_info *)p_cookie;
795 int rc; 830 int rc;
796 831
832 if (!QED_LL2_RX_REGISTERED(p_ll2_conn))
833 return 0;
834
797 rc = qed_ll2_lb_rxq_handler(p_hwfn, p_ll2_conn); 835 rc = qed_ll2_lb_rxq_handler(p_hwfn, p_ll2_conn);
798 if (rc) 836 if (rc)
799 return rc; 837 return rc;
@@ -814,6 +852,9 @@ static int qed_ll2_lb_txq_completion(struct qed_hwfn *p_hwfn, void *p_cookie)
814 u16 new_idx = 0, num_bds = 0; 852 u16 new_idx = 0, num_bds = 0;
815 int rc; 853 int rc;
816 854
855 if (!QED_LL2_TX_REGISTERED(p_ll2_conn))
856 return 0;
857
817 new_idx = le16_to_cpu(*p_tx->p_fw_cons); 858 new_idx = le16_to_cpu(*p_tx->p_fw_cons);
818 num_bds = ((s16)new_idx - (s16)p_tx->bds_idx); 859 num_bds = ((s16)new_idx - (s16)p_tx->bds_idx);
819 860
@@ -1867,17 +1908,25 @@ int qed_ll2_terminate_connection(void *cxt, u8 connection_handle)
1867 1908
1868 /* Stop Tx & Rx of connection, if needed */ 1909 /* Stop Tx & Rx of connection, if needed */
1869 if (QED_LL2_TX_REGISTERED(p_ll2_conn)) { 1910 if (QED_LL2_TX_REGISTERED(p_ll2_conn)) {
1911 p_ll2_conn->tx_queue.b_cb_registred = false;
1912 smp_wmb(); /* Make sure this is seen by ll2_lb_rxq_completion */
1870 rc = qed_sp_ll2_tx_queue_stop(p_hwfn, p_ll2_conn); 1913 rc = qed_sp_ll2_tx_queue_stop(p_hwfn, p_ll2_conn);
1871 if (rc) 1914 if (rc)
1872 goto out; 1915 goto out;
1916
1873 qed_ll2_txq_flush(p_hwfn, connection_handle); 1917 qed_ll2_txq_flush(p_hwfn, connection_handle);
1918 qed_int_unregister_cb(p_hwfn, p_ll2_conn->tx_queue.tx_sb_index);
1874 } 1919 }
1875 1920
1876 if (QED_LL2_RX_REGISTERED(p_ll2_conn)) { 1921 if (QED_LL2_RX_REGISTERED(p_ll2_conn)) {
1922 p_ll2_conn->rx_queue.b_cb_registred = false;
1923 smp_wmb(); /* Make sure this is seen by ll2_lb_rxq_completion */
1877 rc = qed_sp_ll2_rx_queue_stop(p_hwfn, p_ll2_conn); 1924 rc = qed_sp_ll2_rx_queue_stop(p_hwfn, p_ll2_conn);
1878 if (rc) 1925 if (rc)
1879 goto out; 1926 goto out;
1927
1880 qed_ll2_rxq_flush(p_hwfn, connection_handle); 1928 qed_ll2_rxq_flush(p_hwfn, connection_handle);
1929 qed_int_unregister_cb(p_hwfn, p_ll2_conn->rx_queue.rx_sb_index);
1881 } 1930 }
1882 1931
1883 if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO) 1932 if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO)
@@ -1925,16 +1974,6 @@ void qed_ll2_release_connection(void *cxt, u8 connection_handle)
1925 if (!p_ll2_conn) 1974 if (!p_ll2_conn)
1926 return; 1975 return;
1927 1976
1928 if (QED_LL2_RX_REGISTERED(p_ll2_conn)) {
1929 p_ll2_conn->rx_queue.b_cb_registred = false;
1930 qed_int_unregister_cb(p_hwfn, p_ll2_conn->rx_queue.rx_sb_index);
1931 }
1932
1933 if (QED_LL2_TX_REGISTERED(p_ll2_conn)) {
1934 p_ll2_conn->tx_queue.b_cb_registred = false;
1935 qed_int_unregister_cb(p_hwfn, p_ll2_conn->tx_queue.tx_sb_index);
1936 }
1937
1938 kfree(p_ll2_conn->tx_queue.descq_mem); 1977 kfree(p_ll2_conn->tx_queue.descq_mem);
1939 qed_chain_free(p_hwfn->cdev, &p_ll2_conn->tx_queue.txq_chain); 1978 qed_chain_free(p_hwfn->cdev, &p_ll2_conn->tx_queue.txq_chain);
1940 1979
diff --git a/drivers/net/ethernet/qlogic/qede/qede_main.c b/drivers/net/ethernet/qlogic/qede/qede_main.c
index a01e7d6e5442..f6655e251bbd 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_main.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_main.c
@@ -1066,13 +1066,12 @@ static void __qede_remove(struct pci_dev *pdev, enum qede_remove_mode mode)
1066 1066
1067 DP_INFO(edev, "Starting qede_remove\n"); 1067 DP_INFO(edev, "Starting qede_remove\n");
1068 1068
1069 qede_rdma_dev_remove(edev);
1069 unregister_netdev(ndev); 1070 unregister_netdev(ndev);
1070 cancel_delayed_work_sync(&edev->sp_task); 1071 cancel_delayed_work_sync(&edev->sp_task);
1071 1072
1072 qede_ptp_disable(edev); 1073 qede_ptp_disable(edev);
1073 1074
1074 qede_rdma_dev_remove(edev);
1075
1076 edev->ops->common->set_power_state(cdev, PCI_D0); 1075 edev->ops->common->set_power_state(cdev, PCI_D0);
1077 1076
1078 pci_set_drvdata(pdev, NULL); 1077 pci_set_drvdata(pdev, NULL);
diff --git a/drivers/net/ethernet/renesas/sh_eth.h b/drivers/net/ethernet/renesas/sh_eth.h
index a5b792ce2ae7..1bf930d4a1e5 100644
--- a/drivers/net/ethernet/renesas/sh_eth.h
+++ b/drivers/net/ethernet/renesas/sh_eth.h
@@ -163,7 +163,7 @@ enum {
163}; 163};
164 164
165/* Driver's parameters */ 165/* Driver's parameters */
166#if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE) 166#if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_RENESAS)
167#define SH_ETH_RX_ALIGN 32 167#define SH_ETH_RX_ALIGN 32
168#else 168#else
169#define SH_ETH_RX_ALIGN 2 169#define SH_ETH_RX_ALIGN 2
diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c
index 450eec264a5e..4377c26f714d 100644
--- a/drivers/net/ipvlan/ipvlan_main.c
+++ b/drivers/net/ipvlan/ipvlan_main.c
@@ -792,8 +792,10 @@ static int ipvlan_device_event(struct notifier_block *unused,
792 break; 792 break;
793 793
794 case NETDEV_CHANGEADDR: 794 case NETDEV_CHANGEADDR:
795 list_for_each_entry(ipvlan, &port->ipvlans, pnode) 795 list_for_each_entry(ipvlan, &port->ipvlans, pnode) {
796 ether_addr_copy(ipvlan->dev->dev_addr, dev->dev_addr); 796 ether_addr_copy(ipvlan->dev->dev_addr, dev->dev_addr);
797 call_netdevice_notifiers(NETDEV_CHANGEADDR, ipvlan->dev);
798 }
797 break; 799 break;
798 800
799 case NETDEV_PRE_TYPE_CHANGE: 801 case NETDEV_PRE_TYPE_CHANGE:
diff --git a/drivers/net/phy/bcm-cygnus.c b/drivers/net/phy/bcm-cygnus.c
index 6838129839ca..e757b09f1889 100644
--- a/drivers/net/phy/bcm-cygnus.c
+++ b/drivers/net/phy/bcm-cygnus.c
@@ -61,17 +61,17 @@ static int bcm_cygnus_afe_config(struct phy_device *phydev)
61 return rc; 61 return rc;
62 62
63 /* make rcal=100, since rdb default is 000 */ 63 /* make rcal=100, since rdb default is 000 */
64 rc = bcm_phy_write_exp(phydev, MII_BRCM_CORE_EXPB1, 0x10); 64 rc = bcm_phy_write_exp_sel(phydev, MII_BRCM_CORE_EXPB1, 0x10);
65 if (rc < 0) 65 if (rc < 0)
66 return rc; 66 return rc;
67 67
68 /* CORE_EXPB0, Reset R_CAL/RC_CAL Engine */ 68 /* CORE_EXPB0, Reset R_CAL/RC_CAL Engine */
69 rc = bcm_phy_write_exp(phydev, MII_BRCM_CORE_EXPB0, 0x10); 69 rc = bcm_phy_write_exp_sel(phydev, MII_BRCM_CORE_EXPB0, 0x10);
70 if (rc < 0) 70 if (rc < 0)
71 return rc; 71 return rc;
72 72
73 /* CORE_EXPB0, Disable Reset R_CAL/RC_CAL Engine */ 73 /* CORE_EXPB0, Disable Reset R_CAL/RC_CAL Engine */
74 rc = bcm_phy_write_exp(phydev, MII_BRCM_CORE_EXPB0, 0x00); 74 rc = bcm_phy_write_exp_sel(phydev, MII_BRCM_CORE_EXPB0, 0x00);
75 75
76 return 0; 76 return 0;
77} 77}
diff --git a/drivers/net/phy/bcm-phy-lib.c b/drivers/net/phy/bcm-phy-lib.c
index 5ad130c3da43..d5e0833d69b9 100644
--- a/drivers/net/phy/bcm-phy-lib.c
+++ b/drivers/net/phy/bcm-phy-lib.c
@@ -56,7 +56,7 @@ int bcm54xx_auxctl_read(struct phy_device *phydev, u16 regnum)
56 /* The register must be written to both the Shadow Register Select and 56 /* The register must be written to both the Shadow Register Select and
57 * the Shadow Read Register Selector 57 * the Shadow Read Register Selector
58 */ 58 */
59 phy_write(phydev, MII_BCM54XX_AUX_CTL, regnum | 59 phy_write(phydev, MII_BCM54XX_AUX_CTL, MII_BCM54XX_AUXCTL_SHDWSEL_MASK |
60 regnum << MII_BCM54XX_AUXCTL_SHDWSEL_READ_SHIFT); 60 regnum << MII_BCM54XX_AUXCTL_SHDWSEL_READ_SHIFT);
61 return phy_read(phydev, MII_BCM54XX_AUX_CTL); 61 return phy_read(phydev, MII_BCM54XX_AUX_CTL);
62} 62}
diff --git a/drivers/net/phy/bcm-phy-lib.h b/drivers/net/phy/bcm-phy-lib.h
index 7c73808cbbde..81cceaa412fe 100644
--- a/drivers/net/phy/bcm-phy-lib.h
+++ b/drivers/net/phy/bcm-phy-lib.h
@@ -14,11 +14,18 @@
14#ifndef _LINUX_BCM_PHY_LIB_H 14#ifndef _LINUX_BCM_PHY_LIB_H
15#define _LINUX_BCM_PHY_LIB_H 15#define _LINUX_BCM_PHY_LIB_H
16 16
17#include <linux/brcmphy.h>
17#include <linux/phy.h> 18#include <linux/phy.h>
18 19
19int bcm_phy_write_exp(struct phy_device *phydev, u16 reg, u16 val); 20int bcm_phy_write_exp(struct phy_device *phydev, u16 reg, u16 val);
20int bcm_phy_read_exp(struct phy_device *phydev, u16 reg); 21int bcm_phy_read_exp(struct phy_device *phydev, u16 reg);
21 22
23static inline int bcm_phy_write_exp_sel(struct phy_device *phydev,
24 u16 reg, u16 val)
25{
26 return bcm_phy_write_exp(phydev, reg | MII_BCM54XX_EXP_SEL_ER, val);
27}
28
22int bcm54xx_auxctl_write(struct phy_device *phydev, u16 regnum, u16 val); 29int bcm54xx_auxctl_write(struct phy_device *phydev, u16 regnum, u16 val);
23int bcm54xx_auxctl_read(struct phy_device *phydev, u16 regnum); 30int bcm54xx_auxctl_read(struct phy_device *phydev, u16 regnum);
24 31
diff --git a/drivers/net/phy/bcm7xxx.c b/drivers/net/phy/bcm7xxx.c
index 29b1c88b55cc..01d2ff2f6241 100644
--- a/drivers/net/phy/bcm7xxx.c
+++ b/drivers/net/phy/bcm7xxx.c
@@ -65,10 +65,10 @@ struct bcm7xxx_phy_priv {
65static void r_rc_cal_reset(struct phy_device *phydev) 65static void r_rc_cal_reset(struct phy_device *phydev)
66{ 66{
67 /* Reset R_CAL/RC_CAL Engine */ 67 /* Reset R_CAL/RC_CAL Engine */
68 bcm_phy_write_exp(phydev, 0x00b0, 0x0010); 68 bcm_phy_write_exp_sel(phydev, 0x00b0, 0x0010);
69 69
70 /* Disable Reset R_AL/RC_CAL Engine */ 70 /* Disable Reset R_AL/RC_CAL Engine */
71 bcm_phy_write_exp(phydev, 0x00b0, 0x0000); 71 bcm_phy_write_exp_sel(phydev, 0x00b0, 0x0000);
72} 72}
73 73
74static int bcm7xxx_28nm_b0_afe_config_init(struct phy_device *phydev) 74static int bcm7xxx_28nm_b0_afe_config_init(struct phy_device *phydev)
diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index f41b224a9cdb..ab195f0916d6 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -573,9 +573,40 @@ static int ksz9031_config_init(struct phy_device *phydev)
573 ksz9031_of_load_skew_values(phydev, of_node, 573 ksz9031_of_load_skew_values(phydev, of_node,
574 MII_KSZ9031RN_TX_DATA_PAD_SKEW, 4, 574 MII_KSZ9031RN_TX_DATA_PAD_SKEW, 4,
575 tx_data_skews, 4); 575 tx_data_skews, 4);
576
577 /* Silicon Errata Sheet (DS80000691D or DS80000692D):
578 * When the device links in the 1000BASE-T slave mode only,
579 * the optional 125MHz reference output clock (CLK125_NDO)
580 * has wide duty cycle variation.
581 *
582 * The optional CLK125_NDO clock does not meet the RGMII
583 * 45/55 percent (min/max) duty cycle requirement and therefore
584 * cannot be used directly by the MAC side for clocking
585 * applications that have setup/hold time requirements on
586 * rising and falling clock edges.
587 *
588 * Workaround:
589 * Force the phy to be the master to receive a stable clock
590 * which meets the duty cycle requirement.
591 */
592 if (of_property_read_bool(of_node, "micrel,force-master")) {
593 result = phy_read(phydev, MII_CTRL1000);
594 if (result < 0)
595 goto err_force_master;
596
597 /* enable master mode, config & prefer master */
598 result |= CTL1000_ENABLE_MASTER | CTL1000_AS_MASTER;
599 result = phy_write(phydev, MII_CTRL1000, result);
600 if (result < 0)
601 goto err_force_master;
602 }
576 } 603 }
577 604
578 return ksz9031_center_flp_timing(phydev); 605 return ksz9031_center_flp_timing(phydev);
606
607err_force_master:
608 phydev_err(phydev, "failed to force the phy to master mode\n");
609 return result;
579} 610}
580 611
581#define KSZ8873MLL_GLOBAL_CONTROL_4 0x06 612#define KSZ8873MLL_GLOBAL_CONTROL_4 0x06
diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
index dc7c7ec43202..02ad03a2fab7 100644
--- a/drivers/net/ppp/ppp_generic.c
+++ b/drivers/net/ppp/ppp_generic.c
@@ -605,30 +605,13 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
605 605
606 if (cmd == PPPIOCDETACH) { 606 if (cmd == PPPIOCDETACH) {
607 /* 607 /*
608 * We have to be careful here... if the file descriptor 608 * PPPIOCDETACH is no longer supported as it was heavily broken,
609 * has been dup'd, we could have another process in the 609 * and is only known to have been used by pppd older than
610 * middle of a poll using the same file *, so we had 610 * ppp-2.4.2 (released November 2003).
611 * better not free the interface data structures -
612 * instead we fail the ioctl. Even in this case, we
613 * shut down the interface if we are the owner of it.
614 * Actually, we should get rid of PPPIOCDETACH, userland
615 * (i.e. pppd) could achieve the same effect by closing
616 * this fd and reopening /dev/ppp.
617 */ 611 */
612 pr_warn_once("%s (%d) used obsolete PPPIOCDETACH ioctl\n",
613 current->comm, current->pid);
618 err = -EINVAL; 614 err = -EINVAL;
619 if (pf->kind == INTERFACE) {
620 ppp = PF_TO_PPP(pf);
621 rtnl_lock();
622 if (file == ppp->owner)
623 unregister_netdevice(ppp->dev);
624 rtnl_unlock();
625 }
626 if (atomic_long_read(&file->f_count) < 2) {
627 ppp_release(NULL, file);
628 err = 0;
629 } else
630 pr_warn("PPPIOCDETACH file->f_count=%ld\n",
631 atomic_long_read(&file->f_count));
632 goto out; 615 goto out;
633 } 616 }
634 617
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index ef33950a45d9..45d807796a18 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -681,15 +681,6 @@ static void tun_queue_purge(struct tun_file *tfile)
681 skb_queue_purge(&tfile->sk.sk_error_queue); 681 skb_queue_purge(&tfile->sk.sk_error_queue);
682} 682}
683 683
684static void tun_cleanup_tx_ring(struct tun_file *tfile)
685{
686 if (tfile->tx_ring.queue) {
687 ptr_ring_cleanup(&tfile->tx_ring, tun_ptr_free);
688 xdp_rxq_info_unreg(&tfile->xdp_rxq);
689 memset(&tfile->tx_ring, 0, sizeof(tfile->tx_ring));
690 }
691}
692
693static void __tun_detach(struct tun_file *tfile, bool clean) 684static void __tun_detach(struct tun_file *tfile, bool clean)
694{ 685{
695 struct tun_file *ntfile; 686 struct tun_file *ntfile;
@@ -736,7 +727,9 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
736 tun->dev->reg_state == NETREG_REGISTERED) 727 tun->dev->reg_state == NETREG_REGISTERED)
737 unregister_netdevice(tun->dev); 728 unregister_netdevice(tun->dev);
738 } 729 }
739 tun_cleanup_tx_ring(tfile); 730 if (tun)
731 xdp_rxq_info_unreg(&tfile->xdp_rxq);
732 ptr_ring_cleanup(&tfile->tx_ring, tun_ptr_free);
740 sock_put(&tfile->sk); 733 sock_put(&tfile->sk);
741 } 734 }
742} 735}
@@ -783,14 +776,14 @@ static void tun_detach_all(struct net_device *dev)
783 tun_napi_del(tun, tfile); 776 tun_napi_del(tun, tfile);
784 /* Drop read queue */ 777 /* Drop read queue */
785 tun_queue_purge(tfile); 778 tun_queue_purge(tfile);
779 xdp_rxq_info_unreg(&tfile->xdp_rxq);
786 sock_put(&tfile->sk); 780 sock_put(&tfile->sk);
787 tun_cleanup_tx_ring(tfile);
788 } 781 }
789 list_for_each_entry_safe(tfile, tmp, &tun->disabled, next) { 782 list_for_each_entry_safe(tfile, tmp, &tun->disabled, next) {
790 tun_enable_queue(tfile); 783 tun_enable_queue(tfile);
791 tun_queue_purge(tfile); 784 tun_queue_purge(tfile);
785 xdp_rxq_info_unreg(&tfile->xdp_rxq);
792 sock_put(&tfile->sk); 786 sock_put(&tfile->sk);
793 tun_cleanup_tx_ring(tfile);
794 } 787 }
795 BUG_ON(tun->numdisabled != 0); 788 BUG_ON(tun->numdisabled != 0);
796 789
@@ -834,7 +827,8 @@ static int tun_attach(struct tun_struct *tun, struct file *file,
834 } 827 }
835 828
836 if (!tfile->detached && 829 if (!tfile->detached &&
837 ptr_ring_init(&tfile->tx_ring, dev->tx_queue_len, GFP_KERNEL)) { 830 ptr_ring_resize(&tfile->tx_ring, dev->tx_queue_len,
831 GFP_KERNEL, tun_ptr_free)) {
838 err = -ENOMEM; 832 err = -ENOMEM;
839 goto out; 833 goto out;
840 } 834 }
@@ -1429,6 +1423,13 @@ static void tun_net_init(struct net_device *dev)
1429 dev->max_mtu = MAX_MTU - dev->hard_header_len; 1423 dev->max_mtu = MAX_MTU - dev->hard_header_len;
1430} 1424}
1431 1425
1426static bool tun_sock_writeable(struct tun_struct *tun, struct tun_file *tfile)
1427{
1428 struct sock *sk = tfile->socket.sk;
1429
1430 return (tun->dev->flags & IFF_UP) && sock_writeable(sk);
1431}
1432
1432/* Character device part */ 1433/* Character device part */
1433 1434
1434/* Poll */ 1435/* Poll */
@@ -1451,10 +1452,14 @@ static __poll_t tun_chr_poll(struct file *file, poll_table *wait)
1451 if (!ptr_ring_empty(&tfile->tx_ring)) 1452 if (!ptr_ring_empty(&tfile->tx_ring))
1452 mask |= EPOLLIN | EPOLLRDNORM; 1453 mask |= EPOLLIN | EPOLLRDNORM;
1453 1454
1454 if (tun->dev->flags & IFF_UP && 1455 /* Make sure SOCKWQ_ASYNC_NOSPACE is set if not writable to
1455 (sock_writeable(sk) || 1456 * guarantee EPOLLOUT to be raised by either here or
1456 (!test_and_set_bit(SOCKWQ_ASYNC_NOSPACE, &sk->sk_socket->flags) && 1457 * tun_sock_write_space(). Then process could get notification
1457 sock_writeable(sk)))) 1458 * after it writes to a down device and meets -EIO.
1459 */
1460 if (tun_sock_writeable(tun, tfile) ||
1461 (!test_and_set_bit(SOCKWQ_ASYNC_NOSPACE, &sk->sk_socket->flags) &&
1462 tun_sock_writeable(tun, tfile)))
1458 mask |= EPOLLOUT | EPOLLWRNORM; 1463 mask |= EPOLLOUT | EPOLLWRNORM;
1459 1464
1460 if (tun->dev->reg_state != NETREG_REGISTERED) 1465 if (tun->dev->reg_state != NETREG_REGISTERED)
@@ -3219,6 +3224,11 @@ static int tun_chr_open(struct inode *inode, struct file * file)
3219 &tun_proto, 0); 3224 &tun_proto, 0);
3220 if (!tfile) 3225 if (!tfile)
3221 return -ENOMEM; 3226 return -ENOMEM;
3227 if (ptr_ring_init(&tfile->tx_ring, 0, GFP_KERNEL)) {
3228 sk_free(&tfile->sk);
3229 return -ENOMEM;
3230 }
3231
3222 RCU_INIT_POINTER(tfile->tun, NULL); 3232 RCU_INIT_POINTER(tfile->tun, NULL);
3223 tfile->flags = 0; 3233 tfile->flags = 0;
3224 tfile->ifindex = 0; 3234 tfile->ifindex = 0;
@@ -3239,8 +3249,6 @@ static int tun_chr_open(struct inode *inode, struct file * file)
3239 3249
3240 sock_set_flag(&tfile->sk, SOCK_ZEROCOPY); 3250 sock_set_flag(&tfile->sk, SOCK_ZEROCOPY);
3241 3251
3242 memset(&tfile->tx_ring, 0, sizeof(tfile->tx_ring));
3243
3244 return 0; 3252 return 0;
3245} 3253}
3246 3254
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 770422e953f7..032e1ac10a30 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -707,6 +707,13 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
707 void *data; 707 void *data;
708 u32 act; 708 u32 act;
709 709
710 /* Transient failure which in theory could occur if
711 * in-flight packets from before XDP was enabled reach
712 * the receive path after XDP is loaded.
713 */
714 if (unlikely(hdr->hdr.gso_type))
715 goto err_xdp;
716
710 /* This happens when rx buffer size is underestimated 717 /* This happens when rx buffer size is underestimated
711 * or headroom is not enough because of the buffer 718 * or headroom is not enough because of the buffer
712 * was refilled before XDP is set. This should only 719 * was refilled before XDP is set. This should only
@@ -727,14 +734,6 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
727 xdp_page = page; 734 xdp_page = page;
728 } 735 }
729 736
730 /* Transient failure which in theory could occur if
731 * in-flight packets from before XDP was enabled reach
732 * the receive path after XDP is loaded. In practice I
733 * was not able to create this condition.
734 */
735 if (unlikely(hdr->hdr.gso_type))
736 goto err_xdp;
737
738 /* Allow consuming headroom but reserve enough space to push 737 /* Allow consuming headroom but reserve enough space to push
739 * the descriptor on if we get an XDP_TX return code. 738 * the descriptor on if we get an XDP_TX return code.
740 */ 739 */
@@ -775,7 +774,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
775 } 774 }
776 *xdp_xmit = true; 775 *xdp_xmit = true;
777 if (unlikely(xdp_page != page)) 776 if (unlikely(xdp_page != page))
778 goto err_xdp; 777 put_page(page);
779 rcu_read_unlock(); 778 rcu_read_unlock();
780 goto xdp_xmit; 779 goto xdp_xmit;
781 case XDP_REDIRECT: 780 case XDP_REDIRECT:
@@ -787,7 +786,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
787 } 786 }
788 *xdp_xmit = true; 787 *xdp_xmit = true;
789 if (unlikely(xdp_page != page)) 788 if (unlikely(xdp_page != page))
790 goto err_xdp; 789 put_page(page);
791 rcu_read_unlock(); 790 rcu_read_unlock();
792 goto xdp_xmit; 791 goto xdp_xmit;
793 default: 792 default:
@@ -875,7 +874,7 @@ err_xdp:
875 rcu_read_unlock(); 874 rcu_read_unlock();
876err_skb: 875err_skb:
877 put_page(page); 876 put_page(page);
878 while (--num_buf) { 877 while (num_buf-- > 1) {
879 buf = virtqueue_get_buf(rq->vq, &len); 878 buf = virtqueue_get_buf(rq->vq, &len);
880 if (unlikely(!buf)) { 879 if (unlikely(!buf)) {
881 pr_debug("%s: rx error: %d buffers missing\n", 880 pr_debug("%s: rx error: %d buffers missing\n",
diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c
index 9ebe2a689966..27a9bb8c9611 100644
--- a/drivers/net/vmxnet3/vmxnet3_drv.c
+++ b/drivers/net/vmxnet3/vmxnet3_drv.c
@@ -369,6 +369,11 @@ vmxnet3_tq_tx_complete(struct vmxnet3_tx_queue *tq,
369 369
370 gdesc = tq->comp_ring.base + tq->comp_ring.next2proc; 370 gdesc = tq->comp_ring.base + tq->comp_ring.next2proc;
371 while (VMXNET3_TCD_GET_GEN(&gdesc->tcd) == tq->comp_ring.gen) { 371 while (VMXNET3_TCD_GET_GEN(&gdesc->tcd) == tq->comp_ring.gen) {
372 /* Prevent any &gdesc->tcd field from being (speculatively)
373 * read before (&gdesc->tcd)->gen is read.
374 */
375 dma_rmb();
376
372 completed += vmxnet3_unmap_pkt(VMXNET3_TCD_GET_TXIDX( 377 completed += vmxnet3_unmap_pkt(VMXNET3_TCD_GET_TXIDX(
373 &gdesc->tcd), tq, adapter->pdev, 378 &gdesc->tcd), tq, adapter->pdev,
374 adapter); 379 adapter);
@@ -1103,6 +1108,11 @@ vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq,
1103 gdesc->txd.tci = skb_vlan_tag_get(skb); 1108 gdesc->txd.tci = skb_vlan_tag_get(skb);
1104 } 1109 }
1105 1110
1111 /* Ensure that the write to (&gdesc->txd)->gen will be observed after
1112 * all other writes to &gdesc->txd.
1113 */
1114 dma_wmb();
1115
1106 /* finally flips the GEN bit of the SOP desc. */ 1116 /* finally flips the GEN bit of the SOP desc. */
1107 gdesc->dword[2] = cpu_to_le32(le32_to_cpu(gdesc->dword[2]) ^ 1117 gdesc->dword[2] = cpu_to_le32(le32_to_cpu(gdesc->dword[2]) ^
1108 VMXNET3_TXD_GEN); 1118 VMXNET3_TXD_GEN);
@@ -1298,6 +1308,12 @@ vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq,
1298 */ 1308 */
1299 break; 1309 break;
1300 } 1310 }
1311
1312 /* Prevent any rcd field from being (speculatively) read before
1313 * rcd->gen is read.
1314 */
1315 dma_rmb();
1316
1301 BUG_ON(rcd->rqID != rq->qid && rcd->rqID != rq->qid2 && 1317 BUG_ON(rcd->rqID != rq->qid && rcd->rqID != rq->qid2 &&
1302 rcd->rqID != rq->dataRingQid); 1318 rcd->rqID != rq->dataRingQid);
1303 idx = rcd->rxdIdx; 1319 idx = rcd->rxdIdx;
@@ -1528,6 +1544,12 @@ rcd_done:
1528 ring->next2comp = idx; 1544 ring->next2comp = idx;
1529 num_to_alloc = vmxnet3_cmd_ring_desc_avail(ring); 1545 num_to_alloc = vmxnet3_cmd_ring_desc_avail(ring);
1530 ring = rq->rx_ring + ring_idx; 1546 ring = rq->rx_ring + ring_idx;
1547
1548 /* Ensure that the writes to rxd->gen bits will be observed
1549 * after all other writes to rxd objects.
1550 */
1551 dma_wmb();
1552
1531 while (num_to_alloc) { 1553 while (num_to_alloc) {
1532 vmxnet3_getRxDesc(rxd, &ring->base[ring->next2fill].rxd, 1554 vmxnet3_getRxDesc(rxd, &ring->base[ring->next2fill].rxd,
1533 &rxCmdDesc); 1555 &rxCmdDesc);
@@ -2688,7 +2710,7 @@ vmxnet3_set_mac_addr(struct net_device *netdev, void *p)
2688/* ==================== initialization and cleanup routines ============ */ 2710/* ==================== initialization and cleanup routines ============ */
2689 2711
2690static int 2712static int
2691vmxnet3_alloc_pci_resources(struct vmxnet3_adapter *adapter, bool *dma64) 2713vmxnet3_alloc_pci_resources(struct vmxnet3_adapter *adapter)
2692{ 2714{
2693 int err; 2715 int err;
2694 unsigned long mmio_start, mmio_len; 2716 unsigned long mmio_start, mmio_len;
@@ -2700,30 +2722,12 @@ vmxnet3_alloc_pci_resources(struct vmxnet3_adapter *adapter, bool *dma64)
2700 return err; 2722 return err;
2701 } 2723 }
2702 2724
2703 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) == 0) {
2704 if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) {
2705 dev_err(&pdev->dev,
2706 "pci_set_consistent_dma_mask failed\n");
2707 err = -EIO;
2708 goto err_set_mask;
2709 }
2710 *dma64 = true;
2711 } else {
2712 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) {
2713 dev_err(&pdev->dev,
2714 "pci_set_dma_mask failed\n");
2715 err = -EIO;
2716 goto err_set_mask;
2717 }
2718 *dma64 = false;
2719 }
2720
2721 err = pci_request_selected_regions(pdev, (1 << 2) - 1, 2725 err = pci_request_selected_regions(pdev, (1 << 2) - 1,
2722 vmxnet3_driver_name); 2726 vmxnet3_driver_name);
2723 if (err) { 2727 if (err) {
2724 dev_err(&pdev->dev, 2728 dev_err(&pdev->dev,
2725 "Failed to request region for adapter: error %d\n", err); 2729 "Failed to request region for adapter: error %d\n", err);
2726 goto err_set_mask; 2730 goto err_enable_device;
2727 } 2731 }
2728 2732
2729 pci_set_master(pdev); 2733 pci_set_master(pdev);
@@ -2751,7 +2755,7 @@ err_bar1:
2751 iounmap(adapter->hw_addr0); 2755 iounmap(adapter->hw_addr0);
2752err_ioremap: 2756err_ioremap:
2753 pci_release_selected_regions(pdev, (1 << 2) - 1); 2757 pci_release_selected_regions(pdev, (1 << 2) - 1);
2754err_set_mask: 2758err_enable_device:
2755 pci_disable_device(pdev); 2759 pci_disable_device(pdev);
2756 return err; 2760 return err;
2757} 2761}
@@ -3254,7 +3258,7 @@ vmxnet3_probe_device(struct pci_dev *pdev,
3254#endif 3258#endif
3255 }; 3259 };
3256 int err; 3260 int err;
3257 bool dma64 = false; /* stupid gcc */ 3261 bool dma64;
3258 u32 ver; 3262 u32 ver;
3259 struct net_device *netdev; 3263 struct net_device *netdev;
3260 struct vmxnet3_adapter *adapter; 3264 struct vmxnet3_adapter *adapter;
@@ -3300,6 +3304,24 @@ vmxnet3_probe_device(struct pci_dev *pdev,
3300 adapter->rx_ring_size = VMXNET3_DEF_RX_RING_SIZE; 3304 adapter->rx_ring_size = VMXNET3_DEF_RX_RING_SIZE;
3301 adapter->rx_ring2_size = VMXNET3_DEF_RX_RING2_SIZE; 3305 adapter->rx_ring2_size = VMXNET3_DEF_RX_RING2_SIZE;
3302 3306
3307 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) == 0) {
3308 if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) {
3309 dev_err(&pdev->dev,
3310 "pci_set_consistent_dma_mask failed\n");
3311 err = -EIO;
3312 goto err_set_mask;
3313 }
3314 dma64 = true;
3315 } else {
3316 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) {
3317 dev_err(&pdev->dev,
3318 "pci_set_dma_mask failed\n");
3319 err = -EIO;
3320 goto err_set_mask;
3321 }
3322 dma64 = false;
3323 }
3324
3303 spin_lock_init(&adapter->cmd_lock); 3325 spin_lock_init(&adapter->cmd_lock);
3304 adapter->adapter_pa = dma_map_single(&adapter->pdev->dev, adapter, 3326 adapter->adapter_pa = dma_map_single(&adapter->pdev->dev, adapter,
3305 sizeof(struct vmxnet3_adapter), 3327 sizeof(struct vmxnet3_adapter),
@@ -3307,7 +3329,7 @@ vmxnet3_probe_device(struct pci_dev *pdev,
3307 if (dma_mapping_error(&adapter->pdev->dev, adapter->adapter_pa)) { 3329 if (dma_mapping_error(&adapter->pdev->dev, adapter->adapter_pa)) {
3308 dev_err(&pdev->dev, "Failed to map dma\n"); 3330 dev_err(&pdev->dev, "Failed to map dma\n");
3309 err = -EFAULT; 3331 err = -EFAULT;
3310 goto err_dma_map; 3332 goto err_set_mask;
3311 } 3333 }
3312 adapter->shared = dma_alloc_coherent( 3334 adapter->shared = dma_alloc_coherent(
3313 &adapter->pdev->dev, 3335 &adapter->pdev->dev,
@@ -3358,7 +3380,7 @@ vmxnet3_probe_device(struct pci_dev *pdev,
3358 } 3380 }
3359#endif /* VMXNET3_RSS */ 3381#endif /* VMXNET3_RSS */
3360 3382
3361 err = vmxnet3_alloc_pci_resources(adapter, &dma64); 3383 err = vmxnet3_alloc_pci_resources(adapter);
3362 if (err < 0) 3384 if (err < 0)
3363 goto err_alloc_pci; 3385 goto err_alloc_pci;
3364 3386
@@ -3504,7 +3526,7 @@ err_alloc_queue_desc:
3504err_alloc_shared: 3526err_alloc_shared:
3505 dma_unmap_single(&adapter->pdev->dev, adapter->adapter_pa, 3527 dma_unmap_single(&adapter->pdev->dev, adapter->adapter_pa,
3506 sizeof(struct vmxnet3_adapter), PCI_DMA_TODEVICE); 3528 sizeof(struct vmxnet3_adapter), PCI_DMA_TODEVICE);
3507err_dma_map: 3529err_set_mask:
3508 free_netdev(netdev); 3530 free_netdev(netdev);
3509 return err; 3531 return err;
3510} 3532}
diff --git a/drivers/net/vmxnet3/vmxnet3_int.h b/drivers/net/vmxnet3/vmxnet3_int.h
index a3326463b71f..a2c554f8a61b 100644
--- a/drivers/net/vmxnet3/vmxnet3_int.h
+++ b/drivers/net/vmxnet3/vmxnet3_int.h
@@ -69,10 +69,12 @@
69/* 69/*
70 * Version numbers 70 * Version numbers
71 */ 71 */
72#define VMXNET3_DRIVER_VERSION_STRING "1.4.14.0-k" 72#define VMXNET3_DRIVER_VERSION_STRING "1.4.16.0-k"
73 73
74/* a 32-bit int, each byte encode a verion number in VMXNET3_DRIVER_VERSION */ 74/* Each byte of this 32-bit integer encodes a version number in
75#define VMXNET3_DRIVER_VERSION_NUM 0x01040e00 75 * VMXNET3_DRIVER_VERSION_STRING.
76 */
77#define VMXNET3_DRIVER_VERSION_NUM 0x01041000
76 78
77#if defined(CONFIG_PCI_MSI) 79#if defined(CONFIG_PCI_MSI)
78 /* RSS only makes sense if MSI-X is supported. */ 80 /* RSS only makes sense if MSI-X is supported. */
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index 4a017a0d71ea..920c23e542a5 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -3340,7 +3340,7 @@ out_err:
3340static int hwsim_dump_radio_nl(struct sk_buff *skb, 3340static int hwsim_dump_radio_nl(struct sk_buff *skb,
3341 struct netlink_callback *cb) 3341 struct netlink_callback *cb)
3342{ 3342{
3343 int last_idx = cb->args[0]; 3343 int last_idx = cb->args[0] - 1;
3344 struct mac80211_hwsim_data *data = NULL; 3344 struct mac80211_hwsim_data *data = NULL;
3345 int res = 0; 3345 int res = 0;
3346 void *hdr; 3346 void *hdr;
@@ -3368,7 +3368,7 @@ static int hwsim_dump_radio_nl(struct sk_buff *skb,
3368 last_idx = data->idx; 3368 last_idx = data->idx;
3369 } 3369 }
3370 3370
3371 cb->args[0] = last_idx; 3371 cb->args[0] = last_idx + 1;
3372 3372
3373 /* list changed, but no new element sent, set interrupted flag */ 3373 /* list changed, but no new element sent, set interrupted flag */
3374 if (skb->len == 0 && cb->prev_seq && cb->seq != cb->prev_seq) { 3374 if (skb->len == 0 && cb->prev_seq && cb->seq != cb->prev_seq) {
diff --git a/drivers/nvme/host/Kconfig b/drivers/nvme/host/Kconfig
index 88a8b5916624..dbb7464c018c 100644
--- a/drivers/nvme/host/Kconfig
+++ b/drivers/nvme/host/Kconfig
@@ -27,7 +27,7 @@ config NVME_FABRICS
27 27
28config NVME_RDMA 28config NVME_RDMA
29 tristate "NVM Express over Fabrics RDMA host driver" 29 tristate "NVM Express over Fabrics RDMA host driver"
30 depends on INFINIBAND && INFINIBAND_ADDR_TRANS && BLOCK 30 depends on INFINIBAND_ADDR_TRANS && BLOCK
31 select NVME_CORE 31 select NVME_CORE
32 select NVME_FABRICS 32 select NVME_FABRICS
33 select SG_POOL 33 select SG_POOL
diff --git a/drivers/nvme/target/Kconfig b/drivers/nvme/target/Kconfig
index 3c7b61ddb0d1..7595664ee753 100644
--- a/drivers/nvme/target/Kconfig
+++ b/drivers/nvme/target/Kconfig
@@ -27,7 +27,7 @@ config NVME_TARGET_LOOP
27 27
28config NVME_TARGET_RDMA 28config NVME_TARGET_RDMA
29 tristate "NVMe over Fabrics RDMA target support" 29 tristate "NVMe over Fabrics RDMA target support"
30 depends on INFINIBAND && INFINIBAND_ADDR_TRANS 30 depends on INFINIBAND_ADDR_TRANS
31 depends on NVME_TARGET 31 depends on NVME_TARGET
32 select SGL_ALLOC 32 select SGL_ALLOC
33 help 33 help
diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
index e7bbdf947bbc..8350ca2311c7 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -91,6 +91,8 @@ static int send_command(struct cros_ec_device *ec_dev,
91 usleep_range(10000, 11000); 91 usleep_range(10000, 11000);
92 92
93 ret = (*xfer_fxn)(ec_dev, status_msg); 93 ret = (*xfer_fxn)(ec_dev, status_msg);
94 if (ret == -EAGAIN)
95 continue;
94 if (ret < 0) 96 if (ret < 0)
95 break; 97 break;
96 98
diff --git a/drivers/s390/scsi/zfcp_dbf.c b/drivers/s390/scsi/zfcp_dbf.c
index a8b831000b2d..18c4f933e8b9 100644
--- a/drivers/s390/scsi/zfcp_dbf.c
+++ b/drivers/s390/scsi/zfcp_dbf.c
@@ -4,7 +4,7 @@
4 * 4 *
5 * Debug traces for zfcp. 5 * Debug traces for zfcp.
6 * 6 *
7 * Copyright IBM Corp. 2002, 2017 7 * Copyright IBM Corp. 2002, 2018
8 */ 8 */
9 9
10#define KMSG_COMPONENT "zfcp" 10#define KMSG_COMPONENT "zfcp"
@@ -308,6 +308,27 @@ void zfcp_dbf_rec_trig(char *tag, struct zfcp_adapter *adapter,
308 spin_unlock_irqrestore(&dbf->rec_lock, flags); 308 spin_unlock_irqrestore(&dbf->rec_lock, flags);
309} 309}
310 310
311/**
312 * zfcp_dbf_rec_trig_lock - trace event related to triggered recovery with lock
313 * @tag: identifier for event
314 * @adapter: adapter on which the erp_action should run
315 * @port: remote port involved in the erp_action
316 * @sdev: scsi device involved in the erp_action
317 * @want: wanted erp_action
318 * @need: required erp_action
319 *
320 * The adapter->erp_lock must not be held.
321 */
322void zfcp_dbf_rec_trig_lock(char *tag, struct zfcp_adapter *adapter,
323 struct zfcp_port *port, struct scsi_device *sdev,
324 u8 want, u8 need)
325{
326 unsigned long flags;
327
328 read_lock_irqsave(&adapter->erp_lock, flags);
329 zfcp_dbf_rec_trig(tag, adapter, port, sdev, want, need);
330 read_unlock_irqrestore(&adapter->erp_lock, flags);
331}
311 332
312/** 333/**
313 * zfcp_dbf_rec_run_lvl - trace event related to running recovery 334 * zfcp_dbf_rec_run_lvl - trace event related to running recovery
diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h
index bf8ea4df2bb8..e5eed8aac0ce 100644
--- a/drivers/s390/scsi/zfcp_ext.h
+++ b/drivers/s390/scsi/zfcp_ext.h
@@ -4,7 +4,7 @@
4 * 4 *
5 * External function declarations. 5 * External function declarations.
6 * 6 *
7 * Copyright IBM Corp. 2002, 2016 7 * Copyright IBM Corp. 2002, 2018
8 */ 8 */
9 9
10#ifndef ZFCP_EXT_H 10#ifndef ZFCP_EXT_H
@@ -35,6 +35,9 @@ extern int zfcp_dbf_adapter_register(struct zfcp_adapter *);
35extern void zfcp_dbf_adapter_unregister(struct zfcp_adapter *); 35extern void zfcp_dbf_adapter_unregister(struct zfcp_adapter *);
36extern void zfcp_dbf_rec_trig(char *, struct zfcp_adapter *, 36extern void zfcp_dbf_rec_trig(char *, struct zfcp_adapter *,
37 struct zfcp_port *, struct scsi_device *, u8, u8); 37 struct zfcp_port *, struct scsi_device *, u8, u8);
38extern void zfcp_dbf_rec_trig_lock(char *tag, struct zfcp_adapter *adapter,
39 struct zfcp_port *port,
40 struct scsi_device *sdev, u8 want, u8 need);
38extern void zfcp_dbf_rec_run(char *, struct zfcp_erp_action *); 41extern void zfcp_dbf_rec_run(char *, struct zfcp_erp_action *);
39extern void zfcp_dbf_rec_run_lvl(int level, char *tag, 42extern void zfcp_dbf_rec_run_lvl(int level, char *tag,
40 struct zfcp_erp_action *erp); 43 struct zfcp_erp_action *erp);
diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
index 4d2ba5682493..22f9562f415c 100644
--- a/drivers/s390/scsi/zfcp_scsi.c
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -4,7 +4,7 @@
4 * 4 *
5 * Interface to Linux SCSI midlayer. 5 * Interface to Linux SCSI midlayer.
6 * 6 *
7 * Copyright IBM Corp. 2002, 2017 7 * Copyright IBM Corp. 2002, 2018
8 */ 8 */
9 9
10#define KMSG_COMPONENT "zfcp" 10#define KMSG_COMPONENT "zfcp"
@@ -618,9 +618,9 @@ static void zfcp_scsi_rport_register(struct zfcp_port *port)
618 ids.port_id = port->d_id; 618 ids.port_id = port->d_id;
619 ids.roles = FC_RPORT_ROLE_FCP_TARGET; 619 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
620 620
621 zfcp_dbf_rec_trig("scpaddy", port->adapter, port, NULL, 621 zfcp_dbf_rec_trig_lock("scpaddy", port->adapter, port, NULL,
622 ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD, 622 ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD,
623 ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD); 623 ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD);
624 rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids); 624 rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids);
625 if (!rport) { 625 if (!rport) {
626 dev_err(&port->adapter->ccw_device->dev, 626 dev_err(&port->adapter->ccw_device->dev,
@@ -642,9 +642,9 @@ static void zfcp_scsi_rport_block(struct zfcp_port *port)
642 struct fc_rport *rport = port->rport; 642 struct fc_rport *rport = port->rport;
643 643
644 if (rport) { 644 if (rport) {
645 zfcp_dbf_rec_trig("scpdely", port->adapter, port, NULL, 645 zfcp_dbf_rec_trig_lock("scpdely", port->adapter, port, NULL,
646 ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL, 646 ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL,
647 ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL); 647 ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL);
648 fc_remote_port_delete(rport); 648 fc_remote_port_delete(rport);
649 port->rport = NULL; 649 port->rport = NULL;
650 } 650 }
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index e29f9b8fd66d..56c940394729 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -182,7 +182,7 @@ zalon7xx-objs := zalon.o ncr53c8xx.o
182NCR_Q720_mod-objs := NCR_Q720.o ncr53c8xx.o 182NCR_Q720_mod-objs := NCR_Q720.o ncr53c8xx.o
183 183
184# Files generated that shall be removed upon make clean 184# Files generated that shall be removed upon make clean
185clean-files := 53c700_d.h 53c700_u.h 185clean-files := 53c700_d.h 53c700_u.h scsi_devinfo_tbl.c
186 186
187$(obj)/53c700.o $(MODVERDIR)/$(obj)/53c700.ver: $(obj)/53c700_d.h 187$(obj)/53c700.o $(MODVERDIR)/$(obj)/53c700.ver: $(obj)/53c700_d.h
188 188
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index c198b96368dd..5c40d809830f 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1894,7 +1894,7 @@ retry:
1894 num = (rem_sz > scatter_elem_sz_prev) ? 1894 num = (rem_sz > scatter_elem_sz_prev) ?
1895 scatter_elem_sz_prev : rem_sz; 1895 scatter_elem_sz_prev : rem_sz;
1896 1896
1897 schp->pages[k] = alloc_pages(gfp_mask, order); 1897 schp->pages[k] = alloc_pages(gfp_mask | __GFP_ZERO, order);
1898 if (!schp->pages[k]) 1898 if (!schp->pages[k])
1899 goto out; 1899 goto out;
1900 1900
diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c
index 2a21f2d48592..35fab1e18adc 100644
--- a/drivers/scsi/sr_ioctl.c
+++ b/drivers/scsi/sr_ioctl.c
@@ -188,9 +188,13 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
188 struct scsi_device *SDev; 188 struct scsi_device *SDev;
189 struct scsi_sense_hdr sshdr; 189 struct scsi_sense_hdr sshdr;
190 int result, err = 0, retries = 0; 190 int result, err = 0, retries = 0;
191 unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE], *senseptr = NULL;
191 192
192 SDev = cd->device; 193 SDev = cd->device;
193 194
195 if (cgc->sense)
196 senseptr = sense_buffer;
197
194 retry: 198 retry:
195 if (!scsi_block_when_processing_errors(SDev)) { 199 if (!scsi_block_when_processing_errors(SDev)) {
196 err = -ENODEV; 200 err = -ENODEV;
@@ -198,10 +202,12 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
198 } 202 }
199 203
200 result = scsi_execute(SDev, cgc->cmd, cgc->data_direction, 204 result = scsi_execute(SDev, cgc->cmd, cgc->data_direction,
201 cgc->buffer, cgc->buflen, 205 cgc->buffer, cgc->buflen, senseptr, &sshdr,
202 (unsigned char *)cgc->sense, &sshdr,
203 cgc->timeout, IOCTL_RETRIES, 0, 0, NULL); 206 cgc->timeout, IOCTL_RETRIES, 0, 0, NULL);
204 207
208 if (cgc->sense)
209 memcpy(cgc->sense, sense_buffer, sizeof(*cgc->sense));
210
205 /* Minimal error checking. Ignore cases we know about, and report the rest. */ 211 /* Minimal error checking. Ignore cases we know about, and report the rest. */
206 if (driver_byte(result) != 0) { 212 if (driver_byte(result) != 0) {
207 switch (sshdr.sense_key) { 213 switch (sshdr.sense_key) {
diff --git a/drivers/ssb/Kconfig b/drivers/ssb/Kconfig
index 9371651d8017..c574dd210500 100644
--- a/drivers/ssb/Kconfig
+++ b/drivers/ssb/Kconfig
@@ -117,7 +117,7 @@ config SSB_SERIAL
117 117
118config SSB_DRIVER_PCICORE_POSSIBLE 118config SSB_DRIVER_PCICORE_POSSIBLE
119 bool 119 bool
120 depends on SSB_PCIHOST && SSB = y 120 depends on SSB_PCIHOST
121 default y 121 default y
122 122
123config SSB_DRIVER_PCICORE 123config SSB_DRIVER_PCICORE
@@ -131,7 +131,7 @@ config SSB_DRIVER_PCICORE
131 131
132config SSB_PCICORE_HOSTMODE 132config SSB_PCICORE_HOSTMODE
133 bool "Hostmode support for SSB PCI core" 133 bool "Hostmode support for SSB PCI core"
134 depends on SSB_DRIVER_PCICORE && SSB_DRIVER_MIPS 134 depends on SSB_DRIVER_PCICORE && SSB_DRIVER_MIPS && SSB = y
135 help 135 help
136 PCIcore hostmode operation (external PCI bus). 136 PCIcore hostmode operation (external PCI bus).
137 137
diff --git a/drivers/staging/lustre/lnet/Kconfig b/drivers/staging/lustre/lnet/Kconfig
index ad049e6f24e4..f3b1ad4bd3dc 100644
--- a/drivers/staging/lustre/lnet/Kconfig
+++ b/drivers/staging/lustre/lnet/Kconfig
@@ -34,7 +34,7 @@ config LNET_SELFTEST
34 34
35config LNET_XPRT_IB 35config LNET_XPRT_IB
36 tristate "LNET infiniband support" 36 tristate "LNET infiniband support"
37 depends on LNET && PCI && INFINIBAND && INFINIBAND_ADDR_TRANS 37 depends on LNET && PCI && INFINIBAND_ADDR_TRANS
38 default LNET && INFINIBAND 38 default LNET && INFINIBAND
39 help 39 help
40 This option allows the LNET users to use infiniband as an 40 This option allows the LNET users to use infiniband as an
diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
index 4ad89ea71a70..4f26bdc3d1dc 100644
--- a/drivers/target/target_core_user.c
+++ b/drivers/target/target_core_user.c
@@ -2121,6 +2121,8 @@ static ssize_t tcmu_qfull_time_out_store(struct config_item *item,
2121 2121
2122 if (val >= 0) { 2122 if (val >= 0) {
2123 udev->qfull_time_out = val * MSEC_PER_SEC; 2123 udev->qfull_time_out = val * MSEC_PER_SEC;
2124 } else if (val == -1) {
2125 udev->qfull_time_out = val;
2124 } else { 2126 } else {
2125 printk(KERN_ERR "Invalid qfull timeout value %d\n", val); 2127 printk(KERN_ERR "Invalid qfull timeout value %d\n", val);
2126 return -EINVAL; 2128 return -EINVAL;
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index f3bd8e941224..f0be5f35ab28 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -981,6 +981,7 @@ static int vhost_process_iotlb_msg(struct vhost_dev *dev,
981{ 981{
982 int ret = 0; 982 int ret = 0;
983 983
984 mutex_lock(&dev->mutex);
984 vhost_dev_lock_vqs(dev); 985 vhost_dev_lock_vqs(dev);
985 switch (msg->type) { 986 switch (msg->type) {
986 case VHOST_IOTLB_UPDATE: 987 case VHOST_IOTLB_UPDATE:
@@ -1016,6 +1017,8 @@ static int vhost_process_iotlb_msg(struct vhost_dev *dev,
1016 } 1017 }
1017 1018
1018 vhost_dev_unlock_vqs(dev); 1019 vhost_dev_unlock_vqs(dev);
1020 mutex_unlock(&dev->mutex);
1021
1019 return ret; 1022 return ret;
1020} 1023}
1021ssize_t vhost_chr_write_iter(struct vhost_dev *dev, 1024ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index e1c60899fdbc..a6f9ba85dc4b 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -351,7 +351,7 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
351 * physical address */ 351 * physical address */
352 phys = xen_bus_to_phys(dev_addr); 352 phys = xen_bus_to_phys(dev_addr);
353 353
354 if (((dev_addr + size - 1 > dma_mask)) || 354 if (((dev_addr + size - 1 <= dma_mask)) ||
355 range_straddles_page_boundary(phys, size)) 355 range_straddles_page_boundary(phys, size))
356 xen_destroy_contiguous_region(phys, order); 356 xen_destroy_contiguous_region(phys, order);
357 357
diff --git a/fs/affs/namei.c b/fs/affs/namei.c
index d8aa0ae3d037..41c5749f4db7 100644
--- a/fs/affs/namei.c
+++ b/fs/affs/namei.c
@@ -201,14 +201,16 @@ affs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
201 struct super_block *sb = dir->i_sb; 201 struct super_block *sb = dir->i_sb;
202 struct buffer_head *bh; 202 struct buffer_head *bh;
203 struct inode *inode = NULL; 203 struct inode *inode = NULL;
204 struct dentry *res;
204 205
205 pr_debug("%s(\"%pd\")\n", __func__, dentry); 206 pr_debug("%s(\"%pd\")\n", __func__, dentry);
206 207
207 affs_lock_dir(dir); 208 affs_lock_dir(dir);
208 bh = affs_find_entry(dir, dentry); 209 bh = affs_find_entry(dir, dentry);
209 affs_unlock_dir(dir); 210 if (IS_ERR(bh)) {
210 if (IS_ERR(bh)) 211 affs_unlock_dir(dir);
211 return ERR_CAST(bh); 212 return ERR_CAST(bh);
213 }
212 if (bh) { 214 if (bh) {
213 u32 ino = bh->b_blocknr; 215 u32 ino = bh->b_blocknr;
214 216
@@ -222,11 +224,12 @@ affs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
222 } 224 }
223 affs_brelse(bh); 225 affs_brelse(bh);
224 inode = affs_iget(sb, ino); 226 inode = affs_iget(sb, ino);
225 if (IS_ERR(inode))
226 return ERR_CAST(inode);
227 } 227 }
228 d_add(dentry, inode); 228 res = d_splice_alias(inode, dentry);
229 return NULL; 229 if (!IS_ERR_OR_NULL(res))
230 res->d_fsdata = dentry->d_fsdata;
231 affs_unlock_dir(dir);
232 return res;
230} 233}
231 234
232int 235int
diff --git a/fs/aio.c b/fs/aio.c
index 88d7927ffbc6..8061d9787e54 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1078,8 +1078,8 @@ static struct kioctx *lookup_ioctx(unsigned long ctx_id)
1078 1078
1079 ctx = rcu_dereference(table->table[id]); 1079 ctx = rcu_dereference(table->table[id]);
1080 if (ctx && ctx->user_id == ctx_id) { 1080 if (ctx && ctx->user_id == ctx_id) {
1081 percpu_ref_get(&ctx->users); 1081 if (percpu_ref_tryget_live(&ctx->users))
1082 ret = ctx; 1082 ret = ctx;
1083 } 1083 }
1084out: 1084out:
1085 rcu_read_unlock(); 1085 rcu_read_unlock();
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index af2832aaeec5..4700b4534439 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -198,23 +198,16 @@ befs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
198 198
199 if (ret == BEFS_BT_NOT_FOUND) { 199 if (ret == BEFS_BT_NOT_FOUND) {
200 befs_debug(sb, "<--- %s %pd not found", __func__, dentry); 200 befs_debug(sb, "<--- %s %pd not found", __func__, dentry);
201 d_add(dentry, NULL); 201 inode = NULL;
202 return ERR_PTR(-ENOENT);
203
204 } else if (ret != BEFS_OK || offset == 0) { 202 } else if (ret != BEFS_OK || offset == 0) {
205 befs_error(sb, "<--- %s Error", __func__); 203 befs_error(sb, "<--- %s Error", __func__);
206 return ERR_PTR(-ENODATA); 204 inode = ERR_PTR(-ENODATA);
205 } else {
206 inode = befs_iget(dir->i_sb, (ino_t) offset);
207 } 207 }
208
209 inode = befs_iget(dir->i_sb, (ino_t) offset);
210 if (IS_ERR(inode))
211 return ERR_CAST(inode);
212
213 d_add(dentry, inode);
214
215 befs_debug(sb, "<--- %s", __func__); 208 befs_debug(sb, "<--- %s", __func__);
216 209
217 return NULL; 210 return d_splice_alias(inode, dentry);
218} 211}
219 212
220static int 213static int
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 8e604e7071f1..0b86cf10cf2a 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -6586,8 +6586,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
6586 goto out_unlock_inode; 6586 goto out_unlock_inode;
6587 } else { 6587 } else {
6588 btrfs_update_inode(trans, root, inode); 6588 btrfs_update_inode(trans, root, inode);
6589 unlock_new_inode(inode); 6589 d_instantiate_new(dentry, inode);
6590 d_instantiate(dentry, inode);
6591 } 6590 }
6592 6591
6593out_unlock: 6592out_unlock:
@@ -6663,8 +6662,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
6663 goto out_unlock_inode; 6662 goto out_unlock_inode;
6664 6663
6665 BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; 6664 BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
6666 unlock_new_inode(inode); 6665 d_instantiate_new(dentry, inode);
6667 d_instantiate(dentry, inode);
6668 6666
6669out_unlock: 6667out_unlock:
6670 btrfs_end_transaction(trans); 6668 btrfs_end_transaction(trans);
@@ -6809,12 +6807,7 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
6809 if (err) 6807 if (err)
6810 goto out_fail_inode; 6808 goto out_fail_inode;
6811 6809
6812 d_instantiate(dentry, inode); 6810 d_instantiate_new(dentry, inode);
6813 /*
6814 * mkdir is special. We're unlocking after we call d_instantiate
6815 * to avoid a race with nfsd calling d_instantiate.
6816 */
6817 unlock_new_inode(inode);
6818 drop_on_err = 0; 6811 drop_on_err = 0;
6819 6812
6820out_fail: 6813out_fail:
@@ -9124,7 +9117,8 @@ static int btrfs_truncate(struct inode *inode, bool skip_writeback)
9124 BTRFS_EXTENT_DATA_KEY); 9117 BTRFS_EXTENT_DATA_KEY);
9125 trans->block_rsv = &fs_info->trans_block_rsv; 9118 trans->block_rsv = &fs_info->trans_block_rsv;
9126 if (ret != -ENOSPC && ret != -EAGAIN) { 9119 if (ret != -ENOSPC && ret != -EAGAIN) {
9127 err = ret; 9120 if (ret < 0)
9121 err = ret;
9128 break; 9122 break;
9129 } 9123 }
9130 9124
@@ -10257,8 +10251,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
10257 goto out_unlock_inode; 10251 goto out_unlock_inode;
10258 } 10252 }
10259 10253
10260 unlock_new_inode(inode); 10254 d_instantiate_new(dentry, inode);
10261 d_instantiate(dentry, inode);
10262 10255
10263out_unlock: 10256out_unlock:
10264 btrfs_end_transaction(trans); 10257 btrfs_end_transaction(trans);
diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
index 0daa1e3fe0df..ab0bbe93b398 100644
--- a/fs/cachefiles/namei.c
+++ b/fs/cachefiles/namei.c
@@ -572,6 +572,11 @@ lookup_again:
572 if (ret < 0) 572 if (ret < 0)
573 goto create_error; 573 goto create_error;
574 574
575 if (unlikely(d_unhashed(next))) {
576 dput(next);
577 inode_unlock(d_inode(dir));
578 goto lookup_again;
579 }
575 ASSERT(d_backing_inode(next)); 580 ASSERT(d_backing_inode(next));
576 581
577 _debug("mkdir -> %p{%p{ino=%lu}}", 582 _debug("mkdir -> %p{%p{ino=%lu}}",
@@ -764,6 +769,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
764 /* search the current directory for the element name */ 769 /* search the current directory for the element name */
765 inode_lock(d_inode(dir)); 770 inode_lock(d_inode(dir));
766 771
772retry:
767 start = jiffies; 773 start = jiffies;
768 subdir = lookup_one_len(dirname, dir, strlen(dirname)); 774 subdir = lookup_one_len(dirname, dir, strlen(dirname));
769 cachefiles_hist(cachefiles_lookup_histogram, start); 775 cachefiles_hist(cachefiles_lookup_histogram, start);
@@ -793,6 +799,10 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
793 if (ret < 0) 799 if (ret < 0)
794 goto mkdir_error; 800 goto mkdir_error;
795 801
802 if (unlikely(d_unhashed(subdir))) {
803 dput(subdir);
804 goto retry;
805 }
796 ASSERT(d_backing_inode(subdir)); 806 ASSERT(d_backing_inode(subdir));
797 807
798 _debug("mkdir -> %p{%p{ino=%lu}}", 808 _debug("mkdir -> %p{%p{ino=%lu}}",
diff --git a/fs/cifs/Kconfig b/fs/cifs/Kconfig
index 5f132d59dfc2..d61e2de8d0eb 100644
--- a/fs/cifs/Kconfig
+++ b/fs/cifs/Kconfig
@@ -197,7 +197,7 @@ config CIFS_SMB311
197 197
198config CIFS_SMB_DIRECT 198config CIFS_SMB_DIRECT
199 bool "SMB Direct support (Experimental)" 199 bool "SMB Direct support (Experimental)"
200 depends on CIFS=m && INFINIBAND && INFINIBAND_ADDR_TRANS || CIFS=y && INFINIBAND=y && INFINIBAND_ADDR_TRANS=y 200 depends on CIFS=m && INFINIBAND_ADDR_TRANS || CIFS=y && INFINIBAND_ADDR_TRANS=y
201 help 201 help
202 Enables SMB Direct experimental support for SMB 3.0, 3.02 and 3.1.1. 202 Enables SMB Direct experimental support for SMB 3.0, 3.02 and 3.1.1.
203 SMB Direct allows transferring SMB packets over RDMA. If unsure, 203 SMB Direct allows transferring SMB packets over RDMA. If unsure,
diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c
index 017b0ab19bc4..124b093d14e5 100644
--- a/fs/cramfs/inode.c
+++ b/fs/cramfs/inode.c
@@ -492,7 +492,7 @@ static void cramfs_kill_sb(struct super_block *sb)
492{ 492{
493 struct cramfs_sb_info *sbi = CRAMFS_SB(sb); 493 struct cramfs_sb_info *sbi = CRAMFS_SB(sb);
494 494
495 if (IS_ENABLED(CCONFIG_CRAMFS_MTD) && sb->s_mtd) { 495 if (IS_ENABLED(CONFIG_CRAMFS_MTD) && sb->s_mtd) {
496 if (sbi && sbi->mtd_point_size) 496 if (sbi && sbi->mtd_point_size)
497 mtd_unpoint(sb->s_mtd, 0, sbi->mtd_point_size); 497 mtd_unpoint(sb->s_mtd, 0, sbi->mtd_point_size);
498 kill_mtd_super(sb); 498 kill_mtd_super(sb);
diff --git a/fs/dcache.c b/fs/dcache.c
index 86d2de63461e..2acfc69878f5 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1899,6 +1899,28 @@ void d_instantiate(struct dentry *entry, struct inode * inode)
1899} 1899}
1900EXPORT_SYMBOL(d_instantiate); 1900EXPORT_SYMBOL(d_instantiate);
1901 1901
1902/*
1903 * This should be equivalent to d_instantiate() + unlock_new_inode(),
1904 * with lockdep-related part of unlock_new_inode() done before
1905 * anything else. Use that instead of open-coding d_instantiate()/
1906 * unlock_new_inode() combinations.
1907 */
1908void d_instantiate_new(struct dentry *entry, struct inode *inode)
1909{
1910 BUG_ON(!hlist_unhashed(&entry->d_u.d_alias));
1911 BUG_ON(!inode);
1912 lockdep_annotate_inode_mutex_key(inode);
1913 security_d_instantiate(entry, inode);
1914 spin_lock(&inode->i_lock);
1915 __d_instantiate(entry, inode);
1916 WARN_ON(!(inode->i_state & I_NEW));
1917 inode->i_state &= ~I_NEW;
1918 smp_mb();
1919 wake_up_bit(&inode->i_state, __I_NEW);
1920 spin_unlock(&inode->i_lock);
1921}
1922EXPORT_SYMBOL(d_instantiate_new);
1923
1902/** 1924/**
1903 * d_instantiate_no_diralias - instantiate a non-aliased dentry 1925 * d_instantiate_no_diralias - instantiate a non-aliased dentry
1904 * @entry: dentry to complete 1926 * @entry: dentry to complete
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index 97d17eaeba07..49121e5a8de2 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -283,8 +283,7 @@ ecryptfs_create(struct inode *directory_inode, struct dentry *ecryptfs_dentry,
283 iget_failed(ecryptfs_inode); 283 iget_failed(ecryptfs_inode);
284 goto out; 284 goto out;
285 } 285 }
286 unlock_new_inode(ecryptfs_inode); 286 d_instantiate_new(ecryptfs_dentry, ecryptfs_inode);
287 d_instantiate(ecryptfs_dentry, ecryptfs_inode);
288out: 287out:
289 return rc; 288 return rc;
290} 289}
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index 1e01fabef130..71635909df3b 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -1264,21 +1264,11 @@ do_indirects:
1264 1264
1265static void ext2_truncate_blocks(struct inode *inode, loff_t offset) 1265static void ext2_truncate_blocks(struct inode *inode, loff_t offset)
1266{ 1266{
1267 /*
1268 * XXX: it seems like a bug here that we don't allow
1269 * IS_APPEND inode to have blocks-past-i_size trimmed off.
1270 * review and fix this.
1271 *
1272 * Also would be nice to be able to handle IO errors and such,
1273 * but that's probably too much to ask.
1274 */
1275 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || 1267 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
1276 S_ISLNK(inode->i_mode))) 1268 S_ISLNK(inode->i_mode)))
1277 return; 1269 return;
1278 if (ext2_inode_is_fast_symlink(inode)) 1270 if (ext2_inode_is_fast_symlink(inode))
1279 return; 1271 return;
1280 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
1281 return;
1282 1272
1283 dax_sem_down_write(EXT2_I(inode)); 1273 dax_sem_down_write(EXT2_I(inode));
1284 __ext2_truncate_blocks(inode, offset); 1274 __ext2_truncate_blocks(inode, offset);
diff --git a/fs/ext2/namei.c b/fs/ext2/namei.c
index 55f7caadb093..152453a91877 100644
--- a/fs/ext2/namei.c
+++ b/fs/ext2/namei.c
@@ -41,8 +41,7 @@ static inline int ext2_add_nondir(struct dentry *dentry, struct inode *inode)
41{ 41{
42 int err = ext2_add_link(dentry, inode); 42 int err = ext2_add_link(dentry, inode);
43 if (!err) { 43 if (!err) {
44 unlock_new_inode(inode); 44 d_instantiate_new(dentry, inode);
45 d_instantiate(dentry, inode);
46 return 0; 45 return 0;
47 } 46 }
48 inode_dec_link_count(inode); 47 inode_dec_link_count(inode);
@@ -255,8 +254,7 @@ static int ext2_mkdir(struct inode * dir, struct dentry * dentry, umode_t mode)
255 if (err) 254 if (err)
256 goto out_fail; 255 goto out_fail;
257 256
258 unlock_new_inode(inode); 257 d_instantiate_new(dentry, inode);
259 d_instantiate(dentry, inode);
260out: 258out:
261 return err; 259 return err;
262 260
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index b1f21e3a0763..4a09063ce1d2 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -2411,8 +2411,7 @@ static int ext4_add_nondir(handle_t *handle,
2411 int err = ext4_add_entry(handle, dentry, inode); 2411 int err = ext4_add_entry(handle, dentry, inode);
2412 if (!err) { 2412 if (!err) {
2413 ext4_mark_inode_dirty(handle, inode); 2413 ext4_mark_inode_dirty(handle, inode);
2414 unlock_new_inode(inode); 2414 d_instantiate_new(dentry, inode);
2415 d_instantiate(dentry, inode);
2416 return 0; 2415 return 0;
2417 } 2416 }
2418 drop_nlink(inode); 2417 drop_nlink(inode);
@@ -2651,8 +2650,7 @@ out_clear_inode:
2651 err = ext4_mark_inode_dirty(handle, dir); 2650 err = ext4_mark_inode_dirty(handle, dir);
2652 if (err) 2651 if (err)
2653 goto out_clear_inode; 2652 goto out_clear_inode;
2654 unlock_new_inode(inode); 2653 d_instantiate_new(dentry, inode);
2655 d_instantiate(dentry, inode);
2656 if (IS_DIRSYNC(dir)) 2654 if (IS_DIRSYNC(dir))
2657 ext4_handle_sync(handle); 2655 ext4_handle_sync(handle);
2658 2656
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index d5098efe577c..75e37fd720b2 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -294,8 +294,7 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
294 294
295 alloc_nid_done(sbi, ino); 295 alloc_nid_done(sbi, ino);
296 296
297 d_instantiate(dentry, inode); 297 d_instantiate_new(dentry, inode);
298 unlock_new_inode(inode);
299 298
300 if (IS_DIRSYNC(dir)) 299 if (IS_DIRSYNC(dir))
301 f2fs_sync_fs(sbi->sb, 1); 300 f2fs_sync_fs(sbi->sb, 1);
@@ -597,8 +596,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
597 err = page_symlink(inode, disk_link.name, disk_link.len); 596 err = page_symlink(inode, disk_link.name, disk_link.len);
598 597
599err_out: 598err_out:
600 d_instantiate(dentry, inode); 599 d_instantiate_new(dentry, inode);
601 unlock_new_inode(inode);
602 600
603 /* 601 /*
604 * Let's flush symlink data in order to avoid broken symlink as much as 602 * Let's flush symlink data in order to avoid broken symlink as much as
@@ -661,8 +659,7 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
661 659
662 alloc_nid_done(sbi, inode->i_ino); 660 alloc_nid_done(sbi, inode->i_ino);
663 661
664 d_instantiate(dentry, inode); 662 d_instantiate_new(dentry, inode);
665 unlock_new_inode(inode);
666 663
667 if (IS_DIRSYNC(dir)) 664 if (IS_DIRSYNC(dir))
668 f2fs_sync_fs(sbi->sb, 1); 665 f2fs_sync_fs(sbi->sb, 1);
@@ -713,8 +710,7 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
713 710
714 alloc_nid_done(sbi, inode->i_ino); 711 alloc_nid_done(sbi, inode->i_ino);
715 712
716 d_instantiate(dentry, inode); 713 d_instantiate_new(dentry, inode);
717 unlock_new_inode(inode);
718 714
719 if (IS_DIRSYNC(dir)) 715 if (IS_DIRSYNC(dir))
720 f2fs_sync_fs(sbi->sb, 1); 716 f2fs_sync_fs(sbi->sb, 1);
diff --git a/fs/jffs2/dir.c b/fs/jffs2/dir.c
index 0a754f38462e..e5a6deb38e1e 100644
--- a/fs/jffs2/dir.c
+++ b/fs/jffs2/dir.c
@@ -209,8 +209,7 @@ static int jffs2_create(struct inode *dir_i, struct dentry *dentry,
209 __func__, inode->i_ino, inode->i_mode, inode->i_nlink, 209 __func__, inode->i_ino, inode->i_mode, inode->i_nlink,
210 f->inocache->pino_nlink, inode->i_mapping->nrpages); 210 f->inocache->pino_nlink, inode->i_mapping->nrpages);
211 211
212 unlock_new_inode(inode); 212 d_instantiate_new(dentry, inode);
213 d_instantiate(dentry, inode);
214 return 0; 213 return 0;
215 214
216 fail: 215 fail:
@@ -430,8 +429,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
430 mutex_unlock(&dir_f->sem); 429 mutex_unlock(&dir_f->sem);
431 jffs2_complete_reservation(c); 430 jffs2_complete_reservation(c);
432 431
433 unlock_new_inode(inode); 432 d_instantiate_new(dentry, inode);
434 d_instantiate(dentry, inode);
435 return 0; 433 return 0;
436 434
437 fail: 435 fail:
@@ -575,8 +573,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, umode_t mode
575 mutex_unlock(&dir_f->sem); 573 mutex_unlock(&dir_f->sem);
576 jffs2_complete_reservation(c); 574 jffs2_complete_reservation(c);
577 575
578 unlock_new_inode(inode); 576 d_instantiate_new(dentry, inode);
579 d_instantiate(dentry, inode);
580 return 0; 577 return 0;
581 578
582 fail: 579 fail:
@@ -747,8 +744,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, umode_t mode
747 mutex_unlock(&dir_f->sem); 744 mutex_unlock(&dir_f->sem);
748 jffs2_complete_reservation(c); 745 jffs2_complete_reservation(c);
749 746
750 unlock_new_inode(inode); 747 d_instantiate_new(dentry, inode);
751 d_instantiate(dentry, inode);
752 return 0; 748 return 0;
753 749
754 fail: 750 fail:
diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c
index b41596d71858..56c3fcbfe80e 100644
--- a/fs/jfs/namei.c
+++ b/fs/jfs/namei.c
@@ -178,8 +178,7 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, umode_t mode,
178 unlock_new_inode(ip); 178 unlock_new_inode(ip);
179 iput(ip); 179 iput(ip);
180 } else { 180 } else {
181 unlock_new_inode(ip); 181 d_instantiate_new(dentry, ip);
182 d_instantiate(dentry, ip);
183 } 182 }
184 183
185 out2: 184 out2:
@@ -313,8 +312,7 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, umode_t mode)
313 unlock_new_inode(ip); 312 unlock_new_inode(ip);
314 iput(ip); 313 iput(ip);
315 } else { 314 } else {
316 unlock_new_inode(ip); 315 d_instantiate_new(dentry, ip);
317 d_instantiate(dentry, ip);
318 } 316 }
319 317
320 out2: 318 out2:
@@ -1059,8 +1057,7 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
1059 unlock_new_inode(ip); 1057 unlock_new_inode(ip);
1060 iput(ip); 1058 iput(ip);
1061 } else { 1059 } else {
1062 unlock_new_inode(ip); 1060 d_instantiate_new(dentry, ip);
1063 d_instantiate(dentry, ip);
1064 } 1061 }
1065 1062
1066 out2: 1063 out2:
@@ -1447,8 +1444,7 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
1447 unlock_new_inode(ip); 1444 unlock_new_inode(ip);
1448 iput(ip); 1445 iput(ip);
1449 } else { 1446 } else {
1450 unlock_new_inode(ip); 1447 d_instantiate_new(dentry, ip);
1451 d_instantiate(dentry, ip);
1452 } 1448 }
1453 1449
1454 out1: 1450 out1:
diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c
index 26dd9a50f383..ff2716f9322e 100644
--- a/fs/kernfs/mount.c
+++ b/fs/kernfs/mount.c
@@ -316,6 +316,7 @@ struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags,
316 316
317 info->root = root; 317 info->root = root;
318 info->ns = ns; 318 info->ns = ns;
319 INIT_LIST_HEAD(&info->node);
319 320
320 sb = sget_userns(fs_type, kernfs_test_super, kernfs_set_super, flags, 321 sb = sget_userns(fs_type, kernfs_test_super, kernfs_set_super, flags,
321 &init_user_ns, info); 322 &init_user_ns, info);
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 2410b093a2e6..b0555d7d8200 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -1201,6 +1201,28 @@ nfsd_create_locked(struct svc_rqst *rqstp, struct svc_fh *fhp,
1201 break; 1201 break;
1202 case S_IFDIR: 1202 case S_IFDIR:
1203 host_err = vfs_mkdir(dirp, dchild, iap->ia_mode); 1203 host_err = vfs_mkdir(dirp, dchild, iap->ia_mode);
1204 if (!host_err && unlikely(d_unhashed(dchild))) {
1205 struct dentry *d;
1206 d = lookup_one_len(dchild->d_name.name,
1207 dchild->d_parent,
1208 dchild->d_name.len);
1209 if (IS_ERR(d)) {
1210 host_err = PTR_ERR(d);
1211 break;
1212 }
1213 if (unlikely(d_is_negative(d))) {
1214 dput(d);
1215 err = nfserr_serverfault;
1216 goto out;
1217 }
1218 dput(resfhp->fh_dentry);
1219 resfhp->fh_dentry = dget(d);
1220 err = fh_update(resfhp);
1221 dput(dchild);
1222 dchild = d;
1223 if (err)
1224 goto out;
1225 }
1204 break; 1226 break;
1205 case S_IFCHR: 1227 case S_IFCHR:
1206 case S_IFBLK: 1228 case S_IFBLK:
diff --git a/fs/nilfs2/namei.c b/fs/nilfs2/namei.c
index 1a2894aa0194..dd52d3f82e8d 100644
--- a/fs/nilfs2/namei.c
+++ b/fs/nilfs2/namei.c
@@ -46,8 +46,7 @@ static inline int nilfs_add_nondir(struct dentry *dentry, struct inode *inode)
46 int err = nilfs_add_link(dentry, inode); 46 int err = nilfs_add_link(dentry, inode);
47 47
48 if (!err) { 48 if (!err) {
49 d_instantiate(dentry, inode); 49 d_instantiate_new(dentry, inode);
50 unlock_new_inode(inode);
51 return 0; 50 return 0;
52 } 51 }
53 inode_dec_link_count(inode); 52 inode_dec_link_count(inode);
@@ -243,8 +242,7 @@ static int nilfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
243 goto out_fail; 242 goto out_fail;
244 243
245 nilfs_mark_inode_dirty(inode); 244 nilfs_mark_inode_dirty(inode);
246 d_instantiate(dentry, inode); 245 d_instantiate_new(dentry, inode);
247 unlock_new_inode(inode);
248out: 246out:
249 if (!err) 247 if (!err)
250 err = nilfs_transaction_commit(dir->i_sb); 248 err = nilfs_transaction_commit(dir->i_sb);
diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 91a8889abf9b..ea8c551bcd7e 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -570,16 +570,7 @@ static struct bio *o2hb_setup_one_bio(struct o2hb_region *reg,
570 current_page, vec_len, vec_start); 570 current_page, vec_len, vec_start);
571 571
572 len = bio_add_page(bio, page, vec_len, vec_start); 572 len = bio_add_page(bio, page, vec_len, vec_start);
573 if (len != vec_len) { 573 if (len != vec_len) break;
574 mlog(ML_ERROR, "Adding page[%d] to bio failed, "
575 "page %p, len %d, vec_len %u, vec_start %u, "
576 "bi_sector %llu\n", current_page, page, len,
577 vec_len, vec_start,
578 (unsigned long long)bio->bi_iter.bi_sector);
579 bio_put(bio);
580 bio = ERR_PTR(-EIO);
581 return bio;
582 }
583 574
584 cs += vec_len / (PAGE_SIZE/spp); 575 cs += vec_len / (PAGE_SIZE/spp);
585 vec_start = 0; 576 vec_start = 0;
diff --git a/fs/orangefs/namei.c b/fs/orangefs/namei.c
index 6e3134e6d98a..1b5707c44c3f 100644
--- a/fs/orangefs/namei.c
+++ b/fs/orangefs/namei.c
@@ -75,8 +75,7 @@ static int orangefs_create(struct inode *dir,
75 get_khandle_from_ino(inode), 75 get_khandle_from_ino(inode),
76 dentry); 76 dentry);
77 77
78 d_instantiate(dentry, inode); 78 d_instantiate_new(dentry, inode);
79 unlock_new_inode(inode);
80 orangefs_set_timeout(dentry); 79 orangefs_set_timeout(dentry);
81 ORANGEFS_I(inode)->getattr_time = jiffies - 1; 80 ORANGEFS_I(inode)->getattr_time = jiffies - 1;
82 ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; 81 ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS;
@@ -332,8 +331,7 @@ static int orangefs_symlink(struct inode *dir,
332 "Assigned symlink inode new number of %pU\n", 331 "Assigned symlink inode new number of %pU\n",
333 get_khandle_from_ino(inode)); 332 get_khandle_from_ino(inode));
334 333
335 d_instantiate(dentry, inode); 334 d_instantiate_new(dentry, inode);
336 unlock_new_inode(inode);
337 orangefs_set_timeout(dentry); 335 orangefs_set_timeout(dentry);
338 ORANGEFS_I(inode)->getattr_time = jiffies - 1; 336 ORANGEFS_I(inode)->getattr_time = jiffies - 1;
339 ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; 337 ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS;
@@ -402,8 +400,7 @@ static int orangefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode
402 "Assigned dir inode new number of %pU\n", 400 "Assigned dir inode new number of %pU\n",
403 get_khandle_from_ino(inode)); 401 get_khandle_from_ino(inode));
404 402
405 d_instantiate(dentry, inode); 403 d_instantiate_new(dentry, inode);
406 unlock_new_inode(inode);
407 orangefs_set_timeout(dentry); 404 orangefs_set_timeout(dentry);
408 ORANGEFS_I(inode)->getattr_time = jiffies - 1; 405 ORANGEFS_I(inode)->getattr_time = jiffies - 1;
409 ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; 406 ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS;
diff --git a/fs/proc/array.c b/fs/proc/array.c
index ae2c807fd719..72391b3f6927 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -85,6 +85,7 @@
85#include <linux/delayacct.h> 85#include <linux/delayacct.h>
86#include <linux/seq_file.h> 86#include <linux/seq_file.h>
87#include <linux/pid_namespace.h> 87#include <linux/pid_namespace.h>
88#include <linux/prctl.h>
88#include <linux/ptrace.h> 89#include <linux/ptrace.h>
89#include <linux/tracehook.h> 90#include <linux/tracehook.h>
90#include <linux/string_helpers.h> 91#include <linux/string_helpers.h>
@@ -335,6 +336,30 @@ static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
335#ifdef CONFIG_SECCOMP 336#ifdef CONFIG_SECCOMP
336 seq_put_decimal_ull(m, "\nSeccomp:\t", p->seccomp.mode); 337 seq_put_decimal_ull(m, "\nSeccomp:\t", p->seccomp.mode);
337#endif 338#endif
339 seq_printf(m, "\nSpeculation_Store_Bypass:\t");
340 switch (arch_prctl_spec_ctrl_get(p, PR_SPEC_STORE_BYPASS)) {
341 case -EINVAL:
342 seq_printf(m, "unknown");
343 break;
344 case PR_SPEC_NOT_AFFECTED:
345 seq_printf(m, "not vulnerable");
346 break;
347 case PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE:
348 seq_printf(m, "thread force mitigated");
349 break;
350 case PR_SPEC_PRCTL | PR_SPEC_DISABLE:
351 seq_printf(m, "thread mitigated");
352 break;
353 case PR_SPEC_PRCTL | PR_SPEC_ENABLE:
354 seq_printf(m, "thread vulnerable");
355 break;
356 case PR_SPEC_DISABLE:
357 seq_printf(m, "globally mitigated");
358 break;
359 default:
360 seq_printf(m, "vulnerable");
361 break;
362 }
338 seq_putc(m, '\n'); 363 seq_putc(m, '\n');
339} 364}
340 365
diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
index bd39a998843d..5089dac02660 100644
--- a/fs/reiserfs/namei.c
+++ b/fs/reiserfs/namei.c
@@ -687,8 +687,7 @@ static int reiserfs_create(struct inode *dir, struct dentry *dentry, umode_t mod
687 reiserfs_update_inode_transaction(inode); 687 reiserfs_update_inode_transaction(inode);
688 reiserfs_update_inode_transaction(dir); 688 reiserfs_update_inode_transaction(dir);
689 689
690 unlock_new_inode(inode); 690 d_instantiate_new(dentry, inode);
691 d_instantiate(dentry, inode);
692 retval = journal_end(&th); 691 retval = journal_end(&th);
693 692
694out_failed: 693out_failed:
@@ -771,8 +770,7 @@ static int reiserfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode
771 goto out_failed; 770 goto out_failed;
772 } 771 }
773 772
774 unlock_new_inode(inode); 773 d_instantiate_new(dentry, inode);
775 d_instantiate(dentry, inode);
776 retval = journal_end(&th); 774 retval = journal_end(&th);
777 775
778out_failed: 776out_failed:
@@ -871,8 +869,7 @@ static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode
871 /* the above add_entry did not update dir's stat data */ 869 /* the above add_entry did not update dir's stat data */
872 reiserfs_update_sd(&th, dir); 870 reiserfs_update_sd(&th, dir);
873 871
874 unlock_new_inode(inode); 872 d_instantiate_new(dentry, inode);
875 d_instantiate(dentry, inode);
876 retval = journal_end(&th); 873 retval = journal_end(&th);
877out_failed: 874out_failed:
878 reiserfs_write_unlock(dir->i_sb); 875 reiserfs_write_unlock(dir->i_sb);
@@ -1187,8 +1184,7 @@ static int reiserfs_symlink(struct inode *parent_dir,
1187 goto out_failed; 1184 goto out_failed;
1188 } 1185 }
1189 1186
1190 unlock_new_inode(inode); 1187 d_instantiate_new(dentry, inode);
1191 d_instantiate(dentry, inode);
1192 retval = journal_end(&th); 1188 retval = journal_end(&th);
1193out_failed: 1189out_failed:
1194 reiserfs_write_unlock(parent_dir->i_sb); 1190 reiserfs_write_unlock(parent_dir->i_sb);
diff --git a/fs/seq_file.c b/fs/seq_file.c
index c6c27f1f9c98..4cc090b50cc5 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -709,11 +709,6 @@ void seq_put_decimal_ull_width(struct seq_file *m, const char *delimiter,
709 if (m->count + width >= m->size) 709 if (m->count + width >= m->size)
710 goto overflow; 710 goto overflow;
711 711
712 if (num < 10) {
713 m->buf[m->count++] = num + '0';
714 return;
715 }
716
717 len = num_to_str(m->buf + m->count, m->size - m->count, num, width); 712 len = num_to_str(m->buf + m->count, m->size - m->count, num, width);
718 if (!len) 713 if (!len)
719 goto overflow; 714 goto overflow;
diff --git a/fs/super.c b/fs/super.c
index 122c402049a2..4b5b562176d0 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -121,13 +121,23 @@ static unsigned long super_cache_count(struct shrinker *shrink,
121 sb = container_of(shrink, struct super_block, s_shrink); 121 sb = container_of(shrink, struct super_block, s_shrink);
122 122
123 /* 123 /*
124 * Don't call trylock_super as it is a potential 124 * We don't call trylock_super() here as it is a scalability bottleneck,
125 * scalability bottleneck. The counts could get updated 125 * so we're exposed to partial setup state. The shrinker rwsem does not
126 * between super_cache_count and super_cache_scan anyway. 126 * protect filesystem operations backing list_lru_shrink_count() or
127 * Call to super_cache_count with shrinker_rwsem held 127 * s_op->nr_cached_objects(). Counts can change between
128 * ensures the safety of call to list_lru_shrink_count() and 128 * super_cache_count and super_cache_scan, so we really don't need locks
129 * s_op->nr_cached_objects(). 129 * here.
130 *
131 * However, if we are currently mounting the superblock, the underlying
132 * filesystem might be in a state of partial construction and hence it
133 * is dangerous to access it. trylock_super() uses a SB_BORN check to
134 * avoid this situation, so do the same here. The memory barrier is
135 * matched with the one in mount_fs() as we don't hold locks here.
130 */ 136 */
137 if (!(sb->s_flags & SB_BORN))
138 return 0;
139 smp_rmb();
140
131 if (sb->s_op && sb->s_op->nr_cached_objects) 141 if (sb->s_op && sb->s_op->nr_cached_objects)
132 total_objects = sb->s_op->nr_cached_objects(sb, sc); 142 total_objects = sb->s_op->nr_cached_objects(sb, sc);
133 143
@@ -1272,6 +1282,14 @@ mount_fs(struct file_system_type *type, int flags, const char *name, void *data)
1272 sb = root->d_sb; 1282 sb = root->d_sb;
1273 BUG_ON(!sb); 1283 BUG_ON(!sb);
1274 WARN_ON(!sb->s_bdi); 1284 WARN_ON(!sb->s_bdi);
1285
1286 /*
1287 * Write barrier is for super_cache_count(). We place it before setting
1288 * SB_BORN as the data dependency between the two functions is the
1289 * superblock structure contents that we just set up, not the SB_BORN
1290 * flag.
1291 */
1292 smp_wmb();
1275 sb->s_flags |= SB_BORN; 1293 sb->s_flags |= SB_BORN;
1276 1294
1277 error = security_sb_kern_mount(sb, flags, secdata); 1295 error = security_sb_kern_mount(sb, flags, secdata);
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index b428d317ae92..92682fcc41f6 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -25,7 +25,7 @@ static struct dentry *sysfs_mount(struct file_system_type *fs_type,
25{ 25{
26 struct dentry *root; 26 struct dentry *root;
27 void *ns; 27 void *ns;
28 bool new_sb; 28 bool new_sb = false;
29 29
30 if (!(flags & SB_KERNMOUNT)) { 30 if (!(flags & SB_KERNMOUNT)) {
31 if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET)) 31 if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET))
@@ -35,9 +35,9 @@ static struct dentry *sysfs_mount(struct file_system_type *fs_type,
35 ns = kobj_ns_grab_current(KOBJ_NS_TYPE_NET); 35 ns = kobj_ns_grab_current(KOBJ_NS_TYPE_NET);
36 root = kernfs_mount_ns(fs_type, flags, sysfs_root, 36 root = kernfs_mount_ns(fs_type, flags, sysfs_root,
37 SYSFS_MAGIC, &new_sb, ns); 37 SYSFS_MAGIC, &new_sb, ns);
38 if (IS_ERR(root) || !new_sb) 38 if (!new_sb)
39 kobj_ns_drop(KOBJ_NS_TYPE_NET, ns); 39 kobj_ns_drop(KOBJ_NS_TYPE_NET, ns);
40 else if (new_sb) 40 else if (!IS_ERR(root))
41 root->d_sb->s_iflags |= SB_I_USERNS_VISIBLE; 41 root->d_sb->s_iflags |= SB_I_USERNS_VISIBLE;
42 42
43 return root; 43 return root;
diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index 0458dd47e105..c586026508db 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -622,8 +622,7 @@ static int udf_add_nondir(struct dentry *dentry, struct inode *inode)
622 if (fibh.sbh != fibh.ebh) 622 if (fibh.sbh != fibh.ebh)
623 brelse(fibh.ebh); 623 brelse(fibh.ebh);
624 brelse(fibh.sbh); 624 brelse(fibh.sbh);
625 unlock_new_inode(inode); 625 d_instantiate_new(dentry, inode);
626 d_instantiate(dentry, inode);
627 626
628 return 0; 627 return 0;
629} 628}
@@ -733,8 +732,7 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
733 inc_nlink(dir); 732 inc_nlink(dir);
734 dir->i_ctime = dir->i_mtime = current_time(dir); 733 dir->i_ctime = dir->i_mtime = current_time(dir);
735 mark_inode_dirty(dir); 734 mark_inode_dirty(dir);
736 unlock_new_inode(inode); 735 d_instantiate_new(dentry, inode);
737 d_instantiate(dentry, inode);
738 if (fibh.sbh != fibh.ebh) 736 if (fibh.sbh != fibh.ebh)
739 brelse(fibh.ebh); 737 brelse(fibh.ebh);
740 brelse(fibh.sbh); 738 brelse(fibh.sbh);
diff --git a/fs/ufs/namei.c b/fs/ufs/namei.c
index 32545cd00ceb..d5f43ba76c59 100644
--- a/fs/ufs/namei.c
+++ b/fs/ufs/namei.c
@@ -39,8 +39,7 @@ static inline int ufs_add_nondir(struct dentry *dentry, struct inode *inode)
39{ 39{
40 int err = ufs_add_link(dentry, inode); 40 int err = ufs_add_link(dentry, inode);
41 if (!err) { 41 if (!err) {
42 unlock_new_inode(inode); 42 d_instantiate_new(dentry, inode);
43 d_instantiate(dentry, inode);
44 return 0; 43 return 0;
45 } 44 }
46 inode_dec_link_count(inode); 45 inode_dec_link_count(inode);
@@ -193,8 +192,7 @@ static int ufs_mkdir(struct inode * dir, struct dentry * dentry, umode_t mode)
193 if (err) 192 if (err)
194 goto out_fail; 193 goto out_fail;
195 194
196 unlock_new_inode(inode); 195 d_instantiate_new(dentry, inode);
197 d_instantiate(dentry, inode);
198 return 0; 196 return 0;
199 197
200out_fail: 198out_fail:
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index 7e61c395fddf..df36b1b08af0 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -142,10 +142,11 @@ struct bpf_verifier_state_list {
142struct bpf_insn_aux_data { 142struct bpf_insn_aux_data {
143 union { 143 union {
144 enum bpf_reg_type ptr_type; /* pointer type for load/store insns */ 144 enum bpf_reg_type ptr_type; /* pointer type for load/store insns */
145 struct bpf_map *map_ptr; /* pointer for call insn into lookup_elem */ 145 unsigned long map_state; /* pointer/poison value for maps */
146 s32 call_imm; /* saved imm field of call insn */ 146 s32 call_imm; /* saved imm field of call insn */
147 }; 147 };
148 int ctx_field_size; /* the ctx field size for load insn, maybe 0 */ 148 int ctx_field_size; /* the ctx field size for load insn, maybe 0 */
149 int sanitize_stack_off; /* stack slot to be cleared */
149 bool seen; /* this insn was processed by the verifier */ 150 bool seen; /* this insn was processed by the verifier */
150}; 151};
151 152
diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index 7b01bc11c692..a97a63eef59f 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -53,6 +53,8 @@ extern ssize_t cpu_show_spectre_v1(struct device *dev,
53 struct device_attribute *attr, char *buf); 53 struct device_attribute *attr, char *buf);
54extern ssize_t cpu_show_spectre_v2(struct device *dev, 54extern ssize_t cpu_show_spectre_v2(struct device *dev,
55 struct device_attribute *attr, char *buf); 55 struct device_attribute *attr, char *buf);
56extern ssize_t cpu_show_spec_store_bypass(struct device *dev,
57 struct device_attribute *attr, char *buf);
56 58
57extern __printf(4, 5) 59extern __printf(4, 5)
58struct device *cpu_device_create(struct device *parent, void *drvdata, 60struct device *cpu_device_create(struct device *parent, void *drvdata,
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index 94acbde17bb1..66c6e17e61e5 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -224,6 +224,7 @@ extern seqlock_t rename_lock;
224 * These are the low-level FS interfaces to the dcache.. 224 * These are the low-level FS interfaces to the dcache..
225 */ 225 */
226extern void d_instantiate(struct dentry *, struct inode *); 226extern void d_instantiate(struct dentry *, struct inode *);
227extern void d_instantiate_new(struct dentry *, struct inode *);
227extern struct dentry * d_instantiate_unique(struct dentry *, struct inode *); 228extern struct dentry * d_instantiate_unique(struct dentry *, struct inode *);
228extern struct dentry * d_instantiate_anon(struct dentry *, struct inode *); 229extern struct dentry * d_instantiate_anon(struct dentry *, struct inode *);
229extern int d_instantiate_no_diralias(struct dentry *, struct inode *); 230extern int d_instantiate_no_diralias(struct dentry *, struct inode *);
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 1a4582b44d32..fc5ab85278d5 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -464,7 +464,7 @@ static inline struct page *
464__alloc_pages_node(int nid, gfp_t gfp_mask, unsigned int order) 464__alloc_pages_node(int nid, gfp_t gfp_mask, unsigned int order)
465{ 465{
466 VM_BUG_ON(nid < 0 || nid >= MAX_NUMNODES); 466 VM_BUG_ON(nid < 0 || nid >= MAX_NUMNODES);
467 VM_WARN_ON(!node_online(nid)); 467 VM_WARN_ON((gfp_mask & __GFP_THISNODE) && !node_online(nid));
468 468
469 return __alloc_pages(gfp_mask, order, nid); 469 return __alloc_pages(gfp_mask, order, nid);
470} 470}
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index e0e49b5b1ee1..2b0265265c28 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -216,6 +216,9 @@ void put_online_mems(void);
216void mem_hotplug_begin(void); 216void mem_hotplug_begin(void);
217void mem_hotplug_done(void); 217void mem_hotplug_done(void);
218 218
219extern void set_zone_contiguous(struct zone *zone);
220extern void clear_zone_contiguous(struct zone *zone);
221
219#else /* ! CONFIG_MEMORY_HOTPLUG */ 222#else /* ! CONFIG_MEMORY_HOTPLUG */
220#define pfn_to_online_page(pfn) \ 223#define pfn_to_online_page(pfn) \
221({ \ 224({ \
diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h
index 2a156c5dfadd..d703774982ca 100644
--- a/include/linux/mlx5/driver.h
+++ b/include/linux/mlx5/driver.h
@@ -1286,17 +1286,7 @@ enum {
1286static inline const struct cpumask * 1286static inline const struct cpumask *
1287mlx5_get_vector_affinity_hint(struct mlx5_core_dev *dev, int vector) 1287mlx5_get_vector_affinity_hint(struct mlx5_core_dev *dev, int vector)
1288{ 1288{
1289 struct irq_desc *desc; 1289 return dev->priv.irq_info[vector].mask;
1290 unsigned int irq;
1291 int eqn;
1292 int err;
1293
1294 err = mlx5_vector2eqn(dev, vector, &eqn, &irq);
1295 if (err)
1296 return NULL;
1297
1298 desc = irq_to_desc(irq);
1299 return desc->affinity_hint;
1300} 1290}
1301 1291
1302#endif /* MLX5_DRIVER_H */ 1292#endif /* MLX5_DRIVER_H */
diff --git a/include/linux/mm.h b/include/linux/mm.h
index c6fa9a255dbf..02a616e2f17d 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2109,7 +2109,6 @@ extern void setup_per_cpu_pageset(void);
2109 2109
2110extern void zone_pcp_update(struct zone *zone); 2110extern void zone_pcp_update(struct zone *zone);
2111extern void zone_pcp_reset(struct zone *zone); 2111extern void zone_pcp_reset(struct zone *zone);
2112extern void setup_zone_pageset(struct zone *zone);
2113 2112
2114/* page_alloc.c */ 2113/* page_alloc.c */
2115extern int min_free_kbytes; 2114extern int min_free_kbytes;
diff --git a/include/linux/node.h b/include/linux/node.h
index 41f171861dcc..6d336e38d155 100644
--- a/include/linux/node.h
+++ b/include/linux/node.h
@@ -32,9 +32,11 @@ extern struct node *node_devices[];
32typedef void (*node_registration_func_t)(struct node *); 32typedef void (*node_registration_func_t)(struct node *);
33 33
34#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA) 34#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
35extern int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages); 35extern int link_mem_sections(int nid, unsigned long start_pfn,
36 unsigned long nr_pages, bool check_nid);
36#else 37#else
37static inline int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages) 38static inline int link_mem_sections(int nid, unsigned long start_pfn,
39 unsigned long nr_pages, bool check_nid)
38{ 40{
39 return 0; 41 return 0;
40} 42}
@@ -57,7 +59,7 @@ static inline int register_one_node(int nid)
57 if (error) 59 if (error)
58 return error; 60 return error;
59 /* link memory sections under this node */ 61 /* link memory sections under this node */
60 error = link_mem_sections(nid, pgdat->node_start_pfn, pgdat->node_spanned_pages); 62 error = link_mem_sections(nid, pgdat->node_start_pfn, pgdat->node_spanned_pages, true);
61 } 63 }
62 64
63 return error; 65 return error;
diff --git a/include/linux/nospec.h b/include/linux/nospec.h
index e791ebc65c9c..0c5ef54fd416 100644
--- a/include/linux/nospec.h
+++ b/include/linux/nospec.h
@@ -7,6 +7,8 @@
7#define _LINUX_NOSPEC_H 7#define _LINUX_NOSPEC_H
8#include <asm/barrier.h> 8#include <asm/barrier.h>
9 9
10struct task_struct;
11
10/** 12/**
11 * array_index_mask_nospec() - generate a ~0 mask when index < size, 0 otherwise 13 * array_index_mask_nospec() - generate a ~0 mask when index < size, 0 otherwise
12 * @index: array element index 14 * @index: array element index
@@ -55,4 +57,12 @@ static inline unsigned long array_index_mask_nospec(unsigned long index,
55 \ 57 \
56 (typeof(_i)) (_i & _mask); \ 58 (typeof(_i)) (_i & _mask); \
57}) 59})
60
61/* Speculation control prctl */
62int arch_prctl_spec_ctrl_get(struct task_struct *task, unsigned long which);
63int arch_prctl_spec_ctrl_set(struct task_struct *task, unsigned long which,
64 unsigned long ctrl);
65/* Speculation control for seccomp enforced mitigation */
66void arch_seccomp_spec_mitigate(struct task_struct *task);
67
58#endif /* _LINUX_NOSPEC_H */ 68#endif /* _LINUX_NOSPEC_H */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index c2413703f45d..ca3f3eae8980 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1433,7 +1433,8 @@ static inline bool is_percpu_thread(void)
1433#define PFA_NO_NEW_PRIVS 0 /* May not gain new privileges. */ 1433#define PFA_NO_NEW_PRIVS 0 /* May not gain new privileges. */
1434#define PFA_SPREAD_PAGE 1 /* Spread page cache over cpuset */ 1434#define PFA_SPREAD_PAGE 1 /* Spread page cache over cpuset */
1435#define PFA_SPREAD_SLAB 2 /* Spread some slab caches over cpuset */ 1435#define PFA_SPREAD_SLAB 2 /* Spread some slab caches over cpuset */
1436 1436#define PFA_SPEC_SSB_DISABLE 3 /* Speculative Store Bypass disabled */
1437#define PFA_SPEC_SSB_FORCE_DISABLE 4 /* Speculative Store Bypass force disabled*/
1437 1438
1438#define TASK_PFA_TEST(name, func) \ 1439#define TASK_PFA_TEST(name, func) \
1439 static inline bool task_##func(struct task_struct *p) \ 1440 static inline bool task_##func(struct task_struct *p) \
@@ -1458,6 +1459,13 @@ TASK_PFA_TEST(SPREAD_SLAB, spread_slab)
1458TASK_PFA_SET(SPREAD_SLAB, spread_slab) 1459TASK_PFA_SET(SPREAD_SLAB, spread_slab)
1459TASK_PFA_CLEAR(SPREAD_SLAB, spread_slab) 1460TASK_PFA_CLEAR(SPREAD_SLAB, spread_slab)
1460 1461
1462TASK_PFA_TEST(SPEC_SSB_DISABLE, spec_ssb_disable)
1463TASK_PFA_SET(SPEC_SSB_DISABLE, spec_ssb_disable)
1464TASK_PFA_CLEAR(SPEC_SSB_DISABLE, spec_ssb_disable)
1465
1466TASK_PFA_TEST(SPEC_SSB_FORCE_DISABLE, spec_ssb_force_disable)
1467TASK_PFA_SET(SPEC_SSB_FORCE_DISABLE, spec_ssb_force_disable)
1468
1461static inline void 1469static inline void
1462current_restore_flags(unsigned long orig_flags, unsigned long flags) 1470current_restore_flags(unsigned long orig_flags, unsigned long flags)
1463{ 1471{
diff --git a/include/linux/seccomp.h b/include/linux/seccomp.h
index c723a5c4e3ff..e5320f6c8654 100644
--- a/include/linux/seccomp.h
+++ b/include/linux/seccomp.h
@@ -4,8 +4,9 @@
4 4
5#include <uapi/linux/seccomp.h> 5#include <uapi/linux/seccomp.h>
6 6
7#define SECCOMP_FILTER_FLAG_MASK (SECCOMP_FILTER_FLAG_TSYNC | \ 7#define SECCOMP_FILTER_FLAG_MASK (SECCOMP_FILTER_FLAG_TSYNC | \
8 SECCOMP_FILTER_FLAG_LOG) 8 SECCOMP_FILTER_FLAG_LOG | \
9 SECCOMP_FILTER_FLAG_SPEC_ALLOW)
9 10
10#ifdef CONFIG_SECCOMP 11#ifdef CONFIG_SECCOMP
11 12
diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
index cd368d1b8cb8..a1e28dd5d0bf 100644
--- a/include/net/netfilter/nf_tables.h
+++ b/include/net/netfilter/nf_tables.h
@@ -170,6 +170,7 @@ struct nft_data_desc {
170int nft_data_init(const struct nft_ctx *ctx, 170int nft_data_init(const struct nft_ctx *ctx,
171 struct nft_data *data, unsigned int size, 171 struct nft_data *data, unsigned int size,
172 struct nft_data_desc *desc, const struct nlattr *nla); 172 struct nft_data_desc *desc, const struct nlattr *nla);
173void nft_data_hold(const struct nft_data *data, enum nft_data_types type);
173void nft_data_release(const struct nft_data *data, enum nft_data_types type); 174void nft_data_release(const struct nft_data *data, enum nft_data_types type);
174int nft_data_dump(struct sk_buff *skb, int attr, const struct nft_data *data, 175int nft_data_dump(struct sk_buff *skb, int attr, const struct nft_data *data,
175 enum nft_data_types type, unsigned int len); 176 enum nft_data_types type, unsigned int len);
@@ -736,6 +737,10 @@ struct nft_expr_ops {
736 int (*init)(const struct nft_ctx *ctx, 737 int (*init)(const struct nft_ctx *ctx,
737 const struct nft_expr *expr, 738 const struct nft_expr *expr,
738 const struct nlattr * const tb[]); 739 const struct nlattr * const tb[]);
740 void (*activate)(const struct nft_ctx *ctx,
741 const struct nft_expr *expr);
742 void (*deactivate)(const struct nft_ctx *ctx,
743 const struct nft_expr *expr);
739 void (*destroy)(const struct nft_ctx *ctx, 744 void (*destroy)(const struct nft_ctx *ctx,
740 const struct nft_expr *expr); 745 const struct nft_expr *expr);
741 int (*dump)(struct sk_buff *skb, 746 int (*dump)(struct sk_buff *skb,
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index 28b996d63490..35498e613ff5 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -103,6 +103,8 @@ void sctp_addr_wq_mgmt(struct net *, struct sctp_sockaddr_entry *, int);
103/* 103/*
104 * sctp/socket.c 104 * sctp/socket.c
105 */ 105 */
106int sctp_inet_connect(struct socket *sock, struct sockaddr *uaddr,
107 int addr_len, int flags);
106int sctp_backlog_rcv(struct sock *sk, struct sk_buff *skb); 108int sctp_backlog_rcv(struct sock *sk, struct sk_buff *skb);
107int sctp_inet_listen(struct socket *sock, int backlog); 109int sctp_inet_listen(struct socket *sock, int backlog);
108void sctp_write_space(struct sock *sk); 110void sctp_write_space(struct sock *sk);
diff --git a/include/net/tls.h b/include/net/tls.h
index b400d0bb7448..f5fb16da3860 100644
--- a/include/net/tls.h
+++ b/include/net/tls.h
@@ -97,6 +97,9 @@ struct tls_sw_context {
97 u8 control; 97 u8 control;
98 bool decrypted; 98 bool decrypted;
99 99
100 char rx_aad_ciphertext[TLS_AAD_SPACE_SIZE];
101 char rx_aad_plaintext[TLS_AAD_SPACE_SIZE];
102
100 /* Sending context */ 103 /* Sending context */
101 char aad_space[TLS_AAD_SPACE_SIZE]; 104 char aad_space[TLS_AAD_SPACE_SIZE];
102 105
diff --git a/include/rdma/ib_umem.h b/include/rdma/ib_umem.h
index 23159dd5be18..a1fd63871d17 100644
--- a/include/rdma/ib_umem.h
+++ b/include/rdma/ib_umem.h
@@ -48,7 +48,6 @@ struct ib_umem {
48 int writable; 48 int writable;
49 int hugetlb; 49 int hugetlb;
50 struct work_struct work; 50 struct work_struct work;
51 struct pid *pid;
52 struct mm_struct *mm; 51 struct mm_struct *mm;
53 unsigned long diff; 52 unsigned long diff;
54 struct ib_umem_odp *odp_data; 53 struct ib_umem_odp *odp_data;
diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h
index 4a4201d997a7..095383a4bd1a 100644
--- a/include/rdma/uverbs_ioctl.h
+++ b/include/rdma/uverbs_ioctl.h
@@ -411,13 +411,13 @@ static inline int uverbs_attr_get_enum_id(const struct uverbs_attr_bundle *attrs
411static inline void *uverbs_attr_get_obj(const struct uverbs_attr_bundle *attrs_bundle, 411static inline void *uverbs_attr_get_obj(const struct uverbs_attr_bundle *attrs_bundle,
412 u16 idx) 412 u16 idx)
413{ 413{
414 struct ib_uobject *uobj = 414 const struct uverbs_attr *attr;
415 uverbs_attr_get(attrs_bundle, idx)->obj_attr.uobject;
416 415
417 if (IS_ERR(uobj)) 416 attr = uverbs_attr_get(attrs_bundle, idx);
418 return uobj; 417 if (IS_ERR(attr))
418 return ERR_CAST(attr);
419 419
420 return uobj->object; 420 return attr->obj_attr.uobject->object;
421} 421}
422 422
423static inline int uverbs_copy_to(const struct uverbs_attr_bundle *attrs_bundle, 423static inline int uverbs_copy_to(const struct uverbs_attr_bundle *attrs_bundle,
diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index bc01e06bc716..0be866c91f62 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -435,7 +435,9 @@ TRACE_EVENT(sched_pi_setprio,
435 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN); 435 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
436 __entry->pid = tsk->pid; 436 __entry->pid = tsk->pid;
437 __entry->oldprio = tsk->prio; 437 __entry->oldprio = tsk->prio;
438 __entry->newprio = pi_task ? pi_task->prio : tsk->prio; 438 __entry->newprio = pi_task ?
439 min(tsk->normal_prio, pi_task->prio) :
440 tsk->normal_prio;
439 /* XXX SCHED_DEADLINE bits missing */ 441 /* XXX SCHED_DEADLINE bits missing */
440 ), 442 ),
441 443
diff --git a/include/uapi/linux/netfilter/nf_conntrack_tcp.h b/include/uapi/linux/netfilter/nf_conntrack_tcp.h
index 74b91151d494..bcba72def817 100644
--- a/include/uapi/linux/netfilter/nf_conntrack_tcp.h
+++ b/include/uapi/linux/netfilter/nf_conntrack_tcp.h
@@ -46,6 +46,9 @@ enum tcp_conntrack {
46/* Marks possibility for expected RFC5961 challenge ACK */ 46/* Marks possibility for expected RFC5961 challenge ACK */
47#define IP_CT_EXP_CHALLENGE_ACK 0x40 47#define IP_CT_EXP_CHALLENGE_ACK 0x40
48 48
49/* Simultaneous open initialized */
50#define IP_CT_TCP_SIMULTANEOUS_OPEN 0x80
51
49struct nf_ct_tcp_flags { 52struct nf_ct_tcp_flags {
50 __u8 flags; 53 __u8 flags;
51 __u8 mask; 54 __u8 mask;
diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index 9c3630146cec..271b93783d28 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -2698,7 +2698,7 @@ enum nl80211_attrs {
2698#define NL80211_ATTR_KEYS NL80211_ATTR_KEYS 2698#define NL80211_ATTR_KEYS NL80211_ATTR_KEYS
2699#define NL80211_ATTR_FEATURE_FLAGS NL80211_ATTR_FEATURE_FLAGS 2699#define NL80211_ATTR_FEATURE_FLAGS NL80211_ATTR_FEATURE_FLAGS
2700 2700
2701#define NL80211_WIPHY_NAME_MAXLEN 128 2701#define NL80211_WIPHY_NAME_MAXLEN 64
2702 2702
2703#define NL80211_MAX_SUPP_RATES 32 2703#define NL80211_MAX_SUPP_RATES 32
2704#define NL80211_MAX_SUPP_HT_RATES 77 2704#define NL80211_MAX_SUPP_HT_RATES 77
diff --git a/include/uapi/linux/ppp-ioctl.h b/include/uapi/linux/ppp-ioctl.h
index b19a9c249b15..784c2e3e572e 100644
--- a/include/uapi/linux/ppp-ioctl.h
+++ b/include/uapi/linux/ppp-ioctl.h
@@ -106,7 +106,7 @@ struct pppol2tp_ioc_stats {
106#define PPPIOCGIDLE _IOR('t', 63, struct ppp_idle) /* get idle time */ 106#define PPPIOCGIDLE _IOR('t', 63, struct ppp_idle) /* get idle time */
107#define PPPIOCNEWUNIT _IOWR('t', 62, int) /* create new ppp unit */ 107#define PPPIOCNEWUNIT _IOWR('t', 62, int) /* create new ppp unit */
108#define PPPIOCATTACH _IOW('t', 61, int) /* attach to ppp unit */ 108#define PPPIOCATTACH _IOW('t', 61, int) /* attach to ppp unit */
109#define PPPIOCDETACH _IOW('t', 60, int) /* detach from ppp unit/chan */ 109#define PPPIOCDETACH _IOW('t', 60, int) /* obsolete, do not use */
110#define PPPIOCSMRRU _IOW('t', 59, int) /* set multilink MRU */ 110#define PPPIOCSMRRU _IOW('t', 59, int) /* set multilink MRU */
111#define PPPIOCCONNECT _IOW('t', 58, int) /* connect channel to unit */ 111#define PPPIOCCONNECT _IOW('t', 58, int) /* connect channel to unit */
112#define PPPIOCDISCONN _IO('t', 57) /* disconnect channel */ 112#define PPPIOCDISCONN _IO('t', 57) /* disconnect channel */
diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h
index af5f8c2df87a..db9f15f5db04 100644
--- a/include/uapi/linux/prctl.h
+++ b/include/uapi/linux/prctl.h
@@ -207,4 +207,16 @@ struct prctl_mm_map {
207# define PR_SVE_VL_LEN_MASK 0xffff 207# define PR_SVE_VL_LEN_MASK 0xffff
208# define PR_SVE_VL_INHERIT (1 << 17) /* inherit across exec */ 208# define PR_SVE_VL_INHERIT (1 << 17) /* inherit across exec */
209 209
210/* Per task speculation control */
211#define PR_GET_SPECULATION_CTRL 52
212#define PR_SET_SPECULATION_CTRL 53
213/* Speculation control variants */
214# define PR_SPEC_STORE_BYPASS 0
215/* Return and control values for PR_SET/GET_SPECULATION_CTRL */
216# define PR_SPEC_NOT_AFFECTED 0
217# define PR_SPEC_PRCTL (1UL << 0)
218# define PR_SPEC_ENABLE (1UL << 1)
219# define PR_SPEC_DISABLE (1UL << 2)
220# define PR_SPEC_FORCE_DISABLE (1UL << 3)
221
210#endif /* _LINUX_PRCTL_H */ 222#endif /* _LINUX_PRCTL_H */
diff --git a/include/uapi/linux/seccomp.h b/include/uapi/linux/seccomp.h
index 2a0bd9dd104d..9efc0e73d50b 100644
--- a/include/uapi/linux/seccomp.h
+++ b/include/uapi/linux/seccomp.h
@@ -17,8 +17,9 @@
17#define SECCOMP_GET_ACTION_AVAIL 2 17#define SECCOMP_GET_ACTION_AVAIL 2
18 18
19/* Valid flags for SECCOMP_SET_MODE_FILTER */ 19/* Valid flags for SECCOMP_SET_MODE_FILTER */
20#define SECCOMP_FILTER_FLAG_TSYNC 1 20#define SECCOMP_FILTER_FLAG_TSYNC (1UL << 0)
21#define SECCOMP_FILTER_FLAG_LOG 2 21#define SECCOMP_FILTER_FLAG_LOG (1UL << 1)
22#define SECCOMP_FILTER_FLAG_SPEC_ALLOW (1UL << 2)
22 23
23/* 24/*
24 * All BPF programs must return a 32-bit value. 25 * All BPF programs must return a 32-bit value.
diff --git a/init/main.c b/init/main.c
index fd37315835b4..3b4ada11ed52 100644
--- a/init/main.c
+++ b/init/main.c
@@ -91,6 +91,7 @@
91#include <linux/cache.h> 91#include <linux/cache.h>
92#include <linux/rodata_test.h> 92#include <linux/rodata_test.h>
93#include <linux/jump_label.h> 93#include <linux/jump_label.h>
94#include <linux/mem_encrypt.h>
94 95
95#include <asm/io.h> 96#include <asm/io.h>
96#include <asm/bugs.h> 97#include <asm/bugs.h>
diff --git a/ipc/shm.c b/ipc/shm.c
index 3cf48988d68c..d73269381ec7 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -1363,14 +1363,17 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg,
1363 1363
1364 if (addr) { 1364 if (addr) {
1365 if (addr & (shmlba - 1)) { 1365 if (addr & (shmlba - 1)) {
1366 /* 1366 if (shmflg & SHM_RND) {
1367 * Round down to the nearest multiple of shmlba. 1367 addr &= ~(shmlba - 1); /* round down */
1368 * For sane do_mmap_pgoff() parameters, avoid 1368
1369 * round downs that trigger nil-page and MAP_FIXED. 1369 /*
1370 */ 1370 * Ensure that the round-down is non-nil
1371 if ((shmflg & SHM_RND) && addr >= shmlba) 1371 * when remapping. This can happen for
1372 addr &= ~(shmlba - 1); 1372 * cases when addr < shmlba.
1373 else 1373 */
1374 if (!addr && (shmflg & SHM_REMAP))
1375 goto out;
1376 } else
1374#ifndef __ARCH_FORCE_SHMLBA 1377#ifndef __ARCH_FORCE_SHMLBA
1375 if (addr & ~PAGE_MASK) 1378 if (addr & ~PAGE_MASK)
1376#endif 1379#endif
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index ba03ec39efb3..6ef6746a7871 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -218,47 +218,84 @@ int bpf_prog_calc_tag(struct bpf_prog *fp)
218 return 0; 218 return 0;
219} 219}
220 220
221static void bpf_adj_branches(struct bpf_prog *prog, u32 pos, u32 delta) 221static int bpf_adj_delta_to_imm(struct bpf_insn *insn, u32 pos, u32 delta,
222 u32 curr, const bool probe_pass)
222{ 223{
224 const s64 imm_min = S32_MIN, imm_max = S32_MAX;
225 s64 imm = insn->imm;
226
227 if (curr < pos && curr + imm + 1 > pos)
228 imm += delta;
229 else if (curr > pos + delta && curr + imm + 1 <= pos + delta)
230 imm -= delta;
231 if (imm < imm_min || imm > imm_max)
232 return -ERANGE;
233 if (!probe_pass)
234 insn->imm = imm;
235 return 0;
236}
237
238static int bpf_adj_delta_to_off(struct bpf_insn *insn, u32 pos, u32 delta,
239 u32 curr, const bool probe_pass)
240{
241 const s32 off_min = S16_MIN, off_max = S16_MAX;
242 s32 off = insn->off;
243
244 if (curr < pos && curr + off + 1 > pos)
245 off += delta;
246 else if (curr > pos + delta && curr + off + 1 <= pos + delta)
247 off -= delta;
248 if (off < off_min || off > off_max)
249 return -ERANGE;
250 if (!probe_pass)
251 insn->off = off;
252 return 0;
253}
254
255static int bpf_adj_branches(struct bpf_prog *prog, u32 pos, u32 delta,
256 const bool probe_pass)
257{
258 u32 i, insn_cnt = prog->len + (probe_pass ? delta : 0);
223 struct bpf_insn *insn = prog->insnsi; 259 struct bpf_insn *insn = prog->insnsi;
224 u32 i, insn_cnt = prog->len; 260 int ret = 0;
225 bool pseudo_call;
226 u8 code;
227 int off;
228 261
229 for (i = 0; i < insn_cnt; i++, insn++) { 262 for (i = 0; i < insn_cnt; i++, insn++) {
263 u8 code;
264
265 /* In the probing pass we still operate on the original,
266 * unpatched image in order to check overflows before we
267 * do any other adjustments. Therefore skip the patchlet.
268 */
269 if (probe_pass && i == pos) {
270 i += delta + 1;
271 insn++;
272 }
230 code = insn->code; 273 code = insn->code;
231 if (BPF_CLASS(code) != BPF_JMP) 274 if (BPF_CLASS(code) != BPF_JMP ||
232 continue; 275 BPF_OP(code) == BPF_EXIT)
233 if (BPF_OP(code) == BPF_EXIT)
234 continue; 276 continue;
277 /* Adjust offset of jmps if we cross patch boundaries. */
235 if (BPF_OP(code) == BPF_CALL) { 278 if (BPF_OP(code) == BPF_CALL) {
236 if (insn->src_reg == BPF_PSEUDO_CALL) 279 if (insn->src_reg != BPF_PSEUDO_CALL)
237 pseudo_call = true;
238 else
239 continue; 280 continue;
281 ret = bpf_adj_delta_to_imm(insn, pos, delta, i,
282 probe_pass);
240 } else { 283 } else {
241 pseudo_call = false; 284 ret = bpf_adj_delta_to_off(insn, pos, delta, i,
285 probe_pass);
242 } 286 }
243 off = pseudo_call ? insn->imm : insn->off; 287 if (ret)
244 288 break;
245 /* Adjust offset of jmps if we cross boundaries. */
246 if (i < pos && i + off + 1 > pos)
247 off += delta;
248 else if (i > pos + delta && i + off + 1 <= pos + delta)
249 off -= delta;
250
251 if (pseudo_call)
252 insn->imm = off;
253 else
254 insn->off = off;
255 } 289 }
290
291 return ret;
256} 292}
257 293
258struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off, 294struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off,
259 const struct bpf_insn *patch, u32 len) 295 const struct bpf_insn *patch, u32 len)
260{ 296{
261 u32 insn_adj_cnt, insn_rest, insn_delta = len - 1; 297 u32 insn_adj_cnt, insn_rest, insn_delta = len - 1;
298 const u32 cnt_max = S16_MAX;
262 struct bpf_prog *prog_adj; 299 struct bpf_prog *prog_adj;
263 300
264 /* Since our patchlet doesn't expand the image, we're done. */ 301 /* Since our patchlet doesn't expand the image, we're done. */
@@ -269,6 +306,15 @@ struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off,
269 306
270 insn_adj_cnt = prog->len + insn_delta; 307 insn_adj_cnt = prog->len + insn_delta;
271 308
309 /* Reject anything that would potentially let the insn->off
310 * target overflow when we have excessive program expansions.
311 * We need to probe here before we do any reallocation where
312 * we afterwards may not fail anymore.
313 */
314 if (insn_adj_cnt > cnt_max &&
315 bpf_adj_branches(prog, off, insn_delta, true))
316 return NULL;
317
272 /* Several new instructions need to be inserted. Make room 318 /* Several new instructions need to be inserted. Make room
273 * for them. Likely, there's no need for a new allocation as 319 * for them. Likely, there's no need for a new allocation as
274 * last page could have large enough tailroom. 320 * last page could have large enough tailroom.
@@ -294,7 +340,11 @@ struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off,
294 sizeof(*patch) * insn_rest); 340 sizeof(*patch) * insn_rest);
295 memcpy(prog_adj->insnsi + off, patch, sizeof(*patch) * len); 341 memcpy(prog_adj->insnsi + off, patch, sizeof(*patch) * len);
296 342
297 bpf_adj_branches(prog_adj, off, insn_delta); 343 /* We are guaranteed to not fail at this point, otherwise
344 * the ship has sailed to reverse to the original state. An
345 * overflow cannot happen at this point.
346 */
347 BUG_ON(bpf_adj_branches(prog_adj, off, insn_delta, false));
298 348
299 return prog_adj; 349 return prog_adj;
300} 350}
diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c
index 098eca568c2b..95a84b2f10ce 100644
--- a/kernel/bpf/sockmap.c
+++ b/kernel/bpf/sockmap.c
@@ -1703,11 +1703,11 @@ static int sock_map_ctx_update_elem(struct bpf_sock_ops_kern *skops,
1703 * we increment the refcnt. If this is the case abort with an 1703 * we increment the refcnt. If this is the case abort with an
1704 * error. 1704 * error.
1705 */ 1705 */
1706 verdict = bpf_prog_inc_not_zero(stab->bpf_verdict); 1706 verdict = bpf_prog_inc_not_zero(verdict);
1707 if (IS_ERR(verdict)) 1707 if (IS_ERR(verdict))
1708 return PTR_ERR(verdict); 1708 return PTR_ERR(verdict);
1709 1709
1710 parse = bpf_prog_inc_not_zero(stab->bpf_parse); 1710 parse = bpf_prog_inc_not_zero(parse);
1711 if (IS_ERR(parse)) { 1711 if (IS_ERR(parse)) {
1712 bpf_prog_put(verdict); 1712 bpf_prog_put(verdict);
1713 return PTR_ERR(parse); 1713 return PTR_ERR(parse);
@@ -1715,12 +1715,12 @@ static int sock_map_ctx_update_elem(struct bpf_sock_ops_kern *skops,
1715 } 1715 }
1716 1716
1717 if (tx_msg) { 1717 if (tx_msg) {
1718 tx_msg = bpf_prog_inc_not_zero(stab->bpf_tx_msg); 1718 tx_msg = bpf_prog_inc_not_zero(tx_msg);
1719 if (IS_ERR(tx_msg)) { 1719 if (IS_ERR(tx_msg)) {
1720 if (verdict) 1720 if (parse && verdict) {
1721 bpf_prog_put(verdict);
1722 if (parse)
1723 bpf_prog_put(parse); 1721 bpf_prog_put(parse);
1722 bpf_prog_put(verdict);
1723 }
1724 return PTR_ERR(tx_msg); 1724 return PTR_ERR(tx_msg);
1725 } 1725 }
1726 } 1726 }
@@ -1805,10 +1805,10 @@ static int sock_map_ctx_update_elem(struct bpf_sock_ops_kern *skops,
1805out_free: 1805out_free:
1806 smap_release_sock(psock, sock); 1806 smap_release_sock(psock, sock);
1807out_progs: 1807out_progs:
1808 if (verdict) 1808 if (parse && verdict) {
1809 bpf_prog_put(verdict);
1810 if (parse)
1811 bpf_prog_put(parse); 1809 bpf_prog_put(parse);
1810 bpf_prog_put(verdict);
1811 }
1812 if (tx_msg) 1812 if (tx_msg)
1813 bpf_prog_put(tx_msg); 1813 bpf_prog_put(tx_msg);
1814 write_unlock_bh(&sock->sk_callback_lock); 1814 write_unlock_bh(&sock->sk_callback_lock);
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 5dd1dcb902bf..1904e814f282 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -156,7 +156,29 @@ struct bpf_verifier_stack_elem {
156#define BPF_COMPLEXITY_LIMIT_INSNS 131072 156#define BPF_COMPLEXITY_LIMIT_INSNS 131072
157#define BPF_COMPLEXITY_LIMIT_STACK 1024 157#define BPF_COMPLEXITY_LIMIT_STACK 1024
158 158
159#define BPF_MAP_PTR_POISON ((void *)0xeB9F + POISON_POINTER_DELTA) 159#define BPF_MAP_PTR_UNPRIV 1UL
160#define BPF_MAP_PTR_POISON ((void *)((0xeB9FUL << 1) + \
161 POISON_POINTER_DELTA))
162#define BPF_MAP_PTR(X) ((struct bpf_map *)((X) & ~BPF_MAP_PTR_UNPRIV))
163
164static bool bpf_map_ptr_poisoned(const struct bpf_insn_aux_data *aux)
165{
166 return BPF_MAP_PTR(aux->map_state) == BPF_MAP_PTR_POISON;
167}
168
169static bool bpf_map_ptr_unpriv(const struct bpf_insn_aux_data *aux)
170{
171 return aux->map_state & BPF_MAP_PTR_UNPRIV;
172}
173
174static void bpf_map_ptr_store(struct bpf_insn_aux_data *aux,
175 const struct bpf_map *map, bool unpriv)
176{
177 BUILD_BUG_ON((unsigned long)BPF_MAP_PTR_POISON & BPF_MAP_PTR_UNPRIV);
178 unpriv |= bpf_map_ptr_unpriv(aux);
179 aux->map_state = (unsigned long)map |
180 (unpriv ? BPF_MAP_PTR_UNPRIV : 0UL);
181}
160 182
161struct bpf_call_arg_meta { 183struct bpf_call_arg_meta {
162 struct bpf_map *map_ptr; 184 struct bpf_map *map_ptr;
@@ -978,7 +1000,7 @@ static bool register_is_null(struct bpf_reg_state *reg)
978 */ 1000 */
979static int check_stack_write(struct bpf_verifier_env *env, 1001static int check_stack_write(struct bpf_verifier_env *env,
980 struct bpf_func_state *state, /* func where register points to */ 1002 struct bpf_func_state *state, /* func where register points to */
981 int off, int size, int value_regno) 1003 int off, int size, int value_regno, int insn_idx)
982{ 1004{
983 struct bpf_func_state *cur; /* state of the current function */ 1005 struct bpf_func_state *cur; /* state of the current function */
984 int i, slot = -off - 1, spi = slot / BPF_REG_SIZE, err; 1006 int i, slot = -off - 1, spi = slot / BPF_REG_SIZE, err;
@@ -1017,8 +1039,33 @@ static int check_stack_write(struct bpf_verifier_env *env,
1017 state->stack[spi].spilled_ptr = cur->regs[value_regno]; 1039 state->stack[spi].spilled_ptr = cur->regs[value_regno];
1018 state->stack[spi].spilled_ptr.live |= REG_LIVE_WRITTEN; 1040 state->stack[spi].spilled_ptr.live |= REG_LIVE_WRITTEN;
1019 1041
1020 for (i = 0; i < BPF_REG_SIZE; i++) 1042 for (i = 0; i < BPF_REG_SIZE; i++) {
1043 if (state->stack[spi].slot_type[i] == STACK_MISC &&
1044 !env->allow_ptr_leaks) {
1045 int *poff = &env->insn_aux_data[insn_idx].sanitize_stack_off;
1046 int soff = (-spi - 1) * BPF_REG_SIZE;
1047
1048 /* detected reuse of integer stack slot with a pointer
1049 * which means either llvm is reusing stack slot or
1050 * an attacker is trying to exploit CVE-2018-3639
1051 * (speculative store bypass)
1052 * Have to sanitize that slot with preemptive
1053 * store of zero.
1054 */
1055 if (*poff && *poff != soff) {
1056 /* disallow programs where single insn stores
1057 * into two different stack slots, since verifier
1058 * cannot sanitize them
1059 */
1060 verbose(env,
1061 "insn %d cannot access two stack slots fp%d and fp%d",
1062 insn_idx, *poff, soff);
1063 return -EINVAL;
1064 }
1065 *poff = soff;
1066 }
1021 state->stack[spi].slot_type[i] = STACK_SPILL; 1067 state->stack[spi].slot_type[i] = STACK_SPILL;
1068 }
1022 } else { 1069 } else {
1023 u8 type = STACK_MISC; 1070 u8 type = STACK_MISC;
1024 1071
@@ -1694,7 +1741,7 @@ static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, u32 regn
1694 1741
1695 if (t == BPF_WRITE) 1742 if (t == BPF_WRITE)
1696 err = check_stack_write(env, state, off, size, 1743 err = check_stack_write(env, state, off, size,
1697 value_regno); 1744 value_regno, insn_idx);
1698 else 1745 else
1699 err = check_stack_read(env, state, off, size, 1746 err = check_stack_read(env, state, off, size,
1700 value_regno); 1747 value_regno);
@@ -2333,6 +2380,29 @@ static int prepare_func_exit(struct bpf_verifier_env *env, int *insn_idx)
2333 return 0; 2380 return 0;
2334} 2381}
2335 2382
2383static int
2384record_func_map(struct bpf_verifier_env *env, struct bpf_call_arg_meta *meta,
2385 int func_id, int insn_idx)
2386{
2387 struct bpf_insn_aux_data *aux = &env->insn_aux_data[insn_idx];
2388
2389 if (func_id != BPF_FUNC_tail_call &&
2390 func_id != BPF_FUNC_map_lookup_elem)
2391 return 0;
2392 if (meta->map_ptr == NULL) {
2393 verbose(env, "kernel subsystem misconfigured verifier\n");
2394 return -EINVAL;
2395 }
2396
2397 if (!BPF_MAP_PTR(aux->map_state))
2398 bpf_map_ptr_store(aux, meta->map_ptr,
2399 meta->map_ptr->unpriv_array);
2400 else if (BPF_MAP_PTR(aux->map_state) != meta->map_ptr)
2401 bpf_map_ptr_store(aux, BPF_MAP_PTR_POISON,
2402 meta->map_ptr->unpriv_array);
2403 return 0;
2404}
2405
2336static int check_helper_call(struct bpf_verifier_env *env, int func_id, int insn_idx) 2406static int check_helper_call(struct bpf_verifier_env *env, int func_id, int insn_idx)
2337{ 2407{
2338 const struct bpf_func_proto *fn = NULL; 2408 const struct bpf_func_proto *fn = NULL;
@@ -2387,13 +2457,6 @@ static int check_helper_call(struct bpf_verifier_env *env, int func_id, int insn
2387 err = check_func_arg(env, BPF_REG_2, fn->arg2_type, &meta); 2457 err = check_func_arg(env, BPF_REG_2, fn->arg2_type, &meta);
2388 if (err) 2458 if (err)
2389 return err; 2459 return err;
2390 if (func_id == BPF_FUNC_tail_call) {
2391 if (meta.map_ptr == NULL) {
2392 verbose(env, "verifier bug\n");
2393 return -EINVAL;
2394 }
2395 env->insn_aux_data[insn_idx].map_ptr = meta.map_ptr;
2396 }
2397 err = check_func_arg(env, BPF_REG_3, fn->arg3_type, &meta); 2460 err = check_func_arg(env, BPF_REG_3, fn->arg3_type, &meta);
2398 if (err) 2461 if (err)
2399 return err; 2462 return err;
@@ -2404,6 +2467,10 @@ static int check_helper_call(struct bpf_verifier_env *env, int func_id, int insn
2404 if (err) 2467 if (err)
2405 return err; 2468 return err;
2406 2469
2470 err = record_func_map(env, &meta, func_id, insn_idx);
2471 if (err)
2472 return err;
2473
2407 /* Mark slots with STACK_MISC in case of raw mode, stack offset 2474 /* Mark slots with STACK_MISC in case of raw mode, stack offset
2408 * is inferred from register state. 2475 * is inferred from register state.
2409 */ 2476 */
@@ -2428,8 +2495,6 @@ static int check_helper_call(struct bpf_verifier_env *env, int func_id, int insn
2428 } else if (fn->ret_type == RET_VOID) { 2495 } else if (fn->ret_type == RET_VOID) {
2429 regs[BPF_REG_0].type = NOT_INIT; 2496 regs[BPF_REG_0].type = NOT_INIT;
2430 } else if (fn->ret_type == RET_PTR_TO_MAP_VALUE_OR_NULL) { 2497 } else if (fn->ret_type == RET_PTR_TO_MAP_VALUE_OR_NULL) {
2431 struct bpf_insn_aux_data *insn_aux;
2432
2433 regs[BPF_REG_0].type = PTR_TO_MAP_VALUE_OR_NULL; 2498 regs[BPF_REG_0].type = PTR_TO_MAP_VALUE_OR_NULL;
2434 /* There is no offset yet applied, variable or fixed */ 2499 /* There is no offset yet applied, variable or fixed */
2435 mark_reg_known_zero(env, regs, BPF_REG_0); 2500 mark_reg_known_zero(env, regs, BPF_REG_0);
@@ -2445,11 +2510,6 @@ static int check_helper_call(struct bpf_verifier_env *env, int func_id, int insn
2445 } 2510 }
2446 regs[BPF_REG_0].map_ptr = meta.map_ptr; 2511 regs[BPF_REG_0].map_ptr = meta.map_ptr;
2447 regs[BPF_REG_0].id = ++env->id_gen; 2512 regs[BPF_REG_0].id = ++env->id_gen;
2448 insn_aux = &env->insn_aux_data[insn_idx];
2449 if (!insn_aux->map_ptr)
2450 insn_aux->map_ptr = meta.map_ptr;
2451 else if (insn_aux->map_ptr != meta.map_ptr)
2452 insn_aux->map_ptr = BPF_MAP_PTR_POISON;
2453 } else { 2513 } else {
2454 verbose(env, "unknown return type %d of func %s#%d\n", 2514 verbose(env, "unknown return type %d of func %s#%d\n",
2455 fn->ret_type, func_id_name(func_id), func_id); 2515 fn->ret_type, func_id_name(func_id), func_id);
@@ -5169,6 +5229,34 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env)
5169 else 5229 else
5170 continue; 5230 continue;
5171 5231
5232 if (type == BPF_WRITE &&
5233 env->insn_aux_data[i + delta].sanitize_stack_off) {
5234 struct bpf_insn patch[] = {
5235 /* Sanitize suspicious stack slot with zero.
5236 * There are no memory dependencies for this store,
5237 * since it's only using frame pointer and immediate
5238 * constant of zero
5239 */
5240 BPF_ST_MEM(BPF_DW, BPF_REG_FP,
5241 env->insn_aux_data[i + delta].sanitize_stack_off,
5242 0),
5243 /* the original STX instruction will immediately
5244 * overwrite the same stack slot with appropriate value
5245 */
5246 *insn,
5247 };
5248
5249 cnt = ARRAY_SIZE(patch);
5250 new_prog = bpf_patch_insn_data(env, i + delta, patch, cnt);
5251 if (!new_prog)
5252 return -ENOMEM;
5253
5254 delta += cnt - 1;
5255 env->prog = new_prog;
5256 insn = new_prog->insnsi + i + delta;
5257 continue;
5258 }
5259
5172 if (env->insn_aux_data[i + delta].ptr_type != PTR_TO_CTX) 5260 if (env->insn_aux_data[i + delta].ptr_type != PTR_TO_CTX)
5173 continue; 5261 continue;
5174 5262
@@ -5417,6 +5505,7 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)
5417 struct bpf_insn *insn = prog->insnsi; 5505 struct bpf_insn *insn = prog->insnsi;
5418 const struct bpf_func_proto *fn; 5506 const struct bpf_func_proto *fn;
5419 const int insn_cnt = prog->len; 5507 const int insn_cnt = prog->len;
5508 struct bpf_insn_aux_data *aux;
5420 struct bpf_insn insn_buf[16]; 5509 struct bpf_insn insn_buf[16];
5421 struct bpf_prog *new_prog; 5510 struct bpf_prog *new_prog;
5422 struct bpf_map *map_ptr; 5511 struct bpf_map *map_ptr;
@@ -5491,19 +5580,22 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)
5491 insn->imm = 0; 5580 insn->imm = 0;
5492 insn->code = BPF_JMP | BPF_TAIL_CALL; 5581 insn->code = BPF_JMP | BPF_TAIL_CALL;
5493 5582
5583 aux = &env->insn_aux_data[i + delta];
5584 if (!bpf_map_ptr_unpriv(aux))
5585 continue;
5586
5494 /* instead of changing every JIT dealing with tail_call 5587 /* instead of changing every JIT dealing with tail_call
5495 * emit two extra insns: 5588 * emit two extra insns:
5496 * if (index >= max_entries) goto out; 5589 * if (index >= max_entries) goto out;
5497 * index &= array->index_mask; 5590 * index &= array->index_mask;
5498 * to avoid out-of-bounds cpu speculation 5591 * to avoid out-of-bounds cpu speculation
5499 */ 5592 */
5500 map_ptr = env->insn_aux_data[i + delta].map_ptr; 5593 if (bpf_map_ptr_poisoned(aux)) {
5501 if (map_ptr == BPF_MAP_PTR_POISON) {
5502 verbose(env, "tail_call abusing map_ptr\n"); 5594 verbose(env, "tail_call abusing map_ptr\n");
5503 return -EINVAL; 5595 return -EINVAL;
5504 } 5596 }
5505 if (!map_ptr->unpriv_array) 5597
5506 continue; 5598 map_ptr = BPF_MAP_PTR(aux->map_state);
5507 insn_buf[0] = BPF_JMP_IMM(BPF_JGE, BPF_REG_3, 5599 insn_buf[0] = BPF_JMP_IMM(BPF_JGE, BPF_REG_3,
5508 map_ptr->max_entries, 2); 5600 map_ptr->max_entries, 2);
5509 insn_buf[1] = BPF_ALU32_IMM(BPF_AND, BPF_REG_3, 5601 insn_buf[1] = BPF_ALU32_IMM(BPF_AND, BPF_REG_3,
@@ -5527,9 +5619,12 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)
5527 */ 5619 */
5528 if (prog->jit_requested && BITS_PER_LONG == 64 && 5620 if (prog->jit_requested && BITS_PER_LONG == 64 &&
5529 insn->imm == BPF_FUNC_map_lookup_elem) { 5621 insn->imm == BPF_FUNC_map_lookup_elem) {
5530 map_ptr = env->insn_aux_data[i + delta].map_ptr; 5622 aux = &env->insn_aux_data[i + delta];
5531 if (map_ptr == BPF_MAP_PTR_POISON || 5623 if (bpf_map_ptr_poisoned(aux))
5532 !map_ptr->ops->map_gen_lookup) 5624 goto patch_call_imm;
5625
5626 map_ptr = BPF_MAP_PTR(aux->map_state);
5627 if (!map_ptr->ops->map_gen_lookup)
5533 goto patch_call_imm; 5628 goto patch_call_imm;
5534 5629
5535 cnt = map_ptr->ops->map_gen_lookup(map_ptr, insn_buf); 5630 cnt = map_ptr->ops->map_gen_lookup(map_ptr, insn_buf);
diff --git a/kernel/kthread.c b/kernel/kthread.c
index 2017a39ab490..481951bf091d 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -193,7 +193,7 @@ EXPORT_SYMBOL_GPL(kthread_parkme);
193 193
194void kthread_park_complete(struct task_struct *k) 194void kthread_park_complete(struct task_struct *k)
195{ 195{
196 complete(&to_kthread(k)->parked); 196 complete_all(&to_kthread(k)->parked);
197} 197}
198 198
199static int kthread(void *_create) 199static int kthread(void *_create)
@@ -459,6 +459,7 @@ void kthread_unpark(struct task_struct *k)
459 if (test_bit(KTHREAD_IS_PER_CPU, &kthread->flags)) 459 if (test_bit(KTHREAD_IS_PER_CPU, &kthread->flags))
460 __kthread_bind(k, kthread->cpu, TASK_PARKED); 460 __kthread_bind(k, kthread->cpu, TASK_PARKED);
461 461
462 reinit_completion(&kthread->parked);
462 clear_bit(KTHREAD_SHOULD_PARK, &kthread->flags); 463 clear_bit(KTHREAD_SHOULD_PARK, &kthread->flags);
463 wake_up_state(k, TASK_PARKED); 464 wake_up_state(k, TASK_PARKED);
464} 465}
@@ -483,9 +484,6 @@ int kthread_park(struct task_struct *k)
483 if (WARN_ON(k->flags & PF_EXITING)) 484 if (WARN_ON(k->flags & PF_EXITING))
484 return -ENOSYS; 485 return -ENOSYS;
485 486
486 if (WARN_ON_ONCE(test_bit(KTHREAD_SHOULD_PARK, &kthread->flags)))
487 return -EBUSY;
488
489 set_bit(KTHREAD_SHOULD_PARK, &kthread->flags); 487 set_bit(KTHREAD_SHOULD_PARK, &kthread->flags);
490 if (k != current) { 488 if (k != current) {
491 wake_up_process(k); 489 wake_up_process(k);
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index 64cc564f5255..61a1125c1ae4 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -1708,7 +1708,7 @@ build_sched_domains(const struct cpumask *cpu_map, struct sched_domain_attr *att
1708 rcu_read_unlock(); 1708 rcu_read_unlock();
1709 1709
1710 if (rq && sched_debug_enabled) { 1710 if (rq && sched_debug_enabled) {
1711 pr_info("span: %*pbl (max cpu_capacity = %lu)\n", 1711 pr_info("root domain span: %*pbl (max cpu_capacity = %lu)\n",
1712 cpumask_pr_args(cpu_map), rq->rd->max_cpu_capacity); 1712 cpumask_pr_args(cpu_map), rq->rd->max_cpu_capacity);
1713 } 1713 }
1714 1714
diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index dc77548167ef..e691d9a6c58d 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -19,6 +19,8 @@
19#include <linux/compat.h> 19#include <linux/compat.h>
20#include <linux/coredump.h> 20#include <linux/coredump.h>
21#include <linux/kmemleak.h> 21#include <linux/kmemleak.h>
22#include <linux/nospec.h>
23#include <linux/prctl.h>
22#include <linux/sched.h> 24#include <linux/sched.h>
23#include <linux/sched/task_stack.h> 25#include <linux/sched/task_stack.h>
24#include <linux/seccomp.h> 26#include <linux/seccomp.h>
@@ -227,8 +229,11 @@ static inline bool seccomp_may_assign_mode(unsigned long seccomp_mode)
227 return true; 229 return true;
228} 230}
229 231
232void __weak arch_seccomp_spec_mitigate(struct task_struct *task) { }
233
230static inline void seccomp_assign_mode(struct task_struct *task, 234static inline void seccomp_assign_mode(struct task_struct *task,
231 unsigned long seccomp_mode) 235 unsigned long seccomp_mode,
236 unsigned long flags)
232{ 237{
233 assert_spin_locked(&task->sighand->siglock); 238 assert_spin_locked(&task->sighand->siglock);
234 239
@@ -238,6 +243,9 @@ static inline void seccomp_assign_mode(struct task_struct *task,
238 * filter) is set. 243 * filter) is set.
239 */ 244 */
240 smp_mb__before_atomic(); 245 smp_mb__before_atomic();
246 /* Assume default seccomp processes want spec flaw mitigation. */
247 if ((flags & SECCOMP_FILTER_FLAG_SPEC_ALLOW) == 0)
248 arch_seccomp_spec_mitigate(task);
241 set_tsk_thread_flag(task, TIF_SECCOMP); 249 set_tsk_thread_flag(task, TIF_SECCOMP);
242} 250}
243 251
@@ -305,7 +313,7 @@ static inline pid_t seccomp_can_sync_threads(void)
305 * without dropping the locks. 313 * without dropping the locks.
306 * 314 *
307 */ 315 */
308static inline void seccomp_sync_threads(void) 316static inline void seccomp_sync_threads(unsigned long flags)
309{ 317{
310 struct task_struct *thread, *caller; 318 struct task_struct *thread, *caller;
311 319
@@ -346,7 +354,8 @@ static inline void seccomp_sync_threads(void)
346 * allow one thread to transition the other. 354 * allow one thread to transition the other.
347 */ 355 */
348 if (thread->seccomp.mode == SECCOMP_MODE_DISABLED) 356 if (thread->seccomp.mode == SECCOMP_MODE_DISABLED)
349 seccomp_assign_mode(thread, SECCOMP_MODE_FILTER); 357 seccomp_assign_mode(thread, SECCOMP_MODE_FILTER,
358 flags);
350 } 359 }
351} 360}
352 361
@@ -469,7 +478,7 @@ static long seccomp_attach_filter(unsigned int flags,
469 478
470 /* Now that the new filter is in place, synchronize to all threads. */ 479 /* Now that the new filter is in place, synchronize to all threads. */
471 if (flags & SECCOMP_FILTER_FLAG_TSYNC) 480 if (flags & SECCOMP_FILTER_FLAG_TSYNC)
472 seccomp_sync_threads(); 481 seccomp_sync_threads(flags);
473 482
474 return 0; 483 return 0;
475} 484}
@@ -818,7 +827,7 @@ static long seccomp_set_mode_strict(void)
818#ifdef TIF_NOTSC 827#ifdef TIF_NOTSC
819 disable_TSC(); 828 disable_TSC();
820#endif 829#endif
821 seccomp_assign_mode(current, seccomp_mode); 830 seccomp_assign_mode(current, seccomp_mode, 0);
822 ret = 0; 831 ret = 0;
823 832
824out: 833out:
@@ -876,7 +885,7 @@ static long seccomp_set_mode_filter(unsigned int flags,
876 /* Do not free the successfully attached filter. */ 885 /* Do not free the successfully attached filter. */
877 prepared = NULL; 886 prepared = NULL;
878 887
879 seccomp_assign_mode(current, seccomp_mode); 888 seccomp_assign_mode(current, seccomp_mode, flags);
880out: 889out:
881 spin_unlock_irq(&current->sighand->siglock); 890 spin_unlock_irq(&current->sighand->siglock);
882 if (flags & SECCOMP_FILTER_FLAG_TSYNC) 891 if (flags & SECCOMP_FILTER_FLAG_TSYNC)
diff --git a/kernel/sys.c b/kernel/sys.c
index ad692183dfe9..d1b2b8d934bb 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -61,6 +61,8 @@
61#include <linux/uidgid.h> 61#include <linux/uidgid.h>
62#include <linux/cred.h> 62#include <linux/cred.h>
63 63
64#include <linux/nospec.h>
65
64#include <linux/kmsg_dump.h> 66#include <linux/kmsg_dump.h>
65/* Move somewhere else to avoid recompiling? */ 67/* Move somewhere else to avoid recompiling? */
66#include <generated/utsrelease.h> 68#include <generated/utsrelease.h>
@@ -69,6 +71,9 @@
69#include <asm/io.h> 71#include <asm/io.h>
70#include <asm/unistd.h> 72#include <asm/unistd.h>
71 73
74/* Hardening for Spectre-v1 */
75#include <linux/nospec.h>
76
72#include "uid16.h" 77#include "uid16.h"
73 78
74#ifndef SET_UNALIGN_CTL 79#ifndef SET_UNALIGN_CTL
@@ -1451,6 +1456,7 @@ SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
1451 if (resource >= RLIM_NLIMITS) 1456 if (resource >= RLIM_NLIMITS)
1452 return -EINVAL; 1457 return -EINVAL;
1453 1458
1459 resource = array_index_nospec(resource, RLIM_NLIMITS);
1454 task_lock(current->group_leader); 1460 task_lock(current->group_leader);
1455 x = current->signal->rlim[resource]; 1461 x = current->signal->rlim[resource];
1456 task_unlock(current->group_leader); 1462 task_unlock(current->group_leader);
@@ -1470,6 +1476,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
1470 if (resource >= RLIM_NLIMITS) 1476 if (resource >= RLIM_NLIMITS)
1471 return -EINVAL; 1477 return -EINVAL;
1472 1478
1479 resource = array_index_nospec(resource, RLIM_NLIMITS);
1473 task_lock(current->group_leader); 1480 task_lock(current->group_leader);
1474 r = current->signal->rlim[resource]; 1481 r = current->signal->rlim[resource];
1475 task_unlock(current->group_leader); 1482 task_unlock(current->group_leader);
@@ -2242,6 +2249,17 @@ static int propagate_has_child_subreaper(struct task_struct *p, void *data)
2242 return 1; 2249 return 1;
2243} 2250}
2244 2251
2252int __weak arch_prctl_spec_ctrl_get(struct task_struct *t, unsigned long which)
2253{
2254 return -EINVAL;
2255}
2256
2257int __weak arch_prctl_spec_ctrl_set(struct task_struct *t, unsigned long which,
2258 unsigned long ctrl)
2259{
2260 return -EINVAL;
2261}
2262
2245SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, 2263SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
2246 unsigned long, arg4, unsigned long, arg5) 2264 unsigned long, arg4, unsigned long, arg5)
2247{ 2265{
@@ -2450,6 +2468,16 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
2450 case PR_SVE_GET_VL: 2468 case PR_SVE_GET_VL:
2451 error = SVE_GET_VL(); 2469 error = SVE_GET_VL();
2452 break; 2470 break;
2471 case PR_GET_SPECULATION_CTRL:
2472 if (arg3 || arg4 || arg5)
2473 return -EINVAL;
2474 error = arch_prctl_spec_ctrl_get(me, arg2);
2475 break;
2476 case PR_SET_SPECULATION_CTRL:
2477 if (arg4 || arg5)
2478 return -EINVAL;
2479 error = arch_prctl_spec_ctrl_set(me, arg2, arg3);
2480 break;
2453 default: 2481 default:
2454 error = -EINVAL; 2482 error = -EINVAL;
2455 break; 2483 break;
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 970212670b6a..fdae394172fa 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -1012,7 +1012,7 @@ unsigned long iov_iter_gap_alignment(const struct iov_iter *i)
1012} 1012}
1013EXPORT_SYMBOL(iov_iter_gap_alignment); 1013EXPORT_SYMBOL(iov_iter_gap_alignment);
1014 1014
1015static inline size_t __pipe_get_pages(struct iov_iter *i, 1015static inline ssize_t __pipe_get_pages(struct iov_iter *i,
1016 size_t maxsize, 1016 size_t maxsize,
1017 struct page **pages, 1017 struct page **pages,
1018 int idx, 1018 int idx,
@@ -1102,7 +1102,7 @@ static ssize_t pipe_get_pages_alloc(struct iov_iter *i,
1102 size_t *start) 1102 size_t *start)
1103{ 1103{
1104 struct page **p; 1104 struct page **p;
1105 size_t n; 1105 ssize_t n;
1106 int idx; 1106 int idx;
1107 int npages; 1107 int npages;
1108 1108
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 43e0cbedc3a0..a9e41aed6de4 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -2034,10 +2034,12 @@ void *radix_tree_delete_item(struct radix_tree_root *root,
2034 unsigned long index, void *item) 2034 unsigned long index, void *item)
2035{ 2035{
2036 struct radix_tree_node *node = NULL; 2036 struct radix_tree_node *node = NULL;
2037 void __rcu **slot; 2037 void __rcu **slot = NULL;
2038 void *entry; 2038 void *entry;
2039 2039
2040 entry = __radix_tree_lookup(root, index, &node, &slot); 2040 entry = __radix_tree_lookup(root, index, &node, &slot);
2041 if (!slot)
2042 return NULL;
2041 if (!entry && (!is_idr(root) || node_tag_get(root, node, IDR_FREE, 2043 if (!entry && (!is_idr(root) || node_tag_get(root, node, IDR_FREE,
2042 get_slot_offset(node, slot)))) 2044 get_slot_offset(node, slot))))
2043 return NULL; 2045 return NULL;
diff --git a/mm/cma.c b/mm/cma.c
index aa40e6c7b042..5809bbe360d7 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -39,7 +39,6 @@
39#include <trace/events/cma.h> 39#include <trace/events/cma.h>
40 40
41#include "cma.h" 41#include "cma.h"
42#include "internal.h"
43 42
44struct cma cma_areas[MAX_CMA_AREAS]; 43struct cma cma_areas[MAX_CMA_AREAS];
45unsigned cma_area_count; 44unsigned cma_area_count;
@@ -110,25 +109,23 @@ static int __init cma_activate_area(struct cma *cma)
110 if (!cma->bitmap) 109 if (!cma->bitmap)
111 return -ENOMEM; 110 return -ENOMEM;
112 111
112 WARN_ON_ONCE(!pfn_valid(pfn));
113 zone = page_zone(pfn_to_page(pfn));
114
113 do { 115 do {
114 unsigned j; 116 unsigned j;
115 117
116 base_pfn = pfn; 118 base_pfn = pfn;
117 if (!pfn_valid(base_pfn))
118 goto err;
119
120 zone = page_zone(pfn_to_page(base_pfn));
121 for (j = pageblock_nr_pages; j; --j, pfn++) { 119 for (j = pageblock_nr_pages; j; --j, pfn++) {
122 if (!pfn_valid(pfn)) 120 WARN_ON_ONCE(!pfn_valid(pfn));
123 goto err;
124
125 /* 121 /*
126 * In init_cma_reserved_pageblock(), present_pages 122 * alloc_contig_range requires the pfn range
127 * is adjusted with assumption that all pages in 123 * specified to be in the same zone. Make this
128 * the pageblock come from a single zone. 124 * simple by forcing the entire CMA resv range
125 * to be in the same zone.
129 */ 126 */
130 if (page_zone(pfn_to_page(pfn)) != zone) 127 if (page_zone(pfn_to_page(pfn)) != zone)
131 goto err; 128 goto not_in_zone;
132 } 129 }
133 init_cma_reserved_pageblock(pfn_to_page(base_pfn)); 130 init_cma_reserved_pageblock(pfn_to_page(base_pfn));
134 } while (--i); 131 } while (--i);
@@ -142,7 +139,7 @@ static int __init cma_activate_area(struct cma *cma)
142 139
143 return 0; 140 return 0;
144 141
145err: 142not_in_zone:
146 pr_err("CMA area %s could not be activated\n", cma->name); 143 pr_err("CMA area %s could not be activated\n", cma->name);
147 kfree(cma->bitmap); 144 kfree(cma->bitmap);
148 cma->count = 0; 145 cma->count = 0;
@@ -152,41 +149,6 @@ err:
152static int __init cma_init_reserved_areas(void) 149static int __init cma_init_reserved_areas(void)
153{ 150{
154 int i; 151 int i;
155 struct zone *zone;
156 pg_data_t *pgdat;
157
158 if (!cma_area_count)
159 return 0;
160
161 for_each_online_pgdat(pgdat) {
162 unsigned long start_pfn = UINT_MAX, end_pfn = 0;
163
164 zone = &pgdat->node_zones[ZONE_MOVABLE];
165
166 /*
167 * In this case, we cannot adjust the zone range
168 * since it is now maximum node span and we don't
169 * know original zone range.
170 */
171 if (populated_zone(zone))
172 continue;
173
174 for (i = 0; i < cma_area_count; i++) {
175 if (pfn_to_nid(cma_areas[i].base_pfn) !=
176 pgdat->node_id)
177 continue;
178
179 start_pfn = min(start_pfn, cma_areas[i].base_pfn);
180 end_pfn = max(end_pfn, cma_areas[i].base_pfn +
181 cma_areas[i].count);
182 }
183
184 if (!end_pfn)
185 continue;
186
187 zone->zone_start_pfn = start_pfn;
188 zone->spanned_pages = end_pfn - start_pfn;
189 }
190 152
191 for (i = 0; i < cma_area_count; i++) { 153 for (i = 0; i < cma_area_count; i++) {
192 int ret = cma_activate_area(&cma_areas[i]); 154 int ret = cma_activate_area(&cma_areas[i]);
@@ -195,32 +157,9 @@ static int __init cma_init_reserved_areas(void)
195 return ret; 157 return ret;
196 } 158 }
197 159
198 /*
199 * Reserved pages for ZONE_MOVABLE are now activated and
200 * this would change ZONE_MOVABLE's managed page counter and
201 * the other zones' present counter. We need to re-calculate
202 * various zone information that depends on this initialization.
203 */
204 build_all_zonelists(NULL);
205 for_each_populated_zone(zone) {
206 if (zone_idx(zone) == ZONE_MOVABLE) {
207 zone_pcp_reset(zone);
208 setup_zone_pageset(zone);
209 } else
210 zone_pcp_update(zone);
211
212 set_zone_contiguous(zone);
213 }
214
215 /*
216 * We need to re-init per zone wmark by calling
217 * init_per_zone_wmark_min() but doesn't call here because it is
218 * registered on core_initcall and it will be called later than us.
219 */
220
221 return 0; 160 return 0;
222} 161}
223pure_initcall(cma_init_reserved_areas); 162core_initcall(cma_init_reserved_areas);
224 163
225/** 164/**
226 * cma_init_reserved_mem() - create custom contiguous area from reserved memory 165 * cma_init_reserved_mem() - create custom contiguous area from reserved memory
diff --git a/mm/compaction.c b/mm/compaction.c
index 028b7210a669..29bd1df18b98 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -1450,12 +1450,14 @@ static enum compact_result __compaction_suitable(struct zone *zone, int order,
1450 * if compaction succeeds. 1450 * if compaction succeeds.
1451 * For costly orders, we require low watermark instead of min for 1451 * For costly orders, we require low watermark instead of min for
1452 * compaction to proceed to increase its chances. 1452 * compaction to proceed to increase its chances.
1453 * ALLOC_CMA is used, as pages in CMA pageblocks are considered
1454 * suitable migration targets
1453 */ 1455 */
1454 watermark = (order > PAGE_ALLOC_COSTLY_ORDER) ? 1456 watermark = (order > PAGE_ALLOC_COSTLY_ORDER) ?
1455 low_wmark_pages(zone) : min_wmark_pages(zone); 1457 low_wmark_pages(zone) : min_wmark_pages(zone);
1456 watermark += compact_gap(order); 1458 watermark += compact_gap(order);
1457 if (!__zone_watermark_ok(zone, 0, watermark, classzone_idx, 1459 if (!__zone_watermark_ok(zone, 0, watermark, classzone_idx,
1458 0, wmark_target)) 1460 ALLOC_CMA, wmark_target))
1459 return COMPACT_SKIPPED; 1461 return COMPACT_SKIPPED;
1460 1462
1461 return COMPACT_CONTINUE; 1463 return COMPACT_CONTINUE;
diff --git a/mm/internal.h b/mm/internal.h
index 62d8c34e63d5..502d14189794 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -168,9 +168,6 @@ extern void post_alloc_hook(struct page *page, unsigned int order,
168 gfp_t gfp_flags); 168 gfp_t gfp_flags);
169extern int user_min_free_kbytes; 169extern int user_min_free_kbytes;
170 170
171extern void set_zone_contiguous(struct zone *zone);
172extern void clear_zone_contiguous(struct zone *zone);
173
174#if defined CONFIG_COMPACTION || defined CONFIG_CMA 171#if defined CONFIG_COMPACTION || defined CONFIG_CMA
175 172
176/* 173/*
@@ -498,6 +495,7 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone,
498#define ALLOC_HARDER 0x10 /* try to alloc harder */ 495#define ALLOC_HARDER 0x10 /* try to alloc harder */
499#define ALLOC_HIGH 0x20 /* __GFP_HIGH set */ 496#define ALLOC_HIGH 0x20 /* __GFP_HIGH set */
500#define ALLOC_CPUSET 0x40 /* check for correct cpuset */ 497#define ALLOC_CPUSET 0x40 /* check for correct cpuset */
498#define ALLOC_CMA 0x80 /* allow allocations from CMA areas */
501 499
502enum ttu_flags; 500enum ttu_flags;
503struct tlbflush_unmap_batch; 501struct tlbflush_unmap_batch;
diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c
index bc0e68f7dc75..f185455b3406 100644
--- a/mm/kasan/kasan.c
+++ b/mm/kasan/kasan.c
@@ -792,6 +792,40 @@ DEFINE_ASAN_SET_SHADOW(f5);
792DEFINE_ASAN_SET_SHADOW(f8); 792DEFINE_ASAN_SET_SHADOW(f8);
793 793
794#ifdef CONFIG_MEMORY_HOTPLUG 794#ifdef CONFIG_MEMORY_HOTPLUG
795static bool shadow_mapped(unsigned long addr)
796{
797 pgd_t *pgd = pgd_offset_k(addr);
798 p4d_t *p4d;
799 pud_t *pud;
800 pmd_t *pmd;
801 pte_t *pte;
802
803 if (pgd_none(*pgd))
804 return false;
805 p4d = p4d_offset(pgd, addr);
806 if (p4d_none(*p4d))
807 return false;
808 pud = pud_offset(p4d, addr);
809 if (pud_none(*pud))
810 return false;
811
812 /*
813 * We can't use pud_large() or pud_huge(), the first one is
814 * arch-specific, the last one depends on HUGETLB_PAGE. So let's abuse
815 * pud_bad(), if pud is bad then it's bad because it's huge.
816 */
817 if (pud_bad(*pud))
818 return true;
819 pmd = pmd_offset(pud, addr);
820 if (pmd_none(*pmd))
821 return false;
822
823 if (pmd_bad(*pmd))
824 return true;
825 pte = pte_offset_kernel(pmd, addr);
826 return !pte_none(*pte);
827}
828
795static int __meminit kasan_mem_notifier(struct notifier_block *nb, 829static int __meminit kasan_mem_notifier(struct notifier_block *nb,
796 unsigned long action, void *data) 830 unsigned long action, void *data)
797{ 831{
@@ -813,6 +847,14 @@ static int __meminit kasan_mem_notifier(struct notifier_block *nb,
813 case MEM_GOING_ONLINE: { 847 case MEM_GOING_ONLINE: {
814 void *ret; 848 void *ret;
815 849
850 /*
851 * If shadow is mapped already than it must have been mapped
852 * during the boot. This could happen if we onlining previously
853 * offlined memory.
854 */
855 if (shadow_mapped(shadow_start))
856 return NOTIFY_OK;
857
816 ret = __vmalloc_node_range(shadow_size, PAGE_SIZE, shadow_start, 858 ret = __vmalloc_node_range(shadow_size, PAGE_SIZE, shadow_start,
817 shadow_end, GFP_KERNEL, 859 shadow_end, GFP_KERNEL,
818 PAGE_KERNEL, VM_NO_GUARD, 860 PAGE_KERNEL, VM_NO_GUARD,
@@ -824,8 +866,26 @@ static int __meminit kasan_mem_notifier(struct notifier_block *nb,
824 kmemleak_ignore(ret); 866 kmemleak_ignore(ret);
825 return NOTIFY_OK; 867 return NOTIFY_OK;
826 } 868 }
827 case MEM_OFFLINE: 869 case MEM_CANCEL_ONLINE:
828 vfree((void *)shadow_start); 870 case MEM_OFFLINE: {
871 struct vm_struct *vm;
872
873 /*
874 * shadow_start was either mapped during boot by kasan_init()
875 * or during memory online by __vmalloc_node_range().
876 * In the latter case we can use vfree() to free shadow.
877 * Non-NULL result of the find_vm_area() will tell us if
878 * that was the second case.
879 *
880 * Currently it's not possible to free shadow mapped
881 * during boot by kasan_init(). It's because the code
882 * to do that hasn't been written yet. So we'll just
883 * leak the memory.
884 */
885 vm = find_vm_area((void *)shadow_start);
886 if (vm)
887 vfree((void *)shadow_start);
888 }
829 } 889 }
830 890
831 return NOTIFY_OK; 891 return NOTIFY_OK;
@@ -838,5 +898,5 @@ static int __init kasan_memhotplug_init(void)
838 return 0; 898 return 0;
839} 899}
840 900
841module_init(kasan_memhotplug_init); 901core_initcall(kasan_memhotplug_init);
842#endif 902#endif
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index f74826cdceea..25982467800b 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1158,7 +1158,7 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online)
1158 * nodes have to go through register_node. 1158 * nodes have to go through register_node.
1159 * TODO clean up this mess. 1159 * TODO clean up this mess.
1160 */ 1160 */
1161 ret = link_mem_sections(nid, start_pfn, nr_pages); 1161 ret = link_mem_sections(nid, start_pfn, nr_pages, false);
1162register_fail: 1162register_fail:
1163 /* 1163 /*
1164 * If sysfs file of new node can't create, cpu on the node 1164 * If sysfs file of new node can't create, cpu on the node
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 905db9d7962f..22320ea27489 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1743,38 +1743,16 @@ void __init page_alloc_init_late(void)
1743} 1743}
1744 1744
1745#ifdef CONFIG_CMA 1745#ifdef CONFIG_CMA
1746static void __init adjust_present_page_count(struct page *page, long count)
1747{
1748 struct zone *zone = page_zone(page);
1749
1750 /* We don't need to hold a lock since it is boot-up process */
1751 zone->present_pages += count;
1752}
1753
1754/* Free whole pageblock and set its migration type to MIGRATE_CMA. */ 1746/* Free whole pageblock and set its migration type to MIGRATE_CMA. */
1755void __init init_cma_reserved_pageblock(struct page *page) 1747void __init init_cma_reserved_pageblock(struct page *page)
1756{ 1748{
1757 unsigned i = pageblock_nr_pages; 1749 unsigned i = pageblock_nr_pages;
1758 unsigned long pfn = page_to_pfn(page);
1759 struct page *p = page; 1750 struct page *p = page;
1760 int nid = page_to_nid(page);
1761
1762 /*
1763 * ZONE_MOVABLE will steal present pages from other zones by
1764 * changing page links so page_zone() is changed. Before that,
1765 * we need to adjust previous zone's page count first.
1766 */
1767 adjust_present_page_count(page, -pageblock_nr_pages);
1768 1751
1769 do { 1752 do {
1770 __ClearPageReserved(p); 1753 __ClearPageReserved(p);
1771 set_page_count(p, 0); 1754 set_page_count(p, 0);
1772 1755 } while (++p, --i);
1773 /* Steal pages from other zones */
1774 set_page_links(p, ZONE_MOVABLE, nid, pfn);
1775 } while (++p, ++pfn, --i);
1776
1777 adjust_present_page_count(page, pageblock_nr_pages);
1778 1756
1779 set_pageblock_migratetype(page, MIGRATE_CMA); 1757 set_pageblock_migratetype(page, MIGRATE_CMA);
1780 1758
@@ -2889,7 +2867,7 @@ int __isolate_free_page(struct page *page, unsigned int order)
2889 * exists. 2867 * exists.
2890 */ 2868 */
2891 watermark = min_wmark_pages(zone) + (1UL << order); 2869 watermark = min_wmark_pages(zone) + (1UL << order);
2892 if (!zone_watermark_ok(zone, 0, watermark, 0, 0)) 2870 if (!zone_watermark_ok(zone, 0, watermark, 0, ALLOC_CMA))
2893 return 0; 2871 return 0;
2894 2872
2895 __mod_zone_freepage_state(zone, -(1UL << order), mt); 2873 __mod_zone_freepage_state(zone, -(1UL << order), mt);
@@ -3165,6 +3143,12 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark,
3165 } 3143 }
3166 3144
3167 3145
3146#ifdef CONFIG_CMA
3147 /* If allocation can't use CMA areas don't use free CMA pages */
3148 if (!(alloc_flags & ALLOC_CMA))
3149 free_pages -= zone_page_state(z, NR_FREE_CMA_PAGES);
3150#endif
3151
3168 /* 3152 /*
3169 * Check watermarks for an order-0 allocation request. If these 3153 * Check watermarks for an order-0 allocation request. If these
3170 * are not met, then a high-order request also cannot go ahead 3154 * are not met, then a high-order request also cannot go ahead
@@ -3191,8 +3175,10 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark,
3191 } 3175 }
3192 3176
3193#ifdef CONFIG_CMA 3177#ifdef CONFIG_CMA
3194 if (!list_empty(&area->free_list[MIGRATE_CMA])) 3178 if ((alloc_flags & ALLOC_CMA) &&
3179 !list_empty(&area->free_list[MIGRATE_CMA])) {
3195 return true; 3180 return true;
3181 }
3196#endif 3182#endif
3197 if (alloc_harder && 3183 if (alloc_harder &&
3198 !list_empty(&area->free_list[MIGRATE_HIGHATOMIC])) 3184 !list_empty(&area->free_list[MIGRATE_HIGHATOMIC]))
@@ -3212,6 +3198,13 @@ static inline bool zone_watermark_fast(struct zone *z, unsigned int order,
3212 unsigned long mark, int classzone_idx, unsigned int alloc_flags) 3198 unsigned long mark, int classzone_idx, unsigned int alloc_flags)
3213{ 3199{
3214 long free_pages = zone_page_state(z, NR_FREE_PAGES); 3200 long free_pages = zone_page_state(z, NR_FREE_PAGES);
3201 long cma_pages = 0;
3202
3203#ifdef CONFIG_CMA
3204 /* If allocation can't use CMA areas don't use free CMA pages */
3205 if (!(alloc_flags & ALLOC_CMA))
3206 cma_pages = zone_page_state(z, NR_FREE_CMA_PAGES);
3207#endif
3215 3208
3216 /* 3209 /*
3217 * Fast check for order-0 only. If this fails then the reserves 3210 * Fast check for order-0 only. If this fails then the reserves
@@ -3220,7 +3213,7 @@ static inline bool zone_watermark_fast(struct zone *z, unsigned int order,
3220 * the caller is !atomic then it'll uselessly search the free 3213 * the caller is !atomic then it'll uselessly search the free
3221 * list. That corner case is then slower but it is harmless. 3214 * list. That corner case is then slower but it is harmless.
3222 */ 3215 */
3223 if (!order && free_pages > mark + z->lowmem_reserve[classzone_idx]) 3216 if (!order && (free_pages - cma_pages) > mark + z->lowmem_reserve[classzone_idx])
3224 return true; 3217 return true;
3225 3218
3226 return __zone_watermark_ok(z, order, mark, classzone_idx, alloc_flags, 3219 return __zone_watermark_ok(z, order, mark, classzone_idx, alloc_flags,
@@ -3856,6 +3849,10 @@ gfp_to_alloc_flags(gfp_t gfp_mask)
3856 } else if (unlikely(rt_task(current)) && !in_interrupt()) 3849 } else if (unlikely(rt_task(current)) && !in_interrupt())
3857 alloc_flags |= ALLOC_HARDER; 3850 alloc_flags |= ALLOC_HARDER;
3858 3851
3852#ifdef CONFIG_CMA
3853 if (gfpflags_to_migratetype(gfp_mask) == MIGRATE_MOVABLE)
3854 alloc_flags |= ALLOC_CMA;
3855#endif
3859 return alloc_flags; 3856 return alloc_flags;
3860} 3857}
3861 3858
@@ -4322,6 +4319,9 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order,
4322 if (should_fail_alloc_page(gfp_mask, order)) 4319 if (should_fail_alloc_page(gfp_mask, order))
4323 return false; 4320 return false;
4324 4321
4322 if (IS_ENABLED(CONFIG_CMA) && ac->migratetype == MIGRATE_MOVABLE)
4323 *alloc_flags |= ALLOC_CMA;
4324
4325 return true; 4325 return true;
4326} 4326}
4327 4327
@@ -6204,7 +6204,6 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat)
6204{ 6204{
6205 enum zone_type j; 6205 enum zone_type j;
6206 int nid = pgdat->node_id; 6206 int nid = pgdat->node_id;
6207 unsigned long node_end_pfn = 0;
6208 6207
6209 pgdat_resize_init(pgdat); 6208 pgdat_resize_init(pgdat);
6210#ifdef CONFIG_NUMA_BALANCING 6209#ifdef CONFIG_NUMA_BALANCING
@@ -6232,13 +6231,9 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat)
6232 struct zone *zone = pgdat->node_zones + j; 6231 struct zone *zone = pgdat->node_zones + j;
6233 unsigned long size, realsize, freesize, memmap_pages; 6232 unsigned long size, realsize, freesize, memmap_pages;
6234 unsigned long zone_start_pfn = zone->zone_start_pfn; 6233 unsigned long zone_start_pfn = zone->zone_start_pfn;
6235 unsigned long movable_size = 0;
6236 6234
6237 size = zone->spanned_pages; 6235 size = zone->spanned_pages;
6238 realsize = freesize = zone->present_pages; 6236 realsize = freesize = zone->present_pages;
6239 if (zone_end_pfn(zone) > node_end_pfn)
6240 node_end_pfn = zone_end_pfn(zone);
6241
6242 6237
6243 /* 6238 /*
6244 * Adjust freesize so that it accounts for how much memory 6239 * Adjust freesize so that it accounts for how much memory
@@ -6287,30 +6282,12 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat)
6287 zone_seqlock_init(zone); 6282 zone_seqlock_init(zone);
6288 zone_pcp_init(zone); 6283 zone_pcp_init(zone);
6289 6284
6290 /* 6285 if (!size)
6291 * The size of the CMA area is unknown now so we need to
6292 * prepare the memory for the usemap at maximum.
6293 */
6294 if (IS_ENABLED(CONFIG_CMA) && j == ZONE_MOVABLE &&
6295 pgdat->node_spanned_pages) {
6296 movable_size = node_end_pfn - pgdat->node_start_pfn;
6297 }
6298
6299 if (!size && !movable_size)
6300 continue; 6286 continue;
6301 6287
6302 set_pageblock_order(); 6288 set_pageblock_order();
6303 if (movable_size) { 6289 setup_usemap(pgdat, zone, zone_start_pfn, size);
6304 zone->zone_start_pfn = pgdat->node_start_pfn; 6290 init_currently_empty_zone(zone, zone_start_pfn, size);
6305 zone->spanned_pages = movable_size;
6306 setup_usemap(pgdat, zone,
6307 pgdat->node_start_pfn, movable_size);
6308 init_currently_empty_zone(zone,
6309 pgdat->node_start_pfn, movable_size);
6310 } else {
6311 setup_usemap(pgdat, zone, zone_start_pfn, size);
6312 init_currently_empty_zone(zone, zone_start_pfn, size);
6313 }
6314 memmap_init(size, nid, j, zone_start_pfn); 6291 memmap_init(size, nid, j, zone_start_pfn);
6315 } 6292 }
6316} 6293}
@@ -7621,11 +7598,12 @@ bool has_unmovable_pages(struct zone *zone, struct page *page, int count,
7621 unsigned long pfn, iter, found; 7598 unsigned long pfn, iter, found;
7622 7599
7623 /* 7600 /*
7624 * For avoiding noise data, lru_add_drain_all() should be called 7601 * TODO we could make this much more efficient by not checking every
7625 * If ZONE_MOVABLE, the zone never contains unmovable pages 7602 * page in the range if we know all of them are in MOVABLE_ZONE and
7603 * that the movable zone guarantees that pages are migratable but
7604 * the later is not the case right now unfortunatelly. E.g. movablecore
7605 * can still lead to having bootmem allocations in zone_movable.
7626 */ 7606 */
7627 if (zone_idx(zone) == ZONE_MOVABLE)
7628 return false;
7629 7607
7630 /* 7608 /*
7631 * CMA allocations (alloc_contig_range) really need to mark isolate 7609 * CMA allocations (alloc_contig_range) really need to mark isolate
@@ -7646,7 +7624,7 @@ bool has_unmovable_pages(struct zone *zone, struct page *page, int count,
7646 page = pfn_to_page(check); 7624 page = pfn_to_page(check);
7647 7625
7648 if (PageReserved(page)) 7626 if (PageReserved(page))
7649 return true; 7627 goto unmovable;
7650 7628
7651 /* 7629 /*
7652 * Hugepages are not in LRU lists, but they're movable. 7630 * Hugepages are not in LRU lists, but they're movable.
@@ -7696,9 +7674,12 @@ bool has_unmovable_pages(struct zone *zone, struct page *page, int count,
7696 * page at boot. 7674 * page at boot.
7697 */ 7675 */
7698 if (found > count) 7676 if (found > count)
7699 return true; 7677 goto unmovable;
7700 } 7678 }
7701 return false; 7679 return false;
7680unmovable:
7681 WARN_ON_ONCE(zone_idx(zone) == ZONE_MOVABLE);
7682 return true;
7702} 7683}
7703 7684
7704bool is_pageblock_removable_nolock(struct page *page) 7685bool is_pageblock_removable_nolock(struct page *page)
@@ -7951,7 +7932,7 @@ void free_contig_range(unsigned long pfn, unsigned nr_pages)
7951} 7932}
7952#endif 7933#endif
7953 7934
7954#if defined CONFIG_MEMORY_HOTPLUG || defined CONFIG_CMA 7935#ifdef CONFIG_MEMORY_HOTPLUG
7955/* 7936/*
7956 * The zone indicated has a new number of managed_pages; batch sizes and percpu 7937 * The zone indicated has a new number of managed_pages; batch sizes and percpu
7957 * page high values need to be recalulated. 7938 * page high values need to be recalulated.
diff --git a/mm/swapfile.c b/mm/swapfile.c
index cc2cf04d9018..78a015fcec3b 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3112,6 +3112,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
3112 unsigned long *frontswap_map = NULL; 3112 unsigned long *frontswap_map = NULL;
3113 struct page *page = NULL; 3113 struct page *page = NULL;
3114 struct inode *inode = NULL; 3114 struct inode *inode = NULL;
3115 bool inced_nr_rotate_swap = false;
3115 3116
3116 if (swap_flags & ~SWAP_FLAGS_VALID) 3117 if (swap_flags & ~SWAP_FLAGS_VALID)
3117 return -EINVAL; 3118 return -EINVAL;
@@ -3215,8 +3216,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
3215 cluster = per_cpu_ptr(p->percpu_cluster, cpu); 3216 cluster = per_cpu_ptr(p->percpu_cluster, cpu);
3216 cluster_set_null(&cluster->index); 3217 cluster_set_null(&cluster->index);
3217 } 3218 }
3218 } else 3219 } else {
3219 atomic_inc(&nr_rotate_swap); 3220 atomic_inc(&nr_rotate_swap);
3221 inced_nr_rotate_swap = true;
3222 }
3220 3223
3221 error = swap_cgroup_swapon(p->type, maxpages); 3224 error = swap_cgroup_swapon(p->type, maxpages);
3222 if (error) 3225 if (error)
@@ -3307,6 +3310,8 @@ bad_swap:
3307 vfree(swap_map); 3310 vfree(swap_map);
3308 kvfree(cluster_info); 3311 kvfree(cluster_info);
3309 kvfree(frontswap_map); 3312 kvfree(frontswap_map);
3313 if (inced_nr_rotate_swap)
3314 atomic_dec(&nr_rotate_swap);
3310 if (swap_file) { 3315 if (swap_file) {
3311 if (inode && S_ISREG(inode->i_mode)) { 3316 if (inode && S_ISREG(inode->i_mode)) {
3312 inode_unlock(inode); 3317 inode_unlock(inode);
diff --git a/net/9p/Kconfig b/net/9p/Kconfig
index e6014e0e51f7..46c39f7da444 100644
--- a/net/9p/Kconfig
+++ b/net/9p/Kconfig
@@ -32,7 +32,7 @@ config NET_9P_XEN
32 32
33 33
34config NET_9P_RDMA 34config NET_9P_RDMA
35 depends on INET && INFINIBAND && INFINIBAND_ADDR_TRANS 35 depends on INET && INFINIBAND_ADDR_TRANS
36 tristate "9P RDMA Transport (Experimental)" 36 tristate "9P RDMA Transport (Experimental)"
37 help 37 help
38 This builds support for an RDMA transport. 38 This builds support for an RDMA transport.
diff --git a/net/batman-adv/multicast.c b/net/batman-adv/multicast.c
index a11d3d89f012..a35f597e8c8b 100644
--- a/net/batman-adv/multicast.c
+++ b/net/batman-adv/multicast.c
@@ -1536,7 +1536,7 @@ out:
1536 1536
1537 if (!ret && primary_if) 1537 if (!ret && primary_if)
1538 *primary_if = hard_iface; 1538 *primary_if = hard_iface;
1539 else 1539 else if (hard_iface)
1540 batadv_hardif_put(hard_iface); 1540 batadv_hardif_put(hard_iface);
1541 1541
1542 return ret; 1542 return ret;
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 0225616d5771..3986551397ca 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -862,7 +862,7 @@ batadv_tt_prepare_tvlv_global_data(struct batadv_orig_node *orig_node,
862 struct batadv_orig_node_vlan *vlan; 862 struct batadv_orig_node_vlan *vlan;
863 u8 *tt_change_ptr; 863 u8 *tt_change_ptr;
864 864
865 rcu_read_lock(); 865 spin_lock_bh(&orig_node->vlan_list_lock);
866 hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) { 866 hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) {
867 num_vlan++; 867 num_vlan++;
868 num_entries += atomic_read(&vlan->tt.num_entries); 868 num_entries += atomic_read(&vlan->tt.num_entries);
@@ -900,7 +900,7 @@ batadv_tt_prepare_tvlv_global_data(struct batadv_orig_node *orig_node,
900 *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr; 900 *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr;
901 901
902out: 902out:
903 rcu_read_unlock(); 903 spin_unlock_bh(&orig_node->vlan_list_lock);
904 return tvlv_len; 904 return tvlv_len;
905} 905}
906 906
@@ -931,15 +931,20 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,
931 struct batadv_tvlv_tt_vlan_data *tt_vlan; 931 struct batadv_tvlv_tt_vlan_data *tt_vlan;
932 struct batadv_softif_vlan *vlan; 932 struct batadv_softif_vlan *vlan;
933 u16 num_vlan = 0; 933 u16 num_vlan = 0;
934 u16 num_entries = 0; 934 u16 vlan_entries = 0;
935 u16 total_entries = 0;
935 u16 tvlv_len; 936 u16 tvlv_len;
936 u8 *tt_change_ptr; 937 u8 *tt_change_ptr;
937 int change_offset; 938 int change_offset;
938 939
939 rcu_read_lock(); 940 spin_lock_bh(&bat_priv->softif_vlan_list_lock);
940 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) { 941 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
942 vlan_entries = atomic_read(&vlan->tt.num_entries);
943 if (vlan_entries < 1)
944 continue;
945
941 num_vlan++; 946 num_vlan++;
942 num_entries += atomic_read(&vlan->tt.num_entries); 947 total_entries += vlan_entries;
943 } 948 }
944 949
945 change_offset = sizeof(**tt_data); 950 change_offset = sizeof(**tt_data);
@@ -947,7 +952,7 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,
947 952
948 /* if tt_len is negative, allocate the space needed by the full table */ 953 /* if tt_len is negative, allocate the space needed by the full table */
949 if (*tt_len < 0) 954 if (*tt_len < 0)
950 *tt_len = batadv_tt_len(num_entries); 955 *tt_len = batadv_tt_len(total_entries);
951 956
952 tvlv_len = *tt_len; 957 tvlv_len = *tt_len;
953 tvlv_len += change_offset; 958 tvlv_len += change_offset;
@@ -964,6 +969,10 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,
964 969
965 tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data + 1); 970 tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data + 1);
966 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) { 971 hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
972 vlan_entries = atomic_read(&vlan->tt.num_entries);
973 if (vlan_entries < 1)
974 continue;
975
967 tt_vlan->vid = htons(vlan->vid); 976 tt_vlan->vid = htons(vlan->vid);
968 tt_vlan->crc = htonl(vlan->tt.crc); 977 tt_vlan->crc = htonl(vlan->tt.crc);
969 978
@@ -974,7 +983,7 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,
974 *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr; 983 *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr;
975 984
976out: 985out:
977 rcu_read_unlock(); 986 spin_unlock_bh(&bat_priv->softif_vlan_list_lock);
978 return tvlv_len; 987 return tvlv_len;
979} 988}
980 989
@@ -1538,6 +1547,8 @@ batadv_tt_global_orig_entry_find(const struct batadv_tt_global_entry *entry,
1538 * handled by a given originator 1547 * handled by a given originator
1539 * @entry: the TT global entry to check 1548 * @entry: the TT global entry to check
1540 * @orig_node: the originator to search in the list 1549 * @orig_node: the originator to search in the list
1550 * @flags: a pointer to store TT flags for the given @entry received
1551 * from @orig_node
1541 * 1552 *
1542 * find out if an orig_node is already in the list of a tt_global_entry. 1553 * find out if an orig_node is already in the list of a tt_global_entry.
1543 * 1554 *
@@ -1545,7 +1556,8 @@ batadv_tt_global_orig_entry_find(const struct batadv_tt_global_entry *entry,
1545 */ 1556 */
1546static bool 1557static bool
1547batadv_tt_global_entry_has_orig(const struct batadv_tt_global_entry *entry, 1558batadv_tt_global_entry_has_orig(const struct batadv_tt_global_entry *entry,
1548 const struct batadv_orig_node *orig_node) 1559 const struct batadv_orig_node *orig_node,
1560 u8 *flags)
1549{ 1561{
1550 struct batadv_tt_orig_list_entry *orig_entry; 1562 struct batadv_tt_orig_list_entry *orig_entry;
1551 bool found = false; 1563 bool found = false;
@@ -1553,6 +1565,10 @@ batadv_tt_global_entry_has_orig(const struct batadv_tt_global_entry *entry,
1553 orig_entry = batadv_tt_global_orig_entry_find(entry, orig_node); 1565 orig_entry = batadv_tt_global_orig_entry_find(entry, orig_node);
1554 if (orig_entry) { 1566 if (orig_entry) {
1555 found = true; 1567 found = true;
1568
1569 if (flags)
1570 *flags = orig_entry->flags;
1571
1556 batadv_tt_orig_list_entry_put(orig_entry); 1572 batadv_tt_orig_list_entry_put(orig_entry);
1557 } 1573 }
1558 1574
@@ -1731,7 +1747,7 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
1731 if (!(common->flags & BATADV_TT_CLIENT_TEMP)) 1747 if (!(common->flags & BATADV_TT_CLIENT_TEMP))
1732 goto out; 1748 goto out;
1733 if (batadv_tt_global_entry_has_orig(tt_global_entry, 1749 if (batadv_tt_global_entry_has_orig(tt_global_entry,
1734 orig_node)) 1750 orig_node, NULL))
1735 goto out_remove; 1751 goto out_remove;
1736 batadv_tt_global_del_orig_list(tt_global_entry); 1752 batadv_tt_global_del_orig_list(tt_global_entry);
1737 goto add_orig_entry; 1753 goto add_orig_entry;
@@ -2880,23 +2896,46 @@ unlock:
2880} 2896}
2881 2897
2882/** 2898/**
2883 * batadv_tt_local_valid() - verify that given tt entry is a valid one 2899 * batadv_tt_local_valid() - verify local tt entry and get flags
2884 * @entry_ptr: to be checked local tt entry 2900 * @entry_ptr: to be checked local tt entry
2885 * @data_ptr: not used but definition required to satisfy the callback prototype 2901 * @data_ptr: not used but definition required to satisfy the callback prototype
2902 * @flags: a pointer to store TT flags for this client to
2903 *
2904 * Checks the validity of the given local TT entry. If it is, then the provided
2905 * flags pointer is updated.
2886 * 2906 *
2887 * Return: true if the entry is a valid, false otherwise. 2907 * Return: true if the entry is a valid, false otherwise.
2888 */ 2908 */
2889static bool batadv_tt_local_valid(const void *entry_ptr, const void *data_ptr) 2909static bool batadv_tt_local_valid(const void *entry_ptr,
2910 const void *data_ptr,
2911 u8 *flags)
2890{ 2912{
2891 const struct batadv_tt_common_entry *tt_common_entry = entry_ptr; 2913 const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;
2892 2914
2893 if (tt_common_entry->flags & BATADV_TT_CLIENT_NEW) 2915 if (tt_common_entry->flags & BATADV_TT_CLIENT_NEW)
2894 return false; 2916 return false;
2917
2918 if (flags)
2919 *flags = tt_common_entry->flags;
2920
2895 return true; 2921 return true;
2896} 2922}
2897 2923
2924/**
2925 * batadv_tt_global_valid() - verify global tt entry and get flags
2926 * @entry_ptr: to be checked global tt entry
2927 * @data_ptr: an orig_node object (may be NULL)
2928 * @flags: a pointer to store TT flags for this client to
2929 *
2930 * Checks the validity of the given global TT entry. If it is, then the provided
2931 * flags pointer is updated either with the common (summed) TT flags if data_ptr
2932 * is NULL or the specific, per originator TT flags otherwise.
2933 *
2934 * Return: true if the entry is a valid, false otherwise.
2935 */
2898static bool batadv_tt_global_valid(const void *entry_ptr, 2936static bool batadv_tt_global_valid(const void *entry_ptr,
2899 const void *data_ptr) 2937 const void *data_ptr,
2938 u8 *flags)
2900{ 2939{
2901 const struct batadv_tt_common_entry *tt_common_entry = entry_ptr; 2940 const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;
2902 const struct batadv_tt_global_entry *tt_global_entry; 2941 const struct batadv_tt_global_entry *tt_global_entry;
@@ -2910,7 +2949,8 @@ static bool batadv_tt_global_valid(const void *entry_ptr,
2910 struct batadv_tt_global_entry, 2949 struct batadv_tt_global_entry,
2911 common); 2950 common);
2912 2951
2913 return batadv_tt_global_entry_has_orig(tt_global_entry, orig_node); 2952 return batadv_tt_global_entry_has_orig(tt_global_entry, orig_node,
2953 flags);
2914} 2954}
2915 2955
2916/** 2956/**
@@ -2920,25 +2960,34 @@ static bool batadv_tt_global_valid(const void *entry_ptr,
2920 * @hash: hash table containing the tt entries 2960 * @hash: hash table containing the tt entries
2921 * @tt_len: expected tvlv tt data buffer length in number of bytes 2961 * @tt_len: expected tvlv tt data buffer length in number of bytes
2922 * @tvlv_buff: pointer to the buffer to fill with the TT data 2962 * @tvlv_buff: pointer to the buffer to fill with the TT data
2923 * @valid_cb: function to filter tt change entries 2963 * @valid_cb: function to filter tt change entries and to return TT flags
2924 * @cb_data: data passed to the filter function as argument 2964 * @cb_data: data passed to the filter function as argument
2965 *
2966 * Fills the tvlv buff with the tt entries from the specified hash. If valid_cb
2967 * is not provided then this becomes a no-op.
2925 */ 2968 */
2926static void batadv_tt_tvlv_generate(struct batadv_priv *bat_priv, 2969static void batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,
2927 struct batadv_hashtable *hash, 2970 struct batadv_hashtable *hash,
2928 void *tvlv_buff, u16 tt_len, 2971 void *tvlv_buff, u16 tt_len,
2929 bool (*valid_cb)(const void *, 2972 bool (*valid_cb)(const void *,
2930 const void *), 2973 const void *,
2974 u8 *flags),
2931 void *cb_data) 2975 void *cb_data)
2932{ 2976{
2933 struct batadv_tt_common_entry *tt_common_entry; 2977 struct batadv_tt_common_entry *tt_common_entry;
2934 struct batadv_tvlv_tt_change *tt_change; 2978 struct batadv_tvlv_tt_change *tt_change;
2935 struct hlist_head *head; 2979 struct hlist_head *head;
2936 u16 tt_tot, tt_num_entries = 0; 2980 u16 tt_tot, tt_num_entries = 0;
2981 u8 flags;
2982 bool ret;
2937 u32 i; 2983 u32 i;
2938 2984
2939 tt_tot = batadv_tt_entries(tt_len); 2985 tt_tot = batadv_tt_entries(tt_len);
2940 tt_change = (struct batadv_tvlv_tt_change *)tvlv_buff; 2986 tt_change = (struct batadv_tvlv_tt_change *)tvlv_buff;
2941 2987
2988 if (!valid_cb)
2989 return;
2990
2942 rcu_read_lock(); 2991 rcu_read_lock();
2943 for (i = 0; i < hash->size; i++) { 2992 for (i = 0; i < hash->size; i++) {
2944 head = &hash->table[i]; 2993 head = &hash->table[i];
@@ -2948,11 +2997,12 @@ static void batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,
2948 if (tt_tot == tt_num_entries) 2997 if (tt_tot == tt_num_entries)
2949 break; 2998 break;
2950 2999
2951 if ((valid_cb) && (!valid_cb(tt_common_entry, cb_data))) 3000 ret = valid_cb(tt_common_entry, cb_data, &flags);
3001 if (!ret)
2952 continue; 3002 continue;
2953 3003
2954 ether_addr_copy(tt_change->addr, tt_common_entry->addr); 3004 ether_addr_copy(tt_change->addr, tt_common_entry->addr);
2955 tt_change->flags = tt_common_entry->flags; 3005 tt_change->flags = flags;
2956 tt_change->vid = htons(tt_common_entry->vid); 3006 tt_change->vid = htons(tt_common_entry->vid);
2957 memset(tt_change->reserved, 0, 3007 memset(tt_change->reserved, 0,
2958 sizeof(tt_change->reserved)); 3008 sizeof(tt_change->reserved));
diff --git a/net/bridge/netfilter/ebt_stp.c b/net/bridge/netfilter/ebt_stp.c
index 47ba98db145d..46c1fe7637ea 100644
--- a/net/bridge/netfilter/ebt_stp.c
+++ b/net/bridge/netfilter/ebt_stp.c
@@ -161,8 +161,8 @@ static int ebt_stp_mt_check(const struct xt_mtchk_param *par)
161 /* Make sure the match only receives stp frames */ 161 /* Make sure the match only receives stp frames */
162 if (!par->nft_compat && 162 if (!par->nft_compat &&
163 (!ether_addr_equal(e->destmac, eth_stp_addr) || 163 (!ether_addr_equal(e->destmac, eth_stp_addr) ||
164 !is_broadcast_ether_addr(e->destmsk) || 164 !(e->bitmask & EBT_DESTMAC) ||
165 !(e->bitmask & EBT_DESTMAC))) 165 !is_broadcast_ether_addr(e->destmsk)))
166 return -EINVAL; 166 return -EINVAL;
167 167
168 return 0; 168 return 0;
diff --git a/net/core/dev.c b/net/core/dev.c
index af0558b00c6c..2af787e8b130 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2124,7 +2124,7 @@ static bool remove_xps_queue_cpu(struct net_device *dev,
2124 int i, j; 2124 int i, j;
2125 2125
2126 for (i = count, j = offset; i--; j++) { 2126 for (i = count, j = offset; i--; j++) {
2127 if (!remove_xps_queue(dev_maps, cpu, j)) 2127 if (!remove_xps_queue(dev_maps, tci, j))
2128 break; 2128 break;
2129 } 2129 }
2130 2130
diff --git a/net/core/filter.c b/net/core/filter.c
index e77c30ca491d..201ff36b17a8 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -481,11 +481,18 @@ do_pass:
481 481
482#define BPF_EMIT_JMP \ 482#define BPF_EMIT_JMP \
483 do { \ 483 do { \
484 const s32 off_min = S16_MIN, off_max = S16_MAX; \
485 s32 off; \
486 \
484 if (target >= len || target < 0) \ 487 if (target >= len || target < 0) \
485 goto err; \ 488 goto err; \
486 insn->off = addrs ? addrs[target] - addrs[i] - 1 : 0; \ 489 off = addrs ? addrs[target] - addrs[i] - 1 : 0; \
487 /* Adjust pc relative offset for 2nd or 3rd insn. */ \ 490 /* Adjust pc relative offset for 2nd or 3rd insn. */ \
488 insn->off -= insn - tmp_insns; \ 491 off -= insn - tmp_insns; \
492 /* Reject anything not fitting into insn->off. */ \
493 if (off < off_min || off > off_max) \
494 goto err; \
495 insn->off = off; \
489 } while (0) 496 } while (0)
490 497
491 case BPF_JMP | BPF_JA: 498 case BPF_JMP | BPF_JA:
diff --git a/net/core/sock.c b/net/core/sock.c
index 6444525f610c..3b6d02854e57 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1606,7 +1606,7 @@ static void __sk_free(struct sock *sk)
1606 if (likely(sk->sk_net_refcnt)) 1606 if (likely(sk->sk_net_refcnt))
1607 sock_inuse_add(sock_net(sk), -1); 1607 sock_inuse_add(sock_net(sk), -1);
1608 1608
1609 if (unlikely(sock_diag_has_destroy_listeners(sk) && sk->sk_net_refcnt)) 1609 if (unlikely(sk->sk_net_refcnt && sock_diag_has_destroy_listeners(sk)))
1610 sock_diag_broadcast_destroy(sk); 1610 sock_diag_broadcast_destroy(sk);
1611 else 1611 else
1612 sk_destruct(sk); 1612 sk_destruct(sk);
diff --git a/net/dccp/proto.c b/net/dccp/proto.c
index 84cd4e3fd01b..0d56e36a6db7 100644
--- a/net/dccp/proto.c
+++ b/net/dccp/proto.c
@@ -283,9 +283,7 @@ int dccp_disconnect(struct sock *sk, int flags)
283 283
284 dccp_clear_xmit_timers(sk); 284 dccp_clear_xmit_timers(sk);
285 ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk); 285 ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
286 ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
287 dp->dccps_hc_rx_ccid = NULL; 286 dp->dccps_hc_rx_ccid = NULL;
288 dp->dccps_hc_tx_ccid = NULL;
289 287
290 __skb_queue_purge(&sk->sk_receive_queue); 288 __skb_queue_purge(&sk->sk_receive_queue);
291 __skb_queue_purge(&sk->sk_write_queue); 289 __skb_queue_purge(&sk->sk_write_queue);
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index adf50fbc4c13..47725250b4ca 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -258,11 +258,13 @@ static void dsa_tree_teardown_default_cpu(struct dsa_switch_tree *dst)
258static int dsa_port_setup(struct dsa_port *dp) 258static int dsa_port_setup(struct dsa_port *dp)
259{ 259{
260 struct dsa_switch *ds = dp->ds; 260 struct dsa_switch *ds = dp->ds;
261 int err; 261 int err = 0;
262 262
263 memset(&dp->devlink_port, 0, sizeof(dp->devlink_port)); 263 memset(&dp->devlink_port, 0, sizeof(dp->devlink_port));
264 264
265 err = devlink_port_register(ds->devlink, &dp->devlink_port, dp->index); 265 if (dp->type != DSA_PORT_TYPE_UNUSED)
266 err = devlink_port_register(ds->devlink, &dp->devlink_port,
267 dp->index);
266 if (err) 268 if (err)
267 return err; 269 return err;
268 270
@@ -293,7 +295,8 @@ static int dsa_port_setup(struct dsa_port *dp)
293 295
294static void dsa_port_teardown(struct dsa_port *dp) 296static void dsa_port_teardown(struct dsa_port *dp)
295{ 297{
296 devlink_port_unregister(&dp->devlink_port); 298 if (dp->type != DSA_PORT_TYPE_UNUSED)
299 devlink_port_unregister(&dp->devlink_port);
297 300
298 switch (dp->type) { 301 switch (dp->type) {
299 case DSA_PORT_TYPE_UNUSED: 302 case DSA_PORT_TYPE_UNUSED:
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index f05afaf3235c..e66172aaf241 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -326,10 +326,11 @@ static int __fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,
326 u8 tos, int oif, struct net_device *dev, 326 u8 tos, int oif, struct net_device *dev,
327 int rpf, struct in_device *idev, u32 *itag) 327 int rpf, struct in_device *idev, u32 *itag)
328{ 328{
329 struct net *net = dev_net(dev);
330 struct flow_keys flkeys;
329 int ret, no_addr; 331 int ret, no_addr;
330 struct fib_result res; 332 struct fib_result res;
331 struct flowi4 fl4; 333 struct flowi4 fl4;
332 struct net *net = dev_net(dev);
333 bool dev_match; 334 bool dev_match;
334 335
335 fl4.flowi4_oif = 0; 336 fl4.flowi4_oif = 0;
@@ -347,6 +348,11 @@ static int __fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,
347 no_addr = idev->ifa_list == NULL; 348 no_addr = idev->ifa_list == NULL;
348 349
349 fl4.flowi4_mark = IN_DEV_SRC_VMARK(idev) ? skb->mark : 0; 350 fl4.flowi4_mark = IN_DEV_SRC_VMARK(idev) ? skb->mark : 0;
351 if (!fib4_rules_early_flow_dissect(net, skb, &fl4, &flkeys)) {
352 fl4.flowi4_proto = 0;
353 fl4.fl4_sport = 0;
354 fl4.fl4_dport = 0;
355 }
350 356
351 trace_fib_validate_source(dev, &fl4); 357 trace_fib_validate_source(dev, &fl4);
352 358
@@ -643,6 +649,7 @@ const struct nla_policy rtm_ipv4_policy[RTA_MAX + 1] = {
643 [RTA_ENCAP] = { .type = NLA_NESTED }, 649 [RTA_ENCAP] = { .type = NLA_NESTED },
644 [RTA_UID] = { .type = NLA_U32 }, 650 [RTA_UID] = { .type = NLA_U32 },
645 [RTA_MARK] = { .type = NLA_U32 }, 651 [RTA_MARK] = { .type = NLA_U32 },
652 [RTA_TABLE] = { .type = NLA_U32 },
646}; 653};
647 654
648static int rtm_to_fib_config(struct net *net, struct sk_buff *skb, 655static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 9c169bb2444d..f200b304f76c 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -722,10 +722,12 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,
722 erspan_build_header(skb, ntohl(tunnel->parms.o_key), 722 erspan_build_header(skb, ntohl(tunnel->parms.o_key),
723 tunnel->index, 723 tunnel->index,
724 truncate, true); 724 truncate, true);
725 else 725 else if (tunnel->erspan_ver == 2)
726 erspan_build_header_v2(skb, ntohl(tunnel->parms.o_key), 726 erspan_build_header_v2(skb, ntohl(tunnel->parms.o_key),
727 tunnel->dir, tunnel->hwid, 727 tunnel->dir, tunnel->hwid,
728 truncate, true); 728 truncate, true);
729 else
730 goto free_skb;
729 731
730 tunnel->parms.o_flags &= ~TUNNEL_KEY; 732 tunnel->parms.o_flags &= ~TUNNEL_KEY;
731 __gre_xmit(skb, dev, &tunnel->parms.iph, htons(ETH_P_ERSPAN)); 733 __gre_xmit(skb, dev, &tunnel->parms.iph, htons(ETH_P_ERSPAN));
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 83c73bab2c3d..d54abc097800 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -1045,7 +1045,8 @@ alloc_new_skb:
1045 if (copy > length) 1045 if (copy > length)
1046 copy = length; 1046 copy = length;
1047 1047
1048 if (!(rt->dst.dev->features&NETIF_F_SG)) { 1048 if (!(rt->dst.dev->features&NETIF_F_SG) &&
1049 skb_tailroom(skb) >= copy) {
1049 unsigned int off; 1050 unsigned int off;
1050 1051
1051 off = skb->len; 1052 off = skb->len;
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 5ad2d8ed3a3f..57bbb060faaf 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -505,8 +505,6 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
505 int err; 505 int err;
506 int copied; 506 int copied;
507 507
508 WARN_ON_ONCE(sk->sk_family == AF_INET6);
509
510 err = -EAGAIN; 508 err = -EAGAIN;
511 skb = sock_dequeue_err_skb(sk); 509 skb = sock_dequeue_err_skb(sk);
512 if (!skb) 510 if (!skb)
diff --git a/net/ipv4/ipmr_base.c b/net/ipv4/ipmr_base.c
index 4fe97723b53f..30221701614c 100644
--- a/net/ipv4/ipmr_base.c
+++ b/net/ipv4/ipmr_base.c
@@ -43,7 +43,10 @@ mr_table_alloc(struct net *net, u32 id,
43 write_pnet(&mrt->net, net); 43 write_pnet(&mrt->net, net);
44 44
45 mrt->ops = *ops; 45 mrt->ops = *ops;
46 rhltable_init(&mrt->mfc_hash, mrt->ops.rht_params); 46 if (rhltable_init(&mrt->mfc_hash, mrt->ops.rht_params)) {
47 kfree(mrt);
48 return NULL;
49 }
47 INIT_LIST_HEAD(&mrt->mfc_cache_list); 50 INIT_LIST_HEAD(&mrt->mfc_cache_list);
48 INIT_LIST_HEAD(&mrt->mfc_unres_queue); 51 INIT_LIST_HEAD(&mrt->mfc_unres_queue);
49 52
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index 44b308d93ec2..e85f35b89c49 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -34,6 +34,7 @@
34MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
35MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); 35MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
36MODULE_DESCRIPTION("IPv4 packet filter"); 36MODULE_DESCRIPTION("IPv4 packet filter");
37MODULE_ALIAS("ipt_icmp");
37 38
38void *ipt_alloc_initial_table(const struct xt_table *info) 39void *ipt_alloc_initial_table(const struct xt_table *info)
39{ 40{
diff --git a/net/ipv4/netfilter/ipt_rpfilter.c b/net/ipv4/netfilter/ipt_rpfilter.c
index fd01f13c896a..12843c9ef142 100644
--- a/net/ipv4/netfilter/ipt_rpfilter.c
+++ b/net/ipv4/netfilter/ipt_rpfilter.c
@@ -89,10 +89,10 @@ static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par)
89 return true ^ invert; 89 return true ^ invert;
90 } 90 }
91 91
92 memset(&flow, 0, sizeof(flow));
92 flow.flowi4_iif = LOOPBACK_IFINDEX; 93 flow.flowi4_iif = LOOPBACK_IFINDEX;
93 flow.daddr = iph->saddr; 94 flow.daddr = iph->saddr;
94 flow.saddr = rpfilter_get_saddr(iph->daddr); 95 flow.saddr = rpfilter_get_saddr(iph->daddr);
95 flow.flowi4_oif = 0;
96 flow.flowi4_mark = info->flags & XT_RPFILTER_VALID_MARK ? skb->mark : 0; 96 flow.flowi4_mark = info->flags & XT_RPFILTER_VALID_MARK ? skb->mark : 0;
97 flow.flowi4_tos = RT_TOS(iph->tos); 97 flow.flowi4_tos = RT_TOS(iph->tos);
98 flow.flowi4_scope = RT_SCOPE_UNIVERSE; 98 flow.flowi4_scope = RT_SCOPE_UNIVERSE;
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 29268efad247..2cfa1b518f8d 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1961,8 +1961,13 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1961 fl4.saddr = saddr; 1961 fl4.saddr = saddr;
1962 fl4.flowi4_uid = sock_net_uid(net, NULL); 1962 fl4.flowi4_uid = sock_net_uid(net, NULL);
1963 1963
1964 if (fib4_rules_early_flow_dissect(net, skb, &fl4, &_flkeys)) 1964 if (fib4_rules_early_flow_dissect(net, skb, &fl4, &_flkeys)) {
1965 flkeys = &_flkeys; 1965 flkeys = &_flkeys;
1966 } else {
1967 fl4.flowi4_proto = 0;
1968 fl4.fl4_sport = 0;
1969 fl4.fl4_dport = 0;
1970 }
1966 1971
1967 err = fib_lookup(net, &fl4, res, 0); 1972 err = fib_lookup(net, &fl4, res, 0);
1968 if (err != 0) { 1973 if (err != 0) {
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 383cac0ff0ec..d07e34f8e309 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -2833,8 +2833,10 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)
2833 return -EBUSY; 2833 return -EBUSY;
2834 2834
2835 if (before(TCP_SKB_CB(skb)->seq, tp->snd_una)) { 2835 if (before(TCP_SKB_CB(skb)->seq, tp->snd_una)) {
2836 if (before(TCP_SKB_CB(skb)->end_seq, tp->snd_una)) 2836 if (unlikely(before(TCP_SKB_CB(skb)->end_seq, tp->snd_una))) {
2837 BUG(); 2837 WARN_ON_ONCE(1);
2838 return -EINVAL;
2839 }
2838 if (tcp_trim_head(sk, skb, tp->snd_una - TCP_SKB_CB(skb)->seq)) 2840 if (tcp_trim_head(sk, skb, tp->snd_una - TCP_SKB_CB(skb)->seq))
2839 return -ENOMEM; 2841 return -ENOMEM;
2840 } 2842 }
@@ -3342,6 +3344,7 @@ static void tcp_connect_init(struct sock *sk)
3342 sock_reset_flag(sk, SOCK_DONE); 3344 sock_reset_flag(sk, SOCK_DONE);
3343 tp->snd_wnd = 0; 3345 tp->snd_wnd = 0;
3344 tcp_init_wl(tp, 0); 3346 tcp_init_wl(tp, 0);
3347 tcp_write_queue_purge(sk);
3345 tp->snd_una = tp->write_seq; 3348 tp->snd_una = tp->write_seq;
3346 tp->snd_sml = tp->write_seq; 3349 tp->snd_sml = tp->write_seq;
3347 tp->snd_up = tp->write_seq; 3350 tp->snd_up = tp->write_seq;
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 69727bc168cb..458de353f5d9 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -71,6 +71,7 @@ struct ip6gre_net {
71 struct ip6_tnl __rcu *tunnels[4][IP6_GRE_HASH_SIZE]; 71 struct ip6_tnl __rcu *tunnels[4][IP6_GRE_HASH_SIZE];
72 72
73 struct ip6_tnl __rcu *collect_md_tun; 73 struct ip6_tnl __rcu *collect_md_tun;
74 struct ip6_tnl __rcu *collect_md_tun_erspan;
74 struct net_device *fb_tunnel_dev; 75 struct net_device *fb_tunnel_dev;
75}; 76};
76 77
@@ -81,6 +82,7 @@ static int ip6gre_tunnel_init(struct net_device *dev);
81static void ip6gre_tunnel_setup(struct net_device *dev); 82static void ip6gre_tunnel_setup(struct net_device *dev);
82static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t); 83static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
83static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu); 84static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu);
85static void ip6erspan_tnl_link_config(struct ip6_tnl *t, int set_mtu);
84 86
85/* Tunnel hash table */ 87/* Tunnel hash table */
86 88
@@ -232,7 +234,12 @@ static struct ip6_tnl *ip6gre_tunnel_lookup(struct net_device *dev,
232 if (cand) 234 if (cand)
233 return cand; 235 return cand;
234 236
235 t = rcu_dereference(ign->collect_md_tun); 237 if (gre_proto == htons(ETH_P_ERSPAN) ||
238 gre_proto == htons(ETH_P_ERSPAN2))
239 t = rcu_dereference(ign->collect_md_tun_erspan);
240 else
241 t = rcu_dereference(ign->collect_md_tun);
242
236 if (t && t->dev->flags & IFF_UP) 243 if (t && t->dev->flags & IFF_UP)
237 return t; 244 return t;
238 245
@@ -261,6 +268,31 @@ static struct ip6_tnl __rcu **__ip6gre_bucket(struct ip6gre_net *ign,
261 return &ign->tunnels[prio][h]; 268 return &ign->tunnels[prio][h];
262} 269}
263 270
271static void ip6gre_tunnel_link_md(struct ip6gre_net *ign, struct ip6_tnl *t)
272{
273 if (t->parms.collect_md)
274 rcu_assign_pointer(ign->collect_md_tun, t);
275}
276
277static void ip6erspan_tunnel_link_md(struct ip6gre_net *ign, struct ip6_tnl *t)
278{
279 if (t->parms.collect_md)
280 rcu_assign_pointer(ign->collect_md_tun_erspan, t);
281}
282
283static void ip6gre_tunnel_unlink_md(struct ip6gre_net *ign, struct ip6_tnl *t)
284{
285 if (t->parms.collect_md)
286 rcu_assign_pointer(ign->collect_md_tun, NULL);
287}
288
289static void ip6erspan_tunnel_unlink_md(struct ip6gre_net *ign,
290 struct ip6_tnl *t)
291{
292 if (t->parms.collect_md)
293 rcu_assign_pointer(ign->collect_md_tun_erspan, NULL);
294}
295
264static inline struct ip6_tnl __rcu **ip6gre_bucket(struct ip6gre_net *ign, 296static inline struct ip6_tnl __rcu **ip6gre_bucket(struct ip6gre_net *ign,
265 const struct ip6_tnl *t) 297 const struct ip6_tnl *t)
266{ 298{
@@ -271,9 +303,6 @@ static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t)
271{ 303{
272 struct ip6_tnl __rcu **tp = ip6gre_bucket(ign, t); 304 struct ip6_tnl __rcu **tp = ip6gre_bucket(ign, t);
273 305
274 if (t->parms.collect_md)
275 rcu_assign_pointer(ign->collect_md_tun, t);
276
277 rcu_assign_pointer(t->next, rtnl_dereference(*tp)); 306 rcu_assign_pointer(t->next, rtnl_dereference(*tp));
278 rcu_assign_pointer(*tp, t); 307 rcu_assign_pointer(*tp, t);
279} 308}
@@ -283,9 +312,6 @@ static void ip6gre_tunnel_unlink(struct ip6gre_net *ign, struct ip6_tnl *t)
283 struct ip6_tnl __rcu **tp; 312 struct ip6_tnl __rcu **tp;
284 struct ip6_tnl *iter; 313 struct ip6_tnl *iter;
285 314
286 if (t->parms.collect_md)
287 rcu_assign_pointer(ign->collect_md_tun, NULL);
288
289 for (tp = ip6gre_bucket(ign, t); 315 for (tp = ip6gre_bucket(ign, t);
290 (iter = rtnl_dereference(*tp)) != NULL; 316 (iter = rtnl_dereference(*tp)) != NULL;
291 tp = &iter->next) { 317 tp = &iter->next) {
@@ -374,11 +400,23 @@ failed_free:
374 return NULL; 400 return NULL;
375} 401}
376 402
403static void ip6erspan_tunnel_uninit(struct net_device *dev)
404{
405 struct ip6_tnl *t = netdev_priv(dev);
406 struct ip6gre_net *ign = net_generic(t->net, ip6gre_net_id);
407
408 ip6erspan_tunnel_unlink_md(ign, t);
409 ip6gre_tunnel_unlink(ign, t);
410 dst_cache_reset(&t->dst_cache);
411 dev_put(dev);
412}
413
377static void ip6gre_tunnel_uninit(struct net_device *dev) 414static void ip6gre_tunnel_uninit(struct net_device *dev)
378{ 415{
379 struct ip6_tnl *t = netdev_priv(dev); 416 struct ip6_tnl *t = netdev_priv(dev);
380 struct ip6gre_net *ign = net_generic(t->net, ip6gre_net_id); 417 struct ip6gre_net *ign = net_generic(t->net, ip6gre_net_id);
381 418
419 ip6gre_tunnel_unlink_md(ign, t);
382 ip6gre_tunnel_unlink(ign, t); 420 ip6gre_tunnel_unlink(ign, t);
383 dst_cache_reset(&t->dst_cache); 421 dst_cache_reset(&t->dst_cache);
384 dev_put(dev); 422 dev_put(dev);
@@ -698,6 +736,9 @@ static netdev_tx_t __gre6_xmit(struct sk_buff *skb,
698 else 736 else
699 fl6->daddr = tunnel->parms.raddr; 737 fl6->daddr = tunnel->parms.raddr;
700 738
739 if (skb_cow_head(skb, dev->needed_headroom ?: tunnel->hlen))
740 return -ENOMEM;
741
701 /* Push GRE header. */ 742 /* Push GRE header. */
702 protocol = (dev->type == ARPHRD_ETHER) ? htons(ETH_P_TEB) : proto; 743 protocol = (dev->type == ARPHRD_ETHER) ? htons(ETH_P_TEB) : proto;
703 744
@@ -908,7 +949,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
908 truncate = true; 949 truncate = true;
909 } 950 }
910 951
911 if (skb_cow_head(skb, dev->needed_headroom)) 952 if (skb_cow_head(skb, dev->needed_headroom ?: t->hlen))
912 goto tx_err; 953 goto tx_err;
913 954
914 t->parms.o_flags &= ~TUNNEL_KEY; 955 t->parms.o_flags &= ~TUNNEL_KEY;
@@ -979,11 +1020,14 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
979 erspan_build_header(skb, ntohl(t->parms.o_key), 1020 erspan_build_header(skb, ntohl(t->parms.o_key),
980 t->parms.index, 1021 t->parms.index,
981 truncate, false); 1022 truncate, false);
982 else 1023 else if (t->parms.erspan_ver == 2)
983 erspan_build_header_v2(skb, ntohl(t->parms.o_key), 1024 erspan_build_header_v2(skb, ntohl(t->parms.o_key),
984 t->parms.dir, 1025 t->parms.dir,
985 t->parms.hwid, 1026 t->parms.hwid,
986 truncate, false); 1027 truncate, false);
1028 else
1029 goto tx_err;
1030
987 fl6.daddr = t->parms.raddr; 1031 fl6.daddr = t->parms.raddr;
988 } 1032 }
989 1033
@@ -1019,12 +1063,11 @@ tx_err:
1019 return NETDEV_TX_OK; 1063 return NETDEV_TX_OK;
1020} 1064}
1021 1065
1022static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu) 1066static void ip6gre_tnl_link_config_common(struct ip6_tnl *t)
1023{ 1067{
1024 struct net_device *dev = t->dev; 1068 struct net_device *dev = t->dev;
1025 struct __ip6_tnl_parm *p = &t->parms; 1069 struct __ip6_tnl_parm *p = &t->parms;
1026 struct flowi6 *fl6 = &t->fl.u.ip6; 1070 struct flowi6 *fl6 = &t->fl.u.ip6;
1027 int t_hlen;
1028 1071
1029 if (dev->type != ARPHRD_ETHER) { 1072 if (dev->type != ARPHRD_ETHER) {
1030 memcpy(dev->dev_addr, &p->laddr, sizeof(struct in6_addr)); 1073 memcpy(dev->dev_addr, &p->laddr, sizeof(struct in6_addr));
@@ -1051,12 +1094,13 @@ static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu)
1051 dev->flags |= IFF_POINTOPOINT; 1094 dev->flags |= IFF_POINTOPOINT;
1052 else 1095 else
1053 dev->flags &= ~IFF_POINTOPOINT; 1096 dev->flags &= ~IFF_POINTOPOINT;
1097}
1054 1098
1055 t->tun_hlen = gre_calc_hlen(t->parms.o_flags); 1099static void ip6gre_tnl_link_config_route(struct ip6_tnl *t, int set_mtu,
1056 1100 int t_hlen)
1057 t->hlen = t->encap_hlen + t->tun_hlen; 1101{
1058 1102 const struct __ip6_tnl_parm *p = &t->parms;
1059 t_hlen = t->hlen + sizeof(struct ipv6hdr); 1103 struct net_device *dev = t->dev;
1060 1104
1061 if (p->flags & IP6_TNL_F_CAP_XMIT) { 1105 if (p->flags & IP6_TNL_F_CAP_XMIT) {
1062 int strict = (ipv6_addr_type(&p->raddr) & 1106 int strict = (ipv6_addr_type(&p->raddr) &
@@ -1088,8 +1132,26 @@ static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu)
1088 } 1132 }
1089} 1133}
1090 1134
1091static int ip6gre_tnl_change(struct ip6_tnl *t, 1135static int ip6gre_calc_hlen(struct ip6_tnl *tunnel)
1092 const struct __ip6_tnl_parm *p, int set_mtu) 1136{
1137 int t_hlen;
1138
1139 tunnel->tun_hlen = gre_calc_hlen(tunnel->parms.o_flags);
1140 tunnel->hlen = tunnel->tun_hlen + tunnel->encap_hlen;
1141
1142 t_hlen = tunnel->hlen + sizeof(struct ipv6hdr);
1143 tunnel->dev->hard_header_len = LL_MAX_HEADER + t_hlen;
1144 return t_hlen;
1145}
1146
1147static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu)
1148{
1149 ip6gre_tnl_link_config_common(t);
1150 ip6gre_tnl_link_config_route(t, set_mtu, ip6gre_calc_hlen(t));
1151}
1152
1153static void ip6gre_tnl_copy_tnl_parm(struct ip6_tnl *t,
1154 const struct __ip6_tnl_parm *p)
1093{ 1155{
1094 t->parms.laddr = p->laddr; 1156 t->parms.laddr = p->laddr;
1095 t->parms.raddr = p->raddr; 1157 t->parms.raddr = p->raddr;
@@ -1105,6 +1167,12 @@ static int ip6gre_tnl_change(struct ip6_tnl *t,
1105 t->parms.o_flags = p->o_flags; 1167 t->parms.o_flags = p->o_flags;
1106 t->parms.fwmark = p->fwmark; 1168 t->parms.fwmark = p->fwmark;
1107 dst_cache_reset(&t->dst_cache); 1169 dst_cache_reset(&t->dst_cache);
1170}
1171
1172static int ip6gre_tnl_change(struct ip6_tnl *t, const struct __ip6_tnl_parm *p,
1173 int set_mtu)
1174{
1175 ip6gre_tnl_copy_tnl_parm(t, p);
1108 ip6gre_tnl_link_config(t, set_mtu); 1176 ip6gre_tnl_link_config(t, set_mtu);
1109 return 0; 1177 return 0;
1110} 1178}
@@ -1381,11 +1449,7 @@ static int ip6gre_tunnel_init_common(struct net_device *dev)
1381 return ret; 1449 return ret;
1382 } 1450 }
1383 1451
1384 tunnel->tun_hlen = gre_calc_hlen(tunnel->parms.o_flags); 1452 t_hlen = ip6gre_calc_hlen(tunnel);
1385 tunnel->hlen = tunnel->tun_hlen + tunnel->encap_hlen;
1386 t_hlen = tunnel->hlen + sizeof(struct ipv6hdr);
1387
1388 dev->hard_header_len = LL_MAX_HEADER + t_hlen;
1389 dev->mtu = ETH_DATA_LEN - t_hlen; 1453 dev->mtu = ETH_DATA_LEN - t_hlen;
1390 if (dev->type == ARPHRD_ETHER) 1454 if (dev->type == ARPHRD_ETHER)
1391 dev->mtu -= ETH_HLEN; 1455 dev->mtu -= ETH_HLEN;
@@ -1728,6 +1792,19 @@ static const struct net_device_ops ip6gre_tap_netdev_ops = {
1728 .ndo_get_iflink = ip6_tnl_get_iflink, 1792 .ndo_get_iflink = ip6_tnl_get_iflink,
1729}; 1793};
1730 1794
1795static int ip6erspan_calc_hlen(struct ip6_tnl *tunnel)
1796{
1797 int t_hlen;
1798
1799 tunnel->tun_hlen = 8;
1800 tunnel->hlen = tunnel->tun_hlen + tunnel->encap_hlen +
1801 erspan_hdr_len(tunnel->parms.erspan_ver);
1802
1803 t_hlen = tunnel->hlen + sizeof(struct ipv6hdr);
1804 tunnel->dev->hard_header_len = LL_MAX_HEADER + t_hlen;
1805 return t_hlen;
1806}
1807
1731static int ip6erspan_tap_init(struct net_device *dev) 1808static int ip6erspan_tap_init(struct net_device *dev)
1732{ 1809{
1733 struct ip6_tnl *tunnel; 1810 struct ip6_tnl *tunnel;
@@ -1751,12 +1828,7 @@ static int ip6erspan_tap_init(struct net_device *dev)
1751 return ret; 1828 return ret;
1752 } 1829 }
1753 1830
1754 tunnel->tun_hlen = 8; 1831 t_hlen = ip6erspan_calc_hlen(tunnel);
1755 tunnel->hlen = tunnel->tun_hlen + tunnel->encap_hlen +
1756 erspan_hdr_len(tunnel->parms.erspan_ver);
1757 t_hlen = tunnel->hlen + sizeof(struct ipv6hdr);
1758
1759 dev->hard_header_len = LL_MAX_HEADER + t_hlen;
1760 dev->mtu = ETH_DATA_LEN - t_hlen; 1832 dev->mtu = ETH_DATA_LEN - t_hlen;
1761 if (dev->type == ARPHRD_ETHER) 1833 if (dev->type == ARPHRD_ETHER)
1762 dev->mtu -= ETH_HLEN; 1834 dev->mtu -= ETH_HLEN;
@@ -1764,14 +1836,14 @@ static int ip6erspan_tap_init(struct net_device *dev)
1764 dev->mtu -= 8; 1836 dev->mtu -= 8;
1765 1837
1766 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; 1838 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
1767 ip6gre_tnl_link_config(tunnel, 1); 1839 ip6erspan_tnl_link_config(tunnel, 1);
1768 1840
1769 return 0; 1841 return 0;
1770} 1842}
1771 1843
1772static const struct net_device_ops ip6erspan_netdev_ops = { 1844static const struct net_device_ops ip6erspan_netdev_ops = {
1773 .ndo_init = ip6erspan_tap_init, 1845 .ndo_init = ip6erspan_tap_init,
1774 .ndo_uninit = ip6gre_tunnel_uninit, 1846 .ndo_uninit = ip6erspan_tunnel_uninit,
1775 .ndo_start_xmit = ip6erspan_tunnel_xmit, 1847 .ndo_start_xmit = ip6erspan_tunnel_xmit,
1776 .ndo_set_mac_address = eth_mac_addr, 1848 .ndo_set_mac_address = eth_mac_addr,
1777 .ndo_validate_addr = eth_validate_addr, 1849 .ndo_validate_addr = eth_validate_addr,
@@ -1835,13 +1907,11 @@ static bool ip6gre_netlink_encap_parms(struct nlattr *data[],
1835 return ret; 1907 return ret;
1836} 1908}
1837 1909
1838static int ip6gre_newlink(struct net *src_net, struct net_device *dev, 1910static int ip6gre_newlink_common(struct net *src_net, struct net_device *dev,
1839 struct nlattr *tb[], struct nlattr *data[], 1911 struct nlattr *tb[], struct nlattr *data[],
1840 struct netlink_ext_ack *extack) 1912 struct netlink_ext_ack *extack)
1841{ 1913{
1842 struct ip6_tnl *nt; 1914 struct ip6_tnl *nt;
1843 struct net *net = dev_net(dev);
1844 struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
1845 struct ip_tunnel_encap ipencap; 1915 struct ip_tunnel_encap ipencap;
1846 int err; 1916 int err;
1847 1917
@@ -1854,16 +1924,6 @@ static int ip6gre_newlink(struct net *src_net, struct net_device *dev,
1854 return err; 1924 return err;
1855 } 1925 }
1856 1926
1857 ip6gre_netlink_parms(data, &nt->parms);
1858
1859 if (nt->parms.collect_md) {
1860 if (rtnl_dereference(ign->collect_md_tun))
1861 return -EEXIST;
1862 } else {
1863 if (ip6gre_tunnel_find(net, &nt->parms, dev->type))
1864 return -EEXIST;
1865 }
1866
1867 if (dev->type == ARPHRD_ETHER && !tb[IFLA_ADDRESS]) 1927 if (dev->type == ARPHRD_ETHER && !tb[IFLA_ADDRESS])
1868 eth_hw_addr_random(dev); 1928 eth_hw_addr_random(dev);
1869 1929
@@ -1874,51 +1934,94 @@ static int ip6gre_newlink(struct net *src_net, struct net_device *dev,
1874 if (err) 1934 if (err)
1875 goto out; 1935 goto out;
1876 1936
1877 ip6gre_tnl_link_config(nt, !tb[IFLA_MTU]);
1878
1879 if (tb[IFLA_MTU]) 1937 if (tb[IFLA_MTU])
1880 ip6_tnl_change_mtu(dev, nla_get_u32(tb[IFLA_MTU])); 1938 ip6_tnl_change_mtu(dev, nla_get_u32(tb[IFLA_MTU]));
1881 1939
1882 dev_hold(dev); 1940 dev_hold(dev);
1883 ip6gre_tunnel_link(ign, nt);
1884 1941
1885out: 1942out:
1886 return err; 1943 return err;
1887} 1944}
1888 1945
1889static int ip6gre_changelink(struct net_device *dev, struct nlattr *tb[], 1946static int ip6gre_newlink(struct net *src_net, struct net_device *dev,
1890 struct nlattr *data[], 1947 struct nlattr *tb[], struct nlattr *data[],
1891 struct netlink_ext_ack *extack) 1948 struct netlink_ext_ack *extack)
1949{
1950 struct ip6_tnl *nt = netdev_priv(dev);
1951 struct net *net = dev_net(dev);
1952 struct ip6gre_net *ign;
1953 int err;
1954
1955 ip6gre_netlink_parms(data, &nt->parms);
1956 ign = net_generic(net, ip6gre_net_id);
1957
1958 if (nt->parms.collect_md) {
1959 if (rtnl_dereference(ign->collect_md_tun))
1960 return -EEXIST;
1961 } else {
1962 if (ip6gre_tunnel_find(net, &nt->parms, dev->type))
1963 return -EEXIST;
1964 }
1965
1966 err = ip6gre_newlink_common(src_net, dev, tb, data, extack);
1967 if (!err) {
1968 ip6gre_tnl_link_config(nt, !tb[IFLA_MTU]);
1969 ip6gre_tunnel_link_md(ign, nt);
1970 ip6gre_tunnel_link(net_generic(net, ip6gre_net_id), nt);
1971 }
1972 return err;
1973}
1974
1975static struct ip6_tnl *
1976ip6gre_changelink_common(struct net_device *dev, struct nlattr *tb[],
1977 struct nlattr *data[], struct __ip6_tnl_parm *p_p,
1978 struct netlink_ext_ack *extack)
1892{ 1979{
1893 struct ip6_tnl *t, *nt = netdev_priv(dev); 1980 struct ip6_tnl *t, *nt = netdev_priv(dev);
1894 struct net *net = nt->net; 1981 struct net *net = nt->net;
1895 struct ip6gre_net *ign = net_generic(net, ip6gre_net_id); 1982 struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
1896 struct __ip6_tnl_parm p;
1897 struct ip_tunnel_encap ipencap; 1983 struct ip_tunnel_encap ipencap;
1898 1984
1899 if (dev == ign->fb_tunnel_dev) 1985 if (dev == ign->fb_tunnel_dev)
1900 return -EINVAL; 1986 return ERR_PTR(-EINVAL);
1901 1987
1902 if (ip6gre_netlink_encap_parms(data, &ipencap)) { 1988 if (ip6gre_netlink_encap_parms(data, &ipencap)) {
1903 int err = ip6_tnl_encap_setup(nt, &ipencap); 1989 int err = ip6_tnl_encap_setup(nt, &ipencap);
1904 1990
1905 if (err < 0) 1991 if (err < 0)
1906 return err; 1992 return ERR_PTR(err);
1907 } 1993 }
1908 1994
1909 ip6gre_netlink_parms(data, &p); 1995 ip6gre_netlink_parms(data, p_p);
1910 1996
1911 t = ip6gre_tunnel_locate(net, &p, 0); 1997 t = ip6gre_tunnel_locate(net, p_p, 0);
1912 1998
1913 if (t) { 1999 if (t) {
1914 if (t->dev != dev) 2000 if (t->dev != dev)
1915 return -EEXIST; 2001 return ERR_PTR(-EEXIST);
1916 } else { 2002 } else {
1917 t = nt; 2003 t = nt;
1918 } 2004 }
1919 2005
2006 return t;
2007}
2008
2009static int ip6gre_changelink(struct net_device *dev, struct nlattr *tb[],
2010 struct nlattr *data[],
2011 struct netlink_ext_ack *extack)
2012{
2013 struct ip6gre_net *ign = net_generic(dev_net(dev), ip6gre_net_id);
2014 struct __ip6_tnl_parm p;
2015 struct ip6_tnl *t;
2016
2017 t = ip6gre_changelink_common(dev, tb, data, &p, extack);
2018 if (IS_ERR(t))
2019 return PTR_ERR(t);
2020
2021 ip6gre_tunnel_unlink_md(ign, t);
1920 ip6gre_tunnel_unlink(ign, t); 2022 ip6gre_tunnel_unlink(ign, t);
1921 ip6gre_tnl_change(t, &p, !tb[IFLA_MTU]); 2023 ip6gre_tnl_change(t, &p, !tb[IFLA_MTU]);
2024 ip6gre_tunnel_link_md(ign, t);
1922 ip6gre_tunnel_link(ign, t); 2025 ip6gre_tunnel_link(ign, t);
1923 return 0; 2026 return 0;
1924} 2027}
@@ -2068,6 +2171,69 @@ static void ip6erspan_tap_setup(struct net_device *dev)
2068 netif_keep_dst(dev); 2171 netif_keep_dst(dev);
2069} 2172}
2070 2173
2174static int ip6erspan_newlink(struct net *src_net, struct net_device *dev,
2175 struct nlattr *tb[], struct nlattr *data[],
2176 struct netlink_ext_ack *extack)
2177{
2178 struct ip6_tnl *nt = netdev_priv(dev);
2179 struct net *net = dev_net(dev);
2180 struct ip6gre_net *ign;
2181 int err;
2182
2183 ip6gre_netlink_parms(data, &nt->parms);
2184 ign = net_generic(net, ip6gre_net_id);
2185
2186 if (nt->parms.collect_md) {
2187 if (rtnl_dereference(ign->collect_md_tun_erspan))
2188 return -EEXIST;
2189 } else {
2190 if (ip6gre_tunnel_find(net, &nt->parms, dev->type))
2191 return -EEXIST;
2192 }
2193
2194 err = ip6gre_newlink_common(src_net, dev, tb, data, extack);
2195 if (!err) {
2196 ip6erspan_tnl_link_config(nt, !tb[IFLA_MTU]);
2197 ip6erspan_tunnel_link_md(ign, nt);
2198 ip6gre_tunnel_link(net_generic(net, ip6gre_net_id), nt);
2199 }
2200 return err;
2201}
2202
2203static void ip6erspan_tnl_link_config(struct ip6_tnl *t, int set_mtu)
2204{
2205 ip6gre_tnl_link_config_common(t);
2206 ip6gre_tnl_link_config_route(t, set_mtu, ip6erspan_calc_hlen(t));
2207}
2208
2209static int ip6erspan_tnl_change(struct ip6_tnl *t,
2210 const struct __ip6_tnl_parm *p, int set_mtu)
2211{
2212 ip6gre_tnl_copy_tnl_parm(t, p);
2213 ip6erspan_tnl_link_config(t, set_mtu);
2214 return 0;
2215}
2216
2217static int ip6erspan_changelink(struct net_device *dev, struct nlattr *tb[],
2218 struct nlattr *data[],
2219 struct netlink_ext_ack *extack)
2220{
2221 struct ip6gre_net *ign = net_generic(dev_net(dev), ip6gre_net_id);
2222 struct __ip6_tnl_parm p;
2223 struct ip6_tnl *t;
2224
2225 t = ip6gre_changelink_common(dev, tb, data, &p, extack);
2226 if (IS_ERR(t))
2227 return PTR_ERR(t);
2228
2229 ip6gre_tunnel_unlink_md(ign, t);
2230 ip6gre_tunnel_unlink(ign, t);
2231 ip6erspan_tnl_change(t, &p, !tb[IFLA_MTU]);
2232 ip6erspan_tunnel_link_md(ign, t);
2233 ip6gre_tunnel_link(ign, t);
2234 return 0;
2235}
2236
2071static struct rtnl_link_ops ip6gre_link_ops __read_mostly = { 2237static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
2072 .kind = "ip6gre", 2238 .kind = "ip6gre",
2073 .maxtype = IFLA_GRE_MAX, 2239 .maxtype = IFLA_GRE_MAX,
@@ -2104,8 +2270,8 @@ static struct rtnl_link_ops ip6erspan_tap_ops __read_mostly = {
2104 .priv_size = sizeof(struct ip6_tnl), 2270 .priv_size = sizeof(struct ip6_tnl),
2105 .setup = ip6erspan_tap_setup, 2271 .setup = ip6erspan_tap_setup,
2106 .validate = ip6erspan_tap_validate, 2272 .validate = ip6erspan_tap_validate,
2107 .newlink = ip6gre_newlink, 2273 .newlink = ip6erspan_newlink,
2108 .changelink = ip6gre_changelink, 2274 .changelink = ip6erspan_changelink,
2109 .get_size = ip6gre_get_size, 2275 .get_size = ip6gre_get_size,
2110 .fill_info = ip6gre_fill_info, 2276 .fill_info = ip6gre_fill_info,
2111 .get_link_net = ip6_tnl_get_link_net, 2277 .get_link_net = ip6_tnl_get_link_net,
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 2e891d2c30ef..7b6d1689087b 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -1503,7 +1503,8 @@ alloc_new_skb:
1503 if (copy > length) 1503 if (copy > length)
1504 copy = length; 1504 copy = length;
1505 1505
1506 if (!(rt->dst.dev->features&NETIF_F_SG)) { 1506 if (!(rt->dst.dev->features&NETIF_F_SG) &&
1507 skb_tailroom(skb) >= copy) {
1507 unsigned int off; 1508 unsigned int off;
1508 1509
1509 off = skb->len; 1510 off = skb->len;
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index 65c9e1a58305..97f79dc943d7 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -38,6 +38,7 @@
38MODULE_LICENSE("GPL"); 38MODULE_LICENSE("GPL");
39MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); 39MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
40MODULE_DESCRIPTION("IPv6 packet filter"); 40MODULE_DESCRIPTION("IPv6 packet filter");
41MODULE_ALIAS("ip6t_icmp6");
41 42
42void *ip6t_alloc_initial_table(const struct xt_table *info) 43void *ip6t_alloc_initial_table(const struct xt_table *info)
43{ 44{
diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c
index 0f6c9ca59062..5b5b0f95ffd1 100644
--- a/net/mac80211/mesh_plink.c
+++ b/net/mac80211/mesh_plink.c
@@ -401,7 +401,7 @@ u32 mesh_plink_deactivate(struct sta_info *sta)
401 401
402static void mesh_sta_info_init(struct ieee80211_sub_if_data *sdata, 402static void mesh_sta_info_init(struct ieee80211_sub_if_data *sdata,
403 struct sta_info *sta, 403 struct sta_info *sta,
404 struct ieee802_11_elems *elems, bool insert) 404 struct ieee802_11_elems *elems)
405{ 405{
406 struct ieee80211_local *local = sdata->local; 406 struct ieee80211_local *local = sdata->local;
407 struct ieee80211_supported_band *sband; 407 struct ieee80211_supported_band *sband;
@@ -447,7 +447,7 @@ static void mesh_sta_info_init(struct ieee80211_sub_if_data *sdata,
447 sta->sta.bandwidth = IEEE80211_STA_RX_BW_20; 447 sta->sta.bandwidth = IEEE80211_STA_RX_BW_20;
448 } 448 }
449 449
450 if (insert) 450 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
451 rate_control_rate_init(sta); 451 rate_control_rate_init(sta);
452 else 452 else
453 rate_control_rate_update(local, sband, sta, changed); 453 rate_control_rate_update(local, sband, sta, changed);
@@ -551,7 +551,7 @@ mesh_sta_info_get(struct ieee80211_sub_if_data *sdata,
551 rcu_read_lock(); 551 rcu_read_lock();
552 sta = sta_info_get(sdata, addr); 552 sta = sta_info_get(sdata, addr);
553 if (sta) { 553 if (sta) {
554 mesh_sta_info_init(sdata, sta, elems, false); 554 mesh_sta_info_init(sdata, sta, elems);
555 } else { 555 } else {
556 rcu_read_unlock(); 556 rcu_read_unlock();
557 /* can't run atomic */ 557 /* can't run atomic */
@@ -561,7 +561,7 @@ mesh_sta_info_get(struct ieee80211_sub_if_data *sdata,
561 return NULL; 561 return NULL;
562 } 562 }
563 563
564 mesh_sta_info_init(sdata, sta, elems, true); 564 mesh_sta_info_init(sdata, sta, elems);
565 565
566 if (sta_info_insert_rcu(sta)) 566 if (sta_info_insert_rcu(sta))
567 return NULL; 567 return NULL;
diff --git a/net/netfilter/core.c b/net/netfilter/core.c
index 0f6b8172fb9a..206fb2c4c319 100644
--- a/net/netfilter/core.c
+++ b/net/netfilter/core.c
@@ -585,7 +585,8 @@ void (*nf_nat_decode_session_hook)(struct sk_buff *, struct flowi *);
585EXPORT_SYMBOL(nf_nat_decode_session_hook); 585EXPORT_SYMBOL(nf_nat_decode_session_hook);
586#endif 586#endif
587 587
588static void __net_init __netfilter_net_init(struct nf_hook_entries **e, int max) 588static void __net_init
589__netfilter_net_init(struct nf_hook_entries __rcu **e, int max)
589{ 590{
590 int h; 591 int h;
591 592
diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
index 370abbf6f421..75de46576f51 100644
--- a/net/netfilter/ipvs/ip_vs_conn.c
+++ b/net/netfilter/ipvs/ip_vs_conn.c
@@ -232,7 +232,10 @@ static inline int ip_vs_conn_unhash(struct ip_vs_conn *cp)
232static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp) 232static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp)
233{ 233{
234 unsigned int hash; 234 unsigned int hash;
235 bool ret; 235 bool ret = false;
236
237 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
238 return refcount_dec_if_one(&cp->refcnt);
236 239
237 hash = ip_vs_conn_hashkey_conn(cp); 240 hash = ip_vs_conn_hashkey_conn(cp);
238 241
@@ -240,15 +243,13 @@ static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp)
240 spin_lock(&cp->lock); 243 spin_lock(&cp->lock);
241 244
242 if (cp->flags & IP_VS_CONN_F_HASHED) { 245 if (cp->flags & IP_VS_CONN_F_HASHED) {
243 ret = false;
244 /* Decrease refcnt and unlink conn only if we are last user */ 246 /* Decrease refcnt and unlink conn only if we are last user */
245 if (refcount_dec_if_one(&cp->refcnt)) { 247 if (refcount_dec_if_one(&cp->refcnt)) {
246 hlist_del_rcu(&cp->c_list); 248 hlist_del_rcu(&cp->c_list);
247 cp->flags &= ~IP_VS_CONN_F_HASHED; 249 cp->flags &= ~IP_VS_CONN_F_HASHED;
248 ret = true; 250 ret = true;
249 } 251 }
250 } else 252 }
251 ret = refcount_read(&cp->refcnt) ? false : true;
252 253
253 spin_unlock(&cp->lock); 254 spin_unlock(&cp->lock);
254 ct_write_unlock_bh(hash); 255 ct_write_unlock_bh(hash);
@@ -454,12 +455,6 @@ ip_vs_conn_out_get_proto(struct netns_ipvs *ipvs, int af,
454} 455}
455EXPORT_SYMBOL_GPL(ip_vs_conn_out_get_proto); 456EXPORT_SYMBOL_GPL(ip_vs_conn_out_get_proto);
456 457
457static void __ip_vs_conn_put_notimer(struct ip_vs_conn *cp)
458{
459 __ip_vs_conn_put(cp);
460 ip_vs_conn_expire(&cp->timer);
461}
462
463/* 458/*
464 * Put back the conn and restart its timer with its timeout 459 * Put back the conn and restart its timer with its timeout
465 */ 460 */
@@ -478,7 +473,7 @@ void ip_vs_conn_put(struct ip_vs_conn *cp)
478 (refcount_read(&cp->refcnt) == 1) && 473 (refcount_read(&cp->refcnt) == 1) &&
479 !timer_pending(&cp->timer)) 474 !timer_pending(&cp->timer))
480 /* expire connection immediately */ 475 /* expire connection immediately */
481 __ip_vs_conn_put_notimer(cp); 476 ip_vs_conn_expire(&cp->timer);
482 else 477 else
483 __ip_vs_conn_put_timer(cp); 478 __ip_vs_conn_put_timer(cp);
484} 479}
diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
index 5f6f73cf2174..0679dd101e72 100644
--- a/net/netfilter/ipvs/ip_vs_core.c
+++ b/net/netfilter/ipvs/ip_vs_core.c
@@ -119,6 +119,8 @@ ip_vs_in_stats(struct ip_vs_conn *cp, struct sk_buff *skb)
119 struct ip_vs_cpu_stats *s; 119 struct ip_vs_cpu_stats *s;
120 struct ip_vs_service *svc; 120 struct ip_vs_service *svc;
121 121
122 local_bh_disable();
123
122 s = this_cpu_ptr(dest->stats.cpustats); 124 s = this_cpu_ptr(dest->stats.cpustats);
123 u64_stats_update_begin(&s->syncp); 125 u64_stats_update_begin(&s->syncp);
124 s->cnt.inpkts++; 126 s->cnt.inpkts++;
@@ -137,6 +139,8 @@ ip_vs_in_stats(struct ip_vs_conn *cp, struct sk_buff *skb)
137 s->cnt.inpkts++; 139 s->cnt.inpkts++;
138 s->cnt.inbytes += skb->len; 140 s->cnt.inbytes += skb->len;
139 u64_stats_update_end(&s->syncp); 141 u64_stats_update_end(&s->syncp);
142
143 local_bh_enable();
140 } 144 }
141} 145}
142 146
@@ -151,6 +155,8 @@ ip_vs_out_stats(struct ip_vs_conn *cp, struct sk_buff *skb)
151 struct ip_vs_cpu_stats *s; 155 struct ip_vs_cpu_stats *s;
152 struct ip_vs_service *svc; 156 struct ip_vs_service *svc;
153 157
158 local_bh_disable();
159
154 s = this_cpu_ptr(dest->stats.cpustats); 160 s = this_cpu_ptr(dest->stats.cpustats);
155 u64_stats_update_begin(&s->syncp); 161 u64_stats_update_begin(&s->syncp);
156 s->cnt.outpkts++; 162 s->cnt.outpkts++;
@@ -169,6 +175,8 @@ ip_vs_out_stats(struct ip_vs_conn *cp, struct sk_buff *skb)
169 s->cnt.outpkts++; 175 s->cnt.outpkts++;
170 s->cnt.outbytes += skb->len; 176 s->cnt.outbytes += skb->len;
171 u64_stats_update_end(&s->syncp); 177 u64_stats_update_end(&s->syncp);
178
179 local_bh_enable();
172 } 180 }
173} 181}
174 182
@@ -179,6 +187,8 @@ ip_vs_conn_stats(struct ip_vs_conn *cp, struct ip_vs_service *svc)
179 struct netns_ipvs *ipvs = svc->ipvs; 187 struct netns_ipvs *ipvs = svc->ipvs;
180 struct ip_vs_cpu_stats *s; 188 struct ip_vs_cpu_stats *s;
181 189
190 local_bh_disable();
191
182 s = this_cpu_ptr(cp->dest->stats.cpustats); 192 s = this_cpu_ptr(cp->dest->stats.cpustats);
183 u64_stats_update_begin(&s->syncp); 193 u64_stats_update_begin(&s->syncp);
184 s->cnt.conns++; 194 s->cnt.conns++;
@@ -193,6 +203,8 @@ ip_vs_conn_stats(struct ip_vs_conn *cp, struct ip_vs_service *svc)
193 u64_stats_update_begin(&s->syncp); 203 u64_stats_update_begin(&s->syncp);
194 s->cnt.conns++; 204 s->cnt.conns++;
195 u64_stats_update_end(&s->syncp); 205 u64_stats_update_end(&s->syncp);
206
207 local_bh_enable();
196} 208}
197 209
198 210
diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
index e97cdc1cf98c..8e67910185a0 100644
--- a/net/netfilter/nf_conntrack_proto_tcp.c
+++ b/net/netfilter/nf_conntrack_proto_tcp.c
@@ -981,6 +981,17 @@ static int tcp_packet(struct nf_conn *ct,
981 return NF_ACCEPT; /* Don't change state */ 981 return NF_ACCEPT; /* Don't change state */
982 } 982 }
983 break; 983 break;
984 case TCP_CONNTRACK_SYN_SENT2:
985 /* tcp_conntracks table is not smart enough to handle
986 * simultaneous open.
987 */
988 ct->proto.tcp.last_flags |= IP_CT_TCP_SIMULTANEOUS_OPEN;
989 break;
990 case TCP_CONNTRACK_SYN_RECV:
991 if (dir == IP_CT_DIR_REPLY && index == TCP_ACK_SET &&
992 ct->proto.tcp.last_flags & IP_CT_TCP_SIMULTANEOUS_OPEN)
993 new_state = TCP_CONNTRACK_ESTABLISHED;
994 break;
984 case TCP_CONNTRACK_CLOSE: 995 case TCP_CONNTRACK_CLOSE:
985 if (index == TCP_RST_SET 996 if (index == TCP_RST_SET
986 && (ct->proto.tcp.seen[!dir].flags & IP_CT_TCP_FLAG_MAXACK_SET) 997 && (ct->proto.tcp.seen[!dir].flags & IP_CT_TCP_FLAG_MAXACK_SET)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 04d4e3772584..91e80aa852d6 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -214,6 +214,34 @@ static int nft_delchain(struct nft_ctx *ctx)
214 return err; 214 return err;
215} 215}
216 216
217static void nft_rule_expr_activate(const struct nft_ctx *ctx,
218 struct nft_rule *rule)
219{
220 struct nft_expr *expr;
221
222 expr = nft_expr_first(rule);
223 while (expr != nft_expr_last(rule) && expr->ops) {
224 if (expr->ops->activate)
225 expr->ops->activate(ctx, expr);
226
227 expr = nft_expr_next(expr);
228 }
229}
230
231static void nft_rule_expr_deactivate(const struct nft_ctx *ctx,
232 struct nft_rule *rule)
233{
234 struct nft_expr *expr;
235
236 expr = nft_expr_first(rule);
237 while (expr != nft_expr_last(rule) && expr->ops) {
238 if (expr->ops->deactivate)
239 expr->ops->deactivate(ctx, expr);
240
241 expr = nft_expr_next(expr);
242 }
243}
244
217static int 245static int
218nf_tables_delrule_deactivate(struct nft_ctx *ctx, struct nft_rule *rule) 246nf_tables_delrule_deactivate(struct nft_ctx *ctx, struct nft_rule *rule)
219{ 247{
@@ -259,6 +287,7 @@ static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule)
259 nft_trans_destroy(trans); 287 nft_trans_destroy(trans);
260 return err; 288 return err;
261 } 289 }
290 nft_rule_expr_deactivate(ctx, rule);
262 291
263 return 0; 292 return 0;
264} 293}
@@ -2238,6 +2267,13 @@ static void nf_tables_rule_destroy(const struct nft_ctx *ctx,
2238 kfree(rule); 2267 kfree(rule);
2239} 2268}
2240 2269
2270static void nf_tables_rule_release(const struct nft_ctx *ctx,
2271 struct nft_rule *rule)
2272{
2273 nft_rule_expr_deactivate(ctx, rule);
2274 nf_tables_rule_destroy(ctx, rule);
2275}
2276
2241#define NFT_RULE_MAXEXPRS 128 2277#define NFT_RULE_MAXEXPRS 128
2242 2278
2243static struct nft_expr_info *info; 2279static struct nft_expr_info *info;
@@ -2402,7 +2438,7 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
2402 return 0; 2438 return 0;
2403 2439
2404err2: 2440err2:
2405 nf_tables_rule_destroy(&ctx, rule); 2441 nf_tables_rule_release(&ctx, rule);
2406err1: 2442err1:
2407 for (i = 0; i < n; i++) { 2443 for (i = 0; i < n; i++) {
2408 if (info[i].ops != NULL) 2444 if (info[i].ops != NULL)
@@ -4044,8 +4080,10 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
4044 if (nft_set_ext_exists(ext, NFT_SET_EXT_DATA) ^ 4080 if (nft_set_ext_exists(ext, NFT_SET_EXT_DATA) ^
4045 nft_set_ext_exists(ext2, NFT_SET_EXT_DATA) || 4081 nft_set_ext_exists(ext2, NFT_SET_EXT_DATA) ||
4046 nft_set_ext_exists(ext, NFT_SET_EXT_OBJREF) ^ 4082 nft_set_ext_exists(ext, NFT_SET_EXT_OBJREF) ^
4047 nft_set_ext_exists(ext2, NFT_SET_EXT_OBJREF)) 4083 nft_set_ext_exists(ext2, NFT_SET_EXT_OBJREF)) {
4048 return -EBUSY; 4084 err = -EBUSY;
4085 goto err5;
4086 }
4049 if ((nft_set_ext_exists(ext, NFT_SET_EXT_DATA) && 4087 if ((nft_set_ext_exists(ext, NFT_SET_EXT_DATA) &&
4050 nft_set_ext_exists(ext2, NFT_SET_EXT_DATA) && 4088 nft_set_ext_exists(ext2, NFT_SET_EXT_DATA) &&
4051 memcmp(nft_set_ext_data(ext), 4089 memcmp(nft_set_ext_data(ext),
@@ -4130,7 +4168,7 @@ static int nf_tables_newsetelem(struct net *net, struct sock *nlsk,
4130 * NFT_GOTO verdicts. This function must be called on active data objects 4168 * NFT_GOTO verdicts. This function must be called on active data objects
4131 * from the second phase of the commit protocol. 4169 * from the second phase of the commit protocol.
4132 */ 4170 */
4133static void nft_data_hold(const struct nft_data *data, enum nft_data_types type) 4171void nft_data_hold(const struct nft_data *data, enum nft_data_types type)
4134{ 4172{
4135 if (type == NFT_DATA_VERDICT) { 4173 if (type == NFT_DATA_VERDICT) {
4136 switch (data->verdict.code) { 4174 switch (data->verdict.code) {
@@ -5761,7 +5799,7 @@ static void nft_chain_commit_update(struct nft_trans *trans)
5761 } 5799 }
5762} 5800}
5763 5801
5764static void nf_tables_commit_release(struct nft_trans *trans) 5802static void nft_commit_release(struct nft_trans *trans)
5765{ 5803{
5766 switch (trans->msg_type) { 5804 switch (trans->msg_type) {
5767 case NFT_MSG_DELTABLE: 5805 case NFT_MSG_DELTABLE:
@@ -5790,6 +5828,21 @@ static void nf_tables_commit_release(struct nft_trans *trans)
5790 kfree(trans); 5828 kfree(trans);
5791} 5829}
5792 5830
5831static void nf_tables_commit_release(struct net *net)
5832{
5833 struct nft_trans *trans, *next;
5834
5835 if (list_empty(&net->nft.commit_list))
5836 return;
5837
5838 synchronize_rcu();
5839
5840 list_for_each_entry_safe(trans, next, &net->nft.commit_list, list) {
5841 list_del(&trans->list);
5842 nft_commit_release(trans);
5843 }
5844}
5845
5793static int nf_tables_commit(struct net *net, struct sk_buff *skb) 5846static int nf_tables_commit(struct net *net, struct sk_buff *skb)
5794{ 5847{
5795 struct nft_trans *trans, *next; 5848 struct nft_trans *trans, *next;
@@ -5920,13 +5973,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)
5920 } 5973 }
5921 } 5974 }
5922 5975
5923 synchronize_rcu(); 5976 nf_tables_commit_release(net);
5924
5925 list_for_each_entry_safe(trans, next, &net->nft.commit_list, list) {
5926 list_del(&trans->list);
5927 nf_tables_commit_release(trans);
5928 }
5929
5930 nf_tables_gen_notify(net, skb, NFT_MSG_NEWGEN); 5977 nf_tables_gen_notify(net, skb, NFT_MSG_NEWGEN);
5931 5978
5932 return 0; 5979 return 0;
@@ -6006,10 +6053,12 @@ static int nf_tables_abort(struct net *net, struct sk_buff *skb)
6006 case NFT_MSG_NEWRULE: 6053 case NFT_MSG_NEWRULE:
6007 trans->ctx.chain->use--; 6054 trans->ctx.chain->use--;
6008 list_del_rcu(&nft_trans_rule(trans)->list); 6055 list_del_rcu(&nft_trans_rule(trans)->list);
6056 nft_rule_expr_deactivate(&trans->ctx, nft_trans_rule(trans));
6009 break; 6057 break;
6010 case NFT_MSG_DELRULE: 6058 case NFT_MSG_DELRULE:
6011 trans->ctx.chain->use++; 6059 trans->ctx.chain->use++;
6012 nft_clear(trans->ctx.net, nft_trans_rule(trans)); 6060 nft_clear(trans->ctx.net, nft_trans_rule(trans));
6061 nft_rule_expr_activate(&trans->ctx, nft_trans_rule(trans));
6013 nft_trans_destroy(trans); 6062 nft_trans_destroy(trans);
6014 break; 6063 break;
6015 case NFT_MSG_NEWSET: 6064 case NFT_MSG_NEWSET:
@@ -6585,7 +6634,7 @@ int __nft_release_basechain(struct nft_ctx *ctx)
6585 list_for_each_entry_safe(rule, nr, &ctx->chain->rules, list) { 6634 list_for_each_entry_safe(rule, nr, &ctx->chain->rules, list) {
6586 list_del(&rule->list); 6635 list_del(&rule->list);
6587 ctx->chain->use--; 6636 ctx->chain->use--;
6588 nf_tables_rule_destroy(ctx, rule); 6637 nf_tables_rule_release(ctx, rule);
6589 } 6638 }
6590 list_del(&ctx->chain->list); 6639 list_del(&ctx->chain->list);
6591 ctx->table->use--; 6640 ctx->table->use--;
@@ -6623,7 +6672,7 @@ static void __nft_release_tables(struct net *net)
6623 list_for_each_entry_safe(rule, nr, &chain->rules, list) { 6672 list_for_each_entry_safe(rule, nr, &chain->rules, list) {
6624 list_del(&rule->list); 6673 list_del(&rule->list);
6625 chain->use--; 6674 chain->use--;
6626 nf_tables_rule_destroy(&ctx, rule); 6675 nf_tables_rule_release(&ctx, rule);
6627 } 6676 }
6628 } 6677 }
6629 list_for_each_entry_safe(flowtable, nf, &table->flowtables, list) { 6678 list_for_each_entry_safe(flowtable, nf, &table->flowtables, list) {
diff --git a/net/netfilter/nf_tables_core.c b/net/netfilter/nf_tables_core.c
index dfd0bf3810d2..942702a2776f 100644
--- a/net/netfilter/nf_tables_core.c
+++ b/net/netfilter/nf_tables_core.c
@@ -119,15 +119,22 @@ DEFINE_STATIC_KEY_FALSE(nft_counters_enabled);
119static noinline void nft_update_chain_stats(const struct nft_chain *chain, 119static noinline void nft_update_chain_stats(const struct nft_chain *chain,
120 const struct nft_pktinfo *pkt) 120 const struct nft_pktinfo *pkt)
121{ 121{
122 struct nft_base_chain *base_chain;
122 struct nft_stats *stats; 123 struct nft_stats *stats;
123 124
124 local_bh_disable(); 125 base_chain = nft_base_chain(chain);
125 stats = this_cpu_ptr(rcu_dereference(nft_base_chain(chain)->stats)); 126 if (!base_chain->stats)
126 u64_stats_update_begin(&stats->syncp); 127 return;
127 stats->pkts++; 128
128 stats->bytes += pkt->skb->len; 129 stats = this_cpu_ptr(rcu_dereference(base_chain->stats));
129 u64_stats_update_end(&stats->syncp); 130 if (stats) {
130 local_bh_enable(); 131 local_bh_disable();
132 u64_stats_update_begin(&stats->syncp);
133 stats->pkts++;
134 stats->bytes += pkt->skb->len;
135 u64_stats_update_end(&stats->syncp);
136 local_bh_enable();
137 }
131} 138}
132 139
133struct nft_jumpstack { 140struct nft_jumpstack {
diff --git a/net/netfilter/nfnetlink_acct.c b/net/netfilter/nfnetlink_acct.c
index b9505bcd3827..6ddf89183e7b 100644
--- a/net/netfilter/nfnetlink_acct.c
+++ b/net/netfilter/nfnetlink_acct.c
@@ -115,7 +115,7 @@ static int nfnl_acct_new(struct net *net, struct sock *nfnl,
115 nfacct->flags = flags; 115 nfacct->flags = flags;
116 } 116 }
117 117
118 strncpy(nfacct->name, nla_data(tb[NFACCT_NAME]), NFACCT_NAME_MAX); 118 nla_strlcpy(nfacct->name, nla_data(tb[NFACCT_NAME]), NFACCT_NAME_MAX);
119 119
120 if (tb[NFACCT_BYTES]) { 120 if (tb[NFACCT_BYTES]) {
121 atomic64_set(&nfacct->bytes, 121 atomic64_set(&nfacct->bytes,
diff --git a/net/netfilter/nfnetlink_cthelper.c b/net/netfilter/nfnetlink_cthelper.c
index 4a4b293fb2e5..fa026b269b36 100644
--- a/net/netfilter/nfnetlink_cthelper.c
+++ b/net/netfilter/nfnetlink_cthelper.c
@@ -149,8 +149,8 @@ nfnl_cthelper_expect_policy(struct nf_conntrack_expect_policy *expect_policy,
149 !tb[NFCTH_POLICY_EXPECT_TIMEOUT]) 149 !tb[NFCTH_POLICY_EXPECT_TIMEOUT])
150 return -EINVAL; 150 return -EINVAL;
151 151
152 strncpy(expect_policy->name, 152 nla_strlcpy(expect_policy->name,
153 nla_data(tb[NFCTH_POLICY_NAME]), NF_CT_HELPER_NAME_LEN); 153 nla_data(tb[NFCTH_POLICY_NAME]), NF_CT_HELPER_NAME_LEN);
154 expect_policy->max_expected = 154 expect_policy->max_expected =
155 ntohl(nla_get_be32(tb[NFCTH_POLICY_EXPECT_MAX])); 155 ntohl(nla_get_be32(tb[NFCTH_POLICY_EXPECT_MAX]));
156 if (expect_policy->max_expected > NF_CT_EXPECT_MAX_CNT) 156 if (expect_policy->max_expected > NF_CT_EXPECT_MAX_CNT)
@@ -234,7 +234,8 @@ nfnl_cthelper_create(const struct nlattr * const tb[],
234 if (ret < 0) 234 if (ret < 0)
235 goto err1; 235 goto err1;
236 236
237 strncpy(helper->name, nla_data(tb[NFCTH_NAME]), NF_CT_HELPER_NAME_LEN); 237 nla_strlcpy(helper->name,
238 nla_data(tb[NFCTH_NAME]), NF_CT_HELPER_NAME_LEN);
238 size = ntohl(nla_get_be32(tb[NFCTH_PRIV_DATA_LEN])); 239 size = ntohl(nla_get_be32(tb[NFCTH_PRIV_DATA_LEN]));
239 if (size > FIELD_SIZEOF(struct nf_conn_help, data)) { 240 if (size > FIELD_SIZEOF(struct nf_conn_help, data)) {
240 ret = -ENOMEM; 241 ret = -ENOMEM;
diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
index 8e23726b9081..1d99a1efdafc 100644
--- a/net/netfilter/nft_compat.c
+++ b/net/netfilter/nft_compat.c
@@ -27,14 +27,31 @@ struct nft_xt {
27 struct list_head head; 27 struct list_head head;
28 struct nft_expr_ops ops; 28 struct nft_expr_ops ops;
29 unsigned int refcnt; 29 unsigned int refcnt;
30
31 /* Unlike other expressions, ops doesn't have static storage duration.
32 * nft core assumes they do. We use kfree_rcu so that nft core can
33 * can check expr->ops->size even after nft_compat->destroy() frees
34 * the nft_xt struct that holds the ops structure.
35 */
36 struct rcu_head rcu_head;
37};
38
39/* Used for matches where *info is larger than X byte */
40#define NFT_MATCH_LARGE_THRESH 192
41
42struct nft_xt_match_priv {
43 void *info;
30}; 44};
31 45
32static void nft_xt_put(struct nft_xt *xt) 46static bool nft_xt_put(struct nft_xt *xt)
33{ 47{
34 if (--xt->refcnt == 0) { 48 if (--xt->refcnt == 0) {
35 list_del(&xt->head); 49 list_del(&xt->head);
36 kfree(xt); 50 kfree_rcu(xt, rcu_head);
51 return true;
37 } 52 }
53
54 return false;
38} 55}
39 56
40static int nft_compat_chain_validate_dependency(const char *tablename, 57static int nft_compat_chain_validate_dependency(const char *tablename,
@@ -226,6 +243,7 @@ nft_target_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
226 struct xt_target *target = expr->ops->data; 243 struct xt_target *target = expr->ops->data;
227 struct xt_tgchk_param par; 244 struct xt_tgchk_param par;
228 size_t size = XT_ALIGN(nla_len(tb[NFTA_TARGET_INFO])); 245 size_t size = XT_ALIGN(nla_len(tb[NFTA_TARGET_INFO]));
246 struct nft_xt *nft_xt;
229 u16 proto = 0; 247 u16 proto = 0;
230 bool inv = false; 248 bool inv = false;
231 union nft_entry e = {}; 249 union nft_entry e = {};
@@ -236,25 +254,22 @@ nft_target_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
236 if (ctx->nla[NFTA_RULE_COMPAT]) { 254 if (ctx->nla[NFTA_RULE_COMPAT]) {
237 ret = nft_parse_compat(ctx->nla[NFTA_RULE_COMPAT], &proto, &inv); 255 ret = nft_parse_compat(ctx->nla[NFTA_RULE_COMPAT], &proto, &inv);
238 if (ret < 0) 256 if (ret < 0)
239 goto err; 257 return ret;
240 } 258 }
241 259
242 nft_target_set_tgchk_param(&par, ctx, target, info, &e, proto, inv); 260 nft_target_set_tgchk_param(&par, ctx, target, info, &e, proto, inv);
243 261
244 ret = xt_check_target(&par, size, proto, inv); 262 ret = xt_check_target(&par, size, proto, inv);
245 if (ret < 0) 263 if (ret < 0)
246 goto err; 264 return ret;
247 265
248 /* The standard target cannot be used */ 266 /* The standard target cannot be used */
249 if (target->target == NULL) { 267 if (!target->target)
250 ret = -EINVAL; 268 return -EINVAL;
251 goto err;
252 }
253 269
270 nft_xt = container_of(expr->ops, struct nft_xt, ops);
271 nft_xt->refcnt++;
254 return 0; 272 return 0;
255err:
256 module_put(target->me);
257 return ret;
258} 273}
259 274
260static void 275static void
@@ -271,8 +286,8 @@ nft_target_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr)
271 if (par.target->destroy != NULL) 286 if (par.target->destroy != NULL)
272 par.target->destroy(&par); 287 par.target->destroy(&par);
273 288
274 nft_xt_put(container_of(expr->ops, struct nft_xt, ops)); 289 if (nft_xt_put(container_of(expr->ops, struct nft_xt, ops)))
275 module_put(target->me); 290 module_put(target->me);
276} 291}
277 292
278static int nft_target_dump(struct sk_buff *skb, const struct nft_expr *expr) 293static int nft_target_dump(struct sk_buff *skb, const struct nft_expr *expr)
@@ -316,11 +331,11 @@ static int nft_target_validate(const struct nft_ctx *ctx,
316 return 0; 331 return 0;
317} 332}
318 333
319static void nft_match_eval(const struct nft_expr *expr, 334static void __nft_match_eval(const struct nft_expr *expr,
320 struct nft_regs *regs, 335 struct nft_regs *regs,
321 const struct nft_pktinfo *pkt) 336 const struct nft_pktinfo *pkt,
337 void *info)
322{ 338{
323 void *info = nft_expr_priv(expr);
324 struct xt_match *match = expr->ops->data; 339 struct xt_match *match = expr->ops->data;
325 struct sk_buff *skb = pkt->skb; 340 struct sk_buff *skb = pkt->skb;
326 bool ret; 341 bool ret;
@@ -344,6 +359,22 @@ static void nft_match_eval(const struct nft_expr *expr,
344 } 359 }
345} 360}
346 361
362static void nft_match_large_eval(const struct nft_expr *expr,
363 struct nft_regs *regs,
364 const struct nft_pktinfo *pkt)
365{
366 struct nft_xt_match_priv *priv = nft_expr_priv(expr);
367
368 __nft_match_eval(expr, regs, pkt, priv->info);
369}
370
371static void nft_match_eval(const struct nft_expr *expr,
372 struct nft_regs *regs,
373 const struct nft_pktinfo *pkt)
374{
375 __nft_match_eval(expr, regs, pkt, nft_expr_priv(expr));
376}
377
347static const struct nla_policy nft_match_policy[NFTA_MATCH_MAX + 1] = { 378static const struct nla_policy nft_match_policy[NFTA_MATCH_MAX + 1] = {
348 [NFTA_MATCH_NAME] = { .type = NLA_NUL_STRING }, 379 [NFTA_MATCH_NAME] = { .type = NLA_NUL_STRING },
349 [NFTA_MATCH_REV] = { .type = NLA_U32 }, 380 [NFTA_MATCH_REV] = { .type = NLA_U32 },
@@ -404,13 +435,14 @@ static void match_compat_from_user(struct xt_match *m, void *in, void *out)
404} 435}
405 436
406static int 437static int
407nft_match_init(const struct nft_ctx *ctx, const struct nft_expr *expr, 438__nft_match_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
408 const struct nlattr * const tb[]) 439 const struct nlattr * const tb[],
440 void *info)
409{ 441{
410 void *info = nft_expr_priv(expr);
411 struct xt_match *match = expr->ops->data; 442 struct xt_match *match = expr->ops->data;
412 struct xt_mtchk_param par; 443 struct xt_mtchk_param par;
413 size_t size = XT_ALIGN(nla_len(tb[NFTA_MATCH_INFO])); 444 size_t size = XT_ALIGN(nla_len(tb[NFTA_MATCH_INFO]));
445 struct nft_xt *nft_xt;
414 u16 proto = 0; 446 u16 proto = 0;
415 bool inv = false; 447 bool inv = false;
416 union nft_entry e = {}; 448 union nft_entry e = {};
@@ -421,26 +453,50 @@ nft_match_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
421 if (ctx->nla[NFTA_RULE_COMPAT]) { 453 if (ctx->nla[NFTA_RULE_COMPAT]) {
422 ret = nft_parse_compat(ctx->nla[NFTA_RULE_COMPAT], &proto, &inv); 454 ret = nft_parse_compat(ctx->nla[NFTA_RULE_COMPAT], &proto, &inv);
423 if (ret < 0) 455 if (ret < 0)
424 goto err; 456 return ret;
425 } 457 }
426 458
427 nft_match_set_mtchk_param(&par, ctx, match, info, &e, proto, inv); 459 nft_match_set_mtchk_param(&par, ctx, match, info, &e, proto, inv);
428 460
429 ret = xt_check_match(&par, size, proto, inv); 461 ret = xt_check_match(&par, size, proto, inv);
430 if (ret < 0) 462 if (ret < 0)
431 goto err; 463 return ret;
432 464
465 nft_xt = container_of(expr->ops, struct nft_xt, ops);
466 nft_xt->refcnt++;
433 return 0; 467 return 0;
434err: 468}
435 module_put(match->me); 469
470static int
471nft_match_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
472 const struct nlattr * const tb[])
473{
474 return __nft_match_init(ctx, expr, tb, nft_expr_priv(expr));
475}
476
477static int
478nft_match_large_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
479 const struct nlattr * const tb[])
480{
481 struct nft_xt_match_priv *priv = nft_expr_priv(expr);
482 struct xt_match *m = expr->ops->data;
483 int ret;
484
485 priv->info = kmalloc(XT_ALIGN(m->matchsize), GFP_KERNEL);
486 if (!priv->info)
487 return -ENOMEM;
488
489 ret = __nft_match_init(ctx, expr, tb, priv->info);
490 if (ret)
491 kfree(priv->info);
436 return ret; 492 return ret;
437} 493}
438 494
439static void 495static void
440nft_match_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr) 496__nft_match_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr,
497 void *info)
441{ 498{
442 struct xt_match *match = expr->ops->data; 499 struct xt_match *match = expr->ops->data;
443 void *info = nft_expr_priv(expr);
444 struct xt_mtdtor_param par; 500 struct xt_mtdtor_param par;
445 501
446 par.net = ctx->net; 502 par.net = ctx->net;
@@ -450,13 +506,28 @@ nft_match_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr)
450 if (par.match->destroy != NULL) 506 if (par.match->destroy != NULL)
451 par.match->destroy(&par); 507 par.match->destroy(&par);
452 508
453 nft_xt_put(container_of(expr->ops, struct nft_xt, ops)); 509 if (nft_xt_put(container_of(expr->ops, struct nft_xt, ops)))
454 module_put(match->me); 510 module_put(match->me);
455} 511}
456 512
457static int nft_match_dump(struct sk_buff *skb, const struct nft_expr *expr) 513static void
514nft_match_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr)
515{
516 __nft_match_destroy(ctx, expr, nft_expr_priv(expr));
517}
518
519static void
520nft_match_large_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr)
521{
522 struct nft_xt_match_priv *priv = nft_expr_priv(expr);
523
524 __nft_match_destroy(ctx, expr, priv->info);
525 kfree(priv->info);
526}
527
528static int __nft_match_dump(struct sk_buff *skb, const struct nft_expr *expr,
529 void *info)
458{ 530{
459 void *info = nft_expr_priv(expr);
460 struct xt_match *match = expr->ops->data; 531 struct xt_match *match = expr->ops->data;
461 532
462 if (nla_put_string(skb, NFTA_MATCH_NAME, match->name) || 533 if (nla_put_string(skb, NFTA_MATCH_NAME, match->name) ||
@@ -470,6 +541,18 @@ nla_put_failure:
470 return -1; 541 return -1;
471} 542}
472 543
544static int nft_match_dump(struct sk_buff *skb, const struct nft_expr *expr)
545{
546 return __nft_match_dump(skb, expr, nft_expr_priv(expr));
547}
548
549static int nft_match_large_dump(struct sk_buff *skb, const struct nft_expr *e)
550{
551 struct nft_xt_match_priv *priv = nft_expr_priv(e);
552
553 return __nft_match_dump(skb, e, priv->info);
554}
555
473static int nft_match_validate(const struct nft_ctx *ctx, 556static int nft_match_validate(const struct nft_ctx *ctx,
474 const struct nft_expr *expr, 557 const struct nft_expr *expr,
475 const struct nft_data **data) 558 const struct nft_data **data)
@@ -637,6 +720,7 @@ nft_match_select_ops(const struct nft_ctx *ctx,
637{ 720{
638 struct nft_xt *nft_match; 721 struct nft_xt *nft_match;
639 struct xt_match *match; 722 struct xt_match *match;
723 unsigned int matchsize;
640 char *mt_name; 724 char *mt_name;
641 u32 rev, family; 725 u32 rev, family;
642 int err; 726 int err;
@@ -654,13 +738,8 @@ nft_match_select_ops(const struct nft_ctx *ctx,
654 list_for_each_entry(nft_match, &nft_match_list, head) { 738 list_for_each_entry(nft_match, &nft_match_list, head) {
655 struct xt_match *match = nft_match->ops.data; 739 struct xt_match *match = nft_match->ops.data;
656 740
657 if (nft_match_cmp(match, mt_name, rev, family)) { 741 if (nft_match_cmp(match, mt_name, rev, family))
658 if (!try_module_get(match->me))
659 return ERR_PTR(-ENOENT);
660
661 nft_match->refcnt++;
662 return &nft_match->ops; 742 return &nft_match->ops;
663 }
664 } 743 }
665 744
666 match = xt_request_find_match(family, mt_name, rev); 745 match = xt_request_find_match(family, mt_name, rev);
@@ -679,9 +758,8 @@ nft_match_select_ops(const struct nft_ctx *ctx,
679 goto err; 758 goto err;
680 } 759 }
681 760
682 nft_match->refcnt = 1; 761 nft_match->refcnt = 0;
683 nft_match->ops.type = &nft_match_type; 762 nft_match->ops.type = &nft_match_type;
684 nft_match->ops.size = NFT_EXPR_SIZE(XT_ALIGN(match->matchsize));
685 nft_match->ops.eval = nft_match_eval; 763 nft_match->ops.eval = nft_match_eval;
686 nft_match->ops.init = nft_match_init; 764 nft_match->ops.init = nft_match_init;
687 nft_match->ops.destroy = nft_match_destroy; 765 nft_match->ops.destroy = nft_match_destroy;
@@ -689,6 +767,18 @@ nft_match_select_ops(const struct nft_ctx *ctx,
689 nft_match->ops.validate = nft_match_validate; 767 nft_match->ops.validate = nft_match_validate;
690 nft_match->ops.data = match; 768 nft_match->ops.data = match;
691 769
770 matchsize = NFT_EXPR_SIZE(XT_ALIGN(match->matchsize));
771 if (matchsize > NFT_MATCH_LARGE_THRESH) {
772 matchsize = NFT_EXPR_SIZE(sizeof(struct nft_xt_match_priv));
773
774 nft_match->ops.eval = nft_match_large_eval;
775 nft_match->ops.init = nft_match_large_init;
776 nft_match->ops.destroy = nft_match_large_destroy;
777 nft_match->ops.dump = nft_match_large_dump;
778 }
779
780 nft_match->ops.size = matchsize;
781
692 list_add(&nft_match->head, &nft_match_list); 782 list_add(&nft_match->head, &nft_match_list);
693 783
694 return &nft_match->ops; 784 return &nft_match->ops;
@@ -739,13 +829,8 @@ nft_target_select_ops(const struct nft_ctx *ctx,
739 list_for_each_entry(nft_target, &nft_target_list, head) { 829 list_for_each_entry(nft_target, &nft_target_list, head) {
740 struct xt_target *target = nft_target->ops.data; 830 struct xt_target *target = nft_target->ops.data;
741 831
742 if (nft_target_cmp(target, tg_name, rev, family)) { 832 if (nft_target_cmp(target, tg_name, rev, family))
743 if (!try_module_get(target->me))
744 return ERR_PTR(-ENOENT);
745
746 nft_target->refcnt++;
747 return &nft_target->ops; 833 return &nft_target->ops;
748 }
749 } 834 }
750 835
751 target = xt_request_find_target(family, tg_name, rev); 836 target = xt_request_find_target(family, tg_name, rev);
@@ -764,7 +849,7 @@ nft_target_select_ops(const struct nft_ctx *ctx,
764 goto err; 849 goto err;
765 } 850 }
766 851
767 nft_target->refcnt = 1; 852 nft_target->refcnt = 0;
768 nft_target->ops.type = &nft_target_type; 853 nft_target->ops.type = &nft_target_type;
769 nft_target->ops.size = NFT_EXPR_SIZE(XT_ALIGN(target->targetsize)); 854 nft_target->ops.size = NFT_EXPR_SIZE(XT_ALIGN(target->targetsize));
770 nft_target->ops.init = nft_target_init; 855 nft_target->ops.init = nft_target_init;
@@ -823,6 +908,32 @@ err_match:
823 908
824static void __exit nft_compat_module_exit(void) 909static void __exit nft_compat_module_exit(void)
825{ 910{
911 struct nft_xt *xt, *next;
912
913 /* list should be empty here, it can be non-empty only in case there
914 * was an error that caused nft_xt expr to not be initialized fully
915 * and noone else requested the same expression later.
916 *
917 * In this case, the lists contain 0-refcount entries that still
918 * hold module reference.
919 */
920 list_for_each_entry_safe(xt, next, &nft_target_list, head) {
921 struct xt_target *target = xt->ops.data;
922
923 if (WARN_ON_ONCE(xt->refcnt))
924 continue;
925 module_put(target->me);
926 kfree(xt);
927 }
928
929 list_for_each_entry_safe(xt, next, &nft_match_list, head) {
930 struct xt_match *match = xt->ops.data;
931
932 if (WARN_ON_ONCE(xt->refcnt))
933 continue;
934 module_put(match->me);
935 kfree(xt);
936 }
826 nfnetlink_subsys_unregister(&nfnl_compat_subsys); 937 nfnetlink_subsys_unregister(&nfnl_compat_subsys);
827 nft_unregister_expr(&nft_target_type); 938 nft_unregister_expr(&nft_target_type);
828 nft_unregister_expr(&nft_match_type); 939 nft_unregister_expr(&nft_match_type);
diff --git a/net/netfilter/nft_immediate.c b/net/netfilter/nft_immediate.c
index 4717d7796927..aa87ff8beae8 100644
--- a/net/netfilter/nft_immediate.c
+++ b/net/netfilter/nft_immediate.c
@@ -69,8 +69,16 @@ err1:
69 return err; 69 return err;
70} 70}
71 71
72static void nft_immediate_destroy(const struct nft_ctx *ctx, 72static void nft_immediate_activate(const struct nft_ctx *ctx,
73 const struct nft_expr *expr) 73 const struct nft_expr *expr)
74{
75 const struct nft_immediate_expr *priv = nft_expr_priv(expr);
76
77 return nft_data_hold(&priv->data, nft_dreg_to_type(priv->dreg));
78}
79
80static void nft_immediate_deactivate(const struct nft_ctx *ctx,
81 const struct nft_expr *expr)
74{ 82{
75 const struct nft_immediate_expr *priv = nft_expr_priv(expr); 83 const struct nft_immediate_expr *priv = nft_expr_priv(expr);
76 84
@@ -108,7 +116,8 @@ static const struct nft_expr_ops nft_imm_ops = {
108 .size = NFT_EXPR_SIZE(sizeof(struct nft_immediate_expr)), 116 .size = NFT_EXPR_SIZE(sizeof(struct nft_immediate_expr)),
109 .eval = nft_immediate_eval, 117 .eval = nft_immediate_eval,
110 .init = nft_immediate_init, 118 .init = nft_immediate_init,
111 .destroy = nft_immediate_destroy, 119 .activate = nft_immediate_activate,
120 .deactivate = nft_immediate_deactivate,
112 .dump = nft_immediate_dump, 121 .dump = nft_immediate_dump,
113 .validate = nft_immediate_validate, 122 .validate = nft_immediate_validate,
114}; 123};
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index 71325fef647d..cb7cb300c3bc 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -183,6 +183,9 @@ struct xt_match *xt_find_match(u8 af, const char *name, u8 revision)
183 struct xt_match *m; 183 struct xt_match *m;
184 int err = -ENOENT; 184 int err = -ENOENT;
185 185
186 if (strnlen(name, XT_EXTENSION_MAXNAMELEN) == XT_EXTENSION_MAXNAMELEN)
187 return ERR_PTR(-EINVAL);
188
186 mutex_lock(&xt[af].mutex); 189 mutex_lock(&xt[af].mutex);
187 list_for_each_entry(m, &xt[af].match, list) { 190 list_for_each_entry(m, &xt[af].match, list) {
188 if (strcmp(m->name, name) == 0) { 191 if (strcmp(m->name, name) == 0) {
@@ -229,6 +232,9 @@ struct xt_target *xt_find_target(u8 af, const char *name, u8 revision)
229 struct xt_target *t; 232 struct xt_target *t;
230 int err = -ENOENT; 233 int err = -ENOENT;
231 234
235 if (strnlen(name, XT_EXTENSION_MAXNAMELEN) == XT_EXTENSION_MAXNAMELEN)
236 return ERR_PTR(-EINVAL);
237
232 mutex_lock(&xt[af].mutex); 238 mutex_lock(&xt[af].mutex);
233 list_for_each_entry(t, &xt[af].target, list) { 239 list_for_each_entry(t, &xt[af].target, list) {
234 if (strcmp(t->name, name) == 0) { 240 if (strcmp(t->name, name) == 0) {
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 01f3515cada0..acb7b86574cd 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2903,13 +2903,15 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
2903 if (skb == NULL) 2903 if (skb == NULL)
2904 goto out_unlock; 2904 goto out_unlock;
2905 2905
2906 skb_set_network_header(skb, reserve); 2906 skb_reset_network_header(skb);
2907 2907
2908 err = -EINVAL; 2908 err = -EINVAL;
2909 if (sock->type == SOCK_DGRAM) { 2909 if (sock->type == SOCK_DGRAM) {
2910 offset = dev_hard_header(skb, dev, ntohs(proto), addr, NULL, len); 2910 offset = dev_hard_header(skb, dev, ntohs(proto), addr, NULL, len);
2911 if (unlikely(offset < 0)) 2911 if (unlikely(offset < 0))
2912 goto out_free; 2912 goto out_free;
2913 } else if (reserve) {
2914 skb_reserve(skb, -reserve);
2913 } 2915 }
2914 2916
2915 /* Returns -EFAULT on error */ 2917 /* Returns -EFAULT on error */
diff --git a/net/rds/Kconfig b/net/rds/Kconfig
index bffde4b46c5d..1a31502ee7db 100644
--- a/net/rds/Kconfig
+++ b/net/rds/Kconfig
@@ -8,7 +8,7 @@ config RDS
8 8
9config RDS_RDMA 9config RDS_RDMA
10 tristate "RDS over Infiniband" 10 tristate "RDS over Infiniband"
11 depends on RDS && INFINIBAND && INFINIBAND_ADDR_TRANS 11 depends on RDS && INFINIBAND_ADDR_TRANS
12 ---help--- 12 ---help---
13 Allow RDS to use Infiniband as a transport. 13 Allow RDS to use Infiniband as a transport.
14 This transport supports RDMA operations. 14 This transport supports RDMA operations.
diff --git a/net/sched/act_vlan.c b/net/sched/act_vlan.c
index 853604685965..1fb39e1f9d07 100644
--- a/net/sched/act_vlan.c
+++ b/net/sched/act_vlan.c
@@ -161,6 +161,8 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla,
161 case htons(ETH_P_8021AD): 161 case htons(ETH_P_8021AD):
162 break; 162 break;
163 default: 163 default:
164 if (exists)
165 tcf_idr_release(*a, bind);
164 return -EPROTONOSUPPORT; 166 return -EPROTONOSUPPORT;
165 } 167 }
166 } else { 168 } else {
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 963e4bf0aab8..a57e112d9b3e 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -1588,7 +1588,7 @@ int tc_setup_cb_call(struct tcf_block *block, struct tcf_exts *exts,
1588 return ret; 1588 return ret;
1589 ok_count = ret; 1589 ok_count = ret;
1590 1590
1591 if (!exts) 1591 if (!exts || ok_count)
1592 return ok_count; 1592 return ok_count;
1593 ret = tc_exts_setup_cb_egdev_call(exts, type, type_data, err_stop); 1593 ret = tc_exts_setup_cb_egdev_call(exts, type, type_data, err_stop);
1594 if (ret < 0) 1594 if (ret < 0)
diff --git a/net/sched/sch_red.c b/net/sched/sch_red.c
index 16644b3d2362..56c181c3feeb 100644
--- a/net/sched/sch_red.c
+++ b/net/sched/sch_red.c
@@ -222,10 +222,11 @@ static int red_change(struct Qdisc *sch, struct nlattr *opt,
222 extack); 222 extack);
223 if (IS_ERR(child)) 223 if (IS_ERR(child))
224 return PTR_ERR(child); 224 return PTR_ERR(child);
225 }
226 225
227 if (child != &noop_qdisc) 226 /* child is fifo, no need to check for noop_qdisc */
228 qdisc_hash_add(child, true); 227 qdisc_hash_add(child, true);
228 }
229
229 sch_tree_lock(sch); 230 sch_tree_lock(sch);
230 q->flags = ctl->flags; 231 q->flags = ctl->flags;
231 q->limit = ctl->limit; 232 q->limit = ctl->limit;
diff --git a/net/sched/sch_tbf.c b/net/sched/sch_tbf.c
index 03225a8df973..6f74a426f159 100644
--- a/net/sched/sch_tbf.c
+++ b/net/sched/sch_tbf.c
@@ -383,6 +383,9 @@ static int tbf_change(struct Qdisc *sch, struct nlattr *opt,
383 err = PTR_ERR(child); 383 err = PTR_ERR(child);
384 goto done; 384 goto done;
385 } 385 }
386
387 /* child is fifo, no need to check for noop_qdisc */
388 qdisc_hash_add(child, true);
386 } 389 }
387 390
388 sch_tree_lock(sch); 391 sch_tree_lock(sch);
@@ -391,8 +394,6 @@ static int tbf_change(struct Qdisc *sch, struct nlattr *opt,
391 q->qdisc->qstats.backlog); 394 q->qdisc->qstats.backlog);
392 qdisc_destroy(q->qdisc); 395 qdisc_destroy(q->qdisc);
393 q->qdisc = child; 396 q->qdisc = child;
394 if (child != &noop_qdisc)
395 qdisc_hash_add(child, true);
396 } 397 }
397 q->limit = qopt->limit; 398 q->limit = qopt->limit;
398 if (tb[TCA_TBF_PBURST]) 399 if (tb[TCA_TBF_PBURST])
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index 42247110d842..0cd2e764f47f 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -1006,7 +1006,7 @@ static const struct proto_ops inet6_seqpacket_ops = {
1006 .owner = THIS_MODULE, 1006 .owner = THIS_MODULE,
1007 .release = inet6_release, 1007 .release = inet6_release,
1008 .bind = inet6_bind, 1008 .bind = inet6_bind,
1009 .connect = inet_dgram_connect, 1009 .connect = sctp_inet_connect,
1010 .socketpair = sock_no_socketpair, 1010 .socketpair = sock_no_socketpair,
1011 .accept = inet_accept, 1011 .accept = inet_accept,
1012 .getname = sctp_getname, 1012 .getname = sctp_getname,
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index d685f8456762..6bf0a9971888 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -1012,7 +1012,7 @@ static const struct proto_ops inet_seqpacket_ops = {
1012 .owner = THIS_MODULE, 1012 .owner = THIS_MODULE,
1013 .release = inet_release, /* Needs to be wrapped... */ 1013 .release = inet_release, /* Needs to be wrapped... */
1014 .bind = inet_bind, 1014 .bind = inet_bind,
1015 .connect = inet_dgram_connect, 1015 .connect = sctp_inet_connect,
1016 .socketpair = sock_no_socketpair, 1016 .socketpair = sock_no_socketpair,
1017 .accept = inet_accept, 1017 .accept = inet_accept,
1018 .getname = inet_getname, /* Semantics are different. */ 1018 .getname = inet_getname, /* Semantics are different. */
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 80835ac26d2c..ae7e7c606f72 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -1086,7 +1086,7 @@ out:
1086 */ 1086 */
1087static int __sctp_connect(struct sock *sk, 1087static int __sctp_connect(struct sock *sk,
1088 struct sockaddr *kaddrs, 1088 struct sockaddr *kaddrs,
1089 int addrs_size, 1089 int addrs_size, int flags,
1090 sctp_assoc_t *assoc_id) 1090 sctp_assoc_t *assoc_id)
1091{ 1091{
1092 struct net *net = sock_net(sk); 1092 struct net *net = sock_net(sk);
@@ -1104,7 +1104,6 @@ static int __sctp_connect(struct sock *sk,
1104 union sctp_addr *sa_addr = NULL; 1104 union sctp_addr *sa_addr = NULL;
1105 void *addr_buf; 1105 void *addr_buf;
1106 unsigned short port; 1106 unsigned short port;
1107 unsigned int f_flags = 0;
1108 1107
1109 sp = sctp_sk(sk); 1108 sp = sctp_sk(sk);
1110 ep = sp->ep; 1109 ep = sp->ep;
@@ -1254,13 +1253,7 @@ static int __sctp_connect(struct sock *sk,
1254 sp->pf->to_sk_daddr(sa_addr, sk); 1253 sp->pf->to_sk_daddr(sa_addr, sk);
1255 sk->sk_err = 0; 1254 sk->sk_err = 0;
1256 1255
1257 /* in-kernel sockets don't generally have a file allocated to them 1256 timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
1258 * if all they do is call sock_create_kern().
1259 */
1260 if (sk->sk_socket->file)
1261 f_flags = sk->sk_socket->file->f_flags;
1262
1263 timeo = sock_sndtimeo(sk, f_flags & O_NONBLOCK);
1264 1257
1265 if (assoc_id) 1258 if (assoc_id)
1266 *assoc_id = asoc->assoc_id; 1259 *assoc_id = asoc->assoc_id;
@@ -1348,7 +1341,7 @@ static int __sctp_setsockopt_connectx(struct sock *sk,
1348 sctp_assoc_t *assoc_id) 1341 sctp_assoc_t *assoc_id)
1349{ 1342{
1350 struct sockaddr *kaddrs; 1343 struct sockaddr *kaddrs;
1351 int err = 0; 1344 int err = 0, flags = 0;
1352 1345
1353 pr_debug("%s: sk:%p addrs:%p addrs_size:%d\n", 1346 pr_debug("%s: sk:%p addrs:%p addrs_size:%d\n",
1354 __func__, sk, addrs, addrs_size); 1347 __func__, sk, addrs, addrs_size);
@@ -1367,7 +1360,13 @@ static int __sctp_setsockopt_connectx(struct sock *sk,
1367 if (err) 1360 if (err)
1368 goto out_free; 1361 goto out_free;
1369 1362
1370 err = __sctp_connect(sk, kaddrs, addrs_size, assoc_id); 1363 /* in-kernel sockets don't generally have a file allocated to them
1364 * if all they do is call sock_create_kern().
1365 */
1366 if (sk->sk_socket->file)
1367 flags = sk->sk_socket->file->f_flags;
1368
1369 err = __sctp_connect(sk, kaddrs, addrs_size, flags, assoc_id);
1371 1370
1372out_free: 1371out_free:
1373 kvfree(kaddrs); 1372 kvfree(kaddrs);
@@ -4397,16 +4396,26 @@ out_nounlock:
4397 * len: the size of the address. 4396 * len: the size of the address.
4398 */ 4397 */
4399static int sctp_connect(struct sock *sk, struct sockaddr *addr, 4398static int sctp_connect(struct sock *sk, struct sockaddr *addr,
4400 int addr_len) 4399 int addr_len, int flags)
4401{ 4400{
4402 int err = 0; 4401 struct inet_sock *inet = inet_sk(sk);
4403 struct sctp_af *af; 4402 struct sctp_af *af;
4403 int err = 0;
4404 4404
4405 lock_sock(sk); 4405 lock_sock(sk);
4406 4406
4407 pr_debug("%s: sk:%p, sockaddr:%p, addr_len:%d\n", __func__, sk, 4407 pr_debug("%s: sk:%p, sockaddr:%p, addr_len:%d\n", __func__, sk,
4408 addr, addr_len); 4408 addr, addr_len);
4409 4409
4410 /* We may need to bind the socket. */
4411 if (!inet->inet_num) {
4412 if (sk->sk_prot->get_port(sk, 0)) {
4413 release_sock(sk);
4414 return -EAGAIN;
4415 }
4416 inet->inet_sport = htons(inet->inet_num);
4417 }
4418
4410 /* Validate addr_len before calling common connect/connectx routine. */ 4419 /* Validate addr_len before calling common connect/connectx routine. */
4411 af = sctp_get_af_specific(addr->sa_family); 4420 af = sctp_get_af_specific(addr->sa_family);
4412 if (!af || addr_len < af->sockaddr_len) { 4421 if (!af || addr_len < af->sockaddr_len) {
@@ -4415,13 +4424,25 @@ static int sctp_connect(struct sock *sk, struct sockaddr *addr,
4415 /* Pass correct addr len to common routine (so it knows there 4424 /* Pass correct addr len to common routine (so it knows there
4416 * is only one address being passed. 4425 * is only one address being passed.
4417 */ 4426 */
4418 err = __sctp_connect(sk, addr, af->sockaddr_len, NULL); 4427 err = __sctp_connect(sk, addr, af->sockaddr_len, flags, NULL);
4419 } 4428 }
4420 4429
4421 release_sock(sk); 4430 release_sock(sk);
4422 return err; 4431 return err;
4423} 4432}
4424 4433
4434int sctp_inet_connect(struct socket *sock, struct sockaddr *uaddr,
4435 int addr_len, int flags)
4436{
4437 if (addr_len < sizeof(uaddr->sa_family))
4438 return -EINVAL;
4439
4440 if (uaddr->sa_family == AF_UNSPEC)
4441 return -EOPNOTSUPP;
4442
4443 return sctp_connect(sock->sk, uaddr, addr_len, flags);
4444}
4445
4425/* FIXME: Write comments. */ 4446/* FIXME: Write comments. */
4426static int sctp_disconnect(struct sock *sk, int flags) 4447static int sctp_disconnect(struct sock *sk, int flags)
4427{ 4448{
@@ -8724,7 +8745,6 @@ struct proto sctp_prot = {
8724 .name = "SCTP", 8745 .name = "SCTP",
8725 .owner = THIS_MODULE, 8746 .owner = THIS_MODULE,
8726 .close = sctp_close, 8747 .close = sctp_close,
8727 .connect = sctp_connect,
8728 .disconnect = sctp_disconnect, 8748 .disconnect = sctp_disconnect,
8729 .accept = sctp_accept, 8749 .accept = sctp_accept,
8730 .ioctl = sctp_ioctl, 8750 .ioctl = sctp_ioctl,
@@ -8767,7 +8787,6 @@ struct proto sctpv6_prot = {
8767 .name = "SCTPv6", 8787 .name = "SCTPv6",
8768 .owner = THIS_MODULE, 8788 .owner = THIS_MODULE,
8769 .close = sctp_close, 8789 .close = sctp_close,
8770 .connect = sctp_connect,
8771 .disconnect = sctp_disconnect, 8790 .disconnect = sctp_disconnect,
8772 .accept = sctp_accept, 8791 .accept = sctp_accept,
8773 .ioctl = sctp_ioctl, 8792 .ioctl = sctp_ioctl,
diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c
index 74568cdbca70..d7b88b2d1b22 100644
--- a/net/smc/smc_pnet.c
+++ b/net/smc/smc_pnet.c
@@ -245,40 +245,45 @@ out:
245static int smc_pnet_fill_entry(struct net *net, struct smc_pnetentry *pnetelem, 245static int smc_pnet_fill_entry(struct net *net, struct smc_pnetentry *pnetelem,
246 struct nlattr *tb[]) 246 struct nlattr *tb[])
247{ 247{
248 char *string, *ibname = NULL; 248 char *string, *ibname;
249 int rc = 0; 249 int rc;
250 250
251 memset(pnetelem, 0, sizeof(*pnetelem)); 251 memset(pnetelem, 0, sizeof(*pnetelem));
252 INIT_LIST_HEAD(&pnetelem->list); 252 INIT_LIST_HEAD(&pnetelem->list);
253 if (tb[SMC_PNETID_NAME]) { 253
254 string = (char *)nla_data(tb[SMC_PNETID_NAME]); 254 rc = -EINVAL;
255 if (!smc_pnetid_valid(string, pnetelem->pnet_name)) { 255 if (!tb[SMC_PNETID_NAME])
256 rc = -EINVAL; 256 goto error;
257 goto error; 257 string = (char *)nla_data(tb[SMC_PNETID_NAME]);
258 } 258 if (!smc_pnetid_valid(string, pnetelem->pnet_name))
259 } 259 goto error;
260 if (tb[SMC_PNETID_ETHNAME]) { 260
261 string = (char *)nla_data(tb[SMC_PNETID_ETHNAME]); 261 rc = -EINVAL;
262 pnetelem->ndev = dev_get_by_name(net, string); 262 if (!tb[SMC_PNETID_ETHNAME])
263 if (!pnetelem->ndev) 263 goto error;
264 return -ENOENT; 264 rc = -ENOENT;
265 } 265 string = (char *)nla_data(tb[SMC_PNETID_ETHNAME]);
266 if (tb[SMC_PNETID_IBNAME]) { 266 pnetelem->ndev = dev_get_by_name(net, string);
267 ibname = (char *)nla_data(tb[SMC_PNETID_IBNAME]); 267 if (!pnetelem->ndev)
268 ibname = strim(ibname); 268 goto error;
269 pnetelem->smcibdev = smc_pnet_find_ib(ibname); 269
270 if (!pnetelem->smcibdev) { 270 rc = -EINVAL;
271 rc = -ENOENT; 271 if (!tb[SMC_PNETID_IBNAME])
272 goto error; 272 goto error;
273 } 273 rc = -ENOENT;
274 } 274 ibname = (char *)nla_data(tb[SMC_PNETID_IBNAME]);
275 if (tb[SMC_PNETID_IBPORT]) { 275 ibname = strim(ibname);
276 pnetelem->ib_port = nla_get_u8(tb[SMC_PNETID_IBPORT]); 276 pnetelem->smcibdev = smc_pnet_find_ib(ibname);
277 if (pnetelem->ib_port > SMC_MAX_PORTS) { 277 if (!pnetelem->smcibdev)
278 rc = -EINVAL; 278 goto error;
279 goto error; 279
280 } 280 rc = -EINVAL;
281 } 281 if (!tb[SMC_PNETID_IBPORT])
282 goto error;
283 pnetelem->ib_port = nla_get_u8(tb[SMC_PNETID_IBPORT]);
284 if (pnetelem->ib_port < 1 || pnetelem->ib_port > SMC_MAX_PORTS)
285 goto error;
286
282 return 0; 287 return 0;
283 288
284error: 289error:
@@ -307,6 +312,8 @@ static int smc_pnet_get(struct sk_buff *skb, struct genl_info *info)
307 void *hdr; 312 void *hdr;
308 int rc; 313 int rc;
309 314
315 if (!info->attrs[SMC_PNETID_NAME])
316 return -EINVAL;
310 pnetelem = smc_pnet_find_pnetid( 317 pnetelem = smc_pnet_find_pnetid(
311 (char *)nla_data(info->attrs[SMC_PNETID_NAME])); 318 (char *)nla_data(info->attrs[SMC_PNETID_NAME]));
312 if (!pnetelem) 319 if (!pnetelem)
@@ -359,6 +366,8 @@ static int smc_pnet_add(struct sk_buff *skb, struct genl_info *info)
359 366
360static int smc_pnet_del(struct sk_buff *skb, struct genl_info *info) 367static int smc_pnet_del(struct sk_buff *skb, struct genl_info *info)
361{ 368{
369 if (!info->attrs[SMC_PNETID_NAME])
370 return -EINVAL;
362 return smc_pnet_remove_by_pnetid( 371 return smc_pnet_remove_by_pnetid(
363 (char *)nla_data(info->attrs[SMC_PNETID_NAME])); 372 (char *)nla_data(info->attrs[SMC_PNETID_NAME]));
364} 373}
diff --git a/net/sunrpc/Kconfig b/net/sunrpc/Kconfig
index ac09ca803296..6358e5271070 100644
--- a/net/sunrpc/Kconfig
+++ b/net/sunrpc/Kconfig
@@ -50,7 +50,7 @@ config SUNRPC_DEBUG
50 50
51config SUNRPC_XPRT_RDMA 51config SUNRPC_XPRT_RDMA
52 tristate "RPC-over-RDMA transport" 52 tristate "RPC-over-RDMA transport"
53 depends on SUNRPC && INFINIBAND && INFINIBAND_ADDR_TRANS 53 depends on SUNRPC && INFINIBAND_ADDR_TRANS
54 default SUNRPC && INFINIBAND 54 default SUNRPC && INFINIBAND
55 select SG_POOL 55 select SG_POOL
56 help 56 help
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index 71e79597f940..e1c93ce74e0f 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -680,7 +680,6 @@ static int decrypt_skb(struct sock *sk, struct sk_buff *skb,
680 struct scatterlist *sgin = &sgin_arr[0]; 680 struct scatterlist *sgin = &sgin_arr[0];
681 struct strp_msg *rxm = strp_msg(skb); 681 struct strp_msg *rxm = strp_msg(skb);
682 int ret, nsg = ARRAY_SIZE(sgin_arr); 682 int ret, nsg = ARRAY_SIZE(sgin_arr);
683 char aad_recv[TLS_AAD_SPACE_SIZE];
684 struct sk_buff *unused; 683 struct sk_buff *unused;
685 684
686 ret = skb_copy_bits(skb, rxm->offset + TLS_HEADER_SIZE, 685 ret = skb_copy_bits(skb, rxm->offset + TLS_HEADER_SIZE,
@@ -698,13 +697,13 @@ static int decrypt_skb(struct sock *sk, struct sk_buff *skb,
698 } 697 }
699 698
700 sg_init_table(sgin, nsg); 699 sg_init_table(sgin, nsg);
701 sg_set_buf(&sgin[0], aad_recv, sizeof(aad_recv)); 700 sg_set_buf(&sgin[0], ctx->rx_aad_ciphertext, TLS_AAD_SPACE_SIZE);
702 701
703 nsg = skb_to_sgvec(skb, &sgin[1], 702 nsg = skb_to_sgvec(skb, &sgin[1],
704 rxm->offset + tls_ctx->rx.prepend_size, 703 rxm->offset + tls_ctx->rx.prepend_size,
705 rxm->full_len - tls_ctx->rx.prepend_size); 704 rxm->full_len - tls_ctx->rx.prepend_size);
706 705
707 tls_make_aad(aad_recv, 706 tls_make_aad(ctx->rx_aad_ciphertext,
708 rxm->full_len - tls_ctx->rx.overhead_size, 707 rxm->full_len - tls_ctx->rx.overhead_size,
709 tls_ctx->rx.rec_seq, 708 tls_ctx->rx.rec_seq,
710 tls_ctx->rx.rec_seq_size, 709 tls_ctx->rx.rec_seq_size,
@@ -803,12 +802,12 @@ int tls_sw_recvmsg(struct sock *sk,
803 if (to_copy <= len && page_count < MAX_SKB_FRAGS && 802 if (to_copy <= len && page_count < MAX_SKB_FRAGS &&
804 likely(!(flags & MSG_PEEK))) { 803 likely(!(flags & MSG_PEEK))) {
805 struct scatterlist sgin[MAX_SKB_FRAGS + 1]; 804 struct scatterlist sgin[MAX_SKB_FRAGS + 1];
806 char unused[21];
807 int pages = 0; 805 int pages = 0;
808 806
809 zc = true; 807 zc = true;
810 sg_init_table(sgin, MAX_SKB_FRAGS + 1); 808 sg_init_table(sgin, MAX_SKB_FRAGS + 1);
811 sg_set_buf(&sgin[0], unused, 13); 809 sg_set_buf(&sgin[0], ctx->rx_aad_plaintext,
810 TLS_AAD_SPACE_SIZE);
812 811
813 err = zerocopy_from_iter(sk, &msg->msg_iter, 812 err = zerocopy_from_iter(sk, &msg->msg_iter,
814 to_copy, &pages, 813 to_copy, &pages,
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index a052693c2e85..7c5135a92d76 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -15555,7 +15555,8 @@ void cfg80211_ft_event(struct net_device *netdev,
15555 if (!ft_event->target_ap) 15555 if (!ft_event->target_ap)
15556 return; 15556 return;
15557 15557
15558 msg = nlmsg_new(100 + ft_event->ric_ies_len, GFP_KERNEL); 15558 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
15559 GFP_KERNEL);
15559 if (!msg) 15560 if (!msg)
15560 return; 15561 return;
15561 15562
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index ac3e12c32aa3..5fcec5c94eb7 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -916,6 +916,9 @@ int reg_query_regdb_wmm(char *alpha2, int freq, u32 *dbptr,
916 const struct fwdb_header *hdr = regdb; 916 const struct fwdb_header *hdr = regdb;
917 const struct fwdb_country *country; 917 const struct fwdb_country *country;
918 918
919 if (!regdb)
920 return -ENODATA;
921
919 if (IS_ERR(regdb)) 922 if (IS_ERR(regdb))
920 return PTR_ERR(regdb); 923 return PTR_ERR(regdb);
921 924
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e16d6713f236..2d42eb9cd1a5 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5041,7 +5041,7 @@ sub process {
5041 $tmp_stmt =~ s/\b(typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g; 5041 $tmp_stmt =~ s/\b(typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g;
5042 $tmp_stmt =~ s/\#+\s*$arg\b//g; 5042 $tmp_stmt =~ s/\#+\s*$arg\b//g;
5043 $tmp_stmt =~ s/\b$arg\s*\#\#//g; 5043 $tmp_stmt =~ s/\b$arg\s*\#\#//g;
5044 my $use_cnt = $tmp_stmt =~ s/\b$arg\b//g; 5044 my $use_cnt = () = $tmp_stmt =~ /\b$arg\b/g;
5045 if ($use_cnt > 1) { 5045 if ($use_cnt > 1) {
5046 CHK("MACRO_ARG_REUSE", 5046 CHK("MACRO_ARG_REUSE",
5047 "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx"); 5047 "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx");
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index be5817df0a9d..179dd20bec0a 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -1568,8 +1568,15 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent
1568 /* Called from d_instantiate or d_splice_alias. */ 1568 /* Called from d_instantiate or d_splice_alias. */
1569 dentry = dget(opt_dentry); 1569 dentry = dget(opt_dentry);
1570 } else { 1570 } else {
1571 /* Called from selinux_complete_init, try to find a dentry. */ 1571 /*
1572 * Called from selinux_complete_init, try to find a dentry.
1573 * Some filesystems really want a connected one, so try
1574 * that first. We could split SECURITY_FS_USE_XATTR in
1575 * two, depending upon that...
1576 */
1572 dentry = d_find_alias(inode); 1577 dentry = d_find_alias(inode);
1578 if (!dentry)
1579 dentry = d_find_any_alias(inode);
1573 } 1580 }
1574 if (!dentry) { 1581 if (!dentry) {
1575 /* 1582 /*
@@ -1674,14 +1681,19 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent
1674 if ((sbsec->flags & SE_SBGENFS) && !S_ISLNK(inode->i_mode)) { 1681 if ((sbsec->flags & SE_SBGENFS) && !S_ISLNK(inode->i_mode)) {
1675 /* We must have a dentry to determine the label on 1682 /* We must have a dentry to determine the label on
1676 * procfs inodes */ 1683 * procfs inodes */
1677 if (opt_dentry) 1684 if (opt_dentry) {
1678 /* Called from d_instantiate or 1685 /* Called from d_instantiate or
1679 * d_splice_alias. */ 1686 * d_splice_alias. */
1680 dentry = dget(opt_dentry); 1687 dentry = dget(opt_dentry);
1681 else 1688 } else {
1682 /* Called from selinux_complete_init, try to 1689 /* Called from selinux_complete_init, try to
1683 * find a dentry. */ 1690 * find a dentry. Some filesystems really want
1691 * a connected one, so try that first.
1692 */
1684 dentry = d_find_alias(inode); 1693 dentry = d_find_alias(inode);
1694 if (!dentry)
1695 dentry = d_find_any_alias(inode);
1696 }
1685 /* 1697 /*
1686 * This can be hit on boot when a file is accessed 1698 * This can be hit on boot when a file is accessed
1687 * before the policy is loaded. When we load policy we 1699 * before the policy is loaded. When we load policy we
diff --git a/sound/core/timer.c b/sound/core/timer.c
index dc87728c5b74..0ddcae495838 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -592,7 +592,7 @@ static int snd_timer_stop1(struct snd_timer_instance *timeri, bool stop)
592 else 592 else
593 timeri->flags |= SNDRV_TIMER_IFLG_PAUSED; 593 timeri->flags |= SNDRV_TIMER_IFLG_PAUSED;
594 snd_timer_notify1(timeri, stop ? SNDRV_TIMER_EVENT_STOP : 594 snd_timer_notify1(timeri, stop ? SNDRV_TIMER_EVENT_STOP :
595 SNDRV_TIMER_EVENT_CONTINUE); 595 SNDRV_TIMER_EVENT_PAUSE);
596 unlock: 596 unlock:
597 spin_unlock_irqrestore(&timer->lock, flags); 597 spin_unlock_irqrestore(&timer->lock, flags);
598 return result; 598 return result;
@@ -614,7 +614,7 @@ static int snd_timer_stop_slave(struct snd_timer_instance *timeri, bool stop)
614 list_del_init(&timeri->ack_list); 614 list_del_init(&timeri->ack_list);
615 list_del_init(&timeri->active_list); 615 list_del_init(&timeri->active_list);
616 snd_timer_notify1(timeri, stop ? SNDRV_TIMER_EVENT_STOP : 616 snd_timer_notify1(timeri, stop ? SNDRV_TIMER_EVENT_STOP :
617 SNDRV_TIMER_EVENT_CONTINUE); 617 SNDRV_TIMER_EVENT_PAUSE);
618 spin_unlock(&timeri->timer->lock); 618 spin_unlock(&timeri->timer->lock);
619 } 619 }
620 spin_unlock_irqrestore(&slave_active_lock, flags); 620 spin_unlock_irqrestore(&slave_active_lock, flags);
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 321e78baa63c..9bd935216c18 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -622,8 +622,10 @@ snd_hda_check_power_state(struct hda_codec *codec, hda_nid_t nid,
622{ 622{
623 return snd_hdac_check_power_state(&codec->core, nid, target_state); 623 return snd_hdac_check_power_state(&codec->core, nid, target_state);
624} 624}
625static inline bool snd_hda_sync_power_state(struct hda_codec *codec, 625
626 hda_nid_t nid, unsigned int target_state) 626static inline unsigned int snd_hda_sync_power_state(struct hda_codec *codec,
627 hda_nid_t nid,
628 unsigned int target_state)
627{ 629{
628 return snd_hdac_sync_power_state(&codec->core, nid, target_state); 630 return snd_hdac_sync_power_state(&codec->core, nid, target_state);
629} 631}
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 5922443063f0..0f9f06df49bc 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -2035,7 +2035,7 @@ int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr,
2035 return -EINVAL; 2035 return -EINVAL;
2036 2036
2037 obj = bpf_object__open(attr->file); 2037 obj = bpf_object__open(attr->file);
2038 if (IS_ERR(obj)) 2038 if (IS_ERR_OR_NULL(obj))
2039 return -ENOENT; 2039 return -ENOENT;
2040 2040
2041 bpf_object__for_each_program(prog, obj) { 2041 bpf_object__for_each_program(prog, obj) {
diff --git a/tools/testing/radix-tree/idr-test.c b/tools/testing/radix-tree/idr-test.c
index 6c645eb77d42..ee820fcc29b0 100644
--- a/tools/testing/radix-tree/idr-test.c
+++ b/tools/testing/radix-tree/idr-test.c
@@ -252,6 +252,13 @@ void idr_checks(void)
252 idr_remove(&idr, 3); 252 idr_remove(&idr, 3);
253 idr_remove(&idr, 0); 253 idr_remove(&idr, 0);
254 254
255 assert(idr_alloc(&idr, DUMMY_PTR, 0, 0, GFP_KERNEL) == 0);
256 idr_remove(&idr, 1);
257 for (i = 1; i < RADIX_TREE_MAP_SIZE; i++)
258 assert(idr_alloc(&idr, DUMMY_PTR, 0, 0, GFP_KERNEL) == i);
259 idr_remove(&idr, 1 << 30);
260 idr_destroy(&idr);
261
255 for (i = INT_MAX - 3UL; i < INT_MAX + 1UL; i++) { 262 for (i = INT_MAX - 3UL; i < INT_MAX + 1UL; i++) {
256 struct item *item = item_create(i, 0); 263 struct item *item = item_create(i, 0);
257 assert(idr_alloc(&idr, item, i, i + 10, GFP_KERNEL) == i); 264 assert(idr_alloc(&idr, item, i, i + 10, GFP_KERNEL) == i);
diff --git a/tools/testing/selftests/bpf/config b/tools/testing/selftests/bpf/config
index 983dd25d49f4..1eefe211a4a8 100644
--- a/tools/testing/selftests/bpf/config
+++ b/tools/testing/selftests/bpf/config
@@ -5,3 +5,5 @@ CONFIG_BPF_EVENTS=y
5CONFIG_TEST_BPF=m 5CONFIG_TEST_BPF=m
6CONFIG_CGROUP_BPF=y 6CONFIG_CGROUP_BPF=y
7CONFIG_NETDEVSIM=m 7CONFIG_NETDEVSIM=m
8CONFIG_NET_CLS_ACT=y
9CONFIG_NET_SCH_INGRESS=y
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index 3e7718b1a9ae..fd7de7eb329e 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -11713,6 +11713,11 @@ static void get_unpriv_disabled()
11713 FILE *fd; 11713 FILE *fd;
11714 11714
11715 fd = fopen("/proc/sys/"UNPRIV_SYSCTL, "r"); 11715 fd = fopen("/proc/sys/"UNPRIV_SYSCTL, "r");
11716 if (!fd) {
11717 perror("fopen /proc/sys/"UNPRIV_SYSCTL);
11718 unpriv_disabled = true;
11719 return;
11720 }
11716 if (fgets(buf, 2, fd) == buf && atoi(buf)) 11721 if (fgets(buf, 2, fd) == buf && atoi(buf))
11717 unpriv_disabled = true; 11722 unpriv_disabled = true;
11718 fclose(fd); 11723 fclose(fd);
diff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config
index 6a75a3ea44ad..7ba089b33e8b 100644
--- a/tools/testing/selftests/net/config
+++ b/tools/testing/selftests/net/config
@@ -7,3 +7,8 @@ CONFIG_NET_L3_MASTER_DEV=y
7CONFIG_IPV6=y 7CONFIG_IPV6=y
8CONFIG_IPV6_MULTIPLE_TABLES=y 8CONFIG_IPV6_MULTIPLE_TABLES=y
9CONFIG_VETH=y 9CONFIG_VETH=y
10CONFIG_INET_XFRM_MODE_TUNNEL=y
11CONFIG_NET_IPVTI=y
12CONFIG_INET6_XFRM_MODE_TUNNEL=y
13CONFIG_IPV6_VTI=y
14CONFIG_DUMMY=y
diff --git a/tools/testing/selftests/net/reuseport_bpf_numa.c b/tools/testing/selftests/net/reuseport_bpf_numa.c
index 365c32e84189..c9f478b40996 100644
--- a/tools/testing/selftests/net/reuseport_bpf_numa.c
+++ b/tools/testing/selftests/net/reuseport_bpf_numa.c
@@ -23,6 +23,8 @@
23#include <unistd.h> 23#include <unistd.h>
24#include <numa.h> 24#include <numa.h>
25 25
26#include "../kselftest.h"
27
26static const int PORT = 8888; 28static const int PORT = 8888;
27 29
28static void build_rcv_group(int *rcv_fd, size_t len, int family, int proto) 30static void build_rcv_group(int *rcv_fd, size_t len, int family, int proto)
@@ -229,7 +231,7 @@ int main(void)
229 int *rcv_fd, nodes; 231 int *rcv_fd, nodes;
230 232
231 if (numa_available() < 0) 233 if (numa_available() < 0)
232 error(1, errno, "no numa api support"); 234 ksft_exit_skip("no numa api support\n");
233 235
234 nodes = numa_max_node() + 1; 236 nodes = numa_max_node() + 1;
235 237
diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index 168c66d74fc5..e1473234968d 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -134,11 +134,15 @@ struct seccomp_data {
134#endif 134#endif
135 135
136#ifndef SECCOMP_FILTER_FLAG_TSYNC 136#ifndef SECCOMP_FILTER_FLAG_TSYNC
137#define SECCOMP_FILTER_FLAG_TSYNC 1 137#define SECCOMP_FILTER_FLAG_TSYNC (1UL << 0)
138#endif 138#endif
139 139
140#ifndef SECCOMP_FILTER_FLAG_LOG 140#ifndef SECCOMP_FILTER_FLAG_LOG
141#define SECCOMP_FILTER_FLAG_LOG 2 141#define SECCOMP_FILTER_FLAG_LOG (1UL << 1)
142#endif
143
144#ifndef SECCOMP_FILTER_FLAG_SPEC_ALLOW
145#define SECCOMP_FILTER_FLAG_SPEC_ALLOW (1UL << 2)
142#endif 146#endif
143 147
144#ifndef PTRACE_SECCOMP_GET_METADATA 148#ifndef PTRACE_SECCOMP_GET_METADATA
@@ -2072,14 +2076,26 @@ TEST(seccomp_syscall_mode_lock)
2072TEST(detect_seccomp_filter_flags) 2076TEST(detect_seccomp_filter_flags)
2073{ 2077{
2074 unsigned int flags[] = { SECCOMP_FILTER_FLAG_TSYNC, 2078 unsigned int flags[] = { SECCOMP_FILTER_FLAG_TSYNC,
2075 SECCOMP_FILTER_FLAG_LOG }; 2079 SECCOMP_FILTER_FLAG_LOG,
2080 SECCOMP_FILTER_FLAG_SPEC_ALLOW };
2076 unsigned int flag, all_flags; 2081 unsigned int flag, all_flags;
2077 int i; 2082 int i;
2078 long ret; 2083 long ret;
2079 2084
2080 /* Test detection of known-good filter flags */ 2085 /* Test detection of known-good filter flags */
2081 for (i = 0, all_flags = 0; i < ARRAY_SIZE(flags); i++) { 2086 for (i = 0, all_flags = 0; i < ARRAY_SIZE(flags); i++) {
2087 int bits = 0;
2088
2082 flag = flags[i]; 2089 flag = flags[i];
2090 /* Make sure the flag is a single bit! */
2091 while (flag) {
2092 if (flag & 0x1)
2093 bits ++;
2094 flag >>= 1;
2095 }
2096 ASSERT_EQ(1, bits);
2097 flag = flags[i];
2098
2083 ret = seccomp(SECCOMP_SET_MODE_FILTER, flag, NULL); 2099 ret = seccomp(SECCOMP_SET_MODE_FILTER, flag, NULL);
2084 ASSERT_NE(ENOSYS, errno) { 2100 ASSERT_NE(ENOSYS, errno) {
2085 TH_LOG("Kernel does not support seccomp syscall!"); 2101 TH_LOG("Kernel does not support seccomp syscall!");