summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CREDITS4
-rw-r--r--Documentation/admin-guide/cgroup-v2.rst20
-rw-r--r--Documentation/admin-guide/kernel-parameters.txt4
-rw-r--r--Documentation/arm64/memory.rst9
-rw-r--r--Documentation/arm64/silicon-errata.rst2
-rw-r--r--Documentation/core-api/index.rst1
-rw-r--r--Documentation/core-api/memory-allocation.rst4
-rw-r--r--Documentation/core-api/symbol-namespaces.rst (renamed from Documentation/kbuild/namespaces.rst)0
-rw-r--r--Documentation/dev-tools/kasan.rst3
-rw-r--r--Documentation/dev-tools/kselftest.rst16
-rw-r--r--Documentation/devicetree/bindings/dsp/fsl,dsp.yaml1
-rw-r--r--Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml7
-rw-r--r--Documentation/devicetree/bindings/media/rc.yaml1
-rw-r--r--Documentation/devicetree/bindings/phy/lantiq,vrx200-pcie-phy.yaml2
-rw-r--r--Documentation/devicetree/bindings/serial/renesas,sci-serial.txt2
-rw-r--r--Documentation/devicetree/bindings/usb/amlogic,dwc3.txt4
-rw-r--r--Documentation/devicetree/bindings/usb/generic-ehci.yaml7
-rw-r--r--Documentation/devicetree/bindings/usb/generic-ohci.yaml7
-rw-r--r--Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt4
-rw-r--r--Documentation/devicetree/bindings/usb/mediatek,mtu3.txt4
-rw-r--r--Documentation/devicetree/bindings/usb/usb-hcd.yaml5
-rw-r--r--Documentation/devicetree/bindings/usb/usb-uhci.txt2
-rw-r--r--Documentation/devicetree/bindings/usb/usb-xhci.txt4
-rw-r--r--Documentation/hwmon/index.rst1
-rw-r--r--Documentation/hwmon/inspur-ipsps1.rst2
-rw-r--r--Documentation/hwmon/k10temp.rst18
-rw-r--r--Documentation/kbuild/makefiles.rst5
-rw-r--r--Documentation/kbuild/modules.rst7
-rw-r--r--Documentation/kbuild/reproducible-builds.rst13
-rw-r--r--Documentation/networking/device_drivers/index.rst1
-rw-r--r--Documentation/networking/device_drivers/pensando/ionic.rst4
-rw-r--r--Documentation/networking/ip-sysctl.txt11
-rw-r--r--Documentation/networking/j1939.rst2
-rw-r--r--Documentation/networking/net_dim.txt36
-rw-r--r--Documentation/process/coding-style.rst2
-rw-r--r--Documentation/process/deprecated.rst33
-rw-r--r--Documentation/usb/rio.rst109
-rw-r--r--MAINTAINERS29
-rw-r--r--Makefile35
-rw-r--r--arch/arm/boot/dts/am335x-icev2.dts2
-rw-r--r--arch/arm/boot/dts/am33xx-l4.dtsi6
-rw-r--r--arch/arm/boot/dts/am4372.dtsi2
-rw-r--r--arch/arm/boot/dts/dra7-l4.dtsi48
-rw-r--r--arch/arm/boot/dts/mt7629-rfb.dts13
-rw-r--r--arch/arm/boot/dts/mt7629.dtsi2
-rw-r--r--arch/arm/boot/dts/omap3-gta04.dtsi1
-rw-r--r--arch/arm/boot/dts/ste-dbx5x0.dtsi11
-rw-r--r--arch/arm/boot/dts/sun4i-a10.dtsi4
-rw-r--r--arch/arm/boot/dts/sun5i.dtsi2
-rw-r--r--arch/arm/boot/dts/sun6i-a31.dtsi4
-rw-r--r--arch/arm/boot/dts/sun7i-a20.dtsi4
-rw-r--r--arch/arm/boot/dts/sun8i-a23-a33.dtsi2
-rw-r--r--arch/arm/boot/dts/sun8i-a83t.dtsi3
-rw-r--r--arch/arm/boot/dts/sun8i-r40.dtsi4
-rw-r--r--arch/arm/boot/dts/sun9i-a80.dtsi5
-rw-r--r--arch/arm/boot/dts/sunxi-h3-h5.dtsi6
-rw-r--r--arch/arm/configs/badge4_defconfig1
-rw-r--r--arch/arm/configs/corgi_defconfig1
-rw-r--r--arch/arm/configs/davinci_all_defconfig2
-rw-r--r--arch/arm/configs/multi_v7_defconfig4
-rw-r--r--arch/arm/configs/omap2plus_defconfig5
-rw-r--r--arch/arm/configs/pxa_defconfig1
-rw-r--r--arch/arm/configs/s3c2410_defconfig1
-rw-r--r--arch/arm/configs/spitz_defconfig1
-rw-r--r--arch/arm/crypto/Kconfig1
-rw-r--r--arch/arm/crypto/aes-ce-core.S1
-rw-r--r--arch/arm/include/asm/xen/xen-ops.h6
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_33xx_43xx_ipblock_data.c3
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_33xx_data.c5
-rw-r--r--arch/arm/mach-omap2/pm.c100
-rw-r--r--arch/arm/xen/Makefile1
-rw-r--r--arch/arm/xen/efi.c28
-rw-r--r--arch/arm/xen/enlighten.c3
-rw-r--r--arch/arm/xen/mm.c5
-rw-r--r--arch/arm64/Kconfig32
-rw-r--r--arch/arm64/Makefile16
-rw-r--r--arch/arm64/boot/dts/allwinner/sun50i-a64-pinebook.dts2
-rw-r--r--arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi2
-rw-r--r--arch/arm64/boot/dts/allwinner/sun50i-h6.dtsi2
-rw-r--r--arch/arm64/configs/defconfig2
-rw-r--r--arch/arm64/include/asm/asm-uaccess.h7
-rw-r--r--arch/arm64/include/asm/atomic_lse.h6
-rw-r--r--arch/arm64/include/asm/cpucaps.h4
-rw-r--r--arch/arm64/include/asm/kvm_hyp.h24
-rw-r--r--arch/arm64/include/asm/memory.h10
-rw-r--r--arch/arm64/include/asm/pgtable.h3
-rw-r--r--arch/arm64/include/asm/sysreg.h2
-rw-r--r--arch/arm64/include/asm/vdso/compat_barrier.h2
-rw-r--r--arch/arm64/include/asm/vdso_datapage.h33
-rw-r--r--arch/arm64/include/asm/xen/xen-ops.h7
-rw-r--r--arch/arm64/kernel/armv8_deprecated.c5
-rw-r--r--arch/arm64/kernel/cpu_errata.c42
-rw-r--r--arch/arm64/kernel/cpufeature.c16
-rw-r--r--arch/arm64/kernel/entry.S9
-rw-r--r--arch/arm64/kernel/ftrace.c12
-rw-r--r--arch/arm64/kernel/hibernate.c9
-rw-r--r--arch/arm64/kernel/process.c50
-rw-r--r--arch/arm64/kernel/vdso32/Makefile44
-rw-r--r--arch/arm64/kvm/hyp/switch.c86
-rw-r--r--arch/arm64/kvm/hyp/tlb.c36
-rw-r--r--arch/arm64/mm/fault.c19
-rw-r--r--arch/arm64/xen/Makefile1
-rw-r--r--arch/mips/boot/dts/qca/ar9331.dtsi2
-rw-r--r--arch/mips/configs/mtx1_defconfig1
-rw-r--r--arch/mips/configs/rm200_defconfig1
-rw-r--r--arch/mips/fw/arc/memory.c1
-rw-r--r--arch/mips/fw/sni/sniprom.c2
-rw-r--r--arch/mips/include/asm/cmpxchg.h9
-rw-r--r--arch/mips/include/asm/octeon/cvmx-ipd.h1
-rw-r--r--arch/mips/include/asm/unistd.h1
-rw-r--r--arch/mips/include/uapi/asm/hwcap.h11
-rw-r--r--arch/mips/kernel/cpu-bugs64.c14
-rw-r--r--arch/mips/kernel/cpu-probe.c33
-rw-r--r--arch/mips/kernel/setup.c5
-rw-r--r--arch/mips/kernel/syscall.c1
-rw-r--r--arch/mips/kernel/syscalls/syscall_n32.tbl2
-rw-r--r--arch/mips/kernel/syscalls/syscall_n64.tbl2
-rw-r--r--arch/mips/kernel/syscalls/syscall_o32.tbl2
-rw-r--r--arch/mips/loongson64/Platform4
-rw-r--r--arch/mips/loongson64/common/mem.c35
-rw-r--r--arch/mips/loongson64/common/serial.c2
-rw-r--r--arch/mips/loongson64/loongson-3/numa.c11
-rw-r--r--arch/mips/pmcs-msp71xx/msp_prom.c4
-rw-r--r--arch/mips/vdso/Makefile3
-rw-r--r--arch/mips/vdso/gettimeofday.c269
-rw-r--r--arch/parisc/include/asm/cache.h2
-rw-r--r--arch/parisc/include/asm/ldcw.h2
-rw-r--r--arch/parisc/mm/ioremap.c12
-rw-r--r--arch/powerpc/boot/Makefile2
-rw-r--r--arch/powerpc/include/asm/book3s/64/tlbflush-radix.h4
-rw-r--r--arch/powerpc/kvm/book3s.c8
-rw-r--r--arch/powerpc/kvm/book3s_hv_rmhandlers.S1
-rw-r--r--arch/powerpc/platforms/cell/spufs/inode.c1
-rw-r--r--arch/powerpc/platforms/pseries/lpar.c3
-rw-r--r--arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts1
-rw-r--r--arch/riscv/include/asm/asm.h1
-rw-r--r--arch/riscv/include/asm/pgtable.h16
-rw-r--r--arch/riscv/include/asm/tlbflush.h4
-rw-r--r--arch/riscv/kernel/entry.S24
-rw-r--r--arch/riscv/kernel/traps.c18
-rw-r--r--arch/riscv/mm/init.c12
-rw-r--r--arch/s390/configs/debug_defconfig24
-rw-r--r--arch/s390/configs/defconfig25
-rw-r--r--arch/s390/configs/zfcpdump_defconfig2
-rw-r--r--arch/s390/include/asm/atomic_ops.h2
-rw-r--r--arch/s390/include/asm/bitops.h8
-rw-r--r--arch/s390/include/asm/cpacf.h2
-rw-r--r--arch/s390/include/asm/cpu_mf.h8
-rw-r--r--arch/s390/include/asm/hugetlb.h9
-rw-r--r--arch/s390/include/asm/jump_label.h4
-rw-r--r--arch/s390/include/asm/pgtable.h25
-rw-r--r--arch/s390/include/asm/qdio.h2
-rw-r--r--arch/s390/include/asm/uaccess.h4
-rw-r--r--arch/s390/kernel/perf_cpum_cf_diag.c4
-rw-r--r--arch/s390/kernel/perf_cpum_sf.c8
-rw-r--r--arch/s390/kvm/kvm-s390.c6
-rw-r--r--arch/s390/pci/pci_clp.c2
-rw-r--r--arch/sparc/Kconfig1
-rw-r--r--arch/x86/events/amd/core.c30
-rw-r--r--arch/x86/events/intel/core.c4
-rw-r--r--arch/x86/events/intel/cstate.c44
-rw-r--r--arch/x86/events/msr.c7
-rw-r--r--arch/x86/include/asm/cpu_entry_area.h2
-rw-r--r--arch/x86/include/asm/intel-family.h3
-rw-r--r--arch/x86/include/asm/kvm_host.h7
-rw-r--r--arch/x86/include/asm/mwait.h2
-rw-r--r--arch/x86/include/asm/pti.h2
-rw-r--r--arch/x86/include/asm/uaccess.h23
-rw-r--r--arch/x86/kernel/cpu/vmware.c2
-rw-r--r--arch/x86/kernel/process.h2
-rw-r--r--arch/x86/kvm/cpuid.c102
-rw-r--r--arch/x86/kvm/lapic.c13
-rw-r--r--arch/x86/kvm/mmu.c65
-rw-r--r--arch/x86/kvm/vmx/nested.c2
-rw-r--r--arch/x86/kvm/vmx/pmu_intel.c7
-rw-r--r--arch/x86/kvm/vmx/vmx.c15
-rw-r--r--arch/x86/kvm/x86.c72
-rw-r--r--arch/x86/lib/delay.c4
-rw-r--r--arch/x86/platform/efi/efi.c3
-rw-r--r--arch/x86/xen/efi.c14
-rw-r--r--arch/x86/xen/enlighten.c28
-rw-r--r--arch/xtensa/boot/dts/virt.dts2
-rw-r--r--arch/xtensa/include/asm/bitops.h2
-rw-r--r--arch/xtensa/include/asm/uaccess.h94
-rw-r--r--arch/xtensa/kernel/xtensa_ksyms.c7
-rw-r--r--block/blk-cgroup.c69
-rw-r--r--block/blk-mq.c12
-rw-r--r--block/blk-rq-qos.c14
-rw-r--r--block/blk-rq-qos.h17
-rw-r--r--block/blk-wbt.c6
-rw-r--r--block/elevator.c3
-rw-r--r--block/sed-opal.c6
-rw-r--r--drivers/acpi/cppc_acpi.c2
-rw-r--r--drivers/acpi/hmat/hmat.c2
-rw-r--r--drivers/acpi/processor_perflib.c10
-rw-r--r--drivers/acpi/processor_thermal.c10
-rw-r--r--drivers/acpi/sleep.c13
-rw-r--r--drivers/android/binder.c4
-rw-r--r--drivers/android/binder_alloc.c2
-rw-r--r--drivers/android/binder_internal.h2
-rw-r--r--drivers/ata/ahci.c4
-rw-r--r--drivers/ata/libata-scsi.c21
-rw-r--r--drivers/base/core.c3
-rw-r--r--drivers/base/memory.c3
-rw-r--r--drivers/base/platform.c46
-rw-r--r--drivers/block/loop.c10
-rw-r--r--drivers/block/nbd.c2
-rw-r--r--drivers/block/null_blk_zoned.c3
-rw-r--r--drivers/block/rbd.c9
-rw-r--r--drivers/block/zram/zram_drv.c5
-rw-r--r--drivers/char/random.c2
-rw-r--r--drivers/clk/ti/clk-7xx.c6
-rw-r--r--drivers/clocksource/timer-of.c4
-rw-r--r--drivers/cpufreq/cpufreq.c10
-rw-r--r--drivers/crypto/chelsio/chtls/chtls_io.c2
-rw-r--r--drivers/dma-buf/dma-resv.c2
-rw-r--r--drivers/firmware/dmi_scan.c2
-rw-r--r--drivers/firmware/efi/cper.c2
-rw-r--r--drivers/firmware/efi/efi.c3
-rw-r--r--drivers/firmware/efi/rci2-table.c2
-rw-r--r--drivers/firmware/efi/tpm.c26
-rw-r--r--drivers/firmware/google/vpd_decode.c2
-rw-r--r--drivers/gpio/gpio-eic-sprd.c7
-rw-r--r--drivers/gpio/gpio-intel-mid.c9
-rw-r--r--drivers/gpio/gpio-lynxpoint.c10
-rw-r--r--drivers/gpio/gpio-max77620.c6
-rw-r--r--drivers/gpio/gpio-merrifield.c9
-rw-r--r--drivers/gpio/gpiolib-of.c2
-rw-r--r--drivers/gpio/gpiolib.c49
-rw-r--r--drivers/gpu/drm/amd/amdgpu/Makefile2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c34
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c14
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c38
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h1
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c37
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c12
-rw-r--r--drivers/gpu/drm/amd/amdgpu/nv.c6
-rw-r--r--drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/soc15.c8
-rw-r--r--drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c4
-rw-r--r--drivers/gpu/drm/amd/display/dc/dce100/dce100_resource.c1
-rw-r--r--drivers/gpu/drm/amd/display/dc/dce110/dce110_resource.c1
-rw-r--r--drivers/gpu/drm/amd/display/dc/dce112/dce112_resource.c1
-rw-r--r--drivers/gpu/drm/amd/display/dc/dce120/dce120_resource.c1
-rw-r--r--drivers/gpu/drm/amd/display/dc/dce80/dce80_resource.c1
-rw-r--r--drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c1
-rw-r--r--drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c1
-rw-r--r--drivers/gpu/drm/amd/display/dc/dcn21/Makefile12
-rw-r--r--drivers/gpu/drm/amd/display/dc/dml/dcn21/display_mode_vba_21.c13
-rw-r--r--drivers/gpu/drm/amd/powerplay/amdgpu_smu.c2
-rw-r--r--drivers/gpu/drm/amd/powerplay/arcturus_ppt.c2
-rw-r--r--drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h1
-rw-r--r--drivers/gpu/drm/amd/powerplay/navi10_ppt.c4
-rw-r--r--drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c2
-rw-r--r--drivers/gpu/drm/amd/powerplay/smumgr/vegam_smumgr.c2
-rw-r--r--drivers/gpu/drm/amd/powerplay/vega20_ppt.c2
-rw-r--r--drivers/gpu/drm/arm/display/komeda/komeda_wb_connector.c7
-rw-r--r--drivers/gpu/drm/arm/malidp_mw.c4
-rw-r--r--drivers/gpu/drm/bridge/tc358767.c7
-rw-r--r--drivers/gpu/drm/drm_atomic.c13
-rw-r--r--drivers/gpu/drm/drm_edid.c3
-rw-r--r--drivers/gpu/drm/drm_writeback.c23
-rw-r--r--drivers/gpu/drm/i915/display/intel_bios.c22
-rw-r--r--drivers/gpu/drm/i915/display/intel_display.c27
-rw-r--r--drivers/gpu/drm/i915/display/intel_display.h2
-rw-r--r--drivers/gpu/drm/i915/display/intel_dp.c184
-rw-r--r--drivers/gpu/drm/i915/display/intel_dp.h6
-rw-r--r--drivers/gpu/drm/i915/display/intel_dp_mst.c4
-rw-r--r--drivers/gpu/drm/i915/display/intel_sprite.c5
-rw-r--r--drivers/gpu/drm/i915/gem/i915_gem_mman.c19
-rw-r--r--drivers/gpu/drm/i915/gem/i915_gem_object.h6
-rw-r--r--drivers/gpu/drm/i915/gem/i915_gem_object_types.h3
-rw-r--r--drivers/gpu/drm/i915/gem/i915_gem_pm.c3
-rw-r--r--drivers/gpu/drm/i915/gem/i915_gem_userptr.c1
-rw-r--r--drivers/gpu/drm/i915/gt/intel_engine.h14
-rw-r--r--drivers/gpu/drm/i915/gt/intel_engine_cs.c16
-rw-r--r--drivers/gpu/drm/i915/gt/intel_lrc.c164
-rw-r--r--drivers/gpu/drm/i915/gt/intel_reset.c12
-rw-r--r--drivers/gpu/drm/i915/gt/intel_reset.h2
-rw-r--r--drivers/gpu/drm/i915/gt/intel_ringbuffer.c2
-rw-r--r--drivers/gpu/drm/i915/gt/intel_workarounds.c3
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c5
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c3
-rw-r--r--drivers/gpu/drm/i915/i915_gem.h6
-rw-r--r--drivers/gpu/drm/i915/i915_request.c69
-rw-r--r--drivers/gpu/drm/i915/i915_request.h2
-rw-r--r--drivers/gpu/drm/i915/intel_pch.c1
-rw-r--r--drivers/gpu/drm/i915/intel_pch.h1
-rw-r--r--drivers/gpu/drm/i915/selftests/i915_gem.c6
-rw-r--r--drivers/gpu/drm/msm/dsi/dsi_host.c6
-rw-r--r--drivers/gpu/drm/omapdrm/dss/dss.c2
-rw-r--r--drivers/gpu/drm/panel/panel-lg-lb035q02.c9
-rw-r--r--drivers/gpu/drm/panel/panel-nec-nl8048hl11.c9
-rw-r--r--drivers/gpu/drm/panel/panel-sony-acx565akm.c9
-rw-r--r--drivers/gpu/drm/panel/panel-tpo-td028ttec1.c3
-rw-r--r--drivers/gpu/drm/panel/panel-tpo-td043mtea1.c9
-rw-r--r--drivers/gpu/drm/panfrost/panfrost_gpu.c3
-rw-r--r--drivers/gpu/drm/panfrost/panfrost_job.c16
-rw-r--r--drivers/gpu/drm/radeon/radeon_drv.c8
-rw-r--r--drivers/gpu/drm/rcar-du/rcar_du_writeback.c4
-rw-r--r--drivers/gpu/drm/tilcdc/tilcdc_tfp410.c1
-rw-r--r--drivers/gpu/drm/tiny/Kconfig1
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo.c9
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo_vm.c16
-rw-r--r--drivers/gpu/drm/vc4/vc4_txp.c5
-rw-r--r--drivers/gpu/drm/xen/xen_drm_front.c12
-rw-r--r--drivers/hid/hid-hyperv.c56
-rw-r--r--drivers/hv/vmbus_drv.c6
-rw-r--r--drivers/hwmon/nct7904.c33
-rw-r--r--drivers/iio/accel/adxl372.c22
-rw-r--r--drivers/iio/accel/bmc150-accel-core.c2
-rw-r--r--drivers/iio/adc/ad799x.c4
-rw-r--r--drivers/iio/adc/axp288_adc.c32
-rw-r--r--drivers/iio/adc/hx711.c10
-rw-r--r--drivers/iio/adc/meson_saradc.c10
-rw-r--r--drivers/iio/adc/stm32-adc-core.c70
-rw-r--r--drivers/iio/adc/stm32-adc-core.h137
-rw-r--r--drivers/iio/adc/stm32-adc.c109
-rw-r--r--drivers/iio/imu/adis_buffer.c10
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h2
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c28
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c15
-rw-r--r--drivers/iio/light/Kconfig1
-rw-r--r--drivers/iio/light/opt3001.c6
-rw-r--r--drivers/iio/light/vcnl4000.c14
-rw-r--r--drivers/infiniband/core/cm.c3
-rw-r--r--drivers/infiniband/core/cma.c3
-rw-r--r--drivers/infiniband/core/device.c9
-rw-r--r--drivers/infiniband/core/nldev.c12
-rw-r--r--drivers/infiniband/core/security.c2
-rw-r--r--drivers/infiniband/core/umem_odp.c6
-rw-r--r--drivers/infiniband/hw/cxgb4/device.c7
-rw-r--r--drivers/infiniband/hw/cxgb4/mem.c28
-rw-r--r--drivers/infiniband/hw/cxgb4/qp.c10
-rw-r--r--drivers/infiniband/hw/hfi1/sdma.c5
-rw-r--r--drivers/infiniband/hw/i40iw/i40iw_verbs.c4
-rw-r--r--drivers/infiniband/hw/mlx5/devx.c58
-rw-r--r--drivers/infiniband/hw/mlx5/mlx5_ib.h3
-rw-r--r--drivers/infiniband/hw/mlx5/mr.c68
-rw-r--r--drivers/infiniband/hw/mlx5/odp.c58
-rw-r--r--drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c2
-rw-r--r--drivers/infiniband/sw/siw/siw_qp.c15
-rw-r--r--drivers/input/misc/da9063_onkey.c5
-rw-r--r--drivers/input/misc/soc_button_array.c17
-rw-r--r--drivers/input/mouse/elantech.c55
-rw-r--r--drivers/input/rmi4/rmi_driver.c6
-rw-r--r--drivers/input/touchscreen/goodix.c58
-rw-r--r--drivers/iommu/amd_iommu.c12
-rw-r--r--drivers/iommu/amd_iommu_types.h4
-rw-r--r--drivers/iommu/arm-smmu.c1
-rw-r--r--drivers/iommu/io-pgtable-arm.c58
-rw-r--r--drivers/iommu/ipmmu-vmsa.c3
-rw-r--r--drivers/iommu/rockchip-iommu.c19
-rw-r--r--drivers/isdn/capi/capi.c2
-rw-r--r--drivers/md/dm-cache-target.c28
-rw-r--r--drivers/md/dm-clone-target.c4
-rw-r--r--drivers/md/dm-snap.c94
-rw-r--r--drivers/md/raid0.c2
-rw-r--r--drivers/media/usb/stkwebcam/stk-webcam.c3
-rw-r--r--drivers/memstick/host/jmb38x_ms.c2
-rw-r--r--drivers/misc/fastrpc.c1
-rw-r--r--drivers/misc/mei/bus-fixup.c14
-rw-r--r--drivers/misc/mei/hw-me-regs.h3
-rw-r--r--drivers/misc/mei/hw-me.c21
-rw-r--r--drivers/misc/mei/hw-me.h8
-rw-r--r--drivers/misc/mei/mei_dev.h4
-rw-r--r--drivers/misc/mei/pci-me.c13
-rw-r--r--drivers/mmc/host/renesas_sdhi_core.c31
-rw-r--r--drivers/mmc/host/sdhci-iproc.c1
-rw-r--r--drivers/mmc/host/sh_mmcif.c6
-rw-r--r--drivers/mtd/nand/raw/au1550nd.c5
-rw-r--r--drivers/mtd/spi-nor/spi-nor.c2
-rw-r--r--drivers/net/bonding/bond_alb.c2
-rw-r--r--drivers/net/bonding/bond_main.c30
-rw-r--r--drivers/net/dsa/b53/b53_common.c1
-rw-r--r--drivers/net/dsa/microchip/ksz8795.c4
-rw-r--r--drivers/net/dsa/microchip/ksz8795_spi.c7
-rw-r--r--drivers/net/dsa/microchip/ksz9477_i2c.c6
-rw-r--r--drivers/net/dsa/microchip/ksz9477_reg.h4
-rw-r--r--drivers/net/dsa/microchip/ksz9477_spi.c6
-rw-r--r--drivers/net/dsa/microchip/ksz_common.c2
-rw-r--r--drivers/net/dsa/microchip/ksz_common.h20
-rw-r--r--drivers/net/dsa/qca8k.c4
-rw-r--r--drivers/net/dsa/rtl8366.c11
-rw-r--r--drivers/net/dsa/rtl8366rb.c16
-rw-r--r--drivers/net/dsa/sja1105/Kconfig4
-rw-r--r--drivers/net/dsa/sja1105/sja1105.h4
-rw-r--r--drivers/net/dsa/sja1105/sja1105_dynamic_config.h4
-rw-r--r--drivers/net/dsa/sja1105/sja1105_main.c24
-rw-r--r--drivers/net/dsa/sja1105/sja1105_ptp.h4
-rw-r--r--drivers/net/dsa/sja1105/sja1105_spi.c6
-rw-r--r--drivers/net/dsa/sja1105/sja1105_static_config.h4
-rw-r--r--drivers/net/dsa/sja1105/sja1105_tas.h4
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/aq_main.c4
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/aq_nic.c34
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/aq_ring.c3
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c23
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh.c17
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh.h7
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh_internal.h19
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c2
-rw-r--r--drivers/net/ethernet/arc/emac_rockchip.c3
-rw-r--r--drivers/net/ethernet/atheros/ag71xx.c6
-rw-r--r--drivers/net/ethernet/broadcom/Kconfig4
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt.c10
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c112
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.h3
-rw-r--r--drivers/net/ethernet/broadcom/genet/bcmgenet.c41
-rw-r--r--drivers/net/ethernet/broadcom/genet/bcmgenet.h3
-rw-r--r--drivers/net/ethernet/broadcom/genet/bcmmii.c117
-rw-r--r--drivers/net/ethernet/cadence/macb_main.c12
-rw-r--r--drivers/net/ethernet/cavium/common/cavium_ptp.h2
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c37
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/sge.c8
-rw-r--r--drivers/net/ethernet/cortina/gemini.h2
-rw-r--r--drivers/net/ethernet/faraday/ftgmac100.c25
-rw-r--r--drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c50
-rw-r--r--drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.h2
-rw-r--r--drivers/net/ethernet/freescale/dpaa2/dpni.h5
-rw-r--r--drivers/net/ethernet/freescale/dpaa2/dprtc-cmd.h2
-rw-r--r--drivers/net/ethernet/freescale/dpaa2/dprtc.h2
-rw-r--r--drivers/net/ethernet/freescale/fec_main.c2
-rw-r--r--drivers/net/ethernet/freescale/fec_ptp.c4
-rw-r--r--drivers/net/ethernet/hisilicon/hip04_eth.c16
-rw-r--r--drivers/net/ethernet/hisilicon/hns3/hnae3.h2
-rw-r--r--drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c21
-rw-r--r--drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h1
-rw-r--r--drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c11
-rw-r--r--drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c28
-rw-r--r--drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h1
-rw-r--r--drivers/net/ethernet/hisilicon/hns_mdio.c6
-rw-r--r--drivers/net/ethernet/i825xx/lasi_82596.c4
-rw-r--r--drivers/net/ethernet/i825xx/lib82596.c4
-rw-r--r--drivers/net/ethernet/i825xx/sni_82596.c4
-rw-r--r--drivers/net/ethernet/ibm/ibmvnic.c8
-rw-r--r--drivers/net/ethernet/marvell/mvneta_bm.h32
-rw-r--r--drivers/net/ethernet/mediatek/mtk_eth_soc.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/resource_tracker.c42
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en.h3
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en/hv_vhca_stats.c4
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c12
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h13
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.h29
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c190
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_main.c13
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_rep.c4
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_rx.c5
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c15
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_stats.c16
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_stats.h10
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_tc.c36
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_tx.c35
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c22
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/fpga/conn.c4
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c3
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/health.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/mr.c8
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c3
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c10
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/core.c4
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c1
-rw-r--r--drivers/net/ethernet/mscc/ocelot.c11
-rw-r--r--drivers/net/ethernet/mscc/ocelot_board.c14
-rw-r--r--drivers/net/ethernet/netronome/nfp/nfp_net_repr.c18
-rw-r--r--drivers/net/ethernet/nxp/lpc_eth.c3
-rw-r--r--drivers/net/ethernet/pensando/Kconfig1
-rw-r--r--drivers/net/ethernet/pensando/ionic/ionic_lif.c2
-rw-r--r--drivers/net/ethernet/pensando/ionic/ionic_lif.h2
-rw-r--r--drivers/net/ethernet/pensando/ionic/ionic_main.c2
-rw-r--r--drivers/net/ethernet/pensando/ionic/ionic_stats.c29
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_main.c27
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_sriov.c2
-rw-r--r--drivers/net/ethernet/qlogic/qla3xxx.c1
-rw-r--r--drivers/net/ethernet/realtek/r8169_main.c35
-rw-r--r--drivers/net/ethernet/socionext/netsec.c30
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c3
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c15
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac5.c1
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h3
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c9
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c1
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_main.c40
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c2
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c15
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c2
-rw-r--r--drivers/net/ethernet/ti/davinci_cpdma.c2
-rw-r--r--drivers/net/fjes/fjes_main.c15
-rw-r--r--drivers/net/hamradio/bpqether.c22
-rw-r--r--drivers/net/hyperv/netvsc_drv.c15
-rw-r--r--drivers/net/ieee802154/atusb.c3
-rw-r--r--drivers/net/ieee802154/ca8210.c2
-rw-r--r--drivers/net/ieee802154/mcr20a.c2
-rw-r--r--drivers/net/ipvlan/ipvlan_main.c2
-rw-r--r--drivers/net/macsec.c18
-rw-r--r--drivers/net/macvlan.c19
-rw-r--r--drivers/net/netdevsim/dev.c5
-rw-r--r--drivers/net/netdevsim/fib.c3
-rw-r--r--drivers/net/phy/at803x.c69
-rw-r--r--drivers/net/phy/bcm7xxx.c1
-rw-r--r--drivers/net/phy/mdio_device.c2
-rw-r--r--drivers/net/phy/micrel.c42
-rw-r--r--drivers/net/phy/phy-c45.c2
-rw-r--r--drivers/net/phy/phy-core.c20
-rw-r--r--drivers/net/phy/phy.c8
-rw-r--r--drivers/net/phy/phy_device.c74
-rw-r--r--drivers/net/phy/phylink.c2
-rw-r--r--drivers/net/phy/smsc.c1
-rw-r--r--drivers/net/ppp/ppp_generic.c2
-rw-r--r--drivers/net/ppp/pptp.c4
-rw-r--r--drivers/net/team/team.c16
-rw-r--r--drivers/net/tun.c6
-rw-r--r--drivers/net/usb/cdc_ether.c7
-rw-r--r--drivers/net/usb/hso.c25
-rw-r--r--drivers/net/usb/lan78xx.c17
-rw-r--r--drivers/net/usb/qmi_wwan.c2
-rw-r--r--drivers/net/usb/r8152.c4
-rw-r--r--drivers/net/usb/sr9800.c2
-rw-r--r--drivers/net/virtio_net.c2
-rw-r--r--drivers/net/vrf.c9
-rw-r--r--drivers/net/vxlan.c62
-rw-r--r--drivers/net/wimax/i2400m/op-rfkill.c2
-rw-r--r--drivers/net/wireless/intersil/hostap/hostap_hw.c25
-rw-r--r--drivers/net/wireless/mac80211_hwsim.c6
-rw-r--r--drivers/net/wireless/virt_wifi.c54
-rw-r--r--drivers/net/xen-netback/interface.c1
-rw-r--r--drivers/net/xen-netfront.c17
-rw-r--r--drivers/nfc/pn533/usb.c9
-rw-r--r--drivers/nvme/host/core.c226
-rw-r--r--drivers/nvme/host/fabrics.h3
-rw-r--r--drivers/nvme/host/nvme.h7
-rw-r--r--drivers/nvme/host/pci.c103
-rw-r--r--drivers/nvme/host/rdma.c27
-rw-r--r--drivers/nvme/host/tcp.c17
-rw-r--r--drivers/nvme/target/io-cmd-bdev.c16
-rw-r--r--drivers/nvme/target/loop.c4
-rw-r--r--drivers/nvme/target/tcp.c12
-rw-r--r--drivers/parisc/sba_iommu.c8
-rw-r--r--drivers/pci/pci.c24
-rw-r--r--drivers/platform/x86/classmate-laptop.c12
-rw-r--r--drivers/platform/x86/i2c-multi-instantiate.c1
-rw-r--r--drivers/platform/x86/intel_punit_ipc.c3
-rw-r--r--drivers/ptp/Kconfig4
-rw-r--r--drivers/ptp/ptp_qoriq.c3
-rw-r--r--drivers/s390/block/dasd_eckd.c81
-rw-r--r--drivers/s390/cio/cio.h1
-rw-r--r--drivers/s390/cio/css.c7
-rw-r--r--drivers/s390/cio/device.c2
-rw-r--r--drivers/s390/cio/qdio_setup.c2
-rw-r--r--drivers/s390/net/qeth_core_main.c3
-rw-r--r--drivers/s390/net/qeth_l2_main.c23
-rw-r--r--drivers/s390/scsi/zfcp_fsf.c16
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_io.c29
-rw-r--r--drivers/scsi/hisi_sas/hisi_sas_main.c6
-rw-r--r--drivers/scsi/megaraid.c4
-rw-r--r--drivers/scsi/qedf/qedf_main.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_attr.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_def.h4
-rw-r--r--drivers/scsi/qla2xxx/qla_gs.c3
-rw-r--r--drivers/scsi/qla2xxx/qla_init.c109
-rw-r--r--drivers/scsi/qla2xxx/qla_iocb.c7
-rw-r--r--drivers/scsi/qla2xxx/qla_isr.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_mbx.c25
-rw-r--r--drivers/scsi/qla2xxx/qla_mid.c32
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c18
-rw-r--r--drivers/scsi/qla2xxx/qla_target.c26
-rw-r--r--drivers/scsi/scsi_error.c3
-rw-r--r--drivers/scsi/scsi_lib.c4
-rw-r--r--drivers/scsi/sd.c3
-rw-r--r--drivers/scsi/storvsc_drv.c3
-rw-r--r--drivers/scsi/ufs/ufshcd.c3
-rw-r--r--drivers/staging/exfat/Kconfig3
-rw-r--r--drivers/staging/exfat/Makefile2
-rw-r--r--drivers/staging/exfat/exfat.h2
-rw-r--r--drivers/staging/exfat/exfat_blkdev.c2
-rw-r--r--drivers/staging/exfat/exfat_cache.c2
-rw-r--r--drivers/staging/exfat/exfat_core.c2
-rw-r--r--drivers/staging/exfat/exfat_nls.c2
-rw-r--r--drivers/staging/exfat/exfat_super.c7
-rw-r--r--drivers/staging/exfat/exfat_upcase.c2
-rw-r--r--drivers/staging/fbtft/Kconfig12
-rw-r--r--drivers/staging/fbtft/Makefile4
-rw-r--r--drivers/staging/fbtft/fbtft-core.c7
-rw-r--r--drivers/staging/fbtft/fbtft_device.c1261
-rw-r--r--drivers/staging/fbtft/flexfb.c851
-rw-r--r--drivers/staging/octeon/ethernet-tx.c15
-rw-r--r--drivers/staging/octeon/octeon-stubs.h2
-rw-r--r--drivers/staging/rtl8188eu/hal/hal8188e_rate_adaptive.c2
-rw-r--r--drivers/staging/rtl8188eu/os_dep/usb_intf.c6
-rw-r--r--drivers/staging/speakup/sysfs-driver-speakup369
-rw-r--r--drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c4
-rw-r--r--drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c1
-rw-r--r--drivers/staging/vt6655/device_main.c4
-rw-r--r--drivers/tty/n_hdlc.c5
-rw-r--r--drivers/tty/serial/8250/8250_omap.c5
-rw-r--r--drivers/tty/serial/Kconfig1
-rw-r--r--drivers/tty/serial/fsl_linflexuart.c21
-rw-r--r--drivers/tty/serial/fsl_lpuart.c2
-rw-r--r--drivers/tty/serial/imx.c4
-rw-r--r--drivers/tty/serial/owl-uart.c2
-rw-r--r--drivers/tty/serial/rda-uart.c2
-rw-r--r--drivers/tty/serial/serial_core.c2
-rw-r--r--drivers/tty/serial/serial_mctrl_gpio.c3
-rw-r--r--drivers/tty/serial/sh-sci.c8
-rw-r--r--drivers/tty/serial/uartlite.c3
-rw-r--r--drivers/tty/serial/xilinx_uartps.c8
-rw-r--r--drivers/usb/cdns3/cdns3-pci-wrap.c3
-rw-r--r--drivers/usb/cdns3/core.c20
-rw-r--r--drivers/usb/cdns3/ep0.c12
-rw-r--r--drivers/usb/cdns3/gadget.c8
-rw-r--r--drivers/usb/class/usblp.c8
-rw-r--r--drivers/usb/dwc3/drd.c7
-rw-r--r--drivers/usb/dwc3/gadget.c7
-rw-r--r--drivers/usb/dwc3/host.c7
-rw-r--r--drivers/usb/gadget/udc/Kconfig2
-rw-r--r--drivers/usb/gadget/udc/dummy_hcd.c3
-rw-r--r--drivers/usb/gadget/udc/lpc32xx_udc.c4
-rw-r--r--drivers/usb/host/xhci-ext-caps.c1
-rw-r--r--drivers/usb/host/xhci-ring.c4
-rw-r--r--drivers/usb/host/xhci.c78
-rw-r--r--drivers/usb/image/microtek.c4
-rw-r--r--drivers/usb/misc/Kconfig10
-rw-r--r--drivers/usb/misc/Makefile1
-rw-r--r--drivers/usb/misc/adutux.c24
-rw-r--r--drivers/usb/misc/chaoskey.c5
-rw-r--r--drivers/usb/misc/iowarrior.c48
-rw-r--r--drivers/usb/misc/ldusb.c24
-rw-r--r--drivers/usb/misc/legousbtower.c58
-rw-r--r--drivers/usb/misc/rio500.c554
-rw-r--r--drivers/usb/misc/rio500_usb.h20
-rw-r--r--drivers/usb/misc/usblcd.c60
-rw-r--r--drivers/usb/misc/yurex.c18
-rw-r--r--drivers/usb/renesas_usbhs/common.h1
-rw-r--r--drivers/usb/renesas_usbhs/fifo.c2
-rw-r--r--drivers/usb/renesas_usbhs/fifo.h1
-rw-r--r--drivers/usb/renesas_usbhs/mod_gadget.c18
-rw-r--r--drivers/usb/renesas_usbhs/pipe.c15
-rw-r--r--drivers/usb/renesas_usbhs/pipe.h1
-rw-r--r--drivers/usb/serial/ftdi_sio.c3
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h9
-rw-r--r--drivers/usb/serial/keyspan.c4
-rw-r--r--drivers/usb/serial/option.c11
-rw-r--r--drivers/usb/serial/usb-serial.c5
-rw-r--r--drivers/usb/typec/tcpm/tcpm.c14
-rw-r--r--drivers/usb/typec/ucsi/displayport.c2
-rw-r--r--drivers/usb/typec/ucsi/ucsi_ccg.c42
-rw-r--r--drivers/usb/usb-skeleton.c19
-rw-r--r--drivers/usb/usbip/vhci_hcd.c4
-rw-r--r--drivers/vhost/test.c2
-rw-r--r--drivers/video/logo/Makefile21
-rw-r--r--drivers/virt/vboxguest/vboxguest_utils.c3
-rw-r--r--drivers/w1/slaves/Kconfig1
-rw-r--r--drivers/xen/balloon.c24
-rw-r--r--drivers/xen/efi.c84
-rw-r--r--drivers/xen/gntdev.c13
-rw-r--r--drivers/xen/grant-table.c3
-rw-r--r--drivers/xen/pvcalls-back.c2
-rw-r--r--drivers/xen/xenbus/xenbus_dev_frontend.c20
-rw-r--r--fs/binfmt_elf.c13
-rw-r--r--fs/btrfs/file.c13
-rw-r--r--fs/btrfs/inode.c3
-rw-r--r--fs/btrfs/ref-verify.c2
-rw-r--r--fs/btrfs/send.c2
-rw-r--r--fs/btrfs/tree-log.c36
-rw-r--r--fs/btrfs/volumes.c6
-rw-r--r--fs/ceph/mds_client.c21
-rw-r--r--fs/cifs/cifsfs.c24
-rw-r--r--fs/cifs/cifsglob.h2
-rw-r--r--fs/cifs/connect.c4
-rw-r--r--fs/cifs/dir.c8
-rw-r--r--fs/cifs/file.c33
-rw-r--r--fs/cifs/inode.c4
-rw-r--r--fs/cifs/netmisc.c4
-rw-r--r--fs/cifs/smb2pdu.c14
-rw-r--r--fs/cifs/smb2proto.h4
-rw-r--r--fs/direct-io.c3
-rw-r--r--fs/erofs/data.c10
-rw-r--r--fs/erofs/super.c4
-rw-r--r--fs/erofs/zdata.c12
-rw-r--r--fs/fs-writeback.c11
-rw-r--r--fs/io_uring.c153
-rw-r--r--fs/libfs.c140
-rw-r--r--fs/nfs/direct.c106
-rw-r--r--fs/nfs/nfs4proc.c1
-rw-r--r--fs/nfs/write.c5
-rw-r--r--fs/ocfs2/aops.c25
-rw-r--r--fs/ocfs2/file.c2
-rw-r--r--fs/ocfs2/ioctl.c2
-rw-r--r--fs/ocfs2/journal.c3
-rw-r--r--fs/ocfs2/localalloc.c3
-rw-r--r--fs/ocfs2/xattr.c56
-rw-r--r--fs/proc/meminfo.c4
-rw-r--r--fs/proc/page.c28
-rw-r--r--fs/readdir.c128
-rw-r--r--fs/statfs.c17
-rw-r--r--fs/super.c5
-rw-r--r--fs/tracefs/inode.c46
-rw-r--r--fs/xfs/libxfs/xfs_ag.c5
-rw-r--r--fs/xfs/libxfs/xfs_attr_leaf.c21
-rw-r--r--fs/xfs/libxfs/xfs_bmap.c6
-rw-r--r--fs/xfs/libxfs/xfs_bmap.h3
-rw-r--r--fs/xfs/libxfs/xfs_dir2_block.c2
-rw-r--r--fs/xfs/libxfs/xfs_fs.h8
-rw-r--r--fs/xfs/scrub/refcount.c3
-rw-r--r--fs/xfs/xfs_bmap_util.c4
-rw-r--r--fs/xfs/xfs_buf.c12
-rw-r--r--fs/xfs/xfs_log.c2
-rw-r--r--fs/xfs/xfs_log_recover.c2
-rw-r--r--include/linux/bitmap.h3
-rw-r--r--include/linux/bitops.h7
-rw-r--r--include/linux/compiler_attributes.h17
-rw-r--r--include/linux/dsa/sja1105.h4
-rw-r--r--include/linux/dynamic_debug.h6
-rw-r--r--include/linux/export.h10
-rw-r--r--include/linux/filter.h1
-rw-r--r--include/linux/gfp.h23
-rw-r--r--include/linux/gpio/driver.h8
-rw-r--r--include/linux/hwmon.h2
-rw-r--r--include/linux/if_macvlan.h1
-rw-r--r--include/linux/if_team.h1
-rw-r--r--include/linux/if_vlan.h11
-rw-r--r--include/linux/kvm_host.h2
-rw-r--r--include/linux/leds.h5
-rw-r--r--include/linux/memcontrol.h29
-rw-r--r--include/linux/micrel_phy.h2
-rw-r--r--include/linux/mii.h9
-rw-r--r--include/linux/mlx5/mlx5_ifc.h3
-rw-r--r--include/linux/netdevice.h61
-rw-r--r--include/linux/page_ext.h10
-rw-r--r--include/linux/phy.h2
-rw-r--r--include/linux/platform_device.h2
-rw-r--r--include/linux/sched.h1
-rw-r--r--include/linux/skbuff.h46
-rw-r--r--include/linux/slab.h4
-rw-r--r--include/linux/socket.h2
-rw-r--r--include/linux/string.h21
-rw-r--r--include/linux/sunrpc/xprtsock.h1
-rw-r--r--include/linux/tcp.h6
-rw-r--r--include/linux/tpm_eventlog.h16
-rw-r--r--include/linux/uaccess.h76
-rw-r--r--include/linux/xarray.h4
-rw-r--r--include/net/bonding.h2
-rw-r--r--include/net/busy_poll.h6
-rw-r--r--include/net/cfg80211.h8
-rw-r--r--include/net/flow_dissector.h3
-rw-r--r--include/net/fq.h2
-rw-r--r--include/net/fq_impl.h4
-rw-r--r--include/net/hwbm.h10
-rw-r--r--include/net/ip.h4
-rw-r--r--include/net/ip_vs.h1
-rw-r--r--include/net/llc_conn.h2
-rw-r--r--include/net/net_namespace.h27
-rw-r--r--include/net/request_sock.h4
-rw-r--r--include/net/sctp/sctp.h5
-rw-r--r--include/net/sock.h48
-rw-r--r--include/net/tcp.h10
-rw-r--r--include/net/vxlan.h1
-rw-r--r--include/scsi/scsi_eh.h1
-rw-r--r--include/sound/hda_register.h3
-rw-r--r--include/trace/events/rxrpc.h20
-rw-r--r--include/trace/events/sock.h4
-rw-r--r--include/uapi/drm/amdgpu_drm.h2
-rw-r--r--include/uapi/linux/nvme_ioctl.h23
-rw-r--r--include/uapi/linux/pg.h5
-rw-r--r--include/uapi/linux/sched.h30
-rw-r--r--include/uapi/linux/serial_core.h2
-rw-r--r--include/xen/xen-ops.h25
-rw-r--r--kernel/bpf/core.c2
-rw-r--r--kernel/bpf/devmap.c33
-rw-r--r--kernel/bpf/syscall.c31
-rw-r--r--kernel/dma/remap.c4
-rw-r--r--kernel/events/core.c90
-rw-r--r--kernel/events/uprobes.c13
-rw-r--r--kernel/fork.c49
-rw-r--r--kernel/freezer.c6
-rwxr-xr-xkernel/gen_kheaders.sh5
-rw-r--r--kernel/kthread.c6
-rw-r--r--kernel/panic.c1
-rw-r--r--kernel/power/main.c1
-rw-r--r--kernel/sched/core.c43
-rw-r--r--kernel/sched/cputime.c6
-rw-r--r--kernel/sched/fair.c36
-rw-r--r--kernel/sched/membarrier.c1
-rw-r--r--kernel/sysctl.c4
-rw-r--r--kernel/time/tick-broadcast-hrtimer.c62
-rw-r--r--kernel/trace/ftrace.c55
-rw-r--r--kernel/trace/trace.c139
-rw-r--r--kernel/trace/trace.h2
-rw-r--r--kernel/trace/trace_dynevent.c4
-rw-r--r--kernel/trace/trace_events.c35
-rw-r--r--kernel/trace/trace_events_hist.c13
-rw-r--r--kernel/trace/trace_events_trigger.c8
-rw-r--r--kernel/trace/trace_hwlat.c4
-rw-r--r--kernel/trace/trace_kprobe.c12
-rw-r--r--kernel/trace/trace_printk.c7
-rw-r--r--kernel/trace/trace_stack.c8
-rw-r--r--kernel/trace/trace_stat.c6
-rw-r--r--kernel/trace/trace_uprobe.c11
-rw-r--r--lib/generic-radix-tree.c32
-rw-r--r--lib/string.c21
-rw-r--r--lib/strnlen_user.c8
-rw-r--r--lib/test_meminit.c27
-rw-r--r--lib/test_user_copy.c155
-rw-r--r--lib/textsearch.c4
-rw-r--r--lib/usercopy.c55
-rw-r--r--lib/vdso/Kconfig9
-rw-r--r--mm/backing-dev.c4
-rw-r--r--mm/compaction.c7
-rw-r--r--mm/filemap.c1
-rw-r--r--mm/gup.c14
-rw-r--r--mm/huge_memory.c9
-rw-r--r--mm/hugetlb.c5
-rw-r--r--mm/init-mm.c1
-rw-r--r--mm/kmemleak.c30
-rw-r--r--mm/memblock.c6
-rw-r--r--mm/memcontrol.c23
-rw-r--r--mm/memory-failure.c36
-rw-r--r--mm/memory_hotplug.c72
-rw-r--r--mm/memremap.c13
-rw-r--r--mm/page_alloc.c14
-rw-r--r--mm/page_ext.c23
-rw-r--r--mm/page_owner.c60
-rw-r--r--mm/rmap.c1
-rw-r--r--mm/shmem.c6
-rw-r--r--mm/shuffle.c2
-rw-r--r--mm/slab.c3
-rw-r--r--mm/slab_common.c28
-rw-r--r--mm/slob.c62
-rw-r--r--mm/slub.c49
-rw-r--r--mm/sparse.c2
-rw-r--r--mm/truncate.c12
-rw-r--r--mm/vmpressure.c20
-rw-r--r--mm/vmscan.c86
-rw-r--r--mm/z3fold.c10
-rw-r--r--net/8021q/vlan.c1
-rw-r--r--net/8021q/vlan_dev.c33
-rw-r--r--net/atm/common.c2
-rw-r--r--net/batman-adv/bat_iv_ogm.c61
-rw-r--r--net/batman-adv/bat_v_ogm.c41
-rw-r--r--net/batman-adv/hard-interface.c2
-rw-r--r--net/batman-adv/soft-interface.c34
-rw-r--r--net/batman-adv/types.h7
-rw-r--r--net/bluetooth/6lowpan.c8
-rw-r--r--net/bluetooth/af_bluetooth.c4
-rw-r--r--net/bridge/br_device.c8
-rw-r--r--net/bridge/netfilter/nf_conntrack_bridge.c5
-rw-r--r--net/caif/caif_socket.c2
-rw-r--r--net/core/datagram.c10
-rw-r--r--net/core/dev.c620
-rw-r--r--net/core/dev_addr_lists.c12
-rw-r--r--net/core/devlink.c6
-rw-r--r--net/core/ethtool.c4
-rw-r--r--net/core/filter.c8
-rw-r--r--net/core/flow_dissector.c38
-rw-r--r--net/core/lwt_bpf.c7
-rw-r--r--net/core/net_namespace.c23
-rw-r--r--net/core/request_sock.c2
-rw-r--r--net/core/rtnetlink.c17
-rw-r--r--net/core/skbuff.c25
-rw-r--r--net/core/sock.c51
-rw-r--r--net/dccp/ipv4.c2
-rw-r--r--net/decnet/af_decnet.c2
-rw-r--r--net/dsa/dsa2.c2
-rw-r--r--net/dsa/master.c5
-rw-r--r--net/dsa/slave.c12
-rw-r--r--net/dsa/tag_sja1105.c12
-rw-r--r--net/ieee802154/6lowpan/core.c8
-rw-r--r--net/ipv4/fib_frontend.c2
-rw-r--r--net/ipv4/inet_connection_sock.c6
-rw-r--r--net/ipv4/inet_diag.c2
-rw-r--r--net/ipv4/inet_hashtables.c2
-rw-r--r--net/ipv4/ip_gre.c5
-rw-r--r--net/ipv4/ip_input.c2
-rw-r--r--net/ipv4/ip_output.c14
-rw-r--r--net/ipv4/ipmr.c4
-rw-r--r--net/ipv4/netfilter/nf_dup_ipv4.c2
-rw-r--r--net/ipv4/raw.c2
-rw-r--r--net/ipv4/route.c16
-rw-r--r--net/ipv4/tcp.c85
-rw-r--r--net/ipv4/tcp_diag.c5
-rw-r--r--net/ipv4/tcp_fastopen.c2
-rw-r--r--net/ipv4/tcp_input.c37
-rw-r--r--net/ipv4/tcp_ipv4.c34
-rw-r--r--net/ipv4/tcp_minisocks.c17
-rw-r--r--net/ipv4/tcp_output.c32
-rw-r--r--net/ipv4/tcp_timer.c20
-rw-r--r--net/ipv4/udp.c44
-rw-r--r--net/ipv6/addrconf.c17
-rw-r--r--net/ipv6/addrconf_core.c1
-rw-r--r--net/ipv6/inet6_hashtables.c2
-rw-r--r--net/ipv6/ip6_gre.c5
-rw-r--r--net/ipv6/ip6_input.c12
-rw-r--r--net/ipv6/ip6_output.c3
-rw-r--r--net/ipv6/netfilter.c3
-rw-r--r--net/ipv6/netfilter/nf_dup_ipv6.c2
-rw-r--r--net/ipv6/raw.c2
-rw-r--r--net/ipv6/tcp_ipv6.c18
-rw-r--r--net/ipv6/udp.c11
-rw-r--r--net/l2tp/l2tp_core.c2
-rw-r--r--net/l2tp/l2tp_eth.c3
-rw-r--r--net/l2tp/l2tp_ip.c2
-rw-r--r--net/l2tp/l2tp_ip6.c2
-rw-r--r--net/llc/af_llc.c34
-rw-r--r--net/llc/llc_c_ac.c8
-rw-r--r--net/llc/llc_conn.c69
-rw-r--r--net/llc/llc_if.c12
-rw-r--r--net/llc/llc_s_ac.c12
-rw-r--r--net/llc/llc_sap.c23
-rw-r--r--net/mac80211/debugfs_netdev.c11
-rw-r--r--net/mac80211/mlme.c5
-rw-r--r--net/mac80211/rx.c11
-rw-r--r--net/mac80211/scan.c30
-rw-r--r--net/mac80211/util.c13
-rw-r--r--net/netfilter/ipvs/ip_vs_app.c12
-rw-r--r--net/netfilter/ipvs/ip_vs_ctl.c29
-rw-r--r--net/netfilter/ipvs/ip_vs_pe.c3
-rw-r--r--net/netfilter/ipvs/ip_vs_sched.c3
-rw-r--r--net/netfilter/ipvs/ip_vs_sync.c13
-rw-r--r--net/netfilter/ipvs/ip_vs_xmit.c2
-rw-r--r--net/netfilter/nf_conntrack_core.c4
-rw-r--r--net/netfilter/nf_flow_table_core.c3
-rw-r--r--net/netfilter/nf_tables_offload.c2
-rw-r--r--net/netfilter/nft_connlimit.c7
-rw-r--r--net/netfilter/nft_payload.c38
-rw-r--r--net/netrom/af_netrom.c23
-rw-r--r--net/nfc/llcp_sock.c11
-rw-r--r--net/openvswitch/actions.c5
-rw-r--r--net/openvswitch/datapath.c20
-rw-r--r--net/openvswitch/vport-internal_dev.c13
-rw-r--r--net/packet/af_packet.c4
-rw-r--r--net/phonet/socket.c4
-rw-r--r--net/rds/ib.c6
-rw-r--r--net/rose/af_rose.c23
-rw-r--r--net/rxrpc/ar-internal.h2
-rw-r--r--net/rxrpc/call_accept.c5
-rw-r--r--net/rxrpc/call_object.c34
-rw-r--r--net/rxrpc/conn_client.c9
-rw-r--r--net/rxrpc/conn_object.c13
-rw-r--r--net/rxrpc/conn_service.c2
-rw-r--r--net/rxrpc/peer_event.c11
-rw-r--r--net/rxrpc/peer_object.c16
-rw-r--r--net/rxrpc/recvmsg.c24
-rw-r--r--net/rxrpc/sendmsg.c3
-rw-r--r--net/sched/act_api.c23
-rw-r--r--net/sched/act_mirred.c6
-rw-r--r--net/sched/act_mpls.c12
-rw-r--r--net/sched/cls_api.c36
-rw-r--r--net/sched/em_meta.c4
-rw-r--r--net/sched/sch_api.c3
-rw-r--r--net/sched/sch_cbq.c43
-rw-r--r--net/sched/sch_cbs.c2
-rw-r--r--net/sched/sch_dsmark.c2
-rw-r--r--net/sched/sch_etf.c2
-rw-r--r--net/sched/sch_generic.c19
-rw-r--r--net/sched/sch_hhf.c8
-rw-r--r--net/sched/sch_netem.c11
-rw-r--r--net/sched/sch_sfb.c13
-rw-r--r--net/sched/sch_sfq.c14
-rw-r--r--net/sched/sch_taprio.c11
-rw-r--r--net/sctp/diag.c2
-rw-r--r--net/sctp/input.c18
-rw-r--r--net/sctp/sm_make_chunk.c12
-rw-r--r--net/sctp/socket.c10
-rw-r--r--net/smc/af_smc.c13
-rw-r--r--net/smc/smc_core.c7
-rw-r--r--net/smc/smc_pnet.c2
-rw-r--r--net/smc/smc_rx.c29
-rw-r--r--net/sunrpc/xprtsock.c17
-rw-r--r--net/tipc/link.c29
-rw-r--r--net/tipc/msg.c5
-rw-r--r--net/tipc/socket.c12
-rw-r--r--net/unix/af_unix.c6
-rw-r--r--net/vmw_vsock/af_vsock.c18
-rw-r--r--net/vmw_vsock/hyperv_transport.c2
-rw-r--r--net/vmw_vsock/virtio_transport_common.c19
-rw-r--r--net/wireless/chan.c5
-rw-r--r--net/wireless/nl80211.c48
-rw-r--r--net/wireless/reg.c3
-rw-r--r--net/wireless/reg.h8
-rw-r--r--net/wireless/scan.c30
-rw-r--r--net/wireless/util.c3
-rw-r--r--net/wireless/wext-compat.c2
-rw-r--r--net/wireless/wext-sme.c8
-rw-r--r--net/x25/x25_dev.c2
-rw-r--r--net/xdp/xdp_umem.c6
-rw-r--r--net/xdp/xsk.c42
-rw-r--r--net/xfrm/xfrm_input.c2
-rw-r--r--net/xfrm/xfrm_interface.c2
-rw-r--r--net/xfrm/xfrm_output.c2
-rw-r--r--net/xfrm/xfrm_policy.c2
-rw-r--r--samples/bpf/asm_goto_workaround.h13
-rw-r--r--samples/bpf/task_fd_query_user.c1
-rw-r--r--scripts/Kbuild.include5
-rw-r--r--scripts/Makefile.build2
-rw-r--r--scripts/Makefile.lib2
-rw-r--r--scripts/coccinelle/api/devm_platform_ioremap_resource.cocci60
-rw-r--r--scripts/coccinelle/misc/add_namespace.cocci2
-rw-r--r--scripts/gdb/linux/dmesg.py16
-rw-r--r--scripts/gdb/linux/symbols.py8
-rw-r--r--scripts/gdb/linux/utils.py25
-rw-r--r--scripts/mod/modpost.c42
-rwxr-xr-xscripts/namespace.pl13
-rw-r--r--scripts/nsdeps4
-rw-r--r--scripts/recordmcount.h5
-rwxr-xr-xscripts/setlocalversion2
-rw-r--r--security/integrity/Makefile3
-rw-r--r--security/selinux/ss/services.c9
-rw-r--r--sound/hda/ext/hdac_ext_controller.c5
-rw-r--r--sound/pci/hda/patch_hdmi.c2
-rw-r--r--sound/pci/hda/patch_realtek.c35
-rw-r--r--sound/usb/pcm.c3
-rw-r--r--tools/arch/arm/include/uapi/asm/kvm.h4
-rw-r--r--tools/arch/arm64/include/uapi/asm/kvm.h4
-rw-r--r--tools/arch/s390/include/uapi/asm/kvm.h6
-rw-r--r--tools/arch/x86/include/uapi/asm/vmx.h2
-rw-r--r--tools/bpf/Makefile6
-rw-r--r--tools/include/uapi/asm-generic/mman-common.h3
-rw-r--r--tools/include/uapi/drm/i915_drm.h1
-rw-r--r--tools/include/uapi/linux/fs.h55
-rw-r--r--tools/include/uapi/linux/fscrypt.h181
-rw-r--r--tools/include/uapi/linux/kvm.h3
-rw-r--r--tools/include/uapi/linux/usbdevice_fs.h4
-rw-r--r--tools/lib/bpf/Makefile33
-rw-r--r--tools/lib/bpf/libbpf_internal.h16
-rw-r--r--tools/lib/bpf/xsk.c4
-rw-r--r--tools/lib/subcmd/Makefile8
-rw-r--r--tools/perf/Documentation/asciidoc.conf3
-rw-r--r--tools/perf/Documentation/jitdump-specification.txt4
-rw-r--r--tools/perf/arch/arm/annotate/instructions.c4
-rw-r--r--tools/perf/arch/arm64/annotate/instructions.c4
-rw-r--r--tools/perf/arch/powerpc/util/header.c3
-rw-r--r--tools/perf/arch/s390/annotate/instructions.c6
-rw-r--r--tools/perf/arch/s390/util/header.c9
-rw-r--r--tools/perf/arch/x86/annotate/instructions.c6
-rw-r--r--tools/perf/arch/x86/util/header.c3
-rw-r--r--tools/perf/builtin-kvm.c7
-rw-r--r--tools/perf/builtin-script.c6
-rwxr-xr-xtools/perf/check-headers.sh1
-rw-r--r--tools/perf/pmu-events/arch/s390/cf_z15/basic.json (renamed from tools/perf/pmu-events/arch/s390/cf_m8561/basic.json)0
-rw-r--r--tools/perf/pmu-events/arch/s390/cf_z15/crypto.json (renamed from tools/perf/pmu-events/arch/s390/cf_m8561/crypto.json)0
-rw-r--r--tools/perf/pmu-events/arch/s390/cf_z15/crypto6.json (renamed from tools/perf/pmu-events/arch/s390/cf_m8561/crypto6.json)0
-rw-r--r--tools/perf/pmu-events/arch/s390/cf_z15/extended.json (renamed from tools/perf/pmu-events/arch/s390/cf_m8561/extended.json)0
-rw-r--r--tools/perf/pmu-events/arch/s390/cf_z15/transaction.json7
-rw-r--r--tools/perf/pmu-events/arch/s390/mapfile.csv2
-rw-r--r--tools/perf/pmu-events/jevents.c12
-rw-r--r--tools/perf/tests/perf-hooks.c3
-rw-r--r--tools/perf/util/annotate.c35
-rw-r--r--tools/perf/util/annotate.h4
-rw-r--r--tools/perf/util/evsel.c3
-rw-r--r--tools/perf/util/jitdump.c6
-rw-r--r--tools/perf/util/llvm-utils.c6
-rw-r--r--tools/perf/util/map.c3
-rw-r--r--tools/perf/util/python.c6
-rw-r--r--tools/testing/selftests/Makefile19
-rw-r--r--tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c2
-rw-r--r--tools/testing/selftests/bpf/prog_tests/tcp_rtt.c3
-rwxr-xr-xtools/testing/selftests/bpf/test_flow_dissector.sh3
-rwxr-xr-xtools/testing/selftests/bpf/test_lwt_ip_encap.sh6
-rwxr-xr-xtools/testing/selftests/bpf/test_tc_edt.sh2
-rw-r--r--tools/testing/selftests/kselftest/runner.sh36
-rwxr-xr-xtools/testing/selftests/kselftest_install.sh4
-rw-r--r--tools/testing/selftests/kvm/Makefile3
-rw-r--r--tools/testing/selftests/kvm/include/x86_64/processor.h3
-rw-r--r--tools/testing/selftests/kvm/include/x86_64/vmx.h14
-rw-r--r--tools/testing/selftests/kvm/lib/kvm_util.c2
-rw-r--r--tools/testing/selftests/kvm/lib/kvm_util_internal.h3
-rw-r--r--tools/testing/selftests/kvm/lib/x86_64/processor.c2
-rw-r--r--tools/testing/selftests/kvm/lib/x86_64/vmx.c201
-rw-r--r--tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c156
-rw-r--r--tools/testing/selftests/net/.gitignore1
-rwxr-xr-xtools/testing/selftests/net/fib_tests.sh21
-rwxr-xr-x[-rw-r--r--]tools/testing/selftests/net/l2tp.sh0
-rw-r--r--tools/testing/selftests/net/udpgso.c16
-rw-r--r--tools/testing/selftests/pidfd/Makefile2
-rw-r--r--tools/testing/selftests/powerpc/mm/tlbie_test.c2
-rw-r--r--tools/testing/selftests/rtc/settings1
-rw-r--r--tools/testing/selftests/vm/gup_benchmark.c2
-rw-r--r--tools/testing/selftests/watchdog/watchdog-test.c27
-rw-r--r--tools/virtio/crypto/hash.h (renamed from arch/arm64/kernel/vdso/gettimeofday.S)0
-rw-r--r--tools/virtio/linux/dma-mapping.h2
-rw-r--r--tools/virtio/xen/xen.h6
-rw-r--r--usr/include/Makefile10
-rw-r--r--virt/kvm/arm/vgic/trace.h2
-rw-r--r--virt/kvm/kvm_main.c10
1087 files changed, 10460 insertions, 8969 deletions
diff --git a/CREDITS b/CREDITS
index 8b67a85844b5..031605d46b4d 100644
--- a/CREDITS
+++ b/CREDITS
@@ -1637,6 +1637,10 @@ S: Panoramastrasse 18
1637S: D-69126 Heidelberg 1637S: D-69126 Heidelberg
1638S: Germany 1638S: Germany
1639 1639
1640N: Simon Horman
1641M: horms@verge.net.au
1642D: Renesas ARM/ARM64 SoC maintainer
1643
1640N: Christopher Horn 1644N: Christopher Horn
1641E: chorn@warwick.net 1645E: chorn@warwick.net
1642D: Miscellaneous sysctl hacks 1646D: Miscellaneous sysctl hacks
diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst
index 0fa8c0e615c2..5361ebec3361 100644
--- a/Documentation/admin-guide/cgroup-v2.rst
+++ b/Documentation/admin-guide/cgroup-v2.rst
@@ -615,8 +615,8 @@ on an IO device and is an example of this type.
615Protections 615Protections
616----------- 616-----------
617 617
618A cgroup is protected to be allocated upto the configured amount of 618A cgroup is protected upto the configured amount of the resource
619the resource if the usages of all its ancestors are under their 619as long as the usages of all its ancestors are under their
620protected levels. Protections can be hard guarantees or best effort 620protected levels. Protections can be hard guarantees or best effort
621soft boundaries. Protections can also be over-committed in which case 621soft boundaries. Protections can also be over-committed in which case
622only upto the amount available to the parent is protected among 622only upto the amount available to the parent is protected among
@@ -1096,7 +1096,10 @@ PAGE_SIZE multiple when read back.
1096 is within its effective min boundary, the cgroup's memory 1096 is within its effective min boundary, the cgroup's memory
1097 won't be reclaimed under any conditions. If there is no 1097 won't be reclaimed under any conditions. If there is no
1098 unprotected reclaimable memory available, OOM killer 1098 unprotected reclaimable memory available, OOM killer
1099 is invoked. 1099 is invoked. Above the effective min boundary (or
1100 effective low boundary if it is higher), pages are reclaimed
1101 proportionally to the overage, reducing reclaim pressure for
1102 smaller overages.
1100 1103
1101 Effective min boundary is limited by memory.min values of 1104 Effective min boundary is limited by memory.min values of
1102 all ancestor cgroups. If there is memory.min overcommitment 1105 all ancestor cgroups. If there is memory.min overcommitment
@@ -1118,7 +1121,10 @@ PAGE_SIZE multiple when read back.
1118 Best-effort memory protection. If the memory usage of a 1121 Best-effort memory protection. If the memory usage of a
1119 cgroup is within its effective low boundary, the cgroup's 1122 cgroup is within its effective low boundary, the cgroup's
1120 memory won't be reclaimed unless memory can be reclaimed 1123 memory won't be reclaimed unless memory can be reclaimed
1121 from unprotected cgroups. 1124 from unprotected cgroups. Above the effective low boundary (or
1125 effective min boundary if it is higher), pages are reclaimed
1126 proportionally to the overage, reducing reclaim pressure for
1127 smaller overages.
1122 1128
1123 Effective low boundary is limited by memory.low values of 1129 Effective low boundary is limited by memory.low values of
1124 all ancestor cgroups. If there is memory.low overcommitment 1130 all ancestor cgroups. If there is memory.low overcommitment
@@ -2482,8 +2488,10 @@ system performance due to overreclaim, to the point where the feature
2482becomes self-defeating. 2488becomes self-defeating.
2483 2489
2484The memory.low boundary on the other hand is a top-down allocated 2490The memory.low boundary on the other hand is a top-down allocated
2485reserve. A cgroup enjoys reclaim protection when it's within its low, 2491reserve. A cgroup enjoys reclaim protection when it's within its
2486which makes delegation of subtrees possible. 2492effective low, which makes delegation of subtrees possible. It also
2493enjoys having reclaim pressure proportional to its overage when
2494above its effective low.
2487 2495
2488The original high boundary, the hard limit, is defined as a strict 2496The original high boundary, the hard limit, is defined as a strict
2489limit that can not budge, even if the OOM killer has to be called. 2497limit that can not budge, even if the OOM killer has to be called.
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index c7ac2f3ac99f..a84a83f8881e 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -5302,6 +5302,10 @@
5302 the unplug protocol 5302 the unplug protocol
5303 never -- do not unplug even if version check succeeds 5303 never -- do not unplug even if version check succeeds
5304 5304
5305 xen_legacy_crash [X86,XEN]
5306 Crash from Xen panic notifier, without executing late
5307 panic() code such as dumping handler.
5308
5305 xen_nopvspin [X86,XEN] 5309 xen_nopvspin [X86,XEN]
5306 Disables the ticketlock slowpath using Xen PV 5310 Disables the ticketlock slowpath using Xen PV
5307 optimizations. 5311 optimizations.
diff --git a/Documentation/arm64/memory.rst b/Documentation/arm64/memory.rst
index b040909e45f8..02e02175e6f5 100644
--- a/Documentation/arm64/memory.rst
+++ b/Documentation/arm64/memory.rst
@@ -154,11 +154,18 @@ return virtual addresses to userspace from a 48-bit range.
154 154
155Software can "opt-in" to receiving VAs from a 52-bit space by 155Software can "opt-in" to receiving VAs from a 52-bit space by
156specifying an mmap hint parameter that is larger than 48-bit. 156specifying an mmap hint parameter that is larger than 48-bit.
157
157For example: 158For example:
158 maybe_high_address = mmap(~0UL, size, prot, flags,...); 159
160.. code-block:: c
161
162 maybe_high_address = mmap(~0UL, size, prot, flags,...);
159 163
160It is also possible to build a debug kernel that returns addresses 164It is also possible to build a debug kernel that returns addresses
161from a 52-bit space by enabling the following kernel config options: 165from a 52-bit space by enabling the following kernel config options:
166
167.. code-block:: sh
168
162 CONFIG_EXPERT=y && CONFIG_ARM64_FORCE_52BIT=y 169 CONFIG_EXPERT=y && CONFIG_ARM64_FORCE_52BIT=y
163 170
164Note that this option is only intended for debugging applications 171Note that this option is only intended for debugging applications
diff --git a/Documentation/arm64/silicon-errata.rst b/Documentation/arm64/silicon-errata.rst
index 17ea3fecddaa..ab7ed2fd072f 100644
--- a/Documentation/arm64/silicon-errata.rst
+++ b/Documentation/arm64/silicon-errata.rst
@@ -107,6 +107,8 @@ stable kernels.
107+----------------+-----------------+-----------------+-----------------------------+ 107+----------------+-----------------+-----------------+-----------------------------+
108| Cavium | ThunderX2 SMMUv3| #126 | N/A | 108| Cavium | ThunderX2 SMMUv3| #126 | N/A |
109+----------------+-----------------+-----------------+-----------------------------+ 109+----------------+-----------------+-----------------+-----------------------------+
110| Cavium | ThunderX2 Core | #219 | CAVIUM_TX2_ERRATUM_219 |
111+----------------+-----------------+-----------------+-----------------------------+
110+----------------+-----------------+-----------------+-----------------------------+ 112+----------------+-----------------+-----------------+-----------------------------+
111| Freescale/NXP | LS2080A/LS1043A | A-008585 | FSL_ERRATUM_A008585 | 113| Freescale/NXP | LS2080A/LS1043A | A-008585 | FSL_ERRATUM_A008585 |
112+----------------+-----------------+-----------------+-----------------------------+ 114+----------------+-----------------+-----------------+-----------------------------+
diff --git a/Documentation/core-api/index.rst b/Documentation/core-api/index.rst
index fa16a0538dcb..ab0eae1c153a 100644
--- a/Documentation/core-api/index.rst
+++ b/Documentation/core-api/index.rst
@@ -38,6 +38,7 @@ Core utilities
38 protection-keys 38 protection-keys
39 ../RCU/index 39 ../RCU/index
40 gcc-plugins 40 gcc-plugins
41 symbol-namespaces
41 42
42 43
43Interfaces for kernel debugging 44Interfaces for kernel debugging
diff --git a/Documentation/core-api/memory-allocation.rst b/Documentation/core-api/memory-allocation.rst
index 7744aa3bf2e0..939e3dfc86e9 100644
--- a/Documentation/core-api/memory-allocation.rst
+++ b/Documentation/core-api/memory-allocation.rst
@@ -98,6 +98,10 @@ limited. The actual limit depends on the hardware and the kernel
98configuration, but it is a good practice to use `kmalloc` for objects 98configuration, but it is a good practice to use `kmalloc` for objects
99smaller than page size. 99smaller than page size.
100 100
101The address of a chunk allocated with `kmalloc` is aligned to at least
102ARCH_KMALLOC_MINALIGN bytes. For sizes which are a power of two, the
103alignment is also guaranteed to be at least the respective size.
104
101For large allocations you can use :c:func:`vmalloc` and 105For large allocations you can use :c:func:`vmalloc` and
102:c:func:`vzalloc`, or directly request pages from the page 106:c:func:`vzalloc`, or directly request pages from the page
103allocator. The memory allocated by `vmalloc` and related functions is 107allocator. The memory allocated by `vmalloc` and related functions is
diff --git a/Documentation/kbuild/namespaces.rst b/Documentation/core-api/symbol-namespaces.rst
index 982ed7b568ac..982ed7b568ac 100644
--- a/Documentation/kbuild/namespaces.rst
+++ b/Documentation/core-api/symbol-namespaces.rst
diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst
index b72d07d70239..525296121d89 100644
--- a/Documentation/dev-tools/kasan.rst
+++ b/Documentation/dev-tools/kasan.rst
@@ -41,6 +41,9 @@ smaller binary while the latter is 1.1 - 2 times faster.
41Both KASAN modes work with both SLUB and SLAB memory allocators. 41Both KASAN modes work with both SLUB and SLAB memory allocators.
42For better bug detection and nicer reporting, enable CONFIG_STACKTRACE. 42For better bug detection and nicer reporting, enable CONFIG_STACKTRACE.
43 43
44To augment reports with last allocation and freeing stack of the physical page,
45it is recommended to enable also CONFIG_PAGE_OWNER and boot with page_owner=on.
46
44To disable instrumentation for specific files or directories, add a line 47To disable instrumentation for specific files or directories, add a line
45similar to the following to the respective kernel Makefile: 48similar to the following to the respective kernel Makefile:
46 49
diff --git a/Documentation/dev-tools/kselftest.rst b/Documentation/dev-tools/kselftest.rst
index 25604904fa6e..ecdfdc9d4b03 100644
--- a/Documentation/dev-tools/kselftest.rst
+++ b/Documentation/dev-tools/kselftest.rst
@@ -89,6 +89,22 @@ To build, save output files in a separate directory with KBUILD_OUTPUT ::
89 89
90 $ export KBUILD_OUTPUT=/tmp/kselftest; make TARGETS="size timers" kselftest 90 $ export KBUILD_OUTPUT=/tmp/kselftest; make TARGETS="size timers" kselftest
91 91
92Additionally you can use the "SKIP_TARGETS" variable on the make command
93line to specify one or more targets to exclude from the TARGETS list.
94
95To run all tests but a single subsystem::
96
97 $ make -C tools/testing/selftests SKIP_TARGETS=ptrace run_tests
98
99You can specify multiple tests to skip::
100
101 $ make SKIP_TARGETS="size timers" kselftest
102
103You can also specify a restricted list of tests to run together with a
104dedicated skiplist::
105
106 $ make TARGETS="bpf breakpoints size timers" SKIP_TARGETS=bpf kselftest
107
92See the top-level tools/testing/selftests/Makefile for the list of all 108See the top-level tools/testing/selftests/Makefile for the list of all
93possible targets. 109possible targets.
94 110
diff --git a/Documentation/devicetree/bindings/dsp/fsl,dsp.yaml b/Documentation/devicetree/bindings/dsp/fsl,dsp.yaml
index 3248595dc93c..f04870d84542 100644
--- a/Documentation/devicetree/bindings/dsp/fsl,dsp.yaml
+++ b/Documentation/devicetree/bindings/dsp/fsl,dsp.yaml
@@ -85,4 +85,5 @@ examples:
85 <&pd IMX_SC_R_DSP_RAM>; 85 <&pd IMX_SC_R_DSP_RAM>;
86 mbox-names = "txdb0", "txdb1", "rxdb0", "rxdb1"; 86 mbox-names = "txdb0", "txdb1", "rxdb0", "rxdb1";
87 mboxes = <&lsio_mu13 2 0>, <&lsio_mu13 2 1>, <&lsio_mu13 3 0>, <&lsio_mu13 3 1>; 87 mboxes = <&lsio_mu13 2 0>, <&lsio_mu13 2 1>, <&lsio_mu13 3 0>, <&lsio_mu13 3 1>;
88 memory-region = <&dsp_reserved>;
88 }; 89 };
diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml
index 676ec42e1438..567a33a83dce 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml
@@ -43,13 +43,9 @@ properties:
43 43
44 dvdd-supply: 44 dvdd-supply:
45 description: DVdd voltage supply 45 description: DVdd voltage supply
46 items:
47 - const: dvdd
48 46
49 avdd-supply: 47 avdd-supply:
50 description: AVdd voltage supply 48 description: AVdd voltage supply
51 items:
52 - const: avdd
53 49
54 adi,rejection-60-Hz-enable: 50 adi,rejection-60-Hz-enable:
55 description: | 51 description: |
@@ -99,6 +95,9 @@ required:
99examples: 95examples:
100 - | 96 - |
101 spi0 { 97 spi0 {
98 #address-cells = <1>;
99 #size-cells = <0>;
100
102 adc@0 { 101 adc@0 {
103 compatible = "adi,ad7192"; 102 compatible = "adi,ad7192";
104 reg = <0>; 103 reg = <0>;
diff --git a/Documentation/devicetree/bindings/media/rc.yaml b/Documentation/devicetree/bindings/media/rc.yaml
index 3d5c154fd230..9054555e6608 100644
--- a/Documentation/devicetree/bindings/media/rc.yaml
+++ b/Documentation/devicetree/bindings/media/rc.yaml
@@ -73,7 +73,6 @@ properties:
73 - rc-genius-tvgo-a11mce 73 - rc-genius-tvgo-a11mce
74 - rc-gotview7135 74 - rc-gotview7135
75 - rc-hauppauge 75 - rc-hauppauge
76 - rc-hauppauge
77 - rc-hisi-poplar 76 - rc-hisi-poplar
78 - rc-hisi-tv-demo 77 - rc-hisi-tv-demo
79 - rc-imon-mce 78 - rc-imon-mce
diff --git a/Documentation/devicetree/bindings/phy/lantiq,vrx200-pcie-phy.yaml b/Documentation/devicetree/bindings/phy/lantiq,vrx200-pcie-phy.yaml
index 8a56a8526cef..a97482179cf5 100644
--- a/Documentation/devicetree/bindings/phy/lantiq,vrx200-pcie-phy.yaml
+++ b/Documentation/devicetree/bindings/phy/lantiq,vrx200-pcie-phy.yaml
@@ -37,7 +37,7 @@ properties:
37 - description: exclusive PHY reset line 37 - description: exclusive PHY reset line
38 - description: shared reset line between the PCIe PHY and PCIe controller 38 - description: shared reset line between the PCIe PHY and PCIe controller
39 39
40 resets-names: 40 reset-names:
41 items: 41 items:
42 - const: phy 42 - const: phy
43 - const: pcie 43 - const: pcie
diff --git a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
index dd63151dc8b6..b143d9a21b2d 100644
--- a/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
+++ b/Documentation/devicetree/bindings/serial/renesas,sci-serial.txt
@@ -26,6 +26,8 @@ Required properties:
26 - "renesas,hscif-r8a77470" for R8A77470 (RZ/G1C) HSCIF compatible UART. 26 - "renesas,hscif-r8a77470" for R8A77470 (RZ/G1C) HSCIF compatible UART.
27 - "renesas,scif-r8a774a1" for R8A774A1 (RZ/G2M) SCIF compatible UART. 27 - "renesas,scif-r8a774a1" for R8A774A1 (RZ/G2M) SCIF compatible UART.
28 - "renesas,hscif-r8a774a1" for R8A774A1 (RZ/G2M) HSCIF compatible UART. 28 - "renesas,hscif-r8a774a1" for R8A774A1 (RZ/G2M) HSCIF compatible UART.
29 - "renesas,scif-r8a774b1" for R8A774B1 (RZ/G2N) SCIF compatible UART.
30 - "renesas,hscif-r8a774b1" for R8A774B1 (RZ/G2N) HSCIF compatible UART.
29 - "renesas,scif-r8a774c0" for R8A774C0 (RZ/G2E) SCIF compatible UART. 31 - "renesas,scif-r8a774c0" for R8A774C0 (RZ/G2E) SCIF compatible UART.
30 - "renesas,hscif-r8a774c0" for R8A774C0 (RZ/G2E) HSCIF compatible UART. 32 - "renesas,hscif-r8a774c0" for R8A774C0 (RZ/G2E) HSCIF compatible UART.
31 - "renesas,scif-r8a7778" for R8A7778 (R-Car M1) SCIF compatible UART. 33 - "renesas,scif-r8a7778" for R8A7778 (R-Car M1) SCIF compatible UART.
diff --git a/Documentation/devicetree/bindings/usb/amlogic,dwc3.txt b/Documentation/devicetree/bindings/usb/amlogic,dwc3.txt
index b9f04e617eb7..6ffb09be7a76 100644
--- a/Documentation/devicetree/bindings/usb/amlogic,dwc3.txt
+++ b/Documentation/devicetree/bindings/usb/amlogic,dwc3.txt
@@ -85,8 +85,8 @@ A child node must exist to represent the core DWC2 IP block. The name of
85the node is not important. The content of the node is defined in dwc2.txt. 85the node is not important. The content of the node is defined in dwc2.txt.
86 86
87PHY documentation is provided in the following places: 87PHY documentation is provided in the following places:
88- Documentation/devicetree/bindings/phy/meson-g12a-usb2-phy.txt 88- Documentation/devicetree/bindings/phy/amlogic,meson-g12a-usb2-phy.yaml
89- Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt 89- Documentation/devicetree/bindings/phy/amlogic,meson-g12a-usb3-pcie-phy.yaml
90 90
91Example device nodes: 91Example device nodes:
92 usb: usb@ffe09000 { 92 usb: usb@ffe09000 {
diff --git a/Documentation/devicetree/bindings/usb/generic-ehci.yaml b/Documentation/devicetree/bindings/usb/generic-ehci.yaml
index 059f6ef1ad4a..1ca64c85191a 100644
--- a/Documentation/devicetree/bindings/usb/generic-ehci.yaml
+++ b/Documentation/devicetree/bindings/usb/generic-ehci.yaml
@@ -63,7 +63,11 @@ properties:
63 description: 63 description:
64 Set this flag to force EHCI reset after resume. 64 Set this flag to force EHCI reset after resume.
65 65
66 phys: true 66 phys:
67 description: PHY specifier for the USB PHY
68
69 phy-names:
70 const: usb
67 71
68required: 72required:
69 - compatible 73 - compatible
@@ -89,6 +93,7 @@ examples:
89 interrupts = <39>; 93 interrupts = <39>;
90 clocks = <&ahb_gates 1>; 94 clocks = <&ahb_gates 1>;
91 phys = <&usbphy 1>; 95 phys = <&usbphy 1>;
96 phy-names = "usb";
92 }; 97 };
93 98
94... 99...
diff --git a/Documentation/devicetree/bindings/usb/generic-ohci.yaml b/Documentation/devicetree/bindings/usb/generic-ohci.yaml
index da5a14becbe5..bcffec1f1341 100644
--- a/Documentation/devicetree/bindings/usb/generic-ohci.yaml
+++ b/Documentation/devicetree/bindings/usb/generic-ohci.yaml
@@ -67,7 +67,11 @@ properties:
67 description: 67 description:
68 Overrides the detected port count 68 Overrides the detected port count
69 69
70 phys: true 70 phys:
71 description: PHY specifier for the USB PHY
72
73 phy-names:
74 const: usb
71 75
72required: 76required:
73 - compatible 77 - compatible
@@ -84,6 +88,7 @@ examples:
84 interrupts = <64>; 88 interrupts = <64>;
85 clocks = <&usb_clk 6>, <&ahb_gates 2>; 89 clocks = <&usb_clk 6>, <&ahb_gates 2>;
86 phys = <&usbphy 1>; 90 phys = <&usbphy 1>;
91 phy-names = "usb";
87 }; 92 };
88 93
89... 94...
diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
index f3e4acecabe8..42d8814f903a 100644
--- a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
@@ -33,7 +33,7 @@ Required properties:
33 "dma_ck": dma_bus clock for data transfer by DMA, 33 "dma_ck": dma_bus clock for data transfer by DMA,
34 "xhci_ck": controller clock 34 "xhci_ck": controller clock
35 35
36 - phys : see usb-hcd.txt in the current directory 36 - phys : see usb-hcd.yaml in the current directory
37 37
38Optional properties: 38Optional properties:
39 - wakeup-source : enable USB remote wakeup; 39 - wakeup-source : enable USB remote wakeup;
@@ -53,7 +53,7 @@ Optional properties:
53 See: Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt 53 See: Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt
54 - imod-interval-ns: default interrupt moderation interval is 5000ns 54 - imod-interval-ns: default interrupt moderation interval is 5000ns
55 55
56additionally the properties from usb-hcd.txt (in the current directory) are 56additionally the properties from usb-hcd.yaml (in the current directory) are
57supported. 57supported.
58 58
59Example: 59Example:
diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
index b9af7f5ee91d..e0ae6096f7ac 100644
--- a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
@@ -17,7 +17,7 @@ Required properties:
17 - clock-names : must contain "sys_ck" for clock of controller, 17 - clock-names : must contain "sys_ck" for clock of controller,
18 the following clocks are optional: 18 the following clocks are optional:
19 "ref_ck", "mcu_ck" and "dma_ck"; 19 "ref_ck", "mcu_ck" and "dma_ck";
20 - phys : see usb-hcd.txt in the current directory 20 - phys : see usb-hcd.yaml in the current directory
21 - dr_mode : should be one of "host", "peripheral" or "otg", 21 - dr_mode : should be one of "host", "peripheral" or "otg",
22 refer to usb/generic.txt 22 refer to usb/generic.txt
23 23
@@ -60,7 +60,7 @@ Optional properties:
60 - mediatek,u3p-dis-msk : mask to disable u3ports, bit0 for u3port0, 60 - mediatek,u3p-dis-msk : mask to disable u3ports, bit0 for u3port0,
61 bit1 for u3port1, ... etc; 61 bit1 for u3port1, ... etc;
62 62
63additionally the properties from usb-hcd.txt (in the current directory) are 63additionally the properties from usb-hcd.yaml (in the current directory) are
64supported. 64supported.
65 65
66Sub-nodes: 66Sub-nodes:
diff --git a/Documentation/devicetree/bindings/usb/usb-hcd.yaml b/Documentation/devicetree/bindings/usb/usb-hcd.yaml
index 9c8c56d3a792..7263b7f2b510 100644
--- a/Documentation/devicetree/bindings/usb/usb-hcd.yaml
+++ b/Documentation/devicetree/bindings/usb/usb-hcd.yaml
@@ -18,8 +18,13 @@ properties:
18 description: 18 description:
19 List of all the USB PHYs on this HCD 19 List of all the USB PHYs on this HCD
20 20
21 phy-names:
22 description:
23 Name specifier for the USB PHY
24
21examples: 25examples:
22 - | 26 - |
23 usb { 27 usb {
24 phys = <&usb2_phy1>, <&usb3_phy1>; 28 phys = <&usb2_phy1>, <&usb3_phy1>;
29 phy-names = "usb";
25 }; 30 };
diff --git a/Documentation/devicetree/bindings/usb/usb-uhci.txt b/Documentation/devicetree/bindings/usb/usb-uhci.txt
index cc2e6f7d602e..d1702eb2c8bd 100644
--- a/Documentation/devicetree/bindings/usb/usb-uhci.txt
+++ b/Documentation/devicetree/bindings/usb/usb-uhci.txt
@@ -6,7 +6,7 @@ Required properties:
6- reg : Should contain 1 register ranges(address and length) 6- reg : Should contain 1 register ranges(address and length)
7- interrupts : UHCI controller interrupt 7- interrupts : UHCI controller interrupt
8 8
9additionally the properties from usb-hcd.txt (in the current directory) are 9additionally the properties from usb-hcd.yaml (in the current directory) are
10supported. 10supported.
11 11
12Example: 12Example:
diff --git a/Documentation/devicetree/bindings/usb/usb-xhci.txt b/Documentation/devicetree/bindings/usb/usb-xhci.txt
index 97400e8f8605..b49b819571f9 100644
--- a/Documentation/devicetree/bindings/usb/usb-xhci.txt
+++ b/Documentation/devicetree/bindings/usb/usb-xhci.txt
@@ -41,9 +41,9 @@ Optional properties:
41 - usb3-lpm-capable: determines if platform is USB3 LPM capable 41 - usb3-lpm-capable: determines if platform is USB3 LPM capable
42 - quirk-broken-port-ped: set if the controller has broken port disable mechanism 42 - quirk-broken-port-ped: set if the controller has broken port disable mechanism
43 - imod-interval-ns: default interrupt moderation interval is 5000ns 43 - imod-interval-ns: default interrupt moderation interval is 5000ns
44 - phys : see usb-hcd.txt in the current directory 44 - phys : see usb-hcd.yaml in the current directory
45 45
46additionally the properties from usb-hcd.txt (in the current directory) are 46additionally the properties from usb-hcd.yaml (in the current directory) are
47supported. 47supported.
48 48
49 49
diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index 8147c3f218bf..230ad59b462b 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -7,6 +7,7 @@ Linux Hardware Monitoring
7 7
8 hwmon-kernel-api 8 hwmon-kernel-api
9 pmbus-core 9 pmbus-core
10 inspur-ipsps1
10 submitting-patches 11 submitting-patches
11 sysfs-interface 12 sysfs-interface
12 userspace-tools 13 userspace-tools
diff --git a/Documentation/hwmon/inspur-ipsps1.rst b/Documentation/hwmon/inspur-ipsps1.rst
index 2b871ae3448f..292c0c26bdd1 100644
--- a/Documentation/hwmon/inspur-ipsps1.rst
+++ b/Documentation/hwmon/inspur-ipsps1.rst
@@ -1,5 +1,5 @@
1Kernel driver inspur-ipsps1 1Kernel driver inspur-ipsps1
2======================= 2===========================
3 3
4Supported chips: 4Supported chips:
5 5
diff --git a/Documentation/hwmon/k10temp.rst b/Documentation/hwmon/k10temp.rst
index 12a86ba17de9..4451d59b9425 100644
--- a/Documentation/hwmon/k10temp.rst
+++ b/Documentation/hwmon/k10temp.rst
@@ -21,10 +21,17 @@ Supported chips:
21 21
22* AMD Family 14h processors: "Brazos" (C/E/G/Z-Series) 22* AMD Family 14h processors: "Brazos" (C/E/G/Z-Series)
23 23
24* AMD Family 15h processors: "Bulldozer" (FX-Series), "Trinity", "Kaveri", "Carrizo" 24* AMD Family 15h processors: "Bulldozer" (FX-Series), "Trinity", "Kaveri",
25 "Carrizo", "Stoney Ridge", "Bristol Ridge"
25 26
26* AMD Family 16h processors: "Kabini", "Mullins" 27* AMD Family 16h processors: "Kabini", "Mullins"
27 28
29* AMD Family 17h processors: "Zen", "Zen 2"
30
31* AMD Family 18h processors: "Hygon Dhyana"
32
33* AMD Family 19h processors: "Zen 3"
34
28 Prefix: 'k10temp' 35 Prefix: 'k10temp'
29 36
30 Addresses scanned: PCI space 37 Addresses scanned: PCI space
@@ -110,3 +117,12 @@ The maximum value for Tctl is available in the file temp1_max.
110If the BIOS has enabled hardware temperature control, the threshold at 117If the BIOS has enabled hardware temperature control, the threshold at
111which the processor will throttle itself to avoid damage is available in 118which the processor will throttle itself to avoid damage is available in
112temp1_crit and temp1_crit_hyst. 119temp1_crit and temp1_crit_hyst.
120
121On some AMD CPUs, there is a difference between the die temperature (Tdie) and
122the reported temperature (Tctl). Tdie is the real measured temperature, and
123Tctl is used for fan control. While Tctl is always available as temp1_input,
124the driver exports Tdie temperature as temp2_input for those CPUs which support
125it.
126
127Models from 17h family report relative temperature, the driver aims to
128compensate and report the real temperature.
diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst
index 6ba9d5365ff3..b89c88168d6a 100644
--- a/Documentation/kbuild/makefiles.rst
+++ b/Documentation/kbuild/makefiles.rst
@@ -954,11 +954,6 @@ When kbuild executes, the following steps are followed (roughly):
954 954
955 From commandline LDFLAGS_MODULE shall be used (see kbuild.txt). 955 From commandline LDFLAGS_MODULE shall be used (see kbuild.txt).
956 956
957 KBUILD_ARFLAGS Options for $(AR) when creating archives
958
959 $(KBUILD_ARFLAGS) set by the top level Makefile to "D" (deterministic
960 mode) if this option is supported by $(AR).
961
962 KBUILD_LDS 957 KBUILD_LDS
963 958
964 The linker script with full path. Assigned by the top-level Makefile. 959 The linker script with full path. Assigned by the top-level Makefile.
diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst
index d2ae799237fd..774a998dcf37 100644
--- a/Documentation/kbuild/modules.rst
+++ b/Documentation/kbuild/modules.rst
@@ -498,10 +498,11 @@ build.
498 will be written containing all exported symbols that were not 498 will be written containing all exported symbols that were not
499 defined in the kernel. 499 defined in the kernel.
500 500
501--- 6.3 Symbols From Another External Module 5016.3 Symbols From Another External Module
502----------------------------------------
502 503
503 Sometimes, an external module uses exported symbols from 504 Sometimes, an external module uses exported symbols from
504 another external module. kbuild needs to have full knowledge of 505 another external module. Kbuild needs to have full knowledge of
505 all symbols to avoid spitting out warnings about undefined 506 all symbols to avoid spitting out warnings about undefined
506 symbols. Three solutions exist for this situation. 507 symbols. Three solutions exist for this situation.
507 508
@@ -521,7 +522,7 @@ build.
521 The top-level kbuild file would then look like:: 522 The top-level kbuild file would then look like::
522 523
523 #./Kbuild (or ./Makefile): 524 #./Kbuild (or ./Makefile):
524 obj-y := foo/ bar/ 525 obj-m := foo/ bar/
525 526
526 And executing:: 527 And executing::
527 528
diff --git a/Documentation/kbuild/reproducible-builds.rst b/Documentation/kbuild/reproducible-builds.rst
index ab92e98c89c8..503393854e2e 100644
--- a/Documentation/kbuild/reproducible-builds.rst
+++ b/Documentation/kbuild/reproducible-builds.rst
@@ -16,16 +16,21 @@ the kernel may be unreproducible, and how to avoid them.
16Timestamps 16Timestamps
17---------- 17----------
18 18
19The kernel embeds a timestamp in two places: 19The kernel embeds timestamps in three places:
20 20
21* The version string exposed by ``uname()`` and included in 21* The version string exposed by ``uname()`` and included in
22 ``/proc/version`` 22 ``/proc/version``
23 23
24* File timestamps in the embedded initramfs 24* File timestamps in the embedded initramfs
25 25
26By default the timestamp is the current time. This must be overridden 26* If enabled via ``CONFIG_IKHEADERS``, file timestamps of kernel
27using the `KBUILD_BUILD_TIMESTAMP`_ variable. If you are building 27 headers embedded in the kernel or respective module,
28from a git commit, you could use its commit date. 28 exposed via ``/sys/kernel/kheaders.tar.xz``
29
30By default the timestamp is the current time and in the case of
31``kheaders`` the various files' modification times. This must
32be overridden using the `KBUILD_BUILD_TIMESTAMP`_ variable.
33If you are building from a git commit, you could use its commit date.
29 34
30The kernel does *not* use the ``__DATE__`` and ``__TIME__`` macros, 35The kernel does *not* use the ``__DATE__`` and ``__TIME__`` macros,
31and enables warnings if they are used. If you incorporate external 36and enables warnings if they are used. If you incorporate external
diff --git a/Documentation/networking/device_drivers/index.rst b/Documentation/networking/device_drivers/index.rst
index f51f92571e39..c1f7f75e5fd9 100644
--- a/Documentation/networking/device_drivers/index.rst
+++ b/Documentation/networking/device_drivers/index.rst
@@ -23,6 +23,7 @@ Contents:
23 intel/ice 23 intel/ice
24 google/gve 24 google/gve
25 mellanox/mlx5 25 mellanox/mlx5
26 netronome/nfp
26 pensando/ionic 27 pensando/ionic
27 28
28.. only:: subproject and html 29.. only:: subproject and html
diff --git a/Documentation/networking/device_drivers/pensando/ionic.rst b/Documentation/networking/device_drivers/pensando/ionic.rst
index 67b6839d516b..13935896bee6 100644
--- a/Documentation/networking/device_drivers/pensando/ionic.rst
+++ b/Documentation/networking/device_drivers/pensando/ionic.rst
@@ -36,8 +36,10 @@ Support
36======= 36=======
37For general Linux networking support, please use the netdev mailing 37For general Linux networking support, please use the netdev mailing
38list, which is monitored by Pensando personnel:: 38list, which is monitored by Pensando personnel::
39
39 netdev@vger.kernel.org 40 netdev@vger.kernel.org
40 41
41For more specific support needs, please use the Pensando driver support 42For more specific support needs, please use the Pensando driver support
42email:: 43email::
43 drivers@pensando.io 44
45 drivers@pensando.io
diff --git a/Documentation/networking/ip-sysctl.txt b/Documentation/networking/ip-sysctl.txt
index 49e95f438ed7..8d4ad1d1ae26 100644
--- a/Documentation/networking/ip-sysctl.txt
+++ b/Documentation/networking/ip-sysctl.txt
@@ -207,8 +207,8 @@ TCP variables:
207 207
208somaxconn - INTEGER 208somaxconn - INTEGER
209 Limit of socket listen() backlog, known in userspace as SOMAXCONN. 209 Limit of socket listen() backlog, known in userspace as SOMAXCONN.
210 Defaults to 128. See also tcp_max_syn_backlog for additional tuning 210 Defaults to 4096. (Was 128 before linux-5.4)
211 for TCP sockets. 211 See also tcp_max_syn_backlog for additional tuning for TCP sockets.
212 212
213tcp_abort_on_overflow - BOOLEAN 213tcp_abort_on_overflow - BOOLEAN
214 If listening service is too slow to accept new connections, 214 If listening service is too slow to accept new connections,
@@ -408,11 +408,14 @@ tcp_max_orphans - INTEGER
408 up to ~64K of unswappable memory. 408 up to ~64K of unswappable memory.
409 409
410tcp_max_syn_backlog - INTEGER 410tcp_max_syn_backlog - INTEGER
411 Maximal number of remembered connection requests, which have not 411 Maximal number of remembered connection requests (SYN_RECV),
412 received an acknowledgment from connecting client. 412 which have not received an acknowledgment from connecting client.
413 This is a per-listener limit.
413 The minimal value is 128 for low memory machines, and it will 414 The minimal value is 128 for low memory machines, and it will
414 increase in proportion to the memory of machine. 415 increase in proportion to the memory of machine.
415 If server suffers from overload, try increasing this number. 416 If server suffers from overload, try increasing this number.
417 Remember to also check /proc/sys/net/core/somaxconn
418 A SYN_RECV request socket consumes about 304 bytes of memory.
416 419
417tcp_max_tw_buckets - INTEGER 420tcp_max_tw_buckets - INTEGER
418 Maximal number of timewait sockets held by system simultaneously. 421 Maximal number of timewait sockets held by system simultaneously.
diff --git a/Documentation/networking/j1939.rst b/Documentation/networking/j1939.rst
index ce7e7a044e08..dc60b13fcd09 100644
--- a/Documentation/networking/j1939.rst
+++ b/Documentation/networking/j1939.rst
@@ -272,7 +272,7 @@ supported flags are:
272* MSG_DONTWAIT, i.e. non-blocking operation. 272* MSG_DONTWAIT, i.e. non-blocking operation.
273 273
274recvmsg(2) 274recvmsg(2)
275^^^^^^^^^ 275^^^^^^^^^^
276 276
277In most cases recvmsg(2) is needed if you want to extract more information than 277In most cases recvmsg(2) is needed if you want to extract more information than
278recvfrom(2) can provide. For example package priority and timestamp. The 278recvfrom(2) can provide. For example package priority and timestamp. The
diff --git a/Documentation/networking/net_dim.txt b/Documentation/networking/net_dim.txt
index 9cb31c5e2dcd..9bdb7d5a3ba3 100644
--- a/Documentation/networking/net_dim.txt
+++ b/Documentation/networking/net_dim.txt
@@ -92,16 +92,16 @@ under some conditions.
92Part III: Registering a Network Device to DIM 92Part III: Registering a Network Device to DIM
93============================================== 93==============================================
94 94
95Net DIM API exposes the main function net_dim(struct net_dim *dim, 95Net DIM API exposes the main function net_dim(struct dim *dim,
96struct net_dim_sample end_sample). This function is the entry point to the Net 96struct dim_sample end_sample). This function is the entry point to the Net
97DIM algorithm and has to be called every time the driver would like to check if 97DIM algorithm and has to be called every time the driver would like to check if
98it should change interrupt moderation parameters. The driver should provide two 98it should change interrupt moderation parameters. The driver should provide two
99data structures: struct net_dim and struct net_dim_sample. Struct net_dim 99data structures: struct dim and struct dim_sample. Struct dim
100describes the state of DIM for a specific object (RX queue, TX queue, 100describes the state of DIM for a specific object (RX queue, TX queue,
101other queues, etc.). This includes the current selected profile, previous data 101other queues, etc.). This includes the current selected profile, previous data
102samples, the callback function provided by the driver and more. 102samples, the callback function provided by the driver and more.
103Struct net_dim_sample describes a data sample, which will be compared to the 103Struct dim_sample describes a data sample, which will be compared to the
104data sample stored in struct net_dim in order to decide on the algorithm's next 104data sample stored in struct dim in order to decide on the algorithm's next
105step. The sample should include bytes, packets and interrupts, measured by 105step. The sample should include bytes, packets and interrupts, measured by
106the driver. 106the driver.
107 107
@@ -110,9 +110,9 @@ main net_dim() function. The recommended method is to call net_dim() on each
110interrupt. Since Net DIM has a built-in moderation and it might decide to skip 110interrupt. Since Net DIM has a built-in moderation and it might decide to skip
111iterations under certain conditions, there is no need to moderate the net_dim() 111iterations under certain conditions, there is no need to moderate the net_dim()
112calls as well. As mentioned above, the driver needs to provide an object of type 112calls as well. As mentioned above, the driver needs to provide an object of type
113struct net_dim to the net_dim() function call. It is advised for each entity 113struct dim to the net_dim() function call. It is advised for each entity
114using Net DIM to hold a struct net_dim as part of its data structure and use it 114using Net DIM to hold a struct dim as part of its data structure and use it
115as the main Net DIM API object. The struct net_dim_sample should hold the latest 115as the main Net DIM API object. The struct dim_sample should hold the latest
116bytes, packets and interrupts count. No need to perform any calculations, just 116bytes, packets and interrupts count. No need to perform any calculations, just
117include the raw data. 117include the raw data.
118 118
@@ -132,19 +132,19 @@ usage is not complete but it should make the outline of the usage clear.
132 132
133my_driver.c: 133my_driver.c:
134 134
135#include <linux/net_dim.h> 135#include <linux/dim.h>
136 136
137/* Callback for net DIM to schedule on a decision to change moderation */ 137/* Callback for net DIM to schedule on a decision to change moderation */
138void my_driver_do_dim_work(struct work_struct *work) 138void my_driver_do_dim_work(struct work_struct *work)
139{ 139{
140 /* Get struct net_dim from struct work_struct */ 140 /* Get struct dim from struct work_struct */
141 struct net_dim *dim = container_of(work, struct net_dim, 141 struct dim *dim = container_of(work, struct dim,
142 work); 142 work);
143 /* Do interrupt moderation related stuff */ 143 /* Do interrupt moderation related stuff */
144 ... 144 ...
145 145
146 /* Signal net DIM work is done and it should move to next iteration */ 146 /* Signal net DIM work is done and it should move to next iteration */
147 dim->state = NET_DIM_START_MEASURE; 147 dim->state = DIM_START_MEASURE;
148} 148}
149 149
150/* My driver's interrupt handler */ 150/* My driver's interrupt handler */
@@ -152,13 +152,13 @@ int my_driver_handle_interrupt(struct my_driver_entity *my_entity, ...)
152{ 152{
153 ... 153 ...
154 /* A struct to hold current measured data */ 154 /* A struct to hold current measured data */
155 struct net_dim_sample dim_sample; 155 struct dim_sample dim_sample;
156 ... 156 ...
157 /* Initiate data sample struct with current data */ 157 /* Initiate data sample struct with current data */
158 net_dim_sample(my_entity->events, 158 dim_update_sample(my_entity->events,
159 my_entity->packets, 159 my_entity->packets,
160 my_entity->bytes, 160 my_entity->bytes,
161 &dim_sample); 161 &dim_sample);
162 /* Call net DIM */ 162 /* Call net DIM */
163 net_dim(&my_entity->dim, dim_sample); 163 net_dim(&my_entity->dim, dim_sample);
164 ... 164 ...
diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
index f4a2198187f9..ada573b7d703 100644
--- a/Documentation/process/coding-style.rst
+++ b/Documentation/process/coding-style.rst
@@ -56,7 +56,7 @@ instead of ``double-indenting`` the ``case`` labels. E.g.:
56 case 'K': 56 case 'K':
57 case 'k': 57 case 'k':
58 mem <<= 10; 58 mem <<= 10;
59 /* fall through */ 59 fallthrough;
60 default: 60 default:
61 break; 61 break;
62 } 62 }
diff --git a/Documentation/process/deprecated.rst b/Documentation/process/deprecated.rst
index 053b24a6dd38..179f2a5625a0 100644
--- a/Documentation/process/deprecated.rst
+++ b/Documentation/process/deprecated.rst
@@ -122,14 +122,27 @@ memory adjacent to the stack (when built without `CONFIG_VMAP_STACK=y`)
122 122
123Implicit switch case fall-through 123Implicit switch case fall-through
124--------------------------------- 124---------------------------------
125The C language allows switch cases to "fall through" when 125The C language allows switch cases to "fall-through" when a "break" statement
126a "break" statement is missing at the end of a case. This, 126is missing at the end of a case. This, however, introduces ambiguity in the
127however, introduces ambiguity in the code, as it's not always 127code, as it's not always clear if the missing break is intentional or a bug.
128clear if the missing break is intentional or a bug. As there 128
129have been a long list of flaws `due to missing "break" statements 129As there have been a long list of flaws `due to missing "break" statements
130<https://cwe.mitre.org/data/definitions/484.html>`_, we no longer allow 130<https://cwe.mitre.org/data/definitions/484.html>`_, we no longer allow
131"implicit fall-through". In order to identify an intentional fall-through 131"implicit fall-through".
132case, we have adopted the marking used by static analyzers: a comment 132
133saying `/* Fall through */`. Once the C++17 `__attribute__((fallthrough))` 133In order to identify intentional fall-through cases, we have adopted a
134is more widely handled by C compilers, static analyzers, and IDEs, we can 134pseudo-keyword macro 'fallthrough' which expands to gcc's extension
135switch to using that instead. 135__attribute__((__fallthrough__)). `Statement Attributes
136<https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html>`_
137
138When the C17/C18 [[fallthrough]] syntax is more commonly supported by
139C compilers, static analyzers, and IDEs, we can switch to using that syntax
140for the macro pseudo-keyword.
141
142All switch/case blocks must end in one of:
143
144 break;
145 fallthrough;
146 continue;
147 goto <label>;
148 return [expression];
diff --git a/Documentation/usb/rio.rst b/Documentation/usb/rio.rst
deleted file mode 100644
index ea73475471db..000000000000
--- a/Documentation/usb/rio.rst
+++ /dev/null
@@ -1,109 +0,0 @@
1============
2Diamonds Rio
3============
4
5Copyright (C) 1999, 2000 Bruce Tenison
6
7Portions Copyright (C) 1999, 2000 David Nelson
8
9Thanks to David Nelson for guidance and the usage of the scanner.txt
10and scanner.c files to model our driver and this informative file.
11
12Mar. 2, 2000
13
14Changes
15=======
16
17- Initial Revision
18
19
20Overview
21========
22
23This README will address issues regarding how to configure the kernel
24to access a RIO 500 mp3 player.
25Before I explain how to use this to access the Rio500 please be warned:
26
27.. warning::
28
29 Please note that this software is still under development. The authors
30 are in no way responsible for any damage that may occur, no matter how
31 inconsequential.
32
33It seems that the Rio has a problem when sending .mp3 with low batteries.
34I suggest when the batteries are low and you want to transfer stuff that you
35replace it with a fresh one. In my case, what happened is I lost two 16kb
36blocks (they are no longer usable to store information to it). But I don't
37know if that's normal or not; it could simply be a problem with the flash
38memory.
39
40In an extreme case, I left my Rio playing overnight and the batteries wore
41down to nothing and appear to have corrupted the flash memory. My RIO
42needed to be replaced as a result. Diamond tech support is aware of the
43problem. Do NOT allow your batteries to wear down to nothing before
44changing them. It appears RIO 500 firmware does not handle low battery
45power well at all.
46
47On systems with OHCI controllers, the kernel OHCI code appears to have
48power on problems with some chipsets. If you are having problems
49connecting to your RIO 500, try turning it on first and then plugging it
50into the USB cable.
51
52Contact Information
53-------------------
54
55 The main page for the project is hosted at sourceforge.net in the following
56 URL: <http://rio500.sourceforge.net>. You can also go to the project's
57 sourceforge home page at: <http://sourceforge.net/projects/rio500/>.
58 There is also a mailing list: rio500-users@lists.sourceforge.net
59
60Authors
61-------
62
63Most of the code was written by Cesar Miquel <miquel@df.uba.ar>. Keith
64Clayton <kclayton@jps.net> is incharge of the PPC port and making sure
65things work there. Bruce Tenison <btenison@dibbs.net> is adding support
66for .fon files and also does testing. The program will mostly sure be
67re-written and Pete Ikusz along with the rest will re-design it. I would
68also like to thank Tri Nguyen <tmn_3022000@hotmail.com> who provided use
69with some important information regarding the communication with the Rio.
70
71Additional Information and userspace tools
72
73 http://rio500.sourceforge.net/
74
75
76Requirements
77============
78
79A host with a USB port running a Linux kernel with RIO 500 support enabled.
80
81The driver is a module called rio500, which should be automatically loaded
82as you plug in your device. If that fails you can manually load it with
83
84 modprobe rio500
85
86Udev should automatically create a device node as soon as plug in your device.
87If that fails, you can manually add a device for the USB rio500::
88
89 mknod /dev/usb/rio500 c 180 64
90
91In that case, set appropriate permissions for /dev/usb/rio500 (don't forget
92about group and world permissions). Both read and write permissions are
93required for proper operation.
94
95That's it. The Rio500 Utils at: http://rio500.sourceforge.net should
96be able to access the rio500.
97
98Limits
99======
100
101You can use only a single rio500 device at a time with your computer.
102
103Bugs
104====
105
106If you encounter any problems feel free to drop me an email.
107
108Bruce Tenison
109btenison@dibbs.net
diff --git a/MAINTAINERS b/MAINTAINERS
index 296de2b51c83..b6b6c75f7e6f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2165,12 +2165,10 @@ F: arch/arm64/boot/dts/realtek/
2165F: Documentation/devicetree/bindings/arm/realtek.yaml 2165F: Documentation/devicetree/bindings/arm/realtek.yaml
2166 2166
2167ARM/RENESAS ARM64 ARCHITECTURE 2167ARM/RENESAS ARM64 ARCHITECTURE
2168M: Simon Horman <horms@verge.net.au>
2169M: Geert Uytterhoeven <geert+renesas@glider.be> 2168M: Geert Uytterhoeven <geert+renesas@glider.be>
2170M: Magnus Damm <magnus.damm@gmail.com> 2169M: Magnus Damm <magnus.damm@gmail.com>
2171L: linux-renesas-soc@vger.kernel.org 2170L: linux-renesas-soc@vger.kernel.org
2172Q: http://patchwork.kernel.org/project/linux-renesas-soc/list/ 2171Q: http://patchwork.kernel.org/project/linux-renesas-soc/list/
2173T: git git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas.git next
2174T: git git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-devel.git next 2172T: git git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-devel.git next
2175S: Supported 2173S: Supported
2176F: arch/arm64/boot/dts/renesas/ 2174F: arch/arm64/boot/dts/renesas/
@@ -2282,12 +2280,10 @@ S: Maintained
2282F: drivers/media/platform/s5p-mfc/ 2280F: drivers/media/platform/s5p-mfc/
2283 2281
2284ARM/SHMOBILE ARM ARCHITECTURE 2282ARM/SHMOBILE ARM ARCHITECTURE
2285M: Simon Horman <horms@verge.net.au>
2286M: Geert Uytterhoeven <geert+renesas@glider.be> 2283M: Geert Uytterhoeven <geert+renesas@glider.be>
2287M: Magnus Damm <magnus.damm@gmail.com> 2284M: Magnus Damm <magnus.damm@gmail.com>
2288L: linux-renesas-soc@vger.kernel.org 2285L: linux-renesas-soc@vger.kernel.org
2289Q: http://patchwork.kernel.org/project/linux-renesas-soc/list/ 2286Q: http://patchwork.kernel.org/project/linux-renesas-soc/list/
2290T: git git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas.git next
2291T: git git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-devel.git next 2287T: git git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-devel.git next
2292S: Supported 2288S: Supported
2293F: arch/arm/boot/dts/emev2* 2289F: arch/arm/boot/dts/emev2*
@@ -6112,7 +6108,10 @@ M: Gao Xiang <gaoxiang25@huawei.com>
6112M: Chao Yu <yuchao0@huawei.com> 6108M: Chao Yu <yuchao0@huawei.com>
6113L: linux-erofs@lists.ozlabs.org 6109L: linux-erofs@lists.ozlabs.org
6114S: Maintained 6110S: Maintained
6111T: git git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
6112F: Documentation/filesystems/erofs.txt
6115F: fs/erofs/ 6113F: fs/erofs/
6114F: include/trace/events/erofs.h
6116 6115
6117ERRSEQ ERROR TRACKING INFRASTRUCTURE 6116ERRSEQ ERROR TRACKING INFRASTRUCTURE
6118M: Jeff Layton <jlayton@kernel.org> 6117M: Jeff Layton <jlayton@kernel.org>
@@ -9075,6 +9074,7 @@ F: security/keys/
9075KGDB / KDB /debug_core 9074KGDB / KDB /debug_core
9076M: Jason Wessel <jason.wessel@windriver.com> 9075M: Jason Wessel <jason.wessel@windriver.com>
9077M: Daniel Thompson <daniel.thompson@linaro.org> 9076M: Daniel Thompson <daniel.thompson@linaro.org>
9077R: Douglas Anderson <dianders@chromium.org>
9078W: http://kgdb.wiki.kernel.org/ 9078W: http://kgdb.wiki.kernel.org/
9079L: kgdb-bugreport@lists.sourceforge.net 9079L: kgdb-bugreport@lists.sourceforge.net
9080T: git git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/kgdb.git 9080T: git git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/kgdb.git
@@ -9122,7 +9122,7 @@ F: drivers/auxdisplay/ks0108.c
9122F: include/linux/ks0108.h 9122F: include/linux/ks0108.h
9123 9123
9124L3MDEV 9124L3MDEV
9125M: David Ahern <dsa@cumulusnetworks.com> 9125M: David Ahern <dsahern@kernel.org>
9126L: netdev@vger.kernel.org 9126L: netdev@vger.kernel.org
9127S: Maintained 9127S: Maintained
9128F: net/l3mdev 9128F: net/l3mdev
@@ -9183,6 +9183,7 @@ M: Pavel Machek <pavel@ucw.cz>
9183R: Dan Murphy <dmurphy@ti.com> 9183R: Dan Murphy <dmurphy@ti.com>
9184L: linux-leds@vger.kernel.org 9184L: linux-leds@vger.kernel.org
9185T: git git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds.git 9185T: git git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds.git
9186T: git git://git.kernel.org/pub/scm/linux/kernel/git/pavel/linux-leds.git
9186S: Maintained 9187S: Maintained
9187F: Documentation/devicetree/bindings/leds/ 9188F: Documentation/devicetree/bindings/leds/
9188F: drivers/leds/ 9189F: drivers/leds/
@@ -10254,7 +10255,7 @@ MEDIATEK ETHERNET DRIVER
10254M: Felix Fietkau <nbd@openwrt.org> 10255M: Felix Fietkau <nbd@openwrt.org>
10255M: John Crispin <john@phrozen.org> 10256M: John Crispin <john@phrozen.org>
10256M: Sean Wang <sean.wang@mediatek.com> 10257M: Sean Wang <sean.wang@mediatek.com>
10257M: Nelson Chang <nelson.chang@mediatek.com> 10258M: Mark Lee <Mark-MC.Lee@mediatek.com>
10258L: netdev@vger.kernel.org 10259L: netdev@vger.kernel.org
10259S: Maintained 10260S: Maintained
10260F: drivers/net/ethernet/mediatek/ 10261F: drivers/net/ethernet/mediatek/
@@ -11406,7 +11407,6 @@ F: include/trace/events/tcp.h
11406NETWORKING [TLS] 11407NETWORKING [TLS]
11407M: Boris Pismenny <borisp@mellanox.com> 11408M: Boris Pismenny <borisp@mellanox.com>
11408M: Aviad Yehezkel <aviadye@mellanox.com> 11409M: Aviad Yehezkel <aviadye@mellanox.com>
11409M: Dave Watson <davejwatson@fb.com>
11410M: John Fastabend <john.fastabend@gmail.com> 11410M: John Fastabend <john.fastabend@gmail.com>
11411M: Daniel Borkmann <daniel@iogearbox.net> 11411M: Daniel Borkmann <daniel@iogearbox.net>
11412M: Jakub Kicinski <jakub.kicinski@netronome.com> 11412M: Jakub Kicinski <jakub.kicinski@netronome.com>
@@ -11543,6 +11543,7 @@ NSDEPS
11543M: Matthias Maennich <maennich@google.com> 11543M: Matthias Maennich <maennich@google.com>
11544S: Maintained 11544S: Maintained
11545F: scripts/nsdeps 11545F: scripts/nsdeps
11546F: Documentation/core-api/symbol-namespaces.rst
11546 11547
11547NTB AMD DRIVER 11548NTB AMD DRIVER
11548M: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> 11549M: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
@@ -12310,12 +12311,15 @@ F: arch/parisc/
12310F: Documentation/parisc/ 12311F: Documentation/parisc/
12311F: drivers/parisc/ 12312F: drivers/parisc/
12312F: drivers/char/agp/parisc-agp.c 12313F: drivers/char/agp/parisc-agp.c
12314F: drivers/input/misc/hp_sdc_rtc.c
12313F: drivers/input/serio/gscps2.c 12315F: drivers/input/serio/gscps2.c
12316F: drivers/input/serio/hp_sdc*
12314F: drivers/parport/parport_gsc.* 12317F: drivers/parport/parport_gsc.*
12315F: drivers/tty/serial/8250/8250_gsc.c 12318F: drivers/tty/serial/8250/8250_gsc.c
12316F: drivers/video/fbdev/sti* 12319F: drivers/video/fbdev/sti*
12317F: drivers/video/console/sti* 12320F: drivers/video/console/sti*
12318F: drivers/video/logo/logo_parisc* 12321F: drivers/video/logo/logo_parisc*
12322F: include/linux/hp_sdc.h
12319 12323
12320PARMAN 12324PARMAN
12321M: Jiri Pirko <jiri@mellanox.com> 12325M: Jiri Pirko <jiri@mellanox.com>
@@ -13359,7 +13363,7 @@ S: Maintained
13359F: drivers/scsi/qla1280.[ch] 13363F: drivers/scsi/qla1280.[ch]
13360 13364
13361QLOGIC QLA2XXX FC-SCSI DRIVER 13365QLOGIC QLA2XXX FC-SCSI DRIVER
13362M: qla2xxx-upstream@qlogic.com 13366M: hmadhani@marvell.com
13363L: linux-scsi@vger.kernel.org 13367L: linux-scsi@vger.kernel.org
13364S: Supported 13368S: Supported
13365F: Documentation/scsi/LICENSE.qla2xxx 13369F: Documentation/scsi/LICENSE.qla2xxx
@@ -16762,13 +16766,6 @@ W: http://www.linux-usb.org/usbnet
16762S: Maintained 16766S: Maintained
16763F: drivers/net/usb/dm9601.c 16767F: drivers/net/usb/dm9601.c
16764 16768
16765USB DIAMOND RIO500 DRIVER
16766M: Cesar Miquel <miquel@df.uba.ar>
16767L: rio500-users@lists.sourceforge.net
16768W: http://rio500.sourceforge.net
16769S: Maintained
16770F: drivers/usb/misc/rio500*
16771
16772USB EHCI DRIVER 16769USB EHCI DRIVER
16773M: Alan Stern <stern@rowland.harvard.edu> 16770M: Alan Stern <stern@rowland.harvard.edu>
16774L: linux-usb@vger.kernel.org 16771L: linux-usb@vger.kernel.org
@@ -17435,7 +17432,7 @@ F: include/linux/regulator/
17435K: regulator_get_optional 17432K: regulator_get_optional
17436 17433
17437VRF 17434VRF
17438M: David Ahern <dsa@cumulusnetworks.com> 17435M: David Ahern <dsahern@kernel.org>
17439M: Shrijeet Mukherjee <shrijeet@gmail.com> 17436M: Shrijeet Mukherjee <shrijeet@gmail.com>
17440L: netdev@vger.kernel.org 17437L: netdev@vger.kernel.org
17441S: Maintained 17438S: Maintained
diff --git a/Makefile b/Makefile
index 6f54f2f95743..ffd7a912fc46 100644
--- a/Makefile
+++ b/Makefile
@@ -2,8 +2,8 @@
2VERSION = 5 2VERSION = 5
3PATCHLEVEL = 4 3PATCHLEVEL = 4
4SUBLEVEL = 0 4SUBLEVEL = 0
5EXTRAVERSION = -rc1 5EXTRAVERSION = -rc3
6NAME = Bobtail Squid 6NAME = Nesting Opossum
7 7
8# *DOCUMENTATION* 8# *DOCUMENTATION*
9# To see a list of typical targets execute "make help" 9# To see a list of typical targets execute "make help"
@@ -206,24 +206,8 @@ ifndef KBUILD_CHECKSRC
206 KBUILD_CHECKSRC = 0 206 KBUILD_CHECKSRC = 0
207endif 207endif
208 208
209# Use make M=dir to specify directory of external module to build 209# Use make M=dir or set the environment variable KBUILD_EXTMOD to specify the
210# Old syntax make ... SUBDIRS=$PWD is still supported 210# directory of external module to build. Setting M= takes precedence.
211# Setting the environment variable KBUILD_EXTMOD take precedence
212ifdef SUBDIRS
213 $(warning ================= WARNING ================)
214 $(warning 'SUBDIRS' will be removed after Linux 5.3)
215 $(warning )
216 $(warning If you are building an individual subdirectory)
217 $(warning in the kernel tree, you can do like this:)
218 $(warning $$ make path/to/dir/you/want/to/build/)
219 $(warning (Do not forget the trailing slash))
220 $(warning )
221 $(warning If you are building an external module,)
222 $(warning Please use 'M=' or 'KBUILD_EXTMOD' instead)
223 $(warning ==========================================)
224 KBUILD_EXTMOD ?= $(SUBDIRS)
225endif
226
227ifeq ("$(origin M)", "command line") 211ifeq ("$(origin M)", "command line")
228 KBUILD_EXTMOD := $(M) 212 KBUILD_EXTMOD := $(M)
229endif 213endif
@@ -498,7 +482,6 @@ export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN
498export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE 482export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
499export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE 483export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
500export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL 484export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
501export KBUILD_ARFLAGS
502 485
503# Files to ignore in find ... statements 486# Files to ignore in find ... statements
504 487
@@ -616,7 +599,7 @@ endif
616# in addition to whatever we do anyway. 599# in addition to whatever we do anyway.
617# Just "make" or "make all" shall build modules as well 600# Just "make" or "make all" shall build modules as well
618 601
619ifneq ($(filter all _all modules,$(MAKECMDGOALS)),) 602ifneq ($(filter all _all modules nsdeps,$(MAKECMDGOALS)),)
620 KBUILD_MODULES := 1 603 KBUILD_MODULES := 1
621endif 604endif
622 605
@@ -914,9 +897,6 @@ ifdef CONFIG_RETPOLINE
914KBUILD_CFLAGS += $(call cc-option,-fcf-protection=none) 897KBUILD_CFLAGS += $(call cc-option,-fcf-protection=none)
915endif 898endif
916 899
917# use the deterministic mode of AR if available
918KBUILD_ARFLAGS := $(call ar-option,D)
919
920include scripts/Makefile.kasan 900include scripts/Makefile.kasan
921include scripts/Makefile.extrawarn 901include scripts/Makefile.extrawarn
922include scripts/Makefile.ubsan 902include scripts/Makefile.ubsan
@@ -1237,9 +1217,8 @@ PHONY += kselftest
1237kselftest: 1217kselftest:
1238 $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests 1218 $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests
1239 1219
1240PHONY += kselftest-clean 1220kselftest-%: FORCE
1241kselftest-clean: 1221 $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $*
1242 $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests clean
1243 1222
1244PHONY += kselftest-merge 1223PHONY += kselftest-merge
1245kselftest-merge: 1224kselftest-merge:
diff --git a/arch/arm/boot/dts/am335x-icev2.dts b/arch/arm/boot/dts/am335x-icev2.dts
index 18f70b35da4c..204bccfcc110 100644
--- a/arch/arm/boot/dts/am335x-icev2.dts
+++ b/arch/arm/boot/dts/am335x-icev2.dts
@@ -432,7 +432,7 @@
432 pinctrl-0 = <&mmc0_pins_default>; 432 pinctrl-0 = <&mmc0_pins_default>;
433}; 433};
434 434
435&gpio0 { 435&gpio0_target {
436 /* Do not idle the GPIO used for holding the VTT regulator */ 436 /* Do not idle the GPIO used for holding the VTT regulator */
437 ti,no-reset-on-init; 437 ti,no-reset-on-init;
438 ti,no-idle-on-init; 438 ti,no-idle-on-init;
diff --git a/arch/arm/boot/dts/am33xx-l4.dtsi b/arch/arm/boot/dts/am33xx-l4.dtsi
index 9915c891e05f..7a9eb2b0d45b 100644
--- a/arch/arm/boot/dts/am33xx-l4.dtsi
+++ b/arch/arm/boot/dts/am33xx-l4.dtsi
@@ -127,7 +127,7 @@
127 ranges = <0x0 0x5000 0x1000>; 127 ranges = <0x0 0x5000 0x1000>;
128 }; 128 };
129 129
130 target-module@7000 { /* 0x44e07000, ap 14 20.0 */ 130 gpio0_target: target-module@7000 { /* 0x44e07000, ap 14 20.0 */
131 compatible = "ti,sysc-omap2", "ti,sysc"; 131 compatible = "ti,sysc-omap2", "ti,sysc";
132 ti,hwmods = "gpio1"; 132 ti,hwmods = "gpio1";
133 reg = <0x7000 0x4>, 133 reg = <0x7000 0x4>,
@@ -2038,7 +2038,9 @@
2038 reg = <0xe000 0x4>, 2038 reg = <0xe000 0x4>,
2039 <0xe054 0x4>; 2039 <0xe054 0x4>;
2040 reg-names = "rev", "sysc"; 2040 reg-names = "rev", "sysc";
2041 ti,sysc-midle ; 2041 ti,sysc-midle = <SYSC_IDLE_FORCE>,
2042 <SYSC_IDLE_NO>,
2043 <SYSC_IDLE_SMART>;
2042 ti,sysc-sidle = <SYSC_IDLE_FORCE>, 2044 ti,sysc-sidle = <SYSC_IDLE_FORCE>,
2043 <SYSC_IDLE_NO>, 2045 <SYSC_IDLE_NO>,
2044 <SYSC_IDLE_SMART>; 2046 <SYSC_IDLE_SMART>;
diff --git a/arch/arm/boot/dts/am4372.dtsi b/arch/arm/boot/dts/am4372.dtsi
index 848e2a8884e2..14bbc438055f 100644
--- a/arch/arm/boot/dts/am4372.dtsi
+++ b/arch/arm/boot/dts/am4372.dtsi
@@ -337,6 +337,8 @@
337 ti,hwmods = "dss_dispc"; 337 ti,hwmods = "dss_dispc";
338 clocks = <&disp_clk>; 338 clocks = <&disp_clk>;
339 clock-names = "fck"; 339 clock-names = "fck";
340
341 max-memory-bandwidth = <230000000>;
340 }; 342 };
341 343
342 rfbi: rfbi@4832a800 { 344 rfbi: rfbi@4832a800 {
diff --git a/arch/arm/boot/dts/dra7-l4.dtsi b/arch/arm/boot/dts/dra7-l4.dtsi
index ea0e7c19eb4e..5cac2dd58241 100644
--- a/arch/arm/boot/dts/dra7-l4.dtsi
+++ b/arch/arm/boot/dts/dra7-l4.dtsi
@@ -2732,7 +2732,7 @@
2732 interrupt-names = "tx", "rx"; 2732 interrupt-names = "tx", "rx";
2733 dmas = <&edma_xbar 129 1>, <&edma_xbar 128 1>; 2733 dmas = <&edma_xbar 129 1>, <&edma_xbar 128 1>;
2734 dma-names = "tx", "rx"; 2734 dma-names = "tx", "rx";
2735 clocks = <&ipu_clkctrl DRA7_IPU_MCASP1_CLKCTRL 22>, 2735 clocks = <&ipu_clkctrl DRA7_IPU_MCASP1_CLKCTRL 0>,
2736 <&ipu_clkctrl DRA7_IPU_MCASP1_CLKCTRL 24>, 2736 <&ipu_clkctrl DRA7_IPU_MCASP1_CLKCTRL 24>,
2737 <&ipu_clkctrl DRA7_IPU_MCASP1_CLKCTRL 28>; 2737 <&ipu_clkctrl DRA7_IPU_MCASP1_CLKCTRL 28>;
2738 clock-names = "fck", "ahclkx", "ahclkr"; 2738 clock-names = "fck", "ahclkx", "ahclkr";
@@ -2768,8 +2768,8 @@
2768 interrupt-names = "tx", "rx"; 2768 interrupt-names = "tx", "rx";
2769 dmas = <&edma_xbar 131 1>, <&edma_xbar 130 1>; 2769 dmas = <&edma_xbar 131 1>, <&edma_xbar 130 1>;
2770 dma-names = "tx", "rx"; 2770 dma-names = "tx", "rx";
2771 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP2_CLKCTRL 22>, 2771 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP2_CLKCTRL 0>,
2772 <&l4per2_clkctrl DRA7_L4PER2_MCASP2_CLKCTRL 24>, 2772 <&ipu_clkctrl DRA7_IPU_MCASP1_CLKCTRL 24>,
2773 <&l4per2_clkctrl DRA7_L4PER2_MCASP2_CLKCTRL 28>; 2773 <&l4per2_clkctrl DRA7_L4PER2_MCASP2_CLKCTRL 28>;
2774 clock-names = "fck", "ahclkx", "ahclkr"; 2774 clock-names = "fck", "ahclkx", "ahclkr";
2775 status = "disabled"; 2775 status = "disabled";
@@ -2786,9 +2786,8 @@
2786 <SYSC_IDLE_SMART>; 2786 <SYSC_IDLE_SMART>;
2787 /* Domains (P, C): l4per_pwrdm, l4per2_clkdm */ 2787 /* Domains (P, C): l4per_pwrdm, l4per2_clkdm */
2788 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP3_CLKCTRL 0>, 2788 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP3_CLKCTRL 0>,
2789 <&l4per2_clkctrl DRA7_L4PER2_MCASP3_CLKCTRL 24>, 2789 <&l4per2_clkctrl DRA7_L4PER2_MCASP3_CLKCTRL 24>;
2790 <&l4per2_clkctrl DRA7_L4PER2_MCASP3_CLKCTRL 28>; 2790 clock-names = "fck", "ahclkx";
2791 clock-names = "fck", "ahclkx", "ahclkr";
2792 #address-cells = <1>; 2791 #address-cells = <1>;
2793 #size-cells = <1>; 2792 #size-cells = <1>;
2794 ranges = <0x0 0x68000 0x2000>, 2793 ranges = <0x0 0x68000 0x2000>,
@@ -2804,7 +2803,7 @@
2804 interrupt-names = "tx", "rx"; 2803 interrupt-names = "tx", "rx";
2805 dmas = <&edma_xbar 133 1>, <&edma_xbar 132 1>; 2804 dmas = <&edma_xbar 133 1>, <&edma_xbar 132 1>;
2806 dma-names = "tx", "rx"; 2805 dma-names = "tx", "rx";
2807 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP3_CLKCTRL 22>, 2806 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP3_CLKCTRL 0>,
2808 <&l4per2_clkctrl DRA7_L4PER2_MCASP3_CLKCTRL 24>; 2807 <&l4per2_clkctrl DRA7_L4PER2_MCASP3_CLKCTRL 24>;
2809 clock-names = "fck", "ahclkx"; 2808 clock-names = "fck", "ahclkx";
2810 status = "disabled"; 2809 status = "disabled";
@@ -2821,9 +2820,8 @@
2821 <SYSC_IDLE_SMART>; 2820 <SYSC_IDLE_SMART>;
2822 /* Domains (P, C): l4per_pwrdm, l4per2_clkdm */ 2821 /* Domains (P, C): l4per_pwrdm, l4per2_clkdm */
2823 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP4_CLKCTRL 0>, 2822 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP4_CLKCTRL 0>,
2824 <&l4per2_clkctrl DRA7_L4PER2_MCASP4_CLKCTRL 24>, 2823 <&l4per2_clkctrl DRA7_L4PER2_MCASP4_CLKCTRL 24>;
2825 <&l4per2_clkctrl DRA7_L4PER2_MCASP4_CLKCTRL 28>; 2824 clock-names = "fck", "ahclkx";
2826 clock-names = "fck", "ahclkx", "ahclkr";
2827 #address-cells = <1>; 2825 #address-cells = <1>;
2828 #size-cells = <1>; 2826 #size-cells = <1>;
2829 ranges = <0x0 0x6c000 0x2000>, 2827 ranges = <0x0 0x6c000 0x2000>,
@@ -2839,7 +2837,7 @@
2839 interrupt-names = "tx", "rx"; 2837 interrupt-names = "tx", "rx";
2840 dmas = <&edma_xbar 135 1>, <&edma_xbar 134 1>; 2838 dmas = <&edma_xbar 135 1>, <&edma_xbar 134 1>;
2841 dma-names = "tx", "rx"; 2839 dma-names = "tx", "rx";
2842 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP4_CLKCTRL 22>, 2840 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP4_CLKCTRL 0>,
2843 <&l4per2_clkctrl DRA7_L4PER2_MCASP4_CLKCTRL 24>; 2841 <&l4per2_clkctrl DRA7_L4PER2_MCASP4_CLKCTRL 24>;
2844 clock-names = "fck", "ahclkx"; 2842 clock-names = "fck", "ahclkx";
2845 status = "disabled"; 2843 status = "disabled";
@@ -2856,9 +2854,8 @@
2856 <SYSC_IDLE_SMART>; 2854 <SYSC_IDLE_SMART>;
2857 /* Domains (P, C): l4per_pwrdm, l4per2_clkdm */ 2855 /* Domains (P, C): l4per_pwrdm, l4per2_clkdm */
2858 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP5_CLKCTRL 0>, 2856 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP5_CLKCTRL 0>,
2859 <&l4per2_clkctrl DRA7_L4PER2_MCASP5_CLKCTRL 24>, 2857 <&l4per2_clkctrl DRA7_L4PER2_MCASP5_CLKCTRL 24>;
2860 <&l4per2_clkctrl DRA7_L4PER2_MCASP5_CLKCTRL 28>; 2858 clock-names = "fck", "ahclkx";
2861 clock-names = "fck", "ahclkx", "ahclkr";
2862 #address-cells = <1>; 2859 #address-cells = <1>;
2863 #size-cells = <1>; 2860 #size-cells = <1>;
2864 ranges = <0x0 0x70000 0x2000>, 2861 ranges = <0x0 0x70000 0x2000>,
@@ -2874,7 +2871,7 @@
2874 interrupt-names = "tx", "rx"; 2871 interrupt-names = "tx", "rx";
2875 dmas = <&edma_xbar 137 1>, <&edma_xbar 136 1>; 2872 dmas = <&edma_xbar 137 1>, <&edma_xbar 136 1>;
2876 dma-names = "tx", "rx"; 2873 dma-names = "tx", "rx";
2877 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP5_CLKCTRL 22>, 2874 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP5_CLKCTRL 0>,
2878 <&l4per2_clkctrl DRA7_L4PER2_MCASP5_CLKCTRL 24>; 2875 <&l4per2_clkctrl DRA7_L4PER2_MCASP5_CLKCTRL 24>;
2879 clock-names = "fck", "ahclkx"; 2876 clock-names = "fck", "ahclkx";
2880 status = "disabled"; 2877 status = "disabled";
@@ -2891,9 +2888,8 @@
2891 <SYSC_IDLE_SMART>; 2888 <SYSC_IDLE_SMART>;
2892 /* Domains (P, C): l4per_pwrdm, l4per2_clkdm */ 2889 /* Domains (P, C): l4per_pwrdm, l4per2_clkdm */
2893 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP6_CLKCTRL 0>, 2890 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP6_CLKCTRL 0>,
2894 <&l4per2_clkctrl DRA7_L4PER2_MCASP6_CLKCTRL 24>, 2891 <&l4per2_clkctrl DRA7_L4PER2_MCASP6_CLKCTRL 24>;
2895 <&l4per2_clkctrl DRA7_L4PER2_MCASP6_CLKCTRL 28>; 2892 clock-names = "fck", "ahclkx";
2896 clock-names = "fck", "ahclkx", "ahclkr";
2897 #address-cells = <1>; 2893 #address-cells = <1>;
2898 #size-cells = <1>; 2894 #size-cells = <1>;
2899 ranges = <0x0 0x74000 0x2000>, 2895 ranges = <0x0 0x74000 0x2000>,
@@ -2909,7 +2905,7 @@
2909 interrupt-names = "tx", "rx"; 2905 interrupt-names = "tx", "rx";
2910 dmas = <&edma_xbar 139 1>, <&edma_xbar 138 1>; 2906 dmas = <&edma_xbar 139 1>, <&edma_xbar 138 1>;
2911 dma-names = "tx", "rx"; 2907 dma-names = "tx", "rx";
2912 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP6_CLKCTRL 22>, 2908 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP6_CLKCTRL 0>,
2913 <&l4per2_clkctrl DRA7_L4PER2_MCASP6_CLKCTRL 24>; 2909 <&l4per2_clkctrl DRA7_L4PER2_MCASP6_CLKCTRL 24>;
2914 clock-names = "fck", "ahclkx"; 2910 clock-names = "fck", "ahclkx";
2915 status = "disabled"; 2911 status = "disabled";
@@ -2926,9 +2922,8 @@
2926 <SYSC_IDLE_SMART>; 2922 <SYSC_IDLE_SMART>;
2927 /* Domains (P, C): l4per_pwrdm, l4per2_clkdm */ 2923 /* Domains (P, C): l4per_pwrdm, l4per2_clkdm */
2928 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP7_CLKCTRL 0>, 2924 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP7_CLKCTRL 0>,
2929 <&l4per2_clkctrl DRA7_L4PER2_MCASP7_CLKCTRL 24>, 2925 <&l4per2_clkctrl DRA7_L4PER2_MCASP7_CLKCTRL 24>;
2930 <&l4per2_clkctrl DRA7_L4PER2_MCASP7_CLKCTRL 28>; 2926 clock-names = "fck", "ahclkx";
2931 clock-names = "fck", "ahclkx", "ahclkr";
2932 #address-cells = <1>; 2927 #address-cells = <1>;
2933 #size-cells = <1>; 2928 #size-cells = <1>;
2934 ranges = <0x0 0x78000 0x2000>, 2929 ranges = <0x0 0x78000 0x2000>,
@@ -2944,7 +2939,7 @@
2944 interrupt-names = "tx", "rx"; 2939 interrupt-names = "tx", "rx";
2945 dmas = <&edma_xbar 141 1>, <&edma_xbar 140 1>; 2940 dmas = <&edma_xbar 141 1>, <&edma_xbar 140 1>;
2946 dma-names = "tx", "rx"; 2941 dma-names = "tx", "rx";
2947 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP7_CLKCTRL 22>, 2942 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP7_CLKCTRL 0>,
2948 <&l4per2_clkctrl DRA7_L4PER2_MCASP7_CLKCTRL 24>; 2943 <&l4per2_clkctrl DRA7_L4PER2_MCASP7_CLKCTRL 24>;
2949 clock-names = "fck", "ahclkx"; 2944 clock-names = "fck", "ahclkx";
2950 status = "disabled"; 2945 status = "disabled";
@@ -2961,9 +2956,8 @@
2961 <SYSC_IDLE_SMART>; 2956 <SYSC_IDLE_SMART>;
2962 /* Domains (P, C): l4per_pwrdm, l4per2_clkdm */ 2957 /* Domains (P, C): l4per_pwrdm, l4per2_clkdm */
2963 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP8_CLKCTRL 0>, 2958 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP8_CLKCTRL 0>,
2964 <&l4per2_clkctrl DRA7_L4PER2_MCASP8_CLKCTRL 24>, 2959 <&l4per2_clkctrl DRA7_L4PER2_MCASP8_CLKCTRL 24>;
2965 <&l4per2_clkctrl DRA7_L4PER2_MCASP8_CLKCTRL 28>; 2960 clock-names = "fck", "ahclkx";
2966 clock-names = "fck", "ahclkx", "ahclkr";
2967 #address-cells = <1>; 2961 #address-cells = <1>;
2968 #size-cells = <1>; 2962 #size-cells = <1>;
2969 ranges = <0x0 0x7c000 0x2000>, 2963 ranges = <0x0 0x7c000 0x2000>,
@@ -2979,7 +2973,7 @@
2979 interrupt-names = "tx", "rx"; 2973 interrupt-names = "tx", "rx";
2980 dmas = <&edma_xbar 143 1>, <&edma_xbar 142 1>; 2974 dmas = <&edma_xbar 143 1>, <&edma_xbar 142 1>;
2981 dma-names = "tx", "rx"; 2975 dma-names = "tx", "rx";
2982 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP8_CLKCTRL 22>, 2976 clocks = <&l4per2_clkctrl DRA7_L4PER2_MCASP8_CLKCTRL 0>,
2983 <&l4per2_clkctrl DRA7_L4PER2_MCASP8_CLKCTRL 24>; 2977 <&l4per2_clkctrl DRA7_L4PER2_MCASP8_CLKCTRL 24>;
2984 clock-names = "fck", "ahclkx"; 2978 clock-names = "fck", "ahclkx";
2985 status = "disabled"; 2979 status = "disabled";
diff --git a/arch/arm/boot/dts/mt7629-rfb.dts b/arch/arm/boot/dts/mt7629-rfb.dts
index 3621b7d2b22a..9980c10c6e29 100644
--- a/arch/arm/boot/dts/mt7629-rfb.dts
+++ b/arch/arm/boot/dts/mt7629-rfb.dts
@@ -66,9 +66,21 @@
66 pinctrl-1 = <&ephy_leds_pins>; 66 pinctrl-1 = <&ephy_leds_pins>;
67 status = "okay"; 67 status = "okay";
68 68
69 gmac0: mac@0 {
70 compatible = "mediatek,eth-mac";
71 reg = <0>;
72 phy-mode = "2500base-x";
73 fixed-link {
74 speed = <2500>;
75 full-duplex;
76 pause;
77 };
78 };
79
69 gmac1: mac@1 { 80 gmac1: mac@1 {
70 compatible = "mediatek,eth-mac"; 81 compatible = "mediatek,eth-mac";
71 reg = <1>; 82 reg = <1>;
83 phy-mode = "gmii";
72 phy-handle = <&phy0>; 84 phy-handle = <&phy0>;
73 }; 85 };
74 86
@@ -78,7 +90,6 @@
78 90
79 phy0: ethernet-phy@0 { 91 phy0: ethernet-phy@0 {
80 reg = <0>; 92 reg = <0>;
81 phy-mode = "gmii";
82 }; 93 };
83 }; 94 };
84}; 95};
diff --git a/arch/arm/boot/dts/mt7629.dtsi b/arch/arm/boot/dts/mt7629.dtsi
index 9608bc2ccb3f..867b88103b9d 100644
--- a/arch/arm/boot/dts/mt7629.dtsi
+++ b/arch/arm/boot/dts/mt7629.dtsi
@@ -468,14 +468,12 @@
468 compatible = "mediatek,mt7629-sgmiisys", "syscon"; 468 compatible = "mediatek,mt7629-sgmiisys", "syscon";
469 reg = <0x1b128000 0x3000>; 469 reg = <0x1b128000 0x3000>;
470 #clock-cells = <1>; 470 #clock-cells = <1>;
471 mediatek,physpeed = "2500";
472 }; 471 };
473 472
474 sgmiisys1: syscon@1b130000 { 473 sgmiisys1: syscon@1b130000 {
475 compatible = "mediatek,mt7629-sgmiisys", "syscon"; 474 compatible = "mediatek,mt7629-sgmiisys", "syscon";
476 reg = <0x1b130000 0x3000>; 475 reg = <0x1b130000 0x3000>;
477 #clock-cells = <1>; 476 #clock-cells = <1>;
478 mediatek,physpeed = "2500";
479 }; 477 };
480 }; 478 };
481}; 479};
diff --git a/arch/arm/boot/dts/omap3-gta04.dtsi b/arch/arm/boot/dts/omap3-gta04.dtsi
index d01fc8744fd7..b6ef1a7ac8a4 100644
--- a/arch/arm/boot/dts/omap3-gta04.dtsi
+++ b/arch/arm/boot/dts/omap3-gta04.dtsi
@@ -124,6 +124,7 @@
124 spi-max-frequency = <100000>; 124 spi-max-frequency = <100000>;
125 spi-cpol; 125 spi-cpol;
126 spi-cpha; 126 spi-cpha;
127 spi-cs-high;
127 128
128 backlight= <&backlight>; 129 backlight= <&backlight>;
129 label = "lcd"; 130 label = "lcd";
diff --git a/arch/arm/boot/dts/ste-dbx5x0.dtsi b/arch/arm/boot/dts/ste-dbx5x0.dtsi
index a53657b83288..bda454d12150 100644
--- a/arch/arm/boot/dts/ste-dbx5x0.dtsi
+++ b/arch/arm/boot/dts/ste-dbx5x0.dtsi
@@ -8,6 +8,7 @@
8#include <dt-bindings/mfd/dbx500-prcmu.h> 8#include <dt-bindings/mfd/dbx500-prcmu.h>
9#include <dt-bindings/arm/ux500_pm_domains.h> 9#include <dt-bindings/arm/ux500_pm_domains.h>
10#include <dt-bindings/gpio/gpio.h> 10#include <dt-bindings/gpio/gpio.h>
11#include <dt-bindings/thermal/thermal.h>
11 12
12/ { 13/ {
13 #address-cells = <1>; 14 #address-cells = <1>;
@@ -59,8 +60,12 @@
59 * cooling. 60 * cooling.
60 */ 61 */
61 cpu_thermal: cpu-thermal { 62 cpu_thermal: cpu-thermal {
62 polling-delay-passive = <0>; 63 polling-delay-passive = <250>;
63 polling-delay = <1000>; 64 /*
65 * This sensor fires interrupts to update the thermal
66 * zone, so no polling is needed.
67 */
68 polling-delay = <0>;
64 69
65 thermal-sensors = <&thermal>; 70 thermal-sensors = <&thermal>;
66 71
@@ -79,7 +84,7 @@
79 84
80 cooling-maps { 85 cooling-maps {
81 trip = <&cpu_alert>; 86 trip = <&cpu_alert>;
82 cooling-device = <&CPU0 0 2>; 87 cooling-device = <&CPU0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
83 contribution = <100>; 88 contribution = <100>;
84 }; 89 };
85 }; 90 };
diff --git a/arch/arm/boot/dts/sun4i-a10.dtsi b/arch/arm/boot/dts/sun4i-a10.dtsi
index ce823c44e98a..4c268b70b735 100644
--- a/arch/arm/boot/dts/sun4i-a10.dtsi
+++ b/arch/arm/boot/dts/sun4i-a10.dtsi
@@ -520,6 +520,7 @@
520 interrupts = <39>; 520 interrupts = <39>;
521 clocks = <&ccu CLK_AHB_EHCI0>; 521 clocks = <&ccu CLK_AHB_EHCI0>;
522 phys = <&usbphy 1>; 522 phys = <&usbphy 1>;
523 phy-names = "usb";
523 status = "disabled"; 524 status = "disabled";
524 }; 525 };
525 526
@@ -529,6 +530,7 @@
529 interrupts = <64>; 530 interrupts = <64>;
530 clocks = <&ccu CLK_USB_OHCI0>, <&ccu CLK_AHB_OHCI0>; 531 clocks = <&ccu CLK_USB_OHCI0>, <&ccu CLK_AHB_OHCI0>;
531 phys = <&usbphy 1>; 532 phys = <&usbphy 1>;
533 phy-names = "usb";
532 status = "disabled"; 534 status = "disabled";
533 }; 535 };
534 536
@@ -608,6 +610,7 @@
608 interrupts = <40>; 610 interrupts = <40>;
609 clocks = <&ccu CLK_AHB_EHCI1>; 611 clocks = <&ccu CLK_AHB_EHCI1>;
610 phys = <&usbphy 2>; 612 phys = <&usbphy 2>;
613 phy-names = "usb";
611 status = "disabled"; 614 status = "disabled";
612 }; 615 };
613 616
@@ -617,6 +620,7 @@
617 interrupts = <65>; 620 interrupts = <65>;
618 clocks = <&ccu CLK_USB_OHCI1>, <&ccu CLK_AHB_OHCI1>; 621 clocks = <&ccu CLK_USB_OHCI1>, <&ccu CLK_AHB_OHCI1>;
619 phys = <&usbphy 2>; 622 phys = <&usbphy 2>;
623 phy-names = "usb";
620 status = "disabled"; 624 status = "disabled";
621 }; 625 };
622 626
diff --git a/arch/arm/boot/dts/sun5i.dtsi b/arch/arm/boot/dts/sun5i.dtsi
index cfb1efc8828c..6befa236ba99 100644
--- a/arch/arm/boot/dts/sun5i.dtsi
+++ b/arch/arm/boot/dts/sun5i.dtsi
@@ -391,6 +391,7 @@
391 interrupts = <39>; 391 interrupts = <39>;
392 clocks = <&ccu CLK_AHB_EHCI>; 392 clocks = <&ccu CLK_AHB_EHCI>;
393 phys = <&usbphy 1>; 393 phys = <&usbphy 1>;
394 phy-names = "usb";
394 status = "disabled"; 395 status = "disabled";
395 }; 396 };
396 397
@@ -400,6 +401,7 @@
400 interrupts = <40>; 401 interrupts = <40>;
401 clocks = <&ccu CLK_USB_OHCI>, <&ccu CLK_AHB_OHCI>; 402 clocks = <&ccu CLK_USB_OHCI>, <&ccu CLK_AHB_OHCI>;
402 phys = <&usbphy 1>; 403 phys = <&usbphy 1>;
404 phy-names = "usb";
403 status = "disabled"; 405 status = "disabled";
404 }; 406 };
405 407
diff --git a/arch/arm/boot/dts/sun6i-a31.dtsi b/arch/arm/boot/dts/sun6i-a31.dtsi
index bbeb743633c6..ac7638078420 100644
--- a/arch/arm/boot/dts/sun6i-a31.dtsi
+++ b/arch/arm/boot/dts/sun6i-a31.dtsi
@@ -545,6 +545,7 @@
545 clocks = <&ccu CLK_AHB1_EHCI0>; 545 clocks = <&ccu CLK_AHB1_EHCI0>;
546 resets = <&ccu RST_AHB1_EHCI0>; 546 resets = <&ccu RST_AHB1_EHCI0>;
547 phys = <&usbphy 1>; 547 phys = <&usbphy 1>;
548 phy-names = "usb";
548 status = "disabled"; 549 status = "disabled";
549 }; 550 };
550 551
@@ -555,6 +556,7 @@
555 clocks = <&ccu CLK_AHB1_OHCI0>, <&ccu CLK_USB_OHCI0>; 556 clocks = <&ccu CLK_AHB1_OHCI0>, <&ccu CLK_USB_OHCI0>;
556 resets = <&ccu RST_AHB1_OHCI0>; 557 resets = <&ccu RST_AHB1_OHCI0>;
557 phys = <&usbphy 1>; 558 phys = <&usbphy 1>;
559 phy-names = "usb";
558 status = "disabled"; 560 status = "disabled";
559 }; 561 };
560 562
@@ -565,6 +567,7 @@
565 clocks = <&ccu CLK_AHB1_EHCI1>; 567 clocks = <&ccu CLK_AHB1_EHCI1>;
566 resets = <&ccu RST_AHB1_EHCI1>; 568 resets = <&ccu RST_AHB1_EHCI1>;
567 phys = <&usbphy 2>; 569 phys = <&usbphy 2>;
570 phy-names = "usb";
568 status = "disabled"; 571 status = "disabled";
569 }; 572 };
570 573
@@ -575,6 +578,7 @@
575 clocks = <&ccu CLK_AHB1_OHCI1>, <&ccu CLK_USB_OHCI1>; 578 clocks = <&ccu CLK_AHB1_OHCI1>, <&ccu CLK_USB_OHCI1>;
576 resets = <&ccu RST_AHB1_OHCI1>; 579 resets = <&ccu RST_AHB1_OHCI1>;
577 phys = <&usbphy 2>; 580 phys = <&usbphy 2>;
581 phy-names = "usb";
578 status = "disabled"; 582 status = "disabled";
579 }; 583 };
580 584
diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 49380de754a9..874231be04e4 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -623,6 +623,7 @@
623 interrupts = <GIC_SPI 39 IRQ_TYPE_LEVEL_HIGH>; 623 interrupts = <GIC_SPI 39 IRQ_TYPE_LEVEL_HIGH>;
624 clocks = <&ccu CLK_AHB_EHCI0>; 624 clocks = <&ccu CLK_AHB_EHCI0>;
625 phys = <&usbphy 1>; 625 phys = <&usbphy 1>;
626 phy-names = "usb";
626 status = "disabled"; 627 status = "disabled";
627 }; 628 };
628 629
@@ -632,6 +633,7 @@
632 interrupts = <GIC_SPI 64 IRQ_TYPE_LEVEL_HIGH>; 633 interrupts = <GIC_SPI 64 IRQ_TYPE_LEVEL_HIGH>;
633 clocks = <&ccu CLK_USB_OHCI0>, <&ccu CLK_AHB_OHCI0>; 634 clocks = <&ccu CLK_USB_OHCI0>, <&ccu CLK_AHB_OHCI0>;
634 phys = <&usbphy 1>; 635 phys = <&usbphy 1>;
636 phy-names = "usb";
635 status = "disabled"; 637 status = "disabled";
636 }; 638 };
637 639
@@ -714,6 +716,7 @@
714 interrupts = <GIC_SPI 40 IRQ_TYPE_LEVEL_HIGH>; 716 interrupts = <GIC_SPI 40 IRQ_TYPE_LEVEL_HIGH>;
715 clocks = <&ccu CLK_AHB_EHCI1>; 717 clocks = <&ccu CLK_AHB_EHCI1>;
716 phys = <&usbphy 2>; 718 phys = <&usbphy 2>;
719 phy-names = "usb";
717 status = "disabled"; 720 status = "disabled";
718 }; 721 };
719 722
@@ -723,6 +726,7 @@
723 interrupts = <GIC_SPI 65 IRQ_TYPE_LEVEL_HIGH>; 726 interrupts = <GIC_SPI 65 IRQ_TYPE_LEVEL_HIGH>;
724 clocks = <&ccu CLK_USB_OHCI1>, <&ccu CLK_AHB_OHCI1>; 727 clocks = <&ccu CLK_USB_OHCI1>, <&ccu CLK_AHB_OHCI1>;
725 phys = <&usbphy 2>; 728 phys = <&usbphy 2>;
729 phy-names = "usb";
726 status = "disabled"; 730 status = "disabled";
727 }; 731 };
728 732
diff --git a/arch/arm/boot/dts/sun8i-a23-a33.dtsi b/arch/arm/boot/dts/sun8i-a23-a33.dtsi
index 52eed0ae3607..f292f96ab39b 100644
--- a/arch/arm/boot/dts/sun8i-a23-a33.dtsi
+++ b/arch/arm/boot/dts/sun8i-a23-a33.dtsi
@@ -307,6 +307,7 @@
307 clocks = <&ccu CLK_BUS_EHCI>; 307 clocks = <&ccu CLK_BUS_EHCI>;
308 resets = <&ccu RST_BUS_EHCI>; 308 resets = <&ccu RST_BUS_EHCI>;
309 phys = <&usbphy 1>; 309 phys = <&usbphy 1>;
310 phy-names = "usb";
310 status = "disabled"; 311 status = "disabled";
311 }; 312 };
312 313
@@ -317,6 +318,7 @@
317 clocks = <&ccu CLK_BUS_OHCI>, <&ccu CLK_USB_OHCI>; 318 clocks = <&ccu CLK_BUS_OHCI>, <&ccu CLK_USB_OHCI>;
318 resets = <&ccu RST_BUS_OHCI>; 319 resets = <&ccu RST_BUS_OHCI>;
319 phys = <&usbphy 1>; 320 phys = <&usbphy 1>;
321 phy-names = "usb";
320 status = "disabled"; 322 status = "disabled";
321 }; 323 };
322 324
diff --git a/arch/arm/boot/dts/sun8i-a83t.dtsi b/arch/arm/boot/dts/sun8i-a83t.dtsi
index 523be6611c50..74bb053cf23c 100644
--- a/arch/arm/boot/dts/sun8i-a83t.dtsi
+++ b/arch/arm/boot/dts/sun8i-a83t.dtsi
@@ -632,6 +632,7 @@
632 clocks = <&ccu CLK_BUS_EHCI0>; 632 clocks = <&ccu CLK_BUS_EHCI0>;
633 resets = <&ccu RST_BUS_EHCI0>; 633 resets = <&ccu RST_BUS_EHCI0>;
634 phys = <&usbphy 1>; 634 phys = <&usbphy 1>;
635 phy-names = "usb";
635 status = "disabled"; 636 status = "disabled";
636 }; 637 };
637 638
@@ -643,6 +644,7 @@
643 clocks = <&ccu CLK_BUS_OHCI0>, <&ccu CLK_USB_OHCI0>; 644 clocks = <&ccu CLK_BUS_OHCI0>, <&ccu CLK_USB_OHCI0>;
644 resets = <&ccu RST_BUS_OHCI0>; 645 resets = <&ccu RST_BUS_OHCI0>;
645 phys = <&usbphy 1>; 646 phys = <&usbphy 1>;
647 phy-names = "usb";
646 status = "disabled"; 648 status = "disabled";
647 }; 649 };
648 650
@@ -654,6 +656,7 @@
654 clocks = <&ccu CLK_BUS_EHCI1>; 656 clocks = <&ccu CLK_BUS_EHCI1>;
655 resets = <&ccu RST_BUS_EHCI1>; 657 resets = <&ccu RST_BUS_EHCI1>;
656 phys = <&usbphy 2>; 658 phys = <&usbphy 2>;
659 phy-names = "usb";
657 status = "disabled"; 660 status = "disabled";
658 }; 661 };
659 662
diff --git a/arch/arm/boot/dts/sun8i-r40.dtsi b/arch/arm/boot/dts/sun8i-r40.dtsi
index bde068111b85..c9c2688db66d 100644
--- a/arch/arm/boot/dts/sun8i-r40.dtsi
+++ b/arch/arm/boot/dts/sun8i-r40.dtsi
@@ -273,6 +273,7 @@
273 clocks = <&ccu CLK_BUS_EHCI1>; 273 clocks = <&ccu CLK_BUS_EHCI1>;
274 resets = <&ccu RST_BUS_EHCI1>; 274 resets = <&ccu RST_BUS_EHCI1>;
275 phys = <&usbphy 1>; 275 phys = <&usbphy 1>;
276 phy-names = "usb";
276 status = "disabled"; 277 status = "disabled";
277 }; 278 };
278 279
@@ -284,6 +285,7 @@
284 <&ccu CLK_USB_OHCI1>; 285 <&ccu CLK_USB_OHCI1>;
285 resets = <&ccu RST_BUS_OHCI1>; 286 resets = <&ccu RST_BUS_OHCI1>;
286 phys = <&usbphy 1>; 287 phys = <&usbphy 1>;
288 phy-names = "usb";
287 status = "disabled"; 289 status = "disabled";
288 }; 290 };
289 291
@@ -294,6 +296,7 @@
294 clocks = <&ccu CLK_BUS_EHCI2>; 296 clocks = <&ccu CLK_BUS_EHCI2>;
295 resets = <&ccu RST_BUS_EHCI2>; 297 resets = <&ccu RST_BUS_EHCI2>;
296 phys = <&usbphy 2>; 298 phys = <&usbphy 2>;
299 phy-names = "usb";
297 status = "disabled"; 300 status = "disabled";
298 }; 301 };
299 302
@@ -305,6 +308,7 @@
305 <&ccu CLK_USB_OHCI2>; 308 <&ccu CLK_USB_OHCI2>;
306 resets = <&ccu RST_BUS_OHCI2>; 309 resets = <&ccu RST_BUS_OHCI2>;
307 phys = <&usbphy 2>; 310 phys = <&usbphy 2>;
311 phy-names = "usb";
308 status = "disabled"; 312 status = "disabled";
309 }; 313 };
310 314
diff --git a/arch/arm/boot/dts/sun9i-a80.dtsi b/arch/arm/boot/dts/sun9i-a80.dtsi
index c34d505c7efe..b9b6fb00be28 100644
--- a/arch/arm/boot/dts/sun9i-a80.dtsi
+++ b/arch/arm/boot/dts/sun9i-a80.dtsi
@@ -346,6 +346,7 @@
346 clocks = <&usb_clocks CLK_BUS_HCI0>; 346 clocks = <&usb_clocks CLK_BUS_HCI0>;
347 resets = <&usb_clocks RST_USB0_HCI>; 347 resets = <&usb_clocks RST_USB0_HCI>;
348 phys = <&usbphy1>; 348 phys = <&usbphy1>;
349 phy-names = "usb";
349 status = "disabled"; 350 status = "disabled";
350 }; 351 };
351 352
@@ -357,6 +358,7 @@
357 <&usb_clocks CLK_USB_OHCI0>; 358 <&usb_clocks CLK_USB_OHCI0>;
358 resets = <&usb_clocks RST_USB0_HCI>; 359 resets = <&usb_clocks RST_USB0_HCI>;
359 phys = <&usbphy1>; 360 phys = <&usbphy1>;
361 phy-names = "usb";
360 status = "disabled"; 362 status = "disabled";
361 }; 363 };
362 364
@@ -378,6 +380,7 @@
378 clocks = <&usb_clocks CLK_BUS_HCI1>; 380 clocks = <&usb_clocks CLK_BUS_HCI1>;
379 resets = <&usb_clocks RST_USB1_HCI>; 381 resets = <&usb_clocks RST_USB1_HCI>;
380 phys = <&usbphy2>; 382 phys = <&usbphy2>;
383 phy-names = "usb";
381 status = "disabled"; 384 status = "disabled";
382 }; 385 };
383 386
@@ -407,6 +410,7 @@
407 clocks = <&usb_clocks CLK_BUS_HCI2>; 410 clocks = <&usb_clocks CLK_BUS_HCI2>;
408 resets = <&usb_clocks RST_USB2_HCI>; 411 resets = <&usb_clocks RST_USB2_HCI>;
409 phys = <&usbphy3>; 412 phys = <&usbphy3>;
413 phy-names = "usb";
410 status = "disabled"; 414 status = "disabled";
411 }; 415 };
412 416
@@ -418,6 +422,7 @@
418 <&usb_clocks CLK_USB_OHCI2>; 422 <&usb_clocks CLK_USB_OHCI2>;
419 resets = <&usb_clocks RST_USB2_HCI>; 423 resets = <&usb_clocks RST_USB2_HCI>;
420 phys = <&usbphy3>; 424 phys = <&usbphy3>;
425 phy-names = "usb";
421 status = "disabled"; 426 status = "disabled";
422 }; 427 };
423 428
diff --git a/arch/arm/boot/dts/sunxi-h3-h5.dtsi b/arch/arm/boot/dts/sunxi-h3-h5.dtsi
index eba190b3f9de..107eeafad20a 100644
--- a/arch/arm/boot/dts/sunxi-h3-h5.dtsi
+++ b/arch/arm/boot/dts/sunxi-h3-h5.dtsi
@@ -304,6 +304,7 @@
304 clocks = <&ccu CLK_BUS_EHCI1>, <&ccu CLK_BUS_OHCI1>; 304 clocks = <&ccu CLK_BUS_EHCI1>, <&ccu CLK_BUS_OHCI1>;
305 resets = <&ccu RST_BUS_EHCI1>, <&ccu RST_BUS_OHCI1>; 305 resets = <&ccu RST_BUS_EHCI1>, <&ccu RST_BUS_OHCI1>;
306 phys = <&usbphy 1>; 306 phys = <&usbphy 1>;
307 phy-names = "usb";
307 status = "disabled"; 308 status = "disabled";
308 }; 309 };
309 310
@@ -315,6 +316,7 @@
315 <&ccu CLK_USB_OHCI1>; 316 <&ccu CLK_USB_OHCI1>;
316 resets = <&ccu RST_BUS_EHCI1>, <&ccu RST_BUS_OHCI1>; 317 resets = <&ccu RST_BUS_EHCI1>, <&ccu RST_BUS_OHCI1>;
317 phys = <&usbphy 1>; 318 phys = <&usbphy 1>;
319 phy-names = "usb";
318 status = "disabled"; 320 status = "disabled";
319 }; 321 };
320 322
@@ -325,6 +327,7 @@
325 clocks = <&ccu CLK_BUS_EHCI2>, <&ccu CLK_BUS_OHCI2>; 327 clocks = <&ccu CLK_BUS_EHCI2>, <&ccu CLK_BUS_OHCI2>;
326 resets = <&ccu RST_BUS_EHCI2>, <&ccu RST_BUS_OHCI2>; 328 resets = <&ccu RST_BUS_EHCI2>, <&ccu RST_BUS_OHCI2>;
327 phys = <&usbphy 2>; 329 phys = <&usbphy 2>;
330 phy-names = "usb";
328 status = "disabled"; 331 status = "disabled";
329 }; 332 };
330 333
@@ -336,6 +339,7 @@
336 <&ccu CLK_USB_OHCI2>; 339 <&ccu CLK_USB_OHCI2>;
337 resets = <&ccu RST_BUS_EHCI2>, <&ccu RST_BUS_OHCI2>; 340 resets = <&ccu RST_BUS_EHCI2>, <&ccu RST_BUS_OHCI2>;
338 phys = <&usbphy 2>; 341 phys = <&usbphy 2>;
342 phy-names = "usb";
339 status = "disabled"; 343 status = "disabled";
340 }; 344 };
341 345
@@ -346,6 +350,7 @@
346 clocks = <&ccu CLK_BUS_EHCI3>, <&ccu CLK_BUS_OHCI3>; 350 clocks = <&ccu CLK_BUS_EHCI3>, <&ccu CLK_BUS_OHCI3>;
347 resets = <&ccu RST_BUS_EHCI3>, <&ccu RST_BUS_OHCI3>; 351 resets = <&ccu RST_BUS_EHCI3>, <&ccu RST_BUS_OHCI3>;
348 phys = <&usbphy 3>; 352 phys = <&usbphy 3>;
353 phy-names = "usb";
349 status = "disabled"; 354 status = "disabled";
350 }; 355 };
351 356
@@ -357,6 +362,7 @@
357 <&ccu CLK_USB_OHCI3>; 362 <&ccu CLK_USB_OHCI3>;
358 resets = <&ccu RST_BUS_EHCI3>, <&ccu RST_BUS_OHCI3>; 363 resets = <&ccu RST_BUS_EHCI3>, <&ccu RST_BUS_OHCI3>;
359 phys = <&usbphy 3>; 364 phys = <&usbphy 3>;
365 phy-names = "usb";
360 status = "disabled"; 366 status = "disabled";
361 }; 367 };
362 368
diff --git a/arch/arm/configs/badge4_defconfig b/arch/arm/configs/badge4_defconfig
index 5ae5b5228467..ef484c4cfd1a 100644
--- a/arch/arm/configs/badge4_defconfig
+++ b/arch/arm/configs/badge4_defconfig
@@ -91,7 +91,6 @@ CONFIG_USB_SERIAL_PL2303=m
91CONFIG_USB_SERIAL_CYBERJACK=m 91CONFIG_USB_SERIAL_CYBERJACK=m
92CONFIG_USB_SERIAL_XIRCOM=m 92CONFIG_USB_SERIAL_XIRCOM=m
93CONFIG_USB_SERIAL_OMNINET=m 93CONFIG_USB_SERIAL_OMNINET=m
94CONFIG_USB_RIO500=m
95CONFIG_EXT2_FS=m 94CONFIG_EXT2_FS=m
96CONFIG_EXT3_FS=m 95CONFIG_EXT3_FS=m
97CONFIG_MSDOS_FS=y 96CONFIG_MSDOS_FS=y
diff --git a/arch/arm/configs/corgi_defconfig b/arch/arm/configs/corgi_defconfig
index e4f6442588e7..4fec2ec379ad 100644
--- a/arch/arm/configs/corgi_defconfig
+++ b/arch/arm/configs/corgi_defconfig
@@ -195,7 +195,6 @@ CONFIG_USB_SERIAL_XIRCOM=m
195CONFIG_USB_SERIAL_OMNINET=m 195CONFIG_USB_SERIAL_OMNINET=m
196CONFIG_USB_EMI62=m 196CONFIG_USB_EMI62=m
197CONFIG_USB_EMI26=m 197CONFIG_USB_EMI26=m
198CONFIG_USB_RIO500=m
199CONFIG_USB_LEGOTOWER=m 198CONFIG_USB_LEGOTOWER=m
200CONFIG_USB_LCD=m 199CONFIG_USB_LCD=m
201CONFIG_USB_CYTHERM=m 200CONFIG_USB_CYTHERM=m
diff --git a/arch/arm/configs/davinci_all_defconfig b/arch/arm/configs/davinci_all_defconfig
index b34970ce6b31..01e3c0f4be92 100644
--- a/arch/arm/configs/davinci_all_defconfig
+++ b/arch/arm/configs/davinci_all_defconfig
@@ -228,7 +228,7 @@ CONFIG_RTC_DRV_OMAP=m
228CONFIG_DMADEVICES=y 228CONFIG_DMADEVICES=y
229CONFIG_TI_EDMA=y 229CONFIG_TI_EDMA=y
230CONFIG_COMMON_CLK_PWM=m 230CONFIG_COMMON_CLK_PWM=m
231CONFIG_REMOTEPROC=m 231CONFIG_REMOTEPROC=y
232CONFIG_DA8XX_REMOTEPROC=m 232CONFIG_DA8XX_REMOTEPROC=m
233CONFIG_MEMORY=y 233CONFIG_MEMORY=y
234CONFIG_TI_AEMIF=m 234CONFIG_TI_AEMIF=m
diff --git a/arch/arm/configs/multi_v7_defconfig b/arch/arm/configs/multi_v7_defconfig
index 13ba53286901..e4c8def9a0a5 100644
--- a/arch/arm/configs/multi_v7_defconfig
+++ b/arch/arm/configs/multi_v7_defconfig
@@ -415,7 +415,7 @@ CONFIG_SPI_SH_MSIOF=m
415CONFIG_SPI_SH_HSPI=y 415CONFIG_SPI_SH_HSPI=y
416CONFIG_SPI_SIRF=y 416CONFIG_SPI_SIRF=y
417CONFIG_SPI_STM32=m 417CONFIG_SPI_STM32=m
418CONFIG_SPI_STM32_QSPI=m 418CONFIG_SPI_STM32_QSPI=y
419CONFIG_SPI_SUN4I=y 419CONFIG_SPI_SUN4I=y
420CONFIG_SPI_SUN6I=y 420CONFIG_SPI_SUN6I=y
421CONFIG_SPI_TEGRA114=y 421CONFIG_SPI_TEGRA114=y
@@ -933,7 +933,7 @@ CONFIG_BCM2835_MBOX=y
933CONFIG_ROCKCHIP_IOMMU=y 933CONFIG_ROCKCHIP_IOMMU=y
934CONFIG_TEGRA_IOMMU_GART=y 934CONFIG_TEGRA_IOMMU_GART=y
935CONFIG_TEGRA_IOMMU_SMMU=y 935CONFIG_TEGRA_IOMMU_SMMU=y
936CONFIG_REMOTEPROC=m 936CONFIG_REMOTEPROC=y
937CONFIG_ST_REMOTEPROC=m 937CONFIG_ST_REMOTEPROC=m
938CONFIG_RPMSG_VIRTIO=m 938CONFIG_RPMSG_VIRTIO=m
939CONFIG_ASPEED_LPC_CTRL=m 939CONFIG_ASPEED_LPC_CTRL=m
diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
index 64eb896907bf..d3f50971e451 100644
--- a/arch/arm/configs/omap2plus_defconfig
+++ b/arch/arm/configs/omap2plus_defconfig
@@ -364,6 +364,7 @@ CONFIG_DRM_OMAP_PANEL_TPO_TD043MTEA1=m
364CONFIG_DRM_OMAP_PANEL_NEC_NL8048HL11=m 364CONFIG_DRM_OMAP_PANEL_NEC_NL8048HL11=m
365CONFIG_DRM_TILCDC=m 365CONFIG_DRM_TILCDC=m
366CONFIG_DRM_PANEL_SIMPLE=m 366CONFIG_DRM_PANEL_SIMPLE=m
367CONFIG_DRM_TI_TFP410=m
367CONFIG_FB=y 368CONFIG_FB=y
368CONFIG_FIRMWARE_EDID=y 369CONFIG_FIRMWARE_EDID=y
369CONFIG_FB_MODE_HELPERS=y 370CONFIG_FB_MODE_HELPERS=y
@@ -423,6 +424,7 @@ CONFIG_USB_SERIAL_GENERIC=y
423CONFIG_USB_SERIAL_SIMPLE=m 424CONFIG_USB_SERIAL_SIMPLE=m
424CONFIG_USB_SERIAL_FTDI_SIO=m 425CONFIG_USB_SERIAL_FTDI_SIO=m
425CONFIG_USB_SERIAL_PL2303=m 426CONFIG_USB_SERIAL_PL2303=m
427CONFIG_USB_SERIAL_OPTION=m
426CONFIG_USB_TEST=m 428CONFIG_USB_TEST=m
427CONFIG_NOP_USB_XCEIV=m 429CONFIG_NOP_USB_XCEIV=m
428CONFIG_AM335X_PHY_USB=m 430CONFIG_AM335X_PHY_USB=m
@@ -460,6 +462,7 @@ CONFIG_MMC_SDHCI_OMAP=y
460CONFIG_NEW_LEDS=y 462CONFIG_NEW_LEDS=y
461CONFIG_LEDS_CLASS=m 463CONFIG_LEDS_CLASS=m
462CONFIG_LEDS_CPCAP=m 464CONFIG_LEDS_CPCAP=m
465CONFIG_LEDS_LM3532=m
463CONFIG_LEDS_GPIO=m 466CONFIG_LEDS_GPIO=m
464CONFIG_LEDS_PCA963X=m 467CONFIG_LEDS_PCA963X=m
465CONFIG_LEDS_PWM=m 468CONFIG_LEDS_PWM=m
@@ -481,7 +484,7 @@ CONFIG_RTC_DRV_OMAP=m
481CONFIG_RTC_DRV_CPCAP=m 484CONFIG_RTC_DRV_CPCAP=m
482CONFIG_DMADEVICES=y 485CONFIG_DMADEVICES=y
483CONFIG_OMAP_IOMMU=y 486CONFIG_OMAP_IOMMU=y
484CONFIG_REMOTEPROC=m 487CONFIG_REMOTEPROC=y
485CONFIG_OMAP_REMOTEPROC=m 488CONFIG_OMAP_REMOTEPROC=m
486CONFIG_WKUP_M3_RPROC=m 489CONFIG_WKUP_M3_RPROC=m
487CONFIG_SOC_TI=y 490CONFIG_SOC_TI=y
diff --git a/arch/arm/configs/pxa_defconfig b/arch/arm/configs/pxa_defconfig
index 787c3f9be414..b817c57f05f1 100644
--- a/arch/arm/configs/pxa_defconfig
+++ b/arch/arm/configs/pxa_defconfig
@@ -581,7 +581,6 @@ CONFIG_USB_SERIAL_XIRCOM=m
581CONFIG_USB_SERIAL_OMNINET=m 581CONFIG_USB_SERIAL_OMNINET=m
582CONFIG_USB_EMI62=m 582CONFIG_USB_EMI62=m
583CONFIG_USB_EMI26=m 583CONFIG_USB_EMI26=m
584CONFIG_USB_RIO500=m
585CONFIG_USB_LEGOTOWER=m 584CONFIG_USB_LEGOTOWER=m
586CONFIG_USB_LCD=m 585CONFIG_USB_LCD=m
587CONFIG_USB_CYTHERM=m 586CONFIG_USB_CYTHERM=m
diff --git a/arch/arm/configs/s3c2410_defconfig b/arch/arm/configs/s3c2410_defconfig
index 95b5a4ffddea..73ed73a8785a 100644
--- a/arch/arm/configs/s3c2410_defconfig
+++ b/arch/arm/configs/s3c2410_defconfig
@@ -327,7 +327,6 @@ CONFIG_USB_EMI62=m
327CONFIG_USB_EMI26=m 327CONFIG_USB_EMI26=m
328CONFIG_USB_ADUTUX=m 328CONFIG_USB_ADUTUX=m
329CONFIG_USB_SEVSEG=m 329CONFIG_USB_SEVSEG=m
330CONFIG_USB_RIO500=m
331CONFIG_USB_LEGOTOWER=m 330CONFIG_USB_LEGOTOWER=m
332CONFIG_USB_LCD=m 331CONFIG_USB_LCD=m
333CONFIG_USB_CYPRESS_CY7C63=m 332CONFIG_USB_CYPRESS_CY7C63=m
diff --git a/arch/arm/configs/spitz_defconfig b/arch/arm/configs/spitz_defconfig
index 4fb51d665abb..a1cdbfa064c5 100644
--- a/arch/arm/configs/spitz_defconfig
+++ b/arch/arm/configs/spitz_defconfig
@@ -189,7 +189,6 @@ CONFIG_USB_SERIAL_XIRCOM=m
189CONFIG_USB_SERIAL_OMNINET=m 189CONFIG_USB_SERIAL_OMNINET=m
190CONFIG_USB_EMI62=m 190CONFIG_USB_EMI62=m
191CONFIG_USB_EMI26=m 191CONFIG_USB_EMI26=m
192CONFIG_USB_RIO500=m
193CONFIG_USB_LEGOTOWER=m 192CONFIG_USB_LEGOTOWER=m
194CONFIG_USB_LCD=m 193CONFIG_USB_LCD=m
195CONFIG_USB_CYTHERM=m 194CONFIG_USB_CYTHERM=m
diff --git a/arch/arm/crypto/Kconfig b/arch/arm/crypto/Kconfig
index b24df84a1d7a..043b0b18bf7e 100644
--- a/arch/arm/crypto/Kconfig
+++ b/arch/arm/crypto/Kconfig
@@ -98,6 +98,7 @@ config CRYPTO_AES_ARM_CE
98 tristate "Accelerated AES using ARMv8 Crypto Extensions" 98 tristate "Accelerated AES using ARMv8 Crypto Extensions"
99 depends on KERNEL_MODE_NEON 99 depends on KERNEL_MODE_NEON
100 select CRYPTO_BLKCIPHER 100 select CRYPTO_BLKCIPHER
101 select CRYPTO_LIB_AES
101 select CRYPTO_SIMD 102 select CRYPTO_SIMD
102 help 103 help
103 Use an implementation of AES in CBC, CTR and XTS modes that uses 104 Use an implementation of AES in CBC, CTR and XTS modes that uses
diff --git a/arch/arm/crypto/aes-ce-core.S b/arch/arm/crypto/aes-ce-core.S
index b978cdf133af..4d1707388d94 100644
--- a/arch/arm/crypto/aes-ce-core.S
+++ b/arch/arm/crypto/aes-ce-core.S
@@ -9,6 +9,7 @@
9#include <asm/assembler.h> 9#include <asm/assembler.h>
10 10
11 .text 11 .text
12 .arch armv8-a
12 .fpu crypto-neon-fp-armv8 13 .fpu crypto-neon-fp-armv8
13 .align 3 14 .align 3
14 15
diff --git a/arch/arm/include/asm/xen/xen-ops.h b/arch/arm/include/asm/xen/xen-ops.h
deleted file mode 100644
index ec154e719b11..000000000000
--- a/arch/arm/include/asm/xen/xen-ops.h
+++ /dev/null
@@ -1,6 +0,0 @@
1#ifndef _ASM_XEN_OPS_H
2#define _ASM_XEN_OPS_H
3
4void xen_efi_runtime_setup(void);
5
6#endif /* _ASM_XEN_OPS_H */
diff --git a/arch/arm/mach-omap2/omap_hwmod_33xx_43xx_ipblock_data.c b/arch/arm/mach-omap2/omap_hwmod_33xx_43xx_ipblock_data.c
index dd939e1325c6..29fd13684a68 100644
--- a/arch/arm/mach-omap2/omap_hwmod_33xx_43xx_ipblock_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_33xx_43xx_ipblock_data.c
@@ -763,7 +763,8 @@ static struct omap_hwmod_class_sysconfig am33xx_timer_sysc = {
763 .rev_offs = 0x0000, 763 .rev_offs = 0x0000,
764 .sysc_offs = 0x0010, 764 .sysc_offs = 0x0010,
765 .syss_offs = 0x0014, 765 .syss_offs = 0x0014,
766 .sysc_flags = (SYSC_HAS_SIDLEMODE | SYSC_HAS_SOFTRESET), 766 .sysc_flags = SYSC_HAS_SIDLEMODE | SYSC_HAS_SOFTRESET |
767 SYSC_HAS_RESET_STATUS,
767 .idlemodes = (SIDLE_FORCE | SIDLE_NO | SIDLE_SMART | 768 .idlemodes = (SIDLE_FORCE | SIDLE_NO | SIDLE_SMART |
768 SIDLE_SMART_WKUP), 769 SIDLE_SMART_WKUP),
769 .sysc_fields = &omap_hwmod_sysc_type2, 770 .sysc_fields = &omap_hwmod_sysc_type2,
diff --git a/arch/arm/mach-omap2/omap_hwmod_33xx_data.c b/arch/arm/mach-omap2/omap_hwmod_33xx_data.c
index 2bcb6345b873..54524775f278 100644
--- a/arch/arm/mach-omap2/omap_hwmod_33xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_33xx_data.c
@@ -231,8 +231,9 @@ static struct omap_hwmod am33xx_control_hwmod = {
231static struct omap_hwmod_class_sysconfig lcdc_sysc = { 231static struct omap_hwmod_class_sysconfig lcdc_sysc = {
232 .rev_offs = 0x0, 232 .rev_offs = 0x0,
233 .sysc_offs = 0x54, 233 .sysc_offs = 0x54,
234 .sysc_flags = (SYSC_HAS_SIDLEMODE | SYSC_HAS_MIDLEMODE), 234 .sysc_flags = SYSC_HAS_SIDLEMODE | SYSC_HAS_MIDLEMODE,
235 .idlemodes = (SIDLE_FORCE | SIDLE_NO | SIDLE_SMART), 235 .idlemodes = SIDLE_FORCE | SIDLE_NO | SIDLE_SMART |
236 MSTANDBY_FORCE | MSTANDBY_NO | MSTANDBY_SMART,
236 .sysc_fields = &omap_hwmod_sysc_type2, 237 .sysc_fields = &omap_hwmod_sysc_type2,
237}; 238};
238 239
diff --git a/arch/arm/mach-omap2/pm.c b/arch/arm/mach-omap2/pm.c
index 1fde1bf53fb6..7ac9af56762d 100644
--- a/arch/arm/mach-omap2/pm.c
+++ b/arch/arm/mach-omap2/pm.c
@@ -74,83 +74,6 @@ int omap_pm_clkdms_setup(struct clockdomain *clkdm, void *unused)
74 return 0; 74 return 0;
75} 75}
76 76
77/*
78 * This API is to be called during init to set the various voltage
79 * domains to the voltage as per the opp table. Typically we boot up
80 * at the nominal voltage. So this function finds out the rate of
81 * the clock associated with the voltage domain, finds out the correct
82 * opp entry and sets the voltage domain to the voltage specified
83 * in the opp entry
84 */
85static int __init omap2_set_init_voltage(char *vdd_name, char *clk_name,
86 const char *oh_name)
87{
88 struct voltagedomain *voltdm;
89 struct clk *clk;
90 struct dev_pm_opp *opp;
91 unsigned long freq, bootup_volt;
92 struct device *dev;
93
94 if (!vdd_name || !clk_name || !oh_name) {
95 pr_err("%s: invalid parameters\n", __func__);
96 goto exit;
97 }
98
99 if (!strncmp(oh_name, "mpu", 3))
100 /*
101 * All current OMAPs share voltage rail and clock
102 * source, so CPU0 is used to represent the MPU-SS.
103 */
104 dev = get_cpu_device(0);
105 else
106 dev = omap_device_get_by_hwmod_name(oh_name);
107
108 if (IS_ERR(dev)) {
109 pr_err("%s: Unable to get dev pointer for hwmod %s\n",
110 __func__, oh_name);
111 goto exit;
112 }
113
114 voltdm = voltdm_lookup(vdd_name);
115 if (!voltdm) {
116 pr_err("%s: unable to get vdd pointer for vdd_%s\n",
117 __func__, vdd_name);
118 goto exit;
119 }
120
121 clk = clk_get(NULL, clk_name);
122 if (IS_ERR(clk)) {
123 pr_err("%s: unable to get clk %s\n", __func__, clk_name);
124 goto exit;
125 }
126
127 freq = clk_get_rate(clk);
128 clk_put(clk);
129
130 opp = dev_pm_opp_find_freq_ceil(dev, &freq);
131 if (IS_ERR(opp)) {
132 pr_err("%s: unable to find boot up OPP for vdd_%s\n",
133 __func__, vdd_name);
134 goto exit;
135 }
136
137 bootup_volt = dev_pm_opp_get_voltage(opp);
138 dev_pm_opp_put(opp);
139
140 if (!bootup_volt) {
141 pr_err("%s: unable to find voltage corresponding to the bootup OPP for vdd_%s\n",
142 __func__, vdd_name);
143 goto exit;
144 }
145
146 voltdm_scale(voltdm, bootup_volt);
147 return 0;
148
149exit:
150 pr_err("%s: unable to set vdd_%s\n", __func__, vdd_name);
151 return -EINVAL;
152}
153
154#ifdef CONFIG_SUSPEND 77#ifdef CONFIG_SUSPEND
155static int omap_pm_enter(suspend_state_t suspend_state) 78static int omap_pm_enter(suspend_state_t suspend_state)
156{ 79{
@@ -208,25 +131,6 @@ void omap_common_suspend_init(void *pm_suspend)
208} 131}
209#endif /* CONFIG_SUSPEND */ 132#endif /* CONFIG_SUSPEND */
210 133
211static void __init omap3_init_voltages(void)
212{
213 if (!soc_is_omap34xx())
214 return;
215
216 omap2_set_init_voltage("mpu_iva", "dpll1_ck", "mpu");
217 omap2_set_init_voltage("core", "l3_ick", "l3_main");
218}
219
220static void __init omap4_init_voltages(void)
221{
222 if (!soc_is_omap44xx())
223 return;
224
225 omap2_set_init_voltage("mpu", "dpll_mpu_ck", "mpu");
226 omap2_set_init_voltage("core", "l3_div_ck", "l3_main_1");
227 omap2_set_init_voltage("iva", "dpll_iva_m5x2_ck", "iva");
228}
229
230int __maybe_unused omap_pm_nop_init(void) 134int __maybe_unused omap_pm_nop_init(void)
231{ 135{
232 return 0; 136 return 0;
@@ -246,10 +150,6 @@ int __init omap2_common_pm_late_init(void)
246 omap4_twl_init(); 150 omap4_twl_init();
247 omap_voltage_late_init(); 151 omap_voltage_late_init();
248 152
249 /* Initialize the voltages */
250 omap3_init_voltages();
251 omap4_init_voltages();
252
253 /* Smartreflex device init */ 153 /* Smartreflex device init */
254 omap_devinit_smartreflex(); 154 omap_devinit_smartreflex();
255 155
diff --git a/arch/arm/xen/Makefile b/arch/arm/xen/Makefile
index 7ed28982c4c3..c32d04713ba0 100644
--- a/arch/arm/xen/Makefile
+++ b/arch/arm/xen/Makefile
@@ -1,3 +1,2 @@
1# SPDX-License-Identifier: GPL-2.0-only 1# SPDX-License-Identifier: GPL-2.0-only
2obj-y := enlighten.o hypercall.o grant-table.o p2m.o mm.o 2obj-y := enlighten.o hypercall.o grant-table.o p2m.o mm.o
3obj-$(CONFIG_XEN_EFI) += efi.o
diff --git a/arch/arm/xen/efi.c b/arch/arm/xen/efi.c
deleted file mode 100644
index d687a73044bf..000000000000
--- a/arch/arm/xen/efi.c
+++ /dev/null
@@ -1,28 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) 2015, Linaro Limited, Shannon Zhao
4 */
5
6#include <linux/efi.h>
7#include <xen/xen-ops.h>
8#include <asm/xen/xen-ops.h>
9
10/* Set XEN EFI runtime services function pointers. Other fields of struct efi,
11 * e.g. efi.systab, will be set like normal EFI.
12 */
13void __init xen_efi_runtime_setup(void)
14{
15 efi.get_time = xen_efi_get_time;
16 efi.set_time = xen_efi_set_time;
17 efi.get_wakeup_time = xen_efi_get_wakeup_time;
18 efi.set_wakeup_time = xen_efi_set_wakeup_time;
19 efi.get_variable = xen_efi_get_variable;
20 efi.get_next_variable = xen_efi_get_next_variable;
21 efi.set_variable = xen_efi_set_variable;
22 efi.query_variable_info = xen_efi_query_variable_info;
23 efi.update_capsule = xen_efi_update_capsule;
24 efi.query_capsule_caps = xen_efi_query_capsule_caps;
25 efi.get_next_high_mono_count = xen_efi_get_next_high_mono_count;
26 efi.reset_system = xen_efi_reset_system;
27}
28EXPORT_SYMBOL_GPL(xen_efi_runtime_setup);
diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
index 1e57692552d9..dd6804a64f1a 100644
--- a/arch/arm/xen/enlighten.c
+++ b/arch/arm/xen/enlighten.c
@@ -15,7 +15,6 @@
15#include <xen/xen-ops.h> 15#include <xen/xen-ops.h>
16#include <asm/xen/hypervisor.h> 16#include <asm/xen/hypervisor.h>
17#include <asm/xen/hypercall.h> 17#include <asm/xen/hypercall.h>
18#include <asm/xen/xen-ops.h>
19#include <asm/system_misc.h> 18#include <asm/system_misc.h>
20#include <asm/efi.h> 19#include <asm/efi.h>
21#include <linux/interrupt.h> 20#include <linux/interrupt.h>
@@ -437,7 +436,7 @@ EXPORT_SYMBOL_GPL(HYPERVISOR_memory_op);
437EXPORT_SYMBOL_GPL(HYPERVISOR_physdev_op); 436EXPORT_SYMBOL_GPL(HYPERVISOR_physdev_op);
438EXPORT_SYMBOL_GPL(HYPERVISOR_vcpu_op); 437EXPORT_SYMBOL_GPL(HYPERVISOR_vcpu_op);
439EXPORT_SYMBOL_GPL(HYPERVISOR_tmem_op); 438EXPORT_SYMBOL_GPL(HYPERVISOR_tmem_op);
440EXPORT_SYMBOL_GPL(HYPERVISOR_platform_op); 439EXPORT_SYMBOL_GPL(HYPERVISOR_platform_op_raw);
441EXPORT_SYMBOL_GPL(HYPERVISOR_multicall); 440EXPORT_SYMBOL_GPL(HYPERVISOR_multicall);
442EXPORT_SYMBOL_GPL(HYPERVISOR_vm_assist); 441EXPORT_SYMBOL_GPL(HYPERVISOR_vm_assist);
443EXPORT_SYMBOL_GPL(HYPERVISOR_dm_op); 442EXPORT_SYMBOL_GPL(HYPERVISOR_dm_op);
diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index 2b2c208408bb..38fa917c8585 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -28,7 +28,10 @@ unsigned long xen_get_swiotlb_free_pages(unsigned int order)
28 28
29 for_each_memblock(memory, reg) { 29 for_each_memblock(memory, reg) {
30 if (reg->base < (phys_addr_t)0xffffffff) { 30 if (reg->base < (phys_addr_t)0xffffffff) {
31 flags |= __GFP_DMA; 31 if (IS_ENABLED(CONFIG_ZONE_DMA32))
32 flags |= __GFP_DMA32;
33 else
34 flags |= __GFP_DMA;
32 break; 35 break;
33 } 36 }
34 } 37 }
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 41a9b4257b72..3f047afb982c 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -110,7 +110,6 @@ config ARM64
110 select GENERIC_STRNLEN_USER 110 select GENERIC_STRNLEN_USER
111 select GENERIC_TIME_VSYSCALL 111 select GENERIC_TIME_VSYSCALL
112 select GENERIC_GETTIMEOFDAY 112 select GENERIC_GETTIMEOFDAY
113 select GENERIC_COMPAT_VDSO if (!CPU_BIG_ENDIAN && COMPAT)
114 select HANDLE_DOMAIN_IRQ 113 select HANDLE_DOMAIN_IRQ
115 select HARDIRQS_SW_RESEND 114 select HARDIRQS_SW_RESEND
116 select HAVE_PCI 115 select HAVE_PCI
@@ -617,6 +616,23 @@ config CAVIUM_ERRATUM_30115
617 616
618 If unsure, say Y. 617 If unsure, say Y.
619 618
619config CAVIUM_TX2_ERRATUM_219
620 bool "Cavium ThunderX2 erratum 219: PRFM between TTBR change and ISB fails"
621 default y
622 help
623 On Cavium ThunderX2, a load, store or prefetch instruction between a
624 TTBR update and the corresponding context synchronizing operation can
625 cause a spurious Data Abort to be delivered to any hardware thread in
626 the CPU core.
627
628 Work around the issue by avoiding the problematic code sequence and
629 trapping KVM guest TTBRx_EL1 writes to EL2 when SMT is enabled. The
630 trap handler performs the corresponding register access, skips the
631 instruction and ensures context synchronization by virtue of the
632 exception return.
633
634 If unsure, say Y.
635
620config QCOM_FALKOR_ERRATUM_1003 636config QCOM_FALKOR_ERRATUM_1003
621 bool "Falkor E1003: Incorrect translation due to ASID change" 637 bool "Falkor E1003: Incorrect translation due to ASID change"
622 default y 638 default y
@@ -1159,7 +1175,7 @@ menuconfig COMPAT
1159if COMPAT 1175if COMPAT
1160 1176
1161config KUSER_HELPERS 1177config KUSER_HELPERS
1162 bool "Enable kuser helpers page for 32 bit applications" 1178 bool "Enable kuser helpers page for 32-bit applications"
1163 default y 1179 default y
1164 help 1180 help
1165 Warning: disabling this option may break 32-bit user programs. 1181 Warning: disabling this option may break 32-bit user programs.
@@ -1185,6 +1201,18 @@ config KUSER_HELPERS
1185 Say N here only if you are absolutely certain that you do not 1201 Say N here only if you are absolutely certain that you do not
1186 need these helpers; otherwise, the safe option is to say Y. 1202 need these helpers; otherwise, the safe option is to say Y.
1187 1203
1204config COMPAT_VDSO
1205 bool "Enable vDSO for 32-bit applications"
1206 depends on !CPU_BIG_ENDIAN && "$(CROSS_COMPILE_COMPAT)" != ""
1207 select GENERIC_COMPAT_VDSO
1208 default y
1209 help
1210 Place in the process address space of 32-bit applications an
1211 ELF shared object providing fast implementations of gettimeofday
1212 and clock_gettime.
1213
1214 You must have a 32-bit build of glibc 2.22 or later for programs
1215 to seamlessly take advantage of this.
1188 1216
1189menuconfig ARMV8_DEPRECATED 1217menuconfig ARMV8_DEPRECATED
1190 bool "Emulate deprecated/obsolete ARMv8 instructions" 1218 bool "Emulate deprecated/obsolete ARMv8 instructions"
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 84a3d502c5a5..2c0238ce0551 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -53,22 +53,6 @@ $(warning Detected assembler with broken .inst; disassembly will be unreliable)
53 endif 53 endif
54endif 54endif
55 55
56ifeq ($(CONFIG_GENERIC_COMPAT_VDSO), y)
57 CROSS_COMPILE_COMPAT ?= $(CONFIG_CROSS_COMPILE_COMPAT_VDSO:"%"=%)
58
59 ifeq ($(CONFIG_CC_IS_CLANG), y)
60 $(warning CROSS_COMPILE_COMPAT is clang, the compat vDSO will not be built)
61 else ifeq ($(strip $(CROSS_COMPILE_COMPAT)),)
62 $(warning CROSS_COMPILE_COMPAT not defined or empty, the compat vDSO will not be built)
63 else ifeq ($(shell which $(CROSS_COMPILE_COMPAT)gcc 2> /dev/null),)
64 $(error $(CROSS_COMPILE_COMPAT)gcc not found, check CROSS_COMPILE_COMPAT)
65 else
66 export CROSS_COMPILE_COMPAT
67 export CONFIG_COMPAT_VDSO := y
68 compat_vdso := -DCONFIG_COMPAT_VDSO=1
69 endif
70endif
71
72KBUILD_CFLAGS += -mgeneral-regs-only $(lseinstr) $(brokengasinst) \ 56KBUILD_CFLAGS += -mgeneral-regs-only $(lseinstr) $(brokengasinst) \
73 $(compat_vdso) $(cc_has_k_constraint) 57 $(compat_vdso) $(cc_has_k_constraint)
74KBUILD_CFLAGS += -fno-asynchronous-unwind-tables 58KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64-pinebook.dts b/arch/arm64/boot/dts/allwinner/sun50i-a64-pinebook.dts
index 2b6345db7dc0..78c82a665c84 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-a64-pinebook.dts
+++ b/arch/arm64/boot/dts/allwinner/sun50i-a64-pinebook.dts
@@ -104,6 +104,7 @@
104 104
105&ehci0 { 105&ehci0 {
106 phys = <&usbphy 0>; 106 phys = <&usbphy 0>;
107 phy-names = "usb";
107 status = "okay"; 108 status = "okay";
108}; 109};
109 110
@@ -150,6 +151,7 @@
150 151
151&ohci0 { 152&ohci0 {
152 phys = <&usbphy 0>; 153 phys = <&usbphy 0>;
154 phy-names = "usb";
153 status = "okay"; 155 status = "okay";
154}; 156};
155 157
diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi b/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi
index 69128a6dfc46..3eccbdba7154 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi
+++ b/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi
@@ -553,6 +553,7 @@
553 resets = <&ccu RST_BUS_OHCI1>, 553 resets = <&ccu RST_BUS_OHCI1>,
554 <&ccu RST_BUS_EHCI1>; 554 <&ccu RST_BUS_EHCI1>;
555 phys = <&usbphy 1>; 555 phys = <&usbphy 1>;
556 phy-names = "usb";
556 status = "disabled"; 557 status = "disabled";
557 }; 558 };
558 559
@@ -564,6 +565,7 @@
564 <&ccu CLK_USB_OHCI1>; 565 <&ccu CLK_USB_OHCI1>;
565 resets = <&ccu RST_BUS_OHCI1>; 566 resets = <&ccu RST_BUS_OHCI1>;
566 phys = <&usbphy 1>; 567 phys = <&usbphy 1>;
568 phy-names = "usb";
567 status = "disabled"; 569 status = "disabled";
568 }; 570 };
569 571
diff --git a/arch/arm64/boot/dts/allwinner/sun50i-h6.dtsi b/arch/arm64/boot/dts/allwinner/sun50i-h6.dtsi
index 4020a1aafa3e..0d5ea19336a1 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-h6.dtsi
+++ b/arch/arm64/boot/dts/allwinner/sun50i-h6.dtsi
@@ -547,6 +547,7 @@
547 resets = <&ccu RST_BUS_OHCI3>, 547 resets = <&ccu RST_BUS_OHCI3>,
548 <&ccu RST_BUS_EHCI3>; 548 <&ccu RST_BUS_EHCI3>;
549 phys = <&usb2phy 3>; 549 phys = <&usb2phy 3>;
550 phy-names = "usb";
550 status = "disabled"; 551 status = "disabled";
551 }; 552 };
552 553
@@ -558,6 +559,7 @@
558 <&ccu CLK_USB_OHCI3>; 559 <&ccu CLK_USB_OHCI3>;
559 resets = <&ccu RST_BUS_OHCI3>; 560 resets = <&ccu RST_BUS_OHCI3>;
560 phys = <&usb2phy 3>; 561 phys = <&usb2phy 3>;
562 phy-names = "usb";
561 status = "disabled"; 563 status = "disabled";
562 }; 564 };
563 565
diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
index 8e05c39eab08..c9a867ac32d4 100644
--- a/arch/arm64/configs/defconfig
+++ b/arch/arm64/configs/defconfig
@@ -723,7 +723,7 @@ CONFIG_TEGRA_IOMMU_SMMU=y
723CONFIG_ARM_SMMU=y 723CONFIG_ARM_SMMU=y
724CONFIG_ARM_SMMU_V3=y 724CONFIG_ARM_SMMU_V3=y
725CONFIG_QCOM_IOMMU=y 725CONFIG_QCOM_IOMMU=y
726CONFIG_REMOTEPROC=m 726CONFIG_REMOTEPROC=y
727CONFIG_QCOM_Q6V5_MSS=m 727CONFIG_QCOM_Q6V5_MSS=m
728CONFIG_QCOM_Q6V5_PAS=m 728CONFIG_QCOM_Q6V5_PAS=m
729CONFIG_QCOM_SYSMON=m 729CONFIG_QCOM_SYSMON=m
diff --git a/arch/arm64/include/asm/asm-uaccess.h b/arch/arm64/include/asm/asm-uaccess.h
index f74909ba29bd..5bf963830b17 100644
--- a/arch/arm64/include/asm/asm-uaccess.h
+++ b/arch/arm64/include/asm/asm-uaccess.h
@@ -78,10 +78,9 @@ alternative_else_nop_endif
78/* 78/*
79 * Remove the address tag from a virtual address, if present. 79 * Remove the address tag from a virtual address, if present.
80 */ 80 */
81 .macro clear_address_tag, dst, addr 81 .macro untagged_addr, dst, addr
82 tst \addr, #(1 << 55) 82 sbfx \dst, \addr, #0, #56
83 bic \dst, \addr, #(0xff << 56) 83 and \dst, \dst, \addr
84 csel \dst, \dst, \addr, eq
85 .endm 84 .endm
86 85
87#endif 86#endif
diff --git a/arch/arm64/include/asm/atomic_lse.h b/arch/arm64/include/asm/atomic_lse.h
index c6bd87d2915b..574808b9df4c 100644
--- a/arch/arm64/include/asm/atomic_lse.h
+++ b/arch/arm64/include/asm/atomic_lse.h
@@ -321,7 +321,8 @@ static inline s64 __lse_atomic64_dec_if_positive(atomic64_t *v)
321} 321}
322 322
323#define __CMPXCHG_CASE(w, sfx, name, sz, mb, cl...) \ 323#define __CMPXCHG_CASE(w, sfx, name, sz, mb, cl...) \
324static inline u##sz __lse__cmpxchg_case_##name##sz(volatile void *ptr, \ 324static __always_inline u##sz \
325__lse__cmpxchg_case_##name##sz(volatile void *ptr, \
325 u##sz old, \ 326 u##sz old, \
326 u##sz new) \ 327 u##sz new) \
327{ \ 328{ \
@@ -362,7 +363,8 @@ __CMPXCHG_CASE(x, , mb_, 64, al, "memory")
362#undef __CMPXCHG_CASE 363#undef __CMPXCHG_CASE
363 364
364#define __CMPXCHG_DBL(name, mb, cl...) \ 365#define __CMPXCHG_DBL(name, mb, cl...) \
365static inline long __lse__cmpxchg_double##name(unsigned long old1, \ 366static __always_inline long \
367__lse__cmpxchg_double##name(unsigned long old1, \
366 unsigned long old2, \ 368 unsigned long old2, \
367 unsigned long new1, \ 369 unsigned long new1, \
368 unsigned long new2, \ 370 unsigned long new2, \
diff --git a/arch/arm64/include/asm/cpucaps.h b/arch/arm64/include/asm/cpucaps.h
index f19fe4b9acc4..ac1dbca3d0cd 100644
--- a/arch/arm64/include/asm/cpucaps.h
+++ b/arch/arm64/include/asm/cpucaps.h
@@ -52,7 +52,9 @@
52#define ARM64_HAS_IRQ_PRIO_MASKING 42 52#define ARM64_HAS_IRQ_PRIO_MASKING 42
53#define ARM64_HAS_DCPODP 43 53#define ARM64_HAS_DCPODP 43
54#define ARM64_WORKAROUND_1463225 44 54#define ARM64_WORKAROUND_1463225 44
55#define ARM64_WORKAROUND_CAVIUM_TX2_219_TVM 45
56#define ARM64_WORKAROUND_CAVIUM_TX2_219_PRFM 46
55 57
56#define ARM64_NCAPS 45 58#define ARM64_NCAPS 47
57 59
58#endif /* __ASM_CPUCAPS_H */ 60#endif /* __ASM_CPUCAPS_H */
diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h
index 86825aa20852..97f21cc66657 100644
--- a/arch/arm64/include/asm/kvm_hyp.h
+++ b/arch/arm64/include/asm/kvm_hyp.h
@@ -47,30 +47,6 @@
47#define read_sysreg_el2(r) read_sysreg_elx(r, _EL2, _EL1) 47#define read_sysreg_el2(r) read_sysreg_elx(r, _EL2, _EL1)
48#define write_sysreg_el2(v,r) write_sysreg_elx(v, r, _EL2, _EL1) 48#define write_sysreg_el2(v,r) write_sysreg_elx(v, r, _EL2, _EL1)
49 49
50/**
51 * hyp_alternate_select - Generates patchable code sequences that are
52 * used to switch between two implementations of a function, depending
53 * on the availability of a feature.
54 *
55 * @fname: a symbol name that will be defined as a function returning a
56 * function pointer whose type will match @orig and @alt
57 * @orig: A pointer to the default function, as returned by @fname when
58 * @cond doesn't hold
59 * @alt: A pointer to the alternate function, as returned by @fname
60 * when @cond holds
61 * @cond: a CPU feature (as described in asm/cpufeature.h)
62 */
63#define hyp_alternate_select(fname, orig, alt, cond) \
64typeof(orig) * __hyp_text fname(void) \
65{ \
66 typeof(alt) *val = orig; \
67 asm volatile(ALTERNATIVE("nop \n", \
68 "mov %0, %1 \n", \
69 cond) \
70 : "+r" (val) : "r" (alt)); \
71 return val; \
72}
73
74int __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu); 50int __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu);
75 51
76void __vgic_v3_save_state(struct kvm_vcpu *vcpu); 52void __vgic_v3_save_state(struct kvm_vcpu *vcpu);
diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index b61b50bf68b1..c23c47360664 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -215,12 +215,18 @@ static inline unsigned long kaslr_offset(void)
215 * up with a tagged userland pointer. Clear the tag to get a sane pointer to 215 * up with a tagged userland pointer. Clear the tag to get a sane pointer to
216 * pass on to access_ok(), for instance. 216 * pass on to access_ok(), for instance.
217 */ 217 */
218#define untagged_addr(addr) \ 218#define __untagged_addr(addr) \
219 ((__force __typeof__(addr))sign_extend64((__force u64)(addr), 55)) 219 ((__force __typeof__(addr))sign_extend64((__force u64)(addr), 55))
220 220
221#define untagged_addr(addr) ({ \
222 u64 __addr = (__force u64)addr; \
223 __addr &= __untagged_addr(__addr); \
224 (__force __typeof__(addr))__addr; \
225})
226
221#ifdef CONFIG_KASAN_SW_TAGS 227#ifdef CONFIG_KASAN_SW_TAGS
222#define __tag_shifted(tag) ((u64)(tag) << 56) 228#define __tag_shifted(tag) ((u64)(tag) << 56)
223#define __tag_reset(addr) untagged_addr(addr) 229#define __tag_reset(addr) __untagged_addr(addr)
224#define __tag_get(addr) (__u8)((u64)(addr) >> 56) 230#define __tag_get(addr) (__u8)((u64)(addr) >> 56)
225#else 231#else
226#define __tag_shifted(tag) 0UL 232#define __tag_shifted(tag) 0UL
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 7576df00eb50..8330810f699e 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -876,9 +876,6 @@ static inline void update_mmu_cache(struct vm_area_struct *vma,
876 876
877#define update_mmu_cache_pmd(vma, address, pmd) do { } while (0) 877#define update_mmu_cache_pmd(vma, address, pmd) do { } while (0)
878 878
879#define kc_vaddr_to_offset(v) ((v) & ~PAGE_END)
880#define kc_offset_to_vaddr(o) ((o) | PAGE_END)
881
882#ifdef CONFIG_ARM64_PA_BITS_52 879#ifdef CONFIG_ARM64_PA_BITS_52
883#define phys_to_ttbr(addr) (((addr) | ((addr) >> 46)) & TTBR_BADDR_MASK_52) 880#define phys_to_ttbr(addr) (((addr) | ((addr) >> 46)) & TTBR_BADDR_MASK_52)
884#else 881#else
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index 972d196c7714..6e919fafb43d 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -212,7 +212,7 @@
212#define SYS_FAR_EL1 sys_reg(3, 0, 6, 0, 0) 212#define SYS_FAR_EL1 sys_reg(3, 0, 6, 0, 0)
213#define SYS_PAR_EL1 sys_reg(3, 0, 7, 4, 0) 213#define SYS_PAR_EL1 sys_reg(3, 0, 7, 4, 0)
214 214
215#define SYS_PAR_EL1_F BIT(1) 215#define SYS_PAR_EL1_F BIT(0)
216#define SYS_PAR_EL1_FST GENMASK(6, 1) 216#define SYS_PAR_EL1_FST GENMASK(6, 1)
217 217
218/*** Statistical Profiling Extension ***/ 218/*** Statistical Profiling Extension ***/
diff --git a/arch/arm64/include/asm/vdso/compat_barrier.h b/arch/arm64/include/asm/vdso/compat_barrier.h
index fb60a88b5ed4..3fd8fd6d8fc2 100644
--- a/arch/arm64/include/asm/vdso/compat_barrier.h
+++ b/arch/arm64/include/asm/vdso/compat_barrier.h
@@ -20,7 +20,7 @@
20 20
21#define dmb(option) __asm__ __volatile__ ("dmb " #option : : : "memory") 21#define dmb(option) __asm__ __volatile__ ("dmb " #option : : : "memory")
22 22
23#if __LINUX_ARM_ARCH__ >= 8 23#if __LINUX_ARM_ARCH__ >= 8 && defined(CONFIG_AS_DMB_ISHLD)
24#define aarch32_smp_mb() dmb(ish) 24#define aarch32_smp_mb() dmb(ish)
25#define aarch32_smp_rmb() dmb(ishld) 25#define aarch32_smp_rmb() dmb(ishld)
26#define aarch32_smp_wmb() dmb(ishst) 26#define aarch32_smp_wmb() dmb(ishst)
diff --git a/arch/arm64/include/asm/vdso_datapage.h b/arch/arm64/include/asm/vdso_datapage.h
deleted file mode 100644
index 1f38bf330a6e..000000000000
--- a/arch/arm64/include/asm/vdso_datapage.h
+++ /dev/null
@@ -1,33 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (C) 2012 ARM Limited
4 */
5#ifndef __ASM_VDSO_DATAPAGE_H
6#define __ASM_VDSO_DATAPAGE_H
7
8#ifndef __ASSEMBLY__
9
10struct vdso_data {
11 __u64 cs_cycle_last; /* Timebase at clocksource init */
12 __u64 raw_time_sec; /* Raw time */
13 __u64 raw_time_nsec;
14 __u64 xtime_clock_sec; /* Kernel time */
15 __u64 xtime_clock_nsec;
16 __u64 xtime_coarse_sec; /* Coarse time */
17 __u64 xtime_coarse_nsec;
18 __u64 wtm_clock_sec; /* Wall to monotonic time */
19 __u64 wtm_clock_nsec;
20 __u32 tb_seq_count; /* Timebase sequence counter */
21 /* cs_* members must be adjacent and in this order (ldp accesses) */
22 __u32 cs_mono_mult; /* NTP-adjusted clocksource multiplier */
23 __u32 cs_shift; /* Clocksource shift (mono = raw) */
24 __u32 cs_raw_mult; /* Raw clocksource multiplier */
25 __u32 tz_minuteswest; /* Whacky timezone stuff */
26 __u32 tz_dsttime;
27 __u32 use_syscall;
28 __u32 hrtimer_res;
29};
30
31#endif /* !__ASSEMBLY__ */
32
33#endif /* __ASM_VDSO_DATAPAGE_H */
diff --git a/arch/arm64/include/asm/xen/xen-ops.h b/arch/arm64/include/asm/xen/xen-ops.h
deleted file mode 100644
index e6e784051932..000000000000
--- a/arch/arm64/include/asm/xen/xen-ops.h
+++ /dev/null
@@ -1,7 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_XEN_OPS_H
3#define _ASM_XEN_OPS_H
4
5void xen_efi_runtime_setup(void);
6
7#endif /* _ASM_XEN_OPS_H */
diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c
index 2ec09debc2bb..ca158be21f83 100644
--- a/arch/arm64/kernel/armv8_deprecated.c
+++ b/arch/arm64/kernel/armv8_deprecated.c
@@ -174,6 +174,9 @@ static void __init register_insn_emulation(struct insn_emulation_ops *ops)
174 struct insn_emulation *insn; 174 struct insn_emulation *insn;
175 175
176 insn = kzalloc(sizeof(*insn), GFP_KERNEL); 176 insn = kzalloc(sizeof(*insn), GFP_KERNEL);
177 if (!insn)
178 return;
179
177 insn->ops = ops; 180 insn->ops = ops;
178 insn->min = INSN_UNDEF; 181 insn->min = INSN_UNDEF;
179 182
@@ -233,6 +236,8 @@ static void __init register_insn_emulation_sysctl(void)
233 236
234 insns_sysctl = kcalloc(nr_insn_emulated + 1, sizeof(*sysctl), 237 insns_sysctl = kcalloc(nr_insn_emulated + 1, sizeof(*sysctl),
235 GFP_KERNEL); 238 GFP_KERNEL);
239 if (!insns_sysctl)
240 return;
236 241
237 raw_spin_lock_irqsave(&insn_emulation_lock, flags); 242 raw_spin_lock_irqsave(&insn_emulation_lock, flags);
238 list_for_each_entry(insn, &insn_emulation, node) { 243 list_for_each_entry(insn, &insn_emulation, node) {
diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c
index 1e43ba5c79b7..6c3b10a41bd8 100644
--- a/arch/arm64/kernel/cpu_errata.c
+++ b/arch/arm64/kernel/cpu_errata.c
@@ -12,6 +12,7 @@
12#include <asm/cpu.h> 12#include <asm/cpu.h>
13#include <asm/cputype.h> 13#include <asm/cputype.h>
14#include <asm/cpufeature.h> 14#include <asm/cpufeature.h>
15#include <asm/smp_plat.h>
15 16
16static bool __maybe_unused 17static bool __maybe_unused
17is_affected_midr_range(const struct arm64_cpu_capabilities *entry, int scope) 18is_affected_midr_range(const struct arm64_cpu_capabilities *entry, int scope)
@@ -128,8 +129,8 @@ static void install_bp_hardening_cb(bp_hardening_cb_t fn,
128 int cpu, slot = -1; 129 int cpu, slot = -1;
129 130
130 /* 131 /*
131 * enable_smccc_arch_workaround_1() passes NULL for the hyp_vecs 132 * detect_harden_bp_fw() passes NULL for the hyp_vecs start/end if
132 * start/end if we're a guest. Skip the hyp-vectors work. 133 * we're a guest. Skip the hyp-vectors work.
133 */ 134 */
134 if (!hyp_vecs_start) { 135 if (!hyp_vecs_start) {
135 __this_cpu_write(bp_hardening_data.fn, fn); 136 __this_cpu_write(bp_hardening_data.fn, fn);
@@ -623,6 +624,30 @@ check_branch_predictor(const struct arm64_cpu_capabilities *entry, int scope)
623 return (need_wa > 0); 624 return (need_wa > 0);
624} 625}
625 626
627static const __maybe_unused struct midr_range tx2_family_cpus[] = {
628 MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN),
629 MIDR_ALL_VERSIONS(MIDR_CAVIUM_THUNDERX2),
630 {},
631};
632
633static bool __maybe_unused
634needs_tx2_tvm_workaround(const struct arm64_cpu_capabilities *entry,
635 int scope)
636{
637 int i;
638
639 if (!is_affected_midr_range_list(entry, scope) ||
640 !is_hyp_mode_available())
641 return false;
642
643 for_each_possible_cpu(i) {
644 if (MPIDR_AFFINITY_LEVEL(cpu_logical_map(i), 0) != 0)
645 return true;
646 }
647
648 return false;
649}
650
626#ifdef CONFIG_HARDEN_EL2_VECTORS 651#ifdef CONFIG_HARDEN_EL2_VECTORS
627 652
628static const struct midr_range arm64_harden_el2_vectors[] = { 653static const struct midr_range arm64_harden_el2_vectors[] = {
@@ -852,6 +877,19 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
852 .matches = has_cortex_a76_erratum_1463225, 877 .matches = has_cortex_a76_erratum_1463225,
853 }, 878 },
854#endif 879#endif
880#ifdef CONFIG_CAVIUM_TX2_ERRATUM_219
881 {
882 .desc = "Cavium ThunderX2 erratum 219 (KVM guest sysreg trapping)",
883 .capability = ARM64_WORKAROUND_CAVIUM_TX2_219_TVM,
884 ERRATA_MIDR_RANGE_LIST(tx2_family_cpus),
885 .matches = needs_tx2_tvm_workaround,
886 },
887 {
888 .desc = "Cavium ThunderX2 erratum 219 (PRFM removal)",
889 .capability = ARM64_WORKAROUND_CAVIUM_TX2_219_PRFM,
890 ERRATA_MIDR_RANGE_LIST(tx2_family_cpus),
891 },
892#endif
855 { 893 {
856 } 894 }
857}; 895};
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 9323bcc40a58..80f459ad0190 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -136,6 +136,7 @@ static const struct arm64_ftr_bits ftr_id_aa64isar0[] = {
136 136
137static const struct arm64_ftr_bits ftr_id_aa64isar1[] = { 137static const struct arm64_ftr_bits ftr_id_aa64isar1[] = {
138 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_SB_SHIFT, 4, 0), 138 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_SB_SHIFT, 4, 0),
139 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_FRINTTS_SHIFT, 4, 0),
139 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_PTR_AUTH), 140 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_PTR_AUTH),
140 FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_GPI_SHIFT, 4, 0), 141 FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_GPI_SHIFT, 4, 0),
141 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_PTR_AUTH), 142 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_PTR_AUTH),
@@ -175,11 +176,16 @@ static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = {
175}; 176};
176 177
177static const struct arm64_ftr_bits ftr_id_aa64zfr0[] = { 178static const struct arm64_ftr_bits ftr_id_aa64zfr0[] = {
178 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SM4_SHIFT, 4, 0), 179 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
179 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SHA3_SHIFT, 4, 0), 180 FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SM4_SHIFT, 4, 0),
180 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_BITPERM_SHIFT, 4, 0), 181 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
181 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_AES_SHIFT, 4, 0), 182 FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SHA3_SHIFT, 4, 0),
182 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SVEVER_SHIFT, 4, 0), 183 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
184 FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_BITPERM_SHIFT, 4, 0),
185 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
186 FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_AES_SHIFT, 4, 0),
187 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
188 FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SVEVER_SHIFT, 4, 0),
183 ARM64_FTR_END, 189 ARM64_FTR_END,
184}; 190};
185 191
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index 84a822748c84..cf3bd2976e57 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -604,7 +604,7 @@ el1_da:
604 */ 604 */
605 mrs x3, far_el1 605 mrs x3, far_el1
606 inherit_daif pstate=x23, tmp=x2 606 inherit_daif pstate=x23, tmp=x2
607 clear_address_tag x0, x3 607 untagged_addr x0, x3
608 mov x2, sp // struct pt_regs 608 mov x2, sp // struct pt_regs
609 bl do_mem_abort 609 bl do_mem_abort
610 610
@@ -680,7 +680,7 @@ alternative_if ARM64_HAS_IRQ_PRIO_MASKING
680 orr x24, x24, x0 680 orr x24, x24, x0
681alternative_else_nop_endif 681alternative_else_nop_endif
682 cbnz x24, 1f // preempt count != 0 || NMI return path 682 cbnz x24, 1f // preempt count != 0 || NMI return path
683 bl preempt_schedule_irq // irq en/disable is done inside 683 bl arm64_preempt_schedule_irq // irq en/disable is done inside
6841: 6841:
685#endif 685#endif
686 686
@@ -775,6 +775,7 @@ el0_sync_compat:
775 b.ge el0_dbg 775 b.ge el0_dbg
776 b el0_inv 776 b el0_inv
777el0_svc_compat: 777el0_svc_compat:
778 gic_prio_kentry_setup tmp=x1
778 mov x0, sp 779 mov x0, sp
779 bl el0_svc_compat_handler 780 bl el0_svc_compat_handler
780 b ret_to_user 781 b ret_to_user
@@ -807,7 +808,7 @@ el0_da:
807 mrs x26, far_el1 808 mrs x26, far_el1
808 ct_user_exit_irqoff 809 ct_user_exit_irqoff
809 enable_daif 810 enable_daif
810 clear_address_tag x0, x26 811 untagged_addr x0, x26
811 mov x1, x25 812 mov x1, x25
812 mov x2, sp 813 mov x2, sp
813 bl do_mem_abort 814 bl do_mem_abort
@@ -1070,7 +1071,9 @@ alternative_insn isb, nop, ARM64_WORKAROUND_QCOM_FALKOR_E1003
1070#else 1071#else
1071 ldr x30, =vectors 1072 ldr x30, =vectors
1072#endif 1073#endif
1074alternative_if_not ARM64_WORKAROUND_CAVIUM_TX2_219_PRFM
1073 prfm plil1strm, [x30, #(1b - tramp_vectors)] 1075 prfm plil1strm, [x30, #(1b - tramp_vectors)]
1076alternative_else_nop_endif
1074 msr vbar_el1, x30 1077 msr vbar_el1, x30
1075 add x30, x30, #(1b - tramp_vectors) 1078 add x30, x30, #(1b - tramp_vectors)
1076 isb 1079 isb
diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c
index 171773257974..06e56b470315 100644
--- a/arch/arm64/kernel/ftrace.c
+++ b/arch/arm64/kernel/ftrace.c
@@ -121,10 +121,16 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
121 121
122 /* 122 /*
123 * Ensure updated trampoline is visible to instruction 123 * Ensure updated trampoline is visible to instruction
124 * fetch before we patch in the branch. 124 * fetch before we patch in the branch. Although the
125 * architecture doesn't require an IPI in this case,
126 * Neoverse-N1 erratum #1542419 does require one
127 * if the TLB maintenance in module_enable_ro() is
128 * skipped due to rodata_enabled. It doesn't seem worth
129 * it to make it conditional given that this is
130 * certainly not a fast-path.
125 */ 131 */
126 __flush_icache_range((unsigned long)&dst[0], 132 flush_icache_range((unsigned long)&dst[0],
127 (unsigned long)&dst[1]); 133 (unsigned long)&dst[1]);
128 } 134 }
129 addr = (unsigned long)dst; 135 addr = (unsigned long)dst;
130#else /* CONFIG_ARM64_MODULE_PLTS */ 136#else /* CONFIG_ARM64_MODULE_PLTS */
diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c
index e0a7fce0e01c..a96b2921d22c 100644
--- a/arch/arm64/kernel/hibernate.c
+++ b/arch/arm64/kernel/hibernate.c
@@ -201,6 +201,7 @@ static int create_safe_exec_page(void *src_start, size_t length,
201 gfp_t mask) 201 gfp_t mask)
202{ 202{
203 int rc = 0; 203 int rc = 0;
204 pgd_t *trans_pgd;
204 pgd_t *pgdp; 205 pgd_t *pgdp;
205 pud_t *pudp; 206 pud_t *pudp;
206 pmd_t *pmdp; 207 pmd_t *pmdp;
@@ -215,7 +216,13 @@ static int create_safe_exec_page(void *src_start, size_t length,
215 memcpy((void *)dst, src_start, length); 216 memcpy((void *)dst, src_start, length);
216 __flush_icache_range(dst, dst + length); 217 __flush_icache_range(dst, dst + length);
217 218
218 pgdp = pgd_offset_raw(allocator(mask), dst_addr); 219 trans_pgd = allocator(mask);
220 if (!trans_pgd) {
221 rc = -ENOMEM;
222 goto out;
223 }
224
225 pgdp = pgd_offset_raw(trans_pgd, dst_addr);
219 if (pgd_none(READ_ONCE(*pgdp))) { 226 if (pgd_none(READ_ONCE(*pgdp))) {
220 pudp = allocator(mask); 227 pudp = allocator(mask);
221 if (!pudp) { 228 if (!pudp) {
diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index a47462def04b..71f788cd2b18 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -17,6 +17,7 @@
17#include <linux/sched/task.h> 17#include <linux/sched/task.h>
18#include <linux/sched/task_stack.h> 18#include <linux/sched/task_stack.h>
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/lockdep.h>
20#include <linux/mm.h> 21#include <linux/mm.h>
21#include <linux/stddef.h> 22#include <linux/stddef.h>
22#include <linux/sysctl.h> 23#include <linux/sysctl.h>
@@ -44,6 +45,7 @@
44#include <asm/alternative.h> 45#include <asm/alternative.h>
45#include <asm/arch_gicv3.h> 46#include <asm/arch_gicv3.h>
46#include <asm/compat.h> 47#include <asm/compat.h>
48#include <asm/cpufeature.h>
47#include <asm/cacheflush.h> 49#include <asm/cacheflush.h>
48#include <asm/exec.h> 50#include <asm/exec.h>
49#include <asm/fpsimd.h> 51#include <asm/fpsimd.h>
@@ -332,22 +334,27 @@ void arch_release_task_struct(struct task_struct *tsk)
332 fpsimd_release_task(tsk); 334 fpsimd_release_task(tsk);
333} 335}
334 336
335/*
336 * src and dst may temporarily have aliased sve_state after task_struct
337 * is copied. We cannot fix this properly here, because src may have
338 * live SVE state and dst's thread_info may not exist yet, so tweaking
339 * either src's or dst's TIF_SVE is not safe.
340 *
341 * The unaliasing is done in copy_thread() instead. This works because
342 * dst is not schedulable or traceable until both of these functions
343 * have been called.
344 */
345int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) 337int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
346{ 338{
347 if (current->mm) 339 if (current->mm)
348 fpsimd_preserve_current_state(); 340 fpsimd_preserve_current_state();
349 *dst = *src; 341 *dst = *src;
350 342
343 /* We rely on the above assignment to initialize dst's thread_flags: */
344 BUILD_BUG_ON(!IS_ENABLED(CONFIG_THREAD_INFO_IN_TASK));
345
346 /*
347 * Detach src's sve_state (if any) from dst so that it does not
348 * get erroneously used or freed prematurely. dst's sve_state
349 * will be allocated on demand later on if dst uses SVE.
350 * For consistency, also clear TIF_SVE here: this could be done
351 * later in copy_process(), but to avoid tripping up future
352 * maintainers it is best not to leave TIF_SVE and sve_state in
353 * an inconsistent state, even temporarily.
354 */
355 dst->thread.sve_state = NULL;
356 clear_tsk_thread_flag(dst, TIF_SVE);
357
351 return 0; 358 return 0;
352} 359}
353 360
@@ -361,13 +368,6 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,
361 memset(&p->thread.cpu_context, 0, sizeof(struct cpu_context)); 368 memset(&p->thread.cpu_context, 0, sizeof(struct cpu_context));
362 369
363 /* 370 /*
364 * Unalias p->thread.sve_state (if any) from the parent task
365 * and disable discard SVE state for p:
366 */
367 clear_tsk_thread_flag(p, TIF_SVE);
368 p->thread.sve_state = NULL;
369
370 /*
371 * In case p was allocated the same task_struct pointer as some 371 * In case p was allocated the same task_struct pointer as some
372 * other recently-exited task, make sure p is disassociated from 372 * other recently-exited task, make sure p is disassociated from
373 * any cpu that may have run that now-exited task recently. 373 * any cpu that may have run that now-exited task recently.
@@ -633,3 +633,19 @@ static int __init tagged_addr_init(void)
633 633
634core_initcall(tagged_addr_init); 634core_initcall(tagged_addr_init);
635#endif /* CONFIG_ARM64_TAGGED_ADDR_ABI */ 635#endif /* CONFIG_ARM64_TAGGED_ADDR_ABI */
636
637asmlinkage void __sched arm64_preempt_schedule_irq(void)
638{
639 lockdep_assert_irqs_disabled();
640
641 /*
642 * Preempting a task from an IRQ means we leave copies of PSTATE
643 * on the stack. cpufeature's enable calls may modify PSTATE, but
644 * resuming one of these preempted tasks would undo those changes.
645 *
646 * Only allow a task to be preempted once cpufeatures have been
647 * enabled.
648 */
649 if (static_branch_likely(&arm64_const_caps_ready))
650 preempt_schedule_irq();
651}
diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
index 1fba0776ed40..76b327f88fbb 100644
--- a/arch/arm64/kernel/vdso32/Makefile
+++ b/arch/arm64/kernel/vdso32/Makefile
@@ -8,15 +8,21 @@
8ARCH_REL_TYPE_ABS := R_ARM_JUMP_SLOT|R_ARM_GLOB_DAT|R_ARM_ABS32 8ARCH_REL_TYPE_ABS := R_ARM_JUMP_SLOT|R_ARM_GLOB_DAT|R_ARM_ABS32
9include $(srctree)/lib/vdso/Makefile 9include $(srctree)/lib/vdso/Makefile
10 10
11COMPATCC := $(CROSS_COMPILE_COMPAT)gcc 11# Same as cc-*option, but using CC_COMPAT instead of CC
12ifeq ($(CONFIG_CC_IS_CLANG), y)
13CC_COMPAT ?= $(CC)
14else
15CC_COMPAT ?= $(CROSS_COMPILE_COMPAT)gcc
16endif
12 17
13# Same as cc-*option, but using COMPATCC instead of CC
14cc32-option = $(call try-run,\ 18cc32-option = $(call try-run,\
15 $(COMPATCC) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2)) 19 $(CC_COMPAT) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
16cc32-disable-warning = $(call try-run,\ 20cc32-disable-warning = $(call try-run,\
17 $(COMPATCC) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) 21 $(CC_COMPAT) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
18cc32-ldoption = $(call try-run,\ 22cc32-ldoption = $(call try-run,\
19 $(COMPATCC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2)) 23 $(CC_COMPAT) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
24cc32-as-instr = $(call try-run,\
25 printf "%b\n" "$(1)" | $(CC_COMPAT) $(VDSO_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
20 26
21# We cannot use the global flags to compile the vDSO files, the main reason 27# We cannot use the global flags to compile the vDSO files, the main reason
22# being that the 32-bit compiler may be older than the main (64-bit) compiler 28# being that the 32-bit compiler may be older than the main (64-bit) compiler
@@ -25,22 +31,21 @@ cc32-ldoption = $(call try-run,\
25# arm64 one. 31# arm64 one.
26# As a result we set our own flags here. 32# As a result we set our own flags here.
27 33
28# From top-level Makefile 34# KBUILD_CPPFLAGS and NOSTDINC_FLAGS from top-level Makefile
29# NOSTDINC_FLAGS 35VDSO_CPPFLAGS := -D__KERNEL__ -nostdinc -isystem $(shell $(CC_COMPAT) -print-file-name=include)
30VDSO_CPPFLAGS := -nostdinc -isystem $(shell $(COMPATCC) -print-file-name=include)
31VDSO_CPPFLAGS += $(LINUXINCLUDE) 36VDSO_CPPFLAGS += $(LINUXINCLUDE)
32VDSO_CPPFLAGS += $(KBUILD_CPPFLAGS)
33 37
34# Common C and assembly flags 38# Common C and assembly flags
35# From top-level Makefile 39# From top-level Makefile
36VDSO_CAFLAGS := $(VDSO_CPPFLAGS) 40VDSO_CAFLAGS := $(VDSO_CPPFLAGS)
41ifneq ($(shell $(CC_COMPAT) --version 2>&1 | head -n 1 | grep clang),)
42VDSO_CAFLAGS += --target=$(notdir $(CROSS_COMPILE_COMPAT:%-=%))
43endif
44
37VDSO_CAFLAGS += $(call cc32-option,-fno-PIE) 45VDSO_CAFLAGS += $(call cc32-option,-fno-PIE)
38ifdef CONFIG_DEBUG_INFO 46ifdef CONFIG_DEBUG_INFO
39VDSO_CAFLAGS += -g 47VDSO_CAFLAGS += -g
40endif 48endif
41ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(COMPATCC)), y)
42VDSO_CAFLAGS += -DCC_HAVE_ASM_GOTO
43endif
44 49
45# From arm Makefile 50# From arm Makefile
46VDSO_CAFLAGS += $(call cc32-option,-fno-dwarf2-cfi-asm) 51VDSO_CAFLAGS += $(call cc32-option,-fno-dwarf2-cfi-asm)
@@ -55,6 +60,7 @@ endif
55VDSO_CAFLAGS += -fPIC -fno-builtin -fno-stack-protector 60VDSO_CAFLAGS += -fPIC -fno-builtin -fno-stack-protector
56VDSO_CAFLAGS += -DDISABLE_BRANCH_PROFILING 61VDSO_CAFLAGS += -DDISABLE_BRANCH_PROFILING
57 62
63
58# Try to compile for ARMv8. If the compiler is too old and doesn't support it, 64# Try to compile for ARMv8. If the compiler is too old and doesn't support it,
59# fall back to v7. There is no easy way to check for what architecture the code 65# fall back to v7. There is no easy way to check for what architecture the code
60# is being compiled, so define a macro specifying that (see arch/arm/Makefile). 66# is being compiled, so define a macro specifying that (see arch/arm/Makefile).
@@ -91,6 +97,12 @@ VDSO_CFLAGS += -Wno-int-to-pointer-cast
91VDSO_AFLAGS := $(VDSO_CAFLAGS) 97VDSO_AFLAGS := $(VDSO_CAFLAGS)
92VDSO_AFLAGS += -D__ASSEMBLY__ 98VDSO_AFLAGS += -D__ASSEMBLY__
93 99
100# Check for binutils support for dmb ishld
101dmbinstr := $(call cc32-as-instr,dmb ishld,-DCONFIG_AS_DMB_ISHLD=1)
102
103VDSO_CFLAGS += $(dmbinstr)
104VDSO_AFLAGS += $(dmbinstr)
105
94VDSO_LDFLAGS := $(VDSO_CPPFLAGS) 106VDSO_LDFLAGS := $(VDSO_CPPFLAGS)
95# From arm vDSO Makefile 107# From arm vDSO Makefile
96VDSO_LDFLAGS += -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1 108VDSO_LDFLAGS += -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1
@@ -159,14 +171,14 @@ quiet_cmd_vdsold_and_vdso_check = LD32 $@
159 cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check) 171 cmd_vdsold_and_vdso_check = $(cmd_vdsold); $(cmd_vdso_check)
160 172
161quiet_cmd_vdsold = LD32 $@ 173quiet_cmd_vdsold = LD32 $@
162 cmd_vdsold = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_LDFLAGS) \ 174 cmd_vdsold = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_LDFLAGS) \
163 -Wl,-T $(filter %.lds,$^) $(filter %.o,$^) -o $@ 175 -Wl,-T $(filter %.lds,$^) $(filter %.o,$^) -o $@
164quiet_cmd_vdsocc = CC32 $@ 176quiet_cmd_vdsocc = CC32 $@
165 cmd_vdsocc = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $< 177 cmd_vdsocc = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) -c -o $@ $<
166quiet_cmd_vdsocc_gettimeofday = CC32 $@ 178quiet_cmd_vdsocc_gettimeofday = CC32 $@
167 cmd_vdsocc_gettimeofday = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) $(VDSO_CFLAGS_gettimeofday_o) -c -o $@ $< 179 cmd_vdsocc_gettimeofday = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_CFLAGS) $(VDSO_CFLAGS_gettimeofday_o) -c -o $@ $<
168quiet_cmd_vdsoas = AS32 $@ 180quiet_cmd_vdsoas = AS32 $@
169 cmd_vdsoas = $(COMPATCC) -Wp,-MD,$(depfile) $(VDSO_AFLAGS) -c -o $@ $< 181 cmd_vdsoas = $(CC_COMPAT) -Wp,-MD,$(depfile) $(VDSO_AFLAGS) -c -o $@ $<
170 182
171quiet_cmd_vdsomunge = MUNGE $@ 183quiet_cmd_vdsomunge = MUNGE $@
172 cmd_vdsomunge = $(obj)/$(munge) $< $@ 184 cmd_vdsomunge = $(obj)/$(munge) $< $@
diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c
index bd978ad71936..799e84a40335 100644
--- a/arch/arm64/kvm/hyp/switch.c
+++ b/arch/arm64/kvm/hyp/switch.c
@@ -124,6 +124,9 @@ static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu)
124{ 124{
125 u64 hcr = vcpu->arch.hcr_el2; 125 u64 hcr = vcpu->arch.hcr_el2;
126 126
127 if (cpus_have_const_cap(ARM64_WORKAROUND_CAVIUM_TX2_219_TVM))
128 hcr |= HCR_TVM;
129
127 write_sysreg(hcr, hcr_el2); 130 write_sysreg(hcr, hcr_el2);
128 131
129 if (cpus_have_const_cap(ARM64_HAS_RAS_EXTN) && (hcr & HCR_VSE)) 132 if (cpus_have_const_cap(ARM64_HAS_RAS_EXTN) && (hcr & HCR_VSE))
@@ -174,8 +177,10 @@ static void __hyp_text __deactivate_traps(struct kvm_vcpu *vcpu)
174 * the crucial bit is "On taking a vSError interrupt, 177 * the crucial bit is "On taking a vSError interrupt,
175 * HCR_EL2.VSE is cleared to 0." 178 * HCR_EL2.VSE is cleared to 0."
176 */ 179 */
177 if (vcpu->arch.hcr_el2 & HCR_VSE) 180 if (vcpu->arch.hcr_el2 & HCR_VSE) {
178 vcpu->arch.hcr_el2 = read_sysreg(hcr_el2); 181 vcpu->arch.hcr_el2 &= ~HCR_VSE;
182 vcpu->arch.hcr_el2 |= read_sysreg(hcr_el2) & HCR_VSE;
183 }
179 184
180 if (has_vhe()) 185 if (has_vhe())
181 deactivate_traps_vhe(); 186 deactivate_traps_vhe();
@@ -229,20 +234,6 @@ static void __hyp_text __hyp_vgic_restore_state(struct kvm_vcpu *vcpu)
229 } 234 }
230} 235}
231 236
232static bool __hyp_text __true_value(void)
233{
234 return true;
235}
236
237static bool __hyp_text __false_value(void)
238{
239 return false;
240}
241
242static hyp_alternate_select(__check_arm_834220,
243 __false_value, __true_value,
244 ARM64_WORKAROUND_834220);
245
246static bool __hyp_text __translate_far_to_hpfar(u64 far, u64 *hpfar) 237static bool __hyp_text __translate_far_to_hpfar(u64 far, u64 *hpfar)
247{ 238{
248 u64 par, tmp; 239 u64 par, tmp;
@@ -298,7 +289,8 @@ static bool __hyp_text __populate_fault_info(struct kvm_vcpu *vcpu)
298 * resolve the IPA using the AT instruction. 289 * resolve the IPA using the AT instruction.
299 */ 290 */
300 if (!(esr & ESR_ELx_S1PTW) && 291 if (!(esr & ESR_ELx_S1PTW) &&
301 (__check_arm_834220()() || (esr & ESR_ELx_FSC_TYPE) == FSC_PERM)) { 292 (cpus_have_const_cap(ARM64_WORKAROUND_834220) ||
293 (esr & ESR_ELx_FSC_TYPE) == FSC_PERM)) {
302 if (!__translate_far_to_hpfar(far, &hpfar)) 294 if (!__translate_far_to_hpfar(far, &hpfar))
303 return false; 295 return false;
304 } else { 296 } else {
@@ -393,6 +385,61 @@ static bool __hyp_text __hyp_handle_fpsimd(struct kvm_vcpu *vcpu)
393 return true; 385 return true;
394} 386}
395 387
388static bool __hyp_text handle_tx2_tvm(struct kvm_vcpu *vcpu)
389{
390 u32 sysreg = esr_sys64_to_sysreg(kvm_vcpu_get_hsr(vcpu));
391 int rt = kvm_vcpu_sys_get_rt(vcpu);
392 u64 val = vcpu_get_reg(vcpu, rt);
393
394 /*
395 * The normal sysreg handling code expects to see the traps,
396 * let's not do anything here.
397 */
398 if (vcpu->arch.hcr_el2 & HCR_TVM)
399 return false;
400
401 switch (sysreg) {
402 case SYS_SCTLR_EL1:
403 write_sysreg_el1(val, SYS_SCTLR);
404 break;
405 case SYS_TTBR0_EL1:
406 write_sysreg_el1(val, SYS_TTBR0);
407 break;
408 case SYS_TTBR1_EL1:
409 write_sysreg_el1(val, SYS_TTBR1);
410 break;
411 case SYS_TCR_EL1:
412 write_sysreg_el1(val, SYS_TCR);
413 break;
414 case SYS_ESR_EL1:
415 write_sysreg_el1(val, SYS_ESR);
416 break;
417 case SYS_FAR_EL1:
418 write_sysreg_el1(val, SYS_FAR);
419 break;
420 case SYS_AFSR0_EL1:
421 write_sysreg_el1(val, SYS_AFSR0);
422 break;
423 case SYS_AFSR1_EL1:
424 write_sysreg_el1(val, SYS_AFSR1);
425 break;
426 case SYS_MAIR_EL1:
427 write_sysreg_el1(val, SYS_MAIR);
428 break;
429 case SYS_AMAIR_EL1:
430 write_sysreg_el1(val, SYS_AMAIR);
431 break;
432 case SYS_CONTEXTIDR_EL1:
433 write_sysreg_el1(val, SYS_CONTEXTIDR);
434 break;
435 default:
436 return false;
437 }
438
439 __kvm_skip_instr(vcpu);
440 return true;
441}
442
396/* 443/*
397 * Return true when we were able to fixup the guest exit and should return to 444 * Return true when we were able to fixup the guest exit and should return to
398 * the guest, false when we should restore the host state and return to the 445 * the guest, false when we should restore the host state and return to the
@@ -412,6 +459,11 @@ static bool __hyp_text fixup_guest_exit(struct kvm_vcpu *vcpu, u64 *exit_code)
412 if (*exit_code != ARM_EXCEPTION_TRAP) 459 if (*exit_code != ARM_EXCEPTION_TRAP)
413 goto exit; 460 goto exit;
414 461
462 if (cpus_have_const_cap(ARM64_WORKAROUND_CAVIUM_TX2_219_TVM) &&
463 kvm_vcpu_trap_get_class(vcpu) == ESR_ELx_EC_SYS64 &&
464 handle_tx2_tvm(vcpu))
465 return true;
466
415 /* 467 /*
416 * We trap the first access to the FP/SIMD to save the host context 468 * We trap the first access to the FP/SIMD to save the host context
417 * and restore the guest context lazily. 469 * and restore the guest context lazily.
diff --git a/arch/arm64/kvm/hyp/tlb.c b/arch/arm64/kvm/hyp/tlb.c
index c466060b76d6..eb0efc5557f3 100644
--- a/arch/arm64/kvm/hyp/tlb.c
+++ b/arch/arm64/kvm/hyp/tlb.c
@@ -67,10 +67,14 @@ static void __hyp_text __tlb_switch_to_guest_nvhe(struct kvm *kvm,
67 isb(); 67 isb();
68} 68}
69 69
70static hyp_alternate_select(__tlb_switch_to_guest, 70static void __hyp_text __tlb_switch_to_guest(struct kvm *kvm,
71 __tlb_switch_to_guest_nvhe, 71 struct tlb_inv_context *cxt)
72 __tlb_switch_to_guest_vhe, 72{
73 ARM64_HAS_VIRT_HOST_EXTN); 73 if (has_vhe())
74 __tlb_switch_to_guest_vhe(kvm, cxt);
75 else
76 __tlb_switch_to_guest_nvhe(kvm, cxt);
77}
74 78
75static void __hyp_text __tlb_switch_to_host_vhe(struct kvm *kvm, 79static void __hyp_text __tlb_switch_to_host_vhe(struct kvm *kvm,
76 struct tlb_inv_context *cxt) 80 struct tlb_inv_context *cxt)
@@ -98,10 +102,14 @@ static void __hyp_text __tlb_switch_to_host_nvhe(struct kvm *kvm,
98 write_sysreg(0, vttbr_el2); 102 write_sysreg(0, vttbr_el2);
99} 103}
100 104
101static hyp_alternate_select(__tlb_switch_to_host, 105static void __hyp_text __tlb_switch_to_host(struct kvm *kvm,
102 __tlb_switch_to_host_nvhe, 106 struct tlb_inv_context *cxt)
103 __tlb_switch_to_host_vhe, 107{
104 ARM64_HAS_VIRT_HOST_EXTN); 108 if (has_vhe())
109 __tlb_switch_to_host_vhe(kvm, cxt);
110 else
111 __tlb_switch_to_host_nvhe(kvm, cxt);
112}
105 113
106void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa) 114void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
107{ 115{
@@ -111,7 +119,7 @@ void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
111 119
112 /* Switch to requested VMID */ 120 /* Switch to requested VMID */
113 kvm = kern_hyp_va(kvm); 121 kvm = kern_hyp_va(kvm);
114 __tlb_switch_to_guest()(kvm, &cxt); 122 __tlb_switch_to_guest(kvm, &cxt);
115 123
116 /* 124 /*
117 * We could do so much better if we had the VA as well. 125 * We could do so much better if we had the VA as well.
@@ -154,7 +162,7 @@ void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
154 if (!has_vhe() && icache_is_vpipt()) 162 if (!has_vhe() && icache_is_vpipt())
155 __flush_icache_all(); 163 __flush_icache_all();
156 164
157 __tlb_switch_to_host()(kvm, &cxt); 165 __tlb_switch_to_host(kvm, &cxt);
158} 166}
159 167
160void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm) 168void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm)
@@ -165,13 +173,13 @@ void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm)
165 173
166 /* Switch to requested VMID */ 174 /* Switch to requested VMID */
167 kvm = kern_hyp_va(kvm); 175 kvm = kern_hyp_va(kvm);
168 __tlb_switch_to_guest()(kvm, &cxt); 176 __tlb_switch_to_guest(kvm, &cxt);
169 177
170 __tlbi(vmalls12e1is); 178 __tlbi(vmalls12e1is);
171 dsb(ish); 179 dsb(ish);
172 isb(); 180 isb();
173 181
174 __tlb_switch_to_host()(kvm, &cxt); 182 __tlb_switch_to_host(kvm, &cxt);
175} 183}
176 184
177void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu) 185void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu)
@@ -180,13 +188,13 @@ void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu)
180 struct tlb_inv_context cxt; 188 struct tlb_inv_context cxt;
181 189
182 /* Switch to requested VMID */ 190 /* Switch to requested VMID */
183 __tlb_switch_to_guest()(kvm, &cxt); 191 __tlb_switch_to_guest(kvm, &cxt);
184 192
185 __tlbi(vmalle1); 193 __tlbi(vmalle1);
186 dsb(nsh); 194 dsb(nsh);
187 isb(); 195 isb();
188 196
189 __tlb_switch_to_host()(kvm, &cxt); 197 __tlb_switch_to_host(kvm, &cxt);
190} 198}
191 199
192void __hyp_text __kvm_flush_vm_context(void) 200void __hyp_text __kvm_flush_vm_context(void)
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index 115d7a0e4b08..9fc6db0bcbad 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -113,6 +113,15 @@ static inline bool is_ttbr1_addr(unsigned long addr)
113 return arch_kasan_reset_tag(addr) >= PAGE_OFFSET; 113 return arch_kasan_reset_tag(addr) >= PAGE_OFFSET;
114} 114}
115 115
116static inline unsigned long mm_to_pgd_phys(struct mm_struct *mm)
117{
118 /* Either init_pg_dir or swapper_pg_dir */
119 if (mm == &init_mm)
120 return __pa_symbol(mm->pgd);
121
122 return (unsigned long)virt_to_phys(mm->pgd);
123}
124
116/* 125/*
117 * Dump out the page tables associated with 'addr' in the currently active mm. 126 * Dump out the page tables associated with 'addr' in the currently active mm.
118 */ 127 */
@@ -141,7 +150,7 @@ static void show_pte(unsigned long addr)
141 150
142 pr_alert("%s pgtable: %luk pages, %llu-bit VAs, pgdp=%016lx\n", 151 pr_alert("%s pgtable: %luk pages, %llu-bit VAs, pgdp=%016lx\n",
143 mm == &init_mm ? "swapper" : "user", PAGE_SIZE / SZ_1K, 152 mm == &init_mm ? "swapper" : "user", PAGE_SIZE / SZ_1K,
144 vabits_actual, (unsigned long)virt_to_phys(mm->pgd)); 153 vabits_actual, mm_to_pgd_phys(mm));
145 pgdp = pgd_offset(mm, addr); 154 pgdp = pgd_offset(mm, addr);
146 pgd = READ_ONCE(*pgdp); 155 pgd = READ_ONCE(*pgdp);
147 pr_alert("[%016lx] pgd=%016llx", addr, pgd_val(pgd)); 156 pr_alert("[%016lx] pgd=%016llx", addr, pgd_val(pgd));
@@ -259,14 +268,18 @@ static bool __kprobes is_spurious_el1_translation_fault(unsigned long addr,
259 par = read_sysreg(par_el1); 268 par = read_sysreg(par_el1);
260 local_irq_restore(flags); 269 local_irq_restore(flags);
261 270
271 /*
272 * If we now have a valid translation, treat the translation fault as
273 * spurious.
274 */
262 if (!(par & SYS_PAR_EL1_F)) 275 if (!(par & SYS_PAR_EL1_F))
263 return false; 276 return true;
264 277
265 /* 278 /*
266 * If we got a different type of fault from the AT instruction, 279 * If we got a different type of fault from the AT instruction,
267 * treat the translation fault as spurious. 280 * treat the translation fault as spurious.
268 */ 281 */
269 dfsc = FIELD_PREP(SYS_PAR_EL1_FST, par); 282 dfsc = FIELD_GET(SYS_PAR_EL1_FST, par);
270 return (dfsc & ESR_ELx_FSC_TYPE) != ESR_ELx_FSC_FAULT; 283 return (dfsc & ESR_ELx_FSC_TYPE) != ESR_ELx_FSC_FAULT;
271} 284}
272 285
diff --git a/arch/arm64/xen/Makefile b/arch/arm64/xen/Makefile
index a4fc65f3928d..b66215e8658e 100644
--- a/arch/arm64/xen/Makefile
+++ b/arch/arm64/xen/Makefile
@@ -1,4 +1,3 @@
1# SPDX-License-Identifier: GPL-2.0-only 1# SPDX-License-Identifier: GPL-2.0-only
2xen-arm-y += $(addprefix ../../arm/xen/, enlighten.o grant-table.o p2m.o mm.o) 2xen-arm-y += $(addprefix ../../arm/xen/, enlighten.o grant-table.o p2m.o mm.o)
3obj-y := xen-arm.o hypercall.o 3obj-y := xen-arm.o hypercall.o
4obj-$(CONFIG_XEN_EFI) += $(addprefix ../../arm/xen/, efi.o)
diff --git a/arch/mips/boot/dts/qca/ar9331.dtsi b/arch/mips/boot/dts/qca/ar9331.dtsi
index 63a9f33aa43e..5cfc9d347826 100644
--- a/arch/mips/boot/dts/qca/ar9331.dtsi
+++ b/arch/mips/boot/dts/qca/ar9331.dtsi
@@ -99,7 +99,7 @@
99 99
100 miscintc: interrupt-controller@18060010 { 100 miscintc: interrupt-controller@18060010 {
101 compatible = "qca,ar7240-misc-intc"; 101 compatible = "qca,ar7240-misc-intc";
102 reg = <0x18060010 0x4>; 102 reg = <0x18060010 0x8>;
103 103
104 interrupt-parent = <&cpuintc>; 104 interrupt-parent = <&cpuintc>;
105 interrupts = <6>; 105 interrupts = <6>;
diff --git a/arch/mips/configs/mtx1_defconfig b/arch/mips/configs/mtx1_defconfig
index 16bef819fe98..914af125a7fa 100644
--- a/arch/mips/configs/mtx1_defconfig
+++ b/arch/mips/configs/mtx1_defconfig
@@ -571,7 +571,6 @@ CONFIG_USB_SERIAL_OMNINET=m
571CONFIG_USB_EMI62=m 571CONFIG_USB_EMI62=m
572CONFIG_USB_EMI26=m 572CONFIG_USB_EMI26=m
573CONFIG_USB_ADUTUX=m 573CONFIG_USB_ADUTUX=m
574CONFIG_USB_RIO500=m
575CONFIG_USB_LEGOTOWER=m 574CONFIG_USB_LEGOTOWER=m
576CONFIG_USB_LCD=m 575CONFIG_USB_LCD=m
577CONFIG_USB_CYPRESS_CY7C63=m 576CONFIG_USB_CYPRESS_CY7C63=m
diff --git a/arch/mips/configs/rm200_defconfig b/arch/mips/configs/rm200_defconfig
index 8762e75f5d5f..2c7adea7638f 100644
--- a/arch/mips/configs/rm200_defconfig
+++ b/arch/mips/configs/rm200_defconfig
@@ -314,7 +314,6 @@ CONFIG_USB_SERIAL_SAFE_PADDED=y
314CONFIG_USB_SERIAL_CYBERJACK=m 314CONFIG_USB_SERIAL_CYBERJACK=m
315CONFIG_USB_SERIAL_XIRCOM=m 315CONFIG_USB_SERIAL_XIRCOM=m
316CONFIG_USB_SERIAL_OMNINET=m 316CONFIG_USB_SERIAL_OMNINET=m
317CONFIG_USB_RIO500=m
318CONFIG_USB_LEGOTOWER=m 317CONFIG_USB_LEGOTOWER=m
319CONFIG_USB_LCD=m 318CONFIG_USB_LCD=m
320CONFIG_USB_CYTHERM=m 319CONFIG_USB_CYTHERM=m
diff --git a/arch/mips/fw/arc/memory.c b/arch/mips/fw/arc/memory.c
index af44b35d79a1..b4328b3b5288 100644
--- a/arch/mips/fw/arc/memory.c
+++ b/arch/mips/fw/arc/memory.c
@@ -160,7 +160,6 @@ void __init prom_meminit(void)
160 160
161void __init prom_free_prom_memory(void) 161void __init prom_free_prom_memory(void)
162{ 162{
163 unsigned long addr;
164 int i; 163 int i;
165 164
166 if (prom_flags & PROM_FLAG_DONT_FREE_TEMP) 165 if (prom_flags & PROM_FLAG_DONT_FREE_TEMP)
diff --git a/arch/mips/fw/sni/sniprom.c b/arch/mips/fw/sni/sniprom.c
index 8772617b64ce..80112f2298b6 100644
--- a/arch/mips/fw/sni/sniprom.c
+++ b/arch/mips/fw/sni/sniprom.c
@@ -43,7 +43,7 @@
43 43
44/* O32 stack has to be 8-byte aligned. */ 44/* O32 stack has to be 8-byte aligned. */
45static u64 o32_stk[4096]; 45static u64 o32_stk[4096];
46#define O32_STK &o32_stk[sizeof(o32_stk)] 46#define O32_STK (&o32_stk[ARRAY_SIZE(o32_stk)])
47 47
48#define __PROM_O32(fun, arg) fun arg __asm__(#fun); \ 48#define __PROM_O32(fun, arg) fun arg __asm__(#fun); \
49 __asm__(#fun " = call_o32") 49 __asm__(#fun " = call_o32")
diff --git a/arch/mips/include/asm/cmpxchg.h b/arch/mips/include/asm/cmpxchg.h
index 79bf34efbc04..f6136871561d 100644
--- a/arch/mips/include/asm/cmpxchg.h
+++ b/arch/mips/include/asm/cmpxchg.h
@@ -77,8 +77,8 @@ extern unsigned long __xchg_called_with_bad_pointer(void)
77extern unsigned long __xchg_small(volatile void *ptr, unsigned long val, 77extern unsigned long __xchg_small(volatile void *ptr, unsigned long val,
78 unsigned int size); 78 unsigned int size);
79 79
80static inline unsigned long __xchg(volatile void *ptr, unsigned long x, 80static __always_inline
81 int size) 81unsigned long __xchg(volatile void *ptr, unsigned long x, int size)
82{ 82{
83 switch (size) { 83 switch (size) {
84 case 1: 84 case 1:
@@ -153,8 +153,9 @@ static inline unsigned long __xchg(volatile void *ptr, unsigned long x,
153extern unsigned long __cmpxchg_small(volatile void *ptr, unsigned long old, 153extern unsigned long __cmpxchg_small(volatile void *ptr, unsigned long old,
154 unsigned long new, unsigned int size); 154 unsigned long new, unsigned int size);
155 155
156static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, 156static __always_inline
157 unsigned long new, unsigned int size) 157unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
158 unsigned long new, unsigned int size)
158{ 159{
159 switch (size) { 160 switch (size) {
160 case 1: 161 case 1:
diff --git a/arch/mips/include/asm/octeon/cvmx-ipd.h b/arch/mips/include/asm/octeon/cvmx-ipd.h
index cbdc14b77435..adab7b54c3b4 100644
--- a/arch/mips/include/asm/octeon/cvmx-ipd.h
+++ b/arch/mips/include/asm/octeon/cvmx-ipd.h
@@ -36,6 +36,7 @@
36#include <asm/octeon/octeon-feature.h> 36#include <asm/octeon/octeon-feature.h>
37 37
38#include <asm/octeon/cvmx-ipd-defs.h> 38#include <asm/octeon/cvmx-ipd-defs.h>
39#include <asm/octeon/cvmx-pip-defs.h>
39 40
40enum cvmx_ipd_mode { 41enum cvmx_ipd_mode {
41 CVMX_IPD_OPC_MODE_STT = 0LL, /* All blocks DRAM, not cached in L2 */ 42 CVMX_IPD_OPC_MODE_STT = 0LL, /* All blocks DRAM, not cached in L2 */
diff --git a/arch/mips/include/asm/unistd.h b/arch/mips/include/asm/unistd.h
index 071053ece677..5d70babfc9ee 100644
--- a/arch/mips/include/asm/unistd.h
+++ b/arch/mips/include/asm/unistd.h
@@ -52,6 +52,7 @@
52# endif 52# endif
53#define __ARCH_WANT_SYS_FORK 53#define __ARCH_WANT_SYS_FORK
54#define __ARCH_WANT_SYS_CLONE 54#define __ARCH_WANT_SYS_CLONE
55#define __ARCH_WANT_SYS_CLONE3
55 56
56/* whitelists for checksyscalls */ 57/* whitelists for checksyscalls */
57#define __IGNORE_fadvise64_64 58#define __IGNORE_fadvise64_64
diff --git a/arch/mips/include/uapi/asm/hwcap.h b/arch/mips/include/uapi/asm/hwcap.h
index a2aba4b059e6..1ade1daa4921 100644
--- a/arch/mips/include/uapi/asm/hwcap.h
+++ b/arch/mips/include/uapi/asm/hwcap.h
@@ -6,5 +6,16 @@
6#define HWCAP_MIPS_R6 (1 << 0) 6#define HWCAP_MIPS_R6 (1 << 0)
7#define HWCAP_MIPS_MSA (1 << 1) 7#define HWCAP_MIPS_MSA (1 << 1)
8#define HWCAP_MIPS_CRC32 (1 << 2) 8#define HWCAP_MIPS_CRC32 (1 << 2)
9#define HWCAP_MIPS_MIPS16 (1 << 3)
10#define HWCAP_MIPS_MDMX (1 << 4)
11#define HWCAP_MIPS_MIPS3D (1 << 5)
12#define HWCAP_MIPS_SMARTMIPS (1 << 6)
13#define HWCAP_MIPS_DSP (1 << 7)
14#define HWCAP_MIPS_DSP2 (1 << 8)
15#define HWCAP_MIPS_DSP3 (1 << 9)
16#define HWCAP_MIPS_MIPS16E2 (1 << 10)
17#define HWCAP_LOONGSON_MMI (1 << 11)
18#define HWCAP_LOONGSON_EXT (1 << 12)
19#define HWCAP_LOONGSON_EXT2 (1 << 13)
9 20
10#endif /* _UAPI_ASM_HWCAP_H */ 21#endif /* _UAPI_ASM_HWCAP_H */
diff --git a/arch/mips/kernel/cpu-bugs64.c b/arch/mips/kernel/cpu-bugs64.c
index fa62cd1dff93..6a7afe7ef4d3 100644
--- a/arch/mips/kernel/cpu-bugs64.c
+++ b/arch/mips/kernel/cpu-bugs64.c
@@ -24,7 +24,8 @@ static char r4kwar[] __initdata =
24static char daddiwar[] __initdata = 24static char daddiwar[] __initdata =
25 "Enable CPU_DADDI_WORKAROUNDS to rectify."; 25 "Enable CPU_DADDI_WORKAROUNDS to rectify.";
26 26
27static inline void align_mod(const int align, const int mod) 27static __always_inline __init
28void align_mod(const int align, const int mod)
28{ 29{
29 asm volatile( 30 asm volatile(
30 ".set push\n\t" 31 ".set push\n\t"
@@ -38,8 +39,9 @@ static inline void align_mod(const int align, const int mod)
38 : "n"(align), "n"(mod)); 39 : "n"(align), "n"(mod));
39} 40}
40 41
41static __always_inline void mult_sh_align_mod(long *v1, long *v2, long *w, 42static __always_inline __init
42 const int align, const int mod) 43void mult_sh_align_mod(long *v1, long *v2, long *w,
44 const int align, const int mod)
43{ 45{
44 unsigned long flags; 46 unsigned long flags;
45 int m1, m2; 47 int m1, m2;
@@ -113,7 +115,7 @@ static __always_inline void mult_sh_align_mod(long *v1, long *v2, long *w,
113 *w = lw; 115 *w = lw;
114} 116}
115 117
116static inline void check_mult_sh(void) 118static __always_inline __init void check_mult_sh(void)
117{ 119{
118 long v1[8], v2[8], w[8]; 120 long v1[8], v2[8], w[8];
119 int bug, fix, i; 121 int bug, fix, i;
@@ -176,7 +178,7 @@ asmlinkage void __init do_daddi_ov(struct pt_regs *regs)
176 exception_exit(prev_state); 178 exception_exit(prev_state);
177} 179}
178 180
179static inline void check_daddi(void) 181static __init void check_daddi(void)
180{ 182{
181 extern asmlinkage void handle_daddi_ov(void); 183 extern asmlinkage void handle_daddi_ov(void);
182 unsigned long flags; 184 unsigned long flags;
@@ -242,7 +244,7 @@ static inline void check_daddi(void)
242 244
243int daddiu_bug = IS_ENABLED(CONFIG_CPU_MIPSR6) ? 0 : -1; 245int daddiu_bug = IS_ENABLED(CONFIG_CPU_MIPSR6) ? 0 : -1;
244 246
245static inline void check_daddiu(void) 247static __init void check_daddiu(void)
246{ 248{
247 long v, w, tmp; 249 long v, w, tmp;
248 250
diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c
index c2eb392597bf..f521cbf934e7 100644
--- a/arch/mips/kernel/cpu-probe.c
+++ b/arch/mips/kernel/cpu-probe.c
@@ -2180,6 +2180,39 @@ void cpu_probe(void)
2180 elf_hwcap |= HWCAP_MIPS_MSA; 2180 elf_hwcap |= HWCAP_MIPS_MSA;
2181 } 2181 }
2182 2182
2183 if (cpu_has_mips16)
2184 elf_hwcap |= HWCAP_MIPS_MIPS16;
2185
2186 if (cpu_has_mdmx)
2187 elf_hwcap |= HWCAP_MIPS_MDMX;
2188
2189 if (cpu_has_mips3d)
2190 elf_hwcap |= HWCAP_MIPS_MIPS3D;
2191
2192 if (cpu_has_smartmips)
2193 elf_hwcap |= HWCAP_MIPS_SMARTMIPS;
2194
2195 if (cpu_has_dsp)
2196 elf_hwcap |= HWCAP_MIPS_DSP;
2197
2198 if (cpu_has_dsp2)
2199 elf_hwcap |= HWCAP_MIPS_DSP2;
2200
2201 if (cpu_has_dsp3)
2202 elf_hwcap |= HWCAP_MIPS_DSP3;
2203
2204 if (cpu_has_mips16e2)
2205 elf_hwcap |= HWCAP_MIPS_MIPS16E2;
2206
2207 if (cpu_has_loongson_mmi)
2208 elf_hwcap |= HWCAP_LOONGSON_MMI;
2209
2210 if (cpu_has_loongson_ext)
2211 elf_hwcap |= HWCAP_LOONGSON_EXT;
2212
2213 if (cpu_has_loongson_ext2)
2214 elf_hwcap |= HWCAP_LOONGSON_EXT2;
2215
2183 if (cpu_has_vz) 2216 if (cpu_has_vz)
2184 cpu_probe_vz(c); 2217 cpu_probe_vz(c);
2185 2218
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index b8249c233754..5eec13b8d222 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -108,6 +108,9 @@ void __init add_memory_region(phys_addr_t start, phys_addr_t size, long type)
108 return; 108 return;
109 } 109 }
110 110
111 if (start < PHYS_OFFSET)
112 return;
113
111 memblock_add(start, size); 114 memblock_add(start, size);
112 /* Reserve any memory except the ordinary RAM ranges. */ 115 /* Reserve any memory except the ordinary RAM ranges. */
113 switch (type) { 116 switch (type) {
@@ -321,7 +324,7 @@ static void __init bootmem_init(void)
321 * Reserve any memory between the start of RAM and PHYS_OFFSET 324 * Reserve any memory between the start of RAM and PHYS_OFFSET
322 */ 325 */
323 if (ramstart > PHYS_OFFSET) 326 if (ramstart > PHYS_OFFSET)
324 memblock_reserve(PHYS_OFFSET, PFN_UP(ramstart) - PHYS_OFFSET); 327 memblock_reserve(PHYS_OFFSET, ramstart - PHYS_OFFSET);
325 328
326 if (PFN_UP(ramstart) > ARCH_PFN_OFFSET) { 329 if (PFN_UP(ramstart) > ARCH_PFN_OFFSET) {
327 pr_info("Wasting %lu bytes for tracking %lu unused pages\n", 330 pr_info("Wasting %lu bytes for tracking %lu unused pages\n",
diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c
index b0e25e913bdb..3f16f3823031 100644
--- a/arch/mips/kernel/syscall.c
+++ b/arch/mips/kernel/syscall.c
@@ -80,6 +80,7 @@ SYSCALL_DEFINE6(mips_mmap2, unsigned long, addr, unsigned long, len,
80 80
81save_static_function(sys_fork); 81save_static_function(sys_fork);
82save_static_function(sys_clone); 82save_static_function(sys_clone);
83save_static_function(sys_clone3);
83 84
84SYSCALL_DEFINE1(set_thread_area, unsigned long, addr) 85SYSCALL_DEFINE1(set_thread_area, unsigned long, addr)
85{ 86{
diff --git a/arch/mips/kernel/syscalls/syscall_n32.tbl b/arch/mips/kernel/syscalls/syscall_n32.tbl
index c9c879ec9b6d..e7c5ab38e403 100644
--- a/arch/mips/kernel/syscalls/syscall_n32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_n32.tbl
@@ -373,4 +373,4 @@
373432 n32 fsmount sys_fsmount 373432 n32 fsmount sys_fsmount
374433 n32 fspick sys_fspick 374433 n32 fspick sys_fspick
375434 n32 pidfd_open sys_pidfd_open 375434 n32 pidfd_open sys_pidfd_open
376# 435 reserved for clone3 376435 n32 clone3 __sys_clone3
diff --git a/arch/mips/kernel/syscalls/syscall_n64.tbl b/arch/mips/kernel/syscalls/syscall_n64.tbl
index bbce9159caa1..13cd66581f3b 100644
--- a/arch/mips/kernel/syscalls/syscall_n64.tbl
+++ b/arch/mips/kernel/syscalls/syscall_n64.tbl
@@ -349,4 +349,4 @@
349432 n64 fsmount sys_fsmount 349432 n64 fsmount sys_fsmount
350433 n64 fspick sys_fspick 350433 n64 fspick sys_fspick
351434 n64 pidfd_open sys_pidfd_open 351434 n64 pidfd_open sys_pidfd_open
352# 435 reserved for clone3 352435 n64 clone3 __sys_clone3
diff --git a/arch/mips/kernel/syscalls/syscall_o32.tbl b/arch/mips/kernel/syscalls/syscall_o32.tbl
index 9653591428ec..353539ea4140 100644
--- a/arch/mips/kernel/syscalls/syscall_o32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_o32.tbl
@@ -422,4 +422,4 @@
422432 o32 fsmount sys_fsmount 422432 o32 fsmount sys_fsmount
423433 o32 fspick sys_fspick 423433 o32 fspick sys_fspick
424434 o32 pidfd_open sys_pidfd_open 424434 o32 pidfd_open sys_pidfd_open
425# 435 reserved for clone3 425435 o32 clone3 __sys_clone3
diff --git a/arch/mips/loongson64/Platform b/arch/mips/loongson64/Platform
index c1a4d4dc4665..9f79908f5063 100644
--- a/arch/mips/loongson64/Platform
+++ b/arch/mips/loongson64/Platform
@@ -66,6 +66,10 @@ else
66 $(call cc-option,-march=mips64r2,-mips64r2 -U_MIPS_ISA -D_MIPS_ISA=_MIPS_ISA_MIPS64) 66 $(call cc-option,-march=mips64r2,-mips64r2 -U_MIPS_ISA -D_MIPS_ISA=_MIPS_ISA_MIPS64)
67endif 67endif
68 68
69# Some -march= flags enable MMI instructions, and GCC complains about that
70# support being enabled alongside -msoft-float. Thus explicitly disable MMI.
71cflags-y += $(call cc-option,-mno-loongson-mmi)
72
69# 73#
70# Loongson Machines' Support 74# Loongson Machines' Support
71# 75#
diff --git a/arch/mips/loongson64/common/mem.c b/arch/mips/loongson64/common/mem.c
index 4abb92e0fc39..4254ac4ec616 100644
--- a/arch/mips/loongson64/common/mem.c
+++ b/arch/mips/loongson64/common/mem.c
@@ -3,6 +3,7 @@
3 */ 3 */
4#include <linux/fs.h> 4#include <linux/fs.h>
5#include <linux/fcntl.h> 5#include <linux/fcntl.h>
6#include <linux/memblock.h>
6#include <linux/mm.h> 7#include <linux/mm.h>
7 8
8#include <asm/bootinfo.h> 9#include <asm/bootinfo.h>
@@ -64,24 +65,22 @@ void __init prom_init_memory(void)
64 node_id = loongson_memmap->map[i].node_id; 65 node_id = loongson_memmap->map[i].node_id;
65 mem_type = loongson_memmap->map[i].mem_type; 66 mem_type = loongson_memmap->map[i].mem_type;
66 67
67 if (node_id == 0) { 68 if (node_id != 0)
68 switch (mem_type) { 69 continue;
69 case SYSTEM_RAM_LOW: 70
70 add_memory_region(loongson_memmap->map[i].mem_start, 71 switch (mem_type) {
71 (u64)loongson_memmap->map[i].mem_size << 20, 72 case SYSTEM_RAM_LOW:
72 BOOT_MEM_RAM); 73 memblock_add(loongson_memmap->map[i].mem_start,
73 break; 74 (u64)loongson_memmap->map[i].mem_size << 20);
74 case SYSTEM_RAM_HIGH: 75 break;
75 add_memory_region(loongson_memmap->map[i].mem_start, 76 case SYSTEM_RAM_HIGH:
76 (u64)loongson_memmap->map[i].mem_size << 20, 77 memblock_add(loongson_memmap->map[i].mem_start,
77 BOOT_MEM_RAM); 78 (u64)loongson_memmap->map[i].mem_size << 20);
78 break; 79 break;
79 case SYSTEM_RAM_RESERVED: 80 case SYSTEM_RAM_RESERVED:
80 add_memory_region(loongson_memmap->map[i].mem_start, 81 memblock_reserve(loongson_memmap->map[i].mem_start,
81 (u64)loongson_memmap->map[i].mem_size << 20, 82 (u64)loongson_memmap->map[i].mem_size << 20);
82 BOOT_MEM_RESERVED); 83 break;
83 break;
84 }
85 } 84 }
86 } 85 }
87} 86}
diff --git a/arch/mips/loongson64/common/serial.c b/arch/mips/loongson64/common/serial.c
index ffefc1cb2612..98c3a7feb10f 100644
--- a/arch/mips/loongson64/common/serial.c
+++ b/arch/mips/loongson64/common/serial.c
@@ -110,7 +110,7 @@ static int __init serial_init(void)
110} 110}
111module_init(serial_init); 111module_init(serial_init);
112 112
113static void __init serial_exit(void) 113static void __exit serial_exit(void)
114{ 114{
115 platform_device_unregister(&uart8250_device); 115 platform_device_unregister(&uart8250_device);
116} 116}
diff --git a/arch/mips/loongson64/loongson-3/numa.c b/arch/mips/loongson64/loongson-3/numa.c
index 414e97de5dc0..8f20d2cb3767 100644
--- a/arch/mips/loongson64/loongson-3/numa.c
+++ b/arch/mips/loongson64/loongson-3/numa.c
@@ -142,8 +142,6 @@ static void __init szmem(unsigned int node)
142 (u32)node_id, mem_type, mem_start, mem_size); 142 (u32)node_id, mem_type, mem_start, mem_size);
143 pr_info(" start_pfn:0x%llx, end_pfn:0x%llx, num_physpages:0x%lx\n", 143 pr_info(" start_pfn:0x%llx, end_pfn:0x%llx, num_physpages:0x%lx\n",
144 start_pfn, end_pfn, num_physpages); 144 start_pfn, end_pfn, num_physpages);
145 add_memory_region((node_id << 44) + mem_start,
146 (u64)mem_size << 20, BOOT_MEM_RAM);
147 memblock_add_node(PFN_PHYS(start_pfn), 145 memblock_add_node(PFN_PHYS(start_pfn),
148 PFN_PHYS(end_pfn - start_pfn), node); 146 PFN_PHYS(end_pfn - start_pfn), node);
149 break; 147 break;
@@ -156,16 +154,12 @@ static void __init szmem(unsigned int node)
156 (u32)node_id, mem_type, mem_start, mem_size); 154 (u32)node_id, mem_type, mem_start, mem_size);
157 pr_info(" start_pfn:0x%llx, end_pfn:0x%llx, num_physpages:0x%lx\n", 155 pr_info(" start_pfn:0x%llx, end_pfn:0x%llx, num_physpages:0x%lx\n",
158 start_pfn, end_pfn, num_physpages); 156 start_pfn, end_pfn, num_physpages);
159 add_memory_region((node_id << 44) + mem_start,
160 (u64)mem_size << 20, BOOT_MEM_RAM);
161 memblock_add_node(PFN_PHYS(start_pfn), 157 memblock_add_node(PFN_PHYS(start_pfn),
162 PFN_PHYS(end_pfn - start_pfn), node); 158 PFN_PHYS(end_pfn - start_pfn), node);
163 break; 159 break;
164 case SYSTEM_RAM_RESERVED: 160 case SYSTEM_RAM_RESERVED:
165 pr_info("Node%d: mem_type:%d, mem_start:0x%llx, mem_size:0x%llx MB\n", 161 pr_info("Node%d: mem_type:%d, mem_start:0x%llx, mem_size:0x%llx MB\n",
166 (u32)node_id, mem_type, mem_start, mem_size); 162 (u32)node_id, mem_type, mem_start, mem_size);
167 add_memory_region((node_id << 44) + mem_start,
168 (u64)mem_size << 20, BOOT_MEM_RESERVED);
169 memblock_reserve(((node_id << 44) + mem_start), 163 memblock_reserve(((node_id << 44) + mem_start),
170 mem_size << 20); 164 mem_size << 20);
171 break; 165 break;
@@ -191,8 +185,6 @@ static void __init node_mem_init(unsigned int node)
191 NODE_DATA(node)->node_start_pfn = start_pfn; 185 NODE_DATA(node)->node_start_pfn = start_pfn;
192 NODE_DATA(node)->node_spanned_pages = end_pfn - start_pfn; 186 NODE_DATA(node)->node_spanned_pages = end_pfn - start_pfn;
193 187
194 free_bootmem_with_active_regions(node, end_pfn);
195
196 if (node == 0) { 188 if (node == 0) {
197 /* kernel end address */ 189 /* kernel end address */
198 unsigned long kernel_end_pfn = PFN_UP(__pa_symbol(&_end)); 190 unsigned long kernel_end_pfn = PFN_UP(__pa_symbol(&_end));
@@ -209,8 +201,6 @@ static void __init node_mem_init(unsigned int node)
209 memblock_reserve((node_addrspace_offset | 0xfe000000), 201 memblock_reserve((node_addrspace_offset | 0xfe000000),
210 32 << 20); 202 32 << 20);
211 } 203 }
212
213 sparse_memory_present_with_active_regions(node);
214} 204}
215 205
216static __init void prom_meminit(void) 206static __init void prom_meminit(void)
@@ -227,6 +217,7 @@ static __init void prom_meminit(void)
227 cpumask_clear(&__node_data[(node)]->cpumask); 217 cpumask_clear(&__node_data[(node)]->cpumask);
228 } 218 }
229 } 219 }
220 memblocks_present();
230 max_low_pfn = PHYS_PFN(memblock_end_of_DRAM()); 221 max_low_pfn = PHYS_PFN(memblock_end_of_DRAM());
231 222
232 for (cpu = 0; cpu < loongson_sysconf.nr_cpus; cpu++) { 223 for (cpu = 0; cpu < loongson_sysconf.nr_cpus; cpu++) {
diff --git a/arch/mips/pmcs-msp71xx/msp_prom.c b/arch/mips/pmcs-msp71xx/msp_prom.c
index dfb527961a27..800a21b8b8b0 100644
--- a/arch/mips/pmcs-msp71xx/msp_prom.c
+++ b/arch/mips/pmcs-msp71xx/msp_prom.c
@@ -61,6 +61,7 @@ int init_debug = 1;
61/* memory blocks */ 61/* memory blocks */
62struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS]; 62struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
63 63
64#define MAX_PROM_MEM 5
64static phys_addr_t prom_mem_base[MAX_PROM_MEM] __initdata; 65static phys_addr_t prom_mem_base[MAX_PROM_MEM] __initdata;
65static phys_addr_t prom_mem_size[MAX_PROM_MEM] __initdata; 66static phys_addr_t prom_mem_size[MAX_PROM_MEM] __initdata;
66static unsigned int nr_prom_mem __initdata; 67static unsigned int nr_prom_mem __initdata;
@@ -358,7 +359,7 @@ void __init prom_meminit(void)
358 p++; 359 p++;
359 360
360 if (type == BOOT_MEM_ROM_DATA) { 361 if (type == BOOT_MEM_ROM_DATA) {
361 if (nr_prom_mem >= 5) { 362 if (nr_prom_mem >= MAX_PROM_MEM) {
362 pr_err("Too many ROM DATA regions"); 363 pr_err("Too many ROM DATA regions");
363 continue; 364 continue;
364 } 365 }
@@ -377,7 +378,6 @@ void __init prom_free_prom_memory(void)
377 char *ptr; 378 char *ptr;
378 int len = 0; 379 int len = 0;
379 int i; 380 int i;
380 unsigned long addr;
381 381
382 /* 382 /*
383 * preserve environment variables and command line from pmon/bbload 383 * preserve environment variables and command line from pmon/bbload
diff --git a/arch/mips/vdso/Makefile b/arch/mips/vdso/Makefile
index 69cfa0a5339e..996a934ece7d 100644
--- a/arch/mips/vdso/Makefile
+++ b/arch/mips/vdso/Makefile
@@ -15,6 +15,7 @@ ccflags-vdso := \
15 $(filter -mmicromips,$(KBUILD_CFLAGS)) \ 15 $(filter -mmicromips,$(KBUILD_CFLAGS)) \
16 $(filter -march=%,$(KBUILD_CFLAGS)) \ 16 $(filter -march=%,$(KBUILD_CFLAGS)) \
17 $(filter -m%-float,$(KBUILD_CFLAGS)) \ 17 $(filter -m%-float,$(KBUILD_CFLAGS)) \
18 $(filter -mno-loongson-%,$(KBUILD_CFLAGS)) \
18 -D__VDSO__ 19 -D__VDSO__
19 20
20ifdef CONFIG_CC_IS_CLANG 21ifdef CONFIG_CC_IS_CLANG
@@ -59,7 +60,7 @@ CFLAGS_REMOVE_vgettimeofday.o = -pg
59ifndef CONFIG_CPU_MIPSR6 60ifndef CONFIG_CPU_MIPSR6
60 ifeq ($(call ld-ifversion, -lt, 225000000, y),y) 61 ifeq ($(call ld-ifversion, -lt, 225000000, y),y)
61 $(warning MIPS VDSO requires binutils >= 2.25) 62 $(warning MIPS VDSO requires binutils >= 2.25)
62 obj-vdso-y := $(filter-out gettimeofday.o, $(obj-vdso-y)) 63 obj-vdso-y := $(filter-out vgettimeofday.o, $(obj-vdso-y))
63 ccflags-vdso += -DDISABLE_MIPS_VDSO 64 ccflags-vdso += -DDISABLE_MIPS_VDSO
64 endif 65 endif
65endif 66endif
diff --git a/arch/mips/vdso/gettimeofday.c b/arch/mips/vdso/gettimeofday.c
deleted file mode 100644
index e8243c7fd5b5..000000000000
--- a/arch/mips/vdso/gettimeofday.c
+++ /dev/null
@@ -1,269 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (C) 2015 Imagination Technologies
4 * Author: Alex Smith <alex.smith@imgtec.com>
5 */
6
7#include "vdso.h"
8
9#include <linux/compiler.h>
10#include <linux/time.h>
11
12#include <asm/clocksource.h>
13#include <asm/io.h>
14#include <asm/unistd.h>
15#include <asm/vdso.h>
16
17#ifdef CONFIG_MIPS_CLOCK_VSYSCALL
18
19static __always_inline long gettimeofday_fallback(struct timeval *_tv,
20 struct timezone *_tz)
21{
22 register struct timezone *tz asm("a1") = _tz;
23 register struct timeval *tv asm("a0") = _tv;
24 register long ret asm("v0");
25 register long nr asm("v0") = __NR_gettimeofday;
26 register long error asm("a3");
27
28 asm volatile(
29 " syscall\n"
30 : "=r" (ret), "=r" (error)
31 : "r" (tv), "r" (tz), "r" (nr)
32 : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13",
33 "$14", "$15", "$24", "$25", "hi", "lo", "memory");
34
35 return error ? -ret : ret;
36}
37
38#endif
39
40static __always_inline long clock_gettime_fallback(clockid_t _clkid,
41 struct timespec *_ts)
42{
43 register struct timespec *ts asm("a1") = _ts;
44 register clockid_t clkid asm("a0") = _clkid;
45 register long ret asm("v0");
46 register long nr asm("v0") = __NR_clock_gettime;
47 register long error asm("a3");
48
49 asm volatile(
50 " syscall\n"
51 : "=r" (ret), "=r" (error)
52 : "r" (clkid), "r" (ts), "r" (nr)
53 : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13",
54 "$14", "$15", "$24", "$25", "hi", "lo", "memory");
55
56 return error ? -ret : ret;
57}
58
59static __always_inline int do_realtime_coarse(struct timespec *ts,
60 const union mips_vdso_data *data)
61{
62 u32 start_seq;
63
64 do {
65 start_seq = vdso_data_read_begin(data);
66
67 ts->tv_sec = data->xtime_sec;
68 ts->tv_nsec = data->xtime_nsec >> data->cs_shift;
69 } while (vdso_data_read_retry(data, start_seq));
70
71 return 0;
72}
73
74static __always_inline int do_monotonic_coarse(struct timespec *ts,
75 const union mips_vdso_data *data)
76{
77 u32 start_seq;
78 u64 to_mono_sec;
79 u64 to_mono_nsec;
80
81 do {
82 start_seq = vdso_data_read_begin(data);
83
84 ts->tv_sec = data->xtime_sec;
85 ts->tv_nsec = data->xtime_nsec >> data->cs_shift;
86
87 to_mono_sec = data->wall_to_mono_sec;
88 to_mono_nsec = data->wall_to_mono_nsec;
89 } while (vdso_data_read_retry(data, start_seq));
90
91 ts->tv_sec += to_mono_sec;
92 timespec_add_ns(ts, to_mono_nsec);
93
94 return 0;
95}
96
97#ifdef CONFIG_CSRC_R4K
98
99static __always_inline u64 read_r4k_count(void)
100{
101 unsigned int count;
102
103 __asm__ __volatile__(
104 " .set push\n"
105 " .set mips32r2\n"
106 " rdhwr %0, $2\n"
107 " .set pop\n"
108 : "=r" (count));
109
110 return count;
111}
112
113#endif
114
115#ifdef CONFIG_CLKSRC_MIPS_GIC
116
117static __always_inline u64 read_gic_count(const union mips_vdso_data *data)
118{
119 void __iomem *gic = get_gic(data);
120 u32 hi, hi2, lo;
121
122 do {
123 hi = __raw_readl(gic + sizeof(lo));
124 lo = __raw_readl(gic);
125 hi2 = __raw_readl(gic + sizeof(lo));
126 } while (hi2 != hi);
127
128 return (((u64)hi) << 32) + lo;
129}
130
131#endif
132
133static __always_inline u64 get_ns(const union mips_vdso_data *data)
134{
135 u64 cycle_now, delta, nsec;
136
137 switch (data->clock_mode) {
138#ifdef CONFIG_CSRC_R4K
139 case VDSO_CLOCK_R4K:
140 cycle_now = read_r4k_count();
141 break;
142#endif
143#ifdef CONFIG_CLKSRC_MIPS_GIC
144 case VDSO_CLOCK_GIC:
145 cycle_now = read_gic_count(data);
146 break;
147#endif
148 default:
149 return 0;
150 }
151
152 delta = (cycle_now - data->cs_cycle_last) & data->cs_mask;
153
154 nsec = (delta * data->cs_mult) + data->xtime_nsec;
155 nsec >>= data->cs_shift;
156
157 return nsec;
158}
159
160static __always_inline int do_realtime(struct timespec *ts,
161 const union mips_vdso_data *data)
162{
163 u32 start_seq;
164 u64 ns;
165
166 do {
167 start_seq = vdso_data_read_begin(data);
168
169 if (data->clock_mode == VDSO_CLOCK_NONE)
170 return -ENOSYS;
171
172 ts->tv_sec = data->xtime_sec;
173 ns = get_ns(data);
174 } while (vdso_data_read_retry(data, start_seq));
175
176 ts->tv_nsec = 0;
177 timespec_add_ns(ts, ns);
178
179 return 0;
180}
181
182static __always_inline int do_monotonic(struct timespec *ts,
183 const union mips_vdso_data *data)
184{
185 u32 start_seq;
186 u64 ns;
187 u64 to_mono_sec;
188 u64 to_mono_nsec;
189
190 do {
191 start_seq = vdso_data_read_begin(data);
192
193 if (data->clock_mode == VDSO_CLOCK_NONE)
194 return -ENOSYS;
195
196 ts->tv_sec = data->xtime_sec;
197 ns = get_ns(data);
198
199 to_mono_sec = data->wall_to_mono_sec;
200 to_mono_nsec = data->wall_to_mono_nsec;
201 } while (vdso_data_read_retry(data, start_seq));
202
203 ts->tv_sec += to_mono_sec;
204 ts->tv_nsec = 0;
205 timespec_add_ns(ts, ns + to_mono_nsec);
206
207 return 0;
208}
209
210#ifdef CONFIG_MIPS_CLOCK_VSYSCALL
211
212/*
213 * This is behind the ifdef so that we don't provide the symbol when there's no
214 * possibility of there being a usable clocksource, because there's nothing we
215 * can do without it. When libc fails the symbol lookup it should fall back on
216 * the standard syscall path.
217 */
218int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
219{
220 const union mips_vdso_data *data = get_vdso_data();
221 struct timespec ts;
222 int ret;
223
224 ret = do_realtime(&ts, data);
225 if (ret)
226 return gettimeofday_fallback(tv, tz);
227
228 if (tv) {
229 tv->tv_sec = ts.tv_sec;
230 tv->tv_usec = ts.tv_nsec / 1000;
231 }
232
233 if (tz) {
234 tz->tz_minuteswest = data->tz_minuteswest;
235 tz->tz_dsttime = data->tz_dsttime;
236 }
237
238 return 0;
239}
240
241#endif /* CONFIG_MIPS_CLOCK_VSYSCALL */
242
243int __vdso_clock_gettime(clockid_t clkid, struct timespec *ts)
244{
245 const union mips_vdso_data *data = get_vdso_data();
246 int ret = -1;
247
248 switch (clkid) {
249 case CLOCK_REALTIME_COARSE:
250 ret = do_realtime_coarse(ts, data);
251 break;
252 case CLOCK_MONOTONIC_COARSE:
253 ret = do_monotonic_coarse(ts, data);
254 break;
255 case CLOCK_REALTIME:
256 ret = do_realtime(ts, data);
257 break;
258 case CLOCK_MONOTONIC:
259 ret = do_monotonic(ts, data);
260 break;
261 default:
262 break;
263 }
264
265 if (ret)
266 ret = clock_gettime_fallback(clkid, ts);
267
268 return ret;
269}
diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
index 73ca89a47f49..e5de3f897633 100644
--- a/arch/parisc/include/asm/cache.h
+++ b/arch/parisc/include/asm/cache.h
@@ -22,7 +22,7 @@
22 22
23#define ARCH_DMA_MINALIGN L1_CACHE_BYTES 23#define ARCH_DMA_MINALIGN L1_CACHE_BYTES
24 24
25#define __read_mostly __attribute__((__section__(".data..read_mostly"))) 25#define __read_mostly __section(.data..read_mostly)
26 26
27void parisc_cache_init(void); /* initializes cache-flushing */ 27void parisc_cache_init(void); /* initializes cache-flushing */
28void disable_sr_hashing_asm(int); /* low level support for above */ 28void disable_sr_hashing_asm(int); /* low level support for above */
diff --git a/arch/parisc/include/asm/ldcw.h b/arch/parisc/include/asm/ldcw.h
index 3eb4bfc1fb36..e080143e79a3 100644
--- a/arch/parisc/include/asm/ldcw.h
+++ b/arch/parisc/include/asm/ldcw.h
@@ -52,7 +52,7 @@
52}) 52})
53 53
54#ifdef CONFIG_SMP 54#ifdef CONFIG_SMP
55# define __lock_aligned __attribute__((__section__(".data..lock_aligned"))) 55# define __lock_aligned __section(.data..lock_aligned)
56#endif 56#endif
57 57
58#endif /* __PARISC_LDCW_H */ 58#endif /* __PARISC_LDCW_H */
diff --git a/arch/parisc/mm/ioremap.c b/arch/parisc/mm/ioremap.c
index 92a9b5f12f98..f29f682352f0 100644
--- a/arch/parisc/mm/ioremap.c
+++ b/arch/parisc/mm/ioremap.c
@@ -3,7 +3,7 @@
3 * arch/parisc/mm/ioremap.c 3 * arch/parisc/mm/ioremap.c
4 * 4 *
5 * (C) Copyright 1995 1996 Linus Torvalds 5 * (C) Copyright 1995 1996 Linus Torvalds
6 * (C) Copyright 2001-2006 Helge Deller <deller@gmx.de> 6 * (C) Copyright 2001-2019 Helge Deller <deller@gmx.de>
7 * (C) Copyright 2005 Kyle McMartin <kyle@parisc-linux.org> 7 * (C) Copyright 2005 Kyle McMartin <kyle@parisc-linux.org>
8 */ 8 */
9 9
@@ -84,7 +84,7 @@ void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned l
84 addr = (void __iomem *) area->addr; 84 addr = (void __iomem *) area->addr;
85 if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size, 85 if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
86 phys_addr, pgprot)) { 86 phys_addr, pgprot)) {
87 vfree(addr); 87 vunmap(addr);
88 return NULL; 88 return NULL;
89 } 89 }
90 90
@@ -92,9 +92,11 @@ void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned l
92} 92}
93EXPORT_SYMBOL(__ioremap); 93EXPORT_SYMBOL(__ioremap);
94 94
95void iounmap(const volatile void __iomem *addr) 95void iounmap(const volatile void __iomem *io_addr)
96{ 96{
97 if (addr > high_memory) 97 unsigned long addr = (unsigned long)io_addr & PAGE_MASK;
98 return vfree((void *) (PAGE_MASK & (unsigned long __force) addr)); 98
99 if (is_vmalloc_addr((void *)addr))
100 vunmap((void *)addr);
99} 101}
100EXPORT_SYMBOL(iounmap); 102EXPORT_SYMBOL(iounmap);
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index 6841bd52738b..dfbd7f22eef5 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -50,7 +50,7 @@ endif
50 50
51BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -nostdinc 51BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -nostdinc
52 52
53BOOTARFLAGS := -cr$(KBUILD_ARFLAGS) 53BOOTARFLAGS := -crD
54 54
55ifdef CONFIG_CC_IS_CLANG 55ifdef CONFIG_CC_IS_CLANG
56BOOTCFLAGS += $(CLANG_FLAGS) 56BOOTCFLAGS += $(CLANG_FLAGS)
diff --git a/arch/powerpc/include/asm/book3s/64/tlbflush-radix.h b/arch/powerpc/include/asm/book3s/64/tlbflush-radix.h
index 4ce795d30377..ca8db193ae38 100644
--- a/arch/powerpc/include/asm/book3s/64/tlbflush-radix.h
+++ b/arch/powerpc/include/asm/book3s/64/tlbflush-radix.h
@@ -35,6 +35,10 @@ static inline void radix__flush_all_lpid(unsigned int lpid)
35{ 35{
36 WARN_ON(1); 36 WARN_ON(1);
37} 37}
38static inline void radix__flush_all_lpid_guest(unsigned int lpid)
39{
40 WARN_ON(1);
41}
38#endif 42#endif
39 43
40extern void radix__flush_hugetlb_tlb_range(struct vm_area_struct *vma, 44extern void radix__flush_hugetlb_tlb_range(struct vm_area_struct *vma,
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index d7fcdfa7fee4..ec2547cc5ecb 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -36,8 +36,8 @@
36#include "book3s.h" 36#include "book3s.h"
37#include "trace.h" 37#include "trace.h"
38 38
39#define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM 39#define VM_STAT(x, ...) offsetof(struct kvm, stat.x), KVM_STAT_VM, ## __VA_ARGS__
40#define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU 40#define VCPU_STAT(x, ...) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU, ## __VA_ARGS__
41 41
42/* #define EXIT_DEBUG */ 42/* #define EXIT_DEBUG */
43 43
@@ -69,8 +69,8 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
69 { "pthru_all", VCPU_STAT(pthru_all) }, 69 { "pthru_all", VCPU_STAT(pthru_all) },
70 { "pthru_host", VCPU_STAT(pthru_host) }, 70 { "pthru_host", VCPU_STAT(pthru_host) },
71 { "pthru_bad_aff", VCPU_STAT(pthru_bad_aff) }, 71 { "pthru_bad_aff", VCPU_STAT(pthru_bad_aff) },
72 { "largepages_2M", VM_STAT(num_2M_pages) }, 72 { "largepages_2M", VM_STAT(num_2M_pages, .mode = 0444) },
73 { "largepages_1G", VM_STAT(num_1G_pages) }, 73 { "largepages_1G", VM_STAT(num_1G_pages, .mode = 0444) },
74 { NULL } 74 { NULL }
75}; 75};
76 76
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index 74a9cfe84aee..faebcbb8c4db 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -1921,6 +1921,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
1921 mtspr SPRN_PCR, r6 1921 mtspr SPRN_PCR, r6
192218: 192218:
1923 /* Signal secondary CPUs to continue */ 1923 /* Signal secondary CPUs to continue */
1924 li r0, 0
1924 stb r0,VCORE_IN_GUEST(r5) 1925 stb r0,VCORE_IN_GUEST(r5)
192519: lis r8,0x7fff /* MAX_INT@h */ 192619: lis r8,0x7fff /* MAX_INT@h */
1926 mtspr SPRN_HDEC,r8 1927 mtspr SPRN_HDEC,r8
diff --git a/arch/powerpc/platforms/cell/spufs/inode.c b/arch/powerpc/platforms/cell/spufs/inode.c
index 1d93e55a2de1..2dd452a047cd 100644
--- a/arch/powerpc/platforms/cell/spufs/inode.c
+++ b/arch/powerpc/platforms/cell/spufs/inode.c
@@ -761,6 +761,7 @@ static int spufs_init_fs_context(struct fs_context *fc)
761 ctx->gid = current_gid(); 761 ctx->gid = current_gid();
762 ctx->mode = 0755; 762 ctx->mode = 0755;
763 763
764 fc->fs_private = ctx;
764 fc->s_fs_info = sbi; 765 fc->s_fs_info = sbi;
765 fc->ops = &spufs_context_ops; 766 fc->ops = &spufs_context_ops;
766 return 0; 767 return 0;
diff --git a/arch/powerpc/platforms/pseries/lpar.c b/arch/powerpc/platforms/pseries/lpar.c
index b53359258d99..f87a5c64e24d 100644
--- a/arch/powerpc/platforms/pseries/lpar.c
+++ b/arch/powerpc/platforms/pseries/lpar.c
@@ -1419,6 +1419,9 @@ void __init pseries_lpar_read_hblkrm_characteristics(void)
1419 unsigned char local_buffer[SPLPAR_TLB_BIC_MAXLENGTH]; 1419 unsigned char local_buffer[SPLPAR_TLB_BIC_MAXLENGTH];
1420 int call_status, len, idx, bpsize; 1420 int call_status, len, idx, bpsize;
1421 1421
1422 if (!firmware_has_feature(FW_FEATURE_BLOCK_REMOVE))
1423 return;
1424
1422 spin_lock(&rtas_data_buf_lock); 1425 spin_lock(&rtas_data_buf_lock);
1423 memset(rtas_data_buf, 0, RTAS_DATA_BUF_SIZE); 1426 memset(rtas_data_buf, 0, RTAS_DATA_BUF_SIZE);
1424 call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1, 1427 call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
diff --git a/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts b/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts
index 104d334511cd..88cfcb96bf23 100644
--- a/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts
+++ b/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts
@@ -13,6 +13,7 @@
13 compatible = "sifive,hifive-unleashed-a00", "sifive,fu540-c000"; 13 compatible = "sifive,hifive-unleashed-a00", "sifive,fu540-c000";
14 14
15 chosen { 15 chosen {
16 stdout-path = "serial0";
16 }; 17 };
17 18
18 cpus { 19 cpus {
diff --git a/arch/riscv/include/asm/asm.h b/arch/riscv/include/asm/asm.h
index 5a02b7d50940..9c992a88d858 100644
--- a/arch/riscv/include/asm/asm.h
+++ b/arch/riscv/include/asm/asm.h
@@ -22,6 +22,7 @@
22 22
23#define REG_L __REG_SEL(ld, lw) 23#define REG_L __REG_SEL(ld, lw)
24#define REG_S __REG_SEL(sd, sw) 24#define REG_S __REG_SEL(sd, sw)
25#define REG_SC __REG_SEL(sc.d, sc.w)
25#define SZREG __REG_SEL(8, 4) 26#define SZREG __REG_SEL(8, 4)
26#define LGREG __REG_SEL(3, 2) 27#define LGREG __REG_SEL(3, 2)
27 28
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 7255f2d8395b..42292d99cc74 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -87,14 +87,6 @@ extern pgd_t swapper_pg_dir[];
87#define VMALLOC_END (PAGE_OFFSET - 1) 87#define VMALLOC_END (PAGE_OFFSET - 1)
88#define VMALLOC_START (PAGE_OFFSET - VMALLOC_SIZE) 88#define VMALLOC_START (PAGE_OFFSET - VMALLOC_SIZE)
89 89
90#define FIXADDR_TOP VMALLOC_START
91#ifdef CONFIG_64BIT
92#define FIXADDR_SIZE PMD_SIZE
93#else
94#define FIXADDR_SIZE PGDIR_SIZE
95#endif
96#define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
97
98/* 90/*
99 * Roughly size the vmemmap space to be large enough to fit enough 91 * Roughly size the vmemmap space to be large enough to fit enough
100 * struct pages to map half the virtual address space. Then 92 * struct pages to map half the virtual address space. Then
@@ -108,6 +100,14 @@ extern pgd_t swapper_pg_dir[];
108 100
109#define vmemmap ((struct page *)VMEMMAP_START) 101#define vmemmap ((struct page *)VMEMMAP_START)
110 102
103#define FIXADDR_TOP (VMEMMAP_START)
104#ifdef CONFIG_64BIT
105#define FIXADDR_SIZE PMD_SIZE
106#else
107#define FIXADDR_SIZE PGDIR_SIZE
108#endif
109#define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
110
111/* 111/*
112 * ZERO_PAGE is a global shared page that is always zero, 112 * ZERO_PAGE is a global shared page that is always zero,
113 * used for zero-mapped memory areas, etc. 113 * used for zero-mapped memory areas, etc.
diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h
index 37ae4e367ad2..f02188a5b0f4 100644
--- a/arch/riscv/include/asm/tlbflush.h
+++ b/arch/riscv/include/asm/tlbflush.h
@@ -10,10 +10,6 @@
10#include <linux/mm_types.h> 10#include <linux/mm_types.h>
11#include <asm/smp.h> 11#include <asm/smp.h>
12 12
13/*
14 * Flush entire local TLB. 'sfence.vma' implicitly fences with the instruction
15 * cache as well, so a 'fence.i' is not necessary.
16 */
17static inline void local_flush_tlb_all(void) 13static inline void local_flush_tlb_all(void)
18{ 14{
19 __asm__ __volatile__ ("sfence.vma" : : : "memory"); 15 __asm__ __volatile__ ("sfence.vma" : : : "memory");
diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
index da7aa88113c2..8ca479831142 100644
--- a/arch/riscv/kernel/entry.S
+++ b/arch/riscv/kernel/entry.S
@@ -98,7 +98,26 @@ _save_context:
98 */ 98 */
99 .macro RESTORE_ALL 99 .macro RESTORE_ALL
100 REG_L a0, PT_SSTATUS(sp) 100 REG_L a0, PT_SSTATUS(sp)
101 REG_L a2, PT_SEPC(sp) 101 /*
102 * The current load reservation is effectively part of the processor's
103 * state, in the sense that load reservations cannot be shared between
104 * different hart contexts. We can't actually save and restore a load
105 * reservation, so instead here we clear any existing reservation --
106 * it's always legal for implementations to clear load reservations at
107 * any point (as long as the forward progress guarantee is kept, but
108 * we'll ignore that here).
109 *
110 * Dangling load reservations can be the result of taking a trap in the
111 * middle of an LR/SC sequence, but can also be the result of a taken
112 * forward branch around an SC -- which is how we implement CAS. As a
113 * result we need to clear reservations between the last CAS and the
114 * jump back to the new context. While it is unlikely the store
115 * completes, implementations are allowed to expand reservations to be
116 * arbitrarily large.
117 */
118 REG_L a2, PT_SEPC(sp)
119 REG_SC x0, a2, PT_SEPC(sp)
120
102 csrw CSR_SSTATUS, a0 121 csrw CSR_SSTATUS, a0
103 csrw CSR_SEPC, a2 122 csrw CSR_SEPC, a2
104 123
@@ -254,12 +273,11 @@ restore_all:
254resume_kernel: 273resume_kernel:
255 REG_L s0, TASK_TI_PREEMPT_COUNT(tp) 274 REG_L s0, TASK_TI_PREEMPT_COUNT(tp)
256 bnez s0, restore_all 275 bnez s0, restore_all
257need_resched:
258 REG_L s0, TASK_TI_FLAGS(tp) 276 REG_L s0, TASK_TI_FLAGS(tp)
259 andi s0, s0, _TIF_NEED_RESCHED 277 andi s0, s0, _TIF_NEED_RESCHED
260 beqz s0, restore_all 278 beqz s0, restore_all
261 call preempt_schedule_irq 279 call preempt_schedule_irq
262 j need_resched 280 j restore_all
263#endif 281#endif
264 282
265work_pending: 283work_pending:
diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c
index 424eb72d56b1..1ac75f7d0bff 100644
--- a/arch/riscv/kernel/traps.c
+++ b/arch/riscv/kernel/traps.c
@@ -124,24 +124,24 @@ static inline unsigned long get_break_insn_length(unsigned long pc)
124 124
125asmlinkage void do_trap_break(struct pt_regs *regs) 125asmlinkage void do_trap_break(struct pt_regs *regs)
126{ 126{
127 if (user_mode(regs)) {
128 force_sig_fault(SIGTRAP, TRAP_BRKPT,
129 (void __user *)(regs->sepc));
130 return;
131 }
127#ifdef CONFIG_GENERIC_BUG 132#ifdef CONFIG_GENERIC_BUG
128 if (!user_mode(regs)) { 133 {
129 enum bug_trap_type type; 134 enum bug_trap_type type;
130 135
131 type = report_bug(regs->sepc, regs); 136 type = report_bug(regs->sepc, regs);
132 switch (type) { 137 if (type == BUG_TRAP_TYPE_WARN) {
133 case BUG_TRAP_TYPE_NONE:
134 break;
135 case BUG_TRAP_TYPE_WARN:
136 regs->sepc += get_break_insn_length(regs->sepc); 138 regs->sepc += get_break_insn_length(regs->sepc);
137 break; 139 return;
138 case BUG_TRAP_TYPE_BUG:
139 die(regs, "Kernel BUG");
140 } 140 }
141 } 141 }
142#endif /* CONFIG_GENERIC_BUG */ 142#endif /* CONFIG_GENERIC_BUG */
143 143
144 force_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)(regs->sepc)); 144 die(regs, "Kernel BUG");
145} 145}
146 146
147#ifdef CONFIG_GENERIC_BUG 147#ifdef CONFIG_GENERIC_BUG
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index f0ba71304b6e..83f7d12042fb 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -11,6 +11,7 @@
11#include <linux/swap.h> 11#include <linux/swap.h>
12#include <linux/sizes.h> 12#include <linux/sizes.h>
13#include <linux/of_fdt.h> 13#include <linux/of_fdt.h>
14#include <linux/libfdt.h>
14 15
15#include <asm/fixmap.h> 16#include <asm/fixmap.h>
16#include <asm/tlbflush.h> 17#include <asm/tlbflush.h>
@@ -82,6 +83,8 @@ disable:
82} 83}
83#endif /* CONFIG_BLK_DEV_INITRD */ 84#endif /* CONFIG_BLK_DEV_INITRD */
84 85
86static phys_addr_t dtb_early_pa __initdata;
87
85void __init setup_bootmem(void) 88void __init setup_bootmem(void)
86{ 89{
87 struct memblock_region *reg; 90 struct memblock_region *reg;
@@ -117,7 +120,12 @@ void __init setup_bootmem(void)
117 setup_initrd(); 120 setup_initrd();
118#endif /* CONFIG_BLK_DEV_INITRD */ 121#endif /* CONFIG_BLK_DEV_INITRD */
119 122
120 early_init_fdt_reserve_self(); 123 /*
124 * Avoid using early_init_fdt_reserve_self() since __pa() does
125 * not work for DTB pointers that are fixmap addresses
126 */
127 memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va));
128
121 early_init_fdt_scan_reserved_mem(); 129 early_init_fdt_scan_reserved_mem();
122 memblock_allow_resize(); 130 memblock_allow_resize();
123 memblock_dump_all(); 131 memblock_dump_all();
@@ -393,6 +401,8 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
393 401
394 /* Save pointer to DTB for early FDT parsing */ 402 /* Save pointer to DTB for early FDT parsing */
395 dtb_early_va = (void *)fix_to_virt(FIX_FDT) + (dtb_pa & ~PAGE_MASK); 403 dtb_early_va = (void *)fix_to_virt(FIX_FDT) + (dtb_pa & ~PAGE_MASK);
404 /* Save physical address for memblock reservation */
405 dtb_early_pa = dtb_pa;
396} 406}
397 407
398static void __init setup_vm_final(void) 408static void __init setup_vm_final(void)
diff --git a/arch/s390/configs/debug_defconfig b/arch/s390/configs/debug_defconfig
index 347f48702edb..38d64030aacf 100644
--- a/arch/s390/configs/debug_defconfig
+++ b/arch/s390/configs/debug_defconfig
@@ -44,6 +44,7 @@ CONFIG_NR_CPUS=512
44CONFIG_NUMA=y 44CONFIG_NUMA=y
45CONFIG_HZ_100=y 45CONFIG_HZ_100=y
46CONFIG_KEXEC_FILE=y 46CONFIG_KEXEC_FILE=y
47CONFIG_KEXEC_SIG=y
47CONFIG_EXPOLINE=y 48CONFIG_EXPOLINE=y
48CONFIG_EXPOLINE_AUTO=y 49CONFIG_EXPOLINE_AUTO=y
49CONFIG_CHSC_SCH=y 50CONFIG_CHSC_SCH=y
@@ -69,12 +70,13 @@ CONFIG_MODULE_UNLOAD=y
69CONFIG_MODULE_FORCE_UNLOAD=y 70CONFIG_MODULE_FORCE_UNLOAD=y
70CONFIG_MODVERSIONS=y 71CONFIG_MODVERSIONS=y
71CONFIG_MODULE_SRCVERSION_ALL=y 72CONFIG_MODULE_SRCVERSION_ALL=y
72CONFIG_MODULE_SIG=y
73CONFIG_MODULE_SIG_SHA256=y 73CONFIG_MODULE_SIG_SHA256=y
74CONFIG_UNUSED_SYMBOLS=y
74CONFIG_BLK_DEV_INTEGRITY=y 75CONFIG_BLK_DEV_INTEGRITY=y
75CONFIG_BLK_DEV_THROTTLING=y 76CONFIG_BLK_DEV_THROTTLING=y
76CONFIG_BLK_WBT=y 77CONFIG_BLK_WBT=y
77CONFIG_BLK_CGROUP_IOLATENCY=y 78CONFIG_BLK_CGROUP_IOLATENCY=y
79CONFIG_BLK_CGROUP_IOCOST=y
78CONFIG_PARTITION_ADVANCED=y 80CONFIG_PARTITION_ADVANCED=y
79CONFIG_IBM_PARTITION=y 81CONFIG_IBM_PARTITION=y
80CONFIG_BSD_DISKLABEL=y 82CONFIG_BSD_DISKLABEL=y
@@ -370,6 +372,7 @@ CONFIG_NETLINK_DIAG=m
370CONFIG_CGROUP_NET_PRIO=y 372CONFIG_CGROUP_NET_PRIO=y
371CONFIG_BPF_JIT=y 373CONFIG_BPF_JIT=y
372CONFIG_NET_PKTGEN=m 374CONFIG_NET_PKTGEN=m
375# CONFIG_NET_DROP_MONITOR is not set
373CONFIG_PCI=y 376CONFIG_PCI=y
374CONFIG_PCI_DEBUG=y 377CONFIG_PCI_DEBUG=y
375CONFIG_HOTPLUG_PCI=y 378CONFIG_HOTPLUG_PCI=y
@@ -424,6 +427,7 @@ CONFIG_DM_CRYPT=m
424CONFIG_DM_SNAPSHOT=m 427CONFIG_DM_SNAPSHOT=m
425CONFIG_DM_THIN_PROVISIONING=m 428CONFIG_DM_THIN_PROVISIONING=m
426CONFIG_DM_WRITECACHE=m 429CONFIG_DM_WRITECACHE=m
430CONFIG_DM_CLONE=m
427CONFIG_DM_MIRROR=m 431CONFIG_DM_MIRROR=m
428CONFIG_DM_LOG_USERSPACE=m 432CONFIG_DM_LOG_USERSPACE=m
429CONFIG_DM_RAID=m 433CONFIG_DM_RAID=m
@@ -435,6 +439,7 @@ CONFIG_DM_DELAY=m
435CONFIG_DM_UEVENT=y 439CONFIG_DM_UEVENT=y
436CONFIG_DM_FLAKEY=m 440CONFIG_DM_FLAKEY=m
437CONFIG_DM_VERITY=m 441CONFIG_DM_VERITY=m
442CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG=y
438CONFIG_DM_SWITCH=m 443CONFIG_DM_SWITCH=m
439CONFIG_NETDEVICES=y 444CONFIG_NETDEVICES=y
440CONFIG_BONDING=m 445CONFIG_BONDING=m
@@ -489,6 +494,7 @@ CONFIG_MLX5_CORE_EN=y
489# CONFIG_NET_VENDOR_NVIDIA is not set 494# CONFIG_NET_VENDOR_NVIDIA is not set
490# CONFIG_NET_VENDOR_OKI is not set 495# CONFIG_NET_VENDOR_OKI is not set
491# CONFIG_NET_VENDOR_PACKET_ENGINES is not set 496# CONFIG_NET_VENDOR_PACKET_ENGINES is not set
497# CONFIG_NET_VENDOR_PENSANDO is not set
492# CONFIG_NET_VENDOR_QLOGIC is not set 498# CONFIG_NET_VENDOR_QLOGIC is not set
493# CONFIG_NET_VENDOR_QUALCOMM is not set 499# CONFIG_NET_VENDOR_QUALCOMM is not set
494# CONFIG_NET_VENDOR_RDC is not set 500# CONFIG_NET_VENDOR_RDC is not set
@@ -538,15 +544,16 @@ CONFIG_WATCHDOG=y
538CONFIG_WATCHDOG_NOWAYOUT=y 544CONFIG_WATCHDOG_NOWAYOUT=y
539CONFIG_SOFT_WATCHDOG=m 545CONFIG_SOFT_WATCHDOG=m
540CONFIG_DIAG288_WATCHDOG=m 546CONFIG_DIAG288_WATCHDOG=m
541CONFIG_DRM=y 547CONFIG_FB=y
542CONFIG_DRM_VIRTIO_GPU=y
543CONFIG_FRAMEBUFFER_CONSOLE=y 548CONFIG_FRAMEBUFFER_CONSOLE=y
549CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY=y
544# CONFIG_HID is not set 550# CONFIG_HID is not set
545# CONFIG_USB_SUPPORT is not set 551# CONFIG_USB_SUPPORT is not set
546CONFIG_INFINIBAND=m 552CONFIG_INFINIBAND=m
547CONFIG_INFINIBAND_USER_ACCESS=m 553CONFIG_INFINIBAND_USER_ACCESS=m
548CONFIG_MLX4_INFINIBAND=m 554CONFIG_MLX4_INFINIBAND=m
549CONFIG_MLX5_INFINIBAND=m 555CONFIG_MLX5_INFINIBAND=m
556CONFIG_SYNC_FILE=y
550CONFIG_VFIO=m 557CONFIG_VFIO=m
551CONFIG_VFIO_PCI=m 558CONFIG_VFIO_PCI=m
552CONFIG_VFIO_MDEV=m 559CONFIG_VFIO_MDEV=m
@@ -580,6 +587,8 @@ CONFIG_NILFS2_FS=m
580CONFIG_FS_DAX=y 587CONFIG_FS_DAX=y
581CONFIG_EXPORTFS_BLOCK_OPS=y 588CONFIG_EXPORTFS_BLOCK_OPS=y
582CONFIG_FS_ENCRYPTION=y 589CONFIG_FS_ENCRYPTION=y
590CONFIG_FS_VERITY=y
591CONFIG_FS_VERITY_BUILTIN_SIGNATURES=y
583CONFIG_FANOTIFY=y 592CONFIG_FANOTIFY=y
584CONFIG_FANOTIFY_ACCESS_PERMISSIONS=y 593CONFIG_FANOTIFY_ACCESS_PERMISSIONS=y
585CONFIG_QUOTA_NETLINK_INTERFACE=y 594CONFIG_QUOTA_NETLINK_INTERFACE=y
@@ -589,6 +598,7 @@ CONFIG_QFMT_V2=m
589CONFIG_AUTOFS4_FS=m 598CONFIG_AUTOFS4_FS=m
590CONFIG_FUSE_FS=y 599CONFIG_FUSE_FS=y
591CONFIG_CUSE=m 600CONFIG_CUSE=m
601CONFIG_VIRTIO_FS=m
592CONFIG_OVERLAY_FS=m 602CONFIG_OVERLAY_FS=m
593CONFIG_FSCACHE=m 603CONFIG_FSCACHE=m
594CONFIG_CACHEFILES=m 604CONFIG_CACHEFILES=m
@@ -648,12 +658,15 @@ CONFIG_FORTIFY_SOURCE=y
648CONFIG_SECURITY_SELINUX=y 658CONFIG_SECURITY_SELINUX=y
649CONFIG_SECURITY_SELINUX_BOOTPARAM=y 659CONFIG_SECURITY_SELINUX_BOOTPARAM=y
650CONFIG_SECURITY_SELINUX_DISABLE=y 660CONFIG_SECURITY_SELINUX_DISABLE=y
661CONFIG_SECURITY_LOCKDOWN_LSM=y
662CONFIG_SECURITY_LOCKDOWN_LSM_EARLY=y
651CONFIG_INTEGRITY_SIGNATURE=y 663CONFIG_INTEGRITY_SIGNATURE=y
652CONFIG_INTEGRITY_ASYMMETRIC_KEYS=y 664CONFIG_INTEGRITY_ASYMMETRIC_KEYS=y
653CONFIG_IMA=y 665CONFIG_IMA=y
654CONFIG_IMA_DEFAULT_HASH_SHA256=y 666CONFIG_IMA_DEFAULT_HASH_SHA256=y
655CONFIG_IMA_WRITE_POLICY=y 667CONFIG_IMA_WRITE_POLICY=y
656CONFIG_IMA_APPRAISE=y 668CONFIG_IMA_APPRAISE=y
669CONFIG_LSM="yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor"
657CONFIG_CRYPTO_USER=m 670CONFIG_CRYPTO_USER=m
658# CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is not set 671# CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is not set
659CONFIG_CRYPTO_PCRYPT=m 672CONFIG_CRYPTO_PCRYPT=m
@@ -664,10 +677,6 @@ CONFIG_CRYPTO_ECDH=m
664CONFIG_CRYPTO_ECRDSA=m 677CONFIG_CRYPTO_ECRDSA=m
665CONFIG_CRYPTO_CHACHA20POLY1305=m 678CONFIG_CRYPTO_CHACHA20POLY1305=m
666CONFIG_CRYPTO_AEGIS128=m 679CONFIG_CRYPTO_AEGIS128=m
667CONFIG_CRYPTO_AEGIS128L=m
668CONFIG_CRYPTO_AEGIS256=m
669CONFIG_CRYPTO_MORUS640=m
670CONFIG_CRYPTO_MORUS1280=m
671CONFIG_CRYPTO_CFB=m 680CONFIG_CRYPTO_CFB=m
672CONFIG_CRYPTO_LRW=m 681CONFIG_CRYPTO_LRW=m
673CONFIG_CRYPTO_PCBC=m 682CONFIG_CRYPTO_PCBC=m
@@ -739,7 +748,6 @@ CONFIG_DEBUG_INFO=y
739CONFIG_DEBUG_INFO_DWARF4=y 748CONFIG_DEBUG_INFO_DWARF4=y
740CONFIG_GDB_SCRIPTS=y 749CONFIG_GDB_SCRIPTS=y
741CONFIG_FRAME_WARN=1024 750CONFIG_FRAME_WARN=1024
742CONFIG_UNUSED_SYMBOLS=y
743CONFIG_HEADERS_INSTALL=y 751CONFIG_HEADERS_INSTALL=y
744CONFIG_HEADERS_CHECK=y 752CONFIG_HEADERS_CHECK=y
745CONFIG_DEBUG_SECTION_MISMATCH=y 753CONFIG_DEBUG_SECTION_MISMATCH=y
diff --git a/arch/s390/configs/defconfig b/arch/s390/configs/defconfig
index 8514b8b9500f..25f799849582 100644
--- a/arch/s390/configs/defconfig
+++ b/arch/s390/configs/defconfig
@@ -44,6 +44,7 @@ CONFIG_NUMA=y
44# CONFIG_NUMA_EMU is not set 44# CONFIG_NUMA_EMU is not set
45CONFIG_HZ_100=y 45CONFIG_HZ_100=y
46CONFIG_KEXEC_FILE=y 46CONFIG_KEXEC_FILE=y
47CONFIG_KEXEC_SIG=y
47CONFIG_EXPOLINE=y 48CONFIG_EXPOLINE=y
48CONFIG_EXPOLINE_AUTO=y 49CONFIG_EXPOLINE_AUTO=y
49CONFIG_CHSC_SCH=y 50CONFIG_CHSC_SCH=y
@@ -66,11 +67,12 @@ CONFIG_MODULE_UNLOAD=y
66CONFIG_MODULE_FORCE_UNLOAD=y 67CONFIG_MODULE_FORCE_UNLOAD=y
67CONFIG_MODVERSIONS=y 68CONFIG_MODVERSIONS=y
68CONFIG_MODULE_SRCVERSION_ALL=y 69CONFIG_MODULE_SRCVERSION_ALL=y
69CONFIG_MODULE_SIG=y
70CONFIG_MODULE_SIG_SHA256=y 70CONFIG_MODULE_SIG_SHA256=y
71CONFIG_UNUSED_SYMBOLS=y
71CONFIG_BLK_DEV_THROTTLING=y 72CONFIG_BLK_DEV_THROTTLING=y
72CONFIG_BLK_WBT=y 73CONFIG_BLK_WBT=y
73CONFIG_BLK_CGROUP_IOLATENCY=y 74CONFIG_BLK_CGROUP_IOLATENCY=y
75CONFIG_BLK_CGROUP_IOCOST=y
74CONFIG_PARTITION_ADVANCED=y 76CONFIG_PARTITION_ADVANCED=y
75CONFIG_IBM_PARTITION=y 77CONFIG_IBM_PARTITION=y
76CONFIG_BSD_DISKLABEL=y 78CONFIG_BSD_DISKLABEL=y
@@ -363,6 +365,7 @@ CONFIG_NETLINK_DIAG=m
363CONFIG_CGROUP_NET_PRIO=y 365CONFIG_CGROUP_NET_PRIO=y
364CONFIG_BPF_JIT=y 366CONFIG_BPF_JIT=y
365CONFIG_NET_PKTGEN=m 367CONFIG_NET_PKTGEN=m
368# CONFIG_NET_DROP_MONITOR is not set
366CONFIG_PCI=y 369CONFIG_PCI=y
367CONFIG_HOTPLUG_PCI=y 370CONFIG_HOTPLUG_PCI=y
368CONFIG_HOTPLUG_PCI_S390=y 371CONFIG_HOTPLUG_PCI_S390=y
@@ -418,6 +421,7 @@ CONFIG_DM_CRYPT=m
418CONFIG_DM_SNAPSHOT=m 421CONFIG_DM_SNAPSHOT=m
419CONFIG_DM_THIN_PROVISIONING=m 422CONFIG_DM_THIN_PROVISIONING=m
420CONFIG_DM_WRITECACHE=m 423CONFIG_DM_WRITECACHE=m
424CONFIG_DM_CLONE=m
421CONFIG_DM_MIRROR=m 425CONFIG_DM_MIRROR=m
422CONFIG_DM_LOG_USERSPACE=m 426CONFIG_DM_LOG_USERSPACE=m
423CONFIG_DM_RAID=m 427CONFIG_DM_RAID=m
@@ -429,6 +433,7 @@ CONFIG_DM_DELAY=m
429CONFIG_DM_UEVENT=y 433CONFIG_DM_UEVENT=y
430CONFIG_DM_FLAKEY=m 434CONFIG_DM_FLAKEY=m
431CONFIG_DM_VERITY=m 435CONFIG_DM_VERITY=m
436CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG=y
432CONFIG_DM_SWITCH=m 437CONFIG_DM_SWITCH=m
433CONFIG_DM_INTEGRITY=m 438CONFIG_DM_INTEGRITY=m
434CONFIG_NETDEVICES=y 439CONFIG_NETDEVICES=y
@@ -484,6 +489,7 @@ CONFIG_MLX5_CORE_EN=y
484# CONFIG_NET_VENDOR_NVIDIA is not set 489# CONFIG_NET_VENDOR_NVIDIA is not set
485# CONFIG_NET_VENDOR_OKI is not set 490# CONFIG_NET_VENDOR_OKI is not set
486# CONFIG_NET_VENDOR_PACKET_ENGINES is not set 491# CONFIG_NET_VENDOR_PACKET_ENGINES is not set
492# CONFIG_NET_VENDOR_PENSANDO is not set
487# CONFIG_NET_VENDOR_QLOGIC is not set 493# CONFIG_NET_VENDOR_QLOGIC is not set
488# CONFIG_NET_VENDOR_QUALCOMM is not set 494# CONFIG_NET_VENDOR_QUALCOMM is not set
489# CONFIG_NET_VENDOR_RDC is not set 495# CONFIG_NET_VENDOR_RDC is not set
@@ -533,16 +539,16 @@ CONFIG_WATCHDOG_CORE=y
533CONFIG_WATCHDOG_NOWAYOUT=y 539CONFIG_WATCHDOG_NOWAYOUT=y
534CONFIG_SOFT_WATCHDOG=m 540CONFIG_SOFT_WATCHDOG=m
535CONFIG_DIAG288_WATCHDOG=m 541CONFIG_DIAG288_WATCHDOG=m
536CONFIG_DRM=y 542CONFIG_FB=y
537CONFIG_DRM_VIRTIO_GPU=y
538# CONFIG_BACKLIGHT_CLASS_DEVICE is not set
539CONFIG_FRAMEBUFFER_CONSOLE=y 543CONFIG_FRAMEBUFFER_CONSOLE=y
544CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY=y
540# CONFIG_HID is not set 545# CONFIG_HID is not set
541# CONFIG_USB_SUPPORT is not set 546# CONFIG_USB_SUPPORT is not set
542CONFIG_INFINIBAND=m 547CONFIG_INFINIBAND=m
543CONFIG_INFINIBAND_USER_ACCESS=m 548CONFIG_INFINIBAND_USER_ACCESS=m
544CONFIG_MLX4_INFINIBAND=m 549CONFIG_MLX4_INFINIBAND=m
545CONFIG_MLX5_INFINIBAND=m 550CONFIG_MLX5_INFINIBAND=m
551CONFIG_SYNC_FILE=y
546CONFIG_VFIO=m 552CONFIG_VFIO=m
547CONFIG_VFIO_PCI=m 553CONFIG_VFIO_PCI=m
548CONFIG_VFIO_MDEV=m 554CONFIG_VFIO_MDEV=m
@@ -573,6 +579,8 @@ CONFIG_NILFS2_FS=m
573CONFIG_FS_DAX=y 579CONFIG_FS_DAX=y
574CONFIG_EXPORTFS_BLOCK_OPS=y 580CONFIG_EXPORTFS_BLOCK_OPS=y
575CONFIG_FS_ENCRYPTION=y 581CONFIG_FS_ENCRYPTION=y
582CONFIG_FS_VERITY=y
583CONFIG_FS_VERITY_BUILTIN_SIGNATURES=y
576CONFIG_FANOTIFY=y 584CONFIG_FANOTIFY=y
577CONFIG_FANOTIFY_ACCESS_PERMISSIONS=y 585CONFIG_FANOTIFY_ACCESS_PERMISSIONS=y
578CONFIG_QUOTA_NETLINK_INTERFACE=y 586CONFIG_QUOTA_NETLINK_INTERFACE=y
@@ -581,6 +589,7 @@ CONFIG_QFMT_V2=m
581CONFIG_AUTOFS4_FS=m 589CONFIG_AUTOFS4_FS=m
582CONFIG_FUSE_FS=y 590CONFIG_FUSE_FS=y
583CONFIG_CUSE=m 591CONFIG_CUSE=m
592CONFIG_VIRTIO_FS=m
584CONFIG_OVERLAY_FS=m 593CONFIG_OVERLAY_FS=m
585CONFIG_FSCACHE=m 594CONFIG_FSCACHE=m
586CONFIG_CACHEFILES=m 595CONFIG_CACHEFILES=m
@@ -639,12 +648,15 @@ CONFIG_SECURITY_NETWORK=y
639CONFIG_SECURITY_SELINUX=y 648CONFIG_SECURITY_SELINUX=y
640CONFIG_SECURITY_SELINUX_BOOTPARAM=y 649CONFIG_SECURITY_SELINUX_BOOTPARAM=y
641CONFIG_SECURITY_SELINUX_DISABLE=y 650CONFIG_SECURITY_SELINUX_DISABLE=y
651CONFIG_SECURITY_LOCKDOWN_LSM=y
652CONFIG_SECURITY_LOCKDOWN_LSM_EARLY=y
642CONFIG_INTEGRITY_SIGNATURE=y 653CONFIG_INTEGRITY_SIGNATURE=y
643CONFIG_INTEGRITY_ASYMMETRIC_KEYS=y 654CONFIG_INTEGRITY_ASYMMETRIC_KEYS=y
644CONFIG_IMA=y 655CONFIG_IMA=y
645CONFIG_IMA_DEFAULT_HASH_SHA256=y 656CONFIG_IMA_DEFAULT_HASH_SHA256=y
646CONFIG_IMA_WRITE_POLICY=y 657CONFIG_IMA_WRITE_POLICY=y
647CONFIG_IMA_APPRAISE=y 658CONFIG_IMA_APPRAISE=y
659CONFIG_LSM="yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor"
648CONFIG_CRYPTO_FIPS=y 660CONFIG_CRYPTO_FIPS=y
649CONFIG_CRYPTO_USER=m 661CONFIG_CRYPTO_USER=m
650# CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is not set 662# CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is not set
@@ -656,10 +668,6 @@ CONFIG_CRYPTO_ECDH=m
656CONFIG_CRYPTO_ECRDSA=m 668CONFIG_CRYPTO_ECRDSA=m
657CONFIG_CRYPTO_CHACHA20POLY1305=m 669CONFIG_CRYPTO_CHACHA20POLY1305=m
658CONFIG_CRYPTO_AEGIS128=m 670CONFIG_CRYPTO_AEGIS128=m
659CONFIG_CRYPTO_AEGIS128L=m
660CONFIG_CRYPTO_AEGIS256=m
661CONFIG_CRYPTO_MORUS640=m
662CONFIG_CRYPTO_MORUS1280=m
663CONFIG_CRYPTO_CFB=m 671CONFIG_CRYPTO_CFB=m
664CONFIG_CRYPTO_LRW=m 672CONFIG_CRYPTO_LRW=m
665CONFIG_CRYPTO_OFB=m 673CONFIG_CRYPTO_OFB=m
@@ -727,7 +735,6 @@ CONFIG_DEBUG_INFO=y
727CONFIG_DEBUG_INFO_DWARF4=y 735CONFIG_DEBUG_INFO_DWARF4=y
728CONFIG_GDB_SCRIPTS=y 736CONFIG_GDB_SCRIPTS=y
729CONFIG_FRAME_WARN=1024 737CONFIG_FRAME_WARN=1024
730CONFIG_UNUSED_SYMBOLS=y
731CONFIG_DEBUG_SECTION_MISMATCH=y 738CONFIG_DEBUG_SECTION_MISMATCH=y
732CONFIG_MAGIC_SYSRQ=y 739CONFIG_MAGIC_SYSRQ=y
733CONFIG_DEBUG_MEMORY_INIT=y 740CONFIG_DEBUG_MEMORY_INIT=y
diff --git a/arch/s390/configs/zfcpdump_defconfig b/arch/s390/configs/zfcpdump_defconfig
index be09a208b608..20c51e5d9353 100644
--- a/arch/s390/configs/zfcpdump_defconfig
+++ b/arch/s390/configs/zfcpdump_defconfig
@@ -61,7 +61,7 @@ CONFIG_RAW_DRIVER=y
61CONFIG_CONFIGFS_FS=y 61CONFIG_CONFIGFS_FS=y
62# CONFIG_MISC_FILESYSTEMS is not set 62# CONFIG_MISC_FILESYSTEMS is not set
63# CONFIG_NETWORK_FILESYSTEMS is not set 63# CONFIG_NETWORK_FILESYSTEMS is not set
64# CONFIG_DIMLIB is not set 64CONFIG_LSM="yama,loadpin,safesetid,integrity"
65CONFIG_PRINTK_TIME=y 65CONFIG_PRINTK_TIME=y
66CONFIG_DEBUG_INFO=y 66CONFIG_DEBUG_INFO=y
67CONFIG_DEBUG_FS=y 67CONFIG_DEBUG_FS=y
diff --git a/arch/s390/include/asm/atomic_ops.h b/arch/s390/include/asm/atomic_ops.h
index d3f09526ee19..61467b9eecc7 100644
--- a/arch/s390/include/asm/atomic_ops.h
+++ b/arch/s390/include/asm/atomic_ops.h
@@ -41,7 +41,7 @@ __ATOMIC_OPS(__atomic64_xor, long, "laxg")
41#undef __ATOMIC_OP 41#undef __ATOMIC_OP
42 42
43#define __ATOMIC_CONST_OP(op_name, op_type, op_string, op_barrier) \ 43#define __ATOMIC_CONST_OP(op_name, op_type, op_string, op_barrier) \
44static inline void op_name(op_type val, op_type *ptr) \ 44static __always_inline void op_name(op_type val, op_type *ptr) \
45{ \ 45{ \
46 asm volatile( \ 46 asm volatile( \
47 op_string " %[ptr],%[val]\n" \ 47 op_string " %[ptr],%[val]\n" \
diff --git a/arch/s390/include/asm/bitops.h b/arch/s390/include/asm/bitops.h
index b8833ac983fa..eb7eed43e780 100644
--- a/arch/s390/include/asm/bitops.h
+++ b/arch/s390/include/asm/bitops.h
@@ -56,7 +56,7 @@ __bitops_byte(unsigned long nr, volatile unsigned long *ptr)
56 return ((unsigned char *)ptr) + ((nr ^ (BITS_PER_LONG - 8)) >> 3); 56 return ((unsigned char *)ptr) + ((nr ^ (BITS_PER_LONG - 8)) >> 3);
57} 57}
58 58
59static inline void arch_set_bit(unsigned long nr, volatile unsigned long *ptr) 59static __always_inline void arch_set_bit(unsigned long nr, volatile unsigned long *ptr)
60{ 60{
61 unsigned long *addr = __bitops_word(nr, ptr); 61 unsigned long *addr = __bitops_word(nr, ptr);
62 unsigned long mask; 62 unsigned long mask;
@@ -77,7 +77,7 @@ static inline void arch_set_bit(unsigned long nr, volatile unsigned long *ptr)
77 __atomic64_or(mask, (long *)addr); 77 __atomic64_or(mask, (long *)addr);
78} 78}
79 79
80static inline void arch_clear_bit(unsigned long nr, volatile unsigned long *ptr) 80static __always_inline void arch_clear_bit(unsigned long nr, volatile unsigned long *ptr)
81{ 81{
82 unsigned long *addr = __bitops_word(nr, ptr); 82 unsigned long *addr = __bitops_word(nr, ptr);
83 unsigned long mask; 83 unsigned long mask;
@@ -98,8 +98,8 @@ static inline void arch_clear_bit(unsigned long nr, volatile unsigned long *ptr)
98 __atomic64_and(mask, (long *)addr); 98 __atomic64_and(mask, (long *)addr);
99} 99}
100 100
101static inline void arch_change_bit(unsigned long nr, 101static __always_inline void arch_change_bit(unsigned long nr,
102 volatile unsigned long *ptr) 102 volatile unsigned long *ptr)
103{ 103{
104 unsigned long *addr = __bitops_word(nr, ptr); 104 unsigned long *addr = __bitops_word(nr, ptr);
105 unsigned long mask; 105 unsigned long mask;
diff --git a/arch/s390/include/asm/cpacf.h b/arch/s390/include/asm/cpacf.h
index a092f63aac6a..c0f3bfeddcbe 100644
--- a/arch/s390/include/asm/cpacf.h
+++ b/arch/s390/include/asm/cpacf.h
@@ -171,7 +171,7 @@ typedef struct { unsigned char bytes[16]; } cpacf_mask_t;
171 * 171 *
172 * Returns 1 if @func is available for @opcode, 0 otherwise 172 * Returns 1 if @func is available for @opcode, 0 otherwise
173 */ 173 */
174static inline void __cpacf_query(unsigned int opcode, cpacf_mask_t *mask) 174static __always_inline void __cpacf_query(unsigned int opcode, cpacf_mask_t *mask)
175{ 175{
176 register unsigned long r0 asm("0") = 0; /* query function */ 176 register unsigned long r0 asm("0") = 0; /* query function */
177 register unsigned long r1 asm("1") = (unsigned long) mask; 177 register unsigned long r1 asm("1") = (unsigned long) mask;
diff --git a/arch/s390/include/asm/cpu_mf.h b/arch/s390/include/asm/cpu_mf.h
index ceeb552d3472..819803a97c2b 100644
--- a/arch/s390/include/asm/cpu_mf.h
+++ b/arch/s390/include/asm/cpu_mf.h
@@ -28,6 +28,8 @@ asm(".include \"asm/cpu_mf-insn.h\"\n");
28 CPU_MF_INT_SF_PRA|CPU_MF_INT_SF_SACA| \ 28 CPU_MF_INT_SF_PRA|CPU_MF_INT_SF_SACA| \
29 CPU_MF_INT_SF_LSDA) 29 CPU_MF_INT_SF_LSDA)
30 30
31#define CPU_MF_SF_RIBM_NOTAV 0x1 /* Sampling unavailable */
32
31/* CPU measurement facility support */ 33/* CPU measurement facility support */
32static inline int cpum_cf_avail(void) 34static inline int cpum_cf_avail(void)
33{ 35{
@@ -69,7 +71,8 @@ struct hws_qsi_info_block { /* Bit(s) */
69 unsigned long max_sampl_rate; /* 16-23: maximum sampling interval*/ 71 unsigned long max_sampl_rate; /* 16-23: maximum sampling interval*/
70 unsigned long tear; /* 24-31: TEAR contents */ 72 unsigned long tear; /* 24-31: TEAR contents */
71 unsigned long dear; /* 32-39: DEAR contents */ 73 unsigned long dear; /* 32-39: DEAR contents */
72 unsigned int rsvrd0; /* 40-43: reserved */ 74 unsigned int rsvrd0:24; /* 40-42: reserved */
75 unsigned int ribm:8; /* 43: Reserved by IBM */
73 unsigned int cpu_speed; /* 44-47: CPU speed */ 76 unsigned int cpu_speed; /* 44-47: CPU speed */
74 unsigned long long rsvrd1; /* 48-55: reserved */ 77 unsigned long long rsvrd1; /* 48-55: reserved */
75 unsigned long long rsvrd2; /* 56-63: reserved */ 78 unsigned long long rsvrd2; /* 56-63: reserved */
@@ -220,7 +223,8 @@ enum stcctm_ctr_set {
220 MT_DIAG = 5, 223 MT_DIAG = 5,
221 MT_DIAG_CLEARING = 9, /* clears loss-of-MT-ctr-data alert */ 224 MT_DIAG_CLEARING = 9, /* clears loss-of-MT-ctr-data alert */
222}; 225};
223static inline int stcctm(enum stcctm_ctr_set set, u64 range, u64 *dest) 226
227static __always_inline int stcctm(enum stcctm_ctr_set set, u64 range, u64 *dest)
224{ 228{
225 int cc; 229 int cc;
226 230
diff --git a/arch/s390/include/asm/hugetlb.h b/arch/s390/include/asm/hugetlb.h
index bb59dd964590..de8f0bf5f238 100644
--- a/arch/s390/include/asm/hugetlb.h
+++ b/arch/s390/include/asm/hugetlb.h
@@ -12,8 +12,6 @@
12#include <asm/page.h> 12#include <asm/page.h>
13#include <asm/pgtable.h> 13#include <asm/pgtable.h>
14 14
15
16#define is_hugepage_only_range(mm, addr, len) 0
17#define hugetlb_free_pgd_range free_pgd_range 15#define hugetlb_free_pgd_range free_pgd_range
18#define hugepages_supported() (MACHINE_HAS_EDAT1) 16#define hugepages_supported() (MACHINE_HAS_EDAT1)
19 17
@@ -23,6 +21,13 @@ pte_t huge_ptep_get(pte_t *ptep);
23pte_t huge_ptep_get_and_clear(struct mm_struct *mm, 21pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
24 unsigned long addr, pte_t *ptep); 22 unsigned long addr, pte_t *ptep);
25 23
24static inline bool is_hugepage_only_range(struct mm_struct *mm,
25 unsigned long addr,
26 unsigned long len)
27{
28 return false;
29}
30
26/* 31/*
27 * If the arch doesn't supply something else, assume that hugepage 32 * If the arch doesn't supply something else, assume that hugepage
28 * size aligned regions are ok without further preparation. 33 * size aligned regions are ok without further preparation.
diff --git a/arch/s390/include/asm/jump_label.h b/arch/s390/include/asm/jump_label.h
index e548ec1ec12c..39f747d63758 100644
--- a/arch/s390/include/asm/jump_label.h
+++ b/arch/s390/include/asm/jump_label.h
@@ -20,7 +20,7 @@
20 * We use a brcl 0,2 instruction for jump labels at compile time so it 20 * We use a brcl 0,2 instruction for jump labels at compile time so it
21 * can be easily distinguished from a hotpatch generated instruction. 21 * can be easily distinguished from a hotpatch generated instruction.
22 */ 22 */
23static inline bool arch_static_branch(struct static_key *key, bool branch) 23static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
24{ 24{
25 asm_volatile_goto("0: brcl 0,"__stringify(JUMP_LABEL_NOP_OFFSET)"\n" 25 asm_volatile_goto("0: brcl 0,"__stringify(JUMP_LABEL_NOP_OFFSET)"\n"
26 ".pushsection __jump_table,\"aw\"\n" 26 ".pushsection __jump_table,\"aw\"\n"
@@ -34,7 +34,7 @@ label:
34 return true; 34 return true;
35} 35}
36 36
37static inline bool arch_static_branch_jump(struct static_key *key, bool branch) 37static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
38{ 38{
39 asm_volatile_goto("0: brcl 15,%l[label]\n" 39 asm_volatile_goto("0: brcl 15,%l[label]\n"
40 ".pushsection __jump_table,\"aw\"\n" 40 ".pushsection __jump_table,\"aw\"\n"
diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index 36c578c0ff96..5ff98d76a66c 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -997,9 +997,9 @@ static inline pte_t pte_mkhuge(pte_t pte)
997#define IPTE_NODAT 0x400 997#define IPTE_NODAT 0x400
998#define IPTE_GUEST_ASCE 0x800 998#define IPTE_GUEST_ASCE 0x800
999 999
1000static inline void __ptep_ipte(unsigned long address, pte_t *ptep, 1000static __always_inline void __ptep_ipte(unsigned long address, pte_t *ptep,
1001 unsigned long opt, unsigned long asce, 1001 unsigned long opt, unsigned long asce,
1002 int local) 1002 int local)
1003{ 1003{
1004 unsigned long pto = (unsigned long) ptep; 1004 unsigned long pto = (unsigned long) ptep;
1005 1005
@@ -1020,8 +1020,8 @@ static inline void __ptep_ipte(unsigned long address, pte_t *ptep,
1020 : [r1] "a" (pto), [m4] "i" (local) : "memory"); 1020 : [r1] "a" (pto), [m4] "i" (local) : "memory");
1021} 1021}
1022 1022
1023static inline void __ptep_ipte_range(unsigned long address, int nr, 1023static __always_inline void __ptep_ipte_range(unsigned long address, int nr,
1024 pte_t *ptep, int local) 1024 pte_t *ptep, int local)
1025{ 1025{
1026 unsigned long pto = (unsigned long) ptep; 1026 unsigned long pto = (unsigned long) ptep;
1027 1027
@@ -1269,7 +1269,8 @@ static inline pte_t *pte_offset(pmd_t *pmd, unsigned long address)
1269 1269
1270#define pte_offset_kernel(pmd, address) pte_offset(pmd, address) 1270#define pte_offset_kernel(pmd, address) pte_offset(pmd, address)
1271#define pte_offset_map(pmd, address) pte_offset_kernel(pmd, address) 1271#define pte_offset_map(pmd, address) pte_offset_kernel(pmd, address)
1272#define pte_unmap(pte) do { } while (0) 1272
1273static inline void pte_unmap(pte_t *pte) { }
1273 1274
1274static inline bool gup_fast_permitted(unsigned long start, unsigned long end) 1275static inline bool gup_fast_permitted(unsigned long start, unsigned long end)
1275{ 1276{
@@ -1435,9 +1436,9 @@ static inline void __pmdp_csp(pmd_t *pmdp)
1435#define IDTE_NODAT 0x1000 1436#define IDTE_NODAT 0x1000
1436#define IDTE_GUEST_ASCE 0x2000 1437#define IDTE_GUEST_ASCE 0x2000
1437 1438
1438static inline void __pmdp_idte(unsigned long addr, pmd_t *pmdp, 1439static __always_inline void __pmdp_idte(unsigned long addr, pmd_t *pmdp,
1439 unsigned long opt, unsigned long asce, 1440 unsigned long opt, unsigned long asce,
1440 int local) 1441 int local)
1441{ 1442{
1442 unsigned long sto; 1443 unsigned long sto;
1443 1444
@@ -1461,9 +1462,9 @@ static inline void __pmdp_idte(unsigned long addr, pmd_t *pmdp,
1461 } 1462 }
1462} 1463}
1463 1464
1464static inline void __pudp_idte(unsigned long addr, pud_t *pudp, 1465static __always_inline void __pudp_idte(unsigned long addr, pud_t *pudp,
1465 unsigned long opt, unsigned long asce, 1466 unsigned long opt, unsigned long asce,
1466 int local) 1467 int local)
1467{ 1468{
1468 unsigned long r3o; 1469 unsigned long r3o;
1469 1470
diff --git a/arch/s390/include/asm/qdio.h b/arch/s390/include/asm/qdio.h
index 78e8a888306d..e3f238e8c611 100644
--- a/arch/s390/include/asm/qdio.h
+++ b/arch/s390/include/asm/qdio.h
@@ -111,7 +111,7 @@ struct qib {
111 /* private: */ 111 /* private: */
112 u8 res[88]; 112 u8 res[88];
113 /* public: */ 113 /* public: */
114 u8 parm[QDIO_MAX_BUFFERS_PER_Q]; 114 u8 parm[128];
115} __attribute__ ((packed, aligned(256))); 115} __attribute__ ((packed, aligned(256)));
116 116
117/** 117/**
diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
index bd2fd9a7821d..a470f1fa9f2a 100644
--- a/arch/s390/include/asm/uaccess.h
+++ b/arch/s390/include/asm/uaccess.h
@@ -83,7 +83,7 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long n);
83 __rc; \ 83 __rc; \
84}) 84})
85 85
86static inline int __put_user_fn(void *x, void __user *ptr, unsigned long size) 86static __always_inline int __put_user_fn(void *x, void __user *ptr, unsigned long size)
87{ 87{
88 unsigned long spec = 0x010000UL; 88 unsigned long spec = 0x010000UL;
89 int rc; 89 int rc;
@@ -113,7 +113,7 @@ static inline int __put_user_fn(void *x, void __user *ptr, unsigned long size)
113 return rc; 113 return rc;
114} 114}
115 115
116static inline int __get_user_fn(void *x, const void __user *ptr, unsigned long size) 116static __always_inline int __get_user_fn(void *x, const void __user *ptr, unsigned long size)
117{ 117{
118 unsigned long spec = 0x01UL; 118 unsigned long spec = 0x01UL;
119 int rc; 119 int rc;
diff --git a/arch/s390/kernel/perf_cpum_cf_diag.c b/arch/s390/kernel/perf_cpum_cf_diag.c
index 5f1fd1581330..2654e348801a 100644
--- a/arch/s390/kernel/perf_cpum_cf_diag.c
+++ b/arch/s390/kernel/perf_cpum_cf_diag.c
@@ -390,7 +390,7 @@ static size_t cf_diag_getctrset(struct cf_ctrset_entry *ctrdata, int ctrset,
390 390
391 debug_sprintf_event(cf_diag_dbg, 6, 391 debug_sprintf_event(cf_diag_dbg, 6,
392 "%s ctrset %d ctrset_size %zu cfvn %d csvn %d" 392 "%s ctrset %d ctrset_size %zu cfvn %d csvn %d"
393 " need %zd rc:%d\n", 393 " need %zd rc %d\n",
394 __func__, ctrset, ctrset_size, cpuhw->info.cfvn, 394 __func__, ctrset, ctrset_size, cpuhw->info.cfvn,
395 cpuhw->info.csvn, need, rc); 395 cpuhw->info.csvn, need, rc);
396 return need; 396 return need;
@@ -567,7 +567,7 @@ static int cf_diag_add(struct perf_event *event, int flags)
567 int err = 0; 567 int err = 0;
568 568
569 debug_sprintf_event(cf_diag_dbg, 5, 569 debug_sprintf_event(cf_diag_dbg, 5,
570 "%s event %p cpu %d flags %#x cpuhw:%p\n", 570 "%s event %p cpu %d flags %#x cpuhw %p\n",
571 __func__, event, event->cpu, flags, cpuhw); 571 __func__, event, event->cpu, flags, cpuhw);
572 572
573 if (cpuhw->flags & PMU_F_IN_USE) { 573 if (cpuhw->flags & PMU_F_IN_USE) {
diff --git a/arch/s390/kernel/perf_cpum_sf.c b/arch/s390/kernel/perf_cpum_sf.c
index 544a02e944c6..3d8b12a9a6ff 100644
--- a/arch/s390/kernel/perf_cpum_sf.c
+++ b/arch/s390/kernel/perf_cpum_sf.c
@@ -803,6 +803,12 @@ static int __hw_perf_event_init(struct perf_event *event)
803 goto out; 803 goto out;
804 } 804 }
805 805
806 if (si.ribm & CPU_MF_SF_RIBM_NOTAV) {
807 pr_warn("CPU Measurement Facility sampling is temporarily not available\n");
808 err = -EBUSY;
809 goto out;
810 }
811
806 /* Always enable basic sampling */ 812 /* Always enable basic sampling */
807 SAMPL_FLAGS(hwc) = PERF_CPUM_SF_BASIC_MODE; 813 SAMPL_FLAGS(hwc) = PERF_CPUM_SF_BASIC_MODE;
808 814
@@ -895,7 +901,7 @@ static int cpumsf_pmu_event_init(struct perf_event *event)
895 901
896 /* Check online status of the CPU to which the event is pinned */ 902 /* Check online status of the CPU to which the event is pinned */
897 if (event->cpu >= 0 && !cpu_online(event->cpu)) 903 if (event->cpu >= 0 && !cpu_online(event->cpu))
898 return -ENODEV; 904 return -ENODEV;
899 905
900 /* Force reset of idle/hv excludes regardless of what the 906 /* Force reset of idle/hv excludes regardless of what the
901 * user requested. 907 * user requested.
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index f6db0f1bc867..d047e846e1b9 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -332,7 +332,7 @@ static inline int plo_test_bit(unsigned char nr)
332 return cc == 0; 332 return cc == 0;
333} 333}
334 334
335static inline void __insn32_query(unsigned int opcode, u8 query[32]) 335static __always_inline void __insn32_query(unsigned int opcode, u8 *query)
336{ 336{
337 register unsigned long r0 asm("0") = 0; /* query function */ 337 register unsigned long r0 asm("0") = 0; /* query function */
338 register unsigned long r1 asm("1") = (unsigned long) query; 338 register unsigned long r1 asm("1") = (unsigned long) query;
@@ -340,9 +340,9 @@ static inline void __insn32_query(unsigned int opcode, u8 query[32])
340 asm volatile( 340 asm volatile(
341 /* Parameter regs are ignored */ 341 /* Parameter regs are ignored */
342 " .insn rrf,%[opc] << 16,2,4,6,0\n" 342 " .insn rrf,%[opc] << 16,2,4,6,0\n"
343 : "=m" (*query) 343 :
344 : "d" (r0), "a" (r1), [opc] "i" (opcode) 344 : "d" (r0), "a" (r1), [opc] "i" (opcode)
345 : "cc"); 345 : "cc", "memory");
346} 346}
347 347
348#define INSN_SORTL 0xb938 348#define INSN_SORTL 0xb938
diff --git a/arch/s390/pci/pci_clp.c b/arch/s390/pci/pci_clp.c
index 9bdff4defef1..e585a62d6530 100644
--- a/arch/s390/pci/pci_clp.c
+++ b/arch/s390/pci/pci_clp.c
@@ -66,7 +66,7 @@ static inline int clp_get_ilp(unsigned long *ilp)
66/* 66/*
67 * Call Logical Processor with c=0, the give constant lps and an lpcb request. 67 * Call Logical Processor with c=0, the give constant lps and an lpcb request.
68 */ 68 */
69static inline int clp_req(void *data, unsigned int lps) 69static __always_inline int clp_req(void *data, unsigned int lps)
70{ 70{
71 struct { u8 _[CLP_BLK_SIZE]; } *req = data; 71 struct { u8 _[CLP_BLK_SIZE]; } *req = data;
72 u64 ignored; 72 u64 ignored;
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index fbc1aecf0f94..eb24cb1afc11 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -29,7 +29,6 @@ config SPARC
29 select RTC_DRV_M48T59 29 select RTC_DRV_M48T59
30 select RTC_SYSTOHC 30 select RTC_SYSTOHC
31 select HAVE_ARCH_JUMP_LABEL if SPARC64 31 select HAVE_ARCH_JUMP_LABEL if SPARC64
32 select HAVE_FAST_GUP if SPARC64
33 select GENERIC_IRQ_SHOW 32 select GENERIC_IRQ_SHOW
34 select ARCH_WANT_IPC_PARSE_VERSION 33 select ARCH_WANT_IPC_PARSE_VERSION
35 select GENERIC_PCI_IOMAP 34 select GENERIC_PCI_IOMAP
diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
index e7d35f60d53f..64c3e70b0556 100644
--- a/arch/x86/events/amd/core.c
+++ b/arch/x86/events/amd/core.c
@@ -5,12 +5,14 @@
5#include <linux/init.h> 5#include <linux/init.h>
6#include <linux/slab.h> 6#include <linux/slab.h>
7#include <linux/delay.h> 7#include <linux/delay.h>
8#include <linux/jiffies.h>
8#include <asm/apicdef.h> 9#include <asm/apicdef.h>
9#include <asm/nmi.h> 10#include <asm/nmi.h>
10 11
11#include "../perf_event.h" 12#include "../perf_event.h"
12 13
13static DEFINE_PER_CPU(unsigned int, perf_nmi_counter); 14static DEFINE_PER_CPU(unsigned long, perf_nmi_tstamp);
15static unsigned long perf_nmi_window;
14 16
15static __initconst const u64 amd_hw_cache_event_ids 17static __initconst const u64 amd_hw_cache_event_ids
16 [PERF_COUNT_HW_CACHE_MAX] 18 [PERF_COUNT_HW_CACHE_MAX]
@@ -641,11 +643,12 @@ static void amd_pmu_disable_event(struct perf_event *event)
641 * handler when multiple PMCs are active or PMC overflow while handling some 643 * handler when multiple PMCs are active or PMC overflow while handling some
642 * other source of an NMI. 644 * other source of an NMI.
643 * 645 *
644 * Attempt to mitigate this by using the number of active PMCs to determine 646 * Attempt to mitigate this by creating an NMI window in which un-handled NMIs
645 * whether to return NMI_HANDLED if the perf NMI handler did not handle/reset 647 * received during this window will be claimed. This prevents extending the
646 * any PMCs. The per-CPU perf_nmi_counter variable is set to a minimum of the 648 * window past when it is possible that latent NMIs should be received. The
647 * number of active PMCs or 2. The value of 2 is used in case an NMI does not 649 * per-CPU perf_nmi_tstamp will be set to the window end time whenever perf has
648 * arrive at the LAPIC in time to be collapsed into an already pending NMI. 650 * handled a counter. When an un-handled NMI is received, it will be claimed
651 * only if arriving within that window.
649 */ 652 */
650static int amd_pmu_handle_irq(struct pt_regs *regs) 653static int amd_pmu_handle_irq(struct pt_regs *regs)
651{ 654{
@@ -663,21 +666,19 @@ static int amd_pmu_handle_irq(struct pt_regs *regs)
663 handled = x86_pmu_handle_irq(regs); 666 handled = x86_pmu_handle_irq(regs);
664 667
665 /* 668 /*
666 * If a counter was handled, record the number of possible remaining 669 * If a counter was handled, record a timestamp such that un-handled
667 * NMIs that can occur. 670 * NMIs will be claimed if arriving within that window.
668 */ 671 */
669 if (handled) { 672 if (handled) {
670 this_cpu_write(perf_nmi_counter, 673 this_cpu_write(perf_nmi_tstamp,
671 min_t(unsigned int, 2, active)); 674 jiffies + perf_nmi_window);
672 675
673 return handled; 676 return handled;
674 } 677 }
675 678
676 if (!this_cpu_read(perf_nmi_counter)) 679 if (time_after(jiffies, this_cpu_read(perf_nmi_tstamp)))
677 return NMI_DONE; 680 return NMI_DONE;
678 681
679 this_cpu_dec(perf_nmi_counter);
680
681 return NMI_HANDLED; 682 return NMI_HANDLED;
682} 683}
683 684
@@ -909,6 +910,9 @@ static int __init amd_core_pmu_init(void)
909 if (!boot_cpu_has(X86_FEATURE_PERFCTR_CORE)) 910 if (!boot_cpu_has(X86_FEATURE_PERFCTR_CORE))
910 return 0; 911 return 0;
911 912
913 /* Avoid calulating the value each time in the NMI handler */
914 perf_nmi_window = msecs_to_jiffies(100);
915
912 switch (boot_cpu_data.x86) { 916 switch (boot_cpu_data.x86) {
913 case 0x15: 917 case 0x15:
914 pr_cont("Fam15h "); 918 pr_cont("Fam15h ");
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 27ee47a7be66..fcef678c3423 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -4983,6 +4983,8 @@ __init int intel_pmu_init(void)
4983 case INTEL_FAM6_SKYLAKE: 4983 case INTEL_FAM6_SKYLAKE:
4984 case INTEL_FAM6_KABYLAKE_L: 4984 case INTEL_FAM6_KABYLAKE_L:
4985 case INTEL_FAM6_KABYLAKE: 4985 case INTEL_FAM6_KABYLAKE:
4986 case INTEL_FAM6_COMETLAKE_L:
4987 case INTEL_FAM6_COMETLAKE:
4986 x86_add_quirk(intel_pebs_isolation_quirk); 4988 x86_add_quirk(intel_pebs_isolation_quirk);
4987 x86_pmu.late_ack = true; 4989 x86_pmu.late_ack = true;
4988 memcpy(hw_cache_event_ids, skl_hw_cache_event_ids, sizeof(hw_cache_event_ids)); 4990 memcpy(hw_cache_event_ids, skl_hw_cache_event_ids, sizeof(hw_cache_event_ids));
@@ -5031,6 +5033,8 @@ __init int intel_pmu_init(void)
5031 /* fall through */ 5033 /* fall through */
5032 case INTEL_FAM6_ICELAKE_L: 5034 case INTEL_FAM6_ICELAKE_L:
5033 case INTEL_FAM6_ICELAKE: 5035 case INTEL_FAM6_ICELAKE:
5036 case INTEL_FAM6_TIGERLAKE_L:
5037 case INTEL_FAM6_TIGERLAKE:
5034 x86_pmu.late_ack = true; 5038 x86_pmu.late_ack = true;
5035 memcpy(hw_cache_event_ids, skl_hw_cache_event_ids, sizeof(hw_cache_event_ids)); 5039 memcpy(hw_cache_event_ids, skl_hw_cache_event_ids, sizeof(hw_cache_event_ids));
5036 memcpy(hw_cache_extra_regs, skl_hw_cache_extra_regs, sizeof(hw_cache_extra_regs)); 5040 memcpy(hw_cache_extra_regs, skl_hw_cache_extra_regs, sizeof(hw_cache_extra_regs));
diff --git a/arch/x86/events/intel/cstate.c b/arch/x86/events/intel/cstate.c
index 9f2f39003d96..e1daf4151e11 100644
--- a/arch/x86/events/intel/cstate.c
+++ b/arch/x86/events/intel/cstate.c
@@ -45,46 +45,49 @@
45 * MSR_CORE_C3_RESIDENCY: CORE C3 Residency Counter 45 * MSR_CORE_C3_RESIDENCY: CORE C3 Residency Counter
46 * perf code: 0x01 46 * perf code: 0x01
47 * Available model: NHM,WSM,SNB,IVB,HSW,BDW,SKL,GLM, 47 * Available model: NHM,WSM,SNB,IVB,HSW,BDW,SKL,GLM,
48 CNL 48 * CNL,KBL,CML
49 * Scope: Core 49 * Scope: Core
50 * MSR_CORE_C6_RESIDENCY: CORE C6 Residency Counter 50 * MSR_CORE_C6_RESIDENCY: CORE C6 Residency Counter
51 * perf code: 0x02 51 * perf code: 0x02
52 * Available model: SLM,AMT,NHM,WSM,SNB,IVB,HSW,BDW, 52 * Available model: SLM,AMT,NHM,WSM,SNB,IVB,HSW,BDW,
53 * SKL,KNL,GLM,CNL 53 * SKL,KNL,GLM,CNL,KBL,CML,ICL,TGL
54 * Scope: Core 54 * Scope: Core
55 * MSR_CORE_C7_RESIDENCY: CORE C7 Residency Counter 55 * MSR_CORE_C7_RESIDENCY: CORE C7 Residency Counter
56 * perf code: 0x03 56 * perf code: 0x03
57 * Available model: SNB,IVB,HSW,BDW,SKL,CNL 57 * Available model: SNB,IVB,HSW,BDW,SKL,CNL,KBL,CML,
58 * ICL,TGL
58 * Scope: Core 59 * Scope: Core
59 * MSR_PKG_C2_RESIDENCY: Package C2 Residency Counter. 60 * MSR_PKG_C2_RESIDENCY: Package C2 Residency Counter.
60 * perf code: 0x00 61 * perf code: 0x00
61 * Available model: SNB,IVB,HSW,BDW,SKL,KNL,GLM,CNL 62 * Available model: SNB,IVB,HSW,BDW,SKL,KNL,GLM,CNL,
63 * KBL,CML,ICL,TGL
62 * Scope: Package (physical package) 64 * Scope: Package (physical package)
63 * MSR_PKG_C3_RESIDENCY: Package C3 Residency Counter. 65 * MSR_PKG_C3_RESIDENCY: Package C3 Residency Counter.
64 * perf code: 0x01 66 * perf code: 0x01
65 * Available model: NHM,WSM,SNB,IVB,HSW,BDW,SKL,KNL, 67 * Available model: NHM,WSM,SNB,IVB,HSW,BDW,SKL,KNL,
66 * GLM,CNL 68 * GLM,CNL,KBL,CML,ICL,TGL
67 * Scope: Package (physical package) 69 * Scope: Package (physical package)
68 * MSR_PKG_C6_RESIDENCY: Package C6 Residency Counter. 70 * MSR_PKG_C6_RESIDENCY: Package C6 Residency Counter.
69 * perf code: 0x02 71 * perf code: 0x02
70 * Available model: SLM,AMT,NHM,WSM,SNB,IVB,HSW,BDW 72 * Available model: SLM,AMT,NHM,WSM,SNB,IVB,HSW,BDW
71 * SKL,KNL,GLM,CNL 73 * SKL,KNL,GLM,CNL,KBL,CML,ICL,TGL
72 * Scope: Package (physical package) 74 * Scope: Package (physical package)
73 * MSR_PKG_C7_RESIDENCY: Package C7 Residency Counter. 75 * MSR_PKG_C7_RESIDENCY: Package C7 Residency Counter.
74 * perf code: 0x03 76 * perf code: 0x03
75 * Available model: NHM,WSM,SNB,IVB,HSW,BDW,SKL,CNL 77 * Available model: NHM,WSM,SNB,IVB,HSW,BDW,SKL,CNL,
78 * KBL,CML,ICL,TGL
76 * Scope: Package (physical package) 79 * Scope: Package (physical package)
77 * MSR_PKG_C8_RESIDENCY: Package C8 Residency Counter. 80 * MSR_PKG_C8_RESIDENCY: Package C8 Residency Counter.
78 * perf code: 0x04 81 * perf code: 0x04
79 * Available model: HSW ULT,KBL,CNL 82 * Available model: HSW ULT,KBL,CNL,CML,ICL,TGL
80 * Scope: Package (physical package) 83 * Scope: Package (physical package)
81 * MSR_PKG_C9_RESIDENCY: Package C9 Residency Counter. 84 * MSR_PKG_C9_RESIDENCY: Package C9 Residency Counter.
82 * perf code: 0x05 85 * perf code: 0x05
83 * Available model: HSW ULT,KBL,CNL 86 * Available model: HSW ULT,KBL,CNL,CML,ICL,TGL
84 * Scope: Package (physical package) 87 * Scope: Package (physical package)
85 * MSR_PKG_C10_RESIDENCY: Package C10 Residency Counter. 88 * MSR_PKG_C10_RESIDENCY: Package C10 Residency Counter.
86 * perf code: 0x06 89 * perf code: 0x06
87 * Available model: HSW ULT,KBL,GLM,CNL 90 * Available model: HSW ULT,KBL,GLM,CNL,CML,ICL,TGL
88 * Scope: Package (physical package) 91 * Scope: Package (physical package)
89 * 92 *
90 */ 93 */
@@ -544,6 +547,19 @@ static const struct cstate_model cnl_cstates __initconst = {
544 BIT(PERF_CSTATE_PKG_C10_RES), 547 BIT(PERF_CSTATE_PKG_C10_RES),
545}; 548};
546 549
550static const struct cstate_model icl_cstates __initconst = {
551 .core_events = BIT(PERF_CSTATE_CORE_C6_RES) |
552 BIT(PERF_CSTATE_CORE_C7_RES),
553
554 .pkg_events = BIT(PERF_CSTATE_PKG_C2_RES) |
555 BIT(PERF_CSTATE_PKG_C3_RES) |
556 BIT(PERF_CSTATE_PKG_C6_RES) |
557 BIT(PERF_CSTATE_PKG_C7_RES) |
558 BIT(PERF_CSTATE_PKG_C8_RES) |
559 BIT(PERF_CSTATE_PKG_C9_RES) |
560 BIT(PERF_CSTATE_PKG_C10_RES),
561};
562
547static const struct cstate_model slm_cstates __initconst = { 563static const struct cstate_model slm_cstates __initconst = {
548 .core_events = BIT(PERF_CSTATE_CORE_C1_RES) | 564 .core_events = BIT(PERF_CSTATE_CORE_C1_RES) |
549 BIT(PERF_CSTATE_CORE_C6_RES), 565 BIT(PERF_CSTATE_CORE_C6_RES),
@@ -614,6 +630,8 @@ static const struct x86_cpu_id intel_cstates_match[] __initconst = {
614 630
615 X86_CSTATES_MODEL(INTEL_FAM6_KABYLAKE_L, hswult_cstates), 631 X86_CSTATES_MODEL(INTEL_FAM6_KABYLAKE_L, hswult_cstates),
616 X86_CSTATES_MODEL(INTEL_FAM6_KABYLAKE, hswult_cstates), 632 X86_CSTATES_MODEL(INTEL_FAM6_KABYLAKE, hswult_cstates),
633 X86_CSTATES_MODEL(INTEL_FAM6_COMETLAKE_L, hswult_cstates),
634 X86_CSTATES_MODEL(INTEL_FAM6_COMETLAKE, hswult_cstates),
617 635
618 X86_CSTATES_MODEL(INTEL_FAM6_CANNONLAKE_L, cnl_cstates), 636 X86_CSTATES_MODEL(INTEL_FAM6_CANNONLAKE_L, cnl_cstates),
619 637
@@ -625,8 +643,10 @@ static const struct x86_cpu_id intel_cstates_match[] __initconst = {
625 643
626 X86_CSTATES_MODEL(INTEL_FAM6_ATOM_GOLDMONT_PLUS, glm_cstates), 644 X86_CSTATES_MODEL(INTEL_FAM6_ATOM_GOLDMONT_PLUS, glm_cstates),
627 645
628 X86_CSTATES_MODEL(INTEL_FAM6_ICELAKE_L, snb_cstates), 646 X86_CSTATES_MODEL(INTEL_FAM6_ICELAKE_L, icl_cstates),
629 X86_CSTATES_MODEL(INTEL_FAM6_ICELAKE, snb_cstates), 647 X86_CSTATES_MODEL(INTEL_FAM6_ICELAKE, icl_cstates),
648 X86_CSTATES_MODEL(INTEL_FAM6_TIGERLAKE_L, icl_cstates),
649 X86_CSTATES_MODEL(INTEL_FAM6_TIGERLAKE, icl_cstates),
630 { }, 650 { },
631}; 651};
632MODULE_DEVICE_TABLE(x86cpu, intel_cstates_match); 652MODULE_DEVICE_TABLE(x86cpu, intel_cstates_match);
diff --git a/arch/x86/events/msr.c b/arch/x86/events/msr.c
index b1afc77f0704..6f86650b3f77 100644
--- a/arch/x86/events/msr.c
+++ b/arch/x86/events/msr.c
@@ -89,7 +89,14 @@ static bool test_intel(int idx, void *data)
89 case INTEL_FAM6_SKYLAKE_X: 89 case INTEL_FAM6_SKYLAKE_X:
90 case INTEL_FAM6_KABYLAKE_L: 90 case INTEL_FAM6_KABYLAKE_L:
91 case INTEL_FAM6_KABYLAKE: 91 case INTEL_FAM6_KABYLAKE:
92 case INTEL_FAM6_COMETLAKE_L:
93 case INTEL_FAM6_COMETLAKE:
92 case INTEL_FAM6_ICELAKE_L: 94 case INTEL_FAM6_ICELAKE_L:
95 case INTEL_FAM6_ICELAKE:
96 case INTEL_FAM6_ICELAKE_X:
97 case INTEL_FAM6_ICELAKE_D:
98 case INTEL_FAM6_TIGERLAKE_L:
99 case INTEL_FAM6_TIGERLAKE:
93 if (idx == PERF_MSR_SMI || idx == PERF_MSR_PPERF) 100 if (idx == PERF_MSR_SMI || idx == PERF_MSR_PPERF)
94 return true; 101 return true;
95 break; 102 break;
diff --git a/arch/x86/include/asm/cpu_entry_area.h b/arch/x86/include/asm/cpu_entry_area.h
index cff3f3f3bfe0..8348f7d69fd5 100644
--- a/arch/x86/include/asm/cpu_entry_area.h
+++ b/arch/x86/include/asm/cpu_entry_area.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2 2
3#ifndef _ASM_X86_CPU_ENTRY_AREA_H 3#ifndef _ASM_X86_CPU_ENTRY_AREA_H
4#define _ASM_X86_CPU_ENTRY_AREA_H 4#define _ASM_X86_CPU_ENTRY_AREA_H
diff --git a/arch/x86/include/asm/intel-family.h b/arch/x86/include/asm/intel-family.h
index f04622500da3..c606c0b70738 100644
--- a/arch/x86/include/asm/intel-family.h
+++ b/arch/x86/include/asm/intel-family.h
@@ -83,6 +83,9 @@
83#define INTEL_FAM6_TIGERLAKE_L 0x8C 83#define INTEL_FAM6_TIGERLAKE_L 0x8C
84#define INTEL_FAM6_TIGERLAKE 0x8D 84#define INTEL_FAM6_TIGERLAKE 0x8D
85 85
86#define INTEL_FAM6_COMETLAKE 0xA5
87#define INTEL_FAM6_COMETLAKE_L 0xA6
88
86/* "Small Core" Processors (Atom) */ 89/* "Small Core" Processors (Atom) */
87 90
88#define INTEL_FAM6_ATOM_BONNELL 0x1C /* Diamondville, Pineview */ 91#define INTEL_FAM6_ATOM_BONNELL 0x1C /* Diamondville, Pineview */
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 23edf56cf577..50eb430b0ad8 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -219,13 +219,6 @@ enum {
219 PFERR_WRITE_MASK | \ 219 PFERR_WRITE_MASK | \
220 PFERR_PRESENT_MASK) 220 PFERR_PRESENT_MASK)
221 221
222/*
223 * The mask used to denote special SPTEs, which can be either MMIO SPTEs or
224 * Access Tracking SPTEs. We use bit 62 instead of bit 63 to avoid conflicting
225 * with the SVE bit in EPT PTEs.
226 */
227#define SPTE_SPECIAL_MASK (1ULL << 62)
228
229/* apic attention bits */ 222/* apic attention bits */
230#define KVM_APIC_CHECK_VAPIC 0 223#define KVM_APIC_CHECK_VAPIC 0
231/* 224/*
diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
index e28f8b723b5c..9d5252c9685c 100644
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -21,7 +21,7 @@
21#define MWAIT_ECX_INTERRUPT_BREAK 0x1 21#define MWAIT_ECX_INTERRUPT_BREAK 0x1
22#define MWAITX_ECX_TIMER_ENABLE BIT(1) 22#define MWAITX_ECX_TIMER_ENABLE BIT(1)
23#define MWAITX_MAX_LOOPS ((u32)-1) 23#define MWAITX_MAX_LOOPS ((u32)-1)
24#define MWAITX_DISABLE_CSTATES 0xf 24#define MWAITX_DISABLE_CSTATES 0xf0
25 25
26static inline void __monitor(const void *eax, unsigned long ecx, 26static inline void __monitor(const void *eax, unsigned long ecx,
27 unsigned long edx) 27 unsigned long edx)
diff --git a/arch/x86/include/asm/pti.h b/arch/x86/include/asm/pti.h
index 5df09a0b80b8..07375b476c4f 100644
--- a/arch/x86/include/asm/pti.h
+++ b/arch/x86/include/asm/pti.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_X86_PTI_H 2#ifndef _ASM_X86_PTI_H
3#define _ASM_X86_PTI_H 3#define _ASM_X86_PTI_H
4#ifndef __ASSEMBLY__ 4#ifndef __ASSEMBLY__
diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index 35c225ede0e4..61d93f062a36 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -734,5 +734,28 @@ do { \
734 if (unlikely(__gu_err)) goto err_label; \ 734 if (unlikely(__gu_err)) goto err_label; \
735} while (0) 735} while (0)
736 736
737/*
738 * We want the unsafe accessors to always be inlined and use
739 * the error labels - thus the macro games.
740 */
741#define unsafe_copy_loop(dst, src, len, type, label) \
742 while (len >= sizeof(type)) { \
743 unsafe_put_user(*(type *)src,(type __user *)dst,label); \
744 dst += sizeof(type); \
745 src += sizeof(type); \
746 len -= sizeof(type); \
747 }
748
749#define unsafe_copy_to_user(_dst,_src,_len,label) \
750do { \
751 char __user *__ucu_dst = (_dst); \
752 const char *__ucu_src = (_src); \
753 size_t __ucu_len = (_len); \
754 unsafe_copy_loop(__ucu_dst, __ucu_src, __ucu_len, u64, label); \
755 unsafe_copy_loop(__ucu_dst, __ucu_src, __ucu_len, u32, label); \
756 unsafe_copy_loop(__ucu_dst, __ucu_src, __ucu_len, u16, label); \
757 unsafe_copy_loop(__ucu_dst, __ucu_src, __ucu_len, u8, label); \
758} while (0)
759
737#endif /* _ASM_X86_UACCESS_H */ 760#endif /* _ASM_X86_UACCESS_H */
738 761
diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
index 9735139cfdf8..46d732696c1c 100644
--- a/arch/x86/kernel/cpu/vmware.c
+++ b/arch/x86/kernel/cpu/vmware.c
@@ -49,7 +49,7 @@
49#define VMWARE_CMD_VCPU_RESERVED 31 49#define VMWARE_CMD_VCPU_RESERVED 31
50 50
51#define VMWARE_PORT(cmd, eax, ebx, ecx, edx) \ 51#define VMWARE_PORT(cmd, eax, ebx, ecx, edx) \
52 __asm__("inl (%%dx)" : \ 52 __asm__("inl (%%dx), %%eax" : \
53 "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ 53 "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \
54 "a"(VMWARE_HYPERVISOR_MAGIC), \ 54 "a"(VMWARE_HYPERVISOR_MAGIC), \
55 "c"(VMWARE_CMD_##cmd), \ 55 "c"(VMWARE_CMD_##cmd), \
diff --git a/arch/x86/kernel/process.h b/arch/x86/kernel/process.h
index 320ab978fb1f..1d0797b2338a 100644
--- a/arch/x86/kernel/process.h
+++ b/arch/x86/kernel/process.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2// 2//
3// Code shared between 32 and 64 bit 3// Code shared between 32 and 64 bit
4 4
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 63316036f85a..9c5029cf6f3f 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -485,6 +485,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
485 485
486 /* cpuid 0x80000008.ebx */ 486 /* cpuid 0x80000008.ebx */
487 const u32 kvm_cpuid_8000_0008_ebx_x86_features = 487 const u32 kvm_cpuid_8000_0008_ebx_x86_features =
488 F(CLZERO) | F(XSAVEERPTR) |
488 F(WBNOINVD) | F(AMD_IBPB) | F(AMD_IBRS) | F(AMD_SSBD) | F(VIRT_SSBD) | 489 F(WBNOINVD) | F(AMD_IBPB) | F(AMD_IBRS) | F(AMD_SSBD) | F(VIRT_SSBD) |
489 F(AMD_SSB_NO) | F(AMD_STIBP) | F(AMD_STIBP_ALWAYS_ON); 490 F(AMD_SSB_NO) | F(AMD_STIBP) | F(AMD_STIBP_ALWAYS_ON);
490 491
@@ -618,16 +619,20 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
618 */ 619 */
619 case 0x1f: 620 case 0x1f:
620 case 0xb: { 621 case 0xb: {
621 int i, level_type; 622 int i;
622 623
623 /* read more entries until level_type is zero */ 624 /*
624 for (i = 1; ; ++i) { 625 * We filled in entry[0] for CPUID(EAX=<function>,
626 * ECX=00H) above. If its level type (ECX[15:8]) is
627 * zero, then the leaf is unimplemented, and we're
628 * done. Otherwise, continue to populate entries
629 * until the level type (ECX[15:8]) of the previously
630 * added entry is zero.
631 */
632 for (i = 1; entry[i - 1].ecx & 0xff00; ++i) {
625 if (*nent >= maxnent) 633 if (*nent >= maxnent)
626 goto out; 634 goto out;
627 635
628 level_type = entry[i - 1].ecx & 0xff00;
629 if (!level_type)
630 break;
631 do_host_cpuid(&entry[i], function, i); 636 do_host_cpuid(&entry[i], function, i);
632 ++*nent; 637 ++*nent;
633 } 638 }
@@ -969,53 +974,66 @@ struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
969EXPORT_SYMBOL_GPL(kvm_find_cpuid_entry); 974EXPORT_SYMBOL_GPL(kvm_find_cpuid_entry);
970 975
971/* 976/*
972 * If no match is found, check whether we exceed the vCPU's limit 977 * If the basic or extended CPUID leaf requested is higher than the
973 * and return the content of the highest valid _standard_ leaf instead. 978 * maximum supported basic or extended leaf, respectively, then it is
974 * This is to satisfy the CPUID specification. 979 * out of range.
975 */ 980 */
976static struct kvm_cpuid_entry2* check_cpuid_limit(struct kvm_vcpu *vcpu, 981static bool cpuid_function_in_range(struct kvm_vcpu *vcpu, u32 function)
977 u32 function, u32 index)
978{ 982{
979 struct kvm_cpuid_entry2 *maxlevel; 983 struct kvm_cpuid_entry2 *max;
980 984
981 maxlevel = kvm_find_cpuid_entry(vcpu, function & 0x80000000, 0); 985 max = kvm_find_cpuid_entry(vcpu, function & 0x80000000, 0);
982 if (!maxlevel || maxlevel->eax >= function) 986 return max && function <= max->eax;
983 return NULL;
984 if (function & 0x80000000) {
985 maxlevel = kvm_find_cpuid_entry(vcpu, 0, 0);
986 if (!maxlevel)
987 return NULL;
988 }
989 return kvm_find_cpuid_entry(vcpu, maxlevel->eax, index);
990} 987}
991 988
992bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, 989bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
993 u32 *ecx, u32 *edx, bool check_limit) 990 u32 *ecx, u32 *edx, bool check_limit)
994{ 991{
995 u32 function = *eax, index = *ecx; 992 u32 function = *eax, index = *ecx;
996 struct kvm_cpuid_entry2 *best; 993 struct kvm_cpuid_entry2 *entry;
997 bool entry_found = true; 994 struct kvm_cpuid_entry2 *max;
998 995 bool found;
999 best = kvm_find_cpuid_entry(vcpu, function, index);
1000
1001 if (!best) {
1002 entry_found = false;
1003 if (!check_limit)
1004 goto out;
1005 996
1006 best = check_cpuid_limit(vcpu, function, index); 997 entry = kvm_find_cpuid_entry(vcpu, function, index);
998 found = entry;
999 /*
1000 * Intel CPUID semantics treats any query for an out-of-range
1001 * leaf as if the highest basic leaf (i.e. CPUID.0H:EAX) were
1002 * requested. AMD CPUID semantics returns all zeroes for any
1003 * undefined leaf, whether or not the leaf is in range.
1004 */
1005 if (!entry && check_limit && !guest_cpuid_is_amd(vcpu) &&
1006 !cpuid_function_in_range(vcpu, function)) {
1007 max = kvm_find_cpuid_entry(vcpu, 0, 0);
1008 if (max) {
1009 function = max->eax;
1010 entry = kvm_find_cpuid_entry(vcpu, function, index);
1011 }
1007 } 1012 }
1008 1013 if (entry) {
1009out: 1014 *eax = entry->eax;
1010 if (best) { 1015 *ebx = entry->ebx;
1011 *eax = best->eax; 1016 *ecx = entry->ecx;
1012 *ebx = best->ebx; 1017 *edx = entry->edx;
1013 *ecx = best->ecx; 1018 } else {
1014 *edx = best->edx;
1015 } else
1016 *eax = *ebx = *ecx = *edx = 0; 1019 *eax = *ebx = *ecx = *edx = 0;
1017 trace_kvm_cpuid(function, *eax, *ebx, *ecx, *edx, entry_found); 1020 /*
1018 return entry_found; 1021 * When leaf 0BH or 1FH is defined, CL is pass-through
1022 * and EDX is always the x2APIC ID, even for undefined
1023 * subleaves. Index 1 will exist iff the leaf is
1024 * implemented, so we pass through CL iff leaf 1
1025 * exists. EDX can be copied from any existing index.
1026 */
1027 if (function == 0xb || function == 0x1f) {
1028 entry = kvm_find_cpuid_entry(vcpu, function, 1);
1029 if (entry) {
1030 *ecx = index & 0xff;
1031 *edx = entry->edx;
1032 }
1033 }
1034 }
1035 trace_kvm_cpuid(function, *eax, *ebx, *ecx, *edx, found);
1036 return found;
1019} 1037}
1020EXPORT_SYMBOL_GPL(kvm_cpuid); 1038EXPORT_SYMBOL_GPL(kvm_cpuid);
1021 1039
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 3a3a6854dcca..87b0fcc23ef8 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -66,9 +66,10 @@
66#define X2APIC_BROADCAST 0xFFFFFFFFul 66#define X2APIC_BROADCAST 0xFFFFFFFFul
67 67
68static bool lapic_timer_advance_dynamic __read_mostly; 68static bool lapic_timer_advance_dynamic __read_mostly;
69#define LAPIC_TIMER_ADVANCE_ADJUST_MIN 100 69#define LAPIC_TIMER_ADVANCE_ADJUST_MIN 100 /* clock cycles */
70#define LAPIC_TIMER_ADVANCE_ADJUST_MAX 5000 70#define LAPIC_TIMER_ADVANCE_ADJUST_MAX 10000 /* clock cycles */
71#define LAPIC_TIMER_ADVANCE_ADJUST_INIT 1000 71#define LAPIC_TIMER_ADVANCE_NS_INIT 1000
72#define LAPIC_TIMER_ADVANCE_NS_MAX 5000
72/* step-by-step approximation to mitigate fluctuation */ 73/* step-by-step approximation to mitigate fluctuation */
73#define LAPIC_TIMER_ADVANCE_ADJUST_STEP 8 74#define LAPIC_TIMER_ADVANCE_ADJUST_STEP 8
74 75
@@ -1504,8 +1505,8 @@ static inline void adjust_lapic_timer_advance(struct kvm_vcpu *vcpu,
1504 timer_advance_ns += ns/LAPIC_TIMER_ADVANCE_ADJUST_STEP; 1505 timer_advance_ns += ns/LAPIC_TIMER_ADVANCE_ADJUST_STEP;
1505 } 1506 }
1506 1507
1507 if (unlikely(timer_advance_ns > LAPIC_TIMER_ADVANCE_ADJUST_MAX)) 1508 if (unlikely(timer_advance_ns > LAPIC_TIMER_ADVANCE_NS_MAX))
1508 timer_advance_ns = LAPIC_TIMER_ADVANCE_ADJUST_INIT; 1509 timer_advance_ns = LAPIC_TIMER_ADVANCE_NS_INIT;
1509 apic->lapic_timer.timer_advance_ns = timer_advance_ns; 1510 apic->lapic_timer.timer_advance_ns = timer_advance_ns;
1510} 1511}
1511 1512
@@ -2302,7 +2303,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu, int timer_advance_ns)
2302 HRTIMER_MODE_ABS_HARD); 2303 HRTIMER_MODE_ABS_HARD);
2303 apic->lapic_timer.timer.function = apic_timer_fn; 2304 apic->lapic_timer.timer.function = apic_timer_fn;
2304 if (timer_advance_ns == -1) { 2305 if (timer_advance_ns == -1) {
2305 apic->lapic_timer.timer_advance_ns = LAPIC_TIMER_ADVANCE_ADJUST_INIT; 2306 apic->lapic_timer.timer_advance_ns = LAPIC_TIMER_ADVANCE_NS_INIT;
2306 lapic_timer_advance_dynamic = true; 2307 lapic_timer_advance_dynamic = true;
2307 } else { 2308 } else {
2308 apic->lapic_timer.timer_advance_ns = timer_advance_ns; 2309 apic->lapic_timer.timer_advance_ns = timer_advance_ns;
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 5269aa057dfa..24c23c66b226 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -83,7 +83,17 @@ module_param(dbg, bool, 0644);
83#define PTE_PREFETCH_NUM 8 83#define PTE_PREFETCH_NUM 8
84 84
85#define PT_FIRST_AVAIL_BITS_SHIFT 10 85#define PT_FIRST_AVAIL_BITS_SHIFT 10
86#define PT64_SECOND_AVAIL_BITS_SHIFT 52 86#define PT64_SECOND_AVAIL_BITS_SHIFT 54
87
88/*
89 * The mask used to denote special SPTEs, which can be either MMIO SPTEs or
90 * Access Tracking SPTEs.
91 */
92#define SPTE_SPECIAL_MASK (3ULL << 52)
93#define SPTE_AD_ENABLED_MASK (0ULL << 52)
94#define SPTE_AD_DISABLED_MASK (1ULL << 52)
95#define SPTE_AD_WRPROT_ONLY_MASK (2ULL << 52)
96#define SPTE_MMIO_MASK (3ULL << 52)
87 97
88#define PT64_LEVEL_BITS 9 98#define PT64_LEVEL_BITS 9
89 99
@@ -219,12 +229,11 @@ static u64 __read_mostly shadow_present_mask;
219static u64 __read_mostly shadow_me_mask; 229static u64 __read_mostly shadow_me_mask;
220 230
221/* 231/*
222 * SPTEs used by MMUs without A/D bits are marked with shadow_acc_track_value. 232 * SPTEs used by MMUs without A/D bits are marked with SPTE_AD_DISABLED_MASK;
223 * Non-present SPTEs with shadow_acc_track_value set are in place for access 233 * shadow_acc_track_mask is the set of bits to be cleared in non-accessed
224 * tracking. 234 * pages.
225 */ 235 */
226static u64 __read_mostly shadow_acc_track_mask; 236static u64 __read_mostly shadow_acc_track_mask;
227static const u64 shadow_acc_track_value = SPTE_SPECIAL_MASK;
228 237
229/* 238/*
230 * The mask/shift to use for saving the original R/X bits when marking the PTE 239 * The mask/shift to use for saving the original R/X bits when marking the PTE
@@ -304,7 +313,7 @@ void kvm_mmu_set_mmio_spte_mask(u64 mmio_mask, u64 mmio_value, u64 access_mask)
304{ 313{
305 BUG_ON((u64)(unsigned)access_mask != access_mask); 314 BUG_ON((u64)(unsigned)access_mask != access_mask);
306 BUG_ON((mmio_mask & mmio_value) != mmio_value); 315 BUG_ON((mmio_mask & mmio_value) != mmio_value);
307 shadow_mmio_value = mmio_value | SPTE_SPECIAL_MASK; 316 shadow_mmio_value = mmio_value | SPTE_MMIO_MASK;
308 shadow_mmio_mask = mmio_mask | SPTE_SPECIAL_MASK; 317 shadow_mmio_mask = mmio_mask | SPTE_SPECIAL_MASK;
309 shadow_mmio_access_mask = access_mask; 318 shadow_mmio_access_mask = access_mask;
310} 319}
@@ -320,10 +329,27 @@ static inline bool sp_ad_disabled(struct kvm_mmu_page *sp)
320 return sp->role.ad_disabled; 329 return sp->role.ad_disabled;
321} 330}
322 331
332static inline bool kvm_vcpu_ad_need_write_protect(struct kvm_vcpu *vcpu)
333{
334 /*
335 * When using the EPT page-modification log, the GPAs in the log
336 * would come from L2 rather than L1. Therefore, we need to rely
337 * on write protection to record dirty pages. This also bypasses
338 * PML, since writes now result in a vmexit.
339 */
340 return vcpu->arch.mmu == &vcpu->arch.guest_mmu;
341}
342
323static inline bool spte_ad_enabled(u64 spte) 343static inline bool spte_ad_enabled(u64 spte)
324{ 344{
325 MMU_WARN_ON(is_mmio_spte(spte)); 345 MMU_WARN_ON(is_mmio_spte(spte));
326 return !(spte & shadow_acc_track_value); 346 return (spte & SPTE_SPECIAL_MASK) != SPTE_AD_DISABLED_MASK;
347}
348
349static inline bool spte_ad_need_write_protect(u64 spte)
350{
351 MMU_WARN_ON(is_mmio_spte(spte));
352 return (spte & SPTE_SPECIAL_MASK) != SPTE_AD_ENABLED_MASK;
327} 353}
328 354
329static inline u64 spte_shadow_accessed_mask(u64 spte) 355static inline u64 spte_shadow_accessed_mask(u64 spte)
@@ -461,7 +487,7 @@ void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask,
461{ 487{
462 BUG_ON(!dirty_mask != !accessed_mask); 488 BUG_ON(!dirty_mask != !accessed_mask);
463 BUG_ON(!accessed_mask && !acc_track_mask); 489 BUG_ON(!accessed_mask && !acc_track_mask);
464 BUG_ON(acc_track_mask & shadow_acc_track_value); 490 BUG_ON(acc_track_mask & SPTE_SPECIAL_MASK);
465 491
466 shadow_user_mask = user_mask; 492 shadow_user_mask = user_mask;
467 shadow_accessed_mask = accessed_mask; 493 shadow_accessed_mask = accessed_mask;
@@ -1589,16 +1615,16 @@ static bool spte_clear_dirty(u64 *sptep)
1589 1615
1590 rmap_printk("rmap_clear_dirty: spte %p %llx\n", sptep, *sptep); 1616 rmap_printk("rmap_clear_dirty: spte %p %llx\n", sptep, *sptep);
1591 1617
1618 MMU_WARN_ON(!spte_ad_enabled(spte));
1592 spte &= ~shadow_dirty_mask; 1619 spte &= ~shadow_dirty_mask;
1593
1594 return mmu_spte_update(sptep, spte); 1620 return mmu_spte_update(sptep, spte);
1595} 1621}
1596 1622
1597static bool wrprot_ad_disabled_spte(u64 *sptep) 1623static bool spte_wrprot_for_clear_dirty(u64 *sptep)
1598{ 1624{
1599 bool was_writable = test_and_clear_bit(PT_WRITABLE_SHIFT, 1625 bool was_writable = test_and_clear_bit(PT_WRITABLE_SHIFT,
1600 (unsigned long *)sptep); 1626 (unsigned long *)sptep);
1601 if (was_writable) 1627 if (was_writable && !spte_ad_enabled(*sptep))
1602 kvm_set_pfn_dirty(spte_to_pfn(*sptep)); 1628 kvm_set_pfn_dirty(spte_to_pfn(*sptep));
1603 1629
1604 return was_writable; 1630 return was_writable;
@@ -1617,10 +1643,10 @@ static bool __rmap_clear_dirty(struct kvm *kvm, struct kvm_rmap_head *rmap_head)
1617 bool flush = false; 1643 bool flush = false;
1618 1644
1619 for_each_rmap_spte(rmap_head, &iter, sptep) 1645 for_each_rmap_spte(rmap_head, &iter, sptep)
1620 if (spte_ad_enabled(*sptep)) 1646 if (spte_ad_need_write_protect(*sptep))
1621 flush |= spte_clear_dirty(sptep); 1647 flush |= spte_wrprot_for_clear_dirty(sptep);
1622 else 1648 else
1623 flush |= wrprot_ad_disabled_spte(sptep); 1649 flush |= spte_clear_dirty(sptep);
1624 1650
1625 return flush; 1651 return flush;
1626} 1652}
@@ -1631,6 +1657,11 @@ static bool spte_set_dirty(u64 *sptep)
1631 1657
1632 rmap_printk("rmap_set_dirty: spte %p %llx\n", sptep, *sptep); 1658 rmap_printk("rmap_set_dirty: spte %p %llx\n", sptep, *sptep);
1633 1659
1660 /*
1661 * Similar to the !kvm_x86_ops->slot_disable_log_dirty case,
1662 * do not bother adding back write access to pages marked
1663 * SPTE_AD_WRPROT_ONLY_MASK.
1664 */
1634 spte |= shadow_dirty_mask; 1665 spte |= shadow_dirty_mask;
1635 1666
1636 return mmu_spte_update(sptep, spte); 1667 return mmu_spte_update(sptep, spte);
@@ -2622,7 +2653,7 @@ static void link_shadow_page(struct kvm_vcpu *vcpu, u64 *sptep,
2622 shadow_user_mask | shadow_x_mask | shadow_me_mask; 2653 shadow_user_mask | shadow_x_mask | shadow_me_mask;
2623 2654
2624 if (sp_ad_disabled(sp)) 2655 if (sp_ad_disabled(sp))
2625 spte |= shadow_acc_track_value; 2656 spte |= SPTE_AD_DISABLED_MASK;
2626 else 2657 else
2627 spte |= shadow_accessed_mask; 2658 spte |= shadow_accessed_mask;
2628 2659
@@ -2968,7 +2999,9 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
2968 2999
2969 sp = page_header(__pa(sptep)); 3000 sp = page_header(__pa(sptep));
2970 if (sp_ad_disabled(sp)) 3001 if (sp_ad_disabled(sp))
2971 spte |= shadow_acc_track_value; 3002 spte |= SPTE_AD_DISABLED_MASK;
3003 else if (kvm_vcpu_ad_need_write_protect(vcpu))
3004 spte |= SPTE_AD_WRPROT_ONLY_MASK;
2972 3005
2973 /* 3006 /*
2974 * For the EPT case, shadow_present_mask is 0 if hardware 3007 * For the EPT case, shadow_present_mask is 0 if hardware
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 41abc62c9a8a..e76eb4f07f6c 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -2610,7 +2610,7 @@ static int nested_check_vm_entry_controls(struct kvm_vcpu *vcpu,
2610 2610
2611 /* VM-entry exception error code */ 2611 /* VM-entry exception error code */
2612 if (CC(has_error_code && 2612 if (CC(has_error_code &&
2613 vmcs12->vm_entry_exception_error_code & GENMASK(31, 15))) 2613 vmcs12->vm_entry_exception_error_code & GENMASK(31, 16)))
2614 return -EINVAL; 2614 return -EINVAL;
2615 2615
2616 /* VM-entry interruption-info field: reserved bits */ 2616 /* VM-entry interruption-info field: reserved bits */
diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
index 4dea0e0e7e39..3e9c059099e9 100644
--- a/arch/x86/kvm/vmx/pmu_intel.c
+++ b/arch/x86/kvm/vmx/pmu_intel.c
@@ -262,6 +262,7 @@ static int intel_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
262static void intel_pmu_refresh(struct kvm_vcpu *vcpu) 262static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
263{ 263{
264 struct kvm_pmu *pmu = vcpu_to_pmu(vcpu); 264 struct kvm_pmu *pmu = vcpu_to_pmu(vcpu);
265 struct x86_pmu_capability x86_pmu;
265 struct kvm_cpuid_entry2 *entry; 266 struct kvm_cpuid_entry2 *entry;
266 union cpuid10_eax eax; 267 union cpuid10_eax eax;
267 union cpuid10_edx edx; 268 union cpuid10_edx edx;
@@ -283,8 +284,10 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
283 if (!pmu->version) 284 if (!pmu->version)
284 return; 285 return;
285 286
287 perf_get_x86_pmu_capability(&x86_pmu);
288
286 pmu->nr_arch_gp_counters = min_t(int, eax.split.num_counters, 289 pmu->nr_arch_gp_counters = min_t(int, eax.split.num_counters,
287 INTEL_PMC_MAX_GENERIC); 290 x86_pmu.num_counters_gp);
288 pmu->counter_bitmask[KVM_PMC_GP] = ((u64)1 << eax.split.bit_width) - 1; 291 pmu->counter_bitmask[KVM_PMC_GP] = ((u64)1 << eax.split.bit_width) - 1;
289 pmu->available_event_types = ~entry->ebx & 292 pmu->available_event_types = ~entry->ebx &
290 ((1ull << eax.split.mask_length) - 1); 293 ((1ull << eax.split.mask_length) - 1);
@@ -294,7 +297,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
294 } else { 297 } else {
295 pmu->nr_arch_fixed_counters = 298 pmu->nr_arch_fixed_counters =
296 min_t(int, edx.split.num_counters_fixed, 299 min_t(int, edx.split.num_counters_fixed,
297 INTEL_PMC_MAX_FIXED); 300 x86_pmu.num_counters_fixed);
298 pmu->counter_bitmask[KVM_PMC_FIXED] = 301 pmu->counter_bitmask[KVM_PMC_FIXED] =
299 ((u64)1 << edx.split.bit_width_fixed) - 1; 302 ((u64)1 << edx.split.bit_width_fixed) - 1;
300 } 303 }
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index d4575ffb3cec..e7970a2e8eae 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -209,6 +209,11 @@ static int vmx_setup_l1d_flush(enum vmx_l1d_flush_state l1tf)
209 struct page *page; 209 struct page *page;
210 unsigned int i; 210 unsigned int i;
211 211
212 if (!boot_cpu_has_bug(X86_BUG_L1TF)) {
213 l1tf_vmx_mitigation = VMENTER_L1D_FLUSH_NOT_REQUIRED;
214 return 0;
215 }
216
212 if (!enable_ept) { 217 if (!enable_ept) {
213 l1tf_vmx_mitigation = VMENTER_L1D_FLUSH_EPT_DISABLED; 218 l1tf_vmx_mitigation = VMENTER_L1D_FLUSH_EPT_DISABLED;
214 return 0; 219 return 0;
@@ -7995,12 +8000,10 @@ static int __init vmx_init(void)
7995 * contain 'auto' which will be turned into the default 'cond' 8000 * contain 'auto' which will be turned into the default 'cond'
7996 * mitigation mode. 8001 * mitigation mode.
7997 */ 8002 */
7998 if (boot_cpu_has(X86_BUG_L1TF)) { 8003 r = vmx_setup_l1d_flush(vmentry_l1d_flush_param);
7999 r = vmx_setup_l1d_flush(vmentry_l1d_flush_param); 8004 if (r) {
8000 if (r) { 8005 vmx_exit();
8001 vmx_exit(); 8006 return r;
8002 return r;
8003 }
8004 } 8007 }
8005 8008
8006#ifdef CONFIG_KEXEC_CORE 8009#ifdef CONFIG_KEXEC_CORE
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0ed07d8d2caa..661e2bf38526 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -92,8 +92,8 @@ u64 __read_mostly efer_reserved_bits = ~((u64)(EFER_SCE | EFER_LME | EFER_LMA));
92static u64 __read_mostly efer_reserved_bits = ~((u64)EFER_SCE); 92static u64 __read_mostly efer_reserved_bits = ~((u64)EFER_SCE);
93#endif 93#endif
94 94
95#define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM 95#define VM_STAT(x, ...) offsetof(struct kvm, stat.x), KVM_STAT_VM, ## __VA_ARGS__
96#define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU 96#define VCPU_STAT(x, ...) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU, ## __VA_ARGS__
97 97
98#define KVM_X2APIC_API_VALID_FLAGS (KVM_X2APIC_API_USE_32BIT_IDS | \ 98#define KVM_X2APIC_API_VALID_FLAGS (KVM_X2APIC_API_USE_32BIT_IDS | \
99 KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK) 99 KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK)
@@ -212,7 +212,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
212 { "mmu_cache_miss", VM_STAT(mmu_cache_miss) }, 212 { "mmu_cache_miss", VM_STAT(mmu_cache_miss) },
213 { "mmu_unsync", VM_STAT(mmu_unsync) }, 213 { "mmu_unsync", VM_STAT(mmu_unsync) },
214 { "remote_tlb_flush", VM_STAT(remote_tlb_flush) }, 214 { "remote_tlb_flush", VM_STAT(remote_tlb_flush) },
215 { "largepages", VM_STAT(lpages) }, 215 { "largepages", VM_STAT(lpages, .mode = 0444) },
216 { "max_mmu_page_hash_collisions", 216 { "max_mmu_page_hash_collisions",
217 VM_STAT(max_mmu_page_hash_collisions) }, 217 VM_STAT(max_mmu_page_hash_collisions) },
218 { NULL } 218 { NULL }
@@ -885,34 +885,42 @@ int kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr)
885} 885}
886EXPORT_SYMBOL_GPL(kvm_set_xcr); 886EXPORT_SYMBOL_GPL(kvm_set_xcr);
887 887
888int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) 888static int kvm_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
889{ 889{
890 unsigned long old_cr4 = kvm_read_cr4(vcpu);
891 unsigned long pdptr_bits = X86_CR4_PGE | X86_CR4_PSE | X86_CR4_PAE |
892 X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_PKE;
893
894 if (cr4 & CR4_RESERVED_BITS) 890 if (cr4 & CR4_RESERVED_BITS)
895 return 1; 891 return -EINVAL;
896 892
897 if (!guest_cpuid_has(vcpu, X86_FEATURE_XSAVE) && (cr4 & X86_CR4_OSXSAVE)) 893 if (!guest_cpuid_has(vcpu, X86_FEATURE_XSAVE) && (cr4 & X86_CR4_OSXSAVE))
898 return 1; 894 return -EINVAL;
899 895
900 if (!guest_cpuid_has(vcpu, X86_FEATURE_SMEP) && (cr4 & X86_CR4_SMEP)) 896 if (!guest_cpuid_has(vcpu, X86_FEATURE_SMEP) && (cr4 & X86_CR4_SMEP))
901 return 1; 897 return -EINVAL;
902 898
903 if (!guest_cpuid_has(vcpu, X86_FEATURE_SMAP) && (cr4 & X86_CR4_SMAP)) 899 if (!guest_cpuid_has(vcpu, X86_FEATURE_SMAP) && (cr4 & X86_CR4_SMAP))
904 return 1; 900 return -EINVAL;
905 901
906 if (!guest_cpuid_has(vcpu, X86_FEATURE_FSGSBASE) && (cr4 & X86_CR4_FSGSBASE)) 902 if (!guest_cpuid_has(vcpu, X86_FEATURE_FSGSBASE) && (cr4 & X86_CR4_FSGSBASE))
907 return 1; 903 return -EINVAL;
908 904
909 if (!guest_cpuid_has(vcpu, X86_FEATURE_PKU) && (cr4 & X86_CR4_PKE)) 905 if (!guest_cpuid_has(vcpu, X86_FEATURE_PKU) && (cr4 & X86_CR4_PKE))
910 return 1; 906 return -EINVAL;
911 907
912 if (!guest_cpuid_has(vcpu, X86_FEATURE_LA57) && (cr4 & X86_CR4_LA57)) 908 if (!guest_cpuid_has(vcpu, X86_FEATURE_LA57) && (cr4 & X86_CR4_LA57))
913 return 1; 909 return -EINVAL;
914 910
915 if (!guest_cpuid_has(vcpu, X86_FEATURE_UMIP) && (cr4 & X86_CR4_UMIP)) 911 if (!guest_cpuid_has(vcpu, X86_FEATURE_UMIP) && (cr4 & X86_CR4_UMIP))
912 return -EINVAL;
913
914 return 0;
915}
916
917int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
918{
919 unsigned long old_cr4 = kvm_read_cr4(vcpu);
920 unsigned long pdptr_bits = X86_CR4_PGE | X86_CR4_PSE | X86_CR4_PAE |
921 X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_PKE;
922
923 if (kvm_valid_cr4(vcpu, cr4))
916 return 1; 924 return 1;
917 925
918 if (is_long_mode(vcpu)) { 926 if (is_long_mode(vcpu)) {
@@ -1161,13 +1169,6 @@ static u32 msrs_to_save[] = {
1161 MSR_ARCH_PERFMON_PERFCTR0 + 12, MSR_ARCH_PERFMON_PERFCTR0 + 13, 1169 MSR_ARCH_PERFMON_PERFCTR0 + 12, MSR_ARCH_PERFMON_PERFCTR0 + 13,
1162 MSR_ARCH_PERFMON_PERFCTR0 + 14, MSR_ARCH_PERFMON_PERFCTR0 + 15, 1170 MSR_ARCH_PERFMON_PERFCTR0 + 14, MSR_ARCH_PERFMON_PERFCTR0 + 15,
1163 MSR_ARCH_PERFMON_PERFCTR0 + 16, MSR_ARCH_PERFMON_PERFCTR0 + 17, 1171 MSR_ARCH_PERFMON_PERFCTR0 + 16, MSR_ARCH_PERFMON_PERFCTR0 + 17,
1164 MSR_ARCH_PERFMON_PERFCTR0 + 18, MSR_ARCH_PERFMON_PERFCTR0 + 19,
1165 MSR_ARCH_PERFMON_PERFCTR0 + 20, MSR_ARCH_PERFMON_PERFCTR0 + 21,
1166 MSR_ARCH_PERFMON_PERFCTR0 + 22, MSR_ARCH_PERFMON_PERFCTR0 + 23,
1167 MSR_ARCH_PERFMON_PERFCTR0 + 24, MSR_ARCH_PERFMON_PERFCTR0 + 25,
1168 MSR_ARCH_PERFMON_PERFCTR0 + 26, MSR_ARCH_PERFMON_PERFCTR0 + 27,
1169 MSR_ARCH_PERFMON_PERFCTR0 + 28, MSR_ARCH_PERFMON_PERFCTR0 + 29,
1170 MSR_ARCH_PERFMON_PERFCTR0 + 30, MSR_ARCH_PERFMON_PERFCTR0 + 31,
1171 MSR_ARCH_PERFMON_EVENTSEL0, MSR_ARCH_PERFMON_EVENTSEL1, 1172 MSR_ARCH_PERFMON_EVENTSEL0, MSR_ARCH_PERFMON_EVENTSEL1,
1172 MSR_ARCH_PERFMON_EVENTSEL0 + 2, MSR_ARCH_PERFMON_EVENTSEL0 + 3, 1173 MSR_ARCH_PERFMON_EVENTSEL0 + 2, MSR_ARCH_PERFMON_EVENTSEL0 + 3,
1173 MSR_ARCH_PERFMON_EVENTSEL0 + 4, MSR_ARCH_PERFMON_EVENTSEL0 + 5, 1174 MSR_ARCH_PERFMON_EVENTSEL0 + 4, MSR_ARCH_PERFMON_EVENTSEL0 + 5,
@@ -1177,13 +1178,6 @@ static u32 msrs_to_save[] = {
1177 MSR_ARCH_PERFMON_EVENTSEL0 + 12, MSR_ARCH_PERFMON_EVENTSEL0 + 13, 1178 MSR_ARCH_PERFMON_EVENTSEL0 + 12, MSR_ARCH_PERFMON_EVENTSEL0 + 13,
1178 MSR_ARCH_PERFMON_EVENTSEL0 + 14, MSR_ARCH_PERFMON_EVENTSEL0 + 15, 1179 MSR_ARCH_PERFMON_EVENTSEL0 + 14, MSR_ARCH_PERFMON_EVENTSEL0 + 15,
1179 MSR_ARCH_PERFMON_EVENTSEL0 + 16, MSR_ARCH_PERFMON_EVENTSEL0 + 17, 1180 MSR_ARCH_PERFMON_EVENTSEL0 + 16, MSR_ARCH_PERFMON_EVENTSEL0 + 17,
1180 MSR_ARCH_PERFMON_EVENTSEL0 + 18, MSR_ARCH_PERFMON_EVENTSEL0 + 19,
1181 MSR_ARCH_PERFMON_EVENTSEL0 + 20, MSR_ARCH_PERFMON_EVENTSEL0 + 21,
1182 MSR_ARCH_PERFMON_EVENTSEL0 + 22, MSR_ARCH_PERFMON_EVENTSEL0 + 23,
1183 MSR_ARCH_PERFMON_EVENTSEL0 + 24, MSR_ARCH_PERFMON_EVENTSEL0 + 25,
1184 MSR_ARCH_PERFMON_EVENTSEL0 + 26, MSR_ARCH_PERFMON_EVENTSEL0 + 27,
1185 MSR_ARCH_PERFMON_EVENTSEL0 + 28, MSR_ARCH_PERFMON_EVENTSEL0 + 29,
1186 MSR_ARCH_PERFMON_EVENTSEL0 + 30, MSR_ARCH_PERFMON_EVENTSEL0 + 31,
1187}; 1181};
1188 1182
1189static unsigned num_msrs_to_save; 1183static unsigned num_msrs_to_save;
@@ -5097,13 +5091,14 @@ out:
5097 5091
5098static void kvm_init_msr_list(void) 5092static void kvm_init_msr_list(void)
5099{ 5093{
5094 struct x86_pmu_capability x86_pmu;
5100 u32 dummy[2]; 5095 u32 dummy[2];
5101 unsigned i, j; 5096 unsigned i, j;
5102 5097
5103 BUILD_BUG_ON_MSG(INTEL_PMC_MAX_FIXED != 4, 5098 BUILD_BUG_ON_MSG(INTEL_PMC_MAX_FIXED != 4,
5104 "Please update the fixed PMCs in msrs_to_save[]"); 5099 "Please update the fixed PMCs in msrs_to_save[]");
5105 BUILD_BUG_ON_MSG(INTEL_PMC_MAX_GENERIC != 32, 5100
5106 "Please update the generic perfctr/eventsel MSRs in msrs_to_save[]"); 5101 perf_get_x86_pmu_capability(&x86_pmu);
5107 5102
5108 for (i = j = 0; i < ARRAY_SIZE(msrs_to_save); i++) { 5103 for (i = j = 0; i < ARRAY_SIZE(msrs_to_save); i++) {
5109 if (rdmsr_safe(msrs_to_save[i], &dummy[0], &dummy[1]) < 0) 5104 if (rdmsr_safe(msrs_to_save[i], &dummy[0], &dummy[1]) < 0)
@@ -5145,6 +5140,15 @@ static void kvm_init_msr_list(void)
5145 intel_pt_validate_hw_cap(PT_CAP_num_address_ranges) * 2) 5140 intel_pt_validate_hw_cap(PT_CAP_num_address_ranges) * 2)
5146 continue; 5141 continue;
5147 break; 5142 break;
5143 case MSR_ARCH_PERFMON_PERFCTR0 ... MSR_ARCH_PERFMON_PERFCTR0 + 17:
5144 if (msrs_to_save[i] - MSR_ARCH_PERFMON_PERFCTR0 >=
5145 min(INTEL_PMC_MAX_GENERIC, x86_pmu.num_counters_gp))
5146 continue;
5147 break;
5148 case MSR_ARCH_PERFMON_EVENTSEL0 ... MSR_ARCH_PERFMON_EVENTSEL0 + 17:
5149 if (msrs_to_save[i] - MSR_ARCH_PERFMON_EVENTSEL0 >=
5150 min(INTEL_PMC_MAX_GENERIC, x86_pmu.num_counters_gp))
5151 continue;
5148 } 5152 }
5149 default: 5153 default:
5150 break; 5154 break;
@@ -8714,10 +8718,6 @@ EXPORT_SYMBOL_GPL(kvm_task_switch);
8714 8718
8715static int kvm_valid_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) 8719static int kvm_valid_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
8716{ 8720{
8717 if (!guest_cpuid_has(vcpu, X86_FEATURE_XSAVE) &&
8718 (sregs->cr4 & X86_CR4_OSXSAVE))
8719 return -EINVAL;
8720
8721 if ((sregs->efer & EFER_LME) && (sregs->cr0 & X86_CR0_PG)) { 8721 if ((sregs->efer & EFER_LME) && (sregs->cr0 & X86_CR0_PG)) {
8722 /* 8722 /*
8723 * When EFER.LME and CR0.PG are set, the processor is in 8723 * When EFER.LME and CR0.PG are set, the processor is in
@@ -8736,7 +8736,7 @@ static int kvm_valid_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
8736 return -EINVAL; 8736 return -EINVAL;
8737 } 8737 }
8738 8738
8739 return 0; 8739 return kvm_valid_cr4(vcpu, sregs->cr4);
8740} 8740}
8741 8741
8742static int __set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) 8742static int __set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
diff --git a/arch/x86/lib/delay.c b/arch/x86/lib/delay.c
index b7375dc6898f..c126571e5e2e 100644
--- a/arch/x86/lib/delay.c
+++ b/arch/x86/lib/delay.c
@@ -113,8 +113,8 @@ static void delay_mwaitx(unsigned long __loops)
113 __monitorx(raw_cpu_ptr(&cpu_tss_rw), 0, 0); 113 __monitorx(raw_cpu_ptr(&cpu_tss_rw), 0, 0);
114 114
115 /* 115 /*
116 * AMD, like Intel, supports the EAX hint and EAX=0xf 116 * AMD, like Intel's MWAIT version, supports the EAX hint and
117 * means, do not enter any deep C-state and we use it 117 * EAX=0xf0 means, do not enter any deep C-state and we use it
118 * here in delay() to minimize wakeup latency. 118 * here in delay() to minimize wakeup latency.
119 */ 119 */
120 __mwaitx(MWAITX_DISABLE_CSTATES, delay, MWAITX_ECX_TIMER_ENABLE); 120 __mwaitx(MWAITX_DISABLE_CSTATES, delay, MWAITX_ECX_TIMER_ENABLE);
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index c202e1b07e29..425e025341db 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -917,9 +917,6 @@ static void __init kexec_enter_virtual_mode(void)
917 917
918 if (efi_enabled(EFI_OLD_MEMMAP) && (__supported_pte_mask & _PAGE_NX)) 918 if (efi_enabled(EFI_OLD_MEMMAP) && (__supported_pte_mask & _PAGE_NX))
919 runtime_code_page_mkexec(); 919 runtime_code_page_mkexec();
920
921 /* clean DUMMY object */
922 efi_delete_dummy_variable();
923#endif 920#endif
924} 921}
925 922
diff --git a/arch/x86/xen/efi.c b/arch/x86/xen/efi.c
index 0d3365cb64de..a04551ee5568 100644
--- a/arch/x86/xen/efi.c
+++ b/arch/x86/xen/efi.c
@@ -57,19 +57,7 @@ static efi_system_table_t __init *xen_efi_probe(void)
57 return NULL; 57 return NULL;
58 58
59 /* Here we know that Xen runs on EFI platform. */ 59 /* Here we know that Xen runs on EFI platform. */
60 60 xen_efi_runtime_setup();
61 efi.get_time = xen_efi_get_time;
62 efi.set_time = xen_efi_set_time;
63 efi.get_wakeup_time = xen_efi_get_wakeup_time;
64 efi.set_wakeup_time = xen_efi_set_wakeup_time;
65 efi.get_variable = xen_efi_get_variable;
66 efi.get_next_variable = xen_efi_get_next_variable;
67 efi.set_variable = xen_efi_set_variable;
68 efi.query_variable_info = xen_efi_query_variable_info;
69 efi.update_capsule = xen_efi_update_capsule;
70 efi.query_capsule_caps = xen_efi_query_capsule_caps;
71 efi.get_next_high_mono_count = xen_efi_get_next_high_mono_count;
72 efi.reset_system = xen_efi_reset_system;
73 61
74 efi_systab_xen.tables = info->cfg.addr; 62 efi_systab_xen.tables = info->cfg.addr;
75 efi_systab_xen.nr_tables = info->cfg.nent; 63 efi_systab_xen.nr_tables = info->cfg.nent;
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index 750f46ad018a..205b1176084f 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -269,19 +269,41 @@ void xen_reboot(int reason)
269 BUG(); 269 BUG();
270} 270}
271 271
272static int reboot_reason = SHUTDOWN_reboot;
273static bool xen_legacy_crash;
272void xen_emergency_restart(void) 274void xen_emergency_restart(void)
273{ 275{
274 xen_reboot(SHUTDOWN_reboot); 276 xen_reboot(reboot_reason);
275} 277}
276 278
277static int 279static int
278xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr) 280xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
279{ 281{
280 if (!kexec_crash_loaded()) 282 if (!kexec_crash_loaded()) {
281 xen_reboot(SHUTDOWN_crash); 283 if (xen_legacy_crash)
284 xen_reboot(SHUTDOWN_crash);
285
286 reboot_reason = SHUTDOWN_crash;
287
288 /*
289 * If panic_timeout==0 then we are supposed to wait forever.
290 * However, to preserve original dom0 behavior we have to drop
291 * into hypervisor. (domU behavior is controlled by its
292 * config file)
293 */
294 if (panic_timeout == 0)
295 panic_timeout = -1;
296 }
282 return NOTIFY_DONE; 297 return NOTIFY_DONE;
283} 298}
284 299
300static int __init parse_xen_legacy_crash(char *arg)
301{
302 xen_legacy_crash = true;
303 return 0;
304}
305early_param("xen_legacy_crash", parse_xen_legacy_crash);
306
285static struct notifier_block xen_panic_block = { 307static struct notifier_block xen_panic_block = {
286 .notifier_call = xen_panic_event, 308 .notifier_call = xen_panic_event,
287 .priority = INT_MIN 309 .priority = INT_MIN
diff --git a/arch/xtensa/boot/dts/virt.dts b/arch/xtensa/boot/dts/virt.dts
index a9dcd87b6eb1..611b98a02a65 100644
--- a/arch/xtensa/boot/dts/virt.dts
+++ b/arch/xtensa/boot/dts/virt.dts
@@ -56,7 +56,7 @@
56 reg = <0xf0100000 0x03f00000>; 56 reg = <0xf0100000 0x03f00000>;
57 57
58 // BUS_ADDRESS(3) CPU_PHYSICAL(1) SIZE(2) 58 // BUS_ADDRESS(3) CPU_PHYSICAL(1) SIZE(2)
59 ranges = <0x01000000 0x0 0xf0000000 0xf0000000 0x0 0x00010000>, 59 ranges = <0x01000000 0x0 0x00000000 0xf0000000 0x0 0x00010000>,
60 <0x02000000 0x0 0xf4000000 0xf4000000 0x0 0x08000000>; 60 <0x02000000 0x0 0xf4000000 0xf4000000 0x0 0x08000000>;
61 61
62 // PCI_DEVICE(3) INT#(1) CONTROLLER(PHANDLE) CONTROLLER_DATA(2) 62 // PCI_DEVICE(3) INT#(1) CONTROLLER(PHANDLE) CONTROLLER_DATA(2)
diff --git a/arch/xtensa/include/asm/bitops.h b/arch/xtensa/include/asm/bitops.h
index aeb15f4c755b..be8b2be5a98b 100644
--- a/arch/xtensa/include/asm/bitops.h
+++ b/arch/xtensa/include/asm/bitops.h
@@ -148,7 +148,7 @@ static inline void change_bit(unsigned int bit, volatile unsigned long *p)
148 " getex %0\n" 148 " getex %0\n"
149 " beqz %0, 1b\n" 149 " beqz %0, 1b\n"
150 : "=&a" (tmp) 150 : "=&a" (tmp)
151 : "a" (~mask), "a" (p) 151 : "a" (mask), "a" (p)
152 : "memory"); 152 : "memory");
153} 153}
154 154
diff --git a/arch/xtensa/include/asm/uaccess.h b/arch/xtensa/include/asm/uaccess.h
index 6792928ba84a..3f80386f1883 100644
--- a/arch/xtensa/include/asm/uaccess.h
+++ b/arch/xtensa/include/asm/uaccess.h
@@ -100,7 +100,7 @@ do { \
100 case 4: __put_user_asm(x, ptr, retval, 4, "s32i", __cb); break; \ 100 case 4: __put_user_asm(x, ptr, retval, 4, "s32i", __cb); break; \
101 case 8: { \ 101 case 8: { \
102 __typeof__(*ptr) __v64 = x; \ 102 __typeof__(*ptr) __v64 = x; \
103 retval = __copy_to_user(ptr, &__v64, 8); \ 103 retval = __copy_to_user(ptr, &__v64, 8) ? -EFAULT : 0; \
104 break; \ 104 break; \
105 } \ 105 } \
106 default: __put_user_bad(); \ 106 default: __put_user_bad(); \
@@ -132,14 +132,14 @@ do { \
132#define __check_align_1 "" 132#define __check_align_1 ""
133 133
134#define __check_align_2 \ 134#define __check_align_2 \
135 " _bbci.l %3, 0, 1f \n" \ 135 " _bbci.l %[addr], 0, 1f \n" \
136 " movi %0, %4 \n" \ 136 " movi %[err], %[efault] \n" \
137 " _j 2f \n" 137 " _j 2f \n"
138 138
139#define __check_align_4 \ 139#define __check_align_4 \
140 " _bbsi.l %3, 0, 0f \n" \ 140 " _bbsi.l %[addr], 0, 0f \n" \
141 " _bbci.l %3, 1, 1f \n" \ 141 " _bbci.l %[addr], 1, 1f \n" \
142 "0: movi %0, %4 \n" \ 142 "0: movi %[err], %[efault] \n" \
143 " _j 2f \n" 143 " _j 2f \n"
144 144
145 145
@@ -151,40 +151,40 @@ do { \
151 * WARNING: If you modify this macro at all, verify that the 151 * WARNING: If you modify this macro at all, verify that the
152 * __check_align_* macros still work. 152 * __check_align_* macros still work.
153 */ 153 */
154#define __put_user_asm(x, addr, err, align, insn, cb) \ 154#define __put_user_asm(x_, addr_, err_, align, insn, cb)\
155__asm__ __volatile__( \ 155__asm__ __volatile__( \
156 __check_align_##align \ 156 __check_align_##align \
157 "1: "insn" %2, %3, 0 \n" \ 157 "1: "insn" %[x], %[addr], 0 \n" \
158 "2: \n" \ 158 "2: \n" \
159 " .section .fixup,\"ax\" \n" \ 159 " .section .fixup,\"ax\" \n" \
160 " .align 4 \n" \ 160 " .align 4 \n" \
161 " .literal_position \n" \ 161 " .literal_position \n" \
162 "5: \n" \ 162 "5: \n" \
163 " movi %1, 2b \n" \ 163 " movi %[tmp], 2b \n" \
164 " movi %0, %4 \n" \ 164 " movi %[err], %[efault] \n" \
165 " jx %1 \n" \ 165 " jx %[tmp] \n" \
166 " .previous \n" \ 166 " .previous \n" \
167 " .section __ex_table,\"a\" \n" \ 167 " .section __ex_table,\"a\" \n" \
168 " .long 1b, 5b \n" \ 168 " .long 1b, 5b \n" \
169 " .previous" \ 169 " .previous" \
170 :"=r" (err), "=r" (cb) \ 170 :[err] "+r"(err_), [tmp] "=r"(cb) \
171 :"r" ((int)(x)), "r" (addr), "i" (-EFAULT), "0" (err)) 171 :[x] "r"(x_), [addr] "r"(addr_), [efault] "i"(-EFAULT))
172 172
173#define __get_user_nocheck(x, ptr, size) \ 173#define __get_user_nocheck(x, ptr, size) \
174({ \ 174({ \
175 long __gu_err, __gu_val; \ 175 long __gu_err; \
176 __get_user_size(__gu_val, (ptr), (size), __gu_err); \ 176 __get_user_size((x), (ptr), (size), __gu_err); \
177 (x) = (__force __typeof__(*(ptr)))__gu_val; \
178 __gu_err; \ 177 __gu_err; \
179}) 178})
180 179
181#define __get_user_check(x, ptr, size) \ 180#define __get_user_check(x, ptr, size) \
182({ \ 181({ \
183 long __gu_err = -EFAULT, __gu_val = 0; \ 182 long __gu_err = -EFAULT; \
184 const __typeof__(*(ptr)) *__gu_addr = (ptr); \ 183 const __typeof__(*(ptr)) *__gu_addr = (ptr); \
185 if (access_ok(__gu_addr, size)) \ 184 if (access_ok(__gu_addr, size)) \
186 __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \ 185 __get_user_size((x), __gu_addr, (size), __gu_err); \
187 (x) = (__force __typeof__(*(ptr)))__gu_val; \ 186 else \
187 (x) = 0; \
188 __gu_err; \ 188 __gu_err; \
189}) 189})
190 190
@@ -198,8 +198,17 @@ do { \
198 case 1: __get_user_asm(x, ptr, retval, 1, "l8ui", __cb); break;\ 198 case 1: __get_user_asm(x, ptr, retval, 1, "l8ui", __cb); break;\
199 case 2: __get_user_asm(x, ptr, retval, 2, "l16ui", __cb); break;\ 199 case 2: __get_user_asm(x, ptr, retval, 2, "l16ui", __cb); break;\
200 case 4: __get_user_asm(x, ptr, retval, 4, "l32i", __cb); break;\ 200 case 4: __get_user_asm(x, ptr, retval, 4, "l32i", __cb); break;\
201 case 8: retval = __copy_from_user(&x, ptr, 8); break; \ 201 case 8: { \
202 default: (x) = __get_user_bad(); \ 202 u64 __x; \
203 if (unlikely(__copy_from_user(&__x, ptr, 8))) { \
204 retval = -EFAULT; \
205 (x) = 0; \
206 } else { \
207 (x) = *(__force __typeof__((ptr)))&__x; \
208 } \
209 break; \
210 } \
211 default: (x) = 0; __get_user_bad(); \
203 } \ 212 } \
204} while (0) 213} while (0)
205 214
@@ -208,25 +217,28 @@ do { \
208 * WARNING: If you modify this macro at all, verify that the 217 * WARNING: If you modify this macro at all, verify that the
209 * __check_align_* macros still work. 218 * __check_align_* macros still work.
210 */ 219 */
211#define __get_user_asm(x, addr, err, align, insn, cb) \ 220#define __get_user_asm(x_, addr_, err_, align, insn, cb) \
212__asm__ __volatile__( \ 221do { \
213 __check_align_##align \ 222 u32 __x = 0; \
214 "1: "insn" %2, %3, 0 \n" \ 223 __asm__ __volatile__( \
215 "2: \n" \ 224 __check_align_##align \
216 " .section .fixup,\"ax\" \n" \ 225 "1: "insn" %[x], %[addr], 0 \n" \
217 " .align 4 \n" \ 226 "2: \n" \
218 " .literal_position \n" \ 227 " .section .fixup,\"ax\" \n" \
219 "5: \n" \ 228 " .align 4 \n" \
220 " movi %1, 2b \n" \ 229 " .literal_position \n" \
221 " movi %2, 0 \n" \ 230 "5: \n" \
222 " movi %0, %4 \n" \ 231 " movi %[tmp], 2b \n" \
223 " jx %1 \n" \ 232 " movi %[err], %[efault] \n" \
224 " .previous \n" \ 233 " jx %[tmp] \n" \
225 " .section __ex_table,\"a\" \n" \ 234 " .previous \n" \
226 " .long 1b, 5b \n" \ 235 " .section __ex_table,\"a\" \n" \
227 " .previous" \ 236 " .long 1b, 5b \n" \
228 :"=r" (err), "=r" (cb), "=r" (x) \ 237 " .previous" \
229 :"r" (addr), "i" (-EFAULT), "0" (err)) 238 :[err] "+r"(err_), [tmp] "=r"(cb), [x] "+r"(__x) \
239 :[addr] "r"(addr_), [efault] "i"(-EFAULT)); \
240 (x_) = (__force __typeof__(*(addr_)))__x; \
241} while (0)
230 242
231 243
232/* 244/*
diff --git a/arch/xtensa/kernel/xtensa_ksyms.c b/arch/xtensa/kernel/xtensa_ksyms.c
index 04f19de46700..4092555828b1 100644
--- a/arch/xtensa/kernel/xtensa_ksyms.c
+++ b/arch/xtensa/kernel/xtensa_ksyms.c
@@ -119,13 +119,6 @@ EXPORT_SYMBOL(__invalidate_icache_range);
119// FIXME EXPORT_SYMBOL(screen_info); 119// FIXME EXPORT_SYMBOL(screen_info);
120#endif 120#endif
121 121
122EXPORT_SYMBOL(outsb);
123EXPORT_SYMBOL(outsw);
124EXPORT_SYMBOL(outsl);
125EXPORT_SYMBOL(insb);
126EXPORT_SYMBOL(insw);
127EXPORT_SYMBOL(insl);
128
129extern long common_exception_return; 122extern long common_exception_return;
130EXPORT_SYMBOL(common_exception_return); 123EXPORT_SYMBOL(common_exception_return);
131 124
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index b6f20be0fc78..5d21027b1faf 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -1362,7 +1362,7 @@ int blkcg_activate_policy(struct request_queue *q,
1362 const struct blkcg_policy *pol) 1362 const struct blkcg_policy *pol)
1363{ 1363{
1364 struct blkg_policy_data *pd_prealloc = NULL; 1364 struct blkg_policy_data *pd_prealloc = NULL;
1365 struct blkcg_gq *blkg; 1365 struct blkcg_gq *blkg, *pinned_blkg = NULL;
1366 int ret; 1366 int ret;
1367 1367
1368 if (blkcg_policy_enabled(q, pol)) 1368 if (blkcg_policy_enabled(q, pol))
@@ -1370,49 +1370,82 @@ int blkcg_activate_policy(struct request_queue *q,
1370 1370
1371 if (queue_is_mq(q)) 1371 if (queue_is_mq(q))
1372 blk_mq_freeze_queue(q); 1372 blk_mq_freeze_queue(q);
1373pd_prealloc: 1373retry:
1374 if (!pd_prealloc) {
1375 pd_prealloc = pol->pd_alloc_fn(GFP_KERNEL, q, &blkcg_root);
1376 if (!pd_prealloc) {
1377 ret = -ENOMEM;
1378 goto out_bypass_end;
1379 }
1380 }
1381
1382 spin_lock_irq(&q->queue_lock); 1374 spin_lock_irq(&q->queue_lock);
1383 1375
1384 /* blkg_list is pushed at the head, reverse walk to init parents first */ 1376 /* blkg_list is pushed at the head, reverse walk to allocate parents first */
1385 list_for_each_entry_reverse(blkg, &q->blkg_list, q_node) { 1377 list_for_each_entry_reverse(blkg, &q->blkg_list, q_node) {
1386 struct blkg_policy_data *pd; 1378 struct blkg_policy_data *pd;
1387 1379
1388 if (blkg->pd[pol->plid]) 1380 if (blkg->pd[pol->plid])
1389 continue; 1381 continue;
1390 1382
1391 pd = pol->pd_alloc_fn(GFP_NOWAIT | __GFP_NOWARN, q, &blkcg_root); 1383 /* If prealloc matches, use it; otherwise try GFP_NOWAIT */
1392 if (!pd) 1384 if (blkg == pinned_blkg) {
1393 swap(pd, pd_prealloc); 1385 pd = pd_prealloc;
1386 pd_prealloc = NULL;
1387 } else {
1388 pd = pol->pd_alloc_fn(GFP_NOWAIT | __GFP_NOWARN, q,
1389 blkg->blkcg);
1390 }
1391
1394 if (!pd) { 1392 if (!pd) {
1393 /*
1394 * GFP_NOWAIT failed. Free the existing one and
1395 * prealloc for @blkg w/ GFP_KERNEL.
1396 */
1397 if (pinned_blkg)
1398 blkg_put(pinned_blkg);
1399 blkg_get(blkg);
1400 pinned_blkg = blkg;
1401
1395 spin_unlock_irq(&q->queue_lock); 1402 spin_unlock_irq(&q->queue_lock);
1396 goto pd_prealloc; 1403
1404 if (pd_prealloc)
1405 pol->pd_free_fn(pd_prealloc);
1406 pd_prealloc = pol->pd_alloc_fn(GFP_KERNEL, q,
1407 blkg->blkcg);
1408 if (pd_prealloc)
1409 goto retry;
1410 else
1411 goto enomem;
1397 } 1412 }
1398 1413
1399 blkg->pd[pol->plid] = pd; 1414 blkg->pd[pol->plid] = pd;
1400 pd->blkg = blkg; 1415 pd->blkg = blkg;
1401 pd->plid = pol->plid; 1416 pd->plid = pol->plid;
1402 if (pol->pd_init_fn)
1403 pol->pd_init_fn(pd);
1404 } 1417 }
1405 1418
1419 /* all allocated, init in the same order */
1420 if (pol->pd_init_fn)
1421 list_for_each_entry_reverse(blkg, &q->blkg_list, q_node)
1422 pol->pd_init_fn(blkg->pd[pol->plid]);
1423
1406 __set_bit(pol->plid, q->blkcg_pols); 1424 __set_bit(pol->plid, q->blkcg_pols);
1407 ret = 0; 1425 ret = 0;
1408 1426
1409 spin_unlock_irq(&q->queue_lock); 1427 spin_unlock_irq(&q->queue_lock);
1410out_bypass_end: 1428out:
1411 if (queue_is_mq(q)) 1429 if (queue_is_mq(q))
1412 blk_mq_unfreeze_queue(q); 1430 blk_mq_unfreeze_queue(q);
1431 if (pinned_blkg)
1432 blkg_put(pinned_blkg);
1413 if (pd_prealloc) 1433 if (pd_prealloc)
1414 pol->pd_free_fn(pd_prealloc); 1434 pol->pd_free_fn(pd_prealloc);
1415 return ret; 1435 return ret;
1436
1437enomem:
1438 /* alloc failed, nothing's initialized yet, free everything */
1439 spin_lock_irq(&q->queue_lock);
1440 list_for_each_entry(blkg, &q->blkg_list, q_node) {
1441 if (blkg->pd[pol->plid]) {
1442 pol->pd_free_fn(blkg->pd[pol->plid]);
1443 blkg->pd[pol->plid] = NULL;
1444 }
1445 }
1446 spin_unlock_irq(&q->queue_lock);
1447 ret = -ENOMEM;
1448 goto out;
1416} 1449}
1417EXPORT_SYMBOL_GPL(blkcg_activate_policy); 1450EXPORT_SYMBOL_GPL(blkcg_activate_policy);
1418 1451
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 6e3b15f70cd7..ec791156e9cc 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1992,10 +1992,14 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
1992 /* bypass scheduler for flush rq */ 1992 /* bypass scheduler for flush rq */
1993 blk_insert_flush(rq); 1993 blk_insert_flush(rq);
1994 blk_mq_run_hw_queue(data.hctx, true); 1994 blk_mq_run_hw_queue(data.hctx, true);
1995 } else if (plug && (q->nr_hw_queues == 1 || q->mq_ops->commit_rqs)) { 1995 } else if (plug && (q->nr_hw_queues == 1 || q->mq_ops->commit_rqs ||
1996 !blk_queue_nonrot(q))) {
1996 /* 1997 /*
1997 * Use plugging if we have a ->commit_rqs() hook as well, as 1998 * Use plugging if we have a ->commit_rqs() hook as well, as
1998 * we know the driver uses bd->last in a smart fashion. 1999 * we know the driver uses bd->last in a smart fashion.
2000 *
2001 * Use normal plugging if this disk is slow HDD, as sequential
2002 * IO may benefit a lot from plug merging.
1999 */ 2003 */
2000 unsigned int request_count = plug->rq_count; 2004 unsigned int request_count = plug->rq_count;
2001 struct request *last = NULL; 2005 struct request *last = NULL;
@@ -2012,6 +2016,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
2012 } 2016 }
2013 2017
2014 blk_add_rq_to_plug(plug, rq); 2018 blk_add_rq_to_plug(plug, rq);
2019 } else if (q->elevator) {
2020 blk_mq_sched_insert_request(rq, false, true, true);
2015 } else if (plug && !blk_queue_nomerges(q)) { 2021 } else if (plug && !blk_queue_nomerges(q)) {
2016 /* 2022 /*
2017 * We do limited plugging. If the bio can be merged, do that. 2023 * We do limited plugging. If the bio can be merged, do that.
@@ -2035,8 +2041,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
2035 blk_mq_try_issue_directly(data.hctx, same_queue_rq, 2041 blk_mq_try_issue_directly(data.hctx, same_queue_rq,
2036 &cookie); 2042 &cookie);
2037 } 2043 }
2038 } else if ((q->nr_hw_queues > 1 && is_sync) || (!q->elevator && 2044 } else if ((q->nr_hw_queues > 1 && is_sync) ||
2039 !data.hctx->dispatch_busy)) { 2045 !data.hctx->dispatch_busy) {
2040 blk_mq_try_issue_directly(data.hctx, rq, &cookie); 2046 blk_mq_try_issue_directly(data.hctx, rq, &cookie);
2041 } else { 2047 } else {
2042 blk_mq_sched_insert_request(rq, false, true, true); 2048 blk_mq_sched_insert_request(rq, false, true, true);
diff --git a/block/blk-rq-qos.c b/block/blk-rq-qos.c
index 61b635bc2a31..656460636ad3 100644
--- a/block/blk-rq-qos.c
+++ b/block/blk-rq-qos.c
@@ -160,24 +160,27 @@ bool rq_depth_calc_max_depth(struct rq_depth *rqd)
160 return ret; 160 return ret;
161} 161}
162 162
163void rq_depth_scale_up(struct rq_depth *rqd) 163/* Returns true on success and false if scaling up wasn't possible */
164bool rq_depth_scale_up(struct rq_depth *rqd)
164{ 165{
165 /* 166 /*
166 * Hit max in previous round, stop here 167 * Hit max in previous round, stop here
167 */ 168 */
168 if (rqd->scaled_max) 169 if (rqd->scaled_max)
169 return; 170 return false;
170 171
171 rqd->scale_step--; 172 rqd->scale_step--;
172 173
173 rqd->scaled_max = rq_depth_calc_max_depth(rqd); 174 rqd->scaled_max = rq_depth_calc_max_depth(rqd);
175 return true;
174} 176}
175 177
176/* 178/*
177 * Scale rwb down. If 'hard_throttle' is set, do it quicker, since we 179 * Scale rwb down. If 'hard_throttle' is set, do it quicker, since we
178 * had a latency violation. 180 * had a latency violation. Returns true on success and returns false if
181 * scaling down wasn't possible.
179 */ 182 */
180void rq_depth_scale_down(struct rq_depth *rqd, bool hard_throttle) 183bool rq_depth_scale_down(struct rq_depth *rqd, bool hard_throttle)
181{ 184{
182 /* 185 /*
183 * Stop scaling down when we've hit the limit. This also prevents 186 * Stop scaling down when we've hit the limit. This also prevents
@@ -185,7 +188,7 @@ void rq_depth_scale_down(struct rq_depth *rqd, bool hard_throttle)
185 * keep up. 188 * keep up.
186 */ 189 */
187 if (rqd->max_depth == 1) 190 if (rqd->max_depth == 1)
188 return; 191 return false;
189 192
190 if (rqd->scale_step < 0 && hard_throttle) 193 if (rqd->scale_step < 0 && hard_throttle)
191 rqd->scale_step = 0; 194 rqd->scale_step = 0;
@@ -194,6 +197,7 @@ void rq_depth_scale_down(struct rq_depth *rqd, bool hard_throttle)
194 197
195 rqd->scaled_max = false; 198 rqd->scaled_max = false;
196 rq_depth_calc_max_depth(rqd); 199 rq_depth_calc_max_depth(rqd);
200 return true;
197} 201}
198 202
199struct rq_qos_wait_data { 203struct rq_qos_wait_data {
diff --git a/block/blk-rq-qos.h b/block/blk-rq-qos.h
index 08a09dbe0f4b..2bc43e94f4c4 100644
--- a/block/blk-rq-qos.h
+++ b/block/blk-rq-qos.h
@@ -108,16 +108,13 @@ static inline void rq_qos_add(struct request_queue *q, struct rq_qos *rqos)
108 108
109static inline void rq_qos_del(struct request_queue *q, struct rq_qos *rqos) 109static inline void rq_qos_del(struct request_queue *q, struct rq_qos *rqos)
110{ 110{
111 struct rq_qos *cur, *prev = NULL; 111 struct rq_qos **cur;
112 for (cur = q->rq_qos; cur; cur = cur->next) { 112
113 if (cur == rqos) { 113 for (cur = &q->rq_qos; *cur; cur = &(*cur)->next) {
114 if (prev) 114 if (*cur == rqos) {
115 prev->next = rqos->next; 115 *cur = rqos->next;
116 else
117 q->rq_qos = cur;
118 break; 116 break;
119 } 117 }
120 prev = cur;
121 } 118 }
122 119
123 blk_mq_debugfs_unregister_rqos(rqos); 120 blk_mq_debugfs_unregister_rqos(rqos);
@@ -130,8 +127,8 @@ void rq_qos_wait(struct rq_wait *rqw, void *private_data,
130 acquire_inflight_cb_t *acquire_inflight_cb, 127 acquire_inflight_cb_t *acquire_inflight_cb,
131 cleanup_cb_t *cleanup_cb); 128 cleanup_cb_t *cleanup_cb);
132bool rq_wait_inc_below(struct rq_wait *rq_wait, unsigned int limit); 129bool rq_wait_inc_below(struct rq_wait *rq_wait, unsigned int limit);
133void rq_depth_scale_up(struct rq_depth *rqd); 130bool rq_depth_scale_up(struct rq_depth *rqd);
134void rq_depth_scale_down(struct rq_depth *rqd, bool hard_throttle); 131bool rq_depth_scale_down(struct rq_depth *rqd, bool hard_throttle);
135bool rq_depth_calc_max_depth(struct rq_depth *rqd); 132bool rq_depth_calc_max_depth(struct rq_depth *rqd);
136 133
137void __rq_qos_cleanup(struct rq_qos *rqos, struct bio *bio); 134void __rq_qos_cleanup(struct rq_qos *rqos, struct bio *bio);
diff --git a/block/blk-wbt.c b/block/blk-wbt.c
index 8af553a0ba00..8641ba9793c5 100644
--- a/block/blk-wbt.c
+++ b/block/blk-wbt.c
@@ -308,7 +308,8 @@ static void calc_wb_limits(struct rq_wb *rwb)
308 308
309static void scale_up(struct rq_wb *rwb) 309static void scale_up(struct rq_wb *rwb)
310{ 310{
311 rq_depth_scale_up(&rwb->rq_depth); 311 if (!rq_depth_scale_up(&rwb->rq_depth))
312 return;
312 calc_wb_limits(rwb); 313 calc_wb_limits(rwb);
313 rwb->unknown_cnt = 0; 314 rwb->unknown_cnt = 0;
314 rwb_wake_all(rwb); 315 rwb_wake_all(rwb);
@@ -317,7 +318,8 @@ static void scale_up(struct rq_wb *rwb)
317 318
318static void scale_down(struct rq_wb *rwb, bool hard_throttle) 319static void scale_down(struct rq_wb *rwb, bool hard_throttle)
319{ 320{
320 rq_depth_scale_down(&rwb->rq_depth, hard_throttle); 321 if (!rq_depth_scale_down(&rwb->rq_depth, hard_throttle))
322 return;
321 calc_wb_limits(rwb); 323 calc_wb_limits(rwb);
322 rwb->unknown_cnt = 0; 324 rwb->unknown_cnt = 0;
323 rwb_trace_step(rwb, "scale down"); 325 rwb_trace_step(rwb, "scale down");
diff --git a/block/elevator.c b/block/elevator.c
index 5437059c9261..076ba7308e65 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -616,7 +616,8 @@ out:
616 616
617static inline bool elv_support_iosched(struct request_queue *q) 617static inline bool elv_support_iosched(struct request_queue *q)
618{ 618{
619 if (q->tag_set && (q->tag_set->flags & BLK_MQ_F_NO_SCHED)) 619 if (!q->mq_ops ||
620 (q->tag_set && (q->tag_set->flags & BLK_MQ_F_NO_SCHED)))
620 return false; 621 return false;
621 return true; 622 return true;
622} 623}
diff --git a/block/sed-opal.c b/block/sed-opal.c
index 4e95a9792162..b4c761973ac1 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -129,7 +129,7 @@ static const u8 opaluid[][OPAL_UID_LENGTH] = {
129 { 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x84, 0x01 }, 129 { 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x84, 0x01 },
130 130
131 /* tables */ 131 /* tables */
132 [OPAL_TABLE_TABLE] 132 [OPAL_TABLE_TABLE] =
133 { 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01 }, 133 { 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01 },
134 [OPAL_LOCKINGRANGE_GLOBAL] = 134 [OPAL_LOCKINGRANGE_GLOBAL] =
135 { 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00, 0x01 }, 135 { 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00, 0x01 },
@@ -372,8 +372,8 @@ static void check_geometry(struct opal_dev *dev, const void *data)
372{ 372{
373 const struct d0_geometry_features *geo = data; 373 const struct d0_geometry_features *geo = data;
374 374
375 dev->align = geo->alignment_granularity; 375 dev->align = be64_to_cpu(geo->alignment_granularity);
376 dev->lowest_lba = geo->lowest_aligned_lba; 376 dev->lowest_lba = be64_to_cpu(geo->lowest_aligned_lba);
377} 377}
378 378
379static int execute_step(struct opal_dev *dev, 379static int execute_step(struct opal_dev *dev,
diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index 3b2525908dd8..a1a858ad4d18 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -905,8 +905,8 @@ void acpi_cppc_processor_exit(struct acpi_processor *pr)
905 pcc_data[pcc_ss_id]->refcount--; 905 pcc_data[pcc_ss_id]->refcount--;
906 if (!pcc_data[pcc_ss_id]->refcount) { 906 if (!pcc_data[pcc_ss_id]->refcount) {
907 pcc_mbox_free_channel(pcc_data[pcc_ss_id]->pcc_channel); 907 pcc_mbox_free_channel(pcc_data[pcc_ss_id]->pcc_channel);
908 pcc_data[pcc_ss_id]->pcc_channel_acquired = 0;
909 kfree(pcc_data[pcc_ss_id]); 908 kfree(pcc_data[pcc_ss_id]);
909 pcc_data[pcc_ss_id] = NULL;
910 } 910 }
911 } 911 }
912 } 912 }
diff --git a/drivers/acpi/hmat/hmat.c b/drivers/acpi/hmat/hmat.c
index 8f9a28a870b0..8b0de8a3c647 100644
--- a/drivers/acpi/hmat/hmat.c
+++ b/drivers/acpi/hmat/hmat.c
@@ -403,7 +403,7 @@ static int __init hmat_parse_proximity_domain(union acpi_subtable_headers *heade
403 pr_info("HMAT: Memory Flags:%04x Processor Domain:%d Memory Domain:%d\n", 403 pr_info("HMAT: Memory Flags:%04x Processor Domain:%d Memory Domain:%d\n",
404 p->flags, p->processor_PD, p->memory_PD); 404 p->flags, p->processor_PD, p->memory_PD);
405 405
406 if (p->flags & ACPI_HMAT_MEMORY_PD_VALID) { 406 if (p->flags & ACPI_HMAT_MEMORY_PD_VALID && hmat_revision == 1) {
407 target = find_mem_target(p->memory_PD); 407 target = find_mem_target(p->memory_PD);
408 if (!target) { 408 if (!target) {
409 pr_debug("HMAT: Memory Domain missing from SRAT\n"); 409 pr_debug("HMAT: Memory Domain missing from SRAT\n");
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index 2261713d1aec..930a49fa4dfc 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -162,21 +162,23 @@ void acpi_processor_ppc_init(int cpu)
162 struct acpi_processor *pr = per_cpu(processors, cpu); 162 struct acpi_processor *pr = per_cpu(processors, cpu);
163 int ret; 163 int ret;
164 164
165 if (!pr)
166 return;
167
165 ret = dev_pm_qos_add_request(get_cpu_device(cpu), 168 ret = dev_pm_qos_add_request(get_cpu_device(cpu),
166 &pr->perflib_req, DEV_PM_QOS_MAX_FREQUENCY, 169 &pr->perflib_req, DEV_PM_QOS_MAX_FREQUENCY,
167 INT_MAX); 170 INT_MAX);
168 if (ret < 0) { 171 if (ret < 0)
169 pr_err("Failed to add freq constraint for CPU%d (%d)\n", cpu, 172 pr_err("Failed to add freq constraint for CPU%d (%d)\n", cpu,
170 ret); 173 ret);
171 return;
172 }
173} 174}
174 175
175void acpi_processor_ppc_exit(int cpu) 176void acpi_processor_ppc_exit(int cpu)
176{ 177{
177 struct acpi_processor *pr = per_cpu(processors, cpu); 178 struct acpi_processor *pr = per_cpu(processors, cpu);
178 179
179 dev_pm_qos_remove_request(&pr->perflib_req); 180 if (pr)
181 dev_pm_qos_remove_request(&pr->perflib_req);
180} 182}
181 183
182static int acpi_processor_get_performance_control(struct acpi_processor *pr) 184static int acpi_processor_get_performance_control(struct acpi_processor *pr)
diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
index ec2638f1df4f..8227c7dd75b1 100644
--- a/drivers/acpi/processor_thermal.c
+++ b/drivers/acpi/processor_thermal.c
@@ -130,21 +130,23 @@ void acpi_thermal_cpufreq_init(int cpu)
130 struct acpi_processor *pr = per_cpu(processors, cpu); 130 struct acpi_processor *pr = per_cpu(processors, cpu);
131 int ret; 131 int ret;
132 132
133 if (!pr)
134 return;
135
133 ret = dev_pm_qos_add_request(get_cpu_device(cpu), 136 ret = dev_pm_qos_add_request(get_cpu_device(cpu),
134 &pr->thermal_req, DEV_PM_QOS_MAX_FREQUENCY, 137 &pr->thermal_req, DEV_PM_QOS_MAX_FREQUENCY,
135 INT_MAX); 138 INT_MAX);
136 if (ret < 0) { 139 if (ret < 0)
137 pr_err("Failed to add freq constraint for CPU%d (%d)\n", cpu, 140 pr_err("Failed to add freq constraint for CPU%d (%d)\n", cpu,
138 ret); 141 ret);
139 return;
140 }
141} 142}
142 143
143void acpi_thermal_cpufreq_exit(int cpu) 144void acpi_thermal_cpufreq_exit(int cpu)
144{ 145{
145 struct acpi_processor *pr = per_cpu(processors, cpu); 146 struct acpi_processor *pr = per_cpu(processors, cpu);
146 147
147 dev_pm_qos_remove_request(&pr->thermal_req); 148 if (pr)
149 dev_pm_qos_remove_request(&pr->thermal_req);
148} 150}
149#else /* ! CONFIG_CPU_FREQ */ 151#else /* ! CONFIG_CPU_FREQ */
150static int cpufreq_get_max_state(unsigned int cpu) 152static int cpufreq_get_max_state(unsigned int cpu)
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 9fa77d72ef27..2af937a8b1c5 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -362,19 +362,6 @@ static const struct dmi_system_id acpisleep_dmi_table[] __initconst = {
362 }, 362 },
363 }, 363 },
364 /* 364 /*
365 * https://bugzilla.kernel.org/show_bug.cgi?id=196907
366 * Some Dell XPS13 9360 cannot do suspend-to-idle using the Low Power
367 * S0 Idle firmware interface.
368 */
369 {
370 .callback = init_default_s3,
371 .ident = "Dell XPS13 9360",
372 .matches = {
373 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
374 DMI_MATCH(DMI_PRODUCT_NAME, "XPS 13 9360"),
375 },
376 },
377 /*
378 * ThinkPad X1 Tablet(2016) cannot do suspend-to-idle using 365 * ThinkPad X1 Tablet(2016) cannot do suspend-to-idle using
379 * the Low Power S0 Idle firmware interface (see 366 * the Low Power S0 Idle firmware interface (see
380 * https://bugzilla.kernel.org/show_bug.cgi?id=199057). 367 * https://bugzilla.kernel.org/show_bug.cgi?id=199057).
diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index c0a491277aca..5b9ac2122e89 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -57,6 +57,7 @@
57#include <linux/sched/signal.h> 57#include <linux/sched/signal.h>
58#include <linux/sched/mm.h> 58#include <linux/sched/mm.h>
59#include <linux/seq_file.h> 59#include <linux/seq_file.h>
60#include <linux/string.h>
60#include <linux/uaccess.h> 61#include <linux/uaccess.h>
61#include <linux/pid_namespace.h> 62#include <linux/pid_namespace.h>
62#include <linux/security.h> 63#include <linux/security.h>
@@ -66,6 +67,7 @@
66#include <linux/task_work.h> 67#include <linux/task_work.h>
67 68
68#include <uapi/linux/android/binder.h> 69#include <uapi/linux/android/binder.h>
70#include <uapi/linux/android/binderfs.h>
69 71
70#include <asm/cacheflush.h> 72#include <asm/cacheflush.h>
71 73
@@ -2876,7 +2878,7 @@ static void binder_transaction(struct binder_proc *proc,
2876 e->target_handle = tr->target.handle; 2878 e->target_handle = tr->target.handle;
2877 e->data_size = tr->data_size; 2879 e->data_size = tr->data_size;
2878 e->offsets_size = tr->offsets_size; 2880 e->offsets_size = tr->offsets_size;
2879 e->context_name = proc->context->name; 2881 strscpy(e->context_name, proc->context->name, BINDERFS_MAX_NAME);
2880 2882
2881 if (reply) { 2883 if (reply) {
2882 binder_inner_proc_lock(proc); 2884 binder_inner_proc_lock(proc);
diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index 6d79a1b0d446..d42a8b2f636a 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -156,7 +156,7 @@ static struct binder_buffer *binder_alloc_prepare_to_free_locked(
156} 156}
157 157
158/** 158/**
159 * binder_alloc_buffer_lookup() - get buffer given user ptr 159 * binder_alloc_prepare_to_free() - get buffer given user ptr
160 * @alloc: binder_alloc for this proc 160 * @alloc: binder_alloc for this proc
161 * @user_ptr: User pointer to buffer data 161 * @user_ptr: User pointer to buffer data
162 * 162 *
diff --git a/drivers/android/binder_internal.h b/drivers/android/binder_internal.h
index bd47f7f72075..ae991097d14d 100644
--- a/drivers/android/binder_internal.h
+++ b/drivers/android/binder_internal.h
@@ -130,7 +130,7 @@ struct binder_transaction_log_entry {
130 int return_error_line; 130 int return_error_line;
131 uint32_t return_error; 131 uint32_t return_error;
132 uint32_t return_error_param; 132 uint32_t return_error_param;
133 const char *context_name; 133 char context_name[BINDERFS_MAX_NAME + 1];
134}; 134};
135 135
136struct binder_transaction_log { 136struct binder_transaction_log {
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index dd92faf197d5..05c2b32dcc4d 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -1600,7 +1600,9 @@ static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp
1600 */ 1600 */
1601 if (!id || id->vendor != PCI_VENDOR_ID_INTEL) 1601 if (!id || id->vendor != PCI_VENDOR_ID_INTEL)
1602 return; 1602 return;
1603 if (((enum board_ids) id->driver_data) < board_ahci_pcs7) 1603
1604 /* Skip applying the quirk on Denverton and beyond */
1605 if (((enum board_ids) id->driver_data) >= board_ahci_pcs7)
1604 return; 1606 return;
1605 1607
1606 /* 1608 /*
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 76d0f9de767b..58e09ffe8b9c 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -4791,27 +4791,6 @@ void ata_scsi_hotplug(struct work_struct *work)
4791 return; 4791 return;
4792 } 4792 }
4793 4793
4794 /*
4795 * XXX - UGLY HACK
4796 *
4797 * The block layer suspend/resume path is fundamentally broken due
4798 * to freezable kthreads and workqueue and may deadlock if a block
4799 * device gets removed while resume is in progress. I don't know
4800 * what the solution is short of removing freezable kthreads and
4801 * workqueues altogether.
4802 *
4803 * The following is an ugly hack to avoid kicking off device
4804 * removal while freezer is active. This is a joke but does avoid
4805 * this particular deadlock scenario.
4806 *
4807 * https://bugzilla.kernel.org/show_bug.cgi?id=62801
4808 * http://marc.info/?l=linux-kernel&m=138695698516487
4809 */
4810#ifdef CONFIG_FREEZER
4811 while (pm_freezing)
4812 msleep(10);
4813#endif
4814
4815 DPRINTK("ENTER\n"); 4794 DPRINTK("ENTER\n");
4816 mutex_lock(&ap->scsi_scan_mutex); 4795 mutex_lock(&ap->scsi_scan_mutex);
4817 4796
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 2db62d98e395..7bd9cd366d41 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include <linux/acpi.h> 11#include <linux/acpi.h>
12#include <linux/cpufreq.h>
12#include <linux/device.h> 13#include <linux/device.h>
13#include <linux/err.h> 14#include <linux/err.h>
14#include <linux/fwnode.h> 15#include <linux/fwnode.h>
@@ -3179,6 +3180,8 @@ void device_shutdown(void)
3179 wait_for_device_probe(); 3180 wait_for_device_probe();
3180 device_block_probing(); 3181 device_block_probing();
3181 3182
3183 cpufreq_suspend();
3184
3182 spin_lock(&devices_kset->list_lock); 3185 spin_lock(&devices_kset->list_lock);
3183 /* 3186 /*
3184 * Walk the devices list backward, shutting down each in turn. 3187 * Walk the devices list backward, shutting down each in turn.
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 6bea4f3f8040..55907c27075b 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -540,6 +540,9 @@ static ssize_t soft_offline_page_store(struct device *dev,
540 pfn >>= PAGE_SHIFT; 540 pfn >>= PAGE_SHIFT;
541 if (!pfn_valid(pfn)) 541 if (!pfn_valid(pfn))
542 return -ENXIO; 542 return -ENXIO;
543 /* Only online pages can be soft-offlined (esp., not ZONE_DEVICE). */
544 if (!pfn_to_online_page(pfn))
545 return -EIO;
543 ret = soft_offline_page(pfn_to_page(pfn), 0); 546 ret = soft_offline_page(pfn_to_page(pfn), 0);
544 return ret == 0 ? count : ret; 547 return ret == 0 ? count : ret;
545} 548}
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index b6c6c7d97d5b..b230beb6ccb4 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -241,12 +241,8 @@ struct resource *platform_get_resource_byname(struct platform_device *dev,
241} 241}
242EXPORT_SYMBOL_GPL(platform_get_resource_byname); 242EXPORT_SYMBOL_GPL(platform_get_resource_byname);
243 243
244/** 244static int __platform_get_irq_byname(struct platform_device *dev,
245 * platform_get_irq_byname - get an IRQ for a device by name 245 const char *name)
246 * @dev: platform device
247 * @name: IRQ name
248 */
249int platform_get_irq_byname(struct platform_device *dev, const char *name)
250{ 246{
251 struct resource *r; 247 struct resource *r;
252 248
@@ -262,12 +258,48 @@ int platform_get_irq_byname(struct platform_device *dev, const char *name)
262 if (r) 258 if (r)
263 return r->start; 259 return r->start;
264 260
265 dev_err(&dev->dev, "IRQ %s not found\n", name);
266 return -ENXIO; 261 return -ENXIO;
267} 262}
263
264/**
265 * platform_get_irq_byname - get an IRQ for a device by name
266 * @dev: platform device
267 * @name: IRQ name
268 *
269 * Get an IRQ like platform_get_irq(), but then by name rather then by index.
270 *
271 * Return: IRQ number on success, negative error number on failure.
272 */
273int platform_get_irq_byname(struct platform_device *dev, const char *name)
274{
275 int ret;
276
277 ret = __platform_get_irq_byname(dev, name);
278 if (ret < 0 && ret != -EPROBE_DEFER)
279 dev_err(&dev->dev, "IRQ %s not found\n", name);
280
281 return ret;
282}
268EXPORT_SYMBOL_GPL(platform_get_irq_byname); 283EXPORT_SYMBOL_GPL(platform_get_irq_byname);
269 284
270/** 285/**
286 * platform_get_irq_byname_optional - get an optional IRQ for a device by name
287 * @dev: platform device
288 * @name: IRQ name
289 *
290 * Get an optional IRQ by name like platform_get_irq_byname(). Except that it
291 * does not print an error message if an IRQ can not be obtained.
292 *
293 * Return: IRQ number on success, negative error number on failure.
294 */
295int platform_get_irq_byname_optional(struct platform_device *dev,
296 const char *name)
297{
298 return __platform_get_irq_byname(dev, name);
299}
300EXPORT_SYMBOL_GPL(platform_get_irq_byname_optional);
301
302/**
271 * platform_add_devices - add a numbers of platform devices 303 * platform_add_devices - add a numbers of platform devices
272 * @devs: array of platform devices to add 304 * @devs: array of platform devices to add
273 * @num: number of platform devices in array 305 * @num: number of platform devices in array
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 1410fa893653..f6f77eaa7217 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -994,6 +994,16 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
994 if (!(lo_flags & LO_FLAGS_READ_ONLY) && file->f_op->fsync) 994 if (!(lo_flags & LO_FLAGS_READ_ONLY) && file->f_op->fsync)
995 blk_queue_write_cache(lo->lo_queue, true, false); 995 blk_queue_write_cache(lo->lo_queue, true, false);
996 996
997 if (io_is_direct(lo->lo_backing_file) && inode->i_sb->s_bdev) {
998 /* In case of direct I/O, match underlying block size */
999 unsigned short bsize = bdev_logical_block_size(
1000 inode->i_sb->s_bdev);
1001
1002 blk_queue_logical_block_size(lo->lo_queue, bsize);
1003 blk_queue_physical_block_size(lo->lo_queue, bsize);
1004 blk_queue_io_min(lo->lo_queue, bsize);
1005 }
1006
997 loop_update_rotational(lo); 1007 loop_update_rotational(lo);
998 loop_update_dio(lo); 1008 loop_update_dio(lo);
999 set_capacity(lo->lo_disk, size); 1009 set_capacity(lo->lo_disk, size);
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index ac07e8c94c79..478aa86fc1f2 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -248,8 +248,8 @@ static void nbd_put(struct nbd_device *nbd)
248 if (refcount_dec_and_mutex_lock(&nbd->refs, 248 if (refcount_dec_and_mutex_lock(&nbd->refs,
249 &nbd_index_mutex)) { 249 &nbd_index_mutex)) {
250 idr_remove(&nbd_index_idr, nbd->index); 250 idr_remove(&nbd_index_idr, nbd->index);
251 mutex_unlock(&nbd_index_mutex);
252 nbd_dev_remove(nbd); 251 nbd_dev_remove(nbd);
252 mutex_unlock(&nbd_index_mutex);
253 } 253 }
254} 254}
255 255
diff --git a/drivers/block/null_blk_zoned.c b/drivers/block/null_blk_zoned.c
index eabc116832a7..3d7fdea872f8 100644
--- a/drivers/block/null_blk_zoned.c
+++ b/drivers/block/null_blk_zoned.c
@@ -142,8 +142,7 @@ static blk_status_t null_zone_reset(struct nullb_cmd *cmd, sector_t sector)
142 zone->wp = zone->start; 142 zone->wp = zone->start;
143 break; 143 break;
144 default: 144 default:
145 cmd->error = BLK_STS_NOTSUPP; 145 return BLK_STS_NOTSUPP;
146 break;
147 } 146 }
148 return BLK_STS_OK; 147 return BLK_STS_OK;
149} 148}
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 7c4350c0fb77..39136675dae5 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -6639,10 +6639,13 @@ static int rbd_add_acquire_lock(struct rbd_device *rbd_dev)
6639 queue_delayed_work(rbd_dev->task_wq, &rbd_dev->lock_dwork, 0); 6639 queue_delayed_work(rbd_dev->task_wq, &rbd_dev->lock_dwork, 0);
6640 ret = wait_for_completion_killable_timeout(&rbd_dev->acquire_wait, 6640 ret = wait_for_completion_killable_timeout(&rbd_dev->acquire_wait,
6641 ceph_timeout_jiffies(rbd_dev->opts->lock_timeout)); 6641 ceph_timeout_jiffies(rbd_dev->opts->lock_timeout));
6642 if (ret > 0) 6642 if (ret > 0) {
6643 ret = rbd_dev->acquire_err; 6643 ret = rbd_dev->acquire_err;
6644 else if (!ret) 6644 } else {
6645 ret = -ETIMEDOUT; 6645 cancel_delayed_work_sync(&rbd_dev->lock_dwork);
6646 if (!ret)
6647 ret = -ETIMEDOUT;
6648 }
6646 6649
6647 if (ret) { 6650 if (ret) {
6648 rbd_warn(rbd_dev, "failed to acquire exclusive lock: %ld", ret); 6651 rbd_warn(rbd_dev, "failed to acquire exclusive lock: %ld", ret);
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index d58a359a6622..4285e75e52c3 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -413,13 +413,14 @@ static void reset_bdev(struct zram *zram)
413static ssize_t backing_dev_show(struct device *dev, 413static ssize_t backing_dev_show(struct device *dev,
414 struct device_attribute *attr, char *buf) 414 struct device_attribute *attr, char *buf)
415{ 415{
416 struct file *file;
416 struct zram *zram = dev_to_zram(dev); 417 struct zram *zram = dev_to_zram(dev);
417 struct file *file = zram->backing_dev;
418 char *p; 418 char *p;
419 ssize_t ret; 419 ssize_t ret;
420 420
421 down_read(&zram->init_lock); 421 down_read(&zram->init_lock);
422 if (!zram->backing_dev) { 422 file = zram->backing_dev;
423 if (!file) {
423 memcpy(buf, "none\n", 5); 424 memcpy(buf, "none\n", 5);
424 up_read(&zram->init_lock); 425 up_read(&zram->init_lock);
425 return 5; 426 return 5;
diff --git a/drivers/char/random.c b/drivers/char/random.c
index c2f7de9dc543..de434feb873a 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -2520,4 +2520,4 @@ void add_bootloader_randomness(const void *buf, unsigned int size)
2520 else 2520 else
2521 add_device_randomness(buf, size); 2521 add_device_randomness(buf, size);
2522} 2522}
2523EXPORT_SYMBOL_GPL(add_bootloader_randomness); \ No newline at end of file 2523EXPORT_SYMBOL_GPL(add_bootloader_randomness);
diff --git a/drivers/clk/ti/clk-7xx.c b/drivers/clk/ti/clk-7xx.c
index b57fe09b428b..9dd6185a4b4e 100644
--- a/drivers/clk/ti/clk-7xx.c
+++ b/drivers/clk/ti/clk-7xx.c
@@ -683,7 +683,7 @@ static const struct omap_clkctrl_reg_data dra7_l4per2_clkctrl_regs[] __initconst
683 { DRA7_L4PER2_MCASP2_CLKCTRL, dra7_mcasp2_bit_data, CLKF_SW_SUP, "l4per2-clkctrl:0154:22" }, 683 { DRA7_L4PER2_MCASP2_CLKCTRL, dra7_mcasp2_bit_data, CLKF_SW_SUP, "l4per2-clkctrl:0154:22" },
684 { DRA7_L4PER2_MCASP3_CLKCTRL, dra7_mcasp3_bit_data, CLKF_SW_SUP, "l4per2-clkctrl:015c:22" }, 684 { DRA7_L4PER2_MCASP3_CLKCTRL, dra7_mcasp3_bit_data, CLKF_SW_SUP, "l4per2-clkctrl:015c:22" },
685 { DRA7_L4PER2_MCASP5_CLKCTRL, dra7_mcasp5_bit_data, CLKF_SW_SUP, "l4per2-clkctrl:016c:22" }, 685 { DRA7_L4PER2_MCASP5_CLKCTRL, dra7_mcasp5_bit_data, CLKF_SW_SUP, "l4per2-clkctrl:016c:22" },
686 { DRA7_L4PER2_MCASP8_CLKCTRL, dra7_mcasp8_bit_data, CLKF_SW_SUP, "l4per2-clkctrl:0184:24" }, 686 { DRA7_L4PER2_MCASP8_CLKCTRL, dra7_mcasp8_bit_data, CLKF_SW_SUP, "l4per2-clkctrl:0184:22" },
687 { DRA7_L4PER2_MCASP4_CLKCTRL, dra7_mcasp4_bit_data, CLKF_SW_SUP, "l4per2-clkctrl:018c:22" }, 687 { DRA7_L4PER2_MCASP4_CLKCTRL, dra7_mcasp4_bit_data, CLKF_SW_SUP, "l4per2-clkctrl:018c:22" },
688 { DRA7_L4PER2_UART7_CLKCTRL, dra7_uart7_bit_data, CLKF_SW_SUP, "l4per2-clkctrl:01c4:24" }, 688 { DRA7_L4PER2_UART7_CLKCTRL, dra7_uart7_bit_data, CLKF_SW_SUP, "l4per2-clkctrl:01c4:24" },
689 { DRA7_L4PER2_UART8_CLKCTRL, dra7_uart8_bit_data, CLKF_SW_SUP, "l4per2-clkctrl:01d4:24" }, 689 { DRA7_L4PER2_UART8_CLKCTRL, dra7_uart8_bit_data, CLKF_SW_SUP, "l4per2-clkctrl:01d4:24" },
@@ -828,8 +828,8 @@ static struct ti_dt_clk dra7xx_clks[] = {
828 DT_CLK(NULL, "mcasp6_aux_gfclk_mux", "l4per2-clkctrl:01f8:22"), 828 DT_CLK(NULL, "mcasp6_aux_gfclk_mux", "l4per2-clkctrl:01f8:22"),
829 DT_CLK(NULL, "mcasp7_ahclkx_mux", "l4per2-clkctrl:01fc:24"), 829 DT_CLK(NULL, "mcasp7_ahclkx_mux", "l4per2-clkctrl:01fc:24"),
830 DT_CLK(NULL, "mcasp7_aux_gfclk_mux", "l4per2-clkctrl:01fc:22"), 830 DT_CLK(NULL, "mcasp7_aux_gfclk_mux", "l4per2-clkctrl:01fc:22"),
831 DT_CLK(NULL, "mcasp8_ahclkx_mux", "l4per2-clkctrl:0184:22"), 831 DT_CLK(NULL, "mcasp8_ahclkx_mux", "l4per2-clkctrl:0184:24"),
832 DT_CLK(NULL, "mcasp8_aux_gfclk_mux", "l4per2-clkctrl:0184:24"), 832 DT_CLK(NULL, "mcasp8_aux_gfclk_mux", "l4per2-clkctrl:0184:22"),
833 DT_CLK(NULL, "mmc1_clk32k", "l3init-clkctrl:0008:8"), 833 DT_CLK(NULL, "mmc1_clk32k", "l3init-clkctrl:0008:8"),
834 DT_CLK(NULL, "mmc1_fclk_div", "l3init-clkctrl:0008:25"), 834 DT_CLK(NULL, "mmc1_fclk_div", "l3init-clkctrl:0008:25"),
835 DT_CLK(NULL, "mmc1_fclk_mux", "l3init-clkctrl:0008:24"), 835 DT_CLK(NULL, "mmc1_fclk_mux", "l3init-clkctrl:0008:24"),
diff --git a/drivers/clocksource/timer-of.c b/drivers/clocksource/timer-of.c
index d8c2bd4391d0..11ff701ff4bb 100644
--- a/drivers/clocksource/timer-of.c
+++ b/drivers/clocksource/timer-of.c
@@ -25,7 +25,9 @@ static __init void timer_of_irq_exit(struct of_timer_irq *of_irq)
25 25
26 struct clock_event_device *clkevt = &to->clkevt; 26 struct clock_event_device *clkevt = &to->clkevt;
27 27
28 of_irq->percpu ? free_percpu_irq(of_irq->irq, clkevt) : 28 if (of_irq->percpu)
29 free_percpu_irq(of_irq->irq, clkevt);
30 else
29 free_irq(of_irq->irq, clkevt); 31 free_irq(of_irq->irq, clkevt);
30} 32}
31 33
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index c52d6fa32aac..bffc11b87247 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2737,14 +2737,6 @@ int cpufreq_unregister_driver(struct cpufreq_driver *driver)
2737} 2737}
2738EXPORT_SYMBOL_GPL(cpufreq_unregister_driver); 2738EXPORT_SYMBOL_GPL(cpufreq_unregister_driver);
2739 2739
2740/*
2741 * Stop cpufreq at shutdown to make sure it isn't holding any locks
2742 * or mutexes when secondary CPUs are halted.
2743 */
2744static struct syscore_ops cpufreq_syscore_ops = {
2745 .shutdown = cpufreq_suspend,
2746};
2747
2748struct kobject *cpufreq_global_kobject; 2740struct kobject *cpufreq_global_kobject;
2749EXPORT_SYMBOL(cpufreq_global_kobject); 2741EXPORT_SYMBOL(cpufreq_global_kobject);
2750 2742
@@ -2756,8 +2748,6 @@ static int __init cpufreq_core_init(void)
2756 cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj); 2748 cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj);
2757 BUG_ON(!cpufreq_global_kobject); 2749 BUG_ON(!cpufreq_global_kobject);
2758 2750
2759 register_syscore_ops(&cpufreq_syscore_ops);
2760
2761 return 0; 2751 return 0;
2762} 2752}
2763module_param(off, int, 0444); 2753module_param(off, int, 0444);
diff --git a/drivers/crypto/chelsio/chtls/chtls_io.c b/drivers/crypto/chelsio/chtls/chtls_io.c
index 0891ab829b1b..98bc5a4cd5e7 100644
--- a/drivers/crypto/chelsio/chtls/chtls_io.c
+++ b/drivers/crypto/chelsio/chtls/chtls_io.c
@@ -1702,7 +1702,7 @@ int chtls_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
1702 return peekmsg(sk, msg, len, nonblock, flags); 1702 return peekmsg(sk, msg, len, nonblock, flags);
1703 1703
1704 if (sk_can_busy_loop(sk) && 1704 if (sk_can_busy_loop(sk) &&
1705 skb_queue_empty(&sk->sk_receive_queue) && 1705 skb_queue_empty_lockless(&sk->sk_receive_queue) &&
1706 sk->sk_state == TCP_ESTABLISHED) 1706 sk->sk_state == TCP_ESTABLISHED)
1707 sk_busy_loop(sk, nonblock); 1707 sk_busy_loop(sk, nonblock);
1708 1708
diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
index 42a8f3f11681..709002515550 100644
--- a/drivers/dma-buf/dma-resv.c
+++ b/drivers/dma-buf/dma-resv.c
@@ -471,7 +471,7 @@ unlock:
471 if (pfence_excl) 471 if (pfence_excl)
472 *pfence_excl = fence_excl; 472 *pfence_excl = fence_excl;
473 else if (fence_excl) 473 else if (fence_excl)
474 shared[++shared_count] = fence_excl; 474 shared[shared_count++] = fence_excl;
475 475
476 if (!shared_count) { 476 if (!shared_count) {
477 kfree(shared); 477 kfree(shared);
diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
index 35ed56b9c34f..1e21fc3e9851 100644
--- a/drivers/firmware/dmi_scan.c
+++ b/drivers/firmware/dmi_scan.c
@@ -408,7 +408,7 @@ static void __init save_mem_devices(const struct dmi_header *dm, void *v)
408 bytes = ~0ull; 408 bytes = ~0ull;
409 else if (size & 0x8000) 409 else if (size & 0x8000)
410 bytes = (u64)(size & 0x7fff) << 10; 410 bytes = (u64)(size & 0x7fff) << 10;
411 else if (size != 0x7fff) 411 else if (size != 0x7fff || dm->length < 0x20)
412 bytes = (u64)size << 20; 412 bytes = (u64)size << 20;
413 else 413 else
414 bytes = (u64)get_unaligned((u32 *)&d[0x1C]) << 20; 414 bytes = (u64)get_unaligned((u32 *)&d[0x1C]) << 20;
diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
index addf0749dd8b..b1af0de2e100 100644
--- a/drivers/firmware/efi/cper.c
+++ b/drivers/firmware/efi/cper.c
@@ -381,7 +381,7 @@ static void cper_print_pcie(const char *pfx, const struct cper_sec_pcie *pcie,
381 printk("%s""vendor_id: 0x%04x, device_id: 0x%04x\n", pfx, 381 printk("%s""vendor_id: 0x%04x, device_id: 0x%04x\n", pfx,
382 pcie->device_id.vendor_id, pcie->device_id.device_id); 382 pcie->device_id.vendor_id, pcie->device_id.device_id);
383 p = pcie->device_id.class_code; 383 p = pcie->device_id.class_code;
384 printk("%s""class_code: %02x%02x%02x\n", pfx, p[0], p[1], p[2]); 384 printk("%s""class_code: %02x%02x%02x\n", pfx, p[2], p[1], p[0]);
385 } 385 }
386 if (pcie->validation_bits & CPER_PCIE_VALID_SERIAL_NUMBER) 386 if (pcie->validation_bits & CPER_PCIE_VALID_SERIAL_NUMBER)
387 printk("%s""serial number: 0x%04x, 0x%04x\n", pfx, 387 printk("%s""serial number: 0x%04x, 0x%04x\n", pfx,
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 8d3e778e988b..69f00f7453a3 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -267,6 +267,9 @@ static __init int efivar_ssdt_load(void)
267 void *data; 267 void *data;
268 int ret; 268 int ret;
269 269
270 if (!efivar_ssdt[0])
271 return 0;
272
270 ret = efivar_init(efivar_ssdt_iter, &entries, true, &entries); 273 ret = efivar_init(efivar_ssdt_iter, &entries, true, &entries);
271 274
272 list_for_each_entry_safe(entry, aux, &entries, list) { 275 list_for_each_entry_safe(entry, aux, &entries, list) {
diff --git a/drivers/firmware/efi/rci2-table.c b/drivers/firmware/efi/rci2-table.c
index 3e290f96620a..76b0c354a027 100644
--- a/drivers/firmware/efi/rci2-table.c
+++ b/drivers/firmware/efi/rci2-table.c
@@ -76,7 +76,7 @@ static u16 checksum(void)
76 return chksum; 76 return chksum;
77} 77}
78 78
79int __init efi_rci2_sysfs_init(void) 79static int __init efi_rci2_sysfs_init(void)
80{ 80{
81 struct kobject *tables_kobj; 81 struct kobject *tables_kobj;
82 int ret = -ENOMEM; 82 int ret = -ENOMEM;
diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c
index 1d3f5ca3eaaf..ebd7977653a8 100644
--- a/drivers/firmware/efi/tpm.c
+++ b/drivers/firmware/efi/tpm.c
@@ -40,7 +40,7 @@ int __init efi_tpm_eventlog_init(void)
40{ 40{
41 struct linux_efi_tpm_eventlog *log_tbl; 41 struct linux_efi_tpm_eventlog *log_tbl;
42 struct efi_tcg2_final_events_table *final_tbl; 42 struct efi_tcg2_final_events_table *final_tbl;
43 unsigned int tbl_size; 43 int tbl_size;
44 int ret = 0; 44 int ret = 0;
45 45
46 if (efi.tpm_log == EFI_INVALID_TABLE_ADDR) { 46 if (efi.tpm_log == EFI_INVALID_TABLE_ADDR) {
@@ -75,16 +75,28 @@ int __init efi_tpm_eventlog_init(void)
75 goto out; 75 goto out;
76 } 76 }
77 77
78 tbl_size = tpm2_calc_event_log_size((void *)efi.tpm_final_log 78 tbl_size = 0;
79 + sizeof(final_tbl->version) 79 if (final_tbl->nr_events != 0) {
80 + sizeof(final_tbl->nr_events), 80 void *events = (void *)efi.tpm_final_log
81 final_tbl->nr_events, 81 + sizeof(final_tbl->version)
82 log_tbl->log); 82 + sizeof(final_tbl->nr_events);
83
84 tbl_size = tpm2_calc_event_log_size(events,
85 final_tbl->nr_events,
86 log_tbl->log);
87 }
88
89 if (tbl_size < 0) {
90 pr_err(FW_BUG "Failed to parse event in TPM Final Events Log\n");
91 goto out_calc;
92 }
93
83 memblock_reserve((unsigned long)final_tbl, 94 memblock_reserve((unsigned long)final_tbl,
84 tbl_size + sizeof(*final_tbl)); 95 tbl_size + sizeof(*final_tbl));
85 early_memunmap(final_tbl, sizeof(*final_tbl));
86 efi_tpm_final_log_size = tbl_size; 96 efi_tpm_final_log_size = tbl_size;
87 97
98out_calc:
99 early_memunmap(final_tbl, sizeof(*final_tbl));
88out: 100out:
89 early_memunmap(log_tbl, sizeof(*log_tbl)); 101 early_memunmap(log_tbl, sizeof(*log_tbl));
90 return ret; 102 return ret;
diff --git a/drivers/firmware/google/vpd_decode.c b/drivers/firmware/google/vpd_decode.c
index dda525c0f968..5c6f2a74f104 100644
--- a/drivers/firmware/google/vpd_decode.c
+++ b/drivers/firmware/google/vpd_decode.c
@@ -52,7 +52,7 @@ static int vpd_decode_entry(const u32 max_len, const u8 *input_buf,
52 if (max_len - consumed < *entry_len) 52 if (max_len - consumed < *entry_len)
53 return VPD_FAIL; 53 return VPD_FAIL;
54 54
55 consumed += decoded_len; 55 consumed += *entry_len;
56 *_consumed = consumed; 56 *_consumed = consumed;
57 return VPD_OK; 57 return VPD_OK;
58} 58}
diff --git a/drivers/gpio/gpio-eic-sprd.c b/drivers/gpio/gpio-eic-sprd.c
index fe7a73f52329..bb287f35cf40 100644
--- a/drivers/gpio/gpio-eic-sprd.c
+++ b/drivers/gpio/gpio-eic-sprd.c
@@ -530,11 +530,12 @@ static void sprd_eic_handle_one_type(struct gpio_chip *chip)
530 } 530 }
531 531
532 for_each_set_bit(n, &reg, SPRD_EIC_PER_BANK_NR) { 532 for_each_set_bit(n, &reg, SPRD_EIC_PER_BANK_NR) {
533 girq = irq_find_mapping(chip->irq.domain, 533 u32 offset = bank * SPRD_EIC_PER_BANK_NR + n;
534 bank * SPRD_EIC_PER_BANK_NR + n); 534
535 girq = irq_find_mapping(chip->irq.domain, offset);
535 536
536 generic_handle_irq(girq); 537 generic_handle_irq(girq);
537 sprd_eic_toggle_trigger(chip, girq, n); 538 sprd_eic_toggle_trigger(chip, girq, offset);
538 } 539 }
539 } 540 }
540} 541}
diff --git a/drivers/gpio/gpio-intel-mid.c b/drivers/gpio/gpio-intel-mid.c
index 4d835f9089df..86a10c808ef6 100644
--- a/drivers/gpio/gpio-intel-mid.c
+++ b/drivers/gpio/gpio-intel-mid.c
@@ -293,8 +293,9 @@ static void intel_mid_irq_handler(struct irq_desc *desc)
293 chip->irq_eoi(data); 293 chip->irq_eoi(data);
294} 294}
295 295
296static void intel_mid_irq_init_hw(struct intel_mid_gpio *priv) 296static int intel_mid_irq_init_hw(struct gpio_chip *chip)
297{ 297{
298 struct intel_mid_gpio *priv = gpiochip_get_data(chip);
298 void __iomem *reg; 299 void __iomem *reg;
299 unsigned base; 300 unsigned base;
300 301
@@ -309,6 +310,8 @@ static void intel_mid_irq_init_hw(struct intel_mid_gpio *priv)
309 reg = gpio_reg(&priv->chip, base, GEDR); 310 reg = gpio_reg(&priv->chip, base, GEDR);
310 writel(~0, reg); 311 writel(~0, reg);
311 } 312 }
313
314 return 0;
312} 315}
313 316
314static int __maybe_unused intel_gpio_runtime_idle(struct device *dev) 317static int __maybe_unused intel_gpio_runtime_idle(struct device *dev)
@@ -372,6 +375,7 @@ static int intel_gpio_probe(struct pci_dev *pdev,
372 375
373 girq = &priv->chip.irq; 376 girq = &priv->chip.irq;
374 girq->chip = &intel_mid_irqchip; 377 girq->chip = &intel_mid_irqchip;
378 girq->init_hw = intel_mid_irq_init_hw;
375 girq->parent_handler = intel_mid_irq_handler; 379 girq->parent_handler = intel_mid_irq_handler;
376 girq->num_parents = 1; 380 girq->num_parents = 1;
377 girq->parents = devm_kcalloc(&pdev->dev, girq->num_parents, 381 girq->parents = devm_kcalloc(&pdev->dev, girq->num_parents,
@@ -384,9 +388,8 @@ static int intel_gpio_probe(struct pci_dev *pdev,
384 girq->default_type = IRQ_TYPE_NONE; 388 girq->default_type = IRQ_TYPE_NONE;
385 girq->handler = handle_simple_irq; 389 girq->handler = handle_simple_irq;
386 390
387 intel_mid_irq_init_hw(priv);
388
389 pci_set_drvdata(pdev, priv); 391 pci_set_drvdata(pdev, priv);
392
390 retval = devm_gpiochip_add_data(&pdev->dev, &priv->chip, priv); 393 retval = devm_gpiochip_add_data(&pdev->dev, &priv->chip, priv);
391 if (retval) { 394 if (retval) {
392 dev_err(&pdev->dev, "gpiochip_add error %d\n", retval); 395 dev_err(&pdev->dev, "gpiochip_add error %d\n", retval);
diff --git a/drivers/gpio/gpio-lynxpoint.c b/drivers/gpio/gpio-lynxpoint.c
index 6bb9741ad036..e9e47c0d5be7 100644
--- a/drivers/gpio/gpio-lynxpoint.c
+++ b/drivers/gpio/gpio-lynxpoint.c
@@ -294,8 +294,9 @@ static struct irq_chip lp_irqchip = {
294 .flags = IRQCHIP_SKIP_SET_WAKE, 294 .flags = IRQCHIP_SKIP_SET_WAKE,
295}; 295};
296 296
297static void lp_gpio_irq_init_hw(struct lp_gpio *lg) 297static int lp_gpio_irq_init_hw(struct gpio_chip *chip)
298{ 298{
299 struct lp_gpio *lg = gpiochip_get_data(chip);
299 unsigned long reg; 300 unsigned long reg;
300 unsigned base; 301 unsigned base;
301 302
@@ -307,6 +308,8 @@ static void lp_gpio_irq_init_hw(struct lp_gpio *lg)
307 reg = lp_gpio_reg(&lg->chip, base, LP_INT_STAT); 308 reg = lp_gpio_reg(&lg->chip, base, LP_INT_STAT);
308 outl(0xffffffff, reg); 309 outl(0xffffffff, reg);
309 } 310 }
311
312 return 0;
310} 313}
311 314
312static int lp_gpio_probe(struct platform_device *pdev) 315static int lp_gpio_probe(struct platform_device *pdev)
@@ -364,6 +367,7 @@ static int lp_gpio_probe(struct platform_device *pdev)
364 367
365 girq = &gc->irq; 368 girq = &gc->irq;
366 girq->chip = &lp_irqchip; 369 girq->chip = &lp_irqchip;
370 girq->init_hw = lp_gpio_irq_init_hw;
367 girq->parent_handler = lp_gpio_irq_handler; 371 girq->parent_handler = lp_gpio_irq_handler;
368 girq->num_parents = 1; 372 girq->num_parents = 1;
369 girq->parents = devm_kcalloc(&pdev->dev, girq->num_parents, 373 girq->parents = devm_kcalloc(&pdev->dev, girq->num_parents,
@@ -373,9 +377,7 @@ static int lp_gpio_probe(struct platform_device *pdev)
373 return -ENOMEM; 377 return -ENOMEM;
374 girq->parents[0] = (unsigned)irq_rc->start; 378 girq->parents[0] = (unsigned)irq_rc->start;
375 girq->default_type = IRQ_TYPE_NONE; 379 girq->default_type = IRQ_TYPE_NONE;
376 girq->handler = handle_simple_irq; 380 girq->handler = handle_bad_irq;
377
378 lp_gpio_irq_init_hw(lg);
379 } 381 }
380 382
381 ret = devm_gpiochip_add_data(dev, gc, lg); 383 ret = devm_gpiochip_add_data(dev, gc, lg);
diff --git a/drivers/gpio/gpio-max77620.c b/drivers/gpio/gpio-max77620.c
index 47d05e357e61..faf86ea9c51a 100644
--- a/drivers/gpio/gpio-max77620.c
+++ b/drivers/gpio/gpio-max77620.c
@@ -192,13 +192,13 @@ static int max77620_gpio_set_debounce(struct max77620_gpio *mgpio,
192 case 0: 192 case 0:
193 val = MAX77620_CNFG_GPIO_DBNC_None; 193 val = MAX77620_CNFG_GPIO_DBNC_None;
194 break; 194 break;
195 case 1 ... 8: 195 case 1000 ... 8000:
196 val = MAX77620_CNFG_GPIO_DBNC_8ms; 196 val = MAX77620_CNFG_GPIO_DBNC_8ms;
197 break; 197 break;
198 case 9 ... 16: 198 case 9000 ... 16000:
199 val = MAX77620_CNFG_GPIO_DBNC_16ms; 199 val = MAX77620_CNFG_GPIO_DBNC_16ms;
200 break; 200 break;
201 case 17 ... 32: 201 case 17000 ... 32000:
202 val = MAX77620_CNFG_GPIO_DBNC_32ms; 202 val = MAX77620_CNFG_GPIO_DBNC_32ms;
203 break; 203 break;
204 default: 204 default:
diff --git a/drivers/gpio/gpio-merrifield.c b/drivers/gpio/gpio-merrifield.c
index 4f27ddfe1e2f..2f1e9da81c1e 100644
--- a/drivers/gpio/gpio-merrifield.c
+++ b/drivers/gpio/gpio-merrifield.c
@@ -362,8 +362,9 @@ static void mrfld_irq_handler(struct irq_desc *desc)
362 chained_irq_exit(irqchip, desc); 362 chained_irq_exit(irqchip, desc);
363} 363}
364 364
365static void mrfld_irq_init_hw(struct mrfld_gpio *priv) 365static int mrfld_irq_init_hw(struct gpio_chip *chip)
366{ 366{
367 struct mrfld_gpio *priv = gpiochip_get_data(chip);
367 void __iomem *reg; 368 void __iomem *reg;
368 unsigned int base; 369 unsigned int base;
369 370
@@ -375,6 +376,8 @@ static void mrfld_irq_init_hw(struct mrfld_gpio *priv)
375 reg = gpio_reg(&priv->chip, base, GFER); 376 reg = gpio_reg(&priv->chip, base, GFER);
376 writel(0, reg); 377 writel(0, reg);
377 } 378 }
379
380 return 0;
378} 381}
379 382
380static const char *mrfld_gpio_get_pinctrl_dev_name(struct mrfld_gpio *priv) 383static const char *mrfld_gpio_get_pinctrl_dev_name(struct mrfld_gpio *priv)
@@ -447,6 +450,7 @@ static int mrfld_gpio_probe(struct pci_dev *pdev, const struct pci_device_id *id
447 450
448 girq = &priv->chip.irq; 451 girq = &priv->chip.irq;
449 girq->chip = &mrfld_irqchip; 452 girq->chip = &mrfld_irqchip;
453 girq->init_hw = mrfld_irq_init_hw;
450 girq->parent_handler = mrfld_irq_handler; 454 girq->parent_handler = mrfld_irq_handler;
451 girq->num_parents = 1; 455 girq->num_parents = 1;
452 girq->parents = devm_kcalloc(&pdev->dev, girq->num_parents, 456 girq->parents = devm_kcalloc(&pdev->dev, girq->num_parents,
@@ -455,11 +459,10 @@ static int mrfld_gpio_probe(struct pci_dev *pdev, const struct pci_device_id *id
455 if (!girq->parents) 459 if (!girq->parents)
456 return -ENOMEM; 460 return -ENOMEM;
457 girq->parents[0] = pdev->irq; 461 girq->parents[0] = pdev->irq;
462 girq->first = irq_base;
458 girq->default_type = IRQ_TYPE_NONE; 463 girq->default_type = IRQ_TYPE_NONE;
459 girq->handler = handle_bad_irq; 464 girq->handler = handle_bad_irq;
460 465
461 mrfld_irq_init_hw(priv);
462
463 pci_set_drvdata(pdev, priv); 466 pci_set_drvdata(pdev, priv);
464 retval = devm_gpiochip_add_data(&pdev->dev, &priv->chip, priv); 467 retval = devm_gpiochip_add_data(&pdev->dev, &priv->chip, priv);
465 if (retval) { 468 if (retval) {
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 1eea2c6c2e1d..80ea49f570f4 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -317,7 +317,7 @@ struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
317 transitory = flags & OF_GPIO_TRANSITORY; 317 transitory = flags & OF_GPIO_TRANSITORY;
318 318
319 ret = gpiod_request(desc, label); 319 ret = gpiod_request(desc, label);
320 if (ret == -EBUSY && (flags & GPIOD_FLAGS_BIT_NONEXCLUSIVE)) 320 if (ret == -EBUSY && (dflags & GPIOD_FLAGS_BIT_NONEXCLUSIVE))
321 return desc; 321 return desc;
322 if (ret) 322 if (ret)
323 return ERR_PTR(ret); 323 return ERR_PTR(ret);
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index bdbc1649eafa..104ed299d5ea 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -86,6 +86,7 @@ static int gpiochip_add_irqchip(struct gpio_chip *gpiochip,
86 struct lock_class_key *lock_key, 86 struct lock_class_key *lock_key,
87 struct lock_class_key *request_key); 87 struct lock_class_key *request_key);
88static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip); 88static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip);
89static int gpiochip_irqchip_init_hw(struct gpio_chip *gpiochip);
89static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gpiochip); 90static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gpiochip);
90static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gpiochip); 91static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gpiochip);
91 92
@@ -1406,6 +1407,10 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
1406 1407
1407 machine_gpiochip_add(chip); 1408 machine_gpiochip_add(chip);
1408 1409
1410 ret = gpiochip_irqchip_init_hw(chip);
1411 if (ret)
1412 goto err_remove_acpi_chip;
1413
1409 ret = gpiochip_irqchip_init_valid_mask(chip); 1414 ret = gpiochip_irqchip_init_valid_mask(chip);
1410 if (ret) 1415 if (ret)
1411 goto err_remove_acpi_chip; 1416 goto err_remove_acpi_chip;
@@ -1622,6 +1627,16 @@ static struct gpio_chip *find_chip_by_name(const char *name)
1622 * The following is irqchip helper code for gpiochips. 1627 * The following is irqchip helper code for gpiochips.
1623 */ 1628 */
1624 1629
1630static int gpiochip_irqchip_init_hw(struct gpio_chip *gc)
1631{
1632 struct gpio_irq_chip *girq = &gc->irq;
1633
1634 if (!girq->init_hw)
1635 return 0;
1636
1637 return girq->init_hw(gc);
1638}
1639
1625static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc) 1640static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc)
1626{ 1641{
1627 struct gpio_irq_chip *girq = &gc->irq; 1642 struct gpio_irq_chip *girq = &gc->irq;
@@ -2446,8 +2461,13 @@ static inline int gpiochip_add_irqchip(struct gpio_chip *gpiochip,
2446{ 2461{
2447 return 0; 2462 return 0;
2448} 2463}
2449
2450static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip) {} 2464static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip) {}
2465
2466static inline int gpiochip_irqchip_init_hw(struct gpio_chip *gpiochip)
2467{
2468 return 0;
2469}
2470
2451static inline int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gpiochip) 2471static inline int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gpiochip)
2452{ 2472{
2453 return 0; 2473 return 0;
@@ -3070,8 +3090,10 @@ int gpiod_direction_output(struct gpio_desc *desc, int value)
3070 if (!ret) 3090 if (!ret)
3071 goto set_output_value; 3091 goto set_output_value;
3072 /* Emulate open drain by not actively driving the line high */ 3092 /* Emulate open drain by not actively driving the line high */
3073 if (value) 3093 if (value) {
3074 return gpiod_direction_input(desc); 3094 ret = gpiod_direction_input(desc);
3095 goto set_output_flag;
3096 }
3075 } 3097 }
3076 else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) { 3098 else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) {
3077 ret = gpio_set_config(gc, gpio_chip_hwgpio(desc), 3099 ret = gpio_set_config(gc, gpio_chip_hwgpio(desc),
@@ -3079,8 +3101,10 @@ int gpiod_direction_output(struct gpio_desc *desc, int value)
3079 if (!ret) 3101 if (!ret)
3080 goto set_output_value; 3102 goto set_output_value;
3081 /* Emulate open source by not actively driving the line low */ 3103 /* Emulate open source by not actively driving the line low */
3082 if (!value) 3104 if (!value) {
3083 return gpiod_direction_input(desc); 3105 ret = gpiod_direction_input(desc);
3106 goto set_output_flag;
3107 }
3084 } else { 3108 } else {
3085 gpio_set_config(gc, gpio_chip_hwgpio(desc), 3109 gpio_set_config(gc, gpio_chip_hwgpio(desc),
3086 PIN_CONFIG_DRIVE_PUSH_PULL); 3110 PIN_CONFIG_DRIVE_PUSH_PULL);
@@ -3088,6 +3112,17 @@ int gpiod_direction_output(struct gpio_desc *desc, int value)
3088 3112
3089set_output_value: 3113set_output_value:
3090 return gpiod_direction_output_raw_commit(desc, value); 3114 return gpiod_direction_output_raw_commit(desc, value);
3115
3116set_output_flag:
3117 /*
3118 * When emulating open-source or open-drain functionalities by not
3119 * actively driving the line (setting mode to input) we still need to
3120 * set the IS_OUT flag or otherwise we won't be able to set the line
3121 * value anymore.
3122 */
3123 if (ret == 0)
3124 set_bit(FLAG_IS_OUT, &desc->flags);
3125 return ret;
3091} 3126}
3092EXPORT_SYMBOL_GPL(gpiod_direction_output); 3127EXPORT_SYMBOL_GPL(gpiod_direction_output);
3093 3128
@@ -3448,8 +3483,6 @@ static void gpio_set_open_drain_value_commit(struct gpio_desc *desc, bool value)
3448 3483
3449 if (value) { 3484 if (value) {
3450 ret = chip->direction_input(chip, offset); 3485 ret = chip->direction_input(chip, offset);
3451 if (!ret)
3452 clear_bit(FLAG_IS_OUT, &desc->flags);
3453 } else { 3486 } else {
3454 ret = chip->direction_output(chip, offset, 0); 3487 ret = chip->direction_output(chip, offset, 0);
3455 if (!ret) 3488 if (!ret)
@@ -3479,8 +3512,6 @@ static void gpio_set_open_source_value_commit(struct gpio_desc *desc, bool value
3479 set_bit(FLAG_IS_OUT, &desc->flags); 3512 set_bit(FLAG_IS_OUT, &desc->flags);
3480 } else { 3513 } else {
3481 ret = chip->direction_input(chip, offset); 3514 ret = chip->direction_input(chip, offset);
3482 if (!ret)
3483 clear_bit(FLAG_IS_OUT, &desc->flags);
3484 } 3515 }
3485 trace_gpio_direction(desc_to_gpio(desc), !value, ret); 3516 trace_gpio_direction(desc_to_gpio(desc), !value, ret);
3486 if (ret < 0) 3517 if (ret < 0)
diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile b/drivers/gpu/drm/amd/amdgpu/Makefile
index 42e2c1f57152..00962a659009 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -54,7 +54,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
54 amdgpu_gtt_mgr.o amdgpu_vram_mgr.o amdgpu_virt.o amdgpu_atomfirmware.o \ 54 amdgpu_gtt_mgr.o amdgpu_vram_mgr.o amdgpu_virt.o amdgpu_atomfirmware.o \
55 amdgpu_vf_error.o amdgpu_sched.o amdgpu_debugfs.o amdgpu_ids.o \ 55 amdgpu_vf_error.o amdgpu_sched.o amdgpu_debugfs.o amdgpu_ids.o \
56 amdgpu_gmc.o amdgpu_xgmi.o amdgpu_csa.o amdgpu_ras.o amdgpu_vm_cpu.o \ 56 amdgpu_gmc.o amdgpu_xgmi.o amdgpu_csa.o amdgpu_ras.o amdgpu_vm_cpu.o \
57 amdgpu_vm_sdma.o amdgpu_pmu.o amdgpu_discovery.o amdgpu_ras_eeprom.o smu_v11_0_i2c.o 57 amdgpu_vm_sdma.o amdgpu_discovery.o amdgpu_ras_eeprom.o smu_v11_0_i2c.o
58 58
59amdgpu-$(CONFIG_PERF_EVENTS) += amdgpu_pmu.o 59amdgpu-$(CONFIG_PERF_EVENTS) += amdgpu_pmu.o
60 60
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c
index eba42c752bca..82155ac3288a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c
@@ -189,7 +189,7 @@ static int acp_hw_init(void *handle)
189 u32 val = 0; 189 u32 val = 0;
190 u32 count = 0; 190 u32 count = 0;
191 struct device *dev; 191 struct device *dev;
192 struct i2s_platform_data *i2s_pdata; 192 struct i2s_platform_data *i2s_pdata = NULL;
193 193
194 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 194 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
195 195
@@ -231,20 +231,21 @@ static int acp_hw_init(void *handle)
231 adev->acp.acp_cell = kcalloc(ACP_DEVS, sizeof(struct mfd_cell), 231 adev->acp.acp_cell = kcalloc(ACP_DEVS, sizeof(struct mfd_cell),
232 GFP_KERNEL); 232 GFP_KERNEL);
233 233
234 if (adev->acp.acp_cell == NULL) 234 if (adev->acp.acp_cell == NULL) {
235 return -ENOMEM; 235 r = -ENOMEM;
236 goto failure;
237 }
236 238
237 adev->acp.acp_res = kcalloc(5, sizeof(struct resource), GFP_KERNEL); 239 adev->acp.acp_res = kcalloc(5, sizeof(struct resource), GFP_KERNEL);
238 if (adev->acp.acp_res == NULL) { 240 if (adev->acp.acp_res == NULL) {
239 kfree(adev->acp.acp_cell); 241 r = -ENOMEM;
240 return -ENOMEM; 242 goto failure;
241 } 243 }
242 244
243 i2s_pdata = kcalloc(3, sizeof(struct i2s_platform_data), GFP_KERNEL); 245 i2s_pdata = kcalloc(3, sizeof(struct i2s_platform_data), GFP_KERNEL);
244 if (i2s_pdata == NULL) { 246 if (i2s_pdata == NULL) {
245 kfree(adev->acp.acp_res); 247 r = -ENOMEM;
246 kfree(adev->acp.acp_cell); 248 goto failure;
247 return -ENOMEM;
248 } 249 }
249 250
250 switch (adev->asic_type) { 251 switch (adev->asic_type) {
@@ -341,14 +342,14 @@ static int acp_hw_init(void *handle)
341 r = mfd_add_hotplug_devices(adev->acp.parent, adev->acp.acp_cell, 342 r = mfd_add_hotplug_devices(adev->acp.parent, adev->acp.acp_cell,
342 ACP_DEVS); 343 ACP_DEVS);
343 if (r) 344 if (r)
344 return r; 345 goto failure;
345 346
346 for (i = 0; i < ACP_DEVS ; i++) { 347 for (i = 0; i < ACP_DEVS ; i++) {
347 dev = get_mfd_cell_dev(adev->acp.acp_cell[i].name, i); 348 dev = get_mfd_cell_dev(adev->acp.acp_cell[i].name, i);
348 r = pm_genpd_add_device(&adev->acp.acp_genpd->gpd, dev); 349 r = pm_genpd_add_device(&adev->acp.acp_genpd->gpd, dev);
349 if (r) { 350 if (r) {
350 dev_err(dev, "Failed to add dev to genpd\n"); 351 dev_err(dev, "Failed to add dev to genpd\n");
351 return r; 352 goto failure;
352 } 353 }
353 } 354 }
354 355
@@ -367,7 +368,8 @@ static int acp_hw_init(void *handle)
367 break; 368 break;
368 if (--count == 0) { 369 if (--count == 0) {
369 dev_err(&adev->pdev->dev, "Failed to reset ACP\n"); 370 dev_err(&adev->pdev->dev, "Failed to reset ACP\n");
370 return -ETIMEDOUT; 371 r = -ETIMEDOUT;
372 goto failure;
371 } 373 }
372 udelay(100); 374 udelay(100);
373 } 375 }
@@ -384,7 +386,8 @@ static int acp_hw_init(void *handle)
384 break; 386 break;
385 if (--count == 0) { 387 if (--count == 0) {
386 dev_err(&adev->pdev->dev, "Failed to reset ACP\n"); 388 dev_err(&adev->pdev->dev, "Failed to reset ACP\n");
387 return -ETIMEDOUT; 389 r = -ETIMEDOUT;
390 goto failure;
388 } 391 }
389 udelay(100); 392 udelay(100);
390 } 393 }
@@ -393,6 +396,13 @@ static int acp_hw_init(void *handle)
393 val &= ~ACP_SOFT_RESET__SoftResetAud_MASK; 396 val &= ~ACP_SOFT_RESET__SoftResetAud_MASK;
394 cgs_write_register(adev->acp.cgs_device, mmACP_SOFT_RESET, val); 397 cgs_write_register(adev->acp.cgs_device, mmACP_SOFT_RESET, val);
395 return 0; 398 return 0;
399
400failure:
401 kfree(i2s_pdata);
402 kfree(adev->acp.acp_res);
403 kfree(adev->acp.acp_cell);
404 kfree(adev->acp.acp_genpd);
405 return r;
396} 406}
397 407
398/** 408/**
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
index 7bcf86c61999..61e38e43ad1d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
@@ -270,7 +270,7 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
270 270
271 r = amdgpu_bo_create_list_entry_array(&args->in, &info); 271 r = amdgpu_bo_create_list_entry_array(&args->in, &info);
272 if (r) 272 if (r)
273 goto error_free; 273 return r;
274 274
275 switch (args->in.operation) { 275 switch (args->in.operation) {
276 case AMDGPU_BO_LIST_OP_CREATE: 276 case AMDGPU_BO_LIST_OP_CREATE:
@@ -283,8 +283,7 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
283 r = idr_alloc(&fpriv->bo_list_handles, list, 1, 0, GFP_KERNEL); 283 r = idr_alloc(&fpriv->bo_list_handles, list, 1, 0, GFP_KERNEL);
284 mutex_unlock(&fpriv->bo_list_lock); 284 mutex_unlock(&fpriv->bo_list_lock);
285 if (r < 0) { 285 if (r < 0) {
286 amdgpu_bo_list_put(list); 286 goto error_put_list;
287 return r;
288 } 287 }
289 288
290 handle = r; 289 handle = r;
@@ -306,9 +305,8 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
306 mutex_unlock(&fpriv->bo_list_lock); 305 mutex_unlock(&fpriv->bo_list_lock);
307 306
308 if (IS_ERR(old)) { 307 if (IS_ERR(old)) {
309 amdgpu_bo_list_put(list);
310 r = PTR_ERR(old); 308 r = PTR_ERR(old);
311 goto error_free; 309 goto error_put_list;
312 } 310 }
313 311
314 amdgpu_bo_list_put(old); 312 amdgpu_bo_list_put(old);
@@ -325,8 +323,10 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
325 323
326 return 0; 324 return 0;
327 325
326error_put_list:
327 amdgpu_bo_list_put(list);
328
328error_free: 329error_free:
329 if (info) 330 kvfree(info);
330 kvfree(info);
331 return r; 331 return r;
332} 332}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 264677ab248a..2a00a36106b2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -81,9 +81,10 @@
81 * - 3.32.0 - Add syncobj timeline support to AMDGPU_CS. 81 * - 3.32.0 - Add syncobj timeline support to AMDGPU_CS.
82 * - 3.33.0 - Fixes for GDS ENOMEM failures in AMDGPU_CS. 82 * - 3.33.0 - Fixes for GDS ENOMEM failures in AMDGPU_CS.
83 * - 3.34.0 - Non-DC can flip correctly between buffers with different pitches 83 * - 3.34.0 - Non-DC can flip correctly between buffers with different pitches
84 * - 3.35.0 - Add drm_amdgpu_info_device::tcc_disabled_mask
84 */ 85 */
85#define KMS_DRIVER_MAJOR 3 86#define KMS_DRIVER_MAJOR 3
86#define KMS_DRIVER_MINOR 34 87#define KMS_DRIVER_MINOR 35
87#define KMS_DRIVER_PATCHLEVEL 0 88#define KMS_DRIVER_PATCHLEVEL 0
88 89
89#define AMDGPU_MAX_TIMEOUT_PARAM_LENTH 256 90#define AMDGPU_MAX_TIMEOUT_PARAM_LENTH 256
@@ -1047,6 +1048,41 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
1047 return -ENODEV; 1048 return -ENODEV;
1048 } 1049 }
1049 1050
1051#ifdef CONFIG_DRM_AMDGPU_SI
1052 if (!amdgpu_si_support) {
1053 switch (flags & AMD_ASIC_MASK) {
1054 case CHIP_TAHITI:
1055 case CHIP_PITCAIRN:
1056 case CHIP_VERDE:
1057 case CHIP_OLAND:
1058 case CHIP_HAINAN:
1059 dev_info(&pdev->dev,
1060 "SI support provided by radeon.\n");
1061 dev_info(&pdev->dev,
1062 "Use radeon.si_support=0 amdgpu.si_support=1 to override.\n"
1063 );
1064 return -ENODEV;
1065 }
1066 }
1067#endif
1068#ifdef CONFIG_DRM_AMDGPU_CIK
1069 if (!amdgpu_cik_support) {
1070 switch (flags & AMD_ASIC_MASK) {
1071 case CHIP_KAVERI:
1072 case CHIP_BONAIRE:
1073 case CHIP_HAWAII:
1074 case CHIP_KABINI:
1075 case CHIP_MULLINS:
1076 dev_info(&pdev->dev,
1077 "CIK support provided by radeon.\n");
1078 dev_info(&pdev->dev,
1079 "Use radeon.cik_support=0 amdgpu.cik_support=1 to override.\n"
1080 );
1081 return -ENODEV;
1082 }
1083 }
1084#endif
1085
1050 /* Get rid of things like offb */ 1086 /* Get rid of things like offb */
1051 ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, 0, "amdgpudrmfb"); 1087 ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, 0, "amdgpudrmfb");
1052 if (ret) 1088 if (ret)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
index 554a59b3c4a6..6ee4021910e2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
@@ -165,6 +165,7 @@ struct amdgpu_gfx_config {
165 uint32_t num_sc_per_sh; 165 uint32_t num_sc_per_sh;
166 uint32_t num_packer_per_sc; 166 uint32_t num_packer_per_sc;
167 uint32_t pa_sc_tile_steering_override; 167 uint32_t pa_sc_tile_steering_override;
168 uint64_t tcc_disabled_mask;
168}; 169};
169 170
170struct amdgpu_cu_info { 171struct amdgpu_cu_info {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index f6147528be64..d55f5baa83d3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -144,41 +144,6 @@ int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags)
144 struct amdgpu_device *adev; 144 struct amdgpu_device *adev;
145 int r, acpi_status; 145 int r, acpi_status;
146 146
147#ifdef CONFIG_DRM_AMDGPU_SI
148 if (!amdgpu_si_support) {
149 switch (flags & AMD_ASIC_MASK) {
150 case CHIP_TAHITI:
151 case CHIP_PITCAIRN:
152 case CHIP_VERDE:
153 case CHIP_OLAND:
154 case CHIP_HAINAN:
155 dev_info(dev->dev,
156 "SI support provided by radeon.\n");
157 dev_info(dev->dev,
158 "Use radeon.si_support=0 amdgpu.si_support=1 to override.\n"
159 );
160 return -ENODEV;
161 }
162 }
163#endif
164#ifdef CONFIG_DRM_AMDGPU_CIK
165 if (!amdgpu_cik_support) {
166 switch (flags & AMD_ASIC_MASK) {
167 case CHIP_KAVERI:
168 case CHIP_BONAIRE:
169 case CHIP_HAWAII:
170 case CHIP_KABINI:
171 case CHIP_MULLINS:
172 dev_info(dev->dev,
173 "CIK support provided by radeon.\n");
174 dev_info(dev->dev,
175 "Use radeon.cik_support=0 amdgpu.cik_support=1 to override.\n"
176 );
177 return -ENODEV;
178 }
179 }
180#endif
181
182 adev = kzalloc(sizeof(struct amdgpu_device), GFP_KERNEL); 147 adev = kzalloc(sizeof(struct amdgpu_device), GFP_KERNEL);
183 if (adev == NULL) { 148 if (adev == NULL) {
184 return -ENOMEM; 149 return -ENOMEM;
@@ -787,6 +752,8 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
787 dev_info.pa_sc_tile_steering_override = 752 dev_info.pa_sc_tile_steering_override =
788 adev->gfx.config.pa_sc_tile_steering_override; 753 adev->gfx.config.pa_sc_tile_steering_override;
789 754
755 dev_info.tcc_disabled_mask = adev->gfx.config.tcc_disabled_mask;
756
790 return copy_to_user(out, &dev_info, 757 return copy_to_user(out, &dev_info,
791 min((size_t)size, sizeof(dev_info))) ? -EFAULT : 0; 758 min((size_t)size, sizeof(dev_info))) ? -EFAULT : 0;
792 } 759 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index e2fb141ff2e5..5251352f5922 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -603,14 +603,12 @@ void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev,
603 struct ttm_bo_global *glob = adev->mman.bdev.glob; 603 struct ttm_bo_global *glob = adev->mman.bdev.glob;
604 struct amdgpu_vm_bo_base *bo_base; 604 struct amdgpu_vm_bo_base *bo_base;
605 605
606#if 0
607 if (vm->bulk_moveable) { 606 if (vm->bulk_moveable) {
608 spin_lock(&glob->lru_lock); 607 spin_lock(&glob->lru_lock);
609 ttm_bo_bulk_move_lru_tail(&vm->lru_bulk_move); 608 ttm_bo_bulk_move_lru_tail(&vm->lru_bulk_move);
610 spin_unlock(&glob->lru_lock); 609 spin_unlock(&glob->lru_lock);
611 return; 610 return;
612 } 611 }
613#endif
614 612
615 memset(&vm->lru_bulk_move, 0, sizeof(vm->lru_bulk_move)); 613 memset(&vm->lru_bulk_move, 0, sizeof(vm->lru_bulk_move));
616 614
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
index 638c821611ab..957811b73672 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
@@ -1691,6 +1691,17 @@ static void gfx_v10_0_tcp_harvest(struct amdgpu_device *adev)
1691 } 1691 }
1692} 1692}
1693 1693
1694static void gfx_v10_0_get_tcc_info(struct amdgpu_device *adev)
1695{
1696 /* TCCs are global (not instanced). */
1697 uint32_t tcc_disable = RREG32_SOC15(GC, 0, mmCGTS_TCC_DISABLE) |
1698 RREG32_SOC15(GC, 0, mmCGTS_USER_TCC_DISABLE);
1699
1700 adev->gfx.config.tcc_disabled_mask =
1701 REG_GET_FIELD(tcc_disable, CGTS_TCC_DISABLE, TCC_DISABLE) |
1702 (REG_GET_FIELD(tcc_disable, CGTS_TCC_DISABLE, HI_TCC_DISABLE) << 16);
1703}
1704
1694static void gfx_v10_0_constants_init(struct amdgpu_device *adev) 1705static void gfx_v10_0_constants_init(struct amdgpu_device *adev)
1695{ 1706{
1696 u32 tmp; 1707 u32 tmp;
@@ -1702,6 +1713,7 @@ static void gfx_v10_0_constants_init(struct amdgpu_device *adev)
1702 1713
1703 gfx_v10_0_setup_rb(adev); 1714 gfx_v10_0_setup_rb(adev);
1704 gfx_v10_0_get_cu_info(adev, &adev->gfx.cu_info); 1715 gfx_v10_0_get_cu_info(adev, &adev->gfx.cu_info);
1716 gfx_v10_0_get_tcc_info(adev);
1705 adev->gfx.config.pa_sc_tile_steering_override = 1717 adev->gfx.config.pa_sc_tile_steering_override =
1706 gfx_v10_0_init_pa_sc_tile_steering_override(adev); 1718 gfx_v10_0_init_pa_sc_tile_steering_override(adev);
1707 1719
diff --git a/drivers/gpu/drm/amd/amdgpu/nv.c b/drivers/gpu/drm/amd/amdgpu/nv.c
index 85393a99a848..de9b995b65b1 100644
--- a/drivers/gpu/drm/amd/amdgpu/nv.c
+++ b/drivers/gpu/drm/amd/amdgpu/nv.c
@@ -317,10 +317,12 @@ static int nv_asic_reset(struct amdgpu_device *adev)
317 struct smu_context *smu = &adev->smu; 317 struct smu_context *smu = &adev->smu;
318 318
319 if (nv_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) { 319 if (nv_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) {
320 amdgpu_inc_vram_lost(adev); 320 if (!adev->in_suspend)
321 amdgpu_inc_vram_lost(adev);
321 ret = smu_baco_reset(smu); 322 ret = smu_baco_reset(smu);
322 } else { 323 } else {
323 amdgpu_inc_vram_lost(adev); 324 if (!adev->in_suspend)
325 amdgpu_inc_vram_lost(adev);
324 ret = nv_asic_mode1_reset(adev); 326 ret = nv_asic_mode1_reset(adev);
325 } 327 }
326 328
diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c
index fa2f70ce2e2b..f6e81680dd7e 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c
@@ -1129,7 +1129,7 @@ static void sdma_v5_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
1129 amdgpu_ring_write(ring, addr & 0xfffffffc); 1129 amdgpu_ring_write(ring, addr & 0xfffffffc);
1130 amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff); 1130 amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
1131 amdgpu_ring_write(ring, seq); /* reference */ 1131 amdgpu_ring_write(ring, seq); /* reference */
1132 amdgpu_ring_write(ring, 0xfffffff); /* mask */ 1132 amdgpu_ring_write(ring, 0xffffffff); /* mask */
1133 amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) | 1133 amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) |
1134 SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(4)); /* retry count, poll interval */ 1134 SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(4)); /* retry count, poll interval */
1135} 1135}
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c b/drivers/gpu/drm/amd/amdgpu/soc15.c
index f70658a536a9..f8ab80c8801b 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
@@ -558,12 +558,14 @@ static int soc15_asic_reset(struct amdgpu_device *adev)
558{ 558{
559 switch (soc15_asic_reset_method(adev)) { 559 switch (soc15_asic_reset_method(adev)) {
560 case AMD_RESET_METHOD_BACO: 560 case AMD_RESET_METHOD_BACO:
561 amdgpu_inc_vram_lost(adev); 561 if (!adev->in_suspend)
562 amdgpu_inc_vram_lost(adev);
562 return soc15_asic_baco_reset(adev); 563 return soc15_asic_baco_reset(adev);
563 case AMD_RESET_METHOD_MODE2: 564 case AMD_RESET_METHOD_MODE2:
564 return soc15_mode2_reset(adev); 565 return soc15_mode2_reset(adev);
565 default: 566 default:
566 amdgpu_inc_vram_lost(adev); 567 if (!adev->in_suspend)
568 amdgpu_inc_vram_lost(adev);
567 return soc15_asic_mode1_reset(adev); 569 return soc15_asic_mode1_reset(adev);
568 } 570 }
569} 571}
@@ -771,8 +773,6 @@ int soc15_set_ip_blocks(struct amdgpu_device *adev)
771#if defined(CONFIG_DRM_AMD_DC) 773#if defined(CONFIG_DRM_AMD_DC)
772 else if (amdgpu_device_has_dc_support(adev)) 774 else if (amdgpu_device_has_dc_support(adev))
773 amdgpu_device_ip_block_add(adev, &dm_ip_block); 775 amdgpu_device_ip_block_add(adev, &dm_ip_block);
774#else
775# warning "Enable CONFIG_DRM_AMD_DC for display support on SOC15."
776#endif 776#endif
777 amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block); 777 amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
778 break; 778 break;
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 8cab6da512a0..a52f0b13a2c8 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -2385,8 +2385,6 @@ static int amdgpu_dm_initialize_drm_device(struct amdgpu_device *adev)
2385 2385
2386 if (adev->asic_type != CHIP_CARRIZO && adev->asic_type != CHIP_STONEY) 2386 if (adev->asic_type != CHIP_CARRIZO && adev->asic_type != CHIP_STONEY)
2387 dm->dc->debug.disable_stutter = amdgpu_pp_feature_mask & PP_STUTTER_MODE ? false : true; 2387 dm->dc->debug.disable_stutter = amdgpu_pp_feature_mask & PP_STUTTER_MODE ? false : true;
2388 if (adev->asic_type == CHIP_RENOIR)
2389 dm->dc->debug.disable_stutter = true;
2390 2388
2391 return 0; 2389 return 0;
2392fail: 2390fail:
@@ -6019,7 +6017,9 @@ static void amdgpu_dm_enable_crtc_interrupts(struct drm_device *dev,
6019 struct drm_crtc *crtc; 6017 struct drm_crtc *crtc;
6020 struct drm_crtc_state *old_crtc_state, *new_crtc_state; 6018 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
6021 int i; 6019 int i;
6020#ifdef CONFIG_DEBUG_FS
6022 enum amdgpu_dm_pipe_crc_source source; 6021 enum amdgpu_dm_pipe_crc_source source;
6022#endif
6023 6023
6024 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, 6024 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
6025 new_crtc_state, i) { 6025 new_crtc_state, i) {
diff --git a/drivers/gpu/drm/amd/display/dc/dce100/dce100_resource.c b/drivers/gpu/drm/amd/display/dc/dce100/dce100_resource.c
index 1787b9bf800a..76d54885374a 100644
--- a/drivers/gpu/drm/amd/display/dc/dce100/dce100_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/dce100/dce100_resource.c
@@ -668,6 +668,7 @@ struct clock_source *dce100_clock_source_create(
668 return &clk_src->base; 668 return &clk_src->base;
669 } 669 }
670 670
671 kfree(clk_src);
671 BREAK_TO_DEBUGGER(); 672 BREAK_TO_DEBUGGER();
672 return NULL; 673 return NULL;
673} 674}
diff --git a/drivers/gpu/drm/amd/display/dc/dce110/dce110_resource.c b/drivers/gpu/drm/amd/display/dc/dce110/dce110_resource.c
index 318e9c2e2ca8..89620adc81d8 100644
--- a/drivers/gpu/drm/amd/display/dc/dce110/dce110_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/dce110/dce110_resource.c
@@ -714,6 +714,7 @@ struct clock_source *dce110_clock_source_create(
714 return &clk_src->base; 714 return &clk_src->base;
715 } 715 }
716 716
717 kfree(clk_src);
717 BREAK_TO_DEBUGGER(); 718 BREAK_TO_DEBUGGER();
718 return NULL; 719 return NULL;
719} 720}
diff --git a/drivers/gpu/drm/amd/display/dc/dce112/dce112_resource.c b/drivers/gpu/drm/amd/display/dc/dce112/dce112_resource.c
index 83e1878161c9..21a657e79306 100644
--- a/drivers/gpu/drm/amd/display/dc/dce112/dce112_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/dce112/dce112_resource.c
@@ -687,6 +687,7 @@ struct clock_source *dce112_clock_source_create(
687 return &clk_src->base; 687 return &clk_src->base;
688 } 688 }
689 689
690 kfree(clk_src);
690 BREAK_TO_DEBUGGER(); 691 BREAK_TO_DEBUGGER();
691 return NULL; 692 return NULL;
692} 693}
diff --git a/drivers/gpu/drm/amd/display/dc/dce120/dce120_resource.c b/drivers/gpu/drm/amd/display/dc/dce120/dce120_resource.c
index 8b85e5274bba..7c52f7f9196c 100644
--- a/drivers/gpu/drm/amd/display/dc/dce120/dce120_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/dce120/dce120_resource.c
@@ -500,6 +500,7 @@ static struct clock_source *dce120_clock_source_create(
500 return &clk_src->base; 500 return &clk_src->base;
501 } 501 }
502 502
503 kfree(clk_src);
503 BREAK_TO_DEBUGGER(); 504 BREAK_TO_DEBUGGER();
504 return NULL; 505 return NULL;
505} 506}
diff --git a/drivers/gpu/drm/amd/display/dc/dce80/dce80_resource.c b/drivers/gpu/drm/amd/display/dc/dce80/dce80_resource.c
index 4625df9f9fd2..643ccb0ade00 100644
--- a/drivers/gpu/drm/amd/display/dc/dce80/dce80_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/dce80/dce80_resource.c
@@ -701,6 +701,7 @@ struct clock_source *dce80_clock_source_create(
701 return &clk_src->base; 701 return &clk_src->base;
702 } 702 }
703 703
704 kfree(clk_src);
704 BREAK_TO_DEBUGGER(); 705 BREAK_TO_DEBUGGER();
705 return NULL; 706 return NULL;
706} 707}
diff --git a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c
index 59305e411a66..1599bb971111 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c
@@ -786,6 +786,7 @@ struct clock_source *dcn10_clock_source_create(
786 return &clk_src->base; 786 return &clk_src->base;
787 } 787 }
788 788
789 kfree(clk_src);
789 BREAK_TO_DEBUGGER(); 790 BREAK_TO_DEBUGGER();
790 return NULL; 791 return NULL;
791} 792}
diff --git a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c
index b4e3ce22ed52..5a2763daff4d 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_resource.c
@@ -1077,6 +1077,7 @@ struct clock_source *dcn20_clock_source_create(
1077 return &clk_src->base; 1077 return &clk_src->base;
1078 } 1078 }
1079 1079
1080 kfree(clk_src);
1080 BREAK_TO_DEBUGGER(); 1081 BREAK_TO_DEBUGGER();
1081 return NULL; 1082 return NULL;
1082} 1083}
diff --git a/drivers/gpu/drm/amd/display/dc/dcn21/Makefile b/drivers/gpu/drm/amd/display/dc/dcn21/Makefile
index 8cd9de8b1a7a..ef673bffc241 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn21/Makefile
+++ b/drivers/gpu/drm/amd/display/dc/dcn21/Makefile
@@ -3,7 +3,17 @@
3 3
4DCN21 = dcn21_hubp.o dcn21_hubbub.o dcn21_resource.o 4DCN21 = dcn21_hubp.o dcn21_hubbub.o dcn21_resource.o
5 5
6CFLAGS_$(AMDDALPATH)/dc/dcn21/dcn21_resource.o := -mhard-float -msse -mpreferred-stack-boundary=4 6ifneq ($(call cc-option, -mpreferred-stack-boundary=4),)
7 cc_stack_align := -mpreferred-stack-boundary=4
8else ifneq ($(call cc-option, -mstack-alignment=16),)
9 cc_stack_align := -mstack-alignment=16
10endif
11
12CFLAGS_$(AMDDALPATH)/dc/dcn21/dcn21_resource.o := -mhard-float -msse $(cc_stack_align)
13
14ifdef CONFIG_CC_IS_CLANG
15CFLAGS_$(AMDDALPATH)/dc/dcn21/dcn21_resource.o += -msse2
16endif
7 17
8AMD_DAL_DCN21 = $(addprefix $(AMDDALPATH)/dc/dcn21/,$(DCN21)) 18AMD_DAL_DCN21 = $(addprefix $(AMDDALPATH)/dc/dcn21/,$(DCN21))
9 19
diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn21/display_mode_vba_21.c b/drivers/gpu/drm/amd/display/dc/dml/dcn21/display_mode_vba_21.c
index 456cd0e3289c..3b6ed60dcd35 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn21/display_mode_vba_21.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn21/display_mode_vba_21.c
@@ -39,9 +39,6 @@
39 * ways. Unless there is something clearly wrong with it the code should 39 * ways. Unless there is something clearly wrong with it the code should
40 * remain as-is as it provides us with a guarantee from HW that it is correct. 40 * remain as-is as it provides us with a guarantee from HW that it is correct.
41 */ 41 */
42
43typedef unsigned int uint;
44
45typedef struct { 42typedef struct {
46 double DPPCLK; 43 double DPPCLK;
47 double DISPCLK; 44 double DISPCLK;
@@ -4774,7 +4771,7 @@ void dml21_ModeSupportAndSystemConfigurationFull(struct display_mode_lib *mode_l
4774 mode_lib->vba.MaximumReadBandwidthWithoutPrefetch = 0.0; 4771 mode_lib->vba.MaximumReadBandwidthWithoutPrefetch = 0.0;
4775 mode_lib->vba.MaximumReadBandwidthWithPrefetch = 0.0; 4772 mode_lib->vba.MaximumReadBandwidthWithPrefetch = 0.0;
4776 for (k = 0; k <= mode_lib->vba.NumberOfActivePlanes - 1; k++) { 4773 for (k = 0; k <= mode_lib->vba.NumberOfActivePlanes - 1; k++) {
4777 uint m; 4774 unsigned int m;
4778 4775
4779 locals->cursor_bw[k] = 0; 4776 locals->cursor_bw[k] = 0;
4780 locals->cursor_bw_pre[k] = 0; 4777 locals->cursor_bw_pre[k] = 0;
@@ -5285,7 +5282,7 @@ static void CalculateWatermarksAndDRAMSpeedChangeSupport(
5285 double SecondMinActiveDRAMClockChangeMarginOneDisplayInVBLank; 5282 double SecondMinActiveDRAMClockChangeMarginOneDisplayInVBLank;
5286 double FullDETBufferingTimeYStutterCriticalPlane = 0; 5283 double FullDETBufferingTimeYStutterCriticalPlane = 0;
5287 double TimeToFinishSwathTransferStutterCriticalPlane = 0; 5284 double TimeToFinishSwathTransferStutterCriticalPlane = 0;
5288 uint k, j; 5285 unsigned int k, j;
5289 5286
5290 mode_lib->vba.TotalActiveDPP = 0; 5287 mode_lib->vba.TotalActiveDPP = 0;
5291 mode_lib->vba.TotalDCCActiveDPP = 0; 5288 mode_lib->vba.TotalDCCActiveDPP = 0;
@@ -5507,7 +5504,7 @@ static void CalculateDCFCLKDeepSleep(
5507 double DPPCLK[], 5504 double DPPCLK[],
5508 double *DCFCLKDeepSleep) 5505 double *DCFCLKDeepSleep)
5509{ 5506{
5510 uint k; 5507 unsigned int k;
5511 double DisplayPipeLineDeliveryTimeLuma; 5508 double DisplayPipeLineDeliveryTimeLuma;
5512 double DisplayPipeLineDeliveryTimeChroma; 5509 double DisplayPipeLineDeliveryTimeChroma;
5513 //double DCFCLKDeepSleepPerPlane[DC__NUM_DPP__MAX]; 5510 //double DCFCLKDeepSleepPerPlane[DC__NUM_DPP__MAX];
@@ -5727,7 +5724,7 @@ static void CalculatePixelDeliveryTimes(
5727 double DisplayPipeRequestDeliveryTimeChromaPrefetch[]) 5724 double DisplayPipeRequestDeliveryTimeChromaPrefetch[])
5728{ 5725{
5729 double req_per_swath_ub; 5726 double req_per_swath_ub;
5730 uint k; 5727 unsigned int k;
5731 5728
5732 for (k = 0; k < NumberOfActivePlanes; ++k) { 5729 for (k = 0; k < NumberOfActivePlanes; ++k) {
5733 if (VRatio[k] <= 1) { 5730 if (VRatio[k] <= 1) {
@@ -5869,7 +5866,7 @@ static void CalculateMetaAndPTETimes(
5869 unsigned int dpte_groups_per_row_chroma_ub; 5866 unsigned int dpte_groups_per_row_chroma_ub;
5870 unsigned int num_group_per_lower_vm_stage; 5867 unsigned int num_group_per_lower_vm_stage;
5871 unsigned int num_req_per_lower_vm_stage; 5868 unsigned int num_req_per_lower_vm_stage;
5872 uint k; 5869 unsigned int k;
5873 5870
5874 for (k = 0; k < NumberOfActivePlanes; ++k) { 5871 for (k = 0; k < NumberOfActivePlanes; ++k) {
5875 if (GPUVMEnable == true) { 5872 if (GPUVMEnable == true) {
diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
index 33960fb38a5d..4acf139ea014 100644
--- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
@@ -843,6 +843,8 @@ static int smu_sw_init(void *handle)
843 smu->smu_baco.state = SMU_BACO_STATE_EXIT; 843 smu->smu_baco.state = SMU_BACO_STATE_EXIT;
844 smu->smu_baco.platform_support = false; 844 smu->smu_baco.platform_support = false;
845 845
846 mutex_init(&smu->sensor_lock);
847
846 smu->watermarks_bitmap = 0; 848 smu->watermarks_bitmap = 0;
847 smu->power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT; 849 smu->power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
848 smu->default_power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT; 850 smu->default_power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
diff --git a/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c b/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
index f1f072012fac..d493a3f8c07a 100644
--- a/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
@@ -1018,6 +1018,7 @@ static int arcturus_read_sensor(struct smu_context *smu,
1018 if (!data || !size) 1018 if (!data || !size)
1019 return -EINVAL; 1019 return -EINVAL;
1020 1020
1021 mutex_lock(&smu->sensor_lock);
1021 switch (sensor) { 1022 switch (sensor) {
1022 case AMDGPU_PP_SENSOR_MAX_FAN_RPM: 1023 case AMDGPU_PP_SENSOR_MAX_FAN_RPM:
1023 *(uint32_t *)data = pptable->FanMaximumRpm; 1024 *(uint32_t *)data = pptable->FanMaximumRpm;
@@ -1044,6 +1045,7 @@ static int arcturus_read_sensor(struct smu_context *smu,
1044 default: 1045 default:
1045 ret = smu_smc_read_sensor(smu, sensor, data, size); 1046 ret = smu_smc_read_sensor(smu, sensor, data, size);
1046 } 1047 }
1048 mutex_unlock(&smu->sensor_lock);
1047 1049
1048 return ret; 1050 return ret;
1049} 1051}
diff --git a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
index 6109815a0401..23171a4d9a31 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
@@ -344,6 +344,7 @@ struct smu_context
344 const struct smu_funcs *funcs; 344 const struct smu_funcs *funcs;
345 const struct pptable_funcs *ppt_funcs; 345 const struct pptable_funcs *ppt_funcs;
346 struct mutex mutex; 346 struct mutex mutex;
347 struct mutex sensor_lock;
347 uint64_t pool_size; 348 uint64_t pool_size;
348 349
349 struct smu_table_context smu_table; 350 struct smu_table_context smu_table;
diff --git a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
index 12c0e469bf35..0b461404af6b 100644
--- a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
@@ -547,7 +547,7 @@ static int navi10_get_metrics_table(struct smu_context *smu,
547 struct smu_table_context *smu_table= &smu->smu_table; 547 struct smu_table_context *smu_table= &smu->smu_table;
548 int ret = 0; 548 int ret = 0;
549 549
550 if (!smu_table->metrics_time || time_after(jiffies, smu_table->metrics_time + HZ / 1000)) { 550 if (!smu_table->metrics_time || time_after(jiffies, smu_table->metrics_time + msecs_to_jiffies(100))) {
551 ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, 0, 551 ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, 0,
552 (void *)smu_table->metrics_table, false); 552 (void *)smu_table->metrics_table, false);
553 if (ret) { 553 if (ret) {
@@ -1386,6 +1386,7 @@ static int navi10_read_sensor(struct smu_context *smu,
1386 if(!data || !size) 1386 if(!data || !size)
1387 return -EINVAL; 1387 return -EINVAL;
1388 1388
1389 mutex_lock(&smu->sensor_lock);
1389 switch (sensor) { 1390 switch (sensor) {
1390 case AMDGPU_PP_SENSOR_MAX_FAN_RPM: 1391 case AMDGPU_PP_SENSOR_MAX_FAN_RPM:
1391 *(uint32_t *)data = pptable->FanMaximumRpm; 1392 *(uint32_t *)data = pptable->FanMaximumRpm;
@@ -1409,6 +1410,7 @@ static int navi10_read_sensor(struct smu_context *smu,
1409 default: 1410 default:
1410 ret = smu_smc_read_sensor(smu, sensor, data, size); 1411 ret = smu_smc_read_sensor(smu, sensor, data, size);
1411 } 1412 }
1413 mutex_unlock(&smu->sensor_lock);
1412 1414
1413 return ret; 1415 return ret;
1414} 1416}
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c
index dc754447f0dd..23c12018dbc1 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c
@@ -655,7 +655,7 @@ static int polaris10_populate_smc_mvdd_table(struct pp_hwmgr *hwmgr,
655 count = SMU_MAX_SMIO_LEVELS; 655 count = SMU_MAX_SMIO_LEVELS;
656 for (level = 0; level < count; level++) { 656 for (level = 0; level < count; level++) {
657 table->SmioTable2.Pattern[level].Voltage = 657 table->SmioTable2.Pattern[level].Voltage =
658 PP_HOST_TO_SMC_US(data->mvdd_voltage_table.entries[count].value * VOLTAGE_SCALE); 658 PP_HOST_TO_SMC_US(data->mvdd_voltage_table.entries[level].value * VOLTAGE_SCALE);
659 /* Index into DpmTable.Smio. Drive bits from Smio entry to get this voltage level.*/ 659 /* Index into DpmTable.Smio. Drive bits from Smio entry to get this voltage level.*/
660 table->SmioTable2.Pattern[level].Smio = 660 table->SmioTable2.Pattern[level].Smio =
661 (uint8_t) level; 661 (uint8_t) level;
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/vegam_smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/vegam_smumgr.c
index 7c960b07746f..ae18fbcb26fb 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/vegam_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/vegam_smumgr.c
@@ -456,7 +456,7 @@ static int vegam_populate_smc_mvdd_table(struct pp_hwmgr *hwmgr,
456 count = SMU_MAX_SMIO_LEVELS; 456 count = SMU_MAX_SMIO_LEVELS;
457 for (level = 0; level < count; level++) { 457 for (level = 0; level < count; level++) {
458 table->SmioTable2.Pattern[level].Voltage = PP_HOST_TO_SMC_US( 458 table->SmioTable2.Pattern[level].Voltage = PP_HOST_TO_SMC_US(
459 data->mvdd_voltage_table.entries[count].value * VOLTAGE_SCALE); 459 data->mvdd_voltage_table.entries[level].value * VOLTAGE_SCALE);
460 /* Index into DpmTable.Smio. Drive bits from Smio entry to get this voltage level.*/ 460 /* Index into DpmTable.Smio. Drive bits from Smio entry to get this voltage level.*/
461 table->SmioTable2.Pattern[level].Smio = 461 table->SmioTable2.Pattern[level].Smio =
462 (uint8_t) level; 462 (uint8_t) level;
diff --git a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
index 64386ee3f878..bbd8ebd58434 100644
--- a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
@@ -3023,6 +3023,7 @@ static int vega20_read_sensor(struct smu_context *smu,
3023 if(!data || !size) 3023 if(!data || !size)
3024 return -EINVAL; 3024 return -EINVAL;
3025 3025
3026 mutex_lock(&smu->sensor_lock);
3026 switch (sensor) { 3027 switch (sensor) {
3027 case AMDGPU_PP_SENSOR_MAX_FAN_RPM: 3028 case AMDGPU_PP_SENSOR_MAX_FAN_RPM:
3028 *(uint32_t *)data = pptable->FanMaximumRpm; 3029 *(uint32_t *)data = pptable->FanMaximumRpm;
@@ -3048,6 +3049,7 @@ static int vega20_read_sensor(struct smu_context *smu,
3048 default: 3049 default:
3049 ret = smu_smc_read_sensor(smu, sensor, data, size); 3050 ret = smu_smc_read_sensor(smu, sensor, data, size);
3050 } 3051 }
3052 mutex_unlock(&smu->sensor_lock);
3051 3053
3052 return ret; 3054 return ret;
3053} 3055}
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_wb_connector.c b/drivers/gpu/drm/arm/display/komeda/komeda_wb_connector.c
index 2851cac94d86..b72840c06ab7 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_wb_connector.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_wb_connector.c
@@ -43,9 +43,8 @@ komeda_wb_encoder_atomic_check(struct drm_encoder *encoder,
43 struct komeda_data_flow_cfg dflow; 43 struct komeda_data_flow_cfg dflow;
44 int err; 44 int err;
45 45
46 if (!writeback_job || !writeback_job->fb) { 46 if (!writeback_job)
47 return 0; 47 return 0;
48 }
49 48
50 if (!crtc_st->active) { 49 if (!crtc_st->active) {
51 DRM_DEBUG_ATOMIC("Cannot write the composition result out on a inactive CRTC.\n"); 50 DRM_DEBUG_ATOMIC("Cannot write the composition result out on a inactive CRTC.\n");
@@ -166,8 +165,10 @@ static int komeda_wb_connector_add(struct komeda_kms_dev *kms,
166 &komeda_wb_encoder_helper_funcs, 165 &komeda_wb_encoder_helper_funcs,
167 formats, n_formats); 166 formats, n_formats);
168 komeda_put_fourcc_list(formats); 167 komeda_put_fourcc_list(formats);
169 if (err) 168 if (err) {
169 kfree(kwb_conn);
170 return err; 170 return err;
171 }
171 172
172 drm_connector_helper_add(&wb_conn->base, &komeda_wb_conn_helper_funcs); 173 drm_connector_helper_add(&wb_conn->base, &komeda_wb_conn_helper_funcs);
173 174
diff --git a/drivers/gpu/drm/arm/malidp_mw.c b/drivers/gpu/drm/arm/malidp_mw.c
index 22c0847986df..875a3a9eabfa 100644
--- a/drivers/gpu/drm/arm/malidp_mw.c
+++ b/drivers/gpu/drm/arm/malidp_mw.c
@@ -131,7 +131,7 @@ malidp_mw_encoder_atomic_check(struct drm_encoder *encoder,
131 struct drm_framebuffer *fb; 131 struct drm_framebuffer *fb;
132 int i, n_planes; 132 int i, n_planes;
133 133
134 if (!conn_state->writeback_job || !conn_state->writeback_job->fb) 134 if (!conn_state->writeback_job)
135 return 0; 135 return 0;
136 136
137 fb = conn_state->writeback_job->fb; 137 fb = conn_state->writeback_job->fb;
@@ -248,7 +248,7 @@ void malidp_mw_atomic_commit(struct drm_device *drm,
248 248
249 mw_state = to_mw_state(conn_state); 249 mw_state = to_mw_state(conn_state);
250 250
251 if (conn_state->writeback_job && conn_state->writeback_job->fb) { 251 if (conn_state->writeback_job) {
252 struct drm_framebuffer *fb = conn_state->writeback_job->fb; 252 struct drm_framebuffer *fb = conn_state->writeback_job->fb;
253 253
254 DRM_DEV_DEBUG_DRIVER(drm->dev, 254 DRM_DEV_DEBUG_DRIVER(drm->dev,
diff --git a/drivers/gpu/drm/bridge/tc358767.c b/drivers/gpu/drm/bridge/tc358767.c
index cebc8e620820..8a8d605021f0 100644
--- a/drivers/gpu/drm/bridge/tc358767.c
+++ b/drivers/gpu/drm/bridge/tc358767.c
@@ -728,6 +728,8 @@ static int tc_set_video_mode(struct tc_data *tc,
728 int lower_margin = mode->vsync_start - mode->vdisplay; 728 int lower_margin = mode->vsync_start - mode->vdisplay;
729 int vsync_len = mode->vsync_end - mode->vsync_start; 729 int vsync_len = mode->vsync_end - mode->vsync_start;
730 u32 dp0_syncval; 730 u32 dp0_syncval;
731 u32 bits_per_pixel = 24;
732 u32 in_bw, out_bw;
731 733
732 /* 734 /*
733 * Recommended maximum number of symbols transferred in a transfer unit: 735 * Recommended maximum number of symbols transferred in a transfer unit:
@@ -735,7 +737,10 @@ static int tc_set_video_mode(struct tc_data *tc,
735 * (output active video bandwidth in bytes)) 737 * (output active video bandwidth in bytes))
736 * Must be less than tu_size. 738 * Must be less than tu_size.
737 */ 739 */
738 max_tu_symbol = TU_SIZE_RECOMMENDED - 1; 740
741 in_bw = mode->clock * bits_per_pixel / 8;
742 out_bw = tc->link.base.num_lanes * tc->link.base.rate;
743 max_tu_symbol = DIV_ROUND_UP(in_bw * TU_SIZE_RECOMMENDED, out_bw);
739 744
740 dev_dbg(tc->dev, "set mode %dx%d\n", 745 dev_dbg(tc->dev, "set mode %dx%d\n",
741 mode->hdisplay, mode->vdisplay); 746 mode->hdisplay, mode->vdisplay);
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 419381abbdd1..14aeaf736321 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -430,10 +430,15 @@ static int drm_atomic_connector_check(struct drm_connector *connector,
430 return -EINVAL; 430 return -EINVAL;
431 } 431 }
432 432
433 if (writeback_job->out_fence && !writeback_job->fb) { 433 if (!writeback_job->fb) {
434 DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] requesting out-fence without framebuffer\n", 434 if (writeback_job->out_fence) {
435 connector->base.id, connector->name); 435 DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] requesting out-fence without framebuffer\n",
436 return -EINVAL; 436 connector->base.id, connector->name);
437 return -EINVAL;
438 }
439
440 drm_writeback_cleanup_job(writeback_job);
441 state->writeback_job = NULL;
437 } 442 }
438 443
439 return 0; 444 return 0;
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 82a4ceed3fcf..6b0177112e18 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -159,6 +159,9 @@ static const struct edid_quirk {
159 /* Medion MD 30217 PG */ 159 /* Medion MD 30217 PG */
160 { "MED", 0x7b8, EDID_QUIRK_PREFER_LARGE_75 }, 160 { "MED", 0x7b8, EDID_QUIRK_PREFER_LARGE_75 },
161 161
162 /* Lenovo G50 */
163 { "SDC", 18514, EDID_QUIRK_FORCE_6BPC },
164
162 /* Panel in Samsung NP700G7A-S01PL notebook reports 6bpc */ 165 /* Panel in Samsung NP700G7A-S01PL notebook reports 6bpc */
163 { "SEC", 0xd033, EDID_QUIRK_FORCE_8BPC }, 166 { "SEC", 0xd033, EDID_QUIRK_FORCE_8BPC },
164 167
diff --git a/drivers/gpu/drm/drm_writeback.c b/drivers/gpu/drm/drm_writeback.c
index ff138b6ec48b..43d9e3bb3a94 100644
--- a/drivers/gpu/drm/drm_writeback.c
+++ b/drivers/gpu/drm/drm_writeback.c
@@ -324,6 +324,9 @@ void drm_writeback_cleanup_job(struct drm_writeback_job *job)
324 if (job->fb) 324 if (job->fb)
325 drm_framebuffer_put(job->fb); 325 drm_framebuffer_put(job->fb);
326 326
327 if (job->out_fence)
328 dma_fence_put(job->out_fence);
329
327 kfree(job); 330 kfree(job);
328} 331}
329EXPORT_SYMBOL(drm_writeback_cleanup_job); 332EXPORT_SYMBOL(drm_writeback_cleanup_job);
@@ -366,25 +369,29 @@ drm_writeback_signal_completion(struct drm_writeback_connector *wb_connector,
366{ 369{
367 unsigned long flags; 370 unsigned long flags;
368 struct drm_writeback_job *job; 371 struct drm_writeback_job *job;
372 struct dma_fence *out_fence;
369 373
370 spin_lock_irqsave(&wb_connector->job_lock, flags); 374 spin_lock_irqsave(&wb_connector->job_lock, flags);
371 job = list_first_entry_or_null(&wb_connector->job_queue, 375 job = list_first_entry_or_null(&wb_connector->job_queue,
372 struct drm_writeback_job, 376 struct drm_writeback_job,
373 list_entry); 377 list_entry);
374 if (job) { 378 if (job)
375 list_del(&job->list_entry); 379 list_del(&job->list_entry);
376 if (job->out_fence) { 380
377 if (status)
378 dma_fence_set_error(job->out_fence, status);
379 dma_fence_signal(job->out_fence);
380 dma_fence_put(job->out_fence);
381 }
382 }
383 spin_unlock_irqrestore(&wb_connector->job_lock, flags); 381 spin_unlock_irqrestore(&wb_connector->job_lock, flags);
384 382
385 if (WARN_ON(!job)) 383 if (WARN_ON(!job))
386 return; 384 return;
387 385
386 out_fence = job->out_fence;
387 if (out_fence) {
388 if (status)
389 dma_fence_set_error(out_fence, status);
390 dma_fence_signal(out_fence);
391 dma_fence_put(out_fence);
392 job->out_fence = NULL;
393 }
394
388 INIT_WORK(&job->cleanup_work, cleanup_work); 395 INIT_WORK(&job->cleanup_work, cleanup_work);
389 queue_work(system_long_wq, &job->cleanup_work); 396 queue_work(system_long_wq, &job->cleanup_work);
390} 397}
diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c
index efb39f350b19..3250c1b8dcca 100644
--- a/drivers/gpu/drm/i915/display/intel_bios.c
+++ b/drivers/gpu/drm/i915/display/intel_bios.c
@@ -1270,7 +1270,7 @@ static void sanitize_ddc_pin(struct drm_i915_private *dev_priv,
1270 DRM_DEBUG_KMS("port %c trying to use the same DDC pin (0x%x) as port %c, " 1270 DRM_DEBUG_KMS("port %c trying to use the same DDC pin (0x%x) as port %c, "
1271 "disabling port %c DVI/HDMI support\n", 1271 "disabling port %c DVI/HDMI support\n",
1272 port_name(port), info->alternate_ddc_pin, 1272 port_name(port), info->alternate_ddc_pin,
1273 port_name(p), port_name(port)); 1273 port_name(p), port_name(p));
1274 1274
1275 /* 1275 /*
1276 * If we have multiple ports supposedly sharing the 1276 * If we have multiple ports supposedly sharing the
@@ -1278,9 +1278,14 @@ static void sanitize_ddc_pin(struct drm_i915_private *dev_priv,
1278 * port. Otherwise they share the same ddc bin and 1278 * port. Otherwise they share the same ddc bin and
1279 * system couldn't communicate with them separately. 1279 * system couldn't communicate with them separately.
1280 * 1280 *
1281 * Give child device order the priority, first come first 1281 * Give inverse child device order the priority,
1282 * served. 1282 * last one wins. Yes, there are real machines
1283 * (eg. Asrock B250M-HDV) where VBT has both
1284 * port A and port E with the same AUX ch and
1285 * we must pick port E :(
1283 */ 1286 */
1287 info = &dev_priv->vbt.ddi_port_info[p];
1288
1284 info->supports_dvi = false; 1289 info->supports_dvi = false;
1285 info->supports_hdmi = false; 1290 info->supports_hdmi = false;
1286 info->alternate_ddc_pin = 0; 1291 info->alternate_ddc_pin = 0;
@@ -1316,7 +1321,7 @@ static void sanitize_aux_ch(struct drm_i915_private *dev_priv,
1316 DRM_DEBUG_KMS("port %c trying to use the same AUX CH (0x%x) as port %c, " 1321 DRM_DEBUG_KMS("port %c trying to use the same AUX CH (0x%x) as port %c, "
1317 "disabling port %c DP support\n", 1322 "disabling port %c DP support\n",
1318 port_name(port), info->alternate_aux_channel, 1323 port_name(port), info->alternate_aux_channel,
1319 port_name(p), port_name(port)); 1324 port_name(p), port_name(p));
1320 1325
1321 /* 1326 /*
1322 * If we have multiple ports supposedlt sharing the 1327 * If we have multiple ports supposedlt sharing the
@@ -1324,9 +1329,14 @@ static void sanitize_aux_ch(struct drm_i915_private *dev_priv,
1324 * port. Otherwise they share the same aux channel 1329 * port. Otherwise they share the same aux channel
1325 * and system couldn't communicate with them separately. 1330 * and system couldn't communicate with them separately.
1326 * 1331 *
1327 * Give child device order the priority, first come first 1332 * Give inverse child device order the priority,
1328 * served. 1333 * last one wins. Yes, there are real machines
1334 * (eg. Asrock B250M-HDV) where VBT has both
1335 * port A and port E with the same AUX ch and
1336 * we must pick port E :(
1329 */ 1337 */
1338 info = &dev_priv->vbt.ddi_port_info[p];
1339
1330 info->supports_dp = false; 1340 info->supports_dp = false;
1331 info->alternate_aux_channel = 0; 1341 info->alternate_aux_channel = 0;
1332 } 1342 }
diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
index b51d1ceb8739..aa54bb22796d 100644
--- a/drivers/gpu/drm/i915/display/intel_display.c
+++ b/drivers/gpu/drm/i915/display/intel_display.c
@@ -3280,7 +3280,20 @@ static int skl_max_plane_width(const struct drm_framebuffer *fb,
3280 switch (fb->modifier) { 3280 switch (fb->modifier) {
3281 case DRM_FORMAT_MOD_LINEAR: 3281 case DRM_FORMAT_MOD_LINEAR:
3282 case I915_FORMAT_MOD_X_TILED: 3282 case I915_FORMAT_MOD_X_TILED:
3283 return 4096; 3283 /*
3284 * Validated limit is 4k, but has 5k should
3285 * work apart from the following features:
3286 * - Ytile (already limited to 4k)
3287 * - FP16 (already limited to 4k)
3288 * - render compression (already limited to 4k)
3289 * - KVMR sprite and cursor (don't care)
3290 * - horizontal panning (TODO verify this)
3291 * - pipe and plane scaling (TODO verify this)
3292 */
3293 if (cpp == 8)
3294 return 4096;
3295 else
3296 return 5120;
3284 case I915_FORMAT_MOD_Y_TILED_CCS: 3297 case I915_FORMAT_MOD_Y_TILED_CCS:
3285 case I915_FORMAT_MOD_Yf_TILED_CCS: 3298 case I915_FORMAT_MOD_Yf_TILED_CCS:
3286 /* FIXME AUX plane? */ 3299 /* FIXME AUX plane? */
@@ -7261,7 +7274,7 @@ retry:
7261 pipe_config->fdi_lanes = lane; 7274 pipe_config->fdi_lanes = lane;
7262 7275
7263 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, 7276 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
7264 link_bw, &pipe_config->fdi_m_n, false); 7277 link_bw, &pipe_config->fdi_m_n, false, false);
7265 7278
7266 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config); 7279 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
7267 if (ret == -EDEADLK) 7280 if (ret == -EDEADLK)
@@ -7508,11 +7521,15 @@ void
7508intel_link_compute_m_n(u16 bits_per_pixel, int nlanes, 7521intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
7509 int pixel_clock, int link_clock, 7522 int pixel_clock, int link_clock,
7510 struct intel_link_m_n *m_n, 7523 struct intel_link_m_n *m_n,
7511 bool constant_n) 7524 bool constant_n, bool fec_enable)
7512{ 7525{
7513 m_n->tu = 64; 7526 u32 data_clock = bits_per_pixel * pixel_clock;
7514 7527
7515 compute_m_n(bits_per_pixel * pixel_clock, 7528 if (fec_enable)
7529 data_clock = intel_dp_mode_to_fec_clock(data_clock);
7530
7531 m_n->tu = 64;
7532 compute_m_n(data_clock,
7516 link_clock * nlanes * 8, 7533 link_clock * nlanes * 8,
7517 &m_n->gmch_m, &m_n->gmch_n, 7534 &m_n->gmch_m, &m_n->gmch_n,
7518 constant_n); 7535 constant_n);
diff --git a/drivers/gpu/drm/i915/display/intel_display.h b/drivers/gpu/drm/i915/display/intel_display.h
index e57e6969051d..01fa87ad3270 100644
--- a/drivers/gpu/drm/i915/display/intel_display.h
+++ b/drivers/gpu/drm/i915/display/intel_display.h
@@ -414,7 +414,7 @@ enum phy_fia {
414void intel_link_compute_m_n(u16 bpp, int nlanes, 414void intel_link_compute_m_n(u16 bpp, int nlanes,
415 int pixel_clock, int link_clock, 415 int pixel_clock, int link_clock,
416 struct intel_link_m_n *m_n, 416 struct intel_link_m_n *m_n,
417 bool constant_n); 417 bool constant_n, bool fec_enable);
418bool is_ccs_modifier(u64 modifier); 418bool is_ccs_modifier(u64 modifier);
419void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv); 419void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv);
420u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv, 420u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
diff --git a/drivers/gpu/drm/i915/display/intel_dp.c b/drivers/gpu/drm/i915/display/intel_dp.c
index 921ad0a2f7ba..57e9f0ba331b 100644
--- a/drivers/gpu/drm/i915/display/intel_dp.c
+++ b/drivers/gpu/drm/i915/display/intel_dp.c
@@ -78,8 +78,8 @@
78#define DP_DSC_MAX_ENC_THROUGHPUT_0 340000 78#define DP_DSC_MAX_ENC_THROUGHPUT_0 340000
79#define DP_DSC_MAX_ENC_THROUGHPUT_1 400000 79#define DP_DSC_MAX_ENC_THROUGHPUT_1 400000
80 80
81/* DP DSC FEC Overhead factor = (100 - 2.4)/100 */ 81/* DP DSC FEC Overhead factor = 1/(0.972261) */
82#define DP_DSC_FEC_OVERHEAD_FACTOR 976 82#define DP_DSC_FEC_OVERHEAD_FACTOR 972261
83 83
84/* Compliance test status bits */ 84/* Compliance test status bits */
85#define INTEL_DP_RESOLUTION_SHIFT_MASK 0 85#define INTEL_DP_RESOLUTION_SHIFT_MASK 0
@@ -494,6 +494,97 @@ int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
494 return 0; 494 return 0;
495} 495}
496 496
497u32 intel_dp_mode_to_fec_clock(u32 mode_clock)
498{
499 return div_u64(mul_u32_u32(mode_clock, 1000000U),
500 DP_DSC_FEC_OVERHEAD_FACTOR);
501}
502
503static u16 intel_dp_dsc_get_output_bpp(u32 link_clock, u32 lane_count,
504 u32 mode_clock, u32 mode_hdisplay)
505{
506 u32 bits_per_pixel, max_bpp_small_joiner_ram;
507 int i;
508
509 /*
510 * Available Link Bandwidth(Kbits/sec) = (NumberOfLanes)*
511 * (LinkSymbolClock)* 8 * (TimeSlotsPerMTP)
512 * for SST -> TimeSlotsPerMTP is 1,
513 * for MST -> TimeSlotsPerMTP has to be calculated
514 */
515 bits_per_pixel = (link_clock * lane_count * 8) /
516 intel_dp_mode_to_fec_clock(mode_clock);
517 DRM_DEBUG_KMS("Max link bpp: %u\n", bits_per_pixel);
518
519 /* Small Joiner Check: output bpp <= joiner RAM (bits) / Horiz. width */
520 max_bpp_small_joiner_ram = DP_DSC_MAX_SMALL_JOINER_RAM_BUFFER / mode_hdisplay;
521 DRM_DEBUG_KMS("Max small joiner bpp: %u\n", max_bpp_small_joiner_ram);
522
523 /*
524 * Greatest allowed DSC BPP = MIN (output BPP from available Link BW
525 * check, output bpp from small joiner RAM check)
526 */
527 bits_per_pixel = min(bits_per_pixel, max_bpp_small_joiner_ram);
528
529 /* Error out if the max bpp is less than smallest allowed valid bpp */
530 if (bits_per_pixel < valid_dsc_bpp[0]) {
531 DRM_DEBUG_KMS("Unsupported BPP %u, min %u\n",
532 bits_per_pixel, valid_dsc_bpp[0]);
533 return 0;
534 }
535
536 /* Find the nearest match in the array of known BPPs from VESA */
537 for (i = 0; i < ARRAY_SIZE(valid_dsc_bpp) - 1; i++) {
538 if (bits_per_pixel < valid_dsc_bpp[i + 1])
539 break;
540 }
541 bits_per_pixel = valid_dsc_bpp[i];
542
543 /*
544 * Compressed BPP in U6.4 format so multiply by 16, for Gen 11,
545 * fractional part is 0
546 */
547 return bits_per_pixel << 4;
548}
549
550static u8 intel_dp_dsc_get_slice_count(struct intel_dp *intel_dp,
551 int mode_clock, int mode_hdisplay)
552{
553 u8 min_slice_count, i;
554 int max_slice_width;
555
556 if (mode_clock <= DP_DSC_PEAK_PIXEL_RATE)
557 min_slice_count = DIV_ROUND_UP(mode_clock,
558 DP_DSC_MAX_ENC_THROUGHPUT_0);
559 else
560 min_slice_count = DIV_ROUND_UP(mode_clock,
561 DP_DSC_MAX_ENC_THROUGHPUT_1);
562
563 max_slice_width = drm_dp_dsc_sink_max_slice_width(intel_dp->dsc_dpcd);
564 if (max_slice_width < DP_DSC_MIN_SLICE_WIDTH_VALUE) {
565 DRM_DEBUG_KMS("Unsupported slice width %d by DP DSC Sink device\n",
566 max_slice_width);
567 return 0;
568 }
569 /* Also take into account max slice width */
570 min_slice_count = min_t(u8, min_slice_count,
571 DIV_ROUND_UP(mode_hdisplay,
572 max_slice_width));
573
574 /* Find the closest match to the valid slice count values */
575 for (i = 0; i < ARRAY_SIZE(valid_dsc_slicecount); i++) {
576 if (valid_dsc_slicecount[i] >
577 drm_dp_dsc_sink_max_slice_count(intel_dp->dsc_dpcd,
578 false))
579 break;
580 if (min_slice_count <= valid_dsc_slicecount[i])
581 return valid_dsc_slicecount[i];
582 }
583
584 DRM_DEBUG_KMS("Unsupported Slice Count %d\n", min_slice_count);
585 return 0;
586}
587
497static enum drm_mode_status 588static enum drm_mode_status
498intel_dp_mode_valid(struct drm_connector *connector, 589intel_dp_mode_valid(struct drm_connector *connector,
499 struct drm_display_mode *mode) 590 struct drm_display_mode *mode)
@@ -2226,7 +2317,7 @@ intel_dp_compute_config(struct intel_encoder *encoder,
2226 adjusted_mode->crtc_clock, 2317 adjusted_mode->crtc_clock,
2227 pipe_config->port_clock, 2318 pipe_config->port_clock,
2228 &pipe_config->dp_m_n, 2319 &pipe_config->dp_m_n,
2229 constant_n); 2320 constant_n, pipe_config->fec_enable);
2230 2321
2231 if (intel_connector->panel.downclock_mode != NULL && 2322 if (intel_connector->panel.downclock_mode != NULL &&
2232 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) { 2323 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
@@ -2236,7 +2327,7 @@ intel_dp_compute_config(struct intel_encoder *encoder,
2236 intel_connector->panel.downclock_mode->clock, 2327 intel_connector->panel.downclock_mode->clock,
2237 pipe_config->port_clock, 2328 pipe_config->port_clock,
2238 &pipe_config->dp_m2_n2, 2329 &pipe_config->dp_m2_n2,
2239 constant_n); 2330 constant_n, pipe_config->fec_enable);
2240 } 2331 }
2241 2332
2242 if (!HAS_DDI(dev_priv)) 2333 if (!HAS_DDI(dev_priv))
@@ -4323,91 +4414,6 @@ intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4323 DP_DPRX_ESI_LEN; 4414 DP_DPRX_ESI_LEN;
4324} 4415}
4325 4416
4326u16 intel_dp_dsc_get_output_bpp(int link_clock, u8 lane_count,
4327 int mode_clock, int mode_hdisplay)
4328{
4329 u16 bits_per_pixel, max_bpp_small_joiner_ram;
4330 int i;
4331
4332 /*
4333 * Available Link Bandwidth(Kbits/sec) = (NumberOfLanes)*
4334 * (LinkSymbolClock)* 8 * ((100-FECOverhead)/100)*(TimeSlotsPerMTP)
4335 * FECOverhead = 2.4%, for SST -> TimeSlotsPerMTP is 1,
4336 * for MST -> TimeSlotsPerMTP has to be calculated
4337 */
4338 bits_per_pixel = (link_clock * lane_count * 8 *
4339 DP_DSC_FEC_OVERHEAD_FACTOR) /
4340 mode_clock;
4341
4342 /* Small Joiner Check: output bpp <= joiner RAM (bits) / Horiz. width */
4343 max_bpp_small_joiner_ram = DP_DSC_MAX_SMALL_JOINER_RAM_BUFFER /
4344 mode_hdisplay;
4345
4346 /*
4347 * Greatest allowed DSC BPP = MIN (output BPP from avaialble Link BW
4348 * check, output bpp from small joiner RAM check)
4349 */
4350 bits_per_pixel = min(bits_per_pixel, max_bpp_small_joiner_ram);
4351
4352 /* Error out if the max bpp is less than smallest allowed valid bpp */
4353 if (bits_per_pixel < valid_dsc_bpp[0]) {
4354 DRM_DEBUG_KMS("Unsupported BPP %d\n", bits_per_pixel);
4355 return 0;
4356 }
4357
4358 /* Find the nearest match in the array of known BPPs from VESA */
4359 for (i = 0; i < ARRAY_SIZE(valid_dsc_bpp) - 1; i++) {
4360 if (bits_per_pixel < valid_dsc_bpp[i + 1])
4361 break;
4362 }
4363 bits_per_pixel = valid_dsc_bpp[i];
4364
4365 /*
4366 * Compressed BPP in U6.4 format so multiply by 16, for Gen 11,
4367 * fractional part is 0
4368 */
4369 return bits_per_pixel << 4;
4370}
4371
4372u8 intel_dp_dsc_get_slice_count(struct intel_dp *intel_dp,
4373 int mode_clock,
4374 int mode_hdisplay)
4375{
4376 u8 min_slice_count, i;
4377 int max_slice_width;
4378
4379 if (mode_clock <= DP_DSC_PEAK_PIXEL_RATE)
4380 min_slice_count = DIV_ROUND_UP(mode_clock,
4381 DP_DSC_MAX_ENC_THROUGHPUT_0);
4382 else
4383 min_slice_count = DIV_ROUND_UP(mode_clock,
4384 DP_DSC_MAX_ENC_THROUGHPUT_1);
4385
4386 max_slice_width = drm_dp_dsc_sink_max_slice_width(intel_dp->dsc_dpcd);
4387 if (max_slice_width < DP_DSC_MIN_SLICE_WIDTH_VALUE) {
4388 DRM_DEBUG_KMS("Unsupported slice width %d by DP DSC Sink device\n",
4389 max_slice_width);
4390 return 0;
4391 }
4392 /* Also take into account max slice width */
4393 min_slice_count = min_t(u8, min_slice_count,
4394 DIV_ROUND_UP(mode_hdisplay,
4395 max_slice_width));
4396
4397 /* Find the closest match to the valid slice count values */
4398 for (i = 0; i < ARRAY_SIZE(valid_dsc_slicecount); i++) {
4399 if (valid_dsc_slicecount[i] >
4400 drm_dp_dsc_sink_max_slice_count(intel_dp->dsc_dpcd,
4401 false))
4402 break;
4403 if (min_slice_count <= valid_dsc_slicecount[i])
4404 return valid_dsc_slicecount[i];
4405 }
4406
4407 DRM_DEBUG_KMS("Unsupported Slice Count %d\n", min_slice_count);
4408 return 0;
4409}
4410
4411static void 4417static void
4412intel_pixel_encoding_setup_vsc(struct intel_dp *intel_dp, 4418intel_pixel_encoding_setup_vsc(struct intel_dp *intel_dp,
4413 const struct intel_crtc_state *crtc_state) 4419 const struct intel_crtc_state *crtc_state)
diff --git a/drivers/gpu/drm/i915/display/intel_dp.h b/drivers/gpu/drm/i915/display/intel_dp.h
index 657bbb1f5ed0..00981fb9414b 100644
--- a/drivers/gpu/drm/i915/display/intel_dp.h
+++ b/drivers/gpu/drm/i915/display/intel_dp.h
@@ -102,10 +102,6 @@ bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp);
102bool intel_dp_source_supports_hbr3(struct intel_dp *intel_dp); 102bool intel_dp_source_supports_hbr3(struct intel_dp *intel_dp);
103bool 103bool
104intel_dp_get_link_status(struct intel_dp *intel_dp, u8 *link_status); 104intel_dp_get_link_status(struct intel_dp *intel_dp, u8 *link_status);
105u16 intel_dp_dsc_get_output_bpp(int link_clock, u8 lane_count,
106 int mode_clock, int mode_hdisplay);
107u8 intel_dp_dsc_get_slice_count(struct intel_dp *intel_dp, int mode_clock,
108 int mode_hdisplay);
109 105
110bool intel_dp_read_dpcd(struct intel_dp *intel_dp); 106bool intel_dp_read_dpcd(struct intel_dp *intel_dp);
111bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp); 107bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp);
@@ -118,4 +114,6 @@ static inline unsigned int intel_dp_unused_lane_mask(int lane_count)
118 return ~((1 << lane_count) - 1) & 0xf; 114 return ~((1 << lane_count) - 1) & 0xf;
119} 115}
120 116
117u32 intel_dp_mode_to_fec_clock(u32 mode_clock);
118
121#endif /* __INTEL_DP_H__ */ 119#endif /* __INTEL_DP_H__ */
diff --git a/drivers/gpu/drm/i915/display/intel_dp_mst.c b/drivers/gpu/drm/i915/display/intel_dp_mst.c
index 6df240a01b8c..600873c796d0 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_mst.c
+++ b/drivers/gpu/drm/i915/display/intel_dp_mst.c
@@ -81,7 +81,7 @@ static int intel_dp_mst_compute_link_config(struct intel_encoder *encoder,
81 adjusted_mode->crtc_clock, 81 adjusted_mode->crtc_clock,
82 crtc_state->port_clock, 82 crtc_state->port_clock,
83 &crtc_state->dp_m_n, 83 &crtc_state->dp_m_n,
84 constant_n); 84 constant_n, crtc_state->fec_enable);
85 crtc_state->dp_m_n.tu = slots; 85 crtc_state->dp_m_n.tu = slots;
86 86
87 return 0; 87 return 0;
@@ -615,7 +615,7 @@ intel_dp_create_fake_mst_encoder(struct intel_digital_port *intel_dig_port, enum
615 intel_encoder->type = INTEL_OUTPUT_DP_MST; 615 intel_encoder->type = INTEL_OUTPUT_DP_MST;
616 intel_encoder->power_domain = intel_dig_port->base.power_domain; 616 intel_encoder->power_domain = intel_dig_port->base.power_domain;
617 intel_encoder->port = intel_dig_port->base.port; 617 intel_encoder->port = intel_dig_port->base.port;
618 intel_encoder->crtc_mask = BIT(pipe); 618 intel_encoder->crtc_mask = 0x7;
619 intel_encoder->cloneable = 0; 619 intel_encoder->cloneable = 0;
620 620
621 intel_encoder->compute_config = intel_dp_mst_compute_config; 621 intel_encoder->compute_config = intel_dp_mst_compute_config;
diff --git a/drivers/gpu/drm/i915/display/intel_sprite.c b/drivers/gpu/drm/i915/display/intel_sprite.c
index dea63be1964f..cae25e493128 100644
--- a/drivers/gpu/drm/i915/display/intel_sprite.c
+++ b/drivers/gpu/drm/i915/display/intel_sprite.c
@@ -1528,6 +1528,7 @@ g4x_sprite_check_scaling(struct intel_crtc_state *crtc_state,
1528 int src_x, src_w, src_h, crtc_w, crtc_h; 1528 int src_x, src_w, src_h, crtc_w, crtc_h;
1529 const struct drm_display_mode *adjusted_mode = 1529 const struct drm_display_mode *adjusted_mode =
1530 &crtc_state->base.adjusted_mode; 1530 &crtc_state->base.adjusted_mode;
1531 unsigned int stride = plane_state->color_plane[0].stride;
1531 unsigned int cpp = fb->format->cpp[0]; 1532 unsigned int cpp = fb->format->cpp[0];
1532 unsigned int width_bytes; 1533 unsigned int width_bytes;
1533 int min_width, min_height; 1534 int min_width, min_height;
@@ -1569,9 +1570,9 @@ g4x_sprite_check_scaling(struct intel_crtc_state *crtc_state,
1569 return -EINVAL; 1570 return -EINVAL;
1570 } 1571 }
1571 1572
1572 if (width_bytes > 4096 || fb->pitches[0] > 4096) { 1573 if (stride > 4096) {
1573 DRM_DEBUG_KMS("Stride (%u) exceeds hardware max with scaling (%u)\n", 1574 DRM_DEBUG_KMS("Stride (%u) exceeds hardware max with scaling (%u)\n",
1574 fb->pitches[0], 4096); 1575 stride, 4096);
1575 return -EINVAL; 1576 return -EINVAL;
1576 } 1577 }
1577 1578
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_mman.c b/drivers/gpu/drm/i915/gem/i915_gem_mman.c
index 261c9bd83f51..05289edbafe3 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_mman.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_mman.c
@@ -245,11 +245,9 @@ vm_fault_t i915_gem_fault(struct vm_fault *vmf)
245 245
246 wakeref = intel_runtime_pm_get(rpm); 246 wakeref = intel_runtime_pm_get(rpm);
247 247
248 srcu = intel_gt_reset_trylock(ggtt->vm.gt); 248 ret = intel_gt_reset_trylock(ggtt->vm.gt, &srcu);
249 if (srcu < 0) { 249 if (ret)
250 ret = srcu;
251 goto err_rpm; 250 goto err_rpm;
252 }
253 251
254 ret = i915_mutex_lock_interruptible(dev); 252 ret = i915_mutex_lock_interruptible(dev);
255 if (ret) 253 if (ret)
@@ -318,7 +316,11 @@ vm_fault_t i915_gem_fault(struct vm_fault *vmf)
318 intel_wakeref_auto(&i915->ggtt.userfault_wakeref, 316 intel_wakeref_auto(&i915->ggtt.userfault_wakeref,
319 msecs_to_jiffies_timeout(CONFIG_DRM_I915_USERFAULT_AUTOSUSPEND)); 317 msecs_to_jiffies_timeout(CONFIG_DRM_I915_USERFAULT_AUTOSUSPEND));
320 318
321 i915_vma_set_ggtt_write(vma); 319 if (write) {
320 GEM_BUG_ON(!i915_gem_object_has_pinned_pages(obj));
321 i915_vma_set_ggtt_write(vma);
322 obj->mm.dirty = true;
323 }
322 324
323err_fence: 325err_fence:
324 i915_vma_unpin_fence(vma); 326 i915_vma_unpin_fence(vma);
@@ -362,6 +364,7 @@ err:
362 return VM_FAULT_OOM; 364 return VM_FAULT_OOM;
363 case -ENOSPC: 365 case -ENOSPC:
364 case -EFAULT: 366 case -EFAULT:
367 case -ENODEV: /* bad object, how did you get here! */
365 return VM_FAULT_SIGBUS; 368 return VM_FAULT_SIGBUS;
366 default: 369 default:
367 WARN_ONCE(ret, "unhandled error in %s: %i\n", __func__, ret); 370 WARN_ONCE(ret, "unhandled error in %s: %i\n", __func__, ret);
@@ -473,10 +476,16 @@ i915_gem_mmap_gtt(struct drm_file *file,
473 if (!obj) 476 if (!obj)
474 return -ENOENT; 477 return -ENOENT;
475 478
479 if (i915_gem_object_never_bind_ggtt(obj)) {
480 ret = -ENODEV;
481 goto out;
482 }
483
476 ret = create_mmap_offset(obj); 484 ret = create_mmap_offset(obj);
477 if (ret == 0) 485 if (ret == 0)
478 *offset = drm_vma_node_offset_addr(&obj->base.vma_node); 486 *offset = drm_vma_node_offset_addr(&obj->base.vma_node);
479 487
488out:
480 i915_gem_object_put(obj); 489 i915_gem_object_put(obj);
481 return ret; 490 return ret;
482} 491}
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h b/drivers/gpu/drm/i915/gem/i915_gem_object.h
index 5efb9936e05b..ddf3605bea8e 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
@@ -153,6 +153,12 @@ i915_gem_object_is_proxy(const struct drm_i915_gem_object *obj)
153} 153}
154 154
155static inline bool 155static inline bool
156i915_gem_object_never_bind_ggtt(const struct drm_i915_gem_object *obj)
157{
158 return obj->ops->flags & I915_GEM_OBJECT_NO_GGTT;
159}
160
161static inline bool
156i915_gem_object_needs_async_cancel(const struct drm_i915_gem_object *obj) 162i915_gem_object_needs_async_cancel(const struct drm_i915_gem_object *obj)
157{ 163{
158 return obj->ops->flags & I915_GEM_OBJECT_ASYNC_CANCEL; 164 return obj->ops->flags & I915_GEM_OBJECT_ASYNC_CANCEL;
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object_types.h b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h
index ede0eb4218a8..646859fea224 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object_types.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h
@@ -32,7 +32,8 @@ struct drm_i915_gem_object_ops {
32#define I915_GEM_OBJECT_HAS_STRUCT_PAGE BIT(0) 32#define I915_GEM_OBJECT_HAS_STRUCT_PAGE BIT(0)
33#define I915_GEM_OBJECT_IS_SHRINKABLE BIT(1) 33#define I915_GEM_OBJECT_IS_SHRINKABLE BIT(1)
34#define I915_GEM_OBJECT_IS_PROXY BIT(2) 34#define I915_GEM_OBJECT_IS_PROXY BIT(2)
35#define I915_GEM_OBJECT_ASYNC_CANCEL BIT(3) 35#define I915_GEM_OBJECT_NO_GGTT BIT(3)
36#define I915_GEM_OBJECT_ASYNC_CANCEL BIT(4)
36 37
37 /* Interface between the GEM object and its backing storage. 38 /* Interface between the GEM object and its backing storage.
38 * get_pages() is called once prior to the use of the associated set 39 * get_pages() is called once prior to the use of the associated set
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_pm.c b/drivers/gpu/drm/i915/gem/i915_gem_pm.c
index 92e53c25424c..ad2a63dbcac2 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_pm.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_pm.c
@@ -241,9 +241,6 @@ void i915_gem_resume(struct drm_i915_private *i915)
241 mutex_lock(&i915->drm.struct_mutex); 241 mutex_lock(&i915->drm.struct_mutex);
242 intel_uncore_forcewake_get(&i915->uncore, FORCEWAKE_ALL); 242 intel_uncore_forcewake_get(&i915->uncore, FORCEWAKE_ALL);
243 243
244 i915_gem_restore_gtt_mappings(i915);
245 i915_gem_restore_fences(i915);
246
247 if (i915_gem_init_hw(i915)) 244 if (i915_gem_init_hw(i915))
248 goto err_wedged; 245 goto err_wedged;
249 246
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_userptr.c b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c
index 11b231c187c5..6b3b50f0f6d9 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_userptr.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c
@@ -702,6 +702,7 @@ i915_gem_userptr_dmabuf_export(struct drm_i915_gem_object *obj)
702static const struct drm_i915_gem_object_ops i915_gem_userptr_ops = { 702static const struct drm_i915_gem_object_ops i915_gem_userptr_ops = {
703 .flags = I915_GEM_OBJECT_HAS_STRUCT_PAGE | 703 .flags = I915_GEM_OBJECT_HAS_STRUCT_PAGE |
704 I915_GEM_OBJECT_IS_SHRINKABLE | 704 I915_GEM_OBJECT_IS_SHRINKABLE |
705 I915_GEM_OBJECT_NO_GGTT |
705 I915_GEM_OBJECT_ASYNC_CANCEL, 706 I915_GEM_OBJECT_ASYNC_CANCEL,
706 .get_pages = i915_gem_userptr_get_pages, 707 .get_pages = i915_gem_userptr_get_pages,
707 .put_pages = i915_gem_userptr_put_pages, 708 .put_pages = i915_gem_userptr_put_pages,
diff --git a/drivers/gpu/drm/i915/gt/intel_engine.h b/drivers/gpu/drm/i915/gt/intel_engine.h
index d3c6993f4f46..22aab8593abf 100644
--- a/drivers/gpu/drm/i915/gt/intel_engine.h
+++ b/drivers/gpu/drm/i915/gt/intel_engine.h
@@ -136,6 +136,20 @@ execlists_active(const struct intel_engine_execlists *execlists)
136 return READ_ONCE(*execlists->active); 136 return READ_ONCE(*execlists->active);
137} 137}
138 138
139static inline void
140execlists_active_lock_bh(struct intel_engine_execlists *execlists)
141{
142 local_bh_disable(); /* prevent local softirq and lock recursion */
143 tasklet_lock(&execlists->tasklet);
144}
145
146static inline void
147execlists_active_unlock_bh(struct intel_engine_execlists *execlists)
148{
149 tasklet_unlock(&execlists->tasklet);
150 local_bh_enable(); /* restore softirq, and kick ksoftirqd! */
151}
152
139struct i915_request * 153struct i915_request *
140execlists_unwind_incomplete_requests(struct intel_engine_execlists *execlists); 154execlists_unwind_incomplete_requests(struct intel_engine_execlists *execlists);
141 155
diff --git a/drivers/gpu/drm/i915/gt/intel_engine_cs.c b/drivers/gpu/drm/i915/gt/intel_engine_cs.c
index 82630db0394b..4ce8626b140e 100644
--- a/drivers/gpu/drm/i915/gt/intel_engine_cs.c
+++ b/drivers/gpu/drm/i915/gt/intel_engine_cs.c
@@ -1197,9 +1197,7 @@ static void intel_engine_print_registers(struct intel_engine_cs *engine,
1197 struct drm_printer *m) 1197 struct drm_printer *m)
1198{ 1198{
1199 struct drm_i915_private *dev_priv = engine->i915; 1199 struct drm_i915_private *dev_priv = engine->i915;
1200 const struct intel_engine_execlists * const execlists = 1200 struct intel_engine_execlists * const execlists = &engine->execlists;
1201 &engine->execlists;
1202 unsigned long flags;
1203 u64 addr; 1201 u64 addr;
1204 1202
1205 if (engine->id == RENDER_CLASS && IS_GEN_RANGE(dev_priv, 4, 7)) 1203 if (engine->id == RENDER_CLASS && IS_GEN_RANGE(dev_priv, 4, 7))
@@ -1281,7 +1279,7 @@ static void intel_engine_print_registers(struct intel_engine_cs *engine,
1281 idx, hws[idx * 2], hws[idx * 2 + 1]); 1279 idx, hws[idx * 2], hws[idx * 2 + 1]);
1282 } 1280 }
1283 1281
1284 spin_lock_irqsave(&engine->active.lock, flags); 1282 execlists_active_lock_bh(execlists);
1285 for (port = execlists->active; (rq = *port); port++) { 1283 for (port = execlists->active; (rq = *port); port++) {
1286 char hdr[80]; 1284 char hdr[80];
1287 int len; 1285 int len;
@@ -1309,7 +1307,7 @@ static void intel_engine_print_registers(struct intel_engine_cs *engine,
1309 hwsp_seqno(rq)); 1307 hwsp_seqno(rq));
1310 print_request(m, rq, hdr); 1308 print_request(m, rq, hdr);
1311 } 1309 }
1312 spin_unlock_irqrestore(&engine->active.lock, flags); 1310 execlists_active_unlock_bh(execlists);
1313 } else if (INTEL_GEN(dev_priv) > 6) { 1311 } else if (INTEL_GEN(dev_priv) > 6) {
1314 drm_printf(m, "\tPP_DIR_BASE: 0x%08x\n", 1312 drm_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
1315 ENGINE_READ(engine, RING_PP_DIR_BASE)); 1313 ENGINE_READ(engine, RING_PP_DIR_BASE));
@@ -1440,8 +1438,8 @@ int intel_enable_engine_stats(struct intel_engine_cs *engine)
1440 if (!intel_engine_supports_stats(engine)) 1438 if (!intel_engine_supports_stats(engine))
1441 return -ENODEV; 1439 return -ENODEV;
1442 1440
1443 spin_lock_irqsave(&engine->active.lock, flags); 1441 execlists_active_lock_bh(execlists);
1444 write_seqlock(&engine->stats.lock); 1442 write_seqlock_irqsave(&engine->stats.lock, flags);
1445 1443
1446 if (unlikely(engine->stats.enabled == ~0)) { 1444 if (unlikely(engine->stats.enabled == ~0)) {
1447 err = -EBUSY; 1445 err = -EBUSY;
@@ -1469,8 +1467,8 @@ int intel_enable_engine_stats(struct intel_engine_cs *engine)
1469 } 1467 }
1470 1468
1471unlock: 1469unlock:
1472 write_sequnlock(&engine->stats.lock); 1470 write_sequnlock_irqrestore(&engine->stats.lock, flags);
1473 spin_unlock_irqrestore(&engine->active.lock, flags); 1471 execlists_active_unlock_bh(execlists);
1474 1472
1475 return err; 1473 return err;
1476} 1474}
diff --git a/drivers/gpu/drm/i915/gt/intel_lrc.c b/drivers/gpu/drm/i915/gt/intel_lrc.c
index d42584439f51..06a506c29463 100644
--- a/drivers/gpu/drm/i915/gt/intel_lrc.c
+++ b/drivers/gpu/drm/i915/gt/intel_lrc.c
@@ -234,6 +234,13 @@ static void execlists_init_reg_state(u32 *reg_state,
234 struct intel_engine_cs *engine, 234 struct intel_engine_cs *engine,
235 struct intel_ring *ring); 235 struct intel_ring *ring);
236 236
237static void mark_eio(struct i915_request *rq)
238{
239 if (!i915_request_signaled(rq))
240 dma_fence_set_error(&rq->fence, -EIO);
241 i915_request_mark_complete(rq);
242}
243
237static inline u32 intel_hws_preempt_address(struct intel_engine_cs *engine) 244static inline u32 intel_hws_preempt_address(struct intel_engine_cs *engine)
238{ 245{
239 return (i915_ggtt_offset(engine->status_page.vma) + 246 return (i915_ggtt_offset(engine->status_page.vma) +
@@ -631,7 +638,6 @@ execlists_schedule_out(struct i915_request *rq)
631 struct intel_engine_cs *cur, *old; 638 struct intel_engine_cs *cur, *old;
632 639
633 trace_i915_request_out(rq); 640 trace_i915_request_out(rq);
634 GEM_BUG_ON(intel_context_inflight(ce) != rq->engine);
635 641
636 old = READ_ONCE(ce->inflight); 642 old = READ_ONCE(ce->inflight);
637 do 643 do
@@ -797,6 +803,17 @@ static bool can_merge_rq(const struct i915_request *prev,
797 GEM_BUG_ON(prev == next); 803 GEM_BUG_ON(prev == next);
798 GEM_BUG_ON(!assert_priority_queue(prev, next)); 804 GEM_BUG_ON(!assert_priority_queue(prev, next));
799 805
806 /*
807 * We do not submit known completed requests. Therefore if the next
808 * request is already completed, we can pretend to merge it in
809 * with the previous context (and we will skip updating the ELSP
810 * and tracking). Thus hopefully keeping the ELSP full with active
811 * contexts, despite the best efforts of preempt-to-busy to confuse
812 * us.
813 */
814 if (i915_request_completed(next))
815 return true;
816
800 if (!can_merge_ctx(prev->hw_context, next->hw_context)) 817 if (!can_merge_ctx(prev->hw_context, next->hw_context))
801 return false; 818 return false;
802 819
@@ -893,7 +910,7 @@ static void virtual_xfer_breadcrumbs(struct virtual_engine *ve,
893static struct i915_request * 910static struct i915_request *
894last_active(const struct intel_engine_execlists *execlists) 911last_active(const struct intel_engine_execlists *execlists)
895{ 912{
896 struct i915_request * const *last = execlists->active; 913 struct i915_request * const *last = READ_ONCE(execlists->active);
897 914
898 while (*last && i915_request_completed(*last)) 915 while (*last && i915_request_completed(*last))
899 last++; 916 last++;
@@ -1172,21 +1189,6 @@ static void execlists_dequeue(struct intel_engine_cs *engine)
1172 continue; 1189 continue;
1173 } 1190 }
1174 1191
1175 if (i915_request_completed(rq)) {
1176 ve->request = NULL;
1177 ve->base.execlists.queue_priority_hint = INT_MIN;
1178 rb_erase_cached(rb, &execlists->virtual);
1179 RB_CLEAR_NODE(rb);
1180
1181 rq->engine = engine;
1182 __i915_request_submit(rq);
1183
1184 spin_unlock(&ve->base.active.lock);
1185
1186 rb = rb_first_cached(&execlists->virtual);
1187 continue;
1188 }
1189
1190 if (last && !can_merge_rq(last, rq)) { 1192 if (last && !can_merge_rq(last, rq)) {
1191 spin_unlock(&ve->base.active.lock); 1193 spin_unlock(&ve->base.active.lock);
1192 return; /* leave this for another */ 1194 return; /* leave this for another */
@@ -1237,11 +1239,24 @@ static void execlists_dequeue(struct intel_engine_cs *engine)
1237 GEM_BUG_ON(ve->siblings[0] != engine); 1239 GEM_BUG_ON(ve->siblings[0] != engine);
1238 } 1240 }
1239 1241
1240 __i915_request_submit(rq); 1242 if (__i915_request_submit(rq)) {
1241 if (!i915_request_completed(rq)) {
1242 submit = true; 1243 submit = true;
1243 last = rq; 1244 last = rq;
1244 } 1245 }
1246 i915_request_put(rq);
1247
1248 /*
1249 * Hmm, we have a bunch of virtual engine requests,
1250 * but the first one was already completed (thanks
1251 * preempt-to-busy!). Keep looking at the veng queue
1252 * until we have no more relevant requests (i.e.
1253 * the normal submit queue has higher priority).
1254 */
1255 if (!submit) {
1256 spin_unlock(&ve->base.active.lock);
1257 rb = rb_first_cached(&execlists->virtual);
1258 continue;
1259 }
1245 } 1260 }
1246 1261
1247 spin_unlock(&ve->base.active.lock); 1262 spin_unlock(&ve->base.active.lock);
@@ -1254,8 +1269,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine)
1254 int i; 1269 int i;
1255 1270
1256 priolist_for_each_request_consume(rq, rn, p, i) { 1271 priolist_for_each_request_consume(rq, rn, p, i) {
1257 if (i915_request_completed(rq)) 1272 bool merge = true;
1258 goto skip;
1259 1273
1260 /* 1274 /*
1261 * Can we combine this request with the current port? 1275 * Can we combine this request with the current port?
@@ -1296,14 +1310,23 @@ static void execlists_dequeue(struct intel_engine_cs *engine)
1296 ctx_single_port_submission(rq->hw_context)) 1310 ctx_single_port_submission(rq->hw_context))
1297 goto done; 1311 goto done;
1298 1312
1299 *port = execlists_schedule_in(last, port - execlists->pending); 1313 merge = false;
1300 port++;
1301 } 1314 }
1302 1315
1303 last = rq; 1316 if (__i915_request_submit(rq)) {
1304 submit = true; 1317 if (!merge) {
1305skip: 1318 *port = execlists_schedule_in(last, port - execlists->pending);
1306 __i915_request_submit(rq); 1319 port++;
1320 last = NULL;
1321 }
1322
1323 GEM_BUG_ON(last &&
1324 !can_merge_ctx(last->hw_context,
1325 rq->hw_context));
1326
1327 submit = true;
1328 last = rq;
1329 }
1307 } 1330 }
1308 1331
1309 rb_erase_cached(&p->node, &execlists->queue); 1332 rb_erase_cached(&p->node, &execlists->queue);
@@ -1593,8 +1616,11 @@ static void process_csb(struct intel_engine_cs *engine)
1593static void __execlists_submission_tasklet(struct intel_engine_cs *const engine) 1616static void __execlists_submission_tasklet(struct intel_engine_cs *const engine)
1594{ 1617{
1595 lockdep_assert_held(&engine->active.lock); 1618 lockdep_assert_held(&engine->active.lock);
1596 if (!engine->execlists.pending[0]) 1619 if (!engine->execlists.pending[0]) {
1620 rcu_read_lock(); /* protect peeking at execlists->active */
1597 execlists_dequeue(engine); 1621 execlists_dequeue(engine);
1622 rcu_read_unlock();
1623 }
1598} 1624}
1599 1625
1600/* 1626/*
@@ -2399,10 +2425,14 @@ static void reset_csb_pointers(struct intel_engine_cs *engine)
2399 2425
2400static struct i915_request *active_request(struct i915_request *rq) 2426static struct i915_request *active_request(struct i915_request *rq)
2401{ 2427{
2402 const struct list_head * const list = &rq->timeline->requests;
2403 const struct intel_context * const ce = rq->hw_context; 2428 const struct intel_context * const ce = rq->hw_context;
2404 struct i915_request *active = NULL; 2429 struct i915_request *active = NULL;
2430 struct list_head *list;
2405 2431
2432 if (!i915_request_is_active(rq)) /* unwound, but incomplete! */
2433 return rq;
2434
2435 list = &rq->timeline->requests;
2406 list_for_each_entry_from_reverse(rq, list, link) { 2436 list_for_each_entry_from_reverse(rq, list, link) {
2407 if (i915_request_completed(rq)) 2437 if (i915_request_completed(rq))
2408 break; 2438 break;
@@ -2552,12 +2582,8 @@ static void execlists_cancel_requests(struct intel_engine_cs *engine)
2552 __execlists_reset(engine, true); 2582 __execlists_reset(engine, true);
2553 2583
2554 /* Mark all executing requests as skipped. */ 2584 /* Mark all executing requests as skipped. */
2555 list_for_each_entry(rq, &engine->active.requests, sched.link) { 2585 list_for_each_entry(rq, &engine->active.requests, sched.link)
2556 if (!i915_request_signaled(rq)) 2586 mark_eio(rq);
2557 dma_fence_set_error(&rq->fence, -EIO);
2558
2559 i915_request_mark_complete(rq);
2560 }
2561 2587
2562 /* Flush the queued requests to the timeline list (for retiring). */ 2588 /* Flush the queued requests to the timeline list (for retiring). */
2563 while ((rb = rb_first_cached(&execlists->queue))) { 2589 while ((rb = rb_first_cached(&execlists->queue))) {
@@ -2565,10 +2591,8 @@ static void execlists_cancel_requests(struct intel_engine_cs *engine)
2565 int i; 2591 int i;
2566 2592
2567 priolist_for_each_request_consume(rq, rn, p, i) { 2593 priolist_for_each_request_consume(rq, rn, p, i) {
2568 list_del_init(&rq->sched.link); 2594 mark_eio(rq);
2569 __i915_request_submit(rq); 2595 __i915_request_submit(rq);
2570 dma_fence_set_error(&rq->fence, -EIO);
2571 i915_request_mark_complete(rq);
2572 } 2596 }
2573 2597
2574 rb_erase_cached(&p->node, &execlists->queue); 2598 rb_erase_cached(&p->node, &execlists->queue);
@@ -2584,13 +2608,15 @@ static void execlists_cancel_requests(struct intel_engine_cs *engine)
2584 RB_CLEAR_NODE(rb); 2608 RB_CLEAR_NODE(rb);
2585 2609
2586 spin_lock(&ve->base.active.lock); 2610 spin_lock(&ve->base.active.lock);
2587 if (ve->request) { 2611 rq = fetch_and_zero(&ve->request);
2588 ve->request->engine = engine; 2612 if (rq) {
2589 __i915_request_submit(ve->request); 2613 mark_eio(rq);
2590 dma_fence_set_error(&ve->request->fence, -EIO); 2614
2591 i915_request_mark_complete(ve->request); 2615 rq->engine = engine;
2616 __i915_request_submit(rq);
2617 i915_request_put(rq);
2618
2592 ve->base.execlists.queue_priority_hint = INT_MIN; 2619 ve->base.execlists.queue_priority_hint = INT_MIN;
2593 ve->request = NULL;
2594 } 2620 }
2595 spin_unlock(&ve->base.active.lock); 2621 spin_unlock(&ve->base.active.lock);
2596 } 2622 }
@@ -3594,6 +3620,8 @@ submit_engine:
3594static void virtual_submit_request(struct i915_request *rq) 3620static void virtual_submit_request(struct i915_request *rq)
3595{ 3621{
3596 struct virtual_engine *ve = to_virtual_engine(rq->engine); 3622 struct virtual_engine *ve = to_virtual_engine(rq->engine);
3623 struct i915_request *old;
3624 unsigned long flags;
3597 3625
3598 GEM_TRACE("%s: rq=%llx:%lld\n", 3626 GEM_TRACE("%s: rq=%llx:%lld\n",
3599 ve->base.name, 3627 ve->base.name,
@@ -3602,15 +3630,31 @@ static void virtual_submit_request(struct i915_request *rq)
3602 3630
3603 GEM_BUG_ON(ve->base.submit_request != virtual_submit_request); 3631 GEM_BUG_ON(ve->base.submit_request != virtual_submit_request);
3604 3632
3605 GEM_BUG_ON(ve->request); 3633 spin_lock_irqsave(&ve->base.active.lock, flags);
3606 GEM_BUG_ON(!list_empty(virtual_queue(ve))); 3634
3635 old = ve->request;
3636 if (old) { /* background completion event from preempt-to-busy */
3637 GEM_BUG_ON(!i915_request_completed(old));
3638 __i915_request_submit(old);
3639 i915_request_put(old);
3640 }
3641
3642 if (i915_request_completed(rq)) {
3643 __i915_request_submit(rq);
3644
3645 ve->base.execlists.queue_priority_hint = INT_MIN;
3646 ve->request = NULL;
3647 } else {
3648 ve->base.execlists.queue_priority_hint = rq_prio(rq);
3649 ve->request = i915_request_get(rq);
3607 3650
3608 ve->base.execlists.queue_priority_hint = rq_prio(rq); 3651 GEM_BUG_ON(!list_empty(virtual_queue(ve)));
3609 WRITE_ONCE(ve->request, rq); 3652 list_move_tail(&rq->sched.link, virtual_queue(ve));
3610 3653
3611 list_move_tail(&rq->sched.link, virtual_queue(ve)); 3654 tasklet_schedule(&ve->base.execlists.tasklet);
3655 }
3612 3656
3613 tasklet_schedule(&ve->base.execlists.tasklet); 3657 spin_unlock_irqrestore(&ve->base.active.lock, flags);
3614} 3658}
3615 3659
3616static struct ve_bond * 3660static struct ve_bond *
@@ -3631,18 +3675,22 @@ static void
3631virtual_bond_execute(struct i915_request *rq, struct dma_fence *signal) 3675virtual_bond_execute(struct i915_request *rq, struct dma_fence *signal)
3632{ 3676{
3633 struct virtual_engine *ve = to_virtual_engine(rq->engine); 3677 struct virtual_engine *ve = to_virtual_engine(rq->engine);
3678 intel_engine_mask_t allowed, exec;
3634 struct ve_bond *bond; 3679 struct ve_bond *bond;
3635 3680
3681 allowed = ~to_request(signal)->engine->mask;
3682
3636 bond = virtual_find_bond(ve, to_request(signal)->engine); 3683 bond = virtual_find_bond(ve, to_request(signal)->engine);
3637 if (bond) { 3684 if (bond)
3638 intel_engine_mask_t old, new, cmp; 3685 allowed &= bond->sibling_mask;
3639 3686
3640 cmp = READ_ONCE(rq->execution_mask); 3687 /* Restrict the bonded request to run on only the available engines */
3641 do { 3688 exec = READ_ONCE(rq->execution_mask);
3642 old = cmp; 3689 while (!try_cmpxchg(&rq->execution_mask, &exec, exec & allowed))
3643 new = cmp & bond->sibling_mask; 3690 ;
3644 } while ((cmp = cmpxchg(&rq->execution_mask, old, new)) != old); 3691
3645 } 3692 /* Prevent the master from being re-run on the bonded engines */
3693 to_request(signal)->execution_mask &= ~allowed;
3646} 3694}
3647 3695
3648struct intel_context * 3696struct intel_context *
diff --git a/drivers/gpu/drm/i915/gt/intel_reset.c b/drivers/gpu/drm/i915/gt/intel_reset.c
index b9d84d52e986..8cea42379dd7 100644
--- a/drivers/gpu/drm/i915/gt/intel_reset.c
+++ b/drivers/gpu/drm/i915/gt/intel_reset.c
@@ -42,11 +42,10 @@ static void engine_skip_context(struct i915_request *rq)
42 struct intel_engine_cs *engine = rq->engine; 42 struct intel_engine_cs *engine = rq->engine;
43 struct i915_gem_context *hung_ctx = rq->gem_context; 43 struct i915_gem_context *hung_ctx = rq->gem_context;
44 44
45 lockdep_assert_held(&engine->active.lock);
46
47 if (!i915_request_is_active(rq)) 45 if (!i915_request_is_active(rq))
48 return; 46 return;
49 47
48 lockdep_assert_held(&engine->active.lock);
50 list_for_each_entry_continue(rq, &engine->active.requests, sched.link) 49 list_for_each_entry_continue(rq, &engine->active.requests, sched.link)
51 if (rq->gem_context == hung_ctx) 50 if (rq->gem_context == hung_ctx)
52 i915_request_skip(rq, -EIO); 51 i915_request_skip(rq, -EIO);
@@ -123,7 +122,6 @@ void __i915_request_reset(struct i915_request *rq, bool guilty)
123 rq->fence.seqno, 122 rq->fence.seqno,
124 yesno(guilty)); 123 yesno(guilty));
125 124
126 lockdep_assert_held(&rq->engine->active.lock);
127 GEM_BUG_ON(i915_request_completed(rq)); 125 GEM_BUG_ON(i915_request_completed(rq));
128 126
129 if (guilty) { 127 if (guilty) {
@@ -1214,10 +1212,8 @@ out:
1214 intel_runtime_pm_put(&gt->i915->runtime_pm, wakeref); 1212 intel_runtime_pm_put(&gt->i915->runtime_pm, wakeref);
1215} 1213}
1216 1214
1217int intel_gt_reset_trylock(struct intel_gt *gt) 1215int intel_gt_reset_trylock(struct intel_gt *gt, int *srcu)
1218{ 1216{
1219 int srcu;
1220
1221 might_lock(&gt->reset.backoff_srcu); 1217 might_lock(&gt->reset.backoff_srcu);
1222 might_sleep(); 1218 might_sleep();
1223 1219
@@ -1232,10 +1228,10 @@ int intel_gt_reset_trylock(struct intel_gt *gt)
1232 1228
1233 rcu_read_lock(); 1229 rcu_read_lock();
1234 } 1230 }
1235 srcu = srcu_read_lock(&gt->reset.backoff_srcu); 1231 *srcu = srcu_read_lock(&gt->reset.backoff_srcu);
1236 rcu_read_unlock(); 1232 rcu_read_unlock();
1237 1233
1238 return srcu; 1234 return 0;
1239} 1235}
1240 1236
1241void intel_gt_reset_unlock(struct intel_gt *gt, int tag) 1237void intel_gt_reset_unlock(struct intel_gt *gt, int tag)
diff --git a/drivers/gpu/drm/i915/gt/intel_reset.h b/drivers/gpu/drm/i915/gt/intel_reset.h
index 37a987b17108..52c00199e069 100644
--- a/drivers/gpu/drm/i915/gt/intel_reset.h
+++ b/drivers/gpu/drm/i915/gt/intel_reset.h
@@ -38,7 +38,7 @@ int intel_engine_reset(struct intel_engine_cs *engine,
38 38
39void __i915_request_reset(struct i915_request *rq, bool guilty); 39void __i915_request_reset(struct i915_request *rq, bool guilty);
40 40
41int __must_check intel_gt_reset_trylock(struct intel_gt *gt); 41int __must_check intel_gt_reset_trylock(struct intel_gt *gt, int *srcu);
42void intel_gt_reset_unlock(struct intel_gt *gt, int tag); 42void intel_gt_reset_unlock(struct intel_gt *gt, int tag);
43 43
44void intel_gt_set_wedged(struct intel_gt *gt); 44void intel_gt_set_wedged(struct intel_gt *gt);
diff --git a/drivers/gpu/drm/i915/gt/intel_ringbuffer.c b/drivers/gpu/drm/i915/gt/intel_ringbuffer.c
index 601c16239fdf..bacaa7bb8c9a 100644
--- a/drivers/gpu/drm/i915/gt/intel_ringbuffer.c
+++ b/drivers/gpu/drm/i915/gt/intel_ringbuffer.c
@@ -1573,7 +1573,7 @@ static inline int mi_set_context(struct i915_request *rq, u32 flags)
1573 struct intel_engine_cs *engine = rq->engine; 1573 struct intel_engine_cs *engine = rq->engine;
1574 enum intel_engine_id id; 1574 enum intel_engine_id id;
1575 const int num_engines = 1575 const int num_engines =
1576 IS_HSW_GT1(i915) ? RUNTIME_INFO(i915)->num_engines - 1 : 0; 1576 IS_HASWELL(i915) ? RUNTIME_INFO(i915)->num_engines - 1 : 0;
1577 bool force_restore = false; 1577 bool force_restore = false;
1578 int len; 1578 int len;
1579 u32 *cs; 1579 u32 *cs;
diff --git a/drivers/gpu/drm/i915/gt/intel_workarounds.c b/drivers/gpu/drm/i915/gt/intel_workarounds.c
index 45481eb1fa3c..5f6ec2fd29a0 100644
--- a/drivers/gpu/drm/i915/gt/intel_workarounds.c
+++ b/drivers/gpu/drm/i915/gt/intel_workarounds.c
@@ -1063,6 +1063,9 @@ static void gen9_whitelist_build(struct i915_wa_list *w)
1063 1063
1064 /* WaAllowUMDToModifyHDCChicken1:skl,bxt,kbl,glk,cfl */ 1064 /* WaAllowUMDToModifyHDCChicken1:skl,bxt,kbl,glk,cfl */
1065 whitelist_reg(w, GEN8_HDC_CHICKEN1); 1065 whitelist_reg(w, GEN8_HDC_CHICKEN1);
1066
1067 /* WaSendPushConstantsFromMMIO:skl,bxt */
1068 whitelist_reg(w, COMMON_SLICE_CHICKEN2);
1066} 1069}
1067 1070
1068static void skl_whitelist_build(struct intel_engine_cs *engine) 1071static void skl_whitelist_build(struct intel_engine_cs *engine)
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 020696726f9e..bb6f86c7067a 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -1924,6 +1924,11 @@ static int i915_drm_resume(struct drm_device *dev)
1924 if (ret) 1924 if (ret)
1925 DRM_ERROR("failed to re-enable GGTT\n"); 1925 DRM_ERROR("failed to re-enable GGTT\n");
1926 1926
1927 mutex_lock(&dev_priv->drm.struct_mutex);
1928 i915_gem_restore_gtt_mappings(dev_priv);
1929 i915_gem_restore_fences(dev_priv);
1930 mutex_unlock(&dev_priv->drm.struct_mutex);
1931
1927 intel_csr_ucode_resume(dev_priv); 1932 intel_csr_ucode_resume(dev_priv);
1928 1933
1929 i915_restore_state(dev_priv); 1934 i915_restore_state(dev_priv);
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 95e7c52cf8ed..d0f94f239919 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -969,6 +969,9 @@ i915_gem_object_ggtt_pin(struct drm_i915_gem_object *obj,
969 969
970 lockdep_assert_held(&obj->base.dev->struct_mutex); 970 lockdep_assert_held(&obj->base.dev->struct_mutex);
971 971
972 if (i915_gem_object_never_bind_ggtt(obj))
973 return ERR_PTR(-ENODEV);
974
972 if (flags & PIN_MAPPABLE && 975 if (flags & PIN_MAPPABLE &&
973 (!view || view->type == I915_GGTT_VIEW_NORMAL)) { 976 (!view || view->type == I915_GGTT_VIEW_NORMAL)) {
974 /* If the required space is larger than the available 977 /* If the required space is larger than the available
diff --git a/drivers/gpu/drm/i915/i915_gem.h b/drivers/gpu/drm/i915/i915_gem.h
index 167a7b56ed5b..6795f1daa3d5 100644
--- a/drivers/gpu/drm/i915/i915_gem.h
+++ b/drivers/gpu/drm/i915/i915_gem.h
@@ -77,6 +77,12 @@ struct drm_i915_private;
77 77
78#define I915_GEM_IDLE_TIMEOUT (HZ / 5) 78#define I915_GEM_IDLE_TIMEOUT (HZ / 5)
79 79
80static inline void tasklet_lock(struct tasklet_struct *t)
81{
82 while (!tasklet_trylock(t))
83 cpu_relax();
84}
85
80static inline void __tasklet_disable_sync_once(struct tasklet_struct *t) 86static inline void __tasklet_disable_sync_once(struct tasklet_struct *t)
81{ 87{
82 if (!atomic_fetch_inc(&t->count)) 88 if (!atomic_fetch_inc(&t->count))
diff --git a/drivers/gpu/drm/i915/i915_request.c b/drivers/gpu/drm/i915/i915_request.c
index a53777dd371c..1c5506822dc7 100644
--- a/drivers/gpu/drm/i915/i915_request.c
+++ b/drivers/gpu/drm/i915/i915_request.c
@@ -194,6 +194,27 @@ static void free_capture_list(struct i915_request *request)
194 } 194 }
195} 195}
196 196
197static void remove_from_engine(struct i915_request *rq)
198{
199 struct intel_engine_cs *engine, *locked;
200
201 /*
202 * Virtual engines complicate acquiring the engine timeline lock,
203 * as their rq->engine pointer is not stable until under that
204 * engine lock. The simple ploy we use is to take the lock then
205 * check that the rq still belongs to the newly locked engine.
206 */
207 locked = READ_ONCE(rq->engine);
208 spin_lock(&locked->active.lock);
209 while (unlikely(locked != (engine = READ_ONCE(rq->engine)))) {
210 spin_unlock(&locked->active.lock);
211 spin_lock(&engine->active.lock);
212 locked = engine;
213 }
214 list_del(&rq->sched.link);
215 spin_unlock(&locked->active.lock);
216}
217
197static bool i915_request_retire(struct i915_request *rq) 218static bool i915_request_retire(struct i915_request *rq)
198{ 219{
199 struct i915_active_request *active, *next; 220 struct i915_active_request *active, *next;
@@ -259,9 +280,7 @@ static bool i915_request_retire(struct i915_request *rq)
259 * request that we have removed from the HW and put back on a run 280 * request that we have removed from the HW and put back on a run
260 * queue. 281 * queue.
261 */ 282 */
262 spin_lock(&rq->engine->active.lock); 283 remove_from_engine(rq);
263 list_del(&rq->sched.link);
264 spin_unlock(&rq->engine->active.lock);
265 284
266 spin_lock(&rq->lock); 285 spin_lock(&rq->lock);
267 i915_request_mark_complete(rq); 286 i915_request_mark_complete(rq);
@@ -358,9 +377,10 @@ __i915_request_await_execution(struct i915_request *rq,
358 return 0; 377 return 0;
359} 378}
360 379
361void __i915_request_submit(struct i915_request *request) 380bool __i915_request_submit(struct i915_request *request)
362{ 381{
363 struct intel_engine_cs *engine = request->engine; 382 struct intel_engine_cs *engine = request->engine;
383 bool result = false;
364 384
365 GEM_TRACE("%s fence %llx:%lld, current %d\n", 385 GEM_TRACE("%s fence %llx:%lld, current %d\n",
366 engine->name, 386 engine->name,
@@ -370,6 +390,25 @@ void __i915_request_submit(struct i915_request *request)
370 GEM_BUG_ON(!irqs_disabled()); 390 GEM_BUG_ON(!irqs_disabled());
371 lockdep_assert_held(&engine->active.lock); 391 lockdep_assert_held(&engine->active.lock);
372 392
393 /*
394 * With the advent of preempt-to-busy, we frequently encounter
395 * requests that we have unsubmitted from HW, but left running
396 * until the next ack and so have completed in the meantime. On
397 * resubmission of that completed request, we can skip
398 * updating the payload, and execlists can even skip submitting
399 * the request.
400 *
401 * We must remove the request from the caller's priority queue,
402 * and the caller must only call us when the request is in their
403 * priority queue, under the active.lock. This ensures that the
404 * request has *not* yet been retired and we can safely move
405 * the request into the engine->active.list where it will be
406 * dropped upon retiring. (Otherwise if resubmit a *retired*
407 * request, this would be a horrible use-after-free.)
408 */
409 if (i915_request_completed(request))
410 goto xfer;
411
373 if (i915_gem_context_is_banned(request->gem_context)) 412 if (i915_gem_context_is_banned(request->gem_context))
374 i915_request_skip(request, -EIO); 413 i915_request_skip(request, -EIO);
375 414
@@ -393,13 +432,18 @@ void __i915_request_submit(struct i915_request *request)
393 i915_sw_fence_signaled(&request->semaphore)) 432 i915_sw_fence_signaled(&request->semaphore))
394 engine->saturated |= request->sched.semaphores; 433 engine->saturated |= request->sched.semaphores;
395 434
396 /* We may be recursing from the signal callback of another i915 fence */ 435 engine->emit_fini_breadcrumb(request,
397 spin_lock_nested(&request->lock, SINGLE_DEPTH_NESTING); 436 request->ring->vaddr + request->postfix);
398 437
399 list_move_tail(&request->sched.link, &engine->active.requests); 438 trace_i915_request_execute(request);
439 engine->serial++;
440 result = true;
441
442xfer: /* We may be recursing from the signal callback of another i915 fence */
443 spin_lock_nested(&request->lock, SINGLE_DEPTH_NESTING);
400 444
401 GEM_BUG_ON(test_bit(I915_FENCE_FLAG_ACTIVE, &request->fence.flags)); 445 if (!test_and_set_bit(I915_FENCE_FLAG_ACTIVE, &request->fence.flags))
402 set_bit(I915_FENCE_FLAG_ACTIVE, &request->fence.flags); 446 list_move_tail(&request->sched.link, &engine->active.requests);
403 447
404 if (test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &request->fence.flags) && 448 if (test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &request->fence.flags) &&
405 !test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &request->fence.flags) && 449 !test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &request->fence.flags) &&
@@ -410,12 +454,7 @@ void __i915_request_submit(struct i915_request *request)
410 454
411 spin_unlock(&request->lock); 455 spin_unlock(&request->lock);
412 456
413 engine->emit_fini_breadcrumb(request, 457 return result;
414 request->ring->vaddr + request->postfix);
415
416 engine->serial++;
417
418 trace_i915_request_execute(request);
419} 458}
420 459
421void i915_request_submit(struct i915_request *request) 460void i915_request_submit(struct i915_request *request)
diff --git a/drivers/gpu/drm/i915/i915_request.h b/drivers/gpu/drm/i915/i915_request.h
index 8ac6e1226a56..e4dd013761e8 100644
--- a/drivers/gpu/drm/i915/i915_request.h
+++ b/drivers/gpu/drm/i915/i915_request.h
@@ -292,7 +292,7 @@ int i915_request_await_execution(struct i915_request *rq,
292 292
293void i915_request_add(struct i915_request *rq); 293void i915_request_add(struct i915_request *rq);
294 294
295void __i915_request_submit(struct i915_request *request); 295bool __i915_request_submit(struct i915_request *request);
296void i915_request_submit(struct i915_request *request); 296void i915_request_submit(struct i915_request *request);
297 297
298void i915_request_skip(struct i915_request *request, int error); 298void i915_request_skip(struct i915_request *request, int error);
diff --git a/drivers/gpu/drm/i915/intel_pch.c b/drivers/gpu/drm/i915/intel_pch.c
index fa864d8f2b73..15f8bff141f9 100644
--- a/drivers/gpu/drm/i915/intel_pch.c
+++ b/drivers/gpu/drm/i915/intel_pch.c
@@ -69,6 +69,7 @@ intel_pch_type(const struct drm_i915_private *dev_priv, unsigned short id)
69 WARN_ON(!IS_CANNONLAKE(dev_priv) && !IS_COFFEELAKE(dev_priv)); 69 WARN_ON(!IS_CANNONLAKE(dev_priv) && !IS_COFFEELAKE(dev_priv));
70 return PCH_CNP; 70 return PCH_CNP;
71 case INTEL_PCH_CMP_DEVICE_ID_TYPE: 71 case INTEL_PCH_CMP_DEVICE_ID_TYPE:
72 case INTEL_PCH_CMP2_DEVICE_ID_TYPE:
72 DRM_DEBUG_KMS("Found Comet Lake PCH (CMP)\n"); 73 DRM_DEBUG_KMS("Found Comet Lake PCH (CMP)\n");
73 WARN_ON(!IS_COFFEELAKE(dev_priv)); 74 WARN_ON(!IS_COFFEELAKE(dev_priv));
74 /* CometPoint is CNP Compatible */ 75 /* CometPoint is CNP Compatible */
diff --git a/drivers/gpu/drm/i915/intel_pch.h b/drivers/gpu/drm/i915/intel_pch.h
index e6a2d65f19c6..c29c81ec7971 100644
--- a/drivers/gpu/drm/i915/intel_pch.h
+++ b/drivers/gpu/drm/i915/intel_pch.h
@@ -41,6 +41,7 @@ enum intel_pch {
41#define INTEL_PCH_CNP_DEVICE_ID_TYPE 0xA300 41#define INTEL_PCH_CNP_DEVICE_ID_TYPE 0xA300
42#define INTEL_PCH_CNP_LP_DEVICE_ID_TYPE 0x9D80 42#define INTEL_PCH_CNP_LP_DEVICE_ID_TYPE 0x9D80
43#define INTEL_PCH_CMP_DEVICE_ID_TYPE 0x0280 43#define INTEL_PCH_CMP_DEVICE_ID_TYPE 0x0280
44#define INTEL_PCH_CMP2_DEVICE_ID_TYPE 0x0680
44#define INTEL_PCH_ICP_DEVICE_ID_TYPE 0x3480 45#define INTEL_PCH_ICP_DEVICE_ID_TYPE 0x3480
45#define INTEL_PCH_MCC_DEVICE_ID_TYPE 0x4B00 46#define INTEL_PCH_MCC_DEVICE_ID_TYPE 0x4B00
46#define INTEL_PCH_MCC2_DEVICE_ID_TYPE 0x3880 47#define INTEL_PCH_MCC2_DEVICE_ID_TYPE 0x3880
diff --git a/drivers/gpu/drm/i915/selftests/i915_gem.c b/drivers/gpu/drm/i915/selftests/i915_gem.c
index bb6dd54a6ff3..37593831b539 100644
--- a/drivers/gpu/drm/i915/selftests/i915_gem.c
+++ b/drivers/gpu/drm/i915/selftests/i915_gem.c
@@ -118,6 +118,12 @@ static void pm_resume(struct drm_i915_private *i915)
118 with_intel_runtime_pm(&i915->runtime_pm, wakeref) { 118 with_intel_runtime_pm(&i915->runtime_pm, wakeref) {
119 intel_gt_sanitize(&i915->gt, false); 119 intel_gt_sanitize(&i915->gt, false);
120 i915_gem_sanitize(i915); 120 i915_gem_sanitize(i915);
121
122 mutex_lock(&i915->drm.struct_mutex);
123 i915_gem_restore_gtt_mappings(i915);
124 i915_gem_restore_fences(i915);
125 mutex_unlock(&i915->drm.struct_mutex);
126
121 i915_gem_resume(i915); 127 i915_gem_resume(i915);
122 } 128 }
123} 129}
diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c b/drivers/gpu/drm/msm/dsi/dsi_host.c
index 663ff9f4fac9..1e7b1be25bb0 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -26,6 +26,8 @@
26#include "dsi_cfg.h" 26#include "dsi_cfg.h"
27#include "msm_kms.h" 27#include "msm_kms.h"
28 28
29#define DSI_RESET_TOGGLE_DELAY_MS 20
30
29static int dsi_get_version(const void __iomem *base, u32 *major, u32 *minor) 31static int dsi_get_version(const void __iomem *base, u32 *major, u32 *minor)
30{ 32{
31 u32 ver; 33 u32 ver;
@@ -986,7 +988,7 @@ static void dsi_sw_reset(struct msm_dsi_host *msm_host)
986 wmb(); /* clocks need to be enabled before reset */ 988 wmb(); /* clocks need to be enabled before reset */
987 989
988 dsi_write(msm_host, REG_DSI_RESET, 1); 990 dsi_write(msm_host, REG_DSI_RESET, 1);
989 wmb(); /* make sure reset happen */ 991 msleep(DSI_RESET_TOGGLE_DELAY_MS); /* make sure reset happen */
990 dsi_write(msm_host, REG_DSI_RESET, 0); 992 dsi_write(msm_host, REG_DSI_RESET, 0);
991} 993}
992 994
@@ -1396,7 +1398,7 @@ static void dsi_sw_reset_restore(struct msm_dsi_host *msm_host)
1396 1398
1397 /* dsi controller can only be reset while clocks are running */ 1399 /* dsi controller can only be reset while clocks are running */
1398 dsi_write(msm_host, REG_DSI_RESET, 1); 1400 dsi_write(msm_host, REG_DSI_RESET, 1);
1399 wmb(); /* make sure reset happen */ 1401 msleep(DSI_RESET_TOGGLE_DELAY_MS); /* make sure reset happen */
1400 dsi_write(msm_host, REG_DSI_RESET, 0); 1402 dsi_write(msm_host, REG_DSI_RESET, 0);
1401 wmb(); /* controller out of reset */ 1403 wmb(); /* controller out of reset */
1402 dsi_write(msm_host, REG_DSI_CTRL, data0); 1404 dsi_write(msm_host, REG_DSI_CTRL, data0);
diff --git a/drivers/gpu/drm/omapdrm/dss/dss.c b/drivers/gpu/drm/omapdrm/dss/dss.c
index e226324adb69..4bdd63b57100 100644
--- a/drivers/gpu/drm/omapdrm/dss/dss.c
+++ b/drivers/gpu/drm/omapdrm/dss/dss.c
@@ -1083,7 +1083,7 @@ static const struct dss_features omap34xx_dss_feats = {
1083 1083
1084static const struct dss_features omap3630_dss_feats = { 1084static const struct dss_features omap3630_dss_feats = {
1085 .model = DSS_MODEL_OMAP3, 1085 .model = DSS_MODEL_OMAP3,
1086 .fck_div_max = 32, 1086 .fck_div_max = 31,
1087 .fck_freq_max = 173000000, 1087 .fck_freq_max = 173000000,
1088 .dss_fck_multiplier = 1, 1088 .dss_fck_multiplier = 1,
1089 .parent_clk_name = "dpll4_ck", 1089 .parent_clk_name = "dpll4_ck",
diff --git a/drivers/gpu/drm/panel/panel-lg-lb035q02.c b/drivers/gpu/drm/panel/panel-lg-lb035q02.c
index fc82a525b071..ee4379729a5b 100644
--- a/drivers/gpu/drm/panel/panel-lg-lb035q02.c
+++ b/drivers/gpu/drm/panel/panel-lg-lb035q02.c
@@ -220,9 +220,17 @@ static const struct of_device_id lb035q02_of_match[] = {
220 220
221MODULE_DEVICE_TABLE(of, lb035q02_of_match); 221MODULE_DEVICE_TABLE(of, lb035q02_of_match);
222 222
223static const struct spi_device_id lb035q02_ids[] = {
224 { "lb035q02", 0 },
225 { /* sentinel */ }
226};
227
228MODULE_DEVICE_TABLE(spi, lb035q02_ids);
229
223static struct spi_driver lb035q02_driver = { 230static struct spi_driver lb035q02_driver = {
224 .probe = lb035q02_probe, 231 .probe = lb035q02_probe,
225 .remove = lb035q02_remove, 232 .remove = lb035q02_remove,
233 .id_table = lb035q02_ids,
226 .driver = { 234 .driver = {
227 .name = "panel-lg-lb035q02", 235 .name = "panel-lg-lb035q02",
228 .of_match_table = lb035q02_of_match, 236 .of_match_table = lb035q02_of_match,
@@ -231,7 +239,6 @@ static struct spi_driver lb035q02_driver = {
231 239
232module_spi_driver(lb035q02_driver); 240module_spi_driver(lb035q02_driver);
233 241
234MODULE_ALIAS("spi:lgphilips,lb035q02");
235MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>"); 242MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
236MODULE_DESCRIPTION("LG.Philips LB035Q02 LCD Panel driver"); 243MODULE_DESCRIPTION("LG.Philips LB035Q02 LCD Panel driver");
237MODULE_LICENSE("GPL"); 244MODULE_LICENSE("GPL");
diff --git a/drivers/gpu/drm/panel/panel-nec-nl8048hl11.c b/drivers/gpu/drm/panel/panel-nec-nl8048hl11.c
index 299b217c83e1..20f17e46e65d 100644
--- a/drivers/gpu/drm/panel/panel-nec-nl8048hl11.c
+++ b/drivers/gpu/drm/panel/panel-nec-nl8048hl11.c
@@ -230,9 +230,17 @@ static const struct of_device_id nl8048_of_match[] = {
230 230
231MODULE_DEVICE_TABLE(of, nl8048_of_match); 231MODULE_DEVICE_TABLE(of, nl8048_of_match);
232 232
233static const struct spi_device_id nl8048_ids[] = {
234 { "nl8048hl11", 0 },
235 { /* sentinel */ }
236};
237
238MODULE_DEVICE_TABLE(spi, nl8048_ids);
239
233static struct spi_driver nl8048_driver = { 240static struct spi_driver nl8048_driver = {
234 .probe = nl8048_probe, 241 .probe = nl8048_probe,
235 .remove = nl8048_remove, 242 .remove = nl8048_remove,
243 .id_table = nl8048_ids,
236 .driver = { 244 .driver = {
237 .name = "panel-nec-nl8048hl11", 245 .name = "panel-nec-nl8048hl11",
238 .pm = &nl8048_pm_ops, 246 .pm = &nl8048_pm_ops,
@@ -242,7 +250,6 @@ static struct spi_driver nl8048_driver = {
242 250
243module_spi_driver(nl8048_driver); 251module_spi_driver(nl8048_driver);
244 252
245MODULE_ALIAS("spi:nec,nl8048hl11");
246MODULE_AUTHOR("Erik Gilling <konkers@android.com>"); 253MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
247MODULE_DESCRIPTION("NEC-NL8048HL11 Driver"); 254MODULE_DESCRIPTION("NEC-NL8048HL11 Driver");
248MODULE_LICENSE("GPL"); 255MODULE_LICENSE("GPL");
diff --git a/drivers/gpu/drm/panel/panel-sony-acx565akm.c b/drivers/gpu/drm/panel/panel-sony-acx565akm.c
index 305259b58767..3d5b9c4f68d9 100644
--- a/drivers/gpu/drm/panel/panel-sony-acx565akm.c
+++ b/drivers/gpu/drm/panel/panel-sony-acx565akm.c
@@ -684,9 +684,17 @@ static const struct of_device_id acx565akm_of_match[] = {
684 684
685MODULE_DEVICE_TABLE(of, acx565akm_of_match); 685MODULE_DEVICE_TABLE(of, acx565akm_of_match);
686 686
687static const struct spi_device_id acx565akm_ids[] = {
688 { "acx565akm", 0 },
689 { /* sentinel */ }
690};
691
692MODULE_DEVICE_TABLE(spi, acx565akm_ids);
693
687static struct spi_driver acx565akm_driver = { 694static struct spi_driver acx565akm_driver = {
688 .probe = acx565akm_probe, 695 .probe = acx565akm_probe,
689 .remove = acx565akm_remove, 696 .remove = acx565akm_remove,
697 .id_table = acx565akm_ids,
690 .driver = { 698 .driver = {
691 .name = "panel-sony-acx565akm", 699 .name = "panel-sony-acx565akm",
692 .of_match_table = acx565akm_of_match, 700 .of_match_table = acx565akm_of_match,
@@ -695,7 +703,6 @@ static struct spi_driver acx565akm_driver = {
695 703
696module_spi_driver(acx565akm_driver); 704module_spi_driver(acx565akm_driver);
697 705
698MODULE_ALIAS("spi:sony,acx565akm");
699MODULE_AUTHOR("Nokia Corporation"); 706MODULE_AUTHOR("Nokia Corporation");
700MODULE_DESCRIPTION("Sony ACX565AKM LCD Panel Driver"); 707MODULE_DESCRIPTION("Sony ACX565AKM LCD Panel Driver");
701MODULE_LICENSE("GPL"); 708MODULE_LICENSE("GPL");
diff --git a/drivers/gpu/drm/panel/panel-tpo-td028ttec1.c b/drivers/gpu/drm/panel/panel-tpo-td028ttec1.c
index d7b2e34626ef..f2baff827f50 100644
--- a/drivers/gpu/drm/panel/panel-tpo-td028ttec1.c
+++ b/drivers/gpu/drm/panel/panel-tpo-td028ttec1.c
@@ -375,8 +375,7 @@ static const struct of_device_id td028ttec1_of_match[] = {
375MODULE_DEVICE_TABLE(of, td028ttec1_of_match); 375MODULE_DEVICE_TABLE(of, td028ttec1_of_match);
376 376
377static const struct spi_device_id td028ttec1_ids[] = { 377static const struct spi_device_id td028ttec1_ids[] = {
378 { "tpo,td028ttec1", 0}, 378 { "td028ttec1", 0 },
379 { "toppoly,td028ttec1", 0 },
380 { /* sentinel */ } 379 { /* sentinel */ }
381}; 380};
382 381
diff --git a/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c b/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
index 84370562910f..ba163c779084 100644
--- a/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
+++ b/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
@@ -491,9 +491,17 @@ static const struct of_device_id td043mtea1_of_match[] = {
491 491
492MODULE_DEVICE_TABLE(of, td043mtea1_of_match); 492MODULE_DEVICE_TABLE(of, td043mtea1_of_match);
493 493
494static const struct spi_device_id td043mtea1_ids[] = {
495 { "td043mtea1", 0 },
496 { /* sentinel */ }
497};
498
499MODULE_DEVICE_TABLE(spi, td043mtea1_ids);
500
494static struct spi_driver td043mtea1_driver = { 501static struct spi_driver td043mtea1_driver = {
495 .probe = td043mtea1_probe, 502 .probe = td043mtea1_probe,
496 .remove = td043mtea1_remove, 503 .remove = td043mtea1_remove,
504 .id_table = td043mtea1_ids,
497 .driver = { 505 .driver = {
498 .name = "panel-tpo-td043mtea1", 506 .name = "panel-tpo-td043mtea1",
499 .pm = &td043mtea1_pm_ops, 507 .pm = &td043mtea1_pm_ops,
@@ -503,7 +511,6 @@ static struct spi_driver td043mtea1_driver = {
503 511
504module_spi_driver(td043mtea1_driver); 512module_spi_driver(td043mtea1_driver);
505 513
506MODULE_ALIAS("spi:tpo,td043mtea1");
507MODULE_AUTHOR("Gražvydas Ignotas <notasas@gmail.com>"); 514MODULE_AUTHOR("Gražvydas Ignotas <notasas@gmail.com>");
508MODULE_DESCRIPTION("TPO TD043MTEA1 Panel Driver"); 515MODULE_DESCRIPTION("TPO TD043MTEA1 Panel Driver");
509MODULE_LICENSE("GPL"); 516MODULE_LICENSE("GPL");
diff --git a/drivers/gpu/drm/panfrost/panfrost_gpu.c b/drivers/gpu/drm/panfrost/panfrost_gpu.c
index f67ed925c0ef..8822ec13a0d6 100644
--- a/drivers/gpu/drm/panfrost/panfrost_gpu.c
+++ b/drivers/gpu/drm/panfrost/panfrost_gpu.c
@@ -208,6 +208,9 @@ static void panfrost_gpu_init_features(struct panfrost_device *pfdev)
208 pfdev->features.mem_features = gpu_read(pfdev, GPU_MEM_FEATURES); 208 pfdev->features.mem_features = gpu_read(pfdev, GPU_MEM_FEATURES);
209 pfdev->features.mmu_features = gpu_read(pfdev, GPU_MMU_FEATURES); 209 pfdev->features.mmu_features = gpu_read(pfdev, GPU_MMU_FEATURES);
210 pfdev->features.thread_features = gpu_read(pfdev, GPU_THREAD_FEATURES); 210 pfdev->features.thread_features = gpu_read(pfdev, GPU_THREAD_FEATURES);
211 pfdev->features.max_threads = gpu_read(pfdev, GPU_THREAD_MAX_THREADS);
212 pfdev->features.thread_max_workgroup_sz = gpu_read(pfdev, GPU_THREAD_MAX_WORKGROUP_SIZE);
213 pfdev->features.thread_max_barrier_sz = gpu_read(pfdev, GPU_THREAD_MAX_BARRIER_SIZE);
211 pfdev->features.coherency_features = gpu_read(pfdev, GPU_COHERENCY_FEATURES); 214 pfdev->features.coherency_features = gpu_read(pfdev, GPU_COHERENCY_FEATURES);
212 for (i = 0; i < 4; i++) 215 for (i = 0; i < 4; i++)
213 pfdev->features.texture_features[i] = gpu_read(pfdev, GPU_TEXTURE_FEATURES(i)); 216 pfdev->features.texture_features[i] = gpu_read(pfdev, GPU_TEXTURE_FEATURES(i));
diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c
index a58551668d9a..21f34d44aac2 100644
--- a/drivers/gpu/drm/panfrost/panfrost_job.c
+++ b/drivers/gpu/drm/panfrost/panfrost_job.c
@@ -381,13 +381,19 @@ static void panfrost_job_timedout(struct drm_sched_job *sched_job)
381 job_read(pfdev, JS_TAIL_LO(js)), 381 job_read(pfdev, JS_TAIL_LO(js)),
382 sched_job); 382 sched_job);
383 383
384 mutex_lock(&pfdev->reset_lock); 384 if (!mutex_trylock(&pfdev->reset_lock))
385 return;
385 386
386 for (i = 0; i < NUM_JOB_SLOTS; i++) 387 for (i = 0; i < NUM_JOB_SLOTS; i++) {
387 drm_sched_stop(&pfdev->js->queue[i].sched, sched_job); 388 struct drm_gpu_scheduler *sched = &pfdev->js->queue[i].sched;
389
390 drm_sched_stop(sched, sched_job);
391 if (js != i)
392 /* Ensure any timeouts on other slots have finished */
393 cancel_delayed_work_sync(&sched->work_tdr);
394 }
388 395
389 if (sched_job) 396 drm_sched_increase_karma(sched_job);
390 drm_sched_increase_karma(sched_job);
391 397
392 spin_lock_irqsave(&pfdev->js->job_lock, flags); 398 spin_lock_irqsave(&pfdev->js->job_lock, flags);
393 for (i = 0; i < NUM_JOB_SLOTS; i++) { 399 for (i = 0; i < NUM_JOB_SLOTS; i++) {
diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c
index d0bc91ed7c90..9e55076578c6 100644
--- a/drivers/gpu/drm/radeon/radeon_drv.c
+++ b/drivers/gpu/drm/radeon/radeon_drv.c
@@ -379,19 +379,11 @@ radeon_pci_remove(struct pci_dev *pdev)
379static void 379static void
380radeon_pci_shutdown(struct pci_dev *pdev) 380radeon_pci_shutdown(struct pci_dev *pdev)
381{ 381{
382 struct drm_device *ddev = pci_get_drvdata(pdev);
383
384 /* if we are running in a VM, make sure the device 382 /* if we are running in a VM, make sure the device
385 * torn down properly on reboot/shutdown 383 * torn down properly on reboot/shutdown
386 */ 384 */
387 if (radeon_device_is_virtual()) 385 if (radeon_device_is_virtual())
388 radeon_pci_remove(pdev); 386 radeon_pci_remove(pdev);
389
390 /* Some adapters need to be suspended before a
391 * shutdown occurs in order to prevent an error
392 * during kexec.
393 */
394 radeon_suspend_kms(ddev, true, true, false);
395} 387}
396 388
397static int radeon_pmops_suspend(struct device *dev) 389static int radeon_pmops_suspend(struct device *dev)
diff --git a/drivers/gpu/drm/rcar-du/rcar_du_writeback.c b/drivers/gpu/drm/rcar-du/rcar_du_writeback.c
index ae07290bba6a..04efa78d70b6 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_writeback.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_writeback.c
@@ -147,7 +147,7 @@ static int rcar_du_wb_enc_atomic_check(struct drm_encoder *encoder,
147 struct drm_device *dev = encoder->dev; 147 struct drm_device *dev = encoder->dev;
148 struct drm_framebuffer *fb; 148 struct drm_framebuffer *fb;
149 149
150 if (!conn_state->writeback_job || !conn_state->writeback_job->fb) 150 if (!conn_state->writeback_job)
151 return 0; 151 return 0;
152 152
153 fb = conn_state->writeback_job->fb; 153 fb = conn_state->writeback_job->fb;
@@ -221,7 +221,7 @@ void rcar_du_writeback_setup(struct rcar_du_crtc *rcrtc,
221 unsigned int i; 221 unsigned int i;
222 222
223 state = rcrtc->writeback.base.state; 223 state = rcrtc->writeback.base.state;
224 if (!state || !state->writeback_job || !state->writeback_job->fb) 224 if (!state || !state->writeback_job)
225 return; 225 return;
226 226
227 fb = state->writeback_job->fb; 227 fb = state->writeback_job->fb;
diff --git a/drivers/gpu/drm/tilcdc/tilcdc_tfp410.c b/drivers/gpu/drm/tilcdc/tilcdc_tfp410.c
index 525dc1c0f1c1..530edb3b51cc 100644
--- a/drivers/gpu/drm/tilcdc/tilcdc_tfp410.c
+++ b/drivers/gpu/drm/tilcdc/tilcdc_tfp410.c
@@ -7,6 +7,7 @@
7#include <linux/gpio.h> 7#include <linux/gpio.h>
8#include <linux/mod_devicetable.h> 8#include <linux/mod_devicetable.h>
9#include <linux/of_gpio.h> 9#include <linux/of_gpio.h>
10#include <linux/pinctrl/consumer.h>
10#include <linux/platform_device.h> 11#include <linux/platform_device.h>
11 12
12#include <drm/drm_atomic_helper.h> 13#include <drm/drm_atomic_helper.h>
diff --git a/drivers/gpu/drm/tiny/Kconfig b/drivers/gpu/drm/tiny/Kconfig
index 504763423d46..a46ac284dd5e 100644
--- a/drivers/gpu/drm/tiny/Kconfig
+++ b/drivers/gpu/drm/tiny/Kconfig
@@ -63,7 +63,6 @@ config TINYDRM_REPAPER
63 depends on DRM && SPI 63 depends on DRM && SPI
64 select DRM_KMS_HELPER 64 select DRM_KMS_HELPER
65 select DRM_KMS_CMA_HELPER 65 select DRM_KMS_CMA_HELPER
66 depends on THERMAL || !THERMAL
67 help 66 help
68 DRM driver for the following Pervasive Displays panels: 67 DRM driver for the following Pervasive Displays panels:
69 1.44" TFT EPD Panel (E1144CS021) 68 1.44" TFT EPD Panel (E1144CS021)
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 20ff56f27aa4..98819462f025 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -185,8 +185,9 @@ static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object *bo,
185 list_add_tail(&bo->lru, &man->lru[bo->priority]); 185 list_add_tail(&bo->lru, &man->lru[bo->priority]);
186 kref_get(&bo->list_kref); 186 kref_get(&bo->list_kref);
187 187
188 if (bo->ttm && !(bo->ttm->page_flags & 188 if (!(man->flags & TTM_MEMTYPE_FLAG_FIXED) && bo->ttm &&
189 (TTM_PAGE_FLAG_SG | TTM_PAGE_FLAG_SWAPPED))) { 189 !(bo->ttm->page_flags & (TTM_PAGE_FLAG_SG |
190 TTM_PAGE_FLAG_SWAPPED))) {
190 list_add_tail(&bo->swap, &bdev->glob->swap_lru[bo->priority]); 191 list_add_tail(&bo->swap, &bdev->glob->swap_lru[bo->priority]);
191 kref_get(&bo->list_kref); 192 kref_get(&bo->list_kref);
192 } 193 }
@@ -878,11 +879,11 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
878 879
879 if (!bo) { 880 if (!bo) {
880 if (busy_bo) 881 if (busy_bo)
881 ttm_bo_get(busy_bo); 882 kref_get(&busy_bo->list_kref);
882 spin_unlock(&glob->lru_lock); 883 spin_unlock(&glob->lru_lock);
883 ret = ttm_mem_evict_wait_busy(busy_bo, ctx, ticket); 884 ret = ttm_mem_evict_wait_busy(busy_bo, ctx, ticket);
884 if (busy_bo) 885 if (busy_bo)
885 ttm_bo_put(busy_bo); 886 kref_put(&busy_bo->list_kref, ttm_bo_release_list);
886 return ret; 887 return ret;
887 } 888 }
888 889
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index 76eedb963693..46dc3de7e81b 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -278,15 +278,13 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
278 else 278 else
279 ret = vmf_insert_pfn(&cvma, address, pfn); 279 ret = vmf_insert_pfn(&cvma, address, pfn);
280 280
281 /* 281 /* Never error on prefaulted PTEs */
282 * Somebody beat us to this PTE or prefaulting to 282 if (unlikely((ret & VM_FAULT_ERROR))) {
283 * an already populated PTE, or prefaulting error. 283 if (i == 0)
284 */ 284 goto out_io_unlock;
285 285 else
286 if (unlikely((ret == VM_FAULT_NOPAGE && i > 0))) 286 break;
287 break; 287 }
288 else if (unlikely(ret & VM_FAULT_ERROR))
289 goto out_io_unlock;
290 288
291 address += PAGE_SIZE; 289 address += PAGE_SIZE;
292 if (unlikely(++page_offset >= page_last)) 290 if (unlikely(++page_offset >= page_last))
diff --git a/drivers/gpu/drm/vc4/vc4_txp.c b/drivers/gpu/drm/vc4/vc4_txp.c
index 1ce4d7142b6e..bf720206727f 100644
--- a/drivers/gpu/drm/vc4/vc4_txp.c
+++ b/drivers/gpu/drm/vc4/vc4_txp.c
@@ -231,7 +231,7 @@ static int vc4_txp_connector_atomic_check(struct drm_connector *conn,
231 int i; 231 int i;
232 232
233 conn_state = drm_atomic_get_new_connector_state(state, conn); 233 conn_state = drm_atomic_get_new_connector_state(state, conn);
234 if (!conn_state->writeback_job || !conn_state->writeback_job->fb) 234 if (!conn_state->writeback_job)
235 return 0; 235 return 0;
236 236
237 crtc_state = drm_atomic_get_new_crtc_state(state, conn_state->crtc); 237 crtc_state = drm_atomic_get_new_crtc_state(state, conn_state->crtc);
@@ -271,8 +271,7 @@ static void vc4_txp_connector_atomic_commit(struct drm_connector *conn,
271 u32 ctrl; 271 u32 ctrl;
272 int i; 272 int i;
273 273
274 if (WARN_ON(!conn_state->writeback_job || 274 if (WARN_ON(!conn_state->writeback_job))
275 !conn_state->writeback_job->fb))
276 return; 275 return;
277 276
278 mode = &conn_state->crtc->state->adjusted_mode; 277 mode = &conn_state->crtc->state->adjusted_mode;
diff --git a/drivers/gpu/drm/xen/xen_drm_front.c b/drivers/gpu/drm/xen/xen_drm_front.c
index ba1828acd8c9..4be49c1aef51 100644
--- a/drivers/gpu/drm/xen/xen_drm_front.c
+++ b/drivers/gpu/drm/xen/xen_drm_front.c
@@ -718,17 +718,9 @@ static int xen_drv_probe(struct xenbus_device *xb_dev,
718 struct device *dev = &xb_dev->dev; 718 struct device *dev = &xb_dev->dev;
719 int ret; 719 int ret;
720 720
721 /* 721 ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(64));
722 * The device is not spawn from a device tree, so arch_setup_dma_ops
723 * is not called, thus leaving the device with dummy DMA ops.
724 * This makes the device return error on PRIME buffer import, which
725 * is not correct: to fix this call of_dma_configure() with a NULL
726 * node to set default DMA ops.
727 */
728 dev->coherent_dma_mask = DMA_BIT_MASK(32);
729 ret = of_dma_configure(dev, NULL, true);
730 if (ret < 0) { 722 if (ret < 0) {
731 DRM_ERROR("Cannot setup DMA ops, ret %d", ret); 723 DRM_ERROR("Cannot setup DMA mask, ret %d", ret);
732 return ret; 724 return ret;
733 } 725 }
734 726
diff --git a/drivers/hid/hid-hyperv.c b/drivers/hid/hid-hyperv.c
index cc5b09b87ab0..79a28fc91521 100644
--- a/drivers/hid/hid-hyperv.c
+++ b/drivers/hid/hid-hyperv.c
@@ -314,60 +314,24 @@ static void mousevsc_on_receive(struct hv_device *device,
314 314
315static void mousevsc_on_channel_callback(void *context) 315static void mousevsc_on_channel_callback(void *context)
316{ 316{
317 const int packet_size = 0x100;
318 int ret;
319 struct hv_device *device = context; 317 struct hv_device *device = context;
320 u32 bytes_recvd;
321 u64 req_id;
322 struct vmpacket_descriptor *desc; 318 struct vmpacket_descriptor *desc;
323 unsigned char *buffer;
324 int bufferlen = packet_size;
325
326 buffer = kmalloc(bufferlen, GFP_ATOMIC);
327 if (!buffer)
328 return;
329
330 do {
331 ret = vmbus_recvpacket_raw(device->channel, buffer,
332 bufferlen, &bytes_recvd, &req_id);
333
334 switch (ret) {
335 case 0:
336 if (bytes_recvd <= 0) {
337 kfree(buffer);
338 return;
339 }
340 desc = (struct vmpacket_descriptor *)buffer;
341
342 switch (desc->type) {
343 case VM_PKT_COMP:
344 break;
345
346 case VM_PKT_DATA_INBAND:
347 mousevsc_on_receive(device, desc);
348 break;
349
350 default:
351 pr_err("unhandled packet type %d, tid %llx len %d\n",
352 desc->type, req_id, bytes_recvd);
353 break;
354 }
355 319
320 foreach_vmbus_pkt(desc, device->channel) {
321 switch (desc->type) {
322 case VM_PKT_COMP:
356 break; 323 break;
357 324
358 case -ENOBUFS: 325 case VM_PKT_DATA_INBAND:
359 kfree(buffer); 326 mousevsc_on_receive(device, desc);
360 /* Handle large packet */ 327 break;
361 bufferlen = bytes_recvd;
362 buffer = kmalloc(bytes_recvd, GFP_ATOMIC);
363
364 if (!buffer)
365 return;
366 328
329 default:
330 pr_err("Unhandled packet type %d, tid %llx len %d\n",
331 desc->type, desc->trans_id, desc->len8 * 8);
367 break; 332 break;
368 } 333 }
369 } while (1); 334 }
370
371} 335}
372 336
373static int mousevsc_connect_to_vsp(struct hv_device *device) 337static int mousevsc_connect_to_vsp(struct hv_device *device)
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 391f0b225c9a..53a60c81e220 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -912,6 +912,7 @@ static void vmbus_shutdown(struct device *child_device)
912 drv->shutdown(dev); 912 drv->shutdown(dev);
913} 913}
914 914
915#ifdef CONFIG_PM_SLEEP
915/* 916/*
916 * vmbus_suspend - Suspend a vmbus device 917 * vmbus_suspend - Suspend a vmbus device
917 */ 918 */
@@ -949,6 +950,7 @@ static int vmbus_resume(struct device *child_device)
949 950
950 return drv->resume(dev); 951 return drv->resume(dev);
951} 952}
953#endif /* CONFIG_PM_SLEEP */
952 954
953/* 955/*
954 * vmbus_device_release - Final callback release of the vmbus child device 956 * vmbus_device_release - Final callback release of the vmbus child device
@@ -1070,6 +1072,7 @@ msg_handled:
1070 vmbus_signal_eom(msg, message_type); 1072 vmbus_signal_eom(msg, message_type);
1071} 1073}
1072 1074
1075#ifdef CONFIG_PM_SLEEP
1073/* 1076/*
1074 * Fake RESCIND_CHANNEL messages to clean up hv_sock channels by force for 1077 * Fake RESCIND_CHANNEL messages to clean up hv_sock channels by force for
1075 * hibernation, because hv_sock connections can not persist across hibernation. 1078 * hibernation, because hv_sock connections can not persist across hibernation.
@@ -1105,6 +1108,7 @@ static void vmbus_force_channel_rescinded(struct vmbus_channel *channel)
1105 vmbus_connection.work_queue, 1108 vmbus_connection.work_queue,
1106 &ctx->work); 1109 &ctx->work);
1107} 1110}
1111#endif /* CONFIG_PM_SLEEP */
1108 1112
1109/* 1113/*
1110 * Direct callback for channels using other deferred processing 1114 * Direct callback for channels using other deferred processing
@@ -2125,6 +2129,7 @@ acpi_walk_err:
2125 return ret_val; 2129 return ret_val;
2126} 2130}
2127 2131
2132#ifdef CONFIG_PM_SLEEP
2128static int vmbus_bus_suspend(struct device *dev) 2133static int vmbus_bus_suspend(struct device *dev)
2129{ 2134{
2130 struct vmbus_channel *channel, *sc; 2135 struct vmbus_channel *channel, *sc;
@@ -2247,6 +2252,7 @@ static int vmbus_bus_resume(struct device *dev)
2247 2252
2248 return 0; 2253 return 0;
2249} 2254}
2255#endif /* CONFIG_PM_SLEEP */
2250 2256
2251static const struct acpi_device_id vmbus_acpi_device_ids[] = { 2257static const struct acpi_device_id vmbus_acpi_device_ids[] = {
2252 {"VMBUS", 0}, 2258 {"VMBUS", 0},
diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c
index 95b447cfa24c..b26419dbe840 100644
--- a/drivers/hwmon/nct7904.c
+++ b/drivers/hwmon/nct7904.c
@@ -99,6 +99,8 @@ struct nct7904_data {
99 u8 enable_dts; 99 u8 enable_dts;
100 u8 has_dts; 100 u8 has_dts;
101 u8 temp_mode; /* 0: TR mode, 1: TD mode */ 101 u8 temp_mode; /* 0: TR mode, 1: TD mode */
102 u8 fan_alarm[2];
103 u8 vsen_alarm[3];
102}; 104};
103 105
104/* Access functions */ 106/* Access functions */
@@ -214,7 +216,15 @@ static int nct7904_read_fan(struct device *dev, u32 attr, int channel,
214 SMI_STS5_REG + (channel >> 3)); 216 SMI_STS5_REG + (channel >> 3));
215 if (ret < 0) 217 if (ret < 0)
216 return ret; 218 return ret;
217 *val = (ret >> (channel & 0x07)) & 1; 219 if (!data->fan_alarm[channel >> 3])
220 data->fan_alarm[channel >> 3] = ret & 0xff;
221 else
222 /* If there is new alarm showing up */
223 data->fan_alarm[channel >> 3] |= (ret & 0xff);
224 *val = (data->fan_alarm[channel >> 3] >> (channel & 0x07)) & 1;
225 /* Needs to clean the alarm if alarm existing */
226 if (*val)
227 data->fan_alarm[channel >> 3] ^= 1 << (channel & 0x07);
218 return 0; 228 return 0;
219 default: 229 default:
220 return -EOPNOTSUPP; 230 return -EOPNOTSUPP;
@@ -298,7 +308,15 @@ static int nct7904_read_in(struct device *dev, u32 attr, int channel,
298 SMI_STS1_REG + (index >> 3)); 308 SMI_STS1_REG + (index >> 3));
299 if (ret < 0) 309 if (ret < 0)
300 return ret; 310 return ret;
301 *val = (ret >> (index & 0x07)) & 1; 311 if (!data->vsen_alarm[index >> 3])
312 data->vsen_alarm[index >> 3] = ret & 0xff;
313 else
314 /* If there is new alarm showing up */
315 data->vsen_alarm[index >> 3] |= (ret & 0xff);
316 *val = (data->vsen_alarm[index >> 3] >> (index & 0x07)) & 1;
317 /* Needs to clean the alarm if alarm existing */
318 if (*val)
319 data->vsen_alarm[index >> 3] ^= 1 << (index & 0x07);
302 return 0; 320 return 0;
303 default: 321 default:
304 return -EOPNOTSUPP; 322 return -EOPNOTSUPP;
@@ -915,12 +933,15 @@ static int nct7904_probe(struct i2c_client *client,
915 933
916 data->temp_mode = 0; 934 data->temp_mode = 0;
917 for (i = 0; i < 4; i++) { 935 for (i = 0; i < 4; i++) {
918 val = (ret & (0x03 << i)) >> (i * 2); 936 val = (ret >> (i * 2)) & 0x03;
919 bit = (1 << i); 937 bit = (1 << i);
920 if (val == 0) 938 if (val == 0) {
921 data->tcpu_mask &= ~bit; 939 data->tcpu_mask &= ~bit;
922 else if (val == 0x1 || val == 0x2) 940 } else {
923 data->temp_mode |= bit; 941 if (val == 0x1 || val == 0x2)
942 data->temp_mode |= bit;
943 data->vsen_mask &= ~(0x06 << (i * 2));
944 }
924 } 945 }
925 946
926 /* PECI */ 947 /* PECI */
diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
index 055227cb3d43..67b8817995c0 100644
--- a/drivers/iio/accel/adxl372.c
+++ b/drivers/iio/accel/adxl372.c
@@ -474,12 +474,17 @@ static int adxl372_configure_fifo(struct adxl372_state *st)
474 if (ret < 0) 474 if (ret < 0)
475 return ret; 475 return ret;
476 476
477 fifo_samples = st->watermark & 0xFF; 477 /*
478 * watermark stores the number of sets; we need to write the FIFO
479 * registers with the number of samples
480 */
481 fifo_samples = (st->watermark * st->fifo_set_size);
478 fifo_ctl = ADXL372_FIFO_CTL_FORMAT_MODE(st->fifo_format) | 482 fifo_ctl = ADXL372_FIFO_CTL_FORMAT_MODE(st->fifo_format) |
479 ADXL372_FIFO_CTL_MODE_MODE(st->fifo_mode) | 483 ADXL372_FIFO_CTL_MODE_MODE(st->fifo_mode) |
480 ADXL372_FIFO_CTL_SAMPLES_MODE(st->watermark); 484 ADXL372_FIFO_CTL_SAMPLES_MODE(fifo_samples);
481 485
482 ret = regmap_write(st->regmap, ADXL372_FIFO_SAMPLES, fifo_samples); 486 ret = regmap_write(st->regmap,
487 ADXL372_FIFO_SAMPLES, fifo_samples & 0xFF);
483 if (ret < 0) 488 if (ret < 0)
484 return ret; 489 return ret;
485 490
@@ -548,8 +553,7 @@ static irqreturn_t adxl372_trigger_handler(int irq, void *p)
548 goto err; 553 goto err;
549 554
550 /* Each sample is 2 bytes */ 555 /* Each sample is 2 bytes */
551 for (i = 0; i < fifo_entries * sizeof(u16); 556 for (i = 0; i < fifo_entries; i += st->fifo_set_size)
552 i += st->fifo_set_size * sizeof(u16))
553 iio_push_to_buffers(indio_dev, &st->fifo_buf[i]); 557 iio_push_to_buffers(indio_dev, &st->fifo_buf[i]);
554 } 558 }
555err: 559err:
@@ -571,6 +575,14 @@ static int adxl372_setup(struct adxl372_state *st)
571 return -ENODEV; 575 return -ENODEV;
572 } 576 }
573 577
578 /*
579 * Perform a software reset to make sure the device is in a consistent
580 * state after start up.
581 */
582 ret = regmap_write(st->regmap, ADXL372_RESET, ADXL372_RESET_CODE);
583 if (ret < 0)
584 return ret;
585
574 ret = adxl372_set_op_mode(st, ADXL372_STANDBY); 586 ret = adxl372_set_op_mode(st, ADXL372_STANDBY);
575 if (ret < 0) 587 if (ret < 0)
576 return ret; 588 return ret;
diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
index cf6c0e3a83d3..121b4e89f038 100644
--- a/drivers/iio/accel/bmc150-accel-core.c
+++ b/drivers/iio/accel/bmc150-accel-core.c
@@ -117,7 +117,7 @@
117#define BMC150_ACCEL_SLEEP_1_SEC 0x0F 117#define BMC150_ACCEL_SLEEP_1_SEC 0x0F
118 118
119#define BMC150_ACCEL_REG_TEMP 0x08 119#define BMC150_ACCEL_REG_TEMP 0x08
120#define BMC150_ACCEL_TEMP_CENTER_VAL 24 120#define BMC150_ACCEL_TEMP_CENTER_VAL 23
121 121
122#define BMC150_ACCEL_AXIS_TO_REG(axis) (BMC150_ACCEL_REG_XOUT_L + (axis * 2)) 122#define BMC150_ACCEL_AXIS_TO_REG(axis) (BMC150_ACCEL_REG_XOUT_L + (axis * 2))
123#define BMC150_AUTO_SUSPEND_DELAY_MS 2000 123#define BMC150_AUTO_SUSPEND_DELAY_MS 2000
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index 5a3ca5904ded..f658012baad8 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -810,10 +810,10 @@ static int ad799x_probe(struct i2c_client *client,
810 810
811 ret = ad799x_write_config(st, st->chip_config->default_config); 811 ret = ad799x_write_config(st, st->chip_config->default_config);
812 if (ret < 0) 812 if (ret < 0)
813 goto error_disable_reg; 813 goto error_disable_vref;
814 ret = ad799x_read_config(st); 814 ret = ad799x_read_config(st);
815 if (ret < 0) 815 if (ret < 0)
816 goto error_disable_reg; 816 goto error_disable_vref;
817 st->config = ret; 817 st->config = ret;
818 818
819 ret = iio_triggered_buffer_setup(indio_dev, NULL, 819 ret = iio_triggered_buffer_setup(indio_dev, NULL,
diff --git a/drivers/iio/adc/axp288_adc.c b/drivers/iio/adc/axp288_adc.c
index adc9cf7a075d..8ea2aed6d6f5 100644
--- a/drivers/iio/adc/axp288_adc.c
+++ b/drivers/iio/adc/axp288_adc.c
@@ -7,6 +7,7 @@
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 */ 8 */
9 9
10#include <linux/dmi.h>
10#include <linux/module.h> 11#include <linux/module.h>
11#include <linux/kernel.h> 12#include <linux/kernel.h>
12#include <linux/device.h> 13#include <linux/device.h>
@@ -25,6 +26,11 @@
25#define AXP288_ADC_EN_MASK 0xF0 26#define AXP288_ADC_EN_MASK 0xF0
26#define AXP288_ADC_TS_ENABLE 0x01 27#define AXP288_ADC_TS_ENABLE 0x01
27 28
29#define AXP288_ADC_TS_BIAS_MASK GENMASK(5, 4)
30#define AXP288_ADC_TS_BIAS_20UA (0 << 4)
31#define AXP288_ADC_TS_BIAS_40UA (1 << 4)
32#define AXP288_ADC_TS_BIAS_60UA (2 << 4)
33#define AXP288_ADC_TS_BIAS_80UA (3 << 4)
28#define AXP288_ADC_TS_CURRENT_ON_OFF_MASK GENMASK(1, 0) 34#define AXP288_ADC_TS_CURRENT_ON_OFF_MASK GENMASK(1, 0)
29#define AXP288_ADC_TS_CURRENT_OFF (0 << 0) 35#define AXP288_ADC_TS_CURRENT_OFF (0 << 0)
30#define AXP288_ADC_TS_CURRENT_ON_WHEN_CHARGING (1 << 0) 36#define AXP288_ADC_TS_CURRENT_ON_WHEN_CHARGING (1 << 0)
@@ -177,10 +183,36 @@ static int axp288_adc_read_raw(struct iio_dev *indio_dev,
177 return ret; 183 return ret;
178} 184}
179 185
186/*
187 * We rely on the machine's firmware to correctly setup the TS pin bias current
188 * at boot. This lists systems with broken fw where we need to set it ourselves.
189 */
190static const struct dmi_system_id axp288_adc_ts_bias_override[] = {
191 {
192 /* Lenovo Ideapad 100S (11 inch) */
193 .matches = {
194 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
195 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad 100S-11IBY"),
196 },
197 .driver_data = (void *)(uintptr_t)AXP288_ADC_TS_BIAS_80UA,
198 },
199 {}
200};
201
180static int axp288_adc_initialize(struct axp288_adc_info *info) 202static int axp288_adc_initialize(struct axp288_adc_info *info)
181{ 203{
204 const struct dmi_system_id *bias_override;
182 int ret, adc_enable_val; 205 int ret, adc_enable_val;
183 206
207 bias_override = dmi_first_match(axp288_adc_ts_bias_override);
208 if (bias_override) {
209 ret = regmap_update_bits(info->regmap, AXP288_ADC_TS_PIN_CTRL,
210 AXP288_ADC_TS_BIAS_MASK,
211 (uintptr_t)bias_override->driver_data);
212 if (ret)
213 return ret;
214 }
215
184 /* 216 /*
185 * Determine if the TS pin is enabled and set the TS current-source 217 * Determine if the TS pin is enabled and set the TS current-source
186 * accordingly. 218 * accordingly.
diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c
index 88c7fe15003b..62e6c8badd22 100644
--- a/drivers/iio/adc/hx711.c
+++ b/drivers/iio/adc/hx711.c
@@ -100,14 +100,14 @@ struct hx711_data {
100 100
101static int hx711_cycle(struct hx711_data *hx711_data) 101static int hx711_cycle(struct hx711_data *hx711_data)
102{ 102{
103 int val; 103 unsigned long flags;
104 104
105 /* 105 /*
106 * if preempted for more then 60us while PD_SCK is high: 106 * if preempted for more then 60us while PD_SCK is high:
107 * hx711 is going in reset 107 * hx711 is going in reset
108 * ==> measuring is false 108 * ==> measuring is false
109 */ 109 */
110 preempt_disable(); 110 local_irq_save(flags);
111 gpiod_set_value(hx711_data->gpiod_pd_sck, 1); 111 gpiod_set_value(hx711_data->gpiod_pd_sck, 1);
112 112
113 /* 113 /*
@@ -117,7 +117,6 @@ static int hx711_cycle(struct hx711_data *hx711_data)
117 */ 117 */
118 ndelay(hx711_data->data_ready_delay_ns); 118 ndelay(hx711_data->data_ready_delay_ns);
119 119
120 val = gpiod_get_value(hx711_data->gpiod_dout);
121 /* 120 /*
122 * here we are not waiting for 0.2 us as suggested by the datasheet, 121 * here we are not waiting for 0.2 us as suggested by the datasheet,
123 * because the oscilloscope showed in a test scenario 122 * because the oscilloscope showed in a test scenario
@@ -125,7 +124,7 @@ static int hx711_cycle(struct hx711_data *hx711_data)
125 * and 0.56 us for PD_SCK low on TI Sitara with 800 MHz 124 * and 0.56 us for PD_SCK low on TI Sitara with 800 MHz
126 */ 125 */
127 gpiod_set_value(hx711_data->gpiod_pd_sck, 0); 126 gpiod_set_value(hx711_data->gpiod_pd_sck, 0);
128 preempt_enable(); 127 local_irq_restore(flags);
129 128
130 /* 129 /*
131 * make it a square wave for addressing cases with capacitance on 130 * make it a square wave for addressing cases with capacitance on
@@ -133,7 +132,8 @@ static int hx711_cycle(struct hx711_data *hx711_data)
133 */ 132 */
134 ndelay(hx711_data->data_ready_delay_ns); 133 ndelay(hx711_data->data_ready_delay_ns);
135 134
136 return val; 135 /* sample as late as possible */
136 return gpiod_get_value(hx711_data->gpiod_dout);
137} 137}
138 138
139static int hx711_read(struct hx711_data *hx711_data) 139static int hx711_read(struct hx711_data *hx711_data)
diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
index 7b28d045d271..7b27306330a3 100644
--- a/drivers/iio/adc/meson_saradc.c
+++ b/drivers/iio/adc/meson_saradc.c
@@ -1219,6 +1219,11 @@ static int meson_sar_adc_probe(struct platform_device *pdev)
1219 if (IS_ERR(base)) 1219 if (IS_ERR(base))
1220 return PTR_ERR(base); 1220 return PTR_ERR(base);
1221 1221
1222 priv->regmap = devm_regmap_init_mmio(&pdev->dev, base,
1223 priv->param->regmap_config);
1224 if (IS_ERR(priv->regmap))
1225 return PTR_ERR(priv->regmap);
1226
1222 irq = irq_of_parse_and_map(pdev->dev.of_node, 0); 1227 irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
1223 if (!irq) 1228 if (!irq)
1224 return -EINVAL; 1229 return -EINVAL;
@@ -1228,11 +1233,6 @@ static int meson_sar_adc_probe(struct platform_device *pdev)
1228 if (ret) 1233 if (ret)
1229 return ret; 1234 return ret;
1230 1235
1231 priv->regmap = devm_regmap_init_mmio(&pdev->dev, base,
1232 priv->param->regmap_config);
1233 if (IS_ERR(priv->regmap))
1234 return PTR_ERR(priv->regmap);
1235
1236 priv->clkin = devm_clk_get(&pdev->dev, "clkin"); 1236 priv->clkin = devm_clk_get(&pdev->dev, "clkin");
1237 if (IS_ERR(priv->clkin)) { 1237 if (IS_ERR(priv->clkin)) {
1238 dev_err(&pdev->dev, "failed to get clkin\n"); 1238 dev_err(&pdev->dev, "failed to get clkin\n");
diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c
index 9b85fefc0a96..93a096a91f8c 100644
--- a/drivers/iio/adc/stm32-adc-core.c
+++ b/drivers/iio/adc/stm32-adc-core.c
@@ -24,33 +24,6 @@
24 24
25#include "stm32-adc-core.h" 25#include "stm32-adc-core.h"
26 26
27/* STM32F4 - common registers for all ADC instances: 1, 2 & 3 */
28#define STM32F4_ADC_CSR (STM32_ADCX_COMN_OFFSET + 0x00)
29#define STM32F4_ADC_CCR (STM32_ADCX_COMN_OFFSET + 0x04)
30
31/* STM32F4_ADC_CSR - bit fields */
32#define STM32F4_EOC3 BIT(17)
33#define STM32F4_EOC2 BIT(9)
34#define STM32F4_EOC1 BIT(1)
35
36/* STM32F4_ADC_CCR - bit fields */
37#define STM32F4_ADC_ADCPRE_SHIFT 16
38#define STM32F4_ADC_ADCPRE_MASK GENMASK(17, 16)
39
40/* STM32H7 - common registers for all ADC instances */
41#define STM32H7_ADC_CSR (STM32_ADCX_COMN_OFFSET + 0x00)
42#define STM32H7_ADC_CCR (STM32_ADCX_COMN_OFFSET + 0x08)
43
44/* STM32H7_ADC_CSR - bit fields */
45#define STM32H7_EOC_SLV BIT(18)
46#define STM32H7_EOC_MST BIT(2)
47
48/* STM32H7_ADC_CCR - bit fields */
49#define STM32H7_PRESC_SHIFT 18
50#define STM32H7_PRESC_MASK GENMASK(21, 18)
51#define STM32H7_CKMODE_SHIFT 16
52#define STM32H7_CKMODE_MASK GENMASK(17, 16)
53
54#define STM32_ADC_CORE_SLEEP_DELAY_MS 2000 27#define STM32_ADC_CORE_SLEEP_DELAY_MS 2000
55 28
56/* SYSCFG registers */ 29/* SYSCFG registers */
@@ -71,6 +44,8 @@
71 * @eoc1: adc1 end of conversion flag in @csr 44 * @eoc1: adc1 end of conversion flag in @csr
72 * @eoc2: adc2 end of conversion flag in @csr 45 * @eoc2: adc2 end of conversion flag in @csr
73 * @eoc3: adc3 end of conversion flag in @csr 46 * @eoc3: adc3 end of conversion flag in @csr
47 * @ier: interrupt enable register offset for each adc
48 * @eocie_msk: end of conversion interrupt enable mask in @ier
74 */ 49 */
75struct stm32_adc_common_regs { 50struct stm32_adc_common_regs {
76 u32 csr; 51 u32 csr;
@@ -78,6 +53,8 @@ struct stm32_adc_common_regs {
78 u32 eoc1_msk; 53 u32 eoc1_msk;
79 u32 eoc2_msk; 54 u32 eoc2_msk;
80 u32 eoc3_msk; 55 u32 eoc3_msk;
56 u32 ier;
57 u32 eocie_msk;
81}; 58};
82 59
83struct stm32_adc_priv; 60struct stm32_adc_priv;
@@ -303,6 +280,8 @@ static const struct stm32_adc_common_regs stm32f4_adc_common_regs = {
303 .eoc1_msk = STM32F4_EOC1, 280 .eoc1_msk = STM32F4_EOC1,
304 .eoc2_msk = STM32F4_EOC2, 281 .eoc2_msk = STM32F4_EOC2,
305 .eoc3_msk = STM32F4_EOC3, 282 .eoc3_msk = STM32F4_EOC3,
283 .ier = STM32F4_ADC_CR1,
284 .eocie_msk = STM32F4_EOCIE,
306}; 285};
307 286
308/* STM32H7 common registers definitions */ 287/* STM32H7 common registers definitions */
@@ -311,8 +290,24 @@ static const struct stm32_adc_common_regs stm32h7_adc_common_regs = {
311 .ccr = STM32H7_ADC_CCR, 290 .ccr = STM32H7_ADC_CCR,
312 .eoc1_msk = STM32H7_EOC_MST, 291 .eoc1_msk = STM32H7_EOC_MST,
313 .eoc2_msk = STM32H7_EOC_SLV, 292 .eoc2_msk = STM32H7_EOC_SLV,
293 .ier = STM32H7_ADC_IER,
294 .eocie_msk = STM32H7_EOCIE,
295};
296
297static const unsigned int stm32_adc_offset[STM32_ADC_MAX_ADCS] = {
298 0, STM32_ADC_OFFSET, STM32_ADC_OFFSET * 2,
314}; 299};
315 300
301static unsigned int stm32_adc_eoc_enabled(struct stm32_adc_priv *priv,
302 unsigned int adc)
303{
304 u32 ier, offset = stm32_adc_offset[adc];
305
306 ier = readl_relaxed(priv->common.base + offset + priv->cfg->regs->ier);
307
308 return ier & priv->cfg->regs->eocie_msk;
309}
310
316/* ADC common interrupt for all instances */ 311/* ADC common interrupt for all instances */
317static void stm32_adc_irq_handler(struct irq_desc *desc) 312static void stm32_adc_irq_handler(struct irq_desc *desc)
318{ 313{
@@ -323,13 +318,28 @@ static void stm32_adc_irq_handler(struct irq_desc *desc)
323 chained_irq_enter(chip, desc); 318 chained_irq_enter(chip, desc);
324 status = readl_relaxed(priv->common.base + priv->cfg->regs->csr); 319 status = readl_relaxed(priv->common.base + priv->cfg->regs->csr);
325 320
326 if (status & priv->cfg->regs->eoc1_msk) 321 /*
322 * End of conversion may be handled by using IRQ or DMA. There may be a
323 * race here when two conversions complete at the same time on several
324 * ADCs. EOC may be read 'set' for several ADCs, with:
325 * - an ADC configured to use DMA (EOC triggers the DMA request, and
326 * is then automatically cleared by DR read in hardware)
327 * - an ADC configured to use IRQs (EOCIE bit is set. The handler must
328 * be called in this case)
329 * So both EOC status bit in CSR and EOCIE control bit must be checked
330 * before invoking the interrupt handler (e.g. call ISR only for
331 * IRQ-enabled ADCs).
332 */
333 if (status & priv->cfg->regs->eoc1_msk &&
334 stm32_adc_eoc_enabled(priv, 0))
327 generic_handle_irq(irq_find_mapping(priv->domain, 0)); 335 generic_handle_irq(irq_find_mapping(priv->domain, 0));
328 336
329 if (status & priv->cfg->regs->eoc2_msk) 337 if (status & priv->cfg->regs->eoc2_msk &&
338 stm32_adc_eoc_enabled(priv, 1))
330 generic_handle_irq(irq_find_mapping(priv->domain, 1)); 339 generic_handle_irq(irq_find_mapping(priv->domain, 1));
331 340
332 if (status & priv->cfg->regs->eoc3_msk) 341 if (status & priv->cfg->regs->eoc3_msk &&
342 stm32_adc_eoc_enabled(priv, 2))
333 generic_handle_irq(irq_find_mapping(priv->domain, 2)); 343 generic_handle_irq(irq_find_mapping(priv->domain, 2));
334 344
335 chained_irq_exit(chip, desc); 345 chained_irq_exit(chip, desc);
diff --git a/drivers/iio/adc/stm32-adc-core.h b/drivers/iio/adc/stm32-adc-core.h
index 8af507b3f32d..2579d514c2a3 100644
--- a/drivers/iio/adc/stm32-adc-core.h
+++ b/drivers/iio/adc/stm32-adc-core.h
@@ -25,8 +25,145 @@
25 * -------------------------------------------------------- 25 * --------------------------------------------------------
26 */ 26 */
27#define STM32_ADC_MAX_ADCS 3 27#define STM32_ADC_MAX_ADCS 3
28#define STM32_ADC_OFFSET 0x100
28#define STM32_ADCX_COMN_OFFSET 0x300 29#define STM32_ADCX_COMN_OFFSET 0x300
29 30
31/* STM32F4 - Registers for each ADC instance */
32#define STM32F4_ADC_SR 0x00
33#define STM32F4_ADC_CR1 0x04
34#define STM32F4_ADC_CR2 0x08
35#define STM32F4_ADC_SMPR1 0x0C
36#define STM32F4_ADC_SMPR2 0x10
37#define STM32F4_ADC_HTR 0x24
38#define STM32F4_ADC_LTR 0x28
39#define STM32F4_ADC_SQR1 0x2C
40#define STM32F4_ADC_SQR2 0x30
41#define STM32F4_ADC_SQR3 0x34
42#define STM32F4_ADC_JSQR 0x38
43#define STM32F4_ADC_JDR1 0x3C
44#define STM32F4_ADC_JDR2 0x40
45#define STM32F4_ADC_JDR3 0x44
46#define STM32F4_ADC_JDR4 0x48
47#define STM32F4_ADC_DR 0x4C
48
49/* STM32F4 - common registers for all ADC instances: 1, 2 & 3 */
50#define STM32F4_ADC_CSR (STM32_ADCX_COMN_OFFSET + 0x00)
51#define STM32F4_ADC_CCR (STM32_ADCX_COMN_OFFSET + 0x04)
52
53/* STM32F4_ADC_SR - bit fields */
54#define STM32F4_STRT BIT(4)
55#define STM32F4_EOC BIT(1)
56
57/* STM32F4_ADC_CR1 - bit fields */
58#define STM32F4_RES_SHIFT 24
59#define STM32F4_RES_MASK GENMASK(25, 24)
60#define STM32F4_SCAN BIT(8)
61#define STM32F4_EOCIE BIT(5)
62
63/* STM32F4_ADC_CR2 - bit fields */
64#define STM32F4_SWSTART BIT(30)
65#define STM32F4_EXTEN_SHIFT 28
66#define STM32F4_EXTEN_MASK GENMASK(29, 28)
67#define STM32F4_EXTSEL_SHIFT 24
68#define STM32F4_EXTSEL_MASK GENMASK(27, 24)
69#define STM32F4_EOCS BIT(10)
70#define STM32F4_DDS BIT(9)
71#define STM32F4_DMA BIT(8)
72#define STM32F4_ADON BIT(0)
73
74/* STM32F4_ADC_CSR - bit fields */
75#define STM32F4_EOC3 BIT(17)
76#define STM32F4_EOC2 BIT(9)
77#define STM32F4_EOC1 BIT(1)
78
79/* STM32F4_ADC_CCR - bit fields */
80#define STM32F4_ADC_ADCPRE_SHIFT 16
81#define STM32F4_ADC_ADCPRE_MASK GENMASK(17, 16)
82
83/* STM32H7 - Registers for each ADC instance */
84#define STM32H7_ADC_ISR 0x00
85#define STM32H7_ADC_IER 0x04
86#define STM32H7_ADC_CR 0x08
87#define STM32H7_ADC_CFGR 0x0C
88#define STM32H7_ADC_SMPR1 0x14
89#define STM32H7_ADC_SMPR2 0x18
90#define STM32H7_ADC_PCSEL 0x1C
91#define STM32H7_ADC_SQR1 0x30
92#define STM32H7_ADC_SQR2 0x34
93#define STM32H7_ADC_SQR3 0x38
94#define STM32H7_ADC_SQR4 0x3C
95#define STM32H7_ADC_DR 0x40
96#define STM32H7_ADC_DIFSEL 0xC0
97#define STM32H7_ADC_CALFACT 0xC4
98#define STM32H7_ADC_CALFACT2 0xC8
99
100/* STM32H7 - common registers for all ADC instances */
101#define STM32H7_ADC_CSR (STM32_ADCX_COMN_OFFSET + 0x00)
102#define STM32H7_ADC_CCR (STM32_ADCX_COMN_OFFSET + 0x08)
103
104/* STM32H7_ADC_ISR - bit fields */
105#define STM32MP1_VREGREADY BIT(12)
106#define STM32H7_EOC BIT(2)
107#define STM32H7_ADRDY BIT(0)
108
109/* STM32H7_ADC_IER - bit fields */
110#define STM32H7_EOCIE STM32H7_EOC
111
112/* STM32H7_ADC_CR - bit fields */
113#define STM32H7_ADCAL BIT(31)
114#define STM32H7_ADCALDIF BIT(30)
115#define STM32H7_DEEPPWD BIT(29)
116#define STM32H7_ADVREGEN BIT(28)
117#define STM32H7_LINCALRDYW6 BIT(27)
118#define STM32H7_LINCALRDYW5 BIT(26)
119#define STM32H7_LINCALRDYW4 BIT(25)
120#define STM32H7_LINCALRDYW3 BIT(24)
121#define STM32H7_LINCALRDYW2 BIT(23)
122#define STM32H7_LINCALRDYW1 BIT(22)
123#define STM32H7_ADCALLIN BIT(16)
124#define STM32H7_BOOST BIT(8)
125#define STM32H7_ADSTP BIT(4)
126#define STM32H7_ADSTART BIT(2)
127#define STM32H7_ADDIS BIT(1)
128#define STM32H7_ADEN BIT(0)
129
130/* STM32H7_ADC_CFGR bit fields */
131#define STM32H7_EXTEN_SHIFT 10
132#define STM32H7_EXTEN_MASK GENMASK(11, 10)
133#define STM32H7_EXTSEL_SHIFT 5
134#define STM32H7_EXTSEL_MASK GENMASK(9, 5)
135#define STM32H7_RES_SHIFT 2
136#define STM32H7_RES_MASK GENMASK(4, 2)
137#define STM32H7_DMNGT_SHIFT 0
138#define STM32H7_DMNGT_MASK GENMASK(1, 0)
139
140enum stm32h7_adc_dmngt {
141 STM32H7_DMNGT_DR_ONLY, /* Regular data in DR only */
142 STM32H7_DMNGT_DMA_ONESHOT, /* DMA one shot mode */
143 STM32H7_DMNGT_DFSDM, /* DFSDM mode */
144 STM32H7_DMNGT_DMA_CIRC, /* DMA circular mode */
145};
146
147/* STM32H7_ADC_CALFACT - bit fields */
148#define STM32H7_CALFACT_D_SHIFT 16
149#define STM32H7_CALFACT_D_MASK GENMASK(26, 16)
150#define STM32H7_CALFACT_S_SHIFT 0
151#define STM32H7_CALFACT_S_MASK GENMASK(10, 0)
152
153/* STM32H7_ADC_CALFACT2 - bit fields */
154#define STM32H7_LINCALFACT_SHIFT 0
155#define STM32H7_LINCALFACT_MASK GENMASK(29, 0)
156
157/* STM32H7_ADC_CSR - bit fields */
158#define STM32H7_EOC_SLV BIT(18)
159#define STM32H7_EOC_MST BIT(2)
160
161/* STM32H7_ADC_CCR - bit fields */
162#define STM32H7_PRESC_SHIFT 18
163#define STM32H7_PRESC_MASK GENMASK(21, 18)
164#define STM32H7_CKMODE_SHIFT 16
165#define STM32H7_CKMODE_MASK GENMASK(17, 16)
166
30/** 167/**
31 * struct stm32_adc_common - stm32 ADC driver common data (for all instances) 168 * struct stm32_adc_common - stm32 ADC driver common data (for all instances)
32 * @base: control registers base cpu addr 169 * @base: control registers base cpu addr
diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
index 6a7dd08b1e0b..663f8a5012d6 100644
--- a/drivers/iio/adc/stm32-adc.c
+++ b/drivers/iio/adc/stm32-adc.c
@@ -28,115 +28,6 @@
28 28
29#include "stm32-adc-core.h" 29#include "stm32-adc-core.h"
30 30
31/* STM32F4 - Registers for each ADC instance */
32#define STM32F4_ADC_SR 0x00
33#define STM32F4_ADC_CR1 0x04
34#define STM32F4_ADC_CR2 0x08
35#define STM32F4_ADC_SMPR1 0x0C
36#define STM32F4_ADC_SMPR2 0x10
37#define STM32F4_ADC_HTR 0x24
38#define STM32F4_ADC_LTR 0x28
39#define STM32F4_ADC_SQR1 0x2C
40#define STM32F4_ADC_SQR2 0x30
41#define STM32F4_ADC_SQR3 0x34
42#define STM32F4_ADC_JSQR 0x38
43#define STM32F4_ADC_JDR1 0x3C
44#define STM32F4_ADC_JDR2 0x40
45#define STM32F4_ADC_JDR3 0x44
46#define STM32F4_ADC_JDR4 0x48
47#define STM32F4_ADC_DR 0x4C
48
49/* STM32F4_ADC_SR - bit fields */
50#define STM32F4_STRT BIT(4)
51#define STM32F4_EOC BIT(1)
52
53/* STM32F4_ADC_CR1 - bit fields */
54#define STM32F4_RES_SHIFT 24
55#define STM32F4_RES_MASK GENMASK(25, 24)
56#define STM32F4_SCAN BIT(8)
57#define STM32F4_EOCIE BIT(5)
58
59/* STM32F4_ADC_CR2 - bit fields */
60#define STM32F4_SWSTART BIT(30)
61#define STM32F4_EXTEN_SHIFT 28
62#define STM32F4_EXTEN_MASK GENMASK(29, 28)
63#define STM32F4_EXTSEL_SHIFT 24
64#define STM32F4_EXTSEL_MASK GENMASK(27, 24)
65#define STM32F4_EOCS BIT(10)
66#define STM32F4_DDS BIT(9)
67#define STM32F4_DMA BIT(8)
68#define STM32F4_ADON BIT(0)
69
70/* STM32H7 - Registers for each ADC instance */
71#define STM32H7_ADC_ISR 0x00
72#define STM32H7_ADC_IER 0x04
73#define STM32H7_ADC_CR 0x08
74#define STM32H7_ADC_CFGR 0x0C
75#define STM32H7_ADC_SMPR1 0x14
76#define STM32H7_ADC_SMPR2 0x18
77#define STM32H7_ADC_PCSEL 0x1C
78#define STM32H7_ADC_SQR1 0x30
79#define STM32H7_ADC_SQR2 0x34
80#define STM32H7_ADC_SQR3 0x38
81#define STM32H7_ADC_SQR4 0x3C
82#define STM32H7_ADC_DR 0x40
83#define STM32H7_ADC_DIFSEL 0xC0
84#define STM32H7_ADC_CALFACT 0xC4
85#define STM32H7_ADC_CALFACT2 0xC8
86
87/* STM32H7_ADC_ISR - bit fields */
88#define STM32MP1_VREGREADY BIT(12)
89#define STM32H7_EOC BIT(2)
90#define STM32H7_ADRDY BIT(0)
91
92/* STM32H7_ADC_IER - bit fields */
93#define STM32H7_EOCIE STM32H7_EOC
94
95/* STM32H7_ADC_CR - bit fields */
96#define STM32H7_ADCAL BIT(31)
97#define STM32H7_ADCALDIF BIT(30)
98#define STM32H7_DEEPPWD BIT(29)
99#define STM32H7_ADVREGEN BIT(28)
100#define STM32H7_LINCALRDYW6 BIT(27)
101#define STM32H7_LINCALRDYW5 BIT(26)
102#define STM32H7_LINCALRDYW4 BIT(25)
103#define STM32H7_LINCALRDYW3 BIT(24)
104#define STM32H7_LINCALRDYW2 BIT(23)
105#define STM32H7_LINCALRDYW1 BIT(22)
106#define STM32H7_ADCALLIN BIT(16)
107#define STM32H7_BOOST BIT(8)
108#define STM32H7_ADSTP BIT(4)
109#define STM32H7_ADSTART BIT(2)
110#define STM32H7_ADDIS BIT(1)
111#define STM32H7_ADEN BIT(0)
112
113/* STM32H7_ADC_CFGR bit fields */
114#define STM32H7_EXTEN_SHIFT 10
115#define STM32H7_EXTEN_MASK GENMASK(11, 10)
116#define STM32H7_EXTSEL_SHIFT 5
117#define STM32H7_EXTSEL_MASK GENMASK(9, 5)
118#define STM32H7_RES_SHIFT 2
119#define STM32H7_RES_MASK GENMASK(4, 2)
120#define STM32H7_DMNGT_SHIFT 0
121#define STM32H7_DMNGT_MASK GENMASK(1, 0)
122
123enum stm32h7_adc_dmngt {
124 STM32H7_DMNGT_DR_ONLY, /* Regular data in DR only */
125 STM32H7_DMNGT_DMA_ONESHOT, /* DMA one shot mode */
126 STM32H7_DMNGT_DFSDM, /* DFSDM mode */
127 STM32H7_DMNGT_DMA_CIRC, /* DMA circular mode */
128};
129
130/* STM32H7_ADC_CALFACT - bit fields */
131#define STM32H7_CALFACT_D_SHIFT 16
132#define STM32H7_CALFACT_D_MASK GENMASK(26, 16)
133#define STM32H7_CALFACT_S_SHIFT 0
134#define STM32H7_CALFACT_S_MASK GENMASK(10, 0)
135
136/* STM32H7_ADC_CALFACT2 - bit fields */
137#define STM32H7_LINCALFACT_SHIFT 0
138#define STM32H7_LINCALFACT_MASK GENMASK(29, 0)
139
140/* Number of linear calibration shadow registers / LINCALRDYW control bits */ 31/* Number of linear calibration shadow registers / LINCALRDYW control bits */
141#define STM32H7_LINCALFACT_NUM 6 32#define STM32H7_LINCALFACT_NUM 6
142 33
diff --git a/drivers/iio/imu/adis_buffer.c b/drivers/iio/imu/adis_buffer.c
index 9ac8356d9a95..4998a89d083d 100644
--- a/drivers/iio/imu/adis_buffer.c
+++ b/drivers/iio/imu/adis_buffer.c
@@ -35,8 +35,11 @@ static int adis_update_scan_mode_burst(struct iio_dev *indio_dev,
35 return -ENOMEM; 35 return -ENOMEM;
36 36
37 adis->buffer = kzalloc(burst_length + sizeof(u16), GFP_KERNEL); 37 adis->buffer = kzalloc(burst_length + sizeof(u16), GFP_KERNEL);
38 if (!adis->buffer) 38 if (!adis->buffer) {
39 kfree(adis->xfer);
40 adis->xfer = NULL;
39 return -ENOMEM; 41 return -ENOMEM;
42 }
40 43
41 tx = adis->buffer + burst_length; 44 tx = adis->buffer + burst_length;
42 tx[0] = ADIS_READ_REG(adis->burst->reg_cmd); 45 tx[0] = ADIS_READ_REG(adis->burst->reg_cmd);
@@ -78,8 +81,11 @@ int adis_update_scan_mode(struct iio_dev *indio_dev,
78 return -ENOMEM; 81 return -ENOMEM;
79 82
80 adis->buffer = kcalloc(indio_dev->scan_bytes, 2, GFP_KERNEL); 83 adis->buffer = kcalloc(indio_dev->scan_bytes, 2, GFP_KERNEL);
81 if (!adis->buffer) 84 if (!adis->buffer) {
85 kfree(adis->xfer);
86 adis->xfer = NULL;
82 return -ENOMEM; 87 return -ENOMEM;
88 }
83 89
84 rx = adis->buffer; 90 rx = adis->buffer;
85 tx = rx + scan_count; 91 tx = rx + scan_count;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index 80e42c7dbcbe..0fe6999b8257 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -99,7 +99,9 @@ struct st_lsm6dsx_fs {
99#define ST_LSM6DSX_FS_LIST_SIZE 4 99#define ST_LSM6DSX_FS_LIST_SIZE 4
100struct st_lsm6dsx_fs_table_entry { 100struct st_lsm6dsx_fs_table_entry {
101 struct st_lsm6dsx_reg reg; 101 struct st_lsm6dsx_reg reg;
102
102 struct st_lsm6dsx_fs fs_avl[ST_LSM6DSX_FS_LIST_SIZE]; 103 struct st_lsm6dsx_fs fs_avl[ST_LSM6DSX_FS_LIST_SIZE];
104 int fs_len;
103}; 105};
104 106
105/** 107/**
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 2d3495560136..fd5ebe1e1594 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -145,6 +145,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
145 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, 145 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
146 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, 146 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
147 .fs_avl[3] = { IIO_G_TO_M_S_2(732), 0x1 }, 147 .fs_avl[3] = { IIO_G_TO_M_S_2(732), 0x1 },
148 .fs_len = 4,
148 }, 149 },
149 [ST_LSM6DSX_ID_GYRO] = { 150 [ST_LSM6DSX_ID_GYRO] = {
150 .reg = { 151 .reg = {
@@ -154,6 +155,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
154 .fs_avl[0] = { IIO_DEGREE_TO_RAD(245), 0x0 }, 155 .fs_avl[0] = { IIO_DEGREE_TO_RAD(245), 0x0 },
155 .fs_avl[1] = { IIO_DEGREE_TO_RAD(500), 0x1 }, 156 .fs_avl[1] = { IIO_DEGREE_TO_RAD(500), 0x1 },
156 .fs_avl[2] = { IIO_DEGREE_TO_RAD(2000), 0x3 }, 157 .fs_avl[2] = { IIO_DEGREE_TO_RAD(2000), 0x3 },
158 .fs_len = 3,
157 }, 159 },
158 }, 160 },
159 }, 161 },
@@ -215,6 +217,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
215 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, 217 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
216 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, 218 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
217 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, 219 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
220 .fs_len = 4,
218 }, 221 },
219 [ST_LSM6DSX_ID_GYRO] = { 222 [ST_LSM6DSX_ID_GYRO] = {
220 .reg = { 223 .reg = {
@@ -225,6 +228,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
225 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, 228 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
226 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, 229 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
227 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, 230 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
231 .fs_len = 4,
228 }, 232 },
229 }, 233 },
230 .decimator = { 234 .decimator = {
@@ -327,6 +331,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
327 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, 331 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
328 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, 332 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
329 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, 333 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
334 .fs_len = 4,
330 }, 335 },
331 [ST_LSM6DSX_ID_GYRO] = { 336 [ST_LSM6DSX_ID_GYRO] = {
332 .reg = { 337 .reg = {
@@ -337,6 +342,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
337 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, 342 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
338 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, 343 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
339 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, 344 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
345 .fs_len = 4,
340 }, 346 },
341 }, 347 },
342 .decimator = { 348 .decimator = {
@@ -448,6 +454,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
448 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, 454 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
449 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, 455 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
450 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, 456 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
457 .fs_len = 4,
451 }, 458 },
452 [ST_LSM6DSX_ID_GYRO] = { 459 [ST_LSM6DSX_ID_GYRO] = {
453 .reg = { 460 .reg = {
@@ -458,6 +465,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
458 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, 465 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
459 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, 466 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
460 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, 467 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
468 .fs_len = 4,
461 }, 469 },
462 }, 470 },
463 .decimator = { 471 .decimator = {
@@ -563,6 +571,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
563 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, 571 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
564 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, 572 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
565 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, 573 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
574 .fs_len = 4,
566 }, 575 },
567 [ST_LSM6DSX_ID_GYRO] = { 576 [ST_LSM6DSX_ID_GYRO] = {
568 .reg = { 577 .reg = {
@@ -573,6 +582,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
573 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, 582 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
574 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, 583 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
575 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, 584 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
585 .fs_len = 4,
576 }, 586 },
577 }, 587 },
578 .batch = { 588 .batch = {
@@ -693,6 +703,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
693 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, 703 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
694 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, 704 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
695 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, 705 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
706 .fs_len = 4,
696 }, 707 },
697 [ST_LSM6DSX_ID_GYRO] = { 708 [ST_LSM6DSX_ID_GYRO] = {
698 .reg = { 709 .reg = {
@@ -703,6 +714,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
703 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, 714 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
704 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, 715 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
705 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, 716 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
717 .fs_len = 4,
706 }, 718 },
707 }, 719 },
708 .batch = { 720 .batch = {
@@ -800,6 +812,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
800 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, 812 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
801 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, 813 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
802 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, 814 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
815 .fs_len = 4,
803 }, 816 },
804 [ST_LSM6DSX_ID_GYRO] = { 817 [ST_LSM6DSX_ID_GYRO] = {
805 .reg = { 818 .reg = {
@@ -810,6 +823,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
810 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 }, 823 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
811 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 }, 824 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
812 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 }, 825 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
826 .fs_len = 4,
813 }, 827 },
814 }, 828 },
815 .batch = { 829 .batch = {
@@ -933,11 +947,12 @@ static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor,
933 int i, err; 947 int i, err;
934 948
935 fs_table = &sensor->hw->settings->fs_table[sensor->id]; 949 fs_table = &sensor->hw->settings->fs_table[sensor->id];
936 for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++) 950 for (i = 0; i < fs_table->fs_len; i++) {
937 if (fs_table->fs_avl[i].gain == gain) 951 if (fs_table->fs_avl[i].gain == gain)
938 break; 952 break;
953 }
939 954
940 if (i == ST_LSM6DSX_FS_LIST_SIZE) 955 if (i == fs_table->fs_len)
941 return -EINVAL; 956 return -EINVAL;
942 957
943 data = ST_LSM6DSX_SHIFT_VAL(fs_table->fs_avl[i].val, 958 data = ST_LSM6DSX_SHIFT_VAL(fs_table->fs_avl[i].val,
@@ -1196,18 +1211,13 @@ static ssize_t st_lsm6dsx_sysfs_scale_avail(struct device *dev,
1196{ 1211{
1197 struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev)); 1212 struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev));
1198 const struct st_lsm6dsx_fs_table_entry *fs_table; 1213 const struct st_lsm6dsx_fs_table_entry *fs_table;
1199 enum st_lsm6dsx_sensor_id id = sensor->id;
1200 struct st_lsm6dsx_hw *hw = sensor->hw; 1214 struct st_lsm6dsx_hw *hw = sensor->hw;
1201 int i, len = 0; 1215 int i, len = 0;
1202 1216
1203 fs_table = &hw->settings->fs_table[id]; 1217 fs_table = &hw->settings->fs_table[sensor->id];
1204 for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++) { 1218 for (i = 0; i < fs_table->fs_len; i++)
1205 if (!fs_table->fs_avl[i].gain)
1206 break;
1207
1208 len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ", 1219 len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
1209 fs_table->fs_avl[i].gain); 1220 fs_table->fs_avl[i].gain);
1210 }
1211 buf[len - 1] = '\n'; 1221 buf[len - 1] = '\n';
1212 1222
1213 return len; 1223 return len;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
index 66fbcd94642d..ea472cf6db7b 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
@@ -61,6 +61,7 @@ static const struct st_lsm6dsx_ext_dev_settings st_lsm6dsx_ext_dev_table[] = {
61 .gain = 1500, 61 .gain = 1500,
62 .val = 0x0, 62 .val = 0x0,
63 }, /* 1500 uG/LSB */ 63 }, /* 1500 uG/LSB */
64 .fs_len = 1,
64 }, 65 },
65 .temp_comp = { 66 .temp_comp = {
66 .addr = 0x60, 67 .addr = 0x60,
@@ -92,9 +93,11 @@ static const struct st_lsm6dsx_ext_dev_settings st_lsm6dsx_ext_dev_table[] = {
92static void st_lsm6dsx_shub_wait_complete(struct st_lsm6dsx_hw *hw) 93static void st_lsm6dsx_shub_wait_complete(struct st_lsm6dsx_hw *hw)
93{ 94{
94 struct st_lsm6dsx_sensor *sensor; 95 struct st_lsm6dsx_sensor *sensor;
96 u16 odr;
95 97
96 sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]); 98 sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
97 msleep((2000U / sensor->odr) + 1); 99 odr = (hw->enable_mask & BIT(ST_LSM6DSX_ID_ACC)) ? sensor->odr : 13;
100 msleep((2000U / odr) + 1);
98} 101}
99 102
100/** 103/**
@@ -555,13 +558,9 @@ static ssize_t st_lsm6dsx_shub_scale_avail(struct device *dev,
555 int i, len = 0; 558 int i, len = 0;
556 559
557 settings = sensor->ext_info.settings; 560 settings = sensor->ext_info.settings;
558 for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++) { 561 for (i = 0; i < settings->fs_table.fs_len; i++)
559 u16 val = settings->fs_table.fs_avl[i].gain; 562 len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
560 563 settings->fs_table.fs_avl[i].gain);
561 if (val > 0)
562 len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
563 val);
564 }
565 buf[len - 1] = '\n'; 564 buf[len - 1] = '\n';
566 565
567 return len; 566 return len;
diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
index 08d7e1ef2186..4a1a883dc061 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -314,6 +314,7 @@ config MAX44009
314config NOA1305 314config NOA1305
315 tristate "ON Semiconductor NOA1305 ambient light sensor" 315 tristate "ON Semiconductor NOA1305 ambient light sensor"
316 depends on I2C 316 depends on I2C
317 select REGMAP_I2C
317 help 318 help
318 Say Y here if you want to build support for the ON Semiconductor 319 Say Y here if you want to build support for the ON Semiconductor
319 NOA1305 ambient light sensor. 320 NOA1305 ambient light sensor.
diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
index e666879007d2..92004a2563ea 100644
--- a/drivers/iio/light/opt3001.c
+++ b/drivers/iio/light/opt3001.c
@@ -686,6 +686,7 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
686 struct iio_dev *iio = _iio; 686 struct iio_dev *iio = _iio;
687 struct opt3001 *opt = iio_priv(iio); 687 struct opt3001 *opt = iio_priv(iio);
688 int ret; 688 int ret;
689 bool wake_result_ready_queue = false;
689 690
690 if (!opt->ok_to_ignore_lock) 691 if (!opt->ok_to_ignore_lock)
691 mutex_lock(&opt->lock); 692 mutex_lock(&opt->lock);
@@ -720,13 +721,16 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
720 } 721 }
721 opt->result = ret; 722 opt->result = ret;
722 opt->result_ready = true; 723 opt->result_ready = true;
723 wake_up(&opt->result_ready_queue); 724 wake_result_ready_queue = true;
724 } 725 }
725 726
726out: 727out:
727 if (!opt->ok_to_ignore_lock) 728 if (!opt->ok_to_ignore_lock)
728 mutex_unlock(&opt->lock); 729 mutex_unlock(&opt->lock);
729 730
731 if (wake_result_ready_queue)
732 wake_up(&opt->result_ready_queue);
733
730 return IRQ_HANDLED; 734 return IRQ_HANDLED;
731} 735}
732 736
diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
index 51421ac32517..16dacea9eadf 100644
--- a/drivers/iio/light/vcnl4000.c
+++ b/drivers/iio/light/vcnl4000.c
@@ -398,19 +398,23 @@ static int vcnl4000_probe(struct i2c_client *client,
398static const struct of_device_id vcnl_4000_of_match[] = { 398static const struct of_device_id vcnl_4000_of_match[] = {
399 { 399 {
400 .compatible = "vishay,vcnl4000", 400 .compatible = "vishay,vcnl4000",
401 .data = "VCNL4000", 401 .data = (void *)VCNL4000,
402 }, 402 },
403 { 403 {
404 .compatible = "vishay,vcnl4010", 404 .compatible = "vishay,vcnl4010",
405 .data = "VCNL4010", 405 .data = (void *)VCNL4010,
406 }, 406 },
407 { 407 {
408 .compatible = "vishay,vcnl4010", 408 .compatible = "vishay,vcnl4020",
409 .data = "VCNL4020", 409 .data = (void *)VCNL4010,
410 },
411 {
412 .compatible = "vishay,vcnl4040",
413 .data = (void *)VCNL4040,
410 }, 414 },
411 { 415 {
412 .compatible = "vishay,vcnl4200", 416 .compatible = "vishay,vcnl4200",
413 .data = "VCNL4200", 417 .data = (void *)VCNL4200,
414 }, 418 },
415 {}, 419 {},
416}; 420};
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index da10e6ccb43c..5920c0085d35 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -4399,6 +4399,7 @@ error2:
4399error1: 4399error1:
4400 port_modify.set_port_cap_mask = 0; 4400 port_modify.set_port_cap_mask = 0;
4401 port_modify.clr_port_cap_mask = IB_PORT_CM_SUP; 4401 port_modify.clr_port_cap_mask = IB_PORT_CM_SUP;
4402 kfree(port);
4402 while (--i) { 4403 while (--i) {
4403 if (!rdma_cap_ib_cm(ib_device, i)) 4404 if (!rdma_cap_ib_cm(ib_device, i))
4404 continue; 4405 continue;
@@ -4407,6 +4408,7 @@ error1:
4407 ib_modify_port(ib_device, port->port_num, 0, &port_modify); 4408 ib_modify_port(ib_device, port->port_num, 0, &port_modify);
4408 ib_unregister_mad_agent(port->mad_agent); 4409 ib_unregister_mad_agent(port->mad_agent);
4409 cm_remove_port_fs(port); 4410 cm_remove_port_fs(port);
4411 kfree(port);
4410 } 4412 }
4411free: 4413free:
4412 kfree(cm_dev); 4414 kfree(cm_dev);
@@ -4460,6 +4462,7 @@ static void cm_remove_one(struct ib_device *ib_device, void *client_data)
4460 spin_unlock_irq(&cm.state_lock); 4462 spin_unlock_irq(&cm.state_lock);
4461 ib_unregister_mad_agent(cur_mad_agent); 4463 ib_unregister_mad_agent(cur_mad_agent);
4462 cm_remove_port_fs(port); 4464 cm_remove_port_fs(port);
4465 kfree(port);
4463 } 4466 }
4464 4467
4465 kfree(cm_dev); 4468 kfree(cm_dev);
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index 0e3cf3461999..d78f67623f24 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -2396,9 +2396,10 @@ static int iw_conn_req_handler(struct iw_cm_id *cm_id,
2396 conn_id->cm_id.iw = NULL; 2396 conn_id->cm_id.iw = NULL;
2397 cma_exch(conn_id, RDMA_CM_DESTROYING); 2397 cma_exch(conn_id, RDMA_CM_DESTROYING);
2398 mutex_unlock(&conn_id->handler_mutex); 2398 mutex_unlock(&conn_id->handler_mutex);
2399 mutex_unlock(&listen_id->handler_mutex);
2399 cma_deref_id(conn_id); 2400 cma_deref_id(conn_id);
2400 rdma_destroy_id(&conn_id->id); 2401 rdma_destroy_id(&conn_id->id);
2401 goto out; 2402 return ret;
2402 } 2403 }
2403 2404
2404 mutex_unlock(&conn_id->handler_mutex); 2405 mutex_unlock(&conn_id->handler_mutex);
diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index 99c4a55545cf..2dd2cfe9b561 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -1987,8 +1987,6 @@ static int iw_query_port(struct ib_device *device,
1987 if (!netdev) 1987 if (!netdev)
1988 return -ENODEV; 1988 return -ENODEV;
1989 1989
1990 dev_put(netdev);
1991
1992 port_attr->max_mtu = IB_MTU_4096; 1990 port_attr->max_mtu = IB_MTU_4096;
1993 port_attr->active_mtu = ib_mtu_int_to_enum(netdev->mtu); 1991 port_attr->active_mtu = ib_mtu_int_to_enum(netdev->mtu);
1994 1992
@@ -1996,19 +1994,22 @@ static int iw_query_port(struct ib_device *device,
1996 port_attr->state = IB_PORT_DOWN; 1994 port_attr->state = IB_PORT_DOWN;
1997 port_attr->phys_state = IB_PORT_PHYS_STATE_DISABLED; 1995 port_attr->phys_state = IB_PORT_PHYS_STATE_DISABLED;
1998 } else { 1996 } else {
1999 inetdev = in_dev_get(netdev); 1997 rcu_read_lock();
1998 inetdev = __in_dev_get_rcu(netdev);
2000 1999
2001 if (inetdev && inetdev->ifa_list) { 2000 if (inetdev && inetdev->ifa_list) {
2002 port_attr->state = IB_PORT_ACTIVE; 2001 port_attr->state = IB_PORT_ACTIVE;
2003 port_attr->phys_state = IB_PORT_PHYS_STATE_LINK_UP; 2002 port_attr->phys_state = IB_PORT_PHYS_STATE_LINK_UP;
2004 in_dev_put(inetdev);
2005 } else { 2003 } else {
2006 port_attr->state = IB_PORT_INIT; 2004 port_attr->state = IB_PORT_INIT;
2007 port_attr->phys_state = 2005 port_attr->phys_state =
2008 IB_PORT_PHYS_STATE_PORT_CONFIGURATION_TRAINING; 2006 IB_PORT_PHYS_STATE_PORT_CONFIGURATION_TRAINING;
2009 } 2007 }
2008
2009 rcu_read_unlock();
2010 } 2010 }
2011 2011
2012 dev_put(netdev);
2012 err = device->ops.query_port(device, port_num, port_attr); 2013 err = device->ops.query_port(device, port_num, port_attr);
2013 if (err) 2014 if (err)
2014 return err; 2015 return err;
diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
index 7a7474000100..65b36548bc17 100644
--- a/drivers/infiniband/core/nldev.c
+++ b/drivers/infiniband/core/nldev.c
@@ -1230,7 +1230,7 @@ static int res_get_common_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
1230 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 1230 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1231 if (!msg) { 1231 if (!msg) {
1232 ret = -ENOMEM; 1232 ret = -ENOMEM;
1233 goto err; 1233 goto err_get;
1234 } 1234 }
1235 1235
1236 nlh = nlmsg_put(msg, NETLINK_CB(skb).portid, nlh->nlmsg_seq, 1236 nlh = nlmsg_put(msg, NETLINK_CB(skb).portid, nlh->nlmsg_seq,
@@ -1787,10 +1787,6 @@ static int nldev_stat_del_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
1787 1787
1788 cntn = nla_get_u32(tb[RDMA_NLDEV_ATTR_STAT_COUNTER_ID]); 1788 cntn = nla_get_u32(tb[RDMA_NLDEV_ATTR_STAT_COUNTER_ID]);
1789 qpn = nla_get_u32(tb[RDMA_NLDEV_ATTR_RES_LQPN]); 1789 qpn = nla_get_u32(tb[RDMA_NLDEV_ATTR_RES_LQPN]);
1790 ret = rdma_counter_unbind_qpn(device, port, qpn, cntn);
1791 if (ret)
1792 goto err_unbind;
1793
1794 if (fill_nldev_handle(msg, device) || 1790 if (fill_nldev_handle(msg, device) ||
1795 nla_put_u32(msg, RDMA_NLDEV_ATTR_PORT_INDEX, port) || 1791 nla_put_u32(msg, RDMA_NLDEV_ATTR_PORT_INDEX, port) ||
1796 nla_put_u32(msg, RDMA_NLDEV_ATTR_STAT_COUNTER_ID, cntn) || 1792 nla_put_u32(msg, RDMA_NLDEV_ATTR_STAT_COUNTER_ID, cntn) ||
@@ -1799,13 +1795,15 @@ static int nldev_stat_del_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
1799 goto err_fill; 1795 goto err_fill;
1800 } 1796 }
1801 1797
1798 ret = rdma_counter_unbind_qpn(device, port, qpn, cntn);
1799 if (ret)
1800 goto err_fill;
1801
1802 nlmsg_end(msg, nlh); 1802 nlmsg_end(msg, nlh);
1803 ib_device_put(device); 1803 ib_device_put(device);
1804 return rdma_nl_unicast(sock_net(skb->sk), msg, NETLINK_CB(skb).portid); 1804 return rdma_nl_unicast(sock_net(skb->sk), msg, NETLINK_CB(skb).portid);
1805 1805
1806err_fill: 1806err_fill:
1807 rdma_counter_bind_qpn(device, port, qpn, cntn);
1808err_unbind:
1809 nlmsg_free(msg); 1807 nlmsg_free(msg);
1810err: 1808err:
1811 ib_device_put(device); 1809 ib_device_put(device);
diff --git a/drivers/infiniband/core/security.c b/drivers/infiniband/core/security.c
index 1ab423b19f77..6eb6d2717ca5 100644
--- a/drivers/infiniband/core/security.c
+++ b/drivers/infiniband/core/security.c
@@ -426,7 +426,7 @@ int ib_create_qp_security(struct ib_qp *qp, struct ib_device *dev)
426 int ret; 426 int ret;
427 427
428 rdma_for_each_port (dev, i) { 428 rdma_for_each_port (dev, i) {
429 is_ib = rdma_protocol_ib(dev, i++); 429 is_ib = rdma_protocol_ib(dev, i);
430 if (is_ib) 430 if (is_ib)
431 break; 431 break;
432 } 432 }
diff --git a/drivers/infiniband/core/umem_odp.c b/drivers/infiniband/core/umem_odp.c
index f67a30fda1ed..163ff7ba92b7 100644
--- a/drivers/infiniband/core/umem_odp.c
+++ b/drivers/infiniband/core/umem_odp.c
@@ -451,8 +451,10 @@ void ib_umem_odp_release(struct ib_umem_odp *umem_odp)
451 * that the hardware will not attempt to access the MR any more. 451 * that the hardware will not attempt to access the MR any more.
452 */ 452 */
453 if (!umem_odp->is_implicit_odp) { 453 if (!umem_odp->is_implicit_odp) {
454 mutex_lock(&umem_odp->umem_mutex);
454 ib_umem_odp_unmap_dma_pages(umem_odp, ib_umem_start(umem_odp), 455 ib_umem_odp_unmap_dma_pages(umem_odp, ib_umem_start(umem_odp),
455 ib_umem_end(umem_odp)); 456 ib_umem_end(umem_odp));
457 mutex_unlock(&umem_odp->umem_mutex);
456 kvfree(umem_odp->dma_list); 458 kvfree(umem_odp->dma_list);
457 kvfree(umem_odp->page_list); 459 kvfree(umem_odp->page_list);
458 } 460 }
@@ -719,6 +721,8 @@ void ib_umem_odp_unmap_dma_pages(struct ib_umem_odp *umem_odp, u64 virt,
719 u64 addr; 721 u64 addr;
720 struct ib_device *dev = umem_odp->umem.ibdev; 722 struct ib_device *dev = umem_odp->umem.ibdev;
721 723
724 lockdep_assert_held(&umem_odp->umem_mutex);
725
722 virt = max_t(u64, virt, ib_umem_start(umem_odp)); 726 virt = max_t(u64, virt, ib_umem_start(umem_odp));
723 bound = min_t(u64, bound, ib_umem_end(umem_odp)); 727 bound = min_t(u64, bound, ib_umem_end(umem_odp));
724 /* Note that during the run of this function, the 728 /* Note that during the run of this function, the
@@ -726,7 +730,6 @@ void ib_umem_odp_unmap_dma_pages(struct ib_umem_odp *umem_odp, u64 virt,
726 * faults from completion. We might be racing with other 730 * faults from completion. We might be racing with other
727 * invalidations, so we must make sure we free each page only 731 * invalidations, so we must make sure we free each page only
728 * once. */ 732 * once. */
729 mutex_lock(&umem_odp->umem_mutex);
730 for (addr = virt; addr < bound; addr += BIT(umem_odp->page_shift)) { 733 for (addr = virt; addr < bound; addr += BIT(umem_odp->page_shift)) {
731 idx = (addr - ib_umem_start(umem_odp)) >> umem_odp->page_shift; 734 idx = (addr - ib_umem_start(umem_odp)) >> umem_odp->page_shift;
732 if (umem_odp->page_list[idx]) { 735 if (umem_odp->page_list[idx]) {
@@ -757,7 +760,6 @@ void ib_umem_odp_unmap_dma_pages(struct ib_umem_odp *umem_odp, u64 virt,
757 umem_odp->npages--; 760 umem_odp->npages--;
758 } 761 }
759 } 762 }
760 mutex_unlock(&umem_odp->umem_mutex);
761} 763}
762EXPORT_SYMBOL(ib_umem_odp_unmap_dma_pages); 764EXPORT_SYMBOL(ib_umem_odp_unmap_dma_pages);
763 765
diff --git a/drivers/infiniband/hw/cxgb4/device.c b/drivers/infiniband/hw/cxgb4/device.c
index a8b9548bd1a2..599340c1f0b8 100644
--- a/drivers/infiniband/hw/cxgb4/device.c
+++ b/drivers/infiniband/hw/cxgb4/device.c
@@ -242,10 +242,13 @@ static void set_ep_sin6_addrs(struct c4iw_ep *ep,
242 } 242 }
243} 243}
244 244
245static int dump_qp(struct c4iw_qp *qp, struct c4iw_debugfs_data *qpd) 245static int dump_qp(unsigned long id, struct c4iw_qp *qp,
246 struct c4iw_debugfs_data *qpd)
246{ 247{
247 int space; 248 int space;
248 int cc; 249 int cc;
250 if (id != qp->wq.sq.qid)
251 return 0;
249 252
250 space = qpd->bufsize - qpd->pos - 1; 253 space = qpd->bufsize - qpd->pos - 1;
251 if (space == 0) 254 if (space == 0)
@@ -350,7 +353,7 @@ static int qp_open(struct inode *inode, struct file *file)
350 353
351 xa_lock_irq(&qpd->devp->qps); 354 xa_lock_irq(&qpd->devp->qps);
352 xa_for_each(&qpd->devp->qps, index, qp) 355 xa_for_each(&qpd->devp->qps, index, qp)
353 dump_qp(qp, qpd); 356 dump_qp(index, qp, qpd);
354 xa_unlock_irq(&qpd->devp->qps); 357 xa_unlock_irq(&qpd->devp->qps);
355 358
356 qpd->buf[qpd->pos++] = 0; 359 qpd->buf[qpd->pos++] = 0;
diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
index aa772ee0706f..35c284af574d 100644
--- a/drivers/infiniband/hw/cxgb4/mem.c
+++ b/drivers/infiniband/hw/cxgb4/mem.c
@@ -275,13 +275,17 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
275 struct sk_buff *skb, struct c4iw_wr_wait *wr_waitp) 275 struct sk_buff *skb, struct c4iw_wr_wait *wr_waitp)
276{ 276{
277 int err; 277 int err;
278 struct fw_ri_tpte tpt; 278 struct fw_ri_tpte *tpt;
279 u32 stag_idx; 279 u32 stag_idx;
280 static atomic_t key; 280 static atomic_t key;
281 281
282 if (c4iw_fatal_error(rdev)) 282 if (c4iw_fatal_error(rdev))
283 return -EIO; 283 return -EIO;
284 284
285 tpt = kmalloc(sizeof(*tpt), GFP_KERNEL);
286 if (!tpt)
287 return -ENOMEM;
288
285 stag_state = stag_state > 0; 289 stag_state = stag_state > 0;
286 stag_idx = (*stag) >> 8; 290 stag_idx = (*stag) >> 8;
287 291
@@ -291,6 +295,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
291 mutex_lock(&rdev->stats.lock); 295 mutex_lock(&rdev->stats.lock);
292 rdev->stats.stag.fail++; 296 rdev->stats.stag.fail++;
293 mutex_unlock(&rdev->stats.lock); 297 mutex_unlock(&rdev->stats.lock);
298 kfree(tpt);
294 return -ENOMEM; 299 return -ENOMEM;
295 } 300 }
296 mutex_lock(&rdev->stats.lock); 301 mutex_lock(&rdev->stats.lock);
@@ -305,28 +310,28 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
305 310
306 /* write TPT entry */ 311 /* write TPT entry */
307 if (reset_tpt_entry) 312 if (reset_tpt_entry)
308 memset(&tpt, 0, sizeof(tpt)); 313 memset(tpt, 0, sizeof(*tpt));
309 else { 314 else {
310 tpt.valid_to_pdid = cpu_to_be32(FW_RI_TPTE_VALID_F | 315 tpt->valid_to_pdid = cpu_to_be32(FW_RI_TPTE_VALID_F |
311 FW_RI_TPTE_STAGKEY_V((*stag & FW_RI_TPTE_STAGKEY_M)) | 316 FW_RI_TPTE_STAGKEY_V((*stag & FW_RI_TPTE_STAGKEY_M)) |
312 FW_RI_TPTE_STAGSTATE_V(stag_state) | 317 FW_RI_TPTE_STAGSTATE_V(stag_state) |
313 FW_RI_TPTE_STAGTYPE_V(type) | FW_RI_TPTE_PDID_V(pdid)); 318 FW_RI_TPTE_STAGTYPE_V(type) | FW_RI_TPTE_PDID_V(pdid));
314 tpt.locread_to_qpid = cpu_to_be32(FW_RI_TPTE_PERM_V(perm) | 319 tpt->locread_to_qpid = cpu_to_be32(FW_RI_TPTE_PERM_V(perm) |
315 (bind_enabled ? FW_RI_TPTE_MWBINDEN_F : 0) | 320 (bind_enabled ? FW_RI_TPTE_MWBINDEN_F : 0) |
316 FW_RI_TPTE_ADDRTYPE_V((zbva ? FW_RI_ZERO_BASED_TO : 321 FW_RI_TPTE_ADDRTYPE_V((zbva ? FW_RI_ZERO_BASED_TO :
317 FW_RI_VA_BASED_TO))| 322 FW_RI_VA_BASED_TO))|
318 FW_RI_TPTE_PS_V(page_size)); 323 FW_RI_TPTE_PS_V(page_size));
319 tpt.nosnoop_pbladdr = !pbl_size ? 0 : cpu_to_be32( 324 tpt->nosnoop_pbladdr = !pbl_size ? 0 : cpu_to_be32(
320 FW_RI_TPTE_PBLADDR_V(PBL_OFF(rdev, pbl_addr)>>3)); 325 FW_RI_TPTE_PBLADDR_V(PBL_OFF(rdev, pbl_addr)>>3));
321 tpt.len_lo = cpu_to_be32((u32)(len & 0xffffffffUL)); 326 tpt->len_lo = cpu_to_be32((u32)(len & 0xffffffffUL));
322 tpt.va_hi = cpu_to_be32((u32)(to >> 32)); 327 tpt->va_hi = cpu_to_be32((u32)(to >> 32));
323 tpt.va_lo_fbo = cpu_to_be32((u32)(to & 0xffffffffUL)); 328 tpt->va_lo_fbo = cpu_to_be32((u32)(to & 0xffffffffUL));
324 tpt.dca_mwbcnt_pstag = cpu_to_be32(0); 329 tpt->dca_mwbcnt_pstag = cpu_to_be32(0);
325 tpt.len_hi = cpu_to_be32((u32)(len >> 32)); 330 tpt->len_hi = cpu_to_be32((u32)(len >> 32));
326 } 331 }
327 err = write_adapter_mem(rdev, stag_idx + 332 err = write_adapter_mem(rdev, stag_idx +
328 (rdev->lldi.vr->stag.start >> 5), 333 (rdev->lldi.vr->stag.start >> 5),
329 sizeof(tpt), &tpt, skb, wr_waitp); 334 sizeof(*tpt), tpt, skb, wr_waitp);
330 335
331 if (reset_tpt_entry) { 336 if (reset_tpt_entry) {
332 c4iw_put_resource(&rdev->resource.tpt_table, stag_idx); 337 c4iw_put_resource(&rdev->resource.tpt_table, stag_idx);
@@ -334,6 +339,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
334 rdev->stats.stag.cur -= 32; 339 rdev->stats.stag.cur -= 32;
335 mutex_unlock(&rdev->stats.lock); 340 mutex_unlock(&rdev->stats.lock);
336 } 341 }
342 kfree(tpt);
337 return err; 343 return err;
338} 344}
339 345
diff --git a/drivers/infiniband/hw/cxgb4/qp.c b/drivers/infiniband/hw/cxgb4/qp.c
index eb9368be28c1..bbcac539777a 100644
--- a/drivers/infiniband/hw/cxgb4/qp.c
+++ b/drivers/infiniband/hw/cxgb4/qp.c
@@ -2737,15 +2737,11 @@ int c4iw_create_srq(struct ib_srq *ib_srq, struct ib_srq_init_attr *attrs,
2737 if (CHELSIO_CHIP_VERSION(rhp->rdev.lldi.adapter_type) > CHELSIO_T6) 2737 if (CHELSIO_CHIP_VERSION(rhp->rdev.lldi.adapter_type) > CHELSIO_T6)
2738 srq->flags = T4_SRQ_LIMIT_SUPPORT; 2738 srq->flags = T4_SRQ_LIMIT_SUPPORT;
2739 2739
2740 ret = xa_insert_irq(&rhp->qps, srq->wq.qid, srq, GFP_KERNEL);
2741 if (ret)
2742 goto err_free_queue;
2743
2744 if (udata) { 2740 if (udata) {
2745 srq_key_mm = kmalloc(sizeof(*srq_key_mm), GFP_KERNEL); 2741 srq_key_mm = kmalloc(sizeof(*srq_key_mm), GFP_KERNEL);
2746 if (!srq_key_mm) { 2742 if (!srq_key_mm) {
2747 ret = -ENOMEM; 2743 ret = -ENOMEM;
2748 goto err_remove_handle; 2744 goto err_free_queue;
2749 } 2745 }
2750 srq_db_key_mm = kmalloc(sizeof(*srq_db_key_mm), GFP_KERNEL); 2746 srq_db_key_mm = kmalloc(sizeof(*srq_db_key_mm), GFP_KERNEL);
2751 if (!srq_db_key_mm) { 2747 if (!srq_db_key_mm) {
@@ -2789,8 +2785,6 @@ err_free_srq_db_key_mm:
2789 kfree(srq_db_key_mm); 2785 kfree(srq_db_key_mm);
2790err_free_srq_key_mm: 2786err_free_srq_key_mm:
2791 kfree(srq_key_mm); 2787 kfree(srq_key_mm);
2792err_remove_handle:
2793 xa_erase_irq(&rhp->qps, srq->wq.qid);
2794err_free_queue: 2788err_free_queue:
2795 free_srq_queue(srq, ucontext ? &ucontext->uctx : &rhp->rdev.uctx, 2789 free_srq_queue(srq, ucontext ? &ucontext->uctx : &rhp->rdev.uctx,
2796 srq->wr_waitp); 2790 srq->wr_waitp);
@@ -2813,8 +2807,6 @@ void c4iw_destroy_srq(struct ib_srq *ibsrq, struct ib_udata *udata)
2813 rhp = srq->rhp; 2807 rhp = srq->rhp;
2814 2808
2815 pr_debug("%s id %d\n", __func__, srq->wq.qid); 2809 pr_debug("%s id %d\n", __func__, srq->wq.qid);
2816
2817 xa_erase_irq(&rhp->qps, srq->wq.qid);
2818 ucontext = rdma_udata_to_drv_context(udata, struct c4iw_ucontext, 2810 ucontext = rdma_udata_to_drv_context(udata, struct c4iw_ucontext,
2819 ibucontext); 2811 ibucontext);
2820 free_srq_queue(srq, ucontext ? &ucontext->uctx : &rhp->rdev.uctx, 2812 free_srq_queue(srq, ucontext ? &ucontext->uctx : &rhp->rdev.uctx,
diff --git a/drivers/infiniband/hw/hfi1/sdma.c b/drivers/infiniband/hw/hfi1/sdma.c
index 2395fd4233a7..2ed7bfd5feea 100644
--- a/drivers/infiniband/hw/hfi1/sdma.c
+++ b/drivers/infiniband/hw/hfi1/sdma.c
@@ -1526,8 +1526,11 @@ int sdma_init(struct hfi1_devdata *dd, u8 port)
1526 } 1526 }
1527 1527
1528 ret = rhashtable_init(tmp_sdma_rht, &sdma_rht_params); 1528 ret = rhashtable_init(tmp_sdma_rht, &sdma_rht_params);
1529 if (ret < 0) 1529 if (ret < 0) {
1530 kfree(tmp_sdma_rht);
1530 goto bail; 1531 goto bail;
1532 }
1533
1531 dd->sdma_rht = tmp_sdma_rht; 1534 dd->sdma_rht = tmp_sdma_rht;
1532 1535
1533 dd_dev_info(dd, "SDMA num_sdma: %u\n", dd->num_sdma); 1536 dd_dev_info(dd, "SDMA num_sdma: %u\n", dd->num_sdma);
diff --git a/drivers/infiniband/hw/i40iw/i40iw_verbs.c b/drivers/infiniband/hw/i40iw/i40iw_verbs.c
index 8056930bbe2c..cd9ee1664a69 100644
--- a/drivers/infiniband/hw/i40iw/i40iw_verbs.c
+++ b/drivers/infiniband/hw/i40iw/i40iw_verbs.c
@@ -2773,6 +2773,10 @@ int i40iw_register_rdma_device(struct i40iw_device *iwdev)
2773 return -ENOMEM; 2773 return -ENOMEM;
2774 iwibdev = iwdev->iwibdev; 2774 iwibdev = iwdev->iwibdev;
2775 rdma_set_device_sysfs_group(&iwibdev->ibdev, &i40iw_attr_group); 2775 rdma_set_device_sysfs_group(&iwibdev->ibdev, &i40iw_attr_group);
2776 ret = ib_device_set_netdev(&iwibdev->ibdev, iwdev->netdev, 1);
2777 if (ret)
2778 goto error;
2779
2776 ret = ib_register_device(&iwibdev->ibdev, "i40iw%d"); 2780 ret = ib_register_device(&iwibdev->ibdev, "i40iw%d");
2777 if (ret) 2781 if (ret)
2778 goto error; 2782 goto error;
diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c
index 59022b744144..d609f4659afb 100644
--- a/drivers/infiniband/hw/mlx5/devx.c
+++ b/drivers/infiniband/hw/mlx5/devx.c
@@ -1298,29 +1298,6 @@ static int devx_handle_mkey_create(struct mlx5_ib_dev *dev,
1298 return 0; 1298 return 0;
1299} 1299}
1300 1300
1301static void devx_free_indirect_mkey(struct rcu_head *rcu)
1302{
1303 kfree(container_of(rcu, struct devx_obj, devx_mr.rcu));
1304}
1305
1306/* This function to delete from the radix tree needs to be called before
1307 * destroying the underlying mkey. Otherwise a race might occur in case that
1308 * other thread will get the same mkey before this one will be deleted,
1309 * in that case it will fail via inserting to the tree its own data.
1310 *
1311 * Note:
1312 * An error in the destroy is not expected unless there is some other indirect
1313 * mkey which points to this one. In a kernel cleanup flow it will be just
1314 * destroyed in the iterative destruction call. In a user flow, in case
1315 * the application didn't close in the expected order it's its own problem,
1316 * the mkey won't be part of the tree, in both cases the kernel is safe.
1317 */
1318static void devx_cleanup_mkey(struct devx_obj *obj)
1319{
1320 xa_erase(&obj->ib_dev->mdev->priv.mkey_table,
1321 mlx5_base_mkey(obj->devx_mr.mmkey.key));
1322}
1323
1324static void devx_cleanup_subscription(struct mlx5_ib_dev *dev, 1301static void devx_cleanup_subscription(struct mlx5_ib_dev *dev,
1325 struct devx_event_subscription *sub) 1302 struct devx_event_subscription *sub)
1326{ 1303{
@@ -1362,8 +1339,16 @@ static int devx_obj_cleanup(struct ib_uobject *uobject,
1362 int ret; 1339 int ret;
1363 1340
1364 dev = mlx5_udata_to_mdev(&attrs->driver_udata); 1341 dev = mlx5_udata_to_mdev(&attrs->driver_udata);
1365 if (obj->flags & DEVX_OBJ_FLAGS_INDIRECT_MKEY) 1342 if (obj->flags & DEVX_OBJ_FLAGS_INDIRECT_MKEY) {
1366 devx_cleanup_mkey(obj); 1343 /*
1344 * The pagefault_single_data_segment() does commands against
1345 * the mmkey, we must wait for that to stop before freeing the
1346 * mkey, as another allocation could get the same mkey #.
1347 */
1348 xa_erase(&obj->ib_dev->mdev->priv.mkey_table,
1349 mlx5_base_mkey(obj->devx_mr.mmkey.key));
1350 synchronize_srcu(&dev->mr_srcu);
1351 }
1367 1352
1368 if (obj->flags & DEVX_OBJ_FLAGS_DCT) 1353 if (obj->flags & DEVX_OBJ_FLAGS_DCT)
1369 ret = mlx5_core_destroy_dct(obj->ib_dev->mdev, &obj->core_dct); 1354 ret = mlx5_core_destroy_dct(obj->ib_dev->mdev, &obj->core_dct);
@@ -1382,12 +1367,6 @@ static int devx_obj_cleanup(struct ib_uobject *uobject,
1382 devx_cleanup_subscription(dev, sub_entry); 1367 devx_cleanup_subscription(dev, sub_entry);
1383 mutex_unlock(&devx_event_table->event_xa_lock); 1368 mutex_unlock(&devx_event_table->event_xa_lock);
1384 1369
1385 if (obj->flags & DEVX_OBJ_FLAGS_INDIRECT_MKEY) {
1386 call_srcu(&dev->mr_srcu, &obj->devx_mr.rcu,
1387 devx_free_indirect_mkey);
1388 return ret;
1389 }
1390
1391 kfree(obj); 1370 kfree(obj);
1392 return ret; 1371 return ret;
1393} 1372}
@@ -1491,26 +1470,21 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_CREATE)(
1491 &obj_id); 1470 &obj_id);
1492 WARN_ON(obj->dinlen > MLX5_MAX_DESTROY_INBOX_SIZE_DW * sizeof(u32)); 1471 WARN_ON(obj->dinlen > MLX5_MAX_DESTROY_INBOX_SIZE_DW * sizeof(u32));
1493 1472
1494 if (obj->flags & DEVX_OBJ_FLAGS_INDIRECT_MKEY) {
1495 err = devx_handle_mkey_indirect(obj, dev, cmd_in, cmd_out);
1496 if (err)
1497 goto obj_destroy;
1498 }
1499
1500 err = uverbs_copy_to(attrs, MLX5_IB_ATTR_DEVX_OBJ_CREATE_CMD_OUT, cmd_out, cmd_out_len); 1473 err = uverbs_copy_to(attrs, MLX5_IB_ATTR_DEVX_OBJ_CREATE_CMD_OUT, cmd_out, cmd_out_len);
1501 if (err) 1474 if (err)
1502 goto err_copy; 1475 goto obj_destroy;
1503 1476
1504 if (opcode == MLX5_CMD_OP_CREATE_GENERAL_OBJECT) 1477 if (opcode == MLX5_CMD_OP_CREATE_GENERAL_OBJECT)
1505 obj_type = MLX5_GET(general_obj_in_cmd_hdr, cmd_in, obj_type); 1478 obj_type = MLX5_GET(general_obj_in_cmd_hdr, cmd_in, obj_type);
1506
1507 obj->obj_id = get_enc_obj_id(opcode | obj_type << 16, obj_id); 1479 obj->obj_id = get_enc_obj_id(opcode | obj_type << 16, obj_id);
1508 1480
1481 if (obj->flags & DEVX_OBJ_FLAGS_INDIRECT_MKEY) {
1482 err = devx_handle_mkey_indirect(obj, dev, cmd_in, cmd_out);
1483 if (err)
1484 goto obj_destroy;
1485 }
1509 return 0; 1486 return 0;
1510 1487
1511err_copy:
1512 if (obj->flags & DEVX_OBJ_FLAGS_INDIRECT_MKEY)
1513 devx_cleanup_mkey(obj);
1514obj_destroy: 1488obj_destroy:
1515 if (obj->flags & DEVX_OBJ_FLAGS_DCT) 1489 if (obj->flags & DEVX_OBJ_FLAGS_DCT)
1516 mlx5_core_destroy_dct(obj->ib_dev->mdev, &obj->core_dct); 1490 mlx5_core_destroy_dct(obj->ib_dev->mdev, &obj->core_dct);
diff --git a/drivers/infiniband/hw/mlx5/mlx5_ib.h b/drivers/infiniband/hw/mlx5/mlx5_ib.h
index 2ceaef3ea3fb..1a98ee2e01c4 100644
--- a/drivers/infiniband/hw/mlx5/mlx5_ib.h
+++ b/drivers/infiniband/hw/mlx5/mlx5_ib.h
@@ -606,7 +606,7 @@ struct mlx5_ib_mr {
606 struct mlx5_ib_dev *dev; 606 struct mlx5_ib_dev *dev;
607 u32 out[MLX5_ST_SZ_DW(create_mkey_out)]; 607 u32 out[MLX5_ST_SZ_DW(create_mkey_out)];
608 struct mlx5_core_sig_ctx *sig; 608 struct mlx5_core_sig_ctx *sig;
609 int live; 609 unsigned int live;
610 void *descs_alloc; 610 void *descs_alloc;
611 int access_flags; /* Needed for rereg MR */ 611 int access_flags; /* Needed for rereg MR */
612 612
@@ -639,7 +639,6 @@ struct mlx5_ib_mw {
639struct mlx5_ib_devx_mr { 639struct mlx5_ib_devx_mr {
640 struct mlx5_core_mkey mmkey; 640 struct mlx5_core_mkey mmkey;
641 int ndescs; 641 int ndescs;
642 struct rcu_head rcu;
643}; 642};
644 643
645struct mlx5_ib_umr_context { 644struct mlx5_ib_umr_context {
diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c
index 1eff031ef048..630599311586 100644
--- a/drivers/infiniband/hw/mlx5/mr.c
+++ b/drivers/infiniband/hw/mlx5/mr.c
@@ -84,32 +84,6 @@ static bool use_umr_mtt_update(struct mlx5_ib_mr *mr, u64 start, u64 length)
84 length + (start & (MLX5_ADAPTER_PAGE_SIZE - 1)); 84 length + (start & (MLX5_ADAPTER_PAGE_SIZE - 1));
85} 85}
86 86
87static void update_odp_mr(struct mlx5_ib_mr *mr)
88{
89 if (is_odp_mr(mr)) {
90 /*
91 * This barrier prevents the compiler from moving the
92 * setting of umem->odp_data->private to point to our
93 * MR, before reg_umr finished, to ensure that the MR
94 * initialization have finished before starting to
95 * handle invalidations.
96 */
97 smp_wmb();
98 to_ib_umem_odp(mr->umem)->private = mr;
99 /*
100 * Make sure we will see the new
101 * umem->odp_data->private value in the invalidation
102 * routines, before we can get page faults on the
103 * MR. Page faults can happen once we put the MR in
104 * the tree, below this line. Without the barrier,
105 * there can be a fault handling and an invalidation
106 * before umem->odp_data->private == mr is visible to
107 * the invalidation handler.
108 */
109 smp_wmb();
110 }
111}
112
113static void reg_mr_callback(int status, struct mlx5_async_work *context) 87static void reg_mr_callback(int status, struct mlx5_async_work *context)
114{ 88{
115 struct mlx5_ib_mr *mr = 89 struct mlx5_ib_mr *mr =
@@ -1346,8 +1320,6 @@ struct ib_mr *mlx5_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
1346 mr->umem = umem; 1320 mr->umem = umem;
1347 set_mr_fields(dev, mr, npages, length, access_flags); 1321 set_mr_fields(dev, mr, npages, length, access_flags);
1348 1322
1349 update_odp_mr(mr);
1350
1351 if (use_umr) { 1323 if (use_umr) {
1352 int update_xlt_flags = MLX5_IB_UPD_XLT_ENABLE; 1324 int update_xlt_flags = MLX5_IB_UPD_XLT_ENABLE;
1353 1325
@@ -1363,10 +1335,12 @@ struct ib_mr *mlx5_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
1363 } 1335 }
1364 } 1336 }
1365 1337
1366 if (IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING)) { 1338 if (is_odp_mr(mr)) {
1367 mr->live = 1; 1339 to_ib_umem_odp(mr->umem)->private = mr;
1368 atomic_set(&mr->num_pending_prefetch, 0); 1340 atomic_set(&mr->num_pending_prefetch, 0);
1369 } 1341 }
1342 if (IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING))
1343 smp_store_release(&mr->live, 1);
1370 1344
1371 return &mr->ibmr; 1345 return &mr->ibmr;
1372error: 1346error:
@@ -1441,6 +1415,9 @@ int mlx5_ib_rereg_user_mr(struct ib_mr *ib_mr, int flags, u64 start,
1441 if (!mr->umem) 1415 if (!mr->umem)
1442 return -EINVAL; 1416 return -EINVAL;
1443 1417
1418 if (is_odp_mr(mr))
1419 return -EOPNOTSUPP;
1420
1444 if (flags & IB_MR_REREG_TRANS) { 1421 if (flags & IB_MR_REREG_TRANS) {
1445 addr = virt_addr; 1422 addr = virt_addr;
1446 len = length; 1423 len = length;
@@ -1486,8 +1463,6 @@ int mlx5_ib_rereg_user_mr(struct ib_mr *ib_mr, int flags, u64 start,
1486 } 1463 }
1487 1464
1488 mr->allocated_from_cache = 0; 1465 mr->allocated_from_cache = 0;
1489 if (IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING))
1490 mr->live = 1;
1491 } else { 1466 } else {
1492 /* 1467 /*
1493 * Send a UMR WQE 1468 * Send a UMR WQE
@@ -1516,7 +1491,6 @@ int mlx5_ib_rereg_user_mr(struct ib_mr *ib_mr, int flags, u64 start,
1516 1491
1517 set_mr_fields(dev, mr, npages, len, access_flags); 1492 set_mr_fields(dev, mr, npages, len, access_flags);
1518 1493
1519 update_odp_mr(mr);
1520 return 0; 1494 return 0;
1521 1495
1522err: 1496err:
@@ -1607,15 +1581,16 @@ static void dereg_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr)
1607 /* Prevent new page faults and 1581 /* Prevent new page faults and
1608 * prefetch requests from succeeding 1582 * prefetch requests from succeeding
1609 */ 1583 */
1610 mr->live = 0; 1584 WRITE_ONCE(mr->live, 0);
1585
1586 /* Wait for all running page-fault handlers to finish. */
1587 synchronize_srcu(&dev->mr_srcu);
1611 1588
1612 /* dequeue pending prefetch requests for the mr */ 1589 /* dequeue pending prefetch requests for the mr */
1613 if (atomic_read(&mr->num_pending_prefetch)) 1590 if (atomic_read(&mr->num_pending_prefetch))
1614 flush_workqueue(system_unbound_wq); 1591 flush_workqueue(system_unbound_wq);
1615 WARN_ON(atomic_read(&mr->num_pending_prefetch)); 1592 WARN_ON(atomic_read(&mr->num_pending_prefetch));
1616 1593
1617 /* Wait for all running page-fault handlers to finish. */
1618 synchronize_srcu(&dev->mr_srcu);
1619 /* Destroy all page mappings */ 1594 /* Destroy all page mappings */
1620 if (!umem_odp->is_implicit_odp) 1595 if (!umem_odp->is_implicit_odp)
1621 mlx5_ib_invalidate_range(umem_odp, 1596 mlx5_ib_invalidate_range(umem_odp,
@@ -1987,14 +1962,25 @@ free:
1987 1962
1988int mlx5_ib_dealloc_mw(struct ib_mw *mw) 1963int mlx5_ib_dealloc_mw(struct ib_mw *mw)
1989{ 1964{
1965 struct mlx5_ib_dev *dev = to_mdev(mw->device);
1990 struct mlx5_ib_mw *mmw = to_mmw(mw); 1966 struct mlx5_ib_mw *mmw = to_mmw(mw);
1991 int err; 1967 int err;
1992 1968
1993 err = mlx5_core_destroy_mkey((to_mdev(mw->device))->mdev, 1969 if (IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING)) {
1994 &mmw->mmkey); 1970 xa_erase(&dev->mdev->priv.mkey_table,
1995 if (!err) 1971 mlx5_base_mkey(mmw->mmkey.key));
1996 kfree(mmw); 1972 /*
1997 return err; 1973 * pagefault_single_data_segment() may be accessing mmw under
1974 * SRCU if the user bound an ODP MR to this MW.
1975 */
1976 synchronize_srcu(&dev->mr_srcu);
1977 }
1978
1979 err = mlx5_core_destroy_mkey(dev->mdev, &mmw->mmkey);
1980 if (err)
1981 return err;
1982 kfree(mmw);
1983 return 0;
1998} 1984}
1999 1985
2000int mlx5_ib_check_mr_status(struct ib_mr *ibmr, u32 check_mask, 1986int mlx5_ib_check_mr_status(struct ib_mr *ibmr, u32 check_mask,
diff --git a/drivers/infiniband/hw/mlx5/odp.c b/drivers/infiniband/hw/mlx5/odp.c
index 2e9b43061797..3f9478d19376 100644
--- a/drivers/infiniband/hw/mlx5/odp.c
+++ b/drivers/infiniband/hw/mlx5/odp.c
@@ -178,6 +178,29 @@ void mlx5_odp_populate_klm(struct mlx5_klm *pklm, size_t offset,
178 return; 178 return;
179 } 179 }
180 180
181 /*
182 * The locking here is pretty subtle. Ideally the implicit children
183 * list would be protected by the umem_mutex, however that is not
184 * possible. Instead this uses a weaker update-then-lock pattern:
185 *
186 * srcu_read_lock()
187 * <change children list>
188 * mutex_lock(umem_mutex)
189 * mlx5_ib_update_xlt()
190 * mutex_unlock(umem_mutex)
191 * destroy lkey
192 *
193 * ie any change the children list must be followed by the locked
194 * update_xlt before destroying.
195 *
196 * The umem_mutex provides the acquire/release semantic needed to make
197 * the children list visible to a racing thread. While SRCU is not
198 * technically required, using it gives consistent use of the SRCU
199 * locking around the children list.
200 */
201 lockdep_assert_held(&to_ib_umem_odp(mr->umem)->umem_mutex);
202 lockdep_assert_held(&mr->dev->mr_srcu);
203
181 odp = odp_lookup(offset * MLX5_IMR_MTT_SIZE, 204 odp = odp_lookup(offset * MLX5_IMR_MTT_SIZE,
182 nentries * MLX5_IMR_MTT_SIZE, mr); 205 nentries * MLX5_IMR_MTT_SIZE, mr);
183 206
@@ -202,15 +225,22 @@ static void mr_leaf_free_action(struct work_struct *work)
202 struct ib_umem_odp *odp = container_of(work, struct ib_umem_odp, work); 225 struct ib_umem_odp *odp = container_of(work, struct ib_umem_odp, work);
203 int idx = ib_umem_start(odp) >> MLX5_IMR_MTT_SHIFT; 226 int idx = ib_umem_start(odp) >> MLX5_IMR_MTT_SHIFT;
204 struct mlx5_ib_mr *mr = odp->private, *imr = mr->parent; 227 struct mlx5_ib_mr *mr = odp->private, *imr = mr->parent;
228 struct ib_umem_odp *odp_imr = to_ib_umem_odp(imr->umem);
229 int srcu_key;
205 230
206 mr->parent = NULL; 231 mr->parent = NULL;
207 synchronize_srcu(&mr->dev->mr_srcu); 232 synchronize_srcu(&mr->dev->mr_srcu);
208 233
209 ib_umem_odp_release(odp); 234 if (smp_load_acquire(&imr->live)) {
210 if (imr->live) 235 srcu_key = srcu_read_lock(&mr->dev->mr_srcu);
236 mutex_lock(&odp_imr->umem_mutex);
211 mlx5_ib_update_xlt(imr, idx, 1, 0, 237 mlx5_ib_update_xlt(imr, idx, 1, 0,
212 MLX5_IB_UPD_XLT_INDIRECT | 238 MLX5_IB_UPD_XLT_INDIRECT |
213 MLX5_IB_UPD_XLT_ATOMIC); 239 MLX5_IB_UPD_XLT_ATOMIC);
240 mutex_unlock(&odp_imr->umem_mutex);
241 srcu_read_unlock(&mr->dev->mr_srcu, srcu_key);
242 }
243 ib_umem_odp_release(odp);
214 mlx5_mr_cache_free(mr->dev, mr); 244 mlx5_mr_cache_free(mr->dev, mr);
215 245
216 if (atomic_dec_and_test(&imr->num_leaf_free)) 246 if (atomic_dec_and_test(&imr->num_leaf_free))
@@ -278,7 +308,6 @@ void mlx5_ib_invalidate_range(struct ib_umem_odp *umem_odp, unsigned long start,
278 idx - blk_start_idx + 1, 0, 308 idx - blk_start_idx + 1, 0,
279 MLX5_IB_UPD_XLT_ZAP | 309 MLX5_IB_UPD_XLT_ZAP |
280 MLX5_IB_UPD_XLT_ATOMIC); 310 MLX5_IB_UPD_XLT_ATOMIC);
281 mutex_unlock(&umem_odp->umem_mutex);
282 /* 311 /*
283 * We are now sure that the device will not access the 312 * We are now sure that the device will not access the
284 * memory. We can safely unmap it, and mark it as dirty if 313 * memory. We can safely unmap it, and mark it as dirty if
@@ -289,10 +318,12 @@ void mlx5_ib_invalidate_range(struct ib_umem_odp *umem_odp, unsigned long start,
289 318
290 if (unlikely(!umem_odp->npages && mr->parent && 319 if (unlikely(!umem_odp->npages && mr->parent &&
291 !umem_odp->dying)) { 320 !umem_odp->dying)) {
292 WRITE_ONCE(umem_odp->dying, 1); 321 WRITE_ONCE(mr->live, 0);
322 umem_odp->dying = 1;
293 atomic_inc(&mr->parent->num_leaf_free); 323 atomic_inc(&mr->parent->num_leaf_free);
294 schedule_work(&umem_odp->work); 324 schedule_work(&umem_odp->work);
295 } 325 }
326 mutex_unlock(&umem_odp->umem_mutex);
296} 327}
297 328
298void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev) 329void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev)
@@ -429,8 +460,6 @@ static struct mlx5_ib_mr *implicit_mr_alloc(struct ib_pd *pd,
429 mr->ibmr.lkey = mr->mmkey.key; 460 mr->ibmr.lkey = mr->mmkey.key;
430 mr->ibmr.rkey = mr->mmkey.key; 461 mr->ibmr.rkey = mr->mmkey.key;
431 462
432 mr->live = 1;
433
434 mlx5_ib_dbg(dev, "key %x dev %p mr %p\n", 463 mlx5_ib_dbg(dev, "key %x dev %p mr %p\n",
435 mr->mmkey.key, dev->mdev, mr); 464 mr->mmkey.key, dev->mdev, mr);
436 465
@@ -484,6 +513,8 @@ next_mr:
484 mtt->parent = mr; 513 mtt->parent = mr;
485 INIT_WORK(&odp->work, mr_leaf_free_action); 514 INIT_WORK(&odp->work, mr_leaf_free_action);
486 515
516 smp_store_release(&mtt->live, 1);
517
487 if (!nentries) 518 if (!nentries)
488 start_idx = addr >> MLX5_IMR_MTT_SHIFT; 519 start_idx = addr >> MLX5_IMR_MTT_SHIFT;
489 nentries++; 520 nentries++;
@@ -536,6 +567,7 @@ struct mlx5_ib_mr *mlx5_ib_alloc_implicit_mr(struct mlx5_ib_pd *pd,
536 init_waitqueue_head(&imr->q_leaf_free); 567 init_waitqueue_head(&imr->q_leaf_free);
537 atomic_set(&imr->num_leaf_free, 0); 568 atomic_set(&imr->num_leaf_free, 0);
538 atomic_set(&imr->num_pending_prefetch, 0); 569 atomic_set(&imr->num_pending_prefetch, 0);
570 smp_store_release(&imr->live, 1);
539 571
540 return imr; 572 return imr;
541} 573}
@@ -555,15 +587,19 @@ void mlx5_ib_free_implicit_mr(struct mlx5_ib_mr *imr)
555 if (mr->parent != imr) 587 if (mr->parent != imr)
556 continue; 588 continue;
557 589
590 mutex_lock(&umem_odp->umem_mutex);
558 ib_umem_odp_unmap_dma_pages(umem_odp, ib_umem_start(umem_odp), 591 ib_umem_odp_unmap_dma_pages(umem_odp, ib_umem_start(umem_odp),
559 ib_umem_end(umem_odp)); 592 ib_umem_end(umem_odp));
560 593
561 if (umem_odp->dying) 594 if (umem_odp->dying) {
595 mutex_unlock(&umem_odp->umem_mutex);
562 continue; 596 continue;
597 }
563 598
564 WRITE_ONCE(umem_odp->dying, 1); 599 umem_odp->dying = 1;
565 atomic_inc(&imr->num_leaf_free); 600 atomic_inc(&imr->num_leaf_free);
566 schedule_work(&umem_odp->work); 601 schedule_work(&umem_odp->work);
602 mutex_unlock(&umem_odp->umem_mutex);
567 } 603 }
568 up_read(&per_mm->umem_rwsem); 604 up_read(&per_mm->umem_rwsem);
569 605
@@ -773,7 +809,7 @@ next_mr:
773 switch (mmkey->type) { 809 switch (mmkey->type) {
774 case MLX5_MKEY_MR: 810 case MLX5_MKEY_MR:
775 mr = container_of(mmkey, struct mlx5_ib_mr, mmkey); 811 mr = container_of(mmkey, struct mlx5_ib_mr, mmkey);
776 if (!mr->live || !mr->ibmr.pd) { 812 if (!smp_load_acquire(&mr->live) || !mr->ibmr.pd) {
777 mlx5_ib_dbg(dev, "got dead MR\n"); 813 mlx5_ib_dbg(dev, "got dead MR\n");
778 ret = -EFAULT; 814 ret = -EFAULT;
779 goto srcu_unlock; 815 goto srcu_unlock;
@@ -1641,12 +1677,12 @@ static bool num_pending_prefetch_inc(struct ib_pd *pd,
1641 1677
1642 mr = container_of(mmkey, struct mlx5_ib_mr, mmkey); 1678 mr = container_of(mmkey, struct mlx5_ib_mr, mmkey);
1643 1679
1644 if (mr->ibmr.pd != pd) { 1680 if (!smp_load_acquire(&mr->live)) {
1645 ret = false; 1681 ret = false;
1646 break; 1682 break;
1647 } 1683 }
1648 1684
1649 if (!mr->live) { 1685 if (mr->ibmr.pd != pd) {
1650 ret = false; 1686 ret = false;
1651 break; 1687 break;
1652 } 1688 }
diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c
index 6cac0c88cf39..36cdfbdbd325 100644
--- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c
+++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c
@@ -230,8 +230,6 @@ static void pvrdma_free_srq(struct pvrdma_dev *dev, struct pvrdma_srq *srq)
230 230
231 pvrdma_page_dir_cleanup(dev, &srq->pdir); 231 pvrdma_page_dir_cleanup(dev, &srq->pdir);
232 232
233 kfree(srq);
234
235 atomic_dec(&dev->num_srqs); 233 atomic_dec(&dev->num_srqs);
236} 234}
237 235
diff --git a/drivers/infiniband/sw/siw/siw_qp.c b/drivers/infiniband/sw/siw/siw_qp.c
index 430314c8abd9..52d402f39df9 100644
--- a/drivers/infiniband/sw/siw/siw_qp.c
+++ b/drivers/infiniband/sw/siw/siw_qp.c
@@ -182,12 +182,19 @@ void siw_qp_llp_close(struct siw_qp *qp)
182 */ 182 */
183void siw_qp_llp_write_space(struct sock *sk) 183void siw_qp_llp_write_space(struct sock *sk)
184{ 184{
185 struct siw_cep *cep = sk_to_cep(sk); 185 struct siw_cep *cep;
186 186
187 cep->sk_write_space(sk); 187 read_lock(&sk->sk_callback_lock);
188
189 cep = sk_to_cep(sk);
190 if (cep) {
191 cep->sk_write_space(sk);
188 192
189 if (!test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) 193 if (!test_bit(SOCK_NOSPACE, &sk->sk_socket->flags))
190 (void)siw_sq_start(cep->qp); 194 (void)siw_sq_start(cep->qp);
195 }
196
197 read_unlock(&sk->sk_callback_lock);
191} 198}
192 199
193static int siw_qp_readq_init(struct siw_qp *qp, int irq_size, int orq_size) 200static int siw_qp_readq_init(struct siw_qp *qp, int irq_size, int orq_size)
diff --git a/drivers/input/misc/da9063_onkey.c b/drivers/input/misc/da9063_onkey.c
index dace8577fa43..79851923ee57 100644
--- a/drivers/input/misc/da9063_onkey.c
+++ b/drivers/input/misc/da9063_onkey.c
@@ -232,10 +232,7 @@ static int da9063_onkey_probe(struct platform_device *pdev)
232 onkey->input->phys = onkey->phys; 232 onkey->input->phys = onkey->phys;
233 onkey->input->dev.parent = &pdev->dev; 233 onkey->input->dev.parent = &pdev->dev;
234 234
235 if (onkey->key_power) 235 input_set_capability(onkey->input, EV_KEY, KEY_POWER);
236 input_set_capability(onkey->input, EV_KEY, KEY_POWER);
237
238 input_set_capability(onkey->input, EV_KEY, KEY_SLEEP);
239 236
240 INIT_DELAYED_WORK(&onkey->work, da9063_poll_on); 237 INIT_DELAYED_WORK(&onkey->work, da9063_poll_on);
241 238
diff --git a/drivers/input/misc/soc_button_array.c b/drivers/input/misc/soc_button_array.c
index 97e3639e99d0..08520b3a18b8 100644
--- a/drivers/input/misc/soc_button_array.c
+++ b/drivers/input/misc/soc_button_array.c
@@ -92,11 +92,18 @@ soc_button_device_create(struct platform_device *pdev,
92 continue; 92 continue;
93 93
94 gpio = soc_button_lookup_gpio(&pdev->dev, info->acpi_index); 94 gpio = soc_button_lookup_gpio(&pdev->dev, info->acpi_index);
95 if (gpio < 0 && gpio != -ENOENT) { 95 if (!gpio_is_valid(gpio)) {
96 error = gpio; 96 /*
97 goto err_free_mem; 97 * Skip GPIO if not present. Note we deliberately
98 } else if (!gpio_is_valid(gpio)) { 98 * ignore -EPROBE_DEFER errors here. On some devices
99 /* Skip GPIO if not present */ 99 * Intel is using so called virtual GPIOs which are not
100 * GPIOs at all but some way for AML code to check some
101 * random status bits without need a custom opregion.
102 * In some cases the resources table we parse points to
103 * such a virtual GPIO, since these are not real GPIOs
104 * we do not have a driver for these so they will never
105 * show up, therefore we ignore -EPROBE_DEFER.
106 */
100 continue; 107 continue;
101 } 108 }
102 109
diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index 04fe43440a3c..2d8434b7b623 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -1827,31 +1827,6 @@ static int elantech_create_smbus(struct psmouse *psmouse,
1827 leave_breadcrumbs); 1827 leave_breadcrumbs);
1828} 1828}
1829 1829
1830static bool elantech_use_host_notify(struct psmouse *psmouse,
1831 struct elantech_device_info *info)
1832{
1833 if (ETP_NEW_IC_SMBUS_HOST_NOTIFY(info->fw_version))
1834 return true;
1835
1836 switch (info->bus) {
1837 case ETP_BUS_PS2_ONLY:
1838 /* expected case */
1839 break;
1840 case ETP_BUS_SMB_HST_NTFY_ONLY:
1841 case ETP_BUS_PS2_SMB_HST_NTFY:
1842 /* SMbus implementation is stable since 2018 */
1843 if (dmi_get_bios_year() >= 2018)
1844 return true;
1845 /* fall through */
1846 default:
1847 psmouse_dbg(psmouse,
1848 "Ignoring SMBus bus provider %d\n", info->bus);
1849 break;
1850 }
1851
1852 return false;
1853}
1854
1855/** 1830/**
1856 * elantech_setup_smbus - called once the PS/2 devices are enumerated 1831 * elantech_setup_smbus - called once the PS/2 devices are enumerated
1857 * and decides to instantiate a SMBus InterTouch device. 1832 * and decides to instantiate a SMBus InterTouch device.
@@ -1871,7 +1846,7 @@ static int elantech_setup_smbus(struct psmouse *psmouse,
1871 * i2c_blacklist_pnp_ids. 1846 * i2c_blacklist_pnp_ids.
1872 * Old ICs are up to the user to decide. 1847 * Old ICs are up to the user to decide.
1873 */ 1848 */
1874 if (!elantech_use_host_notify(psmouse, info) || 1849 if (!ETP_NEW_IC_SMBUS_HOST_NOTIFY(info->fw_version) ||
1875 psmouse_matches_pnp_id(psmouse, i2c_blacklist_pnp_ids)) 1850 psmouse_matches_pnp_id(psmouse, i2c_blacklist_pnp_ids))
1876 return -ENXIO; 1851 return -ENXIO;
1877 } 1852 }
@@ -1891,6 +1866,34 @@ static int elantech_setup_smbus(struct psmouse *psmouse,
1891 return 0; 1866 return 0;
1892} 1867}
1893 1868
1869static bool elantech_use_host_notify(struct psmouse *psmouse,
1870 struct elantech_device_info *info)
1871{
1872 if (ETP_NEW_IC_SMBUS_HOST_NOTIFY(info->fw_version))
1873 return true;
1874
1875 switch (info->bus) {
1876 case ETP_BUS_PS2_ONLY:
1877 /* expected case */
1878 break;
1879 case ETP_BUS_SMB_ALERT_ONLY:
1880 /* fall-through */
1881 case ETP_BUS_PS2_SMB_ALERT:
1882 psmouse_dbg(psmouse, "Ignoring SMBus provider through alert protocol.\n");
1883 break;
1884 case ETP_BUS_SMB_HST_NTFY_ONLY:
1885 /* fall-through */
1886 case ETP_BUS_PS2_SMB_HST_NTFY:
1887 return true;
1888 default:
1889 psmouse_dbg(psmouse,
1890 "Ignoring SMBus bus provider %d.\n",
1891 info->bus);
1892 }
1893
1894 return false;
1895}
1896
1894int elantech_init_smbus(struct psmouse *psmouse) 1897int elantech_init_smbus(struct psmouse *psmouse)
1895{ 1898{
1896 struct elantech_device_info info; 1899 struct elantech_device_info info;
diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
index 772493b1f665..190b9974526b 100644
--- a/drivers/input/rmi4/rmi_driver.c
+++ b/drivers/input/rmi4/rmi_driver.c
@@ -146,7 +146,7 @@ static int rmi_process_interrupt_requests(struct rmi_device *rmi_dev)
146 } 146 }
147 147
148 mutex_lock(&data->irq_mutex); 148 mutex_lock(&data->irq_mutex);
149 bitmap_and(data->irq_status, data->irq_status, data->current_irq_mask, 149 bitmap_and(data->irq_status, data->irq_status, data->fn_irq_bits,
150 data->irq_count); 150 data->irq_count);
151 /* 151 /*
152 * At this point, irq_status has all bits that are set in the 152 * At this point, irq_status has all bits that are set in the
@@ -385,6 +385,8 @@ static int rmi_driver_set_irq_bits(struct rmi_device *rmi_dev,
385 bitmap_copy(data->current_irq_mask, data->new_irq_mask, 385 bitmap_copy(data->current_irq_mask, data->new_irq_mask,
386 data->num_of_irq_regs); 386 data->num_of_irq_regs);
387 387
388 bitmap_or(data->fn_irq_bits, data->fn_irq_bits, mask, data->irq_count);
389
388error_unlock: 390error_unlock:
389 mutex_unlock(&data->irq_mutex); 391 mutex_unlock(&data->irq_mutex);
390 return error; 392 return error;
@@ -398,6 +400,8 @@ static int rmi_driver_clear_irq_bits(struct rmi_device *rmi_dev,
398 struct device *dev = &rmi_dev->dev; 400 struct device *dev = &rmi_dev->dev;
399 401
400 mutex_lock(&data->irq_mutex); 402 mutex_lock(&data->irq_mutex);
403 bitmap_andnot(data->fn_irq_bits,
404 data->fn_irq_bits, mask, data->irq_count);
401 bitmap_andnot(data->new_irq_mask, 405 bitmap_andnot(data->new_irq_mask,
402 data->current_irq_mask, mask, data->irq_count); 406 data->current_irq_mask, mask, data->irq_count);
403 407
diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c
index 5178ea8b5f30..fb43aa708660 100644
--- a/drivers/input/touchscreen/goodix.c
+++ b/drivers/input/touchscreen/goodix.c
@@ -53,6 +53,7 @@ struct goodix_ts_data {
53 const char *cfg_name; 53 const char *cfg_name;
54 struct completion firmware_loading_complete; 54 struct completion firmware_loading_complete;
55 unsigned long irq_flags; 55 unsigned long irq_flags;
56 unsigned int contact_size;
56}; 57};
57 58
58#define GOODIX_GPIO_INT_NAME "irq" 59#define GOODIX_GPIO_INT_NAME "irq"
@@ -62,6 +63,7 @@ struct goodix_ts_data {
62#define GOODIX_MAX_WIDTH 4096 63#define GOODIX_MAX_WIDTH 4096
63#define GOODIX_INT_TRIGGER 1 64#define GOODIX_INT_TRIGGER 1
64#define GOODIX_CONTACT_SIZE 8 65#define GOODIX_CONTACT_SIZE 8
66#define GOODIX_MAX_CONTACT_SIZE 9
65#define GOODIX_MAX_CONTACTS 10 67#define GOODIX_MAX_CONTACTS 10
66 68
67#define GOODIX_CONFIG_MAX_LENGTH 240 69#define GOODIX_CONFIG_MAX_LENGTH 240
@@ -144,6 +146,19 @@ static const struct dmi_system_id rotated_screen[] = {
144 {} 146 {}
145}; 147};
146 148
149static const struct dmi_system_id nine_bytes_report[] = {
150#if defined(CONFIG_DMI) && defined(CONFIG_X86)
151 {
152 .ident = "Lenovo YogaBook",
153 /* YB1-X91L/F and YB1-X90L/F */
154 .matches = {
155 DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X9")
156 }
157 },
158#endif
159 {}
160};
161
147/** 162/**
148 * goodix_i2c_read - read data from a register of the i2c slave device. 163 * goodix_i2c_read - read data from a register of the i2c slave device.
149 * 164 *
@@ -249,7 +264,7 @@ static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data)
249 max_timeout = jiffies + msecs_to_jiffies(GOODIX_BUFFER_STATUS_TIMEOUT); 264 max_timeout = jiffies + msecs_to_jiffies(GOODIX_BUFFER_STATUS_TIMEOUT);
250 do { 265 do {
251 error = goodix_i2c_read(ts->client, GOODIX_READ_COOR_ADDR, 266 error = goodix_i2c_read(ts->client, GOODIX_READ_COOR_ADDR,
252 data, GOODIX_CONTACT_SIZE + 1); 267 data, ts->contact_size + 1);
253 if (error) { 268 if (error) {
254 dev_err(&ts->client->dev, "I2C transfer error: %d\n", 269 dev_err(&ts->client->dev, "I2C transfer error: %d\n",
255 error); 270 error);
@@ -262,12 +277,12 @@ static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data)
262 return -EPROTO; 277 return -EPROTO;
263 278
264 if (touch_num > 1) { 279 if (touch_num > 1) {
265 data += 1 + GOODIX_CONTACT_SIZE; 280 data += 1 + ts->contact_size;
266 error = goodix_i2c_read(ts->client, 281 error = goodix_i2c_read(ts->client,
267 GOODIX_READ_COOR_ADDR + 282 GOODIX_READ_COOR_ADDR +
268 1 + GOODIX_CONTACT_SIZE, 283 1 + ts->contact_size,
269 data, 284 data,
270 GOODIX_CONTACT_SIZE * 285 ts->contact_size *
271 (touch_num - 1)); 286 (touch_num - 1));
272 if (error) 287 if (error)
273 return error; 288 return error;
@@ -286,7 +301,7 @@ static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data)
286 return 0; 301 return 0;
287} 302}
288 303
289static void goodix_ts_report_touch(struct goodix_ts_data *ts, u8 *coor_data) 304static void goodix_ts_report_touch_8b(struct goodix_ts_data *ts, u8 *coor_data)
290{ 305{
291 int id = coor_data[0] & 0x0F; 306 int id = coor_data[0] & 0x0F;
292 int input_x = get_unaligned_le16(&coor_data[1]); 307 int input_x = get_unaligned_le16(&coor_data[1]);
@@ -301,6 +316,21 @@ static void goodix_ts_report_touch(struct goodix_ts_data *ts, u8 *coor_data)
301 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, input_w); 316 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, input_w);
302} 317}
303 318
319static void goodix_ts_report_touch_9b(struct goodix_ts_data *ts, u8 *coor_data)
320{
321 int id = coor_data[1] & 0x0F;
322 int input_x = get_unaligned_le16(&coor_data[3]);
323 int input_y = get_unaligned_le16(&coor_data[5]);
324 int input_w = get_unaligned_le16(&coor_data[7]);
325
326 input_mt_slot(ts->input_dev, id);
327 input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true);
328 touchscreen_report_pos(ts->input_dev, &ts->prop,
329 input_x, input_y, true);
330 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, input_w);
331 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, input_w);
332}
333
304/** 334/**
305 * goodix_process_events - Process incoming events 335 * goodix_process_events - Process incoming events
306 * 336 *
@@ -311,7 +341,7 @@ static void goodix_ts_report_touch(struct goodix_ts_data *ts, u8 *coor_data)
311 */ 341 */
312static void goodix_process_events(struct goodix_ts_data *ts) 342static void goodix_process_events(struct goodix_ts_data *ts)
313{ 343{
314 u8 point_data[1 + GOODIX_CONTACT_SIZE * GOODIX_MAX_CONTACTS]; 344 u8 point_data[1 + GOODIX_MAX_CONTACT_SIZE * GOODIX_MAX_CONTACTS];
315 int touch_num; 345 int touch_num;
316 int i; 346 int i;
317 347
@@ -326,8 +356,12 @@ static void goodix_process_events(struct goodix_ts_data *ts)
326 input_report_key(ts->input_dev, KEY_LEFTMETA, point_data[0] & BIT(4)); 356 input_report_key(ts->input_dev, KEY_LEFTMETA, point_data[0] & BIT(4));
327 357
328 for (i = 0; i < touch_num; i++) 358 for (i = 0; i < touch_num; i++)
329 goodix_ts_report_touch(ts, 359 if (ts->contact_size == 9)
330 &point_data[1 + GOODIX_CONTACT_SIZE * i]); 360 goodix_ts_report_touch_9b(ts,
361 &point_data[1 + ts->contact_size * i]);
362 else
363 goodix_ts_report_touch_8b(ts,
364 &point_data[1 + ts->contact_size * i]);
331 365
332 input_mt_sync_frame(ts->input_dev); 366 input_mt_sync_frame(ts->input_dev);
333 input_sync(ts->input_dev); 367 input_sync(ts->input_dev);
@@ -730,6 +764,13 @@ static int goodix_configure_dev(struct goodix_ts_data *ts)
730 "Applying '180 degrees rotated screen' quirk\n"); 764 "Applying '180 degrees rotated screen' quirk\n");
731 } 765 }
732 766
767 if (dmi_check_system(nine_bytes_report)) {
768 ts->contact_size = 9;
769
770 dev_dbg(&ts->client->dev,
771 "Non-standard 9-bytes report format quirk\n");
772 }
773
733 error = input_mt_init_slots(ts->input_dev, ts->max_touch_num, 774 error = input_mt_init_slots(ts->input_dev, ts->max_touch_num,
734 INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED); 775 INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
735 if (error) { 776 if (error) {
@@ -810,6 +851,7 @@ static int goodix_ts_probe(struct i2c_client *client,
810 ts->client = client; 851 ts->client = client;
811 i2c_set_clientdata(client, ts); 852 i2c_set_clientdata(client, ts);
812 init_completion(&ts->firmware_loading_complete); 853 init_completion(&ts->firmware_loading_complete);
854 ts->contact_size = GOODIX_CONTACT_SIZE;
813 855
814 error = goodix_get_gpio_config(ts); 856 error = goodix_get_gpio_config(ts);
815 if (error) 857 if (error)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 2369b8af81f3..dd555078258c 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -583,7 +583,8 @@ static void iommu_print_event(struct amd_iommu *iommu, void *__evt)
583retry: 583retry:
584 type = (event[1] >> EVENT_TYPE_SHIFT) & EVENT_TYPE_MASK; 584 type = (event[1] >> EVENT_TYPE_SHIFT) & EVENT_TYPE_MASK;
585 devid = (event[0] >> EVENT_DEVID_SHIFT) & EVENT_DEVID_MASK; 585 devid = (event[0] >> EVENT_DEVID_SHIFT) & EVENT_DEVID_MASK;
586 pasid = PPR_PASID(*(u64 *)&event[0]); 586 pasid = (event[0] & EVENT_DOMID_MASK_HI) |
587 (event[1] & EVENT_DOMID_MASK_LO);
587 flags = (event[1] >> EVENT_FLAGS_SHIFT) & EVENT_FLAGS_MASK; 588 flags = (event[1] >> EVENT_FLAGS_SHIFT) & EVENT_FLAGS_MASK;
588 address = (u64)(((u64)event[3]) << 32) | event[2]; 589 address = (u64)(((u64)event[3]) << 32) | event[2];
589 590
@@ -616,7 +617,7 @@ retry:
616 address, flags); 617 address, flags);
617 break; 618 break;
618 case EVENT_TYPE_PAGE_TAB_ERR: 619 case EVENT_TYPE_PAGE_TAB_ERR:
619 dev_err(dev, "Event logged [PAGE_TAB_HARDWARE_ERROR device=%02x:%02x.%x domain=0x%04x address=0x%llx flags=0x%04x]\n", 620 dev_err(dev, "Event logged [PAGE_TAB_HARDWARE_ERROR device=%02x:%02x.%x pasid=0x%04x address=0x%llx flags=0x%04x]\n",
620 PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), 621 PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
621 pasid, address, flags); 622 pasid, address, flags);
622 break; 623 break;
@@ -1463,6 +1464,7 @@ static void free_pagetable(struct protection_domain *domain)
1463 * to 64 bits. 1464 * to 64 bits.
1464 */ 1465 */
1465static bool increase_address_space(struct protection_domain *domain, 1466static bool increase_address_space(struct protection_domain *domain,
1467 unsigned long address,
1466 gfp_t gfp) 1468 gfp_t gfp)
1467{ 1469{
1468 unsigned long flags; 1470 unsigned long flags;
@@ -1471,8 +1473,8 @@ static bool increase_address_space(struct protection_domain *domain,
1471 1473
1472 spin_lock_irqsave(&domain->lock, flags); 1474 spin_lock_irqsave(&domain->lock, flags);
1473 1475
1474 if (WARN_ON_ONCE(domain->mode == PAGE_MODE_6_LEVEL)) 1476 if (address <= PM_LEVEL_SIZE(domain->mode) ||
1475 /* address space already 64 bit large */ 1477 WARN_ON_ONCE(domain->mode == PAGE_MODE_6_LEVEL))
1476 goto out; 1478 goto out;
1477 1479
1478 pte = (void *)get_zeroed_page(gfp); 1480 pte = (void *)get_zeroed_page(gfp);
@@ -1505,7 +1507,7 @@ static u64 *alloc_pte(struct protection_domain *domain,
1505 BUG_ON(!is_power_of_2(page_size)); 1507 BUG_ON(!is_power_of_2(page_size));
1506 1508
1507 while (address > PM_LEVEL_SIZE(domain->mode)) 1509 while (address > PM_LEVEL_SIZE(domain->mode))
1508 *updated = increase_address_space(domain, gfp) || *updated; 1510 *updated = increase_address_space(domain, address, gfp) || *updated;
1509 1511
1510 level = domain->mode - 1; 1512 level = domain->mode - 1;
1511 pte = &domain->pt_root[PM_LEVEL_INDEX(level, address)]; 1513 pte = &domain->pt_root[PM_LEVEL_INDEX(level, address)];
diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h
index c9c1612d52e0..17bd5a349119 100644
--- a/drivers/iommu/amd_iommu_types.h
+++ b/drivers/iommu/amd_iommu_types.h
@@ -130,8 +130,8 @@
130#define EVENT_TYPE_INV_PPR_REQ 0x9 130#define EVENT_TYPE_INV_PPR_REQ 0x9
131#define EVENT_DEVID_MASK 0xffff 131#define EVENT_DEVID_MASK 0xffff
132#define EVENT_DEVID_SHIFT 0 132#define EVENT_DEVID_SHIFT 0
133#define EVENT_DOMID_MASK 0xffff 133#define EVENT_DOMID_MASK_LO 0xffff
134#define EVENT_DOMID_SHIFT 0 134#define EVENT_DOMID_MASK_HI 0xf0000
135#define EVENT_FLAGS_MASK 0xfff 135#define EVENT_FLAGS_MASK 0xfff
136#define EVENT_FLAGS_SHIFT 0x10 136#define EVENT_FLAGS_SHIFT 0x10
137 137
diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index b18aac4c105e..7c503a6bc585 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -812,6 +812,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
812 return 0; 812 return 0;
813 813
814out_clear_smmu: 814out_clear_smmu:
815 __arm_smmu_free_bitmap(smmu->context_map, cfg->cbndx);
815 smmu_domain->smmu = NULL; 816 smmu_domain->smmu = NULL;
816out_unlock: 817out_unlock:
817 mutex_unlock(&smmu_domain->init_mutex); 818 mutex_unlock(&smmu_domain->init_mutex);
diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c
index 4c91359057c5..ca51036aa53c 100644
--- a/drivers/iommu/io-pgtable-arm.c
+++ b/drivers/iommu/io-pgtable-arm.c
@@ -166,6 +166,9 @@
166#define ARM_MALI_LPAE_TTBR_READ_INNER BIT(2) 166#define ARM_MALI_LPAE_TTBR_READ_INNER BIT(2)
167#define ARM_MALI_LPAE_TTBR_SHARE_OUTER BIT(4) 167#define ARM_MALI_LPAE_TTBR_SHARE_OUTER BIT(4)
168 168
169#define ARM_MALI_LPAE_MEMATTR_IMP_DEF 0x88ULL
170#define ARM_MALI_LPAE_MEMATTR_WRITE_ALLOC 0x8DULL
171
169/* IOPTE accessors */ 172/* IOPTE accessors */
170#define iopte_deref(pte,d) __va(iopte_to_paddr(pte, d)) 173#define iopte_deref(pte,d) __va(iopte_to_paddr(pte, d))
171 174
@@ -1015,27 +1018,56 @@ arm_32_lpae_alloc_pgtable_s2(struct io_pgtable_cfg *cfg, void *cookie)
1015static struct io_pgtable * 1018static struct io_pgtable *
1016arm_mali_lpae_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie) 1019arm_mali_lpae_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
1017{ 1020{
1018 struct io_pgtable *iop; 1021 struct arm_lpae_io_pgtable *data;
1019 1022
1020 if (cfg->ias != 48 || cfg->oas > 40) 1023 /* No quirks for Mali (hopefully) */
1024 if (cfg->quirks)
1025 return NULL;
1026
1027 if (cfg->ias > 48 || cfg->oas > 40)
1021 return NULL; 1028 return NULL;
1022 1029
1023 cfg->pgsize_bitmap &= (SZ_4K | SZ_2M | SZ_1G); 1030 cfg->pgsize_bitmap &= (SZ_4K | SZ_2M | SZ_1G);
1024 iop = arm_64_lpae_alloc_pgtable_s1(cfg, cookie);
1025 if (iop) {
1026 u64 mair, ttbr;
1027 1031
1028 /* Copy values as union fields overlap */ 1032 data = arm_lpae_alloc_pgtable(cfg);
1029 mair = cfg->arm_lpae_s1_cfg.mair[0]; 1033 if (!data)
1030 ttbr = cfg->arm_lpae_s1_cfg.ttbr[0]; 1034 return NULL;
1031 1035
1032 cfg->arm_mali_lpae_cfg.memattr = mair; 1036 /* Mali seems to need a full 4-level table regardless of IAS */
1033 cfg->arm_mali_lpae_cfg.transtab = ttbr | 1037 if (data->levels < ARM_LPAE_MAX_LEVELS) {
1034 ARM_MALI_LPAE_TTBR_READ_INNER | 1038 data->levels = ARM_LPAE_MAX_LEVELS;
1035 ARM_MALI_LPAE_TTBR_ADRMODE_TABLE; 1039 data->pgd_size = sizeof(arm_lpae_iopte);
1036 } 1040 }
1041 /*
1042 * MEMATTR: Mali has no actual notion of a non-cacheable type, so the
1043 * best we can do is mimic the out-of-tree driver and hope that the
1044 * "implementation-defined caching policy" is good enough. Similarly,
1045 * we'll use it for the sake of a valid attribute for our 'device'
1046 * index, although callers should never request that in practice.
1047 */
1048 cfg->arm_mali_lpae_cfg.memattr =
1049 (ARM_MALI_LPAE_MEMATTR_IMP_DEF
1050 << ARM_LPAE_MAIR_ATTR_SHIFT(ARM_LPAE_MAIR_ATTR_IDX_NC)) |
1051 (ARM_MALI_LPAE_MEMATTR_WRITE_ALLOC
1052 << ARM_LPAE_MAIR_ATTR_SHIFT(ARM_LPAE_MAIR_ATTR_IDX_CACHE)) |
1053 (ARM_MALI_LPAE_MEMATTR_IMP_DEF
1054 << ARM_LPAE_MAIR_ATTR_SHIFT(ARM_LPAE_MAIR_ATTR_IDX_DEV));
1037 1055
1038 return iop; 1056 data->pgd = __arm_lpae_alloc_pages(data->pgd_size, GFP_KERNEL, cfg);
1057 if (!data->pgd)
1058 goto out_free_data;
1059
1060 /* Ensure the empty pgd is visible before TRANSTAB can be written */
1061 wmb();
1062
1063 cfg->arm_mali_lpae_cfg.transtab = virt_to_phys(data->pgd) |
1064 ARM_MALI_LPAE_TTBR_READ_INNER |
1065 ARM_MALI_LPAE_TTBR_ADRMODE_TABLE;
1066 return &data->iop;
1067
1068out_free_data:
1069 kfree(data);
1070 return NULL;
1039} 1071}
1040 1072
1041struct io_pgtable_init_fns io_pgtable_arm_64_lpae_s1_init_fns = { 1073struct io_pgtable_init_fns io_pgtable_arm_64_lpae_s1_init_fns = {
diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c
index 9da8309f7170..237103465b82 100644
--- a/drivers/iommu/ipmmu-vmsa.c
+++ b/drivers/iommu/ipmmu-vmsa.c
@@ -1086,8 +1086,6 @@ static int ipmmu_probe(struct platform_device *pdev)
1086 1086
1087 mmu->num_ctx = min(IPMMU_CTX_MAX, mmu->features->number_of_contexts); 1087 mmu->num_ctx = min(IPMMU_CTX_MAX, mmu->features->number_of_contexts);
1088 1088
1089 irq = platform_get_irq(pdev, 0);
1090
1091 /* 1089 /*
1092 * Determine if this IPMMU instance is a root device by checking for 1090 * Determine if this IPMMU instance is a root device by checking for
1093 * the lack of has_cache_leaf_nodes flag or renesas,ipmmu-main property. 1091 * the lack of has_cache_leaf_nodes flag or renesas,ipmmu-main property.
@@ -1106,6 +1104,7 @@ static int ipmmu_probe(struct platform_device *pdev)
1106 1104
1107 /* Root devices have mandatory IRQs */ 1105 /* Root devices have mandatory IRQs */
1108 if (ipmmu_is_root(mmu)) { 1106 if (ipmmu_is_root(mmu)) {
1107 irq = platform_get_irq(pdev, 0);
1109 if (irq < 0) { 1108 if (irq < 0) {
1110 dev_err(&pdev->dev, "no IRQ found\n"); 1109 dev_err(&pdev->dev, "no IRQ found\n");
1111 return irq; 1110 return irq;
diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index 26290f310f90..4dcbf68dfda4 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -100,6 +100,7 @@ struct rk_iommu {
100 struct device *dev; 100 struct device *dev;
101 void __iomem **bases; 101 void __iomem **bases;
102 int num_mmu; 102 int num_mmu;
103 int num_irq;
103 struct clk_bulk_data *clocks; 104 struct clk_bulk_data *clocks;
104 int num_clocks; 105 int num_clocks;
105 bool reset_disabled; 106 bool reset_disabled;
@@ -1136,7 +1137,7 @@ static int rk_iommu_probe(struct platform_device *pdev)
1136 struct rk_iommu *iommu; 1137 struct rk_iommu *iommu;
1137 struct resource *res; 1138 struct resource *res;
1138 int num_res = pdev->num_resources; 1139 int num_res = pdev->num_resources;
1139 int err, i, irq; 1140 int err, i;
1140 1141
1141 iommu = devm_kzalloc(dev, sizeof(*iommu), GFP_KERNEL); 1142 iommu = devm_kzalloc(dev, sizeof(*iommu), GFP_KERNEL);
1142 if (!iommu) 1143 if (!iommu)
@@ -1163,6 +1164,10 @@ static int rk_iommu_probe(struct platform_device *pdev)
1163 if (iommu->num_mmu == 0) 1164 if (iommu->num_mmu == 0)
1164 return PTR_ERR(iommu->bases[0]); 1165 return PTR_ERR(iommu->bases[0]);
1165 1166
1167 iommu->num_irq = platform_irq_count(pdev);
1168 if (iommu->num_irq < 0)
1169 return iommu->num_irq;
1170
1166 iommu->reset_disabled = device_property_read_bool(dev, 1171 iommu->reset_disabled = device_property_read_bool(dev,
1167 "rockchip,disable-mmu-reset"); 1172 "rockchip,disable-mmu-reset");
1168 1173
@@ -1219,8 +1224,9 @@ static int rk_iommu_probe(struct platform_device *pdev)
1219 1224
1220 pm_runtime_enable(dev); 1225 pm_runtime_enable(dev);
1221 1226
1222 i = 0; 1227 for (i = 0; i < iommu->num_irq; i++) {
1223 while ((irq = platform_get_irq(pdev, i++)) != -ENXIO) { 1228 int irq = platform_get_irq(pdev, i);
1229
1224 if (irq < 0) 1230 if (irq < 0)
1225 return irq; 1231 return irq;
1226 1232
@@ -1245,10 +1251,13 @@ err_unprepare_clocks:
1245static void rk_iommu_shutdown(struct platform_device *pdev) 1251static void rk_iommu_shutdown(struct platform_device *pdev)
1246{ 1252{
1247 struct rk_iommu *iommu = platform_get_drvdata(pdev); 1253 struct rk_iommu *iommu = platform_get_drvdata(pdev);
1248 int i = 0, irq; 1254 int i;
1255
1256 for (i = 0; i < iommu->num_irq; i++) {
1257 int irq = platform_get_irq(pdev, i);
1249 1258
1250 while ((irq = platform_get_irq(pdev, i++)) != -ENXIO)
1251 devm_free_irq(iommu->dev, irq, iommu); 1259 devm_free_irq(iommu->dev, irq, iommu);
1260 }
1252 1261
1253 pm_runtime_force_suspend(&pdev->dev); 1262 pm_runtime_force_suspend(&pdev->dev);
1254} 1263}
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index c92b405b7646..ba8619524231 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -744,7 +744,7 @@ capi_poll(struct file *file, poll_table *wait)
744 744
745 poll_wait(file, &(cdev->recvwait), wait); 745 poll_wait(file, &(cdev->recvwait), wait);
746 mask = EPOLLOUT | EPOLLWRNORM; 746 mask = EPOLLOUT | EPOLLWRNORM;
747 if (!skb_queue_empty(&cdev->recvqueue)) 747 if (!skb_queue_empty_lockless(&cdev->recvqueue))
748 mask |= EPOLLIN | EPOLLRDNORM; 748 mask |= EPOLLIN | EPOLLRDNORM;
749 return mask; 749 return mask;
750} 750}
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index d249cf8ac277..8346e6d1816c 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -542,7 +542,7 @@ static void wake_migration_worker(struct cache *cache)
542 542
543static struct dm_bio_prison_cell_v2 *alloc_prison_cell(struct cache *cache) 543static struct dm_bio_prison_cell_v2 *alloc_prison_cell(struct cache *cache)
544{ 544{
545 return dm_bio_prison_alloc_cell_v2(cache->prison, GFP_NOWAIT); 545 return dm_bio_prison_alloc_cell_v2(cache->prison, GFP_NOIO);
546} 546}
547 547
548static void free_prison_cell(struct cache *cache, struct dm_bio_prison_cell_v2 *cell) 548static void free_prison_cell(struct cache *cache, struct dm_bio_prison_cell_v2 *cell)
@@ -554,9 +554,7 @@ static struct dm_cache_migration *alloc_migration(struct cache *cache)
554{ 554{
555 struct dm_cache_migration *mg; 555 struct dm_cache_migration *mg;
556 556
557 mg = mempool_alloc(&cache->migration_pool, GFP_NOWAIT); 557 mg = mempool_alloc(&cache->migration_pool, GFP_NOIO);
558 if (!mg)
559 return NULL;
560 558
561 memset(mg, 0, sizeof(*mg)); 559 memset(mg, 0, sizeof(*mg));
562 560
@@ -664,10 +662,6 @@ static bool bio_detain_shared(struct cache *cache, dm_oblock_t oblock, struct bi
664 struct dm_bio_prison_cell_v2 *cell_prealloc, *cell; 662 struct dm_bio_prison_cell_v2 *cell_prealloc, *cell;
665 663
666 cell_prealloc = alloc_prison_cell(cache); /* FIXME: allow wait if calling from worker */ 664 cell_prealloc = alloc_prison_cell(cache); /* FIXME: allow wait if calling from worker */
667 if (!cell_prealloc) {
668 defer_bio(cache, bio);
669 return false;
670 }
671 665
672 build_key(oblock, end, &key); 666 build_key(oblock, end, &key);
673 r = dm_cell_get_v2(cache->prison, &key, lock_level(bio), bio, cell_prealloc, &cell); 667 r = dm_cell_get_v2(cache->prison, &key, lock_level(bio), bio, cell_prealloc, &cell);
@@ -1493,11 +1487,6 @@ static int mg_lock_writes(struct dm_cache_migration *mg)
1493 struct dm_bio_prison_cell_v2 *prealloc; 1487 struct dm_bio_prison_cell_v2 *prealloc;
1494 1488
1495 prealloc = alloc_prison_cell(cache); 1489 prealloc = alloc_prison_cell(cache);
1496 if (!prealloc) {
1497 DMERR_LIMIT("%s: alloc_prison_cell failed", cache_device_name(cache));
1498 mg_complete(mg, false);
1499 return -ENOMEM;
1500 }
1501 1490
1502 /* 1491 /*
1503 * Prevent writes to the block, but allow reads to continue. 1492 * Prevent writes to the block, but allow reads to continue.
@@ -1535,11 +1524,6 @@ static int mg_start(struct cache *cache, struct policy_work *op, struct bio *bio
1535 } 1524 }
1536 1525
1537 mg = alloc_migration(cache); 1526 mg = alloc_migration(cache);
1538 if (!mg) {
1539 policy_complete_background_work(cache->policy, op, false);
1540 background_work_end(cache);
1541 return -ENOMEM;
1542 }
1543 1527
1544 mg->op = op; 1528 mg->op = op;
1545 mg->overwrite_bio = bio; 1529 mg->overwrite_bio = bio;
@@ -1628,10 +1612,6 @@ static int invalidate_lock(struct dm_cache_migration *mg)
1628 struct dm_bio_prison_cell_v2 *prealloc; 1612 struct dm_bio_prison_cell_v2 *prealloc;
1629 1613
1630 prealloc = alloc_prison_cell(cache); 1614 prealloc = alloc_prison_cell(cache);
1631 if (!prealloc) {
1632 invalidate_complete(mg, false);
1633 return -ENOMEM;
1634 }
1635 1615
1636 build_key(mg->invalidate_oblock, oblock_succ(mg->invalidate_oblock), &key); 1616 build_key(mg->invalidate_oblock, oblock_succ(mg->invalidate_oblock), &key);
1637 r = dm_cell_lock_v2(cache->prison, &key, 1617 r = dm_cell_lock_v2(cache->prison, &key,
@@ -1669,10 +1649,6 @@ static int invalidate_start(struct cache *cache, dm_cblock_t cblock,
1669 return -EPERM; 1649 return -EPERM;
1670 1650
1671 mg = alloc_migration(cache); 1651 mg = alloc_migration(cache);
1672 if (!mg) {
1673 background_work_end(cache);
1674 return -ENOMEM;
1675 }
1676 1652
1677 mg->overwrite_bio = bio; 1653 mg->overwrite_bio = bio;
1678 mg->invalidate_cblock = cblock; 1654 mg->invalidate_cblock = cblock;
diff --git a/drivers/md/dm-clone-target.c b/drivers/md/dm-clone-target.c
index cd6f9e9fc98e..4ca8f1977222 100644
--- a/drivers/md/dm-clone-target.c
+++ b/drivers/md/dm-clone-target.c
@@ -591,8 +591,8 @@ static struct hash_table_bucket *get_hash_table_bucket(struct clone *clone,
591 * 591 *
592 * NOTE: Must be called with the bucket lock held 592 * NOTE: Must be called with the bucket lock held
593 */ 593 */
594struct dm_clone_region_hydration *__hash_find(struct hash_table_bucket *bucket, 594static struct dm_clone_region_hydration *__hash_find(struct hash_table_bucket *bucket,
595 unsigned long region_nr) 595 unsigned long region_nr)
596{ 596{
597 struct dm_clone_region_hydration *hd; 597 struct dm_clone_region_hydration *hd;
598 598
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index f150f5c5492b..4fb1a40e68a0 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -18,7 +18,6 @@
18#include <linux/vmalloc.h> 18#include <linux/vmalloc.h>
19#include <linux/log2.h> 19#include <linux/log2.h>
20#include <linux/dm-kcopyd.h> 20#include <linux/dm-kcopyd.h>
21#include <linux/semaphore.h>
22 21
23#include "dm.h" 22#include "dm.h"
24 23
@@ -107,8 +106,8 @@ struct dm_snapshot {
107 /* The on disk metadata handler */ 106 /* The on disk metadata handler */
108 struct dm_exception_store *store; 107 struct dm_exception_store *store;
109 108
110 /* Maximum number of in-flight COW jobs. */ 109 unsigned in_progress;
111 struct semaphore cow_count; 110 struct wait_queue_head in_progress_wait;
112 111
113 struct dm_kcopyd_client *kcopyd_client; 112 struct dm_kcopyd_client *kcopyd_client;
114 113
@@ -162,8 +161,8 @@ struct dm_snapshot {
162 */ 161 */
163#define DEFAULT_COW_THRESHOLD 2048 162#define DEFAULT_COW_THRESHOLD 2048
164 163
165static int cow_threshold = DEFAULT_COW_THRESHOLD; 164static unsigned cow_threshold = DEFAULT_COW_THRESHOLD;
166module_param_named(snapshot_cow_threshold, cow_threshold, int, 0644); 165module_param_named(snapshot_cow_threshold, cow_threshold, uint, 0644);
167MODULE_PARM_DESC(snapshot_cow_threshold, "Maximum number of chunks being copied on write"); 166MODULE_PARM_DESC(snapshot_cow_threshold, "Maximum number of chunks being copied on write");
168 167
169DECLARE_DM_KCOPYD_THROTTLE_WITH_MODULE_PARM(snapshot_copy_throttle, 168DECLARE_DM_KCOPYD_THROTTLE_WITH_MODULE_PARM(snapshot_copy_throttle,
@@ -1327,7 +1326,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1327 goto bad_hash_tables; 1326 goto bad_hash_tables;
1328 } 1327 }
1329 1328
1330 sema_init(&s->cow_count, (cow_threshold > 0) ? cow_threshold : INT_MAX); 1329 init_waitqueue_head(&s->in_progress_wait);
1331 1330
1332 s->kcopyd_client = dm_kcopyd_client_create(&dm_kcopyd_throttle); 1331 s->kcopyd_client = dm_kcopyd_client_create(&dm_kcopyd_throttle);
1333 if (IS_ERR(s->kcopyd_client)) { 1332 if (IS_ERR(s->kcopyd_client)) {
@@ -1509,9 +1508,56 @@ static void snapshot_dtr(struct dm_target *ti)
1509 1508
1510 dm_put_device(ti, s->origin); 1509 dm_put_device(ti, s->origin);
1511 1510
1511 WARN_ON(s->in_progress);
1512
1512 kfree(s); 1513 kfree(s);
1513} 1514}
1514 1515
1516static void account_start_copy(struct dm_snapshot *s)
1517{
1518 spin_lock(&s->in_progress_wait.lock);
1519 s->in_progress++;
1520 spin_unlock(&s->in_progress_wait.lock);
1521}
1522
1523static void account_end_copy(struct dm_snapshot *s)
1524{
1525 spin_lock(&s->in_progress_wait.lock);
1526 BUG_ON(!s->in_progress);
1527 s->in_progress--;
1528 if (likely(s->in_progress <= cow_threshold) &&
1529 unlikely(waitqueue_active(&s->in_progress_wait)))
1530 wake_up_locked(&s->in_progress_wait);
1531 spin_unlock(&s->in_progress_wait.lock);
1532}
1533
1534static bool wait_for_in_progress(struct dm_snapshot *s, bool unlock_origins)
1535{
1536 if (unlikely(s->in_progress > cow_threshold)) {
1537 spin_lock(&s->in_progress_wait.lock);
1538 if (likely(s->in_progress > cow_threshold)) {
1539 /*
1540 * NOTE: this throttle doesn't account for whether
1541 * the caller is servicing an IO that will trigger a COW
1542 * so excess throttling may result for chunks not required
1543 * to be COW'd. But if cow_threshold was reached, extra
1544 * throttling is unlikely to negatively impact performance.
1545 */
1546 DECLARE_WAITQUEUE(wait, current);
1547 __add_wait_queue(&s->in_progress_wait, &wait);
1548 __set_current_state(TASK_UNINTERRUPTIBLE);
1549 spin_unlock(&s->in_progress_wait.lock);
1550 if (unlock_origins)
1551 up_read(&_origins_lock);
1552 io_schedule();
1553 remove_wait_queue(&s->in_progress_wait, &wait);
1554 return false;
1555 }
1556 spin_unlock(&s->in_progress_wait.lock);
1557 }
1558 return true;
1559}
1560
1515/* 1561/*
1516 * Flush a list of buffers. 1562 * Flush a list of buffers.
1517 */ 1563 */
@@ -1527,7 +1573,7 @@ static void flush_bios(struct bio *bio)
1527 } 1573 }
1528} 1574}
1529 1575
1530static int do_origin(struct dm_dev *origin, struct bio *bio); 1576static int do_origin(struct dm_dev *origin, struct bio *bio, bool limit);
1531 1577
1532/* 1578/*
1533 * Flush a list of buffers. 1579 * Flush a list of buffers.
@@ -1540,7 +1586,7 @@ static void retry_origin_bios(struct dm_snapshot *s, struct bio *bio)
1540 while (bio) { 1586 while (bio) {
1541 n = bio->bi_next; 1587 n = bio->bi_next;
1542 bio->bi_next = NULL; 1588 bio->bi_next = NULL;
1543 r = do_origin(s->origin, bio); 1589 r = do_origin(s->origin, bio, false);
1544 if (r == DM_MAPIO_REMAPPED) 1590 if (r == DM_MAPIO_REMAPPED)
1545 generic_make_request(bio); 1591 generic_make_request(bio);
1546 bio = n; 1592 bio = n;
@@ -1732,7 +1778,7 @@ static void copy_callback(int read_err, unsigned long write_err, void *context)
1732 rb_link_node(&pe->out_of_order_node, parent, p); 1778 rb_link_node(&pe->out_of_order_node, parent, p);
1733 rb_insert_color(&pe->out_of_order_node, &s->out_of_order_tree); 1779 rb_insert_color(&pe->out_of_order_node, &s->out_of_order_tree);
1734 } 1780 }
1735 up(&s->cow_count); 1781 account_end_copy(s);
1736} 1782}
1737 1783
1738/* 1784/*
@@ -1756,7 +1802,7 @@ static void start_copy(struct dm_snap_pending_exception *pe)
1756 dest.count = src.count; 1802 dest.count = src.count;
1757 1803
1758 /* Hand over to kcopyd */ 1804 /* Hand over to kcopyd */
1759 down(&s->cow_count); 1805 account_start_copy(s);
1760 dm_kcopyd_copy(s->kcopyd_client, &src, 1, &dest, 0, copy_callback, pe); 1806 dm_kcopyd_copy(s->kcopyd_client, &src, 1, &dest, 0, copy_callback, pe);
1761} 1807}
1762 1808
@@ -1776,7 +1822,7 @@ static void start_full_bio(struct dm_snap_pending_exception *pe,
1776 pe->full_bio = bio; 1822 pe->full_bio = bio;
1777 pe->full_bio_end_io = bio->bi_end_io; 1823 pe->full_bio_end_io = bio->bi_end_io;
1778 1824
1779 down(&s->cow_count); 1825 account_start_copy(s);
1780 callback_data = dm_kcopyd_prepare_callback(s->kcopyd_client, 1826 callback_data = dm_kcopyd_prepare_callback(s->kcopyd_client,
1781 copy_callback, pe); 1827 copy_callback, pe);
1782 1828
@@ -1866,7 +1912,7 @@ static void zero_callback(int read_err, unsigned long write_err, void *context)
1866 struct bio *bio = context; 1912 struct bio *bio = context;
1867 struct dm_snapshot *s = bio->bi_private; 1913 struct dm_snapshot *s = bio->bi_private;
1868 1914
1869 up(&s->cow_count); 1915 account_end_copy(s);
1870 bio->bi_status = write_err ? BLK_STS_IOERR : 0; 1916 bio->bi_status = write_err ? BLK_STS_IOERR : 0;
1871 bio_endio(bio); 1917 bio_endio(bio);
1872} 1918}
@@ -1880,7 +1926,7 @@ static void zero_exception(struct dm_snapshot *s, struct dm_exception *e,
1880 dest.sector = bio->bi_iter.bi_sector; 1926 dest.sector = bio->bi_iter.bi_sector;
1881 dest.count = s->store->chunk_size; 1927 dest.count = s->store->chunk_size;
1882 1928
1883 down(&s->cow_count); 1929 account_start_copy(s);
1884 WARN_ON_ONCE(bio->bi_private); 1930 WARN_ON_ONCE(bio->bi_private);
1885 bio->bi_private = s; 1931 bio->bi_private = s;
1886 dm_kcopyd_zero(s->kcopyd_client, 1, &dest, 0, zero_callback, bio); 1932 dm_kcopyd_zero(s->kcopyd_client, 1, &dest, 0, zero_callback, bio);
@@ -1916,6 +1962,11 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio)
1916 if (!s->valid) 1962 if (!s->valid)
1917 return DM_MAPIO_KILL; 1963 return DM_MAPIO_KILL;
1918 1964
1965 if (bio_data_dir(bio) == WRITE) {
1966 while (unlikely(!wait_for_in_progress(s, false)))
1967 ; /* wait_for_in_progress() has slept */
1968 }
1969
1919 down_read(&s->lock); 1970 down_read(&s->lock);
1920 dm_exception_table_lock(&lock); 1971 dm_exception_table_lock(&lock);
1921 1972
@@ -2112,7 +2163,7 @@ redirect_to_origin:
2112 2163
2113 if (bio_data_dir(bio) == WRITE) { 2164 if (bio_data_dir(bio) == WRITE) {
2114 up_write(&s->lock); 2165 up_write(&s->lock);
2115 return do_origin(s->origin, bio); 2166 return do_origin(s->origin, bio, false);
2116 } 2167 }
2117 2168
2118out_unlock: 2169out_unlock:
@@ -2487,15 +2538,24 @@ next_snapshot:
2487/* 2538/*
2488 * Called on a write from the origin driver. 2539 * Called on a write from the origin driver.
2489 */ 2540 */
2490static int do_origin(struct dm_dev *origin, struct bio *bio) 2541static int do_origin(struct dm_dev *origin, struct bio *bio, bool limit)
2491{ 2542{
2492 struct origin *o; 2543 struct origin *o;
2493 int r = DM_MAPIO_REMAPPED; 2544 int r = DM_MAPIO_REMAPPED;
2494 2545
2546again:
2495 down_read(&_origins_lock); 2547 down_read(&_origins_lock);
2496 o = __lookup_origin(origin->bdev); 2548 o = __lookup_origin(origin->bdev);
2497 if (o) 2549 if (o) {
2550 if (limit) {
2551 struct dm_snapshot *s;
2552 list_for_each_entry(s, &o->snapshots, list)
2553 if (unlikely(!wait_for_in_progress(s, true)))
2554 goto again;
2555 }
2556
2498 r = __origin_write(&o->snapshots, bio->bi_iter.bi_sector, bio); 2557 r = __origin_write(&o->snapshots, bio->bi_iter.bi_sector, bio);
2558 }
2499 up_read(&_origins_lock); 2559 up_read(&_origins_lock);
2500 2560
2501 return r; 2561 return r;
@@ -2608,7 +2668,7 @@ static int origin_map(struct dm_target *ti, struct bio *bio)
2608 dm_accept_partial_bio(bio, available_sectors); 2668 dm_accept_partial_bio(bio, available_sectors);
2609 2669
2610 /* Only tell snapshots if this is a write */ 2670 /* Only tell snapshots if this is a write */
2611 return do_origin(o->dev, bio); 2671 return do_origin(o->dev, bio, true);
2612} 2672}
2613 2673
2614/* 2674/*
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index f61693e59684..1e772287b1c8 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -154,7 +154,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
154 } else { 154 } else {
155 pr_err("md/raid0:%s: cannot assemble multi-zone RAID0 with default_layout setting\n", 155 pr_err("md/raid0:%s: cannot assemble multi-zone RAID0 with default_layout setting\n",
156 mdname(mddev)); 156 mdname(mddev));
157 pr_err("md/raid0: please set raid.default_layout to 1 or 2\n"); 157 pr_err("md/raid0: please set raid0.default_layout to 1 or 2\n");
158 err = -ENOTSUPP; 158 err = -ENOTSUPP;
159 goto abort; 159 goto abort;
160 } 160 }
diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c b/drivers/media/usb/stkwebcam/stk-webcam.c
index cfca3c70599b..21f90a887485 100644
--- a/drivers/media/usb/stkwebcam/stk-webcam.c
+++ b/drivers/media/usb/stkwebcam/stk-webcam.c
@@ -643,8 +643,7 @@ static int v4l_stk_release(struct file *fp)
643 dev->owner = NULL; 643 dev->owner = NULL;
644 } 644 }
645 645
646 if (is_present(dev)) 646 usb_autopm_put_interface(dev->interface);
647 usb_autopm_put_interface(dev->interface);
648 mutex_unlock(&dev->lock); 647 mutex_unlock(&dev->lock);
649 return v4l2_fh_release(fp); 648 return v4l2_fh_release(fp);
650} 649}
diff --git a/drivers/memstick/host/jmb38x_ms.c b/drivers/memstick/host/jmb38x_ms.c
index 32747425297d..64fff6abe60e 100644
--- a/drivers/memstick/host/jmb38x_ms.c
+++ b/drivers/memstick/host/jmb38x_ms.c
@@ -941,7 +941,7 @@ static int jmb38x_ms_probe(struct pci_dev *pdev,
941 if (!cnt) { 941 if (!cnt) {
942 rc = -ENODEV; 942 rc = -ENODEV;
943 pci_dev_busy = 1; 943 pci_dev_busy = 1;
944 goto err_out; 944 goto err_out_int;
945 } 945 }
946 946
947 jm = kzalloc(sizeof(struct jmb38x_ms) 947 jm = kzalloc(sizeof(struct jmb38x_ms)
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 47ae84afac2e..1b1a794d639d 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -527,6 +527,7 @@ static int fastrpc_dma_buf_attach(struct dma_buf *dmabuf,
527 FASTRPC_PHYS(buffer->phys), buffer->size); 527 FASTRPC_PHYS(buffer->phys), buffer->size);
528 if (ret < 0) { 528 if (ret < 0) {
529 dev_err(buffer->dev, "failed to get scatterlist from DMA API\n"); 529 dev_err(buffer->dev, "failed to get scatterlist from DMA API\n");
530 kfree(a);
530 return -EINVAL; 531 return -EINVAL;
531 } 532 }
532 533
diff --git a/drivers/misc/mei/bus-fixup.c b/drivers/misc/mei/bus-fixup.c
index 32e9b1aed2ca..0a2b99e1af45 100644
--- a/drivers/misc/mei/bus-fixup.c
+++ b/drivers/misc/mei/bus-fixup.c
@@ -218,13 +218,21 @@ static void mei_mkhi_fix(struct mei_cl_device *cldev)
218{ 218{
219 int ret; 219 int ret;
220 220
221 /* No need to enable the client if nothing is needed from it */
222 if (!cldev->bus->fw_f_fw_ver_supported &&
223 !cldev->bus->hbm_f_os_supported)
224 return;
225
221 ret = mei_cldev_enable(cldev); 226 ret = mei_cldev_enable(cldev);
222 if (ret) 227 if (ret)
223 return; 228 return;
224 229
225 ret = mei_fwver(cldev); 230 if (cldev->bus->fw_f_fw_ver_supported) {
226 if (ret < 0) 231 ret = mei_fwver(cldev);
227 dev_err(&cldev->dev, "FW version command failed %d\n", ret); 232 if (ret < 0)
233 dev_err(&cldev->dev, "FW version command failed %d\n",
234 ret);
235 }
228 236
229 if (cldev->bus->hbm_f_os_supported) { 237 if (cldev->bus->hbm_f_os_supported) {
230 ret = mei_osver(cldev); 238 ret = mei_osver(cldev);
diff --git a/drivers/misc/mei/hw-me-regs.h b/drivers/misc/mei/hw-me-regs.h
index 77f7dff7098d..c09f8bb49495 100644
--- a/drivers/misc/mei/hw-me-regs.h
+++ b/drivers/misc/mei/hw-me-regs.h
@@ -79,6 +79,9 @@
79#define MEI_DEV_ID_CNP_H 0xA360 /* Cannon Point H */ 79#define MEI_DEV_ID_CNP_H 0xA360 /* Cannon Point H */
80#define MEI_DEV_ID_CNP_H_4 0xA364 /* Cannon Point H 4 (iTouch) */ 80#define MEI_DEV_ID_CNP_H_4 0xA364 /* Cannon Point H 4 (iTouch) */
81 81
82#define MEI_DEV_ID_CMP_LP 0x02e0 /* Comet Point LP */
83#define MEI_DEV_ID_CMP_LP_3 0x02e4 /* Comet Point LP 3 (iTouch) */
84
82#define MEI_DEV_ID_ICP_LP 0x34E0 /* Ice Lake Point LP */ 85#define MEI_DEV_ID_ICP_LP 0x34E0 /* Ice Lake Point LP */
83 86
84#define MEI_DEV_ID_TGP_LP 0xA0E0 /* Tiger Lake Point LP */ 87#define MEI_DEV_ID_TGP_LP 0xA0E0 /* Tiger Lake Point LP */
diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c
index abe1b1f4362f..c4f6991d3028 100644
--- a/drivers/misc/mei/hw-me.c
+++ b/drivers/misc/mei/hw-me.c
@@ -1355,6 +1355,8 @@ static bool mei_me_fw_type_sps(struct pci_dev *pdev)
1355#define MEI_CFG_FW_SPS \ 1355#define MEI_CFG_FW_SPS \
1356 .quirk_probe = mei_me_fw_type_sps 1356 .quirk_probe = mei_me_fw_type_sps
1357 1357
1358#define MEI_CFG_FW_VER_SUPP \
1359 .fw_ver_supported = 1
1358 1360
1359#define MEI_CFG_ICH_HFS \ 1361#define MEI_CFG_ICH_HFS \
1360 .fw_status.count = 0 1362 .fw_status.count = 0
@@ -1392,31 +1394,41 @@ static const struct mei_cfg mei_me_ich10_cfg = {
1392 MEI_CFG_ICH10_HFS, 1394 MEI_CFG_ICH10_HFS,
1393}; 1395};
1394 1396
1395/* PCH devices */ 1397/* PCH6 devices */
1396static const struct mei_cfg mei_me_pch_cfg = { 1398static const struct mei_cfg mei_me_pch6_cfg = {
1397 MEI_CFG_PCH_HFS, 1399 MEI_CFG_PCH_HFS,
1398}; 1400};
1399 1401
1402/* PCH7 devices */
1403static const struct mei_cfg mei_me_pch7_cfg = {
1404 MEI_CFG_PCH_HFS,
1405 MEI_CFG_FW_VER_SUPP,
1406};
1407
1400/* PCH Cougar Point and Patsburg with quirk for Node Manager exclusion */ 1408/* PCH Cougar Point and Patsburg with quirk for Node Manager exclusion */
1401static const struct mei_cfg mei_me_pch_cpt_pbg_cfg = { 1409static const struct mei_cfg mei_me_pch_cpt_pbg_cfg = {
1402 MEI_CFG_PCH_HFS, 1410 MEI_CFG_PCH_HFS,
1411 MEI_CFG_FW_VER_SUPP,
1403 MEI_CFG_FW_NM, 1412 MEI_CFG_FW_NM,
1404}; 1413};
1405 1414
1406/* PCH8 Lynx Point and newer devices */ 1415/* PCH8 Lynx Point and newer devices */
1407static const struct mei_cfg mei_me_pch8_cfg = { 1416static const struct mei_cfg mei_me_pch8_cfg = {
1408 MEI_CFG_PCH8_HFS, 1417 MEI_CFG_PCH8_HFS,
1418 MEI_CFG_FW_VER_SUPP,
1409}; 1419};
1410 1420
1411/* PCH8 Lynx Point with quirk for SPS Firmware exclusion */ 1421/* PCH8 Lynx Point with quirk for SPS Firmware exclusion */
1412static const struct mei_cfg mei_me_pch8_sps_cfg = { 1422static const struct mei_cfg mei_me_pch8_sps_cfg = {
1413 MEI_CFG_PCH8_HFS, 1423 MEI_CFG_PCH8_HFS,
1424 MEI_CFG_FW_VER_SUPP,
1414 MEI_CFG_FW_SPS, 1425 MEI_CFG_FW_SPS,
1415}; 1426};
1416 1427
1417/* Cannon Lake and newer devices */ 1428/* Cannon Lake and newer devices */
1418static const struct mei_cfg mei_me_pch12_cfg = { 1429static const struct mei_cfg mei_me_pch12_cfg = {
1419 MEI_CFG_PCH8_HFS, 1430 MEI_CFG_PCH8_HFS,
1431 MEI_CFG_FW_VER_SUPP,
1420 MEI_CFG_DMA_128, 1432 MEI_CFG_DMA_128,
1421}; 1433};
1422 1434
@@ -1428,7 +1440,8 @@ static const struct mei_cfg *const mei_cfg_list[] = {
1428 [MEI_ME_UNDEF_CFG] = NULL, 1440 [MEI_ME_UNDEF_CFG] = NULL,
1429 [MEI_ME_ICH_CFG] = &mei_me_ich_cfg, 1441 [MEI_ME_ICH_CFG] = &mei_me_ich_cfg,
1430 [MEI_ME_ICH10_CFG] = &mei_me_ich10_cfg, 1442 [MEI_ME_ICH10_CFG] = &mei_me_ich10_cfg,
1431 [MEI_ME_PCH_CFG] = &mei_me_pch_cfg, 1443 [MEI_ME_PCH6_CFG] = &mei_me_pch6_cfg,
1444 [MEI_ME_PCH7_CFG] = &mei_me_pch7_cfg,
1432 [MEI_ME_PCH_CPT_PBG_CFG] = &mei_me_pch_cpt_pbg_cfg, 1445 [MEI_ME_PCH_CPT_PBG_CFG] = &mei_me_pch_cpt_pbg_cfg,
1433 [MEI_ME_PCH8_CFG] = &mei_me_pch8_cfg, 1446 [MEI_ME_PCH8_CFG] = &mei_me_pch8_cfg,
1434 [MEI_ME_PCH8_SPS_CFG] = &mei_me_pch8_sps_cfg, 1447 [MEI_ME_PCH8_SPS_CFG] = &mei_me_pch8_sps_cfg,
@@ -1473,6 +1486,8 @@ struct mei_device *mei_me_dev_init(struct pci_dev *pdev,
1473 mei_device_init(dev, &pdev->dev, &mei_me_hw_ops); 1486 mei_device_init(dev, &pdev->dev, &mei_me_hw_ops);
1474 hw->cfg = cfg; 1487 hw->cfg = cfg;
1475 1488
1489 dev->fw_f_fw_ver_supported = cfg->fw_ver_supported;
1490
1476 return dev; 1491 return dev;
1477} 1492}
1478 1493
diff --git a/drivers/misc/mei/hw-me.h b/drivers/misc/mei/hw-me.h
index 08c84a0de4a8..1d8794828cbc 100644
--- a/drivers/misc/mei/hw-me.h
+++ b/drivers/misc/mei/hw-me.h
@@ -20,11 +20,13 @@
20 * @fw_status: FW status 20 * @fw_status: FW status
21 * @quirk_probe: device exclusion quirk 21 * @quirk_probe: device exclusion quirk
22 * @dma_size: device DMA buffers size 22 * @dma_size: device DMA buffers size
23 * @fw_ver_supported: is fw version retrievable from FW
23 */ 24 */
24struct mei_cfg { 25struct mei_cfg {
25 const struct mei_fw_status fw_status; 26 const struct mei_fw_status fw_status;
26 bool (*quirk_probe)(struct pci_dev *pdev); 27 bool (*quirk_probe)(struct pci_dev *pdev);
27 size_t dma_size[DMA_DSCR_NUM]; 28 size_t dma_size[DMA_DSCR_NUM];
29 u32 fw_ver_supported:1;
28}; 30};
29 31
30 32
@@ -62,7 +64,8 @@ struct mei_me_hw {
62 * @MEI_ME_UNDEF_CFG: Lower sentinel. 64 * @MEI_ME_UNDEF_CFG: Lower sentinel.
63 * @MEI_ME_ICH_CFG: I/O Controller Hub legacy devices. 65 * @MEI_ME_ICH_CFG: I/O Controller Hub legacy devices.
64 * @MEI_ME_ICH10_CFG: I/O Controller Hub platforms Gen10 66 * @MEI_ME_ICH10_CFG: I/O Controller Hub platforms Gen10
65 * @MEI_ME_PCH_CFG: Platform Controller Hub platforms (Up to Gen8). 67 * @MEI_ME_PCH6_CFG: Platform Controller Hub platforms (Gen6).
68 * @MEI_ME_PCH7_CFG: Platform Controller Hub platforms (Gen7).
66 * @MEI_ME_PCH_CPT_PBG_CFG:Platform Controller Hub workstations 69 * @MEI_ME_PCH_CPT_PBG_CFG:Platform Controller Hub workstations
67 * with quirk for Node Manager exclusion. 70 * with quirk for Node Manager exclusion.
68 * @MEI_ME_PCH8_CFG: Platform Controller Hub Gen8 and newer 71 * @MEI_ME_PCH8_CFG: Platform Controller Hub Gen8 and newer
@@ -77,7 +80,8 @@ enum mei_cfg_idx {
77 MEI_ME_UNDEF_CFG, 80 MEI_ME_UNDEF_CFG,
78 MEI_ME_ICH_CFG, 81 MEI_ME_ICH_CFG,
79 MEI_ME_ICH10_CFG, 82 MEI_ME_ICH10_CFG,
80 MEI_ME_PCH_CFG, 83 MEI_ME_PCH6_CFG,
84 MEI_ME_PCH7_CFG,
81 MEI_ME_PCH_CPT_PBG_CFG, 85 MEI_ME_PCH_CPT_PBG_CFG,
82 MEI_ME_PCH8_CFG, 86 MEI_ME_PCH8_CFG,
83 MEI_ME_PCH8_SPS_CFG, 87 MEI_ME_PCH8_SPS_CFG,
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h
index f71a023aed3c..0f2141178299 100644
--- a/drivers/misc/mei/mei_dev.h
+++ b/drivers/misc/mei/mei_dev.h
@@ -426,6 +426,8 @@ struct mei_fw_version {
426 * 426 *
427 * @fw_ver : FW versions 427 * @fw_ver : FW versions
428 * 428 *
429 * @fw_f_fw_ver_supported : fw feature: fw version supported
430 *
429 * @me_clients_rwsem: rw lock over me_clients list 431 * @me_clients_rwsem: rw lock over me_clients list
430 * @me_clients : list of FW clients 432 * @me_clients : list of FW clients
431 * @me_clients_map : FW clients bit map 433 * @me_clients_map : FW clients bit map
@@ -506,6 +508,8 @@ struct mei_device {
506 508
507 struct mei_fw_version fw_ver[MEI_MAX_FW_VER_BLOCKS]; 509 struct mei_fw_version fw_ver[MEI_MAX_FW_VER_BLOCKS];
508 510
511 unsigned int fw_f_fw_ver_supported:1;
512
509 struct rw_semaphore me_clients_rwsem; 513 struct rw_semaphore me_clients_rwsem;
510 struct list_head me_clients; 514 struct list_head me_clients;
511 DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX); 515 DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
diff --git a/drivers/misc/mei/pci-me.c b/drivers/misc/mei/pci-me.c
index d5a92c6eadb3..3dca63eddaa0 100644
--- a/drivers/misc/mei/pci-me.c
+++ b/drivers/misc/mei/pci-me.c
@@ -61,13 +61,13 @@ static const struct pci_device_id mei_me_pci_tbl[] = {
61 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH10_3, MEI_ME_ICH10_CFG)}, 61 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH10_3, MEI_ME_ICH10_CFG)},
62 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH10_4, MEI_ME_ICH10_CFG)}, 62 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH10_4, MEI_ME_ICH10_CFG)},
63 63
64 {MEI_PCI_DEVICE(MEI_DEV_ID_IBXPK_1, MEI_ME_PCH_CFG)}, 64 {MEI_PCI_DEVICE(MEI_DEV_ID_IBXPK_1, MEI_ME_PCH6_CFG)},
65 {MEI_PCI_DEVICE(MEI_DEV_ID_IBXPK_2, MEI_ME_PCH_CFG)}, 65 {MEI_PCI_DEVICE(MEI_DEV_ID_IBXPK_2, MEI_ME_PCH6_CFG)},
66 {MEI_PCI_DEVICE(MEI_DEV_ID_CPT_1, MEI_ME_PCH_CPT_PBG_CFG)}, 66 {MEI_PCI_DEVICE(MEI_DEV_ID_CPT_1, MEI_ME_PCH_CPT_PBG_CFG)},
67 {MEI_PCI_DEVICE(MEI_DEV_ID_PBG_1, MEI_ME_PCH_CPT_PBG_CFG)}, 67 {MEI_PCI_DEVICE(MEI_DEV_ID_PBG_1, MEI_ME_PCH_CPT_PBG_CFG)},
68 {MEI_PCI_DEVICE(MEI_DEV_ID_PPT_1, MEI_ME_PCH_CFG)}, 68 {MEI_PCI_DEVICE(MEI_DEV_ID_PPT_1, MEI_ME_PCH7_CFG)},
69 {MEI_PCI_DEVICE(MEI_DEV_ID_PPT_2, MEI_ME_PCH_CFG)}, 69 {MEI_PCI_DEVICE(MEI_DEV_ID_PPT_2, MEI_ME_PCH7_CFG)},
70 {MEI_PCI_DEVICE(MEI_DEV_ID_PPT_3, MEI_ME_PCH_CFG)}, 70 {MEI_PCI_DEVICE(MEI_DEV_ID_PPT_3, MEI_ME_PCH7_CFG)},
71 {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_H, MEI_ME_PCH8_SPS_CFG)}, 71 {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_H, MEI_ME_PCH8_SPS_CFG)},
72 {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_W, MEI_ME_PCH8_SPS_CFG)}, 72 {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_W, MEI_ME_PCH8_SPS_CFG)},
73 {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_LP, MEI_ME_PCH8_CFG)}, 73 {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_LP, MEI_ME_PCH8_CFG)},
@@ -96,6 +96,9 @@ static const struct pci_device_id mei_me_pci_tbl[] = {
96 {MEI_PCI_DEVICE(MEI_DEV_ID_CNP_H, MEI_ME_PCH12_CFG)}, 96 {MEI_PCI_DEVICE(MEI_DEV_ID_CNP_H, MEI_ME_PCH12_CFG)},
97 {MEI_PCI_DEVICE(MEI_DEV_ID_CNP_H_4, MEI_ME_PCH8_CFG)}, 97 {MEI_PCI_DEVICE(MEI_DEV_ID_CNP_H_4, MEI_ME_PCH8_CFG)},
98 98
99 {MEI_PCI_DEVICE(MEI_DEV_ID_CMP_LP, MEI_ME_PCH12_CFG)},
100 {MEI_PCI_DEVICE(MEI_DEV_ID_CMP_LP_3, MEI_ME_PCH8_CFG)},
101
99 {MEI_PCI_DEVICE(MEI_DEV_ID_ICP_LP, MEI_ME_PCH12_CFG)}, 102 {MEI_PCI_DEVICE(MEI_DEV_ID_ICP_LP, MEI_ME_PCH12_CFG)},
100 103
101 {MEI_PCI_DEVICE(MEI_DEV_ID_TGP_LP, MEI_ME_PCH12_CFG)}, 104 {MEI_PCI_DEVICE(MEI_DEV_ID_TGP_LP, MEI_ME_PCH12_CFG)},
diff --git a/drivers/mmc/host/renesas_sdhi_core.c b/drivers/mmc/host/renesas_sdhi_core.c
index d4ada5cca2d1..234551a68739 100644
--- a/drivers/mmc/host/renesas_sdhi_core.c
+++ b/drivers/mmc/host/renesas_sdhi_core.c
@@ -646,8 +646,8 @@ int renesas_sdhi_probe(struct platform_device *pdev,
646 struct tmio_mmc_dma *dma_priv; 646 struct tmio_mmc_dma *dma_priv;
647 struct tmio_mmc_host *host; 647 struct tmio_mmc_host *host;
648 struct renesas_sdhi *priv; 648 struct renesas_sdhi *priv;
649 int num_irqs, irq, ret, i;
649 struct resource *res; 650 struct resource *res;
650 int irq, ret, i;
651 u16 ver; 651 u16 ver;
652 652
653 of_data = of_device_get_match_data(&pdev->dev); 653 of_data = of_device_get_match_data(&pdev->dev);
@@ -825,24 +825,31 @@ int renesas_sdhi_probe(struct platform_device *pdev,
825 host->hs400_complete = renesas_sdhi_hs400_complete; 825 host->hs400_complete = renesas_sdhi_hs400_complete;
826 } 826 }
827 827
828 i = 0; 828 num_irqs = platform_irq_count(pdev);
829 while (1) { 829 if (num_irqs < 0) {
830 ret = num_irqs;
831 goto eirq;
832 }
833
834 /* There must be at least one IRQ source */
835 if (!num_irqs) {
836 ret = -ENXIO;
837 goto eirq;
838 }
839
840 for (i = 0; i < num_irqs; i++) {
830 irq = platform_get_irq(pdev, i); 841 irq = platform_get_irq(pdev, i);
831 if (irq < 0) 842 if (irq < 0) {
832 break; 843 ret = irq;
833 i++; 844 goto eirq;
845 }
846
834 ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_irq, 0, 847 ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_irq, 0,
835 dev_name(&pdev->dev), host); 848 dev_name(&pdev->dev), host);
836 if (ret) 849 if (ret)
837 goto eirq; 850 goto eirq;
838 } 851 }
839 852
840 /* There must be at least one IRQ source */
841 if (!i) {
842 ret = irq;
843 goto eirq;
844 }
845
846 dev_info(&pdev->dev, "%s base at 0x%08lx max clock rate %u MHz\n", 853 dev_info(&pdev->dev, "%s base at 0x%08lx max clock rate %u MHz\n",
847 mmc_hostname(host->mmc), (unsigned long) 854 mmc_hostname(host->mmc), (unsigned long)
848 (platform_get_resource(pdev, IORESOURCE_MEM, 0)->start), 855 (platform_get_resource(pdev, IORESOURCE_MEM, 0)->start),
diff --git a/drivers/mmc/host/sdhci-iproc.c b/drivers/mmc/host/sdhci-iproc.c
index 2b9cdcd1dd9d..f4f5f0a70cda 100644
--- a/drivers/mmc/host/sdhci-iproc.c
+++ b/drivers/mmc/host/sdhci-iproc.c
@@ -262,6 +262,7 @@ static const struct sdhci_iproc_data bcm2835_data = {
262}; 262};
263 263
264static const struct sdhci_pltfm_data sdhci_bcm2711_pltfm_data = { 264static const struct sdhci_pltfm_data sdhci_bcm2711_pltfm_data = {
265 .quirks = SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12,
265 .ops = &sdhci_iproc_32only_ops, 266 .ops = &sdhci_iproc_32only_ops,
266}; 267};
267 268
diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c
index 81bd9afb0980..98c575de43c7 100644
--- a/drivers/mmc/host/sh_mmcif.c
+++ b/drivers/mmc/host/sh_mmcif.c
@@ -1393,11 +1393,9 @@ static int sh_mmcif_probe(struct platform_device *pdev)
1393 const char *name; 1393 const char *name;
1394 1394
1395 irq[0] = platform_get_irq(pdev, 0); 1395 irq[0] = platform_get_irq(pdev, 0);
1396 irq[1] = platform_get_irq(pdev, 1); 1396 irq[1] = platform_get_irq_optional(pdev, 1);
1397 if (irq[0] < 0) { 1397 if (irq[0] < 0)
1398 dev_err(dev, "Get irq error\n");
1399 return -ENXIO; 1398 return -ENXIO;
1400 }
1401 1399
1402 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1400 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1403 reg = devm_ioremap_resource(dev, res); 1401 reg = devm_ioremap_resource(dev, res);
diff --git a/drivers/mtd/nand/raw/au1550nd.c b/drivers/mtd/nand/raw/au1550nd.c
index 97a97a9ccc36..e10b76089048 100644
--- a/drivers/mtd/nand/raw/au1550nd.c
+++ b/drivers/mtd/nand/raw/au1550nd.c
@@ -134,16 +134,15 @@ static void au_write_buf16(struct nand_chip *this, const u_char *buf, int len)
134 134
135/** 135/**
136 * au_read_buf16 - read chip data into buffer 136 * au_read_buf16 - read chip data into buffer
137 * @mtd: MTD device structure 137 * @this: NAND chip object
138 * @buf: buffer to store date 138 * @buf: buffer to store date
139 * @len: number of bytes to read 139 * @len: number of bytes to read
140 * 140 *
141 * read function for 16bit buswidth 141 * read function for 16bit buswidth
142 */ 142 */
143static void au_read_buf16(struct mtd_info *mtd, u_char *buf, int len) 143static void au_read_buf16(struct nand_chip *this, u_char *buf, int len)
144{ 144{
145 int i; 145 int i;
146 struct nand_chip *this = mtd_to_nand(mtd);
147 u16 *p = (u16 *) buf; 146 u16 *p = (u16 *) buf;
148 len >>= 1; 147 len >>= 1;
149 148
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 1d8621d43160..7acf4a93b592 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -487,7 +487,7 @@ static int write_sr(struct spi_nor *nor, u8 val)
487 SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_WRSR, 1), 487 SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_WRSR, 1),
488 SPI_MEM_OP_NO_ADDR, 488 SPI_MEM_OP_NO_ADDR,
489 SPI_MEM_OP_NO_DUMMY, 489 SPI_MEM_OP_NO_DUMMY,
490 SPI_MEM_OP_DATA_IN(1, nor->bouncebuf, 1)); 490 SPI_MEM_OP_DATA_OUT(1, nor->bouncebuf, 1));
491 491
492 return spi_mem_exec_op(nor->spimem, &op); 492 return spi_mem_exec_op(nor->spimem, &op);
493 } 493 }
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index 8c79bad2a9a5..4f2e6910c623 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -952,7 +952,7 @@ static int alb_upper_dev_walk(struct net_device *upper, void *_data)
952 struct bond_vlan_tag *tags; 952 struct bond_vlan_tag *tags;
953 953
954 if (is_vlan_dev(upper) && 954 if (is_vlan_dev(upper) &&
955 bond->nest_level == vlan_get_encap_level(upper) - 1) { 955 bond->dev->lower_level == upper->lower_level - 1) {
956 if (upper->addr_assign_type == NET_ADDR_STOLEN) { 956 if (upper->addr_assign_type == NET_ADDR_STOLEN) {
957 alb_send_lp_vid(slave, mac_addr, 957 alb_send_lp_vid(slave, mac_addr,
958 vlan_dev_vlan_proto(upper), 958 vlan_dev_vlan_proto(upper),
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 931d9d935686..480f9459b402 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1733,8 +1733,6 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
1733 goto err_upper_unlink; 1733 goto err_upper_unlink;
1734 } 1734 }
1735 1735
1736 bond->nest_level = dev_get_nest_level(bond_dev) + 1;
1737
1738 /* If the mode uses primary, then the following is handled by 1736 /* If the mode uses primary, then the following is handled by
1739 * bond_change_active_slave(). 1737 * bond_change_active_slave().
1740 */ 1738 */
@@ -1816,7 +1814,8 @@ err_detach:
1816 slave_disable_netpoll(new_slave); 1814 slave_disable_netpoll(new_slave);
1817 1815
1818err_close: 1816err_close:
1819 slave_dev->priv_flags &= ~IFF_BONDING; 1817 if (!netif_is_bond_master(slave_dev))
1818 slave_dev->priv_flags &= ~IFF_BONDING;
1820 dev_close(slave_dev); 1819 dev_close(slave_dev);
1821 1820
1822err_restore_mac: 1821err_restore_mac:
@@ -1956,9 +1955,6 @@ static int __bond_release_one(struct net_device *bond_dev,
1956 if (!bond_has_slaves(bond)) { 1955 if (!bond_has_slaves(bond)) {
1957 bond_set_carrier(bond); 1956 bond_set_carrier(bond);
1958 eth_hw_addr_random(bond_dev); 1957 eth_hw_addr_random(bond_dev);
1959 bond->nest_level = SINGLE_DEPTH_NESTING;
1960 } else {
1961 bond->nest_level = dev_get_nest_level(bond_dev) + 1;
1962 } 1958 }
1963 1959
1964 unblock_netpoll_tx(); 1960 unblock_netpoll_tx();
@@ -2017,7 +2013,8 @@ static int __bond_release_one(struct net_device *bond_dev,
2017 else 2013 else
2018 dev_set_mtu(slave_dev, slave->original_mtu); 2014 dev_set_mtu(slave_dev, slave->original_mtu);
2019 2015
2020 slave_dev->priv_flags &= ~IFF_BONDING; 2016 if (!netif_is_bond_master(slave_dev))
2017 slave_dev->priv_flags &= ~IFF_BONDING;
2021 2018
2022 bond_free_slave(slave); 2019 bond_free_slave(slave);
2023 2020
@@ -3442,13 +3439,6 @@ static void bond_fold_stats(struct rtnl_link_stats64 *_res,
3442 } 3439 }
3443} 3440}
3444 3441
3445static int bond_get_nest_level(struct net_device *bond_dev)
3446{
3447 struct bonding *bond = netdev_priv(bond_dev);
3448
3449 return bond->nest_level;
3450}
3451
3452static void bond_get_stats(struct net_device *bond_dev, 3442static void bond_get_stats(struct net_device *bond_dev,
3453 struct rtnl_link_stats64 *stats) 3443 struct rtnl_link_stats64 *stats)
3454{ 3444{
@@ -3457,7 +3447,7 @@ static void bond_get_stats(struct net_device *bond_dev,
3457 struct list_head *iter; 3447 struct list_head *iter;
3458 struct slave *slave; 3448 struct slave *slave;
3459 3449
3460 spin_lock_nested(&bond->stats_lock, bond_get_nest_level(bond_dev)); 3450 spin_lock(&bond->stats_lock);
3461 memcpy(stats, &bond->bond_stats, sizeof(*stats)); 3451 memcpy(stats, &bond->bond_stats, sizeof(*stats));
3462 3452
3463 rcu_read_lock(); 3453 rcu_read_lock();
@@ -4039,7 +4029,7 @@ out:
4039 * this to-be-skipped slave to send a packet out. 4029 * this to-be-skipped slave to send a packet out.
4040 */ 4030 */
4041 old_arr = rtnl_dereference(bond->slave_arr); 4031 old_arr = rtnl_dereference(bond->slave_arr);
4042 for (idx = 0; idx < old_arr->count; idx++) { 4032 for (idx = 0; old_arr != NULL && idx < old_arr->count; idx++) {
4043 if (skipslave == old_arr->arr[idx]) { 4033 if (skipslave == old_arr->arr[idx]) {
4044 old_arr->arr[idx] = 4034 old_arr->arr[idx] =
4045 old_arr->arr[old_arr->count-1]; 4035 old_arr->arr[old_arr->count-1];
@@ -4268,7 +4258,6 @@ static const struct net_device_ops bond_netdev_ops = {
4268 .ndo_neigh_setup = bond_neigh_setup, 4258 .ndo_neigh_setup = bond_neigh_setup,
4269 .ndo_vlan_rx_add_vid = bond_vlan_rx_add_vid, 4259 .ndo_vlan_rx_add_vid = bond_vlan_rx_add_vid,
4270 .ndo_vlan_rx_kill_vid = bond_vlan_rx_kill_vid, 4260 .ndo_vlan_rx_kill_vid = bond_vlan_rx_kill_vid,
4271 .ndo_get_lock_subclass = bond_get_nest_level,
4272#ifdef CONFIG_NET_POLL_CONTROLLER 4261#ifdef CONFIG_NET_POLL_CONTROLLER
4273 .ndo_netpoll_setup = bond_netpoll_setup, 4262 .ndo_netpoll_setup = bond_netpoll_setup,
4274 .ndo_netpoll_cleanup = bond_netpoll_cleanup, 4263 .ndo_netpoll_cleanup = bond_netpoll_cleanup,
@@ -4296,7 +4285,6 @@ void bond_setup(struct net_device *bond_dev)
4296 struct bonding *bond = netdev_priv(bond_dev); 4285 struct bonding *bond = netdev_priv(bond_dev);
4297 4286
4298 spin_lock_init(&bond->mode_lock); 4287 spin_lock_init(&bond->mode_lock);
4299 spin_lock_init(&bond->stats_lock);
4300 bond->params = bonding_defaults; 4288 bond->params = bonding_defaults;
4301 4289
4302 /* Initialize pointers */ 4290 /* Initialize pointers */
@@ -4365,6 +4353,7 @@ static void bond_uninit(struct net_device *bond_dev)
4365 4353
4366 list_del(&bond->bond_list); 4354 list_del(&bond->bond_list);
4367 4355
4356 lockdep_unregister_key(&bond->stats_lock_key);
4368 bond_debug_unregister(bond); 4357 bond_debug_unregister(bond);
4369} 4358}
4370 4359
@@ -4768,8 +4757,9 @@ static int bond_init(struct net_device *bond_dev)
4768 if (!bond->wq) 4757 if (!bond->wq)
4769 return -ENOMEM; 4758 return -ENOMEM;
4770 4759
4771 bond->nest_level = SINGLE_DEPTH_NESTING; 4760 spin_lock_init(&bond->stats_lock);
4772 netdev_lockdep_set_classes(bond_dev); 4761 lockdep_register_key(&bond->stats_lock_key);
4762 lockdep_set_class(&bond->stats_lock, &bond->stats_lock_key);
4773 4763
4774 list_add_tail(&bond->bond_list, &bn->dev_list); 4764 list_add_tail(&bond->bond_list, &bn->dev_list);
4775 4765
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 526ba2ab66f1..cc3536315eff 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -1845,7 +1845,6 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
1845 loc = B53_EG_MIR_CTL; 1845 loc = B53_EG_MIR_CTL;
1846 1846
1847 b53_read16(dev, B53_MGMT_PAGE, loc, &reg); 1847 b53_read16(dev, B53_MGMT_PAGE, loc, &reg);
1848 reg &= ~MIRROR_MASK;
1849 reg |= BIT(port); 1848 reg |= BIT(port);
1850 b53_write16(dev, B53_MGMT_PAGE, loc, reg); 1849 b53_write16(dev, B53_MGMT_PAGE, loc, reg);
1851 1850
diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index a23d3ffdf0c4..24a5e99f7fd5 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -1224,10 +1224,6 @@ static int ksz8795_switch_init(struct ksz_device *dev)
1224{ 1224{
1225 int i; 1225 int i;
1226 1226
1227 mutex_init(&dev->stats_mutex);
1228 mutex_init(&dev->alu_mutex);
1229 mutex_init(&dev->vlan_mutex);
1230
1231 dev->ds->ops = &ksz8795_switch_ops; 1227 dev->ds->ops = &ksz8795_switch_ops;
1232 1228
1233 for (i = 0; i < ARRAY_SIZE(ksz8795_switch_chips); i++) { 1229 for (i = 0; i < ARRAY_SIZE(ksz8795_switch_chips); i++) {
diff --git a/drivers/net/dsa/microchip/ksz8795_spi.c b/drivers/net/dsa/microchip/ksz8795_spi.c
index d0f8153e86b7..8b00f8e6c02f 100644
--- a/drivers/net/dsa/microchip/ksz8795_spi.c
+++ b/drivers/net/dsa/microchip/ksz8795_spi.c
@@ -25,6 +25,7 @@ KSZ_REGMAP_TABLE(ksz8795, 16, SPI_ADDR_SHIFT,
25 25
26static int ksz8795_spi_probe(struct spi_device *spi) 26static int ksz8795_spi_probe(struct spi_device *spi)
27{ 27{
28 struct regmap_config rc;
28 struct ksz_device *dev; 29 struct ksz_device *dev;
29 int i, ret; 30 int i, ret;
30 31
@@ -33,9 +34,9 @@ static int ksz8795_spi_probe(struct spi_device *spi)
33 return -ENOMEM; 34 return -ENOMEM;
34 35
35 for (i = 0; i < ARRAY_SIZE(ksz8795_regmap_config); i++) { 36 for (i = 0; i < ARRAY_SIZE(ksz8795_regmap_config); i++) {
36 dev->regmap[i] = devm_regmap_init_spi(spi, 37 rc = ksz8795_regmap_config[i];
37 &ksz8795_regmap_config 38 rc.lock_arg = &dev->regmap_mutex;
38 [i]); 39 dev->regmap[i] = devm_regmap_init_spi(spi, &rc);
39 if (IS_ERR(dev->regmap[i])) { 40 if (IS_ERR(dev->regmap[i])) {
40 ret = PTR_ERR(dev->regmap[i]); 41 ret = PTR_ERR(dev->regmap[i]);
41 dev_err(&spi->dev, 42 dev_err(&spi->dev,
diff --git a/drivers/net/dsa/microchip/ksz9477_i2c.c b/drivers/net/dsa/microchip/ksz9477_i2c.c
index 0b1e01f0873d..fdffd9e0c518 100644
--- a/drivers/net/dsa/microchip/ksz9477_i2c.c
+++ b/drivers/net/dsa/microchip/ksz9477_i2c.c
@@ -17,6 +17,7 @@ KSZ_REGMAP_TABLE(ksz9477, not_used, 16, 0, 0);
17static int ksz9477_i2c_probe(struct i2c_client *i2c, 17static int ksz9477_i2c_probe(struct i2c_client *i2c,
18 const struct i2c_device_id *i2c_id) 18 const struct i2c_device_id *i2c_id)
19{ 19{
20 struct regmap_config rc;
20 struct ksz_device *dev; 21 struct ksz_device *dev;
21 int i, ret; 22 int i, ret;
22 23
@@ -25,8 +26,9 @@ static int ksz9477_i2c_probe(struct i2c_client *i2c,
25 return -ENOMEM; 26 return -ENOMEM;
26 27
27 for (i = 0; i < ARRAY_SIZE(ksz9477_regmap_config); i++) { 28 for (i = 0; i < ARRAY_SIZE(ksz9477_regmap_config); i++) {
28 dev->regmap[i] = devm_regmap_init_i2c(i2c, 29 rc = ksz9477_regmap_config[i];
29 &ksz9477_regmap_config[i]); 30 rc.lock_arg = &dev->regmap_mutex;
31 dev->regmap[i] = devm_regmap_init_i2c(i2c, &rc);
30 if (IS_ERR(dev->regmap[i])) { 32 if (IS_ERR(dev->regmap[i])) {
31 ret = PTR_ERR(dev->regmap[i]); 33 ret = PTR_ERR(dev->regmap[i]);
32 dev_err(&i2c->dev, 34 dev_err(&i2c->dev,
diff --git a/drivers/net/dsa/microchip/ksz9477_reg.h b/drivers/net/dsa/microchip/ksz9477_reg.h
index 2938e892b631..16939f29faa5 100644
--- a/drivers/net/dsa/microchip/ksz9477_reg.h
+++ b/drivers/net/dsa/microchip/ksz9477_reg.h
@@ -1,5 +1,5 @@
1/* SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2 * 2/*
3 * Microchip KSZ9477 register definitions 3 * Microchip KSZ9477 register definitions
4 * 4 *
5 * Copyright (C) 2017-2018 Microchip Technology Inc. 5 * Copyright (C) 2017-2018 Microchip Technology Inc.
diff --git a/drivers/net/dsa/microchip/ksz9477_spi.c b/drivers/net/dsa/microchip/ksz9477_spi.c
index f4198d6f72be..c5f64959a184 100644
--- a/drivers/net/dsa/microchip/ksz9477_spi.c
+++ b/drivers/net/dsa/microchip/ksz9477_spi.c
@@ -24,6 +24,7 @@ KSZ_REGMAP_TABLE(ksz9477, 32, SPI_ADDR_SHIFT,
24 24
25static int ksz9477_spi_probe(struct spi_device *spi) 25static int ksz9477_spi_probe(struct spi_device *spi)
26{ 26{
27 struct regmap_config rc;
27 struct ksz_device *dev; 28 struct ksz_device *dev;
28 int i, ret; 29 int i, ret;
29 30
@@ -32,8 +33,9 @@ static int ksz9477_spi_probe(struct spi_device *spi)
32 return -ENOMEM; 33 return -ENOMEM;
33 34
34 for (i = 0; i < ARRAY_SIZE(ksz9477_regmap_config); i++) { 35 for (i = 0; i < ARRAY_SIZE(ksz9477_regmap_config); i++) {
35 dev->regmap[i] = devm_regmap_init_spi(spi, 36 rc = ksz9477_regmap_config[i];
36 &ksz9477_regmap_config[i]); 37 rc.lock_arg = &dev->regmap_mutex;
38 dev->regmap[i] = devm_regmap_init_spi(spi, &rc);
37 if (IS_ERR(dev->regmap[i])) { 39 if (IS_ERR(dev->regmap[i])) {
38 ret = PTR_ERR(dev->regmap[i]); 40 ret = PTR_ERR(dev->regmap[i]);
39 dev_err(&spi->dev, 41 dev_err(&spi->dev,
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index b0b870f0c252..fe47180c908b 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -436,7 +436,7 @@ int ksz_switch_register(struct ksz_device *dev,
436 } 436 }
437 437
438 mutex_init(&dev->dev_mutex); 438 mutex_init(&dev->dev_mutex);
439 mutex_init(&dev->stats_mutex); 439 mutex_init(&dev->regmap_mutex);
440 mutex_init(&dev->alu_mutex); 440 mutex_init(&dev->alu_mutex);
441 mutex_init(&dev->vlan_mutex); 441 mutex_init(&dev->vlan_mutex);
442 442
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index dd60d0837fc6..a20ebb749377 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -1,5 +1,5 @@
1/* SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2 * Microchip switch driver common header 2/* Microchip switch driver common header
3 * 3 *
4 * Copyright (C) 2017-2019 Microchip Technology Inc. 4 * Copyright (C) 2017-2019 Microchip Technology Inc.
5 */ 5 */
@@ -47,7 +47,7 @@ struct ksz_device {
47 const char *name; 47 const char *name;
48 48
49 struct mutex dev_mutex; /* device access */ 49 struct mutex dev_mutex; /* device access */
50 struct mutex stats_mutex; /* status access */ 50 struct mutex regmap_mutex; /* regmap access */
51 struct mutex alu_mutex; /* ALU access */ 51 struct mutex alu_mutex; /* ALU access */
52 struct mutex vlan_mutex; /* vlan access */ 52 struct mutex vlan_mutex; /* vlan access */
53 const struct ksz_dev_ops *dev_ops; 53 const struct ksz_dev_ops *dev_ops;
@@ -290,6 +290,18 @@ static inline void ksz_pwrite32(struct ksz_device *dev, int port, int offset,
290 ksz_write32(dev, dev->dev_ops->get_port_addr(port, offset), data); 290 ksz_write32(dev, dev->dev_ops->get_port_addr(port, offset), data);
291} 291}
292 292
293static inline void ksz_regmap_lock(void *__mtx)
294{
295 struct mutex *mtx = __mtx;
296 mutex_lock(mtx);
297}
298
299static inline void ksz_regmap_unlock(void *__mtx)
300{
301 struct mutex *mtx = __mtx;
302 mutex_unlock(mtx);
303}
304
293/* Regmap tables generation */ 305/* Regmap tables generation */
294#define KSZ_SPI_OP_RD 3 306#define KSZ_SPI_OP_RD 3
295#define KSZ_SPI_OP_WR 2 307#define KSZ_SPI_OP_WR 2
@@ -314,6 +326,8 @@ static inline void ksz_pwrite32(struct ksz_device *dev, int port, int offset,
314 .write_flag_mask = \ 326 .write_flag_mask = \
315 KSZ_SPI_OP_FLAG_MASK(KSZ_SPI_OP_WR, swp, \ 327 KSZ_SPI_OP_FLAG_MASK(KSZ_SPI_OP_WR, swp, \
316 regbits, regpad), \ 328 regbits, regpad), \
329 .lock = ksz_regmap_lock, \
330 .unlock = ksz_regmap_unlock, \
317 .reg_format_endian = REGMAP_ENDIAN_BIG, \ 331 .reg_format_endian = REGMAP_ENDIAN_BIG, \
318 .val_format_endian = REGMAP_ENDIAN_BIG \ 332 .val_format_endian = REGMAP_ENDIAN_BIG \
319 } 333 }
diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c
index 684aa51684db..b00274caae4f 100644
--- a/drivers/net/dsa/qca8k.c
+++ b/drivers/net/dsa/qca8k.c
@@ -705,7 +705,7 @@ qca8k_setup(struct dsa_switch *ds)
705 BIT(0) << QCA8K_GLOBAL_FW_CTRL1_UC_DP_S); 705 BIT(0) << QCA8K_GLOBAL_FW_CTRL1_UC_DP_S);
706 706
707 /* Setup connection between CPU port & user ports */ 707 /* Setup connection between CPU port & user ports */
708 for (i = 0; i < DSA_MAX_PORTS; i++) { 708 for (i = 0; i < QCA8K_NUM_PORTS; i++) {
709 /* CPU port gets connected to all user ports of the switch */ 709 /* CPU port gets connected to all user ports of the switch */
710 if (dsa_is_cpu_port(ds, i)) { 710 if (dsa_is_cpu_port(ds, i)) {
711 qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(QCA8K_CPU_PORT), 711 qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(QCA8K_CPU_PORT),
@@ -1077,7 +1077,7 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
1077 if (id != QCA8K_ID_QCA8337) 1077 if (id != QCA8K_ID_QCA8337)
1078 return -ENODEV; 1078 return -ENODEV;
1079 1079
1080 priv->ds = dsa_switch_alloc(&mdiodev->dev, DSA_MAX_PORTS); 1080 priv->ds = dsa_switch_alloc(&mdiodev->dev, QCA8K_NUM_PORTS);
1081 if (!priv->ds) 1081 if (!priv->ds)
1082 return -ENOMEM; 1082 return -ENOMEM;
1083 1083
diff --git a/drivers/net/dsa/rtl8366.c b/drivers/net/dsa/rtl8366.c
index ca3d17e43ed8..ac88caca5ad4 100644
--- a/drivers/net/dsa/rtl8366.c
+++ b/drivers/net/dsa/rtl8366.c
@@ -339,10 +339,12 @@ int rtl8366_vlan_prepare(struct dsa_switch *ds, int port,
339 const struct switchdev_obj_port_vlan *vlan) 339 const struct switchdev_obj_port_vlan *vlan)
340{ 340{
341 struct realtek_smi *smi = ds->priv; 341 struct realtek_smi *smi = ds->priv;
342 u16 vid;
342 int ret; 343 int ret;
343 344
344 if (!smi->ops->is_vlan_valid(smi, port)) 345 for (vid = vlan->vid_begin; vid < vlan->vid_end; vid++)
345 return -EINVAL; 346 if (!smi->ops->is_vlan_valid(smi, vid))
347 return -EINVAL;
346 348
347 dev_info(smi->dev, "prepare VLANs %04x..%04x\n", 349 dev_info(smi->dev, "prepare VLANs %04x..%04x\n",
348 vlan->vid_begin, vlan->vid_end); 350 vlan->vid_begin, vlan->vid_end);
@@ -370,8 +372,9 @@ void rtl8366_vlan_add(struct dsa_switch *ds, int port,
370 u16 vid; 372 u16 vid;
371 int ret; 373 int ret;
372 374
373 if (!smi->ops->is_vlan_valid(smi, port)) 375 for (vid = vlan->vid_begin; vid < vlan->vid_end; vid++)
374 return; 376 if (!smi->ops->is_vlan_valid(smi, vid))
377 return;
375 378
376 dev_info(smi->dev, "add VLAN on port %d, %s, %s\n", 379 dev_info(smi->dev, "add VLAN on port %d, %s, %s\n",
377 port, 380 port,
diff --git a/drivers/net/dsa/rtl8366rb.c b/drivers/net/dsa/rtl8366rb.c
index a268085ffad2..f5cc8b0a7c74 100644
--- a/drivers/net/dsa/rtl8366rb.c
+++ b/drivers/net/dsa/rtl8366rb.c
@@ -507,7 +507,8 @@ static int rtl8366rb_setup_cascaded_irq(struct realtek_smi *smi)
507 irq = of_irq_get(intc, 0); 507 irq = of_irq_get(intc, 0);
508 if (irq <= 0) { 508 if (irq <= 0) {
509 dev_err(smi->dev, "failed to get parent IRQ\n"); 509 dev_err(smi->dev, "failed to get parent IRQ\n");
510 return irq ? irq : -EINVAL; 510 ret = irq ? irq : -EINVAL;
511 goto out_put_node;
511 } 512 }
512 513
513 /* This clears the IRQ status register */ 514 /* This clears the IRQ status register */
@@ -515,7 +516,7 @@ static int rtl8366rb_setup_cascaded_irq(struct realtek_smi *smi)
515 &val); 516 &val);
516 if (ret) { 517 if (ret) {
517 dev_err(smi->dev, "can't read interrupt status\n"); 518 dev_err(smi->dev, "can't read interrupt status\n");
518 return ret; 519 goto out_put_node;
519 } 520 }
520 521
521 /* Fetch IRQ edge information from the descriptor */ 522 /* Fetch IRQ edge information from the descriptor */
@@ -537,7 +538,7 @@ static int rtl8366rb_setup_cascaded_irq(struct realtek_smi *smi)
537 val); 538 val);
538 if (ret) { 539 if (ret) {
539 dev_err(smi->dev, "could not configure IRQ polarity\n"); 540 dev_err(smi->dev, "could not configure IRQ polarity\n");
540 return ret; 541 goto out_put_node;
541 } 542 }
542 543
543 ret = devm_request_threaded_irq(smi->dev, irq, NULL, 544 ret = devm_request_threaded_irq(smi->dev, irq, NULL,
@@ -545,7 +546,7 @@ static int rtl8366rb_setup_cascaded_irq(struct realtek_smi *smi)
545 "RTL8366RB", smi); 546 "RTL8366RB", smi);
546 if (ret) { 547 if (ret) {
547 dev_err(smi->dev, "unable to request irq: %d\n", ret); 548 dev_err(smi->dev, "unable to request irq: %d\n", ret);
548 return ret; 549 goto out_put_node;
549 } 550 }
550 smi->irqdomain = irq_domain_add_linear(intc, 551 smi->irqdomain = irq_domain_add_linear(intc,
551 RTL8366RB_NUM_INTERRUPT, 552 RTL8366RB_NUM_INTERRUPT,
@@ -553,12 +554,15 @@ static int rtl8366rb_setup_cascaded_irq(struct realtek_smi *smi)
553 smi); 554 smi);
554 if (!smi->irqdomain) { 555 if (!smi->irqdomain) {
555 dev_err(smi->dev, "failed to create IRQ domain\n"); 556 dev_err(smi->dev, "failed to create IRQ domain\n");
556 return -EINVAL; 557 ret = -EINVAL;
558 goto out_put_node;
557 } 559 }
558 for (i = 0; i < smi->num_ports; i++) 560 for (i = 0; i < smi->num_ports; i++)
559 irq_set_parent(irq_create_mapping(smi->irqdomain, i), irq); 561 irq_set_parent(irq_create_mapping(smi->irqdomain, i), irq);
560 562
561 return 0; 563out_put_node:
564 of_node_put(intc);
565 return ret;
562} 566}
563 567
564static int rtl8366rb_set_addr(struct realtek_smi *smi) 568static int rtl8366rb_set_addr(struct realtek_smi *smi)
diff --git a/drivers/net/dsa/sja1105/Kconfig b/drivers/net/dsa/sja1105/Kconfig
index f40b248f0b23..ffac0ea4e8d5 100644
--- a/drivers/net/dsa/sja1105/Kconfig
+++ b/drivers/net/dsa/sja1105/Kconfig
@@ -26,8 +26,8 @@ config NET_DSA_SJA1105_PTP
26 26
27config NET_DSA_SJA1105_TAS 27config NET_DSA_SJA1105_TAS
28 bool "Support for the Time-Aware Scheduler on NXP SJA1105" 28 bool "Support for the Time-Aware Scheduler on NXP SJA1105"
29 depends on NET_DSA_SJA1105 29 depends on NET_DSA_SJA1105 && NET_SCH_TAPRIO
30 depends on NET_SCH_TAPRIO 30 depends on NET_SCH_TAPRIO=y || NET_DSA_SJA1105=m
31 help 31 help
32 This enables support for the TTEthernet-based egress scheduling 32 This enables support for the TTEthernet-based egress scheduling
33 engine in the SJA1105 DSA driver, which is controlled using a 33 engine in the SJA1105 DSA driver, which is controlled using a
diff --git a/drivers/net/dsa/sja1105/sja1105.h b/drivers/net/dsa/sja1105/sja1105.h
index e53e494c22e0..fbb564c3beb8 100644
--- a/drivers/net/dsa/sja1105/sja1105.h
+++ b/drivers/net/dsa/sja1105/sja1105.h
@@ -1,5 +1,5 @@
1/* SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2 * Copyright (c) 2018, Sensor-Technik Wiedemann GmbH 2/* Copyright (c) 2018, Sensor-Technik Wiedemann GmbH
3 * Copyright (c) 2018-2019, Vladimir Oltean <olteanv@gmail.com> 3 * Copyright (c) 2018-2019, Vladimir Oltean <olteanv@gmail.com>
4 */ 4 */
5#ifndef _SJA1105_H 5#ifndef _SJA1105_H
diff --git a/drivers/net/dsa/sja1105/sja1105_dynamic_config.h b/drivers/net/dsa/sja1105/sja1105_dynamic_config.h
index 740dadf43f01..1fc0d13dc623 100644
--- a/drivers/net/dsa/sja1105/sja1105_dynamic_config.h
+++ b/drivers/net/dsa/sja1105/sja1105_dynamic_config.h
@@ -1,5 +1,5 @@
1/* SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2 * Copyright (c) 2019, Vladimir Oltean <olteanv@gmail.com> 2/* Copyright (c) 2019, Vladimir Oltean <olteanv@gmail.com>
3 */ 3 */
4#ifndef _SJA1105_DYNAMIC_CONFIG_H 4#ifndef _SJA1105_DYNAMIC_CONFIG_H
5#define _SJA1105_DYNAMIC_CONFIG_H 5#define _SJA1105_DYNAMIC_CONFIG_H
diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c
index b9def744bcb3..7687ddcae159 100644
--- a/drivers/net/dsa/sja1105/sja1105_main.c
+++ b/drivers/net/dsa/sja1105/sja1105_main.c
@@ -1897,7 +1897,9 @@ static int sja1105_set_ageing_time(struct dsa_switch *ds,
1897 return sja1105_static_config_reload(priv); 1897 return sja1105_static_config_reload(priv);
1898} 1898}
1899 1899
1900/* Caller must hold priv->tagger_data.meta_lock */ 1900/* Must be called only with priv->tagger_data.state bit
1901 * SJA1105_HWTS_RX_EN cleared
1902 */
1901static int sja1105_change_rxtstamping(struct sja1105_private *priv, 1903static int sja1105_change_rxtstamping(struct sja1105_private *priv,
1902 bool on) 1904 bool on)
1903{ 1905{
@@ -1954,16 +1956,17 @@ static int sja1105_hwtstamp_set(struct dsa_switch *ds, int port,
1954 break; 1956 break;
1955 } 1957 }
1956 1958
1957 if (rx_on != priv->tagger_data.hwts_rx_en) { 1959 if (rx_on != test_bit(SJA1105_HWTS_RX_EN, &priv->tagger_data.state)) {
1958 spin_lock(&priv->tagger_data.meta_lock); 1960 clear_bit(SJA1105_HWTS_RX_EN, &priv->tagger_data.state);
1961
1959 rc = sja1105_change_rxtstamping(priv, rx_on); 1962 rc = sja1105_change_rxtstamping(priv, rx_on);
1960 spin_unlock(&priv->tagger_data.meta_lock);
1961 if (rc < 0) { 1963 if (rc < 0) {
1962 dev_err(ds->dev, 1964 dev_err(ds->dev,
1963 "Failed to change RX timestamping: %d\n", rc); 1965 "Failed to change RX timestamping: %d\n", rc);
1964 return -EFAULT; 1966 return rc;
1965 } 1967 }
1966 priv->tagger_data.hwts_rx_en = rx_on; 1968 if (rx_on)
1969 set_bit(SJA1105_HWTS_RX_EN, &priv->tagger_data.state);
1967 } 1970 }
1968 1971
1969 if (copy_to_user(ifr->ifr_data, &config, sizeof(config))) 1972 if (copy_to_user(ifr->ifr_data, &config, sizeof(config)))
@@ -1982,7 +1985,7 @@ static int sja1105_hwtstamp_get(struct dsa_switch *ds, int port,
1982 config.tx_type = HWTSTAMP_TX_ON; 1985 config.tx_type = HWTSTAMP_TX_ON;
1983 else 1986 else
1984 config.tx_type = HWTSTAMP_TX_OFF; 1987 config.tx_type = HWTSTAMP_TX_OFF;
1985 if (priv->tagger_data.hwts_rx_en) 1988 if (test_bit(SJA1105_HWTS_RX_EN, &priv->tagger_data.state))
1986 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; 1989 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
1987 else 1990 else
1988 config.rx_filter = HWTSTAMP_FILTER_NONE; 1991 config.rx_filter = HWTSTAMP_FILTER_NONE;
@@ -2005,12 +2008,12 @@ static void sja1105_rxtstamp_work(struct work_struct *work)
2005 2008
2006 mutex_lock(&priv->ptp_lock); 2009 mutex_lock(&priv->ptp_lock);
2007 2010
2008 now = priv->tstamp_cc.read(&priv->tstamp_cc);
2009
2010 while ((skb = skb_dequeue(&data->skb_rxtstamp_queue)) != NULL) { 2011 while ((skb = skb_dequeue(&data->skb_rxtstamp_queue)) != NULL) {
2011 struct skb_shared_hwtstamps *shwt = skb_hwtstamps(skb); 2012 struct skb_shared_hwtstamps *shwt = skb_hwtstamps(skb);
2012 u64 ts; 2013 u64 ts;
2013 2014
2015 now = priv->tstamp_cc.read(&priv->tstamp_cc);
2016
2014 *shwt = (struct skb_shared_hwtstamps) {0}; 2017 *shwt = (struct skb_shared_hwtstamps) {0};
2015 2018
2016 ts = SJA1105_SKB_CB(skb)->meta_tstamp; 2019 ts = SJA1105_SKB_CB(skb)->meta_tstamp;
@@ -2031,7 +2034,7 @@ static bool sja1105_port_rxtstamp(struct dsa_switch *ds, int port,
2031 struct sja1105_private *priv = ds->priv; 2034 struct sja1105_private *priv = ds->priv;
2032 struct sja1105_tagger_data *data = &priv->tagger_data; 2035 struct sja1105_tagger_data *data = &priv->tagger_data;
2033 2036
2034 if (!data->hwts_rx_en) 2037 if (!test_bit(SJA1105_HWTS_RX_EN, &data->state))
2035 return false; 2038 return false;
2036 2039
2037 /* We need to read the full PTP clock to reconstruct the Rx 2040 /* We need to read the full PTP clock to reconstruct the Rx
@@ -2201,6 +2204,7 @@ static int sja1105_probe(struct spi_device *spi)
2201 tagger_data = &priv->tagger_data; 2204 tagger_data = &priv->tagger_data;
2202 skb_queue_head_init(&tagger_data->skb_rxtstamp_queue); 2205 skb_queue_head_init(&tagger_data->skb_rxtstamp_queue);
2203 INIT_WORK(&tagger_data->rxtstamp_work, sja1105_rxtstamp_work); 2206 INIT_WORK(&tagger_data->rxtstamp_work, sja1105_rxtstamp_work);
2207 spin_lock_init(&tagger_data->meta_lock);
2204 2208
2205 /* Connections between dsa_port and sja1105_port */ 2209 /* Connections between dsa_port and sja1105_port */
2206 for (i = 0; i < SJA1105_NUM_PORTS; i++) { 2210 for (i = 0; i < SJA1105_NUM_PORTS; i++) {
diff --git a/drivers/net/dsa/sja1105/sja1105_ptp.h b/drivers/net/dsa/sja1105/sja1105_ptp.h
index af456b0a4d27..394e12a6ad59 100644
--- a/drivers/net/dsa/sja1105/sja1105_ptp.h
+++ b/drivers/net/dsa/sja1105/sja1105_ptp.h
@@ -1,5 +1,5 @@
1/* SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2 * Copyright (c) 2019, Vladimir Oltean <olteanv@gmail.com> 2/* Copyright (c) 2019, Vladimir Oltean <olteanv@gmail.com>
3 */ 3 */
4#ifndef _SJA1105_PTP_H 4#ifndef _SJA1105_PTP_H
5#define _SJA1105_PTP_H 5#define _SJA1105_PTP_H
diff --git a/drivers/net/dsa/sja1105/sja1105_spi.c b/drivers/net/dsa/sja1105/sja1105_spi.c
index 84dc603138cf..58dd37ecde17 100644
--- a/drivers/net/dsa/sja1105/sja1105_spi.c
+++ b/drivers/net/dsa/sja1105/sja1105_spi.c
@@ -409,7 +409,8 @@ int sja1105_static_config_upload(struct sja1105_private *priv)
409 rc = static_config_buf_prepare_for_upload(priv, config_buf, buf_len); 409 rc = static_config_buf_prepare_for_upload(priv, config_buf, buf_len);
410 if (rc < 0) { 410 if (rc < 0) {
411 dev_err(dev, "Invalid config, cannot upload\n"); 411 dev_err(dev, "Invalid config, cannot upload\n");
412 return -EINVAL; 412 rc = -EINVAL;
413 goto out;
413 } 414 }
414 /* Prevent PHY jabbering during switch reset by inhibiting 415 /* Prevent PHY jabbering during switch reset by inhibiting
415 * Tx on all ports and waiting for current packet to drain. 416 * Tx on all ports and waiting for current packet to drain.
@@ -418,7 +419,8 @@ int sja1105_static_config_upload(struct sja1105_private *priv)
418 rc = sja1105_inhibit_tx(priv, port_bitmap, true); 419 rc = sja1105_inhibit_tx(priv, port_bitmap, true);
419 if (rc < 0) { 420 if (rc < 0) {
420 dev_err(dev, "Failed to inhibit Tx on ports\n"); 421 dev_err(dev, "Failed to inhibit Tx on ports\n");
421 return -ENXIO; 422 rc = -ENXIO;
423 goto out;
422 } 424 }
423 /* Wait for an eventual egress packet to finish transmission 425 /* Wait for an eventual egress packet to finish transmission
424 * (reach IFG). It is guaranteed that a second one will not 426 * (reach IFG). It is guaranteed that a second one will not
diff --git a/drivers/net/dsa/sja1105/sja1105_static_config.h b/drivers/net/dsa/sja1105/sja1105_static_config.h
index 7f87022a2d61..f4a5c5c04311 100644
--- a/drivers/net/dsa/sja1105/sja1105_static_config.h
+++ b/drivers/net/dsa/sja1105/sja1105_static_config.h
@@ -1,5 +1,5 @@
1/* SPDX-License-Identifier: BSD-3-Clause 1/* SPDX-License-Identifier: BSD-3-Clause */
2 * Copyright (c) 2016-2018, NXP Semiconductors 2/* Copyright (c) 2016-2018, NXP Semiconductors
3 * Copyright (c) 2018-2019, Vladimir Oltean <olteanv@gmail.com> 3 * Copyright (c) 2018-2019, Vladimir Oltean <olteanv@gmail.com>
4 */ 4 */
5#ifndef _SJA1105_STATIC_CONFIG_H 5#ifndef _SJA1105_STATIC_CONFIG_H
diff --git a/drivers/net/dsa/sja1105/sja1105_tas.h b/drivers/net/dsa/sja1105/sja1105_tas.h
index 0b803c30e640..0aad212d88b2 100644
--- a/drivers/net/dsa/sja1105/sja1105_tas.h
+++ b/drivers/net/dsa/sja1105/sja1105_tas.h
@@ -1,5 +1,5 @@
1/* SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2 * Copyright (c) 2019, Vladimir Oltean <olteanv@gmail.com> 2/* Copyright (c) 2019, Vladimir Oltean <olteanv@gmail.com>
3 */ 3 */
4#ifndef _SJA1105_TAS_H 4#ifndef _SJA1105_TAS_H
5#define _SJA1105_TAS_H 5#define _SJA1105_TAS_H
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_main.c b/drivers/net/ethernet/aquantia/atlantic/aq_main.c
index b4a0fb281e69..bb65dd39f847 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_main.c
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_main.c
@@ -194,9 +194,7 @@ static void aq_ndev_set_multicast_settings(struct net_device *ndev)
194{ 194{
195 struct aq_nic_s *aq_nic = netdev_priv(ndev); 195 struct aq_nic_s *aq_nic = netdev_priv(ndev);
196 196
197 aq_nic_set_packet_filter(aq_nic, ndev->flags); 197 (void)aq_nic_set_multicast_list(aq_nic, ndev);
198
199 aq_nic_set_multicast_list(aq_nic, ndev);
200} 198}
201 199
202static int aq_ndo_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, 200static int aq_ndo_vlan_rx_add_vid(struct net_device *ndev, __be16 proto,
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c
index 8f66e7817811..137c1de4c6ec 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c
@@ -631,9 +631,12 @@ err_exit:
631 631
632int aq_nic_set_multicast_list(struct aq_nic_s *self, struct net_device *ndev) 632int aq_nic_set_multicast_list(struct aq_nic_s *self, struct net_device *ndev)
633{ 633{
634 unsigned int packet_filter = self->packet_filter; 634 const struct aq_hw_ops *hw_ops = self->aq_hw_ops;
635 struct aq_nic_cfg_s *cfg = &self->aq_nic_cfg;
636 unsigned int packet_filter = ndev->flags;
635 struct netdev_hw_addr *ha = NULL; 637 struct netdev_hw_addr *ha = NULL;
636 unsigned int i = 0U; 638 unsigned int i = 0U;
639 int err = 0;
637 640
638 self->mc_list.count = 0; 641 self->mc_list.count = 0;
639 if (netdev_uc_count(ndev) > AQ_HW_MULTICAST_ADDRESS_MAX) { 642 if (netdev_uc_count(ndev) > AQ_HW_MULTICAST_ADDRESS_MAX) {
@@ -641,29 +644,28 @@ int aq_nic_set_multicast_list(struct aq_nic_s *self, struct net_device *ndev)
641 } else { 644 } else {
642 netdev_for_each_uc_addr(ha, ndev) { 645 netdev_for_each_uc_addr(ha, ndev) {
643 ether_addr_copy(self->mc_list.ar[i++], ha->addr); 646 ether_addr_copy(self->mc_list.ar[i++], ha->addr);
644
645 if (i >= AQ_HW_MULTICAST_ADDRESS_MAX)
646 break;
647 } 647 }
648 } 648 }
649 649
650 if (i + netdev_mc_count(ndev) > AQ_HW_MULTICAST_ADDRESS_MAX) { 650 cfg->is_mc_list_enabled = !!(packet_filter & IFF_MULTICAST);
651 packet_filter |= IFF_ALLMULTI; 651 if (cfg->is_mc_list_enabled) {
652 } else { 652 if (i + netdev_mc_count(ndev) > AQ_HW_MULTICAST_ADDRESS_MAX) {
653 netdev_for_each_mc_addr(ha, ndev) { 653 packet_filter |= IFF_ALLMULTI;
654 ether_addr_copy(self->mc_list.ar[i++], ha->addr); 654 } else {
655 655 netdev_for_each_mc_addr(ha, ndev) {
656 if (i >= AQ_HW_MULTICAST_ADDRESS_MAX) 656 ether_addr_copy(self->mc_list.ar[i++],
657 break; 657 ha->addr);
658 }
658 } 659 }
659 } 660 }
660 661
661 if (i > 0 && i <= AQ_HW_MULTICAST_ADDRESS_MAX) { 662 if (i > 0 && i <= AQ_HW_MULTICAST_ADDRESS_MAX) {
662 packet_filter |= IFF_MULTICAST;
663 self->mc_list.count = i; 663 self->mc_list.count = i;
664 self->aq_hw_ops->hw_multicast_list_set(self->aq_hw, 664 err = hw_ops->hw_multicast_list_set(self->aq_hw,
665 self->mc_list.ar, 665 self->mc_list.ar,
666 self->mc_list.count); 666 self->mc_list.count);
667 if (err < 0)
668 return err;
667 } 669 }
668 return aq_nic_set_packet_filter(self, packet_filter); 670 return aq_nic_set_packet_filter(self, packet_filter);
669} 671}
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_ring.c b/drivers/net/ethernet/aquantia/atlantic/aq_ring.c
index 3901d7994ca1..76bdbe1596d6 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_ring.c
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_ring.c
@@ -313,6 +313,7 @@ int aq_ring_rx_clean(struct aq_ring_s *self,
313 break; 313 break;
314 314
315 buff->is_error |= buff_->is_error; 315 buff->is_error |= buff_->is_error;
316 buff->is_cso_err |= buff_->is_cso_err;
316 317
317 } while (!buff_->is_eop); 318 } while (!buff_->is_eop);
318 319
@@ -320,7 +321,7 @@ int aq_ring_rx_clean(struct aq_ring_s *self,
320 err = 0; 321 err = 0;
321 goto err_exit; 322 goto err_exit;
322 } 323 }
323 if (buff->is_error) { 324 if (buff->is_error || buff->is_cso_err) {
324 buff_ = buff; 325 buff_ = buff;
325 do { 326 do {
326 next_ = buff_->next, 327 next_ = buff_->next,
diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c
index 30f7fc4c97ff..2ad3fa6316ce 100644
--- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c
+++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c
@@ -818,14 +818,15 @@ static int hw_atl_b0_hw_packet_filter_set(struct aq_hw_s *self,
818 cfg->is_vlan_force_promisc); 818 cfg->is_vlan_force_promisc);
819 819
820 hw_atl_rpfl2multicast_flr_en_set(self, 820 hw_atl_rpfl2multicast_flr_en_set(self,
821 IS_FILTER_ENABLED(IFF_ALLMULTI), 0); 821 IS_FILTER_ENABLED(IFF_ALLMULTI) &&
822 IS_FILTER_ENABLED(IFF_MULTICAST), 0);
822 823
823 hw_atl_rpfl2_accept_all_mc_packets_set(self, 824 hw_atl_rpfl2_accept_all_mc_packets_set(self,
824 IS_FILTER_ENABLED(IFF_ALLMULTI)); 825 IS_FILTER_ENABLED(IFF_ALLMULTI) &&
826 IS_FILTER_ENABLED(IFF_MULTICAST));
825 827
826 hw_atl_rpfl2broadcast_en_set(self, IS_FILTER_ENABLED(IFF_BROADCAST)); 828 hw_atl_rpfl2broadcast_en_set(self, IS_FILTER_ENABLED(IFF_BROADCAST));
827 829
828 cfg->is_mc_list_enabled = IS_FILTER_ENABLED(IFF_MULTICAST);
829 830
830 for (i = HW_ATL_B0_MAC_MIN; i < HW_ATL_B0_MAC_MAX; ++i) 831 for (i = HW_ATL_B0_MAC_MIN; i < HW_ATL_B0_MAC_MAX; ++i)
831 hw_atl_rpfl2_uc_flr_en_set(self, 832 hw_atl_rpfl2_uc_flr_en_set(self,
@@ -968,14 +969,26 @@ static int hw_atl_b0_hw_interrupt_moderation_set(struct aq_hw_s *self)
968 969
969static int hw_atl_b0_hw_stop(struct aq_hw_s *self) 970static int hw_atl_b0_hw_stop(struct aq_hw_s *self)
970{ 971{
972 int err;
973 u32 val;
974
971 hw_atl_b0_hw_irq_disable(self, HW_ATL_B0_INT_MASK); 975 hw_atl_b0_hw_irq_disable(self, HW_ATL_B0_INT_MASK);
972 976
973 /* Invalidate Descriptor Cache to prevent writing to the cached 977 /* Invalidate Descriptor Cache to prevent writing to the cached
974 * descriptors and to the data pointer of those descriptors 978 * descriptors and to the data pointer of those descriptors
975 */ 979 */
976 hw_atl_rdm_rx_dma_desc_cache_init_set(self, 1); 980 hw_atl_rdm_rx_dma_desc_cache_init_tgl(self);
977 981
978 return aq_hw_err_from_flags(self); 982 err = aq_hw_err_from_flags(self);
983
984 if (err)
985 goto err_exit;
986
987 readx_poll_timeout_atomic(hw_atl_rdm_rx_dma_desc_cache_init_done_get,
988 self, val, val == 1, 1000U, 10000U);
989
990err_exit:
991 return err;
979} 992}
980 993
981static int hw_atl_b0_hw_ring_tx_stop(struct aq_hw_s *self, 994static int hw_atl_b0_hw_ring_tx_stop(struct aq_hw_s *self,
diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh.c
index 1149812ae463..6f340695e6bd 100644
--- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh.c
+++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh.c
@@ -606,12 +606,25 @@ void hw_atl_rpb_rx_flow_ctl_mode_set(struct aq_hw_s *aq_hw, u32 rx_flow_ctl_mode
606 HW_ATL_RPB_RX_FC_MODE_SHIFT, rx_flow_ctl_mode); 606 HW_ATL_RPB_RX_FC_MODE_SHIFT, rx_flow_ctl_mode);
607} 607}
608 608
609void hw_atl_rdm_rx_dma_desc_cache_init_set(struct aq_hw_s *aq_hw, u32 init) 609void hw_atl_rdm_rx_dma_desc_cache_init_tgl(struct aq_hw_s *aq_hw)
610{ 610{
611 u32 val;
612
613 val = aq_hw_read_reg_bit(aq_hw, HW_ATL_RDM_RX_DMA_DESC_CACHE_INIT_ADR,
614 HW_ATL_RDM_RX_DMA_DESC_CACHE_INIT_MSK,
615 HW_ATL_RDM_RX_DMA_DESC_CACHE_INIT_SHIFT);
616
611 aq_hw_write_reg_bit(aq_hw, HW_ATL_RDM_RX_DMA_DESC_CACHE_INIT_ADR, 617 aq_hw_write_reg_bit(aq_hw, HW_ATL_RDM_RX_DMA_DESC_CACHE_INIT_ADR,
612 HW_ATL_RDM_RX_DMA_DESC_CACHE_INIT_MSK, 618 HW_ATL_RDM_RX_DMA_DESC_CACHE_INIT_MSK,
613 HW_ATL_RDM_RX_DMA_DESC_CACHE_INIT_SHIFT, 619 HW_ATL_RDM_RX_DMA_DESC_CACHE_INIT_SHIFT,
614 init); 620 val ^ 1);
621}
622
623u32 hw_atl_rdm_rx_dma_desc_cache_init_done_get(struct aq_hw_s *aq_hw)
624{
625 return aq_hw_read_reg_bit(aq_hw, RDM_RX_DMA_DESC_CACHE_INIT_DONE_ADR,
626 RDM_RX_DMA_DESC_CACHE_INIT_DONE_MSK,
627 RDM_RX_DMA_DESC_CACHE_INIT_DONE_SHIFT);
615} 628}
616 629
617void hw_atl_rpb_rx_pkt_buff_size_per_tc_set(struct aq_hw_s *aq_hw, 630void hw_atl_rpb_rx_pkt_buff_size_per_tc_set(struct aq_hw_s *aq_hw,
diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh.h b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh.h
index 0c37abbabca5..c3ee278c3747 100644
--- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh.h
+++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh.h
@@ -313,8 +313,11 @@ void hw_atl_rpb_rx_pkt_buff_size_per_tc_set(struct aq_hw_s *aq_hw,
313 u32 rx_pkt_buff_size_per_tc, 313 u32 rx_pkt_buff_size_per_tc,
314 u32 buffer); 314 u32 buffer);
315 315
316/* set rdm rx dma descriptor cache init */ 316/* toggle rdm rx dma descriptor cache init */
317void hw_atl_rdm_rx_dma_desc_cache_init_set(struct aq_hw_s *aq_hw, u32 init); 317void hw_atl_rdm_rx_dma_desc_cache_init_tgl(struct aq_hw_s *aq_hw);
318
319/* get rdm rx dma descriptor cache init done */
320u32 hw_atl_rdm_rx_dma_desc_cache_init_done_get(struct aq_hw_s *aq_hw);
318 321
319/* set rx xoff enable (per tc) */ 322/* set rx xoff enable (per tc) */
320void hw_atl_rpb_rx_xoff_en_per_tc_set(struct aq_hw_s *aq_hw, u32 rx_xoff_en_per_tc, 323void hw_atl_rpb_rx_xoff_en_per_tc_set(struct aq_hw_s *aq_hw, u32 rx_xoff_en_per_tc,
diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh_internal.h b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh_internal.h
index c3febcdfa92e..35887ad89025 100644
--- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh_internal.h
+++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh_internal.h
@@ -318,6 +318,25 @@
318/* default value of bitfield rdm_desc_init_i */ 318/* default value of bitfield rdm_desc_init_i */
319#define HW_ATL_RDM_RX_DMA_DESC_CACHE_INIT_DEFAULT 0x0 319#define HW_ATL_RDM_RX_DMA_DESC_CACHE_INIT_DEFAULT 0x0
320 320
321/* rdm_desc_init_done_i bitfield definitions
322 * preprocessor definitions for the bitfield rdm_desc_init_done_i.
323 * port="pif_rdm_desc_init_done_i"
324 */
325
326/* register address for bitfield rdm_desc_init_done_i */
327#define RDM_RX_DMA_DESC_CACHE_INIT_DONE_ADR 0x00005a10
328/* bitmask for bitfield rdm_desc_init_done_i */
329#define RDM_RX_DMA_DESC_CACHE_INIT_DONE_MSK 0x00000001U
330/* inverted bitmask for bitfield rdm_desc_init_done_i */
331#define RDM_RX_DMA_DESC_CACHE_INIT_DONE_MSKN 0xfffffffe
332/* lower bit position of bitfield rdm_desc_init_done_i */
333#define RDM_RX_DMA_DESC_CACHE_INIT_DONE_SHIFT 0U
334/* width of bitfield rdm_desc_init_done_i */
335#define RDM_RX_DMA_DESC_CACHE_INIT_DONE_WIDTH 1
336/* default value of bitfield rdm_desc_init_done_i */
337#define RDM_RX_DMA_DESC_CACHE_INIT_DONE_DEFAULT 0x0
338
339
321/* rx int_desc_wrb_en bitfield definitions 340/* rx int_desc_wrb_en bitfield definitions
322 * preprocessor definitions for the bitfield "int_desc_wrb_en". 341 * preprocessor definitions for the bitfield "int_desc_wrb_en".
323 * port="pif_rdm_int_desc_wrb_en_i" 342 * port="pif_rdm_int_desc_wrb_en_i"
diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
index da726489e3c8..7bc51f8d6f2f 100644
--- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
+++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
@@ -337,7 +337,7 @@ static int aq_fw2x_get_phy_temp(struct aq_hw_s *self, int *temp)
337 /* Convert PHY temperature from 1/256 degree Celsius 337 /* Convert PHY temperature from 1/256 degree Celsius
338 * to 1/1000 degree Celsius. 338 * to 1/1000 degree Celsius.
339 */ 339 */
340 *temp = temp_res * 1000 / 256; 340 *temp = (temp_res & 0xFFFF) * 1000 / 256;
341 341
342 return 0; 342 return 0;
343} 343}
diff --git a/drivers/net/ethernet/arc/emac_rockchip.c b/drivers/net/ethernet/arc/emac_rockchip.c
index 42d2e1b02c44..664d664e0925 100644
--- a/drivers/net/ethernet/arc/emac_rockchip.c
+++ b/drivers/net/ethernet/arc/emac_rockchip.c
@@ -256,6 +256,9 @@ static int emac_rockchip_remove(struct platform_device *pdev)
256 if (priv->regulator) 256 if (priv->regulator)
257 regulator_disable(priv->regulator); 257 regulator_disable(priv->regulator);
258 258
259 if (priv->soc_data->need_div_macclk)
260 clk_disable_unprepare(priv->macclk);
261
259 free_netdev(ndev); 262 free_netdev(ndev);
260 return err; 263 return err;
261} 264}
diff --git a/drivers/net/ethernet/atheros/ag71xx.c b/drivers/net/ethernet/atheros/ag71xx.c
index 7548247455d7..1b1a09095c0d 100644
--- a/drivers/net/ethernet/atheros/ag71xx.c
+++ b/drivers/net/ethernet/atheros/ag71xx.c
@@ -526,7 +526,7 @@ static int ag71xx_mdio_probe(struct ag71xx *ag)
526 struct device *dev = &ag->pdev->dev; 526 struct device *dev = &ag->pdev->dev;
527 struct net_device *ndev = ag->ndev; 527 struct net_device *ndev = ag->ndev;
528 static struct mii_bus *mii_bus; 528 static struct mii_bus *mii_bus;
529 struct device_node *np; 529 struct device_node *np, *mnp;
530 int err; 530 int err;
531 531
532 np = dev->of_node; 532 np = dev->of_node;
@@ -571,7 +571,9 @@ static int ag71xx_mdio_probe(struct ag71xx *ag)
571 msleep(200); 571 msleep(200);
572 } 572 }
573 573
574 err = of_mdiobus_register(mii_bus, np); 574 mnp = of_get_child_by_name(np, "mdio");
575 err = of_mdiobus_register(mii_bus, mnp);
576 of_node_put(mnp);
575 if (err) 577 if (err)
576 goto mdio_err_put_clk; 578 goto mdio_err_put_clk;
577 579
diff --git a/drivers/net/ethernet/broadcom/Kconfig b/drivers/net/ethernet/broadcom/Kconfig
index e24f5d2b6afe..53055ce5dfd6 100644
--- a/drivers/net/ethernet/broadcom/Kconfig
+++ b/drivers/net/ethernet/broadcom/Kconfig
@@ -8,7 +8,6 @@ config NET_VENDOR_BROADCOM
8 default y 8 default y
9 depends on (SSB_POSSIBLE && HAS_DMA) || PCI || BCM63XX || \ 9 depends on (SSB_POSSIBLE && HAS_DMA) || PCI || BCM63XX || \
10 SIBYTE_SB1xxx_SOC 10 SIBYTE_SB1xxx_SOC
11 select DIMLIB
12 ---help--- 11 ---help---
13 If you have a network (Ethernet) chipset belonging to this class, 12 If you have a network (Ethernet) chipset belonging to this class,
14 say Y. 13 say Y.
@@ -69,6 +68,7 @@ config BCMGENET
69 select FIXED_PHY 68 select FIXED_PHY
70 select BCM7XXX_PHY 69 select BCM7XXX_PHY
71 select MDIO_BCM_UNIMAC 70 select MDIO_BCM_UNIMAC
71 select DIMLIB
72 help 72 help
73 This driver supports the built-in Ethernet MACs found in the 73 This driver supports the built-in Ethernet MACs found in the
74 Broadcom BCM7xxx Set Top Box family chipset. 74 Broadcom BCM7xxx Set Top Box family chipset.
@@ -188,6 +188,7 @@ config SYSTEMPORT
188 select MII 188 select MII
189 select PHYLIB 189 select PHYLIB
190 select FIXED_PHY 190 select FIXED_PHY
191 select DIMLIB
191 help 192 help
192 This driver supports the built-in Ethernet MACs found in the 193 This driver supports the built-in Ethernet MACs found in the
193 Broadcom BCM7xxx Set Top Box family chipset using an internal 194 Broadcom BCM7xxx Set Top Box family chipset using an internal
@@ -200,6 +201,7 @@ config BNXT
200 select LIBCRC32C 201 select LIBCRC32C
201 select NET_DEVLINK 202 select NET_DEVLINK
202 select PAGE_POOL 203 select PAGE_POOL
204 select DIMLIB
203 ---help--- 205 ---help---
204 This driver supports Broadcom NetXtreme-C/E 10/25/40/50 gigabit 206 This driver supports Broadcom NetXtreme-C/E 10/25/40/50 gigabit
205 Ethernet cards. To compile this driver as a module, choose M here: 207 Ethernet cards. To compile this driver as a module, choose M here:
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index b4a8cf620a0c..04ec909e06df 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -10382,7 +10382,8 @@ static void bnxt_cleanup_pci(struct bnxt *bp)
10382{ 10382{
10383 bnxt_unmap_bars(bp, bp->pdev); 10383 bnxt_unmap_bars(bp, bp->pdev);
10384 pci_release_regions(bp->pdev); 10384 pci_release_regions(bp->pdev);
10385 pci_disable_device(bp->pdev); 10385 if (pci_is_enabled(bp->pdev))
10386 pci_disable_device(bp->pdev);
10386} 10387}
10387 10388
10388static void bnxt_init_dflt_coal(struct bnxt *bp) 10389static void bnxt_init_dflt_coal(struct bnxt *bp)
@@ -10669,14 +10670,11 @@ static void bnxt_fw_reset_task(struct work_struct *work)
10669 bp->fw_reset_state = BNXT_FW_RESET_STATE_RESET_FW; 10670 bp->fw_reset_state = BNXT_FW_RESET_STATE_RESET_FW;
10670 } 10671 }
10671 /* fall through */ 10672 /* fall through */
10672 case BNXT_FW_RESET_STATE_RESET_FW: { 10673 case BNXT_FW_RESET_STATE_RESET_FW:
10673 u32 wait_dsecs = bp->fw_health->post_reset_wait_dsecs;
10674
10675 bnxt_reset_all(bp); 10674 bnxt_reset_all(bp);
10676 bp->fw_reset_state = BNXT_FW_RESET_STATE_ENABLE_DEV; 10675 bp->fw_reset_state = BNXT_FW_RESET_STATE_ENABLE_DEV;
10677 bnxt_queue_fw_reset_work(bp, wait_dsecs * HZ / 10); 10676 bnxt_queue_fw_reset_work(bp, bp->fw_reset_min_dsecs * HZ / 10);
10678 return; 10677 return;
10679 }
10680 case BNXT_FW_RESET_STATE_ENABLE_DEV: 10678 case BNXT_FW_RESET_STATE_ENABLE_DEV:
10681 if (test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state) && 10679 if (test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state) &&
10682 bp->fw_health) { 10680 bp->fw_health) {
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c
index e664392dccc0..7151244f8c7d 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c
@@ -29,25 +29,20 @@ static int bnxt_fw_reporter_diagnose(struct devlink_health_reporter *reporter,
29 val = bnxt_fw_health_readl(bp, BNXT_FW_HEALTH_REG); 29 val = bnxt_fw_health_readl(bp, BNXT_FW_HEALTH_REG);
30 health_status = val & 0xffff; 30 health_status = val & 0xffff;
31 31
32 if (health_status == BNXT_FW_STATUS_HEALTHY) { 32 if (health_status < BNXT_FW_STATUS_HEALTHY) {
33 rc = devlink_fmsg_string_pair_put(fmsg, "FW status", 33 rc = devlink_fmsg_string_pair_put(fmsg, "Description",
34 "Healthy;"); 34 "Not yet completed initialization");
35 if (rc)
36 return rc;
37 } else if (health_status < BNXT_FW_STATUS_HEALTHY) {
38 rc = devlink_fmsg_string_pair_put(fmsg, "FW status",
39 "Not yet completed initialization;");
40 if (rc) 35 if (rc)
41 return rc; 36 return rc;
42 } else if (health_status > BNXT_FW_STATUS_HEALTHY) { 37 } else if (health_status > BNXT_FW_STATUS_HEALTHY) {
43 rc = devlink_fmsg_string_pair_put(fmsg, "FW status", 38 rc = devlink_fmsg_string_pair_put(fmsg, "Description",
44 "Encountered fatal error and cannot recover;"); 39 "Encountered fatal error and cannot recover");
45 if (rc) 40 if (rc)
46 return rc; 41 return rc;
47 } 42 }
48 43
49 if (val >> 16) { 44 if (val >> 16) {
50 rc = devlink_fmsg_u32_pair_put(fmsg, "Error", val >> 16); 45 rc = devlink_fmsg_u32_pair_put(fmsg, "Error code", val >> 16);
51 if (rc) 46 if (rc)
52 return rc; 47 return rc;
53 } 48 }
@@ -215,25 +210,68 @@ enum bnxt_dl_param_id {
215 210
216static const struct bnxt_dl_nvm_param nvm_params[] = { 211static const struct bnxt_dl_nvm_param nvm_params[] = {
217 {DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV, NVM_OFF_ENABLE_SRIOV, 212 {DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV, NVM_OFF_ENABLE_SRIOV,
218 BNXT_NVM_SHARED_CFG, 1}, 213 BNXT_NVM_SHARED_CFG, 1, 1},
219 {DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI, NVM_OFF_IGNORE_ARI, 214 {DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI, NVM_OFF_IGNORE_ARI,
220 BNXT_NVM_SHARED_CFG, 1}, 215 BNXT_NVM_SHARED_CFG, 1, 1},
221 {DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX, 216 {DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
222 NVM_OFF_MSIX_VEC_PER_PF_MAX, BNXT_NVM_SHARED_CFG, 10}, 217 NVM_OFF_MSIX_VEC_PER_PF_MAX, BNXT_NVM_SHARED_CFG, 10, 4},
223 {DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN, 218 {DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
224 NVM_OFF_MSIX_VEC_PER_PF_MIN, BNXT_NVM_SHARED_CFG, 7}, 219 NVM_OFF_MSIX_VEC_PER_PF_MIN, BNXT_NVM_SHARED_CFG, 7, 4},
225 {BNXT_DEVLINK_PARAM_ID_GRE_VER_CHECK, NVM_OFF_DIS_GRE_VER_CHECK, 220 {BNXT_DEVLINK_PARAM_ID_GRE_VER_CHECK, NVM_OFF_DIS_GRE_VER_CHECK,
226 BNXT_NVM_SHARED_CFG, 1}, 221 BNXT_NVM_SHARED_CFG, 1, 1},
227}; 222};
228 223
224union bnxt_nvm_data {
225 u8 val8;
226 __le32 val32;
227};
228
229static void bnxt_copy_to_nvm_data(union bnxt_nvm_data *dst,
230 union devlink_param_value *src,
231 int nvm_num_bits, int dl_num_bytes)
232{
233 u32 val32 = 0;
234
235 if (nvm_num_bits == 1) {
236 dst->val8 = src->vbool;
237 return;
238 }
239 if (dl_num_bytes == 4)
240 val32 = src->vu32;
241 else if (dl_num_bytes == 2)
242 val32 = (u32)src->vu16;
243 else if (dl_num_bytes == 1)
244 val32 = (u32)src->vu8;
245 dst->val32 = cpu_to_le32(val32);
246}
247
248static void bnxt_copy_from_nvm_data(union devlink_param_value *dst,
249 union bnxt_nvm_data *src,
250 int nvm_num_bits, int dl_num_bytes)
251{
252 u32 val32;
253
254 if (nvm_num_bits == 1) {
255 dst->vbool = src->val8;
256 return;
257 }
258 val32 = le32_to_cpu(src->val32);
259 if (dl_num_bytes == 4)
260 dst->vu32 = val32;
261 else if (dl_num_bytes == 2)
262 dst->vu16 = (u16)val32;
263 else if (dl_num_bytes == 1)
264 dst->vu8 = (u8)val32;
265}
266
229static int bnxt_hwrm_nvm_req(struct bnxt *bp, u32 param_id, void *msg, 267static int bnxt_hwrm_nvm_req(struct bnxt *bp, u32 param_id, void *msg,
230 int msg_len, union devlink_param_value *val) 268 int msg_len, union devlink_param_value *val)
231{ 269{
232 struct hwrm_nvm_get_variable_input *req = msg; 270 struct hwrm_nvm_get_variable_input *req = msg;
233 void *data_addr = NULL, *buf = NULL;
234 struct bnxt_dl_nvm_param nvm_param; 271 struct bnxt_dl_nvm_param nvm_param;
235 int bytesize, idx = 0, rc, i; 272 union bnxt_nvm_data *data;
236 dma_addr_t data_dma_addr; 273 dma_addr_t data_dma_addr;
274 int idx = 0, rc, i;
237 275
238 /* Get/Set NVM CFG parameter is supported only on PFs */ 276 /* Get/Set NVM CFG parameter is supported only on PFs */
239 if (BNXT_VF(bp)) 277 if (BNXT_VF(bp))
@@ -254,47 +292,31 @@ static int bnxt_hwrm_nvm_req(struct bnxt *bp, u32 param_id, void *msg,
254 else if (nvm_param.dir_type == BNXT_NVM_FUNC_CFG) 292 else if (nvm_param.dir_type == BNXT_NVM_FUNC_CFG)
255 idx = bp->pf.fw_fid - BNXT_FIRST_PF_FID; 293 idx = bp->pf.fw_fid - BNXT_FIRST_PF_FID;
256 294
257 bytesize = roundup(nvm_param.num_bits, BITS_PER_BYTE) / BITS_PER_BYTE; 295 data = dma_alloc_coherent(&bp->pdev->dev, sizeof(*data),
258 switch (bytesize) { 296 &data_dma_addr, GFP_KERNEL);
259 case 1: 297 if (!data)
260 if (nvm_param.num_bits == 1)
261 buf = &val->vbool;
262 else
263 buf = &val->vu8;
264 break;
265 case 2:
266 buf = &val->vu16;
267 break;
268 case 4:
269 buf = &val->vu32;
270 break;
271 default:
272 return -EFAULT;
273 }
274
275 data_addr = dma_alloc_coherent(&bp->pdev->dev, bytesize,
276 &data_dma_addr, GFP_KERNEL);
277 if (!data_addr)
278 return -ENOMEM; 298 return -ENOMEM;
279 299
280 req->dest_data_addr = cpu_to_le64(data_dma_addr); 300 req->dest_data_addr = cpu_to_le64(data_dma_addr);
281 req->data_len = cpu_to_le16(nvm_param.num_bits); 301 req->data_len = cpu_to_le16(nvm_param.nvm_num_bits);
282 req->option_num = cpu_to_le16(nvm_param.offset); 302 req->option_num = cpu_to_le16(nvm_param.offset);
283 req->index_0 = cpu_to_le16(idx); 303 req->index_0 = cpu_to_le16(idx);
284 if (idx) 304 if (idx)
285 req->dimensions = cpu_to_le16(1); 305 req->dimensions = cpu_to_le16(1);
286 306
287 if (req->req_type == cpu_to_le16(HWRM_NVM_SET_VARIABLE)) { 307 if (req->req_type == cpu_to_le16(HWRM_NVM_SET_VARIABLE)) {
288 memcpy(data_addr, buf, bytesize); 308 bnxt_copy_to_nvm_data(data, val, nvm_param.nvm_num_bits,
309 nvm_param.dl_num_bytes);
289 rc = hwrm_send_message(bp, msg, msg_len, HWRM_CMD_TIMEOUT); 310 rc = hwrm_send_message(bp, msg, msg_len, HWRM_CMD_TIMEOUT);
290 } else { 311 } else {
291 rc = hwrm_send_message_silent(bp, msg, msg_len, 312 rc = hwrm_send_message_silent(bp, msg, msg_len,
292 HWRM_CMD_TIMEOUT); 313 HWRM_CMD_TIMEOUT);
314 if (!rc)
315 bnxt_copy_from_nvm_data(val, data,
316 nvm_param.nvm_num_bits,
317 nvm_param.dl_num_bytes);
293 } 318 }
294 if (!rc && req->req_type == cpu_to_le16(HWRM_NVM_GET_VARIABLE)) 319 dma_free_coherent(&bp->pdev->dev, sizeof(*data), data, data_dma_addr);
295 memcpy(buf, data_addr, bytesize);
296
297 dma_free_coherent(&bp->pdev->dev, bytesize, data_addr, data_dma_addr);
298 if (rc == -EACCES) 320 if (rc == -EACCES)
299 netdev_err(bp->dev, "PF does not have admin privileges to modify NVM config\n"); 321 netdev_err(bp->dev, "PF does not have admin privileges to modify NVM config\n");
300 return rc; 322 return rc;
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.h b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.h
index b97e0baeb42d..2f4fd0a7d04b 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.h
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.h
@@ -52,7 +52,8 @@ struct bnxt_dl_nvm_param {
52 u16 id; 52 u16 id;
53 u16 offset; 53 u16 offset;
54 u16 dir_type; 54 u16 dir_type;
55 u16 num_bits; 55 u16 nvm_num_bits;
56 u8 dl_num_bytes;
56}; 57};
57 58
58void bnxt_devlink_health_report(struct bnxt *bp, unsigned long event); 59void bnxt_devlink_health_report(struct bnxt *bp, unsigned long event);
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index 12cb77ef1081..0f138280315a 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -2018,6 +2018,8 @@ static void bcmgenet_link_intr_enable(struct bcmgenet_priv *priv)
2018 */ 2018 */
2019 if (priv->internal_phy) { 2019 if (priv->internal_phy) {
2020 int0_enable |= UMAC_IRQ_LINK_EVENT; 2020 int0_enable |= UMAC_IRQ_LINK_EVENT;
2021 if (GENET_IS_V1(priv) || GENET_IS_V2(priv) || GENET_IS_V3(priv))
2022 int0_enable |= UMAC_IRQ_PHY_DET_R;
2021 } else if (priv->ext_phy) { 2023 } else if (priv->ext_phy) {
2022 int0_enable |= UMAC_IRQ_LINK_EVENT; 2024 int0_enable |= UMAC_IRQ_LINK_EVENT;
2023 } else if (priv->phy_interface == PHY_INTERFACE_MODE_MOCA) { 2025 } else if (priv->phy_interface == PHY_INTERFACE_MODE_MOCA) {
@@ -2611,11 +2613,14 @@ static void bcmgenet_irq_task(struct work_struct *work)
2611 priv->irq0_stat = 0; 2613 priv->irq0_stat = 0;
2612 spin_unlock_irq(&priv->lock); 2614 spin_unlock_irq(&priv->lock);
2613 2615
2616 if (status & UMAC_IRQ_PHY_DET_R &&
2617 priv->dev->phydev->autoneg != AUTONEG_ENABLE)
2618 phy_init_hw(priv->dev->phydev);
2619
2614 /* Link UP/DOWN event */ 2620 /* Link UP/DOWN event */
2615 if (status & UMAC_IRQ_LINK_EVENT) { 2621 if (status & UMAC_IRQ_LINK_EVENT)
2616 priv->dev->phydev->link = !!(status & UMAC_IRQ_LINK_UP);
2617 phy_mac_interrupt(priv->dev->phydev); 2622 phy_mac_interrupt(priv->dev->phydev);
2618 } 2623
2619} 2624}
2620 2625
2621/* bcmgenet_isr1: handle Rx and Tx priority queues */ 2626/* bcmgenet_isr1: handle Rx and Tx priority queues */
@@ -2710,7 +2715,7 @@ static irqreturn_t bcmgenet_isr0(int irq, void *dev_id)
2710 } 2715 }
2711 2716
2712 /* all other interested interrupts handled in bottom half */ 2717 /* all other interested interrupts handled in bottom half */
2713 status &= UMAC_IRQ_LINK_EVENT; 2718 status &= (UMAC_IRQ_LINK_EVENT | UMAC_IRQ_PHY_DET_R);
2714 if (status) { 2719 if (status) {
2715 /* Save irq status for bottom-half processing. */ 2720 /* Save irq status for bottom-half processing. */
2716 spin_lock_irqsave(&priv->lock, flags); 2721 spin_lock_irqsave(&priv->lock, flags);
@@ -2874,6 +2879,12 @@ static int bcmgenet_open(struct net_device *dev)
2874 if (priv->internal_phy) 2879 if (priv->internal_phy)
2875 bcmgenet_power_up(priv, GENET_POWER_PASSIVE); 2880 bcmgenet_power_up(priv, GENET_POWER_PASSIVE);
2876 2881
2882 ret = bcmgenet_mii_connect(dev);
2883 if (ret) {
2884 netdev_err(dev, "failed to connect to PHY\n");
2885 goto err_clk_disable;
2886 }
2887
2877 /* take MAC out of reset */ 2888 /* take MAC out of reset */
2878 bcmgenet_umac_reset(priv); 2889 bcmgenet_umac_reset(priv);
2879 2890
@@ -2883,6 +2894,12 @@ static int bcmgenet_open(struct net_device *dev)
2883 reg = bcmgenet_umac_readl(priv, UMAC_CMD); 2894 reg = bcmgenet_umac_readl(priv, UMAC_CMD);
2884 priv->crc_fwd_en = !!(reg & CMD_CRC_FWD); 2895 priv->crc_fwd_en = !!(reg & CMD_CRC_FWD);
2885 2896
2897 ret = bcmgenet_mii_config(dev, true);
2898 if (ret) {
2899 netdev_err(dev, "unsupported PHY\n");
2900 goto err_disconnect_phy;
2901 }
2902
2886 bcmgenet_set_hw_addr(priv, dev->dev_addr); 2903 bcmgenet_set_hw_addr(priv, dev->dev_addr);
2887 2904
2888 if (priv->internal_phy) { 2905 if (priv->internal_phy) {
@@ -2898,7 +2915,7 @@ static int bcmgenet_open(struct net_device *dev)
2898 ret = bcmgenet_init_dma(priv); 2915 ret = bcmgenet_init_dma(priv);
2899 if (ret) { 2916 if (ret) {
2900 netdev_err(dev, "failed to initialize DMA\n"); 2917 netdev_err(dev, "failed to initialize DMA\n");
2901 goto err_clk_disable; 2918 goto err_disconnect_phy;
2902 } 2919 }
2903 2920
2904 /* Always enable ring 16 - descriptor ring */ 2921 /* Always enable ring 16 - descriptor ring */
@@ -2921,25 +2938,19 @@ static int bcmgenet_open(struct net_device *dev)
2921 goto err_irq0; 2938 goto err_irq0;
2922 } 2939 }
2923 2940
2924 ret = bcmgenet_mii_probe(dev);
2925 if (ret) {
2926 netdev_err(dev, "failed to connect to PHY\n");
2927 goto err_irq1;
2928 }
2929
2930 bcmgenet_netif_start(dev); 2941 bcmgenet_netif_start(dev);
2931 2942
2932 netif_tx_start_all_queues(dev); 2943 netif_tx_start_all_queues(dev);
2933 2944
2934 return 0; 2945 return 0;
2935 2946
2936err_irq1:
2937 free_irq(priv->irq1, priv);
2938err_irq0: 2947err_irq0:
2939 free_irq(priv->irq0, priv); 2948 free_irq(priv->irq0, priv);
2940err_fini_dma: 2949err_fini_dma:
2941 bcmgenet_dma_teardown(priv); 2950 bcmgenet_dma_teardown(priv);
2942 bcmgenet_fini_dma(priv); 2951 bcmgenet_fini_dma(priv);
2952err_disconnect_phy:
2953 phy_disconnect(dev->phydev);
2943err_clk_disable: 2954err_clk_disable:
2944 if (priv->internal_phy) 2955 if (priv->internal_phy)
2945 bcmgenet_power_down(priv, GENET_POWER_PASSIVE); 2956 bcmgenet_power_down(priv, GENET_POWER_PASSIVE);
@@ -3620,6 +3631,8 @@ static int bcmgenet_resume(struct device *d)
3620 if (priv->internal_phy) 3631 if (priv->internal_phy)
3621 bcmgenet_power_up(priv, GENET_POWER_PASSIVE); 3632 bcmgenet_power_up(priv, GENET_POWER_PASSIVE);
3622 3633
3634 phy_init_hw(dev->phydev);
3635
3623 bcmgenet_umac_reset(priv); 3636 bcmgenet_umac_reset(priv);
3624 3637
3625 init_umac(priv); 3638 init_umac(priv);
@@ -3628,8 +3641,6 @@ static int bcmgenet_resume(struct device *d)
3628 if (priv->wolopts) 3641 if (priv->wolopts)
3629 clk_disable_unprepare(priv->clk_wol); 3642 clk_disable_unprepare(priv->clk_wol);
3630 3643
3631 phy_init_hw(dev->phydev);
3632
3633 /* Speed settings must be restored */ 3644 /* Speed settings must be restored */
3634 bcmgenet_mii_config(priv->dev, false); 3645 bcmgenet_mii_config(priv->dev, false);
3635 3646
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
index 4a8fc03d82fd..7fbf573d8d52 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
@@ -366,6 +366,7 @@ struct bcmgenet_mib_counters {
366#define EXT_PWR_DOWN_PHY_EN (1 << 20) 366#define EXT_PWR_DOWN_PHY_EN (1 << 20)
367 367
368#define EXT_RGMII_OOB_CTRL 0x0C 368#define EXT_RGMII_OOB_CTRL 0x0C
369#define RGMII_MODE_EN_V123 (1 << 0)
369#define RGMII_LINK (1 << 4) 370#define RGMII_LINK (1 << 4)
370#define OOB_DISABLE (1 << 5) 371#define OOB_DISABLE (1 << 5)
371#define RGMII_MODE_EN (1 << 6) 372#define RGMII_MODE_EN (1 << 6)
@@ -719,8 +720,8 @@ GENET_IO_MACRO(rbuf, GENET_RBUF_OFF);
719 720
720/* MDIO routines */ 721/* MDIO routines */
721int bcmgenet_mii_init(struct net_device *dev); 722int bcmgenet_mii_init(struct net_device *dev);
723int bcmgenet_mii_connect(struct net_device *dev);
722int bcmgenet_mii_config(struct net_device *dev, bool init); 724int bcmgenet_mii_config(struct net_device *dev, bool init);
723int bcmgenet_mii_probe(struct net_device *dev);
724void bcmgenet_mii_exit(struct net_device *dev); 725void bcmgenet_mii_exit(struct net_device *dev);
725void bcmgenet_phy_power_set(struct net_device *dev, bool enable); 726void bcmgenet_phy_power_set(struct net_device *dev, bool enable);
726void bcmgenet_mii_setup(struct net_device *dev); 727void bcmgenet_mii_setup(struct net_device *dev);
diff --git a/drivers/net/ethernet/broadcom/genet/bcmmii.c b/drivers/net/ethernet/broadcom/genet/bcmmii.c
index 970e478a9017..17bb8d60a157 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmmii.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmmii.c
@@ -173,6 +173,46 @@ static void bcmgenet_moca_phy_setup(struct bcmgenet_priv *priv)
173 bcmgenet_fixed_phy_link_update); 173 bcmgenet_fixed_phy_link_update);
174} 174}
175 175
176int bcmgenet_mii_connect(struct net_device *dev)
177{
178 struct bcmgenet_priv *priv = netdev_priv(dev);
179 struct device_node *dn = priv->pdev->dev.of_node;
180 struct phy_device *phydev;
181 u32 phy_flags = 0;
182 int ret;
183
184 /* Communicate the integrated PHY revision */
185 if (priv->internal_phy)
186 phy_flags = priv->gphy_rev;
187
188 /* Initialize link state variables that bcmgenet_mii_setup() uses */
189 priv->old_link = -1;
190 priv->old_speed = -1;
191 priv->old_duplex = -1;
192 priv->old_pause = -1;
193
194 if (dn) {
195 phydev = of_phy_connect(dev, priv->phy_dn, bcmgenet_mii_setup,
196 phy_flags, priv->phy_interface);
197 if (!phydev) {
198 pr_err("could not attach to PHY\n");
199 return -ENODEV;
200 }
201 } else {
202 phydev = dev->phydev;
203 phydev->dev_flags = phy_flags;
204
205 ret = phy_connect_direct(dev, phydev, bcmgenet_mii_setup,
206 priv->phy_interface);
207 if (ret) {
208 pr_err("could not attach to PHY\n");
209 return -ENODEV;
210 }
211 }
212
213 return 0;
214}
215
176int bcmgenet_mii_config(struct net_device *dev, bool init) 216int bcmgenet_mii_config(struct net_device *dev, bool init)
177{ 217{
178 struct bcmgenet_priv *priv = netdev_priv(dev); 218 struct bcmgenet_priv *priv = netdev_priv(dev);
@@ -258,74 +298,29 @@ int bcmgenet_mii_config(struct net_device *dev, bool init)
258 */ 298 */
259 if (priv->ext_phy) { 299 if (priv->ext_phy) {
260 reg = bcmgenet_ext_readl(priv, EXT_RGMII_OOB_CTRL); 300 reg = bcmgenet_ext_readl(priv, EXT_RGMII_OOB_CTRL);
261 reg |= RGMII_MODE_EN | id_mode_dis; 301 reg |= id_mode_dis;
302 if (GENET_IS_V1(priv) || GENET_IS_V2(priv) || GENET_IS_V3(priv))
303 reg |= RGMII_MODE_EN_V123;
304 else
305 reg |= RGMII_MODE_EN;
262 bcmgenet_ext_writel(priv, reg, EXT_RGMII_OOB_CTRL); 306 bcmgenet_ext_writel(priv, reg, EXT_RGMII_OOB_CTRL);
263 } 307 }
264 308
265 if (init) 309 if (init) {
266 dev_info(kdev, "configuring instance for %s\n", phy_name); 310 linkmode_copy(phydev->advertising, phydev->supported);
267
268 return 0;
269}
270
271int bcmgenet_mii_probe(struct net_device *dev)
272{
273 struct bcmgenet_priv *priv = netdev_priv(dev);
274 struct device_node *dn = priv->pdev->dev.of_node;
275 struct phy_device *phydev;
276 u32 phy_flags;
277 int ret;
278
279 /* Communicate the integrated PHY revision */
280 phy_flags = priv->gphy_rev;
281
282 /* Initialize link state variables that bcmgenet_mii_setup() uses */
283 priv->old_link = -1;
284 priv->old_speed = -1;
285 priv->old_duplex = -1;
286 priv->old_pause = -1;
287
288 if (dn) {
289 phydev = of_phy_connect(dev, priv->phy_dn, bcmgenet_mii_setup,
290 phy_flags, priv->phy_interface);
291 if (!phydev) {
292 pr_err("could not attach to PHY\n");
293 return -ENODEV;
294 }
295 } else {
296 phydev = dev->phydev;
297 phydev->dev_flags = phy_flags;
298 311
299 ret = phy_connect_direct(dev, phydev, bcmgenet_mii_setup, 312 /* The internal PHY has its link interrupts routed to the
300 priv->phy_interface); 313 * Ethernet MAC ISRs. On GENETv5 there is a hardware issue
301 if (ret) { 314 * that prevents the signaling of link UP interrupts when
302 pr_err("could not attach to PHY\n"); 315 * the link operates at 10Mbps, so fallback to polling for
303 return -ENODEV; 316 * those versions of GENET.
304 } 317 */
305 } 318 if (priv->internal_phy && !GENET_IS_V5(priv))
319 phydev->irq = PHY_IGNORE_INTERRUPT;
306 320
307 /* Configure port multiplexer based on what the probed PHY device since 321 dev_info(kdev, "configuring instance for %s\n", phy_name);
308 * reading the 'max-speed' property determines the maximum supported
309 * PHY speed which is needed for bcmgenet_mii_config() to configure
310 * things appropriately.
311 */
312 ret = bcmgenet_mii_config(dev, true);
313 if (ret) {
314 phy_disconnect(dev->phydev);
315 return ret;
316 } 322 }
317 323
318 linkmode_copy(phydev->advertising, phydev->supported);
319
320 /* The internal PHY has its link interrupts routed to the
321 * Ethernet MAC ISRs. On GENETv5 there is a hardware issue
322 * that prevents the signaling of link UP interrupts when
323 * the link operates at 10Mbps, so fallback to polling for
324 * those versions of GENET.
325 */
326 if (priv->internal_phy && !GENET_IS_V5(priv))
327 dev->phydev->irq = PHY_IGNORE_INTERRUPT;
328
329 return 0; 324 return 0;
330} 325}
331 326
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 8e8d557901a9..1e1b774e1953 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -3405,17 +3405,17 @@ static int macb_clk_init(struct platform_device *pdev, struct clk **pclk,
3405 return err; 3405 return err;
3406 } 3406 }
3407 3407
3408 *tx_clk = devm_clk_get(&pdev->dev, "tx_clk"); 3408 *tx_clk = devm_clk_get_optional(&pdev->dev, "tx_clk");
3409 if (IS_ERR(*tx_clk)) 3409 if (IS_ERR(*tx_clk))
3410 *tx_clk = NULL; 3410 return PTR_ERR(*tx_clk);
3411 3411
3412 *rx_clk = devm_clk_get(&pdev->dev, "rx_clk"); 3412 *rx_clk = devm_clk_get_optional(&pdev->dev, "rx_clk");
3413 if (IS_ERR(*rx_clk)) 3413 if (IS_ERR(*rx_clk))
3414 *rx_clk = NULL; 3414 return PTR_ERR(*rx_clk);
3415 3415
3416 *tsu_clk = devm_clk_get(&pdev->dev, "tsu_clk"); 3416 *tsu_clk = devm_clk_get_optional(&pdev->dev, "tsu_clk");
3417 if (IS_ERR(*tsu_clk)) 3417 if (IS_ERR(*tsu_clk))
3418 *tsu_clk = NULL; 3418 return PTR_ERR(*tsu_clk);
3419 3419
3420 err = clk_prepare_enable(*pclk); 3420 err = clk_prepare_enable(*pclk);
3421 if (err) { 3421 if (err) {
diff --git a/drivers/net/ethernet/cavium/common/cavium_ptp.h b/drivers/net/ethernet/cavium/common/cavium_ptp.h
index be2bafc7beeb..a04eccbc78e8 100644
--- a/drivers/net/ethernet/cavium/common/cavium_ptp.h
+++ b/drivers/net/ethernet/cavium/common/cavium_ptp.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* cavium_ptp.h - PTP 1588 clock on Cavium hardware 2/* cavium_ptp.h - PTP 1588 clock on Cavium hardware
3 * Copyright (c) 2003-2015, 2017 Cavium, Inc. 3 * Copyright (c) 2003-2015, 2017 Cavium, Inc.
4 */ 4 */
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c
index 5b602243d573..86b528d8364c 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c
@@ -137,13 +137,12 @@ static int uldrx_handler(struct sge_rspq *q, const __be64 *rsp,
137static int alloc_uld_rxqs(struct adapter *adap, 137static int alloc_uld_rxqs(struct adapter *adap,
138 struct sge_uld_rxq_info *rxq_info, bool lro) 138 struct sge_uld_rxq_info *rxq_info, bool lro)
139{ 139{
140 struct sge *s = &adap->sge;
141 unsigned int nq = rxq_info->nrxq + rxq_info->nciq; 140 unsigned int nq = rxq_info->nrxq + rxq_info->nciq;
141 int i, err, msi_idx, que_idx = 0, bmap_idx = 0;
142 struct sge_ofld_rxq *q = rxq_info->uldrxq; 142 struct sge_ofld_rxq *q = rxq_info->uldrxq;
143 unsigned short *ids = rxq_info->rspq_id; 143 unsigned short *ids = rxq_info->rspq_id;
144 unsigned int bmap_idx = 0; 144 struct sge *s = &adap->sge;
145 unsigned int per_chan; 145 unsigned int per_chan;
146 int i, err, msi_idx, que_idx = 0;
147 146
148 per_chan = rxq_info->nrxq / adap->params.nports; 147 per_chan = rxq_info->nrxq / adap->params.nports;
149 148
@@ -161,6 +160,10 @@ static int alloc_uld_rxqs(struct adapter *adap,
161 160
162 if (msi_idx >= 0) { 161 if (msi_idx >= 0) {
163 bmap_idx = get_msix_idx_from_bmap(adap); 162 bmap_idx = get_msix_idx_from_bmap(adap);
163 if (bmap_idx < 0) {
164 err = -ENOSPC;
165 goto freeout;
166 }
164 msi_idx = adap->msix_info_ulds[bmap_idx].idx; 167 msi_idx = adap->msix_info_ulds[bmap_idx].idx;
165 } 168 }
166 err = t4_sge_alloc_rxq(adap, &q->rspq, false, 169 err = t4_sge_alloc_rxq(adap, &q->rspq, false,
@@ -692,10 +695,10 @@ static void uld_init(struct adapter *adap, struct cxgb4_lld_info *lld)
692 lld->write_cmpl_support = adap->params.write_cmpl_support; 695 lld->write_cmpl_support = adap->params.write_cmpl_support;
693} 696}
694 697
695static void uld_attach(struct adapter *adap, unsigned int uld) 698static int uld_attach(struct adapter *adap, unsigned int uld)
696{ 699{
697 void *handle;
698 struct cxgb4_lld_info lli; 700 struct cxgb4_lld_info lli;
701 void *handle;
699 702
700 uld_init(adap, &lli); 703 uld_init(adap, &lli);
701 uld_queue_init(adap, uld, &lli); 704 uld_queue_init(adap, uld, &lli);
@@ -705,7 +708,7 @@ static void uld_attach(struct adapter *adap, unsigned int uld)
705 dev_warn(adap->pdev_dev, 708 dev_warn(adap->pdev_dev,
706 "could not attach to the %s driver, error %ld\n", 709 "could not attach to the %s driver, error %ld\n",
707 adap->uld[uld].name, PTR_ERR(handle)); 710 adap->uld[uld].name, PTR_ERR(handle));
708 return; 711 return PTR_ERR(handle);
709 } 712 }
710 713
711 adap->uld[uld].handle = handle; 714 adap->uld[uld].handle = handle;
@@ -713,22 +716,22 @@ static void uld_attach(struct adapter *adap, unsigned int uld)
713 716
714 if (adap->flags & CXGB4_FULL_INIT_DONE) 717 if (adap->flags & CXGB4_FULL_INIT_DONE)
715 adap->uld[uld].state_change(handle, CXGB4_STATE_UP); 718 adap->uld[uld].state_change(handle, CXGB4_STATE_UP);
719
720 return 0;
716} 721}
717 722
718/** 723/* cxgb4_register_uld - register an upper-layer driver
719 * cxgb4_register_uld - register an upper-layer driver 724 * @type: the ULD type
720 * @type: the ULD type 725 * @p: the ULD methods
721 * @p: the ULD methods
722 * 726 *
723 * Registers an upper-layer driver with this driver and notifies the ULD 727 * Registers an upper-layer driver with this driver and notifies the ULD
724 * about any presently available devices that support its type. Returns 728 * about any presently available devices that support its type.
725 * %-EBUSY if a ULD of the same type is already registered.
726 */ 729 */
727void cxgb4_register_uld(enum cxgb4_uld type, 730void cxgb4_register_uld(enum cxgb4_uld type,
728 const struct cxgb4_uld_info *p) 731 const struct cxgb4_uld_info *p)
729{ 732{
730 int ret = 0;
731 struct adapter *adap; 733 struct adapter *adap;
734 int ret = 0;
732 735
733 if (type >= CXGB4_ULD_MAX) 736 if (type >= CXGB4_ULD_MAX)
734 return; 737 return;
@@ -760,8 +763,12 @@ void cxgb4_register_uld(enum cxgb4_uld type,
760 if (ret) 763 if (ret)
761 goto free_irq; 764 goto free_irq;
762 adap->uld[type] = *p; 765 adap->uld[type] = *p;
763 uld_attach(adap, type); 766 ret = uld_attach(adap, type);
767 if (ret)
768 goto free_txq;
764 continue; 769 continue;
770free_txq:
771 release_sge_txq_uld(adap, type);
765free_irq: 772free_irq:
766 if (adap->flags & CXGB4_FULL_INIT_DONE) 773 if (adap->flags & CXGB4_FULL_INIT_DONE)
767 quiesce_rx_uld(adap, type); 774 quiesce_rx_uld(adap, type);
diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c b/drivers/net/ethernet/chelsio/cxgb4/sge.c
index b3da81e90132..928bfea5457b 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/sge.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c
@@ -3791,15 +3791,11 @@ int t4_sge_alloc_eth_txq(struct adapter *adap, struct sge_eth_txq *txq,
3791 * write the CIDX Updates into the Status Page at the end of the 3791 * write the CIDX Updates into the Status Page at the end of the
3792 * TX Queue. 3792 * TX Queue.
3793 */ 3793 */
3794 c.autoequiqe_to_viid = htonl((dbqt 3794 c.autoequiqe_to_viid = htonl(FW_EQ_ETH_CMD_AUTOEQUEQE_F |
3795 ? FW_EQ_ETH_CMD_AUTOEQUIQE_F
3796 : FW_EQ_ETH_CMD_AUTOEQUEQE_F) |
3797 FW_EQ_ETH_CMD_VIID_V(pi->viid)); 3795 FW_EQ_ETH_CMD_VIID_V(pi->viid));
3798 3796
3799 c.fetchszm_to_iqid = 3797 c.fetchszm_to_iqid =
3800 htonl(FW_EQ_ETH_CMD_HOSTFCMODE_V(dbqt 3798 htonl(FW_EQ_ETH_CMD_HOSTFCMODE_V(HOSTFCMODE_STATUS_PAGE_X) |
3801 ? HOSTFCMODE_INGRESS_QUEUE_X
3802 : HOSTFCMODE_STATUS_PAGE_X) |
3803 FW_EQ_ETH_CMD_PCIECHN_V(pi->tx_chan) | 3799 FW_EQ_ETH_CMD_PCIECHN_V(pi->tx_chan) |
3804 FW_EQ_ETH_CMD_FETCHRO_F | FW_EQ_ETH_CMD_IQID_V(iqid)); 3800 FW_EQ_ETH_CMD_FETCHRO_F | FW_EQ_ETH_CMD_IQID_V(iqid));
3805 3801
diff --git a/drivers/net/ethernet/cortina/gemini.h b/drivers/net/ethernet/cortina/gemini.h
index 0b12f89bf89a..9fdf77d5eb37 100644
--- a/drivers/net/ethernet/cortina/gemini.h
+++ b/drivers/net/ethernet/cortina/gemini.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* Register definitions for Gemini GMAC Ethernet device driver 2/* Register definitions for Gemini GMAC Ethernet device driver
3 * 3 *
4 * Copyright (C) 2006 Storlink, Corp. 4 * Copyright (C) 2006 Storlink, Corp.
diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index 9b7af94a40bb..96e9565f1e08 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -727,6 +727,18 @@ static netdev_tx_t ftgmac100_hard_start_xmit(struct sk_buff *skb,
727 */ 727 */
728 nfrags = skb_shinfo(skb)->nr_frags; 728 nfrags = skb_shinfo(skb)->nr_frags;
729 729
730 /* Setup HW checksumming */
731 csum_vlan = 0;
732 if (skb->ip_summed == CHECKSUM_PARTIAL &&
733 !ftgmac100_prep_tx_csum(skb, &csum_vlan))
734 goto drop;
735
736 /* Add VLAN tag */
737 if (skb_vlan_tag_present(skb)) {
738 csum_vlan |= FTGMAC100_TXDES1_INS_VLANTAG;
739 csum_vlan |= skb_vlan_tag_get(skb) & 0xffff;
740 }
741
730 /* Get header len */ 742 /* Get header len */
731 len = skb_headlen(skb); 743 len = skb_headlen(skb);
732 744
@@ -753,19 +765,6 @@ static netdev_tx_t ftgmac100_hard_start_xmit(struct sk_buff *skb,
753 if (nfrags == 0) 765 if (nfrags == 0)
754 f_ctl_stat |= FTGMAC100_TXDES0_LTS; 766 f_ctl_stat |= FTGMAC100_TXDES0_LTS;
755 txdes->txdes3 = cpu_to_le32(map); 767 txdes->txdes3 = cpu_to_le32(map);
756
757 /* Setup HW checksumming */
758 csum_vlan = 0;
759 if (skb->ip_summed == CHECKSUM_PARTIAL &&
760 !ftgmac100_prep_tx_csum(skb, &csum_vlan))
761 goto drop;
762
763 /* Add VLAN tag */
764 if (skb_vlan_tag_present(skb)) {
765 csum_vlan |= FTGMAC100_TXDES1_INS_VLANTAG;
766 csum_vlan |= skb_vlan_tag_get(skb) & 0xffff;
767 }
768
769 txdes->txdes1 = cpu_to_le32(csum_vlan); 768 txdes->txdes1 = cpu_to_le32(csum_vlan);
770 769
771 /* Next descriptor */ 770 /* Next descriptor */
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
index 162d7d8fb295..19379bae0144 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
@@ -1235,6 +1235,8 @@ static void dpaa2_eth_set_rx_taildrop(struct dpaa2_eth_priv *priv, bool enable)
1235 priv->rx_td_enabled = enable; 1235 priv->rx_td_enabled = enable;
1236} 1236}
1237 1237
1238static void update_tx_fqids(struct dpaa2_eth_priv *priv);
1239
1238static int link_state_update(struct dpaa2_eth_priv *priv) 1240static int link_state_update(struct dpaa2_eth_priv *priv)
1239{ 1241{
1240 struct dpni_link_state state = {0}; 1242 struct dpni_link_state state = {0};
@@ -1261,6 +1263,7 @@ static int link_state_update(struct dpaa2_eth_priv *priv)
1261 goto out; 1263 goto out;
1262 1264
1263 if (state.up) { 1265 if (state.up) {
1266 update_tx_fqids(priv);
1264 netif_carrier_on(priv->net_dev); 1267 netif_carrier_on(priv->net_dev);
1265 netif_tx_start_all_queues(priv->net_dev); 1268 netif_tx_start_all_queues(priv->net_dev);
1266 } else { 1269 } else {
@@ -2533,6 +2536,47 @@ static int set_pause(struct dpaa2_eth_priv *priv)
2533 return 0; 2536 return 0;
2534} 2537}
2535 2538
2539static void update_tx_fqids(struct dpaa2_eth_priv *priv)
2540{
2541 struct dpni_queue_id qid = {0};
2542 struct dpaa2_eth_fq *fq;
2543 struct dpni_queue queue;
2544 int i, j, err;
2545
2546 /* We only use Tx FQIDs for FQID-based enqueue, so check
2547 * if DPNI version supports it before updating FQIDs
2548 */
2549 if (dpaa2_eth_cmp_dpni_ver(priv, DPNI_ENQUEUE_FQID_VER_MAJOR,
2550 DPNI_ENQUEUE_FQID_VER_MINOR) < 0)
2551 return;
2552
2553 for (i = 0; i < priv->num_fqs; i++) {
2554 fq = &priv->fq[i];
2555 if (fq->type != DPAA2_TX_CONF_FQ)
2556 continue;
2557 for (j = 0; j < dpaa2_eth_tc_count(priv); j++) {
2558 err = dpni_get_queue(priv->mc_io, 0, priv->mc_token,
2559 DPNI_QUEUE_TX, j, fq->flowid,
2560 &queue, &qid);
2561 if (err)
2562 goto out_err;
2563
2564 fq->tx_fqid[j] = qid.fqid;
2565 if (fq->tx_fqid[j] == 0)
2566 goto out_err;
2567 }
2568 }
2569
2570 priv->enqueue = dpaa2_eth_enqueue_fq;
2571
2572 return;
2573
2574out_err:
2575 netdev_info(priv->net_dev,
2576 "Error reading Tx FQID, fallback to QDID-based enqueue\n");
2577 priv->enqueue = dpaa2_eth_enqueue_qd;
2578}
2579
2536/* Configure the DPNI object this interface is associated with */ 2580/* Configure the DPNI object this interface is associated with */
2537static int setup_dpni(struct fsl_mc_device *ls_dev) 2581static int setup_dpni(struct fsl_mc_device *ls_dev)
2538{ 2582{
@@ -3306,6 +3350,9 @@ static irqreturn_t dpni_irq0_handler_thread(int irq_num, void *arg)
3306 if (status & DPNI_IRQ_EVENT_LINK_CHANGED) 3350 if (status & DPNI_IRQ_EVENT_LINK_CHANGED)
3307 link_state_update(netdev_priv(net_dev)); 3351 link_state_update(netdev_priv(net_dev));
3308 3352
3353 if (status & DPNI_IRQ_EVENT_ENDPOINT_CHANGED)
3354 set_mac_addr(netdev_priv(net_dev));
3355
3309 return IRQ_HANDLED; 3356 return IRQ_HANDLED;
3310} 3357}
3311 3358
@@ -3331,7 +3378,8 @@ static int setup_irqs(struct fsl_mc_device *ls_dev)
3331 } 3378 }
3332 3379
3333 err = dpni_set_irq_mask(ls_dev->mc_io, 0, ls_dev->mc_handle, 3380 err = dpni_set_irq_mask(ls_dev->mc_io, 0, ls_dev->mc_handle,
3334 DPNI_IRQ_INDEX, DPNI_IRQ_EVENT_LINK_CHANGED); 3381 DPNI_IRQ_INDEX, DPNI_IRQ_EVENT_LINK_CHANGED |
3382 DPNI_IRQ_EVENT_ENDPOINT_CHANGED);
3335 if (err < 0) { 3383 if (err < 0) {
3336 dev_err(&ls_dev->dev, "dpni_set_irq_mask(): %d\n", err); 3384 dev_err(&ls_dev->dev, "dpni_set_irq_mask(): %d\n", err);
3337 goto free_irq; 3385 goto free_irq;
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.h b/drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.h
index ff2e177395d4..df2458a5e9ef 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.h
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* 2/*
3 * Copyright 2018 NXP 3 * Copyright 2018 NXP
4 */ 4 */
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpni.h b/drivers/net/ethernet/freescale/dpaa2/dpni.h
index fd583911b6c0..ee0711d06b3a 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpni.h
+++ b/drivers/net/ethernet/freescale/dpaa2/dpni.h
@@ -133,9 +133,12 @@ int dpni_reset(struct fsl_mc_io *mc_io,
133 */ 133 */
134#define DPNI_IRQ_INDEX 0 134#define DPNI_IRQ_INDEX 0
135/** 135/**
136 * IRQ event - indicates a change in link state 136 * IRQ events:
137 * indicates a change in link state
138 * indicates a change in endpoint
137 */ 139 */
138#define DPNI_IRQ_EVENT_LINK_CHANGED 0x00000001 140#define DPNI_IRQ_EVENT_LINK_CHANGED 0x00000001
141#define DPNI_IRQ_EVENT_ENDPOINT_CHANGED 0x00000002
139 142
140int dpni_set_irq_enable(struct fsl_mc_io *mc_io, 143int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
141 u32 cmd_flags, 144 u32 cmd_flags,
diff --git a/drivers/net/ethernet/freescale/dpaa2/dprtc-cmd.h b/drivers/net/ethernet/freescale/dpaa2/dprtc-cmd.h
index 720cd50f5895..4ac05bfef338 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dprtc-cmd.h
+++ b/drivers/net/ethernet/freescale/dpaa2/dprtc-cmd.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* 2/*
3 * Copyright 2013-2016 Freescale Semiconductor Inc. 3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2016-2018 NXP 4 * Copyright 2016-2018 NXP
diff --git a/drivers/net/ethernet/freescale/dpaa2/dprtc.h b/drivers/net/ethernet/freescale/dpaa2/dprtc.h
index be7914c1634d..311c184e1aef 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dprtc.h
+++ b/drivers/net/ethernet/freescale/dpaa2/dprtc.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* 2/*
3 * Copyright 2013-2016 Freescale Semiconductor Inc. 3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2016-2018 NXP 4 * Copyright 2016-2018 NXP
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index d4d4c72adf49..22c01b224baa 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -3558,7 +3558,7 @@ fec_probe(struct platform_device *pdev)
3558 3558
3559 for (i = 0; i < irq_cnt; i++) { 3559 for (i = 0; i < irq_cnt; i++) {
3560 snprintf(irq_name, sizeof(irq_name), "int%d", i); 3560 snprintf(irq_name, sizeof(irq_name), "int%d", i);
3561 irq = platform_get_irq_byname(pdev, irq_name); 3561 irq = platform_get_irq_byname_optional(pdev, irq_name);
3562 if (irq < 0) 3562 if (irq < 0)
3563 irq = platform_get_irq(pdev, i); 3563 irq = platform_get_irq(pdev, i);
3564 if (irq < 0) { 3564 if (irq < 0) {
diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c
index 19e2365be7d8..945643c02615 100644
--- a/drivers/net/ethernet/freescale/fec_ptp.c
+++ b/drivers/net/ethernet/freescale/fec_ptp.c
@@ -600,9 +600,9 @@ void fec_ptp_init(struct platform_device *pdev, int irq_idx)
600 600
601 INIT_DELAYED_WORK(&fep->time_keep, fec_time_keep); 601 INIT_DELAYED_WORK(&fep->time_keep, fec_time_keep);
602 602
603 irq = platform_get_irq_byname(pdev, "pps"); 603 irq = platform_get_irq_byname_optional(pdev, "pps");
604 if (irq < 0) 604 if (irq < 0)
605 irq = platform_get_irq(pdev, irq_idx); 605 irq = platform_get_irq_optional(pdev, irq_idx);
606 /* Failure to get an irq is not fatal, 606 /* Failure to get an irq is not fatal,
607 * only the PTP_CLOCK_PPS clock events should stop 607 * only the PTP_CLOCK_PPS clock events should stop
608 */ 608 */
diff --git a/drivers/net/ethernet/hisilicon/hip04_eth.c b/drivers/net/ethernet/hisilicon/hip04_eth.c
index c84167447abe..4606a7e4a6d1 100644
--- a/drivers/net/ethernet/hisilicon/hip04_eth.c
+++ b/drivers/net/ethernet/hisilicon/hip04_eth.c
@@ -237,6 +237,7 @@ struct hip04_priv {
237 dma_addr_t rx_phys[RX_DESC_NUM]; 237 dma_addr_t rx_phys[RX_DESC_NUM];
238 unsigned int rx_head; 238 unsigned int rx_head;
239 unsigned int rx_buf_size; 239 unsigned int rx_buf_size;
240 unsigned int rx_cnt_remaining;
240 241
241 struct device_node *phy_node; 242 struct device_node *phy_node;
242 struct phy_device *phy; 243 struct phy_device *phy;
@@ -575,7 +576,6 @@ static int hip04_rx_poll(struct napi_struct *napi, int budget)
575 struct hip04_priv *priv = container_of(napi, struct hip04_priv, napi); 576 struct hip04_priv *priv = container_of(napi, struct hip04_priv, napi);
576 struct net_device *ndev = priv->ndev; 577 struct net_device *ndev = priv->ndev;
577 struct net_device_stats *stats = &ndev->stats; 578 struct net_device_stats *stats = &ndev->stats;
578 unsigned int cnt = hip04_recv_cnt(priv);
579 struct rx_desc *desc; 579 struct rx_desc *desc;
580 struct sk_buff *skb; 580 struct sk_buff *skb;
581 unsigned char *buf; 581 unsigned char *buf;
@@ -588,8 +588,8 @@ static int hip04_rx_poll(struct napi_struct *napi, int budget)
588 588
589 /* clean up tx descriptors */ 589 /* clean up tx descriptors */
590 tx_remaining = hip04_tx_reclaim(ndev, false); 590 tx_remaining = hip04_tx_reclaim(ndev, false);
591 591 priv->rx_cnt_remaining += hip04_recv_cnt(priv);
592 while (cnt && !last) { 592 while (priv->rx_cnt_remaining && !last) {
593 buf = priv->rx_buf[priv->rx_head]; 593 buf = priv->rx_buf[priv->rx_head];
594 skb = build_skb(buf, priv->rx_buf_size); 594 skb = build_skb(buf, priv->rx_buf_size);
595 if (unlikely(!skb)) { 595 if (unlikely(!skb)) {
@@ -635,11 +635,13 @@ refill:
635 hip04_set_recv_desc(priv, phys); 635 hip04_set_recv_desc(priv, phys);
636 636
637 priv->rx_head = RX_NEXT(priv->rx_head); 637 priv->rx_head = RX_NEXT(priv->rx_head);
638 if (rx >= budget) 638 if (rx >= budget) {
639 --priv->rx_cnt_remaining;
639 goto done; 640 goto done;
641 }
640 642
641 if (--cnt == 0) 643 if (--priv->rx_cnt_remaining == 0)
642 cnt = hip04_recv_cnt(priv); 644 priv->rx_cnt_remaining += hip04_recv_cnt(priv);
643 } 645 }
644 646
645 if (!(priv->reg_inten & RCV_INT)) { 647 if (!(priv->reg_inten & RCV_INT)) {
@@ -724,6 +726,7 @@ static int hip04_mac_open(struct net_device *ndev)
724 int i; 726 int i;
725 727
726 priv->rx_head = 0; 728 priv->rx_head = 0;
729 priv->rx_cnt_remaining = 0;
727 priv->tx_head = 0; 730 priv->tx_head = 0;
728 priv->tx_tail = 0; 731 priv->tx_tail = 0;
729 hip04_reset_ppe(priv); 732 hip04_reset_ppe(priv);
@@ -1038,7 +1041,6 @@ static int hip04_remove(struct platform_device *pdev)
1038 1041
1039 hip04_free_ring(ndev, d); 1042 hip04_free_ring(ndev, d);
1040 unregister_netdev(ndev); 1043 unregister_netdev(ndev);
1041 free_irq(ndev->irq, ndev);
1042 of_node_put(priv->phy_node); 1044 of_node_put(priv->phy_node);
1043 cancel_work_sync(&priv->tx_timeout_task); 1045 cancel_work_sync(&priv->tx_timeout_task);
1044 free_netdev(ndev); 1046 free_netdev(ndev);
diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index c4b7bf851a28..75ccc1e7076b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -32,6 +32,8 @@
32 32
33#define HNAE3_MOD_VERSION "1.0" 33#define HNAE3_MOD_VERSION "1.0"
34 34
35#define HNAE3_MIN_VECTOR_NUM 2 /* first one for misc, another for IO */
36
35/* Device IDs */ 37/* Device IDs */
36#define HNAE3_DEV_ID_GE 0xA220 38#define HNAE3_DEV_ID_GE 0xA220
37#define HNAE3_DEV_ID_25GE 0xA221 39#define HNAE3_DEV_ID_25GE 0xA221
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index fd7f94372ff0..e02e01bd9eff 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -906,6 +906,9 @@ static int hclge_query_pf_resource(struct hclge_dev *hdev)
906 hnae3_get_field(__le16_to_cpu(req->pf_intr_vector_number), 906 hnae3_get_field(__le16_to_cpu(req->pf_intr_vector_number),
907 HCLGE_PF_VEC_NUM_M, HCLGE_PF_VEC_NUM_S); 907 HCLGE_PF_VEC_NUM_M, HCLGE_PF_VEC_NUM_S);
908 908
909 /* nic's msix numbers is always equals to the roce's. */
910 hdev->num_nic_msi = hdev->num_roce_msi;
911
909 /* PF should have NIC vectors and Roce vectors, 912 /* PF should have NIC vectors and Roce vectors,
910 * NIC vectors are queued before Roce vectors. 913 * NIC vectors are queued before Roce vectors.
911 */ 914 */
@@ -915,6 +918,15 @@ static int hclge_query_pf_resource(struct hclge_dev *hdev)
915 hdev->num_msi = 918 hdev->num_msi =
916 hnae3_get_field(__le16_to_cpu(req->pf_intr_vector_number), 919 hnae3_get_field(__le16_to_cpu(req->pf_intr_vector_number),
917 HCLGE_PF_VEC_NUM_M, HCLGE_PF_VEC_NUM_S); 920 HCLGE_PF_VEC_NUM_M, HCLGE_PF_VEC_NUM_S);
921
922 hdev->num_nic_msi = hdev->num_msi;
923 }
924
925 if (hdev->num_nic_msi < HNAE3_MIN_VECTOR_NUM) {
926 dev_err(&hdev->pdev->dev,
927 "Just %u msi resources, not enough for pf(min:2).\n",
928 hdev->num_nic_msi);
929 return -EINVAL;
918 } 930 }
919 931
920 return 0; 932 return 0;
@@ -1507,6 +1519,10 @@ static int hclge_assign_tqp(struct hclge_vport *vport, u16 num_tqps)
1507 kinfo->rss_size = min_t(u16, hdev->rss_size_max, 1519 kinfo->rss_size = min_t(u16, hdev->rss_size_max,
1508 vport->alloc_tqps / hdev->tm_info.num_tc); 1520 vport->alloc_tqps / hdev->tm_info.num_tc);
1509 1521
1522 /* ensure one to one mapping between irq and queue at default */
1523 kinfo->rss_size = min_t(u16, kinfo->rss_size,
1524 (hdev->num_nic_msi - 1) / hdev->tm_info.num_tc);
1525
1510 return 0; 1526 return 0;
1511} 1527}
1512 1528
@@ -2285,7 +2301,8 @@ static int hclge_init_msi(struct hclge_dev *hdev)
2285 int vectors; 2301 int vectors;
2286 int i; 2302 int i;
2287 2303
2288 vectors = pci_alloc_irq_vectors(pdev, 1, hdev->num_msi, 2304 vectors = pci_alloc_irq_vectors(pdev, HNAE3_MIN_VECTOR_NUM,
2305 hdev->num_msi,
2289 PCI_IRQ_MSI | PCI_IRQ_MSIX); 2306 PCI_IRQ_MSI | PCI_IRQ_MSIX);
2290 if (vectors < 0) { 2307 if (vectors < 0) {
2291 dev_err(&pdev->dev, 2308 dev_err(&pdev->dev,
@@ -2300,6 +2317,7 @@ static int hclge_init_msi(struct hclge_dev *hdev)
2300 2317
2301 hdev->num_msi = vectors; 2318 hdev->num_msi = vectors;
2302 hdev->num_msi_left = vectors; 2319 hdev->num_msi_left = vectors;
2320
2303 hdev->base_msi_vector = pdev->irq; 2321 hdev->base_msi_vector = pdev->irq;
2304 hdev->roce_base_vector = hdev->base_msi_vector + 2322 hdev->roce_base_vector = hdev->base_msi_vector +
2305 hdev->roce_base_msix_offset; 2323 hdev->roce_base_msix_offset;
@@ -3903,6 +3921,7 @@ static int hclge_get_vector(struct hnae3_handle *handle, u16 vector_num,
3903 int alloc = 0; 3921 int alloc = 0;
3904 int i, j; 3922 int i, j;
3905 3923
3924 vector_num = min_t(u16, hdev->num_nic_msi - 1, vector_num);
3906 vector_num = min(hdev->num_msi_left, vector_num); 3925 vector_num = min(hdev->num_msi_left, vector_num);
3907 3926
3908 for (j = 0; j < vector_num; j++) { 3927 for (j = 0; j < vector_num; j++) {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
index 3e9574a9e22d..c3d56b872ed7 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
@@ -763,6 +763,7 @@ struct hclge_dev {
763 u32 base_msi_vector; 763 u32 base_msi_vector;
764 u16 *vector_status; 764 u16 *vector_status;
765 int *vector_irq; 765 int *vector_irq;
766 u16 num_nic_msi; /* Num of nic vectors for this PF */
766 u16 num_roce_msi; /* Num of roce vectors for this PF */ 767 u16 num_roce_msi; /* Num of roce vectors for this PF */
767 int roce_base_vector; 768 int roce_base_vector;
768 769
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
index 9f0e35f27789..62399cc1c5a6 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
@@ -537,9 +537,16 @@ static void hclge_tm_vport_tc_info_update(struct hclge_vport *vport)
537 kinfo->rss_size = kinfo->req_rss_size; 537 kinfo->rss_size = kinfo->req_rss_size;
538 } else if (kinfo->rss_size > max_rss_size || 538 } else if (kinfo->rss_size > max_rss_size ||
539 (!kinfo->req_rss_size && kinfo->rss_size < max_rss_size)) { 539 (!kinfo->req_rss_size && kinfo->rss_size < max_rss_size)) {
540 /* if user not set rss, the rss_size should compare with the
541 * valid msi numbers to ensure one to one map between tqp and
542 * irq as default.
543 */
544 if (!kinfo->req_rss_size)
545 max_rss_size = min_t(u16, max_rss_size,
546 (hdev->num_nic_msi - 1) /
547 kinfo->num_tc);
548
540 /* Set to the maximum specification value (max_rss_size). */ 549 /* Set to the maximum specification value (max_rss_size). */
541 dev_info(&hdev->pdev->dev, "rss changes from %d to %d\n",
542 kinfo->rss_size, max_rss_size);
543 kinfo->rss_size = max_rss_size; 550 kinfo->rss_size = max_rss_size;
544 } 551 }
545 552
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index e3090b3dab1d..7d7e712691b9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -411,6 +411,13 @@ static int hclgevf_knic_setup(struct hclgevf_dev *hdev)
411 kinfo->tqp[i] = &hdev->htqp[i].q; 411 kinfo->tqp[i] = &hdev->htqp[i].q;
412 } 412 }
413 413
414 /* after init the max rss_size and tqps, adjust the default tqp numbers
415 * and rss size with the actual vector numbers
416 */
417 kinfo->num_tqps = min_t(u16, hdev->num_nic_msix - 1, kinfo->num_tqps);
418 kinfo->rss_size = min_t(u16, kinfo->num_tqps / kinfo->num_tc,
419 kinfo->rss_size);
420
414 return 0; 421 return 0;
415} 422}
416 423
@@ -502,6 +509,7 @@ static int hclgevf_get_vector(struct hnae3_handle *handle, u16 vector_num,
502 int alloc = 0; 509 int alloc = 0;
503 int i, j; 510 int i, j;
504 511
512 vector_num = min_t(u16, hdev->num_nic_msix - 1, vector_num);
505 vector_num = min(hdev->num_msi_left, vector_num); 513 vector_num = min(hdev->num_msi_left, vector_num);
506 514
507 for (j = 0; j < vector_num; j++) { 515 for (j = 0; j < vector_num; j++) {
@@ -2246,13 +2254,14 @@ static int hclgevf_init_msi(struct hclgevf_dev *hdev)
2246 int vectors; 2254 int vectors;
2247 int i; 2255 int i;
2248 2256
2249 if (hnae3_get_bit(hdev->ae_dev->flag, HNAE3_DEV_SUPPORT_ROCE_B)) 2257 if (hnae3_dev_roce_supported(hdev))
2250 vectors = pci_alloc_irq_vectors(pdev, 2258 vectors = pci_alloc_irq_vectors(pdev,
2251 hdev->roce_base_msix_offset + 1, 2259 hdev->roce_base_msix_offset + 1,
2252 hdev->num_msi, 2260 hdev->num_msi,
2253 PCI_IRQ_MSIX); 2261 PCI_IRQ_MSIX);
2254 else 2262 else
2255 vectors = pci_alloc_irq_vectors(pdev, 1, hdev->num_msi, 2263 vectors = pci_alloc_irq_vectors(pdev, HNAE3_MIN_VECTOR_NUM,
2264 hdev->num_msi,
2256 PCI_IRQ_MSI | PCI_IRQ_MSIX); 2265 PCI_IRQ_MSI | PCI_IRQ_MSIX);
2257 2266
2258 if (vectors < 0) { 2267 if (vectors < 0) {
@@ -2268,6 +2277,7 @@ static int hclgevf_init_msi(struct hclgevf_dev *hdev)
2268 2277
2269 hdev->num_msi = vectors; 2278 hdev->num_msi = vectors;
2270 hdev->num_msi_left = vectors; 2279 hdev->num_msi_left = vectors;
2280
2271 hdev->base_msi_vector = pdev->irq; 2281 hdev->base_msi_vector = pdev->irq;
2272 hdev->roce_base_vector = pdev->irq + hdev->roce_base_msix_offset; 2282 hdev->roce_base_vector = pdev->irq + hdev->roce_base_msix_offset;
2273 2283
@@ -2533,7 +2543,7 @@ static int hclgevf_query_vf_resource(struct hclgevf_dev *hdev)
2533 2543
2534 req = (struct hclgevf_query_res_cmd *)desc.data; 2544 req = (struct hclgevf_query_res_cmd *)desc.data;
2535 2545
2536 if (hnae3_get_bit(hdev->ae_dev->flag, HNAE3_DEV_SUPPORT_ROCE_B)) { 2546 if (hnae3_dev_roce_supported(hdev)) {
2537 hdev->roce_base_msix_offset = 2547 hdev->roce_base_msix_offset =
2538 hnae3_get_field(__le16_to_cpu(req->msixcap_localid_ba_rocee), 2548 hnae3_get_field(__le16_to_cpu(req->msixcap_localid_ba_rocee),
2539 HCLGEVF_MSIX_OFT_ROCEE_M, 2549 HCLGEVF_MSIX_OFT_ROCEE_M,
@@ -2542,6 +2552,9 @@ static int hclgevf_query_vf_resource(struct hclgevf_dev *hdev)
2542 hnae3_get_field(__le16_to_cpu(req->vf_intr_vector_number), 2552 hnae3_get_field(__le16_to_cpu(req->vf_intr_vector_number),
2543 HCLGEVF_VEC_NUM_M, HCLGEVF_VEC_NUM_S); 2553 HCLGEVF_VEC_NUM_M, HCLGEVF_VEC_NUM_S);
2544 2554
2555 /* nic's msix numbers is always equals to the roce's. */
2556 hdev->num_nic_msix = hdev->num_roce_msix;
2557
2545 /* VF should have NIC vectors and Roce vectors, NIC vectors 2558 /* VF should have NIC vectors and Roce vectors, NIC vectors
2546 * are queued before Roce vectors. The offset is fixed to 64. 2559 * are queued before Roce vectors. The offset is fixed to 64.
2547 */ 2560 */
@@ -2551,6 +2564,15 @@ static int hclgevf_query_vf_resource(struct hclgevf_dev *hdev)
2551 hdev->num_msi = 2564 hdev->num_msi =
2552 hnae3_get_field(__le16_to_cpu(req->vf_intr_vector_number), 2565 hnae3_get_field(__le16_to_cpu(req->vf_intr_vector_number),
2553 HCLGEVF_VEC_NUM_M, HCLGEVF_VEC_NUM_S); 2566 HCLGEVF_VEC_NUM_M, HCLGEVF_VEC_NUM_S);
2567
2568 hdev->num_nic_msix = hdev->num_msi;
2569 }
2570
2571 if (hdev->num_nic_msix < HNAE3_MIN_VECTOR_NUM) {
2572 dev_err(&hdev->pdev->dev,
2573 "Just %u msi resources, not enough for vf(min:2).\n",
2574 hdev->num_nic_msix);
2575 return -EINVAL;
2554 } 2576 }
2555 2577
2556 return 0; 2578 return 0;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h
index bdde3afc286b..2b8d6bc6d224 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h
@@ -270,6 +270,7 @@ struct hclgevf_dev {
270 u16 num_msi; 270 u16 num_msi;
271 u16 num_msi_left; 271 u16 num_msi_left;
272 u16 num_msi_used; 272 u16 num_msi_used;
273 u16 num_nic_msix; /* Num of nic vectors for this VF */
273 u16 num_roce_msix; /* Num of roce vectors for this VF */ 274 u16 num_roce_msix; /* Num of roce vectors for this VF */
274 u16 roce_base_msix_offset; 275 u16 roce_base_msix_offset;
275 int roce_base_vector; 276 int roce_base_vector;
diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c b/drivers/net/ethernet/hisilicon/hns_mdio.c
index 3e863a71c513..7df5d7d211d4 100644
--- a/drivers/net/ethernet/hisilicon/hns_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns_mdio.c
@@ -148,11 +148,15 @@ static int mdio_sc_cfg_reg_write(struct hns_mdio_device *mdio_dev,
148{ 148{
149 u32 time_cnt; 149 u32 time_cnt;
150 u32 reg_value; 150 u32 reg_value;
151 int ret;
151 152
152 regmap_write(mdio_dev->subctrl_vbase, cfg_reg, set_val); 153 regmap_write(mdio_dev->subctrl_vbase, cfg_reg, set_val);
153 154
154 for (time_cnt = MDIO_TIMEOUT; time_cnt; time_cnt--) { 155 for (time_cnt = MDIO_TIMEOUT; time_cnt; time_cnt--) {
155 regmap_read(mdio_dev->subctrl_vbase, st_reg, &reg_value); 156 ret = regmap_read(mdio_dev->subctrl_vbase, st_reg, &reg_value);
157 if (ret)
158 return ret;
159
156 reg_value &= st_msk; 160 reg_value &= st_msk;
157 if ((!!check_st) == (!!reg_value)) 161 if ((!!check_st) == (!!reg_value))
158 break; 162 break;
diff --git a/drivers/net/ethernet/i825xx/lasi_82596.c b/drivers/net/ethernet/i825xx/lasi_82596.c
index 211c5f74b4c8..aec7e98bcc85 100644
--- a/drivers/net/ethernet/i825xx/lasi_82596.c
+++ b/drivers/net/ethernet/i825xx/lasi_82596.c
@@ -96,6 +96,8 @@
96 96
97#define OPT_SWAP_PORT 0x0001 /* Need to wordswp on the MPU port */ 97#define OPT_SWAP_PORT 0x0001 /* Need to wordswp on the MPU port */
98 98
99#define LIB82596_DMA_ATTR DMA_ATTR_NON_CONSISTENT
100
99#define DMA_WBACK(ndev, addr, len) \ 101#define DMA_WBACK(ndev, addr, len) \
100 do { dma_cache_sync((ndev)->dev.parent, (void *)addr, len, DMA_TO_DEVICE); } while (0) 102 do { dma_cache_sync((ndev)->dev.parent, (void *)addr, len, DMA_TO_DEVICE); } while (0)
101 103
@@ -200,7 +202,7 @@ static int __exit lan_remove_chip(struct parisc_device *pdev)
200 202
201 unregister_netdev (dev); 203 unregister_netdev (dev);
202 dma_free_attrs(&pdev->dev, sizeof(struct i596_private), lp->dma, 204 dma_free_attrs(&pdev->dev, sizeof(struct i596_private), lp->dma,
203 lp->dma_addr, DMA_ATTR_NON_CONSISTENT); 205 lp->dma_addr, LIB82596_DMA_ATTR);
204 free_netdev (dev); 206 free_netdev (dev);
205 return 0; 207 return 0;
206} 208}
diff --git a/drivers/net/ethernet/i825xx/lib82596.c b/drivers/net/ethernet/i825xx/lib82596.c
index 1274ad24d6af..f9742af7f142 100644
--- a/drivers/net/ethernet/i825xx/lib82596.c
+++ b/drivers/net/ethernet/i825xx/lib82596.c
@@ -1065,7 +1065,7 @@ static int i82596_probe(struct net_device *dev)
1065 1065
1066 dma = dma_alloc_attrs(dev->dev.parent, sizeof(struct i596_dma), 1066 dma = dma_alloc_attrs(dev->dev.parent, sizeof(struct i596_dma),
1067 &lp->dma_addr, GFP_KERNEL, 1067 &lp->dma_addr, GFP_KERNEL,
1068 DMA_ATTR_NON_CONSISTENT); 1068 LIB82596_DMA_ATTR);
1069 if (!dma) { 1069 if (!dma) {
1070 printk(KERN_ERR "%s: Couldn't get shared memory\n", __FILE__); 1070 printk(KERN_ERR "%s: Couldn't get shared memory\n", __FILE__);
1071 return -ENOMEM; 1071 return -ENOMEM;
@@ -1087,7 +1087,7 @@ static int i82596_probe(struct net_device *dev)
1087 i = register_netdev(dev); 1087 i = register_netdev(dev);
1088 if (i) { 1088 if (i) {
1089 dma_free_attrs(dev->dev.parent, sizeof(struct i596_dma), 1089 dma_free_attrs(dev->dev.parent, sizeof(struct i596_dma),
1090 dma, lp->dma_addr, DMA_ATTR_NON_CONSISTENT); 1090 dma, lp->dma_addr, LIB82596_DMA_ATTR);
1091 return i; 1091 return i;
1092 } 1092 }
1093 1093
diff --git a/drivers/net/ethernet/i825xx/sni_82596.c b/drivers/net/ethernet/i825xx/sni_82596.c
index 6eb6c2ff7f09..6436a98c5953 100644
--- a/drivers/net/ethernet/i825xx/sni_82596.c
+++ b/drivers/net/ethernet/i825xx/sni_82596.c
@@ -24,6 +24,8 @@
24 24
25static const char sni_82596_string[] = "snirm_82596"; 25static const char sni_82596_string[] = "snirm_82596";
26 26
27#define LIB82596_DMA_ATTR 0
28
27#define DMA_WBACK(priv, addr, len) do { } while (0) 29#define DMA_WBACK(priv, addr, len) do { } while (0)
28#define DMA_INV(priv, addr, len) do { } while (0) 30#define DMA_INV(priv, addr, len) do { } while (0)
29#define DMA_WBACK_INV(priv, addr, len) do { } while (0) 31#define DMA_WBACK_INV(priv, addr, len) do { } while (0)
@@ -152,7 +154,7 @@ static int sni_82596_driver_remove(struct platform_device *pdev)
152 154
153 unregister_netdev(dev); 155 unregister_netdev(dev);
154 dma_free_attrs(dev->dev.parent, sizeof(struct i596_private), lp->dma, 156 dma_free_attrs(dev->dev.parent, sizeof(struct i596_private), lp->dma,
155 lp->dma_addr, DMA_ATTR_NON_CONSISTENT); 157 lp->dma_addr, LIB82596_DMA_ATTR);
156 iounmap(lp->ca); 158 iounmap(lp->ca);
157 iounmap(lp->mpu_port); 159 iounmap(lp->mpu_port);
158 free_netdev (dev); 160 free_netdev (dev);
diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
index 2b073a3c0b84..f59d9a8e35e2 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -2878,12 +2878,10 @@ static int enable_scrq_irq(struct ibmvnic_adapter *adapter,
2878 2878
2879 if (test_bit(0, &adapter->resetting) && 2879 if (test_bit(0, &adapter->resetting) &&
2880 adapter->reset_reason == VNIC_RESET_MOBILITY) { 2880 adapter->reset_reason == VNIC_RESET_MOBILITY) {
2881 u64 val = (0xff000000) | scrq->hw_irq; 2881 struct irq_desc *desc = irq_to_desc(scrq->irq);
2882 struct irq_chip *chip = irq_desc_get_chip(desc);
2882 2883
2883 rc = plpar_hcall_norets(H_EOI, val); 2884 chip->irq_eoi(&desc->irq_data);
2884 if (rc)
2885 dev_err(dev, "H_EOI FAILED irq 0x%llx. rc=%ld\n",
2886 val, rc);
2887 } 2885 }
2888 2886
2889 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address, 2887 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
diff --git a/drivers/net/ethernet/marvell/mvneta_bm.h b/drivers/net/ethernet/marvell/mvneta_bm.h
index c8425d35c049..e47783ce77e0 100644
--- a/drivers/net/ethernet/marvell/mvneta_bm.h
+++ b/drivers/net/ethernet/marvell/mvneta_bm.h
@@ -160,16 +160,23 @@ static inline u32 mvneta_bm_pool_get_bp(struct mvneta_bm *priv,
160 (bm_pool->id << MVNETA_BM_POOL_ACCESS_OFFS)); 160 (bm_pool->id << MVNETA_BM_POOL_ACCESS_OFFS));
161} 161}
162#else 162#else
163void mvneta_bm_pool_destroy(struct mvneta_bm *priv, 163static inline void mvneta_bm_pool_destroy(struct mvneta_bm *priv,
164 struct mvneta_bm_pool *bm_pool, u8 port_map) {} 164 struct mvneta_bm_pool *bm_pool,
165void mvneta_bm_bufs_free(struct mvneta_bm *priv, struct mvneta_bm_pool *bm_pool, 165 u8 port_map) {}
166 u8 port_map) {} 166static inline void mvneta_bm_bufs_free(struct mvneta_bm *priv,
167int mvneta_bm_construct(struct hwbm_pool *hwbm_pool, void *buf) { return 0; } 167 struct mvneta_bm_pool *bm_pool,
168int mvneta_bm_pool_refill(struct mvneta_bm *priv, 168 u8 port_map) {}
169 struct mvneta_bm_pool *bm_pool) {return 0; } 169static inline int mvneta_bm_construct(struct hwbm_pool *hwbm_pool, void *buf)
170struct mvneta_bm_pool *mvneta_bm_pool_use(struct mvneta_bm *priv, u8 pool_id, 170{ return 0; }
171 enum mvneta_bm_type type, u8 port_id, 171static inline int mvneta_bm_pool_refill(struct mvneta_bm *priv,
172 int pkt_size) { return NULL; } 172 struct mvneta_bm_pool *bm_pool)
173{ return 0; }
174static inline struct mvneta_bm_pool *mvneta_bm_pool_use(struct mvneta_bm *priv,
175 u8 pool_id,
176 enum mvneta_bm_type type,
177 u8 port_id,
178 int pkt_size)
179{ return NULL; }
173 180
174static inline void mvneta_bm_pool_put_bp(struct mvneta_bm *priv, 181static inline void mvneta_bm_pool_put_bp(struct mvneta_bm *priv,
175 struct mvneta_bm_pool *bm_pool, 182 struct mvneta_bm_pool *bm_pool,
@@ -178,7 +185,8 @@ static inline void mvneta_bm_pool_put_bp(struct mvneta_bm *priv,
178static inline u32 mvneta_bm_pool_get_bp(struct mvneta_bm *priv, 185static inline u32 mvneta_bm_pool_get_bp(struct mvneta_bm *priv,
179 struct mvneta_bm_pool *bm_pool) 186 struct mvneta_bm_pool *bm_pool)
180{ return 0; } 187{ return 0; }
181struct mvneta_bm *mvneta_bm_get(struct device_node *node) { return NULL; } 188static inline struct mvneta_bm *mvneta_bm_get(struct device_node *node)
182void mvneta_bm_put(struct mvneta_bm *priv) {} 189{ return NULL; }
190static inline void mvneta_bm_put(struct mvneta_bm *priv) {}
183#endif /* CONFIG_MVNETA_BM */ 191#endif /* CONFIG_MVNETA_BM */
184#endif 192#endif
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index c61069340f4f..703adb96429e 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -261,6 +261,7 @@ static void mtk_mac_config(struct phylink_config *config, unsigned int mode,
261 ge_mode = 0; 261 ge_mode = 0;
262 switch (state->interface) { 262 switch (state->interface) {
263 case PHY_INTERFACE_MODE_MII: 263 case PHY_INTERFACE_MODE_MII:
264 case PHY_INTERFACE_MODE_GMII:
264 ge_mode = 1; 265 ge_mode = 1;
265 break; 266 break;
266 case PHY_INTERFACE_MODE_REVMII: 267 case PHY_INTERFACE_MODE_REVMII:
diff --git a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
index 4356f3a58002..1187ef1375e2 100644
--- a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
+++ b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
@@ -471,12 +471,31 @@ void mlx4_init_quotas(struct mlx4_dev *dev)
471 priv->mfunc.master.res_tracker.res_alloc[RES_MPT].quota[pf]; 471 priv->mfunc.master.res_tracker.res_alloc[RES_MPT].quota[pf];
472} 472}
473 473
474static int get_max_gauranteed_vfs_counter(struct mlx4_dev *dev) 474static int
475mlx4_calc_res_counter_guaranteed(struct mlx4_dev *dev,
476 struct resource_allocator *res_alloc,
477 int vf)
475{ 478{
476 /* reduce the sink counter */ 479 struct mlx4_active_ports actv_ports;
477 return (dev->caps.max_counters - 1 - 480 int ports, counters_guaranteed;
478 (MLX4_PF_COUNTERS_PER_PORT * MLX4_MAX_PORTS)) 481
479 / MLX4_MAX_PORTS; 482 /* For master, only allocate according to the number of phys ports */
483 if (vf == mlx4_master_func_num(dev))
484 return MLX4_PF_COUNTERS_PER_PORT * dev->caps.num_ports;
485
486 /* calculate real number of ports for the VF */
487 actv_ports = mlx4_get_active_ports(dev, vf);
488 ports = bitmap_weight(actv_ports.ports, dev->caps.num_ports);
489 counters_guaranteed = ports * MLX4_VF_COUNTERS_PER_PORT;
490
491 /* If we do not have enough counters for this VF, do not
492 * allocate any for it. '-1' to reduce the sink counter.
493 */
494 if ((res_alloc->res_reserved + counters_guaranteed) >
495 (dev->caps.max_counters - 1))
496 return 0;
497
498 return counters_guaranteed;
480} 499}
481 500
482int mlx4_init_resource_tracker(struct mlx4_dev *dev) 501int mlx4_init_resource_tracker(struct mlx4_dev *dev)
@@ -484,7 +503,6 @@ int mlx4_init_resource_tracker(struct mlx4_dev *dev)
484 struct mlx4_priv *priv = mlx4_priv(dev); 503 struct mlx4_priv *priv = mlx4_priv(dev);
485 int i, j; 504 int i, j;
486 int t; 505 int t;
487 int max_vfs_guarantee_counter = get_max_gauranteed_vfs_counter(dev);
488 506
489 priv->mfunc.master.res_tracker.slave_list = 507 priv->mfunc.master.res_tracker.slave_list =
490 kcalloc(dev->num_slaves, sizeof(struct slave_list), 508 kcalloc(dev->num_slaves, sizeof(struct slave_list),
@@ -603,16 +621,8 @@ int mlx4_init_resource_tracker(struct mlx4_dev *dev)
603 break; 621 break;
604 case RES_COUNTER: 622 case RES_COUNTER:
605 res_alloc->quota[t] = dev->caps.max_counters; 623 res_alloc->quota[t] = dev->caps.max_counters;
606 if (t == mlx4_master_func_num(dev)) 624 res_alloc->guaranteed[t] =
607 res_alloc->guaranteed[t] = 625 mlx4_calc_res_counter_guaranteed(dev, res_alloc, t);
608 MLX4_PF_COUNTERS_PER_PORT *
609 MLX4_MAX_PORTS;
610 else if (t <= max_vfs_guarantee_counter)
611 res_alloc->guaranteed[t] =
612 MLX4_VF_COUNTERS_PER_PORT *
613 MLX4_MAX_PORTS;
614 else
615 res_alloc->guaranteed[t] = 0;
616 break; 626 break;
617 default: 627 default:
618 break; 628 break;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h
index 8d76452cacdc..f1a7bc46f1c0 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h
@@ -345,7 +345,7 @@ struct mlx5e_tx_wqe_info {
345 u8 num_wqebbs; 345 u8 num_wqebbs;
346 u8 num_dma; 346 u8 num_dma;
347#ifdef CONFIG_MLX5_EN_TLS 347#ifdef CONFIG_MLX5_EN_TLS
348 skb_frag_t *resync_dump_frag; 348 struct page *resync_dump_frag_page;
349#endif 349#endif
350}; 350};
351 351
@@ -410,6 +410,7 @@ struct mlx5e_txqsq {
410 struct device *pdev; 410 struct device *pdev;
411 __be32 mkey_be; 411 __be32 mkey_be;
412 unsigned long state; 412 unsigned long state;
413 unsigned int hw_mtu;
413 struct hwtstamp_config *tstamp; 414 struct hwtstamp_config *tstamp;
414 struct mlx5_clock *clock; 415 struct mlx5_clock *clock;
415 416
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/hv_vhca_stats.c b/drivers/net/ethernet/mellanox/mlx5/core/en/hv_vhca_stats.c
index b3a249b2a482..ac44bbe95c5c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/hv_vhca_stats.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/hv_vhca_stats.c
@@ -141,7 +141,7 @@ int mlx5e_hv_vhca_stats_create(struct mlx5e_priv *priv)
141 "Failed to create hv vhca stats agent, err = %ld\n", 141 "Failed to create hv vhca stats agent, err = %ld\n",
142 PTR_ERR(agent)); 142 PTR_ERR(agent));
143 143
144 kfree(priv->stats_agent.buf); 144 kvfree(priv->stats_agent.buf);
145 return IS_ERR_OR_NULL(agent); 145 return IS_ERR_OR_NULL(agent);
146 } 146 }
147 147
@@ -157,5 +157,5 @@ void mlx5e_hv_vhca_stats_destroy(struct mlx5e_priv *priv)
157 return; 157 return;
158 158
159 mlx5_hv_vhca_agent_destroy(priv->stats_agent.agent); 159 mlx5_hv_vhca_agent_destroy(priv->stats_agent.agent);
160 kfree(priv->stats_agent.buf); 160 kvfree(priv->stats_agent.buf);
161} 161}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c
index f8ee18b4da6f..13af72556987 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c
@@ -97,15 +97,19 @@ static int mlx5e_route_lookup_ipv4(struct mlx5e_priv *priv,
97 if (ret) 97 if (ret)
98 return ret; 98 return ret;
99 99
100 if (mlx5_lag_is_multipath(mdev) && rt->rt_gw_family != AF_INET) 100 if (mlx5_lag_is_multipath(mdev) && rt->rt_gw_family != AF_INET) {
101 ip_rt_put(rt);
101 return -ENETUNREACH; 102 return -ENETUNREACH;
103 }
102#else 104#else
103 return -EOPNOTSUPP; 105 return -EOPNOTSUPP;
104#endif 106#endif
105 107
106 ret = get_route_and_out_devs(priv, rt->dst.dev, route_dev, out_dev); 108 ret = get_route_and_out_devs(priv, rt->dst.dev, route_dev, out_dev);
107 if (ret < 0) 109 if (ret < 0) {
110 ip_rt_put(rt);
108 return ret; 111 return ret;
112 }
109 113
110 if (!(*out_ttl)) 114 if (!(*out_ttl))
111 *out_ttl = ip4_dst_hoplimit(&rt->dst); 115 *out_ttl = ip4_dst_hoplimit(&rt->dst);
@@ -149,8 +153,10 @@ static int mlx5e_route_lookup_ipv6(struct mlx5e_priv *priv,
149 *out_ttl = ip6_dst_hoplimit(dst); 153 *out_ttl = ip6_dst_hoplimit(dst);
150 154
151 ret = get_route_and_out_devs(priv, dst->dev, route_dev, out_dev); 155 ret = get_route_and_out_devs(priv, dst->dev, route_dev, out_dev);
152 if (ret < 0) 156 if (ret < 0) {
157 dst_release(dst);
153 return ret; 158 return ret;
159 }
154#else 160#else
155 return -EOPNOTSUPP; 161 return -EOPNOTSUPP;
156#endif 162#endif
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h b/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h
index 87be96747902..7c8796d9743f 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h
@@ -15,15 +15,14 @@
15#else 15#else
16/* TLS offload requires additional stop_room for: 16/* TLS offload requires additional stop_room for:
17 * - a resync SKB. 17 * - a resync SKB.
18 * kTLS offload requires additional stop_room for: 18 * kTLS offload requires fixed additional stop_room for:
19 * - static params WQE, 19 * - a static params WQE, and a progress params WQE.
20 * - progress params WQE, and 20 * The additional MTU-depending room for the resync DUMP WQEs
21 * - resync DUMP per frag. 21 * will be calculated and added in runtime.
22 */ 22 */
23#define MLX5E_SQ_TLS_ROOM \ 23#define MLX5E_SQ_TLS_ROOM \
24 (MLX5_SEND_WQE_MAX_WQEBBS + \ 24 (MLX5_SEND_WQE_MAX_WQEBBS + \
25 MLX5E_KTLS_STATIC_WQEBBS + MLX5E_KTLS_PROGRESS_WQEBBS + \ 25 MLX5E_KTLS_STATIC_WQEBBS + MLX5E_KTLS_PROGRESS_WQEBBS)
26 MAX_SKB_FRAGS * MLX5E_KTLS_MAX_DUMP_WQEBBS)
27#endif 26#endif
28 27
29#define INL_HDR_START_SZ (sizeof(((struct mlx5_wqe_eth_seg *)NULL)->inline_hdr.start)) 28#define INL_HDR_START_SZ (sizeof(((struct mlx5_wqe_eth_seg *)NULL)->inline_hdr.start))
@@ -92,7 +91,7 @@ mlx5e_fill_sq_frag_edge(struct mlx5e_txqsq *sq, struct mlx5_wq_cyc *wq,
92 91
93 /* fill sq frag edge with nops to avoid wqe wrapping two pages */ 92 /* fill sq frag edge with nops to avoid wqe wrapping two pages */
94 for (; wi < edge_wi; wi++) { 93 for (; wi < edge_wi; wi++) {
95 wi->skb = NULL; 94 memset(wi, 0, sizeof(*wi));
96 wi->num_wqebbs = 1; 95 wi->num_wqebbs = 1;
97 mlx5e_post_nop(wq, sq->sqn, &sq->pc); 96 mlx5e_post_nop(wq, sq->sqn, &sq->pc);
98 } 97 }
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c
index d2ff74d52720..46725cd743a3 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c
@@ -38,7 +38,7 @@ static int mlx5e_ktls_add(struct net_device *netdev, struct sock *sk,
38 return -ENOMEM; 38 return -ENOMEM;
39 39
40 tx_priv->expected_seq = start_offload_tcp_sn; 40 tx_priv->expected_seq = start_offload_tcp_sn;
41 tx_priv->crypto_info = crypto_info; 41 tx_priv->crypto_info = *(struct tls12_crypto_info_aes_gcm_128 *)crypto_info;
42 mlx5e_set_ktls_tx_priv_ctx(tls_ctx, tx_priv); 42 mlx5e_set_ktls_tx_priv_ctx(tls_ctx, tx_priv);
43 43
44 /* tc and underlay_qpn values are not in use for tls tis */ 44 /* tc and underlay_qpn values are not in use for tls tis */
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.h
index b7298f9ee3d3..a3efa29a4629 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.h
@@ -21,7 +21,14 @@
21 MLX5_ST_SZ_BYTES(tls_progress_params)) 21 MLX5_ST_SZ_BYTES(tls_progress_params))
22#define MLX5E_KTLS_PROGRESS_WQEBBS \ 22#define MLX5E_KTLS_PROGRESS_WQEBBS \
23 (DIV_ROUND_UP(MLX5E_KTLS_PROGRESS_WQE_SZ, MLX5_SEND_WQE_BB)) 23 (DIV_ROUND_UP(MLX5E_KTLS_PROGRESS_WQE_SZ, MLX5_SEND_WQE_BB))
24#define MLX5E_KTLS_MAX_DUMP_WQEBBS 2 24
25struct mlx5e_dump_wqe {
26 struct mlx5_wqe_ctrl_seg ctrl;
27 struct mlx5_wqe_data_seg data;
28};
29
30#define MLX5E_KTLS_DUMP_WQEBBS \
31 (DIV_ROUND_UP(sizeof(struct mlx5e_dump_wqe), MLX5_SEND_WQE_BB))
25 32
26enum { 33enum {
27 MLX5E_TLS_PROGRESS_PARAMS_AUTH_STATE_NO_OFFLOAD = 0, 34 MLX5E_TLS_PROGRESS_PARAMS_AUTH_STATE_NO_OFFLOAD = 0,
@@ -37,7 +44,7 @@ enum {
37 44
38struct mlx5e_ktls_offload_context_tx { 45struct mlx5e_ktls_offload_context_tx {
39 struct tls_offload_context_tx *tx_ctx; 46 struct tls_offload_context_tx *tx_ctx;
40 struct tls_crypto_info *crypto_info; 47 struct tls12_crypto_info_aes_gcm_128 crypto_info;
41 u32 expected_seq; 48 u32 expected_seq;
42 u32 tisn; 49 u32 tisn;
43 u32 key_id; 50 u32 key_id;
@@ -86,14 +93,28 @@ struct sk_buff *mlx5e_ktls_handle_tx_skb(struct net_device *netdev,
86 struct mlx5e_tx_wqe **wqe, u16 *pi); 93 struct mlx5e_tx_wqe **wqe, u16 *pi);
87void mlx5e_ktls_tx_handle_resync_dump_comp(struct mlx5e_txqsq *sq, 94void mlx5e_ktls_tx_handle_resync_dump_comp(struct mlx5e_txqsq *sq,
88 struct mlx5e_tx_wqe_info *wi, 95 struct mlx5e_tx_wqe_info *wi,
89 struct mlx5e_sq_dma *dma); 96 u32 *dma_fifo_cc);
90 97static inline u8
98mlx5e_ktls_dumps_num_wqebbs(struct mlx5e_txqsq *sq, unsigned int nfrags,
99 unsigned int sync_len)
100{
101 /* Given the MTU and sync_len, calculates an upper bound for the
102 * number of WQEBBs needed for the TX resync DUMP WQEs of a record.
103 */
104 return MLX5E_KTLS_DUMP_WQEBBS *
105 (nfrags + DIV_ROUND_UP(sync_len, sq->hw_mtu));
106}
91#else 107#else
92 108
93static inline void mlx5e_ktls_build_netdev(struct mlx5e_priv *priv) 109static inline void mlx5e_ktls_build_netdev(struct mlx5e_priv *priv)
94{ 110{
95} 111}
96 112
113static inline void
114mlx5e_ktls_tx_handle_resync_dump_comp(struct mlx5e_txqsq *sq,
115 struct mlx5e_tx_wqe_info *wi,
116 u32 *dma_fifo_cc) {}
117
97#endif 118#endif
98 119
99#endif /* __MLX5E_TLS_H__ */ 120#endif /* __MLX5E_TLS_H__ */
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c
index d195366461c9..778dab1af8fc 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c
@@ -24,17 +24,12 @@ enum {
24static void 24static void
25fill_static_params_ctx(void *ctx, struct mlx5e_ktls_offload_context_tx *priv_tx) 25fill_static_params_ctx(void *ctx, struct mlx5e_ktls_offload_context_tx *priv_tx)
26{ 26{
27 struct tls_crypto_info *crypto_info = priv_tx->crypto_info; 27 struct tls12_crypto_info_aes_gcm_128 *info = &priv_tx->crypto_info;
28 struct tls12_crypto_info_aes_gcm_128 *info;
29 char *initial_rn, *gcm_iv; 28 char *initial_rn, *gcm_iv;
30 u16 salt_sz, rec_seq_sz; 29 u16 salt_sz, rec_seq_sz;
31 char *salt, *rec_seq; 30 char *salt, *rec_seq;
32 u8 tls_version; 31 u8 tls_version;
33 32
34 if (WARN_ON(crypto_info->cipher_type != TLS_CIPHER_AES_GCM_128))
35 return;
36
37 info = (struct tls12_crypto_info_aes_gcm_128 *)crypto_info;
38 EXTRACT_INFO_FIELDS; 33 EXTRACT_INFO_FIELDS;
39 34
40 gcm_iv = MLX5_ADDR_OF(tls_static_params, ctx, gcm_iv); 35 gcm_iv = MLX5_ADDR_OF(tls_static_params, ctx, gcm_iv);
@@ -108,16 +103,15 @@ build_progress_params(struct mlx5e_tx_wqe *wqe, u16 pc, u32 sqn,
108} 103}
109 104
110static void tx_fill_wi(struct mlx5e_txqsq *sq, 105static void tx_fill_wi(struct mlx5e_txqsq *sq,
111 u16 pi, u8 num_wqebbs, 106 u16 pi, u8 num_wqebbs, u32 num_bytes,
112 skb_frag_t *resync_dump_frag, 107 struct page *page)
113 u32 num_bytes)
114{ 108{
115 struct mlx5e_tx_wqe_info *wi = &sq->db.wqe_info[pi]; 109 struct mlx5e_tx_wqe_info *wi = &sq->db.wqe_info[pi];
116 110
117 wi->skb = NULL; 111 memset(wi, 0, sizeof(*wi));
118 wi->num_wqebbs = num_wqebbs; 112 wi->num_wqebbs = num_wqebbs;
119 wi->resync_dump_frag = resync_dump_frag; 113 wi->num_bytes = num_bytes;
120 wi->num_bytes = num_bytes; 114 wi->resync_dump_frag_page = page;
121} 115}
122 116
123void mlx5e_ktls_tx_offload_set_pending(struct mlx5e_ktls_offload_context_tx *priv_tx) 117void mlx5e_ktls_tx_offload_set_pending(struct mlx5e_ktls_offload_context_tx *priv_tx)
@@ -145,7 +139,7 @@ post_static_params(struct mlx5e_txqsq *sq,
145 139
146 umr_wqe = mlx5e_sq_fetch_wqe(sq, MLX5E_KTLS_STATIC_UMR_WQE_SZ, &pi); 140 umr_wqe = mlx5e_sq_fetch_wqe(sq, MLX5E_KTLS_STATIC_UMR_WQE_SZ, &pi);
147 build_static_params(umr_wqe, sq->pc, sq->sqn, priv_tx, fence); 141 build_static_params(umr_wqe, sq->pc, sq->sqn, priv_tx, fence);
148 tx_fill_wi(sq, pi, MLX5E_KTLS_STATIC_WQEBBS, NULL, 0); 142 tx_fill_wi(sq, pi, MLX5E_KTLS_STATIC_WQEBBS, 0, NULL);
149 sq->pc += MLX5E_KTLS_STATIC_WQEBBS; 143 sq->pc += MLX5E_KTLS_STATIC_WQEBBS;
150} 144}
151 145
@@ -159,7 +153,7 @@ post_progress_params(struct mlx5e_txqsq *sq,
159 153
160 wqe = mlx5e_sq_fetch_wqe(sq, MLX5E_KTLS_PROGRESS_WQE_SZ, &pi); 154 wqe = mlx5e_sq_fetch_wqe(sq, MLX5E_KTLS_PROGRESS_WQE_SZ, &pi);
161 build_progress_params(wqe, sq->pc, sq->sqn, priv_tx, fence); 155 build_progress_params(wqe, sq->pc, sq->sqn, priv_tx, fence);
162 tx_fill_wi(sq, pi, MLX5E_KTLS_PROGRESS_WQEBBS, NULL, 0); 156 tx_fill_wi(sq, pi, MLX5E_KTLS_PROGRESS_WQEBBS, 0, NULL);
163 sq->pc += MLX5E_KTLS_PROGRESS_WQEBBS; 157 sq->pc += MLX5E_KTLS_PROGRESS_WQEBBS;
164} 158}
165 159
@@ -169,6 +163,14 @@ mlx5e_ktls_tx_post_param_wqes(struct mlx5e_txqsq *sq,
169 bool skip_static_post, bool fence_first_post) 163 bool skip_static_post, bool fence_first_post)
170{ 164{
171 bool progress_fence = skip_static_post || !fence_first_post; 165 bool progress_fence = skip_static_post || !fence_first_post;
166 struct mlx5_wq_cyc *wq = &sq->wq;
167 u16 contig_wqebbs_room, pi;
168
169 pi = mlx5_wq_cyc_ctr2ix(wq, sq->pc);
170 contig_wqebbs_room = mlx5_wq_cyc_get_contig_wqebbs(wq, pi);
171 if (unlikely(contig_wqebbs_room <
172 MLX5E_KTLS_STATIC_WQEBBS + MLX5E_KTLS_PROGRESS_WQEBBS))
173 mlx5e_fill_sq_frag_edge(sq, wq, pi, contig_wqebbs_room);
172 174
173 if (!skip_static_post) 175 if (!skip_static_post)
174 post_static_params(sq, priv_tx, fence_first_post); 176 post_static_params(sq, priv_tx, fence_first_post);
@@ -180,29 +182,36 @@ struct tx_sync_info {
180 u64 rcd_sn; 182 u64 rcd_sn;
181 s32 sync_len; 183 s32 sync_len;
182 int nr_frags; 184 int nr_frags;
183 skb_frag_t *frags[MAX_SKB_FRAGS]; 185 skb_frag_t frags[MAX_SKB_FRAGS];
186};
187
188enum mlx5e_ktls_sync_retval {
189 MLX5E_KTLS_SYNC_DONE,
190 MLX5E_KTLS_SYNC_FAIL,
191 MLX5E_KTLS_SYNC_SKIP_NO_DATA,
184}; 192};
185 193
186static bool tx_sync_info_get(struct mlx5e_ktls_offload_context_tx *priv_tx, 194static enum mlx5e_ktls_sync_retval
187 u32 tcp_seq, struct tx_sync_info *info) 195tx_sync_info_get(struct mlx5e_ktls_offload_context_tx *priv_tx,
196 u32 tcp_seq, struct tx_sync_info *info)
188{ 197{
189 struct tls_offload_context_tx *tx_ctx = priv_tx->tx_ctx; 198 struct tls_offload_context_tx *tx_ctx = priv_tx->tx_ctx;
199 enum mlx5e_ktls_sync_retval ret = MLX5E_KTLS_SYNC_DONE;
190 struct tls_record_info *record; 200 struct tls_record_info *record;
191 int remaining, i = 0; 201 int remaining, i = 0;
192 unsigned long flags; 202 unsigned long flags;
193 bool ret = true;
194 203
195 spin_lock_irqsave(&tx_ctx->lock, flags); 204 spin_lock_irqsave(&tx_ctx->lock, flags);
196 record = tls_get_record(tx_ctx, tcp_seq, &info->rcd_sn); 205 record = tls_get_record(tx_ctx, tcp_seq, &info->rcd_sn);
197 206
198 if (unlikely(!record)) { 207 if (unlikely(!record)) {
199 ret = false; 208 ret = MLX5E_KTLS_SYNC_FAIL;
200 goto out; 209 goto out;
201 } 210 }
202 211
203 if (unlikely(tcp_seq < tls_record_start_seq(record))) { 212 if (unlikely(tcp_seq < tls_record_start_seq(record))) {
204 if (!tls_record_is_start_marker(record)) 213 ret = tls_record_is_start_marker(record) ?
205 ret = false; 214 MLX5E_KTLS_SYNC_SKIP_NO_DATA : MLX5E_KTLS_SYNC_FAIL;
206 goto out; 215 goto out;
207 } 216 }
208 217
@@ -211,13 +220,13 @@ static bool tx_sync_info_get(struct mlx5e_ktls_offload_context_tx *priv_tx,
211 while (remaining > 0) { 220 while (remaining > 0) {
212 skb_frag_t *frag = &record->frags[i]; 221 skb_frag_t *frag = &record->frags[i];
213 222
214 __skb_frag_ref(frag); 223 get_page(skb_frag_page(frag));
215 remaining -= skb_frag_size(frag); 224 remaining -= skb_frag_size(frag);
216 info->frags[i++] = frag; 225 info->frags[i++] = *frag;
217 } 226 }
218 /* reduce the part which will be sent with the original SKB */ 227 /* reduce the part which will be sent with the original SKB */
219 if (remaining < 0) 228 if (remaining < 0)
220 skb_frag_size_add(info->frags[i - 1], remaining); 229 skb_frag_size_add(&info->frags[i - 1], remaining);
221 info->nr_frags = i; 230 info->nr_frags = i;
222out: 231out:
223 spin_unlock_irqrestore(&tx_ctx->lock, flags); 232 spin_unlock_irqrestore(&tx_ctx->lock, flags);
@@ -229,17 +238,12 @@ tx_post_resync_params(struct mlx5e_txqsq *sq,
229 struct mlx5e_ktls_offload_context_tx *priv_tx, 238 struct mlx5e_ktls_offload_context_tx *priv_tx,
230 u64 rcd_sn) 239 u64 rcd_sn)
231{ 240{
232 struct tls_crypto_info *crypto_info = priv_tx->crypto_info; 241 struct tls12_crypto_info_aes_gcm_128 *info = &priv_tx->crypto_info;
233 struct tls12_crypto_info_aes_gcm_128 *info;
234 __be64 rn_be = cpu_to_be64(rcd_sn); 242 __be64 rn_be = cpu_to_be64(rcd_sn);
235 bool skip_static_post; 243 bool skip_static_post;
236 u16 rec_seq_sz; 244 u16 rec_seq_sz;
237 char *rec_seq; 245 char *rec_seq;
238 246
239 if (WARN_ON(crypto_info->cipher_type != TLS_CIPHER_AES_GCM_128))
240 return;
241
242 info = (struct tls12_crypto_info_aes_gcm_128 *)crypto_info;
243 rec_seq = info->rec_seq; 247 rec_seq = info->rec_seq;
244 rec_seq_sz = sizeof(info->rec_seq); 248 rec_seq_sz = sizeof(info->rec_seq);
245 249
@@ -250,11 +254,6 @@ tx_post_resync_params(struct mlx5e_txqsq *sq,
250 mlx5e_ktls_tx_post_param_wqes(sq, priv_tx, skip_static_post, true); 254 mlx5e_ktls_tx_post_param_wqes(sq, priv_tx, skip_static_post, true);
251} 255}
252 256
253struct mlx5e_dump_wqe {
254 struct mlx5_wqe_ctrl_seg ctrl;
255 struct mlx5_wqe_data_seg data;
256};
257
258static int 257static int
259tx_post_resync_dump(struct mlx5e_txqsq *sq, skb_frag_t *frag, u32 tisn, bool first) 258tx_post_resync_dump(struct mlx5e_txqsq *sq, skb_frag_t *frag, u32 tisn, bool first)
260{ 259{
@@ -262,7 +261,6 @@ tx_post_resync_dump(struct mlx5e_txqsq *sq, skb_frag_t *frag, u32 tisn, bool fir
262 struct mlx5_wqe_data_seg *dseg; 261 struct mlx5_wqe_data_seg *dseg;
263 struct mlx5e_dump_wqe *wqe; 262 struct mlx5e_dump_wqe *wqe;
264 dma_addr_t dma_addr = 0; 263 dma_addr_t dma_addr = 0;
265 u8 num_wqebbs;
266 u16 ds_cnt; 264 u16 ds_cnt;
267 int fsz; 265 int fsz;
268 u16 pi; 266 u16 pi;
@@ -270,7 +268,6 @@ tx_post_resync_dump(struct mlx5e_txqsq *sq, skb_frag_t *frag, u32 tisn, bool fir
270 wqe = mlx5e_sq_fetch_wqe(sq, sizeof(*wqe), &pi); 268 wqe = mlx5e_sq_fetch_wqe(sq, sizeof(*wqe), &pi);
271 269
272 ds_cnt = sizeof(*wqe) / MLX5_SEND_WQE_DS; 270 ds_cnt = sizeof(*wqe) / MLX5_SEND_WQE_DS;
273 num_wqebbs = DIV_ROUND_UP(ds_cnt, MLX5_SEND_WQEBB_NUM_DS);
274 271
275 cseg = &wqe->ctrl; 272 cseg = &wqe->ctrl;
276 dseg = &wqe->data; 273 dseg = &wqe->data;
@@ -291,24 +288,27 @@ tx_post_resync_dump(struct mlx5e_txqsq *sq, skb_frag_t *frag, u32 tisn, bool fir
291 dseg->byte_count = cpu_to_be32(fsz); 288 dseg->byte_count = cpu_to_be32(fsz);
292 mlx5e_dma_push(sq, dma_addr, fsz, MLX5E_DMA_MAP_PAGE); 289 mlx5e_dma_push(sq, dma_addr, fsz, MLX5E_DMA_MAP_PAGE);
293 290
294 tx_fill_wi(sq, pi, num_wqebbs, frag, fsz); 291 tx_fill_wi(sq, pi, MLX5E_KTLS_DUMP_WQEBBS, fsz, skb_frag_page(frag));
295 sq->pc += num_wqebbs; 292 sq->pc += MLX5E_KTLS_DUMP_WQEBBS;
296
297 WARN(num_wqebbs > MLX5E_KTLS_MAX_DUMP_WQEBBS,
298 "unexpected DUMP num_wqebbs, %d > %d",
299 num_wqebbs, MLX5E_KTLS_MAX_DUMP_WQEBBS);
300 293
301 return 0; 294 return 0;
302} 295}
303 296
304void mlx5e_ktls_tx_handle_resync_dump_comp(struct mlx5e_txqsq *sq, 297void mlx5e_ktls_tx_handle_resync_dump_comp(struct mlx5e_txqsq *sq,
305 struct mlx5e_tx_wqe_info *wi, 298 struct mlx5e_tx_wqe_info *wi,
306 struct mlx5e_sq_dma *dma) 299 u32 *dma_fifo_cc)
307{ 300{
308 struct mlx5e_sq_stats *stats = sq->stats; 301 struct mlx5e_sq_stats *stats;
302 struct mlx5e_sq_dma *dma;
303
304 if (!wi->resync_dump_frag_page)
305 return;
306
307 dma = mlx5e_dma_get(sq, (*dma_fifo_cc)++);
308 stats = sq->stats;
309 309
310 mlx5e_tx_dma_unmap(sq->pdev, dma); 310 mlx5e_tx_dma_unmap(sq->pdev, dma);
311 __skb_frag_unref(wi->resync_dump_frag); 311 put_page(wi->resync_dump_frag_page);
312 stats->tls_dump_packets++; 312 stats->tls_dump_packets++;
313 stats->tls_dump_bytes += wi->num_bytes; 313 stats->tls_dump_bytes += wi->num_bytes;
314} 314}
@@ -318,25 +318,31 @@ static void tx_post_fence_nop(struct mlx5e_txqsq *sq)
318 struct mlx5_wq_cyc *wq = &sq->wq; 318 struct mlx5_wq_cyc *wq = &sq->wq;
319 u16 pi = mlx5_wq_cyc_ctr2ix(wq, sq->pc); 319 u16 pi = mlx5_wq_cyc_ctr2ix(wq, sq->pc);
320 320
321 tx_fill_wi(sq, pi, 1, NULL, 0); 321 tx_fill_wi(sq, pi, 1, 0, NULL);
322 322
323 mlx5e_post_nop_fence(wq, sq->sqn, &sq->pc); 323 mlx5e_post_nop_fence(wq, sq->sqn, &sq->pc);
324} 324}
325 325
326static struct sk_buff * 326static enum mlx5e_ktls_sync_retval
327mlx5e_ktls_tx_handle_ooo(struct mlx5e_ktls_offload_context_tx *priv_tx, 327mlx5e_ktls_tx_handle_ooo(struct mlx5e_ktls_offload_context_tx *priv_tx,
328 struct mlx5e_txqsq *sq, 328 struct mlx5e_txqsq *sq,
329 struct sk_buff *skb, 329 int datalen,
330 u32 seq) 330 u32 seq)
331{ 331{
332 struct mlx5e_sq_stats *stats = sq->stats; 332 struct mlx5e_sq_stats *stats = sq->stats;
333 struct mlx5_wq_cyc *wq = &sq->wq; 333 struct mlx5_wq_cyc *wq = &sq->wq;
334 enum mlx5e_ktls_sync_retval ret;
334 struct tx_sync_info info = {}; 335 struct tx_sync_info info = {};
335 u16 contig_wqebbs_room, pi; 336 u16 contig_wqebbs_room, pi;
336 u8 num_wqebbs; 337 u8 num_wqebbs;
337 int i; 338 int i = 0;
338 339
339 if (!tx_sync_info_get(priv_tx, seq, &info)) { 340 ret = tx_sync_info_get(priv_tx, seq, &info);
341 if (unlikely(ret != MLX5E_KTLS_SYNC_DONE)) {
342 if (ret == MLX5E_KTLS_SYNC_SKIP_NO_DATA) {
343 stats->tls_skip_no_sync_data++;
344 return MLX5E_KTLS_SYNC_SKIP_NO_DATA;
345 }
340 /* We might get here if a retransmission reaches the driver 346 /* We might get here if a retransmission reaches the driver
341 * after the relevant record is acked. 347 * after the relevant record is acked.
342 * It should be safe to drop the packet in this case 348 * It should be safe to drop the packet in this case
@@ -346,13 +352,8 @@ mlx5e_ktls_tx_handle_ooo(struct mlx5e_ktls_offload_context_tx *priv_tx,
346 } 352 }
347 353
348 if (unlikely(info.sync_len < 0)) { 354 if (unlikely(info.sync_len < 0)) {
349 u32 payload; 355 if (likely(datalen <= -info.sync_len))
350 int headln; 356 return MLX5E_KTLS_SYNC_DONE;
351
352 headln = skb_transport_offset(skb) + tcp_hdrlen(skb);
353 payload = skb->len - headln;
354 if (likely(payload <= -info.sync_len))
355 return skb;
356 357
357 stats->tls_drop_bypass_req++; 358 stats->tls_drop_bypass_req++;
358 goto err_out; 359 goto err_out;
@@ -360,30 +361,62 @@ mlx5e_ktls_tx_handle_ooo(struct mlx5e_ktls_offload_context_tx *priv_tx,
360 361
361 stats->tls_ooo++; 362 stats->tls_ooo++;
362 363
363 num_wqebbs = MLX5E_KTLS_STATIC_WQEBBS + MLX5E_KTLS_PROGRESS_WQEBBS + 364 tx_post_resync_params(sq, priv_tx, info.rcd_sn);
364 (info.nr_frags ? info.nr_frags * MLX5E_KTLS_MAX_DUMP_WQEBBS : 1); 365
366 /* If no dump WQE was sent, we need to have a fence NOP WQE before the
367 * actual data xmit.
368 */
369 if (!info.nr_frags) {
370 tx_post_fence_nop(sq);
371 return MLX5E_KTLS_SYNC_DONE;
372 }
373
374 num_wqebbs = mlx5e_ktls_dumps_num_wqebbs(sq, info.nr_frags, info.sync_len);
365 pi = mlx5_wq_cyc_ctr2ix(wq, sq->pc); 375 pi = mlx5_wq_cyc_ctr2ix(wq, sq->pc);
366 contig_wqebbs_room = mlx5_wq_cyc_get_contig_wqebbs(wq, pi); 376 contig_wqebbs_room = mlx5_wq_cyc_get_contig_wqebbs(wq, pi);
377
367 if (unlikely(contig_wqebbs_room < num_wqebbs)) 378 if (unlikely(contig_wqebbs_room < num_wqebbs))
368 mlx5e_fill_sq_frag_edge(sq, wq, pi, contig_wqebbs_room); 379 mlx5e_fill_sq_frag_edge(sq, wq, pi, contig_wqebbs_room);
369 380
370 tx_post_resync_params(sq, priv_tx, info.rcd_sn); 381 tx_post_resync_params(sq, priv_tx, info.rcd_sn);
371 382
372 for (i = 0; i < info.nr_frags; i++) 383 for (; i < info.nr_frags; i++) {
373 if (tx_post_resync_dump(sq, info.frags[i], priv_tx->tisn, !i)) 384 unsigned int orig_fsz, frag_offset = 0, n = 0;
374 goto err_out; 385 skb_frag_t *f = &info.frags[i];
375 386
376 /* If no dump WQE was sent, we need to have a fence NOP WQE before the 387 orig_fsz = skb_frag_size(f);
377 * actual data xmit.
378 */
379 if (!info.nr_frags)
380 tx_post_fence_nop(sq);
381 388
382 return skb; 389 do {
390 bool fence = !(i || frag_offset);
391 unsigned int fsz;
392
393 n++;
394 fsz = min_t(unsigned int, sq->hw_mtu, orig_fsz - frag_offset);
395 skb_frag_size_set(f, fsz);
396 if (tx_post_resync_dump(sq, f, priv_tx->tisn, fence)) {
397 page_ref_add(skb_frag_page(f), n - 1);
398 goto err_out;
399 }
400
401 skb_frag_off_add(f, fsz);
402 frag_offset += fsz;
403 } while (frag_offset < orig_fsz);
404
405 page_ref_add(skb_frag_page(f), n - 1);
406 }
407
408 return MLX5E_KTLS_SYNC_DONE;
383 409
384err_out: 410err_out:
385 dev_kfree_skb_any(skb); 411 for (; i < info.nr_frags; i++)
386 return NULL; 412 /* The put_page() here undoes the page ref obtained in tx_sync_info_get().
413 * Page refs obtained for the DUMP WQEs above (by page_ref_add) will be
414 * released only upon their completions (or in mlx5e_free_txqsq_descs,
415 * if channel closes).
416 */
417 put_page(skb_frag_page(&info.frags[i]));
418
419 return MLX5E_KTLS_SYNC_FAIL;
387} 420}
388 421
389struct sk_buff *mlx5e_ktls_handle_tx_skb(struct net_device *netdev, 422struct sk_buff *mlx5e_ktls_handle_tx_skb(struct net_device *netdev,
@@ -419,10 +452,15 @@ struct sk_buff *mlx5e_ktls_handle_tx_skb(struct net_device *netdev,
419 452
420 seq = ntohl(tcp_hdr(skb)->seq); 453 seq = ntohl(tcp_hdr(skb)->seq);
421 if (unlikely(priv_tx->expected_seq != seq)) { 454 if (unlikely(priv_tx->expected_seq != seq)) {
422 skb = mlx5e_ktls_tx_handle_ooo(priv_tx, sq, skb, seq); 455 enum mlx5e_ktls_sync_retval ret =
423 if (unlikely(!skb)) 456 mlx5e_ktls_tx_handle_ooo(priv_tx, sq, datalen, seq);
457
458 if (likely(ret == MLX5E_KTLS_SYNC_DONE))
459 *wqe = mlx5e_sq_fetch_wqe(sq, sizeof(**wqe), pi);
460 else if (ret == MLX5E_KTLS_SYNC_FAIL)
461 goto err_out;
462 else /* ret == MLX5E_KTLS_SYNC_SKIP_NO_DATA */
424 goto out; 463 goto out;
425 *wqe = mlx5e_sq_fetch_wqe(sq, sizeof(**wqe), pi);
426 } 464 }
427 465
428 priv_tx->expected_seq = seq + datalen; 466 priv_tx->expected_seq = seq + datalen;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
index c5a9c20d7f00..327c93a7bd55 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
@@ -1021,7 +1021,7 @@ static bool ext_link_mode_requested(const unsigned long *adver)
1021{ 1021{
1022#define MLX5E_MIN_PTYS_EXT_LINK_MODE_BIT ETHTOOL_LINK_MODE_50000baseKR_Full_BIT 1022#define MLX5E_MIN_PTYS_EXT_LINK_MODE_BIT ETHTOOL_LINK_MODE_50000baseKR_Full_BIT
1023 int size = __ETHTOOL_LINK_MODE_MASK_NBITS - MLX5E_MIN_PTYS_EXT_LINK_MODE_BIT; 1023 int size = __ETHTOOL_LINK_MODE_MASK_NBITS - MLX5E_MIN_PTYS_EXT_LINK_MODE_BIT;
1024 __ETHTOOL_DECLARE_LINK_MODE_MASK(modes); 1024 __ETHTOOL_DECLARE_LINK_MODE_MASK(modes) = {0,};
1025 1025
1026 bitmap_set(modes, MLX5E_MIN_PTYS_EXT_LINK_MODE_BIT, size); 1026 bitmap_set(modes, MLX5E_MIN_PTYS_EXT_LINK_MODE_BIT, size);
1027 return bitmap_intersects(modes, adver, __ETHTOOL_LINK_MODE_MASK_NBITS); 1027 return bitmap_intersects(modes, adver, __ETHTOOL_LINK_MODE_MASK_NBITS);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 7569287f8f3c..772bfdbdeb9c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -1128,6 +1128,7 @@ static int mlx5e_alloc_txqsq(struct mlx5e_channel *c,
1128 sq->txq_ix = txq_ix; 1128 sq->txq_ix = txq_ix;
1129 sq->uar_map = mdev->mlx5e_res.bfreg.map; 1129 sq->uar_map = mdev->mlx5e_res.bfreg.map;
1130 sq->min_inline_mode = params->tx_min_inline_mode; 1130 sq->min_inline_mode = params->tx_min_inline_mode;
1131 sq->hw_mtu = MLX5E_SW2HW_MTU(params, params->sw_mtu);
1131 sq->stats = &c->priv->channel_stats[c->ix].sq[tc]; 1132 sq->stats = &c->priv->channel_stats[c->ix].sq[tc];
1132 sq->stop_room = MLX5E_SQ_STOP_ROOM; 1133 sq->stop_room = MLX5E_SQ_STOP_ROOM;
1133 INIT_WORK(&sq->recover_work, mlx5e_tx_err_cqe_work); 1134 INIT_WORK(&sq->recover_work, mlx5e_tx_err_cqe_work);
@@ -1135,10 +1136,14 @@ static int mlx5e_alloc_txqsq(struct mlx5e_channel *c,
1135 set_bit(MLX5E_SQ_STATE_VLAN_NEED_L2_INLINE, &sq->state); 1136 set_bit(MLX5E_SQ_STATE_VLAN_NEED_L2_INLINE, &sq->state);
1136 if (MLX5_IPSEC_DEV(c->priv->mdev)) 1137 if (MLX5_IPSEC_DEV(c->priv->mdev))
1137 set_bit(MLX5E_SQ_STATE_IPSEC, &sq->state); 1138 set_bit(MLX5E_SQ_STATE_IPSEC, &sq->state);
1139#ifdef CONFIG_MLX5_EN_TLS
1138 if (mlx5_accel_is_tls_device(c->priv->mdev)) { 1140 if (mlx5_accel_is_tls_device(c->priv->mdev)) {
1139 set_bit(MLX5E_SQ_STATE_TLS, &sq->state); 1141 set_bit(MLX5E_SQ_STATE_TLS, &sq->state);
1140 sq->stop_room += MLX5E_SQ_TLS_ROOM; 1142 sq->stop_room += MLX5E_SQ_TLS_ROOM +
1143 mlx5e_ktls_dumps_num_wqebbs(sq, MAX_SKB_FRAGS,
1144 TLS_MAX_PAYLOAD_SIZE);
1141 } 1145 }
1146#endif
1142 1147
1143 param->wq.db_numa_node = cpu_to_node(c->cpu); 1148 param->wq.db_numa_node = cpu_to_node(c->cpu);
1144 err = mlx5_wq_cyc_create(mdev, &param->wq, sqc_wq, wq, &sq->wq_ctrl); 1149 err = mlx5_wq_cyc_create(mdev, &param->wq, sqc_wq, wq, &sq->wq_ctrl);
@@ -1349,9 +1354,13 @@ static void mlx5e_deactivate_txqsq(struct mlx5e_txqsq *sq)
1349 /* last doorbell out, godspeed .. */ 1354 /* last doorbell out, godspeed .. */
1350 if (mlx5e_wqc_has_room_for(wq, sq->cc, sq->pc, 1)) { 1355 if (mlx5e_wqc_has_room_for(wq, sq->cc, sq->pc, 1)) {
1351 u16 pi = mlx5_wq_cyc_ctr2ix(wq, sq->pc); 1356 u16 pi = mlx5_wq_cyc_ctr2ix(wq, sq->pc);
1357 struct mlx5e_tx_wqe_info *wi;
1352 struct mlx5e_tx_wqe *nop; 1358 struct mlx5e_tx_wqe *nop;
1353 1359
1354 sq->db.wqe_info[pi].skb = NULL; 1360 wi = &sq->db.wqe_info[pi];
1361
1362 memset(wi, 0, sizeof(*wi));
1363 wi->num_wqebbs = 1;
1355 nop = mlx5e_post_nop(wq, sq->sqn, &sq->pc); 1364 nop = mlx5e_post_nop(wq, sq->sqn, &sq->pc);
1356 mlx5e_notify_hw(wq, sq->pc, sq->uar_map, &nop->ctrl); 1365 mlx5e_notify_hw(wq, sq->pc, sq->uar_map, &nop->ctrl);
1357 } 1366 }
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
index 95892a3b63a1..cd9bb7c7b341 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
@@ -611,8 +611,8 @@ static void mlx5e_rep_update_flows(struct mlx5e_priv *priv,
611 611
612 mutex_lock(&esw->offloads.encap_tbl_lock); 612 mutex_lock(&esw->offloads.encap_tbl_lock);
613 encap_connected = !!(e->flags & MLX5_ENCAP_ENTRY_VALID); 613 encap_connected = !!(e->flags & MLX5_ENCAP_ENTRY_VALID);
614 if (e->compl_result || (encap_connected == neigh_connected && 614 if (e->compl_result < 0 || (encap_connected == neigh_connected &&
615 ether_addr_equal(e->h_dest, ha))) 615 ether_addr_equal(e->h_dest, ha)))
616 goto unlock; 616 goto unlock;
617 617
618 mlx5e_take_all_encap_flows(e, &flow_list); 618 mlx5e_take_all_encap_flows(e, &flow_list);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
index d6a547238de0..82cffb3a9964 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
@@ -1386,8 +1386,11 @@ int mlx5e_poll_rx_cq(struct mlx5e_cq *cq, int budget)
1386 if (unlikely(!test_bit(MLX5E_RQ_STATE_ENABLED, &rq->state))) 1386 if (unlikely(!test_bit(MLX5E_RQ_STATE_ENABLED, &rq->state)))
1387 return 0; 1387 return 0;
1388 1388
1389 if (rq->cqd.left) 1389 if (rq->cqd.left) {
1390 work_done += mlx5e_decompress_cqes_cont(rq, cqwq, 0, budget); 1390 work_done += mlx5e_decompress_cqes_cont(rq, cqwq, 0, budget);
1391 if (rq->cqd.left || work_done >= budget)
1392 goto out;
1393 }
1391 1394
1392 cqe = mlx5_cqwq_get_cqe(cqwq); 1395 cqe = mlx5_cqwq_get_cqe(cqwq);
1393 if (!cqe) { 1396 if (!cqe) {
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c b/drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c
index 840ec945ccba..bbff8d8ded76 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c
@@ -35,6 +35,7 @@
35#include <linux/udp.h> 35#include <linux/udp.h>
36#include <net/udp.h> 36#include <net/udp.h>
37#include "en.h" 37#include "en.h"
38#include "en/port.h"
38 39
39enum { 40enum {
40 MLX5E_ST_LINK_STATE, 41 MLX5E_ST_LINK_STATE,
@@ -80,22 +81,12 @@ static int mlx5e_test_link_state(struct mlx5e_priv *priv)
80 81
81static int mlx5e_test_link_speed(struct mlx5e_priv *priv) 82static int mlx5e_test_link_speed(struct mlx5e_priv *priv)
82{ 83{
83 u32 out[MLX5_ST_SZ_DW(ptys_reg)]; 84 u32 speed;
84 u32 eth_proto_oper;
85 int i;
86 85
87 if (!netif_carrier_ok(priv->netdev)) 86 if (!netif_carrier_ok(priv->netdev))
88 return 1; 87 return 1;
89 88
90 if (mlx5_query_port_ptys(priv->mdev, out, sizeof(out), MLX5_PTYS_EN, 1)) 89 return mlx5e_port_linkspeed(priv->mdev, &speed);
91 return 1;
92
93 eth_proto_oper = MLX5_GET(ptys_reg, out, eth_proto_oper);
94 for (i = 0; i < MLX5E_LINK_MODES_NUMBER; i++) {
95 if (eth_proto_oper & MLX5E_PROT_MASK(i))
96 return 0;
97 }
98 return 1;
99} 90}
100 91
101struct mlx5ehdr { 92struct mlx5ehdr {
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_stats.c b/drivers/net/ethernet/mellanox/mlx5/core/en_stats.c
index ac6fdcda7019..7e6ebd0505cc 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_stats.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_stats.c
@@ -52,11 +52,12 @@ static const struct counter_desc sw_stats_desc[] = {
52 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_encrypted_bytes) }, 52 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_encrypted_bytes) },
53 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_ctx) }, 53 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_ctx) },
54 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_ooo) }, 54 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_ooo) },
55 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_dump_packets) },
56 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_dump_bytes) },
55 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_resync_bytes) }, 57 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_resync_bytes) },
58 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_skip_no_sync_data) },
56 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_drop_no_sync_data) }, 59 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_drop_no_sync_data) },
57 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_drop_bypass_req) }, 60 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_drop_bypass_req) },
58 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_dump_packets) },
59 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_dump_bytes) },
60#endif 61#endif
61 62
62 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_lro_packets) }, 63 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_lro_packets) },
@@ -288,11 +289,12 @@ static void mlx5e_grp_sw_update_stats(struct mlx5e_priv *priv)
288 s->tx_tls_encrypted_bytes += sq_stats->tls_encrypted_bytes; 289 s->tx_tls_encrypted_bytes += sq_stats->tls_encrypted_bytes;
289 s->tx_tls_ctx += sq_stats->tls_ctx; 290 s->tx_tls_ctx += sq_stats->tls_ctx;
290 s->tx_tls_ooo += sq_stats->tls_ooo; 291 s->tx_tls_ooo += sq_stats->tls_ooo;
292 s->tx_tls_dump_bytes += sq_stats->tls_dump_bytes;
293 s->tx_tls_dump_packets += sq_stats->tls_dump_packets;
291 s->tx_tls_resync_bytes += sq_stats->tls_resync_bytes; 294 s->tx_tls_resync_bytes += sq_stats->tls_resync_bytes;
295 s->tx_tls_skip_no_sync_data += sq_stats->tls_skip_no_sync_data;
292 s->tx_tls_drop_no_sync_data += sq_stats->tls_drop_no_sync_data; 296 s->tx_tls_drop_no_sync_data += sq_stats->tls_drop_no_sync_data;
293 s->tx_tls_drop_bypass_req += sq_stats->tls_drop_bypass_req; 297 s->tx_tls_drop_bypass_req += sq_stats->tls_drop_bypass_req;
294 s->tx_tls_dump_bytes += sq_stats->tls_dump_bytes;
295 s->tx_tls_dump_packets += sq_stats->tls_dump_packets;
296#endif 298#endif
297 s->tx_cqes += sq_stats->cqes; 299 s->tx_cqes += sq_stats->cqes;
298 } 300 }
@@ -1472,10 +1474,12 @@ static const struct counter_desc sq_stats_desc[] = {
1472 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_encrypted_bytes) }, 1474 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_encrypted_bytes) },
1473 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_ctx) }, 1475 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_ctx) },
1474 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_ooo) }, 1476 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_ooo) },
1475 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_drop_no_sync_data) },
1476 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_drop_bypass_req) },
1477 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_dump_packets) }, 1477 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_dump_packets) },
1478 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_dump_bytes) }, 1478 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_dump_bytes) },
1479 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_resync_bytes) },
1480 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_skip_no_sync_data) },
1481 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_drop_no_sync_data) },
1482 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_drop_bypass_req) },
1479#endif 1483#endif
1480 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, csum_none) }, 1484 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, csum_none) },
1481 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, stopped) }, 1485 { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, stopped) },
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_stats.h b/drivers/net/ethernet/mellanox/mlx5/core/en_stats.h
index 79f261bf86ac..869f3502f631 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_stats.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_stats.h
@@ -129,11 +129,12 @@ struct mlx5e_sw_stats {
129 u64 tx_tls_encrypted_bytes; 129 u64 tx_tls_encrypted_bytes;
130 u64 tx_tls_ctx; 130 u64 tx_tls_ctx;
131 u64 tx_tls_ooo; 131 u64 tx_tls_ooo;
132 u64 tx_tls_dump_packets;
133 u64 tx_tls_dump_bytes;
132 u64 tx_tls_resync_bytes; 134 u64 tx_tls_resync_bytes;
135 u64 tx_tls_skip_no_sync_data;
133 u64 tx_tls_drop_no_sync_data; 136 u64 tx_tls_drop_no_sync_data;
134 u64 tx_tls_drop_bypass_req; 137 u64 tx_tls_drop_bypass_req;
135 u64 tx_tls_dump_packets;
136 u64 tx_tls_dump_bytes;
137#endif 138#endif
138 139
139 u64 rx_xsk_packets; 140 u64 rx_xsk_packets;
@@ -273,11 +274,12 @@ struct mlx5e_sq_stats {
273 u64 tls_encrypted_bytes; 274 u64 tls_encrypted_bytes;
274 u64 tls_ctx; 275 u64 tls_ctx;
275 u64 tls_ooo; 276 u64 tls_ooo;
277 u64 tls_dump_packets;
278 u64 tls_dump_bytes;
276 u64 tls_resync_bytes; 279 u64 tls_resync_bytes;
280 u64 tls_skip_no_sync_data;
277 u64 tls_drop_no_sync_data; 281 u64 tls_drop_no_sync_data;
278 u64 tls_drop_bypass_req; 282 u64 tls_drop_bypass_req;
279 u64 tls_dump_packets;
280 u64 tls_dump_bytes;
281#endif 283#endif
282 /* less likely accessed in data path */ 284 /* less likely accessed in data path */
283 u64 csum_none; 285 u64 csum_none;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index 3e78a727f3e6..fda0b37075e8 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -1278,8 +1278,10 @@ static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv,
1278 mlx5_eswitch_del_vlan_action(esw, attr); 1278 mlx5_eswitch_del_vlan_action(esw, attr);
1279 1279
1280 for (out_index = 0; out_index < MLX5_MAX_FLOW_FWD_VPORTS; out_index++) 1280 for (out_index = 0; out_index < MLX5_MAX_FLOW_FWD_VPORTS; out_index++)
1281 if (attr->dests[out_index].flags & MLX5_ESW_DEST_ENCAP) 1281 if (attr->dests[out_index].flags & MLX5_ESW_DEST_ENCAP) {
1282 mlx5e_detach_encap(priv, flow, out_index); 1282 mlx5e_detach_encap(priv, flow, out_index);
1283 kfree(attr->parse_attr->tun_info[out_index]);
1284 }
1283 kvfree(attr->parse_attr); 1285 kvfree(attr->parse_attr);
1284 1286
1285 if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR) 1287 if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)
@@ -1559,6 +1561,7 @@ static void mlx5e_encap_dealloc(struct mlx5e_priv *priv, struct mlx5e_encap_entr
1559 mlx5_packet_reformat_dealloc(priv->mdev, e->pkt_reformat); 1561 mlx5_packet_reformat_dealloc(priv->mdev, e->pkt_reformat);
1560 } 1562 }
1561 1563
1564 kfree(e->tun_info);
1562 kfree(e->encap_header); 1565 kfree(e->encap_header);
1563 kfree_rcu(e, rcu); 1566 kfree_rcu(e, rcu);
1564} 1567}
@@ -2972,6 +2975,13 @@ mlx5e_encap_get(struct mlx5e_priv *priv, struct encap_key *key,
2972 return NULL; 2975 return NULL;
2973} 2976}
2974 2977
2978static struct ip_tunnel_info *dup_tun_info(const struct ip_tunnel_info *tun_info)
2979{
2980 size_t tun_size = sizeof(*tun_info) + tun_info->options_len;
2981
2982 return kmemdup(tun_info, tun_size, GFP_KERNEL);
2983}
2984
2975static int mlx5e_attach_encap(struct mlx5e_priv *priv, 2985static int mlx5e_attach_encap(struct mlx5e_priv *priv,
2976 struct mlx5e_tc_flow *flow, 2986 struct mlx5e_tc_flow *flow,
2977 struct net_device *mirred_dev, 2987 struct net_device *mirred_dev,
@@ -3028,13 +3038,15 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
3028 refcount_set(&e->refcnt, 1); 3038 refcount_set(&e->refcnt, 1);
3029 init_completion(&e->res_ready); 3039 init_completion(&e->res_ready);
3030 3040
3041 tun_info = dup_tun_info(tun_info);
3042 if (!tun_info) {
3043 err = -ENOMEM;
3044 goto out_err_init;
3045 }
3031 e->tun_info = tun_info; 3046 e->tun_info = tun_info;
3032 err = mlx5e_tc_tun_init_encap_attr(mirred_dev, priv, e, extack); 3047 err = mlx5e_tc_tun_init_encap_attr(mirred_dev, priv, e, extack);
3033 if (err) { 3048 if (err)
3034 kfree(e); 3049 goto out_err_init;
3035 e = NULL;
3036 goto out_err;
3037 }
3038 3050
3039 INIT_LIST_HEAD(&e->flows); 3051 INIT_LIST_HEAD(&e->flows);
3040 hash_add_rcu(esw->offloads.encap_tbl, &e->encap_hlist, hash_key); 3052 hash_add_rcu(esw->offloads.encap_tbl, &e->encap_hlist, hash_key);
@@ -3075,6 +3087,12 @@ out_err:
3075 if (e) 3087 if (e)
3076 mlx5e_encap_put(priv, e); 3088 mlx5e_encap_put(priv, e);
3077 return err; 3089 return err;
3090
3091out_err_init:
3092 mutex_unlock(&esw->offloads.encap_tbl_lock);
3093 kfree(tun_info);
3094 kfree(e);
3095 return err;
3078} 3096}
3079 3097
3080static int parse_tc_vlan_action(struct mlx5e_priv *priv, 3098static int parse_tc_vlan_action(struct mlx5e_priv *priv,
@@ -3160,7 +3178,7 @@ static int add_vlan_pop_action(struct mlx5e_priv *priv,
3160 struct mlx5_esw_flow_attr *attr, 3178 struct mlx5_esw_flow_attr *attr,
3161 u32 *action) 3179 u32 *action)
3162{ 3180{
3163 int nest_level = vlan_get_encap_level(attr->parse_attr->filter_dev); 3181 int nest_level = attr->parse_attr->filter_dev->lower_level;
3164 struct flow_action_entry vlan_act = { 3182 struct flow_action_entry vlan_act = {
3165 .id = FLOW_ACTION_VLAN_POP, 3183 .id = FLOW_ACTION_VLAN_POP,
3166 }; 3184 };
@@ -3295,7 +3313,9 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,
3295 } else if (encap) { 3313 } else if (encap) {
3296 parse_attr->mirred_ifindex[attr->out_count] = 3314 parse_attr->mirred_ifindex[attr->out_count] =
3297 out_dev->ifindex; 3315 out_dev->ifindex;
3298 parse_attr->tun_info[attr->out_count] = info; 3316 parse_attr->tun_info[attr->out_count] = dup_tun_info(info);
3317 if (!parse_attr->tun_info[attr->out_count])
3318 return -ENOMEM;
3299 encap = false; 3319 encap = false;
3300 attr->dests[attr->out_count].flags |= 3320 attr->dests[attr->out_count].flags |=
3301 MLX5_ESW_DEST_ENCAP; 3321 MLX5_ESW_DEST_ENCAP;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c
index d3a67a9b4eba..67dc4f0921b6 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c
@@ -403,7 +403,10 @@ netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev)
403static void mlx5e_dump_error_cqe(struct mlx5e_txqsq *sq, 403static void mlx5e_dump_error_cqe(struct mlx5e_txqsq *sq,
404 struct mlx5_err_cqe *err_cqe) 404 struct mlx5_err_cqe *err_cqe)
405{ 405{
406 u32 ci = mlx5_cqwq_get_ci(&sq->cq.wq); 406 struct mlx5_cqwq *wq = &sq->cq.wq;
407 u32 ci;
408
409 ci = mlx5_cqwq_ctr2ix(wq, wq->cc - 1);
407 410
408 netdev_err(sq->channel->netdev, 411 netdev_err(sq->channel->netdev,
409 "Error cqe on cqn 0x%x, ci 0x%x, sqn 0x%x, opcode 0x%x, syndrome 0x%x, vendor syndrome 0x%x\n", 412 "Error cqe on cqn 0x%x, ci 0x%x, sqn 0x%x, opcode 0x%x, syndrome 0x%x, vendor syndrome 0x%x\n",
@@ -479,14 +482,7 @@ bool mlx5e_poll_tx_cq(struct mlx5e_cq *cq, int napi_budget)
479 skb = wi->skb; 482 skb = wi->skb;
480 483
481 if (unlikely(!skb)) { 484 if (unlikely(!skb)) {
482#ifdef CONFIG_MLX5_EN_TLS 485 mlx5e_ktls_tx_handle_resync_dump_comp(sq, wi, &dma_fifo_cc);
483 if (wi->resync_dump_frag) {
484 struct mlx5e_sq_dma *dma =
485 mlx5e_dma_get(sq, dma_fifo_cc++);
486
487 mlx5e_ktls_tx_handle_resync_dump_comp(sq, wi, dma);
488 }
489#endif
490 sqcc += wi->num_wqebbs; 486 sqcc += wi->num_wqebbs;
491 continue; 487 continue;
492 } 488 }
@@ -542,29 +538,38 @@ void mlx5e_free_txqsq_descs(struct mlx5e_txqsq *sq)
542{ 538{
543 struct mlx5e_tx_wqe_info *wi; 539 struct mlx5e_tx_wqe_info *wi;
544 struct sk_buff *skb; 540 struct sk_buff *skb;
541 u32 dma_fifo_cc;
542 u16 sqcc;
545 u16 ci; 543 u16 ci;
546 int i; 544 int i;
547 545
548 while (sq->cc != sq->pc) { 546 sqcc = sq->cc;
549 ci = mlx5_wq_cyc_ctr2ix(&sq->wq, sq->cc); 547 dma_fifo_cc = sq->dma_fifo_cc;
548
549 while (sqcc != sq->pc) {
550 ci = mlx5_wq_cyc_ctr2ix(&sq->wq, sqcc);
550 wi = &sq->db.wqe_info[ci]; 551 wi = &sq->db.wqe_info[ci];
551 skb = wi->skb; 552 skb = wi->skb;
552 553
553 if (!skb) { /* nop */ 554 if (!skb) {
554 sq->cc++; 555 mlx5e_ktls_tx_handle_resync_dump_comp(sq, wi, &dma_fifo_cc);
556 sqcc += wi->num_wqebbs;
555 continue; 557 continue;
556 } 558 }
557 559
558 for (i = 0; i < wi->num_dma; i++) { 560 for (i = 0; i < wi->num_dma; i++) {
559 struct mlx5e_sq_dma *dma = 561 struct mlx5e_sq_dma *dma =
560 mlx5e_dma_get(sq, sq->dma_fifo_cc++); 562 mlx5e_dma_get(sq, dma_fifo_cc++);
561 563
562 mlx5e_tx_dma_unmap(sq->pdev, dma); 564 mlx5e_tx_dma_unmap(sq->pdev, dma);
563 } 565 }
564 566
565 dev_kfree_skb_any(skb); 567 dev_kfree_skb_any(skb);
566 sq->cc += wi->num_wqebbs; 568 sqcc += wi->num_wqebbs;
567 } 569 }
570
571 sq->dma_fifo_cc = dma_fifo_cc;
572 sq->cc = sqcc;
568} 573}
569 574
570#ifdef CONFIG_MLX5_CORE_IPOIB 575#ifdef CONFIG_MLX5_CORE_IPOIB
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
index 00d71db15f22..369499e88fe8 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
@@ -285,7 +285,6 @@ mlx5_eswitch_add_fwd_rule(struct mlx5_eswitch *esw,
285 285
286 mlx5_eswitch_set_rule_source_port(esw, spec, attr); 286 mlx5_eswitch_set_rule_source_port(esw, spec, attr);
287 287
288 spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS;
289 if (attr->outer_match_level != MLX5_MATCH_NONE) 288 if (attr->outer_match_level != MLX5_MATCH_NONE)
290 spec->match_criteria_enable |= MLX5_MATCH_OUTER_HEADERS; 289 spec->match_criteria_enable |= MLX5_MATCH_OUTER_HEADERS;
291 290
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c
index 1d55a324a17e..7879e1746297 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c
@@ -177,22 +177,32 @@ mlx5_eswitch_termtbl_actions_move(struct mlx5_flow_act *src,
177 memset(&src->vlan[1], 0, sizeof(src->vlan[1])); 177 memset(&src->vlan[1], 0, sizeof(src->vlan[1]));
178} 178}
179 179
180static bool mlx5_eswitch_offload_is_uplink_port(const struct mlx5_eswitch *esw,
181 const struct mlx5_flow_spec *spec)
182{
183 u32 port_mask, port_value;
184
185 if (MLX5_CAP_ESW_FLOWTABLE(esw->dev, flow_source))
186 return spec->flow_context.flow_source == MLX5_VPORT_UPLINK;
187
188 port_mask = MLX5_GET(fte_match_param, spec->match_criteria,
189 misc_parameters.source_port);
190 port_value = MLX5_GET(fte_match_param, spec->match_value,
191 misc_parameters.source_port);
192 return (port_mask & port_value & 0xffff) == MLX5_VPORT_UPLINK;
193}
194
180bool 195bool
181mlx5_eswitch_termtbl_required(struct mlx5_eswitch *esw, 196mlx5_eswitch_termtbl_required(struct mlx5_eswitch *esw,
182 struct mlx5_flow_act *flow_act, 197 struct mlx5_flow_act *flow_act,
183 struct mlx5_flow_spec *spec) 198 struct mlx5_flow_spec *spec)
184{ 199{
185 u32 port_mask = MLX5_GET(fte_match_param, spec->match_criteria,
186 misc_parameters.source_port);
187 u32 port_value = MLX5_GET(fte_match_param, spec->match_value,
188 misc_parameters.source_port);
189
190 if (!MLX5_CAP_ESW_FLOWTABLE_FDB(esw->dev, termination_table)) 200 if (!MLX5_CAP_ESW_FLOWTABLE_FDB(esw->dev, termination_table))
191 return false; 201 return false;
192 202
193 /* push vlan on RX */ 203 /* push vlan on RX */
194 return (flow_act->action & MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH) && 204 return (flow_act->action & MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH) &&
195 ((port_mask & port_value) == MLX5_VPORT_UPLINK); 205 mlx5_eswitch_offload_is_uplink_port(esw, spec);
196} 206}
197 207
198struct mlx5_flow_handle * 208struct mlx5_flow_handle *
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fpga/conn.c b/drivers/net/ethernet/mellanox/mlx5/core/fpga/conn.c
index 4c50efe4e7f1..61021133029e 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fpga/conn.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fpga/conn.c
@@ -464,8 +464,10 @@ static int mlx5_fpga_conn_create_cq(struct mlx5_fpga_conn *conn, int cq_size)
464 } 464 }
465 465
466 err = mlx5_vector2eqn(mdev, smp_processor_id(), &eqn, &irqn); 466 err = mlx5_vector2eqn(mdev, smp_processor_id(), &eqn, &irqn);
467 if (err) 467 if (err) {
468 kvfree(in);
468 goto err_cqwq; 469 goto err_cqwq;
470 }
469 471
470 cqc = MLX5_ADDR_OF(create_cq_in, in, cq_context); 472 cqc = MLX5_ADDR_OF(create_cq_in, in, cq_context);
471 MLX5_SET(cqc, cqc, log_cq_size, ilog2(cq_size)); 473 MLX5_SET(cqc, cqc, log_cq_size, ilog2(cq_size));
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c
index 579c306caa7b..3c816e81f8d9 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c
@@ -507,7 +507,8 @@ static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
507 MLX5_SET(dest_format_struct, in_dests, 507 MLX5_SET(dest_format_struct, in_dests,
508 destination_eswitch_owner_vhca_id, 508 destination_eswitch_owner_vhca_id,
509 dst->dest_attr.vport.vhca_id); 509 dst->dest_attr.vport.vhca_id);
510 if (extended_dest) { 510 if (extended_dest &&
511 dst->dest_attr.vport.pkt_reformat) {
511 MLX5_SET(dest_format_struct, in_dests, 512 MLX5_SET(dest_format_struct, in_dests,
512 packet_reformat, 513 packet_reformat,
513 !!(dst->dest_attr.vport.flags & 514 !!(dst->dest_attr.vport.flags &
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/health.c b/drivers/net/ethernet/mellanox/mlx5/core/health.c
index d685122d9ff7..c07f3154437c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/health.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/health.c
@@ -572,7 +572,7 @@ mlx5_fw_fatal_reporter_dump(struct devlink_health_reporter *reporter,
572 return -ENOMEM; 572 return -ENOMEM;
573 err = mlx5_crdump_collect(dev, cr_data); 573 err = mlx5_crdump_collect(dev, cr_data);
574 if (err) 574 if (err)
575 return err; 575 goto free_data;
576 576
577 if (priv_ctx) { 577 if (priv_ctx) {
578 struct mlx5_fw_reporter_ctx *fw_reporter_ctx = priv_ctx; 578 struct mlx5_fw_reporter_ctx *fw_reporter_ctx = priv_ctx;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/mr.c b/drivers/net/ethernet/mellanox/mlx5/core/mr.c
index 9231b39d18b2..c501bf2a0252 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/mr.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/mr.c
@@ -112,17 +112,11 @@ int mlx5_core_destroy_mkey(struct mlx5_core_dev *dev,
112 u32 out[MLX5_ST_SZ_DW(destroy_mkey_out)] = {0}; 112 u32 out[MLX5_ST_SZ_DW(destroy_mkey_out)] = {0};
113 u32 in[MLX5_ST_SZ_DW(destroy_mkey_in)] = {0}; 113 u32 in[MLX5_ST_SZ_DW(destroy_mkey_in)] = {0};
114 struct xarray *mkeys = &dev->priv.mkey_table; 114 struct xarray *mkeys = &dev->priv.mkey_table;
115 struct mlx5_core_mkey *deleted_mkey;
116 unsigned long flags; 115 unsigned long flags;
117 116
118 xa_lock_irqsave(mkeys, flags); 117 xa_lock_irqsave(mkeys, flags);
119 deleted_mkey = __xa_erase(mkeys, mlx5_base_mkey(mkey->key)); 118 __xa_erase(mkeys, mlx5_base_mkey(mkey->key));
120 xa_unlock_irqrestore(mkeys, flags); 119 xa_unlock_irqrestore(mkeys, flags);
121 if (!deleted_mkey) {
122 mlx5_core_dbg(dev, "failed xarray delete of mkey 0x%x\n",
123 mlx5_base_mkey(mkey->key));
124 return -ENOENT;
125 }
126 120
127 MLX5_SET(destroy_mkey_in, in, opcode, MLX5_CMD_OP_DESTROY_MKEY); 121 MLX5_SET(destroy_mkey_in, in, opcode, MLX5_CMD_OP_DESTROY_MKEY);
128 MLX5_SET(destroy_mkey_in, in, mkey_index, mlx5_mkey_to_idx(mkey->key)); 122 MLX5_SET(destroy_mkey_in, in, mkey_index, mlx5_mkey_to_idx(mkey->key));
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c
index 913f1e5aaaf2..d7c7467e2d53 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c
@@ -137,7 +137,8 @@ dr_icm_pool_mr_create(struct mlx5dr_icm_pool *pool,
137 137
138 icm_mr->icm_start_addr = icm_mr->dm.addr; 138 icm_mr->icm_start_addr = icm_mr->dm.addr;
139 139
140 align_diff = icm_mr->icm_start_addr % align_base; 140 /* align_base is always a power of 2 */
141 align_diff = icm_mr->icm_start_addr & (align_base - 1);
141 if (align_diff) 142 if (align_diff)
142 icm_mr->used_length = align_base - align_diff; 143 icm_mr->used_length = align_base - align_diff;
143 144
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c
index 4187f2b112b8..e8b656075c6f 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c
@@ -788,12 +788,10 @@ again:
788 * it means that all the previous stes are the same, 788 * it means that all the previous stes are the same,
789 * if so, this rule is duplicated. 789 * if so, this rule is duplicated.
790 */ 790 */
791 if (mlx5dr_ste_is_last_in_rule(nic_matcher, 791 if (!mlx5dr_ste_is_last_in_rule(nic_matcher, ste_location))
792 matched_ste->ste_chain_location)) { 792 return matched_ste;
793 mlx5dr_info(dmn, "Duplicate rule inserted, aborting!!\n"); 793
794 return NULL; 794 mlx5dr_dbg(dmn, "Duplicate rule inserted\n");
795 }
796 return matched_ste;
797 } 795 }
798 796
799 if (!skip_rehash && dr_rule_need_enlarge_hash(cur_htbl, dmn, nic_dmn)) { 797 if (!skip_rehash && dr_rule_need_enlarge_hash(cur_htbl, dmn, nic_dmn)) {
diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c
index 14dcc786926d..4421ab22182f 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core.c
@@ -1186,7 +1186,7 @@ __mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
1186 if (err) 1186 if (err)
1187 goto err_thermal_init; 1187 goto err_thermal_init;
1188 1188
1189 if (mlxsw_driver->params_register && !reload) 1189 if (mlxsw_driver->params_register)
1190 devlink_params_publish(devlink); 1190 devlink_params_publish(devlink);
1191 1191
1192 return 0; 1192 return 0;
@@ -1259,7 +1259,7 @@ void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core,
1259 return; 1259 return;
1260 } 1260 }
1261 1261
1262 if (mlxsw_core->driver->params_unregister && !reload) 1262 if (mlxsw_core->driver->params_unregister)
1263 devlink_params_unpublish(devlink); 1263 devlink_params_unpublish(devlink);
1264 mlxsw_thermal_fini(mlxsw_core->thermal); 1264 mlxsw_thermal_fini(mlxsw_core->thermal);
1265 mlxsw_hwmon_fini(mlxsw_core->hwmon); 1265 mlxsw_hwmon_fini(mlxsw_core->hwmon);
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
index 899450b28621..7c03b661ae7e 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
@@ -99,6 +99,7 @@ static void mlxsw_sp_rx_drop_listener(struct sk_buff *skb, u8 local_port,
99 devlink = priv_to_devlink(mlxsw_sp->core); 99 devlink = priv_to_devlink(mlxsw_sp->core);
100 in_devlink_port = mlxsw_core_port_devlink_port_get(mlxsw_sp->core, 100 in_devlink_port = mlxsw_core_port_devlink_port_get(mlxsw_sp->core,
101 local_port); 101 local_port);
102 skb_push(skb, ETH_HLEN);
102 devlink_trap_report(devlink, skb, trap_ctx, in_devlink_port); 103 devlink_trap_report(devlink, skb, trap_ctx, in_devlink_port);
103 consume_skb(skb); 104 consume_skb(skb);
104} 105}
diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c
index 4d1bce4389c7..344539c0d3aa 100644
--- a/drivers/net/ethernet/mscc/ocelot.c
+++ b/drivers/net/ethernet/mscc/ocelot.c
@@ -261,8 +261,15 @@ static int ocelot_vlan_vid_add(struct net_device *dev, u16 vid, bool pvid,
261 port->pvid = vid; 261 port->pvid = vid;
262 262
263 /* Untagged egress vlan clasification */ 263 /* Untagged egress vlan clasification */
264 if (untagged) 264 if (untagged && port->vid != vid) {
265 if (port->vid) {
266 dev_err(ocelot->dev,
267 "Port already has a native VLAN: %d\n",
268 port->vid);
269 return -EBUSY;
270 }
265 port->vid = vid; 271 port->vid = vid;
272 }
266 273
267 ocelot_vlan_port_apply(ocelot, port); 274 ocelot_vlan_port_apply(ocelot, port);
268 275
@@ -934,7 +941,7 @@ end:
934static int ocelot_vlan_rx_add_vid(struct net_device *dev, __be16 proto, 941static int ocelot_vlan_rx_add_vid(struct net_device *dev, __be16 proto,
935 u16 vid) 942 u16 vid)
936{ 943{
937 return ocelot_vlan_vid_add(dev, vid, false, true); 944 return ocelot_vlan_vid_add(dev, vid, false, false);
938} 945}
939 946
940static int ocelot_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, 947static int ocelot_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
diff --git a/drivers/net/ethernet/mscc/ocelot_board.c b/drivers/net/ethernet/mscc/ocelot_board.c
index b063eb78fa0c..aac115136720 100644
--- a/drivers/net/ethernet/mscc/ocelot_board.c
+++ b/drivers/net/ethernet/mscc/ocelot_board.c
@@ -388,13 +388,14 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
388 continue; 388 continue;
389 389
390 phy = of_phy_find_device(phy_node); 390 phy = of_phy_find_device(phy_node);
391 of_node_put(phy_node);
391 if (!phy) 392 if (!phy)
392 continue; 393 continue;
393 394
394 err = ocelot_probe_port(ocelot, port, regs, phy); 395 err = ocelot_probe_port(ocelot, port, regs, phy);
395 if (err) { 396 if (err) {
396 of_node_put(portnp); 397 of_node_put(portnp);
397 return err; 398 goto out_put_ports;
398 } 399 }
399 400
400 phy_mode = of_get_phy_mode(portnp); 401 phy_mode = of_get_phy_mode(portnp);
@@ -422,7 +423,8 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
422 "invalid phy mode for port%d, (Q)SGMII only\n", 423 "invalid phy mode for port%d, (Q)SGMII only\n",
423 port); 424 port);
424 of_node_put(portnp); 425 of_node_put(portnp);
425 return -EINVAL; 426 err = -EINVAL;
427 goto out_put_ports;
426 } 428 }
427 429
428 serdes = devm_of_phy_get(ocelot->dev, portnp, NULL); 430 serdes = devm_of_phy_get(ocelot->dev, portnp, NULL);
@@ -435,7 +437,8 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
435 "missing SerDes phys for port%d\n", 437 "missing SerDes phys for port%d\n",
436 port); 438 port);
437 439
438 goto err_probe_ports; 440 of_node_put(portnp);
441 goto out_put_ports;
439 } 442 }
440 443
441 ocelot->ports[port]->serdes = serdes; 444 ocelot->ports[port]->serdes = serdes;
@@ -447,9 +450,8 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
447 450
448 dev_info(&pdev->dev, "Ocelot switch probed\n"); 451 dev_info(&pdev->dev, "Ocelot switch probed\n");
449 452
450 return 0; 453out_put_ports:
451 454 of_node_put(ports);
452err_probe_ports:
453 return err; 455 return err;
454} 456}
455 457
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c
index 1eef446036d6..79d72c88bbef 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c
@@ -299,22 +299,6 @@ static void nfp_repr_clean(struct nfp_repr *repr)
299 nfp_port_free(repr->port); 299 nfp_port_free(repr->port);
300} 300}
301 301
302static struct lock_class_key nfp_repr_netdev_xmit_lock_key;
303static struct lock_class_key nfp_repr_netdev_addr_lock_key;
304
305static void nfp_repr_set_lockdep_class_one(struct net_device *dev,
306 struct netdev_queue *txq,
307 void *_unused)
308{
309 lockdep_set_class(&txq->_xmit_lock, &nfp_repr_netdev_xmit_lock_key);
310}
311
312static void nfp_repr_set_lockdep_class(struct net_device *dev)
313{
314 lockdep_set_class(&dev->addr_list_lock, &nfp_repr_netdev_addr_lock_key);
315 netdev_for_each_tx_queue(dev, nfp_repr_set_lockdep_class_one, NULL);
316}
317
318int nfp_repr_init(struct nfp_app *app, struct net_device *netdev, 302int nfp_repr_init(struct nfp_app *app, struct net_device *netdev,
319 u32 cmsg_port_id, struct nfp_port *port, 303 u32 cmsg_port_id, struct nfp_port *port,
320 struct net_device *pf_netdev) 304 struct net_device *pf_netdev)
@@ -324,8 +308,6 @@ int nfp_repr_init(struct nfp_app *app, struct net_device *netdev,
324 u32 repr_cap = nn->tlv_caps.repr_cap; 308 u32 repr_cap = nn->tlv_caps.repr_cap;
325 int err; 309 int err;
326 310
327 nfp_repr_set_lockdep_class(netdev);
328
329 repr->port = port; 311 repr->port = port;
330 repr->dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX, GFP_KERNEL); 312 repr->dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX, GFP_KERNEL);
331 if (!repr->dst) 313 if (!repr->dst)
diff --git a/drivers/net/ethernet/nxp/lpc_eth.c b/drivers/net/ethernet/nxp/lpc_eth.c
index 141571e2ec11..544012a67221 100644
--- a/drivers/net/ethernet/nxp/lpc_eth.c
+++ b/drivers/net/ethernet/nxp/lpc_eth.c
@@ -1356,9 +1356,6 @@ static int lpc_eth_drv_probe(struct platform_device *pdev)
1356 if (!is_valid_ether_addr(ndev->dev_addr)) 1356 if (!is_valid_ether_addr(ndev->dev_addr))
1357 eth_hw_addr_random(ndev); 1357 eth_hw_addr_random(ndev);
1358 1358
1359 /* Reset the ethernet controller */
1360 __lpc_eth_reset(pldat);
1361
1362 /* then shut everything down to save power */ 1359 /* then shut everything down to save power */
1363 __lpc_eth_shutdown(pldat); 1360 __lpc_eth_shutdown(pldat);
1364 1361
diff --git a/drivers/net/ethernet/pensando/Kconfig b/drivers/net/ethernet/pensando/Kconfig
index bd0583e409df..d25b88f53de4 100644
--- a/drivers/net/ethernet/pensando/Kconfig
+++ b/drivers/net/ethernet/pensando/Kconfig
@@ -20,6 +20,7 @@ if NET_VENDOR_PENSANDO
20config IONIC 20config IONIC
21 tristate "Pensando Ethernet IONIC Support" 21 tristate "Pensando Ethernet IONIC Support"
22 depends on 64BIT && PCI 22 depends on 64BIT && PCI
23 select NET_DEVLINK
23 help 24 help
24 This enables the support for the Pensando family of Ethernet 25 This enables the support for the Pensando family of Ethernet
25 adapters. More specific information on this driver can be 26 adapters. More specific information on this driver can be
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
index 72107a0627a9..20faa8d24c9f 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_lif.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
@@ -1,6 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 2017 - 2019 Pensando Systems, Inc */ 2/* Copyright(c) 2017 - 2019 Pensando Systems, Inc */
3 3
4#include <linux/printk.h>
5#include <linux/dynamic_debug.h>
4#include <linux/netdevice.h> 6#include <linux/netdevice.h>
5#include <linux/etherdevice.h> 7#include <linux/etherdevice.h>
6#include <linux/rtnetlink.h> 8#include <linux/rtnetlink.h>
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.h b/drivers/net/ethernet/pensando/ionic/ionic_lif.h
index 812190e729c2..6a95b42a8d8c 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_lif.h
+++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.h
@@ -182,6 +182,8 @@ struct ionic_lif {
182 182
183#define lif_to_txqcq(lif, i) ((lif)->txqcqs[i].qcq) 183#define lif_to_txqcq(lif, i) ((lif)->txqcqs[i].qcq)
184#define lif_to_rxqcq(lif, i) ((lif)->rxqcqs[i].qcq) 184#define lif_to_rxqcq(lif, i) ((lif)->rxqcqs[i].qcq)
185#define lif_to_txstats(lif, i) ((lif)->txqcqs[i].stats->tx)
186#define lif_to_rxstats(lif, i) ((lif)->rxqcqs[i].stats->rx)
185#define lif_to_txq(lif, i) (&lif_to_txqcq((lif), i)->q) 187#define lif_to_txq(lif, i) (&lif_to_txqcq((lif), i)->q)
186#define lif_to_rxq(lif, i) (&lif_to_txqcq((lif), i)->q) 188#define lif_to_rxq(lif, i) (&lif_to_txqcq((lif), i)->q)
187 189
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_main.c b/drivers/net/ethernet/pensando/ionic/ionic_main.c
index 15e432386b35..aab311413412 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_main.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_main.c
@@ -1,6 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 2017 - 2019 Pensando Systems, Inc */ 2/* Copyright(c) 2017 - 2019 Pensando Systems, Inc */
3 3
4#include <linux/printk.h>
5#include <linux/dynamic_debug.h>
4#include <linux/module.h> 6#include <linux/module.h>
5#include <linux/netdevice.h> 7#include <linux/netdevice.h>
6#include <linux/utsname.h> 8#include <linux/utsname.h>
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_stats.c b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
index e2907884f843..03916b6d47f2 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_stats.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
@@ -117,7 +117,8 @@ static u64 ionic_sw_stats_get_count(struct ionic_lif *lif)
117 /* rx stats */ 117 /* rx stats */
118 total += MAX_Q(lif) * IONIC_NUM_RX_STATS; 118 total += MAX_Q(lif) * IONIC_NUM_RX_STATS;
119 119
120 if (test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) { 120 if (test_bit(IONIC_LIF_UP, lif->state) &&
121 test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) {
121 /* tx debug stats */ 122 /* tx debug stats */
122 total += MAX_Q(lif) * (IONIC_NUM_DBG_CQ_STATS + 123 total += MAX_Q(lif) * (IONIC_NUM_DBG_CQ_STATS +
123 IONIC_NUM_TX_Q_STATS + 124 IONIC_NUM_TX_Q_STATS +
@@ -149,7 +150,8 @@ static void ionic_sw_stats_get_strings(struct ionic_lif *lif, u8 **buf)
149 *buf += ETH_GSTRING_LEN; 150 *buf += ETH_GSTRING_LEN;
150 } 151 }
151 152
152 if (test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) { 153 if (test_bit(IONIC_LIF_UP, lif->state) &&
154 test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) {
153 for (i = 0; i < IONIC_NUM_TX_Q_STATS; i++) { 155 for (i = 0; i < IONIC_NUM_TX_Q_STATS; i++) {
154 snprintf(*buf, ETH_GSTRING_LEN, 156 snprintf(*buf, ETH_GSTRING_LEN,
155 "txq_%d_%s", 157 "txq_%d_%s",
@@ -187,7 +189,8 @@ static void ionic_sw_stats_get_strings(struct ionic_lif *lif, u8 **buf)
187 *buf += ETH_GSTRING_LEN; 189 *buf += ETH_GSTRING_LEN;
188 } 190 }
189 191
190 if (test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) { 192 if (test_bit(IONIC_LIF_UP, lif->state) &&
193 test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) {
191 for (i = 0; i < IONIC_NUM_DBG_CQ_STATS; i++) { 194 for (i = 0; i < IONIC_NUM_DBG_CQ_STATS; i++) {
192 snprintf(*buf, ETH_GSTRING_LEN, 195 snprintf(*buf, ETH_GSTRING_LEN,
193 "rxq_%d_cq_%s", 196 "rxq_%d_cq_%s",
@@ -223,6 +226,8 @@ static void ionic_sw_stats_get_values(struct ionic_lif *lif, u64 **buf)
223{ 226{
224 struct ionic_lif_sw_stats lif_stats; 227 struct ionic_lif_sw_stats lif_stats;
225 struct ionic_qcq *txqcq, *rxqcq; 228 struct ionic_qcq *txqcq, *rxqcq;
229 struct ionic_tx_stats *txstats;
230 struct ionic_rx_stats *rxstats;
226 int i, q_num; 231 int i, q_num;
227 232
228 ionic_get_lif_stats(lif, &lif_stats); 233 ionic_get_lif_stats(lif, &lif_stats);
@@ -233,15 +238,17 @@ static void ionic_sw_stats_get_values(struct ionic_lif *lif, u64 **buf)
233 } 238 }
234 239
235 for (q_num = 0; q_num < MAX_Q(lif); q_num++) { 240 for (q_num = 0; q_num < MAX_Q(lif); q_num++) {
236 txqcq = lif_to_txqcq(lif, q_num); 241 txstats = &lif_to_txstats(lif, q_num);
237 242
238 for (i = 0; i < IONIC_NUM_TX_STATS; i++) { 243 for (i = 0; i < IONIC_NUM_TX_STATS; i++) {
239 **buf = IONIC_READ_STAT64(&txqcq->stats->tx, 244 **buf = IONIC_READ_STAT64(txstats,
240 &ionic_tx_stats_desc[i]); 245 &ionic_tx_stats_desc[i]);
241 (*buf)++; 246 (*buf)++;
242 } 247 }
243 248
244 if (test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) { 249 if (test_bit(IONIC_LIF_UP, lif->state) &&
250 test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) {
251 txqcq = lif_to_txqcq(lif, q_num);
245 for (i = 0; i < IONIC_NUM_TX_Q_STATS; i++) { 252 for (i = 0; i < IONIC_NUM_TX_Q_STATS; i++) {
246 **buf = IONIC_READ_STAT64(&txqcq->q, 253 **buf = IONIC_READ_STAT64(&txqcq->q,
247 &ionic_txq_stats_desc[i]); 254 &ionic_txq_stats_desc[i]);
@@ -258,22 +265,24 @@ static void ionic_sw_stats_get_values(struct ionic_lif *lif, u64 **buf)
258 (*buf)++; 265 (*buf)++;
259 } 266 }
260 for (i = 0; i < IONIC_MAX_NUM_SG_CNTR; i++) { 267 for (i = 0; i < IONIC_MAX_NUM_SG_CNTR; i++) {
261 **buf = txqcq->stats->tx.sg_cntr[i]; 268 **buf = txstats->sg_cntr[i];
262 (*buf)++; 269 (*buf)++;
263 } 270 }
264 } 271 }
265 } 272 }
266 273
267 for (q_num = 0; q_num < MAX_Q(lif); q_num++) { 274 for (q_num = 0; q_num < MAX_Q(lif); q_num++) {
268 rxqcq = lif_to_rxqcq(lif, q_num); 275 rxstats = &lif_to_rxstats(lif, q_num);
269 276
270 for (i = 0; i < IONIC_NUM_RX_STATS; i++) { 277 for (i = 0; i < IONIC_NUM_RX_STATS; i++) {
271 **buf = IONIC_READ_STAT64(&rxqcq->stats->rx, 278 **buf = IONIC_READ_STAT64(rxstats,
272 &ionic_rx_stats_desc[i]); 279 &ionic_rx_stats_desc[i]);
273 (*buf)++; 280 (*buf)++;
274 } 281 }
275 282
276 if (test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) { 283 if (test_bit(IONIC_LIF_UP, lif->state) &&
284 test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) {
285 rxqcq = lif_to_rxqcq(lif, q_num);
277 for (i = 0; i < IONIC_NUM_DBG_CQ_STATS; i++) { 286 for (i = 0; i < IONIC_NUM_DBG_CQ_STATS; i++) {
278 **buf = IONIC_READ_STAT64(&rxqcq->cq, 287 **buf = IONIC_READ_STAT64(&rxqcq->cq,
279 &ionic_dbg_cq_stats_desc[i]); 288 &ionic_dbg_cq_stats_desc[i]);
diff --git a/drivers/net/ethernet/qlogic/qed/qed_main.c b/drivers/net/ethernet/qlogic/qed/qed_main.c
index 2ce70097d018..38f7f40b3a4d 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_main.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_main.c
@@ -67,10 +67,9 @@
67#define QED_ROCE_QPS (8192) 67#define QED_ROCE_QPS (8192)
68#define QED_ROCE_DPIS (8) 68#define QED_ROCE_DPIS (8)
69#define QED_RDMA_SRQS QED_ROCE_QPS 69#define QED_RDMA_SRQS QED_ROCE_QPS
70#define QED_NVM_CFG_SET_FLAGS 0xE
71#define QED_NVM_CFG_SET_PF_FLAGS 0x1E
72#define QED_NVM_CFG_GET_FLAGS 0xA 70#define QED_NVM_CFG_GET_FLAGS 0xA
73#define QED_NVM_CFG_GET_PF_FLAGS 0x1A 71#define QED_NVM_CFG_GET_PF_FLAGS 0x1A
72#define QED_NVM_CFG_MAX_ATTRS 50
74 73
75static char version[] = 74static char version[] =
76 "QLogic FastLinQ 4xxxx Core Module qed " DRV_MODULE_VERSION "\n"; 75 "QLogic FastLinQ 4xxxx Core Module qed " DRV_MODULE_VERSION "\n";
@@ -2255,6 +2254,7 @@ static int qed_nvm_flash_cfg_write(struct qed_dev *cdev, const u8 **data)
2255{ 2254{
2256 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 2255 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2257 u8 entity_id, len, buf[32]; 2256 u8 entity_id, len, buf[32];
2257 bool need_nvm_init = true;
2258 struct qed_ptt *ptt; 2258 struct qed_ptt *ptt;
2259 u16 cfg_id, count; 2259 u16 cfg_id, count;
2260 int rc = 0, i; 2260 int rc = 0, i;
@@ -2271,8 +2271,10 @@ static int qed_nvm_flash_cfg_write(struct qed_dev *cdev, const u8 **data)
2271 2271
2272 DP_VERBOSE(cdev, NETIF_MSG_DRV, 2272 DP_VERBOSE(cdev, NETIF_MSG_DRV,
2273 "Read config ids: num_attrs = %0d\n", count); 2273 "Read config ids: num_attrs = %0d\n", count);
2274 /* NVM CFG ID attributes */ 2274 /* NVM CFG ID attributes. Start loop index from 1 to avoid additional
2275 for (i = 0; i < count; i++) { 2275 * arithmetic operations in the implementation.
2276 */
2277 for (i = 1; i <= count; i++) {
2276 cfg_id = *((u16 *)*data); 2278 cfg_id = *((u16 *)*data);
2277 *data += 2; 2279 *data += 2;
2278 entity_id = **data; 2280 entity_id = **data;
@@ -2282,8 +2284,21 @@ static int qed_nvm_flash_cfg_write(struct qed_dev *cdev, const u8 **data)
2282 memcpy(buf, *data, len); 2284 memcpy(buf, *data, len);
2283 *data += len; 2285 *data += len;
2284 2286
2285 flags = entity_id ? QED_NVM_CFG_SET_PF_FLAGS : 2287 flags = 0;
2286 QED_NVM_CFG_SET_FLAGS; 2288 if (need_nvm_init) {
2289 flags |= QED_NVM_CFG_OPTION_INIT;
2290 need_nvm_init = false;
2291 }
2292
2293 /* Commit to flash and free the resources */
2294 if (!(i % QED_NVM_CFG_MAX_ATTRS) || i == count) {
2295 flags |= QED_NVM_CFG_OPTION_COMMIT |
2296 QED_NVM_CFG_OPTION_FREE;
2297 need_nvm_init = true;
2298 }
2299
2300 if (entity_id)
2301 flags |= QED_NVM_CFG_OPTION_ENTITY_SEL;
2287 2302
2288 DP_VERBOSE(cdev, NETIF_MSG_DRV, 2303 DP_VERBOSE(cdev, NETIF_MSG_DRV,
2289 "cfg_id = %d entity = %d len = %d\n", cfg_id, 2304 "cfg_id = %d entity = %d len = %d\n", cfg_id,
diff --git a/drivers/net/ethernet/qlogic/qed/qed_sriov.c b/drivers/net/ethernet/qlogic/qed/qed_sriov.c
index 78f77b712b10..dcb5c917f373 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_sriov.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_sriov.c
@@ -2005,7 +2005,7 @@ static void qed_iov_vf_mbx_stop_vport(struct qed_hwfn *p_hwfn,
2005 (qed_iov_validate_active_txq(p_hwfn, vf))) { 2005 (qed_iov_validate_active_txq(p_hwfn, vf))) {
2006 vf->b_malicious = true; 2006 vf->b_malicious = true;
2007 DP_NOTICE(p_hwfn, 2007 DP_NOTICE(p_hwfn,
2008 "VF [%02x] - considered malicious; Unable to stop RX/TX queuess\n", 2008 "VF [%02x] - considered malicious; Unable to stop RX/TX queues\n",
2009 vf->abs_vf_id); 2009 vf->abs_vf_id);
2010 status = PFVF_STATUS_MALICIOUS; 2010 status = PFVF_STATUS_MALICIOUS;
2011 goto out; 2011 goto out;
diff --git a/drivers/net/ethernet/qlogic/qla3xxx.c b/drivers/net/ethernet/qlogic/qla3xxx.c
index 457444894d80..b4b8ba00ee01 100644
--- a/drivers/net/ethernet/qlogic/qla3xxx.c
+++ b/drivers/net/ethernet/qlogic/qla3xxx.c
@@ -2787,6 +2787,7 @@ static int ql_alloc_large_buffers(struct ql3_adapter *qdev)
2787 netdev_err(qdev->ndev, 2787 netdev_err(qdev->ndev,
2788 "PCI mapping failed with error: %d\n", 2788 "PCI mapping failed with error: %d\n",
2789 err); 2789 err);
2790 dev_kfree_skb_irq(skb);
2790 ql_free_large_buffers(qdev); 2791 ql_free_large_buffers(qdev);
2791 return -ENOMEM; 2792 return -ENOMEM;
2792 } 2793 }
diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
index 74f81fe03810..350b0d949611 100644
--- a/drivers/net/ethernet/realtek/r8169_main.c
+++ b/drivers/net/ethernet/realtek/r8169_main.c
@@ -4146,6 +4146,14 @@ static void rtl_hw_jumbo_disable(struct rtl8169_private *tp)
4146 rtl_lock_config_regs(tp); 4146 rtl_lock_config_regs(tp);
4147} 4147}
4148 4148
4149static void rtl_jumbo_config(struct rtl8169_private *tp, int mtu)
4150{
4151 if (mtu > ETH_DATA_LEN)
4152 rtl_hw_jumbo_enable(tp);
4153 else
4154 rtl_hw_jumbo_disable(tp);
4155}
4156
4149DECLARE_RTL_COND(rtl_chipcmd_cond) 4157DECLARE_RTL_COND(rtl_chipcmd_cond)
4150{ 4158{
4151 return RTL_R8(tp, ChipCmd) & CmdReset; 4159 return RTL_R8(tp, ChipCmd) & CmdReset;
@@ -4442,11 +4450,6 @@ static void rtl8168g_set_pause_thresholds(struct rtl8169_private *tp,
4442static void rtl_hw_start_8168bb(struct rtl8169_private *tp) 4450static void rtl_hw_start_8168bb(struct rtl8169_private *tp)
4443{ 4451{
4444 RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); 4452 RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en);
4445
4446 if (tp->dev->mtu <= ETH_DATA_LEN) {
4447 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B |
4448 PCI_EXP_DEVCTL_NOSNOOP_EN);
4449 }
4450} 4453}
4451 4454
4452static void rtl_hw_start_8168bef(struct rtl8169_private *tp) 4455static void rtl_hw_start_8168bef(struct rtl8169_private *tp)
@@ -4462,9 +4465,6 @@ static void __rtl_hw_start_8168cp(struct rtl8169_private *tp)
4462 4465
4463 RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); 4466 RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en);
4464 4467
4465 if (tp->dev->mtu <= ETH_DATA_LEN)
4466 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
4467
4468 rtl_disable_clock_request(tp); 4468 rtl_disable_clock_request(tp);
4469} 4469}
4470 4470
@@ -4490,9 +4490,6 @@ static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp)
4490 rtl_set_def_aspm_entry_latency(tp); 4490 rtl_set_def_aspm_entry_latency(tp);
4491 4491
4492 RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); 4492 RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en);
4493
4494 if (tp->dev->mtu <= ETH_DATA_LEN)
4495 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
4496} 4493}
4497 4494
4498static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp) 4495static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp)
@@ -4503,9 +4500,6 @@ static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp)
4503 4500
4504 /* Magic. */ 4501 /* Magic. */
4505 RTL_W8(tp, DBG_REG, 0x20); 4502 RTL_W8(tp, DBG_REG, 0x20);
4506
4507 if (tp->dev->mtu <= ETH_DATA_LEN)
4508 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
4509} 4503}
4510 4504
4511static void rtl_hw_start_8168c_1(struct rtl8169_private *tp) 4505static void rtl_hw_start_8168c_1(struct rtl8169_private *tp)
@@ -4611,9 +4605,6 @@ static void rtl_hw_start_8168e_1(struct rtl8169_private *tp)
4611 4605
4612 rtl_ephy_init(tp, e_info_8168e_1); 4606 rtl_ephy_init(tp, e_info_8168e_1);
4613 4607
4614 if (tp->dev->mtu <= ETH_DATA_LEN)
4615 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
4616
4617 rtl_disable_clock_request(tp); 4608 rtl_disable_clock_request(tp);
4618 4609
4619 /* Reset tx FIFO pointer */ 4610 /* Reset tx FIFO pointer */
@@ -4636,9 +4627,6 @@ static void rtl_hw_start_8168e_2(struct rtl8169_private *tp)
4636 4627
4637 rtl_ephy_init(tp, e_info_8168e_2); 4628 rtl_ephy_init(tp, e_info_8168e_2);
4638 4629
4639 if (tp->dev->mtu <= ETH_DATA_LEN)
4640 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
4641
4642 rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); 4630 rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000);
4643 rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); 4631 rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000);
4644 rtl_set_fifo_size(tp, 0x10, 0x10, 0x02, 0x06); 4632 rtl_set_fifo_size(tp, 0x10, 0x10, 0x02, 0x06);
@@ -5485,6 +5473,8 @@ static void rtl_hw_start(struct rtl8169_private *tp)
5485 rtl_set_rx_tx_desc_registers(tp); 5473 rtl_set_rx_tx_desc_registers(tp);
5486 rtl_lock_config_regs(tp); 5474 rtl_lock_config_regs(tp);
5487 5475
5476 rtl_jumbo_config(tp, tp->dev->mtu);
5477
5488 /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ 5478 /* Initially a 10 us delay. Turned it into a PCI commit. - FR */
5489 RTL_R16(tp, CPlusCmd); 5479 RTL_R16(tp, CPlusCmd);
5490 RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); 5480 RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb);
@@ -5498,10 +5488,7 @@ static int rtl8169_change_mtu(struct net_device *dev, int new_mtu)
5498{ 5488{
5499 struct rtl8169_private *tp = netdev_priv(dev); 5489 struct rtl8169_private *tp = netdev_priv(dev);
5500 5490
5501 if (new_mtu > ETH_DATA_LEN) 5491 rtl_jumbo_config(tp, new_mtu);
5502 rtl_hw_jumbo_enable(tp);
5503 else
5504 rtl_hw_jumbo_disable(tp);
5505 5492
5506 dev->mtu = new_mtu; 5493 dev->mtu = new_mtu;
5507 netdev_update_features(dev); 5494 netdev_update_features(dev);
diff --git a/drivers/net/ethernet/socionext/netsec.c b/drivers/net/ethernet/socionext/netsec.c
index 55db7fbd43cc..f9e6744d8fd6 100644
--- a/drivers/net/ethernet/socionext/netsec.c
+++ b/drivers/net/ethernet/socionext/netsec.c
@@ -282,7 +282,6 @@ struct netsec_desc_ring {
282 void *vaddr; 282 void *vaddr;
283 u16 head, tail; 283 u16 head, tail;
284 u16 xdp_xmit; /* netsec_xdp_xmit packets */ 284 u16 xdp_xmit; /* netsec_xdp_xmit packets */
285 bool is_xdp;
286 struct page_pool *page_pool; 285 struct page_pool *page_pool;
287 struct xdp_rxq_info xdp_rxq; 286 struct xdp_rxq_info xdp_rxq;
288 spinlock_t lock; /* XDP tx queue locking */ 287 spinlock_t lock; /* XDP tx queue locking */
@@ -634,8 +633,7 @@ static bool netsec_clean_tx_dring(struct netsec_priv *priv)
634 unsigned int bytes; 633 unsigned int bytes;
635 int cnt = 0; 634 int cnt = 0;
636 635
637 if (dring->is_xdp) 636 spin_lock(&dring->lock);
638 spin_lock(&dring->lock);
639 637
640 bytes = 0; 638 bytes = 0;
641 entry = dring->vaddr + DESC_SZ * tail; 639 entry = dring->vaddr + DESC_SZ * tail;
@@ -682,8 +680,8 @@ next:
682 entry = dring->vaddr + DESC_SZ * tail; 680 entry = dring->vaddr + DESC_SZ * tail;
683 cnt++; 681 cnt++;
684 } 682 }
685 if (dring->is_xdp) 683
686 spin_unlock(&dring->lock); 684 spin_unlock(&dring->lock);
687 685
688 if (!cnt) 686 if (!cnt)
689 return false; 687 return false;
@@ -799,9 +797,6 @@ static void netsec_set_tx_de(struct netsec_priv *priv,
799 de->data_buf_addr_lw = lower_32_bits(desc->dma_addr); 797 de->data_buf_addr_lw = lower_32_bits(desc->dma_addr);
800 de->buf_len_info = (tx_ctrl->tcp_seg_len << 16) | desc->len; 798 de->buf_len_info = (tx_ctrl->tcp_seg_len << 16) | desc->len;
801 de->attr = attr; 799 de->attr = attr;
802 /* under spin_lock if using XDP */
803 if (!dring->is_xdp)
804 dma_wmb();
805 800
806 dring->desc[idx] = *desc; 801 dring->desc[idx] = *desc;
807 if (desc->buf_type == TYPE_NETSEC_SKB) 802 if (desc->buf_type == TYPE_NETSEC_SKB)
@@ -1123,12 +1118,10 @@ static netdev_tx_t netsec_netdev_start_xmit(struct sk_buff *skb,
1123 u16 tso_seg_len = 0; 1118 u16 tso_seg_len = 0;
1124 int filled; 1119 int filled;
1125 1120
1126 if (dring->is_xdp) 1121 spin_lock_bh(&dring->lock);
1127 spin_lock_bh(&dring->lock);
1128 filled = netsec_desc_used(dring); 1122 filled = netsec_desc_used(dring);
1129 if (netsec_check_stop_tx(priv, filled)) { 1123 if (netsec_check_stop_tx(priv, filled)) {
1130 if (dring->is_xdp) 1124 spin_unlock_bh(&dring->lock);
1131 spin_unlock_bh(&dring->lock);
1132 net_warn_ratelimited("%s %s Tx queue full\n", 1125 net_warn_ratelimited("%s %s Tx queue full\n",
1133 dev_name(priv->dev), ndev->name); 1126 dev_name(priv->dev), ndev->name);
1134 return NETDEV_TX_BUSY; 1127 return NETDEV_TX_BUSY;
@@ -1161,8 +1154,7 @@ static netdev_tx_t netsec_netdev_start_xmit(struct sk_buff *skb,
1161 tx_desc.dma_addr = dma_map_single(priv->dev, skb->data, 1154 tx_desc.dma_addr = dma_map_single(priv->dev, skb->data,
1162 skb_headlen(skb), DMA_TO_DEVICE); 1155 skb_headlen(skb), DMA_TO_DEVICE);
1163 if (dma_mapping_error(priv->dev, tx_desc.dma_addr)) { 1156 if (dma_mapping_error(priv->dev, tx_desc.dma_addr)) {
1164 if (dring->is_xdp) 1157 spin_unlock_bh(&dring->lock);
1165 spin_unlock_bh(&dring->lock);
1166 netif_err(priv, drv, priv->ndev, 1158 netif_err(priv, drv, priv->ndev,
1167 "%s: DMA mapping failed\n", __func__); 1159 "%s: DMA mapping failed\n", __func__);
1168 ndev->stats.tx_dropped++; 1160 ndev->stats.tx_dropped++;
@@ -1177,8 +1169,7 @@ static netdev_tx_t netsec_netdev_start_xmit(struct sk_buff *skb,
1177 netdev_sent_queue(priv->ndev, skb->len); 1169 netdev_sent_queue(priv->ndev, skb->len);
1178 1170
1179 netsec_set_tx_de(priv, dring, &tx_ctrl, &tx_desc, skb); 1171 netsec_set_tx_de(priv, dring, &tx_ctrl, &tx_desc, skb);
1180 if (dring->is_xdp) 1172 spin_unlock_bh(&dring->lock);
1181 spin_unlock_bh(&dring->lock);
1182 netsec_write(priv, NETSEC_REG_NRM_TX_PKTCNT, 1); /* submit another tx */ 1173 netsec_write(priv, NETSEC_REG_NRM_TX_PKTCNT, 1); /* submit another tx */
1183 1174
1184 return NETDEV_TX_OK; 1175 return NETDEV_TX_OK;
@@ -1262,7 +1253,6 @@ err:
1262static void netsec_setup_tx_dring(struct netsec_priv *priv) 1253static void netsec_setup_tx_dring(struct netsec_priv *priv)
1263{ 1254{
1264 struct netsec_desc_ring *dring = &priv->desc_ring[NETSEC_RING_TX]; 1255 struct netsec_desc_ring *dring = &priv->desc_ring[NETSEC_RING_TX];
1265 struct bpf_prog *xdp_prog = READ_ONCE(priv->xdp_prog);
1266 int i; 1256 int i;
1267 1257
1268 for (i = 0; i < DESC_NUM; i++) { 1258 for (i = 0; i < DESC_NUM; i++) {
@@ -1275,12 +1265,6 @@ static void netsec_setup_tx_dring(struct netsec_priv *priv)
1275 */ 1265 */
1276 de->attr = 1U << NETSEC_TX_SHIFT_OWN_FIELD; 1266 de->attr = 1U << NETSEC_TX_SHIFT_OWN_FIELD;
1277 } 1267 }
1278
1279 if (xdp_prog)
1280 dring->is_xdp = true;
1281 else
1282 dring->is_xdp = false;
1283
1284} 1268}
1285 1269
1286static int netsec_setup_rx_dring(struct netsec_priv *priv) 1270static int netsec_setup_rx_dring(struct netsec_priv *priv)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index f97a4096f8fc..ddcc191febdb 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -651,7 +651,8 @@ static void sun8i_dwmac_set_filter(struct mac_device_info *hw,
651 } 651 }
652 } 652 }
653 } else { 653 } else {
654 netdev_info(dev, "Too many address, switching to promiscuous\n"); 654 if (!(readl(ioaddr + EMAC_RX_FRM_FLT) & EMAC_FRM_FLT_RXALL))
655 netdev_info(dev, "Too many address, switching to promiscuous\n");
655 v = EMAC_FRM_FLT_RXALL; 656 v = EMAC_FRM_FLT_RXALL;
656 } 657 }
657 658
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index 9b4b5f69fc02..5a7b0aca1d31 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -401,8 +401,11 @@ static void dwmac4_set_filter(struct mac_device_info *hw,
401 int numhashregs = (hw->multicast_filter_bins >> 5); 401 int numhashregs = (hw->multicast_filter_bins >> 5);
402 int mcbitslog2 = hw->mcast_bits_log2; 402 int mcbitslog2 = hw->mcast_bits_log2;
403 unsigned int value; 403 unsigned int value;
404 u32 mc_filter[8];
404 int i; 405 int i;
405 406
407 memset(mc_filter, 0, sizeof(mc_filter));
408
406 value = readl(ioaddr + GMAC_PACKET_FILTER); 409 value = readl(ioaddr + GMAC_PACKET_FILTER);
407 value &= ~GMAC_PACKET_FILTER_HMC; 410 value &= ~GMAC_PACKET_FILTER_HMC;
408 value &= ~GMAC_PACKET_FILTER_HPF; 411 value &= ~GMAC_PACKET_FILTER_HPF;
@@ -416,16 +419,13 @@ static void dwmac4_set_filter(struct mac_device_info *hw,
416 /* Pass all multi */ 419 /* Pass all multi */
417 value |= GMAC_PACKET_FILTER_PM; 420 value |= GMAC_PACKET_FILTER_PM;
418 /* Set all the bits of the HASH tab */ 421 /* Set all the bits of the HASH tab */
419 for (i = 0; i < numhashregs; i++) 422 memset(mc_filter, 0xff, sizeof(mc_filter));
420 writel(0xffffffff, ioaddr + GMAC_HASH_TAB(i));
421 } else if (!netdev_mc_empty(dev)) { 423 } else if (!netdev_mc_empty(dev)) {
422 struct netdev_hw_addr *ha; 424 struct netdev_hw_addr *ha;
423 u32 mc_filter[8];
424 425
425 /* Hash filter for multicast */ 426 /* Hash filter for multicast */
426 value |= GMAC_PACKET_FILTER_HMC; 427 value |= GMAC_PACKET_FILTER_HMC;
427 428
428 memset(mc_filter, 0, sizeof(mc_filter));
429 netdev_for_each_mc_addr(ha, dev) { 429 netdev_for_each_mc_addr(ha, dev) {
430 /* The upper n bits of the calculated CRC are used to 430 /* The upper n bits of the calculated CRC are used to
431 * index the contents of the hash table. The number of 431 * index the contents of the hash table. The number of
@@ -440,14 +440,15 @@ static void dwmac4_set_filter(struct mac_device_info *hw,
440 */ 440 */
441 mc_filter[bit_nr >> 5] |= (1 << (bit_nr & 0x1f)); 441 mc_filter[bit_nr >> 5] |= (1 << (bit_nr & 0x1f));
442 } 442 }
443 for (i = 0; i < numhashregs; i++)
444 writel(mc_filter[i], ioaddr + GMAC_HASH_TAB(i));
445 } 443 }
446 444
445 for (i = 0; i < numhashregs; i++)
446 writel(mc_filter[i], ioaddr + GMAC_HASH_TAB(i));
447
447 value |= GMAC_PACKET_FILTER_HPF; 448 value |= GMAC_PACKET_FILTER_HPF;
448 449
449 /* Handle multiple unicast addresses */ 450 /* Handle multiple unicast addresses */
450 if (netdev_uc_count(dev) > GMAC_MAX_PERFECT_ADDRESSES) { 451 if (netdev_uc_count(dev) > hw->unicast_filter_entries) {
451 /* Switch to promiscuous mode if more than 128 addrs 452 /* Switch to promiscuous mode if more than 128 addrs
452 * are required 453 * are required
453 */ 454 */
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c
index 3f4f3132e16b..e436fa160c7d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c
@@ -515,6 +515,7 @@ int dwmac5_flex_pps_config(void __iomem *ioaddr, int index,
515 515
516 if (!enable) { 516 if (!enable) {
517 val |= PPSCMDx(index, 0x5); 517 val |= PPSCMDx(index, 0x5);
518 val |= PPSEN0;
518 writel(val, ioaddr + MAC_PPS_CONTROL); 519 writel(val, ioaddr + MAC_PPS_CONTROL);
519 return 0; 520 return 0;
520 } 521 }
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
index 5923ca62d793..99037386080a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
@@ -84,7 +84,7 @@
84#define XGMAC_TSIE BIT(12) 84#define XGMAC_TSIE BIT(12)
85#define XGMAC_LPIIE BIT(5) 85#define XGMAC_LPIIE BIT(5)
86#define XGMAC_PMTIE BIT(4) 86#define XGMAC_PMTIE BIT(4)
87#define XGMAC_INT_DEFAULT_EN (XGMAC_LPIIE | XGMAC_PMTIE | XGMAC_TSIE) 87#define XGMAC_INT_DEFAULT_EN (XGMAC_LPIIE | XGMAC_PMTIE)
88#define XGMAC_Qx_TX_FLOW_CTRL(x) (0x00000070 + (x) * 4) 88#define XGMAC_Qx_TX_FLOW_CTRL(x) (0x00000070 + (x) * 4)
89#define XGMAC_PT GENMASK(31, 16) 89#define XGMAC_PT GENMASK(31, 16)
90#define XGMAC_PT_SHIFT 16 90#define XGMAC_PT_SHIFT 16
@@ -122,6 +122,7 @@
122#define XGMAC_HWFEAT_GMIISEL BIT(1) 122#define XGMAC_HWFEAT_GMIISEL BIT(1)
123#define XGMAC_HW_FEATURE1 0x00000120 123#define XGMAC_HW_FEATURE1 0x00000120
124#define XGMAC_HWFEAT_L3L4FNUM GENMASK(30, 27) 124#define XGMAC_HWFEAT_L3L4FNUM GENMASK(30, 27)
125#define XGMAC_HWFEAT_HASHTBLSZ GENMASK(25, 24)
125#define XGMAC_HWFEAT_RSSEN BIT(20) 126#define XGMAC_HWFEAT_RSSEN BIT(20)
126#define XGMAC_HWFEAT_TSOEN BIT(18) 127#define XGMAC_HWFEAT_TSOEN BIT(18)
127#define XGMAC_HWFEAT_SPHEN BIT(17) 128#define XGMAC_HWFEAT_SPHEN BIT(17)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index 2b277b2c586b..5031398e612c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -472,7 +472,7 @@ static void dwxgmac2_set_filter(struct mac_device_info *hw,
472 dwxgmac2_set_mchash(ioaddr, mc_filter, mcbitslog2); 472 dwxgmac2_set_mchash(ioaddr, mc_filter, mcbitslog2);
473 473
474 /* Handle multiple unicast addresses */ 474 /* Handle multiple unicast addresses */
475 if (netdev_uc_count(dev) > XGMAC_ADDR_MAX) { 475 if (netdev_uc_count(dev) > hw->unicast_filter_entries) {
476 value |= XGMAC_FILTER_PR; 476 value |= XGMAC_FILTER_PR;
477 } else { 477 } else {
478 struct netdev_hw_addr *ha; 478 struct netdev_hw_addr *ha;
@@ -523,8 +523,8 @@ static int dwxgmac2_rss_configure(struct mac_device_info *hw,
523 struct stmmac_rss *cfg, u32 num_rxq) 523 struct stmmac_rss *cfg, u32 num_rxq)
524{ 524{
525 void __iomem *ioaddr = hw->pcsr; 525 void __iomem *ioaddr = hw->pcsr;
526 u32 value, *key;
526 int i, ret; 527 int i, ret;
527 u32 value;
528 528
529 value = readl(ioaddr + XGMAC_RSS_CTRL); 529 value = readl(ioaddr + XGMAC_RSS_CTRL);
530 if (!cfg || !cfg->enable) { 530 if (!cfg || !cfg->enable) {
@@ -533,8 +533,9 @@ static int dwxgmac2_rss_configure(struct mac_device_info *hw,
533 return 0; 533 return 0;
534 } 534 }
535 535
536 for (i = 0; i < (sizeof(cfg->key) / sizeof(u32)); i++) { 536 key = (u32 *)cfg->key;
537 ret = dwxgmac2_rss_write_reg(ioaddr, true, i, cfg->key[i]); 537 for (i = 0; i < (ARRAY_SIZE(cfg->key) / sizeof(u32)); i++) {
538 ret = dwxgmac2_rss_write_reg(ioaddr, true, i, key[i]);
538 if (ret) 539 if (ret)
539 return ret; 540 return ret;
540 } 541 }
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
index 53c4a40d8386..965cbe3e6f51 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
@@ -380,6 +380,7 @@ static void dwxgmac2_get_hw_feature(void __iomem *ioaddr,
380 /* MAC HW feature 1 */ 380 /* MAC HW feature 1 */
381 hw_cap = readl(ioaddr + XGMAC_HW_FEATURE1); 381 hw_cap = readl(ioaddr + XGMAC_HW_FEATURE1);
382 dma_cap->l3l4fnum = (hw_cap & XGMAC_HWFEAT_L3L4FNUM) >> 27; 382 dma_cap->l3l4fnum = (hw_cap & XGMAC_HWFEAT_L3L4FNUM) >> 27;
383 dma_cap->hash_tb_sz = (hw_cap & XGMAC_HWFEAT_HASHTBLSZ) >> 24;
383 dma_cap->rssen = (hw_cap & XGMAC_HWFEAT_RSSEN) >> 20; 384 dma_cap->rssen = (hw_cap & XGMAC_HWFEAT_RSSEN) >> 20;
384 dma_cap->tsoen = (hw_cap & XGMAC_HWFEAT_TSOEN) >> 18; 385 dma_cap->tsoen = (hw_cap & XGMAC_HWFEAT_TSOEN) >> 18;
385 dma_cap->sphen = (hw_cap & XGMAC_HWFEAT_SPHEN) >> 17; 386 dma_cap->sphen = (hw_cap & XGMAC_HWFEAT_SPHEN) >> 17;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index d3232738fb25..4e9c848c67cc 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -629,6 +629,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
629 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; 629 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
630 ptp_v2 = PTP_TCR_TSVER2ENA; 630 ptp_v2 = PTP_TCR_TSVER2ENA;
631 snap_type_sel = PTP_TCR_SNAPTYPSEL_1; 631 snap_type_sel = PTP_TCR_SNAPTYPSEL_1;
632 ts_event_en = PTP_TCR_TSEVNTENA;
632 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; 633 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
633 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; 634 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
634 ptp_over_ethernet = PTP_TCR_TSIPENA; 635 ptp_over_ethernet = PTP_TCR_TSIPENA;
@@ -2609,7 +2610,7 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp)
2609 } 2610 }
2610 2611
2611 if (priv->hw->pcs) 2612 if (priv->hw->pcs)
2612 stmmac_pcs_ctrl_ane(priv, priv->hw, 1, priv->hw->ps, 0); 2613 stmmac_pcs_ctrl_ane(priv, priv->ioaddr, 1, priv->hw->ps, 0);
2613 2614
2614 /* set TX and RX rings length */ 2615 /* set TX and RX rings length */
2615 stmmac_set_rings_length(priv); 2616 stmmac_set_rings_length(priv);
@@ -2994,6 +2995,7 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
2994 } else { 2995 } else {
2995 stmmac_set_desc_addr(priv, first, des); 2996 stmmac_set_desc_addr(priv, first, des);
2996 tmp_pay_len = pay_len; 2997 tmp_pay_len = pay_len;
2998 des += proto_hdr_len;
2997 } 2999 }
2998 3000
2999 stmmac_tso_allocator(priv, des, tmp_pay_len, (nfrags == 0), queue); 3001 stmmac_tso_allocator(priv, des, tmp_pay_len, (nfrags == 0), queue);
@@ -4715,11 +4717,9 @@ int stmmac_suspend(struct device *dev)
4715 if (!ndev || !netif_running(ndev)) 4717 if (!ndev || !netif_running(ndev))
4716 return 0; 4718 return 0;
4717 4719
4718 mutex_lock(&priv->lock); 4720 phylink_mac_change(priv->phylink, false);
4719 4721
4720 rtnl_lock(); 4722 mutex_lock(&priv->lock);
4721 phylink_stop(priv->phylink);
4722 rtnl_unlock();
4723 4723
4724 netif_device_detach(ndev); 4724 netif_device_detach(ndev);
4725 stmmac_stop_all_queues(priv); 4725 stmmac_stop_all_queues(priv);
@@ -4734,11 +4734,19 @@ int stmmac_suspend(struct device *dev)
4734 stmmac_pmt(priv, priv->hw, priv->wolopts); 4734 stmmac_pmt(priv, priv->hw, priv->wolopts);
4735 priv->irq_wake = 1; 4735 priv->irq_wake = 1;
4736 } else { 4736 } else {
4737 mutex_unlock(&priv->lock);
4738 rtnl_lock();
4739 phylink_stop(priv->phylink);
4740 rtnl_unlock();
4741 mutex_lock(&priv->lock);
4742
4737 stmmac_mac_set(priv, priv->ioaddr, false); 4743 stmmac_mac_set(priv, priv->ioaddr, false);
4738 pinctrl_pm_select_sleep_state(priv->device); 4744 pinctrl_pm_select_sleep_state(priv->device);
4739 /* Disable clock in case of PWM is off */ 4745 /* Disable clock in case of PWM is off */
4740 clk_disable(priv->plat->pclk); 4746 if (priv->plat->clk_ptp_ref)
4741 clk_disable(priv->plat->stmmac_clk); 4747 clk_disable_unprepare(priv->plat->clk_ptp_ref);
4748 clk_disable_unprepare(priv->plat->pclk);
4749 clk_disable_unprepare(priv->plat->stmmac_clk);
4742 } 4750 }
4743 mutex_unlock(&priv->lock); 4751 mutex_unlock(&priv->lock);
4744 4752
@@ -4801,8 +4809,10 @@ int stmmac_resume(struct device *dev)
4801 } else { 4809 } else {
4802 pinctrl_pm_select_default_state(priv->device); 4810 pinctrl_pm_select_default_state(priv->device);
4803 /* enable the clk previously disabled */ 4811 /* enable the clk previously disabled */
4804 clk_enable(priv->plat->stmmac_clk); 4812 clk_prepare_enable(priv->plat->stmmac_clk);
4805 clk_enable(priv->plat->pclk); 4813 clk_prepare_enable(priv->plat->pclk);
4814 if (priv->plat->clk_ptp_ref)
4815 clk_prepare_enable(priv->plat->clk_ptp_ref);
4806 /* reset the phy so that it's ready */ 4816 /* reset the phy so that it's ready */
4807 if (priv->mii) 4817 if (priv->mii)
4808 stmmac_mdio_reset(priv->mii); 4818 stmmac_mdio_reset(priv->mii);
@@ -4824,12 +4834,16 @@ int stmmac_resume(struct device *dev)
4824 4834
4825 stmmac_start_all_queues(priv); 4835 stmmac_start_all_queues(priv);
4826 4836
4827 rtnl_lock();
4828 phylink_start(priv->phylink);
4829 rtnl_unlock();
4830
4831 mutex_unlock(&priv->lock); 4837 mutex_unlock(&priv->lock);
4832 4838
4839 if (!device_may_wakeup(priv->device)) {
4840 rtnl_lock();
4841 phylink_start(priv->phylink);
4842 rtnl_unlock();
4843 }
4844
4845 phylink_mac_change(priv->phylink, true);
4846
4833 return 0; 4847 return 0;
4834} 4848}
4835EXPORT_SYMBOL_GPL(stmmac_resume); 4849EXPORT_SYMBOL_GPL(stmmac_resume);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
index 173493db038c..df638b18b72c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
@@ -164,7 +164,7 @@ static int stmmac_enable(struct ptp_clock_info *ptp,
164/* structure describing a PTP hardware clock */ 164/* structure describing a PTP hardware clock */
165static struct ptp_clock_info stmmac_ptp_clock_ops = { 165static struct ptp_clock_info stmmac_ptp_clock_ops = {
166 .owner = THIS_MODULE, 166 .owner = THIS_MODULE,
167 .name = "stmmac_ptp_clock", 167 .name = "stmmac ptp",
168 .max_adj = 62500000, 168 .max_adj = 62500000,
169 .n_alarm = 0, 169 .n_alarm = 0,
170 .n_ext_ts = 0, 170 .n_ext_ts = 0,
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index 5f66f6161629..e4ac3c401432 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -487,8 +487,8 @@ static int stmmac_filter_check(struct stmmac_priv *priv)
487 487
488static int stmmac_test_hfilt(struct stmmac_priv *priv) 488static int stmmac_test_hfilt(struct stmmac_priv *priv)
489{ 489{
490 unsigned char gd_addr[ETH_ALEN] = {0x01, 0x00, 0xcc, 0xcc, 0xdd, 0xdd}; 490 unsigned char gd_addr[ETH_ALEN] = {0x01, 0xee, 0xdd, 0xcc, 0xbb, 0xaa};
491 unsigned char bd_addr[ETH_ALEN] = {0x09, 0x00, 0xaa, 0xaa, 0xbb, 0xbb}; 491 unsigned char bd_addr[ETH_ALEN] = {0x01, 0x01, 0x02, 0x03, 0x04, 0x05};
492 struct stmmac_packet_attrs attr = { }; 492 struct stmmac_packet_attrs attr = { };
493 int ret; 493 int ret;
494 494
@@ -496,6 +496,9 @@ static int stmmac_test_hfilt(struct stmmac_priv *priv)
496 if (ret) 496 if (ret)
497 return ret; 497 return ret;
498 498
499 if (netdev_mc_count(priv->dev) >= priv->hw->multicast_filter_bins)
500 return -EOPNOTSUPP;
501
499 ret = dev_mc_add(priv->dev, gd_addr); 502 ret = dev_mc_add(priv->dev, gd_addr);
500 if (ret) 503 if (ret)
501 return ret; 504 return ret;
@@ -573,6 +576,8 @@ static int stmmac_test_mcfilt(struct stmmac_priv *priv)
573 576
574 if (stmmac_filter_check(priv)) 577 if (stmmac_filter_check(priv))
575 return -EOPNOTSUPP; 578 return -EOPNOTSUPP;
579 if (!priv->hw->multicast_filter_bins)
580 return -EOPNOTSUPP;
576 581
577 /* Remove all MC addresses */ 582 /* Remove all MC addresses */
578 __dev_mc_unsync(priv->dev, NULL); 583 __dev_mc_unsync(priv->dev, NULL);
@@ -611,6 +616,8 @@ static int stmmac_test_ucfilt(struct stmmac_priv *priv)
611 616
612 if (stmmac_filter_check(priv)) 617 if (stmmac_filter_check(priv))
613 return -EOPNOTSUPP; 618 return -EOPNOTSUPP;
619 if (!priv->hw->multicast_filter_bins)
620 return -EOPNOTSUPP;
614 621
615 /* Remove all UC addresses */ 622 /* Remove all UC addresses */
616 __dev_uc_unsync(priv->dev, NULL); 623 __dev_uc_unsync(priv->dev, NULL);
@@ -1564,10 +1571,6 @@ static int __stmmac_test_jumbo(struct stmmac_priv *priv, u16 queue)
1564 struct stmmac_packet_attrs attr = { }; 1571 struct stmmac_packet_attrs attr = { };
1565 int size = priv->dma_buf_sz; 1572 int size = priv->dma_buf_sz;
1566 1573
1567 /* Only XGMAC has SW support for multiple RX descs in same packet */
1568 if (priv->plat->has_xgmac)
1569 size = priv->dev->max_mtu;
1570
1571 attr.dst = priv->dev->dev_addr; 1574 attr.dst = priv->dev->dev_addr;
1572 attr.max_size = size - ETH_FCS_LEN; 1575 attr.max_size = size - ETH_FCS_LEN;
1573 attr.queue_mapping = queue; 1576 attr.queue_mapping = queue;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
index e231098061b6..f9a9a9d82233 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
@@ -510,7 +510,7 @@ static struct stmmac_flow_entry *tc_find_flow(struct stmmac_priv *priv,
510 return NULL; 510 return NULL;
511} 511}
512 512
513struct { 513static struct {
514 int (*fn)(struct stmmac_priv *priv, struct flow_cls_offload *cls, 514 int (*fn)(struct stmmac_priv *priv, struct flow_cls_offload *cls,
515 struct stmmac_flow_entry *entry); 515 struct stmmac_flow_entry *entry);
516} tc_flow_parsers[] = { 516} tc_flow_parsers[] = {
diff --git a/drivers/net/ethernet/ti/davinci_cpdma.c b/drivers/net/ethernet/ti/davinci_cpdma.c
index a65edd2770e6..37ba708ac781 100644
--- a/drivers/net/ethernet/ti/davinci_cpdma.c
+++ b/drivers/net/ethernet/ti/davinci_cpdma.c
@@ -722,7 +722,7 @@ static void cpdma_chan_set_descs(struct cpdma_ctlr *ctlr,
722 * cpdma_chan_split_pool - Splits ctrl pool between all channels. 722 * cpdma_chan_split_pool - Splits ctrl pool between all channels.
723 * Has to be called under ctlr lock 723 * Has to be called under ctlr lock
724 */ 724 */
725int cpdma_chan_split_pool(struct cpdma_ctlr *ctlr) 725static int cpdma_chan_split_pool(struct cpdma_ctlr *ctlr)
726{ 726{
727 int tx_per_ch_desc = 0, rx_per_ch_desc = 0; 727 int tx_per_ch_desc = 0, rx_per_ch_desc = 0;
728 int free_rx_num = 0, free_tx_num = 0; 728 int free_rx_num = 0, free_tx_num = 0;
diff --git a/drivers/net/fjes/fjes_main.c b/drivers/net/fjes/fjes_main.c
index bbbc1dcb6ab5..b517c1af9de0 100644
--- a/drivers/net/fjes/fjes_main.c
+++ b/drivers/net/fjes/fjes_main.c
@@ -1237,8 +1237,17 @@ static int fjes_probe(struct platform_device *plat_dev)
1237 adapter->open_guard = false; 1237 adapter->open_guard = false;
1238 1238
1239 adapter->txrx_wq = alloc_workqueue(DRV_NAME "/txrx", WQ_MEM_RECLAIM, 0); 1239 adapter->txrx_wq = alloc_workqueue(DRV_NAME "/txrx", WQ_MEM_RECLAIM, 0);
1240 if (unlikely(!adapter->txrx_wq)) {
1241 err = -ENOMEM;
1242 goto err_free_netdev;
1243 }
1244
1240 adapter->control_wq = alloc_workqueue(DRV_NAME "/control", 1245 adapter->control_wq = alloc_workqueue(DRV_NAME "/control",
1241 WQ_MEM_RECLAIM, 0); 1246 WQ_MEM_RECLAIM, 0);
1247 if (unlikely(!adapter->control_wq)) {
1248 err = -ENOMEM;
1249 goto err_free_txrx_wq;
1250 }
1242 1251
1243 INIT_WORK(&adapter->tx_stall_task, fjes_tx_stall_task); 1252 INIT_WORK(&adapter->tx_stall_task, fjes_tx_stall_task);
1244 INIT_WORK(&adapter->raise_intr_rxdata_task, 1253 INIT_WORK(&adapter->raise_intr_rxdata_task,
@@ -1255,7 +1264,7 @@ static int fjes_probe(struct platform_device *plat_dev)
1255 hw->hw_res.irq = platform_get_irq(plat_dev, 0); 1264 hw->hw_res.irq = platform_get_irq(plat_dev, 0);
1256 err = fjes_hw_init(&adapter->hw); 1265 err = fjes_hw_init(&adapter->hw);
1257 if (err) 1266 if (err)
1258 goto err_free_netdev; 1267 goto err_free_control_wq;
1259 1268
1260 /* setup MAC address (02:00:00:00:00:[epid])*/ 1269 /* setup MAC address (02:00:00:00:00:[epid])*/
1261 netdev->dev_addr[0] = 2; 1270 netdev->dev_addr[0] = 2;
@@ -1277,6 +1286,10 @@ static int fjes_probe(struct platform_device *plat_dev)
1277 1286
1278err_hw_exit: 1287err_hw_exit:
1279 fjes_hw_exit(&adapter->hw); 1288 fjes_hw_exit(&adapter->hw);
1289err_free_control_wq:
1290 destroy_workqueue(adapter->control_wq);
1291err_free_txrx_wq:
1292 destroy_workqueue(adapter->txrx_wq);
1280err_free_netdev: 1293err_free_netdev:
1281 free_netdev(netdev); 1294 free_netdev(netdev);
1282err_out: 1295err_out:
diff --git a/drivers/net/hamradio/bpqether.c b/drivers/net/hamradio/bpqether.c
index fbec711ff514..fbea6f232819 100644
--- a/drivers/net/hamradio/bpqether.c
+++ b/drivers/net/hamradio/bpqether.c
@@ -107,27 +107,6 @@ struct bpqdev {
107 107
108static LIST_HEAD(bpq_devices); 108static LIST_HEAD(bpq_devices);
109 109
110/*
111 * bpqether network devices are paired with ethernet devices below them, so
112 * form a special "super class" of normal ethernet devices; split their locks
113 * off into a separate class since they always nest.
114 */
115static struct lock_class_key bpq_netdev_xmit_lock_key;
116static struct lock_class_key bpq_netdev_addr_lock_key;
117
118static void bpq_set_lockdep_class_one(struct net_device *dev,
119 struct netdev_queue *txq,
120 void *_unused)
121{
122 lockdep_set_class(&txq->_xmit_lock, &bpq_netdev_xmit_lock_key);
123}
124
125static void bpq_set_lockdep_class(struct net_device *dev)
126{
127 lockdep_set_class(&dev->addr_list_lock, &bpq_netdev_addr_lock_key);
128 netdev_for_each_tx_queue(dev, bpq_set_lockdep_class_one, NULL);
129}
130
131/* ------------------------------------------------------------------------ */ 110/* ------------------------------------------------------------------------ */
132 111
133 112
@@ -498,7 +477,6 @@ static int bpq_new_device(struct net_device *edev)
498 err = register_netdevice(ndev); 477 err = register_netdevice(ndev);
499 if (err) 478 if (err)
500 goto error; 479 goto error;
501 bpq_set_lockdep_class(ndev);
502 480
503 /* List protected by RTNL */ 481 /* List protected by RTNL */
504 list_add_rcu(&bpq->bpq_list, &bpq_devices); 482 list_add_rcu(&bpq->bpq_list, &bpq_devices);
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 39dddcd8b3cb..963509add611 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -982,7 +982,7 @@ static int netvsc_attach(struct net_device *ndev,
982 if (netif_running(ndev)) { 982 if (netif_running(ndev)) {
983 ret = rndis_filter_open(nvdev); 983 ret = rndis_filter_open(nvdev);
984 if (ret) 984 if (ret)
985 return ret; 985 goto err;
986 986
987 rdev = nvdev->extension; 987 rdev = nvdev->extension;
988 if (!rdev->link_state) 988 if (!rdev->link_state)
@@ -990,6 +990,13 @@ static int netvsc_attach(struct net_device *ndev,
990 } 990 }
991 991
992 return 0; 992 return 0;
993
994err:
995 netif_device_detach(ndev);
996
997 rndis_filter_device_remove(hdev, nvdev);
998
999 return ret;
993} 1000}
994 1001
995static int netvsc_set_channels(struct net_device *net, 1002static int netvsc_set_channels(struct net_device *net,
@@ -1807,8 +1814,10 @@ static int netvsc_set_features(struct net_device *ndev,
1807 1814
1808 ret = rndis_filter_set_offload_params(ndev, nvdev, &offloads); 1815 ret = rndis_filter_set_offload_params(ndev, nvdev, &offloads);
1809 1816
1810 if (ret) 1817 if (ret) {
1811 features ^= NETIF_F_LRO; 1818 features ^= NETIF_F_LRO;
1819 ndev->features = features;
1820 }
1812 1821
1813syncvf: 1822syncvf:
1814 if (!vf_netdev) 1823 if (!vf_netdev)
@@ -2335,8 +2344,6 @@ static int netvsc_probe(struct hv_device *dev,
2335 NETIF_F_HW_VLAN_CTAG_RX; 2344 NETIF_F_HW_VLAN_CTAG_RX;
2336 net->vlan_features = net->features; 2345 net->vlan_features = net->features;
2337 2346
2338 netdev_lockdep_set_classes(net);
2339
2340 /* MTU range: 68 - 1500 or 65521 */ 2347 /* MTU range: 68 - 1500 or 65521 */
2341 net->min_mtu = NETVSC_MTU_MIN; 2348 net->min_mtu = NETVSC_MTU_MIN;
2342 if (nvdev->nvsp_version >= NVSP_PROTOCOL_VERSION_2) 2349 if (nvdev->nvsp_version >= NVSP_PROTOCOL_VERSION_2)
diff --git a/drivers/net/ieee802154/atusb.c b/drivers/net/ieee802154/atusb.c
index ceddb424f887..0dd0ba915ab9 100644
--- a/drivers/net/ieee802154/atusb.c
+++ b/drivers/net/ieee802154/atusb.c
@@ -1137,10 +1137,11 @@ static void atusb_disconnect(struct usb_interface *interface)
1137 1137
1138 ieee802154_unregister_hw(atusb->hw); 1138 ieee802154_unregister_hw(atusb->hw);
1139 1139
1140 usb_put_dev(atusb->usb_dev);
1141
1140 ieee802154_free_hw(atusb->hw); 1142 ieee802154_free_hw(atusb->hw);
1141 1143
1142 usb_set_intfdata(interface, NULL); 1144 usb_set_intfdata(interface, NULL);
1143 usb_put_dev(atusb->usb_dev);
1144 1145
1145 pr_debug("%s done\n", __func__); 1146 pr_debug("%s done\n", __func__);
1146} 1147}
diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c
index 11402dc347db..430c93786153 100644
--- a/drivers/net/ieee802154/ca8210.c
+++ b/drivers/net/ieee802154/ca8210.c
@@ -3145,12 +3145,12 @@ static int ca8210_probe(struct spi_device *spi_device)
3145 goto error; 3145 goto error;
3146 } 3146 }
3147 3147
3148 priv->spi->dev.platform_data = pdata;
3148 ret = ca8210_get_platform_data(priv->spi, pdata); 3149 ret = ca8210_get_platform_data(priv->spi, pdata);
3149 if (ret) { 3150 if (ret) {
3150 dev_crit(&spi_device->dev, "ca8210_get_platform_data failed\n"); 3151 dev_crit(&spi_device->dev, "ca8210_get_platform_data failed\n");
3151 goto error; 3152 goto error;
3152 } 3153 }
3153 priv->spi->dev.platform_data = pdata;
3154 3154
3155 ret = ca8210_dev_com_init(priv); 3155 ret = ca8210_dev_com_init(priv);
3156 if (ret) { 3156 if (ret) {
diff --git a/drivers/net/ieee802154/mcr20a.c b/drivers/net/ieee802154/mcr20a.c
index 17f2300e63ee..8dc04e2590b1 100644
--- a/drivers/net/ieee802154/mcr20a.c
+++ b/drivers/net/ieee802154/mcr20a.c
@@ -800,7 +800,7 @@ mcr20a_handle_rx_read_buf_complete(void *context)
800 if (!skb) 800 if (!skb)
801 return; 801 return;
802 802
803 memcpy(skb_put(skb, len), lp->rx_buf, len); 803 __skb_put_data(skb, lp->rx_buf, len);
804 ieee802154_rx_irqsafe(lp->hw, skb, lp->rx_lqi[0]); 804 ieee802154_rx_irqsafe(lp->hw, skb, lp->rx_lqi[0]);
805 805
806 print_hex_dump_debug("mcr20a rx: ", DUMP_PREFIX_OFFSET, 16, 1, 806 print_hex_dump_debug("mcr20a rx: ", DUMP_PREFIX_OFFSET, 16, 1,
diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c
index 887bbba4631e..ba3dfac1d904 100644
--- a/drivers/net/ipvlan/ipvlan_main.c
+++ b/drivers/net/ipvlan/ipvlan_main.c
@@ -131,8 +131,6 @@ static int ipvlan_init(struct net_device *dev)
131 dev->gso_max_segs = phy_dev->gso_max_segs; 131 dev->gso_max_segs = phy_dev->gso_max_segs;
132 dev->hard_header_len = phy_dev->hard_header_len; 132 dev->hard_header_len = phy_dev->hard_header_len;
133 133
134 netdev_lockdep_set_classes(dev);
135
136 ipvlan->pcpu_stats = netdev_alloc_pcpu_stats(struct ipvl_pcpu_stats); 134 ipvlan->pcpu_stats = netdev_alloc_pcpu_stats(struct ipvl_pcpu_stats);
137 if (!ipvlan->pcpu_stats) 135 if (!ipvlan->pcpu_stats)
138 return -ENOMEM; 136 return -ENOMEM;
diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
index cb7637364b40..afd8b2a08245 100644
--- a/drivers/net/macsec.c
+++ b/drivers/net/macsec.c
@@ -267,7 +267,6 @@ struct macsec_dev {
267 struct pcpu_secy_stats __percpu *stats; 267 struct pcpu_secy_stats __percpu *stats;
268 struct list_head secys; 268 struct list_head secys;
269 struct gro_cells gro_cells; 269 struct gro_cells gro_cells;
270 unsigned int nest_level;
271}; 270};
272 271
273/** 272/**
@@ -2750,7 +2749,6 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
2750 2749
2751#define MACSEC_FEATURES \ 2750#define MACSEC_FEATURES \
2752 (NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST) 2751 (NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST)
2753static struct lock_class_key macsec_netdev_addr_lock_key;
2754 2752
2755static int macsec_dev_init(struct net_device *dev) 2753static int macsec_dev_init(struct net_device *dev)
2756{ 2754{
@@ -2958,11 +2956,6 @@ static int macsec_get_iflink(const struct net_device *dev)
2958 return macsec_priv(dev)->real_dev->ifindex; 2956 return macsec_priv(dev)->real_dev->ifindex;
2959} 2957}
2960 2958
2961static int macsec_get_nest_level(struct net_device *dev)
2962{
2963 return macsec_priv(dev)->nest_level;
2964}
2965
2966static const struct net_device_ops macsec_netdev_ops = { 2959static const struct net_device_ops macsec_netdev_ops = {
2967 .ndo_init = macsec_dev_init, 2960 .ndo_init = macsec_dev_init,
2968 .ndo_uninit = macsec_dev_uninit, 2961 .ndo_uninit = macsec_dev_uninit,
@@ -2976,7 +2969,6 @@ static const struct net_device_ops macsec_netdev_ops = {
2976 .ndo_start_xmit = macsec_start_xmit, 2969 .ndo_start_xmit = macsec_start_xmit,
2977 .ndo_get_stats64 = macsec_get_stats64, 2970 .ndo_get_stats64 = macsec_get_stats64,
2978 .ndo_get_iflink = macsec_get_iflink, 2971 .ndo_get_iflink = macsec_get_iflink,
2979 .ndo_get_lock_subclass = macsec_get_nest_level,
2980}; 2972};
2981 2973
2982static const struct device_type macsec_type = { 2974static const struct device_type macsec_type = {
@@ -3001,12 +2993,10 @@ static const struct nla_policy macsec_rtnl_policy[IFLA_MACSEC_MAX + 1] = {
3001static void macsec_free_netdev(struct net_device *dev) 2993static void macsec_free_netdev(struct net_device *dev)
3002{ 2994{
3003 struct macsec_dev *macsec = macsec_priv(dev); 2995 struct macsec_dev *macsec = macsec_priv(dev);
3004 struct net_device *real_dev = macsec->real_dev;
3005 2996
3006 free_percpu(macsec->stats); 2997 free_percpu(macsec->stats);
3007 free_percpu(macsec->secy.tx_sc.stats); 2998 free_percpu(macsec->secy.tx_sc.stats);
3008 2999
3009 dev_put(real_dev);
3010} 3000}
3011 3001
3012static void macsec_setup(struct net_device *dev) 3002static void macsec_setup(struct net_device *dev)
@@ -3261,14 +3251,6 @@ static int macsec_newlink(struct net *net, struct net_device *dev,
3261 if (err < 0) 3251 if (err < 0)
3262 return err; 3252 return err;
3263 3253
3264 dev_hold(real_dev);
3265
3266 macsec->nest_level = dev_get_nest_level(real_dev) + 1;
3267 netdev_lockdep_set_classes(dev);
3268 lockdep_set_class_and_subclass(&dev->addr_list_lock,
3269 &macsec_netdev_addr_lock_key,
3270 macsec_get_nest_level(dev));
3271
3272 err = netdev_upper_dev_link(real_dev, dev, extack); 3254 err = netdev_upper_dev_link(real_dev, dev, extack);
3273 if (err < 0) 3255 if (err < 0)
3274 goto unregister; 3256 goto unregister;
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 940192c057b6..34fc59bd1e20 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -852,8 +852,6 @@ static int macvlan_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
852 * "super class" of normal network devices; split their locks off into a 852 * "super class" of normal network devices; split their locks off into a
853 * separate class since they always nest. 853 * separate class since they always nest.
854 */ 854 */
855static struct lock_class_key macvlan_netdev_addr_lock_key;
856
857#define ALWAYS_ON_OFFLOADS \ 855#define ALWAYS_ON_OFFLOADS \
858 (NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_GSO_SOFTWARE | \ 856 (NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_GSO_SOFTWARE | \
859 NETIF_F_GSO_ROBUST | NETIF_F_GSO_ENCAP_ALL) 857 NETIF_F_GSO_ROBUST | NETIF_F_GSO_ENCAP_ALL)
@@ -869,19 +867,6 @@ static struct lock_class_key macvlan_netdev_addr_lock_key;
869#define MACVLAN_STATE_MASK \ 867#define MACVLAN_STATE_MASK \
870 ((1<<__LINK_STATE_NOCARRIER) | (1<<__LINK_STATE_DORMANT)) 868 ((1<<__LINK_STATE_NOCARRIER) | (1<<__LINK_STATE_DORMANT))
871 869
872static int macvlan_get_nest_level(struct net_device *dev)
873{
874 return ((struct macvlan_dev *)netdev_priv(dev))->nest_level;
875}
876
877static void macvlan_set_lockdep_class(struct net_device *dev)
878{
879 netdev_lockdep_set_classes(dev);
880 lockdep_set_class_and_subclass(&dev->addr_list_lock,
881 &macvlan_netdev_addr_lock_key,
882 macvlan_get_nest_level(dev));
883}
884
885static int macvlan_init(struct net_device *dev) 870static int macvlan_init(struct net_device *dev)
886{ 871{
887 struct macvlan_dev *vlan = netdev_priv(dev); 872 struct macvlan_dev *vlan = netdev_priv(dev);
@@ -900,8 +885,6 @@ static int macvlan_init(struct net_device *dev)
900 dev->gso_max_segs = lowerdev->gso_max_segs; 885 dev->gso_max_segs = lowerdev->gso_max_segs;
901 dev->hard_header_len = lowerdev->hard_header_len; 886 dev->hard_header_len = lowerdev->hard_header_len;
902 887
903 macvlan_set_lockdep_class(dev);
904
905 vlan->pcpu_stats = netdev_alloc_pcpu_stats(struct vlan_pcpu_stats); 888 vlan->pcpu_stats = netdev_alloc_pcpu_stats(struct vlan_pcpu_stats);
906 if (!vlan->pcpu_stats) 889 if (!vlan->pcpu_stats)
907 return -ENOMEM; 890 return -ENOMEM;
@@ -1161,7 +1144,6 @@ static const struct net_device_ops macvlan_netdev_ops = {
1161 .ndo_fdb_add = macvlan_fdb_add, 1144 .ndo_fdb_add = macvlan_fdb_add,
1162 .ndo_fdb_del = macvlan_fdb_del, 1145 .ndo_fdb_del = macvlan_fdb_del,
1163 .ndo_fdb_dump = ndo_dflt_fdb_dump, 1146 .ndo_fdb_dump = ndo_dflt_fdb_dump,
1164 .ndo_get_lock_subclass = macvlan_get_nest_level,
1165#ifdef CONFIG_NET_POLL_CONTROLLER 1147#ifdef CONFIG_NET_POLL_CONTROLLER
1166 .ndo_poll_controller = macvlan_dev_poll_controller, 1148 .ndo_poll_controller = macvlan_dev_poll_controller,
1167 .ndo_netpoll_setup = macvlan_dev_netpoll_setup, 1149 .ndo_netpoll_setup = macvlan_dev_netpoll_setup,
@@ -1445,7 +1427,6 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
1445 vlan->dev = dev; 1427 vlan->dev = dev;
1446 vlan->port = port; 1428 vlan->port = port;
1447 vlan->set_features = MACVLAN_FEATURES; 1429 vlan->set_features = MACVLAN_FEATURES;
1448 vlan->nest_level = dev_get_nest_level(lowerdev) + 1;
1449 1430
1450 vlan->mode = MACVLAN_MODE_VEPA; 1431 vlan->mode = MACVLAN_MODE_VEPA;
1451 if (data && data[IFLA_MACVLAN_MODE]) 1432 if (data && data[IFLA_MACVLAN_MODE])
diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
index 56576d4f34a5..54ca6681ba31 100644
--- a/drivers/net/netdevsim/dev.c
+++ b/drivers/net/netdevsim/dev.c
@@ -806,9 +806,11 @@ static void nsim_dev_port_del_all(struct nsim_dev *nsim_dev)
806{ 806{
807 struct nsim_dev_port *nsim_dev_port, *tmp; 807 struct nsim_dev_port *nsim_dev_port, *tmp;
808 808
809 mutex_lock(&nsim_dev->port_list_lock);
809 list_for_each_entry_safe(nsim_dev_port, tmp, 810 list_for_each_entry_safe(nsim_dev_port, tmp,
810 &nsim_dev->port_list, list) 811 &nsim_dev->port_list, list)
811 __nsim_dev_port_del(nsim_dev_port); 812 __nsim_dev_port_del(nsim_dev_port);
813 mutex_unlock(&nsim_dev->port_list_lock);
812} 814}
813 815
814int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev) 816int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev)
@@ -822,14 +824,17 @@ int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev)
822 return PTR_ERR(nsim_dev); 824 return PTR_ERR(nsim_dev);
823 dev_set_drvdata(&nsim_bus_dev->dev, nsim_dev); 825 dev_set_drvdata(&nsim_bus_dev->dev, nsim_dev);
824 826
827 mutex_lock(&nsim_dev->port_list_lock);
825 for (i = 0; i < nsim_bus_dev->port_count; i++) { 828 for (i = 0; i < nsim_bus_dev->port_count; i++) {
826 err = __nsim_dev_port_add(nsim_dev, i); 829 err = __nsim_dev_port_add(nsim_dev, i);
827 if (err) 830 if (err)
828 goto err_port_del_all; 831 goto err_port_del_all;
829 } 832 }
833 mutex_unlock(&nsim_dev->port_list_lock);
830 return 0; 834 return 0;
831 835
832err_port_del_all: 836err_port_del_all:
837 mutex_unlock(&nsim_dev->port_list_lock);
833 nsim_dev_port_del_all(nsim_dev); 838 nsim_dev_port_del_all(nsim_dev);
834 nsim_dev_destroy(nsim_dev); 839 nsim_dev_destroy(nsim_dev);
835 return err; 840 return err;
diff --git a/drivers/net/netdevsim/fib.c b/drivers/net/netdevsim/fib.c
index f61d094746c0..1a251f76d09b 100644
--- a/drivers/net/netdevsim/fib.c
+++ b/drivers/net/netdevsim/fib.c
@@ -241,8 +241,8 @@ static struct pernet_operations nsim_fib_net_ops = {
241 241
242void nsim_fib_exit(void) 242void nsim_fib_exit(void)
243{ 243{
244 unregister_pernet_subsys(&nsim_fib_net_ops);
245 unregister_fib_notifier(&nsim_fib_nb); 244 unregister_fib_notifier(&nsim_fib_nb);
245 unregister_pernet_subsys(&nsim_fib_net_ops);
246} 246}
247 247
248int nsim_fib_init(void) 248int nsim_fib_init(void)
@@ -258,6 +258,7 @@ int nsim_fib_init(void)
258 err = register_fib_notifier(&nsim_fib_nb, nsim_fib_dump_inconsistent); 258 err = register_fib_notifier(&nsim_fib_nb, nsim_fib_dump_inconsistent);
259 if (err < 0) { 259 if (err < 0) {
260 pr_err("Failed to register fib notifier\n"); 260 pr_err("Failed to register fib notifier\n");
261 unregister_pernet_subsys(&nsim_fib_net_ops);
261 goto err_out; 262 goto err_out;
262 } 263 }
263 264
diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
index 2aa7b2e60046..1eb5d4fb8925 100644
--- a/drivers/net/phy/at803x.c
+++ b/drivers/net/phy/at803x.c
@@ -15,6 +15,15 @@
15#include <linux/of_gpio.h> 15#include <linux/of_gpio.h>
16#include <linux/gpio/consumer.h> 16#include <linux/gpio/consumer.h>
17 17
18#define AT803X_SPECIFIC_STATUS 0x11
19#define AT803X_SS_SPEED_MASK (3 << 14)
20#define AT803X_SS_SPEED_1000 (2 << 14)
21#define AT803X_SS_SPEED_100 (1 << 14)
22#define AT803X_SS_SPEED_10 (0 << 14)
23#define AT803X_SS_DUPLEX BIT(13)
24#define AT803X_SS_SPEED_DUPLEX_RESOLVED BIT(11)
25#define AT803X_SS_MDIX BIT(6)
26
18#define AT803X_INTR_ENABLE 0x12 27#define AT803X_INTR_ENABLE 0x12
19#define AT803X_INTR_ENABLE_AUTONEG_ERR BIT(15) 28#define AT803X_INTR_ENABLE_AUTONEG_ERR BIT(15)
20#define AT803X_INTR_ENABLE_SPEED_CHANGED BIT(14) 29#define AT803X_INTR_ENABLE_SPEED_CHANGED BIT(14)
@@ -357,6 +366,64 @@ static int at803x_aneg_done(struct phy_device *phydev)
357 return aneg_done; 366 return aneg_done;
358} 367}
359 368
369static int at803x_read_status(struct phy_device *phydev)
370{
371 int ss, err, old_link = phydev->link;
372
373 /* Update the link, but return if there was an error */
374 err = genphy_update_link(phydev);
375 if (err)
376 return err;
377
378 /* why bother the PHY if nothing can have changed */
379 if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link)
380 return 0;
381
382 phydev->speed = SPEED_UNKNOWN;
383 phydev->duplex = DUPLEX_UNKNOWN;
384 phydev->pause = 0;
385 phydev->asym_pause = 0;
386
387 err = genphy_read_lpa(phydev);
388 if (err < 0)
389 return err;
390
391 /* Read the AT8035 PHY-Specific Status register, which indicates the
392 * speed and duplex that the PHY is actually using, irrespective of
393 * whether we are in autoneg mode or not.
394 */
395 ss = phy_read(phydev, AT803X_SPECIFIC_STATUS);
396 if (ss < 0)
397 return ss;
398
399 if (ss & AT803X_SS_SPEED_DUPLEX_RESOLVED) {
400 switch (ss & AT803X_SS_SPEED_MASK) {
401 case AT803X_SS_SPEED_10:
402 phydev->speed = SPEED_10;
403 break;
404 case AT803X_SS_SPEED_100:
405 phydev->speed = SPEED_100;
406 break;
407 case AT803X_SS_SPEED_1000:
408 phydev->speed = SPEED_1000;
409 break;
410 }
411 if (ss & AT803X_SS_DUPLEX)
412 phydev->duplex = DUPLEX_FULL;
413 else
414 phydev->duplex = DUPLEX_HALF;
415 if (ss & AT803X_SS_MDIX)
416 phydev->mdix = ETH_TP_MDI_X;
417 else
418 phydev->mdix = ETH_TP_MDI;
419 }
420
421 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete)
422 phy_resolve_aneg_pause(phydev);
423
424 return 0;
425}
426
360static struct phy_driver at803x_driver[] = { 427static struct phy_driver at803x_driver[] = {
361{ 428{
362 /* ATHEROS 8035 */ 429 /* ATHEROS 8035 */
@@ -370,6 +437,7 @@ static struct phy_driver at803x_driver[] = {
370 .suspend = at803x_suspend, 437 .suspend = at803x_suspend,
371 .resume = at803x_resume, 438 .resume = at803x_resume,
372 /* PHY_GBIT_FEATURES */ 439 /* PHY_GBIT_FEATURES */
440 .read_status = at803x_read_status,
373 .ack_interrupt = at803x_ack_interrupt, 441 .ack_interrupt = at803x_ack_interrupt,
374 .config_intr = at803x_config_intr, 442 .config_intr = at803x_config_intr,
375}, { 443}, {
@@ -399,6 +467,7 @@ static struct phy_driver at803x_driver[] = {
399 .suspend = at803x_suspend, 467 .suspend = at803x_suspend,
400 .resume = at803x_resume, 468 .resume = at803x_resume,
401 /* PHY_GBIT_FEATURES */ 469 /* PHY_GBIT_FEATURES */
470 .read_status = at803x_read_status,
402 .aneg_done = at803x_aneg_done, 471 .aneg_done = at803x_aneg_done,
403 .ack_interrupt = &at803x_ack_interrupt, 472 .ack_interrupt = &at803x_ack_interrupt,
404 .config_intr = &at803x_config_intr, 473 .config_intr = &at803x_config_intr,
diff --git a/drivers/net/phy/bcm7xxx.c b/drivers/net/phy/bcm7xxx.c
index 8fc33867e524..af8eabe7a6d4 100644
--- a/drivers/net/phy/bcm7xxx.c
+++ b/drivers/net/phy/bcm7xxx.c
@@ -572,6 +572,7 @@ static int bcm7xxx_28nm_probe(struct phy_device *phydev)
572 .name = _name, \ 572 .name = _name, \
573 /* PHY_BASIC_FEATURES */ \ 573 /* PHY_BASIC_FEATURES */ \
574 .flags = PHY_IS_INTERNAL, \ 574 .flags = PHY_IS_INTERNAL, \
575 .soft_reset = genphy_soft_reset, \
575 .config_init = bcm7xxx_config_init, \ 576 .config_init = bcm7xxx_config_init, \
576 .suspend = bcm7xxx_suspend, \ 577 .suspend = bcm7xxx_suspend, \
577 .resume = bcm7xxx_config_init, \ 578 .resume = bcm7xxx_config_init, \
diff --git a/drivers/net/phy/mdio_device.c b/drivers/net/phy/mdio_device.c
index e282600bd83e..c1d345c3cab3 100644
--- a/drivers/net/phy/mdio_device.c
+++ b/drivers/net/phy/mdio_device.c
@@ -121,7 +121,7 @@ void mdio_device_reset(struct mdio_device *mdiodev, int value)
121 return; 121 return;
122 122
123 if (mdiodev->reset_gpio) 123 if (mdiodev->reset_gpio)
124 gpiod_set_value(mdiodev->reset_gpio, value); 124 gpiod_set_value_cansleep(mdiodev->reset_gpio, value);
125 125
126 if (mdiodev->reset_ctrl) { 126 if (mdiodev->reset_ctrl) {
127 if (value) 127 if (value)
diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 2fea5541c35a..63dedec0433d 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -341,6 +341,35 @@ static int ksz8041_config_aneg(struct phy_device *phydev)
341 return genphy_config_aneg(phydev); 341 return genphy_config_aneg(phydev);
342} 342}
343 343
344static int ksz8051_ksz8795_match_phy_device(struct phy_device *phydev,
345 const u32 ksz_phy_id)
346{
347 int ret;
348
349 if ((phydev->phy_id & MICREL_PHY_ID_MASK) != ksz_phy_id)
350 return 0;
351
352 ret = phy_read(phydev, MII_BMSR);
353 if (ret < 0)
354 return ret;
355
356 /* KSZ8051 PHY and KSZ8794/KSZ8795/KSZ8765 switch share the same
357 * exact PHY ID. However, they can be told apart by the extended
358 * capability registers presence. The KSZ8051 PHY has them while
359 * the switch does not.
360 */
361 ret &= BMSR_ERCAP;
362 if (ksz_phy_id == PHY_ID_KSZ8051)
363 return ret;
364 else
365 return !ret;
366}
367
368static int ksz8051_match_phy_device(struct phy_device *phydev)
369{
370 return ksz8051_ksz8795_match_phy_device(phydev, PHY_ID_KSZ8051);
371}
372
344static int ksz8081_config_init(struct phy_device *phydev) 373static int ksz8081_config_init(struct phy_device *phydev)
345{ 374{
346 /* KSZPHY_OMSO_FACTORY_TEST is set at de-assertion of the reset line 375 /* KSZPHY_OMSO_FACTORY_TEST is set at de-assertion of the reset line
@@ -364,6 +393,11 @@ static int ksz8061_config_init(struct phy_device *phydev)
364 return kszphy_config_init(phydev); 393 return kszphy_config_init(phydev);
365} 394}
366 395
396static int ksz8795_match_phy_device(struct phy_device *phydev)
397{
398 return ksz8051_ksz8795_match_phy_device(phydev, PHY_ID_KSZ87XX);
399}
400
367static int ksz9021_load_values_from_of(struct phy_device *phydev, 401static int ksz9021_load_values_from_of(struct phy_device *phydev,
368 const struct device_node *of_node, 402 const struct device_node *of_node,
369 u16 reg, 403 u16 reg,
@@ -1017,8 +1051,6 @@ static struct phy_driver ksphy_driver[] = {
1017 .suspend = genphy_suspend, 1051 .suspend = genphy_suspend,
1018 .resume = genphy_resume, 1052 .resume = genphy_resume,
1019}, { 1053}, {
1020 .phy_id = PHY_ID_KSZ8051,
1021 .phy_id_mask = MICREL_PHY_ID_MASK,
1022 .name = "Micrel KSZ8051", 1054 .name = "Micrel KSZ8051",
1023 /* PHY_BASIC_FEATURES */ 1055 /* PHY_BASIC_FEATURES */
1024 .driver_data = &ksz8051_type, 1056 .driver_data = &ksz8051_type,
@@ -1029,6 +1061,7 @@ static struct phy_driver ksphy_driver[] = {
1029 .get_sset_count = kszphy_get_sset_count, 1061 .get_sset_count = kszphy_get_sset_count,
1030 .get_strings = kszphy_get_strings, 1062 .get_strings = kszphy_get_strings,
1031 .get_stats = kszphy_get_stats, 1063 .get_stats = kszphy_get_stats,
1064 .match_phy_device = ksz8051_match_phy_device,
1032 .suspend = genphy_suspend, 1065 .suspend = genphy_suspend,
1033 .resume = genphy_resume, 1066 .resume = genphy_resume,
1034}, { 1067}, {
@@ -1141,13 +1174,12 @@ static struct phy_driver ksphy_driver[] = {
1141 .suspend = genphy_suspend, 1174 .suspend = genphy_suspend,
1142 .resume = genphy_resume, 1175 .resume = genphy_resume,
1143}, { 1176}, {
1144 .phy_id = PHY_ID_KSZ8795, 1177 .name = "Micrel KSZ87XX Switch",
1145 .phy_id_mask = MICREL_PHY_ID_MASK,
1146 .name = "Micrel KSZ8795",
1147 /* PHY_BASIC_FEATURES */ 1178 /* PHY_BASIC_FEATURES */
1148 .config_init = kszphy_config_init, 1179 .config_init = kszphy_config_init,
1149 .config_aneg = ksz8873mll_config_aneg, 1180 .config_aneg = ksz8873mll_config_aneg,
1150 .read_status = ksz8873mll_read_status, 1181 .read_status = ksz8873mll_read_status,
1182 .match_phy_device = ksz8795_match_phy_device,
1151 .suspend = genphy_suspend, 1183 .suspend = genphy_suspend,
1152 .resume = genphy_resume, 1184 .resume = genphy_resume,
1153}, { 1185}, {
diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c
index 7935593debb1..a1caeee12236 100644
--- a/drivers/net/phy/phy-c45.c
+++ b/drivers/net/phy/phy-c45.c
@@ -323,6 +323,8 @@ int genphy_c45_read_pma(struct phy_device *phydev)
323{ 323{
324 int val; 324 int val;
325 325
326 linkmode_zero(phydev->lp_advertising);
327
326 val = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_CTRL1); 328 val = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_CTRL1);
327 if (val < 0) 329 if (val < 0)
328 return val; 330 return val;
diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
index 369903d9b6ec..9412669b579c 100644
--- a/drivers/net/phy/phy-core.c
+++ b/drivers/net/phy/phy-core.c
@@ -283,6 +283,18 @@ void of_set_phy_eee_broken(struct phy_device *phydev)
283 phydev->eee_broken_modes = broken; 283 phydev->eee_broken_modes = broken;
284} 284}
285 285
286void phy_resolve_aneg_pause(struct phy_device *phydev)
287{
288 if (phydev->duplex == DUPLEX_FULL) {
289 phydev->pause = linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT,
290 phydev->lp_advertising);
291 phydev->asym_pause = linkmode_test_bit(
292 ETHTOOL_LINK_MODE_Asym_Pause_BIT,
293 phydev->lp_advertising);
294 }
295}
296EXPORT_SYMBOL_GPL(phy_resolve_aneg_pause);
297
286/** 298/**
287 * phy_resolve_aneg_linkmode - resolve the advertisements into phy settings 299 * phy_resolve_aneg_linkmode - resolve the advertisements into phy settings
288 * @phydev: The phy_device struct 300 * @phydev: The phy_device struct
@@ -305,13 +317,7 @@ void phy_resolve_aneg_linkmode(struct phy_device *phydev)
305 break; 317 break;
306 } 318 }
307 319
308 if (phydev->duplex == DUPLEX_FULL) { 320 phy_resolve_aneg_pause(phydev);
309 phydev->pause = linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT,
310 phydev->lp_advertising);
311 phydev->asym_pause = linkmode_test_bit(
312 ETHTOOL_LINK_MODE_Asym_Pause_BIT,
313 phydev->lp_advertising);
314 }
315} 321}
316EXPORT_SYMBOL_GPL(phy_resolve_aneg_linkmode); 322EXPORT_SYMBOL_GPL(phy_resolve_aneg_linkmode);
317 323
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 7c92afd36bbe..105d389b58e7 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -457,6 +457,11 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
457 val); 457 val);
458 change_autoneg = true; 458 change_autoneg = true;
459 break; 459 break;
460 case MII_CTRL1000:
461 mii_ctrl1000_mod_linkmode_adv_t(phydev->advertising,
462 val);
463 change_autoneg = true;
464 break;
460 default: 465 default:
461 /* do nothing */ 466 /* do nothing */
462 break; 467 break;
@@ -567,9 +572,6 @@ int phy_start_aneg(struct phy_device *phydev)
567 if (AUTONEG_DISABLE == phydev->autoneg) 572 if (AUTONEG_DISABLE == phydev->autoneg)
568 phy_sanitize_settings(phydev); 573 phy_sanitize_settings(phydev);
569 574
570 /* Invalidate LP advertising flags */
571 linkmode_zero(phydev->lp_advertising);
572
573 err = phy_config_aneg(phydev); 575 err = phy_config_aneg(phydev);
574 if (err < 0) 576 if (err < 0)
575 goto out_unlock; 577 goto out_unlock;
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index d347ddcac45b..adb66a2fae18 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1783,34 +1783,18 @@ done:
1783} 1783}
1784EXPORT_SYMBOL(genphy_update_link); 1784EXPORT_SYMBOL(genphy_update_link);
1785 1785
1786/** 1786int genphy_read_lpa(struct phy_device *phydev)
1787 * genphy_read_status - check the link status and update current link state
1788 * @phydev: target phy_device struct
1789 *
1790 * Description: Check the link, then figure out the current state
1791 * by comparing what we advertise with what the link partner
1792 * advertises. Start by checking the gigabit possibilities,
1793 * then move on to 10/100.
1794 */
1795int genphy_read_status(struct phy_device *phydev)
1796{ 1787{
1797 int lpa, lpagb, err, old_link = phydev->link; 1788 int lpa, lpagb;
1798
1799 /* Update the link, but return if there was an error */
1800 err = genphy_update_link(phydev);
1801 if (err)
1802 return err;
1803
1804 /* why bother the PHY if nothing can have changed */
1805 if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link)
1806 return 0;
1807 1789
1808 phydev->speed = SPEED_UNKNOWN; 1790 if (phydev->autoneg == AUTONEG_ENABLE) {
1809 phydev->duplex = DUPLEX_UNKNOWN; 1791 if (!phydev->autoneg_complete) {
1810 phydev->pause = 0; 1792 mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising,
1811 phydev->asym_pause = 0; 1793 0);
1794 mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, 0);
1795 return 0;
1796 }
1812 1797
1813 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) {
1814 if (phydev->is_gigabit_capable) { 1798 if (phydev->is_gigabit_capable) {
1815 lpagb = phy_read(phydev, MII_STAT1000); 1799 lpagb = phy_read(phydev, MII_STAT1000);
1816 if (lpagb < 0) 1800 if (lpagb < 0)
@@ -1838,6 +1822,46 @@ int genphy_read_status(struct phy_device *phydev)
1838 return lpa; 1822 return lpa;
1839 1823
1840 mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, lpa); 1824 mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, lpa);
1825 } else {
1826 linkmode_zero(phydev->lp_advertising);
1827 }
1828
1829 return 0;
1830}
1831EXPORT_SYMBOL(genphy_read_lpa);
1832
1833/**
1834 * genphy_read_status - check the link status and update current link state
1835 * @phydev: target phy_device struct
1836 *
1837 * Description: Check the link, then figure out the current state
1838 * by comparing what we advertise with what the link partner
1839 * advertises. Start by checking the gigabit possibilities,
1840 * then move on to 10/100.
1841 */
1842int genphy_read_status(struct phy_device *phydev)
1843{
1844 int err, old_link = phydev->link;
1845
1846 /* Update the link, but return if there was an error */
1847 err = genphy_update_link(phydev);
1848 if (err)
1849 return err;
1850
1851 /* why bother the PHY if nothing can have changed */
1852 if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link)
1853 return 0;
1854
1855 phydev->speed = SPEED_UNKNOWN;
1856 phydev->duplex = DUPLEX_UNKNOWN;
1857 phydev->pause = 0;
1858 phydev->asym_pause = 0;
1859
1860 err = genphy_read_lpa(phydev);
1861 if (err < 0)
1862 return err;
1863
1864 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) {
1841 phy_resolve_aneg_linkmode(phydev); 1865 phy_resolve_aneg_linkmode(phydev);
1842 } else if (phydev->autoneg == AUTONEG_DISABLE) { 1866 } else if (phydev->autoneg == AUTONEG_DISABLE) {
1843 int bmcr = phy_read(phydev, MII_BMCR); 1867 int bmcr = phy_read(phydev, MII_BMCR);
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index a5a57ca94c1a..20e2ebe458f2 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -576,7 +576,7 @@ static int phylink_register_sfp(struct phylink *pl,
576 576
577/** 577/**
578 * phylink_create() - create a phylink instance 578 * phylink_create() - create a phylink instance
579 * @ndev: a pointer to the &struct net_device 579 * @config: a pointer to the target &struct phylink_config
580 * @fwnode: a pointer to a &struct fwnode_handle describing the network 580 * @fwnode: a pointer to a &struct fwnode_handle describing the network
581 * interface 581 * interface
582 * @iface: the desired link mode defined by &typedef phy_interface_t 582 * @iface: the desired link mode defined by &typedef phy_interface_t
diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c
index dc3d92d340c4..b73298250793 100644
--- a/drivers/net/phy/smsc.c
+++ b/drivers/net/phy/smsc.c
@@ -327,6 +327,7 @@ static struct phy_driver smsc_phy_driver[] = {
327 .name = "SMSC LAN8740", 327 .name = "SMSC LAN8740",
328 328
329 /* PHY_BASIC_FEATURES */ 329 /* PHY_BASIC_FEATURES */
330 .flags = PHY_RST_AFTER_CLK_EN,
330 331
331 .probe = smsc_phy_probe, 332 .probe = smsc_phy_probe,
332 333
diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
index 9a1b006904a7..61824bbb5588 100644
--- a/drivers/net/ppp/ppp_generic.c
+++ b/drivers/net/ppp/ppp_generic.c
@@ -1324,8 +1324,6 @@ static int ppp_dev_init(struct net_device *dev)
1324{ 1324{
1325 struct ppp *ppp; 1325 struct ppp *ppp;
1326 1326
1327 netdev_lockdep_set_classes(dev);
1328
1329 ppp = netdev_priv(dev); 1327 ppp = netdev_priv(dev);
1330 /* Let the netdevice take a reference on the ppp file. This ensures 1328 /* Let the netdevice take a reference on the ppp file. This ensures
1331 * that ppp_destroy_interface() won't run before the device gets 1329 * that ppp_destroy_interface() won't run before the device gets
diff --git a/drivers/net/ppp/pptp.c b/drivers/net/ppp/pptp.c
index 734de7de03f7..e1fabb3e3246 100644
--- a/drivers/net/ppp/pptp.c
+++ b/drivers/net/ppp/pptp.c
@@ -238,7 +238,7 @@ static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
238 skb_dst_drop(skb); 238 skb_dst_drop(skb);
239 skb_dst_set(skb, &rt->dst); 239 skb_dst_set(skb, &rt->dst);
240 240
241 nf_reset(skb); 241 nf_reset_ct(skb);
242 242
243 skb->ip_summed = CHECKSUM_NONE; 243 skb->ip_summed = CHECKSUM_NONE;
244 ip_select_ident(net, skb, NULL); 244 ip_select_ident(net, skb, NULL);
@@ -358,7 +358,7 @@ static int pptp_rcv(struct sk_buff *skb)
358 po = lookup_chan(htons(header->call_id), iph->saddr); 358 po = lookup_chan(htons(header->call_id), iph->saddr);
359 if (po) { 359 if (po) {
360 skb_dst_drop(skb); 360 skb_dst_drop(skb);
361 nf_reset(skb); 361 nf_reset_ct(skb);
362 return sk_receive_skb(sk_pppox(po), skb, 0); 362 return sk_receive_skb(sk_pppox(po), skb, 0);
363 } 363 }
364drop: 364drop:
diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
index e8089def5a46..8156b33ee3e7 100644
--- a/drivers/net/team/team.c
+++ b/drivers/net/team/team.c
@@ -1615,7 +1615,6 @@ static int team_init(struct net_device *dev)
1615 int err; 1615 int err;
1616 1616
1617 team->dev = dev; 1617 team->dev = dev;
1618 mutex_init(&team->lock);
1619 team_set_no_mode(team); 1618 team_set_no_mode(team);
1620 1619
1621 team->pcpu_stats = netdev_alloc_pcpu_stats(struct team_pcpu_stats); 1620 team->pcpu_stats = netdev_alloc_pcpu_stats(struct team_pcpu_stats);
@@ -1642,7 +1641,8 @@ static int team_init(struct net_device *dev)
1642 goto err_options_register; 1641 goto err_options_register;
1643 netif_carrier_off(dev); 1642 netif_carrier_off(dev);
1644 1643
1645 netdev_lockdep_set_classes(dev); 1644 lockdep_register_key(&team->team_lock_key);
1645 __mutex_init(&team->lock, "team->team_lock_key", &team->team_lock_key);
1646 1646
1647 return 0; 1647 return 0;
1648 1648
@@ -1673,6 +1673,7 @@ static void team_uninit(struct net_device *dev)
1673 team_queue_override_fini(team); 1673 team_queue_override_fini(team);
1674 mutex_unlock(&team->lock); 1674 mutex_unlock(&team->lock);
1675 netdev_change_features(dev); 1675 netdev_change_features(dev);
1676 lockdep_unregister_key(&team->team_lock_key);
1676} 1677}
1677 1678
1678static void team_destructor(struct net_device *dev) 1679static void team_destructor(struct net_device *dev)
@@ -1976,8 +1977,15 @@ static int team_del_slave(struct net_device *dev, struct net_device *port_dev)
1976 err = team_port_del(team, port_dev); 1977 err = team_port_del(team, port_dev);
1977 mutex_unlock(&team->lock); 1978 mutex_unlock(&team->lock);
1978 1979
1979 if (!err) 1980 if (err)
1980 netdev_change_features(dev); 1981 return err;
1982
1983 if (netif_is_team_master(port_dev)) {
1984 lockdep_unregister_key(&team->team_lock_key);
1985 lockdep_register_key(&team->team_lock_key);
1986 lockdep_set_class(&team->lock, &team->team_lock_key);
1987 }
1988 netdev_change_features(dev);
1981 1989
1982 return err; 1990 return err;
1983} 1991}
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index aab0be40d443..a8d3141582a5 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -526,8 +526,8 @@ static void tun_flow_update(struct tun_struct *tun, u32 rxhash,
526 e = tun_flow_find(head, rxhash); 526 e = tun_flow_find(head, rxhash);
527 if (likely(e)) { 527 if (likely(e)) {
528 /* TODO: keep queueing to old queue until it's empty? */ 528 /* TODO: keep queueing to old queue until it's empty? */
529 if (e->queue_index != queue_index) 529 if (READ_ONCE(e->queue_index) != queue_index)
530 e->queue_index = queue_index; 530 WRITE_ONCE(e->queue_index, queue_index);
531 if (e->updated != jiffies) 531 if (e->updated != jiffies)
532 e->updated = jiffies; 532 e->updated = jiffies;
533 sock_rps_record_flow_hash(e->rps_rxhash); 533 sock_rps_record_flow_hash(e->rps_rxhash);
@@ -1104,7 +1104,7 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev)
1104 */ 1104 */
1105 skb_orphan(skb); 1105 skb_orphan(skb);
1106 1106
1107 nf_reset(skb); 1107 nf_reset_ct(skb);
1108 1108
1109 if (ptr_ring_produce(&tfile->tx_ring, skb)) 1109 if (ptr_ring_produce(&tfile->tx_ring, skb))
1110 goto drop; 1110 goto drop;
diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c
index 32f53de5b1fe..fe630438f67b 100644
--- a/drivers/net/usb/cdc_ether.c
+++ b/drivers/net/usb/cdc_ether.c
@@ -787,6 +787,13 @@ static const struct usb_device_id products[] = {
787 .driver_info = 0, 787 .driver_info = 0,
788}, 788},
789 789
790/* ThinkPad USB-C Dock Gen 2 (based on Realtek RTL8153) */
791{
792 USB_DEVICE_AND_INTERFACE_INFO(LENOVO_VENDOR_ID, 0xa387, USB_CLASS_COMM,
793 USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
794 .driver_info = 0,
795},
796
790/* NVIDIA Tegra USB 3.0 Ethernet Adapters (based on Realtek RTL8153) */ 797/* NVIDIA Tegra USB 3.0 Ethernet Adapters (based on Realtek RTL8153) */
791{ 798{
792 USB_DEVICE_AND_INTERFACE_INFO(NVIDIA_VENDOR_ID, 0x09ff, USB_CLASS_COMM, 799 USB_DEVICE_AND_INTERFACE_INFO(NVIDIA_VENDOR_ID, 0x09ff, USB_CLASS_COMM,
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index ce78714f536f..74849da031fa 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -186,7 +186,7 @@ struct hso_tiocmget {
186 int intr_completed; 186 int intr_completed;
187 struct usb_endpoint_descriptor *endp; 187 struct usb_endpoint_descriptor *endp;
188 struct urb *urb; 188 struct urb *urb;
189 struct hso_serial_state_notification serial_state_notification; 189 struct hso_serial_state_notification *serial_state_notification;
190 u16 prev_UART_state_bitmap; 190 u16 prev_UART_state_bitmap;
191 struct uart_icount icount; 191 struct uart_icount icount;
192}; 192};
@@ -1432,7 +1432,7 @@ static int tiocmget_submit_urb(struct hso_serial *serial,
1432 usb_rcvintpipe(usb, 1432 usb_rcvintpipe(usb,
1433 tiocmget->endp-> 1433 tiocmget->endp->
1434 bEndpointAddress & 0x7F), 1434 bEndpointAddress & 0x7F),
1435 &tiocmget->serial_state_notification, 1435 tiocmget->serial_state_notification,
1436 sizeof(struct hso_serial_state_notification), 1436 sizeof(struct hso_serial_state_notification),
1437 tiocmget_intr_callback, serial, 1437 tiocmget_intr_callback, serial,
1438 tiocmget->endp->bInterval); 1438 tiocmget->endp->bInterval);
@@ -1479,7 +1479,7 @@ static void tiocmget_intr_callback(struct urb *urb)
1479 /* wIndex should be the USB interface number of the port to which the 1479 /* wIndex should be the USB interface number of the port to which the
1480 * notification applies, which should always be the Modem port. 1480 * notification applies, which should always be the Modem port.
1481 */ 1481 */
1482 serial_state_notification = &tiocmget->serial_state_notification; 1482 serial_state_notification = tiocmget->serial_state_notification;
1483 if (serial_state_notification->bmRequestType != BM_REQUEST_TYPE || 1483 if (serial_state_notification->bmRequestType != BM_REQUEST_TYPE ||
1484 serial_state_notification->bNotification != B_NOTIFICATION || 1484 serial_state_notification->bNotification != B_NOTIFICATION ||
1485 le16_to_cpu(serial_state_notification->wValue) != W_VALUE || 1485 le16_to_cpu(serial_state_notification->wValue) != W_VALUE ||
@@ -2565,6 +2565,8 @@ static void hso_free_tiomget(struct hso_serial *serial)
2565 usb_free_urb(tiocmget->urb); 2565 usb_free_urb(tiocmget->urb);
2566 tiocmget->urb = NULL; 2566 tiocmget->urb = NULL;
2567 serial->tiocmget = NULL; 2567 serial->tiocmget = NULL;
2568 kfree(tiocmget->serial_state_notification);
2569 tiocmget->serial_state_notification = NULL;
2568 kfree(tiocmget); 2570 kfree(tiocmget);
2569 } 2571 }
2570} 2572}
@@ -2615,19 +2617,26 @@ static struct hso_device *hso_create_bulk_serial_device(
2615 num_urbs = 2; 2617 num_urbs = 2;
2616 serial->tiocmget = kzalloc(sizeof(struct hso_tiocmget), 2618 serial->tiocmget = kzalloc(sizeof(struct hso_tiocmget),
2617 GFP_KERNEL); 2619 GFP_KERNEL);
2620 serial->tiocmget->serial_state_notification
2621 = kzalloc(sizeof(struct hso_serial_state_notification),
2622 GFP_KERNEL);
2618 /* it isn't going to break our heart if serial->tiocmget 2623 /* it isn't going to break our heart if serial->tiocmget
2619 * allocation fails don't bother checking this. 2624 * allocation fails don't bother checking this.
2620 */ 2625 */
2621 if (serial->tiocmget) { 2626 if (serial->tiocmget && serial->tiocmget->serial_state_notification) {
2622 tiocmget = serial->tiocmget; 2627 tiocmget = serial->tiocmget;
2628 tiocmget->endp = hso_get_ep(interface,
2629 USB_ENDPOINT_XFER_INT,
2630 USB_DIR_IN);
2631 if (!tiocmget->endp) {
2632 dev_err(&interface->dev, "Failed to find INT IN ep\n");
2633 goto exit;
2634 }
2635
2623 tiocmget->urb = usb_alloc_urb(0, GFP_KERNEL); 2636 tiocmget->urb = usb_alloc_urb(0, GFP_KERNEL);
2624 if (tiocmget->urb) { 2637 if (tiocmget->urb) {
2625 mutex_init(&tiocmget->mutex); 2638 mutex_init(&tiocmget->mutex);
2626 init_waitqueue_head(&tiocmget->waitq); 2639 init_waitqueue_head(&tiocmget->waitq);
2627 tiocmget->endp = hso_get_ep(
2628 interface,
2629 USB_ENDPOINT_XFER_INT,
2630 USB_DIR_IN);
2631 } else 2640 } else
2632 hso_free_tiomget(serial); 2641 hso_free_tiomget(serial);
2633 } 2642 }
diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
index 58f5a219fb65..f24a1b0b801f 100644
--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -1264,8 +1264,11 @@ static void lan78xx_status(struct lan78xx_net *dev, struct urb *urb)
1264 netif_dbg(dev, link, dev->net, "PHY INTR: 0x%08x\n", intdata); 1264 netif_dbg(dev, link, dev->net, "PHY INTR: 0x%08x\n", intdata);
1265 lan78xx_defer_kevent(dev, EVENT_LINK_RESET); 1265 lan78xx_defer_kevent(dev, EVENT_LINK_RESET);
1266 1266
1267 if (dev->domain_data.phyirq > 0) 1267 if (dev->domain_data.phyirq > 0) {
1268 local_irq_disable();
1268 generic_handle_irq(dev->domain_data.phyirq); 1269 generic_handle_irq(dev->domain_data.phyirq);
1270 local_irq_enable();
1271 }
1269 } else 1272 } else
1270 netdev_warn(dev->net, 1273 netdev_warn(dev->net,
1271 "unexpected interrupt: 0x%08x\n", intdata); 1274 "unexpected interrupt: 0x%08x\n", intdata);
@@ -3782,10 +3785,14 @@ static int lan78xx_probe(struct usb_interface *intf,
3782 /* driver requires remote-wakeup capability during autosuspend. */ 3785 /* driver requires remote-wakeup capability during autosuspend. */
3783 intf->needs_remote_wakeup = 1; 3786 intf->needs_remote_wakeup = 1;
3784 3787
3788 ret = lan78xx_phy_init(dev);
3789 if (ret < 0)
3790 goto out4;
3791
3785 ret = register_netdev(netdev); 3792 ret = register_netdev(netdev);
3786 if (ret != 0) { 3793 if (ret != 0) {
3787 netif_err(dev, probe, netdev, "couldn't register the device\n"); 3794 netif_err(dev, probe, netdev, "couldn't register the device\n");
3788 goto out4; 3795 goto out5;
3789 } 3796 }
3790 3797
3791 usb_set_intfdata(intf, dev); 3798 usb_set_intfdata(intf, dev);
@@ -3798,14 +3805,10 @@ static int lan78xx_probe(struct usb_interface *intf,
3798 pm_runtime_set_autosuspend_delay(&udev->dev, 3805 pm_runtime_set_autosuspend_delay(&udev->dev,
3799 DEFAULT_AUTOSUSPEND_DELAY); 3806 DEFAULT_AUTOSUSPEND_DELAY);
3800 3807
3801 ret = lan78xx_phy_init(dev);
3802 if (ret < 0)
3803 goto out5;
3804
3805 return 0; 3808 return 0;
3806 3809
3807out5: 3810out5:
3808 unregister_netdev(netdev); 3811 phy_disconnect(netdev->phydev);
3809out4: 3812out4:
3810 usb_free_urb(dev->urb_intr); 3813 usb_free_urb(dev->urb_intr);
3811out3: 3814out3:
diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index b6dc5d714b5e..596428ec71df 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -1327,6 +1327,7 @@ static const struct usb_device_id products[] = {
1327 {QMI_FIXED_INTF(0x2357, 0x0201, 4)}, /* TP-LINK HSUPA Modem MA180 */ 1327 {QMI_FIXED_INTF(0x2357, 0x0201, 4)}, /* TP-LINK HSUPA Modem MA180 */
1328 {QMI_FIXED_INTF(0x2357, 0x9000, 4)}, /* TP-LINK MA260 */ 1328 {QMI_FIXED_INTF(0x2357, 0x9000, 4)}, /* TP-LINK MA260 */
1329 {QMI_QUIRK_SET_DTR(0x1bc7, 0x1040, 2)}, /* Telit LE922A */ 1329 {QMI_QUIRK_SET_DTR(0x1bc7, 0x1040, 2)}, /* Telit LE922A */
1330 {QMI_QUIRK_SET_DTR(0x1bc7, 0x1050, 2)}, /* Telit FN980 */
1330 {QMI_FIXED_INTF(0x1bc7, 0x1100, 3)}, /* Telit ME910 */ 1331 {QMI_FIXED_INTF(0x1bc7, 0x1100, 3)}, /* Telit ME910 */
1331 {QMI_FIXED_INTF(0x1bc7, 0x1101, 3)}, /* Telit ME910 dual modem */ 1332 {QMI_FIXED_INTF(0x1bc7, 0x1101, 3)}, /* Telit ME910 dual modem */
1332 {QMI_FIXED_INTF(0x1bc7, 0x1200, 5)}, /* Telit LE920 */ 1333 {QMI_FIXED_INTF(0x1bc7, 0x1200, 5)}, /* Telit LE920 */
@@ -1350,6 +1351,7 @@ static const struct usb_device_id products[] = {
1350 {QMI_FIXED_INTF(0x1e2d, 0x0082, 4)}, /* Cinterion PHxx,PXxx (2 RmNet) */ 1351 {QMI_FIXED_INTF(0x1e2d, 0x0082, 4)}, /* Cinterion PHxx,PXxx (2 RmNet) */
1351 {QMI_FIXED_INTF(0x1e2d, 0x0082, 5)}, /* Cinterion PHxx,PXxx (2 RmNet) */ 1352 {QMI_FIXED_INTF(0x1e2d, 0x0082, 5)}, /* Cinterion PHxx,PXxx (2 RmNet) */
1352 {QMI_FIXED_INTF(0x1e2d, 0x0083, 4)}, /* Cinterion PHxx,PXxx (1 RmNet + USB Audio)*/ 1353 {QMI_FIXED_INTF(0x1e2d, 0x0083, 4)}, /* Cinterion PHxx,PXxx (1 RmNet + USB Audio)*/
1354 {QMI_QUIRK_SET_DTR(0x1e2d, 0x00b0, 4)}, /* Cinterion CLS8 */
1353 {QMI_FIXED_INTF(0x413c, 0x81a2, 8)}, /* Dell Wireless 5806 Gobi(TM) 4G LTE Mobile Broadband Card */ 1355 {QMI_FIXED_INTF(0x413c, 0x81a2, 8)}, /* Dell Wireless 5806 Gobi(TM) 4G LTE Mobile Broadband Card */
1354 {QMI_FIXED_INTF(0x413c, 0x81a3, 8)}, /* Dell Wireless 5570 HSPA+ (42Mbps) Mobile Broadband Card */ 1356 {QMI_FIXED_INTF(0x413c, 0x81a3, 8)}, /* Dell Wireless 5570 HSPA+ (42Mbps) Mobile Broadband Card */
1355 {QMI_FIXED_INTF(0x413c, 0x81a4, 8)}, /* Dell Wireless 5570e HSPA+ (42Mbps) Mobile Broadband Card */ 1357 {QMI_FIXED_INTF(0x413c, 0x81a4, 8)}, /* Dell Wireless 5570e HSPA+ (42Mbps) Mobile Broadband Card */
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 08726090570e..d4a95b50bda6 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -4799,10 +4799,9 @@ static int rtl8152_reset_resume(struct usb_interface *intf)
4799 struct r8152 *tp = usb_get_intfdata(intf); 4799 struct r8152 *tp = usb_get_intfdata(intf);
4800 4800
4801 clear_bit(SELECTIVE_SUSPEND, &tp->flags); 4801 clear_bit(SELECTIVE_SUSPEND, &tp->flags);
4802 mutex_lock(&tp->control);
4803 tp->rtl_ops.init(tp); 4802 tp->rtl_ops.init(tp);
4804 queue_delayed_work(system_long_wq, &tp->hw_phy_work, 0); 4803 queue_delayed_work(system_long_wq, &tp->hw_phy_work, 0);
4805 mutex_unlock(&tp->control); 4804 set_ethernet_addr(tp);
4806 return rtl8152_resume(intf); 4805 return rtl8152_resume(intf);
4807} 4806}
4808 4807
@@ -5756,6 +5755,7 @@ static const struct usb_device_id rtl8152_table[] = {
5756 {REALTEK_USB_DEVICE(VENDOR_ID_LENOVO, 0x7205)}, 5755 {REALTEK_USB_DEVICE(VENDOR_ID_LENOVO, 0x7205)},
5757 {REALTEK_USB_DEVICE(VENDOR_ID_LENOVO, 0x720c)}, 5756 {REALTEK_USB_DEVICE(VENDOR_ID_LENOVO, 0x720c)},
5758 {REALTEK_USB_DEVICE(VENDOR_ID_LENOVO, 0x7214)}, 5757 {REALTEK_USB_DEVICE(VENDOR_ID_LENOVO, 0x7214)},
5758 {REALTEK_USB_DEVICE(VENDOR_ID_LENOVO, 0xa387)},
5759 {REALTEK_USB_DEVICE(VENDOR_ID_LINKSYS, 0x0041)}, 5759 {REALTEK_USB_DEVICE(VENDOR_ID_LINKSYS, 0x0041)},
5760 {REALTEK_USB_DEVICE(VENDOR_ID_NVIDIA, 0x09ff)}, 5760 {REALTEK_USB_DEVICE(VENDOR_ID_NVIDIA, 0x09ff)},
5761 {REALTEK_USB_DEVICE(VENDOR_ID_TPLINK, 0x0601)}, 5761 {REALTEK_USB_DEVICE(VENDOR_ID_TPLINK, 0x0601)},
diff --git a/drivers/net/usb/sr9800.c b/drivers/net/usb/sr9800.c
index c5d4a0060124..681e0def6356 100644
--- a/drivers/net/usb/sr9800.c
+++ b/drivers/net/usb/sr9800.c
@@ -335,7 +335,7 @@ static void sr_set_multicast(struct net_device *net)
335static int sr_mdio_read(struct net_device *net, int phy_id, int loc) 335static int sr_mdio_read(struct net_device *net, int phy_id, int loc)
336{ 336{
337 struct usbnet *dev = netdev_priv(net); 337 struct usbnet *dev = netdev_priv(net);
338 __le16 res; 338 __le16 res = 0;
339 339
340 mutex_lock(&dev->phy_mutex); 340 mutex_lock(&dev->phy_mutex);
341 sr_set_sw_mii(dev); 341 sr_set_sw_mii(dev);
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index ba98e0971b84..5a635f028bdc 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1585,7 +1585,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
1585 /* Don't wait up for transmitted skbs to be freed. */ 1585 /* Don't wait up for transmitted skbs to be freed. */
1586 if (!use_napi) { 1586 if (!use_napi) {
1587 skb_orphan(skb); 1587 skb_orphan(skb);
1588 nf_reset(skb); 1588 nf_reset_ct(skb);
1589 } 1589 }
1590 1590
1591 /* If running out of space, stop queue to avoid getting packets that we 1591 /* If running out of space, stop queue to avoid getting packets that we
diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
index a4b38a980c3c..b8228f50bc94 100644
--- a/drivers/net/vrf.c
+++ b/drivers/net/vrf.c
@@ -366,7 +366,7 @@ static int vrf_finish_output6(struct net *net, struct sock *sk,
366 struct neighbour *neigh; 366 struct neighbour *neigh;
367 int ret; 367 int ret;
368 368
369 nf_reset(skb); 369 nf_reset_ct(skb);
370 370
371 skb->protocol = htons(ETH_P_IPV6); 371 skb->protocol = htons(ETH_P_IPV6);
372 skb->dev = dev; 372 skb->dev = dev;
@@ -459,7 +459,7 @@ static struct sk_buff *vrf_ip6_out_direct(struct net_device *vrf_dev,
459 459
460 /* reset skb device */ 460 /* reset skb device */
461 if (likely(err == 1)) 461 if (likely(err == 1))
462 nf_reset(skb); 462 nf_reset_ct(skb);
463 else 463 else
464 skb = NULL; 464 skb = NULL;
465 465
@@ -560,7 +560,7 @@ static int vrf_finish_output(struct net *net, struct sock *sk, struct sk_buff *s
560 bool is_v6gw = false; 560 bool is_v6gw = false;
561 int ret = -EINVAL; 561 int ret = -EINVAL;
562 562
563 nf_reset(skb); 563 nf_reset_ct(skb);
564 564
565 /* Be paranoid, rather than too clever. */ 565 /* Be paranoid, rather than too clever. */
566 if (unlikely(skb_headroom(skb) < hh_len && dev->header_ops)) { 566 if (unlikely(skb_headroom(skb) < hh_len && dev->header_ops)) {
@@ -670,7 +670,7 @@ static struct sk_buff *vrf_ip_out_direct(struct net_device *vrf_dev,
670 670
671 /* reset skb device */ 671 /* reset skb device */
672 if (likely(err == 1)) 672 if (likely(err == 1))
673 nf_reset(skb); 673 nf_reset_ct(skb);
674 else 674 else
675 skb = NULL; 675 skb = NULL;
676 676
@@ -865,7 +865,6 @@ static int vrf_dev_init(struct net_device *dev)
865 865
866 /* similarly, oper state is irrelevant; set to up to avoid confusion */ 866 /* similarly, oper state is irrelevant; set to up to avoid confusion */
867 dev->operstate = IF_OPER_UP; 867 dev->operstate = IF_OPER_UP;
868 netdev_lockdep_set_classes(dev);
869 return 0; 868 return 0;
870 869
871out_rth: 870out_rth:
diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index 3d9bcc957f7d..8869154fad88 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -2487,9 +2487,11 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
2487 vni = tunnel_id_to_key32(info->key.tun_id); 2487 vni = tunnel_id_to_key32(info->key.tun_id);
2488 ifindex = 0; 2488 ifindex = 0;
2489 dst_cache = &info->dst_cache; 2489 dst_cache = &info->dst_cache;
2490 if (info->options_len && 2490 if (info->key.tun_flags & TUNNEL_VXLAN_OPT) {
2491 info->key.tun_flags & TUNNEL_VXLAN_OPT) 2491 if (info->options_len < sizeof(*md))
2492 goto drop;
2492 md = ip_tunnel_info_opts(info); 2493 md = ip_tunnel_info_opts(info);
2494 }
2493 ttl = info->key.ttl; 2495 ttl = info->key.ttl;
2494 tos = info->key.tos; 2496 tos = info->key.tos;
2495 label = info->key.label; 2497 label = info->key.label;
@@ -3566,10 +3568,13 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev,
3566{ 3568{
3567 struct vxlan_net *vn = net_generic(net, vxlan_net_id); 3569 struct vxlan_net *vn = net_generic(net, vxlan_net_id);
3568 struct vxlan_dev *vxlan = netdev_priv(dev); 3570 struct vxlan_dev *vxlan = netdev_priv(dev);
3571 struct net_device *remote_dev = NULL;
3569 struct vxlan_fdb *f = NULL; 3572 struct vxlan_fdb *f = NULL;
3570 bool unregister = false; 3573 bool unregister = false;
3574 struct vxlan_rdst *dst;
3571 int err; 3575 int err;
3572 3576
3577 dst = &vxlan->default_dst;
3573 err = vxlan_dev_configure(net, dev, conf, false, extack); 3578 err = vxlan_dev_configure(net, dev, conf, false, extack);
3574 if (err) 3579 if (err)
3575 return err; 3580 return err;
@@ -3577,14 +3582,14 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev,
3577 dev->ethtool_ops = &vxlan_ethtool_ops; 3582 dev->ethtool_ops = &vxlan_ethtool_ops;
3578 3583
3579 /* create an fdb entry for a valid default destination */ 3584 /* create an fdb entry for a valid default destination */
3580 if (!vxlan_addr_any(&vxlan->default_dst.remote_ip)) { 3585 if (!vxlan_addr_any(&dst->remote_ip)) {
3581 err = vxlan_fdb_create(vxlan, all_zeros_mac, 3586 err = vxlan_fdb_create(vxlan, all_zeros_mac,
3582 &vxlan->default_dst.remote_ip, 3587 &dst->remote_ip,
3583 NUD_REACHABLE | NUD_PERMANENT, 3588 NUD_REACHABLE | NUD_PERMANENT,
3584 vxlan->cfg.dst_port, 3589 vxlan->cfg.dst_port,
3585 vxlan->default_dst.remote_vni, 3590 dst->remote_vni,
3586 vxlan->default_dst.remote_vni, 3591 dst->remote_vni,
3587 vxlan->default_dst.remote_ifindex, 3592 dst->remote_ifindex,
3588 NTF_SELF, &f); 3593 NTF_SELF, &f);
3589 if (err) 3594 if (err)
3590 return err; 3595 return err;
@@ -3595,26 +3600,41 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev,
3595 goto errout; 3600 goto errout;
3596 unregister = true; 3601 unregister = true;
3597 3602
3603 if (dst->remote_ifindex) {
3604 remote_dev = __dev_get_by_index(net, dst->remote_ifindex);
3605 if (!remote_dev)
3606 goto errout;
3607
3608 err = netdev_upper_dev_link(remote_dev, dev, extack);
3609 if (err)
3610 goto errout;
3611 }
3612
3598 err = rtnl_configure_link(dev, NULL); 3613 err = rtnl_configure_link(dev, NULL);
3599 if (err) 3614 if (err)
3600 goto errout; 3615 goto unlink;
3601 3616
3602 if (f) { 3617 if (f) {
3603 vxlan_fdb_insert(vxlan, all_zeros_mac, 3618 vxlan_fdb_insert(vxlan, all_zeros_mac, dst->remote_vni, f);
3604 vxlan->default_dst.remote_vni, f);
3605 3619
3606 /* notify default fdb entry */ 3620 /* notify default fdb entry */
3607 err = vxlan_fdb_notify(vxlan, f, first_remote_rtnl(f), 3621 err = vxlan_fdb_notify(vxlan, f, first_remote_rtnl(f),
3608 RTM_NEWNEIGH, true, extack); 3622 RTM_NEWNEIGH, true, extack);
3609 if (err) { 3623 if (err) {
3610 vxlan_fdb_destroy(vxlan, f, false, false); 3624 vxlan_fdb_destroy(vxlan, f, false, false);
3625 if (remote_dev)
3626 netdev_upper_dev_unlink(remote_dev, dev);
3611 goto unregister; 3627 goto unregister;
3612 } 3628 }
3613 } 3629 }
3614 3630
3615 list_add(&vxlan->next, &vn->vxlan_list); 3631 list_add(&vxlan->next, &vn->vxlan_list);
3632 if (remote_dev)
3633 dst->remote_dev = remote_dev;
3616 return 0; 3634 return 0;
3617 3635unlink:
3636 if (remote_dev)
3637 netdev_upper_dev_unlink(remote_dev, dev);
3618errout: 3638errout:
3619 /* unregister_netdevice() destroys the default FDB entry with deletion 3639 /* unregister_netdevice() destroys the default FDB entry with deletion
3620 * notification. But the addition notification was not sent yet, so 3640 * notification. But the addition notification was not sent yet, so
@@ -3932,11 +3952,12 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
3932 struct netlink_ext_ack *extack) 3952 struct netlink_ext_ack *extack)
3933{ 3953{
3934 struct vxlan_dev *vxlan = netdev_priv(dev); 3954 struct vxlan_dev *vxlan = netdev_priv(dev);
3935 struct vxlan_rdst *dst = &vxlan->default_dst;
3936 struct net_device *lowerdev; 3955 struct net_device *lowerdev;
3937 struct vxlan_config conf; 3956 struct vxlan_config conf;
3957 struct vxlan_rdst *dst;
3938 int err; 3958 int err;
3939 3959
3960 dst = &vxlan->default_dst;
3940 err = vxlan_nl2conf(tb, data, dev, &conf, true, extack); 3961 err = vxlan_nl2conf(tb, data, dev, &conf, true, extack);
3941 if (err) 3962 if (err)
3942 return err; 3963 return err;
@@ -3946,6 +3967,14 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
3946 if (err) 3967 if (err)
3947 return err; 3968 return err;
3948 3969
3970 if (dst->remote_dev == lowerdev)
3971 lowerdev = NULL;
3972
3973 err = netdev_adjacent_change_prepare(dst->remote_dev, lowerdev, dev,
3974 extack);
3975 if (err)
3976 return err;
3977
3949 /* handle default dst entry */ 3978 /* handle default dst entry */
3950 if (!vxlan_addr_equal(&conf.remote_ip, &dst->remote_ip)) { 3979 if (!vxlan_addr_equal(&conf.remote_ip, &dst->remote_ip)) {
3951 u32 hash_index = fdb_head_index(vxlan, all_zeros_mac, conf.vni); 3980 u32 hash_index = fdb_head_index(vxlan, all_zeros_mac, conf.vni);
@@ -3962,6 +3991,8 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
3962 NTF_SELF, true, extack); 3991 NTF_SELF, true, extack);
3963 if (err) { 3992 if (err) {
3964 spin_unlock_bh(&vxlan->hash_lock[hash_index]); 3993 spin_unlock_bh(&vxlan->hash_lock[hash_index]);
3994 netdev_adjacent_change_abort(dst->remote_dev,
3995 lowerdev, dev);
3965 return err; 3996 return err;
3966 } 3997 }
3967 } 3998 }
@@ -3979,6 +4010,11 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
3979 if (conf.age_interval != vxlan->cfg.age_interval) 4010 if (conf.age_interval != vxlan->cfg.age_interval)
3980 mod_timer(&vxlan->age_timer, jiffies); 4011 mod_timer(&vxlan->age_timer, jiffies);
3981 4012
4013 netdev_adjacent_change_commit(dst->remote_dev, lowerdev, dev);
4014 if (lowerdev && lowerdev != dst->remote_dev) {
4015 dst->remote_dev = lowerdev;
4016 netdev_update_lockdep_key(lowerdev);
4017 }
3982 vxlan_config_apply(dev, &conf, lowerdev, vxlan->net, true); 4018 vxlan_config_apply(dev, &conf, lowerdev, vxlan->net, true);
3983 return 0; 4019 return 0;
3984} 4020}
@@ -3991,6 +4027,8 @@ static void vxlan_dellink(struct net_device *dev, struct list_head *head)
3991 4027
3992 list_del(&vxlan->next); 4028 list_del(&vxlan->next);
3993 unregister_netdevice_queue(dev, head); 4029 unregister_netdevice_queue(dev, head);
4030 if (vxlan->default_dst.remote_dev)
4031 netdev_upper_dev_unlink(vxlan->default_dst.remote_dev, dev);
3994} 4032}
3995 4033
3996static size_t vxlan_get_size(const struct net_device *dev) 4034static size_t vxlan_get_size(const struct net_device *dev)
diff --git a/drivers/net/wimax/i2400m/op-rfkill.c b/drivers/net/wimax/i2400m/op-rfkill.c
index 8efb493ceec2..5c79f052cad2 100644
--- a/drivers/net/wimax/i2400m/op-rfkill.c
+++ b/drivers/net/wimax/i2400m/op-rfkill.c
@@ -127,12 +127,12 @@ int i2400m_op_rfkill_sw_toggle(struct wimax_dev *wimax_dev,
127 "%d\n", result); 127 "%d\n", result);
128 result = 0; 128 result = 0;
129error_cmd: 129error_cmd:
130 kfree(cmd);
131 kfree_skb(ack_skb); 130 kfree_skb(ack_skb);
132error_msg_to_dev: 131error_msg_to_dev:
133error_alloc: 132error_alloc:
134 d_fnend(4, dev, "(wimax_dev %p state %d) = %d\n", 133 d_fnend(4, dev, "(wimax_dev %p state %d) = %d\n",
135 wimax_dev, state, result); 134 wimax_dev, state, result);
135 kfree(cmd);
136 return result; 136 return result;
137} 137}
138 138
diff --git a/drivers/net/wireless/intersil/hostap/hostap_hw.c b/drivers/net/wireless/intersil/hostap/hostap_hw.c
index 158a3d762e55..e323e9a5999f 100644
--- a/drivers/net/wireless/intersil/hostap/hostap_hw.c
+++ b/drivers/net/wireless/intersil/hostap/hostap_hw.c
@@ -3041,30 +3041,6 @@ static void prism2_clear_set_tim_queue(local_info_t *local)
3041 } 3041 }
3042} 3042}
3043 3043
3044
3045/*
3046 * HostAP uses two layers of net devices, where the inner
3047 * layer gets called all the time from the outer layer.
3048 * This is a natural nesting, which needs a split lock type.
3049 */
3050static struct lock_class_key hostap_netdev_xmit_lock_key;
3051static struct lock_class_key hostap_netdev_addr_lock_key;
3052
3053static void prism2_set_lockdep_class_one(struct net_device *dev,
3054 struct netdev_queue *txq,
3055 void *_unused)
3056{
3057 lockdep_set_class(&txq->_xmit_lock,
3058 &hostap_netdev_xmit_lock_key);
3059}
3060
3061static void prism2_set_lockdep_class(struct net_device *dev)
3062{
3063 lockdep_set_class(&dev->addr_list_lock,
3064 &hostap_netdev_addr_lock_key);
3065 netdev_for_each_tx_queue(dev, prism2_set_lockdep_class_one, NULL);
3066}
3067
3068static struct net_device * 3044static struct net_device *
3069prism2_init_local_data(struct prism2_helper_functions *funcs, int card_idx, 3045prism2_init_local_data(struct prism2_helper_functions *funcs, int card_idx,
3070 struct device *sdev) 3046 struct device *sdev)
@@ -3223,7 +3199,6 @@ while (0)
3223 if (ret >= 0) 3199 if (ret >= 0)
3224 ret = register_netdevice(dev); 3200 ret = register_netdevice(dev);
3225 3201
3226 prism2_set_lockdep_class(dev);
3227 rtnl_unlock(); 3202 rtnl_unlock();
3228 if (ret < 0) { 3203 if (ret < 0) {
3229 printk(KERN_WARNING "%s: register netdevice failed!\n", 3204 printk(KERN_WARNING "%s: register netdevice failed!\n",
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index 635956024e88..14f562cd715c 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -1261,8 +1261,8 @@ static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw *hw,
1261 skb_orphan(skb); 1261 skb_orphan(skb);
1262 skb_dst_drop(skb); 1262 skb_dst_drop(skb);
1263 skb->mark = 0; 1263 skb->mark = 0;
1264 secpath_reset(skb); 1264 skb_ext_reset(skb);
1265 nf_reset(skb); 1265 nf_reset_ct(skb);
1266 1266
1267 /* 1267 /*
1268 * Get absolute mactime here so all HWs RX at the "same time", and 1268 * Get absolute mactime here so all HWs RX at the "same time", and
@@ -4026,7 +4026,7 @@ static int __init init_mac80211_hwsim(void)
4026 err = dev_alloc_name(hwsim_mon, hwsim_mon->name); 4026 err = dev_alloc_name(hwsim_mon, hwsim_mon->name);
4027 if (err < 0) { 4027 if (err < 0) {
4028 rtnl_unlock(); 4028 rtnl_unlock();
4029 goto out_free_radios; 4029 goto out_free_mon;
4030 } 4030 }
4031 4031
4032 err = register_netdevice(hwsim_mon); 4032 err = register_netdevice(hwsim_mon);
diff --git a/drivers/net/wireless/virt_wifi.c b/drivers/net/wireless/virt_wifi.c
index be92e1220284..7997cc6de334 100644
--- a/drivers/net/wireless/virt_wifi.c
+++ b/drivers/net/wireless/virt_wifi.c
@@ -548,6 +548,7 @@ static int virt_wifi_newlink(struct net *src_net, struct net_device *dev,
548 priv->is_connected = false; 548 priv->is_connected = false;
549 priv->is_up = false; 549 priv->is_up = false;
550 INIT_DELAYED_WORK(&priv->connect, virt_wifi_connect_complete); 550 INIT_DELAYED_WORK(&priv->connect, virt_wifi_connect_complete);
551 __module_get(THIS_MODULE);
551 552
552 return 0; 553 return 0;
553unregister_netdev: 554unregister_netdev:
@@ -578,6 +579,7 @@ static void virt_wifi_dellink(struct net_device *dev,
578 netdev_upper_dev_unlink(priv->lowerdev, dev); 579 netdev_upper_dev_unlink(priv->lowerdev, dev);
579 580
580 unregister_netdevice_queue(dev, head); 581 unregister_netdevice_queue(dev, head);
582 module_put(THIS_MODULE);
581 583
582 /* Deleting the wiphy is handled in the module destructor. */ 584 /* Deleting the wiphy is handled in the module destructor. */
583} 585}
@@ -590,6 +592,42 @@ static struct rtnl_link_ops virt_wifi_link_ops = {
590 .priv_size = sizeof(struct virt_wifi_netdev_priv), 592 .priv_size = sizeof(struct virt_wifi_netdev_priv),
591}; 593};
592 594
595static bool netif_is_virt_wifi_dev(const struct net_device *dev)
596{
597 return rcu_access_pointer(dev->rx_handler) == virt_wifi_rx_handler;
598}
599
600static int virt_wifi_event(struct notifier_block *this, unsigned long event,
601 void *ptr)
602{
603 struct net_device *lower_dev = netdev_notifier_info_to_dev(ptr);
604 struct virt_wifi_netdev_priv *priv;
605 struct net_device *upper_dev;
606 LIST_HEAD(list_kill);
607
608 if (!netif_is_virt_wifi_dev(lower_dev))
609 return NOTIFY_DONE;
610
611 switch (event) {
612 case NETDEV_UNREGISTER:
613 priv = rtnl_dereference(lower_dev->rx_handler_data);
614 if (!priv)
615 return NOTIFY_DONE;
616
617 upper_dev = priv->upperdev;
618
619 upper_dev->rtnl_link_ops->dellink(upper_dev, &list_kill);
620 unregister_netdevice_many(&list_kill);
621 break;
622 }
623
624 return NOTIFY_DONE;
625}
626
627static struct notifier_block virt_wifi_notifier = {
628 .notifier_call = virt_wifi_event,
629};
630
593/* Acquires and releases the rtnl lock. */ 631/* Acquires and releases the rtnl lock. */
594static int __init virt_wifi_init_module(void) 632static int __init virt_wifi_init_module(void)
595{ 633{
@@ -598,14 +636,25 @@ static int __init virt_wifi_init_module(void)
598 /* Guaranteed to be locallly-administered and not multicast. */ 636 /* Guaranteed to be locallly-administered and not multicast. */
599 eth_random_addr(fake_router_bssid); 637 eth_random_addr(fake_router_bssid);
600 638
639 err = register_netdevice_notifier(&virt_wifi_notifier);
640 if (err)
641 return err;
642
643 err = -ENOMEM;
601 common_wiphy = virt_wifi_make_wiphy(); 644 common_wiphy = virt_wifi_make_wiphy();
602 if (!common_wiphy) 645 if (!common_wiphy)
603 return -ENOMEM; 646 goto notifier;
604 647
605 err = rtnl_link_register(&virt_wifi_link_ops); 648 err = rtnl_link_register(&virt_wifi_link_ops);
606 if (err) 649 if (err)
607 virt_wifi_destroy_wiphy(common_wiphy); 650 goto destroy_wiphy;
608 651
652 return 0;
653
654destroy_wiphy:
655 virt_wifi_destroy_wiphy(common_wiphy);
656notifier:
657 unregister_netdevice_notifier(&virt_wifi_notifier);
609 return err; 658 return err;
610} 659}
611 660
@@ -615,6 +664,7 @@ static void __exit virt_wifi_cleanup_module(void)
615 /* Will delete any devices that depend on the wiphy. */ 664 /* Will delete any devices that depend on the wiphy. */
616 rtnl_link_unregister(&virt_wifi_link_ops); 665 rtnl_link_unregister(&virt_wifi_link_ops);
617 virt_wifi_destroy_wiphy(common_wiphy); 666 virt_wifi_destroy_wiphy(common_wiphy);
667 unregister_netdevice_notifier(&virt_wifi_notifier);
618} 668}
619 669
620module_init(virt_wifi_init_module); 670module_init(virt_wifi_init_module);
diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
index 240f762b3749..103ed00775eb 100644
--- a/drivers/net/xen-netback/interface.c
+++ b/drivers/net/xen-netback/interface.c
@@ -719,7 +719,6 @@ err_unmap:
719 xenvif_unmap_frontend_data_rings(queue); 719 xenvif_unmap_frontend_data_rings(queue);
720 netif_napi_del(&queue->napi); 720 netif_napi_del(&queue->napi);
721err: 721err:
722 module_put(THIS_MODULE);
723 return err; 722 return err;
724} 723}
725 724
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index e14ec75b61d6..482c6c8b0fb7 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -887,9 +887,9 @@ static int xennet_set_skb_gso(struct sk_buff *skb,
887 return 0; 887 return 0;
888} 888}
889 889
890static RING_IDX xennet_fill_frags(struct netfront_queue *queue, 890static int xennet_fill_frags(struct netfront_queue *queue,
891 struct sk_buff *skb, 891 struct sk_buff *skb,
892 struct sk_buff_head *list) 892 struct sk_buff_head *list)
893{ 893{
894 RING_IDX cons = queue->rx.rsp_cons; 894 RING_IDX cons = queue->rx.rsp_cons;
895 struct sk_buff *nskb; 895 struct sk_buff *nskb;
@@ -908,7 +908,7 @@ static RING_IDX xennet_fill_frags(struct netfront_queue *queue,
908 if (unlikely(skb_shinfo(skb)->nr_frags >= MAX_SKB_FRAGS)) { 908 if (unlikely(skb_shinfo(skb)->nr_frags >= MAX_SKB_FRAGS)) {
909 queue->rx.rsp_cons = ++cons + skb_queue_len(list); 909 queue->rx.rsp_cons = ++cons + skb_queue_len(list);
910 kfree_skb(nskb); 910 kfree_skb(nskb);
911 return ~0U; 911 return -ENOENT;
912 } 912 }
913 913
914 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, 914 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
@@ -919,7 +919,9 @@ static RING_IDX xennet_fill_frags(struct netfront_queue *queue,
919 kfree_skb(nskb); 919 kfree_skb(nskb);
920 } 920 }
921 921
922 return cons; 922 queue->rx.rsp_cons = cons;
923
924 return 0;
923} 925}
924 926
925static int checksum_setup(struct net_device *dev, struct sk_buff *skb) 927static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
@@ -1045,8 +1047,7 @@ err:
1045 skb->data_len = rx->status; 1047 skb->data_len = rx->status;
1046 skb->len += rx->status; 1048 skb->len += rx->status;
1047 1049
1048 i = xennet_fill_frags(queue, skb, &tmpq); 1050 if (unlikely(xennet_fill_frags(queue, skb, &tmpq)))
1049 if (unlikely(i == ~0U))
1050 goto err; 1051 goto err;
1051 1052
1052 if (rx->flags & XEN_NETRXF_csum_blank) 1053 if (rx->flags & XEN_NETRXF_csum_blank)
@@ -1056,7 +1057,7 @@ err:
1056 1057
1057 __skb_queue_tail(&rxq, skb); 1058 __skb_queue_tail(&rxq, skb);
1058 1059
1059 queue->rx.rsp_cons = ++i; 1060 i = ++queue->rx.rsp_cons;
1060 work_done++; 1061 work_done++;
1061 } 1062 }
1062 1063
diff --git a/drivers/nfc/pn533/usb.c b/drivers/nfc/pn533/usb.c
index c5289eaf17ee..e897e4d768ef 100644
--- a/drivers/nfc/pn533/usb.c
+++ b/drivers/nfc/pn533/usb.c
@@ -547,18 +547,25 @@ static int pn533_usb_probe(struct usb_interface *interface,
547 547
548 rc = pn533_finalize_setup(priv); 548 rc = pn533_finalize_setup(priv);
549 if (rc) 549 if (rc)
550 goto error; 550 goto err_deregister;
551 551
552 usb_set_intfdata(interface, phy); 552 usb_set_intfdata(interface, phy);
553 553
554 return 0; 554 return 0;
555 555
556err_deregister:
557 pn533_unregister_device(phy->priv);
556error: 558error:
559 usb_kill_urb(phy->in_urb);
560 usb_kill_urb(phy->out_urb);
561 usb_kill_urb(phy->ack_urb);
562
557 usb_free_urb(phy->in_urb); 563 usb_free_urb(phy->in_urb);
558 usb_free_urb(phy->out_urb); 564 usb_free_urb(phy->out_urb);
559 usb_free_urb(phy->ack_urb); 565 usb_free_urb(phy->ack_urb);
560 usb_put_dev(phy->udev); 566 usb_put_dev(phy->udev);
561 kfree(in_buf); 567 kfree(in_buf);
568 kfree(phy->ack_buffer);
562 569
563 return rc; 570 return rc;
564} 571}
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 108f60b46804..fa7ba09dca77 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -102,10 +102,13 @@ static void nvme_set_queue_dying(struct nvme_ns *ns)
102 */ 102 */
103 if (!ns->disk || test_and_set_bit(NVME_NS_DEAD, &ns->flags)) 103 if (!ns->disk || test_and_set_bit(NVME_NS_DEAD, &ns->flags))
104 return; 104 return;
105 revalidate_disk(ns->disk);
106 blk_set_queue_dying(ns->queue); 105 blk_set_queue_dying(ns->queue);
107 /* Forcibly unquiesce queues to avoid blocking dispatch */ 106 /* Forcibly unquiesce queues to avoid blocking dispatch */
108 blk_mq_unquiesce_queue(ns->queue); 107 blk_mq_unquiesce_queue(ns->queue);
108 /*
109 * Revalidate after unblocking dispatchers that may be holding bd_butex
110 */
111 revalidate_disk(ns->disk);
109} 112}
110 113
111static void nvme_queue_scan(struct nvme_ctrl *ctrl) 114static void nvme_queue_scan(struct nvme_ctrl *ctrl)
@@ -113,10 +116,26 @@ static void nvme_queue_scan(struct nvme_ctrl *ctrl)
113 /* 116 /*
114 * Only new queue scan work when admin and IO queues are both alive 117 * Only new queue scan work when admin and IO queues are both alive
115 */ 118 */
116 if (ctrl->state == NVME_CTRL_LIVE) 119 if (ctrl->state == NVME_CTRL_LIVE && ctrl->tagset)
117 queue_work(nvme_wq, &ctrl->scan_work); 120 queue_work(nvme_wq, &ctrl->scan_work);
118} 121}
119 122
123/*
124 * Use this function to proceed with scheduling reset_work for a controller
125 * that had previously been set to the resetting state. This is intended for
126 * code paths that can't be interrupted by other reset attempts. A hot removal
127 * may prevent this from succeeding.
128 */
129int nvme_try_sched_reset(struct nvme_ctrl *ctrl)
130{
131 if (ctrl->state != NVME_CTRL_RESETTING)
132 return -EBUSY;
133 if (!queue_work(nvme_reset_wq, &ctrl->reset_work))
134 return -EBUSY;
135 return 0;
136}
137EXPORT_SYMBOL_GPL(nvme_try_sched_reset);
138
120int nvme_reset_ctrl(struct nvme_ctrl *ctrl) 139int nvme_reset_ctrl(struct nvme_ctrl *ctrl)
121{ 140{
122 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING)) 141 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING))
@@ -134,8 +153,7 @@ int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl)
134 ret = nvme_reset_ctrl(ctrl); 153 ret = nvme_reset_ctrl(ctrl);
135 if (!ret) { 154 if (!ret) {
136 flush_work(&ctrl->reset_work); 155 flush_work(&ctrl->reset_work);
137 if (ctrl->state != NVME_CTRL_LIVE && 156 if (ctrl->state != NVME_CTRL_LIVE)
138 ctrl->state != NVME_CTRL_ADMIN_ONLY)
139 ret = -ENETRESET; 157 ret = -ENETRESET;
140 } 158 }
141 159
@@ -312,15 +330,6 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
312 330
313 old_state = ctrl->state; 331 old_state = ctrl->state;
314 switch (new_state) { 332 switch (new_state) {
315 case NVME_CTRL_ADMIN_ONLY:
316 switch (old_state) {
317 case NVME_CTRL_CONNECTING:
318 changed = true;
319 /* FALLTHRU */
320 default:
321 break;
322 }
323 break;
324 case NVME_CTRL_LIVE: 333 case NVME_CTRL_LIVE:
325 switch (old_state) { 334 switch (old_state) {
326 case NVME_CTRL_NEW: 335 case NVME_CTRL_NEW:
@@ -336,7 +345,6 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
336 switch (old_state) { 345 switch (old_state) {
337 case NVME_CTRL_NEW: 346 case NVME_CTRL_NEW:
338 case NVME_CTRL_LIVE: 347 case NVME_CTRL_LIVE:
339 case NVME_CTRL_ADMIN_ONLY:
340 changed = true; 348 changed = true;
341 /* FALLTHRU */ 349 /* FALLTHRU */
342 default: 350 default:
@@ -356,7 +364,6 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
356 case NVME_CTRL_DELETING: 364 case NVME_CTRL_DELETING:
357 switch (old_state) { 365 switch (old_state) {
358 case NVME_CTRL_LIVE: 366 case NVME_CTRL_LIVE:
359 case NVME_CTRL_ADMIN_ONLY:
360 case NVME_CTRL_RESETTING: 367 case NVME_CTRL_RESETTING:
361 case NVME_CTRL_CONNECTING: 368 case NVME_CTRL_CONNECTING:
362 changed = true; 369 changed = true;
@@ -378,8 +385,10 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
378 break; 385 break;
379 } 386 }
380 387
381 if (changed) 388 if (changed) {
382 ctrl->state = new_state; 389 ctrl->state = new_state;
390 wake_up_all(&ctrl->state_wq);
391 }
383 392
384 spin_unlock_irqrestore(&ctrl->lock, flags); 393 spin_unlock_irqrestore(&ctrl->lock, flags);
385 if (changed && ctrl->state == NVME_CTRL_LIVE) 394 if (changed && ctrl->state == NVME_CTRL_LIVE)
@@ -388,6 +397,39 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
388} 397}
389EXPORT_SYMBOL_GPL(nvme_change_ctrl_state); 398EXPORT_SYMBOL_GPL(nvme_change_ctrl_state);
390 399
400/*
401 * Returns true for sink states that can't ever transition back to live.
402 */
403static bool nvme_state_terminal(struct nvme_ctrl *ctrl)
404{
405 switch (ctrl->state) {
406 case NVME_CTRL_NEW:
407 case NVME_CTRL_LIVE:
408 case NVME_CTRL_RESETTING:
409 case NVME_CTRL_CONNECTING:
410 return false;
411 case NVME_CTRL_DELETING:
412 case NVME_CTRL_DEAD:
413 return true;
414 default:
415 WARN_ONCE(1, "Unhandled ctrl state:%d", ctrl->state);
416 return true;
417 }
418}
419
420/*
421 * Waits for the controller state to be resetting, or returns false if it is
422 * not possible to ever transition to that state.
423 */
424bool nvme_wait_reset(struct nvme_ctrl *ctrl)
425{
426 wait_event(ctrl->state_wq,
427 nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING) ||
428 nvme_state_terminal(ctrl));
429 return ctrl->state == NVME_CTRL_RESETTING;
430}
431EXPORT_SYMBOL_GPL(nvme_wait_reset);
432
391static void nvme_free_ns_head(struct kref *ref) 433static void nvme_free_ns_head(struct kref *ref)
392{ 434{
393 struct nvme_ns_head *head = 435 struct nvme_ns_head *head =
@@ -847,7 +889,7 @@ out:
847static int nvme_submit_user_cmd(struct request_queue *q, 889static int nvme_submit_user_cmd(struct request_queue *q,
848 struct nvme_command *cmd, void __user *ubuffer, 890 struct nvme_command *cmd, void __user *ubuffer,
849 unsigned bufflen, void __user *meta_buffer, unsigned meta_len, 891 unsigned bufflen, void __user *meta_buffer, unsigned meta_len,
850 u32 meta_seed, u32 *result, unsigned timeout) 892 u32 meta_seed, u64 *result, unsigned timeout)
851{ 893{
852 bool write = nvme_is_write(cmd); 894 bool write = nvme_is_write(cmd);
853 struct nvme_ns *ns = q->queuedata; 895 struct nvme_ns *ns = q->queuedata;
@@ -888,7 +930,7 @@ static int nvme_submit_user_cmd(struct request_queue *q,
888 else 930 else
889 ret = nvme_req(req)->status; 931 ret = nvme_req(req)->status;
890 if (result) 932 if (result)
891 *result = le32_to_cpu(nvme_req(req)->result.u32); 933 *result = le64_to_cpu(nvme_req(req)->result.u64);
892 if (meta && !ret && !write) { 934 if (meta && !ret && !write) {
893 if (copy_to_user(meta_buffer, meta, meta_len)) 935 if (copy_to_user(meta_buffer, meta, meta_len))
894 ret = -EFAULT; 936 ret = -EFAULT;
@@ -1303,8 +1345,6 @@ static void nvme_update_formats(struct nvme_ctrl *ctrl)
1303 if (ns->disk && nvme_revalidate_disk(ns->disk)) 1345 if (ns->disk && nvme_revalidate_disk(ns->disk))
1304 nvme_set_queue_dying(ns); 1346 nvme_set_queue_dying(ns);
1305 up_read(&ctrl->namespaces_rwsem); 1347 up_read(&ctrl->namespaces_rwsem);
1306
1307 nvme_remove_invalid_namespaces(ctrl, NVME_NSID_ALL);
1308} 1348}
1309 1349
1310static void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects) 1350static void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects)
@@ -1320,6 +1360,7 @@ static void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects)
1320 nvme_unfreeze(ctrl); 1360 nvme_unfreeze(ctrl);
1321 nvme_mpath_unfreeze(ctrl->subsys); 1361 nvme_mpath_unfreeze(ctrl->subsys);
1322 mutex_unlock(&ctrl->subsys->lock); 1362 mutex_unlock(&ctrl->subsys->lock);
1363 nvme_remove_invalid_namespaces(ctrl, NVME_NSID_ALL);
1323 mutex_unlock(&ctrl->scan_lock); 1364 mutex_unlock(&ctrl->scan_lock);
1324 } 1365 }
1325 if (effects & NVME_CMD_EFFECTS_CCC) 1366 if (effects & NVME_CMD_EFFECTS_CCC)
@@ -1335,6 +1376,54 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
1335 struct nvme_command c; 1376 struct nvme_command c;
1336 unsigned timeout = 0; 1377 unsigned timeout = 0;
1337 u32 effects; 1378 u32 effects;
1379 u64 result;
1380 int status;
1381
1382 if (!capable(CAP_SYS_ADMIN))
1383 return -EACCES;
1384 if (copy_from_user(&cmd, ucmd, sizeof(cmd)))
1385 return -EFAULT;
1386 if (cmd.flags)
1387 return -EINVAL;
1388
1389 memset(&c, 0, sizeof(c));
1390 c.common.opcode = cmd.opcode;
1391 c.common.flags = cmd.flags;
1392 c.common.nsid = cpu_to_le32(cmd.nsid);
1393 c.common.cdw2[0] = cpu_to_le32(cmd.cdw2);
1394 c.common.cdw2[1] = cpu_to_le32(cmd.cdw3);
1395 c.common.cdw10 = cpu_to_le32(cmd.cdw10);
1396 c.common.cdw11 = cpu_to_le32(cmd.cdw11);
1397 c.common.cdw12 = cpu_to_le32(cmd.cdw12);
1398 c.common.cdw13 = cpu_to_le32(cmd.cdw13);
1399 c.common.cdw14 = cpu_to_le32(cmd.cdw14);
1400 c.common.cdw15 = cpu_to_le32(cmd.cdw15);
1401
1402 if (cmd.timeout_ms)
1403 timeout = msecs_to_jiffies(cmd.timeout_ms);
1404
1405 effects = nvme_passthru_start(ctrl, ns, cmd.opcode);
1406 status = nvme_submit_user_cmd(ns ? ns->queue : ctrl->admin_q, &c,
1407 (void __user *)(uintptr_t)cmd.addr, cmd.data_len,
1408 (void __user *)(uintptr_t)cmd.metadata,
1409 cmd.metadata_len, 0, &result, timeout);
1410 nvme_passthru_end(ctrl, effects);
1411
1412 if (status >= 0) {
1413 if (put_user(result, &ucmd->result))
1414 return -EFAULT;
1415 }
1416
1417 return status;
1418}
1419
1420static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
1421 struct nvme_passthru_cmd64 __user *ucmd)
1422{
1423 struct nvme_passthru_cmd64 cmd;
1424 struct nvme_command c;
1425 unsigned timeout = 0;
1426 u32 effects;
1338 int status; 1427 int status;
1339 1428
1340 if (!capable(CAP_SYS_ADMIN)) 1429 if (!capable(CAP_SYS_ADMIN))
@@ -1405,6 +1494,41 @@ static void nvme_put_ns_from_disk(struct nvme_ns_head *head, int idx)
1405 srcu_read_unlock(&head->srcu, idx); 1494 srcu_read_unlock(&head->srcu, idx);
1406} 1495}
1407 1496
1497static bool is_ctrl_ioctl(unsigned int cmd)
1498{
1499 if (cmd == NVME_IOCTL_ADMIN_CMD || cmd == NVME_IOCTL_ADMIN64_CMD)
1500 return true;
1501 if (is_sed_ioctl(cmd))
1502 return true;
1503 return false;
1504}
1505
1506static int nvme_handle_ctrl_ioctl(struct nvme_ns *ns, unsigned int cmd,
1507 void __user *argp,
1508 struct nvme_ns_head *head,
1509 int srcu_idx)
1510{
1511 struct nvme_ctrl *ctrl = ns->ctrl;
1512 int ret;
1513
1514 nvme_get_ctrl(ns->ctrl);
1515 nvme_put_ns_from_disk(head, srcu_idx);
1516
1517 switch (cmd) {
1518 case NVME_IOCTL_ADMIN_CMD:
1519 ret = nvme_user_cmd(ctrl, NULL, argp);
1520 break;
1521 case NVME_IOCTL_ADMIN64_CMD:
1522 ret = nvme_user_cmd64(ctrl, NULL, argp);
1523 break;
1524 default:
1525 ret = sed_ioctl(ctrl->opal_dev, cmd, argp);
1526 break;
1527 }
1528 nvme_put_ctrl(ctrl);
1529 return ret;
1530}
1531
1408static int nvme_ioctl(struct block_device *bdev, fmode_t mode, 1532static int nvme_ioctl(struct block_device *bdev, fmode_t mode,
1409 unsigned int cmd, unsigned long arg) 1533 unsigned int cmd, unsigned long arg)
1410{ 1534{
@@ -1422,20 +1546,8 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode,
1422 * seperately and drop the ns SRCU reference early. This avoids a 1546 * seperately and drop the ns SRCU reference early. This avoids a
1423 * deadlock when deleting namespaces using the passthrough interface. 1547 * deadlock when deleting namespaces using the passthrough interface.
1424 */ 1548 */
1425 if (cmd == NVME_IOCTL_ADMIN_CMD || is_sed_ioctl(cmd)) { 1549 if (is_ctrl_ioctl(cmd))
1426 struct nvme_ctrl *ctrl = ns->ctrl; 1550 return nvme_handle_ctrl_ioctl(ns, cmd, argp, head, srcu_idx);
1427
1428 nvme_get_ctrl(ns->ctrl);
1429 nvme_put_ns_from_disk(head, srcu_idx);
1430
1431 if (cmd == NVME_IOCTL_ADMIN_CMD)
1432 ret = nvme_user_cmd(ctrl, NULL, argp);
1433 else
1434 ret = sed_ioctl(ctrl->opal_dev, cmd, argp);
1435
1436 nvme_put_ctrl(ctrl);
1437 return ret;
1438 }
1439 1551
1440 switch (cmd) { 1552 switch (cmd) {
1441 case NVME_IOCTL_ID: 1553 case NVME_IOCTL_ID:
@@ -1448,6 +1560,9 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode,
1448 case NVME_IOCTL_SUBMIT_IO: 1560 case NVME_IOCTL_SUBMIT_IO:
1449 ret = nvme_submit_io(ns, argp); 1561 ret = nvme_submit_io(ns, argp);
1450 break; 1562 break;
1563 case NVME_IOCTL_IO64_CMD:
1564 ret = nvme_user_cmd64(ns->ctrl, ns, argp);
1565 break;
1451 default: 1566 default:
1452 if (ns->ndev) 1567 if (ns->ndev)
1453 ret = nvme_nvm_ioctl(ns, cmd, arg); 1568 ret = nvme_nvm_ioctl(ns, cmd, arg);
@@ -2289,6 +2404,16 @@ static const struct nvme_core_quirk_entry core_quirks[] = {
2289 .vid = 0x14a4, 2404 .vid = 0x14a4,
2290 .fr = "22301111", 2405 .fr = "22301111",
2291 .quirks = NVME_QUIRK_SIMPLE_SUSPEND, 2406 .quirks = NVME_QUIRK_SIMPLE_SUSPEND,
2407 },
2408 {
2409 /*
2410 * This Kingston E8FK11.T firmware version has no interrupt
2411 * after resume with actions related to suspend to idle
2412 * https://bugzilla.kernel.org/show_bug.cgi?id=204887
2413 */
2414 .vid = 0x2646,
2415 .fr = "E8FK11.T",
2416 .quirks = NVME_QUIRK_SIMPLE_SUSPEND,
2292 } 2417 }
2293}; 2418};
2294 2419
@@ -2540,8 +2665,9 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
2540 list_add_tail(&subsys->entry, &nvme_subsystems); 2665 list_add_tail(&subsys->entry, &nvme_subsystems);
2541 } 2666 }
2542 2667
2543 if (sysfs_create_link(&subsys->dev.kobj, &ctrl->device->kobj, 2668 ret = sysfs_create_link(&subsys->dev.kobj, &ctrl->device->kobj,
2544 dev_name(ctrl->device))) { 2669 dev_name(ctrl->device));
2670 if (ret) {
2545 dev_err(ctrl->device, 2671 dev_err(ctrl->device,
2546 "failed to create sysfs link from subsystem.\n"); 2672 "failed to create sysfs link from subsystem.\n");
2547 goto out_put_subsystem; 2673 goto out_put_subsystem;
@@ -2786,7 +2912,6 @@ static int nvme_dev_open(struct inode *inode, struct file *file)
2786 2912
2787 switch (ctrl->state) { 2913 switch (ctrl->state) {
2788 case NVME_CTRL_LIVE: 2914 case NVME_CTRL_LIVE:
2789 case NVME_CTRL_ADMIN_ONLY:
2790 break; 2915 break;
2791 default: 2916 default:
2792 return -EWOULDBLOCK; 2917 return -EWOULDBLOCK;
@@ -2838,6 +2963,8 @@ static long nvme_dev_ioctl(struct file *file, unsigned int cmd,
2838 switch (cmd) { 2963 switch (cmd) {
2839 case NVME_IOCTL_ADMIN_CMD: 2964 case NVME_IOCTL_ADMIN_CMD:
2840 return nvme_user_cmd(ctrl, NULL, argp); 2965 return nvme_user_cmd(ctrl, NULL, argp);
2966 case NVME_IOCTL_ADMIN64_CMD:
2967 return nvme_user_cmd64(ctrl, NULL, argp);
2841 case NVME_IOCTL_IO_CMD: 2968 case NVME_IOCTL_IO_CMD:
2842 return nvme_dev_user_cmd(ctrl, argp); 2969 return nvme_dev_user_cmd(ctrl, argp);
2843 case NVME_IOCTL_RESET: 2970 case NVME_IOCTL_RESET:
@@ -3045,6 +3172,8 @@ static DEVICE_ATTR(field, S_IRUGO, field##_show, NULL);
3045 3172
3046nvme_show_int_function(cntlid); 3173nvme_show_int_function(cntlid);
3047nvme_show_int_function(numa_node); 3174nvme_show_int_function(numa_node);
3175nvme_show_int_function(queue_count);
3176nvme_show_int_function(sqsize);
3048 3177
3049static ssize_t nvme_sysfs_delete(struct device *dev, 3178static ssize_t nvme_sysfs_delete(struct device *dev,
3050 struct device_attribute *attr, const char *buf, 3179 struct device_attribute *attr, const char *buf,
@@ -3076,7 +3205,6 @@ static ssize_t nvme_sysfs_show_state(struct device *dev,
3076 static const char *const state_name[] = { 3205 static const char *const state_name[] = {
3077 [NVME_CTRL_NEW] = "new", 3206 [NVME_CTRL_NEW] = "new",
3078 [NVME_CTRL_LIVE] = "live", 3207 [NVME_CTRL_LIVE] = "live",
3079 [NVME_CTRL_ADMIN_ONLY] = "only-admin",
3080 [NVME_CTRL_RESETTING] = "resetting", 3208 [NVME_CTRL_RESETTING] = "resetting",
3081 [NVME_CTRL_CONNECTING] = "connecting", 3209 [NVME_CTRL_CONNECTING] = "connecting",
3082 [NVME_CTRL_DELETING] = "deleting", 3210 [NVME_CTRL_DELETING] = "deleting",
@@ -3125,6 +3253,8 @@ static struct attribute *nvme_dev_attrs[] = {
3125 &dev_attr_address.attr, 3253 &dev_attr_address.attr,
3126 &dev_attr_state.attr, 3254 &dev_attr_state.attr,
3127 &dev_attr_numa_node.attr, 3255 &dev_attr_numa_node.attr,
3256 &dev_attr_queue_count.attr,
3257 &dev_attr_sqsize.attr,
3128 NULL 3258 NULL
3129}; 3259};
3130 3260
@@ -3585,11 +3715,10 @@ static void nvme_scan_work(struct work_struct *work)
3585 struct nvme_id_ctrl *id; 3715 struct nvme_id_ctrl *id;
3586 unsigned nn; 3716 unsigned nn;
3587 3717
3588 if (ctrl->state != NVME_CTRL_LIVE) 3718 /* No tagset on a live ctrl means IO queues could not created */
3719 if (ctrl->state != NVME_CTRL_LIVE || !ctrl->tagset)
3589 return; 3720 return;
3590 3721
3591 WARN_ON_ONCE(!ctrl->tagset);
3592
3593 if (test_and_clear_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) { 3722 if (test_and_clear_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) {
3594 dev_info(ctrl->device, "rescanning namespaces.\n"); 3723 dev_info(ctrl->device, "rescanning namespaces.\n");
3595 nvme_clear_changed_ns_log(ctrl); 3724 nvme_clear_changed_ns_log(ctrl);
@@ -3750,13 +3879,13 @@ static void nvme_fw_act_work(struct work_struct *work)
3750 if (time_after(jiffies, fw_act_timeout)) { 3879 if (time_after(jiffies, fw_act_timeout)) {
3751 dev_warn(ctrl->device, 3880 dev_warn(ctrl->device,
3752 "Fw activation timeout, reset controller\n"); 3881 "Fw activation timeout, reset controller\n");
3753 nvme_reset_ctrl(ctrl); 3882 nvme_try_sched_reset(ctrl);
3754 break; 3883 return;
3755 } 3884 }
3756 msleep(100); 3885 msleep(100);
3757 } 3886 }
3758 3887
3759 if (ctrl->state != NVME_CTRL_LIVE) 3888 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_LIVE))
3760 return; 3889 return;
3761 3890
3762 nvme_start_queues(ctrl); 3891 nvme_start_queues(ctrl);
@@ -3776,7 +3905,13 @@ static void nvme_handle_aen_notice(struct nvme_ctrl *ctrl, u32 result)
3776 nvme_queue_scan(ctrl); 3905 nvme_queue_scan(ctrl);
3777 break; 3906 break;
3778 case NVME_AER_NOTICE_FW_ACT_STARTING: 3907 case NVME_AER_NOTICE_FW_ACT_STARTING:
3779 queue_work(nvme_wq, &ctrl->fw_act_work); 3908 /*
3909 * We are (ab)using the RESETTING state to prevent subsequent
3910 * recovery actions from interfering with the controller's
3911 * firmware activation.
3912 */
3913 if (nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING))
3914 queue_work(nvme_wq, &ctrl->fw_act_work);
3780 break; 3915 break;
3781#ifdef CONFIG_NVME_MULTIPATH 3916#ifdef CONFIG_NVME_MULTIPATH
3782 case NVME_AER_NOTICE_ANA: 3917 case NVME_AER_NOTICE_ANA:
@@ -3899,6 +4034,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
3899 INIT_WORK(&ctrl->async_event_work, nvme_async_event_work); 4034 INIT_WORK(&ctrl->async_event_work, nvme_async_event_work);
3900 INIT_WORK(&ctrl->fw_act_work, nvme_fw_act_work); 4035 INIT_WORK(&ctrl->fw_act_work, nvme_fw_act_work);
3901 INIT_WORK(&ctrl->delete_work, nvme_delete_ctrl_work); 4036 INIT_WORK(&ctrl->delete_work, nvme_delete_ctrl_work);
4037 init_waitqueue_head(&ctrl->state_wq);
3902 4038
3903 INIT_DELAYED_WORK(&ctrl->ka_work, nvme_keep_alive_work); 4039 INIT_DELAYED_WORK(&ctrl->ka_work, nvme_keep_alive_work);
3904 memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd)); 4040 memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd));
diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h
index 93f08d77c896..a0ec40ab62ee 100644
--- a/drivers/nvme/host/fabrics.h
+++ b/drivers/nvme/host/fabrics.h
@@ -182,8 +182,7 @@ bool nvmf_ip_options_match(struct nvme_ctrl *ctrl,
182static inline bool nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq, 182static inline bool nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
183 bool queue_live) 183 bool queue_live)
184{ 184{
185 if (likely(ctrl->state == NVME_CTRL_LIVE || 185 if (likely(ctrl->state == NVME_CTRL_LIVE))
186 ctrl->state == NVME_CTRL_ADMIN_ONLY))
187 return true; 186 return true;
188 return __nvmf_check_ready(ctrl, rq, queue_live); 187 return __nvmf_check_ready(ctrl, rq, queue_live);
189} 188}
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index b5013c101b35..22e8401352c2 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -15,6 +15,7 @@
15#include <linux/sed-opal.h> 15#include <linux/sed-opal.h>
16#include <linux/fault-inject.h> 16#include <linux/fault-inject.h>
17#include <linux/rcupdate.h> 17#include <linux/rcupdate.h>
18#include <linux/wait.h>
18 19
19#include <trace/events/block.h> 20#include <trace/events/block.h>
20 21
@@ -161,7 +162,6 @@ static inline u16 nvme_req_qid(struct request *req)
161enum nvme_ctrl_state { 162enum nvme_ctrl_state {
162 NVME_CTRL_NEW, 163 NVME_CTRL_NEW,
163 NVME_CTRL_LIVE, 164 NVME_CTRL_LIVE,
164 NVME_CTRL_ADMIN_ONLY, /* Only admin queue live */
165 NVME_CTRL_RESETTING, 165 NVME_CTRL_RESETTING,
166 NVME_CTRL_CONNECTING, 166 NVME_CTRL_CONNECTING,
167 NVME_CTRL_DELETING, 167 NVME_CTRL_DELETING,
@@ -199,6 +199,7 @@ struct nvme_ctrl {
199 struct cdev cdev; 199 struct cdev cdev;
200 struct work_struct reset_work; 200 struct work_struct reset_work;
201 struct work_struct delete_work; 201 struct work_struct delete_work;
202 wait_queue_head_t state_wq;
202 203
203 struct nvme_subsystem *subsys; 204 struct nvme_subsystem *subsys;
204 struct list_head subsys_entry; 205 struct list_head subsys_entry;
@@ -221,6 +222,7 @@ struct nvme_ctrl {
221 u16 oacs; 222 u16 oacs;
222 u16 nssa; 223 u16 nssa;
223 u16 nr_streams; 224 u16 nr_streams;
225 u16 sqsize;
224 u32 max_namespaces; 226 u32 max_namespaces;
225 atomic_t abort_limit; 227 atomic_t abort_limit;
226 u8 vwc; 228 u8 vwc;
@@ -269,7 +271,6 @@ struct nvme_ctrl {
269 u16 hmmaxd; 271 u16 hmmaxd;
270 272
271 /* Fabrics only */ 273 /* Fabrics only */
272 u16 sqsize;
273 u32 ioccsz; 274 u32 ioccsz;
274 u32 iorcsz; 275 u32 iorcsz;
275 u16 icdoff; 276 u16 icdoff;
@@ -449,6 +450,7 @@ void nvme_complete_rq(struct request *req);
449bool nvme_cancel_request(struct request *req, void *data, bool reserved); 450bool nvme_cancel_request(struct request *req, void *data, bool reserved);
450bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl, 451bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
451 enum nvme_ctrl_state new_state); 452 enum nvme_ctrl_state new_state);
453bool nvme_wait_reset(struct nvme_ctrl *ctrl);
452int nvme_disable_ctrl(struct nvme_ctrl *ctrl); 454int nvme_disable_ctrl(struct nvme_ctrl *ctrl);
453int nvme_enable_ctrl(struct nvme_ctrl *ctrl); 455int nvme_enable_ctrl(struct nvme_ctrl *ctrl);
454int nvme_shutdown_ctrl(struct nvme_ctrl *ctrl); 456int nvme_shutdown_ctrl(struct nvme_ctrl *ctrl);
@@ -499,6 +501,7 @@ int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count);
499void nvme_stop_keep_alive(struct nvme_ctrl *ctrl); 501void nvme_stop_keep_alive(struct nvme_ctrl *ctrl);
500int nvme_reset_ctrl(struct nvme_ctrl *ctrl); 502int nvme_reset_ctrl(struct nvme_ctrl *ctrl);
501int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl); 503int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl);
504int nvme_try_sched_reset(struct nvme_ctrl *ctrl);
502int nvme_delete_ctrl(struct nvme_ctrl *ctrl); 505int nvme_delete_ctrl(struct nvme_ctrl *ctrl);
503 506
504int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, 507int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp,
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index c0808f9eb8ab..869f462e6b6e 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -773,7 +773,8 @@ static blk_status_t nvme_setup_prp_simple(struct nvme_dev *dev,
773 struct bio_vec *bv) 773 struct bio_vec *bv)
774{ 774{
775 struct nvme_iod *iod = blk_mq_rq_to_pdu(req); 775 struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
776 unsigned int first_prp_len = dev->ctrl.page_size - bv->bv_offset; 776 unsigned int offset = bv->bv_offset & (dev->ctrl.page_size - 1);
777 unsigned int first_prp_len = dev->ctrl.page_size - offset;
777 778
778 iod->first_dma = dma_map_bvec(dev->dev, bv, rq_dma_dir(req), 0); 779 iod->first_dma = dma_map_bvec(dev->dev, bv, rq_dma_dir(req), 0);
779 if (dma_mapping_error(dev->dev, iod->first_dma)) 780 if (dma_mapping_error(dev->dev, iod->first_dma))
@@ -2263,10 +2264,7 @@ static bool __nvme_disable_io_queues(struct nvme_dev *dev, u8 opcode)
2263 return true; 2264 return true;
2264} 2265}
2265 2266
2266/* 2267static void nvme_dev_add(struct nvme_dev *dev)
2267 * return error value only when tagset allocation failed
2268 */
2269static int nvme_dev_add(struct nvme_dev *dev)
2270{ 2268{
2271 int ret; 2269 int ret;
2272 2270
@@ -2296,7 +2294,7 @@ static int nvme_dev_add(struct nvme_dev *dev)
2296 if (ret) { 2294 if (ret) {
2297 dev_warn(dev->ctrl.device, 2295 dev_warn(dev->ctrl.device,
2298 "IO queues tagset allocation failed %d\n", ret); 2296 "IO queues tagset allocation failed %d\n", ret);
2299 return ret; 2297 return;
2300 } 2298 }
2301 dev->ctrl.tagset = &dev->tagset; 2299 dev->ctrl.tagset = &dev->tagset;
2302 } else { 2300 } else {
@@ -2307,7 +2305,6 @@ static int nvme_dev_add(struct nvme_dev *dev)
2307 } 2305 }
2308 2306
2309 nvme_dbbuf_set(dev); 2307 nvme_dbbuf_set(dev);
2310 return 0;
2311} 2308}
2312 2309
2313static int nvme_pci_enable(struct nvme_dev *dev) 2310static int nvme_pci_enable(struct nvme_dev *dev)
@@ -2467,6 +2464,14 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)
2467 mutex_unlock(&dev->shutdown_lock); 2464 mutex_unlock(&dev->shutdown_lock);
2468} 2465}
2469 2466
2467static int nvme_disable_prepare_reset(struct nvme_dev *dev, bool shutdown)
2468{
2469 if (!nvme_wait_reset(&dev->ctrl))
2470 return -EBUSY;
2471 nvme_dev_disable(dev, shutdown);
2472 return 0;
2473}
2474
2470static int nvme_setup_prp_pools(struct nvme_dev *dev) 2475static int nvme_setup_prp_pools(struct nvme_dev *dev)
2471{ 2476{
2472 dev->prp_page_pool = dma_pool_create("prp list page", dev->dev, 2477 dev->prp_page_pool = dma_pool_create("prp list page", dev->dev,
@@ -2490,14 +2495,20 @@ static void nvme_release_prp_pools(struct nvme_dev *dev)
2490 dma_pool_destroy(dev->prp_small_pool); 2495 dma_pool_destroy(dev->prp_small_pool);
2491} 2496}
2492 2497
2498static void nvme_free_tagset(struct nvme_dev *dev)
2499{
2500 if (dev->tagset.tags)
2501 blk_mq_free_tag_set(&dev->tagset);
2502 dev->ctrl.tagset = NULL;
2503}
2504
2493static void nvme_pci_free_ctrl(struct nvme_ctrl *ctrl) 2505static void nvme_pci_free_ctrl(struct nvme_ctrl *ctrl)
2494{ 2506{
2495 struct nvme_dev *dev = to_nvme_dev(ctrl); 2507 struct nvme_dev *dev = to_nvme_dev(ctrl);
2496 2508
2497 nvme_dbbuf_dma_free(dev); 2509 nvme_dbbuf_dma_free(dev);
2498 put_device(dev->dev); 2510 put_device(dev->dev);
2499 if (dev->tagset.tags) 2511 nvme_free_tagset(dev);
2500 blk_mq_free_tag_set(&dev->tagset);
2501 if (dev->ctrl.admin_q) 2512 if (dev->ctrl.admin_q)
2502 blk_put_queue(dev->ctrl.admin_q); 2513 blk_put_queue(dev->ctrl.admin_q);
2503 kfree(dev->queues); 2514 kfree(dev->queues);
@@ -2508,6 +2519,11 @@ static void nvme_pci_free_ctrl(struct nvme_ctrl *ctrl)
2508 2519
2509static void nvme_remove_dead_ctrl(struct nvme_dev *dev) 2520static void nvme_remove_dead_ctrl(struct nvme_dev *dev)
2510{ 2521{
2522 /*
2523 * Set state to deleting now to avoid blocking nvme_wait_reset(), which
2524 * may be holding this pci_dev's device lock.
2525 */
2526 nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_DELETING);
2511 nvme_get_ctrl(&dev->ctrl); 2527 nvme_get_ctrl(&dev->ctrl);
2512 nvme_dev_disable(dev, false); 2528 nvme_dev_disable(dev, false);
2513 nvme_kill_queues(&dev->ctrl); 2529 nvme_kill_queues(&dev->ctrl);
@@ -2521,7 +2537,6 @@ static void nvme_reset_work(struct work_struct *work)
2521 container_of(work, struct nvme_dev, ctrl.reset_work); 2537 container_of(work, struct nvme_dev, ctrl.reset_work);
2522 bool was_suspend = !!(dev->ctrl.ctrl_config & NVME_CC_SHN_NORMAL); 2538 bool was_suspend = !!(dev->ctrl.ctrl_config & NVME_CC_SHN_NORMAL);
2523 int result; 2539 int result;
2524 enum nvme_ctrl_state new_state = NVME_CTRL_LIVE;
2525 2540
2526 if (WARN_ON(dev->ctrl.state != NVME_CTRL_RESETTING)) { 2541 if (WARN_ON(dev->ctrl.state != NVME_CTRL_RESETTING)) {
2527 result = -ENODEV; 2542 result = -ENODEV;
@@ -2615,13 +2630,11 @@ static void nvme_reset_work(struct work_struct *work)
2615 dev_warn(dev->ctrl.device, "IO queues not created\n"); 2630 dev_warn(dev->ctrl.device, "IO queues not created\n");
2616 nvme_kill_queues(&dev->ctrl); 2631 nvme_kill_queues(&dev->ctrl);
2617 nvme_remove_namespaces(&dev->ctrl); 2632 nvme_remove_namespaces(&dev->ctrl);
2618 new_state = NVME_CTRL_ADMIN_ONLY; 2633 nvme_free_tagset(dev);
2619 } else { 2634 } else {
2620 nvme_start_queues(&dev->ctrl); 2635 nvme_start_queues(&dev->ctrl);
2621 nvme_wait_freeze(&dev->ctrl); 2636 nvme_wait_freeze(&dev->ctrl);
2622 /* hit this only when allocate tagset fails */ 2637 nvme_dev_add(dev);
2623 if (nvme_dev_add(dev))
2624 new_state = NVME_CTRL_ADMIN_ONLY;
2625 nvme_unfreeze(&dev->ctrl); 2638 nvme_unfreeze(&dev->ctrl);
2626 } 2639 }
2627 2640
@@ -2629,9 +2642,9 @@ static void nvme_reset_work(struct work_struct *work)
2629 * If only admin queue live, keep it to do further investigation or 2642 * If only admin queue live, keep it to do further investigation or
2630 * recovery. 2643 * recovery.
2631 */ 2644 */
2632 if (!nvme_change_ctrl_state(&dev->ctrl, new_state)) { 2645 if (!nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_LIVE)) {
2633 dev_warn(dev->ctrl.device, 2646 dev_warn(dev->ctrl.device,
2634 "failed to mark controller state %d\n", new_state); 2647 "failed to mark controller live state\n");
2635 result = -ENODEV; 2648 result = -ENODEV;
2636 goto out; 2649 goto out;
2637 } 2650 }
@@ -2672,7 +2685,7 @@ static int nvme_pci_reg_write32(struct nvme_ctrl *ctrl, u32 off, u32 val)
2672 2685
2673static int nvme_pci_reg_read64(struct nvme_ctrl *ctrl, u32 off, u64 *val) 2686static int nvme_pci_reg_read64(struct nvme_ctrl *ctrl, u32 off, u64 *val)
2674{ 2687{
2675 *val = readq(to_nvme_dev(ctrl)->bar + off); 2688 *val = lo_hi_readq(to_nvme_dev(ctrl)->bar + off);
2676 return 0; 2689 return 0;
2677} 2690}
2678 2691
@@ -2836,19 +2849,28 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2836static void nvme_reset_prepare(struct pci_dev *pdev) 2849static void nvme_reset_prepare(struct pci_dev *pdev)
2837{ 2850{
2838 struct nvme_dev *dev = pci_get_drvdata(pdev); 2851 struct nvme_dev *dev = pci_get_drvdata(pdev);
2839 nvme_dev_disable(dev, false); 2852
2853 /*
2854 * We don't need to check the return value from waiting for the reset
2855 * state as pci_dev device lock is held, making it impossible to race
2856 * with ->remove().
2857 */
2858 nvme_disable_prepare_reset(dev, false);
2859 nvme_sync_queues(&dev->ctrl);
2840} 2860}
2841 2861
2842static void nvme_reset_done(struct pci_dev *pdev) 2862static void nvme_reset_done(struct pci_dev *pdev)
2843{ 2863{
2844 struct nvme_dev *dev = pci_get_drvdata(pdev); 2864 struct nvme_dev *dev = pci_get_drvdata(pdev);
2845 nvme_reset_ctrl_sync(&dev->ctrl); 2865
2866 if (!nvme_try_sched_reset(&dev->ctrl))
2867 flush_work(&dev->ctrl.reset_work);
2846} 2868}
2847 2869
2848static void nvme_shutdown(struct pci_dev *pdev) 2870static void nvme_shutdown(struct pci_dev *pdev)
2849{ 2871{
2850 struct nvme_dev *dev = pci_get_drvdata(pdev); 2872 struct nvme_dev *dev = pci_get_drvdata(pdev);
2851 nvme_dev_disable(dev, true); 2873 nvme_disable_prepare_reset(dev, true);
2852} 2874}
2853 2875
2854/* 2876/*
@@ -2901,7 +2923,7 @@ static int nvme_resume(struct device *dev)
2901 2923
2902 if (ndev->last_ps == U32_MAX || 2924 if (ndev->last_ps == U32_MAX ||
2903 nvme_set_power_state(ctrl, ndev->last_ps) != 0) 2925 nvme_set_power_state(ctrl, ndev->last_ps) != 0)
2904 nvme_reset_ctrl(ctrl); 2926 return nvme_try_sched_reset(&ndev->ctrl);
2905 return 0; 2927 return 0;
2906} 2928}
2907 2929
@@ -2929,43 +2951,42 @@ static int nvme_suspend(struct device *dev)
2929 */ 2951 */
2930 if (pm_suspend_via_firmware() || !ctrl->npss || 2952 if (pm_suspend_via_firmware() || !ctrl->npss ||
2931 !pcie_aspm_enabled(pdev) || 2953 !pcie_aspm_enabled(pdev) ||
2932 (ndev->ctrl.quirks & NVME_QUIRK_SIMPLE_SUSPEND)) { 2954 (ndev->ctrl.quirks & NVME_QUIRK_SIMPLE_SUSPEND))
2933 nvme_dev_disable(ndev, true); 2955 return nvme_disable_prepare_reset(ndev, true);
2934 return 0;
2935 }
2936 2956
2937 nvme_start_freeze(ctrl); 2957 nvme_start_freeze(ctrl);
2938 nvme_wait_freeze(ctrl); 2958 nvme_wait_freeze(ctrl);
2939 nvme_sync_queues(ctrl); 2959 nvme_sync_queues(ctrl);
2940 2960
2941 if (ctrl->state != NVME_CTRL_LIVE && 2961 if (ctrl->state != NVME_CTRL_LIVE)
2942 ctrl->state != NVME_CTRL_ADMIN_ONLY)
2943 goto unfreeze; 2962 goto unfreeze;
2944 2963
2945 ret = nvme_get_power_state(ctrl, &ndev->last_ps); 2964 ret = nvme_get_power_state(ctrl, &ndev->last_ps);
2946 if (ret < 0) 2965 if (ret < 0)
2947 goto unfreeze; 2966 goto unfreeze;
2948 2967
2968 /*
2969 * A saved state prevents pci pm from generically controlling the
2970 * device's power. If we're using protocol specific settings, we don't
2971 * want pci interfering.
2972 */
2973 pci_save_state(pdev);
2974
2949 ret = nvme_set_power_state(ctrl, ctrl->npss); 2975 ret = nvme_set_power_state(ctrl, ctrl->npss);
2950 if (ret < 0) 2976 if (ret < 0)
2951 goto unfreeze; 2977 goto unfreeze;
2952 2978
2953 if (ret) { 2979 if (ret) {
2980 /* discard the saved state */
2981 pci_load_saved_state(pdev, NULL);
2982
2954 /* 2983 /*
2955 * Clearing npss forces a controller reset on resume. The 2984 * Clearing npss forces a controller reset on resume. The
2956 * correct value will be resdicovered then. 2985 * correct value will be resdicovered then.
2957 */ 2986 */
2958 nvme_dev_disable(ndev, true); 2987 ret = nvme_disable_prepare_reset(ndev, true);
2959 ctrl->npss = 0; 2988 ctrl->npss = 0;
2960 ret = 0;
2961 goto unfreeze;
2962 } 2989 }
2963 /*
2964 * A saved state prevents pci pm from generically controlling the
2965 * device's power. If we're using protocol specific settings, we don't
2966 * want pci interfering.
2967 */
2968 pci_save_state(pdev);
2969unfreeze: 2990unfreeze:
2970 nvme_unfreeze(ctrl); 2991 nvme_unfreeze(ctrl);
2971 return ret; 2992 return ret;
@@ -2974,9 +2995,7 @@ unfreeze:
2974static int nvme_simple_suspend(struct device *dev) 2995static int nvme_simple_suspend(struct device *dev)
2975{ 2996{
2976 struct nvme_dev *ndev = pci_get_drvdata(to_pci_dev(dev)); 2997 struct nvme_dev *ndev = pci_get_drvdata(to_pci_dev(dev));
2977 2998 return nvme_disable_prepare_reset(ndev, true);
2978 nvme_dev_disable(ndev, true);
2979 return 0;
2980} 2999}
2981 3000
2982static int nvme_simple_resume(struct device *dev) 3001static int nvme_simple_resume(struct device *dev)
@@ -2984,8 +3003,7 @@ static int nvme_simple_resume(struct device *dev)
2984 struct pci_dev *pdev = to_pci_dev(dev); 3003 struct pci_dev *pdev = to_pci_dev(dev);
2985 struct nvme_dev *ndev = pci_get_drvdata(pdev); 3004 struct nvme_dev *ndev = pci_get_drvdata(pdev);
2986 3005
2987 nvme_reset_ctrl(&ndev->ctrl); 3006 return nvme_try_sched_reset(&ndev->ctrl);
2988 return 0;
2989} 3007}
2990 3008
2991static const struct dev_pm_ops nvme_dev_pm_ops = { 3009static const struct dev_pm_ops nvme_dev_pm_ops = {
@@ -3090,6 +3108,9 @@ static const struct pci_device_id nvme_id_table[] = {
3090 .driver_data = NVME_QUIRK_LIGHTNVM, }, 3108 .driver_data = NVME_QUIRK_LIGHTNVM, },
3091 { PCI_DEVICE(0x10ec, 0x5762), /* ADATA SX6000LNP */ 3109 { PCI_DEVICE(0x10ec, 0x5762), /* ADATA SX6000LNP */
3092 .driver_data = NVME_QUIRK_IGNORE_DEV_SUBNQN, }, 3110 .driver_data = NVME_QUIRK_IGNORE_DEV_SUBNQN, },
3111 { PCI_DEVICE(0x1cc1, 0x8201), /* ADATA SX8200PNP 512GB */
3112 .driver_data = NVME_QUIRK_NO_DEEPEST_PS |
3113 NVME_QUIRK_IGNORE_DEV_SUBNQN, },
3093 { PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_EXPRESS, 0xffffff) }, 3114 { PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_EXPRESS, 0xffffff) },
3094 { PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x2001) }, 3115 { PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x2001) },
3095 { PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x2003) }, 3116 { PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x2003) },
diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
index dfa07bb9dfeb..f19a28b4e997 100644
--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c
@@ -427,7 +427,7 @@ static void nvme_rdma_destroy_queue_ib(struct nvme_rdma_queue *queue)
427static int nvme_rdma_get_max_fr_pages(struct ib_device *ibdev) 427static int nvme_rdma_get_max_fr_pages(struct ib_device *ibdev)
428{ 428{
429 return min_t(u32, NVME_RDMA_MAX_SEGMENTS, 429 return min_t(u32, NVME_RDMA_MAX_SEGMENTS,
430 ibdev->attrs.max_fast_reg_page_list_len); 430 ibdev->attrs.max_fast_reg_page_list_len - 1);
431} 431}
432 432
433static int nvme_rdma_create_queue_ib(struct nvme_rdma_queue *queue) 433static int nvme_rdma_create_queue_ib(struct nvme_rdma_queue *queue)
@@ -437,7 +437,7 @@ static int nvme_rdma_create_queue_ib(struct nvme_rdma_queue *queue)
437 const int cq_factor = send_wr_factor + 1; /* + RECV */ 437 const int cq_factor = send_wr_factor + 1; /* + RECV */
438 int comp_vector, idx = nvme_rdma_queue_idx(queue); 438 int comp_vector, idx = nvme_rdma_queue_idx(queue);
439 enum ib_poll_context poll_ctx; 439 enum ib_poll_context poll_ctx;
440 int ret; 440 int ret, pages_per_mr;
441 441
442 queue->device = nvme_rdma_find_get_device(queue->cm_id); 442 queue->device = nvme_rdma_find_get_device(queue->cm_id);
443 if (!queue->device) { 443 if (!queue->device) {
@@ -479,10 +479,16 @@ static int nvme_rdma_create_queue_ib(struct nvme_rdma_queue *queue)
479 goto out_destroy_qp; 479 goto out_destroy_qp;
480 } 480 }
481 481
482 /*
483 * Currently we don't use SG_GAPS MR's so if the first entry is
484 * misaligned we'll end up using two entries for a single data page,
485 * so one additional entry is required.
486 */
487 pages_per_mr = nvme_rdma_get_max_fr_pages(ibdev) + 1;
482 ret = ib_mr_pool_init(queue->qp, &queue->qp->rdma_mrs, 488 ret = ib_mr_pool_init(queue->qp, &queue->qp->rdma_mrs,
483 queue->queue_size, 489 queue->queue_size,
484 IB_MR_TYPE_MEM_REG, 490 IB_MR_TYPE_MEM_REG,
485 nvme_rdma_get_max_fr_pages(ibdev), 0); 491 pages_per_mr, 0);
486 if (ret) { 492 if (ret) {
487 dev_err(queue->ctrl->ctrl.device, 493 dev_err(queue->ctrl->ctrl.device,
488 "failed to initialize MR pool sized %d for QID %d\n", 494 "failed to initialize MR pool sized %d for QID %d\n",
@@ -614,7 +620,8 @@ static int nvme_rdma_start_queue(struct nvme_rdma_ctrl *ctrl, int idx)
614 if (!ret) { 620 if (!ret) {
615 set_bit(NVME_RDMA_Q_LIVE, &queue->flags); 621 set_bit(NVME_RDMA_Q_LIVE, &queue->flags);
616 } else { 622 } else {
617 __nvme_rdma_stop_queue(queue); 623 if (test_bit(NVME_RDMA_Q_ALLOCATED, &queue->flags))
624 __nvme_rdma_stop_queue(queue);
618 dev_info(ctrl->ctrl.device, 625 dev_info(ctrl->ctrl.device,
619 "failed to connect queue: %d ret=%d\n", idx, ret); 626 "failed to connect queue: %d ret=%d\n", idx, ret);
620 } 627 }
@@ -820,8 +827,8 @@ static int nvme_rdma_configure_admin_queue(struct nvme_rdma_ctrl *ctrl,
820 if (error) 827 if (error)
821 goto out_stop_queue; 828 goto out_stop_queue;
822 829
823 ctrl->ctrl.max_hw_sectors = 830 ctrl->ctrl.max_segments = ctrl->max_fr_pages;
824 (ctrl->max_fr_pages - 1) << (ilog2(SZ_4K) - 9); 831 ctrl->ctrl.max_hw_sectors = ctrl->max_fr_pages << (ilog2(SZ_4K) - 9);
825 832
826 blk_mq_unquiesce_queue(ctrl->ctrl.admin_q); 833 blk_mq_unquiesce_queue(ctrl->ctrl.admin_q);
827 834
@@ -1694,6 +1701,14 @@ nvme_rdma_timeout(struct request *rq, bool reserved)
1694 dev_warn(ctrl->ctrl.device, "I/O %d QID %d timeout\n", 1701 dev_warn(ctrl->ctrl.device, "I/O %d QID %d timeout\n",
1695 rq->tag, nvme_rdma_queue_idx(queue)); 1702 rq->tag, nvme_rdma_queue_idx(queue));
1696 1703
1704 /*
1705 * Restart the timer if a controller reset is already scheduled. Any
1706 * timed out commands would be handled before entering the connecting
1707 * state.
1708 */
1709 if (ctrl->ctrl.state == NVME_CTRL_RESETTING)
1710 return BLK_EH_RESET_TIMER;
1711
1697 if (ctrl->ctrl.state != NVME_CTRL_LIVE) { 1712 if (ctrl->ctrl.state != NVME_CTRL_LIVE) {
1698 /* 1713 /*
1699 * Teardown immediately if controller times out while starting 1714 * Teardown immediately if controller times out while starting
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 4ffd5957637a..7544be84ab35 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -1042,7 +1042,7 @@ static void nvme_tcp_io_work(struct work_struct *w)
1042{ 1042{
1043 struct nvme_tcp_queue *queue = 1043 struct nvme_tcp_queue *queue =
1044 container_of(w, struct nvme_tcp_queue, io_work); 1044 container_of(w, struct nvme_tcp_queue, io_work);
1045 unsigned long start = jiffies + msecs_to_jiffies(1); 1045 unsigned long deadline = jiffies + msecs_to_jiffies(1);
1046 1046
1047 do { 1047 do {
1048 bool pending = false; 1048 bool pending = false;
@@ -1067,7 +1067,7 @@ static void nvme_tcp_io_work(struct work_struct *w)
1067 if (!pending) 1067 if (!pending)
1068 return; 1068 return;
1069 1069
1070 } while (time_after(jiffies, start)); /* quota is exhausted */ 1070 } while (!time_after(jiffies, deadline)); /* quota is exhausted */
1071 1071
1072 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); 1072 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work);
1073} 1073}
@@ -1386,7 +1386,9 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
1386 queue->sock->sk->sk_data_ready = nvme_tcp_data_ready; 1386 queue->sock->sk->sk_data_ready = nvme_tcp_data_ready;
1387 queue->sock->sk->sk_state_change = nvme_tcp_state_change; 1387 queue->sock->sk->sk_state_change = nvme_tcp_state_change;
1388 queue->sock->sk->sk_write_space = nvme_tcp_write_space; 1388 queue->sock->sk->sk_write_space = nvme_tcp_write_space;
1389#ifdef CONFIG_NET_RX_BUSY_POLL
1389 queue->sock->sk->sk_ll_usec = 1; 1390 queue->sock->sk->sk_ll_usec = 1;
1391#endif
1390 write_unlock_bh(&queue->sock->sk->sk_callback_lock); 1392 write_unlock_bh(&queue->sock->sk->sk_callback_lock);
1391 1393
1392 return 0; 1394 return 0;
@@ -2044,6 +2046,14 @@ nvme_tcp_timeout(struct request *rq, bool reserved)
2044 struct nvme_tcp_ctrl *ctrl = req->queue->ctrl; 2046 struct nvme_tcp_ctrl *ctrl = req->queue->ctrl;
2045 struct nvme_tcp_cmd_pdu *pdu = req->pdu; 2047 struct nvme_tcp_cmd_pdu *pdu = req->pdu;
2046 2048
2049 /*
2050 * Restart the timer if a controller reset is already scheduled. Any
2051 * timed out commands would be handled before entering the connecting
2052 * state.
2053 */
2054 if (ctrl->ctrl.state == NVME_CTRL_RESETTING)
2055 return BLK_EH_RESET_TIMER;
2056
2047 dev_warn(ctrl->ctrl.device, 2057 dev_warn(ctrl->ctrl.device,
2048 "queue %d: timeout request %#x type %d\n", 2058 "queue %d: timeout request %#x type %d\n",
2049 nvme_tcp_queue_id(req->queue), rq->tag, pdu->hdr.type); 2059 nvme_tcp_queue_id(req->queue), rq->tag, pdu->hdr.type);
@@ -2126,6 +2136,7 @@ static blk_status_t nvme_tcp_setup_cmd_pdu(struct nvme_ns *ns,
2126 2136
2127 ret = nvme_tcp_map_data(queue, rq); 2137 ret = nvme_tcp_map_data(queue, rq);
2128 if (unlikely(ret)) { 2138 if (unlikely(ret)) {
2139 nvme_cleanup_cmd(rq);
2129 dev_err(queue->ctrl->ctrl.device, 2140 dev_err(queue->ctrl->ctrl.device,
2130 "Failed to map data (%d)\n", ret); 2141 "Failed to map data (%d)\n", ret);
2131 return ret; 2142 return ret;
@@ -2208,7 +2219,7 @@ static int nvme_tcp_poll(struct blk_mq_hw_ctx *hctx)
2208 struct nvme_tcp_queue *queue = hctx->driver_data; 2219 struct nvme_tcp_queue *queue = hctx->driver_data;
2209 struct sock *sk = queue->sock->sk; 2220 struct sock *sk = queue->sock->sk;
2210 2221
2211 if (sk_can_busy_loop(sk) && skb_queue_empty(&sk->sk_receive_queue)) 2222 if (sk_can_busy_loop(sk) && skb_queue_empty_lockless(&sk->sk_receive_queue))
2212 sk_busy_loop(sk, true); 2223 sk_busy_loop(sk, true);
2213 nvme_tcp_try_recv(queue); 2224 nvme_tcp_try_recv(queue);
2214 return queue->nr_cqe; 2225 return queue->nr_cqe;
diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c
index de0bff70ebb6..32008d85172b 100644
--- a/drivers/nvme/target/io-cmd-bdev.c
+++ b/drivers/nvme/target/io-cmd-bdev.c
@@ -11,10 +11,10 @@
11void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id) 11void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id)
12{ 12{
13 const struct queue_limits *ql = &bdev_get_queue(bdev)->limits; 13 const struct queue_limits *ql = &bdev_get_queue(bdev)->limits;
14 /* Number of physical blocks per logical block. */ 14 /* Number of logical blocks per physical block. */
15 const u32 ppl = ql->physical_block_size / ql->logical_block_size; 15 const u32 lpp = ql->physical_block_size / ql->logical_block_size;
16 /* Physical blocks per logical block, 0's based. */ 16 /* Logical blocks per physical block, 0's based. */
17 const __le16 ppl0b = to0based(ppl); 17 const __le16 lpp0b = to0based(lpp);
18 18
19 /* 19 /*
20 * For NVMe 1.2 and later, bit 1 indicates that the fields NAWUN, 20 * For NVMe 1.2 and later, bit 1 indicates that the fields NAWUN,
@@ -25,9 +25,9 @@ void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id)
25 * field from the identify controller data structure should be used. 25 * field from the identify controller data structure should be used.
26 */ 26 */
27 id->nsfeat |= 1 << 1; 27 id->nsfeat |= 1 << 1;
28 id->nawun = ppl0b; 28 id->nawun = lpp0b;
29 id->nawupf = ppl0b; 29 id->nawupf = lpp0b;
30 id->nacwu = ppl0b; 30 id->nacwu = lpp0b;
31 31
32 /* 32 /*
33 * Bit 4 indicates that the fields NPWG, NPWA, NPDG, NPDA, and 33 * Bit 4 indicates that the fields NPWG, NPWA, NPDG, NPDA, and
@@ -36,7 +36,7 @@ void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id)
36 */ 36 */
37 id->nsfeat |= 1 << 4; 37 id->nsfeat |= 1 << 4;
38 /* NPWG = Namespace Preferred Write Granularity. 0's based */ 38 /* NPWG = Namespace Preferred Write Granularity. 0's based */
39 id->npwg = ppl0b; 39 id->npwg = lpp0b;
40 /* NPWA = Namespace Preferred Write Alignment. 0's based */ 40 /* NPWA = Namespace Preferred Write Alignment. 0's based */
41 id->npwa = id->npwg; 41 id->npwa = id->npwg;
42 /* NPDG = Namespace Preferred Deallocate Granularity. 0's based */ 42 /* NPDG = Namespace Preferred Deallocate Granularity. 0's based */
diff --git a/drivers/nvme/target/loop.c b/drivers/nvme/target/loop.c
index 748a39fca771..11f5aea97d1b 100644
--- a/drivers/nvme/target/loop.c
+++ b/drivers/nvme/target/loop.c
@@ -157,8 +157,10 @@ static blk_status_t nvme_loop_queue_rq(struct blk_mq_hw_ctx *hctx,
157 iod->sg_table.sgl = iod->first_sgl; 157 iod->sg_table.sgl = iod->first_sgl;
158 if (sg_alloc_table_chained(&iod->sg_table, 158 if (sg_alloc_table_chained(&iod->sg_table,
159 blk_rq_nr_phys_segments(req), 159 blk_rq_nr_phys_segments(req),
160 iod->sg_table.sgl, SG_CHUNK_SIZE)) 160 iod->sg_table.sgl, SG_CHUNK_SIZE)) {
161 nvme_cleanup_cmd(req);
161 return BLK_STS_RESOURCE; 162 return BLK_STS_RESOURCE;
163 }
162 164
163 iod->req.sg = iod->sg_table.sgl; 165 iod->req.sg = iod->sg_table.sgl;
164 iod->req.sg_cnt = blk_rq_map_sg(req->q, req, iod->sg_table.sgl); 166 iod->req.sg_cnt = blk_rq_map_sg(req->q, req, iod->sg_table.sgl);
diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c
index bf4f03474e89..d535080b781f 100644
--- a/drivers/nvme/target/tcp.c
+++ b/drivers/nvme/target/tcp.c
@@ -348,8 +348,7 @@ static int nvmet_tcp_map_data(struct nvmet_tcp_cmd *cmd)
348 348
349 return 0; 349 return 0;
350err: 350err:
351 if (cmd->req.sg_cnt) 351 sgl_free(cmd->req.sg);
352 sgl_free(cmd->req.sg);
353 return NVME_SC_INTERNAL; 352 return NVME_SC_INTERNAL;
354} 353}
355 354
@@ -554,8 +553,7 @@ static int nvmet_try_send_data(struct nvmet_tcp_cmd *cmd)
554 553
555 if (queue->nvme_sq.sqhd_disabled) { 554 if (queue->nvme_sq.sqhd_disabled) {
556 kfree(cmd->iov); 555 kfree(cmd->iov);
557 if (cmd->req.sg_cnt) 556 sgl_free(cmd->req.sg);
558 sgl_free(cmd->req.sg);
559 } 557 }
560 558
561 return 1; 559 return 1;
@@ -586,8 +584,7 @@ static int nvmet_try_send_response(struct nvmet_tcp_cmd *cmd,
586 return -EAGAIN; 584 return -EAGAIN;
587 585
588 kfree(cmd->iov); 586 kfree(cmd->iov);
589 if (cmd->req.sg_cnt) 587 sgl_free(cmd->req.sg);
590 sgl_free(cmd->req.sg);
591 cmd->queue->snd_cmd = NULL; 588 cmd->queue->snd_cmd = NULL;
592 nvmet_tcp_put_cmd(cmd); 589 nvmet_tcp_put_cmd(cmd);
593 return 1; 590 return 1;
@@ -1310,8 +1307,7 @@ static void nvmet_tcp_finish_cmd(struct nvmet_tcp_cmd *cmd)
1310 nvmet_req_uninit(&cmd->req); 1307 nvmet_req_uninit(&cmd->req);
1311 nvmet_tcp_unmap_pdu_iovec(cmd); 1308 nvmet_tcp_unmap_pdu_iovec(cmd);
1312 kfree(cmd->iov); 1309 kfree(cmd->iov);
1313 if (cmd->req.sg_cnt) 1310 sgl_free(cmd->req.sg);
1314 sgl_free(cmd->req.sg);
1315} 1311}
1316 1312
1317static void nvmet_tcp_uninit_data_in_cmds(struct nvmet_tcp_queue *queue) 1313static void nvmet_tcp_uninit_data_in_cmds(struct nvmet_tcp_queue *queue)
diff --git a/drivers/parisc/sba_iommu.c b/drivers/parisc/sba_iommu.c
index ed50502cc65a..de8e4e347249 100644
--- a/drivers/parisc/sba_iommu.c
+++ b/drivers/parisc/sba_iommu.c
@@ -678,14 +678,6 @@ static int sba_dma_supported( struct device *dev, u64 mask)
678 return(0); 678 return(0);
679 } 679 }
680 680
681 /* Documentation/DMA-API-HOWTO.txt tells drivers to try 64-bit
682 * first, then fall back to 32-bit if that fails.
683 * We are just "encouraging" 32-bit DMA masks here since we can
684 * never allow IOMMU bypass unless we add special support for ZX1.
685 */
686 if (mask > ~0U)
687 return 0;
688
689 ioc = GET_IOC(dev); 681 ioc = GET_IOC(dev);
690 if (!ioc) 682 if (!ioc)
691 return 0; 683 return 0;
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e7982af9a5d8..a97e2571a527 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -959,19 +959,6 @@ void pci_refresh_power_state(struct pci_dev *dev)
959} 959}
960 960
961/** 961/**
962 * pci_power_up - Put the given device into D0 forcibly
963 * @dev: PCI device to power up
964 */
965void pci_power_up(struct pci_dev *dev)
966{
967 if (platform_pci_power_manageable(dev))
968 platform_pci_set_power_state(dev, PCI_D0);
969
970 pci_raw_set_power_state(dev, PCI_D0);
971 pci_update_current_state(dev, PCI_D0);
972}
973
974/**
975 * pci_platform_power_transition - Use platform to change device power state 962 * pci_platform_power_transition - Use platform to change device power state
976 * @dev: PCI device to handle. 963 * @dev: PCI device to handle.
977 * @state: State to put the device into. 964 * @state: State to put the device into.
@@ -1154,6 +1141,17 @@ int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
1154EXPORT_SYMBOL(pci_set_power_state); 1141EXPORT_SYMBOL(pci_set_power_state);
1155 1142
1156/** 1143/**
1144 * pci_power_up - Put the given device into D0 forcibly
1145 * @dev: PCI device to power up
1146 */
1147void pci_power_up(struct pci_dev *dev)
1148{
1149 __pci_start_power_transition(dev, PCI_D0);
1150 pci_raw_set_power_state(dev, PCI_D0);
1151 pci_update_current_state(dev, PCI_D0);
1152}
1153
1154/**
1157 * pci_choose_state - Choose the power state of a PCI device 1155 * pci_choose_state - Choose the power state of a PCI device
1158 * @dev: PCI device to be suspended 1156 * @dev: PCI device to be suspended
1159 * @state: target sleep state for the whole system. This is the value 1157 * @state: target sleep state for the whole system. This is the value
diff --git a/drivers/platform/x86/classmate-laptop.c b/drivers/platform/x86/classmate-laptop.c
index 86cc2cc68fb5..af063f690846 100644
--- a/drivers/platform/x86/classmate-laptop.c
+++ b/drivers/platform/x86/classmate-laptop.c
@@ -420,12 +420,6 @@ failed_sensitivity:
420 420
421static int cmpc_accel_remove_v4(struct acpi_device *acpi) 421static int cmpc_accel_remove_v4(struct acpi_device *acpi)
422{ 422{
423 struct input_dev *inputdev;
424 struct cmpc_accel *accel;
425
426 inputdev = dev_get_drvdata(&acpi->dev);
427 accel = dev_get_drvdata(&inputdev->dev);
428
429 device_remove_file(&acpi->dev, &cmpc_accel_sensitivity_attr_v4); 423 device_remove_file(&acpi->dev, &cmpc_accel_sensitivity_attr_v4);
430 device_remove_file(&acpi->dev, &cmpc_accel_g_select_attr_v4); 424 device_remove_file(&acpi->dev, &cmpc_accel_g_select_attr_v4);
431 return cmpc_remove_acpi_notify_device(acpi); 425 return cmpc_remove_acpi_notify_device(acpi);
@@ -656,12 +650,6 @@ failed_file:
656 650
657static int cmpc_accel_remove(struct acpi_device *acpi) 651static int cmpc_accel_remove(struct acpi_device *acpi)
658{ 652{
659 struct input_dev *inputdev;
660 struct cmpc_accel *accel;
661
662 inputdev = dev_get_drvdata(&acpi->dev);
663 accel = dev_get_drvdata(&inputdev->dev);
664
665 device_remove_file(&acpi->dev, &cmpc_accel_sensitivity_attr); 653 device_remove_file(&acpi->dev, &cmpc_accel_sensitivity_attr);
666 return cmpc_remove_acpi_notify_device(acpi); 654 return cmpc_remove_acpi_notify_device(acpi);
667} 655}
diff --git a/drivers/platform/x86/i2c-multi-instantiate.c b/drivers/platform/x86/i2c-multi-instantiate.c
index ea68f6ed66ae..ffb8d5d1eb5f 100644
--- a/drivers/platform/x86/i2c-multi-instantiate.c
+++ b/drivers/platform/x86/i2c-multi-instantiate.c
@@ -108,6 +108,7 @@ static int i2c_multi_inst_probe(struct platform_device *pdev)
108 if (ret < 0) { 108 if (ret < 0) {
109 dev_dbg(dev, "Error requesting irq at index %d: %d\n", 109 dev_dbg(dev, "Error requesting irq at index %d: %d\n",
110 inst_data[i].irq_idx, ret); 110 inst_data[i].irq_idx, ret);
111 goto error;
111 } 112 }
112 board_info.irq = ret; 113 board_info.irq = ret;
113 break; 114 break;
diff --git a/drivers/platform/x86/intel_punit_ipc.c b/drivers/platform/x86/intel_punit_ipc.c
index ab7ae1950867..fa97834fdb78 100644
--- a/drivers/platform/x86/intel_punit_ipc.c
+++ b/drivers/platform/x86/intel_punit_ipc.c
@@ -293,9 +293,8 @@ static int intel_punit_ipc_probe(struct platform_device *pdev)
293 293
294 platform_set_drvdata(pdev, punit_ipcdev); 294 platform_set_drvdata(pdev, punit_ipcdev);
295 295
296 irq = platform_get_irq(pdev, 0); 296 irq = platform_get_irq_optional(pdev, 0);
297 if (irq < 0) { 297 if (irq < 0) {
298 punit_ipcdev->irq = 0;
299 dev_warn(&pdev->dev, "Invalid IRQ, using polling mode\n"); 298 dev_warn(&pdev->dev, "Invalid IRQ, using polling mode\n");
300 } else { 299 } else {
301 ret = devm_request_irq(&pdev->dev, irq, intel_punit_ioc, 300 ret = devm_request_irq(&pdev->dev, irq, intel_punit_ioc,
diff --git a/drivers/ptp/Kconfig b/drivers/ptp/Kconfig
index 960961fb0d7c..0517272a268e 100644
--- a/drivers/ptp/Kconfig
+++ b/drivers/ptp/Kconfig
@@ -97,8 +97,8 @@ config PTP_1588_CLOCK_PCH
97 help 97 help
98 This driver adds support for using the PCH EG20T as a PTP 98 This driver adds support for using the PCH EG20T as a PTP
99 clock. The hardware supports time stamping of PTP packets 99 clock. The hardware supports time stamping of PTP packets
100 when using the end-to-end delay (E2E) mechansim. The peer 100 when using the end-to-end delay (E2E) mechanism. The peer
101 delay mechansim (P2P) is not supported. 101 delay mechanism (P2P) is not supported.
102 102
103 This clock is only useful if your PTP programs are getting 103 This clock is only useful if your PTP programs are getting
104 hardware time stamps on the PTP Ethernet packets using the 104 hardware time stamps on the PTP Ethernet packets using the
diff --git a/drivers/ptp/ptp_qoriq.c b/drivers/ptp/ptp_qoriq.c
index c61f00b72e15..a577218d1ab7 100644
--- a/drivers/ptp/ptp_qoriq.c
+++ b/drivers/ptp/ptp_qoriq.c
@@ -507,6 +507,8 @@ int ptp_qoriq_init(struct ptp_qoriq *ptp_qoriq, void __iomem *base,
507 ptp_qoriq->regs.etts_regs = base + ETTS_REGS_OFFSET; 507 ptp_qoriq->regs.etts_regs = base + ETTS_REGS_OFFSET;
508 } 508 }
509 509
510 spin_lock_init(&ptp_qoriq->lock);
511
510 ktime_get_real_ts64(&now); 512 ktime_get_real_ts64(&now);
511 ptp_qoriq_settime(&ptp_qoriq->caps, &now); 513 ptp_qoriq_settime(&ptp_qoriq->caps, &now);
512 514
@@ -514,7 +516,6 @@ int ptp_qoriq_init(struct ptp_qoriq *ptp_qoriq, void __iomem *base,
514 (ptp_qoriq->tclk_period & TCLK_PERIOD_MASK) << TCLK_PERIOD_SHIFT | 516 (ptp_qoriq->tclk_period & TCLK_PERIOD_MASK) << TCLK_PERIOD_SHIFT |
515 (ptp_qoriq->cksel & CKSEL_MASK) << CKSEL_SHIFT; 517 (ptp_qoriq->cksel & CKSEL_MASK) << CKSEL_SHIFT;
516 518
517 spin_lock_init(&ptp_qoriq->lock);
518 spin_lock_irqsave(&ptp_qoriq->lock, flags); 519 spin_lock_irqsave(&ptp_qoriq->lock, flags);
519 520
520 regs = &ptp_qoriq->regs; 521 regs = &ptp_qoriq->regs;
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
index fc53e1e221f0..c94184d080f8 100644
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -1553,8 +1553,8 @@ static int dasd_eckd_read_vol_info(struct dasd_device *device)
1553 if (rc == 0) { 1553 if (rc == 0) {
1554 memcpy(&private->vsq, vsq, sizeof(*vsq)); 1554 memcpy(&private->vsq, vsq, sizeof(*vsq));
1555 } else { 1555 } else {
1556 dev_warn(&device->cdev->dev, 1556 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1557 "Reading the volume storage information failed with rc=%d\n", rc); 1557 "Reading the volume storage information failed with rc=%d", rc);
1558 } 1558 }
1559 1559
1560 if (useglobal) 1560 if (useglobal)
@@ -1737,8 +1737,8 @@ static int dasd_eckd_read_ext_pool_info(struct dasd_device *device)
1737 if (rc == 0) { 1737 if (rc == 0) {
1738 dasd_eckd_cpy_ext_pool_data(device, lcq); 1738 dasd_eckd_cpy_ext_pool_data(device, lcq);
1739 } else { 1739 } else {
1740 dev_warn(&device->cdev->dev, 1740 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1741 "Reading the logical configuration failed with rc=%d\n", rc); 1741 "Reading the logical configuration failed with rc=%d", rc);
1742 } 1742 }
1743 1743
1744 dasd_sfree_request(cqr, cqr->memdev); 1744 dasd_sfree_request(cqr, cqr->memdev);
@@ -2020,14 +2020,10 @@ dasd_eckd_check_characteristics(struct dasd_device *device)
2020 dasd_eckd_read_features(device); 2020 dasd_eckd_read_features(device);
2021 2021
2022 /* Read Volume Information */ 2022 /* Read Volume Information */
2023 rc = dasd_eckd_read_vol_info(device); 2023 dasd_eckd_read_vol_info(device);
2024 if (rc)
2025 goto out_err3;
2026 2024
2027 /* Read Extent Pool Information */ 2025 /* Read Extent Pool Information */
2028 rc = dasd_eckd_read_ext_pool_info(device); 2026 dasd_eckd_read_ext_pool_info(device);
2029 if (rc)
2030 goto out_err3;
2031 2027
2032 /* Read Device Characteristics */ 2028 /* Read Device Characteristics */
2033 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC, 2029 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
@@ -2059,9 +2055,6 @@ dasd_eckd_check_characteristics(struct dasd_device *device)
2059 if (readonly) 2055 if (readonly)
2060 set_bit(DASD_FLAG_DEVICE_RO, &device->flags); 2056 set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
2061 2057
2062 if (dasd_eckd_is_ese(device))
2063 dasd_set_feature(device->cdev, DASD_FEATURE_DISCARD, 1);
2064
2065 dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) " 2058 dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) "
2066 "with %d cylinders, %d heads, %d sectors%s\n", 2059 "with %d cylinders, %d heads, %d sectors%s\n",
2067 private->rdc_data.dev_type, 2060 private->rdc_data.dev_type,
@@ -3695,14 +3688,6 @@ static int dasd_eckd_release_space(struct dasd_device *device,
3695 return -EINVAL; 3688 return -EINVAL;
3696} 3689}
3697 3690
3698static struct dasd_ccw_req *
3699dasd_eckd_build_cp_discard(struct dasd_device *device, struct dasd_block *block,
3700 struct request *req, sector_t first_trk,
3701 sector_t last_trk)
3702{
3703 return dasd_eckd_dso_ras(device, block, req, first_trk, last_trk, 1);
3704}
3705
3706static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single( 3691static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
3707 struct dasd_device *startdev, 3692 struct dasd_device *startdev,
3708 struct dasd_block *block, 3693 struct dasd_block *block,
@@ -4447,10 +4432,6 @@ static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
4447 cmdwtd = private->features.feature[12] & 0x40; 4432 cmdwtd = private->features.feature[12] & 0x40;
4448 use_prefix = private->features.feature[8] & 0x01; 4433 use_prefix = private->features.feature[8] & 0x01;
4449 4434
4450 if (req_op(req) == REQ_OP_DISCARD)
4451 return dasd_eckd_build_cp_discard(startdev, block, req,
4452 first_trk, last_trk);
4453
4454 cqr = NULL; 4435 cqr = NULL;
4455 if (cdlspecial || dasd_page_cache) { 4436 if (cdlspecial || dasd_page_cache) {
4456 /* do nothing, just fall through to the cmd mode single case */ 4437 /* do nothing, just fall through to the cmd mode single case */
@@ -4729,14 +4710,12 @@ static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
4729 struct dasd_block *block, 4710 struct dasd_block *block,
4730 struct request *req) 4711 struct request *req)
4731{ 4712{
4732 struct dasd_device *startdev = NULL;
4733 struct dasd_eckd_private *private; 4713 struct dasd_eckd_private *private;
4734 struct dasd_ccw_req *cqr; 4714 struct dasd_device *startdev;
4735 unsigned long flags; 4715 unsigned long flags;
4716 struct dasd_ccw_req *cqr;
4736 4717
4737 /* Discard requests can only be processed on base devices */ 4718 startdev = dasd_alias_get_start_dev(base);
4738 if (req_op(req) != REQ_OP_DISCARD)
4739 startdev = dasd_alias_get_start_dev(base);
4740 if (!startdev) 4719 if (!startdev)
4741 startdev = base; 4720 startdev = base;
4742 private = startdev->private; 4721 private = startdev->private;
@@ -5663,14 +5642,10 @@ static int dasd_eckd_restore_device(struct dasd_device *device)
5663 dasd_eckd_read_features(device); 5642 dasd_eckd_read_features(device);
5664 5643
5665 /* Read Volume Information */ 5644 /* Read Volume Information */
5666 rc = dasd_eckd_read_vol_info(device); 5645 dasd_eckd_read_vol_info(device);
5667 if (rc)
5668 goto out_err2;
5669 5646
5670 /* Read Extent Pool Information */ 5647 /* Read Extent Pool Information */
5671 rc = dasd_eckd_read_ext_pool_info(device); 5648 dasd_eckd_read_ext_pool_info(device);
5672 if (rc)
5673 goto out_err2;
5674 5649
5675 /* Read Device Characteristics */ 5650 /* Read Device Characteristics */
5676 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC, 5651 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
@@ -6521,20 +6496,8 @@ static void dasd_eckd_setup_blk_queue(struct dasd_block *block)
6521 unsigned int logical_block_size = block->bp_block; 6496 unsigned int logical_block_size = block->bp_block;
6522 struct request_queue *q = block->request_queue; 6497 struct request_queue *q = block->request_queue;
6523 struct dasd_device *device = block->base; 6498 struct dasd_device *device = block->base;
6524 struct dasd_eckd_private *private;
6525 unsigned int max_discard_sectors;
6526 unsigned int max_bytes;
6527 unsigned int ext_bytes; /* Extent Size in Bytes */
6528 int recs_per_trk;
6529 int trks_per_cyl;
6530 int ext_limit;
6531 int ext_size; /* Extent Size in Cylinders */
6532 int max; 6499 int max;
6533 6500
6534 private = device->private;
6535 trks_per_cyl = private->rdc_data.trk_per_cyl;
6536 recs_per_trk = recs_per_track(&private->rdc_data, 0, logical_block_size);
6537
6538 if (device->features & DASD_FEATURE_USERAW) { 6501 if (device->features & DASD_FEATURE_USERAW) {
6539 /* 6502 /*
6540 * the max_blocks value for raw_track access is 256 6503 * the max_blocks value for raw_track access is 256
@@ -6555,28 +6518,6 @@ static void dasd_eckd_setup_blk_queue(struct dasd_block *block)
6555 /* With page sized segments each segment can be translated into one idaw/tidaw */ 6518 /* With page sized segments each segment can be translated into one idaw/tidaw */
6556 blk_queue_max_segment_size(q, PAGE_SIZE); 6519 blk_queue_max_segment_size(q, PAGE_SIZE);
6557 blk_queue_segment_boundary(q, PAGE_SIZE - 1); 6520 blk_queue_segment_boundary(q, PAGE_SIZE - 1);
6558
6559 if (dasd_eckd_is_ese(device)) {
6560 /*
6561 * Depending on the extent size, up to UINT_MAX bytes can be
6562 * accepted. However, neither DASD_ECKD_RAS_EXTS_MAX nor the
6563 * device limits should be exceeded.
6564 */
6565 ext_size = dasd_eckd_ext_size(device);
6566 ext_limit = min(private->real_cyl / ext_size, DASD_ECKD_RAS_EXTS_MAX);
6567 ext_bytes = ext_size * trks_per_cyl * recs_per_trk *
6568 logical_block_size;
6569 max_bytes = UINT_MAX - (UINT_MAX % ext_bytes);
6570 if (max_bytes / ext_bytes > ext_limit)
6571 max_bytes = ext_bytes * ext_limit;
6572
6573 max_discard_sectors = max_bytes / 512;
6574
6575 blk_queue_max_discard_sectors(q, max_discard_sectors);
6576 blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
6577 q->limits.discard_granularity = ext_bytes;
6578 q->limits.discard_alignment = ext_bytes;
6579 }
6580} 6521}
6581 6522
6582static struct ccw_driver dasd_eckd_driver = { 6523static struct ccw_driver dasd_eckd_driver = {
diff --git a/drivers/s390/cio/cio.h b/drivers/s390/cio/cio.h
index ba7d2480613b..dcdaba689b20 100644
--- a/drivers/s390/cio/cio.h
+++ b/drivers/s390/cio/cio.h
@@ -113,6 +113,7 @@ struct subchannel {
113 enum sch_todo todo; 113 enum sch_todo todo;
114 struct work_struct todo_work; 114 struct work_struct todo_work;
115 struct schib_config config; 115 struct schib_config config;
116 u64 dma_mask;
116 char *driver_override; /* Driver name to force a match */ 117 char *driver_override; /* Driver name to force a match */
117} __attribute__ ((aligned(8))); 118} __attribute__ ((aligned(8)));
118 119
diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c
index 1fbfb0a93f5f..831850435c23 100644
--- a/drivers/s390/cio/css.c
+++ b/drivers/s390/cio/css.c
@@ -232,7 +232,12 @@ struct subchannel *css_alloc_subchannel(struct subchannel_id schid,
232 * belong to a subchannel need to fit 31 bit width (e.g. ccw). 232 * belong to a subchannel need to fit 31 bit width (e.g. ccw).
233 */ 233 */
234 sch->dev.coherent_dma_mask = DMA_BIT_MASK(31); 234 sch->dev.coherent_dma_mask = DMA_BIT_MASK(31);
235 sch->dev.dma_mask = &sch->dev.coherent_dma_mask; 235 /*
236 * But we don't have such restrictions imposed on the stuff that
237 * is handled by the streaming API.
238 */
239 sch->dma_mask = DMA_BIT_MASK(64);
240 sch->dev.dma_mask = &sch->dma_mask;
236 return sch; 241 return sch;
237 242
238err: 243err:
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index 131430bd48d9..0c6245fc7706 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -710,7 +710,7 @@ static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch)
710 if (!cdev->private) 710 if (!cdev->private)
711 goto err_priv; 711 goto err_priv;
712 cdev->dev.coherent_dma_mask = sch->dev.coherent_dma_mask; 712 cdev->dev.coherent_dma_mask = sch->dev.coherent_dma_mask;
713 cdev->dev.dma_mask = &cdev->dev.coherent_dma_mask; 713 cdev->dev.dma_mask = sch->dev.dma_mask;
714 dma_pool = cio_gp_dma_create(&cdev->dev, 1); 714 dma_pool = cio_gp_dma_create(&cdev->dev, 1);
715 if (!dma_pool) 715 if (!dma_pool)
716 goto err_dma_pool; 716 goto err_dma_pool;
diff --git a/drivers/s390/cio/qdio_setup.c b/drivers/s390/cio/qdio_setup.c
index f4ca1d29d61b..cd164886132f 100644
--- a/drivers/s390/cio/qdio_setup.c
+++ b/drivers/s390/cio/qdio_setup.c
@@ -113,7 +113,7 @@ static void set_impl_params(struct qdio_irq *irq_ptr,
113 irq_ptr->qib.pfmt = qib_param_field_format; 113 irq_ptr->qib.pfmt = qib_param_field_format;
114 if (qib_param_field) 114 if (qib_param_field)
115 memcpy(irq_ptr->qib.parm, qib_param_field, 115 memcpy(irq_ptr->qib.parm, qib_param_field,
116 QDIO_MAX_BUFFERS_PER_Q); 116 sizeof(irq_ptr->qib.parm));
117 117
118 if (!input_slib_elements) 118 if (!input_slib_elements)
119 goto output; 119 goto output;
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index a7868c8133ee..dda274351c21 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -4715,8 +4715,7 @@ static int qeth_qdio_establish(struct qeth_card *card)
4715 4715
4716 QETH_CARD_TEXT(card, 2, "qdioest"); 4716 QETH_CARD_TEXT(card, 2, "qdioest");
4717 4717
4718 qib_param_field = kzalloc(QDIO_MAX_BUFFERS_PER_Q, 4718 qib_param_field = kzalloc(FIELD_SIZEOF(struct qib, parm), GFP_KERNEL);
4719 GFP_KERNEL);
4720 if (!qib_param_field) { 4719 if (!qib_param_field) {
4721 rc = -ENOMEM; 4720 rc = -ENOMEM;
4722 goto out_free_nothing; 4721 goto out_free_nothing;
diff --git a/drivers/s390/net/qeth_l2_main.c b/drivers/s390/net/qeth_l2_main.c
index b8799cd3e7aa..bd8143e51747 100644
--- a/drivers/s390/net/qeth_l2_main.c
+++ b/drivers/s390/net/qeth_l2_main.c
@@ -2021,10 +2021,10 @@ static bool qeth_l2_vnicc_recover_char(struct qeth_card *card, u32 vnicc,
2021static void qeth_l2_vnicc_init(struct qeth_card *card) 2021static void qeth_l2_vnicc_init(struct qeth_card *card)
2022{ 2022{
2023 u32 *timeout = &card->options.vnicc.learning_timeout; 2023 u32 *timeout = &card->options.vnicc.learning_timeout;
2024 bool enable, error = false;
2024 unsigned int chars_len, i; 2025 unsigned int chars_len, i;
2025 unsigned long chars_tmp; 2026 unsigned long chars_tmp;
2026 u32 sup_cmds, vnicc; 2027 u32 sup_cmds, vnicc;
2027 bool enable, error;
2028 2028
2029 QETH_CARD_TEXT(card, 2, "vniccini"); 2029 QETH_CARD_TEXT(card, 2, "vniccini");
2030 /* reset rx_bcast */ 2030 /* reset rx_bcast */
@@ -2045,17 +2045,24 @@ static void qeth_l2_vnicc_init(struct qeth_card *card)
2045 chars_len = sizeof(card->options.vnicc.sup_chars) * BITS_PER_BYTE; 2045 chars_len = sizeof(card->options.vnicc.sup_chars) * BITS_PER_BYTE;
2046 for_each_set_bit(i, &chars_tmp, chars_len) { 2046 for_each_set_bit(i, &chars_tmp, chars_len) {
2047 vnicc = BIT(i); 2047 vnicc = BIT(i);
2048 qeth_l2_vnicc_query_cmds(card, vnicc, &sup_cmds); 2048 if (qeth_l2_vnicc_query_cmds(card, vnicc, &sup_cmds)) {
2049 if (!(sup_cmds & IPA_VNICC_SET_TIMEOUT) || 2049 sup_cmds = 0;
2050 !(sup_cmds & IPA_VNICC_GET_TIMEOUT)) 2050 error = true;
2051 }
2052 if ((sup_cmds & IPA_VNICC_SET_TIMEOUT) &&
2053 (sup_cmds & IPA_VNICC_GET_TIMEOUT))
2054 card->options.vnicc.getset_timeout_sup |= vnicc;
2055 else
2051 card->options.vnicc.getset_timeout_sup &= ~vnicc; 2056 card->options.vnicc.getset_timeout_sup &= ~vnicc;
2052 if (!(sup_cmds & IPA_VNICC_ENABLE) || 2057 if ((sup_cmds & IPA_VNICC_ENABLE) &&
2053 !(sup_cmds & IPA_VNICC_DISABLE)) 2058 (sup_cmds & IPA_VNICC_DISABLE))
2059 card->options.vnicc.set_char_sup |= vnicc;
2060 else
2054 card->options.vnicc.set_char_sup &= ~vnicc; 2061 card->options.vnicc.set_char_sup &= ~vnicc;
2055 } 2062 }
2056 /* enforce assumed default values and recover settings, if changed */ 2063 /* enforce assumed default values and recover settings, if changed */
2057 error = qeth_l2_vnicc_recover_timeout(card, QETH_VNICC_LEARNING, 2064 error |= qeth_l2_vnicc_recover_timeout(card, QETH_VNICC_LEARNING,
2058 timeout); 2065 timeout);
2059 chars_tmp = card->options.vnicc.wanted_chars ^ QETH_VNICC_DEFAULT; 2066 chars_tmp = card->options.vnicc.wanted_chars ^ QETH_VNICC_DEFAULT;
2060 chars_tmp |= QETH_VNICC_BRIDGE_INVISIBLE; 2067 chars_tmp |= QETH_VNICC_BRIDGE_INVISIBLE;
2061 chars_len = sizeof(card->options.vnicc.wanted_chars) * BITS_PER_BYTE; 2068 chars_len = sizeof(card->options.vnicc.wanted_chars) * BITS_PER_BYTE;
diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c
index 296bbc3c4606..cf63916814cc 100644
--- a/drivers/s390/scsi/zfcp_fsf.c
+++ b/drivers/s390/scsi/zfcp_fsf.c
@@ -27,6 +27,11 @@
27 27
28struct kmem_cache *zfcp_fsf_qtcb_cache; 28struct kmem_cache *zfcp_fsf_qtcb_cache;
29 29
30static bool ber_stop = true;
31module_param(ber_stop, bool, 0600);
32MODULE_PARM_DESC(ber_stop,
33 "Shuts down FCP devices for FCP channels that report a bit-error count in excess of its threshold (default on)");
34
30static void zfcp_fsf_request_timeout_handler(struct timer_list *t) 35static void zfcp_fsf_request_timeout_handler(struct timer_list *t)
31{ 36{
32 struct zfcp_fsf_req *fsf_req = from_timer(fsf_req, t, timer); 37 struct zfcp_fsf_req *fsf_req = from_timer(fsf_req, t, timer);
@@ -236,10 +241,15 @@ static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
236 case FSF_STATUS_READ_SENSE_DATA_AVAIL: 241 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
237 break; 242 break;
238 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD: 243 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
239 dev_warn(&adapter->ccw_device->dev,
240 "The error threshold for checksum statistics "
241 "has been exceeded\n");
242 zfcp_dbf_hba_bit_err("fssrh_3", req); 244 zfcp_dbf_hba_bit_err("fssrh_3", req);
245 if (ber_stop) {
246 dev_warn(&adapter->ccw_device->dev,
247 "All paths over this FCP device are disused because of excessive bit errors\n");
248 zfcp_erp_adapter_shutdown(adapter, 0, "fssrh_b");
249 } else {
250 dev_warn(&adapter->ccw_device->dev,
251 "The error threshold for checksum statistics has been exceeded\n");
252 }
243 break; 253 break;
244 case FSF_STATUS_READ_LINK_DOWN: 254 case FSF_STATUS_READ_LINK_DOWN:
245 zfcp_fsf_status_read_link_down(req); 255 zfcp_fsf_status_read_link_down(req);
diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c
index da00ca5fa5dc..401743e2b429 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_io.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_io.c
@@ -1923,6 +1923,7 @@ void bnx2fc_process_scsi_cmd_compl(struct bnx2fc_cmd *io_req,
1923 struct fcoe_fcp_rsp_payload *fcp_rsp; 1923 struct fcoe_fcp_rsp_payload *fcp_rsp;
1924 struct bnx2fc_rport *tgt = io_req->tgt; 1924 struct bnx2fc_rport *tgt = io_req->tgt;
1925 struct scsi_cmnd *sc_cmd; 1925 struct scsi_cmnd *sc_cmd;
1926 u16 scope = 0, qualifier = 0;
1926 1927
1927 /* scsi_cmd_cmpl is called with tgt lock held */ 1928 /* scsi_cmd_cmpl is called with tgt lock held */
1928 1929
@@ -1990,12 +1991,30 @@ void bnx2fc_process_scsi_cmd_compl(struct bnx2fc_cmd *io_req,
1990 1991
1991 if (io_req->cdb_status == SAM_STAT_TASK_SET_FULL || 1992 if (io_req->cdb_status == SAM_STAT_TASK_SET_FULL ||
1992 io_req->cdb_status == SAM_STAT_BUSY) { 1993 io_req->cdb_status == SAM_STAT_BUSY) {
1993 /* Set the jiffies + retry_delay_timer * 100ms 1994 /* Newer array firmware with BUSY or
1994 for the rport/tgt */ 1995 * TASK_SET_FULL may return a status that needs
1995 tgt->retry_delay_timestamp = jiffies + 1996 * the scope bits masked.
1996 fcp_rsp->retry_delay_timer * HZ / 10; 1997 * Or a huge delay timestamp up to 27 minutes
1998 * can result.
1999 */
2000 if (fcp_rsp->retry_delay_timer) {
2001 /* Upper 2 bits */
2002 scope = fcp_rsp->retry_delay_timer
2003 & 0xC000;
2004 /* Lower 14 bits */
2005 qualifier = fcp_rsp->retry_delay_timer
2006 & 0x3FFF;
2007 }
2008 if (scope > 0 && qualifier > 0 &&
2009 qualifier <= 0x3FEF) {
2010 /* Set the jiffies +
2011 * retry_delay_timer * 100ms
2012 * for the rport/tgt
2013 */
2014 tgt->retry_delay_timestamp = jiffies +
2015 (qualifier * HZ / 10);
2016 }
1997 } 2017 }
1998
1999 } 2018 }
2000 if (io_req->fcp_resid) 2019 if (io_req->fcp_resid)
2001 scsi_set_resid(sc_cmd, io_req->fcp_resid); 2020 scsi_set_resid(sc_cmd, io_req->fcp_resid);
diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c
index d1513fdf1e00..0847e682797b 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
@@ -3683,7 +3683,7 @@ void hisi_sas_debugfs_work_handler(struct work_struct *work)
3683} 3683}
3684EXPORT_SYMBOL_GPL(hisi_sas_debugfs_work_handler); 3684EXPORT_SYMBOL_GPL(hisi_sas_debugfs_work_handler);
3685 3685
3686void hisi_sas_debugfs_release(struct hisi_hba *hisi_hba) 3686static void hisi_sas_debugfs_release(struct hisi_hba *hisi_hba)
3687{ 3687{
3688 struct device *dev = hisi_hba->dev; 3688 struct device *dev = hisi_hba->dev;
3689 int i; 3689 int i;
@@ -3705,7 +3705,7 @@ void hisi_sas_debugfs_release(struct hisi_hba *hisi_hba)
3705 devm_kfree(dev, hisi_hba->debugfs_port_reg[i]); 3705 devm_kfree(dev, hisi_hba->debugfs_port_reg[i]);
3706} 3706}
3707 3707
3708int hisi_sas_debugfs_alloc(struct hisi_hba *hisi_hba) 3708static int hisi_sas_debugfs_alloc(struct hisi_hba *hisi_hba)
3709{ 3709{
3710 const struct hisi_sas_hw *hw = hisi_hba->hw; 3710 const struct hisi_sas_hw *hw = hisi_hba->hw;
3711 struct device *dev = hisi_hba->dev; 3711 struct device *dev = hisi_hba->dev;
@@ -3796,7 +3796,7 @@ fail:
3796 return -ENOMEM; 3796 return -ENOMEM;
3797} 3797}
3798 3798
3799void hisi_sas_debugfs_bist_init(struct hisi_hba *hisi_hba) 3799static void hisi_sas_debugfs_bist_init(struct hisi_hba *hisi_hba)
3800{ 3800{
3801 hisi_hba->debugfs_bist_dentry = 3801 hisi_hba->debugfs_bist_dentry =
3802 debugfs_create_dir("bist", hisi_hba->debugfs_dir); 3802 debugfs_create_dir("bist", hisi_hba->debugfs_dir);
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 45a66048801b..ff6d4aa92421 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -4183,11 +4183,11 @@ megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4183 */ 4183 */
4184 if (pdev->subsystem_vendor == PCI_VENDOR_ID_COMPAQ && 4184 if (pdev->subsystem_vendor == PCI_VENDOR_ID_COMPAQ &&
4185 pdev->subsystem_device == 0xC000) 4185 pdev->subsystem_device == 0xC000)
4186 return -ENODEV; 4186 goto out_disable_device;
4187 /* Now check the magic signature byte */ 4187 /* Now check the magic signature byte */
4188 pci_read_config_word(pdev, PCI_CONF_AMISIG, &magic); 4188 pci_read_config_word(pdev, PCI_CONF_AMISIG, &magic);
4189 if (magic != HBA_SIGNATURE_471 && magic != HBA_SIGNATURE) 4189 if (magic != HBA_SIGNATURE_471 && magic != HBA_SIGNATURE)
4190 return -ENODEV; 4190 goto out_disable_device;
4191 /* Ok it is probably a megaraid */ 4191 /* Ok it is probably a megaraid */
4192 } 4192 }
4193 4193
diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c
index 1659d35cd37b..59ca98f12afd 100644
--- a/drivers/scsi/qedf/qedf_main.c
+++ b/drivers/scsi/qedf/qedf_main.c
@@ -596,7 +596,7 @@ static void qedf_dcbx_handler(void *dev, struct qed_dcbx_get *get, u32 mib_type)
596 tmp_prio = get->operational.app_prio.fcoe; 596 tmp_prio = get->operational.app_prio.fcoe;
597 if (qedf_default_prio > -1) 597 if (qedf_default_prio > -1)
598 qedf->prio = qedf_default_prio; 598 qedf->prio = qedf_default_prio;
599 else if (tmp_prio < 0 || tmp_prio > 7) { 599 else if (tmp_prio > 7) {
600 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, 600 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC,
601 "FIP/FCoE prio %d out of range, setting to %d.\n", 601 "FIP/FCoE prio %d out of range, setting to %d.\n",
602 tmp_prio, QEDF_DEFAULT_PRIO); 602 tmp_prio, QEDF_DEFAULT_PRIO);
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 8190c2a27584..30bafd9d21e9 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -2920,6 +2920,8 @@ qla24xx_vport_delete(struct fc_vport *fc_vport)
2920 struct qla_hw_data *ha = vha->hw; 2920 struct qla_hw_data *ha = vha->hw;
2921 uint16_t id = vha->vp_idx; 2921 uint16_t id = vha->vp_idx;
2922 2922
2923 set_bit(VPORT_DELETE, &vha->dpc_flags);
2924
2923 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) || 2925 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
2924 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags)) 2926 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
2925 msleep(1000); 2927 msleep(1000);
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 873a6aef1c5c..6ffa9877c28b 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -2396,6 +2396,7 @@ typedef struct fc_port {
2396 unsigned int query:1; 2396 unsigned int query:1;
2397 unsigned int id_changed:1; 2397 unsigned int id_changed:1;
2398 unsigned int scan_needed:1; 2398 unsigned int scan_needed:1;
2399 unsigned int n2n_flag:1;
2399 2400
2400 struct completion nvme_del_done; 2401 struct completion nvme_del_done;
2401 uint32_t nvme_prli_service_param; 2402 uint32_t nvme_prli_service_param;
@@ -2446,7 +2447,6 @@ typedef struct fc_port {
2446 uint8_t fc4_type; 2447 uint8_t fc4_type;
2447 uint8_t fc4f_nvme; 2448 uint8_t fc4f_nvme;
2448 uint8_t scan_state; 2449 uint8_t scan_state;
2449 uint8_t n2n_flag;
2450 2450
2451 unsigned long last_queue_full; 2451 unsigned long last_queue_full;
2452 unsigned long last_ramp_up; 2452 unsigned long last_ramp_up;
@@ -3036,6 +3036,7 @@ enum scan_flags_t {
3036enum fc4type_t { 3036enum fc4type_t {
3037 FS_FC4TYPE_FCP = BIT_0, 3037 FS_FC4TYPE_FCP = BIT_0,
3038 FS_FC4TYPE_NVME = BIT_1, 3038 FS_FC4TYPE_NVME = BIT_1,
3039 FS_FCP_IS_N2N = BIT_7,
3039}; 3040};
3040 3041
3041struct fab_scan_rp { 3042struct fab_scan_rp {
@@ -4394,6 +4395,7 @@ typedef struct scsi_qla_host {
4394#define IOCB_WORK_ACTIVE 31 4395#define IOCB_WORK_ACTIVE 31
4395#define SET_ZIO_THRESHOLD_NEEDED 32 4396#define SET_ZIO_THRESHOLD_NEEDED 32
4396#define ISP_ABORT_TO_ROM 33 4397#define ISP_ABORT_TO_ROM 33
4398#define VPORT_DELETE 34
4397 4399
4398 unsigned long pci_flags; 4400 unsigned long pci_flags;
4399#define PFLG_DISCONNECTED 0 /* PCI device removed */ 4401#define PFLG_DISCONNECTED 0 /* PCI device removed */
diff --git a/drivers/scsi/qla2xxx/qla_gs.c b/drivers/scsi/qla2xxx/qla_gs.c
index dc0e36676313..5298ed10059f 100644
--- a/drivers/scsi/qla2xxx/qla_gs.c
+++ b/drivers/scsi/qla2xxx/qla_gs.c
@@ -3102,7 +3102,8 @@ int qla24xx_post_gpnid_work(struct scsi_qla_host *vha, port_id_t *id)
3102{ 3102{
3103 struct qla_work_evt *e; 3103 struct qla_work_evt *e;
3104 3104
3105 if (test_bit(UNLOADING, &vha->dpc_flags)) 3105 if (test_bit(UNLOADING, &vha->dpc_flags) ||
3106 (vha->vp_idx && test_bit(VPORT_DELETE, &vha->dpc_flags)))
3106 return 0; 3107 return 0;
3107 3108
3108 e = qla2x00_alloc_work(vha, QLA_EVT_GPNID); 3109 e = qla2x00_alloc_work(vha, QLA_EVT_GPNID);
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 643d2324082e..1d041313ec52 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -746,12 +746,15 @@ static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
746 break; 746 break;
747 default: 747 default:
748 if ((id.b24 != fcport->d_id.b24 && 748 if ((id.b24 != fcport->d_id.b24 &&
749 fcport->d_id.b24) || 749 fcport->d_id.b24 &&
750 fcport->loop_id != FC_NO_LOOP_ID) ||
750 (fcport->loop_id != FC_NO_LOOP_ID && 751 (fcport->loop_id != FC_NO_LOOP_ID &&
751 fcport->loop_id != loop_id)) { 752 fcport->loop_id != loop_id)) {
752 ql_dbg(ql_dbg_disc, vha, 0x20e3, 753 ql_dbg(ql_dbg_disc, vha, 0x20e3,
753 "%s %d %8phC post del sess\n", 754 "%s %d %8phC post del sess\n",
754 __func__, __LINE__, fcport->port_name); 755 __func__, __LINE__, fcport->port_name);
756 if (fcport->n2n_flag)
757 fcport->d_id.b24 = 0;
755 qlt_schedule_sess_for_deletion(fcport); 758 qlt_schedule_sess_for_deletion(fcport);
756 return; 759 return;
757 } 760 }
@@ -759,6 +762,8 @@ static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
759 } 762 }
760 763
761 fcport->loop_id = loop_id; 764 fcport->loop_id = loop_id;
765 if (fcport->n2n_flag)
766 fcport->d_id.b24 = id.b24;
762 767
763 wwn = wwn_to_u64(fcport->port_name); 768 wwn = wwn_to_u64(fcport->port_name);
764 qlt_find_sess_invalidate_other(vha, wwn, 769 qlt_find_sess_invalidate_other(vha, wwn,
@@ -972,7 +977,7 @@ static void qla24xx_async_gnl_sp_done(srb_t *sp, int res)
972 wwn = wwn_to_u64(e->port_name); 977 wwn = wwn_to_u64(e->port_name);
973 978
974 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8, 979 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
975 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n", 980 "%s %8phC %02x:%02x:%02x CLS %x/%x lid %x \n",
976 __func__, (void *)&wwn, e->port_id[2], e->port_id[1], 981 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
977 e->port_id[0], e->current_login_state, e->last_login_state, 982 e->port_id[0], e->current_login_state, e->last_login_state,
978 (loop_id & 0x7fff)); 983 (loop_id & 0x7fff));
@@ -1499,7 +1504,8 @@ int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1499 (fcport->fw_login_state == DSC_LS_PRLI_PEND))) 1504 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1500 return 0; 1505 return 0;
1501 1506
1502 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) { 1507 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP &&
1508 !N2N_TOPO(vha->hw)) {
1503 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) { 1509 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1504 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 1510 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1505 return 0; 1511 return 0;
@@ -1570,8 +1576,9 @@ int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1570 qla24xx_post_gpdb_work(vha, fcport, 0); 1576 qla24xx_post_gpdb_work(vha, fcport, 0);
1571 } else { 1577 } else {
1572 ql_dbg(ql_dbg_disc, vha, 0x2118, 1578 ql_dbg(ql_dbg_disc, vha, 0x2118,
1573 "%s %d %8phC post NVMe PRLI\n", 1579 "%s %d %8phC post %s PRLI\n",
1574 __func__, __LINE__, fcport->port_name); 1580 __func__, __LINE__, fcport->port_name,
1581 fcport->fc4f_nvme ? "NVME" : "FC");
1575 qla24xx_post_prli_work(vha, fcport); 1582 qla24xx_post_prli_work(vha, fcport);
1576 } 1583 }
1577 break; 1584 break;
@@ -1853,17 +1860,38 @@ qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1853 break; 1860 break;
1854 } 1861 }
1855 1862
1856 if (ea->fcport->n2n_flag) { 1863 if (ea->fcport->fc4f_nvme) {
1857 ql_dbg(ql_dbg_disc, vha, 0x2118, 1864 ql_dbg(ql_dbg_disc, vha, 0x2118,
1858 "%s %d %8phC post fc4 prli\n", 1865 "%s %d %8phC post fc4 prli\n",
1859 __func__, __LINE__, ea->fcport->port_name); 1866 __func__, __LINE__, ea->fcport->port_name);
1860 ea->fcport->fc4f_nvme = 0; 1867 ea->fcport->fc4f_nvme = 0;
1861 ea->fcport->n2n_flag = 0;
1862 qla24xx_post_prli_work(vha, ea->fcport); 1868 qla24xx_post_prli_work(vha, ea->fcport);
1869 return;
1870 }
1871
1872 /* at this point both PRLI NVME & PRLI FCP failed */
1873 if (N2N_TOPO(vha->hw)) {
1874 if (ea->fcport->n2n_link_reset_cnt < 3) {
1875 ea->fcport->n2n_link_reset_cnt++;
1876 /*
1877 * remote port is not sending Plogi. Reset
1878 * link to kick start his state machine
1879 */
1880 set_bit(N2N_LINK_RESET, &vha->dpc_flags);
1881 } else {
1882 ql_log(ql_log_warn, vha, 0x2119,
1883 "%s %d %8phC Unable to reconnect\n",
1884 __func__, __LINE__, ea->fcport->port_name);
1885 }
1886 } else {
1887 /*
1888 * switch connect. login failed. Take connection
1889 * down and allow relogin to retrigger
1890 */
1891 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1892 ea->fcport->keep_nport_handle = 0;
1893 qlt_schedule_sess_for_deletion(ea->fcport);
1863 } 1894 }
1864 ql_dbg(ql_dbg_disc, vha, 0x2119,
1865 "%s %d %8phC unhandle event of %x\n",
1866 __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
1867 break; 1895 break;
1868 } 1896 }
1869} 1897}
@@ -3190,7 +3218,7 @@ qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3190 3218
3191 for (j = 0; j < 2; j++, fwdt++) { 3219 for (j = 0; j < 2; j++, fwdt++) {
3192 if (!fwdt->template) { 3220 if (!fwdt->template) {
3193 ql_log(ql_log_warn, vha, 0x00ba, 3221 ql_dbg(ql_dbg_init, vha, 0x00ba,
3194 "-> fwdt%u no template\n", j); 3222 "-> fwdt%u no template\n", j);
3195 continue; 3223 continue;
3196 } 3224 }
@@ -4986,28 +5014,47 @@ qla2x00_configure_local_loop(scsi_qla_host_t *vha)
4986 unsigned long flags; 5014 unsigned long flags;
4987 5015
4988 /* Inititae N2N login. */ 5016 /* Inititae N2N login. */
4989 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) { 5017 if (N2N_TOPO(ha)) {
4990 /* borrowing */ 5018 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
4991 u32 *bp, i, sz; 5019 /* borrowing */
4992 5020 u32 *bp, i, sz;
4993 memset(ha->init_cb, 0, ha->init_cb_size); 5021
4994 sz = min_t(int, sizeof(struct els_plogi_payload), 5022 memset(ha->init_cb, 0, ha->init_cb_size);
4995 ha->init_cb_size); 5023 sz = min_t(int, sizeof(struct els_plogi_payload),
4996 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma, 5024 ha->init_cb_size);
4997 (void *)ha->init_cb, sz); 5025 rval = qla24xx_get_port_login_templ(vha,
4998 if (rval == QLA_SUCCESS) { 5026 ha->init_cb_dma, (void *)ha->init_cb, sz);
4999 bp = (uint32_t *)ha->init_cb; 5027 if (rval == QLA_SUCCESS) {
5000 for (i = 0; i < sz/4 ; i++, bp++) 5028 bp = (uint32_t *)ha->init_cb;
5001 *bp = cpu_to_be32(*bp); 5029 for (i = 0; i < sz/4 ; i++, bp++)
5030 *bp = cpu_to_be32(*bp);
5002 5031
5003 memcpy(&ha->plogi_els_payld.data, (void *)ha->init_cb, 5032 memcpy(&ha->plogi_els_payld.data,
5004 sizeof(ha->plogi_els_payld.data)); 5033 (void *)ha->init_cb,
5005 set_bit(RELOGIN_NEEDED, &vha->dpc_flags); 5034 sizeof(ha->plogi_els_payld.data));
5006 } else { 5035 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5007 ql_dbg(ql_dbg_init, vha, 0x00d1, 5036 } else {
5008 "PLOGI ELS param read fail.\n"); 5037 ql_dbg(ql_dbg_init, vha, 0x00d1,
5038 "PLOGI ELS param read fail.\n");
5039 goto skip_login;
5040 }
5041 }
5042
5043 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5044 if (fcport->n2n_flag) {
5045 qla24xx_fcport_handle_login(vha, fcport);
5046 return QLA_SUCCESS;
5047 }
5048 }
5049skip_login:
5050 spin_lock_irqsave(&vha->work_lock, flags);
5051 vha->scan.scan_retry++;
5052 spin_unlock_irqrestore(&vha->work_lock, flags);
5053
5054 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5055 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5056 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5009 } 5057 }
5010 return QLA_SUCCESS;
5011 } 5058 }
5012 5059
5013 found_devs = 0; 5060 found_devs = 0;
diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
index e92e52aa6e9b..518eb954cf42 100644
--- a/drivers/scsi/qla2xxx/qla_iocb.c
+++ b/drivers/scsi/qla2xxx/qla_iocb.c
@@ -2656,9 +2656,10 @@ qla24xx_els_logo_iocb(srb_t *sp, struct els_entry_24xx *els_iocb)
2656 els_iocb->port_id[0] = sp->fcport->d_id.b.al_pa; 2656 els_iocb->port_id[0] = sp->fcport->d_id.b.al_pa;
2657 els_iocb->port_id[1] = sp->fcport->d_id.b.area; 2657 els_iocb->port_id[1] = sp->fcport->d_id.b.area;
2658 els_iocb->port_id[2] = sp->fcport->d_id.b.domain; 2658 els_iocb->port_id[2] = sp->fcport->d_id.b.domain;
2659 els_iocb->s_id[0] = vha->d_id.b.al_pa; 2659 /* For SID the byte order is different than DID */
2660 els_iocb->s_id[1] = vha->d_id.b.area; 2660 els_iocb->s_id[1] = vha->d_id.b.al_pa;
2661 els_iocb->s_id[2] = vha->d_id.b.domain; 2661 els_iocb->s_id[2] = vha->d_id.b.area;
2662 els_iocb->s_id[0] = vha->d_id.b.domain;
2662 2663
2663 if (elsio->u.els_logo.els_cmd == ELS_DCMD_PLOGI) { 2664 if (elsio->u.els_logo.els_cmd == ELS_DCMD_PLOGI) {
2664 els_iocb->control_flags = 0; 2665 els_iocb->control_flags = 0;
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 4c26630c1c3e..009fd5a33fcd 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -2837,8 +2837,6 @@ qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
2837 if (sense_len == 0) { 2837 if (sense_len == 0) {
2838 rsp->status_srb = NULL; 2838 rsp->status_srb = NULL;
2839 sp->done(sp, cp->result); 2839 sp->done(sp, cp->result);
2840 } else {
2841 WARN_ON_ONCE(true);
2842 } 2840 }
2843} 2841}
2844 2842
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 4c858e2d0ea8..1cc6913f76c4 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -2249,7 +2249,7 @@ qla2x00_lip_reset(scsi_qla_host_t *vha)
2249 mbx_cmd_t mc; 2249 mbx_cmd_t mc;
2250 mbx_cmd_t *mcp = &mc; 2250 mbx_cmd_t *mcp = &mc;
2251 2251
2252 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105a, 2252 ql_dbg(ql_dbg_disc, vha, 0x105a,
2253 "Entered %s.\n", __func__); 2253 "Entered %s.\n", __func__);
2254 2254
2255 if (IS_CNA_CAPABLE(vha->hw)) { 2255 if (IS_CNA_CAPABLE(vha->hw)) {
@@ -3883,14 +3883,24 @@ qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
3883 case TOPO_N2N: 3883 case TOPO_N2N:
3884 ha->current_topology = ISP_CFG_N; 3884 ha->current_topology = ISP_CFG_N;
3885 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); 3885 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
3886 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3887 fcport->scan_state = QLA_FCPORT_SCAN;
3888 fcport->n2n_flag = 0;
3889 }
3890
3886 fcport = qla2x00_find_fcport_by_wwpn(vha, 3891 fcport = qla2x00_find_fcport_by_wwpn(vha,
3887 rptid_entry->u.f1.port_name, 1); 3892 rptid_entry->u.f1.port_name, 1);
3888 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); 3893 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
3889 3894
3890 if (fcport) { 3895 if (fcport) {
3891 fcport->plogi_nack_done_deadline = jiffies + HZ; 3896 fcport->plogi_nack_done_deadline = jiffies + HZ;
3892 fcport->dm_login_expire = jiffies + 3*HZ; 3897 fcport->dm_login_expire = jiffies + 2*HZ;
3893 fcport->scan_state = QLA_FCPORT_FOUND; 3898 fcport->scan_state = QLA_FCPORT_FOUND;
3899 fcport->n2n_flag = 1;
3900 fcport->keep_nport_handle = 1;
3901 if (vha->flags.nvme_enabled)
3902 fcport->fc4f_nvme = 1;
3903
3894 switch (fcport->disc_state) { 3904 switch (fcport->disc_state) {
3895 case DSC_DELETED: 3905 case DSC_DELETED:
3896 set_bit(RELOGIN_NEEDED, 3906 set_bit(RELOGIN_NEEDED,
@@ -3924,7 +3934,7 @@ qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
3924 rptid_entry->u.f1.port_name, 3934 rptid_entry->u.f1.port_name,
3925 rptid_entry->u.f1.node_name, 3935 rptid_entry->u.f1.node_name,
3926 NULL, 3936 NULL,
3927 FC4_TYPE_UNKNOWN); 3937 FS_FCP_IS_N2N);
3928 } 3938 }
3929 3939
3930 /* if our portname is higher then initiate N2N login */ 3940 /* if our portname is higher then initiate N2N login */
@@ -4023,6 +4033,7 @@ qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
4023 4033
4024 list_for_each_entry(fcport, &vha->vp_fcports, list) { 4034 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4025 fcport->scan_state = QLA_FCPORT_SCAN; 4035 fcport->scan_state = QLA_FCPORT_SCAN;
4036 fcport->n2n_flag = 0;
4026 } 4037 }
4027 4038
4028 fcport = qla2x00_find_fcport_by_wwpn(vha, 4039 fcport = qla2x00_find_fcport_by_wwpn(vha,
@@ -4032,6 +4043,14 @@ qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
4032 fcport->login_retry = vha->hw->login_retry_count; 4043 fcport->login_retry = vha->hw->login_retry_count;
4033 fcport->plogi_nack_done_deadline = jiffies + HZ; 4044 fcport->plogi_nack_done_deadline = jiffies + HZ;
4034 fcport->scan_state = QLA_FCPORT_FOUND; 4045 fcport->scan_state = QLA_FCPORT_FOUND;
4046 fcport->keep_nport_handle = 1;
4047 fcport->n2n_flag = 1;
4048 fcport->d_id.b.domain =
4049 rptid_entry->u.f2.remote_nport_id[2];
4050 fcport->d_id.b.area =
4051 rptid_entry->u.f2.remote_nport_id[1];
4052 fcport->d_id.b.al_pa =
4053 rptid_entry->u.f2.remote_nport_id[0];
4035 } 4054 }
4036 } 4055 }
4037} 4056}
diff --git a/drivers/scsi/qla2xxx/qla_mid.c b/drivers/scsi/qla2xxx/qla_mid.c
index 1a9a11ae7285..6afad68e5ba2 100644
--- a/drivers/scsi/qla2xxx/qla_mid.c
+++ b/drivers/scsi/qla2xxx/qla_mid.c
@@ -66,6 +66,7 @@ qla24xx_deallocate_vp_id(scsi_qla_host_t *vha)
66 uint16_t vp_id; 66 uint16_t vp_id;
67 struct qla_hw_data *ha = vha->hw; 67 struct qla_hw_data *ha = vha->hw;
68 unsigned long flags = 0; 68 unsigned long flags = 0;
69 u8 i;
69 70
70 mutex_lock(&ha->vport_lock); 71 mutex_lock(&ha->vport_lock);
71 /* 72 /*
@@ -75,8 +76,9 @@ qla24xx_deallocate_vp_id(scsi_qla_host_t *vha)
75 * ensures no active vp_list traversal while the vport is removed 76 * ensures no active vp_list traversal while the vport is removed
76 * from the queue) 77 * from the queue)
77 */ 78 */
78 wait_event_timeout(vha->vref_waitq, !atomic_read(&vha->vref_count), 79 for (i = 0; i < 10 && atomic_read(&vha->vref_count); i++)
79 10*HZ); 80 wait_event_timeout(vha->vref_waitq,
81 atomic_read(&vha->vref_count), HZ);
80 82
81 spin_lock_irqsave(&ha->vport_slock, flags); 83 spin_lock_irqsave(&ha->vport_slock, flags);
82 if (atomic_read(&vha->vref_count)) { 84 if (atomic_read(&vha->vref_count)) {
@@ -262,6 +264,9 @@ qla2x00_alert_all_vps(struct rsp_que *rsp, uint16_t *mb)
262 spin_lock_irqsave(&ha->vport_slock, flags); 264 spin_lock_irqsave(&ha->vport_slock, flags);
263 list_for_each_entry(vha, &ha->vp_list, list) { 265 list_for_each_entry(vha, &ha->vp_list, list) {
264 if (vha->vp_idx) { 266 if (vha->vp_idx) {
267 if (test_bit(VPORT_DELETE, &vha->dpc_flags))
268 continue;
269
265 atomic_inc(&vha->vref_count); 270 atomic_inc(&vha->vref_count);
266 spin_unlock_irqrestore(&ha->vport_slock, flags); 271 spin_unlock_irqrestore(&ha->vport_slock, flags);
267 272
@@ -300,6 +305,20 @@ qla2x00_alert_all_vps(struct rsp_que *rsp, uint16_t *mb)
300int 305int
301qla2x00_vp_abort_isp(scsi_qla_host_t *vha) 306qla2x00_vp_abort_isp(scsi_qla_host_t *vha)
302{ 307{
308 fc_port_t *fcport;
309
310 /*
311 * To exclusively reset vport, we need to log it out first.
312 * Note: This control_vp can fail if ISP reset is already
313 * issued, this is expected, as the vp would be already
314 * logged out due to ISP reset.
315 */
316 if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
317 qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL);
318 list_for_each_entry(fcport, &vha->vp_fcports, list)
319 fcport->logout_on_delete = 0;
320 }
321
303 /* 322 /*
304 * Physical port will do most of the abort and recovery work. We can 323 * Physical port will do most of the abort and recovery work. We can
305 * just treat it as a loop down 324 * just treat it as a loop down
@@ -312,16 +331,9 @@ qla2x00_vp_abort_isp(scsi_qla_host_t *vha)
312 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); 331 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
313 } 332 }
314 333
315 /*
316 * To exclusively reset vport, we need to log it out first. Note: this
317 * control_vp can fail if ISP reset is already issued, this is
318 * expected, as the vp would be already logged out due to ISP reset.
319 */
320 if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
321 qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL);
322
323 ql_dbg(ql_dbg_taskm, vha, 0x801d, 334 ql_dbg(ql_dbg_taskm, vha, 0x801d,
324 "Scheduling enable of Vport %d.\n", vha->vp_idx); 335 "Scheduling enable of Vport %d.\n", vha->vp_idx);
336
325 return qla24xx_enable_vp(vha); 337 return qla24xx_enable_vp(vha);
326} 338}
327 339
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 73db01e3b4e4..3568031c6504 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -1115,9 +1115,15 @@ static inline int test_fcport_count(scsi_qla_host_t *vha)
1115void 1115void
1116qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha) 1116qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1117{ 1117{
1118 u8 i;
1119
1118 qla2x00_mark_all_devices_lost(vha, 0); 1120 qla2x00_mark_all_devices_lost(vha, 0);
1119 1121
1120 wait_event_timeout(vha->fcport_waitQ, test_fcport_count(vha), 10*HZ); 1122 for (i = 0; i < 10; i++)
1123 wait_event_timeout(vha->fcport_waitQ, test_fcport_count(vha),
1124 HZ);
1125
1126 flush_workqueue(vha->hw->wq);
1121} 1127}
1122 1128
1123/* 1129/*
@@ -5036,6 +5042,10 @@ void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
5036 5042
5037 memcpy(fcport->port_name, e->u.new_sess.port_name, 5043 memcpy(fcport->port_name, e->u.new_sess.port_name,
5038 WWN_SIZE); 5044 WWN_SIZE);
5045
5046 if (e->u.new_sess.fc4_type & FS_FCP_IS_N2N)
5047 fcport->n2n_flag = 1;
5048
5039 } else { 5049 } else {
5040 ql_dbg(ql_dbg_disc, vha, 0xffff, 5050 ql_dbg(ql_dbg_disc, vha, 0xffff,
5041 "%s %8phC mem alloc fail.\n", 5051 "%s %8phC mem alloc fail.\n",
@@ -5134,11 +5144,9 @@ void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
5134 if (dfcp) 5144 if (dfcp)
5135 qlt_schedule_sess_for_deletion(tfcp); 5145 qlt_schedule_sess_for_deletion(tfcp);
5136 5146
5137
5138 if (N2N_TOPO(vha->hw))
5139 fcport->flags &= ~FCF_FABRIC_DEVICE;
5140
5141 if (N2N_TOPO(vha->hw)) { 5147 if (N2N_TOPO(vha->hw)) {
5148 fcport->flags &= ~FCF_FABRIC_DEVICE;
5149 fcport->keep_nport_handle = 1;
5142 if (vha->flags.nvme_enabled) { 5150 if (vha->flags.nvme_enabled) {
5143 fcport->fc4f_nvme = 1; 5151 fcport->fc4f_nvme = 1;
5144 fcport->n2n_flag = 1; 5152 fcport->n2n_flag = 1;
diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c
index 0ffda6171614..a06e56224a55 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -953,7 +953,7 @@ void qlt_free_session_done(struct work_struct *work)
953 struct qla_hw_data *ha = vha->hw; 953 struct qla_hw_data *ha = vha->hw;
954 unsigned long flags; 954 unsigned long flags;
955 bool logout_started = false; 955 bool logout_started = false;
956 scsi_qla_host_t *base_vha; 956 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
957 struct qlt_plogi_ack_t *own = 957 struct qlt_plogi_ack_t *own =
958 sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]; 958 sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN];
959 959
@@ -1020,6 +1020,7 @@ void qlt_free_session_done(struct work_struct *work)
1020 1020
1021 if (logout_started) { 1021 if (logout_started) {
1022 bool traced = false; 1022 bool traced = false;
1023 u16 cnt = 0;
1023 1024
1024 while (!READ_ONCE(sess->logout_completed)) { 1025 while (!READ_ONCE(sess->logout_completed)) {
1025 if (!traced) { 1026 if (!traced) {
@@ -1029,6 +1030,9 @@ void qlt_free_session_done(struct work_struct *work)
1029 traced = true; 1030 traced = true;
1030 } 1031 }
1031 msleep(100); 1032 msleep(100);
1033 cnt++;
1034 if (cnt > 200)
1035 break;
1032 } 1036 }
1033 1037
1034 ql_dbg(ql_dbg_disc, vha, 0xf087, 1038 ql_dbg(ql_dbg_disc, vha, 0xf087,
@@ -1101,6 +1105,7 @@ void qlt_free_session_done(struct work_struct *work)
1101 } 1105 }
1102 1106
1103 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); 1107 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1108 sess->free_pending = 0;
1104 1109
1105 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf001, 1110 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf001,
1106 "Unregistration of sess %p %8phC finished fcp_cnt %d\n", 1111 "Unregistration of sess %p %8phC finished fcp_cnt %d\n",
@@ -1109,17 +1114,9 @@ void qlt_free_session_done(struct work_struct *work)
1109 if (tgt && (tgt->sess_count == 0)) 1114 if (tgt && (tgt->sess_count == 0))
1110 wake_up_all(&tgt->waitQ); 1115 wake_up_all(&tgt->waitQ);
1111 1116
1112 if (vha->fcport_count == 0) 1117 if (!test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags) &&
1113 wake_up_all(&vha->fcport_waitQ); 1118 !(vha->vp_idx && test_bit(VPORT_DELETE, &vha->dpc_flags)) &&
1114 1119 (!tgt || !tgt->tgt_stop) && !LOOP_TRANSITION(vha)) {
1115 base_vha = pci_get_drvdata(ha->pdev);
1116
1117 sess->free_pending = 0;
1118
1119 if (test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags))
1120 return;
1121
1122 if ((!tgt || !tgt->tgt_stop) && !LOOP_TRANSITION(vha)) {
1123 switch (vha->host->active_mode) { 1120 switch (vha->host->active_mode) {
1124 case MODE_INITIATOR: 1121 case MODE_INITIATOR:
1125 case MODE_DUAL: 1122 case MODE_DUAL:
@@ -1132,6 +1129,9 @@ void qlt_free_session_done(struct work_struct *work)
1132 break; 1129 break;
1133 } 1130 }
1134 } 1131 }
1132
1133 if (vha->fcport_count == 0)
1134 wake_up_all(&vha->fcport_waitQ);
1135} 1135}
1136 1136
1137/* ha->tgt.sess_lock supposed to be held on entry */ 1137/* ha->tgt.sess_lock supposed to be held on entry */
@@ -1161,7 +1161,7 @@ void qlt_unreg_sess(struct fc_port *sess)
1161 sess->last_login_gen = sess->login_gen; 1161 sess->last_login_gen = sess->login_gen;
1162 1162
1163 INIT_WORK(&sess->free_work, qlt_free_session_done); 1163 INIT_WORK(&sess->free_work, qlt_free_session_done);
1164 schedule_work(&sess->free_work); 1164 queue_work(sess->vha->hw->wq, &sess->free_work);
1165} 1165}
1166EXPORT_SYMBOL(qlt_unreg_sess); 1166EXPORT_SYMBOL(qlt_unreg_sess);
1167 1167
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 1c470e31ae81..ae2fa170f6ad 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -967,6 +967,7 @@ void scsi_eh_prep_cmnd(struct scsi_cmnd *scmd, struct scsi_eh_save *ses,
967 ses->data_direction = scmd->sc_data_direction; 967 ses->data_direction = scmd->sc_data_direction;
968 ses->sdb = scmd->sdb; 968 ses->sdb = scmd->sdb;
969 ses->result = scmd->result; 969 ses->result = scmd->result;
970 ses->resid_len = scmd->req.resid_len;
970 ses->underflow = scmd->underflow; 971 ses->underflow = scmd->underflow;
971 ses->prot_op = scmd->prot_op; 972 ses->prot_op = scmd->prot_op;
972 ses->eh_eflags = scmd->eh_eflags; 973 ses->eh_eflags = scmd->eh_eflags;
@@ -977,6 +978,7 @@ void scsi_eh_prep_cmnd(struct scsi_cmnd *scmd, struct scsi_eh_save *ses,
977 memset(scmd->cmnd, 0, BLK_MAX_CDB); 978 memset(scmd->cmnd, 0, BLK_MAX_CDB);
978 memset(&scmd->sdb, 0, sizeof(scmd->sdb)); 979 memset(&scmd->sdb, 0, sizeof(scmd->sdb));
979 scmd->result = 0; 980 scmd->result = 0;
981 scmd->req.resid_len = 0;
980 982
981 if (sense_bytes) { 983 if (sense_bytes) {
982 scmd->sdb.length = min_t(unsigned, SCSI_SENSE_BUFFERSIZE, 984 scmd->sdb.length = min_t(unsigned, SCSI_SENSE_BUFFERSIZE,
@@ -1029,6 +1031,7 @@ void scsi_eh_restore_cmnd(struct scsi_cmnd* scmd, struct scsi_eh_save *ses)
1029 scmd->sc_data_direction = ses->data_direction; 1031 scmd->sc_data_direction = ses->data_direction;
1030 scmd->sdb = ses->sdb; 1032 scmd->sdb = ses->sdb;
1031 scmd->result = ses->result; 1033 scmd->result = ses->result;
1034 scmd->req.resid_len = ses->resid_len;
1032 scmd->underflow = ses->underflow; 1035 scmd->underflow = ses->underflow;
1033 scmd->prot_op = ses->prot_op; 1036 scmd->prot_op = ses->prot_op;
1034 scmd->eh_eflags = ses->eh_eflags; 1037 scmd->eh_eflags = ses->eh_eflags;
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index dc210b9d4896..5447738906ac 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1834,6 +1834,7 @@ static const struct blk_mq_ops scsi_mq_ops_no_commit = {
1834 .init_request = scsi_mq_init_request, 1834 .init_request = scsi_mq_init_request,
1835 .exit_request = scsi_mq_exit_request, 1835 .exit_request = scsi_mq_exit_request,
1836 .initialize_rq_fn = scsi_initialize_rq, 1836 .initialize_rq_fn = scsi_initialize_rq,
1837 .cleanup_rq = scsi_cleanup_rq,
1837 .busy = scsi_mq_lld_busy, 1838 .busy = scsi_mq_lld_busy,
1838 .map_queues = scsi_map_queues, 1839 .map_queues = scsi_map_queues,
1839}; 1840};
@@ -1921,7 +1922,8 @@ struct scsi_device *scsi_device_from_queue(struct request_queue *q)
1921{ 1922{
1922 struct scsi_device *sdev = NULL; 1923 struct scsi_device *sdev = NULL;
1923 1924
1924 if (q->mq_ops == &scsi_mq_ops) 1925 if (q->mq_ops == &scsi_mq_ops_no_commit ||
1926 q->mq_ops == &scsi_mq_ops)
1925 sdev = q->queuedata; 1927 sdev = q->queuedata;
1926 if (!sdev || !get_device(&sdev->sdev_gendev)) 1928 if (!sdev || !get_device(&sdev->sdev_gendev))
1927 sdev = NULL; 1929 sdev = NULL;
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 50928bc266eb..03163ac5fe95 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1654,7 +1654,8 @@ static int sd_sync_cache(struct scsi_disk *sdkp, struct scsi_sense_hdr *sshdr)
1654 /* we need to evaluate the error return */ 1654 /* we need to evaluate the error return */
1655 if (scsi_sense_valid(sshdr) && 1655 if (scsi_sense_valid(sshdr) &&
1656 (sshdr->asc == 0x3a || /* medium not present */ 1656 (sshdr->asc == 0x3a || /* medium not present */
1657 sshdr->asc == 0x20)) /* invalid command */ 1657 sshdr->asc == 0x20 || /* invalid command */
1658 (sshdr->asc == 0x74 && sshdr->ascq == 0x71))) /* drive is password locked */
1658 /* this is no error here */ 1659 /* this is no error here */
1659 return 0; 1660 return 0;
1660 1661
diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index ed8b9ac805e6..542d2bac2922 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -1837,8 +1837,7 @@ static int storvsc_probe(struct hv_device *device,
1837 /* 1837 /*
1838 * Set the number of HW queues we are supporting. 1838 * Set the number of HW queues we are supporting.
1839 */ 1839 */
1840 if (stor_device->num_sc != 0) 1840 host->nr_hw_queues = num_present_cpus();
1841 host->nr_hw_queues = stor_device->num_sc + 1;
1842 1841
1843 /* 1842 /*
1844 * Set the error handler work queue. 1843 * Set the error handler work queue.
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 034dd9cb9ec8..11a87f51c442 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -8143,6 +8143,9 @@ int ufshcd_shutdown(struct ufs_hba *hba)
8143{ 8143{
8144 int ret = 0; 8144 int ret = 0;
8145 8145
8146 if (!hba->is_powered)
8147 goto out;
8148
8146 if (ufshcd_is_ufs_dev_poweroff(hba) && ufshcd_is_link_off(hba)) 8149 if (ufshcd_is_ufs_dev_poweroff(hba) && ufshcd_is_link_off(hba))
8147 goto out; 8150 goto out;
8148 8151
diff --git a/drivers/staging/exfat/Kconfig b/drivers/staging/exfat/Kconfig
index 290dbfc7ace1..ce32dfe33bec 100644
--- a/drivers/staging/exfat/Kconfig
+++ b/drivers/staging/exfat/Kconfig
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1config EXFAT_FS 2config EXFAT_FS
2 tristate "exFAT fs support" 3 tristate "exFAT fs support"
3 depends on BLOCK 4 depends on BLOCK
@@ -6,7 +7,7 @@ config EXFAT_FS
6 This adds support for the exFAT file system. 7 This adds support for the exFAT file system.
7 8
8config EXFAT_DONT_MOUNT_VFAT 9config EXFAT_DONT_MOUNT_VFAT
9 bool "Prohibit mounting of fat/vfat filesysems by exFAT" 10 bool "Prohibit mounting of fat/vfat filesystems by exFAT"
10 depends on EXFAT_FS 11 depends on EXFAT_FS
11 default y 12 default y
12 help 13 help
diff --git a/drivers/staging/exfat/Makefile b/drivers/staging/exfat/Makefile
index 84944dfbae28..6c90aec83feb 100644
--- a/drivers/staging/exfat/Makefile
+++ b/drivers/staging/exfat/Makefile
@@ -1,4 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0-or-later
2 2
3obj-$(CONFIG_EXFAT_FS) += exfat.o 3obj-$(CONFIG_EXFAT_FS) += exfat.o
4 4
diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index 6c12f2d79f4d..3abab33e932c 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -1,4 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */ 1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/* 2/*
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd. 3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 */ 4 */
diff --git a/drivers/staging/exfat/exfat_blkdev.c b/drivers/staging/exfat/exfat_blkdev.c
index f086c75e7076..81d20e6241c6 100644
--- a/drivers/staging/exfat/exfat_blkdev.c
+++ b/drivers/staging/exfat/exfat_blkdev.c
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0-or-later
2/* 2/*
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd. 3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 */ 4 */
diff --git a/drivers/staging/exfat/exfat_cache.c b/drivers/staging/exfat/exfat_cache.c
index 1565ce65d39f..e1b001718709 100644
--- a/drivers/staging/exfat/exfat_cache.c
+++ b/drivers/staging/exfat/exfat_cache.c
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0-or-later
2/* 2/*
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd. 3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 */ 4 */
diff --git a/drivers/staging/exfat/exfat_core.c b/drivers/staging/exfat/exfat_core.c
index b3e9cf725cf5..79174e5c4145 100644
--- a/drivers/staging/exfat/exfat_core.c
+++ b/drivers/staging/exfat/exfat_core.c
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0-or-later
2/* 2/*
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd. 3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 */ 4 */
diff --git a/drivers/staging/exfat/exfat_nls.c b/drivers/staging/exfat/exfat_nls.c
index 03cb8290b5d2..a5c4b68925fb 100644
--- a/drivers/staging/exfat/exfat_nls.c
+++ b/drivers/staging/exfat/exfat_nls.c
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0-or-later
2/* 2/*
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd. 3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 */ 4 */
diff --git a/drivers/staging/exfat/exfat_super.c b/drivers/staging/exfat/exfat_super.c
index 5f6caee819a6..3b2b0ceb7297 100644
--- a/drivers/staging/exfat/exfat_super.c
+++ b/drivers/staging/exfat/exfat_super.c
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0-or-later
2/* 2/*
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd. 3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 */ 4 */
@@ -7,6 +7,7 @@
7#include <linux/init.h> 7#include <linux/init.h>
8#include <linux/time.h> 8#include <linux/time.h>
9#include <linux/slab.h> 9#include <linux/slab.h>
10#include <linux/mm.h>
10#include <linux/seq_file.h> 11#include <linux/seq_file.h>
11#include <linux/pagemap.h> 12#include <linux/pagemap.h>
12#include <linux/mpage.h> 13#include <linux/mpage.h>
@@ -3450,7 +3451,7 @@ static void exfat_free_super(struct exfat_sb_info *sbi)
3450 kfree(sbi->options.iocharset); 3451 kfree(sbi->options.iocharset);
3451 /* mutex_init is in exfat_fill_super function. only for 3.7+ */ 3452 /* mutex_init is in exfat_fill_super function. only for 3.7+ */
3452 mutex_destroy(&sbi->s_lock); 3453 mutex_destroy(&sbi->s_lock);
3453 kfree(sbi); 3454 kvfree(sbi);
3454} 3455}
3455 3456
3456static void exfat_put_super(struct super_block *sb) 3457static void exfat_put_super(struct super_block *sb)
@@ -3845,7 +3846,7 @@ static int exfat_fill_super(struct super_block *sb, void *data, int silent)
3845 * the filesystem, since we're only just about to mount 3846 * the filesystem, since we're only just about to mount
3846 * it and have no inodes etc active! 3847 * it and have no inodes etc active!
3847 */ 3848 */
3848 sbi = kzalloc(sizeof(struct exfat_sb_info), GFP_KERNEL); 3849 sbi = kvzalloc(sizeof(*sbi), GFP_KERNEL);
3849 if (!sbi) 3850 if (!sbi)
3850 return -ENOMEM; 3851 return -ENOMEM;
3851 mutex_init(&sbi->s_lock); 3852 mutex_init(&sbi->s_lock);
diff --git a/drivers/staging/exfat/exfat_upcase.c b/drivers/staging/exfat/exfat_upcase.c
index 366082fb3dab..b91a1faa0e50 100644
--- a/drivers/staging/exfat/exfat_upcase.c
+++ b/drivers/staging/exfat/exfat_upcase.c
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0-or-later
2/* 2/*
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd. 3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 */ 4 */
diff --git a/drivers/staging/fbtft/Kconfig b/drivers/staging/fbtft/Kconfig
index 8ec524a95ec8..cb61c2a772bd 100644
--- a/drivers/staging/fbtft/Kconfig
+++ b/drivers/staging/fbtft/Kconfig
@@ -1,7 +1,7 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2menuconfig FB_TFT 2menuconfig FB_TFT
3 tristate "Support for small TFT LCD display modules" 3 tristate "Support for small TFT LCD display modules"
4 depends on FB && SPI 4 depends on FB && SPI && OF
5 depends on GPIOLIB || COMPILE_TEST 5 depends on GPIOLIB || COMPILE_TEST
6 select FB_SYS_FILLRECT 6 select FB_SYS_FILLRECT
7 select FB_SYS_COPYAREA 7 select FB_SYS_COPYAREA
@@ -199,13 +199,3 @@ config FB_TFT_WATTEROTT
199 depends on FB_TFT 199 depends on FB_TFT
200 help 200 help
201 Generic Framebuffer support for WATTEROTT 201 Generic Framebuffer support for WATTEROTT
202
203config FB_FLEX
204 tristate "Generic FB driver for TFT LCD displays"
205 depends on FB_TFT
206 help
207 Generic Framebuffer support for TFT LCD displays.
208
209config FB_TFT_FBTFT_DEVICE
210 tristate "Module to for adding FBTFT devices"
211 depends on FB_TFT
diff --git a/drivers/staging/fbtft/Makefile b/drivers/staging/fbtft/Makefile
index 6bc03311c9c7..27af43f32f81 100644
--- a/drivers/staging/fbtft/Makefile
+++ b/drivers/staging/fbtft/Makefile
@@ -36,7 +36,3 @@ obj-$(CONFIG_FB_TFT_UC1611) += fb_uc1611.o
36obj-$(CONFIG_FB_TFT_UC1701) += fb_uc1701.o 36obj-$(CONFIG_FB_TFT_UC1701) += fb_uc1701.o
37obj-$(CONFIG_FB_TFT_UPD161704) += fb_upd161704.o 37obj-$(CONFIG_FB_TFT_UPD161704) += fb_upd161704.o
38obj-$(CONFIG_FB_TFT_WATTEROTT) += fb_watterott.o 38obj-$(CONFIG_FB_TFT_WATTEROTT) += fb_watterott.o
39obj-$(CONFIG_FB_FLEX) += flexfb.o
40
41# Device modules
42obj-$(CONFIG_FB_TFT_FBTFT_DEVICE) += fbtft_device.o
diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c
index cf5700a2ea66..a0a67aa517f0 100644
--- a/drivers/staging/fbtft/fbtft-core.c
+++ b/drivers/staging/fbtft/fbtft-core.c
@@ -714,7 +714,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
714 if (par->gamma.curves && gamma) { 714 if (par->gamma.curves && gamma) {
715 if (fbtft_gamma_parse_str(par, par->gamma.curves, gamma, 715 if (fbtft_gamma_parse_str(par, par->gamma.curves, gamma,
716 strlen(gamma))) 716 strlen(gamma)))
717 goto alloc_fail; 717 goto release_framebuf;
718 } 718 }
719 719
720 /* Transmit buffer */ 720 /* Transmit buffer */
@@ -731,7 +731,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
731 if (txbuflen > 0) { 731 if (txbuflen > 0) {
732 txbuf = devm_kzalloc(par->info->device, txbuflen, GFP_KERNEL); 732 txbuf = devm_kzalloc(par->info->device, txbuflen, GFP_KERNEL);
733 if (!txbuf) 733 if (!txbuf)
734 goto alloc_fail; 734 goto release_framebuf;
735 par->txbuf.buf = txbuf; 735 par->txbuf.buf = txbuf;
736 par->txbuf.len = txbuflen; 736 par->txbuf.len = txbuflen;
737 } 737 }
@@ -753,6 +753,9 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
753 753
754 return info; 754 return info;
755 755
756release_framebuf:
757 framebuffer_release(info);
758
756alloc_fail: 759alloc_fail:
757 vfree(vmem); 760 vfree(vmem);
758 761
diff --git a/drivers/staging/fbtft/fbtft_device.c b/drivers/staging/fbtft/fbtft_device.c
deleted file mode 100644
index 44e1410eb3fe..000000000000
--- a/drivers/staging/fbtft/fbtft_device.c
+++ /dev/null
@@ -1,1261 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 *
4 * Copyright (C) 2013, Noralf Tronnes
5 */
6
7#define pr_fmt(fmt) "fbtft_device: " fmt
8#include <linux/module.h>
9#include <linux/kernel.h>
10#include <linux/init.h>
11#include <linux/gpio/consumer.h>
12#include <linux/spi/spi.h>
13#include <video/mipi_display.h>
14
15#include "fbtft.h"
16
17#define MAX_GPIOS 32
18
19static struct spi_device *spi_device;
20static struct platform_device *p_device;
21
22static char *name;
23module_param(name, charp, 0000);
24MODULE_PARM_DESC(name,
25 "Devicename (required). name=list => list all supported devices.");
26
27static unsigned int rotate;
28module_param(rotate, uint, 0000);
29MODULE_PARM_DESC(rotate,
30 "Angle to rotate display counter clockwise: 0, 90, 180, 270");
31
32static unsigned int busnum;
33module_param(busnum, uint, 0000);
34MODULE_PARM_DESC(busnum, "SPI bus number (default=0)");
35
36static unsigned int cs;
37module_param(cs, uint, 0000);
38MODULE_PARM_DESC(cs, "SPI chip select (default=0)");
39
40static unsigned int speed;
41module_param(speed, uint, 0000);
42MODULE_PARM_DESC(speed, "SPI speed (override device default)");
43
44static int mode = -1;
45module_param(mode, int, 0000);
46MODULE_PARM_DESC(mode, "SPI mode (override device default)");
47
48static unsigned int fps;
49module_param(fps, uint, 0000);
50MODULE_PARM_DESC(fps, "Frames per second (override driver default)");
51
52static char *gamma;
53module_param(gamma, charp, 0000);
54MODULE_PARM_DESC(gamma,
55 "String representation of Gamma Curve(s). Driver specific.");
56
57static int txbuflen;
58module_param(txbuflen, int, 0000);
59MODULE_PARM_DESC(txbuflen, "txbuflen (override driver default)");
60
61static int bgr = -1;
62module_param(bgr, int, 0000);
63MODULE_PARM_DESC(bgr,
64 "BGR bit (supported by some drivers).");
65
66static unsigned int startbyte;
67module_param(startbyte, uint, 0000);
68MODULE_PARM_DESC(startbyte, "Sets the Start byte used by some SPI displays.");
69
70static bool custom;
71module_param(custom, bool, 0000);
72MODULE_PARM_DESC(custom, "Add a custom display device. Use speed= argument to make it a SPI device, else platform_device");
73
74static unsigned int width;
75module_param(width, uint, 0000);
76MODULE_PARM_DESC(width, "Display width, used with the custom argument");
77
78static unsigned int height;
79module_param(height, uint, 0000);
80MODULE_PARM_DESC(height, "Display height, used with the custom argument");
81
82static unsigned int buswidth = 8;
83module_param(buswidth, uint, 0000);
84MODULE_PARM_DESC(buswidth, "Display bus width, used with the custom argument");
85
86static s16 init[FBTFT_MAX_INIT_SEQUENCE];
87static int init_num;
88module_param_array(init, short, &init_num, 0000);
89MODULE_PARM_DESC(init, "Init sequence, used with the custom argument");
90
91static unsigned long debug;
92module_param(debug, ulong, 0000);
93MODULE_PARM_DESC(debug,
94 "level: 0-7 (the remaining 29 bits is for advanced usage)");
95
96static unsigned int verbose = 3;
97module_param(verbose, uint, 0000);
98MODULE_PARM_DESC(verbose,
99 "0 silent, >1 show devices, >2 show devices before (default=3)");
100
101struct fbtft_device_display {
102 char *name;
103 struct spi_board_info *spi;
104 struct platform_device *pdev;
105};
106
107static void fbtft_device_pdev_release(struct device *dev);
108
109static int write_gpio16_wr_slow(struct fbtft_par *par, void *buf, size_t len);
110static void adafruit18_green_tab_set_addr_win(struct fbtft_par *par,
111 int xs, int ys, int xe, int ye);
112
113#define ADAFRUIT18_GAMMA \
114 "02 1c 07 12 37 32 29 2d 29 25 2B 39 00 01 03 10\n" \
115 "03 1d 07 06 2E 2C 29 2D 2E 2E 37 3F 00 00 02 10"
116
117#define CBERRY28_GAMMA \
118 "D0 00 14 15 13 2C 42 43 4E 09 16 14 18 21\n" \
119 "D0 00 14 15 13 0B 43 55 53 0C 17 14 23 20"
120
121static const s16 cberry28_init_sequence[] = {
122 /* turn off sleep mode */
123 -1, MIPI_DCS_EXIT_SLEEP_MODE,
124 -2, 120,
125
126 /* set pixel format to RGB-565 */
127 -1, MIPI_DCS_SET_PIXEL_FORMAT, MIPI_DCS_PIXEL_FMT_16BIT,
128
129 -1, 0xB2, 0x0C, 0x0C, 0x00, 0x33, 0x33,
130
131 /*
132 * VGH = 13.26V
133 * VGL = -10.43V
134 */
135 -1, 0xB7, 0x35,
136
137 /*
138 * VDV and VRH register values come from command write
139 * (instead of NVM)
140 */
141 -1, 0xC2, 0x01, 0xFF,
142
143 /*
144 * VAP = 4.7V + (VCOM + VCOM offset + 0.5 * VDV)
145 * VAN = -4.7V + (VCOM + VCOM offset + 0.5 * VDV)
146 */
147 -1, 0xC3, 0x17,
148
149 /* VDV = 0V */
150 -1, 0xC4, 0x20,
151
152 /* VCOM = 0.675V */
153 -1, 0xBB, 0x17,
154
155 /* VCOM offset = 0V */
156 -1, 0xC5, 0x20,
157
158 /*
159 * AVDD = 6.8V
160 * AVCL = -4.8V
161 * VDS = 2.3V
162 */
163 -1, 0xD0, 0xA4, 0xA1,
164
165 -1, MIPI_DCS_SET_DISPLAY_ON,
166
167 -3,
168};
169
170static const s16 hy28b_init_sequence[] = {
171 -1, 0x00e7, 0x0010, -1, 0x0000, 0x0001,
172 -1, 0x0001, 0x0100, -1, 0x0002, 0x0700,
173 -1, 0x0003, 0x1030, -1, 0x0004, 0x0000,
174 -1, 0x0008, 0x0207, -1, 0x0009, 0x0000,
175 -1, 0x000a, 0x0000, -1, 0x000c, 0x0001,
176 -1, 0x000d, 0x0000, -1, 0x000f, 0x0000,
177 -1, 0x0010, 0x0000, -1, 0x0011, 0x0007,
178 -1, 0x0012, 0x0000, -1, 0x0013, 0x0000,
179 -2, 50, -1, 0x0010, 0x1590, -1, 0x0011,
180 0x0227, -2, 50, -1, 0x0012, 0x009c, -2, 50,
181 -1, 0x0013, 0x1900, -1, 0x0029, 0x0023,
182 -1, 0x002b, 0x000e, -2, 50,
183 -1, 0x0020, 0x0000, -1, 0x0021, 0x0000,
184 -2, 50, -1, 0x0050, 0x0000,
185 -1, 0x0051, 0x00ef, -1, 0x0052, 0x0000,
186 -1, 0x0053, 0x013f, -1, 0x0060, 0xa700,
187 -1, 0x0061, 0x0001, -1, 0x006a, 0x0000,
188 -1, 0x0080, 0x0000, -1, 0x0081, 0x0000,
189 -1, 0x0082, 0x0000, -1, 0x0083, 0x0000,
190 -1, 0x0084, 0x0000, -1, 0x0085, 0x0000,
191 -1, 0x0090, 0x0010, -1, 0x0092, 0x0000,
192 -1, 0x0093, 0x0003, -1, 0x0095, 0x0110,
193 -1, 0x0097, 0x0000, -1, 0x0098, 0x0000,
194 -1, 0x0007, 0x0133, -1, 0x0020, 0x0000,
195 -1, 0x0021, 0x0000, -2, 100, -3 };
196
197#define HY28B_GAMMA \
198 "04 1F 4 7 7 0 7 7 6 0\n" \
199 "0F 00 1 7 4 0 0 0 6 7"
200
201static const s16 pitft_init_sequence[] = {
202 -1, MIPI_DCS_SOFT_RESET,
203 -2, 5,
204 -1, MIPI_DCS_SET_DISPLAY_OFF,
205 -1, 0xEF, 0x03, 0x80, 0x02,
206 -1, 0xCF, 0x00, 0xC1, 0x30,
207 -1, 0xED, 0x64, 0x03, 0x12, 0x81,
208 -1, 0xE8, 0x85, 0x00, 0x78,
209 -1, 0xCB, 0x39, 0x2C, 0x00, 0x34, 0x02,
210 -1, 0xF7, 0x20,
211 -1, 0xEA, 0x00, 0x00,
212 -1, 0xC0, 0x23,
213 -1, 0xC1, 0x10,
214 -1, 0xC5, 0x3E, 0x28,
215 -1, 0xC7, 0x86,
216 -1, MIPI_DCS_SET_PIXEL_FORMAT, 0x55,
217 -1, 0xB1, 0x00, 0x18,
218 -1, 0xB6, 0x08, 0x82, 0x27,
219 -1, 0xF2, 0x00,
220 -1, MIPI_DCS_SET_GAMMA_CURVE, 0x01,
221 -1, 0xE0, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E,
222 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00,
223 -1, 0xE1, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31,
224 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F,
225 -1, MIPI_DCS_EXIT_SLEEP_MODE,
226 -2, 100,
227 -1, MIPI_DCS_SET_DISPLAY_ON,
228 -2, 20,
229 -3
230};
231
232static const s16 waveshare32b_init_sequence[] = {
233 -1, 0xCB, 0x39, 0x2C, 0x00, 0x34, 0x02,
234 -1, 0xCF, 0x00, 0xC1, 0x30,
235 -1, 0xE8, 0x85, 0x00, 0x78,
236 -1, 0xEA, 0x00, 0x00,
237 -1, 0xED, 0x64, 0x03, 0x12, 0x81,
238 -1, 0xF7, 0x20,
239 -1, 0xC0, 0x23,
240 -1, 0xC1, 0x10,
241 -1, 0xC5, 0x3E, 0x28,
242 -1, 0xC7, 0x86,
243 -1, MIPI_DCS_SET_ADDRESS_MODE, 0x28,
244 -1, MIPI_DCS_SET_PIXEL_FORMAT, 0x55,
245 -1, 0xB1, 0x00, 0x18,
246 -1, 0xB6, 0x08, 0x82, 0x27,
247 -1, 0xF2, 0x00,
248 -1, MIPI_DCS_SET_GAMMA_CURVE, 0x01,
249 -1, 0xE0, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E,
250 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00,
251 -1, 0xE1, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31,
252 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F,
253 -1, MIPI_DCS_EXIT_SLEEP_MODE,
254 -2, 120,
255 -1, MIPI_DCS_SET_DISPLAY_ON,
256 -1, MIPI_DCS_WRITE_MEMORY_START,
257 -3
258};
259
260#define PIOLED_GAMMA "0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 " \
261 "2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 " \
262 "3 3 3 4 4 4 4 4 4 4 4 4 4 4 4"
263
264/* Supported displays in alphabetical order */
265static struct fbtft_device_display displays[] = {
266 {
267 .name = "adafruit18",
268 .spi = &(struct spi_board_info) {
269 .modalias = "fb_st7735r",
270 .max_speed_hz = 32000000,
271 .mode = SPI_MODE_0,
272 .platform_data = &(struct fbtft_platform_data) {
273 .display = {
274 .buswidth = 8,
275 .backlight = 1,
276 },
277 .gamma = ADAFRUIT18_GAMMA,
278 }
279 }
280 }, {
281 .name = "adafruit18_green",
282 .spi = &(struct spi_board_info) {
283 .modalias = "fb_st7735r",
284 .max_speed_hz = 4000000,
285 .mode = SPI_MODE_0,
286 .platform_data = &(struct fbtft_platform_data) {
287 .display = {
288 .buswidth = 8,
289 .backlight = 1,
290 .fbtftops.set_addr_win =
291 adafruit18_green_tab_set_addr_win,
292 },
293 .bgr = true,
294 .gamma = ADAFRUIT18_GAMMA,
295 }
296 }
297 }, {
298 .name = "adafruit22",
299 .spi = &(struct spi_board_info) {
300 .modalias = "fb_hx8340bn",
301 .max_speed_hz = 32000000,
302 .mode = SPI_MODE_0,
303 .platform_data = &(struct fbtft_platform_data) {
304 .display = {
305 .buswidth = 9,
306 .backlight = 1,
307 },
308 .bgr = true,
309 }
310 }
311 }, {
312 .name = "adafruit22a",
313 .spi = &(struct spi_board_info) {
314 .modalias = "fb_ili9340",
315 .max_speed_hz = 32000000,
316 .mode = SPI_MODE_0,
317 .platform_data = &(struct fbtft_platform_data) {
318 .display = {
319 .buswidth = 8,
320 .backlight = 1,
321 },
322 .bgr = true,
323 }
324 }
325 }, {
326 .name = "adafruit28",
327 .spi = &(struct spi_board_info) {
328 .modalias = "fb_ili9341",
329 .max_speed_hz = 32000000,
330 .mode = SPI_MODE_0,
331 .platform_data = &(struct fbtft_platform_data) {
332 .display = {
333 .buswidth = 8,
334 .backlight = 1,
335 },
336 .bgr = true,
337 }
338 }
339 }, {
340 .name = "adafruit13m",
341 .spi = &(struct spi_board_info) {
342 .modalias = "fb_ssd1306",
343 .max_speed_hz = 16000000,
344 .mode = SPI_MODE_0,
345 .platform_data = &(struct fbtft_platform_data) {
346 .display = {
347 .buswidth = 8,
348 },
349 }
350 }
351 }, {
352 .name = "admatec_c-berry28",
353 .spi = &(struct spi_board_info) {
354 .modalias = "fb_st7789v",
355 .max_speed_hz = 48000000,
356 .mode = SPI_MODE_0,
357 .platform_data = &(struct fbtft_platform_data) {
358 .display = {
359 .buswidth = 8,
360 .backlight = 1,
361 .init_sequence = cberry28_init_sequence,
362 },
363 .gamma = CBERRY28_GAMMA,
364 }
365 }
366 }, {
367 .name = "agm1264k-fl",
368 .pdev = &(struct platform_device) {
369 .name = "fb_agm1264k-fl",
370 .id = 0,
371 .dev = {
372 .release = fbtft_device_pdev_release,
373 .platform_data = &(struct fbtft_platform_data) {
374 .display = {
375 .buswidth = 8,
376 .backlight = FBTFT_ONBOARD_BACKLIGHT,
377 },
378 },
379 }
380 }
381 }, {
382 .name = "dogs102",
383 .spi = &(struct spi_board_info) {
384 .modalias = "fb_uc1701",
385 .max_speed_hz = 8000000,
386 .mode = SPI_MODE_0,
387 .platform_data = &(struct fbtft_platform_data) {
388 .display = {
389 .buswidth = 8,
390 },
391 .bgr = true,
392 }
393 }
394 }, {
395 .name = "er_tftm050_2",
396 .spi = &(struct spi_board_info) {
397 .modalias = "fb_ra8875",
398 .max_speed_hz = 5000000,
399 .mode = SPI_MODE_3,
400 .platform_data = &(struct fbtft_platform_data) {
401 .display = {
402 .buswidth = 8,
403 .backlight = 1,
404 .width = 480,
405 .height = 272,
406 },
407 .bgr = true,
408 }
409 }
410 }, {
411 .name = "er_tftm070_5",
412 .spi = &(struct spi_board_info) {
413 .modalias = "fb_ra8875",
414 .max_speed_hz = 5000000,
415 .mode = SPI_MODE_3,
416 .platform_data = &(struct fbtft_platform_data) {
417 .display = {
418 .buswidth = 8,
419 .backlight = 1,
420 .width = 800,
421 .height = 480,
422 },
423 .bgr = true,
424 }
425 }
426 }, {
427 .name = "ew24ha0",
428 .spi = &(struct spi_board_info) {
429 .modalias = "fb_uc1611",
430 .max_speed_hz = 32000000,
431 .mode = SPI_MODE_3,
432 .platform_data = &(struct fbtft_platform_data) {
433 .display = {
434 .buswidth = 8,
435 },
436 }
437 }
438 }, {
439 .name = "ew24ha0_9bit",
440 .spi = &(struct spi_board_info) {
441 .modalias = "fb_uc1611",
442 .max_speed_hz = 32000000,
443 .mode = SPI_MODE_3,
444 .platform_data = &(struct fbtft_platform_data) {
445 .display = {
446 .buswidth = 9,
447 },
448 }
449 }
450 }, {
451 .name = "flexfb",
452 .spi = &(struct spi_board_info) {
453 .modalias = "flexfb",
454 .max_speed_hz = 32000000,
455 .mode = SPI_MODE_0,
456 }
457 }, {
458 .name = "flexpfb",
459 .pdev = &(struct platform_device) {
460 .name = "flexpfb",
461 .id = 0,
462 .dev = {
463 .release = fbtft_device_pdev_release,
464 }
465 }
466 }, {
467 .name = "freetronicsoled128",
468 .spi = &(struct spi_board_info) {
469 .modalias = "fb_ssd1351",
470 .max_speed_hz = 20000000,
471 .mode = SPI_MODE_0,
472 .platform_data = &(struct fbtft_platform_data) {
473 .display = {
474 .buswidth = 8,
475 .backlight = FBTFT_ONBOARD_BACKLIGHT,
476 },
477 .bgr = true,
478 }
479 }
480 }, {
481 .name = "hx8353d",
482 .spi = &(struct spi_board_info) {
483 .modalias = "fb_hx8353d",
484 .max_speed_hz = 16000000,
485 .mode = SPI_MODE_0,
486 .platform_data = &(struct fbtft_platform_data) {
487 .display = {
488 .buswidth = 8,
489 .backlight = 1,
490 },
491 }
492 }
493 }, {
494 .name = "hy28a",
495 .spi = &(struct spi_board_info) {
496 .modalias = "fb_ili9320",
497 .max_speed_hz = 32000000,
498 .mode = SPI_MODE_3,
499 .platform_data = &(struct fbtft_platform_data) {
500 .display = {
501 .buswidth = 8,
502 .backlight = 1,
503 },
504 .startbyte = 0x70,
505 .bgr = true,
506 }
507 }
508 }, {
509 .name = "hy28b",
510 .spi = &(struct spi_board_info) {
511 .modalias = "fb_ili9325",
512 .max_speed_hz = 48000000,
513 .mode = SPI_MODE_3,
514 .platform_data = &(struct fbtft_platform_data) {
515 .display = {
516 .buswidth = 8,
517 .backlight = 1,
518 .init_sequence = hy28b_init_sequence,
519 },
520 .startbyte = 0x70,
521 .bgr = true,
522 .fps = 50,
523 .gamma = HY28B_GAMMA,
524 }
525 }
526 }, {
527 .name = "ili9481",
528 .spi = &(struct spi_board_info) {
529 .modalias = "fb_ili9481",
530 .max_speed_hz = 32000000,
531 .mode = SPI_MODE_0,
532 .platform_data = &(struct fbtft_platform_data) {
533 .display = {
534 .regwidth = 16,
535 .buswidth = 8,
536 .backlight = 1,
537 },
538 .bgr = true,
539 }
540 }
541 }, {
542 .name = "itdb24",
543 .pdev = &(struct platform_device) {
544 .name = "fb_s6d1121",
545 .id = 0,
546 .dev = {
547 .release = fbtft_device_pdev_release,
548 .platform_data = &(struct fbtft_platform_data) {
549 .display = {
550 .buswidth = 8,
551 .backlight = 1,
552 },
553 .bgr = false,
554 },
555 }
556 }
557 }, {
558 .name = "itdb28",
559 .pdev = &(struct platform_device) {
560 .name = "fb_ili9325",
561 .id = 0,
562 .dev = {
563 .release = fbtft_device_pdev_release,
564 .platform_data = &(struct fbtft_platform_data) {
565 .display = {
566 .buswidth = 8,
567 .backlight = 1,
568 },
569 .bgr = true,
570 },
571 }
572 }
573 }, {
574 .name = "itdb28_spi",
575 .spi = &(struct spi_board_info) {
576 .modalias = "fb_ili9325",
577 .max_speed_hz = 32000000,
578 .mode = SPI_MODE_0,
579 .platform_data = &(struct fbtft_platform_data) {
580 .display = {
581 .buswidth = 8,
582 .backlight = 1,
583 },
584 .bgr = true,
585 }
586 }
587 }, {
588 .name = "mi0283qt-2",
589 .spi = &(struct spi_board_info) {
590 .modalias = "fb_hx8347d",
591 .max_speed_hz = 32000000,
592 .mode = SPI_MODE_0,
593 .platform_data = &(struct fbtft_platform_data) {
594 .display = {
595 .buswidth = 8,
596 .backlight = 1,
597 },
598 .startbyte = 0x70,
599 .bgr = true,
600 }
601 }
602 }, {
603 .name = "mi0283qt-9a",
604 .spi = &(struct spi_board_info) {
605 .modalias = "fb_ili9341",
606 .max_speed_hz = 32000000,
607 .mode = SPI_MODE_0,
608 .platform_data = &(struct fbtft_platform_data) {
609 .display = {
610 .buswidth = 9,
611 .backlight = 1,
612 },
613 .bgr = true,
614 }
615 }
616 }, {
617 .name = "mi0283qt-v2",
618 .spi = &(struct spi_board_info) {
619 .modalias = "fb_watterott",
620 .max_speed_hz = 4000000,
621 .mode = SPI_MODE_3,
622 .platform_data = &(struct fbtft_platform_data) {
623 }
624 }
625 }, {
626 .name = "nokia3310",
627 .spi = &(struct spi_board_info) {
628 .modalias = "fb_pcd8544",
629 .max_speed_hz = 400000,
630 .mode = SPI_MODE_0,
631 .platform_data = &(struct fbtft_platform_data) {
632 .display = {
633 .buswidth = 8,
634 },
635 }
636 }
637 }, {
638 .name = "nokia3310a",
639 .spi = &(struct spi_board_info) {
640 .modalias = "fb_tls8204",
641 .max_speed_hz = 1000000,
642 .mode = SPI_MODE_0,
643 .platform_data = &(struct fbtft_platform_data) {
644 .display = {
645 .buswidth = 8,
646 },
647 }
648 }
649 }, {
650 .name = "nokia5110",
651 .spi = &(struct spi_board_info) {
652 .modalias = "fb_ili9163",
653 .max_speed_hz = 12000000,
654 .mode = SPI_MODE_0,
655 .platform_data = &(struct fbtft_platform_data) {
656 .display = {
657 .buswidth = 8,
658 .backlight = 1,
659 },
660 .bgr = true,
661 }
662 }
663 }, {
664 .name = "piscreen",
665 .spi = &(struct spi_board_info) {
666 .modalias = "fb_ili9486",
667 .max_speed_hz = 32000000,
668 .mode = SPI_MODE_0,
669 .platform_data = &(struct fbtft_platform_data) {
670 .display = {
671 .regwidth = 16,
672 .buswidth = 8,
673 .backlight = 1,
674 },
675 .bgr = true,
676 }
677 }
678 }, {
679 .name = "pitft",
680 .spi = &(struct spi_board_info) {
681 .modalias = "fb_ili9340",
682 .max_speed_hz = 32000000,
683 .mode = SPI_MODE_0,
684 .chip_select = 0,
685 .platform_data = &(struct fbtft_platform_data) {
686 .display = {
687 .buswidth = 8,
688 .backlight = 1,
689 .init_sequence = pitft_init_sequence,
690 },
691 .bgr = true,
692 }
693 }
694 }, {
695 .name = "pioled",
696 .spi = &(struct spi_board_info) {
697 .modalias = "fb_ssd1351",
698 .max_speed_hz = 20000000,
699 .mode = SPI_MODE_0,
700 .platform_data = &(struct fbtft_platform_data) {
701 .display = {
702 .buswidth = 8,
703 },
704 .bgr = true,
705 .gamma = PIOLED_GAMMA
706 }
707 }
708 }, {
709 .name = "rpi-display",
710 .spi = &(struct spi_board_info) {
711 .modalias = "fb_ili9341",
712 .max_speed_hz = 32000000,
713 .mode = SPI_MODE_0,
714 .platform_data = &(struct fbtft_platform_data) {
715 .display = {
716 .buswidth = 8,
717 .backlight = 1,
718 },
719 .bgr = true,
720 }
721 }
722 }, {
723 .name = "s6d02a1",
724 .spi = &(struct spi_board_info) {
725 .modalias = "fb_s6d02a1",
726 .max_speed_hz = 32000000,
727 .mode = SPI_MODE_0,
728 .platform_data = &(struct fbtft_platform_data) {
729 .display = {
730 .buswidth = 8,
731 .backlight = 1,
732 },
733 .bgr = true,
734 }
735 }
736 }, {
737 .name = "sainsmart18",
738 .spi = &(struct spi_board_info) {
739 .modalias = "fb_st7735r",
740 .max_speed_hz = 32000000,
741 .mode = SPI_MODE_0,
742 .platform_data = &(struct fbtft_platform_data) {
743 .display = {
744 .buswidth = 8,
745 },
746 }
747 }
748 }, {
749 .name = "sainsmart32",
750 .pdev = &(struct platform_device) {
751 .name = "fb_ssd1289",
752 .id = 0,
753 .dev = {
754 .release = fbtft_device_pdev_release,
755 .platform_data = &(struct fbtft_platform_data) {
756 .display = {
757 .buswidth = 16,
758 .txbuflen = -2, /* disable buffer */
759 .backlight = 1,
760 .fbtftops.write = write_gpio16_wr_slow,
761 },
762 .bgr = true,
763 },
764 },
765 }
766 }, {
767 .name = "sainsmart32_fast",
768 .pdev = &(struct platform_device) {
769 .name = "fb_ssd1289",
770 .id = 0,
771 .dev = {
772 .release = fbtft_device_pdev_release,
773 .platform_data = &(struct fbtft_platform_data) {
774 .display = {
775 .buswidth = 16,
776 .txbuflen = -2, /* disable buffer */
777 .backlight = 1,
778 },
779 .bgr = true,
780 },
781 },
782 }
783 }, {
784 .name = "sainsmart32_latched",
785 .pdev = &(struct platform_device) {
786 .name = "fb_ssd1289",
787 .id = 0,
788 .dev = {
789 .release = fbtft_device_pdev_release,
790 .platform_data = &(struct fbtft_platform_data) {
791 .display = {
792 .buswidth = 16,
793 .txbuflen = -2, /* disable buffer */
794 .backlight = 1,
795 .fbtftops.write =
796 fbtft_write_gpio16_wr_latched,
797 },
798 .bgr = true,
799 },
800 },
801 }
802 }, {
803 .name = "sainsmart32_spi",
804 .spi = &(struct spi_board_info) {
805 .modalias = "fb_ssd1289",
806 .max_speed_hz = 16000000,
807 .mode = SPI_MODE_0,
808 .platform_data = &(struct fbtft_platform_data) {
809 .display = {
810 .buswidth = 8,
811 .backlight = 1,
812 },
813 .bgr = true,
814 }
815 }
816 }, {
817 .name = "spidev",
818 .spi = &(struct spi_board_info) {
819 .modalias = "spidev",
820 .max_speed_hz = 500000,
821 .bus_num = 0,
822 .chip_select = 0,
823 .mode = SPI_MODE_0,
824 .platform_data = &(struct fbtft_platform_data) {
825 }
826 }
827 }, {
828 .name = "ssd1331",
829 .spi = &(struct spi_board_info) {
830 .modalias = "fb_ssd1331",
831 .max_speed_hz = 20000000,
832 .mode = SPI_MODE_3,
833 .platform_data = &(struct fbtft_platform_data) {
834 .display = {
835 .buswidth = 8,
836 },
837 }
838 }
839 }, {
840 .name = "tinylcd35",
841 .spi = &(struct spi_board_info) {
842 .modalias = "fb_tinylcd",
843 .max_speed_hz = 32000000,
844 .mode = SPI_MODE_0,
845 .platform_data = &(struct fbtft_platform_data) {
846 .display = {
847 .buswidth = 8,
848 .backlight = 1,
849 },
850 .bgr = true,
851 }
852 }
853 }, {
854 .name = "tm022hdh26",
855 .spi = &(struct spi_board_info) {
856 .modalias = "fb_ili9341",
857 .max_speed_hz = 32000000,
858 .mode = SPI_MODE_0,
859 .platform_data = &(struct fbtft_platform_data) {
860 .display = {
861 .buswidth = 8,
862 .backlight = 1,
863 },
864 .bgr = true,
865 }
866 }
867 }, {
868 .name = "tontec35_9481", /* boards before 02 July 2014 */
869 .spi = &(struct spi_board_info) {
870 .modalias = "fb_ili9481",
871 .max_speed_hz = 128000000,
872 .mode = SPI_MODE_3,
873 .platform_data = &(struct fbtft_platform_data) {
874 .display = {
875 .buswidth = 8,
876 .backlight = 1,
877 },
878 .bgr = true,
879 }
880 }
881 }, {
882 .name = "tontec35_9486", /* boards after 02 July 2014 */
883 .spi = &(struct spi_board_info) {
884 .modalias = "fb_ili9486",
885 .max_speed_hz = 128000000,
886 .mode = SPI_MODE_3,
887 .platform_data = &(struct fbtft_platform_data) {
888 .display = {
889 .buswidth = 8,
890 .backlight = 1,
891 },
892 .bgr = true,
893 }
894 }
895 }, {
896 .name = "upd161704",
897 .spi = &(struct spi_board_info) {
898 .modalias = "fb_upd161704",
899 .max_speed_hz = 32000000,
900 .mode = SPI_MODE_0,
901 .platform_data = &(struct fbtft_platform_data) {
902 .display = {
903 .buswidth = 8,
904 },
905 }
906 }
907 }, {
908 .name = "waveshare32b",
909 .spi = &(struct spi_board_info) {
910 .modalias = "fb_ili9340",
911 .max_speed_hz = 48000000,
912 .mode = SPI_MODE_0,
913 .platform_data = &(struct fbtft_platform_data) {
914 .display = {
915 .buswidth = 8,
916 .backlight = 1,
917 .init_sequence =
918 waveshare32b_init_sequence,
919 },
920 .bgr = true,
921 }
922 }
923 }, {
924 .name = "waveshare22",
925 .spi = &(struct spi_board_info) {
926 .modalias = "fb_bd663474",
927 .max_speed_hz = 32000000,
928 .mode = SPI_MODE_3,
929 .platform_data = &(struct fbtft_platform_data) {
930 .display = {
931 .buswidth = 8,
932 },
933 }
934 }
935 }, {
936 /* This should be the last item.
937 * Used with the custom argument
938 */
939 .name = "",
940 .spi = &(struct spi_board_info) {
941 .modalias = "",
942 .max_speed_hz = 0,
943 .mode = SPI_MODE_0,
944 .platform_data = &(struct fbtft_platform_data) {
945 }
946 },
947 .pdev = &(struct platform_device) {
948 .name = "",
949 .id = 0,
950 .dev = {
951 .release = fbtft_device_pdev_release,
952 .platform_data = &(struct fbtft_platform_data) {
953 },
954 },
955 },
956 }
957};
958
959static int write_gpio16_wr_slow(struct fbtft_par *par, void *buf, size_t len)
960{
961 u16 data;
962 int i;
963#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
964 static u16 prev_data;
965#endif
966
967 fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
968 "%s(len=%zu): ", __func__, len);
969
970 while (len) {
971 data = *(u16 *)buf;
972
973 /* Start writing by pulling down /WR */
974 gpiod_set_value(par->gpio.wr, 0);
975
976 /* Set data */
977#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
978 if (data == prev_data) {
979 gpiod_set_value(par->gpio.wr, 0); /* used as delay */
980 } else {
981 for (i = 0; i < 16; i++) {
982 if ((data & 1) != (prev_data & 1))
983 gpiod_set_value(par->gpio.db[i],
984 data & 1);
985 data >>= 1;
986 prev_data >>= 1;
987 }
988 }
989#else
990 for (i = 0; i < 16; i++) {
991 gpiod_set_value(par->gpio.db[i], data & 1);
992 data >>= 1;
993 }
994#endif
995
996 /* Pullup /WR */
997 gpiod_set_value(par->gpio.wr, 1);
998
999#ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
1000 prev_data = *(u16 *)buf;
1001#endif
1002 buf += 2;
1003 len -= 2;
1004 }
1005
1006 return 0;
1007}
1008
1009static void adafruit18_green_tab_set_addr_win(struct fbtft_par *par,
1010 int xs, int ys, int xe, int ye)
1011{
1012 write_reg(par, 0x2A, 0, xs + 2, 0, xe + 2);
1013 write_reg(par, 0x2B, 0, ys + 1, 0, ye + 1);
1014 write_reg(par, 0x2C);
1015}
1016
1017static void fbtft_device_pdev_release(struct device *dev)
1018{
1019/* Needed to silence this message:
1020 * Device 'xxx' does not have a release() function,
1021 * it is broken and must be fixed
1022 */
1023}
1024
1025static int spi_device_found(struct device *dev, void *data)
1026{
1027 struct spi_device *spi = to_spi_device(dev);
1028
1029 dev_info(dev, "%s %s %dkHz %d bits mode=0x%02X\n", spi->modalias,
1030 dev_name(dev), spi->max_speed_hz / 1000, spi->bits_per_word,
1031 spi->mode);
1032
1033 return 0;
1034}
1035
1036static void pr_spi_devices(void)
1037{
1038 pr_debug("SPI devices registered:\n");
1039 bus_for_each_dev(&spi_bus_type, NULL, NULL, spi_device_found);
1040}
1041
1042static int p_device_found(struct device *dev, void *data)
1043{
1044 struct platform_device
1045 *pdev = to_platform_device(dev);
1046
1047 if (strstr(pdev->name, "fb"))
1048 dev_info(dev, "%s id=%d pdata? %s\n", pdev->name, pdev->id,
1049 pdev->dev.platform_data ? "yes" : "no");
1050
1051 return 0;
1052}
1053
1054static void pr_p_devices(void)
1055{
1056 pr_debug("'fb' Platform devices registered:\n");
1057 bus_for_each_dev(&platform_bus_type, NULL, NULL, p_device_found);
1058}
1059
1060#ifdef MODULE
1061static void fbtft_device_spi_delete(struct spi_master *master, unsigned int cs)
1062{
1063 struct device *dev;
1064 char str[32];
1065
1066 snprintf(str, sizeof(str), "%s.%u", dev_name(&master->dev), cs);
1067
1068 dev = bus_find_device_by_name(&spi_bus_type, NULL, str);
1069 if (dev) {
1070 if (verbose)
1071 dev_info(dev, "Deleting %s\n", str);
1072 device_del(dev);
1073 }
1074}
1075
1076static int fbtft_device_spi_device_register(struct spi_board_info *spi)
1077{
1078 struct spi_master *master;
1079
1080 master = spi_busnum_to_master(spi->bus_num);
1081 if (!master) {
1082 pr_err("spi_busnum_to_master(%d) returned NULL\n",
1083 spi->bus_num);
1084 return -EINVAL;
1085 }
1086 /* make sure it's available */
1087 fbtft_device_spi_delete(master, spi->chip_select);
1088 spi_device = spi_new_device(master, spi);
1089 put_device(&master->dev);
1090 if (!spi_device) {
1091 dev_err(&master->dev, "spi_new_device() returned NULL\n");
1092 return -EPERM;
1093 }
1094 return 0;
1095}
1096#else
1097static int fbtft_device_spi_device_register(struct spi_board_info *spi)
1098{
1099 return spi_register_board_info(spi, 1);
1100}
1101#endif
1102
1103static int __init fbtft_device_init(void)
1104{
1105 struct spi_board_info *spi = NULL;
1106 struct fbtft_platform_data *pdata;
1107 bool found = false;
1108 int i = 0;
1109 int ret = 0;
1110
1111 if (!name) {
1112#ifdef MODULE
1113 pr_err("missing module parameter: 'name'\n");
1114 return -EINVAL;
1115#else
1116 return 0;
1117#endif
1118 }
1119
1120 if (init_num > FBTFT_MAX_INIT_SEQUENCE) {
1121 pr_err("init parameter: exceeded max array size: %d\n",
1122 FBTFT_MAX_INIT_SEQUENCE);
1123 return -EINVAL;
1124 }
1125
1126 if (verbose > 2) {
1127 pr_spi_devices(); /* print list of registered SPI devices */
1128 pr_p_devices(); /* print list of 'fb' platform devices */
1129 }
1130
1131 pr_debug("name='%s', busnum=%d, cs=%d\n", name, busnum, cs);
1132
1133 if (rotate > 0 && rotate < 4) {
1134 rotate = (4 - rotate) * 90;
1135 pr_warn("argument 'rotate' should be an angle. Values 1-3 is deprecated. Setting it to %d.\n",
1136 rotate);
1137 }
1138 if (rotate != 0 && rotate != 90 && rotate != 180 && rotate != 270) {
1139 pr_warn("argument 'rotate' illegal value: %d. Setting it to 0.\n",
1140 rotate);
1141 rotate = 0;
1142 }
1143
1144 /* name=list lists all supported displays */
1145 if (strcmp(name, "list") == 0) {
1146 pr_info("Supported displays:\n");
1147
1148 for (i = 0; i < ARRAY_SIZE(displays); i++)
1149 pr_info("%s\n", displays[i].name);
1150 return -ECANCELED;
1151 }
1152
1153 if (custom) {
1154 i = ARRAY_SIZE(displays) - 1;
1155 displays[i].name = name;
1156 if (speed == 0) {
1157 displays[i].pdev->name = name;
1158 displays[i].spi = NULL;
1159 } else {
1160 size_t len;
1161
1162 len = strlcpy(displays[i].spi->modalias, name,
1163 SPI_NAME_SIZE);
1164 if (len >= SPI_NAME_SIZE)
1165 pr_warn("modalias (name) truncated to: %s\n",
1166 displays[i].spi->modalias);
1167 displays[i].pdev = NULL;
1168 }
1169 }
1170
1171 for (i = 0; i < ARRAY_SIZE(displays); i++) {
1172 if (strncmp(name, displays[i].name, SPI_NAME_SIZE) == 0) {
1173 if (displays[i].spi) {
1174 spi = displays[i].spi;
1175 spi->chip_select = cs;
1176 spi->bus_num = busnum;
1177 if (speed)
1178 spi->max_speed_hz = speed;
1179 if (mode != -1)
1180 spi->mode = mode;
1181 pdata = (void *)spi->platform_data;
1182 } else if (displays[i].pdev) {
1183 p_device = displays[i].pdev;
1184 pdata = p_device->dev.platform_data;
1185 } else {
1186 pr_err("broken displays array\n");
1187 return -EINVAL;
1188 }
1189
1190 pdata->rotate = rotate;
1191 if (bgr == 0)
1192 pdata->bgr = false;
1193 else if (bgr == 1)
1194 pdata->bgr = true;
1195 if (startbyte)
1196 pdata->startbyte = startbyte;
1197 if (gamma)
1198 pdata->gamma = gamma;
1199 pdata->display.debug = debug;
1200 if (fps)
1201 pdata->fps = fps;
1202 if (txbuflen)
1203 pdata->txbuflen = txbuflen;
1204 if (init_num)
1205 pdata->display.init_sequence = init;
1206 if (custom) {
1207 pdata->display.width = width;
1208 pdata->display.height = height;
1209 pdata->display.buswidth = buswidth;
1210 pdata->display.backlight = 1;
1211 }
1212
1213 if (displays[i].spi) {
1214 ret = fbtft_device_spi_device_register(spi);
1215 if (ret) {
1216 pr_err("failed to register SPI device\n");
1217 return ret;
1218 }
1219 } else {
1220 ret = platform_device_register(p_device);
1221 if (ret < 0) {
1222 pr_err("platform_device_register() returned %d\n",
1223 ret);
1224 return ret;
1225 }
1226 }
1227 found = true;
1228 break;
1229 }
1230 }
1231
1232 if (!found) {
1233 pr_err("display not supported: '%s'\n", name);
1234 return -EINVAL;
1235 }
1236
1237 if (spi_device && (verbose > 1))
1238 pr_spi_devices();
1239 if (p_device && (verbose > 1))
1240 pr_p_devices();
1241
1242 return 0;
1243}
1244
1245static void __exit fbtft_device_exit(void)
1246{
1247 if (spi_device) {
1248 device_del(&spi_device->dev);
1249 kfree(spi_device);
1250 }
1251
1252 if (p_device)
1253 platform_device_unregister(p_device);
1254}
1255
1256arch_initcall(fbtft_device_init);
1257module_exit(fbtft_device_exit);
1258
1259MODULE_DESCRIPTION("Add a FBTFT device.");
1260MODULE_AUTHOR("Noralf Tronnes");
1261MODULE_LICENSE("GPL");
diff --git a/drivers/staging/fbtft/flexfb.c b/drivers/staging/fbtft/flexfb.c
deleted file mode 100644
index 3747321011fa..000000000000
--- a/drivers/staging/fbtft/flexfb.c
+++ /dev/null
@@ -1,851 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Generic FB driver for TFT LCD displays
4 *
5 * Copyright (C) 2013 Noralf Tronnes
6 */
7
8#include <linux/module.h>
9#include <linux/kernel.h>
10#include <linux/init.h>
11#include <linux/vmalloc.h>
12#include <linux/gpio/consumer.h>
13#include <linux/spi/spi.h>
14#include <linux/delay.h>
15
16#include "fbtft.h"
17
18#define DRVNAME "flexfb"
19
20static char *chip;
21module_param(chip, charp, 0000);
22MODULE_PARM_DESC(chip, "LCD controller");
23
24static unsigned int width;
25module_param(width, uint, 0000);
26MODULE_PARM_DESC(width, "Display width");
27
28static unsigned int height;
29module_param(height, uint, 0000);
30MODULE_PARM_DESC(height, "Display height");
31
32static s16 init[512];
33static int init_num;
34module_param_array(init, short, &init_num, 0000);
35MODULE_PARM_DESC(init, "Init sequence");
36
37static unsigned int setaddrwin;
38module_param(setaddrwin, uint, 0000);
39MODULE_PARM_DESC(setaddrwin, "Which set_addr_win() implementation to use");
40
41static unsigned int buswidth = 8;
42module_param(buswidth, uint, 0000);
43MODULE_PARM_DESC(buswidth, "Width of databus (default: 8)");
44
45static unsigned int regwidth = 8;
46module_param(regwidth, uint, 0000);
47MODULE_PARM_DESC(regwidth, "Width of controller register (default: 8)");
48
49static bool nobacklight;
50module_param(nobacklight, bool, 0000);
51MODULE_PARM_DESC(nobacklight, "Turn off backlight functionality.");
52
53static bool latched;
54module_param(latched, bool, 0000);
55MODULE_PARM_DESC(latched, "Use with latched 16-bit databus");
56
57static const s16 *initp;
58static int initp_num;
59
60/* default init sequences */
61static const s16 st7735r_init[] = {
62 -1, 0x01,
63 -2, 150,
64 -1, 0x11,
65 -2, 500,
66 -1, 0xB1, 0x01, 0x2C, 0x2D,
67 -1, 0xB2, 0x01, 0x2C, 0x2D,
68 -1, 0xB3, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D,
69 -1, 0xB4, 0x07,
70 -1, 0xC0, 0xA2, 0x02, 0x84,
71 -1, 0xC1, 0xC5,
72 -1, 0xC2, 0x0A, 0x00,
73 -1, 0xC3, 0x8A, 0x2A,
74 -1, 0xC4, 0x8A, 0xEE,
75 -1, 0xC5, 0x0E,
76 -1, 0x20,
77 -1, 0x36, 0xC0,
78 -1, 0x3A, 0x05,
79 -1, 0xE0, 0x0f, 0x1a, 0x0f, 0x18, 0x2f, 0x28, 0x20, 0x22,
80 0x1f, 0x1b, 0x23, 0x37, 0x00, 0x07, 0x02, 0x10,
81 -1, 0xE1, 0x0f, 0x1b, 0x0f, 0x17, 0x33, 0x2c, 0x29, 0x2e,
82 0x30, 0x30, 0x39, 0x3f, 0x00, 0x07, 0x03, 0x10,
83 -1, 0x29,
84 -2, 100,
85 -1, 0x13,
86 -2, 10,
87 -3
88};
89
90static const s16 ssd1289_init[] = {
91 -1, 0x00, 0x0001,
92 -1, 0x03, 0xA8A4,
93 -1, 0x0C, 0x0000,
94 -1, 0x0D, 0x080C,
95 -1, 0x0E, 0x2B00,
96 -1, 0x1E, 0x00B7,
97 -1, 0x01, 0x2B3F,
98 -1, 0x02, 0x0600,
99 -1, 0x10, 0x0000,
100 -1, 0x11, 0x6070,
101 -1, 0x05, 0x0000,
102 -1, 0x06, 0x0000,
103 -1, 0x16, 0xEF1C,
104 -1, 0x17, 0x0003,
105 -1, 0x07, 0x0233,
106 -1, 0x0B, 0x0000,
107 -1, 0x0F, 0x0000,
108 -1, 0x41, 0x0000,
109 -1, 0x42, 0x0000,
110 -1, 0x48, 0x0000,
111 -1, 0x49, 0x013F,
112 -1, 0x4A, 0x0000,
113 -1, 0x4B, 0x0000,
114 -1, 0x44, 0xEF00,
115 -1, 0x45, 0x0000,
116 -1, 0x46, 0x013F,
117 -1, 0x30, 0x0707,
118 -1, 0x31, 0x0204,
119 -1, 0x32, 0x0204,
120 -1, 0x33, 0x0502,
121 -1, 0x34, 0x0507,
122 -1, 0x35, 0x0204,
123 -1, 0x36, 0x0204,
124 -1, 0x37, 0x0502,
125 -1, 0x3A, 0x0302,
126 -1, 0x3B, 0x0302,
127 -1, 0x23, 0x0000,
128 -1, 0x24, 0x0000,
129 -1, 0x25, 0x8000,
130 -1, 0x4f, 0x0000,
131 -1, 0x4e, 0x0000,
132 -1, 0x22,
133 -3
134};
135
136static const s16 hx8340bn_init[] = {
137 -1, 0xC1, 0xFF, 0x83, 0x40,
138 -1, 0x11,
139 -2, 150,
140 -1, 0xCA, 0x70, 0x00, 0xD9,
141 -1, 0xB0, 0x01, 0x11,
142 -1, 0xC9, 0x90, 0x49, 0x10, 0x28, 0x28, 0x10, 0x00, 0x06,
143 -2, 20,
144 -1, 0xC2, 0x60, 0x71, 0x01, 0x0E, 0x05, 0x02, 0x09, 0x31, 0x0A,
145 -1, 0xC3, 0x67, 0x30, 0x61, 0x17, 0x48, 0x07, 0x05, 0x33,
146 -2, 10,
147 -1, 0xB5, 0x35, 0x20, 0x45,
148 -1, 0xB4, 0x33, 0x25, 0x4C,
149 -2, 10,
150 -1, 0x3A, 0x05,
151 -1, 0x29,
152 -2, 10,
153 -3
154};
155
156static const s16 ili9225_init[] = {
157 -1, 0x0001, 0x011C,
158 -1, 0x0002, 0x0100,
159 -1, 0x0003, 0x1030,
160 -1, 0x0008, 0x0808,
161 -1, 0x000C, 0x0000,
162 -1, 0x000F, 0x0A01,
163 -1, 0x0020, 0x0000,
164 -1, 0x0021, 0x0000,
165 -2, 50,
166 -1, 0x0010, 0x0A00,
167 -1, 0x0011, 0x1038,
168 -2, 50,
169 -1, 0x0012, 0x1121,
170 -1, 0x0013, 0x004E,
171 -1, 0x0014, 0x676F,
172 -1, 0x0030, 0x0000,
173 -1, 0x0031, 0x00DB,
174 -1, 0x0032, 0x0000,
175 -1, 0x0033, 0x0000,
176 -1, 0x0034, 0x00DB,
177 -1, 0x0035, 0x0000,
178 -1, 0x0036, 0x00AF,
179 -1, 0x0037, 0x0000,
180 -1, 0x0038, 0x00DB,
181 -1, 0x0039, 0x0000,
182 -1, 0x0050, 0x0000,
183 -1, 0x0051, 0x060A,
184 -1, 0x0052, 0x0D0A,
185 -1, 0x0053, 0x0303,
186 -1, 0x0054, 0x0A0D,
187 -1, 0x0055, 0x0A06,
188 -1, 0x0056, 0x0000,
189 -1, 0x0057, 0x0303,
190 -1, 0x0058, 0x0000,
191 -1, 0x0059, 0x0000,
192 -2, 50,
193 -1, 0x0007, 0x1017,
194 -2, 50,
195 -3
196};
197
198static const s16 ili9320_init[] = {
199 -1, 0x00E5, 0x8000,
200 -1, 0x0000, 0x0001,
201 -1, 0x0001, 0x0100,
202 -1, 0x0002, 0x0700,
203 -1, 0x0003, 0x1030,
204 -1, 0x0004, 0x0000,
205 -1, 0x0008, 0x0202,
206 -1, 0x0009, 0x0000,
207 -1, 0x000A, 0x0000,
208 -1, 0x000C, 0x0000,
209 -1, 0x000D, 0x0000,
210 -1, 0x000F, 0x0000,
211 -1, 0x0010, 0x0000,
212 -1, 0x0011, 0x0007,
213 -1, 0x0012, 0x0000,
214 -1, 0x0013, 0x0000,
215 -2, 200,
216 -1, 0x0010, 0x17B0,
217 -1, 0x0011, 0x0031,
218 -2, 50,
219 -1, 0x0012, 0x0138,
220 -2, 50,
221 -1, 0x0013, 0x1800,
222 -1, 0x0029, 0x0008,
223 -2, 50,
224 -1, 0x0020, 0x0000,
225 -1, 0x0021, 0x0000,
226 -1, 0x0030, 0x0000,
227 -1, 0x0031, 0x0505,
228 -1, 0x0032, 0x0004,
229 -1, 0x0035, 0x0006,
230 -1, 0x0036, 0x0707,
231 -1, 0x0037, 0x0105,
232 -1, 0x0038, 0x0002,
233 -1, 0x0039, 0x0707,
234 -1, 0x003C, 0x0704,
235 -1, 0x003D, 0x0807,
236 -1, 0x0050, 0x0000,
237 -1, 0x0051, 0x00EF,
238 -1, 0x0052, 0x0000,
239 -1, 0x0053, 0x013F,
240 -1, 0x0060, 0x2700,
241 -1, 0x0061, 0x0001,
242 -1, 0x006A, 0x0000,
243 -1, 0x0080, 0x0000,
244 -1, 0x0081, 0x0000,
245 -1, 0x0082, 0x0000,
246 -1, 0x0083, 0x0000,
247 -1, 0x0084, 0x0000,
248 -1, 0x0085, 0x0000,
249 -1, 0x0090, 0x0010,
250 -1, 0x0092, 0x0000,
251 -1, 0x0093, 0x0003,
252 -1, 0x0095, 0x0110,
253 -1, 0x0097, 0x0000,
254 -1, 0x0098, 0x0000,
255 -1, 0x0007, 0x0173,
256 -3
257};
258
259static const s16 ili9325_init[] = {
260 -1, 0x00E3, 0x3008,
261 -1, 0x00E7, 0x0012,
262 -1, 0x00EF, 0x1231,
263 -1, 0x0001, 0x0100,
264 -1, 0x0002, 0x0700,
265 -1, 0x0003, 0x1030,
266 -1, 0x0004, 0x0000,
267 -1, 0x0008, 0x0207,
268 -1, 0x0009, 0x0000,
269 -1, 0x000A, 0x0000,
270 -1, 0x000C, 0x0000,
271 -1, 0x000D, 0x0000,
272 -1, 0x000F, 0x0000,
273 -1, 0x0010, 0x0000,
274 -1, 0x0011, 0x0007,
275 -1, 0x0012, 0x0000,
276 -1, 0x0013, 0x0000,
277 -2, 200,
278 -1, 0x0010, 0x1690,
279 -1, 0x0011, 0x0223,
280 -2, 50,
281 -1, 0x0012, 0x000D,
282 -2, 50,
283 -1, 0x0013, 0x1200,
284 -1, 0x0029, 0x000A,
285 -1, 0x002B, 0x000C,
286 -2, 50,
287 -1, 0x0020, 0x0000,
288 -1, 0x0021, 0x0000,
289 -1, 0x0030, 0x0000,
290 -1, 0x0031, 0x0506,
291 -1, 0x0032, 0x0104,
292 -1, 0x0035, 0x0207,
293 -1, 0x0036, 0x000F,
294 -1, 0x0037, 0x0306,
295 -1, 0x0038, 0x0102,
296 -1, 0x0039, 0x0707,
297 -1, 0x003C, 0x0702,
298 -1, 0x003D, 0x1604,
299 -1, 0x0050, 0x0000,
300 -1, 0x0051, 0x00EF,
301 -1, 0x0052, 0x0000,
302 -1, 0x0053, 0x013F,
303 -1, 0x0060, 0xA700,
304 -1, 0x0061, 0x0001,
305 -1, 0x006A, 0x0000,
306 -1, 0x0080, 0x0000,
307 -1, 0x0081, 0x0000,
308 -1, 0x0082, 0x0000,
309 -1, 0x0083, 0x0000,
310 -1, 0x0084, 0x0000,
311 -1, 0x0085, 0x0000,
312 -1, 0x0090, 0x0010,
313 -1, 0x0092, 0x0600,
314 -1, 0x0007, 0x0133,
315 -3
316};
317
318static const s16 ili9341_init[] = {
319 -1, 0x28,
320 -2, 20,
321 -1, 0xCF, 0x00, 0x83, 0x30,
322 -1, 0xED, 0x64, 0x03, 0x12, 0x81,
323 -1, 0xE8, 0x85, 0x01, 0x79,
324 -1, 0xCB, 0x39, 0x2c, 0x00, 0x34, 0x02,
325 -1, 0xF7, 0x20,
326 -1, 0xEA, 0x00, 0x00,
327 -1, 0xC0, 0x26,
328 -1, 0xC1, 0x11,
329 -1, 0xC5, 0x35, 0x3E,
330 -1, 0xC7, 0xBE,
331 -1, 0xB1, 0x00, 0x1B,
332 -1, 0xB6, 0x0a, 0x82, 0x27, 0x00,
333 -1, 0xB7, 0x07,
334 -1, 0x3A, 0x55,
335 -1, 0x36, 0x48,
336 -1, 0x11,
337 -2, 120,
338 -1, 0x29,
339 -2, 20,
340 -3
341};
342
343static const s16 ssd1351_init[] = {
344 -1, 0xfd, 0x12,
345 -1, 0xfd, 0xb1,
346 -1, 0xae,
347 -1, 0xb3, 0xf1,
348 -1, 0xca, 0x7f,
349 -1, 0xa0, 0x74,
350 -1, 0x15, 0x00, 0x7f,
351 -1, 0x75, 0x00, 0x7f,
352 -1, 0xa1, 0x00,
353 -1, 0xa2, 0x00,
354 -1, 0xb5, 0x00,
355 -1, 0xab, 0x01,
356 -1, 0xb1, 0x32,
357 -1, 0xb4, 0xa0, 0xb5, 0x55,
358 -1, 0xbb, 0x17,
359 -1, 0xbe, 0x05,
360 -1, 0xc1, 0xc8, 0x80, 0xc8,
361 -1, 0xc7, 0x0f,
362 -1, 0xb6, 0x01,
363 -1, 0xa6,
364 -1, 0xaf,
365 -3
366};
367
368/**
369 * struct flexfb_lcd_controller - Describes the LCD controller properties
370 * @name: Model name of the chip
371 * @width: Width of display in pixels
372 * @height: Height of display in pixels
373 * @setaddrwin: Which set_addr_win() implementation to use
374 * @regwidth: LCD Controller Register width in bits
375 * @init_seq: LCD initialization sequence
376 * @init_seq_sz: Size of LCD initialization sequence
377 */
378struct flexfb_lcd_controller {
379 const char *name;
380 unsigned int width;
381 unsigned int height;
382 unsigned int setaddrwin;
383 unsigned int regwidth;
384 const s16 *init_seq;
385 int init_seq_sz;
386};
387
388static const struct flexfb_lcd_controller flexfb_chip_table[] = {
389 {
390 .name = "st7735r",
391 .width = 120,
392 .height = 160,
393 .init_seq = st7735r_init,
394 .init_seq_sz = ARRAY_SIZE(st7735r_init),
395 },
396 {
397 .name = "hx8340bn",
398 .width = 176,
399 .height = 220,
400 .init_seq = hx8340bn_init,
401 .init_seq_sz = ARRAY_SIZE(hx8340bn_init),
402 },
403 {
404 .name = "ili9225",
405 .width = 176,
406 .height = 220,
407 .regwidth = 16,
408 .init_seq = ili9225_init,
409 .init_seq_sz = ARRAY_SIZE(ili9225_init),
410 },
411 {
412 .name = "ili9320",
413 .width = 240,
414 .height = 320,
415 .setaddrwin = 1,
416 .regwidth = 16,
417 .init_seq = ili9320_init,
418 .init_seq_sz = ARRAY_SIZE(ili9320_init),
419 },
420 {
421 .name = "ili9325",
422 .width = 240,
423 .height = 320,
424 .setaddrwin = 1,
425 .regwidth = 16,
426 .init_seq = ili9325_init,
427 .init_seq_sz = ARRAY_SIZE(ili9325_init),
428 },
429 {
430 .name = "ili9341",
431 .width = 240,
432 .height = 320,
433 .init_seq = ili9341_init,
434 .init_seq_sz = ARRAY_SIZE(ili9341_init),
435 },
436 {
437 .name = "ssd1289",
438 .width = 240,
439 .height = 320,
440 .setaddrwin = 2,
441 .regwidth = 16,
442 .init_seq = ssd1289_init,
443 .init_seq_sz = ARRAY_SIZE(ssd1289_init),
444 },
445 {
446 .name = "ssd1351",
447 .width = 128,
448 .height = 128,
449 .setaddrwin = 3,
450 .init_seq = ssd1351_init,
451 .init_seq_sz = ARRAY_SIZE(ssd1351_init),
452 },
453};
454
455/* ili9320, ili9325 */
456static void flexfb_set_addr_win_1(struct fbtft_par *par,
457 int xs, int ys, int xe, int ye)
458{
459 switch (par->info->var.rotate) {
460 /* R20h = Horizontal GRAM Start Address */
461 /* R21h = Vertical GRAM Start Address */
462 case 0:
463 write_reg(par, 0x0020, xs);
464 write_reg(par, 0x0021, ys);
465 break;
466 case 180:
467 write_reg(par, 0x0020, width - 1 - xs);
468 write_reg(par, 0x0021, height - 1 - ys);
469 break;
470 case 270:
471 write_reg(par, 0x0020, width - 1 - ys);
472 write_reg(par, 0x0021, xs);
473 break;
474 case 90:
475 write_reg(par, 0x0020, ys);
476 write_reg(par, 0x0021, height - 1 - xs);
477 break;
478 }
479 write_reg(par, 0x0022); /* Write Data to GRAM */
480}
481
482/* ssd1289 */
483static void flexfb_set_addr_win_2(struct fbtft_par *par,
484 int xs, int ys, int xe, int ye)
485{
486 switch (par->info->var.rotate) {
487 /* R4Eh - Set GDDRAM X address counter */
488 /* R4Fh - Set GDDRAM Y address counter */
489 case 0:
490 write_reg(par, 0x4e, xs);
491 write_reg(par, 0x4f, ys);
492 break;
493 case 180:
494 write_reg(par, 0x4e, par->info->var.xres - 1 - xs);
495 write_reg(par, 0x4f, par->info->var.yres - 1 - ys);
496 break;
497 case 270:
498 write_reg(par, 0x4e, par->info->var.yres - 1 - ys);
499 write_reg(par, 0x4f, xs);
500 break;
501 case 90:
502 write_reg(par, 0x4e, ys);
503 write_reg(par, 0x4f, par->info->var.xres - 1 - xs);
504 break;
505 }
506
507 /* R22h - RAM data write */
508 write_reg(par, 0x22, 0);
509}
510
511/* ssd1351 */
512static void set_addr_win_3(struct fbtft_par *par,
513 int xs, int ys, int xe, int ye)
514{
515 write_reg(par, 0x15, xs, xe);
516 write_reg(par, 0x75, ys, ye);
517 write_reg(par, 0x5C);
518}
519
520static int flexfb_verify_gpios_dc(struct fbtft_par *par)
521{
522 fbtft_par_dbg(DEBUG_VERIFY_GPIOS, par, "%s()\n", __func__);
523
524 if (!par->gpio.dc) {
525 dev_err(par->info->device,
526 "Missing info about 'dc' gpio. Aborting.\n");
527 return -EINVAL;
528 }
529
530 return 0;
531}
532
533static int flexfb_verify_gpios_db(struct fbtft_par *par)
534{
535 int i;
536 int num_db = buswidth;
537
538 fbtft_par_dbg(DEBUG_VERIFY_GPIOS, par, "%s()\n", __func__);
539
540 if (!par->gpio.dc) {
541 dev_err(par->info->device, "Missing info about 'dc' gpio. Aborting.\n");
542 return -EINVAL;
543 }
544 if (!par->gpio.wr) {
545 dev_err(par->info->device, "Missing info about 'wr' gpio. Aborting.\n");
546 return -EINVAL;
547 }
548 if (latched && !par->gpio.latch) {
549 dev_err(par->info->device, "Missing info about 'latch' gpio. Aborting.\n");
550 return -EINVAL;
551 }
552 if (latched)
553 num_db = buswidth / 2;
554 for (i = 0; i < num_db; i++) {
555 if (!par->gpio.db[i]) {
556 dev_err(par->info->device,
557 "Missing info about 'db%02d' gpio. Aborting.\n",
558 i);
559 return -EINVAL;
560 }
561 }
562
563 return 0;
564}
565
566static void flexfb_chip_load_param(const struct flexfb_lcd_controller *chip)
567{
568 if (!width)
569 width = chip->width;
570 if (!height)
571 height = chip->height;
572 setaddrwin = chip->setaddrwin;
573 if (chip->regwidth)
574 regwidth = chip->regwidth;
575 if (!init_num) {
576 initp = chip->init_seq;
577 initp_num = chip->init_seq_sz;
578 }
579}
580
581static struct fbtft_display flex_display = { };
582
583static int flexfb_chip_init(const struct device *dev)
584{
585 int i;
586
587 for (i = 0; i < ARRAY_SIZE(flexfb_chip_table); i++)
588 if (!strcmp(chip, flexfb_chip_table[i].name)) {
589 flexfb_chip_load_param(&flexfb_chip_table[i]);
590 return 0;
591 }
592
593 dev_err(dev, "chip=%s is not supported\n", chip);
594
595 return -EINVAL;
596}
597
598static int flexfb_probe_common(struct spi_device *sdev,
599 struct platform_device *pdev)
600{
601 struct device *dev;
602 struct fb_info *info;
603 struct fbtft_par *par;
604 int ret;
605
606 initp = init;
607 initp_num = init_num;
608
609 if (sdev)
610 dev = &sdev->dev;
611 else
612 dev = &pdev->dev;
613
614 fbtft_init_dbg(dev, "%s(%s)\n", __func__,
615 sdev ? "'SPI device'" : "'Platform device'");
616
617 if (chip) {
618 ret = flexfb_chip_init(dev);
619 if (ret)
620 return ret;
621 }
622
623 if (width == 0 || height == 0) {
624 dev_err(dev, "argument(s) missing: width and height has to be set.\n");
625 return -EINVAL;
626 }
627 flex_display.width = width;
628 flex_display.height = height;
629 fbtft_init_dbg(dev, "Display resolution: %dx%d\n", width, height);
630 fbtft_init_dbg(dev, "chip = %s\n", chip ? chip : "not set");
631 fbtft_init_dbg(dev, "setaddrwin = %d\n", setaddrwin);
632 fbtft_init_dbg(dev, "regwidth = %d\n", regwidth);
633 fbtft_init_dbg(dev, "buswidth = %d\n", buswidth);
634
635 info = fbtft_framebuffer_alloc(&flex_display, dev, dev->platform_data);
636 if (!info)
637 return -ENOMEM;
638
639 par = info->par;
640 if (sdev)
641 par->spi = sdev;
642 else
643 par->pdev = pdev;
644 if (!par->init_sequence)
645 par->init_sequence = initp;
646 par->fbtftops.init_display = fbtft_init_display;
647
648 /* registerwrite functions */
649 switch (regwidth) {
650 case 8:
651 par->fbtftops.write_register = fbtft_write_reg8_bus8;
652 break;
653 case 16:
654 par->fbtftops.write_register = fbtft_write_reg16_bus8;
655 break;
656 default:
657 dev_err(dev,
658 "argument 'regwidth': %d is not supported.\n",
659 regwidth);
660 return -EINVAL;
661 }
662
663 /* bus functions */
664 if (sdev) {
665 par->fbtftops.write = fbtft_write_spi;
666 switch (buswidth) {
667 case 8:
668 par->fbtftops.write_vmem = fbtft_write_vmem16_bus8;
669 if (!par->startbyte)
670 par->fbtftops.verify_gpios = flexfb_verify_gpios_dc;
671 break;
672 case 9:
673 if (regwidth == 16) {
674 dev_err(dev, "argument 'regwidth': %d is not supported with buswidth=%d and SPI.\n",
675 regwidth, buswidth);
676 return -EINVAL;
677 }
678 par->fbtftops.write_register = fbtft_write_reg8_bus9;
679 par->fbtftops.write_vmem = fbtft_write_vmem16_bus9;
680 if (par->spi->master->bits_per_word_mask
681 & SPI_BPW_MASK(9)) {
682 par->spi->bits_per_word = 9;
683 break;
684 }
685
686 dev_warn(dev,
687 "9-bit SPI not available, emulating using 8-bit.\n");
688 /* allocate buffer with room for dc bits */
689 par->extra = devm_kzalloc(par->info->device,
690 par->txbuf.len
691 + (par->txbuf.len / 8) + 8,
692 GFP_KERNEL);
693 if (!par->extra) {
694 ret = -ENOMEM;
695 goto out_release;
696 }
697 par->fbtftops.write = fbtft_write_spi_emulate_9;
698
699 break;
700 default:
701 dev_err(dev,
702 "argument 'buswidth': %d is not supported with SPI.\n",
703 buswidth);
704 return -EINVAL;
705 }
706 } else {
707 par->fbtftops.verify_gpios = flexfb_verify_gpios_db;
708 switch (buswidth) {
709 case 8:
710 par->fbtftops.write = fbtft_write_gpio8_wr;
711 par->fbtftops.write_vmem = fbtft_write_vmem16_bus8;
712 break;
713 case 16:
714 par->fbtftops.write_register = fbtft_write_reg16_bus16;
715 if (latched)
716 par->fbtftops.write = fbtft_write_gpio16_wr_latched;
717 else
718 par->fbtftops.write = fbtft_write_gpio16_wr;
719 par->fbtftops.write_vmem = fbtft_write_vmem16_bus16;
720 break;
721 default:
722 dev_err(dev,
723 "argument 'buswidth': %d is not supported with parallel.\n",
724 buswidth);
725 return -EINVAL;
726 }
727 }
728
729 /* set_addr_win function */
730 switch (setaddrwin) {
731 case 0:
732 /* use default */
733 break;
734 case 1:
735 par->fbtftops.set_addr_win = flexfb_set_addr_win_1;
736 break;
737 case 2:
738 par->fbtftops.set_addr_win = flexfb_set_addr_win_2;
739 break;
740 case 3:
741 par->fbtftops.set_addr_win = set_addr_win_3;
742 break;
743 default:
744 dev_err(dev, "argument 'setaddrwin': unknown value %d.\n",
745 setaddrwin);
746 return -EINVAL;
747 }
748
749 if (!nobacklight)
750 par->fbtftops.register_backlight = fbtft_register_backlight;
751
752 ret = fbtft_register_framebuffer(info);
753 if (ret < 0)
754 goto out_release;
755
756 return 0;
757
758out_release:
759 fbtft_framebuffer_release(info);
760
761 return ret;
762}
763
764static int flexfb_remove_common(struct device *dev, struct fb_info *info)
765{
766 struct fbtft_par *par;
767
768 if (!info)
769 return -EINVAL;
770 par = info->par;
771 if (par)
772 fbtft_par_dbg(DEBUG_DRIVER_INIT_FUNCTIONS, par, "%s()\n",
773 __func__);
774 fbtft_unregister_framebuffer(info);
775 fbtft_framebuffer_release(info);
776
777 return 0;
778}
779
780static int flexfb_probe_spi(struct spi_device *spi)
781{
782 return flexfb_probe_common(spi, NULL);
783}
784
785static int flexfb_remove_spi(struct spi_device *spi)
786{
787 struct fb_info *info = spi_get_drvdata(spi);
788
789 return flexfb_remove_common(&spi->dev, info);
790}
791
792static int flexfb_probe_pdev(struct platform_device *pdev)
793{
794 return flexfb_probe_common(NULL, pdev);
795}
796
797static int flexfb_remove_pdev(struct platform_device *pdev)
798{
799 struct fb_info *info = platform_get_drvdata(pdev);
800
801 return flexfb_remove_common(&pdev->dev, info);
802}
803
804static struct spi_driver flexfb_spi_driver = {
805 .driver = {
806 .name = DRVNAME,
807 },
808 .probe = flexfb_probe_spi,
809 .remove = flexfb_remove_spi,
810};
811
812static const struct platform_device_id flexfb_platform_ids[] = {
813 { "flexpfb", 0 },
814 { },
815};
816MODULE_DEVICE_TABLE(platform, flexfb_platform_ids);
817
818static struct platform_driver flexfb_platform_driver = {
819 .driver = {
820 .name = DRVNAME,
821 },
822 .id_table = flexfb_platform_ids,
823 .probe = flexfb_probe_pdev,
824 .remove = flexfb_remove_pdev,
825};
826
827static int __init flexfb_init(void)
828{
829 int ret, ret2;
830
831 ret = spi_register_driver(&flexfb_spi_driver);
832 ret2 = platform_driver_register(&flexfb_platform_driver);
833 if (ret < 0)
834 return ret;
835 return ret2;
836}
837
838static void __exit flexfb_exit(void)
839{
840 spi_unregister_driver(&flexfb_spi_driver);
841 platform_driver_unregister(&flexfb_platform_driver);
842}
843
844/* ------------------------------------------------------------------------- */
845
846module_init(flexfb_init);
847module_exit(flexfb_exit);
848
849MODULE_DESCRIPTION("Generic FB driver for TFT LCD displays");
850MODULE_AUTHOR("Noralf Tronnes");
851MODULE_LICENSE("GPL");
diff --git a/drivers/staging/octeon/ethernet-tx.c b/drivers/staging/octeon/ethernet-tx.c
index c64728fc21f2..83469061a542 100644
--- a/drivers/staging/octeon/ethernet-tx.c
+++ b/drivers/staging/octeon/ethernet-tx.c
@@ -261,11 +261,11 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
261 /* Build the PKO buffer pointer */ 261 /* Build the PKO buffer pointer */
262 hw_buffer.u64 = 0; 262 hw_buffer.u64 = 0;
263 if (skb_shinfo(skb)->nr_frags == 0) { 263 if (skb_shinfo(skb)->nr_frags == 0) {
264 hw_buffer.s.addr = XKPHYS_TO_PHYS((u64)skb->data); 264 hw_buffer.s.addr = XKPHYS_TO_PHYS((uintptr_t)skb->data);
265 hw_buffer.s.pool = 0; 265 hw_buffer.s.pool = 0;
266 hw_buffer.s.size = skb->len; 266 hw_buffer.s.size = skb->len;
267 } else { 267 } else {
268 hw_buffer.s.addr = XKPHYS_TO_PHYS((u64)skb->data); 268 hw_buffer.s.addr = XKPHYS_TO_PHYS((uintptr_t)skb->data);
269 hw_buffer.s.pool = 0; 269 hw_buffer.s.pool = 0;
270 hw_buffer.s.size = skb_headlen(skb); 270 hw_buffer.s.size = skb_headlen(skb);
271 CVM_OCT_SKB_CB(skb)[0] = hw_buffer.u64; 271 CVM_OCT_SKB_CB(skb)[0] = hw_buffer.u64;
@@ -273,11 +273,12 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
273 skb_frag_t *fs = skb_shinfo(skb)->frags + i; 273 skb_frag_t *fs = skb_shinfo(skb)->frags + i;
274 274
275 hw_buffer.s.addr = 275 hw_buffer.s.addr =
276 XKPHYS_TO_PHYS((u64)skb_frag_address(fs)); 276 XKPHYS_TO_PHYS((uintptr_t)skb_frag_address(fs));
277 hw_buffer.s.size = skb_frag_size(fs); 277 hw_buffer.s.size = skb_frag_size(fs);
278 CVM_OCT_SKB_CB(skb)[i + 1] = hw_buffer.u64; 278 CVM_OCT_SKB_CB(skb)[i + 1] = hw_buffer.u64;
279 } 279 }
280 hw_buffer.s.addr = XKPHYS_TO_PHYS((u64)CVM_OCT_SKB_CB(skb)); 280 hw_buffer.s.addr =
281 XKPHYS_TO_PHYS((uintptr_t)CVM_OCT_SKB_CB(skb));
281 hw_buffer.s.size = skb_shinfo(skb)->nr_frags + 1; 282 hw_buffer.s.size = skb_shinfo(skb)->nr_frags + 1;
282 pko_command.s.segs = skb_shinfo(skb)->nr_frags + 1; 283 pko_command.s.segs = skb_shinfo(skb)->nr_frags + 1;
283 pko_command.s.gather = 1; 284 pko_command.s.gather = 1;
@@ -349,10 +350,8 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
349 */ 350 */
350 dst_release(skb_dst(skb)); 351 dst_release(skb_dst(skb));
351 skb_dst_set(skb, NULL); 352 skb_dst_set(skb, NULL);
352#ifdef CONFIG_XFRM 353 skb_ext_reset(skb);
353 secpath_reset(skb); 354 nf_reset_ct(skb);
354#endif
355 nf_reset(skb);
356 355
357#ifdef CONFIG_NET_SCHED 356#ifdef CONFIG_NET_SCHED
358 skb->tc_index = 0; 357 skb->tc_index = 0;
diff --git a/drivers/staging/octeon/octeon-stubs.h b/drivers/staging/octeon/octeon-stubs.h
index a4ac3bfb62a8..b78ce9eaab85 100644
--- a/drivers/staging/octeon/octeon-stubs.h
+++ b/drivers/staging/octeon/octeon-stubs.h
@@ -1202,7 +1202,7 @@ static inline int cvmx_wqe_get_grp(cvmx_wqe_t *work)
1202 1202
1203static inline void *cvmx_phys_to_ptr(uint64_t physical_address) 1203static inline void *cvmx_phys_to_ptr(uint64_t physical_address)
1204{ 1204{
1205 return (void *)(physical_address); 1205 return (void *)(uintptr_t)(physical_address);
1206} 1206}
1207 1207
1208static inline uint64_t cvmx_ptr_to_phys(void *ptr) 1208static inline uint64_t cvmx_ptr_to_phys(void *ptr)
diff --git a/drivers/staging/rtl8188eu/hal/hal8188e_rate_adaptive.c b/drivers/staging/rtl8188eu/hal/hal8188e_rate_adaptive.c
index 9ddd51685063..5792f491b59a 100644
--- a/drivers/staging/rtl8188eu/hal/hal8188e_rate_adaptive.c
+++ b/drivers/staging/rtl8188eu/hal/hal8188e_rate_adaptive.c
@@ -409,7 +409,7 @@ static int odm_ARFBRefresh_8188E(struct odm_dm_struct *dm_odm, struct odm_ra_inf
409 pRaInfo->PTModeSS = 3; 409 pRaInfo->PTModeSS = 3;
410 else if (pRaInfo->HighestRate > 0x0b) 410 else if (pRaInfo->HighestRate > 0x0b)
411 pRaInfo->PTModeSS = 2; 411 pRaInfo->PTModeSS = 2;
412 else if (pRaInfo->HighestRate > 0x0b) 412 else if (pRaInfo->HighestRate > 0x03)
413 pRaInfo->PTModeSS = 1; 413 pRaInfo->PTModeSS = 1;
414 else 414 else
415 pRaInfo->PTModeSS = 0; 415 pRaInfo->PTModeSS = 0;
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 664d93a7f90d..4fac9dca798e 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -348,8 +348,10 @@ static struct adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
348 } 348 }
349 349
350 padapter->HalData = kzalloc(sizeof(struct hal_data_8188e), GFP_KERNEL); 350 padapter->HalData = kzalloc(sizeof(struct hal_data_8188e), GFP_KERNEL);
351 if (!padapter->HalData) 351 if (!padapter->HalData) {
352 DBG_88E("cant not alloc memory for HAL DATA\n"); 352 DBG_88E("Failed to allocate memory for HAL data\n");
353 goto free_adapter;
354 }
353 355
354 /* step read_chip_version */ 356 /* step read_chip_version */
355 rtw_hal_read_chip_version(padapter); 357 rtw_hal_read_chip_version(padapter);
diff --git a/drivers/staging/speakup/sysfs-driver-speakup b/drivers/staging/speakup/sysfs-driver-speakup
new file mode 100644
index 000000000000..be3f5d6962e9
--- /dev/null
+++ b/drivers/staging/speakup/sysfs-driver-speakup
@@ -0,0 +1,369 @@
1What: /sys/accessibility/speakup/attrib_bleep
2KernelVersion: 2.6
3Contact: speakup@linux-speakup.org
4Description: Beeps the PC speaker when there is an attribute change such as
5 foreground or background color when using speakup review
6 commands. One = on, zero = off.
7
8What: /sys/accessibility/speakup/bell_pos
9KernelVersion: 2.6
10Contact: speakup@linux-speakup.org
11Description: This works much like a typewriter bell. If for example 72 is
12 echoed to bell_pos, it will beep the PC speaker when typing on
13 a line past character 72.
14
15What: /sys/accessibility/speakup/bleeps
16KernelVersion: 2.6
17Contact: speakup@linux-speakup.org
18Description: This controls whether one hears beeps through the PC speaker
19 when using speakup's review commands.
20 TODO: what values does it accept?
21
22What: /sys/accessibility/speakup/bleep_time
23KernelVersion: 2.6
24Contact: speakup@linux-speakup.org
25Description: This controls the duration of the PC speaker beeps speakup
26 produces.
27 TODO: What are the units? Jiffies?
28
29What: /sys/accessibility/speakup/cursor_time
30KernelVersion: 2.6
31Contact: speakup@linux-speakup.org
32Description: This controls cursor delay when using arrow keys. When a
33 connection is very slow, with the default setting, when moving
34 with the arrows, or backspacing etc. speakup says the incorrect
35 characters. Set this to a higher value to adjust for the delay
36 and better synchronisation between cursor position and speech.
37
38What: /sys/accessibility/speakup/delimiters
39KernelVersion: 2.6
40Contact: speakup@linux-speakup.org
41Description: Delimit a word from speakup.
42 TODO: add more info
43
44What: /sys/accessibility/speakup/ex_num
45KernelVersion: 2.6
46Contact: speakup@linux-speakup.org
47Description: TODO:
48
49What: /sys/accessibility/speakup/key_echo
50KernelVersion: 2.6
51Contact: speakup@linux-speakup.org
52Description: Controls if speakup speaks keys when they are typed. One = on,
53 zero = off or don't echo keys.
54
55What: /sys/accessibility/speakup/keymap
56KernelVersion: 2.6
57Contact: speakup@linux-speakup.org
58Description: Speakup keymap remaps keys to Speakup functions.
59 It uses a binary
60 format. A special program called genmap is needed to compile a
61 textual keymap into the binary format which is then loaded into
62 /sys/accessibility/speakup/keymap.
63
64What: /sys/accessibility/speakup/no_interrupt
65KernelVersion: 2.6
66Contact: speakup@linux-speakup.org
67Description: Controls if typing interrupts output from speakup. With
68 no_interrupt set to zero, typing on the keyboard will interrupt
69 speakup if for example
70 the say screen command is used before the
71 entire screen is read.
72 With no_interrupt set to one, if the say
73 screen command is used, and one then types on the keyboard,
74 speakup will continue to say the whole screen regardless until
75 it finishes.
76
77What: /sys/accessibility/speakup/punc_all
78KernelVersion: 2.6
79Contact: speakup@linux-speakup.org
80Description: This is a list of all the punctuation speakup should speak when
81 punc_level is set to four.
82
83What: /sys/accessibility/speakup/punc_level
84KernelVersion: 2.6
85Contact: speakup@linux-speakup.org
86Description: Controls the level of punctuation spoken as the screen is
87 displayed, not reviewed. Levels range from zero no punctuation,
88 to four, all punctuation. One corresponds to punc_some, two
89 corresponds to punc_most, and three as well as four both
90 correspond to punc_all. Some hardware synthesizers may have
91 different levels each corresponding to three and four for
92 punc_level. Also note that if punc_level is set to zero, and
93 key_echo is set to one, typed punctuation is still spoken as it
94 is typed.
95
96What: /sys/accessibility/speakup/punc_most
97KernelVersion: 2.6
98Contact: speakup@linux-speakup.org
99Description: This is a list of all the punctuation speakup should speak when
100 punc_level is set to two.
101
102What: /sys/accessibility/speakup/punc_some
103KernelVersion: 2.6
104Contact: speakup@linux-speakup.org
105Description: This is a list of all the punctuation speakup should speak when
106 punc_level is set to one.
107
108What: /sys/accessibility/speakup/reading_punc
109KernelVersion: 2.6
110Contact: speakup@linux-speakup.org
111Description: Almost the same as punc_level, the differences being that
112 reading_punc controls the level of punctuation when reviewing
113 the screen with speakup's screen review commands. The other
114 difference is that reading_punc set to three speaks punc_all,
115 and reading_punc set to four speaks all punctuation, including
116 spaces.
117
118What: /sys/accessibility/speakup/repeats
119KernelVersion: 2.6
120Contact: speakup@linux-speakup.org
121Description: A list of characters speakup repeats. Normally, when there are
122 more than three characters in a row, speakup
123 just reads three of
124 those characters. For example, "......" would be read as dot,
125 dot, dot. If a . is added to the list of characters in repeats,
126 "......" would be read as dot, dot, dot, times six.
127
128What: /sys/accessibility/speakup/say_control
129KernelVersion: 2.6
130Contact: speakup@linux-speakup.org
131Description: If set to one, speakup speaks shift, alt and control when those
132 keys are pressed. If say_control is set to zero, shift, ctrl,
133 and alt are not spoken when they are pressed.
134
135What: /sys/accessibility/speakup/say_word_ctl
136KernelVersion: 2.6
137Contact: speakup@linux-speakup.org
138Description: TODO:
139
140What: /sys/accessibility/speakup/silent
141KernelVersion: 2.6
142Contact: speakup@linux-speakup.org
143Description: TODO:
144
145What: /sys/accessibility/speakup/spell_delay
146KernelVersion: 2.6
147Contact: speakup@linux-speakup.org
148Description: This controls how fast a word is spelled
149 when speakup's say word
150 review command is pressed twice quickly to speak the current
151 word being reviewed. Zero just speaks the letters one after
152 another, while values one through four
153 seem to introduce more of
154 a pause between the spelling of each letter by speakup.
155
156What: /sys/accessibility/speakup/synth
157KernelVersion: 2.6
158Contact: speakup@linux-speakup.org
159Description: Gets or sets the synthesizer driver currently in use. Reading
160 synth returns the synthesizer driver currently in use. Writing
161 synth switches to the given synthesizer driver, provided it is
162 either built into the kernel, or already loaded as a module.
163
164What: /sys/accessibility/speakup/synth_direct
165KernelVersion: 2.6
166Contact: speakup@linux-speakup.org
167Description: Sends whatever is written to synth_direct
168 directly to the speech synthesizer in use, bypassing speakup.
169 This could be used to make the synthesizer speak
170 a string, or to
171 send control sequences to the synthesizer to change how the
172 synthesizer behaves.
173
174What: /sys/accessibility/speakup/version
175KernelVersion: 2.6
176Contact: speakup@linux-speakup.org
177Description: Reading version returns the version of speakup, and the version
178 of the synthesizer driver currently in use.
179
180What: /sys/accessibility/speakup/i18n/announcements
181KernelVersion: 2.6
182Contact: speakup@linux-speakup.org
183Description: This file contains various general announcements, most of which
184 cannot be categorized. You will find messages such as "You
185 killed Speakup", "I'm alive", "leaving help", "parked",
186 "unparked", and others. You will also find the names of the
187 screen edges and cursor tracking modes here.
188
189What: /sys/accessibility/speakup/i18n/chartab
190KernelVersion: 2.6
191Contact: speakup@linux-speakup.org
192Description: TODO
193
194What: /sys/accessibility/speakup/i18n/ctl_keys
195KernelVersion: 2.6
196Contact: speakup@linux-speakup.org
197Description: Here, you will find names of control keys. These are used with
198 Speakup's say_control feature.
199
200What: /sys/accessibility/speakup/i18n/function_names
201KernelVersion: 2.6
202Contact: speakup@linux-speakup.org
203Description: Here, you will find a list of names for Speakup functions.
204 These are used by the help system. For example, suppose that
205 you have activated help mode, and you pressed
206 keypad 3. Speakup
207 says: "keypad 3 is character, say next."
208 The message "character, say next" names a Speakup function, and
209 it comes from this function_names file.
210
211What: /sys/accessibility/speakup/i18n/states
212KernelVersion: 2.6
213Contact: speakup@linux-speakup.org
214Description: This file contains names for key states.
215 Again, these are part of the help system. For instance, if you
216 had pressed speakup + keypad 3, you would hear:
217 "speakup keypad 3 is go to bottom edge."
218 The speakup key is depressed, so the name of the key state is
219 speakup.
220 This part of the message comes from the states collection.
221
222What: /sys/accessibility/speakup/i18n/characters
223KernelVersion: 2.6
224Contact: speakup@linux-speakup.org
225Description: Through this sys entry, Speakup gives you the ability to change
226 how Speakup pronounces a given character. You could, for
227 example, change how some punctuation characters are spoken. You
228 can even change how Speakup will pronounce certain letters. For
229 further details see '12. Changing the Pronunciation of
230 Characters' in Speakup User's Guide (file spkguide.txt in
231 source).
232
233What: /sys/accessibility/speakup/i18n/colors
234KernelVersion: 2.6
235Contact: speakup@linux-speakup.org
236Description: When you use the "say attributes" function, Speakup says the
237 name of the foreground and background colors. These names come
238 from the i18n/colors file.
239
240What: /sys/accessibility/speakup/i18n/formatted
241KernelVersion: 2.6
242Contact: speakup@linux-speakup.org
243Description: This group of messages contains embedded formatting codes, to
244 specify the type and width of displayed data. If you change
245 these, you must preserve all of the formatting codes, and they
246 must appear in the order used by the default messages.
247
248What: /sys/accessibility/speakup/i18n/key_names
249KernelVersion: 2.6
250Contact: speakup@linux-speakup.org
251Description: Again, key_names is used by Speakup's help system. In the
252 previous example, Speakup said that you pressed "keypad 3."
253 This name came from the key_names file.
254
255What: /sys/accessibility/speakup/<synth-name>/
256KernelVersion: 2.6
257Contact: speakup@linux-speakup.org
258Description: In `/sys/accessibility/speakup` is a directory corresponding to
259 the synthesizer driver currently in use (E.G) `soft` for the
260 soft driver. This directory contains files which control the
261 speech synthesizer itself,
262 as opposed to controlling the speakup
263 screen reader. The parameters in this directory have the same
264 names and functions across all
265 supported synthesizers. The range
266 of values for freq, pitch, rate, and vol is the same for all
267 supported synthesizers, with the given range being internally
268 mapped by the driver to more or less fit the range of values
269 supported for a given parameter by the individual synthesizer.
270 Below is a description of values and parameters for soft
271 synthesizer, which is currently the most commonly used.
272
273What: /sys/accessibility/speakup/soft/caps_start
274KernelVersion: 2.6
275Contact: speakup@linux-speakup.org
276Description: This is the string that is sent to the synthesizer to cause it
277 to start speaking uppercase letters. For the soft synthesizer
278 and most others, this causes the pitch of the voice to rise
279 above the currently set pitch.
280
281What: /sys/accessibility/speakup/soft/caps_stop
282KernelVersion: 2.6
283Contact: speakup@linux-speakup.org
284Description: This is the string sent to the synthesizer to cause it to stop
285 speaking uppercase letters. In the case of the soft synthesizer
286 and most others, this returns the pitch of the voice
287 down to the
288 currently set pitch.
289
290What: /sys/accessibility/speakup/soft/delay_time
291KernelVersion: 2.6
292Contact: speakup@linux-speakup.org
293Description: TODO:
294
295What: /sys/accessibility/speakup/soft/direct
296KernelVersion: 2.6
297Contact: speakup@linux-speakup.org
298Description: Controls if punctuation is spoken by speakup, or by the
299 synthesizer.
300 For example, speakup speaks ">" as "greater", while
301 the espeak synthesizer used by the soft driver speaks "greater
302 than". Zero lets speakup speak the punctuation. One lets the
303 synthesizer itself speak punctuation.
304
305What: /sys/accessibility/speakup/soft/freq
306KernelVersion: 2.6
307Contact: speakup@linux-speakup.org
308Description: Gets or sets the frequency of the speech synthesizer. Range is
309 0-9.
310
311What: /sys/accessibility/speakup/soft/full_time
312KernelVersion: 2.6
313Contact: speakup@linux-speakup.org
314Description: TODO:
315
316What: /sys/accessibility/speakup/soft/jiffy_delta
317KernelVersion: 2.6
318Contact: speakup@linux-speakup.org
319Description: This controls how many jiffys the kernel gives to the
320 synthesizer. Setting this too high can make a system unstable,
321 or even crash it.
322
323What: /sys/accessibility/speakup/soft/pitch
324KernelVersion: 2.6
325Contact: speakup@linux-speakup.org
326Description: Gets or sets the pitch of the synthesizer. The range is 0-9.
327
328What: /sys/accessibility/speakup/soft/punct
329KernelVersion: 2.6
330Contact: speakup@linux-speakup.org
331Description: Gets or sets the amount of punctuation spoken by the
332 synthesizer. The range for the soft driver seems to be 0-2.
333 TODO: How is this related to speakup's punc_level, or
334 reading_punc.
335
336What: /sys/accessibility/speakup/soft/rate
337KernelVersion: 2.6
338Contact: speakup@linux-speakup.org
339Description: Gets or sets the rate of the synthesizer. Range is from zero
340 slowest, to nine fastest.
341
342What: /sys/accessibility/speakup/soft/tone
343KernelVersion: 2.6
344Contact: speakup@linux-speakup.org
345Description: Gets or sets the tone of the speech synthesizer. The range for
346 the soft driver seems to be 0-2. This seems to make no
347 difference if using espeak and the espeakup connector.
348 TODO: does espeakup support different tonalities?
349
350What: /sys/accessibility/speakup/soft/trigger_time
351KernelVersion: 2.6
352Contact: speakup@linux-speakup.org
353Description: TODO:
354
355What: /sys/accessibility/speakup/soft/voice
356KernelVersion: 2.6
357Contact: speakup@linux-speakup.org
358Description: Gets or sets the voice used by the synthesizer if the
359 synthesizer can speak in more than one voice. The range for the
360 soft driver is 0-7. Note that while espeak supports multiple
361 voices, this parameter will not set the voice when the espeakup
362 connector is used between speakup and espeak.
363
364What: /sys/accessibility/speakup/soft/vol
365KernelVersion: 2.6
366Contact: speakup@linux-speakup.org
367Description: Gets or sets the volume of the speech synthesizer. Range is 0-9,
368 with zero being the softest, and nine being the loudest.
369
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
index bc1eaa3a0773..826016c3431a 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
@@ -12,7 +12,7 @@
12static const struct snd_pcm_hardware snd_bcm2835_playback_hw = { 12static const struct snd_pcm_hardware snd_bcm2835_playback_hw = {
13 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | 13 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
14 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | 14 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
15 SNDRV_PCM_INFO_DRAIN_TRIGGER | SNDRV_PCM_INFO_SYNC_APPLPTR), 15 SNDRV_PCM_INFO_SYNC_APPLPTR),
16 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, 16 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
17 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, 17 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
18 .rate_min = 8000, 18 .rate_min = 8000,
@@ -29,7 +29,7 @@ static const struct snd_pcm_hardware snd_bcm2835_playback_hw = {
29static const struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = { 29static const struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = {
30 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | 30 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
31 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | 31 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
32 SNDRV_PCM_INFO_DRAIN_TRIGGER | SNDRV_PCM_INFO_SYNC_APPLPTR), 32 SNDRV_PCM_INFO_SYNC_APPLPTR),
33 .formats = SNDRV_PCM_FMTBIT_S16_LE, 33 .formats = SNDRV_PCM_FMTBIT_S16_LE,
34 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_44100 | 34 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_44100 |
35 SNDRV_PCM_RATE_48000, 35 SNDRV_PCM_RATE_48000,
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
index 23fba01107b9..c6f9cf1913d2 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
@@ -289,6 +289,7 @@ int bcm2835_audio_stop(struct bcm2835_alsa_stream *alsa_stream)
289 VC_AUDIO_MSG_TYPE_STOP, false); 289 VC_AUDIO_MSG_TYPE_STOP, false);
290} 290}
291 291
292/* FIXME: this doesn't seem working as expected for "draining" */
292int bcm2835_audio_drain(struct bcm2835_alsa_stream *alsa_stream) 293int bcm2835_audio_drain(struct bcm2835_alsa_stream *alsa_stream)
293{ 294{
294 struct vc_audio_msg m = { 295 struct vc_audio_msg m = {
diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c
index c6bb4aaf9bd0..082302944c37 100644
--- a/drivers/staging/vt6655/device_main.c
+++ b/drivers/staging/vt6655/device_main.c
@@ -1748,8 +1748,10 @@ vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
1748 1748
1749 priv->hw->max_signal = 100; 1749 priv->hw->max_signal = 100;
1750 1750
1751 if (vnt_init(priv)) 1751 if (vnt_init(priv)) {
1752 device_free_info(priv);
1752 return -ENODEV; 1753 return -ENODEV;
1754 }
1753 1755
1754 device_print_info(priv); 1756 device_print_info(priv);
1755 pci_set_drvdata(pcid, priv); 1757 pci_set_drvdata(pcid, priv);
diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index e55c79eb6430..98361acd3053 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -968,6 +968,11 @@ static int __init n_hdlc_init(void)
968 968
969} /* end of init_module() */ 969} /* end of init_module() */
970 970
971#ifdef CONFIG_SPARC
972#undef __exitdata
973#define __exitdata
974#endif
975
971static const char hdlc_unregister_ok[] __exitdata = 976static const char hdlc_unregister_ok[] __exitdata =
972 KERN_INFO "N_HDLC: line discipline unregistered\n"; 977 KERN_INFO "N_HDLC: line discipline unregistered\n";
973static const char hdlc_unregister_fail[] __exitdata = 978static const char hdlc_unregister_fail[] __exitdata =
diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
index c68e2b3a1634..836e736ae188 100644
--- a/drivers/tty/serial/8250/8250_omap.c
+++ b/drivers/tty/serial/8250/8250_omap.c
@@ -141,7 +141,7 @@ static void omap8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
141 141
142 serial8250_do_set_mctrl(port, mctrl); 142 serial8250_do_set_mctrl(port, mctrl);
143 143
144 if (!up->gpios) { 144 if (!mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_RTS)) {
145 /* 145 /*
146 * Turn off autoRTS if RTS is lowered and restore autoRTS 146 * Turn off autoRTS if RTS is lowered and restore autoRTS
147 * setting if RTS is raised 147 * setting if RTS is raised
@@ -456,7 +456,8 @@ static void omap_8250_set_termios(struct uart_port *port,
456 up->port.status &= ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS | UPSTAT_AUTOXOFF); 456 up->port.status &= ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS | UPSTAT_AUTOXOFF);
457 457
458 if (termios->c_cflag & CRTSCTS && up->port.flags & UPF_HARD_FLOW && 458 if (termios->c_cflag & CRTSCTS && up->port.flags & UPF_HARD_FLOW &&
459 !up->gpios) { 459 !mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_RTS) &&
460 !mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_CTS)) {
460 /* Enable AUTOCTS (autoRTS is enabled when RTS is raised) */ 461 /* Enable AUTOCTS (autoRTS is enabled when RTS is raised) */
461 up->port.status |= UPSTAT_AUTOCTS | UPSTAT_AUTORTS; 462 up->port.status |= UPSTAT_AUTOCTS | UPSTAT_AUTORTS;
462 priv->efr |= UART_EFR_CTS; 463 priv->efr |= UART_EFR_CTS;
diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index 4789b5d62f63..67a9eb3f94ce 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -1032,6 +1032,7 @@ config SERIAL_SIFIVE_CONSOLE
1032 bool "Console on SiFive UART" 1032 bool "Console on SiFive UART"
1033 depends on SERIAL_SIFIVE=y 1033 depends on SERIAL_SIFIVE=y
1034 select SERIAL_CORE_CONSOLE 1034 select SERIAL_CORE_CONSOLE
1035 select SERIAL_EARLYCON
1035 help 1036 help
1036 Select this option if you would like to use a SiFive UART as the 1037 Select this option if you would like to use a SiFive UART as the
1037 system console. 1038 system console.
diff --git a/drivers/tty/serial/fsl_linflexuart.c b/drivers/tty/serial/fsl_linflexuart.c
index 68d74f2b5106..a32f0d2afd59 100644
--- a/drivers/tty/serial/fsl_linflexuart.c
+++ b/drivers/tty/serial/fsl_linflexuart.c
@@ -3,7 +3,7 @@
3 * Freescale linflexuart serial port driver 3 * Freescale linflexuart serial port driver
4 * 4 *
5 * Copyright 2012-2016 Freescale Semiconductor, Inc. 5 * Copyright 2012-2016 Freescale Semiconductor, Inc.
6 * Copyright 2017-2018 NXP 6 * Copyright 2017-2019 NXP
7 */ 7 */
8 8
9#if defined(CONFIG_SERIAL_FSL_LINFLEXUART_CONSOLE) && \ 9#if defined(CONFIG_SERIAL_FSL_LINFLEXUART_CONSOLE) && \
@@ -246,12 +246,14 @@ static irqreturn_t linflex_rxint(int irq, void *dev_id)
246 struct tty_port *port = &sport->state->port; 246 struct tty_port *port = &sport->state->port;
247 unsigned long flags, status; 247 unsigned long flags, status;
248 unsigned char rx; 248 unsigned char rx;
249 bool brk;
249 250
250 spin_lock_irqsave(&sport->lock, flags); 251 spin_lock_irqsave(&sport->lock, flags);
251 252
252 status = readl(sport->membase + UARTSR); 253 status = readl(sport->membase + UARTSR);
253 while (status & LINFLEXD_UARTSR_RMB) { 254 while (status & LINFLEXD_UARTSR_RMB) {
254 rx = readb(sport->membase + BDRM); 255 rx = readb(sport->membase + BDRM);
256 brk = false;
255 flg = TTY_NORMAL; 257 flg = TTY_NORMAL;
256 sport->icount.rx++; 258 sport->icount.rx++;
257 259
@@ -261,8 +263,11 @@ static irqreturn_t linflex_rxint(int irq, void *dev_id)
261 status |= LINFLEXD_UARTSR_SZF; 263 status |= LINFLEXD_UARTSR_SZF;
262 if (status & LINFLEXD_UARTSR_BOF) 264 if (status & LINFLEXD_UARTSR_BOF)
263 status |= LINFLEXD_UARTSR_BOF; 265 status |= LINFLEXD_UARTSR_BOF;
264 if (status & LINFLEXD_UARTSR_FEF) 266 if (status & LINFLEXD_UARTSR_FEF) {
267 if (!rx)
268 brk = true;
265 status |= LINFLEXD_UARTSR_FEF; 269 status |= LINFLEXD_UARTSR_FEF;
270 }
266 if (status & LINFLEXD_UARTSR_PE) 271 if (status & LINFLEXD_UARTSR_PE)
267 status |= LINFLEXD_UARTSR_PE; 272 status |= LINFLEXD_UARTSR_PE;
268 } 273 }
@@ -271,13 +276,15 @@ static irqreturn_t linflex_rxint(int irq, void *dev_id)
271 sport->membase + UARTSR); 276 sport->membase + UARTSR);
272 status = readl(sport->membase + UARTSR); 277 status = readl(sport->membase + UARTSR);
273 278
274 if (uart_handle_sysrq_char(sport, (unsigned char)rx)) 279 if (brk) {
275 continue; 280 uart_handle_break(sport);
276 281 } else {
277#ifdef SUPPORT_SYSRQ 282#ifdef SUPPORT_SYSRQ
278 sport->sysrq = 0; 283 if (uart_handle_sysrq_char(sport, (unsigned char)rx))
284 continue;
279#endif 285#endif
280 tty_insert_flip_char(port, rx, flg); 286 tty_insert_flip_char(port, rx, flg);
287 }
281 } 288 }
282 289
283 spin_unlock_irqrestore(&sport->lock, flags); 290 spin_unlock_irqrestore(&sport->lock, flags);
diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 3e17bb8a0b16..537896c4d887 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -548,7 +548,7 @@ static void lpuart_flush_buffer(struct uart_port *port)
548 val |= UARTFIFO_TXFLUSH | UARTFIFO_RXFLUSH; 548 val |= UARTFIFO_TXFLUSH | UARTFIFO_RXFLUSH;
549 lpuart32_write(&sport->port, val, UARTFIFO); 549 lpuart32_write(&sport->port, val, UARTFIFO);
550 } else { 550 } else {
551 val = readb(sport->port.membase + UARTPFIFO); 551 val = readb(sport->port.membase + UARTCFIFO);
552 val |= UARTCFIFO_TXFLUSH | UARTCFIFO_RXFLUSH; 552 val |= UARTCFIFO_TXFLUSH | UARTCFIFO_RXFLUSH;
553 writeb(val, sport->port.membase + UARTCFIFO); 553 writeb(val, sport->port.membase + UARTCFIFO);
554 } 554 }
diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 87c58f9f6390..5e08f2657b90 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -2222,8 +2222,8 @@ static int imx_uart_probe(struct platform_device *pdev)
2222 return PTR_ERR(base); 2222 return PTR_ERR(base);
2223 2223
2224 rxirq = platform_get_irq(pdev, 0); 2224 rxirq = platform_get_irq(pdev, 0);
2225 txirq = platform_get_irq(pdev, 1); 2225 txirq = platform_get_irq_optional(pdev, 1);
2226 rtsirq = platform_get_irq(pdev, 2); 2226 rtsirq = platform_get_irq_optional(pdev, 2);
2227 2227
2228 sport->port.dev = &pdev->dev; 2228 sport->port.dev = &pdev->dev;
2229 sport->port.mapbase = res->start; 2229 sport->port.mapbase = res->start;
diff --git a/drivers/tty/serial/owl-uart.c b/drivers/tty/serial/owl-uart.c
index 03963af77b15..d2d8b3494685 100644
--- a/drivers/tty/serial/owl-uart.c
+++ b/drivers/tty/serial/owl-uart.c
@@ -740,7 +740,7 @@ static int __init owl_uart_init(void)
740 return ret; 740 return ret;
741} 741}
742 742
743static void __init owl_uart_exit(void) 743static void __exit owl_uart_exit(void)
744{ 744{
745 platform_driver_unregister(&owl_uart_platform_driver); 745 platform_driver_unregister(&owl_uart_platform_driver);
746 uart_unregister_driver(&owl_uart_driver); 746 uart_unregister_driver(&owl_uart_driver);
diff --git a/drivers/tty/serial/rda-uart.c b/drivers/tty/serial/rda-uart.c
index c1b0d7662ef9..ff9a27d48bca 100644
--- a/drivers/tty/serial/rda-uart.c
+++ b/drivers/tty/serial/rda-uart.c
@@ -815,7 +815,7 @@ static int __init rda_uart_init(void)
815 return ret; 815 return ret;
816} 816}
817 817
818static void __init rda_uart_exit(void) 818static void __exit rda_uart_exit(void)
819{ 819{
820 platform_driver_unregister(&rda_uart_platform_driver); 820 platform_driver_unregister(&rda_uart_platform_driver);
821 uart_unregister_driver(&rda_uart_driver); 821 uart_unregister_driver(&rda_uart_driver);
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 6e713be1d4e9..c4a414a46c7f 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -1964,8 +1964,10 @@ uart_get_console(struct uart_port *ports, int nr, struct console *co)
1964 * console=<name>,io|mmio|mmio16|mmio32|mmio32be|mmio32native,<addr>,<options> 1964 * console=<name>,io|mmio|mmio16|mmio32|mmio32be|mmio32native,<addr>,<options>
1965 * 1965 *
1966 * The optional form 1966 * The optional form
1967 *
1967 * earlycon=<name>,0x<addr>,<options> 1968 * earlycon=<name>,0x<addr>,<options>
1968 * console=<name>,0x<addr>,<options> 1969 * console=<name>,0x<addr>,<options>
1970 *
1969 * is also accepted; the returned @iotype will be UPIO_MEM. 1971 * is also accepted; the returned @iotype will be UPIO_MEM.
1970 * 1972 *
1971 * Returns 0 on success or -EINVAL on failure 1973 * Returns 0 on success or -EINVAL on failure
diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/serial_mctrl_gpio.c
index d9074303c88e..fb4781292d40 100644
--- a/drivers/tty/serial/serial_mctrl_gpio.c
+++ b/drivers/tty/serial/serial_mctrl_gpio.c
@@ -66,6 +66,9 @@ EXPORT_SYMBOL_GPL(mctrl_gpio_set);
66struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios, 66struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
67 enum mctrl_gpio_idx gidx) 67 enum mctrl_gpio_idx gidx)
68{ 68{
69 if (gpios == NULL)
70 return NULL;
71
69 return gpios->gpio[gidx]; 72 return gpios->gpio[gidx];
70} 73}
71EXPORT_SYMBOL_GPL(mctrl_gpio_to_gpiod); 74EXPORT_SYMBOL_GPL(mctrl_gpio_to_gpiod);
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 4e754a4850e6..22e5d4e13714 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2894,8 +2894,12 @@ static int sci_init_single(struct platform_device *dev,
2894 port->mapbase = res->start; 2894 port->mapbase = res->start;
2895 sci_port->reg_size = resource_size(res); 2895 sci_port->reg_size = resource_size(res);
2896 2896
2897 for (i = 0; i < ARRAY_SIZE(sci_port->irqs); ++i) 2897 for (i = 0; i < ARRAY_SIZE(sci_port->irqs); ++i) {
2898 sci_port->irqs[i] = platform_get_irq(dev, i); 2898 if (i)
2899 sci_port->irqs[i] = platform_get_irq_optional(dev, i);
2900 else
2901 sci_port->irqs[i] = platform_get_irq(dev, i);
2902 }
2899 2903
2900 /* The SCI generates several interrupts. They can be muxed together or 2904 /* The SCI generates several interrupts. They can be muxed together or
2901 * connected to different interrupt lines. In the muxed case only one 2905 * connected to different interrupt lines. In the muxed case only one
diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
index b8b912b5a8b9..06e79c11141d 100644
--- a/drivers/tty/serial/uartlite.c
+++ b/drivers/tty/serial/uartlite.c
@@ -897,7 +897,8 @@ static int __init ulite_init(void)
897static void __exit ulite_exit(void) 897static void __exit ulite_exit(void)
898{ 898{
899 platform_driver_unregister(&ulite_platform_driver); 899 platform_driver_unregister(&ulite_platform_driver);
900 uart_unregister_driver(&ulite_uart_driver); 900 if (ulite_uart_driver.state)
901 uart_unregister_driver(&ulite_uart_driver);
901} 902}
902 903
903module_init(ulite_init); 904module_init(ulite_init);
diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c
index da4563aaaf5c..4e55bc327a54 100644
--- a/drivers/tty/serial/xilinx_uartps.c
+++ b/drivers/tty/serial/xilinx_uartps.c
@@ -1550,7 +1550,6 @@ static int cdns_uart_probe(struct platform_device *pdev)
1550 goto err_out_id; 1550 goto err_out_id;
1551 } 1551 }
1552 1552
1553 uartps_major = cdns_uart_uart_driver->tty_driver->major;
1554 cdns_uart_data->cdns_uart_driver = cdns_uart_uart_driver; 1553 cdns_uart_data->cdns_uart_driver = cdns_uart_uart_driver;
1555 1554
1556 /* 1555 /*
@@ -1680,6 +1679,7 @@ static int cdns_uart_probe(struct platform_device *pdev)
1680 console_port = NULL; 1679 console_port = NULL;
1681#endif 1680#endif
1682 1681
1682 uartps_major = cdns_uart_uart_driver->tty_driver->major;
1683 cdns_uart_data->cts_override = of_property_read_bool(pdev->dev.of_node, 1683 cdns_uart_data->cts_override = of_property_read_bool(pdev->dev.of_node,
1684 "cts-override"); 1684 "cts-override");
1685 return 0; 1685 return 0;
@@ -1741,6 +1741,12 @@ static int cdns_uart_remove(struct platform_device *pdev)
1741 console_port = NULL; 1741 console_port = NULL;
1742#endif 1742#endif
1743 1743
1744 /* If this is last instance major number should be initialized */
1745 mutex_lock(&bitmap_lock);
1746 if (bitmap_empty(bitmap, MAX_UART_INSTANCES))
1747 uartps_major = 0;
1748 mutex_unlock(&bitmap_lock);
1749
1744 uart_unregister_driver(cdns_uart_data->cdns_uart_driver); 1750 uart_unregister_driver(cdns_uart_data->cdns_uart_driver);
1745 return rc; 1751 return rc;
1746} 1752}
diff --git a/drivers/usb/cdns3/cdns3-pci-wrap.c b/drivers/usb/cdns3/cdns3-pci-wrap.c
index c41ddb61b857..b0a29efe7d31 100644
--- a/drivers/usb/cdns3/cdns3-pci-wrap.c
+++ b/drivers/usb/cdns3/cdns3-pci-wrap.c
@@ -159,8 +159,9 @@ static int cdns3_pci_probe(struct pci_dev *pdev,
159 wrap->plat_dev = platform_device_register_full(&plat_info); 159 wrap->plat_dev = platform_device_register_full(&plat_info);
160 if (IS_ERR(wrap->plat_dev)) { 160 if (IS_ERR(wrap->plat_dev)) {
161 pci_disable_device(pdev); 161 pci_disable_device(pdev);
162 err = PTR_ERR(wrap->plat_dev);
162 kfree(wrap); 163 kfree(wrap);
163 return PTR_ERR(wrap->plat_dev); 164 return err;
164 } 165 }
165 } 166 }
166 167
diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
index 06f1e105be4e..1109dc5a4c39 100644
--- a/drivers/usb/cdns3/core.c
+++ b/drivers/usb/cdns3/core.c
@@ -160,10 +160,28 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
160 if (ret) 160 if (ret)
161 goto err; 161 goto err;
162 162
163 if (cdns->dr_mode != USB_DR_MODE_OTG) { 163 /* Initialize idle role to start with */
164 ret = cdns3_role_start(cdns, USB_ROLE_NONE);
165 if (ret)
166 goto err;
167
168 switch (cdns->dr_mode) {
169 case USB_DR_MODE_UNKNOWN:
170 case USB_DR_MODE_OTG:
164 ret = cdns3_hw_role_switch(cdns); 171 ret = cdns3_hw_role_switch(cdns);
165 if (ret) 172 if (ret)
166 goto err; 173 goto err;
174 break;
175 case USB_DR_MODE_PERIPHERAL:
176 ret = cdns3_role_start(cdns, USB_ROLE_DEVICE);
177 if (ret)
178 goto err;
179 break;
180 case USB_DR_MODE_HOST:
181 ret = cdns3_role_start(cdns, USB_ROLE_HOST);
182 if (ret)
183 goto err;
184 break;
167 } 185 }
168 186
169 return ret; 187 return ret;
diff --git a/drivers/usb/cdns3/ep0.c b/drivers/usb/cdns3/ep0.c
index 44f652e8b5a2..e71240b386b4 100644
--- a/drivers/usb/cdns3/ep0.c
+++ b/drivers/usb/cdns3/ep0.c
@@ -234,9 +234,11 @@ static int cdns3_req_ep0_set_address(struct cdns3_device *priv_dev,
234static int cdns3_req_ep0_get_status(struct cdns3_device *priv_dev, 234static int cdns3_req_ep0_get_status(struct cdns3_device *priv_dev,
235 struct usb_ctrlrequest *ctrl) 235 struct usb_ctrlrequest *ctrl)
236{ 236{
237 struct cdns3_endpoint *priv_ep;
237 __le16 *response_pkt; 238 __le16 *response_pkt;
238 u16 usb_status = 0; 239 u16 usb_status = 0;
239 u32 recip; 240 u32 recip;
241 u8 index;
240 242
241 recip = ctrl->bRequestType & USB_RECIP_MASK; 243 recip = ctrl->bRequestType & USB_RECIP_MASK;
242 244
@@ -262,9 +264,13 @@ static int cdns3_req_ep0_get_status(struct cdns3_device *priv_dev,
262 case USB_RECIP_INTERFACE: 264 case USB_RECIP_INTERFACE:
263 return cdns3_ep0_delegate_req(priv_dev, ctrl); 265 return cdns3_ep0_delegate_req(priv_dev, ctrl);
264 case USB_RECIP_ENDPOINT: 266 case USB_RECIP_ENDPOINT:
265 /* check if endpoint is stalled */ 267 index = cdns3_ep_addr_to_index(ctrl->wIndex);
268 priv_ep = priv_dev->eps[index];
269
270 /* check if endpoint is stalled or stall is pending */
266 cdns3_select_ep(priv_dev, ctrl->wIndex); 271 cdns3_select_ep(priv_dev, ctrl->wIndex);
267 if (EP_STS_STALL(readl(&priv_dev->regs->ep_sts))) 272 if (EP_STS_STALL(readl(&priv_dev->regs->ep_sts)) ||
273 (priv_ep->flags & EP_STALL_PENDING))
268 usb_status = BIT(USB_ENDPOINT_HALT); 274 usb_status = BIT(USB_ENDPOINT_HALT);
269 break; 275 break;
270 default: 276 default:
@@ -332,7 +338,7 @@ static int cdns3_ep0_feature_handle_device(struct cdns3_device *priv_dev,
332 * for sending status stage. 338 * for sending status stage.
333 * This time should be less then 3ms. 339 * This time should be less then 3ms.
334 */ 340 */
335 usleep_range(1000, 2000); 341 mdelay(1);
336 cdns3_set_register_bit(&priv_dev->regs->usb_cmd, 342 cdns3_set_register_bit(&priv_dev->regs->usb_cmd,
337 USB_CMD_STMODE | 343 USB_CMD_STMODE |
338 USB_STS_TMODE_SEL(tmode - 1)); 344 USB_STS_TMODE_SEL(tmode - 1));
diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c
index 228cdc4ab886..2ca280f4c054 100644
--- a/drivers/usb/cdns3/gadget.c
+++ b/drivers/usb/cdns3/gadget.c
@@ -2571,6 +2571,7 @@ static int cdns3_gadget_start(struct cdns3 *cdns)
2571 switch (max_speed) { 2571 switch (max_speed) {
2572 case USB_SPEED_FULL: 2572 case USB_SPEED_FULL:
2573 writel(USB_CONF_SFORCE_FS, &priv_dev->regs->usb_conf); 2573 writel(USB_CONF_SFORCE_FS, &priv_dev->regs->usb_conf);
2574 writel(USB_CONF_USB3DIS, &priv_dev->regs->usb_conf);
2574 break; 2575 break;
2575 case USB_SPEED_HIGH: 2576 case USB_SPEED_HIGH:
2576 writel(USB_CONF_USB3DIS, &priv_dev->regs->usb_conf); 2577 writel(USB_CONF_USB3DIS, &priv_dev->regs->usb_conf);
@@ -2662,6 +2663,13 @@ static int __cdns3_gadget_init(struct cdns3 *cdns)
2662{ 2663{
2663 int ret = 0; 2664 int ret = 0;
2664 2665
2666 /* Ensure 32-bit DMA Mask in case we switched back from Host mode */
2667 ret = dma_set_mask_and_coherent(cdns->dev, DMA_BIT_MASK(32));
2668 if (ret) {
2669 dev_err(cdns->dev, "Failed to set dma mask: %d\n", ret);
2670 return ret;
2671 }
2672
2665 cdns3_drd_switch_gadget(cdns, 1); 2673 cdns3_drd_switch_gadget(cdns, 1);
2666 pm_runtime_get_sync(cdns->dev); 2674 pm_runtime_get_sync(cdns->dev);
2667 2675
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 7fea4999d352..fb8bd60c83f4 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -461,10 +461,12 @@ static int usblp_release(struct inode *inode, struct file *file)
461 461
462 mutex_lock(&usblp_mutex); 462 mutex_lock(&usblp_mutex);
463 usblp->used = 0; 463 usblp->used = 0;
464 if (usblp->present) { 464 if (usblp->present)
465 usblp_unlink_urbs(usblp); 465 usblp_unlink_urbs(usblp);
466 usb_autopm_put_interface(usblp->intf); 466
467 } else /* finish cleanup from disconnect */ 467 usb_autopm_put_interface(usblp->intf);
468
469 if (!usblp->present) /* finish cleanup from disconnect */
468 usblp_cleanup(usblp); 470 usblp_cleanup(usblp);
469 mutex_unlock(&usblp_mutex); 471 mutex_unlock(&usblp_mutex);
470 return 0; 472 return 0;
diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
index 726100d1ac0d..c946d64142ad 100644
--- a/drivers/usb/dwc3/drd.c
+++ b/drivers/usb/dwc3/drd.c
@@ -139,14 +139,14 @@ static int dwc3_otg_get_irq(struct dwc3 *dwc)
139 struct platform_device *dwc3_pdev = to_platform_device(dwc->dev); 139 struct platform_device *dwc3_pdev = to_platform_device(dwc->dev);
140 int irq; 140 int irq;
141 141
142 irq = platform_get_irq_byname(dwc3_pdev, "otg"); 142 irq = platform_get_irq_byname_optional(dwc3_pdev, "otg");
143 if (irq > 0) 143 if (irq > 0)
144 goto out; 144 goto out;
145 145
146 if (irq == -EPROBE_DEFER) 146 if (irq == -EPROBE_DEFER)
147 goto out; 147 goto out;
148 148
149 irq = platform_get_irq_byname(dwc3_pdev, "dwc_usb3"); 149 irq = platform_get_irq_byname_optional(dwc3_pdev, "dwc_usb3");
150 if (irq > 0) 150 if (irq > 0)
151 goto out; 151 goto out;
152 152
@@ -157,9 +157,6 @@ static int dwc3_otg_get_irq(struct dwc3 *dwc)
157 if (irq > 0) 157 if (irq > 0)
158 goto out; 158 goto out;
159 159
160 if (irq != -EPROBE_DEFER)
161 dev_err(dwc->dev, "missing OTG IRQ\n");
162
163 if (!irq) 160 if (!irq)
164 irq = -EINVAL; 161 irq = -EINVAL;
165 162
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 8adb59f8e4f1..86dc1db788a9 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -3264,14 +3264,14 @@ static int dwc3_gadget_get_irq(struct dwc3 *dwc)
3264 struct platform_device *dwc3_pdev = to_platform_device(dwc->dev); 3264 struct platform_device *dwc3_pdev = to_platform_device(dwc->dev);
3265 int irq; 3265 int irq;
3266 3266
3267 irq = platform_get_irq_byname(dwc3_pdev, "peripheral"); 3267 irq = platform_get_irq_byname_optional(dwc3_pdev, "peripheral");
3268 if (irq > 0) 3268 if (irq > 0)
3269 goto out; 3269 goto out;
3270 3270
3271 if (irq == -EPROBE_DEFER) 3271 if (irq == -EPROBE_DEFER)
3272 goto out; 3272 goto out;
3273 3273
3274 irq = platform_get_irq_byname(dwc3_pdev, "dwc_usb3"); 3274 irq = platform_get_irq_byname_optional(dwc3_pdev, "dwc_usb3");
3275 if (irq > 0) 3275 if (irq > 0)
3276 goto out; 3276 goto out;
3277 3277
@@ -3282,9 +3282,6 @@ static int dwc3_gadget_get_irq(struct dwc3 *dwc)
3282 if (irq > 0) 3282 if (irq > 0)
3283 goto out; 3283 goto out;
3284 3284
3285 if (irq != -EPROBE_DEFER)
3286 dev_err(dwc->dev, "missing peripheral IRQ\n");
3287
3288 if (!irq) 3285 if (!irq)
3289 irq = -EINVAL; 3286 irq = -EINVAL;
3290 3287
diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
index 8deea8c91e03..5567ed2cddbe 100644
--- a/drivers/usb/dwc3/host.c
+++ b/drivers/usb/dwc3/host.c
@@ -16,14 +16,14 @@ static int dwc3_host_get_irq(struct dwc3 *dwc)
16 struct platform_device *dwc3_pdev = to_platform_device(dwc->dev); 16 struct platform_device *dwc3_pdev = to_platform_device(dwc->dev);
17 int irq; 17 int irq;
18 18
19 irq = platform_get_irq_byname(dwc3_pdev, "host"); 19 irq = platform_get_irq_byname_optional(dwc3_pdev, "host");
20 if (irq > 0) 20 if (irq > 0)
21 goto out; 21 goto out;
22 22
23 if (irq == -EPROBE_DEFER) 23 if (irq == -EPROBE_DEFER)
24 goto out; 24 goto out;
25 25
26 irq = platform_get_irq_byname(dwc3_pdev, "dwc_usb3"); 26 irq = platform_get_irq_byname_optional(dwc3_pdev, "dwc_usb3");
27 if (irq > 0) 27 if (irq > 0)
28 goto out; 28 goto out;
29 29
@@ -34,9 +34,6 @@ static int dwc3_host_get_irq(struct dwc3 *dwc)
34 if (irq > 0) 34 if (irq > 0)
35 goto out; 35 goto out;
36 36
37 if (irq != -EPROBE_DEFER)
38 dev_err(dwc->dev, "missing host IRQ\n");
39
40 if (!irq) 37 if (!irq)
41 irq = -EINVAL; 38 irq = -EINVAL;
42 39
diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index d7e611645533..d354036ff6c8 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -45,7 +45,7 @@ config USB_AT91
45 45
46config USB_LPC32XX 46config USB_LPC32XX
47 tristate "LPC32XX USB Peripheral Controller" 47 tristate "LPC32XX USB Peripheral Controller"
48 depends on ARCH_LPC32XX 48 depends on ARCH_LPC32XX || COMPILE_TEST
49 depends on I2C 49 depends on I2C
50 select USB_ISP1301 50 select USB_ISP1301
51 help 51 help
diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c
index 8414fac74493..3d499d93c083 100644
--- a/drivers/usb/gadget/udc/dummy_hcd.c
+++ b/drivers/usb/gadget/udc/dummy_hcd.c
@@ -48,6 +48,7 @@
48#define DRIVER_VERSION "02 May 2005" 48#define DRIVER_VERSION "02 May 2005"
49 49
50#define POWER_BUDGET 500 /* in mA; use 8 for low-power port testing */ 50#define POWER_BUDGET 500 /* in mA; use 8 for low-power port testing */
51#define POWER_BUDGET_3 900 /* in mA */
51 52
52static const char driver_name[] = "dummy_hcd"; 53static const char driver_name[] = "dummy_hcd";
53static const char driver_desc[] = "USB Host+Gadget Emulator"; 54static const char driver_desc[] = "USB Host+Gadget Emulator";
@@ -2432,7 +2433,7 @@ static int dummy_start_ss(struct dummy_hcd *dum_hcd)
2432 dum_hcd->rh_state = DUMMY_RH_RUNNING; 2433 dum_hcd->rh_state = DUMMY_RH_RUNNING;
2433 dum_hcd->stream_en_ep = 0; 2434 dum_hcd->stream_en_ep = 0;
2434 INIT_LIST_HEAD(&dum_hcd->urbp_list); 2435 INIT_LIST_HEAD(&dum_hcd->urbp_list);
2435 dummy_hcd_to_hcd(dum_hcd)->power_budget = POWER_BUDGET; 2436 dummy_hcd_to_hcd(dum_hcd)->power_budget = POWER_BUDGET_3;
2436 dummy_hcd_to_hcd(dum_hcd)->state = HC_STATE_RUNNING; 2437 dummy_hcd_to_hcd(dum_hcd)->state = HC_STATE_RUNNING;
2437 dummy_hcd_to_hcd(dum_hcd)->uses_new_polling = 1; 2438 dummy_hcd_to_hcd(dum_hcd)->uses_new_polling = 1;
2438#ifdef CONFIG_USB_OTG 2439#ifdef CONFIG_USB_OTG
diff --git a/drivers/usb/gadget/udc/lpc32xx_udc.c b/drivers/usb/gadget/udc/lpc32xx_udc.c
index b3e073fb88c6..2b1f3cc7819b 100644
--- a/drivers/usb/gadget/udc/lpc32xx_udc.c
+++ b/drivers/usb/gadget/udc/lpc32xx_udc.c
@@ -1151,7 +1151,7 @@ static void udc_pop_fifo(struct lpc32xx_udc *udc, u8 *data, u32 bytes)
1151 u32 *p32, tmp, cbytes; 1151 u32 *p32, tmp, cbytes;
1152 1152
1153 /* Use optimal data transfer method based on source address and size */ 1153 /* Use optimal data transfer method based on source address and size */
1154 switch (((u32) data) & 0x3) { 1154 switch (((uintptr_t) data) & 0x3) {
1155 case 0: /* 32-bit aligned */ 1155 case 0: /* 32-bit aligned */
1156 p32 = (u32 *) data; 1156 p32 = (u32 *) data;
1157 cbytes = (bytes & ~0x3); 1157 cbytes = (bytes & ~0x3);
@@ -1252,7 +1252,7 @@ static void udc_stuff_fifo(struct lpc32xx_udc *udc, u8 *data, u32 bytes)
1252 u32 *p32, tmp, cbytes; 1252 u32 *p32, tmp, cbytes;
1253 1253
1254 /* Use optimal data transfer method based on source address and size */ 1254 /* Use optimal data transfer method based on source address and size */
1255 switch (((u32) data) & 0x3) { 1255 switch (((uintptr_t) data) & 0x3) {
1256 case 0: /* 32-bit aligned */ 1256 case 0: /* 32-bit aligned */
1257 p32 = (u32 *) data; 1257 p32 = (u32 *) data;
1258 cbytes = (bytes & ~0x3); 1258 cbytes = (bytes & ~0x3);
diff --git a/drivers/usb/host/xhci-ext-caps.c b/drivers/usb/host/xhci-ext-caps.c
index f498160df969..3351d07c431f 100644
--- a/drivers/usb/host/xhci-ext-caps.c
+++ b/drivers/usb/host/xhci-ext-caps.c
@@ -57,6 +57,7 @@ static int xhci_create_intel_xhci_sw_pdev(struct xhci_hcd *xhci, u32 cap_offset)
57 ret = platform_device_add_properties(pdev, role_switch_props); 57 ret = platform_device_add_properties(pdev, role_switch_props);
58 if (ret) { 58 if (ret) {
59 dev_err(dev, "failed to register device properties\n"); 59 dev_err(dev, "failed to register device properties\n");
60 platform_device_put(pdev);
60 return ret; 61 return ret;
61 } 62 }
62 } 63 }
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 9741cdeea9d7..85ceb43e3405 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -3202,10 +3202,10 @@ static int xhci_align_td(struct xhci_hcd *xhci, struct urb *urb, u32 enqd_len,
3202 if (usb_urb_dir_out(urb)) { 3202 if (usb_urb_dir_out(urb)) {
3203 len = sg_pcopy_to_buffer(urb->sg, urb->num_sgs, 3203 len = sg_pcopy_to_buffer(urb->sg, urb->num_sgs,
3204 seg->bounce_buf, new_buff_len, enqd_len); 3204 seg->bounce_buf, new_buff_len, enqd_len);
3205 if (len != seg->bounce_len) 3205 if (len != new_buff_len)
3206 xhci_warn(xhci, 3206 xhci_warn(xhci,
3207 "WARN Wrong bounce buffer write length: %zu != %d\n", 3207 "WARN Wrong bounce buffer write length: %zu != %d\n",
3208 len, seg->bounce_len); 3208 len, new_buff_len);
3209 seg->bounce_dma = dma_map_single(dev, seg->bounce_buf, 3209 seg->bounce_dma = dma_map_single(dev, seg->bounce_buf,
3210 max_pkt, DMA_TO_DEVICE); 3210 max_pkt, DMA_TO_DEVICE);
3211 } else { 3211 } else {
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 500865975687..517ec3206f6e 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1032,7 +1032,7 @@ int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup)
1032 writel(command, &xhci->op_regs->command); 1032 writel(command, &xhci->op_regs->command);
1033 xhci->broken_suspend = 0; 1033 xhci->broken_suspend = 0;
1034 if (xhci_handshake(&xhci->op_regs->status, 1034 if (xhci_handshake(&xhci->op_regs->status,
1035 STS_SAVE, 0, 10 * 1000)) { 1035 STS_SAVE, 0, 20 * 1000)) {
1036 /* 1036 /*
1037 * AMD SNPS xHC 3.0 occasionally does not clear the 1037 * AMD SNPS xHC 3.0 occasionally does not clear the
1038 * SSS bit of USBSTS and when driver tries to poll 1038 * SSS bit of USBSTS and when driver tries to poll
@@ -1108,6 +1108,18 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
1108 hibernated = true; 1108 hibernated = true;
1109 1109
1110 if (!hibernated) { 1110 if (!hibernated) {
1111 /*
1112 * Some controllers might lose power during suspend, so wait
1113 * for controller not ready bit to clear, just as in xHC init.
1114 */
1115 retval = xhci_handshake(&xhci->op_regs->status,
1116 STS_CNR, 0, 10 * 1000 * 1000);
1117 if (retval) {
1118 xhci_warn(xhci, "Controller not ready at resume %d\n",
1119 retval);
1120 spin_unlock_irq(&xhci->lock);
1121 return retval;
1122 }
1111 /* step 1: restore register */ 1123 /* step 1: restore register */
1112 xhci_restore_registers(xhci); 1124 xhci_restore_registers(xhci);
1113 /* step 2: initialize command ring buffer */ 1125 /* step 2: initialize command ring buffer */
@@ -3083,6 +3095,7 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd,
3083 unsigned int ep_index; 3095 unsigned int ep_index;
3084 unsigned long flags; 3096 unsigned long flags;
3085 u32 ep_flag; 3097 u32 ep_flag;
3098 int err;
3086 3099
3087 xhci = hcd_to_xhci(hcd); 3100 xhci = hcd_to_xhci(hcd);
3088 if (!host_ep->hcpriv) 3101 if (!host_ep->hcpriv)
@@ -3142,7 +3155,17 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd,
3142 xhci_free_command(xhci, cfg_cmd); 3155 xhci_free_command(xhci, cfg_cmd);
3143 goto cleanup; 3156 goto cleanup;
3144 } 3157 }
3145 xhci_queue_stop_endpoint(xhci, stop_cmd, udev->slot_id, ep_index, 0); 3158
3159 err = xhci_queue_stop_endpoint(xhci, stop_cmd, udev->slot_id,
3160 ep_index, 0);
3161 if (err < 0) {
3162 spin_unlock_irqrestore(&xhci->lock, flags);
3163 xhci_free_command(xhci, cfg_cmd);
3164 xhci_dbg(xhci, "%s: Failed to queue stop ep command, %d ",
3165 __func__, err);
3166 goto cleanup;
3167 }
3168
3146 xhci_ring_cmd_db(xhci); 3169 xhci_ring_cmd_db(xhci);
3147 spin_unlock_irqrestore(&xhci->lock, flags); 3170 spin_unlock_irqrestore(&xhci->lock, flags);
3148 3171
@@ -3156,8 +3179,16 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd,
3156 ctrl_ctx, ep_flag, ep_flag); 3179 ctrl_ctx, ep_flag, ep_flag);
3157 xhci_endpoint_copy(xhci, cfg_cmd->in_ctx, vdev->out_ctx, ep_index); 3180 xhci_endpoint_copy(xhci, cfg_cmd->in_ctx, vdev->out_ctx, ep_index);
3158 3181
3159 xhci_queue_configure_endpoint(xhci, cfg_cmd, cfg_cmd->in_ctx->dma, 3182 err = xhci_queue_configure_endpoint(xhci, cfg_cmd, cfg_cmd->in_ctx->dma,
3160 udev->slot_id, false); 3183 udev->slot_id, false);
3184 if (err < 0) {
3185 spin_unlock_irqrestore(&xhci->lock, flags);
3186 xhci_free_command(xhci, cfg_cmd);
3187 xhci_dbg(xhci, "%s: Failed to queue config ep command, %d ",
3188 __func__, err);
3189 goto cleanup;
3190 }
3191
3161 xhci_ring_cmd_db(xhci); 3192 xhci_ring_cmd_db(xhci);
3162 spin_unlock_irqrestore(&xhci->lock, flags); 3193 spin_unlock_irqrestore(&xhci->lock, flags);
3163 3194
@@ -4674,12 +4705,12 @@ static int xhci_update_timeout_for_endpoint(struct xhci_hcd *xhci,
4674 alt_timeout = xhci_call_host_update_timeout_for_endpoint(xhci, udev, 4705 alt_timeout = xhci_call_host_update_timeout_for_endpoint(xhci, udev,
4675 desc, state, timeout); 4706 desc, state, timeout);
4676 4707
4677 /* If we found we can't enable hub-initiated LPM, or 4708 /* If we found we can't enable hub-initiated LPM, and
4678 * the U1 or U2 exit latency was too high to allow 4709 * the U1 or U2 exit latency was too high to allow
4679 * device-initiated LPM as well, just stop searching. 4710 * device-initiated LPM as well, then we will disable LPM
4711 * for this device, so stop searching any further.
4680 */ 4712 */
4681 if (alt_timeout == USB3_LPM_DISABLED || 4713 if (alt_timeout == USB3_LPM_DISABLED) {
4682 alt_timeout == USB3_LPM_DEVICE_INITIATED) {
4683 *timeout = alt_timeout; 4714 *timeout = alt_timeout;
4684 return -E2BIG; 4715 return -E2BIG;
4685 } 4716 }
@@ -4790,10 +4821,12 @@ static u16 xhci_calculate_lpm_timeout(struct usb_hcd *hcd,
4790 if (intf->dev.driver) { 4821 if (intf->dev.driver) {
4791 driver = to_usb_driver(intf->dev.driver); 4822 driver = to_usb_driver(intf->dev.driver);
4792 if (driver && driver->disable_hub_initiated_lpm) { 4823 if (driver && driver->disable_hub_initiated_lpm) {
4793 dev_dbg(&udev->dev, "Hub-initiated %s disabled " 4824 dev_dbg(&udev->dev, "Hub-initiated %s disabled at request of driver %s\n",
4794 "at request of driver %s\n", 4825 state_name, driver->name);
4795 state_name, driver->name); 4826 timeout = xhci_get_timeout_no_hub_lpm(udev,
4796 return xhci_get_timeout_no_hub_lpm(udev, state); 4827 state);
4828 if (timeout == USB3_LPM_DISABLED)
4829 return timeout;
4797 } 4830 }
4798 } 4831 }
4799 4832
@@ -5077,11 +5110,18 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
5077 hcd->has_tt = 1; 5110 hcd->has_tt = 1;
5078 } else { 5111 } else {
5079 /* 5112 /*
5080 * Some 3.1 hosts return sbrn 0x30, use xhci supported protocol 5113 * Early xHCI 1.1 spec did not mention USB 3.1 capable hosts
5081 * minor revision instead of sbrn. Minor revision is a two digit 5114 * should return 0x31 for sbrn, or that the minor revision
5082 * BCD containing minor and sub-minor numbers, only show minor. 5115 * is a two digit BCD containig minor and sub-minor numbers.
5116 * This was later clarified in xHCI 1.2.
5117 *
5118 * Some USB 3.1 capable hosts therefore have sbrn 0x30, and
5119 * minor revision set to 0x1 instead of 0x10.
5083 */ 5120 */
5084 minor_rev = xhci->usb3_rhub.min_rev / 0x10; 5121 if (xhci->usb3_rhub.min_rev == 0x1)
5122 minor_rev = 1;
5123 else
5124 minor_rev = xhci->usb3_rhub.min_rev / 0x10;
5085 5125
5086 switch (minor_rev) { 5126 switch (minor_rev) {
5087 case 2: 5127 case 2:
@@ -5198,8 +5238,16 @@ static void xhci_clear_tt_buffer_complete(struct usb_hcd *hcd,
5198 unsigned int ep_index; 5238 unsigned int ep_index;
5199 unsigned long flags; 5239 unsigned long flags;
5200 5240
5241 /*
5242 * udev might be NULL if tt buffer is cleared during a failed device
5243 * enumeration due to a halted control endpoint. Usb core might
5244 * have allocated a new udev for the next enumeration attempt.
5245 */
5246
5201 xhci = hcd_to_xhci(hcd); 5247 xhci = hcd_to_xhci(hcd);
5202 udev = (struct usb_device *)ep->hcpriv; 5248 udev = (struct usb_device *)ep->hcpriv;
5249 if (!udev)
5250 return;
5203 slot_id = udev->slot_id; 5251 slot_id = udev->slot_id;
5204 ep_index = xhci_get_endpoint_index(&ep->desc); 5252 ep_index = xhci_get_endpoint_index(&ep->desc);
5205 5253
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index 0a57c2cc8e5a..7a6b122c833f 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -716,6 +716,10 @@ static int mts_usb_probe(struct usb_interface *intf,
716 716
717 } 717 }
718 718
719 if (ep_in_current != &ep_in_set[2]) {
720 MTS_WARNING("couldn't find two input bulk endpoints. Bailing out.\n");
721 return -ENODEV;
722 }
719 723
720 if ( ep_out == -1 ) { 724 if ( ep_out == -1 ) {
721 MTS_WARNING( "couldn't find an output bulk endpoint. Bailing out.\n" ); 725 MTS_WARNING( "couldn't find an output bulk endpoint. Bailing out.\n" );
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index bdae62b2ffe0..9bce583aada3 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -47,16 +47,6 @@ config USB_SEVSEG
47 To compile this driver as a module, choose M here: the 47 To compile this driver as a module, choose M here: the
48 module will be called usbsevseg. 48 module will be called usbsevseg.
49 49
50config USB_RIO500
51 tristate "USB Diamond Rio500 support"
52 help
53 Say Y here if you want to connect a USB Rio500 mp3 player to your
54 computer's USB port. Please read <file:Documentation/usb/rio.rst>
55 for more information.
56
57 To compile this driver as a module, choose M here: the
58 module will be called rio500.
59
60config USB_LEGOTOWER 50config USB_LEGOTOWER
61 tristate "USB Lego Infrared Tower support" 51 tristate "USB Lego Infrared Tower support"
62 help 52 help
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index 109f54f5b9aa..0d416eb624bb 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -17,7 +17,6 @@ obj-$(CONFIG_USB_ISIGHTFW) += isight_firmware.o
17obj-$(CONFIG_USB_LCD) += usblcd.o 17obj-$(CONFIG_USB_LCD) += usblcd.o
18obj-$(CONFIG_USB_LD) += ldusb.o 18obj-$(CONFIG_USB_LD) += ldusb.o
19obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o 19obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o
20obj-$(CONFIG_USB_RIO500) += rio500.o
21obj-$(CONFIG_USB_TEST) += usbtest.o 20obj-$(CONFIG_USB_TEST) += usbtest.o
22obj-$(CONFIG_USB_EHSET_TEST_FIXTURE) += ehset.o 21obj-$(CONFIG_USB_EHSET_TEST_FIXTURE) += ehset.o
23obj-$(CONFIG_USB_TRANCEVIBRATOR) += trancevibrator.o 22obj-$(CONFIG_USB_TRANCEVIBRATOR) += trancevibrator.o
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
index 344d523b0502..6f5edb9fc61e 100644
--- a/drivers/usb/misc/adutux.c
+++ b/drivers/usb/misc/adutux.c
@@ -75,6 +75,7 @@ struct adu_device {
75 char serial_number[8]; 75 char serial_number[8];
76 76
77 int open_count; /* number of times this port has been opened */ 77 int open_count; /* number of times this port has been opened */
78 unsigned long disconnected:1;
78 79
79 char *read_buffer_primary; 80 char *read_buffer_primary;
80 int read_buffer_length; 81 int read_buffer_length;
@@ -116,7 +117,7 @@ static void adu_abort_transfers(struct adu_device *dev)
116{ 117{
117 unsigned long flags; 118 unsigned long flags;
118 119
119 if (dev->udev == NULL) 120 if (dev->disconnected)
120 return; 121 return;
121 122
122 /* shutdown transfer */ 123 /* shutdown transfer */
@@ -148,6 +149,7 @@ static void adu_delete(struct adu_device *dev)
148 kfree(dev->read_buffer_secondary); 149 kfree(dev->read_buffer_secondary);
149 kfree(dev->interrupt_in_buffer); 150 kfree(dev->interrupt_in_buffer);
150 kfree(dev->interrupt_out_buffer); 151 kfree(dev->interrupt_out_buffer);
152 usb_put_dev(dev->udev);
151 kfree(dev); 153 kfree(dev);
152} 154}
153 155
@@ -243,7 +245,7 @@ static int adu_open(struct inode *inode, struct file *file)
243 } 245 }
244 246
245 dev = usb_get_intfdata(interface); 247 dev = usb_get_intfdata(interface);
246 if (!dev || !dev->udev) { 248 if (!dev) {
247 retval = -ENODEV; 249 retval = -ENODEV;
248 goto exit_no_device; 250 goto exit_no_device;
249 } 251 }
@@ -326,7 +328,7 @@ static int adu_release(struct inode *inode, struct file *file)
326 } 328 }
327 329
328 adu_release_internal(dev); 330 adu_release_internal(dev);
329 if (dev->udev == NULL) { 331 if (dev->disconnected) {
330 /* the device was unplugged before the file was released */ 332 /* the device was unplugged before the file was released */
331 if (!dev->open_count) /* ... and we're the last user */ 333 if (!dev->open_count) /* ... and we're the last user */
332 adu_delete(dev); 334 adu_delete(dev);
@@ -354,7 +356,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
354 return -ERESTARTSYS; 356 return -ERESTARTSYS;
355 357
356 /* verify that the device wasn't unplugged */ 358 /* verify that the device wasn't unplugged */
357 if (dev->udev == NULL) { 359 if (dev->disconnected) {
358 retval = -ENODEV; 360 retval = -ENODEV;
359 pr_err("No device or device unplugged %d\n", retval); 361 pr_err("No device or device unplugged %d\n", retval);
360 goto exit; 362 goto exit;
@@ -518,7 +520,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
518 goto exit_nolock; 520 goto exit_nolock;
519 521
520 /* verify that the device wasn't unplugged */ 522 /* verify that the device wasn't unplugged */
521 if (dev->udev == NULL) { 523 if (dev->disconnected) {
522 retval = -ENODEV; 524 retval = -ENODEV;
523 pr_err("No device or device unplugged %d\n", retval); 525 pr_err("No device or device unplugged %d\n", retval);
524 goto exit; 526 goto exit;
@@ -663,7 +665,7 @@ static int adu_probe(struct usb_interface *interface,
663 665
664 mutex_init(&dev->mtx); 666 mutex_init(&dev->mtx);
665 spin_lock_init(&dev->buflock); 667 spin_lock_init(&dev->buflock);
666 dev->udev = udev; 668 dev->udev = usb_get_dev(udev);
667 init_waitqueue_head(&dev->read_wait); 669 init_waitqueue_head(&dev->read_wait);
668 init_waitqueue_head(&dev->write_wait); 670 init_waitqueue_head(&dev->write_wait);
669 671
@@ -762,14 +764,18 @@ static void adu_disconnect(struct usb_interface *interface)
762 764
763 dev = usb_get_intfdata(interface); 765 dev = usb_get_intfdata(interface);
764 766
765 mutex_lock(&dev->mtx); /* not interruptible */
766 dev->udev = NULL; /* poison */
767 usb_deregister_dev(interface, &adu_class); 767 usb_deregister_dev(interface, &adu_class);
768 mutex_unlock(&dev->mtx); 768
769 usb_poison_urb(dev->interrupt_in_urb);
770 usb_poison_urb(dev->interrupt_out_urb);
769 771
770 mutex_lock(&adutux_mutex); 772 mutex_lock(&adutux_mutex);
771 usb_set_intfdata(interface, NULL); 773 usb_set_intfdata(interface, NULL);
772 774
775 mutex_lock(&dev->mtx); /* not interruptible */
776 dev->disconnected = 1;
777 mutex_unlock(&dev->mtx);
778
773 /* if the device is not opened, then we clean up right now */ 779 /* if the device is not opened, then we clean up right now */
774 if (!dev->open_count) 780 if (!dev->open_count)
775 adu_delete(dev); 781 adu_delete(dev);
diff --git a/drivers/usb/misc/chaoskey.c b/drivers/usb/misc/chaoskey.c
index cf5828ce927a..34e6cd6f40d3 100644
--- a/drivers/usb/misc/chaoskey.c
+++ b/drivers/usb/misc/chaoskey.c
@@ -98,6 +98,7 @@ static void chaoskey_free(struct chaoskey *dev)
98 usb_free_urb(dev->urb); 98 usb_free_urb(dev->urb);
99 kfree(dev->name); 99 kfree(dev->name);
100 kfree(dev->buf); 100 kfree(dev->buf);
101 usb_put_intf(dev->interface);
101 kfree(dev); 102 kfree(dev);
102 } 103 }
103} 104}
@@ -145,6 +146,8 @@ static int chaoskey_probe(struct usb_interface *interface,
145 if (dev == NULL) 146 if (dev == NULL)
146 goto out; 147 goto out;
147 148
149 dev->interface = usb_get_intf(interface);
150
148 dev->buf = kmalloc(size, GFP_KERNEL); 151 dev->buf = kmalloc(size, GFP_KERNEL);
149 152
150 if (dev->buf == NULL) 153 if (dev->buf == NULL)
@@ -174,8 +177,6 @@ static int chaoskey_probe(struct usb_interface *interface,
174 goto out; 177 goto out;
175 } 178 }
176 179
177 dev->interface = interface;
178
179 dev->in_ep = in_ep; 180 dev->in_ep = in_ep;
180 181
181 if (le16_to_cpu(udev->descriptor.idVendor) != ALEA_VENDOR_ID) 182 if (le16_to_cpu(udev->descriptor.idVendor) != ALEA_VENDOR_ID)
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index f5bed9f29e56..dce44fbf031f 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -54,11 +54,7 @@ MODULE_AUTHOR(DRIVER_AUTHOR);
54MODULE_DESCRIPTION(DRIVER_DESC); 54MODULE_DESCRIPTION(DRIVER_DESC);
55MODULE_LICENSE("GPL"); 55MODULE_LICENSE("GPL");
56 56
57/* Module parameters */
58static DEFINE_MUTEX(iowarrior_mutex);
59
60static struct usb_driver iowarrior_driver; 57static struct usb_driver iowarrior_driver;
61static DEFINE_MUTEX(iowarrior_open_disc_lock);
62 58
63/*--------------*/ 59/*--------------*/
64/* data */ 60/* data */
@@ -87,6 +83,7 @@ struct iowarrior {
87 char chip_serial[9]; /* the serial number string of the chip connected */ 83 char chip_serial[9]; /* the serial number string of the chip connected */
88 int report_size; /* number of bytes in a report */ 84 int report_size; /* number of bytes in a report */
89 u16 product_id; 85 u16 product_id;
86 struct usb_anchor submitted;
90}; 87};
91 88
92/*--------------*/ 89/*--------------*/
@@ -243,6 +240,7 @@ static inline void iowarrior_delete(struct iowarrior *dev)
243 kfree(dev->int_in_buffer); 240 kfree(dev->int_in_buffer);
244 usb_free_urb(dev->int_in_urb); 241 usb_free_urb(dev->int_in_urb);
245 kfree(dev->read_queue); 242 kfree(dev->read_queue);
243 usb_put_intf(dev->interface);
246 kfree(dev); 244 kfree(dev);
247} 245}
248 246
@@ -424,11 +422,13 @@ static ssize_t iowarrior_write(struct file *file,
424 retval = -EFAULT; 422 retval = -EFAULT;
425 goto error; 423 goto error;
426 } 424 }
425 usb_anchor_urb(int_out_urb, &dev->submitted);
427 retval = usb_submit_urb(int_out_urb, GFP_KERNEL); 426 retval = usb_submit_urb(int_out_urb, GFP_KERNEL);
428 if (retval) { 427 if (retval) {
429 dev_dbg(&dev->interface->dev, 428 dev_dbg(&dev->interface->dev,
430 "submit error %d for urb nr.%d\n", 429 "submit error %d for urb nr.%d\n",
431 retval, atomic_read(&dev->write_busy)); 430 retval, atomic_read(&dev->write_busy));
431 usb_unanchor_urb(int_out_urb);
432 goto error; 432 goto error;
433 } 433 }
434 /* submit was ok */ 434 /* submit was ok */
@@ -477,8 +477,6 @@ static long iowarrior_ioctl(struct file *file, unsigned int cmd,
477 if (!buffer) 477 if (!buffer)
478 return -ENOMEM; 478 return -ENOMEM;
479 479
480 /* lock this object */
481 mutex_lock(&iowarrior_mutex);
482 mutex_lock(&dev->mutex); 480 mutex_lock(&dev->mutex);
483 481
484 /* verify that the device wasn't unplugged */ 482 /* verify that the device wasn't unplugged */
@@ -571,7 +569,6 @@ static long iowarrior_ioctl(struct file *file, unsigned int cmd,
571error_out: 569error_out:
572 /* unlock the device */ 570 /* unlock the device */
573 mutex_unlock(&dev->mutex); 571 mutex_unlock(&dev->mutex);
574 mutex_unlock(&iowarrior_mutex);
575 kfree(buffer); 572 kfree(buffer);
576 return retval; 573 return retval;
577} 574}
@@ -586,27 +583,20 @@ static int iowarrior_open(struct inode *inode, struct file *file)
586 int subminor; 583 int subminor;
587 int retval = 0; 584 int retval = 0;
588 585
589 mutex_lock(&iowarrior_mutex);
590 subminor = iminor(inode); 586 subminor = iminor(inode);
591 587
592 interface = usb_find_interface(&iowarrior_driver, subminor); 588 interface = usb_find_interface(&iowarrior_driver, subminor);
593 if (!interface) { 589 if (!interface) {
594 mutex_unlock(&iowarrior_mutex); 590 pr_err("%s - error, can't find device for minor %d\n",
595 printk(KERN_ERR "%s - error, can't find device for minor %d\n",
596 __func__, subminor); 591 __func__, subminor);
597 return -ENODEV; 592 return -ENODEV;
598 } 593 }
599 594
600 mutex_lock(&iowarrior_open_disc_lock);
601 dev = usb_get_intfdata(interface); 595 dev = usb_get_intfdata(interface);
602 if (!dev) { 596 if (!dev)
603 mutex_unlock(&iowarrior_open_disc_lock);
604 mutex_unlock(&iowarrior_mutex);
605 return -ENODEV; 597 return -ENODEV;
606 }
607 598
608 mutex_lock(&dev->mutex); 599 mutex_lock(&dev->mutex);
609 mutex_unlock(&iowarrior_open_disc_lock);
610 600
611 /* Only one process can open each device, no sharing. */ 601 /* Only one process can open each device, no sharing. */
612 if (dev->opened) { 602 if (dev->opened) {
@@ -628,7 +618,6 @@ static int iowarrior_open(struct inode *inode, struct file *file)
628 618
629out: 619out:
630 mutex_unlock(&dev->mutex); 620 mutex_unlock(&dev->mutex);
631 mutex_unlock(&iowarrior_mutex);
632 return retval; 621 return retval;
633} 622}
634 623
@@ -764,11 +753,13 @@ static int iowarrior_probe(struct usb_interface *interface,
764 init_waitqueue_head(&dev->write_wait); 753 init_waitqueue_head(&dev->write_wait);
765 754
766 dev->udev = udev; 755 dev->udev = udev;
767 dev->interface = interface; 756 dev->interface = usb_get_intf(interface);
768 757
769 iface_desc = interface->cur_altsetting; 758 iface_desc = interface->cur_altsetting;
770 dev->product_id = le16_to_cpu(udev->descriptor.idProduct); 759 dev->product_id = le16_to_cpu(udev->descriptor.idProduct);
771 760
761 init_usb_anchor(&dev->submitted);
762
772 res = usb_find_last_int_in_endpoint(iface_desc, &dev->int_in_endpoint); 763 res = usb_find_last_int_in_endpoint(iface_desc, &dev->int_in_endpoint);
773 if (res) { 764 if (res) {
774 dev_err(&interface->dev, "no interrupt-in endpoint found\n"); 765 dev_err(&interface->dev, "no interrupt-in endpoint found\n");
@@ -836,7 +827,6 @@ static int iowarrior_probe(struct usb_interface *interface,
836 if (retval) { 827 if (retval) {
837 /* something prevented us from registering this driver */ 828 /* something prevented us from registering this driver */
838 dev_err(&interface->dev, "Not able to get a minor for this device.\n"); 829 dev_err(&interface->dev, "Not able to get a minor for this device.\n");
839 usb_set_intfdata(interface, NULL);
840 goto error; 830 goto error;
841 } 831 }
842 832
@@ -860,26 +850,15 @@ error:
860 */ 850 */
861static void iowarrior_disconnect(struct usb_interface *interface) 851static void iowarrior_disconnect(struct usb_interface *interface)
862{ 852{
863 struct iowarrior *dev; 853 struct iowarrior *dev = usb_get_intfdata(interface);
864 int minor; 854 int minor = dev->minor;
865
866 dev = usb_get_intfdata(interface);
867 mutex_lock(&iowarrior_open_disc_lock);
868 usb_set_intfdata(interface, NULL);
869 /* prevent device read, write and ioctl */
870 dev->present = 0;
871
872 minor = dev->minor;
873 mutex_unlock(&iowarrior_open_disc_lock);
874 /* give back our minor - this will call close() locks need to be dropped at this point*/
875 855
876 usb_deregister_dev(interface, &iowarrior_class); 856 usb_deregister_dev(interface, &iowarrior_class);
877 857
878 mutex_lock(&dev->mutex); 858 mutex_lock(&dev->mutex);
879 859
880 /* prevent device read, write and ioctl */ 860 /* prevent device read, write and ioctl */
881 861 dev->present = 0;
882 mutex_unlock(&dev->mutex);
883 862
884 if (dev->opened) { 863 if (dev->opened) {
885 /* There is a process that holds a filedescriptor to the device , 864 /* There is a process that holds a filedescriptor to the device ,
@@ -887,10 +866,13 @@ static void iowarrior_disconnect(struct usb_interface *interface)
887 Deleting the device is postponed until close() was called. 866 Deleting the device is postponed until close() was called.
888 */ 867 */
889 usb_kill_urb(dev->int_in_urb); 868 usb_kill_urb(dev->int_in_urb);
869 usb_kill_anchored_urbs(&dev->submitted);
890 wake_up_interruptible(&dev->read_wait); 870 wake_up_interruptible(&dev->read_wait);
891 wake_up_interruptible(&dev->write_wait); 871 wake_up_interruptible(&dev->write_wait);
872 mutex_unlock(&dev->mutex);
892 } else { 873 } else {
893 /* no process is using the device, cleanup now */ 874 /* no process is using the device, cleanup now */
875 mutex_unlock(&dev->mutex);
894 iowarrior_delete(dev); 876 iowarrior_delete(dev);
895 } 877 }
896 878
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index 6581774bdfa4..f3108d85e768 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -153,6 +153,7 @@ MODULE_PARM_DESC(min_interrupt_out_interval, "Minimum interrupt out interval in
153struct ld_usb { 153struct ld_usb {
154 struct mutex mutex; /* locks this structure */ 154 struct mutex mutex; /* locks this structure */
155 struct usb_interface *intf; /* save off the usb interface pointer */ 155 struct usb_interface *intf; /* save off the usb interface pointer */
156 unsigned long disconnected:1;
156 157
157 int open_count; /* number of times this port has been opened */ 158 int open_count; /* number of times this port has been opened */
158 159
@@ -192,12 +193,10 @@ static void ld_usb_abort_transfers(struct ld_usb *dev)
192 /* shutdown transfer */ 193 /* shutdown transfer */
193 if (dev->interrupt_in_running) { 194 if (dev->interrupt_in_running) {
194 dev->interrupt_in_running = 0; 195 dev->interrupt_in_running = 0;
195 if (dev->intf) 196 usb_kill_urb(dev->interrupt_in_urb);
196 usb_kill_urb(dev->interrupt_in_urb);
197 } 197 }
198 if (dev->interrupt_out_busy) 198 if (dev->interrupt_out_busy)
199 if (dev->intf) 199 usb_kill_urb(dev->interrupt_out_urb);
200 usb_kill_urb(dev->interrupt_out_urb);
201} 200}
202 201
203/** 202/**
@@ -205,8 +204,6 @@ static void ld_usb_abort_transfers(struct ld_usb *dev)
205 */ 204 */
206static void ld_usb_delete(struct ld_usb *dev) 205static void ld_usb_delete(struct ld_usb *dev)
207{ 206{
208 ld_usb_abort_transfers(dev);
209
210 /* free data structures */ 207 /* free data structures */
211 usb_free_urb(dev->interrupt_in_urb); 208 usb_free_urb(dev->interrupt_in_urb);
212 usb_free_urb(dev->interrupt_out_urb); 209 usb_free_urb(dev->interrupt_out_urb);
@@ -263,7 +260,7 @@ static void ld_usb_interrupt_in_callback(struct urb *urb)
263 260
264resubmit: 261resubmit:
265 /* resubmit if we're still running */ 262 /* resubmit if we're still running */
266 if (dev->interrupt_in_running && !dev->buffer_overflow && dev->intf) { 263 if (dev->interrupt_in_running && !dev->buffer_overflow) {
267 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_ATOMIC); 264 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_ATOMIC);
268 if (retval) { 265 if (retval) {
269 dev_err(&dev->intf->dev, 266 dev_err(&dev->intf->dev,
@@ -392,7 +389,7 @@ static int ld_usb_release(struct inode *inode, struct file *file)
392 retval = -ENODEV; 389 retval = -ENODEV;
393 goto unlock_exit; 390 goto unlock_exit;
394 } 391 }
395 if (dev->intf == NULL) { 392 if (dev->disconnected) {
396 /* the device was unplugged before the file was released */ 393 /* the device was unplugged before the file was released */
397 mutex_unlock(&dev->mutex); 394 mutex_unlock(&dev->mutex);
398 /* unlock here as ld_usb_delete frees dev */ 395 /* unlock here as ld_usb_delete frees dev */
@@ -423,7 +420,7 @@ static __poll_t ld_usb_poll(struct file *file, poll_table *wait)
423 420
424 dev = file->private_data; 421 dev = file->private_data;
425 422
426 if (!dev->intf) 423 if (dev->disconnected)
427 return EPOLLERR | EPOLLHUP; 424 return EPOLLERR | EPOLLHUP;
428 425
429 poll_wait(file, &dev->read_wait, wait); 426 poll_wait(file, &dev->read_wait, wait);
@@ -462,7 +459,7 @@ static ssize_t ld_usb_read(struct file *file, char __user *buffer, size_t count,
462 } 459 }
463 460
464 /* verify that the device wasn't unplugged */ 461 /* verify that the device wasn't unplugged */
465 if (dev->intf == NULL) { 462 if (dev->disconnected) {
466 retval = -ENODEV; 463 retval = -ENODEV;
467 printk(KERN_ERR "ldusb: No device or device unplugged %d\n", retval); 464 printk(KERN_ERR "ldusb: No device or device unplugged %d\n", retval);
468 goto unlock_exit; 465 goto unlock_exit;
@@ -542,7 +539,7 @@ static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
542 } 539 }
543 540
544 /* verify that the device wasn't unplugged */ 541 /* verify that the device wasn't unplugged */
545 if (dev->intf == NULL) { 542 if (dev->disconnected) {
546 retval = -ENODEV; 543 retval = -ENODEV;
547 printk(KERN_ERR "ldusb: No device or device unplugged %d\n", retval); 544 printk(KERN_ERR "ldusb: No device or device unplugged %d\n", retval);
548 goto unlock_exit; 545 goto unlock_exit;
@@ -764,6 +761,9 @@ static void ld_usb_disconnect(struct usb_interface *intf)
764 /* give back our minor */ 761 /* give back our minor */
765 usb_deregister_dev(intf, &ld_usb_class); 762 usb_deregister_dev(intf, &ld_usb_class);
766 763
764 usb_poison_urb(dev->interrupt_in_urb);
765 usb_poison_urb(dev->interrupt_out_urb);
766
767 mutex_lock(&dev->mutex); 767 mutex_lock(&dev->mutex);
768 768
769 /* if the device is not opened, then we clean up right now */ 769 /* if the device is not opened, then we clean up right now */
@@ -771,7 +771,7 @@ static void ld_usb_disconnect(struct usb_interface *intf)
771 mutex_unlock(&dev->mutex); 771 mutex_unlock(&dev->mutex);
772 ld_usb_delete(dev); 772 ld_usb_delete(dev);
773 } else { 773 } else {
774 dev->intf = NULL; 774 dev->disconnected = 1;
775 /* wake up pollers */ 775 /* wake up pollers */
776 wake_up_interruptible_all(&dev->read_wait); 776 wake_up_interruptible_all(&dev->read_wait);
777 wake_up_interruptible_all(&dev->write_wait); 777 wake_up_interruptible_all(&dev->write_wait);
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 006cf13b2199..9d4c52a7ebe0 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -179,7 +179,6 @@ static const struct usb_device_id tower_table[] = {
179}; 179};
180 180
181MODULE_DEVICE_TABLE (usb, tower_table); 181MODULE_DEVICE_TABLE (usb, tower_table);
182static DEFINE_MUTEX(open_disc_mutex);
183 182
184#define LEGO_USB_TOWER_MINOR_BASE 160 183#define LEGO_USB_TOWER_MINOR_BASE 160
185 184
@@ -191,6 +190,7 @@ struct lego_usb_tower {
191 unsigned char minor; /* the starting minor number for this device */ 190 unsigned char minor; /* the starting minor number for this device */
192 191
193 int open_count; /* number of times this port has been opened */ 192 int open_count; /* number of times this port has been opened */
193 unsigned long disconnected:1;
194 194
195 char* read_buffer; 195 char* read_buffer;
196 size_t read_buffer_length; /* this much came in */ 196 size_t read_buffer_length; /* this much came in */
@@ -290,14 +290,13 @@ static inline void lego_usb_tower_debug_data(struct device *dev,
290 */ 290 */
291static inline void tower_delete (struct lego_usb_tower *dev) 291static inline void tower_delete (struct lego_usb_tower *dev)
292{ 292{
293 tower_abort_transfers (dev);
294
295 /* free data structures */ 293 /* free data structures */
296 usb_free_urb(dev->interrupt_in_urb); 294 usb_free_urb(dev->interrupt_in_urb);
297 usb_free_urb(dev->interrupt_out_urb); 295 usb_free_urb(dev->interrupt_out_urb);
298 kfree (dev->read_buffer); 296 kfree (dev->read_buffer);
299 kfree (dev->interrupt_in_buffer); 297 kfree (dev->interrupt_in_buffer);
300 kfree (dev->interrupt_out_buffer); 298 kfree (dev->interrupt_out_buffer);
299 usb_put_dev(dev->udev);
301 kfree (dev); 300 kfree (dev);
302} 301}
303 302
@@ -332,18 +331,14 @@ static int tower_open (struct inode *inode, struct file *file)
332 goto exit; 331 goto exit;
333 } 332 }
334 333
335 mutex_lock(&open_disc_mutex);
336 dev = usb_get_intfdata(interface); 334 dev = usb_get_intfdata(interface);
337
338 if (!dev) { 335 if (!dev) {
339 mutex_unlock(&open_disc_mutex);
340 retval = -ENODEV; 336 retval = -ENODEV;
341 goto exit; 337 goto exit;
342 } 338 }
343 339
344 /* lock this device */ 340 /* lock this device */
345 if (mutex_lock_interruptible(&dev->lock)) { 341 if (mutex_lock_interruptible(&dev->lock)) {
346 mutex_unlock(&open_disc_mutex);
347 retval = -ERESTARTSYS; 342 retval = -ERESTARTSYS;
348 goto exit; 343 goto exit;
349 } 344 }
@@ -351,12 +346,9 @@ static int tower_open (struct inode *inode, struct file *file)
351 346
352 /* allow opening only once */ 347 /* allow opening only once */
353 if (dev->open_count) { 348 if (dev->open_count) {
354 mutex_unlock(&open_disc_mutex);
355 retval = -EBUSY; 349 retval = -EBUSY;
356 goto unlock_exit; 350 goto unlock_exit;
357 } 351 }
358 dev->open_count = 1;
359 mutex_unlock(&open_disc_mutex);
360 352
361 /* reset the tower */ 353 /* reset the tower */
362 result = usb_control_msg (dev->udev, 354 result = usb_control_msg (dev->udev,
@@ -396,13 +388,14 @@ static int tower_open (struct inode *inode, struct file *file)
396 dev_err(&dev->udev->dev, 388 dev_err(&dev->udev->dev,
397 "Couldn't submit interrupt_in_urb %d\n", retval); 389 "Couldn't submit interrupt_in_urb %d\n", retval);
398 dev->interrupt_in_running = 0; 390 dev->interrupt_in_running = 0;
399 dev->open_count = 0;
400 goto unlock_exit; 391 goto unlock_exit;
401 } 392 }
402 393
403 /* save device in the file's private structure */ 394 /* save device in the file's private structure */
404 file->private_data = dev; 395 file->private_data = dev;
405 396
397 dev->open_count = 1;
398
406unlock_exit: 399unlock_exit:
407 mutex_unlock(&dev->lock); 400 mutex_unlock(&dev->lock);
408 401
@@ -423,10 +416,9 @@ static int tower_release (struct inode *inode, struct file *file)
423 416
424 if (dev == NULL) { 417 if (dev == NULL) {
425 retval = -ENODEV; 418 retval = -ENODEV;
426 goto exit_nolock; 419 goto exit;
427 } 420 }
428 421
429 mutex_lock(&open_disc_mutex);
430 if (mutex_lock_interruptible(&dev->lock)) { 422 if (mutex_lock_interruptible(&dev->lock)) {
431 retval = -ERESTARTSYS; 423 retval = -ERESTARTSYS;
432 goto exit; 424 goto exit;
@@ -438,7 +430,8 @@ static int tower_release (struct inode *inode, struct file *file)
438 retval = -ENODEV; 430 retval = -ENODEV;
439 goto unlock_exit; 431 goto unlock_exit;
440 } 432 }
441 if (dev->udev == NULL) { 433
434 if (dev->disconnected) {
442 /* the device was unplugged before the file was released */ 435 /* the device was unplugged before the file was released */
443 436
444 /* unlock here as tower_delete frees dev */ 437 /* unlock here as tower_delete frees dev */
@@ -456,10 +449,7 @@ static int tower_release (struct inode *inode, struct file *file)
456 449
457unlock_exit: 450unlock_exit:
458 mutex_unlock(&dev->lock); 451 mutex_unlock(&dev->lock);
459
460exit: 452exit:
461 mutex_unlock(&open_disc_mutex);
462exit_nolock:
463 return retval; 453 return retval;
464} 454}
465 455
@@ -477,10 +467,9 @@ static void tower_abort_transfers (struct lego_usb_tower *dev)
477 if (dev->interrupt_in_running) { 467 if (dev->interrupt_in_running) {
478 dev->interrupt_in_running = 0; 468 dev->interrupt_in_running = 0;
479 mb(); 469 mb();
480 if (dev->udev) 470 usb_kill_urb(dev->interrupt_in_urb);
481 usb_kill_urb (dev->interrupt_in_urb);
482 } 471 }
483 if (dev->interrupt_out_busy && dev->udev) 472 if (dev->interrupt_out_busy)
484 usb_kill_urb(dev->interrupt_out_urb); 473 usb_kill_urb(dev->interrupt_out_urb);
485} 474}
486 475
@@ -516,7 +505,7 @@ static __poll_t tower_poll (struct file *file, poll_table *wait)
516 505
517 dev = file->private_data; 506 dev = file->private_data;
518 507
519 if (!dev->udev) 508 if (dev->disconnected)
520 return EPOLLERR | EPOLLHUP; 509 return EPOLLERR | EPOLLHUP;
521 510
522 poll_wait(file, &dev->read_wait, wait); 511 poll_wait(file, &dev->read_wait, wait);
@@ -563,7 +552,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,
563 } 552 }
564 553
565 /* verify that the device wasn't unplugged */ 554 /* verify that the device wasn't unplugged */
566 if (dev->udev == NULL) { 555 if (dev->disconnected) {
567 retval = -ENODEV; 556 retval = -ENODEV;
568 pr_err("No device or device unplugged %d\n", retval); 557 pr_err("No device or device unplugged %d\n", retval);
569 goto unlock_exit; 558 goto unlock_exit;
@@ -649,7 +638,7 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
649 } 638 }
650 639
651 /* verify that the device wasn't unplugged */ 640 /* verify that the device wasn't unplugged */
652 if (dev->udev == NULL) { 641 if (dev->disconnected) {
653 retval = -ENODEV; 642 retval = -ENODEV;
654 pr_err("No device or device unplugged %d\n", retval); 643 pr_err("No device or device unplugged %d\n", retval);
655 goto unlock_exit; 644 goto unlock_exit;
@@ -759,7 +748,7 @@ static void tower_interrupt_in_callback (struct urb *urb)
759 748
760resubmit: 749resubmit:
761 /* resubmit if we're still running */ 750 /* resubmit if we're still running */
762 if (dev->interrupt_in_running && dev->udev) { 751 if (dev->interrupt_in_running) {
763 retval = usb_submit_urb (dev->interrupt_in_urb, GFP_ATOMIC); 752 retval = usb_submit_urb (dev->interrupt_in_urb, GFP_ATOMIC);
764 if (retval) 753 if (retval)
765 dev_err(&dev->udev->dev, 754 dev_err(&dev->udev->dev,
@@ -822,8 +811,9 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
822 811
823 mutex_init(&dev->lock); 812 mutex_init(&dev->lock);
824 813
825 dev->udev = udev; 814 dev->udev = usb_get_dev(udev);
826 dev->open_count = 0; 815 dev->open_count = 0;
816 dev->disconnected = 0;
827 817
828 dev->read_buffer = NULL; 818 dev->read_buffer = NULL;
829 dev->read_buffer_length = 0; 819 dev->read_buffer_length = 0;
@@ -891,8 +881,10 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
891 get_version_reply, 881 get_version_reply,
892 sizeof(*get_version_reply), 882 sizeof(*get_version_reply),
893 1000); 883 1000);
894 if (result < 0) { 884 if (result < sizeof(*get_version_reply)) {
895 dev_err(idev, "LEGO USB Tower get version control request failed\n"); 885 if (result >= 0)
886 result = -EIO;
887 dev_err(idev, "get version request failed: %d\n", result);
896 retval = result; 888 retval = result;
897 goto error; 889 goto error;
898 } 890 }
@@ -910,7 +902,6 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
910 if (retval) { 902 if (retval) {
911 /* something prevented us from registering this driver */ 903 /* something prevented us from registering this driver */
912 dev_err(idev, "Not able to get a minor for this device.\n"); 904 dev_err(idev, "Not able to get a minor for this device.\n");
913 usb_set_intfdata (interface, NULL);
914 goto error; 905 goto error;
915 } 906 }
916 dev->minor = interface->minor; 907 dev->minor = interface->minor;
@@ -942,23 +933,24 @@ static void tower_disconnect (struct usb_interface *interface)
942 int minor; 933 int minor;
943 934
944 dev = usb_get_intfdata (interface); 935 dev = usb_get_intfdata (interface);
945 mutex_lock(&open_disc_mutex);
946 usb_set_intfdata (interface, NULL);
947 936
948 minor = dev->minor; 937 minor = dev->minor;
949 938
950 /* give back our minor */ 939 /* give back our minor and prevent further open() */
951 usb_deregister_dev (interface, &tower_class); 940 usb_deregister_dev (interface, &tower_class);
952 941
942 /* stop I/O */
943 usb_poison_urb(dev->interrupt_in_urb);
944 usb_poison_urb(dev->interrupt_out_urb);
945
953 mutex_lock(&dev->lock); 946 mutex_lock(&dev->lock);
954 mutex_unlock(&open_disc_mutex);
955 947
956 /* if the device is not opened, then we clean up right now */ 948 /* if the device is not opened, then we clean up right now */
957 if (!dev->open_count) { 949 if (!dev->open_count) {
958 mutex_unlock(&dev->lock); 950 mutex_unlock(&dev->lock);
959 tower_delete (dev); 951 tower_delete (dev);
960 } else { 952 } else {
961 dev->udev = NULL; 953 dev->disconnected = 1;
962 /* wake up pollers */ 954 /* wake up pollers */
963 wake_up_interruptible_all(&dev->read_wait); 955 wake_up_interruptible_all(&dev->read_wait);
964 wake_up_interruptible_all(&dev->write_wait); 956 wake_up_interruptible_all(&dev->write_wait);
diff --git a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c
deleted file mode 100644
index 30cae5e1954d..000000000000
--- a/drivers/usb/misc/rio500.c
+++ /dev/null
@@ -1,554 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* -*- linux-c -*- */
3
4/*
5 * Driver for USB Rio 500
6 *
7 * Cesar Miquel (miquel@df.uba.ar)
8 *
9 * based on hp_scanner.c by David E. Nelson (dnelson@jump.net)
10 *
11 * Based upon mouse.c (Brad Keryan) and printer.c (Michael Gee).
12 *
13 * Changelog:
14 * 30/05/2003 replaced lock/unlock kernel with up/down
15 * Daniele Bellucci bellucda@tiscali.it
16 * */
17
18#include <linux/module.h>
19#include <linux/kernel.h>
20#include <linux/signal.h>
21#include <linux/sched/signal.h>
22#include <linux/mutex.h>
23#include <linux/errno.h>
24#include <linux/random.h>
25#include <linux/poll.h>
26#include <linux/slab.h>
27#include <linux/spinlock.h>
28#include <linux/usb.h>
29#include <linux/wait.h>
30
31#include "rio500_usb.h"
32
33#define DRIVER_AUTHOR "Cesar Miquel <miquel@df.uba.ar>"
34#define DRIVER_DESC "USB Rio 500 driver"
35
36#define RIO_MINOR 64
37
38/* stall/wait timeout for rio */
39#define NAK_TIMEOUT (HZ)
40
41#define IBUF_SIZE 0x1000
42
43/* Size of the rio buffer */
44#define OBUF_SIZE 0x10000
45
46struct rio_usb_data {
47 struct usb_device *rio_dev; /* init: probe_rio */
48 unsigned int ifnum; /* Interface number of the USB device */
49 int isopen; /* nz if open */
50 int present; /* Device is present on the bus */
51 char *obuf, *ibuf; /* transfer buffers */
52 char bulk_in_ep, bulk_out_ep; /* Endpoint assignments */
53 wait_queue_head_t wait_q; /* for timeouts */
54};
55
56static DEFINE_MUTEX(rio500_mutex);
57static struct rio_usb_data rio_instance;
58
59static int open_rio(struct inode *inode, struct file *file)
60{
61 struct rio_usb_data *rio = &rio_instance;
62
63 /* against disconnect() */
64 mutex_lock(&rio500_mutex);
65
66 if (rio->isopen || !rio->present) {
67 mutex_unlock(&rio500_mutex);
68 return -EBUSY;
69 }
70 rio->isopen = 1;
71
72 init_waitqueue_head(&rio->wait_q);
73
74
75 dev_info(&rio->rio_dev->dev, "Rio opened.\n");
76 mutex_unlock(&rio500_mutex);
77
78 return 0;
79}
80
81static int close_rio(struct inode *inode, struct file *file)
82{
83 struct rio_usb_data *rio = &rio_instance;
84
85 /* against disconnect() */
86 mutex_lock(&rio500_mutex);
87
88 rio->isopen = 0;
89 if (!rio->present) {
90 /* cleanup has been delayed */
91 kfree(rio->ibuf);
92 kfree(rio->obuf);
93 rio->ibuf = NULL;
94 rio->obuf = NULL;
95 } else {
96 dev_info(&rio->rio_dev->dev, "Rio closed.\n");
97 }
98 mutex_unlock(&rio500_mutex);
99 return 0;
100}
101
102static long ioctl_rio(struct file *file, unsigned int cmd, unsigned long arg)
103{
104 struct RioCommand rio_cmd;
105 struct rio_usb_data *rio = &rio_instance;
106 void __user *data;
107 unsigned char *buffer;
108 int result, requesttype;
109 int retries;
110 int retval=0;
111
112 mutex_lock(&rio500_mutex);
113 /* Sanity check to make sure rio is connected, powered, etc */
114 if (rio->present == 0 || rio->rio_dev == NULL) {
115 retval = -ENODEV;
116 goto err_out;
117 }
118
119 switch (cmd) {
120 case RIO_RECV_COMMAND:
121 data = (void __user *) arg;
122 if (data == NULL)
123 break;
124 if (copy_from_user(&rio_cmd, data, sizeof(struct RioCommand))) {
125 retval = -EFAULT;
126 goto err_out;
127 }
128 if (rio_cmd.length < 0 || rio_cmd.length > PAGE_SIZE) {
129 retval = -EINVAL;
130 goto err_out;
131 }
132 buffer = (unsigned char *) __get_free_page(GFP_KERNEL);
133 if (buffer == NULL) {
134 retval = -ENOMEM;
135 goto err_out;
136 }
137 if (copy_from_user(buffer, rio_cmd.buffer, rio_cmd.length)) {
138 retval = -EFAULT;
139 free_page((unsigned long) buffer);
140 goto err_out;
141 }
142
143 requesttype = rio_cmd.requesttype | USB_DIR_IN |
144 USB_TYPE_VENDOR | USB_RECIP_DEVICE;
145 dev_dbg(&rio->rio_dev->dev,
146 "sending command:reqtype=%0x req=%0x value=%0x index=%0x len=%0x\n",
147 requesttype, rio_cmd.request, rio_cmd.value,
148 rio_cmd.index, rio_cmd.length);
149 /* Send rio control message */
150 retries = 3;
151 while (retries) {
152 result = usb_control_msg(rio->rio_dev,
153 usb_rcvctrlpipe(rio-> rio_dev, 0),
154 rio_cmd.request,
155 requesttype,
156 rio_cmd.value,
157 rio_cmd.index, buffer,
158 rio_cmd.length,
159 jiffies_to_msecs(rio_cmd.timeout));
160 if (result == -ETIMEDOUT)
161 retries--;
162 else if (result < 0) {
163 dev_err(&rio->rio_dev->dev,
164 "Error executing ioctrl. code = %d\n",
165 result);
166 retries = 0;
167 } else {
168 dev_dbg(&rio->rio_dev->dev,
169 "Executed ioctl. Result = %d (data=%02x)\n",
170 result, buffer[0]);
171 if (copy_to_user(rio_cmd.buffer, buffer,
172 rio_cmd.length)) {
173 free_page((unsigned long) buffer);
174 retval = -EFAULT;
175 goto err_out;
176 }
177 retries = 0;
178 }
179
180 /* rio_cmd.buffer contains a raw stream of single byte
181 data which has been returned from rio. Data is
182 interpreted at application level. For data that
183 will be cast to data types longer than 1 byte, data
184 will be little_endian and will potentially need to
185 be swapped at the app level */
186
187 }
188 free_page((unsigned long) buffer);
189 break;
190
191 case RIO_SEND_COMMAND:
192 data = (void __user *) arg;
193 if (data == NULL)
194 break;
195 if (copy_from_user(&rio_cmd, data, sizeof(struct RioCommand))) {
196 retval = -EFAULT;
197 goto err_out;
198 }
199 if (rio_cmd.length < 0 || rio_cmd.length > PAGE_SIZE) {
200 retval = -EINVAL;
201 goto err_out;
202 }
203 buffer = (unsigned char *) __get_free_page(GFP_KERNEL);
204 if (buffer == NULL) {
205 retval = -ENOMEM;
206 goto err_out;
207 }
208 if (copy_from_user(buffer, rio_cmd.buffer, rio_cmd.length)) {
209 free_page((unsigned long)buffer);
210 retval = -EFAULT;
211 goto err_out;
212 }
213
214 requesttype = rio_cmd.requesttype | USB_DIR_OUT |
215 USB_TYPE_VENDOR | USB_RECIP_DEVICE;
216 dev_dbg(&rio->rio_dev->dev,
217 "sending command: reqtype=%0x req=%0x value=%0x index=%0x len=%0x\n",
218 requesttype, rio_cmd.request, rio_cmd.value,
219 rio_cmd.index, rio_cmd.length);
220 /* Send rio control message */
221 retries = 3;
222 while (retries) {
223 result = usb_control_msg(rio->rio_dev,
224 usb_sndctrlpipe(rio-> rio_dev, 0),
225 rio_cmd.request,
226 requesttype,
227 rio_cmd.value,
228 rio_cmd.index, buffer,
229 rio_cmd.length,
230 jiffies_to_msecs(rio_cmd.timeout));
231 if (result == -ETIMEDOUT)
232 retries--;
233 else if (result < 0) {
234 dev_err(&rio->rio_dev->dev,
235 "Error executing ioctrl. code = %d\n",
236 result);
237 retries = 0;
238 } else {
239 dev_dbg(&rio->rio_dev->dev,
240 "Executed ioctl. Result = %d\n", result);
241 retries = 0;
242
243 }
244
245 }
246 free_page((unsigned long) buffer);
247 break;
248
249 default:
250 retval = -ENOTTY;
251 break;
252 }
253
254
255err_out:
256 mutex_unlock(&rio500_mutex);
257 return retval;
258}
259
260static ssize_t
261write_rio(struct file *file, const char __user *buffer,
262 size_t count, loff_t * ppos)
263{
264 DEFINE_WAIT(wait);
265 struct rio_usb_data *rio = &rio_instance;
266
267 unsigned long copy_size;
268 unsigned long bytes_written = 0;
269 unsigned int partial;
270
271 int result = 0;
272 int maxretry;
273 int errn = 0;
274 int intr;
275
276 intr = mutex_lock_interruptible(&rio500_mutex);
277 if (intr)
278 return -EINTR;
279 /* Sanity check to make sure rio is connected, powered, etc */
280 if (rio->present == 0 || rio->rio_dev == NULL) {
281 mutex_unlock(&rio500_mutex);
282 return -ENODEV;
283 }
284
285
286
287 do {
288 unsigned long thistime;
289 char *obuf = rio->obuf;
290
291 thistime = copy_size =
292 (count >= OBUF_SIZE) ? OBUF_SIZE : count;
293 if (copy_from_user(rio->obuf, buffer, copy_size)) {
294 errn = -EFAULT;
295 goto error;
296 }
297 maxretry = 5;
298 while (thistime) {
299 if (!rio->rio_dev) {
300 errn = -ENODEV;
301 goto error;
302 }
303 if (signal_pending(current)) {
304 mutex_unlock(&rio500_mutex);
305 return bytes_written ? bytes_written : -EINTR;
306 }
307
308 result = usb_bulk_msg(rio->rio_dev,
309 usb_sndbulkpipe(rio->rio_dev, 2),
310 obuf, thistime, &partial, 5000);
311
312 dev_dbg(&rio->rio_dev->dev,
313 "write stats: result:%d thistime:%lu partial:%u\n",
314 result, thistime, partial);
315
316 if (result == -ETIMEDOUT) { /* NAK - so hold for a while */
317 if (!maxretry--) {
318 errn = -ETIME;
319 goto error;
320 }
321 prepare_to_wait(&rio->wait_q, &wait, TASK_INTERRUPTIBLE);
322 schedule_timeout(NAK_TIMEOUT);
323 finish_wait(&rio->wait_q, &wait);
324 continue;
325 } else if (!result && partial) {
326 obuf += partial;
327 thistime -= partial;
328 } else
329 break;
330 }
331 if (result) {
332 dev_err(&rio->rio_dev->dev, "Write Whoops - %x\n",
333 result);
334 errn = -EIO;
335 goto error;
336 }
337 bytes_written += copy_size;
338 count -= copy_size;
339 buffer += copy_size;
340 } while (count > 0);
341
342 mutex_unlock(&rio500_mutex);
343
344 return bytes_written ? bytes_written : -EIO;
345
346error:
347 mutex_unlock(&rio500_mutex);
348 return errn;
349}
350
351static ssize_t
352read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
353{
354 DEFINE_WAIT(wait);
355 struct rio_usb_data *rio = &rio_instance;
356 ssize_t read_count;
357 unsigned int partial;
358 int this_read;
359 int result;
360 int maxretry = 10;
361 char *ibuf;
362 int intr;
363
364 intr = mutex_lock_interruptible(&rio500_mutex);
365 if (intr)
366 return -EINTR;
367 /* Sanity check to make sure rio is connected, powered, etc */
368 if (rio->present == 0 || rio->rio_dev == NULL) {
369 mutex_unlock(&rio500_mutex);
370 return -ENODEV;
371 }
372
373 ibuf = rio->ibuf;
374
375 read_count = 0;
376
377
378 while (count > 0) {
379 if (signal_pending(current)) {
380 mutex_unlock(&rio500_mutex);
381 return read_count ? read_count : -EINTR;
382 }
383 if (!rio->rio_dev) {
384 mutex_unlock(&rio500_mutex);
385 return -ENODEV;
386 }
387 this_read = (count >= IBUF_SIZE) ? IBUF_SIZE : count;
388
389 result = usb_bulk_msg(rio->rio_dev,
390 usb_rcvbulkpipe(rio->rio_dev, 1),
391 ibuf, this_read, &partial,
392 8000);
393
394 dev_dbg(&rio->rio_dev->dev,
395 "read stats: result:%d this_read:%u partial:%u\n",
396 result, this_read, partial);
397
398 if (partial) {
399 count = this_read = partial;
400 } else if (result == -ETIMEDOUT || result == 15) { /* FIXME: 15 ??? */
401 if (!maxretry--) {
402 mutex_unlock(&rio500_mutex);
403 dev_err(&rio->rio_dev->dev,
404 "read_rio: maxretry timeout\n");
405 return -ETIME;
406 }
407 prepare_to_wait(&rio->wait_q, &wait, TASK_INTERRUPTIBLE);
408 schedule_timeout(NAK_TIMEOUT);
409 finish_wait(&rio->wait_q, &wait);
410 continue;
411 } else if (result != -EREMOTEIO) {
412 mutex_unlock(&rio500_mutex);
413 dev_err(&rio->rio_dev->dev,
414 "Read Whoops - result:%d partial:%u this_read:%u\n",
415 result, partial, this_read);
416 return -EIO;
417 } else {
418 mutex_unlock(&rio500_mutex);
419 return (0);
420 }
421
422 if (this_read) {
423 if (copy_to_user(buffer, ibuf, this_read)) {
424 mutex_unlock(&rio500_mutex);
425 return -EFAULT;
426 }
427 count -= this_read;
428 read_count += this_read;
429 buffer += this_read;
430 }
431 }
432 mutex_unlock(&rio500_mutex);
433 return read_count;
434}
435
436static const struct file_operations usb_rio_fops = {
437 .owner = THIS_MODULE,
438 .read = read_rio,
439 .write = write_rio,
440 .unlocked_ioctl = ioctl_rio,
441 .open = open_rio,
442 .release = close_rio,
443 .llseek = noop_llseek,
444};
445
446static struct usb_class_driver usb_rio_class = {
447 .name = "rio500%d",
448 .fops = &usb_rio_fops,
449 .minor_base = RIO_MINOR,
450};
451
452static int probe_rio(struct usb_interface *intf,
453 const struct usb_device_id *id)
454{
455 struct usb_device *dev = interface_to_usbdev(intf);
456 struct rio_usb_data *rio = &rio_instance;
457 int retval = -ENOMEM;
458 char *ibuf, *obuf;
459
460 if (rio->present) {
461 dev_info(&intf->dev, "Second USB Rio at address %d refused\n", dev->devnum);
462 return -EBUSY;
463 }
464 dev_info(&intf->dev, "USB Rio found at address %d\n", dev->devnum);
465
466 obuf = kmalloc(OBUF_SIZE, GFP_KERNEL);
467 if (!obuf) {
468 dev_err(&dev->dev,
469 "probe_rio: Not enough memory for the output buffer\n");
470 goto err_obuf;
471 }
472 dev_dbg(&intf->dev, "obuf address: %p\n", obuf);
473
474 ibuf = kmalloc(IBUF_SIZE, GFP_KERNEL);
475 if (!ibuf) {
476 dev_err(&dev->dev,
477 "probe_rio: Not enough memory for the input buffer\n");
478 goto err_ibuf;
479 }
480 dev_dbg(&intf->dev, "ibuf address: %p\n", ibuf);
481
482 mutex_lock(&rio500_mutex);
483 rio->rio_dev = dev;
484 rio->ibuf = ibuf;
485 rio->obuf = obuf;
486 rio->present = 1;
487 mutex_unlock(&rio500_mutex);
488
489 retval = usb_register_dev(intf, &usb_rio_class);
490 if (retval) {
491 dev_err(&dev->dev,
492 "Not able to get a minor for this device.\n");
493 goto err_register;
494 }
495
496 usb_set_intfdata(intf, rio);
497 return retval;
498
499 err_register:
500 mutex_lock(&rio500_mutex);
501 rio->present = 0;
502 mutex_unlock(&rio500_mutex);
503 err_ibuf:
504 kfree(obuf);
505 err_obuf:
506 return retval;
507}
508
509static void disconnect_rio(struct usb_interface *intf)
510{
511 struct rio_usb_data *rio = usb_get_intfdata (intf);
512
513 usb_set_intfdata (intf, NULL);
514 if (rio) {
515 usb_deregister_dev(intf, &usb_rio_class);
516
517 mutex_lock(&rio500_mutex);
518 if (rio->isopen) {
519 rio->isopen = 0;
520 /* better let it finish - the release will do whats needed */
521 rio->rio_dev = NULL;
522 mutex_unlock(&rio500_mutex);
523 return;
524 }
525 kfree(rio->ibuf);
526 kfree(rio->obuf);
527
528 dev_info(&intf->dev, "USB Rio disconnected.\n");
529
530 rio->present = 0;
531 mutex_unlock(&rio500_mutex);
532 }
533}
534
535static const struct usb_device_id rio_table[] = {
536 { USB_DEVICE(0x0841, 1) }, /* Rio 500 */
537 { } /* Terminating entry */
538};
539
540MODULE_DEVICE_TABLE (usb, rio_table);
541
542static struct usb_driver rio_driver = {
543 .name = "rio500",
544 .probe = probe_rio,
545 .disconnect = disconnect_rio,
546 .id_table = rio_table,
547};
548
549module_usb_driver(rio_driver);
550
551MODULE_AUTHOR( DRIVER_AUTHOR );
552MODULE_DESCRIPTION( DRIVER_DESC );
553MODULE_LICENSE("GPL");
554
diff --git a/drivers/usb/misc/rio500_usb.h b/drivers/usb/misc/rio500_usb.h
deleted file mode 100644
index 6db7a5863496..000000000000
--- a/drivers/usb/misc/rio500_usb.h
+++ /dev/null
@@ -1,20 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* ----------------------------------------------------------------------
3 Copyright (C) 2000 Cesar Miquel (miquel@df.uba.ar)
4 ---------------------------------------------------------------------- */
5
6#define RIO_SEND_COMMAND 0x1
7#define RIO_RECV_COMMAND 0x2
8
9#define RIO_DIR_OUT 0x0
10#define RIO_DIR_IN 0x1
11
12struct RioCommand {
13 short length;
14 int request;
15 int requesttype;
16 int value;
17 int index;
18 void __user *buffer;
19 int timeout;
20};
diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c
index 9ba4a4e68d91..61e9e987fe4a 100644
--- a/drivers/usb/misc/usblcd.c
+++ b/drivers/usb/misc/usblcd.c
@@ -18,6 +18,7 @@
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/errno.h> 19#include <linux/errno.h>
20#include <linux/mutex.h> 20#include <linux/mutex.h>
21#include <linux/rwsem.h>
21#include <linux/uaccess.h> 22#include <linux/uaccess.h>
22#include <linux/usb.h> 23#include <linux/usb.h>
23 24
@@ -29,16 +30,12 @@
29#define IOCTL_GET_DRV_VERSION 2 30#define IOCTL_GET_DRV_VERSION 2
30 31
31 32
32static DEFINE_MUTEX(lcd_mutex);
33static const struct usb_device_id id_table[] = { 33static const struct usb_device_id id_table[] = {
34 { .idVendor = 0x10D2, .match_flags = USB_DEVICE_ID_MATCH_VENDOR, }, 34 { .idVendor = 0x10D2, .match_flags = USB_DEVICE_ID_MATCH_VENDOR, },
35 { }, 35 { },
36}; 36};
37MODULE_DEVICE_TABLE(usb, id_table); 37MODULE_DEVICE_TABLE(usb, id_table);
38 38
39static DEFINE_MUTEX(open_disc_mutex);
40
41
42struct usb_lcd { 39struct usb_lcd {
43 struct usb_device *udev; /* init: probe_lcd */ 40 struct usb_device *udev; /* init: probe_lcd */
44 struct usb_interface *interface; /* the interface for 41 struct usb_interface *interface; /* the interface for
@@ -57,6 +54,8 @@ struct usb_lcd {
57 using up all RAM */ 54 using up all RAM */
58 struct usb_anchor submitted; /* URBs to wait for 55 struct usb_anchor submitted; /* URBs to wait for
59 before suspend */ 56 before suspend */
57 struct rw_semaphore io_rwsem;
58 unsigned long disconnected:1;
60}; 59};
61#define to_lcd_dev(d) container_of(d, struct usb_lcd, kref) 60#define to_lcd_dev(d) container_of(d, struct usb_lcd, kref)
62 61
@@ -81,40 +80,29 @@ static int lcd_open(struct inode *inode, struct file *file)
81 struct usb_interface *interface; 80 struct usb_interface *interface;
82 int subminor, r; 81 int subminor, r;
83 82
84 mutex_lock(&lcd_mutex);
85 subminor = iminor(inode); 83 subminor = iminor(inode);
86 84
87 interface = usb_find_interface(&lcd_driver, subminor); 85 interface = usb_find_interface(&lcd_driver, subminor);
88 if (!interface) { 86 if (!interface) {
89 mutex_unlock(&lcd_mutex); 87 pr_err("USBLCD: %s - error, can't find device for minor %d\n",
90 printk(KERN_ERR "USBLCD: %s - error, can't find device for minor %d\n",
91 __func__, subminor); 88 __func__, subminor);
92 return -ENODEV; 89 return -ENODEV;
93 } 90 }
94 91
95 mutex_lock(&open_disc_mutex);
96 dev = usb_get_intfdata(interface); 92 dev = usb_get_intfdata(interface);
97 if (!dev) {
98 mutex_unlock(&open_disc_mutex);
99 mutex_unlock(&lcd_mutex);
100 return -ENODEV;
101 }
102 93
103 /* increment our usage count for the device */ 94 /* increment our usage count for the device */
104 kref_get(&dev->kref); 95 kref_get(&dev->kref);
105 mutex_unlock(&open_disc_mutex);
106 96
107 /* grab a power reference */ 97 /* grab a power reference */
108 r = usb_autopm_get_interface(interface); 98 r = usb_autopm_get_interface(interface);
109 if (r < 0) { 99 if (r < 0) {
110 kref_put(&dev->kref, lcd_delete); 100 kref_put(&dev->kref, lcd_delete);
111 mutex_unlock(&lcd_mutex);
112 return r; 101 return r;
113 } 102 }
114 103
115 /* save our object in the file's private structure */ 104 /* save our object in the file's private structure */
116 file->private_data = dev; 105 file->private_data = dev;
117 mutex_unlock(&lcd_mutex);
118 106
119 return 0; 107 return 0;
120} 108}
@@ -142,6 +130,13 @@ static ssize_t lcd_read(struct file *file, char __user * buffer,
142 130
143 dev = file->private_data; 131 dev = file->private_data;
144 132
133 down_read(&dev->io_rwsem);
134
135 if (dev->disconnected) {
136 retval = -ENODEV;
137 goto out_up_io;
138 }
139
145 /* do a blocking bulk read to get data from the device */ 140 /* do a blocking bulk read to get data from the device */
146 retval = usb_bulk_msg(dev->udev, 141 retval = usb_bulk_msg(dev->udev,
147 usb_rcvbulkpipe(dev->udev, 142 usb_rcvbulkpipe(dev->udev,
@@ -158,6 +153,9 @@ static ssize_t lcd_read(struct file *file, char __user * buffer,
158 retval = bytes_read; 153 retval = bytes_read;
159 } 154 }
160 155
156out_up_io:
157 up_read(&dev->io_rwsem);
158
161 return retval; 159 return retval;
162} 160}
163 161
@@ -173,14 +171,12 @@ static long lcd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
173 171
174 switch (cmd) { 172 switch (cmd) {
175 case IOCTL_GET_HARD_VERSION: 173 case IOCTL_GET_HARD_VERSION:
176 mutex_lock(&lcd_mutex);
177 bcdDevice = le16_to_cpu((dev->udev)->descriptor.bcdDevice); 174 bcdDevice = le16_to_cpu((dev->udev)->descriptor.bcdDevice);
178 sprintf(buf, "%1d%1d.%1d%1d", 175 sprintf(buf, "%1d%1d.%1d%1d",
179 (bcdDevice & 0xF000)>>12, 176 (bcdDevice & 0xF000)>>12,
180 (bcdDevice & 0xF00)>>8, 177 (bcdDevice & 0xF00)>>8,
181 (bcdDevice & 0xF0)>>4, 178 (bcdDevice & 0xF0)>>4,
182 (bcdDevice & 0xF)); 179 (bcdDevice & 0xF));
183 mutex_unlock(&lcd_mutex);
184 if (copy_to_user((void __user *)arg, buf, strlen(buf)) != 0) 180 if (copy_to_user((void __user *)arg, buf, strlen(buf)) != 0)
185 return -EFAULT; 181 return -EFAULT;
186 break; 182 break;
@@ -237,11 +233,18 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer,
237 if (r < 0) 233 if (r < 0)
238 return -EINTR; 234 return -EINTR;
239 235
236 down_read(&dev->io_rwsem);
237
238 if (dev->disconnected) {
239 retval = -ENODEV;
240 goto err_up_io;
241 }
242
240 /* create a urb, and a buffer for it, and copy the data to the urb */ 243 /* create a urb, and a buffer for it, and copy the data to the urb */
241 urb = usb_alloc_urb(0, GFP_KERNEL); 244 urb = usb_alloc_urb(0, GFP_KERNEL);
242 if (!urb) { 245 if (!urb) {
243 retval = -ENOMEM; 246 retval = -ENOMEM;
244 goto err_no_buf; 247 goto err_up_io;
245 } 248 }
246 249
247 buf = usb_alloc_coherent(dev->udev, count, GFP_KERNEL, 250 buf = usb_alloc_coherent(dev->udev, count, GFP_KERNEL,
@@ -278,6 +281,7 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer,
278 the USB core will eventually free it entirely */ 281 the USB core will eventually free it entirely */
279 usb_free_urb(urb); 282 usb_free_urb(urb);
280 283
284 up_read(&dev->io_rwsem);
281exit: 285exit:
282 return count; 286 return count;
283error_unanchor: 287error_unanchor:
@@ -285,7 +289,8 @@ error_unanchor:
285error: 289error:
286 usb_free_coherent(dev->udev, count, buf, urb->transfer_dma); 290 usb_free_coherent(dev->udev, count, buf, urb->transfer_dma);
287 usb_free_urb(urb); 291 usb_free_urb(urb);
288err_no_buf: 292err_up_io:
293 up_read(&dev->io_rwsem);
289 up(&dev->limit_sem); 294 up(&dev->limit_sem);
290 return retval; 295 return retval;
291} 296}
@@ -325,6 +330,7 @@ static int lcd_probe(struct usb_interface *interface,
325 330
326 kref_init(&dev->kref); 331 kref_init(&dev->kref);
327 sema_init(&dev->limit_sem, USB_LCD_CONCURRENT_WRITES); 332 sema_init(&dev->limit_sem, USB_LCD_CONCURRENT_WRITES);
333 init_rwsem(&dev->io_rwsem);
328 init_usb_anchor(&dev->submitted); 334 init_usb_anchor(&dev->submitted);
329 335
330 dev->udev = usb_get_dev(interface_to_usbdev(interface)); 336 dev->udev = usb_get_dev(interface_to_usbdev(interface));
@@ -365,7 +371,6 @@ static int lcd_probe(struct usb_interface *interface,
365 /* something prevented us from registering this driver */ 371 /* something prevented us from registering this driver */
366 dev_err(&interface->dev, 372 dev_err(&interface->dev,
367 "Not able to get a minor for this device.\n"); 373 "Not able to get a minor for this device.\n");
368 usb_set_intfdata(interface, NULL);
369 goto error; 374 goto error;
370 } 375 }
371 376
@@ -411,17 +416,18 @@ static int lcd_resume(struct usb_interface *intf)
411 416
412static void lcd_disconnect(struct usb_interface *interface) 417static void lcd_disconnect(struct usb_interface *interface)
413{ 418{
414 struct usb_lcd *dev; 419 struct usb_lcd *dev = usb_get_intfdata(interface);
415 int minor = interface->minor; 420 int minor = interface->minor;
416 421
417 mutex_lock(&open_disc_mutex);
418 dev = usb_get_intfdata(interface);
419 usb_set_intfdata(interface, NULL);
420 mutex_unlock(&open_disc_mutex);
421
422 /* give back our minor */ 422 /* give back our minor */
423 usb_deregister_dev(interface, &lcd_class); 423 usb_deregister_dev(interface, &lcd_class);
424 424
425 down_write(&dev->io_rwsem);
426 dev->disconnected = 1;
427 up_write(&dev->io_rwsem);
428
429 usb_kill_anchored_urbs(&dev->submitted);
430
425 /* decrement our usage count */ 431 /* decrement our usage count */
426 kref_put(&dev->kref, lcd_delete); 432 kref_put(&dev->kref, lcd_delete);
427 433
diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c
index 6715a128e6c8..be0505b8b5d4 100644
--- a/drivers/usb/misc/yurex.c
+++ b/drivers/usb/misc/yurex.c
@@ -60,6 +60,7 @@ struct usb_yurex {
60 60
61 struct kref kref; 61 struct kref kref;
62 struct mutex io_mutex; 62 struct mutex io_mutex;
63 unsigned long disconnected:1;
63 struct fasync_struct *async_queue; 64 struct fasync_struct *async_queue;
64 wait_queue_head_t waitq; 65 wait_queue_head_t waitq;
65 66
@@ -107,6 +108,7 @@ static void yurex_delete(struct kref *kref)
107 dev->int_buffer, dev->urb->transfer_dma); 108 dev->int_buffer, dev->urb->transfer_dma);
108 usb_free_urb(dev->urb); 109 usb_free_urb(dev->urb);
109 } 110 }
111 usb_put_intf(dev->interface);
110 usb_put_dev(dev->udev); 112 usb_put_dev(dev->udev);
111 kfree(dev); 113 kfree(dev);
112} 114}
@@ -132,6 +134,7 @@ static void yurex_interrupt(struct urb *urb)
132 switch (status) { 134 switch (status) {
133 case 0: /*success*/ 135 case 0: /*success*/
134 break; 136 break;
137 /* The device is terminated or messed up, give up */
135 case -EOVERFLOW: 138 case -EOVERFLOW:
136 dev_err(&dev->interface->dev, 139 dev_err(&dev->interface->dev,
137 "%s - overflow with length %d, actual length is %d\n", 140 "%s - overflow with length %d, actual length is %d\n",
@@ -140,12 +143,13 @@ static void yurex_interrupt(struct urb *urb)
140 case -ENOENT: 143 case -ENOENT:
141 case -ESHUTDOWN: 144 case -ESHUTDOWN:
142 case -EILSEQ: 145 case -EILSEQ:
143 /* The device is terminated, clean up */ 146 case -EPROTO:
147 case -ETIME:
144 return; 148 return;
145 default: 149 default:
146 dev_err(&dev->interface->dev, 150 dev_err(&dev->interface->dev,
147 "%s - unknown status received: %d\n", __func__, status); 151 "%s - unknown status received: %d\n", __func__, status);
148 goto exit; 152 return;
149 } 153 }
150 154
151 /* handle received message */ 155 /* handle received message */
@@ -177,7 +181,6 @@ static void yurex_interrupt(struct urb *urb)
177 break; 181 break;
178 } 182 }
179 183
180exit:
181 retval = usb_submit_urb(dev->urb, GFP_ATOMIC); 184 retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
182 if (retval) { 185 if (retval) {
183 dev_err(&dev->interface->dev, "%s - usb_submit_urb failed: %d\n", 186 dev_err(&dev->interface->dev, "%s - usb_submit_urb failed: %d\n",
@@ -204,7 +207,7 @@ static int yurex_probe(struct usb_interface *interface, const struct usb_device_
204 init_waitqueue_head(&dev->waitq); 207 init_waitqueue_head(&dev->waitq);
205 208
206 dev->udev = usb_get_dev(interface_to_usbdev(interface)); 209 dev->udev = usb_get_dev(interface_to_usbdev(interface));
207 dev->interface = interface; 210 dev->interface = usb_get_intf(interface);
208 211
209 /* set up the endpoint information */ 212 /* set up the endpoint information */
210 iface_desc = interface->cur_altsetting; 213 iface_desc = interface->cur_altsetting;
@@ -315,8 +318,9 @@ static void yurex_disconnect(struct usb_interface *interface)
315 318
316 /* prevent more I/O from starting */ 319 /* prevent more I/O from starting */
317 usb_poison_urb(dev->urb); 320 usb_poison_urb(dev->urb);
321 usb_poison_urb(dev->cntl_urb);
318 mutex_lock(&dev->io_mutex); 322 mutex_lock(&dev->io_mutex);
319 dev->interface = NULL; 323 dev->disconnected = 1;
320 mutex_unlock(&dev->io_mutex); 324 mutex_unlock(&dev->io_mutex);
321 325
322 /* wakeup waiters */ 326 /* wakeup waiters */
@@ -404,7 +408,7 @@ static ssize_t yurex_read(struct file *file, char __user *buffer, size_t count,
404 dev = file->private_data; 408 dev = file->private_data;
405 409
406 mutex_lock(&dev->io_mutex); 410 mutex_lock(&dev->io_mutex);
407 if (!dev->interface) { /* already disconnected */ 411 if (dev->disconnected) { /* already disconnected */
408 mutex_unlock(&dev->io_mutex); 412 mutex_unlock(&dev->io_mutex);
409 return -ENODEV; 413 return -ENODEV;
410 } 414 }
@@ -439,7 +443,7 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
439 goto error; 443 goto error;
440 444
441 mutex_lock(&dev->io_mutex); 445 mutex_lock(&dev->io_mutex);
442 if (!dev->interface) { /* already disconnected */ 446 if (dev->disconnected) { /* already disconnected */
443 mutex_unlock(&dev->io_mutex); 447 mutex_unlock(&dev->io_mutex);
444 retval = -ENODEV; 448 retval = -ENODEV;
445 goto error; 449 goto error;
diff --git a/drivers/usb/renesas_usbhs/common.h b/drivers/usb/renesas_usbhs/common.h
index d1a0a35ecfff..0824099b905e 100644
--- a/drivers/usb/renesas_usbhs/common.h
+++ b/drivers/usb/renesas_usbhs/common.h
@@ -211,6 +211,7 @@ struct usbhs_priv;
211/* DCPCTR */ 211/* DCPCTR */
212#define BSTS (1 << 15) /* Buffer Status */ 212#define BSTS (1 << 15) /* Buffer Status */
213#define SUREQ (1 << 14) /* Sending SETUP Token */ 213#define SUREQ (1 << 14) /* Sending SETUP Token */
214#define INBUFM (1 << 14) /* (PIPEnCTR) Transfer Buffer Monitor */
214#define CSSTS (1 << 12) /* CSSTS Status */ 215#define CSSTS (1 << 12) /* CSSTS Status */
215#define ACLRM (1 << 9) /* Buffer Auto-Clear Mode */ 216#define ACLRM (1 << 9) /* Buffer Auto-Clear Mode */
216#define SQCLR (1 << 8) /* Toggle Bit Clear */ 217#define SQCLR (1 << 8) /* Toggle Bit Clear */
diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c
index 2a01ceb71641..86637cd066cf 100644
--- a/drivers/usb/renesas_usbhs/fifo.c
+++ b/drivers/usb/renesas_usbhs/fifo.c
@@ -89,7 +89,7 @@ static void __usbhsf_pkt_del(struct usbhs_pkt *pkt)
89 list_del_init(&pkt->node); 89 list_del_init(&pkt->node);
90} 90}
91 91
92static struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe) 92struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe)
93{ 93{
94 return list_first_entry_or_null(&pipe->list, struct usbhs_pkt, node); 94 return list_first_entry_or_null(&pipe->list, struct usbhs_pkt, node);
95} 95}
diff --git a/drivers/usb/renesas_usbhs/fifo.h b/drivers/usb/renesas_usbhs/fifo.h
index 88d1816bcda2..c3d3cc35cee0 100644
--- a/drivers/usb/renesas_usbhs/fifo.h
+++ b/drivers/usb/renesas_usbhs/fifo.h
@@ -97,5 +97,6 @@ void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt,
97 void *buf, int len, int zero, int sequence); 97 void *buf, int len, int zero, int sequence);
98struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt); 98struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt);
99void usbhs_pkt_start(struct usbhs_pipe *pipe); 99void usbhs_pkt_start(struct usbhs_pipe *pipe);
100struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe);
100 101
101#endif /* RENESAS_USB_FIFO_H */ 102#endif /* RENESAS_USB_FIFO_H */
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
index 4d571a5205e2..e5ef56991dba 100644
--- a/drivers/usb/renesas_usbhs/mod_gadget.c
+++ b/drivers/usb/renesas_usbhs/mod_gadget.c
@@ -722,8 +722,7 @@ static int __usbhsg_ep_set_halt_wedge(struct usb_ep *ep, int halt, int wedge)
722 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); 722 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
723 struct device *dev = usbhsg_gpriv_to_dev(gpriv); 723 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
724 unsigned long flags; 724 unsigned long flags;
725 725 int ret = 0;
726 usbhsg_pipe_disable(uep);
727 726
728 dev_dbg(dev, "set halt %d (pipe %d)\n", 727 dev_dbg(dev, "set halt %d (pipe %d)\n",
729 halt, usbhs_pipe_number(pipe)); 728 halt, usbhs_pipe_number(pipe));
@@ -731,6 +730,18 @@ static int __usbhsg_ep_set_halt_wedge(struct usb_ep *ep, int halt, int wedge)
731 /******************** spin lock ********************/ 730 /******************** spin lock ********************/
732 usbhs_lock(priv, flags); 731 usbhs_lock(priv, flags);
733 732
733 /*
734 * According to usb_ep_set_halt()'s description, this function should
735 * return -EAGAIN if the IN endpoint has any queue or data. Note
736 * that the usbhs_pipe_is_dir_in() returns false if the pipe is an
737 * IN endpoint in the gadget mode.
738 */
739 if (!usbhs_pipe_is_dir_in(pipe) && (__usbhsf_pkt_get(pipe) ||
740 usbhs_pipe_contains_transmittable_data(pipe))) {
741 ret = -EAGAIN;
742 goto out;
743 }
744
734 if (halt) 745 if (halt)
735 usbhs_pipe_stall(pipe); 746 usbhs_pipe_stall(pipe);
736 else 747 else
@@ -741,10 +752,11 @@ static int __usbhsg_ep_set_halt_wedge(struct usb_ep *ep, int halt, int wedge)
741 else 752 else
742 usbhsg_status_clr(gpriv, USBHSG_STATUS_WEDGE); 753 usbhsg_status_clr(gpriv, USBHSG_STATUS_WEDGE);
743 754
755out:
744 usbhs_unlock(priv, flags); 756 usbhs_unlock(priv, flags);
745 /******************** spin unlock ******************/ 757 /******************** spin unlock ******************/
746 758
747 return 0; 759 return ret;
748} 760}
749 761
750static int usbhsg_ep_set_halt(struct usb_ep *ep, int value) 762static int usbhsg_ep_set_halt(struct usb_ep *ep, int value)
diff --git a/drivers/usb/renesas_usbhs/pipe.c b/drivers/usb/renesas_usbhs/pipe.c
index c4922b96c93b..9e5afdde1adb 100644
--- a/drivers/usb/renesas_usbhs/pipe.c
+++ b/drivers/usb/renesas_usbhs/pipe.c
@@ -277,6 +277,21 @@ int usbhs_pipe_is_accessible(struct usbhs_pipe *pipe)
277 return -EBUSY; 277 return -EBUSY;
278} 278}
279 279
280bool usbhs_pipe_contains_transmittable_data(struct usbhs_pipe *pipe)
281{
282 u16 val;
283
284 /* Do not support for DCP pipe */
285 if (usbhs_pipe_is_dcp(pipe))
286 return false;
287
288 val = usbhsp_pipectrl_get(pipe);
289 if (val & INBUFM)
290 return true;
291
292 return false;
293}
294
280/* 295/*
281 * PID ctrl 296 * PID ctrl
282 */ 297 */
diff --git a/drivers/usb/renesas_usbhs/pipe.h b/drivers/usb/renesas_usbhs/pipe.h
index 3080423e600c..3b130529408b 100644
--- a/drivers/usb/renesas_usbhs/pipe.h
+++ b/drivers/usb/renesas_usbhs/pipe.h
@@ -83,6 +83,7 @@ void usbhs_pipe_clear(struct usbhs_pipe *pipe);
83void usbhs_pipe_clear_without_sequence(struct usbhs_pipe *pipe, 83void usbhs_pipe_clear_without_sequence(struct usbhs_pipe *pipe,
84 int needs_bfre, int bfre_enable); 84 int needs_bfre, int bfre_enable);
85int usbhs_pipe_is_accessible(struct usbhs_pipe *pipe); 85int usbhs_pipe_is_accessible(struct usbhs_pipe *pipe);
86bool usbhs_pipe_contains_transmittable_data(struct usbhs_pipe *pipe);
86void usbhs_pipe_enable(struct usbhs_pipe *pipe); 87void usbhs_pipe_enable(struct usbhs_pipe *pipe);
87void usbhs_pipe_disable(struct usbhs_pipe *pipe); 88void usbhs_pipe_disable(struct usbhs_pipe *pipe);
88void usbhs_pipe_stall(struct usbhs_pipe *pipe); 89void usbhs_pipe_stall(struct usbhs_pipe *pipe);
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index f0688c44b04c..25e81faf4c24 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -1030,6 +1030,9 @@ static const struct usb_device_id id_table_combined[] = {
1030 /* EZPrototypes devices */ 1030 /* EZPrototypes devices */
1031 { USB_DEVICE(EZPROTOTYPES_VID, HJELMSLUND_USB485_ISO_PID) }, 1031 { USB_DEVICE(EZPROTOTYPES_VID, HJELMSLUND_USB485_ISO_PID) },
1032 { USB_DEVICE_INTERFACE_NUMBER(UNJO_VID, UNJO_ISODEBUG_V1_PID, 1) }, 1032 { USB_DEVICE_INTERFACE_NUMBER(UNJO_VID, UNJO_ISODEBUG_V1_PID, 1) },
1033 /* Sienna devices */
1034 { USB_DEVICE(FTDI_VID, FTDI_SIENNA_PID) },
1035 { USB_DEVICE(ECHELON_VID, ECHELON_U20_PID) },
1033 { } /* Terminating entry */ 1036 { } /* Terminating entry */
1034}; 1037};
1035 1038
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index f12d806220b4..22d66217cb41 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -39,6 +39,9 @@
39 39
40#define FTDI_LUMEL_PD12_PID 0x6002 40#define FTDI_LUMEL_PD12_PID 0x6002
41 41
42/* Sienna Serial Interface by Secyourit GmbH */
43#define FTDI_SIENNA_PID 0x8348
44
42/* Cyber Cortex AV by Fabulous Silicon (http://fabuloussilicon.com) */ 45/* Cyber Cortex AV by Fabulous Silicon (http://fabuloussilicon.com) */
43#define CYBER_CORTEX_AV_PID 0x8698 46#define CYBER_CORTEX_AV_PID 0x8698
44 47
@@ -689,6 +692,12 @@
689#define BANDB_ZZ_PROG1_USB_PID 0xBA02 692#define BANDB_ZZ_PROG1_USB_PID 0xBA02
690 693
691/* 694/*
695 * Echelon USB Serial Interface
696 */
697#define ECHELON_VID 0x0920
698#define ECHELON_U20_PID 0x7500
699
700/*
692 * Intrepid Control Systems (http://www.intrepidcs.com/) ValueCAN and NeoVI 701 * Intrepid Control Systems (http://www.intrepidcs.com/) ValueCAN and NeoVI
693 */ 702 */
694#define INTREPID_VID 0x093C 703#define INTREPID_VID 0x093C
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index d34779fe4a8d..e66a59ef43a1 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -1741,8 +1741,8 @@ static struct urb *keyspan_setup_urb(struct usb_serial *serial, int endpoint,
1741 1741
1742 ep_desc = find_ep(serial, endpoint); 1742 ep_desc = find_ep(serial, endpoint);
1743 if (!ep_desc) { 1743 if (!ep_desc) {
1744 /* leak the urb, something's wrong and the callers don't care */ 1744 usb_free_urb(urb);
1745 return urb; 1745 return NULL;
1746 } 1746 }
1747 if (usb_endpoint_xfer_int(ep_desc)) { 1747 if (usb_endpoint_xfer_int(ep_desc)) {
1748 ep_type_name = "INT"; 1748 ep_type_name = "INT";
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 38e920ac7f82..06ab016be0b6 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -419,6 +419,7 @@ static void option_instat_callback(struct urb *urb);
419#define CINTERION_PRODUCT_PH8_AUDIO 0x0083 419#define CINTERION_PRODUCT_PH8_AUDIO 0x0083
420#define CINTERION_PRODUCT_AHXX_2RMNET 0x0084 420#define CINTERION_PRODUCT_AHXX_2RMNET 0x0084
421#define CINTERION_PRODUCT_AHXX_AUDIO 0x0085 421#define CINTERION_PRODUCT_AHXX_AUDIO 0x0085
422#define CINTERION_PRODUCT_CLS8 0x00b0
422 423
423/* Olivetti products */ 424/* Olivetti products */
424#define OLIVETTI_VENDOR_ID 0x0b3c 425#define OLIVETTI_VENDOR_ID 0x0b3c
@@ -1154,6 +1155,14 @@ static const struct usb_device_id option_ids[] = {
1154 .driver_info = NCTRL(0) | RSVD(1) | RSVD(2) | RSVD(3) }, 1155 .driver_info = NCTRL(0) | RSVD(1) | RSVD(2) | RSVD(3) },
1155 { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, TELIT_PRODUCT_LE922_USBCFG5, 0xff), 1156 { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, TELIT_PRODUCT_LE922_USBCFG5, 0xff),
1156 .driver_info = RSVD(0) | RSVD(1) | NCTRL(2) | RSVD(3) }, 1157 .driver_info = RSVD(0) | RSVD(1) | NCTRL(2) | RSVD(3) },
1158 { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1050, 0xff), /* Telit FN980 (rmnet) */
1159 .driver_info = NCTRL(0) | RSVD(1) | RSVD(2) },
1160 { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1051, 0xff), /* Telit FN980 (MBIM) */
1161 .driver_info = NCTRL(0) | RSVD(1) },
1162 { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1052, 0xff), /* Telit FN980 (RNDIS) */
1163 .driver_info = NCTRL(2) | RSVD(3) },
1164 { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1053, 0xff), /* Telit FN980 (ECM) */
1165 .driver_info = NCTRL(0) | RSVD(1) },
1157 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_ME910), 1166 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_ME910),
1158 .driver_info = NCTRL(0) | RSVD(1) | RSVD(3) }, 1167 .driver_info = NCTRL(0) | RSVD(1) | RSVD(3) },
1159 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_ME910_DUAL_MODEM), 1168 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_ME910_DUAL_MODEM),
@@ -1847,6 +1856,8 @@ static const struct usb_device_id option_ids[] = {
1847 .driver_info = RSVD(4) }, 1856 .driver_info = RSVD(4) },
1848 { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_AHXX_2RMNET, 0xff) }, 1857 { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_AHXX_2RMNET, 0xff) },
1849 { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_AHXX_AUDIO, 0xff) }, 1858 { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_AHXX_AUDIO, 0xff) },
1859 { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_CLS8, 0xff),
1860 .driver_info = RSVD(0) | RSVD(4) },
1850 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_HC28_MDM) }, 1861 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_HC28_MDM) },
1851 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_HC28_MDMNET) }, 1862 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_HC28_MDMNET) },
1852 { USB_DEVICE(SIEMENS_VENDOR_ID, CINTERION_PRODUCT_HC25_MDM) }, 1863 { USB_DEVICE(SIEMENS_VENDOR_ID, CINTERION_PRODUCT_HC25_MDM) },
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index a3179fea38c8..8f066bb55d7d 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -314,10 +314,7 @@ static void serial_cleanup(struct tty_struct *tty)
314 serial = port->serial; 314 serial = port->serial;
315 owner = serial->type->driver.owner; 315 owner = serial->type->driver.owner;
316 316
317 mutex_lock(&serial->disc_mutex); 317 usb_autopm_put_interface(serial->interface);
318 if (!serial->disconnected)
319 usb_autopm_put_interface(serial->interface);
320 mutex_unlock(&serial->disc_mutex);
321 318
322 usb_serial_put(serial); 319 usb_serial_put(serial);
323 module_put(owner); 320 module_put(owner);
diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 96562744101c..5f61d9977a15 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -4409,18 +4409,20 @@ static int tcpm_fw_get_caps(struct tcpm_port *port,
4409 /* USB data support is optional */ 4409 /* USB data support is optional */
4410 ret = fwnode_property_read_string(fwnode, "data-role", &cap_str); 4410 ret = fwnode_property_read_string(fwnode, "data-role", &cap_str);
4411 if (ret == 0) { 4411 if (ret == 0) {
4412 port->typec_caps.data = typec_find_port_data_role(cap_str); 4412 ret = typec_find_port_data_role(cap_str);
4413 if (port->typec_caps.data < 0) 4413 if (ret < 0)
4414 return -EINVAL; 4414 return ret;
4415 port->typec_caps.data = ret;
4415 } 4416 }
4416 4417
4417 ret = fwnode_property_read_string(fwnode, "power-role", &cap_str); 4418 ret = fwnode_property_read_string(fwnode, "power-role", &cap_str);
4418 if (ret < 0) 4419 if (ret < 0)
4419 return ret; 4420 return ret;
4420 4421
4421 port->typec_caps.type = typec_find_port_power_role(cap_str); 4422 ret = typec_find_port_power_role(cap_str);
4422 if (port->typec_caps.type < 0) 4423 if (ret < 0)
4423 return -EINVAL; 4424 return ret;
4425 port->typec_caps.type = ret;
4424 port->port_type = port->typec_caps.type; 4426 port->port_type = port->typec_caps.type;
4425 4427
4426 if (port->port_type == TYPEC_PORT_SNK) 4428 if (port->port_type == TYPEC_PORT_SNK)
diff --git a/drivers/usb/typec/ucsi/displayport.c b/drivers/usb/typec/ucsi/displayport.c
index 6c103697c582..d99700cb4dca 100644
--- a/drivers/usb/typec/ucsi/displayport.c
+++ b/drivers/usb/typec/ucsi/displayport.c
@@ -75,6 +75,8 @@ static int ucsi_displayport_enter(struct typec_altmode *alt)
75 75
76 if (cur != 0xff) { 76 if (cur != 0xff) {
77 mutex_unlock(&dp->con->lock); 77 mutex_unlock(&dp->con->lock);
78 if (dp->con->port_altmode[cur] == alt)
79 return 0;
78 return -EBUSY; 80 return -EBUSY;
79 } 81 }
80 82
diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c
index 907e20e1a71e..d772fce51905 100644
--- a/drivers/usb/typec/ucsi/ucsi_ccg.c
+++ b/drivers/usb/typec/ucsi/ucsi_ccg.c
@@ -195,7 +195,6 @@ struct ucsi_ccg {
195 195
196 /* fw build with vendor information */ 196 /* fw build with vendor information */
197 u16 fw_build; 197 u16 fw_build;
198 bool run_isr; /* flag to call ISR routine during resume */
199 struct work_struct pm_work; 198 struct work_struct pm_work;
200}; 199};
201 200
@@ -224,18 +223,6 @@ static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len)
224 if (quirks && quirks->max_read_len) 223 if (quirks && quirks->max_read_len)
225 max_read_len = quirks->max_read_len; 224 max_read_len = quirks->max_read_len;
226 225
227 if (uc->fw_build == CCG_FW_BUILD_NVIDIA &&
228 uc->fw_version <= CCG_OLD_FW_VERSION) {
229 mutex_lock(&uc->lock);
230 /*
231 * Do not schedule pm_work to run ISR in
232 * ucsi_ccg_runtime_resume() after pm_runtime_get_sync()
233 * since we are already in ISR path.
234 */
235 uc->run_isr = false;
236 mutex_unlock(&uc->lock);
237 }
238
239 pm_runtime_get_sync(uc->dev); 226 pm_runtime_get_sync(uc->dev);
240 while (rem_len > 0) { 227 while (rem_len > 0) {
241 msgs[1].buf = &data[len - rem_len]; 228 msgs[1].buf = &data[len - rem_len];
@@ -278,18 +265,6 @@ static int ccg_write(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len)
278 msgs[0].len = len + sizeof(rab); 265 msgs[0].len = len + sizeof(rab);
279 msgs[0].buf = buf; 266 msgs[0].buf = buf;
280 267
281 if (uc->fw_build == CCG_FW_BUILD_NVIDIA &&
282 uc->fw_version <= CCG_OLD_FW_VERSION) {
283 mutex_lock(&uc->lock);
284 /*
285 * Do not schedule pm_work to run ISR in
286 * ucsi_ccg_runtime_resume() after pm_runtime_get_sync()
287 * since we are already in ISR path.
288 */
289 uc->run_isr = false;
290 mutex_unlock(&uc->lock);
291 }
292
293 pm_runtime_get_sync(uc->dev); 268 pm_runtime_get_sync(uc->dev);
294 status = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 269 status = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
295 if (status < 0) { 270 if (status < 0) {
@@ -1130,7 +1105,6 @@ static int ucsi_ccg_probe(struct i2c_client *client,
1130 uc->ppm.sync = ucsi_ccg_sync; 1105 uc->ppm.sync = ucsi_ccg_sync;
1131 uc->dev = dev; 1106 uc->dev = dev;
1132 uc->client = client; 1107 uc->client = client;
1133 uc->run_isr = true;
1134 mutex_init(&uc->lock); 1108 mutex_init(&uc->lock);
1135 INIT_WORK(&uc->work, ccg_update_firmware); 1109 INIT_WORK(&uc->work, ccg_update_firmware);
1136 INIT_WORK(&uc->pm_work, ccg_pm_workaround_work); 1110 INIT_WORK(&uc->pm_work, ccg_pm_workaround_work);
@@ -1188,6 +1162,8 @@ static int ucsi_ccg_probe(struct i2c_client *client,
1188 1162
1189 pm_runtime_set_active(uc->dev); 1163 pm_runtime_set_active(uc->dev);
1190 pm_runtime_enable(uc->dev); 1164 pm_runtime_enable(uc->dev);
1165 pm_runtime_use_autosuspend(uc->dev);
1166 pm_runtime_set_autosuspend_delay(uc->dev, 5000);
1191 pm_runtime_idle(uc->dev); 1167 pm_runtime_idle(uc->dev);
1192 1168
1193 return 0; 1169 return 0;
@@ -1229,7 +1205,6 @@ static int ucsi_ccg_runtime_resume(struct device *dev)
1229{ 1205{
1230 struct i2c_client *client = to_i2c_client(dev); 1206 struct i2c_client *client = to_i2c_client(dev);
1231 struct ucsi_ccg *uc = i2c_get_clientdata(client); 1207 struct ucsi_ccg *uc = i2c_get_clientdata(client);
1232 bool schedule = true;
1233 1208
1234 /* 1209 /*
1235 * Firmware version 3.1.10 or earlier, built for NVIDIA has known issue 1210 * Firmware version 3.1.10 or earlier, built for NVIDIA has known issue
@@ -1237,17 +1212,8 @@ static int ucsi_ccg_runtime_resume(struct device *dev)
1237 * Schedule a work to call ISR as a workaround. 1212 * Schedule a work to call ISR as a workaround.
1238 */ 1213 */
1239 if (uc->fw_build == CCG_FW_BUILD_NVIDIA && 1214 if (uc->fw_build == CCG_FW_BUILD_NVIDIA &&
1240 uc->fw_version <= CCG_OLD_FW_VERSION) { 1215 uc->fw_version <= CCG_OLD_FW_VERSION)
1241 mutex_lock(&uc->lock); 1216 schedule_work(&uc->pm_work);
1242 if (!uc->run_isr) {
1243 uc->run_isr = true;
1244 schedule = false;
1245 }
1246 mutex_unlock(&uc->lock);
1247
1248 if (schedule)
1249 schedule_work(&uc->pm_work);
1250 }
1251 1217
1252 return 0; 1218 return 0;
1253} 1219}
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index c31d17d05810..2dc58766273a 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -61,6 +61,7 @@ struct usb_skel {
61 spinlock_t err_lock; /* lock for errors */ 61 spinlock_t err_lock; /* lock for errors */
62 struct kref kref; 62 struct kref kref;
63 struct mutex io_mutex; /* synchronize I/O with disconnect */ 63 struct mutex io_mutex; /* synchronize I/O with disconnect */
64 unsigned long disconnected:1;
64 wait_queue_head_t bulk_in_wait; /* to wait for an ongoing read */ 65 wait_queue_head_t bulk_in_wait; /* to wait for an ongoing read */
65}; 66};
66#define to_skel_dev(d) container_of(d, struct usb_skel, kref) 67#define to_skel_dev(d) container_of(d, struct usb_skel, kref)
@@ -73,6 +74,7 @@ static void skel_delete(struct kref *kref)
73 struct usb_skel *dev = to_skel_dev(kref); 74 struct usb_skel *dev = to_skel_dev(kref);
74 75
75 usb_free_urb(dev->bulk_in_urb); 76 usb_free_urb(dev->bulk_in_urb);
77 usb_put_intf(dev->interface);
76 usb_put_dev(dev->udev); 78 usb_put_dev(dev->udev);
77 kfree(dev->bulk_in_buffer); 79 kfree(dev->bulk_in_buffer);
78 kfree(dev); 80 kfree(dev);
@@ -124,10 +126,7 @@ static int skel_release(struct inode *inode, struct file *file)
124 return -ENODEV; 126 return -ENODEV;
125 127
126 /* allow the device to be autosuspended */ 128 /* allow the device to be autosuspended */
127 mutex_lock(&dev->io_mutex); 129 usb_autopm_put_interface(dev->interface);
128 if (dev->interface)
129 usb_autopm_put_interface(dev->interface);
130 mutex_unlock(&dev->io_mutex);
131 130
132 /* decrement the count on our device */ 131 /* decrement the count on our device */
133 kref_put(&dev->kref, skel_delete); 132 kref_put(&dev->kref, skel_delete);
@@ -231,8 +230,7 @@ static ssize_t skel_read(struct file *file, char *buffer, size_t count,
231 230
232 dev = file->private_data; 231 dev = file->private_data;
233 232
234 /* if we cannot read at all, return EOF */ 233 if (!count)
235 if (!dev->bulk_in_urb || !count)
236 return 0; 234 return 0;
237 235
238 /* no concurrent readers */ 236 /* no concurrent readers */
@@ -240,7 +238,7 @@ static ssize_t skel_read(struct file *file, char *buffer, size_t count,
240 if (rv < 0) 238 if (rv < 0)
241 return rv; 239 return rv;
242 240
243 if (!dev->interface) { /* disconnect() was called */ 241 if (dev->disconnected) { /* disconnect() was called */
244 rv = -ENODEV; 242 rv = -ENODEV;
245 goto exit; 243 goto exit;
246 } 244 }
@@ -422,7 +420,7 @@ static ssize_t skel_write(struct file *file, const char *user_buffer,
422 420
423 /* this lock makes sure we don't submit URBs to gone devices */ 421 /* this lock makes sure we don't submit URBs to gone devices */
424 mutex_lock(&dev->io_mutex); 422 mutex_lock(&dev->io_mutex);
425 if (!dev->interface) { /* disconnect() was called */ 423 if (dev->disconnected) { /* disconnect() was called */
426 mutex_unlock(&dev->io_mutex); 424 mutex_unlock(&dev->io_mutex);
427 retval = -ENODEV; 425 retval = -ENODEV;
428 goto error; 426 goto error;
@@ -507,7 +505,7 @@ static int skel_probe(struct usb_interface *interface,
507 init_waitqueue_head(&dev->bulk_in_wait); 505 init_waitqueue_head(&dev->bulk_in_wait);
508 506
509 dev->udev = usb_get_dev(interface_to_usbdev(interface)); 507 dev->udev = usb_get_dev(interface_to_usbdev(interface));
510 dev->interface = interface; 508 dev->interface = usb_get_intf(interface);
511 509
512 /* set up the endpoint information */ 510 /* set up the endpoint information */
513 /* use only the first bulk-in and bulk-out endpoints */ 511 /* use only the first bulk-in and bulk-out endpoints */
@@ -573,9 +571,10 @@ static void skel_disconnect(struct usb_interface *interface)
573 571
574 /* prevent more I/O from starting */ 572 /* prevent more I/O from starting */
575 mutex_lock(&dev->io_mutex); 573 mutex_lock(&dev->io_mutex);
576 dev->interface = NULL; 574 dev->disconnected = 1;
577 mutex_unlock(&dev->io_mutex); 575 mutex_unlock(&dev->io_mutex);
578 576
577 usb_kill_urb(dev->bulk_in_urb);
579 usb_kill_anchored_urbs(&dev->submitted); 578 usb_kill_anchored_urbs(&dev->submitted);
580 579
581 /* decrement our usage count */ 580 /* decrement our usage count */
diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
index 585a84d319bd..65850e9c7190 100644
--- a/drivers/usb/usbip/vhci_hcd.c
+++ b/drivers/usb/usbip/vhci_hcd.c
@@ -1195,12 +1195,12 @@ static int vhci_start(struct usb_hcd *hcd)
1195 if (id == 0 && usb_hcd_is_primary_hcd(hcd)) { 1195 if (id == 0 && usb_hcd_is_primary_hcd(hcd)) {
1196 err = vhci_init_attr_group(); 1196 err = vhci_init_attr_group();
1197 if (err) { 1197 if (err) {
1198 pr_err("init attr group\n"); 1198 dev_err(hcd_dev(hcd), "init attr group failed, err = %d\n", err);
1199 return err; 1199 return err;
1200 } 1200 }
1201 err = sysfs_create_group(&hcd_dev(hcd)->kobj, &vhci_attr_group); 1201 err = sysfs_create_group(&hcd_dev(hcd)->kobj, &vhci_attr_group);
1202 if (err) { 1202 if (err) {
1203 pr_err("create sysfs files\n"); 1203 dev_err(hcd_dev(hcd), "create sysfs files failed, err = %d\n", err);
1204 vhci_finish_attr_group(); 1204 vhci_finish_attr_group();
1205 return err; 1205 return err;
1206 } 1206 }
diff --git a/drivers/vhost/test.c b/drivers/vhost/test.c
index 7804869c6a31..056308008288 100644
--- a/drivers/vhost/test.c
+++ b/drivers/vhost/test.c
@@ -161,6 +161,7 @@ static int vhost_test_release(struct inode *inode, struct file *f)
161 161
162 vhost_test_stop(n, &private); 162 vhost_test_stop(n, &private);
163 vhost_test_flush(n); 163 vhost_test_flush(n);
164 vhost_dev_stop(&n->dev);
164 vhost_dev_cleanup(&n->dev); 165 vhost_dev_cleanup(&n->dev);
165 /* We do an extra flush before freeing memory, 166 /* We do an extra flush before freeing memory,
166 * since jobs can re-queue themselves. */ 167 * since jobs can re-queue themselves. */
@@ -237,6 +238,7 @@ static long vhost_test_reset_owner(struct vhost_test *n)
237 } 238 }
238 vhost_test_stop(n, &priv); 239 vhost_test_stop(n, &priv);
239 vhost_test_flush(n); 240 vhost_test_flush(n);
241 vhost_dev_stop(&n->dev);
240 vhost_dev_reset_owner(&n->dev, umem); 242 vhost_dev_reset_owner(&n->dev, umem);
241done: 243done:
242 mutex_unlock(&n->dev.mutex); 244 mutex_unlock(&n->dev.mutex);
diff --git a/drivers/video/logo/Makefile b/drivers/video/logo/Makefile
index 228a89b9bdd1..16f60c1e1766 100644
--- a/drivers/video/logo/Makefile
+++ b/drivers/video/logo/Makefile
@@ -18,23 +18,6 @@ obj-$(CONFIG_SPU_BASE) += logo_spe_clut224.o
18 18
19# How to generate logo's 19# How to generate logo's
20 20
21# Use logo-cfiles to retrieve list of .c files to be built
22logo-cfiles = $(notdir $(patsubst %.$(2), %.c, \
23 $(wildcard $(srctree)/$(src)/*$(1).$(2))))
24
25
26# Mono logos
27extra-y += $(call logo-cfiles,_mono,pbm)
28
29# VGA16 logos
30extra-y += $(call logo-cfiles,_vga16,ppm)
31
32# 224 Logos
33extra-y += $(call logo-cfiles,_clut224,ppm)
34
35# Gray 256
36extra-y += $(call logo-cfiles,_gray256,pgm)
37
38pnmtologo := scripts/pnmtologo 21pnmtologo := scripts/pnmtologo
39 22
40# Create commands like "pnmtologo -t mono -n logo_mac_mono -o ..." 23# Create commands like "pnmtologo -t mono -n logo_mac_mono -o ..."
@@ -55,5 +38,5 @@ $(obj)/%_clut224.c: $(src)/%_clut224.ppm $(pnmtologo) FORCE
55$(obj)/%_gray256.c: $(src)/%_gray256.pgm $(pnmtologo) FORCE 38$(obj)/%_gray256.c: $(src)/%_gray256.pgm $(pnmtologo) FORCE
56 $(call if_changed,logo) 39 $(call if_changed,logo)
57 40
58# Files generated that shall be removed upon make clean 41# generated C files
59clean-files := *.o *_mono.c *_vga16.c *_clut224.c *_gray256.c 42targets += *_mono.c *_vga16.c *_clut224.c *_gray256.c
diff --git a/drivers/virt/vboxguest/vboxguest_utils.c b/drivers/virt/vboxguest/vboxguest_utils.c
index 75fd140b02ff..43c391626a00 100644
--- a/drivers/virt/vboxguest/vboxguest_utils.c
+++ b/drivers/virt/vboxguest/vboxguest_utils.c
@@ -220,6 +220,8 @@ static int hgcm_call_preprocess_linaddr(
220 if (!bounce_buf) 220 if (!bounce_buf)
221 return -ENOMEM; 221 return -ENOMEM;
222 222
223 *bounce_buf_ret = bounce_buf;
224
223 if (copy_in) { 225 if (copy_in) {
224 ret = copy_from_user(bounce_buf, (void __user *)buf, len); 226 ret = copy_from_user(bounce_buf, (void __user *)buf, len);
225 if (ret) 227 if (ret)
@@ -228,7 +230,6 @@ static int hgcm_call_preprocess_linaddr(
228 memset(bounce_buf, 0, len); 230 memset(bounce_buf, 0, len);
229 } 231 }
230 232
231 *bounce_buf_ret = bounce_buf;
232 hgcm_call_add_pagelist_size(bounce_buf, len, extra); 233 hgcm_call_add_pagelist_size(bounce_buf, len, extra);
233 return 0; 234 return 0;
234} 235}
diff --git a/drivers/w1/slaves/Kconfig b/drivers/w1/slaves/Kconfig
index ebed495b9e69..b7847636501d 100644
--- a/drivers/w1/slaves/Kconfig
+++ b/drivers/w1/slaves/Kconfig
@@ -103,6 +103,7 @@ config W1_SLAVE_DS2438
103 103
104config W1_SLAVE_DS250X 104config W1_SLAVE_DS250X
105 tristate "512b/1kb/16kb EPROM family support" 105 tristate "512b/1kb/16kb EPROM family support"
106 select CRC16
106 help 107 help
107 Say Y here if you want to use a 1-wire 108 Say Y here if you want to use a 1-wire
108 512b/1kb/16kb EPROM family device (DS250x). 109 512b/1kb/16kb EPROM family device (DS250x).
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index 4e11de6cde81..5bae515c8e25 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -156,8 +156,10 @@ static DECLARE_DELAYED_WORK(balloon_worker, balloon_process);
156 (GFP_HIGHUSER | __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC) 156 (GFP_HIGHUSER | __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC)
157 157
158/* balloon_append: add the given page to the balloon. */ 158/* balloon_append: add the given page to the balloon. */
159static void __balloon_append(struct page *page) 159static void balloon_append(struct page *page)
160{ 160{
161 __SetPageOffline(page);
162
161 /* Lowmem is re-populated first, so highmem pages go at list tail. */ 163 /* Lowmem is re-populated first, so highmem pages go at list tail. */
162 if (PageHighMem(page)) { 164 if (PageHighMem(page)) {
163 list_add_tail(&page->lru, &ballooned_pages); 165 list_add_tail(&page->lru, &ballooned_pages);
@@ -169,11 +171,6 @@ static void __balloon_append(struct page *page)
169 wake_up(&balloon_wq); 171 wake_up(&balloon_wq);
170} 172}
171 173
172static void balloon_append(struct page *page)
173{
174 __balloon_append(page);
175}
176
177/* balloon_retrieve: rescue a page from the balloon, if it is not empty. */ 174/* balloon_retrieve: rescue a page from the balloon, if it is not empty. */
178static struct page *balloon_retrieve(bool require_lowmem) 175static struct page *balloon_retrieve(bool require_lowmem)
179{ 176{
@@ -192,6 +189,7 @@ static struct page *balloon_retrieve(bool require_lowmem)
192 else 189 else
193 balloon_stats.balloon_low--; 190 balloon_stats.balloon_low--;
194 191
192 __ClearPageOffline(page);
195 return page; 193 return page;
196} 194}
197 195
@@ -377,8 +375,7 @@ static void xen_online_page(struct page *page, unsigned int order)
377 for (i = 0; i < size; i++) { 375 for (i = 0; i < size; i++) {
378 p = pfn_to_page(start_pfn + i); 376 p = pfn_to_page(start_pfn + i);
379 __online_page_set_limits(p); 377 __online_page_set_limits(p);
380 __SetPageOffline(p); 378 balloon_append(p);
381 __balloon_append(p);
382 } 379 }
383 mutex_unlock(&balloon_mutex); 380 mutex_unlock(&balloon_mutex);
384} 381}
@@ -444,7 +441,6 @@ static enum bp_state increase_reservation(unsigned long nr_pages)
444 xenmem_reservation_va_mapping_update(1, &page, &frame_list[i]); 441 xenmem_reservation_va_mapping_update(1, &page, &frame_list[i]);
445 442
446 /* Relinquish the page back to the allocator. */ 443 /* Relinquish the page back to the allocator. */
447 __ClearPageOffline(page);
448 free_reserved_page(page); 444 free_reserved_page(page);
449 } 445 }
450 446
@@ -471,7 +467,6 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
471 state = BP_EAGAIN; 467 state = BP_EAGAIN;
472 break; 468 break;
473 } 469 }
474 __SetPageOffline(page);
475 adjust_managed_page_count(page, -1); 470 adjust_managed_page_count(page, -1);
476 xenmem_reservation_scrub_page(page); 471 xenmem_reservation_scrub_page(page);
477 list_add(&page->lru, &pages); 472 list_add(&page->lru, &pages);
@@ -611,7 +606,6 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages)
611 while (pgno < nr_pages) { 606 while (pgno < nr_pages) {
612 page = balloon_retrieve(true); 607 page = balloon_retrieve(true);
613 if (page) { 608 if (page) {
614 __ClearPageOffline(page);
615 pages[pgno++] = page; 609 pages[pgno++] = page;
616#ifdef CONFIG_XEN_HAVE_PVMMU 610#ifdef CONFIG_XEN_HAVE_PVMMU
617 /* 611 /*
@@ -653,10 +647,8 @@ void free_xenballooned_pages(int nr_pages, struct page **pages)
653 mutex_lock(&balloon_mutex); 647 mutex_lock(&balloon_mutex);
654 648
655 for (i = 0; i < nr_pages; i++) { 649 for (i = 0; i < nr_pages; i++) {
656 if (pages[i]) { 650 if (pages[i])
657 __SetPageOffline(pages[i]);
658 balloon_append(pages[i]); 651 balloon_append(pages[i]);
659 }
660 } 652 }
661 653
662 balloon_stats.target_unpopulated -= nr_pages; 654 balloon_stats.target_unpopulated -= nr_pages;
@@ -674,7 +666,6 @@ static void __init balloon_add_region(unsigned long start_pfn,
674 unsigned long pages) 666 unsigned long pages)
675{ 667{
676 unsigned long pfn, extra_pfn_end; 668 unsigned long pfn, extra_pfn_end;
677 struct page *page;
678 669
679 /* 670 /*
680 * If the amount of usable memory has been limited (e.g., with 671 * If the amount of usable memory has been limited (e.g., with
@@ -684,11 +675,10 @@ static void __init balloon_add_region(unsigned long start_pfn,
684 extra_pfn_end = min(max_pfn, start_pfn + pages); 675 extra_pfn_end = min(max_pfn, start_pfn + pages);
685 676
686 for (pfn = start_pfn; pfn < extra_pfn_end; pfn++) { 677 for (pfn = start_pfn; pfn < extra_pfn_end; pfn++) {
687 page = pfn_to_page(pfn);
688 /* totalram_pages and totalhigh_pages do not 678 /* totalram_pages and totalhigh_pages do not
689 include the boot-time balloon extension, so 679 include the boot-time balloon extension, so
690 don't subtract from it. */ 680 don't subtract from it. */
691 __balloon_append(page); 681 balloon_append(pfn_to_page(pfn));
692 } 682 }
693 683
694 balloon_stats.total_pages += extra_pfn_end - start_pfn; 684 balloon_stats.total_pages += extra_pfn_end - start_pfn;
diff --git a/drivers/xen/efi.c b/drivers/xen/efi.c
index 89d60f8e3c18..d1ff2186ebb4 100644
--- a/drivers/xen/efi.c
+++ b/drivers/xen/efi.c
@@ -40,7 +40,7 @@
40 40
41#define efi_data(op) (op.u.efi_runtime_call) 41#define efi_data(op) (op.u.efi_runtime_call)
42 42
43efi_status_t xen_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc) 43static efi_status_t xen_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
44{ 44{
45 struct xen_platform_op op = INIT_EFI_OP(get_time); 45 struct xen_platform_op op = INIT_EFI_OP(get_time);
46 46
@@ -61,9 +61,8 @@ efi_status_t xen_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
61 61
62 return efi_data(op).status; 62 return efi_data(op).status;
63} 63}
64EXPORT_SYMBOL_GPL(xen_efi_get_time);
65 64
66efi_status_t xen_efi_set_time(efi_time_t *tm) 65static efi_status_t xen_efi_set_time(efi_time_t *tm)
67{ 66{
68 struct xen_platform_op op = INIT_EFI_OP(set_time); 67 struct xen_platform_op op = INIT_EFI_OP(set_time);
69 68
@@ -75,10 +74,10 @@ efi_status_t xen_efi_set_time(efi_time_t *tm)
75 74
76 return efi_data(op).status; 75 return efi_data(op).status;
77} 76}
78EXPORT_SYMBOL_GPL(xen_efi_set_time);
79 77
80efi_status_t xen_efi_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending, 78static efi_status_t xen_efi_get_wakeup_time(efi_bool_t *enabled,
81 efi_time_t *tm) 79 efi_bool_t *pending,
80 efi_time_t *tm)
82{ 81{
83 struct xen_platform_op op = INIT_EFI_OP(get_wakeup_time); 82 struct xen_platform_op op = INIT_EFI_OP(get_wakeup_time);
84 83
@@ -98,9 +97,8 @@ efi_status_t xen_efi_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending,
98 97
99 return efi_data(op).status; 98 return efi_data(op).status;
100} 99}
101EXPORT_SYMBOL_GPL(xen_efi_get_wakeup_time);
102 100
103efi_status_t xen_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm) 101static efi_status_t xen_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
104{ 102{
105 struct xen_platform_op op = INIT_EFI_OP(set_wakeup_time); 103 struct xen_platform_op op = INIT_EFI_OP(set_wakeup_time);
106 104
@@ -117,11 +115,10 @@ efi_status_t xen_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
117 115
118 return efi_data(op).status; 116 return efi_data(op).status;
119} 117}
120EXPORT_SYMBOL_GPL(xen_efi_set_wakeup_time);
121 118
122efi_status_t xen_efi_get_variable(efi_char16_t *name, efi_guid_t *vendor, 119static efi_status_t xen_efi_get_variable(efi_char16_t *name, efi_guid_t *vendor,
123 u32 *attr, unsigned long *data_size, 120 u32 *attr, unsigned long *data_size,
124 void *data) 121 void *data)
125{ 122{
126 struct xen_platform_op op = INIT_EFI_OP(get_variable); 123 struct xen_platform_op op = INIT_EFI_OP(get_variable);
127 124
@@ -141,11 +138,10 @@ efi_status_t xen_efi_get_variable(efi_char16_t *name, efi_guid_t *vendor,
141 138
142 return efi_data(op).status; 139 return efi_data(op).status;
143} 140}
144EXPORT_SYMBOL_GPL(xen_efi_get_variable);
145 141
146efi_status_t xen_efi_get_next_variable(unsigned long *name_size, 142static efi_status_t xen_efi_get_next_variable(unsigned long *name_size,
147 efi_char16_t *name, 143 efi_char16_t *name,
148 efi_guid_t *vendor) 144 efi_guid_t *vendor)
149{ 145{
150 struct xen_platform_op op = INIT_EFI_OP(get_next_variable_name); 146 struct xen_platform_op op = INIT_EFI_OP(get_next_variable_name);
151 147
@@ -165,11 +161,10 @@ efi_status_t xen_efi_get_next_variable(unsigned long *name_size,
165 161
166 return efi_data(op).status; 162 return efi_data(op).status;
167} 163}
168EXPORT_SYMBOL_GPL(xen_efi_get_next_variable);
169 164
170efi_status_t xen_efi_set_variable(efi_char16_t *name, efi_guid_t *vendor, 165static efi_status_t xen_efi_set_variable(efi_char16_t *name, efi_guid_t *vendor,
171 u32 attr, unsigned long data_size, 166 u32 attr, unsigned long data_size,
172 void *data) 167 void *data)
173{ 168{
174 struct xen_platform_op op = INIT_EFI_OP(set_variable); 169 struct xen_platform_op op = INIT_EFI_OP(set_variable);
175 170
@@ -186,11 +181,10 @@ efi_status_t xen_efi_set_variable(efi_char16_t *name, efi_guid_t *vendor,
186 181
187 return efi_data(op).status; 182 return efi_data(op).status;
188} 183}
189EXPORT_SYMBOL_GPL(xen_efi_set_variable);
190 184
191efi_status_t xen_efi_query_variable_info(u32 attr, u64 *storage_space, 185static efi_status_t xen_efi_query_variable_info(u32 attr, u64 *storage_space,
192 u64 *remaining_space, 186 u64 *remaining_space,
193 u64 *max_variable_size) 187 u64 *max_variable_size)
194{ 188{
195 struct xen_platform_op op = INIT_EFI_OP(query_variable_info); 189 struct xen_platform_op op = INIT_EFI_OP(query_variable_info);
196 190
@@ -208,9 +202,8 @@ efi_status_t xen_efi_query_variable_info(u32 attr, u64 *storage_space,
208 202
209 return efi_data(op).status; 203 return efi_data(op).status;
210} 204}
211EXPORT_SYMBOL_GPL(xen_efi_query_variable_info);
212 205
213efi_status_t xen_efi_get_next_high_mono_count(u32 *count) 206static efi_status_t xen_efi_get_next_high_mono_count(u32 *count)
214{ 207{
215 struct xen_platform_op op = INIT_EFI_OP(get_next_high_monotonic_count); 208 struct xen_platform_op op = INIT_EFI_OP(get_next_high_monotonic_count);
216 209
@@ -221,10 +214,9 @@ efi_status_t xen_efi_get_next_high_mono_count(u32 *count)
221 214
222 return efi_data(op).status; 215 return efi_data(op).status;
223} 216}
224EXPORT_SYMBOL_GPL(xen_efi_get_next_high_mono_count);
225 217
226efi_status_t xen_efi_update_capsule(efi_capsule_header_t **capsules, 218static efi_status_t xen_efi_update_capsule(efi_capsule_header_t **capsules,
227 unsigned long count, unsigned long sg_list) 219 unsigned long count, unsigned long sg_list)
228{ 220{
229 struct xen_platform_op op = INIT_EFI_OP(update_capsule); 221 struct xen_platform_op op = INIT_EFI_OP(update_capsule);
230 222
@@ -241,11 +233,9 @@ efi_status_t xen_efi_update_capsule(efi_capsule_header_t **capsules,
241 233
242 return efi_data(op).status; 234 return efi_data(op).status;
243} 235}
244EXPORT_SYMBOL_GPL(xen_efi_update_capsule);
245 236
246efi_status_t xen_efi_query_capsule_caps(efi_capsule_header_t **capsules, 237static efi_status_t xen_efi_query_capsule_caps(efi_capsule_header_t **capsules,
247 unsigned long count, u64 *max_size, 238 unsigned long count, u64 *max_size, int *reset_type)
248 int *reset_type)
249{ 239{
250 struct xen_platform_op op = INIT_EFI_OP(query_capsule_capabilities); 240 struct xen_platform_op op = INIT_EFI_OP(query_capsule_capabilities);
251 241
@@ -264,10 +254,9 @@ efi_status_t xen_efi_query_capsule_caps(efi_capsule_header_t **capsules,
264 254
265 return efi_data(op).status; 255 return efi_data(op).status;
266} 256}
267EXPORT_SYMBOL_GPL(xen_efi_query_capsule_caps);
268 257
269void xen_efi_reset_system(int reset_type, efi_status_t status, 258static void xen_efi_reset_system(int reset_type, efi_status_t status,
270 unsigned long data_size, efi_char16_t *data) 259 unsigned long data_size, efi_char16_t *data)
271{ 260{
272 switch (reset_type) { 261 switch (reset_type) {
273 case EFI_RESET_COLD: 262 case EFI_RESET_COLD:
@@ -281,4 +270,25 @@ void xen_efi_reset_system(int reset_type, efi_status_t status,
281 BUG(); 270 BUG();
282 } 271 }
283} 272}
284EXPORT_SYMBOL_GPL(xen_efi_reset_system); 273
274/*
275 * Set XEN EFI runtime services function pointers. Other fields of struct efi,
276 * e.g. efi.systab, will be set like normal EFI.
277 */
278void __init xen_efi_runtime_setup(void)
279{
280 efi.get_time = xen_efi_get_time;
281 efi.set_time = xen_efi_set_time;
282 efi.get_wakeup_time = xen_efi_get_wakeup_time;
283 efi.set_wakeup_time = xen_efi_set_wakeup_time;
284 efi.get_variable = xen_efi_get_variable;
285 efi.get_next_variable = xen_efi_get_next_variable;
286 efi.set_variable = xen_efi_set_variable;
287 efi.set_variable_nonblocking = xen_efi_set_variable;
288 efi.query_variable_info = xen_efi_query_variable_info;
289 efi.query_variable_info_nonblocking = xen_efi_query_variable_info;
290 efi.update_capsule = xen_efi_update_capsule;
291 efi.query_capsule_caps = xen_efi_query_capsule_caps;
292 efi.get_next_high_mono_count = xen_efi_get_next_high_mono_count;
293 efi.reset_system = xen_efi_reset_system;
294}
diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index a446a7221e13..81401f386c9c 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -22,6 +22,7 @@
22 22
23#define pr_fmt(fmt) "xen:" KBUILD_MODNAME ": " fmt 23#define pr_fmt(fmt) "xen:" KBUILD_MODNAME ": " fmt
24 24
25#include <linux/dma-mapping.h>
25#include <linux/module.h> 26#include <linux/module.h>
26#include <linux/kernel.h> 27#include <linux/kernel.h>
27#include <linux/init.h> 28#include <linux/init.h>
@@ -34,9 +35,6 @@
34#include <linux/slab.h> 35#include <linux/slab.h>
35#include <linux/highmem.h> 36#include <linux/highmem.h>
36#include <linux/refcount.h> 37#include <linux/refcount.h>
37#ifdef CONFIG_XEN_GRANT_DMA_ALLOC
38#include <linux/of_device.h>
39#endif
40 38
41#include <xen/xen.h> 39#include <xen/xen.h>
42#include <xen/grant_table.h> 40#include <xen/grant_table.h>
@@ -625,14 +623,7 @@ static int gntdev_open(struct inode *inode, struct file *flip)
625 flip->private_data = priv; 623 flip->private_data = priv;
626#ifdef CONFIG_XEN_GRANT_DMA_ALLOC 624#ifdef CONFIG_XEN_GRANT_DMA_ALLOC
627 priv->dma_dev = gntdev_miscdev.this_device; 625 priv->dma_dev = gntdev_miscdev.this_device;
628 626 dma_coerce_mask_and_coherent(priv->dma_dev, DMA_BIT_MASK(64));
629 /*
630 * The device is not spawn from a device tree, so arch_setup_dma_ops
631 * is not called, thus leaving the device with dummy DMA ops.
632 * Fix this by calling of_dma_configure() with a NULL node to set
633 * default DMA ops.
634 */
635 of_dma_configure(priv->dma_dev, NULL, true);
636#endif 627#endif
637 pr_debug("priv %p\n", priv); 628 pr_debug("priv %p\n", priv);
638 629
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index 7ea6fb6a2e5d..49b381e104ef 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -1363,8 +1363,7 @@ static int gnttab_setup(void)
1363 if (xen_feature(XENFEAT_auto_translated_physmap) && gnttab_shared.addr == NULL) { 1363 if (xen_feature(XENFEAT_auto_translated_physmap) && gnttab_shared.addr == NULL) {
1364 gnttab_shared.addr = xen_auto_xlat_grant_frames.vaddr; 1364 gnttab_shared.addr = xen_auto_xlat_grant_frames.vaddr;
1365 if (gnttab_shared.addr == NULL) { 1365 if (gnttab_shared.addr == NULL) {
1366 pr_warn("gnttab share frames (addr=0x%08lx) is not mapped!\n", 1366 pr_warn("gnttab share frames is not mapped!\n");
1367 (unsigned long)xen_auto_xlat_grant_frames.vaddr);
1368 return -ENOMEM; 1367 return -ENOMEM;
1369 } 1368 }
1370 } 1369 }
diff --git a/drivers/xen/pvcalls-back.c b/drivers/xen/pvcalls-back.c
index 69a626b0e594..c57c71b7d53d 100644
--- a/drivers/xen/pvcalls-back.c
+++ b/drivers/xen/pvcalls-back.c
@@ -775,7 +775,7 @@ static int pvcalls_back_poll(struct xenbus_device *dev,
775 mappass->reqcopy = *req; 775 mappass->reqcopy = *req;
776 icsk = inet_csk(mappass->sock->sk); 776 icsk = inet_csk(mappass->sock->sk);
777 queue = &icsk->icsk_accept_queue; 777 queue = &icsk->icsk_accept_queue;
778 data = queue->rskq_accept_head != NULL; 778 data = READ_ONCE(queue->rskq_accept_head) != NULL;
779 if (data) { 779 if (data) {
780 mappass->reqcopy.cmd = 0; 780 mappass->reqcopy.cmd = 0;
781 ret = 0; 781 ret = 0;
diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
index 08adc590f631..597af455a522 100644
--- a/drivers/xen/xenbus/xenbus_dev_frontend.c
+++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
@@ -55,6 +55,7 @@
55#include <linux/string.h> 55#include <linux/string.h>
56#include <linux/slab.h> 56#include <linux/slab.h>
57#include <linux/miscdevice.h> 57#include <linux/miscdevice.h>
58#include <linux/workqueue.h>
58 59
59#include <xen/xenbus.h> 60#include <xen/xenbus.h>
60#include <xen/xen.h> 61#include <xen/xen.h>
@@ -116,6 +117,8 @@ struct xenbus_file_priv {
116 wait_queue_head_t read_waitq; 117 wait_queue_head_t read_waitq;
117 118
118 struct kref kref; 119 struct kref kref;
120
121 struct work_struct wq;
119}; 122};
120 123
121/* Read out any raw xenbus messages queued up. */ 124/* Read out any raw xenbus messages queued up. */
@@ -300,14 +303,14 @@ static void watch_fired(struct xenbus_watch *watch,
300 mutex_unlock(&adap->dev_data->reply_mutex); 303 mutex_unlock(&adap->dev_data->reply_mutex);
301} 304}
302 305
303static void xenbus_file_free(struct kref *kref) 306static void xenbus_worker(struct work_struct *wq)
304{ 307{
305 struct xenbus_file_priv *u; 308 struct xenbus_file_priv *u;
306 struct xenbus_transaction_holder *trans, *tmp; 309 struct xenbus_transaction_holder *trans, *tmp;
307 struct watch_adapter *watch, *tmp_watch; 310 struct watch_adapter *watch, *tmp_watch;
308 struct read_buffer *rb, *tmp_rb; 311 struct read_buffer *rb, *tmp_rb;
309 312
310 u = container_of(kref, struct xenbus_file_priv, kref); 313 u = container_of(wq, struct xenbus_file_priv, wq);
311 314
312 /* 315 /*
313 * No need for locking here because there are no other users, 316 * No need for locking here because there are no other users,
@@ -333,6 +336,18 @@ static void xenbus_file_free(struct kref *kref)
333 kfree(u); 336 kfree(u);
334} 337}
335 338
339static void xenbus_file_free(struct kref *kref)
340{
341 struct xenbus_file_priv *u;
342
343 /*
344 * We might be called in xenbus_thread().
345 * Use workqueue to avoid deadlock.
346 */
347 u = container_of(kref, struct xenbus_file_priv, kref);
348 schedule_work(&u->wq);
349}
350
336static struct xenbus_transaction_holder *xenbus_get_transaction( 351static struct xenbus_transaction_holder *xenbus_get_transaction(
337 struct xenbus_file_priv *u, uint32_t tx_id) 352 struct xenbus_file_priv *u, uint32_t tx_id)
338{ 353{
@@ -650,6 +665,7 @@ static int xenbus_file_open(struct inode *inode, struct file *filp)
650 INIT_LIST_HEAD(&u->watches); 665 INIT_LIST_HEAD(&u->watches);
651 INIT_LIST_HEAD(&u->read_buffers); 666 INIT_LIST_HEAD(&u->read_buffers);
652 init_waitqueue_head(&u->read_waitq); 667 init_waitqueue_head(&u->read_waitq);
668 INIT_WORK(&u->wq, xenbus_worker);
653 669
654 mutex_init(&u->reply_mutex); 670 mutex_init(&u->reply_mutex);
655 mutex_init(&u->msgbuffer_mutex); 671 mutex_init(&u->msgbuffer_mutex);
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index ad4c6b1d5074..c5642bcb6b46 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -879,7 +879,7 @@ out_free_interp:
879 the correct location in memory. */ 879 the correct location in memory. */
880 for(i = 0, elf_ppnt = elf_phdata; 880 for(i = 0, elf_ppnt = elf_phdata;
881 i < loc->elf_ex.e_phnum; i++, elf_ppnt++) { 881 i < loc->elf_ex.e_phnum; i++, elf_ppnt++) {
882 int elf_prot, elf_flags, elf_fixed = MAP_FIXED_NOREPLACE; 882 int elf_prot, elf_flags;
883 unsigned long k, vaddr; 883 unsigned long k, vaddr;
884 unsigned long total_size = 0; 884 unsigned long total_size = 0;
885 885
@@ -911,13 +911,6 @@ out_free_interp:
911 */ 911 */
912 } 912 }
913 } 913 }
914
915 /*
916 * Some binaries have overlapping elf segments and then
917 * we have to forcefully map over an existing mapping
918 * e.g. over this newly established brk mapping.
919 */
920 elf_fixed = MAP_FIXED;
921 } 914 }
922 915
923 elf_prot = make_prot(elf_ppnt->p_flags); 916 elf_prot = make_prot(elf_ppnt->p_flags);
@@ -930,7 +923,7 @@ out_free_interp:
930 * the ET_DYN load_addr calculations, proceed normally. 923 * the ET_DYN load_addr calculations, proceed normally.
931 */ 924 */
932 if (loc->elf_ex.e_type == ET_EXEC || load_addr_set) { 925 if (loc->elf_ex.e_type == ET_EXEC || load_addr_set) {
933 elf_flags |= elf_fixed; 926 elf_flags |= MAP_FIXED;
934 } else if (loc->elf_ex.e_type == ET_DYN) { 927 } else if (loc->elf_ex.e_type == ET_DYN) {
935 /* 928 /*
936 * This logic is run once for the first LOAD Program 929 * This logic is run once for the first LOAD Program
@@ -966,7 +959,7 @@ out_free_interp:
966 load_bias = ELF_ET_DYN_BASE; 959 load_bias = ELF_ET_DYN_BASE;
967 if (current->flags & PF_RANDOMIZE) 960 if (current->flags & PF_RANDOMIZE)
968 load_bias += arch_mmap_rnd(); 961 load_bias += arch_mmap_rnd();
969 elf_flags |= elf_fixed; 962 elf_flags |= MAP_FIXED;
970 } else 963 } else
971 load_bias = 0; 964 load_bias = 0;
972 965
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 8fe4eb7e5045..27e5b269e729 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1591,7 +1591,6 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
1591 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); 1591 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
1592 struct btrfs_root *root = BTRFS_I(inode)->root; 1592 struct btrfs_root *root = BTRFS_I(inode)->root;
1593 struct page **pages = NULL; 1593 struct page **pages = NULL;
1594 struct extent_state *cached_state = NULL;
1595 struct extent_changeset *data_reserved = NULL; 1594 struct extent_changeset *data_reserved = NULL;
1596 u64 release_bytes = 0; 1595 u64 release_bytes = 0;
1597 u64 lockstart; 1596 u64 lockstart;
@@ -1611,6 +1610,7 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
1611 return -ENOMEM; 1610 return -ENOMEM;
1612 1611
1613 while (iov_iter_count(i) > 0) { 1612 while (iov_iter_count(i) > 0) {
1613 struct extent_state *cached_state = NULL;
1614 size_t offset = offset_in_page(pos); 1614 size_t offset = offset_in_page(pos);
1615 size_t sector_offset; 1615 size_t sector_offset;
1616 size_t write_bytes = min(iov_iter_count(i), 1616 size_t write_bytes = min(iov_iter_count(i),
@@ -1758,9 +1758,20 @@ again:
1758 if (copied > 0) 1758 if (copied > 0)
1759 ret = btrfs_dirty_pages(inode, pages, dirty_pages, 1759 ret = btrfs_dirty_pages(inode, pages, dirty_pages,
1760 pos, copied, &cached_state); 1760 pos, copied, &cached_state);
1761
1762 /*
1763 * If we have not locked the extent range, because the range's
1764 * start offset is >= i_size, we might still have a non-NULL
1765 * cached extent state, acquired while marking the extent range
1766 * as delalloc through btrfs_dirty_pages(). Therefore free any
1767 * possible cached extent state to avoid a memory leak.
1768 */
1761 if (extents_locked) 1769 if (extents_locked)
1762 unlock_extent_cached(&BTRFS_I(inode)->io_tree, 1770 unlock_extent_cached(&BTRFS_I(inode)->io_tree,
1763 lockstart, lockend, &cached_state); 1771 lockstart, lockend, &cached_state);
1772 else
1773 free_extent_state(cached_state);
1774
1764 btrfs_delalloc_release_extents(BTRFS_I(inode), reserve_bytes, 1775 btrfs_delalloc_release_extents(BTRFS_I(inode), reserve_bytes,
1765 true); 1776 true);
1766 if (ret) { 1777 if (ret) {
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index a0546401bc0a..0f2754eaa05b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -6305,13 +6305,16 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
6305 u32 sizes[2]; 6305 u32 sizes[2];
6306 int nitems = name ? 2 : 1; 6306 int nitems = name ? 2 : 1;
6307 unsigned long ptr; 6307 unsigned long ptr;
6308 unsigned int nofs_flag;
6308 int ret; 6309 int ret;
6309 6310
6310 path = btrfs_alloc_path(); 6311 path = btrfs_alloc_path();
6311 if (!path) 6312 if (!path)
6312 return ERR_PTR(-ENOMEM); 6313 return ERR_PTR(-ENOMEM);
6313 6314
6315 nofs_flag = memalloc_nofs_save();
6314 inode = new_inode(fs_info->sb); 6316 inode = new_inode(fs_info->sb);
6317 memalloc_nofs_restore(nofs_flag);
6315 if (!inode) { 6318 if (!inode) {
6316 btrfs_free_path(path); 6319 btrfs_free_path(path);
6317 return ERR_PTR(-ENOMEM); 6320 return ERR_PTR(-ENOMEM);
diff --git a/fs/btrfs/ref-verify.c b/fs/btrfs/ref-verify.c
index e87cbdad02a3..b57f3618e58e 100644
--- a/fs/btrfs/ref-verify.c
+++ b/fs/btrfs/ref-verify.c
@@ -500,7 +500,7 @@ static int process_leaf(struct btrfs_root *root,
500 struct btrfs_extent_data_ref *dref; 500 struct btrfs_extent_data_ref *dref;
501 struct btrfs_shared_data_ref *sref; 501 struct btrfs_shared_data_ref *sref;
502 u32 count; 502 u32 count;
503 int i = 0, tree_block_level = 0, ret; 503 int i = 0, tree_block_level = 0, ret = 0;
504 struct btrfs_key key; 504 struct btrfs_key key;
505 int nritems = btrfs_header_nritems(leaf); 505 int nritems = btrfs_header_nritems(leaf);
506 506
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index f3215028235c..123ac54af071 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -5085,7 +5085,7 @@ static int clone_range(struct send_ctx *sctx,
5085 struct btrfs_path *path; 5085 struct btrfs_path *path;
5086 struct btrfs_key key; 5086 struct btrfs_key key;
5087 int ret; 5087 int ret;
5088 u64 clone_src_i_size; 5088 u64 clone_src_i_size = 0;
5089 5089
5090 /* 5090 /*
5091 * Prevent cloning from a zero offset with a length matching the sector 5091 * Prevent cloning from a zero offset with a length matching the sector
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 29b82a795522..8a6cc600bf18 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -2932,7 +2932,8 @@ out:
2932 * in the tree of log roots 2932 * in the tree of log roots
2933 */ 2933 */
2934static int update_log_root(struct btrfs_trans_handle *trans, 2934static int update_log_root(struct btrfs_trans_handle *trans,
2935 struct btrfs_root *log) 2935 struct btrfs_root *log,
2936 struct btrfs_root_item *root_item)
2936{ 2937{
2937 struct btrfs_fs_info *fs_info = log->fs_info; 2938 struct btrfs_fs_info *fs_info = log->fs_info;
2938 int ret; 2939 int ret;
@@ -2940,10 +2941,10 @@ static int update_log_root(struct btrfs_trans_handle *trans,
2940 if (log->log_transid == 1) { 2941 if (log->log_transid == 1) {
2941 /* insert root item on the first sync */ 2942 /* insert root item on the first sync */
2942 ret = btrfs_insert_root(trans, fs_info->log_root_tree, 2943 ret = btrfs_insert_root(trans, fs_info->log_root_tree,
2943 &log->root_key, &log->root_item); 2944 &log->root_key, root_item);
2944 } else { 2945 } else {
2945 ret = btrfs_update_root(trans, fs_info->log_root_tree, 2946 ret = btrfs_update_root(trans, fs_info->log_root_tree,
2946 &log->root_key, &log->root_item); 2947 &log->root_key, root_item);
2947 } 2948 }
2948 return ret; 2949 return ret;
2949} 2950}
@@ -3041,6 +3042,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
3041 struct btrfs_fs_info *fs_info = root->fs_info; 3042 struct btrfs_fs_info *fs_info = root->fs_info;
3042 struct btrfs_root *log = root->log_root; 3043 struct btrfs_root *log = root->log_root;
3043 struct btrfs_root *log_root_tree = fs_info->log_root_tree; 3044 struct btrfs_root *log_root_tree = fs_info->log_root_tree;
3045 struct btrfs_root_item new_root_item;
3044 int log_transid = 0; 3046 int log_transid = 0;
3045 struct btrfs_log_ctx root_log_ctx; 3047 struct btrfs_log_ctx root_log_ctx;
3046 struct blk_plug plug; 3048 struct blk_plug plug;
@@ -3104,18 +3106,26 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
3104 goto out; 3106 goto out;
3105 } 3107 }
3106 3108
3109 /*
3110 * We _must_ update under the root->log_mutex in order to make sure we
3111 * have a consistent view of the log root we are trying to commit at
3112 * this moment.
3113 *
3114 * We _must_ copy this into a local copy, because we are not holding the
3115 * log_root_tree->log_mutex yet. This is important because when we
3116 * commit the log_root_tree we must have a consistent view of the
3117 * log_root_tree when we update the super block to point at the
3118 * log_root_tree bytenr. If we update the log_root_tree here we'll race
3119 * with the commit and possibly point at the new block which we may not
3120 * have written out.
3121 */
3107 btrfs_set_root_node(&log->root_item, log->node); 3122 btrfs_set_root_node(&log->root_item, log->node);
3123 memcpy(&new_root_item, &log->root_item, sizeof(new_root_item));
3108 3124
3109 root->log_transid++; 3125 root->log_transid++;
3110 log->log_transid = root->log_transid; 3126 log->log_transid = root->log_transid;
3111 root->log_start_pid = 0; 3127 root->log_start_pid = 0;
3112 /* 3128 /*
3113 * Update or create log root item under the root's log_mutex to prevent
3114 * races with concurrent log syncs that can lead to failure to update
3115 * log root item because it was not created yet.
3116 */
3117 ret = update_log_root(trans, log);
3118 /*
3119 * IO has been started, blocks of the log tree have WRITTEN flag set 3129 * IO has been started, blocks of the log tree have WRITTEN flag set
3120 * in their headers. new modifications of the log will be written to 3130 * in their headers. new modifications of the log will be written to
3121 * new positions. so it's safe to allow log writers to go in. 3131 * new positions. so it's safe to allow log writers to go in.
@@ -3135,6 +3145,14 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
3135 mutex_unlock(&log_root_tree->log_mutex); 3145 mutex_unlock(&log_root_tree->log_mutex);
3136 3146
3137 mutex_lock(&log_root_tree->log_mutex); 3147 mutex_lock(&log_root_tree->log_mutex);
3148
3149 /*
3150 * Now we are safe to update the log_root_tree because we're under the
3151 * log_mutex, and we're a current writer so we're holding the commit
3152 * open until we drop the log_mutex.
3153 */
3154 ret = update_log_root(trans, log, &new_root_item);
3155
3138 if (atomic_dec_and_test(&log_root_tree->log_writers)) { 3156 if (atomic_dec_and_test(&log_root_tree->log_writers)) {
3139 /* atomic_dec_and_test implies a barrier */ 3157 /* atomic_dec_and_test implies a barrier */
3140 cond_wake_up_nomb(&log_root_tree->log_writer_wait); 3158 cond_wake_up_nomb(&log_root_tree->log_writer_wait);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index cdd7af424033..bdfe4493e43a 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -3845,7 +3845,11 @@ static int alloc_profile_is_valid(u64 flags, int extended)
3845 return !extended; /* "0" is valid for usual profiles */ 3845 return !extended; /* "0" is valid for usual profiles */
3846 3846
3847 /* true if exactly one bit set */ 3847 /* true if exactly one bit set */
3848 return is_power_of_2(flags); 3848 /*
3849 * Don't use is_power_of_2(unsigned long) because it won't work
3850 * for the single profile (1ULL << 48) on 32-bit CPUs.
3851 */
3852 return flags != 0 && (flags & (flags - 1)) == 0;
3849} 3853}
3850 3854
3851static inline int balance_need_close(struct btrfs_fs_info *fs_info) 3855static inline int balance_need_close(struct btrfs_fs_info *fs_info)
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index a8a8f84f3bbf..a5163296d9d9 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -384,8 +384,8 @@ static int parse_reply_info_readdir(void **p, void *end,
384 } 384 }
385 385
386done: 386done:
387 if (*p != end) 387 /* Skip over any unrecognized fields */
388 goto bad; 388 *p = end;
389 return 0; 389 return 0;
390 390
391bad: 391bad:
@@ -406,12 +406,10 @@ static int parse_reply_info_filelock(void **p, void *end,
406 goto bad; 406 goto bad;
407 407
408 info->filelock_reply = *p; 408 info->filelock_reply = *p;
409 *p += sizeof(*info->filelock_reply);
410 409
411 if (unlikely(*p != end)) 410 /* Skip over any unrecognized fields */
412 goto bad; 411 *p = end;
413 return 0; 412 return 0;
414
415bad: 413bad:
416 return -EIO; 414 return -EIO;
417} 415}
@@ -425,18 +423,21 @@ static int parse_reply_info_create(void **p, void *end,
425{ 423{
426 if (features == (u64)-1 || 424 if (features == (u64)-1 ||
427 (features & CEPH_FEATURE_REPLY_CREATE_INODE)) { 425 (features & CEPH_FEATURE_REPLY_CREATE_INODE)) {
426 /* Malformed reply? */
428 if (*p == end) { 427 if (*p == end) {
429 info->has_create_ino = false; 428 info->has_create_ino = false;
430 } else { 429 } else {
431 info->has_create_ino = true; 430 info->has_create_ino = true;
432 info->ino = ceph_decode_64(p); 431 ceph_decode_64_safe(p, end, info->ino, bad);
433 } 432 }
433 } else {
434 if (*p != end)
435 goto bad;
434 } 436 }
435 437
436 if (unlikely(*p != end)) 438 /* Skip over any unrecognized fields */
437 goto bad; 439 *p = end;
438 return 0; 440 return 0;
439
440bad: 441bad:
441 return -EIO; 442 return -EIO;
442} 443}
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index 2e9c7f493f99..c049c7b3aa87 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -169,18 +169,26 @@ cifs_read_super(struct super_block *sb)
169 else 169 else
170 sb->s_maxbytes = MAX_NON_LFS; 170 sb->s_maxbytes = MAX_NON_LFS;
171 171
172 /* BB FIXME fix time_gran to be larger for LANMAN sessions */ 172 /* Some very old servers like DOS and OS/2 used 2 second granularity */
173 sb->s_time_gran = 100; 173 if ((tcon->ses->server->vals->protocol_id == SMB10_PROT_ID) &&
174 174 ((tcon->ses->capabilities &
175 if (tcon->unix_ext) { 175 tcon->ses->server->vals->cap_nt_find) == 0) &&
176 ts = cifs_NTtimeToUnix(0); 176 !tcon->unix_ext) {
177 sb->s_time_gran = 1000000000; /* 1 second is max allowed gran */
178 ts = cnvrtDosUnixTm(cpu_to_le16(SMB_DATE_MIN), 0, 0);
177 sb->s_time_min = ts.tv_sec; 179 sb->s_time_min = ts.tv_sec;
178 ts = cifs_NTtimeToUnix(cpu_to_le64(S64_MAX)); 180 ts = cnvrtDosUnixTm(cpu_to_le16(SMB_DATE_MAX),
181 cpu_to_le16(SMB_TIME_MAX), 0);
179 sb->s_time_max = ts.tv_sec; 182 sb->s_time_max = ts.tv_sec;
180 } else { 183 } else {
181 ts = cnvrtDosUnixTm(cpu_to_le16(SMB_DATE_MIN), 0, 0); 184 /*
185 * Almost every server, including all SMB2+, uses DCE TIME
186 * ie 100 nanosecond units, since 1601. See MS-DTYP and MS-FSCC
187 */
188 sb->s_time_gran = 100;
189 ts = cifs_NTtimeToUnix(0);
182 sb->s_time_min = ts.tv_sec; 190 sb->s_time_min = ts.tv_sec;
183 ts = cnvrtDosUnixTm(cpu_to_le16(SMB_DATE_MAX), cpu_to_le16(SMB_TIME_MAX), 0); 191 ts = cifs_NTtimeToUnix(cpu_to_le64(S64_MAX));
184 sb->s_time_max = ts.tv_sec; 192 sb->s_time_max = ts.tv_sec;
185 } 193 }
186 194
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index 2e960e1049db..50dfd9049370 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -1210,7 +1210,7 @@ struct cifs_search_info {
1210 bool smallBuf:1; /* so we know which buf_release function to call */ 1210 bool smallBuf:1; /* so we know which buf_release function to call */
1211}; 1211};
1212 1212
1213#define ACL_NO_MODE -1 1213#define ACL_NO_MODE ((umode_t)(-1))
1214struct cifs_open_parms { 1214struct cifs_open_parms {
1215 struct cifs_tcon *tcon; 1215 struct cifs_tcon *tcon;
1216 struct cifs_sb_info *cifs_sb; 1216 struct cifs_sb_info *cifs_sb;
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 2850c3ce4391..a64dfa95a925 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -4264,7 +4264,7 @@ static int mount_get_conns(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
4264 server->ops->qfs_tcon(*xid, tcon); 4264 server->ops->qfs_tcon(*xid, tcon);
4265 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RO_CACHE) { 4265 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RO_CACHE) {
4266 if (tcon->fsDevInfo.DeviceCharacteristics & 4266 if (tcon->fsDevInfo.DeviceCharacteristics &
4267 FILE_READ_ONLY_DEVICE) 4267 cpu_to_le32(FILE_READ_ONLY_DEVICE))
4268 cifs_dbg(VFS, "mounted to read only share\n"); 4268 cifs_dbg(VFS, "mounted to read only share\n");
4269 else if ((cifs_sb->mnt_cifs_flags & 4269 else if ((cifs_sb->mnt_cifs_flags &
4270 CIFS_MOUNT_RW_CACHE) == 0) 4270 CIFS_MOUNT_RW_CACHE) == 0)
@@ -4445,7 +4445,7 @@ static int setup_dfs_tgt_conn(const char *path,
4445 int rc; 4445 int rc;
4446 struct dfs_info3_param ref = {0}; 4446 struct dfs_info3_param ref = {0};
4447 char *mdata = NULL, *fake_devname = NULL; 4447 char *mdata = NULL, *fake_devname = NULL;
4448 struct smb_vol fake_vol = {0}; 4448 struct smb_vol fake_vol = {NULL};
4449 4449
4450 cifs_dbg(FYI, "%s: dfs path: %s\n", __func__, path); 4450 cifs_dbg(FYI, "%s: dfs path: %s\n", __func__, path);
4451 4451
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index dd5ac841aefa..7ce689d31aa2 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -738,10 +738,16 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
738static int 738static int
739cifs_d_revalidate(struct dentry *direntry, unsigned int flags) 739cifs_d_revalidate(struct dentry *direntry, unsigned int flags)
740{ 740{
741 struct inode *inode;
742
741 if (flags & LOOKUP_RCU) 743 if (flags & LOOKUP_RCU)
742 return -ECHILD; 744 return -ECHILD;
743 745
744 if (d_really_is_positive(direntry)) { 746 if (d_really_is_positive(direntry)) {
747 inode = d_inode(direntry);
748 if ((flags & LOOKUP_REVAL) && !CIFS_CACHE_READ(CIFS_I(inode)))
749 CIFS_I(inode)->time = 0; /* force reval */
750
745 if (cifs_revalidate_dentry(direntry)) 751 if (cifs_revalidate_dentry(direntry))
746 return 0; 752 return 0;
747 else { 753 else {
@@ -752,7 +758,7 @@ cifs_d_revalidate(struct dentry *direntry, unsigned int flags)
752 * attributes will have been updated by 758 * attributes will have been updated by
753 * cifs_revalidate_dentry(). 759 * cifs_revalidate_dentry().
754 */ 760 */
755 if (IS_AUTOMOUNT(d_inode(direntry)) && 761 if (IS_AUTOMOUNT(inode) &&
756 !(direntry->d_flags & DCACHE_NEED_AUTOMOUNT)) { 762 !(direntry->d_flags & DCACHE_NEED_AUTOMOUNT)) {
757 spin_lock(&direntry->d_lock); 763 spin_lock(&direntry->d_lock);
758 direntry->d_flags |= DCACHE_NEED_AUTOMOUNT; 764 direntry->d_flags |= DCACHE_NEED_AUTOMOUNT;
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 4b95700c507c..5ad15de2bb4f 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -253,6 +253,12 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,
253 rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb, 253 rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb,
254 xid, fid); 254 xid, fid);
255 255
256 if (rc) {
257 server->ops->close(xid, tcon, fid);
258 if (rc == -ESTALE)
259 rc = -EOPENSTALE;
260 }
261
256out: 262out:
257 kfree(buf); 263 kfree(buf);
258 return rc; 264 return rc;
@@ -1840,13 +1846,12 @@ struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *cifs_inode,
1840{ 1846{
1841 struct cifsFileInfo *open_file = NULL; 1847 struct cifsFileInfo *open_file = NULL;
1842 struct cifs_sb_info *cifs_sb = CIFS_SB(cifs_inode->vfs_inode.i_sb); 1848 struct cifs_sb_info *cifs_sb = CIFS_SB(cifs_inode->vfs_inode.i_sb);
1843 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
1844 1849
1845 /* only filter by fsuid on multiuser mounts */ 1850 /* only filter by fsuid on multiuser mounts */
1846 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)) 1851 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER))
1847 fsuid_only = false; 1852 fsuid_only = false;
1848 1853
1849 spin_lock(&tcon->open_file_lock); 1854 spin_lock(&cifs_inode->open_file_lock);
1850 /* we could simply get the first_list_entry since write-only entries 1855 /* we could simply get the first_list_entry since write-only entries
1851 are always at the end of the list but since the first entry might 1856 are always at the end of the list but since the first entry might
1852 have a close pending, we go through the whole list */ 1857 have a close pending, we go through the whole list */
@@ -1858,7 +1863,7 @@ struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *cifs_inode,
1858 /* found a good file */ 1863 /* found a good file */
1859 /* lock it so it will not be closed on us */ 1864 /* lock it so it will not be closed on us */
1860 cifsFileInfo_get(open_file); 1865 cifsFileInfo_get(open_file);
1861 spin_unlock(&tcon->open_file_lock); 1866 spin_unlock(&cifs_inode->open_file_lock);
1862 return open_file; 1867 return open_file;
1863 } /* else might as well continue, and look for 1868 } /* else might as well continue, and look for
1864 another, or simply have the caller reopen it 1869 another, or simply have the caller reopen it
@@ -1866,7 +1871,7 @@ struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *cifs_inode,
1866 } else /* write only file */ 1871 } else /* write only file */
1867 break; /* write only files are last so must be done */ 1872 break; /* write only files are last so must be done */
1868 } 1873 }
1869 spin_unlock(&tcon->open_file_lock); 1874 spin_unlock(&cifs_inode->open_file_lock);
1870 return NULL; 1875 return NULL;
1871} 1876}
1872 1877
@@ -1877,7 +1882,6 @@ cifs_get_writable_file(struct cifsInodeInfo *cifs_inode, bool fsuid_only,
1877{ 1882{
1878 struct cifsFileInfo *open_file, *inv_file = NULL; 1883 struct cifsFileInfo *open_file, *inv_file = NULL;
1879 struct cifs_sb_info *cifs_sb; 1884 struct cifs_sb_info *cifs_sb;
1880 struct cifs_tcon *tcon;
1881 bool any_available = false; 1885 bool any_available = false;
1882 int rc = -EBADF; 1886 int rc = -EBADF;
1883 unsigned int refind = 0; 1887 unsigned int refind = 0;
@@ -1897,16 +1901,15 @@ cifs_get_writable_file(struct cifsInodeInfo *cifs_inode, bool fsuid_only,
1897 } 1901 }
1898 1902
1899 cifs_sb = CIFS_SB(cifs_inode->vfs_inode.i_sb); 1903 cifs_sb = CIFS_SB(cifs_inode->vfs_inode.i_sb);
1900 tcon = cifs_sb_master_tcon(cifs_sb);
1901 1904
1902 /* only filter by fsuid on multiuser mounts */ 1905 /* only filter by fsuid on multiuser mounts */
1903 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)) 1906 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER))
1904 fsuid_only = false; 1907 fsuid_only = false;
1905 1908
1906 spin_lock(&tcon->open_file_lock); 1909 spin_lock(&cifs_inode->open_file_lock);
1907refind_writable: 1910refind_writable:
1908 if (refind > MAX_REOPEN_ATT) { 1911 if (refind > MAX_REOPEN_ATT) {
1909 spin_unlock(&tcon->open_file_lock); 1912 spin_unlock(&cifs_inode->open_file_lock);
1910 return rc; 1913 return rc;
1911 } 1914 }
1912 list_for_each_entry(open_file, &cifs_inode->openFileList, flist) { 1915 list_for_each_entry(open_file, &cifs_inode->openFileList, flist) {
@@ -1918,7 +1921,7 @@ refind_writable:
1918 if (!open_file->invalidHandle) { 1921 if (!open_file->invalidHandle) {
1919 /* found a good writable file */ 1922 /* found a good writable file */
1920 cifsFileInfo_get(open_file); 1923 cifsFileInfo_get(open_file);
1921 spin_unlock(&tcon->open_file_lock); 1924 spin_unlock(&cifs_inode->open_file_lock);
1922 *ret_file = open_file; 1925 *ret_file = open_file;
1923 return 0; 1926 return 0;
1924 } else { 1927 } else {
@@ -1938,7 +1941,7 @@ refind_writable:
1938 cifsFileInfo_get(inv_file); 1941 cifsFileInfo_get(inv_file);
1939 } 1942 }
1940 1943
1941 spin_unlock(&tcon->open_file_lock); 1944 spin_unlock(&cifs_inode->open_file_lock);
1942 1945
1943 if (inv_file) { 1946 if (inv_file) {
1944 rc = cifs_reopen_file(inv_file, false); 1947 rc = cifs_reopen_file(inv_file, false);
@@ -1953,7 +1956,7 @@ refind_writable:
1953 cifsFileInfo_put(inv_file); 1956 cifsFileInfo_put(inv_file);
1954 ++refind; 1957 ++refind;
1955 inv_file = NULL; 1958 inv_file = NULL;
1956 spin_lock(&tcon->open_file_lock); 1959 spin_lock(&cifs_inode->open_file_lock);
1957 goto refind_writable; 1960 goto refind_writable;
1958 } 1961 }
1959 1962
@@ -4461,17 +4464,15 @@ static int cifs_readpage(struct file *file, struct page *page)
4461static int is_inode_writable(struct cifsInodeInfo *cifs_inode) 4464static int is_inode_writable(struct cifsInodeInfo *cifs_inode)
4462{ 4465{
4463 struct cifsFileInfo *open_file; 4466 struct cifsFileInfo *open_file;
4464 struct cifs_tcon *tcon =
4465 cifs_sb_master_tcon(CIFS_SB(cifs_inode->vfs_inode.i_sb));
4466 4467
4467 spin_lock(&tcon->open_file_lock); 4468 spin_lock(&cifs_inode->open_file_lock);
4468 list_for_each_entry(open_file, &cifs_inode->openFileList, flist) { 4469 list_for_each_entry(open_file, &cifs_inode->openFileList, flist) {
4469 if (OPEN_FMODE(open_file->f_flags) & FMODE_WRITE) { 4470 if (OPEN_FMODE(open_file->f_flags) & FMODE_WRITE) {
4470 spin_unlock(&tcon->open_file_lock); 4471 spin_unlock(&cifs_inode->open_file_lock);
4471 return 1; 4472 return 1;
4472 } 4473 }
4473 } 4474 }
4474 spin_unlock(&tcon->open_file_lock); 4475 spin_unlock(&cifs_inode->open_file_lock);
4475 return 0; 4476 return 0;
4476} 4477}
4477 4478
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index 3bae2e53f0b8..5dcc95b38310 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -414,6 +414,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
414 /* if uniqueid is different, return error */ 414 /* if uniqueid is different, return error */
415 if (unlikely(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM && 415 if (unlikely(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM &&
416 CIFS_I(*pinode)->uniqueid != fattr.cf_uniqueid)) { 416 CIFS_I(*pinode)->uniqueid != fattr.cf_uniqueid)) {
417 CIFS_I(*pinode)->time = 0; /* force reval */
417 rc = -ESTALE; 418 rc = -ESTALE;
418 goto cgiiu_exit; 419 goto cgiiu_exit;
419 } 420 }
@@ -421,6 +422,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
421 /* if filetype is different, return error */ 422 /* if filetype is different, return error */
422 if (unlikely(((*pinode)->i_mode & S_IFMT) != 423 if (unlikely(((*pinode)->i_mode & S_IFMT) !=
423 (fattr.cf_mode & S_IFMT))) { 424 (fattr.cf_mode & S_IFMT))) {
425 CIFS_I(*pinode)->time = 0; /* force reval */
424 rc = -ESTALE; 426 rc = -ESTALE;
425 goto cgiiu_exit; 427 goto cgiiu_exit;
426 } 428 }
@@ -933,6 +935,7 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
933 /* if uniqueid is different, return error */ 935 /* if uniqueid is different, return error */
934 if (unlikely(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM && 936 if (unlikely(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM &&
935 CIFS_I(*inode)->uniqueid != fattr.cf_uniqueid)) { 937 CIFS_I(*inode)->uniqueid != fattr.cf_uniqueid)) {
938 CIFS_I(*inode)->time = 0; /* force reval */
936 rc = -ESTALE; 939 rc = -ESTALE;
937 goto cgii_exit; 940 goto cgii_exit;
938 } 941 }
@@ -940,6 +943,7 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
940 /* if filetype is different, return error */ 943 /* if filetype is different, return error */
941 if (unlikely(((*inode)->i_mode & S_IFMT) != 944 if (unlikely(((*inode)->i_mode & S_IFMT) !=
942 (fattr.cf_mode & S_IFMT))) { 945 (fattr.cf_mode & S_IFMT))) {
946 CIFS_I(*inode)->time = 0; /* force reval */
943 rc = -ESTALE; 947 rc = -ESTALE;
944 goto cgii_exit; 948 goto cgii_exit;
945 } 949 }
diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
index 49c17ee18254..9b41436fb8db 100644
--- a/fs/cifs/netmisc.c
+++ b/fs/cifs/netmisc.c
@@ -117,10 +117,6 @@ static const struct smb_to_posix_error mapping_table_ERRSRV[] = {
117 {0, 0} 117 {0, 0}
118}; 118};
119 119
120static const struct smb_to_posix_error mapping_table_ERRHRD[] = {
121 {0, 0}
122};
123
124/* 120/*
125 * Convert a string containing text IPv4 or IPv6 address to binary form. 121 * Convert a string containing text IPv4 or IPv6 address to binary form.
126 * 122 *
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 85f9d614d968..05149862aea4 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -751,8 +751,8 @@ add_posix_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode)
751 unsigned int num = *num_iovec; 751 unsigned int num = *num_iovec;
752 752
753 iov[num].iov_base = create_posix_buf(mode); 753 iov[num].iov_base = create_posix_buf(mode);
754 if (mode == -1) 754 if (mode == ACL_NO_MODE)
755 cifs_dbg(VFS, "illegal mode\n"); /* BB REMOVEME */ 755 cifs_dbg(FYI, "illegal mode\n");
756 if (iov[num].iov_base == NULL) 756 if (iov[num].iov_base == NULL)
757 return -ENOMEM; 757 return -ENOMEM;
758 iov[num].iov_len = sizeof(struct create_posix); 758 iov[num].iov_len = sizeof(struct create_posix);
@@ -2521,11 +2521,8 @@ SMB2_open_init(struct cifs_tcon *tcon, struct smb_rqst *rqst, __u8 *oplock,
2521 return rc; 2521 return rc;
2522 } 2522 }
2523 2523
2524 /* TODO: add handling for the mode on create */ 2524 if ((oparms->disposition == FILE_CREATE) &&
2525 if (oparms->disposition == FILE_CREATE) 2525 (oparms->mode != ACL_NO_MODE)) {
2526 cifs_dbg(VFS, "mode is 0x%x\n", oparms->mode); /* BB REMOVEME */
2527
2528 if ((oparms->disposition == FILE_CREATE) && (oparms->mode != -1)) {
2529 if (n_iov > 2) { 2526 if (n_iov > 2) {
2530 struct create_context *ccontext = 2527 struct create_context *ccontext =
2531 (struct create_context *)iov[n_iov-1].iov_base; 2528 (struct create_context *)iov[n_iov-1].iov_base;
@@ -3217,7 +3214,8 @@ SMB2_notify_init(const unsigned int xid, struct smb_rqst *rqst,
3217 3214
3218 req->PersistentFileId = persistent_fid; 3215 req->PersistentFileId = persistent_fid;
3219 req->VolatileFileId = volatile_fid; 3216 req->VolatileFileId = volatile_fid;
3220 req->OutputBufferLength = SMB2_MAX_BUFFER_SIZE - MAX_SMB2_HDR_SIZE; 3217 req->OutputBufferLength =
3218 cpu_to_le32(SMB2_MAX_BUFFER_SIZE - MAX_SMB2_HDR_SIZE);
3221 req->CompletionFilter = cpu_to_le32(completion_filter); 3219 req->CompletionFilter = cpu_to_le32(completion_filter);
3222 if (watch_tree) 3220 if (watch_tree)
3223 req->Flags = cpu_to_le16(SMB2_WATCH_TREE); 3221 req->Flags = cpu_to_le16(SMB2_WATCH_TREE);
diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h
index da3a6d580808..71b2930b8e0b 100644
--- a/fs/cifs/smb2proto.h
+++ b/fs/cifs/smb2proto.h
@@ -150,6 +150,10 @@ extern int SMB2_ioctl_init(struct cifs_tcon *tcon, struct smb_rqst *rqst,
150 bool is_fsctl, char *in_data, u32 indatalen, 150 bool is_fsctl, char *in_data, u32 indatalen,
151 __u32 max_response_size); 151 __u32 max_response_size);
152extern void SMB2_ioctl_free(struct smb_rqst *rqst); 152extern void SMB2_ioctl_free(struct smb_rqst *rqst);
153extern int SMB2_change_notify(const unsigned int xid, struct cifs_tcon *tcon,
154 u64 persistent_fid, u64 volatile_fid, bool watch_tree,
155 u32 completion_filter);
156
153extern int SMB2_close(const unsigned int xid, struct cifs_tcon *tcon, 157extern int SMB2_close(const unsigned int xid, struct cifs_tcon *tcon,
154 u64 persistent_file_id, u64 volatile_file_id); 158 u64 persistent_file_id, u64 volatile_file_id);
155extern int SMB2_close_flags(const unsigned int xid, struct cifs_tcon *tcon, 159extern int SMB2_close_flags(const unsigned int xid, struct cifs_tcon *tcon,
diff --git a/fs/direct-io.c b/fs/direct-io.c
index ae196784f487..9329ced91f1d 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -241,9 +241,8 @@ void dio_warn_stale_pagecache(struct file *filp)
241 } 241 }
242} 242}
243 243
244/** 244/*
245 * dio_complete() - called when all DIO BIO I/O has been completed 245 * dio_complete() - called when all DIO BIO I/O has been completed
246 * @offset: the byte offset in the file of the completed operation
247 * 246 *
248 * This drops i_dio_count, lets interested parties know that a DIO operation 247 * This drops i_dio_count, lets interested parties know that a DIO operation
249 * has completed, and calculates the resulting return code for the operation. 248 * has completed, and calculates the resulting return code for the operation.
diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index 8a9fcbd0e8ac..fc3a8d8064f8 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -34,11 +34,15 @@ static void erofs_readendio(struct bio *bio)
34 34
35struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr) 35struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr)
36{ 36{
37 struct inode *const bd_inode = sb->s_bdev->bd_inode; 37 struct address_space *const mapping = sb->s_bdev->bd_inode->i_mapping;
38 struct address_space *const mapping = bd_inode->i_mapping; 38 struct page *page;
39 39
40 return read_cache_page_gfp(mapping, blkaddr, 40 page = read_cache_page_gfp(mapping, blkaddr,
41 mapping_gfp_constraint(mapping, ~__GFP_FS)); 41 mapping_gfp_constraint(mapping, ~__GFP_FS));
42 /* should already be PageUptodate */
43 if (!IS_ERR(page))
44 lock_page(page);
45 return page;
42} 46}
43 47
44static int erofs_map_blocks_flatmode(struct inode *inode, 48static int erofs_map_blocks_flatmode(struct inode *inode,
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index caf9a95173b0..0e369494f2f2 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -105,9 +105,9 @@ static int erofs_read_superblock(struct super_block *sb)
105 int ret; 105 int ret;
106 106
107 page = read_mapping_page(sb->s_bdev->bd_inode->i_mapping, 0, NULL); 107 page = read_mapping_page(sb->s_bdev->bd_inode->i_mapping, 0, NULL);
108 if (!page) { 108 if (IS_ERR(page)) {
109 erofs_err(sb, "cannot read erofs superblock"); 109 erofs_err(sb, "cannot read erofs superblock");
110 return -EIO; 110 return PTR_ERR(page);
111 } 111 }
112 112
113 sbi = EROFS_SB(sb); 113 sbi = EROFS_SB(sb);
diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index 96e34c90f814..fad80c97d247 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -575,7 +575,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
575 struct erofs_map_blocks *const map = &fe->map; 575 struct erofs_map_blocks *const map = &fe->map;
576 struct z_erofs_collector *const clt = &fe->clt; 576 struct z_erofs_collector *const clt = &fe->clt;
577 const loff_t offset = page_offset(page); 577 const loff_t offset = page_offset(page);
578 bool tight = (clt->mode >= COLLECT_PRIMARY_HOOKED); 578 bool tight = true;
579 579
580 enum z_erofs_cache_alloctype cache_strategy; 580 enum z_erofs_cache_alloctype cache_strategy;
581 enum z_erofs_page_type page_type; 581 enum z_erofs_page_type page_type;
@@ -628,8 +628,16 @@ restart_now:
628 preload_compressed_pages(clt, MNGD_MAPPING(sbi), 628 preload_compressed_pages(clt, MNGD_MAPPING(sbi),
629 cache_strategy, pagepool); 629 cache_strategy, pagepool);
630 630
631 tight &= (clt->mode >= COLLECT_PRIMARY_HOOKED);
632hitted: 631hitted:
632 /*
633 * Ensure the current partial page belongs to this submit chain rather
634 * than other concurrent submit chains or the noio(bypass) chain since
635 * those chains are handled asynchronously thus the page cannot be used
636 * for inplace I/O or pagevec (should be processed in strict order.)
637 */
638 tight &= (clt->mode >= COLLECT_PRIMARY_HOOKED &&
639 clt->mode != COLLECT_PRIMARY_FOLLOWED_NOINPLACE);
640
633 cur = end - min_t(unsigned int, offset + end - map->m_la, end); 641 cur = end - min_t(unsigned int, offset + end - map->m_la, end);
634 if (!(map->m_flags & EROFS_MAP_MAPPED)) { 642 if (!(map->m_flags & EROFS_MAP_MAPPED)) {
635 zero_user_segment(page, cur, end); 643 zero_user_segment(page, cur, end);
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 8aaa7eec7b74..8461a6322039 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -164,8 +164,13 @@ static void finish_writeback_work(struct bdi_writeback *wb,
164 164
165 if (work->auto_free) 165 if (work->auto_free)
166 kfree(work); 166 kfree(work);
167 if (done && atomic_dec_and_test(&done->cnt)) 167 if (done) {
168 wake_up_all(done->waitq); 168 wait_queue_head_t *waitq = done->waitq;
169
170 /* @done can't be accessed after the following dec */
171 if (atomic_dec_and_test(&done->cnt))
172 wake_up_all(waitq);
173 }
169} 174}
170 175
171static void wb_queue_work(struct bdi_writeback *wb, 176static void wb_queue_work(struct bdi_writeback *wb,
@@ -900,7 +905,7 @@ restart:
900 * cgroup_writeback_by_id - initiate cgroup writeback from bdi and memcg IDs 905 * cgroup_writeback_by_id - initiate cgroup writeback from bdi and memcg IDs
901 * @bdi_id: target bdi id 906 * @bdi_id: target bdi id
902 * @memcg_id: target memcg css id 907 * @memcg_id: target memcg css id
903 * @nr_pages: number of pages to write, 0 for best-effort dirty flushing 908 * @nr: number of pages to write, 0 for best-effort dirty flushing
904 * @reason: reason why some writeback work initiated 909 * @reason: reason why some writeback work initiated
905 * @done: target wb_completion 910 * @done: target wb_completion
906 * 911 *
diff --git a/fs/io_uring.c b/fs/io_uring.c
index aa8ac557493c..67dbe0201e0d 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -322,6 +322,8 @@ struct io_kiocb {
322#define REQ_F_FAIL_LINK 256 /* fail rest of links */ 322#define REQ_F_FAIL_LINK 256 /* fail rest of links */
323#define REQ_F_SHADOW_DRAIN 512 /* link-drain shadow req */ 323#define REQ_F_SHADOW_DRAIN 512 /* link-drain shadow req */
324#define REQ_F_TIMEOUT 1024 /* timeout request */ 324#define REQ_F_TIMEOUT 1024 /* timeout request */
325#define REQ_F_ISREG 2048 /* regular file */
326#define REQ_F_MUST_PUNT 4096 /* must be punted even for NONBLOCK */
325 u64 user_data; 327 u64 user_data;
326 u32 result; 328 u32 result;
327 u32 sequence; 329 u32 sequence;
@@ -415,27 +417,27 @@ static struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
415 return ctx; 417 return ctx;
416} 418}
417 419
420static inline bool __io_sequence_defer(struct io_ring_ctx *ctx,
421 struct io_kiocb *req)
422{
423 return req->sequence != ctx->cached_cq_tail + ctx->rings->sq_dropped;
424}
425
418static inline bool io_sequence_defer(struct io_ring_ctx *ctx, 426static inline bool io_sequence_defer(struct io_ring_ctx *ctx,
419 struct io_kiocb *req) 427 struct io_kiocb *req)
420{ 428{
421 /* timeout requests always honor sequence */ 429 if ((req->flags & (REQ_F_IO_DRAIN|REQ_F_IO_DRAINED)) != REQ_F_IO_DRAIN)
422 if (!(req->flags & REQ_F_TIMEOUT) &&
423 (req->flags & (REQ_F_IO_DRAIN|REQ_F_IO_DRAINED)) != REQ_F_IO_DRAIN)
424 return false; 430 return false;
425 431
426 return req->sequence != ctx->cached_cq_tail + ctx->rings->sq_dropped; 432 return __io_sequence_defer(ctx, req);
427} 433}
428 434
429static struct io_kiocb *__io_get_deferred_req(struct io_ring_ctx *ctx, 435static struct io_kiocb *io_get_deferred_req(struct io_ring_ctx *ctx)
430 struct list_head *list)
431{ 436{
432 struct io_kiocb *req; 437 struct io_kiocb *req;
433 438
434 if (list_empty(list)) 439 req = list_first_entry_or_null(&ctx->defer_list, struct io_kiocb, list);
435 return NULL; 440 if (req && !io_sequence_defer(ctx, req)) {
436
437 req = list_first_entry(list, struct io_kiocb, list);
438 if (!io_sequence_defer(ctx, req)) {
439 list_del_init(&req->list); 441 list_del_init(&req->list);
440 return req; 442 return req;
441 } 443 }
@@ -443,14 +445,17 @@ static struct io_kiocb *__io_get_deferred_req(struct io_ring_ctx *ctx,
443 return NULL; 445 return NULL;
444} 446}
445 447
446static struct io_kiocb *io_get_deferred_req(struct io_ring_ctx *ctx)
447{
448 return __io_get_deferred_req(ctx, &ctx->defer_list);
449}
450
451static struct io_kiocb *io_get_timeout_req(struct io_ring_ctx *ctx) 448static struct io_kiocb *io_get_timeout_req(struct io_ring_ctx *ctx)
452{ 449{
453 return __io_get_deferred_req(ctx, &ctx->timeout_list); 450 struct io_kiocb *req;
451
452 req = list_first_entry_or_null(&ctx->timeout_list, struct io_kiocb, list);
453 if (req && !__io_sequence_defer(ctx, req)) {
454 list_del_init(&req->list);
455 return req;
456 }
457
458 return NULL;
454} 459}
455 460
456static void __io_commit_cqring(struct io_ring_ctx *ctx) 461static void __io_commit_cqring(struct io_ring_ctx *ctx)
@@ -591,14 +596,6 @@ static void io_cqring_add_event(struct io_ring_ctx *ctx, u64 user_data,
591 io_cqring_ev_posted(ctx); 596 io_cqring_ev_posted(ctx);
592} 597}
593 598
594static void io_ring_drop_ctx_refs(struct io_ring_ctx *ctx, unsigned refs)
595{
596 percpu_ref_put_many(&ctx->refs, refs);
597
598 if (waitqueue_active(&ctx->wait))
599 wake_up(&ctx->wait);
600}
601
602static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx, 599static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx,
603 struct io_submit_state *state) 600 struct io_submit_state *state)
604{ 601{
@@ -646,7 +643,7 @@ static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx,
646 req->result = 0; 643 req->result = 0;
647 return req; 644 return req;
648out: 645out:
649 io_ring_drop_ctx_refs(ctx, 1); 646 percpu_ref_put(&ctx->refs);
650 return NULL; 647 return NULL;
651} 648}
652 649
@@ -654,7 +651,7 @@ static void io_free_req_many(struct io_ring_ctx *ctx, void **reqs, int *nr)
654{ 651{
655 if (*nr) { 652 if (*nr) {
656 kmem_cache_free_bulk(req_cachep, *nr, reqs); 653 kmem_cache_free_bulk(req_cachep, *nr, reqs);
657 io_ring_drop_ctx_refs(ctx, *nr); 654 percpu_ref_put_many(&ctx->refs, *nr);
658 *nr = 0; 655 *nr = 0;
659 } 656 }
660} 657}
@@ -663,7 +660,7 @@ static void __io_free_req(struct io_kiocb *req)
663{ 660{
664 if (req->file && !(req->flags & REQ_F_FIXED_FILE)) 661 if (req->file && !(req->flags & REQ_F_FIXED_FILE))
665 fput(req->file); 662 fput(req->file);
666 io_ring_drop_ctx_refs(req->ctx, 1); 663 percpu_ref_put(&req->ctx->refs);
667 kmem_cache_free(req_cachep, req); 664 kmem_cache_free(req_cachep, req);
668} 665}
669 666
@@ -919,26 +916,26 @@ static int io_iopoll_check(struct io_ring_ctx *ctx, unsigned *nr_events,
919 return ret; 916 return ret;
920} 917}
921 918
922static void kiocb_end_write(struct kiocb *kiocb) 919static void kiocb_end_write(struct io_kiocb *req)
923{ 920{
924 if (kiocb->ki_flags & IOCB_WRITE) { 921 /*
925 struct inode *inode = file_inode(kiocb->ki_filp); 922 * Tell lockdep we inherited freeze protection from submission
923 * thread.
924 */
925 if (req->flags & REQ_F_ISREG) {
926 struct inode *inode = file_inode(req->file);
926 927
927 /* 928 __sb_writers_acquired(inode->i_sb, SB_FREEZE_WRITE);
928 * Tell lockdep we inherited freeze protection from submission
929 * thread.
930 */
931 if (S_ISREG(inode->i_mode))
932 __sb_writers_acquired(inode->i_sb, SB_FREEZE_WRITE);
933 file_end_write(kiocb->ki_filp);
934 } 929 }
930 file_end_write(req->file);
935} 931}
936 932
937static void io_complete_rw(struct kiocb *kiocb, long res, long res2) 933static void io_complete_rw(struct kiocb *kiocb, long res, long res2)
938{ 934{
939 struct io_kiocb *req = container_of(kiocb, struct io_kiocb, rw); 935 struct io_kiocb *req = container_of(kiocb, struct io_kiocb, rw);
940 936
941 kiocb_end_write(kiocb); 937 if (kiocb->ki_flags & IOCB_WRITE)
938 kiocb_end_write(req);
942 939
943 if ((req->flags & REQ_F_LINK) && res != req->result) 940 if ((req->flags & REQ_F_LINK) && res != req->result)
944 req->flags |= REQ_F_FAIL_LINK; 941 req->flags |= REQ_F_FAIL_LINK;
@@ -950,7 +947,8 @@ static void io_complete_rw_iopoll(struct kiocb *kiocb, long res, long res2)
950{ 947{
951 struct io_kiocb *req = container_of(kiocb, struct io_kiocb, rw); 948 struct io_kiocb *req = container_of(kiocb, struct io_kiocb, rw);
952 949
953 kiocb_end_write(kiocb); 950 if (kiocb->ki_flags & IOCB_WRITE)
951 kiocb_end_write(req);
954 952
955 if ((req->flags & REQ_F_LINK) && res != req->result) 953 if ((req->flags & REQ_F_LINK) && res != req->result)
956 req->flags |= REQ_F_FAIL_LINK; 954 req->flags |= REQ_F_FAIL_LINK;
@@ -1064,8 +1062,17 @@ static int io_prep_rw(struct io_kiocb *req, const struct sqe_submit *s,
1064 if (!req->file) 1062 if (!req->file)
1065 return -EBADF; 1063 return -EBADF;
1066 1064
1067 if (force_nonblock && !io_file_supports_async(req->file)) 1065 if (S_ISREG(file_inode(req->file)->i_mode))
1068 force_nonblock = false; 1066 req->flags |= REQ_F_ISREG;
1067
1068 /*
1069 * If the file doesn't support async, mark it as REQ_F_MUST_PUNT so
1070 * we know to async punt it even if it was opened O_NONBLOCK
1071 */
1072 if (force_nonblock && !io_file_supports_async(req->file)) {
1073 req->flags |= REQ_F_MUST_PUNT;
1074 return -EAGAIN;
1075 }
1069 1076
1070 kiocb->ki_pos = READ_ONCE(sqe->off); 1077 kiocb->ki_pos = READ_ONCE(sqe->off);
1071 kiocb->ki_flags = iocb_flags(kiocb->ki_filp); 1078 kiocb->ki_flags = iocb_flags(kiocb->ki_filp);
@@ -1086,7 +1093,8 @@ static int io_prep_rw(struct io_kiocb *req, const struct sqe_submit *s,
1086 return ret; 1093 return ret;
1087 1094
1088 /* don't allow async punt if RWF_NOWAIT was requested */ 1095 /* don't allow async punt if RWF_NOWAIT was requested */
1089 if (kiocb->ki_flags & IOCB_NOWAIT) 1096 if ((kiocb->ki_flags & IOCB_NOWAIT) ||
1097 (req->file->f_flags & O_NONBLOCK))
1090 req->flags |= REQ_F_NOWAIT; 1098 req->flags |= REQ_F_NOWAIT;
1091 1099
1092 if (force_nonblock) 1100 if (force_nonblock)
@@ -1387,7 +1395,9 @@ static int io_read(struct io_kiocb *req, const struct sqe_submit *s,
1387 * need async punt anyway, so it's more efficient to do it 1395 * need async punt anyway, so it's more efficient to do it
1388 * here. 1396 * here.
1389 */ 1397 */
1390 if (force_nonblock && ret2 > 0 && ret2 < read_size) 1398 if (force_nonblock && !(req->flags & REQ_F_NOWAIT) &&
1399 (req->flags & REQ_F_ISREG) &&
1400 ret2 > 0 && ret2 < read_size)
1391 ret2 = -EAGAIN; 1401 ret2 = -EAGAIN;
1392 /* Catch -EAGAIN return for forced non-blocking submission */ 1402 /* Catch -EAGAIN return for forced non-blocking submission */
1393 if (!force_nonblock || ret2 != -EAGAIN) { 1403 if (!force_nonblock || ret2 != -EAGAIN) {
@@ -1452,7 +1462,7 @@ static int io_write(struct io_kiocb *req, const struct sqe_submit *s,
1452 * released so that it doesn't complain about the held lock when 1462 * released so that it doesn't complain about the held lock when
1453 * we return to userspace. 1463 * we return to userspace.
1454 */ 1464 */
1455 if (S_ISREG(file_inode(file)->i_mode)) { 1465 if (req->flags & REQ_F_ISREG) {
1456 __sb_start_write(file_inode(file)->i_sb, 1466 __sb_start_write(file_inode(file)->i_sb,
1457 SB_FREEZE_WRITE, true); 1467 SB_FREEZE_WRITE, true);
1458 __sb_writers_release(file_inode(file)->i_sb, 1468 __sb_writers_release(file_inode(file)->i_sb,
@@ -1889,18 +1899,18 @@ static enum hrtimer_restart io_timeout_fn(struct hrtimer *timer)
1889 1899
1890static int io_timeout(struct io_kiocb *req, const struct io_uring_sqe *sqe) 1900static int io_timeout(struct io_kiocb *req, const struct io_uring_sqe *sqe)
1891{ 1901{
1892 unsigned count, req_dist, tail_index; 1902 unsigned count;
1893 struct io_ring_ctx *ctx = req->ctx; 1903 struct io_ring_ctx *ctx = req->ctx;
1894 struct list_head *entry; 1904 struct list_head *entry;
1895 struct timespec ts; 1905 struct timespec64 ts;
1896 1906
1897 if (unlikely(ctx->flags & IORING_SETUP_IOPOLL)) 1907 if (unlikely(ctx->flags & IORING_SETUP_IOPOLL))
1898 return -EINVAL; 1908 return -EINVAL;
1899 if (sqe->flags || sqe->ioprio || sqe->buf_index || sqe->timeout_flags || 1909 if (sqe->flags || sqe->ioprio || sqe->buf_index || sqe->timeout_flags ||
1900 sqe->len != 1) 1910 sqe->len != 1)
1901 return -EINVAL; 1911 return -EINVAL;
1902 if (copy_from_user(&ts, (void __user *) (unsigned long) sqe->addr, 1912
1903 sizeof(ts))) 1913 if (get_timespec64(&ts, u64_to_user_ptr(sqe->addr)))
1904 return -EFAULT; 1914 return -EFAULT;
1905 1915
1906 /* 1916 /*
@@ -1912,21 +1922,36 @@ static int io_timeout(struct io_kiocb *req, const struct io_uring_sqe *sqe)
1912 count = 1; 1922 count = 1;
1913 1923
1914 req->sequence = ctx->cached_sq_head + count - 1; 1924 req->sequence = ctx->cached_sq_head + count - 1;
1925 /* reuse it to store the count */
1926 req->submit.sequence = count;
1915 req->flags |= REQ_F_TIMEOUT; 1927 req->flags |= REQ_F_TIMEOUT;
1916 1928
1917 /* 1929 /*
1918 * Insertion sort, ensuring the first entry in the list is always 1930 * Insertion sort, ensuring the first entry in the list is always
1919 * the one we need first. 1931 * the one we need first.
1920 */ 1932 */
1921 tail_index = ctx->cached_cq_tail - ctx->rings->sq_dropped;
1922 req_dist = req->sequence - tail_index;
1923 spin_lock_irq(&ctx->completion_lock); 1933 spin_lock_irq(&ctx->completion_lock);
1924 list_for_each_prev(entry, &ctx->timeout_list) { 1934 list_for_each_prev(entry, &ctx->timeout_list) {
1925 struct io_kiocb *nxt = list_entry(entry, struct io_kiocb, list); 1935 struct io_kiocb *nxt = list_entry(entry, struct io_kiocb, list);
1926 unsigned dist; 1936 unsigned nxt_sq_head;
1937 long long tmp, tmp_nxt;
1927 1938
1928 dist = nxt->sequence - tail_index; 1939 /*
1929 if (req_dist >= dist) 1940 * Since cached_sq_head + count - 1 can overflow, use type long
1941 * long to store it.
1942 */
1943 tmp = (long long)ctx->cached_sq_head + count - 1;
1944 nxt_sq_head = nxt->sequence - nxt->submit.sequence + 1;
1945 tmp_nxt = (long long)nxt_sq_head + nxt->submit.sequence - 1;
1946
1947 /*
1948 * cached_sq_head may overflow, and it will never overflow twice
1949 * once there is some timeout req still be valid.
1950 */
1951 if (ctx->cached_sq_head < nxt_sq_head)
1952 tmp += UINT_MAX;
1953
1954 if (tmp >= tmp_nxt)
1930 break; 1955 break;
1931 } 1956 }
1932 list_add(&req->list, entry); 1957 list_add(&req->list, entry);
@@ -1934,7 +1959,7 @@ static int io_timeout(struct io_kiocb *req, const struct io_uring_sqe *sqe)
1934 1959
1935 hrtimer_init(&req->timeout.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 1960 hrtimer_init(&req->timeout.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
1936 req->timeout.timer.function = io_timeout_fn; 1961 req->timeout.timer.function = io_timeout_fn;
1937 hrtimer_start(&req->timeout.timer, timespec_to_ktime(ts), 1962 hrtimer_start(&req->timeout.timer, timespec64_to_ktime(ts),
1938 HRTIMER_MODE_REL); 1963 HRTIMER_MODE_REL);
1939 return 0; 1964 return 0;
1940} 1965}
@@ -2272,7 +2297,13 @@ static int __io_queue_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req,
2272 int ret; 2297 int ret;
2273 2298
2274 ret = __io_submit_sqe(ctx, req, s, force_nonblock); 2299 ret = __io_submit_sqe(ctx, req, s, force_nonblock);
2275 if (ret == -EAGAIN && !(req->flags & REQ_F_NOWAIT)) { 2300
2301 /*
2302 * We async punt it if the file wasn't marked NOWAIT, or if the file
2303 * doesn't support non-blocking read/write attempts
2304 */
2305 if (ret == -EAGAIN && (!(req->flags & REQ_F_NOWAIT) ||
2306 (req->flags & REQ_F_MUST_PUNT))) {
2276 struct io_uring_sqe *sqe_copy; 2307 struct io_uring_sqe *sqe_copy;
2277 2308
2278 sqe_copy = kmemdup(s->sqe, sizeof(*sqe_copy), GFP_KERNEL); 2309 sqe_copy = kmemdup(s->sqe, sizeof(*sqe_copy), GFP_KERNEL);
@@ -2761,7 +2792,7 @@ out:
2761 2792
2762 if (link) 2793 if (link)
2763 io_queue_link_head(ctx, link, &link->submit, shadow_req, 2794 io_queue_link_head(ctx, link, &link->submit, shadow_req,
2764 block_for_last); 2795 !block_for_last);
2765 if (statep) 2796 if (statep)
2766 io_submit_state_end(statep); 2797 io_submit_state_end(statep);
2767 2798
@@ -2920,8 +2951,12 @@ static void io_finish_async(struct io_ring_ctx *ctx)
2920static void io_destruct_skb(struct sk_buff *skb) 2951static void io_destruct_skb(struct sk_buff *skb)
2921{ 2952{
2922 struct io_ring_ctx *ctx = skb->sk->sk_user_data; 2953 struct io_ring_ctx *ctx = skb->sk->sk_user_data;
2954 int i;
2955
2956 for (i = 0; i < ARRAY_SIZE(ctx->sqo_wq); i++)
2957 if (ctx->sqo_wq[i])
2958 flush_workqueue(ctx->sqo_wq[i]);
2923 2959
2924 io_finish_async(ctx);
2925 unix_destruct_scm(skb); 2960 unix_destruct_scm(skb);
2926} 2961}
2927 2962
@@ -3630,7 +3665,7 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
3630 } 3665 }
3631 } 3666 }
3632 3667
3633 io_ring_drop_ctx_refs(ctx, 1); 3668 percpu_ref_put(&ctx->refs);
3634out_fput: 3669out_fput:
3635 fdput(f); 3670 fdput(f);
3636 return submitted ? submitted : ret; 3671 return submitted ? submitted : ret;
diff --git a/fs/libfs.c b/fs/libfs.c
index c9b2850c0f7c..1463b038ffc4 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -89,58 +89,45 @@ int dcache_dir_close(struct inode *inode, struct file *file)
89EXPORT_SYMBOL(dcache_dir_close); 89EXPORT_SYMBOL(dcache_dir_close);
90 90
91/* parent is locked at least shared */ 91/* parent is locked at least shared */
92static struct dentry *next_positive(struct dentry *parent, 92/*
93 struct list_head *from, 93 * Returns an element of siblings' list.
94 int count) 94 * We are looking for <count>th positive after <p>; if
95 * found, dentry is grabbed and returned to caller.
96 * If no such element exists, NULL is returned.
97 */
98static struct dentry *scan_positives(struct dentry *cursor,
99 struct list_head *p,
100 loff_t count,
101 struct dentry *last)
95{ 102{
96 unsigned *seq = &parent->d_inode->i_dir_seq, n; 103 struct dentry *dentry = cursor->d_parent, *found = NULL;
97 struct dentry *res;
98 struct list_head *p;
99 bool skipped;
100 int i;
101 104
102retry: 105 spin_lock(&dentry->d_lock);
103 i = count; 106 while ((p = p->next) != &dentry->d_subdirs) {
104 skipped = false;
105 n = smp_load_acquire(seq) & ~1;
106 res = NULL;
107 rcu_read_lock();
108 for (p = from->next; p != &parent->d_subdirs; p = p->next) {
109 struct dentry *d = list_entry(p, struct dentry, d_child); 107 struct dentry *d = list_entry(p, struct dentry, d_child);
110 if (!simple_positive(d)) { 108 // we must at least skip cursors, to avoid livelocks
111 skipped = true; 109 if (d->d_flags & DCACHE_DENTRY_CURSOR)
112 } else if (!--i) { 110 continue;
113 res = d; 111 if (simple_positive(d) && !--count) {
114 break; 112 spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
113 if (simple_positive(d))
114 found = dget_dlock(d);
115 spin_unlock(&d->d_lock);
116 if (likely(found))
117 break;
118 count = 1;
119 }
120 if (need_resched()) {
121 list_move(&cursor->d_child, p);
122 p = &cursor->d_child;
123 spin_unlock(&dentry->d_lock);
124 cond_resched();
125 spin_lock(&dentry->d_lock);
115 } 126 }
116 } 127 }
117 rcu_read_unlock(); 128 spin_unlock(&dentry->d_lock);
118 if (skipped) { 129 dput(last);
119 smp_rmb(); 130 return found;
120 if (unlikely(*seq != n))
121 goto retry;
122 }
123 return res;
124}
125
126static void move_cursor(struct dentry *cursor, struct list_head *after)
127{
128 struct dentry *parent = cursor->d_parent;
129 unsigned n, *seq = &parent->d_inode->i_dir_seq;
130 spin_lock(&parent->d_lock);
131 for (;;) {
132 n = *seq;
133 if (!(n & 1) && cmpxchg(seq, n, n + 1) == n)
134 break;
135 cpu_relax();
136 }
137 __list_del(cursor->d_child.prev, cursor->d_child.next);
138 if (after)
139 list_add(&cursor->d_child, after);
140 else
141 list_add_tail(&cursor->d_child, &parent->d_subdirs);
142 smp_store_release(seq, n + 2);
143 spin_unlock(&parent->d_lock);
144} 131}
145 132
146loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence) 133loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence)
@@ -158,17 +145,25 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence)
158 return -EINVAL; 145 return -EINVAL;
159 } 146 }
160 if (offset != file->f_pos) { 147 if (offset != file->f_pos) {
148 struct dentry *cursor = file->private_data;
149 struct dentry *to = NULL;
150
151 inode_lock_shared(dentry->d_inode);
152
153 if (offset > 2)
154 to = scan_positives(cursor, &dentry->d_subdirs,
155 offset - 2, NULL);
156 spin_lock(&dentry->d_lock);
157 if (to)
158 list_move(&cursor->d_child, &to->d_child);
159 else
160 list_del_init(&cursor->d_child);
161 spin_unlock(&dentry->d_lock);
162 dput(to);
163
161 file->f_pos = offset; 164 file->f_pos = offset;
162 if (file->f_pos >= 2) { 165
163 struct dentry *cursor = file->private_data; 166 inode_unlock_shared(dentry->d_inode);
164 struct dentry *to;
165 loff_t n = file->f_pos - 2;
166
167 inode_lock_shared(dentry->d_inode);
168 to = next_positive(dentry, &dentry->d_subdirs, n);
169 move_cursor(cursor, to ? &to->d_child : NULL);
170 inode_unlock_shared(dentry->d_inode);
171 }
172 } 167 }
173 return offset; 168 return offset;
174} 169}
@@ -190,25 +185,35 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
190{ 185{
191 struct dentry *dentry = file->f_path.dentry; 186 struct dentry *dentry = file->f_path.dentry;
192 struct dentry *cursor = file->private_data; 187 struct dentry *cursor = file->private_data;
193 struct list_head *p = &cursor->d_child; 188 struct list_head *anchor = &dentry->d_subdirs;
194 struct dentry *next; 189 struct dentry *next = NULL;
195 bool moved = false; 190 struct list_head *p;
196 191
197 if (!dir_emit_dots(file, ctx)) 192 if (!dir_emit_dots(file, ctx))
198 return 0; 193 return 0;
199 194
200 if (ctx->pos == 2) 195 if (ctx->pos == 2)
201 p = &dentry->d_subdirs; 196 p = anchor;
202 while ((next = next_positive(dentry, p, 1)) != NULL) { 197 else if (!list_empty(&cursor->d_child))
198 p = &cursor->d_child;
199 else
200 return 0;
201
202 while ((next = scan_positives(cursor, p, 1, next)) != NULL) {
203 if (!dir_emit(ctx, next->d_name.name, next->d_name.len, 203 if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
204 d_inode(next)->i_ino, dt_type(d_inode(next)))) 204 d_inode(next)->i_ino, dt_type(d_inode(next))))
205 break; 205 break;
206 moved = true;
207 p = &next->d_child;
208 ctx->pos++; 206 ctx->pos++;
207 p = &next->d_child;
209 } 208 }
210 if (moved) 209 spin_lock(&dentry->d_lock);
211 move_cursor(cursor, p); 210 if (next)
211 list_move_tail(&cursor->d_child, &next->d_child);
212 else
213 list_del_init(&cursor->d_child);
214 spin_unlock(&dentry->d_lock);
215 dput(next);
216
212 return 0; 217 return 0;
213} 218}
214EXPORT_SYMBOL(dcache_readdir); 219EXPORT_SYMBOL(dcache_readdir);
@@ -468,8 +473,7 @@ EXPORT_SYMBOL(simple_write_begin);
468 473
469/** 474/**
470 * simple_write_end - .write_end helper for non-block-device FSes 475 * simple_write_end - .write_end helper for non-block-device FSes
471 * @available: See .write_end of address_space_operations 476 * @file: See .write_end of address_space_operations
472 * @file: "
473 * @mapping: " 477 * @mapping: "
474 * @pos: " 478 * @pos: "
475 * @len: " 479 * @len: "
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index 222d7115db71..040a50fd9bf3 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -64,13 +64,6 @@
64 64
65static struct kmem_cache *nfs_direct_cachep; 65static struct kmem_cache *nfs_direct_cachep;
66 66
67/*
68 * This represents a set of asynchronous requests that we're waiting on
69 */
70struct nfs_direct_mirror {
71 ssize_t count;
72};
73
74struct nfs_direct_req { 67struct nfs_direct_req {
75 struct kref kref; /* release manager */ 68 struct kref kref; /* release manager */
76 69
@@ -84,9 +77,6 @@ struct nfs_direct_req {
84 atomic_t io_count; /* i/os we're waiting for */ 77 atomic_t io_count; /* i/os we're waiting for */
85 spinlock_t lock; /* protect completion state */ 78 spinlock_t lock; /* protect completion state */
86 79
87 struct nfs_direct_mirror mirrors[NFS_PAGEIO_DESCRIPTOR_MIRROR_MAX];
88 int mirror_count;
89
90 loff_t io_start; /* Start offset for I/O */ 80 loff_t io_start; /* Start offset for I/O */
91 ssize_t count, /* bytes actually processed */ 81 ssize_t count, /* bytes actually processed */
92 max_count, /* max expected count */ 82 max_count, /* max expected count */
@@ -123,32 +113,42 @@ static inline int put_dreq(struct nfs_direct_req *dreq)
123} 113}
124 114
125static void 115static void
126nfs_direct_good_bytes(struct nfs_direct_req *dreq, struct nfs_pgio_header *hdr) 116nfs_direct_handle_truncated(struct nfs_direct_req *dreq,
117 const struct nfs_pgio_header *hdr,
118 ssize_t dreq_len)
127{ 119{
128 int i; 120 if (!(test_bit(NFS_IOHDR_ERROR, &hdr->flags) ||
129 ssize_t count; 121 test_bit(NFS_IOHDR_EOF, &hdr->flags)))
122 return;
123 if (dreq->max_count >= dreq_len) {
124 dreq->max_count = dreq_len;
125 if (dreq->count > dreq_len)
126 dreq->count = dreq_len;
127
128 if (test_bit(NFS_IOHDR_ERROR, &hdr->flags))
129 dreq->error = hdr->error;
130 else /* Clear outstanding error if this is EOF */
131 dreq->error = 0;
132 }
133}
130 134
131 WARN_ON_ONCE(dreq->count >= dreq->max_count); 135static void
136nfs_direct_count_bytes(struct nfs_direct_req *dreq,
137 const struct nfs_pgio_header *hdr)
138{
139 loff_t hdr_end = hdr->io_start + hdr->good_bytes;
140 ssize_t dreq_len = 0;
132 141
133 if (dreq->mirror_count == 1) { 142 if (hdr_end > dreq->io_start)
134 dreq->mirrors[hdr->pgio_mirror_idx].count += hdr->good_bytes; 143 dreq_len = hdr_end - dreq->io_start;
135 dreq->count += hdr->good_bytes;
136 } else {
137 /* mirrored writes */
138 count = dreq->mirrors[hdr->pgio_mirror_idx].count;
139 if (count + dreq->io_start < hdr->io_start + hdr->good_bytes) {
140 count = hdr->io_start + hdr->good_bytes - dreq->io_start;
141 dreq->mirrors[hdr->pgio_mirror_idx].count = count;
142 }
143 /* update the dreq->count by finding the minimum agreed count from all
144 * mirrors */
145 count = dreq->mirrors[0].count;
146 144
147 for (i = 1; i < dreq->mirror_count; i++) 145 nfs_direct_handle_truncated(dreq, hdr, dreq_len);
148 count = min(count, dreq->mirrors[i].count);
149 146
150 dreq->count = count; 147 if (dreq_len > dreq->max_count)
151 } 148 dreq_len = dreq->max_count;
149
150 if (dreq->count < dreq_len)
151 dreq->count = dreq_len;
152} 152}
153 153
154/* 154/*
@@ -293,18 +293,6 @@ void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo,
293 cinfo->completion_ops = &nfs_direct_commit_completion_ops; 293 cinfo->completion_ops = &nfs_direct_commit_completion_ops;
294} 294}
295 295
296static inline void nfs_direct_setup_mirroring(struct nfs_direct_req *dreq,
297 struct nfs_pageio_descriptor *pgio,
298 struct nfs_page *req)
299{
300 int mirror_count = 1;
301
302 if (pgio->pg_ops->pg_get_mirror_count)
303 mirror_count = pgio->pg_ops->pg_get_mirror_count(pgio, req);
304
305 dreq->mirror_count = mirror_count;
306}
307
308static inline struct nfs_direct_req *nfs_direct_req_alloc(void) 296static inline struct nfs_direct_req *nfs_direct_req_alloc(void)
309{ 297{
310 struct nfs_direct_req *dreq; 298 struct nfs_direct_req *dreq;
@@ -319,7 +307,6 @@ static inline struct nfs_direct_req *nfs_direct_req_alloc(void)
319 INIT_LIST_HEAD(&dreq->mds_cinfo.list); 307 INIT_LIST_HEAD(&dreq->mds_cinfo.list);
320 dreq->verf.committed = NFS_INVALID_STABLE_HOW; /* not set yet */ 308 dreq->verf.committed = NFS_INVALID_STABLE_HOW; /* not set yet */
321 INIT_WORK(&dreq->work, nfs_direct_write_schedule_work); 309 INIT_WORK(&dreq->work, nfs_direct_write_schedule_work);
322 dreq->mirror_count = 1;
323 spin_lock_init(&dreq->lock); 310 spin_lock_init(&dreq->lock);
324 311
325 return dreq; 312 return dreq;
@@ -402,20 +389,12 @@ static void nfs_direct_read_completion(struct nfs_pgio_header *hdr)
402 struct nfs_direct_req *dreq = hdr->dreq; 389 struct nfs_direct_req *dreq = hdr->dreq;
403 390
404 spin_lock(&dreq->lock); 391 spin_lock(&dreq->lock);
405 if (test_bit(NFS_IOHDR_ERROR, &hdr->flags))
406 dreq->error = hdr->error;
407
408 if (test_bit(NFS_IOHDR_REDO, &hdr->flags)) { 392 if (test_bit(NFS_IOHDR_REDO, &hdr->flags)) {
409 spin_unlock(&dreq->lock); 393 spin_unlock(&dreq->lock);
410 goto out_put; 394 goto out_put;
411 } 395 }
412 396
413 if (hdr->good_bytes != 0) 397 nfs_direct_count_bytes(dreq, hdr);
414 nfs_direct_good_bytes(dreq, hdr);
415
416 if (test_bit(NFS_IOHDR_EOF, &hdr->flags))
417 dreq->error = 0;
418
419 spin_unlock(&dreq->lock); 398 spin_unlock(&dreq->lock);
420 399
421 while (!list_empty(&hdr->pages)) { 400 while (!list_empty(&hdr->pages)) {
@@ -646,29 +625,22 @@ static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq)
646 LIST_HEAD(reqs); 625 LIST_HEAD(reqs);
647 struct nfs_commit_info cinfo; 626 struct nfs_commit_info cinfo;
648 LIST_HEAD(failed); 627 LIST_HEAD(failed);
649 int i;
650 628
651 nfs_init_cinfo_from_dreq(&cinfo, dreq); 629 nfs_init_cinfo_from_dreq(&cinfo, dreq);
652 nfs_direct_write_scan_commit_list(dreq->inode, &reqs, &cinfo); 630 nfs_direct_write_scan_commit_list(dreq->inode, &reqs, &cinfo);
653 631
654 dreq->count = 0; 632 dreq->count = 0;
633 dreq->max_count = 0;
634 list_for_each_entry(req, &reqs, wb_list)
635 dreq->max_count += req->wb_bytes;
655 dreq->verf.committed = NFS_INVALID_STABLE_HOW; 636 dreq->verf.committed = NFS_INVALID_STABLE_HOW;
656 nfs_clear_pnfs_ds_commit_verifiers(&dreq->ds_cinfo); 637 nfs_clear_pnfs_ds_commit_verifiers(&dreq->ds_cinfo);
657 for (i = 0; i < dreq->mirror_count; i++)
658 dreq->mirrors[i].count = 0;
659 get_dreq(dreq); 638 get_dreq(dreq);
660 639
661 nfs_pageio_init_write(&desc, dreq->inode, FLUSH_STABLE, false, 640 nfs_pageio_init_write(&desc, dreq->inode, FLUSH_STABLE, false,
662 &nfs_direct_write_completion_ops); 641 &nfs_direct_write_completion_ops);
663 desc.pg_dreq = dreq; 642 desc.pg_dreq = dreq;
664 643
665 req = nfs_list_entry(reqs.next);
666 nfs_direct_setup_mirroring(dreq, &desc, req);
667 if (desc.pg_error < 0) {
668 list_splice_init(&reqs, &failed);
669 goto out_failed;
670 }
671
672 list_for_each_entry_safe(req, tmp, &reqs, wb_list) { 644 list_for_each_entry_safe(req, tmp, &reqs, wb_list) {
673 /* Bump the transmission count */ 645 /* Bump the transmission count */
674 req->wb_nio++; 646 req->wb_nio++;
@@ -686,7 +658,6 @@ static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq)
686 } 658 }
687 nfs_pageio_complete(&desc); 659 nfs_pageio_complete(&desc);
688 660
689out_failed:
690 while (!list_empty(&failed)) { 661 while (!list_empty(&failed)) {
691 req = nfs_list_entry(failed.next); 662 req = nfs_list_entry(failed.next);
692 nfs_list_remove_request(req); 663 nfs_list_remove_request(req);
@@ -791,17 +762,13 @@ static void nfs_direct_write_completion(struct nfs_pgio_header *hdr)
791 nfs_init_cinfo_from_dreq(&cinfo, dreq); 762 nfs_init_cinfo_from_dreq(&cinfo, dreq);
792 763
793 spin_lock(&dreq->lock); 764 spin_lock(&dreq->lock);
794
795 if (test_bit(NFS_IOHDR_ERROR, &hdr->flags))
796 dreq->error = hdr->error;
797
798 if (test_bit(NFS_IOHDR_REDO, &hdr->flags)) { 765 if (test_bit(NFS_IOHDR_REDO, &hdr->flags)) {
799 spin_unlock(&dreq->lock); 766 spin_unlock(&dreq->lock);
800 goto out_put; 767 goto out_put;
801 } 768 }
802 769
770 nfs_direct_count_bytes(dreq, hdr);
803 if (hdr->good_bytes != 0) { 771 if (hdr->good_bytes != 0) {
804 nfs_direct_good_bytes(dreq, hdr);
805 if (nfs_write_need_commit(hdr)) { 772 if (nfs_write_need_commit(hdr)) {
806 if (dreq->flags == NFS_ODIRECT_RESCHED_WRITES) 773 if (dreq->flags == NFS_ODIRECT_RESCHED_WRITES)
807 request_commit = true; 774 request_commit = true;
@@ -923,7 +890,6 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq,
923 break; 890 break;
924 } 891 }
925 892
926 nfs_direct_setup_mirroring(dreq, &desc, req);
927 if (desc.pg_error < 0) { 893 if (desc.pg_error < 0) {
928 nfs_free_request(req); 894 nfs_free_request(req);
929 result = desc.pg_error; 895 result = desc.pg_error;
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 11eafcfc490b..ab8ca20fd579 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -6106,6 +6106,7 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
6106 6106
6107 status = nfs4_call_sync_custom(&task_setup_data); 6107 status = nfs4_call_sync_custom(&task_setup_data);
6108 if (setclientid.sc_cred) { 6108 if (setclientid.sc_cred) {
6109 kfree(clp->cl_acceptor);
6109 clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); 6110 clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred);
6110 put_rpccred(setclientid.sc_cred); 6111 put_rpccred(setclientid.sc_cred);
6111 } 6112 }
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 85ca49549b39..52cab65f91cf 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -786,7 +786,6 @@ static void nfs_inode_remove_request(struct nfs_page *req)
786 struct nfs_inode *nfsi = NFS_I(inode); 786 struct nfs_inode *nfsi = NFS_I(inode);
787 struct nfs_page *head; 787 struct nfs_page *head;
788 788
789 atomic_long_dec(&nfsi->nrequests);
790 if (nfs_page_group_sync_on_bit(req, PG_REMOVE)) { 789 if (nfs_page_group_sync_on_bit(req, PG_REMOVE)) {
791 head = req->wb_head; 790 head = req->wb_head;
792 791
@@ -799,8 +798,10 @@ static void nfs_inode_remove_request(struct nfs_page *req)
799 spin_unlock(&mapping->private_lock); 798 spin_unlock(&mapping->private_lock);
800 } 799 }
801 800
802 if (test_and_clear_bit(PG_INODE_REF, &req->wb_flags)) 801 if (test_and_clear_bit(PG_INODE_REF, &req->wb_flags)) {
803 nfs_release_request(req); 802 nfs_release_request(req);
803 atomic_long_dec(&nfsi->nrequests);
804 }
804} 805}
805 806
806static void 807static void
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index 8de1c9d644f6..9cd0a6815933 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -2049,7 +2049,8 @@ out_write_size:
2049 inode->i_mtime = inode->i_ctime = current_time(inode); 2049 inode->i_mtime = inode->i_ctime = current_time(inode);
2050 di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec); 2050 di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec);
2051 di->i_mtime_nsec = di->i_ctime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec); 2051 di->i_mtime_nsec = di->i_ctime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
2052 ocfs2_update_inode_fsync_trans(handle, inode, 1); 2052 if (handle)
2053 ocfs2_update_inode_fsync_trans(handle, inode, 1);
2053 } 2054 }
2054 if (handle) 2055 if (handle)
2055 ocfs2_journal_dirty(handle, wc->w_di_bh); 2056 ocfs2_journal_dirty(handle, wc->w_di_bh);
@@ -2146,13 +2147,30 @@ static int ocfs2_dio_wr_get_block(struct inode *inode, sector_t iblock,
2146 struct ocfs2_dio_write_ctxt *dwc = NULL; 2147 struct ocfs2_dio_write_ctxt *dwc = NULL;
2147 struct buffer_head *di_bh = NULL; 2148 struct buffer_head *di_bh = NULL;
2148 u64 p_blkno; 2149 u64 p_blkno;
2149 loff_t pos = iblock << inode->i_sb->s_blocksize_bits; 2150 unsigned int i_blkbits = inode->i_sb->s_blocksize_bits;
2151 loff_t pos = iblock << i_blkbits;
2152 sector_t endblk = (i_size_read(inode) - 1) >> i_blkbits;
2150 unsigned len, total_len = bh_result->b_size; 2153 unsigned len, total_len = bh_result->b_size;
2151 int ret = 0, first_get_block = 0; 2154 int ret = 0, first_get_block = 0;
2152 2155
2153 len = osb->s_clustersize - (pos & (osb->s_clustersize - 1)); 2156 len = osb->s_clustersize - (pos & (osb->s_clustersize - 1));
2154 len = min(total_len, len); 2157 len = min(total_len, len);
2155 2158
2159 /*
2160 * bh_result->b_size is count in get_more_blocks according to write
2161 * "pos" and "end", we need map twice to return different buffer state:
2162 * 1. area in file size, not set NEW;
2163 * 2. area out file size, set NEW.
2164 *
2165 * iblock endblk
2166 * |--------|---------|---------|---------
2167 * |<-------area in file------->|
2168 */
2169
2170 if ((iblock <= endblk) &&
2171 ((iblock + ((len - 1) >> i_blkbits)) > endblk))
2172 len = (endblk - iblock + 1) << i_blkbits;
2173
2156 mlog(0, "get block of %lu at %llu:%u req %u\n", 2174 mlog(0, "get block of %lu at %llu:%u req %u\n",
2157 inode->i_ino, pos, len, total_len); 2175 inode->i_ino, pos, len, total_len);
2158 2176
@@ -2236,6 +2254,9 @@ static int ocfs2_dio_wr_get_block(struct inode *inode, sector_t iblock,
2236 if (desc->c_needs_zero) 2254 if (desc->c_needs_zero)
2237 set_buffer_new(bh_result); 2255 set_buffer_new(bh_result);
2238 2256
2257 if (iblock > endblk)
2258 set_buffer_new(bh_result);
2259
2239 /* May sleep in end_io. It should not happen in a irq context. So defer 2260 /* May sleep in end_io. It should not happen in a irq context. So defer
2240 * it to dio work queue. */ 2261 * it to dio work queue. */
2241 set_buffer_defer_completion(bh_result); 2262 set_buffer_defer_completion(bh_result);
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 2e982db3e1ae..53939bf9d7d2 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -1230,6 +1230,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
1230 transfer_to[USRQUOTA] = dqget(sb, make_kqid_uid(attr->ia_uid)); 1230 transfer_to[USRQUOTA] = dqget(sb, make_kqid_uid(attr->ia_uid));
1231 if (IS_ERR(transfer_to[USRQUOTA])) { 1231 if (IS_ERR(transfer_to[USRQUOTA])) {
1232 status = PTR_ERR(transfer_to[USRQUOTA]); 1232 status = PTR_ERR(transfer_to[USRQUOTA]);
1233 transfer_to[USRQUOTA] = NULL;
1233 goto bail_unlock; 1234 goto bail_unlock;
1234 } 1235 }
1235 } 1236 }
@@ -1239,6 +1240,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
1239 transfer_to[GRPQUOTA] = dqget(sb, make_kqid_gid(attr->ia_gid)); 1240 transfer_to[GRPQUOTA] = dqget(sb, make_kqid_gid(attr->ia_gid));
1240 if (IS_ERR(transfer_to[GRPQUOTA])) { 1241 if (IS_ERR(transfer_to[GRPQUOTA])) {
1241 status = PTR_ERR(transfer_to[GRPQUOTA]); 1242 status = PTR_ERR(transfer_to[GRPQUOTA]);
1243 transfer_to[GRPQUOTA] = NULL;
1242 goto bail_unlock; 1244 goto bail_unlock;
1243 } 1245 }
1244 } 1246 }
diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c
index d6f7b299eb23..efeea208fdeb 100644
--- a/fs/ocfs2/ioctl.c
+++ b/fs/ocfs2/ioctl.c
@@ -283,7 +283,7 @@ static int ocfs2_info_scan_inode_alloc(struct ocfs2_super *osb,
283 if (inode_alloc) 283 if (inode_alloc)
284 inode_lock(inode_alloc); 284 inode_lock(inode_alloc);
285 285
286 if (o2info_coherent(&fi->ifi_req)) { 286 if (inode_alloc && o2info_coherent(&fi->ifi_req)) {
287 status = ocfs2_inode_lock(inode_alloc, &bh, 0); 287 status = ocfs2_inode_lock(inode_alloc, &bh, 0);
288 if (status < 0) { 288 if (status < 0) {
289 mlog_errno(status); 289 mlog_errno(status);
diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
index 930e3d388579..699a560efbb0 100644
--- a/fs/ocfs2/journal.c
+++ b/fs/ocfs2/journal.c
@@ -217,7 +217,8 @@ void ocfs2_recovery_exit(struct ocfs2_super *osb)
217 /* At this point, we know that no more recovery threads can be 217 /* At this point, we know that no more recovery threads can be
218 * launched, so wait for any recovery completion work to 218 * launched, so wait for any recovery completion work to
219 * complete. */ 219 * complete. */
220 flush_workqueue(osb->ocfs2_wq); 220 if (osb->ocfs2_wq)
221 flush_workqueue(osb->ocfs2_wq);
221 222
222 /* 223 /*
223 * Now that recovery is shut down, and the osb is about to be 224 * Now that recovery is shut down, and the osb is about to be
diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
index 158e5af767fd..720e9f94957e 100644
--- a/fs/ocfs2/localalloc.c
+++ b/fs/ocfs2/localalloc.c
@@ -377,7 +377,8 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb)
377 struct ocfs2_dinode *alloc = NULL; 377 struct ocfs2_dinode *alloc = NULL;
378 378
379 cancel_delayed_work(&osb->la_enable_wq); 379 cancel_delayed_work(&osb->la_enable_wq);
380 flush_workqueue(osb->ocfs2_wq); 380 if (osb->ocfs2_wq)
381 flush_workqueue(osb->ocfs2_wq);
381 382
382 if (osb->local_alloc_state == OCFS2_LA_UNUSED) 383 if (osb->local_alloc_state == OCFS2_LA_UNUSED)
383 goto out; 384 goto out;
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 90c830e3758e..d8507972ee13 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -1490,18 +1490,6 @@ static int ocfs2_xa_check_space(struct ocfs2_xa_loc *loc,
1490 return loc->xl_ops->xlo_check_space(loc, xi); 1490 return loc->xl_ops->xlo_check_space(loc, xi);
1491} 1491}
1492 1492
1493static void ocfs2_xa_add_entry(struct ocfs2_xa_loc *loc, u32 name_hash)
1494{
1495 loc->xl_ops->xlo_add_entry(loc, name_hash);
1496 loc->xl_entry->xe_name_hash = cpu_to_le32(name_hash);
1497 /*
1498 * We can't leave the new entry's xe_name_offset at zero or
1499 * add_namevalue() will go nuts. We set it to the size of our
1500 * storage so that it can never be less than any other entry.
1501 */
1502 loc->xl_entry->xe_name_offset = cpu_to_le16(loc->xl_size);
1503}
1504
1505static void ocfs2_xa_add_namevalue(struct ocfs2_xa_loc *loc, 1493static void ocfs2_xa_add_namevalue(struct ocfs2_xa_loc *loc,
1506 struct ocfs2_xattr_info *xi) 1494 struct ocfs2_xattr_info *xi)
1507{ 1495{
@@ -2133,29 +2121,31 @@ static int ocfs2_xa_prepare_entry(struct ocfs2_xa_loc *loc,
2133 if (rc) 2121 if (rc)
2134 goto out; 2122 goto out;
2135 2123
2136 if (loc->xl_entry) { 2124 if (!loc->xl_entry) {
2137 if (ocfs2_xa_can_reuse_entry(loc, xi)) { 2125 rc = -EINVAL;
2138 orig_value_size = loc->xl_entry->xe_value_size; 2126 goto out;
2139 rc = ocfs2_xa_reuse_entry(loc, xi, ctxt); 2127 }
2140 if (rc)
2141 goto out;
2142 goto alloc_value;
2143 }
2144 2128
2145 if (!ocfs2_xattr_is_local(loc->xl_entry)) { 2129 if (ocfs2_xa_can_reuse_entry(loc, xi)) {
2146 orig_clusters = ocfs2_xa_value_clusters(loc); 2130 orig_value_size = loc->xl_entry->xe_value_size;
2147 rc = ocfs2_xa_value_truncate(loc, 0, ctxt); 2131 rc = ocfs2_xa_reuse_entry(loc, xi, ctxt);
2148 if (rc) { 2132 if (rc)
2149 mlog_errno(rc); 2133 goto out;
2150 ocfs2_xa_cleanup_value_truncate(loc, 2134 goto alloc_value;
2151 "overwriting", 2135 }
2152 orig_clusters); 2136
2153 goto out; 2137 if (!ocfs2_xattr_is_local(loc->xl_entry)) {
2154 } 2138 orig_clusters = ocfs2_xa_value_clusters(loc);
2139 rc = ocfs2_xa_value_truncate(loc, 0, ctxt);
2140 if (rc) {
2141 mlog_errno(rc);
2142 ocfs2_xa_cleanup_value_truncate(loc,
2143 "overwriting",
2144 orig_clusters);
2145 goto out;
2155 } 2146 }
2156 ocfs2_xa_wipe_namevalue(loc); 2147 }
2157 } else 2148 ocfs2_xa_wipe_namevalue(loc);
2158 ocfs2_xa_add_entry(loc, name_hash);
2159 2149
2160 /* 2150 /*
2161 * If we get here, we have a blank entry. Fill it. We grow our 2151 * If we get here, we have a blank entry. Fill it. We grow our
diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index ac9247371871..8c1f1bb1a5ce 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -132,9 +132,9 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
132 global_node_page_state(NR_SHMEM_THPS) * HPAGE_PMD_NR); 132 global_node_page_state(NR_SHMEM_THPS) * HPAGE_PMD_NR);
133 show_val_kb(m, "ShmemPmdMapped: ", 133 show_val_kb(m, "ShmemPmdMapped: ",
134 global_node_page_state(NR_SHMEM_PMDMAPPED) * HPAGE_PMD_NR); 134 global_node_page_state(NR_SHMEM_PMDMAPPED) * HPAGE_PMD_NR);
135 show_val_kb(m, "FileHugePages: ", 135 show_val_kb(m, "FileHugePages: ",
136 global_node_page_state(NR_FILE_THPS) * HPAGE_PMD_NR); 136 global_node_page_state(NR_FILE_THPS) * HPAGE_PMD_NR);
137 show_val_kb(m, "FilePmdMapped: ", 137 show_val_kb(m, "FilePmdMapped: ",
138 global_node_page_state(NR_FILE_PMDMAPPED) * HPAGE_PMD_NR); 138 global_node_page_state(NR_FILE_PMDMAPPED) * HPAGE_PMD_NR);
139#endif 139#endif
140 140
diff --git a/fs/proc/page.c b/fs/proc/page.c
index 544d1ee15aee..7c952ee732e6 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -42,10 +42,12 @@ static ssize_t kpagecount_read(struct file *file, char __user *buf,
42 return -EINVAL; 42 return -EINVAL;
43 43
44 while (count > 0) { 44 while (count > 0) {
45 if (pfn_valid(pfn)) 45 /*
46 ppage = pfn_to_page(pfn); 46 * TODO: ZONE_DEVICE support requires to identify
47 else 47 * memmaps that were actually initialized.
48 ppage = NULL; 48 */
49 ppage = pfn_to_online_page(pfn);
50
49 if (!ppage || PageSlab(ppage) || page_has_type(ppage)) 51 if (!ppage || PageSlab(ppage) || page_has_type(ppage))
50 pcount = 0; 52 pcount = 0;
51 else 53 else
@@ -216,10 +218,11 @@ static ssize_t kpageflags_read(struct file *file, char __user *buf,
216 return -EINVAL; 218 return -EINVAL;
217 219
218 while (count > 0) { 220 while (count > 0) {
219 if (pfn_valid(pfn)) 221 /*
220 ppage = pfn_to_page(pfn); 222 * TODO: ZONE_DEVICE support requires to identify
221 else 223 * memmaps that were actually initialized.
222 ppage = NULL; 224 */
225 ppage = pfn_to_online_page(pfn);
223 226
224 if (put_user(stable_page_flags(ppage), out)) { 227 if (put_user(stable_page_flags(ppage), out)) {
225 ret = -EFAULT; 228 ret = -EFAULT;
@@ -261,10 +264,11 @@ static ssize_t kpagecgroup_read(struct file *file, char __user *buf,
261 return -EINVAL; 264 return -EINVAL;
262 265
263 while (count > 0) { 266 while (count > 0) {
264 if (pfn_valid(pfn)) 267 /*
265 ppage = pfn_to_page(pfn); 268 * TODO: ZONE_DEVICE support requires to identify
266 else 269 * memmaps that were actually initialized.
267 ppage = NULL; 270 */
271 ppage = pfn_to_online_page(pfn);
268 272
269 if (ppage) 273 if (ppage)
270 ino = page_cgroup_ino(ppage); 274 ino = page_cgroup_ino(ppage);
diff --git a/fs/readdir.c b/fs/readdir.c
index 2f6a4534e0df..d26d5ea4de7b 100644
--- a/fs/readdir.c
+++ b/fs/readdir.c
@@ -20,9 +20,23 @@
20#include <linux/syscalls.h> 20#include <linux/syscalls.h>
21#include <linux/unistd.h> 21#include <linux/unistd.h>
22#include <linux/compat.h> 22#include <linux/compat.h>
23
24#include <linux/uaccess.h> 23#include <linux/uaccess.h>
25 24
25#include <asm/unaligned.h>
26
27/*
28 * Note the "unsafe_put_user() semantics: we goto a
29 * label for errors.
30 */
31#define unsafe_copy_dirent_name(_dst, _src, _len, label) do { \
32 char __user *dst = (_dst); \
33 const char *src = (_src); \
34 size_t len = (_len); \
35 unsafe_put_user(0, dst+len, label); \
36 unsafe_copy_to_user(dst, src, len, label); \
37} while (0)
38
39
26int iterate_dir(struct file *file, struct dir_context *ctx) 40int iterate_dir(struct file *file, struct dir_context *ctx)
27{ 41{
28 struct inode *inode = file_inode(file); 42 struct inode *inode = file_inode(file);
@@ -65,6 +79,40 @@ out:
65EXPORT_SYMBOL(iterate_dir); 79EXPORT_SYMBOL(iterate_dir);
66 80
67/* 81/*
82 * POSIX says that a dirent name cannot contain NULL or a '/'.
83 *
84 * It's not 100% clear what we should really do in this case.
85 * The filesystem is clearly corrupted, but returning a hard
86 * error means that you now don't see any of the other names
87 * either, so that isn't a perfect alternative.
88 *
89 * And if you return an error, what error do you use? Several
90 * filesystems seem to have decided on EUCLEAN being the error
91 * code for EFSCORRUPTED, and that may be the error to use. Or
92 * just EIO, which is perhaps more obvious to users.
93 *
94 * In order to see the other file names in the directory, the
95 * caller might want to make this a "soft" error: skip the
96 * entry, and return the error at the end instead.
97 *
98 * Note that this should likely do a "memchr(name, 0, len)"
99 * check too, since that would be filesystem corruption as
100 * well. However, that case can't actually confuse user space,
101 * which has to do a strlen() on the name anyway to find the
102 * filename length, and the above "soft error" worry means
103 * that it's probably better left alone until we have that
104 * issue clarified.
105 */
106static int verify_dirent_name(const char *name, int len)
107{
108 if (!len)
109 return -EIO;
110 if (memchr(name, '/', len))
111 return -EIO;
112 return 0;
113}
114
115/*
68 * Traditional linux readdir() handling.. 116 * Traditional linux readdir() handling..
69 * 117 *
70 * "count=1" is a special case, meaning that the buffer is one 118 * "count=1" is a special case, meaning that the buffer is one
@@ -173,6 +221,9 @@ static int filldir(struct dir_context *ctx, const char *name, int namlen,
173 int reclen = ALIGN(offsetof(struct linux_dirent, d_name) + namlen + 2, 221 int reclen = ALIGN(offsetof(struct linux_dirent, d_name) + namlen + 2,
174 sizeof(long)); 222 sizeof(long));
175 223
224 buf->error = verify_dirent_name(name, namlen);
225 if (unlikely(buf->error))
226 return buf->error;
176 buf->error = -EINVAL; /* only used if we fail.. */ 227 buf->error = -EINVAL; /* only used if we fail.. */
177 if (reclen > buf->count) 228 if (reclen > buf->count)
178 return -EINVAL; 229 return -EINVAL;
@@ -182,28 +233,31 @@ static int filldir(struct dir_context *ctx, const char *name, int namlen,
182 return -EOVERFLOW; 233 return -EOVERFLOW;
183 } 234 }
184 dirent = buf->previous; 235 dirent = buf->previous;
185 if (dirent) { 236 if (dirent && signal_pending(current))
186 if (signal_pending(current)) 237 return -EINTR;
187 return -EINTR; 238
188 if (__put_user(offset, &dirent->d_off)) 239 /*
189 goto efault; 240 * Note! This range-checks 'previous' (which may be NULL).
190 } 241 * The real range was checked in getdents
191 dirent = buf->current_dir; 242 */
192 if (__put_user(d_ino, &dirent->d_ino)) 243 if (!user_access_begin(dirent, sizeof(*dirent)))
193 goto efault;
194 if (__put_user(reclen, &dirent->d_reclen))
195 goto efault;
196 if (copy_to_user(dirent->d_name, name, namlen))
197 goto efault;
198 if (__put_user(0, dirent->d_name + namlen))
199 goto efault;
200 if (__put_user(d_type, (char __user *) dirent + reclen - 1))
201 goto efault; 244 goto efault;
245 if (dirent)
246 unsafe_put_user(offset, &dirent->d_off, efault_end);
247 dirent = buf->current_dir;
248 unsafe_put_user(d_ino, &dirent->d_ino, efault_end);
249 unsafe_put_user(reclen, &dirent->d_reclen, efault_end);
250 unsafe_put_user(d_type, (char __user *) dirent + reclen - 1, efault_end);
251 unsafe_copy_dirent_name(dirent->d_name, name, namlen, efault_end);
252 user_access_end();
253
202 buf->previous = dirent; 254 buf->previous = dirent;
203 dirent = (void __user *)dirent + reclen; 255 dirent = (void __user *)dirent + reclen;
204 buf->current_dir = dirent; 256 buf->current_dir = dirent;
205 buf->count -= reclen; 257 buf->count -= reclen;
206 return 0; 258 return 0;
259efault_end:
260 user_access_end();
207efault: 261efault:
208 buf->error = -EFAULT; 262 buf->error = -EFAULT;
209 return -EFAULT; 263 return -EFAULT;
@@ -259,34 +313,38 @@ static int filldir64(struct dir_context *ctx, const char *name, int namlen,
259 int reclen = ALIGN(offsetof(struct linux_dirent64, d_name) + namlen + 1, 313 int reclen = ALIGN(offsetof(struct linux_dirent64, d_name) + namlen + 1,
260 sizeof(u64)); 314 sizeof(u64));
261 315
316 buf->error = verify_dirent_name(name, namlen);
317 if (unlikely(buf->error))
318 return buf->error;
262 buf->error = -EINVAL; /* only used if we fail.. */ 319 buf->error = -EINVAL; /* only used if we fail.. */
263 if (reclen > buf->count) 320 if (reclen > buf->count)
264 return -EINVAL; 321 return -EINVAL;
265 dirent = buf->previous; 322 dirent = buf->previous;
266 if (dirent) { 323 if (dirent && signal_pending(current))
267 if (signal_pending(current)) 324 return -EINTR;
268 return -EINTR; 325
269 if (__put_user(offset, &dirent->d_off)) 326 /*
270 goto efault; 327 * Note! This range-checks 'previous' (which may be NULL).
271 } 328 * The real range was checked in getdents
272 dirent = buf->current_dir; 329 */
273 if (__put_user(ino, &dirent->d_ino)) 330 if (!user_access_begin(dirent, sizeof(*dirent)))
274 goto efault;
275 if (__put_user(0, &dirent->d_off))
276 goto efault;
277 if (__put_user(reclen, &dirent->d_reclen))
278 goto efault;
279 if (__put_user(d_type, &dirent->d_type))
280 goto efault;
281 if (copy_to_user(dirent->d_name, name, namlen))
282 goto efault;
283 if (__put_user(0, dirent->d_name + namlen))
284 goto efault; 331 goto efault;
332 if (dirent)
333 unsafe_put_user(offset, &dirent->d_off, efault_end);
334 dirent = buf->current_dir;
335 unsafe_put_user(ino, &dirent->d_ino, efault_end);
336 unsafe_put_user(reclen, &dirent->d_reclen, efault_end);
337 unsafe_put_user(d_type, &dirent->d_type, efault_end);
338 unsafe_copy_dirent_name(dirent->d_name, name, namlen, efault_end);
339 user_access_end();
340
285 buf->previous = dirent; 341 buf->previous = dirent;
286 dirent = (void __user *)dirent + reclen; 342 dirent = (void __user *)dirent + reclen;
287 buf->current_dir = dirent; 343 buf->current_dir = dirent;
288 buf->count -= reclen; 344 buf->count -= reclen;
289 return 0; 345 return 0;
346efault_end:
347 user_access_end();
290efault: 348efault:
291 buf->error = -EFAULT; 349 buf->error = -EFAULT;
292 return -EFAULT; 350 return -EFAULT;
diff --git a/fs/statfs.c b/fs/statfs.c
index eea7af6f2f22..2616424012ea 100644
--- a/fs/statfs.c
+++ b/fs/statfs.c
@@ -318,19 +318,10 @@ COMPAT_SYSCALL_DEFINE2(fstatfs, unsigned int, fd, struct compat_statfs __user *,
318static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstatfs *kbuf) 318static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstatfs *kbuf)
319{ 319{
320 struct compat_statfs64 buf; 320 struct compat_statfs64 buf;
321 if (sizeof(ubuf->f_bsize) == 4) { 321
322 if ((kbuf->f_type | kbuf->f_bsize | kbuf->f_namelen | 322 if ((kbuf->f_bsize | kbuf->f_frsize) & 0xffffffff00000000ULL)
323 kbuf->f_frsize | kbuf->f_flags) & 0xffffffff00000000ULL) 323 return -EOVERFLOW;
324 return -EOVERFLOW; 324
325 /* f_files and f_ffree may be -1; it's okay
326 * to stuff that into 32 bits */
327 if (kbuf->f_files != 0xffffffffffffffffULL
328 && (kbuf->f_files & 0xffffffff00000000ULL))
329 return -EOVERFLOW;
330 if (kbuf->f_ffree != 0xffffffffffffffffULL
331 && (kbuf->f_ffree & 0xffffffff00000000ULL))
332 return -EOVERFLOW;
333 }
334 memset(&buf, 0, sizeof(struct compat_statfs64)); 325 memset(&buf, 0, sizeof(struct compat_statfs64));
335 buf.f_type = kbuf->f_type; 326 buf.f_type = kbuf->f_type;
336 buf.f_bsize = kbuf->f_bsize; 327 buf.f_bsize = kbuf->f_bsize;
diff --git a/fs/super.c b/fs/super.c
index f627b7c53d2b..cfadab2cbf35 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -1300,6 +1300,7 @@ int get_tree_bdev(struct fs_context *fc,
1300 mutex_lock(&bdev->bd_fsfreeze_mutex); 1300 mutex_lock(&bdev->bd_fsfreeze_mutex);
1301 if (bdev->bd_fsfreeze_count > 0) { 1301 if (bdev->bd_fsfreeze_count > 0) {
1302 mutex_unlock(&bdev->bd_fsfreeze_mutex); 1302 mutex_unlock(&bdev->bd_fsfreeze_mutex);
1303 blkdev_put(bdev, mode);
1303 warnf(fc, "%pg: Can't mount, blockdev is frozen", bdev); 1304 warnf(fc, "%pg: Can't mount, blockdev is frozen", bdev);
1304 return -EBUSY; 1305 return -EBUSY;
1305 } 1306 }
@@ -1308,8 +1309,10 @@ int get_tree_bdev(struct fs_context *fc,
1308 fc->sget_key = bdev; 1309 fc->sget_key = bdev;
1309 s = sget_fc(fc, test_bdev_super_fc, set_bdev_super_fc); 1310 s = sget_fc(fc, test_bdev_super_fc, set_bdev_super_fc);
1310 mutex_unlock(&bdev->bd_fsfreeze_mutex); 1311 mutex_unlock(&bdev->bd_fsfreeze_mutex);
1311 if (IS_ERR(s)) 1312 if (IS_ERR(s)) {
1313 blkdev_put(bdev, mode);
1312 return PTR_ERR(s); 1314 return PTR_ERR(s);
1315 }
1313 1316
1314 if (s->s_root) { 1317 if (s->s_root) {
1315 /* Don't summarily change the RO/RW state. */ 1318 /* Don't summarily change the RO/RW state. */
diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c
index 9fc14e38927f..0caa151cae4e 100644
--- a/fs/tracefs/inode.c
+++ b/fs/tracefs/inode.c
@@ -16,11 +16,11 @@
16#include <linux/namei.h> 16#include <linux/namei.h>
17#include <linux/tracefs.h> 17#include <linux/tracefs.h>
18#include <linux/fsnotify.h> 18#include <linux/fsnotify.h>
19#include <linux/security.h>
19#include <linux/seq_file.h> 20#include <linux/seq_file.h>
20#include <linux/parser.h> 21#include <linux/parser.h>
21#include <linux/magic.h> 22#include <linux/magic.h>
22#include <linux/slab.h> 23#include <linux/slab.h>
23#include <linux/security.h>
24 24
25#define TRACEFS_DEFAULT_MODE 0700 25#define TRACEFS_DEFAULT_MODE 0700
26 26
@@ -28,25 +28,6 @@ static struct vfsmount *tracefs_mount;
28static int tracefs_mount_count; 28static int tracefs_mount_count;
29static bool tracefs_registered; 29static bool tracefs_registered;
30 30
31static int default_open_file(struct inode *inode, struct file *filp)
32{
33 struct dentry *dentry = filp->f_path.dentry;
34 struct file_operations *real_fops;
35 int ret;
36
37 if (!dentry)
38 return -EINVAL;
39
40 ret = security_locked_down(LOCKDOWN_TRACEFS);
41 if (ret)
42 return ret;
43
44 real_fops = dentry->d_fsdata;
45 if (!real_fops->open)
46 return 0;
47 return real_fops->open(inode, filp);
48}
49
50static ssize_t default_read_file(struct file *file, char __user *buf, 31static ssize_t default_read_file(struct file *file, char __user *buf,
51 size_t count, loff_t *ppos) 32 size_t count, loff_t *ppos)
52{ 33{
@@ -241,12 +222,6 @@ static int tracefs_apply_options(struct super_block *sb)
241 return 0; 222 return 0;
242} 223}
243 224
244static void tracefs_destroy_inode(struct inode *inode)
245{
246 if (S_ISREG(inode->i_mode))
247 kfree(inode->i_fop);
248}
249
250static int tracefs_remount(struct super_block *sb, int *flags, char *data) 225static int tracefs_remount(struct super_block *sb, int *flags, char *data)
251{ 226{
252 int err; 227 int err;
@@ -283,7 +258,6 @@ static int tracefs_show_options(struct seq_file *m, struct dentry *root)
283static const struct super_operations tracefs_super_operations = { 258static const struct super_operations tracefs_super_operations = {
284 .statfs = simple_statfs, 259 .statfs = simple_statfs,
285 .remount_fs = tracefs_remount, 260 .remount_fs = tracefs_remount,
286 .destroy_inode = tracefs_destroy_inode,
287 .show_options = tracefs_show_options, 261 .show_options = tracefs_show_options,
288}; 262};
289 263
@@ -414,10 +388,12 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode,
414 struct dentry *parent, void *data, 388 struct dentry *parent, void *data,
415 const struct file_operations *fops) 389 const struct file_operations *fops)
416{ 390{
417 struct file_operations *proxy_fops;
418 struct dentry *dentry; 391 struct dentry *dentry;
419 struct inode *inode; 392 struct inode *inode;
420 393
394 if (security_locked_down(LOCKDOWN_TRACEFS))
395 return NULL;
396
421 if (!(mode & S_IFMT)) 397 if (!(mode & S_IFMT))
422 mode |= S_IFREG; 398 mode |= S_IFREG;
423 BUG_ON(!S_ISREG(mode)); 399 BUG_ON(!S_ISREG(mode));
@@ -430,20 +406,8 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode,
430 if (unlikely(!inode)) 406 if (unlikely(!inode))
431 return failed_creating(dentry); 407 return failed_creating(dentry);
432 408
433 proxy_fops = kzalloc(sizeof(struct file_operations), GFP_KERNEL);
434 if (unlikely(!proxy_fops)) {
435 iput(inode);
436 return failed_creating(dentry);
437 }
438
439 if (!fops)
440 fops = &tracefs_file_operations;
441
442 dentry->d_fsdata = (void *)fops;
443 memcpy(proxy_fops, fops, sizeof(*proxy_fops));
444 proxy_fops->open = default_open_file;
445 inode->i_mode = mode; 409 inode->i_mode = mode;
446 inode->i_fop = proxy_fops; 410 inode->i_fop = fops ? fops : &tracefs_file_operations;
447 inode->i_private = data; 411 inode->i_private = data;
448 d_instantiate(dentry, inode); 412 d_instantiate(dentry, inode);
449 fsnotify_create(dentry->d_parent->d_inode, dentry); 413 fsnotify_create(dentry->d_parent->d_inode, dentry);
diff --git a/fs/xfs/libxfs/xfs_ag.c b/fs/xfs/libxfs/xfs_ag.c
index 5de296b34ab1..14fbdf22b7e7 100644
--- a/fs/xfs/libxfs/xfs_ag.c
+++ b/fs/xfs/libxfs/xfs_ag.c
@@ -28,12 +28,11 @@ xfs_get_aghdr_buf(
28 struct xfs_mount *mp, 28 struct xfs_mount *mp,
29 xfs_daddr_t blkno, 29 xfs_daddr_t blkno,
30 size_t numblks, 30 size_t numblks,
31 int flags,
32 const struct xfs_buf_ops *ops) 31 const struct xfs_buf_ops *ops)
33{ 32{
34 struct xfs_buf *bp; 33 struct xfs_buf *bp;
35 34
36 bp = xfs_buf_get_uncached(mp->m_ddev_targp, numblks, flags); 35 bp = xfs_buf_get_uncached(mp->m_ddev_targp, numblks, 0);
37 if (!bp) 36 if (!bp)
38 return NULL; 37 return NULL;
39 38
@@ -345,7 +344,7 @@ xfs_ag_init_hdr(
345{ 344{
346 struct xfs_buf *bp; 345 struct xfs_buf *bp;
347 346
348 bp = xfs_get_aghdr_buf(mp, id->daddr, id->numblks, 0, ops); 347 bp = xfs_get_aghdr_buf(mp, id->daddr, id->numblks, ops);
349 if (!bp) 348 if (!bp)
350 return -ENOMEM; 349 return -ENOMEM;
351 350
diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
index b9f019603d0b..f0089e862216 100644
--- a/fs/xfs/libxfs/xfs_attr_leaf.c
+++ b/fs/xfs/libxfs/xfs_attr_leaf.c
@@ -826,32 +826,17 @@ xfs_attr_shortform_to_leaf(
826 sf = (xfs_attr_shortform_t *)tmpbuffer; 826 sf = (xfs_attr_shortform_t *)tmpbuffer;
827 827
828 xfs_idata_realloc(dp, -size, XFS_ATTR_FORK); 828 xfs_idata_realloc(dp, -size, XFS_ATTR_FORK);
829 xfs_bmap_local_to_extents_empty(dp, XFS_ATTR_FORK); 829 xfs_bmap_local_to_extents_empty(args->trans, dp, XFS_ATTR_FORK);
830 830
831 bp = NULL; 831 bp = NULL;
832 error = xfs_da_grow_inode(args, &blkno); 832 error = xfs_da_grow_inode(args, &blkno);
833 if (error) { 833 if (error)
834 /*
835 * If we hit an IO error middle of the transaction inside
836 * grow_inode(), we may have inconsistent data. Bail out.
837 */
838 if (error == -EIO)
839 goto out;
840 xfs_idata_realloc(dp, size, XFS_ATTR_FORK); /* try to put */
841 memcpy(ifp->if_u1.if_data, tmpbuffer, size); /* it back */
842 goto out; 834 goto out;
843 }
844 835
845 ASSERT(blkno == 0); 836 ASSERT(blkno == 0);
846 error = xfs_attr3_leaf_create(args, blkno, &bp); 837 error = xfs_attr3_leaf_create(args, blkno, &bp);
847 if (error) { 838 if (error)
848 /* xfs_attr3_leaf_create may not have instantiated a block */
849 if (bp && (xfs_da_shrink_inode(args, 0, bp) != 0))
850 goto out;
851 xfs_idata_realloc(dp, size, XFS_ATTR_FORK); /* try to put */
852 memcpy(ifp->if_u1.if_data, tmpbuffer, size); /* it back */
853 goto out; 839 goto out;
854 }
855 840
856 memset((char *)&nargs, 0, sizeof(nargs)); 841 memset((char *)&nargs, 0, sizeof(nargs));
857 nargs.dp = dp; 842 nargs.dp = dp;
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 4edc25a2ba80..02469d59c787 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -792,6 +792,7 @@ out_root_realloc:
792 */ 792 */
793void 793void
794xfs_bmap_local_to_extents_empty( 794xfs_bmap_local_to_extents_empty(
795 struct xfs_trans *tp,
795 struct xfs_inode *ip, 796 struct xfs_inode *ip,
796 int whichfork) 797 int whichfork)
797{ 798{
@@ -808,6 +809,7 @@ xfs_bmap_local_to_extents_empty(
808 ifp->if_u1.if_root = NULL; 809 ifp->if_u1.if_root = NULL;
809 ifp->if_height = 0; 810 ifp->if_height = 0;
810 XFS_IFORK_FMT_SET(ip, whichfork, XFS_DINODE_FMT_EXTENTS); 811 XFS_IFORK_FMT_SET(ip, whichfork, XFS_DINODE_FMT_EXTENTS);
812 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
811} 813}
812 814
813 815
@@ -840,7 +842,7 @@ xfs_bmap_local_to_extents(
840 ASSERT(XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_LOCAL); 842 ASSERT(XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_LOCAL);
841 843
842 if (!ifp->if_bytes) { 844 if (!ifp->if_bytes) {
843 xfs_bmap_local_to_extents_empty(ip, whichfork); 845 xfs_bmap_local_to_extents_empty(tp, ip, whichfork);
844 flags = XFS_ILOG_CORE; 846 flags = XFS_ILOG_CORE;
845 goto done; 847 goto done;
846 } 848 }
@@ -887,7 +889,7 @@ xfs_bmap_local_to_extents(
887 889
888 /* account for the change in fork size */ 890 /* account for the change in fork size */
889 xfs_idata_realloc(ip, -ifp->if_bytes, whichfork); 891 xfs_idata_realloc(ip, -ifp->if_bytes, whichfork);
890 xfs_bmap_local_to_extents_empty(ip, whichfork); 892 xfs_bmap_local_to_extents_empty(tp, ip, whichfork);
891 flags |= XFS_ILOG_CORE; 893 flags |= XFS_ILOG_CORE;
892 894
893 ifp->if_u1.if_root = NULL; 895 ifp->if_u1.if_root = NULL;
diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h
index 5bb446d80542..e2798c6f3a5f 100644
--- a/fs/xfs/libxfs/xfs_bmap.h
+++ b/fs/xfs/libxfs/xfs_bmap.h
@@ -182,7 +182,8 @@ void xfs_trim_extent(struct xfs_bmbt_irec *irec, xfs_fileoff_t bno,
182 xfs_filblks_t len); 182 xfs_filblks_t len);
183int xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd); 183int xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd);
184int xfs_bmap_set_attrforkoff(struct xfs_inode *ip, int size, int *version); 184int xfs_bmap_set_attrforkoff(struct xfs_inode *ip, int size, int *version);
185void xfs_bmap_local_to_extents_empty(struct xfs_inode *ip, int whichfork); 185void xfs_bmap_local_to_extents_empty(struct xfs_trans *tp,
186 struct xfs_inode *ip, int whichfork);
186void __xfs_bmap_add_free(struct xfs_trans *tp, xfs_fsblock_t bno, 187void __xfs_bmap_add_free(struct xfs_trans *tp, xfs_fsblock_t bno,
187 xfs_filblks_t len, const struct xfs_owner_info *oinfo, 188 xfs_filblks_t len, const struct xfs_owner_info *oinfo,
188 bool skip_discard); 189 bool skip_discard);
diff --git a/fs/xfs/libxfs/xfs_dir2_block.c b/fs/xfs/libxfs/xfs_dir2_block.c
index 9595ced393dc..49e4bc39e7bb 100644
--- a/fs/xfs/libxfs/xfs_dir2_block.c
+++ b/fs/xfs/libxfs/xfs_dir2_block.c
@@ -1096,7 +1096,7 @@ xfs_dir2_sf_to_block(
1096 memcpy(sfp, oldsfp, ifp->if_bytes); 1096 memcpy(sfp, oldsfp, ifp->if_bytes);
1097 1097
1098 xfs_idata_realloc(dp, -ifp->if_bytes, XFS_DATA_FORK); 1098 xfs_idata_realloc(dp, -ifp->if_bytes, XFS_DATA_FORK);
1099 xfs_bmap_local_to_extents_empty(dp, XFS_DATA_FORK); 1099 xfs_bmap_local_to_extents_empty(tp, dp, XFS_DATA_FORK);
1100 dp->i_d.di_size = 0; 1100 dp->i_d.di_size = 0;
1101 1101
1102 /* 1102 /*
diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h
index 39dd2b908106..e9371a8e0e26 100644
--- a/fs/xfs/libxfs/xfs_fs.h
+++ b/fs/xfs/libxfs/xfs_fs.h
@@ -366,11 +366,11 @@ struct xfs_bulkstat {
366 uint64_t bs_blocks; /* number of blocks */ 366 uint64_t bs_blocks; /* number of blocks */
367 uint64_t bs_xflags; /* extended flags */ 367 uint64_t bs_xflags; /* extended flags */
368 368
369 uint64_t bs_atime; /* access time, seconds */ 369 int64_t bs_atime; /* access time, seconds */
370 uint64_t bs_mtime; /* modify time, seconds */ 370 int64_t bs_mtime; /* modify time, seconds */
371 371
372 uint64_t bs_ctime; /* inode change time, seconds */ 372 int64_t bs_ctime; /* inode change time, seconds */
373 uint64_t bs_btime; /* creation time, seconds */ 373 int64_t bs_btime; /* creation time, seconds */
374 374
375 uint32_t bs_gen; /* generation count */ 375 uint32_t bs_gen; /* generation count */
376 uint32_t bs_uid; /* user id */ 376 uint32_t bs_uid; /* user id */
diff --git a/fs/xfs/scrub/refcount.c b/fs/xfs/scrub/refcount.c
index 93b3793bc5b3..0cab11a5d390 100644
--- a/fs/xfs/scrub/refcount.c
+++ b/fs/xfs/scrub/refcount.c
@@ -341,7 +341,6 @@ xchk_refcountbt_rec(
341 xfs_extlen_t len; 341 xfs_extlen_t len;
342 xfs_nlink_t refcount; 342 xfs_nlink_t refcount;
343 bool has_cowflag; 343 bool has_cowflag;
344 int error = 0;
345 344
346 bno = be32_to_cpu(rec->refc.rc_startblock); 345 bno = be32_to_cpu(rec->refc.rc_startblock);
347 len = be32_to_cpu(rec->refc.rc_blockcount); 346 len = be32_to_cpu(rec->refc.rc_blockcount);
@@ -366,7 +365,7 @@ xchk_refcountbt_rec(
366 365
367 xchk_refcountbt_xref(bs->sc, bno, len, refcount); 366 xchk_refcountbt_xref(bs->sc, bno, len, refcount);
368 367
369 return error; 368 return 0;
370} 369}
371 370
372/* Make sure we have as many refc blocks as the rmap says. */ 371/* Make sure we have as many refc blocks as the rmap says. */
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 0910cb75b65d..4f443703065e 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -864,6 +864,7 @@ xfs_alloc_file_space(
864 xfs_filblks_t allocatesize_fsb; 864 xfs_filblks_t allocatesize_fsb;
865 xfs_extlen_t extsz, temp; 865 xfs_extlen_t extsz, temp;
866 xfs_fileoff_t startoffset_fsb; 866 xfs_fileoff_t startoffset_fsb;
867 xfs_fileoff_t endoffset_fsb;
867 int nimaps; 868 int nimaps;
868 int quota_flag; 869 int quota_flag;
869 int rt; 870 int rt;
@@ -891,7 +892,8 @@ xfs_alloc_file_space(
891 imapp = &imaps[0]; 892 imapp = &imaps[0];
892 nimaps = 1; 893 nimaps = 1;
893 startoffset_fsb = XFS_B_TO_FSBT(mp, offset); 894 startoffset_fsb = XFS_B_TO_FSBT(mp, offset);
894 allocatesize_fsb = XFS_B_TO_FSB(mp, count); 895 endoffset_fsb = XFS_B_TO_FSB(mp, offset + count);
896 allocatesize_fsb = endoffset_fsb - startoffset_fsb;
895 897
896 /* 898 /*
897 * Allocate file space until done or until there is an error 899 * Allocate file space until done or until there is an error
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index 21c243622a79..0abba171aa89 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -345,6 +345,15 @@ xfs_buf_allocate_memory(
345 unsigned short page_count, i; 345 unsigned short page_count, i;
346 xfs_off_t start, end; 346 xfs_off_t start, end;
347 int error; 347 int error;
348 xfs_km_flags_t kmflag_mask = 0;
349
350 /*
351 * assure zeroed buffer for non-read cases.
352 */
353 if (!(flags & XBF_READ)) {
354 kmflag_mask |= KM_ZERO;
355 gfp_mask |= __GFP_ZERO;
356 }
348 357
349 /* 358 /*
350 * for buffers that are contained within a single page, just allocate 359 * for buffers that are contained within a single page, just allocate
@@ -354,7 +363,8 @@ xfs_buf_allocate_memory(
354 size = BBTOB(bp->b_length); 363 size = BBTOB(bp->b_length);
355 if (size < PAGE_SIZE) { 364 if (size < PAGE_SIZE) {
356 int align_mask = xfs_buftarg_dma_alignment(bp->b_target); 365 int align_mask = xfs_buftarg_dma_alignment(bp->b_target);
357 bp->b_addr = kmem_alloc_io(size, align_mask, KM_NOFS); 366 bp->b_addr = kmem_alloc_io(size, align_mask,
367 KM_NOFS | kmflag_mask);
358 if (!bp->b_addr) { 368 if (!bp->b_addr) {
359 /* low memory - use alloc_page loop instead */ 369 /* low memory - use alloc_page loop instead */
360 goto use_alloc_page; 370 goto use_alloc_page;
diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c
index a2beee9f74da..641d07f30a27 100644
--- a/fs/xfs/xfs_log.c
+++ b/fs/xfs/xfs_log.c
@@ -1443,7 +1443,7 @@ xlog_alloc_log(
1443 prev_iclog = iclog; 1443 prev_iclog = iclog;
1444 1444
1445 iclog->ic_data = kmem_alloc_io(log->l_iclog_size, align_mask, 1445 iclog->ic_data = kmem_alloc_io(log->l_iclog_size, align_mask,
1446 KM_MAYFAIL); 1446 KM_MAYFAIL | KM_ZERO);
1447 if (!iclog->ic_data) 1447 if (!iclog->ic_data)
1448 goto out_free_iclog; 1448 goto out_free_iclog;
1449#ifdef DEBUG 1449#ifdef DEBUG
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
index 508319039dce..c1a514ffff55 100644
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -127,7 +127,7 @@ xlog_alloc_buffer(
127 if (nbblks > 1 && log->l_sectBBsize > 1) 127 if (nbblks > 1 && log->l_sectBBsize > 1)
128 nbblks += log->l_sectBBsize; 128 nbblks += log->l_sectBBsize;
129 nbblks = round_up(nbblks, log->l_sectBBsize); 129 nbblks = round_up(nbblks, log->l_sectBBsize);
130 return kmem_alloc_io(BBTOB(nbblks), align_mask, KM_MAYFAIL); 130 return kmem_alloc_io(BBTOB(nbblks), align_mask, KM_MAYFAIL | KM_ZERO);
131} 131}
132 132
133/* 133/*
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 90528f12bdfa..29fc933df3bf 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -326,10 +326,11 @@ static inline int bitmap_equal(const unsigned long *src1,
326} 326}
327 327
328/** 328/**
329 * bitmap_or_equal - Check whether the or of two bitnaps is equal to a third 329 * bitmap_or_equal - Check whether the or of two bitmaps is equal to a third
330 * @src1: Pointer to bitmap 1 330 * @src1: Pointer to bitmap 1
331 * @src2: Pointer to bitmap 2 will be or'ed with bitmap 1 331 * @src2: Pointer to bitmap 2 will be or'ed with bitmap 1
332 * @src3: Pointer to bitmap 3. Compare to the result of *@src1 | *@src2 332 * @src3: Pointer to bitmap 3. Compare to the result of *@src1 | *@src2
333 * @nbits: number of bits in each of these bitmaps
333 * 334 *
334 * Returns: True if (*@src1 | *@src2) == *@src3, false otherwise 335 * Returns: True if (*@src1 | *@src2) == *@src3, false otherwise
335 */ 336 */
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index cf074bce3eb3..c94a9ff9f082 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -4,6 +4,13 @@
4#include <asm/types.h> 4#include <asm/types.h>
5#include <linux/bits.h> 5#include <linux/bits.h>
6 6
7/* Set bits in the first 'n' bytes when loaded from memory */
8#ifdef __LITTLE_ENDIAN
9# define aligned_byte_mask(n) ((1UL << 8*(n))-1)
10#else
11# define aligned_byte_mask(n) (~0xffUL << (BITS_PER_LONG - 8 - 8*(n)))
12#endif
13
7#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE) 14#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
8#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(long)) 15#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
9 16
diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h
index 6b318efd8a74..cdf016596659 100644
--- a/include/linux/compiler_attributes.h
+++ b/include/linux/compiler_attributes.h
@@ -40,6 +40,7 @@
40# define __GCC4_has_attribute___noclone__ 1 40# define __GCC4_has_attribute___noclone__ 1
41# define __GCC4_has_attribute___nonstring__ 0 41# define __GCC4_has_attribute___nonstring__ 0
42# define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8) 42# define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8)
43# define __GCC4_has_attribute___fallthrough__ 0
43#endif 44#endif
44 45
45/* 46/*
@@ -186,6 +187,22 @@
186#endif 187#endif
187 188
188/* 189/*
190 * Add the pseudo keyword 'fallthrough' so case statement blocks
191 * must end with any of these keywords:
192 * break;
193 * fallthrough;
194 * goto <label>;
195 * return [expression];
196 *
197 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes
198 */
199#if __has_attribute(__fallthrough__)
200# define fallthrough __attribute__((__fallthrough__))
201#else
202# define fallthrough do {} while (0) /* fallthrough */
203#endif
204
205/*
189 * Note the missing underscores. 206 * Note the missing underscores.
190 * 207 *
191 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noinline-function-attribute 208 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noinline-function-attribute
diff --git a/include/linux/dsa/sja1105.h b/include/linux/dsa/sja1105.h
index 79435cfc20eb..897e799dbcb9 100644
--- a/include/linux/dsa/sja1105.h
+++ b/include/linux/dsa/sja1105.h
@@ -31,6 +31,8 @@
31#define SJA1105_META_SMAC 0x222222222222ull 31#define SJA1105_META_SMAC 0x222222222222ull
32#define SJA1105_META_DMAC 0x0180C200000Eull 32#define SJA1105_META_DMAC 0x0180C200000Eull
33 33
34#define SJA1105_HWTS_RX_EN 0
35
34/* Global tagger data: each struct sja1105_port has a reference to 36/* Global tagger data: each struct sja1105_port has a reference to
35 * the structure defined in struct sja1105_private. 37 * the structure defined in struct sja1105_private.
36 */ 38 */
@@ -42,7 +44,7 @@ struct sja1105_tagger_data {
42 * from taggers running on multiple ports on SMP systems 44 * from taggers running on multiple ports on SMP systems
43 */ 45 */
44 spinlock_t meta_lock; 46 spinlock_t meta_lock;
45 bool hwts_rx_en; 47 unsigned long state;
46}; 48};
47 49
48struct sja1105_skb_cb { 50struct sja1105_skb_cb {
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 6c809440f319..4cf02ecd67de 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -204,6 +204,12 @@ static inline int ddebug_dyndbg_module_param_cb(char *param, char *val,
204 do { if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0) 204 do { if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0)
205#define dynamic_dev_dbg(dev, fmt, ...) \ 205#define dynamic_dev_dbg(dev, fmt, ...) \
206 do { if (0) dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); } while (0) 206 do { if (0) dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); } while (0)
207#define dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
208 groupsize, buf, len, ascii) \
209 do { if (0) \
210 print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, \
211 rowsize, groupsize, buf, len, ascii); \
212 } while (0)
207#endif 213#endif
208 214
209#endif 215#endif
diff --git a/include/linux/export.h b/include/linux/export.h
index 95f55b7f83a0..621158ecd2e2 100644
--- a/include/linux/export.h
+++ b/include/linux/export.h
@@ -52,10 +52,10 @@ extern struct module __this_module;
52 __ADDRESSABLE(sym) \ 52 __ADDRESSABLE(sym) \
53 asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \ 53 asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
54 " .balign 4 \n" \ 54 " .balign 4 \n" \
55 "__ksymtab_" #sym NS_SEPARATOR #ns ": \n" \ 55 "__ksymtab_" #ns NS_SEPARATOR #sym ": \n" \
56 " .long " #sym "- . \n" \ 56 " .long " #sym "- . \n" \
57 " .long __kstrtab_" #sym "- . \n" \ 57 " .long __kstrtab_" #sym "- . \n" \
58 " .long __kstrtab_ns_" #sym "- . \n" \ 58 " .long __kstrtabns_" #sym "- . \n" \
59 " .previous \n") 59 " .previous \n")
60 60
61#define __KSYMTAB_ENTRY(sym, sec) \ 61#define __KSYMTAB_ENTRY(sym, sec) \
@@ -76,10 +76,10 @@ struct kernel_symbol {
76#else 76#else
77#define __KSYMTAB_ENTRY_NS(sym, sec, ns) \ 77#define __KSYMTAB_ENTRY_NS(sym, sec, ns) \
78 static const struct kernel_symbol __ksymtab_##sym##__##ns \ 78 static const struct kernel_symbol __ksymtab_##sym##__##ns \
79 asm("__ksymtab_" #sym NS_SEPARATOR #ns) \ 79 asm("__ksymtab_" #ns NS_SEPARATOR #sym) \
80 __attribute__((section("___ksymtab" sec "+" #sym), used)) \ 80 __attribute__((section("___ksymtab" sec "+" #sym), used)) \
81 __aligned(sizeof(void *)) \ 81 __aligned(sizeof(void *)) \
82 = { (unsigned long)&sym, __kstrtab_##sym, __kstrtab_ns_##sym } 82 = { (unsigned long)&sym, __kstrtab_##sym, __kstrtabns_##sym }
83 83
84#define __KSYMTAB_ENTRY(sym, sec) \ 84#define __KSYMTAB_ENTRY(sym, sec) \
85 static const struct kernel_symbol __ksymtab_##sym \ 85 static const struct kernel_symbol __ksymtab_##sym \
@@ -112,7 +112,7 @@ struct kernel_symbol {
112/* For every exported symbol, place a struct in the __ksymtab section */ 112/* For every exported symbol, place a struct in the __ksymtab section */
113#define ___EXPORT_SYMBOL_NS(sym, sec, ns) \ 113#define ___EXPORT_SYMBOL_NS(sym, sec, ns) \
114 ___export_symbol_common(sym, sec); \ 114 ___export_symbol_common(sym, sec); \
115 static const char __kstrtab_ns_##sym[] \ 115 static const char __kstrtabns_##sym[] \
116 __attribute__((section("__ksymtab_strings"), used, aligned(1))) \ 116 __attribute__((section("__ksymtab_strings"), used, aligned(1))) \
117 = #ns; \ 117 = #ns; \
118 __KSYMTAB_ENTRY_NS(sym, sec, ns) 118 __KSYMTAB_ENTRY_NS(sym, sec, ns)
diff --git a/include/linux/filter.h b/include/linux/filter.h
index 2ce57645f3cd..0367a75f873b 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -1099,7 +1099,6 @@ static inline void bpf_get_prog_name(const struct bpf_prog *prog, char *sym)
1099 1099
1100#endif /* CONFIG_BPF_JIT */ 1100#endif /* CONFIG_BPF_JIT */
1101 1101
1102void bpf_prog_kallsyms_del_subprogs(struct bpf_prog *fp);
1103void bpf_prog_kallsyms_del_all(struct bpf_prog *fp); 1102void bpf_prog_kallsyms_del_all(struct bpf_prog *fp);
1104 1103
1105#define BPF_ANC BIT(15) 1104#define BPF_ANC BIT(15)
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index fb07b503dc45..61f2f6ff9467 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -325,6 +325,29 @@ static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags)
325 return !!(gfp_flags & __GFP_DIRECT_RECLAIM); 325 return !!(gfp_flags & __GFP_DIRECT_RECLAIM);
326} 326}
327 327
328/**
329 * gfpflags_normal_context - is gfp_flags a normal sleepable context?
330 * @gfp_flags: gfp_flags to test
331 *
332 * Test whether @gfp_flags indicates that the allocation is from the
333 * %current context and allowed to sleep.
334 *
335 * An allocation being allowed to block doesn't mean it owns the %current
336 * context. When direct reclaim path tries to allocate memory, the
337 * allocation context is nested inside whatever %current was doing at the
338 * time of the original allocation. The nested allocation may be allowed
339 * to block but modifying anything %current owns can corrupt the outer
340 * context's expectations.
341 *
342 * %true result from this function indicates that the allocation context
343 * can sleep and use anything that's associated with %current.
344 */
345static inline bool gfpflags_normal_context(const gfp_t gfp_flags)
346{
347 return (gfp_flags & (__GFP_DIRECT_RECLAIM | __GFP_MEMALLOC)) ==
348 __GFP_DIRECT_RECLAIM;
349}
350
328#ifdef CONFIG_HIGHMEM 351#ifdef CONFIG_HIGHMEM
329#define OPT_ZONE_HIGHMEM ZONE_HIGHMEM 352#define OPT_ZONE_HIGHMEM ZONE_HIGHMEM
330#else 353#else
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index f8245d67f070..5dd9c982e2cb 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -202,6 +202,14 @@ struct gpio_irq_chip {
202 bool threaded; 202 bool threaded;
203 203
204 /** 204 /**
205 * @init_hw: optional routine to initialize hardware before
206 * an IRQ chip will be added. This is quite useful when
207 * a particular driver wants to clear IRQ related registers
208 * in order to avoid undesired events.
209 */
210 int (*init_hw)(struct gpio_chip *chip);
211
212 /**
205 * @init_valid_mask: optional routine to initialize @valid_mask, to be 213 * @init_valid_mask: optional routine to initialize @valid_mask, to be
206 * used if not all GPIO lines are valid interrupts. Sometimes some 214 * used if not all GPIO lines are valid interrupts. Sometimes some
207 * lines just cannot fire interrupts, and this routine, when defined, 215 * lines just cannot fire interrupts, and this routine, when defined,
diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
index 04c36b7a61dd..72579168189d 100644
--- a/include/linux/hwmon.h
+++ b/include/linux/hwmon.h
@@ -235,7 +235,7 @@ enum hwmon_power_attributes {
235#define HWMON_P_LABEL BIT(hwmon_power_label) 235#define HWMON_P_LABEL BIT(hwmon_power_label)
236#define HWMON_P_ALARM BIT(hwmon_power_alarm) 236#define HWMON_P_ALARM BIT(hwmon_power_alarm)
237#define HWMON_P_CAP_ALARM BIT(hwmon_power_cap_alarm) 237#define HWMON_P_CAP_ALARM BIT(hwmon_power_cap_alarm)
238#define HWMON_P_MIN_ALARM BIT(hwmon_power_max_alarm) 238#define HWMON_P_MIN_ALARM BIT(hwmon_power_min_alarm)
239#define HWMON_P_MAX_ALARM BIT(hwmon_power_max_alarm) 239#define HWMON_P_MAX_ALARM BIT(hwmon_power_max_alarm)
240#define HWMON_P_LCRIT_ALARM BIT(hwmon_power_lcrit_alarm) 240#define HWMON_P_LCRIT_ALARM BIT(hwmon_power_lcrit_alarm)
241#define HWMON_P_CRIT_ALARM BIT(hwmon_power_crit_alarm) 241#define HWMON_P_CRIT_ALARM BIT(hwmon_power_crit_alarm)
diff --git a/include/linux/if_macvlan.h b/include/linux/if_macvlan.h
index 2e55e4cdbd8a..a367ead4bf4b 100644
--- a/include/linux/if_macvlan.h
+++ b/include/linux/if_macvlan.h
@@ -29,7 +29,6 @@ struct macvlan_dev {
29 netdev_features_t set_features; 29 netdev_features_t set_features;
30 enum macvlan_mode mode; 30 enum macvlan_mode mode;
31 u16 flags; 31 u16 flags;
32 int nest_level;
33 unsigned int macaddr_count; 32 unsigned int macaddr_count;
34#ifdef CONFIG_NET_POLL_CONTROLLER 33#ifdef CONFIG_NET_POLL_CONTROLLER
35 struct netpoll *netpoll; 34 struct netpoll *netpoll;
diff --git a/include/linux/if_team.h b/include/linux/if_team.h
index 06faa066496f..ec7e4bd07f82 100644
--- a/include/linux/if_team.h
+++ b/include/linux/if_team.h
@@ -223,6 +223,7 @@ struct team {
223 atomic_t count_pending; 223 atomic_t count_pending;
224 struct delayed_work dw; 224 struct delayed_work dw;
225 } mcast_rejoin; 225 } mcast_rejoin;
226 struct lock_class_key team_lock_key;
226 long mode_priv[TEAM_MODE_PRIV_LONGS]; 227 long mode_priv[TEAM_MODE_PRIV_LONGS];
227}; 228};
228 229
diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h
index 244278d5c222..b05e855f1ddd 100644
--- a/include/linux/if_vlan.h
+++ b/include/linux/if_vlan.h
@@ -182,7 +182,6 @@ struct vlan_dev_priv {
182#ifdef CONFIG_NET_POLL_CONTROLLER 182#ifdef CONFIG_NET_POLL_CONTROLLER
183 struct netpoll *netpoll; 183 struct netpoll *netpoll;
184#endif 184#endif
185 unsigned int nest_level;
186}; 185};
187 186
188static inline struct vlan_dev_priv *vlan_dev_priv(const struct net_device *dev) 187static inline struct vlan_dev_priv *vlan_dev_priv(const struct net_device *dev)
@@ -221,11 +220,6 @@ extern void vlan_vids_del_by_dev(struct net_device *dev,
221 220
222extern bool vlan_uses_dev(const struct net_device *dev); 221extern bool vlan_uses_dev(const struct net_device *dev);
223 222
224static inline int vlan_get_encap_level(struct net_device *dev)
225{
226 BUG_ON(!is_vlan_dev(dev));
227 return vlan_dev_priv(dev)->nest_level;
228}
229#else 223#else
230static inline struct net_device * 224static inline struct net_device *
231__vlan_find_dev_deep_rcu(struct net_device *real_dev, 225__vlan_find_dev_deep_rcu(struct net_device *real_dev,
@@ -295,11 +289,6 @@ static inline bool vlan_uses_dev(const struct net_device *dev)
295{ 289{
296 return false; 290 return false;
297} 291}
298static inline int vlan_get_encap_level(struct net_device *dev)
299{
300 BUG();
301 return 0;
302}
303#endif 292#endif
304 293
305/** 294/**
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index fcb46b3374c6..719fc3e15ea4 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -1090,6 +1090,7 @@ enum kvm_stat_kind {
1090 1090
1091struct kvm_stat_data { 1091struct kvm_stat_data {
1092 int offset; 1092 int offset;
1093 int mode;
1093 struct kvm *kvm; 1094 struct kvm *kvm;
1094}; 1095};
1095 1096
@@ -1097,6 +1098,7 @@ struct kvm_stats_debugfs_item {
1097 const char *name; 1098 const char *name;
1098 int offset; 1099 int offset;
1099 enum kvm_stat_kind kind; 1100 enum kvm_stat_kind kind;
1101 int mode;
1100}; 1102};
1101extern struct kvm_stats_debugfs_item debugfs_entries[]; 1103extern struct kvm_stats_debugfs_item debugfs_entries[];
1102extern struct dentry *kvm_debugfs_dir; 1104extern struct dentry *kvm_debugfs_dir;
diff --git a/include/linux/leds.h b/include/linux/leds.h
index b8df71193329..efb309dba914 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -247,7 +247,7 @@ extern void led_set_brightness(struct led_classdev *led_cdev,
247/** 247/**
248 * led_set_brightness_sync - set LED brightness synchronously 248 * led_set_brightness_sync - set LED brightness synchronously
249 * @led_cdev: the LED to set 249 * @led_cdev: the LED to set
250 * @brightness: the brightness to set it to 250 * @value: the brightness to set it to
251 * 251 *
252 * Set an LED's brightness immediately. This function will block 252 * Set an LED's brightness immediately. This function will block
253 * the caller for the time required for accessing device registers, 253 * the caller for the time required for accessing device registers,
@@ -301,8 +301,7 @@ extern void led_sysfs_enable(struct led_classdev *led_cdev);
301/** 301/**
302 * led_compose_name - compose LED class device name 302 * led_compose_name - compose LED class device name
303 * @dev: LED controller device object 303 * @dev: LED controller device object
304 * @child: child fwnode_handle describing a LED or a group of synchronized LEDs; 304 * @init_data: the LED class device initialization data
305 * it must be provided only for fwnode based LEDs
306 * @led_classdev_name: composed LED class device name 305 * @led_classdev_name: composed LED class device name
307 * 306 *
308 * Create LED class device name basing on the provided init_data argument. 307 * Create LED class device name basing on the provided init_data argument.
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 9b60863429cc..ae703ea3ef48 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -356,6 +356,19 @@ static inline bool mem_cgroup_disabled(void)
356 return !cgroup_subsys_enabled(memory_cgrp_subsys); 356 return !cgroup_subsys_enabled(memory_cgrp_subsys);
357} 357}
358 358
359static inline unsigned long mem_cgroup_protection(struct mem_cgroup *memcg,
360 bool in_low_reclaim)
361{
362 if (mem_cgroup_disabled())
363 return 0;
364
365 if (in_low_reclaim)
366 return READ_ONCE(memcg->memory.emin);
367
368 return max(READ_ONCE(memcg->memory.emin),
369 READ_ONCE(memcg->memory.elow));
370}
371
359enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, 372enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root,
360 struct mem_cgroup *memcg); 373 struct mem_cgroup *memcg);
361 374
@@ -537,6 +550,8 @@ void mem_cgroup_handle_over_high(void);
537 550
538unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg); 551unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg);
539 552
553unsigned long mem_cgroup_size(struct mem_cgroup *memcg);
554
540void mem_cgroup_print_oom_context(struct mem_cgroup *memcg, 555void mem_cgroup_print_oom_context(struct mem_cgroup *memcg,
541 struct task_struct *p); 556 struct task_struct *p);
542 557
@@ -829,6 +844,12 @@ static inline void memcg_memory_event_mm(struct mm_struct *mm,
829{ 844{
830} 845}
831 846
847static inline unsigned long mem_cgroup_protection(struct mem_cgroup *memcg,
848 bool in_low_reclaim)
849{
850 return 0;
851}
852
832static inline enum mem_cgroup_protection mem_cgroup_protected( 853static inline enum mem_cgroup_protection mem_cgroup_protected(
833 struct mem_cgroup *root, struct mem_cgroup *memcg) 854 struct mem_cgroup *root, struct mem_cgroup *memcg)
834{ 855{
@@ -968,6 +989,11 @@ static inline unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg)
968 return 0; 989 return 0;
969} 990}
970 991
992static inline unsigned long mem_cgroup_size(struct mem_cgroup *memcg)
993{
994 return 0;
995}
996
971static inline void 997static inline void
972mem_cgroup_print_oom_context(struct mem_cgroup *memcg, struct task_struct *p) 998mem_cgroup_print_oom_context(struct mem_cgroup *memcg, struct task_struct *p)
973{ 999{
@@ -1264,6 +1290,9 @@ void mem_cgroup_track_foreign_dirty_slowpath(struct page *page,
1264static inline void mem_cgroup_track_foreign_dirty(struct page *page, 1290static inline void mem_cgroup_track_foreign_dirty(struct page *page,
1265 struct bdi_writeback *wb) 1291 struct bdi_writeback *wb)
1266{ 1292{
1293 if (mem_cgroup_disabled())
1294 return;
1295
1267 if (unlikely(&page->mem_cgroup->css != wb->memcg_css)) 1296 if (unlikely(&page->mem_cgroup->css != wb->memcg_css))
1268 mem_cgroup_track_foreign_dirty_slowpath(page, wb); 1297 mem_cgroup_track_foreign_dirty_slowpath(page, wb);
1269} 1298}
diff --git a/include/linux/micrel_phy.h b/include/linux/micrel_phy.h
index ad24554f11f9..75f880c25bb8 100644
--- a/include/linux/micrel_phy.h
+++ b/include/linux/micrel_phy.h
@@ -31,7 +31,7 @@
31#define PHY_ID_KSZ886X 0x00221430 31#define PHY_ID_KSZ886X 0x00221430
32#define PHY_ID_KSZ8863 0x00221435 32#define PHY_ID_KSZ8863 0x00221435
33 33
34#define PHY_ID_KSZ8795 0x00221550 34#define PHY_ID_KSZ87XX 0x00221550
35 35
36#define PHY_ID_KSZ9477 0x00221631 36#define PHY_ID_KSZ9477 0x00221631
37 37
diff --git a/include/linux/mii.h b/include/linux/mii.h
index 5cd824c1c0ca..4ce8901a1af6 100644
--- a/include/linux/mii.h
+++ b/include/linux/mii.h
@@ -455,6 +455,15 @@ static inline void mii_lpa_mod_linkmode_lpa_t(unsigned long *lp_advertising,
455 lp_advertising, lpa & LPA_LPACK); 455 lp_advertising, lpa & LPA_LPACK);
456} 456}
457 457
458static inline void mii_ctrl1000_mod_linkmode_adv_t(unsigned long *advertising,
459 u32 ctrl1000)
460{
461 linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, advertising,
462 ctrl1000 & ADVERTISE_1000HALF);
463 linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, advertising,
464 ctrl1000 & ADVERTISE_1000FULL);
465}
466
458/** 467/**
459 * linkmode_adv_to_lcl_adv_t 468 * linkmode_adv_to_lcl_adv_t
460 * @advertising:pointer to linkmode advertising 469 * @advertising:pointer to linkmode advertising
diff --git a/include/linux/mlx5/mlx5_ifc.h b/include/linux/mlx5/mlx5_ifc.h
index 138c50d5a353..0836fe232f97 100644
--- a/include/linux/mlx5/mlx5_ifc.h
+++ b/include/linux/mlx5/mlx5_ifc.h
@@ -1545,9 +1545,8 @@ struct mlx5_ifc_extended_dest_format_bits {
1545}; 1545};
1546 1546
1547union mlx5_ifc_dest_format_struct_flow_counter_list_auto_bits { 1547union mlx5_ifc_dest_format_struct_flow_counter_list_auto_bits {
1548 struct mlx5_ifc_dest_format_struct_bits dest_format_struct; 1548 struct mlx5_ifc_extended_dest_format_bits extended_dest_format;
1549 struct mlx5_ifc_flow_counter_list_bits flow_counter_list; 1549 struct mlx5_ifc_flow_counter_list_bits flow_counter_list;
1550 u8 reserved_at_0[0x40];
1551}; 1550};
1552 1551
1553struct mlx5_ifc_fte_match_param_bits { 1552struct mlx5_ifc_fte_match_param_bits {
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 9eda1c31d1f7..c20f190b4c18 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -925,6 +925,7 @@ struct dev_ifalias {
925struct devlink; 925struct devlink;
926struct tlsdev_ops; 926struct tlsdev_ops;
927 927
928
928/* 929/*
929 * This structure defines the management hooks for network devices. 930 * This structure defines the management hooks for network devices.
930 * The following hooks can be defined; unless noted otherwise, they are 931 * The following hooks can be defined; unless noted otherwise, they are
@@ -1421,7 +1422,6 @@ struct net_device_ops {
1421 void (*ndo_dfwd_del_station)(struct net_device *pdev, 1422 void (*ndo_dfwd_del_station)(struct net_device *pdev,
1422 void *priv); 1423 void *priv);
1423 1424
1424 int (*ndo_get_lock_subclass)(struct net_device *dev);
1425 int (*ndo_set_tx_maxrate)(struct net_device *dev, 1425 int (*ndo_set_tx_maxrate)(struct net_device *dev,
1426 int queue_index, 1426 int queue_index,
1427 u32 maxrate); 1427 u32 maxrate);
@@ -1649,6 +1649,8 @@ enum netdev_priv_flags {
1649 * @perm_addr: Permanent hw address 1649 * @perm_addr: Permanent hw address
1650 * @addr_assign_type: Hw address assignment type 1650 * @addr_assign_type: Hw address assignment type
1651 * @addr_len: Hardware address length 1651 * @addr_len: Hardware address length
1652 * @upper_level: Maximum depth level of upper devices.
1653 * @lower_level: Maximum depth level of lower devices.
1652 * @neigh_priv_len: Used in neigh_alloc() 1654 * @neigh_priv_len: Used in neigh_alloc()
1653 * @dev_id: Used to differentiate devices that share 1655 * @dev_id: Used to differentiate devices that share
1654 * the same link layer address 1656 * the same link layer address
@@ -1758,9 +1760,13 @@ enum netdev_priv_flags {
1758 * @phydev: Physical device may attach itself 1760 * @phydev: Physical device may attach itself
1759 * for hardware timestamping 1761 * for hardware timestamping
1760 * @sfp_bus: attached &struct sfp_bus structure. 1762 * @sfp_bus: attached &struct sfp_bus structure.
1761 * 1763 * @qdisc_tx_busylock_key: lockdep class annotating Qdisc->busylock
1762 * @qdisc_tx_busylock: lockdep class annotating Qdisc->busylock spinlock 1764 spinlock
1763 * @qdisc_running_key: lockdep class annotating Qdisc->running seqcount 1765 * @qdisc_running_key: lockdep class annotating Qdisc->running seqcount
1766 * @qdisc_xmit_lock_key: lockdep class annotating
1767 * netdev_queue->_xmit_lock spinlock
1768 * @addr_list_lock_key: lockdep class annotating
1769 * net_device->addr_list_lock spinlock
1764 * 1770 *
1765 * @proto_down: protocol port state information can be sent to the 1771 * @proto_down: protocol port state information can be sent to the
1766 * switch driver and used to set the phys state of the 1772 * switch driver and used to set the phys state of the
@@ -1875,6 +1881,8 @@ struct net_device {
1875 unsigned char perm_addr[MAX_ADDR_LEN]; 1881 unsigned char perm_addr[MAX_ADDR_LEN];
1876 unsigned char addr_assign_type; 1882 unsigned char addr_assign_type;
1877 unsigned char addr_len; 1883 unsigned char addr_len;
1884 unsigned char upper_level;
1885 unsigned char lower_level;
1878 unsigned short neigh_priv_len; 1886 unsigned short neigh_priv_len;
1879 unsigned short dev_id; 1887 unsigned short dev_id;
1880 unsigned short dev_port; 1888 unsigned short dev_port;
@@ -2045,8 +2053,10 @@ struct net_device {
2045#endif 2053#endif
2046 struct phy_device *phydev; 2054 struct phy_device *phydev;
2047 struct sfp_bus *sfp_bus; 2055 struct sfp_bus *sfp_bus;
2048 struct lock_class_key *qdisc_tx_busylock; 2056 struct lock_class_key qdisc_tx_busylock_key;
2049 struct lock_class_key *qdisc_running_key; 2057 struct lock_class_key qdisc_running_key;
2058 struct lock_class_key qdisc_xmit_lock_key;
2059 struct lock_class_key addr_list_lock_key;
2050 bool proto_down; 2060 bool proto_down;
2051 unsigned wol_enabled:1; 2061 unsigned wol_enabled:1;
2052}; 2062};
@@ -2124,23 +2134,6 @@ static inline void netdev_for_each_tx_queue(struct net_device *dev,
2124 f(dev, &dev->_tx[i], arg); 2134 f(dev, &dev->_tx[i], arg);
2125} 2135}
2126 2136
2127#define netdev_lockdep_set_classes(dev) \
2128{ \
2129 static struct lock_class_key qdisc_tx_busylock_key; \
2130 static struct lock_class_key qdisc_running_key; \
2131 static struct lock_class_key qdisc_xmit_lock_key; \
2132 static struct lock_class_key dev_addr_list_lock_key; \
2133 unsigned int i; \
2134 \
2135 (dev)->qdisc_tx_busylock = &qdisc_tx_busylock_key; \
2136 (dev)->qdisc_running_key = &qdisc_running_key; \
2137 lockdep_set_class(&(dev)->addr_list_lock, \
2138 &dev_addr_list_lock_key); \
2139 for (i = 0; i < (dev)->num_tx_queues; i++) \
2140 lockdep_set_class(&(dev)->_tx[i]._xmit_lock, \
2141 &qdisc_xmit_lock_key); \
2142}
2143
2144u16 netdev_pick_tx(struct net_device *dev, struct sk_buff *skb, 2137u16 netdev_pick_tx(struct net_device *dev, struct sk_buff *skb,
2145 struct net_device *sb_dev); 2138 struct net_device *sb_dev);
2146struct netdev_queue *netdev_core_pick_tx(struct net_device *dev, 2139struct netdev_queue *netdev_core_pick_tx(struct net_device *dev,
@@ -3139,6 +3132,7 @@ static inline void netif_stop_queue(struct net_device *dev)
3139} 3132}
3140 3133
3141void netif_tx_stop_all_queues(struct net_device *dev); 3134void netif_tx_stop_all_queues(struct net_device *dev);
3135void netdev_update_lockdep_key(struct net_device *dev);
3142 3136
3143static inline bool netif_tx_queue_stopped(const struct netdev_queue *dev_queue) 3137static inline bool netif_tx_queue_stopped(const struct netdev_queue *dev_queue)
3144{ 3138{
@@ -4056,16 +4050,6 @@ static inline void netif_addr_lock(struct net_device *dev)
4056 spin_lock(&dev->addr_list_lock); 4050 spin_lock(&dev->addr_list_lock);
4057} 4051}
4058 4052
4059static inline void netif_addr_lock_nested(struct net_device *dev)
4060{
4061 int subclass = SINGLE_DEPTH_NESTING;
4062
4063 if (dev->netdev_ops->ndo_get_lock_subclass)
4064 subclass = dev->netdev_ops->ndo_get_lock_subclass(dev);
4065
4066 spin_lock_nested(&dev->addr_list_lock, subclass);
4067}
4068
4069static inline void netif_addr_lock_bh(struct net_device *dev) 4053static inline void netif_addr_lock_bh(struct net_device *dev)
4070{ 4054{
4071 spin_lock_bh(&dev->addr_list_lock); 4055 spin_lock_bh(&dev->addr_list_lock);
@@ -4329,6 +4313,16 @@ int netdev_master_upper_dev_link(struct net_device *dev,
4329 struct netlink_ext_ack *extack); 4313 struct netlink_ext_ack *extack);
4330void netdev_upper_dev_unlink(struct net_device *dev, 4314void netdev_upper_dev_unlink(struct net_device *dev,
4331 struct net_device *upper_dev); 4315 struct net_device *upper_dev);
4316int netdev_adjacent_change_prepare(struct net_device *old_dev,
4317 struct net_device *new_dev,
4318 struct net_device *dev,
4319 struct netlink_ext_ack *extack);
4320void netdev_adjacent_change_commit(struct net_device *old_dev,
4321 struct net_device *new_dev,
4322 struct net_device *dev);
4323void netdev_adjacent_change_abort(struct net_device *old_dev,
4324 struct net_device *new_dev,
4325 struct net_device *dev);
4332void netdev_adjacent_rename_links(struct net_device *dev, char *oldname); 4326void netdev_adjacent_rename_links(struct net_device *dev, char *oldname);
4333void *netdev_lower_dev_get_private(struct net_device *dev, 4327void *netdev_lower_dev_get_private(struct net_device *dev,
4334 struct net_device *lower_dev); 4328 struct net_device *lower_dev);
@@ -4340,7 +4334,6 @@ void netdev_lower_state_changed(struct net_device *lower_dev,
4340extern u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly; 4334extern u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly;
4341void netdev_rss_key_fill(void *buffer, size_t len); 4335void netdev_rss_key_fill(void *buffer, size_t len);
4342 4336
4343int dev_get_nest_level(struct net_device *dev);
4344int skb_checksum_help(struct sk_buff *skb); 4337int skb_checksum_help(struct sk_buff *skb);
4345int skb_crc32c_csum_help(struct sk_buff *skb); 4338int skb_crc32c_csum_help(struct sk_buff *skb);
4346int skb_csum_hwoffload_help(struct sk_buff *skb, 4339int skb_csum_hwoffload_help(struct sk_buff *skb,
diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h
index 682fd465df06..cfce186f0c4e 100644
--- a/include/linux/page_ext.h
+++ b/include/linux/page_ext.h
@@ -18,7 +18,7 @@ struct page_ext_operations {
18 18
19enum page_ext_flags { 19enum page_ext_flags {
20 PAGE_EXT_OWNER, 20 PAGE_EXT_OWNER,
21 PAGE_EXT_OWNER_ACTIVE, 21 PAGE_EXT_OWNER_ALLOCATED,
22#if defined(CONFIG_IDLE_PAGE_TRACKING) && !defined(CONFIG_64BIT) 22#if defined(CONFIG_IDLE_PAGE_TRACKING) && !defined(CONFIG_64BIT)
23 PAGE_EXT_YOUNG, 23 PAGE_EXT_YOUNG,
24 PAGE_EXT_IDLE, 24 PAGE_EXT_IDLE,
@@ -36,6 +36,7 @@ struct page_ext {
36 unsigned long flags; 36 unsigned long flags;
37}; 37};
38 38
39extern unsigned long page_ext_size;
39extern void pgdat_page_ext_init(struct pglist_data *pgdat); 40extern void pgdat_page_ext_init(struct pglist_data *pgdat);
40 41
41#ifdef CONFIG_SPARSEMEM 42#ifdef CONFIG_SPARSEMEM
@@ -52,6 +53,13 @@ static inline void page_ext_init(void)
52 53
53struct page_ext *lookup_page_ext(const struct page *page); 54struct page_ext *lookup_page_ext(const struct page *page);
54 55
56static inline struct page_ext *page_ext_next(struct page_ext *curr)
57{
58 void *next = curr;
59 next += page_ext_size;
60 return next;
61}
62
55#else /* !CONFIG_PAGE_EXTENSION */ 63#else /* !CONFIG_PAGE_EXTENSION */
56struct page_ext; 64struct page_ext;
57 65
diff --git a/include/linux/phy.h b/include/linux/phy.h
index a7ecbe0e55aa..9a0e981df502 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -678,6 +678,7 @@ static inline bool phy_is_started(struct phy_device *phydev)
678 return phydev->state >= PHY_UP; 678 return phydev->state >= PHY_UP;
679} 679}
680 680
681void phy_resolve_aneg_pause(struct phy_device *phydev);
681void phy_resolve_aneg_linkmode(struct phy_device *phydev); 682void phy_resolve_aneg_linkmode(struct phy_device *phydev);
682 683
683/** 684/**
@@ -1076,6 +1077,7 @@ int genphy_config_eee_advert(struct phy_device *phydev);
1076int __genphy_config_aneg(struct phy_device *phydev, bool changed); 1077int __genphy_config_aneg(struct phy_device *phydev, bool changed);
1077int genphy_aneg_done(struct phy_device *phydev); 1078int genphy_aneg_done(struct phy_device *phydev);
1078int genphy_update_link(struct phy_device *phydev); 1079int genphy_update_link(struct phy_device *phydev);
1080int genphy_read_lpa(struct phy_device *phydev);
1079int genphy_read_status(struct phy_device *phydev); 1081int genphy_read_status(struct phy_device *phydev);
1080int genphy_suspend(struct phy_device *phydev); 1082int genphy_suspend(struct phy_device *phydev);
1081int genphy_resume(struct phy_device *phydev); 1083int genphy_resume(struct phy_device *phydev);
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 1b5cec067533..f2688404d1cd 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -64,6 +64,8 @@ extern struct resource *platform_get_resource_byname(struct platform_device *,
64 unsigned int, 64 unsigned int,
65 const char *); 65 const char *);
66extern int platform_get_irq_byname(struct platform_device *, const char *); 66extern int platform_get_irq_byname(struct platform_device *, const char *);
67extern int platform_get_irq_byname_optional(struct platform_device *dev,
68 const char *name);
67extern int platform_add_devices(struct platform_device **, int); 69extern int platform_add_devices(struct platform_device **, int);
68 70
69struct platform_device_info { 71struct platform_device_info {
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 2c2e56bd8913..67a1d86981a9 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -223,6 +223,7 @@ extern long schedule_timeout_uninterruptible(long timeout);
223extern long schedule_timeout_idle(long timeout); 223extern long schedule_timeout_idle(long timeout);
224asmlinkage void schedule(void); 224asmlinkage void schedule(void);
225extern void schedule_preempt_disabled(void); 225extern void schedule_preempt_disabled(void);
226asmlinkage void preempt_schedule_irq(void);
226 227
227extern int __must_check io_schedule_prepare(void); 228extern int __must_check io_schedule_prepare(void);
228extern void io_schedule_finish(int token); 229extern void io_schedule_finish(int token);
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index e7d3b1a513ef..64a395c7f689 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1354,7 +1354,8 @@ static inline __u32 skb_get_hash_flowi6(struct sk_buff *skb, const struct flowi6
1354 return skb->hash; 1354 return skb->hash;
1355} 1355}
1356 1356
1357__u32 skb_get_hash_perturb(const struct sk_buff *skb, u32 perturb); 1357__u32 skb_get_hash_perturb(const struct sk_buff *skb,
1358 const siphash_key_t *perturb);
1358 1359
1359static inline __u32 skb_get_hash_raw(const struct sk_buff *skb) 1360static inline __u32 skb_get_hash_raw(const struct sk_buff *skb)
1360{ 1361{
@@ -1495,6 +1496,19 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
1495} 1496}
1496 1497
1497/** 1498/**
1499 * skb_queue_empty_lockless - check if a queue is empty
1500 * @list: queue head
1501 *
1502 * Returns true if the queue is empty, false otherwise.
1503 * This variant can be used in lockless contexts.
1504 */
1505static inline bool skb_queue_empty_lockless(const struct sk_buff_head *list)
1506{
1507 return READ_ONCE(list->next) == (const struct sk_buff *) list;
1508}
1509
1510
1511/**
1498 * skb_queue_is_last - check if skb is the last entry in the queue 1512 * skb_queue_is_last - check if skb is the last entry in the queue
1499 * @list: queue head 1513 * @list: queue head
1500 * @skb: buffer 1514 * @skb: buffer
@@ -1847,9 +1861,11 @@ static inline void __skb_insert(struct sk_buff *newsk,
1847 struct sk_buff *prev, struct sk_buff *next, 1861 struct sk_buff *prev, struct sk_buff *next,
1848 struct sk_buff_head *list) 1862 struct sk_buff_head *list)
1849{ 1863{
1850 newsk->next = next; 1864 /* see skb_queue_empty_lockless() for the opposite READ_ONCE() */
1851 newsk->prev = prev; 1865 WRITE_ONCE(newsk->next, next);
1852 next->prev = prev->next = newsk; 1866 WRITE_ONCE(newsk->prev, prev);
1867 WRITE_ONCE(next->prev, newsk);
1868 WRITE_ONCE(prev->next, newsk);
1853 list->qlen++; 1869 list->qlen++;
1854} 1870}
1855 1871
@@ -1860,11 +1876,11 @@ static inline void __skb_queue_splice(const struct sk_buff_head *list,
1860 struct sk_buff *first = list->next; 1876 struct sk_buff *first = list->next;
1861 struct sk_buff *last = list->prev; 1877 struct sk_buff *last = list->prev;
1862 1878
1863 first->prev = prev; 1879 WRITE_ONCE(first->prev, prev);
1864 prev->next = first; 1880 WRITE_ONCE(prev->next, first);
1865 1881
1866 last->next = next; 1882 WRITE_ONCE(last->next, next);
1867 next->prev = last; 1883 WRITE_ONCE(next->prev, last);
1868} 1884}
1869 1885
1870/** 1886/**
@@ -2005,8 +2021,8 @@ static inline void __skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
2005 next = skb->next; 2021 next = skb->next;
2006 prev = skb->prev; 2022 prev = skb->prev;
2007 skb->next = skb->prev = NULL; 2023 skb->next = skb->prev = NULL;
2008 next->prev = prev; 2024 WRITE_ONCE(next->prev, prev);
2009 prev->next = next; 2025 WRITE_ONCE(prev->next, next);
2010} 2026}
2011 2027
2012/** 2028/**
@@ -3510,8 +3526,9 @@ int skb_ensure_writable(struct sk_buff *skb, int write_len);
3510int __skb_vlan_pop(struct sk_buff *skb, u16 *vlan_tci); 3526int __skb_vlan_pop(struct sk_buff *skb, u16 *vlan_tci);
3511int skb_vlan_pop(struct sk_buff *skb); 3527int skb_vlan_pop(struct sk_buff *skb);
3512int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci); 3528int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci);
3513int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto); 3529int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto,
3514int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto); 3530 int mac_len);
3531int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len);
3515int skb_mpls_update_lse(struct sk_buff *skb, __be32 mpls_lse); 3532int skb_mpls_update_lse(struct sk_buff *skb, __be32 mpls_lse);
3516int skb_mpls_dec_ttl(struct sk_buff *skb); 3533int skb_mpls_dec_ttl(struct sk_buff *skb);
3517struct sk_buff *pskb_extract(struct sk_buff *skb, int off, int to_copy, 3534struct sk_buff *pskb_extract(struct sk_buff *skb, int off, int to_copy,
@@ -4160,15 +4177,12 @@ static inline void __skb_ext_copy(struct sk_buff *d, const struct sk_buff *s) {}
4160static inline void skb_ext_copy(struct sk_buff *dst, const struct sk_buff *s) {} 4177static inline void skb_ext_copy(struct sk_buff *dst, const struct sk_buff *s) {}
4161#endif /* CONFIG_SKB_EXTENSIONS */ 4178#endif /* CONFIG_SKB_EXTENSIONS */
4162 4179
4163static inline void nf_reset(struct sk_buff *skb) 4180static inline void nf_reset_ct(struct sk_buff *skb)
4164{ 4181{
4165#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) 4182#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
4166 nf_conntrack_put(skb_nfct(skb)); 4183 nf_conntrack_put(skb_nfct(skb));
4167 skb->_nfct = 0; 4184 skb->_nfct = 0;
4168#endif 4185#endif
4169#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
4170 skb_ext_del(skb, SKB_EXT_BRIDGE_NF);
4171#endif
4172} 4186}
4173 4187
4174static inline void nf_reset_trace(struct sk_buff *skb) 4188static inline void nf_reset_trace(struct sk_buff *skb)
diff --git a/include/linux/slab.h b/include/linux/slab.h
index ab2b98ad76e1..4d2a2fa55ed5 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -493,6 +493,10 @@ static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
493 * kmalloc is the normal method of allocating memory 493 * kmalloc is the normal method of allocating memory
494 * for objects smaller than page size in the kernel. 494 * for objects smaller than page size in the kernel.
495 * 495 *
496 * The allocated object address is aligned to at least ARCH_KMALLOC_MINALIGN
497 * bytes. For @size of power of two bytes, the alignment is also guaranteed
498 * to be at least to the size.
499 *
496 * The @flags argument may be one of the GFP flags defined at 500 * The @flags argument may be one of the GFP flags defined at
497 * include/linux/gfp.h and described at 501 * include/linux/gfp.h and described at
498 * :ref:`Documentation/core-api/mm-api.rst <mm-api-gfp-flags>` 502 * :ref:`Documentation/core-api/mm-api.rst <mm-api-gfp-flags>`
diff --git a/include/linux/socket.h b/include/linux/socket.h
index fc0bed59fc84..4049d9755cf1 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -263,7 +263,7 @@ struct ucred {
263#define PF_MAX AF_MAX 263#define PF_MAX AF_MAX
264 264
265/* Maximum queue length specifiable by listen. */ 265/* Maximum queue length specifiable by listen. */
266#define SOMAXCONN 128 266#define SOMAXCONN 4096
267 267
268/* Flags we can use with send/ and recv. 268/* Flags we can use with send/ and recv.
269 Added those for 1003.1g not all are supported yet 269 Added those for 1003.1g not all are supported yet
diff --git a/include/linux/string.h b/include/linux/string.h
index b2f9df7f0761..b6ccdc2c7f02 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -227,7 +227,26 @@ static inline bool strstarts(const char *str, const char *prefix)
227} 227}
228 228
229size_t memweight(const void *ptr, size_t bytes); 229size_t memweight(const void *ptr, size_t bytes);
230void memzero_explicit(void *s, size_t count); 230
231/**
232 * memzero_explicit - Fill a region of memory (e.g. sensitive
233 * keying data) with 0s.
234 * @s: Pointer to the start of the area.
235 * @count: The size of the area.
236 *
237 * Note: usually using memset() is just fine (!), but in cases
238 * where clearing out _local_ data at the end of a scope is
239 * necessary, memzero_explicit() should be used instead in
240 * order to prevent the compiler from optimising away zeroing.
241 *
242 * memzero_explicit() doesn't need an arch-specific version as
243 * it just invokes the one of memset() implicitly.
244 */
245static inline void memzero_explicit(void *s, size_t count)
246{
247 memset(s, 0, count);
248 barrier_data(s);
249}
231 250
232/** 251/**
233 * kbasename - return the last part of a pathname. 252 * kbasename - return the last part of a pathname.
diff --git a/include/linux/sunrpc/xprtsock.h b/include/linux/sunrpc/xprtsock.h
index 7638dbe7bc50..a940de03808d 100644
--- a/include/linux/sunrpc/xprtsock.h
+++ b/include/linux/sunrpc/xprtsock.h
@@ -61,6 +61,7 @@ struct sock_xprt {
61 struct mutex recv_mutex; 61 struct mutex recv_mutex;
62 struct sockaddr_storage srcaddr; 62 struct sockaddr_storage srcaddr;
63 unsigned short srcport; 63 unsigned short srcport;
64 int xprt_err;
64 65
65 /* 66 /*
66 * UDP socket buffer size parameters 67 * UDP socket buffer size parameters
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index 99617e528ea2..668e25a76d69 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -393,7 +393,7 @@ struct tcp_sock {
393 /* fastopen_rsk points to request_sock that resulted in this big 393 /* fastopen_rsk points to request_sock that resulted in this big
394 * socket. Used to retransmit SYNACKs etc. 394 * socket. Used to retransmit SYNACKs etc.
395 */ 395 */
396 struct request_sock *fastopen_rsk; 396 struct request_sock __rcu *fastopen_rsk;
397 u32 *saved_syn; 397 u32 *saved_syn;
398}; 398};
399 399
@@ -447,8 +447,8 @@ static inline struct tcp_timewait_sock *tcp_twsk(const struct sock *sk)
447 447
448static inline bool tcp_passive_fastopen(const struct sock *sk) 448static inline bool tcp_passive_fastopen(const struct sock *sk)
449{ 449{
450 return (sk->sk_state == TCP_SYN_RECV && 450 return sk->sk_state == TCP_SYN_RECV &&
451 tcp_sk(sk)->fastopen_rsk != NULL); 451 rcu_access_pointer(tcp_sk(sk)->fastopen_rsk) != NULL;
452} 452}
453 453
454static inline void fastopen_queue_tune(struct sock *sk, int backlog) 454static inline void fastopen_queue_tune(struct sock *sk, int backlog)
diff --git a/include/linux/tpm_eventlog.h b/include/linux/tpm_eventlog.h
index 63238c84dc0b..131ea1bad458 100644
--- a/include/linux/tpm_eventlog.h
+++ b/include/linux/tpm_eventlog.h
@@ -152,7 +152,7 @@ struct tcg_algorithm_info {
152 * total. Once we've done this we know the offset of the data length field, 152 * total. Once we've done this we know the offset of the data length field,
153 * and can calculate the total size of the event. 153 * and can calculate the total size of the event.
154 * 154 *
155 * Return: size of the event on success, <0 on failure 155 * Return: size of the event on success, 0 on failure
156 */ 156 */
157 157
158static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event, 158static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
@@ -170,6 +170,7 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
170 u16 halg; 170 u16 halg;
171 int i; 171 int i;
172 int j; 172 int j;
173 u32 count, event_type;
173 174
174 marker = event; 175 marker = event;
175 marker_start = marker; 176 marker_start = marker;
@@ -190,16 +191,22 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
190 } 191 }
191 192
192 event = (struct tcg_pcr_event2_head *)mapping; 193 event = (struct tcg_pcr_event2_head *)mapping;
194 /*
195 * The loop below will unmap these fields if the log is larger than
196 * one page, so save them here for reference:
197 */
198 count = READ_ONCE(event->count);
199 event_type = READ_ONCE(event->event_type);
193 200
194 efispecid = (struct tcg_efi_specid_event_head *)event_header->event; 201 efispecid = (struct tcg_efi_specid_event_head *)event_header->event;
195 202
196 /* Check if event is malformed. */ 203 /* Check if event is malformed. */
197 if (event->count > efispecid->num_algs) { 204 if (count > efispecid->num_algs) {
198 size = 0; 205 size = 0;
199 goto out; 206 goto out;
200 } 207 }
201 208
202 for (i = 0; i < event->count; i++) { 209 for (i = 0; i < count; i++) {
203 halg_size = sizeof(event->digests[i].alg_id); 210 halg_size = sizeof(event->digests[i].alg_id);
204 211
205 /* Map the digest's algorithm identifier */ 212 /* Map the digest's algorithm identifier */
@@ -256,8 +263,9 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
256 + event_field->event_size; 263 + event_field->event_size;
257 size = marker - marker_start; 264 size = marker - marker_start;
258 265
259 if ((event->event_type == 0) && (event_field->event_size == 0)) 266 if (event_type == 0 && event_field->event_size == 0)
260 size = 0; 267 size = 0;
268
261out: 269out:
262 if (do_mapping) 270 if (do_mapping)
263 TPM_MEMUNMAP(mapping, mapping_size); 271 TPM_MEMUNMAP(mapping, mapping_size);
diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
index 70bbdc38dc37..d4ee6e942562 100644
--- a/include/linux/uaccess.h
+++ b/include/linux/uaccess.h
@@ -231,6 +231,76 @@ __copy_from_user_inatomic_nocache(void *to, const void __user *from,
231 231
232#endif /* ARCH_HAS_NOCACHE_UACCESS */ 232#endif /* ARCH_HAS_NOCACHE_UACCESS */
233 233
234extern __must_check int check_zeroed_user(const void __user *from, size_t size);
235
236/**
237 * copy_struct_from_user: copy a struct from userspace
238 * @dst: Destination address, in kernel space. This buffer must be @ksize
239 * bytes long.
240 * @ksize: Size of @dst struct.
241 * @src: Source address, in userspace.
242 * @usize: (Alleged) size of @src struct.
243 *
244 * Copies a struct from userspace to kernel space, in a way that guarantees
245 * backwards-compatibility for struct syscall arguments (as long as future
246 * struct extensions are made such that all new fields are *appended* to the
247 * old struct, and zeroed-out new fields have the same meaning as the old
248 * struct).
249 *
250 * @ksize is just sizeof(*dst), and @usize should've been passed by userspace.
251 * The recommended usage is something like the following:
252 *
253 * SYSCALL_DEFINE2(foobar, const struct foo __user *, uarg, size_t, usize)
254 * {
255 * int err;
256 * struct foo karg = {};
257 *
258 * if (usize > PAGE_SIZE)
259 * return -E2BIG;
260 * if (usize < FOO_SIZE_VER0)
261 * return -EINVAL;
262 *
263 * err = copy_struct_from_user(&karg, sizeof(karg), uarg, usize);
264 * if (err)
265 * return err;
266 *
267 * // ...
268 * }
269 *
270 * There are three cases to consider:
271 * * If @usize == @ksize, then it's copied verbatim.
272 * * If @usize < @ksize, then the userspace has passed an old struct to a
273 * newer kernel. The rest of the trailing bytes in @dst (@ksize - @usize)
274 * are to be zero-filled.
275 * * If @usize > @ksize, then the userspace has passed a new struct to an
276 * older kernel. The trailing bytes unknown to the kernel (@usize - @ksize)
277 * are checked to ensure they are zeroed, otherwise -E2BIG is returned.
278 *
279 * Returns (in all cases, some data may have been copied):
280 * * -E2BIG: (@usize > @ksize) and there are non-zero trailing bytes in @src.
281 * * -EFAULT: access to userspace failed.
282 */
283static __always_inline __must_check int
284copy_struct_from_user(void *dst, size_t ksize, const void __user *src,
285 size_t usize)
286{
287 size_t size = min(ksize, usize);
288 size_t rest = max(ksize, usize) - size;
289
290 /* Deal with trailing bytes. */
291 if (usize < ksize) {
292 memset(dst + size, 0, rest);
293 } else if (usize > ksize) {
294 int ret = check_zeroed_user(src + size, rest);
295 if (ret <= 0)
296 return ret ?: -E2BIG;
297 }
298 /* Copy the interoperable parts of the struct. */
299 if (copy_from_user(dst, src, size))
300 return -EFAULT;
301 return 0;
302}
303
234/* 304/*
235 * probe_kernel_read(): safely attempt to read from a location 305 * probe_kernel_read(): safely attempt to read from a location
236 * @dst: pointer to the buffer that shall take the data 306 * @dst: pointer to the buffer that shall take the data
@@ -285,8 +355,10 @@ extern long strnlen_unsafe_user(const void __user *unsafe_addr, long count);
285#ifndef user_access_begin 355#ifndef user_access_begin
286#define user_access_begin(ptr,len) access_ok(ptr, len) 356#define user_access_begin(ptr,len) access_ok(ptr, len)
287#define user_access_end() do { } while (0) 357#define user_access_end() do { } while (0)
288#define unsafe_get_user(x, ptr, err) do { if (unlikely(__get_user(x, ptr))) goto err; } while (0) 358#define unsafe_op_wrap(op, err) do { if (unlikely(op)) goto err; } while (0)
289#define unsafe_put_user(x, ptr, err) do { if (unlikely(__put_user(x, ptr))) goto err; } while (0) 359#define unsafe_get_user(x,p,e) unsafe_op_wrap(__get_user(x,p),e)
360#define unsafe_put_user(x,p,e) unsafe_op_wrap(__put_user(x,p),e)
361#define unsafe_copy_to_user(d,s,l,e) unsafe_op_wrap(__copy_to_user(d,s,l),e)
290static inline unsigned long user_access_save(void) { return 0UL; } 362static inline unsigned long user_access_save(void) { return 0UL; }
291static inline void user_access_restore(unsigned long flags) { } 363static inline void user_access_restore(unsigned long flags) { }
292#endif 364#endif
diff --git a/include/linux/xarray.h b/include/linux/xarray.h
index 5921599b6dc4..86eecbd98e84 100644
--- a/include/linux/xarray.h
+++ b/include/linux/xarray.h
@@ -230,8 +230,8 @@ static inline int xa_err(void *entry)
230 * This structure is used either directly or via the XA_LIMIT() macro 230 * This structure is used either directly or via the XA_LIMIT() macro
231 * to communicate the range of IDs that are valid for allocation. 231 * to communicate the range of IDs that are valid for allocation.
232 * Two common ranges are predefined for you: 232 * Two common ranges are predefined for you:
233 * * xa_limit_32b - [0 - UINT_MAX] 233 * * xa_limit_32b - [0 - UINT_MAX]
234 * * xa_limit_31b - [0 - INT_MAX] 234 * * xa_limit_31b - [0 - INT_MAX]
235 */ 235 */
236struct xa_limit { 236struct xa_limit {
237 u32 max; 237 u32 max;
diff --git a/include/net/bonding.h b/include/net/bonding.h
index f7fe45689142..1afc125014da 100644
--- a/include/net/bonding.h
+++ b/include/net/bonding.h
@@ -203,7 +203,6 @@ struct bonding {
203 struct slave __rcu *primary_slave; 203 struct slave __rcu *primary_slave;
204 struct bond_up_slave __rcu *slave_arr; /* Array of usable slaves */ 204 struct bond_up_slave __rcu *slave_arr; /* Array of usable slaves */
205 bool force_primary; 205 bool force_primary;
206 u32 nest_level;
207 s32 slave_cnt; /* never change this value outside the attach/detach wrappers */ 206 s32 slave_cnt; /* never change this value outside the attach/detach wrappers */
208 int (*recv_probe)(const struct sk_buff *, struct bonding *, 207 int (*recv_probe)(const struct sk_buff *, struct bonding *,
209 struct slave *); 208 struct slave *);
@@ -239,6 +238,7 @@ struct bonding {
239 struct dentry *debug_dir; 238 struct dentry *debug_dir;
240#endif /* CONFIG_DEBUG_FS */ 239#endif /* CONFIG_DEBUG_FS */
241 struct rtnl_link_stats64 bond_stats; 240 struct rtnl_link_stats64 bond_stats;
241 struct lock_class_key stats_lock_key;
242}; 242};
243 243
244#define bond_slave_get_rcu(dev) \ 244#define bond_slave_get_rcu(dev) \
diff --git a/include/net/busy_poll.h b/include/net/busy_poll.h
index 127a5c4e3699..86e028388bad 100644
--- a/include/net/busy_poll.h
+++ b/include/net/busy_poll.h
@@ -122,7 +122,7 @@ static inline void skb_mark_napi_id(struct sk_buff *skb,
122static inline void sk_mark_napi_id(struct sock *sk, const struct sk_buff *skb) 122static inline void sk_mark_napi_id(struct sock *sk, const struct sk_buff *skb)
123{ 123{
124#ifdef CONFIG_NET_RX_BUSY_POLL 124#ifdef CONFIG_NET_RX_BUSY_POLL
125 sk->sk_napi_id = skb->napi_id; 125 WRITE_ONCE(sk->sk_napi_id, skb->napi_id);
126#endif 126#endif
127 sk_rx_queue_set(sk, skb); 127 sk_rx_queue_set(sk, skb);
128} 128}
@@ -132,8 +132,8 @@ static inline void sk_mark_napi_id_once(struct sock *sk,
132 const struct sk_buff *skb) 132 const struct sk_buff *skb)
133{ 133{
134#ifdef CONFIG_NET_RX_BUSY_POLL 134#ifdef CONFIG_NET_RX_BUSY_POLL
135 if (!sk->sk_napi_id) 135 if (!READ_ONCE(sk->sk_napi_id))
136 sk->sk_napi_id = skb->napi_id; 136 WRITE_ONCE(sk->sk_napi_id, skb->napi_id);
137#endif 137#endif
138} 138}
139 139
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index ff45c3e1abff..4ab2c49423dc 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -5550,6 +5550,14 @@ const struct ieee80211_reg_rule *freq_reg_info(struct wiphy *wiphy,
5550const char *reg_initiator_name(enum nl80211_reg_initiator initiator); 5550const char *reg_initiator_name(enum nl80211_reg_initiator initiator);
5551 5551
5552/** 5552/**
5553 * regulatory_pre_cac_allowed - check if pre-CAC allowed in the current regdom
5554 * @wiphy: wiphy for which pre-CAC capability is checked.
5555 *
5556 * Pre-CAC is allowed only in some regdomains (notable ETSI).
5557 */
5558bool regulatory_pre_cac_allowed(struct wiphy *wiphy);
5559
5560/**
5553 * DOC: Internal regulatory db functions 5561 * DOC: Internal regulatory db functions
5554 * 5562 *
5555 */ 5563 */
diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h
index 90bd210be060..5cd12276ae21 100644
--- a/include/net/flow_dissector.h
+++ b/include/net/flow_dissector.h
@@ -4,6 +4,7 @@
4 4
5#include <linux/types.h> 5#include <linux/types.h>
6#include <linux/in6.h> 6#include <linux/in6.h>
7#include <linux/siphash.h>
7#include <uapi/linux/if_ether.h> 8#include <uapi/linux/if_ether.h>
8 9
9/** 10/**
@@ -276,7 +277,7 @@ struct flow_keys_basic {
276struct flow_keys { 277struct flow_keys {
277 struct flow_dissector_key_control control; 278 struct flow_dissector_key_control control;
278#define FLOW_KEYS_HASH_START_FIELD basic 279#define FLOW_KEYS_HASH_START_FIELD basic
279 struct flow_dissector_key_basic basic; 280 struct flow_dissector_key_basic basic __aligned(SIPHASH_ALIGNMENT);
280 struct flow_dissector_key_tags tags; 281 struct flow_dissector_key_tags tags;
281 struct flow_dissector_key_vlan vlan; 282 struct flow_dissector_key_vlan vlan;
282 struct flow_dissector_key_vlan cvlan; 283 struct flow_dissector_key_vlan cvlan;
diff --git a/include/net/fq.h b/include/net/fq.h
index d126b5d20261..2ad85e683041 100644
--- a/include/net/fq.h
+++ b/include/net/fq.h
@@ -69,7 +69,7 @@ struct fq {
69 struct list_head backlogs; 69 struct list_head backlogs;
70 spinlock_t lock; 70 spinlock_t lock;
71 u32 flows_cnt; 71 u32 flows_cnt;
72 u32 perturbation; 72 siphash_key_t perturbation;
73 u32 limit; 73 u32 limit;
74 u32 memory_limit; 74 u32 memory_limit;
75 u32 memory_usage; 75 u32 memory_usage;
diff --git a/include/net/fq_impl.h b/include/net/fq_impl.h
index be40a4b327e3..107c0d700ed6 100644
--- a/include/net/fq_impl.h
+++ b/include/net/fq_impl.h
@@ -108,7 +108,7 @@ begin:
108 108
109static u32 fq_flow_idx(struct fq *fq, struct sk_buff *skb) 109static u32 fq_flow_idx(struct fq *fq, struct sk_buff *skb)
110{ 110{
111 u32 hash = skb_get_hash_perturb(skb, fq->perturbation); 111 u32 hash = skb_get_hash_perturb(skb, &fq->perturbation);
112 112
113 return reciprocal_scale(hash, fq->flows_cnt); 113 return reciprocal_scale(hash, fq->flows_cnt);
114} 114}
@@ -308,7 +308,7 @@ static int fq_init(struct fq *fq, int flows_cnt)
308 INIT_LIST_HEAD(&fq->backlogs); 308 INIT_LIST_HEAD(&fq->backlogs);
309 spin_lock_init(&fq->lock); 309 spin_lock_init(&fq->lock);
310 fq->flows_cnt = max_t(u32, flows_cnt, 1); 310 fq->flows_cnt = max_t(u32, flows_cnt, 1);
311 fq->perturbation = prandom_u32(); 311 get_random_bytes(&fq->perturbation, sizeof(fq->perturbation));
312 fq->quantum = 300; 312 fq->quantum = 300;
313 fq->limit = 8192; 313 fq->limit = 8192;
314 fq->memory_limit = 16 << 20; /* 16 MBytes */ 314 fq->memory_limit = 16 << 20; /* 16 MBytes */
diff --git a/include/net/hwbm.h b/include/net/hwbm.h
index 81643cf8a1c4..c81444611a22 100644
--- a/include/net/hwbm.h
+++ b/include/net/hwbm.h
@@ -21,9 +21,13 @@ void hwbm_buf_free(struct hwbm_pool *bm_pool, void *buf);
21int hwbm_pool_refill(struct hwbm_pool *bm_pool, gfp_t gfp); 21int hwbm_pool_refill(struct hwbm_pool *bm_pool, gfp_t gfp);
22int hwbm_pool_add(struct hwbm_pool *bm_pool, unsigned int buf_num); 22int hwbm_pool_add(struct hwbm_pool *bm_pool, unsigned int buf_num);
23#else 23#else
24void hwbm_buf_free(struct hwbm_pool *bm_pool, void *buf) {} 24static inline void hwbm_buf_free(struct hwbm_pool *bm_pool, void *buf) {}
25int hwbm_pool_refill(struct hwbm_pool *bm_pool, gfp_t gfp) { return 0; } 25
26int hwbm_pool_add(struct hwbm_pool *bm_pool, unsigned int buf_num) 26static inline int hwbm_pool_refill(struct hwbm_pool *bm_pool, gfp_t gfp)
27{ return 0; }
28
29static inline int hwbm_pool_add(struct hwbm_pool *bm_pool,
30 unsigned int buf_num)
27{ return 0; } 31{ return 0; }
28#endif /* CONFIG_HWBM */ 32#endif /* CONFIG_HWBM */
29#endif /* _HWBM_H */ 33#endif /* _HWBM_H */
diff --git a/include/net/ip.h b/include/net/ip.h
index 95bb77f95bcc..a2c61c36dc4a 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -185,7 +185,7 @@ static inline struct sk_buff *ip_fraglist_next(struct ip_fraglist_iter *iter)
185} 185}
186 186
187struct ip_frag_state { 187struct ip_frag_state {
188 struct iphdr *iph; 188 bool DF;
189 unsigned int hlen; 189 unsigned int hlen;
190 unsigned int ll_rs; 190 unsigned int ll_rs;
191 unsigned int mtu; 191 unsigned int mtu;
@@ -196,7 +196,7 @@ struct ip_frag_state {
196}; 196};
197 197
198void ip_frag_init(struct sk_buff *skb, unsigned int hlen, unsigned int ll_rs, 198void ip_frag_init(struct sk_buff *skb, unsigned int hlen, unsigned int ll_rs,
199 unsigned int mtu, struct ip_frag_state *state); 199 unsigned int mtu, bool DF, struct ip_frag_state *state);
200struct sk_buff *ip_frag_next(struct sk_buff *skb, 200struct sk_buff *ip_frag_next(struct sk_buff *skb,
201 struct ip_frag_state *state); 201 struct ip_frag_state *state);
202 202
diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
index 3759167f91f5..078887c8c586 100644
--- a/include/net/ip_vs.h
+++ b/include/net/ip_vs.h
@@ -889,6 +889,7 @@ struct netns_ipvs {
889 struct delayed_work defense_work; /* Work handler */ 889 struct delayed_work defense_work; /* Work handler */
890 int drop_rate; 890 int drop_rate;
891 int drop_counter; 891 int drop_counter;
892 int old_secure_tcp;
892 atomic_t dropentry; 893 atomic_t dropentry;
893 /* locks in ctl.c */ 894 /* locks in ctl.c */
894 spinlock_t dropentry_lock; /* drop entry handling */ 895 spinlock_t dropentry_lock; /* drop entry handling */
diff --git a/include/net/llc_conn.h b/include/net/llc_conn.h
index df528a623548..ea985aa7a6c5 100644
--- a/include/net/llc_conn.h
+++ b/include/net/llc_conn.h
@@ -104,7 +104,7 @@ void llc_sk_reset(struct sock *sk);
104 104
105/* Access to a connection */ 105/* Access to a connection */
106int llc_conn_state_process(struct sock *sk, struct sk_buff *skb); 106int llc_conn_state_process(struct sock *sk, struct sk_buff *skb);
107int llc_conn_send_pdu(struct sock *sk, struct sk_buff *skb); 107void llc_conn_send_pdu(struct sock *sk, struct sk_buff *skb);
108void llc_conn_rtn_pdu(struct sock *sk, struct sk_buff *skb); 108void llc_conn_rtn_pdu(struct sock *sk, struct sk_buff *skb);
109void llc_conn_resend_i_pdu_as_cmd(struct sock *sk, u8 nr, u8 first_p_bit); 109void llc_conn_resend_i_pdu_as_cmd(struct sock *sk, u8 nr, u8 first_p_bit);
110void llc_conn_resend_i_pdu_as_rsp(struct sock *sk, u8 nr, u8 first_f_bit); 110void llc_conn_resend_i_pdu_as_rsp(struct sock *sk, u8 nr, u8 first_f_bit);
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index f8712bbeb2e0..c7e15a213ef2 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -52,6 +52,9 @@ struct bpf_prog;
52#define NETDEV_HASHENTRIES (1 << NETDEV_HASHBITS) 52#define NETDEV_HASHENTRIES (1 << NETDEV_HASHBITS)
53 53
54struct net { 54struct net {
55 /* First cache line can be often dirtied.
56 * Do not place here read-mostly fields.
57 */
55 refcount_t passive; /* To decide when the network 58 refcount_t passive; /* To decide when the network
56 * namespace should be freed. 59 * namespace should be freed.
57 */ 60 */
@@ -60,7 +63,13 @@ struct net {
60 */ 63 */
61 spinlock_t rules_mod_lock; 64 spinlock_t rules_mod_lock;
62 65
63 u32 hash_mix; 66 unsigned int dev_unreg_count;
67
68 unsigned int dev_base_seq; /* protected by rtnl_mutex */
69 int ifindex;
70
71 spinlock_t nsid_lock;
72 atomic_t fnhe_genid;
64 73
65 struct list_head list; /* list of network namespaces */ 74 struct list_head list; /* list of network namespaces */
66 struct list_head exit_list; /* To linked to call pernet exit 75 struct list_head exit_list; /* To linked to call pernet exit
@@ -76,11 +85,11 @@ struct net {
76#endif 85#endif
77 struct user_namespace *user_ns; /* Owning user namespace */ 86 struct user_namespace *user_ns; /* Owning user namespace */
78 struct ucounts *ucounts; 87 struct ucounts *ucounts;
79 spinlock_t nsid_lock;
80 struct idr netns_ids; 88 struct idr netns_ids;
81 89
82 struct ns_common ns; 90 struct ns_common ns;
83 91
92 struct list_head dev_base_head;
84 struct proc_dir_entry *proc_net; 93 struct proc_dir_entry *proc_net;
85 struct proc_dir_entry *proc_net_stat; 94 struct proc_dir_entry *proc_net_stat;
86 95
@@ -93,17 +102,18 @@ struct net {
93 102
94 struct uevent_sock *uevent_sock; /* uevent socket */ 103 struct uevent_sock *uevent_sock; /* uevent socket */
95 104
96 struct list_head dev_base_head;
97 struct hlist_head *dev_name_head; 105 struct hlist_head *dev_name_head;
98 struct hlist_head *dev_index_head; 106 struct hlist_head *dev_index_head;
99 unsigned int dev_base_seq; /* protected by rtnl_mutex */ 107 /* Note that @hash_mix can be read millions times per second,
100 int ifindex; 108 * it is critical that it is on a read_mostly cache line.
101 unsigned int dev_unreg_count; 109 */
110 u32 hash_mix;
111
112 struct net_device *loopback_dev; /* The loopback */
102 113
103 /* core fib_rules */ 114 /* core fib_rules */
104 struct list_head rules_ops; 115 struct list_head rules_ops;
105 116
106 struct net_device *loopback_dev; /* The loopback */
107 struct netns_core core; 117 struct netns_core core;
108 struct netns_mib mib; 118 struct netns_mib mib;
109 struct netns_packet packet; 119 struct netns_packet packet;
@@ -171,7 +181,6 @@ struct net {
171 struct sock *crypto_nlsk; 181 struct sock *crypto_nlsk;
172#endif 182#endif
173 struct sock *diag_nlsk; 183 struct sock *diag_nlsk;
174 atomic_t fnhe_genid;
175} __randomize_layout; 184} __randomize_layout;
176 185
177#include <linux/seq_file_net.h> 186#include <linux/seq_file_net.h>
@@ -333,7 +342,7 @@ static inline struct net *read_pnet(const possible_net_t *pnet)
333#define __net_initconst __initconst 342#define __net_initconst __initconst
334#endif 343#endif
335 344
336int peernet2id_alloc(struct net *net, struct net *peer); 345int peernet2id_alloc(struct net *net, struct net *peer, gfp_t gfp);
337int peernet2id(struct net *net, struct net *peer); 346int peernet2id(struct net *net, struct net *peer);
338bool peernet_has_id(struct net *net, struct net *peer); 347bool peernet_has_id(struct net *net, struct net *peer);
339struct net *get_net_ns_by_id(struct net *net, int id); 348struct net *get_net_ns_by_id(struct net *net, int id);
diff --git a/include/net/request_sock.h b/include/net/request_sock.h
index fd178d58fa84..cf8b33213bbc 100644
--- a/include/net/request_sock.h
+++ b/include/net/request_sock.h
@@ -185,7 +185,7 @@ void reqsk_fastopen_remove(struct sock *sk, struct request_sock *req,
185 185
186static inline bool reqsk_queue_empty(const struct request_sock_queue *queue) 186static inline bool reqsk_queue_empty(const struct request_sock_queue *queue)
187{ 187{
188 return queue->rskq_accept_head == NULL; 188 return READ_ONCE(queue->rskq_accept_head) == NULL;
189} 189}
190 190
191static inline struct request_sock *reqsk_queue_remove(struct request_sock_queue *queue, 191static inline struct request_sock *reqsk_queue_remove(struct request_sock_queue *queue,
@@ -197,7 +197,7 @@ static inline struct request_sock *reqsk_queue_remove(struct request_sock_queue
197 req = queue->rskq_accept_head; 197 req = queue->rskq_accept_head;
198 if (req) { 198 if (req) {
199 sk_acceptq_removed(parent); 199 sk_acceptq_removed(parent);
200 queue->rskq_accept_head = req->dl_next; 200 WRITE_ONCE(queue->rskq_accept_head, req->dl_next);
201 if (queue->rskq_accept_head == NULL) 201 if (queue->rskq_accept_head == NULL)
202 queue->rskq_accept_tail = NULL; 202 queue->rskq_accept_tail = NULL;
203 } 203 }
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index 5d60f13d2347..3ab5c6bbb90b 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -610,4 +610,9 @@ static inline __u32 sctp_min_frag_point(struct sctp_sock *sp, __u16 datasize)
610 return sctp_mtu_payload(sp, SCTP_DEFAULT_MINSEGMENT, datasize); 610 return sctp_mtu_payload(sp, SCTP_DEFAULT_MINSEGMENT, datasize);
611} 611}
612 612
613static inline bool sctp_newsk_ready(const struct sock *sk)
614{
615 return sock_flag(sk, SOCK_DEAD) || sk->sk_socket;
616}
617
613#endif /* __net_sctp_h__ */ 618#endif /* __net_sctp_h__ */
diff --git a/include/net/sock.h b/include/net/sock.h
index 2c53f1a1d905..8f9adcfac41b 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -878,12 +878,17 @@ static inline bool sk_acceptq_is_full(const struct sock *sk)
878 */ 878 */
879static inline int sk_stream_min_wspace(const struct sock *sk) 879static inline int sk_stream_min_wspace(const struct sock *sk)
880{ 880{
881 return sk->sk_wmem_queued >> 1; 881 return READ_ONCE(sk->sk_wmem_queued) >> 1;
882} 882}
883 883
884static inline int sk_stream_wspace(const struct sock *sk) 884static inline int sk_stream_wspace(const struct sock *sk)
885{ 885{
886 return sk->sk_sndbuf - sk->sk_wmem_queued; 886 return READ_ONCE(sk->sk_sndbuf) - READ_ONCE(sk->sk_wmem_queued);
887}
888
889static inline void sk_wmem_queued_add(struct sock *sk, int val)
890{
891 WRITE_ONCE(sk->sk_wmem_queued, sk->sk_wmem_queued + val);
887} 892}
888 893
889void sk_stream_write_space(struct sock *sk); 894void sk_stream_write_space(struct sock *sk);
@@ -949,8 +954,8 @@ static inline void sk_incoming_cpu_update(struct sock *sk)
949{ 954{
950 int cpu = raw_smp_processor_id(); 955 int cpu = raw_smp_processor_id();
951 956
952 if (unlikely(sk->sk_incoming_cpu != cpu)) 957 if (unlikely(READ_ONCE(sk->sk_incoming_cpu) != cpu))
953 sk->sk_incoming_cpu = cpu; 958 WRITE_ONCE(sk->sk_incoming_cpu, cpu);
954} 959}
955 960
956static inline void sock_rps_record_flow_hash(__u32 hash) 961static inline void sock_rps_record_flow_hash(__u32 hash)
@@ -1207,7 +1212,7 @@ static inline void sk_refcnt_debug_release(const struct sock *sk)
1207 1212
1208static inline bool __sk_stream_memory_free(const struct sock *sk, int wake) 1213static inline bool __sk_stream_memory_free(const struct sock *sk, int wake)
1209{ 1214{
1210 if (sk->sk_wmem_queued >= sk->sk_sndbuf) 1215 if (READ_ONCE(sk->sk_wmem_queued) >= READ_ONCE(sk->sk_sndbuf))
1211 return false; 1216 return false;
1212 1217
1213 return sk->sk_prot->stream_memory_free ? 1218 return sk->sk_prot->stream_memory_free ?
@@ -1467,7 +1472,7 @@ DECLARE_STATIC_KEY_FALSE(tcp_tx_skb_cache_key);
1467static inline void sk_wmem_free_skb(struct sock *sk, struct sk_buff *skb) 1472static inline void sk_wmem_free_skb(struct sock *sk, struct sk_buff *skb)
1468{ 1473{
1469 sock_set_flag(sk, SOCK_QUEUE_SHRUNK); 1474 sock_set_flag(sk, SOCK_QUEUE_SHRUNK);
1470 sk->sk_wmem_queued -= skb->truesize; 1475 sk_wmem_queued_add(sk, -skb->truesize);
1471 sk_mem_uncharge(sk, skb->truesize); 1476 sk_mem_uncharge(sk, skb->truesize);
1472 if (static_branch_unlikely(&tcp_tx_skb_cache_key) && 1477 if (static_branch_unlikely(&tcp_tx_skb_cache_key) &&
1473 !sk->sk_tx_skb_cache && !skb_cloned(skb)) { 1478 !sk->sk_tx_skb_cache && !skb_cloned(skb)) {
@@ -2014,7 +2019,7 @@ static inline int skb_copy_to_page_nocache(struct sock *sk, struct iov_iter *fro
2014 skb->len += copy; 2019 skb->len += copy;
2015 skb->data_len += copy; 2020 skb->data_len += copy;
2016 skb->truesize += copy; 2021 skb->truesize += copy;
2017 sk->sk_wmem_queued += copy; 2022 sk_wmem_queued_add(sk, copy);
2018 sk_mem_charge(sk, copy); 2023 sk_mem_charge(sk, copy);
2019 return 0; 2024 return 0;
2020} 2025}
@@ -2220,10 +2225,14 @@ static inline void sk_wake_async(const struct sock *sk, int how, int band)
2220 2225
2221static inline void sk_stream_moderate_sndbuf(struct sock *sk) 2226static inline void sk_stream_moderate_sndbuf(struct sock *sk)
2222{ 2227{
2223 if (!(sk->sk_userlocks & SOCK_SNDBUF_LOCK)) { 2228 u32 val;
2224 sk->sk_sndbuf = min(sk->sk_sndbuf, sk->sk_wmem_queued >> 1); 2229
2225 sk->sk_sndbuf = max_t(u32, sk->sk_sndbuf, SOCK_MIN_SNDBUF); 2230 if (sk->sk_userlocks & SOCK_SNDBUF_LOCK)
2226 } 2231 return;
2232
2233 val = min(sk->sk_sndbuf, sk->sk_wmem_queued >> 1);
2234
2235 WRITE_ONCE(sk->sk_sndbuf, max_t(u32, val, SOCK_MIN_SNDBUF));
2227} 2236}
2228 2237
2229struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp, 2238struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp,
@@ -2233,12 +2242,17 @@ struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp,
2233 * sk_page_frag - return an appropriate page_frag 2242 * sk_page_frag - return an appropriate page_frag
2234 * @sk: socket 2243 * @sk: socket
2235 * 2244 *
2236 * If socket allocation mode allows current thread to sleep, it means its 2245 * Use the per task page_frag instead of the per socket one for
2237 * safe to use the per task page_frag instead of the per socket one. 2246 * optimization when we know that we're in the normal context and owns
2247 * everything that's associated with %current.
2248 *
2249 * gfpflags_allow_blocking() isn't enough here as direct reclaim may nest
2250 * inside other socket operations and end up recursing into sk_page_frag()
2251 * while it's already in use.
2238 */ 2252 */
2239static inline struct page_frag *sk_page_frag(struct sock *sk) 2253static inline struct page_frag *sk_page_frag(struct sock *sk)
2240{ 2254{
2241 if (gfpflags_allow_blocking(sk->sk_allocation)) 2255 if (gfpflags_normal_context(sk->sk_allocation))
2242 return &current->task_frag; 2256 return &current->task_frag;
2243 2257
2244 return &sk->sk_frag; 2258 return &sk->sk_frag;
@@ -2251,7 +2265,7 @@ bool sk_page_frag_refill(struct sock *sk, struct page_frag *pfrag);
2251 */ 2265 */
2252static inline bool sock_writeable(const struct sock *sk) 2266static inline bool sock_writeable(const struct sock *sk)
2253{ 2267{
2254 return refcount_read(&sk->sk_wmem_alloc) < (sk->sk_sndbuf >> 1); 2268 return refcount_read(&sk->sk_wmem_alloc) < (READ_ONCE(sk->sk_sndbuf) >> 1);
2255} 2269}
2256 2270
2257static inline gfp_t gfp_any(void) 2271static inline gfp_t gfp_any(void)
@@ -2271,7 +2285,9 @@ static inline long sock_sndtimeo(const struct sock *sk, bool noblock)
2271 2285
2272static inline int sock_rcvlowat(const struct sock *sk, int waitall, int len) 2286static inline int sock_rcvlowat(const struct sock *sk, int waitall, int len)
2273{ 2287{
2274 return (waitall ? len : min_t(int, sk->sk_rcvlowat, len)) ? : 1; 2288 int v = waitall ? len : min_t(int, READ_ONCE(sk->sk_rcvlowat), len);
2289
2290 return v ?: 1;
2275} 2291}
2276 2292
2277/* Alas, with timeout socket operations are not restartable. 2293/* Alas, with timeout socket operations are not restartable.
diff --git a/include/net/tcp.h b/include/net/tcp.h
index c9a3f9688223..ab4eb5eb5d07 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -258,7 +258,7 @@ static inline bool tcp_under_memory_pressure(const struct sock *sk)
258 mem_cgroup_under_socket_pressure(sk->sk_memcg)) 258 mem_cgroup_under_socket_pressure(sk->sk_memcg))
259 return true; 259 return true;
260 260
261 return tcp_memory_pressure; 261 return READ_ONCE(tcp_memory_pressure);
262} 262}
263/* 263/*
264 * The next routines deal with comparing 32 bit unsigned ints 264 * The next routines deal with comparing 32 bit unsigned ints
@@ -1380,13 +1380,14 @@ static inline int tcp_win_from_space(const struct sock *sk, int space)
1380/* Note: caller must be prepared to deal with negative returns */ 1380/* Note: caller must be prepared to deal with negative returns */
1381static inline int tcp_space(const struct sock *sk) 1381static inline int tcp_space(const struct sock *sk)
1382{ 1382{
1383 return tcp_win_from_space(sk, sk->sk_rcvbuf - sk->sk_backlog.len - 1383 return tcp_win_from_space(sk, READ_ONCE(sk->sk_rcvbuf) -
1384 READ_ONCE(sk->sk_backlog.len) -
1384 atomic_read(&sk->sk_rmem_alloc)); 1385 atomic_read(&sk->sk_rmem_alloc));
1385} 1386}
1386 1387
1387static inline int tcp_full_space(const struct sock *sk) 1388static inline int tcp_full_space(const struct sock *sk)
1388{ 1389{
1389 return tcp_win_from_space(sk, sk->sk_rcvbuf); 1390 return tcp_win_from_space(sk, READ_ONCE(sk->sk_rcvbuf));
1390} 1391}
1391 1392
1392extern void tcp_openreq_init_rwin(struct request_sock *req, 1393extern void tcp_openreq_init_rwin(struct request_sock *req,
@@ -1916,7 +1917,8 @@ static inline u32 tcp_notsent_lowat(const struct tcp_sock *tp)
1916static inline bool tcp_stream_memory_free(const struct sock *sk, int wake) 1917static inline bool tcp_stream_memory_free(const struct sock *sk, int wake)
1917{ 1918{
1918 const struct tcp_sock *tp = tcp_sk(sk); 1919 const struct tcp_sock *tp = tcp_sk(sk);
1919 u32 notsent_bytes = tp->write_seq - tp->snd_nxt; 1920 u32 notsent_bytes = READ_ONCE(tp->write_seq) -
1921 READ_ONCE(tp->snd_nxt);
1920 1922
1921 return (notsent_bytes << wake) < tcp_notsent_lowat(tp); 1923 return (notsent_bytes << wake) < tcp_notsent_lowat(tp);
1922} 1924}
diff --git a/include/net/vxlan.h b/include/net/vxlan.h
index 335283dbe9b3..373aadcfea21 100644
--- a/include/net/vxlan.h
+++ b/include/net/vxlan.h
@@ -197,6 +197,7 @@ struct vxlan_rdst {
197 u8 offloaded:1; 197 u8 offloaded:1;
198 __be32 remote_vni; 198 __be32 remote_vni;
199 u32 remote_ifindex; 199 u32 remote_ifindex;
200 struct net_device *remote_dev;
200 struct list_head list; 201 struct list_head list;
201 struct rcu_head rcu; 202 struct rcu_head rcu;
202 struct dst_cache dst_cache; 203 struct dst_cache dst_cache;
diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h
index 3810b340551c..6bd5ed695a5e 100644
--- a/include/scsi/scsi_eh.h
+++ b/include/scsi/scsi_eh.h
@@ -32,6 +32,7 @@ extern int scsi_ioctl_reset(struct scsi_device *, int __user *);
32struct scsi_eh_save { 32struct scsi_eh_save {
33 /* saved state */ 33 /* saved state */
34 int result; 34 int result;
35 unsigned int resid_len;
35 int eh_eflags; 36 int eh_eflags;
36 enum dma_data_direction data_direction; 37 enum dma_data_direction data_direction;
37 unsigned underflow; 38 unsigned underflow;
diff --git a/include/sound/hda_register.h b/include/sound/hda_register.h
index 0fd39295b426..057d2a2d0bd0 100644
--- a/include/sound/hda_register.h
+++ b/include/sound/hda_register.h
@@ -264,6 +264,9 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
264#define AZX_REG_ML_LOUTPAY 0x20 264#define AZX_REG_ML_LOUTPAY 0x20
265#define AZX_REG_ML_LINPAY 0x30 265#define AZX_REG_ML_LINPAY 0x30
266 266
267/* bit0 is reserved, with BIT(1) mapping to stream1 */
268#define ML_LOSIDV_STREAM_MASK 0xFFFE
269
267#define ML_LCTL_SCF_MASK 0xF 270#define ML_LCTL_SCF_MASK 0xF
268#define AZX_MLCTL_SPA (0x1 << 16) 271#define AZX_MLCTL_SPA (0x1 << 16)
269#define AZX_MLCTL_CPA (0x1 << 23) 272#define AZX_MLCTL_CPA (0x1 << 23)
diff --git a/include/trace/events/rxrpc.h b/include/trace/events/rxrpc.h
index a13a62db3565..191fe447f990 100644
--- a/include/trace/events/rxrpc.h
+++ b/include/trace/events/rxrpc.h
@@ -519,10 +519,10 @@ TRACE_EVENT(rxrpc_local,
519 ); 519 );
520 520
521TRACE_EVENT(rxrpc_peer, 521TRACE_EVENT(rxrpc_peer,
522 TP_PROTO(struct rxrpc_peer *peer, enum rxrpc_peer_trace op, 522 TP_PROTO(unsigned int peer_debug_id, enum rxrpc_peer_trace op,
523 int usage, const void *where), 523 int usage, const void *where),
524 524
525 TP_ARGS(peer, op, usage, where), 525 TP_ARGS(peer_debug_id, op, usage, where),
526 526
527 TP_STRUCT__entry( 527 TP_STRUCT__entry(
528 __field(unsigned int, peer ) 528 __field(unsigned int, peer )
@@ -532,7 +532,7 @@ TRACE_EVENT(rxrpc_peer,
532 ), 532 ),
533 533
534 TP_fast_assign( 534 TP_fast_assign(
535 __entry->peer = peer->debug_id; 535 __entry->peer = peer_debug_id;
536 __entry->op = op; 536 __entry->op = op;
537 __entry->usage = usage; 537 __entry->usage = usage;
538 __entry->where = where; 538 __entry->where = where;
@@ -546,10 +546,10 @@ TRACE_EVENT(rxrpc_peer,
546 ); 546 );
547 547
548TRACE_EVENT(rxrpc_conn, 548TRACE_EVENT(rxrpc_conn,
549 TP_PROTO(struct rxrpc_connection *conn, enum rxrpc_conn_trace op, 549 TP_PROTO(unsigned int conn_debug_id, enum rxrpc_conn_trace op,
550 int usage, const void *where), 550 int usage, const void *where),
551 551
552 TP_ARGS(conn, op, usage, where), 552 TP_ARGS(conn_debug_id, op, usage, where),
553 553
554 TP_STRUCT__entry( 554 TP_STRUCT__entry(
555 __field(unsigned int, conn ) 555 __field(unsigned int, conn )
@@ -559,7 +559,7 @@ TRACE_EVENT(rxrpc_conn,
559 ), 559 ),
560 560
561 TP_fast_assign( 561 TP_fast_assign(
562 __entry->conn = conn->debug_id; 562 __entry->conn = conn_debug_id;
563 __entry->op = op; 563 __entry->op = op;
564 __entry->usage = usage; 564 __entry->usage = usage;
565 __entry->where = where; 565 __entry->where = where;
@@ -606,10 +606,10 @@ TRACE_EVENT(rxrpc_client,
606 ); 606 );
607 607
608TRACE_EVENT(rxrpc_call, 608TRACE_EVENT(rxrpc_call,
609 TP_PROTO(struct rxrpc_call *call, enum rxrpc_call_trace op, 609 TP_PROTO(unsigned int call_debug_id, enum rxrpc_call_trace op,
610 int usage, const void *where, const void *aux), 610 int usage, const void *where, const void *aux),
611 611
612 TP_ARGS(call, op, usage, where, aux), 612 TP_ARGS(call_debug_id, op, usage, where, aux),
613 613
614 TP_STRUCT__entry( 614 TP_STRUCT__entry(
615 __field(unsigned int, call ) 615 __field(unsigned int, call )
@@ -620,7 +620,7 @@ TRACE_EVENT(rxrpc_call,
620 ), 620 ),
621 621
622 TP_fast_assign( 622 TP_fast_assign(
623 __entry->call = call->debug_id; 623 __entry->call = call_debug_id;
624 __entry->op = op; 624 __entry->op = op;
625 __entry->usage = usage; 625 __entry->usage = usage;
626 __entry->where = where; 626 __entry->where = where;
@@ -1068,7 +1068,7 @@ TRACE_EVENT(rxrpc_recvmsg,
1068 ), 1068 ),
1069 1069
1070 TP_fast_assign( 1070 TP_fast_assign(
1071 __entry->call = call->debug_id; 1071 __entry->call = call ? call->debug_id : 0;
1072 __entry->why = why; 1072 __entry->why = why;
1073 __entry->seq = seq; 1073 __entry->seq = seq;
1074 __entry->offset = offset; 1074 __entry->offset = offset;
diff --git a/include/trace/events/sock.h b/include/trace/events/sock.h
index a0c4b8a30966..51fe9f6719eb 100644
--- a/include/trace/events/sock.h
+++ b/include/trace/events/sock.h
@@ -82,7 +82,7 @@ TRACE_EVENT(sock_rcvqueue_full,
82 TP_fast_assign( 82 TP_fast_assign(
83 __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc); 83 __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc);
84 __entry->truesize = skb->truesize; 84 __entry->truesize = skb->truesize;
85 __entry->sk_rcvbuf = sk->sk_rcvbuf; 85 __entry->sk_rcvbuf = READ_ONCE(sk->sk_rcvbuf);
86 ), 86 ),
87 87
88 TP_printk("rmem_alloc=%d truesize=%u sk_rcvbuf=%d", 88 TP_printk("rmem_alloc=%d truesize=%u sk_rcvbuf=%d",
@@ -115,7 +115,7 @@ TRACE_EVENT(sock_exceed_buf_limit,
115 __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc); 115 __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc);
116 __entry->sysctl_wmem = sk_get_wmem0(sk, prot); 116 __entry->sysctl_wmem = sk_get_wmem0(sk, prot);
117 __entry->wmem_alloc = refcount_read(&sk->sk_wmem_alloc); 117 __entry->wmem_alloc = refcount_read(&sk->sk_wmem_alloc);
118 __entry->wmem_queued = sk->sk_wmem_queued; 118 __entry->wmem_queued = READ_ONCE(sk->sk_wmem_queued);
119 __entry->kind = kind; 119 __entry->kind = kind;
120 ), 120 ),
121 121
diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index c99b4f2482c6..4fe35d600ab8 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -1003,6 +1003,8 @@ struct drm_amdgpu_info_device {
1003 __u64 high_va_max; 1003 __u64 high_va_max;
1004 /* gfx10 pa_sc_tile_steering_override */ 1004 /* gfx10 pa_sc_tile_steering_override */
1005 __u32 pa_sc_tile_steering_override; 1005 __u32 pa_sc_tile_steering_override;
1006 /* disabled TCCs */
1007 __u64 tcc_disabled_mask;
1006}; 1008};
1007 1009
1008struct drm_amdgpu_info_hw_ip { 1010struct drm_amdgpu_info_hw_ip {
diff --git a/include/uapi/linux/nvme_ioctl.h b/include/uapi/linux/nvme_ioctl.h
index 1c215ea1798e..e168dc59e9a0 100644
--- a/include/uapi/linux/nvme_ioctl.h
+++ b/include/uapi/linux/nvme_ioctl.h
@@ -45,6 +45,27 @@ struct nvme_passthru_cmd {
45 __u32 result; 45 __u32 result;
46}; 46};
47 47
48struct nvme_passthru_cmd64 {
49 __u8 opcode;
50 __u8 flags;
51 __u16 rsvd1;
52 __u32 nsid;
53 __u32 cdw2;
54 __u32 cdw3;
55 __u64 metadata;
56 __u64 addr;
57 __u32 metadata_len;
58 __u32 data_len;
59 __u32 cdw10;
60 __u32 cdw11;
61 __u32 cdw12;
62 __u32 cdw13;
63 __u32 cdw14;
64 __u32 cdw15;
65 __u32 timeout_ms;
66 __u64 result;
67};
68
48#define nvme_admin_cmd nvme_passthru_cmd 69#define nvme_admin_cmd nvme_passthru_cmd
49 70
50#define NVME_IOCTL_ID _IO('N', 0x40) 71#define NVME_IOCTL_ID _IO('N', 0x40)
@@ -54,5 +75,7 @@ struct nvme_passthru_cmd {
54#define NVME_IOCTL_RESET _IO('N', 0x44) 75#define NVME_IOCTL_RESET _IO('N', 0x44)
55#define NVME_IOCTL_SUBSYS_RESET _IO('N', 0x45) 76#define NVME_IOCTL_SUBSYS_RESET _IO('N', 0x45)
56#define NVME_IOCTL_RESCAN _IO('N', 0x46) 77#define NVME_IOCTL_RESCAN _IO('N', 0x46)
78#define NVME_IOCTL_ADMIN64_CMD _IOWR('N', 0x47, struct nvme_passthru_cmd64)
79#define NVME_IOCTL_IO64_CMD _IOWR('N', 0x48, struct nvme_passthru_cmd64)
57 80
58#endif /* _UAPI_LINUX_NVME_IOCTL_H */ 81#endif /* _UAPI_LINUX_NVME_IOCTL_H */
diff --git a/include/uapi/linux/pg.h b/include/uapi/linux/pg.h
index 364c350e85cd..62b6f69bd9fb 100644
--- a/include/uapi/linux/pg.h
+++ b/include/uapi/linux/pg.h
@@ -35,6 +35,9 @@
35 35
36*/ 36*/
37 37
38#ifndef _UAPI_LINUX_PG_H
39#define _UAPI_LINUX_PG_H
40
38#define PG_MAGIC 'P' 41#define PG_MAGIC 'P'
39#define PG_RESET 'Z' 42#define PG_RESET 'Z'
40#define PG_COMMAND 'C' 43#define PG_COMMAND 'C'
@@ -61,4 +64,4 @@ struct pg_read_hdr {
61 64
62}; 65};
63 66
64/* end of pg.h */ 67#endif /* _UAPI_LINUX_PG_H */
diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h
index b3105ac1381a..99335e1f4a27 100644
--- a/include/uapi/linux/sched.h
+++ b/include/uapi/linux/sched.h
@@ -33,8 +33,31 @@
33#define CLONE_NEWNET 0x40000000 /* New network namespace */ 33#define CLONE_NEWNET 0x40000000 /* New network namespace */
34#define CLONE_IO 0x80000000 /* Clone io context */ 34#define CLONE_IO 0x80000000 /* Clone io context */
35 35
36/* 36#ifndef __ASSEMBLY__
37 * Arguments for the clone3 syscall 37/**
38 * struct clone_args - arguments for the clone3 syscall
39 * @flags: Flags for the new process as listed above.
40 * All flags are valid except for CSIGNAL and
41 * CLONE_DETACHED.
42 * @pidfd: If CLONE_PIDFD is set, a pidfd will be
43 * returned in this argument.
44 * @child_tid: If CLONE_CHILD_SETTID is set, the TID of the
45 * child process will be returned in the child's
46 * memory.
47 * @parent_tid: If CLONE_PARENT_SETTID is set, the TID of
48 * the child process will be returned in the
49 * parent's memory.
50 * @exit_signal: The exit_signal the parent process will be
51 * sent when the child exits.
52 * @stack: Specify the location of the stack for the
53 * child process.
54 * @stack_size: The size of the stack for the child process.
55 * @tls: If CLONE_SETTLS is set, the tls descriptor
56 * is set to tls.
57 *
58 * The structure is versioned by size and thus extensible.
59 * New struct members must go at the end of the struct and
60 * must be properly 64bit aligned.
38 */ 61 */
39struct clone_args { 62struct clone_args {
40 __aligned_u64 flags; 63 __aligned_u64 flags;
@@ -46,6 +69,9 @@ struct clone_args {
46 __aligned_u64 stack_size; 69 __aligned_u64 stack_size;
47 __aligned_u64 tls; 70 __aligned_u64 tls;
48}; 71};
72#endif
73
74#define CLONE_ARGS_SIZE_VER0 64 /* sizeof first published struct */
49 75
50/* 76/*
51 * Scheduling policies 77 * Scheduling policies
diff --git a/include/uapi/linux/serial_core.h b/include/uapi/linux/serial_core.h
index 0f4f87a6fd54..e7fe550b6038 100644
--- a/include/uapi/linux/serial_core.h
+++ b/include/uapi/linux/serial_core.h
@@ -291,6 +291,6 @@
291#define PORT_SUNIX 121 291#define PORT_SUNIX 121
292 292
293/* Freescale Linflex UART */ 293/* Freescale Linflex UART */
294#define PORT_LINFLEXUART 121 294#define PORT_LINFLEXUART 122
295 295
296#endif /* _UAPILINUX_SERIAL_CORE_H */ 296#endif /* _UAPILINUX_SERIAL_CORE_H */
diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h
index 98b30c1613b2..d89969aa9942 100644
--- a/include/xen/xen-ops.h
+++ b/include/xen/xen-ops.h
@@ -212,30 +212,7 @@ int xen_xlate_map_ballooned_pages(xen_pfn_t **pfns, void **vaddr,
212 212
213bool xen_running_on_version_or_later(unsigned int major, unsigned int minor); 213bool xen_running_on_version_or_later(unsigned int major, unsigned int minor);
214 214
215efi_status_t xen_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc); 215void xen_efi_runtime_setup(void);
216efi_status_t xen_efi_set_time(efi_time_t *tm);
217efi_status_t xen_efi_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending,
218 efi_time_t *tm);
219efi_status_t xen_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm);
220efi_status_t xen_efi_get_variable(efi_char16_t *name, efi_guid_t *vendor,
221 u32 *attr, unsigned long *data_size,
222 void *data);
223efi_status_t xen_efi_get_next_variable(unsigned long *name_size,
224 efi_char16_t *name, efi_guid_t *vendor);
225efi_status_t xen_efi_set_variable(efi_char16_t *name, efi_guid_t *vendor,
226 u32 attr, unsigned long data_size,
227 void *data);
228efi_status_t xen_efi_query_variable_info(u32 attr, u64 *storage_space,
229 u64 *remaining_space,
230 u64 *max_variable_size);
231efi_status_t xen_efi_get_next_high_mono_count(u32 *count);
232efi_status_t xen_efi_update_capsule(efi_capsule_header_t **capsules,
233 unsigned long count, unsigned long sg_list);
234efi_status_t xen_efi_query_capsule_caps(efi_capsule_header_t **capsules,
235 unsigned long count, u64 *max_size,
236 int *reset_type);
237void xen_efi_reset_system(int reset_type, efi_status_t status,
238 unsigned long data_size, efi_char16_t *data);
239 216
240 217
241#ifdef CONFIG_PREEMPT 218#ifdef CONFIG_PREEMPT
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 66088a9e9b9e..ef0e1e3e66f4 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -502,7 +502,7 @@ int bpf_remove_insns(struct bpf_prog *prog, u32 off, u32 cnt)
502 return WARN_ON_ONCE(bpf_adj_branches(prog, off, off + cnt, off, false)); 502 return WARN_ON_ONCE(bpf_adj_branches(prog, off, off + cnt, off, false));
503} 503}
504 504
505void bpf_prog_kallsyms_del_subprogs(struct bpf_prog *fp) 505static void bpf_prog_kallsyms_del_subprogs(struct bpf_prog *fp)
506{ 506{
507 int i; 507 int i;
508 508
diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index d27f3b60ff6d..3867864cdc2f 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -128,7 +128,7 @@ static int dev_map_init_map(struct bpf_dtab *dtab, union bpf_attr *attr)
128 128
129 if (!dtab->n_buckets) /* Overflow check */ 129 if (!dtab->n_buckets) /* Overflow check */
130 return -EINVAL; 130 return -EINVAL;
131 cost += sizeof(struct hlist_head) * dtab->n_buckets; 131 cost += (u64) sizeof(struct hlist_head) * dtab->n_buckets;
132 } 132 }
133 133
134 /* if map size is larger than memlock limit, reject it */ 134 /* if map size is larger than memlock limit, reject it */
@@ -719,6 +719,32 @@ const struct bpf_map_ops dev_map_hash_ops = {
719 .map_check_btf = map_check_no_btf, 719 .map_check_btf = map_check_no_btf,
720}; 720};
721 721
722static void dev_map_hash_remove_netdev(struct bpf_dtab *dtab,
723 struct net_device *netdev)
724{
725 unsigned long flags;
726 u32 i;
727
728 spin_lock_irqsave(&dtab->index_lock, flags);
729 for (i = 0; i < dtab->n_buckets; i++) {
730 struct bpf_dtab_netdev *dev;
731 struct hlist_head *head;
732 struct hlist_node *next;
733
734 head = dev_map_index_hash(dtab, i);
735
736 hlist_for_each_entry_safe(dev, next, head, index_hlist) {
737 if (netdev != dev->dev)
738 continue;
739
740 dtab->items--;
741 hlist_del_rcu(&dev->index_hlist);
742 call_rcu(&dev->rcu, __dev_map_entry_free);
743 }
744 }
745 spin_unlock_irqrestore(&dtab->index_lock, flags);
746}
747
722static int dev_map_notification(struct notifier_block *notifier, 748static int dev_map_notification(struct notifier_block *notifier,
723 ulong event, void *ptr) 749 ulong event, void *ptr)
724{ 750{
@@ -735,6 +761,11 @@ static int dev_map_notification(struct notifier_block *notifier,
735 */ 761 */
736 rcu_read_lock(); 762 rcu_read_lock();
737 list_for_each_entry_rcu(dtab, &dev_map_list, list) { 763 list_for_each_entry_rcu(dtab, &dev_map_list, list) {
764 if (dtab->map.map_type == BPF_MAP_TYPE_DEVMAP_HASH) {
765 dev_map_hash_remove_netdev(dtab, netdev);
766 continue;
767 }
768
738 for (i = 0; i < dtab->map.max_entries; i++) { 769 for (i = 0; i < dtab->map.max_entries; i++) {
739 struct bpf_dtab_netdev *dev, *odev; 770 struct bpf_dtab_netdev *dev, *odev;
740 771
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 82eabd4e38ad..0937719b87e2 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -1326,24 +1326,32 @@ static void __bpf_prog_put_rcu(struct rcu_head *rcu)
1326{ 1326{
1327 struct bpf_prog_aux *aux = container_of(rcu, struct bpf_prog_aux, rcu); 1327 struct bpf_prog_aux *aux = container_of(rcu, struct bpf_prog_aux, rcu);
1328 1328
1329 kvfree(aux->func_info);
1329 free_used_maps(aux); 1330 free_used_maps(aux);
1330 bpf_prog_uncharge_memlock(aux->prog); 1331 bpf_prog_uncharge_memlock(aux->prog);
1331 security_bpf_prog_free(aux); 1332 security_bpf_prog_free(aux);
1332 bpf_prog_free(aux->prog); 1333 bpf_prog_free(aux->prog);
1333} 1334}
1334 1335
1336static void __bpf_prog_put_noref(struct bpf_prog *prog, bool deferred)
1337{
1338 bpf_prog_kallsyms_del_all(prog);
1339 btf_put(prog->aux->btf);
1340 bpf_prog_free_linfo(prog);
1341
1342 if (deferred)
1343 call_rcu(&prog->aux->rcu, __bpf_prog_put_rcu);
1344 else
1345 __bpf_prog_put_rcu(&prog->aux->rcu);
1346}
1347
1335static void __bpf_prog_put(struct bpf_prog *prog, bool do_idr_lock) 1348static void __bpf_prog_put(struct bpf_prog *prog, bool do_idr_lock)
1336{ 1349{
1337 if (atomic_dec_and_test(&prog->aux->refcnt)) { 1350 if (atomic_dec_and_test(&prog->aux->refcnt)) {
1338 perf_event_bpf_event(prog, PERF_BPF_EVENT_PROG_UNLOAD, 0); 1351 perf_event_bpf_event(prog, PERF_BPF_EVENT_PROG_UNLOAD, 0);
1339 /* bpf_prog_free_id() must be called first */ 1352 /* bpf_prog_free_id() must be called first */
1340 bpf_prog_free_id(prog, do_idr_lock); 1353 bpf_prog_free_id(prog, do_idr_lock);
1341 bpf_prog_kallsyms_del_all(prog); 1354 __bpf_prog_put_noref(prog, true);
1342 btf_put(prog->aux->btf);
1343 kvfree(prog->aux->func_info);
1344 bpf_prog_free_linfo(prog);
1345
1346 call_rcu(&prog->aux->rcu, __bpf_prog_put_rcu);
1347 } 1355 }
1348} 1356}
1349 1357
@@ -1741,11 +1749,12 @@ static int bpf_prog_load(union bpf_attr *attr, union bpf_attr __user *uattr)
1741 return err; 1749 return err;
1742 1750
1743free_used_maps: 1751free_used_maps:
1744 bpf_prog_free_linfo(prog); 1752 /* In case we have subprogs, we need to wait for a grace
1745 kvfree(prog->aux->func_info); 1753 * period before we can tear down JIT memory since symbols
1746 btf_put(prog->aux->btf); 1754 * are already exposed under kallsyms.
1747 bpf_prog_kallsyms_del_subprogs(prog); 1755 */
1748 free_used_maps(prog->aux); 1756 __bpf_prog_put_noref(prog, prog->aux->func_cnt);
1757 return err;
1749free_prog: 1758free_prog:
1750 bpf_prog_uncharge_memlock(prog); 1759 bpf_prog_uncharge_memlock(prog);
1751free_prog_sec: 1760free_prog_sec:
diff --git a/kernel/dma/remap.c b/kernel/dma/remap.c
index ca4e5d44b571..c00b9258fa6a 100644
--- a/kernel/dma/remap.c
+++ b/kernel/dma/remap.c
@@ -87,9 +87,9 @@ void *dma_common_contiguous_remap(struct page *page, size_t size,
87 */ 87 */
88void dma_common_free_remap(void *cpu_addr, size_t size) 88void dma_common_free_remap(void *cpu_addr, size_t size)
89{ 89{
90 struct page **pages = dma_common_find_pages(cpu_addr); 90 struct vm_struct *area = find_vm_area(cpu_addr);
91 91
92 if (!pages) { 92 if (!area || area->flags != VM_DMA_COHERENT) {
93 WARN(1, "trying to free invalid coherent area: %p\n", cpu_addr); 93 WARN(1, "trying to free invalid coherent area: %p\n", cpu_addr);
94 return; 94 return;
95 } 95 }
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4655adbbae10..9ec0b0bfddbd 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3779,11 +3779,23 @@ static void rotate_ctx(struct perf_event_context *ctx, struct perf_event *event)
3779 perf_event_groups_insert(&ctx->flexible_groups, event); 3779 perf_event_groups_insert(&ctx->flexible_groups, event);
3780} 3780}
3781 3781
3782/* pick an event from the flexible_groups to rotate */
3782static inline struct perf_event * 3783static inline struct perf_event *
3783ctx_first_active(struct perf_event_context *ctx) 3784ctx_event_to_rotate(struct perf_event_context *ctx)
3784{ 3785{
3785 return list_first_entry_or_null(&ctx->flexible_active, 3786 struct perf_event *event;
3786 struct perf_event, active_list); 3787
3788 /* pick the first active flexible event */
3789 event = list_first_entry_or_null(&ctx->flexible_active,
3790 struct perf_event, active_list);
3791
3792 /* if no active flexible event, pick the first event */
3793 if (!event) {
3794 event = rb_entry_safe(rb_first(&ctx->flexible_groups.tree),
3795 typeof(*event), group_node);
3796 }
3797
3798 return event;
3787} 3799}
3788 3800
3789static bool perf_rotate_context(struct perf_cpu_context *cpuctx) 3801static bool perf_rotate_context(struct perf_cpu_context *cpuctx)
@@ -3808,9 +3820,9 @@ static bool perf_rotate_context(struct perf_cpu_context *cpuctx)
3808 perf_pmu_disable(cpuctx->ctx.pmu); 3820 perf_pmu_disable(cpuctx->ctx.pmu);
3809 3821
3810 if (task_rotate) 3822 if (task_rotate)
3811 task_event = ctx_first_active(task_ctx); 3823 task_event = ctx_event_to_rotate(task_ctx);
3812 if (cpu_rotate) 3824 if (cpu_rotate)
3813 cpu_event = ctx_first_active(&cpuctx->ctx); 3825 cpu_event = ctx_event_to_rotate(&cpuctx->ctx);
3814 3826
3815 /* 3827 /*
3816 * As per the order given at ctx_resched() first 'pop' task flexible 3828 * As per the order given at ctx_resched() first 'pop' task flexible
@@ -5668,7 +5680,8 @@ again:
5668 * undo the VM accounting. 5680 * undo the VM accounting.
5669 */ 5681 */
5670 5682
5671 atomic_long_sub((size >> PAGE_SHIFT) + 1, &mmap_user->locked_vm); 5683 atomic_long_sub((size >> PAGE_SHIFT) + 1 - mmap_locked,
5684 &mmap_user->locked_vm);
5672 atomic64_sub(mmap_locked, &vma->vm_mm->pinned_vm); 5685 atomic64_sub(mmap_locked, &vma->vm_mm->pinned_vm);
5673 free_uid(mmap_user); 5686 free_uid(mmap_user);
5674 5687
@@ -5812,8 +5825,20 @@ accounting:
5812 5825
5813 user_locked = atomic_long_read(&user->locked_vm) + user_extra; 5826 user_locked = atomic_long_read(&user->locked_vm) + user_extra;
5814 5827
5815 if (user_locked > user_lock_limit) 5828 if (user_locked <= user_lock_limit) {
5829 /* charge all to locked_vm */
5830 } else if (atomic_long_read(&user->locked_vm) >= user_lock_limit) {
5831 /* charge all to pinned_vm */
5832 extra = user_extra;
5833 user_extra = 0;
5834 } else {
5835 /*
5836 * charge locked_vm until it hits user_lock_limit;
5837 * charge the rest from pinned_vm
5838 */
5816 extra = user_locked - user_lock_limit; 5839 extra = user_locked - user_lock_limit;
5840 user_extra -= extra;
5841 }
5817 5842
5818 lock_limit = rlimit(RLIMIT_MEMLOCK); 5843 lock_limit = rlimit(RLIMIT_MEMLOCK);
5819 lock_limit >>= PAGE_SHIFT; 5844 lock_limit >>= PAGE_SHIFT;
@@ -10586,55 +10611,26 @@ static int perf_copy_attr(struct perf_event_attr __user *uattr,
10586 u32 size; 10611 u32 size;
10587 int ret; 10612 int ret;
10588 10613
10589 if (!access_ok(uattr, PERF_ATTR_SIZE_VER0)) 10614 /* Zero the full structure, so that a short copy will be nice. */
10590 return -EFAULT;
10591
10592 /*
10593 * zero the full structure, so that a short copy will be nice.
10594 */
10595 memset(attr, 0, sizeof(*attr)); 10615 memset(attr, 0, sizeof(*attr));
10596 10616
10597 ret = get_user(size, &uattr->size); 10617 ret = get_user(size, &uattr->size);
10598 if (ret) 10618 if (ret)
10599 return ret; 10619 return ret;
10600 10620
10601 if (size > PAGE_SIZE) /* silly large */ 10621 /* ABI compatibility quirk: */
10602 goto err_size; 10622 if (!size)
10603
10604 if (!size) /* abi compat */
10605 size = PERF_ATTR_SIZE_VER0; 10623 size = PERF_ATTR_SIZE_VER0;
10606 10624 if (size < PERF_ATTR_SIZE_VER0 || size > PAGE_SIZE)
10607 if (size < PERF_ATTR_SIZE_VER0)
10608 goto err_size; 10625 goto err_size;
10609 10626
10610 /* 10627 ret = copy_struct_from_user(attr, sizeof(*attr), uattr, size);
10611 * If we're handed a bigger struct than we know of, 10628 if (ret) {
10612 * ensure all the unknown bits are 0 - i.e. new 10629 if (ret == -E2BIG)
10613 * user-space does not rely on any kernel feature 10630 goto err_size;
10614 * extensions we dont know about yet. 10631 return ret;
10615 */
10616 if (size > sizeof(*attr)) {
10617 unsigned char __user *addr;
10618 unsigned char __user *end;
10619 unsigned char val;
10620
10621 addr = (void __user *)uattr + sizeof(*attr);
10622 end = (void __user *)uattr + size;
10623
10624 for (; addr < end; addr++) {
10625 ret = get_user(val, addr);
10626 if (ret)
10627 return ret;
10628 if (val)
10629 goto err_size;
10630 }
10631 size = sizeof(*attr);
10632 } 10632 }
10633 10633
10634 ret = copy_from_user(attr, uattr, size);
10635 if (ret)
10636 return -EFAULT;
10637
10638 attr->size = size; 10634 attr->size = size;
10639 10635
10640 if (attr->__reserved_1) 10636 if (attr->__reserved_1)
@@ -11891,6 +11887,10 @@ static int inherit_group(struct perf_event *parent_event,
11891 child, leader, child_ctx); 11887 child, leader, child_ctx);
11892 if (IS_ERR(child_ctr)) 11888 if (IS_ERR(child_ctr))
11893 return PTR_ERR(child_ctr); 11889 return PTR_ERR(child_ctr);
11890
11891 if (sub->aux_event == parent_event &&
11892 !perf_get_aux_event(child_ctr, leader))
11893 return -EINVAL;
11894 } 11894 }
11895 return 0; 11895 return 0;
11896} 11896}
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 94d38a39d72e..c74761004ee5 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -474,14 +474,17 @@ int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm,
474 struct vm_area_struct *vma; 474 struct vm_area_struct *vma;
475 int ret, is_register, ref_ctr_updated = 0; 475 int ret, is_register, ref_ctr_updated = 0;
476 bool orig_page_huge = false; 476 bool orig_page_huge = false;
477 unsigned int gup_flags = FOLL_FORCE;
477 478
478 is_register = is_swbp_insn(&opcode); 479 is_register = is_swbp_insn(&opcode);
479 uprobe = container_of(auprobe, struct uprobe, arch); 480 uprobe = container_of(auprobe, struct uprobe, arch);
480 481
481retry: 482retry:
483 if (is_register)
484 gup_flags |= FOLL_SPLIT_PMD;
482 /* Read the page with vaddr into memory */ 485 /* Read the page with vaddr into memory */
483 ret = get_user_pages_remote(NULL, mm, vaddr, 1, 486 ret = get_user_pages_remote(NULL, mm, vaddr, 1, gup_flags,
484 FOLL_FORCE | FOLL_SPLIT_PMD, &old_page, &vma, NULL); 487 &old_page, &vma, NULL);
485 if (ret <= 0) 488 if (ret <= 0)
486 return ret; 489 return ret;
487 490
@@ -489,6 +492,12 @@ retry:
489 if (ret <= 0) 492 if (ret <= 0)
490 goto put_old; 493 goto put_old;
491 494
495 if (WARN(!is_register && PageCompound(old_page),
496 "uprobe unregister should never work on compound page\n")) {
497 ret = -EINVAL;
498 goto put_old;
499 }
500
492 /* We are going to replace instruction, update ref_ctr. */ 501 /* We are going to replace instruction, update ref_ctr. */
493 if (!ref_ctr_updated && uprobe->ref_ctr_offset) { 502 if (!ref_ctr_updated && uprobe->ref_ctr_offset) {
494 ret = update_ref_ctr(uprobe, mm, is_register ? 1 : -1); 503 ret = update_ref_ctr(uprobe, mm, is_register ? 1 : -1);
diff --git a/kernel/fork.c b/kernel/fork.c
index f9572f416126..bcdf53125210 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -2525,39 +2525,19 @@ SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp,
2525#ifdef __ARCH_WANT_SYS_CLONE3 2525#ifdef __ARCH_WANT_SYS_CLONE3
2526noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs, 2526noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs,
2527 struct clone_args __user *uargs, 2527 struct clone_args __user *uargs,
2528 size_t size) 2528 size_t usize)
2529{ 2529{
2530 int err;
2530 struct clone_args args; 2531 struct clone_args args;
2531 2532
2532 if (unlikely(size > PAGE_SIZE)) 2533 if (unlikely(usize > PAGE_SIZE))
2533 return -E2BIG; 2534 return -E2BIG;
2534 2535 if (unlikely(usize < CLONE_ARGS_SIZE_VER0))
2535 if (unlikely(size < sizeof(struct clone_args)))
2536 return -EINVAL; 2536 return -EINVAL;
2537 2537
2538 if (unlikely(!access_ok(uargs, size))) 2538 err = copy_struct_from_user(&args, sizeof(args), uargs, usize);
2539 return -EFAULT; 2539 if (err)
2540 2540 return err;
2541 if (size > sizeof(struct clone_args)) {
2542 unsigned char __user *addr;
2543 unsigned char __user *end;
2544 unsigned char val;
2545
2546 addr = (void __user *)uargs + sizeof(struct clone_args);
2547 end = (void __user *)uargs + size;
2548
2549 for (; addr < end; addr++) {
2550 if (get_user(val, addr))
2551 return -EFAULT;
2552 if (val)
2553 return -E2BIG;
2554 }
2555
2556 size = sizeof(struct clone_args);
2557 }
2558
2559 if (copy_from_user(&args, uargs, size))
2560 return -EFAULT;
2561 2541
2562 /* 2542 /*
2563 * Verify that higher 32bits of exit_signal are unset and that 2543 * Verify that higher 32bits of exit_signal are unset and that
@@ -2604,6 +2584,17 @@ static bool clone3_args_valid(const struct kernel_clone_args *kargs)
2604 return true; 2584 return true;
2605} 2585}
2606 2586
2587/**
2588 * clone3 - create a new process with specific properties
2589 * @uargs: argument structure
2590 * @size: size of @uargs
2591 *
2592 * clone3() is the extensible successor to clone()/clone2().
2593 * It takes a struct as argument that is versioned by its size.
2594 *
2595 * Return: On success, a positive PID for the child process.
2596 * On error, a negative errno number.
2597 */
2607SYSCALL_DEFINE2(clone3, struct clone_args __user *, uargs, size_t, size) 2598SYSCALL_DEFINE2(clone3, struct clone_args __user *, uargs, size_t, size)
2608{ 2599{
2609 int err; 2600 int err;
@@ -2934,7 +2925,7 @@ int sysctl_max_threads(struct ctl_table *table, int write,
2934 struct ctl_table t; 2925 struct ctl_table t;
2935 int ret; 2926 int ret;
2936 int threads = max_threads; 2927 int threads = max_threads;
2937 int min = MIN_THREADS; 2928 int min = 1;
2938 int max = MAX_THREADS; 2929 int max = MAX_THREADS;
2939 2930
2940 t = *table; 2931 t = *table;
@@ -2946,7 +2937,7 @@ int sysctl_max_threads(struct ctl_table *table, int write,
2946 if (ret || !write) 2937 if (ret || !write)
2947 return ret; 2938 return ret;
2948 2939
2949 set_max_threads(threads); 2940 max_threads = threads;
2950 2941
2951 return 0; 2942 return 0;
2952} 2943}
diff --git a/kernel/freezer.c b/kernel/freezer.c
index c0738424bb43..dc520f01f99d 100644
--- a/kernel/freezer.c
+++ b/kernel/freezer.c
@@ -22,12 +22,6 @@ EXPORT_SYMBOL(system_freezing_cnt);
22bool pm_freezing; 22bool pm_freezing;
23bool pm_nosig_freezing; 23bool pm_nosig_freezing;
24 24
25/*
26 * Temporary export for the deadlock workaround in ata_scsi_hotplug().
27 * Remove once the hack becomes unnecessary.
28 */
29EXPORT_SYMBOL_GPL(pm_freezing);
30
31/* protects freezing and frozen transitions */ 25/* protects freezing and frozen transitions */
32static DEFINE_SPINLOCK(freezer_lock); 26static DEFINE_SPINLOCK(freezer_lock);
33 27
diff --git a/kernel/gen_kheaders.sh b/kernel/gen_kheaders.sh
index 9ff449888d9c..aff79e461fc9 100755
--- a/kernel/gen_kheaders.sh
+++ b/kernel/gen_kheaders.sh
@@ -71,7 +71,10 @@ done | cpio --quiet -pd $cpio_dir >/dev/null 2>&1
71find $cpio_dir -type f -print0 | 71find $cpio_dir -type f -print0 |
72 xargs -0 -P8 -n1 perl -pi -e 'BEGIN {undef $/;}; s/\/\*((?!SPDX).)*?\*\///smg;' 72 xargs -0 -P8 -n1 perl -pi -e 'BEGIN {undef $/;}; s/\/\*((?!SPDX).)*?\*\///smg;'
73 73
74tar -Jcf $tarfile -C $cpio_dir/ . > /dev/null 74# Create archive and try to normalize metadata for reproducibility
75tar "${KBUILD_BUILD_TIMESTAMP:+--mtime=$KBUILD_BUILD_TIMESTAMP}" \
76 --owner=0 --group=0 --sort=name --numeric-owner \
77 -Jcf $tarfile -C $cpio_dir/ . > /dev/null
75 78
76echo "$src_files_md5" > kernel/kheaders.md5 79echo "$src_files_md5" > kernel/kheaders.md5
77echo "$obj_files_md5" >> kernel/kheaders.md5 80echo "$obj_files_md5" >> kernel/kheaders.md5
diff --git a/kernel/kthread.c b/kernel/kthread.c
index 621467c33fef..b262f47046ca 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -866,9 +866,9 @@ void kthread_delayed_work_timer_fn(struct timer_list *t)
866} 866}
867EXPORT_SYMBOL(kthread_delayed_work_timer_fn); 867EXPORT_SYMBOL(kthread_delayed_work_timer_fn);
868 868
869void __kthread_queue_delayed_work(struct kthread_worker *worker, 869static void __kthread_queue_delayed_work(struct kthread_worker *worker,
870 struct kthread_delayed_work *dwork, 870 struct kthread_delayed_work *dwork,
871 unsigned long delay) 871 unsigned long delay)
872{ 872{
873 struct timer_list *timer = &dwork->timer; 873 struct timer_list *timer = &dwork->timer;
874 struct kthread_work *work = &dwork->work; 874 struct kthread_work *work = &dwork->work;
diff --git a/kernel/panic.c b/kernel/panic.c
index 47e8ebccc22b..f470a038b05b 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -180,6 +180,7 @@ void panic(const char *fmt, ...)
180 * after setting panic_cpu) from invoking panic() again. 180 * after setting panic_cpu) from invoking panic() again.
181 */ 181 */
182 local_irq_disable(); 182 local_irq_disable();
183 preempt_disable_notrace();
183 184
184 /* 185 /*
185 * It's possible to come here directly from a panic-assertion and 186 * It's possible to come here directly from a panic-assertion and
diff --git a/kernel/power/main.c b/kernel/power/main.c
index e8710d179b35..e26de7af520b 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -15,6 +15,7 @@
15#include <linux/seq_file.h> 15#include <linux/seq_file.h>
16#include <linux/suspend.h> 16#include <linux/suspend.h>
17#include <linux/syscalls.h> 17#include <linux/syscalls.h>
18#include <linux/pm_runtime.h>
18 19
19#include "power.h" 20#include "power.h"
20 21
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 7880f4f64d0e..dd05a378631a 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5106,9 +5106,6 @@ static int sched_copy_attr(struct sched_attr __user *uattr, struct sched_attr *a
5106 u32 size; 5106 u32 size;
5107 int ret; 5107 int ret;
5108 5108
5109 if (!access_ok(uattr, SCHED_ATTR_SIZE_VER0))
5110 return -EFAULT;
5111
5112 /* Zero the full structure, so that a short copy will be nice: */ 5109 /* Zero the full structure, so that a short copy will be nice: */
5113 memset(attr, 0, sizeof(*attr)); 5110 memset(attr, 0, sizeof(*attr));
5114 5111
@@ -5116,45 +5113,19 @@ static int sched_copy_attr(struct sched_attr __user *uattr, struct sched_attr *a
5116 if (ret) 5113 if (ret)
5117 return ret; 5114 return ret;
5118 5115
5119 /* Bail out on silly large: */
5120 if (size > PAGE_SIZE)
5121 goto err_size;
5122
5123 /* ABI compatibility quirk: */ 5116 /* ABI compatibility quirk: */
5124 if (!size) 5117 if (!size)
5125 size = SCHED_ATTR_SIZE_VER0; 5118 size = SCHED_ATTR_SIZE_VER0;
5126 5119 if (size < SCHED_ATTR_SIZE_VER0 || size > PAGE_SIZE)
5127 if (size < SCHED_ATTR_SIZE_VER0)
5128 goto err_size; 5120 goto err_size;
5129 5121
5130 /* 5122 ret = copy_struct_from_user(attr, sizeof(*attr), uattr, size);
5131 * If we're handed a bigger struct than we know of, 5123 if (ret) {
5132 * ensure all the unknown bits are 0 - i.e. new 5124 if (ret == -E2BIG)
5133 * user-space does not rely on any kernel feature 5125 goto err_size;
5134 * extensions we dont know about yet. 5126 return ret;
5135 */
5136 if (size > sizeof(*attr)) {
5137 unsigned char __user *addr;
5138 unsigned char __user *end;
5139 unsigned char val;
5140
5141 addr = (void __user *)uattr + sizeof(*attr);
5142 end = (void __user *)uattr + size;
5143
5144 for (; addr < end; addr++) {
5145 ret = get_user(val, addr);
5146 if (ret)
5147 return ret;
5148 if (val)
5149 goto err_size;
5150 }
5151 size = sizeof(*attr);
5152 } 5127 }
5153 5128
5154 ret = copy_from_user(attr, uattr, size);
5155 if (ret)
5156 return -EFAULT;
5157
5158 if ((attr->sched_flags & SCHED_FLAG_UTIL_CLAMP) && 5129 if ((attr->sched_flags & SCHED_FLAG_UTIL_CLAMP) &&
5159 size < SCHED_ATTR_SIZE_VER1) 5130 size < SCHED_ATTR_SIZE_VER1)
5160 return -EINVAL; 5131 return -EINVAL;
@@ -5354,7 +5325,7 @@ sched_attr_copy_to_user(struct sched_attr __user *uattr,
5354 * sys_sched_getattr - similar to sched_getparam, but with sched_attr 5325 * sys_sched_getattr - similar to sched_getparam, but with sched_attr
5355 * @pid: the pid in question. 5326 * @pid: the pid in question.
5356 * @uattr: structure containing the extended parameters. 5327 * @uattr: structure containing the extended parameters.
5357 * @usize: sizeof(attr) that user-space knows about, for forwards and backwards compatibility. 5328 * @usize: sizeof(attr) for fwd/bwd comp.
5358 * @flags: for future extension. 5329 * @flags: for future extension.
5359 */ 5330 */
5360SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr, 5331SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr,
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 2305ce89a26c..46ed4e1383e2 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -740,7 +740,7 @@ void vtime_account_system(struct task_struct *tsk)
740 740
741 write_seqcount_begin(&vtime->seqcount); 741 write_seqcount_begin(&vtime->seqcount);
742 /* We might have scheduled out from guest path */ 742 /* We might have scheduled out from guest path */
743 if (current->flags & PF_VCPU) 743 if (tsk->flags & PF_VCPU)
744 vtime_account_guest(tsk, vtime); 744 vtime_account_guest(tsk, vtime);
745 else 745 else
746 __vtime_account_system(tsk, vtime); 746 __vtime_account_system(tsk, vtime);
@@ -783,7 +783,7 @@ void vtime_guest_enter(struct task_struct *tsk)
783 */ 783 */
784 write_seqcount_begin(&vtime->seqcount); 784 write_seqcount_begin(&vtime->seqcount);
785 __vtime_account_system(tsk, vtime); 785 __vtime_account_system(tsk, vtime);
786 current->flags |= PF_VCPU; 786 tsk->flags |= PF_VCPU;
787 write_seqcount_end(&vtime->seqcount); 787 write_seqcount_end(&vtime->seqcount);
788} 788}
789EXPORT_SYMBOL_GPL(vtime_guest_enter); 789EXPORT_SYMBOL_GPL(vtime_guest_enter);
@@ -794,7 +794,7 @@ void vtime_guest_exit(struct task_struct *tsk)
794 794
795 write_seqcount_begin(&vtime->seqcount); 795 write_seqcount_begin(&vtime->seqcount);
796 vtime_account_guest(tsk, vtime); 796 vtime_account_guest(tsk, vtime);
797 current->flags &= ~PF_VCPU; 797 tsk->flags &= ~PF_VCPU;
798 write_seqcount_end(&vtime->seqcount); 798 write_seqcount_end(&vtime->seqcount);
799} 799}
800EXPORT_SYMBOL_GPL(vtime_guest_exit); 800EXPORT_SYMBOL_GPL(vtime_guest_exit);
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 83ab35e2374f..682a754ea3e1 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4926,20 +4926,28 @@ static enum hrtimer_restart sched_cfs_period_timer(struct hrtimer *timer)
4926 if (++count > 3) { 4926 if (++count > 3) {
4927 u64 new, old = ktime_to_ns(cfs_b->period); 4927 u64 new, old = ktime_to_ns(cfs_b->period);
4928 4928
4929 new = (old * 147) / 128; /* ~115% */ 4929 /*
4930 new = min(new, max_cfs_quota_period); 4930 * Grow period by a factor of 2 to avoid losing precision.
4931 4931 * Precision loss in the quota/period ratio can cause __cfs_schedulable
4932 cfs_b->period = ns_to_ktime(new); 4932 * to fail.
4933 4933 */
4934 /* since max is 1s, this is limited to 1e9^2, which fits in u64 */ 4934 new = old * 2;
4935 cfs_b->quota *= new; 4935 if (new < max_cfs_quota_period) {
4936 cfs_b->quota = div64_u64(cfs_b->quota, old); 4936 cfs_b->period = ns_to_ktime(new);
4937 4937 cfs_b->quota *= 2;
4938 pr_warn_ratelimited( 4938
4939 "cfs_period_timer[cpu%d]: period too short, scaling up (new cfs_period_us %lld, cfs_quota_us = %lld)\n", 4939 pr_warn_ratelimited(
4940 smp_processor_id(), 4940 "cfs_period_timer[cpu%d]: period too short, scaling up (new cfs_period_us = %lld, cfs_quota_us = %lld)\n",
4941 div_u64(new, NSEC_PER_USEC), 4941 smp_processor_id(),
4942 div_u64(cfs_b->quota, NSEC_PER_USEC)); 4942 div_u64(new, NSEC_PER_USEC),
4943 div_u64(cfs_b->quota, NSEC_PER_USEC));
4944 } else {
4945 pr_warn_ratelimited(
4946 "cfs_period_timer[cpu%d]: period too short, but cannot scale up without losing precision (cfs_period_us = %lld, cfs_quota_us = %lld)\n",
4947 smp_processor_id(),
4948 div_u64(old, NSEC_PER_USEC),
4949 div_u64(cfs_b->quota, NSEC_PER_USEC));
4950 }
4943 4951
4944 /* reset count so we don't come right back in here */ 4952 /* reset count so we don't come right back in here */
4945 count = 0; 4953 count = 0;
diff --git a/kernel/sched/membarrier.c b/kernel/sched/membarrier.c
index a39bed2c784f..168479a7d61b 100644
--- a/kernel/sched/membarrier.c
+++ b/kernel/sched/membarrier.c
@@ -174,7 +174,6 @@ static int membarrier_private_expedited(int flags)
174 */ 174 */
175 if (cpu == raw_smp_processor_id()) 175 if (cpu == raw_smp_processor_id())
176 continue; 176 continue;
177 rcu_read_lock();
178 p = rcu_dereference(cpu_rq(cpu)->curr); 177 p = rcu_dereference(cpu_rq(cpu)->curr);
179 if (p && p->mm == mm) 178 if (p && p->mm == mm)
180 __cpumask_set_cpu(cpu, tmpmask); 179 __cpumask_set_cpu(cpu, tmpmask);
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 00fcea236eba..b6f2f35d0bcf 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -163,7 +163,7 @@ static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
163#ifdef CONFIG_SPARC 163#ifdef CONFIG_SPARC
164#endif 164#endif
165 165
166#ifdef __hppa__ 166#ifdef CONFIG_PARISC
167extern int pwrsw_enabled; 167extern int pwrsw_enabled;
168#endif 168#endif
169 169
@@ -620,7 +620,7 @@ static struct ctl_table kern_table[] = {
620 .proc_handler = proc_dointvec, 620 .proc_handler = proc_dointvec,
621 }, 621 },
622#endif 622#endif
623#ifdef __hppa__ 623#ifdef CONFIG_PARISC
624 { 624 {
625 .procname = "soft-power", 625 .procname = "soft-power",
626 .data = &pwrsw_enabled, 626 .data = &pwrsw_enabled,
diff --git a/kernel/time/tick-broadcast-hrtimer.c b/kernel/time/tick-broadcast-hrtimer.c
index c1f5bb590b5e..b5a65e212df2 100644
--- a/kernel/time/tick-broadcast-hrtimer.c
+++ b/kernel/time/tick-broadcast-hrtimer.c
@@ -42,39 +42,39 @@ static int bc_shutdown(struct clock_event_device *evt)
42 */ 42 */
43static int bc_set_next(ktime_t expires, struct clock_event_device *bc) 43static int bc_set_next(ktime_t expires, struct clock_event_device *bc)
44{ 44{
45 int bc_moved;
46 /* 45 /*
47 * We try to cancel the timer first. If the callback is on 46 * This is called either from enter/exit idle code or from the
48 * flight on some other cpu then we let it handle it. If we 47 * broadcast handler. In all cases tick_broadcast_lock is held.
49 * were able to cancel the timer nothing can rearm it as we
50 * own broadcast_lock.
51 * 48 *
52 * However we can also be called from the event handler of 49 * hrtimer_cancel() cannot be called here neither from the
53 * ce_broadcast_hrtimer itself when it expires. We cannot 50 * broadcast handler nor from the enter/exit idle code. The idle
54 * restart the timer because we are in the callback, but we 51 * code can run into the problem described in bc_shutdown() and the
55 * can set the expiry time and let the callback return 52 * broadcast handler cannot wait for itself to complete for obvious
56 * HRTIMER_RESTART. 53 * reasons.
57 * 54 *
58 * Since we are in the idle loop at this point and because 55 * Each caller tries to arm the hrtimer on its own CPU, but if the
59 * hrtimer_{start/cancel} functions call into tracing, 56 * hrtimer callbback function is currently running, then
60 * calls to these functions must be bound within RCU_NONIDLE. 57 * hrtimer_start() cannot move it and the timer stays on the CPU on
58 * which it is assigned at the moment.
59 *
60 * As this can be called from idle code, the hrtimer_start()
61 * invocation has to be wrapped with RCU_NONIDLE() as
62 * hrtimer_start() can call into tracing.
61 */ 63 */
62 RCU_NONIDLE( 64 RCU_NONIDLE( {
63 { 65 hrtimer_start(&bctimer, expires, HRTIMER_MODE_ABS_PINNED_HARD);
64 bc_moved = hrtimer_try_to_cancel(&bctimer) >= 0; 66 /*
65 if (bc_moved) { 67 * The core tick broadcast mode expects bc->bound_on to be set
66 hrtimer_start(&bctimer, expires, 68 * correctly to prevent a CPU which has the broadcast hrtimer
67 HRTIMER_MODE_ABS_PINNED_HARD); 69 * armed from going deep idle.
68 } 70 *
69 } 71 * As tick_broadcast_lock is held, nothing can change the cpu
70 ); 72 * base which was just established in hrtimer_start() above. So
71 73 * the below access is safe even without holding the hrtimer
72 if (bc_moved) { 74 * base lock.
73 /* Bind the "device" to the cpu */ 75 */
74 bc->bound_on = smp_processor_id(); 76 bc->bound_on = bctimer.base->cpu_base->cpu;
75 } else if (bc->bound_on == smp_processor_id()) { 77 } );
76 hrtimer_set_expires(&bctimer, expires);
77 }
78 return 0; 78 return 0;
79} 79}
80 80
@@ -100,10 +100,6 @@ static enum hrtimer_restart bc_handler(struct hrtimer *t)
100{ 100{
101 ce_broadcast_hrtimer.event_handler(&ce_broadcast_hrtimer); 101 ce_broadcast_hrtimer.event_handler(&ce_broadcast_hrtimer);
102 102
103 if (clockevent_state_oneshot(&ce_broadcast_hrtimer))
104 if (ce_broadcast_hrtimer.next_event != KTIME_MAX)
105 return HRTIMER_RESTART;
106
107 return HRTIMER_NORESTART; 103 return HRTIMER_NORESTART;
108} 104}
109 105
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 62a50bf399d6..f296d89be757 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -18,6 +18,7 @@
18#include <linux/clocksource.h> 18#include <linux/clocksource.h>
19#include <linux/sched/task.h> 19#include <linux/sched/task.h>
20#include <linux/kallsyms.h> 20#include <linux/kallsyms.h>
21#include <linux/security.h>
21#include <linux/seq_file.h> 22#include <linux/seq_file.h>
22#include <linux/tracefs.h> 23#include <linux/tracefs.h>
23#include <linux/hardirq.h> 24#include <linux/hardirq.h>
@@ -3486,6 +3487,11 @@ static int
3486ftrace_avail_open(struct inode *inode, struct file *file) 3487ftrace_avail_open(struct inode *inode, struct file *file)
3487{ 3488{
3488 struct ftrace_iterator *iter; 3489 struct ftrace_iterator *iter;
3490 int ret;
3491
3492 ret = security_locked_down(LOCKDOWN_TRACEFS);
3493 if (ret)
3494 return ret;
3489 3495
3490 if (unlikely(ftrace_disabled)) 3496 if (unlikely(ftrace_disabled))
3491 return -ENODEV; 3497 return -ENODEV;
@@ -3505,6 +3511,15 @@ ftrace_enabled_open(struct inode *inode, struct file *file)
3505{ 3511{
3506 struct ftrace_iterator *iter; 3512 struct ftrace_iterator *iter;
3507 3513
3514 /*
3515 * This shows us what functions are currently being
3516 * traced and by what. Not sure if we want lockdown
3517 * to hide such critical information for an admin.
3518 * Although, perhaps it can show information we don't
3519 * want people to see, but if something is tracing
3520 * something, we probably want to know about it.
3521 */
3522
3508 iter = __seq_open_private(file, &show_ftrace_seq_ops, sizeof(*iter)); 3523 iter = __seq_open_private(file, &show_ftrace_seq_ops, sizeof(*iter));
3509 if (!iter) 3524 if (!iter)
3510 return -ENOMEM; 3525 return -ENOMEM;
@@ -3540,21 +3555,22 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
3540 struct ftrace_hash *hash; 3555 struct ftrace_hash *hash;
3541 struct list_head *mod_head; 3556 struct list_head *mod_head;
3542 struct trace_array *tr = ops->private; 3557 struct trace_array *tr = ops->private;
3543 int ret = 0; 3558 int ret = -ENOMEM;
3544 3559
3545 ftrace_ops_init(ops); 3560 ftrace_ops_init(ops);
3546 3561
3547 if (unlikely(ftrace_disabled)) 3562 if (unlikely(ftrace_disabled))
3548 return -ENODEV; 3563 return -ENODEV;
3549 3564
3565 if (tracing_check_open_get_tr(tr))
3566 return -ENODEV;
3567
3550 iter = kzalloc(sizeof(*iter), GFP_KERNEL); 3568 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
3551 if (!iter) 3569 if (!iter)
3552 return -ENOMEM; 3570 goto out;
3553 3571
3554 if (trace_parser_get_init(&iter->parser, FTRACE_BUFF_MAX)) { 3572 if (trace_parser_get_init(&iter->parser, FTRACE_BUFF_MAX))
3555 kfree(iter); 3573 goto out;
3556 return -ENOMEM;
3557 }
3558 3574
3559 iter->ops = ops; 3575 iter->ops = ops;
3560 iter->flags = flag; 3576 iter->flags = flag;
@@ -3584,13 +3600,13 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
3584 3600
3585 if (!iter->hash) { 3601 if (!iter->hash) {
3586 trace_parser_put(&iter->parser); 3602 trace_parser_put(&iter->parser);
3587 kfree(iter);
3588 ret = -ENOMEM;
3589 goto out_unlock; 3603 goto out_unlock;
3590 } 3604 }
3591 } else 3605 } else
3592 iter->hash = hash; 3606 iter->hash = hash;
3593 3607
3608 ret = 0;
3609
3594 if (file->f_mode & FMODE_READ) { 3610 if (file->f_mode & FMODE_READ) {
3595 iter->pg = ftrace_pages_start; 3611 iter->pg = ftrace_pages_start;
3596 3612
@@ -3602,7 +3618,6 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
3602 /* Failed */ 3618 /* Failed */
3603 free_ftrace_hash(iter->hash); 3619 free_ftrace_hash(iter->hash);
3604 trace_parser_put(&iter->parser); 3620 trace_parser_put(&iter->parser);
3605 kfree(iter);
3606 } 3621 }
3607 } else 3622 } else
3608 file->private_data = iter; 3623 file->private_data = iter;
@@ -3610,6 +3625,13 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
3610 out_unlock: 3625 out_unlock:
3611 mutex_unlock(&ops->func_hash->regex_lock); 3626 mutex_unlock(&ops->func_hash->regex_lock);
3612 3627
3628 out:
3629 if (ret) {
3630 kfree(iter);
3631 if (tr)
3632 trace_array_put(tr);
3633 }
3634
3613 return ret; 3635 return ret;
3614} 3636}
3615 3637
@@ -3618,6 +3640,7 @@ ftrace_filter_open(struct inode *inode, struct file *file)
3618{ 3640{
3619 struct ftrace_ops *ops = inode->i_private; 3641 struct ftrace_ops *ops = inode->i_private;
3620 3642
3643 /* Checks for tracefs lockdown */
3621 return ftrace_regex_open(ops, 3644 return ftrace_regex_open(ops,
3622 FTRACE_ITER_FILTER | FTRACE_ITER_DO_PROBES, 3645 FTRACE_ITER_FILTER | FTRACE_ITER_DO_PROBES,
3623 inode, file); 3646 inode, file);
@@ -3628,6 +3651,7 @@ ftrace_notrace_open(struct inode *inode, struct file *file)
3628{ 3651{
3629 struct ftrace_ops *ops = inode->i_private; 3652 struct ftrace_ops *ops = inode->i_private;
3630 3653
3654 /* Checks for tracefs lockdown */
3631 return ftrace_regex_open(ops, FTRACE_ITER_NOTRACE, 3655 return ftrace_regex_open(ops, FTRACE_ITER_NOTRACE,
3632 inode, file); 3656 inode, file);
3633} 3657}
@@ -5037,6 +5061,8 @@ int ftrace_regex_release(struct inode *inode, struct file *file)
5037 5061
5038 mutex_unlock(&iter->ops->func_hash->regex_lock); 5062 mutex_unlock(&iter->ops->func_hash->regex_lock);
5039 free_ftrace_hash(iter->hash); 5063 free_ftrace_hash(iter->hash);
5064 if (iter->tr)
5065 trace_array_put(iter->tr);
5040 kfree(iter); 5066 kfree(iter);
5041 5067
5042 return 0; 5068 return 0;
@@ -5194,9 +5220,13 @@ static int
5194__ftrace_graph_open(struct inode *inode, struct file *file, 5220__ftrace_graph_open(struct inode *inode, struct file *file,
5195 struct ftrace_graph_data *fgd) 5221 struct ftrace_graph_data *fgd)
5196{ 5222{
5197 int ret = 0; 5223 int ret;
5198 struct ftrace_hash *new_hash = NULL; 5224 struct ftrace_hash *new_hash = NULL;
5199 5225
5226 ret = security_locked_down(LOCKDOWN_TRACEFS);
5227 if (ret)
5228 return ret;
5229
5200 if (file->f_mode & FMODE_WRITE) { 5230 if (file->f_mode & FMODE_WRITE) {
5201 const int size_bits = FTRACE_HASH_DEFAULT_BITS; 5231 const int size_bits = FTRACE_HASH_DEFAULT_BITS;
5202 5232
@@ -6537,8 +6567,9 @@ ftrace_pid_open(struct inode *inode, struct file *file)
6537 struct seq_file *m; 6567 struct seq_file *m;
6538 int ret = 0; 6568 int ret = 0;
6539 6569
6540 if (trace_array_get(tr) < 0) 6570 ret = tracing_check_open_get_tr(tr);
6541 return -ENODEV; 6571 if (ret)
6572 return ret;
6542 6573
6543 if ((file->f_mode & FMODE_WRITE) && 6574 if ((file->f_mode & FMODE_WRITE) &&
6544 (file->f_flags & O_TRUNC)) 6575 (file->f_flags & O_TRUNC))
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 252f79c435f8..6a0ee9178365 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -17,6 +17,7 @@
17#include <linux/stacktrace.h> 17#include <linux/stacktrace.h>
18#include <linux/writeback.h> 18#include <linux/writeback.h>
19#include <linux/kallsyms.h> 19#include <linux/kallsyms.h>
20#include <linux/security.h>
20#include <linux/seq_file.h> 21#include <linux/seq_file.h>
21#include <linux/notifier.h> 22#include <linux/notifier.h>
22#include <linux/irqflags.h> 23#include <linux/irqflags.h>
@@ -304,6 +305,23 @@ void trace_array_put(struct trace_array *this_tr)
304 mutex_unlock(&trace_types_lock); 305 mutex_unlock(&trace_types_lock);
305} 306}
306 307
308int tracing_check_open_get_tr(struct trace_array *tr)
309{
310 int ret;
311
312 ret = security_locked_down(LOCKDOWN_TRACEFS);
313 if (ret)
314 return ret;
315
316 if (tracing_disabled)
317 return -ENODEV;
318
319 if (tr && trace_array_get(tr) < 0)
320 return -ENODEV;
321
322 return 0;
323}
324
307int call_filter_check_discard(struct trace_event_call *call, void *rec, 325int call_filter_check_discard(struct trace_event_call *call, void *rec,
308 struct ring_buffer *buffer, 326 struct ring_buffer *buffer,
309 struct ring_buffer_event *event) 327 struct ring_buffer_event *event)
@@ -4140,8 +4158,11 @@ release:
4140 4158
4141int tracing_open_generic(struct inode *inode, struct file *filp) 4159int tracing_open_generic(struct inode *inode, struct file *filp)
4142{ 4160{
4143 if (tracing_disabled) 4161 int ret;
4144 return -ENODEV; 4162
4163 ret = tracing_check_open_get_tr(NULL);
4164 if (ret)
4165 return ret;
4145 4166
4146 filp->private_data = inode->i_private; 4167 filp->private_data = inode->i_private;
4147 return 0; 4168 return 0;
@@ -4156,15 +4177,14 @@ bool tracing_is_disabled(void)
4156 * Open and update trace_array ref count. 4177 * Open and update trace_array ref count.
4157 * Must have the current trace_array passed to it. 4178 * Must have the current trace_array passed to it.
4158 */ 4179 */
4159static int tracing_open_generic_tr(struct inode *inode, struct file *filp) 4180int tracing_open_generic_tr(struct inode *inode, struct file *filp)
4160{ 4181{
4161 struct trace_array *tr = inode->i_private; 4182 struct trace_array *tr = inode->i_private;
4183 int ret;
4162 4184
4163 if (tracing_disabled) 4185 ret = tracing_check_open_get_tr(tr);
4164 return -ENODEV; 4186 if (ret)
4165 4187 return ret;
4166 if (trace_array_get(tr) < 0)
4167 return -ENODEV;
4168 4188
4169 filp->private_data = inode->i_private; 4189 filp->private_data = inode->i_private;
4170 4190
@@ -4233,10 +4253,11 @@ static int tracing_open(struct inode *inode, struct file *file)
4233{ 4253{
4234 struct trace_array *tr = inode->i_private; 4254 struct trace_array *tr = inode->i_private;
4235 struct trace_iterator *iter; 4255 struct trace_iterator *iter;
4236 int ret = 0; 4256 int ret;
4237 4257
4238 if (trace_array_get(tr) < 0) 4258 ret = tracing_check_open_get_tr(tr);
4239 return -ENODEV; 4259 if (ret)
4260 return ret;
4240 4261
4241 /* If this file was open for write, then erase contents */ 4262 /* If this file was open for write, then erase contents */
4242 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) { 4263 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) {
@@ -4352,12 +4373,15 @@ static int show_traces_open(struct inode *inode, struct file *file)
4352 struct seq_file *m; 4373 struct seq_file *m;
4353 int ret; 4374 int ret;
4354 4375
4355 if (tracing_disabled) 4376 ret = tracing_check_open_get_tr(tr);
4356 return -ENODEV; 4377 if (ret)
4378 return ret;
4357 4379
4358 ret = seq_open(file, &show_traces_seq_ops); 4380 ret = seq_open(file, &show_traces_seq_ops);
4359 if (ret) 4381 if (ret) {
4382 trace_array_put(tr);
4360 return ret; 4383 return ret;
4384 }
4361 4385
4362 m = file->private_data; 4386 m = file->private_data;
4363 m->private = tr; 4387 m->private = tr;
@@ -4365,6 +4389,14 @@ static int show_traces_open(struct inode *inode, struct file *file)
4365 return 0; 4389 return 0;
4366} 4390}
4367 4391
4392static int show_traces_release(struct inode *inode, struct file *file)
4393{
4394 struct trace_array *tr = inode->i_private;
4395
4396 trace_array_put(tr);
4397 return seq_release(inode, file);
4398}
4399
4368static ssize_t 4400static ssize_t
4369tracing_write_stub(struct file *filp, const char __user *ubuf, 4401tracing_write_stub(struct file *filp, const char __user *ubuf,
4370 size_t count, loff_t *ppos) 4402 size_t count, loff_t *ppos)
@@ -4395,8 +4427,8 @@ static const struct file_operations tracing_fops = {
4395static const struct file_operations show_traces_fops = { 4427static const struct file_operations show_traces_fops = {
4396 .open = show_traces_open, 4428 .open = show_traces_open,
4397 .read = seq_read, 4429 .read = seq_read,
4398 .release = seq_release,
4399 .llseek = seq_lseek, 4430 .llseek = seq_lseek,
4431 .release = show_traces_release,
4400}; 4432};
4401 4433
4402static ssize_t 4434static ssize_t
@@ -4697,11 +4729,9 @@ static int tracing_trace_options_open(struct inode *inode, struct file *file)
4697 struct trace_array *tr = inode->i_private; 4729 struct trace_array *tr = inode->i_private;
4698 int ret; 4730 int ret;
4699 4731
4700 if (tracing_disabled) 4732 ret = tracing_check_open_get_tr(tr);
4701 return -ENODEV; 4733 if (ret)
4702 4734 return ret;
4703 if (trace_array_get(tr) < 0)
4704 return -ENODEV;
4705 4735
4706 ret = single_open(file, tracing_trace_options_show, inode->i_private); 4736 ret = single_open(file, tracing_trace_options_show, inode->i_private);
4707 if (ret < 0) 4737 if (ret < 0)
@@ -5038,8 +5068,11 @@ static const struct seq_operations tracing_saved_tgids_seq_ops = {
5038 5068
5039static int tracing_saved_tgids_open(struct inode *inode, struct file *filp) 5069static int tracing_saved_tgids_open(struct inode *inode, struct file *filp)
5040{ 5070{
5041 if (tracing_disabled) 5071 int ret;
5042 return -ENODEV; 5072
5073 ret = tracing_check_open_get_tr(NULL);
5074 if (ret)
5075 return ret;
5043 5076
5044 return seq_open(filp, &tracing_saved_tgids_seq_ops); 5077 return seq_open(filp, &tracing_saved_tgids_seq_ops);
5045} 5078}
@@ -5115,8 +5148,11 @@ static const struct seq_operations tracing_saved_cmdlines_seq_ops = {
5115 5148
5116static int tracing_saved_cmdlines_open(struct inode *inode, struct file *filp) 5149static int tracing_saved_cmdlines_open(struct inode *inode, struct file *filp)
5117{ 5150{
5118 if (tracing_disabled) 5151 int ret;
5119 return -ENODEV; 5152
5153 ret = tracing_check_open_get_tr(NULL);
5154 if (ret)
5155 return ret;
5120 5156
5121 return seq_open(filp, &tracing_saved_cmdlines_seq_ops); 5157 return seq_open(filp, &tracing_saved_cmdlines_seq_ops);
5122} 5158}
@@ -5280,8 +5316,11 @@ static const struct seq_operations tracing_eval_map_seq_ops = {
5280 5316
5281static int tracing_eval_map_open(struct inode *inode, struct file *filp) 5317static int tracing_eval_map_open(struct inode *inode, struct file *filp)
5282{ 5318{
5283 if (tracing_disabled) 5319 int ret;
5284 return -ENODEV; 5320
5321 ret = tracing_check_open_get_tr(NULL);
5322 if (ret)
5323 return ret;
5285 5324
5286 return seq_open(filp, &tracing_eval_map_seq_ops); 5325 return seq_open(filp, &tracing_eval_map_seq_ops);
5287} 5326}
@@ -5804,13 +5843,11 @@ static int tracing_open_pipe(struct inode *inode, struct file *filp)
5804{ 5843{
5805 struct trace_array *tr = inode->i_private; 5844 struct trace_array *tr = inode->i_private;
5806 struct trace_iterator *iter; 5845 struct trace_iterator *iter;
5807 int ret = 0; 5846 int ret;
5808
5809 if (tracing_disabled)
5810 return -ENODEV;
5811 5847
5812 if (trace_array_get(tr) < 0) 5848 ret = tracing_check_open_get_tr(tr);
5813 return -ENODEV; 5849 if (ret)
5850 return ret;
5814 5851
5815 mutex_lock(&trace_types_lock); 5852 mutex_lock(&trace_types_lock);
5816 5853
@@ -5999,6 +6036,7 @@ waitagain:
5999 sizeof(struct trace_iterator) - 6036 sizeof(struct trace_iterator) -
6000 offsetof(struct trace_iterator, seq)); 6037 offsetof(struct trace_iterator, seq));
6001 cpumask_clear(iter->started); 6038 cpumask_clear(iter->started);
6039 trace_seq_init(&iter->seq);
6002 iter->pos = -1; 6040 iter->pos = -1;
6003 6041
6004 trace_event_read_lock(); 6042 trace_event_read_lock();
@@ -6547,11 +6585,9 @@ static int tracing_clock_open(struct inode *inode, struct file *file)
6547 struct trace_array *tr = inode->i_private; 6585 struct trace_array *tr = inode->i_private;
6548 int ret; 6586 int ret;
6549 6587
6550 if (tracing_disabled) 6588 ret = tracing_check_open_get_tr(tr);
6551 return -ENODEV; 6589 if (ret)
6552 6590 return ret;
6553 if (trace_array_get(tr))
6554 return -ENODEV;
6555 6591
6556 ret = single_open(file, tracing_clock_show, inode->i_private); 6592 ret = single_open(file, tracing_clock_show, inode->i_private);
6557 if (ret < 0) 6593 if (ret < 0)
@@ -6581,11 +6617,9 @@ static int tracing_time_stamp_mode_open(struct inode *inode, struct file *file)
6581 struct trace_array *tr = inode->i_private; 6617 struct trace_array *tr = inode->i_private;
6582 int ret; 6618 int ret;
6583 6619
6584 if (tracing_disabled) 6620 ret = tracing_check_open_get_tr(tr);
6585 return -ENODEV; 6621 if (ret)
6586 6622 return ret;
6587 if (trace_array_get(tr))
6588 return -ENODEV;
6589 6623
6590 ret = single_open(file, tracing_time_stamp_mode_show, inode->i_private); 6624 ret = single_open(file, tracing_time_stamp_mode_show, inode->i_private);
6591 if (ret < 0) 6625 if (ret < 0)
@@ -6638,10 +6672,11 @@ static int tracing_snapshot_open(struct inode *inode, struct file *file)
6638 struct trace_array *tr = inode->i_private; 6672 struct trace_array *tr = inode->i_private;
6639 struct trace_iterator *iter; 6673 struct trace_iterator *iter;
6640 struct seq_file *m; 6674 struct seq_file *m;
6641 int ret = 0; 6675 int ret;
6642 6676
6643 if (trace_array_get(tr) < 0) 6677 ret = tracing_check_open_get_tr(tr);
6644 return -ENODEV; 6678 if (ret)
6679 return ret;
6645 6680
6646 if (file->f_mode & FMODE_READ) { 6681 if (file->f_mode & FMODE_READ) {
6647 iter = __tracing_open(inode, file, true); 6682 iter = __tracing_open(inode, file, true);
@@ -6786,6 +6821,7 @@ static int snapshot_raw_open(struct inode *inode, struct file *filp)
6786 struct ftrace_buffer_info *info; 6821 struct ftrace_buffer_info *info;
6787 int ret; 6822 int ret;
6788 6823
6824 /* The following checks for tracefs lockdown */
6789 ret = tracing_buffers_open(inode, filp); 6825 ret = tracing_buffers_open(inode, filp);
6790 if (ret < 0) 6826 if (ret < 0)
6791 return ret; 6827 return ret;
@@ -7105,8 +7141,9 @@ static int tracing_err_log_open(struct inode *inode, struct file *file)
7105 struct trace_array *tr = inode->i_private; 7141 struct trace_array *tr = inode->i_private;
7106 int ret = 0; 7142 int ret = 0;
7107 7143
7108 if (trace_array_get(tr) < 0) 7144 ret = tracing_check_open_get_tr(tr);
7109 return -ENODEV; 7145 if (ret)
7146 return ret;
7110 7147
7111 /* If this file was opened for write, then erase contents */ 7148 /* If this file was opened for write, then erase contents */
7112 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) 7149 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC))
@@ -7157,11 +7194,9 @@ static int tracing_buffers_open(struct inode *inode, struct file *filp)
7157 struct ftrace_buffer_info *info; 7194 struct ftrace_buffer_info *info;
7158 int ret; 7195 int ret;
7159 7196
7160 if (tracing_disabled) 7197 ret = tracing_check_open_get_tr(tr);
7161 return -ENODEV; 7198 if (ret)
7162 7199 return ret;
7163 if (trace_array_get(tr) < 0)
7164 return -ENODEV;
7165 7200
7166 info = kzalloc(sizeof(*info), GFP_KERNEL); 7201 info = kzalloc(sizeof(*info), GFP_KERNEL);
7167 if (!info) { 7202 if (!info) {
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index f801d154ff6a..d685c61085c0 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -338,6 +338,7 @@ extern struct mutex trace_types_lock;
338 338
339extern int trace_array_get(struct trace_array *tr); 339extern int trace_array_get(struct trace_array *tr);
340extern void trace_array_put(struct trace_array *tr); 340extern void trace_array_put(struct trace_array *tr);
341extern int tracing_check_open_get_tr(struct trace_array *tr);
341 342
342extern int tracing_set_time_stamp_abs(struct trace_array *tr, bool abs); 343extern int tracing_set_time_stamp_abs(struct trace_array *tr, bool abs);
343extern int tracing_set_clock(struct trace_array *tr, const char *clockstr); 344extern int tracing_set_clock(struct trace_array *tr, const char *clockstr);
@@ -681,6 +682,7 @@ void tracing_reset_online_cpus(struct trace_buffer *buf);
681void tracing_reset_current(int cpu); 682void tracing_reset_current(int cpu);
682void tracing_reset_all_online_cpus(void); 683void tracing_reset_all_online_cpus(void);
683int tracing_open_generic(struct inode *inode, struct file *filp); 684int tracing_open_generic(struct inode *inode, struct file *filp);
685int tracing_open_generic_tr(struct inode *inode, struct file *filp);
684bool tracing_is_disabled(void); 686bool tracing_is_disabled(void);
685bool tracer_tracing_is_on(struct trace_array *tr); 687bool tracer_tracing_is_on(struct trace_array *tr);
686void tracer_tracing_on(struct trace_array *tr); 688void tracer_tracing_on(struct trace_array *tr);
diff --git a/kernel/trace/trace_dynevent.c b/kernel/trace/trace_dynevent.c
index a41fed46c285..89779eb84a07 100644
--- a/kernel/trace/trace_dynevent.c
+++ b/kernel/trace/trace_dynevent.c
@@ -174,6 +174,10 @@ static int dyn_event_open(struct inode *inode, struct file *file)
174{ 174{
175 int ret; 175 int ret;
176 176
177 ret = tracing_check_open_get_tr(NULL);
178 if (ret)
179 return ret;
180
177 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) { 181 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) {
178 ret = dyn_events_release_all(NULL); 182 ret = dyn_events_release_all(NULL);
179 if (ret < 0) 183 if (ret < 0)
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index b89cdfe20bc1..fba87d10f0c1 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -12,6 +12,7 @@
12#define pr_fmt(fmt) fmt 12#define pr_fmt(fmt) fmt
13 13
14#include <linux/workqueue.h> 14#include <linux/workqueue.h>
15#include <linux/security.h>
15#include <linux/spinlock.h> 16#include <linux/spinlock.h>
16#include <linux/kthread.h> 17#include <linux/kthread.h>
17#include <linux/tracefs.h> 18#include <linux/tracefs.h>
@@ -1294,6 +1295,8 @@ static int trace_format_open(struct inode *inode, struct file *file)
1294 struct seq_file *m; 1295 struct seq_file *m;
1295 int ret; 1296 int ret;
1296 1297
1298 /* Do we want to hide event format files on tracefs lockdown? */
1299
1297 ret = seq_open(file, &trace_format_seq_ops); 1300 ret = seq_open(file, &trace_format_seq_ops);
1298 if (ret < 0) 1301 if (ret < 0)
1299 return ret; 1302 return ret;
@@ -1440,28 +1443,17 @@ static int system_tr_open(struct inode *inode, struct file *filp)
1440 struct trace_array *tr = inode->i_private; 1443 struct trace_array *tr = inode->i_private;
1441 int ret; 1444 int ret;
1442 1445
1443 if (tracing_is_disabled())
1444 return -ENODEV;
1445
1446 if (trace_array_get(tr) < 0)
1447 return -ENODEV;
1448
1449 /* Make a temporary dir that has no system but points to tr */ 1446 /* Make a temporary dir that has no system but points to tr */
1450 dir = kzalloc(sizeof(*dir), GFP_KERNEL); 1447 dir = kzalloc(sizeof(*dir), GFP_KERNEL);
1451 if (!dir) { 1448 if (!dir)
1452 trace_array_put(tr);
1453 return -ENOMEM; 1449 return -ENOMEM;
1454 }
1455 1450
1456 dir->tr = tr; 1451 ret = tracing_open_generic_tr(inode, filp);
1457
1458 ret = tracing_open_generic(inode, filp);
1459 if (ret < 0) { 1452 if (ret < 0) {
1460 trace_array_put(tr);
1461 kfree(dir); 1453 kfree(dir);
1462 return ret; 1454 return ret;
1463 } 1455 }
1464 1456 dir->tr = tr;
1465 filp->private_data = dir; 1457 filp->private_data = dir;
1466 1458
1467 return 0; 1459 return 0;
@@ -1771,6 +1763,10 @@ ftrace_event_open(struct inode *inode, struct file *file,
1771 struct seq_file *m; 1763 struct seq_file *m;
1772 int ret; 1764 int ret;
1773 1765
1766 ret = security_locked_down(LOCKDOWN_TRACEFS);
1767 if (ret)
1768 return ret;
1769
1774 ret = seq_open(file, seq_ops); 1770 ret = seq_open(file, seq_ops);
1775 if (ret < 0) 1771 if (ret < 0)
1776 return ret; 1772 return ret;
@@ -1795,6 +1791,7 @@ ftrace_event_avail_open(struct inode *inode, struct file *file)
1795{ 1791{
1796 const struct seq_operations *seq_ops = &show_event_seq_ops; 1792 const struct seq_operations *seq_ops = &show_event_seq_ops;
1797 1793
1794 /* Checks for tracefs lockdown */
1798 return ftrace_event_open(inode, file, seq_ops); 1795 return ftrace_event_open(inode, file, seq_ops);
1799} 1796}
1800 1797
@@ -1805,8 +1802,9 @@ ftrace_event_set_open(struct inode *inode, struct file *file)
1805 struct trace_array *tr = inode->i_private; 1802 struct trace_array *tr = inode->i_private;
1806 int ret; 1803 int ret;
1807 1804
1808 if (trace_array_get(tr) < 0) 1805 ret = tracing_check_open_get_tr(tr);
1809 return -ENODEV; 1806 if (ret)
1807 return ret;
1810 1808
1811 if ((file->f_mode & FMODE_WRITE) && 1809 if ((file->f_mode & FMODE_WRITE) &&
1812 (file->f_flags & O_TRUNC)) 1810 (file->f_flags & O_TRUNC))
@@ -1825,8 +1823,9 @@ ftrace_event_set_pid_open(struct inode *inode, struct file *file)
1825 struct trace_array *tr = inode->i_private; 1823 struct trace_array *tr = inode->i_private;
1826 int ret; 1824 int ret;
1827 1825
1828 if (trace_array_get(tr) < 0) 1826 ret = tracing_check_open_get_tr(tr);
1829 return -ENODEV; 1827 if (ret)
1828 return ret;
1830 1829
1831 if ((file->f_mode & FMODE_WRITE) && 1830 if ((file->f_mode & FMODE_WRITE) &&
1832 (file->f_flags & O_TRUNC)) 1831 (file->f_flags & O_TRUNC))
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 9468bd8d44a2..57648c5aa679 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -7,6 +7,7 @@
7 7
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/kallsyms.h> 9#include <linux/kallsyms.h>
10#include <linux/security.h>
10#include <linux/mutex.h> 11#include <linux/mutex.h>
11#include <linux/slab.h> 12#include <linux/slab.h>
12#include <linux/stacktrace.h> 13#include <linux/stacktrace.h>
@@ -1448,6 +1449,10 @@ static int synth_events_open(struct inode *inode, struct file *file)
1448{ 1449{
1449 int ret; 1450 int ret;
1450 1451
1452 ret = security_locked_down(LOCKDOWN_TRACEFS);
1453 if (ret)
1454 return ret;
1455
1451 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) { 1456 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) {
1452 ret = dyn_events_release_all(&synth_event_ops); 1457 ret = dyn_events_release_all(&synth_event_ops);
1453 if (ret < 0) 1458 if (ret < 0)
@@ -1680,7 +1685,7 @@ static int save_hist_vars(struct hist_trigger_data *hist_data)
1680 if (var_data) 1685 if (var_data)
1681 return 0; 1686 return 0;
1682 1687
1683 if (trace_array_get(tr) < 0) 1688 if (tracing_check_open_get_tr(tr))
1684 return -ENODEV; 1689 return -ENODEV;
1685 1690
1686 var_data = kzalloc(sizeof(*var_data), GFP_KERNEL); 1691 var_data = kzalloc(sizeof(*var_data), GFP_KERNEL);
@@ -5515,6 +5520,12 @@ static int hist_show(struct seq_file *m, void *v)
5515 5520
5516static int event_hist_open(struct inode *inode, struct file *file) 5521static int event_hist_open(struct inode *inode, struct file *file)
5517{ 5522{
5523 int ret;
5524
5525 ret = security_locked_down(LOCKDOWN_TRACEFS);
5526 if (ret)
5527 return ret;
5528
5518 return single_open(file, hist_show, file); 5529 return single_open(file, hist_show, file);
5519} 5530}
5520 5531
diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_events_trigger.c
index 2a2912cb4533..2cd53ca21b51 100644
--- a/kernel/trace/trace_events_trigger.c
+++ b/kernel/trace/trace_events_trigger.c
@@ -5,6 +5,7 @@
5 * Copyright (C) 2013 Tom Zanussi <tom.zanussi@linux.intel.com> 5 * Copyright (C) 2013 Tom Zanussi <tom.zanussi@linux.intel.com>
6 */ 6 */
7 7
8#include <linux/security.h>
8#include <linux/module.h> 9#include <linux/module.h>
9#include <linux/ctype.h> 10#include <linux/ctype.h>
10#include <linux/mutex.h> 11#include <linux/mutex.h>
@@ -173,7 +174,11 @@ static const struct seq_operations event_triggers_seq_ops = {
173 174
174static int event_trigger_regex_open(struct inode *inode, struct file *file) 175static int event_trigger_regex_open(struct inode *inode, struct file *file)
175{ 176{
176 int ret = 0; 177 int ret;
178
179 ret = security_locked_down(LOCKDOWN_TRACEFS);
180 if (ret)
181 return ret;
177 182
178 mutex_lock(&event_mutex); 183 mutex_lock(&event_mutex);
179 184
@@ -292,6 +297,7 @@ event_trigger_write(struct file *filp, const char __user *ubuf,
292static int 297static int
293event_trigger_open(struct inode *inode, struct file *filp) 298event_trigger_open(struct inode *inode, struct file *filp)
294{ 299{
300 /* Checks for tracefs lockdown */
295 return event_trigger_regex_open(inode, filp); 301 return event_trigger_regex_open(inode, filp);
296} 302}
297 303
diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c
index fa95139445b2..862f4b0139fc 100644
--- a/kernel/trace/trace_hwlat.c
+++ b/kernel/trace/trace_hwlat.c
@@ -150,7 +150,7 @@ void trace_hwlat_callback(bool enter)
150 if (enter) 150 if (enter)
151 nmi_ts_start = time_get(); 151 nmi_ts_start = time_get();
152 else 152 else
153 nmi_total_ts = time_get() - nmi_ts_start; 153 nmi_total_ts += time_get() - nmi_ts_start;
154 } 154 }
155 155
156 if (enter) 156 if (enter)
@@ -256,6 +256,8 @@ static int get_sample(void)
256 /* Keep a running maximum ever recorded hardware latency */ 256 /* Keep a running maximum ever recorded hardware latency */
257 if (sample > tr->max_latency) 257 if (sample > tr->max_latency)
258 tr->max_latency = sample; 258 tr->max_latency = sample;
259 if (outer_sample > tr->max_latency)
260 tr->max_latency = outer_sample;
259 } 261 }
260 262
261out: 263out:
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 324ffbea3556..1552a95c743b 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -7,11 +7,11 @@
7 */ 7 */
8#define pr_fmt(fmt) "trace_kprobe: " fmt 8#define pr_fmt(fmt) "trace_kprobe: " fmt
9 9
10#include <linux/security.h>
10#include <linux/module.h> 11#include <linux/module.h>
11#include <linux/uaccess.h> 12#include <linux/uaccess.h>
12#include <linux/rculist.h> 13#include <linux/rculist.h>
13#include <linux/error-injection.h> 14#include <linux/error-injection.h>
14#include <linux/security.h>
15 15
16#include <asm/setup.h> /* for COMMAND_LINE_SIZE */ 16#include <asm/setup.h> /* for COMMAND_LINE_SIZE */
17 17
@@ -936,6 +936,10 @@ static int probes_open(struct inode *inode, struct file *file)
936{ 936{
937 int ret; 937 int ret;
938 938
939 ret = security_locked_down(LOCKDOWN_TRACEFS);
940 if (ret)
941 return ret;
942
939 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) { 943 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) {
940 ret = dyn_events_release_all(&trace_kprobe_ops); 944 ret = dyn_events_release_all(&trace_kprobe_ops);
941 if (ret < 0) 945 if (ret < 0)
@@ -988,6 +992,12 @@ static const struct seq_operations profile_seq_op = {
988 992
989static int profile_open(struct inode *inode, struct file *file) 993static int profile_open(struct inode *inode, struct file *file)
990{ 994{
995 int ret;
996
997 ret = security_locked_down(LOCKDOWN_TRACEFS);
998 if (ret)
999 return ret;
1000
991 return seq_open(file, &profile_seq_op); 1001 return seq_open(file, &profile_seq_op);
992} 1002}
993 1003
diff --git a/kernel/trace/trace_printk.c b/kernel/trace/trace_printk.c
index c3fd849d4a8f..d4e31e969206 100644
--- a/kernel/trace/trace_printk.c
+++ b/kernel/trace/trace_printk.c
@@ -6,6 +6,7 @@
6 * 6 *
7 */ 7 */
8#include <linux/seq_file.h> 8#include <linux/seq_file.h>
9#include <linux/security.h>
9#include <linux/uaccess.h> 10#include <linux/uaccess.h>
10#include <linux/kernel.h> 11#include <linux/kernel.h>
11#include <linux/ftrace.h> 12#include <linux/ftrace.h>
@@ -348,6 +349,12 @@ static const struct seq_operations show_format_seq_ops = {
348static int 349static int
349ftrace_formats_open(struct inode *inode, struct file *file) 350ftrace_formats_open(struct inode *inode, struct file *file)
350{ 351{
352 int ret;
353
354 ret = security_locked_down(LOCKDOWN_TRACEFS);
355 if (ret)
356 return ret;
357
351 return seq_open(file, &show_format_seq_ops); 358 return seq_open(file, &show_format_seq_ops);
352} 359}
353 360
diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
index ec9a34a97129..4df9a209f7ca 100644
--- a/kernel/trace/trace_stack.c
+++ b/kernel/trace/trace_stack.c
@@ -5,6 +5,7 @@
5 */ 5 */
6#include <linux/sched/task_stack.h> 6#include <linux/sched/task_stack.h>
7#include <linux/stacktrace.h> 7#include <linux/stacktrace.h>
8#include <linux/security.h>
8#include <linux/kallsyms.h> 9#include <linux/kallsyms.h>
9#include <linux/seq_file.h> 10#include <linux/seq_file.h>
10#include <linux/spinlock.h> 11#include <linux/spinlock.h>
@@ -470,6 +471,12 @@ static const struct seq_operations stack_trace_seq_ops = {
470 471
471static int stack_trace_open(struct inode *inode, struct file *file) 472static int stack_trace_open(struct inode *inode, struct file *file)
472{ 473{
474 int ret;
475
476 ret = security_locked_down(LOCKDOWN_TRACEFS);
477 if (ret)
478 return ret;
479
473 return seq_open(file, &stack_trace_seq_ops); 480 return seq_open(file, &stack_trace_seq_ops);
474} 481}
475 482
@@ -487,6 +494,7 @@ stack_trace_filter_open(struct inode *inode, struct file *file)
487{ 494{
488 struct ftrace_ops *ops = inode->i_private; 495 struct ftrace_ops *ops = inode->i_private;
489 496
497 /* Checks for tracefs lockdown */
490 return ftrace_regex_open(ops, FTRACE_ITER_FILTER, 498 return ftrace_regex_open(ops, FTRACE_ITER_FILTER,
491 inode, file); 499 inode, file);
492} 500}
diff --git a/kernel/trace/trace_stat.c b/kernel/trace/trace_stat.c
index 75bf1bcb4a8a..9ab0a1a7ad5e 100644
--- a/kernel/trace/trace_stat.c
+++ b/kernel/trace/trace_stat.c
@@ -9,7 +9,7 @@
9 * 9 *
10 */ 10 */
11 11
12 12#include <linux/security.h>
13#include <linux/list.h> 13#include <linux/list.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/rbtree.h> 15#include <linux/rbtree.h>
@@ -238,6 +238,10 @@ static int tracing_stat_open(struct inode *inode, struct file *file)
238 struct seq_file *m; 238 struct seq_file *m;
239 struct stat_session *session = inode->i_private; 239 struct stat_session *session = inode->i_private;
240 240
241 ret = security_locked_down(LOCKDOWN_TRACEFS);
242 if (ret)
243 return ret;
244
241 ret = stat_seq_init(session); 245 ret = stat_seq_init(session);
242 if (ret) 246 if (ret)
243 return ret; 247 return ret;
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index dd884341f5c5..352073d36585 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -7,6 +7,7 @@
7 */ 7 */
8#define pr_fmt(fmt) "trace_uprobe: " fmt 8#define pr_fmt(fmt) "trace_uprobe: " fmt
9 9
10#include <linux/security.h>
10#include <linux/ctype.h> 11#include <linux/ctype.h>
11#include <linux/module.h> 12#include <linux/module.h>
12#include <linux/uaccess.h> 13#include <linux/uaccess.h>
@@ -769,6 +770,10 @@ static int probes_open(struct inode *inode, struct file *file)
769{ 770{
770 int ret; 771 int ret;
771 772
773 ret = security_locked_down(LOCKDOWN_TRACEFS);
774 if (ret)
775 return ret;
776
772 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) { 777 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) {
773 ret = dyn_events_release_all(&trace_uprobe_ops); 778 ret = dyn_events_release_all(&trace_uprobe_ops);
774 if (ret) 779 if (ret)
@@ -818,6 +823,12 @@ static const struct seq_operations profile_seq_op = {
818 823
819static int profile_open(struct inode *inode, struct file *file) 824static int profile_open(struct inode *inode, struct file *file)
820{ 825{
826 int ret;
827
828 ret = security_locked_down(LOCKDOWN_TRACEFS);
829 if (ret)
830 return ret;
831
821 return seq_open(file, &profile_seq_op); 832 return seq_open(file, &profile_seq_op);
822} 833}
823 834
diff --git a/lib/generic-radix-tree.c b/lib/generic-radix-tree.c
index ae25e2fa2187..f25eb111c051 100644
--- a/lib/generic-radix-tree.c
+++ b/lib/generic-radix-tree.c
@@ -2,6 +2,7 @@
2#include <linux/export.h> 2#include <linux/export.h>
3#include <linux/generic-radix-tree.h> 3#include <linux/generic-radix-tree.h>
4#include <linux/gfp.h> 4#include <linux/gfp.h>
5#include <linux/kmemleak.h>
5 6
6#define GENRADIX_ARY (PAGE_SIZE / sizeof(struct genradix_node *)) 7#define GENRADIX_ARY (PAGE_SIZE / sizeof(struct genradix_node *))
7#define GENRADIX_ARY_SHIFT ilog2(GENRADIX_ARY) 8#define GENRADIX_ARY_SHIFT ilog2(GENRADIX_ARY)
@@ -75,6 +76,27 @@ void *__genradix_ptr(struct __genradix *radix, size_t offset)
75} 76}
76EXPORT_SYMBOL(__genradix_ptr); 77EXPORT_SYMBOL(__genradix_ptr);
77 78
79static inline struct genradix_node *genradix_alloc_node(gfp_t gfp_mask)
80{
81 struct genradix_node *node;
82
83 node = (struct genradix_node *)__get_free_page(gfp_mask|__GFP_ZERO);
84
85 /*
86 * We're using pages (not slab allocations) directly for kernel data
87 * structures, so we need to explicitly inform kmemleak of them in order
88 * to avoid false positive memory leak reports.
89 */
90 kmemleak_alloc(node, PAGE_SIZE, 1, gfp_mask);
91 return node;
92}
93
94static inline void genradix_free_node(struct genradix_node *node)
95{
96 kmemleak_free(node);
97 free_page((unsigned long)node);
98}
99
78/* 100/*
79 * Returns pointer to the specified byte @offset within @radix, allocating it if 101 * Returns pointer to the specified byte @offset within @radix, allocating it if
80 * necessary - newly allocated slots are always zeroed out: 102 * necessary - newly allocated slots are always zeroed out:
@@ -97,8 +119,7 @@ void *__genradix_ptr_alloc(struct __genradix *radix, size_t offset,
97 break; 119 break;
98 120
99 if (!new_node) { 121 if (!new_node) {
100 new_node = (void *) 122 new_node = genradix_alloc_node(gfp_mask);
101 __get_free_page(gfp_mask|__GFP_ZERO);
102 if (!new_node) 123 if (!new_node)
103 return NULL; 124 return NULL;
104 } 125 }
@@ -121,8 +142,7 @@ void *__genradix_ptr_alloc(struct __genradix *radix, size_t offset,
121 n = READ_ONCE(*p); 142 n = READ_ONCE(*p);
122 if (!n) { 143 if (!n) {
123 if (!new_node) { 144 if (!new_node) {
124 new_node = (void *) 145 new_node = genradix_alloc_node(gfp_mask);
125 __get_free_page(gfp_mask|__GFP_ZERO);
126 if (!new_node) 146 if (!new_node)
127 return NULL; 147 return NULL;
128 } 148 }
@@ -133,7 +153,7 @@ void *__genradix_ptr_alloc(struct __genradix *radix, size_t offset,
133 } 153 }
134 154
135 if (new_node) 155 if (new_node)
136 free_page((unsigned long) new_node); 156 genradix_free_node(new_node);
137 157
138 return &n->data[offset]; 158 return &n->data[offset];
139} 159}
@@ -191,7 +211,7 @@ static void genradix_free_recurse(struct genradix_node *n, unsigned level)
191 genradix_free_recurse(n->children[i], level - 1); 211 genradix_free_recurse(n->children[i], level - 1);
192 } 212 }
193 213
194 free_page((unsigned long) n); 214 genradix_free_node(n);
195} 215}
196 216
197int __genradix_prealloc(struct __genradix *radix, size_t size, 217int __genradix_prealloc(struct __genradix *radix, size_t size,
diff --git a/lib/string.c b/lib/string.c
index cd7a10c19210..08ec58cc673b 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -748,27 +748,6 @@ void *memset(void *s, int c, size_t count)
748EXPORT_SYMBOL(memset); 748EXPORT_SYMBOL(memset);
749#endif 749#endif
750 750
751/**
752 * memzero_explicit - Fill a region of memory (e.g. sensitive
753 * keying data) with 0s.
754 * @s: Pointer to the start of the area.
755 * @count: The size of the area.
756 *
757 * Note: usually using memset() is just fine (!), but in cases
758 * where clearing out _local_ data at the end of a scope is
759 * necessary, memzero_explicit() should be used instead in
760 * order to prevent the compiler from optimising away zeroing.
761 *
762 * memzero_explicit() doesn't need an arch-specific version as
763 * it just invokes the one of memset() implicitly.
764 */
765void memzero_explicit(void *s, size_t count)
766{
767 memset(s, 0, count);
768 barrier_data(s);
769}
770EXPORT_SYMBOL(memzero_explicit);
771
772#ifndef __HAVE_ARCH_MEMSET16 751#ifndef __HAVE_ARCH_MEMSET16
773/** 752/**
774 * memset16() - Fill a memory area with a uint16_t 753 * memset16() - Fill a memory area with a uint16_t
diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
index 28ff554a1be8..6c0005d5dd5c 100644
--- a/lib/strnlen_user.c
+++ b/lib/strnlen_user.c
@@ -3,16 +3,10 @@
3#include <linux/export.h> 3#include <linux/export.h>
4#include <linux/uaccess.h> 4#include <linux/uaccess.h>
5#include <linux/mm.h> 5#include <linux/mm.h>
6#include <linux/bitops.h>
6 7
7#include <asm/word-at-a-time.h> 8#include <asm/word-at-a-time.h>
8 9
9/* Set bits in the first 'n' bytes when loaded from memory */
10#ifdef __LITTLE_ENDIAN
11# define aligned_byte_mask(n) ((1ul << 8*(n))-1)
12#else
13# define aligned_byte_mask(n) (~0xfful << (BITS_PER_LONG - 8 - 8*(n)))
14#endif
15
16/* 10/*
17 * Do a strnlen, return length of string *with* final '\0'. 11 * Do a strnlen, return length of string *with* final '\0'.
18 * 'count' is the user-supplied count, while 'max' is the 12 * 'count' is the user-supplied count, while 'max' is the
diff --git a/lib/test_meminit.c b/lib/test_meminit.c
index 9729f271d150..9742e5cb853a 100644
--- a/lib/test_meminit.c
+++ b/lib/test_meminit.c
@@ -297,6 +297,32 @@ out:
297 return 1; 297 return 1;
298} 298}
299 299
300static int __init do_kmem_cache_size_bulk(int size, int *total_failures)
301{
302 struct kmem_cache *c;
303 int i, iter, maxiter = 1024;
304 int num, bytes;
305 bool fail = false;
306 void *objects[10];
307
308 c = kmem_cache_create("test_cache", size, size, 0, NULL);
309 for (iter = 0; (iter < maxiter) && !fail; iter++) {
310 num = kmem_cache_alloc_bulk(c, GFP_KERNEL, ARRAY_SIZE(objects),
311 objects);
312 for (i = 0; i < num; i++) {
313 bytes = count_nonzero_bytes(objects[i], size);
314 if (bytes)
315 fail = true;
316 fill_with_garbage(objects[i], size);
317 }
318
319 if (num)
320 kmem_cache_free_bulk(c, num, objects);
321 }
322 *total_failures += fail;
323 return 1;
324}
325
300/* 326/*
301 * Test kmem_cache allocation by creating caches of different sizes, with and 327 * Test kmem_cache allocation by creating caches of different sizes, with and
302 * without constructors, with and without SLAB_TYPESAFE_BY_RCU. 328 * without constructors, with and without SLAB_TYPESAFE_BY_RCU.
@@ -318,6 +344,7 @@ static int __init test_kmemcache(int *total_failures)
318 num_tests += do_kmem_cache_size(size, ctor, rcu, zero, 344 num_tests += do_kmem_cache_size(size, ctor, rcu, zero,
319 &failures); 345 &failures);
320 } 346 }
347 num_tests += do_kmem_cache_size_bulk(size, &failures);
321 } 348 }
322 REPORT_FAILURES_IN_FN(); 349 REPORT_FAILURES_IN_FN();
323 *total_failures += failures; 350 *total_failures += failures;
diff --git a/lib/test_user_copy.c b/lib/test_user_copy.c
index 67bcd5dfd847..5ff04d8fe971 100644
--- a/lib/test_user_copy.c
+++ b/lib/test_user_copy.c
@@ -31,14 +31,152 @@
31# define TEST_U64 31# define TEST_U64
32#endif 32#endif
33 33
34#define test(condition, msg) \ 34#define test(condition, msg, ...) \
35({ \ 35({ \
36 int cond = (condition); \ 36 int cond = (condition); \
37 if (cond) \ 37 if (cond) \
38 pr_warn("%s\n", msg); \ 38 pr_warn("[%d] " msg "\n", __LINE__, ##__VA_ARGS__); \
39 cond; \ 39 cond; \
40}) 40})
41 41
42static bool is_zeroed(void *from, size_t size)
43{
44 return memchr_inv(from, 0x0, size) == NULL;
45}
46
47static int test_check_nonzero_user(char *kmem, char __user *umem, size_t size)
48{
49 int ret = 0;
50 size_t start, end, i, zero_start, zero_end;
51
52 if (test(size < 2 * PAGE_SIZE, "buffer too small"))
53 return -EINVAL;
54
55 /*
56 * We want to cross a page boundary to exercise the code more
57 * effectively. We also don't want to make the size we scan too large,
58 * otherwise the test can take a long time and cause soft lockups. So
59 * scan a 1024 byte region across the page boundary.
60 */
61 size = 1024;
62 start = PAGE_SIZE - (size / 2);
63
64 kmem += start;
65 umem += start;
66
67 zero_start = size / 4;
68 zero_end = size - zero_start;
69
70 /*
71 * We conduct a series of check_nonzero_user() tests on a block of
72 * memory with the following byte-pattern (trying every possible
73 * [start,end] pair):
74 *
75 * [ 00 ff 00 ff ... 00 00 00 00 ... ff 00 ff 00 ]
76 *
77 * And we verify that check_nonzero_user() acts identically to
78 * memchr_inv().
79 */
80
81 memset(kmem, 0x0, size);
82 for (i = 1; i < zero_start; i += 2)
83 kmem[i] = 0xff;
84 for (i = zero_end; i < size; i += 2)
85 kmem[i] = 0xff;
86
87 ret |= test(copy_to_user(umem, kmem, size),
88 "legitimate copy_to_user failed");
89
90 for (start = 0; start <= size; start++) {
91 for (end = start; end <= size; end++) {
92 size_t len = end - start;
93 int retval = check_zeroed_user(umem + start, len);
94 int expected = is_zeroed(kmem + start, len);
95
96 ret |= test(retval != expected,
97 "check_nonzero_user(=%d) != memchr_inv(=%d) mismatch (start=%zu, end=%zu)",
98 retval, expected, start, end);
99 }
100 }
101
102 return ret;
103}
104
105static int test_copy_struct_from_user(char *kmem, char __user *umem,
106 size_t size)
107{
108 int ret = 0;
109 char *umem_src = NULL, *expected = NULL;
110 size_t ksize, usize;
111
112 umem_src = kmalloc(size, GFP_KERNEL);
113 ret = test(umem_src == NULL, "kmalloc failed");
114 if (ret)
115 goto out_free;
116
117 expected = kmalloc(size, GFP_KERNEL);
118 ret = test(expected == NULL, "kmalloc failed");
119 if (ret)
120 goto out_free;
121
122 /* Fill umem with a fixed byte pattern. */
123 memset(umem_src, 0x3e, size);
124 ret |= test(copy_to_user(umem, umem_src, size),
125 "legitimate copy_to_user failed");
126
127 /* Check basic case -- (usize == ksize). */
128 ksize = size;
129 usize = size;
130
131 memcpy(expected, umem_src, ksize);
132
133 memset(kmem, 0x0, size);
134 ret |= test(copy_struct_from_user(kmem, ksize, umem, usize),
135 "copy_struct_from_user(usize == ksize) failed");
136 ret |= test(memcmp(kmem, expected, ksize),
137 "copy_struct_from_user(usize == ksize) gives unexpected copy");
138
139 /* Old userspace case -- (usize < ksize). */
140 ksize = size;
141 usize = size / 2;
142
143 memcpy(expected, umem_src, usize);
144 memset(expected + usize, 0x0, ksize - usize);
145
146 memset(kmem, 0x0, size);
147 ret |= test(copy_struct_from_user(kmem, ksize, umem, usize),
148 "copy_struct_from_user(usize < ksize) failed");
149 ret |= test(memcmp(kmem, expected, ksize),
150 "copy_struct_from_user(usize < ksize) gives unexpected copy");
151
152 /* New userspace (-E2BIG) case -- (usize > ksize). */
153 ksize = size / 2;
154 usize = size;
155
156 memset(kmem, 0x0, size);
157 ret |= test(copy_struct_from_user(kmem, ksize, umem, usize) != -E2BIG,
158 "copy_struct_from_user(usize > ksize) didn't give E2BIG");
159
160 /* New userspace (success) case -- (usize > ksize). */
161 ksize = size / 2;
162 usize = size;
163
164 memcpy(expected, umem_src, ksize);
165 ret |= test(clear_user(umem + ksize, usize - ksize),
166 "legitimate clear_user failed");
167
168 memset(kmem, 0x0, size);
169 ret |= test(copy_struct_from_user(kmem, ksize, umem, usize),
170 "copy_struct_from_user(usize > ksize) failed");
171 ret |= test(memcmp(kmem, expected, ksize),
172 "copy_struct_from_user(usize > ksize) gives unexpected copy");
173
174out_free:
175 kfree(expected);
176 kfree(umem_src);
177 return ret;
178}
179
42static int __init test_user_copy_init(void) 180static int __init test_user_copy_init(void)
43{ 181{
44 int ret = 0; 182 int ret = 0;
@@ -106,6 +244,11 @@ static int __init test_user_copy_init(void)
106#endif 244#endif
107#undef test_legit 245#undef test_legit
108 246
247 /* Test usage of check_nonzero_user(). */
248 ret |= test_check_nonzero_user(kmem, usermem, 2 * PAGE_SIZE);
249 /* Test usage of copy_struct_from_user(). */
250 ret |= test_copy_struct_from_user(kmem, usermem, 2 * PAGE_SIZE);
251
109 /* 252 /*
110 * Invalid usage: none of these copies should succeed. 253 * Invalid usage: none of these copies should succeed.
111 */ 254 */
diff --git a/lib/textsearch.c b/lib/textsearch.c
index 4f16eec5d554..f68dea8806be 100644
--- a/lib/textsearch.c
+++ b/lib/textsearch.c
@@ -89,9 +89,9 @@
89 * goto errout; 89 * goto errout;
90 * } 90 * }
91 * 91 *
92 * pos = textsearch_find_continuous(conf, \&state, example, strlen(example)); 92 * pos = textsearch_find_continuous(conf, &state, example, strlen(example));
93 * if (pos != UINT_MAX) 93 * if (pos != UINT_MAX)
94 * panic("Oh my god, dancing chickens at \%d\n", pos); 94 * panic("Oh my god, dancing chickens at %d\n", pos);
95 * 95 *
96 * textsearch_destroy(conf); 96 * textsearch_destroy(conf);
97 */ 97 */
diff --git a/lib/usercopy.c b/lib/usercopy.c
index c2bfbcaeb3dc..cbb4d9ec00f2 100644
--- a/lib/usercopy.c
+++ b/lib/usercopy.c
@@ -1,5 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0
2#include <linux/uaccess.h> 2#include <linux/uaccess.h>
3#include <linux/bitops.h>
3 4
4/* out-of-line parts */ 5/* out-of-line parts */
5 6
@@ -31,3 +32,57 @@ unsigned long _copy_to_user(void __user *to, const void *from, unsigned long n)
31} 32}
32EXPORT_SYMBOL(_copy_to_user); 33EXPORT_SYMBOL(_copy_to_user);
33#endif 34#endif
35
36/**
37 * check_zeroed_user: check if a userspace buffer only contains zero bytes
38 * @from: Source address, in userspace.
39 * @size: Size of buffer.
40 *
41 * This is effectively shorthand for "memchr_inv(from, 0, size) == NULL" for
42 * userspace addresses (and is more efficient because we don't care where the
43 * first non-zero byte is).
44 *
45 * Returns:
46 * * 0: There were non-zero bytes present in the buffer.
47 * * 1: The buffer was full of zero bytes.
48 * * -EFAULT: access to userspace failed.
49 */
50int check_zeroed_user(const void __user *from, size_t size)
51{
52 unsigned long val;
53 uintptr_t align = (uintptr_t) from % sizeof(unsigned long);
54
55 if (unlikely(size == 0))
56 return 1;
57
58 from -= align;
59 size += align;
60
61 if (!user_access_begin(from, size))
62 return -EFAULT;
63
64 unsafe_get_user(val, (unsigned long __user *) from, err_fault);
65 if (align)
66 val &= ~aligned_byte_mask(align);
67
68 while (size > sizeof(unsigned long)) {
69 if (unlikely(val))
70 goto done;
71
72 from += sizeof(unsigned long);
73 size -= sizeof(unsigned long);
74
75 unsafe_get_user(val, (unsigned long __user *) from, err_fault);
76 }
77
78 if (size < sizeof(unsigned long))
79 val &= aligned_byte_mask(size);
80
81done:
82 user_access_end();
83 return (val == 0);
84err_fault:
85 user_access_end();
86 return -EFAULT;
87}
88EXPORT_SYMBOL(check_zeroed_user);
diff --git a/lib/vdso/Kconfig b/lib/vdso/Kconfig
index cc00364bd2c2..9fe698ff62ec 100644
--- a/lib/vdso/Kconfig
+++ b/lib/vdso/Kconfig
@@ -24,13 +24,4 @@ config GENERIC_COMPAT_VDSO
24 help 24 help
25 This config option enables the compat VDSO layer. 25 This config option enables the compat VDSO layer.
26 26
27config CROSS_COMPILE_COMPAT_VDSO
28 string "32 bit Toolchain prefix for compat vDSO"
29 default ""
30 depends on GENERIC_COMPAT_VDSO
31 help
32 Defines the cross-compiler prefix for compiling compat vDSO.
33 If a 64 bit compiler (i.e. x86_64) can compile the VDSO for
34 32 bit, it does not need to define this parameter.
35
36endif 27endif
diff --git a/mm/backing-dev.c b/mm/backing-dev.c
index d9daa3e422d0..c360f6a6c844 100644
--- a/mm/backing-dev.c
+++ b/mm/backing-dev.c
@@ -239,8 +239,8 @@ static int __init default_bdi_init(void)
239{ 239{
240 int err; 240 int err;
241 241
242 bdi_wq = alloc_workqueue("writeback", WQ_MEM_RECLAIM | WQ_FREEZABLE | 242 bdi_wq = alloc_workqueue("writeback", WQ_MEM_RECLAIM | WQ_UNBOUND |
243 WQ_UNBOUND | WQ_SYSFS, 0); 243 WQ_SYSFS, 0);
244 if (!bdi_wq) 244 if (!bdi_wq)
245 return -ENOMEM; 245 return -ENOMEM;
246 246
diff --git a/mm/compaction.c b/mm/compaction.c
index ce08b39d85d4..672d3c78c6ab 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -270,14 +270,15 @@ __reset_isolation_pfn(struct zone *zone, unsigned long pfn, bool check_source,
270 270
271 /* Ensure the start of the pageblock or zone is online and valid */ 271 /* Ensure the start of the pageblock or zone is online and valid */
272 block_pfn = pageblock_start_pfn(pfn); 272 block_pfn = pageblock_start_pfn(pfn);
273 block_page = pfn_to_online_page(max(block_pfn, zone->zone_start_pfn)); 273 block_pfn = max(block_pfn, zone->zone_start_pfn);
274 block_page = pfn_to_online_page(block_pfn);
274 if (block_page) { 275 if (block_page) {
275 page = block_page; 276 page = block_page;
276 pfn = block_pfn; 277 pfn = block_pfn;
277 } 278 }
278 279
279 /* Ensure the end of the pageblock or zone is online and valid */ 280 /* Ensure the end of the pageblock or zone is online and valid */
280 block_pfn += pageblock_nr_pages; 281 block_pfn = pageblock_end_pfn(pfn) - 1;
281 block_pfn = min(block_pfn, zone_end_pfn(zone) - 1); 282 block_pfn = min(block_pfn, zone_end_pfn(zone) - 1);
282 end_page = pfn_to_online_page(block_pfn); 283 end_page = pfn_to_online_page(block_pfn);
283 if (!end_page) 284 if (!end_page)
@@ -303,7 +304,7 @@ __reset_isolation_pfn(struct zone *zone, unsigned long pfn, bool check_source,
303 304
304 page += (1 << PAGE_ALLOC_COSTLY_ORDER); 305 page += (1 << PAGE_ALLOC_COSTLY_ORDER);
305 pfn += (1 << PAGE_ALLOC_COSTLY_ORDER); 306 pfn += (1 << PAGE_ALLOC_COSTLY_ORDER);
306 } while (page < end_page); 307 } while (page <= end_page);
307 308
308 return false; 309 return false;
309} 310}
diff --git a/mm/filemap.c b/mm/filemap.c
index 1146fcfa3215..85b7d087eb45 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -40,6 +40,7 @@
40#include <linux/rmap.h> 40#include <linux/rmap.h>
41#include <linux/delayacct.h> 41#include <linux/delayacct.h>
42#include <linux/psi.h> 42#include <linux/psi.h>
43#include <linux/ramfs.h>
43#include "internal.h" 44#include "internal.h"
44 45
45#define CREATE_TRACE_POINTS 46#define CREATE_TRACE_POINTS
diff --git a/mm/gup.c b/mm/gup.c
index 23a9f9c9d377..8f236a335ae9 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1973,7 +1973,8 @@ static unsigned long hugepte_addr_end(unsigned long addr, unsigned long end,
1973} 1973}
1974 1974
1975static int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr, 1975static int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr,
1976 unsigned long end, int write, struct page **pages, int *nr) 1976 unsigned long end, unsigned int flags,
1977 struct page **pages, int *nr)
1977{ 1978{
1978 unsigned long pte_end; 1979 unsigned long pte_end;
1979 struct page *head, *page; 1980 struct page *head, *page;
@@ -1986,7 +1987,7 @@ static int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr,
1986 1987
1987 pte = READ_ONCE(*ptep); 1988 pte = READ_ONCE(*ptep);
1988 1989
1989 if (!pte_access_permitted(pte, write)) 1990 if (!pte_access_permitted(pte, flags & FOLL_WRITE))
1990 return 0; 1991 return 0;
1991 1992
1992 /* hugepages are never "special" */ 1993 /* hugepages are never "special" */
@@ -2023,7 +2024,7 @@ static int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr,
2023} 2024}
2024 2025
2025static int gup_huge_pd(hugepd_t hugepd, unsigned long addr, 2026static int gup_huge_pd(hugepd_t hugepd, unsigned long addr,
2026 unsigned int pdshift, unsigned long end, int write, 2027 unsigned int pdshift, unsigned long end, unsigned int flags,
2027 struct page **pages, int *nr) 2028 struct page **pages, int *nr)
2028{ 2029{
2029 pte_t *ptep; 2030 pte_t *ptep;
@@ -2033,7 +2034,7 @@ static int gup_huge_pd(hugepd_t hugepd, unsigned long addr,
2033 ptep = hugepte_offset(hugepd, addr, pdshift); 2034 ptep = hugepte_offset(hugepd, addr, pdshift);
2034 do { 2035 do {
2035 next = hugepte_addr_end(addr, end, sz); 2036 next = hugepte_addr_end(addr, end, sz);
2036 if (!gup_hugepte(ptep, sz, addr, end, write, pages, nr)) 2037 if (!gup_hugepte(ptep, sz, addr, end, flags, pages, nr))
2037 return 0; 2038 return 0;
2038 } while (ptep++, addr = next, addr != end); 2039 } while (ptep++, addr = next, addr != end);
2039 2040
@@ -2041,7 +2042,7 @@ static int gup_huge_pd(hugepd_t hugepd, unsigned long addr,
2041} 2042}
2042#else 2043#else
2043static inline int gup_huge_pd(hugepd_t hugepd, unsigned long addr, 2044static inline int gup_huge_pd(hugepd_t hugepd, unsigned long addr,
2044 unsigned pdshift, unsigned long end, int write, 2045 unsigned int pdshift, unsigned long end, unsigned int flags,
2045 struct page **pages, int *nr) 2046 struct page **pages, int *nr)
2046{ 2047{
2047 return 0; 2048 return 0;
@@ -2049,7 +2050,8 @@ static inline int gup_huge_pd(hugepd_t hugepd, unsigned long addr,
2049#endif /* CONFIG_ARCH_HAS_HUGEPD */ 2050#endif /* CONFIG_ARCH_HAS_HUGEPD */
2050 2051
2051static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr, 2052static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr,
2052 unsigned long end, unsigned int flags, struct page **pages, int *nr) 2053 unsigned long end, unsigned int flags,
2054 struct page **pages, int *nr)
2053{ 2055{
2054 struct page *head, *page; 2056 struct page *head, *page;
2055 int refs; 2057 int refs;
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index c5cb6dcd6c69..13cc93785006 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2789,8 +2789,13 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
2789 ds_queue->split_queue_len--; 2789 ds_queue->split_queue_len--;
2790 list_del(page_deferred_list(head)); 2790 list_del(page_deferred_list(head));
2791 } 2791 }
2792 if (mapping) 2792 if (mapping) {
2793 __dec_node_page_state(page, NR_SHMEM_THPS); 2793 if (PageSwapBacked(page))
2794 __dec_node_page_state(page, NR_SHMEM_THPS);
2795 else
2796 __dec_node_page_state(page, NR_FILE_THPS);
2797 }
2798
2794 spin_unlock(&ds_queue->split_queue_lock); 2799 spin_unlock(&ds_queue->split_queue_lock);
2795 __split_huge_page(page, list, end, flags); 2800 __split_huge_page(page, list, end, flags);
2796 if (PageSwapCache(head)) { 2801 if (PageSwapCache(head)) {
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index ef37c85423a5..b45a95363a84 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1084,11 +1084,10 @@ static bool pfn_range_valid_gigantic(struct zone *z,
1084 struct page *page; 1084 struct page *page;
1085 1085
1086 for (i = start_pfn; i < end_pfn; i++) { 1086 for (i = start_pfn; i < end_pfn; i++) {
1087 if (!pfn_valid(i)) 1087 page = pfn_to_online_page(i);
1088 if (!page)
1088 return false; 1089 return false;
1089 1090
1090 page = pfn_to_page(i);
1091
1092 if (page_zone(page) != z) 1091 if (page_zone(page) != z)
1093 return false; 1092 return false;
1094 1093
diff --git a/mm/init-mm.c b/mm/init-mm.c
index fb1e15028ef0..19603302a77f 100644
--- a/mm/init-mm.c
+++ b/mm/init-mm.c
@@ -5,6 +5,7 @@
5#include <linux/spinlock.h> 5#include <linux/spinlock.h>
6#include <linux/list.h> 6#include <linux/list.h>
7#include <linux/cpumask.h> 7#include <linux/cpumask.h>
8#include <linux/mman.h>
8 9
9#include <linux/atomic.h> 10#include <linux/atomic.h>
10#include <linux/user_namespace.h> 11#include <linux/user_namespace.h>
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 03a8d84badad..244607663363 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -527,6 +527,16 @@ static struct kmemleak_object *find_and_get_object(unsigned long ptr, int alias)
527} 527}
528 528
529/* 529/*
530 * Remove an object from the object_tree_root and object_list. Must be called
531 * with the kmemleak_lock held _if_ kmemleak is still enabled.
532 */
533static void __remove_object(struct kmemleak_object *object)
534{
535 rb_erase(&object->rb_node, &object_tree_root);
536 list_del_rcu(&object->object_list);
537}
538
539/*
530 * Look up an object in the object search tree and remove it from both 540 * Look up an object in the object search tree and remove it from both
531 * object_tree_root and object_list. The returned object's use_count should be 541 * object_tree_root and object_list. The returned object's use_count should be
532 * at least 1, as initially set by create_object(). 542 * at least 1, as initially set by create_object().
@@ -538,10 +548,8 @@ static struct kmemleak_object *find_and_remove_object(unsigned long ptr, int ali
538 548
539 write_lock_irqsave(&kmemleak_lock, flags); 549 write_lock_irqsave(&kmemleak_lock, flags);
540 object = lookup_object(ptr, alias); 550 object = lookup_object(ptr, alias);
541 if (object) { 551 if (object)
542 rb_erase(&object->rb_node, &object_tree_root); 552 __remove_object(object);
543 list_del_rcu(&object->object_list);
544 }
545 write_unlock_irqrestore(&kmemleak_lock, flags); 553 write_unlock_irqrestore(&kmemleak_lock, flags);
546 554
547 return object; 555 return object;
@@ -1834,12 +1842,16 @@ static const struct file_operations kmemleak_fops = {
1834 1842
1835static void __kmemleak_do_cleanup(void) 1843static void __kmemleak_do_cleanup(void)
1836{ 1844{
1837 struct kmemleak_object *object; 1845 struct kmemleak_object *object, *tmp;
1838 1846
1839 rcu_read_lock(); 1847 /*
1840 list_for_each_entry_rcu(object, &object_list, object_list) 1848 * Kmemleak has already been disabled, no need for RCU list traversal
1841 delete_object_full(object->pointer); 1849 * or kmemleak_lock held.
1842 rcu_read_unlock(); 1850 */
1851 list_for_each_entry_safe(object, tmp, &object_list, object_list) {
1852 __remove_object(object);
1853 __delete_object(object);
1854 }
1843} 1855}
1844 1856
1845/* 1857/*
diff --git a/mm/memblock.c b/mm/memblock.c
index 7d4f61ae666a..c4b16cae2bc9 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1356,9 +1356,6 @@ static phys_addr_t __init memblock_alloc_range_nid(phys_addr_t size,
1356 align = SMP_CACHE_BYTES; 1356 align = SMP_CACHE_BYTES;
1357 } 1357 }
1358 1358
1359 if (end > memblock.current_limit)
1360 end = memblock.current_limit;
1361
1362again: 1359again:
1363 found = memblock_find_in_range_node(size, align, start, end, nid, 1360 found = memblock_find_in_range_node(size, align, start, end, nid,
1364 flags); 1361 flags);
@@ -1469,6 +1466,9 @@ static void * __init memblock_alloc_internal(
1469 if (WARN_ON_ONCE(slab_is_available())) 1466 if (WARN_ON_ONCE(slab_is_available()))
1470 return kzalloc_node(size, GFP_NOWAIT, nid); 1467 return kzalloc_node(size, GFP_NOWAIT, nid);
1471 1468
1469 if (max_addr > memblock.current_limit)
1470 max_addr = memblock.current_limit;
1471
1472 alloc = memblock_alloc_range_nid(size, align, min_addr, max_addr, nid); 1472 alloc = memblock_alloc_range_nid(size, align, min_addr, max_addr, nid);
1473 1473
1474 /* retry allocation without lower limit */ 1474 /* retry allocation without lower limit */
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index c313c49074ca..363106578876 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1567,6 +1567,11 @@ unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg)
1567 return max; 1567 return max;
1568} 1568}
1569 1569
1570unsigned long mem_cgroup_size(struct mem_cgroup *memcg)
1571{
1572 return page_counter_read(&memcg->memory);
1573}
1574
1570static bool mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask, 1575static bool mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask,
1571 int order) 1576 int order)
1572{ 1577{
@@ -5415,6 +5420,8 @@ static int mem_cgroup_move_account(struct page *page,
5415 struct mem_cgroup *from, 5420 struct mem_cgroup *from,
5416 struct mem_cgroup *to) 5421 struct mem_cgroup *to)
5417{ 5422{
5423 struct lruvec *from_vec, *to_vec;
5424 struct pglist_data *pgdat;
5418 unsigned long flags; 5425 unsigned long flags;
5419 unsigned int nr_pages = compound ? hpage_nr_pages(page) : 1; 5426 unsigned int nr_pages = compound ? hpage_nr_pages(page) : 1;
5420 int ret; 5427 int ret;
@@ -5438,11 +5445,15 @@ static int mem_cgroup_move_account(struct page *page,
5438 5445
5439 anon = PageAnon(page); 5446 anon = PageAnon(page);
5440 5447
5448 pgdat = page_pgdat(page);
5449 from_vec = mem_cgroup_lruvec(pgdat, from);
5450 to_vec = mem_cgroup_lruvec(pgdat, to);
5451
5441 spin_lock_irqsave(&from->move_lock, flags); 5452 spin_lock_irqsave(&from->move_lock, flags);
5442 5453
5443 if (!anon && page_mapped(page)) { 5454 if (!anon && page_mapped(page)) {
5444 __mod_memcg_state(from, NR_FILE_MAPPED, -nr_pages); 5455 __mod_lruvec_state(from_vec, NR_FILE_MAPPED, -nr_pages);
5445 __mod_memcg_state(to, NR_FILE_MAPPED, nr_pages); 5456 __mod_lruvec_state(to_vec, NR_FILE_MAPPED, nr_pages);
5446 } 5457 }
5447 5458
5448 /* 5459 /*
@@ -5454,14 +5465,14 @@ static int mem_cgroup_move_account(struct page *page,
5454 struct address_space *mapping = page_mapping(page); 5465 struct address_space *mapping = page_mapping(page);
5455 5466
5456 if (mapping_cap_account_dirty(mapping)) { 5467 if (mapping_cap_account_dirty(mapping)) {
5457 __mod_memcg_state(from, NR_FILE_DIRTY, -nr_pages); 5468 __mod_lruvec_state(from_vec, NR_FILE_DIRTY, -nr_pages);
5458 __mod_memcg_state(to, NR_FILE_DIRTY, nr_pages); 5469 __mod_lruvec_state(to_vec, NR_FILE_DIRTY, nr_pages);
5459 } 5470 }
5460 } 5471 }
5461 5472
5462 if (PageWriteback(page)) { 5473 if (PageWriteback(page)) {
5463 __mod_memcg_state(from, NR_WRITEBACK, -nr_pages); 5474 __mod_lruvec_state(from_vec, NR_WRITEBACK, -nr_pages);
5464 __mod_memcg_state(to, NR_WRITEBACK, nr_pages); 5475 __mod_lruvec_state(to_vec, NR_WRITEBACK, nr_pages);
5465 } 5476 }
5466 5477
5467#ifdef CONFIG_TRANSPARENT_HUGEPAGE 5478#ifdef CONFIG_TRANSPARENT_HUGEPAGE
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 7ef849da8278..3151c87dff73 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -199,7 +199,6 @@ struct to_kill {
199 struct task_struct *tsk; 199 struct task_struct *tsk;
200 unsigned long addr; 200 unsigned long addr;
201 short size_shift; 201 short size_shift;
202 char addr_valid;
203}; 202};
204 203
205/* 204/*
@@ -324,22 +323,27 @@ static void add_to_kill(struct task_struct *tsk, struct page *p,
324 } 323 }
325 } 324 }
326 tk->addr = page_address_in_vma(p, vma); 325 tk->addr = page_address_in_vma(p, vma);
327 tk->addr_valid = 1;
328 if (is_zone_device_page(p)) 326 if (is_zone_device_page(p))
329 tk->size_shift = dev_pagemap_mapping_shift(p, vma); 327 tk->size_shift = dev_pagemap_mapping_shift(p, vma);
330 else 328 else
331 tk->size_shift = compound_order(compound_head(p)) + PAGE_SHIFT; 329 tk->size_shift = compound_order(compound_head(p)) + PAGE_SHIFT;
332 330
333 /* 331 /*
334 * In theory we don't have to kill when the page was 332 * Send SIGKILL if "tk->addr == -EFAULT". Also, as
335 * munmaped. But it could be also a mremap. Since that's 333 * "tk->size_shift" is always non-zero for !is_zone_device_page(),
336 * likely very rare kill anyways just out of paranoia, but use 334 * so "tk->size_shift == 0" effectively checks no mapping on
337 * a SIGKILL because the error is not contained anymore. 335 * ZONE_DEVICE. Indeed, when a devdax page is mmapped N times
336 * to a process' address space, it's possible not all N VMAs
337 * contain mappings for the page, but at least one VMA does.
338 * Only deliver SIGBUS with payload derived from the VMA that
339 * has a mapping for the page.
338 */ 340 */
339 if (tk->addr == -EFAULT || tk->size_shift == 0) { 341 if (tk->addr == -EFAULT) {
340 pr_info("Memory failure: Unable to find user space address %lx in %s\n", 342 pr_info("Memory failure: Unable to find user space address %lx in %s\n",
341 page_to_pfn(p), tsk->comm); 343 page_to_pfn(p), tsk->comm);
342 tk->addr_valid = 0; 344 } else if (tk->size_shift == 0) {
345 kfree(tk);
346 return;
343 } 347 }
344 get_task_struct(tsk); 348 get_task_struct(tsk);
345 tk->tsk = tsk; 349 tk->tsk = tsk;
@@ -366,7 +370,7 @@ static void kill_procs(struct list_head *to_kill, int forcekill, bool fail,
366 * make sure the process doesn't catch the 370 * make sure the process doesn't catch the
367 * signal and then access the memory. Just kill it. 371 * signal and then access the memory. Just kill it.
368 */ 372 */
369 if (fail || tk->addr_valid == 0) { 373 if (fail || tk->addr == -EFAULT) {
370 pr_err("Memory failure: %#lx: forcibly killing %s:%d because of failure to unmap corrupted page\n", 374 pr_err("Memory failure: %#lx: forcibly killing %s:%d because of failure to unmap corrupted page\n",
371 pfn, tk->tsk->comm, tk->tsk->pid); 375 pfn, tk->tsk->comm, tk->tsk->pid);
372 do_send_sig_info(SIGKILL, SEND_SIG_PRIV, 376 do_send_sig_info(SIGKILL, SEND_SIG_PRIV,
@@ -1253,17 +1257,19 @@ int memory_failure(unsigned long pfn, int flags)
1253 if (!sysctl_memory_failure_recovery) 1257 if (!sysctl_memory_failure_recovery)
1254 panic("Memory failure on page %lx", pfn); 1258 panic("Memory failure on page %lx", pfn);
1255 1259
1256 if (!pfn_valid(pfn)) { 1260 p = pfn_to_online_page(pfn);
1261 if (!p) {
1262 if (pfn_valid(pfn)) {
1263 pgmap = get_dev_pagemap(pfn, NULL);
1264 if (pgmap)
1265 return memory_failure_dev_pagemap(pfn, flags,
1266 pgmap);
1267 }
1257 pr_err("Memory failure: %#lx: memory outside kernel control\n", 1268 pr_err("Memory failure: %#lx: memory outside kernel control\n",
1258 pfn); 1269 pfn);
1259 return -ENXIO; 1270 return -ENXIO;
1260 } 1271 }
1261 1272
1262 pgmap = get_dev_pagemap(pfn, NULL);
1263 if (pgmap)
1264 return memory_failure_dev_pagemap(pfn, flags, pgmap);
1265
1266 p = pfn_to_page(pfn);
1267 if (PageHuge(p)) 1273 if (PageHuge(p))
1268 return memory_failure_hugetlb(pfn, flags); 1274 return memory_failure_hugetlb(pfn, flags);
1269 if (TestSetPageHWPoison(p)) { 1275 if (TestSetPageHWPoison(p)) {
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index b1be791f772d..df570e5c71cc 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -436,67 +436,25 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
436 zone_span_writeunlock(zone); 436 zone_span_writeunlock(zone);
437} 437}
438 438
439static void shrink_pgdat_span(struct pglist_data *pgdat, 439static void update_pgdat_span(struct pglist_data *pgdat)
440 unsigned long start_pfn, unsigned long end_pfn)
441{ 440{
442 unsigned long pgdat_start_pfn = pgdat->node_start_pfn; 441 unsigned long node_start_pfn = 0, node_end_pfn = 0;
443 unsigned long p = pgdat_end_pfn(pgdat); /* pgdat_end_pfn namespace clash */ 442 struct zone *zone;
444 unsigned long pgdat_end_pfn = p;
445 unsigned long pfn;
446 int nid = pgdat->node_id;
447
448 if (pgdat_start_pfn == start_pfn) {
449 /*
450 * If the section is smallest section in the pgdat, it need
451 * shrink pgdat->node_start_pfn and pgdat->node_spanned_pages.
452 * In this case, we find second smallest valid mem_section
453 * for shrinking zone.
454 */
455 pfn = find_smallest_section_pfn(nid, NULL, end_pfn,
456 pgdat_end_pfn);
457 if (pfn) {
458 pgdat->node_start_pfn = pfn;
459 pgdat->node_spanned_pages = pgdat_end_pfn - pfn;
460 }
461 } else if (pgdat_end_pfn == end_pfn) {
462 /*
463 * If the section is biggest section in the pgdat, it need
464 * shrink pgdat->node_spanned_pages.
465 * In this case, we find second biggest valid mem_section for
466 * shrinking zone.
467 */
468 pfn = find_biggest_section_pfn(nid, NULL, pgdat_start_pfn,
469 start_pfn);
470 if (pfn)
471 pgdat->node_spanned_pages = pfn - pgdat_start_pfn + 1;
472 }
473
474 /*
475 * If the section is not biggest or smallest mem_section in the pgdat,
476 * it only creates a hole in the pgdat. So in this case, we need not
477 * change the pgdat.
478 * But perhaps, the pgdat has only hole data. Thus it check the pgdat
479 * has only hole or not.
480 */
481 pfn = pgdat_start_pfn;
482 for (; pfn < pgdat_end_pfn; pfn += PAGES_PER_SUBSECTION) {
483 if (unlikely(!pfn_valid(pfn)))
484 continue;
485
486 if (pfn_to_nid(pfn) != nid)
487 continue;
488 443
489 /* Skip range to be removed */ 444 for (zone = pgdat->node_zones;
490 if (pfn >= start_pfn && pfn < end_pfn) 445 zone < pgdat->node_zones + MAX_NR_ZONES; zone++) {
491 continue; 446 unsigned long zone_end_pfn = zone->zone_start_pfn +
447 zone->spanned_pages;
492 448
493 /* If we find valid section, we have nothing to do */ 449 /* No need to lock the zones, they can't change. */
494 return; 450 if (zone_end_pfn > node_end_pfn)
451 node_end_pfn = zone_end_pfn;
452 if (zone->zone_start_pfn < node_start_pfn)
453 node_start_pfn = zone->zone_start_pfn;
495 } 454 }
496 455
497 /* The pgdat has no valid section */ 456 pgdat->node_start_pfn = node_start_pfn;
498 pgdat->node_start_pfn = 0; 457 pgdat->node_spanned_pages = node_end_pfn - node_start_pfn;
499 pgdat->node_spanned_pages = 0;
500} 458}
501 459
502static void __remove_zone(struct zone *zone, unsigned long start_pfn, 460static void __remove_zone(struct zone *zone, unsigned long start_pfn,
@@ -507,7 +465,7 @@ static void __remove_zone(struct zone *zone, unsigned long start_pfn,
507 465
508 pgdat_resize_lock(zone->zone_pgdat, &flags); 466 pgdat_resize_lock(zone->zone_pgdat, &flags);
509 shrink_zone_span(zone, start_pfn, start_pfn + nr_pages); 467 shrink_zone_span(zone, start_pfn, start_pfn + nr_pages);
510 shrink_pgdat_span(pgdat, start_pfn, start_pfn + nr_pages); 468 update_pgdat_span(pgdat);
511 pgdat_resize_unlock(zone->zone_pgdat, &flags); 469 pgdat_resize_unlock(zone->zone_pgdat, &flags);
512} 470}
513 471
diff --git a/mm/memremap.c b/mm/memremap.c
index 32c79b51af86..03ccbdfeb697 100644
--- a/mm/memremap.c
+++ b/mm/memremap.c
@@ -13,8 +13,6 @@
13#include <linux/xarray.h> 13#include <linux/xarray.h>
14 14
15static DEFINE_XARRAY(pgmap_array); 15static DEFINE_XARRAY(pgmap_array);
16#define SECTION_MASK ~((1UL << PA_SECTION_SHIFT) - 1)
17#define SECTION_SIZE (1UL << PA_SECTION_SHIFT)
18 16
19#ifdef CONFIG_DEV_PAGEMAP_OPS 17#ifdef CONFIG_DEV_PAGEMAP_OPS
20DEFINE_STATIC_KEY_FALSE(devmap_managed_key); 18DEFINE_STATIC_KEY_FALSE(devmap_managed_key);
@@ -105,6 +103,7 @@ static void dev_pagemap_cleanup(struct dev_pagemap *pgmap)
105void memunmap_pages(struct dev_pagemap *pgmap) 103void memunmap_pages(struct dev_pagemap *pgmap)
106{ 104{
107 struct resource *res = &pgmap->res; 105 struct resource *res = &pgmap->res;
106 struct page *first_page;
108 unsigned long pfn; 107 unsigned long pfn;
109 int nid; 108 int nid;
110 109
@@ -113,14 +112,16 @@ void memunmap_pages(struct dev_pagemap *pgmap)
113 put_page(pfn_to_page(pfn)); 112 put_page(pfn_to_page(pfn));
114 dev_pagemap_cleanup(pgmap); 113 dev_pagemap_cleanup(pgmap);
115 114
115 /* make sure to access a memmap that was actually initialized */
116 first_page = pfn_to_page(pfn_first(pgmap));
117
116 /* pages are dead and unused, undo the arch mapping */ 118 /* pages are dead and unused, undo the arch mapping */
117 nid = page_to_nid(pfn_to_page(PHYS_PFN(res->start))); 119 nid = page_to_nid(first_page);
118 120
119 mem_hotplug_begin(); 121 mem_hotplug_begin();
120 if (pgmap->type == MEMORY_DEVICE_PRIVATE) { 122 if (pgmap->type == MEMORY_DEVICE_PRIVATE) {
121 pfn = PHYS_PFN(res->start); 123 __remove_pages(page_zone(first_page), PHYS_PFN(res->start),
122 __remove_pages(page_zone(pfn_to_page(pfn)), pfn, 124 PHYS_PFN(resource_size(res)), NULL);
123 PHYS_PFN(resource_size(res)), NULL);
124 } else { 125 } else {
125 arch_remove_memory(nid, res->start, resource_size(res), 126 arch_remove_memory(nid, res->start, resource_size(res),
126 pgmap_altmap(pgmap)); 127 pgmap_altmap(pgmap));
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 15c2050c629b..ecc3dbad606b 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1175,11 +1175,17 @@ static __always_inline bool free_pages_prepare(struct page *page,
1175 debug_check_no_obj_freed(page_address(page), 1175 debug_check_no_obj_freed(page_address(page),
1176 PAGE_SIZE << order); 1176 PAGE_SIZE << order);
1177 } 1177 }
1178 arch_free_page(page, order);
1179 if (want_init_on_free()) 1178 if (want_init_on_free())
1180 kernel_init_free_pages(page, 1 << order); 1179 kernel_init_free_pages(page, 1 << order);
1181 1180
1182 kernel_poison_pages(page, 1 << order, 0); 1181 kernel_poison_pages(page, 1 << order, 0);
1182 /*
1183 * arch_free_page() can make the page's contents inaccessible. s390
1184 * does this. So nothing which can access the page's contents should
1185 * happen after this.
1186 */
1187 arch_free_page(page, order);
1188
1183 if (debug_pagealloc_enabled()) 1189 if (debug_pagealloc_enabled())
1184 kernel_map_pages(page, 1 << order, 0); 1190 kernel_map_pages(page, 1 << order, 0);
1185 1191
@@ -4467,12 +4473,14 @@ retry_cpuset:
4467 if (page) 4473 if (page)
4468 goto got_pg; 4474 goto got_pg;
4469 4475
4470 if (order >= pageblock_order && (gfp_mask & __GFP_IO)) { 4476 if (order >= pageblock_order && (gfp_mask & __GFP_IO) &&
4477 !(gfp_mask & __GFP_RETRY_MAYFAIL)) {
4471 /* 4478 /*
4472 * If allocating entire pageblock(s) and compaction 4479 * If allocating entire pageblock(s) and compaction
4473 * failed because all zones are below low watermarks 4480 * failed because all zones are below low watermarks
4474 * or is prohibited because it recently failed at this 4481 * or is prohibited because it recently failed at this
4475 * order, fail immediately. 4482 * order, fail immediately unless the allocator has
4483 * requested compaction and reclaim retry.
4476 * 4484 *
4477 * Reclaim is 4485 * Reclaim is
4478 * - potentially very expensive because zones are far 4486 * - potentially very expensive because zones are far
diff --git a/mm/page_ext.c b/mm/page_ext.c
index 5f5769c7db3b..4ade843ff588 100644
--- a/mm/page_ext.c
+++ b/mm/page_ext.c
@@ -67,8 +67,9 @@ static struct page_ext_operations *page_ext_ops[] = {
67#endif 67#endif
68}; 68};
69 69
70unsigned long page_ext_size = sizeof(struct page_ext);
71
70static unsigned long total_usage; 72static unsigned long total_usage;
71static unsigned long extra_mem;
72 73
73static bool __init invoke_need_callbacks(void) 74static bool __init invoke_need_callbacks(void)
74{ 75{
@@ -78,9 +79,8 @@ static bool __init invoke_need_callbacks(void)
78 79
79 for (i = 0; i < entries; i++) { 80 for (i = 0; i < entries; i++) {
80 if (page_ext_ops[i]->need && page_ext_ops[i]->need()) { 81 if (page_ext_ops[i]->need && page_ext_ops[i]->need()) {
81 page_ext_ops[i]->offset = sizeof(struct page_ext) + 82 page_ext_ops[i]->offset = page_ext_size;
82 extra_mem; 83 page_ext_size += page_ext_ops[i]->size;
83 extra_mem += page_ext_ops[i]->size;
84 need = true; 84 need = true;
85 } 85 }
86 } 86 }
@@ -99,14 +99,9 @@ static void __init invoke_init_callbacks(void)
99 } 99 }
100} 100}
101 101
102static unsigned long get_entry_size(void)
103{
104 return sizeof(struct page_ext) + extra_mem;
105}
106
107static inline struct page_ext *get_entry(void *base, unsigned long index) 102static inline struct page_ext *get_entry(void *base, unsigned long index)
108{ 103{
109 return base + get_entry_size() * index; 104 return base + page_ext_size * index;
110} 105}
111 106
112#if !defined(CONFIG_SPARSEMEM) 107#if !defined(CONFIG_SPARSEMEM)
@@ -156,7 +151,7 @@ static int __init alloc_node_page_ext(int nid)
156 !IS_ALIGNED(node_end_pfn(nid), MAX_ORDER_NR_PAGES)) 151 !IS_ALIGNED(node_end_pfn(nid), MAX_ORDER_NR_PAGES))
157 nr_pages += MAX_ORDER_NR_PAGES; 152 nr_pages += MAX_ORDER_NR_PAGES;
158 153
159 table_size = get_entry_size() * nr_pages; 154 table_size = page_ext_size * nr_pages;
160 155
161 base = memblock_alloc_try_nid( 156 base = memblock_alloc_try_nid(
162 table_size, PAGE_SIZE, __pa(MAX_DMA_ADDRESS), 157 table_size, PAGE_SIZE, __pa(MAX_DMA_ADDRESS),
@@ -234,7 +229,7 @@ static int __meminit init_section_page_ext(unsigned long pfn, int nid)
234 if (section->page_ext) 229 if (section->page_ext)
235 return 0; 230 return 0;
236 231
237 table_size = get_entry_size() * PAGES_PER_SECTION; 232 table_size = page_ext_size * PAGES_PER_SECTION;
238 base = alloc_page_ext(table_size, nid); 233 base = alloc_page_ext(table_size, nid);
239 234
240 /* 235 /*
@@ -254,7 +249,7 @@ static int __meminit init_section_page_ext(unsigned long pfn, int nid)
254 * we need to apply a mask. 249 * we need to apply a mask.
255 */ 250 */
256 pfn &= PAGE_SECTION_MASK; 251 pfn &= PAGE_SECTION_MASK;
257 section->page_ext = (void *)base - get_entry_size() * pfn; 252 section->page_ext = (void *)base - page_ext_size * pfn;
258 total_usage += table_size; 253 total_usage += table_size;
259 return 0; 254 return 0;
260} 255}
@@ -267,7 +262,7 @@ static void free_page_ext(void *addr)
267 struct page *page = virt_to_page(addr); 262 struct page *page = virt_to_page(addr);
268 size_t table_size; 263 size_t table_size;
269 264
270 table_size = get_entry_size() * PAGES_PER_SECTION; 265 table_size = page_ext_size * PAGES_PER_SECTION;
271 266
272 BUG_ON(PageReserved(page)); 267 BUG_ON(PageReserved(page));
273 kmemleak_free(addr); 268 kmemleak_free(addr);
diff --git a/mm/page_owner.c b/mm/page_owner.c
index dee931184788..18ecde9f45b2 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -24,12 +24,10 @@ struct page_owner {
24 short last_migrate_reason; 24 short last_migrate_reason;
25 gfp_t gfp_mask; 25 gfp_t gfp_mask;
26 depot_stack_handle_t handle; 26 depot_stack_handle_t handle;
27#ifdef CONFIG_DEBUG_PAGEALLOC
28 depot_stack_handle_t free_handle; 27 depot_stack_handle_t free_handle;
29#endif
30}; 28};
31 29
32static bool page_owner_disabled = true; 30static bool page_owner_enabled = false;
33DEFINE_STATIC_KEY_FALSE(page_owner_inited); 31DEFINE_STATIC_KEY_FALSE(page_owner_inited);
34 32
35static depot_stack_handle_t dummy_handle; 33static depot_stack_handle_t dummy_handle;
@@ -44,7 +42,7 @@ static int __init early_page_owner_param(char *buf)
44 return -EINVAL; 42 return -EINVAL;
45 43
46 if (strcmp(buf, "on") == 0) 44 if (strcmp(buf, "on") == 0)
47 page_owner_disabled = false; 45 page_owner_enabled = true;
48 46
49 return 0; 47 return 0;
50} 48}
@@ -52,10 +50,7 @@ early_param("page_owner", early_page_owner_param);
52 50
53static bool need_page_owner(void) 51static bool need_page_owner(void)
54{ 52{
55 if (page_owner_disabled) 53 return page_owner_enabled;
56 return false;
57
58 return true;
59} 54}
60 55
61static __always_inline depot_stack_handle_t create_dummy_stack(void) 56static __always_inline depot_stack_handle_t create_dummy_stack(void)
@@ -84,7 +79,7 @@ static noinline void register_early_stack(void)
84 79
85static void init_page_owner(void) 80static void init_page_owner(void)
86{ 81{
87 if (page_owner_disabled) 82 if (!page_owner_enabled)
88 return; 83 return;
89 84
90 register_dummy_stack(); 85 register_dummy_stack();
@@ -148,25 +143,19 @@ void __reset_page_owner(struct page *page, unsigned int order)
148{ 143{
149 int i; 144 int i;
150 struct page_ext *page_ext; 145 struct page_ext *page_ext;
151#ifdef CONFIG_DEBUG_PAGEALLOC
152 depot_stack_handle_t handle = 0; 146 depot_stack_handle_t handle = 0;
153 struct page_owner *page_owner; 147 struct page_owner *page_owner;
154 148
155 if (debug_pagealloc_enabled()) 149 handle = save_stack(GFP_NOWAIT | __GFP_NOWARN);
156 handle = save_stack(GFP_NOWAIT | __GFP_NOWARN);
157#endif
158 150
151 page_ext = lookup_page_ext(page);
152 if (unlikely(!page_ext))
153 return;
159 for (i = 0; i < (1 << order); i++) { 154 for (i = 0; i < (1 << order); i++) {
160 page_ext = lookup_page_ext(page + i); 155 __clear_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags);
161 if (unlikely(!page_ext)) 156 page_owner = get_page_owner(page_ext);
162 continue; 157 page_owner->free_handle = handle;
163 __clear_bit(PAGE_EXT_OWNER_ACTIVE, &page_ext->flags); 158 page_ext = page_ext_next(page_ext);
164#ifdef CONFIG_DEBUG_PAGEALLOC
165 if (debug_pagealloc_enabled()) {
166 page_owner = get_page_owner(page_ext);
167 page_owner->free_handle = handle;
168 }
169#endif
170 } 159 }
171} 160}
172 161
@@ -184,9 +173,9 @@ static inline void __set_page_owner_handle(struct page *page,
184 page_owner->gfp_mask = gfp_mask; 173 page_owner->gfp_mask = gfp_mask;
185 page_owner->last_migrate_reason = -1; 174 page_owner->last_migrate_reason = -1;
186 __set_bit(PAGE_EXT_OWNER, &page_ext->flags); 175 __set_bit(PAGE_EXT_OWNER, &page_ext->flags);
187 __set_bit(PAGE_EXT_OWNER_ACTIVE, &page_ext->flags); 176 __set_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags);
188 177
189 page_ext = lookup_page_ext(page + i); 178 page_ext = page_ext_next(page_ext);
190 } 179 }
191} 180}
192 181
@@ -224,12 +213,10 @@ void __split_page_owner(struct page *page, unsigned int order)
224 if (unlikely(!page_ext)) 213 if (unlikely(!page_ext))
225 return; 214 return;
226 215
227 page_owner = get_page_owner(page_ext); 216 for (i = 0; i < (1 << order); i++) {
228 page_owner->order = 0;
229 for (i = 1; i < (1 << order); i++) {
230 page_ext = lookup_page_ext(page + i);
231 page_owner = get_page_owner(page_ext); 217 page_owner = get_page_owner(page_ext);
232 page_owner->order = 0; 218 page_owner->order = 0;
219 page_ext = page_ext_next(page_ext);
233 } 220 }
234} 221}
235 222
@@ -260,7 +247,7 @@ void __copy_page_owner(struct page *oldpage, struct page *newpage)
260 * the new page, which will be freed. 247 * the new page, which will be freed.
261 */ 248 */
262 __set_bit(PAGE_EXT_OWNER, &new_ext->flags); 249 __set_bit(PAGE_EXT_OWNER, &new_ext->flags);
263 __set_bit(PAGE_EXT_OWNER_ACTIVE, &new_ext->flags); 250 __set_bit(PAGE_EXT_OWNER_ALLOCATED, &new_ext->flags);
264} 251}
265 252
266void pagetypeinfo_showmixedcount_print(struct seq_file *m, 253void pagetypeinfo_showmixedcount_print(struct seq_file *m,
@@ -284,7 +271,8 @@ void pagetypeinfo_showmixedcount_print(struct seq_file *m,
284 * not matter as the mixed block count will still be correct 271 * not matter as the mixed block count will still be correct
285 */ 272 */
286 for (; pfn < end_pfn; ) { 273 for (; pfn < end_pfn; ) {
287 if (!pfn_valid(pfn)) { 274 page = pfn_to_online_page(pfn);
275 if (!page) {
288 pfn = ALIGN(pfn + 1, MAX_ORDER_NR_PAGES); 276 pfn = ALIGN(pfn + 1, MAX_ORDER_NR_PAGES);
289 continue; 277 continue;
290 } 278 }
@@ -292,13 +280,13 @@ void pagetypeinfo_showmixedcount_print(struct seq_file *m,
292 block_end_pfn = ALIGN(pfn + 1, pageblock_nr_pages); 280 block_end_pfn = ALIGN(pfn + 1, pageblock_nr_pages);
293 block_end_pfn = min(block_end_pfn, end_pfn); 281 block_end_pfn = min(block_end_pfn, end_pfn);
294 282
295 page = pfn_to_page(pfn);
296 pageblock_mt = get_pageblock_migratetype(page); 283 pageblock_mt = get_pageblock_migratetype(page);
297 284
298 for (; pfn < block_end_pfn; pfn++) { 285 for (; pfn < block_end_pfn; pfn++) {
299 if (!pfn_valid_within(pfn)) 286 if (!pfn_valid_within(pfn))
300 continue; 287 continue;
301 288
289 /* The pageblock is online, no need to recheck. */
302 page = pfn_to_page(pfn); 290 page = pfn_to_page(pfn);
303 291
304 if (page_zone(page) != zone) 292 if (page_zone(page) != zone)
@@ -320,7 +308,7 @@ void pagetypeinfo_showmixedcount_print(struct seq_file *m,
320 if (unlikely(!page_ext)) 308 if (unlikely(!page_ext))
321 continue; 309 continue;
322 310
323 if (!test_bit(PAGE_EXT_OWNER_ACTIVE, &page_ext->flags)) 311 if (!test_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags))
324 continue; 312 continue;
325 313
326 page_owner = get_page_owner(page_ext); 314 page_owner = get_page_owner(page_ext);
@@ -435,7 +423,7 @@ void __dump_page_owner(struct page *page)
435 return; 423 return;
436 } 424 }
437 425
438 if (test_bit(PAGE_EXT_OWNER_ACTIVE, &page_ext->flags)) 426 if (test_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags))
439 pr_alert("page_owner tracks the page as allocated\n"); 427 pr_alert("page_owner tracks the page as allocated\n");
440 else 428 else
441 pr_alert("page_owner tracks the page as freed\n"); 429 pr_alert("page_owner tracks the page as freed\n");
@@ -451,7 +439,6 @@ void __dump_page_owner(struct page *page)
451 stack_trace_print(entries, nr_entries, 0); 439 stack_trace_print(entries, nr_entries, 0);
452 } 440 }
453 441
454#ifdef CONFIG_DEBUG_PAGEALLOC
455 handle = READ_ONCE(page_owner->free_handle); 442 handle = READ_ONCE(page_owner->free_handle);
456 if (!handle) { 443 if (!handle) {
457 pr_alert("page_owner free stack trace missing\n"); 444 pr_alert("page_owner free stack trace missing\n");
@@ -460,7 +447,6 @@ void __dump_page_owner(struct page *page)
460 pr_alert("page last free stack trace:\n"); 447 pr_alert("page last free stack trace:\n");
461 stack_trace_print(entries, nr_entries, 0); 448 stack_trace_print(entries, nr_entries, 0);
462 } 449 }
463#endif
464 450
465 if (page_owner->last_migrate_reason != -1) 451 if (page_owner->last_migrate_reason != -1)
466 pr_alert("page has been migrated, last migrate reason: %s\n", 452 pr_alert("page has been migrated, last migrate reason: %s\n",
@@ -527,7 +513,7 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
527 * Although we do have the info about past allocation of free 513 * Although we do have the info about past allocation of free
528 * pages, it's not relevant for current memory usage. 514 * pages, it's not relevant for current memory usage.
529 */ 515 */
530 if (!test_bit(PAGE_EXT_OWNER_ACTIVE, &page_ext->flags)) 516 if (!test_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags))
531 continue; 517 continue;
532 518
533 page_owner = get_page_owner(page_ext); 519 page_owner = get_page_owner(page_ext);
diff --git a/mm/rmap.c b/mm/rmap.c
index d9a23bb773bf..0c7b2a9400d4 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -61,6 +61,7 @@
61#include <linux/mmu_notifier.h> 61#include <linux/mmu_notifier.h>
62#include <linux/migrate.h> 62#include <linux/migrate.h>
63#include <linux/hugetlb.h> 63#include <linux/hugetlb.h>
64#include <linux/huge_mm.h>
64#include <linux/backing-dev.h> 65#include <linux/backing-dev.h>
65#include <linux/page_idle.h> 66#include <linux/page_idle.h>
66#include <linux/memremap.h> 67#include <linux/memremap.h>
diff --git a/mm/shmem.c b/mm/shmem.c
index cd570cc79c76..220be9fa2c41 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -3482,6 +3482,12 @@ static int shmem_parse_options(struct fs_context *fc, void *data)
3482{ 3482{
3483 char *options = data; 3483 char *options = data;
3484 3484
3485 if (options) {
3486 int err = security_sb_eat_lsm_opts(options, &fc->security);
3487 if (err)
3488 return err;
3489 }
3490
3485 while (options != NULL) { 3491 while (options != NULL) {
3486 char *this_char = options; 3492 char *this_char = options;
3487 for (;;) { 3493 for (;;) {
diff --git a/mm/shuffle.c b/mm/shuffle.c
index 3ce12481b1dc..b3fe97fd6654 100644
--- a/mm/shuffle.c
+++ b/mm/shuffle.c
@@ -33,7 +33,7 @@ __meminit void page_alloc_shuffle(enum mm_shuffle_ctl ctl)
33} 33}
34 34
35static bool shuffle_param; 35static bool shuffle_param;
36extern int shuffle_show(char *buffer, const struct kernel_param *kp) 36static int shuffle_show(char *buffer, const struct kernel_param *kp)
37{ 37{
38 return sprintf(buffer, "%c\n", test_bit(SHUFFLE_ENABLE, &shuffle_state) 38 return sprintf(buffer, "%c\n", test_bit(SHUFFLE_ENABLE, &shuffle_state)
39 ? 'Y' : 'N'); 39 ? 'Y' : 'N');
diff --git a/mm/slab.c b/mm/slab.c
index 9df370558e5d..66e5d8032bae 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -4206,9 +4206,12 @@ void __check_heap_object(const void *ptr, unsigned long n, struct page *page,
4206 4206
4207/** 4207/**
4208 * __ksize -- Uninstrumented ksize. 4208 * __ksize -- Uninstrumented ksize.
4209 * @objp: pointer to the object
4209 * 4210 *
4210 * Unlike ksize(), __ksize() is uninstrumented, and does not provide the same 4211 * Unlike ksize(), __ksize() is uninstrumented, and does not provide the same
4211 * safety checks as ksize() with KASAN instrumentation enabled. 4212 * safety checks as ksize() with KASAN instrumentation enabled.
4213 *
4214 * Return: size of the actual memory used by @objp in bytes
4212 */ 4215 */
4213size_t __ksize(const void *objp) 4216size_t __ksize(const void *objp)
4214{ 4217{
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 6491c3a41805..f9fb27b4c843 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -178,10 +178,13 @@ static int init_memcg_params(struct kmem_cache *s,
178 178
179static void destroy_memcg_params(struct kmem_cache *s) 179static void destroy_memcg_params(struct kmem_cache *s)
180{ 180{
181 if (is_root_cache(s)) 181 if (is_root_cache(s)) {
182 kvfree(rcu_access_pointer(s->memcg_params.memcg_caches)); 182 kvfree(rcu_access_pointer(s->memcg_params.memcg_caches));
183 else 183 } else {
184 mem_cgroup_put(s->memcg_params.memcg);
185 WRITE_ONCE(s->memcg_params.memcg, NULL);
184 percpu_ref_exit(&s->memcg_params.refcnt); 186 percpu_ref_exit(&s->memcg_params.refcnt);
187 }
185} 188}
186 189
187static void free_memcg_params(struct rcu_head *rcu) 190static void free_memcg_params(struct rcu_head *rcu)
@@ -253,8 +256,6 @@ static void memcg_unlink_cache(struct kmem_cache *s)
253 } else { 256 } else {
254 list_del(&s->memcg_params.children_node); 257 list_del(&s->memcg_params.children_node);
255 list_del(&s->memcg_params.kmem_caches_node); 258 list_del(&s->memcg_params.kmem_caches_node);
256 mem_cgroup_put(s->memcg_params.memcg);
257 WRITE_ONCE(s->memcg_params.memcg, NULL);
258 } 259 }
259} 260}
260#else 261#else
@@ -1030,10 +1031,19 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name,
1030 unsigned int useroffset, unsigned int usersize) 1031 unsigned int useroffset, unsigned int usersize)
1031{ 1032{
1032 int err; 1033 int err;
1034 unsigned int align = ARCH_KMALLOC_MINALIGN;
1033 1035
1034 s->name = name; 1036 s->name = name;
1035 s->size = s->object_size = size; 1037 s->size = s->object_size = size;
1036 s->align = calculate_alignment(flags, ARCH_KMALLOC_MINALIGN, size); 1038
1039 /*
1040 * For power of two sizes, guarantee natural alignment for kmalloc
1041 * caches, regardless of SL*B debugging options.
1042 */
1043 if (is_power_of_2(size))
1044 align = max(align, size);
1045 s->align = calculate_alignment(flags, align, size);
1046
1037 s->useroffset = useroffset; 1047 s->useroffset = useroffset;
1038 s->usersize = usersize; 1048 s->usersize = usersize;
1039 1049
@@ -1287,12 +1297,16 @@ void __init create_kmalloc_caches(slab_flags_t flags)
1287 */ 1297 */
1288void *kmalloc_order(size_t size, gfp_t flags, unsigned int order) 1298void *kmalloc_order(size_t size, gfp_t flags, unsigned int order)
1289{ 1299{
1290 void *ret; 1300 void *ret = NULL;
1291 struct page *page; 1301 struct page *page;
1292 1302
1293 flags |= __GFP_COMP; 1303 flags |= __GFP_COMP;
1294 page = alloc_pages(flags, order); 1304 page = alloc_pages(flags, order);
1295 ret = page ? page_address(page) : NULL; 1305 if (likely(page)) {
1306 ret = page_address(page);
1307 mod_node_page_state(page_pgdat(page), NR_SLAB_UNRECLAIMABLE,
1308 1 << order);
1309 }
1296 ret = kasan_kmalloc_large(ret, size, flags); 1310 ret = kasan_kmalloc_large(ret, size, flags);
1297 /* As ret might get tagged, call kmemleak hook after KASAN. */ 1311 /* As ret might get tagged, call kmemleak hook after KASAN. */
1298 kmemleak_alloc(ret, size, 1, flags); 1312 kmemleak_alloc(ret, size, 1, flags);
diff --git a/mm/slob.c b/mm/slob.c
index cf377beab962..fa53e9f73893 100644
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -190,7 +190,7 @@ static int slob_last(slob_t *s)
190 190
191static void *slob_new_pages(gfp_t gfp, int order, int node) 191static void *slob_new_pages(gfp_t gfp, int order, int node)
192{ 192{
193 void *page; 193 struct page *page;
194 194
195#ifdef CONFIG_NUMA 195#ifdef CONFIG_NUMA
196 if (node != NUMA_NO_NODE) 196 if (node != NUMA_NO_NODE)
@@ -202,14 +202,21 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
202 if (!page) 202 if (!page)
203 return NULL; 203 return NULL;
204 204
205 mod_node_page_state(page_pgdat(page), NR_SLAB_UNRECLAIMABLE,
206 1 << order);
205 return page_address(page); 207 return page_address(page);
206} 208}
207 209
208static void slob_free_pages(void *b, int order) 210static void slob_free_pages(void *b, int order)
209{ 211{
212 struct page *sp = virt_to_page(b);
213
210 if (current->reclaim_state) 214 if (current->reclaim_state)
211 current->reclaim_state->reclaimed_slab += 1 << order; 215 current->reclaim_state->reclaimed_slab += 1 << order;
212 free_pages((unsigned long)b, order); 216
217 mod_node_page_state(page_pgdat(sp), NR_SLAB_UNRECLAIMABLE,
218 -(1 << order));
219 __free_pages(sp, order);
213} 220}
214 221
215/* 222/*
@@ -217,6 +224,7 @@ static void slob_free_pages(void *b, int order)
217 * @sp: Page to look in. 224 * @sp: Page to look in.
218 * @size: Size of the allocation. 225 * @size: Size of the allocation.
219 * @align: Allocation alignment. 226 * @align: Allocation alignment.
227 * @align_offset: Offset in the allocated block that will be aligned.
220 * @page_removed_from_list: Return parameter. 228 * @page_removed_from_list: Return parameter.
221 * 229 *
222 * Tries to find a chunk of memory at least @size bytes big within @page. 230 * Tries to find a chunk of memory at least @size bytes big within @page.
@@ -227,7 +235,7 @@ static void slob_free_pages(void *b, int order)
227 * true (set to false otherwise). 235 * true (set to false otherwise).
228 */ 236 */
229static void *slob_page_alloc(struct page *sp, size_t size, int align, 237static void *slob_page_alloc(struct page *sp, size_t size, int align,
230 bool *page_removed_from_list) 238 int align_offset, bool *page_removed_from_list)
231{ 239{
232 slob_t *prev, *cur, *aligned = NULL; 240 slob_t *prev, *cur, *aligned = NULL;
233 int delta = 0, units = SLOB_UNITS(size); 241 int delta = 0, units = SLOB_UNITS(size);
@@ -236,8 +244,17 @@ static void *slob_page_alloc(struct page *sp, size_t size, int align,
236 for (prev = NULL, cur = sp->freelist; ; prev = cur, cur = slob_next(cur)) { 244 for (prev = NULL, cur = sp->freelist; ; prev = cur, cur = slob_next(cur)) {
237 slobidx_t avail = slob_units(cur); 245 slobidx_t avail = slob_units(cur);
238 246
247 /*
248 * 'aligned' will hold the address of the slob block so that the
249 * address 'aligned'+'align_offset' is aligned according to the
250 * 'align' parameter. This is for kmalloc() which prepends the
251 * allocated block with its size, so that the block itself is
252 * aligned when needed.
253 */
239 if (align) { 254 if (align) {
240 aligned = (slob_t *)ALIGN((unsigned long)cur, align); 255 aligned = (slob_t *)
256 (ALIGN((unsigned long)cur + align_offset, align)
257 - align_offset);
241 delta = aligned - cur; 258 delta = aligned - cur;
242 } 259 }
243 if (avail >= units + delta) { /* room enough? */ 260 if (avail >= units + delta) { /* room enough? */
@@ -281,7 +298,8 @@ static void *slob_page_alloc(struct page *sp, size_t size, int align,
281/* 298/*
282 * slob_alloc: entry point into the slob allocator. 299 * slob_alloc: entry point into the slob allocator.
283 */ 300 */
284static void *slob_alloc(size_t size, gfp_t gfp, int align, int node) 301static void *slob_alloc(size_t size, gfp_t gfp, int align, int node,
302 int align_offset)
285{ 303{
286 struct page *sp; 304 struct page *sp;
287 struct list_head *slob_list; 305 struct list_head *slob_list;
@@ -312,7 +330,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
312 if (sp->units < SLOB_UNITS(size)) 330 if (sp->units < SLOB_UNITS(size))
313 continue; 331 continue;
314 332
315 b = slob_page_alloc(sp, size, align, &page_removed_from_list); 333 b = slob_page_alloc(sp, size, align, align_offset, &page_removed_from_list);
316 if (!b) 334 if (!b)
317 continue; 335 continue;
318 336
@@ -349,7 +367,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
349 INIT_LIST_HEAD(&sp->slab_list); 367 INIT_LIST_HEAD(&sp->slab_list);
350 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE)); 368 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
351 set_slob_page_free(sp, slob_list); 369 set_slob_page_free(sp, slob_list);
352 b = slob_page_alloc(sp, size, align, &_unused); 370 b = slob_page_alloc(sp, size, align, align_offset, &_unused);
353 BUG_ON(!b); 371 BUG_ON(!b);
354 spin_unlock_irqrestore(&slob_lock, flags); 372 spin_unlock_irqrestore(&slob_lock, flags);
355 } 373 }
@@ -451,7 +469,7 @@ static __always_inline void *
451__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller) 469__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
452{ 470{
453 unsigned int *m; 471 unsigned int *m;
454 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN); 472 int minalign = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
455 void *ret; 473 void *ret;
456 474
457 gfp &= gfp_allowed_mask; 475 gfp &= gfp_allowed_mask;
@@ -459,19 +477,28 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
459 fs_reclaim_acquire(gfp); 477 fs_reclaim_acquire(gfp);
460 fs_reclaim_release(gfp); 478 fs_reclaim_release(gfp);
461 479
462 if (size < PAGE_SIZE - align) { 480 if (size < PAGE_SIZE - minalign) {
481 int align = minalign;
482
483 /*
484 * For power of two sizes, guarantee natural alignment for
485 * kmalloc()'d objects.
486 */
487 if (is_power_of_2(size))
488 align = max(minalign, (int) size);
489
463 if (!size) 490 if (!size)
464 return ZERO_SIZE_PTR; 491 return ZERO_SIZE_PTR;
465 492
466 m = slob_alloc(size + align, gfp, align, node); 493 m = slob_alloc(size + minalign, gfp, align, node, minalign);
467 494
468 if (!m) 495 if (!m)
469 return NULL; 496 return NULL;
470 *m = size; 497 *m = size;
471 ret = (void *)m + align; 498 ret = (void *)m + minalign;
472 499
473 trace_kmalloc_node(caller, ret, 500 trace_kmalloc_node(caller, ret,
474 size, size + align, gfp, node); 501 size, size + minalign, gfp, node);
475 } else { 502 } else {
476 unsigned int order = get_order(size); 503 unsigned int order = get_order(size);
477 504
@@ -521,8 +548,13 @@ void kfree(const void *block)
521 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN); 548 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
522 unsigned int *m = (unsigned int *)(block - align); 549 unsigned int *m = (unsigned int *)(block - align);
523 slob_free(m, *m + align); 550 slob_free(m, *m + align);
524 } else 551 } else {
525 __free_pages(sp, compound_order(sp)); 552 unsigned int order = compound_order(sp);
553 mod_node_page_state(page_pgdat(sp), NR_SLAB_UNRECLAIMABLE,
554 -(1 << order));
555 __free_pages(sp, order);
556
557 }
526} 558}
527EXPORT_SYMBOL(kfree); 559EXPORT_SYMBOL(kfree);
528 560
@@ -567,7 +599,7 @@ static void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
567 fs_reclaim_release(flags); 599 fs_reclaim_release(flags);
568 600
569 if (c->size < PAGE_SIZE) { 601 if (c->size < PAGE_SIZE) {
570 b = slob_alloc(c->size, flags, c->align, node); 602 b = slob_alloc(c->size, flags, c->align, node, 0);
571 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size, 603 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
572 SLOB_UNITS(c->size) * SLOB_UNIT, 604 SLOB_UNITS(c->size) * SLOB_UNIT,
573 flags, node); 605 flags, node);
diff --git a/mm/slub.c b/mm/slub.c
index 42c1b3af3c98..b25c807a111f 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2672,6 +2672,17 @@ static void *__slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
2672} 2672}
2673 2673
2674/* 2674/*
2675 * If the object has been wiped upon free, make sure it's fully initialized by
2676 * zeroing out freelist pointer.
2677 */
2678static __always_inline void maybe_wipe_obj_freeptr(struct kmem_cache *s,
2679 void *obj)
2680{
2681 if (unlikely(slab_want_init_on_free(s)) && obj)
2682 memset((void *)((char *)obj + s->offset), 0, sizeof(void *));
2683}
2684
2685/*
2675 * Inlined fastpath so that allocation functions (kmalloc, kmem_cache_alloc) 2686 * Inlined fastpath so that allocation functions (kmalloc, kmem_cache_alloc)
2676 * have the fastpath folded into their functions. So no function call 2687 * have the fastpath folded into their functions. So no function call
2677 * overhead for requests that can be satisfied on the fastpath. 2688 * overhead for requests that can be satisfied on the fastpath.
@@ -2759,12 +2770,8 @@ redo:
2759 prefetch_freepointer(s, next_object); 2770 prefetch_freepointer(s, next_object);
2760 stat(s, ALLOC_FASTPATH); 2771 stat(s, ALLOC_FASTPATH);
2761 } 2772 }
2762 /* 2773
2763 * If the object has been wiped upon free, make sure it's fully 2774 maybe_wipe_obj_freeptr(s, object);
2764 * initialized by zeroing out freelist pointer.
2765 */
2766 if (unlikely(slab_want_init_on_free(s)) && object)
2767 memset(object + s->offset, 0, sizeof(void *));
2768 2775
2769 if (unlikely(slab_want_init_on_alloc(gfpflags, s)) && object) 2776 if (unlikely(slab_want_init_on_alloc(gfpflags, s)) && object)
2770 memset(object, 0, s->object_size); 2777 memset(object, 0, s->object_size);
@@ -3178,10 +3185,13 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
3178 goto error; 3185 goto error;
3179 3186
3180 c = this_cpu_ptr(s->cpu_slab); 3187 c = this_cpu_ptr(s->cpu_slab);
3188 maybe_wipe_obj_freeptr(s, p[i]);
3189
3181 continue; /* goto for-loop */ 3190 continue; /* goto for-loop */
3182 } 3191 }
3183 c->freelist = get_freepointer(s, object); 3192 c->freelist = get_freepointer(s, object);
3184 p[i] = object; 3193 p[i] = object;
3194 maybe_wipe_obj_freeptr(s, p[i]);
3185 } 3195 }
3186 c->tid = next_tid(c->tid); 3196 c->tid = next_tid(c->tid);
3187 local_irq_enable(); 3197 local_irq_enable();
@@ -3821,11 +3831,15 @@ static void *kmalloc_large_node(size_t size, gfp_t flags, int node)
3821{ 3831{
3822 struct page *page; 3832 struct page *page;
3823 void *ptr = NULL; 3833 void *ptr = NULL;
3834 unsigned int order = get_order(size);
3824 3835
3825 flags |= __GFP_COMP; 3836 flags |= __GFP_COMP;
3826 page = alloc_pages_node(node, flags, get_order(size)); 3837 page = alloc_pages_node(node, flags, order);
3827 if (page) 3838 if (page) {
3828 ptr = page_address(page); 3839 ptr = page_address(page);
3840 mod_node_page_state(page_pgdat(page), NR_SLAB_UNRECLAIMABLE,
3841 1 << order);
3842 }
3829 3843
3830 return kmalloc_large_node_hook(ptr, size, flags); 3844 return kmalloc_large_node_hook(ptr, size, flags);
3831} 3845}
@@ -3951,9 +3965,13 @@ void kfree(const void *x)
3951 3965
3952 page = virt_to_head_page(x); 3966 page = virt_to_head_page(x);
3953 if (unlikely(!PageSlab(page))) { 3967 if (unlikely(!PageSlab(page))) {
3968 unsigned int order = compound_order(page);
3969
3954 BUG_ON(!PageCompound(page)); 3970 BUG_ON(!PageCompound(page));
3955 kfree_hook(object); 3971 kfree_hook(object);
3956 __free_pages(page, compound_order(page)); 3972 mod_node_page_state(page_pgdat(page), NR_SLAB_UNRECLAIMABLE,
3973 -(1 << order));
3974 __free_pages(page, order);
3957 return; 3975 return;
3958 } 3976 }
3959 slab_free(page->slab_cache, page, object, NULL, 1, _RET_IP_); 3977 slab_free(page->slab_cache, page, object, NULL, 1, _RET_IP_);
@@ -4838,7 +4856,17 @@ static ssize_t show_slab_objects(struct kmem_cache *s,
4838 } 4856 }
4839 } 4857 }
4840 4858
4841 get_online_mems(); 4859 /*
4860 * It is impossible to take "mem_hotplug_lock" here with "kernfs_mutex"
4861 * already held which will conflict with an existing lock order:
4862 *
4863 * mem_hotplug_lock->slab_mutex->kernfs_mutex
4864 *
4865 * We don't really need mem_hotplug_lock (to hold off
4866 * slab_mem_going_offline_callback) here because slab's memory hot
4867 * unplug code doesn't destroy the kmem_cache->node[] data.
4868 */
4869
4842#ifdef CONFIG_SLUB_DEBUG 4870#ifdef CONFIG_SLUB_DEBUG
4843 if (flags & SO_ALL) { 4871 if (flags & SO_ALL) {
4844 struct kmem_cache_node *n; 4872 struct kmem_cache_node *n;
@@ -4879,7 +4907,6 @@ static ssize_t show_slab_objects(struct kmem_cache *s,
4879 x += sprintf(buf + x, " N%d=%lu", 4907 x += sprintf(buf + x, " N%d=%lu",
4880 node, nodes[node]); 4908 node, nodes[node]);
4881#endif 4909#endif
4882 put_online_mems();
4883 kfree(nodes); 4910 kfree(nodes);
4884 return x + sprintf(buf + x, "\n"); 4911 return x + sprintf(buf + x, "\n");
4885} 4912}
diff --git a/mm/sparse.c b/mm/sparse.c
index bf32de9e666b..f6891c1992b1 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -219,7 +219,7 @@ static inline unsigned long first_present_section_nr(void)
219 return next_present_section_nr(-1); 219 return next_present_section_nr(-1);
220} 220}
221 221
222void subsection_mask_set(unsigned long *map, unsigned long pfn, 222static void subsection_mask_set(unsigned long *map, unsigned long pfn,
223 unsigned long nr_pages) 223 unsigned long nr_pages)
224{ 224{
225 int idx = subsection_map_index(pfn); 225 int idx = subsection_map_index(pfn);
diff --git a/mm/truncate.c b/mm/truncate.c
index 8563339041f6..dd9ebc1da356 100644
--- a/mm/truncate.c
+++ b/mm/truncate.c
@@ -592,6 +592,16 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
592 unlock_page(page); 592 unlock_page(page);
593 continue; 593 continue;
594 } 594 }
595
596 /* Take a pin outside pagevec */
597 get_page(page);
598
599 /*
600 * Drop extra pins before trying to invalidate
601 * the huge page.
602 */
603 pagevec_remove_exceptionals(&pvec);
604 pagevec_release(&pvec);
595 } 605 }
596 606
597 ret = invalidate_inode_page(page); 607 ret = invalidate_inode_page(page);
@@ -602,6 +612,8 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
602 */ 612 */
603 if (!ret) 613 if (!ret)
604 deactivate_file_page(page); 614 deactivate_file_page(page);
615 if (PageTransHuge(page))
616 put_page(page);
605 count += ret; 617 count += ret;
606 } 618 }
607 pagevec_remove_exceptionals(&pvec); 619 pagevec_remove_exceptionals(&pvec);
diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index f3b50811497a..4bac22fe1aa2 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -355,6 +355,9 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio)
355 * "hierarchy" or "local"). 355 * "hierarchy" or "local").
356 * 356 *
357 * To be used as memcg event method. 357 * To be used as memcg event method.
358 *
359 * Return: 0 on success, -ENOMEM on memory failure or -EINVAL if @args could
360 * not be parsed.
358 */ 361 */
359int vmpressure_register_event(struct mem_cgroup *memcg, 362int vmpressure_register_event(struct mem_cgroup *memcg,
360 struct eventfd_ctx *eventfd, const char *args) 363 struct eventfd_ctx *eventfd, const char *args)
@@ -362,7 +365,7 @@ int vmpressure_register_event(struct mem_cgroup *memcg,
362 struct vmpressure *vmpr = memcg_to_vmpressure(memcg); 365 struct vmpressure *vmpr = memcg_to_vmpressure(memcg);
363 struct vmpressure_event *ev; 366 struct vmpressure_event *ev;
364 enum vmpressure_modes mode = VMPRESSURE_NO_PASSTHROUGH; 367 enum vmpressure_modes mode = VMPRESSURE_NO_PASSTHROUGH;
365 enum vmpressure_levels level = -1; 368 enum vmpressure_levels level;
366 char *spec, *spec_orig; 369 char *spec, *spec_orig;
367 char *token; 370 char *token;
368 int ret = 0; 371 int ret = 0;
@@ -375,20 +378,18 @@ int vmpressure_register_event(struct mem_cgroup *memcg,
375 378
376 /* Find required level */ 379 /* Find required level */
377 token = strsep(&spec, ","); 380 token = strsep(&spec, ",");
378 level = match_string(vmpressure_str_levels, VMPRESSURE_NUM_LEVELS, token); 381 ret = match_string(vmpressure_str_levels, VMPRESSURE_NUM_LEVELS, token);
379 if (level < 0) { 382 if (ret < 0)
380 ret = level;
381 goto out; 383 goto out;
382 } 384 level = ret;
383 385
384 /* Find optional mode */ 386 /* Find optional mode */
385 token = strsep(&spec, ","); 387 token = strsep(&spec, ",");
386 if (token) { 388 if (token) {
387 mode = match_string(vmpressure_str_modes, VMPRESSURE_NUM_MODES, token); 389 ret = match_string(vmpressure_str_modes, VMPRESSURE_NUM_MODES, token);
388 if (mode < 0) { 390 if (ret < 0)
389 ret = mode;
390 goto out; 391 goto out;
391 } 392 mode = ret;
392 } 393 }
393 394
394 ev = kzalloc(sizeof(*ev), GFP_KERNEL); 395 ev = kzalloc(sizeof(*ev), GFP_KERNEL);
@@ -404,6 +405,7 @@ int vmpressure_register_event(struct mem_cgroup *memcg,
404 mutex_lock(&vmpr->events_lock); 405 mutex_lock(&vmpr->events_lock);
405 list_add(&ev->node, &vmpr->events); 406 list_add(&ev->node, &vmpr->events);
406 mutex_unlock(&vmpr->events_lock); 407 mutex_unlock(&vmpr->events_lock);
408 ret = 0;
407out: 409out:
408 kfree(spec_orig); 410 kfree(spec_orig);
409 return ret; 411 return ret;
diff --git a/mm/vmscan.c b/mm/vmscan.c
index e5d52d6a24af..ee4eecc7e1c2 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -351,12 +351,13 @@ unsigned long zone_reclaimable_pages(struct zone *zone)
351 */ 351 */
352unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, int zone_idx) 352unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, int zone_idx)
353{ 353{
354 unsigned long lru_size; 354 unsigned long lru_size = 0;
355 int zid; 355 int zid;
356 356
357 if (!mem_cgroup_disabled()) 357 if (!mem_cgroup_disabled()) {
358 lru_size = lruvec_page_state_local(lruvec, NR_LRU_BASE + lru); 358 for (zid = 0; zid < MAX_NR_ZONES; zid++)
359 else 359 lru_size += mem_cgroup_get_zone_lru_size(lruvec, lru, zid);
360 } else
360 lru_size = node_page_state(lruvec_pgdat(lruvec), NR_LRU_BASE + lru); 361 lru_size = node_page_state(lruvec_pgdat(lruvec), NR_LRU_BASE + lru);
361 362
362 for (zid = zone_idx + 1; zid < MAX_NR_ZONES; zid++) { 363 for (zid = zone_idx + 1; zid < MAX_NR_ZONES; zid++) {
@@ -932,10 +933,7 @@ static int __remove_mapping(struct address_space *mapping, struct page *page,
932 * Note that if SetPageDirty is always performed via set_page_dirty, 933 * Note that if SetPageDirty is always performed via set_page_dirty,
933 * and thus under the i_pages lock, then this ordering is not required. 934 * and thus under the i_pages lock, then this ordering is not required.
934 */ 935 */
935 if (unlikely(PageTransHuge(page)) && PageSwapCache(page)) 936 refcount = 1 + compound_nr(page);
936 refcount = 1 + HPAGE_PMD_NR;
937 else
938 refcount = 2;
939 if (!page_ref_freeze(page, refcount)) 937 if (!page_ref_freeze(page, refcount))
940 goto cannot_free; 938 goto cannot_free;
941 /* note: atomic_cmpxchg in page_ref_freeze provides the smp_rmb */ 939 /* note: atomic_cmpxchg in page_ref_freeze provides the smp_rmb */
@@ -2459,17 +2457,70 @@ out:
2459 *lru_pages = 0; 2457 *lru_pages = 0;
2460 for_each_evictable_lru(lru) { 2458 for_each_evictable_lru(lru) {
2461 int file = is_file_lru(lru); 2459 int file = is_file_lru(lru);
2462 unsigned long size; 2460 unsigned long lruvec_size;
2463 unsigned long scan; 2461 unsigned long scan;
2462 unsigned long protection;
2463
2464 lruvec_size = lruvec_lru_size(lruvec, lru, sc->reclaim_idx);
2465 protection = mem_cgroup_protection(memcg,
2466 sc->memcg_low_reclaim);
2467
2468 if (protection) {
2469 /*
2470 * Scale a cgroup's reclaim pressure by proportioning
2471 * its current usage to its memory.low or memory.min
2472 * setting.
2473 *
2474 * This is important, as otherwise scanning aggression
2475 * becomes extremely binary -- from nothing as we
2476 * approach the memory protection threshold, to totally
2477 * nominal as we exceed it. This results in requiring
2478 * setting extremely liberal protection thresholds. It
2479 * also means we simply get no protection at all if we
2480 * set it too low, which is not ideal.
2481 *
2482 * If there is any protection in place, we reduce scan
2483 * pressure by how much of the total memory used is
2484 * within protection thresholds.
2485 *
2486 * There is one special case: in the first reclaim pass,
2487 * we skip over all groups that are within their low
2488 * protection. If that fails to reclaim enough pages to
2489 * satisfy the reclaim goal, we come back and override
2490 * the best-effort low protection. However, we still
2491 * ideally want to honor how well-behaved groups are in
2492 * that case instead of simply punishing them all
2493 * equally. As such, we reclaim them based on how much
2494 * memory they are using, reducing the scan pressure
2495 * again by how much of the total memory used is under
2496 * hard protection.
2497 */
2498 unsigned long cgroup_size = mem_cgroup_size(memcg);
2499
2500 /* Avoid TOCTOU with earlier protection check */
2501 cgroup_size = max(cgroup_size, protection);
2502
2503 scan = lruvec_size - lruvec_size * protection /
2504 cgroup_size;
2505
2506 /*
2507 * Minimally target SWAP_CLUSTER_MAX pages to keep
2508 * reclaim moving forwards, avoiding decremeting
2509 * sc->priority further than desirable.
2510 */
2511 scan = max(scan, SWAP_CLUSTER_MAX);
2512 } else {
2513 scan = lruvec_size;
2514 }
2515
2516 scan >>= sc->priority;
2464 2517
2465 size = lruvec_lru_size(lruvec, lru, sc->reclaim_idx);
2466 scan = size >> sc->priority;
2467 /* 2518 /*
2468 * If the cgroup's already been deleted, make sure to 2519 * If the cgroup's already been deleted, make sure to
2469 * scrape out the remaining cache. 2520 * scrape out the remaining cache.
2470 */ 2521 */
2471 if (!scan && !mem_cgroup_online(memcg)) 2522 if (!scan && !mem_cgroup_online(memcg))
2472 scan = min(size, SWAP_CLUSTER_MAX); 2523 scan = min(lruvec_size, SWAP_CLUSTER_MAX);
2473 2524
2474 switch (scan_balance) { 2525 switch (scan_balance) {
2475 case SCAN_EQUAL: 2526 case SCAN_EQUAL:
@@ -2489,7 +2540,7 @@ out:
2489 case SCAN_ANON: 2540 case SCAN_ANON:
2490 /* Scan one type exclusively */ 2541 /* Scan one type exclusively */
2491 if ((scan_balance == SCAN_FILE) != file) { 2542 if ((scan_balance == SCAN_FILE) != file) {
2492 size = 0; 2543 lruvec_size = 0;
2493 scan = 0; 2544 scan = 0;
2494 } 2545 }
2495 break; 2546 break;
@@ -2498,7 +2549,7 @@ out:
2498 BUG(); 2549 BUG();
2499 } 2550 }
2500 2551
2501 *lru_pages += size; 2552 *lru_pages += lruvec_size;
2502 nr[lru] = scan; 2553 nr[lru] = scan;
2503 } 2554 }
2504} 2555}
@@ -2742,6 +2793,13 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc)
2742 memcg_memory_event(memcg, MEMCG_LOW); 2793 memcg_memory_event(memcg, MEMCG_LOW);
2743 break; 2794 break;
2744 case MEMCG_PROT_NONE: 2795 case MEMCG_PROT_NONE:
2796 /*
2797 * All protection thresholds breached. We may
2798 * still choose to vary the scan pressure
2799 * applied based on by how much the cgroup in
2800 * question has exceeded its protection
2801 * thresholds (see get_scan_count).
2802 */
2745 break; 2803 break;
2746 } 2804 }
2747 2805
diff --git a/mm/z3fold.c b/mm/z3fold.c
index 05bdf90646e7..6d3d3f698ebb 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -998,9 +998,11 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
998 struct z3fold_header *zhdr; 998 struct z3fold_header *zhdr;
999 struct page *page; 999 struct page *page;
1000 enum buddy bud; 1000 enum buddy bud;
1001 bool page_claimed;
1001 1002
1002 zhdr = handle_to_z3fold_header(handle); 1003 zhdr = handle_to_z3fold_header(handle);
1003 page = virt_to_page(zhdr); 1004 page = virt_to_page(zhdr);
1005 page_claimed = test_and_set_bit(PAGE_CLAIMED, &page->private);
1004 1006
1005 if (test_bit(PAGE_HEADLESS, &page->private)) { 1007 if (test_bit(PAGE_HEADLESS, &page->private)) {
1006 /* if a headless page is under reclaim, just leave. 1008 /* if a headless page is under reclaim, just leave.
@@ -1008,7 +1010,7 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
1008 * has not been set before, we release this page 1010 * has not been set before, we release this page
1009 * immediately so we don't care about its value any more. 1011 * immediately so we don't care about its value any more.
1010 */ 1012 */
1011 if (!test_and_set_bit(PAGE_CLAIMED, &page->private)) { 1013 if (!page_claimed) {
1012 spin_lock(&pool->lock); 1014 spin_lock(&pool->lock);
1013 list_del(&page->lru); 1015 list_del(&page->lru);
1014 spin_unlock(&pool->lock); 1016 spin_unlock(&pool->lock);
@@ -1044,13 +1046,15 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
1044 atomic64_dec(&pool->pages_nr); 1046 atomic64_dec(&pool->pages_nr);
1045 return; 1047 return;
1046 } 1048 }
1047 if (test_bit(PAGE_CLAIMED, &page->private)) { 1049 if (page_claimed) {
1050 /* the page has not been claimed by us */
1048 z3fold_page_unlock(zhdr); 1051 z3fold_page_unlock(zhdr);
1049 return; 1052 return;
1050 } 1053 }
1051 if (unlikely(PageIsolated(page)) || 1054 if (unlikely(PageIsolated(page)) ||
1052 test_and_set_bit(NEEDS_COMPACTING, &page->private)) { 1055 test_and_set_bit(NEEDS_COMPACTING, &page->private)) {
1053 z3fold_page_unlock(zhdr); 1056 z3fold_page_unlock(zhdr);
1057 clear_bit(PAGE_CLAIMED, &page->private);
1054 return; 1058 return;
1055 } 1059 }
1056 if (zhdr->cpu < 0 || !cpu_online(zhdr->cpu)) { 1060 if (zhdr->cpu < 0 || !cpu_online(zhdr->cpu)) {
@@ -1060,10 +1064,12 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
1060 zhdr->cpu = -1; 1064 zhdr->cpu = -1;
1061 kref_get(&zhdr->refcount); 1065 kref_get(&zhdr->refcount);
1062 do_compact_page(zhdr, true); 1066 do_compact_page(zhdr, true);
1067 clear_bit(PAGE_CLAIMED, &page->private);
1063 return; 1068 return;
1064 } 1069 }
1065 kref_get(&zhdr->refcount); 1070 kref_get(&zhdr->refcount);
1066 queue_work_on(zhdr->cpu, pool->compact_wq, &zhdr->work); 1071 queue_work_on(zhdr->cpu, pool->compact_wq, &zhdr->work);
1072 clear_bit(PAGE_CLAIMED, &page->private);
1067 z3fold_page_unlock(zhdr); 1073 z3fold_page_unlock(zhdr);
1068} 1074}
1069 1075
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index 54728d2eda18..d4bcfd8f95bf 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -172,7 +172,6 @@ int register_vlan_dev(struct net_device *dev, struct netlink_ext_ack *extack)
172 if (err < 0) 172 if (err < 0)
173 goto out_uninit_mvrp; 173 goto out_uninit_mvrp;
174 174
175 vlan->nest_level = dev_get_nest_level(real_dev) + 1;
176 err = register_netdevice(dev); 175 err = register_netdevice(dev);
177 if (err < 0) 176 if (err < 0)
178 goto out_uninit_mvrp; 177 goto out_uninit_mvrp;
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
index 93eadf179123..e5bff5cc6f97 100644
--- a/net/8021q/vlan_dev.c
+++ b/net/8021q/vlan_dev.c
@@ -489,36 +489,6 @@ static void vlan_dev_set_rx_mode(struct net_device *vlan_dev)
489 dev_uc_sync(vlan_dev_priv(vlan_dev)->real_dev, vlan_dev); 489 dev_uc_sync(vlan_dev_priv(vlan_dev)->real_dev, vlan_dev);
490} 490}
491 491
492/*
493 * vlan network devices have devices nesting below it, and are a special
494 * "super class" of normal network devices; split their locks off into a
495 * separate class since they always nest.
496 */
497static struct lock_class_key vlan_netdev_xmit_lock_key;
498static struct lock_class_key vlan_netdev_addr_lock_key;
499
500static void vlan_dev_set_lockdep_one(struct net_device *dev,
501 struct netdev_queue *txq,
502 void *_subclass)
503{
504 lockdep_set_class_and_subclass(&txq->_xmit_lock,
505 &vlan_netdev_xmit_lock_key,
506 *(int *)_subclass);
507}
508
509static void vlan_dev_set_lockdep_class(struct net_device *dev, int subclass)
510{
511 lockdep_set_class_and_subclass(&dev->addr_list_lock,
512 &vlan_netdev_addr_lock_key,
513 subclass);
514 netdev_for_each_tx_queue(dev, vlan_dev_set_lockdep_one, &subclass);
515}
516
517static int vlan_dev_get_lock_subclass(struct net_device *dev)
518{
519 return vlan_dev_priv(dev)->nest_level;
520}
521
522static const struct header_ops vlan_header_ops = { 492static const struct header_ops vlan_header_ops = {
523 .create = vlan_dev_hard_header, 493 .create = vlan_dev_hard_header,
524 .parse = eth_header_parse, 494 .parse = eth_header_parse,
@@ -609,8 +579,6 @@ static int vlan_dev_init(struct net_device *dev)
609 579
610 SET_NETDEV_DEVTYPE(dev, &vlan_type); 580 SET_NETDEV_DEVTYPE(dev, &vlan_type);
611 581
612 vlan_dev_set_lockdep_class(dev, vlan_dev_get_lock_subclass(dev));
613
614 vlan->vlan_pcpu_stats = netdev_alloc_pcpu_stats(struct vlan_pcpu_stats); 582 vlan->vlan_pcpu_stats = netdev_alloc_pcpu_stats(struct vlan_pcpu_stats);
615 if (!vlan->vlan_pcpu_stats) 583 if (!vlan->vlan_pcpu_stats)
616 return -ENOMEM; 584 return -ENOMEM;
@@ -812,7 +780,6 @@ static const struct net_device_ops vlan_netdev_ops = {
812 .ndo_netpoll_cleanup = vlan_dev_netpoll_cleanup, 780 .ndo_netpoll_cleanup = vlan_dev_netpoll_cleanup,
813#endif 781#endif
814 .ndo_fix_features = vlan_dev_fix_features, 782 .ndo_fix_features = vlan_dev_fix_features,
815 .ndo_get_lock_subclass = vlan_dev_get_lock_subclass,
816 .ndo_get_iflink = vlan_dev_get_iflink, 783 .ndo_get_iflink = vlan_dev_get_iflink,
817}; 784};
818 785
diff --git a/net/atm/common.c b/net/atm/common.c
index b7528e77997c..0ce530af534d 100644
--- a/net/atm/common.c
+++ b/net/atm/common.c
@@ -668,7 +668,7 @@ __poll_t vcc_poll(struct file *file, struct socket *sock, poll_table *wait)
668 mask |= EPOLLHUP; 668 mask |= EPOLLHUP;
669 669
670 /* readable? */ 670 /* readable? */
671 if (!skb_queue_empty(&sk->sk_receive_queue)) 671 if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
672 mask |= EPOLLIN | EPOLLRDNORM; 672 mask |= EPOLLIN | EPOLLRDNORM;
673 673
674 /* writable? */ 674 /* writable? */
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index d78938e3e008..5b0b20e6da95 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -22,6 +22,8 @@
22#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/kref.h> 23#include <linux/kref.h>
24#include <linux/list.h> 24#include <linux/list.h>
25#include <linux/lockdep.h>
26#include <linux/mutex.h>
25#include <linux/netdevice.h> 27#include <linux/netdevice.h>
26#include <linux/netlink.h> 28#include <linux/netlink.h>
27#include <linux/pkt_sched.h> 29#include <linux/pkt_sched.h>
@@ -193,14 +195,18 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
193 unsigned char *ogm_buff; 195 unsigned char *ogm_buff;
194 u32 random_seqno; 196 u32 random_seqno;
195 197
198 mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
199
196 /* randomize initial seqno to avoid collision */ 200 /* randomize initial seqno to avoid collision */
197 get_random_bytes(&random_seqno, sizeof(random_seqno)); 201 get_random_bytes(&random_seqno, sizeof(random_seqno));
198 atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno); 202 atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
199 203
200 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN; 204 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
201 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC); 205 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
202 if (!ogm_buff) 206 if (!ogm_buff) {
207 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
203 return -ENOMEM; 208 return -ENOMEM;
209 }
204 210
205 hard_iface->bat_iv.ogm_buff = ogm_buff; 211 hard_iface->bat_iv.ogm_buff = ogm_buff;
206 212
@@ -212,35 +218,59 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
212 batadv_ogm_packet->reserved = 0; 218 batadv_ogm_packet->reserved = 0;
213 batadv_ogm_packet->tq = BATADV_TQ_MAX_VALUE; 219 batadv_ogm_packet->tq = BATADV_TQ_MAX_VALUE;
214 220
221 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
222
215 return 0; 223 return 0;
216} 224}
217 225
218static void batadv_iv_ogm_iface_disable(struct batadv_hard_iface *hard_iface) 226static void batadv_iv_ogm_iface_disable(struct batadv_hard_iface *hard_iface)
219{ 227{
228 mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
229
220 kfree(hard_iface->bat_iv.ogm_buff); 230 kfree(hard_iface->bat_iv.ogm_buff);
221 hard_iface->bat_iv.ogm_buff = NULL; 231 hard_iface->bat_iv.ogm_buff = NULL;
232
233 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
222} 234}
223 235
224static void batadv_iv_ogm_iface_update_mac(struct batadv_hard_iface *hard_iface) 236static void batadv_iv_ogm_iface_update_mac(struct batadv_hard_iface *hard_iface)
225{ 237{
226 struct batadv_ogm_packet *batadv_ogm_packet; 238 struct batadv_ogm_packet *batadv_ogm_packet;
227 unsigned char *ogm_buff = hard_iface->bat_iv.ogm_buff; 239 void *ogm_buff;
228 240
229 batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff; 241 mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
242
243 ogm_buff = hard_iface->bat_iv.ogm_buff;
244 if (!ogm_buff)
245 goto unlock;
246
247 batadv_ogm_packet = ogm_buff;
230 ether_addr_copy(batadv_ogm_packet->orig, 248 ether_addr_copy(batadv_ogm_packet->orig,
231 hard_iface->net_dev->dev_addr); 249 hard_iface->net_dev->dev_addr);
232 ether_addr_copy(batadv_ogm_packet->prev_sender, 250 ether_addr_copy(batadv_ogm_packet->prev_sender,
233 hard_iface->net_dev->dev_addr); 251 hard_iface->net_dev->dev_addr);
252
253unlock:
254 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
234} 255}
235 256
236static void 257static void
237batadv_iv_ogm_primary_iface_set(struct batadv_hard_iface *hard_iface) 258batadv_iv_ogm_primary_iface_set(struct batadv_hard_iface *hard_iface)
238{ 259{
239 struct batadv_ogm_packet *batadv_ogm_packet; 260 struct batadv_ogm_packet *batadv_ogm_packet;
240 unsigned char *ogm_buff = hard_iface->bat_iv.ogm_buff; 261 void *ogm_buff;
241 262
242 batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff; 263 mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
264
265 ogm_buff = hard_iface->bat_iv.ogm_buff;
266 if (!ogm_buff)
267 goto unlock;
268
269 batadv_ogm_packet = ogm_buff;
243 batadv_ogm_packet->ttl = BATADV_TTL; 270 batadv_ogm_packet->ttl = BATADV_TTL;
271
272unlock:
273 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
244} 274}
245 275
246/* when do we schedule our own ogm to be sent */ 276/* when do we schedule our own ogm to be sent */
@@ -742,7 +772,11 @@ batadv_iv_ogm_slide_own_bcast_window(struct batadv_hard_iface *hard_iface)
742 } 772 }
743} 773}
744 774
745static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface) 775/**
776 * batadv_iv_ogm_schedule_buff() - schedule submission of hardif ogm buffer
777 * @hard_iface: interface whose ogm buffer should be transmitted
778 */
779static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)
746{ 780{
747 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); 781 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
748 unsigned char **ogm_buff = &hard_iface->bat_iv.ogm_buff; 782 unsigned char **ogm_buff = &hard_iface->bat_iv.ogm_buff;
@@ -753,9 +787,7 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
753 u16 tvlv_len = 0; 787 u16 tvlv_len = 0;
754 unsigned long send_time; 788 unsigned long send_time;
755 789
756 if (hard_iface->if_status == BATADV_IF_NOT_IN_USE || 790 lockdep_assert_held(&hard_iface->bat_iv.ogm_buff_mutex);
757 hard_iface->if_status == BATADV_IF_TO_BE_REMOVED)
758 return;
759 791
760 /* the interface gets activated here to avoid race conditions between 792 /* the interface gets activated here to avoid race conditions between
761 * the moment of activating the interface in 793 * the moment of activating the interface in
@@ -823,6 +855,17 @@ out:
823 batadv_hardif_put(primary_if); 855 batadv_hardif_put(primary_if);
824} 856}
825 857
858static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
859{
860 if (hard_iface->if_status == BATADV_IF_NOT_IN_USE ||
861 hard_iface->if_status == BATADV_IF_TO_BE_REMOVED)
862 return;
863
864 mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
865 batadv_iv_ogm_schedule_buff(hard_iface);
866 mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
867}
868
826/** 869/**
827 * batadv_iv_orig_ifinfo_sum() - Get bcast_own sum for originator over iterface 870 * batadv_iv_orig_ifinfo_sum() - Get bcast_own sum for originator over iterface
828 * @orig_node: originator which reproadcasted the OGMs directly 871 * @orig_node: originator which reproadcasted the OGMs directly
diff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c
index dc4f7430cb5a..8033f24f506c 100644
--- a/net/batman-adv/bat_v_ogm.c
+++ b/net/batman-adv/bat_v_ogm.c
@@ -18,6 +18,7 @@
18#include <linux/kref.h> 18#include <linux/kref.h>
19#include <linux/list.h> 19#include <linux/list.h>
20#include <linux/lockdep.h> 20#include <linux/lockdep.h>
21#include <linux/mutex.h>
21#include <linux/netdevice.h> 22#include <linux/netdevice.h>
22#include <linux/random.h> 23#include <linux/random.h>
23#include <linux/rculist.h> 24#include <linux/rculist.h>
@@ -256,14 +257,12 @@ static void batadv_v_ogm_queue_on_if(struct sk_buff *skb,
256} 257}
257 258
258/** 259/**
259 * batadv_v_ogm_send() - periodic worker broadcasting the own OGM 260 * batadv_v_ogm_send_softif() - periodic worker broadcasting the own OGM
260 * @work: work queue item 261 * @bat_priv: the bat priv with all the soft interface information
261 */ 262 */
262static void batadv_v_ogm_send(struct work_struct *work) 263static void batadv_v_ogm_send_softif(struct batadv_priv *bat_priv)
263{ 264{
264 struct batadv_hard_iface *hard_iface; 265 struct batadv_hard_iface *hard_iface;
265 struct batadv_priv_bat_v *bat_v;
266 struct batadv_priv *bat_priv;
267 struct batadv_ogm2_packet *ogm_packet; 266 struct batadv_ogm2_packet *ogm_packet;
268 struct sk_buff *skb, *skb_tmp; 267 struct sk_buff *skb, *skb_tmp;
269 unsigned char *ogm_buff; 268 unsigned char *ogm_buff;
@@ -271,8 +270,7 @@ static void batadv_v_ogm_send(struct work_struct *work)
271 u16 tvlv_len = 0; 270 u16 tvlv_len = 0;
272 int ret; 271 int ret;
273 272
274 bat_v = container_of(work, struct batadv_priv_bat_v, ogm_wq.work); 273 lockdep_assert_held(&bat_priv->bat_v.ogm_buff_mutex);
275 bat_priv = container_of(bat_v, struct batadv_priv, bat_v);
276 274
277 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING) 275 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING)
278 goto out; 276 goto out;
@@ -364,6 +362,23 @@ out:
364} 362}
365 363
366/** 364/**
365 * batadv_v_ogm_send() - periodic worker broadcasting the own OGM
366 * @work: work queue item
367 */
368static void batadv_v_ogm_send(struct work_struct *work)
369{
370 struct batadv_priv_bat_v *bat_v;
371 struct batadv_priv *bat_priv;
372
373 bat_v = container_of(work, struct batadv_priv_bat_v, ogm_wq.work);
374 bat_priv = container_of(bat_v, struct batadv_priv, bat_v);
375
376 mutex_lock(&bat_priv->bat_v.ogm_buff_mutex);
377 batadv_v_ogm_send_softif(bat_priv);
378 mutex_unlock(&bat_priv->bat_v.ogm_buff_mutex);
379}
380
381/**
367 * batadv_v_ogm_aggr_work() - OGM queue periodic task per interface 382 * batadv_v_ogm_aggr_work() - OGM queue periodic task per interface
368 * @work: work queue item 383 * @work: work queue item
369 * 384 *
@@ -424,11 +439,15 @@ void batadv_v_ogm_primary_iface_set(struct batadv_hard_iface *primary_iface)
424 struct batadv_priv *bat_priv = netdev_priv(primary_iface->soft_iface); 439 struct batadv_priv *bat_priv = netdev_priv(primary_iface->soft_iface);
425 struct batadv_ogm2_packet *ogm_packet; 440 struct batadv_ogm2_packet *ogm_packet;
426 441
442 mutex_lock(&bat_priv->bat_v.ogm_buff_mutex);
427 if (!bat_priv->bat_v.ogm_buff) 443 if (!bat_priv->bat_v.ogm_buff)
428 return; 444 goto unlock;
429 445
430 ogm_packet = (struct batadv_ogm2_packet *)bat_priv->bat_v.ogm_buff; 446 ogm_packet = (struct batadv_ogm2_packet *)bat_priv->bat_v.ogm_buff;
431 ether_addr_copy(ogm_packet->orig, primary_iface->net_dev->dev_addr); 447 ether_addr_copy(ogm_packet->orig, primary_iface->net_dev->dev_addr);
448
449unlock:
450 mutex_unlock(&bat_priv->bat_v.ogm_buff_mutex);
432} 451}
433 452
434/** 453/**
@@ -1050,6 +1069,8 @@ int batadv_v_ogm_init(struct batadv_priv *bat_priv)
1050 atomic_set(&bat_priv->bat_v.ogm_seqno, random_seqno); 1069 atomic_set(&bat_priv->bat_v.ogm_seqno, random_seqno);
1051 INIT_DELAYED_WORK(&bat_priv->bat_v.ogm_wq, batadv_v_ogm_send); 1070 INIT_DELAYED_WORK(&bat_priv->bat_v.ogm_wq, batadv_v_ogm_send);
1052 1071
1072 mutex_init(&bat_priv->bat_v.ogm_buff_mutex);
1073
1053 return 0; 1074 return 0;
1054} 1075}
1055 1076
@@ -1061,7 +1082,11 @@ void batadv_v_ogm_free(struct batadv_priv *bat_priv)
1061{ 1082{
1062 cancel_delayed_work_sync(&bat_priv->bat_v.ogm_wq); 1083 cancel_delayed_work_sync(&bat_priv->bat_v.ogm_wq);
1063 1084
1085 mutex_lock(&bat_priv->bat_v.ogm_buff_mutex);
1086
1064 kfree(bat_priv->bat_v.ogm_buff); 1087 kfree(bat_priv->bat_v.ogm_buff);
1065 bat_priv->bat_v.ogm_buff = NULL; 1088 bat_priv->bat_v.ogm_buff = NULL;
1066 bat_priv->bat_v.ogm_buff_len = 0; 1089 bat_priv->bat_v.ogm_buff_len = 0;
1090
1091 mutex_unlock(&bat_priv->bat_v.ogm_buff_mutex);
1067} 1092}
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index c90e47342bb0..afb52282d5bd 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -18,6 +18,7 @@
18#include <linux/kref.h> 18#include <linux/kref.h>
19#include <linux/limits.h> 19#include <linux/limits.h>
20#include <linux/list.h> 20#include <linux/list.h>
21#include <linux/mutex.h>
21#include <linux/netdevice.h> 22#include <linux/netdevice.h>
22#include <linux/printk.h> 23#include <linux/printk.h>
23#include <linux/rculist.h> 24#include <linux/rculist.h>
@@ -929,6 +930,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
929 INIT_LIST_HEAD(&hard_iface->list); 930 INIT_LIST_HEAD(&hard_iface->list);
930 INIT_HLIST_HEAD(&hard_iface->neigh_list); 931 INIT_HLIST_HEAD(&hard_iface->neigh_list);
931 932
933 mutex_init(&hard_iface->bat_iv.ogm_buff_mutex);
932 spin_lock_init(&hard_iface->neigh_list_lock); 934 spin_lock_init(&hard_iface->neigh_list_lock);
933 kref_init(&hard_iface->refcount); 935 kref_init(&hard_iface->refcount);
934 936
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index a1146cb10919..5ee8e9a100f9 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -436,7 +436,7 @@ void batadv_interface_rx(struct net_device *soft_iface,
436 /* clean the netfilter state now that the batman-adv header has been 436 /* clean the netfilter state now that the batman-adv header has been
437 * removed 437 * removed
438 */ 438 */
439 nf_reset(skb); 439 nf_reset_ct(skb);
440 440
441 if (unlikely(!pskb_may_pull(skb, ETH_HLEN))) 441 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
442 goto dropped; 442 goto dropped;
@@ -740,36 +740,6 @@ static int batadv_interface_kill_vid(struct net_device *dev, __be16 proto,
740 return 0; 740 return 0;
741} 741}
742 742
743/* batman-adv network devices have devices nesting below it and are a special
744 * "super class" of normal network devices; split their locks off into a
745 * separate class since they always nest.
746 */
747static struct lock_class_key batadv_netdev_xmit_lock_key;
748static struct lock_class_key batadv_netdev_addr_lock_key;
749
750/**
751 * batadv_set_lockdep_class_one() - Set lockdep class for a single tx queue
752 * @dev: device which owns the tx queue
753 * @txq: tx queue to modify
754 * @_unused: always NULL
755 */
756static void batadv_set_lockdep_class_one(struct net_device *dev,
757 struct netdev_queue *txq,
758 void *_unused)
759{
760 lockdep_set_class(&txq->_xmit_lock, &batadv_netdev_xmit_lock_key);
761}
762
763/**
764 * batadv_set_lockdep_class() - Set txq and addr_list lockdep class
765 * @dev: network device to modify
766 */
767static void batadv_set_lockdep_class(struct net_device *dev)
768{
769 lockdep_set_class(&dev->addr_list_lock, &batadv_netdev_addr_lock_key);
770 netdev_for_each_tx_queue(dev, batadv_set_lockdep_class_one, NULL);
771}
772
773/** 743/**
774 * batadv_softif_init_late() - late stage initialization of soft interface 744 * batadv_softif_init_late() - late stage initialization of soft interface
775 * @dev: registered network device to modify 745 * @dev: registered network device to modify
@@ -783,8 +753,6 @@ static int batadv_softif_init_late(struct net_device *dev)
783 int ret; 753 int ret;
784 size_t cnt_len = sizeof(u64) * BATADV_CNT_NUM; 754 size_t cnt_len = sizeof(u64) * BATADV_CNT_NUM;
785 755
786 batadv_set_lockdep_class(dev);
787
788 bat_priv = netdev_priv(dev); 756 bat_priv = netdev_priv(dev);
789 bat_priv->soft_iface = dev; 757 bat_priv->soft_iface = dev;
790 758
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index be7c02aa91e2..4d7f1baee7b7 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -17,6 +17,7 @@
17#include <linux/if.h> 17#include <linux/if.h>
18#include <linux/if_ether.h> 18#include <linux/if_ether.h>
19#include <linux/kref.h> 19#include <linux/kref.h>
20#include <linux/mutex.h>
20#include <linux/netdevice.h> 21#include <linux/netdevice.h>
21#include <linux/netlink.h> 22#include <linux/netlink.h>
22#include <linux/sched.h> /* for linux/wait.h */ 23#include <linux/sched.h> /* for linux/wait.h */
@@ -81,6 +82,9 @@ struct batadv_hard_iface_bat_iv {
81 82
82 /** @ogm_seqno: OGM sequence number - used to identify each OGM */ 83 /** @ogm_seqno: OGM sequence number - used to identify each OGM */
83 atomic_t ogm_seqno; 84 atomic_t ogm_seqno;
85
86 /** @ogm_buff_mutex: lock protecting ogm_buff and ogm_buff_len */
87 struct mutex ogm_buff_mutex;
84}; 88};
85 89
86/** 90/**
@@ -1539,6 +1543,9 @@ struct batadv_priv_bat_v {
1539 /** @ogm_seqno: OGM sequence number - used to identify each OGM */ 1543 /** @ogm_seqno: OGM sequence number - used to identify each OGM */
1540 atomic_t ogm_seqno; 1544 atomic_t ogm_seqno;
1541 1545
1546 /** @ogm_buff_mutex: lock protecting ogm_buff and ogm_buff_len */
1547 struct mutex ogm_buff_mutex;
1548
1542 /** @ogm_wq: workqueue used to schedule OGM transmissions */ 1549 /** @ogm_wq: workqueue used to schedule OGM transmissions */
1543 struct delayed_work ogm_wq; 1550 struct delayed_work ogm_wq;
1544}; 1551};
diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
index bb55d92691b0..4febc82a7c76 100644
--- a/net/bluetooth/6lowpan.c
+++ b/net/bluetooth/6lowpan.c
@@ -571,15 +571,7 @@ static netdev_tx_t bt_xmit(struct sk_buff *skb, struct net_device *netdev)
571 return err < 0 ? NET_XMIT_DROP : err; 571 return err < 0 ? NET_XMIT_DROP : err;
572} 572}
573 573
574static int bt_dev_init(struct net_device *dev)
575{
576 netdev_lockdep_set_classes(dev);
577
578 return 0;
579}
580
581static const struct net_device_ops netdev_ops = { 574static const struct net_device_ops netdev_ops = {
582 .ndo_init = bt_dev_init,
583 .ndo_start_xmit = bt_xmit, 575 .ndo_start_xmit = bt_xmit,
584}; 576};
585 577
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 94ddf19998c7..5f508c50649d 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -460,7 +460,7 @@ __poll_t bt_sock_poll(struct file *file, struct socket *sock,
460 if (sk->sk_state == BT_LISTEN) 460 if (sk->sk_state == BT_LISTEN)
461 return bt_accept_poll(sk); 461 return bt_accept_poll(sk);
462 462
463 if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) 463 if (sk->sk_err || !skb_queue_empty_lockless(&sk->sk_error_queue))
464 mask |= EPOLLERR | 464 mask |= EPOLLERR |
465 (sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0); 465 (sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0);
466 466
@@ -470,7 +470,7 @@ __poll_t bt_sock_poll(struct file *file, struct socket *sock,
470 if (sk->sk_shutdown == SHUTDOWN_MASK) 470 if (sk->sk_shutdown == SHUTDOWN_MASK)
471 mask |= EPOLLHUP; 471 mask |= EPOLLHUP;
472 472
473 if (!skb_queue_empty(&sk->sk_receive_queue)) 473 if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
474 mask |= EPOLLIN | EPOLLRDNORM; 474 mask |= EPOLLIN | EPOLLRDNORM;
475 475
476 if (sk->sk_state == BT_CLOSED) 476 if (sk->sk_state == BT_CLOSED)
diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index 681b72862c16..e804a3016902 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -24,8 +24,6 @@
24const struct nf_br_ops __rcu *nf_br_ops __read_mostly; 24const struct nf_br_ops __rcu *nf_br_ops __read_mostly;
25EXPORT_SYMBOL_GPL(nf_br_ops); 25EXPORT_SYMBOL_GPL(nf_br_ops);
26 26
27static struct lock_class_key bridge_netdev_addr_lock_key;
28
29/* net device transmit always called with BH disabled */ 27/* net device transmit always called with BH disabled */
30netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev) 28netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
31{ 29{
@@ -108,11 +106,6 @@ out:
108 return NETDEV_TX_OK; 106 return NETDEV_TX_OK;
109} 107}
110 108
111static void br_set_lockdep_class(struct net_device *dev)
112{
113 lockdep_set_class(&dev->addr_list_lock, &bridge_netdev_addr_lock_key);
114}
115
116static int br_dev_init(struct net_device *dev) 109static int br_dev_init(struct net_device *dev)
117{ 110{
118 struct net_bridge *br = netdev_priv(dev); 111 struct net_bridge *br = netdev_priv(dev);
@@ -150,7 +143,6 @@ static int br_dev_init(struct net_device *dev)
150 br_mdb_hash_fini(br); 143 br_mdb_hash_fini(br);
151 br_fdb_hash_fini(br); 144 br_fdb_hash_fini(br);
152 } 145 }
153 br_set_lockdep_class(dev);
154 146
155 return err; 147 return err;
156} 148}
diff --git a/net/bridge/netfilter/nf_conntrack_bridge.c b/net/bridge/netfilter/nf_conntrack_bridge.c
index 8842798c29e6..809673222382 100644
--- a/net/bridge/netfilter/nf_conntrack_bridge.c
+++ b/net/bridge/netfilter/nf_conntrack_bridge.c
@@ -33,6 +33,7 @@ static int nf_br_ip_fragment(struct net *net, struct sock *sk,
33{ 33{
34 int frag_max_size = BR_INPUT_SKB_CB(skb)->frag_max_size; 34 int frag_max_size = BR_INPUT_SKB_CB(skb)->frag_max_size;
35 unsigned int hlen, ll_rs, mtu; 35 unsigned int hlen, ll_rs, mtu;
36 ktime_t tstamp = skb->tstamp;
36 struct ip_frag_state state; 37 struct ip_frag_state state;
37 struct iphdr *iph; 38 struct iphdr *iph;
38 int err; 39 int err;
@@ -80,6 +81,7 @@ static int nf_br_ip_fragment(struct net *net, struct sock *sk,
80 if (iter.frag) 81 if (iter.frag)
81 ip_fraglist_prepare(skb, &iter); 82 ip_fraglist_prepare(skb, &iter);
82 83
84 skb->tstamp = tstamp;
83 err = output(net, sk, data, skb); 85 err = output(net, sk, data, skb);
84 if (err || !iter.frag) 86 if (err || !iter.frag)
85 break; 87 break;
@@ -93,7 +95,7 @@ slow_path:
93 * This may also be a clone skbuff, we could preserve the geometry for 95 * This may also be a clone skbuff, we could preserve the geometry for
94 * the copies but probably not worth the effort. 96 * the copies but probably not worth the effort.
95 */ 97 */
96 ip_frag_init(skb, hlen, ll_rs, frag_max_size, &state); 98 ip_frag_init(skb, hlen, ll_rs, frag_max_size, false, &state);
97 99
98 while (state.left > 0) { 100 while (state.left > 0) {
99 struct sk_buff *skb2; 101 struct sk_buff *skb2;
@@ -104,6 +106,7 @@ slow_path:
104 goto blackhole; 106 goto blackhole;
105 } 107 }
106 108
109 skb2->tstamp = tstamp;
107 err = output(net, sk, data, skb2); 110 err = output(net, sk, data, skb2);
108 if (err) 111 if (err)
109 goto blackhole; 112 goto blackhole;
diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
index 13ea920600ae..ef14da50a981 100644
--- a/net/caif/caif_socket.c
+++ b/net/caif/caif_socket.c
@@ -953,7 +953,7 @@ static __poll_t caif_poll(struct file *file,
953 mask |= EPOLLRDHUP; 953 mask |= EPOLLRDHUP;
954 954
955 /* readable? */ 955 /* readable? */
956 if (!skb_queue_empty(&sk->sk_receive_queue) || 956 if (!skb_queue_empty_lockless(&sk->sk_receive_queue) ||
957 (sk->sk_shutdown & RCV_SHUTDOWN)) 957 (sk->sk_shutdown & RCV_SHUTDOWN))
958 mask |= EPOLLIN | EPOLLRDNORM; 958 mask |= EPOLLIN | EPOLLRDNORM;
959 959
diff --git a/net/core/datagram.c b/net/core/datagram.c
index 4cc8dc5db2b7..da3c24ed129c 100644
--- a/net/core/datagram.c
+++ b/net/core/datagram.c
@@ -97,7 +97,7 @@ int __skb_wait_for_more_packets(struct sock *sk, int *err, long *timeo_p,
97 if (error) 97 if (error)
98 goto out_err; 98 goto out_err;
99 99
100 if (sk->sk_receive_queue.prev != skb) 100 if (READ_ONCE(sk->sk_receive_queue.prev) != skb)
101 goto out; 101 goto out;
102 102
103 /* Socket shut down? */ 103 /* Socket shut down? */
@@ -278,7 +278,7 @@ struct sk_buff *__skb_try_recv_datagram(struct sock *sk, unsigned int flags,
278 break; 278 break;
279 279
280 sk_busy_loop(sk, flags & MSG_DONTWAIT); 280 sk_busy_loop(sk, flags & MSG_DONTWAIT);
281 } while (sk->sk_receive_queue.prev != *last); 281 } while (READ_ONCE(sk->sk_receive_queue.prev) != *last);
282 282
283 error = -EAGAIN; 283 error = -EAGAIN;
284 284
@@ -640,7 +640,7 @@ int __zerocopy_sg_from_iter(struct sock *sk, struct sk_buff *skb,
640 skb->len += copied; 640 skb->len += copied;
641 skb->truesize += truesize; 641 skb->truesize += truesize;
642 if (sk && sk->sk_type == SOCK_STREAM) { 642 if (sk && sk->sk_type == SOCK_STREAM) {
643 sk->sk_wmem_queued += truesize; 643 sk_wmem_queued_add(sk, truesize);
644 sk_mem_charge(sk, truesize); 644 sk_mem_charge(sk, truesize);
645 } else { 645 } else {
646 refcount_add(truesize, &skb->sk->sk_wmem_alloc); 646 refcount_add(truesize, &skb->sk->sk_wmem_alloc);
@@ -767,7 +767,7 @@ __poll_t datagram_poll(struct file *file, struct socket *sock,
767 mask = 0; 767 mask = 0;
768 768
769 /* exceptional events? */ 769 /* exceptional events? */
770 if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) 770 if (sk->sk_err || !skb_queue_empty_lockless(&sk->sk_error_queue))
771 mask |= EPOLLERR | 771 mask |= EPOLLERR |
772 (sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0); 772 (sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0);
773 773
@@ -777,7 +777,7 @@ __poll_t datagram_poll(struct file *file, struct socket *sock,
777 mask |= EPOLLHUP; 777 mask |= EPOLLHUP;
778 778
779 /* readable? */ 779 /* readable? */
780 if (!skb_queue_empty(&sk->sk_receive_queue)) 780 if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
781 mask |= EPOLLIN | EPOLLRDNORM; 781 mask |= EPOLLIN | EPOLLRDNORM;
782 782
783 /* Connection-based need to check for termination and startup */ 783 /* Connection-based need to check for termination and startup */
diff --git a/net/core/dev.c b/net/core/dev.c
index bf3ed413abaf..96afd464284a 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -146,6 +146,7 @@
146#include "net-sysfs.h" 146#include "net-sysfs.h"
147 147
148#define MAX_GRO_SKBS 8 148#define MAX_GRO_SKBS 8
149#define MAX_NEST_DEV 8
149 150
150/* This should be increased if a protocol with a bigger head is added. */ 151/* This should be increased if a protocol with a bigger head is added. */
151#define GRO_MAX_HEAD (MAX_HEADER + 128) 152#define GRO_MAX_HEAD (MAX_HEADER + 128)
@@ -276,88 +277,6 @@ static RAW_NOTIFIER_HEAD(netdev_chain);
276DEFINE_PER_CPU_ALIGNED(struct softnet_data, softnet_data); 277DEFINE_PER_CPU_ALIGNED(struct softnet_data, softnet_data);
277EXPORT_PER_CPU_SYMBOL(softnet_data); 278EXPORT_PER_CPU_SYMBOL(softnet_data);
278 279
279#ifdef CONFIG_LOCKDEP
280/*
281 * register_netdevice() inits txq->_xmit_lock and sets lockdep class
282 * according to dev->type
283 */
284static const unsigned short netdev_lock_type[] = {
285 ARPHRD_NETROM, ARPHRD_ETHER, ARPHRD_EETHER, ARPHRD_AX25,
286 ARPHRD_PRONET, ARPHRD_CHAOS, ARPHRD_IEEE802, ARPHRD_ARCNET,
287 ARPHRD_APPLETLK, ARPHRD_DLCI, ARPHRD_ATM, ARPHRD_METRICOM,
288 ARPHRD_IEEE1394, ARPHRD_EUI64, ARPHRD_INFINIBAND, ARPHRD_SLIP,
289 ARPHRD_CSLIP, ARPHRD_SLIP6, ARPHRD_CSLIP6, ARPHRD_RSRVD,
290 ARPHRD_ADAPT, ARPHRD_ROSE, ARPHRD_X25, ARPHRD_HWX25,
291 ARPHRD_PPP, ARPHRD_CISCO, ARPHRD_LAPB, ARPHRD_DDCMP,
292 ARPHRD_RAWHDLC, ARPHRD_TUNNEL, ARPHRD_TUNNEL6, ARPHRD_FRAD,
293 ARPHRD_SKIP, ARPHRD_LOOPBACK, ARPHRD_LOCALTLK, ARPHRD_FDDI,
294 ARPHRD_BIF, ARPHRD_SIT, ARPHRD_IPDDP, ARPHRD_IPGRE,
295 ARPHRD_PIMREG, ARPHRD_HIPPI, ARPHRD_ASH, ARPHRD_ECONET,
296 ARPHRD_IRDA, ARPHRD_FCPP, ARPHRD_FCAL, ARPHRD_FCPL,
297 ARPHRD_FCFABRIC, ARPHRD_IEEE80211, ARPHRD_IEEE80211_PRISM,
298 ARPHRD_IEEE80211_RADIOTAP, ARPHRD_PHONET, ARPHRD_PHONET_PIPE,
299 ARPHRD_IEEE802154, ARPHRD_VOID, ARPHRD_NONE};
300
301static const char *const netdev_lock_name[] = {
302 "_xmit_NETROM", "_xmit_ETHER", "_xmit_EETHER", "_xmit_AX25",
303 "_xmit_PRONET", "_xmit_CHAOS", "_xmit_IEEE802", "_xmit_ARCNET",
304 "_xmit_APPLETLK", "_xmit_DLCI", "_xmit_ATM", "_xmit_METRICOM",
305 "_xmit_IEEE1394", "_xmit_EUI64", "_xmit_INFINIBAND", "_xmit_SLIP",
306 "_xmit_CSLIP", "_xmit_SLIP6", "_xmit_CSLIP6", "_xmit_RSRVD",
307 "_xmit_ADAPT", "_xmit_ROSE", "_xmit_X25", "_xmit_HWX25",
308 "_xmit_PPP", "_xmit_CISCO", "_xmit_LAPB", "_xmit_DDCMP",
309 "_xmit_RAWHDLC", "_xmit_TUNNEL", "_xmit_TUNNEL6", "_xmit_FRAD",
310 "_xmit_SKIP", "_xmit_LOOPBACK", "_xmit_LOCALTLK", "_xmit_FDDI",
311 "_xmit_BIF", "_xmit_SIT", "_xmit_IPDDP", "_xmit_IPGRE",
312 "_xmit_PIMREG", "_xmit_HIPPI", "_xmit_ASH", "_xmit_ECONET",
313 "_xmit_IRDA", "_xmit_FCPP", "_xmit_FCAL", "_xmit_FCPL",
314 "_xmit_FCFABRIC", "_xmit_IEEE80211", "_xmit_IEEE80211_PRISM",
315 "_xmit_IEEE80211_RADIOTAP", "_xmit_PHONET", "_xmit_PHONET_PIPE",
316 "_xmit_IEEE802154", "_xmit_VOID", "_xmit_NONE"};
317
318static struct lock_class_key netdev_xmit_lock_key[ARRAY_SIZE(netdev_lock_type)];
319static struct lock_class_key netdev_addr_lock_key[ARRAY_SIZE(netdev_lock_type)];
320
321static inline unsigned short netdev_lock_pos(unsigned short dev_type)
322{
323 int i;
324
325 for (i = 0; i < ARRAY_SIZE(netdev_lock_type); i++)
326 if (netdev_lock_type[i] == dev_type)
327 return i;
328 /* the last key is used by default */
329 return ARRAY_SIZE(netdev_lock_type) - 1;
330}
331
332static inline void netdev_set_xmit_lockdep_class(spinlock_t *lock,
333 unsigned short dev_type)
334{
335 int i;
336
337 i = netdev_lock_pos(dev_type);
338 lockdep_set_class_and_name(lock, &netdev_xmit_lock_key[i],
339 netdev_lock_name[i]);
340}
341
342static inline void netdev_set_addr_lockdep_class(struct net_device *dev)
343{
344 int i;
345
346 i = netdev_lock_pos(dev->type);
347 lockdep_set_class_and_name(&dev->addr_list_lock,
348 &netdev_addr_lock_key[i],
349 netdev_lock_name[i]);
350}
351#else
352static inline void netdev_set_xmit_lockdep_class(spinlock_t *lock,
353 unsigned short dev_type)
354{
355}
356static inline void netdev_set_addr_lockdep_class(struct net_device *dev)
357{
358}
359#endif
360
361/******************************************************************************* 280/*******************************************************************************
362 * 281 *
363 * Protocol management and registration routines 282 * Protocol management and registration routines
@@ -6489,6 +6408,9 @@ struct netdev_adjacent {
6489 /* upper master flag, there can only be one master device per list */ 6408 /* upper master flag, there can only be one master device per list */
6490 bool master; 6409 bool master;
6491 6410
6411 /* lookup ignore flag */
6412 bool ignore;
6413
6492 /* counter for the number of times this device was added to us */ 6414 /* counter for the number of times this device was added to us */
6493 u16 ref_nr; 6415 u16 ref_nr;
6494 6416
@@ -6511,7 +6433,7 @@ static struct netdev_adjacent *__netdev_find_adj(struct net_device *adj_dev,
6511 return NULL; 6433 return NULL;
6512} 6434}
6513 6435
6514static int __netdev_has_upper_dev(struct net_device *upper_dev, void *data) 6436static int ____netdev_has_upper_dev(struct net_device *upper_dev, void *data)
6515{ 6437{
6516 struct net_device *dev = data; 6438 struct net_device *dev = data;
6517 6439
@@ -6532,7 +6454,7 @@ bool netdev_has_upper_dev(struct net_device *dev,
6532{ 6454{
6533 ASSERT_RTNL(); 6455 ASSERT_RTNL();
6534 6456
6535 return netdev_walk_all_upper_dev_rcu(dev, __netdev_has_upper_dev, 6457 return netdev_walk_all_upper_dev_rcu(dev, ____netdev_has_upper_dev,
6536 upper_dev); 6458 upper_dev);
6537} 6459}
6538EXPORT_SYMBOL(netdev_has_upper_dev); 6460EXPORT_SYMBOL(netdev_has_upper_dev);
@@ -6550,7 +6472,7 @@ EXPORT_SYMBOL(netdev_has_upper_dev);
6550bool netdev_has_upper_dev_all_rcu(struct net_device *dev, 6472bool netdev_has_upper_dev_all_rcu(struct net_device *dev,
6551 struct net_device *upper_dev) 6473 struct net_device *upper_dev)
6552{ 6474{
6553 return !!netdev_walk_all_upper_dev_rcu(dev, __netdev_has_upper_dev, 6475 return !!netdev_walk_all_upper_dev_rcu(dev, ____netdev_has_upper_dev,
6554 upper_dev); 6476 upper_dev);
6555} 6477}
6556EXPORT_SYMBOL(netdev_has_upper_dev_all_rcu); 6478EXPORT_SYMBOL(netdev_has_upper_dev_all_rcu);
@@ -6594,6 +6516,22 @@ struct net_device *netdev_master_upper_dev_get(struct net_device *dev)
6594} 6516}
6595EXPORT_SYMBOL(netdev_master_upper_dev_get); 6517EXPORT_SYMBOL(netdev_master_upper_dev_get);
6596 6518
6519static struct net_device *__netdev_master_upper_dev_get(struct net_device *dev)
6520{
6521 struct netdev_adjacent *upper;
6522
6523 ASSERT_RTNL();
6524
6525 if (list_empty(&dev->adj_list.upper))
6526 return NULL;
6527
6528 upper = list_first_entry(&dev->adj_list.upper,
6529 struct netdev_adjacent, list);
6530 if (likely(upper->master) && !upper->ignore)
6531 return upper->dev;
6532 return NULL;
6533}
6534
6597/** 6535/**
6598 * netdev_has_any_lower_dev - Check if device is linked to some device 6536 * netdev_has_any_lower_dev - Check if device is linked to some device
6599 * @dev: device 6537 * @dev: device
@@ -6644,6 +6582,23 @@ struct net_device *netdev_upper_get_next_dev_rcu(struct net_device *dev,
6644} 6582}
6645EXPORT_SYMBOL(netdev_upper_get_next_dev_rcu); 6583EXPORT_SYMBOL(netdev_upper_get_next_dev_rcu);
6646 6584
6585static struct net_device *__netdev_next_upper_dev(struct net_device *dev,
6586 struct list_head **iter,
6587 bool *ignore)
6588{
6589 struct netdev_adjacent *upper;
6590
6591 upper = list_entry((*iter)->next, struct netdev_adjacent, list);
6592
6593 if (&upper->list == &dev->adj_list.upper)
6594 return NULL;
6595
6596 *iter = &upper->list;
6597 *ignore = upper->ignore;
6598
6599 return upper->dev;
6600}
6601
6647static struct net_device *netdev_next_upper_dev_rcu(struct net_device *dev, 6602static struct net_device *netdev_next_upper_dev_rcu(struct net_device *dev,
6648 struct list_head **iter) 6603 struct list_head **iter)
6649{ 6604{
@@ -6661,34 +6616,111 @@ static struct net_device *netdev_next_upper_dev_rcu(struct net_device *dev,
6661 return upper->dev; 6616 return upper->dev;
6662} 6617}
6663 6618
6619static int __netdev_walk_all_upper_dev(struct net_device *dev,
6620 int (*fn)(struct net_device *dev,
6621 void *data),
6622 void *data)
6623{
6624 struct net_device *udev, *next, *now, *dev_stack[MAX_NEST_DEV + 1];
6625 struct list_head *niter, *iter, *iter_stack[MAX_NEST_DEV + 1];
6626 int ret, cur = 0;
6627 bool ignore;
6628
6629 now = dev;
6630 iter = &dev->adj_list.upper;
6631
6632 while (1) {
6633 if (now != dev) {
6634 ret = fn(now, data);
6635 if (ret)
6636 return ret;
6637 }
6638
6639 next = NULL;
6640 while (1) {
6641 udev = __netdev_next_upper_dev(now, &iter, &ignore);
6642 if (!udev)
6643 break;
6644 if (ignore)
6645 continue;
6646
6647 next = udev;
6648 niter = &udev->adj_list.upper;
6649 dev_stack[cur] = now;
6650 iter_stack[cur++] = iter;
6651 break;
6652 }
6653
6654 if (!next) {
6655 if (!cur)
6656 return 0;
6657 next = dev_stack[--cur];
6658 niter = iter_stack[cur];
6659 }
6660
6661 now = next;
6662 iter = niter;
6663 }
6664
6665 return 0;
6666}
6667
6664int netdev_walk_all_upper_dev_rcu(struct net_device *dev, 6668int netdev_walk_all_upper_dev_rcu(struct net_device *dev,
6665 int (*fn)(struct net_device *dev, 6669 int (*fn)(struct net_device *dev,
6666 void *data), 6670 void *data),
6667 void *data) 6671 void *data)
6668{ 6672{
6669 struct net_device *udev; 6673 struct net_device *udev, *next, *now, *dev_stack[MAX_NEST_DEV + 1];
6670 struct list_head *iter; 6674 struct list_head *niter, *iter, *iter_stack[MAX_NEST_DEV + 1];
6671 int ret; 6675 int ret, cur = 0;
6672 6676
6673 for (iter = &dev->adj_list.upper, 6677 now = dev;
6674 udev = netdev_next_upper_dev_rcu(dev, &iter); 6678 iter = &dev->adj_list.upper;
6675 udev;
6676 udev = netdev_next_upper_dev_rcu(dev, &iter)) {
6677 /* first is the upper device itself */
6678 ret = fn(udev, data);
6679 if (ret)
6680 return ret;
6681 6679
6682 /* then look at all of its upper devices */ 6680 while (1) {
6683 ret = netdev_walk_all_upper_dev_rcu(udev, fn, data); 6681 if (now != dev) {
6684 if (ret) 6682 ret = fn(now, data);
6685 return ret; 6683 if (ret)
6684 return ret;
6685 }
6686
6687 next = NULL;
6688 while (1) {
6689 udev = netdev_next_upper_dev_rcu(now, &iter);
6690 if (!udev)
6691 break;
6692
6693 next = udev;
6694 niter = &udev->adj_list.upper;
6695 dev_stack[cur] = now;
6696 iter_stack[cur++] = iter;
6697 break;
6698 }
6699
6700 if (!next) {
6701 if (!cur)
6702 return 0;
6703 next = dev_stack[--cur];
6704 niter = iter_stack[cur];
6705 }
6706
6707 now = next;
6708 iter = niter;
6686 } 6709 }
6687 6710
6688 return 0; 6711 return 0;
6689} 6712}
6690EXPORT_SYMBOL_GPL(netdev_walk_all_upper_dev_rcu); 6713EXPORT_SYMBOL_GPL(netdev_walk_all_upper_dev_rcu);
6691 6714
6715static bool __netdev_has_upper_dev(struct net_device *dev,
6716 struct net_device *upper_dev)
6717{
6718 ASSERT_RTNL();
6719
6720 return __netdev_walk_all_upper_dev(dev, ____netdev_has_upper_dev,
6721 upper_dev);
6722}
6723
6692/** 6724/**
6693 * netdev_lower_get_next_private - Get the next ->private from the 6725 * netdev_lower_get_next_private - Get the next ->private from the
6694 * lower neighbour list 6726 * lower neighbour list
@@ -6785,34 +6817,119 @@ static struct net_device *netdev_next_lower_dev(struct net_device *dev,
6785 return lower->dev; 6817 return lower->dev;
6786} 6818}
6787 6819
6820static struct net_device *__netdev_next_lower_dev(struct net_device *dev,
6821 struct list_head **iter,
6822 bool *ignore)
6823{
6824 struct netdev_adjacent *lower;
6825
6826 lower = list_entry((*iter)->next, struct netdev_adjacent, list);
6827
6828 if (&lower->list == &dev->adj_list.lower)
6829 return NULL;
6830
6831 *iter = &lower->list;
6832 *ignore = lower->ignore;
6833
6834 return lower->dev;
6835}
6836
6788int netdev_walk_all_lower_dev(struct net_device *dev, 6837int netdev_walk_all_lower_dev(struct net_device *dev,
6789 int (*fn)(struct net_device *dev, 6838 int (*fn)(struct net_device *dev,
6790 void *data), 6839 void *data),
6791 void *data) 6840 void *data)
6792{ 6841{
6793 struct net_device *ldev; 6842 struct net_device *ldev, *next, *now, *dev_stack[MAX_NEST_DEV + 1];
6794 struct list_head *iter; 6843 struct list_head *niter, *iter, *iter_stack[MAX_NEST_DEV + 1];
6795 int ret; 6844 int ret, cur = 0;
6796 6845
6797 for (iter = &dev->adj_list.lower, 6846 now = dev;
6798 ldev = netdev_next_lower_dev(dev, &iter); 6847 iter = &dev->adj_list.lower;
6799 ldev;
6800 ldev = netdev_next_lower_dev(dev, &iter)) {
6801 /* first is the lower device itself */
6802 ret = fn(ldev, data);
6803 if (ret)
6804 return ret;
6805 6848
6806 /* then look at all of its lower devices */ 6849 while (1) {
6807 ret = netdev_walk_all_lower_dev(ldev, fn, data); 6850 if (now != dev) {
6808 if (ret) 6851 ret = fn(now, data);
6809 return ret; 6852 if (ret)
6853 return ret;
6854 }
6855
6856 next = NULL;
6857 while (1) {
6858 ldev = netdev_next_lower_dev(now, &iter);
6859 if (!ldev)
6860 break;
6861
6862 next = ldev;
6863 niter = &ldev->adj_list.lower;
6864 dev_stack[cur] = now;
6865 iter_stack[cur++] = iter;
6866 break;
6867 }
6868
6869 if (!next) {
6870 if (!cur)
6871 return 0;
6872 next = dev_stack[--cur];
6873 niter = iter_stack[cur];
6874 }
6875
6876 now = next;
6877 iter = niter;
6810 } 6878 }
6811 6879
6812 return 0; 6880 return 0;
6813} 6881}
6814EXPORT_SYMBOL_GPL(netdev_walk_all_lower_dev); 6882EXPORT_SYMBOL_GPL(netdev_walk_all_lower_dev);
6815 6883
6884static int __netdev_walk_all_lower_dev(struct net_device *dev,
6885 int (*fn)(struct net_device *dev,
6886 void *data),
6887 void *data)
6888{
6889 struct net_device *ldev, *next, *now, *dev_stack[MAX_NEST_DEV + 1];
6890 struct list_head *niter, *iter, *iter_stack[MAX_NEST_DEV + 1];
6891 int ret, cur = 0;
6892 bool ignore;
6893
6894 now = dev;
6895 iter = &dev->adj_list.lower;
6896
6897 while (1) {
6898 if (now != dev) {
6899 ret = fn(now, data);
6900 if (ret)
6901 return ret;
6902 }
6903
6904 next = NULL;
6905 while (1) {
6906 ldev = __netdev_next_lower_dev(now, &iter, &ignore);
6907 if (!ldev)
6908 break;
6909 if (ignore)
6910 continue;
6911
6912 next = ldev;
6913 niter = &ldev->adj_list.lower;
6914 dev_stack[cur] = now;
6915 iter_stack[cur++] = iter;
6916 break;
6917 }
6918
6919 if (!next) {
6920 if (!cur)
6921 return 0;
6922 next = dev_stack[--cur];
6923 niter = iter_stack[cur];
6924 }
6925
6926 now = next;
6927 iter = niter;
6928 }
6929
6930 return 0;
6931}
6932
6816static struct net_device *netdev_next_lower_dev_rcu(struct net_device *dev, 6933static struct net_device *netdev_next_lower_dev_rcu(struct net_device *dev,
6817 struct list_head **iter) 6934 struct list_head **iter)
6818{ 6935{
@@ -6827,28 +6944,99 @@ static struct net_device *netdev_next_lower_dev_rcu(struct net_device *dev,
6827 return lower->dev; 6944 return lower->dev;
6828} 6945}
6829 6946
6830int netdev_walk_all_lower_dev_rcu(struct net_device *dev, 6947static u8 __netdev_upper_depth(struct net_device *dev)
6831 int (*fn)(struct net_device *dev, 6948{
6832 void *data), 6949 struct net_device *udev;
6833 void *data) 6950 struct list_head *iter;
6951 u8 max_depth = 0;
6952 bool ignore;
6953
6954 for (iter = &dev->adj_list.upper,
6955 udev = __netdev_next_upper_dev(dev, &iter, &ignore);
6956 udev;
6957 udev = __netdev_next_upper_dev(dev, &iter, &ignore)) {
6958 if (ignore)
6959 continue;
6960 if (max_depth < udev->upper_level)
6961 max_depth = udev->upper_level;
6962 }
6963
6964 return max_depth;
6965}
6966
6967static u8 __netdev_lower_depth(struct net_device *dev)
6834{ 6968{
6835 struct net_device *ldev; 6969 struct net_device *ldev;
6836 struct list_head *iter; 6970 struct list_head *iter;
6837 int ret; 6971 u8 max_depth = 0;
6972 bool ignore;
6838 6973
6839 for (iter = &dev->adj_list.lower, 6974 for (iter = &dev->adj_list.lower,
6840 ldev = netdev_next_lower_dev_rcu(dev, &iter); 6975 ldev = __netdev_next_lower_dev(dev, &iter, &ignore);
6841 ldev; 6976 ldev;
6842 ldev = netdev_next_lower_dev_rcu(dev, &iter)) { 6977 ldev = __netdev_next_lower_dev(dev, &iter, &ignore)) {
6843 /* first is the lower device itself */ 6978 if (ignore)
6844 ret = fn(ldev, data); 6979 continue;
6845 if (ret) 6980 if (max_depth < ldev->lower_level)
6846 return ret; 6981 max_depth = ldev->lower_level;
6982 }
6847 6983
6848 /* then look at all of its lower devices */ 6984 return max_depth;
6849 ret = netdev_walk_all_lower_dev_rcu(ldev, fn, data); 6985}
6850 if (ret) 6986
6851 return ret; 6987static int __netdev_update_upper_level(struct net_device *dev, void *data)
6988{
6989 dev->upper_level = __netdev_upper_depth(dev) + 1;
6990 return 0;
6991}
6992
6993static int __netdev_update_lower_level(struct net_device *dev, void *data)
6994{
6995 dev->lower_level = __netdev_lower_depth(dev) + 1;
6996 return 0;
6997}
6998
6999int netdev_walk_all_lower_dev_rcu(struct net_device *dev,
7000 int (*fn)(struct net_device *dev,
7001 void *data),
7002 void *data)
7003{
7004 struct net_device *ldev, *next, *now, *dev_stack[MAX_NEST_DEV + 1];
7005 struct list_head *niter, *iter, *iter_stack[MAX_NEST_DEV + 1];
7006 int ret, cur = 0;
7007
7008 now = dev;
7009 iter = &dev->adj_list.lower;
7010
7011 while (1) {
7012 if (now != dev) {
7013 ret = fn(now, data);
7014 if (ret)
7015 return ret;
7016 }
7017
7018 next = NULL;
7019 while (1) {
7020 ldev = netdev_next_lower_dev_rcu(now, &iter);
7021 if (!ldev)
7022 break;
7023
7024 next = ldev;
7025 niter = &ldev->adj_list.lower;
7026 dev_stack[cur] = now;
7027 iter_stack[cur++] = iter;
7028 break;
7029 }
7030
7031 if (!next) {
7032 if (!cur)
7033 return 0;
7034 next = dev_stack[--cur];
7035 niter = iter_stack[cur];
7036 }
7037
7038 now = next;
7039 iter = niter;
6852 } 7040 }
6853 7041
6854 return 0; 7042 return 0;
@@ -6952,6 +7140,7 @@ static int __netdev_adjacent_dev_insert(struct net_device *dev,
6952 adj->master = master; 7140 adj->master = master;
6953 adj->ref_nr = 1; 7141 adj->ref_nr = 1;
6954 adj->private = private; 7142 adj->private = private;
7143 adj->ignore = false;
6955 dev_hold(adj_dev); 7144 dev_hold(adj_dev);
6956 7145
6957 pr_debug("Insert adjacency: dev %s adj_dev %s adj->ref_nr %d; dev_hold on %s\n", 7146 pr_debug("Insert adjacency: dev %s adj_dev %s adj->ref_nr %d; dev_hold on %s\n",
@@ -7102,14 +7291,17 @@ static int __netdev_upper_dev_link(struct net_device *dev,
7102 return -EBUSY; 7291 return -EBUSY;
7103 7292
7104 /* To prevent loops, check if dev is not upper device to upper_dev. */ 7293 /* To prevent loops, check if dev is not upper device to upper_dev. */
7105 if (netdev_has_upper_dev(upper_dev, dev)) 7294 if (__netdev_has_upper_dev(upper_dev, dev))
7106 return -EBUSY; 7295 return -EBUSY;
7107 7296
7297 if ((dev->lower_level + upper_dev->upper_level) > MAX_NEST_DEV)
7298 return -EMLINK;
7299
7108 if (!master) { 7300 if (!master) {
7109 if (netdev_has_upper_dev(dev, upper_dev)) 7301 if (__netdev_has_upper_dev(dev, upper_dev))
7110 return -EEXIST; 7302 return -EEXIST;
7111 } else { 7303 } else {
7112 master_dev = netdev_master_upper_dev_get(dev); 7304 master_dev = __netdev_master_upper_dev_get(dev);
7113 if (master_dev) 7305 if (master_dev)
7114 return master_dev == upper_dev ? -EEXIST : -EBUSY; 7306 return master_dev == upper_dev ? -EEXIST : -EBUSY;
7115 } 7307 }
@@ -7131,6 +7323,13 @@ static int __netdev_upper_dev_link(struct net_device *dev,
7131 if (ret) 7323 if (ret)
7132 goto rollback; 7324 goto rollback;
7133 7325
7326 __netdev_update_upper_level(dev, NULL);
7327 __netdev_walk_all_lower_dev(dev, __netdev_update_upper_level, NULL);
7328
7329 __netdev_update_lower_level(upper_dev, NULL);
7330 __netdev_walk_all_upper_dev(upper_dev, __netdev_update_lower_level,
7331 NULL);
7332
7134 return 0; 7333 return 0;
7135 7334
7136rollback: 7335rollback:
@@ -7213,9 +7412,96 @@ void netdev_upper_dev_unlink(struct net_device *dev,
7213 7412
7214 call_netdevice_notifiers_info(NETDEV_CHANGEUPPER, 7413 call_netdevice_notifiers_info(NETDEV_CHANGEUPPER,
7215 &changeupper_info.info); 7414 &changeupper_info.info);
7415
7416 __netdev_update_upper_level(dev, NULL);
7417 __netdev_walk_all_lower_dev(dev, __netdev_update_upper_level, NULL);
7418
7419 __netdev_update_lower_level(upper_dev, NULL);
7420 __netdev_walk_all_upper_dev(upper_dev, __netdev_update_lower_level,
7421 NULL);
7216} 7422}
7217EXPORT_SYMBOL(netdev_upper_dev_unlink); 7423EXPORT_SYMBOL(netdev_upper_dev_unlink);
7218 7424
7425static void __netdev_adjacent_dev_set(struct net_device *upper_dev,
7426 struct net_device *lower_dev,
7427 bool val)
7428{
7429 struct netdev_adjacent *adj;
7430
7431 adj = __netdev_find_adj(lower_dev, &upper_dev->adj_list.lower);
7432 if (adj)
7433 adj->ignore = val;
7434
7435 adj = __netdev_find_adj(upper_dev, &lower_dev->adj_list.upper);
7436 if (adj)
7437 adj->ignore = val;
7438}
7439
7440static void netdev_adjacent_dev_disable(struct net_device *upper_dev,
7441 struct net_device *lower_dev)
7442{
7443 __netdev_adjacent_dev_set(upper_dev, lower_dev, true);
7444}
7445
7446static void netdev_adjacent_dev_enable(struct net_device *upper_dev,
7447 struct net_device *lower_dev)
7448{
7449 __netdev_adjacent_dev_set(upper_dev, lower_dev, false);
7450}
7451
7452int netdev_adjacent_change_prepare(struct net_device *old_dev,
7453 struct net_device *new_dev,
7454 struct net_device *dev,
7455 struct netlink_ext_ack *extack)
7456{
7457 int err;
7458
7459 if (!new_dev)
7460 return 0;
7461
7462 if (old_dev && new_dev != old_dev)
7463 netdev_adjacent_dev_disable(dev, old_dev);
7464
7465 err = netdev_upper_dev_link(new_dev, dev, extack);
7466 if (err) {
7467 if (old_dev && new_dev != old_dev)
7468 netdev_adjacent_dev_enable(dev, old_dev);
7469 return err;
7470 }
7471
7472 return 0;
7473}
7474EXPORT_SYMBOL(netdev_adjacent_change_prepare);
7475
7476void netdev_adjacent_change_commit(struct net_device *old_dev,
7477 struct net_device *new_dev,
7478 struct net_device *dev)
7479{
7480 if (!new_dev || !old_dev)
7481 return;
7482
7483 if (new_dev == old_dev)
7484 return;
7485
7486 netdev_adjacent_dev_enable(dev, old_dev);
7487 netdev_upper_dev_unlink(old_dev, dev);
7488}
7489EXPORT_SYMBOL(netdev_adjacent_change_commit);
7490
7491void netdev_adjacent_change_abort(struct net_device *old_dev,
7492 struct net_device *new_dev,
7493 struct net_device *dev)
7494{
7495 if (!new_dev)
7496 return;
7497
7498 if (old_dev && new_dev != old_dev)
7499 netdev_adjacent_dev_enable(dev, old_dev);
7500
7501 netdev_upper_dev_unlink(new_dev, dev);
7502}
7503EXPORT_SYMBOL(netdev_adjacent_change_abort);
7504
7219/** 7505/**
7220 * netdev_bonding_info_change - Dispatch event about slave change 7506 * netdev_bonding_info_change - Dispatch event about slave change
7221 * @dev: device 7507 * @dev: device
@@ -7329,25 +7615,6 @@ void *netdev_lower_dev_get_private(struct net_device *dev,
7329EXPORT_SYMBOL(netdev_lower_dev_get_private); 7615EXPORT_SYMBOL(netdev_lower_dev_get_private);
7330 7616
7331 7617
7332int dev_get_nest_level(struct net_device *dev)
7333{
7334 struct net_device *lower = NULL;
7335 struct list_head *iter;
7336 int max_nest = -1;
7337 int nest;
7338
7339 ASSERT_RTNL();
7340
7341 netdev_for_each_lower_dev(dev, lower, iter) {
7342 nest = dev_get_nest_level(lower);
7343 if (max_nest < nest)
7344 max_nest = nest;
7345 }
7346
7347 return max_nest + 1;
7348}
7349EXPORT_SYMBOL(dev_get_nest_level);
7350
7351/** 7618/**
7352 * netdev_lower_change - Dispatch event about lower device state change 7619 * netdev_lower_change - Dispatch event about lower device state change
7353 * @lower_dev: device 7620 * @lower_dev: device
@@ -8619,7 +8886,7 @@ static void netdev_init_one_queue(struct net_device *dev,
8619{ 8886{
8620 /* Initialize queue lock */ 8887 /* Initialize queue lock */
8621 spin_lock_init(&queue->_xmit_lock); 8888 spin_lock_init(&queue->_xmit_lock);
8622 netdev_set_xmit_lockdep_class(&queue->_xmit_lock, dev->type); 8889 lockdep_set_class(&queue->_xmit_lock, &dev->qdisc_xmit_lock_key);
8623 queue->xmit_lock_owner = -1; 8890 queue->xmit_lock_owner = -1;
8624 netdev_queue_numa_node_write(queue, NUMA_NO_NODE); 8891 netdev_queue_numa_node_write(queue, NUMA_NO_NODE);
8625 queue->dev = dev; 8892 queue->dev = dev;
@@ -8666,6 +8933,43 @@ void netif_tx_stop_all_queues(struct net_device *dev)
8666} 8933}
8667EXPORT_SYMBOL(netif_tx_stop_all_queues); 8934EXPORT_SYMBOL(netif_tx_stop_all_queues);
8668 8935
8936static void netdev_register_lockdep_key(struct net_device *dev)
8937{
8938 lockdep_register_key(&dev->qdisc_tx_busylock_key);
8939 lockdep_register_key(&dev->qdisc_running_key);
8940 lockdep_register_key(&dev->qdisc_xmit_lock_key);
8941 lockdep_register_key(&dev->addr_list_lock_key);
8942}
8943
8944static void netdev_unregister_lockdep_key(struct net_device *dev)
8945{
8946 lockdep_unregister_key(&dev->qdisc_tx_busylock_key);
8947 lockdep_unregister_key(&dev->qdisc_running_key);
8948 lockdep_unregister_key(&dev->qdisc_xmit_lock_key);
8949 lockdep_unregister_key(&dev->addr_list_lock_key);
8950}
8951
8952void netdev_update_lockdep_key(struct net_device *dev)
8953{
8954 struct netdev_queue *queue;
8955 int i;
8956
8957 lockdep_unregister_key(&dev->qdisc_xmit_lock_key);
8958 lockdep_unregister_key(&dev->addr_list_lock_key);
8959
8960 lockdep_register_key(&dev->qdisc_xmit_lock_key);
8961 lockdep_register_key(&dev->addr_list_lock_key);
8962
8963 lockdep_set_class(&dev->addr_list_lock, &dev->addr_list_lock_key);
8964 for (i = 0; i < dev->num_tx_queues; i++) {
8965 queue = netdev_get_tx_queue(dev, i);
8966
8967 lockdep_set_class(&queue->_xmit_lock,
8968 &dev->qdisc_xmit_lock_key);
8969 }
8970}
8971EXPORT_SYMBOL(netdev_update_lockdep_key);
8972
8669/** 8973/**
8670 * register_netdevice - register a network device 8974 * register_netdevice - register a network device
8671 * @dev: device to register 8975 * @dev: device to register
@@ -8700,7 +9004,7 @@ int register_netdevice(struct net_device *dev)
8700 BUG_ON(!net); 9004 BUG_ON(!net);
8701 9005
8702 spin_lock_init(&dev->addr_list_lock); 9006 spin_lock_init(&dev->addr_list_lock);
8703 netdev_set_addr_lockdep_class(dev); 9007 lockdep_set_class(&dev->addr_list_lock, &dev->addr_list_lock_key);
8704 9008
8705 ret = dev_get_valid_name(net, dev, dev->name); 9009 ret = dev_get_valid_name(net, dev, dev->name);
8706 if (ret < 0) 9010 if (ret < 0)
@@ -9210,8 +9514,12 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
9210 9514
9211 dev_net_set(dev, &init_net); 9515 dev_net_set(dev, &init_net);
9212 9516
9517 netdev_register_lockdep_key(dev);
9518
9213 dev->gso_max_size = GSO_MAX_SIZE; 9519 dev->gso_max_size = GSO_MAX_SIZE;
9214 dev->gso_max_segs = GSO_MAX_SEGS; 9520 dev->gso_max_segs = GSO_MAX_SEGS;
9521 dev->upper_level = 1;
9522 dev->lower_level = 1;
9215 9523
9216 INIT_LIST_HEAD(&dev->napi_list); 9524 INIT_LIST_HEAD(&dev->napi_list);
9217 INIT_LIST_HEAD(&dev->unreg_list); 9525 INIT_LIST_HEAD(&dev->unreg_list);
@@ -9292,6 +9600,8 @@ void free_netdev(struct net_device *dev)
9292 free_percpu(dev->pcpu_refcnt); 9600 free_percpu(dev->pcpu_refcnt);
9293 dev->pcpu_refcnt = NULL; 9601 dev->pcpu_refcnt = NULL;
9294 9602
9603 netdev_unregister_lockdep_key(dev);
9604
9295 /* Compatibility with error handling in drivers */ 9605 /* Compatibility with error handling in drivers */
9296 if (dev->reg_state == NETREG_UNINITIALIZED) { 9606 if (dev->reg_state == NETREG_UNINITIALIZED) {
9297 netdev_freemem(dev); 9607 netdev_freemem(dev);
@@ -9460,7 +9770,7 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
9460 call_netdevice_notifiers(NETDEV_UNREGISTER, dev); 9770 call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
9461 rcu_barrier(); 9771 rcu_barrier();
9462 9772
9463 new_nsid = peernet2id_alloc(dev_net(dev), net); 9773 new_nsid = peernet2id_alloc(dev_net(dev), net, GFP_KERNEL);
9464 /* If there is an ifindex conflict assign a new one */ 9774 /* If there is an ifindex conflict assign a new one */
9465 if (__dev_get_by_index(net, dev->ifindex)) 9775 if (__dev_get_by_index(net, dev->ifindex))
9466 new_ifindex = dev_new_index(net); 9776 new_ifindex = dev_new_index(net);
diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c
index 6393ba930097..2f949b5a1eb9 100644
--- a/net/core/dev_addr_lists.c
+++ b/net/core/dev_addr_lists.c
@@ -637,7 +637,7 @@ int dev_uc_sync(struct net_device *to, struct net_device *from)
637 if (to->addr_len != from->addr_len) 637 if (to->addr_len != from->addr_len)
638 return -EINVAL; 638 return -EINVAL;
639 639
640 netif_addr_lock_nested(to); 640 netif_addr_lock(to);
641 err = __hw_addr_sync(&to->uc, &from->uc, to->addr_len); 641 err = __hw_addr_sync(&to->uc, &from->uc, to->addr_len);
642 if (!err) 642 if (!err)
643 __dev_set_rx_mode(to); 643 __dev_set_rx_mode(to);
@@ -667,7 +667,7 @@ int dev_uc_sync_multiple(struct net_device *to, struct net_device *from)
667 if (to->addr_len != from->addr_len) 667 if (to->addr_len != from->addr_len)
668 return -EINVAL; 668 return -EINVAL;
669 669
670 netif_addr_lock_nested(to); 670 netif_addr_lock(to);
671 err = __hw_addr_sync_multiple(&to->uc, &from->uc, to->addr_len); 671 err = __hw_addr_sync_multiple(&to->uc, &from->uc, to->addr_len);
672 if (!err) 672 if (!err)
673 __dev_set_rx_mode(to); 673 __dev_set_rx_mode(to);
@@ -691,7 +691,7 @@ void dev_uc_unsync(struct net_device *to, struct net_device *from)
691 return; 691 return;
692 692
693 netif_addr_lock_bh(from); 693 netif_addr_lock_bh(from);
694 netif_addr_lock_nested(to); 694 netif_addr_lock(to);
695 __hw_addr_unsync(&to->uc, &from->uc, to->addr_len); 695 __hw_addr_unsync(&to->uc, &from->uc, to->addr_len);
696 __dev_set_rx_mode(to); 696 __dev_set_rx_mode(to);
697 netif_addr_unlock(to); 697 netif_addr_unlock(to);
@@ -858,7 +858,7 @@ int dev_mc_sync(struct net_device *to, struct net_device *from)
858 if (to->addr_len != from->addr_len) 858 if (to->addr_len != from->addr_len)
859 return -EINVAL; 859 return -EINVAL;
860 860
861 netif_addr_lock_nested(to); 861 netif_addr_lock(to);
862 err = __hw_addr_sync(&to->mc, &from->mc, to->addr_len); 862 err = __hw_addr_sync(&to->mc, &from->mc, to->addr_len);
863 if (!err) 863 if (!err)
864 __dev_set_rx_mode(to); 864 __dev_set_rx_mode(to);
@@ -888,7 +888,7 @@ int dev_mc_sync_multiple(struct net_device *to, struct net_device *from)
888 if (to->addr_len != from->addr_len) 888 if (to->addr_len != from->addr_len)
889 return -EINVAL; 889 return -EINVAL;
890 890
891 netif_addr_lock_nested(to); 891 netif_addr_lock(to);
892 err = __hw_addr_sync_multiple(&to->mc, &from->mc, to->addr_len); 892 err = __hw_addr_sync_multiple(&to->mc, &from->mc, to->addr_len);
893 if (!err) 893 if (!err)
894 __dev_set_rx_mode(to); 894 __dev_set_rx_mode(to);
@@ -912,7 +912,7 @@ void dev_mc_unsync(struct net_device *to, struct net_device *from)
912 return; 912 return;
913 913
914 netif_addr_lock_bh(from); 914 netif_addr_lock_bh(from);
915 netif_addr_lock_nested(to); 915 netif_addr_lock(to);
916 __hw_addr_unsync(&to->mc, &from->mc, to->addr_len); 916 __hw_addr_unsync(&to->mc, &from->mc, to->addr_len);
917 __dev_set_rx_mode(to); 917 __dev_set_rx_mode(to);
918 netif_addr_unlock(to); 918 netif_addr_unlock(to);
diff --git a/net/core/devlink.c b/net/core/devlink.c
index e48680efe54a..f80151eeaf51 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -3172,7 +3172,7 @@ static int devlink_nl_cmd_param_get_dumpit(struct sk_buff *msg,
3172 NETLINK_CB(cb->skb).portid, 3172 NETLINK_CB(cb->skb).portid,
3173 cb->nlh->nlmsg_seq, 3173 cb->nlh->nlmsg_seq,
3174 NLM_F_MULTI); 3174 NLM_F_MULTI);
3175 if (err) { 3175 if (err && err != -EOPNOTSUPP) {
3176 mutex_unlock(&devlink->lock); 3176 mutex_unlock(&devlink->lock);
3177 goto out; 3177 goto out;
3178 } 3178 }
@@ -3432,7 +3432,7 @@ static int devlink_nl_cmd_port_param_get_dumpit(struct sk_buff *msg,
3432 NETLINK_CB(cb->skb).portid, 3432 NETLINK_CB(cb->skb).portid,
3433 cb->nlh->nlmsg_seq, 3433 cb->nlh->nlmsg_seq,
3434 NLM_F_MULTI); 3434 NLM_F_MULTI);
3435 if (err) { 3435 if (err && err != -EOPNOTSUPP) {
3436 mutex_unlock(&devlink->lock); 3436 mutex_unlock(&devlink->lock);
3437 goto out; 3437 goto out;
3438 } 3438 }
@@ -4088,7 +4088,7 @@ static int devlink_nl_cmd_info_get_dumpit(struct sk_buff *msg,
4088 cb->nlh->nlmsg_seq, NLM_F_MULTI, 4088 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4089 cb->extack); 4089 cb->extack);
4090 mutex_unlock(&devlink->lock); 4090 mutex_unlock(&devlink->lock);
4091 if (err) 4091 if (err && err != -EOPNOTSUPP)
4092 break; 4092 break;
4093 idx++; 4093 idx++;
4094 } 4094 }
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index c763106c73fc..cd9bc67381b2 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -1396,11 +1396,13 @@ static int ethtool_reset(struct net_device *dev, char __user *useraddr)
1396 1396
1397static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) 1397static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
1398{ 1398{
1399 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL }; 1399 struct ethtool_wolinfo wol;
1400 1400
1401 if (!dev->ethtool_ops->get_wol) 1401 if (!dev->ethtool_ops->get_wol)
1402 return -EOPNOTSUPP; 1402 return -EOPNOTSUPP;
1403 1403
1404 memset(&wol, 0, sizeof(struct ethtool_wolinfo));
1405 wol.cmd = ETHTOOL_GWOL;
1404 dev->ethtool_ops->get_wol(dev, &wol); 1406 dev->ethtool_ops->get_wol(dev, &wol);
1405 1407
1406 if (copy_to_user(useraddr, &wol, sizeof(wol))) 1408 if (copy_to_user(useraddr, &wol, sizeof(wol)))
diff --git a/net/core/filter.c b/net/core/filter.c
index ed6563622ce3..3fed5755494b 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4252,12 +4252,14 @@ BPF_CALL_5(bpf_setsockopt, struct bpf_sock_ops_kern *, bpf_sock,
4252 case SO_RCVBUF: 4252 case SO_RCVBUF:
4253 val = min_t(u32, val, sysctl_rmem_max); 4253 val = min_t(u32, val, sysctl_rmem_max);
4254 sk->sk_userlocks |= SOCK_RCVBUF_LOCK; 4254 sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
4255 sk->sk_rcvbuf = max_t(int, val * 2, SOCK_MIN_RCVBUF); 4255 WRITE_ONCE(sk->sk_rcvbuf,
4256 max_t(int, val * 2, SOCK_MIN_RCVBUF));
4256 break; 4257 break;
4257 case SO_SNDBUF: 4258 case SO_SNDBUF:
4258 val = min_t(u32, val, sysctl_wmem_max); 4259 val = min_t(u32, val, sysctl_wmem_max);
4259 sk->sk_userlocks |= SOCK_SNDBUF_LOCK; 4260 sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
4260 sk->sk_sndbuf = max_t(int, val * 2, SOCK_MIN_SNDBUF); 4261 WRITE_ONCE(sk->sk_sndbuf,
4262 max_t(int, val * 2, SOCK_MIN_SNDBUF));
4261 break; 4263 break;
4262 case SO_MAX_PACING_RATE: /* 32bit version */ 4264 case SO_MAX_PACING_RATE: /* 32bit version */
4263 if (val != ~0U) 4265 if (val != ~0U)
@@ -4274,7 +4276,7 @@ BPF_CALL_5(bpf_setsockopt, struct bpf_sock_ops_kern *, bpf_sock,
4274 case SO_RCVLOWAT: 4276 case SO_RCVLOWAT:
4275 if (val < 0) 4277 if (val < 0)
4276 val = INT_MAX; 4278 val = INT_MAX;
4277 sk->sk_rcvlowat = val ? : 1; 4279 WRITE_ONCE(sk->sk_rcvlowat, val ? : 1);
4278 break; 4280 break;
4279 case SO_MARK: 4281 case SO_MARK:
4280 if (sk->sk_mark != val) { 4282 if (sk->sk_mark != val) {
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 7c09d87d3269..68eda10d0680 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -1350,30 +1350,21 @@ out_bad:
1350} 1350}
1351EXPORT_SYMBOL(__skb_flow_dissect); 1351EXPORT_SYMBOL(__skb_flow_dissect);
1352 1352
1353static u32 hashrnd __read_mostly; 1353static siphash_key_t hashrnd __read_mostly;
1354static __always_inline void __flow_hash_secret_init(void) 1354static __always_inline void __flow_hash_secret_init(void)
1355{ 1355{
1356 net_get_random_once(&hashrnd, sizeof(hashrnd)); 1356 net_get_random_once(&hashrnd, sizeof(hashrnd));
1357} 1357}
1358 1358
1359static __always_inline u32 __flow_hash_words(const u32 *words, u32 length, 1359static const void *flow_keys_hash_start(const struct flow_keys *flow)
1360 u32 keyval)
1361{ 1360{
1362 return jhash2(words, length, keyval); 1361 BUILD_BUG_ON(FLOW_KEYS_HASH_OFFSET % SIPHASH_ALIGNMENT);
1363} 1362 return &flow->FLOW_KEYS_HASH_START_FIELD;
1364
1365static inline const u32 *flow_keys_hash_start(const struct flow_keys *flow)
1366{
1367 const void *p = flow;
1368
1369 BUILD_BUG_ON(FLOW_KEYS_HASH_OFFSET % sizeof(u32));
1370 return (const u32 *)(p + FLOW_KEYS_HASH_OFFSET);
1371} 1363}
1372 1364
1373static inline size_t flow_keys_hash_length(const struct flow_keys *flow) 1365static inline size_t flow_keys_hash_length(const struct flow_keys *flow)
1374{ 1366{
1375 size_t diff = FLOW_KEYS_HASH_OFFSET + sizeof(flow->addrs); 1367 size_t diff = FLOW_KEYS_HASH_OFFSET + sizeof(flow->addrs);
1376 BUILD_BUG_ON((sizeof(*flow) - FLOW_KEYS_HASH_OFFSET) % sizeof(u32));
1377 BUILD_BUG_ON(offsetof(typeof(*flow), addrs) != 1368 BUILD_BUG_ON(offsetof(typeof(*flow), addrs) !=
1378 sizeof(*flow) - sizeof(flow->addrs)); 1369 sizeof(*flow) - sizeof(flow->addrs));
1379 1370
@@ -1388,7 +1379,7 @@ static inline size_t flow_keys_hash_length(const struct flow_keys *flow)
1388 diff -= sizeof(flow->addrs.tipckey); 1379 diff -= sizeof(flow->addrs.tipckey);
1389 break; 1380 break;
1390 } 1381 }
1391 return (sizeof(*flow) - diff) / sizeof(u32); 1382 return sizeof(*flow) - diff;
1392} 1383}
1393 1384
1394__be32 flow_get_u32_src(const struct flow_keys *flow) 1385__be32 flow_get_u32_src(const struct flow_keys *flow)
@@ -1454,14 +1445,15 @@ static inline void __flow_hash_consistentify(struct flow_keys *keys)
1454 } 1445 }
1455} 1446}
1456 1447
1457static inline u32 __flow_hash_from_keys(struct flow_keys *keys, u32 keyval) 1448static inline u32 __flow_hash_from_keys(struct flow_keys *keys,
1449 const siphash_key_t *keyval)
1458{ 1450{
1459 u32 hash; 1451 u32 hash;
1460 1452
1461 __flow_hash_consistentify(keys); 1453 __flow_hash_consistentify(keys);
1462 1454
1463 hash = __flow_hash_words(flow_keys_hash_start(keys), 1455 hash = siphash(flow_keys_hash_start(keys),
1464 flow_keys_hash_length(keys), keyval); 1456 flow_keys_hash_length(keys), keyval);
1465 if (!hash) 1457 if (!hash)
1466 hash = 1; 1458 hash = 1;
1467 1459
@@ -1471,12 +1463,13 @@ static inline u32 __flow_hash_from_keys(struct flow_keys *keys, u32 keyval)
1471u32 flow_hash_from_keys(struct flow_keys *keys) 1463u32 flow_hash_from_keys(struct flow_keys *keys)
1472{ 1464{
1473 __flow_hash_secret_init(); 1465 __flow_hash_secret_init();
1474 return __flow_hash_from_keys(keys, hashrnd); 1466 return __flow_hash_from_keys(keys, &hashrnd);
1475} 1467}
1476EXPORT_SYMBOL(flow_hash_from_keys); 1468EXPORT_SYMBOL(flow_hash_from_keys);
1477 1469
1478static inline u32 ___skb_get_hash(const struct sk_buff *skb, 1470static inline u32 ___skb_get_hash(const struct sk_buff *skb,
1479 struct flow_keys *keys, u32 keyval) 1471 struct flow_keys *keys,
1472 const siphash_key_t *keyval)
1480{ 1473{
1481 skb_flow_dissect_flow_keys(skb, keys, 1474 skb_flow_dissect_flow_keys(skb, keys,
1482 FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL); 1475 FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL);
@@ -1524,7 +1517,7 @@ u32 __skb_get_hash_symmetric(const struct sk_buff *skb)
1524 &keys, NULL, 0, 0, 0, 1517 &keys, NULL, 0, 0, 0,
1525 FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL); 1518 FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL);
1526 1519
1527 return __flow_hash_from_keys(&keys, hashrnd); 1520 return __flow_hash_from_keys(&keys, &hashrnd);
1528} 1521}
1529EXPORT_SYMBOL_GPL(__skb_get_hash_symmetric); 1522EXPORT_SYMBOL_GPL(__skb_get_hash_symmetric);
1530 1523
@@ -1544,13 +1537,14 @@ void __skb_get_hash(struct sk_buff *skb)
1544 1537
1545 __flow_hash_secret_init(); 1538 __flow_hash_secret_init();
1546 1539
1547 hash = ___skb_get_hash(skb, &keys, hashrnd); 1540 hash = ___skb_get_hash(skb, &keys, &hashrnd);
1548 1541
1549 __skb_set_sw_hash(skb, hash, flow_keys_have_l4(&keys)); 1542 __skb_set_sw_hash(skb, hash, flow_keys_have_l4(&keys));
1550} 1543}
1551EXPORT_SYMBOL(__skb_get_hash); 1544EXPORT_SYMBOL(__skb_get_hash);
1552 1545
1553__u32 skb_get_hash_perturb(const struct sk_buff *skb, u32 perturb) 1546__u32 skb_get_hash_perturb(const struct sk_buff *skb,
1547 const siphash_key_t *perturb)
1554{ 1548{
1555 struct flow_keys keys; 1549 struct flow_keys keys;
1556 1550
diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c
index f93785e5833c..74cfb8b5ab33 100644
--- a/net/core/lwt_bpf.c
+++ b/net/core/lwt_bpf.c
@@ -88,11 +88,16 @@ static int bpf_lwt_input_reroute(struct sk_buff *skb)
88 int err = -EINVAL; 88 int err = -EINVAL;
89 89
90 if (skb->protocol == htons(ETH_P_IP)) { 90 if (skb->protocol == htons(ETH_P_IP)) {
91 struct net_device *dev = skb_dst(skb)->dev;
91 struct iphdr *iph = ip_hdr(skb); 92 struct iphdr *iph = ip_hdr(skb);
92 93
94 dev_hold(dev);
95 skb_dst_drop(skb);
93 err = ip_route_input_noref(skb, iph->daddr, iph->saddr, 96 err = ip_route_input_noref(skb, iph->daddr, iph->saddr,
94 iph->tos, skb_dst(skb)->dev); 97 iph->tos, dev);
98 dev_put(dev);
95 } else if (skb->protocol == htons(ETH_P_IPV6)) { 99 } else if (skb->protocol == htons(ETH_P_IPV6)) {
100 skb_dst_drop(skb);
96 err = ipv6_stub->ipv6_route_input(skb); 101 err = ipv6_stub->ipv6_route_input(skb);
97 } else { 102 } else {
98 err = -EAFNOSUPPORT; 103 err = -EAFNOSUPPORT;
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index a0e0d298c991..39402840025e 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -245,11 +245,12 @@ static int __peernet2id(struct net *net, struct net *peer)
245 return __peernet2id_alloc(net, peer, &no); 245 return __peernet2id_alloc(net, peer, &no);
246} 246}
247 247
248static void rtnl_net_notifyid(struct net *net, int cmd, int id); 248static void rtnl_net_notifyid(struct net *net, int cmd, int id, u32 portid,
249 struct nlmsghdr *nlh, gfp_t gfp);
249/* This function returns the id of a peer netns. If no id is assigned, one will 250/* This function returns the id of a peer netns. If no id is assigned, one will
250 * be allocated and returned. 251 * be allocated and returned.
251 */ 252 */
252int peernet2id_alloc(struct net *net, struct net *peer) 253int peernet2id_alloc(struct net *net, struct net *peer, gfp_t gfp)
253{ 254{
254 bool alloc = false, alive = false; 255 bool alloc = false, alive = false;
255 int id; 256 int id;
@@ -268,7 +269,7 @@ int peernet2id_alloc(struct net *net, struct net *peer)
268 id = __peernet2id_alloc(net, peer, &alloc); 269 id = __peernet2id_alloc(net, peer, &alloc);
269 spin_unlock_bh(&net->nsid_lock); 270 spin_unlock_bh(&net->nsid_lock);
270 if (alloc && id >= 0) 271 if (alloc && id >= 0)
271 rtnl_net_notifyid(net, RTM_NEWNSID, id); 272 rtnl_net_notifyid(net, RTM_NEWNSID, id, 0, NULL, gfp);
272 if (alive) 273 if (alive)
273 put_net(peer); 274 put_net(peer);
274 return id; 275 return id;
@@ -478,6 +479,7 @@ struct net *copy_net_ns(unsigned long flags,
478 479
479 if (rv < 0) { 480 if (rv < 0) {
480put_userns: 481put_userns:
482 key_remove_domain(net->key_domain);
481 put_user_ns(user_ns); 483 put_user_ns(user_ns);
482 net_drop_ns(net); 484 net_drop_ns(net);
483dec_ucounts: 485dec_ucounts:
@@ -532,7 +534,8 @@ static void unhash_nsid(struct net *net, struct net *last)
532 idr_remove(&tmp->netns_ids, id); 534 idr_remove(&tmp->netns_ids, id);
533 spin_unlock_bh(&tmp->nsid_lock); 535 spin_unlock_bh(&tmp->nsid_lock);
534 if (id >= 0) 536 if (id >= 0)
535 rtnl_net_notifyid(tmp, RTM_DELNSID, id); 537 rtnl_net_notifyid(tmp, RTM_DELNSID, id, 0, NULL,
538 GFP_KERNEL);
536 if (tmp == last) 539 if (tmp == last)
537 break; 540 break;
538 } 541 }
@@ -764,7 +767,8 @@ static int rtnl_net_newid(struct sk_buff *skb, struct nlmsghdr *nlh,
764 err = alloc_netid(net, peer, nsid); 767 err = alloc_netid(net, peer, nsid);
765 spin_unlock_bh(&net->nsid_lock); 768 spin_unlock_bh(&net->nsid_lock);
766 if (err >= 0) { 769 if (err >= 0) {
767 rtnl_net_notifyid(net, RTM_NEWNSID, err); 770 rtnl_net_notifyid(net, RTM_NEWNSID, err, NETLINK_CB(skb).portid,
771 nlh, GFP_KERNEL);
768 err = 0; 772 err = 0;
769 } else if (err == -ENOSPC && nsid >= 0) { 773 } else if (err == -ENOSPC && nsid >= 0) {
770 err = -EEXIST; 774 err = -EEXIST;
@@ -1051,16 +1055,19 @@ end:
1051 return err < 0 ? err : skb->len; 1055 return err < 0 ? err : skb->len;
1052} 1056}
1053 1057
1054static void rtnl_net_notifyid(struct net *net, int cmd, int id) 1058static void rtnl_net_notifyid(struct net *net, int cmd, int id, u32 portid,
1059 struct nlmsghdr *nlh, gfp_t gfp)
1055{ 1060{
1056 struct net_fill_args fillargs = { 1061 struct net_fill_args fillargs = {
1062 .portid = portid,
1063 .seq = nlh ? nlh->nlmsg_seq : 0,
1057 .cmd = cmd, 1064 .cmd = cmd,
1058 .nsid = id, 1065 .nsid = id,
1059 }; 1066 };
1060 struct sk_buff *msg; 1067 struct sk_buff *msg;
1061 int err = -ENOMEM; 1068 int err = -ENOMEM;
1062 1069
1063 msg = nlmsg_new(rtnl_net_get_size(), GFP_KERNEL); 1070 msg = nlmsg_new(rtnl_net_get_size(), gfp);
1064 if (!msg) 1071 if (!msg)
1065 goto out; 1072 goto out;
1066 1073
@@ -1068,7 +1075,7 @@ static void rtnl_net_notifyid(struct net *net, int cmd, int id)
1068 if (err < 0) 1075 if (err < 0)
1069 goto err_out; 1076 goto err_out;
1070 1077
1071 rtnl_notify(msg, net, 0, RTNLGRP_NSID, NULL, 0); 1078 rtnl_notify(msg, net, portid, RTNLGRP_NSID, nlh, gfp);
1072 return; 1079 return;
1073 1080
1074err_out: 1081err_out:
diff --git a/net/core/request_sock.c b/net/core/request_sock.c
index c9bb00008528..f35c2e998406 100644
--- a/net/core/request_sock.c
+++ b/net/core/request_sock.c
@@ -96,7 +96,7 @@ void reqsk_fastopen_remove(struct sock *sk, struct request_sock *req,
96 96
97 fastopenq = &inet_csk(lsk)->icsk_accept_queue.fastopenq; 97 fastopenq = &inet_csk(lsk)->icsk_accept_queue.fastopenq;
98 98
99 tcp_sk(sk)->fastopen_rsk = NULL; 99 RCU_INIT_POINTER(tcp_sk(sk)->fastopen_rsk, NULL);
100 spin_lock_bh(&fastopenq->lock); 100 spin_lock_bh(&fastopenq->lock);
101 fastopenq->qlen--; 101 fastopenq->qlen--;
102 tcp_rsk(req)->tfo_listener = false; 102 tcp_rsk(req)->tfo_listener = false;
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 1ee6460f8275..c81cd80114d9 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1523,7 +1523,7 @@ static noinline_for_stack int nla_put_ifalias(struct sk_buff *skb,
1523 1523
1524static int rtnl_fill_link_netnsid(struct sk_buff *skb, 1524static int rtnl_fill_link_netnsid(struct sk_buff *skb,
1525 const struct net_device *dev, 1525 const struct net_device *dev,
1526 struct net *src_net) 1526 struct net *src_net, gfp_t gfp)
1527{ 1527{
1528 bool put_iflink = false; 1528 bool put_iflink = false;
1529 1529
@@ -1531,7 +1531,7 @@ static int rtnl_fill_link_netnsid(struct sk_buff *skb,
1531 struct net *link_net = dev->rtnl_link_ops->get_link_net(dev); 1531 struct net *link_net = dev->rtnl_link_ops->get_link_net(dev);
1532 1532
1533 if (!net_eq(dev_net(dev), link_net)) { 1533 if (!net_eq(dev_net(dev), link_net)) {
1534 int id = peernet2id_alloc(src_net, link_net); 1534 int id = peernet2id_alloc(src_net, link_net, gfp);
1535 1535
1536 if (nla_put_s32(skb, IFLA_LINK_NETNSID, id)) 1536 if (nla_put_s32(skb, IFLA_LINK_NETNSID, id))
1537 return -EMSGSIZE; 1537 return -EMSGSIZE;
@@ -1589,7 +1589,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
1589 int type, u32 pid, u32 seq, u32 change, 1589 int type, u32 pid, u32 seq, u32 change,
1590 unsigned int flags, u32 ext_filter_mask, 1590 unsigned int flags, u32 ext_filter_mask,
1591 u32 event, int *new_nsid, int new_ifindex, 1591 u32 event, int *new_nsid, int new_ifindex,
1592 int tgt_netnsid) 1592 int tgt_netnsid, gfp_t gfp)
1593{ 1593{
1594 struct ifinfomsg *ifm; 1594 struct ifinfomsg *ifm;
1595 struct nlmsghdr *nlh; 1595 struct nlmsghdr *nlh;
@@ -1681,7 +1681,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
1681 goto nla_put_failure; 1681 goto nla_put_failure;
1682 } 1682 }
1683 1683
1684 if (rtnl_fill_link_netnsid(skb, dev, src_net)) 1684 if (rtnl_fill_link_netnsid(skb, dev, src_net, gfp))
1685 goto nla_put_failure; 1685 goto nla_put_failure;
1686 1686
1687 if (new_nsid && 1687 if (new_nsid &&
@@ -2001,7 +2001,7 @@ walk_entries:
2001 NETLINK_CB(cb->skb).portid, 2001 NETLINK_CB(cb->skb).portid,
2002 nlh->nlmsg_seq, 0, flags, 2002 nlh->nlmsg_seq, 0, flags,
2003 ext_filter_mask, 0, NULL, 0, 2003 ext_filter_mask, 0, NULL, 0,
2004 netnsid); 2004 netnsid, GFP_KERNEL);
2005 2005
2006 if (err < 0) { 2006 if (err < 0) {
2007 if (likely(skb->len)) 2007 if (likely(skb->len))
@@ -2355,6 +2355,7 @@ static int do_set_master(struct net_device *dev, int ifindex,
2355 err = ops->ndo_del_slave(upper_dev, dev); 2355 err = ops->ndo_del_slave(upper_dev, dev);
2356 if (err) 2356 if (err)
2357 return err; 2357 return err;
2358 netdev_update_lockdep_key(dev);
2358 } else { 2359 } else {
2359 return -EOPNOTSUPP; 2360 return -EOPNOTSUPP;
2360 } 2361 }
@@ -3359,7 +3360,7 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh,
3359 err = rtnl_fill_ifinfo(nskb, dev, net, 3360 err = rtnl_fill_ifinfo(nskb, dev, net,
3360 RTM_NEWLINK, NETLINK_CB(skb).portid, 3361 RTM_NEWLINK, NETLINK_CB(skb).portid,
3361 nlh->nlmsg_seq, 0, 0, ext_filter_mask, 3362 nlh->nlmsg_seq, 0, 0, ext_filter_mask,
3362 0, NULL, 0, netnsid); 3363 0, NULL, 0, netnsid, GFP_KERNEL);
3363 if (err < 0) { 3364 if (err < 0) {
3364 /* -EMSGSIZE implies BUG in if_nlmsg_size */ 3365 /* -EMSGSIZE implies BUG in if_nlmsg_size */
3365 WARN_ON(err == -EMSGSIZE); 3366 WARN_ON(err == -EMSGSIZE);
@@ -3471,7 +3472,7 @@ struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev,
3471 3472
3472 err = rtnl_fill_ifinfo(skb, dev, dev_net(dev), 3473 err = rtnl_fill_ifinfo(skb, dev, dev_net(dev),
3473 type, 0, 0, change, 0, 0, event, 3474 type, 0, 0, change, 0, 0, event,
3474 new_nsid, new_ifindex, -1); 3475 new_nsid, new_ifindex, -1, flags);
3475 if (err < 0) { 3476 if (err < 0) {
3476 /* -EMSGSIZE implies BUG in if_nlmsg_size() */ 3477 /* -EMSGSIZE implies BUG in if_nlmsg_size() */
3477 WARN_ON(err == -EMSGSIZE); 3478 WARN_ON(err == -EMSGSIZE);
@@ -3916,7 +3917,7 @@ static int valid_fdb_dump_strict(const struct nlmsghdr *nlh,
3916 ndm = nlmsg_data(nlh); 3917 ndm = nlmsg_data(nlh);
3917 if (ndm->ndm_pad1 || ndm->ndm_pad2 || ndm->ndm_state || 3918 if (ndm->ndm_pad1 || ndm->ndm_pad2 || ndm->ndm_state ||
3918 ndm->ndm_flags || ndm->ndm_type) { 3919 ndm->ndm_flags || ndm->ndm_type) {
3919 NL_SET_ERR_MSG(extack, "Invalid values in header for fbd dump request"); 3920 NL_SET_ERR_MSG(extack, "Invalid values in header for fdb dump request");
3920 return -EINVAL; 3921 return -EINVAL;
3921 } 3922 }
3922 3923
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 01d65206f4fb..867e61df00db 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -4415,7 +4415,7 @@ static void skb_set_err_queue(struct sk_buff *skb)
4415int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb) 4415int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb)
4416{ 4416{
4417 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >= 4417 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
4418 (unsigned int)sk->sk_rcvbuf) 4418 (unsigned int)READ_ONCE(sk->sk_rcvbuf))
4419 return -ENOMEM; 4419 return -ENOMEM;
4420 4420
4421 skb_orphan(skb); 4421 skb_orphan(skb);
@@ -5120,7 +5120,7 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet)
5120 skb->ignore_df = 0; 5120 skb->ignore_df = 0;
5121 skb_dst_drop(skb); 5121 skb_dst_drop(skb);
5122 skb_ext_reset(skb); 5122 skb_ext_reset(skb);
5123 nf_reset(skb); 5123 nf_reset_ct(skb);
5124 nf_reset_trace(skb); 5124 nf_reset_trace(skb);
5125 5125
5126#ifdef CONFIG_NET_SWITCHDEV 5126#ifdef CONFIG_NET_SWITCHDEV
@@ -5477,12 +5477,14 @@ static void skb_mod_eth_type(struct sk_buff *skb, struct ethhdr *hdr,
5477 * @skb: buffer 5477 * @skb: buffer
5478 * @mpls_lse: MPLS label stack entry to push 5478 * @mpls_lse: MPLS label stack entry to push
5479 * @mpls_proto: ethertype of the new MPLS header (expects 0x8847 or 0x8848) 5479 * @mpls_proto: ethertype of the new MPLS header (expects 0x8847 or 0x8848)
5480 * @mac_len: length of the MAC header
5480 * 5481 *
5481 * Expects skb->data at mac header. 5482 * Expects skb->data at mac header.
5482 * 5483 *
5483 * Returns 0 on success, -errno otherwise. 5484 * Returns 0 on success, -errno otherwise.
5484 */ 5485 */
5485int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto) 5486int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto,
5487 int mac_len)
5486{ 5488{
5487 struct mpls_shim_hdr *lse; 5489 struct mpls_shim_hdr *lse;
5488 int err; 5490 int err;
@@ -5499,15 +5501,15 @@ int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto)
5499 return err; 5501 return err;
5500 5502
5501 if (!skb->inner_protocol) { 5503 if (!skb->inner_protocol) {
5502 skb_set_inner_network_header(skb, skb->mac_len); 5504 skb_set_inner_network_header(skb, mac_len);
5503 skb_set_inner_protocol(skb, skb->protocol); 5505 skb_set_inner_protocol(skb, skb->protocol);
5504 } 5506 }
5505 5507
5506 skb_push(skb, MPLS_HLEN); 5508 skb_push(skb, MPLS_HLEN);
5507 memmove(skb_mac_header(skb) - MPLS_HLEN, skb_mac_header(skb), 5509 memmove(skb_mac_header(skb) - MPLS_HLEN, skb_mac_header(skb),
5508 skb->mac_len); 5510 mac_len);
5509 skb_reset_mac_header(skb); 5511 skb_reset_mac_header(skb);
5510 skb_set_network_header(skb, skb->mac_len); 5512 skb_set_network_header(skb, mac_len);
5511 5513
5512 lse = mpls_hdr(skb); 5514 lse = mpls_hdr(skb);
5513 lse->label_stack_entry = mpls_lse; 5515 lse->label_stack_entry = mpls_lse;
@@ -5526,29 +5528,30 @@ EXPORT_SYMBOL_GPL(skb_mpls_push);
5526 * 5528 *
5527 * @skb: buffer 5529 * @skb: buffer
5528 * @next_proto: ethertype of header after popped MPLS header 5530 * @next_proto: ethertype of header after popped MPLS header
5531 * @mac_len: length of the MAC header
5529 * 5532 *
5530 * Expects skb->data at mac header. 5533 * Expects skb->data at mac header.
5531 * 5534 *
5532 * Returns 0 on success, -errno otherwise. 5535 * Returns 0 on success, -errno otherwise.
5533 */ 5536 */
5534int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto) 5537int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len)
5535{ 5538{
5536 int err; 5539 int err;
5537 5540
5538 if (unlikely(!eth_p_mpls(skb->protocol))) 5541 if (unlikely(!eth_p_mpls(skb->protocol)))
5539 return -EINVAL; 5542 return 0;
5540 5543
5541 err = skb_ensure_writable(skb, skb->mac_len + MPLS_HLEN); 5544 err = skb_ensure_writable(skb, mac_len + MPLS_HLEN);
5542 if (unlikely(err)) 5545 if (unlikely(err))
5543 return err; 5546 return err;
5544 5547
5545 skb_postpull_rcsum(skb, mpls_hdr(skb), MPLS_HLEN); 5548 skb_postpull_rcsum(skb, mpls_hdr(skb), MPLS_HLEN);
5546 memmove(skb_mac_header(skb) + MPLS_HLEN, skb_mac_header(skb), 5549 memmove(skb_mac_header(skb) + MPLS_HLEN, skb_mac_header(skb),
5547 skb->mac_len); 5550 mac_len);
5548 5551
5549 __skb_pull(skb, MPLS_HLEN); 5552 __skb_pull(skb, MPLS_HLEN);
5550 skb_reset_mac_header(skb); 5553 skb_reset_mac_header(skb);
5551 skb_set_network_header(skb, skb->mac_len); 5554 skb_set_network_header(skb, mac_len);
5552 5555
5553 if (skb->dev && skb->dev->type == ARPHRD_ETHER) { 5556 if (skb->dev && skb->dev->type == ARPHRD_ETHER) {
5554 struct ethhdr *hdr; 5557 struct ethhdr *hdr;
diff --git a/net/core/sock.c b/net/core/sock.c
index 07863edbe6fc..ac78a570e43a 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -522,7 +522,7 @@ int __sk_receive_skb(struct sock *sk, struct sk_buff *skb,
522 rc = sk_backlog_rcv(sk, skb); 522 rc = sk_backlog_rcv(sk, skb);
523 523
524 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_); 524 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
525 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) { 525 } else if (sk_add_backlog(sk, skb, READ_ONCE(sk->sk_rcvbuf))) {
526 bh_unlock_sock(sk); 526 bh_unlock_sock(sk);
527 atomic_inc(&sk->sk_drops); 527 atomic_inc(&sk->sk_drops);
528 goto discard_and_relse; 528 goto discard_and_relse;
@@ -785,7 +785,8 @@ set_sndbuf:
785 */ 785 */
786 val = min_t(int, val, INT_MAX / 2); 786 val = min_t(int, val, INT_MAX / 2);
787 sk->sk_userlocks |= SOCK_SNDBUF_LOCK; 787 sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
788 sk->sk_sndbuf = max_t(int, val * 2, SOCK_MIN_SNDBUF); 788 WRITE_ONCE(sk->sk_sndbuf,
789 max_t(int, val * 2, SOCK_MIN_SNDBUF));
789 /* Wake up sending tasks if we upped the value. */ 790 /* Wake up sending tasks if we upped the value. */
790 sk->sk_write_space(sk); 791 sk->sk_write_space(sk);
791 break; 792 break;
@@ -831,7 +832,8 @@ set_rcvbuf:
831 * returning the value we actually used in getsockopt 832 * returning the value we actually used in getsockopt
832 * is the most desirable behavior. 833 * is the most desirable behavior.
833 */ 834 */
834 sk->sk_rcvbuf = max_t(int, val * 2, SOCK_MIN_RCVBUF); 835 WRITE_ONCE(sk->sk_rcvbuf,
836 max_t(int, val * 2, SOCK_MIN_RCVBUF));
835 break; 837 break;
836 838
837 case SO_RCVBUFFORCE: 839 case SO_RCVBUFFORCE:
@@ -974,7 +976,7 @@ set_rcvbuf:
974 if (sock->ops->set_rcvlowat) 976 if (sock->ops->set_rcvlowat)
975 ret = sock->ops->set_rcvlowat(sk, val); 977 ret = sock->ops->set_rcvlowat(sk, val);
976 else 978 else
977 sk->sk_rcvlowat = val ? : 1; 979 WRITE_ONCE(sk->sk_rcvlowat, val ? : 1);
978 break; 980 break;
979 981
980 case SO_RCVTIMEO_OLD: 982 case SO_RCVTIMEO_OLD:
@@ -1125,7 +1127,7 @@ set_rcvbuf:
1125 break; 1127 break;
1126 } 1128 }
1127 case SO_INCOMING_CPU: 1129 case SO_INCOMING_CPU:
1128 sk->sk_incoming_cpu = val; 1130 WRITE_ONCE(sk->sk_incoming_cpu, val);
1129 break; 1131 break;
1130 1132
1131 case SO_CNX_ADVICE: 1133 case SO_CNX_ADVICE:
@@ -1474,7 +1476,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
1474 break; 1476 break;
1475 1477
1476 case SO_INCOMING_CPU: 1478 case SO_INCOMING_CPU:
1477 v.val = sk->sk_incoming_cpu; 1479 v.val = READ_ONCE(sk->sk_incoming_cpu);
1478 break; 1480 break;
1479 1481
1480 case SO_MEMINFO: 1482 case SO_MEMINFO:
@@ -1700,8 +1702,6 @@ static void __sk_destruct(struct rcu_head *head)
1700 sk_filter_uncharge(sk, filter); 1702 sk_filter_uncharge(sk, filter);
1701 RCU_INIT_POINTER(sk->sk_filter, NULL); 1703 RCU_INIT_POINTER(sk->sk_filter, NULL);
1702 } 1704 }
1703 if (rcu_access_pointer(sk->sk_reuseport_cb))
1704 reuseport_detach_sock(sk);
1705 1705
1706 sock_disable_timestamp(sk, SK_FLAGS_TIMESTAMP); 1706 sock_disable_timestamp(sk, SK_FLAGS_TIMESTAMP);
1707 1707
@@ -1728,7 +1728,14 @@ static void __sk_destruct(struct rcu_head *head)
1728 1728
1729void sk_destruct(struct sock *sk) 1729void sk_destruct(struct sock *sk)
1730{ 1730{
1731 if (sock_flag(sk, SOCK_RCU_FREE)) 1731 bool use_call_rcu = sock_flag(sk, SOCK_RCU_FREE);
1732
1733 if (rcu_access_pointer(sk->sk_reuseport_cb)) {
1734 reuseport_detach_sock(sk);
1735 use_call_rcu = true;
1736 }
1737
1738 if (use_call_rcu)
1732 call_rcu(&sk->sk_rcu, __sk_destruct); 1739 call_rcu(&sk->sk_rcu, __sk_destruct);
1733 else 1740 else
1734 __sk_destruct(&sk->sk_rcu); 1741 __sk_destruct(&sk->sk_rcu);
@@ -2083,8 +2090,10 @@ EXPORT_SYMBOL(sock_i_ino);
2083struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force, 2090struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force,
2084 gfp_t priority) 2091 gfp_t priority)
2085{ 2092{
2086 if (force || refcount_read(&sk->sk_wmem_alloc) < sk->sk_sndbuf) { 2093 if (force ||
2094 refcount_read(&sk->sk_wmem_alloc) < READ_ONCE(sk->sk_sndbuf)) {
2087 struct sk_buff *skb = alloc_skb(size, priority); 2095 struct sk_buff *skb = alloc_skb(size, priority);
2096
2088 if (skb) { 2097 if (skb) {
2089 skb_set_owner_w(skb, sk); 2098 skb_set_owner_w(skb, sk);
2090 return skb; 2099 return skb;
@@ -2185,7 +2194,7 @@ static long sock_wait_for_wmem(struct sock *sk, long timeo)
2185 break; 2194 break;
2186 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); 2195 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
2187 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); 2196 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
2188 if (refcount_read(&sk->sk_wmem_alloc) < sk->sk_sndbuf) 2197 if (refcount_read(&sk->sk_wmem_alloc) < READ_ONCE(sk->sk_sndbuf))
2189 break; 2198 break;
2190 if (sk->sk_shutdown & SEND_SHUTDOWN) 2199 if (sk->sk_shutdown & SEND_SHUTDOWN)
2191 break; 2200 break;
@@ -2220,7 +2229,7 @@ struct sk_buff *sock_alloc_send_pskb(struct sock *sk, unsigned long header_len,
2220 if (sk->sk_shutdown & SEND_SHUTDOWN) 2229 if (sk->sk_shutdown & SEND_SHUTDOWN)
2221 goto failure; 2230 goto failure;
2222 2231
2223 if (sk_wmem_alloc_get(sk) < sk->sk_sndbuf) 2232 if (sk_wmem_alloc_get(sk) < READ_ONCE(sk->sk_sndbuf))
2224 break; 2233 break;
2225 2234
2226 sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk); 2235 sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk);
@@ -2329,8 +2338,8 @@ static void sk_leave_memory_pressure(struct sock *sk)
2329 } else { 2338 } else {
2330 unsigned long *memory_pressure = sk->sk_prot->memory_pressure; 2339 unsigned long *memory_pressure = sk->sk_prot->memory_pressure;
2331 2340
2332 if (memory_pressure && *memory_pressure) 2341 if (memory_pressure && READ_ONCE(*memory_pressure))
2333 *memory_pressure = 0; 2342 WRITE_ONCE(*memory_pressure, 0);
2334 } 2343 }
2335} 2344}
2336 2345
@@ -2801,7 +2810,7 @@ static void sock_def_write_space(struct sock *sk)
2801 /* Do not wake up a writer until he can make "significant" 2810 /* Do not wake up a writer until he can make "significant"
2802 * progress. --DaveM 2811 * progress. --DaveM
2803 */ 2812 */
2804 if ((refcount_read(&sk->sk_wmem_alloc) << 1) <= sk->sk_sndbuf) { 2813 if ((refcount_read(&sk->sk_wmem_alloc) << 1) <= READ_ONCE(sk->sk_sndbuf)) {
2805 wq = rcu_dereference(sk->sk_wq); 2814 wq = rcu_dereference(sk->sk_wq);
2806 if (skwq_has_sleeper(wq)) 2815 if (skwq_has_sleeper(wq))
2807 wake_up_interruptible_sync_poll(&wq->wait, EPOLLOUT | 2816 wake_up_interruptible_sync_poll(&wq->wait, EPOLLOUT |
@@ -3199,13 +3208,13 @@ void sk_get_meminfo(const struct sock *sk, u32 *mem)
3199 memset(mem, 0, sizeof(*mem) * SK_MEMINFO_VARS); 3208 memset(mem, 0, sizeof(*mem) * SK_MEMINFO_VARS);
3200 3209
3201 mem[SK_MEMINFO_RMEM_ALLOC] = sk_rmem_alloc_get(sk); 3210 mem[SK_MEMINFO_RMEM_ALLOC] = sk_rmem_alloc_get(sk);
3202 mem[SK_MEMINFO_RCVBUF] = sk->sk_rcvbuf; 3211 mem[SK_MEMINFO_RCVBUF] = READ_ONCE(sk->sk_rcvbuf);
3203 mem[SK_MEMINFO_WMEM_ALLOC] = sk_wmem_alloc_get(sk); 3212 mem[SK_MEMINFO_WMEM_ALLOC] = sk_wmem_alloc_get(sk);
3204 mem[SK_MEMINFO_SNDBUF] = sk->sk_sndbuf; 3213 mem[SK_MEMINFO_SNDBUF] = READ_ONCE(sk->sk_sndbuf);
3205 mem[SK_MEMINFO_FWD_ALLOC] = sk->sk_forward_alloc; 3214 mem[SK_MEMINFO_FWD_ALLOC] = sk->sk_forward_alloc;
3206 mem[SK_MEMINFO_WMEM_QUEUED] = sk->sk_wmem_queued; 3215 mem[SK_MEMINFO_WMEM_QUEUED] = READ_ONCE(sk->sk_wmem_queued);
3207 mem[SK_MEMINFO_OPTMEM] = atomic_read(&sk->sk_omem_alloc); 3216 mem[SK_MEMINFO_OPTMEM] = atomic_read(&sk->sk_omem_alloc);
3208 mem[SK_MEMINFO_BACKLOG] = sk->sk_backlog.len; 3217 mem[SK_MEMINFO_BACKLOG] = READ_ONCE(sk->sk_backlog.len);
3209 mem[SK_MEMINFO_DROPS] = atomic_read(&sk->sk_drops); 3218 mem[SK_MEMINFO_DROPS] = atomic_read(&sk->sk_drops);
3210} 3219}
3211 3220
@@ -3492,7 +3501,7 @@ static long sock_prot_memory_allocated(struct proto *proto)
3492 return proto->memory_allocated != NULL ? proto_memory_allocated(proto) : -1L; 3501 return proto->memory_allocated != NULL ? proto_memory_allocated(proto) : -1L;
3493} 3502}
3494 3503
3495static char *sock_prot_memory_pressure(struct proto *proto) 3504static const char *sock_prot_memory_pressure(struct proto *proto)
3496{ 3505{
3497 return proto->memory_pressure != NULL ? 3506 return proto->memory_pressure != NULL ?
3498 proto_memory_pressure(proto) ? "yes" : "no" : "NI"; 3507 proto_memory_pressure(proto) ? "yes" : "no" : "NI";
@@ -3591,7 +3600,7 @@ bool sk_busy_loop_end(void *p, unsigned long start_time)
3591{ 3600{
3592 struct sock *sk = p; 3601 struct sock *sk = p;
3593 3602
3594 return !skb_queue_empty(&sk->sk_receive_queue) || 3603 return !skb_queue_empty_lockless(&sk->sk_receive_queue) ||
3595 sk_busy_loop_timeout(sk, start_time); 3604 sk_busy_loop_timeout(sk, start_time);
3596} 3605}
3597EXPORT_SYMBOL(sk_busy_loop_end); 3606EXPORT_SYMBOL(sk_busy_loop_end);
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index b685bc82f8d0..d9b4200ed12d 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -871,7 +871,7 @@ lookup:
871 871
872 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) 872 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
873 goto discard_and_relse; 873 goto discard_and_relse;
874 nf_reset(skb); 874 nf_reset_ct(skb);
875 875
876 return __sk_receive_skb(sk, skb, 1, dh->dccph_doff * 4, refcounted); 876 return __sk_receive_skb(sk, skb, 1, dh->dccph_doff * 4, refcounted);
877 877
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
index 0ea75286abf4..3349ea81f901 100644
--- a/net/decnet/af_decnet.c
+++ b/net/decnet/af_decnet.c
@@ -1205,7 +1205,7 @@ static __poll_t dn_poll(struct file *file, struct socket *sock, poll_table *wai
1205 struct dn_scp *scp = DN_SK(sk); 1205 struct dn_scp *scp = DN_SK(sk);
1206 __poll_t mask = datagram_poll(file, sock, wait); 1206 __poll_t mask = datagram_poll(file, sock, wait);
1207 1207
1208 if (!skb_queue_empty(&scp->other_receive_queue)) 1208 if (!skb_queue_empty_lockless(&scp->other_receive_queue))
1209 mask |= EPOLLRDBAND; 1209 mask |= EPOLLRDBAND;
1210 1210
1211 return mask; 1211 return mask;
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 73002022c9d8..716d265ba8ca 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -46,7 +46,7 @@ static struct dsa_switch_tree *dsa_tree_alloc(int index)
46 dst->index = index; 46 dst->index = index;
47 47
48 INIT_LIST_HEAD(&dst->list); 48 INIT_LIST_HEAD(&dst->list);
49 list_add_tail(&dsa_tree_list, &dst->list); 49 list_add_tail(&dst->list, &dsa_tree_list);
50 50
51 kref_init(&dst->refcount); 51 kref_init(&dst->refcount);
52 52
diff --git a/net/dsa/master.c b/net/dsa/master.c
index a8e52c9967f4..3255dfc97f86 100644
--- a/net/dsa/master.c
+++ b/net/dsa/master.c
@@ -310,8 +310,6 @@ static void dsa_master_reset_mtu(struct net_device *dev)
310 rtnl_unlock(); 310 rtnl_unlock();
311} 311}
312 312
313static struct lock_class_key dsa_master_addr_list_lock_key;
314
315int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp) 313int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp)
316{ 314{
317 int ret; 315 int ret;
@@ -325,9 +323,6 @@ int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp)
325 wmb(); 323 wmb();
326 324
327 dev->dsa_ptr = cpu_dp; 325 dev->dsa_ptr = cpu_dp;
328 lockdep_set_class(&dev->addr_list_lock,
329 &dsa_master_addr_list_lock_key);
330
331 ret = dsa_master_ethtool_setup(dev); 326 ret = dsa_master_ethtool_setup(dev);
332 if (ret) 327 if (ret)
333 return ret; 328 return ret;
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 75d58229a4bd..028e65f4b5ba 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -1341,15 +1341,6 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)
1341 return ret; 1341 return ret;
1342} 1342}
1343 1343
1344static struct lock_class_key dsa_slave_netdev_xmit_lock_key;
1345static void dsa_slave_set_lockdep_class_one(struct net_device *dev,
1346 struct netdev_queue *txq,
1347 void *_unused)
1348{
1349 lockdep_set_class(&txq->_xmit_lock,
1350 &dsa_slave_netdev_xmit_lock_key);
1351}
1352
1353int dsa_slave_suspend(struct net_device *slave_dev) 1344int dsa_slave_suspend(struct net_device *slave_dev)
1354{ 1345{
1355 struct dsa_port *dp = dsa_slave_to_port(slave_dev); 1346 struct dsa_port *dp = dsa_slave_to_port(slave_dev);
@@ -1433,9 +1424,6 @@ int dsa_slave_create(struct dsa_port *port)
1433 slave_dev->max_mtu = ETH_MAX_MTU; 1424 slave_dev->max_mtu = ETH_MAX_MTU;
1434 SET_NETDEV_DEVTYPE(slave_dev, &dsa_type); 1425 SET_NETDEV_DEVTYPE(slave_dev, &dsa_type);
1435 1426
1436 netdev_for_each_tx_queue(slave_dev, dsa_slave_set_lockdep_class_one,
1437 NULL);
1438
1439 SET_NETDEV_DEV(slave_dev, port->ds->dev); 1427 SET_NETDEV_DEV(slave_dev, port->ds->dev);
1440 slave_dev->dev.of_node = port->dn; 1428 slave_dev->dev.of_node = port->dn;
1441 slave_dev->vlan_features = master->vlan_features; 1429 slave_dev->vlan_features = master->vlan_features;
diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c
index 9c9aff3e52cf..63ef2a14c934 100644
--- a/net/dsa/tag_sja1105.c
+++ b/net/dsa/tag_sja1105.c
@@ -156,7 +156,11 @@ static struct sk_buff
156 /* Step 1: A timestampable frame was received. 156 /* Step 1: A timestampable frame was received.
157 * Buffer it until we get its meta frame. 157 * Buffer it until we get its meta frame.
158 */ 158 */
159 if (is_link_local && sp->data->hwts_rx_en) { 159 if (is_link_local) {
160 if (!test_bit(SJA1105_HWTS_RX_EN, &sp->data->state))
161 /* Do normal processing. */
162 return skb;
163
160 spin_lock(&sp->data->meta_lock); 164 spin_lock(&sp->data->meta_lock);
161 /* Was this a link-local frame instead of the meta 165 /* Was this a link-local frame instead of the meta
162 * that we were expecting? 166 * that we were expecting?
@@ -187,6 +191,12 @@ static struct sk_buff
187 } else if (is_meta) { 191 } else if (is_meta) {
188 struct sk_buff *stampable_skb; 192 struct sk_buff *stampable_skb;
189 193
194 /* Drop the meta frame if we're not in the right state
195 * to process it.
196 */
197 if (!test_bit(SJA1105_HWTS_RX_EN, &sp->data->state))
198 return NULL;
199
190 spin_lock(&sp->data->meta_lock); 200 spin_lock(&sp->data->meta_lock);
191 201
192 stampable_skb = sp->data->stampable_skb; 202 stampable_skb = sp->data->stampable_skb;
diff --git a/net/ieee802154/6lowpan/core.c b/net/ieee802154/6lowpan/core.c
index 3297e7fa9945..c0b107cdd715 100644
--- a/net/ieee802154/6lowpan/core.c
+++ b/net/ieee802154/6lowpan/core.c
@@ -58,13 +58,6 @@ static const struct header_ops lowpan_header_ops = {
58 .create = lowpan_header_create, 58 .create = lowpan_header_create,
59}; 59};
60 60
61static int lowpan_dev_init(struct net_device *ldev)
62{
63 netdev_lockdep_set_classes(ldev);
64
65 return 0;
66}
67
68static int lowpan_open(struct net_device *dev) 61static int lowpan_open(struct net_device *dev)
69{ 62{
70 if (!open_count) 63 if (!open_count)
@@ -96,7 +89,6 @@ static int lowpan_get_iflink(const struct net_device *dev)
96} 89}
97 90
98static const struct net_device_ops lowpan_netdev_ops = { 91static const struct net_device_ops lowpan_netdev_ops = {
99 .ndo_init = lowpan_dev_init,
100 .ndo_start_xmit = lowpan_xmit, 92 .ndo_start_xmit = lowpan_xmit,
101 .ndo_open = lowpan_open, 93 .ndo_open = lowpan_open,
102 .ndo_stop = lowpan_stop, 94 .ndo_stop = lowpan_stop,
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index dde77f72e03e..71c78d223dfd 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -1148,7 +1148,7 @@ void fib_modify_prefix_metric(struct in_ifaddr *ifa, u32 new_metric)
1148 if (!(dev->flags & IFF_UP) || 1148 if (!(dev->flags & IFF_UP) ||
1149 ifa->ifa_flags & (IFA_F_SECONDARY | IFA_F_NOPREFIXROUTE) || 1149 ifa->ifa_flags & (IFA_F_SECONDARY | IFA_F_NOPREFIXROUTE) ||
1150 ipv4_is_zeronet(prefix) || 1150 ipv4_is_zeronet(prefix) ||
1151 prefix == ifa->ifa_local || ifa->ifa_prefixlen == 32) 1151 (prefix == ifa->ifa_local && ifa->ifa_prefixlen == 32))
1152 return; 1152 return;
1153 1153
1154 /* add the new */ 1154 /* add the new */
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index a9183543ca30..eb30fc1770de 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -906,7 +906,7 @@ static void inet_child_forget(struct sock *sk, struct request_sock *req,
906 percpu_counter_inc(sk->sk_prot->orphan_count); 906 percpu_counter_inc(sk->sk_prot->orphan_count);
907 907
908 if (sk->sk_protocol == IPPROTO_TCP && tcp_rsk(req)->tfo_listener) { 908 if (sk->sk_protocol == IPPROTO_TCP && tcp_rsk(req)->tfo_listener) {
909 BUG_ON(tcp_sk(child)->fastopen_rsk != req); 909 BUG_ON(rcu_access_pointer(tcp_sk(child)->fastopen_rsk) != req);
910 BUG_ON(sk != req->rsk_listener); 910 BUG_ON(sk != req->rsk_listener);
911 911
912 /* Paranoid, to prevent race condition if 912 /* Paranoid, to prevent race condition if
@@ -915,7 +915,7 @@ static void inet_child_forget(struct sock *sk, struct request_sock *req,
915 * Also to satisfy an assertion in 915 * Also to satisfy an assertion in
916 * tcp_v4_destroy_sock(). 916 * tcp_v4_destroy_sock().
917 */ 917 */
918 tcp_sk(child)->fastopen_rsk = NULL; 918 RCU_INIT_POINTER(tcp_sk(child)->fastopen_rsk, NULL);
919 } 919 }
920 inet_csk_destroy_sock(child); 920 inet_csk_destroy_sock(child);
921} 921}
@@ -934,7 +934,7 @@ struct sock *inet_csk_reqsk_queue_add(struct sock *sk,
934 req->sk = child; 934 req->sk = child;
935 req->dl_next = NULL; 935 req->dl_next = NULL;
936 if (queue->rskq_accept_head == NULL) 936 if (queue->rskq_accept_head == NULL)
937 queue->rskq_accept_head = req; 937 WRITE_ONCE(queue->rskq_accept_head, req);
938 else 938 else
939 queue->rskq_accept_tail->dl_next = req; 939 queue->rskq_accept_tail->dl_next = req;
940 queue->rskq_accept_tail = req; 940 queue->rskq_accept_tail = req;
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index bbb005eb5218..7dc79b973e6e 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -193,7 +193,7 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
193 if (ext & (1 << (INET_DIAG_MEMINFO - 1))) { 193 if (ext & (1 << (INET_DIAG_MEMINFO - 1))) {
194 struct inet_diag_meminfo minfo = { 194 struct inet_diag_meminfo minfo = {
195 .idiag_rmem = sk_rmem_alloc_get(sk), 195 .idiag_rmem = sk_rmem_alloc_get(sk),
196 .idiag_wmem = sk->sk_wmem_queued, 196 .idiag_wmem = READ_ONCE(sk->sk_wmem_queued),
197 .idiag_fmem = sk->sk_forward_alloc, 197 .idiag_fmem = sk->sk_forward_alloc,
198 .idiag_tmem = sk_wmem_alloc_get(sk), 198 .idiag_tmem = sk_wmem_alloc_get(sk),
199 }; 199 };
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 97824864e40d..83fb00153018 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -240,7 +240,7 @@ static inline int compute_score(struct sock *sk, struct net *net,
240 return -1; 240 return -1;
241 241
242 score = sk->sk_family == PF_INET ? 2 : 1; 242 score = sk->sk_family == PF_INET ? 2 : 1;
243 if (sk->sk_incoming_cpu == raw_smp_processor_id()) 243 if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id())
244 score++; 244 score++;
245 } 245 }
246 return score; 246 return score;
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index a53a543fe055..10636fb6093e 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -509,9 +509,9 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)
509 key = &tun_info->key; 509 key = &tun_info->key;
510 if (!(tun_info->key.tun_flags & TUNNEL_ERSPAN_OPT)) 510 if (!(tun_info->key.tun_flags & TUNNEL_ERSPAN_OPT))
511 goto err_free_skb; 511 goto err_free_skb;
512 md = ip_tunnel_info_opts(tun_info); 512 if (tun_info->options_len < sizeof(*md))
513 if (!md)
514 goto err_free_skb; 513 goto err_free_skb;
514 md = ip_tunnel_info_opts(tun_info);
515 515
516 /* ERSPAN has fixed 8 byte GRE header */ 516 /* ERSPAN has fixed 8 byte GRE header */
517 version = md->version; 517 version = md->version;
@@ -1446,6 +1446,7 @@ static void erspan_setup(struct net_device *dev)
1446 struct ip_tunnel *t = netdev_priv(dev); 1446 struct ip_tunnel *t = netdev_priv(dev);
1447 1447
1448 ether_setup(dev); 1448 ether_setup(dev);
1449 dev->max_mtu = 0;
1449 dev->netdev_ops = &erspan_netdev_ops; 1450 dev->netdev_ops = &erspan_netdev_ops;
1450 dev->priv_flags &= ~IFF_TX_SKB_SHARING; 1451 dev->priv_flags &= ~IFF_TX_SKB_SHARING;
1451 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; 1452 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index 1e2392b7c64e..c59a78a267c3 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -199,7 +199,7 @@ resubmit:
199 kfree_skb(skb); 199 kfree_skb(skb);
200 return; 200 return;
201 } 201 }
202 nf_reset(skb); 202 nf_reset_ct(skb);
203 } 203 }
204 ret = INDIRECT_CALL_2(ipprot->handler, tcp_v4_rcv, udp_rcv, 204 ret = INDIRECT_CALL_2(ipprot->handler, tcp_v4_rcv, udp_rcv,
205 skb); 205 skb);
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 28fca408812c..3d8baaaf7086 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -645,11 +645,12 @@ void ip_fraglist_prepare(struct sk_buff *skb, struct ip_fraglist_iter *iter)
645EXPORT_SYMBOL(ip_fraglist_prepare); 645EXPORT_SYMBOL(ip_fraglist_prepare);
646 646
647void ip_frag_init(struct sk_buff *skb, unsigned int hlen, 647void ip_frag_init(struct sk_buff *skb, unsigned int hlen,
648 unsigned int ll_rs, unsigned int mtu, 648 unsigned int ll_rs, unsigned int mtu, bool DF,
649 struct ip_frag_state *state) 649 struct ip_frag_state *state)
650{ 650{
651 struct iphdr *iph = ip_hdr(skb); 651 struct iphdr *iph = ip_hdr(skb);
652 652
653 state->DF = DF;
653 state->hlen = hlen; 654 state->hlen = hlen;
654 state->ll_rs = ll_rs; 655 state->ll_rs = ll_rs;
655 state->mtu = mtu; 656 state->mtu = mtu;
@@ -668,9 +669,6 @@ static void ip_frag_ipcb(struct sk_buff *from, struct sk_buff *to,
668 /* Copy the flags to each fragment. */ 669 /* Copy the flags to each fragment. */
669 IPCB(to)->flags = IPCB(from)->flags; 670 IPCB(to)->flags = IPCB(from)->flags;
670 671
671 if (IPCB(from)->flags & IPSKB_FRAG_PMTU)
672 state->iph->frag_off |= htons(IP_DF);
673
674 /* ANK: dirty, but effective trick. Upgrade options only if 672 /* ANK: dirty, but effective trick. Upgrade options only if
675 * the segment to be fragmented was THE FIRST (otherwise, 673 * the segment to be fragmented was THE FIRST (otherwise,
676 * options are already fixed) and make it ONCE 674 * options are already fixed) and make it ONCE
@@ -738,6 +736,8 @@ struct sk_buff *ip_frag_next(struct sk_buff *skb, struct ip_frag_state *state)
738 */ 736 */
739 iph = ip_hdr(skb2); 737 iph = ip_hdr(skb2);
740 iph->frag_off = htons((state->offset >> 3)); 738 iph->frag_off = htons((state->offset >> 3));
739 if (state->DF)
740 iph->frag_off |= htons(IP_DF);
741 741
742 /* 742 /*
743 * Added AC : If we are fragmenting a fragment that's not the 743 * Added AC : If we are fragmenting a fragment that's not the
@@ -771,6 +771,7 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
771 struct rtable *rt = skb_rtable(skb); 771 struct rtable *rt = skb_rtable(skb);
772 unsigned int mtu, hlen, ll_rs; 772 unsigned int mtu, hlen, ll_rs;
773 struct ip_fraglist_iter iter; 773 struct ip_fraglist_iter iter;
774 ktime_t tstamp = skb->tstamp;
774 struct ip_frag_state state; 775 struct ip_frag_state state;
775 int err = 0; 776 int err = 0;
776 777
@@ -846,6 +847,7 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
846 ip_fraglist_prepare(skb, &iter); 847 ip_fraglist_prepare(skb, &iter);
847 } 848 }
848 849
850 skb->tstamp = tstamp;
849 err = output(net, sk, skb); 851 err = output(net, sk, skb);
850 852
851 if (!err) 853 if (!err)
@@ -881,7 +883,8 @@ slow_path:
881 * Fragment the datagram. 883 * Fragment the datagram.
882 */ 884 */
883 885
884 ip_frag_init(skb, hlen, ll_rs, mtu, &state); 886 ip_frag_init(skb, hlen, ll_rs, mtu, IPCB(skb)->flags & IPSKB_FRAG_PMTU,
887 &state);
885 888
886 /* 889 /*
887 * Keep copying data until we run out. 890 * Keep copying data until we run out.
@@ -900,6 +903,7 @@ slow_path:
900 /* 903 /*
901 * Put this fragment into the sending queue. 904 * Put this fragment into the sending queue.
902 */ 905 */
906 skb2->tstamp = tstamp;
903 err = output(net, sk, skb2); 907 err = output(net, sk, skb2);
904 if (err) 908 if (err)
905 goto fail; 909 goto fail;
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 313470f6bb14..716d5472c022 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -1794,7 +1794,7 @@ static void ip_encap(struct net *net, struct sk_buff *skb,
1794 ip_send_check(iph); 1794 ip_send_check(iph);
1795 1795
1796 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); 1796 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
1797 nf_reset(skb); 1797 nf_reset_ct(skb);
1798} 1798}
1799 1799
1800static inline int ipmr_forward_finish(struct net *net, struct sock *sk, 1800static inline int ipmr_forward_finish(struct net *net, struct sock *sk,
@@ -2140,7 +2140,7 @@ int ip_mr_input(struct sk_buff *skb)
2140 2140
2141 mroute_sk = rcu_dereference(mrt->mroute_sk); 2141 mroute_sk = rcu_dereference(mrt->mroute_sk);
2142 if (mroute_sk) { 2142 if (mroute_sk) {
2143 nf_reset(skb); 2143 nf_reset_ct(skb);
2144 raw_rcv(mroute_sk, skb); 2144 raw_rcv(mroute_sk, skb);
2145 return 0; 2145 return 0;
2146 } 2146 }
diff --git a/net/ipv4/netfilter/nf_dup_ipv4.c b/net/ipv4/netfilter/nf_dup_ipv4.c
index af3fbf76dbd3..6cc5743c553a 100644
--- a/net/ipv4/netfilter/nf_dup_ipv4.c
+++ b/net/ipv4/netfilter/nf_dup_ipv4.c
@@ -65,7 +65,7 @@ void nf_dup_ipv4(struct net *net, struct sk_buff *skb, unsigned int hooknum,
65 65
66#if IS_ENABLED(CONFIG_NF_CONNTRACK) 66#if IS_ENABLED(CONFIG_NF_CONNTRACK)
67 /* Avoid counting cloned packets towards the original connection. */ 67 /* Avoid counting cloned packets towards the original connection. */
68 nf_reset(skb); 68 nf_reset_ct(skb);
69 nf_ct_set(skb, NULL, IP_CT_UNTRACKED); 69 nf_ct_set(skb, NULL, IP_CT_UNTRACKED);
70#endif 70#endif
71 /* 71 /*
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index 80da5a66d5d7..3183413ebc6c 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -332,7 +332,7 @@ int raw_rcv(struct sock *sk, struct sk_buff *skb)
332 kfree_skb(skb); 332 kfree_skb(skb);
333 return NET_RX_DROP; 333 return NET_RX_DROP;
334 } 334 }
335 nf_reset(skb); 335 nf_reset_ct(skb);
336 336
337 skb_push(skb, skb->data - skb_network_header(skb)); 337 skb_push(skb, skb->data - skb_network_header(skb));
338 338
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 7dcce724c78b..621f83434b24 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -916,16 +916,15 @@ void ip_rt_send_redirect(struct sk_buff *skb)
916 if (peer->rate_tokens == 0 || 916 if (peer->rate_tokens == 0 ||
917 time_after(jiffies, 917 time_after(jiffies,
918 (peer->rate_last + 918 (peer->rate_last +
919 (ip_rt_redirect_load << peer->rate_tokens)))) { 919 (ip_rt_redirect_load << peer->n_redirects)))) {
920 __be32 gw = rt_nexthop(rt, ip_hdr(skb)->daddr); 920 __be32 gw = rt_nexthop(rt, ip_hdr(skb)->daddr);
921 921
922 icmp_send(skb, ICMP_REDIRECT, ICMP_REDIR_HOST, gw); 922 icmp_send(skb, ICMP_REDIRECT, ICMP_REDIR_HOST, gw);
923 peer->rate_last = jiffies; 923 peer->rate_last = jiffies;
924 ++peer->rate_tokens;
925 ++peer->n_redirects; 924 ++peer->n_redirects;
926#ifdef CONFIG_IP_ROUTE_VERBOSE 925#ifdef CONFIG_IP_ROUTE_VERBOSE
927 if (log_martians && 926 if (log_martians &&
928 peer->rate_tokens == ip_rt_redirect_number) 927 peer->n_redirects == ip_rt_redirect_number)
929 net_warn_ratelimited("host %pI4/if%d ignores redirects for %pI4 to %pI4\n", 928 net_warn_ratelimited("host %pI4/if%d ignores redirects for %pI4 to %pI4\n",
930 &ip_hdr(skb)->saddr, inet_iif(skb), 929 &ip_hdr(skb)->saddr, inet_iif(skb),
931 &ip_hdr(skb)->daddr, &gw); 930 &ip_hdr(skb)->daddr, &gw);
@@ -1483,7 +1482,7 @@ static bool rt_cache_route(struct fib_nh_common *nhc, struct rtable *rt)
1483 prev = cmpxchg(p, orig, rt); 1482 prev = cmpxchg(p, orig, rt);
1484 if (prev == orig) { 1483 if (prev == orig) {
1485 if (orig) { 1484 if (orig) {
1486 dst_dev_put(&orig->dst); 1485 rt_add_uncached_list(orig);
1487 dst_release(&orig->dst); 1486 dst_release(&orig->dst);
1488 } 1487 }
1489 } else { 1488 } else {
@@ -2471,14 +2470,17 @@ struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *fl4,
2471 int orig_oif = fl4->flowi4_oif; 2470 int orig_oif = fl4->flowi4_oif;
2472 unsigned int flags = 0; 2471 unsigned int flags = 0;
2473 struct rtable *rth; 2472 struct rtable *rth;
2474 int err = -ENETUNREACH; 2473 int err;
2475 2474
2476 if (fl4->saddr) { 2475 if (fl4->saddr) {
2477 rth = ERR_PTR(-EINVAL);
2478 if (ipv4_is_multicast(fl4->saddr) || 2476 if (ipv4_is_multicast(fl4->saddr) ||
2479 ipv4_is_lbcast(fl4->saddr) || 2477 ipv4_is_lbcast(fl4->saddr) ||
2480 ipv4_is_zeronet(fl4->saddr)) 2478 ipv4_is_zeronet(fl4->saddr)) {
2479 rth = ERR_PTR(-EINVAL);
2481 goto out; 2480 goto out;
2481 }
2482
2483 rth = ERR_PTR(-ENETUNREACH);
2482 2484
2483 /* I removed check for oif == dev_out->oif here. 2485 /* I removed check for oif == dev_out->oif here.
2484 It was wrong for two reasons: 2486 It was wrong for two reasons:
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 79c325a07ba5..d8876f0e9672 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -326,7 +326,7 @@ void tcp_enter_memory_pressure(struct sock *sk)
326{ 326{
327 unsigned long val; 327 unsigned long val;
328 328
329 if (tcp_memory_pressure) 329 if (READ_ONCE(tcp_memory_pressure))
330 return; 330 return;
331 val = jiffies; 331 val = jiffies;
332 332
@@ -341,7 +341,7 @@ void tcp_leave_memory_pressure(struct sock *sk)
341{ 341{
342 unsigned long val; 342 unsigned long val;
343 343
344 if (!tcp_memory_pressure) 344 if (!READ_ONCE(tcp_memory_pressure))
345 return; 345 return;
346 val = xchg(&tcp_memory_pressure, 0); 346 val = xchg(&tcp_memory_pressure, 0);
347 if (val) 347 if (val)
@@ -450,8 +450,8 @@ void tcp_init_sock(struct sock *sk)
450 450
451 icsk->icsk_sync_mss = tcp_sync_mss; 451 icsk->icsk_sync_mss = tcp_sync_mss;
452 452
453 sk->sk_sndbuf = sock_net(sk)->ipv4.sysctl_tcp_wmem[1]; 453 WRITE_ONCE(sk->sk_sndbuf, sock_net(sk)->ipv4.sysctl_tcp_wmem[1]);
454 sk->sk_rcvbuf = sock_net(sk)->ipv4.sysctl_tcp_rmem[1]; 454 WRITE_ONCE(sk->sk_rcvbuf, sock_net(sk)->ipv4.sysctl_tcp_rmem[1]);
455 455
456 sk_sockets_allocated_inc(sk); 456 sk_sockets_allocated_inc(sk);
457 sk->sk_route_forced_caps = NETIF_F_GSO; 457 sk->sk_route_forced_caps = NETIF_F_GSO;
@@ -477,7 +477,7 @@ static void tcp_tx_timestamp(struct sock *sk, u16 tsflags)
477static inline bool tcp_stream_is_readable(const struct tcp_sock *tp, 477static inline bool tcp_stream_is_readable(const struct tcp_sock *tp,
478 int target, struct sock *sk) 478 int target, struct sock *sk)
479{ 479{
480 return (tp->rcv_nxt - tp->copied_seq >= target) || 480 return (READ_ONCE(tp->rcv_nxt) - READ_ONCE(tp->copied_seq) >= target) ||
481 (sk->sk_prot->stream_memory_read ? 481 (sk->sk_prot->stream_memory_read ?
482 sk->sk_prot->stream_memory_read(sk) : false); 482 sk->sk_prot->stream_memory_read(sk) : false);
483} 483}
@@ -543,10 +543,10 @@ __poll_t tcp_poll(struct file *file, struct socket *sock, poll_table *wait)
543 543
544 /* Connected or passive Fast Open socket? */ 544 /* Connected or passive Fast Open socket? */
545 if (state != TCP_SYN_SENT && 545 if (state != TCP_SYN_SENT &&
546 (state != TCP_SYN_RECV || tp->fastopen_rsk)) { 546 (state != TCP_SYN_RECV || rcu_access_pointer(tp->fastopen_rsk))) {
547 int target = sock_rcvlowat(sk, 0, INT_MAX); 547 int target = sock_rcvlowat(sk, 0, INT_MAX);
548 548
549 if (tp->urg_seq == tp->copied_seq && 549 if (READ_ONCE(tp->urg_seq) == READ_ONCE(tp->copied_seq) &&
550 !sock_flag(sk, SOCK_URGINLINE) && 550 !sock_flag(sk, SOCK_URGINLINE) &&
551 tp->urg_data) 551 tp->urg_data)
552 target++; 552 target++;
@@ -584,7 +584,7 @@ __poll_t tcp_poll(struct file *file, struct socket *sock, poll_table *wait)
584 } 584 }
585 /* This barrier is coupled with smp_wmb() in tcp_reset() */ 585 /* This barrier is coupled with smp_wmb() in tcp_reset() */
586 smp_rmb(); 586 smp_rmb();
587 if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) 587 if (sk->sk_err || !skb_queue_empty_lockless(&sk->sk_error_queue))
588 mask |= EPOLLERR; 588 mask |= EPOLLERR;
589 589
590 return mask; 590 return mask;
@@ -607,7 +607,8 @@ int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg)
607 unlock_sock_fast(sk, slow); 607 unlock_sock_fast(sk, slow);
608 break; 608 break;
609 case SIOCATMARK: 609 case SIOCATMARK:
610 answ = tp->urg_data && tp->urg_seq == tp->copied_seq; 610 answ = tp->urg_data &&
611 READ_ONCE(tp->urg_seq) == READ_ONCE(tp->copied_seq);
611 break; 612 break;
612 case SIOCOUTQ: 613 case SIOCOUTQ:
613 if (sk->sk_state == TCP_LISTEN) 614 if (sk->sk_state == TCP_LISTEN)
@@ -616,7 +617,7 @@ int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg)
616 if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) 617 if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))
617 answ = 0; 618 answ = 0;
618 else 619 else
619 answ = tp->write_seq - tp->snd_una; 620 answ = READ_ONCE(tp->write_seq) - tp->snd_una;
620 break; 621 break;
621 case SIOCOUTQNSD: 622 case SIOCOUTQNSD:
622 if (sk->sk_state == TCP_LISTEN) 623 if (sk->sk_state == TCP_LISTEN)
@@ -625,7 +626,8 @@ int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg)
625 if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) 626 if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))
626 answ = 0; 627 answ = 0;
627 else 628 else
628 answ = tp->write_seq - tp->snd_nxt; 629 answ = READ_ONCE(tp->write_seq) -
630 READ_ONCE(tp->snd_nxt);
629 break; 631 break;
630 default: 632 default:
631 return -ENOIOCTLCMD; 633 return -ENOIOCTLCMD;
@@ -657,7 +659,7 @@ static void skb_entail(struct sock *sk, struct sk_buff *skb)
657 tcb->sacked = 0; 659 tcb->sacked = 0;
658 __skb_header_release(skb); 660 __skb_header_release(skb);
659 tcp_add_write_queue_tail(sk, skb); 661 tcp_add_write_queue_tail(sk, skb);
660 sk->sk_wmem_queued += skb->truesize; 662 sk_wmem_queued_add(sk, skb->truesize);
661 sk_mem_charge(sk, skb->truesize); 663 sk_mem_charge(sk, skb->truesize);
662 if (tp->nonagle & TCP_NAGLE_PUSH) 664 if (tp->nonagle & TCP_NAGLE_PUSH)
663 tp->nonagle &= ~TCP_NAGLE_PUSH; 665 tp->nonagle &= ~TCP_NAGLE_PUSH;
@@ -1032,10 +1034,10 @@ new_segment:
1032 skb->len += copy; 1034 skb->len += copy;
1033 skb->data_len += copy; 1035 skb->data_len += copy;
1034 skb->truesize += copy; 1036 skb->truesize += copy;
1035 sk->sk_wmem_queued += copy; 1037 sk_wmem_queued_add(sk, copy);
1036 sk_mem_charge(sk, copy); 1038 sk_mem_charge(sk, copy);
1037 skb->ip_summed = CHECKSUM_PARTIAL; 1039 skb->ip_summed = CHECKSUM_PARTIAL;
1038 tp->write_seq += copy; 1040 WRITE_ONCE(tp->write_seq, tp->write_seq + copy);
1039 TCP_SKB_CB(skb)->end_seq += copy; 1041 TCP_SKB_CB(skb)->end_seq += copy;
1040 tcp_skb_pcount_set(skb, 0); 1042 tcp_skb_pcount_set(skb, 0);
1041 1043
@@ -1362,7 +1364,7 @@ new_segment:
1362 if (!copied) 1364 if (!copied)
1363 TCP_SKB_CB(skb)->tcp_flags &= ~TCPHDR_PSH; 1365 TCP_SKB_CB(skb)->tcp_flags &= ~TCPHDR_PSH;
1364 1366
1365 tp->write_seq += copy; 1367 WRITE_ONCE(tp->write_seq, tp->write_seq + copy);
1366 TCP_SKB_CB(skb)->end_seq += copy; 1368 TCP_SKB_CB(skb)->end_seq += copy;
1367 tcp_skb_pcount_set(skb, 0); 1369 tcp_skb_pcount_set(skb, 0);
1368 1370
@@ -1668,9 +1670,9 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,
1668 sk_eat_skb(sk, skb); 1670 sk_eat_skb(sk, skb);
1669 if (!desc->count) 1671 if (!desc->count)
1670 break; 1672 break;
1671 tp->copied_seq = seq; 1673 WRITE_ONCE(tp->copied_seq, seq);
1672 } 1674 }
1673 tp->copied_seq = seq; 1675 WRITE_ONCE(tp->copied_seq, seq);
1674 1676
1675 tcp_rcv_space_adjust(sk); 1677 tcp_rcv_space_adjust(sk);
1676 1678
@@ -1699,7 +1701,7 @@ int tcp_set_rcvlowat(struct sock *sk, int val)
1699 else 1701 else
1700 cap = sock_net(sk)->ipv4.sysctl_tcp_rmem[2] >> 1; 1702 cap = sock_net(sk)->ipv4.sysctl_tcp_rmem[2] >> 1;
1701 val = min(val, cap); 1703 val = min(val, cap);
1702 sk->sk_rcvlowat = val ? : 1; 1704 WRITE_ONCE(sk->sk_rcvlowat, val ? : 1);
1703 1705
1704 /* Check if we need to signal EPOLLIN right now */ 1706 /* Check if we need to signal EPOLLIN right now */
1705 tcp_data_ready(sk); 1707 tcp_data_ready(sk);
@@ -1709,7 +1711,7 @@ int tcp_set_rcvlowat(struct sock *sk, int val)
1709 1711
1710 val <<= 1; 1712 val <<= 1;
1711 if (val > sk->sk_rcvbuf) { 1713 if (val > sk->sk_rcvbuf) {
1712 sk->sk_rcvbuf = val; 1714 WRITE_ONCE(sk->sk_rcvbuf, val);
1713 tcp_sk(sk)->window_clamp = tcp_win_from_space(sk, val); 1715 tcp_sk(sk)->window_clamp = tcp_win_from_space(sk, val);
1714 } 1716 }
1715 return 0; 1717 return 0;
@@ -1798,13 +1800,11 @@ static int tcp_zerocopy_receive(struct sock *sk,
1798 } 1800 }
1799 if (skb_frag_size(frags) != PAGE_SIZE || skb_frag_off(frags)) { 1801 if (skb_frag_size(frags) != PAGE_SIZE || skb_frag_off(frags)) {
1800 int remaining = zc->recv_skip_hint; 1802 int remaining = zc->recv_skip_hint;
1801 int size = skb_frag_size(frags);
1802 1803
1803 while (remaining && (size != PAGE_SIZE || 1804 while (remaining && (skb_frag_size(frags) != PAGE_SIZE ||
1804 skb_frag_off(frags))) { 1805 skb_frag_off(frags))) {
1805 remaining -= size; 1806 remaining -= skb_frag_size(frags);
1806 frags++; 1807 frags++;
1807 size = skb_frag_size(frags);
1808 } 1808 }
1809 zc->recv_skip_hint -= remaining; 1809 zc->recv_skip_hint -= remaining;
1810 break; 1810 break;
@@ -1821,7 +1821,7 @@ static int tcp_zerocopy_receive(struct sock *sk,
1821out: 1821out:
1822 up_read(&current->mm->mmap_sem); 1822 up_read(&current->mm->mmap_sem);
1823 if (length) { 1823 if (length) {
1824 tp->copied_seq = seq; 1824 WRITE_ONCE(tp->copied_seq, seq);
1825 tcp_rcv_space_adjust(sk); 1825 tcp_rcv_space_adjust(sk);
1826 1826
1827 /* Clean up data we have read: This will do ACK frames. */ 1827 /* Clean up data we have read: This will do ACK frames. */
@@ -1964,7 +1964,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock,
1964 if (unlikely(flags & MSG_ERRQUEUE)) 1964 if (unlikely(flags & MSG_ERRQUEUE))
1965 return inet_recv_error(sk, msg, len, addr_len); 1965 return inet_recv_error(sk, msg, len, addr_len);
1966 1966
1967 if (sk_can_busy_loop(sk) && skb_queue_empty(&sk->sk_receive_queue) && 1967 if (sk_can_busy_loop(sk) && skb_queue_empty_lockless(&sk->sk_receive_queue) &&
1968 (sk->sk_state == TCP_ESTABLISHED)) 1968 (sk->sk_state == TCP_ESTABLISHED))
1969 sk_busy_loop(sk, nonblock); 1969 sk_busy_loop(sk, nonblock);
1970 1970
@@ -2119,7 +2119,7 @@ found_ok_skb:
2119 if (urg_offset < used) { 2119 if (urg_offset < used) {
2120 if (!urg_offset) { 2120 if (!urg_offset) {
2121 if (!sock_flag(sk, SOCK_URGINLINE)) { 2121 if (!sock_flag(sk, SOCK_URGINLINE)) {
2122 ++*seq; 2122 WRITE_ONCE(*seq, *seq + 1);
2123 urg_hole++; 2123 urg_hole++;
2124 offset++; 2124 offset++;
2125 used--; 2125 used--;
@@ -2141,7 +2141,7 @@ found_ok_skb:
2141 } 2141 }
2142 } 2142 }
2143 2143
2144 *seq += used; 2144 WRITE_ONCE(*seq, *seq + used);
2145 copied += used; 2145 copied += used;
2146 len -= used; 2146 len -= used;
2147 2147
@@ -2168,7 +2168,7 @@ skip_copy:
2168 2168
2169found_fin_ok: 2169found_fin_ok:
2170 /* Process the FIN. */ 2170 /* Process the FIN. */
2171 ++*seq; 2171 WRITE_ONCE(*seq, *seq + 1);
2172 if (!(flags & MSG_PEEK)) 2172 if (!(flags & MSG_PEEK))
2173 sk_eat_skb(sk, skb); 2173 sk_eat_skb(sk, skb);
2174 break; 2174 break;
@@ -2489,7 +2489,10 @@ adjudge_to_death:
2489 } 2489 }
2490 2490
2491 if (sk->sk_state == TCP_CLOSE) { 2491 if (sk->sk_state == TCP_CLOSE) {
2492 struct request_sock *req = tcp_sk(sk)->fastopen_rsk; 2492 struct request_sock *req;
2493
2494 req = rcu_dereference_protected(tcp_sk(sk)->fastopen_rsk,
2495 lockdep_sock_is_held(sk));
2493 /* We could get here with a non-NULL req if the socket is 2496 /* We could get here with a non-NULL req if the socket is
2494 * aborted (e.g., closed with unread data) before 3WHS 2497 * aborted (e.g., closed with unread data) before 3WHS
2495 * finishes. 2498 * finishes.
@@ -2561,6 +2564,7 @@ int tcp_disconnect(struct sock *sk, int flags)
2561 struct inet_connection_sock *icsk = inet_csk(sk); 2564 struct inet_connection_sock *icsk = inet_csk(sk);
2562 struct tcp_sock *tp = tcp_sk(sk); 2565 struct tcp_sock *tp = tcp_sk(sk);
2563 int old_state = sk->sk_state; 2566 int old_state = sk->sk_state;
2567 u32 seq;
2564 2568
2565 if (old_state != TCP_CLOSE) 2569 if (old_state != TCP_CLOSE)
2566 tcp_set_state(sk, TCP_CLOSE); 2570 tcp_set_state(sk, TCP_CLOSE);
@@ -2587,7 +2591,7 @@ int tcp_disconnect(struct sock *sk, int flags)
2587 __kfree_skb(sk->sk_rx_skb_cache); 2591 __kfree_skb(sk->sk_rx_skb_cache);
2588 sk->sk_rx_skb_cache = NULL; 2592 sk->sk_rx_skb_cache = NULL;
2589 } 2593 }
2590 tp->copied_seq = tp->rcv_nxt; 2594 WRITE_ONCE(tp->copied_seq, tp->rcv_nxt);
2591 tp->urg_data = 0; 2595 tp->urg_data = 0;
2592 tcp_write_queue_purge(sk); 2596 tcp_write_queue_purge(sk);
2593 tcp_fastopen_active_disable_ofo_check(sk); 2597 tcp_fastopen_active_disable_ofo_check(sk);
@@ -2603,9 +2607,12 @@ int tcp_disconnect(struct sock *sk, int flags)
2603 tp->srtt_us = 0; 2607 tp->srtt_us = 0;
2604 tp->mdev_us = jiffies_to_usecs(TCP_TIMEOUT_INIT); 2608 tp->mdev_us = jiffies_to_usecs(TCP_TIMEOUT_INIT);
2605 tp->rcv_rtt_last_tsecr = 0; 2609 tp->rcv_rtt_last_tsecr = 0;
2606 tp->write_seq += tp->max_window + 2; 2610
2607 if (tp->write_seq == 0) 2611 seq = tp->write_seq + tp->max_window + 2;
2608 tp->write_seq = 1; 2612 if (!seq)
2613 seq = 1;
2614 WRITE_ONCE(tp->write_seq, seq);
2615
2609 icsk->icsk_backoff = 0; 2616 icsk->icsk_backoff = 0;
2610 tp->snd_cwnd = 2; 2617 tp->snd_cwnd = 2;
2611 icsk->icsk_probes_out = 0; 2618 icsk->icsk_probes_out = 0;
@@ -2932,9 +2939,9 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
2932 if (sk->sk_state != TCP_CLOSE) 2939 if (sk->sk_state != TCP_CLOSE)
2933 err = -EPERM; 2940 err = -EPERM;
2934 else if (tp->repair_queue == TCP_SEND_QUEUE) 2941 else if (tp->repair_queue == TCP_SEND_QUEUE)
2935 tp->write_seq = val; 2942 WRITE_ONCE(tp->write_seq, val);
2936 else if (tp->repair_queue == TCP_RECV_QUEUE) 2943 else if (tp->repair_queue == TCP_RECV_QUEUE)
2937 tp->rcv_nxt = val; 2944 WRITE_ONCE(tp->rcv_nxt, val);
2938 else 2945 else
2939 err = -EINVAL; 2946 err = -EINVAL;
2940 break; 2947 break;
@@ -3833,7 +3840,13 @@ EXPORT_SYMBOL(tcp_md5_hash_key);
3833 3840
3834void tcp_done(struct sock *sk) 3841void tcp_done(struct sock *sk)
3835{ 3842{
3836 struct request_sock *req = tcp_sk(sk)->fastopen_rsk; 3843 struct request_sock *req;
3844
3845 /* We might be called with a new socket, after
3846 * inet_csk_prepare_forced_close() has been called
3847 * so we can not use lockdep_sock_is_held(sk)
3848 */
3849 req = rcu_dereference_protected(tcp_sk(sk)->fastopen_rsk, 1);
3837 3850
3838 if (sk->sk_state == TCP_SYN_SENT || sk->sk_state == TCP_SYN_RECV) 3851 if (sk->sk_state == TCP_SYN_SENT || sk->sk_state == TCP_SYN_RECV)
3839 TCP_INC_STATS(sock_net(sk), TCP_MIB_ATTEMPTFAILS); 3852 TCP_INC_STATS(sock_net(sk), TCP_MIB_ATTEMPTFAILS);
diff --git a/net/ipv4/tcp_diag.c b/net/ipv4/tcp_diag.c
index 81a8221d650a..549506162dde 100644
--- a/net/ipv4/tcp_diag.c
+++ b/net/ipv4/tcp_diag.c
@@ -26,8 +26,9 @@ static void tcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
26 } else if (sk->sk_type == SOCK_STREAM) { 26 } else if (sk->sk_type == SOCK_STREAM) {
27 const struct tcp_sock *tp = tcp_sk(sk); 27 const struct tcp_sock *tp = tcp_sk(sk);
28 28
29 r->idiag_rqueue = max_t(int, tp->rcv_nxt - tp->copied_seq, 0); 29 r->idiag_rqueue = max_t(int, READ_ONCE(tp->rcv_nxt) -
30 r->idiag_wqueue = tp->write_seq - tp->snd_una; 30 READ_ONCE(tp->copied_seq), 0);
31 r->idiag_wqueue = READ_ONCE(tp->write_seq) - tp->snd_una;
31 } 32 }
32 if (info) 33 if (info)
33 tcp_get_info(sk, info); 34 tcp_get_info(sk, info);
diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c
index 3fd451271a70..a915ade0c818 100644
--- a/net/ipv4/tcp_fastopen.c
+++ b/net/ipv4/tcp_fastopen.c
@@ -253,7 +253,7 @@ static struct sock *tcp_fastopen_create_child(struct sock *sk,
253 */ 253 */
254 tp = tcp_sk(child); 254 tp = tcp_sk(child);
255 255
256 tp->fastopen_rsk = req; 256 rcu_assign_pointer(tp->fastopen_rsk, req);
257 tcp_rsk(req)->tfo_listener = true; 257 tcp_rsk(req)->tfo_listener = true;
258 258
259 /* RFC1323: The window in SYN & SYN/ACK segments is never 259 /* RFC1323: The window in SYN & SYN/ACK segments is never
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 3578357abe30..a2e52ad7cdab 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -359,7 +359,8 @@ static void tcp_sndbuf_expand(struct sock *sk)
359 sndmem *= nr_segs * per_mss; 359 sndmem *= nr_segs * per_mss;
360 360
361 if (sk->sk_sndbuf < sndmem) 361 if (sk->sk_sndbuf < sndmem)
362 sk->sk_sndbuf = min(sndmem, sock_net(sk)->ipv4.sysctl_tcp_wmem[2]); 362 WRITE_ONCE(sk->sk_sndbuf,
363 min(sndmem, sock_net(sk)->ipv4.sysctl_tcp_wmem[2]));
363} 364}
364 365
365/* 2. Tuning advertised window (window_clamp, rcv_ssthresh) 366/* 2. Tuning advertised window (window_clamp, rcv_ssthresh)
@@ -483,8 +484,9 @@ static void tcp_clamp_window(struct sock *sk)
483 !(sk->sk_userlocks & SOCK_RCVBUF_LOCK) && 484 !(sk->sk_userlocks & SOCK_RCVBUF_LOCK) &&
484 !tcp_under_memory_pressure(sk) && 485 !tcp_under_memory_pressure(sk) &&
485 sk_memory_allocated(sk) < sk_prot_mem_limits(sk, 0)) { 486 sk_memory_allocated(sk) < sk_prot_mem_limits(sk, 0)) {
486 sk->sk_rcvbuf = min(atomic_read(&sk->sk_rmem_alloc), 487 WRITE_ONCE(sk->sk_rcvbuf,
487 net->ipv4.sysctl_tcp_rmem[2]); 488 min(atomic_read(&sk->sk_rmem_alloc),
489 net->ipv4.sysctl_tcp_rmem[2]));
488 } 490 }
489 if (atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf) 491 if (atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf)
490 tp->rcv_ssthresh = min(tp->window_clamp, 2U * tp->advmss); 492 tp->rcv_ssthresh = min(tp->window_clamp, 2U * tp->advmss);
@@ -648,7 +650,7 @@ void tcp_rcv_space_adjust(struct sock *sk)
648 rcvbuf = min_t(u64, rcvwin * rcvmem, 650 rcvbuf = min_t(u64, rcvwin * rcvmem,
649 sock_net(sk)->ipv4.sysctl_tcp_rmem[2]); 651 sock_net(sk)->ipv4.sysctl_tcp_rmem[2]);
650 if (rcvbuf > sk->sk_rcvbuf) { 652 if (rcvbuf > sk->sk_rcvbuf) {
651 sk->sk_rcvbuf = rcvbuf; 653 WRITE_ONCE(sk->sk_rcvbuf, rcvbuf);
652 654
653 /* Make the window clamp follow along. */ 655 /* Make the window clamp follow along. */
654 tp->window_clamp = tcp_win_from_space(sk, rcvbuf); 656 tp->window_clamp = tcp_win_from_space(sk, rcvbuf);
@@ -2666,7 +2668,7 @@ static void tcp_process_loss(struct sock *sk, int flag, int num_dupack,
2666 struct tcp_sock *tp = tcp_sk(sk); 2668 struct tcp_sock *tp = tcp_sk(sk);
2667 bool recovered = !before(tp->snd_una, tp->high_seq); 2669 bool recovered = !before(tp->snd_una, tp->high_seq);
2668 2670
2669 if ((flag & FLAG_SND_UNA_ADVANCED || tp->fastopen_rsk) && 2671 if ((flag & FLAG_SND_UNA_ADVANCED || rcu_access_pointer(tp->fastopen_rsk)) &&
2670 tcp_try_undo_loss(sk, false)) 2672 tcp_try_undo_loss(sk, false))
2671 return; 2673 return;
2672 2674
@@ -2990,7 +2992,7 @@ void tcp_rearm_rto(struct sock *sk)
2990 /* If the retrans timer is currently being used by Fast Open 2992 /* If the retrans timer is currently being used by Fast Open
2991 * for SYN-ACK retrans purpose, stay put. 2993 * for SYN-ACK retrans purpose, stay put.
2992 */ 2994 */
2993 if (tp->fastopen_rsk) 2995 if (rcu_access_pointer(tp->fastopen_rsk))
2994 return; 2996 return;
2995 2997
2996 if (!tp->packets_out) { 2998 if (!tp->packets_out) {
@@ -3362,7 +3364,7 @@ static void tcp_rcv_nxt_update(struct tcp_sock *tp, u32 seq)
3362 3364
3363 sock_owned_by_me((struct sock *)tp); 3365 sock_owned_by_me((struct sock *)tp);
3364 tp->bytes_received += delta; 3366 tp->bytes_received += delta;
3365 tp->rcv_nxt = seq; 3367 WRITE_ONCE(tp->rcv_nxt, seq);
3366} 3368}
3367 3369
3368/* Update our send window. 3370/* Update our send window.
@@ -5356,7 +5358,7 @@ static void tcp_check_urg(struct sock *sk, const struct tcphdr *th)
5356 } 5358 }
5357 5359
5358 tp->urg_data = TCP_URG_NOTYET; 5360 tp->urg_data = TCP_URG_NOTYET;
5359 tp->urg_seq = ptr; 5361 WRITE_ONCE(tp->urg_seq, ptr);
5360 5362
5361 /* Disable header prediction. */ 5363 /* Disable header prediction. */
5362 tp->pred_flags = 0; 5364 tp->pred_flags = 0;
@@ -5932,7 +5934,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
5932 /* Ok.. it's good. Set up sequence numbers and 5934 /* Ok.. it's good. Set up sequence numbers and
5933 * move to established. 5935 * move to established.
5934 */ 5936 */
5935 tp->rcv_nxt = TCP_SKB_CB(skb)->seq + 1; 5937 WRITE_ONCE(tp->rcv_nxt, TCP_SKB_CB(skb)->seq + 1);
5936 tp->rcv_wup = TCP_SKB_CB(skb)->seq + 1; 5938 tp->rcv_wup = TCP_SKB_CB(skb)->seq + 1;
5937 5939
5938 /* RFC1323: The window in SYN & SYN/ACK segments is 5940 /* RFC1323: The window in SYN & SYN/ACK segments is
@@ -5961,7 +5963,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
5961 /* Remember, tcp_poll() does not lock socket! 5963 /* Remember, tcp_poll() does not lock socket!
5962 * Change state from SYN-SENT only after copied_seq 5964 * Change state from SYN-SENT only after copied_seq
5963 * is initialized. */ 5965 * is initialized. */
5964 tp->copied_seq = tp->rcv_nxt; 5966 WRITE_ONCE(tp->copied_seq, tp->rcv_nxt);
5965 5967
5966 smc_check_reset_syn(tp); 5968 smc_check_reset_syn(tp);
5967 5969
@@ -6035,8 +6037,8 @@ discard:
6035 tp->tcp_header_len = sizeof(struct tcphdr); 6037 tp->tcp_header_len = sizeof(struct tcphdr);
6036 } 6038 }
6037 6039
6038 tp->rcv_nxt = TCP_SKB_CB(skb)->seq + 1; 6040 WRITE_ONCE(tp->rcv_nxt, TCP_SKB_CB(skb)->seq + 1);
6039 tp->copied_seq = tp->rcv_nxt; 6041 WRITE_ONCE(tp->copied_seq, tp->rcv_nxt);
6040 tp->rcv_wup = TCP_SKB_CB(skb)->seq + 1; 6042 tp->rcv_wup = TCP_SKB_CB(skb)->seq + 1;
6041 6043
6042 /* RFC1323: The window in SYN & SYN/ACK segments is 6044 /* RFC1323: The window in SYN & SYN/ACK segments is
@@ -6087,6 +6089,8 @@ reset_and_undo:
6087 6089
6088static void tcp_rcv_synrecv_state_fastopen(struct sock *sk) 6090static void tcp_rcv_synrecv_state_fastopen(struct sock *sk)
6089{ 6091{
6092 struct request_sock *req;
6093
6090 tcp_try_undo_loss(sk, false); 6094 tcp_try_undo_loss(sk, false);
6091 6095
6092 /* Reset rtx states to prevent spurious retransmits_timed_out() */ 6096 /* Reset rtx states to prevent spurious retransmits_timed_out() */
@@ -6096,7 +6100,9 @@ static void tcp_rcv_synrecv_state_fastopen(struct sock *sk)
6096 /* Once we leave TCP_SYN_RECV or TCP_FIN_WAIT_1, 6100 /* Once we leave TCP_SYN_RECV or TCP_FIN_WAIT_1,
6097 * we no longer need req so release it. 6101 * we no longer need req so release it.
6098 */ 6102 */
6099 reqsk_fastopen_remove(sk, tcp_sk(sk)->fastopen_rsk, false); 6103 req = rcu_dereference_protected(tcp_sk(sk)->fastopen_rsk,
6104 lockdep_sock_is_held(sk));
6105 reqsk_fastopen_remove(sk, req, false);
6100 6106
6101 /* Re-arm the timer because data may have been sent out. 6107 /* Re-arm the timer because data may have been sent out.
6102 * This is similar to the regular data transmission case 6108 * This is similar to the regular data transmission case
@@ -6171,7 +6177,8 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
6171 6177
6172 tcp_mstamp_refresh(tp); 6178 tcp_mstamp_refresh(tp);
6173 tp->rx_opt.saw_tstamp = 0; 6179 tp->rx_opt.saw_tstamp = 0;
6174 req = tp->fastopen_rsk; 6180 req = rcu_dereference_protected(tp->fastopen_rsk,
6181 lockdep_sock_is_held(sk));
6175 if (req) { 6182 if (req) {
6176 bool req_stolen; 6183 bool req_stolen;
6177 6184
@@ -6211,7 +6218,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
6211 tcp_try_undo_spurious_syn(sk); 6218 tcp_try_undo_spurious_syn(sk);
6212 tp->retrans_stamp = 0; 6219 tp->retrans_stamp = 0;
6213 tcp_init_transfer(sk, BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB); 6220 tcp_init_transfer(sk, BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB);
6214 tp->copied_seq = tp->rcv_nxt; 6221 WRITE_ONCE(tp->copied_seq, tp->rcv_nxt);
6215 } 6222 }
6216 smp_mb(); 6223 smp_mb();
6217 tcp_set_state(sk, TCP_ESTABLISHED); 6224 tcp_set_state(sk, TCP_ESTABLISHED);
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 2ee45e3755e9..b74192695955 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -164,9 +164,11 @@ int tcp_twsk_unique(struct sock *sk, struct sock *sktw, void *twp)
164 * without appearing to create any others. 164 * without appearing to create any others.
165 */ 165 */
166 if (likely(!tp->repair)) { 166 if (likely(!tp->repair)) {
167 tp->write_seq = tcptw->tw_snd_nxt + 65535 + 2; 167 u32 seq = tcptw->tw_snd_nxt + 65535 + 2;
168 if (tp->write_seq == 0) 168
169 tp->write_seq = 1; 169 if (!seq)
170 seq = 1;
171 WRITE_ONCE(tp->write_seq, seq);
170 tp->rx_opt.ts_recent = tcptw->tw_ts_recent; 172 tp->rx_opt.ts_recent = tcptw->tw_ts_recent;
171 tp->rx_opt.ts_recent_stamp = tcptw->tw_ts_recent_stamp; 173 tp->rx_opt.ts_recent_stamp = tcptw->tw_ts_recent_stamp;
172 } 174 }
@@ -253,7 +255,7 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
253 tp->rx_opt.ts_recent = 0; 255 tp->rx_opt.ts_recent = 0;
254 tp->rx_opt.ts_recent_stamp = 0; 256 tp->rx_opt.ts_recent_stamp = 0;
255 if (likely(!tp->repair)) 257 if (likely(!tp->repair))
256 tp->write_seq = 0; 258 WRITE_ONCE(tp->write_seq, 0);
257 } 259 }
258 260
259 inet->inet_dport = usin->sin_port; 261 inet->inet_dport = usin->sin_port;
@@ -291,10 +293,11 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
291 293
292 if (likely(!tp->repair)) { 294 if (likely(!tp->repair)) {
293 if (!tp->write_seq) 295 if (!tp->write_seq)
294 tp->write_seq = secure_tcp_seq(inet->inet_saddr, 296 WRITE_ONCE(tp->write_seq,
295 inet->inet_daddr, 297 secure_tcp_seq(inet->inet_saddr,
296 inet->inet_sport, 298 inet->inet_daddr,
297 usin->sin_port); 299 inet->inet_sport,
300 usin->sin_port));
298 tp->tsoffset = secure_tcp_ts_off(sock_net(sk), 301 tp->tsoffset = secure_tcp_ts_off(sock_net(sk),
299 inet->inet_saddr, 302 inet->inet_saddr,
300 inet->inet_daddr); 303 inet->inet_daddr);
@@ -478,7 +481,7 @@ int tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
478 icsk = inet_csk(sk); 481 icsk = inet_csk(sk);
479 tp = tcp_sk(sk); 482 tp = tcp_sk(sk);
480 /* XXX (TFO) - tp->snd_una should be ISN (tcp_create_openreq_child() */ 483 /* XXX (TFO) - tp->snd_una should be ISN (tcp_create_openreq_child() */
481 fastopen = tp->fastopen_rsk; 484 fastopen = rcu_dereference(tp->fastopen_rsk);
482 snd_una = fastopen ? tcp_rsk(fastopen)->snt_isn : tp->snd_una; 485 snd_una = fastopen ? tcp_rsk(fastopen)->snt_isn : tp->snd_una;
483 if (sk->sk_state != TCP_LISTEN && 486 if (sk->sk_state != TCP_LISTEN &&
484 !between(seq, snd_una, tp->snd_nxt)) { 487 !between(seq, snd_una, tp->snd_nxt)) {
@@ -1644,7 +1647,7 @@ int tcp_v4_early_demux(struct sk_buff *skb)
1644 1647
1645bool tcp_add_backlog(struct sock *sk, struct sk_buff *skb) 1648bool tcp_add_backlog(struct sock *sk, struct sk_buff *skb)
1646{ 1649{
1647 u32 limit = sk->sk_rcvbuf + sk->sk_sndbuf; 1650 u32 limit = READ_ONCE(sk->sk_rcvbuf) + READ_ONCE(sk->sk_sndbuf);
1648 struct skb_shared_info *shinfo; 1651 struct skb_shared_info *shinfo;
1649 const struct tcphdr *th; 1652 const struct tcphdr *th;
1650 struct tcphdr *thtail; 1653 struct tcphdr *thtail;
@@ -1916,7 +1919,7 @@ process:
1916 if (tcp_v4_inbound_md5_hash(sk, skb)) 1919 if (tcp_v4_inbound_md5_hash(sk, skb))
1917 goto discard_and_relse; 1920 goto discard_and_relse;
1918 1921
1919 nf_reset(skb); 1922 nf_reset_ct(skb);
1920 1923
1921 if (tcp_filter(sk, skb)) 1924 if (tcp_filter(sk, skb))
1922 goto discard_and_relse; 1925 goto discard_and_relse;
@@ -2121,7 +2124,7 @@ void tcp_v4_destroy_sock(struct sock *sk)
2121 if (inet_csk(sk)->icsk_bind_hash) 2124 if (inet_csk(sk)->icsk_bind_hash)
2122 inet_put_port(sk); 2125 inet_put_port(sk);
2123 2126
2124 BUG_ON(tp->fastopen_rsk); 2127 BUG_ON(rcu_access_pointer(tp->fastopen_rsk));
2125 2128
2126 /* If socket is aborted during connect operation */ 2129 /* If socket is aborted during connect operation */
2127 tcp_free_fastopen_req(tp); 2130 tcp_free_fastopen_req(tp);
@@ -2455,12 +2458,13 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i)
2455 /* Because we don't lock the socket, 2458 /* Because we don't lock the socket,
2456 * we might find a transient negative value. 2459 * we might find a transient negative value.
2457 */ 2460 */
2458 rx_queue = max_t(int, tp->rcv_nxt - tp->copied_seq, 0); 2461 rx_queue = max_t(int, READ_ONCE(tp->rcv_nxt) -
2462 READ_ONCE(tp->copied_seq), 0);
2459 2463
2460 seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX " 2464 seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
2461 "%08X %5u %8d %lu %d %pK %lu %lu %u %u %d", 2465 "%08X %5u %8d %lu %d %pK %lu %lu %u %u %d",
2462 i, src, srcp, dest, destp, state, 2466 i, src, srcp, dest, destp, state,
2463 tp->write_seq - tp->snd_una, 2467 READ_ONCE(tp->write_seq) - tp->snd_una,
2464 rx_queue, 2468 rx_queue,
2465 timer_active, 2469 timer_active,
2466 jiffies_delta_to_clock_t(timer_expires - jiffies), 2470 jiffies_delta_to_clock_t(timer_expires - jiffies),
@@ -2677,7 +2681,7 @@ static int __net_init tcp_sk_init(struct net *net)
2677 net->ipv4.tcp_death_row.sysctl_max_tw_buckets = cnt / 2; 2681 net->ipv4.tcp_death_row.sysctl_max_tw_buckets = cnt / 2;
2678 net->ipv4.tcp_death_row.hashinfo = &tcp_hashinfo; 2682 net->ipv4.tcp_death_row.hashinfo = &tcp_hashinfo;
2679 2683
2680 net->ipv4.sysctl_max_syn_backlog = max(128, cnt / 256); 2684 net->ipv4.sysctl_max_syn_backlog = max(128, cnt / 128);
2681 net->ipv4.sysctl_tcp_sack = 1; 2685 net->ipv4.sysctl_tcp_sack = 1;
2682 net->ipv4.sysctl_tcp_window_scaling = 1; 2686 net->ipv4.sysctl_tcp_window_scaling = 1;
2683 net->ipv4.sysctl_tcp_timestamps = 1; 2687 net->ipv4.sysctl_tcp_timestamps = 1;
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index bb140a5db8c0..c802bc80c400 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -462,6 +462,7 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
462 struct tcp_request_sock *treq = tcp_rsk(req); 462 struct tcp_request_sock *treq = tcp_rsk(req);
463 struct inet_connection_sock *newicsk; 463 struct inet_connection_sock *newicsk;
464 struct tcp_sock *oldtp, *newtp; 464 struct tcp_sock *oldtp, *newtp;
465 u32 seq;
465 466
466 if (!newsk) 467 if (!newsk)
467 return NULL; 468 return NULL;
@@ -475,12 +476,16 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
475 /* Now setup tcp_sock */ 476 /* Now setup tcp_sock */
476 newtp->pred_flags = 0; 477 newtp->pred_flags = 0;
477 478
478 newtp->rcv_wup = newtp->copied_seq = 479 seq = treq->rcv_isn + 1;
479 newtp->rcv_nxt = treq->rcv_isn + 1; 480 newtp->rcv_wup = seq;
481 WRITE_ONCE(newtp->copied_seq, seq);
482 WRITE_ONCE(newtp->rcv_nxt, seq);
480 newtp->segs_in = 1; 483 newtp->segs_in = 1;
481 484
482 newtp->snd_sml = newtp->snd_una = 485 seq = treq->snt_isn + 1;
483 newtp->snd_nxt = newtp->snd_up = treq->snt_isn + 1; 486 newtp->snd_sml = newtp->snd_una = seq;
487 WRITE_ONCE(newtp->snd_nxt, seq);
488 newtp->snd_up = seq;
484 489
485 INIT_LIST_HEAD(&newtp->tsq_node); 490 INIT_LIST_HEAD(&newtp->tsq_node);
486 INIT_LIST_HEAD(&newtp->tsorted_sent_queue); 491 INIT_LIST_HEAD(&newtp->tsorted_sent_queue);
@@ -495,7 +500,7 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
495 newtp->total_retrans = req->num_retrans; 500 newtp->total_retrans = req->num_retrans;
496 501
497 tcp_init_xmit_timers(newsk); 502 tcp_init_xmit_timers(newsk);
498 newtp->write_seq = newtp->pushed_seq = treq->snt_isn + 1; 503 WRITE_ONCE(newtp->write_seq, newtp->pushed_seq = treq->snt_isn + 1);
499 504
500 if (sock_flag(newsk, SOCK_KEEPOPEN)) 505 if (sock_flag(newsk, SOCK_KEEPOPEN))
501 inet_csk_reset_keepalive_timer(newsk, 506 inet_csk_reset_keepalive_timer(newsk,
@@ -541,7 +546,7 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
541 newtp->rx_opt.mss_clamp = req->mss; 546 newtp->rx_opt.mss_clamp = req->mss;
542 tcp_ecn_openreq_child(newtp, req); 547 tcp_ecn_openreq_child(newtp, req);
543 newtp->fastopen_req = NULL; 548 newtp->fastopen_req = NULL;
544 newtp->fastopen_rsk = NULL; 549 RCU_INIT_POINTER(newtp->fastopen_rsk, NULL);
545 550
546 __TCP_INC_STATS(sock_net(sk), TCP_MIB_PASSIVEOPENS); 551 __TCP_INC_STATS(sock_net(sk), TCP_MIB_PASSIVEOPENS);
547 552
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index fec6d67bfd14..0488607c5cd3 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -67,7 +67,7 @@ static void tcp_event_new_data_sent(struct sock *sk, struct sk_buff *skb)
67 struct tcp_sock *tp = tcp_sk(sk); 67 struct tcp_sock *tp = tcp_sk(sk);
68 unsigned int prior_packets = tp->packets_out; 68 unsigned int prior_packets = tp->packets_out;
69 69
70 tp->snd_nxt = TCP_SKB_CB(skb)->end_seq; 70 WRITE_ONCE(tp->snd_nxt, TCP_SKB_CB(skb)->end_seq);
71 71
72 __skb_unlink(skb, &sk->sk_write_queue); 72 __skb_unlink(skb, &sk->sk_write_queue);
73 tcp_rbtree_insert(&sk->tcp_rtx_queue, skb); 73 tcp_rbtree_insert(&sk->tcp_rtx_queue, skb);
@@ -1196,10 +1196,10 @@ static void tcp_queue_skb(struct sock *sk, struct sk_buff *skb)
1196 struct tcp_sock *tp = tcp_sk(sk); 1196 struct tcp_sock *tp = tcp_sk(sk);
1197 1197
1198 /* Advance write_seq and place onto the write_queue. */ 1198 /* Advance write_seq and place onto the write_queue. */
1199 tp->write_seq = TCP_SKB_CB(skb)->end_seq; 1199 WRITE_ONCE(tp->write_seq, TCP_SKB_CB(skb)->end_seq);
1200 __skb_header_release(skb); 1200 __skb_header_release(skb);
1201 tcp_add_write_queue_tail(sk, skb); 1201 tcp_add_write_queue_tail(sk, skb);
1202 sk->sk_wmem_queued += skb->truesize; 1202 sk_wmem_queued_add(sk, skb->truesize);
1203 sk_mem_charge(sk, skb->truesize); 1203 sk_mem_charge(sk, skb->truesize);
1204} 1204}
1205 1205
@@ -1333,7 +1333,7 @@ int tcp_fragment(struct sock *sk, enum tcp_queue tcp_queue,
1333 return -ENOMEM; /* We'll just try again later. */ 1333 return -ENOMEM; /* We'll just try again later. */
1334 skb_copy_decrypted(buff, skb); 1334 skb_copy_decrypted(buff, skb);
1335 1335
1336 sk->sk_wmem_queued += buff->truesize; 1336 sk_wmem_queued_add(sk, buff->truesize);
1337 sk_mem_charge(sk, buff->truesize); 1337 sk_mem_charge(sk, buff->truesize);
1338 nlen = skb->len - len - nsize; 1338 nlen = skb->len - len - nsize;
1339 buff->truesize += nlen; 1339 buff->truesize += nlen;
@@ -1443,7 +1443,7 @@ int tcp_trim_head(struct sock *sk, struct sk_buff *skb, u32 len)
1443 1443
1444 if (delta_truesize) { 1444 if (delta_truesize) {
1445 skb->truesize -= delta_truesize; 1445 skb->truesize -= delta_truesize;
1446 sk->sk_wmem_queued -= delta_truesize; 1446 sk_wmem_queued_add(sk, -delta_truesize);
1447 sk_mem_uncharge(sk, delta_truesize); 1447 sk_mem_uncharge(sk, delta_truesize);
1448 sock_set_flag(sk, SOCK_QUEUE_SHRUNK); 1448 sock_set_flag(sk, SOCK_QUEUE_SHRUNK);
1449 } 1449 }
@@ -1888,7 +1888,7 @@ static int tso_fragment(struct sock *sk, struct sk_buff *skb, unsigned int len,
1888 return -ENOMEM; 1888 return -ENOMEM;
1889 skb_copy_decrypted(buff, skb); 1889 skb_copy_decrypted(buff, skb);
1890 1890
1891 sk->sk_wmem_queued += buff->truesize; 1891 sk_wmem_queued_add(sk, buff->truesize);
1892 sk_mem_charge(sk, buff->truesize); 1892 sk_mem_charge(sk, buff->truesize);
1893 buff->truesize += nlen; 1893 buff->truesize += nlen;
1894 skb->truesize -= nlen; 1894 skb->truesize -= nlen;
@@ -2152,7 +2152,7 @@ static int tcp_mtu_probe(struct sock *sk)
2152 nskb = sk_stream_alloc_skb(sk, probe_size, GFP_ATOMIC, false); 2152 nskb = sk_stream_alloc_skb(sk, probe_size, GFP_ATOMIC, false);
2153 if (!nskb) 2153 if (!nskb)
2154 return -1; 2154 return -1;
2155 sk->sk_wmem_queued += nskb->truesize; 2155 sk_wmem_queued_add(sk, nskb->truesize);
2156 sk_mem_charge(sk, nskb->truesize); 2156 sk_mem_charge(sk, nskb->truesize);
2157 2157
2158 skb = tcp_send_head(sk); 2158 skb = tcp_send_head(sk);
@@ -2482,7 +2482,7 @@ bool tcp_schedule_loss_probe(struct sock *sk, bool advancing_rto)
2482 /* Don't do any loss probe on a Fast Open connection before 3WHS 2482 /* Don't do any loss probe on a Fast Open connection before 3WHS
2483 * finishes. 2483 * finishes.
2484 */ 2484 */
2485 if (tp->fastopen_rsk) 2485 if (rcu_access_pointer(tp->fastopen_rsk))
2486 return false; 2486 return false;
2487 2487
2488 early_retrans = sock_net(sk)->ipv4.sysctl_tcp_early_retrans; 2488 early_retrans = sock_net(sk)->ipv4.sysctl_tcp_early_retrans;
@@ -3142,7 +3142,7 @@ void tcp_send_fin(struct sock *sk)
3142 * if FIN had been sent. This is because retransmit path 3142 * if FIN had been sent. This is because retransmit path
3143 * does not change tp->snd_nxt. 3143 * does not change tp->snd_nxt.
3144 */ 3144 */
3145 tp->snd_nxt++; 3145 WRITE_ONCE(tp->snd_nxt, tp->snd_nxt + 1);
3146 return; 3146 return;
3147 } 3147 }
3148 } else { 3148 } else {
@@ -3222,7 +3222,7 @@ int tcp_send_synack(struct sock *sk)
3222 tcp_rtx_queue_unlink_and_free(skb, sk); 3222 tcp_rtx_queue_unlink_and_free(skb, sk);
3223 __skb_header_release(nskb); 3223 __skb_header_release(nskb);
3224 tcp_rbtree_insert(&sk->tcp_rtx_queue, nskb); 3224 tcp_rbtree_insert(&sk->tcp_rtx_queue, nskb);
3225 sk->sk_wmem_queued += nskb->truesize; 3225 sk_wmem_queued_add(sk, nskb->truesize);
3226 sk_mem_charge(sk, nskb->truesize); 3226 sk_mem_charge(sk, nskb->truesize);
3227 skb = nskb; 3227 skb = nskb;
3228 } 3228 }
@@ -3426,14 +3426,14 @@ static void tcp_connect_init(struct sock *sk)
3426 tp->snd_una = tp->write_seq; 3426 tp->snd_una = tp->write_seq;
3427 tp->snd_sml = tp->write_seq; 3427 tp->snd_sml = tp->write_seq;
3428 tp->snd_up = tp->write_seq; 3428 tp->snd_up = tp->write_seq;
3429 tp->snd_nxt = tp->write_seq; 3429 WRITE_ONCE(tp->snd_nxt, tp->write_seq);
3430 3430
3431 if (likely(!tp->repair)) 3431 if (likely(!tp->repair))
3432 tp->rcv_nxt = 0; 3432 tp->rcv_nxt = 0;
3433 else 3433 else
3434 tp->rcv_tstamp = tcp_jiffies32; 3434 tp->rcv_tstamp = tcp_jiffies32;
3435 tp->rcv_wup = tp->rcv_nxt; 3435 tp->rcv_wup = tp->rcv_nxt;
3436 tp->copied_seq = tp->rcv_nxt; 3436 WRITE_ONCE(tp->copied_seq, tp->rcv_nxt);
3437 3437
3438 inet_csk(sk)->icsk_rto = tcp_timeout_init(sk); 3438 inet_csk(sk)->icsk_rto = tcp_timeout_init(sk);
3439 inet_csk(sk)->icsk_retransmits = 0; 3439 inet_csk(sk)->icsk_retransmits = 0;
@@ -3447,9 +3447,9 @@ static void tcp_connect_queue_skb(struct sock *sk, struct sk_buff *skb)
3447 3447
3448 tcb->end_seq += skb->len; 3448 tcb->end_seq += skb->len;
3449 __skb_header_release(skb); 3449 __skb_header_release(skb);
3450 sk->sk_wmem_queued += skb->truesize; 3450 sk_wmem_queued_add(sk, skb->truesize);
3451 sk_mem_charge(sk, skb->truesize); 3451 sk_mem_charge(sk, skb->truesize);
3452 tp->write_seq = tcb->end_seq; 3452 WRITE_ONCE(tp->write_seq, tcb->end_seq);
3453 tp->packets_out += tcp_skb_pcount(skb); 3453 tp->packets_out += tcp_skb_pcount(skb);
3454} 3454}
3455 3455
@@ -3586,11 +3586,11 @@ int tcp_connect(struct sock *sk)
3586 /* We change tp->snd_nxt after the tcp_transmit_skb() call 3586 /* We change tp->snd_nxt after the tcp_transmit_skb() call
3587 * in order to make this packet get counted in tcpOutSegs. 3587 * in order to make this packet get counted in tcpOutSegs.
3588 */ 3588 */
3589 tp->snd_nxt = tp->write_seq; 3589 WRITE_ONCE(tp->snd_nxt, tp->write_seq);
3590 tp->pushed_seq = tp->write_seq; 3590 tp->pushed_seq = tp->write_seq;
3591 buff = tcp_send_head(sk); 3591 buff = tcp_send_head(sk);
3592 if (unlikely(buff)) { 3592 if (unlikely(buff)) {
3593 tp->snd_nxt = TCP_SKB_CB(buff)->seq; 3593 WRITE_ONCE(tp->snd_nxt, TCP_SKB_CB(buff)->seq);
3594 tp->pushed_seq = TCP_SKB_CB(buff)->seq; 3594 tp->pushed_seq = TCP_SKB_CB(buff)->seq;
3595 } 3595 }
3596 TCP_INC_STATS(sock_net(sk), TCP_MIB_ACTIVEOPENS); 3596 TCP_INC_STATS(sock_net(sk), TCP_MIB_ACTIVEOPENS);
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index 40de2d2364a1..dd5a6317a801 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -198,8 +198,13 @@ static bool retransmits_timed_out(struct sock *sk,
198 return false; 198 return false;
199 199
200 start_ts = tcp_sk(sk)->retrans_stamp; 200 start_ts = tcp_sk(sk)->retrans_stamp;
201 if (likely(timeout == 0)) 201 if (likely(timeout == 0)) {
202 timeout = tcp_model_timeout(sk, boundary, TCP_RTO_MIN); 202 unsigned int rto_base = TCP_RTO_MIN;
203
204 if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))
205 rto_base = tcp_timeout_init(sk);
206 timeout = tcp_model_timeout(sk, boundary, rto_base);
207 }
203 208
204 return (s32)(tcp_time_stamp(tcp_sk(sk)) - start_ts - timeout) >= 0; 209 return (s32)(tcp_time_stamp(tcp_sk(sk)) - start_ts - timeout) >= 0;
205} 210}
@@ -381,15 +386,13 @@ abort: tcp_write_err(sk);
381 * Timer for Fast Open socket to retransmit SYNACK. Note that the 386 * Timer for Fast Open socket to retransmit SYNACK. Note that the
382 * sk here is the child socket, not the parent (listener) socket. 387 * sk here is the child socket, not the parent (listener) socket.
383 */ 388 */
384static void tcp_fastopen_synack_timer(struct sock *sk) 389static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock *req)
385{ 390{
386 struct inet_connection_sock *icsk = inet_csk(sk); 391 struct inet_connection_sock *icsk = inet_csk(sk);
387 int max_retries = icsk->icsk_syn_retries ? : 392 int max_retries = icsk->icsk_syn_retries ? :
388 sock_net(sk)->ipv4.sysctl_tcp_synack_retries + 1; /* add one more retry for fastopen */ 393 sock_net(sk)->ipv4.sysctl_tcp_synack_retries + 1; /* add one more retry for fastopen */
389 struct tcp_sock *tp = tcp_sk(sk); 394 struct tcp_sock *tp = tcp_sk(sk);
390 struct request_sock *req;
391 395
392 req = tcp_sk(sk)->fastopen_rsk;
393 req->rsk_ops->syn_ack_timeout(req); 396 req->rsk_ops->syn_ack_timeout(req);
394 397
395 if (req->num_timeout >= max_retries) { 398 if (req->num_timeout >= max_retries) {
@@ -430,11 +433,14 @@ void tcp_retransmit_timer(struct sock *sk)
430 struct tcp_sock *tp = tcp_sk(sk); 433 struct tcp_sock *tp = tcp_sk(sk);
431 struct net *net = sock_net(sk); 434 struct net *net = sock_net(sk);
432 struct inet_connection_sock *icsk = inet_csk(sk); 435 struct inet_connection_sock *icsk = inet_csk(sk);
436 struct request_sock *req;
433 437
434 if (tp->fastopen_rsk) { 438 req = rcu_dereference_protected(tp->fastopen_rsk,
439 lockdep_sock_is_held(sk));
440 if (req) {
435 WARN_ON_ONCE(sk->sk_state != TCP_SYN_RECV && 441 WARN_ON_ONCE(sk->sk_state != TCP_SYN_RECV &&
436 sk->sk_state != TCP_FIN_WAIT1); 442 sk->sk_state != TCP_FIN_WAIT1);
437 tcp_fastopen_synack_timer(sk); 443 tcp_fastopen_synack_timer(sk, req);
438 /* Before we receive ACK to our SYN-ACK don't retransmit 444 /* Before we receive ACK to our SYN-ACK don't retransmit
439 * anything else (e.g., data or FIN segments). 445 * anything else (e.g., data or FIN segments).
440 */ 446 */
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index cf755156a684..1d58ce829dca 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -388,7 +388,7 @@ static int compute_score(struct sock *sk, struct net *net,
388 return -1; 388 return -1;
389 score += 4; 389 score += 4;
390 390
391 if (sk->sk_incoming_cpu == raw_smp_processor_id()) 391 if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id())
392 score++; 392 score++;
393 return score; 393 return score;
394} 394}
@@ -821,6 +821,7 @@ static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4,
821 int is_udplite = IS_UDPLITE(sk); 821 int is_udplite = IS_UDPLITE(sk);
822 int offset = skb_transport_offset(skb); 822 int offset = skb_transport_offset(skb);
823 int len = skb->len - offset; 823 int len = skb->len - offset;
824 int datalen = len - sizeof(*uh);
824 __wsum csum = 0; 825 __wsum csum = 0;
825 826
826 /* 827 /*
@@ -854,10 +855,12 @@ static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4,
854 return -EIO; 855 return -EIO;
855 } 856 }
856 857
857 skb_shinfo(skb)->gso_size = cork->gso_size; 858 if (datalen > cork->gso_size) {
858 skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4; 859 skb_shinfo(skb)->gso_size = cork->gso_size;
859 skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(len - sizeof(uh), 860 skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
860 cork->gso_size); 861 skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(datalen,
862 cork->gso_size);
863 }
861 goto csum_partial; 864 goto csum_partial;
862 } 865 }
863 866
@@ -1313,6 +1316,20 @@ static void udp_set_dev_scratch(struct sk_buff *skb)
1313 scratch->_tsize_state |= UDP_SKB_IS_STATELESS; 1316 scratch->_tsize_state |= UDP_SKB_IS_STATELESS;
1314} 1317}
1315 1318
1319static void udp_skb_csum_unnecessary_set(struct sk_buff *skb)
1320{
1321 /* We come here after udp_lib_checksum_complete() returned 0.
1322 * This means that __skb_checksum_complete() might have
1323 * set skb->csum_valid to 1.
1324 * On 64bit platforms, we can set csum_unnecessary
1325 * to true, but only if the skb is not shared.
1326 */
1327#if BITS_PER_LONG == 64
1328 if (!skb_shared(skb))
1329 udp_skb_scratch(skb)->csum_unnecessary = true;
1330#endif
1331}
1332
1316static int udp_skb_truesize(struct sk_buff *skb) 1333static int udp_skb_truesize(struct sk_buff *skb)
1317{ 1334{
1318 return udp_skb_scratch(skb)->_tsize_state & ~UDP_SKB_IS_STATELESS; 1335 return udp_skb_scratch(skb)->_tsize_state & ~UDP_SKB_IS_STATELESS;
@@ -1547,10 +1564,7 @@ static struct sk_buff *__first_packet_length(struct sock *sk,
1547 *total += skb->truesize; 1564 *total += skb->truesize;
1548 kfree_skb(skb); 1565 kfree_skb(skb);
1549 } else { 1566 } else {
1550 /* the csum related bits could be changed, refresh 1567 udp_skb_csum_unnecessary_set(skb);
1551 * the scratch area
1552 */
1553 udp_set_dev_scratch(skb);
1554 break; 1568 break;
1555 } 1569 }
1556 } 1570 }
@@ -1574,7 +1588,7 @@ static int first_packet_length(struct sock *sk)
1574 1588
1575 spin_lock_bh(&rcvq->lock); 1589 spin_lock_bh(&rcvq->lock);
1576 skb = __first_packet_length(sk, rcvq, &total); 1590 skb = __first_packet_length(sk, rcvq, &total);
1577 if (!skb && !skb_queue_empty(sk_queue)) { 1591 if (!skb && !skb_queue_empty_lockless(sk_queue)) {
1578 spin_lock(&sk_queue->lock); 1592 spin_lock(&sk_queue->lock);
1579 skb_queue_splice_tail_init(sk_queue, rcvq); 1593 skb_queue_splice_tail_init(sk_queue, rcvq);
1580 spin_unlock(&sk_queue->lock); 1594 spin_unlock(&sk_queue->lock);
@@ -1647,7 +1661,7 @@ struct sk_buff *__skb_recv_udp(struct sock *sk, unsigned int flags,
1647 return skb; 1661 return skb;
1648 } 1662 }
1649 1663
1650 if (skb_queue_empty(sk_queue)) { 1664 if (skb_queue_empty_lockless(sk_queue)) {
1651 spin_unlock_bh(&queue->lock); 1665 spin_unlock_bh(&queue->lock);
1652 goto busy_check; 1666 goto busy_check;
1653 } 1667 }
@@ -1673,7 +1687,7 @@ busy_check:
1673 break; 1687 break;
1674 1688
1675 sk_busy_loop(sk, flags & MSG_DONTWAIT); 1689 sk_busy_loop(sk, flags & MSG_DONTWAIT);
1676 } while (!skb_queue_empty(sk_queue)); 1690 } while (!skb_queue_empty_lockless(sk_queue));
1677 1691
1678 /* sk_queue is empty, reader_queue may contain peeked packets */ 1692 /* sk_queue is empty, reader_queue may contain peeked packets */
1679 } while (timeo && 1693 } while (timeo &&
@@ -1969,7 +1983,7 @@ static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb)
1969 */ 1983 */
1970 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) 1984 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
1971 goto drop; 1985 goto drop;
1972 nf_reset(skb); 1986 nf_reset_ct(skb);
1973 1987
1974 if (static_branch_unlikely(&udp_encap_needed_key) && up->encap_type) { 1988 if (static_branch_unlikely(&udp_encap_needed_key) && up->encap_type) {
1975 int (*encap_rcv)(struct sock *sk, struct sk_buff *skb); 1989 int (*encap_rcv)(struct sock *sk, struct sk_buff *skb);
@@ -2298,7 +2312,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
2298 2312
2299 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) 2313 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb))
2300 goto drop; 2314 goto drop;
2301 nf_reset(skb); 2315 nf_reset_ct(skb);
2302 2316
2303 /* No socket. Drop packet silently, if checksum is wrong */ 2317 /* No socket. Drop packet silently, if checksum is wrong */
2304 if (udp_lib_checksum_complete(skb)) 2318 if (udp_lib_checksum_complete(skb))
@@ -2709,7 +2723,7 @@ __poll_t udp_poll(struct file *file, struct socket *sock, poll_table *wait)
2709 __poll_t mask = datagram_poll(file, sock, wait); 2723 __poll_t mask = datagram_poll(file, sock, wait);
2710 struct sock *sk = sock->sk; 2724 struct sock *sk = sock->sk;
2711 2725
2712 if (!skb_queue_empty(&udp_sk(sk)->reader_queue)) 2726 if (!skb_queue_empty_lockless(&udp_sk(sk)->reader_queue))
2713 mask |= EPOLLIN | EPOLLRDNORM; 2727 mask |= EPOLLIN | EPOLLRDNORM;
2714 2728
2715 /* Check for false positives due to checksum errors */ 2729 /* Check for false positives due to checksum errors */
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 6a576ff92c39..34ccef18b40e 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -5964,13 +5964,20 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
5964 switch (event) { 5964 switch (event) {
5965 case RTM_NEWADDR: 5965 case RTM_NEWADDR:
5966 /* 5966 /*
5967 * If the address was optimistic 5967 * If the address was optimistic we inserted the route at the
5968 * we inserted the route at the start of 5968 * start of our DAD process, so we don't need to do it again.
5969 * our DAD process, so we don't need 5969 * If the device was taken down in the middle of the DAD
5970 * to do it again 5970 * cycle there is a race where we could get here without a
5971 * host route, so nothing to insert. That will be fixed when
5972 * the device is brought up.
5971 */ 5973 */
5972 if (!rcu_access_pointer(ifp->rt->fib6_node)) 5974 if (ifp->rt && !rcu_access_pointer(ifp->rt->fib6_node)) {
5973 ip6_ins_rt(net, ifp->rt); 5975 ip6_ins_rt(net, ifp->rt);
5976 } else if (!ifp->rt && (ifp->idev->dev->flags & IFF_UP)) {
5977 pr_warn("BUG: Address %pI6c on device %s is missing its host route.\n",
5978 &ifp->addr, ifp->idev->dev->name);
5979 }
5980
5974 if (ifp->idev->cnf.forwarding) 5981 if (ifp->idev->cnf.forwarding)
5975 addrconf_join_anycast(ifp); 5982 addrconf_join_anycast(ifp);
5976 if (!ipv6_addr_any(&ifp->peer_addr)) 5983 if (!ipv6_addr_any(&ifp->peer_addr))
diff --git a/net/ipv6/addrconf_core.c b/net/ipv6/addrconf_core.c
index 783f3c1466da..2fc079284ca4 100644
--- a/net/ipv6/addrconf_core.c
+++ b/net/ipv6/addrconf_core.c
@@ -7,6 +7,7 @@
7#include <linux/export.h> 7#include <linux/export.h>
8#include <net/ipv6.h> 8#include <net/ipv6.h>
9#include <net/ipv6_stubs.h> 9#include <net/ipv6_stubs.h>
10#include <net/addrconf.h>
10#include <net/ip.h> 11#include <net/ip.h>
11 12
12/* if ipv6 module registers this function is used by xfrm to force all 13/* if ipv6 module registers this function is used by xfrm to force all
diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
index cf60fae9533b..fbe9d4295eac 100644
--- a/net/ipv6/inet6_hashtables.c
+++ b/net/ipv6/inet6_hashtables.c
@@ -105,7 +105,7 @@ static inline int compute_score(struct sock *sk, struct net *net,
105 return -1; 105 return -1;
106 106
107 score = 1; 107 score = 1;
108 if (sk->sk_incoming_cpu == raw_smp_processor_id()) 108 if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id())
109 score++; 109 score++;
110 } 110 }
111 return score; 111 return score;
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index d5779d6a6065..923034c52ce4 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -980,9 +980,9 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
980 dsfield = key->tos; 980 dsfield = key->tos;
981 if (!(tun_info->key.tun_flags & TUNNEL_ERSPAN_OPT)) 981 if (!(tun_info->key.tun_flags & TUNNEL_ERSPAN_OPT))
982 goto tx_err; 982 goto tx_err;
983 md = ip_tunnel_info_opts(tun_info); 983 if (tun_info->options_len < sizeof(*md))
984 if (!md)
985 goto tx_err; 984 goto tx_err;
985 md = ip_tunnel_info_opts(tun_info);
986 986
987 tun_id = tunnel_id_to_key32(key->tun_id); 987 tun_id = tunnel_id_to_key32(key->tun_id);
988 if (md->version == 1) { 988 if (md->version == 1) {
@@ -2192,6 +2192,7 @@ static void ip6erspan_tap_setup(struct net_device *dev)
2192{ 2192{
2193 ether_setup(dev); 2193 ether_setup(dev);
2194 2194
2195 dev->max_mtu = 0;
2195 dev->netdev_ops = &ip6erspan_netdev_ops; 2196 dev->netdev_ops = &ip6erspan_netdev_ops;
2196 dev->needs_free_netdev = true; 2197 dev->needs_free_netdev = true;
2197 dev->priv_destructor = ip6gre_dev_free; 2198 dev->priv_destructor = ip6gre_dev_free;
diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c
index d432d0011c16..3d71c7d6102c 100644
--- a/net/ipv6/ip6_input.c
+++ b/net/ipv6/ip6_input.c
@@ -223,6 +223,16 @@ static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev,
223 if (ipv6_addr_is_multicast(&hdr->saddr)) 223 if (ipv6_addr_is_multicast(&hdr->saddr))
224 goto err; 224 goto err;
225 225
226 /* While RFC4291 is not explicit about v4mapped addresses
227 * in IPv6 headers, it seems clear linux dual-stack
228 * model can not deal properly with these.
229 * Security models could be fooled by ::ffff:127.0.0.1 for example.
230 *
231 * https://tools.ietf.org/html/draft-itojun-v6ops-v4mapped-harmful-02
232 */
233 if (ipv6_addr_v4mapped(&hdr->saddr))
234 goto err;
235
226 skb->transport_header = skb->network_header + sizeof(*hdr); 236 skb->transport_header = skb->network_header + sizeof(*hdr);
227 IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr); 237 IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr);
228 238
@@ -371,7 +381,7 @@ resubmit_final:
371 /* Free reference early: we don't need it any more, 381 /* Free reference early: we don't need it any more,
372 and it may hold ip_conntrack module loaded 382 and it may hold ip_conntrack module loaded
373 indefinitely. */ 383 indefinitely. */
374 nf_reset(skb); 384 nf_reset_ct(skb);
375 385
376 skb_postpull_rcsum(skb, skb_network_header(skb), 386 skb_postpull_rcsum(skb, skb_network_header(skb),
377 skb_network_header_len(skb)); 387 skb_network_header_len(skb));
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index edadee4a7e76..71827b56c006 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -768,6 +768,7 @@ int ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
768 inet6_sk(skb->sk) : NULL; 768 inet6_sk(skb->sk) : NULL;
769 struct ip6_frag_state state; 769 struct ip6_frag_state state;
770 unsigned int mtu, hlen, nexthdr_offset; 770 unsigned int mtu, hlen, nexthdr_offset;
771 ktime_t tstamp = skb->tstamp;
771 int hroom, err = 0; 772 int hroom, err = 0;
772 __be32 frag_id; 773 __be32 frag_id;
773 u8 *prevhdr, nexthdr = 0; 774 u8 *prevhdr, nexthdr = 0;
@@ -855,6 +856,7 @@ int ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
855 if (iter.frag) 856 if (iter.frag)
856 ip6_fraglist_prepare(skb, &iter); 857 ip6_fraglist_prepare(skb, &iter);
857 858
859 skb->tstamp = tstamp;
858 err = output(net, sk, skb); 860 err = output(net, sk, skb);
859 if (!err) 861 if (!err)
860 IP6_INC_STATS(net, ip6_dst_idev(&rt->dst), 862 IP6_INC_STATS(net, ip6_dst_idev(&rt->dst),
@@ -913,6 +915,7 @@ slow_path:
913 /* 915 /*
914 * Put this fragment into the sending queue. 916 * Put this fragment into the sending queue.
915 */ 917 */
918 frag->tstamp = tstamp;
916 err = output(net, sk, frag); 919 err = output(net, sk, frag);
917 if (err) 920 if (err)
918 goto fail; 921 goto fail;
diff --git a/net/ipv6/netfilter.c b/net/ipv6/netfilter.c
index a9bff556d3b2..409e79b84a83 100644
--- a/net/ipv6/netfilter.c
+++ b/net/ipv6/netfilter.c
@@ -119,6 +119,7 @@ int br_ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
119 struct sk_buff *)) 119 struct sk_buff *))
120{ 120{
121 int frag_max_size = BR_INPUT_SKB_CB(skb)->frag_max_size; 121 int frag_max_size = BR_INPUT_SKB_CB(skb)->frag_max_size;
122 ktime_t tstamp = skb->tstamp;
122 struct ip6_frag_state state; 123 struct ip6_frag_state state;
123 u8 *prevhdr, nexthdr = 0; 124 u8 *prevhdr, nexthdr = 0;
124 unsigned int mtu, hlen; 125 unsigned int mtu, hlen;
@@ -183,6 +184,7 @@ int br_ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
183 if (iter.frag) 184 if (iter.frag)
184 ip6_fraglist_prepare(skb, &iter); 185 ip6_fraglist_prepare(skb, &iter);
185 186
187 skb->tstamp = tstamp;
186 err = output(net, sk, data, skb); 188 err = output(net, sk, data, skb);
187 if (err || !iter.frag) 189 if (err || !iter.frag)
188 break; 190 break;
@@ -215,6 +217,7 @@ slow_path:
215 goto blackhole; 217 goto blackhole;
216 } 218 }
217 219
220 skb2->tstamp = tstamp;
218 err = output(net, sk, data, skb2); 221 err = output(net, sk, data, skb2);
219 if (err) 222 if (err)
220 goto blackhole; 223 goto blackhole;
diff --git a/net/ipv6/netfilter/nf_dup_ipv6.c b/net/ipv6/netfilter/nf_dup_ipv6.c
index e6c9da9866b1..a0a2de30be3e 100644
--- a/net/ipv6/netfilter/nf_dup_ipv6.c
+++ b/net/ipv6/netfilter/nf_dup_ipv6.c
@@ -54,7 +54,7 @@ void nf_dup_ipv6(struct net *net, struct sk_buff *skb, unsigned int hooknum,
54 return; 54 return;
55 55
56#if IS_ENABLED(CONFIG_NF_CONNTRACK) 56#if IS_ENABLED(CONFIG_NF_CONNTRACK)
57 nf_reset(skb); 57 nf_reset_ct(skb);
58 nf_ct_set(skb, NULL, IP_CT_UNTRACKED); 58 nf_ct_set(skb, NULL, IP_CT_UNTRACKED);
59#endif 59#endif
60 if (hooknum == NF_INET_PRE_ROUTING || 60 if (hooknum == NF_INET_PRE_ROUTING ||
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index 6e1888ee4036..a77f6b7d3a7c 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -215,7 +215,7 @@ static bool ipv6_raw_deliver(struct sk_buff *skb, int nexthdr)
215 215
216 /* Not releasing hash table! */ 216 /* Not releasing hash table! */
217 if (clone) { 217 if (clone) {
218 nf_reset(clone); 218 nf_reset_ct(clone);
219 rawv6_rcv(sk, clone); 219 rawv6_rcv(sk, clone);
220 } 220 }
221 } 221 }
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index e3d9f4559c99..4804b6dc5e65 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -215,7 +215,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
215 !ipv6_addr_equal(&sk->sk_v6_daddr, &usin->sin6_addr)) { 215 !ipv6_addr_equal(&sk->sk_v6_daddr, &usin->sin6_addr)) {
216 tp->rx_opt.ts_recent = 0; 216 tp->rx_opt.ts_recent = 0;
217 tp->rx_opt.ts_recent_stamp = 0; 217 tp->rx_opt.ts_recent_stamp = 0;
218 tp->write_seq = 0; 218 WRITE_ONCE(tp->write_seq, 0);
219 } 219 }
220 220
221 sk->sk_v6_daddr = usin->sin6_addr; 221 sk->sk_v6_daddr = usin->sin6_addr;
@@ -311,10 +311,11 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
311 311
312 if (likely(!tp->repair)) { 312 if (likely(!tp->repair)) {
313 if (!tp->write_seq) 313 if (!tp->write_seq)
314 tp->write_seq = secure_tcpv6_seq(np->saddr.s6_addr32, 314 WRITE_ONCE(tp->write_seq,
315 sk->sk_v6_daddr.s6_addr32, 315 secure_tcpv6_seq(np->saddr.s6_addr32,
316 inet->inet_sport, 316 sk->sk_v6_daddr.s6_addr32,
317 inet->inet_dport); 317 inet->inet_sport,
318 inet->inet_dport));
318 tp->tsoffset = secure_tcpv6_ts_off(sock_net(sk), 319 tp->tsoffset = secure_tcpv6_ts_off(sock_net(sk),
319 np->saddr.s6_addr32, 320 np->saddr.s6_addr32,
320 sk->sk_v6_daddr.s6_addr32); 321 sk->sk_v6_daddr.s6_addr32);
@@ -406,7 +407,7 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
406 407
407 tp = tcp_sk(sk); 408 tp = tcp_sk(sk);
408 /* XXX (TFO) - tp->snd_una should be ISN (tcp_create_openreq_child() */ 409 /* XXX (TFO) - tp->snd_una should be ISN (tcp_create_openreq_child() */
409 fastopen = tp->fastopen_rsk; 410 fastopen = rcu_dereference(tp->fastopen_rsk);
410 snd_una = fastopen ? tcp_rsk(fastopen)->snt_isn : tp->snd_una; 411 snd_una = fastopen ? tcp_rsk(fastopen)->snt_isn : tp->snd_una;
411 if (sk->sk_state != TCP_LISTEN && 412 if (sk->sk_state != TCP_LISTEN &&
412 !between(seq, snd_una, tp->snd_nxt)) { 413 !between(seq, snd_una, tp->snd_nxt)) {
@@ -1895,7 +1896,8 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
1895 /* Because we don't lock the socket, 1896 /* Because we don't lock the socket,
1896 * we might find a transient negative value. 1897 * we might find a transient negative value.
1897 */ 1898 */
1898 rx_queue = max_t(int, tp->rcv_nxt - tp->copied_seq, 0); 1899 rx_queue = max_t(int, READ_ONCE(tp->rcv_nxt) -
1900 READ_ONCE(tp->copied_seq), 0);
1899 1901
1900 seq_printf(seq, 1902 seq_printf(seq,
1901 "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " 1903 "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X "
@@ -1906,7 +1908,7 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
1906 dest->s6_addr32[0], dest->s6_addr32[1], 1908 dest->s6_addr32[0], dest->s6_addr32[1],
1907 dest->s6_addr32[2], dest->s6_addr32[3], destp, 1909 dest->s6_addr32[2], dest->s6_addr32[3], destp,
1908 state, 1910 state,
1909 tp->write_seq - tp->snd_una, 1911 READ_ONCE(tp->write_seq) - tp->snd_una,
1910 rx_queue, 1912 rx_queue,
1911 timer_active, 1913 timer_active,
1912 jiffies_delta_to_clock_t(timer_expires - jiffies), 1914 jiffies_delta_to_clock_t(timer_expires - jiffies),
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index aae4938f3dea..9fec580c968e 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -135,7 +135,7 @@ static int compute_score(struct sock *sk, struct net *net,
135 return -1; 135 return -1;
136 score++; 136 score++;
137 137
138 if (sk->sk_incoming_cpu == raw_smp_processor_id()) 138 if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id())
139 score++; 139 score++;
140 140
141 return score; 141 return score;
@@ -1109,6 +1109,7 @@ static int udp_v6_send_skb(struct sk_buff *skb, struct flowi6 *fl6,
1109 __wsum csum = 0; 1109 __wsum csum = 0;
1110 int offset = skb_transport_offset(skb); 1110 int offset = skb_transport_offset(skb);
1111 int len = skb->len - offset; 1111 int len = skb->len - offset;
1112 int datalen = len - sizeof(*uh);
1112 1113
1113 /* 1114 /*
1114 * Create a UDP header 1115 * Create a UDP header
@@ -1141,8 +1142,12 @@ static int udp_v6_send_skb(struct sk_buff *skb, struct flowi6 *fl6,
1141 return -EIO; 1142 return -EIO;
1142 } 1143 }
1143 1144
1144 skb_shinfo(skb)->gso_size = cork->gso_size; 1145 if (datalen > cork->gso_size) {
1145 skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4; 1146 skb_shinfo(skb)->gso_size = cork->gso_size;
1147 skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
1148 skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(datalen,
1149 cork->gso_size);
1150 }
1146 goto csum_partial; 1151 goto csum_partial;
1147 } 1152 }
1148 1153
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
index 105e5a7092e7..f82ea12bac37 100644
--- a/net/l2tp/l2tp_core.c
+++ b/net/l2tp/l2tp_core.c
@@ -1078,7 +1078,7 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len
1078 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); 1078 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
1079 IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED | 1079 IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED |
1080 IPSKB_REROUTED); 1080 IPSKB_REROUTED);
1081 nf_reset(skb); 1081 nf_reset_ct(skb);
1082 1082
1083 bh_lock_sock(sk); 1083 bh_lock_sock(sk);
1084 if (sock_owned_by_user(sk)) { 1084 if (sock_owned_by_user(sk)) {
diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
index bd3f39349d40..d3b520b9b2c9 100644
--- a/net/l2tp/l2tp_eth.c
+++ b/net/l2tp/l2tp_eth.c
@@ -56,7 +56,6 @@ static int l2tp_eth_dev_init(struct net_device *dev)
56{ 56{
57 eth_hw_addr_random(dev); 57 eth_hw_addr_random(dev);
58 eth_broadcast_addr(dev->broadcast); 58 eth_broadcast_addr(dev->broadcast);
59 netdev_lockdep_set_classes(dev);
60 59
61 return 0; 60 return 0;
62} 61}
@@ -151,7 +150,7 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
151 skb->ip_summed = CHECKSUM_NONE; 150 skb->ip_summed = CHECKSUM_NONE;
152 151
153 skb_dst_drop(skb); 152 skb_dst_drop(skb);
154 nf_reset(skb); 153 nf_reset_ct(skb);
155 154
156 rcu_read_lock(); 155 rcu_read_lock();
157 dev = rcu_dereference(spriv->dev); 156 dev = rcu_dereference(spriv->dev);
diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
index 622833317dcb..0d7c887a2b75 100644
--- a/net/l2tp/l2tp_ip.c
+++ b/net/l2tp/l2tp_ip.c
@@ -193,7 +193,7 @@ pass_up:
193 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) 193 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
194 goto discard_put; 194 goto discard_put;
195 195
196 nf_reset(skb); 196 nf_reset_ct(skb);
197 197
198 return sk_receive_skb(sk, skb, 1); 198 return sk_receive_skb(sk, skb, 1);
199 199
diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
index 687e23a8b326..802f19aba7e3 100644
--- a/net/l2tp/l2tp_ip6.c
+++ b/net/l2tp/l2tp_ip6.c
@@ -206,7 +206,7 @@ pass_up:
206 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) 206 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
207 goto discard_put; 207 goto discard_put;
208 208
209 nf_reset(skb); 209 nf_reset_ct(skb);
210 210
211 return sk_receive_skb(sk, skb, 1); 211 return sk_receive_skb(sk, skb, 1);
212 212
diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
index 2017b7d780f5..c74f44dfaa22 100644
--- a/net/llc/af_llc.c
+++ b/net/llc/af_llc.c
@@ -113,22 +113,26 @@ static inline u8 llc_ui_header_len(struct sock *sk, struct sockaddr_llc *addr)
113 * 113 *
114 * Send data via reliable llc2 connection. 114 * Send data via reliable llc2 connection.
115 * Returns 0 upon success, non-zero if action did not succeed. 115 * Returns 0 upon success, non-zero if action did not succeed.
116 *
117 * This function always consumes a reference to the skb.
116 */ 118 */
117static int llc_ui_send_data(struct sock* sk, struct sk_buff *skb, int noblock) 119static int llc_ui_send_data(struct sock* sk, struct sk_buff *skb, int noblock)
118{ 120{
119 struct llc_sock* llc = llc_sk(sk); 121 struct llc_sock* llc = llc_sk(sk);
120 int rc = 0;
121 122
122 if (unlikely(llc_data_accept_state(llc->state) || 123 if (unlikely(llc_data_accept_state(llc->state) ||
123 llc->remote_busy_flag || 124 llc->remote_busy_flag ||
124 llc->p_flag)) { 125 llc->p_flag)) {
125 long timeout = sock_sndtimeo(sk, noblock); 126 long timeout = sock_sndtimeo(sk, noblock);
127 int rc;
126 128
127 rc = llc_ui_wait_for_busy_core(sk, timeout); 129 rc = llc_ui_wait_for_busy_core(sk, timeout);
130 if (rc) {
131 kfree_skb(skb);
132 return rc;
133 }
128 } 134 }
129 if (unlikely(!rc)) 135 return llc_build_and_send_pkt(sk, skb);
130 rc = llc_build_and_send_pkt(sk, skb);
131 return rc;
132} 136}
133 137
134static void llc_ui_sk_init(struct socket *sock, struct sock *sk) 138static void llc_ui_sk_init(struct socket *sock, struct sock *sk)
@@ -899,7 +903,7 @@ static int llc_ui_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
899 DECLARE_SOCKADDR(struct sockaddr_llc *, addr, msg->msg_name); 903 DECLARE_SOCKADDR(struct sockaddr_llc *, addr, msg->msg_name);
900 int flags = msg->msg_flags; 904 int flags = msg->msg_flags;
901 int noblock = flags & MSG_DONTWAIT; 905 int noblock = flags & MSG_DONTWAIT;
902 struct sk_buff *skb; 906 struct sk_buff *skb = NULL;
903 size_t size = 0; 907 size_t size = 0;
904 int rc = -EINVAL, copied = 0, hdrlen; 908 int rc = -EINVAL, copied = 0, hdrlen;
905 909
@@ -908,10 +912,10 @@ static int llc_ui_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
908 lock_sock(sk); 912 lock_sock(sk);
909 if (addr) { 913 if (addr) {
910 if (msg->msg_namelen < sizeof(*addr)) 914 if (msg->msg_namelen < sizeof(*addr))
911 goto release; 915 goto out;
912 } else { 916 } else {
913 if (llc_ui_addr_null(&llc->addr)) 917 if (llc_ui_addr_null(&llc->addr))
914 goto release; 918 goto out;
915 addr = &llc->addr; 919 addr = &llc->addr;
916 } 920 }
917 /* must bind connection to sap if user hasn't done it. */ 921 /* must bind connection to sap if user hasn't done it. */
@@ -919,7 +923,7 @@ static int llc_ui_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
919 /* bind to sap with null dev, exclusive. */ 923 /* bind to sap with null dev, exclusive. */
920 rc = llc_ui_autobind(sock, addr); 924 rc = llc_ui_autobind(sock, addr);
921 if (rc) 925 if (rc)
922 goto release; 926 goto out;
923 } 927 }
924 hdrlen = llc->dev->hard_header_len + llc_ui_header_len(sk, addr); 928 hdrlen = llc->dev->hard_header_len + llc_ui_header_len(sk, addr);
925 size = hdrlen + len; 929 size = hdrlen + len;
@@ -928,12 +932,12 @@ static int llc_ui_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
928 copied = size - hdrlen; 932 copied = size - hdrlen;
929 rc = -EINVAL; 933 rc = -EINVAL;
930 if (copied < 0) 934 if (copied < 0)
931 goto release; 935 goto out;
932 release_sock(sk); 936 release_sock(sk);
933 skb = sock_alloc_send_skb(sk, size, noblock, &rc); 937 skb = sock_alloc_send_skb(sk, size, noblock, &rc);
934 lock_sock(sk); 938 lock_sock(sk);
935 if (!skb) 939 if (!skb)
936 goto release; 940 goto out;
937 skb->dev = llc->dev; 941 skb->dev = llc->dev;
938 skb->protocol = llc_proto_type(addr->sllc_arphrd); 942 skb->protocol = llc_proto_type(addr->sllc_arphrd);
939 skb_reserve(skb, hdrlen); 943 skb_reserve(skb, hdrlen);
@@ -943,29 +947,31 @@ static int llc_ui_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
943 if (sk->sk_type == SOCK_DGRAM || addr->sllc_ua) { 947 if (sk->sk_type == SOCK_DGRAM || addr->sllc_ua) {
944 llc_build_and_send_ui_pkt(llc->sap, skb, addr->sllc_mac, 948 llc_build_and_send_ui_pkt(llc->sap, skb, addr->sllc_mac,
945 addr->sllc_sap); 949 addr->sllc_sap);
950 skb = NULL;
946 goto out; 951 goto out;
947 } 952 }
948 if (addr->sllc_test) { 953 if (addr->sllc_test) {
949 llc_build_and_send_test_pkt(llc->sap, skb, addr->sllc_mac, 954 llc_build_and_send_test_pkt(llc->sap, skb, addr->sllc_mac,
950 addr->sllc_sap); 955 addr->sllc_sap);
956 skb = NULL;
951 goto out; 957 goto out;
952 } 958 }
953 if (addr->sllc_xid) { 959 if (addr->sllc_xid) {
954 llc_build_and_send_xid_pkt(llc->sap, skb, addr->sllc_mac, 960 llc_build_and_send_xid_pkt(llc->sap, skb, addr->sllc_mac,
955 addr->sllc_sap); 961 addr->sllc_sap);
962 skb = NULL;
956 goto out; 963 goto out;
957 } 964 }
958 rc = -ENOPROTOOPT; 965 rc = -ENOPROTOOPT;
959 if (!(sk->sk_type == SOCK_STREAM && !addr->sllc_ua)) 966 if (!(sk->sk_type == SOCK_STREAM && !addr->sllc_ua))
960 goto out; 967 goto out;
961 rc = llc_ui_send_data(sk, skb, noblock); 968 rc = llc_ui_send_data(sk, skb, noblock);
969 skb = NULL;
962out: 970out:
963 if (rc) { 971 kfree_skb(skb);
964 kfree_skb(skb); 972 if (rc)
965release:
966 dprintk("%s: failed sending from %02X to %02X: %d\n", 973 dprintk("%s: failed sending from %02X to %02X: %d\n",
967 __func__, llc->laddr.lsap, llc->daddr.lsap, rc); 974 __func__, llc->laddr.lsap, llc->daddr.lsap, rc);
968 }
969 release_sock(sk); 975 release_sock(sk);
970 return rc ? : copied; 976 return rc ? : copied;
971} 977}
diff --git a/net/llc/llc_c_ac.c b/net/llc/llc_c_ac.c
index 4d78375f9872..647c0554d04c 100644
--- a/net/llc/llc_c_ac.c
+++ b/net/llc/llc_c_ac.c
@@ -372,6 +372,7 @@ int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
372 llc_pdu_init_as_i_cmd(skb, 1, llc->vS, llc->vR); 372 llc_pdu_init_as_i_cmd(skb, 1, llc->vS, llc->vR);
373 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); 373 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
374 if (likely(!rc)) { 374 if (likely(!rc)) {
375 skb_get(skb);
375 llc_conn_send_pdu(sk, skb); 376 llc_conn_send_pdu(sk, skb);
376 llc_conn_ac_inc_vs_by_1(sk, skb); 377 llc_conn_ac_inc_vs_by_1(sk, skb);
377 } 378 }
@@ -389,7 +390,8 @@ static int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb)
389 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR); 390 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
390 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); 391 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
391 if (likely(!rc)) { 392 if (likely(!rc)) {
392 rc = llc_conn_send_pdu(sk, skb); 393 skb_get(skb);
394 llc_conn_send_pdu(sk, skb);
393 llc_conn_ac_inc_vs_by_1(sk, skb); 395 llc_conn_ac_inc_vs_by_1(sk, skb);
394 } 396 }
395 return rc; 397 return rc;
@@ -406,6 +408,7 @@ int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
406 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR); 408 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
407 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); 409 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
408 if (likely(!rc)) { 410 if (likely(!rc)) {
411 skb_get(skb);
409 llc_conn_send_pdu(sk, skb); 412 llc_conn_send_pdu(sk, skb);
410 llc_conn_ac_inc_vs_by_1(sk, skb); 413 llc_conn_ac_inc_vs_by_1(sk, skb);
411 } 414 }
@@ -916,7 +919,8 @@ static int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock *sk,
916 llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR); 919 llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR);
917 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); 920 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
918 if (likely(!rc)) { 921 if (likely(!rc)) {
919 rc = llc_conn_send_pdu(sk, skb); 922 skb_get(skb);
923 llc_conn_send_pdu(sk, skb);
920 llc_conn_ac_inc_vs_by_1(sk, skb); 924 llc_conn_ac_inc_vs_by_1(sk, skb);
921 } 925 }
922 return rc; 926 return rc;
diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c
index 4ff89cb7c86f..7b620acaca9e 100644
--- a/net/llc/llc_conn.c
+++ b/net/llc/llc_conn.c
@@ -30,7 +30,7 @@
30#endif 30#endif
31 31
32static int llc_find_offset(int state, int ev_type); 32static int llc_find_offset(int state, int ev_type);
33static int llc_conn_send_pdus(struct sock *sk, struct sk_buff *skb); 33static void llc_conn_send_pdus(struct sock *sk);
34static int llc_conn_service(struct sock *sk, struct sk_buff *skb); 34static int llc_conn_service(struct sock *sk, struct sk_buff *skb);
35static int llc_exec_conn_trans_actions(struct sock *sk, 35static int llc_exec_conn_trans_actions(struct sock *sk,
36 struct llc_conn_state_trans *trans, 36 struct llc_conn_state_trans *trans,
@@ -55,6 +55,8 @@ int sysctl_llc2_busy_timeout = LLC2_BUSY_TIME * HZ;
55 * (executing it's actions and changing state), upper layer will be 55 * (executing it's actions and changing state), upper layer will be
56 * indicated or confirmed, if needed. Returns 0 for success, 1 for 56 * indicated or confirmed, if needed. Returns 0 for success, 1 for
57 * failure. The socket lock has to be held before calling this function. 57 * failure. The socket lock has to be held before calling this function.
58 *
59 * This function always consumes a reference to the skb.
58 */ 60 */
59int llc_conn_state_process(struct sock *sk, struct sk_buff *skb) 61int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
60{ 62{
@@ -62,12 +64,6 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
62 struct llc_sock *llc = llc_sk(skb->sk); 64 struct llc_sock *llc = llc_sk(skb->sk);
63 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 65 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
64 66
65 /*
66 * We have to hold the skb, because llc_conn_service will kfree it in
67 * the sending path and we need to look at the skb->cb, where we encode
68 * llc_conn_state_ev.
69 */
70 skb_get(skb);
71 ev->ind_prim = ev->cfm_prim = 0; 67 ev->ind_prim = ev->cfm_prim = 0;
72 /* 68 /*
73 * Send event to state machine 69 * Send event to state machine
@@ -75,21 +71,12 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
75 rc = llc_conn_service(skb->sk, skb); 71 rc = llc_conn_service(skb->sk, skb);
76 if (unlikely(rc != 0)) { 72 if (unlikely(rc != 0)) {
77 printk(KERN_ERR "%s: llc_conn_service failed\n", __func__); 73 printk(KERN_ERR "%s: llc_conn_service failed\n", __func__);
78 goto out_kfree_skb;
79 }
80
81 if (unlikely(!ev->ind_prim && !ev->cfm_prim)) {
82 /* indicate or confirm not required */
83 if (!skb->next)
84 goto out_kfree_skb;
85 goto out_skb_put; 74 goto out_skb_put;
86 } 75 }
87 76
88 if (unlikely(ev->ind_prim && ev->cfm_prim)) /* Paranoia */
89 skb_get(skb);
90
91 switch (ev->ind_prim) { 77 switch (ev->ind_prim) {
92 case LLC_DATA_PRIM: 78 case LLC_DATA_PRIM:
79 skb_get(skb);
93 llc_save_primitive(sk, skb, LLC_DATA_PRIM); 80 llc_save_primitive(sk, skb, LLC_DATA_PRIM);
94 if (unlikely(sock_queue_rcv_skb(sk, skb))) { 81 if (unlikely(sock_queue_rcv_skb(sk, skb))) {
95 /* 82 /*
@@ -106,6 +93,7 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
106 * skb->sk pointing to the newly created struct sock in 93 * skb->sk pointing to the newly created struct sock in
107 * llc_conn_handler. -acme 94 * llc_conn_handler. -acme
108 */ 95 */
96 skb_get(skb);
109 skb_queue_tail(&sk->sk_receive_queue, skb); 97 skb_queue_tail(&sk->sk_receive_queue, skb);
110 sk->sk_state_change(sk); 98 sk->sk_state_change(sk);
111 break; 99 break;
@@ -121,7 +109,6 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
121 sk->sk_state_change(sk); 109 sk->sk_state_change(sk);
122 } 110 }
123 } 111 }
124 kfree_skb(skb);
125 sock_put(sk); 112 sock_put(sk);
126 break; 113 break;
127 case LLC_RESET_PRIM: 114 case LLC_RESET_PRIM:
@@ -130,14 +117,11 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
130 * RESET is not being notified to upper layers for now 117 * RESET is not being notified to upper layers for now
131 */ 118 */
132 printk(KERN_INFO "%s: received a reset ind!\n", __func__); 119 printk(KERN_INFO "%s: received a reset ind!\n", __func__);
133 kfree_skb(skb);
134 break; 120 break;
135 default: 121 default:
136 if (ev->ind_prim) { 122 if (ev->ind_prim)
137 printk(KERN_INFO "%s: received unknown %d prim!\n", 123 printk(KERN_INFO "%s: received unknown %d prim!\n",
138 __func__, ev->ind_prim); 124 __func__, ev->ind_prim);
139 kfree_skb(skb);
140 }
141 /* No indication */ 125 /* No indication */
142 break; 126 break;
143 } 127 }
@@ -179,25 +163,22 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
179 printk(KERN_INFO "%s: received a reset conf!\n", __func__); 163 printk(KERN_INFO "%s: received a reset conf!\n", __func__);
180 break; 164 break;
181 default: 165 default:
182 if (ev->cfm_prim) { 166 if (ev->cfm_prim)
183 printk(KERN_INFO "%s: received unknown %d prim!\n", 167 printk(KERN_INFO "%s: received unknown %d prim!\n",
184 __func__, ev->cfm_prim); 168 __func__, ev->cfm_prim);
185 break; 169 /* No confirmation */
186 } 170 break;
187 goto out_skb_put; /* No confirmation */
188 } 171 }
189out_kfree_skb:
190 kfree_skb(skb);
191out_skb_put: 172out_skb_put:
192 kfree_skb(skb); 173 kfree_skb(skb);
193 return rc; 174 return rc;
194} 175}
195 176
196int llc_conn_send_pdu(struct sock *sk, struct sk_buff *skb) 177void llc_conn_send_pdu(struct sock *sk, struct sk_buff *skb)
197{ 178{
198 /* queue PDU to send to MAC layer */ 179 /* queue PDU to send to MAC layer */
199 skb_queue_tail(&sk->sk_write_queue, skb); 180 skb_queue_tail(&sk->sk_write_queue, skb);
200 return llc_conn_send_pdus(sk, skb); 181 llc_conn_send_pdus(sk);
201} 182}
202 183
203/** 184/**
@@ -255,7 +236,7 @@ void llc_conn_resend_i_pdu_as_cmd(struct sock *sk, u8 nr, u8 first_p_bit)
255 if (howmany_resend > 0) 236 if (howmany_resend > 0)
256 llc->vS = (llc->vS + 1) % LLC_2_SEQ_NBR_MODULO; 237 llc->vS = (llc->vS + 1) % LLC_2_SEQ_NBR_MODULO;
257 /* any PDUs to re-send are queued up; start sending to MAC */ 238 /* any PDUs to re-send are queued up; start sending to MAC */
258 llc_conn_send_pdus(sk, NULL); 239 llc_conn_send_pdus(sk);
259out:; 240out:;
260} 241}
261 242
@@ -296,7 +277,7 @@ void llc_conn_resend_i_pdu_as_rsp(struct sock *sk, u8 nr, u8 first_f_bit)
296 if (howmany_resend > 0) 277 if (howmany_resend > 0)
297 llc->vS = (llc->vS + 1) % LLC_2_SEQ_NBR_MODULO; 278 llc->vS = (llc->vS + 1) % LLC_2_SEQ_NBR_MODULO;
298 /* any PDUs to re-send are queued up; start sending to MAC */ 279 /* any PDUs to re-send are queued up; start sending to MAC */
299 llc_conn_send_pdus(sk, NULL); 280 llc_conn_send_pdus(sk);
300out:; 281out:;
301} 282}
302 283
@@ -340,16 +321,12 @@ out:
340/** 321/**
341 * llc_conn_send_pdus - Sends queued PDUs 322 * llc_conn_send_pdus - Sends queued PDUs
342 * @sk: active connection 323 * @sk: active connection
343 * @hold_skb: the skb held by caller, or NULL if does not care
344 * 324 *
345 * Sends queued pdus to MAC layer for transmission. When @hold_skb is 325 * Sends queued pdus to MAC layer for transmission.
346 * NULL, always return 0. Otherwise, return 0 if @hold_skb is sent
347 * successfully, or 1 for failure.
348 */ 326 */
349static int llc_conn_send_pdus(struct sock *sk, struct sk_buff *hold_skb) 327static void llc_conn_send_pdus(struct sock *sk)
350{ 328{
351 struct sk_buff *skb; 329 struct sk_buff *skb;
352 int ret = 0;
353 330
354 while ((skb = skb_dequeue(&sk->sk_write_queue)) != NULL) { 331 while ((skb = skb_dequeue(&sk->sk_write_queue)) != NULL) {
355 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 332 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
@@ -361,20 +338,10 @@ static int llc_conn_send_pdus(struct sock *sk, struct sk_buff *hold_skb)
361 skb_queue_tail(&llc_sk(sk)->pdu_unack_q, skb); 338 skb_queue_tail(&llc_sk(sk)->pdu_unack_q, skb);
362 if (!skb2) 339 if (!skb2)
363 break; 340 break;
364 dev_queue_xmit(skb2); 341 skb = skb2;
365 } else {
366 bool is_target = skb == hold_skb;
367 int rc;
368
369 if (is_target)
370 skb_get(skb);
371 rc = dev_queue_xmit(skb);
372 if (is_target)
373 ret = rc;
374 } 342 }
343 dev_queue_xmit(skb);
375 } 344 }
376
377 return ret;
378} 345}
379 346
380/** 347/**
@@ -846,7 +813,7 @@ void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb)
846 else { 813 else {
847 dprintk("%s: adding to backlog...\n", __func__); 814 dprintk("%s: adding to backlog...\n", __func__);
848 llc_set_backlog_type(skb, LLC_PACKET); 815 llc_set_backlog_type(skb, LLC_PACKET);
849 if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) 816 if (sk_add_backlog(sk, skb, READ_ONCE(sk->sk_rcvbuf)))
850 goto drop_unlock; 817 goto drop_unlock;
851 } 818 }
852out: 819out:
diff --git a/net/llc/llc_if.c b/net/llc/llc_if.c
index 8db03c2d5440..ad6547736c21 100644
--- a/net/llc/llc_if.c
+++ b/net/llc/llc_if.c
@@ -38,6 +38,8 @@
38 * closed and -EBUSY when sending data is not permitted in this state or 38 * closed and -EBUSY when sending data is not permitted in this state or
39 * LLC has send an I pdu with p bit set to 1 and is waiting for it's 39 * LLC has send an I pdu with p bit set to 1 and is waiting for it's
40 * response. 40 * response.
41 *
42 * This function always consumes a reference to the skb.
41 */ 43 */
42int llc_build_and_send_pkt(struct sock *sk, struct sk_buff *skb) 44int llc_build_and_send_pkt(struct sock *sk, struct sk_buff *skb)
43{ 45{
@@ -46,20 +48,22 @@ int llc_build_and_send_pkt(struct sock *sk, struct sk_buff *skb)
46 struct llc_sock *llc = llc_sk(sk); 48 struct llc_sock *llc = llc_sk(sk);
47 49
48 if (unlikely(llc->state == LLC_CONN_STATE_ADM)) 50 if (unlikely(llc->state == LLC_CONN_STATE_ADM))
49 goto out; 51 goto out_free;
50 rc = -EBUSY; 52 rc = -EBUSY;
51 if (unlikely(llc_data_accept_state(llc->state) || /* data_conn_refuse */ 53 if (unlikely(llc_data_accept_state(llc->state) || /* data_conn_refuse */
52 llc->p_flag)) { 54 llc->p_flag)) {
53 llc->failed_data_req = 1; 55 llc->failed_data_req = 1;
54 goto out; 56 goto out_free;
55 } 57 }
56 ev = llc_conn_ev(skb); 58 ev = llc_conn_ev(skb);
57 ev->type = LLC_CONN_EV_TYPE_PRIM; 59 ev->type = LLC_CONN_EV_TYPE_PRIM;
58 ev->prim = LLC_DATA_PRIM; 60 ev->prim = LLC_DATA_PRIM;
59 ev->prim_type = LLC_PRIM_TYPE_REQ; 61 ev->prim_type = LLC_PRIM_TYPE_REQ;
60 skb->dev = llc->dev; 62 skb->dev = llc->dev;
61 rc = llc_conn_state_process(sk, skb); 63 return llc_conn_state_process(sk, skb);
62out: 64
65out_free:
66 kfree_skb(skb);
63 return rc; 67 return rc;
64} 68}
65 69
diff --git a/net/llc/llc_s_ac.c b/net/llc/llc_s_ac.c
index a94bd56bcac6..7ae4cc684d3a 100644
--- a/net/llc/llc_s_ac.c
+++ b/net/llc/llc_s_ac.c
@@ -58,8 +58,10 @@ int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb)
58 ev->daddr.lsap, LLC_PDU_CMD); 58 ev->daddr.lsap, LLC_PDU_CMD);
59 llc_pdu_init_as_ui_cmd(skb); 59 llc_pdu_init_as_ui_cmd(skb);
60 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac); 60 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
61 if (likely(!rc)) 61 if (likely(!rc)) {
62 skb_get(skb);
62 rc = dev_queue_xmit(skb); 63 rc = dev_queue_xmit(skb);
64 }
63 return rc; 65 return rc;
64} 66}
65 67
@@ -81,8 +83,10 @@ int llc_sap_action_send_xid_c(struct llc_sap *sap, struct sk_buff *skb)
81 ev->daddr.lsap, LLC_PDU_CMD); 83 ev->daddr.lsap, LLC_PDU_CMD);
82 llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0); 84 llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0);
83 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac); 85 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
84 if (likely(!rc)) 86 if (likely(!rc)) {
87 skb_get(skb);
85 rc = dev_queue_xmit(skb); 88 rc = dev_queue_xmit(skb);
89 }
86 return rc; 90 return rc;
87} 91}
88 92
@@ -135,8 +139,10 @@ int llc_sap_action_send_test_c(struct llc_sap *sap, struct sk_buff *skb)
135 ev->daddr.lsap, LLC_PDU_CMD); 139 ev->daddr.lsap, LLC_PDU_CMD);
136 llc_pdu_init_as_test_cmd(skb); 140 llc_pdu_init_as_test_cmd(skb);
137 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac); 141 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
138 if (likely(!rc)) 142 if (likely(!rc)) {
143 skb_get(skb);
139 rc = dev_queue_xmit(skb); 144 rc = dev_queue_xmit(skb);
145 }
140 return rc; 146 return rc;
141} 147}
142 148
diff --git a/net/llc/llc_sap.c b/net/llc/llc_sap.c
index a7f7b8ff4729..be419062e19a 100644
--- a/net/llc/llc_sap.c
+++ b/net/llc/llc_sap.c
@@ -197,29 +197,22 @@ out:
197 * After executing actions of the event, upper layer will be indicated 197 * After executing actions of the event, upper layer will be indicated
198 * if needed(on receiving an UI frame). sk can be null for the 198 * if needed(on receiving an UI frame). sk can be null for the
199 * datalink_proto case. 199 * datalink_proto case.
200 *
201 * This function always consumes a reference to the skb.
200 */ 202 */
201static void llc_sap_state_process(struct llc_sap *sap, struct sk_buff *skb) 203static void llc_sap_state_process(struct llc_sap *sap, struct sk_buff *skb)
202{ 204{
203 struct llc_sap_state_ev *ev = llc_sap_ev(skb); 205 struct llc_sap_state_ev *ev = llc_sap_ev(skb);
204 206
205 /*
206 * We have to hold the skb, because llc_sap_next_state
207 * will kfree it in the sending path and we need to
208 * look at the skb->cb, where we encode llc_sap_state_ev.
209 */
210 skb_get(skb);
211 ev->ind_cfm_flag = 0; 207 ev->ind_cfm_flag = 0;
212 llc_sap_next_state(sap, skb); 208 llc_sap_next_state(sap, skb);
213 if (ev->ind_cfm_flag == LLC_IND) {
214 if (skb->sk->sk_state == TCP_LISTEN)
215 kfree_skb(skb);
216 else {
217 llc_save_primitive(skb->sk, skb, ev->prim);
218 209
219 /* queue skb to the user. */ 210 if (ev->ind_cfm_flag == LLC_IND && skb->sk->sk_state != TCP_LISTEN) {
220 if (sock_queue_rcv_skb(skb->sk, skb)) 211 llc_save_primitive(skb->sk, skb, ev->prim);
221 kfree_skb(skb); 212
222 } 213 /* queue skb to the user. */
214 if (sock_queue_rcv_skb(skb->sk, skb) == 0)
215 return;
223 } 216 }
224 kfree_skb(skb); 217 kfree_skb(skb);
225} 218}
diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index b1438fd4d876..64b544ae9966 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -487,9 +487,14 @@ static ssize_t ieee80211_if_fmt_aqm(
487 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen) 487 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
488{ 488{
489 struct ieee80211_local *local = sdata->local; 489 struct ieee80211_local *local = sdata->local;
490 struct txq_info *txqi = to_txq_info(sdata->vif.txq); 490 struct txq_info *txqi;
491 int len; 491 int len;
492 492
493 if (!sdata->vif.txq)
494 return 0;
495
496 txqi = to_txq_info(sdata->vif.txq);
497
493 spin_lock_bh(&local->fq.lock); 498 spin_lock_bh(&local->fq.lock);
494 rcu_read_lock(); 499 rcu_read_lock();
495 500
@@ -658,7 +663,9 @@ static void add_common_files(struct ieee80211_sub_if_data *sdata)
658 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz); 663 DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz);
659 DEBUGFS_ADD(hw_queues); 664 DEBUGFS_ADD(hw_queues);
660 665
661 if (sdata->local->ops->wake_tx_queue) 666 if (sdata->local->ops->wake_tx_queue &&
667 sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
668 sdata->vif.type != NL80211_IFTYPE_NAN)
662 DEBUGFS_ADD(aqm); 669 DEBUGFS_ADD(aqm);
663} 670}
664 671
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 26a2f49208b6..54dd8849d1cc 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -2633,7 +2633,8 @@ struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2633 2633
2634 rcu_read_lock(); 2634 rcu_read_lock();
2635 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID); 2635 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
2636 if (WARN_ON_ONCE(ssid == NULL)) 2636 if (WARN_ONCE(!ssid || ssid[1] > IEEE80211_MAX_SSID_LEN,
2637 "invalid SSID element (len=%d)", ssid ? ssid[1] : -1))
2637 ssid_len = 0; 2638 ssid_len = 0;
2638 else 2639 else
2639 ssid_len = ssid[1]; 2640 ssid_len = ssid[1];
@@ -5233,7 +5234,7 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
5233 5234
5234 rcu_read_lock(); 5235 rcu_read_lock();
5235 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); 5236 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
5236 if (!ssidie) { 5237 if (!ssidie || ssidie[1] > sizeof(assoc_data->ssid)) {
5237 rcu_read_unlock(); 5238 rcu_read_unlock();
5238 kfree(assoc_data); 5239 kfree(assoc_data);
5239 return -EINVAL; 5240 return -EINVAL;
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 768d14c9a716..0e05ff037672 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -3467,9 +3467,18 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
3467 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP): 3467 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3468 /* process for all: mesh, mlme, ibss */ 3468 /* process for all: mesh, mlme, ibss */
3469 break; 3469 break;
3470 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3471 if (is_multicast_ether_addr(mgmt->da) &&
3472 !is_broadcast_ether_addr(mgmt->da))
3473 return RX_DROP_MONITOR;
3474
3475 /* process only for station/IBSS */
3476 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3477 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3478 return RX_DROP_MONITOR;
3479 break;
3470 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP): 3480 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3471 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP): 3481 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3472 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3473 case cpu_to_le16(IEEE80211_STYPE_DISASSOC): 3482 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
3474 if (is_multicast_ether_addr(mgmt->da) && 3483 if (is_multicast_ether_addr(mgmt->da) &&
3475 !is_broadcast_ether_addr(mgmt->da)) 3484 !is_broadcast_ether_addr(mgmt->da))
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index adf94ba1ed77..4d31d9688dc2 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -520,10 +520,33 @@ static int ieee80211_start_sw_scan(struct ieee80211_local *local,
520 return 0; 520 return 0;
521} 521}
522 522
523static bool __ieee80211_can_leave_ch(struct ieee80211_sub_if_data *sdata)
524{
525 struct ieee80211_local *local = sdata->local;
526 struct ieee80211_sub_if_data *sdata_iter;
527
528 if (!ieee80211_is_radar_required(local))
529 return true;
530
531 if (!regulatory_pre_cac_allowed(local->hw.wiphy))
532 return false;
533
534 mutex_lock(&local->iflist_mtx);
535 list_for_each_entry(sdata_iter, &local->interfaces, list) {
536 if (sdata_iter->wdev.cac_started) {
537 mutex_unlock(&local->iflist_mtx);
538 return false;
539 }
540 }
541 mutex_unlock(&local->iflist_mtx);
542
543 return true;
544}
545
523static bool ieee80211_can_scan(struct ieee80211_local *local, 546static bool ieee80211_can_scan(struct ieee80211_local *local,
524 struct ieee80211_sub_if_data *sdata) 547 struct ieee80211_sub_if_data *sdata)
525{ 548{
526 if (ieee80211_is_radar_required(local)) 549 if (!__ieee80211_can_leave_ch(sdata))
527 return false; 550 return false;
528 551
529 if (!list_empty(&local->roc_list)) 552 if (!list_empty(&local->roc_list))
@@ -630,7 +653,10 @@ static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
630 653
631 lockdep_assert_held(&local->mtx); 654 lockdep_assert_held(&local->mtx);
632 655
633 if (local->scan_req || ieee80211_is_radar_required(local)) 656 if (local->scan_req)
657 return -EBUSY;
658
659 if (!__ieee80211_can_leave_ch(sdata))
634 return -EBUSY; 660 return -EBUSY;
635 661
636 if (!ieee80211_can_scan(local, sdata)) { 662 if (!ieee80211_can_scan(local, sdata)) {
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 051a02ddcb85..32a7a53833c0 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -247,7 +247,8 @@ static void __ieee80211_wake_txqs(struct ieee80211_sub_if_data *sdata, int ac)
247 struct sta_info *sta; 247 struct sta_info *sta;
248 int i; 248 int i;
249 249
250 spin_lock_bh(&fq->lock); 250 local_bh_disable();
251 spin_lock(&fq->lock);
251 252
252 if (sdata->vif.type == NL80211_IFTYPE_AP) 253 if (sdata->vif.type == NL80211_IFTYPE_AP)
253 ps = &sdata->bss->ps; 254 ps = &sdata->bss->ps;
@@ -273,9 +274,9 @@ static void __ieee80211_wake_txqs(struct ieee80211_sub_if_data *sdata, int ac)
273 &txqi->flags)) 274 &txqi->flags))
274 continue; 275 continue;
275 276
276 spin_unlock_bh(&fq->lock); 277 spin_unlock(&fq->lock);
277 drv_wake_tx_queue(local, txqi); 278 drv_wake_tx_queue(local, txqi);
278 spin_lock_bh(&fq->lock); 279 spin_lock(&fq->lock);
279 } 280 }
280 } 281 }
281 282
@@ -288,12 +289,14 @@ static void __ieee80211_wake_txqs(struct ieee80211_sub_if_data *sdata, int ac)
288 (ps && atomic_read(&ps->num_sta_ps)) || ac != vif->txq->ac) 289 (ps && atomic_read(&ps->num_sta_ps)) || ac != vif->txq->ac)
289 goto out; 290 goto out;
290 291
291 spin_unlock_bh(&fq->lock); 292 spin_unlock(&fq->lock);
292 293
293 drv_wake_tx_queue(local, txqi); 294 drv_wake_tx_queue(local, txqi);
295 local_bh_enable();
294 return; 296 return;
295out: 297out:
296 spin_unlock_bh(&fq->lock); 298 spin_unlock(&fq->lock);
299 local_bh_enable();
297} 300}
298 301
299static void 302static void
diff --git a/net/netfilter/ipvs/ip_vs_app.c b/net/netfilter/ipvs/ip_vs_app.c
index 4515056ef1c2..f9b16f2b2219 100644
--- a/net/netfilter/ipvs/ip_vs_app.c
+++ b/net/netfilter/ipvs/ip_vs_app.c
@@ -193,21 +193,29 @@ struct ip_vs_app *register_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *
193 193
194 mutex_lock(&__ip_vs_app_mutex); 194 mutex_lock(&__ip_vs_app_mutex);
195 195
196 /* increase the module use count */
197 if (!ip_vs_use_count_inc()) {
198 err = -ENOENT;
199 goto out_unlock;
200 }
201
196 list_for_each_entry(a, &ipvs->app_list, a_list) { 202 list_for_each_entry(a, &ipvs->app_list, a_list) {
197 if (!strcmp(app->name, a->name)) { 203 if (!strcmp(app->name, a->name)) {
198 err = -EEXIST; 204 err = -EEXIST;
205 /* decrease the module use count */
206 ip_vs_use_count_dec();
199 goto out_unlock; 207 goto out_unlock;
200 } 208 }
201 } 209 }
202 a = kmemdup(app, sizeof(*app), GFP_KERNEL); 210 a = kmemdup(app, sizeof(*app), GFP_KERNEL);
203 if (!a) { 211 if (!a) {
204 err = -ENOMEM; 212 err = -ENOMEM;
213 /* decrease the module use count */
214 ip_vs_use_count_dec();
205 goto out_unlock; 215 goto out_unlock;
206 } 216 }
207 INIT_LIST_HEAD(&a->incs_list); 217 INIT_LIST_HEAD(&a->incs_list);
208 list_add(&a->a_list, &ipvs->app_list); 218 list_add(&a->a_list, &ipvs->app_list);
209 /* increase the module use count */
210 ip_vs_use_count_inc();
211 219
212out_unlock: 220out_unlock:
213 mutex_unlock(&__ip_vs_app_mutex); 221 mutex_unlock(&__ip_vs_app_mutex);
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index 8b48e7ce1c2c..3cccc88ef817 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -93,7 +93,6 @@ static bool __ip_vs_addr_is_local_v6(struct net *net,
93static void update_defense_level(struct netns_ipvs *ipvs) 93static void update_defense_level(struct netns_ipvs *ipvs)
94{ 94{
95 struct sysinfo i; 95 struct sysinfo i;
96 static int old_secure_tcp = 0;
97 int availmem; 96 int availmem;
98 int nomem; 97 int nomem;
99 int to_change = -1; 98 int to_change = -1;
@@ -174,35 +173,35 @@ static void update_defense_level(struct netns_ipvs *ipvs)
174 spin_lock(&ipvs->securetcp_lock); 173 spin_lock(&ipvs->securetcp_lock);
175 switch (ipvs->sysctl_secure_tcp) { 174 switch (ipvs->sysctl_secure_tcp) {
176 case 0: 175 case 0:
177 if (old_secure_tcp >= 2) 176 if (ipvs->old_secure_tcp >= 2)
178 to_change = 0; 177 to_change = 0;
179 break; 178 break;
180 case 1: 179 case 1:
181 if (nomem) { 180 if (nomem) {
182 if (old_secure_tcp < 2) 181 if (ipvs->old_secure_tcp < 2)
183 to_change = 1; 182 to_change = 1;
184 ipvs->sysctl_secure_tcp = 2; 183 ipvs->sysctl_secure_tcp = 2;
185 } else { 184 } else {
186 if (old_secure_tcp >= 2) 185 if (ipvs->old_secure_tcp >= 2)
187 to_change = 0; 186 to_change = 0;
188 } 187 }
189 break; 188 break;
190 case 2: 189 case 2:
191 if (nomem) { 190 if (nomem) {
192 if (old_secure_tcp < 2) 191 if (ipvs->old_secure_tcp < 2)
193 to_change = 1; 192 to_change = 1;
194 } else { 193 } else {
195 if (old_secure_tcp >= 2) 194 if (ipvs->old_secure_tcp >= 2)
196 to_change = 0; 195 to_change = 0;
197 ipvs->sysctl_secure_tcp = 1; 196 ipvs->sysctl_secure_tcp = 1;
198 } 197 }
199 break; 198 break;
200 case 3: 199 case 3:
201 if (old_secure_tcp < 2) 200 if (ipvs->old_secure_tcp < 2)
202 to_change = 1; 201 to_change = 1;
203 break; 202 break;
204 } 203 }
205 old_secure_tcp = ipvs->sysctl_secure_tcp; 204 ipvs->old_secure_tcp = ipvs->sysctl_secure_tcp;
206 if (to_change >= 0) 205 if (to_change >= 0)
207 ip_vs_protocol_timeout_change(ipvs, 206 ip_vs_protocol_timeout_change(ipvs,
208 ipvs->sysctl_secure_tcp > 1); 207 ipvs->sysctl_secure_tcp > 1);
@@ -1275,7 +1274,8 @@ ip_vs_add_service(struct netns_ipvs *ipvs, struct ip_vs_service_user_kern *u,
1275 struct ip_vs_service *svc = NULL; 1274 struct ip_vs_service *svc = NULL;
1276 1275
1277 /* increase the module use count */ 1276 /* increase the module use count */
1278 ip_vs_use_count_inc(); 1277 if (!ip_vs_use_count_inc())
1278 return -ENOPROTOOPT;
1279 1279
1280 /* Lookup the scheduler by 'u->sched_name' */ 1280 /* Lookup the scheduler by 'u->sched_name' */
1281 if (strcmp(u->sched_name, "none")) { 1281 if (strcmp(u->sched_name, "none")) {
@@ -2435,9 +2435,6 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
2435 if (copy_from_user(arg, user, len) != 0) 2435 if (copy_from_user(arg, user, len) != 0)
2436 return -EFAULT; 2436 return -EFAULT;
2437 2437
2438 /* increase the module use count */
2439 ip_vs_use_count_inc();
2440
2441 /* Handle daemons since they have another lock */ 2438 /* Handle daemons since they have another lock */
2442 if (cmd == IP_VS_SO_SET_STARTDAEMON || 2439 if (cmd == IP_VS_SO_SET_STARTDAEMON ||
2443 cmd == IP_VS_SO_SET_STOPDAEMON) { 2440 cmd == IP_VS_SO_SET_STOPDAEMON) {
@@ -2450,13 +2447,13 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
2450 ret = -EINVAL; 2447 ret = -EINVAL;
2451 if (strscpy(cfg.mcast_ifn, dm->mcast_ifn, 2448 if (strscpy(cfg.mcast_ifn, dm->mcast_ifn,
2452 sizeof(cfg.mcast_ifn)) <= 0) 2449 sizeof(cfg.mcast_ifn)) <= 0)
2453 goto out_dec; 2450 return ret;
2454 cfg.syncid = dm->syncid; 2451 cfg.syncid = dm->syncid;
2455 ret = start_sync_thread(ipvs, &cfg, dm->state); 2452 ret = start_sync_thread(ipvs, &cfg, dm->state);
2456 } else { 2453 } else {
2457 ret = stop_sync_thread(ipvs, dm->state); 2454 ret = stop_sync_thread(ipvs, dm->state);
2458 } 2455 }
2459 goto out_dec; 2456 return ret;
2460 } 2457 }
2461 2458
2462 mutex_lock(&__ip_vs_mutex); 2459 mutex_lock(&__ip_vs_mutex);
@@ -2551,10 +2548,6 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
2551 2548
2552 out_unlock: 2549 out_unlock:
2553 mutex_unlock(&__ip_vs_mutex); 2550 mutex_unlock(&__ip_vs_mutex);
2554 out_dec:
2555 /* decrease the module use count */
2556 ip_vs_use_count_dec();
2557
2558 return ret; 2551 return ret;
2559} 2552}
2560 2553
diff --git a/net/netfilter/ipvs/ip_vs_pe.c b/net/netfilter/ipvs/ip_vs_pe.c
index 8e104dff7abc..166c669f0763 100644
--- a/net/netfilter/ipvs/ip_vs_pe.c
+++ b/net/netfilter/ipvs/ip_vs_pe.c
@@ -68,7 +68,8 @@ int register_ip_vs_pe(struct ip_vs_pe *pe)
68 struct ip_vs_pe *tmp; 68 struct ip_vs_pe *tmp;
69 69
70 /* increase the module use count */ 70 /* increase the module use count */
71 ip_vs_use_count_inc(); 71 if (!ip_vs_use_count_inc())
72 return -ENOENT;
72 73
73 mutex_lock(&ip_vs_pe_mutex); 74 mutex_lock(&ip_vs_pe_mutex);
74 /* Make sure that the pe with this name doesn't exist 75 /* Make sure that the pe with this name doesn't exist
diff --git a/net/netfilter/ipvs/ip_vs_sched.c b/net/netfilter/ipvs/ip_vs_sched.c
index 2f9d5cd5daee..d4903723be7e 100644
--- a/net/netfilter/ipvs/ip_vs_sched.c
+++ b/net/netfilter/ipvs/ip_vs_sched.c
@@ -179,7 +179,8 @@ int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler)
179 } 179 }
180 180
181 /* increase the module use count */ 181 /* increase the module use count */
182 ip_vs_use_count_inc(); 182 if (!ip_vs_use_count_inc())
183 return -ENOENT;
183 184
184 mutex_lock(&ip_vs_sched_mutex); 185 mutex_lock(&ip_vs_sched_mutex);
185 186
diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
index a4a78c4b06de..8dc892a9dc91 100644
--- a/net/netfilter/ipvs/ip_vs_sync.c
+++ b/net/netfilter/ipvs/ip_vs_sync.c
@@ -1762,6 +1762,10 @@ int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *c,
1762 IP_VS_DBG(7, "Each ip_vs_sync_conn entry needs %zd bytes\n", 1762 IP_VS_DBG(7, "Each ip_vs_sync_conn entry needs %zd bytes\n",
1763 sizeof(struct ip_vs_sync_conn_v0)); 1763 sizeof(struct ip_vs_sync_conn_v0));
1764 1764
1765 /* increase the module use count */
1766 if (!ip_vs_use_count_inc())
1767 return -ENOPROTOOPT;
1768
1765 /* Do not hold one mutex and then to block on another */ 1769 /* Do not hold one mutex and then to block on another */
1766 for (;;) { 1770 for (;;) {
1767 rtnl_lock(); 1771 rtnl_lock();
@@ -1892,9 +1896,6 @@ int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *c,
1892 mutex_unlock(&ipvs->sync_mutex); 1896 mutex_unlock(&ipvs->sync_mutex);
1893 rtnl_unlock(); 1897 rtnl_unlock();
1894 1898
1895 /* increase the module use count */
1896 ip_vs_use_count_inc();
1897
1898 return 0; 1899 return 0;
1899 1900
1900out: 1901out:
@@ -1924,11 +1925,17 @@ out:
1924 } 1925 }
1925 kfree(ti); 1926 kfree(ti);
1926 } 1927 }
1928
1929 /* decrease the module use count */
1930 ip_vs_use_count_dec();
1927 return result; 1931 return result;
1928 1932
1929out_early: 1933out_early:
1930 mutex_unlock(&ipvs->sync_mutex); 1934 mutex_unlock(&ipvs->sync_mutex);
1931 rtnl_unlock(); 1935 rtnl_unlock();
1936
1937 /* decrease the module use count */
1938 ip_vs_use_count_dec();
1932 return result; 1939 return result;
1933} 1940}
1934 1941
diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
index 9c464d24beec..888d3068a492 100644
--- a/net/netfilter/ipvs/ip_vs_xmit.c
+++ b/net/netfilter/ipvs/ip_vs_xmit.c
@@ -613,7 +613,7 @@ static inline int ip_vs_tunnel_xmit_prepare(struct sk_buff *skb,
613 if (unlikely(cp->flags & IP_VS_CONN_F_NFCT)) 613 if (unlikely(cp->flags & IP_VS_CONN_F_NFCT))
614 ret = ip_vs_confirm_conntrack(skb); 614 ret = ip_vs_confirm_conntrack(skb);
615 if (ret == NF_ACCEPT) { 615 if (ret == NF_ACCEPT) {
616 nf_reset(skb); 616 nf_reset_ct(skb);
617 skb_forward_csum(skb); 617 skb_forward_csum(skb);
618 } 618 }
619 return ret; 619 return ret;
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 0c63120b2db2..5cd610b547e0 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -1792,8 +1792,8 @@ void __nf_ct_refresh_acct(struct nf_conn *ct,
1792 if (nf_ct_is_confirmed(ct)) 1792 if (nf_ct_is_confirmed(ct))
1793 extra_jiffies += nfct_time_stamp; 1793 extra_jiffies += nfct_time_stamp;
1794 1794
1795 if (ct->timeout != extra_jiffies) 1795 if (READ_ONCE(ct->timeout) != extra_jiffies)
1796 ct->timeout = extra_jiffies; 1796 WRITE_ONCE(ct->timeout, extra_jiffies);
1797acct: 1797acct:
1798 if (do_acct) 1798 if (do_acct)
1799 nf_ct_acct_update(ct, ctinfo, skb->len); 1799 nf_ct_acct_update(ct, ctinfo, skb->len);
diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index 132f5228b431..128245efe84a 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -202,6 +202,8 @@ int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow)
202{ 202{
203 int err; 203 int err;
204 204
205 flow->timeout = (u32)jiffies + NF_FLOW_TIMEOUT;
206
205 err = rhashtable_insert_fast(&flow_table->rhashtable, 207 err = rhashtable_insert_fast(&flow_table->rhashtable,
206 &flow->tuplehash[0].node, 208 &flow->tuplehash[0].node,
207 nf_flow_offload_rhash_params); 209 nf_flow_offload_rhash_params);
@@ -218,7 +220,6 @@ int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow)
218 return err; 220 return err;
219 } 221 }
220 222
221 flow->timeout = (u32)jiffies + NF_FLOW_TIMEOUT;
222 return 0; 223 return 0;
223} 224}
224EXPORT_SYMBOL_GPL(flow_offload_add); 225EXPORT_SYMBOL_GPL(flow_offload_add);
diff --git a/net/netfilter/nf_tables_offload.c b/net/netfilter/nf_tables_offload.c
index e546f759b7a7..ad783f4840ef 100644
--- a/net/netfilter/nf_tables_offload.c
+++ b/net/netfilter/nf_tables_offload.c
@@ -347,7 +347,7 @@ int nft_flow_rule_offload_commit(struct net *net)
347 347
348 policy = nft_trans_chain_policy(trans); 348 policy = nft_trans_chain_policy(trans);
349 err = nft_flow_offload_chain(trans->ctx.chain, &policy, 349 err = nft_flow_offload_chain(trans->ctx.chain, &policy,
350 FLOW_BLOCK_BIND); 350 FLOW_BLOCK_UNBIND);
351 break; 351 break;
352 case NFT_MSG_NEWRULE: 352 case NFT_MSG_NEWRULE:
353 if (!(trans->ctx.chain->flags & NFT_CHAIN_HW_OFFLOAD)) 353 if (!(trans->ctx.chain->flags & NFT_CHAIN_HW_OFFLOAD))
diff --git a/net/netfilter/nft_connlimit.c b/net/netfilter/nft_connlimit.c
index af1497ab9464..69d6173f91e2 100644
--- a/net/netfilter/nft_connlimit.c
+++ b/net/netfilter/nft_connlimit.c
@@ -218,8 +218,13 @@ static void nft_connlimit_destroy_clone(const struct nft_ctx *ctx,
218static bool nft_connlimit_gc(struct net *net, const struct nft_expr *expr) 218static bool nft_connlimit_gc(struct net *net, const struct nft_expr *expr)
219{ 219{
220 struct nft_connlimit *priv = nft_expr_priv(expr); 220 struct nft_connlimit *priv = nft_expr_priv(expr);
221 bool ret;
221 222
222 return nf_conncount_gc_list(net, &priv->list); 223 local_bh_disable();
224 ret = nf_conncount_gc_list(net, &priv->list);
225 local_bh_enable();
226
227 return ret;
223} 228}
224 229
225static struct nft_expr_type nft_connlimit_type; 230static struct nft_expr_type nft_connlimit_type;
diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
index 22a80eb60222..5cb2d8908d2a 100644
--- a/net/netfilter/nft_payload.c
+++ b/net/netfilter/nft_payload.c
@@ -161,13 +161,21 @@ static int nft_payload_offload_ll(struct nft_offload_ctx *ctx,
161 161
162 switch (priv->offset) { 162 switch (priv->offset) {
163 case offsetof(struct ethhdr, h_source): 163 case offsetof(struct ethhdr, h_source):
164 if (priv->len != ETH_ALEN)
165 return -EOPNOTSUPP;
166
164 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_ETH_ADDRS, eth_addrs, 167 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_ETH_ADDRS, eth_addrs,
165 src, ETH_ALEN, reg); 168 src, ETH_ALEN, reg);
166 break; 169 break;
167 case offsetof(struct ethhdr, h_dest): 170 case offsetof(struct ethhdr, h_dest):
171 if (priv->len != ETH_ALEN)
172 return -EOPNOTSUPP;
173
168 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_ETH_ADDRS, eth_addrs, 174 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_ETH_ADDRS, eth_addrs,
169 dst, ETH_ALEN, reg); 175 dst, ETH_ALEN, reg);
170 break; 176 break;
177 default:
178 return -EOPNOTSUPP;
171 } 179 }
172 180
173 return 0; 181 return 0;
@@ -181,14 +189,23 @@ static int nft_payload_offload_ip(struct nft_offload_ctx *ctx,
181 189
182 switch (priv->offset) { 190 switch (priv->offset) {
183 case offsetof(struct iphdr, saddr): 191 case offsetof(struct iphdr, saddr):
192 if (priv->len != sizeof(struct in_addr))
193 return -EOPNOTSUPP;
194
184 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_IPV4_ADDRS, ipv4, src, 195 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_IPV4_ADDRS, ipv4, src,
185 sizeof(struct in_addr), reg); 196 sizeof(struct in_addr), reg);
186 break; 197 break;
187 case offsetof(struct iphdr, daddr): 198 case offsetof(struct iphdr, daddr):
199 if (priv->len != sizeof(struct in_addr))
200 return -EOPNOTSUPP;
201
188 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_IPV4_ADDRS, ipv4, dst, 202 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_IPV4_ADDRS, ipv4, dst,
189 sizeof(struct in_addr), reg); 203 sizeof(struct in_addr), reg);
190 break; 204 break;
191 case offsetof(struct iphdr, protocol): 205 case offsetof(struct iphdr, protocol):
206 if (priv->len != sizeof(__u8))
207 return -EOPNOTSUPP;
208
192 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_BASIC, basic, ip_proto, 209 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_BASIC, basic, ip_proto,
193 sizeof(__u8), reg); 210 sizeof(__u8), reg);
194 nft_offload_set_dependency(ctx, NFT_OFFLOAD_DEP_TRANSPORT); 211 nft_offload_set_dependency(ctx, NFT_OFFLOAD_DEP_TRANSPORT);
@@ -208,14 +225,23 @@ static int nft_payload_offload_ip6(struct nft_offload_ctx *ctx,
208 225
209 switch (priv->offset) { 226 switch (priv->offset) {
210 case offsetof(struct ipv6hdr, saddr): 227 case offsetof(struct ipv6hdr, saddr):
228 if (priv->len != sizeof(struct in6_addr))
229 return -EOPNOTSUPP;
230
211 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_IPV6_ADDRS, ipv6, src, 231 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_IPV6_ADDRS, ipv6, src,
212 sizeof(struct in6_addr), reg); 232 sizeof(struct in6_addr), reg);
213 break; 233 break;
214 case offsetof(struct ipv6hdr, daddr): 234 case offsetof(struct ipv6hdr, daddr):
235 if (priv->len != sizeof(struct in6_addr))
236 return -EOPNOTSUPP;
237
215 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_IPV6_ADDRS, ipv6, dst, 238 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_IPV6_ADDRS, ipv6, dst,
216 sizeof(struct in6_addr), reg); 239 sizeof(struct in6_addr), reg);
217 break; 240 break;
218 case offsetof(struct ipv6hdr, nexthdr): 241 case offsetof(struct ipv6hdr, nexthdr):
242 if (priv->len != sizeof(__u8))
243 return -EOPNOTSUPP;
244
219 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_BASIC, basic, ip_proto, 245 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_BASIC, basic, ip_proto,
220 sizeof(__u8), reg); 246 sizeof(__u8), reg);
221 nft_offload_set_dependency(ctx, NFT_OFFLOAD_DEP_TRANSPORT); 247 nft_offload_set_dependency(ctx, NFT_OFFLOAD_DEP_TRANSPORT);
@@ -255,10 +281,16 @@ static int nft_payload_offload_tcp(struct nft_offload_ctx *ctx,
255 281
256 switch (priv->offset) { 282 switch (priv->offset) {
257 case offsetof(struct tcphdr, source): 283 case offsetof(struct tcphdr, source):
284 if (priv->len != sizeof(__be16))
285 return -EOPNOTSUPP;
286
258 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_PORTS, tp, src, 287 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_PORTS, tp, src,
259 sizeof(__be16), reg); 288 sizeof(__be16), reg);
260 break; 289 break;
261 case offsetof(struct tcphdr, dest): 290 case offsetof(struct tcphdr, dest):
291 if (priv->len != sizeof(__be16))
292 return -EOPNOTSUPP;
293
262 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_PORTS, tp, dst, 294 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_PORTS, tp, dst,
263 sizeof(__be16), reg); 295 sizeof(__be16), reg);
264 break; 296 break;
@@ -277,10 +309,16 @@ static int nft_payload_offload_udp(struct nft_offload_ctx *ctx,
277 309
278 switch (priv->offset) { 310 switch (priv->offset) {
279 case offsetof(struct udphdr, source): 311 case offsetof(struct udphdr, source):
312 if (priv->len != sizeof(__be16))
313 return -EOPNOTSUPP;
314
280 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_PORTS, tp, src, 315 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_PORTS, tp, src,
281 sizeof(__be16), reg); 316 sizeof(__be16), reg);
282 break; 317 break;
283 case offsetof(struct udphdr, dest): 318 case offsetof(struct udphdr, dest):
319 if (priv->len != sizeof(__be16))
320 return -EOPNOTSUPP;
321
284 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_PORTS, tp, dst, 322 NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_PORTS, tp, dst,
285 sizeof(__be16), reg); 323 sizeof(__be16), reg);
286 break; 324 break;
diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
index c4f54ad2b98a..58d5373c513c 100644
--- a/net/netrom/af_netrom.c
+++ b/net/netrom/af_netrom.c
@@ -64,28 +64,6 @@ static DEFINE_SPINLOCK(nr_list_lock);
64static const struct proto_ops nr_proto_ops; 64static const struct proto_ops nr_proto_ops;
65 65
66/* 66/*
67 * NETROM network devices are virtual network devices encapsulating NETROM
68 * frames into AX.25 which will be sent through an AX.25 device, so form a
69 * special "super class" of normal net devices; split their locks off into a
70 * separate class since they always nest.
71 */
72static struct lock_class_key nr_netdev_xmit_lock_key;
73static struct lock_class_key nr_netdev_addr_lock_key;
74
75static void nr_set_lockdep_one(struct net_device *dev,
76 struct netdev_queue *txq,
77 void *_unused)
78{
79 lockdep_set_class(&txq->_xmit_lock, &nr_netdev_xmit_lock_key);
80}
81
82static void nr_set_lockdep_key(struct net_device *dev)
83{
84 lockdep_set_class(&dev->addr_list_lock, &nr_netdev_addr_lock_key);
85 netdev_for_each_tx_queue(dev, nr_set_lockdep_one, NULL);
86}
87
88/*
89 * Socket removal during an interrupt is now safe. 67 * Socket removal during an interrupt is now safe.
90 */ 68 */
91static void nr_remove_socket(struct sock *sk) 69static void nr_remove_socket(struct sock *sk)
@@ -1414,7 +1392,6 @@ static int __init nr_proto_init(void)
1414 free_netdev(dev); 1392 free_netdev(dev);
1415 goto fail; 1393 goto fail;
1416 } 1394 }
1417 nr_set_lockdep_key(dev);
1418 dev_nr[i] = dev; 1395 dev_nr[i] = dev;
1419 } 1396 }
1420 1397
diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c
index 8dfea26536c9..28604414dec1 100644
--- a/net/nfc/llcp_sock.c
+++ b/net/nfc/llcp_sock.c
@@ -107,9 +107,14 @@ static int llcp_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
107 llcp_sock->service_name = kmemdup(llcp_addr.service_name, 107 llcp_sock->service_name = kmemdup(llcp_addr.service_name,
108 llcp_sock->service_name_len, 108 llcp_sock->service_name_len,
109 GFP_KERNEL); 109 GFP_KERNEL);
110 110 if (!llcp_sock->service_name) {
111 ret = -ENOMEM;
112 goto put_dev;
113 }
111 llcp_sock->ssap = nfc_llcp_get_sdp_ssap(local, llcp_sock); 114 llcp_sock->ssap = nfc_llcp_get_sdp_ssap(local, llcp_sock);
112 if (llcp_sock->ssap == LLCP_SAP_MAX) { 115 if (llcp_sock->ssap == LLCP_SAP_MAX) {
116 kfree(llcp_sock->service_name);
117 llcp_sock->service_name = NULL;
113 ret = -EADDRINUSE; 118 ret = -EADDRINUSE;
114 goto put_dev; 119 goto put_dev;
115 } 120 }
@@ -549,11 +554,11 @@ static __poll_t llcp_sock_poll(struct file *file, struct socket *sock,
549 if (sk->sk_state == LLCP_LISTEN) 554 if (sk->sk_state == LLCP_LISTEN)
550 return llcp_accept_poll(sk); 555 return llcp_accept_poll(sk);
551 556
552 if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) 557 if (sk->sk_err || !skb_queue_empty_lockless(&sk->sk_error_queue))
553 mask |= EPOLLERR | 558 mask |= EPOLLERR |
554 (sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0); 559 (sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0);
555 560
556 if (!skb_queue_empty(&sk->sk_receive_queue)) 561 if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
557 mask |= EPOLLIN | EPOLLRDNORM; 562 mask |= EPOLLIN | EPOLLRDNORM;
558 563
559 if (sk->sk_state == LLCP_CLOSED) 564 if (sk->sk_state == LLCP_CLOSED)
diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
index 3572e11b6f21..1c77f520f474 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -165,7 +165,8 @@ static int push_mpls(struct sk_buff *skb, struct sw_flow_key *key,
165{ 165{
166 int err; 166 int err;
167 167
168 err = skb_mpls_push(skb, mpls->mpls_lse, mpls->mpls_ethertype); 168 err = skb_mpls_push(skb, mpls->mpls_lse, mpls->mpls_ethertype,
169 skb->mac_len);
169 if (err) 170 if (err)
170 return err; 171 return err;
171 172
@@ -178,7 +179,7 @@ static int pop_mpls(struct sk_buff *skb, struct sw_flow_key *key,
178{ 179{
179 int err; 180 int err;
180 181
181 err = skb_mpls_pop(skb, ethertype); 182 err = skb_mpls_pop(skb, ethertype, skb->mac_len);
182 if (err) 183 if (err)
183 return err; 184 return err;
184 185
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index f30e406fbec5..d8c364d637b1 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -1881,7 +1881,7 @@ static struct genl_family dp_datapath_genl_family __ro_after_init = {
1881/* Called with ovs_mutex or RCU read lock. */ 1881/* Called with ovs_mutex or RCU read lock. */
1882static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb, 1882static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb,
1883 struct net *net, u32 portid, u32 seq, 1883 struct net *net, u32 portid, u32 seq,
1884 u32 flags, u8 cmd) 1884 u32 flags, u8 cmd, gfp_t gfp)
1885{ 1885{
1886 struct ovs_header *ovs_header; 1886 struct ovs_header *ovs_header;
1887 struct ovs_vport_stats vport_stats; 1887 struct ovs_vport_stats vport_stats;
@@ -1902,7 +1902,7 @@ static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb,
1902 goto nla_put_failure; 1902 goto nla_put_failure;
1903 1903
1904 if (!net_eq(net, dev_net(vport->dev))) { 1904 if (!net_eq(net, dev_net(vport->dev))) {
1905 int id = peernet2id_alloc(net, dev_net(vport->dev)); 1905 int id = peernet2id_alloc(net, dev_net(vport->dev), gfp);
1906 1906
1907 if (nla_put_s32(skb, OVS_VPORT_ATTR_NETNSID, id)) 1907 if (nla_put_s32(skb, OVS_VPORT_ATTR_NETNSID, id))
1908 goto nla_put_failure; 1908 goto nla_put_failure;
@@ -1943,11 +1943,12 @@ struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, struct net *net,
1943 struct sk_buff *skb; 1943 struct sk_buff *skb;
1944 int retval; 1944 int retval;
1945 1945
1946 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); 1946 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1947 if (!skb) 1947 if (!skb)
1948 return ERR_PTR(-ENOMEM); 1948 return ERR_PTR(-ENOMEM);
1949 1949
1950 retval = ovs_vport_cmd_fill_info(vport, skb, net, portid, seq, 0, cmd); 1950 retval = ovs_vport_cmd_fill_info(vport, skb, net, portid, seq, 0, cmd,
1951 GFP_KERNEL);
1951 BUG_ON(retval < 0); 1952 BUG_ON(retval < 0);
1952 1953
1953 return skb; 1954 return skb;
@@ -2089,7 +2090,7 @@ restart:
2089 2090
2090 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info), 2091 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2091 info->snd_portid, info->snd_seq, 0, 2092 info->snd_portid, info->snd_seq, 0,
2092 OVS_VPORT_CMD_NEW); 2093 OVS_VPORT_CMD_NEW, GFP_KERNEL);
2093 2094
2094 new_headroom = netdev_get_fwd_headroom(vport->dev); 2095 new_headroom = netdev_get_fwd_headroom(vport->dev);
2095 2096
@@ -2150,7 +2151,7 @@ static int ovs_vport_cmd_set(struct sk_buff *skb, struct genl_info *info)
2150 2151
2151 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info), 2152 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2152 info->snd_portid, info->snd_seq, 0, 2153 info->snd_portid, info->snd_seq, 0,
2153 OVS_VPORT_CMD_SET); 2154 OVS_VPORT_CMD_SET, GFP_KERNEL);
2154 BUG_ON(err < 0); 2155 BUG_ON(err < 0);
2155 2156
2156 ovs_unlock(); 2157 ovs_unlock();
@@ -2190,7 +2191,7 @@ static int ovs_vport_cmd_del(struct sk_buff *skb, struct genl_info *info)
2190 2191
2191 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info), 2192 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2192 info->snd_portid, info->snd_seq, 0, 2193 info->snd_portid, info->snd_seq, 0,
2193 OVS_VPORT_CMD_DEL); 2194 OVS_VPORT_CMD_DEL, GFP_KERNEL);
2194 BUG_ON(err < 0); 2195 BUG_ON(err < 0);
2195 2196
2196 /* the vport deletion may trigger dp headroom update */ 2197 /* the vport deletion may trigger dp headroom update */
@@ -2237,7 +2238,7 @@ static int ovs_vport_cmd_get(struct sk_buff *skb, struct genl_info *info)
2237 goto exit_unlock_free; 2238 goto exit_unlock_free;
2238 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info), 2239 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2239 info->snd_portid, info->snd_seq, 0, 2240 info->snd_portid, info->snd_seq, 0,
2240 OVS_VPORT_CMD_GET); 2241 OVS_VPORT_CMD_GET, GFP_ATOMIC);
2241 BUG_ON(err < 0); 2242 BUG_ON(err < 0);
2242 rcu_read_unlock(); 2243 rcu_read_unlock();
2243 2244
@@ -2273,7 +2274,8 @@ static int ovs_vport_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
2273 NETLINK_CB(cb->skb).portid, 2274 NETLINK_CB(cb->skb).portid,
2274 cb->nlh->nlmsg_seq, 2275 cb->nlh->nlmsg_seq,
2275 NLM_F_MULTI, 2276 NLM_F_MULTI,
2276 OVS_VPORT_CMD_GET) < 0) 2277 OVS_VPORT_CMD_GET,
2278 GFP_ATOMIC) < 0)
2277 goto out; 2279 goto out;
2278 2280
2279 j++; 2281 j++;
diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c
index d2437b5b2f6a..58a7b8312c28 100644
--- a/net/openvswitch/vport-internal_dev.c
+++ b/net/openvswitch/vport-internal_dev.c
@@ -137,7 +137,7 @@ static void do_setup(struct net_device *netdev)
137 netdev->priv_flags |= IFF_LIVE_ADDR_CHANGE | IFF_OPENVSWITCH | 137 netdev->priv_flags |= IFF_LIVE_ADDR_CHANGE | IFF_OPENVSWITCH |
138 IFF_NO_QUEUE; 138 IFF_NO_QUEUE;
139 netdev->needs_free_netdev = true; 139 netdev->needs_free_netdev = true;
140 netdev->priv_destructor = internal_dev_destructor; 140 netdev->priv_destructor = NULL;
141 netdev->ethtool_ops = &internal_dev_ethtool_ops; 141 netdev->ethtool_ops = &internal_dev_ethtool_ops;
142 netdev->rtnl_link_ops = &internal_dev_link_ops; 142 netdev->rtnl_link_ops = &internal_dev_link_ops;
143 143
@@ -159,7 +159,6 @@ static struct vport *internal_dev_create(const struct vport_parms *parms)
159 struct internal_dev *internal_dev; 159 struct internal_dev *internal_dev;
160 struct net_device *dev; 160 struct net_device *dev;
161 int err; 161 int err;
162 bool free_vport = true;
163 162
164 vport = ovs_vport_alloc(0, &ovs_internal_vport_ops, parms); 163 vport = ovs_vport_alloc(0, &ovs_internal_vport_ops, parms);
165 if (IS_ERR(vport)) { 164 if (IS_ERR(vport)) {
@@ -190,10 +189,9 @@ static struct vport *internal_dev_create(const struct vport_parms *parms)
190 189
191 rtnl_lock(); 190 rtnl_lock();
192 err = register_netdevice(vport->dev); 191 err = register_netdevice(vport->dev);
193 if (err) { 192 if (err)
194 free_vport = false;
195 goto error_unlock; 193 goto error_unlock;
196 } 194 vport->dev->priv_destructor = internal_dev_destructor;
197 195
198 dev_set_promiscuity(vport->dev, 1); 196 dev_set_promiscuity(vport->dev, 1);
199 rtnl_unlock(); 197 rtnl_unlock();
@@ -207,8 +205,7 @@ error_unlock:
207error_free_netdev: 205error_free_netdev:
208 free_netdev(dev); 206 free_netdev(dev);
209error_free_vport: 207error_free_vport:
210 if (free_vport) 208 ovs_vport_free(vport);
211 ovs_vport_free(vport);
212error: 209error:
213 return ERR_PTR(err); 210 return ERR_PTR(err);
214} 211}
@@ -237,7 +234,7 @@ static netdev_tx_t internal_dev_recv(struct sk_buff *skb)
237 } 234 }
238 235
239 skb_dst_drop(skb); 236 skb_dst_drop(skb);
240 nf_reset(skb); 237 nf_reset_ct(skb);
241 secpath_reset(skb); 238 secpath_reset(skb);
242 239
243 skb->pkt_type = PACKET_HOST; 240 skb->pkt_type = PACKET_HOST;
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index e2742b006d25..82a50e850245 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1821,7 +1821,7 @@ static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev,
1821 skb_dst_drop(skb); 1821 skb_dst_drop(skb);
1822 1822
1823 /* drop conntrack reference */ 1823 /* drop conntrack reference */
1824 nf_reset(skb); 1824 nf_reset_ct(skb);
1825 1825
1826 spkt = &PACKET_SKB_CB(skb)->sa.pkt; 1826 spkt = &PACKET_SKB_CB(skb)->sa.pkt;
1827 1827
@@ -2121,7 +2121,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
2121 skb_dst_drop(skb); 2121 skb_dst_drop(skb);
2122 2122
2123 /* drop conntrack reference */ 2123 /* drop conntrack reference */
2124 nf_reset(skb); 2124 nf_reset_ct(skb);
2125 2125
2126 spin_lock(&sk->sk_receive_queue.lock); 2126 spin_lock(&sk->sk_receive_queue.lock);
2127 po->stats.stats1.tp_packets++; 2127 po->stats.stats1.tp_packets++;
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index 96ea9f254ae9..76d499f6af9a 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -338,9 +338,9 @@ static __poll_t pn_socket_poll(struct file *file, struct socket *sock,
338 338
339 if (sk->sk_state == TCP_CLOSE) 339 if (sk->sk_state == TCP_CLOSE)
340 return EPOLLERR; 340 return EPOLLERR;
341 if (!skb_queue_empty(&sk->sk_receive_queue)) 341 if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
342 mask |= EPOLLIN | EPOLLRDNORM; 342 mask |= EPOLLIN | EPOLLRDNORM;
343 if (!skb_queue_empty(&pn->ctrlreq_queue)) 343 if (!skb_queue_empty_lockless(&pn->ctrlreq_queue))
344 mask |= EPOLLPRI; 344 mask |= EPOLLPRI;
345 if (!mask && sk->sk_state == TCP_CLOSE_WAIT) 345 if (!mask && sk->sk_state == TCP_CLOSE_WAIT)
346 return EPOLLHUP; 346 return EPOLLHUP;
diff --git a/net/rds/ib.c b/net/rds/ib.c
index 45acab2de0cf..9de2ae22d583 100644
--- a/net/rds/ib.c
+++ b/net/rds/ib.c
@@ -143,6 +143,9 @@ static void rds_ib_add_one(struct ib_device *device)
143 refcount_set(&rds_ibdev->refcount, 1); 143 refcount_set(&rds_ibdev->refcount, 1);
144 INIT_WORK(&rds_ibdev->free_work, rds_ib_dev_free); 144 INIT_WORK(&rds_ibdev->free_work, rds_ib_dev_free);
145 145
146 INIT_LIST_HEAD(&rds_ibdev->ipaddr_list);
147 INIT_LIST_HEAD(&rds_ibdev->conn_list);
148
146 rds_ibdev->max_wrs = device->attrs.max_qp_wr; 149 rds_ibdev->max_wrs = device->attrs.max_qp_wr;
147 rds_ibdev->max_sge = min(device->attrs.max_send_sge, RDS_IB_MAX_SGE); 150 rds_ibdev->max_sge = min(device->attrs.max_send_sge, RDS_IB_MAX_SGE);
148 151
@@ -203,9 +206,6 @@ static void rds_ib_add_one(struct ib_device *device)
203 device->name, 206 device->name,
204 rds_ibdev->use_fastreg ? "FRMR" : "FMR"); 207 rds_ibdev->use_fastreg ? "FRMR" : "FMR");
205 208
206 INIT_LIST_HEAD(&rds_ibdev->ipaddr_list);
207 INIT_LIST_HEAD(&rds_ibdev->conn_list);
208
209 down_write(&rds_ib_devices_lock); 209 down_write(&rds_ib_devices_lock);
210 list_add_tail_rcu(&rds_ibdev->list, &rds_ib_devices); 210 list_add_tail_rcu(&rds_ibdev->list, &rds_ib_devices);
211 up_write(&rds_ib_devices_lock); 211 up_write(&rds_ib_devices_lock);
diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c
index f0e9ccf472a9..6a0df7c8a939 100644
--- a/net/rose/af_rose.c
+++ b/net/rose/af_rose.c
@@ -65,28 +65,6 @@ static const struct proto_ops rose_proto_ops;
65ax25_address rose_callsign; 65ax25_address rose_callsign;
66 66
67/* 67/*
68 * ROSE network devices are virtual network devices encapsulating ROSE
69 * frames into AX.25 which will be sent through an AX.25 device, so form a
70 * special "super class" of normal net devices; split their locks off into a
71 * separate class since they always nest.
72 */
73static struct lock_class_key rose_netdev_xmit_lock_key;
74static struct lock_class_key rose_netdev_addr_lock_key;
75
76static void rose_set_lockdep_one(struct net_device *dev,
77 struct netdev_queue *txq,
78 void *_unused)
79{
80 lockdep_set_class(&txq->_xmit_lock, &rose_netdev_xmit_lock_key);
81}
82
83static void rose_set_lockdep_key(struct net_device *dev)
84{
85 lockdep_set_class(&dev->addr_list_lock, &rose_netdev_addr_lock_key);
86 netdev_for_each_tx_queue(dev, rose_set_lockdep_one, NULL);
87}
88
89/*
90 * Convert a ROSE address into text. 68 * Convert a ROSE address into text.
91 */ 69 */
92char *rose2asc(char *buf, const rose_address *addr) 70char *rose2asc(char *buf, const rose_address *addr)
@@ -1533,7 +1511,6 @@ static int __init rose_proto_init(void)
1533 free_netdev(dev); 1511 free_netdev(dev);
1534 goto fail; 1512 goto fail;
1535 } 1513 }
1536 rose_set_lockdep_key(dev);
1537 dev_rose[i] = dev; 1514 dev_rose[i] = dev;
1538 } 1515 }
1539 1516
diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
index 1091bf35a199..7c7d10f2e0c1 100644
--- a/net/rxrpc/ar-internal.h
+++ b/net/rxrpc/ar-internal.h
@@ -556,6 +556,7 @@ struct rxrpc_call {
556 struct rxrpc_peer *peer; /* Peer record for remote address */ 556 struct rxrpc_peer *peer; /* Peer record for remote address */
557 struct rxrpc_sock __rcu *socket; /* socket responsible */ 557 struct rxrpc_sock __rcu *socket; /* socket responsible */
558 struct rxrpc_net *rxnet; /* Network namespace to which call belongs */ 558 struct rxrpc_net *rxnet; /* Network namespace to which call belongs */
559 const struct rxrpc_security *security; /* applied security module */
559 struct mutex user_mutex; /* User access mutex */ 560 struct mutex user_mutex; /* User access mutex */
560 unsigned long ack_at; /* When deferred ACK needs to happen */ 561 unsigned long ack_at; /* When deferred ACK needs to happen */
561 unsigned long ack_lost_at; /* When ACK is figured as lost */ 562 unsigned long ack_lost_at; /* When ACK is figured as lost */
@@ -600,6 +601,7 @@ struct rxrpc_call {
600 int debug_id; /* debug ID for printks */ 601 int debug_id; /* debug ID for printks */
601 unsigned short rx_pkt_offset; /* Current recvmsg packet offset */ 602 unsigned short rx_pkt_offset; /* Current recvmsg packet offset */
602 unsigned short rx_pkt_len; /* Current recvmsg packet len */ 603 unsigned short rx_pkt_len; /* Current recvmsg packet len */
604 bool rx_pkt_last; /* Current recvmsg packet is last */
603 605
604 /* Rx/Tx circular buffer, depending on phase. 606 /* Rx/Tx circular buffer, depending on phase.
605 * 607 *
diff --git a/net/rxrpc/call_accept.c b/net/rxrpc/call_accept.c
index 00c095d74145..135bf5cd8dd5 100644
--- a/net/rxrpc/call_accept.c
+++ b/net/rxrpc/call_accept.c
@@ -84,7 +84,7 @@ static int rxrpc_service_prealloc_one(struct rxrpc_sock *rx,
84 smp_store_release(&b->conn_backlog_head, 84 smp_store_release(&b->conn_backlog_head,
85 (head + 1) & (size - 1)); 85 (head + 1) & (size - 1));
86 86
87 trace_rxrpc_conn(conn, rxrpc_conn_new_service, 87 trace_rxrpc_conn(conn->debug_id, rxrpc_conn_new_service,
88 atomic_read(&conn->usage), here); 88 atomic_read(&conn->usage), here);
89 } 89 }
90 90
@@ -97,7 +97,7 @@ static int rxrpc_service_prealloc_one(struct rxrpc_sock *rx,
97 call->flags |= (1 << RXRPC_CALL_IS_SERVICE); 97 call->flags |= (1 << RXRPC_CALL_IS_SERVICE);
98 call->state = RXRPC_CALL_SERVER_PREALLOC; 98 call->state = RXRPC_CALL_SERVER_PREALLOC;
99 99
100 trace_rxrpc_call(call, rxrpc_call_new_service, 100 trace_rxrpc_call(call->debug_id, rxrpc_call_new_service,
101 atomic_read(&call->usage), 101 atomic_read(&call->usage),
102 here, (const void *)user_call_ID); 102 here, (const void *)user_call_ID);
103 103
@@ -307,6 +307,7 @@ static struct rxrpc_call *rxrpc_alloc_incoming_call(struct rxrpc_sock *rx,
307 307
308 rxrpc_see_call(call); 308 rxrpc_see_call(call);
309 call->conn = conn; 309 call->conn = conn;
310 call->security = conn->security;
310 call->peer = rxrpc_get_peer(conn->params.peer); 311 call->peer = rxrpc_get_peer(conn->params.peer);
311 call->cong_cwnd = call->peer->cong_cwnd; 312 call->cong_cwnd = call->peer->cong_cwnd;
312 return call; 313 return call;
diff --git a/net/rxrpc/call_object.c b/net/rxrpc/call_object.c
index 32d8dc677142..a31c18c09894 100644
--- a/net/rxrpc/call_object.c
+++ b/net/rxrpc/call_object.c
@@ -240,7 +240,8 @@ struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *rx,
240 if (p->intr) 240 if (p->intr)
241 __set_bit(RXRPC_CALL_IS_INTR, &call->flags); 241 __set_bit(RXRPC_CALL_IS_INTR, &call->flags);
242 call->tx_total_len = p->tx_total_len; 242 call->tx_total_len = p->tx_total_len;
243 trace_rxrpc_call(call, rxrpc_call_new_client, atomic_read(&call->usage), 243 trace_rxrpc_call(call->debug_id, rxrpc_call_new_client,
244 atomic_read(&call->usage),
244 here, (const void *)p->user_call_ID); 245 here, (const void *)p->user_call_ID);
245 246
246 /* We need to protect a partially set up call against the user as we 247 /* We need to protect a partially set up call against the user as we
@@ -290,8 +291,8 @@ struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *rx,
290 if (ret < 0) 291 if (ret < 0)
291 goto error; 292 goto error;
292 293
293 trace_rxrpc_call(call, rxrpc_call_connected, atomic_read(&call->usage), 294 trace_rxrpc_call(call->debug_id, rxrpc_call_connected,
294 here, NULL); 295 atomic_read(&call->usage), here, NULL);
295 296
296 rxrpc_start_call_timer(call); 297 rxrpc_start_call_timer(call);
297 298
@@ -313,8 +314,8 @@ error_dup_user_ID:
313error: 314error:
314 __rxrpc_set_call_completion(call, RXRPC_CALL_LOCAL_ERROR, 315 __rxrpc_set_call_completion(call, RXRPC_CALL_LOCAL_ERROR,
315 RX_CALL_DEAD, ret); 316 RX_CALL_DEAD, ret);
316 trace_rxrpc_call(call, rxrpc_call_error, atomic_read(&call->usage), 317 trace_rxrpc_call(call->debug_id, rxrpc_call_error,
317 here, ERR_PTR(ret)); 318 atomic_read(&call->usage), here, ERR_PTR(ret));
318 rxrpc_release_call(rx, call); 319 rxrpc_release_call(rx, call);
319 mutex_unlock(&call->user_mutex); 320 mutex_unlock(&call->user_mutex);
320 rxrpc_put_call(call, rxrpc_call_put); 321 rxrpc_put_call(call, rxrpc_call_put);
@@ -376,7 +377,8 @@ bool rxrpc_queue_call(struct rxrpc_call *call)
376 if (n == 0) 377 if (n == 0)
377 return false; 378 return false;
378 if (rxrpc_queue_work(&call->processor)) 379 if (rxrpc_queue_work(&call->processor))
379 trace_rxrpc_call(call, rxrpc_call_queued, n + 1, here, NULL); 380 trace_rxrpc_call(call->debug_id, rxrpc_call_queued, n + 1,
381 here, NULL);
380 else 382 else
381 rxrpc_put_call(call, rxrpc_call_put_noqueue); 383 rxrpc_put_call(call, rxrpc_call_put_noqueue);
382 return true; 384 return true;
@@ -391,7 +393,8 @@ bool __rxrpc_queue_call(struct rxrpc_call *call)
391 int n = atomic_read(&call->usage); 393 int n = atomic_read(&call->usage);
392 ASSERTCMP(n, >=, 1); 394 ASSERTCMP(n, >=, 1);
393 if (rxrpc_queue_work(&call->processor)) 395 if (rxrpc_queue_work(&call->processor))
394 trace_rxrpc_call(call, rxrpc_call_queued_ref, n, here, NULL); 396 trace_rxrpc_call(call->debug_id, rxrpc_call_queued_ref, n,
397 here, NULL);
395 else 398 else
396 rxrpc_put_call(call, rxrpc_call_put_noqueue); 399 rxrpc_put_call(call, rxrpc_call_put_noqueue);
397 return true; 400 return true;
@@ -406,7 +409,8 @@ void rxrpc_see_call(struct rxrpc_call *call)
406 if (call) { 409 if (call) {
407 int n = atomic_read(&call->usage); 410 int n = atomic_read(&call->usage);
408 411
409 trace_rxrpc_call(call, rxrpc_call_seen, n, here, NULL); 412 trace_rxrpc_call(call->debug_id, rxrpc_call_seen, n,
413 here, NULL);
410 } 414 }
411} 415}
412 416
@@ -418,7 +422,7 @@ void rxrpc_get_call(struct rxrpc_call *call, enum rxrpc_call_trace op)
418 const void *here = __builtin_return_address(0); 422 const void *here = __builtin_return_address(0);
419 int n = atomic_inc_return(&call->usage); 423 int n = atomic_inc_return(&call->usage);
420 424
421 trace_rxrpc_call(call, op, n, here, NULL); 425 trace_rxrpc_call(call->debug_id, op, n, here, NULL);
422} 426}
423 427
424/* 428/*
@@ -445,7 +449,8 @@ void rxrpc_release_call(struct rxrpc_sock *rx, struct rxrpc_call *call)
445 449
446 _enter("{%d,%d}", call->debug_id, atomic_read(&call->usage)); 450 _enter("{%d,%d}", call->debug_id, atomic_read(&call->usage));
447 451
448 trace_rxrpc_call(call, rxrpc_call_release, atomic_read(&call->usage), 452 trace_rxrpc_call(call->debug_id, rxrpc_call_release,
453 atomic_read(&call->usage),
449 here, (const void *)call->flags); 454 here, (const void *)call->flags);
450 455
451 ASSERTCMP(call->state, ==, RXRPC_CALL_COMPLETE); 456 ASSERTCMP(call->state, ==, RXRPC_CALL_COMPLETE);
@@ -488,10 +493,10 @@ void rxrpc_release_call(struct rxrpc_sock *rx, struct rxrpc_call *call)
488 493
489 _debug("RELEASE CALL %p (%d CONN %p)", call, call->debug_id, conn); 494 _debug("RELEASE CALL %p (%d CONN %p)", call, call->debug_id, conn);
490 495
491 if (conn) { 496 if (conn)
492 rxrpc_disconnect_call(call); 497 rxrpc_disconnect_call(call);
493 conn->security->free_call_crypto(call); 498 if (call->security)
494 } 499 call->security->free_call_crypto(call);
495 500
496 rxrpc_cleanup_ring(call); 501 rxrpc_cleanup_ring(call);
497 _leave(""); 502 _leave("");
@@ -534,12 +539,13 @@ void rxrpc_put_call(struct rxrpc_call *call, enum rxrpc_call_trace op)
534{ 539{
535 struct rxrpc_net *rxnet = call->rxnet; 540 struct rxrpc_net *rxnet = call->rxnet;
536 const void *here = __builtin_return_address(0); 541 const void *here = __builtin_return_address(0);
542 unsigned int debug_id = call->debug_id;
537 int n; 543 int n;
538 544
539 ASSERT(call != NULL); 545 ASSERT(call != NULL);
540 546
541 n = atomic_dec_return(&call->usage); 547 n = atomic_dec_return(&call->usage);
542 trace_rxrpc_call(call, op, n, here, NULL); 548 trace_rxrpc_call(debug_id, op, n, here, NULL);
543 ASSERTCMP(n, >=, 0); 549 ASSERTCMP(n, >=, 0);
544 if (n == 0) { 550 if (n == 0) {
545 _debug("call %d dead", call->debug_id); 551 _debug("call %d dead", call->debug_id);
diff --git a/net/rxrpc/conn_client.c b/net/rxrpc/conn_client.c
index 3f1da1b49f69..376370cd9285 100644
--- a/net/rxrpc/conn_client.c
+++ b/net/rxrpc/conn_client.c
@@ -212,7 +212,8 @@ rxrpc_alloc_client_connection(struct rxrpc_conn_parameters *cp, gfp_t gfp)
212 rxrpc_get_local(conn->params.local); 212 rxrpc_get_local(conn->params.local);
213 key_get(conn->params.key); 213 key_get(conn->params.key);
214 214
215 trace_rxrpc_conn(conn, rxrpc_conn_new_client, atomic_read(&conn->usage), 215 trace_rxrpc_conn(conn->debug_id, rxrpc_conn_new_client,
216 atomic_read(&conn->usage),
216 __builtin_return_address(0)); 217 __builtin_return_address(0));
217 trace_rxrpc_client(conn, -1, rxrpc_client_alloc); 218 trace_rxrpc_client(conn, -1, rxrpc_client_alloc);
218 _leave(" = %p", conn); 219 _leave(" = %p", conn);
@@ -352,6 +353,7 @@ static int rxrpc_get_client_conn(struct rxrpc_sock *rx,
352 353
353 if (cp->exclusive) { 354 if (cp->exclusive) {
354 call->conn = candidate; 355 call->conn = candidate;
356 call->security = candidate->security;
355 call->security_ix = candidate->security_ix; 357 call->security_ix = candidate->security_ix;
356 call->service_id = candidate->service_id; 358 call->service_id = candidate->service_id;
357 _leave(" = 0 [exclusive %d]", candidate->debug_id); 359 _leave(" = 0 [exclusive %d]", candidate->debug_id);
@@ -403,6 +405,7 @@ static int rxrpc_get_client_conn(struct rxrpc_sock *rx,
403candidate_published: 405candidate_published:
404 set_bit(RXRPC_CONN_IN_CLIENT_CONNS, &candidate->flags); 406 set_bit(RXRPC_CONN_IN_CLIENT_CONNS, &candidate->flags);
405 call->conn = candidate; 407 call->conn = candidate;
408 call->security = candidate->security;
406 call->security_ix = candidate->security_ix; 409 call->security_ix = candidate->security_ix;
407 call->service_id = candidate->service_id; 410 call->service_id = candidate->service_id;
408 spin_unlock(&local->client_conns_lock); 411 spin_unlock(&local->client_conns_lock);
@@ -425,6 +428,7 @@ found_extant_conn:
425 428
426 spin_lock(&conn->channel_lock); 429 spin_lock(&conn->channel_lock);
427 call->conn = conn; 430 call->conn = conn;
431 call->security = conn->security;
428 call->security_ix = conn->security_ix; 432 call->security_ix = conn->security_ix;
429 call->service_id = conn->service_id; 433 call->service_id = conn->service_id;
430 list_add_tail(&call->chan_wait_link, &conn->waiting_calls); 434 list_add_tail(&call->chan_wait_link, &conn->waiting_calls);
@@ -985,11 +989,12 @@ rxrpc_put_one_client_conn(struct rxrpc_connection *conn)
985void rxrpc_put_client_conn(struct rxrpc_connection *conn) 989void rxrpc_put_client_conn(struct rxrpc_connection *conn)
986{ 990{
987 const void *here = __builtin_return_address(0); 991 const void *here = __builtin_return_address(0);
992 unsigned int debug_id = conn->debug_id;
988 int n; 993 int n;
989 994
990 do { 995 do {
991 n = atomic_dec_return(&conn->usage); 996 n = atomic_dec_return(&conn->usage);
992 trace_rxrpc_conn(conn, rxrpc_conn_put_client, n, here); 997 trace_rxrpc_conn(debug_id, rxrpc_conn_put_client, n, here);
993 if (n > 0) 998 if (n > 0)
994 return; 999 return;
995 ASSERTCMP(n, >=, 0); 1000 ASSERTCMP(n, >=, 0);
diff --git a/net/rxrpc/conn_object.c b/net/rxrpc/conn_object.c
index ed05b6922132..38d718e90dc6 100644
--- a/net/rxrpc/conn_object.c
+++ b/net/rxrpc/conn_object.c
@@ -269,7 +269,7 @@ bool rxrpc_queue_conn(struct rxrpc_connection *conn)
269 if (n == 0) 269 if (n == 0)
270 return false; 270 return false;
271 if (rxrpc_queue_work(&conn->processor)) 271 if (rxrpc_queue_work(&conn->processor))
272 trace_rxrpc_conn(conn, rxrpc_conn_queued, n + 1, here); 272 trace_rxrpc_conn(conn->debug_id, rxrpc_conn_queued, n + 1, here);
273 else 273 else
274 rxrpc_put_connection(conn); 274 rxrpc_put_connection(conn);
275 return true; 275 return true;
@@ -284,7 +284,7 @@ void rxrpc_see_connection(struct rxrpc_connection *conn)
284 if (conn) { 284 if (conn) {
285 int n = atomic_read(&conn->usage); 285 int n = atomic_read(&conn->usage);
286 286
287 trace_rxrpc_conn(conn, rxrpc_conn_seen, n, here); 287 trace_rxrpc_conn(conn->debug_id, rxrpc_conn_seen, n, here);
288 } 288 }
289} 289}
290 290
@@ -296,7 +296,7 @@ void rxrpc_get_connection(struct rxrpc_connection *conn)
296 const void *here = __builtin_return_address(0); 296 const void *here = __builtin_return_address(0);
297 int n = atomic_inc_return(&conn->usage); 297 int n = atomic_inc_return(&conn->usage);
298 298
299 trace_rxrpc_conn(conn, rxrpc_conn_got, n, here); 299 trace_rxrpc_conn(conn->debug_id, rxrpc_conn_got, n, here);
300} 300}
301 301
302/* 302/*
@@ -310,7 +310,7 @@ rxrpc_get_connection_maybe(struct rxrpc_connection *conn)
310 if (conn) { 310 if (conn) {
311 int n = atomic_fetch_add_unless(&conn->usage, 1, 0); 311 int n = atomic_fetch_add_unless(&conn->usage, 1, 0);
312 if (n > 0) 312 if (n > 0)
313 trace_rxrpc_conn(conn, rxrpc_conn_got, n + 1, here); 313 trace_rxrpc_conn(conn->debug_id, rxrpc_conn_got, n + 1, here);
314 else 314 else
315 conn = NULL; 315 conn = NULL;
316 } 316 }
@@ -333,10 +333,11 @@ static void rxrpc_set_service_reap_timer(struct rxrpc_net *rxnet,
333void rxrpc_put_service_conn(struct rxrpc_connection *conn) 333void rxrpc_put_service_conn(struct rxrpc_connection *conn)
334{ 334{
335 const void *here = __builtin_return_address(0); 335 const void *here = __builtin_return_address(0);
336 unsigned int debug_id = conn->debug_id;
336 int n; 337 int n;
337 338
338 n = atomic_dec_return(&conn->usage); 339 n = atomic_dec_return(&conn->usage);
339 trace_rxrpc_conn(conn, rxrpc_conn_put_service, n, here); 340 trace_rxrpc_conn(debug_id, rxrpc_conn_put_service, n, here);
340 ASSERTCMP(n, >=, 0); 341 ASSERTCMP(n, >=, 0);
341 if (n == 1) 342 if (n == 1)
342 rxrpc_set_service_reap_timer(conn->params.local->rxnet, 343 rxrpc_set_service_reap_timer(conn->params.local->rxnet,
@@ -420,7 +421,7 @@ void rxrpc_service_connection_reaper(struct work_struct *work)
420 */ 421 */
421 if (atomic_cmpxchg(&conn->usage, 1, 0) != 1) 422 if (atomic_cmpxchg(&conn->usage, 1, 0) != 1)
422 continue; 423 continue;
423 trace_rxrpc_conn(conn, rxrpc_conn_reap_service, 0, NULL); 424 trace_rxrpc_conn(conn->debug_id, rxrpc_conn_reap_service, 0, NULL);
424 425
425 if (rxrpc_conn_is_client(conn)) 426 if (rxrpc_conn_is_client(conn))
426 BUG(); 427 BUG();
diff --git a/net/rxrpc/conn_service.c b/net/rxrpc/conn_service.c
index b30e13f6d95f..123d6ceab15c 100644
--- a/net/rxrpc/conn_service.c
+++ b/net/rxrpc/conn_service.c
@@ -134,7 +134,7 @@ struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *rxn
134 list_add_tail(&conn->proc_link, &rxnet->conn_proc_list); 134 list_add_tail(&conn->proc_link, &rxnet->conn_proc_list);
135 write_unlock(&rxnet->conn_lock); 135 write_unlock(&rxnet->conn_lock);
136 136
137 trace_rxrpc_conn(conn, rxrpc_conn_new_service, 137 trace_rxrpc_conn(conn->debug_id, rxrpc_conn_new_service,
138 atomic_read(&conn->usage), 138 atomic_read(&conn->usage),
139 __builtin_return_address(0)); 139 __builtin_return_address(0));
140 } 140 }
diff --git a/net/rxrpc/peer_event.c b/net/rxrpc/peer_event.c
index c97ebdc043e4..48f67a9b1037 100644
--- a/net/rxrpc/peer_event.c
+++ b/net/rxrpc/peer_event.c
@@ -147,10 +147,16 @@ void rxrpc_error_report(struct sock *sk)
147{ 147{
148 struct sock_exterr_skb *serr; 148 struct sock_exterr_skb *serr;
149 struct sockaddr_rxrpc srx; 149 struct sockaddr_rxrpc srx;
150 struct rxrpc_local *local = sk->sk_user_data; 150 struct rxrpc_local *local;
151 struct rxrpc_peer *peer; 151 struct rxrpc_peer *peer;
152 struct sk_buff *skb; 152 struct sk_buff *skb;
153 153
154 rcu_read_lock();
155 local = rcu_dereference_sk_user_data(sk);
156 if (unlikely(!local)) {
157 rcu_read_unlock();
158 return;
159 }
154 _enter("%p{%d}", sk, local->debug_id); 160 _enter("%p{%d}", sk, local->debug_id);
155 161
156 /* Clear the outstanding error value on the socket so that it doesn't 162 /* Clear the outstanding error value on the socket so that it doesn't
@@ -160,6 +166,7 @@ void rxrpc_error_report(struct sock *sk)
160 166
161 skb = sock_dequeue_err_skb(sk); 167 skb = sock_dequeue_err_skb(sk);
162 if (!skb) { 168 if (!skb) {
169 rcu_read_unlock();
163 _leave("UDP socket errqueue empty"); 170 _leave("UDP socket errqueue empty");
164 return; 171 return;
165 } 172 }
@@ -167,11 +174,11 @@ void rxrpc_error_report(struct sock *sk)
167 serr = SKB_EXT_ERR(skb); 174 serr = SKB_EXT_ERR(skb);
168 if (!skb->len && serr->ee.ee_origin == SO_EE_ORIGIN_TIMESTAMPING) { 175 if (!skb->len && serr->ee.ee_origin == SO_EE_ORIGIN_TIMESTAMPING) {
169 _leave("UDP empty message"); 176 _leave("UDP empty message");
177 rcu_read_unlock();
170 rxrpc_free_skb(skb, rxrpc_skb_freed); 178 rxrpc_free_skb(skb, rxrpc_skb_freed);
171 return; 179 return;
172 } 180 }
173 181
174 rcu_read_lock();
175 peer = rxrpc_lookup_peer_icmp_rcu(local, skb, &srx); 182 peer = rxrpc_lookup_peer_icmp_rcu(local, skb, &srx);
176 if (peer && !rxrpc_get_peer_maybe(peer)) 183 if (peer && !rxrpc_get_peer_maybe(peer))
177 peer = NULL; 184 peer = NULL;
diff --git a/net/rxrpc/peer_object.c b/net/rxrpc/peer_object.c
index 9c3ac96f71cb..64830d8c1fdb 100644
--- a/net/rxrpc/peer_object.c
+++ b/net/rxrpc/peer_object.c
@@ -216,7 +216,7 @@ struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *local, gfp_t gfp)
216 peer = kzalloc(sizeof(struct rxrpc_peer), gfp); 216 peer = kzalloc(sizeof(struct rxrpc_peer), gfp);
217 if (peer) { 217 if (peer) {
218 atomic_set(&peer->usage, 1); 218 atomic_set(&peer->usage, 1);
219 peer->local = local; 219 peer->local = rxrpc_get_local(local);
220 INIT_HLIST_HEAD(&peer->error_targets); 220 INIT_HLIST_HEAD(&peer->error_targets);
221 peer->service_conns = RB_ROOT; 221 peer->service_conns = RB_ROOT;
222 seqlock_init(&peer->service_conn_lock); 222 seqlock_init(&peer->service_conn_lock);
@@ -307,7 +307,6 @@ void rxrpc_new_incoming_peer(struct rxrpc_sock *rx, struct rxrpc_local *local,
307 unsigned long hash_key; 307 unsigned long hash_key;
308 308
309 hash_key = rxrpc_peer_hash_key(local, &peer->srx); 309 hash_key = rxrpc_peer_hash_key(local, &peer->srx);
310 peer->local = local;
311 rxrpc_init_peer(rx, peer, hash_key); 310 rxrpc_init_peer(rx, peer, hash_key);
312 311
313 spin_lock(&rxnet->peer_hash_lock); 312 spin_lock(&rxnet->peer_hash_lock);
@@ -382,7 +381,7 @@ struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *peer)
382 int n; 381 int n;
383 382
384 n = atomic_inc_return(&peer->usage); 383 n = atomic_inc_return(&peer->usage);
385 trace_rxrpc_peer(peer, rxrpc_peer_got, n, here); 384 trace_rxrpc_peer(peer->debug_id, rxrpc_peer_got, n, here);
386 return peer; 385 return peer;
387} 386}
388 387
@@ -396,7 +395,7 @@ struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer)
396 if (peer) { 395 if (peer) {
397 int n = atomic_fetch_add_unless(&peer->usage, 1, 0); 396 int n = atomic_fetch_add_unless(&peer->usage, 1, 0);
398 if (n > 0) 397 if (n > 0)
399 trace_rxrpc_peer(peer, rxrpc_peer_got, n + 1, here); 398 trace_rxrpc_peer(peer->debug_id, rxrpc_peer_got, n + 1, here);
400 else 399 else
401 peer = NULL; 400 peer = NULL;
402 } 401 }
@@ -417,6 +416,7 @@ static void __rxrpc_put_peer(struct rxrpc_peer *peer)
417 list_del_init(&peer->keepalive_link); 416 list_del_init(&peer->keepalive_link);
418 spin_unlock_bh(&rxnet->peer_hash_lock); 417 spin_unlock_bh(&rxnet->peer_hash_lock);
419 418
419 rxrpc_put_local(peer->local);
420 kfree_rcu(peer, rcu); 420 kfree_rcu(peer, rcu);
421} 421}
422 422
@@ -426,11 +426,13 @@ static void __rxrpc_put_peer(struct rxrpc_peer *peer)
426void rxrpc_put_peer(struct rxrpc_peer *peer) 426void rxrpc_put_peer(struct rxrpc_peer *peer)
427{ 427{
428 const void *here = __builtin_return_address(0); 428 const void *here = __builtin_return_address(0);
429 unsigned int debug_id;
429 int n; 430 int n;
430 431
431 if (peer) { 432 if (peer) {
433 debug_id = peer->debug_id;
432 n = atomic_dec_return(&peer->usage); 434 n = atomic_dec_return(&peer->usage);
433 trace_rxrpc_peer(peer, rxrpc_peer_put, n, here); 435 trace_rxrpc_peer(debug_id, rxrpc_peer_put, n, here);
434 if (n == 0) 436 if (n == 0)
435 __rxrpc_put_peer(peer); 437 __rxrpc_put_peer(peer);
436 } 438 }
@@ -443,13 +445,15 @@ void rxrpc_put_peer(struct rxrpc_peer *peer)
443void rxrpc_put_peer_locked(struct rxrpc_peer *peer) 445void rxrpc_put_peer_locked(struct rxrpc_peer *peer)
444{ 446{
445 const void *here = __builtin_return_address(0); 447 const void *here = __builtin_return_address(0);
448 unsigned int debug_id = peer->debug_id;
446 int n; 449 int n;
447 450
448 n = atomic_dec_return(&peer->usage); 451 n = atomic_dec_return(&peer->usage);
449 trace_rxrpc_peer(peer, rxrpc_peer_put, n, here); 452 trace_rxrpc_peer(debug_id, rxrpc_peer_put, n, here);
450 if (n == 0) { 453 if (n == 0) {
451 hash_del_rcu(&peer->hash_link); 454 hash_del_rcu(&peer->hash_link);
452 list_del_init(&peer->keepalive_link); 455 list_del_init(&peer->keepalive_link);
456 rxrpc_put_local(peer->local);
453 kfree_rcu(peer, rcu); 457 kfree_rcu(peer, rcu);
454 } 458 }
455} 459}
diff --git a/net/rxrpc/recvmsg.c b/net/rxrpc/recvmsg.c
index 3b0becb12041..8578c39ec839 100644
--- a/net/rxrpc/recvmsg.c
+++ b/net/rxrpc/recvmsg.c
@@ -251,8 +251,8 @@ static int rxrpc_verify_packet(struct rxrpc_call *call, struct sk_buff *skb,
251 seq += subpacket; 251 seq += subpacket;
252 } 252 }
253 253
254 return call->conn->security->verify_packet(call, skb, offset, len, 254 return call->security->verify_packet(call, skb, offset, len,
255 seq, cksum); 255 seq, cksum);
256} 256}
257 257
258/* 258/*
@@ -267,11 +267,13 @@ static int rxrpc_verify_packet(struct rxrpc_call *call, struct sk_buff *skb,
267 */ 267 */
268static int rxrpc_locate_data(struct rxrpc_call *call, struct sk_buff *skb, 268static int rxrpc_locate_data(struct rxrpc_call *call, struct sk_buff *skb,
269 u8 *_annotation, 269 u8 *_annotation,
270 unsigned int *_offset, unsigned int *_len) 270 unsigned int *_offset, unsigned int *_len,
271 bool *_last)
271{ 272{
272 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 273 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
273 unsigned int offset = sizeof(struct rxrpc_wire_header); 274 unsigned int offset = sizeof(struct rxrpc_wire_header);
274 unsigned int len; 275 unsigned int len;
276 bool last = false;
275 int ret; 277 int ret;
276 u8 annotation = *_annotation; 278 u8 annotation = *_annotation;
277 u8 subpacket = annotation & RXRPC_RX_ANNO_SUBPACKET; 279 u8 subpacket = annotation & RXRPC_RX_ANNO_SUBPACKET;
@@ -281,6 +283,8 @@ static int rxrpc_locate_data(struct rxrpc_call *call, struct sk_buff *skb,
281 len = skb->len - offset; 283 len = skb->len - offset;
282 if (subpacket < sp->nr_subpackets - 1) 284 if (subpacket < sp->nr_subpackets - 1)
283 len = RXRPC_JUMBO_DATALEN; 285 len = RXRPC_JUMBO_DATALEN;
286 else if (sp->rx_flags & RXRPC_SKB_INCL_LAST)
287 last = true;
284 288
285 if (!(annotation & RXRPC_RX_ANNO_VERIFIED)) { 289 if (!(annotation & RXRPC_RX_ANNO_VERIFIED)) {
286 ret = rxrpc_verify_packet(call, skb, annotation, offset, len); 290 ret = rxrpc_verify_packet(call, skb, annotation, offset, len);
@@ -291,7 +295,8 @@ static int rxrpc_locate_data(struct rxrpc_call *call, struct sk_buff *skb,
291 295
292 *_offset = offset; 296 *_offset = offset;
293 *_len = len; 297 *_len = len;
294 call->conn->security->locate_data(call, skb, _offset, _len); 298 *_last = last;
299 call->security->locate_data(call, skb, _offset, _len);
295 return 0; 300 return 0;
296} 301}
297 302
@@ -309,7 +314,7 @@ static int rxrpc_recvmsg_data(struct socket *sock, struct rxrpc_call *call,
309 rxrpc_serial_t serial; 314 rxrpc_serial_t serial;
310 rxrpc_seq_t hard_ack, top, seq; 315 rxrpc_seq_t hard_ack, top, seq;
311 size_t remain; 316 size_t remain;
312 bool last; 317 bool rx_pkt_last;
313 unsigned int rx_pkt_offset, rx_pkt_len; 318 unsigned int rx_pkt_offset, rx_pkt_len;
314 int ix, copy, ret = -EAGAIN, ret2; 319 int ix, copy, ret = -EAGAIN, ret2;
315 320
@@ -319,6 +324,7 @@ static int rxrpc_recvmsg_data(struct socket *sock, struct rxrpc_call *call,
319 324
320 rx_pkt_offset = call->rx_pkt_offset; 325 rx_pkt_offset = call->rx_pkt_offset;
321 rx_pkt_len = call->rx_pkt_len; 326 rx_pkt_len = call->rx_pkt_len;
327 rx_pkt_last = call->rx_pkt_last;
322 328
323 if (call->state >= RXRPC_CALL_SERVER_ACK_REQUEST) { 329 if (call->state >= RXRPC_CALL_SERVER_ACK_REQUEST) {
324 seq = call->rx_hard_ack; 330 seq = call->rx_hard_ack;
@@ -329,6 +335,7 @@ static int rxrpc_recvmsg_data(struct socket *sock, struct rxrpc_call *call,
329 /* Barriers against rxrpc_input_data(). */ 335 /* Barriers against rxrpc_input_data(). */
330 hard_ack = call->rx_hard_ack; 336 hard_ack = call->rx_hard_ack;
331 seq = hard_ack + 1; 337 seq = hard_ack + 1;
338
332 while (top = smp_load_acquire(&call->rx_top), 339 while (top = smp_load_acquire(&call->rx_top),
333 before_eq(seq, top) 340 before_eq(seq, top)
334 ) { 341 ) {
@@ -356,7 +363,8 @@ static int rxrpc_recvmsg_data(struct socket *sock, struct rxrpc_call *call,
356 if (rx_pkt_offset == 0) { 363 if (rx_pkt_offset == 0) {
357 ret2 = rxrpc_locate_data(call, skb, 364 ret2 = rxrpc_locate_data(call, skb,
358 &call->rxtx_annotations[ix], 365 &call->rxtx_annotations[ix],
359 &rx_pkt_offset, &rx_pkt_len); 366 &rx_pkt_offset, &rx_pkt_len,
367 &rx_pkt_last);
360 trace_rxrpc_recvmsg(call, rxrpc_recvmsg_next, seq, 368 trace_rxrpc_recvmsg(call, rxrpc_recvmsg_next, seq,
361 rx_pkt_offset, rx_pkt_len, ret2); 369 rx_pkt_offset, rx_pkt_len, ret2);
362 if (ret2 < 0) { 370 if (ret2 < 0) {
@@ -396,13 +404,12 @@ static int rxrpc_recvmsg_data(struct socket *sock, struct rxrpc_call *call,
396 } 404 }
397 405
398 /* The whole packet has been transferred. */ 406 /* The whole packet has been transferred. */
399 last = sp->hdr.flags & RXRPC_LAST_PACKET;
400 if (!(flags & MSG_PEEK)) 407 if (!(flags & MSG_PEEK))
401 rxrpc_rotate_rx_window(call); 408 rxrpc_rotate_rx_window(call);
402 rx_pkt_offset = 0; 409 rx_pkt_offset = 0;
403 rx_pkt_len = 0; 410 rx_pkt_len = 0;
404 411
405 if (last) { 412 if (rx_pkt_last) {
406 ASSERTCMP(seq, ==, READ_ONCE(call->rx_top)); 413 ASSERTCMP(seq, ==, READ_ONCE(call->rx_top));
407 ret = 1; 414 ret = 1;
408 goto out; 415 goto out;
@@ -415,6 +422,7 @@ out:
415 if (!(flags & MSG_PEEK)) { 422 if (!(flags & MSG_PEEK)) {
416 call->rx_pkt_offset = rx_pkt_offset; 423 call->rx_pkt_offset = rx_pkt_offset;
417 call->rx_pkt_len = rx_pkt_len; 424 call->rx_pkt_len = rx_pkt_len;
425 call->rx_pkt_last = rx_pkt_last;
418 } 426 }
419done: 427done:
420 trace_rxrpc_recvmsg(call, rxrpc_recvmsg_data_return, seq, 428 trace_rxrpc_recvmsg(call, rxrpc_recvmsg_data_return, seq,
diff --git a/net/rxrpc/sendmsg.c b/net/rxrpc/sendmsg.c
index 6a1547b270fe..813fd6888142 100644
--- a/net/rxrpc/sendmsg.c
+++ b/net/rxrpc/sendmsg.c
@@ -419,7 +419,7 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
419 call->tx_winsize) 419 call->tx_winsize)
420 sp->hdr.flags |= RXRPC_MORE_PACKETS; 420 sp->hdr.flags |= RXRPC_MORE_PACKETS;
421 421
422 ret = conn->security->secure_packet( 422 ret = call->security->secure_packet(
423 call, skb, skb->mark, skb->head); 423 call, skb, skb->mark, skb->head);
424 if (ret < 0) 424 if (ret < 0)
425 goto out; 425 goto out;
@@ -661,6 +661,7 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
661 case RXRPC_CALL_SERVER_PREALLOC: 661 case RXRPC_CALL_SERVER_PREALLOC:
662 case RXRPC_CALL_SERVER_SECURING: 662 case RXRPC_CALL_SERVER_SECURING:
663 case RXRPC_CALL_SERVER_ACCEPTING: 663 case RXRPC_CALL_SERVER_ACCEPTING:
664 rxrpc_put_call(call, rxrpc_call_put);
664 ret = -EBUSY; 665 ret = -EBUSY;
665 goto error_release_sock; 666 goto error_release_sock;
666 default: 667 default:
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 2558f00f6b3e..69d4676a402f 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -832,8 +832,7 @@ static struct tc_cookie *nla_memdup_cookie(struct nlattr **tb)
832} 832}
833 833
834static const struct nla_policy tcf_action_policy[TCA_ACT_MAX + 1] = { 834static const struct nla_policy tcf_action_policy[TCA_ACT_MAX + 1] = {
835 [TCA_ACT_KIND] = { .type = NLA_NUL_STRING, 835 [TCA_ACT_KIND] = { .type = NLA_STRING },
836 .len = IFNAMSIZ - 1 },
837 [TCA_ACT_INDEX] = { .type = NLA_U32 }, 836 [TCA_ACT_INDEX] = { .type = NLA_U32 },
838 [TCA_ACT_COOKIE] = { .type = NLA_BINARY, 837 [TCA_ACT_COOKIE] = { .type = NLA_BINARY,
839 .len = TC_COOKIE_MAX_SIZE }, 838 .len = TC_COOKIE_MAX_SIZE },
@@ -865,8 +864,10 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
865 NL_SET_ERR_MSG(extack, "TC action kind must be specified"); 864 NL_SET_ERR_MSG(extack, "TC action kind must be specified");
866 goto err_out; 865 goto err_out;
867 } 866 }
868 nla_strlcpy(act_name, kind, IFNAMSIZ); 867 if (nla_strlcpy(act_name, kind, IFNAMSIZ) >= IFNAMSIZ) {
869 868 NL_SET_ERR_MSG(extack, "TC action name too long");
869 goto err_out;
870 }
870 if (tb[TCA_ACT_COOKIE]) { 871 if (tb[TCA_ACT_COOKIE]) {
871 cookie = nla_memdup_cookie(tb); 872 cookie = nla_memdup_cookie(tb);
872 if (!cookie) { 873 if (!cookie) {
@@ -1352,11 +1353,16 @@ static int tcf_action_add(struct net *net, struct nlattr *nla,
1352 struct netlink_ext_ack *extack) 1353 struct netlink_ext_ack *extack)
1353{ 1354{
1354 size_t attr_size = 0; 1355 size_t attr_size = 0;
1355 int ret = 0; 1356 int loop, ret;
1356 struct tc_action *actions[TCA_ACT_MAX_PRIO] = {}; 1357 struct tc_action *actions[TCA_ACT_MAX_PRIO] = {};
1357 1358
1358 ret = tcf_action_init(net, NULL, nla, NULL, NULL, ovr, 0, actions, 1359 for (loop = 0; loop < 10; loop++) {
1359 &attr_size, true, extack); 1360 ret = tcf_action_init(net, NULL, nla, NULL, NULL, ovr, 0,
1361 actions, &attr_size, true, extack);
1362 if (ret != -EAGAIN)
1363 break;
1364 }
1365
1360 if (ret < 0) 1366 if (ret < 0)
1361 return ret; 1367 return ret;
1362 ret = tcf_add_notify(net, n, actions, portid, attr_size, extack); 1368 ret = tcf_add_notify(net, n, actions, portid, attr_size, extack);
@@ -1406,11 +1412,8 @@ static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n,
1406 */ 1412 */
1407 if (n->nlmsg_flags & NLM_F_REPLACE) 1413 if (n->nlmsg_flags & NLM_F_REPLACE)
1408 ovr = 1; 1414 ovr = 1;
1409replay:
1410 ret = tcf_action_add(net, tca[TCA_ACT_TAB], n, portid, ovr, 1415 ret = tcf_action_add(net, tca[TCA_ACT_TAB], n, portid, ovr,
1411 extack); 1416 extack);
1412 if (ret == -EAGAIN)
1413 goto replay;
1414 break; 1417 break;
1415 case RTM_DELACTION: 1418 case RTM_DELACTION:
1416 ret = tca_action_gd(net, tca[TCA_ACT_TAB], n, 1419 ret = tca_action_gd(net, tca[TCA_ACT_TAB], n,
diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c
index 9ce073a05414..08923b21e566 100644
--- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -484,7 +484,11 @@ static int __init mirred_init_module(void)
484 return err; 484 return err;
485 485
486 pr_info("Mirror/redirect action on\n"); 486 pr_info("Mirror/redirect action on\n");
487 return tcf_register_action(&act_mirred_ops, &mirred_net_ops); 487 err = tcf_register_action(&act_mirred_ops, &mirred_net_ops);
488 if (err)
489 unregister_netdevice_notifier(&mirred_device_notifier);
490
491 return err;
488} 492}
489 493
490static void __exit mirred_cleanup_module(void) 494static void __exit mirred_cleanup_module(void)
diff --git a/net/sched/act_mpls.c b/net/sched/act_mpls.c
index e168df0e008a..4cf6c553bb0b 100644
--- a/net/sched/act_mpls.c
+++ b/net/sched/act_mpls.c
@@ -55,7 +55,7 @@ static int tcf_mpls_act(struct sk_buff *skb, const struct tc_action *a,
55 struct tcf_mpls *m = to_mpls(a); 55 struct tcf_mpls *m = to_mpls(a);
56 struct tcf_mpls_params *p; 56 struct tcf_mpls_params *p;
57 __be32 new_lse; 57 __be32 new_lse;
58 int ret; 58 int ret, mac_len;
59 59
60 tcf_lastuse_update(&m->tcf_tm); 60 tcf_lastuse_update(&m->tcf_tm);
61 bstats_cpu_update(this_cpu_ptr(m->common.cpu_bstats), skb); 61 bstats_cpu_update(this_cpu_ptr(m->common.cpu_bstats), skb);
@@ -63,8 +63,12 @@ static int tcf_mpls_act(struct sk_buff *skb, const struct tc_action *a,
63 /* Ensure 'data' points at mac_header prior calling mpls manipulating 63 /* Ensure 'data' points at mac_header prior calling mpls manipulating
64 * functions. 64 * functions.
65 */ 65 */
66 if (skb_at_tc_ingress(skb)) 66 if (skb_at_tc_ingress(skb)) {
67 skb_push_rcsum(skb, skb->mac_len); 67 skb_push_rcsum(skb, skb->mac_len);
68 mac_len = skb->mac_len;
69 } else {
70 mac_len = skb_network_header(skb) - skb_mac_header(skb);
71 }
68 72
69 ret = READ_ONCE(m->tcf_action); 73 ret = READ_ONCE(m->tcf_action);
70 74
@@ -72,12 +76,12 @@ static int tcf_mpls_act(struct sk_buff *skb, const struct tc_action *a,
72 76
73 switch (p->tcfm_action) { 77 switch (p->tcfm_action) {
74 case TCA_MPLS_ACT_POP: 78 case TCA_MPLS_ACT_POP:
75 if (skb_mpls_pop(skb, p->tcfm_proto)) 79 if (skb_mpls_pop(skb, p->tcfm_proto, mac_len))
76 goto drop; 80 goto drop;
77 break; 81 break;
78 case TCA_MPLS_ACT_PUSH: 82 case TCA_MPLS_ACT_PUSH:
79 new_lse = tcf_mpls_get_lse(NULL, p, !eth_p_mpls(skb->protocol)); 83 new_lse = tcf_mpls_get_lse(NULL, p, !eth_p_mpls(skb->protocol));
80 if (skb_mpls_push(skb, new_lse, p->tcfm_proto)) 84 if (skb_mpls_push(skb, new_lse, p->tcfm_proto, mac_len))
81 goto drop; 85 goto drop;
82 break; 86 break;
83 case TCA_MPLS_ACT_MODIFY: 87 case TCA_MPLS_ACT_MODIFY:
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 64584a1df425..8717c0b26c90 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -162,11 +162,22 @@ static inline u32 tcf_auto_prio(struct tcf_proto *tp)
162 return TC_H_MAJ(first); 162 return TC_H_MAJ(first);
163} 163}
164 164
165static bool tcf_proto_check_kind(struct nlattr *kind, char *name)
166{
167 if (kind)
168 return nla_strlcpy(name, kind, IFNAMSIZ) >= IFNAMSIZ;
169 memset(name, 0, IFNAMSIZ);
170 return false;
171}
172
165static bool tcf_proto_is_unlocked(const char *kind) 173static bool tcf_proto_is_unlocked(const char *kind)
166{ 174{
167 const struct tcf_proto_ops *ops; 175 const struct tcf_proto_ops *ops;
168 bool ret; 176 bool ret;
169 177
178 if (strlen(kind) == 0)
179 return false;
180
170 ops = tcf_proto_lookup_ops(kind, false, NULL); 181 ops = tcf_proto_lookup_ops(kind, false, NULL);
171 /* On error return false to take rtnl lock. Proto lookup/create 182 /* On error return false to take rtnl lock. Proto lookup/create
172 * functions will perform lookup again and properly handle errors. 183 * functions will perform lookup again and properly handle errors.
@@ -1843,6 +1854,7 @@ static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
1843{ 1854{
1844 struct net *net = sock_net(skb->sk); 1855 struct net *net = sock_net(skb->sk);
1845 struct nlattr *tca[TCA_MAX + 1]; 1856 struct nlattr *tca[TCA_MAX + 1];
1857 char name[IFNAMSIZ];
1846 struct tcmsg *t; 1858 struct tcmsg *t;
1847 u32 protocol; 1859 u32 protocol;
1848 u32 prio; 1860 u32 prio;
@@ -1899,13 +1911,19 @@ replay:
1899 if (err) 1911 if (err)
1900 return err; 1912 return err;
1901 1913
1914 if (tcf_proto_check_kind(tca[TCA_KIND], name)) {
1915 NL_SET_ERR_MSG(extack, "Specified TC filter name too long");
1916 err = -EINVAL;
1917 goto errout;
1918 }
1919
1902 /* Take rtnl mutex if rtnl_held was set to true on previous iteration, 1920 /* Take rtnl mutex if rtnl_held was set to true on previous iteration,
1903 * block is shared (no qdisc found), qdisc is not unlocked, classifier 1921 * block is shared (no qdisc found), qdisc is not unlocked, classifier
1904 * type is not specified, classifier is not unlocked. 1922 * type is not specified, classifier is not unlocked.
1905 */ 1923 */
1906 if (rtnl_held || 1924 if (rtnl_held ||
1907 (q && !(q->ops->cl_ops->flags & QDISC_CLASS_OPS_DOIT_UNLOCKED)) || 1925 (q && !(q->ops->cl_ops->flags & QDISC_CLASS_OPS_DOIT_UNLOCKED)) ||
1908 !tca[TCA_KIND] || !tcf_proto_is_unlocked(nla_data(tca[TCA_KIND]))) { 1926 !tcf_proto_is_unlocked(name)) {
1909 rtnl_held = true; 1927 rtnl_held = true;
1910 rtnl_lock(); 1928 rtnl_lock();
1911 } 1929 }
@@ -2063,6 +2081,7 @@ static int tc_del_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
2063{ 2081{
2064 struct net *net = sock_net(skb->sk); 2082 struct net *net = sock_net(skb->sk);
2065 struct nlattr *tca[TCA_MAX + 1]; 2083 struct nlattr *tca[TCA_MAX + 1];
2084 char name[IFNAMSIZ];
2066 struct tcmsg *t; 2085 struct tcmsg *t;
2067 u32 protocol; 2086 u32 protocol;
2068 u32 prio; 2087 u32 prio;
@@ -2102,13 +2121,18 @@ static int tc_del_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
2102 if (err) 2121 if (err)
2103 return err; 2122 return err;
2104 2123
2124 if (tcf_proto_check_kind(tca[TCA_KIND], name)) {
2125 NL_SET_ERR_MSG(extack, "Specified TC filter name too long");
2126 err = -EINVAL;
2127 goto errout;
2128 }
2105 /* Take rtnl mutex if flushing whole chain, block is shared (no qdisc 2129 /* Take rtnl mutex if flushing whole chain, block is shared (no qdisc
2106 * found), qdisc is not unlocked, classifier type is not specified, 2130 * found), qdisc is not unlocked, classifier type is not specified,
2107 * classifier is not unlocked. 2131 * classifier is not unlocked.
2108 */ 2132 */
2109 if (!prio || 2133 if (!prio ||
2110 (q && !(q->ops->cl_ops->flags & QDISC_CLASS_OPS_DOIT_UNLOCKED)) || 2134 (q && !(q->ops->cl_ops->flags & QDISC_CLASS_OPS_DOIT_UNLOCKED)) ||
2111 !tca[TCA_KIND] || !tcf_proto_is_unlocked(nla_data(tca[TCA_KIND]))) { 2135 !tcf_proto_is_unlocked(name)) {
2112 rtnl_held = true; 2136 rtnl_held = true;
2113 rtnl_lock(); 2137 rtnl_lock();
2114 } 2138 }
@@ -2216,6 +2240,7 @@ static int tc_get_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
2216{ 2240{
2217 struct net *net = sock_net(skb->sk); 2241 struct net *net = sock_net(skb->sk);
2218 struct nlattr *tca[TCA_MAX + 1]; 2242 struct nlattr *tca[TCA_MAX + 1];
2243 char name[IFNAMSIZ];
2219 struct tcmsg *t; 2244 struct tcmsg *t;
2220 u32 protocol; 2245 u32 protocol;
2221 u32 prio; 2246 u32 prio;
@@ -2252,12 +2277,17 @@ static int tc_get_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
2252 if (err) 2277 if (err)
2253 return err; 2278 return err;
2254 2279
2280 if (tcf_proto_check_kind(tca[TCA_KIND], name)) {
2281 NL_SET_ERR_MSG(extack, "Specified TC filter name too long");
2282 err = -EINVAL;
2283 goto errout;
2284 }
2255 /* Take rtnl mutex if block is shared (no qdisc found), qdisc is not 2285 /* Take rtnl mutex if block is shared (no qdisc found), qdisc is not
2256 * unlocked, classifier type is not specified, classifier is not 2286 * unlocked, classifier type is not specified, classifier is not
2257 * unlocked. 2287 * unlocked.
2258 */ 2288 */
2259 if ((q && !(q->ops->cl_ops->flags & QDISC_CLASS_OPS_DOIT_UNLOCKED)) || 2289 if ((q && !(q->ops->cl_ops->flags & QDISC_CLASS_OPS_DOIT_UNLOCKED)) ||
2260 !tca[TCA_KIND] || !tcf_proto_is_unlocked(nla_data(tca[TCA_KIND]))) { 2290 !tcf_proto_is_unlocked(name)) {
2261 rtnl_held = true; 2291 rtnl_held = true;
2262 rtnl_lock(); 2292 rtnl_lock();
2263 } 2293 }
diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c
index 82bd14e7ac93..3177dcb17316 100644
--- a/net/sched/em_meta.c
+++ b/net/sched/em_meta.c
@@ -446,7 +446,7 @@ META_COLLECTOR(int_sk_wmem_queued)
446 *err = -1; 446 *err = -1;
447 return; 447 return;
448 } 448 }
449 dst->value = sk->sk_wmem_queued; 449 dst->value = READ_ONCE(sk->sk_wmem_queued);
450} 450}
451 451
452META_COLLECTOR(int_sk_fwd_alloc) 452META_COLLECTOR(int_sk_fwd_alloc)
@@ -554,7 +554,7 @@ META_COLLECTOR(int_sk_rcvlowat)
554 *err = -1; 554 *err = -1;
555 return; 555 return;
556 } 556 }
557 dst->value = sk->sk_rcvlowat; 557 dst->value = READ_ONCE(sk->sk_rcvlowat);
558} 558}
559 559
560META_COLLECTOR(int_sk_rcvtimeo) 560META_COLLECTOR(int_sk_rcvtimeo)
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 81d58b280612..1047825d9f48 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -1390,8 +1390,7 @@ check_loop_fn(struct Qdisc *q, unsigned long cl, struct qdisc_walker *w)
1390} 1390}
1391 1391
1392const struct nla_policy rtm_tca_policy[TCA_MAX + 1] = { 1392const struct nla_policy rtm_tca_policy[TCA_MAX + 1] = {
1393 [TCA_KIND] = { .type = NLA_NUL_STRING, 1393 [TCA_KIND] = { .type = NLA_STRING },
1394 .len = IFNAMSIZ - 1 },
1395 [TCA_RATE] = { .type = NLA_BINARY, 1394 [TCA_RATE] = { .type = NLA_BINARY,
1396 .len = sizeof(struct tc_estimator) }, 1395 .len = sizeof(struct tc_estimator) },
1397 [TCA_STAB] = { .type = NLA_NESTED }, 1396 [TCA_STAB] = { .type = NLA_NESTED },
diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c
index 06c7a2da21bc..39b427dc7512 100644
--- a/net/sched/sch_cbq.c
+++ b/net/sched/sch_cbq.c
@@ -1127,6 +1127,33 @@ static const struct nla_policy cbq_policy[TCA_CBQ_MAX + 1] = {
1127 [TCA_CBQ_POLICE] = { .len = sizeof(struct tc_cbq_police) }, 1127 [TCA_CBQ_POLICE] = { .len = sizeof(struct tc_cbq_police) },
1128}; 1128};
1129 1129
1130static int cbq_opt_parse(struct nlattr *tb[TCA_CBQ_MAX + 1],
1131 struct nlattr *opt,
1132 struct netlink_ext_ack *extack)
1133{
1134 int err;
1135
1136 if (!opt) {
1137 NL_SET_ERR_MSG(extack, "CBQ options are required for this operation");
1138 return -EINVAL;
1139 }
1140
1141 err = nla_parse_nested_deprecated(tb, TCA_CBQ_MAX, opt,
1142 cbq_policy, extack);
1143 if (err < 0)
1144 return err;
1145
1146 if (tb[TCA_CBQ_WRROPT]) {
1147 const struct tc_cbq_wrropt *wrr = nla_data(tb[TCA_CBQ_WRROPT]);
1148
1149 if (wrr->priority > TC_CBQ_MAXPRIO) {
1150 NL_SET_ERR_MSG(extack, "priority is bigger than TC_CBQ_MAXPRIO");
1151 err = -EINVAL;
1152 }
1153 }
1154 return err;
1155}
1156
1130static int cbq_init(struct Qdisc *sch, struct nlattr *opt, 1157static int cbq_init(struct Qdisc *sch, struct nlattr *opt,
1131 struct netlink_ext_ack *extack) 1158 struct netlink_ext_ack *extack)
1132{ 1159{
@@ -1139,13 +1166,7 @@ static int cbq_init(struct Qdisc *sch, struct nlattr *opt,
1139 hrtimer_init(&q->delay_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_PINNED); 1166 hrtimer_init(&q->delay_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_PINNED);
1140 q->delay_timer.function = cbq_undelay; 1167 q->delay_timer.function = cbq_undelay;
1141 1168
1142 if (!opt) { 1169 err = cbq_opt_parse(tb, opt, extack);
1143 NL_SET_ERR_MSG(extack, "CBQ options are required for this operation");
1144 return -EINVAL;
1145 }
1146
1147 err = nla_parse_nested_deprecated(tb, TCA_CBQ_MAX, opt, cbq_policy,
1148 extack);
1149 if (err < 0) 1170 if (err < 0)
1150 return err; 1171 return err;
1151 1172
@@ -1464,13 +1485,7 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t
1464 struct cbq_class *parent; 1485 struct cbq_class *parent;
1465 struct qdisc_rate_table *rtab = NULL; 1486 struct qdisc_rate_table *rtab = NULL;
1466 1487
1467 if (!opt) { 1488 err = cbq_opt_parse(tb, opt, extack);
1468 NL_SET_ERR_MSG(extack, "Mandatory qdisc options missing");
1469 return -EINVAL;
1470 }
1471
1472 err = nla_parse_nested_deprecated(tb, TCA_CBQ_MAX, opt, cbq_policy,
1473 extack);
1474 if (err < 0) 1489 if (err < 0)
1475 return err; 1490 return err;
1476 1491
diff --git a/net/sched/sch_cbs.c b/net/sched/sch_cbs.c
index 1bef152c5721..b2905b03a432 100644
--- a/net/sched/sch_cbs.c
+++ b/net/sched/sch_cbs.c
@@ -306,7 +306,7 @@ static void cbs_set_port_rate(struct net_device *dev, struct cbs_sched_data *q)
306 if (err < 0) 306 if (err < 0)
307 goto skip; 307 goto skip;
308 308
309 if (ecmd.base.speed != SPEED_UNKNOWN) 309 if (ecmd.base.speed && ecmd.base.speed != SPEED_UNKNOWN)
310 speed = ecmd.base.speed; 310 speed = ecmd.base.speed;
311 311
312skip: 312skip:
diff --git a/net/sched/sch_dsmark.c b/net/sched/sch_dsmark.c
index bad1cbe59a56..05605b30bef3 100644
--- a/net/sched/sch_dsmark.c
+++ b/net/sched/sch_dsmark.c
@@ -361,6 +361,8 @@ static int dsmark_init(struct Qdisc *sch, struct nlattr *opt,
361 goto errout; 361 goto errout;
362 362
363 err = -EINVAL; 363 err = -EINVAL;
364 if (!tb[TCA_DSMARK_INDICES])
365 goto errout;
364 indices = nla_get_u16(tb[TCA_DSMARK_INDICES]); 366 indices = nla_get_u16(tb[TCA_DSMARK_INDICES]);
365 367
366 if (hweight32(indices) != 1) 368 if (hweight32(indices) != 1)
diff --git a/net/sched/sch_etf.c b/net/sched/sch_etf.c
index cebfb65d8556..b1da5589a0c6 100644
--- a/net/sched/sch_etf.c
+++ b/net/sched/sch_etf.c
@@ -177,7 +177,7 @@ static int etf_enqueue_timesortedlist(struct sk_buff *nskb, struct Qdisc *sch,
177 177
178 parent = *p; 178 parent = *p;
179 skb = rb_to_skb(parent); 179 skb = rb_to_skb(parent);
180 if (ktime_after(txtime, skb->tstamp)) { 180 if (ktime_compare(txtime, skb->tstamp) >= 0) {
181 p = &parent->rb_right; 181 p = &parent->rb_right;
182 leftmost = false; 182 leftmost = false;
183 } else { 183 } else {
diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
index 17bd8f539bc7..8769b4b8807d 100644
--- a/net/sched/sch_generic.c
+++ b/net/sched/sch_generic.c
@@ -799,9 +799,6 @@ struct Qdisc_ops pfifo_fast_ops __read_mostly = {
799}; 799};
800EXPORT_SYMBOL(pfifo_fast_ops); 800EXPORT_SYMBOL(pfifo_fast_ops);
801 801
802static struct lock_class_key qdisc_tx_busylock;
803static struct lock_class_key qdisc_running_key;
804
805struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue, 802struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
806 const struct Qdisc_ops *ops, 803 const struct Qdisc_ops *ops,
807 struct netlink_ext_ack *extack) 804 struct netlink_ext_ack *extack)
@@ -854,17 +851,9 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
854 } 851 }
855 852
856 spin_lock_init(&sch->busylock); 853 spin_lock_init(&sch->busylock);
857 lockdep_set_class(&sch->busylock,
858 dev->qdisc_tx_busylock ?: &qdisc_tx_busylock);
859
860 /* seqlock has the same scope of busylock, for NOLOCK qdisc */ 854 /* seqlock has the same scope of busylock, for NOLOCK qdisc */
861 spin_lock_init(&sch->seqlock); 855 spin_lock_init(&sch->seqlock);
862 lockdep_set_class(&sch->busylock,
863 dev->qdisc_tx_busylock ?: &qdisc_tx_busylock);
864
865 seqcount_init(&sch->running); 856 seqcount_init(&sch->running);
866 lockdep_set_class(&sch->running,
867 dev->qdisc_running_key ?: &qdisc_running_key);
868 857
869 sch->ops = ops; 858 sch->ops = ops;
870 sch->flags = ops->static_flags; 859 sch->flags = ops->static_flags;
@@ -875,6 +864,12 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
875 dev_hold(dev); 864 dev_hold(dev);
876 refcount_set(&sch->refcnt, 1); 865 refcount_set(&sch->refcnt, 1);
877 866
867 if (sch != &noop_qdisc) {
868 lockdep_set_class(&sch->busylock, &dev->qdisc_tx_busylock_key);
869 lockdep_set_class(&sch->seqlock, &dev->qdisc_tx_busylock_key);
870 lockdep_set_class(&sch->running, &dev->qdisc_running_key);
871 }
872
878 return sch; 873 return sch;
879errout1: 874errout1:
880 kfree(p); 875 kfree(p);
@@ -1043,6 +1038,8 @@ static void attach_one_default_qdisc(struct net_device *dev,
1043 1038
1044 if (dev->priv_flags & IFF_NO_QUEUE) 1039 if (dev->priv_flags & IFF_NO_QUEUE)
1045 ops = &noqueue_qdisc_ops; 1040 ops = &noqueue_qdisc_ops;
1041 else if(dev->type == ARPHRD_CAN)
1042 ops = &pfifo_fast_ops;
1046 1043
1047 qdisc = qdisc_create_dflt(dev_queue, ops, TC_H_ROOT, NULL); 1044 qdisc = qdisc_create_dflt(dev_queue, ops, TC_H_ROOT, NULL);
1048 if (!qdisc) { 1045 if (!qdisc) {
diff --git a/net/sched/sch_hhf.c b/net/sched/sch_hhf.c
index 23cd1c873a2c..be35f03b657b 100644
--- a/net/sched/sch_hhf.c
+++ b/net/sched/sch_hhf.c
@@ -5,11 +5,11 @@
5 * Copyright (C) 2013 Nandita Dukkipati <nanditad@google.com> 5 * Copyright (C) 2013 Nandita Dukkipati <nanditad@google.com>
6 */ 6 */
7 7
8#include <linux/jhash.h>
9#include <linux/jiffies.h> 8#include <linux/jiffies.h>
10#include <linux/module.h> 9#include <linux/module.h>
11#include <linux/skbuff.h> 10#include <linux/skbuff.h>
12#include <linux/vmalloc.h> 11#include <linux/vmalloc.h>
12#include <linux/siphash.h>
13#include <net/pkt_sched.h> 13#include <net/pkt_sched.h>
14#include <net/sock.h> 14#include <net/sock.h>
15 15
@@ -126,7 +126,7 @@ struct wdrr_bucket {
126 126
127struct hhf_sched_data { 127struct hhf_sched_data {
128 struct wdrr_bucket buckets[WDRR_BUCKET_CNT]; 128 struct wdrr_bucket buckets[WDRR_BUCKET_CNT];
129 u32 perturbation; /* hash perturbation */ 129 siphash_key_t perturbation; /* hash perturbation */
130 u32 quantum; /* psched_mtu(qdisc_dev(sch)); */ 130 u32 quantum; /* psched_mtu(qdisc_dev(sch)); */
131 u32 drop_overlimit; /* number of times max qdisc packet 131 u32 drop_overlimit; /* number of times max qdisc packet
132 * limit was hit 132 * limit was hit
@@ -264,7 +264,7 @@ static enum wdrr_bucket_idx hhf_classify(struct sk_buff *skb, struct Qdisc *sch)
264 } 264 }
265 265
266 /* Get hashed flow-id of the skb. */ 266 /* Get hashed flow-id of the skb. */
267 hash = skb_get_hash_perturb(skb, q->perturbation); 267 hash = skb_get_hash_perturb(skb, &q->perturbation);
268 268
269 /* Check if this packet belongs to an already established HH flow. */ 269 /* Check if this packet belongs to an already established HH flow. */
270 flow_pos = hash & HHF_BIT_MASK; 270 flow_pos = hash & HHF_BIT_MASK;
@@ -582,7 +582,7 @@ static int hhf_init(struct Qdisc *sch, struct nlattr *opt,
582 582
583 sch->limit = 1000; 583 sch->limit = 1000;
584 q->quantum = psched_mtu(qdisc_dev(sch)); 584 q->quantum = psched_mtu(qdisc_dev(sch));
585 q->perturbation = prandom_u32(); 585 get_random_bytes(&q->perturbation, sizeof(q->perturbation));
586 INIT_LIST_HEAD(&q->new_buckets); 586 INIT_LIST_HEAD(&q->new_buckets);
587 INIT_LIST_HEAD(&q->old_buckets); 587 INIT_LIST_HEAD(&q->old_buckets);
588 588
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index 0e44039e729c..42e557d48e4e 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -509,6 +509,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
509 if (skb->ip_summed == CHECKSUM_PARTIAL && 509 if (skb->ip_summed == CHECKSUM_PARTIAL &&
510 skb_checksum_help(skb)) { 510 skb_checksum_help(skb)) {
511 qdisc_drop(skb, sch, to_free); 511 qdisc_drop(skb, sch, to_free);
512 skb = NULL;
512 goto finish_segs; 513 goto finish_segs;
513 } 514 }
514 515
@@ -593,9 +594,10 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
593finish_segs: 594finish_segs:
594 if (segs) { 595 if (segs) {
595 unsigned int len, last_len; 596 unsigned int len, last_len;
596 int nb = 0; 597 int nb;
597 598
598 len = skb->len; 599 len = skb ? skb->len : 0;
600 nb = skb ? 1 : 0;
599 601
600 while (segs) { 602 while (segs) {
601 skb2 = segs->next; 603 skb2 = segs->next;
@@ -612,7 +614,10 @@ finish_segs:
612 } 614 }
613 segs = skb2; 615 segs = skb2;
614 } 616 }
615 qdisc_tree_reduce_backlog(sch, -nb, prev_len - len); 617 /* Parent qdiscs accounted for 1 skb of size @prev_len */
618 qdisc_tree_reduce_backlog(sch, -(nb - 1), -(len - prev_len));
619 } else if (!skb) {
620 return NET_XMIT_DROP;
616 } 621 }
617 return NET_XMIT_SUCCESS; 622 return NET_XMIT_SUCCESS;
618} 623}
diff --git a/net/sched/sch_sfb.c b/net/sched/sch_sfb.c
index d448fe3068e5..4074c50ac3d7 100644
--- a/net/sched/sch_sfb.c
+++ b/net/sched/sch_sfb.c
@@ -18,7 +18,7 @@
18#include <linux/errno.h> 18#include <linux/errno.h>
19#include <linux/skbuff.h> 19#include <linux/skbuff.h>
20#include <linux/random.h> 20#include <linux/random.h>
21#include <linux/jhash.h> 21#include <linux/siphash.h>
22#include <net/ip.h> 22#include <net/ip.h>
23#include <net/pkt_sched.h> 23#include <net/pkt_sched.h>
24#include <net/pkt_cls.h> 24#include <net/pkt_cls.h>
@@ -45,7 +45,7 @@ struct sfb_bucket {
45 * (Section 4.4 of SFB reference : moving hash functions) 45 * (Section 4.4 of SFB reference : moving hash functions)
46 */ 46 */
47struct sfb_bins { 47struct sfb_bins {
48 u32 perturbation; /* jhash perturbation */ 48 siphash_key_t perturbation; /* siphash key */
49 struct sfb_bucket bins[SFB_LEVELS][SFB_NUMBUCKETS]; 49 struct sfb_bucket bins[SFB_LEVELS][SFB_NUMBUCKETS];
50}; 50};
51 51
@@ -217,7 +217,8 @@ static u32 sfb_compute_qlen(u32 *prob_r, u32 *avgpm_r, const struct sfb_sched_da
217 217
218static void sfb_init_perturbation(u32 slot, struct sfb_sched_data *q) 218static void sfb_init_perturbation(u32 slot, struct sfb_sched_data *q)
219{ 219{
220 q->bins[slot].perturbation = prandom_u32(); 220 get_random_bytes(&q->bins[slot].perturbation,
221 sizeof(q->bins[slot].perturbation));
221} 222}
222 223
223static void sfb_swap_slot(struct sfb_sched_data *q) 224static void sfb_swap_slot(struct sfb_sched_data *q)
@@ -314,9 +315,9 @@ static int sfb_enqueue(struct sk_buff *skb, struct Qdisc *sch,
314 /* If using external classifiers, get result and record it. */ 315 /* If using external classifiers, get result and record it. */
315 if (!sfb_classify(skb, fl, &ret, &salt)) 316 if (!sfb_classify(skb, fl, &ret, &salt))
316 goto other_drop; 317 goto other_drop;
317 sfbhash = jhash_1word(salt, q->bins[slot].perturbation); 318 sfbhash = siphash_1u32(salt, &q->bins[slot].perturbation);
318 } else { 319 } else {
319 sfbhash = skb_get_hash_perturb(skb, q->bins[slot].perturbation); 320 sfbhash = skb_get_hash_perturb(skb, &q->bins[slot].perturbation);
320 } 321 }
321 322
322 323
@@ -352,7 +353,7 @@ static int sfb_enqueue(struct sk_buff *skb, struct Qdisc *sch,
352 /* Inelastic flow */ 353 /* Inelastic flow */
353 if (q->double_buffering) { 354 if (q->double_buffering) {
354 sfbhash = skb_get_hash_perturb(skb, 355 sfbhash = skb_get_hash_perturb(skb,
355 q->bins[slot].perturbation); 356 &q->bins[slot].perturbation);
356 if (!sfbhash) 357 if (!sfbhash)
357 sfbhash = 1; 358 sfbhash = 1;
358 sfb_skb_cb(skb)->hashes[slot] = sfbhash; 359 sfb_skb_cb(skb)->hashes[slot] = sfbhash;
diff --git a/net/sched/sch_sfq.c b/net/sched/sch_sfq.c
index 68404a9d2ce4..c787d4d46017 100644
--- a/net/sched/sch_sfq.c
+++ b/net/sched/sch_sfq.c
@@ -14,7 +14,7 @@
14#include <linux/errno.h> 14#include <linux/errno.h>
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/skbuff.h> 16#include <linux/skbuff.h>
17#include <linux/jhash.h> 17#include <linux/siphash.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/vmalloc.h> 19#include <linux/vmalloc.h>
20#include <net/netlink.h> 20#include <net/netlink.h>
@@ -117,7 +117,7 @@ struct sfq_sched_data {
117 u8 headdrop; 117 u8 headdrop;
118 u8 maxdepth; /* limit of packets per flow */ 118 u8 maxdepth; /* limit of packets per flow */
119 119
120 u32 perturbation; 120 siphash_key_t perturbation;
121 u8 cur_depth; /* depth of longest slot */ 121 u8 cur_depth; /* depth of longest slot */
122 u8 flags; 122 u8 flags;
123 unsigned short scaled_quantum; /* SFQ_ALLOT_SIZE(quantum) */ 123 unsigned short scaled_quantum; /* SFQ_ALLOT_SIZE(quantum) */
@@ -157,7 +157,7 @@ static inline struct sfq_head *sfq_dep_head(struct sfq_sched_data *q, sfq_index
157static unsigned int sfq_hash(const struct sfq_sched_data *q, 157static unsigned int sfq_hash(const struct sfq_sched_data *q,
158 const struct sk_buff *skb) 158 const struct sk_buff *skb)
159{ 159{
160 return skb_get_hash_perturb(skb, q->perturbation) & (q->divisor - 1); 160 return skb_get_hash_perturb(skb, &q->perturbation) & (q->divisor - 1);
161} 161}
162 162
163static unsigned int sfq_classify(struct sk_buff *skb, struct Qdisc *sch, 163static unsigned int sfq_classify(struct sk_buff *skb, struct Qdisc *sch,
@@ -607,9 +607,11 @@ static void sfq_perturbation(struct timer_list *t)
607 struct sfq_sched_data *q = from_timer(q, t, perturb_timer); 607 struct sfq_sched_data *q = from_timer(q, t, perturb_timer);
608 struct Qdisc *sch = q->sch; 608 struct Qdisc *sch = q->sch;
609 spinlock_t *root_lock = qdisc_lock(qdisc_root_sleeping(sch)); 609 spinlock_t *root_lock = qdisc_lock(qdisc_root_sleeping(sch));
610 siphash_key_t nkey;
610 611
612 get_random_bytes(&nkey, sizeof(nkey));
611 spin_lock(root_lock); 613 spin_lock(root_lock);
612 q->perturbation = prandom_u32(); 614 q->perturbation = nkey;
613 if (!q->filter_list && q->tail) 615 if (!q->filter_list && q->tail)
614 sfq_rehash(sch); 616 sfq_rehash(sch);
615 spin_unlock(root_lock); 617 spin_unlock(root_lock);
@@ -688,7 +690,7 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt)
688 del_timer(&q->perturb_timer); 690 del_timer(&q->perturb_timer);
689 if (q->perturb_period) { 691 if (q->perturb_period) {
690 mod_timer(&q->perturb_timer, jiffies + q->perturb_period); 692 mod_timer(&q->perturb_timer, jiffies + q->perturb_period);
691 q->perturbation = prandom_u32(); 693 get_random_bytes(&q->perturbation, sizeof(q->perturbation));
692 } 694 }
693 sch_tree_unlock(sch); 695 sch_tree_unlock(sch);
694 kfree(p); 696 kfree(p);
@@ -745,7 +747,7 @@ static int sfq_init(struct Qdisc *sch, struct nlattr *opt,
745 q->quantum = psched_mtu(qdisc_dev(sch)); 747 q->quantum = psched_mtu(qdisc_dev(sch));
746 q->scaled_quantum = SFQ_ALLOT_SIZE(q->quantum); 748 q->scaled_quantum = SFQ_ALLOT_SIZE(q->quantum);
747 q->perturb_period = 0; 749 q->perturb_period = 0;
748 q->perturbation = prandom_u32(); 750 get_random_bytes(&q->perturbation, sizeof(q->perturbation));
749 751
750 if (opt) { 752 if (opt) {
751 int err = sfq_change(sch, opt); 753 int err = sfq_change(sch, opt);
diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
index 2f7b34205c82..2121187229cd 100644
--- a/net/sched/sch_taprio.c
+++ b/net/sched/sch_taprio.c
@@ -1044,12 +1044,11 @@ static void taprio_set_picos_per_byte(struct net_device *dev,
1044 if (err < 0) 1044 if (err < 0)
1045 goto skip; 1045 goto skip;
1046 1046
1047 if (ecmd.base.speed != SPEED_UNKNOWN) 1047 if (ecmd.base.speed && ecmd.base.speed != SPEED_UNKNOWN)
1048 speed = ecmd.base.speed; 1048 speed = ecmd.base.speed;
1049 1049
1050skip: 1050skip:
1051 picos_per_byte = div64_s64(NSEC_PER_SEC * 1000LL * 8, 1051 picos_per_byte = (USEC_PER_SEC * 8) / speed;
1052 speed * 1000 * 1000);
1053 1052
1054 atomic64_set(&q->picos_per_byte, picos_per_byte); 1053 atomic64_set(&q->picos_per_byte, picos_per_byte);
1055 netdev_dbg(dev, "taprio: set %s's picos_per_byte to: %lld, linkspeed: %d\n", 1054 netdev_dbg(dev, "taprio: set %s's picos_per_byte to: %lld, linkspeed: %d\n",
@@ -1153,7 +1152,7 @@ EXPORT_SYMBOL_GPL(taprio_offload_free);
1153 * offload state (PENDING, ACTIVE, INACTIVE) so it can be visible in dump(). 1152 * offload state (PENDING, ACTIVE, INACTIVE) so it can be visible in dump().
1154 * This is left as TODO. 1153 * This is left as TODO.
1155 */ 1154 */
1156void taprio_offload_config_changed(struct taprio_sched *q) 1155static void taprio_offload_config_changed(struct taprio_sched *q)
1157{ 1156{
1158 struct sched_gate_list *oper, *admin; 1157 struct sched_gate_list *oper, *admin;
1159 1158
@@ -1342,6 +1341,10 @@ static int taprio_parse_clockid(struct Qdisc *sch, struct nlattr **tb,
1342 NL_SET_ERR_MSG(extack, "Specifying a 'clockid' is mandatory"); 1341 NL_SET_ERR_MSG(extack, "Specifying a 'clockid' is mandatory");
1343 goto out; 1342 goto out;
1344 } 1343 }
1344
1345 /* Everything went ok, return success. */
1346 err = 0;
1347
1345out: 1348out:
1346 return err; 1349 return err;
1347} 1350}
diff --git a/net/sctp/diag.c b/net/sctp/diag.c
index fc9a4c6629ce..0851166b9175 100644
--- a/net/sctp/diag.c
+++ b/net/sctp/diag.c
@@ -175,7 +175,7 @@ static int inet_sctp_diag_fill(struct sock *sk, struct sctp_association *asoc,
175 mem[SK_MEMINFO_FWD_ALLOC] = sk->sk_forward_alloc; 175 mem[SK_MEMINFO_FWD_ALLOC] = sk->sk_forward_alloc;
176 mem[SK_MEMINFO_WMEM_QUEUED] = sk->sk_wmem_queued; 176 mem[SK_MEMINFO_WMEM_QUEUED] = sk->sk_wmem_queued;
177 mem[SK_MEMINFO_OPTMEM] = atomic_read(&sk->sk_omem_alloc); 177 mem[SK_MEMINFO_OPTMEM] = atomic_read(&sk->sk_omem_alloc);
178 mem[SK_MEMINFO_BACKLOG] = sk->sk_backlog.len; 178 mem[SK_MEMINFO_BACKLOG] = READ_ONCE(sk->sk_backlog.len);
179 mem[SK_MEMINFO_DROPS] = atomic_read(&sk->sk_drops); 179 mem[SK_MEMINFO_DROPS] = atomic_read(&sk->sk_drops);
180 180
181 if (nla_put(skb, INET_DIAG_SKMEMINFO, sizeof(mem), &mem) < 0) 181 if (nla_put(skb, INET_DIAG_SKMEMINFO, sizeof(mem), &mem) < 0)
diff --git a/net/sctp/input.c b/net/sctp/input.c
index 1008cdc44dd6..2277981559d0 100644
--- a/net/sctp/input.c
+++ b/net/sctp/input.c
@@ -201,7 +201,7 @@ int sctp_rcv(struct sk_buff *skb)
201 201
202 if (!xfrm_policy_check(sk, XFRM_POLICY_IN, skb, family)) 202 if (!xfrm_policy_check(sk, XFRM_POLICY_IN, skb, family))
203 goto discard_release; 203 goto discard_release;
204 nf_reset(skb); 204 nf_reset_ct(skb);
205 205
206 if (sk_filter(sk, skb)) 206 if (sk_filter(sk, skb))
207 goto discard_release; 207 goto discard_release;
@@ -243,7 +243,7 @@ int sctp_rcv(struct sk_buff *skb)
243 bh_lock_sock(sk); 243 bh_lock_sock(sk);
244 } 244 }
245 245
246 if (sock_owned_by_user(sk)) { 246 if (sock_owned_by_user(sk) || !sctp_newsk_ready(sk)) {
247 if (sctp_add_backlog(sk, skb)) { 247 if (sctp_add_backlog(sk, skb)) {
248 bh_unlock_sock(sk); 248 bh_unlock_sock(sk);
249 sctp_chunk_free(chunk); 249 sctp_chunk_free(chunk);
@@ -321,8 +321,8 @@ int sctp_backlog_rcv(struct sock *sk, struct sk_buff *skb)
321 local_bh_disable(); 321 local_bh_disable();
322 bh_lock_sock(sk); 322 bh_lock_sock(sk);
323 323
324 if (sock_owned_by_user(sk)) { 324 if (sock_owned_by_user(sk) || !sctp_newsk_ready(sk)) {
325 if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) 325 if (sk_add_backlog(sk, skb, READ_ONCE(sk->sk_rcvbuf)))
326 sctp_chunk_free(chunk); 326 sctp_chunk_free(chunk);
327 else 327 else
328 backloged = 1; 328 backloged = 1;
@@ -336,7 +336,13 @@ int sctp_backlog_rcv(struct sock *sk, struct sk_buff *skb)
336 if (backloged) 336 if (backloged)
337 return 0; 337 return 0;
338 } else { 338 } else {
339 sctp_inq_push(inqueue, chunk); 339 if (!sctp_newsk_ready(sk)) {
340 if (!sk_add_backlog(sk, skb, READ_ONCE(sk->sk_rcvbuf)))
341 return 0;
342 sctp_chunk_free(chunk);
343 } else {
344 sctp_inq_push(inqueue, chunk);
345 }
340 } 346 }
341 347
342done: 348done:
@@ -358,7 +364,7 @@ static int sctp_add_backlog(struct sock *sk, struct sk_buff *skb)
358 struct sctp_ep_common *rcvr = chunk->rcvr; 364 struct sctp_ep_common *rcvr = chunk->rcvr;
359 int ret; 365 int ret;
360 366
361 ret = sk_add_backlog(sk, skb, sk->sk_rcvbuf); 367 ret = sk_add_backlog(sk, skb, READ_ONCE(sk->sk_rcvbuf));
362 if (!ret) { 368 if (!ret) {
363 /* Hold the assoc/ep while hanging on the backlog queue. 369 /* Hold the assoc/ep while hanging on the backlog queue.
364 * This way, we know structures we need will not disappear 370 * This way, we know structures we need will not disappear
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index e41ed2e0ae7d..48d63956a68c 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -2155,7 +2155,7 @@ static enum sctp_ierror sctp_verify_param(struct net *net,
2155 case SCTP_PARAM_SET_PRIMARY: 2155 case SCTP_PARAM_SET_PRIMARY:
2156 if (ep->asconf_enable) 2156 if (ep->asconf_enable)
2157 break; 2157 break;
2158 goto fallthrough; 2158 goto unhandled;
2159 2159
2160 case SCTP_PARAM_HOST_NAME_ADDRESS: 2160 case SCTP_PARAM_HOST_NAME_ADDRESS:
2161 /* Tell the peer, we won't support this param. */ 2161 /* Tell the peer, we won't support this param. */
@@ -2166,11 +2166,11 @@ static enum sctp_ierror sctp_verify_param(struct net *net,
2166 case SCTP_PARAM_FWD_TSN_SUPPORT: 2166 case SCTP_PARAM_FWD_TSN_SUPPORT:
2167 if (ep->prsctp_enable) 2167 if (ep->prsctp_enable)
2168 break; 2168 break;
2169 goto fallthrough; 2169 goto unhandled;
2170 2170
2171 case SCTP_PARAM_RANDOM: 2171 case SCTP_PARAM_RANDOM:
2172 if (!ep->auth_enable) 2172 if (!ep->auth_enable)
2173 goto fallthrough; 2173 goto unhandled;
2174 2174
2175 /* SCTP-AUTH: Secion 6.1 2175 /* SCTP-AUTH: Secion 6.1
2176 * If the random number is not 32 byte long the association 2176 * If the random number is not 32 byte long the association
@@ -2187,7 +2187,7 @@ static enum sctp_ierror sctp_verify_param(struct net *net,
2187 2187
2188 case SCTP_PARAM_CHUNKS: 2188 case SCTP_PARAM_CHUNKS:
2189 if (!ep->auth_enable) 2189 if (!ep->auth_enable)
2190 goto fallthrough; 2190 goto unhandled;
2191 2191
2192 /* SCTP-AUTH: Section 3.2 2192 /* SCTP-AUTH: Section 3.2
2193 * The CHUNKS parameter MUST be included once in the INIT or 2193 * The CHUNKS parameter MUST be included once in the INIT or
@@ -2203,7 +2203,7 @@ static enum sctp_ierror sctp_verify_param(struct net *net,
2203 2203
2204 case SCTP_PARAM_HMAC_ALGO: 2204 case SCTP_PARAM_HMAC_ALGO:
2205 if (!ep->auth_enable) 2205 if (!ep->auth_enable)
2206 goto fallthrough; 2206 goto unhandled;
2207 2207
2208 hmacs = (struct sctp_hmac_algo_param *)param.p; 2208 hmacs = (struct sctp_hmac_algo_param *)param.p;
2209 n_elt = (ntohs(param.p->length) - 2209 n_elt = (ntohs(param.p->length) -
@@ -2226,7 +2226,7 @@ static enum sctp_ierror sctp_verify_param(struct net *net,
2226 retval = SCTP_IERROR_ABORT; 2226 retval = SCTP_IERROR_ABORT;
2227 } 2227 }
2228 break; 2228 break;
2229fallthrough: 2229unhandled:
2230 default: 2230 default:
2231 pr_debug("%s: unrecognized param:%d for chunk:%d\n", 2231 pr_debug("%s: unrecognized param:%d for chunk:%d\n",
2232 __func__, ntohs(param.p->type), cid); 2232 __func__, ntohs(param.p->type), cid);
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 939b8d2595bc..ca81e06df165 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -8476,7 +8476,7 @@ __poll_t sctp_poll(struct file *file, struct socket *sock, poll_table *wait)
8476 mask = 0; 8476 mask = 0;
8477 8477
8478 /* Is there any exceptional events? */ 8478 /* Is there any exceptional events? */
8479 if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) 8479 if (sk->sk_err || !skb_queue_empty_lockless(&sk->sk_error_queue))
8480 mask |= EPOLLERR | 8480 mask |= EPOLLERR |
8481 (sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0); 8481 (sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0);
8482 if (sk->sk_shutdown & RCV_SHUTDOWN) 8482 if (sk->sk_shutdown & RCV_SHUTDOWN)
@@ -8485,7 +8485,7 @@ __poll_t sctp_poll(struct file *file, struct socket *sock, poll_table *wait)
8485 mask |= EPOLLHUP; 8485 mask |= EPOLLHUP;
8486 8486
8487 /* Is it readable? Reconsider this code with TCP-style support. */ 8487 /* Is it readable? Reconsider this code with TCP-style support. */
8488 if (!skb_queue_empty(&sk->sk_receive_queue)) 8488 if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
8489 mask |= EPOLLIN | EPOLLRDNORM; 8489 mask |= EPOLLIN | EPOLLRDNORM;
8490 8490
8491 /* The association is either gone or not ready. */ 8491 /* The association is either gone or not ready. */
@@ -8871,7 +8871,7 @@ struct sk_buff *sctp_skb_recv_datagram(struct sock *sk, int flags,
8871 if (sk_can_busy_loop(sk)) { 8871 if (sk_can_busy_loop(sk)) {
8872 sk_busy_loop(sk, noblock); 8872 sk_busy_loop(sk, noblock);
8873 8873
8874 if (!skb_queue_empty(&sk->sk_receive_queue)) 8874 if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
8875 continue; 8875 continue;
8876 } 8876 }
8877 8877
@@ -9500,7 +9500,7 @@ struct proto sctp_prot = {
9500 .backlog_rcv = sctp_backlog_rcv, 9500 .backlog_rcv = sctp_backlog_rcv,
9501 .hash = sctp_hash, 9501 .hash = sctp_hash,
9502 .unhash = sctp_unhash, 9502 .unhash = sctp_unhash,
9503 .get_port = sctp_get_port, 9503 .no_autobind = true,
9504 .obj_size = sizeof(struct sctp_sock), 9504 .obj_size = sizeof(struct sctp_sock),
9505 .useroffset = offsetof(struct sctp_sock, subscribe), 9505 .useroffset = offsetof(struct sctp_sock, subscribe),
9506 .usersize = offsetof(struct sctp_sock, initmsg) - 9506 .usersize = offsetof(struct sctp_sock, initmsg) -
@@ -9542,7 +9542,7 @@ struct proto sctpv6_prot = {
9542 .backlog_rcv = sctp_backlog_rcv, 9542 .backlog_rcv = sctp_backlog_rcv,
9543 .hash = sctp_hash, 9543 .hash = sctp_hash,
9544 .unhash = sctp_unhash, 9544 .unhash = sctp_unhash,
9545 .get_port = sctp_get_port, 9545 .no_autobind = true,
9546 .obj_size = sizeof(struct sctp6_sock), 9546 .obj_size = sizeof(struct sctp6_sock),
9547 .useroffset = offsetof(struct sctp6_sock, sctp.subscribe), 9547 .useroffset = offsetof(struct sctp6_sock, sctp.subscribe),
9548 .usersize = offsetof(struct sctp6_sock, sctp.initmsg) - 9548 .usersize = offsetof(struct sctp6_sock, sctp.initmsg) -
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 5b932583e407..47946f489fd4 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -123,6 +123,12 @@ struct proto smc_proto6 = {
123}; 123};
124EXPORT_SYMBOL_GPL(smc_proto6); 124EXPORT_SYMBOL_GPL(smc_proto6);
125 125
126static void smc_restore_fallback_changes(struct smc_sock *smc)
127{
128 smc->clcsock->file->private_data = smc->sk.sk_socket;
129 smc->clcsock->file = NULL;
130}
131
126static int __smc_release(struct smc_sock *smc) 132static int __smc_release(struct smc_sock *smc)
127{ 133{
128 struct sock *sk = &smc->sk; 134 struct sock *sk = &smc->sk;
@@ -141,6 +147,7 @@ static int __smc_release(struct smc_sock *smc)
141 } 147 }
142 sk->sk_state = SMC_CLOSED; 148 sk->sk_state = SMC_CLOSED;
143 sk->sk_state_change(sk); 149 sk->sk_state_change(sk);
150 smc_restore_fallback_changes(smc);
144 } 151 }
145 152
146 sk->sk_prot->unhash(sk); 153 sk->sk_prot->unhash(sk);
@@ -700,8 +707,6 @@ static int __smc_connect(struct smc_sock *smc)
700 int smc_type; 707 int smc_type;
701 int rc = 0; 708 int rc = 0;
702 709
703 sock_hold(&smc->sk); /* sock put in passive closing */
704
705 if (smc->use_fallback) 710 if (smc->use_fallback)
706 return smc_connect_fallback(smc, smc->fallback_rsn); 711 return smc_connect_fallback(smc, smc->fallback_rsn);
707 712
@@ -846,6 +851,8 @@ static int smc_connect(struct socket *sock, struct sockaddr *addr,
846 rc = kernel_connect(smc->clcsock, addr, alen, flags); 851 rc = kernel_connect(smc->clcsock, addr, alen, flags);
847 if (rc && rc != -EINPROGRESS) 852 if (rc && rc != -EINPROGRESS)
848 goto out; 853 goto out;
854
855 sock_hold(&smc->sk); /* sock put in passive closing */
849 if (flags & O_NONBLOCK) { 856 if (flags & O_NONBLOCK) {
850 if (schedule_work(&smc->connect_work)) 857 if (schedule_work(&smc->connect_work))
851 smc->connect_nonblock = 1; 858 smc->connect_nonblock = 1;
@@ -1291,8 +1298,8 @@ static void smc_listen_work(struct work_struct *work)
1291 /* check if RDMA is available */ 1298 /* check if RDMA is available */
1292 if (!ism_supported) { /* SMC_TYPE_R or SMC_TYPE_B */ 1299 if (!ism_supported) { /* SMC_TYPE_R or SMC_TYPE_B */
1293 /* prepare RDMA check */ 1300 /* prepare RDMA check */
1294 memset(&ini, 0, sizeof(ini));
1295 ini.is_smcd = false; 1301 ini.is_smcd = false;
1302 ini.ism_dev = NULL;
1296 ini.ib_lcl = &pclc->lcl; 1303 ini.ib_lcl = &pclc->lcl;
1297 rc = smc_find_rdma_device(new_smc, &ini); 1304 rc = smc_find_rdma_device(new_smc, &ini);
1298 if (rc) { 1305 if (rc) {
diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index 4ca50ddf8d16..2ba97ff325a5 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -213,7 +213,7 @@ static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini)
213 lgr = kzalloc(sizeof(*lgr), GFP_KERNEL); 213 lgr = kzalloc(sizeof(*lgr), GFP_KERNEL);
214 if (!lgr) { 214 if (!lgr) {
215 rc = SMC_CLC_DECL_MEM; 215 rc = SMC_CLC_DECL_MEM;
216 goto out; 216 goto ism_put_vlan;
217 } 217 }
218 lgr->is_smcd = ini->is_smcd; 218 lgr->is_smcd = ini->is_smcd;
219 lgr->sync_err = 0; 219 lgr->sync_err = 0;
@@ -289,6 +289,9 @@ clear_llc_lnk:
289 smc_llc_link_clear(lnk); 289 smc_llc_link_clear(lnk);
290free_lgr: 290free_lgr:
291 kfree(lgr); 291 kfree(lgr);
292ism_put_vlan:
293 if (ini->is_smcd && ini->vlan_id)
294 smc_ism_put_vlan(ini->ism_dev, ini->vlan_id);
292out: 295out:
293 if (rc < 0) { 296 if (rc < 0) {
294 if (rc == -ENOMEM) 297 if (rc == -ENOMEM)
@@ -558,7 +561,7 @@ int smc_vlan_by_tcpsk(struct socket *clcsock, struct smc_init_info *ini)
558 } 561 }
559 562
560 rtnl_lock(); 563 rtnl_lock();
561 nest_lvl = dev_get_nest_level(ndev); 564 nest_lvl = ndev->lower_level;
562 for (i = 0; i < nest_lvl; i++) { 565 for (i = 0; i < nest_lvl; i++) {
563 struct list_head *lower = &ndev->adj_list.lower; 566 struct list_head *lower = &ndev->adj_list.lower;
564 567
diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c
index bab2da8cf17a..2920b006f65c 100644
--- a/net/smc/smc_pnet.c
+++ b/net/smc/smc_pnet.c
@@ -718,7 +718,7 @@ static struct net_device *pnet_find_base_ndev(struct net_device *ndev)
718 int i, nest_lvl; 718 int i, nest_lvl;
719 719
720 rtnl_lock(); 720 rtnl_lock();
721 nest_lvl = dev_get_nest_level(ndev); 721 nest_lvl = ndev->lower_level;
722 for (i = 0; i < nest_lvl; i++) { 722 for (i = 0; i < nest_lvl; i++) {
723 struct list_head *lower = &ndev->adj_list.lower; 723 struct list_head *lower = &ndev->adj_list.lower;
724 724
diff --git a/net/smc/smc_rx.c b/net/smc/smc_rx.c
index 413a6abf227e..97e8369002d7 100644
--- a/net/smc/smc_rx.c
+++ b/net/smc/smc_rx.c
@@ -211,8 +211,7 @@ int smc_rx_wait(struct smc_sock *smc, long *timeo,
211 rc = sk_wait_event(sk, timeo, 211 rc = sk_wait_event(sk, timeo,
212 sk->sk_err || 212 sk->sk_err ||
213 sk->sk_shutdown & RCV_SHUTDOWN || 213 sk->sk_shutdown & RCV_SHUTDOWN ||
214 fcrit(conn) || 214 fcrit(conn),
215 smc_cdc_rxed_any_close_or_senddone(conn),
216 &wait); 215 &wait);
217 remove_wait_queue(sk_sleep(sk), &wait); 216 remove_wait_queue(sk_sleep(sk), &wait);
218 sk_clear_bit(SOCKWQ_ASYNC_WAITDATA, sk); 217 sk_clear_bit(SOCKWQ_ASYNC_WAITDATA, sk);
@@ -262,6 +261,18 @@ static int smc_rx_recv_urg(struct smc_sock *smc, struct msghdr *msg, int len,
262 return -EAGAIN; 261 return -EAGAIN;
263} 262}
264 263
264static bool smc_rx_recvmsg_data_available(struct smc_sock *smc)
265{
266 struct smc_connection *conn = &smc->conn;
267
268 if (smc_rx_data_available(conn))
269 return true;
270 else if (conn->urg_state == SMC_URG_VALID)
271 /* we received a single urgent Byte - skip */
272 smc_rx_update_cons(smc, 0);
273 return false;
274}
275
265/* smc_rx_recvmsg - receive data from RMBE 276/* smc_rx_recvmsg - receive data from RMBE
266 * @msg: copy data to receive buffer 277 * @msg: copy data to receive buffer
267 * @pipe: copy data to pipe if set - indicates splice() call 278 * @pipe: copy data to pipe if set - indicates splice() call
@@ -303,16 +314,18 @@ int smc_rx_recvmsg(struct smc_sock *smc, struct msghdr *msg,
303 if (read_done >= target || (pipe && read_done)) 314 if (read_done >= target || (pipe && read_done))
304 break; 315 break;
305 316
306 if (atomic_read(&conn->bytes_to_rcv)) 317 if (smc_rx_recvmsg_data_available(smc))
307 goto copy; 318 goto copy;
308 else if (conn->urg_state == SMC_URG_VALID)
309 /* we received a single urgent Byte - skip */
310 smc_rx_update_cons(smc, 0);
311 319
312 if (sk->sk_shutdown & RCV_SHUTDOWN || 320 if (sk->sk_shutdown & RCV_SHUTDOWN ||
313 smc_cdc_rxed_any_close_or_senddone(conn) || 321 conn->local_tx_ctrl.conn_state_flags.peer_conn_abort) {
314 conn->local_tx_ctrl.conn_state_flags.peer_conn_abort) 322 /* smc_cdc_msg_recv_action() could have run after
323 * above smc_rx_recvmsg_data_available()
324 */
325 if (smc_rx_recvmsg_data_available(smc))
326 goto copy;
315 break; 327 break;
328 }
316 329
317 if (read_done) { 330 if (read_done) {
318 if (sk->sk_err || 331 if (sk->sk_err ||
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 9ac88722fa83..70e52f567b2a 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -1249,19 +1249,21 @@ static void xs_error_report(struct sock *sk)
1249{ 1249{
1250 struct sock_xprt *transport; 1250 struct sock_xprt *transport;
1251 struct rpc_xprt *xprt; 1251 struct rpc_xprt *xprt;
1252 int err;
1253 1252
1254 read_lock_bh(&sk->sk_callback_lock); 1253 read_lock_bh(&sk->sk_callback_lock);
1255 if (!(xprt = xprt_from_sock(sk))) 1254 if (!(xprt = xprt_from_sock(sk)))
1256 goto out; 1255 goto out;
1257 1256
1258 transport = container_of(xprt, struct sock_xprt, xprt); 1257 transport = container_of(xprt, struct sock_xprt, xprt);
1259 err = -sk->sk_err; 1258 transport->xprt_err = -sk->sk_err;
1260 if (err == 0) 1259 if (transport->xprt_err == 0)
1261 goto out; 1260 goto out;
1262 dprintk("RPC: xs_error_report client %p, error=%d...\n", 1261 dprintk("RPC: xs_error_report client %p, error=%d...\n",
1263 xprt, -err); 1262 xprt, -transport->xprt_err);
1264 trace_rpc_socket_error(xprt, sk->sk_socket, err); 1263 trace_rpc_socket_error(xprt, sk->sk_socket, transport->xprt_err);
1264
1265 /* barrier ensures xprt_err is set before XPRT_SOCK_WAKE_ERROR */
1266 smp_mb__before_atomic();
1265 xs_run_error_worker(transport, XPRT_SOCK_WAKE_ERROR); 1267 xs_run_error_worker(transport, XPRT_SOCK_WAKE_ERROR);
1266 out: 1268 out:
1267 read_unlock_bh(&sk->sk_callback_lock); 1269 read_unlock_bh(&sk->sk_callback_lock);
@@ -2476,7 +2478,6 @@ static void xs_wake_write(struct sock_xprt *transport)
2476static void xs_wake_error(struct sock_xprt *transport) 2478static void xs_wake_error(struct sock_xprt *transport)
2477{ 2479{
2478 int sockerr; 2480 int sockerr;
2479 int sockerr_len = sizeof(sockerr);
2480 2481
2481 if (!test_bit(XPRT_SOCK_WAKE_ERROR, &transport->sock_state)) 2482 if (!test_bit(XPRT_SOCK_WAKE_ERROR, &transport->sock_state))
2482 return; 2483 return;
@@ -2485,9 +2486,7 @@ static void xs_wake_error(struct sock_xprt *transport)
2485 goto out; 2486 goto out;
2486 if (!test_and_clear_bit(XPRT_SOCK_WAKE_ERROR, &transport->sock_state)) 2487 if (!test_and_clear_bit(XPRT_SOCK_WAKE_ERROR, &transport->sock_state))
2487 goto out; 2488 goto out;
2488 if (kernel_getsockopt(transport->sock, SOL_SOCKET, SO_ERROR, 2489 sockerr = xchg(&transport->xprt_err, 0);
2489 (char *)&sockerr, &sockerr_len) != 0)
2490 goto out;
2491 if (sockerr < 0) 2490 if (sockerr < 0)
2492 xprt_wake_pending_tasks(&transport->xprt, sockerr); 2491 xprt_wake_pending_tasks(&transport->xprt, sockerr);
2493out: 2492out:
diff --git a/net/tipc/link.c b/net/tipc/link.c
index 6cc75ffd9e2c..999eab592de8 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -160,6 +160,7 @@ struct tipc_link {
160 struct { 160 struct {
161 u16 len; 161 u16 len;
162 u16 limit; 162 u16 limit;
163 struct sk_buff *target_bskb;
163 } backlog[5]; 164 } backlog[5];
164 u16 snd_nxt; 165 u16 snd_nxt;
165 u16 window; 166 u16 window;
@@ -880,6 +881,7 @@ static void link_prepare_wakeup(struct tipc_link *l)
880void tipc_link_reset(struct tipc_link *l) 881void tipc_link_reset(struct tipc_link *l)
881{ 882{
882 struct sk_buff_head list; 883 struct sk_buff_head list;
884 u32 imp;
883 885
884 __skb_queue_head_init(&list); 886 __skb_queue_head_init(&list);
885 887
@@ -901,11 +903,10 @@ void tipc_link_reset(struct tipc_link *l)
901 __skb_queue_purge(&l->deferdq); 903 __skb_queue_purge(&l->deferdq);
902 __skb_queue_purge(&l->backlogq); 904 __skb_queue_purge(&l->backlogq);
903 __skb_queue_purge(&l->failover_deferdq); 905 __skb_queue_purge(&l->failover_deferdq);
904 l->backlog[TIPC_LOW_IMPORTANCE].len = 0; 906 for (imp = 0; imp <= TIPC_SYSTEM_IMPORTANCE; imp++) {
905 l->backlog[TIPC_MEDIUM_IMPORTANCE].len = 0; 907 l->backlog[imp].len = 0;
906 l->backlog[TIPC_HIGH_IMPORTANCE].len = 0; 908 l->backlog[imp].target_bskb = NULL;
907 l->backlog[TIPC_CRITICAL_IMPORTANCE].len = 0; 909 }
908 l->backlog[TIPC_SYSTEM_IMPORTANCE].len = 0;
909 kfree_skb(l->reasm_buf); 910 kfree_skb(l->reasm_buf);
910 kfree_skb(l->reasm_tnlmsg); 911 kfree_skb(l->reasm_tnlmsg);
911 kfree_skb(l->failover_reasm_skb); 912 kfree_skb(l->failover_reasm_skb);
@@ -947,7 +948,7 @@ int tipc_link_xmit(struct tipc_link *l, struct sk_buff_head *list,
947 u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1; 948 u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
948 struct sk_buff_head *transmq = &l->transmq; 949 struct sk_buff_head *transmq = &l->transmq;
949 struct sk_buff_head *backlogq = &l->backlogq; 950 struct sk_buff_head *backlogq = &l->backlogq;
950 struct sk_buff *skb, *_skb, *bskb; 951 struct sk_buff *skb, *_skb, **tskb;
951 int pkt_cnt = skb_queue_len(list); 952 int pkt_cnt = skb_queue_len(list);
952 int rc = 0; 953 int rc = 0;
953 954
@@ -999,19 +1000,21 @@ int tipc_link_xmit(struct tipc_link *l, struct sk_buff_head *list,
999 seqno++; 1000 seqno++;
1000 continue; 1001 continue;
1001 } 1002 }
1002 if (tipc_msg_bundle(skb_peek_tail(backlogq), hdr, mtu)) { 1003 tskb = &l->backlog[imp].target_bskb;
1004 if (tipc_msg_bundle(*tskb, hdr, mtu)) {
1003 kfree_skb(__skb_dequeue(list)); 1005 kfree_skb(__skb_dequeue(list));
1004 l->stats.sent_bundled++; 1006 l->stats.sent_bundled++;
1005 continue; 1007 continue;
1006 } 1008 }
1007 if (tipc_msg_make_bundle(&bskb, hdr, mtu, l->addr)) { 1009 if (tipc_msg_make_bundle(tskb, hdr, mtu, l->addr)) {
1008 kfree_skb(__skb_dequeue(list)); 1010 kfree_skb(__skb_dequeue(list));
1009 __skb_queue_tail(backlogq, bskb); 1011 __skb_queue_tail(backlogq, *tskb);
1010 l->backlog[msg_importance(buf_msg(bskb))].len++; 1012 l->backlog[imp].len++;
1011 l->stats.sent_bundled++; 1013 l->stats.sent_bundled++;
1012 l->stats.sent_bundles++; 1014 l->stats.sent_bundles++;
1013 continue; 1015 continue;
1014 } 1016 }
1017 l->backlog[imp].target_bskb = NULL;
1015 l->backlog[imp].len += skb_queue_len(list); 1018 l->backlog[imp].len += skb_queue_len(list);
1016 skb_queue_splice_tail_init(list, backlogq); 1019 skb_queue_splice_tail_init(list, backlogq);
1017 } 1020 }
@@ -1027,6 +1030,7 @@ static void tipc_link_advance_backlog(struct tipc_link *l,
1027 u16 seqno = l->snd_nxt; 1030 u16 seqno = l->snd_nxt;
1028 u16 ack = l->rcv_nxt - 1; 1031 u16 ack = l->rcv_nxt - 1;
1029 u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1; 1032 u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
1033 u32 imp;
1030 1034
1031 while (skb_queue_len(&l->transmq) < l->window) { 1035 while (skb_queue_len(&l->transmq) < l->window) {
1032 skb = skb_peek(&l->backlogq); 1036 skb = skb_peek(&l->backlogq);
@@ -1037,7 +1041,10 @@ static void tipc_link_advance_backlog(struct tipc_link *l,
1037 break; 1041 break;
1038 __skb_dequeue(&l->backlogq); 1042 __skb_dequeue(&l->backlogq);
1039 hdr = buf_msg(skb); 1043 hdr = buf_msg(skb);
1040 l->backlog[msg_importance(hdr)].len--; 1044 imp = msg_importance(hdr);
1045 l->backlog[imp].len--;
1046 if (unlikely(skb == l->backlog[imp].target_bskb))
1047 l->backlog[imp].target_bskb = NULL;
1041 __skb_queue_tail(&l->transmq, skb); 1048 __skb_queue_tail(&l->transmq, skb);
1042 /* next retransmit attempt */ 1049 /* next retransmit attempt */
1043 if (link_is_bc_sndlink(l)) 1050 if (link_is_bc_sndlink(l))
diff --git a/net/tipc/msg.c b/net/tipc/msg.c
index e6d49cdc61b4..922d262e153f 100644
--- a/net/tipc/msg.c
+++ b/net/tipc/msg.c
@@ -543,10 +543,7 @@ bool tipc_msg_make_bundle(struct sk_buff **skb, struct tipc_msg *msg,
543 bmsg = buf_msg(_skb); 543 bmsg = buf_msg(_skb);
544 tipc_msg_init(msg_prevnode(msg), bmsg, MSG_BUNDLER, 0, 544 tipc_msg_init(msg_prevnode(msg), bmsg, MSG_BUNDLER, 0,
545 INT_H_SIZE, dnode); 545 INT_H_SIZE, dnode);
546 if (msg_isdata(msg)) 546 msg_set_importance(bmsg, msg_importance(msg));
547 msg_set_importance(bmsg, TIPC_CRITICAL_IMPORTANCE);
548 else
549 msg_set_importance(bmsg, TIPC_SYSTEM_IMPORTANCE);
550 msg_set_seqno(bmsg, msg_seqno(msg)); 547 msg_set_seqno(bmsg, msg_seqno(msg));
551 msg_set_ack(bmsg, msg_ack(msg)); 548 msg_set_ack(bmsg, msg_ack(msg));
552 msg_set_bcast_ack(bmsg, msg_bcast_ack(msg)); 549 msg_set_bcast_ack(bmsg, msg_bcast_ack(msg));
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 3b9f8cc328f5..4b92b196cfa6 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -740,7 +740,7 @@ static __poll_t tipc_poll(struct file *file, struct socket *sock,
740 /* fall through */ 740 /* fall through */
741 case TIPC_LISTEN: 741 case TIPC_LISTEN:
742 case TIPC_CONNECTING: 742 case TIPC_CONNECTING:
743 if (!skb_queue_empty(&sk->sk_receive_queue)) 743 if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
744 revents |= EPOLLIN | EPOLLRDNORM; 744 revents |= EPOLLIN | EPOLLRDNORM;
745 break; 745 break;
746 case TIPC_OPEN: 746 case TIPC_OPEN:
@@ -748,7 +748,7 @@ static __poll_t tipc_poll(struct file *file, struct socket *sock,
748 revents |= EPOLLOUT; 748 revents |= EPOLLOUT;
749 if (!tipc_sk_type_connectionless(sk)) 749 if (!tipc_sk_type_connectionless(sk))
750 break; 750 break;
751 if (skb_queue_empty(&sk->sk_receive_queue)) 751 if (skb_queue_empty_lockless(&sk->sk_receive_queue))
752 break; 752 break;
753 revents |= EPOLLIN | EPOLLRDNORM; 753 revents |= EPOLLIN | EPOLLRDNORM;
754 break; 754 break;
@@ -2119,13 +2119,13 @@ static unsigned int rcvbuf_limit(struct sock *sk, struct sk_buff *skb)
2119 struct tipc_msg *hdr = buf_msg(skb); 2119 struct tipc_msg *hdr = buf_msg(skb);
2120 2120
2121 if (unlikely(msg_in_group(hdr))) 2121 if (unlikely(msg_in_group(hdr)))
2122 return sk->sk_rcvbuf; 2122 return READ_ONCE(sk->sk_rcvbuf);
2123 2123
2124 if (unlikely(!msg_connected(hdr))) 2124 if (unlikely(!msg_connected(hdr)))
2125 return sk->sk_rcvbuf << msg_importance(hdr); 2125 return READ_ONCE(sk->sk_rcvbuf) << msg_importance(hdr);
2126 2126
2127 if (likely(tsk->peer_caps & TIPC_BLOCK_FLOWCTL)) 2127 if (likely(tsk->peer_caps & TIPC_BLOCK_FLOWCTL))
2128 return sk->sk_rcvbuf; 2128 return READ_ONCE(sk->sk_rcvbuf);
2129 2129
2130 return FLOWCTL_MSG_LIM; 2130 return FLOWCTL_MSG_LIM;
2131} 2131}
@@ -3790,7 +3790,7 @@ int tipc_sk_dump(struct sock *sk, u16 dqueues, char *buf)
3790 i += scnprintf(buf + i, sz - i, " %d", sk->sk_sndbuf); 3790 i += scnprintf(buf + i, sz - i, " %d", sk->sk_sndbuf);
3791 i += scnprintf(buf + i, sz - i, " | %d", sk_rmem_alloc_get(sk)); 3791 i += scnprintf(buf + i, sz - i, " | %d", sk_rmem_alloc_get(sk));
3792 i += scnprintf(buf + i, sz - i, " %d", sk->sk_rcvbuf); 3792 i += scnprintf(buf + i, sz - i, " %d", sk->sk_rcvbuf);
3793 i += scnprintf(buf + i, sz - i, " | %d\n", sk->sk_backlog.len); 3793 i += scnprintf(buf + i, sz - i, " | %d\n", READ_ONCE(sk->sk_backlog.len));
3794 3794
3795 if (dqueues & TIPC_DUMP_SK_SNDQ) { 3795 if (dqueues & TIPC_DUMP_SK_SNDQ) {
3796 i += scnprintf(buf + i, sz - i, "sk_write_queue: "); 3796 i += scnprintf(buf + i, sz - i, "sk_write_queue: ");
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 67e87db5877f..0d8da809bea2 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2599,7 +2599,7 @@ static __poll_t unix_poll(struct file *file, struct socket *sock, poll_table *wa
2599 mask |= EPOLLRDHUP | EPOLLIN | EPOLLRDNORM; 2599 mask |= EPOLLRDHUP | EPOLLIN | EPOLLRDNORM;
2600 2600
2601 /* readable? */ 2601 /* readable? */
2602 if (!skb_queue_empty(&sk->sk_receive_queue)) 2602 if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
2603 mask |= EPOLLIN | EPOLLRDNORM; 2603 mask |= EPOLLIN | EPOLLRDNORM;
2604 2604
2605 /* Connection-based need to check for termination and startup */ 2605 /* Connection-based need to check for termination and startup */
@@ -2628,7 +2628,7 @@ static __poll_t unix_dgram_poll(struct file *file, struct socket *sock,
2628 mask = 0; 2628 mask = 0;
2629 2629
2630 /* exceptional events? */ 2630 /* exceptional events? */
2631 if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) 2631 if (sk->sk_err || !skb_queue_empty_lockless(&sk->sk_error_queue))
2632 mask |= EPOLLERR | 2632 mask |= EPOLLERR |
2633 (sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0); 2633 (sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0);
2634 2634
@@ -2638,7 +2638,7 @@ static __poll_t unix_dgram_poll(struct file *file, struct socket *sock,
2638 mask |= EPOLLHUP; 2638 mask |= EPOLLHUP;
2639 2639
2640 /* readable? */ 2640 /* readable? */
2641 if (!skb_queue_empty(&sk->sk_receive_queue)) 2641 if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
2642 mask |= EPOLLIN | EPOLLRDNORM; 2642 mask |= EPOLLIN | EPOLLRDNORM;
2643 2643
2644 /* Connection-based need to check for termination and startup */ 2644 /* Connection-based need to check for termination and startup */
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index ab47bf3ab66e..582a3e4dfce2 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -638,7 +638,7 @@ struct sock *__vsock_create(struct net *net,
638} 638}
639EXPORT_SYMBOL_GPL(__vsock_create); 639EXPORT_SYMBOL_GPL(__vsock_create);
640 640
641static void __vsock_release(struct sock *sk) 641static void __vsock_release(struct sock *sk, int level)
642{ 642{
643 if (sk) { 643 if (sk) {
644 struct sk_buff *skb; 644 struct sk_buff *skb;
@@ -648,9 +648,17 @@ static void __vsock_release(struct sock *sk)
648 vsk = vsock_sk(sk); 648 vsk = vsock_sk(sk);
649 pending = NULL; /* Compiler warning. */ 649 pending = NULL; /* Compiler warning. */
650 650
651 /* The release call is supposed to use lock_sock_nested()
652 * rather than lock_sock(), if a sock lock should be acquired.
653 */
651 transport->release(vsk); 654 transport->release(vsk);
652 655
653 lock_sock(sk); 656 /* When "level" is SINGLE_DEPTH_NESTING, use the nested
657 * version to avoid the warning "possible recursive locking
658 * detected". When "level" is 0, lock_sock_nested(sk, level)
659 * is the same as lock_sock(sk).
660 */
661 lock_sock_nested(sk, level);
654 sock_orphan(sk); 662 sock_orphan(sk);
655 sk->sk_shutdown = SHUTDOWN_MASK; 663 sk->sk_shutdown = SHUTDOWN_MASK;
656 664
@@ -659,7 +667,7 @@ static void __vsock_release(struct sock *sk)
659 667
660 /* Clean up any sockets that never were accepted. */ 668 /* Clean up any sockets that never were accepted. */
661 while ((pending = vsock_dequeue_accept(sk)) != NULL) { 669 while ((pending = vsock_dequeue_accept(sk)) != NULL) {
662 __vsock_release(pending); 670 __vsock_release(pending, SINGLE_DEPTH_NESTING);
663 sock_put(pending); 671 sock_put(pending);
664 } 672 }
665 673
@@ -708,7 +716,7 @@ EXPORT_SYMBOL_GPL(vsock_stream_has_space);
708 716
709static int vsock_release(struct socket *sock) 717static int vsock_release(struct socket *sock)
710{ 718{
711 __vsock_release(sock->sk); 719 __vsock_release(sock->sk, 0);
712 sock->sk = NULL; 720 sock->sk = NULL;
713 sock->state = SS_FREE; 721 sock->state = SS_FREE;
714 722
@@ -862,7 +870,7 @@ static __poll_t vsock_poll(struct file *file, struct socket *sock,
862 * the queue and write as long as the socket isn't shutdown for 870 * the queue and write as long as the socket isn't shutdown for
863 * sending. 871 * sending.
864 */ 872 */
865 if (!skb_queue_empty(&sk->sk_receive_queue) || 873 if (!skb_queue_empty_lockless(&sk->sk_receive_queue) ||
866 (sk->sk_shutdown & RCV_SHUTDOWN)) { 874 (sk->sk_shutdown & RCV_SHUTDOWN)) {
867 mask |= EPOLLIN | EPOLLRDNORM; 875 mask |= EPOLLIN | EPOLLRDNORM;
868 } 876 }
diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transport.c
index 261521d286d6..c443db7af8d4 100644
--- a/net/vmw_vsock/hyperv_transport.c
+++ b/net/vmw_vsock/hyperv_transport.c
@@ -559,7 +559,7 @@ static void hvs_release(struct vsock_sock *vsk)
559 struct sock *sk = sk_vsock(vsk); 559 struct sock *sk = sk_vsock(vsk);
560 bool remove_sock; 560 bool remove_sock;
561 561
562 lock_sock(sk); 562 lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
563 remove_sock = hvs_close_lock_held(vsk); 563 remove_sock = hvs_close_lock_held(vsk);
564 release_sock(sk); 564 release_sock(sk);
565 if (remove_sock) 565 if (remove_sock)
diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index 5bb70c692b1e..481f7f8a1655 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -204,10 +204,14 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk,
204 return virtio_transport_get_ops()->send_pkt(pkt); 204 return virtio_transport_get_ops()->send_pkt(pkt);
205} 205}
206 206
207static void virtio_transport_inc_rx_pkt(struct virtio_vsock_sock *vvs, 207static bool virtio_transport_inc_rx_pkt(struct virtio_vsock_sock *vvs,
208 struct virtio_vsock_pkt *pkt) 208 struct virtio_vsock_pkt *pkt)
209{ 209{
210 if (vvs->rx_bytes + pkt->len > vvs->buf_alloc)
211 return false;
212
210 vvs->rx_bytes += pkt->len; 213 vvs->rx_bytes += pkt->len;
214 return true;
211} 215}
212 216
213static void virtio_transport_dec_rx_pkt(struct virtio_vsock_sock *vvs, 217static void virtio_transport_dec_rx_pkt(struct virtio_vsock_sock *vvs,
@@ -458,6 +462,9 @@ void virtio_transport_set_buffer_size(struct vsock_sock *vsk, u64 val)
458 vvs->buf_size_max = val; 462 vvs->buf_size_max = val;
459 vvs->buf_size = val; 463 vvs->buf_size = val;
460 vvs->buf_alloc = val; 464 vvs->buf_alloc = val;
465
466 virtio_transport_send_credit_update(vsk, VIRTIO_VSOCK_TYPE_STREAM,
467 NULL);
461} 468}
462EXPORT_SYMBOL_GPL(virtio_transport_set_buffer_size); 469EXPORT_SYMBOL_GPL(virtio_transport_set_buffer_size);
463 470
@@ -820,7 +827,7 @@ void virtio_transport_release(struct vsock_sock *vsk)
820 struct sock *sk = &vsk->sk; 827 struct sock *sk = &vsk->sk;
821 bool remove_sock = true; 828 bool remove_sock = true;
822 829
823 lock_sock(sk); 830 lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
824 if (sk->sk_type == SOCK_STREAM) 831 if (sk->sk_type == SOCK_STREAM)
825 remove_sock = virtio_transport_close(vsk); 832 remove_sock = virtio_transport_close(vsk);
826 833
@@ -876,14 +883,18 @@ virtio_transport_recv_enqueue(struct vsock_sock *vsk,
876 struct virtio_vsock_pkt *pkt) 883 struct virtio_vsock_pkt *pkt)
877{ 884{
878 struct virtio_vsock_sock *vvs = vsk->trans; 885 struct virtio_vsock_sock *vvs = vsk->trans;
879 bool free_pkt = false; 886 bool can_enqueue, free_pkt = false;
880 887
881 pkt->len = le32_to_cpu(pkt->hdr.len); 888 pkt->len = le32_to_cpu(pkt->hdr.len);
882 pkt->off = 0; 889 pkt->off = 0;
883 890
884 spin_lock_bh(&vvs->rx_lock); 891 spin_lock_bh(&vvs->rx_lock);
885 892
886 virtio_transport_inc_rx_pkt(vvs, pkt); 893 can_enqueue = virtio_transport_inc_rx_pkt(vvs, pkt);
894 if (!can_enqueue) {
895 free_pkt = true;
896 goto out;
897 }
887 898
888 /* Try to copy small packets into the buffer of last packet queued, 899 /* Try to copy small packets into the buffer of last packet queued,
889 * to avoid wasting memory queueing the entire buffer with a small 900 * to avoid wasting memory queueing the entire buffer with a small
diff --git a/net/wireless/chan.c b/net/wireless/chan.c
index e851cafd8e2f..fcac5c6366e1 100644
--- a/net/wireless/chan.c
+++ b/net/wireless/chan.c
@@ -204,6 +204,11 @@ bool cfg80211_chandef_valid(const struct cfg80211_chan_def *chandef)
204 return false; 204 return false;
205 } 205 }
206 206
207 /* channel 14 is only for IEEE 802.11b */
208 if (chandef->center_freq1 == 2484 &&
209 chandef->width != NL80211_CHAN_WIDTH_20_NOHT)
210 return false;
211
207 if (cfg80211_chandef_is_edmg(chandef) && 212 if (cfg80211_chandef_is_edmg(chandef) &&
208 !cfg80211_edmg_chandef_valid(chandef)) 213 !cfg80211_edmg_chandef_valid(chandef))
209 return false; 214 return false;
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index d21b1581a665..7b72286922f7 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -201,6 +201,38 @@ cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
201 return __cfg80211_rdev_from_attrs(netns, info->attrs); 201 return __cfg80211_rdev_from_attrs(netns, info->attrs);
202} 202}
203 203
204static int validate_beacon_head(const struct nlattr *attr,
205 struct netlink_ext_ack *extack)
206{
207 const u8 *data = nla_data(attr);
208 unsigned int len = nla_len(attr);
209 const struct element *elem;
210 const struct ieee80211_mgmt *mgmt = (void *)data;
211 unsigned int fixedlen = offsetof(struct ieee80211_mgmt,
212 u.beacon.variable);
213
214 if (len < fixedlen)
215 goto err;
216
217 if (ieee80211_hdrlen(mgmt->frame_control) !=
218 offsetof(struct ieee80211_mgmt, u.beacon))
219 goto err;
220
221 data += fixedlen;
222 len -= fixedlen;
223
224 for_each_element(elem, data, len) {
225 /* nothing */
226 }
227
228 if (for_each_element_completed(elem, data, len))
229 return 0;
230
231err:
232 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head");
233 return -EINVAL;
234}
235
204static int validate_ie_attr(const struct nlattr *attr, 236static int validate_ie_attr(const struct nlattr *attr,
205 struct netlink_ext_ack *extack) 237 struct netlink_ext_ack *extack)
206{ 238{
@@ -338,8 +370,9 @@ const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
338 370
339 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, 371 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
340 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, 372 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
341 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, 373 [NL80211_ATTR_BEACON_HEAD] =
342 .len = IEEE80211_MAX_DATA_LEN }, 374 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head,
375 IEEE80211_MAX_DATA_LEN),
343 [NL80211_ATTR_BEACON_TAIL] = 376 [NL80211_ATTR_BEACON_TAIL] =
344 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 377 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
345 IEEE80211_MAX_DATA_LEN), 378 IEEE80211_MAX_DATA_LEN),
@@ -360,7 +393,7 @@ const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
360 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, 393 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
361 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, 394 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
362 .len = IEEE80211_MAX_MESH_ID_LEN }, 395 .len = IEEE80211_MAX_MESH_ID_LEN },
363 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, 396 [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT,
364 397
365 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, 398 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
366 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, 399 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
@@ -2636,6 +2669,8 @@ int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2636 2669
2637 control_freq = nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]); 2670 control_freq = nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]);
2638 2671
2672 memset(chandef, 0, sizeof(*chandef));
2673
2639 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); 2674 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
2640 chandef->width = NL80211_CHAN_WIDTH_20_NOHT; 2675 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2641 chandef->center_freq1 = control_freq; 2676 chandef->center_freq1 = control_freq;
@@ -3176,7 +3211,7 @@ static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flag
3176 3211
3177 if (rdev->ops->get_channel) { 3212 if (rdev->ops->get_channel) {
3178 int ret; 3213 int ret;
3179 struct cfg80211_chan_def chandef; 3214 struct cfg80211_chan_def chandef = {};
3180 3215
3181 ret = rdev_get_channel(rdev, wdev, &chandef); 3216 ret = rdev_get_channel(rdev, wdev, &chandef);
3182 if (ret == 0) { 3217 if (ret == 0) {
@@ -6270,6 +6305,9 @@ static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
6270 if (!rdev->ops->del_mpath) 6305 if (!rdev->ops->del_mpath)
6271 return -EOPNOTSUPP; 6306 return -EOPNOTSUPP;
6272 6307
6308 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6309 return -EOPNOTSUPP;
6310
6273 return rdev_del_mpath(rdev, dev, dst); 6311 return rdev_del_mpath(rdev, dev, dst);
6274} 6312}
6275 6313
@@ -13644,7 +13682,7 @@ static int nl80211_get_ftm_responder_stats(struct sk_buff *skb,
13644 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 13682 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13645 NL80211_CMD_GET_FTM_RESPONDER_STATS); 13683 NL80211_CMD_GET_FTM_RESPONDER_STATS);
13646 if (!hdr) 13684 if (!hdr)
13647 return -ENOBUFS; 13685 goto nla_put_failure;
13648 13686
13649 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 13687 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
13650 goto nla_put_failure; 13688 goto nla_put_failure;
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 5311d0ae2454..446c76d44e65 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -2108,7 +2108,7 @@ static void reg_call_notifier(struct wiphy *wiphy,
2108 2108
2109static bool reg_wdev_chan_valid(struct wiphy *wiphy, struct wireless_dev *wdev) 2109static bool reg_wdev_chan_valid(struct wiphy *wiphy, struct wireless_dev *wdev)
2110{ 2110{
2111 struct cfg80211_chan_def chandef; 2111 struct cfg80211_chan_def chandef = {};
2112 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 2112 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
2113 enum nl80211_iftype iftype; 2113 enum nl80211_iftype iftype;
2114 2114
@@ -3883,6 +3883,7 @@ bool regulatory_pre_cac_allowed(struct wiphy *wiphy)
3883 3883
3884 return pre_cac_allowed; 3884 return pre_cac_allowed;
3885} 3885}
3886EXPORT_SYMBOL(regulatory_pre_cac_allowed);
3886 3887
3887void regulatory_propagate_dfs_state(struct wiphy *wiphy, 3888void regulatory_propagate_dfs_state(struct wiphy *wiphy,
3888 struct cfg80211_chan_def *chandef, 3889 struct cfg80211_chan_def *chandef,
diff --git a/net/wireless/reg.h b/net/wireless/reg.h
index 504133d76de4..dc8f689bd469 100644
--- a/net/wireless/reg.h
+++ b/net/wireless/reg.h
@@ -156,14 +156,6 @@ bool regulatory_indoor_allowed(void);
156#define REG_PRE_CAC_EXPIRY_GRACE_MS 2000 156#define REG_PRE_CAC_EXPIRY_GRACE_MS 2000
157 157
158/** 158/**
159 * regulatory_pre_cac_allowed - if pre-CAC allowed in the current dfs domain
160 * @wiphy: wiphy for which pre-CAC capability is checked.
161
162 * Pre-CAC is allowed only in ETSI domain.
163 */
164bool regulatory_pre_cac_allowed(struct wiphy *wiphy);
165
166/**
167 * regulatory_propagate_dfs_state - Propagate DFS channel state to other wiphys 159 * regulatory_propagate_dfs_state - Propagate DFS channel state to other wiphys
168 * @wiphy - wiphy on which radar is detected and the event will be propagated 160 * @wiphy - wiphy on which radar is detected and the event will be propagated
169 * to other available wiphys having the same DFS domain 161 * to other available wiphys having the same DFS domain
diff --git a/net/wireless/scan.c b/net/wireless/scan.c
index d313c9befa23..aef240fdf8df 100644
--- a/net/wireless/scan.c
+++ b/net/wireless/scan.c
@@ -1703,8 +1703,7 @@ cfg80211_parse_mbssid_frame_data(struct wiphy *wiphy,
1703static void 1703static void
1704cfg80211_update_notlisted_nontrans(struct wiphy *wiphy, 1704cfg80211_update_notlisted_nontrans(struct wiphy *wiphy,
1705 struct cfg80211_bss *nontrans_bss, 1705 struct cfg80211_bss *nontrans_bss,
1706 struct ieee80211_mgmt *mgmt, size_t len, 1706 struct ieee80211_mgmt *mgmt, size_t len)
1707 gfp_t gfp)
1708{ 1707{
1709 u8 *ie, *new_ie, *pos; 1708 u8 *ie, *new_ie, *pos;
1710 const u8 *nontrans_ssid, *trans_ssid, *mbssid; 1709 const u8 *nontrans_ssid, *trans_ssid, *mbssid;
@@ -1715,6 +1714,8 @@ cfg80211_update_notlisted_nontrans(struct wiphy *wiphy,
1715 const struct cfg80211_bss_ies *old; 1714 const struct cfg80211_bss_ies *old;
1716 u8 cpy_len; 1715 u8 cpy_len;
1717 1716
1717 lockdep_assert_held(&wiphy_to_rdev(wiphy)->bss_lock);
1718
1718 ie = mgmt->u.probe_resp.variable; 1719 ie = mgmt->u.probe_resp.variable;
1719 1720
1720 new_ie_len = ielen; 1721 new_ie_len = ielen;
@@ -1723,26 +1724,30 @@ cfg80211_update_notlisted_nontrans(struct wiphy *wiphy,
1723 return; 1724 return;
1724 new_ie_len -= trans_ssid[1]; 1725 new_ie_len -= trans_ssid[1];
1725 mbssid = cfg80211_find_ie(WLAN_EID_MULTIPLE_BSSID, ie, ielen); 1726 mbssid = cfg80211_find_ie(WLAN_EID_MULTIPLE_BSSID, ie, ielen);
1726 if (!mbssid) 1727 /*
1728 * It's not valid to have the MBSSID element before SSID
1729 * ignore if that happens - the code below assumes it is
1730 * after (while copying things inbetween).
1731 */
1732 if (!mbssid || mbssid < trans_ssid)
1727 return; 1733 return;
1728 new_ie_len -= mbssid[1]; 1734 new_ie_len -= mbssid[1];
1729 rcu_read_lock(); 1735
1730 nontrans_ssid = ieee80211_bss_get_ie(nontrans_bss, WLAN_EID_SSID); 1736 nontrans_ssid = ieee80211_bss_get_ie(nontrans_bss, WLAN_EID_SSID);
1731 if (!nontrans_ssid) { 1737 if (!nontrans_ssid)
1732 rcu_read_unlock();
1733 return; 1738 return;
1734 } 1739
1735 new_ie_len += nontrans_ssid[1]; 1740 new_ie_len += nontrans_ssid[1];
1736 rcu_read_unlock();
1737 1741
1738 /* generate new ie for nontrans BSS 1742 /* generate new ie for nontrans BSS
1739 * 1. replace SSID with nontrans BSS' SSID 1743 * 1. replace SSID with nontrans BSS' SSID
1740 * 2. skip MBSSID IE 1744 * 2. skip MBSSID IE
1741 */ 1745 */
1742 new_ie = kzalloc(new_ie_len, gfp); 1746 new_ie = kzalloc(new_ie_len, GFP_ATOMIC);
1743 if (!new_ie) 1747 if (!new_ie)
1744 return; 1748 return;
1745 new_ies = kzalloc(sizeof(*new_ies) + new_ie_len, gfp); 1749
1750 new_ies = kzalloc(sizeof(*new_ies) + new_ie_len, GFP_ATOMIC);
1746 if (!new_ies) 1751 if (!new_ies)
1747 goto out_free; 1752 goto out_free;
1748 1753
@@ -1896,6 +1901,8 @@ cfg80211_inform_bss_frame_data(struct wiphy *wiphy,
1896 cfg80211_parse_mbssid_frame_data(wiphy, data, mgmt, len, 1901 cfg80211_parse_mbssid_frame_data(wiphy, data, mgmt, len,
1897 &non_tx_data, gfp); 1902 &non_tx_data, gfp);
1898 1903
1904 spin_lock_bh(&wiphy_to_rdev(wiphy)->bss_lock);
1905
1899 /* check if the res has other nontransmitting bss which is not 1906 /* check if the res has other nontransmitting bss which is not
1900 * in MBSSID IE 1907 * in MBSSID IE
1901 */ 1908 */
@@ -1910,8 +1917,9 @@ cfg80211_inform_bss_frame_data(struct wiphy *wiphy,
1910 ies2 = rcu_access_pointer(tmp_bss->ies); 1917 ies2 = rcu_access_pointer(tmp_bss->ies);
1911 if (ies2->tsf < ies1->tsf) 1918 if (ies2->tsf < ies1->tsf)
1912 cfg80211_update_notlisted_nontrans(wiphy, tmp_bss, 1919 cfg80211_update_notlisted_nontrans(wiphy, tmp_bss,
1913 mgmt, len, gfp); 1920 mgmt, len);
1914 } 1921 }
1922 spin_unlock_bh(&wiphy_to_rdev(wiphy)->bss_lock);
1915 1923
1916 return res; 1924 return res;
1917} 1925}
diff --git a/net/wireless/util.c b/net/wireless/util.c
index 419eb12c1e93..5b4ed5bbc542 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -1559,7 +1559,8 @@ bool ieee80211_chandef_to_operating_class(struct cfg80211_chan_def *chandef,
1559 } 1559 }
1560 1560
1561 if (freq == 2484) { 1561 if (freq == 2484) {
1562 if (chandef->width > NL80211_CHAN_WIDTH_40) 1562 /* channel 14 is only for IEEE 802.11b */
1563 if (chandef->width != NL80211_CHAN_WIDTH_20_NOHT)
1563 return false; 1564 return false;
1564 1565
1565 *op_class = 82; /* channel 14 */ 1566 *op_class = 82; /* channel 14 */
diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c
index 7b6529d81c61..cac9e28d852b 100644
--- a/net/wireless/wext-compat.c
+++ b/net/wireless/wext-compat.c
@@ -798,7 +798,7 @@ static int cfg80211_wext_giwfreq(struct net_device *dev,
798{ 798{
799 struct wireless_dev *wdev = dev->ieee80211_ptr; 799 struct wireless_dev *wdev = dev->ieee80211_ptr;
800 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 800 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
801 struct cfg80211_chan_def chandef; 801 struct cfg80211_chan_def chandef = {};
802 int ret; 802 int ret;
803 803
804 switch (wdev->iftype) { 804 switch (wdev->iftype) {
diff --git a/net/wireless/wext-sme.c b/net/wireless/wext-sme.c
index c67d7a82ab13..73fd0eae08ca 100644
--- a/net/wireless/wext-sme.c
+++ b/net/wireless/wext-sme.c
@@ -202,6 +202,7 @@ int cfg80211_mgd_wext_giwessid(struct net_device *dev,
202 struct iw_point *data, char *ssid) 202 struct iw_point *data, char *ssid)
203{ 203{
204 struct wireless_dev *wdev = dev->ieee80211_ptr; 204 struct wireless_dev *wdev = dev->ieee80211_ptr;
205 int ret = 0;
205 206
206 /* call only for station! */ 207 /* call only for station! */
207 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) 208 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
@@ -219,7 +220,10 @@ int cfg80211_mgd_wext_giwessid(struct net_device *dev,
219 if (ie) { 220 if (ie) {
220 data->flags = 1; 221 data->flags = 1;
221 data->length = ie[1]; 222 data->length = ie[1];
222 memcpy(ssid, ie + 2, data->length); 223 if (data->length > IW_ESSID_MAX_SIZE)
224 ret = -EINVAL;
225 else
226 memcpy(ssid, ie + 2, data->length);
223 } 227 }
224 rcu_read_unlock(); 228 rcu_read_unlock();
225 } else if (wdev->wext.connect.ssid && wdev->wext.connect.ssid_len) { 229 } else if (wdev->wext.connect.ssid && wdev->wext.connect.ssid_len) {
@@ -229,7 +233,7 @@ int cfg80211_mgd_wext_giwessid(struct net_device *dev,
229 } 233 }
230 wdev_unlock(wdev); 234 wdev_unlock(wdev);
231 235
232 return 0; 236 return ret;
233} 237}
234 238
235int cfg80211_mgd_wext_siwap(struct net_device *dev, 239int cfg80211_mgd_wext_siwap(struct net_device *dev,
diff --git a/net/x25/x25_dev.c b/net/x25/x25_dev.c
index 5c111bc3c8ea..00e782335cb0 100644
--- a/net/x25/x25_dev.c
+++ b/net/x25/x25_dev.c
@@ -55,7 +55,7 @@ static int x25_receive_data(struct sk_buff *skb, struct x25_neigh *nb)
55 if (!sock_owned_by_user(sk)) { 55 if (!sock_owned_by_user(sk)) {
56 queued = x25_process_rx_frame(sk, skb); 56 queued = x25_process_rx_frame(sk, skb);
57 } else { 57 } else {
58 queued = !sk_add_backlog(sk, skb, sk->sk_rcvbuf); 58 queued = !sk_add_backlog(sk, skb, READ_ONCE(sk->sk_rcvbuf));
59 } 59 }
60 bh_unlock_sock(sk); 60 bh_unlock_sock(sk);
61 sock_put(sk); 61 sock_put(sk);
diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c
index 16d5f353163a..3049af269fbf 100644
--- a/net/xdp/xdp_umem.c
+++ b/net/xdp/xdp_umem.c
@@ -27,6 +27,9 @@ void xdp_add_sk_umem(struct xdp_umem *umem, struct xdp_sock *xs)
27{ 27{
28 unsigned long flags; 28 unsigned long flags;
29 29
30 if (!xs->tx)
31 return;
32
30 spin_lock_irqsave(&umem->xsk_list_lock, flags); 33 spin_lock_irqsave(&umem->xsk_list_lock, flags);
31 list_add_rcu(&xs->list, &umem->xsk_list); 34 list_add_rcu(&xs->list, &umem->xsk_list);
32 spin_unlock_irqrestore(&umem->xsk_list_lock, flags); 35 spin_unlock_irqrestore(&umem->xsk_list_lock, flags);
@@ -36,6 +39,9 @@ void xdp_del_sk_umem(struct xdp_umem *umem, struct xdp_sock *xs)
36{ 39{
37 unsigned long flags; 40 unsigned long flags;
38 41
42 if (!xs->tx)
43 return;
44
39 spin_lock_irqsave(&umem->xsk_list_lock, flags); 45 spin_lock_irqsave(&umem->xsk_list_lock, flags);
40 list_del_rcu(&xs->list); 46 list_del_rcu(&xs->list);
41 spin_unlock_irqrestore(&umem->xsk_list_lock, flags); 47 spin_unlock_irqrestore(&umem->xsk_list_lock, flags);
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index fa8fbb8fa3c8..9044073fbf22 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -305,9 +305,8 @@ out:
305} 305}
306EXPORT_SYMBOL(xsk_umem_consume_tx); 306EXPORT_SYMBOL(xsk_umem_consume_tx);
307 307
308static int xsk_zc_xmit(struct sock *sk) 308static int xsk_zc_xmit(struct xdp_sock *xs)
309{ 309{
310 struct xdp_sock *xs = xdp_sk(sk);
311 struct net_device *dev = xs->dev; 310 struct net_device *dev = xs->dev;
312 311
313 return dev->netdev_ops->ndo_xsk_wakeup(dev, xs->queue_id, 312 return dev->netdev_ops->ndo_xsk_wakeup(dev, xs->queue_id,
@@ -327,11 +326,10 @@ static void xsk_destruct_skb(struct sk_buff *skb)
327 sock_wfree(skb); 326 sock_wfree(skb);
328} 327}
329 328
330static int xsk_generic_xmit(struct sock *sk, struct msghdr *m, 329static int xsk_generic_xmit(struct sock *sk)
331 size_t total_len)
332{ 330{
333 u32 max_batch = TX_BATCH_SIZE;
334 struct xdp_sock *xs = xdp_sk(sk); 331 struct xdp_sock *xs = xdp_sk(sk);
332 u32 max_batch = TX_BATCH_SIZE;
335 bool sent_frame = false; 333 bool sent_frame = false;
336 struct xdp_desc desc; 334 struct xdp_desc desc;
337 struct sk_buff *skb; 335 struct sk_buff *skb;
@@ -394,6 +392,18 @@ out:
394 return err; 392 return err;
395} 393}
396 394
395static int __xsk_sendmsg(struct sock *sk)
396{
397 struct xdp_sock *xs = xdp_sk(sk);
398
399 if (unlikely(!(xs->dev->flags & IFF_UP)))
400 return -ENETDOWN;
401 if (unlikely(!xs->tx))
402 return -ENOBUFS;
403
404 return xs->zc ? xsk_zc_xmit(xs) : xsk_generic_xmit(sk);
405}
406
397static int xsk_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len) 407static int xsk_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)
398{ 408{
399 bool need_wait = !(m->msg_flags & MSG_DONTWAIT); 409 bool need_wait = !(m->msg_flags & MSG_DONTWAIT);
@@ -402,21 +412,18 @@ static int xsk_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)
402 412
403 if (unlikely(!xsk_is_bound(xs))) 413 if (unlikely(!xsk_is_bound(xs)))
404 return -ENXIO; 414 return -ENXIO;
405 if (unlikely(!(xs->dev->flags & IFF_UP))) 415 if (unlikely(need_wait))
406 return -ENETDOWN;
407 if (unlikely(!xs->tx))
408 return -ENOBUFS;
409 if (need_wait)
410 return -EOPNOTSUPP; 416 return -EOPNOTSUPP;
411 417
412 return (xs->zc) ? xsk_zc_xmit(sk) : xsk_generic_xmit(sk, m, total_len); 418 return __xsk_sendmsg(sk);
413} 419}
414 420
415static unsigned int xsk_poll(struct file *file, struct socket *sock, 421static unsigned int xsk_poll(struct file *file, struct socket *sock,
416 struct poll_table_struct *wait) 422 struct poll_table_struct *wait)
417{ 423{
418 unsigned int mask = datagram_poll(file, sock, wait); 424 unsigned int mask = datagram_poll(file, sock, wait);
419 struct xdp_sock *xs = xdp_sk(sock->sk); 425 struct sock *sk = sock->sk;
426 struct xdp_sock *xs = xdp_sk(sk);
420 struct net_device *dev; 427 struct net_device *dev;
421 struct xdp_umem *umem; 428 struct xdp_umem *umem;
422 429
@@ -426,9 +433,14 @@ static unsigned int xsk_poll(struct file *file, struct socket *sock,
426 dev = xs->dev; 433 dev = xs->dev;
427 umem = xs->umem; 434 umem = xs->umem;
428 435
429 if (umem->need_wakeup) 436 if (umem->need_wakeup) {
430 dev->netdev_ops->ndo_xsk_wakeup(dev, xs->queue_id, 437 if (dev->netdev_ops->ndo_xsk_wakeup)
431 umem->need_wakeup); 438 dev->netdev_ops->ndo_xsk_wakeup(dev, xs->queue_id,
439 umem->need_wakeup);
440 else
441 /* Poll needs to drive Tx also in copy mode */
442 __xsk_sendmsg(sk);
443 }
432 444
433 if (xs->rx && !xskq_empty_desc(xs->rx)) 445 if (xs->rx && !xskq_empty_desc(xs->rx))
434 mask |= POLLIN | POLLRDNORM; 446 mask |= POLLIN | POLLRDNORM;
diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
index 6088bc2dc11e..9b599ed66d97 100644
--- a/net/xfrm/xfrm_input.c
+++ b/net/xfrm/xfrm_input.c
@@ -706,7 +706,7 @@ resume:
706 if (err) 706 if (err)
707 goto drop; 707 goto drop;
708 708
709 nf_reset(skb); 709 nf_reset_ct(skb);
710 710
711 if (decaps) { 711 if (decaps) {
712 sp = skb_sec_path(skb); 712 sp = skb_sec_path(skb);
diff --git a/net/xfrm/xfrm_interface.c b/net/xfrm/xfrm_interface.c
index 2ab4859df55a..0f5131bc3342 100644
--- a/net/xfrm/xfrm_interface.c
+++ b/net/xfrm/xfrm_interface.c
@@ -185,7 +185,7 @@ static void xfrmi_scrub_packet(struct sk_buff *skb, bool xnet)
185 skb->skb_iif = 0; 185 skb->skb_iif = 0;
186 skb->ignore_df = 0; 186 skb->ignore_df = 0;
187 skb_dst_drop(skb); 187 skb_dst_drop(skb);
188 nf_reset(skb); 188 nf_reset_ct(skb);
189 nf_reset_trace(skb); 189 nf_reset_trace(skb);
190 190
191 if (!xnet) 191 if (!xnet)
diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
index 9499b35feb92..b1db55b50ba1 100644
--- a/net/xfrm/xfrm_output.c
+++ b/net/xfrm/xfrm_output.c
@@ -502,7 +502,7 @@ int xfrm_output_resume(struct sk_buff *skb, int err)
502 struct net *net = xs_net(skb_dst(skb)->xfrm); 502 struct net *net = xs_net(skb_dst(skb)->xfrm);
503 503
504 while (likely((err = xfrm_output_one(skb, err)) == 0)) { 504 while (likely((err = xfrm_output_one(skb, err)) == 0)) {
505 nf_reset(skb); 505 nf_reset_ct(skb);
506 506
507 err = skb_dst(skb)->ops->local_out(net, skb->sk, skb); 507 err = skb_dst(skb)->ops->local_out(net, skb->sk, skb);
508 if (unlikely(err != 1)) 508 if (unlikely(err != 1))
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 21e939235b39..f2d1e573ea55 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -2808,7 +2808,7 @@ static void xfrm_policy_queue_process(struct timer_list *t)
2808 continue; 2808 continue;
2809 } 2809 }
2810 2810
2811 nf_reset(skb); 2811 nf_reset_ct(skb);
2812 skb_dst_drop(skb); 2812 skb_dst_drop(skb);
2813 skb_dst_set(skb, dst); 2813 skb_dst_set(skb, dst);
2814 2814
diff --git a/samples/bpf/asm_goto_workaround.h b/samples/bpf/asm_goto_workaround.h
index 7409722727ca..7048bb3594d6 100644
--- a/samples/bpf/asm_goto_workaround.h
+++ b/samples/bpf/asm_goto_workaround.h
@@ -3,7 +3,8 @@
3#ifndef __ASM_GOTO_WORKAROUND_H 3#ifndef __ASM_GOTO_WORKAROUND_H
4#define __ASM_GOTO_WORKAROUND_H 4#define __ASM_GOTO_WORKAROUND_H
5 5
6/* this will bring in asm_volatile_goto macro definition 6/*
7 * This will bring in asm_volatile_goto and asm_inline macro definitions
7 * if enabled by compiler and config options. 8 * if enabled by compiler and config options.
8 */ 9 */
9#include <linux/types.h> 10#include <linux/types.h>
@@ -13,5 +14,15 @@
13#define asm_volatile_goto(x...) asm volatile("invalid use of asm_volatile_goto") 14#define asm_volatile_goto(x...) asm volatile("invalid use of asm_volatile_goto")
14#endif 15#endif
15 16
17/*
18 * asm_inline is defined as asm __inline in "include/linux/compiler_types.h"
19 * if supported by the kernel's CC (i.e CONFIG_CC_HAS_ASM_INLINE) which is not
20 * supported by CLANG.
21 */
22#ifdef asm_inline
23#undef asm_inline
24#define asm_inline asm
25#endif
26
16#define volatile(x...) volatile("") 27#define volatile(x...) volatile("")
17#endif 28#endif
diff --git a/samples/bpf/task_fd_query_user.c b/samples/bpf/task_fd_query_user.c
index e39938058223..4c31b305e6ef 100644
--- a/samples/bpf/task_fd_query_user.c
+++ b/samples/bpf/task_fd_query_user.c
@@ -13,6 +13,7 @@
13#include <sys/resource.h> 13#include <sys/resource.h>
14#include <sys/types.h> 14#include <sys/types.h>
15#include <sys/stat.h> 15#include <sys/stat.h>
16#include <linux/perf_event.h>
16 17
17#include "libbpf.h" 18#include "libbpf.h"
18#include "bpf_load.h" 19#include "bpf_load.h"
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 4b0432e095ae..10ba926ae292 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -143,11 +143,6 @@ cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || e
143# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y) 143# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
144ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3)) 144ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3))
145 145
146# ar-option
147# Usage: KBUILD_ARFLAGS := $(call ar-option,D)
148# Important: no spaces around options
149ar-option = $(call try-run, $(AR) rc$(1) "$$TMP",$(1),$(2))
150
151# ld-version 146# ld-version
152# Note this is mainly for HJ Lu's 3 number binutil versions 147# Note this is mainly for HJ Lu's 3 number binutil versions
153ld-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh) 148ld-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh)
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index f72aba64d611..a9e47953ca53 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -389,7 +389,7 @@ $(sort $(subdir-obj-y)): $(subdir-ym) ;
389ifdef builtin-target 389ifdef builtin-target
390 390
391quiet_cmd_ar_builtin = AR $@ 391quiet_cmd_ar_builtin = AR $@
392 cmd_ar_builtin = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) $@ $(real-prereqs) 392 cmd_ar_builtin = rm -f $@; $(AR) cDPrST $@ $(real-prereqs)
393 393
394$(builtin-target): $(real-obj-y) FORCE 394$(builtin-target): $(real-obj-y) FORCE
395 $(call if_changed,ar_builtin) 395 $(call if_changed,ar_builtin)
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 4a0cdd6f5909..179d55af5852 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -232,7 +232,7 @@ quiet_cmd_ld = LD $@
232# --------------------------------------------------------------------------- 232# ---------------------------------------------------------------------------
233 233
234quiet_cmd_ar = AR $@ 234quiet_cmd_ar = AR $@
235 cmd_ar = rm -f $@; $(AR) rcsTP$(KBUILD_ARFLAGS) $@ $(real-prereqs) 235 cmd_ar = rm -f $@; $(AR) cDPrsT $@ $(real-prereqs)
236 236
237# Objcopy 237# Objcopy
238# --------------------------------------------------------------------------- 238# ---------------------------------------------------------------------------
diff --git a/scripts/coccinelle/api/devm_platform_ioremap_resource.cocci b/scripts/coccinelle/api/devm_platform_ioremap_resource.cocci
deleted file mode 100644
index 56a2e261d61d..000000000000
--- a/scripts/coccinelle/api/devm_platform_ioremap_resource.cocci
+++ /dev/null
@@ -1,60 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2/// Use devm_platform_ioremap_resource helper which wraps
3/// platform_get_resource() and devm_ioremap_resource() together.
4///
5// Confidence: High
6// Copyright: (C) 2019 Himanshu Jha GPLv2.
7// Copyright: (C) 2019 Julia Lawall, Inria/LIP6. GPLv2.
8// Keywords: platform_get_resource, devm_ioremap_resource,
9// Keywords: devm_platform_ioremap_resource
10
11virtual patch
12virtual report
13
14@r depends on patch && !report@
15expression e1, e2, arg1, arg2, arg3;
16identifier id;
17@@
18
19(
20- id = platform_get_resource(arg1, IORESOURCE_MEM, arg2);
21|
22- struct resource *id = platform_get_resource(arg1, IORESOURCE_MEM, arg2);
23)
24 ... when != id
25- e1 = devm_ioremap_resource(arg3, id);
26+ e1 = devm_platform_ioremap_resource(arg1, arg2);
27 ... when != id
28? id = e2
29
30@r1 depends on patch && !report@
31identifier r.id;
32type T;
33@@
34
35- T *id;
36 ...when != id
37
38@r2 depends on report && !patch@
39identifier id;
40expression e1, e2, arg1, arg2, arg3;
41position j0;
42@@
43
44(
45 id = platform_get_resource(arg1, IORESOURCE_MEM, arg2);
46|
47 struct resource *id = platform_get_resource(arg1, IORESOURCE_MEM, arg2);
48)
49 ... when != id
50 e1@j0 = devm_ioremap_resource(arg3, id);
51 ... when != id
52? id = e2
53
54@script:python depends on report && !patch@
55e1 << r2.e1;
56j0 << r2.j0;
57@@
58
59msg = "WARNING: Use devm_platform_ioremap_resource for %s" % (e1)
60coccilib.report.print_report(j0[0], msg)
diff --git a/scripts/coccinelle/misc/add_namespace.cocci b/scripts/coccinelle/misc/add_namespace.cocci
index c832bb6445a8..99e93a6c2e24 100644
--- a/scripts/coccinelle/misc/add_namespace.cocci
+++ b/scripts/coccinelle/misc/add_namespace.cocci
@@ -6,6 +6,8 @@
6/// add a missing namespace tag to a module source file. 6/// add a missing namespace tag to a module source file.
7/// 7///
8 8
9virtual report
10
9@has_ns_import@ 11@has_ns_import@
10declarer name MODULE_IMPORT_NS; 12declarer name MODULE_IMPORT_NS;
11identifier virtual.ns; 13identifier virtual.ns;
diff --git a/scripts/gdb/linux/dmesg.py b/scripts/gdb/linux/dmesg.py
index 6d2e09a2ad2f..2fa7bb83885f 100644
--- a/scripts/gdb/linux/dmesg.py
+++ b/scripts/gdb/linux/dmesg.py
@@ -16,6 +16,8 @@ import sys
16 16
17from linux import utils 17from linux import utils
18 18
19printk_log_type = utils.CachedType("struct printk_log")
20
19 21
20class LxDmesg(gdb.Command): 22class LxDmesg(gdb.Command):
21 """Print Linux kernel log buffer.""" 23 """Print Linux kernel log buffer."""
@@ -42,9 +44,14 @@ class LxDmesg(gdb.Command):
42 b = utils.read_memoryview(inf, log_buf_addr, log_next_idx) 44 b = utils.read_memoryview(inf, log_buf_addr, log_next_idx)
43 log_buf = a.tobytes() + b.tobytes() 45 log_buf = a.tobytes() + b.tobytes()
44 46
47 length_offset = printk_log_type.get_type()['len'].bitpos // 8
48 text_len_offset = printk_log_type.get_type()['text_len'].bitpos // 8
49 time_stamp_offset = printk_log_type.get_type()['ts_nsec'].bitpos // 8
50 text_offset = printk_log_type.get_type().sizeof
51
45 pos = 0 52 pos = 0
46 while pos < log_buf.__len__(): 53 while pos < log_buf.__len__():
47 length = utils.read_u16(log_buf[pos + 8:pos + 10]) 54 length = utils.read_u16(log_buf, pos + length_offset)
48 if length == 0: 55 if length == 0:
49 if log_buf_2nd_half == -1: 56 if log_buf_2nd_half == -1:
50 gdb.write("Corrupted log buffer!\n") 57 gdb.write("Corrupted log buffer!\n")
@@ -52,10 +59,11 @@ class LxDmesg(gdb.Command):
52 pos = log_buf_2nd_half 59 pos = log_buf_2nd_half
53 continue 60 continue
54 61
55 text_len = utils.read_u16(log_buf[pos + 10:pos + 12]) 62 text_len = utils.read_u16(log_buf, pos + text_len_offset)
56 text = log_buf[pos + 16:pos + 16 + text_len].decode( 63 text_start = pos + text_offset
64 text = log_buf[text_start:text_start + text_len].decode(
57 encoding='utf8', errors='replace') 65 encoding='utf8', errors='replace')
58 time_stamp = utils.read_u64(log_buf[pos:pos + 8]) 66 time_stamp = utils.read_u64(log_buf, pos + time_stamp_offset)
59 67
60 for line in text.splitlines(): 68 for line in text.splitlines():
61 msg = u"[{time:12.6f}] {line}\n".format( 69 msg = u"[{time:12.6f}] {line}\n".format(
diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
index 34e40e96dee2..7b7c2fafbc68 100644
--- a/scripts/gdb/linux/symbols.py
+++ b/scripts/gdb/linux/symbols.py
@@ -15,7 +15,7 @@ import gdb
15import os 15import os
16import re 16import re
17 17
18from linux import modules 18from linux import modules, utils
19 19
20 20
21if hasattr(gdb, 'Breakpoint'): 21if hasattr(gdb, 'Breakpoint'):
@@ -116,6 +116,12 @@ lx-symbols command."""
116 module_file = self._get_module_file(module_name) 116 module_file = self._get_module_file(module_name)
117 117
118 if module_file: 118 if module_file:
119 if utils.is_target_arch('s390'):
120 # Module text is preceded by PLT stubs on s390.
121 module_arch = module['arch']
122 plt_offset = int(module_arch['plt_offset'])
123 plt_size = int(module_arch['plt_size'])
124 module_addr = hex(int(module_addr, 0) + plt_offset + plt_size)
119 gdb.write("loading @{addr}: {filename}\n".format( 125 gdb.write("loading @{addr}: {filename}\n".format(
120 addr=module_addr, filename=module_file)) 126 addr=module_addr, filename=module_file))
121 cmdline = "add-symbol-file {filename} {addr}{sections}".format( 127 cmdline = "add-symbol-file {filename} {addr}{sections}".format(
diff --git a/scripts/gdb/linux/utils.py b/scripts/gdb/linux/utils.py
index bc67126118c4..ea94221dbd39 100644
--- a/scripts/gdb/linux/utils.py
+++ b/scripts/gdb/linux/utils.py
@@ -92,15 +92,16 @@ def read_memoryview(inf, start, length):
92 return memoryview(inf.read_memory(start, length)) 92 return memoryview(inf.read_memory(start, length))
93 93
94 94
95def read_u16(buffer): 95def read_u16(buffer, offset):
96 buffer_val = buffer[offset:offset + 2]
96 value = [0, 0] 97 value = [0, 0]
97 98
98 if type(buffer[0]) is str: 99 if type(buffer_val[0]) is str:
99 value[0] = ord(buffer[0]) 100 value[0] = ord(buffer_val[0])
100 value[1] = ord(buffer[1]) 101 value[1] = ord(buffer_val[1])
101 else: 102 else:
102 value[0] = buffer[0] 103 value[0] = buffer_val[0]
103 value[1] = buffer[1] 104 value[1] = buffer_val[1]
104 105
105 if get_target_endianness() == LITTLE_ENDIAN: 106 if get_target_endianness() == LITTLE_ENDIAN:
106 return value[0] + (value[1] << 8) 107 return value[0] + (value[1] << 8)
@@ -108,18 +109,18 @@ def read_u16(buffer):
108 return value[1] + (value[0] << 8) 109 return value[1] + (value[0] << 8)
109 110
110 111
111def read_u32(buffer): 112def read_u32(buffer, offset):
112 if get_target_endianness() == LITTLE_ENDIAN: 113 if get_target_endianness() == LITTLE_ENDIAN:
113 return read_u16(buffer[0:2]) + (read_u16(buffer[2:4]) << 16) 114 return read_u16(buffer, offset) + (read_u16(buffer, offset + 2) << 16)
114 else: 115 else:
115 return read_u16(buffer[2:4]) + (read_u16(buffer[0:2]) << 16) 116 return read_u16(buffer, offset + 2) + (read_u16(buffer, offset) << 16)
116 117
117 118
118def read_u64(buffer): 119def read_u64(buffer, offset):
119 if get_target_endianness() == LITTLE_ENDIAN: 120 if get_target_endianness() == LITTLE_ENDIAN:
120 return read_u32(buffer[0:4]) + (read_u32(buffer[4:8]) << 32) 121 return read_u32(buffer, offset) + (read_u32(buffer, offset + 4) << 32)
121 else: 122 else:
122 return read_u32(buffer[4:8]) + (read_u32(buffer[0:4]) << 32) 123 return read_u32(buffer, offset + 4) + (read_u32(buffer, offset) << 32)
123 124
124 125
125target_arch = None 126target_arch = None
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 3961941e8e7a..936d3ad23c83 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -166,7 +166,7 @@ struct symbol {
166 struct module *module; 166 struct module *module;
167 unsigned int crc; 167 unsigned int crc;
168 int crc_valid; 168 int crc_valid;
169 const char *namespace; 169 char *namespace;
170 unsigned int weak:1; 170 unsigned int weak:1;
171 unsigned int vmlinux:1; /* 1 if symbol is defined in vmlinux */ 171 unsigned int vmlinux:1; /* 1 if symbol is defined in vmlinux */
172 unsigned int kernel:1; /* 1 if symbol is from kernel 172 unsigned int kernel:1; /* 1 if symbol is from kernel
@@ -348,20 +348,18 @@ static enum export export_from_sec(struct elf_info *elf, unsigned int sec)
348 return export_unknown; 348 return export_unknown;
349} 349}
350 350
351static const char *sym_extract_namespace(const char **symname) 351static char *sym_extract_namespace(const char **symname)
352{ 352{
353 size_t n; 353 char *namespace = NULL;
354 char *dupsymname; 354 char *ns_separator;
355 355
356 n = strcspn(*symname, "."); 356 ns_separator = strchr(*symname, '.');
357 if (n < strlen(*symname) - 1) { 357 if (ns_separator) {
358 dupsymname = NOFAIL(strdup(*symname)); 358 namespace = NOFAIL(strndup(*symname, ns_separator - *symname));
359 dupsymname[n] = '\0'; 359 *symname = ns_separator + 1;
360 *symname = dupsymname;
361 return dupsymname + n + 1;
362 } 360 }
363 361
364 return NULL; 362 return namespace;
365} 363}
366 364
367/** 365/**
@@ -375,7 +373,6 @@ static struct symbol *sym_add_exported(const char *name, const char *namespace,
375 373
376 if (!s) { 374 if (!s) {
377 s = new_symbol(name, mod, export); 375 s = new_symbol(name, mod, export);
378 s->namespace = namespace;
379 } else { 376 } else {
380 if (!s->preloaded) { 377 if (!s->preloaded) {
381 warn("%s: '%s' exported twice. Previous export was in %s%s\n", 378 warn("%s: '%s' exported twice. Previous export was in %s%s\n",
@@ -386,6 +383,8 @@ static struct symbol *sym_add_exported(const char *name, const char *namespace,
386 s->module = mod; 383 s->module = mod;
387 } 384 }
388 } 385 }
386 free(s->namespace);
387 s->namespace = namespace ? strdup(namespace) : NULL;
389 s->preloaded = 0; 388 s->preloaded = 0;
390 s->vmlinux = is_vmlinux(mod->name); 389 s->vmlinux = is_vmlinux(mod->name);
391 s->kernel = 0; 390 s->kernel = 0;
@@ -672,7 +671,8 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
672 unsigned int crc; 671 unsigned int crc;
673 enum export export; 672 enum export export;
674 bool is_crc = false; 673 bool is_crc = false;
675 const char *name, *namespace; 674 const char *name;
675 char *namespace;
676 676
677 if ((!is_vmlinux(mod->name) || mod->is_dot_o) && 677 if ((!is_vmlinux(mod->name) || mod->is_dot_o) &&
678 strstarts(symname, "__ksymtab")) 678 strstarts(symname, "__ksymtab"))
@@ -747,6 +747,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
747 name = symname + strlen("__ksymtab_"); 747 name = symname + strlen("__ksymtab_");
748 namespace = sym_extract_namespace(&name); 748 namespace = sym_extract_namespace(&name);
749 sym_add_exported(name, namespace, mod, export); 749 sym_add_exported(name, namespace, mod, export);
750 free(namespace);
750 } 751 }
751 if (strcmp(symname, "init_module") == 0) 752 if (strcmp(symname, "init_module") == 0)
752 mod->has_init = 1; 753 mod->has_init = 1;
@@ -2195,7 +2196,7 @@ static int check_exports(struct module *mod)
2195 else 2196 else
2196 basename = mod->name; 2197 basename = mod->name;
2197 2198
2198 if (exp->namespace) { 2199 if (exp->namespace && exp->namespace[0]) {
2199 add_namespace(&mod->required_namespaces, 2200 add_namespace(&mod->required_namespaces,
2200 exp->namespace); 2201 exp->namespace);
2201 2202
@@ -2652,15 +2653,20 @@ int main(int argc, char **argv)
2652 fatal("modpost: Section mismatches detected.\n" 2653 fatal("modpost: Section mismatches detected.\n"
2653 "Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.\n"); 2654 "Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.\n");
2654 for (n = 0; n < SYMBOL_HASH_SIZE; n++) { 2655 for (n = 0; n < SYMBOL_HASH_SIZE; n++) {
2655 struct symbol *s = symbolhash[n]; 2656 struct symbol *s;
2657
2658 for (s = symbolhash[n]; s; s = s->next) {
2659 /*
2660 * Do not check "vmlinux". This avoids the same warnings
2661 * shown twice, and false-positives for ARCH=um.
2662 */
2663 if (is_vmlinux(s->module->name) && !s->module->is_dot_o)
2664 continue;
2656 2665
2657 while (s) {
2658 if (s->is_static) 2666 if (s->is_static)
2659 warn("\"%s\" [%s] is a static %s\n", 2667 warn("\"%s\" [%s] is a static %s\n",
2660 s->name, s->module->name, 2668 s->name, s->module->name,
2661 export_str(s->export)); 2669 export_str(s->export));
2662
2663 s = s->next;
2664 } 2670 }
2665 } 2671 }
2666 2672
diff --git a/scripts/namespace.pl b/scripts/namespace.pl
index 6135574a6f39..1da7bca201a4 100755
--- a/scripts/namespace.pl
+++ b/scripts/namespace.pl
@@ -65,13 +65,14 @@
65use warnings; 65use warnings;
66use strict; 66use strict;
67use File::Find; 67use File::Find;
68use File::Spec;
68 69
69my $nm = ($ENV{'NM'} || "nm") . " -p"; 70my $nm = ($ENV{'NM'} || "nm") . " -p";
70my $objdump = ($ENV{'OBJDUMP'} || "objdump") . " -s -j .comment"; 71my $objdump = ($ENV{'OBJDUMP'} || "objdump") . " -s -j .comment";
71my $srctree = ""; 72my $srctree = File::Spec->curdir();
72my $objtree = ""; 73my $objtree = File::Spec->curdir();
73$srctree = "$ENV{'srctree'}/" if (exists($ENV{'srctree'})); 74$srctree = File::Spec->rel2abs($ENV{'srctree'}) if (exists($ENV{'srctree'}));
74$objtree = "$ENV{'objtree'}/" if (exists($ENV{'objtree'})); 75$objtree = File::Spec->rel2abs($ENV{'objtree'}) if (exists($ENV{'objtree'}));
75 76
76if ($#ARGV != -1) { 77if ($#ARGV != -1) {
77 print STDERR "usage: $0 takes no parameters\n"; 78 print STDERR "usage: $0 takes no parameters\n";
@@ -231,9 +232,9 @@ sub do_nm
231 } 232 }
232 ($source = $basename) =~ s/\.o$//; 233 ($source = $basename) =~ s/\.o$//;
233 if (-e "$source.c" || -e "$source.S") { 234 if (-e "$source.c" || -e "$source.S") {
234 $source = "$objtree$File::Find::dir/$source"; 235 $source = File::Spec->catfile($objtree, $File::Find::dir, $source)
235 } else { 236 } else {
236 $source = "$srctree$File::Find::dir/$source"; 237 $source = File::Spec->catfile($srctree, $File::Find::dir, $source)
237 } 238 }
238 if (! -e "$source.c" && ! -e "$source.S") { 239 if (! -e "$source.c" && ! -e "$source.S") {
239 # No obvious source, exclude the object if it is conglomerate 240 # No obvious source, exclude the object if it is conglomerate
diff --git a/scripts/nsdeps b/scripts/nsdeps
index ac2b6031dd13..3754dac13b31 100644
--- a/scripts/nsdeps
+++ b/scripts/nsdeps
@@ -1,4 +1,4 @@
1#!/bin/bash 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0 2# SPDX-License-Identifier: GPL-2.0
3# Linux kernel symbol namespace import generator 3# Linux kernel symbol namespace import generator
4# 4#
@@ -41,7 +41,7 @@ generate_deps() {
41 for source_file in $mod_source_files; do 41 for source_file in $mod_source_files; do
42 sed '/MODULE_IMPORT_NS/Q' $source_file > ${source_file}.tmp 42 sed '/MODULE_IMPORT_NS/Q' $source_file > ${source_file}.tmp
43 offset=$(wc -l ${source_file}.tmp | awk '{print $1;}') 43 offset=$(wc -l ${source_file}.tmp | awk '{print $1;}')
44 cat $source_file | grep MODULE_IMPORT_NS | sort -u >> ${source_file}.tmp 44 cat $source_file | grep MODULE_IMPORT_NS | LANG=C sort -u >> ${source_file}.tmp
45 tail -n +$((offset +1)) ${source_file} | grep -v MODULE_IMPORT_NS >> ${source_file}.tmp 45 tail -n +$((offset +1)) ${source_file} | grep -v MODULE_IMPORT_NS >> ${source_file}.tmp
46 if ! diff -q ${source_file} ${source_file}.tmp; then 46 if ! diff -q ${source_file} ${source_file}.tmp; then
47 mv ${source_file}.tmp ${source_file} 47 mv ${source_file}.tmp ${source_file}
diff --git a/scripts/recordmcount.h b/scripts/recordmcount.h
index 8f0a278ce0af..74eab03e31d4 100644
--- a/scripts/recordmcount.h
+++ b/scripts/recordmcount.h
@@ -389,11 +389,8 @@ static int nop_mcount(Elf_Shdr const *const relhdr,
389 mcountsym = get_mcountsym(sym0, relp, str0); 389 mcountsym = get_mcountsym(sym0, relp, str0);
390 390
391 if (mcountsym == Elf_r_sym(relp) && !is_fake_mcount(relp)) { 391 if (mcountsym == Elf_r_sym(relp) && !is_fake_mcount(relp)) {
392 if (make_nop) { 392 if (make_nop)
393 ret = make_nop((void *)ehdr, _w(shdr->sh_offset) + _w(relp->r_offset)); 393 ret = make_nop((void *)ehdr, _w(shdr->sh_offset) + _w(relp->r_offset));
394 if (ret < 0)
395 return -1;
396 }
397 if (warn_on_notrace_sect && !once) { 394 if (warn_on_notrace_sect && !once) {
398 printf("Section %s has mcount callers being ignored\n", 395 printf("Section %s has mcount callers being ignored\n",
399 txtname); 396 txtname);
diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index 365b3c2b8f43..220dae0db3f1 100755
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -126,7 +126,7 @@ scm_version()
126 126
127collect_files() 127collect_files()
128{ 128{
129 local file res 129 local file res=
130 130
131 for file; do 131 for file; do
132 case "$file" in 132 case "$file" in
diff --git a/security/integrity/Makefile b/security/integrity/Makefile
index 19faace69644..35e6ca773734 100644
--- a/security/integrity/Makefile
+++ b/security/integrity/Makefile
@@ -13,9 +13,6 @@ integrity-$(CONFIG_INTEGRITY_PLATFORM_KEYRING) += platform_certs/platform_keyrin
13integrity-$(CONFIG_LOAD_UEFI_KEYS) += platform_certs/efi_parser.o \ 13integrity-$(CONFIG_LOAD_UEFI_KEYS) += platform_certs/efi_parser.o \
14 platform_certs/load_uefi.o 14 platform_certs/load_uefi.o
15integrity-$(CONFIG_LOAD_IPL_KEYS) += platform_certs/load_ipl_s390.o 15integrity-$(CONFIG_LOAD_IPL_KEYS) += platform_certs/load_ipl_s390.o
16$(obj)/load_uefi.o: KBUILD_CFLAGS += -fshort-wchar
17 16
18subdir-$(CONFIG_IMA) += ima
19obj-$(CONFIG_IMA) += ima/ 17obj-$(CONFIG_IMA) += ima/
20subdir-$(CONFIG_EVM) += evm
21obj-$(CONFIG_EVM) += evm/ 18obj-$(CONFIG_EVM) += evm/
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index 3a29e7c24ba9..a5813c7629c1 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -1946,7 +1946,14 @@ static int convert_context(struct context *oldc, struct context *newc, void *p)
1946 rc = string_to_context_struct(args->newp, NULL, s, 1946 rc = string_to_context_struct(args->newp, NULL, s,
1947 newc, SECSID_NULL); 1947 newc, SECSID_NULL);
1948 if (rc == -EINVAL) { 1948 if (rc == -EINVAL) {
1949 /* Retain string representation for later mapping. */ 1949 /*
1950 * Retain string representation for later mapping.
1951 *
1952 * IMPORTANT: We need to copy the contents of oldc->str
1953 * back into s again because string_to_context_struct()
1954 * may have garbled it.
1955 */
1956 memcpy(s, oldc->str, oldc->len);
1950 context_init(newc); 1957 context_init(newc);
1951 newc->str = s; 1958 newc->str = s;
1952 newc->len = oldc->len; 1959 newc->len = oldc->len;
diff --git a/sound/hda/ext/hdac_ext_controller.c b/sound/hda/ext/hdac_ext_controller.c
index 211ca85acd8c..cfab60d88c92 100644
--- a/sound/hda/ext/hdac_ext_controller.c
+++ b/sound/hda/ext/hdac_ext_controller.c
@@ -271,6 +271,11 @@ int snd_hdac_ext_bus_link_get(struct hdac_bus *bus,
271 ret = snd_hdac_ext_bus_link_power_up(link); 271 ret = snd_hdac_ext_bus_link_power_up(link);
272 272
273 /* 273 /*
274 * clear the register to invalidate all the output streams
275 */
276 snd_hdac_updatew(link->ml_addr, AZX_REG_ML_LOSIDV,
277 ML_LOSIDV_STREAM_MASK, 0);
278 /*
274 * wait for 521usec for codec to report status 279 * wait for 521usec for codec to report status
275 * HDA spec section 4.3 - Codec Discovery 280 * HDA spec section 4.3 - Codec Discovery
276 */ 281 */
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index bca5de78e9ad..795cbda32cbb 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -3474,6 +3474,8 @@ static int patch_nvhdmi(struct hda_codec *codec)
3474 nvhdmi_chmap_cea_alloc_validate_get_type; 3474 nvhdmi_chmap_cea_alloc_validate_get_type;
3475 spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate; 3475 spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate;
3476 3476
3477 codec->link_down_at_suspend = 1;
3478
3477 generic_acomp_init(codec, &nvhdmi_audio_ops, nvhdmi_port2pin); 3479 generic_acomp_init(codec, &nvhdmi_audio_ops, nvhdmi_port2pin);
3478 3480
3479 return 0; 3481 return 0;
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index b000b36ac3c6..ce4f11659765 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -5358,6 +5358,17 @@ static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
5358 } 5358 }
5359} 5359}
5360 5360
5361static void alc256_fixup_dell_xps_13_headphone_noise2(struct hda_codec *codec,
5362 const struct hda_fixup *fix,
5363 int action)
5364{
5365 if (action != HDA_FIXUP_ACT_PRE_PROBE)
5366 return;
5367
5368 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 0, HDA_AMP_VOLMASK, 1);
5369 snd_hda_override_wcaps(codec, 0x1a, get_wcaps(codec, 0x1a) & ~AC_WCAP_IN_AMP);
5370}
5371
5361static void alc269_fixup_limit_int_mic_boost(struct hda_codec *codec, 5372static void alc269_fixup_limit_int_mic_boost(struct hda_codec *codec,
5362 const struct hda_fixup *fix, 5373 const struct hda_fixup *fix,
5363 int action) 5374 int action)
@@ -5822,6 +5833,7 @@ enum {
5822 ALC298_FIXUP_DELL_AIO_MIC_NO_PRESENCE, 5833 ALC298_FIXUP_DELL_AIO_MIC_NO_PRESENCE,
5823 ALC275_FIXUP_DELL_XPS, 5834 ALC275_FIXUP_DELL_XPS,
5824 ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE, 5835 ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE,
5836 ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE2,
5825 ALC293_FIXUP_LENOVO_SPK_NOISE, 5837 ALC293_FIXUP_LENOVO_SPK_NOISE,
5826 ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY, 5838 ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY,
5827 ALC255_FIXUP_DELL_SPK_NOISE, 5839 ALC255_FIXUP_DELL_SPK_NOISE,
@@ -5869,6 +5881,7 @@ enum {
5869 ALC225_FIXUP_WYSE_AUTO_MUTE, 5881 ALC225_FIXUP_WYSE_AUTO_MUTE,
5870 ALC225_FIXUP_WYSE_DISABLE_MIC_VREF, 5882 ALC225_FIXUP_WYSE_DISABLE_MIC_VREF,
5871 ALC286_FIXUP_ACER_AIO_HEADSET_MIC, 5883 ALC286_FIXUP_ACER_AIO_HEADSET_MIC,
5884 ALC256_FIXUP_ASUS_HEADSET_MIC,
5872 ALC256_FIXUP_ASUS_MIC_NO_PRESENCE, 5885 ALC256_FIXUP_ASUS_MIC_NO_PRESENCE,
5873 ALC299_FIXUP_PREDATOR_SPK, 5886 ALC299_FIXUP_PREDATOR_SPK,
5874 ALC294_FIXUP_ASUS_INTSPK_HEADSET_MIC, 5887 ALC294_FIXUP_ASUS_INTSPK_HEADSET_MIC,
@@ -6558,6 +6571,12 @@ static const struct hda_fixup alc269_fixups[] = {
6558 .chained = true, 6571 .chained = true,
6559 .chain_id = ALC255_FIXUP_DELL1_MIC_NO_PRESENCE 6572 .chain_id = ALC255_FIXUP_DELL1_MIC_NO_PRESENCE
6560 }, 6573 },
6574 [ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE2] = {
6575 .type = HDA_FIXUP_FUNC,
6576 .v.func = alc256_fixup_dell_xps_13_headphone_noise2,
6577 .chained = true,
6578 .chain_id = ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE
6579 },
6561 [ALC293_FIXUP_LENOVO_SPK_NOISE] = { 6580 [ALC293_FIXUP_LENOVO_SPK_NOISE] = {
6562 .type = HDA_FIXUP_FUNC, 6581 .type = HDA_FIXUP_FUNC,
6563 .v.func = alc_fixup_disable_aamix, 6582 .v.func = alc_fixup_disable_aamix,
@@ -6912,6 +6931,15 @@ static const struct hda_fixup alc269_fixups[] = {
6912 .chained = true, 6931 .chained = true,
6913 .chain_id = ALC286_FIXUP_ACER_AIO_MIC_NO_PRESENCE 6932 .chain_id = ALC286_FIXUP_ACER_AIO_MIC_NO_PRESENCE
6914 }, 6933 },
6934 [ALC256_FIXUP_ASUS_HEADSET_MIC] = {
6935 .type = HDA_FIXUP_PINS,
6936 .v.pins = (const struct hda_pintbl[]) {
6937 { 0x19, 0x03a11020 }, /* headset mic with jack detect */
6938 { }
6939 },
6940 .chained = true,
6941 .chain_id = ALC256_FIXUP_ASUS_HEADSET_MODE
6942 },
6915 [ALC256_FIXUP_ASUS_MIC_NO_PRESENCE] = { 6943 [ALC256_FIXUP_ASUS_MIC_NO_PRESENCE] = {
6916 .type = HDA_FIXUP_PINS, 6944 .type = HDA_FIXUP_PINS,
6917 .v.pins = (const struct hda_pintbl[]) { 6945 .v.pins = (const struct hda_pintbl[]) {
@@ -7001,17 +7029,17 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
7001 SND_PCI_QUIRK(0x1028, 0x06de, "Dell", ALC293_FIXUP_DISABLE_AAMIX_MULTIJACK), 7029 SND_PCI_QUIRK(0x1028, 0x06de, "Dell", ALC293_FIXUP_DISABLE_AAMIX_MULTIJACK),
7002 SND_PCI_QUIRK(0x1028, 0x06df, "Dell", ALC293_FIXUP_DISABLE_AAMIX_MULTIJACK), 7030 SND_PCI_QUIRK(0x1028, 0x06df, "Dell", ALC293_FIXUP_DISABLE_AAMIX_MULTIJACK),
7003 SND_PCI_QUIRK(0x1028, 0x06e0, "Dell", ALC293_FIXUP_DISABLE_AAMIX_MULTIJACK), 7031 SND_PCI_QUIRK(0x1028, 0x06e0, "Dell", ALC293_FIXUP_DISABLE_AAMIX_MULTIJACK),
7004 SND_PCI_QUIRK(0x1028, 0x0704, "Dell XPS 13 9350", ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE), 7032 SND_PCI_QUIRK(0x1028, 0x0704, "Dell XPS 13 9350", ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE2),
7005 SND_PCI_QUIRK(0x1028, 0x0706, "Dell Inspiron 7559", ALC256_FIXUP_DELL_INSPIRON_7559_SUBWOOFER), 7033 SND_PCI_QUIRK(0x1028, 0x0706, "Dell Inspiron 7559", ALC256_FIXUP_DELL_INSPIRON_7559_SUBWOOFER),
7006 SND_PCI_QUIRK(0x1028, 0x0725, "Dell Inspiron 3162", ALC255_FIXUP_DELL_SPK_NOISE), 7034 SND_PCI_QUIRK(0x1028, 0x0725, "Dell Inspiron 3162", ALC255_FIXUP_DELL_SPK_NOISE),
7007 SND_PCI_QUIRK(0x1028, 0x0738, "Dell Precision 5820", ALC269_FIXUP_NO_SHUTUP), 7035 SND_PCI_QUIRK(0x1028, 0x0738, "Dell Precision 5820", ALC269_FIXUP_NO_SHUTUP),
7008 SND_PCI_QUIRK(0x1028, 0x075b, "Dell XPS 13 9360", ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE), 7036 SND_PCI_QUIRK(0x1028, 0x075b, "Dell XPS 13 9360", ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE2),
7009 SND_PCI_QUIRK(0x1028, 0x075c, "Dell XPS 27 7760", ALC298_FIXUP_SPK_VOLUME), 7037 SND_PCI_QUIRK(0x1028, 0x075c, "Dell XPS 27 7760", ALC298_FIXUP_SPK_VOLUME),
7010 SND_PCI_QUIRK(0x1028, 0x075d, "Dell AIO", ALC298_FIXUP_SPK_VOLUME), 7038 SND_PCI_QUIRK(0x1028, 0x075d, "Dell AIO", ALC298_FIXUP_SPK_VOLUME),
7011 SND_PCI_QUIRK(0x1028, 0x07b0, "Dell Precision 7520", ALC295_FIXUP_DISABLE_DAC3), 7039 SND_PCI_QUIRK(0x1028, 0x07b0, "Dell Precision 7520", ALC295_FIXUP_DISABLE_DAC3),
7012 SND_PCI_QUIRK(0x1028, 0x0798, "Dell Inspiron 17 7000 Gaming", ALC256_FIXUP_DELL_INSPIRON_7559_SUBWOOFER), 7040 SND_PCI_QUIRK(0x1028, 0x0798, "Dell Inspiron 17 7000 Gaming", ALC256_FIXUP_DELL_INSPIRON_7559_SUBWOOFER),
7013 SND_PCI_QUIRK(0x1028, 0x080c, "Dell WYSE", ALC225_FIXUP_DELL_WYSE_MIC_NO_PRESENCE), 7041 SND_PCI_QUIRK(0x1028, 0x080c, "Dell WYSE", ALC225_FIXUP_DELL_WYSE_MIC_NO_PRESENCE),
7014 SND_PCI_QUIRK(0x1028, 0x082a, "Dell XPS 13 9360", ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE), 7042 SND_PCI_QUIRK(0x1028, 0x082a, "Dell XPS 13 9360", ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE2),
7015 SND_PCI_QUIRK(0x1028, 0x084b, "Dell", ALC274_FIXUP_DELL_AIO_LINEOUT_VERB), 7043 SND_PCI_QUIRK(0x1028, 0x084b, "Dell", ALC274_FIXUP_DELL_AIO_LINEOUT_VERB),
7016 SND_PCI_QUIRK(0x1028, 0x084e, "Dell", ALC274_FIXUP_DELL_AIO_LINEOUT_VERB), 7044 SND_PCI_QUIRK(0x1028, 0x084e, "Dell", ALC274_FIXUP_DELL_AIO_LINEOUT_VERB),
7017 SND_PCI_QUIRK(0x1028, 0x0871, "Dell Precision 3630", ALC255_FIXUP_DELL_HEADSET_MIC), 7045 SND_PCI_QUIRK(0x1028, 0x0871, "Dell Precision 3630", ALC255_FIXUP_DELL_HEADSET_MIC),
@@ -7108,6 +7136,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
7108 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_ASUS_ZENBOOK_UX31A), 7136 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_ASUS_ZENBOOK_UX31A),
7109 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC), 7137 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
7110 SND_PCI_QUIRK(0x1043, 0x17d1, "ASUS UX431FL", ALC294_FIXUP_ASUS_INTSPK_HEADSET_MIC), 7138 SND_PCI_QUIRK(0x1043, 0x17d1, "ASUS UX431FL", ALC294_FIXUP_ASUS_INTSPK_HEADSET_MIC),
7139 SND_PCI_QUIRK(0x1043, 0x18b1, "Asus MJ401TA", ALC256_FIXUP_ASUS_HEADSET_MIC),
7111 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW), 7140 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
7112 SND_PCI_QUIRK(0x1043, 0x1a30, "ASUS X705UD", ALC256_FIXUP_ASUS_MIC), 7141 SND_PCI_QUIRK(0x1043, 0x1a30, "ASUS X705UD", ALC256_FIXUP_ASUS_MIC),
7113 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC), 7142 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index 33cd26763c0e..ff5ab24f3bd1 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -348,6 +348,9 @@ static int set_sync_ep_implicit_fb_quirk(struct snd_usb_substream *subs,
348 ep = 0x84; 348 ep = 0x84;
349 ifnum = 0; 349 ifnum = 0;
350 goto add_sync_ep_from_ifnum; 350 goto add_sync_ep_from_ifnum;
351 case USB_ID(0x0582, 0x01d8): /* BOSS Katana */
352 /* BOSS Katana amplifiers do not need quirks */
353 return 0;
351 } 354 }
352 355
353 if (attr == USB_ENDPOINT_SYNC_ASYNC && 356 if (attr == USB_ENDPOINT_SYNC_ASYNC &&
diff --git a/tools/arch/arm/include/uapi/asm/kvm.h b/tools/arch/arm/include/uapi/asm/kvm.h
index a4217c1a5d01..2769360f195c 100644
--- a/tools/arch/arm/include/uapi/asm/kvm.h
+++ b/tools/arch/arm/include/uapi/asm/kvm.h
@@ -266,8 +266,10 @@ struct kvm_vcpu_events {
266#define KVM_DEV_ARM_ITS_CTRL_RESET 4 266#define KVM_DEV_ARM_ITS_CTRL_RESET 4
267 267
268/* KVM_IRQ_LINE irq field index values */ 268/* KVM_IRQ_LINE irq field index values */
269#define KVM_ARM_IRQ_VCPU2_SHIFT 28
270#define KVM_ARM_IRQ_VCPU2_MASK 0xf
269#define KVM_ARM_IRQ_TYPE_SHIFT 24 271#define KVM_ARM_IRQ_TYPE_SHIFT 24
270#define KVM_ARM_IRQ_TYPE_MASK 0xff 272#define KVM_ARM_IRQ_TYPE_MASK 0xf
271#define KVM_ARM_IRQ_VCPU_SHIFT 16 273#define KVM_ARM_IRQ_VCPU_SHIFT 16
272#define KVM_ARM_IRQ_VCPU_MASK 0xff 274#define KVM_ARM_IRQ_VCPU_MASK 0xff
273#define KVM_ARM_IRQ_NUM_SHIFT 0 275#define KVM_ARM_IRQ_NUM_SHIFT 0
diff --git a/tools/arch/arm64/include/uapi/asm/kvm.h b/tools/arch/arm64/include/uapi/asm/kvm.h
index 9a507716ae2f..67c21f9bdbad 100644
--- a/tools/arch/arm64/include/uapi/asm/kvm.h
+++ b/tools/arch/arm64/include/uapi/asm/kvm.h
@@ -325,8 +325,10 @@ struct kvm_vcpu_events {
325#define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1 325#define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1
326 326
327/* KVM_IRQ_LINE irq field index values */ 327/* KVM_IRQ_LINE irq field index values */
328#define KVM_ARM_IRQ_VCPU2_SHIFT 28
329#define KVM_ARM_IRQ_VCPU2_MASK 0xf
328#define KVM_ARM_IRQ_TYPE_SHIFT 24 330#define KVM_ARM_IRQ_TYPE_SHIFT 24
329#define KVM_ARM_IRQ_TYPE_MASK 0xff 331#define KVM_ARM_IRQ_TYPE_MASK 0xf
330#define KVM_ARM_IRQ_VCPU_SHIFT 16 332#define KVM_ARM_IRQ_VCPU_SHIFT 16
331#define KVM_ARM_IRQ_VCPU_MASK 0xff 333#define KVM_ARM_IRQ_VCPU_MASK 0xff
332#define KVM_ARM_IRQ_NUM_SHIFT 0 334#define KVM_ARM_IRQ_NUM_SHIFT 0
diff --git a/tools/arch/s390/include/uapi/asm/kvm.h b/tools/arch/s390/include/uapi/asm/kvm.h
index 47104e5b47fd..436ec7636927 100644
--- a/tools/arch/s390/include/uapi/asm/kvm.h
+++ b/tools/arch/s390/include/uapi/asm/kvm.h
@@ -231,6 +231,12 @@ struct kvm_guest_debug_arch {
231#define KVM_SYNC_GSCB (1UL << 9) 231#define KVM_SYNC_GSCB (1UL << 9)
232#define KVM_SYNC_BPBC (1UL << 10) 232#define KVM_SYNC_BPBC (1UL << 10)
233#define KVM_SYNC_ETOKEN (1UL << 11) 233#define KVM_SYNC_ETOKEN (1UL << 11)
234
235#define KVM_SYNC_S390_VALID_FIELDS \
236 (KVM_SYNC_PREFIX | KVM_SYNC_GPRS | KVM_SYNC_ACRS | KVM_SYNC_CRS | \
237 KVM_SYNC_ARCH0 | KVM_SYNC_PFAULT | KVM_SYNC_VRS | KVM_SYNC_RICCB | \
238 KVM_SYNC_FPRS | KVM_SYNC_GSCB | KVM_SYNC_BPBC | KVM_SYNC_ETOKEN)
239
234/* length and alignment of the sdnx as a power of two */ 240/* length and alignment of the sdnx as a power of two */
235#define SDNXC 8 241#define SDNXC 8
236#define SDNXL (1UL << SDNXC) 242#define SDNXL (1UL << SDNXC)
diff --git a/tools/arch/x86/include/uapi/asm/vmx.h b/tools/arch/x86/include/uapi/asm/vmx.h
index f0b0c90dd398..f01950aa7fae 100644
--- a/tools/arch/x86/include/uapi/asm/vmx.h
+++ b/tools/arch/x86/include/uapi/asm/vmx.h
@@ -31,6 +31,7 @@
31#define EXIT_REASON_EXCEPTION_NMI 0 31#define EXIT_REASON_EXCEPTION_NMI 0
32#define EXIT_REASON_EXTERNAL_INTERRUPT 1 32#define EXIT_REASON_EXTERNAL_INTERRUPT 1
33#define EXIT_REASON_TRIPLE_FAULT 2 33#define EXIT_REASON_TRIPLE_FAULT 2
34#define EXIT_REASON_INIT_SIGNAL 3
34 35
35#define EXIT_REASON_PENDING_INTERRUPT 7 36#define EXIT_REASON_PENDING_INTERRUPT 7
36#define EXIT_REASON_NMI_WINDOW 8 37#define EXIT_REASON_NMI_WINDOW 8
@@ -90,6 +91,7 @@
90 { EXIT_REASON_EXCEPTION_NMI, "EXCEPTION_NMI" }, \ 91 { EXIT_REASON_EXCEPTION_NMI, "EXCEPTION_NMI" }, \
91 { EXIT_REASON_EXTERNAL_INTERRUPT, "EXTERNAL_INTERRUPT" }, \ 92 { EXIT_REASON_EXTERNAL_INTERRUPT, "EXTERNAL_INTERRUPT" }, \
92 { EXIT_REASON_TRIPLE_FAULT, "TRIPLE_FAULT" }, \ 93 { EXIT_REASON_TRIPLE_FAULT, "TRIPLE_FAULT" }, \
94 { EXIT_REASON_INIT_SIGNAL, "INIT_SIGNAL" }, \
93 { EXIT_REASON_PENDING_INTERRUPT, "PENDING_INTERRUPT" }, \ 95 { EXIT_REASON_PENDING_INTERRUPT, "PENDING_INTERRUPT" }, \
94 { EXIT_REASON_NMI_WINDOW, "NMI_WINDOW" }, \ 96 { EXIT_REASON_NMI_WINDOW, "NMI_WINDOW" }, \
95 { EXIT_REASON_TASK_SWITCH, "TASK_SWITCH" }, \ 97 { EXIT_REASON_TASK_SWITCH, "TASK_SWITCH" }, \
diff --git a/tools/bpf/Makefile b/tools/bpf/Makefile
index fbf5e4a0cb9c..5d1995fd369c 100644
--- a/tools/bpf/Makefile
+++ b/tools/bpf/Makefile
@@ -12,7 +12,11 @@ INSTALL ?= install
12CFLAGS += -Wall -O2 12CFLAGS += -Wall -O2
13CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/include/uapi -I$(srctree)/include 13CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/include/uapi -I$(srctree)/include
14 14
15ifeq ($(srctree),) 15# This will work when bpf is built in tools env. where srctree
16# isn't set and when invoked from selftests build, where srctree
17# is set to ".". building_out_of_srctree is undefined for in srctree
18# builds
19ifndef building_out_of_srctree
16srctree := $(patsubst %/,%,$(dir $(CURDIR))) 20srctree := $(patsubst %/,%,$(dir $(CURDIR)))
17srctree := $(patsubst %/,%,$(dir $(srctree))) 21srctree := $(patsubst %/,%,$(dir $(srctree)))
18endif 22endif
diff --git a/tools/include/uapi/asm-generic/mman-common.h b/tools/include/uapi/asm-generic/mman-common.h
index 63b1f506ea67..c160a5354eb6 100644
--- a/tools/include/uapi/asm-generic/mman-common.h
+++ b/tools/include/uapi/asm-generic/mman-common.h
@@ -67,6 +67,9 @@
67#define MADV_WIPEONFORK 18 /* Zero memory on fork, child only */ 67#define MADV_WIPEONFORK 18 /* Zero memory on fork, child only */
68#define MADV_KEEPONFORK 19 /* Undo MADV_WIPEONFORK */ 68#define MADV_KEEPONFORK 19 /* Undo MADV_WIPEONFORK */
69 69
70#define MADV_COLD 20 /* deactivate these pages */
71#define MADV_PAGEOUT 21 /* reclaim these pages */
72
70/* compatibility flags */ 73/* compatibility flags */
71#define MAP_FILE 0 74#define MAP_FILE 0
72 75
diff --git a/tools/include/uapi/drm/i915_drm.h b/tools/include/uapi/drm/i915_drm.h
index 328d05e77d9f..469dc512cca3 100644
--- a/tools/include/uapi/drm/i915_drm.h
+++ b/tools/include/uapi/drm/i915_drm.h
@@ -521,6 +521,7 @@ typedef struct drm_i915_irq_wait {
521#define I915_SCHEDULER_CAP_PRIORITY (1ul << 1) 521#define I915_SCHEDULER_CAP_PRIORITY (1ul << 1)
522#define I915_SCHEDULER_CAP_PREEMPTION (1ul << 2) 522#define I915_SCHEDULER_CAP_PREEMPTION (1ul << 2)
523#define I915_SCHEDULER_CAP_SEMAPHORES (1ul << 3) 523#define I915_SCHEDULER_CAP_SEMAPHORES (1ul << 3)
524#define I915_SCHEDULER_CAP_ENGINE_BUSY_STATS (1ul << 4)
524 525
525#define I915_PARAM_HUC_STATUS 42 526#define I915_PARAM_HUC_STATUS 42
526 527
diff --git a/tools/include/uapi/linux/fs.h b/tools/include/uapi/linux/fs.h
index 2a616aa3f686..379a612f8f1d 100644
--- a/tools/include/uapi/linux/fs.h
+++ b/tools/include/uapi/linux/fs.h
@@ -13,6 +13,9 @@
13#include <linux/limits.h> 13#include <linux/limits.h>
14#include <linux/ioctl.h> 14#include <linux/ioctl.h>
15#include <linux/types.h> 15#include <linux/types.h>
16#ifndef __KERNEL__
17#include <linux/fscrypt.h>
18#endif
16 19
17/* Use of MS_* flags within the kernel is restricted to core mount(2) code. */ 20/* Use of MS_* flags within the kernel is restricted to core mount(2) code. */
18#if !defined(__KERNEL__) 21#if !defined(__KERNEL__)
@@ -213,57 +216,6 @@ struct fsxattr {
213#define FS_IOC_SETFSLABEL _IOW(0x94, 50, char[FSLABEL_MAX]) 216#define FS_IOC_SETFSLABEL _IOW(0x94, 50, char[FSLABEL_MAX])
214 217
215/* 218/*
216 * File system encryption support
217 */
218/* Policy provided via an ioctl on the topmost directory */
219#define FS_KEY_DESCRIPTOR_SIZE 8
220
221#define FS_POLICY_FLAGS_PAD_4 0x00
222#define FS_POLICY_FLAGS_PAD_8 0x01
223#define FS_POLICY_FLAGS_PAD_16 0x02
224#define FS_POLICY_FLAGS_PAD_32 0x03
225#define FS_POLICY_FLAGS_PAD_MASK 0x03
226#define FS_POLICY_FLAG_DIRECT_KEY 0x04 /* use master key directly */
227#define FS_POLICY_FLAGS_VALID 0x07
228
229/* Encryption algorithms */
230#define FS_ENCRYPTION_MODE_INVALID 0
231#define FS_ENCRYPTION_MODE_AES_256_XTS 1
232#define FS_ENCRYPTION_MODE_AES_256_GCM 2
233#define FS_ENCRYPTION_MODE_AES_256_CBC 3
234#define FS_ENCRYPTION_MODE_AES_256_CTS 4
235#define FS_ENCRYPTION_MODE_AES_128_CBC 5
236#define FS_ENCRYPTION_MODE_AES_128_CTS 6
237#define FS_ENCRYPTION_MODE_SPECK128_256_XTS 7 /* Removed, do not use. */
238#define FS_ENCRYPTION_MODE_SPECK128_256_CTS 8 /* Removed, do not use. */
239#define FS_ENCRYPTION_MODE_ADIANTUM 9
240
241struct fscrypt_policy {
242 __u8 version;
243 __u8 contents_encryption_mode;
244 __u8 filenames_encryption_mode;
245 __u8 flags;
246 __u8 master_key_descriptor[FS_KEY_DESCRIPTOR_SIZE];
247};
248
249#define FS_IOC_SET_ENCRYPTION_POLICY _IOR('f', 19, struct fscrypt_policy)
250#define FS_IOC_GET_ENCRYPTION_PWSALT _IOW('f', 20, __u8[16])
251#define FS_IOC_GET_ENCRYPTION_POLICY _IOW('f', 21, struct fscrypt_policy)
252
253/* Parameters for passing an encryption key into the kernel keyring */
254#define FS_KEY_DESC_PREFIX "fscrypt:"
255#define FS_KEY_DESC_PREFIX_SIZE 8
256
257/* Structure that userspace passes to the kernel keyring */
258#define FS_MAX_KEY_SIZE 64
259
260struct fscrypt_key {
261 __u32 mode;
262 __u8 raw[FS_MAX_KEY_SIZE];
263 __u32 size;
264};
265
266/*
267 * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS) 219 * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS)
268 * 220 *
269 * Note: for historical reasons, these flags were originally used and 221 * Note: for historical reasons, these flags were originally used and
@@ -306,6 +258,7 @@ struct fscrypt_key {
306#define FS_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ 258#define FS_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
307#define FS_HUGE_FILE_FL 0x00040000 /* Reserved for ext4 */ 259#define FS_HUGE_FILE_FL 0x00040000 /* Reserved for ext4 */
308#define FS_EXTENT_FL 0x00080000 /* Extents */ 260#define FS_EXTENT_FL 0x00080000 /* Extents */
261#define FS_VERITY_FL 0x00100000 /* Verity protected inode */
309#define FS_EA_INODE_FL 0x00200000 /* Inode used for large EA */ 262#define FS_EA_INODE_FL 0x00200000 /* Inode used for large EA */
310#define FS_EOFBLOCKS_FL 0x00400000 /* Reserved for ext4 */ 263#define FS_EOFBLOCKS_FL 0x00400000 /* Reserved for ext4 */
311#define FS_NOCOW_FL 0x00800000 /* Do not cow file */ 264#define FS_NOCOW_FL 0x00800000 /* Do not cow file */
diff --git a/tools/include/uapi/linux/fscrypt.h b/tools/include/uapi/linux/fscrypt.h
new file mode 100644
index 000000000000..39ccfe9311c3
--- /dev/null
+++ b/tools/include/uapi/linux/fscrypt.h
@@ -0,0 +1,181 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * fscrypt user API
4 *
5 * These ioctls can be used on filesystems that support fscrypt. See the
6 * "User API" section of Documentation/filesystems/fscrypt.rst.
7 */
8#ifndef _UAPI_LINUX_FSCRYPT_H
9#define _UAPI_LINUX_FSCRYPT_H
10
11#include <linux/types.h>
12
13/* Encryption policy flags */
14#define FSCRYPT_POLICY_FLAGS_PAD_4 0x00
15#define FSCRYPT_POLICY_FLAGS_PAD_8 0x01
16#define FSCRYPT_POLICY_FLAGS_PAD_16 0x02
17#define FSCRYPT_POLICY_FLAGS_PAD_32 0x03
18#define FSCRYPT_POLICY_FLAGS_PAD_MASK 0x03
19#define FSCRYPT_POLICY_FLAG_DIRECT_KEY 0x04
20#define FSCRYPT_POLICY_FLAGS_VALID 0x07
21
22/* Encryption algorithms */
23#define FSCRYPT_MODE_AES_256_XTS 1
24#define FSCRYPT_MODE_AES_256_CTS 4
25#define FSCRYPT_MODE_AES_128_CBC 5
26#define FSCRYPT_MODE_AES_128_CTS 6
27#define FSCRYPT_MODE_ADIANTUM 9
28#define __FSCRYPT_MODE_MAX 9
29
30/*
31 * Legacy policy version; ad-hoc KDF and no key verification.
32 * For new encrypted directories, use fscrypt_policy_v2 instead.
33 *
34 * Careful: the .version field for this is actually 0, not 1.
35 */
36#define FSCRYPT_POLICY_V1 0
37#define FSCRYPT_KEY_DESCRIPTOR_SIZE 8
38struct fscrypt_policy_v1 {
39 __u8 version;
40 __u8 contents_encryption_mode;
41 __u8 filenames_encryption_mode;
42 __u8 flags;
43 __u8 master_key_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE];
44};
45#define fscrypt_policy fscrypt_policy_v1
46
47/*
48 * Process-subscribed "logon" key description prefix and payload format.
49 * Deprecated; prefer FS_IOC_ADD_ENCRYPTION_KEY instead.
50 */
51#define FSCRYPT_KEY_DESC_PREFIX "fscrypt:"
52#define FSCRYPT_KEY_DESC_PREFIX_SIZE 8
53#define FSCRYPT_MAX_KEY_SIZE 64
54struct fscrypt_key {
55 __u32 mode;
56 __u8 raw[FSCRYPT_MAX_KEY_SIZE];
57 __u32 size;
58};
59
60/*
61 * New policy version with HKDF and key verification (recommended).
62 */
63#define FSCRYPT_POLICY_V2 2
64#define FSCRYPT_KEY_IDENTIFIER_SIZE 16
65struct fscrypt_policy_v2 {
66 __u8 version;
67 __u8 contents_encryption_mode;
68 __u8 filenames_encryption_mode;
69 __u8 flags;
70 __u8 __reserved[4];
71 __u8 master_key_identifier[FSCRYPT_KEY_IDENTIFIER_SIZE];
72};
73
74/* Struct passed to FS_IOC_GET_ENCRYPTION_POLICY_EX */
75struct fscrypt_get_policy_ex_arg {
76 __u64 policy_size; /* input/output */
77 union {
78 __u8 version;
79 struct fscrypt_policy_v1 v1;
80 struct fscrypt_policy_v2 v2;
81 } policy; /* output */
82};
83
84/*
85 * v1 policy keys are specified by an arbitrary 8-byte key "descriptor",
86 * matching fscrypt_policy_v1::master_key_descriptor.
87 */
88#define FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR 1
89
90/*
91 * v2 policy keys are specified by a 16-byte key "identifier" which the kernel
92 * calculates as a cryptographic hash of the key itself,
93 * matching fscrypt_policy_v2::master_key_identifier.
94 */
95#define FSCRYPT_KEY_SPEC_TYPE_IDENTIFIER 2
96
97/*
98 * Specifies a key, either for v1 or v2 policies. This doesn't contain the
99 * actual key itself; this is just the "name" of the key.
100 */
101struct fscrypt_key_specifier {
102 __u32 type; /* one of FSCRYPT_KEY_SPEC_TYPE_* */
103 __u32 __reserved;
104 union {
105 __u8 __reserved[32]; /* reserve some extra space */
106 __u8 descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE];
107 __u8 identifier[FSCRYPT_KEY_IDENTIFIER_SIZE];
108 } u;
109};
110
111/* Struct passed to FS_IOC_ADD_ENCRYPTION_KEY */
112struct fscrypt_add_key_arg {
113 struct fscrypt_key_specifier key_spec;
114 __u32 raw_size;
115 __u32 __reserved[9];
116 __u8 raw[];
117};
118
119/* Struct passed to FS_IOC_REMOVE_ENCRYPTION_KEY */
120struct fscrypt_remove_key_arg {
121 struct fscrypt_key_specifier key_spec;
122#define FSCRYPT_KEY_REMOVAL_STATUS_FLAG_FILES_BUSY 0x00000001
123#define FSCRYPT_KEY_REMOVAL_STATUS_FLAG_OTHER_USERS 0x00000002
124 __u32 removal_status_flags; /* output */
125 __u32 __reserved[5];
126};
127
128/* Struct passed to FS_IOC_GET_ENCRYPTION_KEY_STATUS */
129struct fscrypt_get_key_status_arg {
130 /* input */
131 struct fscrypt_key_specifier key_spec;
132 __u32 __reserved[6];
133
134 /* output */
135#define FSCRYPT_KEY_STATUS_ABSENT 1
136#define FSCRYPT_KEY_STATUS_PRESENT 2
137#define FSCRYPT_KEY_STATUS_INCOMPLETELY_REMOVED 3
138 __u32 status;
139#define FSCRYPT_KEY_STATUS_FLAG_ADDED_BY_SELF 0x00000001
140 __u32 status_flags;
141 __u32 user_count;
142 __u32 __out_reserved[13];
143};
144
145#define FS_IOC_SET_ENCRYPTION_POLICY _IOR('f', 19, struct fscrypt_policy)
146#define FS_IOC_GET_ENCRYPTION_PWSALT _IOW('f', 20, __u8[16])
147#define FS_IOC_GET_ENCRYPTION_POLICY _IOW('f', 21, struct fscrypt_policy)
148#define FS_IOC_GET_ENCRYPTION_POLICY_EX _IOWR('f', 22, __u8[9]) /* size + version */
149#define FS_IOC_ADD_ENCRYPTION_KEY _IOWR('f', 23, struct fscrypt_add_key_arg)
150#define FS_IOC_REMOVE_ENCRYPTION_KEY _IOWR('f', 24, struct fscrypt_remove_key_arg)
151#define FS_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS _IOWR('f', 25, struct fscrypt_remove_key_arg)
152#define FS_IOC_GET_ENCRYPTION_KEY_STATUS _IOWR('f', 26, struct fscrypt_get_key_status_arg)
153
154/**********************************************************************/
155
156/* old names; don't add anything new here! */
157#ifndef __KERNEL__
158#define FS_KEY_DESCRIPTOR_SIZE FSCRYPT_KEY_DESCRIPTOR_SIZE
159#define FS_POLICY_FLAGS_PAD_4 FSCRYPT_POLICY_FLAGS_PAD_4
160#define FS_POLICY_FLAGS_PAD_8 FSCRYPT_POLICY_FLAGS_PAD_8
161#define FS_POLICY_FLAGS_PAD_16 FSCRYPT_POLICY_FLAGS_PAD_16
162#define FS_POLICY_FLAGS_PAD_32 FSCRYPT_POLICY_FLAGS_PAD_32
163#define FS_POLICY_FLAGS_PAD_MASK FSCRYPT_POLICY_FLAGS_PAD_MASK
164#define FS_POLICY_FLAG_DIRECT_KEY FSCRYPT_POLICY_FLAG_DIRECT_KEY
165#define FS_POLICY_FLAGS_VALID FSCRYPT_POLICY_FLAGS_VALID
166#define FS_ENCRYPTION_MODE_INVALID 0 /* never used */
167#define FS_ENCRYPTION_MODE_AES_256_XTS FSCRYPT_MODE_AES_256_XTS
168#define FS_ENCRYPTION_MODE_AES_256_GCM 2 /* never used */
169#define FS_ENCRYPTION_MODE_AES_256_CBC 3 /* never used */
170#define FS_ENCRYPTION_MODE_AES_256_CTS FSCRYPT_MODE_AES_256_CTS
171#define FS_ENCRYPTION_MODE_AES_128_CBC FSCRYPT_MODE_AES_128_CBC
172#define FS_ENCRYPTION_MODE_AES_128_CTS FSCRYPT_MODE_AES_128_CTS
173#define FS_ENCRYPTION_MODE_SPECK128_256_XTS 7 /* removed */
174#define FS_ENCRYPTION_MODE_SPECK128_256_CTS 8 /* removed */
175#define FS_ENCRYPTION_MODE_ADIANTUM FSCRYPT_MODE_ADIANTUM
176#define FS_KEY_DESC_PREFIX FSCRYPT_KEY_DESC_PREFIX
177#define FS_KEY_DESC_PREFIX_SIZE FSCRYPT_KEY_DESC_PREFIX_SIZE
178#define FS_MAX_KEY_SIZE FSCRYPT_MAX_KEY_SIZE
179#endif /* !__KERNEL__ */
180
181#endif /* _UAPI_LINUX_FSCRYPT_H */
diff --git a/tools/include/uapi/linux/kvm.h b/tools/include/uapi/linux/kvm.h
index 5e3f12d5359e..233efbb1c81c 100644
--- a/tools/include/uapi/linux/kvm.h
+++ b/tools/include/uapi/linux/kvm.h
@@ -243,6 +243,8 @@ struct kvm_hyperv_exit {
243#define KVM_INTERNAL_ERROR_SIMUL_EX 2 243#define KVM_INTERNAL_ERROR_SIMUL_EX 2
244/* Encounter unexpected vm-exit due to delivery event. */ 244/* Encounter unexpected vm-exit due to delivery event. */
245#define KVM_INTERNAL_ERROR_DELIVERY_EV 3 245#define KVM_INTERNAL_ERROR_DELIVERY_EV 3
246/* Encounter unexpected vm-exit reason */
247#define KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON 4
246 248
247/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */ 249/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
248struct kvm_run { 250struct kvm_run {
@@ -996,6 +998,7 @@ struct kvm_ppc_resize_hpt {
996#define KVM_CAP_ARM_PTRAUTH_ADDRESS 171 998#define KVM_CAP_ARM_PTRAUTH_ADDRESS 171
997#define KVM_CAP_ARM_PTRAUTH_GENERIC 172 999#define KVM_CAP_ARM_PTRAUTH_GENERIC 172
998#define KVM_CAP_PMU_EVENT_FILTER 173 1000#define KVM_CAP_PMU_EVENT_FILTER 173
1001#define KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 174
999 1002
1000#ifdef KVM_CAP_IRQ_ROUTING 1003#ifdef KVM_CAP_IRQ_ROUTING
1001 1004
diff --git a/tools/include/uapi/linux/usbdevice_fs.h b/tools/include/uapi/linux/usbdevice_fs.h
index 78efe870c2b7..cf525cddeb94 100644
--- a/tools/include/uapi/linux/usbdevice_fs.h
+++ b/tools/include/uapi/linux/usbdevice_fs.h
@@ -158,6 +158,7 @@ struct usbdevfs_hub_portinfo {
158#define USBDEVFS_CAP_MMAP 0x20 158#define USBDEVFS_CAP_MMAP 0x20
159#define USBDEVFS_CAP_DROP_PRIVILEGES 0x40 159#define USBDEVFS_CAP_DROP_PRIVILEGES 0x40
160#define USBDEVFS_CAP_CONNINFO_EX 0x80 160#define USBDEVFS_CAP_CONNINFO_EX 0x80
161#define USBDEVFS_CAP_SUSPEND 0x100
161 162
162/* USBDEVFS_DISCONNECT_CLAIM flags & struct */ 163/* USBDEVFS_DISCONNECT_CLAIM flags & struct */
163 164
@@ -223,5 +224,8 @@ struct usbdevfs_streams {
223 * extending size of the data returned. 224 * extending size of the data returned.
224 */ 225 */
225#define USBDEVFS_CONNINFO_EX(len) _IOC(_IOC_READ, 'U', 32, len) 226#define USBDEVFS_CONNINFO_EX(len) _IOC(_IOC_READ, 'U', 32, len)
227#define USBDEVFS_FORBID_SUSPEND _IO('U', 33)
228#define USBDEVFS_ALLOW_SUSPEND _IO('U', 34)
229#define USBDEVFS_WAIT_FOR_RESUME _IO('U', 35)
226 230
227#endif /* _UAPI_LINUX_USBDEVICE_FS_H */ 231#endif /* _UAPI_LINUX_USBDEVICE_FS_H */
diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
index c6f94cffe06e..56ce6292071b 100644
--- a/tools/lib/bpf/Makefile
+++ b/tools/lib/bpf/Makefile
@@ -8,7 +8,11 @@ LIBBPF_MAJOR_VERSION := $(firstword $(subst ., ,$(LIBBPF_VERSION)))
8 8
9MAKEFLAGS += --no-print-directory 9MAKEFLAGS += --no-print-directory
10 10
11ifeq ($(srctree),) 11# This will work when bpf is built in tools env. where srctree
12# isn't set and when invoked from selftests build, where srctree
13# is a ".". building_out_of_srctree is undefined for in srctree
14# builds
15ifndef building_out_of_srctree
12srctree := $(patsubst %/,%,$(dir $(CURDIR))) 16srctree := $(patsubst %/,%,$(dir $(CURDIR)))
13srctree := $(patsubst %/,%,$(dir $(srctree))) 17srctree := $(patsubst %/,%,$(dir $(srctree)))
14srctree := $(patsubst %/,%,$(dir $(srctree))) 18srctree := $(patsubst %/,%,$(dir $(srctree)))
@@ -110,6 +114,9 @@ override CFLAGS += $(INCLUDES)
110override CFLAGS += -fvisibility=hidden 114override CFLAGS += -fvisibility=hidden
111override CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 115override CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
112 116
117# flags specific for shared library
118SHLIB_FLAGS := -DSHARED
119
113ifeq ($(VERBOSE),1) 120ifeq ($(VERBOSE),1)
114 Q = 121 Q =
115else 122else
@@ -126,14 +133,17 @@ all:
126export srctree OUTPUT CC LD CFLAGS V 133export srctree OUTPUT CC LD CFLAGS V
127include $(srctree)/tools/build/Makefile.include 134include $(srctree)/tools/build/Makefile.include
128 135
129BPF_IN := $(OUTPUT)libbpf-in.o 136SHARED_OBJDIR := $(OUTPUT)sharedobjs/
137STATIC_OBJDIR := $(OUTPUT)staticobjs/
138BPF_IN_SHARED := $(SHARED_OBJDIR)libbpf-in.o
139BPF_IN_STATIC := $(STATIC_OBJDIR)libbpf-in.o
130VERSION_SCRIPT := libbpf.map 140VERSION_SCRIPT := libbpf.map
131 141
132LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET)) 142LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET))
133LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE)) 143LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE))
134PC_FILE := $(addprefix $(OUTPUT),$(PC_FILE)) 144PC_FILE := $(addprefix $(OUTPUT),$(PC_FILE))
135 145
136GLOBAL_SYM_COUNT = $(shell readelf -s --wide $(BPF_IN) | \ 146GLOBAL_SYM_COUNT = $(shell readelf -s --wide $(BPF_IN_SHARED) | \
137 cut -d "@" -f1 | sed 's/_v[0-9]_[0-9]_[0-9].*//' | \ 147 cut -d "@" -f1 | sed 's/_v[0-9]_[0-9]_[0-9].*//' | \
138 awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$8}' | \ 148 awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$8}' | \
139 sort -u | wc -l) 149 sort -u | wc -l)
@@ -155,7 +165,7 @@ all: fixdep
155 165
156all_cmd: $(CMD_TARGETS) check 166all_cmd: $(CMD_TARGETS) check
157 167
158$(BPF_IN): force elfdep bpfdep 168$(BPF_IN_SHARED): force elfdep bpfdep
159 @(test -f ../../include/uapi/linux/bpf.h -a -f ../../../include/uapi/linux/bpf.h && ( \ 169 @(test -f ../../include/uapi/linux/bpf.h -a -f ../../../include/uapi/linux/bpf.h && ( \
160 (diff -B ../../include/uapi/linux/bpf.h ../../../include/uapi/linux/bpf.h >/dev/null) || \ 170 (diff -B ../../include/uapi/linux/bpf.h ../../../include/uapi/linux/bpf.h >/dev/null) || \
161 echo "Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf.h' differs from latest version at 'include/uapi/linux/bpf.h'" >&2 )) || true 171 echo "Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf.h' differs from latest version at 'include/uapi/linux/bpf.h'" >&2 )) || true
@@ -171,17 +181,20 @@ $(BPF_IN): force elfdep bpfdep
171 @(test -f ../../include/uapi/linux/if_xdp.h -a -f ../../../include/uapi/linux/if_xdp.h && ( \ 181 @(test -f ../../include/uapi/linux/if_xdp.h -a -f ../../../include/uapi/linux/if_xdp.h && ( \
172 (diff -B ../../include/uapi/linux/if_xdp.h ../../../include/uapi/linux/if_xdp.h >/dev/null) || \ 182 (diff -B ../../include/uapi/linux/if_xdp.h ../../../include/uapi/linux/if_xdp.h >/dev/null) || \
173 echo "Warning: Kernel ABI header at 'tools/include/uapi/linux/if_xdp.h' differs from latest version at 'include/uapi/linux/if_xdp.h'" >&2 )) || true 183 echo "Warning: Kernel ABI header at 'tools/include/uapi/linux/if_xdp.h' differs from latest version at 'include/uapi/linux/if_xdp.h'" >&2 )) || true
174 $(Q)$(MAKE) $(build)=libbpf 184 $(Q)$(MAKE) $(build)=libbpf OUTPUT=$(SHARED_OBJDIR) CFLAGS="$(CFLAGS) $(SHLIB_FLAGS)"
185
186$(BPF_IN_STATIC): force elfdep bpfdep
187 $(Q)$(MAKE) $(build)=libbpf OUTPUT=$(STATIC_OBJDIR)
175 188
176$(OUTPUT)libbpf.so: $(OUTPUT)libbpf.so.$(LIBBPF_VERSION) 189$(OUTPUT)libbpf.so: $(OUTPUT)libbpf.so.$(LIBBPF_VERSION)
177 190
178$(OUTPUT)libbpf.so.$(LIBBPF_VERSION): $(BPF_IN) 191$(OUTPUT)libbpf.so.$(LIBBPF_VERSION): $(BPF_IN_SHARED)
179 $(QUIET_LINK)$(CC) --shared -Wl,-soname,libbpf.so.$(LIBBPF_MAJOR_VERSION) \ 192 $(QUIET_LINK)$(CC) --shared -Wl,-soname,libbpf.so.$(LIBBPF_MAJOR_VERSION) \
180 -Wl,--version-script=$(VERSION_SCRIPT) $^ -lelf -o $@ 193 -Wl,--version-script=$(VERSION_SCRIPT) $^ -lelf -o $@
181 @ln -sf $(@F) $(OUTPUT)libbpf.so 194 @ln -sf $(@F) $(OUTPUT)libbpf.so
182 @ln -sf $(@F) $(OUTPUT)libbpf.so.$(LIBBPF_MAJOR_VERSION) 195 @ln -sf $(@F) $(OUTPUT)libbpf.so.$(LIBBPF_MAJOR_VERSION)
183 196
184$(OUTPUT)libbpf.a: $(BPF_IN) 197$(OUTPUT)libbpf.a: $(BPF_IN_STATIC)
185 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^ 198 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
186 199
187$(OUTPUT)test_libbpf: test_libbpf.cpp $(OUTPUT)libbpf.a 200$(OUTPUT)test_libbpf: test_libbpf.cpp $(OUTPUT)libbpf.a
@@ -197,7 +210,7 @@ check: check_abi
197 210
198check_abi: $(OUTPUT)libbpf.so 211check_abi: $(OUTPUT)libbpf.so
199 @if [ "$(GLOBAL_SYM_COUNT)" != "$(VERSIONED_SYM_COUNT)" ]; then \ 212 @if [ "$(GLOBAL_SYM_COUNT)" != "$(VERSIONED_SYM_COUNT)" ]; then \
200 echo "Warning: Num of global symbols in $(BPF_IN)" \ 213 echo "Warning: Num of global symbols in $(BPF_IN_SHARED)" \
201 "($(GLOBAL_SYM_COUNT)) does NOT match with num of" \ 214 "($(GLOBAL_SYM_COUNT)) does NOT match with num of" \
202 "versioned symbols in $^ ($(VERSIONED_SYM_COUNT))." \ 215 "versioned symbols in $^ ($(VERSIONED_SYM_COUNT))." \
203 "Please make sure all LIBBPF_API symbols are" \ 216 "Please make sure all LIBBPF_API symbols are" \
@@ -255,9 +268,9 @@ config-clean:
255 $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null 268 $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null
256 269
257clean: 270clean:
258 $(call QUIET_CLEAN, libbpf) $(RM) $(TARGETS) $(CXX_TEST_TARGET) \ 271 $(call QUIET_CLEAN, libbpf) $(RM) -rf $(TARGETS) $(CXX_TEST_TARGET) \
259 *.o *~ *.a *.so *.so.$(LIBBPF_MAJOR_VERSION) .*.d .*.cmd \ 272 *.o *~ *.a *.so *.so.$(LIBBPF_MAJOR_VERSION) .*.d .*.cmd \
260 *.pc LIBBPF-CFLAGS 273 *.pc LIBBPF-CFLAGS $(SHARED_OBJDIR) $(STATIC_OBJDIR)
261 $(call QUIET_CLEAN, core-gen) $(RM) $(OUTPUT)FEATURE-DUMP.libbpf 274 $(call QUIET_CLEAN, core-gen) $(RM) $(OUTPUT)FEATURE-DUMP.libbpf
262 275
263 276
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 2e83a34f8c79..98216a69c32f 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -34,6 +34,22 @@
34 (offsetof(TYPE, FIELD) + sizeof(((TYPE *)0)->FIELD)) 34 (offsetof(TYPE, FIELD) + sizeof(((TYPE *)0)->FIELD))
35#endif 35#endif
36 36
37/* Symbol versioning is different between static and shared library.
38 * Properly versioned symbols are needed for shared library, but
39 * only the symbol of the new version is needed for static library.
40 */
41#ifdef SHARED
42# define COMPAT_VERSION(internal_name, api_name, version) \
43 asm(".symver " #internal_name "," #api_name "@" #version);
44# define DEFAULT_VERSION(internal_name, api_name, version) \
45 asm(".symver " #internal_name "," #api_name "@@" #version);
46#else
47# define COMPAT_VERSION(internal_name, api_name, version)
48# define DEFAULT_VERSION(internal_name, api_name, version) \
49 extern typeof(internal_name) api_name \
50 __attribute__((alias(#internal_name)));
51#endif
52
37extern void libbpf_print(enum libbpf_print_level level, 53extern void libbpf_print(enum libbpf_print_level level,
38 const char *format, ...) 54 const char *format, ...)
39 __attribute__((format(printf, 2, 3))); 55 __attribute__((format(printf, 2, 3)));
diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
index 24fa313524fb..a902838f9fcc 100644
--- a/tools/lib/bpf/xsk.c
+++ b/tools/lib/bpf/xsk.c
@@ -261,8 +261,8 @@ int xsk_umem__create_v0_0_2(struct xsk_umem **umem_ptr, void *umem_area,
261 return xsk_umem__create_v0_0_4(umem_ptr, umem_area, size, fill, comp, 261 return xsk_umem__create_v0_0_4(umem_ptr, umem_area, size, fill, comp,
262 &config); 262 &config);
263} 263}
264asm(".symver xsk_umem__create_v0_0_2, xsk_umem__create@LIBBPF_0.0.2"); 264COMPAT_VERSION(xsk_umem__create_v0_0_2, xsk_umem__create, LIBBPF_0.0.2)
265asm(".symver xsk_umem__create_v0_0_4, xsk_umem__create@@LIBBPF_0.0.4"); 265DEFAULT_VERSION(xsk_umem__create_v0_0_4, xsk_umem__create, LIBBPF_0.0.4)
266 266
267static int xsk_load_xdp_prog(struct xsk_socket *xsk) 267static int xsk_load_xdp_prog(struct xsk_socket *xsk)
268{ 268{
diff --git a/tools/lib/subcmd/Makefile b/tools/lib/subcmd/Makefile
index ed61fb3a46c0..5b2cd5e58df0 100644
--- a/tools/lib/subcmd/Makefile
+++ b/tools/lib/subcmd/Makefile
@@ -20,7 +20,13 @@ MAKEFLAGS += --no-print-directory
20LIBFILE = $(OUTPUT)libsubcmd.a 20LIBFILE = $(OUTPUT)libsubcmd.a
21 21
22CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) 22CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
23CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIC 23CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -fPIC
24
25ifeq ($(DEBUG),0)
26 ifeq ($(feature-fortify-source), 1)
27 CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
28 endif
29endif
24 30
25ifeq ($(CC_NO_CLANG), 0) 31ifeq ($(CC_NO_CLANG), 0)
26 CFLAGS += -O3 32 CFLAGS += -O3
diff --git a/tools/perf/Documentation/asciidoc.conf b/tools/perf/Documentation/asciidoc.conf
index 356b23a40339..2b62ba1e72b7 100644
--- a/tools/perf/Documentation/asciidoc.conf
+++ b/tools/perf/Documentation/asciidoc.conf
@@ -71,6 +71,9 @@ ifdef::backend-docbook[]
71[header] 71[header]
72template::[header-declarations] 72template::[header-declarations]
73<refentry> 73<refentry>
74ifdef::perf_date[]
75<refentryinfo><date>{perf_date}</date></refentryinfo>
76endif::perf_date[]
74<refmeta> 77<refmeta>
75<refentrytitle>{mantitle}</refentrytitle> 78<refentrytitle>{mantitle}</refentrytitle>
76<manvolnum>{manvolnum}</manvolnum> 79<manvolnum>{manvolnum}</manvolnum>
diff --git a/tools/perf/Documentation/jitdump-specification.txt b/tools/perf/Documentation/jitdump-specification.txt
index 4c62b0713651..52152d156ad9 100644
--- a/tools/perf/Documentation/jitdump-specification.txt
+++ b/tools/perf/Documentation/jitdump-specification.txt
@@ -36,8 +36,8 @@ III/ Jitdump file header format
36Each jitdump file starts with a fixed size header containing the following fields in order: 36Each jitdump file starts with a fixed size header containing the following fields in order:
37 37
38 38
39* uint32_t magic : a magic number tagging the file type. The value is 4-byte long and represents the string "JiTD" in ASCII form. It is 0x4A695444 or 0x4454694a depending on the endianness. The field can be used to detect the endianness of the file 39* uint32_t magic : a magic number tagging the file type. The value is 4-byte long and represents the string "JiTD" in ASCII form. It written is as 0x4A695444. The reader will detect an endian mismatch when it reads 0x4454694a.
40* uint32_t version : a 4-byte value representing the format version. It is currently set to 2 40* uint32_t version : a 4-byte value representing the format version. It is currently set to 1
41* uint32_t total_size: size in bytes of file header 41* uint32_t total_size: size in bytes of file header
42* uint32_t elf_mach : ELF architecture encoding (ELF e_machine value as specified in /usr/include/elf.h) 42* uint32_t elf_mach : ELF architecture encoding (ELF e_machine value as specified in /usr/include/elf.h)
43* uint32_t pad1 : padding. Reserved for future use 43* uint32_t pad1 : padding. Reserved for future use
diff --git a/tools/perf/arch/arm/annotate/instructions.c b/tools/perf/arch/arm/annotate/instructions.c
index e1d4b484cc4b..2ff6cedeb9c5 100644
--- a/tools/perf/arch/arm/annotate/instructions.c
+++ b/tools/perf/arch/arm/annotate/instructions.c
@@ -37,7 +37,7 @@ static int arm__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
37 37
38 arm = zalloc(sizeof(*arm)); 38 arm = zalloc(sizeof(*arm));
39 if (!arm) 39 if (!arm)
40 return -1; 40 return ENOMEM;
41 41
42#define ARM_CONDS "(cc|cs|eq|ge|gt|hi|le|ls|lt|mi|ne|pl|vc|vs)" 42#define ARM_CONDS "(cc|cs|eq|ge|gt|hi|le|ls|lt|mi|ne|pl|vc|vs)"
43 err = regcomp(&arm->call_insn, "^blx?" ARM_CONDS "?$", REG_EXTENDED); 43 err = regcomp(&arm->call_insn, "^blx?" ARM_CONDS "?$", REG_EXTENDED);
@@ -59,5 +59,5 @@ out_free_call:
59 regfree(&arm->call_insn); 59 regfree(&arm->call_insn);
60out_free_arm: 60out_free_arm:
61 free(arm); 61 free(arm);
62 return -1; 62 return SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP;
63} 63}
diff --git a/tools/perf/arch/arm64/annotate/instructions.c b/tools/perf/arch/arm64/annotate/instructions.c
index 43aa93ed8414..037e292ecd8e 100644
--- a/tools/perf/arch/arm64/annotate/instructions.c
+++ b/tools/perf/arch/arm64/annotate/instructions.c
@@ -95,7 +95,7 @@ static int arm64__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
95 95
96 arm = zalloc(sizeof(*arm)); 96 arm = zalloc(sizeof(*arm));
97 if (!arm) 97 if (!arm)
98 return -1; 98 return ENOMEM;
99 99
100 /* bl, blr */ 100 /* bl, blr */
101 err = regcomp(&arm->call_insn, "^blr?$", REG_EXTENDED); 101 err = regcomp(&arm->call_insn, "^blr?$", REG_EXTENDED);
@@ -118,5 +118,5 @@ out_free_call:
118 regfree(&arm->call_insn); 118 regfree(&arm->call_insn);
119out_free_arm: 119out_free_arm:
120 free(arm); 120 free(arm);
121 return -1; 121 return SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP;
122} 122}
diff --git a/tools/perf/arch/powerpc/util/header.c b/tools/perf/arch/powerpc/util/header.c
index b6b7bc7e31a1..3b4cdfc5efd6 100644
--- a/tools/perf/arch/powerpc/util/header.c
+++ b/tools/perf/arch/powerpc/util/header.c
@@ -1,5 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0
2#include <sys/types.h> 2#include <sys/types.h>
3#include <errno.h>
3#include <unistd.h> 4#include <unistd.h>
4#include <stdio.h> 5#include <stdio.h>
5#include <stdlib.h> 6#include <stdlib.h>
@@ -30,7 +31,7 @@ get_cpuid(char *buffer, size_t sz)
30 buffer[nb-1] = '\0'; 31 buffer[nb-1] = '\0';
31 return 0; 32 return 0;
32 } 33 }
33 return -1; 34 return ENOBUFS;
34} 35}
35 36
36char * 37char *
diff --git a/tools/perf/arch/s390/annotate/instructions.c b/tools/perf/arch/s390/annotate/instructions.c
index 89bb8f2c54ce..a50e70baf918 100644
--- a/tools/perf/arch/s390/annotate/instructions.c
+++ b/tools/perf/arch/s390/annotate/instructions.c
@@ -164,8 +164,10 @@ static int s390__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
164 if (!arch->initialized) { 164 if (!arch->initialized) {
165 arch->initialized = true; 165 arch->initialized = true;
166 arch->associate_instruction_ops = s390__associate_ins_ops; 166 arch->associate_instruction_ops = s390__associate_ins_ops;
167 if (cpuid) 167 if (cpuid) {
168 err = s390__cpuid_parse(arch, cpuid); 168 if (s390__cpuid_parse(arch, cpuid))
169 err = SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING;
170 }
169 } 171 }
170 172
171 return err; 173 return err;
diff --git a/tools/perf/arch/s390/util/header.c b/tools/perf/arch/s390/util/header.c
index 8b0b018d896a..7933f6871c81 100644
--- a/tools/perf/arch/s390/util/header.c
+++ b/tools/perf/arch/s390/util/header.c
@@ -8,6 +8,7 @@
8 */ 8 */
9 9
10#include <sys/types.h> 10#include <sys/types.h>
11#include <errno.h>
11#include <unistd.h> 12#include <unistd.h>
12#include <stdio.h> 13#include <stdio.h>
13#include <string.h> 14#include <string.h>
@@ -54,7 +55,7 @@ int get_cpuid(char *buffer, size_t sz)
54 55
55 sysinfo = fopen(SYSINFO, "r"); 56 sysinfo = fopen(SYSINFO, "r");
56 if (sysinfo == NULL) 57 if (sysinfo == NULL)
57 return -1; 58 return errno;
58 59
59 while ((read = getline(&line, &line_sz, sysinfo)) != -1) { 60 while ((read = getline(&line, &line_sz, sysinfo)) != -1) {
60 if (!strncmp(line, SYSINFO_MANU, strlen(SYSINFO_MANU))) { 61 if (!strncmp(line, SYSINFO_MANU, strlen(SYSINFO_MANU))) {
@@ -89,7 +90,7 @@ int get_cpuid(char *buffer, size_t sz)
89 90
90 /* Missing manufacturer, type or model information should not happen */ 91 /* Missing manufacturer, type or model information should not happen */
91 if (!manufacturer[0] || !type[0] || !model[0]) 92 if (!manufacturer[0] || !type[0] || !model[0])
92 return -1; 93 return EINVAL;
93 94
94 /* 95 /*
95 * Scan /proc/service_levels and return the CPU-MF counter facility 96 * Scan /proc/service_levels and return the CPU-MF counter facility
@@ -133,14 +134,14 @@ skip_sysinfo:
133 else 134 else
134 nbytes = snprintf(buffer, sz, "%s,%s,%s", manufacturer, type, 135 nbytes = snprintf(buffer, sz, "%s,%s,%s", manufacturer, type,
135 model); 136 model);
136 return (nbytes >= sz) ? -1 : 0; 137 return (nbytes >= sz) ? ENOBUFS : 0;
137} 138}
138 139
139char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused) 140char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
140{ 141{
141 char *buf = malloc(128); 142 char *buf = malloc(128);
142 143
143 if (buf && get_cpuid(buf, 128) < 0) 144 if (buf && get_cpuid(buf, 128))
144 zfree(&buf); 145 zfree(&buf);
145 return buf; 146 return buf;
146} 147}
diff --git a/tools/perf/arch/x86/annotate/instructions.c b/tools/perf/arch/x86/annotate/instructions.c
index 44f5aba78210..7eb5621c021d 100644
--- a/tools/perf/arch/x86/annotate/instructions.c
+++ b/tools/perf/arch/x86/annotate/instructions.c
@@ -196,8 +196,10 @@ static int x86__annotate_init(struct arch *arch, char *cpuid)
196 if (arch->initialized) 196 if (arch->initialized)
197 return 0; 197 return 0;
198 198
199 if (cpuid) 199 if (cpuid) {
200 err = x86__cpuid_parse(arch, cpuid); 200 if (x86__cpuid_parse(arch, cpuid))
201 err = SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING;
202 }
201 203
202 arch->initialized = true; 204 arch->initialized = true;
203 return err; 205 return err;
diff --git a/tools/perf/arch/x86/util/header.c b/tools/perf/arch/x86/util/header.c
index 662ecf84a421..aa6deb463bf3 100644
--- a/tools/perf/arch/x86/util/header.c
+++ b/tools/perf/arch/x86/util/header.c
@@ -1,5 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0
2#include <sys/types.h> 2#include <sys/types.h>
3#include <errno.h>
3#include <unistd.h> 4#include <unistd.h>
4#include <stdio.h> 5#include <stdio.h>
5#include <stdlib.h> 6#include <stdlib.h>
@@ -58,7 +59,7 @@ __get_cpuid(char *buffer, size_t sz, const char *fmt)
58 buffer[nb-1] = '\0'; 59 buffer[nb-1] = '\0';
59 return 0; 60 return 0;
60 } 61 }
61 return -1; 62 return ENOBUFS;
62} 63}
63 64
64int 65int
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 2227e2f42c09..58a9e0989491 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -705,14 +705,15 @@ static int process_sample_event(struct perf_tool *tool,
705 705
706static int cpu_isa_config(struct perf_kvm_stat *kvm) 706static int cpu_isa_config(struct perf_kvm_stat *kvm)
707{ 707{
708 char buf[64], *cpuid; 708 char buf[128], *cpuid;
709 int err; 709 int err;
710 710
711 if (kvm->live) { 711 if (kvm->live) {
712 err = get_cpuid(buf, sizeof(buf)); 712 err = get_cpuid(buf, sizeof(buf));
713 if (err != 0) { 713 if (err != 0) {
714 pr_err("Failed to look up CPU type\n"); 714 pr_err("Failed to look up CPU type: %s\n",
715 return err; 715 str_error_r(err, buf, sizeof(buf)));
716 return -err;
716 } 717 }
717 cpuid = buf; 718 cpuid = buf;
718 } else 719 } else
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 286fc70d7402..67be8d31afab 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1063,7 +1063,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample,
1063 continue; 1063 continue;
1064 1064
1065 insn = 0; 1065 insn = 0;
1066 for (off = 0;; off += ilen) { 1066 for (off = 0; off < (unsigned)len; off += ilen) {
1067 uint64_t ip = start + off; 1067 uint64_t ip = start + off;
1068 1068
1069 printed += ip__fprintf_sym(ip, thread, x.cpumode, x.cpu, &lastsym, attr, fp); 1069 printed += ip__fprintf_sym(ip, thread, x.cpumode, x.cpu, &lastsym, attr, fp);
@@ -1074,6 +1074,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample,
1074 printed += print_srccode(thread, x.cpumode, ip); 1074 printed += print_srccode(thread, x.cpumode, ip);
1075 break; 1075 break;
1076 } else { 1076 } else {
1077 ilen = 0;
1077 printed += fprintf(fp, "\t%016" PRIx64 "\t%s\n", ip, 1078 printed += fprintf(fp, "\t%016" PRIx64 "\t%s\n", ip,
1078 dump_insn(&x, ip, buffer + off, len - off, &ilen)); 1079 dump_insn(&x, ip, buffer + off, len - off, &ilen));
1079 if (ilen == 0) 1080 if (ilen == 0)
@@ -1083,6 +1084,8 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample,
1083 insn++; 1084 insn++;
1084 } 1085 }
1085 } 1086 }
1087 if (off != (unsigned)len)
1088 printed += fprintf(fp, "\tmismatch of LBR data and executable\n");
1086 } 1089 }
1087 1090
1088 /* 1091 /*
@@ -1123,6 +1126,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample,
1123 goto out; 1126 goto out;
1124 } 1127 }
1125 for (off = 0; off <= end - start; off += ilen) { 1128 for (off = 0; off <= end - start; off += ilen) {
1129 ilen = 0;
1126 printed += fprintf(fp, "\t%016" PRIx64 "\t%s\n", start + off, 1130 printed += fprintf(fp, "\t%016" PRIx64 "\t%s\n", start + off,
1127 dump_insn(&x, start + off, buffer + off, len - off, &ilen)); 1131 dump_insn(&x, start + off, buffer + off, len - off, &ilen));
1128 if (ilen == 0) 1132 if (ilen == 0)
diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
index e2e0f06c97d0..cea13cb987d0 100755
--- a/tools/perf/check-headers.sh
+++ b/tools/perf/check-headers.sh
@@ -8,6 +8,7 @@ include/uapi/drm/i915_drm.h
8include/uapi/linux/fadvise.h 8include/uapi/linux/fadvise.h
9include/uapi/linux/fcntl.h 9include/uapi/linux/fcntl.h
10include/uapi/linux/fs.h 10include/uapi/linux/fs.h
11include/uapi/linux/fscrypt.h
11include/uapi/linux/kcmp.h 12include/uapi/linux/kcmp.h
12include/uapi/linux/kvm.h 13include/uapi/linux/kvm.h
13include/uapi/linux/in.h 14include/uapi/linux/in.h
diff --git a/tools/perf/pmu-events/arch/s390/cf_m8561/basic.json b/tools/perf/pmu-events/arch/s390/cf_z15/basic.json
index 17fb5241928b..17fb5241928b 100644
--- a/tools/perf/pmu-events/arch/s390/cf_m8561/basic.json
+++ b/tools/perf/pmu-events/arch/s390/cf_z15/basic.json
diff --git a/tools/perf/pmu-events/arch/s390/cf_m8561/crypto.json b/tools/perf/pmu-events/arch/s390/cf_z15/crypto.json
index db286f19e7b6..db286f19e7b6 100644
--- a/tools/perf/pmu-events/arch/s390/cf_m8561/crypto.json
+++ b/tools/perf/pmu-events/arch/s390/cf_z15/crypto.json
diff --git a/tools/perf/pmu-events/arch/s390/cf_m8561/crypto6.json b/tools/perf/pmu-events/arch/s390/cf_z15/crypto6.json
index 5e36bc2468d0..5e36bc2468d0 100644
--- a/tools/perf/pmu-events/arch/s390/cf_m8561/crypto6.json
+++ b/tools/perf/pmu-events/arch/s390/cf_z15/crypto6.json
diff --git a/tools/perf/pmu-events/arch/s390/cf_m8561/extended.json b/tools/perf/pmu-events/arch/s390/cf_z15/extended.json
index 89e070727e1b..89e070727e1b 100644
--- a/tools/perf/pmu-events/arch/s390/cf_m8561/extended.json
+++ b/tools/perf/pmu-events/arch/s390/cf_z15/extended.json
diff --git a/tools/perf/pmu-events/arch/s390/cf_z15/transaction.json b/tools/perf/pmu-events/arch/s390/cf_z15/transaction.json
new file mode 100644
index 000000000000..1a0034f79f73
--- /dev/null
+++ b/tools/perf/pmu-events/arch/s390/cf_z15/transaction.json
@@ -0,0 +1,7 @@
1[
2 {
3 "BriefDescription": "Transaction count",
4 "MetricName": "transaction",
5 "MetricExpr": "TX_C_TEND + TX_NC_TEND + TX_NC_TABORT + TX_C_TABORT_SPECIAL + TX_C_TABORT_NO_SPECIAL"
6 }
7]
diff --git a/tools/perf/pmu-events/arch/s390/mapfile.csv b/tools/perf/pmu-events/arch/s390/mapfile.csv
index bd3fc577139c..61641a3480e0 100644
--- a/tools/perf/pmu-events/arch/s390/mapfile.csv
+++ b/tools/perf/pmu-events/arch/s390/mapfile.csv
@@ -4,4 +4,4 @@ Family-model,Version,Filename,EventType
4^IBM.282[78].*[13]\.[1-5].[[:xdigit:]]+$,1,cf_zec12,core 4^IBM.282[78].*[13]\.[1-5].[[:xdigit:]]+$,1,cf_zec12,core
5^IBM.296[45].*[13]\.[1-5].[[:xdigit:]]+$,1,cf_z13,core 5^IBM.296[45].*[13]\.[1-5].[[:xdigit:]]+$,1,cf_z13,core
6^IBM.390[67].*[13]\.[1-5].[[:xdigit:]]+$,3,cf_z14,core 6^IBM.390[67].*[13]\.[1-5].[[:xdigit:]]+$,3,cf_z14,core
7^IBM.856[12].*3\.6.[[:xdigit:]]+$,3,cf_m8561,core 7^IBM.856[12].*3\.6.[[:xdigit:]]+$,3,cf_z15,core
diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c
index 9e37287da924..e2837260ca4d 100644
--- a/tools/perf/pmu-events/jevents.c
+++ b/tools/perf/pmu-events/jevents.c
@@ -450,12 +450,12 @@ static struct fixed {
450 const char *name; 450 const char *name;
451 const char *event; 451 const char *event;
452} fixed[] = { 452} fixed[] = {
453 { "inst_retired.any", "event=0xc0" }, 453 { "inst_retired.any", "event=0xc0,period=2000003" },
454 { "inst_retired.any_p", "event=0xc0" }, 454 { "inst_retired.any_p", "event=0xc0,period=2000003" },
455 { "cpu_clk_unhalted.ref", "event=0x0,umask=0x03" }, 455 { "cpu_clk_unhalted.ref", "event=0x0,umask=0x03,period=2000003" },
456 { "cpu_clk_unhalted.thread", "event=0x3c" }, 456 { "cpu_clk_unhalted.thread", "event=0x3c,period=2000003" },
457 { "cpu_clk_unhalted.core", "event=0x3c" }, 457 { "cpu_clk_unhalted.core", "event=0x3c,period=2000003" },
458 { "cpu_clk_unhalted.thread_any", "event=0x3c,any=1" }, 458 { "cpu_clk_unhalted.thread_any", "event=0x3c,any=1,period=2000003" },
459 { NULL, NULL}, 459 { NULL, NULL},
460}; 460};
461 461
diff --git a/tools/perf/tests/perf-hooks.c b/tools/perf/tests/perf-hooks.c
index dbc27199c65e..dd865e0bea12 100644
--- a/tools/perf/tests/perf-hooks.c
+++ b/tools/perf/tests/perf-hooks.c
@@ -19,12 +19,11 @@ static void sigsegv_handler(int sig __maybe_unused)
19static void the_hook(void *_hook_flags) 19static void the_hook(void *_hook_flags)
20{ 20{
21 int *hook_flags = _hook_flags; 21 int *hook_flags = _hook_flags;
22 int *p = NULL;
23 22
24 *hook_flags = 1234; 23 *hook_flags = 1234;
25 24
26 /* Generate a segfault, test perf_hooks__recover */ 25 /* Generate a segfault, test perf_hooks__recover */
27 *p = 0; 26 raise(SIGSEGV);
28} 27}
29 28
30int test__perf_hooks(struct test *test __maybe_unused, int subtest __maybe_unused) 29int test__perf_hooks(struct test *test __maybe_unused, int subtest __maybe_unused)
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index e830eadfca2a..4036c7f7b0fb 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1631,6 +1631,19 @@ int symbol__strerror_disassemble(struct symbol *sym __maybe_unused, struct map *
1631 case SYMBOL_ANNOTATE_ERRNO__NO_LIBOPCODES_FOR_BPF: 1631 case SYMBOL_ANNOTATE_ERRNO__NO_LIBOPCODES_FOR_BPF:
1632 scnprintf(buf, buflen, "Please link with binutils's libopcode to enable BPF annotation"); 1632 scnprintf(buf, buflen, "Please link with binutils's libopcode to enable BPF annotation");
1633 break; 1633 break;
1634 case SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP:
1635 scnprintf(buf, buflen, "Problems with arch specific instruction name regular expressions.");
1636 break;
1637 case SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING:
1638 scnprintf(buf, buflen, "Problems while parsing the CPUID in the arch specific initialization.");
1639 break;
1640 case SYMBOL_ANNOTATE_ERRNO__BPF_INVALID_FILE:
1641 scnprintf(buf, buflen, "Invalid BPF file: %s.", dso->long_name);
1642 break;
1643 case SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF:
1644 scnprintf(buf, buflen, "The %s BPF file has no BTF section, compile with -g or use pahole -J.",
1645 dso->long_name);
1646 break;
1634 default: 1647 default:
1635 scnprintf(buf, buflen, "Internal error: Invalid %d error code\n", errnum); 1648 scnprintf(buf, buflen, "Internal error: Invalid %d error code\n", errnum);
1636 break; 1649 break;
@@ -1662,7 +1675,7 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil
1662 1675
1663 build_id_path = strdup(filename); 1676 build_id_path = strdup(filename);
1664 if (!build_id_path) 1677 if (!build_id_path)
1665 return -1; 1678 return ENOMEM;
1666 1679
1667 /* 1680 /*
1668 * old style build-id cache has name of XX/XXXXXXX.. while 1681 * old style build-id cache has name of XX/XXXXXXX.. while
@@ -1713,13 +1726,13 @@ static int symbol__disassemble_bpf(struct symbol *sym,
1713 char tpath[PATH_MAX]; 1726 char tpath[PATH_MAX];
1714 size_t buf_size; 1727 size_t buf_size;
1715 int nr_skip = 0; 1728 int nr_skip = 0;
1716 int ret = -1;
1717 char *buf; 1729 char *buf;
1718 bfd *bfdf; 1730 bfd *bfdf;
1731 int ret;
1719 FILE *s; 1732 FILE *s;
1720 1733
1721 if (dso->binary_type != DSO_BINARY_TYPE__BPF_PROG_INFO) 1734 if (dso->binary_type != DSO_BINARY_TYPE__BPF_PROG_INFO)
1722 return -1; 1735 return SYMBOL_ANNOTATE_ERRNO__BPF_INVALID_FILE;
1723 1736
1724 pr_debug("%s: handling sym %s addr %" PRIx64 " len %" PRIx64 "\n", __func__, 1737 pr_debug("%s: handling sym %s addr %" PRIx64 " len %" PRIx64 "\n", __func__,
1725 sym->name, sym->start, sym->end - sym->start); 1738 sym->name, sym->start, sym->end - sym->start);
@@ -1732,8 +1745,10 @@ static int symbol__disassemble_bpf(struct symbol *sym,
1732 assert(bfd_check_format(bfdf, bfd_object)); 1745 assert(bfd_check_format(bfdf, bfd_object));
1733 1746
1734 s = open_memstream(&buf, &buf_size); 1747 s = open_memstream(&buf, &buf_size);
1735 if (!s) 1748 if (!s) {
1749 ret = errno;
1736 goto out; 1750 goto out;
1751 }
1737 init_disassemble_info(&info, s, 1752 init_disassemble_info(&info, s,
1738 (fprintf_ftype) fprintf); 1753 (fprintf_ftype) fprintf);
1739 1754
@@ -1742,8 +1757,10 @@ static int symbol__disassemble_bpf(struct symbol *sym,
1742 1757
1743 info_node = perf_env__find_bpf_prog_info(dso->bpf_prog.env, 1758 info_node = perf_env__find_bpf_prog_info(dso->bpf_prog.env,
1744 dso->bpf_prog.id); 1759 dso->bpf_prog.id);
1745 if (!info_node) 1760 if (!info_node) {
1761 return SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF;
1746 goto out; 1762 goto out;
1763 }
1747 info_linear = info_node->info_linear; 1764 info_linear = info_node->info_linear;
1748 sub_id = dso->bpf_prog.sub_id; 1765 sub_id = dso->bpf_prog.sub_id;
1749 1766
@@ -2071,11 +2088,11 @@ int symbol__annotate(struct symbol *sym, struct map *map,
2071 int err; 2088 int err;
2072 2089
2073 if (!arch_name) 2090 if (!arch_name)
2074 return -1; 2091 return errno;
2075 2092
2076 args.arch = arch = arch__find(arch_name); 2093 args.arch = arch = arch__find(arch_name);
2077 if (arch == NULL) 2094 if (arch == NULL)
2078 return -ENOTSUP; 2095 return ENOTSUP;
2079 2096
2080 if (parch) 2097 if (parch)
2081 *parch = arch; 2098 *parch = arch;
@@ -2971,7 +2988,7 @@ int symbol__annotate2(struct symbol *sym, struct map *map, struct evsel *evsel,
2971 2988
2972 notes->offsets = zalloc(size * sizeof(struct annotation_line *)); 2989 notes->offsets = zalloc(size * sizeof(struct annotation_line *));
2973 if (notes->offsets == NULL) 2990 if (notes->offsets == NULL)
2974 return -1; 2991 return ENOMEM;
2975 2992
2976 if (perf_evsel__is_group_event(evsel)) 2993 if (perf_evsel__is_group_event(evsel))
2977 nr_pcnt = evsel->core.nr_members; 2994 nr_pcnt = evsel->core.nr_members;
@@ -2997,7 +3014,7 @@ int symbol__annotate2(struct symbol *sym, struct map *map, struct evsel *evsel,
2997 3014
2998out_free_offsets: 3015out_free_offsets:
2999 zfree(&notes->offsets); 3016 zfree(&notes->offsets);
3000 return -1; 3017 return err;
3001} 3018}
3002 3019
3003#define ANNOTATION__CFG(n) \ 3020#define ANNOTATION__CFG(n) \
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index d94be9140e31..d76fd0e81f46 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -370,6 +370,10 @@ enum symbol_disassemble_errno {
370 370
371 SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX = __SYMBOL_ANNOTATE_ERRNO__START, 371 SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX = __SYMBOL_ANNOTATE_ERRNO__START,
372 SYMBOL_ANNOTATE_ERRNO__NO_LIBOPCODES_FOR_BPF, 372 SYMBOL_ANNOTATE_ERRNO__NO_LIBOPCODES_FOR_BPF,
373 SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING,
374 SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP,
375 SYMBOL_ANNOTATE_ERRNO__BPF_INVALID_FILE,
376 SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF,
373 377
374 __SYMBOL_ANNOTATE_ERRNO__END, 378 __SYMBOL_ANNOTATE_ERRNO__END,
375}; 379};
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 5591af81a070..abc7fda4a0fe 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -30,6 +30,7 @@
30#include "counts.h" 30#include "counts.h"
31#include "event.h" 31#include "event.h"
32#include "evsel.h" 32#include "evsel.h"
33#include "util/env.h"
33#include "util/evsel_config.h" 34#include "util/evsel_config.h"
34#include "util/evsel_fprintf.h" 35#include "util/evsel_fprintf.h"
35#include "evlist.h" 36#include "evlist.h"
@@ -2512,7 +2513,7 @@ struct perf_env *perf_evsel__env(struct evsel *evsel)
2512{ 2513{
2513 if (evsel && evsel->evlist) 2514 if (evsel && evsel->evlist)
2514 return evsel->evlist->env; 2515 return evsel->evlist->env;
2515 return NULL; 2516 return &perf_env;
2516} 2517}
2517 2518
2518static int store_evsel_ids(struct evsel *evsel, struct evlist *evlist) 2519static int store_evsel_ids(struct evsel *evsel, struct evlist *evlist)
diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index 1bdf4c6ea3e5..e3ccb0ce1938 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -395,7 +395,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
395 size_t size; 395 size_t size;
396 u16 idr_size; 396 u16 idr_size;
397 const char *sym; 397 const char *sym;
398 uint32_t count; 398 uint64_t count;
399 int ret, csize, usize; 399 int ret, csize, usize;
400 pid_t pid, tid; 400 pid_t pid, tid;
401 struct { 401 struct {
@@ -418,7 +418,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
418 return -1; 418 return -1;
419 419
420 filename = event->mmap2.filename; 420 filename = event->mmap2.filename;
421 size = snprintf(filename, PATH_MAX, "%s/jitted-%d-%u.so", 421 size = snprintf(filename, PATH_MAX, "%s/jitted-%d-%" PRIu64 ".so",
422 jd->dir, 422 jd->dir,
423 pid, 423 pid,
424 count); 424 count);
@@ -529,7 +529,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
529 return -1; 529 return -1;
530 530
531 filename = event->mmap2.filename; 531 filename = event->mmap2.filename;
532 size = snprintf(filename, PATH_MAX, "%s/jitted-%d-%"PRIu64, 532 size = snprintf(filename, PATH_MAX, "%s/jitted-%d-%" PRIu64 ".so",
533 jd->dir, 533 jd->dir,
534 pid, 534 pid,
535 jr->move.code_index); 535 jr->move.code_index);
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 8d04e3d070b1..8b14e4a7f1dc 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -233,14 +233,14 @@ static int detect_kbuild_dir(char **kbuild_dir)
233 const char *prefix_dir = ""; 233 const char *prefix_dir = "";
234 const char *suffix_dir = ""; 234 const char *suffix_dir = "";
235 235
236 /* _UTSNAME_LENGTH is 65 */
237 char release[128];
238
236 char *autoconf_path; 239 char *autoconf_path;
237 240
238 int err; 241 int err;
239 242
240 if (!test_dir) { 243 if (!test_dir) {
241 /* _UTSNAME_LENGTH is 65 */
242 char release[128];
243
244 err = fetch_kernel_version(NULL, release, 244 err = fetch_kernel_version(NULL, release,
245 sizeof(release)); 245 sizeof(release));
246 if (err) 246 if (err)
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 5b83ed1ebbd6..eec9b282c047 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -1,5 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0
2#include "symbol.h" 2#include "symbol.h"
3#include <assert.h>
3#include <errno.h> 4#include <errno.h>
4#include <inttypes.h> 5#include <inttypes.h>
5#include <limits.h> 6#include <limits.h>
@@ -850,6 +851,8 @@ static int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp
850 } 851 }
851 852
852 after->start = map->end; 853 after->start = map->end;
854 after->pgoff += map->end - pos->start;
855 assert(pos->map_ip(pos, map->end) == after->map_ip(after, map->end));
853 __map_groups__insert(pos->groups, after); 856 __map_groups__insert(pos->groups, after);
854 if (verbose >= 2 && !use_browser) 857 if (verbose >= 2 && !use_browser)
855 map__fprintf(after, fp); 858 map__fprintf(after, fp);
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 53f31053a27a..02460362256d 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -14,6 +14,7 @@
14#include "thread_map.h" 14#include "thread_map.h"
15#include "trace-event.h" 15#include "trace-event.h"
16#include "mmap.h" 16#include "mmap.h"
17#include "util/env.h"
17#include <internal/lib.h> 18#include <internal/lib.h>
18#include "../perf-sys.h" 19#include "../perf-sys.h"
19 20
@@ -54,6 +55,11 @@ int parse_callchain_record(const char *arg __maybe_unused,
54} 55}
55 56
56/* 57/*
58 * Add this one here not to drag util/env.c
59 */
60struct perf_env perf_env;
61
62/*
57 * Support debug printing even though util/debug.c is not linked. That means 63 * Support debug printing even though util/debug.c is not linked. That means
58 * implementing 'verbose' and 'eprintf'. 64 * implementing 'verbose' and 'eprintf'.
59 */ 65 */
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index c3feccb99ff5..4cdbae6f4e61 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -63,6 +63,13 @@ TARGETS += zram
63TARGETS_HOTPLUG = cpu-hotplug 63TARGETS_HOTPLUG = cpu-hotplug
64TARGETS_HOTPLUG += memory-hotplug 64TARGETS_HOTPLUG += memory-hotplug
65 65
66# User can optionally provide a TARGETS skiplist.
67SKIP_TARGETS ?=
68ifneq ($(SKIP_TARGETS),)
69 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
70 override TARGETS := $(TMP)
71endif
72
66# Clear LDFLAGS and MAKEFLAGS if called from main 73# Clear LDFLAGS and MAKEFLAGS if called from main
67# Makefile to avoid test build failures when test 74# Makefile to avoid test build failures when test
68# Makefile doesn't have explicit build rules. 75# Makefile doesn't have explicit build rules.
@@ -171,9 +178,12 @@ run_pstore_crash:
171# 1. output_dir=kernel_src 178# 1. output_dir=kernel_src
172# 2. a separate output directory is specified using O= KBUILD_OUTPUT 179# 2. a separate output directory is specified using O= KBUILD_OUTPUT
173# 3. a separate output directory is specified using KBUILD_OUTPUT 180# 3. a separate output directory is specified using KBUILD_OUTPUT
181# Avoid conflict with INSTALL_PATH set by the main Makefile
174# 182#
175INSTALL_PATH ?= $(BUILD)/install 183KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
176INSTALL_PATH := $(abspath $(INSTALL_PATH)) 184KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
185# Avoid changing the rest of the logic here and lib.mk.
186INSTALL_PATH := $(KSFT_INSTALL_PATH)
177ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh 187ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
178 188
179install: all 189install: all
@@ -198,11 +208,16 @@ ifdef INSTALL_PATH
198 echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT) 208 echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
199 echo "fi" >> $(ALL_SCRIPT) 209 echo "fi" >> $(ALL_SCRIPT)
200 210
211 @# While building run_kselftest.sh skip also non-existent TARGET dirs:
212 @# they could be the result of a build failure and should NOT be
213 @# included in the generated runlist.
201 for TARGET in $(TARGETS); do \ 214 for TARGET in $(TARGETS); do \
202 BUILD_TARGET=$$BUILD/$$TARGET; \ 215 BUILD_TARGET=$$BUILD/$$TARGET; \
216 [ ! -d $$INSTALL_PATH/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
203 echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \ 217 echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
204 echo "cd $$TARGET" >> $(ALL_SCRIPT); \ 218 echo "cd $$TARGET" >> $(ALL_SCRIPT); \
205 echo -n "run_many" >> $(ALL_SCRIPT); \ 219 echo -n "run_many" >> $(ALL_SCRIPT); \
220 echo -n "Emit Tests for $$TARGET\n"; \
206 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \ 221 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
207 echo "" >> $(ALL_SCRIPT); \ 222 echo "" >> $(ALL_SCRIPT); \
208 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \ 223 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c
index 6cbeea7b4bf1..8547ecbdc61f 100644
--- a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c
+++ b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c
@@ -195,7 +195,7 @@ static void run_test(int cgroup_fd)
195 195
196 if (CHECK_FAIL(pthread_create(&tid, NULL, server_thread, 196 if (CHECK_FAIL(pthread_create(&tid, NULL, server_thread,
197 (void *)&server_fd))) 197 (void *)&server_fd)))
198 goto close_bpf_object; 198 goto close_server_fd;
199 199
200 pthread_mutex_lock(&server_started_mtx); 200 pthread_mutex_lock(&server_started_mtx);
201 pthread_cond_wait(&server_started, &server_started_mtx); 201 pthread_cond_wait(&server_started, &server_started_mtx);
diff --git a/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c b/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c
index a82da555b1b0..f4cd60d6fba2 100644
--- a/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c
+++ b/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c
@@ -260,13 +260,14 @@ void test_tcp_rtt(void)
260 260
261 if (CHECK_FAIL(pthread_create(&tid, NULL, server_thread, 261 if (CHECK_FAIL(pthread_create(&tid, NULL, server_thread,
262 (void *)&server_fd))) 262 (void *)&server_fd)))
263 goto close_cgroup_fd; 263 goto close_server_fd;
264 264
265 pthread_mutex_lock(&server_started_mtx); 265 pthread_mutex_lock(&server_started_mtx);
266 pthread_cond_wait(&server_started, &server_started_mtx); 266 pthread_cond_wait(&server_started, &server_started_mtx);
267 pthread_mutex_unlock(&server_started_mtx); 267 pthread_mutex_unlock(&server_started_mtx);
268 268
269 CHECK_FAIL(run_test(cgroup_fd, server_fd)); 269 CHECK_FAIL(run_test(cgroup_fd, server_fd));
270close_server_fd:
270 close(server_fd); 271 close(server_fd);
271close_cgroup_fd: 272close_cgroup_fd:
272 close(cgroup_fd); 273 close(cgroup_fd);
diff --git a/tools/testing/selftests/bpf/test_flow_dissector.sh b/tools/testing/selftests/bpf/test_flow_dissector.sh
index d23d4da66b83..e2d06191bd35 100755
--- a/tools/testing/selftests/bpf/test_flow_dissector.sh
+++ b/tools/testing/selftests/bpf/test_flow_dissector.sh
@@ -63,6 +63,9 @@ fi
63 63
64# Setup 64# Setup
65tc qdisc add dev lo ingress 65tc qdisc add dev lo ingress
66echo 0 > /proc/sys/net/ipv4/conf/default/rp_filter
67echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter
68echo 0 > /proc/sys/net/ipv4/conf/lo/rp_filter
66 69
67echo "Testing IPv4..." 70echo "Testing IPv4..."
68# Drops all IP/UDP packets coming from port 9 71# Drops all IP/UDP packets coming from port 9
diff --git a/tools/testing/selftests/bpf/test_lwt_ip_encap.sh b/tools/testing/selftests/bpf/test_lwt_ip_encap.sh
index acf7a74f97cd..59ea56945e6c 100755
--- a/tools/testing/selftests/bpf/test_lwt_ip_encap.sh
+++ b/tools/testing/selftests/bpf/test_lwt_ip_encap.sh
@@ -314,15 +314,15 @@ test_gso()
314 command -v nc >/dev/null 2>&1 || \ 314 command -v nc >/dev/null 2>&1 || \
315 { echo >&2 "nc is not available: skipping TSO tests"; return; } 315 { echo >&2 "nc is not available: skipping TSO tests"; return; }
316 316
317 # listen on IPv*_DST, capture TCP into $TMPFILE 317 # listen on port 9000, capture TCP into $TMPFILE
318 if [ "${PROTO}" == "IPv4" ] ; then 318 if [ "${PROTO}" == "IPv4" ] ; then
319 IP_DST=${IPv4_DST} 319 IP_DST=${IPv4_DST}
320 ip netns exec ${NS3} bash -c \ 320 ip netns exec ${NS3} bash -c \
321 "nc -4 -l -s ${IPv4_DST} -p 9000 > ${TMPFILE} &" 321 "nc -4 -l -p 9000 > ${TMPFILE} &"
322 elif [ "${PROTO}" == "IPv6" ] ; then 322 elif [ "${PROTO}" == "IPv6" ] ; then
323 IP_DST=${IPv6_DST} 323 IP_DST=${IPv6_DST}
324 ip netns exec ${NS3} bash -c \ 324 ip netns exec ${NS3} bash -c \
325 "nc -6 -l -s ${IPv6_DST} -p 9000 > ${TMPFILE} &" 325 "nc -6 -l -p 9000 > ${TMPFILE} &"
326 RET=$? 326 RET=$?
327 else 327 else
328 echo " test_gso: unknown PROTO: ${PROTO}" 328 echo " test_gso: unknown PROTO: ${PROTO}"
diff --git a/tools/testing/selftests/bpf/test_tc_edt.sh b/tools/testing/selftests/bpf/test_tc_edt.sh
index f38567ef694b..daa7d1b8d309 100755
--- a/tools/testing/selftests/bpf/test_tc_edt.sh
+++ b/tools/testing/selftests/bpf/test_tc_edt.sh
@@ -59,7 +59,7 @@ ip netns exec ${NS_SRC} tc filter add dev veth_src egress \
59 59
60# start the listener 60# start the listener
61ip netns exec ${NS_DST} bash -c \ 61ip netns exec ${NS_DST} bash -c \
62 "nc -4 -l -s ${IP_DST} -p 9000 >/dev/null &" 62 "nc -4 -l -p 9000 >/dev/null &"
63declare -i NC_PID=$! 63declare -i NC_PID=$!
64sleep 1 64sleep 1
65 65
diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh
index 00c9020bdda8..84de7bc74f2c 100644
--- a/tools/testing/selftests/kselftest/runner.sh
+++ b/tools/testing/selftests/kselftest/runner.sh
@@ -3,9 +3,14 @@
3# 3#
4# Runs a set of tests in a given subdirectory. 4# Runs a set of tests in a given subdirectory.
5export skip_rc=4 5export skip_rc=4
6export timeout_rc=124
6export logfile=/dev/stdout 7export logfile=/dev/stdout
7export per_test_logging= 8export per_test_logging=
8 9
10# Defaults for "settings" file fields:
11# "timeout" how many seconds to let each test run before failing.
12export kselftest_default_timeout=45
13
9# There isn't a shell-agnostic way to find the path of a sourced file, 14# There isn't a shell-agnostic way to find the path of a sourced file,
10# so we must rely on BASE_DIR being set to find other tools. 15# so we must rely on BASE_DIR being set to find other tools.
11if [ -z "$BASE_DIR" ]; then 16if [ -z "$BASE_DIR" ]; then
@@ -24,6 +29,16 @@ tap_prefix()
24 fi 29 fi
25} 30}
26 31
32tap_timeout()
33{
34 # Make sure tests will time out if utility is available.
35 if [ -x /usr/bin/timeout ] ; then
36 /usr/bin/timeout "$kselftest_timeout" "$1"
37 else
38 "$1"
39 fi
40}
41
27run_one() 42run_one()
28{ 43{
29 DIR="$1" 44 DIR="$1"
@@ -32,6 +47,18 @@ run_one()
32 47
33 BASENAME_TEST=$(basename $TEST) 48 BASENAME_TEST=$(basename $TEST)
34 49
50 # Reset any "settings"-file variables.
51 export kselftest_timeout="$kselftest_default_timeout"
52 # Load per-test-directory kselftest "settings" file.
53 settings="$BASE_DIR/$DIR/settings"
54 if [ -r "$settings" ] ; then
55 while read line ; do
56 field=$(echo "$line" | cut -d= -f1)
57 value=$(echo "$line" | cut -d= -f2-)
58 eval "kselftest_$field"="$value"
59 done < "$settings"
60 fi
61
35 TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST" 62 TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST"
36 echo "# $TEST_HDR_MSG" 63 echo "# $TEST_HDR_MSG"
37 if [ ! -x "$TEST" ]; then 64 if [ ! -x "$TEST" ]; then
@@ -44,14 +71,17 @@ run_one()
44 echo "not ok $test_num $TEST_HDR_MSG" 71 echo "not ok $test_num $TEST_HDR_MSG"
45 else 72 else
46 cd `dirname $TEST` > /dev/null 73 cd `dirname $TEST` > /dev/null
47 (((((./$BASENAME_TEST 2>&1; echo $? >&3) | 74 ((((( tap_timeout ./$BASENAME_TEST 2>&1; echo $? >&3) |
48 tap_prefix >&4) 3>&1) | 75 tap_prefix >&4) 3>&1) |
49 (read xs; exit $xs)) 4>>"$logfile" && 76 (read xs; exit $xs)) 4>>"$logfile" &&
50 echo "ok $test_num $TEST_HDR_MSG") || 77 echo "ok $test_num $TEST_HDR_MSG") ||
51 (if [ $? -eq $skip_rc ]; then \ 78 (rc=$?; \
79 if [ $rc -eq $skip_rc ]; then \
52 echo "not ok $test_num $TEST_HDR_MSG # SKIP" 80 echo "not ok $test_num $TEST_HDR_MSG # SKIP"
81 elif [ $rc -eq $timeout_rc ]; then \
82 echo "not ok $test_num $TEST_HDR_MSG # TIMEOUT"
53 else 83 else
54 echo "not ok $test_num $TEST_HDR_MSG" 84 echo "not ok $test_num $TEST_HDR_MSG # exit=$rc"
55 fi) 85 fi)
56 cd - >/dev/null 86 cd - >/dev/null
57 fi 87 fi
diff --git a/tools/testing/selftests/kselftest_install.sh b/tools/testing/selftests/kselftest_install.sh
index ec304463883c..e2e1911d62d5 100755
--- a/tools/testing/selftests/kselftest_install.sh
+++ b/tools/testing/selftests/kselftest_install.sh
@@ -24,12 +24,12 @@ main()
24 echo "$0: Installing in specified location - $install_loc ..." 24 echo "$0: Installing in specified location - $install_loc ..."
25 fi 25 fi
26 26
27 install_dir=$install_loc/kselftest 27 install_dir=$install_loc/kselftest_install
28 28
29# Create install directory 29# Create install directory
30 mkdir -p $install_dir 30 mkdir -p $install_dir
31# Build tests 31# Build tests
32 INSTALL_PATH=$install_dir make install 32 KSFT_INSTALL_PATH=$install_dir make install
33} 33}
34 34
35main "$@" 35main "$@"
diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index 62c591f87dab..c5ec868fa1e5 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -22,6 +22,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/smm_test
22TEST_GEN_PROGS_x86_64 += x86_64/state_test 22TEST_GEN_PROGS_x86_64 += x86_64/state_test
23TEST_GEN_PROGS_x86_64 += x86_64/sync_regs_test 23TEST_GEN_PROGS_x86_64 += x86_64/sync_regs_test
24TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test 24TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test
25TEST_GEN_PROGS_x86_64 += x86_64/vmx_dirty_log_test
25TEST_GEN_PROGS_x86_64 += x86_64/vmx_set_nested_state_test 26TEST_GEN_PROGS_x86_64 += x86_64/vmx_set_nested_state_test
26TEST_GEN_PROGS_x86_64 += x86_64/vmx_tsc_adjust_test 27TEST_GEN_PROGS_x86_64 += x86_64/vmx_tsc_adjust_test
27TEST_GEN_PROGS_x86_64 += clear_dirty_log_test 28TEST_GEN_PROGS_x86_64 += clear_dirty_log_test
@@ -48,7 +49,7 @@ CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \
48 -I$(LINUX_HDR_PATH) -Iinclude -I$(<D) -Iinclude/$(UNAME_M) -I.. 49 -I$(LINUX_HDR_PATH) -Iinclude -I$(<D) -Iinclude/$(UNAME_M) -I..
49 50
50no-pie-option := $(call try-run, echo 'int main() { return 0; }' | \ 51no-pie-option := $(call try-run, echo 'int main() { return 0; }' | \
51 $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -no-pie -x c - -o "$$TMP", -no-pie) 52 $(CC) -Werror -no-pie -x c - -o "$$TMP", -no-pie)
52 53
53# On s390, build the testcases KVM-enabled 54# On s390, build the testcases KVM-enabled
54pgste-option = $(call try-run, echo 'int main() { return 0; }' | \ 55pgste-option = $(call try-run, echo 'int main() { return 0; }' | \
diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h
index 0c17f2ee685e..ff234018219c 100644
--- a/tools/testing/selftests/kvm/include/x86_64/processor.h
+++ b/tools/testing/selftests/kvm/include/x86_64/processor.h
@@ -1083,6 +1083,9 @@ void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits);
1083#define VMX_BASIC_MEM_TYPE_WB 6LLU 1083#define VMX_BASIC_MEM_TYPE_WB 6LLU
1084#define VMX_BASIC_INOUT 0x0040000000000000LLU 1084#define VMX_BASIC_INOUT 0x0040000000000000LLU
1085 1085
1086/* VMX_EPT_VPID_CAP bits */
1087#define VMX_EPT_VPID_CAP_AD_BITS (1ULL << 21)
1088
1086/* MSR_IA32_VMX_MISC bits */ 1089/* MSR_IA32_VMX_MISC bits */
1087#define MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS (1ULL << 29) 1090#define MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS (1ULL << 29)
1088#define MSR_IA32_VMX_MISC_PREEMPTION_TIMER_SCALE 0x1F 1091#define MSR_IA32_VMX_MISC_PREEMPTION_TIMER_SCALE 0x1F
diff --git a/tools/testing/selftests/kvm/include/x86_64/vmx.h b/tools/testing/selftests/kvm/include/x86_64/vmx.h
index 69b17055f63d..6ae5a47fe067 100644
--- a/tools/testing/selftests/kvm/include/x86_64/vmx.h
+++ b/tools/testing/selftests/kvm/include/x86_64/vmx.h
@@ -569,6 +569,10 @@ struct vmx_pages {
569 void *enlightened_vmcs_hva; 569 void *enlightened_vmcs_hva;
570 uint64_t enlightened_vmcs_gpa; 570 uint64_t enlightened_vmcs_gpa;
571 void *enlightened_vmcs; 571 void *enlightened_vmcs;
572
573 void *eptp_hva;
574 uint64_t eptp_gpa;
575 void *eptp;
572}; 576};
573 577
574struct vmx_pages *vcpu_alloc_vmx(struct kvm_vm *vm, vm_vaddr_t *p_vmx_gva); 578struct vmx_pages *vcpu_alloc_vmx(struct kvm_vm *vm, vm_vaddr_t *p_vmx_gva);
@@ -576,4 +580,14 @@ bool prepare_for_vmx_operation(struct vmx_pages *vmx);
576void prepare_vmcs(struct vmx_pages *vmx, void *guest_rip, void *guest_rsp); 580void prepare_vmcs(struct vmx_pages *vmx, void *guest_rip, void *guest_rsp);
577bool load_vmcs(struct vmx_pages *vmx); 581bool load_vmcs(struct vmx_pages *vmx);
578 582
583void nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm,
584 uint64_t nested_paddr, uint64_t paddr, uint32_t eptp_memslot);
585void nested_map(struct vmx_pages *vmx, struct kvm_vm *vm,
586 uint64_t nested_paddr, uint64_t paddr, uint64_t size,
587 uint32_t eptp_memslot);
588void nested_map_memslot(struct vmx_pages *vmx, struct kvm_vm *vm,
589 uint32_t memslot, uint32_t eptp_memslot);
590void prepare_eptp(struct vmx_pages *vmx, struct kvm_vm *vm,
591 uint32_t eptp_memslot);
592
579#endif /* SELFTEST_KVM_VMX_H */ 593#endif /* SELFTEST_KVM_VMX_H */
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 80a338b5403c..41cf45416060 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -705,7 +705,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
705 * on error (e.g. currently no memory region using memslot as a KVM 705 * on error (e.g. currently no memory region using memslot as a KVM
706 * memory slot ID). 706 * memory slot ID).
707 */ 707 */
708static struct userspace_mem_region * 708struct userspace_mem_region *
709memslot2region(struct kvm_vm *vm, uint32_t memslot) 709memslot2region(struct kvm_vm *vm, uint32_t memslot)
710{ 710{
711 struct userspace_mem_region *region; 711 struct userspace_mem_region *region;
diff --git a/tools/testing/selftests/kvm/lib/kvm_util_internal.h b/tools/testing/selftests/kvm/lib/kvm_util_internal.h
index f36262e0f655..ac50c42750cf 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util_internal.h
+++ b/tools/testing/selftests/kvm/lib/kvm_util_internal.h
@@ -68,4 +68,7 @@ void virt_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent);
68void regs_dump(FILE *stream, struct kvm_regs *regs, uint8_t indent); 68void regs_dump(FILE *stream, struct kvm_regs *regs, uint8_t indent);
69void sregs_dump(FILE *stream, struct kvm_sregs *sregs, uint8_t indent); 69void sregs_dump(FILE *stream, struct kvm_sregs *sregs, uint8_t indent);
70 70
71struct userspace_mem_region *
72memslot2region(struct kvm_vm *vm, uint32_t memslot);
73
71#endif /* SELFTEST_KVM_UTIL_INTERNAL_H */ 74#endif /* SELFTEST_KVM_UTIL_INTERNAL_H */
diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c
index c53dbc6bc568..6698cb741e10 100644
--- a/tools/testing/selftests/kvm/lib/x86_64/processor.c
+++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c
@@ -1085,7 +1085,7 @@ struct kvm_x86_state *vcpu_save_state(struct kvm_vm *vm, uint32_t vcpuid)
1085 for (i = 0; i < nmsrs; i++) 1085 for (i = 0; i < nmsrs; i++)
1086 state->msrs.entries[i].index = list->indices[i]; 1086 state->msrs.entries[i].index = list->indices[i];
1087 r = ioctl(vcpu->fd, KVM_GET_MSRS, &state->msrs); 1087 r = ioctl(vcpu->fd, KVM_GET_MSRS, &state->msrs);
1088 TEST_ASSERT(r == nmsrs, "Unexpected result from KVM_GET_MSRS, r: %i (failed at %x)", 1088 TEST_ASSERT(r == nmsrs, "Unexpected result from KVM_GET_MSRS, r: %i (failed MSR was 0x%x)",
1089 r, r == nmsrs ? -1 : list->indices[r]); 1089 r, r == nmsrs ? -1 : list->indices[r]);
1090 1090
1091 r = ioctl(vcpu->fd, KVM_GET_DEBUGREGS, &state->debugregs); 1091 r = ioctl(vcpu->fd, KVM_GET_DEBUGREGS, &state->debugregs);
diff --git a/tools/testing/selftests/kvm/lib/x86_64/vmx.c b/tools/testing/selftests/kvm/lib/x86_64/vmx.c
index 9cef0455b819..fab8f6b0bf52 100644
--- a/tools/testing/selftests/kvm/lib/x86_64/vmx.c
+++ b/tools/testing/selftests/kvm/lib/x86_64/vmx.c
@@ -7,11 +7,39 @@
7 7
8#include "test_util.h" 8#include "test_util.h"
9#include "kvm_util.h" 9#include "kvm_util.h"
10#include "../kvm_util_internal.h"
10#include "processor.h" 11#include "processor.h"
11#include "vmx.h" 12#include "vmx.h"
12 13
14#define PAGE_SHIFT_4K 12
15
16#define KVM_EPT_PAGE_TABLE_MIN_PADDR 0x1c0000
17
13bool enable_evmcs; 18bool enable_evmcs;
14 19
20struct eptPageTableEntry {
21 uint64_t readable:1;
22 uint64_t writable:1;
23 uint64_t executable:1;
24 uint64_t memory_type:3;
25 uint64_t ignore_pat:1;
26 uint64_t page_size:1;
27 uint64_t accessed:1;
28 uint64_t dirty:1;
29 uint64_t ignored_11_10:2;
30 uint64_t address:40;
31 uint64_t ignored_62_52:11;
32 uint64_t suppress_ve:1;
33};
34
35struct eptPageTablePointer {
36 uint64_t memory_type:3;
37 uint64_t page_walk_length:3;
38 uint64_t ad_enabled:1;
39 uint64_t reserved_11_07:5;
40 uint64_t address:40;
41 uint64_t reserved_63_52:12;
42};
15int vcpu_enable_evmcs(struct kvm_vm *vm, int vcpu_id) 43int vcpu_enable_evmcs(struct kvm_vm *vm, int vcpu_id)
16{ 44{
17 uint16_t evmcs_ver; 45 uint16_t evmcs_ver;
@@ -174,15 +202,35 @@ bool load_vmcs(struct vmx_pages *vmx)
174 */ 202 */
175static inline void init_vmcs_control_fields(struct vmx_pages *vmx) 203static inline void init_vmcs_control_fields(struct vmx_pages *vmx)
176{ 204{
205 uint32_t sec_exec_ctl = 0;
206
177 vmwrite(VIRTUAL_PROCESSOR_ID, 0); 207 vmwrite(VIRTUAL_PROCESSOR_ID, 0);
178 vmwrite(POSTED_INTR_NV, 0); 208 vmwrite(POSTED_INTR_NV, 0);
179 209
180 vmwrite(PIN_BASED_VM_EXEC_CONTROL, rdmsr(MSR_IA32_VMX_TRUE_PINBASED_CTLS)); 210 vmwrite(PIN_BASED_VM_EXEC_CONTROL, rdmsr(MSR_IA32_VMX_TRUE_PINBASED_CTLS));
181 if (!vmwrite(SECONDARY_VM_EXEC_CONTROL, 0)) 211
212 if (vmx->eptp_gpa) {
213 uint64_t ept_paddr;
214 struct eptPageTablePointer eptp = {
215 .memory_type = VMX_BASIC_MEM_TYPE_WB,
216 .page_walk_length = 3, /* + 1 */
217 .ad_enabled = !!(rdmsr(MSR_IA32_VMX_EPT_VPID_CAP) & VMX_EPT_VPID_CAP_AD_BITS),
218 .address = vmx->eptp_gpa >> PAGE_SHIFT_4K,
219 };
220
221 memcpy(&ept_paddr, &eptp, sizeof(ept_paddr));
222 vmwrite(EPT_POINTER, ept_paddr);
223 sec_exec_ctl |= SECONDARY_EXEC_ENABLE_EPT;
224 }
225
226 if (!vmwrite(SECONDARY_VM_EXEC_CONTROL, sec_exec_ctl))
182 vmwrite(CPU_BASED_VM_EXEC_CONTROL, 227 vmwrite(CPU_BASED_VM_EXEC_CONTROL,
183 rdmsr(MSR_IA32_VMX_TRUE_PROCBASED_CTLS) | CPU_BASED_ACTIVATE_SECONDARY_CONTROLS); 228 rdmsr(MSR_IA32_VMX_TRUE_PROCBASED_CTLS) | CPU_BASED_ACTIVATE_SECONDARY_CONTROLS);
184 else 229 else {
185 vmwrite(CPU_BASED_VM_EXEC_CONTROL, rdmsr(MSR_IA32_VMX_TRUE_PROCBASED_CTLS)); 230 vmwrite(CPU_BASED_VM_EXEC_CONTROL, rdmsr(MSR_IA32_VMX_TRUE_PROCBASED_CTLS));
231 GUEST_ASSERT(!sec_exec_ctl);
232 }
233
186 vmwrite(EXCEPTION_BITMAP, 0); 234 vmwrite(EXCEPTION_BITMAP, 0);
187 vmwrite(PAGE_FAULT_ERROR_CODE_MASK, 0); 235 vmwrite(PAGE_FAULT_ERROR_CODE_MASK, 0);
188 vmwrite(PAGE_FAULT_ERROR_CODE_MATCH, -1); /* Never match */ 236 vmwrite(PAGE_FAULT_ERROR_CODE_MATCH, -1); /* Never match */
@@ -327,3 +375,152 @@ void prepare_vmcs(struct vmx_pages *vmx, void *guest_rip, void *guest_rsp)
327 init_vmcs_host_state(); 375 init_vmcs_host_state();
328 init_vmcs_guest_state(guest_rip, guest_rsp); 376 init_vmcs_guest_state(guest_rip, guest_rsp);
329} 377}
378
379void nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm,
380 uint64_t nested_paddr, uint64_t paddr, uint32_t eptp_memslot)
381{
382 uint16_t index[4];
383 struct eptPageTableEntry *pml4e;
384
385 TEST_ASSERT(vm->mode == VM_MODE_PXXV48_4K, "Attempt to use "
386 "unknown or unsupported guest mode, mode: 0x%x", vm->mode);
387
388 TEST_ASSERT((nested_paddr % vm->page_size) == 0,
389 "Nested physical address not on page boundary,\n"
390 " nested_paddr: 0x%lx vm->page_size: 0x%x",
391 nested_paddr, vm->page_size);
392 TEST_ASSERT((nested_paddr >> vm->page_shift) <= vm->max_gfn,
393 "Physical address beyond beyond maximum supported,\n"
394 " nested_paddr: 0x%lx vm->max_gfn: 0x%lx vm->page_size: 0x%x",
395 paddr, vm->max_gfn, vm->page_size);
396 TEST_ASSERT((paddr % vm->page_size) == 0,
397 "Physical address not on page boundary,\n"
398 " paddr: 0x%lx vm->page_size: 0x%x",
399 paddr, vm->page_size);
400 TEST_ASSERT((paddr >> vm->page_shift) <= vm->max_gfn,
401 "Physical address beyond beyond maximum supported,\n"
402 " paddr: 0x%lx vm->max_gfn: 0x%lx vm->page_size: 0x%x",
403 paddr, vm->max_gfn, vm->page_size);
404
405 index[0] = (nested_paddr >> 12) & 0x1ffu;
406 index[1] = (nested_paddr >> 21) & 0x1ffu;
407 index[2] = (nested_paddr >> 30) & 0x1ffu;
408 index[3] = (nested_paddr >> 39) & 0x1ffu;
409
410 /* Allocate page directory pointer table if not present. */
411 pml4e = vmx->eptp_hva;
412 if (!pml4e[index[3]].readable) {
413 pml4e[index[3]].address = vm_phy_page_alloc(vm,
414 KVM_EPT_PAGE_TABLE_MIN_PADDR, eptp_memslot)
415 >> vm->page_shift;
416 pml4e[index[3]].writable = true;
417 pml4e[index[3]].readable = true;
418 pml4e[index[3]].executable = true;
419 }
420
421 /* Allocate page directory table if not present. */
422 struct eptPageTableEntry *pdpe;
423 pdpe = addr_gpa2hva(vm, pml4e[index[3]].address * vm->page_size);
424 if (!pdpe[index[2]].readable) {
425 pdpe[index[2]].address = vm_phy_page_alloc(vm,
426 KVM_EPT_PAGE_TABLE_MIN_PADDR, eptp_memslot)
427 >> vm->page_shift;
428 pdpe[index[2]].writable = true;
429 pdpe[index[2]].readable = true;
430 pdpe[index[2]].executable = true;
431 }
432
433 /* Allocate page table if not present. */
434 struct eptPageTableEntry *pde;
435 pde = addr_gpa2hva(vm, pdpe[index[2]].address * vm->page_size);
436 if (!pde[index[1]].readable) {
437 pde[index[1]].address = vm_phy_page_alloc(vm,
438 KVM_EPT_PAGE_TABLE_MIN_PADDR, eptp_memslot)
439 >> vm->page_shift;
440 pde[index[1]].writable = true;
441 pde[index[1]].readable = true;
442 pde[index[1]].executable = true;
443 }
444
445 /* Fill in page table entry. */
446 struct eptPageTableEntry *pte;
447 pte = addr_gpa2hva(vm, pde[index[1]].address * vm->page_size);
448 pte[index[0]].address = paddr >> vm->page_shift;
449 pte[index[0]].writable = true;
450 pte[index[0]].readable = true;
451 pte[index[0]].executable = true;
452
453 /*
454 * For now mark these as accessed and dirty because the only
455 * testcase we have needs that. Can be reconsidered later.
456 */
457 pte[index[0]].accessed = true;
458 pte[index[0]].dirty = true;
459}
460
461/*
462 * Map a range of EPT guest physical addresses to the VM's physical address
463 *
464 * Input Args:
465 * vm - Virtual Machine
466 * nested_paddr - Nested guest physical address to map
467 * paddr - VM Physical Address
468 * size - The size of the range to map
469 * eptp_memslot - Memory region slot for new virtual translation tables
470 *
471 * Output Args: None
472 *
473 * Return: None
474 *
475 * Within the VM given by vm, creates a nested guest translation for the
476 * page range starting at nested_paddr to the page range starting at paddr.
477 */
478void nested_map(struct vmx_pages *vmx, struct kvm_vm *vm,
479 uint64_t nested_paddr, uint64_t paddr, uint64_t size,
480 uint32_t eptp_memslot)
481{
482 size_t page_size = vm->page_size;
483 size_t npages = size / page_size;
484
485 TEST_ASSERT(nested_paddr + size > nested_paddr, "Vaddr overflow");
486 TEST_ASSERT(paddr + size > paddr, "Paddr overflow");
487
488 while (npages--) {
489 nested_pg_map(vmx, vm, nested_paddr, paddr, eptp_memslot);
490 nested_paddr += page_size;
491 paddr += page_size;
492 }
493}
494
495/* Prepare an identity extended page table that maps all the
496 * physical pages in VM.
497 */
498void nested_map_memslot(struct vmx_pages *vmx, struct kvm_vm *vm,
499 uint32_t memslot, uint32_t eptp_memslot)
500{
501 sparsebit_idx_t i, last;
502 struct userspace_mem_region *region =
503 memslot2region(vm, memslot);
504
505 i = (region->region.guest_phys_addr >> vm->page_shift) - 1;
506 last = i + (region->region.memory_size >> vm->page_shift);
507 for (;;) {
508 i = sparsebit_next_clear(region->unused_phy_pages, i);
509 if (i > last)
510 break;
511
512 nested_map(vmx, vm,
513 (uint64_t)i << vm->page_shift,
514 (uint64_t)i << vm->page_shift,
515 1 << vm->page_shift,
516 eptp_memslot);
517 }
518}
519
520void prepare_eptp(struct vmx_pages *vmx, struct kvm_vm *vm,
521 uint32_t eptp_memslot)
522{
523 vmx->eptp = (void *)vm_vaddr_alloc(vm, getpagesize(), 0x10000, 0, 0);
524 vmx->eptp_hva = addr_gva2hva(vm, (uintptr_t)vmx->eptp);
525 vmx->eptp_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->eptp);
526}
diff --git a/tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c b/tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c
new file mode 100644
index 000000000000..0bca1cfe2c1e
--- /dev/null
+++ b/tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c
@@ -0,0 +1,156 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * KVM dirty page logging test
4 *
5 * Copyright (C) 2018, Red Hat, Inc.
6 */
7
8#define _GNU_SOURCE /* for program_invocation_name */
9
10#include <stdio.h>
11#include <stdlib.h>
12#include <linux/bitmap.h>
13#include <linux/bitops.h>
14
15#include "test_util.h"
16#include "kvm_util.h"
17#include "processor.h"
18#include "vmx.h"
19
20#define VCPU_ID 1
21
22/* The memory slot index to track dirty pages */
23#define TEST_MEM_SLOT_INDEX 1
24#define TEST_MEM_SIZE 3
25
26/* L1 guest test virtual memory offset */
27#define GUEST_TEST_MEM 0xc0000000
28
29/* L2 guest test virtual memory offset */
30#define NESTED_TEST_MEM1 0xc0001000
31#define NESTED_TEST_MEM2 0xc0002000
32
33static void l2_guest_code(void)
34{
35 *(volatile uint64_t *)NESTED_TEST_MEM1;
36 *(volatile uint64_t *)NESTED_TEST_MEM1 = 1;
37 GUEST_SYNC(true);
38 GUEST_SYNC(false);
39
40 *(volatile uint64_t *)NESTED_TEST_MEM2 = 1;
41 GUEST_SYNC(true);
42 *(volatile uint64_t *)NESTED_TEST_MEM2 = 1;
43 GUEST_SYNC(true);
44 GUEST_SYNC(false);
45
46 /* Exit to L1 and never come back. */
47 vmcall();
48}
49
50void l1_guest_code(struct vmx_pages *vmx)
51{
52#define L2_GUEST_STACK_SIZE 64
53 unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE];
54
55 GUEST_ASSERT(vmx->vmcs_gpa);
56 GUEST_ASSERT(prepare_for_vmx_operation(vmx));
57 GUEST_ASSERT(load_vmcs(vmx));
58
59 prepare_vmcs(vmx, l2_guest_code,
60 &l2_guest_stack[L2_GUEST_STACK_SIZE]);
61
62 GUEST_SYNC(false);
63 GUEST_ASSERT(!vmlaunch());
64 GUEST_SYNC(false);
65 GUEST_ASSERT(vmreadz(VM_EXIT_REASON) == EXIT_REASON_VMCALL);
66 GUEST_DONE();
67}
68
69int main(int argc, char *argv[])
70{
71 vm_vaddr_t vmx_pages_gva = 0;
72 struct vmx_pages *vmx;
73 unsigned long *bmap;
74 uint64_t *host_test_mem;
75
76 struct kvm_vm *vm;
77 struct kvm_run *run;
78 struct ucall uc;
79 bool done = false;
80
81 /* Create VM */
82 vm = vm_create_default(VCPU_ID, 0, l1_guest_code);
83 vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
84 vmx = vcpu_alloc_vmx(vm, &vmx_pages_gva);
85 vcpu_args_set(vm, VCPU_ID, 1, vmx_pages_gva);
86 run = vcpu_state(vm, VCPU_ID);
87
88 /* Add an extra memory slot for testing dirty logging */
89 vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS,
90 GUEST_TEST_MEM,
91 TEST_MEM_SLOT_INDEX,
92 TEST_MEM_SIZE,
93 KVM_MEM_LOG_DIRTY_PAGES);
94
95 /*
96 * Add an identity map for GVA range [0xc0000000, 0xc0002000). This
97 * affects both L1 and L2. However...
98 */
99 virt_map(vm, GUEST_TEST_MEM, GUEST_TEST_MEM,
100 TEST_MEM_SIZE * 4096, 0);
101
102 /*
103 * ... pages in the L2 GPA range [0xc0001000, 0xc0003000) will map to
104 * 0xc0000000.
105 *
106 * Note that prepare_eptp should be called only L1's GPA map is done,
107 * meaning after the last call to virt_map.
108 */
109 prepare_eptp(vmx, vm, 0);
110 nested_map_memslot(vmx, vm, 0, 0);
111 nested_map(vmx, vm, NESTED_TEST_MEM1, GUEST_TEST_MEM, 4096, 0);
112 nested_map(vmx, vm, NESTED_TEST_MEM2, GUEST_TEST_MEM, 4096, 0);
113
114 bmap = bitmap_alloc(TEST_MEM_SIZE);
115 host_test_mem = addr_gpa2hva(vm, GUEST_TEST_MEM);
116
117 while (!done) {
118 memset(host_test_mem, 0xaa, TEST_MEM_SIZE * 4096);
119 _vcpu_run(vm, VCPU_ID);
120 TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
121 "Unexpected exit reason: %u (%s),\n",
122 run->exit_reason,
123 exit_reason_str(run->exit_reason));
124
125 switch (get_ucall(vm, VCPU_ID, &uc)) {
126 case UCALL_ABORT:
127 TEST_ASSERT(false, "%s at %s:%d", (const char *)uc.args[0],
128 __FILE__, uc.args[1]);
129 /* NOT REACHED */
130 case UCALL_SYNC:
131 /*
132 * The nested guest wrote at offset 0x1000 in the memslot, but the
133 * dirty bitmap must be filled in according to L1 GPA, not L2.
134 */
135 kvm_vm_get_dirty_log(vm, TEST_MEM_SLOT_INDEX, bmap);
136 if (uc.args[1]) {
137 TEST_ASSERT(test_bit(0, bmap), "Page 0 incorrectly reported clean\n");
138 TEST_ASSERT(host_test_mem[0] == 1, "Page 0 not written by guest\n");
139 } else {
140 TEST_ASSERT(!test_bit(0, bmap), "Page 0 incorrectly reported dirty\n");
141 TEST_ASSERT(host_test_mem[0] == 0xaaaaaaaaaaaaaaaaULL, "Page 0 written by guest\n");
142 }
143
144 TEST_ASSERT(!test_bit(1, bmap), "Page 1 incorrectly reported dirty\n");
145 TEST_ASSERT(host_test_mem[4096 / 8] == 0xaaaaaaaaaaaaaaaaULL, "Page 1 written by guest\n");
146 TEST_ASSERT(!test_bit(2, bmap), "Page 2 incorrectly reported dirty\n");
147 TEST_ASSERT(host_test_mem[8192 / 8] == 0xaaaaaaaaaaaaaaaaULL, "Page 2 written by guest\n");
148 break;
149 case UCALL_DONE:
150 done = true;
151 break;
152 default:
153 TEST_ASSERT(false, "Unknown ucall 0x%x.", uc.cmd);
154 }
155 }
156}
diff --git a/tools/testing/selftests/net/.gitignore b/tools/testing/selftests/net/.gitignore
index c7cced739c34..8aefd81fbc86 100644
--- a/tools/testing/selftests/net/.gitignore
+++ b/tools/testing/selftests/net/.gitignore
@@ -21,3 +21,4 @@ ipv6_flowlabel
21ipv6_flowlabel_mgr 21ipv6_flowlabel_mgr
22so_txtime 22so_txtime
23tcp_fastopen_backup_key 23tcp_fastopen_backup_key
24nettest
diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
index c4ba0ff4a53f..76c1897e6352 100755
--- a/tools/testing/selftests/net/fib_tests.sh
+++ b/tools/testing/selftests/net/fib_tests.sh
@@ -1438,6 +1438,27 @@ ipv4_addr_metric_test()
1438 fi 1438 fi
1439 log_test $rc 0 "Prefix route with metric on link up" 1439 log_test $rc 0 "Prefix route with metric on link up"
1440 1440
1441 # explicitly check for metric changes on edge scenarios
1442 run_cmd "$IP addr flush dev dummy2"
1443 run_cmd "$IP addr add dev dummy2 172.16.104.0/24 metric 259"
1444 run_cmd "$IP addr change dev dummy2 172.16.104.0/24 metric 260"
1445 rc=$?
1446 if [ $rc -eq 0 ]; then
1447 check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.0 metric 260"
1448 rc=$?
1449 fi
1450 log_test $rc 0 "Modify metric of .0/24 address"
1451
1452 run_cmd "$IP addr flush dev dummy2"
1453 run_cmd "$IP addr add dev dummy2 172.16.104.1/32 peer 172.16.104.2 metric 260"
1454 run_cmd "$IP addr change dev dummy2 172.16.104.1/32 peer 172.16.104.2 metric 261"
1455 rc=$?
1456 if [ $rc -eq 0 ]; then
1457 check_route "172.16.104.2 dev dummy2 proto kernel scope link src 172.16.104.1 metric 261"
1458 rc=$?
1459 fi
1460 log_test $rc 0 "Modify metric of address with peer route"
1461
1441 $IP li del dummy1 1462 $IP li del dummy1
1442 $IP li del dummy2 1463 $IP li del dummy2
1443 cleanup 1464 cleanup
diff --git a/tools/testing/selftests/net/l2tp.sh b/tools/testing/selftests/net/l2tp.sh
index 5782433886fc..5782433886fc 100644..100755
--- a/tools/testing/selftests/net/l2tp.sh
+++ b/tools/testing/selftests/net/l2tp.sh
diff --git a/tools/testing/selftests/net/udpgso.c b/tools/testing/selftests/net/udpgso.c
index b8265ee9923f..614b31aad168 100644
--- a/tools/testing/selftests/net/udpgso.c
+++ b/tools/testing/selftests/net/udpgso.c
@@ -89,12 +89,9 @@ struct testcase testcases_v4[] = {
89 .tfail = true, 89 .tfail = true,
90 }, 90 },
91 { 91 {
92 /* send a single MSS: will fail with GSO, because the segment 92 /* send a single MSS: will fall back to no GSO */
93 * logic in udp4_ufo_fragment demands a gso skb to be > MTU
94 */
95 .tlen = CONST_MSS_V4, 93 .tlen = CONST_MSS_V4,
96 .gso_len = CONST_MSS_V4, 94 .gso_len = CONST_MSS_V4,
97 .tfail = true,
98 .r_num_mss = 1, 95 .r_num_mss = 1,
99 }, 96 },
100 { 97 {
@@ -139,10 +136,9 @@ struct testcase testcases_v4[] = {
139 .tfail = true, 136 .tfail = true,
140 }, 137 },
141 { 138 {
142 /* send a single 1B MSS: will fail, see single MSS above */ 139 /* send a single 1B MSS: will fall back to no GSO */
143 .tlen = 1, 140 .tlen = 1,
144 .gso_len = 1, 141 .gso_len = 1,
145 .tfail = true,
146 .r_num_mss = 1, 142 .r_num_mss = 1,
147 }, 143 },
148 { 144 {
@@ -196,12 +192,9 @@ struct testcase testcases_v6[] = {
196 .tfail = true, 192 .tfail = true,
197 }, 193 },
198 { 194 {
199 /* send a single MSS: will fail with GSO, because the segment 195 /* send a single MSS: will fall back to no GSO */
200 * logic in udp4_ufo_fragment demands a gso skb to be > MTU
201 */
202 .tlen = CONST_MSS_V6, 196 .tlen = CONST_MSS_V6,
203 .gso_len = CONST_MSS_V6, 197 .gso_len = CONST_MSS_V6,
204 .tfail = true,
205 .r_num_mss = 1, 198 .r_num_mss = 1,
206 }, 199 },
207 { 200 {
@@ -246,10 +239,9 @@ struct testcase testcases_v6[] = {
246 .tfail = true, 239 .tfail = true,
247 }, 240 },
248 { 241 {
249 /* send a single 1B MSS: will fail, see single MSS above */ 242 /* send a single 1B MSS: will fall back to no GSO */
250 .tlen = 1, 243 .tlen = 1,
251 .gso_len = 1, 244 .gso_len = 1,
252 .tfail = true,
253 .r_num_mss = 1, 245 .r_num_mss = 1,
254 }, 246 },
255 { 247 {
diff --git a/tools/testing/selftests/pidfd/Makefile b/tools/testing/selftests/pidfd/Makefile
index 464c9b76148f..7550f08822a3 100644
--- a/tools/testing/selftests/pidfd/Makefile
+++ b/tools/testing/selftests/pidfd/Makefile
@@ -1,5 +1,5 @@
1# SPDX-License-Identifier: GPL-2.0-only 1# SPDX-License-Identifier: GPL-2.0-only
2CFLAGS += -g -I../../../../usr/include/ -lpthread 2CFLAGS += -g -I../../../../usr/include/ -pthread
3 3
4TEST_GEN_PROGS := pidfd_test pidfd_open_test pidfd_poll_test pidfd_wait 4TEST_GEN_PROGS := pidfd_test pidfd_open_test pidfd_poll_test pidfd_wait
5 5
diff --git a/tools/testing/selftests/powerpc/mm/tlbie_test.c b/tools/testing/selftests/powerpc/mm/tlbie_test.c
index 9868a5ddd847..f85a0938ab25 100644
--- a/tools/testing/selftests/powerpc/mm/tlbie_test.c
+++ b/tools/testing/selftests/powerpc/mm/tlbie_test.c
@@ -636,7 +636,7 @@ int main(int argc, char *argv[])
636 nrthreads = strtoul(optarg, NULL, 10); 636 nrthreads = strtoul(optarg, NULL, 10);
637 break; 637 break;
638 case 'l': 638 case 'l':
639 strncpy(logdir, optarg, LOGDIR_NAME_SIZE); 639 strncpy(logdir, optarg, LOGDIR_NAME_SIZE - 1);
640 break; 640 break;
641 case 't': 641 case 't':
642 run_time = strtoul(optarg, NULL, 10); 642 run_time = strtoul(optarg, NULL, 10);
diff --git a/tools/testing/selftests/rtc/settings b/tools/testing/selftests/rtc/settings
new file mode 100644
index 000000000000..ba4d85f74cd6
--- /dev/null
+++ b/tools/testing/selftests/rtc/settings
@@ -0,0 +1 @@
timeout=90
diff --git a/tools/testing/selftests/vm/gup_benchmark.c b/tools/testing/selftests/vm/gup_benchmark.c
index c0534e298b51..cb3fc09645c4 100644
--- a/tools/testing/selftests/vm/gup_benchmark.c
+++ b/tools/testing/selftests/vm/gup_benchmark.c
@@ -37,7 +37,7 @@ int main(int argc, char **argv)
37 char *file = "/dev/zero"; 37 char *file = "/dev/zero";
38 char *p; 38 char *p;
39 39
40 while ((opt = getopt(argc, argv, "m:r:n:f:tTLUSH")) != -1) { 40 while ((opt = getopt(argc, argv, "m:r:n:f:tTLUwSH")) != -1) {
41 switch (opt) { 41 switch (opt) {
42 case 'm': 42 case 'm':
43 size = atoi(optarg) * MB; 43 size = atoi(optarg) * MB;
diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c
index afff120c7be6..f45e510500c0 100644
--- a/tools/testing/selftests/watchdog/watchdog-test.c
+++ b/tools/testing/selftests/watchdog/watchdog-test.c
@@ -19,7 +19,7 @@
19 19
20int fd; 20int fd;
21const char v = 'V'; 21const char v = 'V';
22static const char sopts[] = "bdehp:t:Tn:NLf:"; 22static const char sopts[] = "bdehp:t:Tn:NLf:i";
23static const struct option lopts[] = { 23static const struct option lopts[] = {
24 {"bootstatus", no_argument, NULL, 'b'}, 24 {"bootstatus", no_argument, NULL, 'b'},
25 {"disable", no_argument, NULL, 'd'}, 25 {"disable", no_argument, NULL, 'd'},
@@ -32,6 +32,7 @@ static const struct option lopts[] = {
32 {"getpretimeout", no_argument, NULL, 'N'}, 32 {"getpretimeout", no_argument, NULL, 'N'},
33 {"gettimeleft", no_argument, NULL, 'L'}, 33 {"gettimeleft", no_argument, NULL, 'L'},
34 {"file", required_argument, NULL, 'f'}, 34 {"file", required_argument, NULL, 'f'},
35 {"info", no_argument, NULL, 'i'},
35 {NULL, no_argument, NULL, 0x0} 36 {NULL, no_argument, NULL, 0x0}
36}; 37};
37 38
@@ -72,6 +73,7 @@ static void usage(char *progname)
72 printf("Usage: %s [options]\n", progname); 73 printf("Usage: %s [options]\n", progname);
73 printf(" -f, --file\t\tOpen watchdog device file\n"); 74 printf(" -f, --file\t\tOpen watchdog device file\n");
74 printf("\t\t\tDefault is /dev/watchdog\n"); 75 printf("\t\t\tDefault is /dev/watchdog\n");
76 printf(" -i, --info\t\tShow watchdog_info\n");
75 printf(" -b, --bootstatus\tGet last boot status (Watchdog/POR)\n"); 77 printf(" -b, --bootstatus\tGet last boot status (Watchdog/POR)\n");
76 printf(" -d, --disable\t\tTurn off the watchdog timer\n"); 78 printf(" -d, --disable\t\tTurn off the watchdog timer\n");
77 printf(" -e, --enable\t\tTurn on the watchdog timer\n"); 79 printf(" -e, --enable\t\tTurn on the watchdog timer\n");
@@ -97,6 +99,7 @@ int main(int argc, char *argv[])
97 int c; 99 int c;
98 int oneshot = 0; 100 int oneshot = 0;
99 char *file = "/dev/watchdog"; 101 char *file = "/dev/watchdog";
102 struct watchdog_info info;
100 103
101 setbuf(stdout, NULL); 104 setbuf(stdout, NULL);
102 105
@@ -118,6 +121,16 @@ int main(int argc, char *argv[])
118 exit(-1); 121 exit(-1);
119 } 122 }
120 123
124 /*
125 * Validate that `file` is a watchdog device
126 */
127 ret = ioctl(fd, WDIOC_GETSUPPORT, &info);
128 if (ret) {
129 printf("WDIOC_GETSUPPORT error '%s'\n", strerror(errno));
130 close(fd);
131 exit(ret);
132 }
133
121 optind = 0; 134 optind = 0;
122 135
123 while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) { 136 while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
@@ -205,6 +218,18 @@ int main(int argc, char *argv[])
205 case 'f': 218 case 'f':
206 /* Handled above */ 219 /* Handled above */
207 break; 220 break;
221 case 'i':
222 /*
223 * watchdog_info was obtained as part of file open
224 * validation. So we just show it here.
225 */
226 oneshot = 1;
227 printf("watchdog_info:\n");
228 printf(" identity:\t\t%s\n", info.identity);
229 printf(" firmware_version:\t%u\n",
230 info.firmware_version);
231 printf(" options:\t\t%08x\n", info.options);
232 break;
208 233
209 default: 234 default:
210 usage(argv[0]); 235 usage(argv[0]);
diff --git a/arch/arm64/kernel/vdso/gettimeofday.S b/tools/virtio/crypto/hash.h
index e69de29bb2d1..e69de29bb2d1 100644
--- a/arch/arm64/kernel/vdso/gettimeofday.S
+++ b/tools/virtio/crypto/hash.h
diff --git a/tools/virtio/linux/dma-mapping.h b/tools/virtio/linux/dma-mapping.h
index f91aeb5fe571..8f41cd6bd5c0 100644
--- a/tools/virtio/linux/dma-mapping.h
+++ b/tools/virtio/linux/dma-mapping.h
@@ -29,4 +29,6 @@ enum dma_data_direction {
29#define dma_unmap_single(...) do { } while (0) 29#define dma_unmap_single(...) do { } while (0)
30#define dma_unmap_page(...) do { } while (0) 30#define dma_unmap_page(...) do { } while (0)
31 31
32#define dma_max_mapping_size(...) SIZE_MAX
33
32#endif 34#endif
diff --git a/tools/virtio/xen/xen.h b/tools/virtio/xen/xen.h
new file mode 100644
index 000000000000..f569387d1403
--- /dev/null
+++ b/tools/virtio/xen/xen.h
@@ -0,0 +1,6 @@
1#ifndef XEN_XEN_STUB_H
2#define XEN_XEN_STUB_H
3
4#define xen_domain() 0
5
6#endif
diff --git a/usr/include/Makefile b/usr/include/Makefile
index c9449aaf438d..57b20f7b6729 100644
--- a/usr/include/Makefile
+++ b/usr/include/Makefile
@@ -29,13 +29,11 @@ header-test- += linux/android/binderfs.h
29header-test-$(CONFIG_CPU_BIG_ENDIAN) += linux/byteorder/big_endian.h 29header-test-$(CONFIG_CPU_BIG_ENDIAN) += linux/byteorder/big_endian.h
30header-test-$(CONFIG_CPU_LITTLE_ENDIAN) += linux/byteorder/little_endian.h 30header-test-$(CONFIG_CPU_LITTLE_ENDIAN) += linux/byteorder/little_endian.h
31header-test- += linux/coda.h 31header-test- += linux/coda.h
32header-test- += linux/coda_psdev.h
33header-test- += linux/elfcore.h 32header-test- += linux/elfcore.h
34header-test- += linux/errqueue.h 33header-test- += linux/errqueue.h
35header-test- += linux/fsmap.h 34header-test- += linux/fsmap.h
36header-test- += linux/hdlc/ioctl.h 35header-test- += linux/hdlc/ioctl.h
37header-test- += linux/ivtv.h 36header-test- += linux/ivtv.h
38header-test- += linux/jffs2.h
39header-test- += linux/kexec.h 37header-test- += linux/kexec.h
40header-test- += linux/matroxfb.h 38header-test- += linux/matroxfb.h
41header-test- += linux/netfilter_ipv4/ipt_LOG.h 39header-test- += linux/netfilter_ipv4/ipt_LOG.h
@@ -55,20 +53,12 @@ header-test- += linux/v4l2-mediabus.h
55header-test- += linux/v4l2-subdev.h 53header-test- += linux/v4l2-subdev.h
56header-test- += linux/videodev2.h 54header-test- += linux/videodev2.h
57header-test- += linux/vm_sockets.h 55header-test- += linux/vm_sockets.h
58header-test- += scsi/scsi_bsg_fc.h
59header-test- += scsi/scsi_netlink.h
60header-test- += scsi/scsi_netlink_fc.h
61header-test- += sound/asequencer.h 56header-test- += sound/asequencer.h
62header-test- += sound/asoc.h 57header-test- += sound/asoc.h
63header-test- += sound/asound.h 58header-test- += sound/asound.h
64header-test- += sound/compress_offload.h 59header-test- += sound/compress_offload.h
65header-test- += sound/emu10k1.h 60header-test- += sound/emu10k1.h
66header-test- += sound/sfnt_info.h 61header-test- += sound/sfnt_info.h
67header-test- += sound/sof/eq.h
68header-test- += sound/sof/fw.h
69header-test- += sound/sof/header.h
70header-test- += sound/sof/manifest.h
71header-test- += sound/sof/trace.h
72header-test- += xen/evtchn.h 62header-test- += xen/evtchn.h
73header-test- += xen/gntdev.h 63header-test- += xen/gntdev.h
74header-test- += xen/privcmd.h 64header-test- += xen/privcmd.h
diff --git a/virt/kvm/arm/vgic/trace.h b/virt/kvm/arm/vgic/trace.h
index 55fed77a9f73..4fd4f6db181b 100644
--- a/virt/kvm/arm/vgic/trace.h
+++ b/virt/kvm/arm/vgic/trace.h
@@ -30,7 +30,7 @@ TRACE_EVENT(vgic_update_irq_pending,
30#endif /* _TRACE_VGIC_H */ 30#endif /* _TRACE_VGIC_H */
31 31
32#undef TRACE_INCLUDE_PATH 32#undef TRACE_INCLUDE_PATH
33#define TRACE_INCLUDE_PATH ../../../virt/kvm/arm/vgic 33#define TRACE_INCLUDE_PATH ../../virt/kvm/arm/vgic
34#undef TRACE_INCLUDE_FILE 34#undef TRACE_INCLUDE_FILE
35#define TRACE_INCLUDE_FILE trace 35#define TRACE_INCLUDE_FILE trace
36 36
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e6de3159e682..fd68fbe0a75d 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -617,8 +617,9 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
617 617
618 stat_data->kvm = kvm; 618 stat_data->kvm = kvm;
619 stat_data->offset = p->offset; 619 stat_data->offset = p->offset;
620 stat_data->mode = p->mode ? p->mode : 0644;
620 kvm->debugfs_stat_data[p - debugfs_entries] = stat_data; 621 kvm->debugfs_stat_data[p - debugfs_entries] = stat_data;
621 debugfs_create_file(p->name, 0644, kvm->debugfs_dentry, 622 debugfs_create_file(p->name, stat_data->mode, kvm->debugfs_dentry,
622 stat_data, stat_fops_per_vm[p->kind]); 623 stat_data, stat_fops_per_vm[p->kind]);
623 } 624 }
624 return 0; 625 return 0;
@@ -3929,7 +3930,9 @@ static int kvm_debugfs_open(struct inode *inode, struct file *file,
3929 if (!refcount_inc_not_zero(&stat_data->kvm->users_count)) 3930 if (!refcount_inc_not_zero(&stat_data->kvm->users_count))
3930 return -ENOENT; 3931 return -ENOENT;
3931 3932
3932 if (simple_attr_open(inode, file, get, set, fmt)) { 3933 if (simple_attr_open(inode, file, get,
3934 stat_data->mode & S_IWUGO ? set : NULL,
3935 fmt)) {
3933 kvm_put_kvm(stat_data->kvm); 3936 kvm_put_kvm(stat_data->kvm);
3934 return -ENOMEM; 3937 return -ENOMEM;
3935 } 3938 }
@@ -4177,7 +4180,8 @@ static void kvm_init_debug(void)
4177 4180
4178 kvm_debugfs_num_entries = 0; 4181 kvm_debugfs_num_entries = 0;
4179 for (p = debugfs_entries; p->name; ++p, kvm_debugfs_num_entries++) { 4182 for (p = debugfs_entries; p->name; ++p, kvm_debugfs_num_entries++) {
4180 debugfs_create_file(p->name, 0644, kvm_debugfs_dir, 4183 int mode = p->mode ? p->mode : 0644;
4184 debugfs_create_file(p->name, mode, kvm_debugfs_dir,
4181 (void *)(long)p->offset, 4185 (void *)(long)p->offset,
4182 stat_fops[p->kind]); 4186 stat_fops[p->kind]);
4183 } 4187 }