Merge tag 'media/v5.10-2' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab...
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 25 Nov 2020 18:35:44 +0000 (10:35 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 25 Nov 2020 18:35:44 +0000 (10:35 -0800)
Pull media fixes from Mauro Carvalho Chehab:

 - a rand Kconfig fixup for mtk-vcodec

 - a fix at h264 handling at cedrus codec driver

 - some warning fixes when config PM is not enabled at marvell-ccic

 - two fixes at venus codec driver: one related to codec profile and the
   other one related to a bad error path which causes an OOPS on module
   re-bind

* tag 'media/v5.10-2' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media:
  media: venus: pm_helpers: Fix kernel module reload
  media: venus: venc: Fix setting of profile and level
  media: cedrus: h264: Fix check for presence of scaling matrix
  media: media/platform/marvell-ccic: fix warnings when CONFIG_PM is not enabled
  media: mtk-vcodec: fix build breakage when one of VPU or SCP is enabled
  media: mtk-vcodec: move firmware implementations into their own files

1191 files changed:
.mailmap
CREDITS
Documentation/ABI/stable/sysfs-driver-dma-ioatdma
Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
Documentation/ABI/testing/sysfs-class-net
Documentation/Makefile
Documentation/admin-guide/LSM/SafeSetID.rst
Documentation/admin-guide/kernel-parameters.txt
Documentation/admin-guide/pm/cpuidle.rst
Documentation/admin-guide/sysctl/net.rst
Documentation/arm/sunxi.rst
Documentation/conf.py
Documentation/dev-tools/kasan.rst
Documentation/dev-tools/kunit/faq.rst
Documentation/dev-tools/kunit/start.rst
Documentation/dev-tools/kunit/style.rst
Documentation/dev-tools/kunit/usage.rst
Documentation/devicetree/bindings/clock/hi6220-clock.txt
Documentation/devicetree/bindings/clock/imx5-clock.yaml
Documentation/devicetree/bindings/interrupt-controller/ti,sci-inta.yaml
Documentation/devicetree/bindings/net/can/can-controller.yaml [new file with mode: 0644]
Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml [new file with mode: 0644]
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt [deleted file]
Documentation/devicetree/bindings/sound/rt1015.txt
Documentation/filesystems/api-summary.rst
Documentation/filesystems/ext4/journal.rst
Documentation/filesystems/ext4/super.rst
Documentation/filesystems/journalling.rst
Documentation/firmware-guide/acpi/acpi-lid.rst
Documentation/firmware-guide/acpi/gpio-properties.rst
Documentation/firmware-guide/acpi/method-tracing.rst
Documentation/gpu/amdgpu.rst
Documentation/hwmon/adm1266.rst
Documentation/hwmon/index.rst
Documentation/hwmon/mp2975.rst
Documentation/leds/index.rst
Documentation/locking/lockdep-design.rst
Documentation/misc-devices/index.rst
Documentation/networking/devlink/ice.rst
Documentation/networking/j1939.rst
Documentation/networking/netdev-FAQ.rst
Documentation/networking/phy.rst
Documentation/networking/statistics.rst
Documentation/process/stable-kernel-rules.rst
Documentation/sphinx/automarkup.py
Documentation/translations/it_IT/process/stable-kernel-rules.rst
Documentation/userspace-api/index.rst
Documentation/virt/kvm/api.rst
Documentation/xtensa/mmu.rst
MAINTAINERS
Makefile
arch/arc/include/asm/bitops.h
arch/arc/kernel/head.S
arch/arc/kernel/stacktrace.c
arch/arc/mm/tlb.c
arch/arc/plat-hsdk/platform.c
arch/arm/boot/compressed/head.S
arch/arm/boot/dts/exynos4412-odroid-common.dtsi
arch/arm/boot/dts/imx50-evk.dts
arch/arm/boot/dts/imx6q-prti6q.dts
arch/arm/boot/dts/imx6qdl-udoo.dtsi
arch/arm/boot/dts/stm32mp15xx-dhcom-pdk2.dtsi
arch/arm/boot/dts/stm32mp15xx-dhcom-som.dtsi
arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi
arch/arm/boot/dts/sun6i-a31-hummingbird.dts
arch/arm/boot/dts/sun7i-a20-bananapi-m1-plus.dts
arch/arm/boot/dts/sun7i-a20-cubietruck.dts
arch/arm/boot/dts/sun8i-a83t-bananapi-m3.dts
arch/arm/boot/dts/sun8i-a83t-cubietruck-plus.dts
arch/arm/boot/dts/sun8i-h3-orangepi-pc-plus.dts
arch/arm/boot/dts/sun8i-h3-orangepi-plus2e.dts
arch/arm/boot/dts/sun8i-r40-bananapi-m2-ultra.dts
arch/arm/boot/dts/sun9i-a80-cubieboard4.dts
arch/arm/boot/dts/sun9i-a80-optimus.dts
arch/arm/boot/dts/sunxi-bananapi-m2-plus.dtsi
arch/arm/boot/dts/vf610-zii-dev-rev-b.dts
arch/arm/include/asm/kprobes.h
arch/arm/kernel/perf_regs.c
arch/arm/mm/init.c
arch/arm/probes/kprobes/opt-arm.c
arch/arm64/Kconfig
arch/arm64/boot/dts/allwinner/sun50i-a64-bananapi-m64.dts
arch/arm64/boot/dts/allwinner/sun50i-a64-orangepi-win.dts
arch/arm64/boot/dts/allwinner/sun50i-a64-pine64-plus.dts
arch/arm64/boot/dts/allwinner/sun50i-a64-pinetab.dts
arch/arm64/boot/dts/allwinner/sun50i-h5-libretech-all-h5-cc.dts
arch/arm64/boot/dts/allwinner/sun50i-h5-orangepi-pc2.dts
arch/arm64/boot/dts/allwinner/sun50i-h5-orangepi-prime.dts
arch/arm64/boot/dts/allwinner/sun50i-h6-beelink-gs1.dts
arch/arm64/boot/dts/allwinner/sun50i-h6-pine-h64.dts
arch/arm64/boot/dts/altera/socfpga_stratix10_socdk.dts
arch/arm64/boot/dts/altera/socfpga_stratix10_socdk_nand.dts
arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28.dts
arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi
arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi
arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi
arch/arm64/boot/dts/freescale/imx8mm-beacon-som.dtsi
arch/arm64/boot/dts/freescale/imx8mm-evk.dtsi
arch/arm64/boot/dts/freescale/imx8mm-var-som.dtsi
arch/arm64/boot/dts/freescale/imx8mm.dtsi
arch/arm64/boot/dts/freescale/imx8mn-ddr4-evk.dts
arch/arm64/boot/dts/freescale/imx8mn-evk.dts
arch/arm64/boot/dts/freescale/imx8mn-var-som.dtsi
arch/arm64/boot/dts/freescale/imx8mn.dtsi
arch/arm64/boot/dts/freescale/qoriq-fman3-0.dtsi
arch/arm64/boot/dts/intel/socfpga_agilex_socdk.dts
arch/arm64/boot/dts/renesas/r8a774e1.dtsi
arch/arm64/include/asm/brk-imm.h
arch/arm64/include/asm/cpufeature.h
arch/arm64/include/asm/cputype.h
arch/arm64/include/asm/debug-monitors.h
arch/arm64/include/asm/kprobes.h
arch/arm64/include/asm/kvm_host.h
arch/arm64/include/asm/sysreg.h
arch/arm64/kernel/cpu_errata.c
arch/arm64/kernel/cpufeature.c
arch/arm64/kernel/kexec_image.c
arch/arm64/kernel/machine_kexec_file.c
arch/arm64/kernel/perf_regs.c
arch/arm64/kernel/probes/kprobes.c
arch/arm64/kernel/process.c
arch/arm64/kernel/proton-pack.c
arch/arm64/kernel/psci.c
arch/arm64/kernel/smp.c
arch/arm64/kvm/arm.c
arch/arm64/kvm/mmu.c
arch/arm64/kvm/sys_regs.c
arch/arm64/kvm/sys_regs.h
arch/arm64/mm/mmu.c
arch/csky/kernel/perf_regs.c
arch/ia64/include/asm/sparsemem.h
arch/mips/alchemy/common/clock.c
arch/mips/kernel/setup.c
arch/mips/mm/tlb-r4k.c
arch/powerpc/include/asm/book3s/64/kup-radix.h
arch/powerpc/include/asm/exception-64s.h
arch/powerpc/include/asm/feature-fixups.h
arch/powerpc/include/asm/kup.h
arch/powerpc/include/asm/mmzone.h
arch/powerpc/include/asm/nohash/32/kup-8xx.h
arch/powerpc/include/asm/nohash/32/mmu-8xx.h
arch/powerpc/include/asm/nohash/32/pte-8xx.h
arch/powerpc/include/asm/security_features.h
arch/powerpc/include/asm/setup.h
arch/powerpc/include/asm/sparsemem.h
arch/powerpc/include/asm/topology.h
arch/powerpc/include/asm/uaccess.h
arch/powerpc/kernel/eeh_cache.c
arch/powerpc/kernel/exceptions-64s.S
arch/powerpc/kernel/head_40x.S
arch/powerpc/kernel/head_8xx.S
arch/powerpc/kernel/head_book3s_32.S
arch/powerpc/kernel/setup_64.c
arch/powerpc/kernel/smp.c
arch/powerpc/kernel/syscall_64.c
arch/powerpc/kernel/vmlinux.lds.S
arch/powerpc/lib/feature-fixups.c
arch/powerpc/mm/mem.c
arch/powerpc/perf/imc-pmu.c
arch/powerpc/perf/perf_regs.c
arch/powerpc/platforms/powernv/setup.c
arch/powerpc/platforms/pseries/mobility.c
arch/powerpc/platforms/pseries/pseries.h
arch/powerpc/platforms/pseries/setup.c
arch/riscv/include/asm/uaccess.h
arch/riscv/kernel/ftrace.c
arch/riscv/kernel/head.S
arch/riscv/kernel/perf_regs.c
arch/riscv/kernel/vdso/.gitignore
arch/riscv/kernel/vdso/Makefile
arch/riscv/kernel/vdso/so2s.sh [new file with mode: 0755]
arch/riscv/mm/fault.c
arch/riscv/mm/init.c
arch/s390/configs/debug_defconfig
arch/s390/configs/defconfig
arch/s390/configs/zfcpdump_defconfig
arch/s390/include/asm/pgtable.h
arch/s390/include/asm/vdso/vdso.h [deleted file]
arch/s390/kernel/asm-offsets.c
arch/s390/kernel/entry.S
arch/s390/kernel/perf_cpum_sf.c
arch/s390/kernel/perf_regs.c
arch/s390/kernel/smp.c
arch/s390/pci/pci_event.c
arch/um/include/asm/pgalloc.h
arch/x86/boot/compressed/ident_map_64.c
arch/x86/boot/compressed/mem_encrypt.S
arch/x86/boot/compressed/misc.h
arch/x86/events/intel/core.c
arch/x86/events/intel/cstate.c
arch/x86/events/intel/ds.c
arch/x86/events/intel/uncore.c
arch/x86/events/intel/uncore.h
arch/x86/events/intel/uncore_snb.c
arch/x86/events/perf_event.h
arch/x86/events/rapl.c
arch/x86/hyperv/hv_apic.c
arch/x86/include/asm/kvm_host.h
arch/x86/include/asm/perf_event.h
arch/x86/include/asm/sparsemem.h
arch/x86/include/asm/uv/uv.h
arch/x86/kernel/apic/x2apic_uv_x.c
arch/x86/kernel/cpu/bugs.c
arch/x86/kernel/cpu/microcode/intel.c
arch/x86/kernel/dumpstack.c
arch/x86/kernel/head_64.S
arch/x86/kernel/perf_regs.c
arch/x86/kernel/sev-es-shared.c
arch/x86/kernel/sev-es.c
arch/x86/kernel/sev_verify_cbit.S [new file with mode: 0644]
arch/x86/kernel/tboot.c
arch/x86/kvm/cpuid.c
arch/x86/kvm/cpuid.h
arch/x86/kvm/emulate.c
arch/x86/kvm/mmu/mmu.c
arch/x86/kvm/mmu/tdp_mmu.c
arch/x86/kvm/svm/svm.c
arch/x86/kvm/x86.c
arch/x86/kvm/x86.h
arch/x86/lib/memcpy_64.S
arch/x86/lib/memmove_64.S
arch/x86/lib/memset_64.S
arch/x86/mm/mem_encrypt.c
arch/x86/mm/numa.c
arch/x86/platform/efi/efi_64.c
arch/x86/xen/spinlock.c
arch/xtensa/include/asm/pgtable.h
arch/xtensa/include/asm/uaccess.h
arch/xtensa/mm/cache.c
arch/xtensa/mm/init.c
block/blk-cgroup.c
block/blk-flush.c
block/genhd.c
drivers/accessibility/speakup/main.c
drivers/accessibility/speakup/selection.c
drivers/accessibility/speakup/speakup.h
drivers/accessibility/speakup/spk_ttyio.c
drivers/accessibility/speakup/spk_types.h
drivers/acpi/acpi_video.c
drivers/acpi/apei/apei-base.c
drivers/acpi/battery.c
drivers/acpi/button.c
drivers/acpi/dptf/dptf_pch_fivr.c
drivers/acpi/dptf/dptf_power.c
drivers/acpi/dptf/int340x_thermal.c
drivers/acpi/event.c
drivers/acpi/evged.c
drivers/acpi/fan.c
drivers/acpi/internal.h
drivers/acpi/nfit/core.c
drivers/acpi/pci_irq.c
drivers/acpi/pci_link.c
drivers/acpi/pci_mcfg.c
drivers/acpi/power.c
drivers/acpi/processor_perflib.c
drivers/acpi/sbs.c
drivers/acpi/sbshc.c
drivers/acpi/sbshc.h
drivers/acpi/scan.c
drivers/acpi/video_detect.c
drivers/acpi/wakeup.c
drivers/atm/nicstar.c
drivers/base/core.c
drivers/base/dd.c
drivers/base/power/runtime.c
drivers/block/loop.c
drivers/block/nbd.c
drivers/block/null_blk.h
drivers/block/null_blk_zoned.c
drivers/char/tpm/eventlog/efi.c
drivers/char/tpm/tpm_tis.c
drivers/char/virtio_console.c
drivers/clk/imx/clk-imx8mm.c
drivers/clk/imx/clk-imx8mn.c
drivers/clk/imx/clk-imx8mp.c
drivers/clk/imx/clk-imx8mq.c
drivers/clk/imx/clk.h
drivers/clk/meson/clk-regmap.h
drivers/clk/qcom/clk-regmap.h
drivers/counter/ti-eqep.c
drivers/cpufreq/cpufreq.c
drivers/cpufreq/cpufreq_governor.h
drivers/cpufreq/cpufreq_performance.c
drivers/cpufreq/cpufreq_powersave.c
drivers/cpufreq/intel_pstate.c
drivers/cpufreq/scmi-cpufreq.c
drivers/cpufreq/tegra186-cpufreq.c
drivers/cpuidle/cpuidle-tegra.c
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c
drivers/dax/Kconfig
drivers/dma/dmaengine.c
drivers/dma/idxd/device.c
drivers/dma/idxd/idxd.h
drivers/dma/idxd/init.c
drivers/dma/idxd/registers.h
drivers/dma/idxd/submit.c
drivers/dma/ioat/dca.c
drivers/dma/pl330.c
drivers/dma/ti/k3-udma-private.c
drivers/dma/ti/omap-dma.c
drivers/dma/xilinx/xilinx_dma.c
drivers/firmware/xilinx/zynqmp.c
drivers/gpio/gpio-aspeed.c
drivers/gpio/gpio-dwapb.c
drivers/gpio/gpio-omap.c
drivers/gpio/gpio-pcie-idio-24.c
drivers/gpio/gpio-sifive.c
drivers/gpio/gpiolib-cdev.h
drivers/gpio/gpiolib.c
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
drivers/gpu/drm/amd/amdgpu/cik.c
drivers/gpu/drm/amd/amdgpu/cik_sdma.c
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
drivers/gpu/drm/amd/amdgpu/nv.c
drivers/gpu/drm/amd/amdgpu/psp_v12_0.c
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
drivers/gpu/drm/amd/amdgpu/soc15.c
drivers/gpu/drm/amd/amdkfd/kfd_crat.c
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
drivers/gpu/drm/amd/display/dc/clk_mgr/clk_mgr.c
drivers/gpu/drm/amd/display/dc/core/dc_resource.c
drivers/gpu/drm/amd/display/dc/irq/dcn20/irq_service_dcn20.c
drivers/gpu/drm/amd/display/dc/irq/dcn30/irq_service_dcn30.c
drivers/gpu/drm/amd/display/include/dal_asic_id.h
drivers/gpu/drm/amd/include/amd_shared.h
drivers/gpu/drm/amd/pm/inc/hwmgr.h
drivers/gpu/drm/amd/pm/inc/smumgr.h
drivers/gpu/drm/amd/pm/powerplay/hwmgr/ci_baco.c
drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c
drivers/gpu/drm/amd/pm/powerplay/smumgr/ci_smumgr.c
drivers/gpu/drm/amd/pm/powerplay/smumgr/smumgr.c
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
drivers/gpu/drm/bridge/cadence/Kconfig
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
drivers/gpu/drm/drm_gem_vram_helper.c
drivers/gpu/drm/gma500/psb_irq.c
drivers/gpu/drm/i915/display/intel_display.c
drivers/gpu/drm/i915/display/intel_psr.c
drivers/gpu/drm/i915/gem/i915_gem_domain.c
drivers/gpu/drm/i915/gem/i915_gem_object_types.h
drivers/gpu/drm/i915/gem/i915_gem_phys.c
drivers/gpu/drm/i915/gt/intel_engine.h
drivers/gpu/drm/i915/gt/intel_engine_cs.c
drivers/gpu/drm/i915/gt/intel_lrc.c
drivers/gpu/drm/i915/gt/intel_mocs.c
drivers/gpu/drm/i915/gt/intel_rc6.c
drivers/gpu/drm/i915/gt/intel_timeline.c
drivers/gpu/drm/i915/gt/intel_timeline_types.h
drivers/gpu/drm/i915/gt/intel_workarounds.c
drivers/gpu/drm/i915/gvt/display.c
drivers/gpu/drm/i915/gvt/handlers.c
drivers/gpu/drm/i915/gvt/kvmgt.c
drivers/gpu/drm/i915/gvt/scheduler.c
drivers/gpu/drm/i915/gvt/vgpu.c
drivers/gpu/drm/i915/i915_gem.c
drivers/gpu/drm/i915/i915_reg.h
drivers/gpu/drm/i915/i915_vma.c
drivers/gpu/drm/i915/intel_pm.c
drivers/gpu/drm/i915/selftests/i915_request.c
drivers/gpu/drm/imx/dw_hdmi-imx.c
drivers/gpu/drm/imx/imx-drm-core.c
drivers/gpu/drm/imx/imx-ldb.c
drivers/gpu/drm/imx/imx-tve.c
drivers/gpu/drm/imx/parallel-display.c
drivers/gpu/drm/mcde/mcde_drv.c
drivers/gpu/drm/nouveau/dispnv50/disp.c
drivers/gpu/drm/nouveau/nouveau_bo.c
drivers/gpu/drm/nouveau/nouveau_connector.c
drivers/gpu/drm/panfrost/panfrost_drv.c
drivers/gpu/drm/panfrost/panfrost_gem.c
drivers/gpu/drm/panfrost/panfrost_gem.h
drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c
drivers/gpu/drm/sun4i/sun4i_backend.c
drivers/gpu/drm/sun4i/sun8i_dw_hdmi.c
drivers/gpu/drm/vc4/vc4_bo.c
drivers/gpu/drm/vc4/vc4_drv.c
drivers/gpu/drm/vc4/vc4_drv.h
drivers/gpu/drm/vc4/vc4_gem.c
drivers/gpu/drm/vc4/vc4_hvs.c
drivers/gpu/drm/vc4/vc4_kms.c
drivers/gpu/drm/vc4/vc4_v3d.c
drivers/gpu/ipu-v3/ipu-common.c
drivers/hid/hid-cypress.c
drivers/hid/hid-ids.h
drivers/hid/hid-input.c
drivers/hid/hid-ite.c
drivers/hid/hid-logitech-dj.c
drivers/hid/hid-logitech-hidpp.c
drivers/hid/hid-mcp2221.c
drivers/hid/hid-quirks.c
drivers/hid/hid-sensor-hub.c
drivers/hid/hid-uclogic-core.c
drivers/hid/hid-uclogic-params.c
drivers/hid/i2c-hid/i2c-hid-core.c
drivers/hv/hv.c
drivers/hv/hv_balloon.c
drivers/hwmon/amd_energy.c
drivers/hwmon/applesmc.c
drivers/hwmon/pmbus/max20730.c
drivers/hwmon/pmbus/pmbus_core.c
drivers/hwmon/pwm-fan.c
drivers/i2c/busses/Kconfig
drivers/i2c/busses/i2c-designware-slave.c
drivers/i2c/busses/i2c-mlxbf.c
drivers/i2c/busses/i2c-mt65xx.c
drivers/i2c/busses/i2c-sh_mobile.c
drivers/iio/accel/kxcjk-1013.c
drivers/iio/adc/ingenic-adc.c
drivers/iio/adc/mt6577_auxadc.c
drivers/iio/adc/stm32-adc-core.c
drivers/iio/adc/stm32-adc.c
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
drivers/iio/light/Kconfig
drivers/infiniband/Kconfig
drivers/infiniband/core/cm.c
drivers/infiniband/hw/hfi1/chip.c
drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c
drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.h
drivers/infiniband/sw/rdmavt/Kconfig
drivers/infiniband/sw/rdmavt/vt.c
drivers/infiniband/sw/rxe/Kconfig
drivers/infiniband/sw/rxe/rxe_verbs.c
drivers/infiniband/sw/siw/Kconfig
drivers/infiniband/sw/siw/siw_main.c
drivers/infiniband/ulp/srpt/ib_srpt.c
drivers/infiniband/ulp/srpt/ib_srpt.h
drivers/input/keyboard/sunkbd.c
drivers/input/misc/adxl34x.c
drivers/input/mouse/elan_i2c.h
drivers/input/mouse/elan_i2c_core.c
drivers/input/mouse/elan_i2c_i2c.c
drivers/input/mouse/elan_i2c_smbus.c
drivers/input/serio/i8042.c
drivers/input/touchscreen/Kconfig
drivers/iommu/amd/amd_iommu_types.h
drivers/iommu/intel/dmar.c
drivers/iommu/intel/iommu.c
drivers/iommu/intel/svm.c
drivers/iommu/iommu.c
drivers/irqchip/Kconfig
drivers/irqchip/irq-bcm2836.c
drivers/irqchip/irq-mst-intc.c
drivers/irqchip/irq-renesas-intc-irqpin.c
drivers/irqchip/irq-sifive-plic.c
drivers/irqchip/irq-stm32-exti.c
drivers/irqchip/irq-ti-sci-inta.c
drivers/misc/habanalabs/common/command_buffer.c
drivers/misc/habanalabs/common/habanalabs.h
drivers/misc/habanalabs/common/hw_queue.c
drivers/misc/habanalabs/common/irq.c
drivers/misc/habanalabs/gaudi/gaudi.c
drivers/misc/habanalabs/gaudi/gaudiP.h
drivers/misc/habanalabs/gaudi/gaudi_coresight.c
drivers/misc/habanalabs/goya/goya.c
drivers/misc/habanalabs/goya/goyaP.h
drivers/misc/habanalabs/include/gaudi/gaudi_masks.h
drivers/misc/mei/client.h
drivers/mmc/host/renesas_sdhi_core.c
drivers/mmc/host/sdhci-of-arasan.c
drivers/mmc/host/sdhci-of-esdhc.c
drivers/mmc/host/sdhci-pci-core.c
drivers/mmc/host/tmio_mmc_core.c
drivers/mtd/nand/raw/fsl_ifc_nand.c
drivers/mtd/nand/raw/mxc_nand.c
drivers/mtd/nand/raw/stm32_fmc2_nand.c
drivers/mtd/spi-nor/core.c
drivers/net/can/dev.c
drivers/net/can/flexcan.c
drivers/net/can/kvaser_pciefd.c
drivers/net/can/m_can/Kconfig
drivers/net/can/m_can/m_can.c
drivers/net/can/m_can/m_can.h
drivers/net/can/m_can/m_can_platform.c
drivers/net/can/m_can/tcan4x5x.c
drivers/net/can/peak_canfd/peak_canfd.c
drivers/net/can/rx-offload.c
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
drivers/net/can/spi/mcp251xfd/mcp251xfd-regmap.c
drivers/net/can/ti_hecc.c
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
drivers/net/can/usb/mcba_usb.c
drivers/net/can/usb/peak_usb/pcan_usb_core.c
drivers/net/can/usb/peak_usb/pcan_usb_fd.c
drivers/net/can/xilinx_can.c
drivers/net/dsa/lantiq_gswip.c
drivers/net/dsa/mv88e6xxx/chip.c
drivers/net/dsa/mv88e6xxx/devlink.c
drivers/net/dsa/mv88e6xxx/global1.c
drivers/net/dsa/mv88e6xxx/global1.h
drivers/net/dsa/mv88e6xxx/global1_vtu.c
drivers/net/dsa/qca8k.c
drivers/net/ethernet/atheros/atl1c/atl1c_main.c
drivers/net/ethernet/atheros/atl1e/atl1e_main.c
drivers/net/ethernet/broadcom/b44.c
drivers/net/ethernet/broadcom/bnxt/bnxt.c
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c
drivers/net/ethernet/cadence/macb_main.c
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h
drivers/net/ethernet/chelsio/cxgb4/sge.c
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.h
drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c
drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_hw.c
drivers/net/ethernet/faraday/ftgmac100.c
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
drivers/net/ethernet/freescale/enetc/Kconfig
drivers/net/ethernet/freescale/enetc/enetc.c
drivers/net/ethernet/freescale/enetc/enetc_hw.h
drivers/net/ethernet/freescale/enetc/enetc_mdio.c
drivers/net/ethernet/freescale/fec.h
drivers/net/ethernet/freescale/fec_main.c
drivers/net/ethernet/freescale/gianfar.c
drivers/net/ethernet/ibm/ibmvnic.c
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
drivers/net/ethernet/intel/i40e/i40e_xsk.c
drivers/net/ethernet/intel/igc/igc_main.c
drivers/net/ethernet/marvell/mvneta.c
drivers/net/ethernet/marvell/prestera/Kconfig
drivers/net/ethernet/marvell/prestera/prestera_pci.c
drivers/net/ethernet/mediatek/mtk_star_emac.c
drivers/net/ethernet/mellanox/mlx4/fw.c
drivers/net/ethernet/mellanox/mlx4/fw.h
drivers/net/ethernet/mellanox/mlx5/core/en/rep/bond.c
drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/tx.c
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_rxtx.c
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_rxtx.h
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_rx.c
drivers/net/ethernet/mellanox/mlx5/core/en_main.c
drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
drivers/net/ethernet/mellanox/mlx5/core/en_tc.h
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.c
drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.h
drivers/net/ethernet/mellanox/mlxsw/Kconfig
drivers/net/ethernet/mellanox/mlxsw/core.c
drivers/net/ethernet/microchip/lan743x_main.c
drivers/net/ethernet/microchip/lan743x_main.h
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
drivers/net/ethernet/qlogic/qed/qed_cxt.c
drivers/net/ethernet/qlogic/qed/qed_cxt.h
drivers/net/ethernet/qlogic/qed/qed_iwarp.c
drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c
drivers/net/ethernet/realtek/r8169_main.c
drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
drivers/net/ethernet/ti/am65-cpts.c
drivers/net/ethernet/ti/cpsw.c
drivers/net/ethernet/ti/cpsw_ethtool.c
drivers/net/ethernet/ti/cpsw_new.c
drivers/net/ethernet/ti/cpsw_priv.c
drivers/net/geneve.c
drivers/net/ipa/gsi_trans.c
drivers/net/netdevsim/dev.c
drivers/net/netdevsim/health.c
drivers/net/netdevsim/udp_tunnels.c
drivers/net/phy/mscc/mscc_macsec.c
drivers/net/phy/realtek.c
drivers/net/phy/sfp.c
drivers/net/phy/smsc.c
drivers/net/usb/cx82310_eth.c
drivers/net/usb/qmi_wwan.c
drivers/net/vrf.c
drivers/net/wan/cosa.c
drivers/nvme/host/core.c
drivers/nvme/host/nvme.h
drivers/nvme/host/pci.c
drivers/nvme/host/rdma.c
drivers/nvme/host/tcp.c
drivers/of/address.c
drivers/of/device.c
drivers/opp/core.c
drivers/opp/of.c
drivers/pci/controller/dwc/pcie-designware-host.c
drivers/pci/controller/pci-mvebu.c
drivers/pci/pci.c
drivers/pinctrl/aspeed/pinctrl-aspeed.c
drivers/pinctrl/intel/pinctrl-intel.c
drivers/pinctrl/pinctrl-amd.c
drivers/pinctrl/pinctrl-ingenic.c
drivers/pinctrl/pinctrl-mcp23s08_spi.c
drivers/pinctrl/pinctrl-rockchip.c
drivers/pinctrl/qcom/pinctrl-msm.c
drivers/pinctrl/qcom/pinctrl-sm8250.c
drivers/powercap/intel_rapl_common.c
drivers/powercap/powercap_sys.c
drivers/regulator/core.c
drivers/regulator/pfuze100-regulator.c
drivers/regulator/ti-abb-regulator.c
drivers/s390/block/dasd.c
drivers/s390/crypto/ap_bus.c
drivers/s390/crypto/pkey_api.c
drivers/s390/crypto/zcrypt_card.c
drivers/s390/crypto/zcrypt_queue.c
drivers/scsi/device_handler/scsi_dh_alua.c
drivers/scsi/hpsa.c
drivers/scsi/libiscsi.c
drivers/scsi/mpt3sas/mpt3sas_base.c
drivers/scsi/ufs/ufshcd.c
drivers/scsi/ufs/ufshcd.h
drivers/spi/spi-bcm-qspi.c
drivers/spi/spi-bcm2835.c
drivers/spi/spi-bcm2835aux.c
drivers/spi/spi-cadence-quadspi.c
drivers/spi/spi-dw-core.c
drivers/spi/spi-fsi.c
drivers/spi/spi-fsl-dspi.c
drivers/spi/spi-fsl-lpspi.c
drivers/spi/spi-imx.c
drivers/spi/spi-npcm-fiu.c
drivers/spi/spi.c
drivers/staging/mt7621-pci/pci-mt7621.c
drivers/staging/ralink-gdma/Kconfig
drivers/staging/rtl8723bs/os_dep/sdio_intf.c
drivers/staging/wfx/Documentation/devicetree/bindings/net/wireless/silabs,wfx.yaml
drivers/target/iscsi/iscsi_target.c
drivers/tee/amdtee/amdtee_private.h
drivers/tee/amdtee/core.c
drivers/thermal/ti-soc-thermal/ti-bandgap.c
drivers/thunderbolt/debugfs.c
drivers/thunderbolt/icm.c
drivers/thunderbolt/nhi.c
drivers/thunderbolt/nhi.h
drivers/thunderbolt/tb.h
drivers/thunderbolt/usb4.c
drivers/thunderbolt/xdomain.c
drivers/tty/serial/8250/8250_mtk.c
drivers/tty/serial/Kconfig
drivers/tty/serial/ar933x_uart.c
drivers/tty/serial/imx.c
drivers/tty/serial/serial_txx9.c
drivers/tty/tty_io.c
drivers/tty/vt/vt.c
drivers/tty/vt/vt_ioctl.c
drivers/uio/uio.c
drivers/usb/class/cdc-acm.c
drivers/usb/core/quirks.c
drivers/usb/dwc2/platform.c
drivers/usb/dwc3/dwc3-pci.c
drivers/usb/dwc3/ep0.c
drivers/usb/gadget/legacy/raw_gadget.c
drivers/usb/gadget/udc/fsl_udc_core.c
drivers/usb/gadget/udc/goku_udc.c
drivers/usb/host/xhci-histb.c
drivers/usb/misc/apple-mfi-fastcharge.c
drivers/usb/mtu3/mtu3_gadget.c
drivers/usb/musb/musb_dsps.c
drivers/usb/serial/cyberjack.c
drivers/usb/serial/option.c
drivers/usb/typec/ucsi/psy.c
drivers/usb/typec/ucsi/ucsi.c
drivers/usb/typec/ucsi/ucsi.h
drivers/vdpa/Kconfig
drivers/vfio/fsl-mc/vfio_fsl_mc.c
drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c
drivers/vfio/pci/vfio_pci.c
drivers/vfio/pci/vfio_pci_rdwr.c
drivers/vfio/platform/vfio_platform_common.c
drivers/vfio/vfio_iommu_type1.c
drivers/vhost/scsi.c
drivers/vhost/vhost.c
drivers/vhost/vhost.h
drivers/video/fbdev/hyperv_fb.c
drivers/virt/nitro_enclaves/ne_misc_dev.c
drivers/xen/swiotlb-xen.c
fs/afs/dir.c
fs/afs/inode.c
fs/afs/internal.h
fs/afs/write.c
fs/afs/xattr.c
fs/afs/yfsclient.c
fs/aio.c
fs/btrfs/block-rsv.c
fs/btrfs/dev-replace.c
fs/btrfs/ioctl.c
fs/btrfs/qgroup.c
fs/btrfs/ref-verify.c
fs/btrfs/relocation.c
fs/btrfs/scrub.c
fs/btrfs/volumes.c
fs/ceph/caps.c
fs/ceph/mds_client.c
fs/ceph/mds_client.h
fs/ceph/quota.c
fs/ceph/snap.c
fs/cifs/cifsacl.c
fs/cifs/smb2ops.c
fs/crypto/inline_crypt.c
fs/crypto/keysetup.c
fs/efivarfs/super.c
fs/erofs/inode.c
fs/erofs/zdata.c
fs/ext4/ext4.h
fs/ext4/extents.c
fs/ext4/fast_commit.c
fs/ext4/fast_commit.h
fs/ext4/file.c
fs/ext4/fsmap.c
fs/ext4/fsync.c
fs/ext4/inline.c
fs/ext4/inode.c
fs/ext4/mballoc.c
fs/ext4/namei.c
fs/ext4/super.c
fs/gfs2/aops.c
fs/gfs2/bmap.c
fs/gfs2/glock.c
fs/gfs2/glops.c
fs/gfs2/glops.h
fs/gfs2/inode.c
fs/gfs2/log.c
fs/gfs2/lops.c
fs/gfs2/lops.h
fs/gfs2/ops_fstype.c
fs/gfs2/recovery.c
fs/gfs2/rgrp.c
fs/gfs2/super.c
fs/io-wq.c
fs/io_uring.c
fs/iomap/buffered-io.c
fs/jbd2/checkpoint.c
fs/jbd2/commit.c
fs/jbd2/journal.c
fs/jbd2/recovery.c
fs/jbd2/transaction.c
fs/libfs.c
fs/nfs/dir.c
fs/nfs/nfs42xattr.c
fs/nfs/nfs42xdr.c
fs/nfs/nfsroot.c
fs/nfsd/nfs3proc.c
fs/nfsd/nfs3xdr.c
fs/nfsd/nfs4proc.c
fs/notify/fsnotify.c
fs/ocfs2/journal.c
fs/ocfs2/super.c
fs/proc/base.c
fs/proc/cpuinfo.c
fs/proc/generic.c
fs/proc/inode.c
fs/proc/self.c
fs/proc/stat.c
fs/seq_file.c
fs/super.c
fs/xfs/libxfs/xfs_alloc.c
fs/xfs/libxfs/xfs_attr_leaf.c
fs/xfs/libxfs/xfs_bmap.h
fs/xfs/libxfs/xfs_rmap.c
fs/xfs/scrub/bmap.c
fs/xfs/scrub/btree.c
fs/xfs/scrub/dir.c
fs/xfs/scrub/inode.c
fs/xfs/scrub/refcount.c
fs/xfs/xfs_aops.c
fs/xfs/xfs_iomap.c
fs/xfs/xfs_iops.c
fs/xfs/xfs_iwalk.c
fs/xfs/xfs_mount.c
fs/xfs/xfs_pnfs.c
fs/xfs/xfs_reflink.c
include/asm-generic/barrier.h
include/asm-generic/percpu.h
include/kunit/test.h
include/linux/blk-mq.h
include/linux/can/skb.h
include/linux/compiler-clang.h
include/linux/compiler-gcc.h
include/linux/compiler.h
include/linux/compiler_types.h
include/linux/cpufreq.h
include/linux/filter.h
include/linux/fs.h
include/linux/genhd.h
include/linux/intel-iommu.h
include/linux/io_uring.h
include/linux/iomap.h
include/linux/jbd2.h
include/linux/memcontrol.h
include/linux/memory_hotplug.h
include/linux/mm.h
include/linux/netfilter/nfnetlink.h
include/linux/netfilter_ipv4.h
include/linux/netfilter_ipv6.h
include/linux/numa.h
include/linux/pagemap.h
include/linux/perf_event.h
include/linux/perf_regs.h
include/linux/pgtable.h
include/linux/phy.h
include/linux/pm_runtime.h
include/linux/refcount.h
include/linux/sched.h
include/linux/seq_file.h
include/linux/spi/spi.h
include/linux/swiotlb.h
include/net/cfg80211.h
include/net/ip_tunnels.h
include/net/ipv6_frag.h
include/net/mac80211.h
include/net/neighbour.h
include/net/tls.h
include/net/xsk_buff_pool.h
include/scsi/libiscsi.h
include/sound/control.h
include/sound/core.h
include/sound/pcm.h
include/sound/rt1015.h [new file with mode: 0644]
include/trace/events/ext4.h
include/trace/events/sunrpc.h
include/uapi/linux/gpio.h
include/uapi/linux/icmpv6.h
include/uapi/sound/compress_offload.h
include/video/imx-ipu-v3.h
init/main.c
kernel/bpf/Makefile
kernel/bpf/bpf_lsm.c
kernel/bpf/core.c
kernel/bpf/hashtab.c
kernel/bpf/preload/Kconfig
kernel/bpf/verifier.c
kernel/dma/swiotlb.c
kernel/entry/common.c
kernel/events/core.c
kernel/events/internal.h
kernel/events/ring_buffer.c
kernel/exit.c
kernel/fail_function.c
kernel/fork.c
kernel/futex.c
kernel/hung_task.c
kernel/irq/Kconfig
kernel/kprobes.c
kernel/kthread.c
kernel/locking/lockdep.c
kernel/panic.c
kernel/ptrace.c
kernel/rcu/tree.c
kernel/rcu/tree_stall.h
kernel/reboot.c
kernel/sched/core.c
kernel/sched/cpufreq_schedutil.c
kernel/sched/deadline.c
kernel/sched/debug.c
kernel/sched/fair.c
kernel/seccomp.c
kernel/signal.c
kernel/trace/bpf_trace.c
kernel/trace/ring_buffer.c
kernel/trace/trace.c
kernel/trace/trace.h
kernel/trace/trace_events_synth.c
kernel/trace/trace_selftest.c
kernel/watchdog.c
lib/crc32test.c
lib/fonts/font_10x18.c
lib/fonts/font_6x10.c
lib/fonts/font_6x11.c
lib/fonts/font_6x8.c
lib/fonts/font_7x14.c
lib/fonts/font_8x16.c
lib/fonts/font_8x8.c
lib/fonts/font_acorn_8x8.c
lib/fonts/font_mini_4x6.c
lib/fonts/font_pearl_8x8.c
lib/fonts/font_sun12x22.c
lib/fonts/font_sun8x16.c
lib/fonts/font_ter16x32.c
lib/strncpy_from_user.c
lib/test_kasan.c
mm/compaction.c
mm/filemap.c
mm/gup.c
mm/huge_memory.c
mm/hugetlb.c
mm/madvise.c
mm/memcontrol.c
mm/memory-failure.c
mm/memory_hotplug.c
mm/mempolicy.c
mm/memremap.c
mm/migrate.c
mm/page-writeback.c
mm/page_alloc.c
mm/percpu.c
mm/rmap.c
mm/slub.c
mm/truncate.c
mm/vmscan.c
net/atm/lec.c
net/bridge/br_device.c
net/can/Kconfig
net/can/af_can.c
net/can/isotp.c
net/can/j1939/socket.c
net/can/proc.c
net/core/devlink.c
net/core/neighbour.c
net/core/netpoll.c
net/core/skmsg.c
net/ethtool/features.c
net/ipv4/arp.c
net/ipv4/fib_frontend.c
net/ipv4/inet_diag.c
net/ipv4/ip_tunnel.c
net/ipv4/ip_tunnel_core.c
net/ipv4/netfilter.c
net/ipv4/netfilter/iptable_mangle.c
net/ipv4/netfilter/nf_reject_ipv4.c
net/ipv4/syncookies.c
net/ipv4/tcp_bbr.c
net/ipv4/tcp_bpf.c
net/ipv4/udp_offload.c
net/ipv4/xfrm4_tunnel.c
net/ipv6/addrconf.c
net/ipv6/ah6.c
net/ipv6/icmp.c
net/ipv6/ip6_tunnel.c
net/ipv6/ndisc.c
net/ipv6/netfilter.c
net/ipv6/netfilter/ip6table_mangle.c
net/ipv6/netfilter/nf_conntrack_reasm.c
net/ipv6/reassembly.c
net/ipv6/sit.c
net/ipv6/syncookies.c
net/ipv6/udp_offload.c
net/ipv6/xfrm6_tunnel.c
net/iucv/af_iucv.c
net/mac80211/mlme.c
net/mac80211/rc80211_minstrel.c
net/mac80211/rc80211_minstrel.h
net/mac80211/sta_info.c
net/mac80211/sta_info.h
net/mac80211/status.c
net/mac80211/tx.c
net/mptcp/protocol.c
net/mptcp/token.c
net/ncsi/ncsi-manage.c
net/ncsi/ncsi-netlink.c
net/ncsi/ncsi-netlink.h
net/netfilter/ipset/ip_set_core.c
net/netfilter/ipvs/ip_vs_core.c
net/netfilter/nf_nat_proto.c
net/netfilter/nf_synproxy_core.c
net/netfilter/nf_tables_api.c
net/netfilter/nfnetlink.c
net/netfilter/nft_chain_route.c
net/netfilter/utils.c
net/netlabel/netlabel_unlabeled.c
net/openvswitch/datapath.c
net/openvswitch/flow_table.c
net/rfkill/core.c
net/sctp/input.c
net/sctp/sm_sideeffect.c
net/sctp/transport.c
net/smc/af_smc.c
net/smc/smc_core.c
net/smc/smc_ib.c
net/sunrpc/sysctl.c
net/tipc/topsrv.c
net/tls/tls_device.c
net/tls/tls_sw.c
net/vmw_vsock/af_vsock.c
net/wireless/core.c
net/wireless/core.h
net/wireless/nl80211.c
net/wireless/reg.c
net/x25/af_x25.c
net/xdp/xsk.c
net/xdp/xsk_buff_pool.c
net/xfrm/xfrm_interface.c
net/xfrm/xfrm_state.c
samples/bpf/task_fd_query_user.c
samples/bpf/tracex2_user.c
samples/bpf/tracex3_user.c
samples/bpf/xdp_redirect_cpu_user.c
samples/bpf/xdp_rxq_info_user.c
scripts/bpf_helpers_doc.py
scripts/get_abi.pl
scripts/kernel-doc
security/selinux/ibpkey.c
sound/core/control.c
sound/core/pcm_dmaengine.c
sound/core/pcm_lib.c
sound/core/pcm_native.c
sound/firewire/fireworks/fireworks_transaction.c
sound/hda/ext/hdac_ext_controller.c
sound/pci/hda/hda_codec.c
sound/pci/hda/hda_controller.h
sound/pci/hda/hda_intel.c
sound/pci/hda/patch_ca0132.c
sound/pci/hda/patch_hdmi.c
sound/pci/hda/patch_realtek.c
sound/pci/mixart/mixart_core.c
sound/soc/atmel/mchp-spdiftx.c
sound/soc/codecs/cs42l51.c
sound/soc/codecs/rt1015.c
sound/soc/codecs/rt1015.h
sound/soc/codecs/wcd9335.c
sound/soc/codecs/wcd934x.c
sound/soc/codecs/wsa881x.c
sound/soc/intel/Kconfig
sound/soc/intel/atom/Makefile
sound/soc/intel/atom/sst/Makefile
sound/soc/intel/boards/kbl_rt5663_max98927.c
sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c
sound/soc/intel/catpt/dsp.c
sound/soc/intel/catpt/pcm.c
sound/soc/intel/keembay/kmb_platform.c
sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
sound/soc/qcom/lpass-cpu.c
sound/soc/qcom/lpass-platform.c
sound/soc/qcom/lpass-sc7180.c
sound/soc/qcom/sdm845.c
sound/soc/soc-core.c
sound/soc/soc-dapm.c
sound/soc/sof/loader.c
sound/usb/card.c
sound/usb/mixer_maps.c
sound/usb/pcm.c
sound/usb/quirks.c
tools/arch/arm64/include/uapi/asm/kvm.h
tools/arch/s390/include/uapi/asm/sie.h
tools/arch/x86/include/asm/cpufeatures.h
tools/arch/x86/include/asm/disabled-features.h
tools/arch/x86/include/asm/msr-index.h
tools/arch/x86/include/asm/required-features.h
tools/arch/x86/include/uapi/asm/kvm.h
tools/arch/x86/include/uapi/asm/svm.h
tools/arch/x86/lib/memcpy_64.S
tools/arch/x86/lib/memset_64.S
tools/bpf/bpftool/feature.c
tools/bpf/bpftool/net.c
tools/bpf/bpftool/prog.c
tools/bpf/bpftool/skeleton/profiler.bpf.c
tools/build/feature/test-all.c
tools/include/linux/compiler-gcc.h
tools/include/linux/compiler.h
tools/include/uapi/asm-generic/unistd.h
tools/include/uapi/drm/i915_drm.h
tools/include/uapi/linux/fscrypt.h
tools/include/uapi/linux/kvm.h
tools/include/uapi/linux/mman.h
tools/include/uapi/linux/mount.h
tools/include/uapi/linux/perf_event.h
tools/include/uapi/linux/prctl.h
tools/include/uapi/linux/vhost.h
tools/lib/bpf/Makefile
tools/lib/bpf/hashmap.h
tools/lib/bpf/libbpf.c
tools/lib/bpf/xsk.c
tools/perf/Makefile.config
tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
tools/perf/arch/x86/tests/dwarf-unwind.c
tools/perf/bench/mem-memcpy-x86-64-asm.S
tools/perf/bench/mem-memset-x86-64-asm.S
tools/perf/builtin-inject.c
tools/perf/builtin-lock.c
tools/perf/builtin-trace.c
tools/perf/pmu-events/arch/x86/cascadelakex/clx-metrics.json
tools/perf/pmu-events/arch/x86/skylakex/skx-metrics.json
tools/perf/tests/dwarf-unwind.c
tools/perf/tests/shell/test_arm_coresight.sh
tools/perf/ui/browsers/hists.c
tools/perf/util/build-id.c
tools/perf/util/hashmap.c
tools/perf/util/hashmap.h
tools/perf/util/include/linux/linkage.h
tools/perf/util/machine.c
tools/perf/util/scripting-engines/trace-event-python.c
tools/perf/util/session.c
tools/perf/util/symbol.c
tools/perf/util/symbol.h
tools/power/x86/turbostat/Makefile
tools/power/x86/turbostat/turbostat.8
tools/power/x86/turbostat/turbostat.c
tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
tools/testing/kunit/.gitattributes [deleted file]
tools/testing/kunit/kunit.py
tools/testing/kunit/kunit_kernel.py
tools/testing/kunit/kunit_parser.py
tools/testing/kunit/kunit_tool_test.py
tools/testing/kunit/test_data/test_config_printk_time.log
tools/testing/kunit/test_data/test_interrupted_tap_output.log
tools/testing/kunit/test_data/test_kernel_panic_interrupt.log
tools/testing/kunit/test_data/test_multiple_prefixes.log
tools/testing/kunit/test_data/test_pound_no_prefix.log
tools/testing/kunit/test_data/test_pound_sign.log
tools/testing/scatterlist/linux/mm.h
tools/testing/scatterlist/main.c
tools/testing/selftests/bpf/prog_tests/map_init.c [new file with mode: 0644]
tools/testing/selftests/bpf/prog_tests/probe_read_user_str.c [new file with mode: 0644]
tools/testing/selftests/bpf/prog_tests/sockopt_multi.c
tools/testing/selftests/bpf/prog_tests/subprogs.c
tools/testing/selftests/bpf/prog_tests/test_global_funcs.c
tools/testing/selftests/bpf/progs/profiler.inc.h
tools/testing/selftests/bpf/progs/test_global_func8.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/test_map_init.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/test_probe_read_user_str.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/test_subprogs_unused.c [new file with mode: 0644]
tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c
tools/testing/selftests/core/close_range_test.c
tools/testing/selftests/filesystems/binderfs/binderfs_test.c
tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c
tools/testing/selftests/ftrace/test.d/dynevent/add_remove_kprobe.tc
tools/testing/selftests/ftrace/test.d/dynevent/clear_select_events.tc
tools/testing/selftests/ftrace/test.d/dynevent/generic_clear_event.tc
tools/testing/selftests/ftrace/test.d/ftrace/func-filter-notrace-pid.tc
tools/testing/selftests/ftrace/test.d/ftrace/func-filter-pid.tc
tools/testing/selftests/ftrace/test.d/ftrace/func-filter-stacktrace.tc
tools/testing/selftests/ftrace/test.d/functions
tools/testing/selftests/ftrace/test.d/kprobe/add_and_remove.tc
tools/testing/selftests/ftrace/test.d/kprobe/busy_check.tc
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args.tc
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_comm.tc
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_symbol.tc
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_ftrace.tc
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_multiprobe.tc
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc
tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_args.tc
tools/testing/selftests/ftrace/test.d/kprobe/profile.tc
tools/testing/selftests/kselftest_harness.h
tools/testing/selftests/kvm/.gitignore
tools/testing/selftests/kvm/Makefile
tools/testing/selftests/kvm/aarch64/get-reg-list-sve.c [new file with mode: 0644]
tools/testing/selftests/kvm/aarch64/get-reg-list.c [new file with mode: 0644]
tools/testing/selftests/kvm/clear_dirty_log_test.c [deleted file]
tools/testing/selftests/kvm/demand_paging_test.c
tools/testing/selftests/kvm/dirty_log_perf_test.c [new file with mode: 0644]
tools/testing/selftests/kvm/dirty_log_test.c
tools/testing/selftests/kvm/include/kvm_util.h
tools/testing/selftests/kvm/include/perf_test_util.h [new file with mode: 0644]
tools/testing/selftests/kvm/include/test_util.h
tools/testing/selftests/kvm/include/x86_64/processor.h
tools/testing/selftests/kvm/lib/aarch64/processor.c
tools/testing/selftests/kvm/lib/aarch64/ucall.c
tools/testing/selftests/kvm/lib/kvm_util.c
tools/testing/selftests/kvm/lib/kvm_util_internal.h
tools/testing/selftests/kvm/lib/s390x/processor.c
tools/testing/selftests/kvm/lib/s390x/ucall.c
tools/testing/selftests/kvm/lib/test_util.c
tools/testing/selftests/kvm/lib/x86_64/handlers.S [new file with mode: 0644]
tools/testing/selftests/kvm/lib/x86_64/processor.c
tools/testing/selftests/kvm/lib/x86_64/ucall.c
tools/testing/selftests/kvm/x86_64/kvm_pv_test.c [new file with mode: 0644]
tools/testing/selftests/lib.mk
tools/testing/selftests/pidfd/config
tools/testing/selftests/pidfd/pidfd_getfd_test.c
tools/testing/selftests/pidfd/pidfd_open_test.c
tools/testing/selftests/pidfd/pidfd_poll_test.c
tools/testing/selftests/pidfd/pidfd_setns_test.c
tools/testing/selftests/pidfd/pidfd_test.c
tools/testing/selftests/powerpc/include/utils.h
tools/testing/selftests/powerpc/security/.gitignore
tools/testing/selftests/powerpc/security/Makefile
tools/testing/selftests/powerpc/security/entry_flush.c [new file with mode: 0644]
tools/testing/selftests/powerpc/security/flush_utils.c [new file with mode: 0644]
tools/testing/selftests/powerpc/security/flush_utils.h [new file with mode: 0644]
tools/testing/selftests/powerpc/security/rfi_flush.c
tools/testing/selftests/proc/proc-loadavg-001.c
tools/testing/selftests/proc/proc-self-syscall.c
tools/testing/selftests/proc/proc-uptime-002.c
tools/testing/selftests/seccomp/seccomp_bpf.c
tools/testing/selftests/tc-testing/tc-tests/filters/tests.json
tools/testing/selftests/wireguard/netns.sh
tools/testing/selftests/wireguard/qemu/kernel.config

index 1e14566..505b3d7 100644 (file)
--- a/.mailmap
+++ b/.mailmap
@@ -82,7 +82,10 @@ Dengcheng Zhu <dzhu@wavecomp.com> <dengcheng.zhu@gmail.com>
 Dengcheng Zhu <dzhu@wavecomp.com> <dengcheng.zhu@imgtec.com>
 Dengcheng Zhu <dzhu@wavecomp.com> <dengcheng.zhu@mips.com>
 <dev.kurt@vandijck-laurijssen.be> <kurt.van.dijck@eia.be>
-Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
+Dmitry Baryshkov <dbaryshkov@gmail.com>
+Dmitry Baryshkov <dbaryshkov@gmail.com> <[dbaryshkov@gmail.com]>
+Dmitry Baryshkov <dbaryshkov@gmail.com> <dmitry_baryshkov@mentor.com>
+Dmitry Baryshkov <dbaryshkov@gmail.com> <dmitry_eremin@mentor.com>
 Dmitry Safonov <0x7f454c46@gmail.com> <dima@arista.com>
 Dmitry Safonov <0x7f454c46@gmail.com> <d.safonov@partner.samsung.com>
 Dmitry Safonov <0x7f454c46@gmail.com> <dsafonov@virtuozzo.com>
diff --git a/CREDITS b/CREDITS
index 8592e45..7483019 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -98,7 +98,7 @@ N: Erik Andersen
 E: andersen@codepoet.org
 W: https://www.codepoet.org/
 P: 1024D/30D39057 1BC4 2742 E885 E4DE 9301  0C82 5F9B 643E 30D3 9057
-D: Maintainer of ide-cd and Uniform CD-ROM driver, 
+D: Maintainer of ide-cd and Uniform CD-ROM driver,
 D: ATAPI CD-Changer support, Major 2.1.x CD-ROM update.
 S: 352 North 525 East
 S: Springville, Utah 84663
@@ -263,7 +263,7 @@ N: Paul Barton-Davis
 E: pbd@op.net
 D: Driver for WaveFront soundcards (Turtle Beach Maui, Tropez, Tropez+)
 D: Various bugfixes and changes to sound drivers
-S: USA 
+S: USA
 
 N: Carlos Henrique Bauer
 E: chbauer@acm.org
@@ -849,6 +849,12 @@ D: trivial hack to add variable address length routing to Rose.
 D: AX25-HOWTO, HAM-HOWTO, IPX-HOWTO, NET-2-HOWTO
 D: ax25-utils maintainer.
 
+N: Kamil Debski
+E: kamil@wypas.org
+D: Samsung S5P 2D graphics acceleration and Multi Format Codec drivers
+D: Samsung USB2 phy drivers
+D: PWM fan driver
+
 N: Helge Deller
 E: deller@gmx.de
 W: http://www.parisc-linux.org/
@@ -1199,7 +1205,7 @@ N: Daniel J. Frasnelli
 E: dfrasnel@alphalinux.org
 W: http://www.alphalinux.org/
 P: 1024/3EF87611 B9 F1 44 50 D3 E8 C2 80  DA E5 55 AA 56 7C 42 DA
-D: DEC Alpha hacker 
+D: DEC Alpha hacker
 D: Miscellaneous bug squisher
 
 N: Jim Freeman
@@ -1299,7 +1305,7 @@ S: P.O. Box 76, Epping
 S: New South Wales, 2121
 S: Australia
 
-N: Carlos E. Gorges 
+N: Carlos E. Gorges
 E: carlos@techlinux.com.br
 D: fix smp support on cmpci driver
 P: 2048G/EA3C4B19 FF31 33A6 0362 4915 B7EB  E541 17D0 0379 EA3C 4B19
@@ -1340,7 +1346,7 @@ E: wgreathouse@smva.com
 E: wgreathouse@myfavoritei.com
 D: Current Belkin USB Serial Adapter F5U103 hacker
 D: Kernel hacker, embedded systems
-S: 7802 Fitzwater Road   
+S: 7802 Fitzwater Road
 S: Brecksville, OH  44141-1334
 S: USA
 
@@ -1381,7 +1387,7 @@ N: Grant Guenther
 E: grant@torque.net
 W: http://www.torque.net/linux-pp.html
 D: original author of ppa driver for parallel port ZIP drive
-D: original architect of the parallel-port sharing scheme 
+D: original architect of the parallel-port sharing scheme
 D: PARIDE subsystem: drivers for parallel port IDE & ATAPI devices
 S: 44 St. Joseph Street, Suite 506
 S: Toronto, Ontario, M4Y 2W4
@@ -1523,7 +1529,7 @@ N: Benjamin Herrenschmidt
 E: benh@kernel.crashing.org
 D: Various parts of PPC/PPC64 & PowerMac
 S: 312/107 Canberra Avenue
-S: Griffith, ACT 2603 
+S: Griffith, ACT 2603
 S: Australia
 
 N: Andreas Herrmann
@@ -1825,7 +1831,7 @@ S: Hungary
 N: Bernhard Kaindl
 E: bkaindl@netway.at
 E: edv@bartelt.via.at
-D: Author of a menu based configuration tool, kmenu, which 
+D: Author of a menu based configuration tool, kmenu, which
 D: is the predecessor of 'make menuconfig' and 'make xconfig'.
 D: digiboard driver update(modularisation work and 2.1.x upd)
 S: Tallak 95
@@ -2016,7 +2022,7 @@ W: http://www.xos.nl/
 D: IP transparent proxy support
 S: X/OS Experts in Open Systems BV
 S: Kruislaan 419
-S: 1098 VA Amsterdam 
+S: 1098 VA Amsterdam
 S: The Netherlands
 
 N: Goran Koruga
@@ -2088,7 +2094,7 @@ S: Germany
 
 N: Andrzej M. Krzysztofowicz
 E: ankry@mif.pg.gda.pl
-D: Some 8-bit XT disk driver and devfs hacking 
+D: Some 8-bit XT disk driver and devfs hacking
 D: Aladdin 1533/1543(C) chipset IDE
 D: PIIX chipset IDE
 S: ul. Matemblewska 1B/10
@@ -2463,7 +2469,7 @@ E: mge@EZ-Darmstadt.Telekom.de
 D: Logical Volume Manager
 S: Bartningstr. 12
 S: 64289 Darmstadt
-S: Germany 
+S: Germany
 
 N: Mark W. McClelland
 E: mmcclell@bigfoot.com
@@ -2547,7 +2553,7 @@ E: meskes@debian.org
 P: 1024/04B6E8F5 6C 77 33 CA CC D6 22 03  AB AB 15 A3 AE AD 39 7D
 D: Kernel hacker. PostgreSQL hacker. Software watchdog daemon.
 D: Maintainer of several Debian packages
-S: Th.-Heuss-Str. 61 
+S: Th.-Heuss-Str. 61
 S: D-41812 Erkelenz
 S: Germany
 
@@ -2785,7 +2791,7 @@ E: neuffer@goofy.zdv.uni-mainz.de
 W: http://www.i-Connect.Net/~mike/
 D: Developer and maintainer of the EATA-DMA SCSI driver
 D: Co-developer EATA-PIO SCSI driver
-D: /proc/scsi and assorted other snippets 
+D: /proc/scsi and assorted other snippets
 S: Zum Schiersteiner Grund 2
 S: 55127 Mainz
 S: Germany
@@ -2852,6 +2858,10 @@ D: IPX development and support
 N: Venkatesh Pallipadi (Venki)
 D: x86/HPET
 
+N: Kyungmin Park
+E: kyungmin.park@samsung.com
+D: Samsung S5Pv210 and Exynos4210 mobile platforms
+
 N: David Parsons
 E: orc@pell.chi.il.us
 D: improved memory detection code.
@@ -3019,7 +3029,7 @@ D: Embedded PowerPC 4xx/6xx/7xx/74xx support
 S: Chandler, Arizona 85249
 S: USA
 
-N: Frederic Potter 
+N: Frederic Potter
 E: fpotter@cirpack.com
 D: Some PCI kernel support
 
@@ -3452,21 +3462,21 @@ S: Klosterweg 28 / i309
 S: 76131 Karlsruhe
 S: Germany
 
-N: James Simmons 
+N: James Simmons
 E: jsimmons@infradead.org
-E: jsimmons@users.sf.net 
+E: jsimmons@users.sf.net
 D: Frame buffer device maintainer
 D: input layer development
 D: tty/console layer
-D: various mipsel devices 
-S: 115 Carmel Avenue 
+D: various mipsel devices
+S: 115 Carmel Avenue
 S: El Cerrito CA 94530
-S: USA 
+S: USA
 
 N: Jaspreet Singh
 E: jaspreet@sangoma.com
 W: www.sangoma.com
-D: WANPIPE drivers & API Support for Sangoma S508/FT1 cards 
+D: WANPIPE drivers & API Support for Sangoma S508/FT1 cards
 S: Sangoma Technologies Inc.,
 S: 1001 Denison Street
 S: Suite 101
@@ -3490,7 +3500,7 @@ N: Craig Small
 E: csmall@triode.apana.org.au
 E: vk2xlz@gonzo.vk2xlz.ampr.org (packet radio)
 D: Gracilis PackeTwin device driver
-D: RSPF daemon 
+D: RSPF daemon
 S: 10 Stockalls Place
 S: Minto, NSW, 2566
 S: Australia
@@ -3700,7 +3710,7 @@ N: Tsu-Sheng Tsao
 E: tsusheng@scf.usc.edu
 D: IGMP(Internet Group Management Protocol) version 2
 S: 2F 14 ALY 31 LN 166 SEC 1 SHIH-PEI RD
-S: Taipei 
+S: Taipei
 S: Taiwan 112
 S: Republic of China
 S: 24335 Delta Drive
@@ -3861,7 +3871,7 @@ D: Produced the Slackware distribution, updated the SVGAlib
 D: patches for ghostscript, worked on color 'ls', etc.
 S: 301 15th Street S.
 S: Moorhead, Minnesota 56560
-S: USA 
+S: USA
 
 N: Jos Vos
 E: jos@xos.nl
@@ -3869,7 +3879,7 @@ W: http://www.xos.nl/
 D: Various IP firewall updates, ipfwadm
 S: X/OS Experts in Open Systems BV
 S: Kruislaan 419
-S: 1098 VA Amsterdam 
+S: 1098 VA Amsterdam
 S: The Netherlands
 
 N: Jeroen Vreeken
@@ -4107,7 +4117,7 @@ S: People's Repulic of China
 N: Victor Yodaiken
 E: yodaiken@fsmlabs.com
 D: RTLinux (RealTime Linux)
-S: POB 1822 
+S: POB 1822
 S: Socorro NM, 87801
 S: USA
 
@@ -4205,7 +4215,7 @@ D: EISA/sysfs subsystem
 S: France
 
 # Don't add your name here, unless you really _are_ after Marc
-# alphabetically. Leonard used to be very proud of being the 
+# alphabetically. Leonard used to be very proud of being the
 # last entry, and he'll get positively pissed if he can't even
 # be second-to-last.  (and this file really _is_ supposed to be
 # in alphabetic order)
index 420c1d0..3a4e2cd 100644 (file)
@@ -1,29 +1,29 @@
-What:           sys/devices/pciXXXX:XX/0000:XX:XX.X/dma/dma<n>chan<n>/quickdata/cap
+What:           /sys/devices/pciXXXX:XX/0000:XX:XX.X/dma/dma<n>chan<n>/quickdata/cap
 Date:           December 3, 2009
 KernelVersion:  2.6.32
 Contact:        dmaengine@vger.kernel.org
 Description:   Capabilities the DMA supports.Currently there are DMA_PQ, DMA_PQ_VAL,
                DMA_XOR,DMA_XOR_VAL,DMA_INTERRUPT.
 
-What:           sys/devices/pciXXXX:XX/0000:XX:XX.X/dma/dma<n>chan<n>/quickdata/ring_active
+What:           /sys/devices/pciXXXX:XX/0000:XX:XX.X/dma/dma<n>chan<n>/quickdata/ring_active
 Date:           December 3, 2009
 KernelVersion:  2.6.32
 Contact:        dmaengine@vger.kernel.org
 Description:   The number of descriptors active in the ring.
 
-What:           sys/devices/pciXXXX:XX/0000:XX:XX.X/dma/dma<n>chan<n>/quickdata/ring_size
+What:           /sys/devices/pciXXXX:XX/0000:XX:XX.X/dma/dma<n>chan<n>/quickdata/ring_size
 Date:           December 3, 2009
 KernelVersion:  2.6.32
 Contact:        dmaengine@vger.kernel.org
 Description:   Descriptor ring size, total number of descriptors available.
 
-What:           sys/devices/pciXXXX:XX/0000:XX:XX.X/dma/dma<n>chan<n>/quickdata/version
+What:           /sys/devices/pciXXXX:XX/0000:XX:XX.X/dma/dma<n>chan<n>/quickdata/version
 Date:           December 3, 2009
 KernelVersion:  2.6.32
 Contact:        dmaengine@vger.kernel.org
 Description:   Version of ioatdma device.
 
-What:           sys/devices/pciXXXX:XX/0000:XX:XX.X/dma/dma<n>chan<n>/quickdata/intr_coalesce
+What:           /sys/devices/pciXXXX:XX/0000:XX:XX.X/dma/dma<n>chan<n>/quickdata/intr_coalesce
 Date:           August 8, 2017
 KernelVersion:  4.14
 Contact:        dmaengine@vger.kernel.org
index a10a4de..c4a4497 100644 (file)
@@ -109,30 +109,6 @@ Description:
                When counting down the counter start from preset value
                and fire event when reach 0.
 
-What:          /sys/bus/iio/devices/iio:deviceX/in_count_quadrature_mode_available
-KernelVersion: 4.12
-Contact:       benjamin.gaignard@st.com
-Description:
-               Reading returns the list possible quadrature modes.
-
-What:          /sys/bus/iio/devices/iio:deviceX/in_count0_quadrature_mode
-KernelVersion: 4.12
-Contact:       benjamin.gaignard@st.com
-Description:
-               Configure the device counter quadrature modes:
-
-               channel_A:
-                       Encoder A input servers as the count input and B as
-                       the UP/DOWN direction control input.
-
-               channel_B:
-                       Encoder B input serves as the count input and A as
-                       the UP/DOWN direction control input.
-
-               quadrature:
-                       Encoder A and B inputs are mixed to get direction
-                       and count with a scale of 0.25.
-
 What:          /sys/bus/iio/devices/iio:deviceX/in_count_enable_mode_available
 KernelVersion: 4.12
 Contact:       benjamin.gaignard@st.com
index 7670012..1f2002d 100644 (file)
@@ -152,7 +152,7 @@ Description:
                When an interface is under test, it cannot be expected
                to pass packets as normal.
 
-What:          /sys/clas/net/<iface>/duplex
+What:          /sys/class/net/<iface>/duplex
 Date:          October 2009
 KernelVersion: 2.6.33
 Contact:       netdev@vger.kernel.org
index 6a59a13..61a7310 100644 (file)
@@ -26,6 +26,10 @@ BUILDDIR      = $(obj)/output
 PDFLATEX      = xelatex
 LATEXOPTS     = -interaction=batchmode
 
+ifeq ($(KBUILD_VERBOSE),0)
+SPHINXOPTS    += "-q"
+endif
+
 # User-friendly check for sphinx-build
 HAVE_SPHINX := $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then echo 1; else echo 0; fi)
 
index 17996c9..0ec3486 100644 (file)
@@ -107,7 +107,7 @@ for a UID/GID will prevent that UID/GID from obtaining auxiliary setid
 privileges, such as allowing a user to set up user namespace UID/GID mappings.
 
 Note on GID policies and setgroups()
-==================
+====================================
 In v5.9 we are adding support for limiting CAP_SETGID privileges as was done
 previously for CAP_SETUID. However, for compatibility with common sandboxing
 related code conventions in userspace, we currently allow arbitrary
index 526d65d..44fde25 100644 (file)
                                               mds=off [X86]
                                               tsx_async_abort=off [X86]
                                               kvm.nx_huge_pages=off [X86]
+                                              no_entry_flush [PPC]
+                                              no_uaccess_flush [PPC]
 
                                Exceptions:
                                               This does not have any effect on
 
        noefi           Disable EFI runtime services support.
 
+       no_entry_flush  [PPC] Don't flush the L1-D cache when entering the kernel.
+
        noexec          [IA-64]
 
        noexec          [X86]
        nospec_store_bypass_disable
                        [HW] Disable all mitigations for the Speculative Store Bypass vulnerability
 
+       no_uaccess_flush
+                       [PPC] Don't flush the L1-D cache after accessing user data.
+
        noxsave         [BUGS=X86] Disables x86 extended register state save
                        and restore using xsave. The kernel will fallback to
                        enabling legacy floating-point and sse state.
index 37940a0..10fde58 100644 (file)
@@ -478,7 +478,7 @@ order to ask the hardware to enter that state.  Also, for each
 statistics of the given idle state.  That information is exposed by the kernel
 via ``sysfs``.
 
-For each CPU in the system, there is a :file:`/sys/devices/system/cpu<N>/cpuidle/`
+For each CPU in the system, there is a :file:`/sys/devices/system/cpu/cpu<N>/cpuidle/`
 directory in ``sysfs``, where the number ``<N>`` is assigned to the given
 CPU at the initialization time.  That directory contains a set of subdirectories
 called :file:`state0`, :file:`state1` and so on, up to the number of idle state
@@ -494,7 +494,7 @@ object corresponding to it, as follows:
        residency.
 
 ``below``
-       Total number of times this idle state had been asked for, but cerainly
+       Total number of times this idle state had been asked for, but certainly
        a deeper idle state would have been a better match for the observed idle
        duration.
 
index 57fd6ce..f2ab8a5 100644 (file)
@@ -300,6 +300,7 @@ Note:
       0:    0     1     2     3     4     5     6     7
   RSS hash key:
   84:50:f4:00:a8:15:d1:a7:e9:7f:1d:60:35:c7:47:25:42:97:74:ca:56:bb:b6:a1:d8:43:e3:c9:0c:fd:17:55:c2:3a:4d:69:ed:f1:42:89
+
 netdev_tstamp_prequeue
 ----------------------
 
index 62b533d..0c536ae 100644 (file)
@@ -148,3 +148,13 @@ SunXi family
         * User Manual
 
           http://dl.linux-sunxi.org/A64/Allwinner%20A64%20User%20Manual%20v1.0.pdf
+
+      - Allwinner H6
+
+       * Datasheet
+
+         https://linux-sunxi.org/images/5/5c/Allwinner_H6_V200_Datasheet_V1.1.pdf
+
+       * User Manual
+
+         https://linux-sunxi.org/images/4/46/Allwinner_H6_V200_User_Manual_V1.1.pdf
index 1e44983..ed2b43e 100644 (file)
@@ -51,7 +51,7 @@ if major >= 3:
         support for Sphinx v3.0 and above is brand new. Be prepared for
         possible issues in the generated output.
         ''')
-    if minor > 0 or patch >= 2:
+    if (major > 3) or (minor > 0 or patch >= 2):
         # Sphinx c function parser is more pedantic with regards to type
         # checking. Due to that, having macros at c:function cause problems.
         # Those needed to be scaped by using c_id_attributes[] array
index c09c9ca..2b68add 100644 (file)
@@ -295,11 +295,13 @@ print the number of the test and the status of the test:
 pass::
 
         ok 28 - kmalloc_double_kzfree
+
 or, if kmalloc failed::
 
         # kmalloc_large_oob_right: ASSERTION FAILED at lib/test_kasan.c:163
         Expected ptr is not null, but is
         not ok 4 - kmalloc_large_oob_right
+
 or, if a KASAN report was expected, but not found::
 
         # kmalloc_double_kzfree: EXPECTATION FAILED at lib/test_kasan.c:629
index 1628862..8d5029a 100644 (file)
@@ -90,7 +90,7 @@ things to try.
    re-run kunit_tool.
 5. Try to run ``make ARCH=um defconfig`` before running ``kunit.py run``. This
    may help clean up any residual config items which could be causing problems.
-6. Finally, try running KUnit outside UML. KUnit and KUnit tests can run be
+6. Finally, try running KUnit outside UML. KUnit and KUnit tests can be
    built into any kernel, or can be built as a module and loaded at runtime.
    Doing so should allow you to determine if UML is causing the issue you're
    seeing. When tests are built-in, they will execute when the kernel boots, and
index d23385e..454f307 100644 (file)
@@ -197,7 +197,7 @@ Now add the following to ``drivers/misc/Kconfig``:
 
        config MISC_EXAMPLE_TEST
                bool "Test for my example"
-               depends on MISC_EXAMPLE && KUNIT
+               depends on MISC_EXAMPLE && KUNIT=y
 
 and the following to ``drivers/misc/Makefile``:
 
index da1d6f0..8dbcdc5 100644 (file)
@@ -175,17 +175,17 @@ An example Kconfig entry:
 
 .. code-block:: none
 
-        config FOO_KUNIT_TEST
-                tristate "KUnit test for foo" if !KUNIT_ALL_TESTS
-                depends on KUNIT
-                default KUNIT_ALL_TESTS
-                help
-                    This builds unit tests for foo.
+       config FOO_KUNIT_TEST
+               tristate "KUnit test for foo" if !KUNIT_ALL_TESTS
+               depends on KUNIT
+               default KUNIT_ALL_TESTS
+               help
+                 This builds unit tests for foo.
 
-                    For more information on KUnit and unit tests in general, please refer
-                    to the KUnit documentation in Documentation/dev-tools/kunit
+                 For more information on KUnit and unit tests in general, please refer
+                 to the KUnit documentation in Documentation/dev-tools/kunit/.
 
-                    If unsure, say N
+                 If unsure, say N.
 
 
 Test File and Module Names
index 961d3ea..9c28c51 100644 (file)
@@ -92,7 +92,7 @@ behavior of a function called ``add``; the first parameter is always of type
 the second parameter, in this case, is what the value is expected to be; the
 last value is what the value actually is. If ``add`` passes all of these
 expectations, the test case, ``add_test_basic`` will pass; if any one of these
-expectations fail, the test case will fail.
+expectations fails, the test case will fail.
 
 It is important to understand that a test case *fails* when any expectation is
 violated; however, the test will continue running, potentially trying other
@@ -202,7 +202,7 @@ Example:
        kunit_test_suite(example_test_suite);
 
 In the above example the test suite, ``example_test_suite``, would run the test
-cases ``example_test_foo``, ``example_test_bar``, and ``example_test_baz``,
+cases ``example_test_foo``, ``example_test_bar``, and ``example_test_baz``;
 each would have ``example_test_init`` called immediately before it and would
 have ``example_test_exit`` called immediately after it.
 ``kunit_test_suite(example_test_suite)`` registers the test suite with the
@@ -229,7 +229,7 @@ through some sort of indirection where a function is exposed as part of an API
 such that the definition of that function can be changed without affecting the
 rest of the code base. In the kernel this primarily comes from two constructs,
 classes, structs that contain function pointers that are provided by the
-implementer, and architecture specific functions which have definitions selected
+implementer, and architecture-specific functions which have definitions selected
 at compile time.
 
 Classes
@@ -459,7 +459,7 @@ KUnit on non-UML architectures
 By default KUnit uses UML as a way to provide dependencies for code under test.
 Under most circumstances KUnit's usage of UML should be treated as an
 implementation detail of how KUnit works under the hood. Nevertheless, there
-are instances where being able to run architecture specific code or test
+are instances where being able to run architecture-specific code or test
 against real hardware is desirable. For these reasons KUnit supports running on
 other architectures.
 
@@ -561,6 +561,11 @@ Once the kernel is built and installed, a simple
 
 ...will run the tests.
 
+.. note::
+   Note that you should make sure your test depends on ``KUNIT=y`` in Kconfig
+   if the test does not support module build.  Otherwise, it will trigger
+   compile errors if ``CONFIG_KUNIT`` is ``m``.
+
 Writing new tests for other architectures
 -----------------------------------------
 
@@ -594,7 +599,7 @@ writing normal KUnit tests. One special caveat is that you have to reset
 hardware state in between test cases; if this is not possible, you may only be
 able to run one test case per invocation.
 
-.. TODO(brendanhiggins@google.com): Add an actual example of an architecture
+.. TODO(brendanhiggins@google.com): Add an actual example of an architecture-
    dependent KUnit test.
 
 KUnit debugfs representation
index ef3deb7..17ac4a3 100644 (file)
@@ -4,7 +4,7 @@ Clock control registers reside in different Hi6220 system controllers,
 please refer the following document to know more about the binding rules
 for these system controllers:
 
-Documentation/devicetree/bindings/arm/hisilicon/hisilicon.txt
+Documentation/devicetree/bindings/arm/hisilicon/hisilicon.yaml
 
 Required Properties:
 
index 4d9e7c7..90775c2 100644 (file)
@@ -57,7 +57,7 @@ examples:
     };
 
     can@53fc8000 {
-        compatible = "fsl,imx53-flexcan", "fsl,p1010-flexcan";
+        compatible = "fsl,imx53-flexcan", "fsl,imx25-flexcan";
         reg = <0x53fc8000 0x4000>;
         interrupts = <82>;
         clocks = <&clks IMX5_CLK_CAN1_IPG_GATE>, <&clks IMX5_CLK_CAN1_SERIAL_GATE>;
index f6c3fcc..b5af120 100644 (file)
@@ -32,6 +32,11 @@ description: |
                        | | vint  | bit  |  | 0 |.....|63| vintx  |
                        | +--------------+  +------------+        |
                        |                                         |
+                       |      Unmap                              |
+                       | +--------------+                        |
+  Unmapped events ---->| |   umapidx    |-------------------------> Globalevents
+                       | +--------------+                        |
+                       |                                         |
                        +-----------------------------------------+
 
   Configuration of these Intmap registers that maps global events to vint is
@@ -70,6 +75,11 @@ properties:
         - description: |
             "limit" specifies the limit for translation
 
+  ti,unmapped-event-sources:
+    $ref: /schemas/types.yaml#definitions/phandle-array
+    description:
+      Array of phandles to DMA controllers where the unmapped events originate.
+
 required:
   - compatible
   - reg
diff --git a/Documentation/devicetree/bindings/net/can/can-controller.yaml b/Documentation/devicetree/bindings/net/can/can-controller.yaml
new file mode 100644 (file)
index 0000000..9cf2ae0
--- /dev/null
@@ -0,0 +1,18 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/can/can-controller.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: CAN Controller Generic Binding
+
+maintainers:
+  - Marc Kleine-Budde <mkl@pengutronix.de>
+
+properties:
+  $nodename:
+    pattern: "^can(@.*)?$"
+
+additionalProperties: true
+
+...
diff --git a/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml b/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml
new file mode 100644 (file)
index 0000000..13875ea
--- /dev/null
@@ -0,0 +1,139 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/can/fsl,flexcan.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title:
+  Flexcan CAN controller on Freescale's ARM and PowerPC system-on-a-chip (SOC).
+
+maintainers:
+  - Marc Kleine-Budde <mkl@pengutronix.de>
+
+allOf:
+  - $ref: can-controller.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - enum:
+          - fsl,imx8qm-flexcan
+          - fsl,imx8mp-flexcan
+          - fsl,imx6q-flexcan
+          - fsl,imx28-flexcan
+          - fsl,imx25-flexcan
+          - fsl,p1010-flexcan
+          - fsl,vf610-flexcan
+          - fsl,ls1021ar2-flexcan
+          - fsl,lx2160ar1-flexcan
+      - items:
+          - enum:
+              - fsl,imx53-flexcan
+              - fsl,imx35-flexcan
+          - const: fsl,imx25-flexcan
+      - items:
+          - enum:
+              - fsl,imx7d-flexcan
+              - fsl,imx6ul-flexcan
+              - fsl,imx6sx-flexcan
+          - const: fsl,imx6q-flexcan
+      - items:
+          - enum:
+              - fsl,ls1028ar1-flexcan
+          - const: fsl,lx2160ar1-flexcan
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 2
+
+  clock-names:
+    items:
+      - const: ipg
+      - const: per
+
+  clock-frequency:
+    description: |
+      The oscillator frequency driving the flexcan device, filled in by the
+      boot loader. This property should only be used the used operating system
+      doesn't support the clocks and clock-names property.
+
+  xceiver-supply:
+    description: Regulator that powers the CAN transceiver.
+
+  big-endian:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description: |
+      This means the registers of FlexCAN controller are big endian. This is
+      optional property.i.e. if this property is not present in device tree
+      node then controller is assumed to be little endian. If this property is
+      present then controller is assumed to be big endian.
+
+  fsl,stop-mode:
+    description: |
+      Register bits of stop mode control.
+
+      The format should be as follows:
+      <gpr req_gpr req_bit>
+      gpr is the phandle to general purpose register node.
+      req_gpr is the gpr register offset of CAN stop request.
+      req_bit is the bit offset of CAN stop request.
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    items:
+      items:
+        - description: The 'gpr' is the phandle to general purpose register node.
+        - description: The 'req_gpr' is the gpr register offset of CAN stop request.
+          maximum: 0xff
+        - description: The 'req_bit' is the bit offset of CAN stop request.
+          maximum: 0x1f
+
+  fsl,clk-source:
+    description: |
+      Select the clock source to the CAN Protocol Engine (PE). It's SoC
+      implementation dependent. Refer to RM for detailed definition. If this
+      property is not set in device tree node then driver selects clock source 1
+      by default.
+      0: clock source 0 (oscillator clock)
+      1: clock source 1 (peripheral clock)
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 1
+    minimum: 0
+    maximum: 1
+
+  wakeup-source:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description:
+      Enable CAN remote wakeup.
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    can@1c000 {
+        compatible = "fsl,p1010-flexcan";
+        reg = <0x1c000 0x1000>;
+        interrupts = <48 0x2>;
+        interrupt-parent = <&mpic>;
+        clock-frequency = <200000000>;
+        fsl,clk-source = <0>;
+    };
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    can@2090000 {
+        compatible = "fsl,imx6q-flexcan";
+        reg = <0x02090000 0x4000>;
+        interrupts = <0 110 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clks 1>, <&clks 2>;
+        clock-names = "ipg", "per";
+        fsl,stop-mode = <&gpr 0x34 28>;
+    };
diff --git a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
deleted file mode 100644 (file)
index e10b6eb..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-Flexcan CAN controller on Freescale's ARM and PowerPC system-on-a-chip (SOC).
-
-Required properties:
-
-- compatible : Should be "fsl,<processor>-flexcan"
-
-  where <processor> is imx8qm, imx6q, imx28, imx53, imx35, imx25, p1010,
-  vf610, ls1021ar2, lx2160ar1, ls1028ar1.
-
-  The ls1028ar1 must be followed by lx2160ar1, e.g.
-   - "fsl,ls1028ar1-flexcan", "fsl,lx2160ar1-flexcan"
-
-  An implementation should also claim any of the following compatibles
-  that it is fully backwards compatible with:
-
-  - fsl,p1010-flexcan
-
-- reg : Offset and length of the register set for this device
-- interrupts : Interrupt tuple for this device
-
-Optional properties:
-
-- clock-frequency : The oscillator frequency driving the flexcan device
-
-- xceiver-supply: Regulator that powers the CAN transceiver
-
-- big-endian: This means the registers of FlexCAN controller are big endian.
-              This is optional property.i.e. if this property is not present in
-              device tree node then controller is assumed to be little endian.
-              if this property is present then controller is assumed to be big
-              endian.
-
-- fsl,stop-mode: register bits of stop mode control, the format is
-                <&gpr req_gpr req_bit>.
-                gpr is the phandle to general purpose register node.
-                req_gpr is the gpr register offset of CAN stop request.
-                req_bit is the bit offset of CAN stop request.
-
-- fsl,clk-source: Select the clock source to the CAN Protocol Engine (PE).
-                 It's SoC Implementation dependent. Refer to RM for detailed
-                 definition. If this property is not set in device tree node
-                 then driver selects clock source 1 by default.
-                 0: clock source 0 (oscillator clock)
-                 1: clock source 1 (peripheral clock)
-
-- wakeup-source: enable CAN remote wakeup
-
-Example:
-
-       can@1c000 {
-               compatible = "fsl,p1010-flexcan";
-               reg = <0x1c000 0x1000>;
-               interrupts = <48 0x2>;
-               interrupt-parent = <&mpic>;
-               clock-frequency = <200000000>; // filled in by bootloader
-               fsl,clk-source = <0>; // select clock source 0 for PE
-       };
index fcfd02d..e498966 100644 (file)
@@ -8,10 +8,16 @@ Required properties:
 
 - reg : The I2C address of the device.
 
+Optional properties:
+
+- realtek,power-up-delay-ms
+  Set a delay time for flush work to be completed,
+  this value is adjustable depending on platform.
 
 Example:
 
 rt1015: codec@28 {
        compatible = "realtek,rt1015";
        reg = <0x28>;
+       realtek,power-up-delay-ms = <50>;
 };
index bbb0c1c..a94f17d 100644 (file)
@@ -86,9 +86,6 @@ Other Functions
 .. kernel-doc:: fs/dax.c
    :export:
 
-.. kernel-doc:: fs/direct-io.c
-   :export:
-
 .. kernel-doc:: fs/libfs.c
    :export:
 
index 805a1e9..849d5b1 100644 (file)
@@ -256,6 +256,10 @@ which is 1024 bytes long:
      - s\_padding2
      -
    * - 0x54
+     - \_\_be32
+     - s\_num\_fc\_blocks
+     - Number of fast commit blocks in the journal.
+   * - 0x58
      - \_\_u32
      - s\_padding[42]
      -
@@ -310,6 +314,8 @@ The journal incompat features are any combination of the following:
      - This journal uses v3 of the checksum on-disk format. This is the same as
        v2, but the journal block tag size is fixed regardless of the size of
        block numbers. (JBD2\_FEATURE\_INCOMPAT\_CSUM\_V3)
+   * - 0x20
+     - Journal has fast commit blocks. (JBD2\_FEATURE\_INCOMPAT\_FAST\_COMMIT)
 
 .. _jbd2_checksum_type:
 
index 93e55d7..2eb1ab2 100644 (file)
@@ -596,6 +596,13 @@ following:
      - Sparse Super Block, v2. If this flag is set, the SB field s\_backup\_bgs
        points to the two block groups that contain backup superblocks
        (COMPAT\_SPARSE\_SUPER2).
+   * - 0x400
+     - Fast commits supported. Although fast commits blocks are
+       backward incompatible, fast commit blocks are not always
+       present in the journal. If fast commit blocks are present in
+       the journal, JBD2 incompat feature
+       (JBD2\_FEATURE\_INCOMPAT\_FAST\_COMMIT) gets
+       set (COMPAT\_FAST\_COMMIT).
 
 .. _super_incompat:
 
index 5a5f70b..e18f90f 100644 (file)
@@ -136,10 +136,8 @@ Fast commits
 ~~~~~~~~~~~~
 
 JBD2 to also allows you to perform file-system specific delta commits known as
-fast commits. In order to use fast commits, you first need to call
-:c:func:`jbd2_fc_init` and tell how many blocks at the end of journal
-area should be reserved for fast commits. Along with that, you will also need
-to set following callbacks that perform correspodning work:
+fast commits. In order to use fast commits, you will need to set following
+callbacks that perform correspodning work:
 
 `journal->j_fc_cleanup_cb`: Cleanup function called after every full commit and
 fast commit.
index 874ce0e..71b9af1 100644 (file)
@@ -19,9 +19,9 @@ report the "current" state of the lid as either "opened" or "closed".
 
 For most platforms, both the _LID method and the lid notifications are
 reliable. However, there are exceptions. In order to work with these
-exceptional buggy platforms, special restrictions and expections should be
+exceptional buggy platforms, special restrictions and exceptions should be
 taken into account. This document describes the restrictions and the
-expections of the Linux ACPI lid device driver.
+exceptions of the Linux ACPI lid device driver.
 
 
 Restrictions of the returning value of the _LID control method
@@ -46,7 +46,7 @@ state is changed to "closed". The "closed" notification is normally used to
 trigger some system power saving operations on Windows. Since it is fully
 tested, it is reliable from all AML tables.
 
-Expections for the userspace users of the ACPI lid device driver
+Exceptions for the userspace users of the ACPI lid device driver
 ================================================================
 
 The ACPI button driver exports the lid state to the userspace via the
@@ -100,7 +100,7 @@ use the following kernel parameter:
 C. button.lid_init_state=ignore:
    When this option is specified, the ACPI button driver never reports the
    initial lid state and there is a compensation mechanism implemented to
-   ensure that the reliable "closed" notifications can always be delievered
+   ensure that the reliable "closed" notifications can always be delivered
    to the userspace by always pairing "closed" input events with complement
    "opened" input events. But there is still no guarantee that the "opened"
    notifications can be delivered to the userspace when the lid is actually
index bb6d74f..59aad61 100644 (file)
@@ -20,9 +20,9 @@ index, like the ASL example below shows::
 
       Name (_CRS, ResourceTemplate ()
       {
-          GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionInputOnly,
+          GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionOutputOnly,
                   "\\_SB.GPO0", 0, ResourceConsumer) {15}
-          GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionInputOnly,
+          GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionOutputOnly,
                   "\\_SB.GPO0", 0, ResourceConsumer) {27, 31}
       })
 
@@ -49,15 +49,41 @@ index
 pin
   Pin in the GpioIo()/GpioInt() resource. Typically this is zero.
 active_low
-  If 1 the GPIO is marked as active_low.
+  If 1, the GPIO is marked as active_low.
 
 Since ACPI GpioIo() resource does not have a field saying whether it is
 active low or high, the "active_low" argument can be used here.  Setting
 it to 1 marks the GPIO as active low.
 
+Note, active_low in _DSD does not make sense for GpioInt() resource and
+must be 0. GpioInt() resource has its own means of defining it.
+
 In our Bluetooth example the "reset-gpios" refers to the second GpioIo()
 resource, second pin in that resource with the GPIO number of 31.
 
+The GpioIo() resource unfortunately doesn't explicitly provide an initial
+state of the output pin which driver should use during its initialization.
+
+Linux tries to use common sense here and derives the state from the bias
+and polarity settings. The table below shows the expectations:
+
+=========  =============  ==============
+Pull Bias     Polarity     Requested...
+=========  =============  ==============
+Implicit     x            AS IS (assumed firmware configured for us)
+Explicit     x (no _DSD)  as Pull Bias (Up == High, Down == Low),
+                          assuming non-active (Polarity = !Pull Bias)
+Down         Low          as low, assuming active
+Down         High         as low, assuming non-active
+Up           Low          as high, assuming non-active
+Up           High         as high, assuming active
+=========  =============  ==============
+
+That said, for our above example the both GPIOs, since the bias setting
+is explicit and _DSD is present, will be treated as active with a high
+polarity and Linux will configure the pins in this state until a driver
+reprograms them differently.
+
 It is possible to leave holes in the array of GPIOs. This is useful in
 cases like with SPI host controllers where some chip selects may be
 implemented as GPIOs and some as native signals. For example a SPI host
@@ -112,8 +138,8 @@ Example::
   Package () {
       "gpio-line-names",
       Package () {
-          "SPI0_CS_N", "EXP2_INT", "MUX6_IO", "UART0_RXD", "MUX7_IO",
-          "LVL_C_A1", "MUX0_IO", "SPI1_MISO"
+          "SPI0_CS_N", "EXP2_INT", "MUX6_IO", "UART0_RXD",
+          "MUX7_IO", "LVL_C_A1", "MUX0_IO", "SPI1_MISO",
       }
   }
 
@@ -137,7 +163,7 @@ to the GPIO lines it is going to use and provide the GPIO subsystem with a
 mapping between those names and the ACPI GPIO resources corresponding to them.
 
 To do that, the driver needs to define a mapping table as a NULL-terminated
-array of struct acpi_gpio_mapping objects that each contain a name, a pointer
+array of struct acpi_gpio_mapping objects that each contains a name, a pointer
 to an array of line data (struct acpi_gpio_params) objects and the size of that
 array.  Each struct acpi_gpio_params object consists of three fields,
 crs_entry_index, line_index, active_low, representing the index of the target
@@ -154,13 +180,14 @@ question would look like this::
   static const struct acpi_gpio_mapping bluetooth_acpi_gpios[] = {
     { "reset-gpios", &reset_gpio, 1 },
     { "shutdown-gpios", &shutdown_gpio, 1 },
-    { },
+    { }
   };
 
 Next, the mapping table needs to be passed as the second argument to
-acpi_dev_add_driver_gpios() that will register it with the ACPI device object
-pointed to by its first argument.  That should be done in the driver's .probe()
-routine.  On removal, the driver should unregister its GPIO mapping table by
+acpi_dev_add_driver_gpios() or its managed analogue that will
+register it with the ACPI device object pointed to by its first
+argument. That should be done in the driver's .probe() routine.
+On removal, the driver should unregister its GPIO mapping table by
 calling acpi_dev_remove_driver_gpios() on the ACPI device object where that
 table was previously registered.
 
@@ -191,12 +218,12 @@ The driver might expect to get the right GPIO when it does::
 but since there is no way to know the mapping between "reset" and
 the GpioIo() in _CRS desc will hold ERR_PTR(-ENOENT).
 
-The driver author can solve this by passing the mapping explictly
-(the recommended way and documented in the above chapter).
+The driver author can solve this by passing the mapping explicitly
+(this is the recommended way and it's documented in the above chapter).
 
 The ACPI GPIO mapping tables should not contaminate drivers that are not
 knowing about which exact device they are servicing on. It implies that
-the ACPI GPIO mapping tables are hardly linked to ACPI ID and certain
+the ACPI GPIO mapping tables are hardly linked to an ACPI ID and certain
 objects, as listed in the above chapter, of the device in question.
 
 Getting GPIO descriptor
@@ -229,5 +256,5 @@ Case 2 explicitly tells GPIO core to look for resources in _CRS.
 Be aware that gpiod_get_index() in cases 1 and 2, assuming that there
 are two versions of ACPI device description provided and no mapping is
 present in the driver, will return different resources. That's why a
-certain driver has to handle them carefully as explained in previous
+certain driver has to handle them carefully as explained in the previous
 chapter.
index 0aa7e2c..6ab6c09 100644 (file)
@@ -98,7 +98,7 @@ subject to change::
    [    0.188903]   exdebug-0398 ex_trace_point        : Method End [0xf58394d8:\_SB.PCI0.LPCB.ECOK] execution.
 
 Developers can utilize these special log entries to track the AML
-interpretion, thus can aid issue debugging and performance tuning. Note
+interpretation, thus can aid issue debugging and performance tuning. Note
 that, as the "AML tracer" logs are implemented via ACPI_DEBUG_PRINT()
 macro, CONFIG_ACPI_DEBUG is also required to be enabled for enabling
 "AML tracer" logs.
index 1f9ea82..2062a60 100644 (file)
@@ -83,10 +83,6 @@ AMDGPU XGMI Support
 ===================
 
 .. kernel-doc:: drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
-   :doc: AMDGPU XGMI Support
-
-.. kernel-doc:: drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
-   :internal:
 
 AMDGPU RAS Support
 ==================
@@ -124,9 +120,6 @@ RAS VRAM Bad Pages sysfs Interface
 .. kernel-doc:: drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
    :doc: AMDGPU RAS sysfs gpu_vram_bad_pages Interface
 
-.. kernel-doc:: drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
-   :internal:
-
 Sample Code
 -----------
 Sample code for testing error injection can be found here:
index 9257f8a..2b87701 100644 (file)
@@ -20,7 +20,7 @@ ADM1266 is a sequencer that features voltage readback from 17 channels via an
 integrated 12 bit SAR ADC, accessed using a PMBus interface.
 
 The driver is a client driver to the core PMBus driver. Please see
-Documentation/hwmon/pmbus for details on PMBus client drivers.
+Documentation/hwmon/pmbus.rst for details on PMBus client drivers.
 
 
 Sysfs entries
index e6b91ab..b797db7 100644 (file)
@@ -132,6 +132,7 @@ Hardware Monitoring Kernel Drivers
    mcp3021
    menf21bmc
    mlxreg-fan
+   mp2975
    nct6683
    nct6775
    nct7802
index 5b0609c..81d816b 100644 (file)
@@ -20,6 +20,7 @@ This driver implements support for Monolithic Power Systems, Inc. (MPS)
 vendor dual-loop, digital, multi-phase controller MP2975.
 
 This device:
+
 - Supports up to two power rail.
 - Provides 8 pulse-width modulations (PWMs), and can be configured up
   to 8-phase operation for rail 1 and up to 4-phase operation for rail
@@ -32,10 +33,12 @@ This device:
   10-mV DAC, IMVP9 mode with 5-mV DAC.
 
 Device supports:
+
 - SVID interface.
 - AVSBus interface.
 
 Device complaint with:
+
 - PMBus rev 1.3 interface.
 
 Device supports direct format for reading output current, output voltage,
@@ -45,11 +48,14 @@ Device supports VID and direct formats for reading output voltage.
 The below VID modes are supported: VR12, VR13, IMVP9.
 
 The driver provides the next attributes for the current:
+
 - for current in: input, maximum alarm;
 - for current out input, maximum alarm and highest values;
 - for phase current: input and label.
-attributes.
+  attributes.
+
 The driver exports the following attributes via the 'sysfs' files, where
+
 - 'n' is number of telemetry pages (from 1 to 2);
 - 'k' is number of configured phases (from 1 to 8);
 - indexes 1, 1*n for "iin";
@@ -65,11 +71,14 @@ The driver exports the following attributes via the 'sysfs' files, where
 **curr[1-{2n+k}]_label**
 
 The driver provides the next attributes for the voltage:
+
 - for voltage in: input, high critical threshold, high critical alarm, all only
   from page 0;
 - for voltage out: input, low and high critical thresholds, low and high
   critical alarms, from pages 0 and 1;
+
 The driver exports the following attributes via the 'sysfs' files, where
+
 - 'n' is number of telemetry pages (from 1 to 2);
 - indexes 1 for "iin";
 - indexes n+1, n+2 for "vout";
@@ -87,9 +96,12 @@ The driver exports the following attributes via the 'sysfs' files, where
 **in[2-{n+1}1_lcrit_alarm**
 
 The driver provides the next attributes for the power:
+
 - for power in alarm and input.
 - for power out: highest and input.
+
 The driver exports the following attributes via the 'sysfs' files, where
+
 - 'n' is number of telemetry pages (from 1 to 2);
 - indexes 1 for "pin";
 - indexes n+1, n+2 for "pout";
index 53e6090..e5d63b9 100644 (file)
@@ -25,3 +25,4 @@ LEDs
    leds-lp5562
    leds-lp55xx
    leds-mlxcpld
+   leds-sc27xx
index cec03bd..9f3cfca 100644 (file)
@@ -42,6 +42,7 @@ The validator tracks lock-class usage history and divides the usage into
 (4 usages * n STATEs + 1) categories:
 
 where the 4 usages can be:
+
 - 'ever held in STATE context'
 - 'ever held as readlock in STATE context'
 - 'ever held with STATE enabled'
@@ -49,10 +50,12 @@ where the 4 usages can be:
 
 where the n STATEs are coded in kernel/locking/lockdep_states.h and as of
 now they include:
+
 - hardirq
 - softirq
 
 where the last 1 category is:
+
 - 'ever used'                                       [ == !unused        ]
 
 When locking rules are violated, these usage bits are presented in the
@@ -96,9 +99,9 @@ exact case is for the lock as of the reporting time.
   +--------------+-------------+--------------+
   |              | irq enabled | irq disabled |
   +--------------+-------------+--------------+
-  | ever in irq  |      ?      |       -      |
+  | ever in irq  |     '?'     |      '-'     |
   +--------------+-------------+--------------+
-  | never in irq |      +      |       .      |
+  | never in irq |     '+'     |      '.'     |
   +--------------+-------------+--------------+
 
 The character '-' suggests irq is disabled because if otherwise the
@@ -216,7 +219,7 @@ looks like this::
        BD_MUTEX_PARTITION
   };
 
-mutex_lock_nested(&bdev->bd_contains->bd_mutex, BD_MUTEX_PARTITION);
+  mutex_lock_nested(&bdev->bd_contains->bd_mutex, BD_MUTEX_PARTITION);
 
 In this case the locking is done on a bdev object that is known to be a
 partition.
@@ -334,7 +337,7 @@ Troubleshooting:
 ----------------
 
 The validator tracks a maximum of MAX_LOCKDEP_KEYS number of lock classes.
-Exceeding this number will trigger the following lockdep warning:
+Exceeding this number will trigger the following lockdep warning::
 
        (DEBUG_LOCKS_WARN_ON(id >= MAX_LOCKDEP_KEYS))
 
@@ -420,7 +423,8 @@ the critical section of another reader of the same lock instance.
 
 The difference between recursive readers and non-recursive readers is because:
 recursive readers get blocked only by a write lock *holder*, while non-recursive
-readers could get blocked by a write lock *waiter*. Considering the follow example:
+readers could get blocked by a write lock *waiter*. Considering the follow
+example::
 
        TASK A:                 TASK B:
 
@@ -448,20 +452,22 @@ There are simply four block conditions:
 
 Block condition matrix, Y means the row blocks the column, and N means otherwise.
 
-           | E | r | R |
        +---+---+---+---+
-         E | Y | Y | Y |
+       |   | E | r | R |
+       +---+---+---+---+
+       | E | Y | Y | Y |
+       +---+---+---+---+
+       | r | Y | Y | N |
        +---+---+---+---+
-         r | Y | Y | N |
+       | R | Y | Y | N |
        +---+---+---+---+
-         R | Y | Y | N |
 
        (W: writers, r: non-recursive readers, R: recursive readers)
 
 
 acquired recursively. Unlike non-recursive read locks, recursive read locks
 only get blocked by current write lock *holders* other than write lock
-*waiters*, for example:
+*waiters*, for example::
 
        TASK A:                 TASK B:
 
@@ -491,7 +497,7 @@ Recursive locks don't block each other, while non-recursive locks do (this is
 even true for two non-recursive read locks). A non-recursive lock can block the
 corresponding recursive lock, and vice versa.
 
-A deadlock case with recursive locks involved is as follow:
+A deadlock case with recursive locks involved is as follow::
 
        TASK A:                 TASK B:
 
@@ -510,7 +516,7 @@ because there are 3 types for lockers, there are, in theory, 9 types of lock
 dependencies, but we can show that 4 types of lock dependencies are enough for
 deadlock detection.
 
-For each lock dependency:
+For each lock dependency::
 
        L1 -> L2
 
@@ -525,20 +531,25 @@ same types).
 With the above combination for simplification, there are 4 types of dependency edges
 in the lockdep graph:
 
-1) -(ER)->: exclusive writer to recursive reader dependency, "X -(ER)-> Y" means
+1) -(ER)->:
+           exclusive writer to recursive reader dependency, "X -(ER)-> Y" means
            X -> Y and X is a writer and Y is a recursive reader.
 
-2) -(EN)->: exclusive writer to non-recursive locker dependency, "X -(EN)-> Y" means
+2) -(EN)->:
+           exclusive writer to non-recursive locker dependency, "X -(EN)-> Y" means
            X -> Y and X is a writer and Y is either a writer or non-recursive reader.
 
-3) -(SR)->: shared reader to recursive reader dependency, "X -(SR)-> Y" means
+3) -(SR)->:
+           shared reader to recursive reader dependency, "X -(SR)-> Y" means
            X -> Y and X is a reader (recursive or not) and Y is a recursive reader.
 
-4) -(SN)->: shared reader to non-recursive locker dependency, "X -(SN)-> Y" means
+4) -(SN)->:
+           shared reader to non-recursive locker dependency, "X -(SN)-> Y" means
            X -> Y and X is a reader (recursive or not) and Y is either a writer or
            non-recursive reader.
 
-Note that given two locks, they may have multiple dependencies between them, for example:
+Note that given two locks, they may have multiple dependencies between them,
+for example::
 
        TASK A:
 
@@ -592,11 +603,11 @@ circles that won't cause deadlocks.
 
 Proof for sufficiency (Lemma 1):
 
-Let's say we have a strong circle:
+Let's say we have a strong circle::
 
        L1 -> L2 ... -> Ln -> L1
 
-, which means we have dependencies:
+, which means we have dependencies::
 
        L1 -> L2
        L2 -> L3
@@ -633,7 +644,7 @@ a lock held by P2, and P2 is waiting for a lock held by P3, ... and Pn is waitin
 for a lock held by P1. Let's name the lock Px is waiting as Lx, so since P1 is waiting
 for L1 and holding Ln, so we will have Ln -> L1 in the dependency graph. Similarly,
 we have L1 -> L2, L2 -> L3, ..., Ln-1 -> Ln in the dependency graph, which means we
-have a circle:
+have a circle::
 
        Ln -> L1 -> L2 -> ... -> Ln
 
index 46072ce..64420b3 100644 (file)
@@ -24,7 +24,6 @@ fit into other categories.
    isl29003
    lis3lv02d
    max6875
-   mic/index
    pci-endpoint-test
    spear-pcie-gadget
    uacce
index b165181..a432dc4 100644 (file)
@@ -70,6 +70,7 @@ The ``ice`` driver reports the following versions
         that both the name (as reported by ``fw.app.name``) and version are
         required to uniquely identify the package.
     * - ``fw.app.bundle_id``
+      - running
       - 0xc0000001
       - Unique identifier for the DDP package loaded in the device. Also
         referred to as the DDP Track ID. Can be used to uniquely identify
index f5be243..0a4b73b 100644 (file)
@@ -10,9 +10,9 @@ Overview / What Is J1939
 SAE J1939 defines a higher layer protocol on CAN. It implements a more
 sophisticated addressing scheme and extends the maximum packet size above 8
 bytes. Several derived specifications exist, which differ from the original
-J1939 on the application level, like MilCAN A, NMEA2000 and especially
+J1939 on the application level, like MilCAN A, NMEA2000, and especially
 ISO-11783 (ISOBUS). This last one specifies the so-called ETP (Extended
-Transport Protocol) which is has been included in this implementation. This
+Transport Protocol), which has been included in this implementation. This
 results in a maximum packet size of ((2 ^ 24) - 1) * 7 bytes == 111 MiB.
 
 Specifications used
@@ -32,15 +32,15 @@ sockets, we found some reasons to justify a kernel implementation for the
 addressing and transport methods used by J1939.
 
 * **Addressing:** when a process on an ECU communicates via J1939, it should
-  not necessarily know its source address. Although at least one process per
+  not necessarily know its source address. Although, at least one process per
   ECU should know the source address. Other processes should be able to reuse
   that address. This way, address parameters for different processes
   cooperating for the same ECU, are not duplicated. This way of working is
-  closely related to the UNIX concept where programs do just one thing, and do
+  closely related to the UNIX concept, where programs do just one thing and do
   it well.
 
 * **Dynamic addressing:** Address Claiming in J1939 is time critical.
-  Furthermore data transport should be handled properly during the address
+  Furthermore, data transport should be handled properly during the address
   negotiation. Putting this functionality in the kernel eliminates it as a
   requirement for _every_ user space process that communicates via J1939. This
   results in a consistent J1939 bus with proper addressing.
@@ -58,7 +58,7 @@ Therefore, these parts are left to user space.
 
 The J1939 sockets operate on CAN network devices (see SocketCAN). Any J1939
 user space library operating on CAN raw sockets will still operate properly.
-Since such library does not communicate with the in-kernel implementation, care
+Since such library does not communicate with the in-kernel implementation, care
 must be taken that these two do not interfere. In practice, this means they
 cannot share ECU addresses. A single ECU (or virtual ECU) address is used by
 the library exclusively, or by the in-kernel system exclusively.
@@ -77,13 +77,13 @@ is composed as follows:
 8 bits : PS (PDU Specific)
 
 In J1939-21 distinction is made between PDU1 format (where PF < 240) and PDU2
-format (where PF >= 240). Furthermore, when using PDU2 format, the PS-field
+format (where PF >= 240). Furthermore, when using the PDU2 format, the PS-field
 contains a so-called Group Extension, which is part of the PGN. When using PDU2
 format, the Group Extension is set in the PS-field.
 
 On the other hand, when using PDU1 format, the PS-field contains a so-called
 Destination Address, which is _not_ part of the PGN. When communicating a PGN
-from user space to kernel (or visa versa) and PDU2 format is used, the PS-field
+from user space to kernel (or vice versa) and PDU2 format is used, the PS-field
 of the PGN shall be set to zero. The Destination Address shall be set
 elsewhere.
 
@@ -96,15 +96,15 @@ Addressing
 
 Both static and dynamic addressing methods can be used.
 
-For static addresses, no extra checks are made by the kernel, and provided
+For static addresses, no extra checks are made by the kernel and provided
 addresses are considered right. This responsibility is for the OEM or system
 integrator.
 
 For dynamic addressing, so-called Address Claiming, extra support is foreseen
-in the kernel. In J1939 any ECU is known by it's 64-bit NAME. At the moment of
+in the kernel. In J1939 any ECU is known by its 64-bit NAME. At the moment of
 a successful address claim, the kernel keeps track of both NAME and source
 address being claimed. This serves as a base for filter schemes. By default,
-packets with a destination that is not locally, will be rejected.
+packets with a destination that is not locally will be rejected.
 
 Mixed mode packets (from a static to a dynamic address or vice versa) are
 allowed. The BSD sockets define separate API calls for getting/setting the
@@ -131,31 +131,31 @@ API Calls
 ---------
 
 On CAN, you first need to open a socket for communicating over a CAN network.
-To use J1939, #include <linux/can/j1939.h>. From there, <linux/can.h> will be
+To use J1939, ``#include <linux/can/j1939.h>``. From there, ``<linux/can.h>`` will be
 included too. To open a socket, use:
 
 .. code-block:: C
 
     s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
 
-J1939 does use SOCK_DGRAM sockets. In the J1939 specification, connections are
+J1939 does use ``SOCK_DGRAM`` sockets. In the J1939 specification, connections are
 mentioned in the context of transport protocol sessions. These still deliver
-packets to the other end (using several CAN packets). SOCK_STREAM is not
+packets to the other end (using several CAN packets). ``SOCK_STREAM`` is not
 supported.
 
-After the successful creation of the socket, you would normally use the bind(2)
-and/or connect(2) system call to bind the socket to a CAN interface.  After
-binding and/or connecting the socket, you can read(2) and write(2) from/to the
-socket or use send(2), sendto(2), sendmsg(2) and the recv*() counterpart
+After the successful creation of the socket, you would normally use the ``bind(2)``
+and/or ``connect(2)`` system call to bind the socket to a CAN interface. After
+binding and/or connecting the socket, you can ``read(2)`` and ``write(2)`` from/to the
+socket or use ``send(2)``, ``sendto(2)``, ``sendmsg(2)`` and the ``recv*()`` counterpart
 operations on the socket as usual. There are also J1939 specific socket options
 described below.
 
-In order to send data, a bind(2) must have been successful. bind(2) assigns a
+In order to send data, a ``bind(2)`` must have been successful. ``bind(2)`` assigns a
 local address to a socket.
 
-Different from CAN is that the payload data is just the data that get send,
-without it's header info. The header info is derived from the sockaddr supplied
-to bind(2), connect(2), sendto(2) and recvfrom(2). A write(2) with size 4 will
+Different from CAN is that the payload data is just the data that get sends,
+without its header info. The header info is derived from the sockaddr supplied
+to ``bind(2)``, ``connect(2)``, ``sendto(2)`` and ``recvfrom(2)``. A ``write(2)`` with size 4 will
 result in a packet with 4 bytes.
 
 The sockaddr structure has extensions for use with J1939 as specified below:
@@ -180,47 +180,47 @@ The sockaddr structure has extensions for use with J1939 as specified below:
          } can_addr;
       }
 
-can_family & can_ifindex serve the same purpose as for other SocketCAN sockets.
+``can_family`` & ``can_ifindex`` serve the same purpose as for other SocketCAN sockets.
 
-can_addr.j1939.pgn specifies the PGN (max 0x3ffff). Individual bits are
+``can_addr.j1939.pgn`` specifies the PGN (max 0x3ffff). Individual bits are
 specified above.
 
-can_addr.j1939.name contains the 64-bit J1939 NAME.
+``can_addr.j1939.name`` contains the 64-bit J1939 NAME.
 
-can_addr.j1939.addr contains the address.
+``can_addr.j1939.addr`` contains the address.
 
-The bind(2) system call assigns the local address, i.e. the source address when
-sending packages. If a PGN during bind(2) is set, it's used as a RX filter.
-I.e.  only packets with a matching PGN are received. If an ADDR or NAME is set
+The ``bind(2)`` system call assigns the local address, i.e. the source address when
+sending packages. If a PGN during ``bind(2)`` is set, it's used as a RX filter.
+I.e. only packets with a matching PGN are received. If an ADDR or NAME is set
 it is used as a receive filter, too. It will match the destination NAME or ADDR
 of the incoming packet. The NAME filter will work only if appropriate Address
 Claiming for this name was done on the CAN bus and registered/cached by the
 kernel.
 
-On the other hand connect(2) assigns the remote address, i.e. the destination
-address. The PGN from connect(2) is used as the default PGN when sending
+On the other hand ``connect(2)`` assigns the remote address, i.e. the destination
+address. The PGN from ``connect(2)`` is used as the default PGN when sending
 packets. If ADDR or NAME is set it will be used as the default destination ADDR
-or NAME. Further a set ADDR or NAME during connect(2) is used as a receive
+or NAME. Further a set ADDR or NAME during ``connect(2)`` is used as a receive
 filter. It will match the source NAME or ADDR of the incoming packet.
 
-Both write(2) and send(2) will send a packet with local address from bind(2) and
-the remote address from connect(2). Use sendto(2) to overwrite the destination
+Both ``write(2)`` and ``send(2)`` will send a packet with local address from ``bind(2)`` and the
+remote address from ``connect(2)``. Use ``sendto(2)`` to overwrite the destination
 address.
 
-If can_addr.j1939.name is set (!= 0) the NAME is looked up by the kernel and
-the corresponding ADDR is used. If can_addr.j1939.name is not set (== 0),
-can_addr.j1939.addr is used.
+If ``can_addr.j1939.name`` is set (!= 0) the NAME is looked up by the kernel and
+the corresponding ADDR is used. If ``can_addr.j1939.name`` is not set (== 0),
+``can_addr.j1939.addr`` is used.
 
 When creating a socket, reasonable defaults are set. Some options can be
-modified with setsockopt(2) & getsockopt(2).
+modified with ``setsockopt(2)`` & ``getsockopt(2)``.
 
 RX path related options:
 
-- SO_J1939_FILTER - configure array of filters
-- SO_J1939_PROMISC - disable filters set by bind(2) and connect(2)
+- ``SO_J1939_FILTER`` - configure array of filters
+- ``SO_J1939_PROMISC`` - disable filters set by ``bind(2)`` and ``connect(2)``
 
 By default no broadcast packets can be send or received. To enable sending or
-receiving broadcast packets use the socket option SO_BROADCAST:
+receiving broadcast packets use the socket option ``SO_BROADCAST``:
 
 .. code-block:: C
 
@@ -261,26 +261,26 @@ The following diagram illustrates the RX path:
      +---------------------------+
 
 TX path related options:
-SO_J1939_SEND_PRIO - change default send priority for the socket
+``SO_J1939_SEND_PRIO`` - change default send priority for the socket
 
 Message Flags during send() and Related System Calls
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-send(2), sendto(2) and sendmsg(2) take a 'flags' argument. Currently
+``send(2)``, ``sendto(2)`` and ``sendmsg(2)`` take a 'flags' argument. Currently
 supported flags are:
 
-* MSG_DONTWAIT, i.e. non-blocking operation.
+* ``MSG_DONTWAIT``, i.e. non-blocking operation.
 
 recvmsg(2)
 ^^^^^^^^^^
 
-In most cases recvmsg(2) is needed if you want to extract more information than
-recvfrom(2) can provide. For example package priority and timestamp. The
+In most cases ``recvmsg(2)`` is needed if you want to extract more information than
+``recvfrom(2)`` can provide. For example package priority and timestamp. The
 Destination Address, name and packet priority (if applicable) are attached to
-the msghdr in the recvmsg(2) call. They can be extracted using cmsg(3) macros,
-with cmsg_level == SOL_J1939 && cmsg_type == SCM_J1939_DEST_ADDR,
-SCM_J1939_DEST_NAME or SCM_J1939_PRIO. The returned data is a uint8_t for
-priority and dst_addr, and uint64_t for dst_name.
+the msghdr in the ``recvmsg(2)`` call. They can be extracted using ``cmsg(3)`` macros,
+with ``cmsg_level == SOL_J1939 && cmsg_type == SCM_J1939_DEST_ADDR``,
+``SCM_J1939_DEST_NAME`` or ``SCM_J1939_PRIO``. The returned data is a ``uint8_t`` for
+``priority`` and ``dst_addr``, and ``uint64_t`` for ``dst_name``.
 
 .. code-block:: C
 
@@ -305,12 +305,12 @@ Dynamic Addressing
 
 Distinction has to be made between using the claimed address and doing an
 address claim. To use an already claimed address, one has to fill in the
-j1939.name member and provide it to bind(2). If the name had claimed an address
+``j1939.name`` member and provide it to ``bind(2)``. If the name had claimed an address
 earlier, all further messages being sent will use that address. And the
-j1939.addr member will be ignored.
+``j1939.addr`` member will be ignored.
 
 An exception on this is PGN 0x0ee00. This is the "Address Claim/Cannot Claim
-Address" message and the kernel will use the j1939.addr member for that PGN if
+Address" message and the kernel will use the ``j1939.addr`` member for that PGN if
 necessary.
 
 To claim an address following code example can be used:
@@ -371,12 +371,12 @@ NAME can send packets.
 
 If another ECU claims the address, the kernel will mark the NAME-SA expired.
 No socket bound to the NAME can send packets (other than address claims). To
-claim another address, some socket bound to NAME, must bind(2) again, but with
-only j1939.addr changed to the new SA, and must then send a valid address claim
+claim another address, some socket bound to NAME, must ``bind(2)`` again, but with
+only ``j1939.addr`` changed to the new SA, and must then send a valid address claim
 packet. This restarts the state machine in the kernel (and any other
 participant on the bus) for this NAME.
 
-can-utils also include the jacd tool, so it can be used as code example or as
+``can-utils`` also include the ``j1939acd`` tool, so it can be used as code example or as
 default Address Claiming daemon.
 
 Send Examples
@@ -403,8 +403,8 @@ Bind:
 
        bind(sock, (struct sockaddr *)&baddr, sizeof(baddr));
 
-Now, the socket 'sock' is bound to the SA 0x20. Since no connect(2) was called,
-at this point we can use only sendto(2) or sendmsg(2).
+Now, the socket 'sock' is bound to the SA 0x20. Since no ``connect(2)`` was called,
+at this point we can use only ``sendto(2)`` or ``sendmsg(2)``.
 
 Send:
 
@@ -414,8 +414,8 @@ Send:
                .can_family = AF_CAN,
                .can_addr.j1939 = {
                        .name = J1939_NO_NAME;
-                       .pgn = 0x30,
-                       .addr = 0x12300,
+                       .addr = 0x30,
+                       .pgn = 0x12300,
                },
        };
 
index d5c9320..2153776 100644 (file)
@@ -110,7 +110,7 @@ Q: I sent a patch and I'm wondering what happened to it?
 Q: How can I tell whether it got merged?
 A: Start by looking at the main patchworks queue for netdev:
 
-  http://patchwork.ozlabs.org/project/netdev/list/
+  https://patchwork.kernel.org/project/netdevbpf/list/
 
 The "State" field will tell you exactly where things are at with your
 patch.
@@ -152,7 +152,7 @@ networking subsystem, and then hands them off to Greg.
 
 There is a patchworks queue that you can see here:
 
-  http://patchwork.ozlabs.org/bundle/davem/stable/?state=*
+  https://patchwork.kernel.org/bundle/netdev/stable/?state=*
 
 It contains the patches which Dave has selected, but not yet handed off
 to Greg.  If Greg already has the patch, then it will be here:
index 2561060..b2f7ec7 100644 (file)
@@ -247,8 +247,8 @@ Some of the interface modes are described below:
     speeds (see below.)
 
 ``PHY_INTERFACE_MODE_2500BASEX``
-    This defines a variant of 1000BASE-X which is clocked 2.5 times faster,
-    than the 802.3 standard giving a fixed bit rate of 3.125Gbaud.
+    This defines a variant of 1000BASE-X which is clocked 2.5 times as fast
+    as the 802.3 standard, giving a fixed bit rate of 3.125Gbaud.
 
 ``PHY_INTERFACE_MODE_SGMII``
     This is used for Cisco SGMII, which is a modification of 1000BASE-X
index 8e15bc9..234abed 100644 (file)
@@ -175,5 +175,4 @@ The following structures are internal to the kernel, their members are
 translated to netlink attributes when dumped. Drivers must not overwrite
 the statistics they don't report with 0.
 
-.. kernel-doc:: include/linux/ethtool.h
-    :identifiers: ethtool_pause_stats
+- ethtool_pause_stats()
index 06f743b..3973556 100644 (file)
@@ -39,7 +39,7 @@ Procedure for submitting patches to the -stable tree
    submission guidelines as described in
    :ref:`Documentation/networking/netdev-FAQ.rst <netdev-FAQ>`
    after first checking the stable networking queue at
-   https://patchwork.ozlabs.org/bundle/davem/stable/?series=&submitter=&state=*&q=&archive=
+   https://patchwork.kernel.org/bundle/netdev/stable/?state=*
    to ensure the requested patch is not already queued up.
  - Security patches should not be handled (solely) by the -stable review
    process but should follow the procedures in
index 409dbc4..3e81eba 100644 (file)
@@ -15,6 +15,14 @@ else:
 import re
 from itertools import chain
 
+#
+# Python 2 lacks re.ASCII...
+#
+try:
+    ascii_p3 = re.ASCII
+except AttributeError:
+    ascii_p3 = 0
+
 #
 # Regex nastiness.  Of course.
 # Try to identify "function()" that's not already marked up some
@@ -22,22 +30,22 @@ from itertools import chain
 # :c:func: block (i.e. ":c:func:`mmap()`s" flakes out), so the last
 # bit tries to restrict matches to things that won't create trouble.
 #
-RE_function = re.compile(r'\b(([a-zA-Z_]\w+)\(\))', flags=re.ASCII)
+RE_function = re.compile(r'\b(([a-zA-Z_]\w+)\(\))', flags=ascii_p3)
 
 #
 # Sphinx 2 uses the same :c:type role for struct, union, enum and typedef
 #
 RE_generic_type = re.compile(r'\b(struct|union|enum|typedef)\s+([a-zA-Z_]\w+)',
-                             flags=re.ASCII)
+                             flags=ascii_p3)
 
 #
 # Sphinx 3 uses a different C role for each one of struct, union, enum and
 # typedef
 #
-RE_struct = re.compile(r'\b(struct)\s+([a-zA-Z_]\w+)', flags=re.ASCII)
-RE_union = re.compile(r'\b(union)\s+([a-zA-Z_]\w+)', flags=re.ASCII)
-RE_enum = re.compile(r'\b(enum)\s+([a-zA-Z_]\w+)', flags=re.ASCII)
-RE_typedef = re.compile(r'\b(typedef)\s+([a-zA-Z_]\w+)', flags=re.ASCII)
+RE_struct = re.compile(r'\b(struct)\s+([a-zA-Z_]\w+)', flags=ascii_p3)
+RE_union = re.compile(r'\b(union)\s+([a-zA-Z_]\w+)', flags=ascii_p3)
+RE_enum = re.compile(r'\b(enum)\s+([a-zA-Z_]\w+)', flags=ascii_p3)
+RE_typedef = re.compile(r'\b(typedef)\s+([a-zA-Z_]\w+)', flags=ascii_p3)
 
 #
 # Detects a reference to a documentation page of the form Documentation/... with
index 4f206ce..283d625 100644 (file)
@@ -46,7 +46,7 @@ Procedura per sottomettere patch per i sorgenti -stable
    :ref:`Documentation/translations/it_IT/networking/netdev-FAQ.rst <it_netdev-FAQ>`;
    ma solo dopo aver verificato al seguente indirizzo che la patch non sia
    già in coda:
-   https://patchwork.ozlabs.org/bundle/davem/stable/?series=&submitter=&state=*&q=&archive=
+   https://patchwork.kernel.org/bundle/netdev/stable/?state=*
  - Una patch di sicurezza non dovrebbero essere gestite (solamente) dal processo
    di revisione -stable, ma dovrebbe seguire le procedure descritte in
    :ref:`Documentation/translations/it_IT/admin-guide/security-bugs.rst <it_securitybugs>`.
index 69fc516..acd2cc2 100644 (file)
@@ -22,6 +22,7 @@ place where this information is gathered.
    spec_ctrl
    accelerators/ocxl
    ioctl/index
+   iommu
    media/index
 
 .. only::  subproject and html
index 36d5f1f..e00a66d 100644 (file)
@@ -6367,7 +6367,7 @@ accesses that would usually trigger a #GP by KVM into the guest will
 instead get bounced to user space through the KVM_EXIT_X86_RDMSR and
 KVM_EXIT_X86_WRMSR exit notifications.
 
-8.25 KVM_X86_SET_MSR_FILTER
+8.27 KVM_X86_SET_MSR_FILTER
 ---------------------------
 
 :Architectures: x86
@@ -6381,8 +6381,7 @@ In combination with KVM_CAP_X86_USER_SPACE_MSR, this allows user space to
 trap and emulate MSRs that are outside of the scope of KVM as well as
 limit the attack surface on KVM's MSR emulation code.
 
-
-8.26 KVM_CAP_ENFORCE_PV_CPUID
+8.28 KVM_CAP_ENFORCE_PV_CPUID
 -----------------------------
 
 Architectures: x86
index e52a129..450573a 100644 (file)
@@ -82,7 +82,8 @@ Default MMUv2-compatible layout::
   +------------------+
   | VMALLOC area     |  VMALLOC_START            0xc0000000  128MB - 64KB
   +------------------+  VMALLOC_END
-  | Cache aliasing   |  TLBTEMP_BASE_1           0xc7ff0000  DCACHE_WAY_SIZE
+  +------------------+
+  | Cache aliasing   |  TLBTEMP_BASE_1           0xc8000000  DCACHE_WAY_SIZE
   | remap area 1     |
   +------------------+
   | Cache aliasing   |  TLBTEMP_BASE_2                       DCACHE_WAY_SIZE
@@ -124,7 +125,8 @@ Default MMUv2-compatible layout::
   +------------------+
   | VMALLOC area     |  VMALLOC_START            0xa0000000  128MB - 64KB
   +------------------+  VMALLOC_END
-  | Cache aliasing   |  TLBTEMP_BASE_1           0xa7ff0000  DCACHE_WAY_SIZE
+  +------------------+
+  | Cache aliasing   |  TLBTEMP_BASE_1           0xa8000000  DCACHE_WAY_SIZE
   | remap area 1     |
   +------------------+
   | Cache aliasing   |  TLBTEMP_BASE_2                       DCACHE_WAY_SIZE
@@ -167,7 +169,8 @@ Default MMUv2-compatible layout::
   +------------------+
   | VMALLOC area     |  VMALLOC_START            0x90000000  128MB - 64KB
   +------------------+  VMALLOC_END
-  | Cache aliasing   |  TLBTEMP_BASE_1           0x97ff0000  DCACHE_WAY_SIZE
+  +------------------+
+  | Cache aliasing   |  TLBTEMP_BASE_1           0x98000000  DCACHE_WAY_SIZE
   | remap area 1     |
   +------------------+
   | Cache aliasing   |  TLBTEMP_BASE_2                       DCACHE_WAY_SIZE
index b516bb3..a008b70 100644 (file)
@@ -934,7 +934,7 @@ M:  Evan Quan <evan.quan@amd.com>
 L:     amd-gfx@lists.freedesktop.org
 S:     Supported
 T:     git git://people.freedesktop.org/~agd5f/linux
-F:     drivers/gpu/drm/amd/powerplay/
+F:     drivers/gpu/drm/amd/pm/powerplay/
 
 AMD SEATTLE DEVICE TREE SUPPORT
 M:     Brijesh Singh <brijeshkumar.singh@amd.com>
@@ -978,7 +978,7 @@ M:  Michael Hennerich <Michael.Hennerich@analog.com>
 L:     linux-iio@vger.kernel.org
 S:     Supported
 W:     http://ez.analog.com/community/linux-device-drivers
-F:     Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.txt
+F:     Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml
 F:     drivers/iio/adc/ad7768-1.c
 
 ANALOG DEVICES INC AD7780 DRIVER
@@ -1279,7 +1279,7 @@ M:        Igor Russkikh <irusskikh@marvell.com>
 L:     netdev@vger.kernel.org
 S:     Supported
 W:     https://www.marvell.com/
-Q:     http://patchwork.ozlabs.org/project/netdev/list/
+Q:     https://patchwork.kernel.org/project/netdevbpf/list/
 F:     Documentation/networking/device_drivers/ethernet/aquantia/atlantic.rst
 F:     drivers/net/ethernet/aquantia/atlantic/
 
@@ -1546,6 +1546,7 @@ F:        drivers/clk/sunxi/
 ARM/Allwinner sunXi SoC support
 M:     Maxime Ripard <mripard@kernel.org>
 M:     Chen-Yu Tsai <wens@csie.org>
+R:     Jernej Skrabec <jernej.skrabec@siol.net>
 L:     linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
 S:     Maintained
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/sunxi/linux.git
@@ -2374,7 +2375,7 @@ F:        drivers/i2c/busses/i2c-rk3x.c
 F:     sound/soc/rockchip/
 N:     rockchip
 
-ARM/SAMSUNG EXYNOS ARM ARCHITECTURES
+ARM/SAMSUNG S3C, S5P AND EXYNOS ARM ARCHITECTURES
 M:     Krzysztof Kozlowski <krzk@kernel.org>
 L:     linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
 L:     linux-samsung-soc@vger.kernel.org
@@ -2403,15 +2404,7 @@ N:       s3c2410
 N:     s3c64xx
 N:     s5pv210
 
-ARM/SAMSUNG MOBILE MACHINE SUPPORT
-M:     Kyungmin Park <kyungmin.park@samsung.com>
-L:     linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
-S:     Maintained
-F:     arch/arm/mach-s5pv210/
-
 ARM/SAMSUNG S5P SERIES 2D GRAPHICS ACCELERATION (G2D) SUPPORT
-M:     Kyungmin Park <kyungmin.park@samsung.com>
-M:     Kamil Debski <kamil@wypas.org>
 M:     Andrzej Hajda <a.hajda@samsung.com>
 L:     linux-arm-kernel@lists.infradead.org
 L:     linux-media@vger.kernel.org
@@ -2436,9 +2429,6 @@ S:        Maintained
 F:     drivers/media/platform/s5p-jpeg/
 
 ARM/SAMSUNG S5P SERIES Multi Format Codec (MFC) SUPPORT
-M:     Kyungmin Park <kyungmin.park@samsung.com>
-M:     Kamil Debski <kamil@wypas.org>
-M:     Jeongtae Park <jtp.park@samsung.com>
 M:     Andrzej Hajda <a.hajda@samsung.com>
 L:     linux-arm-kernel@lists.infradead.org
 L:     linux-media@vger.kernel.org
@@ -3243,10 +3233,10 @@ F:      drivers/iio/accel/bma400*
 BPF (Safe dynamic programs and tools)
 M:     Alexei Starovoitov <ast@kernel.org>
 M:     Daniel Borkmann <daniel@iogearbox.net>
+M:     Andrii Nakryiko <andrii@kernel.org>
 R:     Martin KaFai Lau <kafai@fb.com>
 R:     Song Liu <songliubraving@fb.com>
 R:     Yonghong Song <yhs@fb.com>
-R:     Andrii Nakryiko <andrii@kernel.org>
 R:     John Fastabend <john.fastabend@gmail.com>
 R:     KP Singh <kpsingh@chromium.org>
 L:     netdev@vger.kernel.org
@@ -3857,7 +3847,7 @@ M:        Roger Quadros <rogerq@ti.com>
 L:     linux-usb@vger.kernel.org
 S:     Maintained
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git
-F:     Documentation/devicetree/bindings/usb/cdns-usb3.txt
+F:     Documentation/devicetree/bindings/usb/cdns,usb3.yaml
 F:     drivers/usb/cdns3/
 
 CADET FM/AM RADIO RECEIVER DRIVER
@@ -4710,7 +4700,7 @@ T:        git git://linuxtv.org/anttip/media_tree.git
 F:     drivers/media/dvb-frontends/cxd2820r*
 
 CXGB3 ETHERNET DRIVER (CXGB3)
-M:     Vishal Kulkarni <vishal@chelsio.com>
+M:     Raju Rangoju <rajur@chelsio.com>
 L:     netdev@vger.kernel.org
 S:     Supported
 W:     http://www.chelsio.com
@@ -4742,7 +4732,7 @@ W:        http://www.chelsio.com
 F:     drivers/net/ethernet/chelsio/inline_crypto/
 
 CXGB4 ETHERNET DRIVER (CXGB4)
-M:     Vishal Kulkarni <vishal@chelsio.com>
+M:     Raju Rangoju <rajur@chelsio.com>
 L:     netdev@vger.kernel.org
 S:     Supported
 W:     http://www.chelsio.com
@@ -4764,7 +4754,7 @@ F:        drivers/infiniband/hw/cxgb4/
 F:     include/uapi/rdma/cxgb4-abi.h
 
 CXGB4VF ETHERNET DRIVER (CXGB4VF)
-M:     Vishal Kulkarni <vishal@gmail.com>
+M:     Raju Rangoju <rajur@chelsio.com>
 L:     netdev@vger.kernel.org
 S:     Supported
 W:     http://www.chelsio.com
@@ -6614,6 +6604,7 @@ Q:        http://patchwork.ozlabs.org/project/linux-ext4/list/
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git
 F:     Documentation/filesystems/ext4/
 F:     fs/ext4/
+F:     include/trace/events/ext4.h
 
 Extended Verification Module (EVM)
 M:     Mimi Zohar <zohar@linux.ibm.com>
@@ -7916,7 +7907,7 @@ HISILICON LPC BUS DRIVER
 M:     john.garry@huawei.com
 S:     Maintained
 W:     http://www.hisilicon.com
-F:     Documentation/devicetree/bindings/arm/hisilicon/hisilicon-low-pin-count.txt
+F:     Documentation/devicetree/bindings/arm/hisilicon/low-pin-count.yaml
 F:     drivers/bus/hisi_lpc.c
 
 HISILICON NETWORK SUBSYSTEM 3 DRIVER (HNS3)
@@ -8829,8 +8820,8 @@ S:        Supported
 W:     http://www.intel.com/support/feedback.htm
 W:     http://e1000.sourceforge.net/
 Q:     http://patchwork.ozlabs.org/project/intel-wired-lan/list/
-T:     git git://git.kernel.org/pub/scm/linux/kernel/git/jkirsher/net-queue.git
-T:     git git://git.kernel.org/pub/scm/linux/kernel/git/jkirsher/next-queue.git
+T:     git git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/net-queue.git
+T:     git git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue.git
 F:     Documentation/networking/device_drivers/ethernet/intel/
 F:     drivers/net/ethernet/intel/
 F:     drivers/net/ethernet/intel/*/
@@ -9171,6 +9162,7 @@ F:        include/linux/iomap.h
 
 IOMMU DRIVERS
 M:     Joerg Roedel <joro@8bytes.org>
+M:     Will Deacon <will@kernel.org>
 L:     iommu@lists.linux-foundation.org
 S:     Maintained
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git
@@ -9842,13 +9834,6 @@ S:       Maintained
 F:     arch/mips/lantiq
 F:     drivers/soc/lantiq
 
-LAPB module
-L:     linux-x25@vger.kernel.org
-S:     Orphan
-F:     Documentation/networking/lapb-module.rst
-F:     include/*/lapb.h
-F:     net/lapb/
-
 LASI 53c700 driver for PARISC
 M:     "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
 L:     linux-scsi@vger.kernel.org
@@ -11163,7 +11148,7 @@ F:      Documentation/devicetree/bindings/input/touchscreen/melfas_mip4.txt
 F:     drivers/input/touchscreen/melfas_mip4.c
 
 MELLANOX BLUEFIELD I2C DRIVER
-M:     Khalil Blaiech <kblaiech@mellanox.com>
+M:     Khalil Blaiech <kblaiech@nvidia.com>
 L:     linux-i2c@vger.kernel.org
 S:     Supported
 F:     drivers/i2c/busses/i2c-mlxbf.c
@@ -11173,7 +11158,7 @@ M:      Tariq Toukan <tariqt@nvidia.com>
 L:     netdev@vger.kernel.org
 S:     Supported
 W:     http://www.mellanox.com
-Q:     http://patchwork.ozlabs.org/project/netdev/list/
+Q:     https://patchwork.kernel.org/project/netdevbpf/list/
 F:     drivers/net/ethernet/mellanox/mlx4/en_*
 
 MELLANOX ETHERNET DRIVER (mlx5e)
@@ -11181,7 +11166,7 @@ M:      Saeed Mahameed <saeedm@nvidia.com>
 L:     netdev@vger.kernel.org
 S:     Supported
 W:     http://www.mellanox.com
-Q:     http://patchwork.ozlabs.org/project/netdev/list/
+Q:     https://patchwork.kernel.org/project/netdevbpf/list/
 F:     drivers/net/ethernet/mellanox/mlx5/core/en_*
 
 MELLANOX ETHERNET INNOVA DRIVERS
@@ -11189,7 +11174,7 @@ R:      Boris Pismenny <borisp@nvidia.com>
 L:     netdev@vger.kernel.org
 S:     Supported
 W:     http://www.mellanox.com
-Q:     http://patchwork.ozlabs.org/project/netdev/list/
+Q:     https://patchwork.kernel.org/project/netdevbpf/list/
 F:     drivers/net/ethernet/mellanox/mlx5/core/accel/*
 F:     drivers/net/ethernet/mellanox/mlx5/core/en_accel/*
 F:     drivers/net/ethernet/mellanox/mlx5/core/fpga/*
@@ -11201,7 +11186,7 @@ M:      Ido Schimmel <idosch@nvidia.com>
 L:     netdev@vger.kernel.org
 S:     Supported
 W:     http://www.mellanox.com
-Q:     http://patchwork.ozlabs.org/project/netdev/list/
+Q:     https://patchwork.kernel.org/project/netdevbpf/list/
 F:     drivers/net/ethernet/mellanox/mlxsw/
 F:     tools/testing/selftests/drivers/net/mlxsw/
 
@@ -11210,7 +11195,7 @@ M:      mlxsw@nvidia.com
 L:     netdev@vger.kernel.org
 S:     Supported
 W:     http://www.mellanox.com
-Q:     http://patchwork.ozlabs.org/project/netdev/list/
+Q:     https://patchwork.kernel.org/project/netdevbpf/list/
 F:     drivers/net/ethernet/mellanox/mlxfw/
 
 MELLANOX HARDWARE PLATFORM SUPPORT
@@ -11229,7 +11214,7 @@ L:      netdev@vger.kernel.org
 L:     linux-rdma@vger.kernel.org
 S:     Supported
 W:     http://www.mellanox.com
-Q:     http://patchwork.ozlabs.org/project/netdev/list/
+Q:     https://patchwork.kernel.org/project/netdevbpf/list/
 F:     drivers/net/ethernet/mellanox/mlx4/
 F:     include/linux/mlx4/
 
@@ -11250,7 +11235,7 @@ L:      netdev@vger.kernel.org
 L:     linux-rdma@vger.kernel.org
 S:     Supported
 W:     http://www.mellanox.com
-Q:     http://patchwork.ozlabs.org/project/netdev/list/
+Q:     https://patchwork.kernel.org/project/netdevbpf/list/
 F:     Documentation/networking/device_drivers/ethernet/mellanox/
 F:     drivers/net/ethernet/mellanox/mlx5/core/
 F:     include/linux/mlx5/
@@ -12130,7 +12115,7 @@ M:      Jakub Kicinski <kuba@kernel.org>
 L:     netdev@vger.kernel.org
 S:     Maintained
 W:     http://www.linuxfoundation.org/en/Net
-Q:     http://patchwork.ozlabs.org/project/netdev/list/
+Q:     https://patchwork.kernel.org/project/netdevbpf/list/
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git
 F:     Documentation/devicetree/bindings/net/
@@ -12175,7 +12160,7 @@ M:      Jakub Kicinski <kuba@kernel.org>
 L:     netdev@vger.kernel.org
 S:     Maintained
 W:     http://www.linuxfoundation.org/en/Net
-Q:     http://patchwork.ozlabs.org/project/netdev/list/
+Q:     https://patchwork.kernel.org/project/netdevbpf/list/
 B:     mailto:netdev@vger.kernel.org
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git
@@ -14210,7 +14195,6 @@ F:      drivers/media/usb/pwc/*
 F:     include/trace/events/pwc.h
 
 PWM FAN DRIVER
-M:     Kamil Debski <kamil@wypas.org>
 M:     Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
 L:     linux-hwmon@vger.kernel.org
 S:     Supported
@@ -14527,6 +14511,14 @@ F:     Documentation/devicetree/bindings/mailbox/qcom-ipcc.yaml
 F:     drivers/mailbox/qcom-ipcc.c
 F:     include/dt-bindings/mailbox/qcom-ipcc.h
 
+QUALCOMM IPQ4019 VQMMC REGULATOR DRIVER
+M:     Robert Marko <robert.marko@sartura.hr>
+M:     Luka Perkov <luka.perkov@sartura.hr>
+L:     linux-arm-msm@vger.kernel.org
+S:     Maintained
+F:     Documentation/devicetree/bindings/regulator/vqmmc-ipq4019-regulator.yaml
+F:     drivers/regulator/vqmmc-ipq4019-regulator.c
+
 QUALCOMM RMNET DRIVER
 M:     Subash Abhinov Kasiviswanathan <subashab@codeaurora.org>
 M:     Sean Tranchetti <stranche@codeaurora.org>
@@ -14882,7 +14874,6 @@ RENESAS ETHERNET DRIVERS
 R:     Sergei Shtylyov <sergei.shtylyov@gmail.com>
 L:     netdev@vger.kernel.org
 L:     linux-renesas-soc@vger.kernel.org
-F:     Documentation/devicetree/bindings/net/renesas,*.txt
 F:     Documentation/devicetree/bindings/net/renesas,*.yaml
 F:     drivers/net/ethernet/renesas/
 F:     include/linux/sh_eth.h
@@ -15239,7 +15230,6 @@ F:      drivers/iommu/s390-iommu.c
 S390 IUCV NETWORK LAYER
 M:     Julian Wiedmann <jwi@linux.ibm.com>
 M:     Karsten Graul <kgraul@linux.ibm.com>
-M:     Ursula Braun <ubraun@linux.ibm.com>
 L:     linux-s390@vger.kernel.org
 S:     Supported
 W:     http://www.ibm.com/developerworks/linux/linux390/
@@ -15250,7 +15240,6 @@ F:      net/iucv/
 S390 NETWORK DRIVERS
 M:     Julian Wiedmann <jwi@linux.ibm.com>
 M:     Karsten Graul <kgraul@linux.ibm.com>
-M:     Ursula Braun <ubraun@linux.ibm.com>
 L:     linux-s390@vger.kernel.org
 S:     Supported
 W:     http://www.ibm.com/developerworks/linux/linux390/
@@ -15419,14 +15408,12 @@ F:    Documentation/devicetree/bindings/net/nfc/samsung,s3fwrn5.yaml
 F:     drivers/nfc/s3fwrn5
 
 SAMSUNG S5C73M3 CAMERA DRIVER
-M:     Kyungmin Park <kyungmin.park@samsung.com>
 M:     Andrzej Hajda <a.hajda@samsung.com>
 L:     linux-media@vger.kernel.org
 S:     Supported
 F:     drivers/media/i2c/s5c73m3/*
 
 SAMSUNG S5K5BAF CAMERA DRIVER
-M:     Kyungmin Park <kyungmin.park@samsung.com>
 M:     Andrzej Hajda <a.hajda@samsung.com>
 L:     linux-media@vger.kernel.org
 S:     Supported
@@ -15444,7 +15431,6 @@ F:      Documentation/devicetree/bindings/crypto/samsung-sss.yaml
 F:     drivers/crypto/s5p-sss.c
 
 SAMSUNG S5P/EXYNOS4 SOC SERIES CAMERA SUBSYSTEM DRIVERS
-M:     Kyungmin Park <kyungmin.park@samsung.com>
 M:     Sylwester Nawrocki <s.nawrocki@samsung.com>
 L:     linux-media@vger.kernel.org
 S:     Supported
@@ -15492,7 +15478,6 @@ T:      git https://github.com/lmajewski/linux-samsung-thermal.git
 F:     drivers/thermal/samsung/
 
 SAMSUNG USB2 PHY DRIVER
-M:     Kamil Debski <kamil@wypas.org>
 M:     Sylwester Nawrocki <s.nawrocki@samsung.com>
 L:     linux-kernel@vger.kernel.org
 S:     Supported
@@ -15821,7 +15806,6 @@ S:      Maintained
 F:     drivers/misc/sgi-xp/
 
 SHARED MEMORY COMMUNICATIONS (SMC) SOCKETS
-M:     Ursula Braun <ubraun@linux.ibm.com>
 M:     Karsten Graul <kgraul@linux.ibm.com>
 L:     linux-s390@vger.kernel.org
 S:     Supported
@@ -18083,7 +18067,7 @@ M:      Yu Chen <chenyu56@huawei.com>
 M:     Binghui Wang <wangbinghui@hisilicon.com>
 L:     linux-usb@vger.kernel.org
 S:     Maintained
-F:     Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt
+F:     Documentation/devicetree/bindings/phy/hisilicon,hi3660-usb3.yaml
 F:     drivers/phy/hisilicon/phy-hi3660-usb3.c
 
 USB ISP116X DRIVER
@@ -18168,6 +18152,14 @@ L:     linux-usb@vger.kernel.org
 S:     Supported
 F:     drivers/usb/class/usblp.c
 
+USB RAW GADGET DRIVER
+R:     Andrey Konovalov <andreyknvl@gmail.com>
+L:     linux-usb@vger.kernel.org
+S:     Maintained
+F:     Documentation/usb/raw-gadget.rst
+F:     drivers/usb/gadget/legacy/raw_gadget.c
+F:     include/uapi/linux/usb/raw_gadget.h
+
 USB QMI WWAN NETWORK DRIVER
 M:     Bjørn Mork <bjorn@mork.no>
 L:     netdev@vger.kernel.org
@@ -18993,12 +18985,18 @@ L:    linux-kernel@vger.kernel.org
 S:     Maintained
 N:     axp[128]
 
-X.25 NETWORK LAYER
-M:     Andrew Hendry <andrew.hendry@gmail.com>
+X.25 STACK
+M:     Martin Schiller <ms@dev.tdt.de>
 L:     linux-x25@vger.kernel.org
-S:     Odd Fixes
+S:     Maintained
+F:     Documentation/networking/lapb-module.rst
 F:     Documentation/networking/x25*
+F:     drivers/net/wan/hdlc_x25.c
+F:     drivers/net/wan/lapbether.c
+F:     include/*/lapb.h
 F:     include/net/x25*
+F:     include/uapi/linux/x25.h
+F:     net/lapb/
 F:     net/x25/
 
 X86 ARCHITECTURE (32-BIT AND 64-BIT)
index 9e7fd6a..ed081e3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
 VERSION = 5
 PATCHLEVEL = 10
 SUBLEVEL = 0
-EXTRAVERSION = -rc2
+EXTRAVERSION = -rc5
 NAME = Kleptomaniac Octopus
 
 # *DOCUMENTATION*
index c6606f4..fb98440 100644 (file)
@@ -243,10 +243,8 @@ static inline int constant_fls(unsigned int x)
                x <<= 2;
                r -= 2;
        }
-       if (!(x & 0x80000000u)) {
-               x <<= 1;
+       if (!(x & 0x80000000u))
                r -= 1;
-       }
        return r;
 }
 
index 17fd1ed..9152782 100644 (file)
        sr      r5, [ARC_REG_LPB_CTRL]
 1:
 #endif /* CONFIG_ARC_LPB_DISABLE */
-#endif
+
+       /* On HSDK, CCMs need to remapped super early */
+#ifdef CONFIG_ARC_SOC_HSDK
+       mov     r6, 0x60000000
+       lr      r5, [ARC_REG_ICCM_BUILD]
+       breq    r5, 0, 1f
+       sr      r6, [ARC_REG_AUX_ICCM]
+1:
+       lr      r5, [ARC_REG_DCCM_BUILD]
+       breq    r5, 0, 2f
+       sr      r6, [ARC_REG_AUX_DCCM]
+2:
+#endif /* CONFIG_ARC_SOC_HSDK */
+
+#endif /* CONFIG_ISA_ARCV2 */
+
        ; Config DSP_CTRL properly, so kernel may use integer multiply,
        ; multiply-accumulate, and divide operations
        DSP_EARLY_INIT
index feba91c..f73da20 100644 (file)
 
 #ifdef CONFIG_ARC_DW2_UNWIND
 
-static void seed_unwind_frame_info(struct task_struct *tsk,
-                                  struct pt_regs *regs,
-                                  struct unwind_frame_info *frame_info)
+static int
+seed_unwind_frame_info(struct task_struct *tsk, struct pt_regs *regs,
+                      struct unwind_frame_info *frame_info)
 {
-       /*
-        * synchronous unwinding (e.g. dump_stack)
-        *  - uses current values of SP and friends
-        */
-       if (tsk == NULL && regs == NULL) {
+       if (regs) {
+               /*
+                * Asynchronous unwinding of intr/exception
+                *  - Just uses the pt_regs passed
+                */
+               frame_info->task = tsk;
+
+               frame_info->regs.r27 = regs->fp;
+               frame_info->regs.r28 = regs->sp;
+               frame_info->regs.r31 = regs->blink;
+               frame_info->regs.r63 = regs->ret;
+               frame_info->call_frame = 0;
+       } else if (tsk == NULL || tsk == current) {
+               /*
+                * synchronous unwinding (e.g. dump_stack)
+                *  - uses current values of SP and friends
+                */
                unsigned long fp, sp, blink, ret;
                frame_info->task = current;
 
@@ -63,13 +75,17 @@ static void seed_unwind_frame_info(struct task_struct *tsk,
                frame_info->regs.r31 = blink;
                frame_info->regs.r63 = ret;
                frame_info->call_frame = 0;
-       } else if (regs == NULL) {
+       } else {
                /*
-                * Asynchronous unwinding of sleeping task
-                *  - Gets SP etc from task's pt_regs (saved bottom of kernel
-                *    mode stack of task)
+                * Asynchronous unwinding of a likely sleeping task
+                *  - first ensure it is actually sleeping
+                *  - if so, it will be in __switch_to, kernel mode SP of task
+                *    is safe-kept and BLINK at a well known location in there
                 */
 
+               if (tsk->state == TASK_RUNNING)
+                       return -1;
+
                frame_info->task = tsk;
 
                frame_info->regs.r27 = TSK_K_FP(tsk);
@@ -90,19 +106,8 @@ static void seed_unwind_frame_info(struct task_struct *tsk,
                frame_info->regs.r28 += 60;
                frame_info->call_frame = 0;
 
-       } else {
-               /*
-                * Asynchronous unwinding of intr/exception
-                *  - Just uses the pt_regs passed
-                */
-               frame_info->task = tsk;
-
-               frame_info->regs.r27 = regs->fp;
-               frame_info->regs.r28 = regs->sp;
-               frame_info->regs.r31 = regs->blink;
-               frame_info->regs.r63 = regs->ret;
-               frame_info->call_frame = 0;
        }
+       return 0;
 }
 
 #endif
@@ -112,11 +117,12 @@ arc_unwind_core(struct task_struct *tsk, struct pt_regs *regs,
                int (*consumer_fn) (unsigned int, void *), void *arg)
 {
 #ifdef CONFIG_ARC_DW2_UNWIND
-       int ret = 0;
+       int ret = 0, cnt = 0;
        unsigned int address;
        struct unwind_frame_info frame_info;
 
-       seed_unwind_frame_info(tsk, regs, &frame_info);
+       if (seed_unwind_frame_info(tsk, regs, &frame_info))
+               return 0;
 
        while (1) {
                address = UNW_PC(&frame_info);
@@ -132,6 +138,11 @@ arc_unwind_core(struct task_struct *tsk, struct pt_regs *regs,
                        break;
 
                frame_info.regs.r63 = frame_info.regs.r31;
+
+               if (cnt++ > 128) {
+                       printk("unwinder looping too long, aborting !\n");
+                       return 0;
+               }
        }
 
        return address;         /* return the last address it saw */
index c340acd..9bb3c24 100644 (file)
  *  -Changes related to MMU v2 (Rel 4.8)
  *
  * Vineetg: Aug 29th 2008
- *  -In TLB Flush operations (Metal Fix MMU) there is a explict command to
+ *  -In TLB Flush operations (Metal Fix MMU) there is a explicit command to
  *    flush Micro-TLBS. If TLB Index Reg is invalid prior to TLBIVUTLB cmd,
  *    it fails. Thus need to load it with ANY valid value before invoking
  *    TLBIVUTLB cmd
  *
  * Vineetg: Aug 21th 2008:
  *  -Reduced the duration of IRQ lockouts in TLB Flush routines
- *  -Multiple copies of TLB erase code seperated into a "single" function
+ *  -Multiple copies of TLB erase code separated into a "single" function
  *  -In TLB Flush routines, interrupt disabling moved UP to retrieve ASID
  *       in interrupt-safe region.
  *
@@ -66,7 +66,7 @@
  *
  * Although J-TLB is 2 way set assoc, ARC700 caches J-TLB into uTLBS which has
  * much higher associativity. u-D-TLB is 8 ways, u-I-TLB is 4 ways.
- * Given this, the thrasing problem should never happen because once the 3
+ * Given this, the thrashing problem should never happen because once the 3
  * J-TLB entries are created (even though 3rd will knock out one of the prev
  * two), the u-D-TLB and u-I-TLB will have what is required to accomplish memcpy
  *
@@ -127,7 +127,7 @@ static void utlb_invalidate(void)
         * There was however an obscure hardware bug, where uTLB flush would
         * fail when a prior probe for J-TLB (both totally unrelated) would
         * return lkup err - because the entry didn't exist in MMU.
-        * The Workround was to set Index reg with some valid value, prior to
+        * The Workaround was to set Index reg with some valid value, prior to
         * flush. This was fixed in MMU v3
         */
        unsigned int idx;
@@ -272,7 +272,7 @@ noinline void local_flush_tlb_all(void)
 }
 
 /*
- * Flush the entrie MM for userland. The fastest way is to move to Next ASID
+ * Flush the entire MM for userland. The fastest way is to move to Next ASID
  */
 noinline void local_flush_tlb_mm(struct mm_struct *mm)
 {
@@ -303,7 +303,7 @@ noinline void local_flush_tlb_mm(struct mm_struct *mm)
  * Difference between this and Kernel Range Flush is
  *  -Here the fastest way (if range is too large) is to move to next ASID
  *      without doing any explicit Shootdown
- *  -In case of kernel Flush, entry has to be shot down explictly
+ *  -In case of kernel Flush, entry has to be shot down explicitly
  */
 void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
                           unsigned long end)
@@ -620,7 +620,7 @@ void update_mmu_cache(struct vm_area_struct *vma, unsigned long vaddr_unaligned,
  * Super Page size is configurable in hardware (4K to 16M), but fixed once
  * RTL builds.
  *
- * The exact THP size a Linx configuration will support is a function of:
+ * The exact THP size a Linux configuration will support is a function of:
  *  - MMU page size (typical 8K, RTL fixed)
  *  - software page walker address split between PGD:PTE:PFN (typical
  *    11:8:13, but can be changed with 1 line)
@@ -698,7 +698,7 @@ void local_flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start,
 
 #endif
 
-/* Read the Cache Build Confuration Registers, Decode them and save into
+/* Read the Cache Build Configuration Registers, Decode them and save into
  * the cpuinfo structure for later use.
  * No Validation is done here, simply read/convert the BCRs
  */
@@ -803,13 +803,13 @@ void arc_mmu_init(void)
        pr_info("%s", arc_mmu_mumbojumbo(0, str, sizeof(str)));
 
        /*
-        * Can't be done in processor.h due to header include depenedencies
+        * Can't be done in processor.h due to header include dependencies
         */
        BUILD_BUG_ON(!IS_ALIGNED((CONFIG_ARC_KVADDR_SIZE << 20), PMD_SIZE));
 
        /*
         * stack top size sanity check,
-        * Can't be done in processor.h due to header include depenedencies
+        * Can't be done in processor.h due to header include dependencies
         */
        BUILD_BUG_ON(!IS_ALIGNED(STACK_TOP, PMD_SIZE));
 
@@ -881,7 +881,7 @@ void arc_mmu_init(void)
  *      the duplicate one.
  * -Knob to be verbose abt it.(TODO: hook them up to debugfs)
  */
-volatile int dup_pd_silent; /* Be slient abt it or complain (default) */
+volatile int dup_pd_silent; /* Be silent abt it or complain (default) */
 
 void do_tlb_overlap_fault(unsigned long cause, unsigned long address,
                          struct pt_regs *regs)
@@ -948,7 +948,7 @@ void do_tlb_overlap_fault(unsigned long cause, unsigned long address,
 
 /***********************************************************************
  * Diagnostic Routines
- *  -Called from Low Level TLB Hanlders if things don;t look good
+ *  -Called from Low Level TLB Handlers if things don;t look good
  **********************************************************************/
 
 #ifdef CONFIG_ARC_DBG_TLB_PARANOIA
index 0b63fc0..b3ea1fa 100644 (file)
@@ -17,22 +17,6 @@ int arc_hsdk_axi_dmac_coherent __section(".data") = 0;
 
 #define ARC_CCM_UNUSED_ADDR    0x60000000
 
-static void __init hsdk_init_per_cpu(unsigned int cpu)
-{
-       /*
-        * By default ICCM is mapped to 0x7z while this area is used for
-        * kernel virtual mappings, so move it to currently unused area.
-        */
-       if (cpuinfo_arc700[cpu].iccm.sz)
-               write_aux_reg(ARC_REG_AUX_ICCM, ARC_CCM_UNUSED_ADDR);
-
-       /*
-        * By default DCCM is mapped to 0x8z while this area is used by kernel,
-        * so move it to currently unused area.
-        */
-       if (cpuinfo_arc700[cpu].dccm.sz)
-               write_aux_reg(ARC_REG_AUX_DCCM, ARC_CCM_UNUSED_ADDR);
-}
 
 #define ARC_PERIPHERAL_BASE    0xf0000000
 #define CREG_BASE              (ARC_PERIPHERAL_BASE + 0x1000)
@@ -339,5 +323,4 @@ static const char *hsdk_compat[] __initconst = {
 MACHINE_START(SIMULATION, "hsdk")
        .dt_compat      = hsdk_compat,
        .init_early     = hsdk_init_early,
-       .init_per_cpu   = hsdk_init_per_cpu,
 MACHINE_END
index 2e04ec5..caa2732 100644 (file)
@@ -1472,6 +1472,9 @@ ENTRY(efi_enter_kernel)
                @ issued from HYP mode take us to the correct handler code. We
                @ will disable the MMU before jumping to the kernel proper.
                @
+ ARM(          bic     r1, r1, #(1 << 30)      ) @ clear HSCTLR.TE
+ THUMB(                orr     r1, r1, #(1 << 30)      ) @ set HSCTLR.TE
+               mcr     p15, 4, r1, c1, c0, 0
                adr     r0, __hyp_reentry_vectors
                mcr     p15, 4, r0, c12, c0, 0  @ set HYP vector base (HVBAR)
                isb
index ab291ce..2983e91 100644 (file)
 };
 
 &clock {
-       clocks = <&clock CLK_XUSBXTI>;
        assigned-clocks = <&clock CLK_FOUT_EPLL>;
        assigned-clock-rates = <45158401>;
 };
index 878e89c..4ea5c23 100644 (file)
@@ -59,7 +59,7 @@
                                MX50_PAD_CSPI_MISO__CSPI_MISO           0x00
                                MX50_PAD_CSPI_MOSI__CSPI_MOSI           0x00
                                MX50_PAD_CSPI_SS0__GPIO4_11             0xc4
-                               MX50_PAD_ECSPI1_MOSI__CSPI_SS1          0xf4
+                               MX50_PAD_ECSPI1_MOSI__GPIO4_13          0x84
                        >;
                };
 
index d112b50..b4605ed 100644 (file)
                #size-cells = <0>;
 
                /* Microchip KSZ9031RNX PHY */
-               rgmii_phy: ethernet-phy@4 {
-                       reg = <4>;
+               rgmii_phy: ethernet-phy@0 {
+                       reg = <0>;
                        interrupts-extended = <&gpio1 28 IRQ_TYPE_LEVEL_LOW>;
                        reset-gpios = <&gpio1 25 GPIO_ACTIVE_LOW>;
                        reset-assert-us = <10000>;
index 828dd20..d07d8f8 100644 (file)
@@ -98,7 +98,7 @@
 &fec {
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_enet>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
        status = "okay";
 };
 
index 5dff24e..8456f17 100644 (file)
                        linux,code = <KEY_A>;
                        gpios = <&gpiof 3 GPIO_ACTIVE_LOW>;
                };
+
+               /*
+                * The EXTi IRQ line 0 is shared with PMIC,
+                * so mark this as polled GPIO key.
+                */
+               button-2 {
+                       label = "TA3-GPIO-C";
+                       linux,code = <KEY_C>;
+                       gpios = <&gpiog 0 GPIO_ACTIVE_LOW>;
+               };
        };
 
        gpio-keys {
                        wakeup-source;
                };
 
-               button-2 {
-                       label = "TA3-GPIO-C";
-                       linux,code = <KEY_C>;
-                       gpios = <&gpioi 11 GPIO_ACTIVE_LOW>;
-                       wakeup-source;
-               };
-
                button-3 {
                        label = "TA4-GPIO-D";
                        linux,code = <KEY_D>;
@@ -79,7 +82,7 @@
 
                led-0 {
                        label = "green:led5";
-                       gpios = <&gpiog 2 GPIO_ACTIVE_HIGH>;
+                       gpios = <&gpioc 6 GPIO_ACTIVE_HIGH>;
                        default-state = "off";
                };
 
index b4b52cf..f796a61 100644 (file)
@@ -68,6 +68,7 @@
                gpio = <&gpiog 3 GPIO_ACTIVE_LOW>;
                regulator-always-on;
                regulator-boot-on;
+               vin-supply = <&vdd>;
        };
 };
 
 
                        vdda: ldo1 {
                                regulator-name = "vdda";
+                               regulator-always-on;
                                regulator-min-microvolt = <2900000>;
                                regulator-max-microvolt = <2900000>;
                                interrupts = <IT_CURLIM_LDO1 0>;
index 04fbb32..803eb8b 100644 (file)
        };
 };
 
+&dts {
+       status = "okay";
+};
+
 &i2c4 {
        pinctrl-names = "default";
        pinctrl-0 = <&i2c4_pins_a>;
index 049e6ab..73de34a 100644 (file)
        pinctrl-names = "default";
        pinctrl-0 = <&gmac_rgmii_pins>;
        phy-handle = <&phy1>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
        status = "okay";
 };
 
index 32d5d45..8945dbb 100644 (file)
        pinctrl-names = "default";
        pinctrl-0 = <&gmac_rgmii_pins>;
        phy-handle = <&phy1>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
        phy-supply = <&reg_gmac_3v3>;
        status = "okay";
 };
index 8c8dee6..9109ca0 100644 (file)
        pinctrl-names = "default";
        pinctrl-0 = <&gmac_rgmii_pins>;
        phy-handle = <&phy1>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
        status = "okay";
 };
 
index 9d34eab..431f702 100644 (file)
        pinctrl-0 = <&emac_rgmii_pins>;
        phy-supply = <&reg_sw>;
        phy-handle = <&rgmii_phy>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
        allwinner,rx-delay-ps = <700>;
        allwinner,tx-delay-ps = <700>;
        status = "okay";
index d9be511..d8326a5 100644 (file)
        pinctrl-0 = <&emac_rgmii_pins>;
        phy-supply = <&reg_dldo4>;
        phy-handle = <&rgmii_phy>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
        status = "okay";
 };
 
index 71fb732..babf4cf 100644 (file)
        };
 };
 
-&emac {
-       /* LEDs changed to active high on the plus */
-       /delete-property/ allwinner,leds-active-low;
-};
-
 &mmc1 {
        vmmc-supply = <&reg_vcc3v3>;
        bus-width = <4>;
index 6dbf7b2..b6ca45d 100644 (file)
@@ -67,7 +67,7 @@
        pinctrl-0 = <&emac_rgmii_pins>;
        phy-supply = <&reg_gmac_3v3>;
        phy-handle = <&ext_rgmii_phy>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
        status = "okay";
 };
 
index 2fc62ef..a6a1087 100644 (file)
        pinctrl-names = "default";
        pinctrl-0 = <&gmac_rgmii_pins>;
        phy-handle = <&phy1>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
        phy-supply = <&reg_dc1sw>;
        status = "okay";
 };
index d3b337b..484b93d 100644 (file)
        pinctrl-names = "default";
        pinctrl-0 = <&gmac_rgmii_pins>;
        phy-handle = <&phy1>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
        phy-supply = <&reg_cldo1>;
        status = "okay";
 };
index bbc6335..5c3580d 100644 (file)
        pinctrl-names = "default";
        pinctrl-0 = <&gmac_rgmii_pins>;
        phy-handle = <&phy1>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
        phy-supply = <&reg_cldo1>;
        status = "okay";
 };
index 39263e7..8e5cb3b 100644 (file)
        pinctrl-0 = <&emac_rgmii_pins>;
        phy-supply = <&reg_gmac_3v3>;
        phy-handle = <&ext_rgmii_phy>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
 
        status = "okay";
 };
index e500911..6f1e0f0 100644 (file)
        };
 };
 
+&mdio1 {
+       clock-frequency = <5000000>;
+};
 
 &iomuxc {
        pinctrl_gpio_e6185_eeprom_sel: pinctrl-gpio-e6185-eeprom-spi0 {
index 213607a..e26a278 100644 (file)
@@ -44,20 +44,20 @@ int kprobe_exceptions_notify(struct notifier_block *self,
                             unsigned long val, void *data);
 
 /* optinsn template addresses */
-extern __visible kprobe_opcode_t optprobe_template_entry;
-extern __visible kprobe_opcode_t optprobe_template_val;
-extern __visible kprobe_opcode_t optprobe_template_call;
-extern __visible kprobe_opcode_t optprobe_template_end;
-extern __visible kprobe_opcode_t optprobe_template_sub_sp;
-extern __visible kprobe_opcode_t optprobe_template_add_sp;
-extern __visible kprobe_opcode_t optprobe_template_restore_begin;
-extern __visible kprobe_opcode_t optprobe_template_restore_orig_insn;
-extern __visible kprobe_opcode_t optprobe_template_restore_end;
+extern __visible kprobe_opcode_t optprobe_template_entry[];
+extern __visible kprobe_opcode_t optprobe_template_val[];
+extern __visible kprobe_opcode_t optprobe_template_call[];
+extern __visible kprobe_opcode_t optprobe_template_end[];
+extern __visible kprobe_opcode_t optprobe_template_sub_sp[];
+extern __visible kprobe_opcode_t optprobe_template_add_sp[];
+extern __visible kprobe_opcode_t optprobe_template_restore_begin[];
+extern __visible kprobe_opcode_t optprobe_template_restore_orig_insn[];
+extern __visible kprobe_opcode_t optprobe_template_restore_end[];
 
 #define MAX_OPTIMIZED_LENGTH   4
 #define MAX_OPTINSN_SIZE                               \
-       ((unsigned long)&optprobe_template_end -        \
-        (unsigned long)&optprobe_template_entry)
+       ((unsigned long)optprobe_template_end - \
+        (unsigned long)optprobe_template_entry)
 #define RELATIVEJUMP_SIZE      4
 
 struct arch_optimized_insn {
index 05fe92a..0529f90 100644 (file)
@@ -32,8 +32,7 @@ u64 perf_reg_abi(struct task_struct *task)
 }
 
 void perf_get_regs_user(struct perf_regs *regs_user,
-                       struct pt_regs *regs,
-                       struct pt_regs *regs_user_copy)
+                       struct pt_regs *regs)
 {
        regs_user->regs = task_pt_regs(current);
        regs_user->abi = perf_reg_abi(current);
index d57112a..c23dbf8 100644 (file)
@@ -354,8 +354,8 @@ static void __init free_highpages(void)
        /* set highmem page free */
        for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE,
                                &range_start, &range_end, NULL) {
-               unsigned long start = PHYS_PFN(range_start);
-               unsigned long end = PHYS_PFN(range_end);
+               unsigned long start = PFN_UP(range_start);
+               unsigned long end = PFN_DOWN(range_end);
 
                /* Ignore complete lowmem entries */
                if (end <= max_low)
index 7a449df..c781801 100644 (file)
@@ -85,21 +85,21 @@ asm (
                        "optprobe_template_end:\n");
 
 #define TMPL_VAL_IDX \
-       ((unsigned long *)&optprobe_template_val - (unsigned long *)&optprobe_template_entry)
+       ((unsigned long *)optprobe_template_val - (unsigned long *)optprobe_template_entry)
 #define TMPL_CALL_IDX \
-       ((unsigned long *)&optprobe_template_call - (unsigned long *)&optprobe_template_entry)
+       ((unsigned long *)optprobe_template_call - (unsigned long *)optprobe_template_entry)
 #define TMPL_END_IDX \
-       ((unsigned long *)&optprobe_template_end - (unsigned long *)&optprobe_template_entry)
+       ((unsigned long *)optprobe_template_end - (unsigned long *)optprobe_template_entry)
 #define TMPL_ADD_SP \
-       ((unsigned long *)&optprobe_template_add_sp - (unsigned long *)&optprobe_template_entry)
+       ((unsigned long *)optprobe_template_add_sp - (unsigned long *)optprobe_template_entry)
 #define TMPL_SUB_SP \
-       ((unsigned long *)&optprobe_template_sub_sp - (unsigned long *)&optprobe_template_entry)
+       ((unsigned long *)optprobe_template_sub_sp - (unsigned long *)optprobe_template_entry)
 #define TMPL_RESTORE_BEGIN \
-       ((unsigned long *)&optprobe_template_restore_begin - (unsigned long *)&optprobe_template_entry)
+       ((unsigned long *)optprobe_template_restore_begin - (unsigned long *)optprobe_template_entry)
 #define TMPL_RESTORE_ORIGN_INSN \
-       ((unsigned long *)&optprobe_template_restore_orig_insn - (unsigned long *)&optprobe_template_entry)
+       ((unsigned long *)optprobe_template_restore_orig_insn - (unsigned long *)optprobe_template_entry)
 #define TMPL_RESTORE_END \
-       ((unsigned long *)&optprobe_template_restore_end - (unsigned long *)&optprobe_template_entry)
+       ((unsigned long *)optprobe_template_restore_end - (unsigned long *)optprobe_template_entry)
 
 /*
  * ARM can always optimize an instruction when using ARM ISA, except
@@ -234,7 +234,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op, struct kprobe *or
        }
 
        /* Copy arch-dep-instance from template. */
-       memcpy(code, (unsigned long *)&optprobe_template_entry,
+       memcpy(code, (unsigned long *)optprobe_template_entry,
                        TMPL_END_IDX * sizeof(kprobe_opcode_t));
 
        /* Adjust buffer according to instruction. */
index 1d466ad..1515f6f 100644 (file)
@@ -1002,7 +1002,7 @@ config NUMA
 config NODES_SHIFT
        int "Maximum NUMA Nodes (as a power of 2)"
        range 1 10
-       default "2"
+       default "4"
        depends on NEED_MULTIPLE_NODES
        help
          Specify the maximum number of NUMA Nodes available on the target
index 3ea5182..e5e840b 100644 (file)
 &emac {
        pinctrl-names = "default";
        pinctrl-0 = <&rgmii_pins>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
        phy-handle = <&ext_rgmii_phy>;
        phy-supply = <&reg_dc1sw>;
        status = "okay";
index d894ec5..70e3174 100644 (file)
 &emac {
        pinctrl-names = "default";
        pinctrl-0 = <&rgmii_pins>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
        phy-handle = <&ext_rgmii_phy>;
        phy-supply = <&reg_gmac_3v3>;
        status = "okay";
index b26181c..b54099b 100644 (file)
@@ -13,7 +13,7 @@
 &emac {
        pinctrl-names = "default";
        pinctrl-0 = <&rgmii_pins>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-txid";
        phy-handle = <&ext_rgmii_phy>;
        status = "okay";
 };
index 3ab0f03..0494bfa 100644 (file)
        status = "okay";
 
        port {
-               #address-cells = <1>;
-               #size-cells = <0>;
-
                csi_ep: endpoint {
                        remote-endpoint = <&ov5640_ep>;
                        bus-width = <8>;
index df1b926..6e30a56 100644 (file)
@@ -36,7 +36,7 @@
        pinctrl-0 = <&emac_rgmii_pins>;
        phy-supply = <&reg_gmac_3v3>;
        phy-handle = <&ext_rgmii_phy>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
        /delete-property/ allwinner,leds-active-low;
        status = "okay";
 };
index 7d7aad1..8bf2db9 100644 (file)
        pinctrl-0 = <&emac_rgmii_pins>;
        phy-supply = <&reg_gmac_3v3>;
        phy-handle = <&ext_rgmii_phy>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
        status = "okay";
 };
 
index cb44bfa..33ab440 100644 (file)
        pinctrl-0 = <&emac_rgmii_pins>;
        phy-supply = <&reg_gmac_3v3>;
        phy-handle = <&ext_rgmii_phy>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
        status = "okay";
 };
 
index 3f7ceeb..7c9dbde 100644 (file)
@@ -97,7 +97,7 @@
 &emac {
        pinctrl-names = "default";
        pinctrl-0 = <&ext_rgmii_pins>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
        phy-handle = <&ext_rgmii_phy>;
        phy-supply = <&reg_aldo2>;
        status = "okay";
index af85b20..961732c 100644 (file)
 &emac {
        pinctrl-names = "default";
        pinctrl-0 = <&ext_rgmii_pins>;
-       phy-mode = "rgmii";
+       phy-mode = "rgmii-id";
        phy-handle = <&ext_rgmii_phy>;
        phy-supply = <&reg_gmac_3v3>;
        allwinner,rx-delay-ps = <200>;
index feadd21..46e558a 100644 (file)
        flash@0 {
                #address-cells = <1>;
                #size-cells = <1>;
-               compatible = "n25q00a";
+               compatible = "micron,mt25qu02g", "jedec,spi-nor";
                reg = <0>;
                spi-max-frequency = <100000000>;
 
index c079667..f9b4a39 100644 (file)
        flash@0 {
                #address-cells = <1>;
                #size-cells = <1>;
-               compatible = "n25q00a";
+               compatible = "micron,mt25qu02g", "jedec,spi-nor";
                reg = <0>;
                spi-max-frequency = <100000000>;
 
index f46eb47..8161dd2 100644 (file)
@@ -75,6 +75,7 @@
 &enetc_port0 {
        phy-handle = <&phy0>;
        phy-connection-type = "sgmii";
+       managed = "in-band-status";
        status = "okay";
 
        mdio {
index 73e4f94..7a6fb7e 100644 (file)
                        compatible = "fsl,ls1028a-rcpm", "fsl,qoriq-rcpm-2.1+";
                        reg = <0x0 0x1e34040 0x0 0x1c>;
                        #fsl,rcpm-wakeup-cells = <7>;
+                       little-endian;
                };
 
                ftm_alarm0: timer@2800000 {
index ff58052..692d8f4 100644 (file)
                        compatible = "fsl,ls1088a-rcpm", "fsl,qoriq-rcpm-2.1+";
                        reg = <0x0 0x1e34040 0x0 0x18>;
                        #fsl,rcpm-wakeup-cells = <6>;
+                       little-endian;
                };
 
                ftm_alarm0: timer@2800000 {
index bf72918..e7abb74 100644 (file)
                        compatible = "fsl,ls208xa-rcpm", "fsl,qoriq-rcpm-2.1+";
                        reg = <0x0 0x1e34040 0x0 0x18>;
                        #fsl,rcpm-wakeup-cells = <6>;
+                       little-endian;
                };
 
                ftm_alarm0: timer@2800000 {
index 6de86a4..b88c3c9 100644 (file)
@@ -72,6 +72,7 @@
        pmic@4b {
                compatible = "rohm,bd71847";
                reg = <0x4b>;
+               pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_pmic>;
                interrupt-parent = <&gpio1>;
                interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
                host-wakeup-gpios = <&gpio2 8 GPIO_ACTIVE_HIGH>;
                device-wakeup-gpios = <&gpio2 7 GPIO_ACTIVE_HIGH>;
                clocks = <&osc_32k>;
+               max-speed = <4000000>;
                clock-names = "extclk";
        };
 };
index f305a53..521eb3a 100644 (file)
        pmic@4b {
                compatible = "rohm,bd71847";
                reg = <0x4b>;
+               pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_pmic>;
                interrupt-parent = <&gpio1>;
                interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
index 4107fe9..4908252 100644 (file)
        pmic@4b {
                compatible = "rohm,bd71847";
                reg = <0x4b>;
+               pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_pmic>;
                interrupt-parent = <&gpio2>;
-               /*
-                * The interrupt is not correct. It should be level low,
-                * however with internal pull up this causes IRQ storm.
-                */
-               interrupts = <8 IRQ_TYPE_EDGE_RISING>;
+               interrupts = <8 IRQ_TYPE_LEVEL_LOW>;
                rohm,reset-snvs-powered;
 
                #clock-cells = <0>;
 
        pinctrl_pmic: pmicirqgrp {
                fsl,pins = <
-                       MX8MM_IOMUXC_SD1_DATA6_GPIO2_IO8        0x41
+                       MX8MM_IOMUXC_SD1_DATA6_GPIO2_IO8        0x141
                >;
        };
 
index b83f400..05ee062 100644 (file)
 
                opp-1600000000 {
                        opp-hz = /bits/ 64 <1600000000>;
-                       opp-microvolt = <900000>;
+                       opp-microvolt = <950000>;
                        opp-supported-hw = <0xc>, <0x7>;
                        clock-latency-ns = <150000>;
                        opp-suspend;
index 46e76cf..7dfee71 100644 (file)
@@ -53,6 +53,7 @@
        pmic@4b {
                compatible = "rohm,bd71847";
                reg = <0x4b>;
+               pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_pmic>;
                interrupt-parent = <&gpio1>;
                interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
index 707d848..8311b95 100644 (file)
@@ -18,6 +18,7 @@
        pmic: pmic@25 {
                compatible = "nxp,pca9450b";
                reg = <0x25>;
+               pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_pmic>;
                interrupt-parent = <&gpio1>;
                interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
index a2d0190..7f356ed 100644 (file)
        pmic@4b {
                compatible = "rohm,bd71847";
                reg = <0x4b>;
+               pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_pmic>;
                interrupt-parent = <&gpio2>;
-               /*
-                * The interrupt is not correct. It should be level low,
-                * however with internal pull up this causes IRQ storm.
-                */
-               interrupts = <8 IRQ_TYPE_EDGE_RISING>;
+               interrupts = <8 IRQ_TYPE_LEVEL_LOW>;
                rohm,reset-snvs-powered;
 
                regulators {
 
        pinctrl_pmic: pmicirqgrp {
                fsl,pins = <
-                       MX8MN_IOMUXC_SD1_DATA6_GPIO2_IO8        0x101
+                       MX8MN_IOMUXC_SD1_DATA6_GPIO2_IO8        0x141
                >;
        };
 
index 746faf1..16c7202 100644 (file)
                                #index-cells = <1>;
                                reg = <0x32e40200 0x200>;
                        };
-
-                       usbotg2: usb@32e50000 {
-                               compatible = "fsl,imx8mn-usb", "fsl,imx7d-usb";
-                               reg = <0x32e50000 0x200>;
-                               interrupts = <GIC_SPI 41 IRQ_TYPE_LEVEL_HIGH>;
-                               clocks = <&clk IMX8MN_CLK_USB1_CTRL_ROOT>;
-                               clock-names = "usb1_ctrl_root_clk";
-                               assigned-clocks = <&clk IMX8MN_CLK_USB_BUS>,
-                                                 <&clk IMX8MN_CLK_USB_CORE_REF>;
-                               assigned-clock-parents = <&clk IMX8MN_SYS_PLL2_500M>,
-                                                        <&clk IMX8MN_SYS_PLL1_100M>;
-                               fsl,usbphy = <&usbphynop2>;
-                               fsl,usbmisc = <&usbmisc2 0>;
-                               status = "disabled";
-                       };
-
-                       usbmisc2: usbmisc@32e50200 {
-                               compatible = "fsl,imx8mn-usbmisc", "fsl,imx7d-usbmisc";
-                               #index-cells = <1>;
-                               reg = <0x32e50200 0x200>;
-                       };
-
                };
 
                dma_apbh: dma-controller@33000000 {
                assigned-clock-parents = <&clk IMX8MN_SYS_PLL1_100M>;
                clock-names = "main_clk";
        };
-
-       usbphynop2: usbphynop2 {
-               compatible = "usb-nop-xceiv";
-               clocks = <&clk IMX8MN_CLK_USB_PHY_REF>;
-               assigned-clocks = <&clk IMX8MN_CLK_USB_PHY_REF>;
-               assigned-clock-parents = <&clk IMX8MN_SYS_PLL1_100M>;
-               clock-names = "main_clk";
-       };
 };
index 8bc6caa..4338db1 100644 (file)
@@ -19,6 +19,7 @@ fman0: fman@1a00000 {
        clock-names = "fmanclk";
        fsl,qman-channel-range = <0x800 0x10>;
        ptimer-handle = <&ptp_timer0>;
+       dma-coherent;
 
        muram@0 {
                compatible = "fsl,fman-muram";
index 96c50d4..a7a83f2 100644 (file)
        flash@0 {
                #address-cells = <1>;
                #size-cells = <1>;
-               compatible = "mt25qu02g";
+               compatible = "micron,mt25qu02g", "jedec,spi-nor";
                reg = <0>;
                spi-max-frequency = <100000000>;
 
index 9cbf963..c296434 100644 (file)
                clock-frequency = <0>;
        };
 
+       audio_clk_b: audio_clk_b {
+               compatible = "fixed-clock";
+               #clock-cells = <0>;
+               clock-frequency = <0>;
+       };
+
        audio_clk_c: audio_clk_c {
                compatible = "fixed-clock";
                #clock-cells = <0>;
index e3d47b5..ec7720d 100644 (file)
@@ -10,6 +10,7 @@
  * #imm16 values used for BRK instruction generation
  * 0x004: for installing kprobes
  * 0x005: for installing uprobes
+ * 0x006: for kprobe software single-step
  * Allowed values for kgdb are 0x400 - 0x7ff
  * 0x100: for triggering a fault on purpose (reserved)
  * 0x400: for dynamic BRK instruction
@@ -19,6 +20,7 @@
  */
 #define KPROBES_BRK_IMM                        0x004
 #define UPROBES_BRK_IMM                        0x005
+#define KPROBES_BRK_SS_IMM             0x006
 #define FAULT_BRK_IMM                  0x100
 #define KGDB_DYN_DBG_BRK_IMM           0x400
 #define KGDB_COMPILED_DBG_BRK_IMM      0x401
index 97244d4..da250e4 100644 (file)
@@ -268,6 +268,8 @@ extern struct arm64_ftr_reg arm64_ftr_reg_ctrel0;
 /*
  * CPU feature detected at boot time based on feature of one or more CPUs.
  * All possible conflicts for a late CPU are ignored.
+ * NOTE: this means that a late CPU with the feature will *not* cause the
+ * capability to be advertised by cpus_have_*cap()!
  */
 #define ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE            \
        (ARM64_CPUCAP_SCOPE_LOCAL_CPU           |       \
index 9e2e9a6..ef5b040 100644 (file)
@@ -86,6 +86,8 @@
 #define QCOM_CPU_PART_FALKOR_V1                0x800
 #define QCOM_CPU_PART_FALKOR           0xC00
 #define QCOM_CPU_PART_KRYO             0x200
+#define QCOM_CPU_PART_KRYO_2XX_GOLD    0x800
+#define QCOM_CPU_PART_KRYO_2XX_SILVER  0x801
 #define QCOM_CPU_PART_KRYO_3XX_SILVER  0x803
 #define QCOM_CPU_PART_KRYO_4XX_GOLD    0x804
 #define QCOM_CPU_PART_KRYO_4XX_SILVER  0x805
 #define MIDR_QCOM_FALKOR_V1 MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_FALKOR_V1)
 #define MIDR_QCOM_FALKOR MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_FALKOR)
 #define MIDR_QCOM_KRYO MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO)
+#define MIDR_QCOM_KRYO_2XX_GOLD MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO_2XX_GOLD)
+#define MIDR_QCOM_KRYO_2XX_SILVER MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO_2XX_SILVER)
 #define MIDR_QCOM_KRYO_3XX_SILVER MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO_3XX_SILVER)
 #define MIDR_QCOM_KRYO_4XX_GOLD MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO_4XX_GOLD)
 #define MIDR_QCOM_KRYO_4XX_SILVER MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO_4XX_SILVER)
index 0b298f4..657c921 100644 (file)
@@ -53,6 +53,7 @@
 
 /* kprobes BRK opcodes with ESR encoding  */
 #define BRK64_OPCODE_KPROBES   (AARCH64_BREAK_MON | (KPROBES_BRK_IMM << 5))
+#define BRK64_OPCODE_KPROBES_SS        (AARCH64_BREAK_MON | (KPROBES_BRK_SS_IMM << 5))
 /* uprobes BRK opcodes with ESR encoding  */
 #define BRK64_OPCODE_UPROBES   (AARCH64_BREAK_MON | (UPROBES_BRK_IMM << 5))
 
index 97e511d..8699ce3 100644 (file)
@@ -16,7 +16,7 @@
 #include <linux/percpu.h>
 
 #define __ARCH_WANT_KPROBES_INSN_SLOT
-#define MAX_INSN_SIZE                  1
+#define MAX_INSN_SIZE                  2
 
 #define flush_insn_slot(p)             do { } while (0)
 #define kretprobe_blacklist_size       0
index 781d029..0cd9f0f 100644 (file)
@@ -118,6 +118,8 @@ struct kvm_arch {
         */
        unsigned long *pmu_filter;
        unsigned int pmuver;
+
+       u8 pfr0_csv2;
 };
 
 struct kvm_vcpu_fault_info {
index 174817b..e2ef4c2 100644 (file)
 #define SYS_CONTEXTIDR_EL1             sys_reg(3, 0, 13, 0, 1)
 #define SYS_TPIDR_EL1                  sys_reg(3, 0, 13, 0, 4)
 
+#define SYS_SCXTNUM_EL1                        sys_reg(3, 0, 13, 0, 7)
+
 #define SYS_CNTKCTL_EL1                        sys_reg(3, 0, 14, 1, 0)
 
 #define SYS_CCSIDR_EL1                 sys_reg(3, 1, 0, 0, 0)
 #define SYS_TPIDR_EL0                  sys_reg(3, 3, 13, 0, 2)
 #define SYS_TPIDRRO_EL0                        sys_reg(3, 3, 13, 0, 3)
 
+#define SYS_SCXTNUM_EL0                        sys_reg(3, 3, 13, 0, 7)
+
 /* Definitions for system register interface to AMU for ARMv8.4 onwards */
 #define SYS_AM_EL0(crm, op2)           sys_reg(3, 3, 13, (crm), (op2))
 #define SYS_AMCR_EL0                   SYS_AM_EL0(2, 0)
index 61314fd..cafaf0d 100644 (file)
@@ -299,6 +299,8 @@ static const struct midr_range erratum_845719_list[] = {
        MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 4),
        /* Brahma-B53 r0p[0] */
        MIDR_REV(MIDR_BRAHMA_B53, 0, 0),
+       /* Kryo2XX Silver rAp4 */
+       MIDR_REV(MIDR_QCOM_KRYO_2XX_SILVER, 0xa, 0x4),
        {},
 };
 #endif
index dcc165b..6f36c4f 100644 (file)
@@ -1337,6 +1337,8 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry,
                MIDR_ALL_VERSIONS(MIDR_CORTEX_A73),
                MIDR_ALL_VERSIONS(MIDR_HISI_TSV110),
                MIDR_ALL_VERSIONS(MIDR_NVIDIA_CARMEL),
+               MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_2XX_GOLD),
+               MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_2XX_SILVER),
                MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_3XX_SILVER),
                MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_4XX_SILVER),
                { /* sentinel */ }
index af9987c..9ec3469 100644 (file)
@@ -43,7 +43,7 @@ static void *image_load(struct kimage *image,
        u64 flags, value;
        bool be_image, be_kernel;
        struct kexec_buf kbuf;
-       unsigned long text_offset;
+       unsigned long text_offset, kernel_segment_number;
        struct kexec_segment *kernel_segment;
        int ret;
 
@@ -88,11 +88,37 @@ static void *image_load(struct kimage *image,
        /* Adjust kernel segment with TEXT_OFFSET */
        kbuf.memsz += text_offset;
 
-       ret = kexec_add_buffer(&kbuf);
-       if (ret)
+       kernel_segment_number = image->nr_segments;
+
+       /*
+        * The location of the kernel segment may make it impossible to satisfy
+        * the other segment requirements, so we try repeatedly to find a
+        * location that will work.
+        */
+       while ((ret = kexec_add_buffer(&kbuf)) == 0) {
+               /* Try to load additional data */
+               kernel_segment = &image->segment[kernel_segment_number];
+               ret = load_other_segments(image, kernel_segment->mem,
+                                         kernel_segment->memsz, initrd,
+                                         initrd_len, cmdline);
+               if (!ret)
+                       break;
+
+               /*
+                * We couldn't find space for the other segments; erase the
+                * kernel segment and try the next available hole.
+                */
+               image->nr_segments -= 1;
+               kbuf.buf_min = kernel_segment->mem + kernel_segment->memsz;
+               kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
+       }
+
+       if (ret) {
+               pr_err("Could not find any suitable kernel location!");
                return ERR_PTR(ret);
+       }
 
-       kernel_segment = &image->segment[image->nr_segments - 1];
+       kernel_segment = &image->segment[kernel_segment_number];
        kernel_segment->mem += text_offset;
        kernel_segment->memsz -= text_offset;
        image->start = kernel_segment->mem;
@@ -101,12 +127,7 @@ static void *image_load(struct kimage *image,
                                kernel_segment->mem, kbuf.bufsz,
                                kernel_segment->memsz);
 
-       /* Load additional data */
-       ret = load_other_segments(image,
-                               kernel_segment->mem, kernel_segment->memsz,
-                               initrd, initrd_len, cmdline);
-
-       return ERR_PTR(ret);
+       return NULL;
 }
 
 #ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG
index 5b0e67b..03210f6 100644 (file)
@@ -240,6 +240,11 @@ static int prepare_elf_headers(void **addr, unsigned long *sz)
        return ret;
 }
 
+/*
+ * Tries to add the initrd and DTB to the image. If it is not possible to find
+ * valid locations, this function will undo changes to the image and return non
+ * zero.
+ */
 int load_other_segments(struct kimage *image,
                        unsigned long kernel_load_addr,
                        unsigned long kernel_size,
@@ -248,7 +253,8 @@ int load_other_segments(struct kimage *image,
 {
        struct kexec_buf kbuf;
        void *headers, *dtb = NULL;
-       unsigned long headers_sz, initrd_load_addr = 0, dtb_len;
+       unsigned long headers_sz, initrd_load_addr = 0, dtb_len,
+                     orig_segments = image->nr_segments;
        int ret = 0;
 
        kbuf.image = image;
@@ -334,6 +340,7 @@ int load_other_segments(struct kimage *image,
        return 0;
 
 out_err:
+       image->nr_segments = orig_segments;
        vfree(dtb);
        return ret;
 }
index 94e8718..f6f58e6 100644 (file)
@@ -73,8 +73,7 @@ u64 perf_reg_abi(struct task_struct *task)
 }
 
 void perf_get_regs_user(struct perf_regs *regs_user,
-                       struct pt_regs *regs,
-                       struct pt_regs *regs_user_copy)
+                       struct pt_regs *regs)
 {
        regs_user->regs = task_pt_regs(current);
        regs_user->abi = perf_reg_abi(current);
index deba738..f11a1a1 100644 (file)
@@ -36,25 +36,16 @@ DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
 static void __kprobes
 post_kprobe_handler(struct kprobe_ctlblk *, struct pt_regs *);
 
-static int __kprobes patch_text(kprobe_opcode_t *addr, u32 opcode)
-{
-       void *addrs[1];
-       u32 insns[1];
-
-       addrs[0] = addr;
-       insns[0] = opcode;
-
-       return aarch64_insn_patch_text(addrs, insns, 1);
-}
-
 static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
 {
+       kprobe_opcode_t *addr = p->ainsn.api.insn;
+       void *addrs[] = {addr, addr + 1};
+       u32 insns[] = {p->opcode, BRK64_OPCODE_KPROBES_SS};
+
        /* prepare insn slot */
-       patch_text(p->ainsn.api.insn, p->opcode);
+       aarch64_insn_patch_text(addrs, insns, 2);
 
-       flush_icache_range((uintptr_t) (p->ainsn.api.insn),
-                          (uintptr_t) (p->ainsn.api.insn) +
-                          MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
+       flush_icache_range((uintptr_t)addr, (uintptr_t)(addr + MAX_INSN_SIZE));
 
        /*
         * Needs restoring of return address after stepping xol.
@@ -128,13 +119,18 @@ void *alloc_insn_page(void)
 /* arm kprobe: install breakpoint in text */
 void __kprobes arch_arm_kprobe(struct kprobe *p)
 {
-       patch_text(p->addr, BRK64_OPCODE_KPROBES);
+       void *addr = p->addr;
+       u32 insn = BRK64_OPCODE_KPROBES;
+
+       aarch64_insn_patch_text(&addr, &insn, 1);
 }
 
 /* disarm kprobe: remove breakpoint from text */
 void __kprobes arch_disarm_kprobe(struct kprobe *p)
 {
-       patch_text(p->addr, p->opcode);
+       void *addr = p->addr;
+
+       aarch64_insn_patch_text(&addr, &p->opcode, 1);
 }
 
 void __kprobes arch_remove_kprobe(struct kprobe *p)
@@ -163,20 +159,15 @@ static void __kprobes set_current_kprobe(struct kprobe *p)
 }
 
 /*
- * Interrupts need to be disabled before single-step mode is set, and not
- * reenabled until after single-step mode ends.
- * Without disabling interrupt on local CPU, there is a chance of
- * interrupt occurrence in the period of exception return and  start of
- * out-of-line single-step, that result in wrongly single stepping
- * into the interrupt handler.
+ * Mask all of DAIF while executing the instruction out-of-line, to keep things
+ * simple and avoid nesting exceptions. Interrupts do have to be disabled since
+ * the kprobe state is per-CPU and doesn't get migrated.
  */
 static void __kprobes kprobes_save_local_irqflag(struct kprobe_ctlblk *kcb,
                                                struct pt_regs *regs)
 {
        kcb->saved_irqflag = regs->pstate & DAIF_MASK;
-       regs->pstate |= PSR_I_BIT;
-       /* Unmask PSTATE.D for enabling software step exceptions. */
-       regs->pstate &= ~PSR_D_BIT;
+       regs->pstate |= DAIF_MASK;
 }
 
 static void __kprobes kprobes_restore_local_irqflag(struct kprobe_ctlblk *kcb,
@@ -219,10 +210,7 @@ static void __kprobes setup_singlestep(struct kprobe *p,
                slot = (unsigned long)p->ainsn.api.insn;
 
                set_ss_context(kcb, slot);      /* mark pending ss */
-
-               /* IRQs and single stepping do not mix well. */
                kprobes_save_local_irqflag(kcb, regs);
-               kernel_enable_single_step(regs);
                instruction_pointer_set(regs, slot);
        } else {
                /* insn simulation */
@@ -273,12 +261,8 @@ post_kprobe_handler(struct kprobe_ctlblk *kcb, struct pt_regs *regs)
        }
        /* call post handler */
        kcb->kprobe_status = KPROBE_HIT_SSDONE;
-       if (cur->post_handler)  {
-               /* post_handler can hit breakpoint and single step
-                * again, so we enable D-flag for recursive exception.
-                */
+       if (cur->post_handler)
                cur->post_handler(cur, regs, 0);
-       }
 
        reset_current_kprobe();
 }
@@ -302,8 +286,6 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr)
                if (!instruction_pointer(regs))
                        BUG();
 
-               kernel_disable_single_step();
-
                if (kcb->kprobe_status == KPROBE_REENTER)
                        restore_previous_kprobe(kcb);
                else
@@ -365,10 +347,6 @@ static void __kprobes kprobe_handler(struct pt_regs *regs)
                         * pre-handler and it returned non-zero, it will
                         * modify the execution path and no need to single
                         * stepping. Let's just reset current kprobe and exit.
-                        *
-                        * pre_handler can hit a breakpoint and can step thru
-                        * before return, keep PSTATE D-flag enabled until
-                        * pre_handler return back.
                         */
                        if (!p->pre_handler || !p->pre_handler(p, regs)) {
                                setup_singlestep(p, regs, kcb, 0);
@@ -399,7 +377,7 @@ kprobe_ss_hit(struct kprobe_ctlblk *kcb, unsigned long addr)
 }
 
 static int __kprobes
-kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr)
+kprobe_breakpoint_ss_handler(struct pt_regs *regs, unsigned int esr)
 {
        struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
        int retval;
@@ -409,16 +387,15 @@ kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr)
 
        if (retval == DBG_HOOK_HANDLED) {
                kprobes_restore_local_irqflag(kcb, regs);
-               kernel_disable_single_step();
-
                post_kprobe_handler(kcb, regs);
        }
 
        return retval;
 }
 
-static struct step_hook kprobes_step_hook = {
-       .fn = kprobe_single_step_handler,
+static struct break_hook kprobes_break_ss_hook = {
+       .imm = KPROBES_BRK_SS_IMM,
+       .fn = kprobe_breakpoint_ss_handler,
 };
 
 static int __kprobes
@@ -486,7 +463,7 @@ int __kprobes arch_trampoline_kprobe(struct kprobe *p)
 int __init arch_init_kprobes(void)
 {
        register_kernel_break_hook(&kprobes_break_hook);
-       register_kernel_step_hook(&kprobes_step_hook);
+       register_kernel_break_hook(&kprobes_break_ss_hook);
 
        return 0;
 }
index 4784011..a47a40e 100644 (file)
@@ -522,14 +522,13 @@ static void erratum_1418040_thread_switch(struct task_struct *prev,
        bool prev32, next32;
        u64 val;
 
-       if (!(IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040) &&
-             cpus_have_const_cap(ARM64_WORKAROUND_1418040)))
+       if (!IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040))
                return;
 
        prev32 = is_compat_thread(task_thread_info(prev));
        next32 = is_compat_thread(task_thread_info(next));
 
-       if (prev32 == next32)
+       if (prev32 == next32 || !this_cpu_has_cap(ARM64_WORKAROUND_1418040))
                return;
 
        val = read_sysreg(cntkctl_el1);
index c18eb7d..f6e4e37 100644 (file)
@@ -118,6 +118,7 @@ static enum mitigation_state spectre_v2_get_cpu_hw_mitigation_state(void)
                MIDR_ALL_VERSIONS(MIDR_CORTEX_A55),
                MIDR_ALL_VERSIONS(MIDR_BRAHMA_B53),
                MIDR_ALL_VERSIONS(MIDR_HISI_TSV110),
+               MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_2XX_SILVER),
                MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_3XX_SILVER),
                MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_4XX_SILVER),
                { /* sentinel */ }
index 43ae4e0..62d2bda 100644 (file)
@@ -66,7 +66,6 @@ static int cpu_psci_cpu_disable(unsigned int cpu)
 
 static void cpu_psci_cpu_die(unsigned int cpu)
 {
-       int ret;
        /*
         * There are no known implementations of PSCI actually using the
         * power state field, pass a sensible default for now.
@@ -74,9 +73,7 @@ static void cpu_psci_cpu_die(unsigned int cpu)
        u32 state = PSCI_POWER_STATE_TYPE_POWER_DOWN <<
                    PSCI_0_2_POWER_STATE_TYPE_SHIFT;
 
-       ret = psci_ops.cpu_off(state);
-
-       pr_crit("unable to power off CPU%u (%d)\n", cpu, ret);
+       psci_ops.cpu_off(state);
 }
 
 static int cpu_psci_cpu_kill(unsigned int cpu)
index 09c96f5..18e9727 100644 (file)
@@ -413,6 +413,7 @@ void cpu_die_early(void)
 
        /* Mark this CPU absent */
        set_cpu_present(cpu, 0);
+       rcu_report_dead(cpu);
 
        if (IS_ENABLED(CONFIG_HOTPLUG_CPU)) {
                update_cpu_boot_status(CPU_KILL_ME);
index 5750ec3..c0ffb01 100644 (file)
@@ -102,6 +102,20 @@ static int kvm_arm_default_max_vcpus(void)
        return vgic_present ? kvm_vgic_get_max_vcpus() : KVM_MAX_VCPUS;
 }
 
+static void set_default_csv2(struct kvm *kvm)
+{
+       /*
+        * The default is to expose CSV2 == 1 if the HW isn't affected.
+        * Although this is a per-CPU feature, we make it global because
+        * asymmetric systems are just a nuisance.
+        *
+        * Userspace can override this as long as it doesn't promise
+        * the impossible.
+        */
+       if (arm64_get_spectre_v2_state() == SPECTRE_UNAFFECTED)
+               kvm->arch.pfr0_csv2 = 1;
+}
+
 /**
  * kvm_arch_init_vm - initializes a VM data structure
  * @kvm:       pointer to the KVM struct
@@ -127,6 +141,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
        /* The maximum number of VCPUs is limited by the host's GIC model */
        kvm->arch.max_vcpus = kvm_arm_default_max_vcpus();
 
+       set_default_csv2(kvm);
+
        return ret;
 out_free_stage2_pgd:
        kvm_free_stage2_pgd(&kvm->arch.mmu);
index 57972bd..1a01da9 100644 (file)
@@ -788,10 +788,12 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
        }
 
        switch (vma_shift) {
+#ifndef __PAGETABLE_PMD_FOLDED
        case PUD_SHIFT:
                if (fault_supports_stage2_huge_mapping(memslot, hva, PUD_SIZE))
                        break;
                fallthrough;
+#endif
        case CONT_PMD_SHIFT:
                vma_shift = PMD_SHIFT;
                fallthrough;
index fb12d3e..c1fac98 100644 (file)
@@ -1038,8 +1038,8 @@ static bool access_pmuserenr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
        { SYS_DESC(SYS_PMEVTYPERn_EL0(n)),                                      \
          access_pmu_evtyper, reset_unknown, (PMEVTYPER0_EL0 + n), }
 
-static bool access_amu(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
-                            const struct sys_reg_desc *r)
+static bool undef_access(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
+                        const struct sys_reg_desc *r)
 {
        kvm_inject_undefined(vcpu);
 
@@ -1047,33 +1047,25 @@ static bool access_amu(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
 }
 
 /* Macro to expand the AMU counter and type registers*/
-#define AMU_AMEVCNTR0_EL0(n) { SYS_DESC(SYS_AMEVCNTR0_EL0(n)), access_amu }
-#define AMU_AMEVTYPER0_EL0(n) { SYS_DESC(SYS_AMEVTYPER0_EL0(n)), access_amu }
-#define AMU_AMEVCNTR1_EL0(n) { SYS_DESC(SYS_AMEVCNTR1_EL0(n)), access_amu }
-#define AMU_AMEVTYPER1_EL0(n) { SYS_DESC(SYS_AMEVTYPER1_EL0(n)), access_amu }
-
-static bool trap_ptrauth(struct kvm_vcpu *vcpu,
-                        struct sys_reg_params *p,
-                        const struct sys_reg_desc *rd)
-{
-       /*
-        * If we land here, that is because we didn't fixup the access on exit
-        * by allowing the PtrAuth sysregs. The only way this happens is when
-        * the guest does not have PtrAuth support enabled.
-        */
-       kvm_inject_undefined(vcpu);
-
-       return false;
-}
+#define AMU_AMEVCNTR0_EL0(n) { SYS_DESC(SYS_AMEVCNTR0_EL0(n)), undef_access }
+#define AMU_AMEVTYPER0_EL0(n) { SYS_DESC(SYS_AMEVTYPER0_EL0(n)), undef_access }
+#define AMU_AMEVCNTR1_EL0(n) { SYS_DESC(SYS_AMEVCNTR1_EL0(n)), undef_access }
+#define AMU_AMEVTYPER1_EL0(n) { SYS_DESC(SYS_AMEVTYPER1_EL0(n)), undef_access }
 
 static unsigned int ptrauth_visibility(const struct kvm_vcpu *vcpu,
                        const struct sys_reg_desc *rd)
 {
-       return vcpu_has_ptrauth(vcpu) ? 0 : REG_HIDDEN_USER | REG_HIDDEN_GUEST;
+       return vcpu_has_ptrauth(vcpu) ? 0 : REG_HIDDEN;
 }
 
+/*
+ * If we land here on a PtrAuth access, that is because we didn't
+ * fixup the access on exit by allowing the PtrAuth sysregs. The only
+ * way this happens is when the guest does not have PtrAuth support
+ * enabled.
+ */
 #define __PTRAUTH_KEY(k)                                               \
-       { SYS_DESC(SYS_## k), trap_ptrauth, reset_unknown, k,           \
+       { SYS_DESC(SYS_## k), undef_access, reset_unknown, k,           \
        .visibility = ptrauth_visibility}
 
 #define PTRAUTH_KEY(k)                                                 \
@@ -1128,9 +1120,8 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,
                if (!vcpu_has_sve(vcpu))
                        val &= ~(0xfUL << ID_AA64PFR0_SVE_SHIFT);
                val &= ~(0xfUL << ID_AA64PFR0_AMU_SHIFT);
-               if (!(val & (0xfUL << ID_AA64PFR0_CSV2_SHIFT)) &&
-                   arm64_get_spectre_v2_state() == SPECTRE_UNAFFECTED)
-                       val |= (1UL << ID_AA64PFR0_CSV2_SHIFT);
+               val &= ~(0xfUL << ID_AA64PFR0_CSV2_SHIFT);
+               val |= ((u64)vcpu->kvm->arch.pfr0_csv2 << ID_AA64PFR0_CSV2_SHIFT);
        } else if (id == SYS_ID_AA64PFR1_EL1) {
                val &= ~(0xfUL << ID_AA64PFR1_MTE_SHIFT);
        } else if (id == SYS_ID_AA64ISAR1_EL1 && !vcpu_has_ptrauth(vcpu)) {
@@ -1153,6 +1144,22 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,
        return val;
 }
 
+static unsigned int id_visibility(const struct kvm_vcpu *vcpu,
+                                 const struct sys_reg_desc *r)
+{
+       u32 id = sys_reg((u32)r->Op0, (u32)r->Op1,
+                        (u32)r->CRn, (u32)r->CRm, (u32)r->Op2);
+
+       switch (id) {
+       case SYS_ID_AA64ZFR0_EL1:
+               if (!vcpu_has_sve(vcpu))
+                       return REG_RAZ;
+               break;
+       }
+
+       return 0;
+}
+
 /* cpufeature ID register access trap handlers */
 
 static bool __access_id_reg(struct kvm_vcpu *vcpu,
@@ -1171,7 +1178,9 @@ static bool access_id_reg(struct kvm_vcpu *vcpu,
                          struct sys_reg_params *p,
                          const struct sys_reg_desc *r)
 {
-       return __access_id_reg(vcpu, p, r, false);
+       bool raz = sysreg_visible_as_raz(vcpu, r);
+
+       return __access_id_reg(vcpu, p, r, raz);
 }
 
 static bool access_raz_id_reg(struct kvm_vcpu *vcpu,
@@ -1192,71 +1201,40 @@ static unsigned int sve_visibility(const struct kvm_vcpu *vcpu,
        if (vcpu_has_sve(vcpu))
                return 0;
 
-       return REG_HIDDEN_USER | REG_HIDDEN_GUEST;
-}
-
-/* Visibility overrides for SVE-specific ID registers */
-static unsigned int sve_id_visibility(const struct kvm_vcpu *vcpu,
-                                     const struct sys_reg_desc *rd)
-{
-       if (vcpu_has_sve(vcpu))
-               return 0;
-
-       return REG_HIDDEN_USER;
+       return REG_HIDDEN;
 }
 
-/* Generate the emulated ID_AA64ZFR0_EL1 value exposed to the guest */
-static u64 guest_id_aa64zfr0_el1(const struct kvm_vcpu *vcpu)
-{
-       if (!vcpu_has_sve(vcpu))
-               return 0;
-
-       return read_sanitised_ftr_reg(SYS_ID_AA64ZFR0_EL1);
-}
-
-static bool access_id_aa64zfr0_el1(struct kvm_vcpu *vcpu,
-                                  struct sys_reg_params *p,
-                                  const struct sys_reg_desc *rd)
-{
-       if (p->is_write)
-               return write_to_read_only(vcpu, p, rd);
-
-       p->regval = guest_id_aa64zfr0_el1(vcpu);
-       return true;
-}
-
-static int get_id_aa64zfr0_el1(struct kvm_vcpu *vcpu,
-               const struct sys_reg_desc *rd,
-               const struct kvm_one_reg *reg, void __user *uaddr)
-{
-       u64 val;
-
-       if (WARN_ON(!vcpu_has_sve(vcpu)))
-               return -ENOENT;
-
-       val = guest_id_aa64zfr0_el1(vcpu);
-       return reg_to_user(uaddr, &val, reg->id);
-}
-
-static int set_id_aa64zfr0_el1(struct kvm_vcpu *vcpu,
-               const struct sys_reg_desc *rd,
-               const struct kvm_one_reg *reg, void __user *uaddr)
+static int set_id_aa64pfr0_el1(struct kvm_vcpu *vcpu,
+                              const struct sys_reg_desc *rd,
+                              const struct kvm_one_reg *reg, void __user *uaddr)
 {
        const u64 id = sys_reg_to_index(rd);
        int err;
        u64 val;
-
-       if (WARN_ON(!vcpu_has_sve(vcpu)))
-               return -ENOENT;
+       u8 csv2;
 
        err = reg_from_user(&val, uaddr, id);
        if (err)
                return err;
 
-       /* This is what we mean by invariant: you can't change it. */
-       if (val != guest_id_aa64zfr0_el1(vcpu))
+       /*
+        * Allow AA64PFR0_EL1.CSV2 to be set from userspace as long as
+        * it doesn't promise more than what is actually provided (the
+        * guest could otherwise be covered in ectoplasmic residue).
+        */
+       csv2 = cpuid_feature_extract_unsigned_field(val, ID_AA64PFR0_CSV2_SHIFT);
+       if (csv2 > 1 ||
+           (csv2 && arm64_get_spectre_v2_state() != SPECTRE_UNAFFECTED))
                return -EINVAL;
 
+       /* We can only differ with CSV2, and anything else is an error */
+       val ^= read_id_reg(vcpu, rd, false);
+       val &= ~(0xFUL << ID_AA64PFR0_CSV2_SHIFT);
+       if (val)
+               return -EINVAL;
+
+       vcpu->kvm->arch.pfr0_csv2 = csv2;
+
        return 0;
 }
 
@@ -1299,13 +1277,17 @@ static int __set_id_reg(const struct kvm_vcpu *vcpu,
 static int get_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
                      const struct kvm_one_reg *reg, void __user *uaddr)
 {
-       return __get_id_reg(vcpu, rd, uaddr, false);
+       bool raz = sysreg_visible_as_raz(vcpu, rd);
+
+       return __get_id_reg(vcpu, rd, uaddr, raz);
 }
 
 static int set_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
                      const struct kvm_one_reg *reg, void __user *uaddr)
 {
-       return __set_id_reg(vcpu, rd, uaddr, false);
+       bool raz = sysreg_visible_as_raz(vcpu, rd);
+
+       return __set_id_reg(vcpu, rd, uaddr, raz);
 }
 
 static int get_raz_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
@@ -1384,19 +1366,13 @@ static bool access_ccsidr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
        return true;
 }
 
-static bool access_mte_regs(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
-                           const struct sys_reg_desc *r)
-{
-       kvm_inject_undefined(vcpu);
-       return false;
-}
-
 /* sys_reg_desc initialiser for known cpufeature ID registers */
 #define ID_SANITISED(name) {                   \
        SYS_DESC(SYS_##name),                   \
        .access = access_id_reg,                \
        .get_user = get_id_reg,                 \
        .set_user = set_id_reg,                 \
+       .visibility = id_visibility,            \
 }
 
 /*
@@ -1514,11 +1490,12 @@ static const struct sys_reg_desc sys_reg_descs[] = {
 
        /* AArch64 ID registers */
        /* CRm=4 */
-       ID_SANITISED(ID_AA64PFR0_EL1),
+       { SYS_DESC(SYS_ID_AA64PFR0_EL1), .access = access_id_reg,
+         .get_user = get_id_reg, .set_user = set_id_aa64pfr0_el1, },
        ID_SANITISED(ID_AA64PFR1_EL1),
        ID_UNALLOCATED(4,2),
        ID_UNALLOCATED(4,3),
-       { SYS_DESC(SYS_ID_AA64ZFR0_EL1), access_id_aa64zfr0_el1, .get_user = get_id_aa64zfr0_el1, .set_user = set_id_aa64zfr0_el1, .visibility = sve_id_visibility },
+       ID_SANITISED(ID_AA64ZFR0_EL1),
        ID_UNALLOCATED(4,5),
        ID_UNALLOCATED(4,6),
        ID_UNALLOCATED(4,7),
@@ -1557,8 +1534,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {
        { SYS_DESC(SYS_ACTLR_EL1), access_actlr, reset_actlr, ACTLR_EL1 },
        { SYS_DESC(SYS_CPACR_EL1), NULL, reset_val, CPACR_EL1, 0 },
 
-       { SYS_DESC(SYS_RGSR_EL1), access_mte_regs },
-       { SYS_DESC(SYS_GCR_EL1), access_mte_regs },
+       { SYS_DESC(SYS_RGSR_EL1), undef_access },
+       { SYS_DESC(SYS_GCR_EL1), undef_access },
 
        { SYS_DESC(SYS_ZCR_EL1), NULL, reset_val, ZCR_EL1, 0, .visibility = sve_visibility },
        { SYS_DESC(SYS_TTBR0_EL1), access_vm_reg, reset_unknown, TTBR0_EL1 },
@@ -1584,8 +1561,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {
        { SYS_DESC(SYS_ERXMISC0_EL1), trap_raz_wi },
        { SYS_DESC(SYS_ERXMISC1_EL1), trap_raz_wi },
 
-       { SYS_DESC(SYS_TFSR_EL1), access_mte_regs },
-       { SYS_DESC(SYS_TFSRE0_EL1), access_mte_regs },
+       { SYS_DESC(SYS_TFSR_EL1), undef_access },
+       { SYS_DESC(SYS_TFSRE0_EL1), undef_access },
 
        { SYS_DESC(SYS_FAR_EL1), access_vm_reg, reset_unknown, FAR_EL1 },
        { SYS_DESC(SYS_PAR_EL1), NULL, reset_unknown, PAR_EL1 },
@@ -1621,6 +1598,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {
        { SYS_DESC(SYS_CONTEXTIDR_EL1), access_vm_reg, reset_val, CONTEXTIDR_EL1, 0 },
        { SYS_DESC(SYS_TPIDR_EL1), NULL, reset_unknown, TPIDR_EL1 },
 
+       { SYS_DESC(SYS_SCXTNUM_EL1), undef_access },
+
        { SYS_DESC(SYS_CNTKCTL_EL1), NULL, reset_val, CNTKCTL_EL1, 0},
 
        { SYS_DESC(SYS_CCSIDR_EL1), access_ccsidr },
@@ -1649,14 +1628,16 @@ static const struct sys_reg_desc sys_reg_descs[] = {
        { SYS_DESC(SYS_TPIDR_EL0), NULL, reset_unknown, TPIDR_EL0 },
        { SYS_DESC(SYS_TPIDRRO_EL0), NULL, reset_unknown, TPIDRRO_EL0 },
 
-       { SYS_DESC(SYS_AMCR_EL0), access_amu },
-       { SYS_DESC(SYS_AMCFGR_EL0), access_amu },
-       { SYS_DESC(SYS_AMCGCR_EL0), access_amu },
-       { SYS_DESC(SYS_AMUSERENR_EL0), access_amu },
-       { SYS_DESC(SYS_AMCNTENCLR0_EL0), access_amu },
-       { SYS_DESC(SYS_AMCNTENSET0_EL0), access_amu },
-       { SYS_DESC(SYS_AMCNTENCLR1_EL0), access_amu },
-       { SYS_DESC(SYS_AMCNTENSET1_EL0), access_amu },
+       { SYS_DESC(SYS_SCXTNUM_EL0), undef_access },
+
+       { SYS_DESC(SYS_AMCR_EL0), undef_access },
+       { SYS_DESC(SYS_AMCFGR_EL0), undef_access },
+       { SYS_DESC(SYS_AMCGCR_EL0), undef_access },
+       { SYS_DESC(SYS_AMUSERENR_EL0), undef_access },
+       { SYS_DESC(SYS_AMCNTENCLR0_EL0), undef_access },
+       { SYS_DESC(SYS_AMCNTENSET0_EL0), undef_access },
+       { SYS_DESC(SYS_AMCNTENCLR1_EL0), undef_access },
+       { SYS_DESC(SYS_AMCNTENSET1_EL0), undef_access },
        AMU_AMEVCNTR0_EL0(0),
        AMU_AMEVCNTR0_EL0(1),
        AMU_AMEVCNTR0_EL0(2),
@@ -2185,7 +2166,7 @@ static void perform_access(struct kvm_vcpu *vcpu,
        trace_kvm_sys_access(*vcpu_pc(vcpu), params, r);
 
        /* Check for regs disabled by runtime config */
-       if (sysreg_hidden_from_guest(vcpu, r)) {
+       if (sysreg_hidden(vcpu, r)) {
                kvm_inject_undefined(vcpu);
                return;
        }
@@ -2684,7 +2665,7 @@ int kvm_arm_sys_reg_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg
                return get_invariant_sys_reg(reg->id, uaddr);
 
        /* Check for regs disabled by runtime config */
-       if (sysreg_hidden_from_user(vcpu, r))
+       if (sysreg_hidden(vcpu, r))
                return -ENOENT;
 
        if (r->get_user)
@@ -2709,7 +2690,7 @@ int kvm_arm_sys_reg_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg
                return set_invariant_sys_reg(reg->id, uaddr);
 
        /* Check for regs disabled by runtime config */
-       if (sysreg_hidden_from_user(vcpu, r))
+       if (sysreg_hidden(vcpu, r))
                return -ENOENT;
 
        if (r->set_user)
@@ -2780,7 +2761,7 @@ static int walk_one_sys_reg(const struct kvm_vcpu *vcpu,
        if (!(rd->reg || rd->get_user))
                return 0;
 
-       if (sysreg_hidden_from_user(vcpu, rd))
+       if (sysreg_hidden(vcpu, rd))
                return 0;
 
        if (!copy_reg_to_user(rd, uind))
index 5a6fc30..0f95964 100644 (file)
@@ -59,8 +59,8 @@ struct sys_reg_desc {
                                   const struct sys_reg_desc *rd);
 };
 
-#define REG_HIDDEN_USER                (1 << 0) /* hidden from userspace ioctls */
-#define REG_HIDDEN_GUEST       (1 << 1) /* hidden from guest */
+#define REG_HIDDEN             (1 << 0) /* hidden from userspace and guest */
+#define REG_RAZ                        (1 << 1) /* RAZ from userspace and guest */
 
 static __printf(2, 3)
 inline void print_sys_reg_msg(const struct sys_reg_params *p,
@@ -111,22 +111,22 @@ static inline void reset_val(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r
        __vcpu_sys_reg(vcpu, r->reg) = r->val;
 }
 
-static inline bool sysreg_hidden_from_guest(const struct kvm_vcpu *vcpu,
-                                           const struct sys_reg_desc *r)
+static inline bool sysreg_hidden(const struct kvm_vcpu *vcpu,
+                                const struct sys_reg_desc *r)
 {
        if (likely(!r->visibility))
                return false;
 
-       return r->visibility(vcpu, r) & REG_HIDDEN_GUEST;
+       return r->visibility(vcpu, r) & REG_HIDDEN;
 }
 
-static inline bool sysreg_hidden_from_user(const struct kvm_vcpu *vcpu,
-                                          const struct sys_reg_desc *r)
+static inline bool sysreg_visible_as_raz(const struct kvm_vcpu *vcpu,
+                                        const struct sys_reg_desc *r)
 {
        if (likely(!r->visibility))
                return false;
 
-       return r->visibility(vcpu, r) & REG_HIDDEN_USER;
+       return r->visibility(vcpu, r) & REG_RAZ;
 }
 
 static inline int cmp_sys_reg(const struct sys_reg_desc *i1,
index 1c0f3e0..ca692a8 100644 (file)
@@ -1444,11 +1444,28 @@ static void __remove_pgd_mapping(pgd_t *pgdir, unsigned long start, u64 size)
        free_empty_tables(start, end, PAGE_OFFSET, PAGE_END);
 }
 
+static bool inside_linear_region(u64 start, u64 size)
+{
+       /*
+        * Linear mapping region is the range [PAGE_OFFSET..(PAGE_END - 1)]
+        * accommodating both its ends but excluding PAGE_END. Max physical
+        * range which can be mapped inside this linear mapping range, must
+        * also be derived from its end points.
+        */
+       return start >= __pa(_PAGE_OFFSET(vabits_actual)) &&
+              (start + size - 1) <= __pa(PAGE_END - 1);
+}
+
 int arch_add_memory(int nid, u64 start, u64 size,
                    struct mhp_params *params)
 {
        int ret, flags = 0;
 
+       if (!inside_linear_region(start, size)) {
+               pr_err("[%llx %llx] is outside linear mapping region\n", start, start + size);
+               return -EINVAL;
+       }
+
        if (rodata_full || debug_pagealloc_enabled())
                flags = NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS;
 
index eb32838..09b7f88 100644 (file)
@@ -32,8 +32,7 @@ u64 perf_reg_abi(struct task_struct *task)
 }
 
 void perf_get_regs_user(struct perf_regs *regs_user,
-                       struct pt_regs *regs,
-                       struct pt_regs *regs_user_copy)
+                       struct pt_regs *regs)
 {
        regs_user->regs = task_pt_regs(current);
        regs_user->abi = perf_reg_abi(current);
index 336d057..dd8c166 100644 (file)
 #endif
 
 #endif /* CONFIG_SPARSEMEM */
+
+#ifdef CONFIG_MEMORY_HOTPLUG
+int memory_add_physaddr_to_nid(u64 addr);
+#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid
+#endif
+
 #endif /* _ASM_IA64_SPARSEMEM_H */
index a95a894..f0c8303 100644 (file)
@@ -152,6 +152,7 @@ static struct clk __init *alchemy_clk_setup_cpu(const char *parent_name,
 {
        struct clk_init_data id;
        struct clk_hw *h;
+       struct clk *clk;
 
        h = kzalloc(sizeof(*h), GFP_KERNEL);
        if (!h)
@@ -164,7 +165,13 @@ static struct clk __init *alchemy_clk_setup_cpu(const char *parent_name,
        id.ops = &alchemy_clkops_cpu;
        h->init = &id;
 
-       return clk_register(NULL, h);
+       clk = clk_register(NULL, h);
+       if (IS_ERR(clk)) {
+               pr_err("failed to register clock\n");
+               kfree(h);
+       }
+
+       return clk;
 }
 
 /* AUXPLLs ************************************************************/
index 0d42532..ca579de 100644 (file)
@@ -262,8 +262,8 @@ static void __init bootmem_init(void)
 static void __init bootmem_init(void)
 {
        phys_addr_t ramstart, ramend;
-       phys_addr_t start, end;
-       u64 i;
+       unsigned long start, end;
+       int i;
 
        ramstart = memblock_start_of_DRAM();
        ramend = memblock_end_of_DRAM();
@@ -300,7 +300,7 @@ static void __init bootmem_init(void)
 
        min_low_pfn = ARCH_PFN_OFFSET;
        max_pfn = PFN_DOWN(ramend);
-       for_each_mem_range(i, &start, &end) {
+       for_each_mem_pfn_range(i, MAX_NUMNODES, &start, &end, NULL) {
                /*
                 * Skip highmem here so we get an accurate max_low_pfn if low
                 * memory stops short of high memory.
index 38e2894..1b939ab 100644 (file)
@@ -438,6 +438,7 @@ int has_transparent_hugepage(void)
        }
        return mask == PM_HUGE_MASK;
 }
+EXPORT_SYMBOL(has_transparent_hugepage);
 
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE  */
 
index 3ee1ec6..28716e2 100644 (file)
@@ -27,6 +27,7 @@
 #endif
 .endm
 
+#ifdef CONFIG_PPC_KUAP
 .macro kuap_check_amr gpr1, gpr2
 #ifdef CONFIG_PPC_KUAP_DEBUG
        BEGIN_MMU_FTR_SECTION_NESTED(67)
@@ -38,6 +39,7 @@
        END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_RADIX_KUAP, 67)
 #endif
 .endm
+#endif
 
 .macro kuap_save_amr_and_lock gpr1, gpr2, use_cr, msr_pr_cr
 #ifdef CONFIG_PPC_KUAP
@@ -61,6 +63,8 @@
 
 #else /* !__ASSEMBLY__ */
 
+DECLARE_STATIC_KEY_FALSE(uaccess_flush_key);
+
 #ifdef CONFIG_PPC_KUAP
 
 #include <asm/mmu.h>
@@ -103,8 +107,16 @@ static inline void kuap_check_amr(void)
 
 static inline unsigned long get_kuap(void)
 {
+       /*
+        * We return AMR_KUAP_BLOCKED when we don't support KUAP because
+        * prevent_user_access_return needs to return AMR_KUAP_BLOCKED to
+        * cause restore_user_access to do a flush.
+        *
+        * This has no effect in terms of actually blocking things on hash,
+        * so it doesn't break anything.
+        */
        if (!early_mmu_has_feature(MMU_FTR_RADIX_KUAP))
-               return 0;
+               return AMR_KUAP_BLOCKED;
 
        return mfspr(SPRN_AMR);
 }
@@ -123,6 +135,29 @@ static inline void set_kuap(unsigned long value)
        isync();
 }
 
+static inline bool
+bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
+{
+       return WARN(mmu_has_feature(MMU_FTR_RADIX_KUAP) &&
+                   (regs->kuap & (is_write ? AMR_KUAP_BLOCK_WRITE : AMR_KUAP_BLOCK_READ)),
+                   "Bug: %s fault blocked by AMR!", is_write ? "Write" : "Read");
+}
+#else /* CONFIG_PPC_KUAP */
+static inline void kuap_restore_amr(struct pt_regs *regs, unsigned long amr) { }
+
+static inline unsigned long kuap_get_and_check_amr(void)
+{
+       return 0UL;
+}
+
+static inline unsigned long get_kuap(void)
+{
+       return AMR_KUAP_BLOCKED;
+}
+
+static inline void set_kuap(unsigned long value) { }
+#endif /* !CONFIG_PPC_KUAP */
+
 static __always_inline void allow_user_access(void __user *to, const void __user *from,
                                              unsigned long size, unsigned long dir)
 {
@@ -142,6 +177,8 @@ static inline void prevent_user_access(void __user *to, const void __user *from,
                                       unsigned long size, unsigned long dir)
 {
        set_kuap(AMR_KUAP_BLOCKED);
+       if (static_branch_unlikely(&uaccess_flush_key))
+               do_uaccess_flush();
 }
 
 static inline unsigned long prevent_user_access_return(void)
@@ -149,6 +186,8 @@ static inline unsigned long prevent_user_access_return(void)
        unsigned long flags = get_kuap();
 
        set_kuap(AMR_KUAP_BLOCKED);
+       if (static_branch_unlikely(&uaccess_flush_key))
+               do_uaccess_flush();
 
        return flags;
 }
@@ -156,30 +195,9 @@ static inline unsigned long prevent_user_access_return(void)
 static inline void restore_user_access(unsigned long flags)
 {
        set_kuap(flags);
+       if (static_branch_unlikely(&uaccess_flush_key) && flags == AMR_KUAP_BLOCKED)
+               do_uaccess_flush();
 }
-
-static inline bool
-bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
-{
-       return WARN(mmu_has_feature(MMU_FTR_RADIX_KUAP) &&
-                   (regs->kuap & (is_write ? AMR_KUAP_BLOCK_WRITE : AMR_KUAP_BLOCK_READ)),
-                   "Bug: %s fault blocked by AMR!", is_write ? "Write" : "Read");
-}
-#else /* CONFIG_PPC_KUAP */
-static inline void kuap_restore_amr(struct pt_regs *regs, unsigned long amr)
-{
-}
-
-static inline void kuap_check_amr(void)
-{
-}
-
-static inline unsigned long kuap_get_and_check_amr(void)
-{
-       return 0;
-}
-#endif /* CONFIG_PPC_KUAP */
-
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_POWERPC_BOOK3S_64_KUP_RADIX_H */
index ebe95aa..1d32b17 100644 (file)
        nop;                                                            \
        nop
 
+#define ENTRY_FLUSH_SLOT                                               \
+       ENTRY_FLUSH_FIXUP_SECTION;                                      \
+       nop;                                                            \
+       nop;                                                            \
+       nop;
+
 /*
  * r10 must be free to use, r13 must be paca
  */
 #define INTERRUPT_TO_KERNEL                                            \
-       STF_ENTRY_BARRIER_SLOT
+       STF_ENTRY_BARRIER_SLOT;                                         \
+       ENTRY_FLUSH_SLOT
 
 /*
  * Macros for annotating the expected destination of (h)rfid
        RFSCV;                                                          \
        b       rfscv_flush_fallback
 
+#else /* __ASSEMBLY__ */
+/* Prototype for function defined in exceptions-64s.S */
+void do_uaccess_flush(void);
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_POWERPC_EXCEPTION_H */
index b0af97a..fbd406c 100644 (file)
@@ -205,6 +205,22 @@ label##3:                                          \
        FTR_ENTRY_OFFSET 955b-956b;                     \
        .popsection;
 
+#define UACCESS_FLUSH_FIXUP_SECTION                    \
+959:                                                   \
+       .pushsection __uaccess_flush_fixup,"a";         \
+       .align 2;                                       \
+960:                                                   \
+       FTR_ENTRY_OFFSET 959b-960b;                     \
+       .popsection;
+
+#define ENTRY_FLUSH_FIXUP_SECTION                      \
+957:                                                   \
+       .pushsection __entry_flush_fixup,"a";           \
+       .align 2;                                       \
+958:                                                   \
+       FTR_ENTRY_OFFSET 957b-958b;                     \
+       .popsection;
+
 #define RFI_FLUSH_FIXUP_SECTION                                \
 951:                                                   \
        .pushsection __rfi_flush_fixup,"a";             \
@@ -237,8 +253,11 @@ label##3:                                          \
 #include <linux/types.h>
 
 extern long stf_barrier_fallback;
+extern long entry_flush_fallback;
 extern long __start___stf_entry_barrier_fixup, __stop___stf_entry_barrier_fixup;
 extern long __start___stf_exit_barrier_fixup, __stop___stf_exit_barrier_fixup;
+extern long __start___uaccess_flush_fixup, __stop___uaccess_flush_fixup;
+extern long __start___entry_flush_fixup, __stop___entry_flush_fixup;
 extern long __start___rfi_flush_fixup, __stop___rfi_flush_fixup;
 extern long __start___barrier_nospec_fixup, __stop___barrier_nospec_fixup;
 extern long __start__btb_flush_fixup, __stop__btb_flush_fixup;
index 1d0f7d8..0d93331 100644 (file)
@@ -14,7 +14,7 @@
 #define KUAP_CURRENT_WRITE     8
 #define KUAP_CURRENT           (KUAP_CURRENT_READ | KUAP_CURRENT_WRITE)
 
-#ifdef CONFIG_PPC64
+#ifdef CONFIG_PPC_BOOK3S_64
 #include <asm/book3s/64/kup-radix.h>
 #endif
 #ifdef CONFIG_PPC_8xx
@@ -35,6 +35,9 @@
 .macro kuap_check      current, gpr
 .endm
 
+.macro kuap_check_amr  gpr1, gpr2
+.endm
+
 #endif
 
 #else /* !__ASSEMBLY__ */
@@ -53,17 +56,28 @@ static inline void setup_kuep(bool disabled) { }
 void setup_kuap(bool disabled);
 #else
 static inline void setup_kuap(bool disabled) { }
+
+static inline bool
+bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
+{
+       return false;
+}
+
+static inline void kuap_check_amr(void) { }
+
+/*
+ * book3s/64/kup-radix.h defines these functions for the !KUAP case to flush
+ * the L1D cache after user accesses. Only include the empty stubs for other
+ * platforms.
+ */
+#ifndef CONFIG_PPC_BOOK3S_64
 static inline void allow_user_access(void __user *to, const void __user *from,
                                     unsigned long size, unsigned long dir) { }
 static inline void prevent_user_access(void __user *to, const void __user *from,
                                       unsigned long size, unsigned long dir) { }
 static inline unsigned long prevent_user_access_return(void) { return 0UL; }
 static inline void restore_user_access(unsigned long flags) { }
-static inline bool
-bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
-{
-       return false;
-}
+#endif /* CONFIG_PPC_BOOK3S_64 */
 #endif /* CONFIG_PPC_KUAP */
 
 static inline void allow_read_from_user(const void __user *from, unsigned long size)
index 91c69ff..6cda76b 100644 (file)
@@ -46,5 +46,10 @@ u64 memory_hotplug_max(void);
 #define __HAVE_ARCH_RESERVED_KERNEL_PAGES
 #endif
 
+#ifdef CONFIG_MEMORY_HOTPLUG
+extern int create_section_mapping(unsigned long start, unsigned long end,
+                                 int nid, pgprot_t prot);
+#endif
+
 #endif /* __KERNEL__ */
 #endif /* _ASM_MMZONE_H_ */
index 85ed239..567cdc5 100644 (file)
@@ -63,7 +63,7 @@ static inline void restore_user_access(unsigned long flags)
 static inline bool
 bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
 {
-       return WARN(!((regs->kuap ^ MD_APG_KUAP) & 0xf0000000),
+       return WARN(!((regs->kuap ^ MD_APG_KUAP) & 0xff000000),
                    "Bug: fault blocked by AP register !");
 }
 
index 1d9ac0f..0bd1b14 100644 (file)
  * respectively NA for All or X for Supervisor and no access for User.
  * Then we use the APG to say whether accesses are according to Page rules or
  * "all Supervisor" rules (Access to all)
- * Therefore, we define 2 APG groups. lsb is _PMD_USER
- * 0 => Kernel => 01 (all accesses performed according to page definition)
- * 1 => User => 00 (all accesses performed as supervisor iaw page definition)
- * 2-15 => Not Used
- */
-#define MI_APG_INIT    0x40000000
-
-/*
- * 0 => Kernel => 01 (all accesses performed according to page definition)
- * 1 => User => 10 (all accesses performed according to swaped page definition)
- * 2-15 => Not Used
- */
-#define MI_APG_KUEP    0x60000000
+ * _PAGE_ACCESSED is also managed via APG. When _PAGE_ACCESSED is not set, say
+ * "all User" rules, that will lead to NA for all.
+ * Therefore, we define 4 APG groups. lsb is _PAGE_ACCESSED
+ * 0 => Kernel => 11 (all accesses performed according as user iaw page definition)
+ * 1 => Kernel+Accessed => 01 (all accesses performed according to page definition)
+ * 2 => User => 11 (all accesses performed according as user iaw page definition)
+ * 3 => User+Accessed => 00 (all accesses performed as supervisor iaw page definition) for INIT
+ *                    => 10 (all accesses performed according to swaped page definition) for KUEP
+ * 4-15 => Not Used
+ */
+#define MI_APG_INIT    0xdc000000
+#define MI_APG_KUEP    0xde000000
 
 /* The effective page number register.  When read, contains the information
  * about the last instruction TLB miss.  When MI_RPN is written, bits in
 #define MD_Ks          0x80000000      /* Should not be set */
 #define MD_Kp          0x40000000      /* Should always be set */
 
-/*
- * All pages' PP data bits are set to either 000 or 011 or 001, which means
- * respectively RW for Supervisor and no access for User, or RO for
- * Supervisor and no access for user and NA for ALL.
- * Then we use the APG to say whether accesses are according to Page rules or
- * "all Supervisor" rules (Access to all)
- * Therefore, we define 2 APG groups. lsb is _PMD_USER
- * 0 => Kernel => 01 (all accesses performed according to page definition)
- * 1 => User => 00 (all accesses performed as supervisor iaw page definition)
- * 2-15 => Not Used
- */
-#define MD_APG_INIT    0x40000000
-
-/*
- * 0 => No user => 01 (all accesses performed according to page definition)
- * 1 => User => 10 (all accesses performed according to swaped page definition)
- * 2-15 => Not Used
- */
-#define MD_APG_KUAP    0x60000000
+/* See explanation above at the definition of MI_APG_INIT */
+#define MD_APG_INIT    0xdc000000
+#define MD_APG_KUAP    0xde000000
 
 /* The effective page number register.  When read, contains the information
  * about the last instruction TLB miss.  When MD_RPN is written, bits in
index 66f403a..1581204 100644 (file)
@@ -39,9 +39,9 @@
  * into the TLB.
  */
 #define _PAGE_GUARDED  0x0010  /* Copied to L1 G entry in DTLB */
-#define _PAGE_SPECIAL  0x0020  /* SW entry */
+#define _PAGE_ACCESSED 0x0020  /* Copied to L1 APG 1 entry in I/DTLB */
 #define _PAGE_EXEC     0x0040  /* Copied to PP (bit 21) in ITLB */
-#define _PAGE_ACCESSED 0x0080  /* software: page referenced */
+#define _PAGE_SPECIAL  0x0080  /* SW entry */
 
 #define _PAGE_NA       0x0200  /* Supervisor NA, User no access */
 #define _PAGE_RO       0x0600  /* Supervisor RO, User no access */
 
 #define _PMD_PRESENT   0x0001
 #define _PMD_PRESENT_MASK      _PMD_PRESENT
-#define _PMD_BAD       0x0fd0
+#define _PMD_BAD       0x0f90
 #define _PMD_PAGE_MASK 0x000c
 #define _PMD_PAGE_8M   0x000c
 #define _PMD_PAGE_512K 0x0004
-#define _PMD_USER      0x0020  /* APG 1 */
+#define _PMD_ACCESSED  0x0020  /* APG 1 */
+#define _PMD_USER      0x0040  /* APG 2 */
 
 #define _PTE_NONE_MASK 0
 
index fbb8fa3..b774a44 100644 (file)
@@ -86,12 +86,19 @@ static inline bool security_ftr_enabled(u64 feature)
 // Software required to flush link stack on context switch
 #define SEC_FTR_FLUSH_LINK_STACK       0x0000000000001000ull
 
+// The L1-D cache should be flushed when entering the kernel
+#define SEC_FTR_L1D_FLUSH_ENTRY                0x0000000000004000ull
+
+// The L1-D cache should be flushed after user accesses from the kernel
+#define SEC_FTR_L1D_FLUSH_UACCESS      0x0000000000008000ull
 
 // Features enabled by default
 #define SEC_FTR_DEFAULT \
        (SEC_FTR_L1D_FLUSH_HV | \
         SEC_FTR_L1D_FLUSH_PR | \
         SEC_FTR_BNDS_CHK_SPEC_BAR | \
+        SEC_FTR_L1D_FLUSH_ENTRY | \
+        SEC_FTR_L1D_FLUSH_UACCESS | \
         SEC_FTR_FAVOUR_SECURITY)
 
 #endif /* _ASM_POWERPC_SECURITY_FEATURES_H */
index 9efbdde..a466749 100644 (file)
@@ -52,12 +52,16 @@ enum l1d_flush_type {
 };
 
 void setup_rfi_flush(enum l1d_flush_type, bool enable);
+void setup_entry_flush(bool enable);
+void setup_uaccess_flush(bool enable);
 void do_rfi_flush_fixups(enum l1d_flush_type types);
 #ifdef CONFIG_PPC_BARRIER_NOSPEC
 void setup_barrier_nospec(void);
 #else
 static inline void setup_barrier_nospec(void) { };
 #endif
+void do_uaccess_flush_fixups(enum l1d_flush_type types);
+void do_entry_flush_fixups(enum l1d_flush_type types);
 void do_barrier_nospec_fixups(bool enable);
 extern bool barrier_nospec_enabled;
 
index 1e6fa37..d072866 100644 (file)
@@ -13,9 +13,9 @@
 #endif /* CONFIG_SPARSEMEM */
 
 #ifdef CONFIG_MEMORY_HOTPLUG
-extern int create_section_mapping(unsigned long start, unsigned long end,
-                                 int nid, pgprot_t prot);
 extern int remove_section_mapping(unsigned long start, unsigned long end);
+extern int memory_add_physaddr_to_nid(u64 start);
+#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid
 
 #ifdef CONFIG_NUMA
 extern int hot_add_scn_to_nid(unsigned long scn_addr);
@@ -26,6 +26,5 @@ static inline int hot_add_scn_to_nid(unsigned long scn_addr)
 }
 #endif /* CONFIG_NUMA */
 #endif /* CONFIG_MEMORY_HOTPLUG */
-
 #endif /* __KERNEL__ */
 #endif /* _ASM_POWERPC_SPARSEMEM_H */
index 8728590..3beeb03 100644 (file)
@@ -6,6 +6,7 @@
 
 struct device;
 struct device_node;
+struct drmem_lmb;
 
 #ifdef CONFIG_NUMA
 
@@ -61,6 +62,9 @@ static inline int early_cpu_to_node(int cpu)
         */
        return (nid < 0) ? 0 : nid;
 }
+
+int of_drconf_to_nid_single(struct drmem_lmb *lmb);
+
 #else
 
 static inline int early_cpu_to_node(int cpu) { return 0; }
@@ -84,10 +88,12 @@ static inline int cpu_distance(__be32 *cpu1_assoc, __be32 *cpu2_assoc)
        return 0;
 }
 
-#endif /* CONFIG_NUMA */
+static inline int of_drconf_to_nid_single(struct drmem_lmb *lmb)
+{
+       return first_online_node;
+}
 
-struct drmem_lmb;
-int of_drconf_to_nid_single(struct drmem_lmb *lmb);
+#endif /* CONFIG_NUMA */
 
 #if defined(CONFIG_NUMA) && defined(CONFIG_PPC_SPLPAR)
 extern int find_and_online_cpu_nid(int cpu);
index ef5bbb7..501c9a7 100644 (file)
@@ -178,7 +178,7 @@ do {                                                                \
  * are no aliasing issues.
  */
 #define __put_user_asm_goto(x, addr, label, op)                        \
-       asm volatile goto(                                      \
+       asm_volatile_goto(                                      \
                "1:     " op "%U1%X1 %0,%1      # put_user\n"   \
                EX_TABLE(1b, %l2)                               \
                :                                               \
@@ -191,7 +191,7 @@ do {                                                                \
        __put_user_asm_goto(x, ptr, label, "std")
 #else /* __powerpc64__ */
 #define __put_user_asm2_goto(x, addr, label)                   \
-       asm volatile goto(                                      \
+       asm_volatile_goto(                                      \
                "1:     stw%X1 %0, %1\n"                        \
                "2:     stw%X1 %L0, %L1\n"                      \
                EX_TABLE(1b, %l2)                               \
index 6b50bf1..bf32704 100644 (file)
@@ -264,8 +264,9 @@ static int eeh_addr_cache_show(struct seq_file *s, void *v)
 {
        struct pci_io_addr_range *piar;
        struct rb_node *n;
+       unsigned long flags;
 
-       spin_lock(&pci_io_addr_cache_root.piar_lock);
+       spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
        for (n = rb_first(&pci_io_addr_cache_root.rb_root); n; n = rb_next(n)) {
                piar = rb_entry(n, struct pci_io_addr_range, rb_node);
 
@@ -273,7 +274,7 @@ static int eeh_addr_cache_show(struct seq_file *s, void *v)
                       (piar->flags & IORESOURCE_IO) ? "i/o" : "mem",
                       &piar->addr_lo, &piar->addr_hi, pci_name(piar->pcidev));
        }
-       spin_unlock(&pci_io_addr_cache_root.piar_lock);
+       spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
 
        return 0;
 }
index f7d748b..f63a3d3 100644 (file)
@@ -2951,15 +2951,8 @@ TRAMP_REAL_BEGIN(stf_barrier_fallback)
        .endr
        blr
 
-TRAMP_REAL_BEGIN(rfi_flush_fallback)
-       SET_SCRATCH0(r13);
-       GET_PACA(r13);
-       std     r1,PACA_EXRFI+EX_R12(r13)
-       ld      r1,PACAKSAVE(r13)
-       std     r9,PACA_EXRFI+EX_R9(r13)
-       std     r10,PACA_EXRFI+EX_R10(r13)
-       std     r11,PACA_EXRFI+EX_R11(r13)
-       mfctr   r9
+/* Clobbers r10, r11, ctr */
+.macro L1D_DISPLACEMENT_FLUSH
        ld      r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
        ld      r11,PACA_L1D_FLUSH_SIZE(r13)
        srdi    r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */
@@ -2970,7 +2963,7 @@ TRAMP_REAL_BEGIN(rfi_flush_fallback)
        sync
 
        /*
-        * The load adresses are at staggered offsets within cachelines,
+        * The load addresses are at staggered offsets within cachelines,
         * which suits some pipelines better (on others it should not
         * hurt).
         */
@@ -2985,7 +2978,30 @@ TRAMP_REAL_BEGIN(rfi_flush_fallback)
        ld      r11,(0x80 + 8)*7(r10)
        addi    r10,r10,0x80*8
        bdnz    1b
+.endm
+
+TRAMP_REAL_BEGIN(entry_flush_fallback)
+       std     r9,PACA_EXRFI+EX_R9(r13)
+       std     r10,PACA_EXRFI+EX_R10(r13)
+       std     r11,PACA_EXRFI+EX_R11(r13)
+       mfctr   r9
+       L1D_DISPLACEMENT_FLUSH
+       mtctr   r9
+       ld      r9,PACA_EXRFI+EX_R9(r13)
+       ld      r10,PACA_EXRFI+EX_R10(r13)
+       ld      r11,PACA_EXRFI+EX_R11(r13)
+       blr
 
+TRAMP_REAL_BEGIN(rfi_flush_fallback)
+       SET_SCRATCH0(r13);
+       GET_PACA(r13);
+       std     r1,PACA_EXRFI+EX_R12(r13)
+       ld      r1,PACAKSAVE(r13)
+       std     r9,PACA_EXRFI+EX_R9(r13)
+       std     r10,PACA_EXRFI+EX_R10(r13)
+       std     r11,PACA_EXRFI+EX_R11(r13)
+       mfctr   r9
+       L1D_DISPLACEMENT_FLUSH
        mtctr   r9
        ld      r9,PACA_EXRFI+EX_R9(r13)
        ld      r10,PACA_EXRFI+EX_R10(r13)
@@ -3003,32 +3019,7 @@ TRAMP_REAL_BEGIN(hrfi_flush_fallback)
        std     r10,PACA_EXRFI+EX_R10(r13)
        std     r11,PACA_EXRFI+EX_R11(r13)
        mfctr   r9
-       ld      r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
-       ld      r11,PACA_L1D_FLUSH_SIZE(r13)
-       srdi    r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */
-       mtctr   r11
-       DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
-
-       /* order ld/st prior to dcbt stop all streams with flushing */
-       sync
-
-       /*
-        * The load adresses are at staggered offsets within cachelines,
-        * which suits some pipelines better (on others it should not
-        * hurt).
-        */
-1:
-       ld      r11,(0x80 + 8)*0(r10)
-       ld      r11,(0x80 + 8)*1(r10)
-       ld      r11,(0x80 + 8)*2(r10)
-       ld      r11,(0x80 + 8)*3(r10)
-       ld      r11,(0x80 + 8)*4(r10)
-       ld      r11,(0x80 + 8)*5(r10)
-       ld      r11,(0x80 + 8)*6(r10)
-       ld      r11,(0x80 + 8)*7(r10)
-       addi    r10,r10,0x80*8
-       bdnz    1b
-
+       L1D_DISPLACEMENT_FLUSH
        mtctr   r9
        ld      r9,PACA_EXRFI+EX_R9(r13)
        ld      r10,PACA_EXRFI+EX_R10(r13)
@@ -3079,8 +3070,21 @@ TRAMP_REAL_BEGIN(rfscv_flush_fallback)
        RFSCV
 
 USE_TEXT_SECTION()
-       MASKED_INTERRUPT
-       MASKED_INTERRUPT hsrr=1
+
+_GLOBAL(do_uaccess_flush)
+       UACCESS_FLUSH_FIXUP_SECTION
+       nop
+       nop
+       nop
+       blr
+       L1D_DISPLACEMENT_FLUSH
+       blr
+_ASM_NOKPROBE_SYMBOL(do_uaccess_flush)
+EXPORT_SYMBOL(do_uaccess_flush)
+
+
+MASKED_INTERRUPT
+MASKED_INTERRUPT hsrr=1
 
 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
 kvmppc_skip_interrupt:
index 44c9018..a1ae006 100644 (file)
@@ -284,11 +284,7 @@ _ENTRY(saved_ksp_limit)
 
        rlwimi  r11, r10, 22, 20, 29    /* Compute PTE address */
        lwz     r11, 0(r11)             /* Get Linux PTE */
-#ifdef CONFIG_SWAP
        li      r9, _PAGE_PRESENT | _PAGE_ACCESSED
-#else
-       li      r9, _PAGE_PRESENT
-#endif
        andc.   r9, r9, r11             /* Check permission */
        bne     5f
 
@@ -369,11 +365,7 @@ _ENTRY(saved_ksp_limit)
 
        rlwimi  r11, r10, 22, 20, 29    /* Compute PTE address */
        lwz     r11, 0(r11)             /* Get Linux PTE */
-#ifdef CONFIG_SWAP
        li      r9, _PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
-#else
-       li      r9, _PAGE_PRESENT | _PAGE_EXEC
-#endif
        andc.   r9, r9, r11             /* Check permission */
        bne     5f
 
index 9f359d3..ee0bfeb 100644 (file)
@@ -202,9 +202,7 @@ SystemCall:
 
 InstructionTLBMiss:
        mtspr   SPRN_SPRG_SCRATCH0, r10
-#if defined(ITLB_MISS_KERNEL) || defined(CONFIG_SWAP) || defined(CONFIG_HUGETLBFS)
        mtspr   SPRN_SPRG_SCRATCH1, r11
-#endif
 
        /* If we are faulting a kernel address, we have to use the
         * kernel page tables.
@@ -224,25 +222,13 @@ InstructionTLBMiss:
 3:
        mtcr    r11
 #endif
-#if defined(CONFIG_HUGETLBFS) || !defined(CONFIG_PIN_TLB_TEXT)
        lwz     r11, (swapper_pg_dir-PAGE_OFFSET)@l(r10)        /* Get level 1 entry */
        mtspr   SPRN_MD_TWC, r11
-#else
-       lwz     r10, (swapper_pg_dir-PAGE_OFFSET)@l(r10)        /* Get level 1 entry */
-       mtspr   SPRN_MI_TWC, r10        /* Set segment attributes */
-       mtspr   SPRN_MD_TWC, r10
-#endif
        mfspr   r10, SPRN_MD_TWC
        lwz     r10, 0(r10)     /* Get the pte */
-#if defined(CONFIG_HUGETLBFS) || !defined(CONFIG_PIN_TLB_TEXT)
+       rlwimi  r11, r10, 0, _PAGE_GUARDED | _PAGE_ACCESSED
        rlwimi  r11, r10, 32 - 9, _PMD_PAGE_512K
        mtspr   SPRN_MI_TWC, r11
-#endif
-#ifdef CONFIG_SWAP
-       rlwinm  r11, r10, 32-5, _PAGE_PRESENT
-       and     r11, r11, r10
-       rlwimi  r10, r11, 0, _PAGE_PRESENT
-#endif
        /* The Linux PTE won't go exactly into the MMU TLB.
         * Software indicator bits 20 and 23 must be clear.
         * Software indicator bits 22, 24, 25, 26, and 27 must be
@@ -256,9 +242,7 @@ InstructionTLBMiss:
 
        /* Restore registers */
 0:     mfspr   r10, SPRN_SPRG_SCRATCH0
-#if defined(ITLB_MISS_KERNEL) || defined(CONFIG_SWAP) || defined(CONFIG_HUGETLBFS)
        mfspr   r11, SPRN_SPRG_SCRATCH1
-#endif
        rfi
        patch_site      0b, patch__itlbmiss_exit_1
 
@@ -268,9 +252,7 @@ InstructionTLBMiss:
        addi    r10, r10, 1
        stw     r10, (itlb_miss_counter - PAGE_OFFSET)@l(0)
        mfspr   r10, SPRN_SPRG_SCRATCH0
-#if defined(ITLB_MISS_KERNEL) || defined(CONFIG_SWAP)
        mfspr   r11, SPRN_SPRG_SCRATCH1
-#endif
        rfi
 #endif
 
@@ -297,30 +279,16 @@ DataStoreTLBMiss:
        mfspr   r10, SPRN_MD_TWC
        lwz     r10, 0(r10)     /* Get the pte */
 
-       /* Insert the Guarded flag into the TWC from the Linux PTE.
+       /* Insert Guarded and Accessed flags into the TWC from the Linux PTE.
         * It is bit 27 of both the Linux PTE and the TWC (at least
         * I got that right :-).  It will be better when we can put
         * this into the Linux pgd/pmd and load it in the operation
         * above.
         */
-       rlwimi  r11, r10, 0, _PAGE_GUARDED
+       rlwimi  r11, r10, 0, _PAGE_GUARDED | _PAGE_ACCESSED
        rlwimi  r11, r10, 32 - 9, _PMD_PAGE_512K
        mtspr   SPRN_MD_TWC, r11
 
-       /* Both _PAGE_ACCESSED and _PAGE_PRESENT has to be set.
-        * We also need to know if the insn is a load/store, so:
-        * Clear _PAGE_PRESENT and load that which will
-        * trap into DTLB Error with store bit set accordinly.
-        */
-       /* PRESENT=0x1, ACCESSED=0x20
-        * r11 = ((r10 & PRESENT) & ((r10 & ACCESSED) >> 5));
-        * r10 = (r10 & ~PRESENT) | r11;
-        */
-#ifdef CONFIG_SWAP
-       rlwinm  r11, r10, 32-5, _PAGE_PRESENT
-       and     r11, r11, r10
-       rlwimi  r10, r11, 0, _PAGE_PRESENT
-#endif
        /* The Linux PTE won't go exactly into the MMU TLB.
         * Software indicator bits 24, 25, 26, and 27 must be
         * set.  All other Linux PTE bits control the behavior
@@ -711,7 +679,7 @@ initial_mmu:
        li      r9, 4                           /* up to 4 pages of 8M */
        mtctr   r9
        lis     r9, KERNELBASE@h                /* Create vaddr for TLB */
-       li      r10, MI_PS8MEG | MI_SVALID      /* Set 8M byte page */
+       li      r10, MI_PS8MEG | _PMD_ACCESSED | MI_SVALID
        li      r11, MI_BOOTINIT                /* Create RPN for address 0 */
 1:
        mtspr   SPRN_MI_CTR, r8 /* Set instruction MMU control */
@@ -775,7 +743,7 @@ _GLOBAL(mmu_pin_tlb)
 #ifdef CONFIG_PIN_TLB_TEXT
        LOAD_REG_IMMEDIATE(r5, 28 << 8)
        LOAD_REG_IMMEDIATE(r6, PAGE_OFFSET)
-       LOAD_REG_IMMEDIATE(r7, MI_SVALID | MI_PS8MEG)
+       LOAD_REG_IMMEDIATE(r7, MI_SVALID | MI_PS8MEG | _PMD_ACCESSED)
        LOAD_REG_IMMEDIATE(r8, 0xf0 | _PAGE_RO | _PAGE_SPS | _PAGE_SH | _PAGE_PRESENT)
        LOAD_REG_ADDR(r9, _sinittext)
        li      r0, 4
@@ -797,7 +765,7 @@ _GLOBAL(mmu_pin_tlb)
        LOAD_REG_IMMEDIATE(r5, 28 << 8 | MD_TWAM)
 #ifdef CONFIG_PIN_TLB_DATA
        LOAD_REG_IMMEDIATE(r6, PAGE_OFFSET)
-       LOAD_REG_IMMEDIATE(r7, MI_SVALID | MI_PS8MEG)
+       LOAD_REG_IMMEDIATE(r7, MI_SVALID | MI_PS8MEG | _PMD_ACCESSED)
 #ifdef CONFIG_PIN_TLB_IMMR
        li      r0, 3
 #else
@@ -834,7 +802,7 @@ _GLOBAL(mmu_pin_tlb)
 #endif
 #ifdef CONFIG_PIN_TLB_IMMR
        LOAD_REG_IMMEDIATE(r0, VIRT_IMMR_BASE | MD_EVALID)
-       LOAD_REG_IMMEDIATE(r7, MD_SVALID | MD_PS512K | MD_GUARDED)
+       LOAD_REG_IMMEDIATE(r7, MD_SVALID | MD_PS512K | MD_GUARDED | _PMD_ACCESSED)
        mfspr   r8, SPRN_IMMR
        rlwinm  r8, r8, 0, 0xfff80000
        ori     r8, r8, 0xf0 | _PAGE_DIRTY | _PAGE_SPS | _PAGE_SH | \
index 5eb9eed..2aa16d5 100644 (file)
@@ -457,11 +457,7 @@ InstructionTLBMiss:
        cmplw   0,r1,r3
 #endif
        mfspr   r2, SPRN_SPRG_PGDIR
-#ifdef CONFIG_SWAP
        li      r1,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
-#else
-       li      r1,_PAGE_PRESENT | _PAGE_EXEC
-#endif
 #if defined(CONFIG_MODULES) || defined(CONFIG_DEBUG_PAGEALLOC)
        bgt-    112f
        lis     r2, (swapper_pg_dir - PAGE_OFFSET)@ha   /* if kernel address, use */
@@ -523,11 +519,7 @@ DataLoadTLBMiss:
        lis     r1, TASK_SIZE@h         /* check if kernel address */
        cmplw   0,r1,r3
        mfspr   r2, SPRN_SPRG_PGDIR
-#ifdef CONFIG_SWAP
        li      r1, _PAGE_PRESENT | _PAGE_ACCESSED
-#else
-       li      r1, _PAGE_PRESENT
-#endif
        bgt-    112f
        lis     r2, (swapper_pg_dir - PAGE_OFFSET)@ha   /* if kernel address, use */
        addi    r2, r2, (swapper_pg_dir - PAGE_OFFSET)@l        /* kernel page table */
@@ -603,11 +595,7 @@ DataStoreTLBMiss:
        lis     r1, TASK_SIZE@h         /* check if kernel address */
        cmplw   0,r1,r3
        mfspr   r2, SPRN_SPRG_PGDIR
-#ifdef CONFIG_SWAP
        li      r1, _PAGE_RW | _PAGE_DIRTY | _PAGE_PRESENT | _PAGE_ACCESSED
-#else
-       li      r1, _PAGE_RW | _PAGE_DIRTY | _PAGE_PRESENT
-#endif
        bgt-    112f
        lis     r2, (swapper_pg_dir - PAGE_OFFSET)@ha   /* if kernel address, use */
        addi    r2, r2, (swapper_pg_dir - PAGE_OFFSET)@l        /* kernel page table */
index bb9cab3..74fd47f 100644 (file)
@@ -945,7 +945,13 @@ early_initcall(disable_hardlockup_detector);
 static enum l1d_flush_type enabled_flush_types;
 static void *l1d_flush_fallback_area;
 static bool no_rfi_flush;
+static bool no_entry_flush;
+static bool no_uaccess_flush;
 bool rfi_flush;
+bool entry_flush;
+bool uaccess_flush;
+DEFINE_STATIC_KEY_FALSE(uaccess_flush_key);
+EXPORT_SYMBOL(uaccess_flush_key);
 
 static int __init handle_no_rfi_flush(char *p)
 {
@@ -955,6 +961,22 @@ static int __init handle_no_rfi_flush(char *p)
 }
 early_param("no_rfi_flush", handle_no_rfi_flush);
 
+static int __init handle_no_entry_flush(char *p)
+{
+       pr_info("entry-flush: disabled on command line.");
+       no_entry_flush = true;
+       return 0;
+}
+early_param("no_entry_flush", handle_no_entry_flush);
+
+static int __init handle_no_uaccess_flush(char *p)
+{
+       pr_info("uaccess-flush: disabled on command line.");
+       no_uaccess_flush = true;
+       return 0;
+}
+early_param("no_uaccess_flush", handle_no_uaccess_flush);
+
 /*
  * The RFI flush is not KPTI, but because users will see doco that says to use
  * nopti we hijack that option here to also disable the RFI flush.
@@ -986,6 +1008,32 @@ void rfi_flush_enable(bool enable)
        rfi_flush = enable;
 }
 
+void entry_flush_enable(bool enable)
+{
+       if (enable) {
+               do_entry_flush_fixups(enabled_flush_types);
+               on_each_cpu(do_nothing, NULL, 1);
+       } else {
+               do_entry_flush_fixups(L1D_FLUSH_NONE);
+       }
+
+       entry_flush = enable;
+}
+
+void uaccess_flush_enable(bool enable)
+{
+       if (enable) {
+               do_uaccess_flush_fixups(enabled_flush_types);
+               static_branch_enable(&uaccess_flush_key);
+               on_each_cpu(do_nothing, NULL, 1);
+       } else {
+               static_branch_disable(&uaccess_flush_key);
+               do_uaccess_flush_fixups(L1D_FLUSH_NONE);
+       }
+
+       uaccess_flush = enable;
+}
+
 static void __ref init_fallback_flush(void)
 {
        u64 l1d_size, limit;
@@ -1044,10 +1092,28 @@ void setup_rfi_flush(enum l1d_flush_type types, bool enable)
 
        enabled_flush_types = types;
 
-       if (!no_rfi_flush && !cpu_mitigations_off())
+       if (!cpu_mitigations_off() && !no_rfi_flush)
                rfi_flush_enable(enable);
 }
 
+void setup_entry_flush(bool enable)
+{
+       if (cpu_mitigations_off())
+               return;
+
+       if (!no_entry_flush)
+               entry_flush_enable(enable);
+}
+
+void setup_uaccess_flush(bool enable)
+{
+       if (cpu_mitigations_off())
+               return;
+
+       if (!no_uaccess_flush)
+               uaccess_flush_enable(enable);
+}
+
 #ifdef CONFIG_DEBUG_FS
 static int rfi_flush_set(void *data, u64 val)
 {
@@ -1075,9 +1141,63 @@ static int rfi_flush_get(void *data, u64 *val)
 
 DEFINE_SIMPLE_ATTRIBUTE(fops_rfi_flush, rfi_flush_get, rfi_flush_set, "%llu\n");
 
+static int entry_flush_set(void *data, u64 val)
+{
+       bool enable;
+
+       if (val == 1)
+               enable = true;
+       else if (val == 0)
+               enable = false;
+       else
+               return -EINVAL;
+
+       /* Only do anything if we're changing state */
+       if (enable != entry_flush)
+               entry_flush_enable(enable);
+
+       return 0;
+}
+
+static int entry_flush_get(void *data, u64 *val)
+{
+       *val = entry_flush ? 1 : 0;
+       return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(fops_entry_flush, entry_flush_get, entry_flush_set, "%llu\n");
+
+static int uaccess_flush_set(void *data, u64 val)
+{
+       bool enable;
+
+       if (val == 1)
+               enable = true;
+       else if (val == 0)
+               enable = false;
+       else
+               return -EINVAL;
+
+       /* Only do anything if we're changing state */
+       if (enable != uaccess_flush)
+               uaccess_flush_enable(enable);
+
+       return 0;
+}
+
+static int uaccess_flush_get(void *data, u64 *val)
+{
+       *val = uaccess_flush ? 1 : 0;
+       return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(fops_uaccess_flush, uaccess_flush_get, uaccess_flush_set, "%llu\n");
+
 static __init int rfi_flush_debugfs_init(void)
 {
        debugfs_create_file("rfi_flush", 0600, powerpc_debugfs_root, NULL, &fops_rfi_flush);
+       debugfs_create_file("entry_flush", 0600, powerpc_debugfs_root, NULL, &fops_entry_flush);
+       debugfs_create_file("uaccess_flush", 0600, powerpc_debugfs_root, NULL, &fops_uaccess_flush);
        return 0;
 }
 device_initcall(rfi_flush_debugfs_init);
index 3c6b982..8c2857c 100644 (file)
@@ -1393,13 +1393,14 @@ static void add_cpu_to_masks(int cpu)
 /* Activate a secondary processor. */
 void start_secondary(void *unused)
 {
-       unsigned int cpu = smp_processor_id();
+       unsigned int cpu = raw_smp_processor_id();
 
        mmgrab(&init_mm);
        current->active_mm = &init_mm;
 
        smp_store_cpu_info(cpu);
        set_dec(tb_ticks_per_jiffy);
+       rcu_cpu_starting(cpu);
        preempt_disable();
        cpu_callin_map[cpu] = 1;
 
index 8e50818..310bcd7 100644 (file)
@@ -2,7 +2,7 @@
 
 #include <linux/err.h>
 #include <asm/asm-prototypes.h>
-#include <asm/book3s/64/kup-radix.h>
+#include <asm/kup.h>
 #include <asm/cputime.h>
 #include <asm/hw_irq.h>
 #include <asm/kprobes.h>
index e0548b4..6db90cd 100644 (file)
@@ -131,6 +131,20 @@ SECTIONS
                __stop___stf_entry_barrier_fixup = .;
        }
 
+       . = ALIGN(8);
+       __uaccess_flush_fixup : AT(ADDR(__uaccess_flush_fixup) - LOAD_OFFSET) {
+               __start___uaccess_flush_fixup = .;
+               *(__uaccess_flush_fixup)
+               __stop___uaccess_flush_fixup = .;
+       }
+
+       . = ALIGN(8);
+       __entry_flush_fixup : AT(ADDR(__entry_flush_fixup) - LOAD_OFFSET) {
+               __start___entry_flush_fixup = .;
+               *(__entry_flush_fixup)
+               __stop___entry_flush_fixup = .;
+       }
+
        . = ALIGN(8);
        __stf_exit_barrier_fixup : AT(ADDR(__stf_exit_barrier_fixup) - LOAD_OFFSET) {
                __start___stf_exit_barrier_fixup = .;
index 4c0a7ee..321c12a 100644 (file)
@@ -234,6 +234,110 @@ void do_stf_barrier_fixups(enum stf_barrier_type types)
        do_stf_exit_barrier_fixups(types);
 }
 
+void do_uaccess_flush_fixups(enum l1d_flush_type types)
+{
+       unsigned int instrs[4], *dest;
+       long *start, *end;
+       int i;
+
+       start = PTRRELOC(&__start___uaccess_flush_fixup);
+       end = PTRRELOC(&__stop___uaccess_flush_fixup);
+
+       instrs[0] = 0x60000000; /* nop */
+       instrs[1] = 0x60000000; /* nop */
+       instrs[2] = 0x60000000; /* nop */
+       instrs[3] = 0x4e800020; /* blr */
+
+       i = 0;
+       if (types == L1D_FLUSH_FALLBACK) {
+               instrs[3] = 0x60000000; /* nop */
+               /* fallthrough to fallback flush */
+       }
+
+       if (types & L1D_FLUSH_ORI) {
+               instrs[i++] = 0x63ff0000; /* ori 31,31,0 speculation barrier */
+               instrs[i++] = 0x63de0000; /* ori 30,30,0 L1d flush*/
+       }
+
+       if (types & L1D_FLUSH_MTTRIG)
+               instrs[i++] = 0x7c12dba6; /* mtspr TRIG2,r0 (SPR #882) */
+
+       for (i = 0; start < end; start++, i++) {
+               dest = (void *)start + *start;
+
+               pr_devel("patching dest %lx\n", (unsigned long)dest);
+
+               patch_instruction((struct ppc_inst *)dest, ppc_inst(instrs[0]));
+
+               patch_instruction((struct ppc_inst *)(dest + 1), ppc_inst(instrs[1]));
+               patch_instruction((struct ppc_inst *)(dest + 2), ppc_inst(instrs[2]));
+               patch_instruction((struct ppc_inst *)(dest + 3), ppc_inst(instrs[3]));
+       }
+
+       printk(KERN_DEBUG "uaccess-flush: patched %d locations (%s flush)\n", i,
+               (types == L1D_FLUSH_NONE)       ? "no" :
+               (types == L1D_FLUSH_FALLBACK)   ? "fallback displacement" :
+               (types &  L1D_FLUSH_ORI)        ? (types & L1D_FLUSH_MTTRIG)
+                                                       ? "ori+mttrig type"
+                                                       : "ori type" :
+               (types &  L1D_FLUSH_MTTRIG)     ? "mttrig type"
+                                               : "unknown");
+}
+
+void do_entry_flush_fixups(enum l1d_flush_type types)
+{
+       unsigned int instrs[3], *dest;
+       long *start, *end;
+       int i;
+
+       start = PTRRELOC(&__start___entry_flush_fixup);
+       end = PTRRELOC(&__stop___entry_flush_fixup);
+
+       instrs[0] = 0x60000000; /* nop */
+       instrs[1] = 0x60000000; /* nop */
+       instrs[2] = 0x60000000; /* nop */
+
+       i = 0;
+       if (types == L1D_FLUSH_FALLBACK) {
+               instrs[i++] = 0x7d4802a6; /* mflr r10           */
+               instrs[i++] = 0x60000000; /* branch patched below */
+               instrs[i++] = 0x7d4803a6; /* mtlr r10           */
+       }
+
+       if (types & L1D_FLUSH_ORI) {
+               instrs[i++] = 0x63ff0000; /* ori 31,31,0 speculation barrier */
+               instrs[i++] = 0x63de0000; /* ori 30,30,0 L1d flush*/
+       }
+
+       if (types & L1D_FLUSH_MTTRIG)
+               instrs[i++] = 0x7c12dba6; /* mtspr TRIG2,r0 (SPR #882) */
+
+       for (i = 0; start < end; start++, i++) {
+               dest = (void *)start + *start;
+
+               pr_devel("patching dest %lx\n", (unsigned long)dest);
+
+               patch_instruction((struct ppc_inst *)dest, ppc_inst(instrs[0]));
+
+               if (types == L1D_FLUSH_FALLBACK)
+                       patch_branch((struct ppc_inst *)(dest + 1), (unsigned long)&entry_flush_fallback,
+                                    BRANCH_SET_LINK);
+               else
+                       patch_instruction((struct ppc_inst *)(dest + 1), ppc_inst(instrs[1]));
+
+               patch_instruction((struct ppc_inst *)(dest + 2), ppc_inst(instrs[2]));
+       }
+
+       printk(KERN_DEBUG "entry-flush: patched %d locations (%s flush)\n", i,
+               (types == L1D_FLUSH_NONE)       ? "no" :
+               (types == L1D_FLUSH_FALLBACK)   ? "fallback displacement" :
+               (types &  L1D_FLUSH_ORI)        ? (types & L1D_FLUSH_MTTRIG)
+                                                       ? "ori+mttrig type"
+                                                       : "ori type" :
+               (types &  L1D_FLUSH_MTTRIG)     ? "mttrig type"
+                                               : "unknown");
+}
+
 void do_rfi_flush_fixups(enum l1d_flush_type types)
 {
        unsigned int instrs[3], *dest;
index 01ec2a2..3fc325b 100644 (file)
@@ -50,6 +50,7 @@
 #include <asm/rtas.h>
 #include <asm/kasan.h>
 #include <asm/svm.h>
+#include <asm/mmzone.h>
 
 #include <mm/mmu_decl.h>
 
index 9ed4fcc..7b25548 100644 (file)
@@ -1336,7 +1336,7 @@ static void dump_trace_imc_data(struct perf_event *event)
                        /* If this is a valid record, create the sample */
                        struct perf_output_handle handle;
 
-                       if (perf_output_begin(&handle, event, header.size))
+                       if (perf_output_begin(&handle, &data, event, header.size))
                                return;
 
                        perf_output_sample(&handle, &header, &data, event);
index 8e53f2f..6f681b1 100644 (file)
@@ -144,8 +144,7 @@ u64 perf_reg_abi(struct task_struct *task)
 }
 
 void perf_get_regs_user(struct perf_regs *regs_user,
-                       struct pt_regs *regs,
-                       struct pt_regs *regs_user_copy)
+                       struct pt_regs *regs)
 {
        regs_user->regs = task_pt_regs(current);
        regs_user->abi = (regs_user->regs) ? perf_reg_abi(current) :
index 9acaa0f..4611523 100644 (file)
@@ -98,7 +98,7 @@ static void init_fw_feat_flags(struct device_node *np)
                security_ftr_clear(SEC_FTR_BNDS_CHK_SPEC_BAR);
 }
 
-static void pnv_setup_rfi_flush(void)
+static void pnv_setup_security_mitigations(void)
 {
        struct device_node *np, *fw_features;
        enum l1d_flush_type type;
@@ -122,12 +122,31 @@ static void pnv_setup_rfi_flush(void)
                        type = L1D_FLUSH_ORI;
        }
 
+       /*
+        * If we are non-Power9 bare metal, we don't need to flush on kernel
+        * entry or after user access: they fix a P9 specific vulnerability.
+        */
+       if (!pvr_version_is(PVR_POWER9)) {
+               security_ftr_clear(SEC_FTR_L1D_FLUSH_ENTRY);
+               security_ftr_clear(SEC_FTR_L1D_FLUSH_UACCESS);
+       }
+
        enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) && \
                 (security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR)   || \
                  security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV));
 
        setup_rfi_flush(type, enable);
        setup_count_cache_flush();
+
+       enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) &&
+                security_ftr_enabled(SEC_FTR_L1D_FLUSH_ENTRY);
+       setup_entry_flush(enable);
+
+       enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) &&
+                security_ftr_enabled(SEC_FTR_L1D_FLUSH_UACCESS);
+       setup_uaccess_flush(enable);
+
+       setup_stf_barrier();
 }
 
 static void __init pnv_check_guarded_cores(void)
@@ -156,8 +175,7 @@ static void __init pnv_setup_arch(void)
 {
        set_arch_panic_timeout(10, ARCH_PANIC_TIMEOUT);
 
-       pnv_setup_rfi_flush();
-       setup_stf_barrier();
+       pnv_setup_security_mitigations();
 
        /* Initialize SMP */
        pnv_smp_init();
index d6f4162..2f73cb5 100644 (file)
@@ -349,8 +349,8 @@ void post_mobility_fixup(void)
 
        cpus_read_unlock();
 
-       /* Possibly switch to a new RFI flush type */
-       pseries_setup_rfi_flush();
+       /* Possibly switch to a new L1 flush type */
+       pseries_setup_security_mitigations();
 
        /* Reinitialise system information for hv-24x7 */
        read_24x7_sys_info();
index 13fa370..5938408 100644 (file)
@@ -111,7 +111,7 @@ static inline unsigned long cmo_get_page_size(void)
 
 int dlpar_workqueue_init(void);
 
-void pseries_setup_rfi_flush(void);
+void pseries_setup_security_mitigations(void);
 void pseries_lpar_read_hblkrm_characteristics(void);
 
 #endif /* _PSERIES_PSERIES_H */
index 633c45e..090c13f 100644 (file)
@@ -542,7 +542,7 @@ static void init_cpu_char_feature_flags(struct h_cpu_char_result *result)
                security_ftr_clear(SEC_FTR_BNDS_CHK_SPEC_BAR);
 }
 
-void pseries_setup_rfi_flush(void)
+void pseries_setup_security_mitigations(void)
 {
        struct h_cpu_char_result result;
        enum l1d_flush_type types;
@@ -579,6 +579,16 @@ void pseries_setup_rfi_flush(void)
 
        setup_rfi_flush(types, enable);
        setup_count_cache_flush();
+
+       enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) &&
+                security_ftr_enabled(SEC_FTR_L1D_FLUSH_ENTRY);
+       setup_entry_flush(enable);
+
+       enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) &&
+                security_ftr_enabled(SEC_FTR_L1D_FLUSH_UACCESS);
+       setup_uaccess_flush(enable);
+
+       setup_stf_barrier();
 }
 
 #ifdef CONFIG_PCI_IOV
@@ -768,8 +778,7 @@ static void __init pSeries_setup_arch(void)
 
        fwnmi_init();
 
-       pseries_setup_rfi_flush();
-       setup_stf_barrier();
+       pseries_setup_security_mitigations();
        pseries_lpar_read_hblkrm_characteristics();
 
        /* By default, only probe PCI (can be overridden by rtas_pci) */
index c47e6b3..824b2c9 100644 (file)
@@ -476,7 +476,7 @@ do {                                                                        \
 do {                                                                   \
        long __kr_err;                                                  \
                                                                        \
-       __put_user_nocheck(*((type *)(dst)), (type *)(src), __kr_err);  \
+       __put_user_nocheck(*((type *)(src)), (type *)(dst), __kr_err);  \
        if (unlikely(__kr_err))                                         \
                goto err_label;                                         \
 } while (0)
index 99e12fa..765b624 100644 (file)
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: GPL-2.0 */
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (C) 2013 Linaro Limited
  * Author: AKASHI Takahiro <takahiro.akashi@linaro.org>
index 11e2a4f..7e84979 100644 (file)
@@ -35,12 +35,17 @@ ENTRY(_start)
        .word 0
 #endif
        .balign 8
+#ifdef CONFIG_RISCV_M_MODE
+       /* Image load offset (0MB) from start of RAM for M-mode */
+       .dword 0
+#else
 #if __riscv_xlen == 64
        /* Image load offset(2MB) from start of RAM */
        .dword 0x200000
 #else
        /* Image load offset(4MB) from start of RAM */
        .dword 0x400000
+#endif
 #endif
        /* Effective size of kernel image */
        .dword _end - _start
index 04a38fb..fd304a2 100644 (file)
@@ -36,8 +36,7 @@ u64 perf_reg_abi(struct task_struct *task)
 }
 
 void perf_get_regs_user(struct perf_regs *regs_user,
-                       struct pt_regs *regs,
-                       struct pt_regs *regs_user_copy)
+                       struct pt_regs *regs)
 {
        regs_user->regs = task_pt_regs(current);
        regs_user->abi = perf_reg_abi(current);
index 11ebee9..3a19def 100644 (file)
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 vdso.lds
 *.tmp
+vdso-syms.S
index 7d6a94d..cb8f9e4 100644 (file)
@@ -43,19 +43,14 @@ $(obj)/vdso.o: $(obj)/vdso.so
 SYSCFLAGS_vdso.so.dbg = $(c_flags)
 $(obj)/vdso.so.dbg: $(src)/vdso.lds $(obj-vdso) FORCE
        $(call if_changed,vdsold)
+SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \
+       -Wl,--build-id -Wl,--hash-style=both
 
 # We also create a special relocatable object that should mirror the symbol
 # table and layout of the linked DSO. With ld --just-symbols we can then
 # refer to these symbols in the kernel code rather than hand-coded addresses.
-
-SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \
-       -Wl,--build-id=sha1 -Wl,--hash-style=both
-$(obj)/vdso-dummy.o: $(src)/vdso.lds $(obj)/rt_sigreturn.o FORCE
-       $(call if_changed,vdsold)
-
-LDFLAGS_vdso-syms.o := -r --just-symbols
-$(obj)/vdso-syms.o: $(obj)/vdso-dummy.o FORCE
-       $(call if_changed,ld)
+$(obj)/vdso-syms.S: $(obj)/vdso.so FORCE
+       $(call if_changed,so2s)
 
 # strip rule for the .so file
 $(obj)/%.so: OBJCOPYFLAGS := -S
@@ -73,6 +68,11 @@ quiet_cmd_vdsold = VDSOLD  $@
                            $(patsubst %, -G __vdso_%, $(vdso-syms)) $@.tmp $@ && \
                    rm $@.tmp
 
+# Extracts symbol offsets from the VDSO, converting them into an assembly file
+# that contains the same symbols at the same offsets.
+quiet_cmd_so2s = SO2S    $@
+      cmd_so2s = $(NM) -D $< | $(srctree)/$(src)/so2s.sh > $@
+
 # install commands for the unstripped file
 quiet_cmd_vdso_install = INSTALL $@
       cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@
diff --git a/arch/riscv/kernel/vdso/so2s.sh b/arch/riscv/kernel/vdso/so2s.sh
new file mode 100755 (executable)
index 0000000..e64cb6d
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2020 Palmer Dabbelt <palmerdabbelt@google.com>
+
+sed 's!\([0-9a-f]*\) T \([a-z0-9_]*\)\(@@LINUX_4.15\)*!.global \2\n.set \2,0x\1!' \
+| grep '^\.'
index 1359e21..3c8b9e4 100644 (file)
@@ -86,6 +86,7 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
        pmd_t *pmd, *pmd_k;
        pte_t *pte_k;
        int index;
+       unsigned long pfn;
 
        /* User mode accesses just cause a SIGSEGV */
        if (user_mode(regs))
@@ -100,7 +101,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
         * of a task switch.
         */
        index = pgd_index(addr);
-       pgd = (pgd_t *)pfn_to_virt(csr_read(CSR_SATP)) + index;
+       pfn = csr_read(CSR_SATP) & SATP_PPN;
+       pgd = (pgd_t *)pfn_to_virt(pfn) + index;
        pgd_k = init_mm.pgd + index;
 
        if (!pgd_present(*pgd_k)) {
index ea933b7..8e577f1 100644 (file)
@@ -154,9 +154,8 @@ disable:
 
 void __init setup_bootmem(void)
 {
-       phys_addr_t mem_size = 0;
-       phys_addr_t total_mem = 0;
-       phys_addr_t mem_start, start, end = 0;
+       phys_addr_t mem_start = 0;
+       phys_addr_t start, end = 0;
        phys_addr_t vmlinux_end = __pa_symbol(&_end);
        phys_addr_t vmlinux_start = __pa_symbol(&_start);
        u64 i;
@@ -164,21 +163,18 @@ void __init setup_bootmem(void)
        /* Find the memory region containing the kernel */
        for_each_mem_range(i, &start, &end) {
                phys_addr_t size = end - start;
-               if (!total_mem)
+               if (!mem_start)
                        mem_start = start;
                if (start <= vmlinux_start && vmlinux_end <= end)
                        BUG_ON(size == 0);
-               total_mem = total_mem + size;
        }
 
        /*
-        * Remove memblock from the end of usable area to the
-        * end of region
+        * The maximal physical memory size is -PAGE_OFFSET.
+        * Make sure that any memory beyond mem_start + (-PAGE_OFFSET) is removed
+        * as it is unusable by kernel.
         */
-       mem_size = min(total_mem, (phys_addr_t)-PAGE_OFFSET);
-       if (mem_start + mem_size < end)
-               memblock_remove(mem_start + mem_size,
-                               end - mem_start - mem_size);
+       memblock_enforce_memory_limit(mem_start - PAGE_OFFSET);
 
        /* Reserve from the start of the kernel to the end of the kernel */
        memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
@@ -297,6 +293,7 @@ pmd_t fixmap_pmd[PTRS_PER_PMD] __page_aligned_bss;
 #define NUM_EARLY_PMDS         (1UL + MAX_EARLY_MAPPING_SIZE / PGDIR_SIZE)
 #endif
 pmd_t early_pmd[PTRS_PER_PMD * NUM_EARLY_PMDS] __initdata __aligned(PAGE_SIZE);
+pmd_t early_dtb_pmd[PTRS_PER_PMD] __initdata __aligned(PAGE_SIZE);
 
 static pmd_t *__init get_pmd_virt_early(phys_addr_t pa)
 {
@@ -494,6 +491,18 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
                                   load_pa + (va - PAGE_OFFSET),
                                   map_size, PAGE_KERNEL_EXEC);
 
+#ifndef __PAGETABLE_PMD_FOLDED
+       /* Setup early PMD for DTB */
+       create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA,
+                          (uintptr_t)early_dtb_pmd, PGDIR_SIZE, PAGE_TABLE);
+       /* Create two consecutive PMD mappings for FDT early scan */
+       pa = dtb_pa & ~(PMD_SIZE - 1);
+       create_pmd_mapping(early_dtb_pmd, DTB_EARLY_BASE_VA,
+                          pa, PMD_SIZE, PAGE_KERNEL);
+       create_pmd_mapping(early_dtb_pmd, DTB_EARLY_BASE_VA + PMD_SIZE,
+                          pa + PMD_SIZE, PMD_SIZE, PAGE_KERNEL);
+       dtb_early_va = (void *)DTB_EARLY_BASE_VA + (dtb_pa & (PMD_SIZE - 1));
+#else
        /* Create two consecutive PGD mappings for FDT early scan */
        pa = dtb_pa & ~(PGDIR_SIZE - 1);
        create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA,
@@ -501,6 +510,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
        create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA + PGDIR_SIZE,
                           pa + PGDIR_SIZE, PGDIR_SIZE, PAGE_KERNEL);
        dtb_early_va = (void *)DTB_EARLY_BASE_VA + (dtb_pa & (PGDIR_SIZE - 1));
+#endif
        dtb_early_pa = dtb_pa;
 
        /*
index 0784bf3..fe6f529 100644 (file)
@@ -1,3 +1,4 @@
+CONFIG_UAPI_HEADER_TEST=y
 CONFIG_SYSVIPC=y
 CONFIG_POSIX_MQUEUE=y
 CONFIG_WATCH_QUEUE=y
@@ -93,9 +94,10 @@ CONFIG_CLEANCACHE=y
 CONFIG_FRONTSWAP=y
 CONFIG_CMA_DEBUG=y
 CONFIG_CMA_DEBUGFS=y
+CONFIG_CMA_AREAS=7
 CONFIG_MEM_SOFT_DIRTY=y
 CONFIG_ZSWAP=y
-CONFIG_ZSMALLOC=m
+CONFIG_ZSMALLOC=y
 CONFIG_ZSMALLOC_STAT=y
 CONFIG_DEFERRED_STRUCT_PAGE_INIT=y
 CONFIG_IDLE_PAGE_TRACKING=y
@@ -378,7 +380,6 @@ CONFIG_NETLINK_DIAG=m
 CONFIG_CGROUP_NET_PRIO=y
 CONFIG_BPF_JIT=y
 CONFIG_NET_PKTGEN=m
-# CONFIG_NET_DROP_MONITOR is not set
 CONFIG_PCI=y
 # CONFIG_PCIEASPM is not set
 CONFIG_PCI_DEBUG=y
@@ -386,7 +387,7 @@ CONFIG_HOTPLUG_PCI=y
 CONFIG_HOTPLUG_PCI_S390=y
 CONFIG_DEVTMPFS=y
 CONFIG_CONNECTOR=y
-CONFIG_ZRAM=m
+CONFIG_ZRAM=y
 CONFIG_BLK_DEV_LOOP=m
 CONFIG_BLK_DEV_CRYPTOLOOP=m
 CONFIG_BLK_DEV_DRBD=m
@@ -689,6 +690,7 @@ CONFIG_CRYPTO_TEST=m
 CONFIG_CRYPTO_DH=m
 CONFIG_CRYPTO_ECDH=m
 CONFIG_CRYPTO_ECRDSA=m
+CONFIG_CRYPTO_SM2=m
 CONFIG_CRYPTO_CURVE25519=m
 CONFIG_CRYPTO_GCM=y
 CONFIG_CRYPTO_CHACHA20POLY1305=m
@@ -709,7 +711,6 @@ CONFIG_CRYPTO_RMD160=m
 CONFIG_CRYPTO_RMD256=m
 CONFIG_CRYPTO_RMD320=m
 CONFIG_CRYPTO_SHA3=m
-CONFIG_CRYPTO_SM3=m
 CONFIG_CRYPTO_TGR192=m
 CONFIG_CRYPTO_WP512=m
 CONFIG_CRYPTO_AES_TI=m
@@ -753,6 +754,7 @@ CONFIG_CRYPTO_DES_S390=m
 CONFIG_CRYPTO_AES_S390=m
 CONFIG_CRYPTO_GHASH_S390=m
 CONFIG_CRYPTO_CRC32_S390=y
+CONFIG_CRYPTO_DEV_VIRTIO=m
 CONFIG_CORDIC=m
 CONFIG_CRC32_SELFTEST=y
 CONFIG_CRC4=m
@@ -829,6 +831,7 @@ CONFIG_NETDEV_NOTIFIER_ERROR_INJECT=m
 CONFIG_FAULT_INJECTION=y
 CONFIG_FAILSLAB=y
 CONFIG_FAIL_PAGE_ALLOC=y
+CONFIG_FAULT_INJECTION_USERCOPY=y
 CONFIG_FAIL_MAKE_REQUEST=y
 CONFIG_FAIL_IO_TIMEOUT=y
 CONFIG_FAIL_FUTEX=y
index 905bc8c..17d5df2 100644 (file)
@@ -87,9 +87,10 @@ CONFIG_KSM=y
 CONFIG_TRANSPARENT_HUGEPAGE=y
 CONFIG_CLEANCACHE=y
 CONFIG_FRONTSWAP=y
+CONFIG_CMA_AREAS=7
 CONFIG_MEM_SOFT_DIRTY=y
 CONFIG_ZSWAP=y
-CONFIG_ZSMALLOC=m
+CONFIG_ZSMALLOC=y
 CONFIG_ZSMALLOC_STAT=y
 CONFIG_DEFERRED_STRUCT_PAGE_INIT=y
 CONFIG_IDLE_PAGE_TRACKING=y
@@ -371,7 +372,6 @@ CONFIG_NETLINK_DIAG=m
 CONFIG_CGROUP_NET_PRIO=y
 CONFIG_BPF_JIT=y
 CONFIG_NET_PKTGEN=m
-# CONFIG_NET_DROP_MONITOR is not set
 CONFIG_PCI=y
 # CONFIG_PCIEASPM is not set
 CONFIG_HOTPLUG_PCI=y
@@ -379,7 +379,7 @@ CONFIG_HOTPLUG_PCI_S390=y
 CONFIG_UEVENT_HELPER=y
 CONFIG_DEVTMPFS=y
 CONFIG_CONNECTOR=y
-CONFIG_ZRAM=m
+CONFIG_ZRAM=y
 CONFIG_BLK_DEV_LOOP=m
 CONFIG_BLK_DEV_CRYPTOLOOP=m
 CONFIG_BLK_DEV_DRBD=m
@@ -680,6 +680,7 @@ CONFIG_CRYPTO_TEST=m
 CONFIG_CRYPTO_DH=m
 CONFIG_CRYPTO_ECDH=m
 CONFIG_CRYPTO_ECRDSA=m
+CONFIG_CRYPTO_SM2=m
 CONFIG_CRYPTO_CURVE25519=m
 CONFIG_CRYPTO_GCM=y
 CONFIG_CRYPTO_CHACHA20POLY1305=m
@@ -701,7 +702,6 @@ CONFIG_CRYPTO_RMD160=m
 CONFIG_CRYPTO_RMD256=m
 CONFIG_CRYPTO_RMD320=m
 CONFIG_CRYPTO_SHA3=m
-CONFIG_CRYPTO_SM3=m
 CONFIG_CRYPTO_TGR192=m
 CONFIG_CRYPTO_WP512=m
 CONFIG_CRYPTO_AES_TI=m
@@ -745,6 +745,7 @@ CONFIG_CRYPTO_DES_S390=m
 CONFIG_CRYPTO_AES_S390=m
 CONFIG_CRYPTO_GHASH_S390=m
 CONFIG_CRYPTO_CRC32_S390=y
+CONFIG_CRYPTO_DEV_VIRTIO=m
 CONFIG_CORDIC=m
 CONFIG_PRIME_NUMBERS=m
 CONFIG_CRC4=m
index 8f67c55..a302630 100644 (file)
@@ -17,11 +17,11 @@ CONFIG_HZ_100=y
 # CONFIG_CHSC_SCH is not set
 # CONFIG_SCM_BUS is not set
 CONFIG_CRASH_DUMP=y
-# CONFIG_SECCOMP is not set
 # CONFIG_PFAULT is not set
 # CONFIG_S390_HYPFS_FS is not set
 # CONFIG_VIRTUALIZATION is not set
 # CONFIG_S390_GUEST is not set
+# CONFIG_SECCOMP is not set
 CONFIG_PARTITION_ADVANCED=y
 CONFIG_IBM_PARTITION=y
 # CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
index 6b8d8c6..b5dbae7 100644 (file)
@@ -692,16 +692,6 @@ static inline int pud_large(pud_t pud)
        return !!(pud_val(pud) & _REGION3_ENTRY_LARGE);
 }
 
-static inline unsigned long pud_pfn(pud_t pud)
-{
-       unsigned long origin_mask;
-
-       origin_mask = _REGION_ENTRY_ORIGIN;
-       if (pud_large(pud))
-               origin_mask = _REGION3_ENTRY_ORIGIN_LARGE;
-       return (pud_val(pud) & origin_mask) >> PAGE_SHIFT;
-}
-
 #define pmd_leaf       pmd_large
 static inline int pmd_large(pmd_t pmd)
 {
@@ -747,16 +737,6 @@ static inline int pmd_none(pmd_t pmd)
        return pmd_val(pmd) == _SEGMENT_ENTRY_EMPTY;
 }
 
-static inline unsigned long pmd_pfn(pmd_t pmd)
-{
-       unsigned long origin_mask;
-
-       origin_mask = _SEGMENT_ENTRY_ORIGIN;
-       if (pmd_large(pmd))
-               origin_mask = _SEGMENT_ENTRY_ORIGIN_LARGE;
-       return (pmd_val(pmd) & origin_mask) >> PAGE_SHIFT;
-}
-
 #define pmd_write pmd_write
 static inline int pmd_write(pmd_t pmd)
 {
@@ -1238,11 +1218,39 @@ static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
 #define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
 #define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
 
-#define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN)
-#define pud_deref(pud) (pud_val(pud) & _REGION_ENTRY_ORIGIN)
 #define p4d_deref(pud) (p4d_val(pud) & _REGION_ENTRY_ORIGIN)
 #define pgd_deref(pgd) (pgd_val(pgd) & _REGION_ENTRY_ORIGIN)
 
+static inline unsigned long pmd_deref(pmd_t pmd)
+{
+       unsigned long origin_mask;
+
+       origin_mask = _SEGMENT_ENTRY_ORIGIN;
+       if (pmd_large(pmd))
+               origin_mask = _SEGMENT_ENTRY_ORIGIN_LARGE;
+       return pmd_val(pmd) & origin_mask;
+}
+
+static inline unsigned long pmd_pfn(pmd_t pmd)
+{
+       return pmd_deref(pmd) >> PAGE_SHIFT;
+}
+
+static inline unsigned long pud_deref(pud_t pud)
+{
+       unsigned long origin_mask;
+
+       origin_mask = _REGION_ENTRY_ORIGIN;
+       if (pud_large(pud))
+               origin_mask = _REGION3_ENTRY_ORIGIN_LARGE;
+       return pud_val(pud) & origin_mask;
+}
+
+static inline unsigned long pud_pfn(pud_t pud)
+{
+       return pud_deref(pud) >> PAGE_SHIFT;
+}
+
 /*
  * The pgd_offset function *always* adds the index for the top-level
  * region/segment table. This is done to get a sequence like the
diff --git a/arch/s390/include/asm/vdso/vdso.h b/arch/s390/include/asm/vdso/vdso.h
deleted file mode 100644 (file)
index e69de29..0000000
index ece58f2..483051e 100644 (file)
@@ -53,22 +53,14 @@ int main(void)
        /* stack_frame offsets */
        OFFSET(__SF_BACKCHAIN, stack_frame, back_chain);
        OFFSET(__SF_GPRS, stack_frame, gprs);
-       OFFSET(__SF_EMPTY, stack_frame, empty1);
-       OFFSET(__SF_SIE_CONTROL, stack_frame, empty1[0]);
-       OFFSET(__SF_SIE_SAVEAREA, stack_frame, empty1[1]);
-       OFFSET(__SF_SIE_REASON, stack_frame, empty1[2]);
-       OFFSET(__SF_SIE_FLAGS, stack_frame, empty1[3]);
+       OFFSET(__SF_EMPTY, stack_frame, empty1[0]);
+       OFFSET(__SF_SIE_CONTROL, stack_frame, empty1[1]);
+       OFFSET(__SF_SIE_SAVEAREA, stack_frame, empty1[2]);
+       OFFSET(__SF_SIE_REASON, stack_frame, empty1[3]);
+       OFFSET(__SF_SIE_FLAGS, stack_frame, empty1[4]);
        BLANK();
        OFFSET(__VDSO_GETCPU_VAL, vdso_per_cpu_data, getcpu_val);
        BLANK();
-       /* constants used by the vdso */
-       DEFINE(__CLOCK_REALTIME, CLOCK_REALTIME);
-       DEFINE(__CLOCK_MONOTONIC, CLOCK_MONOTONIC);
-       DEFINE(__CLOCK_REALTIME_COARSE, CLOCK_REALTIME_COARSE);
-       DEFINE(__CLOCK_MONOTONIC_COARSE, CLOCK_MONOTONIC_COARSE);
-       DEFINE(__CLOCK_THREAD_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID);
-       DEFINE(__CLOCK_COARSE_RES, LOW_RES_NSEC);
-       BLANK();
        /* idle data offsets */
        OFFSET(__CLOCK_IDLE_ENTER, s390_idle_data, clock_idle_enter);
        OFFSET(__CLOCK_IDLE_EXIT, s390_idle_data, clock_idle_exit);
index 8623591..26bb060 100644 (file)
@@ -422,6 +422,7 @@ ENTRY(system_call)
 #endif
        LOCKDEP_SYS_EXIT
 .Lsysc_tif:
+       DISABLE_INTS
        TSTMSK  __PT_FLAGS(%r11),_PIF_WORK
        jnz     .Lsysc_work
        TSTMSK  __TI_flags(%r12),_TIF_WORK
@@ -444,6 +445,7 @@ ENTRY(system_call)
 # One of the work bits is on. Find out which one.
 #
 .Lsysc_work:
+       ENABLE_INTS
        TSTMSK  __TI_flags(%r12),_TIF_NEED_RESCHED
        jo      .Lsysc_reschedule
        TSTMSK  __PT_FLAGS(%r11),_PIF_SYSCALL_RESTART
@@ -1066,6 +1068,7 @@ EXPORT_SYMBOL(save_fpu_regs)
  *     %r4
  */
 load_fpu_regs:
+       stnsm   __SF_EMPTY(%r15),0xfc
        lg      %r4,__LC_CURRENT
        aghi    %r4,__TASK_thread
        TSTMSK  __LC_CPU_FLAGS,_CIF_FPU
@@ -1097,6 +1100,7 @@ load_fpu_regs:
 .Lload_fpu_regs_done:
        ni      __LC_CPU_FLAGS+7,255-_CIF_FPU
 .Lload_fpu_regs_exit:
+       ssm     __SF_EMPTY(%r15)
        BR_EX   %r14
 .Lload_fpu_regs_end:
 ENDPROC(load_fpu_regs)
index 4f9e462..19cd7b9 100644 (file)
@@ -672,7 +672,7 @@ static void cpumsf_output_event_pid(struct perf_event *event,
        rcu_read_lock();
 
        perf_prepare_sample(&header, data, event, regs);
-       if (perf_output_begin(&handle, event, header.size))
+       if (perf_output_begin(&handle, data, event, header.size))
                goto out;
 
        /* Update the process ID (see also kernel/events/core.c) */
@@ -2228,4 +2228,4 @@ out:
 }
 
 arch_initcall(init_cpum_sampling_pmu);
-core_param(cpum_sfb_size, CPUM_SF_MAX_SDB, sfb_size, 0640);
+core_param(cpum_sfb_size, CPUM_SF_MAX_SDB, sfb_size, 0644);
index 4352a50..6e9e5d5 100644 (file)
@@ -53,8 +53,7 @@ u64 perf_reg_abi(struct task_struct *task)
 }
 
 void perf_get_regs_user(struct perf_regs *regs_user,
-                       struct pt_regs *regs,
-                       struct pt_regs *regs_user_copy)
+                       struct pt_regs *regs)
 {
        /*
         * Use the regs from the first interruption and let
index ebfe86d..390d97d 100644 (file)
@@ -855,13 +855,14 @@ void __init smp_detect_cpus(void)
 
 static void smp_init_secondary(void)
 {
-       int cpu = smp_processor_id();
+       int cpu = raw_smp_processor_id();
 
        S390_lowcore.last_update_clock = get_tod_clock();
        restore_access_regs(S390_lowcore.access_regs_save_area);
        set_cpu_flag(CIF_ASCE_PRIMARY);
        set_cpu_flag(CIF_ASCE_SECONDARY);
        cpu_init();
+       rcu_cpu_starting(cpu);
        preempt_disable();
        init_cpu_timer();
        vtime_init();
index d33f215..9a6bae5 100644 (file)
@@ -101,6 +101,10 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
                if (ret)
                        break;
 
+               /* the PCI function will be scanned once function 0 appears */
+               if (!zdev->zbus->bus)
+                       break;
+
                pdev = pci_scan_single_device(zdev->zbus->bus, zdev->devfn);
                if (!pdev)
                        break;
index 5393e13..2bbf28c 100644 (file)
@@ -33,7 +33,13 @@ do {                                                 \
 } while (0)
 
 #ifdef CONFIG_3_LEVEL_PGTABLES
-#define __pmd_free_tlb(tlb,x, address)   tlb_remove_page((tlb),virt_to_page(x))
+
+#define __pmd_free_tlb(tlb, pmd, address)              \
+do {                                                   \
+       pgtable_pmd_page_dtor(virt_to_page(pmd));       \
+       tlb_remove_page((tlb),virt_to_page(pmd));       \
+} while (0)                                            \
+
 #endif
 
 #endif
index a5e5db6..39b2ede 100644 (file)
@@ -164,6 +164,7 @@ void initialize_identity_maps(void *rmode)
        add_identity_map(cmdline, cmdline + COMMAND_LINE_SIZE);
 
        /* Load the new page-table. */
+       sev_verify_cbit(top_level_pgt);
        write_cr3(top_level_pgt);
 }
 
index dd07e7b..aa56179 100644 (file)
@@ -68,6 +68,9 @@ SYM_FUNC_START(get_sev_encryption_bit)
 SYM_FUNC_END(get_sev_encryption_bit)
 
        .code64
+
+#include "../../kernel/sev_verify_cbit.S"
+
 SYM_FUNC_START(set_sev_encryption_mask)
 #ifdef CONFIG_AMD_MEM_ENCRYPT
        push    %rbp
@@ -81,6 +84,19 @@ SYM_FUNC_START(set_sev_encryption_mask)
 
        bts     %rax, sme_me_mask(%rip) /* Create the encryption mask */
 
+       /*
+        * Read MSR_AMD64_SEV again and store it to sev_status. Can't do this in
+        * get_sev_encryption_bit() because this function is 32-bit code and
+        * shared between 64-bit and 32-bit boot path.
+        */
+       movl    $MSR_AMD64_SEV, %ecx    /* Read the SEV MSR */
+       rdmsr
+
+       /* Store MSR value in sev_status */
+       shlq    $32, %rdx
+       orq     %rdx, %rax
+       movq    %rax, sev_status(%rip)
+
 .Lno_sev_mask:
        movq    %rbp, %rsp              /* Restore original stack pointer */
 
@@ -96,5 +112,7 @@ SYM_FUNC_END(set_sev_encryption_mask)
 
 #ifdef CONFIG_AMD_MEM_ENCRYPT
        .balign 8
-SYM_DATA(sme_me_mask, .quad 0)
+SYM_DATA(sme_me_mask,          .quad 0)
+SYM_DATA(sev_status,           .quad 0)
+SYM_DATA(sev_check_data,       .quad 0)
 #endif
index 6d31f1b..d9a631c 100644 (file)
@@ -159,4 +159,6 @@ void boot_page_fault(void);
 void boot_stage1_vc(void);
 void boot_stage2_vc(void);
 
+unsigned long sev_verify_cbit(unsigned long cr3);
+
 #endif /* BOOT_COMPRESSED_MISC_H */
index f1926e9..af457f8 100644 (file)
@@ -2630,7 +2630,7 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status)
                u64 pebs_enabled = cpuc->pebs_enabled;
 
                handled++;
-               x86_pmu.drain_pebs(regs);
+               x86_pmu.drain_pebs(regs, &data);
                status &= x86_pmu.intel_ctrl | GLOBAL_STATUS_TRACE_TOPAPMI;
 
                /*
@@ -4987,6 +4987,12 @@ __init int intel_pmu_init(void)
 
        x86_add_quirk(intel_arch_events_quirk); /* Install first, so it runs last */
 
+       if (version >= 5) {
+               x86_pmu.intel_cap.anythread_deprecated = edx.split.anythread_deprecated;
+               if (x86_pmu.intel_cap.anythread_deprecated)
+                       pr_cont(" AnyThread deprecated, ");
+       }
+
        /*
         * Install the hw-cache-events table:
         */
@@ -5512,6 +5518,10 @@ __init int intel_pmu_init(void)
        x86_pmu.intel_ctrl |=
                ((1LL << x86_pmu.num_counters_fixed)-1) << INTEL_PMC_IDX_FIXED;
 
+       /* AnyThread may be deprecated on arch perfmon v5 or later */
+       if (x86_pmu.intel_cap.anythread_deprecated)
+               x86_pmu.format_attrs = intel_arch_formats_attr;
+
        if (x86_pmu.event_constraints) {
                /*
                 * event on fixed counter2 (REF_CYCLES) only works on this
index 442e1ed..4eb7ee5 100644 (file)
 MODULE_LICENSE("GPL");
 
 #define DEFINE_CSTATE_FORMAT_ATTR(_var, _name, _format)                \
-static ssize_t __cstate_##_var##_show(struct kobject *kobj,    \
-                               struct kobj_attribute *attr,    \
+static ssize_t __cstate_##_var##_show(struct device *dev,      \
+                               struct device_attribute *attr,  \
                                char *page)                     \
 {                                                              \
        BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE);             \
        return sprintf(page, _format "\n");                     \
 }                                                              \
-static struct kobj_attribute format_attr_##_var =              \
+static struct device_attribute format_attr_##_var =            \
        __ATTR(_name, 0444, __cstate_##_var##_show, NULL)
 
 static ssize_t cstate_get_attr_cpumask(struct device *dev,
index 404315d..b47cc42 100644 (file)
@@ -642,8 +642,8 @@ int intel_pmu_drain_bts_buffer(void)
        rcu_read_lock();
        perf_prepare_sample(&header, &data, event, &regs);
 
-       if (perf_output_begin(&handle, event, header.size *
-                             (top - base - skip)))
+       if (perf_output_begin(&handle, &data, event,
+                             header.size * (top - base - skip)))
                goto unlock;
 
        for (at = base; at < top; at++) {
@@ -670,7 +670,9 @@ unlock:
 
 static inline void intel_pmu_drain_pebs_buffer(void)
 {
-       x86_pmu.drain_pebs(NULL);
+       struct perf_sample_data data;
+
+       x86_pmu.drain_pebs(NULL, &data);
 }
 
 /*
@@ -1719,23 +1721,24 @@ intel_pmu_save_and_restart_reload(struct perf_event *event, int count)
        return 0;
 }
 
-static void __intel_pmu_pebs_event(struct perf_event *event,
-                                  struct pt_regs *iregs,
-                                  void *base, void *top,
-                                  int bit, int count,
-                                  void (*setup_sample)(struct perf_event *,
-                                               struct pt_regs *,
-                                               void *,
-                                               struct perf_sample_data *,
-                                               struct pt_regs *))
+static __always_inline void
+__intel_pmu_pebs_event(struct perf_event *event,
+                      struct pt_regs *iregs,
+                      struct perf_sample_data *data,
+                      void *base, void *top,
+                      int bit, int count,
+                      void (*setup_sample)(struct perf_event *,
+                                           struct pt_regs *,
+                                           void *,
+                                           struct perf_sample_data *,
+                                           struct pt_regs *))
 {
        struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
        struct hw_perf_event *hwc = &event->hw;
-       struct perf_sample_data data;
        struct x86_perf_regs perf_regs;
        struct pt_regs *regs = &perf_regs.regs;
        void *at = get_next_pebs_record_by_bit(base, top, bit);
-       struct pt_regs dummy_iregs;
+       static struct pt_regs dummy_iregs;
 
        if (hwc->flags & PERF_X86_EVENT_AUTO_RELOAD) {
                /*
@@ -1752,14 +1755,14 @@ static void __intel_pmu_pebs_event(struct perf_event *event,
                iregs = &dummy_iregs;
 
        while (count > 1) {
-               setup_sample(event, iregs, at, &data, regs);
-               perf_event_output(event, &data, regs);
+               setup_sample(event, iregs, at, data, regs);
+               perf_event_output(event, data, regs);
                at += cpuc->pebs_record_size;
                at = get_next_pebs_record_by_bit(at, top, bit);
                count--;
        }
 
-       setup_sample(event, iregs, at, &data, regs);
+       setup_sample(event, iregs, at, data, regs);
        if (iregs == &dummy_iregs) {
                /*
                 * The PEBS records may be drained in the non-overflow context,
@@ -1767,18 +1770,18 @@ static void __intel_pmu_pebs_event(struct perf_event *event,
                 * last record the same as other PEBS records, and doesn't
                 * invoke the generic overflow handler.
                 */
-               perf_event_output(event, &data, regs);
+               perf_event_output(event, data, regs);
        } else {
                /*
                 * All but the last records are processed.
                 * The last one is left to be able to call the overflow handler.
                 */
-               if (perf_event_overflow(event, &data, regs))
+               if (perf_event_overflow(event, data, regs))
                        x86_pmu_stop(event, 0);
        }
 }
 
-static void intel_pmu_drain_pebs_core(struct pt_regs *iregs)
+static void intel_pmu_drain_pebs_core(struct pt_regs *iregs, struct perf_sample_data *data)
 {
        struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
        struct debug_store *ds = cpuc->ds;
@@ -1812,7 +1815,7 @@ static void intel_pmu_drain_pebs_core(struct pt_regs *iregs)
                return;
        }
 
-       __intel_pmu_pebs_event(event, iregs, at, top, 0, n,
+       __intel_pmu_pebs_event(event, iregs, data, at, top, 0, n,
                               setup_pebs_fixed_sample_data);
 }
 
@@ -1835,7 +1838,7 @@ static void intel_pmu_pebs_event_update_no_drain(struct cpu_hw_events *cpuc, int
        }
 }
 
-static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs)
+static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs, struct perf_sample_data *data)
 {
        struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
        struct debug_store *ds = cpuc->ds;
@@ -1942,14 +1945,14 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs)
                }
 
                if (counts[bit]) {
-                       __intel_pmu_pebs_event(event, iregs, base,
+                       __intel_pmu_pebs_event(event, iregs, data, base,
                                               top, bit, counts[bit],
                                               setup_pebs_fixed_sample_data);
                }
        }
 }
 
-static void intel_pmu_drain_pebs_icl(struct pt_regs *iregs)
+static void intel_pmu_drain_pebs_icl(struct pt_regs *iregs, struct perf_sample_data *data)
 {
        short counts[INTEL_PMC_IDX_FIXED + MAX_FIXED_PEBS_EVENTS] = {};
        struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
@@ -1997,7 +2000,7 @@ static void intel_pmu_drain_pebs_icl(struct pt_regs *iregs)
                if (WARN_ON_ONCE(!event->attr.precise_ip))
                        continue;
 
-               __intel_pmu_pebs_event(event, iregs, base,
+               __intel_pmu_pebs_event(event, iregs, data, base,
                                       top, bit, counts[bit],
                                       setup_pebs_adaptive_sample_data);
        }
index 86d012b..80d52cb 100644 (file)
@@ -94,8 +94,8 @@ end:
        return map;
 }
 
-ssize_t uncore_event_show(struct kobject *kobj,
-                         struct kobj_attribute *attr, char *buf)
+ssize_t uncore_event_show(struct device *dev,
+                         struct device_attribute *attr, char *buf)
 {
        struct uncore_event_desc *event =
                container_of(attr, struct uncore_event_desc, attr);
index 83d2a7d..9efea15 100644 (file)
@@ -157,7 +157,7 @@ struct intel_uncore_box {
 #define UNCORE_BOX_FLAG_CFL8_CBOX_MSR_OFFS     2
 
 struct uncore_event_desc {
-       struct kobj_attribute attr;
+       struct device_attribute attr;
        const char *config;
 };
 
@@ -179,8 +179,8 @@ struct pci2phy_map {
 struct pci2phy_map *__find_pci2phy_map(int segment);
 int uncore_pcibus_to_physid(struct pci_bus *bus);
 
-ssize_t uncore_event_show(struct kobject *kobj,
-                         struct kobj_attribute *attr, char *buf);
+ssize_t uncore_event_show(struct device *dev,
+                         struct device_attribute *attr, char *buf);
 
 static inline struct intel_uncore_pmu *dev_to_uncore_pmu(struct device *dev)
 {
@@ -201,14 +201,14 @@ extern int __uncore_max_dies;
 }
 
 #define DEFINE_UNCORE_FORMAT_ATTR(_var, _name, _format)                        \
-static ssize_t __uncore_##_var##_show(struct kobject *kobj,            \
-                               struct kobj_attribute *attr,            \
+static ssize_t __uncore_##_var##_show(struct device *dev,              \
+                               struct device_attribute *attr,          \
                                char *page)                             \
 {                                                                      \
        BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE);                     \
        return sprintf(page, _format "\n");                             \
 }                                                                      \
-static struct kobj_attribute format_attr_##_var =                      \
+static struct device_attribute format_attr_##_var =                    \
        __ATTR(_name, 0444, __uncore_##_var##_show, NULL)
 
 static inline bool uncore_pmc_fixed(int idx)
index 39e632e..bbd1120 100644 (file)
@@ -475,7 +475,7 @@ enum perf_snb_uncore_imc_freerunning_types {
 static struct freerunning_counters snb_uncore_imc_freerunning[] = {
        [SNB_PCI_UNCORE_IMC_DATA_READS]         = { SNB_UNCORE_PCI_IMC_DATA_READS_BASE,
                                                        0x0, 0x0, 1, 32 },
-       [SNB_PCI_UNCORE_IMC_DATA_READS]         = { SNB_UNCORE_PCI_IMC_DATA_WRITES_BASE,
+       [SNB_PCI_UNCORE_IMC_DATA_WRITES]        = { SNB_UNCORE_PCI_IMC_DATA_WRITES_BASE,
                                                        0x0, 0x0, 1, 32 },
        [SNB_PCI_UNCORE_IMC_GT_REQUESTS]        = { SNB_UNCORE_PCI_IMC_GT_REQUESTS_BASE,
                                                        0x0, 0x0, 1, 32 },
index ee2b9b9..6a8edfe 100644 (file)
@@ -585,6 +585,7 @@ union perf_capabilities {
                u64     pebs_baseline:1;
                u64     perf_metrics:1;
                u64     pebs_output_pt_available:1;
+               u64     anythread_deprecated:1;
        };
        u64     capabilities;
 };
@@ -727,7 +728,7 @@ struct x86_pmu {
        int             pebs_record_size;
        int             pebs_buffer_size;
        int             max_pebs_events;
-       void            (*drain_pebs)(struct pt_regs *regs);
+       void            (*drain_pebs)(struct pt_regs *regs, struct perf_sample_data *data);
        struct event_constraint *pebs_constraints;
        void            (*pebs_aliases)(struct perf_event *event);
        unsigned long   large_pebs_flags;
index 7c0120e..7dbbeaa 100644 (file)
@@ -93,18 +93,6 @@ static const char *const rapl_domain_names[NR_RAPL_DOMAINS] __initconst = {
  * any other bit is reserved
  */
 #define RAPL_EVENT_MASK        0xFFULL
-
-#define DEFINE_RAPL_FORMAT_ATTR(_var, _name, _format)          \
-static ssize_t __rapl_##_var##_show(struct kobject *kobj,      \
-                               struct kobj_attribute *attr,    \
-                               char *page)                     \
-{                                                              \
-       BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE);             \
-       return sprintf(page, _format "\n");                     \
-}                                                              \
-static struct kobj_attribute format_attr_##_var =              \
-       __ATTR(_name, 0444, __rapl_##_var##_show, NULL)
-
 #define RAPL_CNTR_WIDTH 32
 
 #define RAPL_EVENT_ATTR_STR(_name, v, str)                                     \
@@ -441,7 +429,7 @@ static struct attribute_group rapl_pmu_events_group = {
        .attrs = attrs_empty,
 };
 
-DEFINE_RAPL_FORMAT_ATTR(event, event, "config:0-7");
+PMU_FORMAT_ATTR(event, "config:0-7");
 static struct attribute *rapl_formats_attr[] = {
        &format_attr_event.attr,
        NULL,
index 40e0e32..284e736 100644 (file)
@@ -273,11 +273,15 @@ void __init hv_apic_init(void)
                pr_info("Hyper-V: Using enlightened APIC (%s mode)",
                        x2apic_enabled() ? "x2apic" : "xapic");
                /*
-                * With x2apic, architectural x2apic MSRs are equivalent to the
-                * respective synthetic MSRs, so there's no need to override
-                * the apic accessors.  The only exception is
-                * hv_apic_eoi_write, because it benefits from lazy EOI when
-                * available, but it works for both xapic and x2apic modes.
+                * When in x2apic mode, don't use the Hyper-V specific APIC
+                * accessors since the field layout in the ICR register is
+                * different in x2apic mode. Furthermore, the architectural
+                * x2apic MSRs function just as well as the Hyper-V
+                * synthetic APIC MSRs, so there's no benefit in having
+                * separate Hyper-V accessors for x2apic mode. The only
+                * exception is hv_apic_eoi_write, because it benefits from
+                * lazy EOI when available, but the same accessor works for
+                * both xapic and x2apic because the field layout is the same.
                 */
                apic_set_eoi_write(hv_apic_eoi_write);
                if (!x2apic_enabled()) {
index d44858b..324ddd7 100644 (file)
@@ -639,6 +639,7 @@ struct kvm_vcpu_arch {
        int cpuid_nent;
        struct kvm_cpuid_entry2 *cpuid_entries;
 
+       unsigned long cr3_lm_rsvd_bits;
        int maxphyaddr;
        int max_tdp_level;
 
index 6960cd6..b9a7fd0 100644 (file)
@@ -137,7 +137,9 @@ union cpuid10_edx {
        struct {
                unsigned int num_counters_fixed:5;
                unsigned int bit_width_fixed:8;
-               unsigned int reserved:19;
+               unsigned int reserved1:2;
+               unsigned int anythread_deprecated:1;
+               unsigned int reserved2:16;
        } split;
        unsigned int full;
 };
index 6bfc878..6a9ccc1 100644 (file)
 #endif
 
 #endif /* CONFIG_SPARSEMEM */
+
+#ifndef __ASSEMBLY__
+#ifdef CONFIG_NUMA_KEEP_MEMINFO
+extern int phys_to_target_node(phys_addr_t start);
+#define phys_to_target_node phys_to_target_node
+extern int memory_add_physaddr_to_nid(u64 start);
+#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid
+#endif
+#endif /* __ASSEMBLY__ */
+
 #endif /* _ASM_X86_SPARSEMEM_H */
index 172d3e4..648eb23 100644 (file)
@@ -2,14 +2,8 @@
 #ifndef _ASM_X86_UV_UV_H
 #define _ASM_X86_UV_UV_H
 
-#include <asm/tlbflush.h>
-
 enum uv_system_type {UV_NONE, UV_LEGACY_APIC, UV_X2APIC};
 
-struct cpumask;
-struct mm_struct;
-struct flush_tlb_info;
-
 #ifdef CONFIG_X86_UV
 #include <linux/efi.h>
 
@@ -44,10 +38,6 @@ static inline int is_uv_system(void) { return 0; }
 static inline int is_uv_hubbed(int uv) { return 0; }
 static inline void uv_cpu_init(void)   { }
 static inline void uv_system_init(void)        { }
-static inline const struct cpumask *
-uv_flush_tlb_others(const struct cpumask *cpumask,
-                   const struct flush_tlb_info *info)
-{ return cpumask; }
 
 #endif /* X86_UV */
 
index 714233c..1b98f8c 100644 (file)
@@ -33,7 +33,7 @@ static union uvh_apicid               uvh_apicid;
 static int                     uv_node_id;
 
 /* Unpack AT/OEM/TABLE ID's to be NULL terminated strings */
-static u8 uv_archtype[UV_AT_SIZE];
+static u8 uv_archtype[UV_AT_SIZE + 1];
 static u8 oem_id[ACPI_OEM_ID_SIZE + 1];
 static u8 oem_table_id[ACPI_OEM_TABLE_ID_SIZE + 1];
 
@@ -290,6 +290,9 @@ static void __init uv_stringify(int len, char *to, char *from)
 {
        /* Relies on 'to' being NULL chars so result will be NULL terminated */
        strncpy(to, from, len-1);
+
+       /* Trim trailing spaces */
+       (void)strim(to);
 }
 
 /* Find UV arch type entry in UVsystab */
@@ -317,7 +320,7 @@ static int __init decode_arch_type(unsigned long ptr)
 
        if (n > 0 && n < sizeof(uv_ate->archtype)) {
                pr_info("UV: UVarchtype received from BIOS\n");
-               uv_stringify(UV_AT_SIZE, uv_archtype, uv_ate->archtype);
+               uv_stringify(sizeof(uv_archtype), uv_archtype, uv_ate->archtype);
                return 1;
        }
        return 0;
@@ -366,7 +369,7 @@ static int __init early_get_arch_type(void)
        return ret;
 }
 
-static int __init uv_set_system_type(char *_oem_id)
+static int __init uv_set_system_type(char *_oem_id, char *_oem_table_id)
 {
        /* Save OEM_ID passed from ACPI MADT */
        uv_stringify(sizeof(oem_id), oem_id, _oem_id);
@@ -375,7 +378,7 @@ static int __init uv_set_system_type(char *_oem_id)
        if (!early_get_arch_type())
 
                /* If not use OEM ID for UVarchtype */
-               uv_stringify(UV_AT_SIZE, uv_archtype, _oem_id);
+               uv_stringify(sizeof(uv_archtype), uv_archtype, oem_id);
 
        /* Check if not hubbed */
        if (strncmp(uv_archtype, "SGI", 3) != 0) {
@@ -386,13 +389,23 @@ static int __init uv_set_system_type(char *_oem_id)
                        /* (Not hubless), not a UV */
                        return 0;
 
+               /* Is UV hubless system */
+               uv_hubless_system = 0x01;
+
+               /* UV5 Hubless */
+               if (strncmp(uv_archtype, "NSGI5", 5) == 0)
+                       uv_hubless_system |= 0x20;
+
                /* UV4 Hubless: CH */
-               if (strncmp(uv_archtype, "NSGI4", 5) == 0)
-                       uv_hubless_system = 0x11;
+               else if (strncmp(uv_archtype, "NSGI4", 5) == 0)
+                       uv_hubless_system |= 0x10;
 
                /* UV3 Hubless: UV300/MC990X w/o hub */
                else
-                       uv_hubless_system = 0x9;
+                       uv_hubless_system |= 0x8;
+
+               /* Copy APIC type */
+               uv_stringify(sizeof(oem_table_id), oem_table_id, _oem_table_id);
 
                pr_info("UV: OEM IDs %s/%s, SystemType %d, HUBLESS ID %x\n",
                        oem_id, oem_table_id, uv_system_type, uv_hubless_system);
@@ -456,7 +469,7 @@ static int __init uv_acpi_madt_oem_check(char *_oem_id, char *_oem_table_id)
        uv_cpu_info->p_uv_hub_info = &uv_hub_info_node0;
 
        /* If not UV, return. */
-       if (likely(uv_set_system_type(_oem_id) == 0))
+       if (uv_set_system_type(_oem_id, _oem_table_id) == 0)
                return 0;
 
        /* Save and Decode OEM Table ID */
index d3f0db4..581fb72 100644 (file)
@@ -1254,6 +1254,14 @@ static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl)
        return 0;
 }
 
+static bool is_spec_ib_user_controlled(void)
+{
+       return spectre_v2_user_ibpb == SPECTRE_V2_USER_PRCTL ||
+               spectre_v2_user_ibpb == SPECTRE_V2_USER_SECCOMP ||
+               spectre_v2_user_stibp == SPECTRE_V2_USER_PRCTL ||
+               spectre_v2_user_stibp == SPECTRE_V2_USER_SECCOMP;
+}
+
 static int ib_prctl_set(struct task_struct *task, unsigned long ctrl)
 {
        switch (ctrl) {
@@ -1261,16 +1269,26 @@ static int ib_prctl_set(struct task_struct *task, unsigned long ctrl)
                if (spectre_v2_user_ibpb == SPECTRE_V2_USER_NONE &&
                    spectre_v2_user_stibp == SPECTRE_V2_USER_NONE)
                        return 0;
+
                /*
-                * Indirect branch speculation is always disabled in strict
-                * mode. It can neither be enabled if it was force-disabled
-                * by a  previous prctl call.
+                * With strict mode for both IBPB and STIBP, the instruction
+                * code paths avoid checking this task flag and instead,
+                * unconditionally run the instruction. However, STIBP and IBPB
+                * are independent and either can be set to conditionally
+                * enabled regardless of the mode of the other.
+                *
+                * If either is set to conditional, allow the task flag to be
+                * updated, unless it was force-disabled by a previous prctl
+                * call. Currently, this is possible on an AMD CPU which has the
+                * feature X86_FEATURE_AMD_STIBP_ALWAYS_ON. In this case, if the
+                * kernel is booted with 'spectre_v2_user=seccomp', then
+                * spectre_v2_user_ibpb == SPECTRE_V2_USER_SECCOMP and
+                * spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT_PREFERRED.
                 */
-               if (spectre_v2_user_ibpb == SPECTRE_V2_USER_STRICT ||
-                   spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT ||
-                   spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT_PREFERRED ||
+               if (!is_spec_ib_user_controlled() ||
                    task_spec_ib_force_disable(task))
                        return -EPERM;
+
                task_clear_spec_ib_disable(task);
                task_update_spec_tif(task);
                break;
@@ -1283,10 +1301,10 @@ static int ib_prctl_set(struct task_struct *task, unsigned long ctrl)
                if (spectre_v2_user_ibpb == SPECTRE_V2_USER_NONE &&
                    spectre_v2_user_stibp == SPECTRE_V2_USER_NONE)
                        return -EPERM;
-               if (spectre_v2_user_ibpb == SPECTRE_V2_USER_STRICT ||
-                   spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT ||
-                   spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT_PREFERRED)
+
+               if (!is_spec_ib_user_controlled())
                        return 0;
+
                task_set_spec_ib_disable(task);
                if (ctrl == PR_SPEC_FORCE_DISABLE)
                        task_set_spec_ib_force_disable(task);
@@ -1351,20 +1369,17 @@ static int ib_prctl_get(struct task_struct *task)
        if (spectre_v2_user_ibpb == SPECTRE_V2_USER_NONE &&
            spectre_v2_user_stibp == SPECTRE_V2_USER_NONE)
                return PR_SPEC_ENABLE;
-       else if (spectre_v2_user_ibpb == SPECTRE_V2_USER_STRICT ||
-           spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT ||
-           spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT_PREFERRED)
-               return PR_SPEC_DISABLE;
-       else if (spectre_v2_user_ibpb == SPECTRE_V2_USER_PRCTL ||
-           spectre_v2_user_ibpb == SPECTRE_V2_USER_SECCOMP ||
-           spectre_v2_user_stibp == SPECTRE_V2_USER_PRCTL ||
-           spectre_v2_user_stibp == SPECTRE_V2_USER_SECCOMP) {
+       else if (is_spec_ib_user_controlled()) {
                if (task_spec_ib_force_disable(task))
                        return PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE;
                if (task_spec_ib_disable(task))
                        return PR_SPEC_PRCTL | PR_SPEC_DISABLE;
                return PR_SPEC_PRCTL | PR_SPEC_ENABLE;
-       } else
+       } else if (spectre_v2_user_ibpb == SPECTRE_V2_USER_STRICT ||
+           spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT ||
+           spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT_PREFERRED)
+               return PR_SPEC_DISABLE;
+       else
                return PR_SPEC_NOT_AFFECTED;
 }
 
index 6a99535..7e8e07b 100644 (file)
@@ -100,53 +100,6 @@ static int has_newer_microcode(void *mc, unsigned int csig, int cpf, int new_rev
        return find_matching_signature(mc, csig, cpf);
 }
 
-/*
- * Given CPU signature and a microcode patch, this function finds if the
- * microcode patch has matching family and model with the CPU.
- *
- * %true - if there's a match
- * %false - otherwise
- */
-static bool microcode_matches(struct microcode_header_intel *mc_header,
-                             unsigned long sig)
-{
-       unsigned long total_size = get_totalsize(mc_header);
-       unsigned long data_size = get_datasize(mc_header);
-       struct extended_sigtable *ext_header;
-       unsigned int fam_ucode, model_ucode;
-       struct extended_signature *ext_sig;
-       unsigned int fam, model;
-       int ext_sigcount, i;
-
-       fam   = x86_family(sig);
-       model = x86_model(sig);
-
-       fam_ucode   = x86_family(mc_header->sig);
-       model_ucode = x86_model(mc_header->sig);
-
-       if (fam == fam_ucode && model == model_ucode)
-               return true;
-
-       /* Look for ext. headers: */
-       if (total_size <= data_size + MC_HEADER_SIZE)
-               return false;
-
-       ext_header   = (void *) mc_header + data_size + MC_HEADER_SIZE;
-       ext_sig      = (void *)ext_header + EXT_HEADER_SIZE;
-       ext_sigcount = ext_header->count;
-
-       for (i = 0; i < ext_sigcount; i++) {
-               fam_ucode   = x86_family(ext_sig->sig);
-               model_ucode = x86_model(ext_sig->sig);
-
-               if (fam == fam_ucode && model == model_ucode)
-                       return true;
-
-               ext_sig++;
-       }
-       return false;
-}
-
 static struct ucode_patch *memdup_patch(void *data, unsigned int size)
 {
        struct ucode_patch *p;
@@ -164,7 +117,7 @@ static struct ucode_patch *memdup_patch(void *data, unsigned int size)
        return p;
 }
 
-static void save_microcode_patch(void *data, unsigned int size)
+static void save_microcode_patch(struct ucode_cpu_info *uci, void *data, unsigned int size)
 {
        struct microcode_header_intel *mc_hdr, *mc_saved_hdr;
        struct ucode_patch *iter, *tmp, *p = NULL;
@@ -210,6 +163,9 @@ static void save_microcode_patch(void *data, unsigned int size)
        if (!p)
                return;
 
+       if (!find_matching_signature(p->data, uci->cpu_sig.sig, uci->cpu_sig.pf))
+               return;
+
        /*
         * Save for early loading. On 32-bit, that needs to be a physical
         * address as the APs are running from physical addresses, before
@@ -344,13 +300,14 @@ scan_microcode(void *data, size_t size, struct ucode_cpu_info *uci, bool save)
 
                size -= mc_size;
 
-               if (!microcode_matches(mc_header, uci->cpu_sig.sig)) {
+               if (!find_matching_signature(data, uci->cpu_sig.sig,
+                                            uci->cpu_sig.pf)) {
                        data += mc_size;
                        continue;
                }
 
                if (save) {
-                       save_microcode_patch(data, mc_size);
+                       save_microcode_patch(uci, data, mc_size);
                        goto next;
                }
 
@@ -483,14 +440,14 @@ static void show_saved_mc(void)
  * Save this microcode patch. It will be loaded early when a CPU is
  * hot-added or resumes.
  */
-static void save_mc_for_early(u8 *mc, unsigned int size)
+static void save_mc_for_early(struct ucode_cpu_info *uci, u8 *mc, unsigned int size)
 {
        /* Synchronization during CPU hotplug. */
        static DEFINE_MUTEX(x86_cpu_microcode_mutex);
 
        mutex_lock(&x86_cpu_microcode_mutex);
 
-       save_microcode_patch(mc, size);
+       save_microcode_patch(uci, mc, size);
        show_saved_mc();
 
        mutex_unlock(&x86_cpu_microcode_mutex);
@@ -935,7 +892,7 @@ static enum ucode_state generic_load_microcode(int cpu, struct iov_iter *iter)
         * permanent memory. So it will be loaded early when a CPU is hot added
         * or resumes.
         */
-       save_mc_for_early(new_mc, new_mc_size);
+       save_mc_for_early(uci, new_mc, new_mc_size);
 
        pr_debug("CPU%d found a matching microcode update with version 0x%x (current=0x%x)\n",
                 cpu, new_rev, uci->cpu_sig.rev);
index 25c06b6..97aa900 100644 (file)
@@ -78,6 +78,9 @@ static int copy_code(struct pt_regs *regs, u8 *buf, unsigned long src,
        if (!user_mode(regs))
                return copy_from_kernel_nofault(buf, (u8 *)src, nbytes);
 
+       /* The user space code from other tasks cannot be accessed. */
+       if (regs != task_pt_regs(current))
+               return -EPERM;
        /*
         * Make sure userspace isn't trying to trick us into dumping kernel
         * memory by pointing the userspace instruction pointer at it.
@@ -85,6 +88,12 @@ static int copy_code(struct pt_regs *regs, u8 *buf, unsigned long src,
        if (__chk_range_not_ok(src, nbytes, TASK_SIZE_MAX))
                return -EINVAL;
 
+       /*
+        * Even if named copy_from_user_nmi() this can be invoked from
+        * other contexts and will not try to resolve a pagefault, which is
+        * the correct thing to do here as this code can be called from any
+        * context.
+        */
        return copy_from_user_nmi(buf, (void __user *)src, nbytes);
 }
 
@@ -115,13 +124,19 @@ void show_opcodes(struct pt_regs *regs, const char *loglvl)
        u8 opcodes[OPCODE_BUFSIZE];
        unsigned long prologue = regs->ip - PROLOGUE_SIZE;
 
-       if (copy_code(regs, opcodes, prologue, sizeof(opcodes))) {
-               printk("%sCode: Unable to access opcode bytes at RIP 0x%lx.\n",
-                      loglvl, prologue);
-       } else {
+       switch (copy_code(regs, opcodes, prologue, sizeof(opcodes))) {
+       case 0:
                printk("%sCode: %" __stringify(PROLOGUE_SIZE) "ph <%02x> %"
                       __stringify(EPILOGUE_SIZE) "ph\n", loglvl, opcodes,
                       opcodes[PROLOGUE_SIZE], opcodes + PROLOGUE_SIZE + 1);
+               break;
+       case -EPERM:
+               /* No access to the user space stack of other tasks. Ignore. */
+               break;
+       default:
+               printk("%sCode: Unable to access opcode bytes at RIP 0x%lx.\n",
+                      loglvl, prologue);
+               break;
        }
 }
 
index 7eb2a1c..3c41773 100644 (file)
@@ -161,6 +161,21 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL)
 
        /* Setup early boot stage 4-/5-level pagetables. */
        addq    phys_base(%rip), %rax
+
+       /*
+        * For SEV guests: Verify that the C-bit is correct. A malicious
+        * hypervisor could lie about the C-bit position to perform a ROP
+        * attack on the guest by writing to the unencrypted stack and wait for
+        * the next RET instruction.
+        * %rsi carries pointer to realmode data and is callee-clobbered. Save
+        * and restore it.
+        */
+       pushq   %rsi
+       movq    %rax, %rdi
+       call    sev_verify_cbit
+       popq    %rsi
+
+       /* Switch to new page-table */
        movq    %rax, %cr3
 
        /* Ensure I am executing from virtual addresses */
@@ -279,6 +294,7 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL)
 SYM_CODE_END(secondary_startup_64)
 
 #include "verify_cpu.S"
+#include "sev_verify_cbit.S"
 
 #ifdef CONFIG_HOTPLUG_CPU
 /*
index bb7e113..f9e5352 100644 (file)
@@ -101,8 +101,7 @@ u64 perf_reg_abi(struct task_struct *task)
 }
 
 void perf_get_regs_user(struct perf_regs *regs_user,
-                       struct pt_regs *regs,
-                       struct pt_regs *regs_user_copy)
+                       struct pt_regs *regs)
 {
        regs_user->regs = task_pt_regs(current);
        regs_user->abi = perf_reg_abi(current);
@@ -129,12 +128,20 @@ u64 perf_reg_abi(struct task_struct *task)
                return PERF_SAMPLE_REGS_ABI_64;
 }
 
+static DEFINE_PER_CPU(struct pt_regs, nmi_user_regs);
+
 void perf_get_regs_user(struct perf_regs *regs_user,
-                       struct pt_regs *regs,
-                       struct pt_regs *regs_user_copy)
+                       struct pt_regs *regs)
 {
+       struct pt_regs *regs_user_copy = this_cpu_ptr(&nmi_user_regs);
        struct pt_regs *user_regs = task_pt_regs(current);
 
+       if (!in_nmi()) {
+               regs_user->regs = user_regs;
+               regs_user->abi = perf_reg_abi(current);
+               return;
+       }
+
        /*
         * If we're in an NMI that interrupted task_pt_regs setup, then
         * we can't sample user regs at all.  This check isn't really
index 5f83cca..7d04b35 100644 (file)
@@ -178,6 +178,32 @@ void __init do_vc_no_ghcb(struct pt_regs *regs, unsigned long exit_code)
                goto fail;
        regs->dx = val >> 32;
 
+       /*
+        * This is a VC handler and the #VC is only raised when SEV-ES is
+        * active, which means SEV must be active too. Do sanity checks on the
+        * CPUID results to make sure the hypervisor does not trick the kernel
+        * into the no-sev path. This could map sensitive data unencrypted and
+        * make it accessible to the hypervisor.
+        *
+        * In particular, check for:
+        *      - Hypervisor CPUID bit
+        *      - Availability of CPUID leaf 0x8000001f
+        *      - SEV CPUID bit.
+        *
+        * The hypervisor might still report the wrong C-bit position, but this
+        * can't be checked here.
+        */
+
+       if ((fn == 1 && !(regs->cx & BIT(31))))
+               /* Hypervisor bit */
+               goto fail;
+       else if (fn == 0x80000000 && (regs->ax < 0x8000001f))
+               /* SEV leaf check */
+               goto fail;
+       else if ((fn == 0x8000001f && !(regs->ax & BIT(1))))
+               /* SEV bit */
+               goto fail;
+
        /* Skip over the CPUID two-byte opcode */
        regs->ip += 2;
 
index 4a96726..0bd1a0f 100644 (file)
@@ -374,8 +374,8 @@ fault:
        return ES_EXCEPTION;
 }
 
-static bool vc_slow_virt_to_phys(struct ghcb *ghcb, struct es_em_ctxt *ctxt,
-                                unsigned long vaddr, phys_addr_t *paddr)
+static enum es_result vc_slow_virt_to_phys(struct ghcb *ghcb, struct es_em_ctxt *ctxt,
+                                          unsigned long vaddr, phys_addr_t *paddr)
 {
        unsigned long va = (unsigned long)vaddr;
        unsigned int level;
@@ -394,15 +394,19 @@ static bool vc_slow_virt_to_phys(struct ghcb *ghcb, struct es_em_ctxt *ctxt,
                if (user_mode(ctxt->regs))
                        ctxt->fi.error_code |= X86_PF_USER;
 
-               return false;
+               return ES_EXCEPTION;
        }
 
+       if (WARN_ON_ONCE(pte_val(*pte) & _PAGE_ENC))
+               /* Emulated MMIO to/from encrypted memory not supported */
+               return ES_UNSUPPORTED;
+
        pa = (phys_addr_t)pte_pfn(*pte) << PAGE_SHIFT;
        pa |= va & ~page_level_mask(level);
 
        *paddr = pa;
 
-       return true;
+       return ES_OK;
 }
 
 /* Include code shared with pre-decompression boot stage */
@@ -731,6 +735,7 @@ static enum es_result vc_do_mmio(struct ghcb *ghcb, struct es_em_ctxt *ctxt,
 {
        u64 exit_code, exit_info_1, exit_info_2;
        unsigned long ghcb_pa = __pa(ghcb);
+       enum es_result res;
        phys_addr_t paddr;
        void __user *ref;
 
@@ -740,11 +745,12 @@ static enum es_result vc_do_mmio(struct ghcb *ghcb, struct es_em_ctxt *ctxt,
 
        exit_code = read ? SVM_VMGEXIT_MMIO_READ : SVM_VMGEXIT_MMIO_WRITE;
 
-       if (!vc_slow_virt_to_phys(ghcb, ctxt, (unsigned long)ref, &paddr)) {
-               if (!read)
+       res = vc_slow_virt_to_phys(ghcb, ctxt, (unsigned long)ref, &paddr);
+       if (res != ES_OK) {
+               if (res == ES_EXCEPTION && !read)
                        ctxt->fi.error_code |= X86_PF_WRITE;
 
-               return ES_EXCEPTION;
+               return res;
        }
 
        exit_info_1 = paddr;
diff --git a/arch/x86/kernel/sev_verify_cbit.S b/arch/x86/kernel/sev_verify_cbit.S
new file mode 100644 (file)
index 0000000..ee04941
--- /dev/null
@@ -0,0 +1,89 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ *     sev_verify_cbit.S - Code for verification of the C-bit position reported
+ *                         by the Hypervisor when running with SEV enabled.
+ *
+ *     Copyright (c) 2020  Joerg Roedel (jroedel@suse.de)
+ *
+ * sev_verify_cbit() is called before switching to a new long-mode page-table
+ * at boot.
+ *
+ * Verify that the C-bit position is correct by writing a random value to
+ * an encrypted memory location while on the current page-table. Then it
+ * switches to the new page-table to verify the memory content is still the
+ * same. After that it switches back to the current page-table and when the
+ * check succeeded it returns. If the check failed the code invalidates the
+ * stack pointer and goes into a hlt loop. The stack-pointer is invalidated to
+ * make sure no interrupt or exception can get the CPU out of the hlt loop.
+ *
+ * New page-table pointer is expected in %rdi (first parameter)
+ *
+ */
+SYM_FUNC_START(sev_verify_cbit)
+#ifdef CONFIG_AMD_MEM_ENCRYPT
+       /* First check if a C-bit was detected */
+       movq    sme_me_mask(%rip), %rsi
+       testq   %rsi, %rsi
+       jz      3f
+
+       /* sme_me_mask != 0 could mean SME or SEV - Check also for SEV */
+       movq    sev_status(%rip), %rsi
+       testq   %rsi, %rsi
+       jz      3f
+
+       /* Save CR4 in %rsi */
+       movq    %cr4, %rsi
+
+       /* Disable Global Pages */
+       movq    %rsi, %rdx
+       andq    $(~X86_CR4_PGE), %rdx
+       movq    %rdx, %cr4
+
+       /*
+        * Verified that running under SEV - now get a random value using
+        * RDRAND. This instruction is mandatory when running as an SEV guest.
+        *
+        * Don't bail out of the loop if RDRAND returns errors. It is better to
+        * prevent forward progress than to work with a non-random value here.
+        */
+1:     rdrand  %rdx
+       jnc     1b
+
+       /* Store value to memory and keep it in %rdx */
+       movq    %rdx, sev_check_data(%rip)
+
+       /* Backup current %cr3 value to restore it later */
+       movq    %cr3, %rcx
+
+       /* Switch to new %cr3 - This might unmap the stack */
+       movq    %rdi, %cr3
+
+       /*
+        * Compare value in %rdx with memory location. If C-bit is incorrect
+        * this would read the encrypted data and make the check fail.
+        */
+       cmpq    %rdx, sev_check_data(%rip)
+
+       /* Restore old %cr3 */
+       movq    %rcx, %cr3
+
+       /* Restore previous CR4 */
+       movq    %rsi, %cr4
+
+       /* Check CMPQ result */
+       je      3f
+
+       /*
+        * The check failed, prevent any forward progress to prevent ROP
+        * attacks, invalidate the stack and go into a hlt loop.
+        */
+       xorq    %rsp, %rsp
+       subq    $0x1000, %rsp
+2:     hlt
+       jmp 2b
+3:
+#endif
+       /* Return page-table pointer */
+       movq    %rdi, %rax
+       ret
+SYM_FUNC_END(sev_verify_cbit)
index 992fb14..420be87 100644 (file)
@@ -514,9 +514,6 @@ int tboot_force_iommu(void)
        if (!tboot_enabled())
                return 0;
 
-       if (intel_iommu_tboot_noforce)
-               return 1;
-
        if (no_iommu || swiotlb || dmar_disabled)
                pr_warn("Forcing Intel-IOMMU to enabled\n");
 
index 06a278b..83637a2 100644 (file)
@@ -90,6 +90,20 @@ static int kvm_check_cpuid(struct kvm_cpuid_entry2 *entries, int nent)
        return 0;
 }
 
+void kvm_update_pv_runtime(struct kvm_vcpu *vcpu)
+{
+       struct kvm_cpuid_entry2 *best;
+
+       best = kvm_find_cpuid_entry(vcpu, KVM_CPUID_FEATURES, 0);
+
+       /*
+        * save the feature bitmap to avoid cpuid lookup for every PV
+        * operation
+        */
+       if (best)
+               vcpu->arch.pv_cpuid.features = best->eax;
+}
+
 void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
 {
        struct kvm_cpuid_entry2 *best;
@@ -124,13 +138,6 @@ void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
                (best->eax & (1 << KVM_FEATURE_PV_UNHALT)))
                best->eax &= ~(1 << KVM_FEATURE_PV_UNHALT);
 
-       /*
-        * save the feature bitmap to avoid cpuid lookup for every PV
-        * operation
-        */
-       if (best)
-               vcpu->arch.pv_cpuid.features = best->eax;
-
        if (!kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT)) {
                best = kvm_find_cpuid_entry(vcpu, 0x1, 0);
                if (best)
@@ -162,6 +169,8 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
                vcpu->arch.guest_supported_xcr0 =
                        (best->eax | ((u64)best->edx << 32)) & supported_xcr0;
 
+       kvm_update_pv_runtime(vcpu);
+
        vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu);
        kvm_mmu_reset_context(vcpu);
 
@@ -169,6 +178,8 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
        vcpu->arch.cr4_guest_rsvd_bits =
            __cr4_reserved_bits(guest_cpuid_has, vcpu);
 
+       vcpu->arch.cr3_lm_rsvd_bits = rsvd_bits(cpuid_maxphyaddr(vcpu), 63);
+
        /* Invoke the vendor callback only after the above state is updated. */
        kvm_x86_ops.vcpu_after_set_cpuid(vcpu);
 }
@@ -672,7 +683,9 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
 
                edx.split.num_counters_fixed = min(cap.num_counters_fixed, MAX_FIXED_COUNTERS);
                edx.split.bit_width_fixed = cap.bit_width_fixed;
-               edx.split.reserved = 0;
+               edx.split.anythread_deprecated = 1;
+               edx.split.reserved1 = 0;
+               edx.split.reserved2 = 0;
 
                entry->eax = eax.full;
                entry->ebx = cap.events_mask;
index bf85779..f7a6e8f 100644 (file)
@@ -11,6 +11,7 @@ extern u32 kvm_cpu_caps[NCAPINTS] __read_mostly;
 void kvm_set_cpu_caps(void);
 
 void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu);
+void kvm_update_pv_runtime(struct kvm_vcpu *vcpu);
 struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
                                              u32 function, u32 index);
 int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
index 0d917eb..56cae1f 100644 (file)
@@ -4046,6 +4046,12 @@ static int em_clflush(struct x86_emulate_ctxt *ctxt)
        return X86EMUL_CONTINUE;
 }
 
+static int em_clflushopt(struct x86_emulate_ctxt *ctxt)
+{
+       /* emulating clflushopt regardless of cpuid */
+       return X86EMUL_CONTINUE;
+}
+
 static int em_movsxd(struct x86_emulate_ctxt *ctxt)
 {
        ctxt->dst.val = (s32) ctxt->src.val;
@@ -4585,7 +4591,7 @@ static const struct opcode group11[] = {
 };
 
 static const struct gprefix pfx_0f_ae_7 = {
-       I(SrcMem | ByteOp, em_clflush), N, N, N,
+       I(SrcMem | ByteOp, em_clflush), I(SrcMem | ByteOp, em_clflushopt), N, N,
 };
 
 static const struct group_dual group15 = { {
index 1f96adf..5bb1939 100644 (file)
@@ -856,12 +856,14 @@ static int pte_list_add(struct kvm_vcpu *vcpu, u64 *spte,
        } else {
                rmap_printk("pte_list_add: %p %llx many->many\n", spte, *spte);
                desc = (struct pte_list_desc *)(rmap_head->val & ~1ul);
-               while (desc->sptes[PTE_LIST_EXT-1] && desc->more) {
-                       desc = desc->more;
+               while (desc->sptes[PTE_LIST_EXT-1]) {
                        count += PTE_LIST_EXT;
-               }
-               if (desc->sptes[PTE_LIST_EXT-1]) {
-                       desc->more = mmu_alloc_pte_list_desc(vcpu);
+
+                       if (!desc->more) {
+                               desc->more = mmu_alloc_pte_list_desc(vcpu);
+                               desc = desc->more;
+                               break;
+                       }
                        desc = desc->more;
                }
                for (i = 0; desc->sptes[i]; ++i)
index 27e381c..ff28a5c 100644 (file)
@@ -49,7 +49,14 @@ bool is_tdp_mmu_root(struct kvm *kvm, hpa_t hpa)
 {
        struct kvm_mmu_page *sp;
 
+       if (!kvm->arch.tdp_mmu_enabled)
+               return false;
+       if (WARN_ON(!VALID_PAGE(hpa)))
+               return false;
+
        sp = to_shadow_page(hpa);
+       if (WARN_ON(!sp))
+               return false;
 
        return sp->tdp_mmu_page && sp->root_count;
 }
index 2f32fd0..1e81cfe 100644 (file)
@@ -3741,6 +3741,7 @@ static u64 svm_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio)
 static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
 {
        struct vcpu_svm *svm = to_svm(vcpu);
+       struct kvm_cpuid_entry2 *best;
 
        vcpu->arch.xsaves_enabled = guest_cpuid_has(vcpu, X86_FEATURE_XSAVE) &&
                                    boot_cpu_has(X86_FEATURE_XSAVE) &&
@@ -3753,6 +3754,13 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
        /* Check again if INVPCID interception if required */
        svm_check_invpcid(svm);
 
+       /* For sev guests, the memory encryption bit is not reserved in CR3.  */
+       if (sev_guest(vcpu->kvm)) {
+               best = kvm_find_cpuid_entry(vcpu, 0x8000001F, 0);
+               if (best)
+                       vcpu->arch.cr3_lm_rsvd_bits &= ~(1UL << (best->ebx & 0x3f));
+       }
+
        if (!kvm_vcpu_apicv_active(vcpu))
                return;
 
index f5ede41..078a39d 100644 (file)
@@ -255,11 +255,10 @@ static struct kmem_cache *x86_emulator_cache;
 
 /*
  * When called, it means the previous get/set msr reached an invalid msr.
- * Return 0 if we want to ignore/silent this failed msr access, or 1 if we want
- * to fail the caller.
+ * Return true if we want to ignore/silent this failed msr access.
  */
-static int kvm_msr_ignored_check(struct kvm_vcpu *vcpu, u32 msr,
-                                u64 data, bool write)
+static bool kvm_msr_ignored_check(struct kvm_vcpu *vcpu, u32 msr,
+                                 u64 data, bool write)
 {
        const char *op = write ? "wrmsr" : "rdmsr";
 
@@ -268,11 +267,11 @@ static int kvm_msr_ignored_check(struct kvm_vcpu *vcpu, u32 msr,
                        kvm_pr_unimpl("ignored %s: 0x%x data 0x%llx\n",
                                      op, msr, data);
                /* Mask the error */
-               return 0;
+               return true;
        } else {
                kvm_debug_ratelimited("unhandled %s: 0x%x data 0x%llx\n",
                                      op, msr, data);
-               return -ENOENT;
+               return false;
        }
 }
 
@@ -1042,7 +1041,7 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
        }
 
        if (is_long_mode(vcpu) &&
-           (cr3 & rsvd_bits(cpuid_maxphyaddr(vcpu), 63)))
+           (cr3 & vcpu->arch.cr3_lm_rsvd_bits))
                return 1;
        else if (is_pae_paging(vcpu) &&
                 !load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3))
@@ -1416,7 +1415,8 @@ static int do_get_msr_feature(struct kvm_vcpu *vcpu, unsigned index, u64 *data)
        if (r == KVM_MSR_RET_INVALID) {
                /* Unconditionally clear the output for simplicity */
                *data = 0;
-               r = kvm_msr_ignored_check(vcpu, index, 0, false);
+               if (kvm_msr_ignored_check(vcpu, index, 0, false))
+                       r = 0;
        }
 
        if (r)
@@ -1540,7 +1540,7 @@ static int __kvm_set_msr(struct kvm_vcpu *vcpu, u32 index, u64 data,
        struct msr_data msr;
 
        if (!host_initiated && !kvm_msr_allowed(vcpu, index, KVM_MSR_FILTER_WRITE))
-               return -EPERM;
+               return KVM_MSR_RET_FILTERED;
 
        switch (index) {
        case MSR_FS_BASE:
@@ -1581,7 +1581,8 @@ static int kvm_set_msr_ignored_check(struct kvm_vcpu *vcpu,
        int ret = __kvm_set_msr(vcpu, index, data, host_initiated);
 
        if (ret == KVM_MSR_RET_INVALID)
-               ret = kvm_msr_ignored_check(vcpu, index, data, true);
+               if (kvm_msr_ignored_check(vcpu, index, data, true))
+                       ret = 0;
 
        return ret;
 }
@@ -1599,7 +1600,7 @@ int __kvm_get_msr(struct kvm_vcpu *vcpu, u32 index, u64 *data,
        int ret;
 
        if (!host_initiated && !kvm_msr_allowed(vcpu, index, KVM_MSR_FILTER_READ))
-               return -EPERM;
+               return KVM_MSR_RET_FILTERED;
 
        msr.index = index;
        msr.host_initiated = host_initiated;
@@ -1618,7 +1619,8 @@ static int kvm_get_msr_ignored_check(struct kvm_vcpu *vcpu,
        if (ret == KVM_MSR_RET_INVALID) {
                /* Unconditionally clear *data for simplicity */
                *data = 0;
-               ret = kvm_msr_ignored_check(vcpu, index, 0, false);
+               if (kvm_msr_ignored_check(vcpu, index, 0, false))
+                       ret = 0;
        }
 
        return ret;
@@ -1662,9 +1664,9 @@ static int complete_emulated_wrmsr(struct kvm_vcpu *vcpu)
 static u64 kvm_msr_reason(int r)
 {
        switch (r) {
-       case -ENOENT:
+       case KVM_MSR_RET_INVALID:
                return KVM_MSR_EXIT_REASON_UNKNOWN;
-       case -EPERM:
+       case KVM_MSR_RET_FILTERED:
                return KVM_MSR_EXIT_REASON_FILTER;
        default:
                return KVM_MSR_EXIT_REASON_INVAL;
@@ -1965,7 +1967,7 @@ static void kvm_write_system_time(struct kvm_vcpu *vcpu, gpa_t system_time,
        struct kvm_arch *ka = &vcpu->kvm->arch;
 
        if (vcpu->vcpu_id == 0 && !host_initiated) {
-               if (ka->boot_vcpu_runs_old_kvmclock && old_msr)
+               if (ka->boot_vcpu_runs_old_kvmclock != old_msr)
                        kvm_make_request(KVM_REQ_MASTERCLOCK_UPDATE, vcpu);
 
                ka->boot_vcpu_runs_old_kvmclock = old_msr;
@@ -3063,9 +3065,9 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
                        /* Values other than LBR and BTF are vendor-specific,
                           thus reserved and should throw a #GP */
                        return 1;
-               }
-               vcpu_unimpl(vcpu, "%s: MSR_IA32_DEBUGCTLMSR 0x%llx, nop\n",
-                           __func__, data);
+               } else if (report_ignored_msrs)
+                       vcpu_unimpl(vcpu, "%s: MSR_IA32_DEBUGCTLMSR 0x%llx, nop\n",
+                                   __func__, data);
                break;
        case 0x200 ... 0x2ff:
                return kvm_mtrr_set_msr(vcpu, msr, data);
@@ -3463,29 +3465,63 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
                msr_info->data = vcpu->arch.efer;
                break;
        case MSR_KVM_WALL_CLOCK:
+               if (!guest_pv_has(vcpu, KVM_FEATURE_CLOCKSOURCE))
+                       return 1;
+
+               msr_info->data = vcpu->kvm->arch.wall_clock;
+               break;
        case MSR_KVM_WALL_CLOCK_NEW:
+               if (!guest_pv_has(vcpu, KVM_FEATURE_CLOCKSOURCE2))
+                       return 1;
+
                msr_info->data = vcpu->kvm->arch.wall_clock;
                break;
        case MSR_KVM_SYSTEM_TIME:
+               if (!guest_pv_has(vcpu, KVM_FEATURE_CLOCKSOURCE))
+                       return 1;
+
+               msr_info->data = vcpu->arch.time;
+               break;
        case MSR_KVM_SYSTEM_TIME_NEW:
+               if (!guest_pv_has(vcpu, KVM_FEATURE_CLOCKSOURCE2))
+                       return 1;
+
                msr_info->data = vcpu->arch.time;
                break;
        case MSR_KVM_ASYNC_PF_EN:
+               if (!guest_pv_has(vcpu, KVM_FEATURE_ASYNC_PF))
+                       return 1;
+
                msr_info->data = vcpu->arch.apf.msr_en_val;
                break;
        case MSR_KVM_ASYNC_PF_INT:
+               if (!guest_pv_has(vcpu, KVM_FEATURE_ASYNC_PF_INT))
+                       return 1;
+
                msr_info->data = vcpu->arch.apf.msr_int_val;
                break;
        case MSR_KVM_ASYNC_PF_ACK:
+               if (!guest_pv_has(vcpu, KVM_FEATURE_ASYNC_PF))
+                       return 1;
+
                msr_info->data = 0;
                break;
        case MSR_KVM_STEAL_TIME:
+               if (!guest_pv_has(vcpu, KVM_FEATURE_STEAL_TIME))
+                       return 1;
+
                msr_info->data = vcpu->arch.st.msr_val;
                break;
        case MSR_KVM_PV_EOI_EN:
+               if (!guest_pv_has(vcpu, KVM_FEATURE_PV_EOI))
+                       return 1;
+
                msr_info->data = vcpu->arch.pv_eoi.msr_val;
                break;
        case MSR_KVM_POLL_CONTROL:
+               if (!guest_pv_has(vcpu, KVM_FEATURE_POLL_CONTROL))
+                       return 1;
+
                msr_info->data = vcpu->arch.msr_kvm_poll_control;
                break;
        case MSR_IA32_P5_MC_ADDR:
@@ -4575,6 +4611,8 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
 
        case KVM_CAP_ENFORCE_PV_FEATURE_CPUID:
                vcpu->arch.pv_cpuid.enforce = cap->args[0];
+               if (vcpu->arch.pv_cpuid.enforce)
+                       kvm_update_pv_runtime(vcpu);
 
                return 0;
 
index 3900ab0..e7ca622 100644 (file)
@@ -376,7 +376,13 @@ int kvm_handle_memory_failure(struct kvm_vcpu *vcpu, int r,
 int kvm_handle_invpcid(struct kvm_vcpu *vcpu, unsigned long type, gva_t gva);
 bool kvm_msr_allowed(struct kvm_vcpu *vcpu, u32 index, u32 type);
 
-#define  KVM_MSR_RET_INVALID  2
+/*
+ * Internal error codes that are used to indicate that MSR emulation encountered
+ * an error that should result in #GP in the guest, unless userspace
+ * handles it.
+ */
+#define  KVM_MSR_RET_INVALID   2       /* in-kernel MSR emulation #GP condition */
+#define  KVM_MSR_RET_FILTERED  3       /* #GP due to userspace MSR filter */
 
 #define __cr4_reserved_bits(__cpu_has, __c)             \
 ({                                                      \
index 037faac..1e299ac 100644 (file)
@@ -16,8 +16,6 @@
  * to a jmp to memcpy_erms which does the REP; MOVSB mem copy.
  */
 
-.weak memcpy
-
 /*
  * memcpy - Copy a memory block.
  *
@@ -30,7 +28,7 @@
  * rax original destination
  */
 SYM_FUNC_START_ALIAS(__memcpy)
-SYM_FUNC_START_LOCAL(memcpy)
+SYM_FUNC_START_WEAK(memcpy)
        ALTERNATIVE_2 "jmp memcpy_orig", "", X86_FEATURE_REP_GOOD, \
                      "jmp memcpy_erms", X86_FEATURE_ERMS
 
index 7ff00ea..41902fe 100644 (file)
@@ -24,9 +24,7 @@
  * Output:
  * rax: dest
  */
-.weak memmove
-
-SYM_FUNC_START_ALIAS(memmove)
+SYM_FUNC_START_WEAK(memmove)
 SYM_FUNC_START(__memmove)
 
        mov %rdi, %rax
index 9ff15ee..0bfd26e 100644 (file)
@@ -6,8 +6,6 @@
 #include <asm/alternative-asm.h>
 #include <asm/export.h>
 
-.weak memset
-
 /*
  * ISO C memset - set a memory block to a byte value. This function uses fast
  * string to get better performance than the original function. The code is
@@ -19,7 +17,7 @@
  *
  * rax   original destination
  */
-SYM_FUNC_START_ALIAS(memset)
+SYM_FUNC_START_WEAK(memset)
 SYM_FUNC_START(__memset)
        /*
         * Some CPUs support enhanced REP MOVSB/STOSB feature. It is recommended
index efbb3de..bc08337 100644 (file)
@@ -39,6 +39,7 @@
  */
 u64 sme_me_mask __section(".data") = 0;
 u64 sev_status __section(".data") = 0;
+u64 sev_check_data __section(".data") = 0;
 EXPORT_SYMBOL(sme_me_mask);
 DEFINE_STATIC_KEY_FALSE(sev_enable_key);
 EXPORT_SYMBOL_GPL(sev_enable_key);
index 4414869..5eb4dc2 100644 (file)
@@ -938,6 +938,7 @@ int phys_to_target_node(phys_addr_t start)
 
        return meminfo_to_nid(&numa_reserved_meminfo, start);
 }
+EXPORT_SYMBOL_GPL(phys_to_target_node);
 
 int memory_add_physaddr_to_nid(u64 start)
 {
@@ -947,4 +948,5 @@ int memory_add_physaddr_to_nid(u64 start)
                nid = numa_meminfo.blk[0].nid;
        return nid;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
 #endif
index 8f5759d..e1e8d4e 100644 (file)
@@ -78,28 +78,30 @@ int __init efi_alloc_page_tables(void)
        gfp_mask = GFP_KERNEL | __GFP_ZERO;
        efi_pgd = (pgd_t *)__get_free_pages(gfp_mask, PGD_ALLOCATION_ORDER);
        if (!efi_pgd)
-               return -ENOMEM;
+               goto fail;
 
        pgd = efi_pgd + pgd_index(EFI_VA_END);
        p4d = p4d_alloc(&init_mm, pgd, EFI_VA_END);
-       if (!p4d) {
-               free_page((unsigned long)efi_pgd);
-               return -ENOMEM;
-       }
+       if (!p4d)
+               goto free_pgd;
 
        pud = pud_alloc(&init_mm, p4d, EFI_VA_END);
-       if (!pud) {
-               if (pgtable_l5_enabled())
-                       free_page((unsigned long) pgd_page_vaddr(*pgd));
-               free_pages((unsigned long)efi_pgd, PGD_ALLOCATION_ORDER);
-               return -ENOMEM;
-       }
+       if (!pud)
+               goto free_p4d;
 
        efi_mm.pgd = efi_pgd;
        mm_init_cpumask(&efi_mm);
        init_new_context(NULL, &efi_mm);
 
        return 0;
+
+free_p4d:
+       if (pgtable_l5_enabled())
+               free_page((unsigned long)pgd_page_vaddr(*pgd));
+free_pgd:
+       free_pages((unsigned long)efi_pgd, PGD_ALLOCATION_ORDER);
+fail:
+       return -ENOMEM;
 }
 
 /*
index 799f4eb..043c73d 100644 (file)
@@ -93,10 +93,20 @@ void xen_init_lock_cpu(int cpu)
 
 void xen_uninit_lock_cpu(int cpu)
 {
+       int irq;
+
        if (!xen_pvspin)
                return;
 
-       unbind_from_irqhandler(per_cpu(lock_kicker_irq, cpu), NULL);
+       /*
+        * When booting the kernel with 'mitigations=auto,nosmt', the secondary
+        * CPUs are not activated, and lock_kicker_irq is not initialized.
+        */
+       irq = per_cpu(lock_kicker_irq, cpu);
+       if (irq == -1)
+               return;
+
+       unbind_from_irqhandler(irq, NULL);
        per_cpu(lock_kicker_irq, cpu) = -1;
        kfree(per_cpu(irq_name, cpu));
        per_cpu(irq_name, cpu) = NULL;
index fa054a1..4dc04e6 100644 (file)
@@ -69,7 +69,7 @@
  */
 #define VMALLOC_START          (XCHAL_KSEG_CACHED_VADDR - 0x10000000)
 #define VMALLOC_END            (VMALLOC_START + 0x07FEFFFF)
-#define TLBTEMP_BASE_1         (VMALLOC_END + 1)
+#define TLBTEMP_BASE_1         (VMALLOC_START + 0x08000000)
 #define TLBTEMP_BASE_2         (TLBTEMP_BASE_1 + DCACHE_WAY_SIZE)
 #if 2 * DCACHE_WAY_SIZE > ICACHE_WAY_SIZE
 #define TLBTEMP_SIZE           (2 * DCACHE_WAY_SIZE)
index b975811..5c9fb80 100644 (file)
@@ -302,7 +302,7 @@ strncpy_from_user(char *dst, const char __user *src, long count)
        return -EFAULT;
 }
 #else
-long strncpy_from_user(char *dst, const char *src, long count);
+long strncpy_from_user(char *dst, const char __user *src, long count);
 #endif
 
 /*
index 5835406..085b8c7 100644 (file)
@@ -70,8 +70,10 @@ static inline void kmap_invalidate_coherent(struct page *page,
                        kvaddr = TLBTEMP_BASE_1 +
                                (page_to_phys(page) & DCACHE_ALIAS_MASK);
 
+                       preempt_disable();
                        __invalidate_dcache_page_alias(kvaddr,
                                                       page_to_phys(page));
+                       preempt_enable();
                }
        }
 }
@@ -156,6 +158,7 @@ void flush_dcache_page(struct page *page)
                if (!alias && !mapping)
                        return;
 
+               preempt_disable();
                virt = TLBTEMP_BASE_1 + (phys & DCACHE_ALIAS_MASK);
                __flush_invalidate_dcache_page_alias(virt, phys);
 
@@ -166,6 +169,7 @@ void flush_dcache_page(struct page *page)
 
                if (mapping)
                        __invalidate_icache_page_alias(virt, phys);
+               preempt_enable();
        }
 
        /* There shouldn't be an entry in the cache for this page anymore. */
@@ -199,8 +203,10 @@ void local_flush_cache_page(struct vm_area_struct *vma, unsigned long address,
        unsigned long phys = page_to_phys(pfn_to_page(pfn));
        unsigned long virt = TLBTEMP_BASE_1 + (address & DCACHE_ALIAS_MASK);
 
+       preempt_disable();
        __flush_invalidate_dcache_page_alias(virt, phys);
        __invalidate_icache_page_alias(virt, phys);
+       preempt_enable();
 }
 EXPORT_SYMBOL(local_flush_cache_page);
 
@@ -227,11 +233,13 @@ update_mmu_cache(struct vm_area_struct * vma, unsigned long addr, pte_t *ptep)
                unsigned long phys = page_to_phys(page);
                unsigned long tmp;
 
+               preempt_disable();
                tmp = TLBTEMP_BASE_1 + (phys & DCACHE_ALIAS_MASK);
                __flush_invalidate_dcache_page_alias(tmp, phys);
                tmp = TLBTEMP_BASE_1 + (addr & DCACHE_ALIAS_MASK);
                __flush_invalidate_dcache_page_alias(tmp, phys);
                __invalidate_icache_page_alias(tmp, phys);
+               preempt_enable();
 
                clear_bit(PG_arch_1, &page->flags);
        }
@@ -265,7 +273,9 @@ void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
 
        if (alias) {
                unsigned long t = TLBTEMP_BASE_1 + (vaddr & DCACHE_ALIAS_MASK);
+               preempt_disable();
                __flush_invalidate_dcache_page_alias(t, phys);
+               preempt_enable();
        }
 
        /* Copy data */
@@ -280,9 +290,11 @@ void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
        if (alias) {
                unsigned long t = TLBTEMP_BASE_1 + (vaddr & DCACHE_ALIAS_MASK);
 
+               preempt_disable();
                __flush_invalidate_dcache_range((unsigned long) dst, len);
                if ((vma->vm_flags & VM_EXEC) != 0)
                        __invalidate_icache_page_alias(t, phys);
+               preempt_enable();
 
        } else if ((vma->vm_flags & VM_EXEC) != 0) {
                __flush_dcache_range((unsigned long)dst,len);
@@ -304,7 +316,9 @@ extern void copy_from_user_page(struct vm_area_struct *vma, struct page *page,
 
        if (alias) {
                unsigned long t = TLBTEMP_BASE_1 + (vaddr & DCACHE_ALIAS_MASK);
+               preempt_disable();
                __flush_invalidate_dcache_page_alias(t, phys);
+               preempt_enable();
        }
 
        memcpy(dst, src, len);
index c6fc83e..8731b7a 100644 (file)
@@ -89,8 +89,8 @@ static void __init free_highpages(void)
        /* set highmem page free */
        for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE,
                                &range_start, &range_end, NULL) {
-               unsigned long start = PHYS_PFN(range_start);
-               unsigned long end = PHYS_PFN(range_end);
+               unsigned long start = PFN_UP(range_start);
+               unsigned long end = PFN_DOWN(range_end);
 
                /* Ignore complete lowmem entries */
                if (end <= max_low)
index c68bdf5..54fbe1e 100644 (file)
@@ -849,6 +849,7 @@ static void blkcg_fill_root_iostats(void)
                        blkg_iostat_set(&blkg->iostat.cur, &tmp);
                        u64_stats_update_end(&blkg->iostat.sync);
                }
+               disk_put_part(part);
        }
 }
 
index e32958f..fd5cee9 100644 (file)
@@ -225,13 +225,18 @@ static void flush_end_io(struct request *flush_rq, blk_status_t error)
        /* release the tag's ownership to the req cloned from */
        spin_lock_irqsave(&fq->mq_flush_lock, flags);
 
-       WRITE_ONCE(flush_rq->state, MQ_RQ_IDLE);
        if (!refcount_dec_and_test(&flush_rq->ref)) {
                fq->rq_status = error;
                spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
                return;
        }
 
+       /*
+        * Flush request has to be marked as IDLE when it is really ended
+        * because its .end_io() is called from timeout code path too for
+        * avoiding use-after-free.
+        */
+       WRITE_ONCE(flush_rq->state, MQ_RQ_IDLE);
        if (fq->rq_status != BLK_STS_OK)
                error = fq->rq_status;
 
index 0a27321..9387f05 100644 (file)
@@ -49,7 +49,7 @@ static void disk_release_events(struct gendisk *disk);
  * Set disk capacity and notify if the size is not currently
  * zero and will not be set to zero
  */
-void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
+bool set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
                                        bool update_bdev)
 {
        sector_t capacity = get_capacity(disk);
@@ -62,7 +62,10 @@ void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
                char *envp[] = { "RESIZE=1", NULL };
 
                kobject_uevent_env(&disk_to_dev(disk)->kobj, KOBJ_CHANGE, envp);
+               return true;
        }
+
+       return false;
 }
 
 EXPORT_SYMBOL_GPL(set_capacity_revalidate_and_notify);
index be79b21..4801966 100644 (file)
@@ -357,7 +357,6 @@ static void speakup_cut(struct vc_data *vc)
        mark_cut_flag = 0;
        synth_printf("%s\n", spk_msg_get(MSG_CUT));
 
-       speakup_clear_selection();
        ret = speakup_set_selection(tty);
 
        switch (ret) {
index 032f326..7df7afa 100644 (file)
@@ -22,13 +22,6 @@ struct speakup_selection_work {
        struct tty_struct *tty;
 };
 
-void speakup_clear_selection(void)
-{
-       console_lock();
-       clear_selection();
-       console_unlock();
-}
-
 static void __speakup_set_selection(struct work_struct *work)
 {
        struct speakup_selection_work *ssw =
@@ -51,6 +44,10 @@ static void __speakup_set_selection(struct work_struct *work)
                goto unref;
        }
 
+       console_lock();
+       clear_selection();
+       console_unlock();
+
        set_selection_kernel(&sel, tty);
 
 unref:
index 74fe49c..33594f5 100644 (file)
@@ -70,7 +70,6 @@ void spk_do_flush(void);
 void speakup_start_ttys(void);
 void synth_buffer_add(u16 ch);
 void synth_buffer_clear(void);
-void speakup_clear_selection(void);
 int speakup_set_selection(struct tty_struct *tty);
 void speakup_cancel_selection(void);
 int speakup_paste_selection(struct tty_struct *tty);
index a831ff6..669392f 100644 (file)
@@ -49,15 +49,25 @@ static int spk_ttyio_ldisc_open(struct tty_struct *tty)
 
        if (!tty->ops->write)
                return -EOPNOTSUPP;
+
+       mutex_lock(&speakup_tty_mutex);
+       if (speakup_tty) {
+               mutex_unlock(&speakup_tty_mutex);
+               return -EBUSY;
+       }
        speakup_tty = tty;
 
        ldisc_data = kmalloc(sizeof(*ldisc_data), GFP_KERNEL);
-       if (!ldisc_data)
+       if (!ldisc_data) {
+               speakup_tty = NULL;
+               mutex_unlock(&speakup_tty_mutex);
                return -ENOMEM;
+       }
 
        init_completion(&ldisc_data->completion);
        ldisc_data->buf_free = true;
        speakup_tty->disc_data = ldisc_data;
+       mutex_unlock(&speakup_tty_mutex);
 
        return 0;
 }
@@ -298,11 +308,13 @@ static unsigned char ttyio_in(int timeout)
        struct spk_ldisc_data *ldisc_data = speakup_tty->disc_data;
        char rv;
 
-       if (wait_for_completion_timeout(&ldisc_data->completion,
+       if (!timeout) {
+               if (!try_wait_for_completion(&ldisc_data->completion))
+                       return 0xff;
+       } else if (wait_for_completion_timeout(&ldisc_data->completion,
                                        usecs_to_jiffies(timeout)) == 0) {
-               if (timeout)
-                       pr_warn("spk_ttyio: timeout (%d)  while waiting for input\n",
-                               timeout);
+               pr_warn("spk_ttyio: timeout (%d)  while waiting for input\n",
+                       timeout);
                return 0xff;
        }
 
index 7398f11..91fca30 100644 (file)
@@ -32,6 +32,10 @@ enum {
        E_NEW_DEFAULT,
 };
 
+/*
+ * Note: add new members at the end, speakupmap.h depends on the values of the
+ * enum starting from SPELL_DELAY (see inc_dec_var)
+ */
 enum var_id_t {
        VERSION = 0, SYNTH, SILENT, SYNTH_DIRECT,
        KEYMAP, CHARS,
@@ -42,9 +46,9 @@ enum var_id_t {
        SAY_CONTROL, SAY_WORD_CTL, NO_INTERRUPT, KEY_ECHO,
        SPELL_DELAY, PUNC_LEVEL, READING_PUNC,
        ATTRIB_BLEEP, BLEEPS,
-       RATE, PITCH, INFLECTION, VOL, TONE, PUNCT, VOICE, FREQUENCY, LANG,
+       RATE, PITCH, VOL, TONE, PUNCT, VOICE, FREQUENCY, LANG,
        DIRECT, PAUSE,
-       CAPS_START, CAPS_STOP, CHARTAB,
+       CAPS_START, CAPS_STOP, CHARTAB, INFLECTION,
        MAXVARS
 };
 
index bc96457..a322a7b 100644 (file)
@@ -578,7 +578,7 @@ acpi_video_bqc_value_to_level(struct acpi_video_device *device,
                                ACPI_VIDEO_FIRST_LEVEL - 1 - bqc_value;
 
                level = device->brightness->levels[bqc_value +
-                                                  ACPI_VIDEO_FIRST_LEVEL];
+                                                  ACPI_VIDEO_FIRST_LEVEL];
        } else {
                level = bqc_value;
        }
@@ -990,8 +990,8 @@ set_level:
                goto out_free_levels;
 
        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                         "found %d brightness levels\n",
-                         br->count - ACPI_VIDEO_FIRST_LEVEL));
+                         "found %d brightness levels\n",
+                         br->count - ACPI_VIDEO_FIRST_LEVEL));
        return 0;
 
 out_free_levels:
index 552fd9f..3294cc8 100644 (file)
@@ -633,6 +633,10 @@ int apei_map_generic_address(struct acpi_generic_address *reg)
        if (rc)
                return rc;
 
+       /* IO space doesn't need mapping */
+       if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
+               return 0;
+
        if (!acpi_os_map_generic_address(reg))
                return -ENXIO;
 
index cab4af5..08ee1c7 100644 (file)
@@ -987,7 +987,7 @@ static int acpi_battery_update(struct acpi_battery *battery, bool resume)
         */
        if ((battery->state & ACPI_BATTERY_STATE_CRITICAL) ||
            (test_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags) &&
-            (battery->capacity_now <= battery->alarm)))
+            (battery->capacity_now <= battery->alarm)))
                acpi_pm_wakeup_event(&battery->device->dev);
 
        return result;
index 0761529..0d93a5e 100644 (file)
@@ -89,7 +89,18 @@ static const struct dmi_system_id dmi_lid_quirks[] = {
                 */
                .matches = {
                        DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
-                       DMI_MATCH(DMI_PRODUCT_NAME, "E2215T MD60198"),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "E2215T"),
+               },
+               .driver_data = (void *)(long)ACPI_BUTTON_LID_INIT_OPEN,
+       },
+       {
+               /*
+                * Medion Akoya E2228T, notification of the LID device only
+                * happens on close, not on open and _LID always returns closed.
+                */
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "E2228T"),
                },
                .driver_data = (void *)(long)ACPI_BUTTON_LID_INIT_OPEN,
        },
index 4c1992f..5fca182 100644 (file)
@@ -106,6 +106,7 @@ static int pch_fivr_remove(struct platform_device *pdev)
 
 static const struct acpi_device_id pch_fivr_device_ids[] = {
        {"INTC1045", 0},
+       {"INTC1049", 0},
        {"", 0},
 };
 MODULE_DEVICE_TABLE(acpi, pch_fivr_device_ids);
index 0674130..a24d5d7 100644 (file)
@@ -229,6 +229,8 @@ static const struct acpi_device_id int3407_device_ids[] = {
        {"INT3532", 0},
        {"INTC1047", 0},
        {"INTC1050", 0},
+       {"INTC1060", 0},
+       {"INTC1061", 0},
        {"", 0},
 };
 MODULE_DEVICE_TABLE(acpi, int3407_device_ids);
index 8d420c7..d14025a 100644 (file)
@@ -25,10 +25,16 @@ static const struct acpi_device_id int340x_thermal_device_ids[] = {
        {"INT340A"},
        {"INT340B"},
        {"INTC1040"},
+       {"INTC1041"},
        {"INTC1043"},
        {"INTC1044"},
        {"INTC1045"},
+       {"INTC1046"},
        {"INTC1047"},
+       {"INTC1048"},
+       {"INTC1049"},
+       {"INTC1060"},
+       {"INTC1061"},
        {""},
 };
 
index 1706439..92e59f4 100644 (file)
@@ -31,7 +31,7 @@ int acpi_notifier_call_chain(struct acpi_device *dev, u32 type, u32 data)
        event.type = type;
        event.data = data;
        return (blocking_notifier_call_chain(&acpi_chain_head, 0, (void *)&event)
-                        == NOTIFY_BAD) ? -EINVAL : 0;
+                       == NOTIFY_BAD) ? -EINVAL : 0;
 }
 EXPORT_SYMBOL(acpi_notifier_call_chain);
 
index b1a7f8d..fe6b679 100644 (file)
@@ -101,7 +101,7 @@ static acpi_status acpi_ged_request_interrupt(struct acpi_resource *ares,
 
        switch (gsi) {
        case 0 ... 255:
-               sprintf(ev_name, "_%c%02hhX",
+               sprintf(ev_name, "_%c%02X",
                        trigger == ACPI_EDGE_SENSITIVE ? 'E' : 'L', gsi);
 
                if (ACPI_SUCCESS(acpi_get_handle(handle, ev_name, &evt_handle)))
index 6287338..66c3983 100644 (file)
@@ -27,6 +27,7 @@ static const struct acpi_device_id fan_device_ids[] = {
        {"PNP0C0B", 0},
        {"INT3404", 0},
        {"INTC1044", 0},
+       {"INTC1048", 0},
        {"", 0},
 };
 MODULE_DEVICE_TABLE(acpi, fan_device_ids);
@@ -351,6 +352,7 @@ static int acpi_fan_get_fps(struct acpi_device *device)
                struct acpi_fan_fps *fps = &fan->fps[i];
 
                snprintf(fps->name, ACPI_FPS_NAME_LEN, "state%d", i);
+               sysfs_attr_init(&fps->dev_attr.attr);
                fps->dev_attr.show = show_state;
                fps->dev_attr.store = NULL;
                fps->dev_attr.attr.name = fps->name;
index 43411a7..e3638ba 100644 (file)
@@ -134,7 +134,7 @@ int acpi_add_power_resource(acpi_handle handle);
 void acpi_power_add_remove_device(struct acpi_device *adev, bool add);
 int acpi_power_wakeup_list_init(struct list_head *list, int *system_level);
 int acpi_device_sleep_wake(struct acpi_device *dev,
-                           int enable, int sleep_state, int dev_state);
+                          int enable, int sleep_state, int dev_state);
 int acpi_power_get_inferred_state(struct acpi_device *device, int *state);
 int acpi_power_on_resources(struct acpi_device *device, int state);
 int acpi_power_transition(struct acpi_device *device, int state);
index 3a3c209..4426082 100644 (file)
@@ -2175,10 +2175,10 @@ static int acpi_nfit_register_dimms(struct acpi_nfit_desc *acpi_desc)
  * these commands.
  */
 enum nfit_aux_cmds {
-        NFIT_CMD_TRANSLATE_SPA = 5,
-        NFIT_CMD_ARS_INJECT_SET = 7,
-        NFIT_CMD_ARS_INJECT_CLEAR = 8,
-        NFIT_CMD_ARS_INJECT_GET = 9,
+       NFIT_CMD_TRANSLATE_SPA = 5,
+       NFIT_CMD_ARS_INJECT_SET = 7,
+       NFIT_CMD_ARS_INJECT_CLEAR = 8,
+       NFIT_CMD_ARS_INJECT_GET = 9,
 };
 
 static void acpi_nfit_init_dsms(struct acpi_nfit_desc *acpi_desc)
@@ -2632,7 +2632,7 @@ static int acpi_nfit_blk_region_enable(struct nvdimm_bus *nvdimm_bus,
        nfit_blk->bdw_offset = nfit_mem->bdw->offset;
        mmio = &nfit_blk->mmio[BDW];
        mmio->addr.base = devm_nvdimm_memremap(dev, nfit_mem->spa_bdw->address,
-                        nfit_mem->spa_bdw->length, nd_blk_memremap_flags(ndbr));
+                       nfit_mem->spa_bdw->length, nd_blk_memremap_flags(ndbr));
        if (!mmio->addr.base) {
                dev_dbg(dev, "%s failed to map bdw\n",
                                nvdimm_name(nvdimm));
index dea8a60..14ee631 100644 (file)
@@ -175,7 +175,7 @@ static int acpi_pci_irq_check_entry(acpi_handle handle, struct pci_dev *dev,
         * configure the IRQ assigned to this slot|dev|pin.  The 'source_index'
         * indicates which resource descriptor in the resource template (of
         * the link device) this interrupt is allocated from.
-        * 
+        *
         * NOTE: Don't query the Link Device for IRQ information at this time
         *       because Link Device enumeration may not have occurred yet
         *       (e.g. exists somewhere 'below' this _PRT entry in the ACPI
index 606da5d..fb4c563 100644 (file)
@@ -6,8 +6,8 @@
  *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  *  Copyright (C) 2002       Dominik Brodowski <devel@brodo.de>
  *
- * TBD: 
- *      1. Support more than one IRQ resource entry per link device (index).
+ * TBD:
+ *     1. Support more than one IRQ resource entry per link device (index).
  *     2. Implement start/stop mechanism and use ACPI Bus Driver facilities
  *        for IRQ management (e.g. start()->_SRS).
  */
@@ -249,8 +249,8 @@ static int acpi_pci_link_get_current(struct acpi_pci_link *link)
                }
        }
 
-       /* 
-        * Query and parse _CRS to get the current IRQ assignment. 
+       /*
+        * Query and parse _CRS to get the current IRQ assignment.
         */
 
        status = acpi_walk_resources(link->device->handle, METHOD_NAME__CRS,
@@ -396,7 +396,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
 /*
  * "acpi_irq_balance" (default in APIC mode) enables ACPI to use PIC Interrupt
  * Link Devices to move the PIRQs around to minimize sharing.
- * 
+ *
  * "acpi_irq_nobalance" (default in PIC mode) tells ACPI not to move any PIC IRQs
  * that the BIOS has already set to active.  This is necessary because
  * ACPI has no automatic means of knowing what ISA IRQs are used.  Note that
@@ -414,7 +414,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
  *
  * Note that PCI IRQ routers have a list of possible IRQs,
  * which may not include the IRQs this table says are available.
- * 
+ *
  * Since this heuristic can't tell the difference between a link
  * that no device will attach to, vs. a link which may be shared
  * by multiple active devices -- it is not optimal.
index 7ddd57a..95f23ac 100644 (file)
@@ -173,7 +173,7 @@ static int pci_mcfg_quirk_matches(struct mcfg_fixup *f, u16 segment,
 {
        if (!memcmp(f->oem_id, mcfg_oem_id, ACPI_OEM_ID_SIZE) &&
            !memcmp(f->oem_table_id, mcfg_oem_table_id,
-                   ACPI_OEM_TABLE_ID_SIZE) &&
+                   ACPI_OEM_TABLE_ID_SIZE) &&
            f->oem_revision == mcfg_oem_revision &&
            f->segment == segment &&
            resource_contains(&f->bus_range, bus_range))
index 837b875..8048da8 100644 (file)
@@ -13,7 +13,7 @@
  * 1. via "Device Specific (D-State) Control"
  * 2. via "Power Resource Control".
  * The code below deals with ACPI Power Resources control.
- * 
+ *
  * An ACPI "power resource object" represents a software controllable power
  * plane, clock plane, or other resource depended on by a device.
  *
@@ -645,7 +645,7 @@ int acpi_power_wakeup_list_init(struct list_head *list, int *system_level_p)
  * -ENODEV if the execution of either _DSW or _PSW has failed
  */
 int acpi_device_sleep_wake(struct acpi_device *dev,
-                           int enable, int sleep_state, int dev_state)
+                          int enable, int sleep_state, int dev_state)
 {
        union acpi_object in_arg[3];
        struct acpi_object_list arg_list = { 3, in_arg };
@@ -690,7 +690,7 @@ int acpi_device_sleep_wake(struct acpi_device *dev,
 
 /*
  * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229):
- * 1. Power on the power resources required for the wakeup device 
+ * 1. Power on the power resources required for the wakeup device
  * 2. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power
  *    State Wake) for the device, if present
  */
index 5909e8f..b04a689 100644 (file)
@@ -354,7 +354,7 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)
                                  (u32) px->control, (u32) px->status));
 
                /*
-                * Check that ACPI's u64 MHz will be valid as u32 KHz in cpufreq
+                * Check that ACPI's u64 MHz will be valid as u32 KHz in cpufreq
                 */
                if (!px->core_frequency ||
                    ((u32)(px->core_frequency * 1000) !=
@@ -627,7 +627,7 @@ int acpi_processor_preregister_performance(
                goto err_ret;
 
        /*
-        * Now that we have _PSD data from all CPUs, lets setup P-state 
+        * Now that we have _PSD data from all CPUs, lets setup P-state
         * domain info.
         */
        for_each_possible_cpu(i) {
@@ -693,7 +693,7 @@ int acpi_processor_preregister_performance(
                        if (match_pdomain->domain != pdomain->domain)
                                continue;
 
-                       match_pr->performance->shared_type = 
+                       match_pr->performance->shared_type =
                                        pr->performance->shared_type;
                        cpumask_copy(match_pr->performance->shared_cpu_map,
                                     pr->performance->shared_cpu_map);
index f158b8c..e6d9f4d 100644 (file)
@@ -366,7 +366,7 @@ static int acpi_battery_get_state(struct acpi_battery *battery)
                                         state_readers[i].mode,
                                         ACPI_SBS_BATTERY,
                                         state_readers[i].command,
-                                        (u8 *)battery +
+                                        (u8 *)battery +
                                                state_readers[i].offset);
                if (result)
                        goto end;
index 87b74e9..53c2862 100644 (file)
@@ -176,7 +176,7 @@ int acpi_smbus_write(struct acpi_smb_hc *hc, u8 protocol, u8 address,
 EXPORT_SYMBOL_GPL(acpi_smbus_write);
 
 int acpi_smbus_register_callback(struct acpi_smb_hc *hc,
-                                smbus_alarm_callback callback, void *context)
+                                smbus_alarm_callback callback, void *context)
 {
        mutex_lock(&hc->lock);
        hc->callback = callback;
index c3522bb..695c390 100644 (file)
@@ -24,9 +24,9 @@ enum acpi_sbs_device_addr {
 typedef void (*smbus_alarm_callback)(void *context);
 
 extern int acpi_smbus_read(struct acpi_smb_hc *hc, u8 protocol, u8 address,
-              u8 command, u8 * data);
+               u8 command, u8 *data);
 extern int acpi_smbus_write(struct acpi_smb_hc *hc, u8 protocol, u8 slave_address,
-               u8 command, u8 * data, u8 length);
+               u8 command, u8 *data, u8 length);
 extern int acpi_smbus_register_callback(struct acpi_smb_hc *hc,
-                                smbus_alarm_callback callback, void *context);
+               smbus_alarm_callback callback, void *context);
 extern int acpi_smbus_unregister_callback(struct acpi_smb_hc *hc);
index a896e5e..bc6a79e 100644 (file)
@@ -1453,7 +1453,7 @@ int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
 }
 
 /**
- * acpi_dma_configure - Set-up DMA configuration for the device.
+ * acpi_dma_configure_id - Set-up DMA configuration for the device.
  * @dev: The pointer to the device
  * @attr: device dma attributes
  * @input_id: input device id const value pointer
index 3a032af..4f5463b 100644 (file)
@@ -178,14 +178,14 @@ static const struct dmi_system_id video_detect_dmi_table[] = {
                DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201s"),
                },
        },
-        {
-         .callback = video_detect_force_video,
-         .ident = "ThinkPad X201T",
-         .matches = {
-                DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
-                DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201T"),
-                },
-        },
+       {
+        .callback = video_detect_force_video,
+        .ident = "ThinkPad X201T",
+        .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+               DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201T"),
+               },
+       },
 
        /* The native backlight controls do not work on some older machines */
        {
index f89dd9a..b02bf77 100644 (file)
@@ -44,7 +44,7 @@ void acpi_enable_wakeup_devices(u8 sleep_state)
                if (!dev->wakeup.flags.valid
                    || sleep_state > (u32) dev->wakeup.sleep_state
                    || !(device_may_wakeup(&dev->dev)
-                       || dev->wakeup.prepare_count))
+                        || dev->wakeup.prepare_count))
                        continue;
 
                if (device_may_wakeup(&dev->dev))
@@ -69,7 +69,7 @@ void acpi_disable_wakeup_devices(u8 sleep_state)
                if (!dev->wakeup.flags.valid
                    || sleep_state > (u32) dev->wakeup.sleep_state
                    || !(device_may_wakeup(&dev->dev)
-                       || dev->wakeup.prepare_count))
+                        || dev->wakeup.prepare_count))
                        continue;
 
                acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
index 7af74fb..09ad733 100644 (file)
@@ -1706,6 +1706,8 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
 
        if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
                atomic_inc(&vcc->stats->tx_err);
+               dma_unmap_single(&card->pcidev->dev, NS_PRV_DMA(skb), skb->len,
+                                DMA_TO_DEVICE);
                dev_kfree_skb_any(skb);
                return -EIO;
        }
index 78114dd..d661ada 100644 (file)
@@ -773,8 +773,7 @@ static void __device_link_del(struct kref *kref)
        dev_dbg(link->consumer, "Dropping the link to %s\n",
                dev_name(link->supplier));
 
-       if (link->flags & DL_FLAG_PM_RUNTIME)
-               pm_runtime_drop_link(link->consumer);
+       pm_runtime_drop_link(link);
 
        list_del_rcu(&link->s_node);
        list_del_rcu(&link->c_node);
@@ -788,8 +787,7 @@ static void __device_link_del(struct kref *kref)
        dev_info(link->consumer, "Dropping the link to %s\n",
                 dev_name(link->supplier));
 
-       if (link->flags & DL_FLAG_PM_RUNTIME)
-               pm_runtime_drop_link(link->consumer);
+       pm_runtime_drop_link(link);
 
        list_del(&link->s_node);
        list_del(&link->c_node);
index b42229b..148e819 100644 (file)
@@ -1117,6 +1117,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)
 
        drv = dev->driver;
        if (drv) {
+               pm_runtime_get_sync(dev);
+
                while (device_links_busy(dev)) {
                        __device_driver_unlock(dev, parent);
 
@@ -1128,13 +1130,12 @@ static void __device_release_driver(struct device *dev, struct device *parent)
                         * have released the driver successfully while this one
                         * was waiting, so check for that.
                         */
-                       if (dev->driver != drv)
+                       if (dev->driver != drv) {
+                               pm_runtime_put(dev);
                                return;
+                       }
                }
 
-               pm_runtime_get_sync(dev);
-               pm_runtime_clean_up_links(dev);
-
                driver_sysfs_remove(dev);
 
                if (dev->bus)
index 6f605f7..bfda153 100644 (file)
@@ -1642,42 +1642,6 @@ void pm_runtime_remove(struct device *dev)
        pm_runtime_reinit(dev);
 }
 
-/**
- * pm_runtime_clean_up_links - Prepare links to consumers for driver removal.
- * @dev: Device whose driver is going to be removed.
- *
- * Check links from this device to any consumers and if any of them have active
- * runtime PM references to the device, drop the usage counter of the device
- * (as many times as needed).
- *
- * Links with the DL_FLAG_MANAGED flag unset are ignored.
- *
- * Since the device is guaranteed to be runtime-active at the point this is
- * called, nothing else needs to be done here.
- *
- * Moreover, this is called after device_links_busy() has returned 'false', so
- * the status of each link is guaranteed to be DL_STATE_SUPPLIER_UNBIND and
- * therefore rpm_active can't be manipulated concurrently.
- */
-void pm_runtime_clean_up_links(struct device *dev)
-{
-       struct device_link *link;
-       int idx;
-
-       idx = device_links_read_lock();
-
-       list_for_each_entry_rcu(link, &dev->links.consumers, s_node,
-                               device_links_read_lock_held()) {
-               if (!(link->flags & DL_FLAG_MANAGED))
-                       continue;
-
-               while (refcount_dec_not_one(&link->rpm_active))
-                       pm_runtime_put_noidle(dev);
-       }
-
-       device_links_read_unlock(idx);
-}
-
 /**
  * pm_runtime_get_suppliers - Resume and reference-count supplier devices.
  * @dev: Consumer device.
@@ -1729,7 +1693,7 @@ void pm_runtime_new_link(struct device *dev)
        spin_unlock_irq(&dev->power.lock);
 }
 
-void pm_runtime_drop_link(struct device *dev)
+static void pm_runtime_drop_link_count(struct device *dev)
 {
        spin_lock_irq(&dev->power.lock);
        WARN_ON(dev->power.links_count == 0);
@@ -1737,6 +1701,25 @@ void pm_runtime_drop_link(struct device *dev)
        spin_unlock_irq(&dev->power.lock);
 }
 
+/**
+ * pm_runtime_drop_link - Prepare for device link removal.
+ * @link: Device link going away.
+ *
+ * Drop the link count of the consumer end of @link and decrement the supplier
+ * device's runtime PM usage counter as many times as needed to drop all of the
+ * PM runtime reference to it from the consumer.
+ */
+void pm_runtime_drop_link(struct device_link *link)
+{
+       if (!(link->flags & DL_FLAG_PM_RUNTIME))
+               return;
+
+       pm_runtime_drop_link_count(link->consumer);
+
+       while (refcount_dec_not_one(&link->rpm_active))
+               pm_runtime_put(link->supplier);
+}
+
 static bool pm_runtime_need_not_resume(struct device *dev)
 {
        return atomic_read(&dev->power.usage_count) <= 1 &&
index cb1191d..a58084c 100644 (file)
@@ -255,7 +255,8 @@ static void loop_set_size(struct loop_device *lo, loff_t size)
 
        bd_set_nr_sectors(bdev, size);
 
-       set_capacity_revalidate_and_notify(lo->lo_disk, size, false);
+       if (!set_capacity_revalidate_and_notify(lo->lo_disk, size, false))
+               kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE);
 }
 
 static inline int
index c4f9ccf..aaae922 100644 (file)
@@ -1518,6 +1518,7 @@ static void nbd_release(struct gendisk *disk, fmode_t mode)
        if (test_bit(NBD_RT_DISCONNECT_ON_CLOSE, &nbd->config->runtime_flags) &&
                        bdev->bd_openers == 0)
                nbd_disconnect_and_put(nbd);
+       bdput(bdev);
 
        nbd_config_put(nbd);
        nbd_put(nbd);
index cfd00ad..c24d9b5 100644 (file)
@@ -47,7 +47,7 @@ struct nullb_device {
        unsigned int nr_zones_closed;
        struct blk_zone *zones;
        sector_t zone_size_sects;
-       spinlock_t zone_dev_lock;
+       spinlock_t zone_lock;
        unsigned long *zone_locks;
 
        unsigned long size; /* device size in MB */
index 8775acb..beb34b4 100644 (file)
@@ -46,11 +46,20 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q)
        if (!dev->zones)
                return -ENOMEM;
 
-       spin_lock_init(&dev->zone_dev_lock);
-       dev->zone_locks = bitmap_zalloc(dev->nr_zones, GFP_KERNEL);
-       if (!dev->zone_locks) {
-               kvfree(dev->zones);
-               return -ENOMEM;
+       /*
+        * With memory backing, the zone_lock spinlock needs to be temporarily
+        * released to avoid scheduling in atomic context. To guarantee zone
+        * information protection, use a bitmap to lock zones with
+        * wait_on_bit_lock_io(). Sleeping on the lock is OK as memory backing
+        * implies that the queue is marked with BLK_MQ_F_BLOCKING.
+        */
+       spin_lock_init(&dev->zone_lock);
+       if (dev->memory_backed) {
+               dev->zone_locks = bitmap_zalloc(dev->nr_zones, GFP_KERNEL);
+               if (!dev->zone_locks) {
+                       kvfree(dev->zones);
+                       return -ENOMEM;
+               }
        }
 
        if (dev->zone_nr_conv >= dev->nr_zones) {
@@ -137,12 +146,17 @@ void null_free_zoned_dev(struct nullb_device *dev)
 
 static inline void null_lock_zone(struct nullb_device *dev, unsigned int zno)
 {
-       wait_on_bit_lock_io(dev->zone_locks, zno, TASK_UNINTERRUPTIBLE);
+       if (dev->memory_backed)
+               wait_on_bit_lock_io(dev->zone_locks, zno, TASK_UNINTERRUPTIBLE);
+       spin_lock_irq(&dev->zone_lock);
 }
 
 static inline void null_unlock_zone(struct nullb_device *dev, unsigned int zno)
 {
-       clear_and_wake_up_bit(zno, dev->zone_locks);
+       spin_unlock_irq(&dev->zone_lock);
+
+       if (dev->memory_backed)
+               clear_and_wake_up_bit(zno, dev->zone_locks);
 }
 
 int null_report_zones(struct gendisk *disk, sector_t sector,
@@ -322,7 +336,6 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
                return null_process_cmd(cmd, REQ_OP_WRITE, sector, nr_sectors);
 
        null_lock_zone(dev, zno);
-       spin_lock(&dev->zone_dev_lock);
 
        switch (zone->cond) {
        case BLK_ZONE_COND_FULL:
@@ -375,9 +388,17 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
        if (zone->cond != BLK_ZONE_COND_EXP_OPEN)
                zone->cond = BLK_ZONE_COND_IMP_OPEN;
 
-       spin_unlock(&dev->zone_dev_lock);
+       /*
+        * Memory backing allocation may sleep: release the zone_lock spinlock
+        * to avoid scheduling in atomic context. Zone operation atomicity is
+        * still guaranteed through the zone_locks bitmap.
+        */
+       if (dev->memory_backed)
+               spin_unlock_irq(&dev->zone_lock);
        ret = null_process_cmd(cmd, REQ_OP_WRITE, sector, nr_sectors);
-       spin_lock(&dev->zone_dev_lock);
+       if (dev->memory_backed)
+               spin_lock_irq(&dev->zone_lock);
+
        if (ret != BLK_STS_OK)
                goto unlock;
 
@@ -392,7 +413,6 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
        ret = BLK_STS_OK;
 
 unlock:
-       spin_unlock(&dev->zone_dev_lock);
        null_unlock_zone(dev, zno);
 
        return ret;
@@ -516,9 +536,7 @@ static blk_status_t null_zone_mgmt(struct nullb_cmd *cmd, enum req_opf op,
                        null_lock_zone(dev, i);
                        zone = &dev->zones[i];
                        if (zone->cond != BLK_ZONE_COND_EMPTY) {
-                               spin_lock(&dev->zone_dev_lock);
                                null_reset_zone(dev, zone);
-                               spin_unlock(&dev->zone_dev_lock);
                                trace_nullb_zone_op(cmd, i, zone->cond);
                        }
                        null_unlock_zone(dev, i);
@@ -530,7 +548,6 @@ static blk_status_t null_zone_mgmt(struct nullb_cmd *cmd, enum req_opf op,
        zone = &dev->zones[zone_no];
 
        null_lock_zone(dev, zone_no);
-       spin_lock(&dev->zone_dev_lock);
 
        switch (op) {
        case REQ_OP_ZONE_RESET:
@@ -550,8 +567,6 @@ static blk_status_t null_zone_mgmt(struct nullb_cmd *cmd, enum req_opf op,
                break;
        }
 
-       spin_unlock(&dev->zone_dev_lock);
-
        if (ret == BLK_STS_OK)
                trace_nullb_zone_op(cmd, zone_no, zone->cond);
 
index 6bb023d..35229e5 100644 (file)
@@ -41,6 +41,11 @@ int tpm_read_log_efi(struct tpm_chip *chip)
        log_size = log_tbl->size;
        memunmap(log_tbl);
 
+       if (!log_size) {
+               pr_warn("UEFI TPM log area empty\n");
+               return -EIO;
+       }
+
        log_tbl = memremap(efi.tpm_log, sizeof(*log_tbl) + log_size,
                           MEMREMAP_WB);
        if (!log_tbl) {
index 0b21496..4ed6e66 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/kernel.h>
+#include <linux/dmi.h>
 #include "tpm.h"
 #include "tpm_tis_core.h"
 
@@ -49,8 +50,8 @@ static inline struct tpm_tis_tcg_phy *to_tpm_tis_tcg_phy(struct tpm_tis_data *da
        return container_of(data, struct tpm_tis_tcg_phy, priv);
 }
 
-static bool interrupts = true;
-module_param(interrupts, bool, 0444);
+static int interrupts = -1;
+module_param(interrupts, int, 0444);
 MODULE_PARM_DESC(interrupts, "Enable interrupts");
 
 static bool itpm;
@@ -63,6 +64,28 @@ module_param(force, bool, 0444);
 MODULE_PARM_DESC(force, "Force device probe rather than using ACPI entry");
 #endif
 
+static int tpm_tis_disable_irq(const struct dmi_system_id *d)
+{
+       if (interrupts == -1) {
+               pr_notice("tpm_tis: %s detected: disabling interrupts.\n", d->ident);
+               interrupts = 0;
+       }
+
+       return 0;
+}
+
+static const struct dmi_system_id tpm_tis_dmi_table[] = {
+       {
+               .callback = tpm_tis_disable_irq,
+               .ident = "ThinkPad T490s",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+                       DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T490s"),
+               },
+       },
+       {}
+};
+
 #if defined(CONFIG_PNP) && defined(CONFIG_ACPI)
 static int has_hid(struct acpi_device *dev, const char *hid)
 {
@@ -192,6 +215,8 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info)
        int irq = -1;
        int rc;
 
+       dmi_check_system(tpm_tis_dmi_table);
+
        rc = check_acpi_tpm2(dev);
        if (rc)
                return rc;
index a2da8f7..1836cc5 100644 (file)
@@ -435,12 +435,12 @@ static struct port_buffer *alloc_buf(struct virtio_device *vdev, size_t buf_size
                /*
                 * Allocate DMA memory from ancestor. When a virtio
                 * device is created by remoteproc, the DMA memory is
-                * associated with the grandparent device:
-                * vdev => rproc => platform-dev.
+                * associated with the parent device:
+                * virtioY => remoteprocX#vdevYbuffer.
                 */
-               if (!vdev->dev.parent || !vdev->dev.parent->parent)
+               buf->dev = vdev->dev.parent;
+               if (!buf->dev)
                        goto free_buf;
-               buf->dev = vdev->dev.parent->parent;
 
                /* Increase device refcnt to avoid freeing it */
                get_device(buf->dev);
index 0de0be0..f358ad9 100644 (file)
@@ -443,9 +443,9 @@ static int imx8mm_clocks_probe(struct platform_device *pdev)
        hws[IMX8MM_CLK_A53_CORE] = imx_clk_hw_mux2("arm_a53_core", base + 0x9880, 24, 1, imx8mm_a53_core_sels, ARRAY_SIZE(imx8mm_a53_core_sels));
 
        /* BUS */
-       hws[IMX8MM_CLK_MAIN_AXI] = imx8m_clk_hw_composite_critical("main_axi",  imx8mm_main_axi_sels, base + 0x8800);
+       hws[IMX8MM_CLK_MAIN_AXI] = imx8m_clk_hw_composite_bus_critical("main_axi",  imx8mm_main_axi_sels, base + 0x8800);
        hws[IMX8MM_CLK_ENET_AXI] = imx8m_clk_hw_composite_bus("enet_axi", imx8mm_enet_axi_sels, base + 0x8880);
-       hws[IMX8MM_CLK_NAND_USDHC_BUS] = imx8m_clk_hw_composite_critical("nand_usdhc_bus", imx8mm_nand_usdhc_sels, base + 0x8900);
+       hws[IMX8MM_CLK_NAND_USDHC_BUS] = imx8m_clk_hw_composite_bus_critical("nand_usdhc_bus", imx8mm_nand_usdhc_sels, base + 0x8900);
        hws[IMX8MM_CLK_VPU_BUS] = imx8m_clk_hw_composite_bus("vpu_bus", imx8mm_vpu_bus_sels, base + 0x8980);
        hws[IMX8MM_CLK_DISP_AXI] = imx8m_clk_hw_composite_bus("disp_axi", imx8mm_disp_axi_sels, base + 0x8a00);
        hws[IMX8MM_CLK_DISP_APB] = imx8m_clk_hw_composite_bus("disp_apb", imx8mm_disp_apb_sels, base + 0x8a80);
@@ -453,11 +453,11 @@ static int imx8mm_clocks_probe(struct platform_device *pdev)
        hws[IMX8MM_CLK_USB_BUS] = imx8m_clk_hw_composite_bus("usb_bus", imx8mm_usb_bus_sels, base + 0x8b80);
        hws[IMX8MM_CLK_GPU_AXI] = imx8m_clk_hw_composite_bus("gpu_axi", imx8mm_gpu_axi_sels, base + 0x8c00);
        hws[IMX8MM_CLK_GPU_AHB] = imx8m_clk_hw_composite_bus("gpu_ahb", imx8mm_gpu_ahb_sels, base + 0x8c80);
-       hws[IMX8MM_CLK_NOC] = imx8m_clk_hw_composite_critical("noc", imx8mm_noc_sels, base + 0x8d00);
-       hws[IMX8MM_CLK_NOC_APB] = imx8m_clk_hw_composite_critical("noc_apb", imx8mm_noc_apb_sels, base + 0x8d80);
+       hws[IMX8MM_CLK_NOC] = imx8m_clk_hw_composite_bus_critical("noc", imx8mm_noc_sels, base + 0x8d00);
+       hws[IMX8MM_CLK_NOC_APB] = imx8m_clk_hw_composite_bus_critical("noc_apb", imx8mm_noc_apb_sels, base + 0x8d80);
 
        /* AHB */
-       hws[IMX8MM_CLK_AHB] = imx8m_clk_hw_composite_critical("ahb", imx8mm_ahb_sels, base + 0x9000);
+       hws[IMX8MM_CLK_AHB] = imx8m_clk_hw_composite_bus_critical("ahb", imx8mm_ahb_sels, base + 0x9000);
        hws[IMX8MM_CLK_AUDIO_AHB] = imx8m_clk_hw_composite_bus("audio_ahb", imx8mm_audio_ahb_sels, base + 0x9100);
 
        /* IPG */
index e984de5..f3c5e6c 100644 (file)
@@ -431,7 +431,7 @@ static int imx8mn_clocks_probe(struct platform_device *pdev)
        hws[IMX8MN_CLK_A53_CORE] = imx_clk_hw_mux2("arm_a53_core", base + 0x9880, 24, 1, imx8mn_a53_core_sels, ARRAY_SIZE(imx8mn_a53_core_sels));
 
        /* BUS */
-       hws[IMX8MN_CLK_MAIN_AXI] = imx8m_clk_hw_composite_critical("main_axi", imx8mn_main_axi_sels, base + 0x8800);
+       hws[IMX8MN_CLK_MAIN_AXI] = imx8m_clk_hw_composite_bus_critical("main_axi", imx8mn_main_axi_sels, base + 0x8800);
        hws[IMX8MN_CLK_ENET_AXI] = imx8m_clk_hw_composite_bus("enet_axi", imx8mn_enet_axi_sels, base + 0x8880);
        hws[IMX8MN_CLK_NAND_USDHC_BUS] = imx8m_clk_hw_composite_bus("nand_usdhc_bus", imx8mn_nand_usdhc_sels, base + 0x8900);
        hws[IMX8MN_CLK_DISP_AXI] = imx8m_clk_hw_composite_bus("disp_axi", imx8mn_disp_axi_sels, base + 0x8a00);
@@ -439,9 +439,9 @@ static int imx8mn_clocks_probe(struct platform_device *pdev)
        hws[IMX8MN_CLK_USB_BUS] = imx8m_clk_hw_composite_bus("usb_bus", imx8mn_usb_bus_sels, base + 0x8b80);
        hws[IMX8MN_CLK_GPU_AXI] = imx8m_clk_hw_composite_bus("gpu_axi", imx8mn_gpu_axi_sels, base + 0x8c00);
        hws[IMX8MN_CLK_GPU_AHB] = imx8m_clk_hw_composite_bus("gpu_ahb", imx8mn_gpu_ahb_sels, base + 0x8c80);
-       hws[IMX8MN_CLK_NOC] = imx8m_clk_hw_composite_critical("noc", imx8mn_noc_sels, base + 0x8d00);
+       hws[IMX8MN_CLK_NOC] = imx8m_clk_hw_composite_bus_critical("noc", imx8mn_noc_sels, base + 0x8d00);
 
-       hws[IMX8MN_CLK_AHB] = imx8m_clk_hw_composite_critical("ahb", imx8mn_ahb_sels, base + 0x9000);
+       hws[IMX8MN_CLK_AHB] = imx8m_clk_hw_composite_bus_critical("ahb", imx8mn_ahb_sels, base + 0x9000);
        hws[IMX8MN_CLK_AUDIO_AHB] = imx8m_clk_hw_composite_bus("audio_ahb", imx8mn_audio_ahb_sels, base + 0x9100);
        hws[IMX8MN_CLK_IPG_ROOT] = imx_clk_hw_divider2("ipg_root", "ahb", base + 0x9080, 0, 1);
        hws[IMX8MN_CLK_IPG_AUDIO_ROOT] = imx_clk_hw_divider2("ipg_audio_root", "audio_ahb", base + 0x9180, 0, 1);
index 12ce477..48e2124 100644 (file)
@@ -557,9 +557,9 @@ static int imx8mp_clocks_probe(struct platform_device *pdev)
        /* CORE SEL */
        hws[IMX8MP_CLK_A53_CORE] = imx_clk_hw_mux2("arm_a53_core", ccm_base + 0x9880, 24, 1, imx8mp_a53_core_sels, ARRAY_SIZE(imx8mp_a53_core_sels));
 
-       hws[IMX8MP_CLK_MAIN_AXI] = imx8m_clk_hw_composite_critical("main_axi", imx8mp_main_axi_sels, ccm_base + 0x8800);
+       hws[IMX8MP_CLK_MAIN_AXI] = imx8m_clk_hw_composite_bus_critical("main_axi", imx8mp_main_axi_sels, ccm_base + 0x8800);
        hws[IMX8MP_CLK_ENET_AXI] = imx8m_clk_hw_composite_bus("enet_axi", imx8mp_enet_axi_sels, ccm_base + 0x8880);
-       hws[IMX8MP_CLK_NAND_USDHC_BUS] = imx8m_clk_hw_composite_critical("nand_usdhc_bus", imx8mp_nand_usdhc_sels, ccm_base + 0x8900);
+       hws[IMX8MP_CLK_NAND_USDHC_BUS] = imx8m_clk_hw_composite_bus_critical("nand_usdhc_bus", imx8mp_nand_usdhc_sels, ccm_base + 0x8900);
        hws[IMX8MP_CLK_VPU_BUS] = imx8m_clk_hw_composite_bus("vpu_bus", imx8mp_vpu_bus_sels, ccm_base + 0x8980);
        hws[IMX8MP_CLK_MEDIA_AXI] = imx8m_clk_hw_composite_bus("media_axi", imx8mp_media_axi_sels, ccm_base + 0x8a00);
        hws[IMX8MP_CLK_MEDIA_APB] = imx8m_clk_hw_composite_bus("media_apb", imx8mp_media_apb_sels, ccm_base + 0x8a80);
@@ -567,12 +567,12 @@ static int imx8mp_clocks_probe(struct platform_device *pdev)
        hws[IMX8MP_CLK_HDMI_AXI] = imx8m_clk_hw_composite_bus("hdmi_axi", imx8mp_media_axi_sels, ccm_base + 0x8b80);
        hws[IMX8MP_CLK_GPU_AXI] = imx8m_clk_hw_composite_bus("gpu_axi", imx8mp_gpu_axi_sels, ccm_base + 0x8c00);
        hws[IMX8MP_CLK_GPU_AHB] = imx8m_clk_hw_composite_bus("gpu_ahb", imx8mp_gpu_ahb_sels, ccm_base + 0x8c80);
-       hws[IMX8MP_CLK_NOC] = imx8m_clk_hw_composite_critical("noc", imx8mp_noc_sels, ccm_base + 0x8d00);
-       hws[IMX8MP_CLK_NOC_IO] = imx8m_clk_hw_composite_critical("noc_io", imx8mp_noc_io_sels, ccm_base + 0x8d80);
+       hws[IMX8MP_CLK_NOC] = imx8m_clk_hw_composite_bus_critical("noc", imx8mp_noc_sels, ccm_base + 0x8d00);
+       hws[IMX8MP_CLK_NOC_IO] = imx8m_clk_hw_composite_bus_critical("noc_io", imx8mp_noc_io_sels, ccm_base + 0x8d80);
        hws[IMX8MP_CLK_ML_AXI] = imx8m_clk_hw_composite_bus("ml_axi", imx8mp_ml_axi_sels, ccm_base + 0x8e00);
        hws[IMX8MP_CLK_ML_AHB] = imx8m_clk_hw_composite_bus("ml_ahb", imx8mp_ml_ahb_sels, ccm_base + 0x8e80);
 
-       hws[IMX8MP_CLK_AHB] = imx8m_clk_hw_composite_critical("ahb_root", imx8mp_ahb_sels, ccm_base + 0x9000);
+       hws[IMX8MP_CLK_AHB] = imx8m_clk_hw_composite_bus_critical("ahb_root", imx8mp_ahb_sels, ccm_base + 0x9000);
        hws[IMX8MP_CLK_AUDIO_AHB] = imx8m_clk_hw_composite_bus("audio_ahb", imx8mp_audio_ahb_sels, ccm_base + 0x9100);
        hws[IMX8MP_CLK_MIPI_DSI_ESC_RX] = imx8m_clk_hw_composite_bus("mipi_dsi_esc_rx", imx8mp_mipi_dsi_esc_rx_sels, ccm_base + 0x9200);
 
index 8265d1d..06292d4 100644 (file)
@@ -431,7 +431,7 @@ static int imx8mq_clocks_probe(struct platform_device *pdev)
        hws[IMX8MQ_CLK_A53_CORE] = imx_clk_hw_mux2("arm_a53_core", base + 0x9880, 24, 1, imx8mq_a53_core_sels, ARRAY_SIZE(imx8mq_a53_core_sels));
 
        /* BUS */
-       hws[IMX8MQ_CLK_MAIN_AXI] = imx8m_clk_hw_composite_critical("main_axi", imx8mq_main_axi_sels, base + 0x8800);
+       hws[IMX8MQ_CLK_MAIN_AXI] = imx8m_clk_hw_composite_bus_critical("main_axi", imx8mq_main_axi_sels, base + 0x8800);
        hws[IMX8MQ_CLK_ENET_AXI] = imx8m_clk_hw_composite_bus("enet_axi", imx8mq_enet_axi_sels, base + 0x8880);
        hws[IMX8MQ_CLK_NAND_USDHC_BUS] = imx8m_clk_hw_composite_bus("nand_usdhc_bus", imx8mq_nand_usdhc_sels, base + 0x8900);
        hws[IMX8MQ_CLK_VPU_BUS] = imx8m_clk_hw_composite_bus("vpu_bus", imx8mq_vpu_bus_sels, base + 0x8980);
@@ -441,12 +441,12 @@ static int imx8mq_clocks_probe(struct platform_device *pdev)
        hws[IMX8MQ_CLK_USB_BUS] = imx8m_clk_hw_composite_bus("usb_bus", imx8mq_usb_bus_sels, base + 0x8b80);
        hws[IMX8MQ_CLK_GPU_AXI] = imx8m_clk_hw_composite_bus("gpu_axi", imx8mq_gpu_axi_sels, base + 0x8c00);
        hws[IMX8MQ_CLK_GPU_AHB] = imx8m_clk_hw_composite_bus("gpu_ahb", imx8mq_gpu_ahb_sels, base + 0x8c80);
-       hws[IMX8MQ_CLK_NOC] = imx8m_clk_hw_composite_critical("noc", imx8mq_noc_sels, base + 0x8d00);
-       hws[IMX8MQ_CLK_NOC_APB] = imx8m_clk_hw_composite_critical("noc_apb", imx8mq_noc_apb_sels, base + 0x8d80);
+       hws[IMX8MQ_CLK_NOC] = imx8m_clk_hw_composite_bus_critical("noc", imx8mq_noc_sels, base + 0x8d00);
+       hws[IMX8MQ_CLK_NOC_APB] = imx8m_clk_hw_composite_bus_critical("noc_apb", imx8mq_noc_apb_sels, base + 0x8d80);
 
        /* AHB */
        /* AHB clock is used by the AHB bus therefore marked as critical */
-       hws[IMX8MQ_CLK_AHB] = imx8m_clk_hw_composite_critical("ahb", imx8mq_ahb_sels, base + 0x9000);
+       hws[IMX8MQ_CLK_AHB] = imx8m_clk_hw_composite_bus_critical("ahb", imx8mq_ahb_sels, base + 0x9000);
        hws[IMX8MQ_CLK_AUDIO_AHB] = imx8m_clk_hw_composite_bus("audio_ahb", imx8mq_audio_ahb_sels, base + 0x9100);
 
        /* IPG */
index 3b796b3..1d7be0c 100644 (file)
@@ -549,6 +549,11 @@ struct clk_hw *imx8m_clk_hw_composite_flags(const char *name,
                        IMX_COMPOSITE_BUS, \
                        CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE)
 
+#define imx8m_clk_hw_composite_bus_critical(name, parent_names, reg)   \
+       imx8m_clk_hw_composite_flags(name, parent_names, ARRAY_SIZE(parent_names), reg, \
+                       IMX_COMPOSITE_BUS, \
+                       CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE | CLK_IS_CRITICAL)
+
 #define imx8m_clk_hw_composite_core(name, parent_names, reg)   \
        imx8m_clk_hw_composite_flags(name, parent_names, \
                        ARRAY_SIZE(parent_names), reg, \
index c4a3960..e365312 100644 (file)
@@ -26,7 +26,10 @@ struct clk_regmap {
        void            *data;
 };
 
-#define to_clk_regmap(_hw) container_of(_hw, struct clk_regmap, hw)
+static inline struct clk_regmap *to_clk_regmap(struct clk_hw *hw)
+{
+       return container_of(hw, struct clk_regmap, hw);
+}
 
 /**
  * struct clk_regmap_gate_data - regmap backed gate specific data
index 6cfc1bc..14ec659 100644 (file)
@@ -24,7 +24,11 @@ struct clk_regmap {
        unsigned int enable_mask;
        bool enable_is_inverted;
 };
-#define to_clk_regmap(_hw) container_of(_hw, struct clk_regmap, hw)
+
+static inline struct clk_regmap *to_clk_regmap(struct clk_hw *hw)
+{
+       return container_of(hw, struct clk_regmap, hw);
+}
 
 int clk_is_enabled_regmap(struct clk_hw *hw);
 int clk_enable_regmap(struct clk_hw *hw);
index e27771d..a60aee1 100644 (file)
@@ -368,7 +368,7 @@ static const struct regmap_config ti_eqep_regmap32_config = {
        .reg_bits = 32,
        .val_bits = 32,
        .reg_stride = 4,
-       .max_register = 0x24,
+       .max_register = QUPRD,
 };
 
 static const struct regmap_config ti_eqep_regmap16_config = {
@@ -376,7 +376,7 @@ static const struct regmap_config ti_eqep_regmap16_config = {
        .reg_bits = 16,
        .val_bits = 16,
        .reg_stride = 2,
-       .max_register = 0x1e,
+       .max_register = QCPRDLAT,
 };
 
 static int ti_eqep_probe(struct platform_device *pdev)
index 336b5e9..1e7e3f2 100644 (file)
@@ -2254,7 +2254,7 @@ static int cpufreq_init_governor(struct cpufreq_policy *policy)
                return -EINVAL;
 
        /* Platform doesn't want dynamic frequency switching ? */
-       if (policy->governor->dynamic_switching &&
+       if (policy->governor->flags & CPUFREQ_GOV_DYNAMIC_SWITCHING &&
            cpufreq_driver->flags & CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING) {
                struct cpufreq_governor *gov = cpufreq_fallback_governor();
 
@@ -2280,6 +2280,8 @@ static int cpufreq_init_governor(struct cpufreq_policy *policy)
                }
        }
 
+       policy->strict_target = !!(policy->governor->flags & CPUFREQ_GOV_STRICT_TARGET);
+
        return 0;
 }
 
index c56773c..bab8e61 100644 (file)
@@ -156,7 +156,7 @@ void cpufreq_dbs_governor_limits(struct cpufreq_policy *policy);
 #define CPUFREQ_DBS_GOVERNOR_INITIALIZER(_name_)                       \
        {                                                               \
                .name = _name_,                                         \
-               .dynamic_switching = true,                              \
+               .flags = CPUFREQ_GOV_DYNAMIC_SWITCHING,                 \
                .owner = THIS_MODULE,                                   \
                .init = cpufreq_dbs_governor_init,                      \
                .exit = cpufreq_dbs_governor_exit,                      \
index 71c1d9a..addd93f 100644 (file)
@@ -20,6 +20,7 @@ static void cpufreq_gov_performance_limits(struct cpufreq_policy *policy)
 static struct cpufreq_governor cpufreq_gov_performance = {
        .name           = "performance",
        .owner          = THIS_MODULE,
+       .flags          = CPUFREQ_GOV_STRICT_TARGET,
        .limits         = cpufreq_gov_performance_limits,
 };
 
index 7749522..8d830d8 100644 (file)
@@ -21,6 +21,7 @@ static struct cpufreq_governor cpufreq_gov_powersave = {
        .name           = "powersave",
        .limits         = cpufreq_gov_powersave_limits,
        .owner          = THIS_MODULE,
+       .flags          = CPUFREQ_GOV_STRICT_TARGET,
 };
 
 MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>");
index b7a9779..36a3ccf 100644 (file)
@@ -2527,7 +2527,7 @@ static void intel_cpufreq_trace(struct cpudata *cpu, unsigned int trace_type, in
 }
 
 static void intel_cpufreq_adjust_hwp(struct cpudata *cpu, u32 target_pstate,
-                                    bool fast_switch)
+                                    bool strict, bool fast_switch)
 {
        u64 prev = READ_ONCE(cpu->hwp_req_cached), value = prev;
 
@@ -2539,7 +2539,7 @@ static void intel_cpufreq_adjust_hwp(struct cpudata *cpu, u32 target_pstate,
         * field in it, so opportunistically update the max too if needed.
         */
        value &= ~HWP_MAX_PERF(~0L);
-       value |= HWP_MAX_PERF(cpu->max_perf_ratio);
+       value |= HWP_MAX_PERF(strict ? target_pstate : cpu->max_perf_ratio);
 
        if (value == prev)
                return;
@@ -2562,14 +2562,16 @@ static void intel_cpufreq_adjust_perf_ctl(struct cpudata *cpu,
                              pstate_funcs.get_val(cpu, target_pstate));
 }
 
-static int intel_cpufreq_update_pstate(struct cpudata *cpu, int target_pstate,
-                                      bool fast_switch)
+static int intel_cpufreq_update_pstate(struct cpufreq_policy *policy,
+                                      int target_pstate, bool fast_switch)
 {
+       struct cpudata *cpu = all_cpu_data[policy->cpu];
        int old_pstate = cpu->pstate.current_pstate;
 
        target_pstate = intel_pstate_prepare_request(cpu, target_pstate);
        if (hwp_active) {
-               intel_cpufreq_adjust_hwp(cpu, target_pstate, fast_switch);
+               intel_cpufreq_adjust_hwp(cpu, target_pstate,
+                                        policy->strict_target, fast_switch);
                cpu->pstate.current_pstate = target_pstate;
        } else if (target_pstate != old_pstate) {
                intel_cpufreq_adjust_perf_ctl(cpu, target_pstate, fast_switch);
@@ -2609,7 +2611,7 @@ static int intel_cpufreq_target(struct cpufreq_policy *policy,
                break;
        }
 
-       target_pstate = intel_cpufreq_update_pstate(cpu, target_pstate, false);
+       target_pstate = intel_cpufreq_update_pstate(policy, target_pstate, false);
 
        freqs.new = target_pstate * cpu->pstate.scaling;
 
@@ -2628,7 +2630,7 @@ static unsigned int intel_cpufreq_fast_switch(struct cpufreq_policy *policy,
 
        target_pstate = DIV_ROUND_UP(target_freq, cpu->pstate.scaling);
 
-       target_pstate = intel_cpufreq_update_pstate(cpu, target_pstate, true);
+       target_pstate = intel_cpufreq_update_pstate(policy, target_pstate, true);
 
        return target_pstate * cpu->pstate.scaling;
 }
index e855e86..7831850 100644 (file)
@@ -8,6 +8,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/clk-provider.h>
 #include <linux/cpu.h>
 #include <linux/cpufreq.h>
 #include <linux/cpumask.h>
@@ -228,12 +229,17 @@ static struct cpufreq_driver scmi_cpufreq_driver = {
 static int scmi_cpufreq_probe(struct scmi_device *sdev)
 {
        int ret;
+       struct device *dev = &sdev->dev;
 
        handle = sdev->handle;
 
        if (!handle || !handle->perf_ops)
                return -ENODEV;
 
+       /* dummy clock provider as needed by OPP if clocks property is used */
+       if (of_find_property(dev->of_node, "#clock-cells", NULL))
+               devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, NULL);
+
        ret = cpufreq_register_driver(&scmi_cpufreq_driver);
        if (ret) {
                dev_err(&sdev->dev, "%s: registering cpufreq failed, err: %d\n",
index 4b4079f..7eb2c56 100644 (file)
@@ -42,6 +42,8 @@ static const struct tegra186_cpufreq_cluster_info tegra186_clusters[] = {
 struct tegra186_cpufreq_cluster {
        const struct tegra186_cpufreq_cluster_info *info;
        struct cpufreq_frequency_table *table;
+       u32 ref_clk_khz;
+       u32 div;
 };
 
 struct tegra186_cpufreq_data {
@@ -94,7 +96,7 @@ static int tegra186_cpufreq_set_target(struct cpufreq_policy *policy,
 
 static unsigned int tegra186_cpufreq_get(unsigned int cpu)
 {
-       struct cpufreq_frequency_table *tbl;
+       struct tegra186_cpufreq_data *data = cpufreq_get_driver_data();
        struct cpufreq_policy *policy;
        void __iomem *edvd_reg;
        unsigned int i, freq = 0;
@@ -104,17 +106,23 @@ static unsigned int tegra186_cpufreq_get(unsigned int cpu)
        if (!policy)
                return 0;
 
-       tbl = policy->freq_table;
        edvd_reg = policy->driver_data;
        ndiv = readl(edvd_reg) & EDVD_CORE_VOLT_FREQ_F_MASK;
 
-       for (i = 0; tbl[i].frequency != CPUFREQ_TABLE_END; i++) {
-               if ((tbl[i].driver_data & EDVD_CORE_VOLT_FREQ_F_MASK) == ndiv) {
-                       freq = tbl[i].frequency;
-                       break;
+       for (i = 0; i < data->num_clusters; i++) {
+               struct tegra186_cpufreq_cluster *cluster = &data->clusters[i];
+               int core;
+
+               for (core = 0; core < ARRAY_SIZE(cluster->info->cpus); core++) {
+                       if (cluster->info->cpus[core] != policy->cpu)
+                               continue;
+
+                       freq = (cluster->ref_clk_khz * ndiv) / cluster->div;
+                       goto out;
                }
        }
 
+out:
        cpufreq_cpu_put(policy);
 
        return freq;
@@ -133,7 +141,7 @@ static struct cpufreq_driver tegra186_cpufreq_driver = {
 
 static struct cpufreq_frequency_table *init_vhint_table(
        struct platform_device *pdev, struct tegra_bpmp *bpmp,
-       unsigned int cluster_id)
+       struct tegra186_cpufreq_cluster *cluster)
 {
        struct cpufreq_frequency_table *table;
        struct mrq_cpu_vhint_request req;
@@ -152,7 +160,7 @@ static struct cpufreq_frequency_table *init_vhint_table(
 
        memset(&req, 0, sizeof(req));
        req.addr = phys;
-       req.cluster_id = cluster_id;
+       req.cluster_id = cluster->info->bpmp_cluster_id;
 
        memset(&msg, 0, sizeof(msg));
        msg.mrq = MRQ_CPU_VHINT;
@@ -185,6 +193,9 @@ static struct cpufreq_frequency_table *init_vhint_table(
                goto free;
        }
 
+       cluster->ref_clk_khz = data->ref_clk_hz / 1000;
+       cluster->div = data->pdiv * data->mdiv;
+
        for (i = data->vfloor, j = 0; i <= data->vceil; i++) {
                struct cpufreq_frequency_table *point;
                u16 ndiv = data->ndiv[i];
@@ -202,8 +213,7 @@ static struct cpufreq_frequency_table *init_vhint_table(
 
                point = &table[j++];
                point->driver_data = edvd_val;
-               point->frequency = data->ref_clk_hz * ndiv / data->pdiv /
-                       data->mdiv / 1000;
+               point->frequency = (cluster->ref_clk_khz * ndiv) / cluster->div;
        }
 
        table[j].frequency = CPUFREQ_TABLE_END;
@@ -245,8 +255,7 @@ static int tegra186_cpufreq_probe(struct platform_device *pdev)
                struct tegra186_cpufreq_cluster *cluster = &data->clusters[i];
 
                cluster->info = &tegra186_clusters[i];
-               cluster->table = init_vhint_table(
-                       pdev, bpmp, cluster->info->bpmp_cluster_id);
+               cluster->table = init_vhint_table(pdev, bpmp, cluster);
                if (IS_ERR(cluster->table)) {
                        err = PTR_ERR(cluster->table);
                        goto put_bpmp;
index e895670..191966d 100644 (file)
@@ -189,7 +189,7 @@ static int tegra_cpuidle_state_enter(struct cpuidle_device *dev,
        }
 
        local_fiq_disable();
-       tegra_pm_set_cpu_in_lp2();
+       RCU_NONIDLE(tegra_pm_set_cpu_in_lp2());
        cpu_pm_enter();
 
        switch (index) {
@@ -207,7 +207,7 @@ static int tegra_cpuidle_state_enter(struct cpuidle_device *dev,
        }
 
        cpu_pm_exit();
-       tegra_pm_clear_cpu_in_lp2();
+       RCU_NONIDLE(tegra_pm_clear_cpu_in_lp2());
        local_fiq_enable();
 
        return err ?: index;
index fa2f1b4..a94bf28 100644 (file)
@@ -7,7 +7,7 @@
  *
  * This file add support for MD5 and SHA1/SHA224/SHA256/SHA384/SHA512.
  *
- * You could find the datasheet in Documentation/arm/sunxi/README
+ * You could find the datasheet in Documentation/arm/sunxi.rst
  */
 #include <linux/dma-mapping.h>
 #include <linux/pm_runtime.h>
index 7850300..cfde9ee 100644 (file)
@@ -7,7 +7,7 @@
  *
  * This file handle the PRNG
  *
- * You could find a link for the datasheet in Documentation/arm/sunxi/README
+ * You could find a link for the datasheet in Documentation/arm/sunxi.rst
  */
 #include "sun8i-ce.h"
 #include <linux/dma-mapping.h>
index 6543281..5b7af44 100644 (file)
@@ -7,7 +7,7 @@
  *
  * This file handle the TRNG
  *
- * You could find a link for the datasheet in Documentation/arm/sunxi/README
+ * You could find a link for the datasheet in Documentation/arm/sunxi.rst
  */
 #include "sun8i-ce.h"
 #include <linux/dma-mapping.h>
index 567428e..d2834c2 100644 (file)
@@ -50,7 +50,6 @@ config DEV_DAX_HMEM
          Say M if unsure.
 
 config DEV_DAX_HMEM_DEVICES
-       depends on NUMA_KEEP_MEMINFO # for phys_to_target_node()
        depends on DEV_DAX_HMEM && DAX=y
        def_bool y
 
index 7974fa0..962cbb5 100644 (file)
@@ -1039,16 +1039,15 @@ static int get_dma_id(struct dma_device *device)
 static int __dma_async_device_channel_register(struct dma_device *device,
                                               struct dma_chan *chan)
 {
-       int rc = 0;
+       int rc;
 
        chan->local = alloc_percpu(typeof(*chan->local));
        if (!chan->local)
-               goto err_out;
+               return -ENOMEM;
        chan->dev = kzalloc(sizeof(*chan->dev), GFP_KERNEL);
        if (!chan->dev) {
-               free_percpu(chan->local);
-               chan->local = NULL;
-               goto err_out;
+               rc = -ENOMEM;
+               goto err_free_local;
        }
 
        /*
@@ -1061,7 +1060,8 @@ static int __dma_async_device_channel_register(struct dma_device *device,
        if (chan->chan_id < 0) {
                pr_err("%s: unable to alloc ida for chan: %d\n",
                       __func__, chan->chan_id);
-               goto err_out;
+               rc = chan->chan_id;
+               goto err_free_dev;
        }
 
        chan->dev->device.class = &dma_devclass;
@@ -1082,9 +1082,10 @@ static int __dma_async_device_channel_register(struct dma_device *device,
        mutex_lock(&device->chan_mutex);
        ida_free(&device->chan_ida, chan->chan_id);
        mutex_unlock(&device->chan_mutex);
- err_out:
-       free_percpu(chan->local);
+ err_free_dev:
        kfree(chan->dev);
+ err_free_local:
+       free_percpu(chan->local);
        return rc;
 }
 
index 200b910..6633449 100644 (file)
@@ -271,7 +271,7 @@ int idxd_wq_map_portal(struct idxd_wq *wq)
        resource_size_t start;
 
        start = pci_resource_start(pdev, IDXD_WQ_BAR);
-       start = start + wq->id * IDXD_PORTAL_SIZE;
+       start += idxd_get_wq_portal_full_offset(wq->id, IDXD_PORTAL_LIMITED);
 
        wq->dportal = devm_ioremap(dev, start, IDXD_PORTAL_SIZE);
        if (!wq->dportal)
@@ -295,7 +295,7 @@ void idxd_wq_disable_cleanup(struct idxd_wq *wq)
        int i, wq_offset;
 
        lockdep_assert_held(&idxd->dev_lock);
-       memset(&wq->wqcfg, 0, sizeof(wq->wqcfg));
+       memset(wq->wqcfg, 0, idxd->wqcfg_size);
        wq->type = IDXD_WQT_NONE;
        wq->size = 0;
        wq->group = NULL;
@@ -304,8 +304,8 @@ void idxd_wq_disable_cleanup(struct idxd_wq *wq)
        clear_bit(WQ_FLAG_DEDICATED, &wq->flags);
        memset(wq->name, 0, WQ_NAME_SIZE);
 
-       for (i = 0; i < 8; i++) {
-               wq_offset = idxd->wqcfg_offset + wq->id * 32 + i * sizeof(u32);
+       for (i = 0; i < WQCFG_STRIDES(idxd); i++) {
+               wq_offset = WQCFG_OFFSET(idxd, wq->id, i);
                iowrite32(0, idxd->reg_base + wq_offset);
                dev_dbg(dev, "WQ[%d][%d][%#x]: %#x\n",
                        wq->id, i, wq_offset,
@@ -539,10 +539,10 @@ static int idxd_wq_config_write(struct idxd_wq *wq)
        if (!wq->group)
                return 0;
 
-       memset(&wq->wqcfg, 0, sizeof(union wqcfg));
+       memset(wq->wqcfg, 0, idxd->wqcfg_size);
 
        /* byte 0-3 */
-       wq->wqcfg.wq_size = wq->size;
+       wq->wqcfg->wq_size = wq->size;
 
        if (wq->size == 0) {
                dev_warn(dev, "Incorrect work queue size: 0\n");
@@ -550,22 +550,21 @@ static int idxd_wq_config_write(struct idxd_wq *wq)
        }
 
        /* bytes 4-7 */
-       wq->wqcfg.wq_thresh = wq->threshold;
+       wq->wqcfg->wq_thresh = wq->threshold;
 
        /* byte 8-11 */
-       wq->wqcfg.priv = !!(wq->type == IDXD_WQT_KERNEL);
-       wq->wqcfg.mode = 1;
-
-       wq->wqcfg.priority = wq->priority;
+       wq->wqcfg->priv = !!(wq->type == IDXD_WQT_KERNEL);
+       wq->wqcfg->mode = 1;
+       wq->wqcfg->priority = wq->priority;
 
        /* bytes 12-15 */
-       wq->wqcfg.max_xfer_shift = ilog2(wq->max_xfer_bytes);
-       wq->wqcfg.max_batch_shift = ilog2(wq->max_batch_size);
+       wq->wqcfg->max_xfer_shift = ilog2(wq->max_xfer_bytes);
+       wq->wqcfg->max_batch_shift = ilog2(wq->max_batch_size);
 
        dev_dbg(dev, "WQ %d CFGs\n", wq->id);
-       for (i = 0; i < 8; i++) {
-               wq_offset = idxd->wqcfg_offset + wq->id * 32 + i * sizeof(u32);
-               iowrite32(wq->wqcfg.bits[i], idxd->reg_base + wq_offset);
+       for (i = 0; i < WQCFG_STRIDES(idxd); i++) {
+               wq_offset = WQCFG_OFFSET(idxd, wq->id, i);
+               iowrite32(wq->wqcfg->bits[i], idxd->reg_base + wq_offset);
                dev_dbg(dev, "WQ[%d][%d][%#x]: %#x\n",
                        wq->id, i, wq_offset,
                        ioread32(idxd->reg_base + wq_offset));
index c64df19..d48f193 100644 (file)
@@ -103,7 +103,7 @@ struct idxd_wq {
        u32 priority;
        enum idxd_wq_state state;
        unsigned long flags;
-       union wqcfg wqcfg;
+       union wqcfg *wqcfg;
        u32 vec_ptr;            /* interrupt steering */
        struct dsa_hw_desc **hw_descs;
        int num_descs;
@@ -183,6 +183,7 @@ struct idxd_device {
        int max_wq_size;
        int token_limit;
        int nr_tokens;          /* non-reserved tokens */
+       unsigned int wqcfg_size;
 
        union sw_err_reg sw_err;
        wait_queue_head_t cmd_waitq;
index 11e5ce1..0a4432b 100644 (file)
@@ -178,6 +178,9 @@ static int idxd_setup_internals(struct idxd_device *idxd)
                wq->idxd_cdev.minor = -1;
                wq->max_xfer_bytes = idxd->max_xfer_bytes;
                wq->max_batch_size = idxd->max_batch_size;
+               wq->wqcfg = devm_kzalloc(dev, idxd->wqcfg_size, GFP_KERNEL);
+               if (!wq->wqcfg)
+                       return -ENOMEM;
        }
 
        for (i = 0; i < idxd->max_engines; i++) {
@@ -251,6 +254,8 @@ static void idxd_read_caps(struct idxd_device *idxd)
        dev_dbg(dev, "total workqueue size: %u\n", idxd->max_wq_size);
        idxd->max_wqs = idxd->hw.wq_cap.num_wqs;
        dev_dbg(dev, "max workqueues: %u\n", idxd->max_wqs);
+       idxd->wqcfg_size = 1 << (idxd->hw.wq_cap.wqcfg_size + IDXD_WQCFG_MIN);
+       dev_dbg(dev, "wqcfg size: %u\n", idxd->wqcfg_size);
 
        /* reading operation capabilities */
        for (i = 0; i < 4; i++) {
index a39e7ae..5439033 100644 (file)
@@ -8,7 +8,7 @@
 
 #define IDXD_MMIO_BAR          0
 #define IDXD_WQ_BAR            2
-#define IDXD_PORTAL_SIZE       0x4000
+#define IDXD_PORTAL_SIZE       PAGE_SIZE
 
 /* MMIO Device BAR0 Registers */
 #define IDXD_VER_OFFSET                        0x00
@@ -43,7 +43,8 @@ union wq_cap_reg {
        struct {
                u64 total_wq_size:16;
                u64 num_wqs:8;
-               u64 rsvd:24;
+               u64 wqcfg_size:4;
+               u64 rsvd:20;
                u64 shared_mode:1;
                u64 dedicated_mode:1;
                u64 rsvd2:1;
@@ -55,6 +56,7 @@ union wq_cap_reg {
        u64 bits;
 } __packed;
 #define IDXD_WQCAP_OFFSET              0x20
+#define IDXD_WQCFG_MIN                 5
 
 union group_cap_reg {
        struct {
@@ -333,4 +335,23 @@ union wqcfg {
        };
        u32 bits[8];
 } __packed;
+
+/*
+ * This macro calculates the offset into the WQCFG register
+ * idxd - struct idxd *
+ * n - wq id
+ * ofs - the index of the 32b dword for the config register
+ *
+ * The WQCFG register block is divided into groups per each wq. The n index
+ * allows us to move to the register group that's for that particular wq.
+ * Each register is 32bits. The ofs gives us the number of register to access.
+ */
+#define WQCFG_OFFSET(_idxd_dev, n, ofs) \
+({\
+       typeof(_idxd_dev) __idxd_dev = (_idxd_dev);     \
+       (__idxd_dev)->wqcfg_offset + (n) * (__idxd_dev)->wqcfg_size + sizeof(u32) * (ofs);      \
+})
+
+#define WQCFG_STRIDES(_idxd_dev) ((_idxd_dev)->wqcfg_size / sizeof(u32))
+
 #endif
index 156a1ee..417048e 100644 (file)
@@ -74,7 +74,7 @@ int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)
        if (idxd->state != IDXD_DEV_ENABLED)
                return -EIO;
 
-       portal = wq->dportal + idxd_get_wq_portal_offset(IDXD_PORTAL_UNLIMITED);
+       portal = wq->dportal;
        /*
         * The wmb() flushes writes to coherent DMA data before possibly
         * triggering a DMA read. The wmb() is necessary even on UP because
index 0be3855..289c59e 100644 (file)
 #define DCA2_TAG_MAP_BYTE3 0x82
 #define DCA2_TAG_MAP_BYTE4 0x82
 
-/* verify if tag map matches expected values */
-static inline int dca2_tag_map_valid(u8 *tag_map)
-{
-       return ((tag_map[0] == DCA2_TAG_MAP_BYTE0) &&
-               (tag_map[1] == DCA2_TAG_MAP_BYTE1) &&
-               (tag_map[2] == DCA2_TAG_MAP_BYTE2) &&
-               (tag_map[3] == DCA2_TAG_MAP_BYTE3) &&
-               (tag_map[4] == DCA2_TAG_MAP_BYTE4));
-}
-
 /*
  * "Legacy" DCA systems do not implement the DCA register set in the
  * I/OAT device.  Software needs direct support for their tag mappings.
index e9f0101..0f5c193 100644 (file)
@@ -2799,7 +2799,7 @@ pl330_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dst,
         * If burst size is smaller than bus width then make sure we only
         * transfer one at a time to avoid a burst stradling an MFIFO entry.
         */
-       if (desc->rqcfg.brst_size * 8 < pl330->pcfg.data_bus_width)
+       if (burst * 8 < pl330->pcfg.data_bus_width)
                desc->rqcfg.brst_len = 1;
 
        desc->bytes_requested = len;
index aa24e55..8563a39 100644 (file)
@@ -83,7 +83,7 @@ EXPORT_SYMBOL(xudma_rflow_is_gp);
 #define XUDMA_GET_PUT_RESOURCE(res)                                    \
 struct udma_##res *xudma_##res##_get(struct udma_dev *ud, int id)      \
 {                                                                      \
-       return __udma_reserve_##res(ud, false, id);                     \
+       return __udma_reserve_##res(ud, UDMA_TP_NORMAL, id);            \
 }                                                                      \
 EXPORT_SYMBOL(xudma_##res##_get);                                      \
                                                                        \
index c9fe5e3..268a080 100644 (file)
@@ -1522,29 +1522,38 @@ static void omap_dma_free(struct omap_dmadev *od)
        }
 }
 
+/* Currently used by omap2 & 3 to block deeper SoC idle states */
+static bool omap_dma_busy(struct omap_dmadev *od)
+{
+       struct omap_chan *c;
+       int lch = -1;
+
+       while (1) {
+               lch = find_next_bit(od->lch_bitmap, od->lch_count, lch + 1);
+               if (lch >= od->lch_count)
+                       break;
+               c = od->lch_map[lch];
+               if (!c)
+                       continue;
+               if (omap_dma_chan_read(c, CCR) & CCR_ENABLE)
+                       return true;
+       }
+
+       return false;
+}
+
 /* Currently only used for omap2. For omap1, also a check for lcd_dma is needed */
 static int omap_dma_busy_notifier(struct notifier_block *nb,
                                  unsigned long cmd, void *v)
 {
        struct omap_dmadev *od;
-       struct omap_chan *c;
-       int lch = -1;
 
        od = container_of(nb, struct omap_dmadev, nb);
 
        switch (cmd) {
        case CPU_CLUSTER_PM_ENTER:
-               while (1) {
-                       lch = find_next_bit(od->lch_bitmap, od->lch_count,
-                                           lch + 1);
-                       if (lch >= od->lch_count)
-                               break;
-                       c = od->lch_map[lch];
-                       if (!c)
-                               continue;
-                       if (omap_dma_chan_read(c, CCR) & CCR_ENABLE)
-                               return NOTIFY_BAD;
-               }
+               if (omap_dma_busy(od))
+                       return NOTIFY_BAD;
                break;
        case CPU_CLUSTER_PM_ENTER_FAILED:
        case CPU_CLUSTER_PM_EXIT:
@@ -1595,6 +1604,8 @@ static int omap_dma_context_notifier(struct notifier_block *nb,
 
        switch (cmd) {
        case CPU_CLUSTER_PM_ENTER:
+               if (omap_dma_busy(od))
+                       return NOTIFY_BAD;
                omap_dma_context_save(od);
                break;
        case CPU_CLUSTER_PM_ENTER_FAILED:
index ecff354..22faea6 100644 (file)
@@ -517,8 +517,8 @@ struct xilinx_dma_device {
 #define to_dma_tx_descriptor(tx) \
        container_of(tx, struct xilinx_dma_tx_descriptor, async_tx)
 #define xilinx_dma_poll_timeout(chan, reg, val, cond, delay_us, timeout_us) \
-       readl_poll_timeout(chan->xdev->regs + chan->ctrl_offset + reg, val, \
-                          cond, delay_us, timeout_us)
+       readl_poll_timeout_atomic(chan->xdev->regs + chan->ctrl_offset + reg, \
+                                 val, cond, delay_us, timeout_us)
 
 /* IO accessors */
 static inline u32 dma_read(struct xilinx_dma_chan *chan, u32 reg)
@@ -948,8 +948,10 @@ static u32 xilinx_dma_get_residue(struct xilinx_dma_chan *chan,
 {
        struct xilinx_cdma_tx_segment *cdma_seg;
        struct xilinx_axidma_tx_segment *axidma_seg;
+       struct xilinx_aximcdma_tx_segment *aximcdma_seg;
        struct xilinx_cdma_desc_hw *cdma_hw;
        struct xilinx_axidma_desc_hw *axidma_hw;
+       struct xilinx_aximcdma_desc_hw *aximcdma_hw;
        struct list_head *entry;
        u32 residue = 0;
 
@@ -961,13 +963,23 @@ static u32 xilinx_dma_get_residue(struct xilinx_dma_chan *chan,
                        cdma_hw = &cdma_seg->hw;
                        residue += (cdma_hw->control - cdma_hw->status) &
                                   chan->xdev->max_buffer_len;
-               } else {
+               } else if (chan->xdev->dma_config->dmatype ==
+                          XDMA_TYPE_AXIDMA) {
                        axidma_seg = list_entry(entry,
                                                struct xilinx_axidma_tx_segment,
                                                node);
                        axidma_hw = &axidma_seg->hw;
                        residue += (axidma_hw->control - axidma_hw->status) &
                                   chan->xdev->max_buffer_len;
+               } else {
+                       aximcdma_seg =
+                               list_entry(entry,
+                                          struct xilinx_aximcdma_tx_segment,
+                                          node);
+                       aximcdma_hw = &aximcdma_seg->hw;
+                       residue +=
+                               (aximcdma_hw->control - aximcdma_hw->status) &
+                               chan->xdev->max_buffer_len;
                }
        }
 
@@ -1135,7 +1147,7 @@ static int xilinx_dma_alloc_chan_resources(struct dma_chan *dchan)
                        upper_32_bits(chan->seg_p + sizeof(*chan->seg_mv) *
                                ((i + 1) % XILINX_DMA_NUM_DESCS));
                        chan->seg_mv[i].phys = chan->seg_p +
-                               sizeof(*chan->seg_v) * i;
+                               sizeof(*chan->seg_mv) * i;
                        list_add_tail(&chan->seg_mv[i].node,
                                      &chan->free_seg_list);
                }
@@ -1560,7 +1572,7 @@ static void xilinx_dma_start_transfer(struct xilinx_dma_chan *chan)
 static void xilinx_mcdma_start_transfer(struct xilinx_dma_chan *chan)
 {
        struct xilinx_dma_tx_descriptor *head_desc, *tail_desc;
-       struct xilinx_axidma_tx_segment *tail_segment;
+       struct xilinx_aximcdma_tx_segment *tail_segment;
        u32 reg;
 
        /*
@@ -1582,7 +1594,7 @@ static void xilinx_mcdma_start_transfer(struct xilinx_dma_chan *chan)
        tail_desc = list_last_entry(&chan->pending_list,
                                    struct xilinx_dma_tx_descriptor, node);
        tail_segment = list_last_entry(&tail_desc->segments,
-                                      struct xilinx_axidma_tx_segment, node);
+                                      struct xilinx_aximcdma_tx_segment, node);
 
        reg = dma_ctrl_read(chan, XILINX_MCDMA_CHAN_CR_OFFSET(chan->tdest));
 
@@ -1864,6 +1876,7 @@ static void append_desc_queue(struct xilinx_dma_chan *chan,
        struct xilinx_vdma_tx_segment *tail_segment;
        struct xilinx_dma_tx_descriptor *tail_desc;
        struct xilinx_axidma_tx_segment *axidma_tail_segment;
+       struct xilinx_aximcdma_tx_segment *aximcdma_tail_segment;
        struct xilinx_cdma_tx_segment *cdma_tail_segment;
 
        if (list_empty(&chan->pending_list))
@@ -1885,11 +1898,17 @@ static void append_desc_queue(struct xilinx_dma_chan *chan,
                                                struct xilinx_cdma_tx_segment,
                                                node);
                cdma_tail_segment->hw.next_desc = (u32)desc->async_tx.phys;
-       } else {
+       } else if (chan->xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) {
                axidma_tail_segment = list_last_entry(&tail_desc->segments,
                                               struct xilinx_axidma_tx_segment,
                                               node);
                axidma_tail_segment->hw.next_desc = (u32)desc->async_tx.phys;
+       } else {
+               aximcdma_tail_segment =
+                       list_last_entry(&tail_desc->segments,
+                                       struct xilinx_aximcdma_tx_segment,
+                                       node);
+               aximcdma_tail_segment->hw.next_desc = (u32)desc->async_tx.phys;
        }
 
        /*
@@ -2836,10 +2855,11 @@ static int xilinx_dma_chan_probe(struct xilinx_dma_device *xdev,
                chan->stop_transfer = xilinx_dma_stop_transfer;
        }
 
-       /* check if SG is enabled (only for AXIDMA and CDMA) */
+       /* check if SG is enabled (only for AXIDMA, AXIMCDMA, and CDMA) */
        if (xdev->dma_config->dmatype != XDMA_TYPE_VDMA) {
-               if (dma_ctrl_read(chan, XILINX_DMA_REG_DMASR) &
-                   XILINX_DMA_DMASR_SG_MASK)
+               if (xdev->dma_config->dmatype == XDMA_TYPE_AXIMCDMA ||
+                   dma_ctrl_read(chan, XILINX_DMA_REG_DMASR) &
+                           XILINX_DMA_DMASR_SG_MASK)
                        chan->has_sg = true;
                dev_dbg(chan->dev, "ch %d: SG %s\n", chan->id,
                        chan->has_sg ? "enabled" : "disabled");
index 8d1ff24..efb8a66 100644 (file)
@@ -147,6 +147,9 @@ static int zynqmp_pm_feature(u32 api_id)
                return 0;
 
        /* Return value if feature is already checked */
+       if (api_id > ARRAY_SIZE(zynqmp_pm_features))
+               return PM_FEATURE_INVALID;
+
        if (zynqmp_pm_features[api_id] != PM_FEATURE_UNCHECKED)
                return zynqmp_pm_features[api_id];
 
index e44d5de..b966f5e 100644 (file)
@@ -1114,6 +1114,7 @@ static const struct aspeed_gpio_config ast2500_config =
 
 static const struct aspeed_bank_props ast2600_bank_props[] = {
        /*     input      output   */
+       {4, 0xffffffff,  0x00ffffff}, /* Q/R/S/T */
        {5, 0xffffffff,  0xffffff00}, /* U/V/W/X */
        {6, 0x0000ffff,  0x0000ffff}, /* Y/Z */
        { },
index a5b3267..2a9046c 100644 (file)
@@ -343,8 +343,8 @@ static int dwapb_irq_set_type(struct irq_data *d, u32 type)
 #ifdef CONFIG_PM_SLEEP
 static int dwapb_irq_set_wake(struct irq_data *d, unsigned int enable)
 {
-       struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d);
-       struct dwapb_gpio *gpio = igc->private;
+       struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+       struct dwapb_gpio *gpio = to_dwapb_gpio(gc);
        struct dwapb_context *ctx = gpio->ports[0].ctx;
        irq_hw_number_t bit = irqd_to_hwirq(d);
 
index 6d59e3a..f7ceb2b 100644 (file)
@@ -1114,13 +1114,23 @@ static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context)
 {
        struct device *dev = bank->chip.parent;
        void __iomem *base = bank->base;
-       u32 nowake;
+       u32 mask, nowake;
 
        bank->saved_datain = readl_relaxed(base + bank->regs->datain);
 
        if (!bank->enabled_non_wakeup_gpios)
                goto update_gpio_context_count;
 
+       /* Check for pending EDGE_FALLING, ignore EDGE_BOTH */
+       mask = bank->enabled_non_wakeup_gpios & bank->context.fallingdetect;
+       mask &= ~bank->context.risingdetect;
+       bank->saved_datain |= mask;
+
+       /* Check for pending EDGE_RISING, ignore EDGE_BOTH */
+       mask = bank->enabled_non_wakeup_gpios & bank->context.risingdetect;
+       mask &= ~bank->context.fallingdetect;
+       bank->saved_datain &= ~mask;
+
        if (!may_lose_context)
                goto update_gpio_context_count;
 
index a68941d..2a07fd9 100644 (file)
 #include <linux/spinlock.h>
 #include <linux/types.h>
 
+/*
+ * PLX PEX8311 PCI LCS_INTCSR Interrupt Control/Status
+ *
+ * Bit: Description
+ *   0: Enable Interrupt Sources (Bit 0)
+ *   1: Enable Interrupt Sources (Bit 1)
+ *   2: Generate Internal PCI Bus Internal SERR# Interrupt
+ *   3: Mailbox Interrupt Enable
+ *   4: Power Management Interrupt Enable
+ *   5: Power Management Interrupt
+ *   6: Slave Read Local Data Parity Check Error Enable
+ *   7: Slave Read Local Data Parity Check Error Status
+ *   8: Internal PCI Wire Interrupt Enable
+ *   9: PCI Express Doorbell Interrupt Enable
+ *  10: PCI Abort Interrupt Enable
+ *  11: Local Interrupt Input Enable
+ *  12: Retry Abort Enable
+ *  13: PCI Express Doorbell Interrupt Active
+ *  14: PCI Abort Interrupt Active
+ *  15: Local Interrupt Input Active
+ *  16: Local Interrupt Output Enable
+ *  17: Local Doorbell Interrupt Enable
+ *  18: DMA Channel 0 Interrupt Enable
+ *  19: DMA Channel 1 Interrupt Enable
+ *  20: Local Doorbell Interrupt Active
+ *  21: DMA Channel 0 Interrupt Active
+ *  22: DMA Channel 1 Interrupt Active
+ *  23: Built-In Self-Test (BIST) Interrupt Active
+ *  24: Direct Master was the Bus Master during a Master or Target Abort
+ *  25: DMA Channel 0 was the Bus Master during a Master or Target Abort
+ *  26: DMA Channel 1 was the Bus Master during a Master or Target Abort
+ *  27: Target Abort after internal 256 consecutive Master Retrys
+ *  28: PCI Bus wrote data to LCS_MBOX0
+ *  29: PCI Bus wrote data to LCS_MBOX1
+ *  30: PCI Bus wrote data to LCS_MBOX2
+ *  31: PCI Bus wrote data to LCS_MBOX3
+ */
+#define PLX_PEX8311_PCI_LCS_INTCSR  0x68
+#define INTCSR_INTERNAL_PCI_WIRE    BIT(8)
+#define INTCSR_LOCAL_INPUT          BIT(11)
+
 /**
  * struct idio_24_gpio_reg - GPIO device registers structure
  * @out0_7:    Read: FET Outputs 0-7
@@ -92,6 +133,7 @@ struct idio_24_gpio_reg {
 struct idio_24_gpio {
        struct gpio_chip chip;
        raw_spinlock_t lock;
+       __u8 __iomem *plx;
        struct idio_24_gpio_reg __iomem *reg;
        unsigned long irq_mask;
 };
@@ -334,13 +376,13 @@ static void idio_24_irq_mask(struct irq_data *data)
        unsigned long flags;
        const unsigned long bit_offset = irqd_to_hwirq(data) - 24;
        unsigned char new_irq_mask;
-       const unsigned long bank_offset = bit_offset/8 * 8;
+       const unsigned long bank_offset = bit_offset / 8;
        unsigned char cos_enable_state;
 
        raw_spin_lock_irqsave(&idio24gpio->lock, flags);
 
-       idio24gpio->irq_mask &= BIT(bit_offset);
-       new_irq_mask = idio24gpio->irq_mask >> bank_offset;
+       idio24gpio->irq_mask &= ~BIT(bit_offset);
+       new_irq_mask = idio24gpio->irq_mask >> bank_offset * 8;
 
        if (!new_irq_mask) {
                cos_enable_state = ioread8(&idio24gpio->reg->cos_enable);
@@ -363,12 +405,12 @@ static void idio_24_irq_unmask(struct irq_data *data)
        unsigned long flags;
        unsigned char prev_irq_mask;
        const unsigned long bit_offset = irqd_to_hwirq(data) - 24;
-       const unsigned long bank_offset = bit_offset/8 * 8;
+       const unsigned long bank_offset = bit_offset / 8;
        unsigned char cos_enable_state;
 
        raw_spin_lock_irqsave(&idio24gpio->lock, flags);
 
-       prev_irq_mask = idio24gpio->irq_mask >> bank_offset;
+       prev_irq_mask = idio24gpio->irq_mask >> bank_offset * 8;
        idio24gpio->irq_mask |= BIT(bit_offset);
 
        if (!prev_irq_mask) {
@@ -455,6 +497,7 @@ static int idio_24_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        struct device *const dev = &pdev->dev;
        struct idio_24_gpio *idio24gpio;
        int err;
+       const size_t pci_plx_bar_index = 1;
        const size_t pci_bar_index = 2;
        const char *const name = pci_name(pdev);
        struct gpio_irq_chip *girq;
@@ -469,12 +512,13 @@ static int idio_24_probe(struct pci_dev *pdev, const struct pci_device_id *id)
                return err;
        }
 
-       err = pcim_iomap_regions(pdev, BIT(pci_bar_index), name);
+       err = pcim_iomap_regions(pdev, BIT(pci_plx_bar_index) | BIT(pci_bar_index), name);
        if (err) {
                dev_err(dev, "Unable to map PCI I/O addresses (%d)\n", err);
                return err;
        }
 
+       idio24gpio->plx = pcim_iomap_table(pdev)[pci_plx_bar_index];
        idio24gpio->reg = pcim_iomap_table(pdev)[pci_bar_index];
 
        idio24gpio->chip.label = name;
@@ -504,6 +548,12 @@ static int idio_24_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
        /* Software board reset */
        iowrite8(0, &idio24gpio->reg->soft_reset);
+       /*
+        * enable PLX PEX8311 internal PCI wire interrupt and local interrupt
+        * input
+        */
+       iowrite8((INTCSR_INTERNAL_PCI_WIRE | INTCSR_LOCAL_INPUT) >> 8,
+                idio24gpio->plx + PLX_PEX8311_PCI_LCS_INTCSR + 1);
 
        err = devm_gpiochip_add_data(dev, &idio24gpio->chip, idio24gpio);
        if (err) {
index c54dd08..d5eb9ca 100644 (file)
@@ -183,7 +183,7 @@ static int sifive_gpio_probe(struct platform_device *pdev)
                return PTR_ERR(chip->regs);
 
        ngpio = of_irq_count(node);
-       if (ngpio >= SIFIVE_GPIO_MAX) {
+       if (ngpio > SIFIVE_GPIO_MAX) {
                dev_err(dev, "Too many GPIO interrupts (max=%d)\n",
                        SIFIVE_GPIO_MAX);
                return -ENXIO;
index cb41dd7..b42644c 100644 (file)
@@ -7,22 +7,7 @@
 
 struct gpio_device;
 
-#ifdef CONFIG_GPIO_CDEV
-
 int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt);
 void gpiolib_cdev_unregister(struct gpio_device *gdev);
 
-#else
-
-static inline int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)
-{
-       return 0;
-}
-
-static inline void gpiolib_cdev_unregister(struct gpio_device *gdev)
-{
-}
-
-#endif /* CONFIG_GPIO_CDEV */
-
 #endif /* GPIOLIB_CDEV_H */
index 3cdf9ef..089ddca 100644 (file)
@@ -480,11 +480,23 @@ static void gpiodevice_release(struct device *dev)
        kfree(gdev);
 }
 
+#ifdef CONFIG_GPIO_CDEV
+#define gcdev_register(gdev, devt)     gpiolib_cdev_register((gdev), (devt))
+#define gcdev_unregister(gdev)         gpiolib_cdev_unregister((gdev))
+#else
+/*
+ * gpiolib_cdev_register() indirectly calls device_add(), which is still
+ * required even when cdev is not selected.
+ */
+#define gcdev_register(gdev, devt)     device_add(&(gdev)->dev)
+#define gcdev_unregister(gdev)         device_del(&(gdev)->dev)
+#endif
+
 static int gpiochip_setup_dev(struct gpio_device *gdev)
 {
        int ret;
 
-       ret = gpiolib_cdev_register(gdev, gpio_devt);
+       ret = gcdev_register(gdev, gpio_devt);
        if (ret)
                return ret;
 
@@ -500,7 +512,7 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
        return 0;
 
 err_remove_device:
-       gpiolib_cdev_unregister(gdev);
+       gcdev_unregister(gdev);
        return ret;
 }
 
@@ -825,7 +837,7 @@ void gpiochip_remove(struct gpio_chip *gc)
         * be removed, else it will be dangling until the last user is
         * gone.
         */
-       gpiolib_cdev_unregister(gdev);
+       gcdev_unregister(gdev);
        put_device(&gdev->dev);
 }
 EXPORT_SYMBOL_GPL(gpiochip_remove);
index 37da353..e3783f5 100644 (file)
@@ -80,6 +80,7 @@ MODULE_FIRMWARE("amdgpu/renoir_gpu_info.bin");
 MODULE_FIRMWARE("amdgpu/navi10_gpu_info.bin");
 MODULE_FIRMWARE("amdgpu/navi14_gpu_info.bin");
 MODULE_FIRMWARE("amdgpu/navi12_gpu_info.bin");
+MODULE_FIRMWARE("amdgpu/green_sardine_gpu_info.bin");
 
 #define AMDGPU_RESUME_MS               2000
 
@@ -239,9 +240,11 @@ bool amdgpu_device_supports_baco(struct drm_device *dev)
        return amdgpu_asic_supports_baco(adev);
 }
 
+/*
+ * VRAM access helper functions
+ */
+
 /**
- * VRAM access helper functions.
- *
  * amdgpu_device_vram_access - read/write a buffer in vram
  *
  * @adev: amdgpu_device pointer
@@ -705,7 +708,7 @@ void amdgpu_device_indirect_wreg64(struct amdgpu_device *adev,
 /**
  * amdgpu_invalid_rreg - dummy reg read function
  *
- * @adev: amdgpu device pointer
+ * @adev: amdgpu_device pointer
  * @reg: offset of register
  *
  * Dummy register read function.  Used for register blocks
@@ -722,7 +725,7 @@ static uint32_t amdgpu_invalid_rreg(struct amdgpu_device *adev, uint32_t reg)
 /**
  * amdgpu_invalid_wreg - dummy reg write function
  *
- * @adev: amdgpu device pointer
+ * @adev: amdgpu_device pointer
  * @reg: offset of register
  * @v: value to write to the register
  *
@@ -739,7 +742,7 @@ static void amdgpu_invalid_wreg(struct amdgpu_device *adev, uint32_t reg, uint32
 /**
  * amdgpu_invalid_rreg64 - dummy 64 bit reg read function
  *
- * @adev: amdgpu device pointer
+ * @adev: amdgpu_device pointer
  * @reg: offset of register
  *
  * Dummy register read function.  Used for register blocks
@@ -756,7 +759,7 @@ static uint64_t amdgpu_invalid_rreg64(struct amdgpu_device *adev, uint32_t reg)
 /**
  * amdgpu_invalid_wreg64 - dummy reg write function
  *
- * @adev: amdgpu device pointer
+ * @adev: amdgpu_device pointer
  * @reg: offset of register
  * @v: value to write to the register
  *
@@ -773,7 +776,7 @@ static void amdgpu_invalid_wreg64(struct amdgpu_device *adev, uint32_t reg, uint
 /**
  * amdgpu_block_invalid_rreg - dummy reg read function
  *
- * @adev: amdgpu device pointer
+ * @adev: amdgpu_device pointer
  * @block: offset of instance
  * @reg: offset of register
  *
@@ -793,7 +796,7 @@ static uint32_t amdgpu_block_invalid_rreg(struct amdgpu_device *adev,
 /**
  * amdgpu_block_invalid_wreg - dummy reg write function
  *
- * @adev: amdgpu device pointer
+ * @adev: amdgpu_device pointer
  * @block: offset of instance
  * @reg: offset of register
  * @v: value to write to the register
@@ -813,7 +816,7 @@ static void amdgpu_block_invalid_wreg(struct amdgpu_device *adev,
 /**
  * amdgpu_device_asic_init - Wrapper for atom asic_init
  *
- * @dev: drm_device pointer
+ * @adev: amdgpu_device pointer
  *
  * Does any asic specific work and then calls atom asic init.
  */
@@ -827,7 +830,7 @@ static int amdgpu_device_asic_init(struct amdgpu_device *adev)
 /**
  * amdgpu_device_vram_scratch_init - allocate the VRAM scratch page
  *
- * @adev: amdgpu device pointer
+ * @adev: amdgpu_device pointer
  *
  * Allocates a scratch page of VRAM for use by various things in the
  * driver.
@@ -844,7 +847,7 @@ static int amdgpu_device_vram_scratch_init(struct amdgpu_device *adev)
 /**
  * amdgpu_device_vram_scratch_fini - Free the VRAM scratch page
  *
- * @adev: amdgpu device pointer
+ * @adev: amdgpu_device pointer
  *
  * Frees the VRAM scratch page.
  */
@@ -1803,7 +1806,10 @@ static int amdgpu_device_parse_gpu_info_fw(struct amdgpu_device *adev)
                chip_name = "arcturus";
                break;
        case CHIP_RENOIR:
-               chip_name = "renoir";
+               if (adev->apu_flags & AMD_APU_IS_RENOIR)
+                       chip_name = "renoir";
+               else
+                       chip_name = "green_sardine";
                break;
        case CHIP_NAVI10:
                chip_name = "navi10";
@@ -3011,7 +3017,7 @@ bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type)
 /**
  * amdgpu_device_has_dc_support - check if dc is supported
  *
- * @adev: amdgpu_device_pointer
+ * @adev: amdgpu_device pointer
  *
  * Returns true for supported, false for not supported
  */
@@ -4045,7 +4051,7 @@ static int amdgpu_device_recover_vram(struct amdgpu_device *adev)
 /**
  * amdgpu_device_reset_sriov - reset ASIC for SR-IOV vf
  *
- * @adev: amdgpu device pointer
+ * @adev: amdgpu_device pointer
  * @from_hypervisor: request from hypervisor
  *
  * do VF FLR and reinitialize Asic
@@ -4100,7 +4106,7 @@ error:
 /**
  * amdgpu_device_has_job_running - check if there is any job in mirror list
  *
- * @adev: amdgpu device pointer
+ * @adev: amdgpu_device pointer
  *
  * check if there is any job in mirror list
  */
@@ -4128,7 +4134,7 @@ bool amdgpu_device_has_job_running(struct amdgpu_device *adev)
 /**
  * amdgpu_device_should_recover_gpu - check if we should try GPU recovery
  *
- * @adev: amdgpu device pointer
+ * @adev: amdgpu_device pointer
  *
  * Check amdgpu_gpu_recovery and SRIOV status to see if we should try to recover
  * a hung GPU.
@@ -4477,7 +4483,7 @@ static int amdgpu_device_suspend_display_audio(struct amdgpu_device *adev)
 /**
  * amdgpu_device_gpu_recover - reset the asic and recover scheduler
  *
- * @adev: amdgpu device pointer
+ * @adev: amdgpu_device pointer
  * @job: which job trigger hang
  *
  * Attempt to reset the GPU if it has hung (all asics).
@@ -4497,7 +4503,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
        bool need_emergency_restart = false;
        bool audio_suspended = false;
 
-       /**
+       /*
         * Special case: RAS triggered and full reset isn't supported
         */
        need_emergency_restart = amdgpu_ras_need_emergency_restart(adev);
index 42d9748..8e988f0 100644 (file)
@@ -1055,10 +1055,10 @@ static const struct pci_device_id pciidlist[] = {
        {0x1002, 0x15dd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RAVEN|AMD_IS_APU},
        {0x1002, 0x15d8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RAVEN|AMD_IS_APU},
        /* Arcturus */
-       {0x1002, 0x738C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_ARCTURUS|AMD_EXP_HW_SUPPORT},
-       {0x1002, 0x7388, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_ARCTURUS|AMD_EXP_HW_SUPPORT},
-       {0x1002, 0x738E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_ARCTURUS|AMD_EXP_HW_SUPPORT},
-       {0x1002, 0x7390, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_ARCTURUS|AMD_EXP_HW_SUPPORT},
+       {0x1002, 0x738C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_ARCTURUS},
+       {0x1002, 0x7388, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_ARCTURUS},
+       {0x1002, 0x738E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_ARCTURUS},
+       {0x1002, 0x7390, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_ARCTURUS},
        /* Navi10 */
        {0x1002, 0x7310, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_NAVI10},
        {0x1002, 0x7312, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_NAVI10},
index f203e4a..731f3aa 100644 (file)
@@ -81,8 +81,8 @@ static const struct ttm_resource_manager_func amdgpu_gtt_mgr_func;
 /**
  * amdgpu_gtt_mgr_init - init GTT manager and DRM MM
  *
- * @man: TTM memory type manager
- * @p_size: maximum size of GTT
+ * @adev: amdgpu_device pointer
+ * @gtt_size: maximum size of GTT
  *
  * Allocate and initialize the GTT manager.
  */
@@ -123,7 +123,7 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
 /**
  * amdgpu_gtt_mgr_fini - free and destroy GTT manager
  *
- * @man: TTM memory type manager
+ * @adev: amdgpu_device pointer
  *
  * Destroy and free the GTT manager, returns -EBUSY if ranges are still
  * allocated inside it.
index 96a9699..a6dbe4b 100644 (file)
@@ -2524,6 +2524,7 @@ int parse_ta_bin_descriptor(struct psp_context *psp,
                psp->asd_feature_version   = le32_to_cpu(desc->fw_version);
                psp->asd_ucode_size        = le32_to_cpu(desc->size_bytes);
                psp->asd_start_addr        = ucode_start_addr;
+               psp->asd_fw                = psp->ta_fw;
                break;
        case TA_FW_TYPE_PSP_XGMI:
                psp->ta_xgmi_ucode_version = le32_to_cpu(desc->fw_version);
index f3b7287..a563328 100644 (file)
@@ -39,6 +39,7 @@
 #define FIRMWARE_RAVEN2                "amdgpu/raven2_vcn.bin"
 #define FIRMWARE_ARCTURUS      "amdgpu/arcturus_vcn.bin"
 #define FIRMWARE_RENOIR        "amdgpu/renoir_vcn.bin"
+#define FIRMWARE_GREEN_SARDINE         "amdgpu/green_sardine_vcn.bin"
 #define FIRMWARE_NAVI10        "amdgpu/navi10_vcn.bin"
 #define FIRMWARE_NAVI14        "amdgpu/navi14_vcn.bin"
 #define FIRMWARE_NAVI12        "amdgpu/navi12_vcn.bin"
@@ -50,6 +51,7 @@ MODULE_FIRMWARE(FIRMWARE_PICASSO);
 MODULE_FIRMWARE(FIRMWARE_RAVEN2);
 MODULE_FIRMWARE(FIRMWARE_ARCTURUS);
 MODULE_FIRMWARE(FIRMWARE_RENOIR);
+MODULE_FIRMWARE(FIRMWARE_GREEN_SARDINE);
 MODULE_FIRMWARE(FIRMWARE_NAVI10);
 MODULE_FIRMWARE(FIRMWARE_NAVI14);
 MODULE_FIRMWARE(FIRMWARE_NAVI12);
@@ -89,7 +91,11 @@ int amdgpu_vcn_sw_init(struct amdgpu_device *adev)
                        adev->vcn.indirect_sram = true;
                break;
        case CHIP_RENOIR:
-               fw_name = FIRMWARE_RENOIR;
+               if (adev->apu_flags & AMD_APU_IS_RENOIR)
+                       fw_name = FIRMWARE_RENOIR;
+               else
+                       fw_name = FIRMWARE_GREEN_SARDINE;
+
                if ((adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) &&
                    (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG))
                        adev->vcn.indirect_sram = true;
index 01c1171..0c6b7c5 100644 (file)
@@ -168,8 +168,7 @@ static const struct ttm_resource_manager_func amdgpu_vram_mgr_func;
 /**
  * amdgpu_vram_mgr_init - init VRAM manager and DRM MM
  *
- * @man: TTM memory type manager
- * @p_size: maximum size of VRAM
+ * @adev: amdgpu_device pointer
  *
  * Allocate and initialize the VRAM manager.
  */
@@ -199,7 +198,7 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
 /**
  * amdgpu_vram_mgr_fini - free and destroy VRAM manager
  *
- * @man: TTM memory type manager
+ * @adev: amdgpu_device pointer
  *
  * Destroy and free the VRAM manager, returns -EBUSY if ranges are still
  * allocated inside it.
@@ -229,7 +228,7 @@ void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
 /**
  * amdgpu_vram_mgr_vis_size - Calculate visible node size
  *
- * @adev: amdgpu device structure
+ * @adev: amdgpu_device pointer
  * @node: MM node structure
  *
  * Calculate how many bytes of the MM node are inside visible VRAM
index 03ff8bd..5442df0 100644 (file)
@@ -1336,11 +1336,13 @@ cik_asic_reset_method(struct amdgpu_device *adev)
 
        switch (adev->asic_type) {
        case CHIP_BONAIRE:
-       case CHIP_HAWAII:
                /* disable baco reset until it works */
                /* smu7_asic_get_baco_capability(adev, &baco_reset); */
                baco_reset = false;
                break;
+       case CHIP_HAWAII:
+               baco_reset = cik_asic_supports_baco(adev);
+               break;
        default:
                baco_reset = false;
                break;
index 20f1088..a3c3fe9 100644 (file)
@@ -1071,22 +1071,19 @@ static int cik_sdma_soft_reset(void *handle)
 {
        u32 srbm_soft_reset = 0;
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-       u32 tmp = RREG32(mmSRBM_STATUS2);
+       u32 tmp;
 
-       if (tmp & SRBM_STATUS2__SDMA_BUSY_MASK) {
-               /* sdma0 */
-               tmp = RREG32(mmSDMA0_F32_CNTL + SDMA0_REGISTER_OFFSET);
-               tmp |= SDMA0_F32_CNTL__HALT_MASK;
-               WREG32(mmSDMA0_F32_CNTL + SDMA0_REGISTER_OFFSET, tmp);
-               srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_SDMA_MASK;
-       }
-       if (tmp & SRBM_STATUS2__SDMA1_BUSY_MASK) {
-               /* sdma1 */
-               tmp = RREG32(mmSDMA0_F32_CNTL + SDMA1_REGISTER_OFFSET);
-               tmp |= SDMA0_F32_CNTL__HALT_MASK;
-               WREG32(mmSDMA0_F32_CNTL + SDMA1_REGISTER_OFFSET, tmp);
-               srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_SDMA1_MASK;
-       }
+       /* sdma0 */
+       tmp = RREG32(mmSDMA0_F32_CNTL + SDMA0_REGISTER_OFFSET);
+       tmp |= SDMA0_F32_CNTL__HALT_MASK;
+       WREG32(mmSDMA0_F32_CNTL + SDMA0_REGISTER_OFFSET, tmp);
+       srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_SDMA_MASK;
+
+       /* sdma1 */
+       tmp = RREG32(mmSDMA0_F32_CNTL + SDMA1_REGISTER_OFFSET);
+       tmp |= SDMA0_F32_CNTL__HALT_MASK;
+       WREG32(mmSDMA0_F32_CNTL + SDMA1_REGISTER_OFFSET, tmp);
+       srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_SDMA1_MASK;
 
        if (srbm_soft_reset) {
                tmp = RREG32(mmSRBM_SOFT_RESET);
index 56fdbe6..3579565 100644 (file)
 #define PA_SC_ENHANCE_3__FORCE_PBB_WORKLOAD_MODE_TO_ZERO__SHIFT 0x3
 #define PA_SC_ENHANCE_3__FORCE_PBB_WORKLOAD_MODE_TO_ZERO_MASK   0x00000008L
 
+#define mmCGTT_SPI_CS_CLK_CTRL                 0x507c
+#define mmCGTT_SPI_CS_CLK_CTRL_BASE_IDX         1
+
 MODULE_FIRMWARE("amdgpu/navi10_ce.bin");
 MODULE_FIRMWARE("amdgpu/navi10_pfp.bin");
 MODULE_FIRMWARE("amdgpu/navi10_me.bin");
@@ -3094,6 +3097,7 @@ static const struct soc15_reg_golden golden_settings_gc_rlc_spm_10_1_2_nv12[] =
 
 static const struct soc15_reg_golden golden_settings_gc_10_3[] =
 {
+       SOC15_REG_GOLDEN_VALUE(GC, 0, mmCGTT_SPI_CS_CLK_CTRL, 0x78000000, 0x78000100),
        SOC15_REG_GOLDEN_VALUE(GC, 0, mmCGTT_SPI_PS_CLK_CTRL, 0xff7f0fff, 0x78000100),
        SOC15_REG_GOLDEN_VALUE(GC, 0, mmCGTT_SPI_RA0_CLK_CTRL, 0xff7f0fff, 0x30000100),
        SOC15_REG_GOLDEN_VALUE(GC, 0, mmCGTT_SPI_RA1_CLK_CTRL, 0xff7f0fff, 0x7e000100),
index 6959aeb..0d8e203 100644 (file)
@@ -117,6 +117,13 @@ MODULE_FIRMWARE("amdgpu/renoir_mec.bin");
 MODULE_FIRMWARE("amdgpu/renoir_mec2.bin");
 MODULE_FIRMWARE("amdgpu/renoir_rlc.bin");
 
+MODULE_FIRMWARE("amdgpu/green_sardine_ce.bin");
+MODULE_FIRMWARE("amdgpu/green_sardine_pfp.bin");
+MODULE_FIRMWARE("amdgpu/green_sardine_me.bin");
+MODULE_FIRMWARE("amdgpu/green_sardine_mec.bin");
+MODULE_FIRMWARE("amdgpu/green_sardine_mec2.bin");
+MODULE_FIRMWARE("amdgpu/green_sardine_rlc.bin");
+
 #define mmTCP_CHAN_STEER_0_ARCT                                                                0x0b03
 #define mmTCP_CHAN_STEER_0_ARCT_BASE_IDX                                                       0
 #define mmTCP_CHAN_STEER_1_ARCT                                                                0x0b04
@@ -1630,7 +1637,10 @@ static int gfx_v9_0_init_microcode(struct amdgpu_device *adev)
                chip_name = "arcturus";
                break;
        case CHIP_RENOIR:
-               chip_name = "renoir";
+               if (adev->apu_flags & AMD_APU_IS_RENOIR)
+                       chip_name = "renoir";
+               else
+                       chip_name = "green_sardine";
                break;
        default:
                BUG();
index 03462c8..8eeba80 100644 (file)
@@ -455,10 +455,11 @@ void nv_set_virt_ops(struct amdgpu_device *adev)
        adev->virt.ops = &xgpu_nv_virt_ops;
 }
 
-static bool nv_is_blockchain_sku(struct pci_dev *pdev)
+static bool nv_is_headless_sku(struct pci_dev *pdev)
 {
-       if (pdev->device == 0x731E &&
-           (pdev->revision == 0xC6 || pdev->revision == 0xC7))
+       if ((pdev->device == 0x731E &&
+           (pdev->revision == 0xC6 || pdev->revision == 0xC7)) ||
+           (pdev->device == 0x7340 && pdev->revision == 0xC9))
                return true;
        return false;
 }
@@ -491,8 +492,7 @@ int nv_set_ip_blocks(struct amdgpu_device *adev)
                if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
                        amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
 #if defined(CONFIG_DRM_AMD_DC)
-               else if (amdgpu_device_has_dc_support(adev) &&
-                        !nv_is_blockchain_sku(adev->pdev))
+               else if (amdgpu_device_has_dc_support(adev))
                        amdgpu_device_ip_block_add(adev, &dm_ip_block);
 #endif
                amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
@@ -500,7 +500,7 @@ int nv_set_ip_blocks(struct amdgpu_device *adev)
                if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
                    !amdgpu_sriov_vf(adev))
                        amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
-               if (!nv_is_blockchain_sku(adev->pdev))
+               if (!nv_is_headless_sku(adev->pdev))
                        amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
                amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block);
                if (adev->enable_mes)
index 7548931..c4828bd 100644 (file)
@@ -39,6 +39,8 @@
 
 MODULE_FIRMWARE("amdgpu/renoir_asd.bin");
 MODULE_FIRMWARE("amdgpu/renoir_ta.bin");
+MODULE_FIRMWARE("amdgpu/green_sardine_asd.bin");
+MODULE_FIRMWARE("amdgpu/green_sardine_ta.bin");
 
 /* address block */
 #define smnMP1_FIRMWARE_FLAGS          0x3010024
@@ -54,7 +56,10 @@ static int psp_v12_0_init_microcode(struct psp_context *psp)
 
        switch (adev->asic_type) {
        case CHIP_RENOIR:
-               chip_name = "renoir";
+               if (adev->apu_flags & AMD_APU_IS_RENOIR)
+                       chip_name = "renoir";
+               else
+                       chip_name = "green_sardine";
                break;
        default:
                BUG();
index 86fb1ed..e82f49f 100644 (file)
@@ -69,6 +69,7 @@ MODULE_FIRMWARE("amdgpu/picasso_sdma.bin");
 MODULE_FIRMWARE("amdgpu/raven2_sdma.bin");
 MODULE_FIRMWARE("amdgpu/arcturus_sdma.bin");
 MODULE_FIRMWARE("amdgpu/renoir_sdma.bin");
+MODULE_FIRMWARE("amdgpu/green_sardine_sdma.bin");
 
 #define SDMA0_POWER_CNTL__ON_OFF_CONDITION_HOLD_TIME_MASK  0x000000F8L
 #define SDMA0_POWER_CNTL__ON_OFF_STATUS_DURATION_TIME_MASK 0xFC000000L
@@ -619,7 +620,10 @@ static int sdma_v4_0_init_microcode(struct amdgpu_device *adev)
                chip_name = "arcturus";
                break;
        case CHIP_RENOIR:
-               chip_name = "renoir";
+               if (adev->apu_flags & AMD_APU_IS_RENOIR)
+                       chip_name = "renoir";
+               else
+                       chip_name = "green_sardine";
                break;
        default:
                BUG();
index afcccc6..f57c5f5 100644 (file)
@@ -1195,8 +1195,7 @@ static int soc15_common_early_init(void *handle)
 
                        adev->pg_flags = AMD_PG_SUPPORT_SDMA |
                                AMD_PG_SUPPORT_MMHUB |
-                               AMD_PG_SUPPORT_VCN |
-                               AMD_PG_SUPPORT_VCN_DPG;
+                               AMD_PG_SUPPORT_VCN;
                } else {
                        adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
                                AMD_CG_SUPPORT_GFX_MGLS |
@@ -1243,7 +1242,15 @@ static int soc15_common_early_init(void *handle)
                break;
        case CHIP_RENOIR:
                adev->asic_funcs = &soc15_asic_funcs;
-               adev->apu_flags |= AMD_APU_IS_RENOIR;
+               if (adev->pdev->device == 0x1636)
+                       adev->apu_flags |= AMD_APU_IS_RENOIR;
+               else
+                       adev->apu_flags |= AMD_APU_IS_GREEN_SARDINE;
+
+               if (adev->apu_flags & AMD_APU_IS_RENOIR)
+                       adev->external_rev_id = adev->rev_id + 0x91;
+               else
+                       adev->external_rev_id = adev->rev_id + 0xa1;
                adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
                                 AMD_CG_SUPPORT_GFX_MGLS |
                                 AMD_CG_SUPPORT_GFX_3D_CGCG |
@@ -1268,7 +1275,6 @@ static int soc15_common_early_init(void *handle)
                                 AMD_PG_SUPPORT_VCN |
                                 AMD_PG_SUPPORT_JPEG |
                                 AMD_PG_SUPPORT_VCN_DPG;
-               adev->external_rev_id = adev->rev_id + 0x91;
                break;
        default:
                /* FIXME: not supported yet */
index 5e2254b..3de5e14 100644 (file)
@@ -798,10 +798,10 @@ int kfd_create_crat_image_acpi(void **crat_image, size_t *size)
        }
 
        pcrat_image = kvmalloc(crat_table->length, GFP_KERNEL);
-       memcpy(pcrat_image, crat_table, crat_table->length);
        if (!pcrat_image)
                return -ENOMEM;
 
+       memcpy(pcrat_image, crat_table, crat_table->length);
        *crat_image = pcrat_image;
        *size = crat_table->length;
 
index e2b2348..0e71180 100644 (file)
@@ -100,6 +100,8 @@ MODULE_FIRMWARE(FIRMWARE_SIENNA_CICHLID_DMUB);
 #define FIRMWARE_NAVY_FLOUNDER_DMUB "amdgpu/navy_flounder_dmcub.bin"
 MODULE_FIRMWARE(FIRMWARE_NAVY_FLOUNDER_DMUB);
 #endif
+#define FIRMWARE_GREEN_SARDINE_DMUB "amdgpu/green_sardine_dmcub.bin"
+MODULE_FIRMWARE(FIRMWARE_GREEN_SARDINE_DMUB);
 
 #define FIRMWARE_RAVEN_DMCU            "amdgpu/raven_dmcu.bin"
 MODULE_FIRMWARE(FIRMWARE_RAVEN_DMCU);
@@ -583,7 +585,7 @@ static void amdgpu_dm_fbc_init(struct drm_connector *connector)
 {
        struct drm_device *dev = connector->dev;
        struct amdgpu_device *adev = drm_to_adev(dev);
-       struct dm_comressor_info *compressor = &adev->dm.compressor;
+       struct dm_compressor_info *compressor = &adev->dm.compressor;
        struct amdgpu_dm_connector *aconn = to_amdgpu_dm_connector(connector);
        struct drm_display_mode *mode;
        unsigned long max_size = 0;
@@ -973,6 +975,8 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)
        case CHIP_RAVEN:
        case CHIP_RENOIR:
                init_data.flags.gpu_vm_support = true;
+               if (ASICREV_IS_GREEN_SARDINE(adev->external_rev_id))
+                       init_data.flags.disable_dmcu = true;
                break;
        default:
                break;
@@ -1267,6 +1271,8 @@ static int dm_dmub_sw_init(struct amdgpu_device *adev)
        case CHIP_RENOIR:
                dmub_asic = DMUB_ASIC_DCN21;
                fw_name_dmub = FIRMWARE_RENOIR_DMUB;
+               if (ASICREV_IS_GREEN_SARDINE(adev->external_rev_id))
+                       fw_name_dmub = FIRMWARE_GREEN_SARDINE_DMUB;
                break;
 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
        case CHIP_SIENNA_CICHLID:
@@ -7500,7 +7506,6 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state)
        bool mode_set_reset_required = false;
 
        drm_atomic_helper_update_legacy_modeset_state(dev, state);
-       drm_atomic_helper_calc_timestamping_constants(state);
 
        dm_state = dm_atomic_get_new_state(state);
        if (dm_state && dm_state->context) {
@@ -7527,6 +7532,8 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state)
                }
        }
 
+       drm_atomic_helper_calc_timestamping_constants(state);
+
        /* update changed items */
        for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
                struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
index 34f6369..a8a0e8c 100644 (file)
@@ -86,7 +86,7 @@ struct irq_list_head {
  * @bo_ptr: Pointer to the buffer object
  * @gpu_addr: MMIO gpu addr
  */
-struct dm_comressor_info {
+struct dm_compressor_info {
        void *cpu_addr;
        struct amdgpu_bo *bo_ptr;
        uint64_t gpu_addr;
@@ -148,7 +148,7 @@ struct amdgpu_dm_backlight_caps {
  * @soc_bounding_box: SOC bounding box values provided by gpu_info FW
  * @cached_state: Caches device atomic state for suspend/resume
  * @cached_dc_state: Cached state of content streams
- * @compressor: Frame buffer compression buffer. See &struct dm_comressor_info
+ * @compressor: Frame buffer compression buffer. See &struct dm_compressor_info
  * @force_timing_sync: set via debugfs. When set, indicates that all connected
  *                    displays will be forced to synchronize.
  */
@@ -324,7 +324,7 @@ struct amdgpu_display_manager {
        struct drm_atomic_state *cached_state;
        struct dc_state *cached_dc_state;
 
-       struct dm_comressor_info compressor;
+       struct dm_compressor_info compressor;
 
        const struct firmware *fw_dmcu;
        uint32_t dmcu_fw_version;
index efb909e..857f156 100644 (file)
@@ -166,6 +166,11 @@ struct clk_mgr *dc_clk_mgr_create(struct dc_context *ctx, struct pp_smu_funcs *p
                        rn_clk_mgr_construct(ctx, clk_mgr, pp_smu, dccg);
                        break;
                }
+
+               if (ASICREV_IS_GREEN_SARDINE(asic_id.hw_internal_rev)) {
+                       rn_clk_mgr_construct(ctx, clk_mgr, pp_smu, dccg);
+                       break;
+               }
                if (ASICREV_IS_RAVEN2(asic_id.hw_internal_rev)) {
                        rv2_clk_mgr_construct(ctx, clk_mgr, pp_smu);
                        break;
index e430148..59d48cf 100644 (file)
@@ -120,6 +120,8 @@ enum dce_version resource_parse_asic_id(struct hw_asic_id asic_id)
                        dc_version = DCN_VERSION_1_01;
                if (ASICREV_IS_RENOIR(asic_id.hw_internal_rev))
                        dc_version = DCN_VERSION_2_1;
+               if (ASICREV_IS_GREEN_SARDINE(asic_id.hw_internal_rev))
+                       dc_version = DCN_VERSION_2_1;
                break;
 #endif
 
index 2a1fea5..3f1e7a1 100644 (file)
@@ -299,8 +299,8 @@ irq_source_info_dcn20[DAL_IRQ_SOURCES_NUMBER] = {
        pflip_int_entry(1),
        pflip_int_entry(2),
        pflip_int_entry(3),
-       [DC_IRQ_SOURCE_PFLIP5] = dummy_irq_entry(),
-       [DC_IRQ_SOURCE_PFLIP6] = dummy_irq_entry(),
+       pflip_int_entry(4),
+       pflip_int_entry(5),
        [DC_IRQ_SOURCE_PFLIP_UNDERLAY0] = dummy_irq_entry(),
        gpio_pad_int_entry(0),
        gpio_pad_int_entry(1),
index 49689f7..0effbb2 100644 (file)
@@ -306,8 +306,8 @@ irq_source_info_dcn30[DAL_IRQ_SOURCES_NUMBER] = {
        pflip_int_entry(1),
        pflip_int_entry(2),
        pflip_int_entry(3),
-       [DC_IRQ_SOURCE_PFLIP5] = dummy_irq_entry(),
-       [DC_IRQ_SOURCE_PFLIP6] = dummy_irq_entry(),
+       pflip_int_entry(4),
+       pflip_int_entry(5),
        [DC_IRQ_SOURCE_PFLIP_UNDERLAY0] = dummy_irq_entry(),
        gpio_pad_int_entry(0),
        gpio_pad_int_entry(1),
index b267987..ffcb059 100644 (file)
@@ -205,6 +205,10 @@ enum {
 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
 #define ASICREV_IS_SIENNA_CICHLID_P(eChipRev)        ((eChipRev >= NV_SIENNA_CICHLID_P_A0))
 #endif
+#define GREEN_SARDINE_A0 0xA1
+#ifndef ASICREV_IS_GREEN_SARDINE
+#define ASICREV_IS_GREEN_SARDINE(eChipRev) ((eChipRev >= GREEN_SARDINE_A0) && (eChipRev < 0xFF))
+#endif
 
 /*
  * ASIC chip ID
index 10dc481..06c1aab 100644 (file)
@@ -45,6 +45,7 @@ enum amd_apu_flags {
        AMD_APU_IS_RAVEN2 = 0x00000002UL,
        AMD_APU_IS_PICASSO = 0x00000004UL,
        AMD_APU_IS_RENOIR = 0x00000008UL,
+       AMD_APU_IS_GREEN_SARDINE = 0x00000010UL,
 };
 
 /**
index 3898a95..518796a 100644 (file)
@@ -229,6 +229,7 @@ struct pp_smumgr_func {
        bool (*is_hw_avfs_present)(struct pp_hwmgr  *hwmgr);
        int (*update_dpm_settings)(struct pp_hwmgr *hwmgr, void *profile_setting);
        int (*smc_table_manager)(struct pp_hwmgr *hwmgr, uint8_t *table, uint16_t table_id, bool rw); /*rw: true for read, false for write */
+       int (*stop_smc)(struct pp_hwmgr *hwmgr);
 };
 
 struct pp_hwmgr_func {
index ad100b5..5f46f1a 100644 (file)
@@ -113,4 +113,6 @@ extern int smum_update_dpm_settings(struct pp_hwmgr *hwmgr, void *profile_settin
 
 extern int smum_smc_table_manager(struct pp_hwmgr *hwmgr, uint8_t *table, uint16_t table_id, bool rw);
 
+extern int smum_stop_smc(struct pp_hwmgr *hwmgr);
+
 #endif
index 3be4011..45f6088 100644 (file)
@@ -142,12 +142,12 @@ static const struct baco_cmd_entry exit_baco_tbl[] =
        { CMD_READMODIFYWRITE, mmBACO_CNTL, BACO_CNTL__BACO_BCLK_OFF_MASK,           BACO_CNTL__BACO_BCLK_OFF__SHIFT, 0, 0x00 },
        { CMD_READMODIFYWRITE, mmBACO_CNTL, BACO_CNTL__BACO_POWER_OFF_MASK,          BACO_CNTL__BACO_POWER_OFF__SHIFT, 0, 0x00 },
        { CMD_DELAY_MS, 0, 0, 0, 20, 0 },
-       { CMD_WAITFOR, mmBACO_CNTL, BACO_CNTL__PWRGOOD_BF_MASK, 0, 0xffffffff, 0x20 },
+       { CMD_WAITFOR, mmBACO_CNTL, BACO_CNTL__PWRGOOD_BF_MASK, 0, 0xffffffff, 0x200 },
        { CMD_READMODIFYWRITE, mmBACO_CNTL, BACO_CNTL__BACO_ISO_DIS_MASK, BACO_CNTL__BACO_ISO_DIS__SHIFT, 0, 0x01 },
-       { CMD_WAITFOR, mmBACO_CNTL, BACO_CNTL__PWRGOOD_MASK, 0, 5, 0x1c },
+       { CMD_WAITFOR, mmBACO_CNTL, BACO_CNTL__PWRGOOD_MASK, 0, 5, 0x1c00 },
        { CMD_READMODIFYWRITE, mmBACO_CNTL, BACO_CNTL__BACO_ANA_ISO_DIS_MASK, BACO_CNTL__BACO_ANA_ISO_DIS__SHIFT, 0, 0x01 },
        { CMD_READMODIFYWRITE, mmBACO_CNTL, BACO_CNTL__BACO_RESET_EN_MASK, BACO_CNTL__BACO_RESET_EN__SHIFT, 0, 0x00 },
-       { CMD_WAITFOR, mmBACO_CNTL, BACO_CNTL__RCU_BIF_CONFIG_DONE_MASK, 0, 5, 0x10 },
+       { CMD_WAITFOR, mmBACO_CNTL, BACO_CNTL__RCU_BIF_CONFIG_DONE_MASK, 0, 5, 0x100 },
        { CMD_READMODIFYWRITE, mmBACO_CNTL, BACO_CNTL__BACO_EN_MASK, BACO_CNTL__BACO_EN__SHIFT, 0, 0x00 },
        { CMD_WAITFOR, mmBACO_CNTL, BACO_CNTL__BACO_MODE_MASK, 0, 0xffffffff, 0x00 }
 };
@@ -155,6 +155,7 @@ static const struct baco_cmd_entry exit_baco_tbl[] =
 static const struct baco_cmd_entry clean_baco_tbl[] =
 {
        { CMD_WRITE, mmBIOS_SCRATCH_6, 0, 0, 0, 0 },
+       { CMD_WRITE, mmBIOS_SCRATCH_7, 0, 0, 0, 0 },
        { CMD_WRITE, mmCP_PFP_UCODE_ADDR, 0, 0, 0, 0 }
 };
 
index 1e8919b..3562914 100644 (file)
@@ -1541,6 +1541,10 @@ static int smu7_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
        PP_ASSERT_WITH_CODE((tmp_result == 0),
                        "Failed to reset to default!", result = tmp_result);
 
+       tmp_result = smum_stop_smc(hwmgr);
+       PP_ASSERT_WITH_CODE((tmp_result == 0),
+                       "Failed to stop smc!", result = tmp_result);
+
        tmp_result = smu7_force_switch_to_arbf0(hwmgr);
        PP_ASSERT_WITH_CODE((tmp_result == 0),
                        "Failed to force to switch arbf0!", result = tmp_result);
@@ -1585,18 +1589,24 @@ static void smu7_init_dpm_defaults(struct pp_hwmgr *hwmgr)
        data->current_profile_setting.sclk_down_hyst = 100;
        data->current_profile_setting.sclk_activity = SMU7_SCLK_TARGETACTIVITY_DFLT;
        data->current_profile_setting.bupdate_mclk = 1;
-       if (adev->gmc.vram_width == 256) {
-               data->current_profile_setting.mclk_up_hyst = 10;
-               data->current_profile_setting.mclk_down_hyst = 60;
-               data->current_profile_setting.mclk_activity = 25;
-       } else if (adev->gmc.vram_width == 128) {
-               data->current_profile_setting.mclk_up_hyst = 5;
-               data->current_profile_setting.mclk_down_hyst = 16;
-               data->current_profile_setting.mclk_activity = 20;
-       } else if (adev->gmc.vram_width == 64) {
-               data->current_profile_setting.mclk_up_hyst = 3;
-               data->current_profile_setting.mclk_down_hyst = 16;
-               data->current_profile_setting.mclk_activity = 20;
+       if (hwmgr->chip_id >= CHIP_POLARIS10) {
+               if (adev->gmc.vram_width == 256) {
+                       data->current_profile_setting.mclk_up_hyst = 10;
+                       data->current_profile_setting.mclk_down_hyst = 60;
+                       data->current_profile_setting.mclk_activity = 25;
+               } else if (adev->gmc.vram_width == 128) {
+                       data->current_profile_setting.mclk_up_hyst = 5;
+                       data->current_profile_setting.mclk_down_hyst = 16;
+                       data->current_profile_setting.mclk_activity = 20;
+               } else if (adev->gmc.vram_width == 64) {
+                       data->current_profile_setting.mclk_up_hyst = 3;
+                       data->current_profile_setting.mclk_down_hyst = 16;
+                       data->current_profile_setting.mclk_activity = 20;
+               }
+       } else {
+               data->current_profile_setting.mclk_up_hyst = 0;
+               data->current_profile_setting.mclk_down_hyst = 100;
+               data->current_profile_setting.mclk_activity = SMU7_MCLK_TARGETACTIVITY_DFLT;
        }
        hwmgr->workload_mask = 1 << hwmgr->workload_prority[PP_SMC_POWER_PROFILE_FULLSCREEN3D];
        hwmgr->power_profile_mode = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
index e4d1f3d..329bf4d 100644 (file)
@@ -2726,10 +2726,7 @@ static int ci_initialize_mc_reg_table(struct pp_hwmgr *hwmgr)
 
 static bool ci_is_dpm_running(struct pp_hwmgr *hwmgr)
 {
-       return (1 == PHM_READ_INDIRECT_FIELD(hwmgr->device,
-                                            CGS_IND_REG__SMC, FEATURE_STATUS,
-                                            VOLTAGE_CONTROLLER_ON))
-               ? true : false;
+       return ci_is_smc_ram_running(hwmgr);
 }
 
 static int ci_smu_init(struct pp_hwmgr *hwmgr)
@@ -2939,6 +2936,29 @@ static int ci_update_smc_table(struct pp_hwmgr *hwmgr, uint32_t type)
        return 0;
 }
 
+static void ci_reset_smc(struct pp_hwmgr *hwmgr)
+{
+       PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
+                                 SMC_SYSCON_RESET_CNTL,
+                                 rst_reg, 1);
+}
+
+
+static void ci_stop_smc_clock(struct pp_hwmgr *hwmgr)
+{
+       PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
+                                 SMC_SYSCON_CLOCK_CNTL_0,
+                                 ck_disable, 1);
+}
+
+static int ci_stop_smc(struct pp_hwmgr *hwmgr)
+{
+       ci_reset_smc(hwmgr);
+       ci_stop_smc_clock(hwmgr);
+
+       return 0;
+}
+
 const struct pp_smumgr_func ci_smu_funcs = {
        .name = "ci_smu",
        .smu_init = ci_smu_init,
@@ -2964,4 +2984,5 @@ const struct pp_smumgr_func ci_smu_funcs = {
        .is_dpm_running = ci_is_dpm_running,
        .update_dpm_settings = ci_update_dpm_settings,
        .update_smc_table = ci_update_smc_table,
+       .stop_smc = ci_stop_smc,
 };
index b6fb480..b6921db 100644 (file)
@@ -245,3 +245,11 @@ int smum_smc_table_manager(struct pp_hwmgr *hwmgr, uint8_t *table, uint16_t tabl
 
        return -EINVAL;
 }
+
+int smum_stop_smc(struct pp_hwmgr *hwmgr)
+{
+       if (hwmgr->smumgr_funcs->stop_smc)
+               return hwmgr->smumgr_funcs->stop_smc(hwmgr);
+
+       return 0;
+}
index fc4f95f..b1e5ec0 100644 (file)
@@ -1029,17 +1029,6 @@ static int smu_smc_hw_setup(struct smu_context *smu)
                return ret;
        }
 
-       /*
-        * Set initialized values (get from vbios) to dpm tables context such as
-        * gfxclk, memclk, dcefclk, and etc. And enable the DPM feature for each
-        * type of clks.
-        */
-       ret = smu_set_default_dpm_table(smu);
-       if (ret) {
-               dev_err(adev->dev, "Failed to setup default dpm clock tables!\n");
-               return ret;
-       }
-
        ret = smu_notify_display_change(smu);
        if (ret)
                return ret;
index 511d67b..ef8c230 100644 (file)
@@ -13,7 +13,7 @@ config DRM_CDNS_MHDP8546
 if DRM_CDNS_MHDP8546
 
 config DRM_CDNS_MHDP8546_J721E
-       depends on ARCH_K3_J721E_SOC || COMPILE_TEST
+       depends on ARCH_K3 || COMPILE_TEST
        bool "J721E Cadence DPI/DP wrapper support"
        default y
        help
index 748df1c..0c79a9b 100644 (file)
@@ -2327,12 +2327,6 @@ static enum drm_connector_status dw_hdmi_detect(struct dw_hdmi *hdmi)
 {
        enum drm_connector_status result;
 
-       mutex_lock(&hdmi->mutex);
-       hdmi->force = DRM_FORCE_UNSPECIFIED;
-       dw_hdmi_update_power(hdmi);
-       dw_hdmi_update_phy_mask(hdmi);
-       mutex_unlock(&hdmi->mutex);
-
        result = hdmi->phy.ops->read_hpd(hdmi, hdmi->phy.data);
 
        mutex_lock(&hdmi->mutex);
index 50cad0e..375c79e 100644 (file)
@@ -140,7 +140,7 @@ static void drm_gem_vram_placement(struct drm_gem_vram_object *gbo,
        unsigned int c = 0;
 
        if (pl_flag & DRM_GEM_VRAM_PL_FLAG_TOPDOWN)
-               pl_flag = TTM_PL_FLAG_TOPDOWN;
+               invariant_flags = TTM_PL_FLAG_TOPDOWN;
 
        gbo->placement.placement = gbo->placements;
        gbo->placement.busy_placement = gbo->placements;
index 15eb377..361e3a0 100644 (file)
@@ -347,6 +347,7 @@ int psb_irq_postinstall(struct drm_device *dev)
 {
        struct drm_psb_private *dev_priv = dev->dev_private;
        unsigned long irqflags;
+       unsigned int i;
 
        spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
 
@@ -359,20 +360,12 @@ int psb_irq_postinstall(struct drm_device *dev)
        PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
        PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
 
-       if (dev->vblank[0].enabled)
-               psb_enable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE);
-       else
-               psb_disable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE);
-
-       if (dev->vblank[1].enabled)
-               psb_enable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE);
-       else
-               psb_disable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE);
-
-       if (dev->vblank[2].enabled)
-               psb_enable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE);
-       else
-               psb_disable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE);
+       for (i = 0; i < dev->num_crtcs; ++i) {
+               if (dev->vblank[i].enabled)
+                       psb_enable_pipestat(dev_priv, i, PIPE_VBLANK_INTERRUPT_ENABLE);
+               else
+                       psb_disable_pipestat(dev_priv, i, PIPE_VBLANK_INTERRUPT_ENABLE);
+       }
 
        if (dev_priv->ops->hotplug_enable)
                dev_priv->ops->hotplug_enable(dev, true);
@@ -385,6 +378,7 @@ void psb_irq_uninstall(struct drm_device *dev)
 {
        struct drm_psb_private *dev_priv = dev->dev_private;
        unsigned long irqflags;
+       unsigned int i;
 
        spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
 
@@ -393,14 +387,10 @@ void psb_irq_uninstall(struct drm_device *dev)
 
        PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
 
-       if (dev->vblank[0].enabled)
-               psb_disable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE);
-
-       if (dev->vblank[1].enabled)
-               psb_disable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE);
-
-       if (dev->vblank[2].enabled)
-               psb_disable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE);
+       for (i = 0; i < dev->num_crtcs; ++i) {
+               if (dev->vblank[i].enabled)
+                       psb_disable_pipestat(dev_priv, i, PIPE_VBLANK_INTERRUPT_ENABLE);
+       }
 
        dev_priv->vdc_irq_mask &= _PSB_IRQ_SGX_FLAG |
                                  _PSB_IRQ_MSVDX_FLAG |
index 31337d2..99e6825 100644 (file)
@@ -12878,10 +12878,11 @@ compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
        case 10 ... 11:
                bpp = 10 * 3;
                break;
-       case 12:
+       case 12 ... 16:
                bpp = 12 * 3;
                break;
        default:
+               MISSING_CASE(conn_state->max_bpc);
                return -EINVAL;
        }
 
index 8a9d0bd..40e9cb2 100644 (file)
@@ -1754,7 +1754,7 @@ void intel_psr_atomic_check(struct drm_connector *connector,
                return;
 
        intel_connector = to_intel_connector(connector);
-       dig_port = enc_to_dig_port(intel_attached_encoder(intel_connector));
+       dig_port = enc_to_dig_port(to_intel_encoder(new_state->best_encoder));
        if (dev_priv->psr.dp != &dig_port->dp)
                return;
 
index 7c90a63..fcce690 100644 (file)
@@ -508,21 +508,6 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
        if (!obj)
                return -ENOENT;
 
-       /*
-        * Already in the desired write domain? Nothing for us to do!
-        *
-        * We apply a little bit of cunning here to catch a broader set of
-        * no-ops. If obj->write_domain is set, we must be in the same
-        * obj->read_domains, and only that domain. Therefore, if that
-        * obj->write_domain matches the request read_domains, we are
-        * already in the same read/write domain and can skip the operation,
-        * without having to further check the requested write_domain.
-        */
-       if (READ_ONCE(obj->write_domain) == read_domains) {
-               err = 0;
-               goto out;
-       }
-
        /*
         * Try to flush the object off the GPU without holding the lock.
         * We will repeat the flush holding the lock in the normal manner
@@ -560,6 +545,19 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
        if (err)
                goto out;
 
+       /*
+        * Already in the desired write domain? Nothing for us to do!
+        *
+        * We apply a little bit of cunning here to catch a broader set of
+        * no-ops. If obj->write_domain is set, we must be in the same
+        * obj->read_domains, and only that domain. Therefore, if that
+        * obj->write_domain matches the request read_domains, we are
+        * already in the same read/write domain and can skip the operation,
+        * without having to further check the requested write_domain.
+        */
+       if (READ_ONCE(obj->write_domain) == read_domains)
+               goto out_unpin;
+
        err = i915_gem_object_lock_interruptible(obj, NULL);
        if (err)
                goto out_unpin;
index b5c1555..d6711ca 100644 (file)
@@ -56,6 +56,8 @@ struct drm_i915_gem_object_ops {
        void (*truncate)(struct drm_i915_gem_object *obj);
        void (*writeback)(struct drm_i915_gem_object *obj);
 
+       int (*pread)(struct drm_i915_gem_object *obj,
+                    const struct drm_i915_gem_pread *arg);
        int (*pwrite)(struct drm_i915_gem_object *obj,
                      const struct drm_i915_gem_pwrite *arg);
 
index 28147aa..3a4dfe2 100644 (file)
@@ -134,6 +134,58 @@ i915_gem_object_put_pages_phys(struct drm_i915_gem_object *obj,
                          vaddr, dma);
 }
 
+static int
+phys_pwrite(struct drm_i915_gem_object *obj,
+           const struct drm_i915_gem_pwrite *args)
+{
+       void *vaddr = sg_page(obj->mm.pages->sgl) + args->offset;
+       char __user *user_data = u64_to_user_ptr(args->data_ptr);
+       int err;
+
+       err = i915_gem_object_wait(obj,
+                                  I915_WAIT_INTERRUPTIBLE |
+                                  I915_WAIT_ALL,
+                                  MAX_SCHEDULE_TIMEOUT);
+       if (err)
+               return err;
+
+       /*
+        * We manually control the domain here and pretend that it
+        * remains coherent i.e. in the GTT domain, like shmem_pwrite.
+        */
+       i915_gem_object_invalidate_frontbuffer(obj, ORIGIN_CPU);
+
+       if (copy_from_user(vaddr, user_data, args->size))
+               return -EFAULT;
+
+       drm_clflush_virt_range(vaddr, args->size);
+       intel_gt_chipset_flush(&to_i915(obj->base.dev)->gt);
+
+       i915_gem_object_flush_frontbuffer(obj, ORIGIN_CPU);
+       return 0;
+}
+
+static int
+phys_pread(struct drm_i915_gem_object *obj,
+          const struct drm_i915_gem_pread *args)
+{
+       void *vaddr = sg_page(obj->mm.pages->sgl) + args->offset;
+       char __user *user_data = u64_to_user_ptr(args->data_ptr);
+       int err;
+
+       err = i915_gem_object_wait(obj,
+                                  I915_WAIT_INTERRUPTIBLE,
+                                  MAX_SCHEDULE_TIMEOUT);
+       if (err)
+               return err;
+
+       drm_clflush_virt_range(vaddr, args->size);
+       if (copy_to_user(user_data, vaddr, args->size))
+               return -EFAULT;
+
+       return 0;
+}
+
 static void phys_release(struct drm_i915_gem_object *obj)
 {
        fput(obj->base.filp);
@@ -144,6 +196,9 @@ static const struct drm_i915_gem_object_ops i915_gem_phys_ops = {
        .get_pages = i915_gem_object_get_pages_phys,
        .put_pages = i915_gem_object_put_pages_phys,
 
+       .pread  = phys_pread,
+       .pwrite = phys_pwrite,
+
        .release = phys_release,
 };
 
index 7c3a101..760fefd 100644 (file)
@@ -245,22 +245,14 @@ static inline u32 *gen12_emit_pipe_control(u32 *batch, u32 flags0, u32 flags1, u
 }
 
 static inline u32 *
-__gen8_emit_ggtt_write_rcs(u32 *cs, u32 value, u32 gtt_offset, u32 flags0, u32 flags1)
+__gen8_emit_write_rcs(u32 *cs, u32 value, u32 offset, u32 flags0, u32 flags1)
 {
-       /* We're using qword write, offset should be aligned to 8 bytes. */
-       GEM_BUG_ON(!IS_ALIGNED(gtt_offset, 8));
-
-       /* w/a for post sync ops following a GPGPU operation we
-        * need a prior CS_STALL, which is emitted by the flush
-        * following the batch.
-        */
        *cs++ = GFX_OP_PIPE_CONTROL(6) | flags0;
-       *cs++ = flags1 | PIPE_CONTROL_QW_WRITE | PIPE_CONTROL_GLOBAL_GTT_IVB;
-       *cs++ = gtt_offset;
+       *cs++ = flags1 | PIPE_CONTROL_QW_WRITE;
+       *cs++ = offset;
        *cs++ = 0;
        *cs++ = value;
-       /* We're thrashing one dword of HWS. */
-       *cs++ = 0;
+       *cs++ = 0; /* We're thrashing one extra dword. */
 
        return cs;
 }
@@ -268,13 +260,38 @@ __gen8_emit_ggtt_write_rcs(u32 *cs, u32 value, u32 gtt_offset, u32 flags0, u32 f
 static inline u32*
 gen8_emit_ggtt_write_rcs(u32 *cs, u32 value, u32 gtt_offset, u32 flags)
 {
-       return __gen8_emit_ggtt_write_rcs(cs, value, gtt_offset, 0, flags);
+       /* We're using qword write, offset should be aligned to 8 bytes. */
+       GEM_BUG_ON(!IS_ALIGNED(gtt_offset, 8));
+
+       return __gen8_emit_write_rcs(cs,
+                                    value,
+                                    gtt_offset,
+                                    0,
+                                    flags | PIPE_CONTROL_GLOBAL_GTT_IVB);
 }
 
 static inline u32*
 gen12_emit_ggtt_write_rcs(u32 *cs, u32 value, u32 gtt_offset, u32 flags0, u32 flags1)
 {
-       return __gen8_emit_ggtt_write_rcs(cs, value, gtt_offset, flags0, flags1);
+       /* We're using qword write, offset should be aligned to 8 bytes. */
+       GEM_BUG_ON(!IS_ALIGNED(gtt_offset, 8));
+
+       return __gen8_emit_write_rcs(cs,
+                                    value,
+                                    gtt_offset,
+                                    flags0,
+                                    flags1 | PIPE_CONTROL_GLOBAL_GTT_IVB);
+}
+
+static inline u32 *
+__gen8_emit_flush_dw(u32 *cs, u32 value, u32 gtt_offset, u32 flags)
+{
+       *cs++ = (MI_FLUSH_DW + 1) | flags;
+       *cs++ = gtt_offset;
+       *cs++ = 0;
+       *cs++ = value;
+
+       return cs;
 }
 
 static inline u32 *
@@ -285,12 +302,10 @@ gen8_emit_ggtt_write(u32 *cs, u32 value, u32 gtt_offset, u32 flags)
        /* Offset should be aligned to 8 bytes for both (QW/DW) write types */
        GEM_BUG_ON(!IS_ALIGNED(gtt_offset, 8));
 
-       *cs++ = (MI_FLUSH_DW + 1) | MI_FLUSH_DW_OP_STOREDW | flags;
-       *cs++ = gtt_offset | MI_FLUSH_DW_USE_GTT;
-       *cs++ = 0;
-       *cs++ = value;
-
-       return cs;
+       return __gen8_emit_flush_dw(cs,
+                                   value,
+                                   gtt_offset | MI_FLUSH_DW_USE_GTT,
+                                   flags | MI_FLUSH_DW_OP_STOREDW);
 }
 
 static inline void __intel_engine_reset(struct intel_engine_cs *engine,
index 5bfb5f7..efdeb7b 100644 (file)
@@ -371,7 +371,8 @@ static void __setup_engine_capabilities(struct intel_engine_cs *engine)
                 * instances.
                 */
                if ((INTEL_GEN(i915) >= 11 &&
-                    engine->gt->info.vdbox_sfc_access & engine->mask) ||
+                    (engine->gt->info.vdbox_sfc_access &
+                     BIT(engine->instance))) ||
                    (INTEL_GEN(i915) >= 9 && engine->instance == 0))
                        engine->uabi_capabilities |=
                                I915_VIDEO_AND_ENHANCE_CLASS_CAPABILITY_SFC;
index a32aabc..9bb16bd 100644 (file)
@@ -3547,6 +3547,19 @@ static const struct intel_context_ops execlists_context_ops = {
        .destroy = execlists_context_destroy,
 };
 
+static u32 hwsp_offset(const struct i915_request *rq)
+{
+       const struct intel_timeline_cacheline *cl;
+
+       /* Before the request is executed, the timeline/cachline is fixed */
+
+       cl = rcu_dereference_protected(rq->hwsp_cacheline, 1);
+       if (cl)
+               return cl->ggtt_offset;
+
+       return rcu_dereference_protected(rq->timeline, 1)->hwsp_offset;
+}
+
 static int gen8_emit_init_breadcrumb(struct i915_request *rq)
 {
        u32 *cs;
@@ -3569,7 +3582,7 @@ static int gen8_emit_init_breadcrumb(struct i915_request *rq)
        *cs++ = MI_NOOP;
 
        *cs++ = MI_STORE_DWORD_IMM_GEN4 | MI_USE_GGTT;
-       *cs++ = i915_request_timeline(rq)->hwsp_offset;
+       *cs++ = hwsp_offset(rq);
        *cs++ = 0;
        *cs++ = rq->fence.seqno - 1;
 
@@ -4886,11 +4899,9 @@ gen8_emit_fini_breadcrumb_tail(struct i915_request *request, u32 *cs)
        return gen8_emit_wa_tail(request, cs);
 }
 
-static u32 *emit_xcs_breadcrumb(struct i915_request *request, u32 *cs)
+static u32 *emit_xcs_breadcrumb(struct i915_request *rq, u32 *cs)
 {
-       u32 addr = i915_request_active_timeline(request)->hwsp_offset;
-
-       return gen8_emit_ggtt_write(cs, request->fence.seqno, addr, 0);
+       return gen8_emit_ggtt_write(cs, rq->fence.seqno, hwsp_offset(rq), 0);
 }
 
 static u32 *gen8_emit_fini_breadcrumb(struct i915_request *rq, u32 *cs)
@@ -4909,7 +4920,7 @@ static u32 *gen8_emit_fini_breadcrumb_rcs(struct i915_request *request, u32 *cs)
        /* XXX flush+write+CS_STALL all in one upsets gem_concurrent_blt:kbl */
        cs = gen8_emit_ggtt_write_rcs(cs,
                                      request->fence.seqno,
-                                     i915_request_active_timeline(request)->hwsp_offset,
+                                     hwsp_offset(request),
                                      PIPE_CONTROL_FLUSH_ENABLE |
                                      PIPE_CONTROL_CS_STALL);
 
@@ -4921,7 +4932,7 @@ gen11_emit_fini_breadcrumb_rcs(struct i915_request *request, u32 *cs)
 {
        cs = gen8_emit_ggtt_write_rcs(cs,
                                      request->fence.seqno,
-                                     i915_request_active_timeline(request)->hwsp_offset,
+                                     hwsp_offset(request),
                                      PIPE_CONTROL_CS_STALL |
                                      PIPE_CONTROL_TILE_CACHE_FLUSH |
                                      PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH |
@@ -4983,7 +4994,9 @@ gen12_emit_fini_breadcrumb_tail(struct i915_request *request, u32 *cs)
 
 static u32 *gen12_emit_fini_breadcrumb(struct i915_request *rq, u32 *cs)
 {
-       return gen12_emit_fini_breadcrumb_tail(rq, emit_xcs_breadcrumb(rq, cs));
+       /* XXX Stalling flush before seqno write; post-sync not */
+       cs = emit_xcs_breadcrumb(rq, __gen8_emit_flush_dw(cs, 0, 0, 0));
+       return gen12_emit_fini_breadcrumb_tail(rq, cs);
 }
 
 static u32 *
@@ -4991,7 +5004,7 @@ gen12_emit_fini_breadcrumb_rcs(struct i915_request *request, u32 *cs)
 {
        cs = gen12_emit_ggtt_write_rcs(cs,
                                       request->fence.seqno,
-                                      i915_request_active_timeline(request)->hwsp_offset,
+                                      hwsp_offset(request),
                                       PIPE_CONTROL0_HDC_PIPELINE_FLUSH,
                                       PIPE_CONTROL_CS_STALL |
                                       PIPE_CONTROL_TILE_CACHE_FLUSH |
@@ -5444,6 +5457,7 @@ static void virtual_context_destroy(struct kref *kref)
                __execlists_context_fini(&ve->context);
        intel_context_fini(&ve->context);
 
+       intel_breadcrumbs_free(ve->base.breadcrumbs);
        intel_engine_free_request_pool(&ve->base);
 
        kfree(ve->bonds);
index b8f56e6..313e51e 100644 (file)
@@ -243,8 +243,9 @@ static const struct drm_i915_mocs_entry tgl_mocs_table[] = {
         * only, __init_mocs_table() take care to program unused index with
         * this entry.
         */
-       MOCS_ENTRY(1, LE_3_WB | LE_TC_1_LLC | LE_LRUM(3),
-                  L3_3_WB),
+       MOCS_ENTRY(I915_MOCS_PTE,
+                  LE_0_PAGETABLE | LE_TC_0_PAGETABLE,
+                  L3_1_UC),
        GEN11_MOCS_ENTRIES,
 
        /* Implicitly enable L1 - HDC:L1 + L3 + LLC */
index ab675d3..d7b8e44 100644 (file)
@@ -56,9 +56,12 @@ static inline void set(struct intel_uncore *uncore, i915_reg_t reg, u32 val)
 
 static void gen11_rc6_enable(struct intel_rc6 *rc6)
 {
-       struct intel_uncore *uncore = rc6_to_uncore(rc6);
+       struct intel_gt *gt = rc6_to_gt(rc6);
+       struct intel_uncore *uncore = gt->uncore;
        struct intel_engine_cs *engine;
        enum intel_engine_id id;
+       u32 pg_enable;
+       int i;
 
        /* 2b: Program RC6 thresholds.*/
        set(uncore, GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16 | 85);
@@ -102,10 +105,19 @@ static void gen11_rc6_enable(struct intel_rc6 *rc6)
                GEN6_RC_CTL_RC6_ENABLE |
                GEN6_RC_CTL_EI_MODE(1);
 
-       set(uncore, GEN9_PG_ENABLE,
-           GEN9_RENDER_PG_ENABLE |
-           GEN9_MEDIA_PG_ENABLE |
-           GEN11_MEDIA_SAMPLER_PG_ENABLE);
+       pg_enable =
+               GEN9_RENDER_PG_ENABLE |
+               GEN9_MEDIA_PG_ENABLE |
+               GEN11_MEDIA_SAMPLER_PG_ENABLE;
+
+       if (INTEL_GEN(gt->i915) >= 12) {
+               for (i = 0; i < I915_MAX_VCS; i++)
+                       if (HAS_ENGINE(gt, _VCS(i)))
+                               pg_enable |= (VDN_HCP_POWERGATE_ENABLE(i) |
+                                             VDN_MFX_POWERGATE_ENABLE(i));
+       }
+
+       set(uncore, GEN9_PG_ENABLE, pg_enable);
 }
 
 static void gen9_rc6_enable(struct intel_rc6 *rc6)
index a2f74ce..7ea94d2 100644 (file)
@@ -188,10 +188,14 @@ cacheline_alloc(struct intel_timeline_hwsp *hwsp, unsigned int cacheline)
        return cl;
 }
 
-static void cacheline_acquire(struct intel_timeline_cacheline *cl)
+static void cacheline_acquire(struct intel_timeline_cacheline *cl,
+                             u32 ggtt_offset)
 {
-       if (cl)
-               i915_active_acquire(&cl->active);
+       if (!cl)
+               return;
+
+       cl->ggtt_offset = ggtt_offset;
+       i915_active_acquire(&cl->active);
 }
 
 static void cacheline_release(struct intel_timeline_cacheline *cl)
@@ -340,7 +344,7 @@ int intel_timeline_pin(struct intel_timeline *tl, struct i915_gem_ww_ctx *ww)
        GT_TRACE(tl->gt, "timeline:%llx using HWSP offset:%x\n",
                 tl->fence_context, tl->hwsp_offset);
 
-       cacheline_acquire(tl->hwsp_cacheline);
+       cacheline_acquire(tl->hwsp_cacheline, tl->hwsp_offset);
        if (atomic_fetch_inc(&tl->pin_count)) {
                cacheline_release(tl->hwsp_cacheline);
                __i915_vma_unpin(tl->hwsp_ggtt);
@@ -515,7 +519,7 @@ __intel_timeline_get_seqno(struct intel_timeline *tl,
        GT_TRACE(tl->gt, "timeline:%llx using HWSP offset:%x\n",
                 tl->fence_context, tl->hwsp_offset);
 
-       cacheline_acquire(cl);
+       cacheline_acquire(cl, tl->hwsp_offset);
        tl->hwsp_cacheline = cl;
 
        *seqno = timeline_advance(tl);
@@ -573,9 +577,7 @@ int intel_timeline_read_hwsp(struct i915_request *from,
        if (err)
                goto out;
 
-       *hwsp = i915_ggtt_offset(cl->hwsp->vma) +
-               ptr_unmask_bits(cl->vaddr, CACHELINE_BITS) * CACHELINE_BYTES;
-
+       *hwsp = cl->ggtt_offset;
 out:
        i915_active_release(&cl->active);
        return err;
index 02181c5..4474f48 100644 (file)
@@ -94,6 +94,8 @@ struct intel_timeline_cacheline {
        struct intel_timeline_hwsp *hwsp;
        void *vaddr;
 
+       u32 ggtt_offset;
+
        struct rcu_head rcu;
 };
 
index 6c580d0..4a3bde7 100644 (file)
@@ -131,8 +131,10 @@ static void _wa_add(struct i915_wa_list *wal, const struct i915_wa *wa)
                        return;
                }
 
-               if (wal->list)
+               if (wal->list) {
                        memcpy(list, wal->list, sizeof(*wa) * wal->count);
+                       kfree(wal->list);
+               }
 
                wal->list = list;
        }
index 7ba16dd..d7898e8 100644 (file)
@@ -164,7 +164,7 @@ static unsigned char virtual_dp_monitor_edid[GVT_EDID_NUM][EDID_SIZE] = {
 
 /* let the virtual display supports DP1.2 */
 static u8 dpcd_fix_data[DPCD_HEADER_SIZE] = {
-       0x12, 0x014, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+       0x12, 0x014, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 };
 
 static void emulate_monitor_status_change(struct intel_vgpu *vgpu)
index 3be37e6..eb342a7 100644 (file)
@@ -1489,7 +1489,8 @@ static int hws_pga_write(struct intel_vgpu *vgpu, unsigned int offset,
        const struct intel_engine_cs *engine =
                intel_gvt_render_mmio_to_engine(vgpu->gvt, offset);
 
-       if (!intel_gvt_ggtt_validate_range(vgpu, value, I915_GTT_PAGE_SIZE)) {
+       if (value != 0 &&
+           !intel_gvt_ggtt_validate_range(vgpu, value, I915_GTT_PAGE_SIZE)) {
                gvt_vgpu_err("write invalid HWSP address, reg:0x%x, value:0x%x\n",
                              offset, value);
                return -EINVAL;
@@ -1650,6 +1651,34 @@ static int edp_psr_imr_iir_write(struct intel_vgpu *vgpu,
        return 0;
 }
 
+/**
+ * FixMe:
+ * If guest fills non-priv batch buffer on ApolloLake/Broxton as Mesa i965 did:
+ * 717e7539124d (i965: Use a WC map and memcpy for the batch instead of pwrite.)
+ * Due to the missing flush of bb filled by VM vCPU, host GPU hangs on executing
+ * these MI_BATCH_BUFFER.
+ * Temporarily workaround this by setting SNOOP bit for PAT3 used by PPGTT
+ * PML4 PTE: PAT(0) PCD(1) PWT(1).
+ * The performance is still expected to be low, will need further improvement.
+ */
+static int bxt_ppat_low_write(struct intel_vgpu *vgpu, unsigned int offset,
+                             void *p_data, unsigned int bytes)
+{
+       u64 pat =
+               GEN8_PPAT(0, CHV_PPAT_SNOOP) |
+               GEN8_PPAT(1, 0) |
+               GEN8_PPAT(2, 0) |
+               GEN8_PPAT(3, CHV_PPAT_SNOOP) |
+               GEN8_PPAT(4, CHV_PPAT_SNOOP) |
+               GEN8_PPAT(5, CHV_PPAT_SNOOP) |
+               GEN8_PPAT(6, CHV_PPAT_SNOOP) |
+               GEN8_PPAT(7, CHV_PPAT_SNOOP);
+
+       vgpu_vreg(vgpu, offset) = lower_32_bits(pat);
+
+       return 0;
+}
+
 static int guc_status_read(struct intel_vgpu *vgpu,
                           unsigned int offset, void *p_data,
                           unsigned int bytes)
@@ -2812,7 +2841,7 @@ static int init_bdw_mmio_info(struct intel_gvt *gvt)
 
        MMIO_DH(GEN6_PCODE_MAILBOX, D_BDW_PLUS, NULL, mailbox_write);
 
-       MMIO_D(GEN8_PRIVATE_PAT_LO, D_BDW_PLUS);
+       MMIO_D(GEN8_PRIVATE_PAT_LO, D_BDW_PLUS & ~D_BXT);
        MMIO_D(GEN8_PRIVATE_PAT_HI, D_BDW_PLUS);
 
        MMIO_D(GAMTARBMODE, D_BDW_PLUS);
@@ -3139,7 +3168,7 @@ static int init_skl_mmio_info(struct intel_gvt *gvt)
                 NULL, NULL);
 
        MMIO_DFH(GAMT_CHKN_BIT_REG, D_KBL | D_CFL, F_CMD_ACCESS, NULL, NULL);
-       MMIO_D(GEN9_CTX_PREEMPT_REG, D_SKL_PLUS);
+       MMIO_D(GEN9_CTX_PREEMPT_REG, D_SKL_PLUS & ~D_BXT);
 
        return 0;
 }
@@ -3313,9 +3342,21 @@ static int init_bxt_mmio_info(struct intel_gvt *gvt)
        MMIO_D(GEN8_PUSHBUS_SHIFT, D_BXT);
        MMIO_D(GEN6_GFXPAUSE, D_BXT);
        MMIO_DFH(GEN8_L3SQCREG1, D_BXT, F_CMD_ACCESS, NULL, NULL);
+       MMIO_DFH(GEN8_L3CNTLREG, D_BXT, F_CMD_ACCESS, NULL, NULL);
+       MMIO_DFH(_MMIO(0x20D8), D_BXT, F_CMD_ACCESS, NULL, NULL);
+       MMIO_F(GEN8_RING_CS_GPR(RENDER_RING_BASE, 0), 0x40, F_CMD_ACCESS,
+              0, 0, D_BXT, NULL, NULL);
+       MMIO_F(GEN8_RING_CS_GPR(GEN6_BSD_RING_BASE, 0), 0x40, F_CMD_ACCESS,
+              0, 0, D_BXT, NULL, NULL);
+       MMIO_F(GEN8_RING_CS_GPR(BLT_RING_BASE, 0), 0x40, F_CMD_ACCESS,
+              0, 0, D_BXT, NULL, NULL);
+       MMIO_F(GEN8_RING_CS_GPR(VEBOX_RING_BASE, 0), 0x40, F_CMD_ACCESS,
+              0, 0, D_BXT, NULL, NULL);
 
        MMIO_DFH(GEN9_CTX_PREEMPT_REG, D_BXT, F_CMD_ACCESS, NULL, NULL);
 
+       MMIO_DH(GEN8_PRIVATE_PAT_LO, D_BXT, NULL, bxt_ppat_low_write);
+
        return 0;
 }
 
index ad8a9df..778eb8c 100644 (file)
@@ -829,8 +829,10 @@ static int intel_vgpu_open(struct mdev_device *mdev)
        /* Take a module reference as mdev core doesn't take
         * a reference for vendor driver.
         */
-       if (!try_module_get(THIS_MODULE))
+       if (!try_module_get(THIS_MODULE)) {
+               ret = -ENODEV;
                goto undo_group;
+       }
 
        ret = kvmgt_guest_init(mdev);
        if (ret)
index 1570eb8..aed2ef6 100644 (file)
@@ -1277,7 +1277,7 @@ void intel_vgpu_clean_submission(struct intel_vgpu *vgpu)
 
        i915_context_ppgtt_root_restore(s, i915_vm_to_ppgtt(s->shadow[0]->vm));
        for_each_engine(engine, vgpu->gvt->gt, id)
-               intel_context_unpin(s->shadow[id]);
+               intel_context_put(s->shadow[id]);
 
        kmem_cache_destroy(s->workloads);
 }
@@ -1369,11 +1369,6 @@ int intel_vgpu_setup_submission(struct intel_vgpu *vgpu)
                        ce->ring = __intel_context_ring_size(ring_size);
                }
 
-               ret = intel_context_pin(ce);
-               intel_context_put(ce);
-               if (ret)
-                       goto out_shadow_ctx;
-
                s->shadow[i] = ce;
        }
 
@@ -1405,7 +1400,6 @@ out_shadow_ctx:
                if (IS_ERR(s->shadow[i]))
                        break;
 
-               intel_context_unpin(s->shadow[i]);
                intel_context_put(s->shadow[i]);
        }
        i915_vm_put(&ppgtt->vm);
@@ -1479,6 +1473,7 @@ void intel_vgpu_destroy_workload(struct intel_vgpu_workload *workload)
 {
        struct intel_vgpu_submission *s = &workload->vgpu->submission;
 
+       intel_context_unpin(s->shadow[workload->engine->id]);
        release_shadow_batch_buffer(workload);
        release_shadow_wa_ctx(&workload->wa_ctx);
 
@@ -1724,6 +1719,12 @@ intel_vgpu_create_workload(struct intel_vgpu *vgpu,
                return ERR_PTR(ret);
        }
 
+       ret = intel_context_pin(s->shadow[engine->id]);
+       if (ret) {
+               intel_vgpu_destroy_workload(workload);
+               return ERR_PTR(ret);
+       }
+
        return workload;
 }
 
index f6d7e33..399582a 100644 (file)
@@ -439,7 +439,8 @@ static struct intel_vgpu *__intel_gvt_create_vgpu(struct intel_gvt *gvt,
 
        if (IS_BROADWELL(dev_priv))
                ret = intel_gvt_hypervisor_set_edid(vgpu, PORT_B);
-       else
+       /* FixMe: Re-enable APL/BXT once vfio_edid enabled */
+       else if (!IS_BROXTON(dev_priv))
                ret = intel_gvt_hypervisor_set_edid(vgpu, PORT_D);
        if (ret)
                goto out_clean_sched_policy;
index bb0c129..5827669 100644 (file)
@@ -179,30 +179,6 @@ try_again:
        return ret;
 }
 
-static int
-i915_gem_phys_pwrite(struct drm_i915_gem_object *obj,
-                    struct drm_i915_gem_pwrite *args,
-                    struct drm_file *file)
-{
-       void *vaddr = sg_page(obj->mm.pages->sgl) + args->offset;
-       char __user *user_data = u64_to_user_ptr(args->data_ptr);
-
-       /*
-        * We manually control the domain here and pretend that it
-        * remains coherent i.e. in the GTT domain, like shmem_pwrite.
-        */
-       i915_gem_object_invalidate_frontbuffer(obj, ORIGIN_CPU);
-
-       if (copy_from_user(vaddr, user_data, args->size))
-               return -EFAULT;
-
-       drm_clflush_virt_range(vaddr, args->size);
-       intel_gt_chipset_flush(&to_i915(obj->base.dev)->gt);
-
-       i915_gem_object_flush_frontbuffer(obj, ORIGIN_CPU);
-       return 0;
-}
-
 static int
 i915_gem_create(struct drm_file *file,
                struct intel_memory_region *mr,
@@ -527,6 +503,12 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
 
        trace_i915_gem_object_pread(obj, args->offset, args->size);
 
+       ret = -ENODEV;
+       if (obj->ops->pread)
+               ret = obj->ops->pread(obj, args);
+       if (ret != -ENODEV)
+               goto out;
+
        ret = i915_gem_object_wait(obj,
                                   I915_WAIT_INTERRUPTIBLE,
                                   MAX_SCHEDULE_TIMEOUT);
@@ -866,8 +848,6 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
        if (ret == -EFAULT || ret == -ENOSPC) {
                if (i915_gem_object_has_struct_page(obj))
                        ret = i915_gem_shmem_pwrite(obj, args);
-               else
-                       ret = i915_gem_phys_pwrite(obj, args, file);
        }
 
        i915_gem_object_unpin_pages(obj);
index d805d4d..664f3bf 100644 (file)
@@ -8971,10 +8971,6 @@ enum {
 #define   GEN9_PWRGT_MEDIA_STATUS_MASK         (1 << 0)
 #define   GEN9_PWRGT_RENDER_STATUS_MASK                (1 << 1)
 
-#define POWERGATE_ENABLE                       _MMIO(0xa210)
-#define    VDN_HCP_POWERGATE_ENABLE(n)         BIT(((n) * 2) + 3)
-#define    VDN_MFX_POWERGATE_ENABLE(n)         BIT(((n) * 2) + 4)
-
 #define  GTFIFODBG                             _MMIO(0x120000)
 #define    GT_FIFO_SBDEDICATE_FREE_ENTRY_CHV   (0x1f << 20)
 #define    GT_FIFO_FREE_ENTRIES_CHV            (0x7f << 13)
@@ -9114,9 +9110,11 @@ enum {
 #define GEN9_MEDIA_PG_IDLE_HYSTERESIS          _MMIO(0xA0C4)
 #define GEN9_RENDER_PG_IDLE_HYSTERESIS         _MMIO(0xA0C8)
 #define GEN9_PG_ENABLE                         _MMIO(0xA210)
-#define GEN9_RENDER_PG_ENABLE                  REG_BIT(0)
-#define GEN9_MEDIA_PG_ENABLE                   REG_BIT(1)
-#define GEN11_MEDIA_SAMPLER_PG_ENABLE          REG_BIT(2)
+#define   GEN9_RENDER_PG_ENABLE                        REG_BIT(0)
+#define   GEN9_MEDIA_PG_ENABLE                 REG_BIT(1)
+#define   GEN11_MEDIA_SAMPLER_PG_ENABLE                REG_BIT(2)
+#define   VDN_HCP_POWERGATE_ENABLE(n)          REG_BIT(3 + 2 * (n))
+#define   VDN_MFX_POWERGATE_ENABLE(n)          REG_BIT(4 + 2 * (n))
 #define GEN8_PUSHBUS_CONTROL                   _MMIO(0xA248)
 #define GEN8_PUSHBUS_ENABLE                    _MMIO(0xA250)
 #define GEN8_PUSHBUS_SHIFT                     _MMIO(0xA25C)
index ffb5287..caa9b04 100644 (file)
@@ -314,8 +314,10 @@ static void __vma_release(struct dma_fence_work *work)
 {
        struct i915_vma_work *vw = container_of(work, typeof(*vw), base);
 
-       if (vw->pinned)
+       if (vw->pinned) {
                __i915_gem_object_unpin_pages(vw->pinned);
+               i915_gem_object_put(vw->pinned);
+       }
 
        i915_vm_free_pt_stash(vw->vm, &vw->stash);
        i915_vm_put(vw->vm);
@@ -431,7 +433,7 @@ int i915_vma_bind(struct i915_vma *vma,
 
                if (vma->obj) {
                        __i915_gem_object_pin_pages(vma->obj);
-                       work->pinned = vma->obj;
+                       work->pinned = i915_gem_object_get(vma->obj);
                }
        } else {
                vma->ops->bind_vma(vma->vm, NULL, vma, cache_level, bind_flags);
index 34e0d22..cfb8067 100644 (file)
@@ -7118,23 +7118,10 @@ static void icl_init_clock_gating(struct drm_i915_private *dev_priv)
 
 static void tgl_init_clock_gating(struct drm_i915_private *dev_priv)
 {
-       u32 vd_pg_enable = 0;
-       unsigned int i;
-
        /* Wa_1409120013:tgl */
        I915_WRITE(ILK_DPFC_CHICKEN,
                   ILK_DPFC_CHICKEN_COMP_DUMMY_PIXEL);
 
-       /* This is not a WA. Enable VD HCP & MFX_ENC powergate */
-       for (i = 0; i < I915_MAX_VCS; i++) {
-               if (HAS_ENGINE(&dev_priv->gt, _VCS(i)))
-                       vd_pg_enable |= VDN_HCP_POWERGATE_ENABLE(i) |
-                                       VDN_MFX_POWERGATE_ENABLE(i);
-       }
-
-       I915_WRITE(POWERGATE_ENABLE,
-                  I915_READ(POWERGATE_ENABLE) | vd_pg_enable);
-
        /* Wa_1409825376:tgl (pre-prod)*/
        if (IS_TGL_DISP_REVID(dev_priv, TGL_REVID_A0, TGL_REVID_B1))
                I915_WRITE(GEN9_CLKGATE_DIS_3, I915_READ(GEN9_CLKGATE_DIS_3) |
index 64bbb82..e424a6d 100644 (file)
@@ -2293,8 +2293,10 @@ static int perf_request_latency(void *arg)
                struct intel_context *ce;
 
                ce = intel_context_create(engine);
-               if (IS_ERR(ce))
+               if (IS_ERR(ce)) {
+                       err = PTR_ERR(ce);
                        goto out;
+               }
 
                err = intel_context_pin(ce);
                if (err) {
@@ -2467,8 +2469,10 @@ static int perf_series_engines(void *arg)
                struct intel_context *ce;
 
                ce = intel_context_create(engine);
-               if (IS_ERR(ce))
+               if (IS_ERR(ce)) {
+                       err = PTR_ERR(ce);
                        goto out;
+               }
 
                err = intel_context_pin(ce);
                if (err) {
index 71d84c7..d07b39b 100644 (file)
@@ -111,10 +111,6 @@ static int dw_hdmi_imx_parse_dt(struct imx_hdmi *hdmi)
        return 0;
 }
 
-static void dw_hdmi_imx_encoder_disable(struct drm_encoder *encoder)
-{
-}
-
 static void dw_hdmi_imx_encoder_enable(struct drm_encoder *encoder)
 {
        struct imx_hdmi *hdmi = enc_to_imx_hdmi(encoder);
@@ -140,7 +136,6 @@ static int dw_hdmi_imx_atomic_check(struct drm_encoder *encoder,
 
 static const struct drm_encoder_helper_funcs dw_hdmi_imx_encoder_helper_funcs = {
        .enable     = dw_hdmi_imx_encoder_enable,
-       .disable    = dw_hdmi_imx_encoder_disable,
        .atomic_check = dw_hdmi_imx_atomic_check,
 };
 
@@ -219,15 +214,9 @@ static int dw_hdmi_imx_bind(struct device *dev, struct device *master,
        hdmi->dev = &pdev->dev;
        encoder = &hdmi->encoder;
 
-       encoder->possible_crtcs = drm_of_find_possible_crtcs(drm, dev->of_node);
-       /*
-        * If we failed to find the CRTC(s) which this encoder is
-        * supposed to be connected to, it's because the CRTC has
-        * not been registered yet.  Defer probing, and hope that
-        * the required CRTC is added later.
-        */
-       if (encoder->possible_crtcs == 0)
-               return -EPROBE_DEFER;
+       ret = imx_drm_encoder_parse_of(drm, encoder, dev->of_node);
+       if (ret)
+               return ret;
 
        ret = dw_hdmi_imx_parse_dt(hdmi);
        if (ret < 0)
index 7d00c49..9bf5ad6 100644 (file)
@@ -20,6 +20,7 @@
 #include <drm/drm_fb_helper.h>
 #include <drm/drm_gem_cma_helper.h>
 #include <drm/drm_gem_framebuffer_helper.h>
+#include <drm/drm_managed.h>
 #include <drm/drm_of.h>
 #include <drm/drm_plane_helper.h>
 #include <drm/drm_probe_helper.h>
@@ -212,7 +213,9 @@ static int imx_drm_bind(struct device *dev)
        drm->mode_config.allow_fb_modifiers = true;
        drm->mode_config.normalize_zpos = true;
 
-       drm_mode_config_init(drm);
+       ret = drmm_mode_config_init(drm);
+       if (ret)
+               return ret;
 
        ret = drm_vblank_init(drm, MAX_CRTC);
        if (ret)
@@ -251,7 +254,6 @@ err_poll_fini:
        drm_kms_helper_poll_fini(drm);
        component_unbind_all(drm->dev, drm);
 err_kms:
-       drm_mode_config_cleanup(drm);
        drm_dev_put(drm);
 
        return ret;
@@ -267,11 +269,9 @@ static void imx_drm_unbind(struct device *dev)
 
        component_unbind_all(drm->dev, drm);
 
-       drm_mode_config_cleanup(drm);
+       drm_dev_put(drm);
 
        dev_set_drvdata(dev, NULL);
-
-       drm_dev_put(drm);
 }
 
 static const struct component_master_ops imx_drm_ops = {
index af757d1..41e2978 100644 (file)
@@ -62,7 +62,6 @@ struct imx_ldb_channel {
        struct i2c_adapter *ddc;
        int chno;
        void *edid;
-       int edid_len;
        struct drm_display_mode mode;
        int mode_valid;
        u32 bus_format;
@@ -536,15 +535,14 @@ static int imx_ldb_panel_ddc(struct device *dev,
        }
 
        if (!channel->ddc) {
+               int edid_len;
+
                /* if no DDC available, fallback to hardcoded EDID */
                dev_dbg(dev, "no ddc available\n");
 
-               edidp = of_get_property(child, "edid",
-                                       &channel->edid_len);
+               edidp = of_get_property(child, "edid", &edid_len);
                if (edidp) {
-                       channel->edid = kmemdup(edidp,
-                                               channel->edid_len,
-                                               GFP_KERNEL);
+                       channel->edid = kmemdup(edidp, edid_len, GFP_KERNEL);
                } else if (!channel->panel) {
                        /* fallback to display-timings node */
                        ret = of_get_drm_display_mode(child,
index 813bb61..2a8d2e3 100644 (file)
@@ -13,7 +13,6 @@
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
-#include <linux/spinlock.h>
 #include <linux/videodev2.h>
 
 #include <video/imx-ipu-v3.h>
@@ -104,8 +103,6 @@ struct imx_tve {
        struct drm_connector connector;
        struct drm_encoder encoder;
        struct device *dev;
-       spinlock_t lock;        /* register lock */
-       bool enabled;
        int mode;
        int di_hsync_pin;
        int di_vsync_pin;
@@ -129,30 +126,10 @@ static inline struct imx_tve *enc_to_tve(struct drm_encoder *e)
        return container_of(e, struct imx_tve, encoder);
 }
 
-static void tve_lock(void *__tve)
-__acquires(&tve->lock)
-{
-       struct imx_tve *tve = __tve;
-
-       spin_lock(&tve->lock);
-}
-
-static void tve_unlock(void *__tve)
-__releases(&tve->lock)
-{
-       struct imx_tve *tve = __tve;
-
-       spin_unlock(&tve->lock);
-}
-
 static void tve_enable(struct imx_tve *tve)
 {
-       if (!tve->enabled) {
-               tve->enabled = true;
-               clk_prepare_enable(tve->clk);
-               regmap_update_bits(tve->regmap, TVE_COM_CONF_REG,
-                                  TVE_EN, TVE_EN);
-       }
+       clk_prepare_enable(tve->clk);
+       regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, TVE_EN, TVE_EN);
 
        /* clear interrupt status register */
        regmap_write(tve->regmap, TVE_STAT_REG, 0xffffffff);
@@ -169,11 +146,8 @@ static void tve_enable(struct imx_tve *tve)
 
 static void tve_disable(struct imx_tve *tve)
 {
-       if (tve->enabled) {
-               tve->enabled = false;
-               regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, TVE_EN, 0);
-               clk_disable_unprepare(tve->clk);
-       }
+       regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, TVE_EN, 0);
+       clk_disable_unprepare(tve->clk);
 }
 
 static int tve_setup_tvout(struct imx_tve *tve)
@@ -500,8 +474,7 @@ static struct regmap_config tve_regmap_config = {
 
        .readable_reg = imx_tve_readable_reg,
 
-       .lock = tve_lock,
-       .unlock = tve_unlock,
+       .fast_io = true,
 
        .max_register = 0xdc,
 };
@@ -511,7 +484,7 @@ static const char * const imx_tve_modes[] = {
        [TVE_MODE_VGA] = "vga",
 };
 
-static const int of_get_tve_mode(struct device_node *np)
+static int of_get_tve_mode(struct device_node *np)
 {
        const char *bm;
        int ret, i;
@@ -544,7 +517,6 @@ static int imx_tve_bind(struct device *dev, struct device *master, void *data)
        memset(tve, 0, sizeof(*tve));
 
        tve->dev = dev;
-       spin_lock_init(&tve->lock);
 
        ddc_node = of_parse_phandle(np, "ddc-i2c-bus", 0);
        if (ddc_node) {
index 8232f51..2eb8df4 100644 (file)
@@ -28,7 +28,6 @@ struct imx_parallel_display {
        struct drm_bridge bridge;
        struct device *dev;
        void *edid;
-       int edid_len;
        u32 bus_format;
        u32 bus_flags;
        struct drm_display_mode mode;
@@ -41,11 +40,6 @@ static inline struct imx_parallel_display *con_to_imxpd(struct drm_connector *c)
        return container_of(c, struct imx_parallel_display, connector);
 }
 
-static inline struct imx_parallel_display *enc_to_imxpd(struct drm_encoder *e)
-{
-       return container_of(e, struct imx_parallel_display, encoder);
-}
-
 static inline struct imx_parallel_display *bridge_to_imxpd(struct drm_bridge *b)
 {
        return container_of(b, struct imx_parallel_display, bridge);
@@ -310,6 +304,7 @@ static int imx_pd_bind(struct device *dev, struct device *master, void *data)
        struct device_node *np = dev->of_node;
        const u8 *edidp;
        struct imx_parallel_display *imxpd;
+       int edid_len;
        int ret;
        u32 bus_format = 0;
        const char *fmt;
@@ -323,9 +318,9 @@ static int imx_pd_bind(struct device *dev, struct device *master, void *data)
        if (ret && ret != -ENODEV)
                return ret;
 
-       edidp = of_get_property(np, "edid", &imxpd->edid_len);
+       edidp = of_get_property(np, "edid", &edid_len);
        if (edidp)
-               imxpd->edid = kmemdup(edidp, imxpd->edid_len, GFP_KERNEL);
+               imxpd->edid = devm_kmemdup(dev, edidp, edid_len, GFP_KERNEL);
 
        ret = of_property_read_string(np, "interface-pix-fmt", &fmt);
        if (!ret) {
@@ -349,17 +344,8 @@ static int imx_pd_bind(struct device *dev, struct device *master, void *data)
        return 0;
 }
 
-static void imx_pd_unbind(struct device *dev, struct device *master,
-       void *data)
-{
-       struct imx_parallel_display *imxpd = dev_get_drvdata(dev);
-
-       kfree(imxpd->edid);
-}
-
 static const struct component_ops imx_pd_ops = {
        .bind   = imx_pd_bind,
-       .unbind = imx_pd_unbind,
 };
 
 static int imx_pd_probe(struct platform_device *pdev)
index c592957..92f8bd9 100644 (file)
@@ -413,7 +413,13 @@ static int mcde_probe(struct platform_device *pdev)
                                              match);
        if (ret) {
                dev_err(dev, "failed to add component master\n");
-               goto clk_disable;
+               /*
+                * The EPOD regulator is already disabled at this point so some
+                * special errorpath code is needed
+                */
+               clk_disable_unprepare(mcde->mcde_clk);
+               regulator_disable(mcde->vana);
+               return ret;
        }
 
        return 0;
index b111fe2..36d6b60 100644 (file)
@@ -455,7 +455,7 @@ nv50_outp_get_old_connector(struct nouveau_encoder *outp,
  * DAC
  *****************************************************************************/
 static void
-nv50_dac_disable(struct drm_encoder *encoder)
+nv50_dac_disable(struct drm_encoder *encoder, struct drm_atomic_state *state)
 {
        struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
        struct nv50_core *core = nv50_disp(encoder->dev)->core;
@@ -467,7 +467,7 @@ nv50_dac_disable(struct drm_encoder *encoder)
 }
 
 static void
-nv50_dac_enable(struct drm_encoder *encoder)
+nv50_dac_enable(struct drm_encoder *encoder, struct drm_atomic_state *state)
 {
        struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
        struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
@@ -525,8 +525,8 @@ nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
 static const struct drm_encoder_helper_funcs
 nv50_dac_help = {
        .atomic_check = nv50_outp_atomic_check,
-       .enable = nv50_dac_enable,
-       .disable = nv50_dac_disable,
+       .atomic_enable = nv50_dac_enable,
+       .atomic_disable = nv50_dac_disable,
        .detect = nv50_dac_detect
 };
 
@@ -1055,7 +1055,7 @@ nv50_dp_bpc_to_depth(unsigned int bpc)
 }
 
 static void
-nv50_msto_enable(struct drm_encoder *encoder)
+nv50_msto_enable(struct drm_encoder *encoder, struct drm_atomic_state *state)
 {
        struct nv50_head *head = nv50_head(encoder->crtc);
        struct nv50_head_atom *armh = nv50_head_atom(head->base.base.state);
@@ -1101,7 +1101,7 @@ nv50_msto_enable(struct drm_encoder *encoder)
 }
 
 static void
-nv50_msto_disable(struct drm_encoder *encoder)
+nv50_msto_disable(struct drm_encoder *encoder, struct drm_atomic_state *state)
 {
        struct nv50_msto *msto = nv50_msto(encoder);
        struct nv50_mstc *mstc = msto->mstc;
@@ -1118,8 +1118,8 @@ nv50_msto_disable(struct drm_encoder *encoder)
 
 static const struct drm_encoder_helper_funcs
 nv50_msto_help = {
-       .disable = nv50_msto_disable,
-       .enable = nv50_msto_enable,
+       .atomic_disable = nv50_msto_disable,
+       .atomic_enable = nv50_msto_enable,
        .atomic_check = nv50_msto_atomic_check,
 };
 
@@ -1645,8 +1645,7 @@ nv50_sor_disable(struct drm_encoder *encoder,
 }
 
 static void
-nv50_sor_enable(struct drm_encoder *encoder,
-               struct drm_atomic_state *state)
+nv50_sor_enable(struct drm_encoder *encoder, struct drm_atomic_state *state)
 {
        struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
        struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
@@ -1873,7 +1872,7 @@ nv50_pior_atomic_check(struct drm_encoder *encoder,
 }
 
 static void
-nv50_pior_disable(struct drm_encoder *encoder)
+nv50_pior_disable(struct drm_encoder *encoder, struct drm_atomic_state *state)
 {
        struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
        struct nv50_core *core = nv50_disp(encoder->dev)->core;
@@ -1885,7 +1884,7 @@ nv50_pior_disable(struct drm_encoder *encoder)
 }
 
 static void
-nv50_pior_enable(struct drm_encoder *encoder)
+nv50_pior_enable(struct drm_encoder *encoder, struct drm_atomic_state *state)
 {
        struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
        struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
@@ -1921,14 +1920,14 @@ nv50_pior_enable(struct drm_encoder *encoder)
        }
 
        core->func->pior->ctrl(core, nv_encoder->or, ctrl, asyh);
-       nv_encoder->crtc = encoder->crtc;
+       nv_encoder->crtc = &nv_crtc->base;
 }
 
 static const struct drm_encoder_helper_funcs
 nv50_pior_help = {
        .atomic_check = nv50_pior_atomic_check,
-       .enable = nv50_pior_enable,
-       .disable = nv50_pior_disable,
+       .atomic_enable = nv50_pior_enable,
+       .atomic_disable = nv50_pior_disable,
 };
 
 static void
index 2ee7564..56b335a 100644 (file)
@@ -350,14 +350,13 @@ set_placement_list(struct nouveau_drm *drm, struct ttm_place *pl, unsigned *n,
 
        if (domain & NOUVEAU_GEM_DOMAIN_VRAM) {
                struct nvif_mmu *mmu = &drm->client.mmu;
-               const u8 type = mmu->type[drm->ttm.type_vram].type;
 
                pl[*n].mem_type = TTM_PL_VRAM;
                pl[*n].flags = flags & ~TTM_PL_FLAG_CACHED;
 
                /* Some BARs do not support being ioremapped WC */
                if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA &&
-                   type & NVIF_MEM_UNCACHED)
+                   mmu->type[drm->ttm.type_vram].type & NVIF_MEM_UNCACHED)
                        pl[*n].flags &= ~TTM_PL_FLAG_WC;
 
                (*n)++;
index 6f21f36..8b4b368 100644 (file)
@@ -532,11 +532,13 @@ static void
 nouveau_connector_set_edid(struct nouveau_connector *nv_connector,
                           struct edid *edid)
 {
-       struct edid *old_edid = nv_connector->edid;
+       if (nv_connector->edid != edid) {
+               struct edid *old_edid = nv_connector->edid;
 
-       drm_connector_update_edid_property(&nv_connector->base, edid);
-       kfree(old_edid);
-       nv_connector->edid = edid;
+               drm_connector_update_edid_property(&nv_connector->base, edid);
+               kfree(old_edid);
+               nv_connector->edid = edid;
+       }
 }
 
 static enum drm_connector_status
@@ -669,8 +671,10 @@ nouveau_connector_detect_lvds(struct drm_connector *connector, bool force)
        /* Try retrieving EDID via DDC */
        if (!drm->vbios.fp_no_ddc) {
                status = nouveau_connector_detect(connector, force);
-               if (status == connector_status_connected)
+               if (status == connector_status_connected) {
+                       edid = nv_connector->edid;
                        goto out;
+               }
        }
 
        /* On some laptops (Sony, i'm looking at you) there appears to
index 37d4cb7..0fc0841 100644 (file)
@@ -626,6 +626,7 @@ static int panfrost_probe(struct platform_device *pdev)
 err_out1:
        pm_runtime_disable(pfdev->dev);
        panfrost_device_fini(pfdev);
+       pm_runtime_set_suspended(pfdev->dev);
 err_out0:
        drm_dev_put(ddev);
        return err;
@@ -640,9 +641,9 @@ static int panfrost_remove(struct platform_device *pdev)
        panfrost_gem_shrinker_cleanup(ddev);
 
        pm_runtime_get_sync(pfdev->dev);
-       panfrost_device_fini(pfdev);
-       pm_runtime_put_sync_suspend(pfdev->dev);
        pm_runtime_disable(pfdev->dev);
+       panfrost_device_fini(pfdev);
+       pm_runtime_set_suspended(pfdev->dev);
 
        drm_dev_put(ddev);
        return 0;
index 1a6cea0..62d4d71 100644 (file)
@@ -105,14 +105,12 @@ void panfrost_gem_mapping_put(struct panfrost_gem_mapping *mapping)
        kref_put(&mapping->refcount, panfrost_gem_mapping_release);
 }
 
-void panfrost_gem_teardown_mappings(struct panfrost_gem_object *bo)
+void panfrost_gem_teardown_mappings_locked(struct panfrost_gem_object *bo)
 {
        struct panfrost_gem_mapping *mapping;
 
-       mutex_lock(&bo->mappings.lock);
        list_for_each_entry(mapping, &bo->mappings.list, node)
                panfrost_gem_teardown_mapping(mapping);
-       mutex_unlock(&bo->mappings.lock);
 }
 
 int panfrost_gem_open(struct drm_gem_object *obj, struct drm_file *file_priv)
index b3517ff..8088d5f 100644 (file)
@@ -82,7 +82,7 @@ struct panfrost_gem_mapping *
 panfrost_gem_mapping_get(struct panfrost_gem_object *bo,
                         struct panfrost_file_priv *priv);
 void panfrost_gem_mapping_put(struct panfrost_gem_mapping *mapping);
-void panfrost_gem_teardown_mappings(struct panfrost_gem_object *bo);
+void panfrost_gem_teardown_mappings_locked(struct panfrost_gem_object *bo);
 
 void panfrost_gem_shrinker_init(struct drm_device *dev);
 void panfrost_gem_shrinker_cleanup(struct drm_device *dev);
index 288e46c..1b9f68d 100644 (file)
@@ -40,18 +40,26 @@ static bool panfrost_gem_purge(struct drm_gem_object *obj)
 {
        struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
        struct panfrost_gem_object *bo = to_panfrost_bo(obj);
+       bool ret = false;
 
        if (atomic_read(&bo->gpu_usecount))
                return false;
 
-       if (!mutex_trylock(&shmem->pages_lock))
+       if (!mutex_trylock(&bo->mappings.lock))
                return false;
 
-       panfrost_gem_teardown_mappings(bo);
+       if (!mutex_trylock(&shmem->pages_lock))
+               goto unlock_mappings;
+
+       panfrost_gem_teardown_mappings_locked(bo);
        drm_gem_shmem_purge_locked(obj);
+       ret = true;
 
        mutex_unlock(&shmem->pages_lock);
-       return true;
+
+unlock_mappings:
+       mutex_unlock(&bo->mappings.lock);
+       return ret;
 }
 
 static unsigned long
index 77497b4..55960cb 100644 (file)
@@ -814,9 +814,15 @@ static int sun4i_backend_bind(struct device *dev, struct device *master,
                 *
                 * XXX(hch): this has no business in a driver and needs to move
                 * to the device tree.
+                *
+                * If we have two subsequent calls to dma_direct_set_offset
+                * returns -EINVAL. Unfortunately, this happens when we have two
+                * backends in the system, and will result in the driver
+                * reporting an error while it has been setup properly before.
+                * Ignore EINVAL, but it should really be removed eventually.
                 */
                ret = dma_direct_set_offset(drm->dev, PHYS_OFFSET, 0, SZ_4G);
-               if (ret)
+               if (ret && ret != -EINVAL)
                        return ret;
        }
 
index d4c0804..92add2c 100644 (file)
@@ -208,6 +208,7 @@ static int sun8i_dw_hdmi_bind(struct device *dev, struct device *master,
        phy_node = of_parse_phandle(dev->of_node, "phys", 0);
        if (!phy_node) {
                dev_err(dev, "Can't found PHY phandle\n");
+               ret = -EINVAL;
                goto err_disable_clk_tmds;
        }
 
index 74ceebd..cc74a3f 100644 (file)
@@ -449,7 +449,7 @@ struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t unaligned_size,
        }
 
        if (IS_ERR(cma_obj)) {
-               struct drm_printer p = drm_info_printer(vc4->dev->dev);
+               struct drm_printer p = drm_info_printer(vc4->base.dev);
                DRM_ERROR("Failed to allocate from CMA:\n");
                vc4_bo_stats_print(&p, vc4);
                return ERR_PTR(-ENOMEM);
@@ -590,7 +590,7 @@ static void vc4_bo_cache_time_work(struct work_struct *work)
 {
        struct vc4_dev *vc4 =
                container_of(work, struct vc4_dev, bo_cache.time_work);
-       struct drm_device *dev = vc4->dev;
+       struct drm_device *dev = &vc4->base;
 
        mutex_lock(&vc4->bo_lock);
        vc4_bo_cache_free_old(dev);
@@ -1005,6 +1005,7 @@ int vc4_get_tiling_ioctl(struct drm_device *dev, void *data,
        return 0;
 }
 
+static void vc4_bo_cache_destroy(struct drm_device *dev, void *unused);
 int vc4_bo_cache_init(struct drm_device *dev)
 {
        struct vc4_dev *vc4 = to_vc4_dev(dev);
@@ -1033,10 +1034,10 @@ int vc4_bo_cache_init(struct drm_device *dev)
        INIT_WORK(&vc4->bo_cache.time_work, vc4_bo_cache_time_work);
        timer_setup(&vc4->bo_cache.time_timer, vc4_bo_cache_time_timer, 0);
 
-       return 0;
+       return drmm_add_action_or_reset(dev, vc4_bo_cache_destroy, NULL);
 }
 
-void vc4_bo_cache_destroy(struct drm_device *dev)
+static void vc4_bo_cache_destroy(struct drm_device *dev, void *unused)
 {
        struct vc4_dev *vc4 = to_vc4_dev(dev);
        int i;
index a17aa1d..839610f 100644 (file)
@@ -257,37 +257,37 @@ static int vc4_drm_bind(struct device *dev)
 
        dev->coherent_dma_mask = DMA_BIT_MASK(32);
 
-       vc4 = devm_kzalloc(dev, sizeof(*vc4), GFP_KERNEL);
-       if (!vc4)
-               return -ENOMEM;
-
        /* If VC4 V3D is missing, don't advertise render nodes. */
        node = of_find_matching_node_and_match(NULL, vc4_v3d_dt_match, NULL);
        if (!node || !of_device_is_available(node))
                vc4_drm_driver.driver_features &= ~DRIVER_RENDER;
        of_node_put(node);
 
-       drm = drm_dev_alloc(&vc4_drm_driver, dev);
-       if (IS_ERR(drm))
-               return PTR_ERR(drm);
+       vc4 = devm_drm_dev_alloc(dev, &vc4_drm_driver, struct vc4_dev, base);
+       if (IS_ERR(vc4))
+               return PTR_ERR(vc4);
+
+       drm = &vc4->base;
        platform_set_drvdata(pdev, drm);
-       vc4->dev = drm;
-       drm->dev_private = vc4;
        INIT_LIST_HEAD(&vc4->debugfs_list);
 
        mutex_init(&vc4->bin_bo_lock);
 
        ret = vc4_bo_cache_init(drm);
        if (ret)
-               goto dev_put;
+               return ret;
 
-       drm_mode_config_init(drm);
+       ret = drmm_mode_config_init(drm);
+       if (ret)
+               return ret;
 
-       vc4_gem_init(drm);
+       ret = vc4_gem_init(drm);
+       if (ret)
+               return ret;
 
        ret = component_bind_all(dev, drm);
        if (ret)
-               goto gem_destroy;
+               return ret;
 
        ret = vc4_plane_create_additional_planes(drm);
        if (ret)
@@ -312,30 +312,17 @@ static int vc4_drm_bind(struct device *dev)
 
 unbind_all:
        component_unbind_all(dev, drm);
-gem_destroy:
-       vc4_gem_destroy(drm);
-       drm_mode_config_cleanup(drm);
-       vc4_bo_cache_destroy(drm);
-dev_put:
-       drm_dev_put(drm);
+
        return ret;
 }
 
 static void vc4_drm_unbind(struct device *dev)
 {
        struct drm_device *drm = dev_get_drvdata(dev);
-       struct vc4_dev *vc4 = to_vc4_dev(drm);
 
        drm_dev_unregister(drm);
 
        drm_atomic_helper_shutdown(drm);
-
-       drm_mode_config_cleanup(drm);
-
-       drm_atomic_private_obj_fini(&vc4->load_tracker);
-       drm_atomic_private_obj_fini(&vc4->ctm_manager);
-
-       drm_dev_put(drm);
 }
 
 static const struct component_master_ops vc4_drm_ops = {
index 66d4fb1..19b75be 100644 (file)
@@ -14,6 +14,7 @@
 #include <drm/drm_device.h>
 #include <drm/drm_encoder.h>
 #include <drm/drm_gem_cma_helper.h>
+#include <drm/drm_managed.h>
 #include <drm/drm_mm.h>
 #include <drm/drm_modeset_lock.h>
 
@@ -71,7 +72,7 @@ struct vc4_perfmon {
 };
 
 struct vc4_dev {
-       struct drm_device *dev;
+       struct drm_device base;
 
        struct vc4_hvs *hvs;
        struct vc4_v3d *v3d;
@@ -234,7 +235,7 @@ struct vc4_dev {
 static inline struct vc4_dev *
 to_vc4_dev(struct drm_device *dev)
 {
-       return (struct vc4_dev *)dev->dev_private;
+       return container_of(dev, struct vc4_dev, base);
 }
 
 struct vc4_bo {
@@ -809,7 +810,6 @@ struct drm_gem_object *vc4_prime_import_sg_table(struct drm_device *dev,
                                                 struct sg_table *sgt);
 void *vc4_prime_vmap(struct drm_gem_object *obj);
 int vc4_bo_cache_init(struct drm_device *dev);
-void vc4_bo_cache_destroy(struct drm_device *dev);
 int vc4_bo_inc_usecnt(struct vc4_bo *bo);
 void vc4_bo_dec_usecnt(struct vc4_bo *bo);
 void vc4_bo_add_to_purgeable_pool(struct vc4_bo *bo);
@@ -874,8 +874,7 @@ extern struct platform_driver vc4_dsi_driver;
 extern const struct dma_fence_ops vc4_fence_ops;
 
 /* vc4_gem.c */
-void vc4_gem_init(struct drm_device *dev);
-void vc4_gem_destroy(struct drm_device *dev);
+int vc4_gem_init(struct drm_device *dev);
 int vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
                        struct drm_file *file_priv);
 int vc4_wait_seqno_ioctl(struct drm_device *dev, void *data,
index 9f01ddd..b641252 100644 (file)
@@ -314,16 +314,16 @@ vc4_reset_work(struct work_struct *work)
        struct vc4_dev *vc4 =
                container_of(work, struct vc4_dev, hangcheck.reset_work);
 
-       vc4_save_hang_state(vc4->dev);
+       vc4_save_hang_state(&vc4->base);
 
-       vc4_reset(vc4->dev);
+       vc4_reset(&vc4->base);
 }
 
 static void
 vc4_hangcheck_elapsed(struct timer_list *t)
 {
        struct vc4_dev *vc4 = from_timer(vc4, t, hangcheck.timer);
-       struct drm_device *dev = vc4->dev;
+       struct drm_device *dev = &vc4->base;
        uint32_t ct0ca, ct1ca;
        unsigned long irqflags;
        struct vc4_exec_info *bin_exec, *render_exec;
@@ -1000,7 +1000,7 @@ vc4_job_handle_completed(struct vc4_dev *vc4)
                list_del(&exec->head);
 
                spin_unlock_irqrestore(&vc4->job_lock, irqflags);
-               vc4_complete_exec(vc4->dev, exec);
+               vc4_complete_exec(&vc4->base, exec);
                spin_lock_irqsave(&vc4->job_lock, irqflags);
        }
 
@@ -1258,13 +1258,13 @@ vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
        return 0;
 
 fail:
-       vc4_complete_exec(vc4->dev, exec);
+       vc4_complete_exec(&vc4->base, exec);
 
        return ret;
 }
 
-void
-vc4_gem_init(struct drm_device *dev)
+static void vc4_gem_destroy(struct drm_device *dev, void *unused);
+int vc4_gem_init(struct drm_device *dev)
 {
        struct vc4_dev *vc4 = to_vc4_dev(dev);
 
@@ -1285,10 +1285,11 @@ vc4_gem_init(struct drm_device *dev)
 
        INIT_LIST_HEAD(&vc4->purgeable.list);
        mutex_init(&vc4->purgeable.lock);
+
+       return drmm_add_action_or_reset(dev, vc4_gem_destroy, NULL);
 }
 
-void
-vc4_gem_destroy(struct drm_device *dev)
+static void vc4_gem_destroy(struct drm_device *dev, void *unused)
 {
        struct vc4_dev *vc4 = to_vc4_dev(dev);
 
index 4d0a833..b72b2bd 100644 (file)
@@ -560,7 +560,7 @@ static int vc4_hvs_bind(struct device *dev, struct device *master, void *data)
 {
        struct platform_device *pdev = to_platform_device(dev);
        struct drm_device *drm = dev_get_drvdata(master);
-       struct vc4_dev *vc4 = drm->dev_private;
+       struct vc4_dev *vc4 = to_vc4_dev(drm);
        struct vc4_hvs *hvs = NULL;
        int ret;
        u32 dispctrl;
@@ -679,7 +679,7 @@ static void vc4_hvs_unbind(struct device *dev, struct device *master,
                           void *data)
 {
        struct drm_device *drm = dev_get_drvdata(master);
-       struct vc4_dev *vc4 = drm->dev_private;
+       struct vc4_dev *vc4 = to_vc4_dev(drm);
        struct vc4_hvs *hvs = vc4->hvs;
 
        if (drm_mm_node_allocated(&vc4->hvs->mitchell_netravali_filter))
index 149825f..2b951ca 100644 (file)
@@ -51,7 +51,7 @@ static struct vc4_ctm_state *vc4_get_ctm_state(struct drm_atomic_state *state,
                                               struct drm_private_obj *manager)
 {
        struct drm_device *dev = state->dev;
-       struct vc4_dev *vc4 = dev->dev_private;
+       struct vc4_dev *vc4 = to_vc4_dev(dev);
        struct drm_private_state *priv_state;
        int ret;
 
@@ -93,6 +93,29 @@ static const struct drm_private_state_funcs vc4_ctm_state_funcs = {
        .atomic_destroy_state = vc4_ctm_destroy_state,
 };
 
+static void vc4_ctm_obj_fini(struct drm_device *dev, void *unused)
+{
+       struct vc4_dev *vc4 = to_vc4_dev(dev);
+
+       drm_atomic_private_obj_fini(&vc4->ctm_manager);
+}
+
+static int vc4_ctm_obj_init(struct vc4_dev *vc4)
+{
+       struct vc4_ctm_state *ctm_state;
+
+       drm_modeset_lock_init(&vc4->ctm_state_lock);
+
+       ctm_state = kzalloc(sizeof(*ctm_state), GFP_KERNEL);
+       if (!ctm_state)
+               return -ENOMEM;
+
+       drm_atomic_private_obj_init(&vc4->base, &vc4->ctm_manager, &ctm_state->base,
+                                   &vc4_ctm_state_funcs);
+
+       return drmm_add_action(&vc4->base, vc4_ctm_obj_fini, NULL);
+}
+
 /* Converts a DRM S31.32 value to the HW S0.9 format. */
 static u16 vc4_ctm_s31_32_to_s0_9(u64 in)
 {
@@ -609,6 +632,34 @@ static const struct drm_private_state_funcs vc4_load_tracker_state_funcs = {
        .atomic_destroy_state = vc4_load_tracker_destroy_state,
 };
 
+static void vc4_load_tracker_obj_fini(struct drm_device *dev, void *unused)
+{
+       struct vc4_dev *vc4 = to_vc4_dev(dev);
+
+       if (!vc4->load_tracker_available)
+               return;
+
+       drm_atomic_private_obj_fini(&vc4->load_tracker);
+}
+
+static int vc4_load_tracker_obj_init(struct vc4_dev *vc4)
+{
+       struct vc4_load_tracker_state *load_state;
+
+       if (!vc4->load_tracker_available)
+               return 0;
+
+       load_state = kzalloc(sizeof(*load_state), GFP_KERNEL);
+       if (!load_state)
+               return -ENOMEM;
+
+       drm_atomic_private_obj_init(&vc4->base, &vc4->load_tracker,
+                                   &load_state->base,
+                                   &vc4_load_tracker_state_funcs);
+
+       return drmm_add_action(&vc4->base, vc4_load_tracker_obj_fini, NULL);
+}
+
 #define NUM_OUTPUTS  6
 #define NUM_CHANNELS 3
 
@@ -711,8 +762,6 @@ static const struct drm_mode_config_funcs vc4_mode_funcs = {
 int vc4_kms_load(struct drm_device *dev)
 {
        struct vc4_dev *vc4 = to_vc4_dev(dev);
-       struct vc4_ctm_state *ctm_state;
-       struct vc4_load_tracker_state *load_state;
        bool is_vc5 = of_device_is_compatible(dev->dev->of_node,
                                              "brcm,bcm2711-vc5");
        int ret;
@@ -751,26 +800,13 @@ int vc4_kms_load(struct drm_device *dev)
        dev->mode_config.async_page_flip = true;
        dev->mode_config.allow_fb_modifiers = true;
 
-       drm_modeset_lock_init(&vc4->ctm_state_lock);
-
-       ctm_state = kzalloc(sizeof(*ctm_state), GFP_KERNEL);
-       if (!ctm_state)
-               return -ENOMEM;
-
-       drm_atomic_private_obj_init(dev, &vc4->ctm_manager, &ctm_state->base,
-                                   &vc4_ctm_state_funcs);
-
-       if (vc4->load_tracker_available) {
-               load_state = kzalloc(sizeof(*load_state), GFP_KERNEL);
-               if (!load_state) {
-                       drm_atomic_private_obj_fini(&vc4->ctm_manager);
-                       return -ENOMEM;
-               }
+       ret = vc4_ctm_obj_init(vc4);
+       if (ret)
+               return ret;
 
-               drm_atomic_private_obj_init(dev, &vc4->load_tracker,
-                                           &load_state->base,
-                                           &vc4_load_tracker_state_funcs);
-       }
+       ret = vc4_load_tracker_obj_init(vc4);
+       if (ret)
+               return ret;
 
        drm_mode_config_reset(dev);
 
index f7ab979..65d0dac 100644 (file)
@@ -168,7 +168,7 @@ static void vc4_v3d_init_hw(struct drm_device *dev)
 
 int vc4_v3d_get_bin_slot(struct vc4_dev *vc4)
 {
-       struct drm_device *dev = vc4->dev;
+       struct drm_device *dev = &vc4->base;
        unsigned long irqflags;
        int slot;
        uint64_t seqno = 0;
@@ -246,7 +246,7 @@ static int bin_bo_alloc(struct vc4_dev *vc4)
        INIT_LIST_HEAD(&list);
 
        while (true) {
-               struct vc4_bo *bo = vc4_bo_create(vc4->dev, size, true,
+               struct vc4_bo *bo = vc4_bo_create(&vc4->base, size, true,
                                                  VC4_BO_TYPE_BIN);
 
                if (IS_ERR(bo)) {
@@ -361,7 +361,7 @@ static int vc4_v3d_runtime_suspend(struct device *dev)
        struct vc4_v3d *v3d = dev_get_drvdata(dev);
        struct vc4_dev *vc4 = v3d->vc4;
 
-       vc4_irq_uninstall(vc4->dev);
+       vc4_irq_uninstall(&vc4->base);
 
        clk_disable_unprepare(v3d->clk);
 
@@ -378,11 +378,11 @@ static int vc4_v3d_runtime_resume(struct device *dev)
        if (ret != 0)
                return ret;
 
-       vc4_v3d_init_hw(vc4->dev);
+       vc4_v3d_init_hw(&vc4->base);
 
        /* We disabled the IRQ as part of vc4_irq_uninstall in suspend. */
-       enable_irq(vc4->dev->irq);
-       vc4_irq_postinstall(vc4->dev);
+       enable_irq(vc4->base.irq);
+       vc4_irq_postinstall(&vc4->base);
 
        return 0;
 }
index b3dae9e..d166ee2 100644 (file)
@@ -133,73 +133,6 @@ enum ipu_color_space ipu_pixelformat_to_colorspace(u32 pixelformat)
 }
 EXPORT_SYMBOL_GPL(ipu_pixelformat_to_colorspace);
 
-bool ipu_pixelformat_is_planar(u32 pixelformat)
-{
-       switch (pixelformat) {
-       case V4L2_PIX_FMT_YUV420:
-       case V4L2_PIX_FMT_YVU420:
-       case V4L2_PIX_FMT_YUV422P:
-       case V4L2_PIX_FMT_NV12:
-       case V4L2_PIX_FMT_NV21:
-       case V4L2_PIX_FMT_NV16:
-       case V4L2_PIX_FMT_NV61:
-               return true;
-       }
-
-       return false;
-}
-EXPORT_SYMBOL_GPL(ipu_pixelformat_is_planar);
-
-enum ipu_color_space ipu_mbus_code_to_colorspace(u32 mbus_code)
-{
-       switch (mbus_code & 0xf000) {
-       case 0x1000:
-               return IPUV3_COLORSPACE_RGB;
-       case 0x2000:
-               return IPUV3_COLORSPACE_YUV;
-       default:
-               return IPUV3_COLORSPACE_UNKNOWN;
-       }
-}
-EXPORT_SYMBOL_GPL(ipu_mbus_code_to_colorspace);
-
-int ipu_stride_to_bytes(u32 pixel_stride, u32 pixelformat)
-{
-       switch (pixelformat) {
-       case V4L2_PIX_FMT_YUV420:
-       case V4L2_PIX_FMT_YVU420:
-       case V4L2_PIX_FMT_YUV422P:
-       case V4L2_PIX_FMT_NV12:
-       case V4L2_PIX_FMT_NV21:
-       case V4L2_PIX_FMT_NV16:
-       case V4L2_PIX_FMT_NV61:
-               /*
-                * for the planar YUV formats, the stride passed to
-                * cpmem must be the stride in bytes of the Y plane.
-                * And all the planar YUV formats have an 8-bit
-                * Y component.
-                */
-               return (8 * pixel_stride) >> 3;
-       case V4L2_PIX_FMT_RGB565:
-       case V4L2_PIX_FMT_YUYV:
-       case V4L2_PIX_FMT_UYVY:
-               return (16 * pixel_stride) >> 3;
-       case V4L2_PIX_FMT_BGR24:
-       case V4L2_PIX_FMT_RGB24:
-               return (24 * pixel_stride) >> 3;
-       case V4L2_PIX_FMT_BGR32:
-       case V4L2_PIX_FMT_RGB32:
-       case V4L2_PIX_FMT_XBGR32:
-       case V4L2_PIX_FMT_XRGB32:
-               return (32 * pixel_stride) >> 3;
-       default:
-               break;
-       }
-
-       return -EINVAL;
-}
-EXPORT_SYMBOL_GPL(ipu_stride_to_bytes);
-
 int ipu_degrees_to_rot_mode(enum ipu_rotate_mode *mode, int degrees,
                            bool hflip, bool vflip)
 {
index a50ba4a..b88f889 100644 (file)
 #define CP_2WHEEL_MOUSE_HACK           0x02
 #define CP_2WHEEL_MOUSE_HACK_ON                0x04
 
+#define VA_INVAL_LOGICAL_BOUNDARY      0x08
+
 /*
  * Some USB barcode readers from cypress have usage min and usage max in
  * the wrong order
  */
-static __u8 *cp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
+static __u8 *cp_rdesc_fixup(struct hid_device *hdev, __u8 *rdesc,
                unsigned int *rsize)
 {
-       unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
        unsigned int i;
 
-       if (!(quirks & CP_RDESC_SWAPPED_MIN_MAX))
-               return rdesc;
-
        if (*rsize < 4)
                return rdesc;
 
@@ -48,6 +46,40 @@ static __u8 *cp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
        return rdesc;
 }
 
+static __u8 *va_logical_boundary_fixup(struct hid_device *hdev, __u8 *rdesc,
+               unsigned int *rsize)
+{
+       /*
+        * Varmilo VA104M (with VID Cypress and device ID 07B1) incorrectly
+        * reports Logical Minimum of its Consumer Control device as 572
+        * (0x02 0x3c). Fix this by setting its Logical Minimum to zero.
+        */
+       if (*rsize == 25 &&
+                       rdesc[0] == 0x05 && rdesc[1] == 0x0c &&
+                       rdesc[2] == 0x09 && rdesc[3] == 0x01 &&
+                       rdesc[6] == 0x19 && rdesc[7] == 0x00 &&
+                       rdesc[11] == 0x16 && rdesc[12] == 0x3c && rdesc[13] == 0x02) {
+               hid_info(hdev,
+                        "fixing up varmilo VA104M consumer control report descriptor\n");
+               rdesc[12] = 0x00;
+               rdesc[13] = 0x00;
+       }
+       return rdesc;
+}
+
+static __u8 *cp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
+               unsigned int *rsize)
+{
+       unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
+
+       if (quirks & CP_RDESC_SWAPPED_MIN_MAX)
+               rdesc = cp_rdesc_fixup(hdev, rdesc, rsize);
+       if (quirks & VA_INVAL_LOGICAL_BOUNDARY)
+               rdesc = va_logical_boundary_fixup(hdev, rdesc, rsize);
+
+       return rdesc;
+}
+
 static int cp_input_mapped(struct hid_device *hdev, struct hid_input *hi,
                struct hid_field *field, struct hid_usage *usage,
                unsigned long **bit, int *max)
@@ -128,6 +160,8 @@ static const struct hid_device_id cp_devices[] = {
                .driver_data = CP_RDESC_SWAPPED_MIN_MAX },
        { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE),
                .driver_data = CP_2WHEEL_MOUSE_HACK },
+       { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_VARMILO_VA104M_07B1),
+               .driver_data = VA_INVAL_LOGICAL_BOUNDARY },
        { }
 };
 MODULE_DEVICE_TABLE(hid, cp_devices);
index d69842f..f170fea 100644 (file)
 #define USB_DEVICE_ID_CYPRESS_BARCODE_4        0xed81
 #define USB_DEVICE_ID_CYPRESS_TRUETOUCH        0xc001
 
+#define USB_DEVICE_ID_CYPRESS_VARMILO_VA104M_07B1   0X07b1
+
 #define USB_VENDOR_ID_DATA_MODUL       0x7374
 #define USB_VENDOR_ID_DATA_MODUL_EASYMAXTOUCH  0x1201
 
 #define USB_VENDOR_ID_FRUCTEL  0x25B6
 #define USB_DEVICE_ID_GAMETEL_MT_MODE  0x0002
 
+#define USB_VENDOR_ID_GAMEVICE 0x27F8
+#define USB_DEVICE_ID_GAMEVICE_GV186   0x0BBE
+#define USB_DEVICE_ID_GAMEVICE_KISHI   0x0BBF
+
 #define USB_VENDOR_ID_GAMERON          0x0810
 #define USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR 0x0001
 #define USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR 0x0002
 #define USB_DEVICE_ID_PENPOWER         0x00f4
 
 #define USB_VENDOR_ID_GREENASIA                0x0e8f
+#define USB_DEVICE_ID_GREENASIA_DUAL_SAT_ADAPTOR 0x3010
 #define USB_DEVICE_ID_GREENASIA_DUAL_USB_JOYPAD        0x3013
 
 #define USB_VENDOR_ID_GRETAGMACBETH    0x0971
 #define USB_VENDOR_ID_LOGITECH         0x046d
 #define USB_DEVICE_ID_LOGITECH_AUDIOHUB 0x0a0e
 #define USB_DEVICE_ID_LOGITECH_T651    0xb00c
+#define USB_DEVICE_ID_LOGITECH_DINOVO_EDGE_KBD 0xb309
 #define USB_DEVICE_ID_LOGITECH_C007    0xc007
 #define USB_DEVICE_ID_LOGITECH_C077    0xc077
 #define USB_DEVICE_ID_LOGITECH_RECEIVER        0xc101
 
 #define USB_VENDOR_ID_UGTIZER                  0x2179
 #define USB_DEVICE_ID_UGTIZER_TABLET_GP0610    0x0053
+#define USB_DEVICE_ID_UGTIZER_TABLET_GT5040    0x0077
 
 #define USB_VENDOR_ID_VIEWSONIC                        0x0543
 #define USB_DEVICE_ID_VIEWSONIC_PD1011         0xe621
index 9770db6..4dca113 100644 (file)
@@ -319,6 +319,9 @@ static const struct hid_device_id hid_battery_quirks[] = {
        { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ASUSTEK,
                USB_DEVICE_ID_ASUSTEK_T100CHI_KEYBOARD),
          HID_BATTERY_QUIRK_IGNORE },
+       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH,
+               USB_DEVICE_ID_LOGITECH_DINOVO_EDGE_KBD),
+         HID_BATTERY_QUIRK_IGNORE },
        {}
 };
 
index 044a93f..742c052 100644 (file)
 
 #include "hid-ids.h"
 
+#define QUIRK_TOUCHPAD_ON_OFF_REPORT           BIT(0)
+
+static __u8 *ite_report_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize)
+{
+       unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
+
+       if (quirks & QUIRK_TOUCHPAD_ON_OFF_REPORT) {
+               if (*rsize == 188 && rdesc[162] == 0x81 && rdesc[163] == 0x02) {
+                       hid_info(hdev, "Fixing up ITE keyboard report descriptor\n");
+                       rdesc[163] = HID_MAIN_ITEM_RELATIVE;
+               }
+       }
+
+       return rdesc;
+}
+
+static int ite_input_mapping(struct hid_device *hdev,
+               struct hid_input *hi, struct hid_field *field,
+               struct hid_usage *usage, unsigned long **bit,
+               int *max)
+{
+
+       unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
+
+       if ((quirks & QUIRK_TOUCHPAD_ON_OFF_REPORT) &&
+           (usage->hid & HID_USAGE_PAGE) == 0x00880000) {
+               if (usage->hid == 0x00880078) {
+                       /* Touchpad on, userspace expects F22 for this */
+                       hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_F22);
+                       return 1;
+               }
+               if (usage->hid == 0x00880079) {
+                       /* Touchpad off, userspace expects F23 for this */
+                       hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_F23);
+                       return 1;
+               }
+               return -1;
+       }
+
+       return 0;
+}
+
 static int ite_event(struct hid_device *hdev, struct hid_field *field,
                     struct hid_usage *usage, __s32 value)
 {
@@ -37,13 +79,27 @@ static int ite_event(struct hid_device *hdev, struct hid_field *field,
        return 0;
 }
 
+static int ite_probe(struct hid_device *hdev, const struct hid_device_id *id)
+{
+       int ret;
+
+       hid_set_drvdata(hdev, (void *)id->driver_data);
+
+       ret = hid_open_report(hdev);
+       if (ret)
+               return ret;
+
+       return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
+}
+
 static const struct hid_device_id ite_devices[] = {
        { HID_USB_DEVICE(USB_VENDOR_ID_ITE, USB_DEVICE_ID_ITE8595) },
        { HID_USB_DEVICE(USB_VENDOR_ID_258A, USB_DEVICE_ID_258A_6A88) },
        /* ITE8595 USB kbd ctlr, with Synaptics touchpad connected to it. */
        { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
                     USB_VENDOR_ID_SYNAPTICS,
-                    USB_DEVICE_ID_SYNAPTICS_ACER_SWITCH5_012) },
+                    USB_DEVICE_ID_SYNAPTICS_ACER_SWITCH5_012),
+         .driver_data = QUIRK_TOUCHPAD_ON_OFF_REPORT },
        /* ITE8910 USB kbd ctlr, with Synaptics touchpad connected to it. */
        { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
                     USB_VENDOR_ID_SYNAPTICS,
@@ -55,6 +111,9 @@ MODULE_DEVICE_TABLE(hid, ite_devices);
 static struct hid_driver ite_driver = {
        .name = "itetech",
        .id_table = ite_devices,
+       .probe = ite_probe,
+       .report_fixup = ite_report_fixup,
+       .input_mapping = ite_input_mapping,
        .event = ite_event,
 };
 module_hid_driver(ite_driver);
index 72fb6e5..1ffcfc9 100644 (file)
@@ -328,7 +328,7 @@ static const char mse_bluetooth_descriptor[] = {
        0x25, 0x01,             /*      LOGICAL_MAX (1)                 */
        0x75, 0x01,             /*      REPORT_SIZE (1)                 */
        0x95, 0x04,             /*      REPORT_COUNT (4)                */
-       0x81, 0x06,             /*      INPUT                           */
+       0x81, 0x02,             /*      INPUT (Data,Var,Abs)            */
        0xC0,                   /*    END_COLLECTION                    */
        0xC0,                   /*  END_COLLECTION                      */
 };
@@ -866,11 +866,24 @@ static void logi_dj_recv_queue_notification(struct dj_receiver_dev *djrcv_dev,
        schedule_work(&djrcv_dev->work);
 }
 
+/*
+ * Some quad/bluetooth keyboards have a builtin touchpad in this case we see
+ * only 1 paired device with a device_type of REPORT_TYPE_KEYBOARD. For the
+ * touchpad to work we must also forward mouse input reports to the dj_hiddev
+ * created for the keyboard (instead of forwarding them to a second paired
+ * device with a device_type of REPORT_TYPE_MOUSE as we normally would).
+ */
+static const u16 kbd_builtin_touchpad_ids[] = {
+       0xb309, /* Dinovo Edge */
+       0xb30c, /* Dinovo Mini */
+};
+
 static void logi_hidpp_dev_conn_notif_equad(struct hid_device *hdev,
                                            struct hidpp_event *hidpp_report,
                                            struct dj_workitem *workitem)
 {
        struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
+       int i, id;
 
        workitem->type = WORKITEM_TYPE_PAIRED;
        workitem->device_type = hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] &
@@ -882,6 +895,13 @@ static void logi_hidpp_dev_conn_notif_equad(struct hid_device *hdev,
                workitem->reports_supported |= STD_KEYBOARD | MULTIMEDIA |
                                               POWER_KEYS | MEDIA_CENTER |
                                               HIDPP;
+               id = (workitem->quad_id_msb << 8) | workitem->quad_id_lsb;
+               for (i = 0; i < ARRAY_SIZE(kbd_builtin_touchpad_ids); i++) {
+                       if (id == kbd_builtin_touchpad_ids[i]) {
+                               workitem->reports_supported |= STD_MOUSE;
+                               break;
+                       }
+               }
                break;
        case REPORT_TYPE_MOUSE:
                workitem->reports_supported |= STD_MOUSE | HIDPP;
index b8b53dc..0ca7231 100644 (file)
@@ -93,6 +93,8 @@ MODULE_PARM_DESC(disable_tap_to_click,
 #define HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS  BIT(3)
 #define HIDPP_CAPABILITY_BATTERY_VOLTAGE       BIT(4)
 
+#define lg_map_key_clear(c)  hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c))
+
 /*
  * There are two hidpp protocols in use, the first version hidpp10 is known
  * as register access protocol or RAP, the second version hidpp20 is known as
@@ -2950,6 +2952,26 @@ static int g920_get_config(struct hidpp_device *hidpp,
        return g920_ff_set_autocenter(hidpp, data);
 }
 
+/* -------------------------------------------------------------------------- */
+/* Logitech Dinovo Mini keyboard with builtin touchpad                        */
+/* -------------------------------------------------------------------------- */
+#define DINOVO_MINI_PRODUCT_ID         0xb30c
+
+static int lg_dinovo_input_mapping(struct hid_device *hdev, struct hid_input *hi,
+               struct hid_field *field, struct hid_usage *usage,
+               unsigned long **bit, int *max)
+{
+       if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
+               return 0;
+
+       switch (usage->hid & HID_USAGE) {
+       case 0x00d: lg_map_key_clear(KEY_MEDIA);        break;
+       default:
+               return 0;
+       }
+       return 1;
+}
+
 /* -------------------------------------------------------------------------- */
 /* HID++1.0 devices which use HID++ reports for their wheels                  */
 /* -------------------------------------------------------------------------- */
@@ -3185,6 +3207,9 @@ static int hidpp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
                        field->application != HID_GD_MOUSE)
                return m560_input_mapping(hdev, hi, field, usage, bit, max);
 
+       if (hdev->product == DINOVO_MINI_PRODUCT_ID)
+               return lg_dinovo_input_mapping(hdev, hi, field, usage, bit, max);
+
        return 0;
 }
 
@@ -3947,6 +3972,7 @@ static const struct hid_device_id hidpp_devices[] = {
          LDJ_DEVICE(0x405e), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
        { /* Mouse Logitech MX Anywhere 2 */
          LDJ_DEVICE(0x404a), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
+       { LDJ_DEVICE(0x4072), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
        { LDJ_DEVICE(0xb013), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
        { LDJ_DEVICE(0xb018), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
        { LDJ_DEVICE(0xb01f), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
@@ -3971,6 +3997,9 @@ static const struct hid_device_id hidpp_devices[] = {
        { /* Keyboard MX5000 (Bluetooth-receiver in HID proxy mode) */
          LDJ_DEVICE(0xb305),
          .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
+       { /* Dinovo Edge (Bluetooth-receiver in HID proxy mode) */
+         LDJ_DEVICE(0xb309),
+         .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
        { /* Keyboard MX5500 (Bluetooth-receiver in HID proxy mode) */
          LDJ_DEVICE(0xb30b),
          .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
@@ -4013,6 +4042,9 @@ static const struct hid_device_id hidpp_devices[] = {
        { /* MX5000 keyboard over Bluetooth */
          HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb305),
          .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
+       { /* Dinovo Edge keyboard over Bluetooth */
+         HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb309),
+         .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
        { /* MX5500 keyboard over Bluetooth */
          HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb30b),
          .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
index 0d27ccb..4211b98 100644 (file)
@@ -49,6 +49,36 @@ enum {
        MCP2221_ALT_F_NOT_GPIOD = 0xEF,
 };
 
+/* MCP GPIO direction encoding */
+enum {
+       MCP2221_DIR_OUT = 0x00,
+       MCP2221_DIR_IN = 0x01,
+};
+
+#define MCP_NGPIO      4
+
+/* MCP GPIO set command layout */
+struct mcp_set_gpio {
+       u8 cmd;
+       u8 dummy;
+       struct {
+               u8 change_value;
+               u8 value;
+               u8 change_direction;
+               u8 direction;
+       } gpio[MCP_NGPIO];
+} __packed;
+
+/* MCP GPIO get command layout */
+struct mcp_get_gpio {
+       u8 cmd;
+       u8 dummy;
+       struct {
+               u8 direction;
+               u8 value;
+       } gpio[MCP_NGPIO];
+} __packed;
+
 /*
  * There is no way to distinguish responses. Therefore next command
  * is sent only after response to previous has been received. Mutex
@@ -542,7 +572,7 @@ static int mcp_gpio_get(struct gpio_chip *gc,
 
        mcp->txbuf[0] = MCP2221_GPIO_GET;
 
-       mcp->gp_idx = (offset + 1) * 2;
+       mcp->gp_idx = offsetof(struct mcp_get_gpio, gpio[offset].value);
 
        mutex_lock(&mcp->lock);
        ret = mcp_send_data_req_status(mcp, mcp->txbuf, 1);
@@ -559,7 +589,7 @@ static void mcp_gpio_set(struct gpio_chip *gc,
        memset(mcp->txbuf, 0, 18);
        mcp->txbuf[0] = MCP2221_GPIO_SET;
 
-       mcp->gp_idx = ((offset + 1) * 4) - 1;
+       mcp->gp_idx = offsetof(struct mcp_set_gpio, gpio[offset].value);
 
        mcp->txbuf[mcp->gp_idx - 1] = 1;
        mcp->txbuf[mcp->gp_idx] = !!value;
@@ -575,7 +605,7 @@ static int mcp_gpio_dir_set(struct mcp2221 *mcp,
        memset(mcp->txbuf, 0, 18);
        mcp->txbuf[0] = MCP2221_GPIO_SET;
 
-       mcp->gp_idx = (offset + 1) * 5;
+       mcp->gp_idx = offsetof(struct mcp_set_gpio, gpio[offset].direction);
 
        mcp->txbuf[mcp->gp_idx - 1] = 1;
        mcp->txbuf[mcp->gp_idx] = val;
@@ -590,7 +620,7 @@ static int mcp_gpio_direction_input(struct gpio_chip *gc,
        struct mcp2221 *mcp = gpiochip_get_data(gc);
 
        mutex_lock(&mcp->lock);
-       ret = mcp_gpio_dir_set(mcp, offset, 0);
+       ret = mcp_gpio_dir_set(mcp, offset, MCP2221_DIR_IN);
        mutex_unlock(&mcp->lock);
 
        return ret;
@@ -603,7 +633,7 @@ static int mcp_gpio_direction_output(struct gpio_chip *gc,
        struct mcp2221 *mcp = gpiochip_get_data(gc);
 
        mutex_lock(&mcp->lock);
-       ret = mcp_gpio_dir_set(mcp, offset, 1);
+       ret = mcp_gpio_dir_set(mcp, offset, MCP2221_DIR_OUT);
        mutex_unlock(&mcp->lock);
 
        /* Can't configure as output, bailout early */
@@ -623,7 +653,7 @@ static int mcp_gpio_get_direction(struct gpio_chip *gc,
 
        mcp->txbuf[0] = MCP2221_GPIO_GET;
 
-       mcp->gp_idx = (offset + 1) * 2;
+       mcp->gp_idx = offsetof(struct mcp_get_gpio, gpio[offset].direction);
 
        mutex_lock(&mcp->lock);
        ret = mcp_send_data_req_status(mcp, mcp->txbuf, 1);
@@ -632,7 +662,7 @@ static int mcp_gpio_get_direction(struct gpio_chip *gc,
        if (ret)
                return ret;
 
-       if (mcp->gpio_dir)
+       if (mcp->gpio_dir == MCP2221_DIR_IN)
                return GPIO_LINE_DIRECTION_IN;
 
        return GPIO_LINE_DIRECTION_OUT;
@@ -758,7 +788,7 @@ static int mcp2221_raw_event(struct hid_device *hdev,
                                mcp->status = -ENOENT;
                        } else {
                                mcp->status = !!data[mcp->gp_idx];
-                               mcp->gpio_dir = !!data[mcp->gp_idx + 1];
+                               mcp->gpio_dir = data[mcp->gp_idx + 1];
                        }
                        break;
                default:
@@ -860,7 +890,7 @@ static int mcp2221_probe(struct hid_device *hdev,
        mcp->gc->get_direction = mcp_gpio_get_direction;
        mcp->gc->set = mcp_gpio_set;
        mcp->gc->get = mcp_gpio_get;
-       mcp->gc->ngpio = 4;
+       mcp->gc->ngpio = MCP_NGPIO;
        mcp->gc->base = -1;
        mcp->gc->can_sleep = 1;
        mcp->gc->parent = &hdev->dev;
index 7a2be02..bf7ecab 100644 (file)
@@ -83,7 +83,12 @@ static const struct hid_device_id hid_quirks[] = {
        { HID_USB_DEVICE(USB_VENDOR_ID_FORMOSA, USB_DEVICE_ID_FORMOSA_IR_RECEIVER), HID_QUIRK_NO_INIT_REPORTS },
        { HID_USB_DEVICE(USB_VENDOR_ID_FREESCALE, USB_DEVICE_ID_FREESCALE_MX28), HID_QUIRK_NOGET },
        { HID_USB_DEVICE(USB_VENDOR_ID_FUTABA, USB_DEVICE_ID_LED_DISPLAY), HID_QUIRK_NO_INIT_REPORTS },
+       { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, USB_DEVICE_ID_GREENASIA_DUAL_SAT_ADAPTOR), HID_QUIRK_MULTI_INPUT },
        { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, USB_DEVICE_ID_GREENASIA_DUAL_USB_JOYPAD), HID_QUIRK_MULTI_INPUT },
+       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_GAMEVICE, USB_DEVICE_ID_GAMEVICE_GV186),
+               HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE },
+       { HID_USB_DEVICE(USB_VENDOR_ID_GAMEVICE, USB_DEVICE_ID_GAMEVICE_KISHI),
+               HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE },
        { HID_USB_DEVICE(USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING), HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
        { HID_USB_DEVICE(USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FIGHTING), HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
        { HID_USB_DEVICE(USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FLYING), HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
index 94c7398..3dd7d32 100644 (file)
@@ -483,7 +483,8 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
                return 1;
 
        ptr = raw_data;
-       ptr++; /* Skip report id */
+       if (report->id)
+               ptr++; /* Skip report id */
 
        spin_lock_irqsave(&pdata->lock, flags);
 
index 86b5680..8e9c9e6 100644 (file)
@@ -385,6 +385,8 @@ static const struct hid_device_id uclogic_devices[] = {
                                USB_DEVICE_ID_UCLOGIC_DRAWIMAGE_G3) },
        { HID_USB_DEVICE(USB_VENDOR_ID_UGTIZER,
                                USB_DEVICE_ID_UGTIZER_TABLET_GP0610) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_UGTIZER,
+                               USB_DEVICE_ID_UGTIZER_TABLET_GT5040) },
        { HID_USB_DEVICE(USB_VENDOR_ID_UGEE,
                                USB_DEVICE_ID_UGEE_TABLET_G5) },
        { HID_USB_DEVICE(USB_VENDOR_ID_UGEE,
index 7d20d1f..d26d8cd 100644 (file)
@@ -997,6 +997,8 @@ int uclogic_params_init(struct uclogic_params *params,
                break;
        case VID_PID(USB_VENDOR_ID_UGTIZER,
                     USB_DEVICE_ID_UGTIZER_TABLET_GP0610):
+       case VID_PID(USB_VENDOR_ID_UGTIZER,
+                    USB_DEVICE_ID_UGTIZER_TABLET_GT5040):
        case VID_PID(USB_VENDOR_ID_UGEE,
                     USB_DEVICE_ID_UGEE_XPPEN_TABLET_G540):
        case VID_PID(USB_VENDOR_ID_UGEE,
index 786e3e9..aeff1ff 100644 (file)
@@ -943,6 +943,11 @@ static void i2c_hid_acpi_enable_wakeup(struct device *dev)
        }
 }
 
+static void i2c_hid_acpi_shutdown(struct device *dev)
+{
+       acpi_device_set_power(ACPI_COMPANION(dev), ACPI_STATE_D3_COLD);
+}
+
 static const struct acpi_device_id i2c_hid_acpi_match[] = {
        {"ACPI0C50", 0 },
        {"PNP0C50", 0 },
@@ -959,6 +964,8 @@ static inline int i2c_hid_acpi_pdata(struct i2c_client *client,
 static inline void i2c_hid_acpi_fix_up_power(struct device *dev) {}
 
 static inline void i2c_hid_acpi_enable_wakeup(struct device *dev) {}
+
+static inline void i2c_hid_acpi_shutdown(struct device *dev) {}
 #endif
 
 #ifdef CONFIG_OF
@@ -1175,6 +1182,8 @@ static void i2c_hid_shutdown(struct i2c_client *client)
 
        i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
        free_irq(client->irq, ihid);
+
+       i2c_hid_acpi_shutdown(&client->dev);
 }
 
 #ifdef CONFIG_PM_SLEEP
index 0cde10f..f202ac7 100644 (file)
@@ -244,9 +244,13 @@ int hv_synic_cleanup(unsigned int cpu)
 
        /*
         * Hyper-V does not provide a way to change the connect CPU once
-        * it is set; we must prevent the connect CPU from going offline.
+        * it is set; we must prevent the connect CPU from going offline
+        * while the VM is running normally. But in the panic or kexec()
+        * path where the vmbus is already disconnected, the CPU must be
+        * allowed to shut down.
         */
-       if (cpu == VMBUS_CONNECT_CPU)
+       if (cpu == VMBUS_CONNECT_CPU &&
+           vmbus_connection.conn_state == CONNECTED)
                return -EBUSY;
 
        /*
index b64d2ef..eb56e09 100644 (file)
@@ -1275,7 +1275,7 @@ static void balloon_up(struct work_struct *dummy)
 
        /* Refuse to balloon below the floor. */
        if (avail_pages < num_pages || avail_pages - num_pages < floor) {
-               pr_warn("Balloon request will be partially fulfilled. %s\n",
+               pr_info("Balloon request will be partially fulfilled. %s\n",
                        avail_pages < num_pages ? "Not enough memory." :
                        "Balloon floor reached.");
 
index d065973..3197cda 100644 (file)
@@ -171,7 +171,7 @@ static umode_t amd_energy_is_visible(const void *_data,
                                     enum hwmon_sensor_types type,
                                     u32 attr, int channel)
 {
-       return 0444;
+       return 0440;
 }
 
 static int energy_accumulator(void *p)
index a188879..79b498f 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/hwmon.h>
 #include <linux/workqueue.h>
 #include <linux/err.h>
+#include <linux/bits.h>
 
 /* data port used by Apple SMC */
 #define APPLESMC_DATA_PORT     0x300
 
 #define APPLESMC_MAX_DATA_LENGTH 32
 
-/* wait up to 128 ms for a status change. */
-#define APPLESMC_MIN_WAIT      0x0010
-#define APPLESMC_RETRY_WAIT    0x0100
-#define APPLESMC_MAX_WAIT      0x20000
+/* Apple SMC status bits */
+#define SMC_STATUS_AWAITING_DATA  BIT(0) /* SMC has data waiting to be read */
+#define SMC_STATUS_IB_CLOSED      BIT(1) /* Will ignore any input */
+#define SMC_STATUS_BUSY           BIT(2) /* Command in progress */
+
+/* Initial wait is 8us */
+#define APPLESMC_MIN_WAIT      0x0008
 
 #define APPLESMC_READ_CMD      0x10
 #define APPLESMC_WRITE_CMD     0x11
@@ -151,65 +155,84 @@ static unsigned int key_at_index;
 static struct workqueue_struct *applesmc_led_wq;
 
 /*
- * wait_read - Wait for a byte to appear on SMC port. Callers must
- * hold applesmc_lock.
+ * Wait for specific status bits with a mask on the SMC.
+ * Used before all transactions.
+ * This does 10 fast loops of 8us then exponentially backs off for a
+ * minimum total wait of 262ms. Depending on usleep_range this could
+ * run out past 500ms.
  */
-static int wait_read(void)
+
+static int wait_status(u8 val, u8 mask)
 {
-       unsigned long end = jiffies + (APPLESMC_MAX_WAIT * HZ) / USEC_PER_SEC;
        u8 status;
        int us;
+       int i;
 
-       for (us = APPLESMC_MIN_WAIT; us < APPLESMC_MAX_WAIT; us <<= 1) {
-               usleep_range(us, us * 16);
+       us = APPLESMC_MIN_WAIT;
+       for (i = 0; i < 24 ; i++) {
                status = inb(APPLESMC_CMD_PORT);
-               /* read: wait for smc to settle */
-               if (status & 0x01)
+               if ((status & mask) == val)
                        return 0;
-               /* timeout: give up */
-               if (time_after(jiffies, end))
-                       break;
+               usleep_range(us, us * 2);
+               if (i > 9)
+                       us <<= 1;
        }
-
-       pr_warn("wait_read() fail: 0x%02x\n", status);
        return -EIO;
 }
 
-/*
- * send_byte - Write to SMC port, retrying when necessary. Callers
- * must hold applesmc_lock.
- */
+/* send_byte - Write to SMC data port. Callers must hold applesmc_lock. */
+
 static int send_byte(u8 cmd, u16 port)
 {
-       u8 status;
-       int us;
-       unsigned long end = jiffies + (APPLESMC_MAX_WAIT * HZ) / USEC_PER_SEC;
+       int status;
+
+       status = wait_status(0, SMC_STATUS_IB_CLOSED);
+       if (status)
+               return status;
+       /*
+        * This needs to be a separate read looking for bit 0x04
+        * after bit 0x02 falls. If consolidated with the wait above
+        * this extra read may not happen if status returns both
+        * simultaneously and this would appear to be required.
+        */
+       status = wait_status(SMC_STATUS_BUSY, SMC_STATUS_BUSY);
+       if (status)
+               return status;
 
        outb(cmd, port);
-       for (us = APPLESMC_MIN_WAIT; us < APPLESMC_MAX_WAIT; us <<= 1) {
-               usleep_range(us, us * 16);
-               status = inb(APPLESMC_CMD_PORT);
-               /* write: wait for smc to settle */
-               if (status & 0x02)
-                       continue;
-               /* ready: cmd accepted, return */
-               if (status & 0x04)
-                       return 0;
-               /* timeout: give up */
-               if (time_after(jiffies, end))
-                       break;
-               /* busy: long wait and resend */
-               udelay(APPLESMC_RETRY_WAIT);
-               outb(cmd, port);
-       }
-
-       pr_warn("send_byte(0x%02x, 0x%04x) fail: 0x%02x\n", cmd, port, status);
-       return -EIO;
+       return 0;
 }
 
+/* send_command - Write a command to the SMC. Callers must hold applesmc_lock. */
+
 static int send_command(u8 cmd)
 {
-       return send_byte(cmd, APPLESMC_CMD_PORT);
+       int ret;
+
+       ret = wait_status(0, SMC_STATUS_IB_CLOSED);
+       if (ret)
+               return ret;
+       outb(cmd, APPLESMC_CMD_PORT);
+       return 0;
+}
+
+/*
+ * Based on logic from the Apple driver. This is issued before any interaction
+ * If busy is stuck high, issue a read command to reset the SMC state machine.
+ * If busy is stuck high after the command then the SMC is jammed.
+ */
+
+static int smc_sane(void)
+{
+       int ret;
+
+       ret = wait_status(0, SMC_STATUS_BUSY);
+       if (!ret)
+               return ret;
+       ret = send_command(APPLESMC_READ_CMD);
+       if (ret)
+               return ret;
+       return wait_status(0, SMC_STATUS_BUSY);
 }
 
 static int send_argument(const char *key)
@@ -226,6 +249,11 @@ static int read_smc(u8 cmd, const char *key, u8 *buffer, u8 len)
 {
        u8 status, data = 0;
        int i;
+       int ret;
+
+       ret = smc_sane();
+       if (ret)
+               return ret;
 
        if (send_command(cmd) || send_argument(key)) {
                pr_warn("%.4s: read arg fail\n", key);
@@ -239,7 +267,8 @@ static int read_smc(u8 cmd, const char *key, u8 *buffer, u8 len)
        }
 
        for (i = 0; i < len; i++) {
-               if (wait_read()) {
+               if (wait_status(SMC_STATUS_AWAITING_DATA | SMC_STATUS_BUSY,
+                               SMC_STATUS_AWAITING_DATA | SMC_STATUS_BUSY)) {
                        pr_warn("%.4s: read data[%d] fail\n", key, i);
                        return -EIO;
                }
@@ -250,19 +279,24 @@ static int read_smc(u8 cmd, const char *key, u8 *buffer, u8 len)
        for (i = 0; i < 16; i++) {
                udelay(APPLESMC_MIN_WAIT);
                status = inb(APPLESMC_CMD_PORT);
-               if (!(status & 0x01))
+               if (!(status & SMC_STATUS_AWAITING_DATA))
                        break;
                data = inb(APPLESMC_DATA_PORT);
        }
        if (i)
                pr_warn("flushed %d bytes, last value is: %d\n", i, data);
 
-       return 0;
+       return wait_status(0, SMC_STATUS_BUSY);
 }
 
 static int write_smc(u8 cmd, const char *key, const u8 *buffer, u8 len)
 {
        int i;
+       int ret;
+
+       ret = smc_sane();
+       if (ret)
+               return ret;
 
        if (send_command(cmd) || send_argument(key)) {
                pr_warn("%s: write arg fail\n", key);
@@ -281,7 +315,7 @@ static int write_smc(u8 cmd, const char *key, const u8 *buffer, u8 len)
                }
        }
 
-       return 0;
+       return wait_status(0, SMC_STATUS_BUSY);
 }
 
 static int read_register_count(unsigned int *count)
index 57923d7..be83b98 100644 (file)
@@ -122,8 +122,8 @@ static ssize_t max20730_debugfs_read(struct file *file, char __user *buf,
        switch (idx) {
        case MAX20730_DEBUGFS_VOUT_MIN:
                ret = VOLT_FROM_REG(data->mfr_voutmin * 10000);
-               len = snprintf(tbuf, DEBUG_FS_DATA_MAX, "%d.%d\n",
-                              ret / 10000, ret % 10000);
+               len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d.%d\n",
+                               ret / 10000, ret % 10000);
                break;
        case MAX20730_DEBUGFS_FREQUENCY:
                val = (data->mfr_devset1 & MAX20730_MFR_DEVSET1_FSW_MASK)
@@ -141,7 +141,7 @@ static ssize_t max20730_debugfs_read(struct file *file, char __user *buf,
                        ret = 800;
                else
                        ret = 900;
-               len = snprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret);
+               len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret);
                break;
        case MAX20730_DEBUGFS_PG_DELAY:
                val = (data->mfr_devset1 & MAX20730_MFR_DEVSET1_TSTAT_MASK)
@@ -223,7 +223,7 @@ static ssize_t max20730_debugfs_read(struct file *file, char __user *buf,
        case MAX20730_DEBUGFS_OC_PROTECT_MODE:
                ret = (data->mfr_devset2 & MAX20730_MFR_DEVSET2_OCPM_MASK)
                        >> MAX20730_MFR_DEVSET2_OCPM_BIT_POS;
-               len = snprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret);
+               len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret);
                break;
        case MAX20730_DEBUGFS_SS_TIMING:
                val = (data->mfr_devset2 & MAX20730_MFR_DEVSET2_SS_MASK)
@@ -241,32 +241,32 @@ static ssize_t max20730_debugfs_read(struct file *file, char __user *buf,
        case MAX20730_DEBUGFS_IMAX:
                ret = (data->mfr_devset2 & MAX20730_MFR_DEVSET2_IMAX_MASK)
                        >> MAX20730_MFR_DEVSET2_IMAX_BIT_POS;
-               len = snprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret);
+               len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret);
                break;
        case MAX20730_DEBUGFS_OPERATION:
                ret = i2c_smbus_read_byte_data(psu->client, PMBUS_OPERATION);
                if (ret < 0)
                        return ret;
-               len = snprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret);
+               len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret);
                break;
        case MAX20730_DEBUGFS_ON_OFF_CONFIG:
                ret = i2c_smbus_read_byte_data(psu->client, PMBUS_ON_OFF_CONFIG);
                if (ret < 0)
                        return ret;
-               len = snprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret);
+               len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret);
                break;
        case MAX20730_DEBUGFS_SMBALERT_MASK:
                ret = i2c_smbus_read_word_data(psu->client,
                                               PMBUS_SMB_ALERT_MASK);
                if (ret < 0)
                        return ret;
-               len = snprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret);
+               len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret);
                break;
        case MAX20730_DEBUGFS_VOUT_MODE:
                ret = i2c_smbus_read_byte_data(psu->client, PMBUS_VOUT_MODE);
                if (ret < 0)
                        return ret;
-               len = snprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret);
+               len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret);
                break;
        case MAX20730_DEBUGFS_VOUT_COMMAND:
                ret = i2c_smbus_read_word_data(psu->client, PMBUS_VOUT_COMMAND);
@@ -274,8 +274,8 @@ static ssize_t max20730_debugfs_read(struct file *file, char __user *buf,
                        return ret;
 
                ret = VOLT_FROM_REG(ret * 10000);
-               len = snprintf(tbuf, DEBUG_FS_DATA_MAX,
-                              "%d.%d\n", ret / 10000, ret % 10000);
+               len = scnprintf(tbuf, DEBUG_FS_DATA_MAX,
+                               "%d.%d\n", ret / 10000, ret % 10000);
                break;
        case MAX20730_DEBUGFS_VOUT_MAX:
                ret = i2c_smbus_read_word_data(psu->client, PMBUS_VOUT_MAX);
@@ -283,8 +283,8 @@ static ssize_t max20730_debugfs_read(struct file *file, char __user *buf,
                        return ret;
 
                ret = VOLT_FROM_REG(ret * 10000);
-               len = snprintf(tbuf, DEBUG_FS_DATA_MAX,
-                              "%d.%d\n", ret / 10000, ret % 10000);
+               len = scnprintf(tbuf, DEBUG_FS_DATA_MAX,
+                               "%d.%d\n", ret / 10000, ret % 10000);
                break;
        default:
                len = strlcpy(tbuf, "Invalid\n", DEBUG_FS_DATA_MAX);
index 170a9f8..b0e2820 100644 (file)
@@ -941,12 +941,16 @@ static ssize_t pmbus_show_sensor(struct device *dev,
        struct i2c_client *client = to_i2c_client(dev->parent);
        struct pmbus_sensor *sensor = to_pmbus_sensor(devattr);
        struct pmbus_data *data = i2c_get_clientdata(client);
+       ssize_t ret;
 
+       mutex_lock(&data->update_lock);
        pmbus_update_sensor_data(client, sensor);
        if (sensor->data < 0)
-               return sensor->data;
-
-       return snprintf(buf, PAGE_SIZE, "%lld\n", pmbus_reg2data(data, sensor));
+               ret = sensor->data;
+       else
+               ret = snprintf(buf, PAGE_SIZE, "%lld\n", pmbus_reg2data(data, sensor));
+       mutex_unlock(&data->update_lock);
+       return ret;
 }
 
 static ssize_t pmbus_set_sensor(struct device *dev,
@@ -2012,8 +2016,11 @@ static ssize_t pmbus_show_samples(struct device *dev,
        int val;
        struct i2c_client *client = to_i2c_client(dev->parent);
        struct pmbus_samples_reg *reg = to_samples_reg(devattr);
+       struct pmbus_data *data = i2c_get_clientdata(client);
 
+       mutex_lock(&data->update_lock);
        val = _pmbus_read_word_data(client, reg->page, 0xff, reg->attr->reg);
+       mutex_unlock(&data->update_lock);
        if (val < 0)
                return val;
 
index bdba214..1f63807 100644 (file)
@@ -54,16 +54,18 @@ static irqreturn_t pulse_handler(int irq, void *dev_id)
 static void sample_timer(struct timer_list *t)
 {
        struct pwm_fan_ctx *ctx = from_timer(ctx, t, rpm_timer);
+       unsigned int delta = ktime_ms_delta(ktime_get(), ctx->sample_start);
        int pulses;
-       u64 tmp;
 
-       pulses = atomic_read(&ctx->pulses);
-       atomic_sub(pulses, &ctx->pulses);
-       tmp = (u64)pulses * ktime_ms_delta(ktime_get(), ctx->sample_start) * 60;
-       do_div(tmp, ctx->pulses_per_revolution * 1000);
-       ctx->rpm = tmp;
+       if (delta) {
+               pulses = atomic_read(&ctx->pulses);
+               atomic_sub(pulses, &ctx->pulses);
+               ctx->rpm = (unsigned int)(pulses * 1000 * 60) /
+                       (ctx->pulses_per_revolution * delta);
+
+               ctx->sample_start = ktime_get();
+       }
 
-       ctx->sample_start = ktime_get();
        mod_timer(&ctx->rpm_timer, jiffies + HZ);
 }
 
index a4f473e..a97a9d0 100644 (file)
@@ -733,7 +733,7 @@ config I2C_LPC2K
 
 config I2C_MLXBF
         tristate "Mellanox BlueField I2C controller"
-        depends on ARM64
+        depends on MELLANOX_PLATFORM && ARM64
         help
           Enabling this option will add I2C SMBus support for Mellanox BlueField
           system.
index 44974b5..0d15f4c 100644 (file)
@@ -159,7 +159,6 @@ static int i2c_dw_irq_handler_slave(struct dw_i2c_dev *dev)
        u32 raw_stat, stat, enabled, tmp;
        u8 val = 0, slave_activity;
 
-       regmap_read(dev->map, DW_IC_INTR_STAT, &stat);
        regmap_read(dev->map, DW_IC_ENABLE, &enabled);
        regmap_read(dev->map, DW_IC_RAW_INTR_STAT, &raw_stat);
        regmap_read(dev->map, DW_IC_STATUS, &tmp);
@@ -168,32 +167,30 @@ static int i2c_dw_irq_handler_slave(struct dw_i2c_dev *dev)
        if (!enabled || !(raw_stat & ~DW_IC_INTR_ACTIVITY) || !dev->slave)
                return 0;
 
+       stat = i2c_dw_read_clear_intrbits_slave(dev);
        dev_dbg(dev->dev,
                "%#x STATUS SLAVE_ACTIVITY=%#x : RAW_INTR_STAT=%#x : INTR_STAT=%#x\n",
                enabled, slave_activity, raw_stat, stat);
 
-       if ((stat & DW_IC_INTR_RX_FULL) && (stat & DW_IC_INTR_STOP_DET))
-               i2c_slave_event(dev->slave, I2C_SLAVE_WRITE_REQUESTED, &val);
+       if (stat & DW_IC_INTR_RX_FULL) {
+               if (dev->status != STATUS_WRITE_IN_PROGRESS) {
+                       dev->status = STATUS_WRITE_IN_PROGRESS;
+                       i2c_slave_event(dev->slave, I2C_SLAVE_WRITE_REQUESTED,
+                                       &val);
+               }
+
+               regmap_read(dev->map, DW_IC_DATA_CMD, &tmp);
+               val = tmp;
+               if (!i2c_slave_event(dev->slave, I2C_SLAVE_WRITE_RECEIVED,
+                                    &val))
+                       dev_vdbg(dev->dev, "Byte %X acked!", val);
+       }
 
        if (stat & DW_IC_INTR_RD_REQ) {
                if (slave_activity) {
-                       if (stat & DW_IC_INTR_RX_FULL) {
-                               regmap_read(dev->map, DW_IC_DATA_CMD, &tmp);
-                               val = tmp;
-
-                               if (!i2c_slave_event(dev->slave,
-                                                    I2C_SLAVE_WRITE_RECEIVED,
-                                                    &val)) {
-                                       dev_vdbg(dev->dev, "Byte %X acked!",
-                                                val);
-                               }
-                               regmap_read(dev->map, DW_IC_CLR_RD_REQ, &tmp);
-                               stat = i2c_dw_read_clear_intrbits_slave(dev);
-                       } else {
-                               regmap_read(dev->map, DW_IC_CLR_RD_REQ, &tmp);
-                               regmap_read(dev->map, DW_IC_CLR_RX_UNDER, &tmp);
-                               stat = i2c_dw_read_clear_intrbits_slave(dev);
-                       }
+                       regmap_read(dev->map, DW_IC_CLR_RD_REQ, &tmp);
+
+                       dev->status = STATUS_READ_IN_PROGRESS;
                        if (!i2c_slave_event(dev->slave,
                                             I2C_SLAVE_READ_REQUESTED,
                                             &val))
@@ -205,21 +202,11 @@ static int i2c_dw_irq_handler_slave(struct dw_i2c_dev *dev)
                if (!i2c_slave_event(dev->slave, I2C_SLAVE_READ_PROCESSED,
                                     &val))
                        regmap_read(dev->map, DW_IC_CLR_RX_DONE, &tmp);
-
-               i2c_slave_event(dev->slave, I2C_SLAVE_STOP, &val);
-               stat = i2c_dw_read_clear_intrbits_slave(dev);
-               return 1;
        }
 
-       if (stat & DW_IC_INTR_RX_FULL) {
-               regmap_read(dev->map, DW_IC_DATA_CMD, &tmp);
-               val = tmp;
-               if (!i2c_slave_event(dev->slave, I2C_SLAVE_WRITE_RECEIVED,
-                                    &val))
-                       dev_vdbg(dev->dev, "Byte %X acked!", val);
-       } else {
+       if (stat & DW_IC_INTR_STOP_DET) {
+               dev->status = STATUS_IDLE;
                i2c_slave_event(dev->slave, I2C_SLAVE_STOP, &val);
-               stat = i2c_dw_read_clear_intrbits_slave(dev);
        }
 
        return 1;
@@ -230,7 +217,6 @@ static irqreturn_t i2c_dw_isr_slave(int this_irq, void *dev_id)
        struct dw_i2c_dev *dev = dev_id;
        int ret;
 
-       i2c_dw_read_clear_intrbits_slave(dev);
        ret = i2c_dw_irq_handler_slave(dev);
        if (ret > 0)
                complete(&dev->cmd_complete);
index ee59e0d..33574d4 100644 (file)
  * Master. Default value is set to 400MHz.
  */
 #define MLXBF_I2C_TYU_PLL_OUT_FREQ  (400 * 1000 * 1000)
-/* Reference clock for Bluefield 1 - 156 MHz. */
-#define MLXBF_I2C_TYU_PLL_IN_FREQ   (156 * 1000 * 1000)
-/* Reference clock for BlueField 2 - 200 MHz. */
-#define MLXBF_I2C_YU_PLL_IN_FREQ    (200 * 1000 * 1000)
+/* Reference clock for Bluefield - 156 MHz. */
+#define MLXBF_I2C_PLL_IN_FREQ       (156 * 1000 * 1000)
 
 /* Constant used to determine the PLL frequency. */
 #define MLNXBF_I2C_COREPLL_CONST    16384
@@ -489,44 +487,6 @@ static struct mutex mlxbf_i2c_bus_lock;
 
 #define MLXBF_I2C_FREQUENCY_1GHZ  1000000000
 
-static void mlxbf_i2c_write(void __iomem *io, int reg, u32 val)
-{
-       writel(val, io + reg);
-}
-
-static u32 mlxbf_i2c_read(void __iomem *io, int reg)
-{
-       return readl(io + reg);
-}
-
-/*
- * This function is used to read data from Master GW Data Descriptor.
- * Data bytes in the Master GW Data Descriptor are shifted left so the
- * data starts at the MSB of the descriptor registers as set by the
- * underlying hardware. TYU_READ_DATA enables byte swapping while
- * reading data bytes, and MUST be called by the SMBus read routines
- * to copy data from the 32 * 32-bit HW Data registers a.k.a Master GW
- * Data Descriptor.
- */
-static u32 mlxbf_i2c_read_data(void __iomem *io, int reg)
-{
-       return (u32)be32_to_cpu(mlxbf_i2c_read(io, reg));
-}
-
-/*
- * This function is used to write data to the Master GW Data Descriptor.
- * Data copied to the Master GW Data Descriptor MUST be shifted left so
- * the data starts at the MSB of the descriptor registers as required by
- * the underlying hardware. TYU_WRITE_DATA enables byte swapping when
- * writing data bytes, and MUST be called by the SMBus write routines to
- * copy data to the 32 * 32-bit HW Data registers a.k.a Master GW Data
- * Descriptor.
- */
-static void mlxbf_i2c_write_data(void __iomem *io, int reg, u32 val)
-{
-       mlxbf_i2c_write(io, reg, (u32)cpu_to_be32(val));
-}
-
 /*
  * Function to poll a set of bits at a specific address; it checks whether
  * the bits are equal to zero when eq_zero is set to 'true', and not equal
@@ -541,7 +501,7 @@ static u32 mlxbf_smbus_poll(void __iomem *io, u32 addr, u32 mask,
        timeout = (timeout / MLXBF_I2C_POLL_FREQ_IN_USEC) + 1;
 
        do {
-               bits = mlxbf_i2c_read(io, addr) & mask;
+               bits = readl(io + addr) & mask;
                if (eq_zero ? bits == 0 : bits != 0)
                        return eq_zero ? 1 : bits;
                udelay(MLXBF_I2C_POLL_FREQ_IN_USEC);
@@ -609,16 +569,16 @@ static int mlxbf_i2c_smbus_check_status(struct mlxbf_i2c_priv *priv)
                         MLXBF_I2C_SMBUS_TIMEOUT);
 
        /* Read cause status bits. */
-       cause_status_bits = mlxbf_i2c_read(priv->mst_cause->io,
-                                          MLXBF_I2C_CAUSE_ARBITER);
+       cause_status_bits = readl(priv->mst_cause->io +
+                                       MLXBF_I2C_CAUSE_ARBITER);
        cause_status_bits &= MLXBF_I2C_CAUSE_MASTER_ARBITER_BITS_MASK;
 
        /*
         * Parse both Cause and Master GW bits, then return transaction status.
         */
 
-       master_status_bits = mlxbf_i2c_read(priv->smbus->io,
-                                           MLXBF_I2C_SMBUS_MASTER_STATUS);
+       master_status_bits = readl(priv->smbus->io +
+                                       MLXBF_I2C_SMBUS_MASTER_STATUS);
        master_status_bits &= MLXBF_I2C_SMBUS_MASTER_STATUS_MASK;
 
        if (mlxbf_i2c_smbus_transaction_success(master_status_bits,
@@ -649,10 +609,17 @@ static void mlxbf_i2c_smbus_write_data(struct mlxbf_i2c_priv *priv,
 
        aligned_length = round_up(length, 4);
 
-       /* Copy data bytes from 4-byte aligned source buffer. */
+       /*
+        * Copy data bytes from 4-byte aligned source buffer.
+        * Data copied to the Master GW Data Descriptor MUST be shifted
+        * left so the data starts at the MSB of the descriptor registers
+        * as required by the underlying hardware. Enable byte swapping
+        * when writing data bytes to the 32 * 32-bit HW Data registers
+        * a.k.a Master GW Data Descriptor.
+        */
        for (offset = 0; offset < aligned_length; offset += sizeof(u32)) {
                data32 = *((u32 *)(data + offset));
-               mlxbf_i2c_write_data(priv->smbus->io, addr + offset, data32);
+               iowrite32be(data32, priv->smbus->io + addr + offset);
        }
 }
 
@@ -664,15 +631,23 @@ static void mlxbf_i2c_smbus_read_data(struct mlxbf_i2c_priv *priv,
 
        mask = sizeof(u32) - 1;
 
+       /*
+        * Data bytes in the Master GW Data Descriptor are shifted left
+        * so the data starts at the MSB of the descriptor registers as
+        * set by the underlying hardware. Enable byte swapping while
+        * reading data bytes from the 32 * 32-bit HW Data registers
+        * a.k.a Master GW Data Descriptor.
+        */
+
        for (offset = 0; offset < (length & ~mask); offset += sizeof(u32)) {
-               data32 = mlxbf_i2c_read_data(priv->smbus->io, addr + offset);
+               data32 = ioread32be(priv->smbus->io + addr + offset);
                *((u32 *)(data + offset)) = data32;
        }
 
        if (!(length & mask))
                return;
 
-       data32 = mlxbf_i2c_read_data(priv->smbus->io, addr + offset);
+       data32 = ioread32be(priv->smbus->io + addr + offset);
 
        for (byte = 0; byte < (length & mask); byte++) {
                data[offset + byte] = data32 & GENMASK(7, 0);
@@ -698,16 +673,16 @@ static int mlxbf_i2c_smbus_enable(struct mlxbf_i2c_priv *priv, u8 slave,
        command |= rol32(pec_en, MLXBF_I2C_MASTER_SEND_PEC_SHIFT);
 
        /* Clear status bits. */
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_MASTER_STATUS, 0x0);
+       writel(0x0, priv->smbus->io + MLXBF_I2C_SMBUS_MASTER_STATUS);
        /* Set the cause data. */
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_CAUSE_OR_CLEAR, ~0x0);
+       writel(~0x0, priv->smbus->io + MLXBF_I2C_CAUSE_OR_CLEAR);
        /* Zero PEC byte. */
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_MASTER_PEC, 0x0);
+       writel(0x0, priv->smbus->io + MLXBF_I2C_SMBUS_MASTER_PEC);
        /* Zero byte count. */
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_RS_BYTES, 0x0);
+       writel(0x0, priv->smbus->io + MLXBF_I2C_SMBUS_RS_BYTES);
 
        /* GW activation. */
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_MASTER_GW, command);
+       writel(command, priv->smbus->io + MLXBF_I2C_SMBUS_MASTER_GW);
 
        /*
         * Poll master status and check status bits. An ACK is sent when
@@ -823,8 +798,8 @@ mlxbf_i2c_smbus_start_transaction(struct mlxbf_i2c_priv *priv,
                 * needs to be 'manually' reset. This should be removed in
                 * next tag integration.
                 */
-               mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_MASTER_FSM,
-                               MLXBF_I2C_SMBUS_MASTER_FSM_PS_STATE_MASK);
+               writel(MLXBF_I2C_SMBUS_MASTER_FSM_PS_STATE_MASK,
+                       priv->smbus->io + MLXBF_I2C_SMBUS_MASTER_FSM);
        }
 
        return ret;
@@ -1113,8 +1088,8 @@ static void mlxbf_i2c_set_timings(struct mlxbf_i2c_priv *priv,
        timer |= mlxbf_i2c_set_timer(priv, timings->scl_low,
                                     false, MLXBF_I2C_MASK_16,
                                     MLXBF_I2C_SHIFT_16);
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_TIMER_SCL_LOW_SCL_HIGH,
-                         timer);
+       writel(timer, priv->smbus->io +
+               MLXBF_I2C_SMBUS_TIMER_SCL_LOW_SCL_HIGH);
 
        timer = mlxbf_i2c_set_timer(priv, timings->sda_rise, false,
                                    MLXBF_I2C_MASK_8, MLXBF_I2C_SHIFT_0);
@@ -1124,37 +1099,34 @@ static void mlxbf_i2c_set_timings(struct mlxbf_i2c_priv *priv,
                                     MLXBF_I2C_MASK_8, MLXBF_I2C_SHIFT_16);
        timer |= mlxbf_i2c_set_timer(priv, timings->scl_fall, false,
                                     MLXBF_I2C_MASK_8, MLXBF_I2C_SHIFT_24);
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_TIMER_FALL_RISE_SPIKE,
-                         timer);
+       writel(timer, priv->smbus->io +
+               MLXBF_I2C_SMBUS_TIMER_FALL_RISE_SPIKE);
 
        timer = mlxbf_i2c_set_timer(priv, timings->hold_start, true,
                                    MLXBF_I2C_MASK_16, MLXBF_I2C_SHIFT_0);
        timer |= mlxbf_i2c_set_timer(priv, timings->hold_data, true,
                                     MLXBF_I2C_MASK_16, MLXBF_I2C_SHIFT_16);
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_TIMER_THOLD, timer);
+       writel(timer, priv->smbus->io + MLXBF_I2C_SMBUS_TIMER_THOLD);
 
        timer = mlxbf_i2c_set_timer(priv, timings->setup_start, true,
                                    MLXBF_I2C_MASK_16, MLXBF_I2C_SHIFT_0);
        timer |= mlxbf_i2c_set_timer(priv, timings->setup_stop, true,
                                     MLXBF_I2C_MASK_16, MLXBF_I2C_SHIFT_16);
-       mlxbf_i2c_write(priv->smbus->io,
-                       MLXBF_I2C_SMBUS_TIMER_TSETUP_START_STOP, timer);
+       writel(timer, priv->smbus->io +
+               MLXBF_I2C_SMBUS_TIMER_TSETUP_START_STOP);
 
        timer = mlxbf_i2c_set_timer(priv, timings->setup_data, true,
                                    MLXBF_I2C_MASK_16, MLXBF_I2C_SHIFT_0);
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_TIMER_TSETUP_DATA,
-                         timer);
+       writel(timer, priv->smbus->io + MLXBF_I2C_SMBUS_TIMER_TSETUP_DATA);
 
        timer = mlxbf_i2c_set_timer(priv, timings->buf, false,
                                    MLXBF_I2C_MASK_16, MLXBF_I2C_SHIFT_0);
        timer |= mlxbf_i2c_set_timer(priv, timings->thigh_max, false,
                                     MLXBF_I2C_MASK_16, MLXBF_I2C_SHIFT_16);
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_THIGH_MAX_TBUF,
-                       timer);
+       writel(timer, priv->smbus->io + MLXBF_I2C_SMBUS_THIGH_MAX_TBUF);
 
        timer = timings->timeout;
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_SCL_LOW_TIMEOUT,
-                       timer);
+       writel(timer, priv->smbus->io + MLXBF_I2C_SMBUS_SCL_LOW_TIMEOUT);
 }
 
 enum mlxbf_i2c_timings_config {
@@ -1426,19 +1398,15 @@ static int mlxbf_i2c_init_master(struct platform_device *pdev,
         * platform firmware; disabling the bus might compromise the system
         * functionality.
         */
-       config_reg = mlxbf_i2c_read(gpio_res->io,
-                                   MLXBF_I2C_GPIO_0_FUNC_EN_0);
+       config_reg = readl(gpio_res->io + MLXBF_I2C_GPIO_0_FUNC_EN_0);
        config_reg = MLXBF_I2C_GPIO_SMBUS_GW_ASSERT_PINS(priv->bus,
                                                         config_reg);
-       mlxbf_i2c_write(gpio_res->io, MLXBF_I2C_GPIO_0_FUNC_EN_0,
-                       config_reg);
+       writel(config_reg, gpio_res->io + MLXBF_I2C_GPIO_0_FUNC_EN_0);
 
-       config_reg = mlxbf_i2c_read(gpio_res->io,
-                                   MLXBF_I2C_GPIO_0_FORCE_OE_EN);
+       config_reg = readl(gpio_res->io + MLXBF_I2C_GPIO_0_FORCE_OE_EN);
        config_reg = MLXBF_I2C_GPIO_SMBUS_GW_RESET_PINS(priv->bus,
                                                        config_reg);
-       mlxbf_i2c_write(gpio_res->io, MLXBF_I2C_GPIO_0_FORCE_OE_EN,
-                       config_reg);
+       writel(config_reg, gpio_res->io + MLXBF_I2C_GPIO_0_FORCE_OE_EN);
 
        mutex_unlock(gpio_res->lock);
 
@@ -1452,10 +1420,9 @@ static u64 mlxbf_calculate_freq_from_tyu(struct mlxbf_i2c_resource *corepll_res)
        u32 corepll_val;
        u16 core_f;
 
-       pad_frequency = MLXBF_I2C_TYU_PLL_IN_FREQ;
+       pad_frequency = MLXBF_I2C_PLL_IN_FREQ;
 
-       corepll_val = mlxbf_i2c_read(corepll_res->io,
-                                    MLXBF_I2C_CORE_PLL_REG1);
+       corepll_val = readl(corepll_res->io + MLXBF_I2C_CORE_PLL_REG1);
 
        /* Get Core PLL configuration bits. */
        core_f = rol32(corepll_val, MLXBF_I2C_COREPLL_CORE_F_TYU_SHIFT) &
@@ -1488,12 +1455,10 @@ static u64 mlxbf_calculate_freq_from_yu(struct mlxbf_i2c_resource *corepll_res)
        u8 core_od, core_r;
        u32 core_f;
 
-       pad_frequency = MLXBF_I2C_YU_PLL_IN_FREQ;
+       pad_frequency = MLXBF_I2C_PLL_IN_FREQ;
 
-       corepll_reg1_val = mlxbf_i2c_read(corepll_res->io,
-                                         MLXBF_I2C_CORE_PLL_REG1);
-       corepll_reg2_val = mlxbf_i2c_read(corepll_res->io,
-                                         MLXBF_I2C_CORE_PLL_REG2);
+       corepll_reg1_val = readl(corepll_res->io + MLXBF_I2C_CORE_PLL_REG1);
+       corepll_reg2_val = readl(corepll_res->io + MLXBF_I2C_CORE_PLL_REG2);
 
        /* Get Core PLL configuration bits */
        core_f = rol32(corepll_reg1_val, MLXBF_I2C_COREPLL_CORE_F_YU_SHIFT) &
@@ -1585,7 +1550,7 @@ static int mlxbf_slave_enable(struct mlxbf_i2c_priv *priv, u8 addr)
         * (7-bit address, 1 status bit (1 if enabled, 0 if not)).
         */
        for (reg = 0; reg < reg_cnt; reg++) {
-               slave_reg = mlxbf_i2c_read(priv->smbus->io,
+               slave_reg = readl(priv->smbus->io +
                                MLXBF_I2C_SMBUS_SLAVE_ADDR_CFG + reg * 0x4);
                /*
                 * Each register holds 4 slave addresses. So, we have to keep
@@ -1643,8 +1608,8 @@ static int mlxbf_slave_enable(struct mlxbf_i2c_priv *priv, u8 addr)
 
        /* Enable the slave address and update the register. */
        slave_reg |= (1 << MLXBF_I2C_SMBUS_SLAVE_ADDR_EN_BIT) << (byte * 8);
-       mlxbf_i2c_write(priv->smbus->io,
-                       MLXBF_I2C_SMBUS_SLAVE_ADDR_CFG + reg * 0x4, slave_reg);
+       writel(slave_reg, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_ADDR_CFG +
+               reg * 0x4);
 
        return 0;
 }
@@ -1668,7 +1633,7 @@ static int mlxbf_slave_disable(struct mlxbf_i2c_priv *priv)
         * (7-bit address, 1 status bit (1 if enabled, 0 if not)).
         */
        for (reg = 0; reg < reg_cnt; reg++) {
-               slave_reg = mlxbf_i2c_read(priv->smbus->io,
+               slave_reg = readl(priv->smbus->io +
                                MLXBF_I2C_SMBUS_SLAVE_ADDR_CFG + reg * 0x4);
 
                /* Check whether the address slots are empty. */
@@ -1708,8 +1673,8 @@ static int mlxbf_slave_disable(struct mlxbf_i2c_priv *priv)
 
        /* Cleanup the slave address slot. */
        slave_reg &= ~(GENMASK(7, 0) << (slave_byte * 8));
-       mlxbf_i2c_write(priv->smbus->io,
-                       MLXBF_I2C_SMBUS_SLAVE_ADDR_CFG + reg * 0x4, slave_reg);
+       writel(slave_reg, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_ADDR_CFG +
+               reg * 0x4);
 
        return 0;
 }
@@ -1801,7 +1766,7 @@ static int mlxbf_i2c_init_slave(struct platform_device *pdev,
        int ret;
 
        /* Reset FSM. */
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_SLAVE_FSM, 0);
+       writel(0, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_FSM);
 
        /*
         * Enable slave cause interrupt bits. Drive
@@ -1810,15 +1775,13 @@ static int mlxbf_i2c_init_slave(struct platform_device *pdev,
         * masters issue a Read and Write, respectively. But, clear all
         * interrupts first.
         */
-       mlxbf_i2c_write(priv->slv_cause->io,
-                         MLXBF_I2C_CAUSE_OR_CLEAR, ~0);
+       writel(~0, priv->slv_cause->io + MLXBF_I2C_CAUSE_OR_CLEAR);
        int_reg = MLXBF_I2C_CAUSE_READ_WAIT_FW_RESPONSE;
        int_reg |= MLXBF_I2C_CAUSE_WRITE_SUCCESS;
-       mlxbf_i2c_write(priv->slv_cause->io,
-                         MLXBF_I2C_CAUSE_OR_EVTEN0, int_reg);
+       writel(int_reg, priv->slv_cause->io + MLXBF_I2C_CAUSE_OR_EVTEN0);
 
        /* Finally, set the 'ready' bit to start handling transactions. */
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_SLAVE_READY, 0x1);
+       writel(0x1, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_READY);
 
        /* Initialize the cause coalesce resource. */
        ret = mlxbf_i2c_init_coalesce(pdev, priv);
@@ -1844,23 +1807,21 @@ static bool mlxbf_i2c_has_coalesce(struct mlxbf_i2c_priv *priv, bool *read,
                                MLXBF_I2C_CAUSE_YU_SLAVE_BIT :
                                priv->bus + MLXBF_I2C_CAUSE_TYU_SLAVE_BIT;
 
-       coalesce0_reg = mlxbf_i2c_read(priv->coalesce->io,
-                                      MLXBF_I2C_CAUSE_COALESCE_0);
+       coalesce0_reg = readl(priv->coalesce->io + MLXBF_I2C_CAUSE_COALESCE_0);
        is_set = coalesce0_reg & (1 << slave_shift);
 
        if (!is_set)
                return false;
 
        /* Check the source of the interrupt, i.e. whether a Read or Write. */
-       cause_reg = mlxbf_i2c_read(priv->slv_cause->io,
-                                    MLXBF_I2C_CAUSE_ARBITER);
+       cause_reg = readl(priv->slv_cause->io + MLXBF_I2C_CAUSE_ARBITER);
        if (cause_reg & MLXBF_I2C_CAUSE_READ_WAIT_FW_RESPONSE)
                *read = true;
        else if (cause_reg & MLXBF_I2C_CAUSE_WRITE_SUCCESS)
                *write = true;
 
        /* Clear cause bits. */
-       mlxbf_i2c_write(priv->slv_cause->io, MLXBF_I2C_CAUSE_OR_CLEAR, ~0x0);
+       writel(~0x0, priv->slv_cause->io + MLXBF_I2C_CAUSE_OR_CLEAR);
 
        return true;
 }
@@ -1900,8 +1861,8 @@ static int mlxbf_smbus_irq_send(struct mlxbf_i2c_priv *priv, u8 recv_bytes)
         * address, if supplied.
         */
        if (recv_bytes > 0) {
-               data32 = mlxbf_i2c_read_data(priv->smbus->io,
-                                            MLXBF_I2C_SLAVE_DATA_DESC_ADDR);
+               data32 = ioread32be(priv->smbus->io +
+                                       MLXBF_I2C_SLAVE_DATA_DESC_ADDR);
 
                /* Parse the received bytes. */
                switch (recv_bytes) {
@@ -1966,7 +1927,7 @@ static int mlxbf_smbus_irq_send(struct mlxbf_i2c_priv *priv, u8 recv_bytes)
        control32 |= rol32(write_size, MLXBF_I2C_SLAVE_WRITE_BYTES_SHIFT);
        control32 |= rol32(pec_en, MLXBF_I2C_SLAVE_SEND_PEC_SHIFT);
 
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_SLAVE_GW, control32);
+       writel(control32, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_GW);
 
        /*
         * Wait until the transfer is completed; the driver will wait
@@ -1975,10 +1936,9 @@ static int mlxbf_smbus_irq_send(struct mlxbf_i2c_priv *priv, u8 recv_bytes)
        mlxbf_smbus_slave_wait_for_idle(priv, MLXBF_I2C_SMBUS_TIMEOUT);
 
        /* Release the Slave GW. */
-       mlxbf_i2c_write(priv->smbus->io,
-                       MLXBF_I2C_SMBUS_SLAVE_RS_MASTER_BYTES, 0x0);
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_SLAVE_PEC, 0x0);
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_SLAVE_READY, 0x1);
+       writel(0x0, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_RS_MASTER_BYTES);
+       writel(0x0, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_PEC);
+       writel(0x1, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_READY);
 
        return 0;
 }
@@ -2023,10 +1983,9 @@ static int mlxbf_smbus_irq_recv(struct mlxbf_i2c_priv *priv, u8 recv_bytes)
        i2c_slave_event(slave, I2C_SLAVE_STOP, &value);
 
        /* Release the Slave GW. */
-       mlxbf_i2c_write(priv->smbus->io,
-                       MLXBF_I2C_SMBUS_SLAVE_RS_MASTER_BYTES, 0x0);
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_SLAVE_PEC, 0x0);
-       mlxbf_i2c_write(priv->smbus->io, MLXBF_I2C_SMBUS_SLAVE_READY, 0x1);
+       writel(0x0, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_RS_MASTER_BYTES);
+       writel(0x0, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_PEC);
+       writel(0x1, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_READY);
 
        return ret;
 }
@@ -2061,8 +2020,8 @@ static irqreturn_t mlxbf_smbus_irq(int irq, void *ptr)
         * slave, if the higher 8 bits are sent then the slave expect N bytes
         * from the master.
         */
-       rw_bytes_reg = mlxbf_i2c_read(priv->smbus->io,
-                                     MLXBF_I2C_SMBUS_SLAVE_RS_MASTER_BYTES);
+       rw_bytes_reg = readl(priv->smbus->io +
+                               MLXBF_I2C_SMBUS_SLAVE_RS_MASTER_BYTES);
        recv_bytes = (rw_bytes_reg >> 8) & GENMASK(7, 0);
 
        /*
@@ -2264,6 +2223,7 @@ static const struct of_device_id mlxbf_i2c_dt_ids[] = {
 
 MODULE_DEVICE_TABLE(of, mlxbf_i2c_dt_ids);
 
+#ifdef CONFIG_ACPI
 static const struct acpi_device_id mlxbf_i2c_acpi_ids[] = {
        { "MLNXBF03", (kernel_ulong_t)&mlxbf_i2c_chip[MLXBF_I2C_CHIP_TYPE_1] },
        { "MLNXBF23", (kernel_ulong_t)&mlxbf_i2c_chip[MLXBF_I2C_CHIP_TYPE_2] },
@@ -2305,6 +2265,12 @@ static int mlxbf_i2c_acpi_probe(struct device *dev, struct mlxbf_i2c_priv *priv)
 
        return ret;
 }
+#else
+static int mlxbf_i2c_acpi_probe(struct device *dev, struct mlxbf_i2c_priv *priv)
+{
+       return -ENOENT;
+}
+#endif /* CONFIG_ACPI */
 
 static int mlxbf_i2c_of_probe(struct device *dev, struct mlxbf_i2c_priv *priv)
 {
@@ -2473,7 +2439,9 @@ static struct platform_driver mlxbf_i2c_driver = {
        .driver = {
                .name = "i2c-mlxbf",
                .of_match_table = mlxbf_i2c_dt_ids,
+#ifdef CONFIG_ACPI
                .acpi_match_table = ACPI_PTR(mlxbf_i2c_acpi_ids),
+#endif /* CONFIG_ACPI  */
        },
 };
 
@@ -2502,5 +2470,5 @@ static void __exit mlxbf_i2c_exit(void)
 module_exit(mlxbf_i2c_exit);
 
 MODULE_DESCRIPTION("Mellanox BlueField I2C bus driver");
-MODULE_AUTHOR("Khalil Blaiech <kblaiech@mellanox.com>");
+MODULE_AUTHOR("Khalil Blaiech <kblaiech@nvidia.com>");
 MODULE_LICENSE("GPL v2");
index 0cbdfbe..33de99b 100644 (file)
@@ -475,6 +475,10 @@ static void mtk_i2c_init_hw(struct mtk_i2c *i2c)
 {
        u16 control_reg;
 
+       writel(I2C_DMA_HARD_RST, i2c->pdmabase + OFFSET_RST);
+       udelay(50);
+       writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_RST);
+
        mtk_i2c_writew(i2c, I2C_SOFT_RST, OFFSET_SOFTRESET);
 
        /* Set ioconfig */
@@ -529,10 +533,6 @@ static void mtk_i2c_init_hw(struct mtk_i2c *i2c)
 
        mtk_i2c_writew(i2c, control_reg, OFFSET_CONTROL);
        mtk_i2c_writew(i2c, I2C_DELAY_LEN, OFFSET_DELAY_LEN);
-
-       writel(I2C_DMA_HARD_RST, i2c->pdmabase + OFFSET_RST);
-       udelay(50);
-       writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_RST);
 }
 
 static const struct i2c_spec_values *mtk_i2c_get_spec(unsigned int speed)
index cab7255..bdd6077 100644 (file)
@@ -129,6 +129,7 @@ struct sh_mobile_i2c_data {
        int sr;
        bool send_stop;
        bool stop_after_dma;
+       bool atomic_xfer;
 
        struct resource *res;
        struct dma_chan *dma_tx;
@@ -330,13 +331,15 @@ static unsigned char i2c_op(struct sh_mobile_i2c_data *pd, enum sh_mobile_i2c_op
                ret = iic_rd(pd, ICDR);
                break;
        case OP_RX_STOP: /* enable DTE interrupt, issue stop */
-               iic_wr(pd, ICIC,
-                      ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE);
+               if (!pd->atomic_xfer)
+                       iic_wr(pd, ICIC,
+                              ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE);
                iic_wr(pd, ICCR, ICCR_ICE | ICCR_RACK);
                break;
        case OP_RX_STOP_DATA: /* enable DTE interrupt, read data, issue stop */
-               iic_wr(pd, ICIC,
-                      ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE);
+               if (!pd->atomic_xfer)
+                       iic_wr(pd, ICIC,
+                              ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE);
                ret = iic_rd(pd, ICDR);
                iic_wr(pd, ICCR, ICCR_ICE | ICCR_RACK);
                break;
@@ -429,7 +432,8 @@ static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id)
 
        if (wakeup) {
                pd->sr |= SW_DONE;
-               wake_up(&pd->wait);
+               if (!pd->atomic_xfer)
+                       wake_up(&pd->wait);
        }
 
        /* defeat write posting to avoid spurious WAIT interrupts */
@@ -581,6 +585,9 @@ static void start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg,
        pd->pos = -1;
        pd->sr = 0;
 
+       if (pd->atomic_xfer)
+               return;
+
        pd->dma_buf = i2c_get_dma_safe_msg_buf(pd->msg, 8);
        if (pd->dma_buf)
                sh_mobile_i2c_xfer_dma(pd);
@@ -637,15 +644,13 @@ static int poll_busy(struct sh_mobile_i2c_data *pd)
        return i ? 0 : -ETIMEDOUT;
 }
 
-static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter,
-                             struct i2c_msg *msgs,
-                             int num)
+static int sh_mobile_xfer(struct sh_mobile_i2c_data *pd,
+                        struct i2c_msg *msgs, int num)
 {
-       struct sh_mobile_i2c_data *pd = i2c_get_adapdata(adapter);
        struct i2c_msg  *msg;
        int err = 0;
        int i;
-       long timeout;
+       long time_left;
 
        /* Wake up device and enable clock */
        pm_runtime_get_sync(pd->dev);
@@ -662,15 +667,35 @@ static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter,
                if (do_start)
                        i2c_op(pd, OP_START);
 
-               /* The interrupt handler takes care of the rest... */
-               timeout = wait_event_timeout(pd->wait,
-                                      pd->sr & (ICSR_TACK | SW_DONE),
-                                      adapter->timeout);
-
-               /* 'stop_after_dma' tells if DMA transfer was complete */
-               i2c_put_dma_safe_msg_buf(pd->dma_buf, pd->msg, pd->stop_after_dma);
+               if (pd->atomic_xfer) {
+                       unsigned long j = jiffies + pd->adap.timeout;
+
+                       time_left = time_before_eq(jiffies, j);
+                       while (time_left &&
+                              !(pd->sr & (ICSR_TACK | SW_DONE))) {
+                               unsigned char sr = iic_rd(pd, ICSR);
+
+                               if (sr & (ICSR_AL   | ICSR_TACK |
+                                         ICSR_WAIT | ICSR_DTE)) {
+                                       sh_mobile_i2c_isr(0, pd);
+                                       udelay(150);
+                               } else {
+                                       cpu_relax();
+                               }
+                               time_left = time_before_eq(jiffies, j);
+                       }
+               } else {
+                       /* The interrupt handler takes care of the rest... */
+                       time_left = wait_event_timeout(pd->wait,
+                                       pd->sr & (ICSR_TACK | SW_DONE),
+                                       pd->adap.timeout);
+
+                       /* 'stop_after_dma' tells if DMA xfer was complete */
+                       i2c_put_dma_safe_msg_buf(pd->dma_buf, pd->msg,
+                                                pd->stop_after_dma);
+               }
 
-               if (!timeout) {
+               if (!time_left) {
                        dev_err(pd->dev, "Transfer request timed out\n");
                        if (pd->dma_direction != DMA_NONE)
                                sh_mobile_i2c_cleanup_dma(pd);
@@ -696,14 +721,35 @@ static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter,
        return err ?: num;
 }
 
+static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter,
+                             struct i2c_msg *msgs,
+                             int num)
+{
+       struct sh_mobile_i2c_data *pd = i2c_get_adapdata(adapter);
+
+       pd->atomic_xfer = false;
+       return sh_mobile_xfer(pd, msgs, num);
+}
+
+static int sh_mobile_i2c_xfer_atomic(struct i2c_adapter *adapter,
+                                    struct i2c_msg *msgs,
+                                    int num)
+{
+       struct sh_mobile_i2c_data *pd = i2c_get_adapdata(adapter);
+
+       pd->atomic_xfer = true;
+       return sh_mobile_xfer(pd, msgs, num);
+}
+
 static u32 sh_mobile_i2c_func(struct i2c_adapter *adapter)
 {
        return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_PROTOCOL_MANGLING;
 }
 
 static const struct i2c_algorithm sh_mobile_i2c_algorithm = {
-       .functionality  = sh_mobile_i2c_func,
-       .master_xfer    = sh_mobile_i2c_xfer,
+       .functionality = sh_mobile_i2c_func,
+       .master_xfer = sh_mobile_i2c_xfer,
+       .master_xfer_atomic = sh_mobile_i2c_xfer_atomic,
 };
 
 static const struct i2c_adapter_quirks sh_mobile_i2c_quirks = {
index beb38d9..560a337 100644 (file)
@@ -126,6 +126,12 @@ enum kx_chipset {
        KX_MAX_CHIPS /* this must be last */
 };
 
+enum kx_acpi_type {
+       ACPI_GENERIC,
+       ACPI_SMO8500,
+       ACPI_KIOX010A,
+};
+
 struct kxcjk1013_data {
        struct i2c_client *client;
        struct iio_trigger *dready_trig;
@@ -143,7 +149,7 @@ struct kxcjk1013_data {
        bool motion_trigger_on;
        int64_t timestamp;
        enum kx_chipset chipset;
-       bool is_smo8500_device;
+       enum kx_acpi_type acpi_type;
 };
 
 enum kxcjk1013_axis {
@@ -270,6 +276,32 @@ static const struct {
                              {19163, 1, 0},
                              {38326, 0, 1} };
 
+#ifdef CONFIG_ACPI
+enum kiox010a_fn_index {
+       KIOX010A_SET_LAPTOP_MODE = 1,
+       KIOX010A_SET_TABLET_MODE = 2,
+};
+
+static int kiox010a_dsm(struct device *dev, int fn_index)
+{
+       acpi_handle handle = ACPI_HANDLE(dev);
+       guid_t kiox010a_dsm_guid;
+       union acpi_object *obj;
+
+       if (!handle)
+               return -ENODEV;
+
+       guid_parse("1f339696-d475-4e26-8cad-2e9f8e6d7a91", &kiox010a_dsm_guid);
+
+       obj = acpi_evaluate_dsm(handle, &kiox010a_dsm_guid, 1, fn_index, NULL);
+       if (!obj)
+               return -EIO;
+
+       ACPI_FREE(obj);
+       return 0;
+}
+#endif
+
 static int kxcjk1013_set_mode(struct kxcjk1013_data *data,
                              enum kxcjk1013_mode mode)
 {
@@ -347,6 +379,13 @@ static int kxcjk1013_chip_init(struct kxcjk1013_data *data)
 {
        int ret;
 
+#ifdef CONFIG_ACPI
+       if (data->acpi_type == ACPI_KIOX010A) {
+               /* Make sure the kbd and touchpad on 2-in-1s using 2 KXCJ91008-s work */
+               kiox010a_dsm(&data->client->dev, KIOX010A_SET_LAPTOP_MODE);
+       }
+#endif
+
        ret = i2c_smbus_read_byte_data(data->client, KXCJK1013_REG_WHO_AM_I);
        if (ret < 0) {
                dev_err(&data->client->dev, "Error reading who_am_i\n");
@@ -1247,7 +1286,7 @@ static irqreturn_t kxcjk1013_data_rdy_trig_poll(int irq, void *private)
 
 static const char *kxcjk1013_match_acpi_device(struct device *dev,
                                               enum kx_chipset *chipset,
-                                              bool *is_smo8500_device)
+                                              enum kx_acpi_type *acpi_type)
 {
        const struct acpi_device_id *id;
 
@@ -1256,7 +1295,9 @@ static const char *kxcjk1013_match_acpi_device(struct device *dev,
                return NULL;
 
        if (strcmp(id->id, "SMO8500") == 0)
-               *is_smo8500_device = true;
+               *acpi_type = ACPI_SMO8500;
+       else if (strcmp(id->id, "KIOX010A") == 0)
+               *acpi_type = ACPI_KIOX010A;
 
        *chipset = (enum kx_chipset)id->driver_data;
 
@@ -1299,7 +1340,7 @@ static int kxcjk1013_probe(struct i2c_client *client,
        } else if (ACPI_HANDLE(&client->dev)) {
                name = kxcjk1013_match_acpi_device(&client->dev,
                                                   &data->chipset,
-                                                  &data->is_smo8500_device);
+                                                  &data->acpi_type);
        } else
                return -ENODEV;
 
@@ -1316,7 +1357,7 @@ static int kxcjk1013_probe(struct i2c_client *client,
        indio_dev->modes = INDIO_DIRECT_MODE;
        indio_dev->info = &kxcjk1013_info;
 
-       if (client->irq > 0 && !data->is_smo8500_device) {
+       if (client->irq > 0 && data->acpi_type != ACPI_SMO8500) {
                ret = devm_request_threaded_irq(&client->dev, client->irq,
                                                kxcjk1013_data_rdy_trig_poll,
                                                kxcjk1013_event_handler,
index 92b2508..1aafbe2 100644 (file)
@@ -71,7 +71,7 @@
 #define JZ4725B_ADC_BATTERY_HIGH_VREF_BITS     10
 #define JZ4740_ADC_BATTERY_HIGH_VREF           (7500 * 0.986)
 #define JZ4740_ADC_BATTERY_HIGH_VREF_BITS      12
-#define JZ4770_ADC_BATTERY_VREF                        6600
+#define JZ4770_ADC_BATTERY_VREF                        1200
 #define JZ4770_ADC_BATTERY_VREF_BITS           12
 
 #define JZ_ADC_IRQ_AUX                 BIT(0)
@@ -177,13 +177,12 @@ static void ingenic_adc_set_config(struct ingenic_adc *adc,
        mutex_unlock(&adc->lock);
 }
 
-static void ingenic_adc_enable(struct ingenic_adc *adc,
-                              int engine,
-                              bool enabled)
+static void ingenic_adc_enable_unlocked(struct ingenic_adc *adc,
+                                       int engine,
+                                       bool enabled)
 {
        u8 val;
 
-       mutex_lock(&adc->lock);
        val = readb(adc->base + JZ_ADC_REG_ENABLE);
 
        if (enabled)
@@ -192,20 +191,41 @@ static void ingenic_adc_enable(struct ingenic_adc *adc,
                val &= ~BIT(engine);
 
        writeb(val, adc->base + JZ_ADC_REG_ENABLE);
+}
+
+static void ingenic_adc_enable(struct ingenic_adc *adc,
+                              int engine,
+                              bool enabled)
+{
+       mutex_lock(&adc->lock);
+       ingenic_adc_enable_unlocked(adc, engine, enabled);
        mutex_unlock(&adc->lock);
 }
 
 static int ingenic_adc_capture(struct ingenic_adc *adc,
                               int engine)
 {
+       u32 cfg;
        u8 val;
        int ret;
 
-       ingenic_adc_enable(adc, engine, true);
+       /*
+        * Disable CMD_SEL temporarily, because it causes wrong VBAT readings,
+        * probably due to the switch of VREF. We must keep the lock here to
+        * avoid races with the buffer enable/disable functions.
+        */
+       mutex_lock(&adc->lock);
+       cfg = readl(adc->base + JZ_ADC_REG_CFG);
+       writel(cfg & ~JZ_ADC_REG_CFG_CMD_SEL, adc->base + JZ_ADC_REG_CFG);
+
+       ingenic_adc_enable_unlocked(adc, engine, true);
        ret = readb_poll_timeout(adc->base + JZ_ADC_REG_ENABLE, val,
                                 !(val & BIT(engine)), 250, 1000);
        if (ret)
-               ingenic_adc_enable(adc, engine, false);
+               ingenic_adc_enable_unlocked(adc, engine, false);
+
+       writel(cfg, adc->base + JZ_ADC_REG_CFG);
+       mutex_unlock(&adc->lock);
 
        return ret;
 }
index ac415cb..79c1dd6 100644 (file)
@@ -9,9 +9,9 @@
 #include <linux/err.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/of.h>
-#include <linux/of_device.h>
+#include <linux/mod_devicetable.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/iopoll.h>
 #include <linux/io.h>
 #include <linux/iio/iio.h>
@@ -276,6 +276,8 @@ static int mt6577_auxadc_probe(struct platform_device *pdev)
                goto err_disable_clk;
        }
 
+       adc_dev->dev_comp = device_get_match_data(&pdev->dev);
+
        mutex_init(&adc_dev->lock);
 
        mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC,
index cd870c0..a83199b 100644 (file)
  * struct stm32_adc_common_regs - stm32 common registers
  * @csr:       common status register offset
  * @ccr:       common control register offset
- * @eoc1_msk:  adc1 end of conversion flag in @csr
- * @eoc2_msk:  adc2 end of conversion flag in @csr
- * @eoc3_msk:  adc3 end of conversion flag in @csr
+ * @eoc_msk:    array of eoc (end of conversion flag) masks in csr for adc1..n
+ * @ovr_msk:    array of ovr (overrun flag) masks in csr for adc1..n
  * @ier:       interrupt enable register offset for each adc
  * @eocie_msk: end of conversion interrupt enable mask in @ier
  */
 struct stm32_adc_common_regs {
        u32 csr;
        u32 ccr;
-       u32 eoc1_msk;
-       u32 eoc2_msk;
-       u32 eoc3_msk;
+       u32 eoc_msk[STM32_ADC_MAX_ADCS];
+       u32 ovr_msk[STM32_ADC_MAX_ADCS];
        u32 ier;
        u32 eocie_msk;
 };
@@ -282,21 +280,20 @@ out:
 static const struct stm32_adc_common_regs stm32f4_adc_common_regs = {
        .csr = STM32F4_ADC_CSR,
        .ccr = STM32F4_ADC_CCR,
-       .eoc1_msk = STM32F4_EOC1 | STM32F4_OVR1,
-       .eoc2_msk = STM32F4_EOC2 | STM32F4_OVR2,
-       .eoc3_msk = STM32F4_EOC3 | STM32F4_OVR3,
+       .eoc_msk = { STM32F4_EOC1, STM32F4_EOC2, STM32F4_EOC3},
+       .ovr_msk = { STM32F4_OVR1, STM32F4_OVR2, STM32F4_OVR3},
        .ier = STM32F4_ADC_CR1,
-       .eocie_msk = STM32F4_EOCIE | STM32F4_OVRIE,
+       .eocie_msk = STM32F4_EOCIE,
 };
 
 /* STM32H7 common registers definitions */
 static const struct stm32_adc_common_regs stm32h7_adc_common_regs = {
        .csr = STM32H7_ADC_CSR,
        .ccr = STM32H7_ADC_CCR,
-       .eoc1_msk = STM32H7_EOC_MST | STM32H7_OVR_MST,
-       .eoc2_msk = STM32H7_EOC_SLV | STM32H7_OVR_SLV,
+       .eoc_msk = { STM32H7_EOC_MST, STM32H7_EOC_SLV},
+       .ovr_msk = { STM32H7_OVR_MST, STM32H7_OVR_SLV},
        .ier = STM32H7_ADC_IER,
-       .eocie_msk = STM32H7_EOCIE | STM32H7_OVRIE,
+       .eocie_msk = STM32H7_EOCIE,
 };
 
 static const unsigned int stm32_adc_offset[STM32_ADC_MAX_ADCS] = {
@@ -318,6 +315,7 @@ static void stm32_adc_irq_handler(struct irq_desc *desc)
 {
        struct stm32_adc_priv *priv = irq_desc_get_handler_data(desc);
        struct irq_chip *chip = irq_desc_get_chip(desc);
+       int i;
        u32 status;
 
        chained_irq_enter(chip, desc);
@@ -335,17 +333,12 @@ static void stm32_adc_irq_handler(struct irq_desc *desc)
         * before invoking the interrupt handler (e.g. call ISR only for
         * IRQ-enabled ADCs).
         */
-       if (status & priv->cfg->regs->eoc1_msk &&
-           stm32_adc_eoc_enabled(priv, 0))
-               generic_handle_irq(irq_find_mapping(priv->domain, 0));
-
-       if (status & priv->cfg->regs->eoc2_msk &&
-           stm32_adc_eoc_enabled(priv, 1))
-               generic_handle_irq(irq_find_mapping(priv->domain, 1));
-
-       if (status & priv->cfg->regs->eoc3_msk &&
-           stm32_adc_eoc_enabled(priv, 2))
-               generic_handle_irq(irq_find_mapping(priv->domain, 2));
+       for (i = 0; i < priv->cfg->num_irqs; i++) {
+               if ((status & priv->cfg->regs->eoc_msk[i] &&
+                    stm32_adc_eoc_enabled(priv, i)) ||
+                    (status & priv->cfg->regs->ovr_msk[i]))
+                       generic_handle_irq(irq_find_mapping(priv->domain, i));
+       }
 
        chained_irq_exit(chip, desc);
 };
index b3f31f1..16c02c3 100644 (file)
@@ -154,6 +154,7 @@ struct stm32_adc;
  * @start_conv:                routine to start conversions
  * @stop_conv:         routine to stop conversions
  * @unprepare:         optional unprepare routine (disable, power-down)
+ * @irq_clear:         routine to clear irqs
  * @smp_cycles:                programmable sampling time (ADC clock cycles)
  */
 struct stm32_adc_cfg {
@@ -166,6 +167,7 @@ struct stm32_adc_cfg {
        void (*start_conv)(struct iio_dev *, bool dma);
        void (*stop_conv)(struct iio_dev *);
        void (*unprepare)(struct iio_dev *);
+       void (*irq_clear)(struct iio_dev *indio_dev, u32 msk);
        const unsigned int *smp_cycles;
 };
 
@@ -621,6 +623,13 @@ static void stm32f4_adc_stop_conv(struct iio_dev *indio_dev)
                           STM32F4_ADON | STM32F4_DMA | STM32F4_DDS);
 }
 
+static void stm32f4_adc_irq_clear(struct iio_dev *indio_dev, u32 msk)
+{
+       struct stm32_adc *adc = iio_priv(indio_dev);
+
+       stm32_adc_clr_bits(adc, adc->cfg->regs->isr_eoc.reg, msk);
+}
+
 static void stm32h7_adc_start_conv(struct iio_dev *indio_dev, bool dma)
 {
        struct stm32_adc *adc = iio_priv(indio_dev);
@@ -659,6 +668,13 @@ static void stm32h7_adc_stop_conv(struct iio_dev *indio_dev)
        stm32_adc_clr_bits(adc, STM32H7_ADC_CFGR, STM32H7_DMNGT_MASK);
 }
 
+static void stm32h7_adc_irq_clear(struct iio_dev *indio_dev, u32 msk)
+{
+       struct stm32_adc *adc = iio_priv(indio_dev);
+       /* On STM32H7 IRQs are cleared by writing 1 into ISR register */
+       stm32_adc_set_bits(adc, adc->cfg->regs->isr_eoc.reg, msk);
+}
+
 static int stm32h7_adc_exit_pwr_down(struct iio_dev *indio_dev)
 {
        struct stm32_adc *adc = iio_priv(indio_dev);
@@ -1235,17 +1251,40 @@ static int stm32_adc_read_raw(struct iio_dev *indio_dev,
        }
 }
 
+static void stm32_adc_irq_clear(struct iio_dev *indio_dev, u32 msk)
+{
+       struct stm32_adc *adc = iio_priv(indio_dev);
+
+       adc->cfg->irq_clear(indio_dev, msk);
+}
+
 static irqreturn_t stm32_adc_threaded_isr(int irq, void *data)
 {
        struct iio_dev *indio_dev = data;
        struct stm32_adc *adc = iio_priv(indio_dev);
        const struct stm32_adc_regspec *regs = adc->cfg->regs;
        u32 status = stm32_adc_readl(adc, regs->isr_eoc.reg);
+       u32 mask = stm32_adc_readl(adc, regs->ier_eoc.reg);
 
-       if (status & regs->isr_ovr.mask)
+       /* Check ovr status right now, as ovr mask should be already disabled */
+       if (status & regs->isr_ovr.mask) {
+               /*
+                * Clear ovr bit to avoid subsequent calls to IRQ handler.
+                * This requires to stop ADC first. OVR bit state in ISR,
+                * is propaged to CSR register by hardware.
+                */
+               adc->cfg->stop_conv(indio_dev);
+               stm32_adc_irq_clear(indio_dev, regs->isr_ovr.mask);
                dev_err(&indio_dev->dev, "Overrun, stopping: restart needed\n");
+               return IRQ_HANDLED;
+       }
 
-       return IRQ_HANDLED;
+       if (!(status & mask))
+               dev_err_ratelimited(&indio_dev->dev,
+                                   "Unexpected IRQ: IER=0x%08x, ISR=0x%08x\n",
+                                   mask, status);
+
+       return IRQ_NONE;
 }
 
 static irqreturn_t stm32_adc_isr(int irq, void *data)
@@ -1254,6 +1293,10 @@ static irqreturn_t stm32_adc_isr(int irq, void *data)
        struct stm32_adc *adc = iio_priv(indio_dev);
        const struct stm32_adc_regspec *regs = adc->cfg->regs;
        u32 status = stm32_adc_readl(adc, regs->isr_eoc.reg);
+       u32 mask = stm32_adc_readl(adc, regs->ier_eoc.reg);
+
+       if (!(status & mask))
+               return IRQ_WAKE_THREAD;
 
        if (status & regs->isr_ovr.mask) {
                /*
@@ -2046,6 +2089,7 @@ static const struct stm32_adc_cfg stm32f4_adc_cfg = {
        .start_conv = stm32f4_adc_start_conv,
        .stop_conv = stm32f4_adc_stop_conv,
        .smp_cycles = stm32f4_adc_smp_cycles,
+       .irq_clear = stm32f4_adc_irq_clear,
 };
 
 static const struct stm32_adc_cfg stm32h7_adc_cfg = {
@@ -2057,6 +2101,7 @@ static const struct stm32_adc_cfg stm32h7_adc_cfg = {
        .prepare = stm32h7_adc_prepare,
        .unprepare = stm32h7_adc_unprepare,
        .smp_cycles = stm32h7_adc_smp_cycles,
+       .irq_clear = stm32h7_adc_irq_clear,
 };
 
 static const struct stm32_adc_cfg stm32mp1_adc_cfg = {
@@ -2069,6 +2114,7 @@ static const struct stm32_adc_cfg stm32mp1_adc_cfg = {
        .prepare = stm32h7_adc_prepare,
        .unprepare = stm32h7_adc_unprepare,
        .smp_cycles = stm32h7_adc_smp_cycles,
+       .irq_clear = stm32h7_adc_irq_clear,
 };
 
 static const struct of_device_id stm32_adc_of_match[] = {
index c62cacc..e3f5077 100644 (file)
@@ -256,7 +256,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
        struct cros_ec_sensorhub *sensor_hub = dev_get_drvdata(dev->parent);
        struct cros_ec_dev *ec = sensor_hub->ec;
        struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
-       u32 ver_mask;
+       u32 ver_mask, temp;
        int frequencies[ARRAY_SIZE(state->frequencies) / 2] = { 0 };
        int ret, i;
 
@@ -311,10 +311,16 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
                                                 &frequencies[2],
                                                 &state->fifo_max_event_count);
                } else {
-                       frequencies[1] = state->resp->info_3.min_frequency;
-                       frequencies[2] = state->resp->info_3.max_frequency;
-                       state->fifo_max_event_count =
-                           state->resp->info_3.fifo_max_event_count;
+                       if (state->resp->info_3.max_frequency == 0) {
+                               get_default_min_max_freq(state->resp->info.type,
+                                                        &frequencies[1],
+                                                        &frequencies[2],
+                                                        &temp);
+                       } else {
+                               frequencies[1] = state->resp->info_3.min_frequency;
+                               frequencies[2] = state->resp->info_3.max_frequency;
+                       }
+                       state->fifo_max_event_count = state->resp->info_3.fifo_max_event_count;
                }
                for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
                        state->frequencies[2 * i] = frequencies[i] / 1000;
index 8c8d887..99562ba 100644 (file)
@@ -156,11 +156,13 @@ static const struct st_lsm6dsx_ext_dev_settings st_lsm6dsx_ext_dev_table[] = {
 static void st_lsm6dsx_shub_wait_complete(struct st_lsm6dsx_hw *hw)
 {
        struct st_lsm6dsx_sensor *sensor;
-       u32 odr;
+       u32 odr, timeout;
 
        sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
        odr = (hw->enable_mask & BIT(ST_LSM6DSX_ID_ACC)) ? sensor->odr : 12500;
-       msleep((2000000U / odr) + 1);
+       /* set 10ms as minimum timeout for i2c slave configuration */
+       timeout = max_t(u32, 2000000U / odr + 1, 10);
+       msleep(timeout);
 }
 
 /*
index cade6dc..33ad4dd 100644 (file)
@@ -544,6 +544,7 @@ config VCNL4000
 
 config VCNL4035
        tristate "VCNL4035 combined ALS and proximity sensor"
+       select IIO_BUFFER
        select IIO_TRIGGERED_BUFFER
        select REGMAP_I2C
        depends on I2C
index 32a5143..9325e18 100644 (file)
@@ -73,6 +73,9 @@ config INFINIBAND_ADDR_TRANS_CONFIGFS
          This allows the user to config the default GID type that the CM
          uses for each device, when initiaing new connections.
 
+config INFINIBAND_VIRT_DMA
+       def_bool !HIGHMEM
+
 if INFINIBAND_USER_ACCESS || !INFINIBAND_USER_ACCESS
 source "drivers/infiniband/hw/mthca/Kconfig"
 source "drivers/infiniband/hw/qib/Kconfig"
index 5740d1b..0121566 100644 (file)
@@ -859,8 +859,8 @@ static struct cm_id_private *cm_alloc_id_priv(struct ib_device *device,
        atomic_set(&cm_id_priv->work_count, -1);
        refcount_set(&cm_id_priv->refcount, 1);
 
-       ret = xa_alloc_cyclic_irq(&cm.local_id_table, &id, NULL, xa_limit_32b,
-                                 &cm.local_id_next, GFP_KERNEL);
+       ret = xa_alloc_cyclic(&cm.local_id_table, &id, NULL, xa_limit_32b,
+                             &cm.local_id_next, GFP_KERNEL);
        if (ret < 0)
                goto error;
        cm_id_priv->id.local_id = (__force __be32)id ^ cm.random_id_operand;
@@ -878,8 +878,8 @@ error:
  */
 static void cm_finalize_id(struct cm_id_private *cm_id_priv)
 {
-       xa_store_irq(&cm.local_id_table, cm_local_id(cm_id_priv->id.local_id),
-                    cm_id_priv, GFP_KERNEL);
+       xa_store(&cm.local_id_table, cm_local_id(cm_id_priv->id.local_id),
+                cm_id_priv, GFP_ATOMIC);
 }
 
 struct ib_cm_id *ib_create_cm_id(struct ib_device *device,
@@ -1169,7 +1169,7 @@ retest:
        spin_unlock(&cm.lock);
        spin_unlock_irq(&cm_id_priv->lock);
 
-       xa_erase_irq(&cm.local_id_table, cm_local_id(cm_id->local_id));
+       xa_erase(&cm.local_id_table, cm_local_id(cm_id->local_id));
        cm_deref_id(cm_id_priv);
        wait_for_completion(&cm_id_priv->comp);
        while ((work = cm_dequeue_work(cm_id_priv)) != NULL)
@@ -4482,7 +4482,7 @@ static int __init ib_cm_init(void)
        cm.remote_id_table = RB_ROOT;
        cm.remote_qp_table = RB_ROOT;
        cm.remote_sidr_table = RB_ROOT;
-       xa_init_flags(&cm.local_id_table, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ);
+       xa_init_flags(&cm.local_id_table, XA_FLAGS_ALLOC);
        get_random_bytes(&cm.random_id_operand, sizeof cm.random_id_operand);
        INIT_LIST_HEAD(&cm.timewait_list);
 
index 7eaf995..c87b94e 100644 (file)
@@ -15245,7 +15245,8 @@ int hfi1_init_dd(struct hfi1_devdata *dd)
                    & CCE_REVISION_SW_MASK);
 
        /* alloc netdev data */
-       if (hfi1_netdev_alloc(dd))
+       ret = hfi1_netdev_alloc(dd);
+       if (ret)
                goto bail_cleanup;
 
        ret = set_up_context_variables(dd);
index fa2a3fa..6895bac 100644 (file)
@@ -266,7 +266,7 @@ static int pvrdma_register_device(struct pvrdma_dev *dev)
        }
        ret = ib_device_set_netdev(&dev->ib_dev, dev->netdev, 1);
        if (ret)
-               return ret;
+               goto err_srq_free;
        spin_lock_init(&dev->srq_tbl_lock);
        rdma_set_device_sysfs_group(&dev->ib_dev, &pvrdma_attr_group);
 
index f0e5ffb..97ed8f9 100644 (file)
@@ -176,7 +176,7 @@ struct pvrdma_port_attr {
        u8                      subnet_timeout;
        u8                      init_type_reply;
        u8                      active_width;
-       u16                     active_speed;
+       u                     active_speed;
        u8                      phys_state;
        u8                      reserved[2];
 };
index 9ef5f5c..c8e2680 100644 (file)
@@ -1,7 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config INFINIBAND_RDMAVT
        tristate "RDMA verbs transport library"
-       depends on X86_64 && ARCH_DMA_ADDR_T_64BIT
+       depends on INFINIBAND_VIRT_DMA
+       depends on X86_64
        depends on PCI
        select DMA_VIRT_OPS
        help
index 5221868..670a962 100644 (file)
@@ -524,6 +524,7 @@ static noinline int check_support(struct rvt_dev_info *rdi, int verb)
 int rvt_register_device(struct rvt_dev_info *rdi)
 {
        int ret = 0, i;
+       u64 dma_mask;
 
        if (!rdi)
                return -EINVAL;
@@ -580,8 +581,10 @@ int rvt_register_device(struct rvt_dev_info *rdi)
 
        /* DMA Operations */
        rdi->ibdev.dev.dma_parms = rdi->ibdev.dev.parent->dma_parms;
-       dma_set_coherent_mask(&rdi->ibdev.dev,
-                             rdi->ibdev.dev.parent->coherent_dma_mask);
+       dma_mask = IS_ENABLED(CONFIG_64BIT) ? DMA_BIT_MASK(64) : DMA_BIT_MASK(32);
+       ret = dma_coerce_mask_and_coherent(&rdi->ibdev.dev, dma_mask);
+       if (ret)
+               goto bail_wss;
 
        /* Protection Domain */
        spin_lock_init(&rdi->n_pds_lock);
index a0c6c7d..8810bfa 100644 (file)
@@ -2,7 +2,7 @@
 config RDMA_RXE
        tristate "Software RDMA over Ethernet (RoCE) driver"
        depends on INET && PCI && INFINIBAND
-       depends on !64BIT || ARCH_DMA_ADDR_T_64BIT
+       depends on INFINIBAND_VIRT_DMA
        select NET_UDP_TUNNEL
        select CRYPTO_CRC32
        select DMA_VIRT_OPS
index 1fc0223..f9c832e 100644 (file)
@@ -1118,6 +1118,7 @@ int rxe_register_device(struct rxe_dev *rxe, const char *ibdev_name)
        int err;
        struct ib_device *dev = &rxe->ib_dev;
        struct crypto_shash *tfm;
+       u64 dma_mask;
 
        strlcpy(dev->node_desc, "rxe", sizeof(dev->node_desc));
 
@@ -1130,7 +1131,10 @@ int rxe_register_device(struct rxe_dev *rxe, const char *ibdev_name)
                            rxe->ndev->dev_addr);
        dev->dev.dma_parms = &rxe->dma_parms;
        dma_set_max_seg_size(&dev->dev, UINT_MAX);
-       dma_set_coherent_mask(&dev->dev, dma_get_required_mask(&dev->dev));
+       dma_mask = IS_ENABLED(CONFIG_64BIT) ? DMA_BIT_MASK(64) : DMA_BIT_MASK(32);
+       err = dma_coerce_mask_and_coherent(&dev->dev, dma_mask);
+       if (err)
+               return err;
 
        dev->uverbs_cmd_mask = BIT_ULL(IB_USER_VERBS_CMD_GET_CONTEXT)
            | BIT_ULL(IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL)
index b622fc6..3450ba5 100644 (file)
@@ -1,6 +1,7 @@
 config RDMA_SIW
        tristate "Software RDMA over TCP/IP (iWARP) driver"
        depends on INET && INFINIBAND && LIBCRC32C
+       depends on INFINIBAND_VIRT_DMA
        select DMA_VIRT_OPS
        help
        This driver implements the iWARP RDMA transport over
index ca8bc72..181e06c 100644 (file)
@@ -306,6 +306,7 @@ static struct siw_device *siw_device_create(struct net_device *netdev)
        struct siw_device *sdev = NULL;
        struct ib_device *base_dev;
        struct device *parent = netdev->dev.parent;
+       u64 dma_mask;
        int rv;
 
        if (!parent) {
@@ -384,8 +385,10 @@ static struct siw_device *siw_device_create(struct net_device *netdev)
        base_dev->dev.parent = parent;
        base_dev->dev.dma_parms = &sdev->dma_parms;
        dma_set_max_seg_size(&base_dev->dev, UINT_MAX);
-       dma_set_coherent_mask(&base_dev->dev,
-                             dma_get_required_mask(&base_dev->dev));
+       dma_mask = IS_ENABLED(CONFIG_64BIT) ? DMA_BIT_MASK(64) : DMA_BIT_MASK(32);
+       if (dma_coerce_mask_and_coherent(&base_dev->dev, dma_mask))
+               goto error;
+
        base_dev->num_comp_vectors = num_possible_cpus();
 
        xa_init_flags(&sdev->qp_xa, XA_FLAGS_ALLOC1);
index 0065eb1..53a8bec 100644 (file)
@@ -622,10 +622,11 @@ static int srpt_refresh_port(struct srpt_port *sport)
 /**
  * srpt_unregister_mad_agent - unregister MAD callback functions
  * @sdev: SRPT HCA pointer.
+ * @port_cnt: number of ports with registered MAD
  *
  * Note: It is safe to call this function more than once for the same device.
  */
-static void srpt_unregister_mad_agent(struct srpt_device *sdev)
+static void srpt_unregister_mad_agent(struct srpt_device *sdev, int port_cnt)
 {
        struct ib_port_modify port_modify = {
                .clr_port_cap_mask = IB_PORT_DEVICE_MGMT_SUP,
@@ -633,7 +634,7 @@ static void srpt_unregister_mad_agent(struct srpt_device *sdev)
        struct srpt_port *sport;
        int i;
 
-       for (i = 1; i <= sdev->device->phys_port_cnt; i++) {
+       for (i = 1; i <= port_cnt; i++) {
                sport = &sdev->port[i - 1];
                WARN_ON(sport->port != i);
                if (sport->mad_agent) {
@@ -3185,7 +3186,8 @@ static int srpt_add_one(struct ib_device *device)
                if (ret) {
                        pr_err("MAD registration failed for %s-%d.\n",
                               dev_name(&sdev->device->dev), i);
-                       goto err_event;
+                       i--;
+                       goto err_port;
                }
        }
 
@@ -3197,7 +3199,8 @@ static int srpt_add_one(struct ib_device *device)
        pr_debug("added %s.\n", dev_name(&device->dev));
        return 0;
 
-err_event:
+err_port:
+       srpt_unregister_mad_agent(sdev, i);
        ib_unregister_event_handler(&sdev->event_handler);
 err_cm:
        if (sdev->cm_id)
@@ -3221,7 +3224,7 @@ static void srpt_remove_one(struct ib_device *device, void *client_data)
        struct srpt_device *sdev = client_data;
        int i;
 
-       srpt_unregister_mad_agent(sdev);
+       srpt_unregister_mad_agent(sdev, sdev->device->phys_port_cnt);
 
        ib_unregister_event_handler(&sdev->event_handler);
 
index 41435a6..bdeb010 100644 (file)
@@ -256,6 +256,7 @@ enum rdma_ch_state {
  * @rdma_cm:      See below.
  * @rdma_cm.cm_id: RDMA CM ID associated with the channel.
  * @cq:            IB completion queue for this channel.
+ * @cq_size:      Number of CQEs in @cq.
  * @zw_cqe:       Zero-length write CQE.
  * @rcu:           RCU head.
  * @kref:         kref for this channel.
index 27126e6..d450f11 100644 (file)
@@ -99,7 +99,8 @@ static irqreturn_t sunkbd_interrupt(struct serio *serio,
        switch (data) {
 
        case SUNKBD_RET_RESET:
-               schedule_work(&sunkbd->tq);
+               if (sunkbd->enabled)
+                       schedule_work(&sunkbd->tq);
                sunkbd->reset = -1;
                break;
 
@@ -200,16 +201,12 @@ static int sunkbd_initialize(struct sunkbd *sunkbd)
 }
 
 /*
- * sunkbd_reinit() sets leds and beeps to a state the computer remembers they
- * were in.
+ * sunkbd_set_leds_beeps() sets leds and beeps to a state the computer remembers
+ * they were in.
  */
 
-static void sunkbd_reinit(struct work_struct *work)
+static void sunkbd_set_leds_beeps(struct sunkbd *sunkbd)
 {
-       struct sunkbd *sunkbd = container_of(work, struct sunkbd, tq);
-
-       wait_event_interruptible_timeout(sunkbd->wait, sunkbd->reset >= 0, HZ);
-
        serio_write(sunkbd->serio, SUNKBD_CMD_SETLED);
        serio_write(sunkbd->serio,
                (!!test_bit(LED_CAPSL,   sunkbd->dev->led) << 3) |
@@ -222,11 +219,39 @@ static void sunkbd_reinit(struct work_struct *work)
                SUNKBD_CMD_BELLOFF - !!test_bit(SND_BELL, sunkbd->dev->snd));
 }
 
+
+/*
+ * sunkbd_reinit() wait for the keyboard reset to complete and restores state
+ * of leds and beeps.
+ */
+
+static void sunkbd_reinit(struct work_struct *work)
+{
+       struct sunkbd *sunkbd = container_of(work, struct sunkbd, tq);
+
+       /*
+        * It is OK that we check sunkbd->enabled without pausing serio,
+        * as we only want to catch true->false transition that will
+        * happen once and we will be woken up for it.
+        */
+       wait_event_interruptible_timeout(sunkbd->wait,
+                                        sunkbd->reset >= 0 || !sunkbd->enabled,
+                                        HZ);
+
+       if (sunkbd->reset >= 0 && sunkbd->enabled)
+               sunkbd_set_leds_beeps(sunkbd);
+}
+
 static void sunkbd_enable(struct sunkbd *sunkbd, bool enable)
 {
        serio_pause_rx(sunkbd->serio);
        sunkbd->enabled = enable;
        serio_continue_rx(sunkbd->serio);
+
+       if (!enable) {
+               wake_up_interruptible(&sunkbd->wait);
+               cancel_work_sync(&sunkbd->tq);
+       }
 }
 
 /*
index 5fe92d4..4cc4e8f 100644 (file)
@@ -696,7 +696,7 @@ struct adxl34x *adxl34x_probe(struct device *dev, int irq,
        struct input_dev *input_dev;
        const struct adxl34x_platform_data *pdata;
        int err, range, i;
-       unsigned char revid;
+       int revid;
 
        if (!irq) {
                dev_err(dev, "no IRQ?\n");
index c75b00c..36e3cd9 100644 (file)
@@ -78,7 +78,7 @@ struct elan_transport_ops {
        int (*iap_reset)(struct i2c_client *client);
 
        int (*prepare_fw_update)(struct i2c_client *client, u16 ic_type,
-                                u8 iap_version);
+                                u8 iap_version, u16 fw_page_size);
        int (*write_fw_block)(struct i2c_client *client, u16 fw_page_size,
                              const u8 *page, u16 checksum, int idx);
        int (*finish_fw_update)(struct i2c_client *client,
index c599e21..61ed3f5 100644 (file)
@@ -497,7 +497,8 @@ static int __elan_update_firmware(struct elan_tp_data *data,
        u16 sw_checksum = 0, fw_checksum = 0;
 
        error = data->ops->prepare_fw_update(client, data->ic_type,
-                                            data->iap_version);
+                                            data->iap_version,
+                                            data->fw_page_size);
        if (error)
                return error;
 
index 5a496d4..13dc097 100644 (file)
@@ -517,7 +517,7 @@ static int elan_i2c_set_flash_key(struct i2c_client *client)
        return 0;
 }
 
-static int elan_read_write_iap_type(struct i2c_client *client)
+static int elan_read_write_iap_type(struct i2c_client *client, u16 fw_page_size)
 {
        int error;
        u16 constant;
@@ -526,7 +526,7 @@ static int elan_read_write_iap_type(struct i2c_client *client)
 
        do {
                error = elan_i2c_write_cmd(client, ETP_I2C_IAP_TYPE_CMD,
-                                          ETP_I2C_IAP_TYPE_REG);
+                                          fw_page_size / 2);
                if (error) {
                        dev_err(&client->dev,
                                "cannot write iap type: %d\n", error);
@@ -543,7 +543,7 @@ static int elan_read_write_iap_type(struct i2c_client *client)
                constant = le16_to_cpup((__le16 *)val);
                dev_dbg(&client->dev, "iap type reg: 0x%04x\n", constant);
 
-               if (constant == ETP_I2C_IAP_TYPE_REG)
+               if (constant == fw_page_size / 2)
                        return 0;
 
        } while (--retry > 0);
@@ -553,7 +553,7 @@ static int elan_read_write_iap_type(struct i2c_client *client)
 }
 
 static int elan_i2c_prepare_fw_update(struct i2c_client *client, u16 ic_type,
-                                     u8 iap_version)
+                                     u8 iap_version, u16 fw_page_size)
 {
        struct device *dev = &client->dev;
        int error;
@@ -594,7 +594,7 @@ static int elan_i2c_prepare_fw_update(struct i2c_client *client, u16 ic_type,
        }
 
        if (ic_type >= 0x0D && iap_version >= 1) {
-               error = elan_read_write_iap_type(client);
+               error = elan_read_write_iap_type(client, fw_page_size);
                if (error)
                        return error;
        }
index 8ff8237..1820f1c 100644 (file)
@@ -340,7 +340,7 @@ static int elan_smbus_set_flash_key(struct i2c_client *client)
 }
 
 static int elan_smbus_prepare_fw_update(struct i2c_client *client, u16 ic_type,
-                                       u8 iap_version)
+                                       u8 iap_version, u16 fw_page_size)
 {
        struct device *dev = &client->dev;
        int len;
index d3eda48..944cbb5 100644 (file)
@@ -122,6 +122,7 @@ module_param_named(unmask_kbd_data, i8042_unmask_kbd_data, bool, 0600);
 MODULE_PARM_DESC(unmask_kbd_data, "Unconditional enable (may reveal sensitive data) of normally sanitize-filtered kbd data traffic debug log [pre-condition: i8042.debug=1 enabled]");
 #endif
 
+static bool i8042_present;
 static bool i8042_bypass_aux_irq_test;
 static char i8042_kbd_firmware_id[128];
 static char i8042_aux_firmware_id[128];
@@ -343,6 +344,9 @@ int i8042_command(unsigned char *param, int command)
        unsigned long flags;
        int retval;
 
+       if (!i8042_present)
+               return -1;
+
        spin_lock_irqsave(&i8042_lock, flags);
        retval = __i8042_command(param, command);
        spin_unlock_irqrestore(&i8042_lock, flags);
@@ -1612,12 +1616,15 @@ static int __init i8042_init(void)
 
        err = i8042_platform_init();
        if (err)
-               return err;
+               return (err == -ENODEV) ? 0 : err;
 
        err = i8042_controller_check();
        if (err)
                goto err_platform_exit;
 
+       /* Set this before creating the dev to allow i8042_command to work right away */
+       i8042_present = true;
+
        pdev = platform_create_bundle(&i8042_driver, i8042_probe, NULL, 0, NULL, 0);
        if (IS_ERR(pdev)) {
                err = PTR_ERR(pdev);
@@ -1636,6 +1643,9 @@ static int __init i8042_init(void)
 
 static void __exit i8042_exit(void)
 {
+       if (!i8042_present)
+               return;
+
        platform_device_unregister(i8042_platform_device);
        platform_driver_unregister(&i8042_driver);
        i8042_platform_exit();
index f012fe7..cc18f54 100644 (file)
@@ -96,6 +96,7 @@ config TOUCHSCREEN_AD7879_SPI
 config TOUCHSCREEN_ADC
        tristate "Generic ADC based resistive touchscreen"
        depends on IIO
+       select IIO_BUFFER
        select IIO_BUFFER_CB
        help
          Say Y here if you want to use the generic ADC
index f696ac7..8964770 100644 (file)
@@ -409,7 +409,11 @@ extern bool amd_iommu_np_cache;
 /* Only true if all IOMMUs support device IOTLBs */
 extern bool amd_iommu_iotlb_sup;
 
-#define MAX_IRQS_PER_TABLE     256
+/*
+ * AMD IOMMU hardware only support 512 IRTEs despite
+ * the architectural limitation of 2048 entries.
+ */
+#define MAX_IRQS_PER_TABLE     512
 #define IRQ_TABLE_ALIGNMENT    128
 
 struct irq_remap_table {
index 404b40a..11319e4 100644 (file)
@@ -333,6 +333,13 @@ static void  dmar_pci_bus_del_dev(struct dmar_pci_notify_info *info)
        dmar_iommu_notify_scope_dev(info);
 }
 
+static inline void vf_inherit_msi_domain(struct pci_dev *pdev)
+{
+       struct pci_dev *physfn = pci_physfn(pdev);
+
+       dev_set_msi_domain(&pdev->dev, dev_get_msi_domain(&physfn->dev));
+}
+
 static int dmar_pci_bus_notifier(struct notifier_block *nb,
                                 unsigned long action, void *data)
 {
@@ -342,8 +349,20 @@ static int dmar_pci_bus_notifier(struct notifier_block *nb,
        /* Only care about add/remove events for physical functions.
         * For VFs we actually do the lookup based on the corresponding
         * PF in device_to_iommu() anyway. */
-       if (pdev->is_virtfn)
+       if (pdev->is_virtfn) {
+               /*
+                * Ensure that the VF device inherits the irq domain of the
+                * PF device. Ideally the device would inherit the domain
+                * from the bus, but DMAR can have multiple units per bus
+                * which makes this impossible. The VF 'bus' could inherit
+                * from the PF device, but that's yet another x86'sism to
+                * inflict on everybody else.
+                */
+               if (action == BUS_NOTIFY_ADD_DEVICE)
+                       vf_inherit_msi_domain(pdev);
                return NOTIFY_DONE;
+       }
+
        if (action != BUS_NOTIFY_ADD_DEVICE &&
            action != BUS_NOTIFY_REMOVED_DEVICE)
                return NOTIFY_DONE;
index 8651f6d..c71a9c2 100644 (file)
@@ -179,7 +179,7 @@ static int rwbf_quirk;
  * (used when kernel is launched w/ TXT)
  */
 static int force_on = 0;
-int intel_iommu_tboot_noforce;
+static int intel_iommu_tboot_noforce;
 static int no_platform_optin;
 
 #define ROOT_ENTRY_NR (VTD_PAGE_SIZE/sizeof(struct root_entry))
@@ -2525,6 +2525,9 @@ struct dmar_domain *find_domain(struct device *dev)
 {
        struct device_domain_info *info;
 
+       if (unlikely(!dev || !dev->iommu))
+               return NULL;
+
        if (unlikely(attach_deferred(dev)))
                return NULL;
 
@@ -3815,9 +3818,8 @@ bounce_map_single(struct device *dev, phys_addr_t paddr, size_t size,
         * page aligned, we don't need to use a bounce page.
         */
        if (!IS_ALIGNED(paddr | size, VTD_PAGE_SIZE)) {
-               tlb_addr = swiotlb_tbl_map_single(dev,
-                               phys_to_dma_unencrypted(dev, io_tlb_start),
-                               paddr, size, aligned_size, dir, attrs);
+               tlb_addr = swiotlb_tbl_map_single(dev, paddr, size,
+                               aligned_size, dir, attrs);
                if (tlb_addr == DMA_MAPPING_ERROR) {
                        goto swiotlb_error;
                } else {
@@ -4882,7 +4884,8 @@ int __init intel_iommu_init(void)
         * Intel IOMMU is required for a TXT/tboot launch or platform
         * opt in, so enforce that.
         */
-       force_on = tboot_force_iommu() || platform_optin_force_iommu();
+       force_on = (!intel_iommu_tboot_noforce && tboot_force_iommu()) ||
+                   platform_optin_force_iommu();
 
        if (iommu_init_mempool()) {
                if (force_on)
index f1861fa..3242ebd 100644 (file)
@@ -279,6 +279,7 @@ int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev,
        struct intel_iommu *iommu = device_to_iommu(dev, NULL, NULL);
        struct intel_svm_dev *sdev = NULL;
        struct dmar_domain *dmar_domain;
+       struct device_domain_info *info;
        struct intel_svm *svm = NULL;
        int ret = 0;
 
@@ -310,6 +311,10 @@ int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev,
        if (data->hpasid <= 0 || data->hpasid >= PASID_MAX)
                return -EINVAL;
 
+       info = get_domain_info(dev);
+       if (!info)
+               return -EINVAL;
+
        dmar_domain = to_dmar_domain(domain);
 
        mutex_lock(&pasid_mutex);
@@ -357,6 +362,7 @@ int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev,
                goto out;
        }
        sdev->dev = dev;
+       sdev->sid = PCI_DEVID(info->bus, info->devfn);
 
        /* Only count users if device has aux domains */
        if (iommu_dev_feature_enabled(dev, IOMMU_DEV_FEAT_AUX))
@@ -1029,7 +1035,7 @@ no_pasid:
                        resp.qw0 = QI_PGRP_PASID(req->pasid) |
                                QI_PGRP_DID(req->rid) |
                                QI_PGRP_PASID_P(req->pasid_present) |
-                               QI_PGRP_PDP(req->pasid_present) |
+                               QI_PGRP_PDP(req->priv_data_present) |
                                QI_PGRP_RESP_CODE(result) |
                                QI_PGRP_RESP_TYPE;
                        resp.qw1 = QI_PGRP_IDX(req->prg_index) |
index 8c470f4..b53446b 100644 (file)
@@ -2071,7 +2071,7 @@ EXPORT_SYMBOL_GPL(iommu_uapi_cache_invalidate);
 
 static int iommu_check_bind_data(struct iommu_gpasid_bind_data *data)
 {
-       u32 mask;
+       u64 mask;
        int i;
 
        if (data->version != IOMMU_GPASID_BIND_VERSION_1)
index c6098ee..2aa79c3 100644 (file)
@@ -180,7 +180,6 @@ config IRQ_MIPS_CPU
        select GENERIC_IRQ_CHIP
        select GENERIC_IRQ_IPI if SYS_SUPPORTS_MULTITHREADING
        select IRQ_DOMAIN
-       select IRQ_DOMAIN_HIERARCHY if GENERIC_IRQ_IPI
        select GENERIC_IRQ_EFFECTIVE_AFF_MASK
 
 config CLPS711X_IRQCHIP
@@ -315,7 +314,6 @@ config KEYSTONE_IRQ
 config MIPS_GIC
        bool
        select GENERIC_IRQ_IPI
-       select IRQ_DOMAIN_HIERARCHY
        select MIPS_CM
 
 config INGENIC_IRQ
@@ -591,6 +589,7 @@ config LOONGSON_PCH_MSI
 
 config MST_IRQ
        bool "MStar Interrupt Controller"
+       depends on ARCH_MEDIATEK || ARCH_MSTARV7 || COMPILE_TEST
        default ARCH_MEDIATEK
        select IRQ_DOMAIN
        select IRQ_DOMAIN_HIERARCHY
index 97838eb..cbc7c74 100644 (file)
@@ -244,7 +244,7 @@ static int bcm2836_cpu_dying(unsigned int cpu)
 
 #define BITS_PER_MBOX  32
 
-static void bcm2836_arm_irqchip_smp_init(void)
+static void __init bcm2836_arm_irqchip_smp_init(void)
 {
        struct irq_fwspec ipi_fwspec = {
                .fwnode         = intc.domain->fwnode,
index 4be0775..143657b 100644 (file)
@@ -154,8 +154,8 @@ static const struct irq_domain_ops mst_intc_domain_ops = {
        .free           = irq_domain_free_irqs_common,
 };
 
-int __init
-mst_intc_of_init(struct device_node *dn, struct device_node *parent)
+static int __init mst_intc_of_init(struct device_node *dn,
+                                  struct device_node *parent)
 {
        struct irq_domain *domain, *domain_parent;
        struct mst_intc_chip_data *cd;
index 3819185..cb7f60b 100644 (file)
@@ -71,8 +71,7 @@ struct intc_irqpin_priv {
 };
 
 struct intc_irqpin_config {
-       unsigned int irlm_bit;
-       unsigned needs_irlm:1;
+       int irlm_bit;           /* -1 if non-existent */
 };
 
 static unsigned long intc_irqpin_read32(void __iomem *iomem)
@@ -349,11 +348,10 @@ static const struct irq_domain_ops intc_irqpin_irq_domain_ops = {
 
 static const struct intc_irqpin_config intc_irqpin_irlm_r8a777x = {
        .irlm_bit = 23, /* ICR0.IRLM0 */
-       .needs_irlm = 1,
 };
 
 static const struct intc_irqpin_config intc_irqpin_rmobile = {
-       .needs_irlm = 0,
+       .irlm_bit = -1,
 };
 
 static const struct of_device_id intc_irqpin_dt_ids[] = {
@@ -470,7 +468,7 @@ static int intc_irqpin_probe(struct platform_device *pdev)
        }
 
        /* configure "individual IRQ mode" where needed */
-       if (config && config->needs_irlm) {
+       if (config && config->irlm_bit >= 0) {
                if (io[INTC_IRQPIN_REG_IRLM])
                        intc_irqpin_read_modify_write(p, INTC_IRQPIN_REG_IRLM,
                                                      config->irlm_bit, 1, 1);
index eaa3e9f..6f432d2 100644 (file)
@@ -99,7 +99,7 @@ static inline void plic_irq_toggle(const struct cpumask *mask,
                                   struct irq_data *d, int enable)
 {
        int cpu;
-       struct plic_priv *priv = irq_get_chip_data(d->irq);
+       struct plic_priv *priv = irq_data_get_irq_chip_data(d);
 
        writel(enable, priv->regs + PRIORITY_BASE + d->hwirq * PRIORITY_PER_ID);
        for_each_cpu(cpu, mask) {
@@ -115,7 +115,7 @@ static void plic_irq_unmask(struct irq_data *d)
 {
        struct cpumask amask;
        unsigned int cpu;
-       struct plic_priv *priv = irq_get_chip_data(d->irq);
+       struct plic_priv *priv = irq_data_get_irq_chip_data(d);
 
        cpumask_and(&amask, &priv->lmask, cpu_online_mask);
        cpu = cpumask_any_and(irq_data_get_affinity_mask(d),
@@ -127,7 +127,7 @@ static void plic_irq_unmask(struct irq_data *d)
 
 static void plic_irq_mask(struct irq_data *d)
 {
-       struct plic_priv *priv = irq_get_chip_data(d->irq);
+       struct plic_priv *priv = irq_data_get_irq_chip_data(d);
 
        plic_irq_toggle(&priv->lmask, d, 0);
 }
@@ -138,7 +138,7 @@ static int plic_set_affinity(struct irq_data *d,
 {
        unsigned int cpu;
        struct cpumask amask;
-       struct plic_priv *priv = irq_get_chip_data(d->irq);
+       struct plic_priv *priv = irq_data_get_irq_chip_data(d);
 
        cpumask_and(&amask, &priv->lmask, mask_val);
 
@@ -151,7 +151,7 @@ static int plic_set_affinity(struct irq_data *d,
                return -EINVAL;
 
        plic_irq_toggle(&priv->lmask, d, 0);
-       plic_irq_toggle(cpumask_of(cpu), d, 1);
+       plic_irq_toggle(cpumask_of(cpu), d, !irqd_irq_masked(d));
 
        irq_data_update_effective_affinity(d, cpumask_of(cpu));
 
index 0c2c61d..8662d7b 100644 (file)
@@ -195,6 +195,10 @@ static const struct stm32_desc_irq stm32mp1_desc_irq[] = {
        { .exti = 25, .irq_parent = 107, .chip = &stm32_exti_h_chip_direct },
        { .exti = 30, .irq_parent = 52, .chip = &stm32_exti_h_chip_direct },
        { .exti = 47, .irq_parent = 93, .chip = &stm32_exti_h_chip_direct },
+       { .exti = 48, .irq_parent = 138, .chip = &stm32_exti_h_chip_direct },
+       { .exti = 50, .irq_parent = 139, .chip = &stm32_exti_h_chip_direct },
+       { .exti = 52, .irq_parent = 140, .chip = &stm32_exti_h_chip_direct },
+       { .exti = 53, .irq_parent = 141, .chip = &stm32_exti_h_chip_direct },
        { .exti = 54, .irq_parent = 135, .chip = &stm32_exti_h_chip_direct },
        { .exti = 61, .irq_parent = 100, .chip = &stm32_exti_h_chip_direct },
        { .exti = 65, .irq_parent = 144, .chip = &stm32_exti_h_chip },
index e0cceb8..b2ab8db 100644 (file)
@@ -85,6 +85,17 @@ struct ti_sci_inta_vint_desc {
  * @base:              Base address of the memory mapped IO registers
  * @pdev:              Pointer to platform device.
  * @ti_sci_id:         TI-SCI device identifier
+ * @unmapped_cnt:      Number of @unmapped_dev_ids entries
+ * @unmapped_dev_ids:  Pointer to an array of TI-SCI device identifiers of
+ *                     unmapped event sources.
+ *                     Unmapped Events are not part of the Global Event Map and
+ *                     they are converted to Global event within INTA to be
+ *                     received by the same INTA to generate an interrupt.
+ *                     In case an interrupt request comes for a device which is
+ *                     generating Unmapped Event, we must use the INTA's TI-SCI
+ *                     device identifier in place of the source device
+ *                     identifier to let sysfw know where it has to program the
+ *                     Global Event number.
  */
 struct ti_sci_inta_irq_domain {
        const struct ti_sci_handle *sci;
@@ -96,11 +107,37 @@ struct ti_sci_inta_irq_domain {
        void __iomem *base;
        struct platform_device *pdev;
        u32 ti_sci_id;
+
+       int unmapped_cnt;
+       u16 *unmapped_dev_ids;
 };
 
 #define to_vint_desc(e, i) container_of(e, struct ti_sci_inta_vint_desc, \
                                        events[i])
 
+static u16 ti_sci_inta_get_dev_id(struct ti_sci_inta_irq_domain *inta, u32 hwirq)
+{
+       u16 dev_id = HWIRQ_TO_DEVID(hwirq);
+       int i;
+
+       if (inta->unmapped_cnt == 0)
+               return dev_id;
+
+       /*
+        * For devices sending Unmapped Events we must use the INTA's TI-SCI
+        * device identifier number to be able to convert it to a Global Event
+        * and map it to an interrupt.
+        */
+       for (i = 0; i < inta->unmapped_cnt; i++) {
+               if (dev_id == inta->unmapped_dev_ids[i]) {
+                       dev_id = inta->ti_sci_id;
+                       break;
+               }
+       }
+
+       return dev_id;
+}
+
 /**
  * ti_sci_inta_irq_handler() - Chained IRQ handler for the vint irqs
  * @desc:      Pointer to irq_desc corresponding to the irq
@@ -251,7 +288,7 @@ static struct ti_sci_inta_event_desc *ti_sci_inta_alloc_event(struct ti_sci_inta
        u16 dev_id, dev_index;
        int err;
 
-       dev_id = HWIRQ_TO_DEVID(hwirq);
+       dev_id = ti_sci_inta_get_dev_id(inta, hwirq);
        dev_index = HWIRQ_TO_IRQID(hwirq);
 
        event_desc = &vint_desc->events[free_bit];
@@ -352,14 +389,15 @@ static void ti_sci_inta_free_irq(struct ti_sci_inta_event_desc *event_desc,
 {
        struct ti_sci_inta_vint_desc *vint_desc;
        struct ti_sci_inta_irq_domain *inta;
+       u16 dev_id;
 
        vint_desc = to_vint_desc(event_desc, event_desc->vint_bit);
        inta = vint_desc->domain->host_data;
+       dev_id = ti_sci_inta_get_dev_id(inta, hwirq);
        /* free event irq */
        mutex_lock(&inta->vint_mutex);
        inta->sci->ops.rm_irq_ops.free_event_map(inta->sci,
-                                                HWIRQ_TO_DEVID(hwirq),
-                                                HWIRQ_TO_IRQID(hwirq),
+                                                dev_id, HWIRQ_TO_IRQID(hwirq),
                                                 inta->ti_sci_id,
                                                 vint_desc->vint_id,
                                                 event_desc->global_event,
@@ -574,6 +612,41 @@ static struct msi_domain_info ti_sci_inta_msi_domain_info = {
        .chip   = &ti_sci_inta_msi_irq_chip,
 };
 
+static int ti_sci_inta_get_unmapped_sources(struct ti_sci_inta_irq_domain *inta)
+{
+       struct device *dev = &inta->pdev->dev;
+       struct device_node *node = dev_of_node(dev);
+       struct of_phandle_iterator it;
+       int count, err, ret, i;
+
+       count = of_count_phandle_with_args(node, "ti,unmapped-event-sources", NULL);
+       if (count <= 0)
+               return 0;
+
+       inta->unmapped_dev_ids = devm_kcalloc(dev, count,
+                                             sizeof(*inta->unmapped_dev_ids),
+                                             GFP_KERNEL);
+       if (!inta->unmapped_dev_ids)
+               return -ENOMEM;
+
+       i = 0;
+       of_for_each_phandle(&it, err, node, "ti,unmapped-event-sources", NULL, 0) {
+               u32 dev_id;
+
+               ret = of_property_read_u32(it.node, "ti,sci-dev-id", &dev_id);
+               if (ret) {
+                       dev_err(dev, "ti,sci-dev-id read failure for %pOFf\n", it.node);
+                       of_node_put(it.node);
+                       return ret;
+               }
+               inta->unmapped_dev_ids[i++] = dev_id;
+       }
+
+       inta->unmapped_cnt = count;
+
+       return 0;
+}
+
 static int ti_sci_inta_irq_domain_probe(struct platform_device *pdev)
 {
        struct irq_domain *parent_domain, *domain, *msi_domain;
@@ -629,6 +702,10 @@ static int ti_sci_inta_irq_domain_probe(struct platform_device *pdev)
        if (IS_ERR(inta->base))
                return PTR_ERR(inta->base);
 
+       ret = ti_sci_inta_get_unmapped_sources(inta);
+       if (ret)
+               return ret;
+
        domain = irq_domain_add_linear(dev_of_node(dev),
                                       ti_sci_get_num_resources(inta->vint),
                                       &ti_sci_inta_irq_domain_ops, inta);
index 901e213..ada570f 100644 (file)
@@ -142,11 +142,10 @@ static void cb_fini(struct hl_device *hdev, struct hl_cb *cb)
 {
        if (cb->is_internal)
                gen_pool_free(hdev->internal_cb_pool,
-                               cb->kernel_address, cb->size);
+                               (uintptr_t)cb->kernel_address, cb->size);
        else
                hdev->asic_funcs->asic_dma_free_coherent(hdev, cb->size,
-                               (void *) (uintptr_t) cb->kernel_address,
-                               cb->bus_address);
+                               cb->kernel_address, cb->bus_address);
 
        kfree(cb);
 }
@@ -230,7 +229,7 @@ static struct hl_cb *hl_cb_alloc(struct hl_device *hdev, u32 cb_size,
                return NULL;
        }
 
-       cb->kernel_address = (u64) (uintptr_t) p;
+       cb->kernel_address = p;
        cb->size = cb_size;
 
        return cb;
@@ -509,7 +508,7 @@ int hl_cb_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma)
 
        vma->vm_private_data = cb;
 
-       rc = hdev->asic_funcs->cb_mmap(hdev, vma, (void *) cb->kernel_address,
+       rc = hdev->asic_funcs->cb_mmap(hdev, vma, cb->kernel_address,
                                        cb->bus_address, cb->size);
        if (rc) {
                spin_lock(&cb->lock);
index 80d4d73..6ed974d 100644 (file)
@@ -452,7 +452,7 @@ struct hl_cb {
        struct list_head        pool_list;
        struct list_head        va_block_list;
        u64                     id;
-       u64                     kernel_address;
+       void                    *kernel_address;
        dma_addr_t              bus_address;
        u32                     mmap_size;
        u32                     size;
@@ -515,7 +515,7 @@ struct hl_hw_queue {
        struct hl_hw_sob        hw_sob[HL_RSVD_SOBS];
        struct hl_cs_job        **shadow_queue;
        enum hl_queue_type      queue_type;
-       u64                     kernel_address;
+       void                    *kernel_address;
        dma_addr_t              bus_address;
        u32                     pi;
        atomic_t                ci;
@@ -544,7 +544,7 @@ struct hl_hw_queue {
  */
 struct hl_cq {
        struct hl_device        *hdev;
-       u64                     kernel_address;
+       void                    *kernel_address;
        dma_addr_t              bus_address;
        u32                     cq_idx;
        u32                     hw_queue_id;
@@ -562,7 +562,7 @@ struct hl_cq {
  */
 struct hl_eq {
        struct hl_device        *hdev;
-       u64                     kernel_address;
+       void                    *kernel_address;
        dma_addr_t              bus_address;
        u32                     ci;
 };
@@ -757,7 +757,7 @@ struct hl_asic_funcs {
        u32 (*get_dma_desc_list_size)(struct hl_device *hdev,
                                        struct sg_table *sgt);
        void (*add_end_of_cb_packets)(struct hl_device *hdev,
-                                       u64 kernel_address, u32 len,
+                                       void *kernel_address, u32 len,
                                        u64 cq_addr, u32 cq_val, u32 msix_num,
                                        bool eb);
        void (*update_eq_ci)(struct hl_device *hdev, u32 val);
@@ -1382,13 +1382,13 @@ void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);
        for (;;) { \
                /* Verify we read updates done by other cores or by device */ \
                mb(); \
-               (val) = *((u32 *) (uintptr_t) (addr)); \
+               (val) = *((u32 *)(addr)); \
                if (mem_written_by_device) \
                        (val) = le32_to_cpu(*(__le32 *) &(val)); \
                if (cond) \
                        break; \
                if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \
-                       (val) = *((u32 *) (uintptr_t) (addr)); \
+                       (val) = *((u32 *)(addr)); \
                        if (mem_written_by_device) \
                                (val) = le32_to_cpu(*(__le32 *) &(val)); \
                        break; \
index 5e66c98..250cf9c 100644 (file)
@@ -75,7 +75,7 @@ static void ext_and_hw_queue_submit_bd(struct hl_device *hdev,
 {
        struct hl_bd *bd;
 
-       bd = (struct hl_bd *) (uintptr_t) q->kernel_address;
+       bd = q->kernel_address;
        bd += hl_pi_2_offset(q->pi);
        bd->ctl = cpu_to_le32(ctl);
        bd->len = cpu_to_le32(len);
@@ -335,8 +335,7 @@ static void int_queue_schedule_job(struct hl_cs_job *job)
        bd.len = cpu_to_le32(job->job_cb_size);
        bd.ptr = cpu_to_le64((u64) (uintptr_t) job->user_cb);
 
-       pi = (__le64 *) (uintptr_t) (q->kernel_address +
-               ((q->pi & (q->int_queue_len - 1)) * sizeof(bd)));
+       pi = q->kernel_address + (q->pi & (q->int_queue_len - 1)) * sizeof(bd);
 
        q->pi++;
        q->pi &= ((q->int_queue_len << 1) - 1);
@@ -630,7 +629,7 @@ static int ext_and_cpu_queue_init(struct hl_device *hdev, struct hl_hw_queue *q,
        if (!p)
                return -ENOMEM;
 
-       q->kernel_address = (u64) (uintptr_t) p;
+       q->kernel_address = p;
 
        q->shadow_queue = kmalloc_array(HL_QUEUE_LENGTH,
                                        sizeof(*q->shadow_queue),
@@ -653,11 +652,11 @@ free_queue:
        if (is_cpu_queue)
                hdev->asic_funcs->cpu_accessible_dma_pool_free(hdev,
                                        HL_QUEUE_SIZE_IN_BYTES,
-                                       (void *) (uintptr_t) q->kernel_address);
+                                       q->kernel_address);
        else
                hdev->asic_funcs->asic_dma_free_coherent(hdev,
                                        HL_QUEUE_SIZE_IN_BYTES,
-                                       (void *) (uintptr_t) q->kernel_address,
+                                       q->kernel_address,
                                        q->bus_address);
 
        return rc;
@@ -676,7 +675,7 @@ static int int_queue_init(struct hl_device *hdev, struct hl_hw_queue *q)
                return -EFAULT;
        }
 
-       q->kernel_address = (u64) (uintptr_t) p;
+       q->kernel_address = p;
        q->pi = 0;
        atomic_set(&q->ci, 0);
 
@@ -704,7 +703,7 @@ static int hw_queue_init(struct hl_device *hdev, struct hl_hw_queue *q)
        if (!p)
                return -ENOMEM;
 
-       q->kernel_address = (u64) (uintptr_t) p;
+       q->kernel_address = p;
 
        /* Make sure read/write pointers are initialized to start of queue */
        atomic_set(&q->ci, 0);
@@ -839,11 +838,11 @@ static void queue_fini(struct hl_device *hdev, struct hl_hw_queue *q)
        if (q->queue_type == QUEUE_TYPE_CPU)
                hdev->asic_funcs->cpu_accessible_dma_pool_free(hdev,
                                        HL_QUEUE_SIZE_IN_BYTES,
-                                       (void *) (uintptr_t) q->kernel_address);
+                                       q->kernel_address);
        else
                hdev->asic_funcs->asic_dma_free_coherent(hdev,
                                        HL_QUEUE_SIZE_IN_BYTES,
-                                       (void *) (uintptr_t) q->kernel_address,
+                                       q->kernel_address,
                                        q->bus_address);
 }
 
index d20e40a..de53fb5 100644 (file)
@@ -90,7 +90,7 @@ irqreturn_t hl_irq_handler_cq(int irq, void *arg)
                return IRQ_HANDLED;
        }
 
-       cq_base = (struct hl_cq_entry *) (uintptr_t) cq->kernel_address;
+       cq_base = cq->kernel_address;
 
        while (1) {
                bool entry_ready = ((le32_to_cpu(cq_base[cq->ci].data) &
@@ -152,7 +152,7 @@ irqreturn_t hl_irq_handler_eq(int irq, void *arg)
        struct hl_eq_entry *eq_base;
        struct hl_eqe_work *handle_eqe_work;
 
-       eq_base = (struct hl_eq_entry *) (uintptr_t) eq->kernel_address;
+       eq_base = eq->kernel_address;
 
        while (1) {
                bool entry_ready =
@@ -221,7 +221,7 @@ int hl_cq_init(struct hl_device *hdev, struct hl_cq *q, u32 hw_queue_id)
                return -ENOMEM;
 
        q->hdev = hdev;
-       q->kernel_address = (u64) (uintptr_t) p;
+       q->kernel_address = p;
        q->hw_queue_id = hw_queue_id;
        q->ci = 0;
        q->pi = 0;
@@ -242,7 +242,8 @@ int hl_cq_init(struct hl_device *hdev, struct hl_cq *q, u32 hw_queue_id)
 void hl_cq_fini(struct hl_device *hdev, struct hl_cq *q)
 {
        hdev->asic_funcs->asic_dma_free_coherent(hdev, HL_CQ_SIZE_IN_BYTES,
-                       (void *) (uintptr_t) q->kernel_address, q->bus_address);
+                                                q->kernel_address,
+                                                q->bus_address);
 }
 
 void hl_cq_reset(struct hl_device *hdev, struct hl_cq *q)
@@ -259,7 +260,7 @@ void hl_cq_reset(struct hl_device *hdev, struct hl_cq *q)
         * when the device is operational again
         */
 
-       memset((void *) (uintptr_t) q->kernel_address, 0, HL_CQ_SIZE_IN_BYTES);
+       memset(q->kernel_address, 0, HL_CQ_SIZE_IN_BYTES);
 }
 
 /**
@@ -282,7 +283,7 @@ int hl_eq_init(struct hl_device *hdev, struct hl_eq *q)
                return -ENOMEM;
 
        q->hdev = hdev;
-       q->kernel_address = (u64) (uintptr_t) p;
+       q->kernel_address = p;
        q->ci = 0;
 
        return 0;
@@ -302,7 +303,7 @@ void hl_eq_fini(struct hl_device *hdev, struct hl_eq *q)
 
        hdev->asic_funcs->cpu_accessible_dma_pool_free(hdev,
                                        HL_EQ_SIZE_IN_BYTES,
-                                       (void *) (uintptr_t) q->kernel_address);
+                                       q->kernel_address);
 }
 
 void hl_eq_reset(struct hl_device *hdev, struct hl_eq *q)
@@ -316,5 +317,5 @@ void hl_eq_reset(struct hl_device *hdev, struct hl_eq *q)
         * when the device is operational again
         */
 
-       memset((void *) (uintptr_t) q->kernel_address, 0, HL_EQ_SIZE_IN_BYTES);
+       memset(q->kernel_address, 0, HL_EQ_SIZE_IN_BYTES);
 }
index 5f65a16..2519a34 100644 (file)
@@ -680,8 +680,7 @@ static int _gaudi_init_tpc_mem(struct hl_device *hdev,
        if (!cb)
                return -EFAULT;
 
-       init_tpc_mem_pkt = (struct packet_lin_dma *) (uintptr_t)
-                                       cb->kernel_address;
+       init_tpc_mem_pkt = cb->kernel_address;
        cb_size = sizeof(*init_tpc_mem_pkt);
        memset(init_tpc_mem_pkt, 0, cb_size);
 
@@ -3811,8 +3810,7 @@ static int gaudi_validate_cb(struct hl_device *hdev,
                u16 pkt_size;
                struct gaudi_packet *user_pkt;
 
-               user_pkt = (struct gaudi_packet *) (uintptr_t)
-                       (parser->user_cb->kernel_address + cb_parsed_length);
+               user_pkt = parser->user_cb->kernel_address + cb_parsed_length;
 
                pkt_id = (enum packet_id) (
                                (le64_to_cpu(user_pkt->header) &
@@ -4035,11 +4033,9 @@ static int gaudi_patch_cb(struct hl_device *hdev,
                u32 new_pkt_size = 0;
                struct gaudi_packet *user_pkt, *kernel_pkt;
 
-               user_pkt = (struct gaudi_packet *) (uintptr_t)
-                       (parser->user_cb->kernel_address + cb_parsed_length);
-               kernel_pkt = (struct gaudi_packet *) (uintptr_t)
-                       (parser->patched_cb->kernel_address +
-                                       cb_patched_cur_length);
+               user_pkt = parser->user_cb->kernel_address + cb_parsed_length;
+               kernel_pkt = parser->patched_cb->kernel_address +
+                                       cb_patched_cur_length;
 
                pkt_id = (enum packet_id) (
                                (le64_to_cpu(user_pkt->header) &
@@ -4155,8 +4151,8 @@ static int gaudi_parse_cb_mmu(struct hl_device *hdev,
         * The check that parser->user_cb_size <= parser->user_cb->size was done
         * in validate_queue_index().
         */
-       memcpy((void *) (uintptr_t) parser->patched_cb->kernel_address,
-               (void *) (uintptr_t) parser->user_cb->kernel_address,
+       memcpy(parser->patched_cb->kernel_address,
+               parser->user_cb->kernel_address,
                parser->user_cb_size);
 
        patched_cb_size = parser->patched_cb_size;
@@ -4290,7 +4286,7 @@ static int gaudi_cs_parser(struct hl_device *hdev, struct hl_cs_parser *parser)
 }
 
 static void gaudi_add_end_of_cb_packets(struct hl_device *hdev,
-                                       u64 kernel_address, u32 len,
+                                       void *kernel_address, u32 len,
                                        u64 cq_addr, u32 cq_val, u32 msi_vec,
                                        bool eb)
 {
@@ -4298,8 +4294,7 @@ static void gaudi_add_end_of_cb_packets(struct hl_device *hdev,
        struct packet_msg_prot *cq_pkt;
        u32 tmp;
 
-       cq_pkt = (struct packet_msg_prot *) (uintptr_t)
-               (kernel_address + len - (sizeof(struct packet_msg_prot) * 2));
+       cq_pkt = kernel_address + len - (sizeof(struct packet_msg_prot) * 2);
 
        tmp = FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_MSG_PROT);
        tmp |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1);
@@ -4342,7 +4337,7 @@ static int gaudi_memset_device_memory(struct hl_device *hdev, u64 addr,
        if (!cb)
                return -EFAULT;
 
-       lin_dma_pkt = (struct packet_lin_dma *) (uintptr_t) cb->kernel_address;
+       lin_dma_pkt = cb->kernel_address;
        memset(lin_dma_pkt, 0, sizeof(*lin_dma_pkt));
        cb_size = sizeof(*lin_dma_pkt);
 
@@ -4747,7 +4742,7 @@ static void gaudi_write_pte(struct hl_device *hdev, u64 addr, u64 val)
                        (addr - gaudi->hbm_bar_cur_addr));
 }
 
-static void gaudi_mmu_prepare_reg(struct hl_device *hdev, u64 reg, u32 asid)
+void gaudi_mmu_prepare_reg(struct hl_device *hdev, u64 reg, u32 asid)
 {
        /* mask to zero the MMBP and ASID bits */
        WREG32_AND(reg, ~0x7FF);
@@ -4915,9 +4910,6 @@ static void gaudi_mmu_prepare(struct hl_device *hdev, u32 asid)
        gaudi_mmu_prepare_reg(hdev, mmMME2_ACC_WBC, asid);
        gaudi_mmu_prepare_reg(hdev, mmMME3_ACC_WBC, asid);
 
-       gaudi_mmu_prepare_reg(hdev, mmPSOC_GLOBAL_CONF_TRACE_ARUSER, asid);
-       gaudi_mmu_prepare_reg(hdev, mmPSOC_GLOBAL_CONF_TRACE_AWUSER, asid);
-
        hdev->asic_funcs->set_clock_gating(hdev);
 
        mutex_unlock(&gaudi->clk_gate_mutex);
@@ -4954,8 +4946,8 @@ static int gaudi_send_job_on_qman0(struct hl_device *hdev,
 
        cb = job->patched_cb;
 
-       fence_pkt = (struct packet_msg_prot *) (uintptr_t) (cb->kernel_address +
-                       job->job_cb_size - sizeof(struct packet_msg_prot));
+       fence_pkt = cb->kernel_address +
+                       job->job_cb_size - sizeof(struct packet_msg_prot);
 
        tmp = FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_MSG_PROT);
        tmp |= FIELD_PREP(GAUDI_PKT_CTL_EB_MASK, 1);
@@ -6386,7 +6378,7 @@ static void gaudi_gen_signal_cb(struct hl_device *hdev, void *data, u16 sob_id)
        struct packet_msg_short *pkt;
        u32 value, ctl;
 
-       pkt = (struct packet_msg_short *) (uintptr_t) cb->kernel_address;
+       pkt = cb->kernel_address;
        memset(pkt, 0, sizeof(*pkt));
 
        /* Inc by 1, Mode ADD */
@@ -6478,7 +6470,7 @@ static void gaudi_gen_wait_cb(struct hl_device *hdev, void *data, u16 sob_id,
                        u16 sob_val, u16 mon_id, u32 q_idx)
 {
        struct hl_cb *cb = (struct hl_cb *) data;
-       void *buf = (void *) (uintptr_t) cb->kernel_address;
+       void *buf = cb->kernel_address;
        u64 monitor_base, fence_addr = 0;
        u32 size = 0;
        u16 msg_addr_offset;
index 83ad2b0..8eb598d 100644 (file)
@@ -271,5 +271,6 @@ void gaudi_set_pll_profile(struct hl_device *hdev, enum hl_pll_frequency freq);
 int gaudi_debug_coresight(struct hl_device *hdev, void *data);
 void gaudi_halt_coresight(struct hl_device *hdev);
 int gaudi_get_clk_rate(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk);
+void gaudi_mmu_prepare_reg(struct hl_device *hdev, u64 reg, u32 asid);
 
 #endif /* GAUDIP_H_ */
index 881531d..3d2b0f0 100644 (file)
@@ -623,6 +623,11 @@ static int gaudi_config_etr(struct hl_device *hdev,
                        return -EINVAL;
                }
 
+               gaudi_mmu_prepare_reg(hdev, mmPSOC_GLOBAL_CONF_TRACE_ARUSER,
+                                               hdev->compute_ctx->asid);
+               gaudi_mmu_prepare_reg(hdev, mmPSOC_GLOBAL_CONF_TRACE_AWUSER,
+                                               hdev->compute_ctx->asid);
+
                msb = upper_32_bits(input->buffer_address) >> 8;
                msb &= PSOC_GLOBAL_CONF_TRACE_ADDR_MSB_MASK;
                WREG32(mmPSOC_GLOBAL_CONF_TRACE_ADDR, msb);
index 5db5206..235d47b 100644 (file)
@@ -2882,8 +2882,8 @@ static int goya_send_job_on_qman0(struct hl_device *hdev, struct hl_cs_job *job)
 
        cb = job->patched_cb;
 
-       fence_pkt = (struct packet_msg_prot *) (uintptr_t) (cb->kernel_address +
-                       job->job_cb_size - sizeof(struct packet_msg_prot));
+       fence_pkt = cb->kernel_address +
+                       job->job_cb_size - sizeof(struct packet_msg_prot);
 
        tmp = (PACKET_MSG_PROT << GOYA_PKT_CTL_OPCODE_SHIFT) |
                        (1 << GOYA_PKT_CTL_EB_SHIFT) |
@@ -3475,8 +3475,7 @@ static int goya_validate_cb(struct hl_device *hdev,
                u16 pkt_size;
                struct goya_packet *user_pkt;
 
-               user_pkt = (struct goya_packet *) (uintptr_t)
-                       (parser->user_cb->kernel_address + cb_parsed_length);
+               user_pkt = parser->user_cb->kernel_address + cb_parsed_length;
 
                pkt_id = (enum packet_id) (
                                (le64_to_cpu(user_pkt->header) &
@@ -3713,11 +3712,9 @@ static int goya_patch_cb(struct hl_device *hdev,
                u32 new_pkt_size = 0;
                struct goya_packet *user_pkt, *kernel_pkt;
 
-               user_pkt = (struct goya_packet *) (uintptr_t)
-                       (parser->user_cb->kernel_address + cb_parsed_length);
-               kernel_pkt = (struct goya_packet *) (uintptr_t)
-                       (parser->patched_cb->kernel_address +
-                                       cb_patched_cur_length);
+               user_pkt = parser->user_cb->kernel_address + cb_parsed_length;
+               kernel_pkt = parser->patched_cb->kernel_address +
+                                       cb_patched_cur_length;
 
                pkt_id = (enum packet_id) (
                                (le64_to_cpu(user_pkt->header) &
@@ -3841,8 +3838,8 @@ static int goya_parse_cb_mmu(struct hl_device *hdev,
         * The check that parser->user_cb_size <= parser->user_cb->size was done
         * in validate_queue_index().
         */
-       memcpy((void *) (uintptr_t) parser->patched_cb->kernel_address,
-               (void *) (uintptr_t) parser->user_cb->kernel_address,
+       memcpy(parser->patched_cb->kernel_address,
+               parser->user_cb->kernel_address,
                parser->user_cb_size);
 
        patched_cb_size = parser->patched_cb_size;
@@ -3974,15 +3971,14 @@ int goya_cs_parser(struct hl_device *hdev, struct hl_cs_parser *parser)
                return goya_parse_cb_no_mmu(hdev, parser);
 }
 
-void goya_add_end_of_cb_packets(struct hl_device *hdev, u64 kernel_address,
+void goya_add_end_of_cb_packets(struct hl_device *hdev, void *kernel_address,
                                u32 len, u64 cq_addr, u32 cq_val, u32 msix_vec,
                                bool eb)
 {
        struct packet_msg_prot *cq_pkt;
        u32 tmp;
 
-       cq_pkt = (struct packet_msg_prot *) (uintptr_t)
-               (kernel_address + len - (sizeof(struct packet_msg_prot) * 2));
+       cq_pkt = kernel_address + len - (sizeof(struct packet_msg_prot) * 2);
 
        tmp = (PACKET_MSG_PROT << GOYA_PKT_CTL_OPCODE_SHIFT) |
                        (1 << GOYA_PKT_CTL_EB_SHIFT) |
@@ -4746,7 +4742,7 @@ static int goya_memset_device_memory(struct hl_device *hdev, u64 addr, u64 size,
        if (!cb)
                return -ENOMEM;
 
-       lin_dma_pkt = (struct packet_lin_dma *) (uintptr_t) cb->kernel_address;
+       lin_dma_pkt = cb->kernel_address;
 
        do {
                memset(lin_dma_pkt, 0, sizeof(*lin_dma_pkt));
index 09b4006..def86c7 100644 (file)
@@ -217,7 +217,7 @@ int goya_resume(struct hl_device *hdev);
 void goya_handle_eqe(struct hl_device *hdev, struct hl_eq_entry *eq_entry);
 void *goya_get_events_stat(struct hl_device *hdev, bool aggregate, u32 *size);
 
-void goya_add_end_of_cb_packets(struct hl_device *hdev, u64 kernel_address,
+void goya_add_end_of_cb_packets(struct hl_device *hdev, void *kernel_address,
                                u32 len, u64 cq_addr, u32 cq_val, u32 msix_vec,
                                bool eb);
 int goya_cs_parser(struct hl_device *hdev, struct hl_cs_parser *parser);
index f395721..46aed13 100644 (file)
@@ -421,7 +421,6 @@ enum axi_id {
 
 #define QM_ARB_ERR_MSG_EN_MASK         (\
                                        QM_ARB_ERR_MSG_EN_CHOISE_OVF_MASK |\
-                                       QM_ARB_ERR_MSG_EN_CHOISE_WDT_MASK |\
                                        QM_ARB_ERR_MSG_EN_AXI_LBW_ERR_MASK)
 
 #define PCIE_AUX_FLR_CTRL_HW_CTRL_MASK                               0x1
index 64143d4..9e08a98 100644 (file)
@@ -182,11 +182,11 @@ static inline u8 mei_cl_me_id(const struct mei_cl *cl)
  *
  * @cl: host client
  *
- * Return: mtu
+ * Return: mtu or 0 if client is not connected
  */
 static inline size_t mei_cl_mtu(const struct mei_cl *cl)
 {
-       return cl->me_cl->props.max_msg_length;
+       return cl->me_cl ? cl->me_cl->props.max_msg_length : 0;
 }
 
 /**
index 4143141..acb9c81 100644 (file)
@@ -572,17 +572,6 @@ static void renesas_sdhi_reset(struct tmio_mmc_host *host)
                                             TMIO_MASK_INIT_RCAR2);
 }
 
-/*
- * This is a temporary workaround! This driver used 'hw_reset' wrongly and the
- * fix for that showed a regression. So, we mimic the old behaviour until the
- * proper solution is found.
- */
-static void renesas_sdhi_hw_reset(struct mmc_host *mmc)
-{
-       struct tmio_mmc_host *host = mmc_priv(mmc);
-       renesas_sdhi_reset(host);
-}
-
 #define SH_MOBILE_SDHI_MIN_TAP_ROW 3
 
 static int renesas_sdhi_select_tuning(struct tmio_mmc_host *host)
@@ -1020,8 +1009,6 @@ int renesas_sdhi_probe(struct platform_device *pdev,
                if (of_data && of_data->scc_offset) {
                        priv->scc_ctl = host->ctl + of_data->scc_offset;
                        host->reset = renesas_sdhi_reset;
-                       host->ops.hw_reset = renesas_sdhi_hw_reset;
-                       host->mmc->caps |= MMC_CAP_HW_RESET;
                }
        }
 
@@ -1160,6 +1147,7 @@ int renesas_sdhi_remove(struct platform_device *pdev)
 
        tmio_mmc_host_remove(host);
        renesas_sdhi_clk_disable(host);
+       tmio_mmc_host_free(host);
 
        return 0;
 }
index 829ccef..d25a4b5 100644 (file)
 #define SDHCI_ARASAN_VENDOR_REGISTER   0x78
 
 #define SDHCI_ARASAN_ITAPDLY_REGISTER  0xF0F8
+#define SDHCI_ARASAN_ITAPDLY_SEL_MASK  0xFF
+
 #define SDHCI_ARASAN_OTAPDLY_REGISTER  0xF0FC
+#define SDHCI_ARASAN_OTAPDLY_SEL_MASK  0x3F
 
 #define SDHCI_ARASAN_CQE_BASE_ADDR     0x200
 #define VENDOR_ENHANCED_STROBE         BIT(0)
@@ -600,14 +603,8 @@ static int sdhci_zynqmp_sdcardclk_set_phase(struct clk_hw *hw, int degrees)
        u8 tap_delay, tap_max = 0;
        int ret;
 
-       /*
-        * This is applicable for SDHCI_SPEC_300 and above
-        * ZynqMP does not set phase for <=25MHz clock.
-        * If degrees is zero, no need to do anything.
-        */
-       if (host->version < SDHCI_SPEC_300 ||
-           host->timing == MMC_TIMING_LEGACY ||
-           host->timing == MMC_TIMING_UHS_SDR12 || !degrees)
+       /* This is applicable for SDHCI_SPEC_300 and above */
+       if (host->version < SDHCI_SPEC_300)
                return 0;
 
        switch (host->timing) {
@@ -638,6 +635,9 @@ static int sdhci_zynqmp_sdcardclk_set_phase(struct clk_hw *hw, int degrees)
        if (ret)
                pr_err("Error setting Output Tap Delay\n");
 
+       /* Release DLL Reset */
+       zynqmp_pm_sd_dll_reset(node_id, PM_DLL_RESET_RELEASE);
+
        return ret;
 }
 
@@ -668,16 +668,13 @@ static int sdhci_zynqmp_sampleclk_set_phase(struct clk_hw *hw, int degrees)
        u8 tap_delay, tap_max = 0;
        int ret;
 
-       /*
-        * This is applicable for SDHCI_SPEC_300 and above
-        * ZynqMP does not set phase for <=25MHz clock.
-        * If degrees is zero, no need to do anything.
-        */
-       if (host->version < SDHCI_SPEC_300 ||
-           host->timing == MMC_TIMING_LEGACY ||
-           host->timing == MMC_TIMING_UHS_SDR12 || !degrees)
+       /* This is applicable for SDHCI_SPEC_300 and above */
+       if (host->version < SDHCI_SPEC_300)
                return 0;
 
+       /* Assert DLL Reset */
+       zynqmp_pm_sd_dll_reset(node_id, PM_DLL_RESET_ASSERT);
+
        switch (host->timing) {
        case MMC_TIMING_MMC_HS:
        case MMC_TIMING_SD_HS:
@@ -733,14 +730,8 @@ static int sdhci_versal_sdcardclk_set_phase(struct clk_hw *hw, int degrees)
        struct sdhci_host *host = sdhci_arasan->host;
        u8 tap_delay, tap_max = 0;
 
-       /*
-        * This is applicable for SDHCI_SPEC_300 and above
-        * Versal does not set phase for <=25MHz clock.
-        * If degrees is zero, no need to do anything.
-        */
-       if (host->version < SDHCI_SPEC_300 ||
-           host->timing == MMC_TIMING_LEGACY ||
-           host->timing == MMC_TIMING_UHS_SDR12 || !degrees)
+       /* This is applicable for SDHCI_SPEC_300 and above */
+       if (host->version < SDHCI_SPEC_300)
                return 0;
 
        switch (host->timing) {
@@ -773,6 +764,7 @@ static int sdhci_versal_sdcardclk_set_phase(struct clk_hw *hw, int degrees)
                regval = sdhci_readl(host, SDHCI_ARASAN_OTAPDLY_REGISTER);
                regval |= SDHCI_OTAPDLY_ENABLE;
                sdhci_writel(host, regval, SDHCI_ARASAN_OTAPDLY_REGISTER);
+               regval &= ~SDHCI_ARASAN_OTAPDLY_SEL_MASK;
                regval |= tap_delay;
                sdhci_writel(host, regval, SDHCI_ARASAN_OTAPDLY_REGISTER);
        }
@@ -804,14 +796,8 @@ static int sdhci_versal_sampleclk_set_phase(struct clk_hw *hw, int degrees)
        struct sdhci_host *host = sdhci_arasan->host;
        u8 tap_delay, tap_max = 0;
 
-       /*
-        * This is applicable for SDHCI_SPEC_300 and above
-        * Versal does not set phase for <=25MHz clock.
-        * If degrees is zero, no need to do anything.
-        */
-       if (host->version < SDHCI_SPEC_300 ||
-           host->timing == MMC_TIMING_LEGACY ||
-           host->timing == MMC_TIMING_UHS_SDR12 || !degrees)
+       /* This is applicable for SDHCI_SPEC_300 and above */
+       if (host->version < SDHCI_SPEC_300)
                return 0;
 
        switch (host->timing) {
@@ -846,6 +832,7 @@ static int sdhci_versal_sampleclk_set_phase(struct clk_hw *hw, int degrees)
                sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER);
                regval |= SDHCI_ITAPDLY_ENABLE;
                sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER);
+               regval &= ~SDHCI_ARASAN_ITAPDLY_SEL_MASK;
                regval |= tap_delay;
                sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER);
                regval &= ~SDHCI_ITAPDLY_CHGWIN;
index bb09445..ab5ab96 100644 (file)
@@ -1324,6 +1324,8 @@ static struct soc_device_attribute soc_fixup_sdhc_clkdivs[] = {
 
 static struct soc_device_attribute soc_unreliable_pulse_detection[] = {
        { .family = "QorIQ LX2160A", .revision = "1.0", },
+       { .family = "QorIQ LX2160A", .revision = "2.0", },
+       { .family = "QorIQ LS1028A", .revision = "1.0", },
        { },
 };
 
index 23da7f7..9552708 100644 (file)
@@ -665,6 +665,15 @@ static void sdhci_intel_set_power(struct sdhci_host *host, unsigned char mode,
        }
 }
 
+static void sdhci_intel_set_uhs_signaling(struct sdhci_host *host,
+                                         unsigned int timing)
+{
+       /* Set UHS timing to SDR25 for High Speed mode */
+       if (timing == MMC_TIMING_MMC_HS || timing == MMC_TIMING_SD_HS)
+               timing = MMC_TIMING_UHS_SDR25;
+       sdhci_set_uhs_signaling(host, timing);
+}
+
 #define INTEL_HS400_ES_REG 0x78
 #define INTEL_HS400_ES_BIT BIT(0)
 
@@ -721,7 +730,7 @@ static const struct sdhci_ops sdhci_intel_byt_ops = {
        .enable_dma             = sdhci_pci_enable_dma,
        .set_bus_width          = sdhci_set_bus_width,
        .reset                  = sdhci_reset,
-       .set_uhs_signaling      = sdhci_set_uhs_signaling,
+       .set_uhs_signaling      = sdhci_intel_set_uhs_signaling,
        .hw_reset               = sdhci_pci_hw_reset,
 };
 
@@ -731,7 +740,7 @@ static const struct sdhci_ops sdhci_intel_glk_ops = {
        .enable_dma             = sdhci_pci_enable_dma,
        .set_bus_width          = sdhci_set_bus_width,
        .reset                  = sdhci_cqhci_reset,
-       .set_uhs_signaling      = sdhci_set_uhs_signaling,
+       .set_uhs_signaling      = sdhci_intel_set_uhs_signaling,
        .hw_reset               = sdhci_pci_hw_reset,
        .irq                    = sdhci_cqhci_irq,
 };
index 2fce051..cb4149f 100644 (file)
@@ -175,6 +175,8 @@ static void tmio_mmc_reset(struct tmio_mmc_host *host)
        if (host->reset)
                host->reset(host);
 
+       tmio_mmc_abort_dma(host);
+
        if (host->pdata->flags & TMIO_MMC_SDIO_IRQ) {
                sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask);
                sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0001);
@@ -223,8 +225,6 @@ static void tmio_mmc_reset_work(struct work_struct *work)
 
        /* Ready for new calls */
        host->mrq = NULL;
-
-       tmio_mmc_abort_dma(host);
        mmc_request_done(host->mmc, mrq);
 }
 
@@ -927,6 +927,9 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
        switch (ios->power_mode) {
        case MMC_POWER_OFF:
                tmio_mmc_power_off(host);
+               /* Downgrade ensures a sane state for tuning HW (e.g. SCC) */
+               if (host->mmc->ops->hs400_downgrade)
+                       host->mmc->ops->hs400_downgrade(host->mmc);
                host->set_clock(host, 0);
                break;
        case MMC_POWER_UP:
index 0e7a9b6..e345f9d 100644 (file)
@@ -707,6 +707,30 @@ static int fsl_ifc_attach_chip(struct nand_chip *chip)
 {
        struct mtd_info *mtd = nand_to_mtd(chip);
        struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
+       struct fsl_ifc_ctrl *ctrl = priv->ctrl;
+       struct fsl_ifc_global __iomem *ifc_global = ctrl->gregs;
+       u32 csor;
+
+       csor = ifc_in32(&ifc_global->csor_cs[priv->bank].csor);
+
+       /* Must also set CSOR_NAND_ECC_ENC_EN if DEC_EN set */
+       if (csor & CSOR_NAND_ECC_DEC_EN) {
+               chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
+               mtd_set_ooblayout(mtd, &fsl_ifc_ooblayout_ops);
+
+               /* Hardware generates ECC per 512 Bytes */
+               chip->ecc.size = 512;
+               if ((csor & CSOR_NAND_ECC_MODE_MASK) == CSOR_NAND_ECC_MODE_4) {
+                       chip->ecc.bytes = 8;
+                       chip->ecc.strength = 4;
+               } else {
+                       chip->ecc.bytes = 16;
+                       chip->ecc.strength = 8;
+               }
+       } else {
+               chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
+               chip->ecc.algo = NAND_ECC_ALGO_HAMMING;
+       }
 
        dev_dbg(priv->dev, "%s: nand->numchips = %d\n", __func__,
                nanddev_ntargets(&chip->base));
@@ -910,25 +934,6 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
                return -ENODEV;
        }
 
-       /* Must also set CSOR_NAND_ECC_ENC_EN if DEC_EN set */
-       if (csor & CSOR_NAND_ECC_DEC_EN) {
-               chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
-               mtd_set_ooblayout(mtd, &fsl_ifc_ooblayout_ops);
-
-               /* Hardware generates ECC per 512 Bytes */
-               chip->ecc.size = 512;
-               if ((csor & CSOR_NAND_ECC_MODE_MASK) == CSOR_NAND_ECC_MODE_4) {
-                       chip->ecc.bytes = 8;
-                       chip->ecc.strength = 4;
-               } else {
-                       chip->ecc.bytes = 16;
-                       chip->ecc.strength = 8;
-               }
-       } else {
-               chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
-               chip->ecc.algo = NAND_ECC_ALGO_HAMMING;
-       }
-
        ret = fsl_ifc_sram_init(priv);
        if (ret)
                return ret;
index d4200eb..684c51e 100644 (file)
@@ -1681,6 +1681,11 @@ static int mxcnd_attach_chip(struct nand_chip *chip)
        struct mxc_nand_host *host = nand_get_controller_data(chip);
        struct device *dev = mtd->dev.parent;
 
+       chip->ecc.bytes = host->devtype_data->eccbytes;
+       host->eccsize = host->devtype_data->eccsize;
+       chip->ecc.size = 512;
+       mtd_set_ooblayout(mtd, host->devtype_data->ooblayout);
+
        switch (chip->ecc.engine_type) {
        case NAND_ECC_ENGINE_TYPE_ON_HOST:
                chip->ecc.read_page = mxc_nand_read_page;
@@ -1836,19 +1841,7 @@ static int mxcnd_probe(struct platform_device *pdev)
        if (host->devtype_data->axi_offset)
                host->regs_axi = host->base + host->devtype_data->axi_offset;
 
-       this->ecc.bytes = host->devtype_data->eccbytes;
-       host->eccsize = host->devtype_data->eccsize;
-
        this->legacy.select_chip = host->devtype_data->select_chip;
-       this->ecc.size = 512;
-       mtd_set_ooblayout(mtd, host->devtype_data->ooblayout);
-
-       if (host->pdata.hw_ecc) {
-               this->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
-       } else {
-               this->ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
-               this->ecc.algo = NAND_ECC_ALGO_HAMMING;
-       }
 
        /* NAND bus width determines access functions used by upper layer */
        if (host->pdata.width == 2)
index b31a581..550bda4 100644 (file)
@@ -1708,6 +1708,13 @@ static int stm32_fmc2_nfc_attach_chip(struct nand_chip *chip)
                return -EINVAL;
        }
 
+       /* Default ECC settings in case they are not set in the device tree */
+       if (!chip->ecc.size)
+               chip->ecc.size = FMC2_ECC_STEP_SIZE;
+
+       if (!chip->ecc.strength)
+               chip->ecc.strength = FMC2_ECC_BCH8;
+
        ret = nand_ecc_choose_conf(chip, &stm32_fmc2_nfc_ecc_caps,
                                   mtd->oobsize - FMC2_BBM_LEN);
        if (ret) {
@@ -1727,8 +1734,7 @@ static int stm32_fmc2_nfc_attach_chip(struct nand_chip *chip)
 
        mtd_set_ooblayout(mtd, &stm32_fmc2_nfc_ooblayout_ops);
 
-       if (chip->options & NAND_BUSWIDTH_16)
-               stm32_fmc2_nfc_set_buswidth_16(nfc, true);
+       stm32_fmc2_nfc_setup(chip);
 
        return 0;
 }
@@ -1952,11 +1958,6 @@ static int stm32_fmc2_nfc_probe(struct platform_device *pdev)
        chip->options |= NAND_BUSWIDTH_AUTO | NAND_NO_SUBPAGE_WRITE |
                         NAND_USES_DMA;
 
-       /* Default ECC settings */
-       chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
-       chip->ecc.size = FMC2_ECC_STEP_SIZE;
-       chip->ecc.strength = FMC2_ECC_BCH8;
-
        /* Scan to find existence of the device */
        ret = nand_scan(chip, nand->ncs);
        if (ret)
index 0369d98..f0ae7a0 100644 (file)
@@ -2701,11 +2701,10 @@ static void spi_nor_sfdp_init_params(struct spi_nor *nor)
 
        memcpy(&sfdp_params, nor->params, sizeof(sfdp_params));
 
-       if (spi_nor_parse_sfdp(nor, &sfdp_params)) {
+       if (spi_nor_parse_sfdp(nor, nor->params)) {
+               memcpy(nor->params, &sfdp_params, sizeof(*nor->params));
                nor->addr_width = 0;
                nor->flags &= ~SNOR_F_4B_OPCODES;
-       } else {
-               memcpy(nor->params, &sfdp_params, sizeof(*nor->params));
        }
 }
 
@@ -3009,13 +3008,15 @@ static int spi_nor_set_addr_width(struct spi_nor *nor)
                /* already configured from SFDP */
        } else if (nor->info->addr_width) {
                nor->addr_width = nor->info->addr_width;
-       } else if (nor->mtd.size > 0x1000000) {
-               /* enable 4-byte addressing if the device exceeds 16MiB */
-               nor->addr_width = 4;
        } else {
                nor->addr_width = 3;
        }
 
+       if (nor->addr_width == 3 && nor->mtd.size > 0x1000000) {
+               /* enable 4-byte addressing if the device exceeds 16MiB */
+               nor->addr_width = 4;
+       }
+
        if (nor->addr_width > SPI_NOR_MAX_ADDR_WIDTH) {
                dev_dbg(nor->dev, "address width is too large: %u\n",
                        nor->addr_width);
index b70ded3..81e39d7 100644 (file)
@@ -512,9 +512,13 @@ __can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 *len_ptr)
                 */
                struct sk_buff *skb = priv->echo_skb[idx];
                struct canfd_frame *cf = (struct canfd_frame *)skb->data;
-               u8 len = cf->len;
 
-               *len_ptr = len;
+               /* get the real payload length for netdev statistics */
+               if (cf->can_id & CAN_RTR_FLAG)
+                       *len_ptr = 0;
+               else
+                       *len_ptr = cf->len;
+
                priv->echo_skb[idx] = NULL;
 
                return skb;
@@ -538,7 +542,11 @@ unsigned int can_get_echo_skb(struct net_device *dev, unsigned int idx)
        if (!skb)
                return 0;
 
-       netif_rx(skb);
+       skb_get(skb);
+       if (netif_rx(skb) == NET_RX_SUCCESS)
+               dev_consume_skb_any(skb);
+       else
+               dev_kfree_skb_any(skb);
 
        return len;
 }
@@ -584,7 +592,7 @@ static void can_restart(struct net_device *dev)
 
        cf->can_id |= CAN_ERR_RESTARTED;
 
-       netif_rx(skb);
+       netif_rx_ni(skb);
 
        stats->rx_packets++;
        stats->rx_bytes += cf->can_dlc;
index 4d594e9..99e5f27 100644 (file)
  *   MX8MP FlexCAN3  03.00.17.01    yes       yes        no      yes       yes          yes
  *   VF610 FlexCAN3  ?               no       yes        no      yes       yes?          no
  * LS1021A FlexCAN2  03.00.04.00     no       yes        no       no       yes           no
- * LX2160A FlexCAN3  03.00.23.00     no       yes        no       no       yes          yes
+ * LX2160A FlexCAN3  03.00.23.00     no       yes        no      yes       yes          yes
  *
  * Some SOCs do not have the RX_WARN & TX_WARN interrupt line connected.
  */
@@ -400,19 +400,19 @@ static struct flexcan_devtype_data fsl_imx8mp_devtype_data = {
 static const struct flexcan_devtype_data fsl_vf610_devtype_data = {
        .quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS |
                FLEXCAN_QUIRK_DISABLE_MECR | FLEXCAN_QUIRK_USE_OFF_TIMESTAMP |
-               FLEXCAN_QUIRK_BROKEN_PERR_STATE,
+               FLEXCAN_QUIRK_BROKEN_PERR_STATE | FLEXCAN_QUIRK_SUPPORT_ECC,
 };
 
 static const struct flexcan_devtype_data fsl_ls1021a_r2_devtype_data = {
        .quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS |
-               FLEXCAN_QUIRK_DISABLE_MECR | FLEXCAN_QUIRK_BROKEN_PERR_STATE |
-               FLEXCAN_QUIRK_USE_OFF_TIMESTAMP,
+               FLEXCAN_QUIRK_BROKEN_PERR_STATE | FLEXCAN_QUIRK_USE_OFF_TIMESTAMP,
 };
 
 static const struct flexcan_devtype_data fsl_lx2160a_r1_devtype_data = {
        .quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS |
                FLEXCAN_QUIRK_DISABLE_MECR | FLEXCAN_QUIRK_BROKEN_PERR_STATE |
-               FLEXCAN_QUIRK_USE_OFF_TIMESTAMP | FLEXCAN_QUIRK_SUPPORT_FD,
+               FLEXCAN_QUIRK_USE_OFF_TIMESTAMP | FLEXCAN_QUIRK_SUPPORT_FD |
+               FLEXCAN_QUIRK_SUPPORT_ECC,
 };
 
 static const struct can_bittiming_const flexcan_bittiming_const = {
@@ -728,8 +728,10 @@ static int flexcan_get_berr_counter(const struct net_device *dev,
        int err;
 
        err = pm_runtime_get_sync(priv->dev);
-       if (err < 0)
+       if (err < 0) {
+               pm_runtime_put_noidle(priv->dev);
                return err;
+       }
 
        err = __flexcan_get_berr_counter(dev, bec);
 
@@ -1565,14 +1567,10 @@ static int flexcan_chip_start(struct net_device *dev)
                priv->write(reg_ctrl2, &regs->ctrl2);
        }
 
-       err = flexcan_transceiver_enable(priv);
-       if (err)
-               goto out_chip_disable;
-
        /* synchronize with the can bus */
        err = flexcan_chip_unfreeze(priv);
        if (err)
-               goto out_transceiver_disable;
+               goto out_chip_disable;
 
        priv->can.state = CAN_STATE_ERROR_ACTIVE;
 
@@ -1590,8 +1588,6 @@ static int flexcan_chip_start(struct net_device *dev)
 
        return 0;
 
- out_transceiver_disable:
-       flexcan_transceiver_disable(priv);
  out_chip_disable:
        flexcan_chip_disable(priv);
        return err;
@@ -1621,7 +1617,6 @@ static int __flexcan_chip_stop(struct net_device *dev, bool disable_on_error)
        priv->write(priv->reg_ctrl_default & ~FLEXCAN_CTRL_ERR_ALL,
                    &regs->ctrl);
 
-       flexcan_transceiver_disable(priv);
        priv->can.state = CAN_STATE_STOPPED;
 
        return 0;
@@ -1654,17 +1649,23 @@ static int flexcan_open(struct net_device *dev)
        }
 
        err = pm_runtime_get_sync(priv->dev);
-       if (err < 0)
+       if (err < 0) {
+               pm_runtime_put_noidle(priv->dev);
                return err;
+       }
 
        err = open_candev(dev);
        if (err)
                goto out_runtime_put;
 
-       err = request_irq(dev->irq, flexcan_irq, IRQF_SHARED, dev->name, dev);
+       err = flexcan_transceiver_enable(priv);
        if (err)
                goto out_close;
 
+       err = request_irq(dev->irq, flexcan_irq, IRQF_SHARED, dev->name, dev);
+       if (err)
+               goto out_transceiver_disable;
+
        if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
                priv->mb_size = sizeof(struct flexcan_mb) + CANFD_MAX_DLEN;
        else
@@ -1716,6 +1717,8 @@ static int flexcan_open(struct net_device *dev)
        can_rx_offload_del(&priv->offload);
  out_free_irq:
        free_irq(dev->irq, dev);
+ out_transceiver_disable:
+       flexcan_transceiver_disable(priv);
  out_close:
        close_candev(dev);
  out_runtime_put:
@@ -1734,6 +1737,7 @@ static int flexcan_close(struct net_device *dev)
 
        can_rx_offload_del(&priv->offload);
        free_irq(dev->irq, dev);
+       flexcan_transceiver_disable(priv);
 
        close_candev(dev);
        pm_runtime_put(priv->dev);
@@ -1852,7 +1856,7 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev)
                return -EINVAL;
 
        /* stop mode property format is:
-        * <&gpr req_gpr>.
+        * <&gpr req_gpr req_bit>.
         */
        ret = of_property_read_u32_array(np, "fsl,stop-mode", out_val,
                                         ARRAY_SIZE(out_val));
@@ -2062,6 +2066,8 @@ static int flexcan_remove(struct platform_device *pdev)
 {
        struct net_device *dev = platform_get_drvdata(pdev);
 
+       device_set_wakeup_enable(&pdev->dev, false);
+       device_set_wakeup_capable(&pdev->dev, false);
        unregister_flexcandev(dev);
        pm_runtime_disable(&pdev->dev);
        free_candev(dev);
index 6f76691..72acd1b 100644 (file)
@@ -287,12 +287,12 @@ struct kvaser_pciefd_tx_packet {
 static const struct can_bittiming_const kvaser_pciefd_bittiming_const = {
        .name = KVASER_PCIEFD_DRV_NAME,
        .tseg1_min = 1,
-       .tseg1_max = 255,
+       .tseg1_max = 512,
        .tseg2_min = 1,
        .tseg2_max = 32,
        .sjw_max = 16,
        .brp_min = 1,
-       .brp_max = 4096,
+       .brp_max = 8192,
        .brp_inc = 1,
 };
 
index 48be627..5f9f819 100644 (file)
@@ -16,7 +16,8 @@ config CAN_M_CAN_PLATFORM
 
 config CAN_M_CAN_TCAN4X5X
        depends on CAN_M_CAN
-       depends on REGMAP_SPI
+       depends on SPI
+       select REGMAP_SPI
        tristate "TCAN4X5X M_CAN device"
        help
          Say Y here if you want support for Texas Instruments TCAN4x5x
index 02c5795..f3fc37e 100644 (file)
@@ -665,7 +665,7 @@ static int m_can_handle_state_change(struct net_device *dev,
        unsigned int ecr;
 
        switch (new_state) {
-       case CAN_STATE_ERROR_ACTIVE:
+       case CAN_STATE_ERROR_WARNING:
                /* error warning state */
                cdev->can.can_stats.error_warning++;
                cdev->can.state = CAN_STATE_ERROR_WARNING;
@@ -694,7 +694,7 @@ static int m_can_handle_state_change(struct net_device *dev,
        __m_can_get_berr_counter(dev, &bec);
 
        switch (new_state) {
-       case CAN_STATE_ERROR_ACTIVE:
+       case CAN_STATE_ERROR_WARNING:
                /* error warning state */
                cf->can_id |= CAN_ERR_CRTL;
                cf->data[1] = (bec.txerr > bec.rxerr) ?
@@ -956,6 +956,8 @@ static irqreturn_t m_can_isr(int irq, void *dev_id)
        struct net_device_stats *stats = &dev->stats;
        u32 ir;
 
+       if (pm_runtime_suspended(cdev->dev))
+               return IRQ_NONE;
        ir = m_can_read(cdev, M_CAN_IR);
        if (!ir)
                return IRQ_NONE;
@@ -1414,6 +1416,9 @@ static void m_can_stop(struct net_device *dev)
        /* disable all interrupts */
        m_can_disable_all_interrupts(cdev);
 
+       /* Set init mode to disengage from the network */
+       m_can_config_endisable(cdev, true);
+
        /* set the state as STOPPED */
        cdev->can.state = CAN_STATE_STOPPED;
 }
@@ -1812,6 +1817,12 @@ out:
 }
 EXPORT_SYMBOL_GPL(m_can_class_allocate_dev);
 
+void m_can_class_free_dev(struct net_device *net)
+{
+       free_candev(net);
+}
+EXPORT_SYMBOL_GPL(m_can_class_free_dev);
+
 int m_can_class_register(struct m_can_classdev *m_can_dev)
 {
        int ret;
@@ -1850,7 +1861,6 @@ pm_runtime_fail:
        if (ret) {
                if (m_can_dev->pm_clock_support)
                        pm_runtime_disable(m_can_dev->dev);
-               free_candev(m_can_dev->net);
        }
 
        return ret;
@@ -1908,8 +1918,6 @@ void m_can_class_unregister(struct m_can_classdev *m_can_dev)
        unregister_candev(m_can_dev->net);
 
        m_can_clk_stop(m_can_dev);
-
-       free_candev(m_can_dev->net);
 }
 EXPORT_SYMBOL_GPL(m_can_class_unregister);
 
index 49f42b5..b2699a7 100644 (file)
@@ -99,6 +99,7 @@ struct m_can_classdev {
 };
 
 struct m_can_classdev *m_can_class_allocate_dev(struct device *dev);
+void m_can_class_free_dev(struct net_device *net);
 int m_can_class_register(struct m_can_classdev *cdev);
 void m_can_class_unregister(struct m_can_classdev *cdev);
 int m_can_class_get_clocks(struct m_can_classdev *cdev);
index e6d0cb9..161cb9b 100644 (file)
@@ -67,32 +67,36 @@ static int m_can_plat_probe(struct platform_device *pdev)
                return -ENOMEM;
 
        priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
-       if (!priv)
-               return -ENOMEM;
+       if (!priv) {
+               ret = -ENOMEM;
+               goto probe_fail;
+       }
 
        mcan_class->device_data = priv;
 
-       m_can_class_get_clocks(mcan_class);
+       ret = m_can_class_get_clocks(mcan_class);
+       if (ret)
+               goto probe_fail;
 
        res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "m_can");
        addr = devm_ioremap_resource(&pdev->dev, res);
        irq = platform_get_irq_byname(pdev, "int0");
        if (IS_ERR(addr) || irq < 0) {
                ret = -EINVAL;
-               goto failed_ret;
+               goto probe_fail;
        }
 
        /* message ram could be shared */
        res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "message_ram");
        if (!res) {
                ret = -ENODEV;
-               goto failed_ret;
+               goto probe_fail;
        }
 
        mram_addr = devm_ioremap(&pdev->dev, res->start, resource_size(res));
        if (!mram_addr) {
                ret = -ENOMEM;
-               goto failed_ret;
+               goto probe_fail;
        }
 
        priv->base = addr;
@@ -111,9 +115,10 @@ static int m_can_plat_probe(struct platform_device *pdev)
 
        m_can_init_ram(mcan_class);
 
-       ret = m_can_class_register(mcan_class);
+       return m_can_class_register(mcan_class);
 
-failed_ret:
+probe_fail:
+       m_can_class_free_dev(mcan_class->net);
        return ret;
 }
 
@@ -134,6 +139,8 @@ static int m_can_plat_remove(struct platform_device *pdev)
 
        m_can_class_unregister(mcan_class);
 
+       m_can_class_free_dev(mcan_class->net);
+
        platform_set_drvdata(pdev, NULL);
 
        return 0;
index eacd428..e5d7d85 100644 (file)
@@ -440,14 +440,18 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
                return -ENOMEM;
 
        priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL);
-       if (!priv)
-               return -ENOMEM;
+       if (!priv) {
+               ret = -ENOMEM;
+               goto out_m_can_class_free_dev;
+       }
 
        priv->power = devm_regulator_get_optional(&spi->dev, "vsup");
-       if (PTR_ERR(priv->power) == -EPROBE_DEFER)
-               return -EPROBE_DEFER;
-       else
+       if (PTR_ERR(priv->power) == -EPROBE_DEFER) {
+               ret = -EPROBE_DEFER;
+               goto out_m_can_class_free_dev;
+       } else {
                priv->power = NULL;
+       }
 
        mcan_class->device_data = priv;
 
@@ -460,8 +464,10 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
        }
 
        /* Sanity check */
-       if (freq < 20000000 || freq > TCAN4X5X_EXT_CLK_DEF)
-               return -ERANGE;
+       if (freq < 20000000 || freq > TCAN4X5X_EXT_CLK_DEF) {
+               ret = -ERANGE;
+               goto out_m_can_class_free_dev;
+       }
 
        priv->reg_offset = TCAN4X5X_MCAN_OFFSET;
        priv->mram_start = TCAN4X5X_MRAM_START;
@@ -487,6 +493,10 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
 
        priv->regmap = devm_regmap_init(&spi->dev, &tcan4x5x_bus,
                                        &spi->dev, &tcan4x5x_regmap);
+       if (IS_ERR(priv->regmap)) {
+               ret = PTR_ERR(priv->regmap);
+               goto out_clk;
+       }
 
        ret = tcan4x5x_power_enable(priv->power, 1);
        if (ret)
@@ -514,8 +524,10 @@ out_clk:
                clk_disable_unprepare(mcan_class->cclk);
                clk_disable_unprepare(mcan_class->hclk);
        }
-
+ out_m_can_class_free_dev:
+       m_can_class_free_dev(mcan_class->net);
        dev_err(&spi->dev, "Probe failed, err=%d\n", ret);
+
        return ret;
 }
 
@@ -523,9 +535,11 @@ static int tcan4x5x_can_remove(struct spi_device *spi)
 {
        struct tcan4x5x_priv *priv = spi_get_drvdata(spi);
 
+       m_can_class_unregister(priv->mcan_dev);
+
        tcan4x5x_power_enable(priv->power, 0);
 
-       m_can_class_unregister(priv->mcan_dev);
+       m_can_class_free_dev(priv->mcan_dev->net);
 
        return 0;
 }
index 10aa3e4..40c33b8 100644 (file)
@@ -262,8 +262,7 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
                cf_len = get_can_dlc(pucan_msg_get_dlc(msg));
 
        /* if this frame is an echo, */
-       if ((rx_msg_flags & PUCAN_MSG_LOOPED_BACK) &&
-           !(rx_msg_flags & PUCAN_MSG_SELF_RECEIVE)) {
+       if (rx_msg_flags & PUCAN_MSG_LOOPED_BACK) {
                unsigned long flags;
 
                spin_lock_irqsave(&priv->echo_lock, flags);
@@ -277,7 +276,13 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
                netif_wake_queue(priv->ndev);
 
                spin_unlock_irqrestore(&priv->echo_lock, flags);
-               return 0;
+
+               /* if this frame is only an echo, stop here. Otherwise,
+                * continue to push this application self-received frame into
+                * its own rx queue.
+                */
+               if (!(rx_msg_flags & PUCAN_MSG_SELF_RECEIVE))
+                       return 0;
        }
 
        /* otherwise, it should be pushed into rx fifo */
index 3b18026..6e95193 100644 (file)
@@ -245,7 +245,7 @@ int can_rx_offload_queue_sorted(struct can_rx_offload *offload,
 
        if (skb_queue_len(&offload->skb_queue) >
            offload->skb_queue_len_max) {
-               kfree_skb(skb);
+               dev_kfree_skb_any(skb);
                return -ENOBUFS;
        }
 
@@ -290,7 +290,7 @@ int can_rx_offload_queue_tail(struct can_rx_offload *offload,
 {
        if (skb_queue_len(&offload->skb_queue) >
            offload->skb_queue_len_max) {
-               kfree_skb(skb);
+               dev_kfree_skb_any(skb);
                return -ENOBUFS;
        }
 
index c3f4954..9c215f7 100644 (file)
@@ -75,11 +75,11 @@ static const char *__mcp251xfd_get_model_str(enum mcp251xfd_model model)
 {
        switch (model) {
        case MCP251XFD_MODEL_MCP2517FD:
-               return "MCP2517FD"; break;
+               return "MCP2517FD";
        case MCP251XFD_MODEL_MCP2518FD:
-               return "MCP2518FD"; break;
+               return "MCP2518FD";
        case MCP251XFD_MODEL_MCP251XFD:
-               return "MCP251xFD"; break;
+               return "MCP251xFD";
        }
 
        return "<unknown>";
@@ -95,21 +95,21 @@ static const char *mcp251xfd_get_mode_str(const u8 mode)
 {
        switch (mode) {
        case MCP251XFD_REG_CON_MODE_MIXED:
-               return "Mixed (CAN FD/CAN 2.0)"; break;
+               return "Mixed (CAN FD/CAN 2.0)";
        case MCP251XFD_REG_CON_MODE_SLEEP:
-               return "Sleep"; break;
+               return "Sleep";
        case MCP251XFD_REG_CON_MODE_INT_LOOPBACK:
-               return "Internal Loopback"; break;
+               return "Internal Loopback";
        case MCP251XFD_REG_CON_MODE_LISTENONLY:
-               return "Listen Only"; break;
+               return "Listen Only";
        case MCP251XFD_REG_CON_MODE_CONFIG:
-               return "Configuration"; break;
+               return "Configuration";
        case MCP251XFD_REG_CON_MODE_EXT_LOOPBACK:
-               return "External Loopback"; break;
+               return "External Loopback";
        case MCP251XFD_REG_CON_MODE_CAN2_0:
-               return "CAN 2.0"; break;
+               return "CAN 2.0";
        case MCP251XFD_REG_CON_MODE_RESTRICTED:
-               return "Restricted Operation"; break;
+               return "Restricted Operation";
        }
 
        return "<unknown>";
index ba25902..314f868 100644 (file)
@@ -173,7 +173,7 @@ mcp251xfd_regmap_nocrc_read(void *context,
                memcpy(&buf_tx->cmd, reg, sizeof(buf_tx->cmd));
                if (MCP251XFD_SANITIZE_SPI)
                        memset(buf_tx->data, 0x0, val_len);
-       };
+       }
 
        err = spi_sync(spi, &msg);
        if (err)
@@ -330,17 +330,17 @@ mcp251xfd_regmap_crc_read(void *context,
                        goto out;
                }
 
-               netdev_dbg(priv->ndev,
-                          "CRC read error at address 0x%04x (length=%zd, data=%*ph, CRC=0x%04x) retrying.\n",
-                          reg, val_len, (int)val_len, buf_rx->data,
-                          get_unaligned_be16(buf_rx->data + val_len));
-       }
-
-       if (err) {
                netdev_info(priv->ndev,
-                           "CRC read error at address 0x%04x (length=%zd, data=%*ph, CRC=0x%04x).\n",
+                           "CRC read error at address 0x%04x (length=%zd, data=%*ph, CRC=0x%04x) retrying.\n",
                            reg, val_len, (int)val_len, buf_rx->data,
                            get_unaligned_be16(buf_rx->data + val_len));
+       }
+
+       if (err) {
+               netdev_err(priv->ndev,
+                          "CRC read error at address 0x%04x (length=%zd, data=%*ph, CRC=0x%04x).\n",
+                          reg, val_len, (int)val_len, buf_rx->data,
+                          get_unaligned_be16(buf_rx->data + val_len));
 
                return err;
        }
index 1d63006..2c22f40 100644 (file)
@@ -881,7 +881,8 @@ static int ti_hecc_probe(struct platform_device *pdev)
        priv->base = devm_platform_ioremap_resource_byname(pdev, "hecc");
        if (IS_ERR(priv->base)) {
                dev_err(&pdev->dev, "hecc ioremap failed\n");
-               return PTR_ERR(priv->base);
+               err = PTR_ERR(priv->base);
+               goto probe_exit_candev;
        }
 
        /* handle hecc-ram memory */
@@ -889,20 +890,22 @@ static int ti_hecc_probe(struct platform_device *pdev)
                                                               "hecc-ram");
        if (IS_ERR(priv->hecc_ram)) {
                dev_err(&pdev->dev, "hecc-ram ioremap failed\n");
-               return PTR_ERR(priv->hecc_ram);
+               err = PTR_ERR(priv->hecc_ram);
+               goto probe_exit_candev;
        }
 
        /* handle mbx memory */
        priv->mbx = devm_platform_ioremap_resource_byname(pdev, "mbx");
        if (IS_ERR(priv->mbx)) {
                dev_err(&pdev->dev, "mbx ioremap failed\n");
-               return PTR_ERR(priv->mbx);
+               err = PTR_ERR(priv->mbx);
+               goto probe_exit_candev;
        }
 
        irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
        if (!irq) {
                dev_err(&pdev->dev, "No irq resource\n");
-               goto probe_exit;
+               goto probe_exit_candev;
        }
 
        priv->ndev = ndev;
@@ -933,7 +936,7 @@ static int ti_hecc_probe(struct platform_device *pdev)
        err = clk_prepare_enable(priv->clk);
        if (err) {
                dev_err(&pdev->dev, "clk_prepare_enable() failed\n");
-               goto probe_exit_clk;
+               goto probe_exit_release_clk;
        }
 
        priv->offload.mailbox_read = ti_hecc_mailbox_read;
@@ -942,7 +945,7 @@ static int ti_hecc_probe(struct platform_device *pdev)
        err = can_rx_offload_add_timestamp(ndev, &priv->offload);
        if (err) {
                dev_err(&pdev->dev, "can_rx_offload_add_timestamp() failed\n");
-               goto probe_exit_clk;
+               goto probe_exit_disable_clk;
        }
 
        err = register_candev(ndev);
@@ -960,11 +963,13 @@ static int ti_hecc_probe(struct platform_device *pdev)
 
 probe_exit_offload:
        can_rx_offload_del(&priv->offload);
-probe_exit_clk:
+probe_exit_disable_clk:
+       clk_disable_unprepare(priv->clk);
+probe_exit_release_clk:
        clk_put(priv->clk);
 probe_exit_candev:
        free_candev(ndev);
-probe_exit:
+
        return err;
 }
 
index 7ab87a7..218fadc 100644 (file)
@@ -367,7 +367,7 @@ static const struct can_bittiming_const kvaser_usb_hydra_kcan_bittiming_c = {
        .tseg2_max = 32,
        .sjw_max = 16,
        .brp_min = 1,
-       .brp_max = 4096,
+       .brp_max = 8192,
        .brp_inc = 1,
 };
 
index 5857b37..e97f2e0 100644 (file)
@@ -326,8 +326,6 @@ static netdev_tx_t mcba_usb_start_xmit(struct sk_buff *skb,
        if (!ctx)
                return NETDEV_TX_BUSY;
 
-       can_put_echo_skb(skb, priv->netdev, ctx->ndx);
-
        if (cf->can_id & CAN_EFF_FLAG) {
                /* SIDH    | SIDL                 | EIDH   | EIDL
                 * 28 - 21 | 20 19 18 x x x 17 16 | 15 - 8 | 7 - 0
@@ -357,6 +355,8 @@ static netdev_tx_t mcba_usb_start_xmit(struct sk_buff *skb,
        if (cf->can_id & CAN_RTR_FLAG)
                usb_msg.dlc |= MCBA_DLC_RTR_MASK;
 
+       can_put_echo_skb(skb, priv->netdev, ctx->ndx);
+
        err = mcba_usb_xmit(priv, (struct mcba_usb_msg *)&usb_msg, ctx);
        if (err)
                goto xmit_failed;
index d91df34..204ccb2 100644 (file)
@@ -130,14 +130,55 @@ void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *time)
        /* protect from getting time before setting now */
        if (ktime_to_ns(time_ref->tv_host)) {
                u64 delta_us;
+               s64 delta_ts = 0;
+
+               /* General case: dev_ts_1 < dev_ts_2 < ts, with:
+                *
+                * - dev_ts_1 = previous sync timestamp
+                * - dev_ts_2 = last sync timestamp
+                * - ts = event timestamp
+                * - ts_period = known sync period (theoretical)
+                *             ~ dev_ts2 - dev_ts1
+                * *but*:
+                *
+                * - time counters wrap (see adapter->ts_used_bits)
+                * - sometimes, dev_ts_1 < ts < dev_ts2
+                *
+                * "normal" case (sync time counters increase):
+                * must take into account case when ts wraps (tsw)
+                *
+                *      < ts_period > <          >
+                *     |             |            |
+                *  ---+--------+----+-------0-+--+-->
+                *     ts_dev_1 |    ts_dev_2  |
+                *              ts             tsw
+                */
+               if (time_ref->ts_dev_1 < time_ref->ts_dev_2) {
+                       /* case when event time (tsw) wraps */
+                       if (ts < time_ref->ts_dev_1)
+                               delta_ts = BIT_ULL(time_ref->adapter->ts_used_bits);
+
+               /* Otherwise, sync time counter (ts_dev_2) has wrapped:
+                * handle case when event time (tsn) hasn't.
+                *
+                *      < ts_period > <          >
+                *     |             |            |
+                *  ---+--------+--0-+---------+--+-->
+                *     ts_dev_1 |    ts_dev_2  |
+                *              tsn            ts
+                */
+               } else if (time_ref->ts_dev_1 < ts) {
+                       delta_ts = -BIT_ULL(time_ref->adapter->ts_used_bits);
+               }
 
-               delta_us = ts - time_ref->ts_dev_2;
-               if (ts < time_ref->ts_dev_2)
-                       delta_us &= (1 << time_ref->adapter->ts_used_bits) - 1;
+               /* add delay between last sync and event timestamps */
+               delta_ts += (signed int)(ts - time_ref->ts_dev_2);
 
-               delta_us += time_ref->ts_total;
+               /* add time from beginning to last sync */
+               delta_ts += time_ref->ts_total;
 
-               delta_us *= time_ref->adapter->us_per_ts_scale;
+               /* convert ticks number into microseconds */
+               delta_us = delta_ts * time_ref->adapter->us_per_ts_scale;
                delta_us >>= time_ref->adapter->us_per_ts_shift;
 
                *time = ktime_add_us(time_ref->tv_host_0, delta_us);
index ab63fd9..d29d205 100644 (file)
@@ -468,12 +468,18 @@ static int pcan_usb_fd_decode_canmsg(struct pcan_usb_fd_if *usb_if,
                                     struct pucan_msg *rx_msg)
 {
        struct pucan_rx_msg *rm = (struct pucan_rx_msg *)rx_msg;
-       struct peak_usb_device *dev = usb_if->dev[pucan_msg_get_channel(rm)];
-       struct net_device *netdev = dev->netdev;
+       struct peak_usb_device *dev;
+       struct net_device *netdev;
        struct canfd_frame *cfd;
        struct sk_buff *skb;
        const u16 rx_msg_flags = le16_to_cpu(rm->flags);
 
+       if (pucan_msg_get_channel(rm) >= ARRAY_SIZE(usb_if->dev))
+               return -ENOMEM;
+
+       dev = usb_if->dev[pucan_msg_get_channel(rm)];
+       netdev = dev->netdev;
+
        if (rx_msg_flags & PUCAN_MSG_EXT_DATA_LEN) {
                /* CANFD frame case */
                skb = alloc_canfd_skb(netdev, &cfd);
@@ -519,15 +525,21 @@ static int pcan_usb_fd_decode_status(struct pcan_usb_fd_if *usb_if,
                                     struct pucan_msg *rx_msg)
 {
        struct pucan_status_msg *sm = (struct pucan_status_msg *)rx_msg;
-       struct peak_usb_device *dev = usb_if->dev[pucan_stmsg_get_channel(sm)];
-       struct pcan_usb_fd_device *pdev =
-                       container_of(dev, struct pcan_usb_fd_device, dev);
+       struct pcan_usb_fd_device *pdev;
        enum can_state new_state = CAN_STATE_ERROR_ACTIVE;
        enum can_state rx_state, tx_state;
-       struct net_device *netdev = dev->netdev;
+       struct peak_usb_device *dev;
+       struct net_device *netdev;
        struct can_frame *cf;
        struct sk_buff *skb;
 
+       if (pucan_stmsg_get_channel(sm) >= ARRAY_SIZE(usb_if->dev))
+               return -ENOMEM;
+
+       dev = usb_if->dev[pucan_stmsg_get_channel(sm)];
+       pdev = container_of(dev, struct pcan_usb_fd_device, dev);
+       netdev = dev->netdev;
+
        /* nothing should be sent while in BUS_OFF state */
        if (dev->can.state == CAN_STATE_BUS_OFF)
                return 0;
@@ -579,9 +591,14 @@ static int pcan_usb_fd_decode_error(struct pcan_usb_fd_if *usb_if,
                                    struct pucan_msg *rx_msg)
 {
        struct pucan_error_msg *er = (struct pucan_error_msg *)rx_msg;
-       struct peak_usb_device *dev = usb_if->dev[pucan_ermsg_get_channel(er)];
-       struct pcan_usb_fd_device *pdev =
-                       container_of(dev, struct pcan_usb_fd_device, dev);
+       struct pcan_usb_fd_device *pdev;
+       struct peak_usb_device *dev;
+
+       if (pucan_ermsg_get_channel(er) >= ARRAY_SIZE(usb_if->dev))
+               return -EINVAL;
+
+       dev = usb_if->dev[pucan_ermsg_get_channel(er)];
+       pdev = container_of(dev, struct pcan_usb_fd_device, dev);
 
        /* keep a trace of tx and rx error counters for later use */
        pdev->bec.txerr = er->tx_err_cnt;
@@ -595,11 +612,17 @@ static int pcan_usb_fd_decode_overrun(struct pcan_usb_fd_if *usb_if,
                                      struct pucan_msg *rx_msg)
 {
        struct pcan_ufd_ovr_msg *ov = (struct pcan_ufd_ovr_msg *)rx_msg;
-       struct peak_usb_device *dev = usb_if->dev[pufd_omsg_get_channel(ov)];
-       struct net_device *netdev = dev->netdev;
+       struct peak_usb_device *dev;
+       struct net_device *netdev;
        struct can_frame *cf;
        struct sk_buff *skb;
 
+       if (pufd_omsg_get_channel(ov) >= ARRAY_SIZE(usb_if->dev))
+               return -EINVAL;
+
+       dev = usb_if->dev[pufd_omsg_get_channel(ov)];
+       netdev = dev->netdev;
+
        /* allocate an skb to store the error frame */
        skb = alloc_can_err_skb(netdev, &cf);
        if (!skb)
@@ -716,6 +739,9 @@ static int pcan_usb_fd_encode_msg(struct peak_usb_device *dev,
        u16 tx_msg_size, tx_msg_flags;
        u8 can_dlc;
 
+       if (cfd->len > CANFD_MAX_DLEN)
+               return -EINVAL;
+
        tx_msg_size = ALIGN(sizeof(struct pucan_tx_msg) + cfd->len, 4);
        tx_msg->size = cpu_to_le16(tx_msg_size);
        tx_msg->type = cpu_to_le16(PUCAN_MSG_CAN_TX);
index 6c4d00d..48d746e 100644 (file)
@@ -1395,7 +1395,7 @@ static int xcan_open(struct net_device *ndev)
        if (ret < 0) {
                netdev_err(ndev, "%s: pm_runtime_get failed(%d)\n",
                           __func__, ret);
-               return ret;
+               goto err;
        }
 
        ret = request_irq(ndev->irq, xcan_interrupt, priv->irq_flags,
@@ -1479,6 +1479,7 @@ static int xcan_get_berr_counter(const struct net_device *ndev,
        if (ret < 0) {
                netdev_err(ndev, "%s: pm_runtime_get failed(%d)\n",
                           __func__, ret);
+               pm_runtime_put(priv->dev);
                return ret;
        }
 
@@ -1793,7 +1794,7 @@ static int xcan_probe(struct platform_device *pdev)
        if (ret < 0) {
                netdev_err(ndev, "%s: pm_runtime_get failed(%d)\n",
                           __func__, ret);
-               goto err_pmdisable;
+               goto err_disableclks;
        }
 
        if (priv->read_reg(priv, XCAN_SR_OFFSET) != XCAN_SR_CONFIG_MASK) {
@@ -1828,7 +1829,6 @@ static int xcan_probe(struct platform_device *pdev)
 
 err_disableclks:
        pm_runtime_put(priv->dev);
-err_pmdisable:
        pm_runtime_disable(&pdev->dev);
 err_free:
        free_candev(ndev);
index 74db81d..09701c1 100644 (file)
@@ -26,6 +26,7 @@
  */
 
 #include <linux/clk.h>
+#include <linux/delay.h>
 #include <linux/etherdevice.h>
 #include <linux/firmware.h>
 #include <linux/if_bridge.h>
@@ -1837,6 +1838,16 @@ static int gswip_gphy_fw_list(struct gswip_priv *priv,
                i++;
        }
 
+       /* The standalone PHY11G requires 300ms to be fully
+        * initialized and ready for any MDIO communication after being
+        * taken out of reset. For the SoC-internal GPHY variant there
+        * is no (known) documentation for the minimum time after a
+        * reset. Use the same value as for the standalone variant as
+        * some users have reported internal PHYs not being detected
+        * without any delay.
+        */
+       msleep(300);
+
        return 0;
 
 remove_gphy:
index bd297ae..34cca0a 100644 (file)
@@ -2297,6 +2297,8 @@ static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
                usleep_range(10000, 20000);
                gpiod_set_value_cansleep(gpiod, 0);
                usleep_range(10000, 20000);
+
+               mv88e6xxx_g1_wait_eeprom_done(chip);
        }
 }
 
index 10cd1bf..ade04c0 100644 (file)
@@ -393,8 +393,10 @@ static int mv88e6xxx_region_atu_snapshot(struct devlink *dl,
        mv88e6xxx_reg_lock(chip);
 
        err = mv88e6xxx_fid_map(chip, fid_bitmap);
-       if (err)
+       if (err) {
+               kfree(table);
                goto out;
+       }
 
        while (1) {
                fid = find_next_bit(fid_bitmap, MV88E6XXX_N_FID, fid + 1);
index f62aa83..33d443a 100644 (file)
@@ -75,6 +75,37 @@ static int mv88e6xxx_g1_wait_init_ready(struct mv88e6xxx_chip *chip)
        return mv88e6xxx_g1_wait_bit(chip, MV88E6XXX_G1_STS, bit, 1);
 }
 
+void mv88e6xxx_g1_wait_eeprom_done(struct mv88e6xxx_chip *chip)
+{
+       const unsigned long timeout = jiffies + 1 * HZ;
+       u16 val;
+       int err;
+
+       /* Wait up to 1 second for the switch to finish reading the
+        * EEPROM.
+        */
+       while (time_before(jiffies, timeout)) {
+               err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &val);
+               if (err) {
+                       dev_err(chip->dev, "Error reading status");
+                       return;
+               }
+
+               /* If the switch is still resetting, it may not
+                * respond on the bus, and so MDIO read returns
+                * 0xffff. Differentiate between that, and waiting for
+                * the EEPROM to be done by bit 0 being set.
+                */
+               if (val != 0xffff &&
+                   val & BIT(MV88E6XXX_G1_STS_IRQ_EEPROM_DONE))
+                       return;
+
+               usleep_range(1000, 2000);
+       }
+
+       dev_err(chip->dev, "Timeout waiting for EEPROM done");
+}
+
 /* Offset 0x01: Switch MAC Address Register Bytes 0 & 1
  * Offset 0x02: Switch MAC Address Register Bytes 2 & 3
  * Offset 0x03: Switch MAC Address Register Bytes 4 & 5
index 1e3546f..e05abe6 100644 (file)
@@ -278,6 +278,7 @@ int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr);
 int mv88e6185_g1_reset(struct mv88e6xxx_chip *chip);
 int mv88e6352_g1_reset(struct mv88e6xxx_chip *chip);
 int mv88e6250_g1_reset(struct mv88e6xxx_chip *chip);
+void mv88e6xxx_g1_wait_eeprom_done(struct mv88e6xxx_chip *chip);
 
 int mv88e6185_g1_ppu_enable(struct mv88e6xxx_chip *chip);
 int mv88e6185_g1_ppu_disable(struct mv88e6xxx_chip *chip);
index 48390b7..1048509 100644 (file)
@@ -125,11 +125,9 @@ static int mv88e6xxx_g1_vtu_vid_write(struct mv88e6xxx_chip *chip,
  * Offset 0x08: VTU/STU Data Register 2
  * Offset 0x09: VTU/STU Data Register 3
  */
-
-static int mv88e6185_g1_vtu_data_read(struct mv88e6xxx_chip *chip,
-                                     struct mv88e6xxx_vtu_entry *entry)
+static int mv88e6185_g1_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
+                                         u16 *regs)
 {
-       u16 regs[3];
        int i;
 
        /* Read all 3 VTU/STU Data registers */
@@ -142,12 +140,45 @@ static int mv88e6185_g1_vtu_data_read(struct mv88e6xxx_chip *chip,
                        return err;
        }
 
-       /* Extract MemberTag and PortState data */
+       return 0;
+}
+
+static int mv88e6185_g1_vtu_data_read(struct mv88e6xxx_chip *chip,
+                                     struct mv88e6xxx_vtu_entry *entry)
+{
+       u16 regs[3];
+       int err;
+       int i;
+
+       err = mv88e6185_g1_vtu_stu_data_read(chip, regs);
+       if (err)
+               return err;
+
+       /* Extract MemberTag data */
        for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
                unsigned int member_offset = (i % 4) * 4;
-               unsigned int state_offset = member_offset + 2;
 
                entry->member[i] = (regs[i / 4] >> member_offset) & 0x3;
+       }
+
+       return 0;
+}
+
+static int mv88e6185_g1_stu_data_read(struct mv88e6xxx_chip *chip,
+                                     struct mv88e6xxx_vtu_entry *entry)
+{
+       u16 regs[3];
+       int err;
+       int i;
+
+       err = mv88e6185_g1_vtu_stu_data_read(chip, regs);
+       if (err)
+               return err;
+
+       /* Extract PortState data */
+       for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
+               unsigned int state_offset = (i % 4) * 4 + 2;
+
                entry->state[i] = (regs[i / 4] >> state_offset) & 0x3;
        }
 
@@ -349,6 +380,10 @@ int mv88e6185_g1_vtu_getnext(struct mv88e6xxx_chip *chip,
                if (err)
                        return err;
 
+               err = mv88e6185_g1_stu_data_read(chip, entry);
+               if (err)
+                       return err;
+
                /* VTU DBNum[3:0] are located in VTU Operation 3:0
                 * VTU DBNum[7:4] are located in VTU Operation 11:8
                 */
@@ -374,16 +409,20 @@ int mv88e6352_g1_vtu_getnext(struct mv88e6xxx_chip *chip,
                return err;
 
        if (entry->valid) {
-               /* Fetch (and mask) VLAN PortState data from the STU */
-               err = mv88e6xxx_g1_vtu_stu_get(chip, entry);
+               err = mv88e6185_g1_vtu_data_read(chip, entry);
                if (err)
                        return err;
 
-               err = mv88e6185_g1_vtu_data_read(chip, entry);
+               err = mv88e6xxx_g1_vtu_fid_read(chip, entry);
                if (err)
                        return err;
 
-               err = mv88e6xxx_g1_vtu_fid_read(chip, entry);
+               /* Fetch VLAN PortState data from the STU */
+               err = mv88e6xxx_g1_vtu_stu_get(chip, entry);
+               if (err)
+                       return err;
+
+               err = mv88e6185_g1_stu_data_read(chip, entry);
                if (err)
                        return err;
        }
index 53064e0..5bdac66 100644 (file)
@@ -1219,8 +1219,8 @@ qca8k_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
        priv->port_mtu[port] = new_mtu;
 
        for (i = 0; i < QCA8K_NUM_PORTS; i++)
-               if (priv->port_mtu[port] > mtu)
-                       mtu = priv->port_mtu[port];
+               if (priv->port_mtu[i] > mtu)
+                       mtu = priv->port_mtu[i];
 
        /* Include L2 header / FCS length */
        qca8k_write(priv, QCA8K_MAX_FRAME_SIZE, mtu + ETH_HLEN + ETH_FCS_LEN);
index 0c12cf7..3f65f2b 100644 (file)
@@ -2543,8 +2543,8 @@ static int atl1c_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
         * various kernel subsystems to support the mechanics required by a
         * fixed-high-32-bit system.
         */
-       if ((dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)) != 0) ||
-           (dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)) != 0)) {
+       err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
+       if (err) {
                dev_err(&pdev->dev, "No usable DMA configuration,aborting\n");
                goto err_dma;
        }
index 098b032..ff9f96d 100644 (file)
@@ -2312,8 +2312,8 @@ static int atl1e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
         * various kernel subsystems to support the mechanics required by a
         * fixed-high-32-bit system.
         */
-       if ((dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)) != 0) ||
-           (dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)) != 0)) {
+       err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
+       if (err) {
                dev_err(&pdev->dev, "No usable DMA configuration,aborting\n");
                goto err_dma;
        }
index 74c1778..b455b60 100644 (file)
@@ -2383,7 +2383,8 @@ static int b44_init_one(struct ssb_device *sdev,
                goto err_out_free_dev;
        }
 
-       if (dma_set_mask_and_coherent(sdev->dma_dev, DMA_BIT_MASK(30))) {
+       err = dma_set_mask_and_coherent(sdev->dma_dev, DMA_BIT_MASK(30));
+       if (err) {
                dev_err(sdev->dev,
                        "Required 30BIT DMA mask unsupported by the system\n");
                goto err_out_powerdown;
index 7975f59..7c21aaa 100644 (file)
@@ -4099,7 +4099,8 @@ static void bnxt_free_mem(struct bnxt *bp, bool irq_re_init)
        bnxt_free_ntp_fltrs(bp, irq_re_init);
        if (irq_re_init) {
                bnxt_free_ring_stats(bp);
-               if (!(bp->fw_cap & BNXT_FW_CAP_PORT_STATS_NO_RESET))
+               if (!(bp->fw_cap & BNXT_FW_CAP_PORT_STATS_NO_RESET) ||
+                   test_bit(BNXT_STATE_IN_FW_RESET, &bp->state))
                        bnxt_free_port_stats(bp);
                bnxt_free_ring_grps(bp);
                bnxt_free_vnics(bp);
@@ -7757,6 +7758,7 @@ static void bnxt_add_one_ctr(u64 hw, u64 *sw, u64 mask)
 {
        u64 sw_tmp;
 
+       hw &= mask;
        sw_tmp = (*sw & ~mask) | hw;
        if (hw < (*sw & mask))
                sw_tmp += mask + 1;
index 53687bc..1471c9a 100644 (file)
@@ -2079,6 +2079,9 @@ int bnxt_hwrm_nvm_get_dev_info(struct bnxt *bp,
        struct hwrm_nvm_get_dev_info_input req = {0};
        int rc;
 
+       if (BNXT_VF(bp))
+               return -EOPNOTSUPP;
+
        bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DEV_INFO, -1, -1);
        mutex_lock(&bp->hwrm_cmd_lock);
        rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
@@ -2997,7 +3000,7 @@ static int bnxt_get_module_eeprom(struct net_device *dev,
        /* Read A2 portion of the EEPROM */
        if (length) {
                start -= ETH_MODULE_SFF_8436_LEN;
-               rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A2, 1,
+               rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A2, 0,
                                                      start, length, data);
        }
        return rc;
index 883e47c..286f034 100644 (file)
@@ -1929,7 +1929,8 @@ static inline int macb_clear_csum(struct sk_buff *skb)
 
 static int macb_pad_and_fcs(struct sk_buff **skb, struct net_device *ndev)
 {
-       bool cloned = skb_cloned(*skb) || skb_header_cloned(*skb);
+       bool cloned = skb_cloned(*skb) || skb_header_cloned(*skb) ||
+                     skb_is_nonlinear(*skb);
        int padlen = ETH_ZLEN - (*skb)->len;
        int headroom = skb_headroom(*skb);
        int tailroom = skb_tailroom(*skb);
index 3352dad..2730860 100644 (file)
@@ -2124,6 +2124,9 @@ void cxgb4_inline_tx_skb(const struct sk_buff *skb, const struct sge_txq *q,
 void cxgb4_write_sgl(const struct sk_buff *skb, struct sge_txq *q,
                     struct ulptx_sgl *sgl, u64 *end, unsigned int start,
                     const dma_addr_t *addr);
+void cxgb4_write_partial_sgl(const struct sk_buff *skb, struct sge_txq *q,
+                            struct ulptx_sgl *sgl, u64 *end,
+                            const dma_addr_t *addr, u32 start, u32 send_len);
 void cxgb4_ring_tx_db(struct adapter *adap, struct sge_txq *q, int n);
 int t4_set_vlan_acl(struct adapter *adap, unsigned int mbox, unsigned int vf,
                    u16 vlan);
index 0273f40..17410fe 100644 (file)
@@ -3573,6 +3573,8 @@ static int chcr_stats_show(struct seq_file *seq, void *v)
                   atomic64_read(&adap->ch_ktls_stats.ktls_tx_complete_pkts));
        seq_printf(seq, "TX trim pkts :                    %20llu\n",
                   atomic64_read(&adap->ch_ktls_stats.ktls_tx_trimmed_pkts));
+       seq_printf(seq, "TX sw fallback :                  %20llu\n",
+                  atomic64_read(&adap->ch_ktls_stats.ktls_tx_fallback));
        while (i < MAX_NPORTS) {
                ktls_port = &adap->ch_ktls_stats.ktls_port[i];
                seq_printf(seq, "Port %d\n", i);
index a952fe1..7fd264a 100644 (file)
@@ -1176,6 +1176,7 @@ static u16 cxgb_select_queue(struct net_device *dev, struct sk_buff *skb,
                txq = netdev_pick_tx(dev, skb, sb_dev);
                if (xfrm_offload(skb) || is_ptp_enabled(skb, dev) ||
                    skb->encapsulation ||
+                   cxgb4_is_ktls_skb(skb) ||
                    (proto != IPPROTO_TCP && proto != IPPROTO_UDP))
                        txq = txq % pi->nqsets;
 
index b169776..1b49f2f 100644 (file)
@@ -388,6 +388,7 @@ struct ch_ktls_stats_debug {
        atomic64_t ktls_tx_retransmit_pkts;
        atomic64_t ktls_tx_complete_pkts;
        atomic64_t ktls_tx_trimmed_pkts;
+       atomic64_t ktls_tx_fallback;
 };
 #endif
 
@@ -493,6 +494,11 @@ struct cxgb4_uld_info {
 #endif
 };
 
+static inline bool cxgb4_is_ktls_skb(struct sk_buff *skb)
+{
+       return skb->sk && tls_is_sk_tx_device_offloaded(skb->sk);
+}
+
 void cxgb4_uld_enable(struct adapter *adap);
 void cxgb4_register_uld(enum cxgb4_uld type, const struct cxgb4_uld_info *p);
 int cxgb4_unregister_uld(enum cxgb4_uld type);
index a9e9c7a..196652a 100644 (file)
@@ -890,6 +890,114 @@ void cxgb4_write_sgl(const struct sk_buff *skb, struct sge_txq *q,
 }
 EXPORT_SYMBOL(cxgb4_write_sgl);
 
+/*     cxgb4_write_partial_sgl - populate SGL for partial packet
+ *     @skb: the packet
+ *     @q: the Tx queue we are writing into
+ *     @sgl: starting location for writing the SGL
+ *     @end: points right after the end of the SGL
+ *     @addr: the list of bus addresses for the SGL elements
+ *     @start: start offset in the SKB where partial data starts
+ *     @len: length of data from @start to send out
+ *
+ *     This API will handle sending out partial data of a skb if required.
+ *     Unlike cxgb4_write_sgl, @start can be any offset into the skb data,
+ *     and @len will decide how much data after @start offset to send out.
+ */
+void cxgb4_write_partial_sgl(const struct sk_buff *skb, struct sge_txq *q,
+                            struct ulptx_sgl *sgl, u64 *end,
+                            const dma_addr_t *addr, u32 start, u32 len)
+{
+       struct ulptx_sge_pair buf[MAX_SKB_FRAGS / 2 + 1] = {0}, *to;
+       u32 frag_size, skb_linear_data_len = skb_headlen(skb);
+       struct skb_shared_info *si = skb_shinfo(skb);
+       u8 i = 0, frag_idx = 0, nfrags = 0;
+       skb_frag_t *frag;
+
+       /* Fill the first SGL either from linear data or from partial
+        * frag based on @start.
+        */
+       if (unlikely(start < skb_linear_data_len)) {
+               frag_size = min(len, skb_linear_data_len - start);
+               sgl->len0 = htonl(frag_size);
+               sgl->addr0 = cpu_to_be64(addr[0] + start);
+               len -= frag_size;
+               nfrags++;
+       } else {
+               start -= skb_linear_data_len;
+               frag = &si->frags[frag_idx];
+               frag_size = skb_frag_size(frag);
+               /* find the first frag */
+               while (start >= frag_size) {
+                       start -= frag_size;
+                       frag_idx++;
+                       frag = &si->frags[frag_idx];
+                       frag_size = skb_frag_size(frag);
+               }
+
+               frag_size = min(len, skb_frag_size(frag) - start);
+               sgl->len0 = cpu_to_be32(frag_size);
+               sgl->addr0 = cpu_to_be64(addr[frag_idx + 1] + start);
+               len -= frag_size;
+               nfrags++;
+               frag_idx++;
+       }
+
+       /* If the entire partial data fit in one SGL, then send it out
+        * now.
+        */
+       if (!len)
+               goto done;
+
+       /* Most of the complexity below deals with the possibility we hit the
+        * end of the queue in the middle of writing the SGL.  For this case
+        * only we create the SGL in a temporary buffer and then copy it.
+        */
+       to = (u8 *)end > (u8 *)q->stat ? buf : sgl->sge;
+
+       /* If the skb couldn't fit in first SGL completely, fill the
+        * rest of the frags in subsequent SGLs. Note that each SGL
+        * pair can store 2 frags.
+        */
+       while (len) {
+               frag_size = min(len, skb_frag_size(&si->frags[frag_idx]));
+               to->len[i & 1] = cpu_to_be32(frag_size);
+               to->addr[i & 1] = cpu_to_be64(addr[frag_idx + 1]);
+               if (i && (i & 1))
+                       to++;
+               nfrags++;
+               frag_idx++;
+               i++;
+               len -= frag_size;
+       }
+
+       /* If we ended in an odd boundary, then set the second SGL's
+        * length in the pair to 0.
+        */
+       if (i & 1)
+               to->len[1] = cpu_to_be32(0);
+
+       /* Copy from temporary buffer to Tx ring, in case we hit the
+        * end of the queue in the middle of writing the SGL.
+        */
+       if (unlikely((u8 *)end > (u8 *)q->stat)) {
+               u32 part0 = (u8 *)q->stat - (u8 *)sgl->sge, part1;
+
+               if (likely(part0))
+                       memcpy(sgl->sge, buf, part0);
+               part1 = (u8 *)end - (u8 *)q->stat;
+               memcpy(q->desc, (u8 *)buf + part0, part1);
+               end = (void *)q->desc + part1;
+       }
+
+       /* 0-pad to multiple of 16 */
+       if ((uintptr_t)end & 8)
+               *end = 0;
+done:
+       sgl->cmd_nsge = htonl(ULPTX_CMD_V(ULP_TX_SC_DSGL) |
+                       ULPTX_NSGE_V(nfrags));
+}
+EXPORT_SYMBOL(cxgb4_write_partial_sgl);
+
 /* This function copies 64 byte coalesced work request to
  * memory mapped BAR2 space. For coalesced WR SGE fetches
  * data from the FIFO instead of from Host.
@@ -1422,7 +1530,8 @@ static netdev_tx_t cxgb4_eth_xmit(struct sk_buff *skb, struct net_device *dev)
 #endif /* CHELSIO_IPSEC_INLINE */
 
 #if IS_ENABLED(CONFIG_CHELSIO_TLS_DEVICE)
-       if (skb->decrypted)
+       if (cxgb4_is_ktls_skb(skb) &&
+           (skb->len - (skb_transport_offset(skb) + tcp_hdrlen(skb))))
                return adap->uld[CXGB4_ULD_KTLS].tx_handler(skb, dev);
 #endif /* CHELSIO_TLS_DEVICE */
 
index 5195f69..c24485c 100644 (file)
 static LIST_HEAD(uld_ctx_list);
 static DEFINE_MUTEX(dev_mutex);
 
+/* chcr_get_nfrags_to_send: get the remaining nfrags after start offset
+ * @skb: skb
+ * @start: start offset.
+ * @len: how much data to send after @start
+ */
+static int chcr_get_nfrags_to_send(struct sk_buff *skb, u32 start, u32 len)
+{
+       struct skb_shared_info *si = skb_shinfo(skb);
+       u32 frag_size, skb_linear_data_len = skb_headlen(skb);
+       u8 nfrags = 0, frag_idx = 0;
+       skb_frag_t *frag;
+
+       /* if its a linear skb then return 1 */
+       if (!skb_is_nonlinear(skb))
+               return 1;
+
+       if (unlikely(start < skb_linear_data_len)) {
+               frag_size = min(len, skb_linear_data_len - start);
+               start = 0;
+       } else {
+               start -= skb_linear_data_len;
+
+               frag = &si->frags[frag_idx];
+               frag_size = skb_frag_size(frag);
+               while (start >= frag_size) {
+                       start -= frag_size;
+                       frag_idx++;
+                       frag = &si->frags[frag_idx];
+                       frag_size = skb_frag_size(frag);
+               }
+               frag_size = min(len, skb_frag_size(frag) - start);
+       }
+       len -= frag_size;
+       nfrags++;
+
+       while (len) {
+               frag_size = min(len, skb_frag_size(&si->frags[frag_idx]));
+               len -= frag_size;
+               nfrags++;
+               frag_idx++;
+       }
+       return nfrags;
+}
+
 static int chcr_init_tcb_fields(struct chcr_ktls_info *tx_info);
 /*
  * chcr_ktls_save_keys: calculate and save crypto keys.
@@ -689,7 +733,8 @@ static int chcr_ktls_cpl_set_tcb_rpl(struct adapter *adap, unsigned char *input)
 }
 
 static void *__chcr_write_cpl_set_tcb_ulp(struct chcr_ktls_info *tx_info,
-                                       u32 tid, void *pos, u16 word, u64 mask,
+                                       u32 tid, void *pos, u16 word,
+                                       struct sge_eth_txq *q, u64 mask,
                                        u64 val, u32 reply)
 {
        struct cpl_set_tcb_field_core *cpl;
@@ -698,7 +743,10 @@ static void *__chcr_write_cpl_set_tcb_ulp(struct chcr_ktls_info *tx_info,
 
        /* ULP_TXPKT */
        txpkt = pos;
-       txpkt->cmd_dest = htonl(ULPTX_CMD_V(ULP_TX_PKT) | ULP_TXPKT_DEST_V(0));
+       txpkt->cmd_dest = htonl(ULPTX_CMD_V(ULP_TX_PKT) |
+                               ULP_TXPKT_CHANNELID_V(tx_info->port_id) |
+                               ULP_TXPKT_FID_V(q->q.cntxt_id) |
+                               ULP_TXPKT_RO_F);
        txpkt->len = htonl(DIV_ROUND_UP(CHCR_SET_TCB_FIELD_LEN, 16));
 
        /* ULPTX_IDATA sub-command */
@@ -753,7 +801,7 @@ static void *chcr_write_cpl_set_tcb_ulp(struct chcr_ktls_info *tx_info,
                } else {
                        u8 buf[48] = {0};
 
-                       __chcr_write_cpl_set_tcb_ulp(tx_info, tid, buf, word,
+                       __chcr_write_cpl_set_tcb_ulp(tx_info, tid, buf, word, q,
                                                     mask, val, reply);
 
                        return chcr_copy_to_txd(buf, &q->q, pos,
@@ -761,7 +809,7 @@ static void *chcr_write_cpl_set_tcb_ulp(struct chcr_ktls_info *tx_info,
                }
        }
 
-       pos = __chcr_write_cpl_set_tcb_ulp(tx_info, tid, pos, word,
+       pos = __chcr_write_cpl_set_tcb_ulp(tx_info, tid, pos, word, q,
                                           mask, val, reply);
 
        /* check again if we are at the end of the queue */
@@ -783,11 +831,11 @@ static void *chcr_write_cpl_set_tcb_ulp(struct chcr_ktls_info *tx_info,
  */
 static int chcr_ktls_xmit_tcb_cpls(struct chcr_ktls_info *tx_info,
                                   struct sge_eth_txq *q, u64 tcp_seq,
-                                  u64 tcp_ack, u64 tcp_win)
+                                  u64 tcp_ack, u64 tcp_win, bool offset)
 {
        bool first_wr = ((tx_info->prev_ack == 0) && (tx_info->prev_win == 0));
        struct ch_ktls_port_stats_debug *port_stats;
-       u32 len, cpl = 0, ndesc, wr_len;
+       u32 len, cpl = 0, ndesc, wr_len, wr_mid = 0;
        struct fw_ulptx_wr *wr;
        int credits;
        void *pos;
@@ -803,6 +851,11 @@ static int chcr_ktls_xmit_tcb_cpls(struct chcr_ktls_info *tx_info,
                return NETDEV_TX_BUSY;
        }
 
+       if (unlikely(credits < ETHTXQ_STOP_THRES)) {
+               chcr_eth_txq_stop(q);
+               wr_mid |= FW_WR_EQUEQ_F | FW_WR_EQUIQ_F;
+       }
+
        pos = &q->q.desc[q->q.pidx];
        /* make space for WR, we'll fill it later when we know all the cpls
         * being sent out and have complete length.
@@ -818,7 +871,7 @@ static int chcr_ktls_xmit_tcb_cpls(struct chcr_ktls_info *tx_info,
                cpl++;
        }
        /* reset snd una if it's a re-transmit pkt */
-       if (tcp_seq != tx_info->prev_seq) {
+       if (tcp_seq != tx_info->prev_seq || offset) {
                /* reset snd_una */
                port_stats =
                        &tx_info->adap->ch_ktls_stats.ktls_port[tx_info->port_id];
@@ -827,7 +880,8 @@ static int chcr_ktls_xmit_tcb_cpls(struct chcr_ktls_info *tx_info,
                                                 TCB_SND_UNA_RAW_V
                                                 (TCB_SND_UNA_RAW_M),
                                                 TCB_SND_UNA_RAW_V(0), 0);
-               atomic64_inc(&port_stats->ktls_tx_ooo);
+               if (tcp_seq != tx_info->prev_seq)
+                       atomic64_inc(&port_stats->ktls_tx_ooo);
                cpl++;
        }
        /* update ack */
@@ -856,7 +910,8 @@ static int chcr_ktls_xmit_tcb_cpls(struct chcr_ktls_info *tx_info,
                wr->op_to_compl = htonl(FW_WR_OP_V(FW_ULPTX_WR));
                wr->cookie = 0;
                /* fill len in wr field */
-               wr->flowid_len16 = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(len, 16)));
+               wr->flowid_len16 = htonl(wr_mid |
+                                        FW_WR_LEN16_V(DIV_ROUND_UP(len, 16)));
 
                ndesc = DIV_ROUND_UP(len, 64);
                chcr_txq_advance(&q->q, ndesc);
@@ -865,35 +920,15 @@ static int chcr_ktls_xmit_tcb_cpls(struct chcr_ktls_info *tx_info,
        return 0;
 }
 
-/*
- * chcr_ktls_skb_copy
- * @nskb - new skb where the frags to be added.
- * @skb - old skb from which frags will be copied.
- */
-static void chcr_ktls_skb_copy(struct sk_buff *skb, struct sk_buff *nskb)
-{
-       int i;
-
-       for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
-               skb_shinfo(nskb)->frags[i] = skb_shinfo(skb)->frags[i];
-               __skb_frag_ref(&skb_shinfo(nskb)->frags[i]);
-       }
-
-       skb_shinfo(nskb)->nr_frags = skb_shinfo(skb)->nr_frags;
-       nskb->len += skb->data_len;
-       nskb->data_len = skb->data_len;
-       nskb->truesize += skb->data_len;
-}
-
 /*
  * chcr_ktls_get_tx_flits
  * returns number of flits to be sent out, it includes key context length, WR
  * size and skb fragments.
  */
 static unsigned int
-chcr_ktls_get_tx_flits(const struct sk_buff *skb, unsigned int key_ctx_len)
+chcr_ktls_get_tx_flits(u32 nr_frags, unsigned int key_ctx_len)
 {
-       return chcr_sgl_len(skb_shinfo(skb)->nr_frags) +
+       return chcr_sgl_len(nr_frags) +
               DIV_ROUND_UP(key_ctx_len + CHCR_KTLS_WR_SIZE, 8);
 }
 
@@ -957,8 +992,10 @@ chcr_ktls_write_tcp_options(struct chcr_ktls_info *tx_info, struct sk_buff *skb,
        struct tcphdr *tcp;
        int len16, pktlen;
        struct iphdr *ip;
+       u32 wr_mid = 0;
        int credits;
        u8 buf[150];
+       u64 cntrl1;
        void *pos;
 
        iplen = skb_network_header_len(skb);
@@ -967,7 +1004,7 @@ chcr_ktls_write_tcp_options(struct chcr_ktls_info *tx_info, struct sk_buff *skb,
        /* packet length = eth hdr len + ip hdr len + tcp hdr len
         * (including options).
         */
-       pktlen = skb->len - skb->data_len;
+       pktlen = skb_transport_offset(skb) + tcp_hdrlen(skb);
 
        ctrl = sizeof(*cpl) + pktlen;
        len16 = DIV_ROUND_UP(sizeof(*wr) + ctrl, 16);
@@ -980,6 +1017,11 @@ chcr_ktls_write_tcp_options(struct chcr_ktls_info *tx_info, struct sk_buff *skb,
                return NETDEV_TX_BUSY;
        }
 
+       if (unlikely(credits < ETHTXQ_STOP_THRES)) {
+               chcr_eth_txq_stop(q);
+               wr_mid |= FW_WR_EQUEQ_F | FW_WR_EQUIQ_F;
+       }
+
        pos = &q->q.desc[q->q.pidx];
        wr = pos;
 
@@ -987,7 +1029,7 @@ chcr_ktls_write_tcp_options(struct chcr_ktls_info *tx_info, struct sk_buff *skb,
        wr->op_immdlen = htonl(FW_WR_OP_V(FW_ETH_TX_PKT_WR) |
                               FW_WR_IMMDLEN_V(ctrl));
 
-       wr->equiq_to_len16 = htonl(FW_WR_LEN16_V(len16));
+       wr->equiq_to_len16 = htonl(wr_mid | FW_WR_LEN16_V(len16));
        wr->r3 = 0;
 
        cpl = (void *)(wr + 1);
@@ -997,22 +1039,28 @@ chcr_ktls_write_tcp_options(struct chcr_ktls_info *tx_info, struct sk_buff *skb,
                           TXPKT_PF_V(tx_info->adap->pf));
        cpl->pack = 0;
        cpl->len = htons(pktlen);
-       /* checksum offload */
-       cpl->ctrl1 = 0;
-
-       pos = cpl + 1;
 
        memcpy(buf, skb->data, pktlen);
        if (tx_info->ip_family == AF_INET) {
                /* we need to correct ip header len */
                ip = (struct iphdr *)(buf + maclen);
                ip->tot_len = htons(pktlen - maclen);
+               cntrl1 = TXPKT_CSUM_TYPE_V(TX_CSUM_TCPIP);
 #if IS_ENABLED(CONFIG_IPV6)
        } else {
                ip6 = (struct ipv6hdr *)(buf + maclen);
                ip6->payload_len = htons(pktlen - maclen - iplen);
+               cntrl1 = TXPKT_CSUM_TYPE_V(TX_CSUM_TCPIP6);
 #endif
        }
+
+       cntrl1 |= T6_TXPKT_ETHHDR_LEN_V(maclen - ETH_HLEN) |
+                 TXPKT_IPHDR_LEN_V(iplen);
+       /* checksum offload */
+       cpl->ctrl1 = cpu_to_be64(cntrl1);
+
+       pos = cpl + 1;
+
        /* now take care of the tcp header, if fin is not set then clear push
         * bit as well, and if fin is set, it will be sent at the last so we
         * need to update the tcp sequence number as per the last packet.
@@ -1031,71 +1079,6 @@ chcr_ktls_write_tcp_options(struct chcr_ktls_info *tx_info, struct sk_buff *skb,
        return 0;
 }
 
-/* chcr_ktls_skb_shift - Shifts request length paged data from skb to another.
- * @tgt- buffer into which tail data gets added
- * @skb- buffer from which the paged data comes from
- * @shiftlen- shift up to this many bytes
- */
-static int chcr_ktls_skb_shift(struct sk_buff *tgt, struct sk_buff *skb,
-                              int shiftlen)
-{
-       skb_frag_t *fragfrom, *fragto;
-       int from, to, todo;
-
-       WARN_ON(shiftlen > skb->data_len);
-
-       todo = shiftlen;
-       from = 0;
-       to = 0;
-       fragfrom = &skb_shinfo(skb)->frags[from];
-
-       while ((todo > 0) && (from < skb_shinfo(skb)->nr_frags)) {
-               fragfrom = &skb_shinfo(skb)->frags[from];
-               fragto = &skb_shinfo(tgt)->frags[to];
-
-               if (todo >= skb_frag_size(fragfrom)) {
-                       *fragto = *fragfrom;
-                       todo -= skb_frag_size(fragfrom);
-                       from++;
-                       to++;
-
-               } else {
-                       __skb_frag_ref(fragfrom);
-                       skb_frag_page_copy(fragto, fragfrom);
-                       skb_frag_off_copy(fragto, fragfrom);
-                       skb_frag_size_set(fragto, todo);
-
-                       skb_frag_off_add(fragfrom, todo);
-                       skb_frag_size_sub(fragfrom, todo);
-                       todo = 0;
-
-                       to++;
-                       break;
-               }
-       }
-
-       /* Ready to "commit" this state change to tgt */
-       skb_shinfo(tgt)->nr_frags = to;
-
-       /* Reposition in the original skb */
-       to = 0;
-       while (from < skb_shinfo(skb)->nr_frags)
-               skb_shinfo(skb)->frags[to++] = skb_shinfo(skb)->frags[from++];
-
-       skb_shinfo(skb)->nr_frags = to;
-
-       WARN_ON(todo > 0 && !skb_shinfo(skb)->nr_frags);
-
-       skb->len -= shiftlen;
-       skb->data_len -= shiftlen;
-       skb->truesize -= shiftlen;
-       tgt->len += shiftlen;
-       tgt->data_len += shiftlen;
-       tgt->truesize += shiftlen;
-
-       return shiftlen;
-}
-
 /*
  * chcr_ktls_xmit_wr_complete: This sends out the complete record. If an skb
  * received has partial end part of the record, send out the complete record, so
@@ -1111,6 +1094,8 @@ static int chcr_ktls_skb_shift(struct sk_buff *tgt, struct sk_buff *skb,
 static int chcr_ktls_xmit_wr_complete(struct sk_buff *skb,
                                      struct chcr_ktls_info *tx_info,
                                      struct sge_eth_txq *q, u32 tcp_seq,
+                                     bool is_last_wr, u32 data_len,
+                                     u32 skb_offset, u32 nfrags,
                                      bool tcp_push, u32 mss)
 {
        u32 len16, wr_mid = 0, flits = 0, ndesc, cipher_start;
@@ -1126,7 +1111,7 @@ static int chcr_ktls_xmit_wr_complete(struct sk_buff *skb,
        u64 *end;
 
        /* get the number of flits required */
-       flits = chcr_ktls_get_tx_flits(skb, tx_info->key_ctx_len);
+       flits = chcr_ktls_get_tx_flits(nfrags, tx_info->key_ctx_len);
        /* number of descriptors */
        ndesc = chcr_flits_to_desc(flits);
        /* check if enough credits available */
@@ -1155,6 +1140,9 @@ static int chcr_ktls_xmit_wr_complete(struct sk_buff *skb,
                return NETDEV_TX_BUSY;
        }
 
+       if (!is_last_wr)
+               skb_get(skb);
+
        pos = &q->q.desc[q->q.pidx];
        end = (u64 *)pos + flits;
        /* FW_ULPTX_WR */
@@ -1187,7 +1175,7 @@ static int chcr_ktls_xmit_wr_complete(struct sk_buff *skb,
                      CPL_TX_SEC_PDU_CPLLEN_V(CHCR_CPL_TX_SEC_PDU_LEN_64BIT) |
                      CPL_TX_SEC_PDU_PLACEHOLDER_V(1) |
                      CPL_TX_SEC_PDU_IVINSRTOFST_V(TLS_HEADER_SIZE + 1));
-       cpl->pldlen = htonl(skb->data_len);
+       cpl->pldlen = htonl(data_len);
 
        /* encryption should start after tls header size + iv size */
        cipher_start = TLS_HEADER_SIZE + tx_info->iv_size + 1;
@@ -1229,7 +1217,7 @@ static int chcr_ktls_xmit_wr_complete(struct sk_buff *skb,
        /* CPL_TX_DATA */
        tx_data = (void *)pos;
        OPCODE_TID(tx_data) = htonl(MK_OPCODE_TID(CPL_TX_DATA, tx_info->tid));
-       tx_data->len = htonl(TX_DATA_MSS_V(mss) | TX_LENGTH_V(skb->data_len));
+       tx_data->len = htonl(TX_DATA_MSS_V(mss) | TX_LENGTH_V(data_len));
 
        tx_data->rsvd = htonl(tcp_seq);
 
@@ -1249,8 +1237,8 @@ static int chcr_ktls_xmit_wr_complete(struct sk_buff *skb,
        }
 
        /* send the complete packet except the header */
-       cxgb4_write_sgl(skb, &q->q, pos, end, skb->len - skb->data_len,
-                       sgl_sdesc->addr);
+       cxgb4_write_partial_sgl(skb, &q->q, pos, end, sgl_sdesc->addr,
+                               skb_offset, data_len);
        sgl_sdesc->skb = skb;
 
        chcr_txq_advance(&q->q, ndesc);
@@ -1282,10 +1270,11 @@ static int chcr_ktls_xmit_wr_short(struct sk_buff *skb,
                                   struct sge_eth_txq *q,
                                   u32 tcp_seq, bool tcp_push, u32 mss,
                                   u32 tls_rec_offset, u8 *prior_data,
-                                  u32 prior_data_len)
+                                  u32 prior_data_len, u32 data_len,
+                                  u32 skb_offset)
 {
+       u32 len16, wr_mid = 0, cipher_start, nfrags;
        struct adapter *adap = tx_info->adap;
-       u32 len16, wr_mid = 0, cipher_start;
        unsigned int flits = 0, ndesc;
        int credits, left, last_desc;
        struct tx_sw_desc *sgl_sdesc;
@@ -1298,10 +1287,11 @@ static int chcr_ktls_xmit_wr_short(struct sk_buff *skb,
        void *pos;
        u64 *end;
 
+       nfrags = chcr_get_nfrags_to_send(skb, skb_offset, data_len);
        /* get the number of flits required, it's a partial record so 2 flits
         * (AES_BLOCK_SIZE) will be added.
         */
-       flits = chcr_ktls_get_tx_flits(skb, tx_info->key_ctx_len) + 2;
+       flits = chcr_ktls_get_tx_flits(nfrags, tx_info->key_ctx_len) + 2;
        /* get the correct 8 byte IV of this record */
        iv_record = cpu_to_be64(tx_info->iv + tx_info->record_no);
        /* If it's a middle record and not 16 byte aligned to run AES CTR, need
@@ -1373,7 +1363,7 @@ static int chcr_ktls_xmit_wr_short(struct sk_buff *skb,
                htonl(CPL_TX_SEC_PDU_OPCODE_V(CPL_TX_SEC_PDU) |
                      CPL_TX_SEC_PDU_CPLLEN_V(CHCR_CPL_TX_SEC_PDU_LEN_64BIT) |
                      CPL_TX_SEC_PDU_IVINSRTOFST_V(1));
-       cpl->pldlen = htonl(skb->data_len + AES_BLOCK_LEN + prior_data_len);
+       cpl->pldlen = htonl(data_len + AES_BLOCK_LEN + prior_data_len);
        cpl->aadstart_cipherstop_hi =
                htonl(CPL_TX_SEC_PDU_CIPHERSTART_V(cipher_start));
        cpl->cipherstop_lo_authinsert = 0;
@@ -1404,7 +1394,7 @@ static int chcr_ktls_xmit_wr_short(struct sk_buff *skb,
        tx_data = (void *)pos;
        OPCODE_TID(tx_data) = htonl(MK_OPCODE_TID(CPL_TX_DATA, tx_info->tid));
        tx_data->len = htonl(TX_DATA_MSS_V(mss) |
-                       TX_LENGTH_V(skb->data_len + prior_data_len));
+                            TX_LENGTH_V(data_len + prior_data_len));
        tx_data->rsvd = htonl(tcp_seq);
        tx_data->flags = htonl(TX_BYPASS_F);
        if (tcp_push)
@@ -1437,8 +1427,8 @@ static int chcr_ktls_xmit_wr_short(struct sk_buff *skb,
        if (prior_data_len)
                pos = chcr_copy_to_txd(prior_data, &q->q, pos, 16);
        /* send the complete packet except the header */
-       cxgb4_write_sgl(skb, &q->q, pos, end, skb->len - skb->data_len,
-                       sgl_sdesc->addr);
+       cxgb4_write_partial_sgl(skb, &q->q, pos, end, sgl_sdesc->addr,
+                               skb_offset, data_len);
        sgl_sdesc->skb = skb;
 
        chcr_txq_advance(&q->q, ndesc);
@@ -1466,6 +1456,7 @@ static int chcr_ktls_tx_plaintxt(struct chcr_ktls_info *tx_info,
                                 struct sk_buff *skb, u32 tcp_seq, u32 mss,
                                 bool tcp_push, struct sge_eth_txq *q,
                                 u32 port_id, u8 *prior_data,
+                                u32 data_len, u32 skb_offset,
                                 u32 prior_data_len)
 {
        int credits, left, len16, last_desc;
@@ -1475,14 +1466,16 @@ static int chcr_ktls_tx_plaintxt(struct chcr_ktls_info *tx_info,
        struct ulptx_idata *idata;
        struct ulp_txpkt *ulptx;
        struct fw_ulptx_wr *wr;
-       u32 wr_mid = 0;
+       u32 wr_mid = 0, nfrags;
        void *pos;
        u64 *end;
 
        flits = DIV_ROUND_UP(CHCR_PLAIN_TX_DATA_LEN, 8);
-       flits += chcr_sgl_len(skb_shinfo(skb)->nr_frags);
+       nfrags = chcr_get_nfrags_to_send(skb, skb_offset, data_len);
+       flits += chcr_sgl_len(nfrags);
        if (prior_data_len)
                flits += 2;
+
        /* WR will need len16 */
        len16 = DIV_ROUND_UP(flits, 2);
        /* check how many descriptors needed */
@@ -1535,7 +1528,7 @@ static int chcr_ktls_tx_plaintxt(struct chcr_ktls_info *tx_info,
        tx_data = (struct cpl_tx_data *)(idata + 1);
        OPCODE_TID(tx_data) = htonl(MK_OPCODE_TID(CPL_TX_DATA, tx_info->tid));
        tx_data->len = htonl(TX_DATA_MSS_V(mss) |
-                       TX_LENGTH_V(skb->data_len + prior_data_len));
+                            TX_LENGTH_V(data_len + prior_data_len));
        /* set tcp seq number */
        tx_data->rsvd = htonl(tcp_seq);
        tx_data->flags = htonl(TX_BYPASS_F);
@@ -1559,8 +1552,8 @@ static int chcr_ktls_tx_plaintxt(struct chcr_ktls_info *tx_info,
                end = pos + left;
        }
        /* send the complete packet including the header */
-       cxgb4_write_sgl(skb, &q->q, pos, end, skb->len - skb->data_len,
-                       sgl_sdesc->addr);
+       cxgb4_write_partial_sgl(skb, &q->q, pos, end, sgl_sdesc->addr,
+                               skb_offset, data_len);
        sgl_sdesc->skb = skb;
 
        chcr_txq_advance(&q->q, ndesc);
@@ -1568,12 +1561,96 @@ static int chcr_ktls_tx_plaintxt(struct chcr_ktls_info *tx_info,
        return 0;
 }
 
+static int chcr_ktls_tunnel_pkt(struct chcr_ktls_info *tx_info,
+                               struct sk_buff *skb,
+                               struct sge_eth_txq *q)
+{
+       u32 ctrl, iplen, maclen, wr_mid = 0, len16;
+       struct tx_sw_desc *sgl_sdesc;
+       struct fw_eth_tx_pkt_wr *wr;
+       struct cpl_tx_pkt_core *cpl;
+       unsigned int flits, ndesc;
+       int credits, last_desc;
+       u64 cntrl1, *end;
+       void *pos;
+
+       ctrl = sizeof(*cpl);
+       flits = DIV_ROUND_UP(sizeof(*wr) + ctrl, 8);
+
+       flits += chcr_sgl_len(skb_shinfo(skb)->nr_frags + 1);
+       len16 = DIV_ROUND_UP(flits, 2);
+       /* check how many descriptors needed */
+       ndesc = DIV_ROUND_UP(flits, 8);
+
+       credits = chcr_txq_avail(&q->q) - ndesc;
+       if (unlikely(credits < 0)) {
+               chcr_eth_txq_stop(q);
+               return -ENOMEM;
+       }
+
+       if (unlikely(credits < ETHTXQ_STOP_THRES)) {
+               chcr_eth_txq_stop(q);
+               wr_mid |= FW_WR_EQUEQ_F | FW_WR_EQUIQ_F;
+       }
+
+       last_desc = q->q.pidx + ndesc - 1;
+       if (last_desc >= q->q.size)
+               last_desc -= q->q.size;
+       sgl_sdesc = &q->q.sdesc[last_desc];
+
+       if (unlikely(cxgb4_map_skb(tx_info->adap->pdev_dev, skb,
+                                  sgl_sdesc->addr) < 0)) {
+               memset(sgl_sdesc->addr, 0, sizeof(sgl_sdesc->addr));
+               q->mapping_err++;
+               return -ENOMEM;
+       }
+
+       iplen = skb_network_header_len(skb);
+       maclen = skb_mac_header_len(skb);
+
+       pos = &q->q.desc[q->q.pidx];
+       end = (u64 *)pos + flits;
+       wr = pos;
+
+       /* Firmware work request header */
+       wr->op_immdlen = htonl(FW_WR_OP_V(FW_ETH_TX_PKT_WR) |
+                              FW_WR_IMMDLEN_V(ctrl));
+
+       wr->equiq_to_len16 = htonl(wr_mid | FW_WR_LEN16_V(len16));
+       wr->r3 = 0;
+
+       cpl = (void *)(wr + 1);
+
+       /* CPL header */
+       cpl->ctrl0 = htonl(TXPKT_OPCODE_V(CPL_TX_PKT) |
+                          TXPKT_INTF_V(tx_info->tx_chan) |
+                          TXPKT_PF_V(tx_info->adap->pf));
+       cpl->pack = 0;
+       cntrl1 = TXPKT_CSUM_TYPE_V(tx_info->ip_family == AF_INET ?
+                                  TX_CSUM_TCPIP : TX_CSUM_TCPIP6);
+       cntrl1 |= T6_TXPKT_ETHHDR_LEN_V(maclen - ETH_HLEN) |
+                 TXPKT_IPHDR_LEN_V(iplen);
+       /* checksum offload */
+       cpl->ctrl1 = cpu_to_be64(cntrl1);
+       cpl->len = htons(skb->len);
+
+       pos = cpl + 1;
+
+       cxgb4_write_sgl(skb, &q->q, pos, end, 0, sgl_sdesc->addr);
+       sgl_sdesc->skb = skb;
+       chcr_txq_advance(&q->q, ndesc);
+       cxgb4_ring_tx_db(tx_info->adap, &q->q, ndesc);
+       return 0;
+}
+
 /*
  * chcr_ktls_copy_record_in_skb
  * @nskb - new skb where the frags to be added.
+ * @skb - old skb, to copy socket and destructor details.
  * @record - specific record which has complete 16k record in frags.
  */
 static void chcr_ktls_copy_record_in_skb(struct sk_buff *nskb,
+                                        struct sk_buff *skb,
                                         struct tls_record_info *record)
 {
        int i = 0;
@@ -1588,6 +1665,9 @@ static void chcr_ktls_copy_record_in_skb(struct sk_buff *nskb,
        nskb->data_len = record->len;
        nskb->len += record->len;
        nskb->truesize += record->len;
+       nskb->sk = skb->sk;
+       nskb->destructor = skb->destructor;
+       refcount_add(nskb->truesize, &nskb->sk->sk_wmem_alloc);
 }
 
 /*
@@ -1659,7 +1739,7 @@ static int chcr_end_part_handler(struct chcr_ktls_info *tx_info,
                                 struct sk_buff *skb,
                                 struct tls_record_info *record,
                                 u32 tcp_seq, int mss, bool tcp_push_no_fin,
-                                struct sge_eth_txq *q,
+                                struct sge_eth_txq *q, u32 skb_offset,
                                 u32 tls_end_offset, bool last_wr)
 {
        struct sk_buff *nskb = NULL;
@@ -1668,30 +1748,37 @@ static int chcr_end_part_handler(struct chcr_ktls_info *tx_info,
                nskb = skb;
                atomic64_inc(&tx_info->adap->ch_ktls_stats.ktls_tx_complete_pkts);
        } else {
-               dev_kfree_skb_any(skb);
-
-               nskb = alloc_skb(0, GFP_KERNEL);
-               if (!nskb)
+               nskb = alloc_skb(0, GFP_ATOMIC);
+               if (!nskb) {
+                       dev_kfree_skb_any(skb);
                        return NETDEV_TX_BUSY;
+               }
+
                /* copy complete record in skb */
-               chcr_ktls_copy_record_in_skb(nskb, record);
+               chcr_ktls_copy_record_in_skb(nskb, skb, record);
                /* packet is being sent from the beginning, update the tcp_seq
                 * accordingly.
                 */
                tcp_seq = tls_record_start_seq(record);
-               /* reset snd una, so the middle record won't send the already
-                * sent part.
-                */
-               if (chcr_ktls_update_snd_una(tx_info, q))
-                       goto out;
+               /* reset skb offset */
+               skb_offset = 0;
+
+               if (last_wr)
+                       dev_kfree_skb_any(skb);
+
+               last_wr = true;
+
                atomic64_inc(&tx_info->adap->ch_ktls_stats.ktls_tx_end_pkts);
        }
 
        if (chcr_ktls_xmit_wr_complete(nskb, tx_info, q, tcp_seq,
+                                      last_wr, record->len, skb_offset,
+                                      record->num_frags,
                                       (last_wr && tcp_push_no_fin),
                                       mss)) {
                goto out;
        }
+       tx_info->prev_seq = record->end_seq;
        return 0;
 out:
        dev_kfree_skb_any(nskb);
@@ -1723,41 +1810,47 @@ static int chcr_short_record_handler(struct chcr_ktls_info *tx_info,
                                     struct sk_buff *skb,
                                     struct tls_record_info *record,
                                     u32 tcp_seq, int mss, bool tcp_push_no_fin,
+                                    u32 data_len, u32 skb_offset,
                                     struct sge_eth_txq *q, u32 tls_end_offset)
 {
        u32 tls_rec_offset = tcp_seq - tls_record_start_seq(record);
        u8 prior_data[16] = {0};
        u32 prior_data_len = 0;
-       u32 data_len;
 
        /* check if the skb is ending in middle of tag/HASH, its a big
         * trouble, send the packet before the HASH.
         */
-       int remaining_record = tls_end_offset - skb->data_len;
+       int remaining_record = tls_end_offset - data_len;
 
        if (remaining_record > 0 &&
            remaining_record < TLS_CIPHER_AES_GCM_128_TAG_SIZE) {
-               int trimmed_len = skb->data_len -
-                       (TLS_CIPHER_AES_GCM_128_TAG_SIZE - remaining_record);
-               struct sk_buff *tmp_skb = NULL;
-               /* don't process the pkt if it is only a partial tag */
-               if (skb->data_len < TLS_CIPHER_AES_GCM_128_TAG_SIZE)
-                       goto out;
+               int trimmed_len = 0;
 
-               WARN_ON(trimmed_len > skb->data_len);
+               if (tls_end_offset > TLS_CIPHER_AES_GCM_128_TAG_SIZE)
+                       trimmed_len = data_len -
+                                     (TLS_CIPHER_AES_GCM_128_TAG_SIZE -
+                                      remaining_record);
+               if (!trimmed_len)
+                       return FALLBACK;
 
-               /* shift to those many bytes */
-               tmp_skb = alloc_skb(0, GFP_KERNEL);
-               if (unlikely(!tmp_skb))
-                       goto out;
+               WARN_ON(trimmed_len > data_len);
 
-               chcr_ktls_skb_shift(tmp_skb, skb, trimmed_len);
-               /* free the last trimmed portion */
-               dev_kfree_skb_any(skb);
-               skb = tmp_skb;
+               data_len = trimmed_len;
                atomic64_inc(&tx_info->adap->ch_ktls_stats.ktls_tx_trimmed_pkts);
        }
-       data_len = skb->data_len;
+
+       /* check if it is only the header part. */
+       if (tls_rec_offset + data_len <= (TLS_HEADER_SIZE + tx_info->iv_size)) {
+               if (chcr_ktls_tx_plaintxt(tx_info, skb, tcp_seq, mss,
+                                         tcp_push_no_fin, q,
+                                         tx_info->port_id, prior_data,
+                                         data_len, skb_offset, prior_data_len))
+                       goto out;
+
+               tx_info->prev_seq = tcp_seq + data_len;
+               return 0;
+       }
+
        /* check if the middle record's start point is 16 byte aligned. CTR
         * needs 16 byte aligned start point to start encryption.
         */
@@ -1818,9 +1911,6 @@ static int chcr_short_record_handler(struct chcr_ktls_info *tx_info,
                        }
                        /* reset tcp_seq as per the prior_data_required len */
                        tcp_seq -= prior_data_len;
-                       /* include prio_data_len for  further calculation.
-                        */
-                       data_len += prior_data_len;
                }
                /* reset snd una, so the middle record won't send the already
                 * sent part.
@@ -1829,37 +1919,54 @@ static int chcr_short_record_handler(struct chcr_ktls_info *tx_info,
                        goto out;
                atomic64_inc(&tx_info->adap->ch_ktls_stats.ktls_tx_middle_pkts);
        } else {
-               /* Else means, its a partial first part of the record. Check if
-                * its only the header, don't need to send for encryption then.
-                */
-               if (data_len <= TLS_HEADER_SIZE + tx_info->iv_size) {
-                       if (chcr_ktls_tx_plaintxt(tx_info, skb, tcp_seq, mss,
-                                                 tcp_push_no_fin, q,
-                                                 tx_info->port_id,
-                                                 prior_data,
-                                                 prior_data_len)) {
-                               goto out;
-                       }
-                       return 0;
-               }
                atomic64_inc(&tx_info->adap->ch_ktls_stats.ktls_tx_start_pkts);
        }
 
        if (chcr_ktls_xmit_wr_short(skb, tx_info, q, tcp_seq, tcp_push_no_fin,
                                    mss, tls_rec_offset, prior_data,
-                                   prior_data_len)) {
+                                   prior_data_len, data_len, skb_offset)) {
                goto out;
        }
 
+       tx_info->prev_seq = tcp_seq + data_len + prior_data_len;
        return 0;
 out:
        dev_kfree_skb_any(skb);
        return NETDEV_TX_BUSY;
 }
 
+static int chcr_ktls_sw_fallback(struct sk_buff *skb,
+                                struct chcr_ktls_info *tx_info,
+                                struct sge_eth_txq *q)
+{
+       u32 data_len, skb_offset;
+       struct sk_buff *nskb;
+       struct tcphdr *th;
+
+       nskb = tls_encrypt_skb(skb);
+
+       if (!nskb)
+               return 0;
+
+       th = tcp_hdr(nskb);
+       skb_offset =  skb_transport_offset(nskb) + tcp_hdrlen(nskb);
+       data_len = nskb->len - skb_offset;
+       skb_tx_timestamp(nskb);
+
+       if (chcr_ktls_tunnel_pkt(tx_info, nskb, q))
+               goto out;
+
+       tx_info->prev_seq = ntohl(th->seq) + data_len;
+       atomic64_inc(&tx_info->adap->ch_ktls_stats.ktls_tx_fallback);
+       return 0;
+out:
+       dev_kfree_skb_any(nskb);
+       return 0;
+}
 /* nic tls TX handler */
 static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)
 {
+       u32 tls_end_offset, tcp_seq, skb_data_len, skb_offset;
        struct ch_ktls_port_stats_debug *port_stats;
        struct chcr_ktls_ofld_ctx_tx *tx_ctx;
        struct ch_ktls_stats_debug *stats;
@@ -1867,20 +1974,17 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)
        int data_len, qidx, ret = 0, mss;
        struct tls_record_info *record;
        struct chcr_ktls_info *tx_info;
-       u32 tls_end_offset, tcp_seq;
        struct tls_context *tls_ctx;
-       struct sk_buff *local_skb;
        struct sge_eth_txq *q;
        struct adapter *adap;
        unsigned long flags;
 
        tcp_seq = ntohl(th->seq);
+       skb_offset = skb_transport_offset(skb) + tcp_hdrlen(skb);
+       skb_data_len = skb->len - skb_offset;
+       data_len = skb_data_len;
 
-       mss = skb_is_gso(skb) ? skb_shinfo(skb)->gso_size : skb->data_len;
-
-       /* check if we haven't set it for ktls offload */
-       if (!skb->sk || !tls_is_sk_tx_device_offloaded(skb->sk))
-               goto out;
+       mss = skb_is_gso(skb) ? skb_shinfo(skb)->gso_size : data_len;
 
        tls_ctx = tls_get_ctx(skb->sk);
        if (unlikely(tls_ctx->netdev != dev))
@@ -1892,14 +1996,6 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)
        if (unlikely(!tx_info))
                goto out;
 
-       /* don't touch the original skb, make a new skb to extract each records
-        * and send them separately.
-        */
-       local_skb = alloc_skb(0, GFP_KERNEL);
-
-       if (unlikely(!local_skb))
-               return NETDEV_TX_BUSY;
-
        adap = tx_info->adap;
        stats = &adap->ch_ktls_stats;
        port_stats = &stats->ktls_port[tx_info->port_id];
@@ -1914,20 +2010,7 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)
                if (ret)
                        return NETDEV_TX_BUSY;
        }
-       /* update tcb */
-       ret = chcr_ktls_xmit_tcb_cpls(tx_info, q, ntohl(th->seq),
-                                     ntohl(th->ack_seq),
-                                     ntohs(th->window));
-       if (ret) {
-               dev_kfree_skb_any(local_skb);
-               return NETDEV_TX_BUSY;
-       }
 
-       /* copy skb contents into local skb */
-       chcr_ktls_skb_copy(skb, local_skb);
-
-       /* go through the skb and send only one record at a time. */
-       data_len = skb->data_len;
        /* TCP segments can be in received either complete or partial.
         * chcr_end_part_handler will handle cases if complete record or end
         * part of the record is received. Incase of partial end part of record,
@@ -1952,10 +2035,64 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)
                        goto out;
                }
 
+               tls_end_offset = record->end_seq - tcp_seq;
+
+               pr_debug("seq 0x%x, end_seq 0x%x prev_seq 0x%x, datalen 0x%x\n",
+                        tcp_seq, record->end_seq, tx_info->prev_seq, data_len);
+               /* update tcb for the skb */
+               if (skb_data_len == data_len) {
+                       u32 tx_max = tcp_seq;
+
+                       if (!tls_record_is_start_marker(record) &&
+                           tls_end_offset < TLS_CIPHER_AES_GCM_128_TAG_SIZE)
+                               tx_max = record->end_seq -
+                                       TLS_CIPHER_AES_GCM_128_TAG_SIZE;
+
+                       ret = chcr_ktls_xmit_tcb_cpls(tx_info, q, tx_max,
+                                                     ntohl(th->ack_seq),
+                                                     ntohs(th->window),
+                                                     tls_end_offset !=
+                                                     record->len);
+                       if (ret) {
+                               spin_unlock_irqrestore(&tx_ctx->base.lock,
+                                                      flags);
+                               goto out;
+                       }
+
+                       if (th->fin)
+                               skb_get(skb);
+               }
+
                if (unlikely(tls_record_is_start_marker(record))) {
-                       spin_unlock_irqrestore(&tx_ctx->base.lock, flags);
                        atomic64_inc(&port_stats->ktls_tx_skip_no_sync_data);
-                       goto out;
+                       /* If tls_end_offset < data_len, means there is some
+                        * data after start marker, which needs encryption, send
+                        * plaintext first and take skb refcount. else send out
+                        * complete pkt as plaintext.
+                        */
+                       if (tls_end_offset < data_len)
+                               skb_get(skb);
+                       else
+                               tls_end_offset = data_len;
+
+                       ret = chcr_ktls_tx_plaintxt(tx_info, skb, tcp_seq, mss,
+                                                   (!th->fin && th->psh), q,
+                                                   tx_info->port_id, NULL,
+                                                   tls_end_offset, skb_offset,
+                                                   0);
+
+                       spin_unlock_irqrestore(&tx_ctx->base.lock, flags);
+                       if (ret) {
+                               /* free the refcount taken earlier */
+                               if (tls_end_offset < data_len)
+                                       dev_kfree_skb_any(skb);
+                               goto out;
+                       }
+
+                       data_len -= tls_end_offset;
+                       tcp_seq = record->end_seq;
+                       skb_offset += tls_end_offset;
+                       continue;
                }
 
                /* increase page reference count of the record, so that there
@@ -1967,73 +2104,64 @@ static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)
                /* lock cleared */
                spin_unlock_irqrestore(&tx_ctx->base.lock, flags);
 
-               tls_end_offset = record->end_seq - tcp_seq;
 
-               pr_debug("seq 0x%x, end_seq 0x%x prev_seq 0x%x, datalen 0x%x\n",
-                        tcp_seq, record->end_seq, tx_info->prev_seq, data_len);
                /* if a tls record is finishing in this SKB */
                if (tls_end_offset <= data_len) {
-                       struct sk_buff *nskb = NULL;
-
-                       if (tls_end_offset < data_len) {
-                               nskb = alloc_skb(0, GFP_KERNEL);
-                               if (unlikely(!nskb)) {
-                                       ret = -ENOMEM;
-                                       goto clear_ref;
-                               }
-
-                               chcr_ktls_skb_shift(nskb, local_skb,
-                                                   tls_end_offset);
-                       } else {
-                               /* its the only record in this skb, directly
-                                * point it.
-                                */
-                               nskb = local_skb;
-                       }
-                       ret = chcr_end_part_handler(tx_info, nskb, record,
+                       ret = chcr_end_part_handler(tx_info, skb, record,
                                                    tcp_seq, mss,
                                                    (!th->fin && th->psh), q,
+                                                   skb_offset,
                                                    tls_end_offset,
-                                                   (nskb == local_skb));
-
-                       if (ret && nskb != local_skb)
-                               dev_kfree_skb_any(local_skb);
+                                                   skb_offset +
+                                                   tls_end_offset == skb->len);
 
                        data_len -= tls_end_offset;
                        /* tcp_seq increment is required to handle next record.
                         */
                        tcp_seq += tls_end_offset;
+                       skb_offset += tls_end_offset;
                } else {
-                       ret = chcr_short_record_handler(tx_info, local_skb,
+                       ret = chcr_short_record_handler(tx_info, skb,
                                                        record, tcp_seq, mss,
                                                        (!th->fin && th->psh),
+                                                       data_len, skb_offset,
                                                        q, tls_end_offset);
                        data_len = 0;
                }
-clear_ref:
+
                /* clear the frag ref count which increased locally before */
                for (i = 0; i < record->num_frags; i++) {
                        /* clear the frag ref count */
                        __skb_frag_unref(&record->frags[i]);
                }
                /* if any failure, come out from the loop. */
-               if (ret)
-                       goto out;
+               if (ret) {
+                       if (th->fin)
+                               dev_kfree_skb_any(skb);
+
+                       if (ret == FALLBACK)
+                               return chcr_ktls_sw_fallback(skb, tx_info, q);
+
+                       return NETDEV_TX_OK;
+               }
+
                /* length should never be less than 0 */
                WARN_ON(data_len < 0);
 
        } while (data_len > 0);
 
-       tx_info->prev_seq = ntohl(th->seq) + skb->data_len;
        atomic64_inc(&port_stats->ktls_tx_encrypted_packets);
-       atomic64_add(skb->data_len, &port_stats->ktls_tx_encrypted_bytes);
+       atomic64_add(skb_data_len, &port_stats->ktls_tx_encrypted_bytes);
 
        /* tcp finish is set, send a separate tcp msg including all the options
         * as well.
         */
-       if (th->fin)
+       if (th->fin) {
                chcr_ktls_write_tcp_options(tx_info, skb, q, tx_info->tx_chan);
+               dev_kfree_skb_any(skb);
+       }
 
+       return NETDEV_TX_OK;
 out:
        dev_kfree_skb_any(skb);
        return NETDEV_TX_OK;
index c1651b1..18b3b1f 100644 (file)
@@ -26,6 +26,7 @@
 
 #define CHCR_KTLS_WR_SIZE      (CHCR_PLAIN_TX_DATA_LEN +\
                                 sizeof(struct cpl_tx_sec_pdu))
+#define FALLBACK               35
 
 enum ch_ktls_open_state {
        CH_KTLS_OPEN_SUCCESS = 0,
index d581c4e..96d5616 100644 (file)
@@ -212,7 +212,7 @@ static struct sk_buff *alloc_ctrl_skb(struct sk_buff *skb, int len)
 {
        if (likely(skb && !skb_shared(skb) && !skb_cloned(skb))) {
                __skb_trim(skb, 0);
-               refcount_add(2, &skb->users);
+               refcount_inc(&skb->users);
        } else {
                skb = alloc_skb(len, GFP_KERNEL | __GFP_NOFAIL);
        }
index f1820ac..62c8290 100644 (file)
@@ -383,6 +383,9 @@ int chtls_setkey(struct chtls_sock *csk, u32 keylen,
        if (ret)
                goto out_notcb;
 
+       if (unlikely(csk_flag(sk, CSK_ABORT_SHUTDOWN)))
+               goto out_notcb;
+
        set_wr_txq(skb, CPL_PRIORITY_DATA, csk->tlshws.txqid);
        csk->wr_credits -= DIV_ROUND_UP(len, 16);
        csk->wr_unacked += DIV_ROUND_UP(len, 16);
index 00024dd..80fb1f5 100644 (file)
@@ -1907,6 +1907,8 @@ err_register_netdev:
        clk_disable_unprepare(priv->rclk);
        clk_disable_unprepare(priv->clk);
 err_ncsi_dev:
+       if (priv->ndev)
+               ncsi_unregister_dev(priv->ndev);
        ftgmac100_destroy_mdio(netdev);
 err_setup_mdio:
        iounmap(priv->base);
@@ -1926,6 +1928,8 @@ static int ftgmac100_remove(struct platform_device *pdev)
        netdev = platform_get_drvdata(pdev);
        priv = netdev_priv(netdev);
 
+       if (priv->ndev)
+               ncsi_unregister_dev(priv->ndev);
        unregister_netdev(netdev);
 
        clk_disable_unprepare(priv->rclk);
index 06cc863..d9c2859 100644 (file)
@@ -174,12 +174,17 @@ MODULE_PARM_DESC(tx_timeout, "The Tx timeout in ms");
 #define DPAA_PARSE_RESULTS_SIZE sizeof(struct fman_prs_result)
 #define DPAA_TIME_STAMP_SIZE 8
 #define DPAA_HASH_RESULTS_SIZE 8
+#define DPAA_HWA_SIZE (DPAA_PARSE_RESULTS_SIZE + DPAA_TIME_STAMP_SIZE \
+                      + DPAA_HASH_RESULTS_SIZE)
+#define DPAA_RX_PRIV_DATA_DEFAULT_SIZE (DPAA_TX_PRIV_DATA_SIZE + \
+                                       dpaa_rx_extra_headroom)
 #ifdef CONFIG_DPAA_ERRATUM_A050385
-#define DPAA_RX_PRIV_DATA_SIZE (DPAA_A050385_ALIGN - (DPAA_PARSE_RESULTS_SIZE\
-        + DPAA_TIME_STAMP_SIZE + DPAA_HASH_RESULTS_SIZE))
+#define DPAA_RX_PRIV_DATA_A050385_SIZE (DPAA_A050385_ALIGN - DPAA_HWA_SIZE)
+#define DPAA_RX_PRIV_DATA_SIZE (fman_has_errata_a050385() ? \
+                               DPAA_RX_PRIV_DATA_A050385_SIZE : \
+                               DPAA_RX_PRIV_DATA_DEFAULT_SIZE)
 #else
-#define DPAA_RX_PRIV_DATA_SIZE (u16)(DPAA_TX_PRIV_DATA_SIZE + \
-                                       dpaa_rx_extra_headroom)
+#define DPAA_RX_PRIV_DATA_SIZE DPAA_RX_PRIV_DATA_DEFAULT_SIZE
 #endif
 
 #define DPAA_ETH_PCD_RXQ_NUM   128
@@ -2840,7 +2845,8 @@ out_error:
        return err;
 }
 
-static inline u16 dpaa_get_headroom(struct dpaa_buffer_layout *bl)
+static u16 dpaa_get_headroom(struct dpaa_buffer_layout *bl,
+                            enum port_type port)
 {
        u16 headroom;
 
@@ -2854,10 +2860,12 @@ static inline u16 dpaa_get_headroom(struct dpaa_buffer_layout *bl)
         *
         * Also make sure the headroom is a multiple of data_align bytes
         */
-       headroom = (u16)(bl->priv_data_size + DPAA_PARSE_RESULTS_SIZE +
-               DPAA_TIME_STAMP_SIZE + DPAA_HASH_RESULTS_SIZE);
+       headroom = (u16)(bl[port].priv_data_size + DPAA_HWA_SIZE);
 
-       return ALIGN(headroom, DPAA_FD_DATA_ALIGNMENT);
+       if (port == RX)
+               return ALIGN(headroom, DPAA_FD_RX_DATA_ALIGNMENT);
+       else
+               return ALIGN(headroom, DPAA_FD_DATA_ALIGNMENT);
 }
 
 static int dpaa_eth_probe(struct platform_device *pdev)
@@ -3025,8 +3033,8 @@ static int dpaa_eth_probe(struct platform_device *pdev)
                        goto free_dpaa_fqs;
        }
 
-       priv->tx_headroom = dpaa_get_headroom(&priv->buf_layout[TX]);
-       priv->rx_headroom = dpaa_get_headroom(&priv->buf_layout[RX]);
+       priv->tx_headroom = dpaa_get_headroom(priv->buf_layout, TX);
+       priv->rx_headroom = dpaa_get_headroom(priv->buf_layout, RX);
 
        /* All real interfaces need their ports initialized */
        err = dpaa_eth_init_ports(mac_dev, dpaa_bp, &port_fqs,
index 0fa18b0..d99ea0f 100644 (file)
@@ -16,6 +16,7 @@ config FSL_ENETC
 config FSL_ENETC_VF
        tristate "ENETC VF driver"
        depends on PCI && PCI_MSI
+       select FSL_ENETC_MDIO
        select PHYLINK
        select DIMLIB
        help
index 52be6e3..fc2075e 100644 (file)
@@ -33,7 +33,10 @@ netdev_tx_t enetc_xmit(struct sk_buff *skb, struct net_device *ndev)
                return NETDEV_TX_BUSY;
        }
 
+       enetc_lock_mdio();
        count = enetc_map_tx_buffs(tx_ring, skb, priv->active_offloads);
+       enetc_unlock_mdio();
+
        if (unlikely(!count))
                goto drop_packet_err;
 
@@ -239,7 +242,7 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb,
        skb_tx_timestamp(skb);
 
        /* let H/W know BD ring has been updated */
-       enetc_wr_reg(tx_ring->tpir, i); /* includes wmb() */
+       enetc_wr_reg_hot(tx_ring->tpir, i); /* includes wmb() */
 
        return count;
 
@@ -262,12 +265,16 @@ static irqreturn_t enetc_msix(int irq, void *data)
        struct enetc_int_vector *v = data;
        int i;
 
+       enetc_lock_mdio();
+
        /* disable interrupts */
-       enetc_wr_reg(v->rbier, 0);
-       enetc_wr_reg(v->ricr1, v->rx_ictt);
+       enetc_wr_reg_hot(v->rbier, 0);
+       enetc_wr_reg_hot(v->ricr1, v->rx_ictt);
 
        for_each_set_bit(i, &v->tx_rings_map, ENETC_MAX_NUM_TXQS)
-               enetc_wr_reg(v->tbier_base + ENETC_BDR_OFF(i), 0);
+               enetc_wr_reg_hot(v->tbier_base + ENETC_BDR_OFF(i), 0);
+
+       enetc_unlock_mdio();
 
        napi_schedule(&v->napi);
 
@@ -334,19 +341,23 @@ static int enetc_poll(struct napi_struct *napi, int budget)
 
        v->rx_napi_work = false;
 
+       enetc_lock_mdio();
+
        /* enable interrupts */
-       enetc_wr_reg(v->rbier, ENETC_RBIER_RXTIE);
+       enetc_wr_reg_hot(v->rbier, ENETC_RBIER_RXTIE);
 
        for_each_set_bit(i, &v->tx_rings_map, ENETC_MAX_NUM_TXQS)
-               enetc_wr_reg(v->tbier_base + ENETC_BDR_OFF(i),
-                            ENETC_TBIER_TXTIE);
+               enetc_wr_reg_hot(v->tbier_base + ENETC_BDR_OFF(i),
+                                ENETC_TBIER_TXTIE);
+
+       enetc_unlock_mdio();
 
        return work_done;
 }
 
 static int enetc_bd_ready_count(struct enetc_bdr *tx_ring, int ci)
 {
-       int pi = enetc_rd_reg(tx_ring->tcir) & ENETC_TBCIR_IDX_MASK;
+       int pi = enetc_rd_reg_hot(tx_ring->tcir) & ENETC_TBCIR_IDX_MASK;
 
        return pi >= ci ? pi - ci : tx_ring->bd_count - ci + pi;
 }
@@ -386,7 +397,10 @@ static bool enetc_clean_tx_ring(struct enetc_bdr *tx_ring, int napi_budget)
 
        i = tx_ring->next_to_clean;
        tx_swbd = &tx_ring->tx_swbd[i];
+
+       enetc_lock_mdio();
        bds_to_clean = enetc_bd_ready_count(tx_ring, i);
+       enetc_unlock_mdio();
 
        do_tstamp = false;
 
@@ -429,16 +443,20 @@ static bool enetc_clean_tx_ring(struct enetc_bdr *tx_ring, int napi_budget)
                        tx_swbd = tx_ring->tx_swbd;
                }
 
+               enetc_lock_mdio();
+
                /* BD iteration loop end */
                if (is_eof) {
                        tx_frm_cnt++;
                        /* re-arm interrupt source */
-                       enetc_wr_reg(tx_ring->idr, BIT(tx_ring->index) |
-                                    BIT(16 + tx_ring->index));
+                       enetc_wr_reg_hot(tx_ring->idr, BIT(tx_ring->index) |
+                                        BIT(16 + tx_ring->index));
                }
 
                if (unlikely(!bds_to_clean))
                        bds_to_clean = enetc_bd_ready_count(tx_ring, i);
+
+               enetc_unlock_mdio();
        }
 
        tx_ring->next_to_clean = i;
@@ -515,8 +533,6 @@ static int enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt)
        if (likely(j)) {
                rx_ring->next_to_alloc = i; /* keep track from page reuse */
                rx_ring->next_to_use = i;
-               /* update ENETC's consumer index */
-               enetc_wr_reg(rx_ring->rcir, i);
        }
 
        return j;
@@ -534,8 +550,8 @@ static void enetc_get_rx_tstamp(struct net_device *ndev,
        u64 tstamp;
 
        if (le16_to_cpu(rxbd->r.flags) & ENETC_RXBD_FLAG_TSTMP) {
-               lo = enetc_rd(hw, ENETC_SICTR0);
-               hi = enetc_rd(hw, ENETC_SICTR1);
+               lo = enetc_rd_reg_hot(hw->reg + ENETC_SICTR0);
+               hi = enetc_rd_reg_hot(hw->reg + ENETC_SICTR1);
                rxbd = enetc_rxbd_ext(rxbd);
                tstamp_lo = le32_to_cpu(rxbd->ext.tstamp);
                if (lo <= tstamp_lo)
@@ -684,23 +700,31 @@ static int enetc_clean_rx_ring(struct enetc_bdr *rx_ring,
                u32 bd_status;
                u16 size;
 
+               enetc_lock_mdio();
+
                if (cleaned_cnt >= ENETC_RXBD_BUNDLE) {
                        int count = enetc_refill_rx_ring(rx_ring, cleaned_cnt);
 
+                       /* update ENETC's consumer index */
+                       enetc_wr_reg_hot(rx_ring->rcir, rx_ring->next_to_use);
                        cleaned_cnt -= count;
                }
 
                rxbd = enetc_rxbd(rx_ring, i);
                bd_status = le32_to_cpu(rxbd->r.lstatus);
-               if (!bd_status)
+               if (!bd_status) {
+                       enetc_unlock_mdio();
                        break;
+               }
 
-               enetc_wr_reg(rx_ring->idr, BIT(rx_ring->index));
+               enetc_wr_reg_hot(rx_ring->idr, BIT(rx_ring->index));
                dma_rmb(); /* for reading other rxbd fields */
                size = le16_to_cpu(rxbd->r.buf_len);
                skb = enetc_map_rx_buff_to_skb(rx_ring, i, size);
-               if (!skb)
+               if (!skb) {
+                       enetc_unlock_mdio();
                        break;
+               }
 
                enetc_get_offloads(rx_ring, rxbd, skb);
 
@@ -712,6 +736,7 @@ static int enetc_clean_rx_ring(struct enetc_bdr *rx_ring,
 
                if (unlikely(bd_status &
                             ENETC_RXBD_LSTATUS(ENETC_RXBD_ERR_MASK))) {
+                       enetc_unlock_mdio();
                        dev_kfree_skb(skb);
                        while (!(bd_status & ENETC_RXBD_LSTATUS_F)) {
                                dma_rmb();
@@ -751,6 +776,8 @@ static int enetc_clean_rx_ring(struct enetc_bdr *rx_ring,
 
                enetc_process_skb(rx_ring, skb);
 
+               enetc_unlock_mdio();
+
                napi_gro_receive(napi, skb);
 
                rx_frm_cnt++;
@@ -1225,6 +1252,7 @@ static void enetc_setup_rxbdr(struct enetc_hw *hw, struct enetc_bdr *rx_ring)
        rx_ring->idr = hw->reg + ENETC_SIRXIDR;
 
        enetc_refill_rx_ring(rx_ring, enetc_bd_unused(rx_ring));
+       enetc_wr(hw, ENETC_SIRXIDR, rx_ring->next_to_use);
 
        /* enable ring */
        enetc_rxbdr_wr(hw, idx, ENETC_RBMR, rbmr);
index 17cf7c9..eb6bbf1 100644 (file)
@@ -324,14 +324,100 @@ struct enetc_hw {
        void __iomem *global;
 };
 
-/* general register accessors */
-#define enetc_rd_reg(reg)      ioread32((reg))
-#define enetc_wr_reg(reg, val) iowrite32((val), (reg))
+/* ENETC register accessors */
+
+/* MDIO issue workaround (on LS1028A) -
+ * Due to a hardware issue, an access to MDIO registers
+ * that is concurrent with other ENETC register accesses
+ * may lead to the MDIO access being dropped or corrupted.
+ * To protect the MDIO accesses a readers-writers locking
+ * scheme is used, where the MDIO register accesses are
+ * protected by write locks to insure exclusivity, while
+ * the remaining ENETC registers are accessed under read
+ * locks since they only compete with MDIO accesses.
+ */
+extern rwlock_t enetc_mdio_lock;
+
+/* use this locking primitive only on the fast datapath to
+ * group together multiple non-MDIO register accesses to
+ * minimize the overhead of the lock
+ */
+static inline void enetc_lock_mdio(void)
+{
+       read_lock(&enetc_mdio_lock);
+}
+
+static inline void enetc_unlock_mdio(void)
+{
+       read_unlock(&enetc_mdio_lock);
+}
+
+/* use these accessors only on the fast datapath under
+ * the enetc_lock_mdio() locking primitive to minimize
+ * the overhead of the lock
+ */
+static inline u32 enetc_rd_reg_hot(void __iomem *reg)
+{
+       lockdep_assert_held(&enetc_mdio_lock);
+
+       return ioread32(reg);
+}
+
+static inline void enetc_wr_reg_hot(void __iomem *reg, u32 val)
+{
+       lockdep_assert_held(&enetc_mdio_lock);
+
+       iowrite32(val, reg);
+}
+
+/* internal helpers for the MDIO w/a */
+static inline u32 _enetc_rd_reg_wa(void __iomem *reg)
+{
+       u32 val;
+
+       enetc_lock_mdio();
+       val = ioread32(reg);
+       enetc_unlock_mdio();
+
+       return val;
+}
+
+static inline void _enetc_wr_reg_wa(void __iomem *reg, u32 val)
+{
+       enetc_lock_mdio();
+       iowrite32(val, reg);
+       enetc_unlock_mdio();
+}
+
+static inline u32 _enetc_rd_mdio_reg_wa(void __iomem *reg)
+{
+       unsigned long flags;
+       u32 val;
+
+       write_lock_irqsave(&enetc_mdio_lock, flags);
+       val = ioread32(reg);
+       write_unlock_irqrestore(&enetc_mdio_lock, flags);
+
+       return val;
+}
+
+static inline void _enetc_wr_mdio_reg_wa(void __iomem *reg, u32 val)
+{
+       unsigned long flags;
+
+       write_lock_irqsave(&enetc_mdio_lock, flags);
+       iowrite32(val, reg);
+       write_unlock_irqrestore(&enetc_mdio_lock, flags);
+}
+
 #ifdef ioread64
-#define enetc_rd_reg64(reg)    ioread64((reg))
+static inline u64 _enetc_rd_reg64(void __iomem *reg)
+{
+       return ioread64(reg);
+}
 #else
 /* using this to read out stats on 32b systems */
-static inline u64 enetc_rd_reg64(void __iomem *reg)
+static inline u64 _enetc_rd_reg64(void __iomem *reg)
 {
        u32 low, high, tmp;
 
@@ -345,12 +431,29 @@ static inline u64 enetc_rd_reg64(void __iomem *reg)
 }
 #endif
 
+static inline u64 _enetc_rd_reg64_wa(void __iomem *reg)
+{
+       u64 val;
+
+       enetc_lock_mdio();
+       val = _enetc_rd_reg64(reg);
+       enetc_unlock_mdio();
+
+       return val;
+}
+
+/* general register accessors */
+#define enetc_rd_reg(reg)              _enetc_rd_reg_wa((reg))
+#define enetc_wr_reg(reg, val)         _enetc_wr_reg_wa((reg), (val))
 #define enetc_rd(hw, off)              enetc_rd_reg((hw)->reg + (off))
 #define enetc_wr(hw, off, val)         enetc_wr_reg((hw)->reg + (off), val)
-#define enetc_rd64(hw, off)            enetc_rd_reg64((hw)->reg + (off))
+#define enetc_rd64(hw, off)            _enetc_rd_reg64_wa((hw)->reg + (off))
 /* port register accessors - PF only */
 #define enetc_port_rd(hw, off)         enetc_rd_reg((hw)->port + (off))
 #define enetc_port_wr(hw, off, val)    enetc_wr_reg((hw)->port + (off), val)
+#define enetc_port_rd_mdio(hw, off)    _enetc_rd_mdio_reg_wa((hw)->port + (off))
+#define enetc_port_wr_mdio(hw, off, val)       _enetc_wr_mdio_reg_wa(\
+                                                       (hw)->port + (off), val)
 /* global register accessors - PF only */
 #define enetc_global_rd(hw, off)       enetc_rd_reg((hw)->global + (off))
 #define enetc_global_wr(hw, off, val)  enetc_wr_reg((hw)->global + (off), val)
index 48c32a1..ee0116e 100644 (file)
 
 static inline u32 _enetc_mdio_rd(struct enetc_mdio_priv *mdio_priv, int off)
 {
-       return enetc_port_rd(mdio_priv->hw, mdio_priv->mdio_base + off);
+       return enetc_port_rd_mdio(mdio_priv->hw, mdio_priv->mdio_base + off);
 }
 
 static inline void _enetc_mdio_wr(struct enetc_mdio_priv *mdio_priv, int off,
                                  u32 val)
 {
-       enetc_port_wr(mdio_priv->hw, mdio_priv->mdio_base + off, val);
+       enetc_port_wr_mdio(mdio_priv->hw, mdio_priv->mdio_base + off, val);
 }
 
 #define enetc_mdio_rd(mdio_priv, off) \
@@ -174,3 +174,7 @@ struct enetc_hw *enetc_hw_alloc(struct device *dev, void __iomem *port_regs)
        return hw;
 }
 EXPORT_SYMBOL_GPL(enetc_hw_alloc);
+
+/* Lock for MDIO access errata on LS1028A */
+DEFINE_RWLOCK(enetc_mdio_lock);
+EXPORT_SYMBOL_GPL(enetc_mdio_lock);
index 832a217..c527f4e 100644 (file)
@@ -456,6 +456,12 @@ struct bufdesc_ex {
  */
 #define FEC_QUIRK_HAS_FRREG            (1 << 16)
 
+/* Some FEC hardware blocks need the MMFR cleared at setup time to avoid
+ * the generation of an MII event. This must be avoided in the older
+ * FEC blocks where it will stop MII events being generated.
+ */
+#define FEC_QUIRK_CLEAR_SETUP_MII      (1 << 17)
+
 struct bufdesc_prop {
        int qid;
        /* Address of Rx and Tx buffers */
index 8f7eca1..04f24c6 100644 (file)
@@ -100,14 +100,14 @@ static const struct fec_devinfo fec_imx27_info = {
 static const struct fec_devinfo fec_imx28_info = {
        .quirks = FEC_QUIRK_ENET_MAC | FEC_QUIRK_SWAP_FRAME |
                  FEC_QUIRK_SINGLE_MDIO | FEC_QUIRK_HAS_RACC |
-                 FEC_QUIRK_HAS_FRREG,
+                 FEC_QUIRK_HAS_FRREG | FEC_QUIRK_CLEAR_SETUP_MII,
 };
 
 static const struct fec_devinfo fec_imx6q_info = {
        .quirks = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT |
                  FEC_QUIRK_HAS_BUFDESC_EX | FEC_QUIRK_HAS_CSUM |
                  FEC_QUIRK_HAS_VLAN | FEC_QUIRK_ERR006358 |
-                 FEC_QUIRK_HAS_RACC,
+                 FEC_QUIRK_HAS_RACC | FEC_QUIRK_CLEAR_SETUP_MII,
 };
 
 static const struct fec_devinfo fec_mvf600_info = {
@@ -119,7 +119,8 @@ static const struct fec_devinfo fec_imx6x_info = {
                  FEC_QUIRK_HAS_BUFDESC_EX | FEC_QUIRK_HAS_CSUM |
                  FEC_QUIRK_HAS_VLAN | FEC_QUIRK_HAS_AVB |
                  FEC_QUIRK_ERR007885 | FEC_QUIRK_BUG_CAPTURE |
-                 FEC_QUIRK_HAS_RACC | FEC_QUIRK_HAS_COALESCE,
+                 FEC_QUIRK_HAS_RACC | FEC_QUIRK_HAS_COALESCE |
+                 FEC_QUIRK_CLEAR_SETUP_MII,
 };
 
 static const struct fec_devinfo fec_imx6ul_info = {
@@ -127,7 +128,7 @@ static const struct fec_devinfo fec_imx6ul_info = {
                  FEC_QUIRK_HAS_BUFDESC_EX | FEC_QUIRK_HAS_CSUM |
                  FEC_QUIRK_HAS_VLAN | FEC_QUIRK_ERR007885 |
                  FEC_QUIRK_BUG_CAPTURE | FEC_QUIRK_HAS_RACC |
-                 FEC_QUIRK_HAS_COALESCE,
+                 FEC_QUIRK_HAS_COALESCE | FEC_QUIRK_CLEAR_SETUP_MII,
 };
 
 static struct platform_device_id fec_devtype[] = {
@@ -1807,7 +1808,7 @@ static int fec_enet_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
        int ret = 0, frame_start, frame_addr, frame_op;
        bool is_c45 = !!(regnum & MII_ADDR_C45);
 
-       ret = pm_runtime_get_sync(dev);
+       ret = pm_runtime_resume_and_get(dev);
        if (ret < 0)
                return ret;
 
@@ -1866,11 +1867,9 @@ static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
        int ret, frame_start, frame_addr;
        bool is_c45 = !!(regnum & MII_ADDR_C45);
 
-       ret = pm_runtime_get_sync(dev);
+       ret = pm_runtime_resume_and_get(dev);
        if (ret < 0)
                return ret;
-       else
-               ret = 0;
 
        if (is_c45) {
                frame_start = FEC_MMFR_ST_C45;
@@ -2134,15 +2133,17 @@ static int fec_enet_mii_init(struct platform_device *pdev)
        if (suppress_preamble)
                fep->phy_speed |= BIT(7);
 
-       /* Clear MMFR to avoid to generate MII event by writing MSCR.
-        * MII event generation condition:
-        * - writing MSCR:
-        *      - mmfr[31:0]_not_zero & mscr[7:0]_is_zero &
-        *        mscr_reg_data_in[7:0] != 0
-        * - writing MMFR:
-        *      - mscr[7:0]_not_zero
-        */
-       writel(0, fep->hwp + FEC_MII_DATA);
+       if (fep->quirks & FEC_QUIRK_CLEAR_SETUP_MII) {
+               /* Clear MMFR to avoid to generate MII event by writing MSCR.
+                * MII event generation condition:
+                * - writing MSCR:
+                *      - mmfr[31:0]_not_zero & mscr[7:0]_is_zero &
+                *        mscr_reg_data_in[7:0] != 0
+                * - writing MMFR:
+                *      - mscr[7:0]_not_zero
+                */
+               writel(0, fep->hwp + FEC_MII_DATA);
+       }
 
        writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
 
@@ -2272,7 +2273,7 @@ static void fec_enet_get_regs(struct net_device *ndev,
        u32 i, off;
        int ret;
 
-       ret = pm_runtime_get_sync(dev);
+       ret = pm_runtime_resume_and_get(dev);
        if (ret < 0)
                return;
 
@@ -2973,7 +2974,7 @@ fec_enet_open(struct net_device *ndev)
        int ret;
        bool reset_again;
 
-       ret = pm_runtime_get_sync(&fep->pdev->dev);
+       ret = pm_runtime_resume_and_get(&fep->pdev->dev);
        if (ret < 0)
                return ret;
 
@@ -3767,7 +3768,7 @@ fec_drv_remove(struct platform_device *pdev)
        struct device_node *np = pdev->dev.of_node;
        int ret;
 
-       ret = pm_runtime_get_sync(&pdev->dev);
+       ret = pm_runtime_resume_and_get(&pdev->dev);
        if (ret < 0)
                return ret;
 
index 41dd3d0..d391a45 100644 (file)
@@ -1829,20 +1829,12 @@ static netdev_tx_t gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
                fcb_len = GMAC_FCB_LEN + GMAC_TXPAL_LEN;
 
        /* make space for additional header when fcb is needed */
-       if (fcb_len && unlikely(skb_headroom(skb) < fcb_len)) {
-               struct sk_buff *skb_new;
-
-               skb_new = skb_realloc_headroom(skb, fcb_len);
-               if (!skb_new) {
+       if (fcb_len) {
+               if (unlikely(skb_cow_head(skb, fcb_len))) {
                        dev->stats.tx_errors++;
                        dev_kfree_skb_any(skb);
                        return NETDEV_TX_OK;
                }
-
-               if (skb->sk)
-                       skb_set_owner_w(skb_new, skb->sk);
-               dev_consume_skb_any(skb);
-               skb = skb_new;
        }
 
        /* total number of fragments in the SKB */
@@ -3380,7 +3372,7 @@ static int gfar_probe(struct platform_device *ofdev)
 
        if (dev->features & NETIF_F_IP_CSUM ||
            priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER)
-               dev->needed_headroom = GMAC_FCB_LEN;
+               dev->needed_headroom = GMAC_FCB_LEN + GMAC_TXPAL_LEN;
 
        /* Initializing some of the rx/tx queue level parameters */
        for (i = 0; i < priv->num_tx_queues; i++) {
index af4dfbe..da15913 100644 (file)
@@ -1185,18 +1185,27 @@ static int ibmvnic_open(struct net_device *netdev)
        if (adapter->state != VNIC_CLOSED) {
                rc = ibmvnic_login(netdev);
                if (rc)
-                       return rc;
+                       goto out;
 
                rc = init_resources(adapter);
                if (rc) {
                        netdev_err(netdev, "failed to initialize resources\n");
                        release_resources(adapter);
-                       return rc;
+                       goto out;
                }
        }
 
        rc = __ibmvnic_open(netdev);
 
+out:
+       /*
+        * If open fails due to a pending failover, set device state and
+        * return. Device operation will be handled by reset routine.
+        */
+       if (rc && adapter->failover_pending) {
+               adapter->state = VNIC_OPEN;
+               rc = 0;
+       }
        return rc;
 }
 
@@ -1922,6 +1931,13 @@ static int do_reset(struct ibmvnic_adapter *adapter,
                   rwi->reset_reason);
 
        rtnl_lock();
+       /*
+        * Now that we have the rtnl lock, clear any pending failover.
+        * This will ensure ibmvnic_open() has either completed or will
+        * block until failover is complete.
+        */
+       if (rwi->reset_reason == VNIC_RESET_FAILOVER)
+               adapter->failover_pending = false;
 
        netif_carrier_off(netdev);
        adapter->reset_reason = rwi->reset_reason;
@@ -2202,6 +2218,13 @@ static void __ibmvnic_reset(struct work_struct *work)
                        /* CHANGE_PARAM requestor holds rtnl_lock */
                        rc = do_change_param_reset(adapter, rwi, reset_state);
                } else if (adapter->force_reset_recovery) {
+                       /*
+                        * Since we are doing a hard reset now, clear the
+                        * failover_pending flag so we don't ignore any
+                        * future MOBILITY or other resets.
+                        */
+                       adapter->failover_pending = false;
+
                        /* Transport event occurred during previous reset */
                        if (adapter->wait_for_reset) {
                                /* Previous was CHANGE_PARAM; caller locked */
@@ -2266,9 +2289,15 @@ static int ibmvnic_reset(struct ibmvnic_adapter *adapter,
        unsigned long flags;
        int ret;
 
+       /*
+        * If failover is pending don't schedule any other reset.
+        * Instead let the failover complete. If there is already a
+        * a failover reset scheduled, we will detect and drop the
+        * duplicate reset when walking the ->rwi_list below.
+        */
        if (adapter->state == VNIC_REMOVING ||
            adapter->state == VNIC_REMOVED ||
-           adapter->failover_pending) {
+           (adapter->failover_pending && reason != VNIC_RESET_FAILOVER)) {
                ret = EBUSY;
                netdev_dbg(netdev, "Adapter removing or pending failover, skipping reset\n");
                goto err;
@@ -4713,7 +4742,6 @@ static void ibmvnic_handle_crq(union ibmvnic_crq *crq,
                case IBMVNIC_CRQ_INIT:
                        dev_info(dev, "Partner initialized\n");
                        adapter->from_passive_init = true;
-                       adapter->failover_pending = false;
                        if (!completion_done(&adapter->init_done)) {
                                complete(&adapter->init_done);
                                adapter->init_done_rc = -EIO;
index c96e2f2..4919d22 100644 (file)
@@ -2713,6 +2713,10 @@ static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg)
                                spin_unlock_bh(&vsi->mac_filter_hash_lock);
                                goto error_param;
                        }
+                       if (is_valid_ether_addr(al->list[i].addr) &&
+                           is_zero_ether_addr(vf->default_lan_addr.addr))
+                               ether_addr_copy(vf->default_lan_addr.addr,
+                                               al->list[i].addr);
                }
        }
        spin_unlock_bh(&vsi->mac_filter_hash_lock);
@@ -2740,6 +2744,7 @@ static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg)
 {
        struct virtchnl_ether_addr_list *al =
            (struct virtchnl_ether_addr_list *)msg;
+       bool was_unimac_deleted = false;
        struct i40e_pf *pf = vf->pf;
        struct i40e_vsi *vsi = NULL;
        i40e_status ret = 0;
@@ -2759,6 +2764,8 @@ static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg)
                        ret = I40E_ERR_INVALID_MAC_ADDR;
                        goto error_param;
                }
+               if (ether_addr_equal(al->list[i].addr, vf->default_lan_addr.addr))
+                       was_unimac_deleted = true;
        }
        vsi = pf->vsi[vf->lan_vsi_idx];
 
@@ -2779,10 +2786,25 @@ static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg)
                dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
                        vf->vf_id, ret);
 
+       if (vf->trusted && was_unimac_deleted) {
+               struct i40e_mac_filter *f;
+               struct hlist_node *h;
+               u8 *macaddr = NULL;
+               int bkt;
+
+               /* set last unicast mac address as default */
+               spin_lock_bh(&vsi->mac_filter_hash_lock);
+               hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
+                       if (is_valid_ether_addr(f->macaddr))
+                               macaddr = f->macaddr;
+               }
+               if (macaddr)
+                       ether_addr_copy(vf->default_lan_addr.addr, macaddr);
+               spin_unlock_bh(&vsi->mac_filter_hash_lock);
+       }
 error_param:
        /* send the response to the VF */
-       return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DEL_ETH_ADDR,
-                                      ret);
+       return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DEL_ETH_ADDR, ret);
 }
 
 /**
index 6acede0..567fd67 100644 (file)
@@ -281,8 +281,8 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget)
        unsigned int total_rx_bytes = 0, total_rx_packets = 0;
        u16 cleaned_count = I40E_DESC_UNUSED(rx_ring);
        unsigned int xdp_res, xdp_xmit = 0;
+       bool failure = false;
        struct sk_buff *skb;
-       bool failure;
 
        while (likely(total_rx_packets < (unsigned int)budget)) {
                union i40e_rx_desc *rx_desc;
index 9112dff..b673ac1 100644 (file)
@@ -3891,21 +3891,23 @@ static int igc_change_mtu(struct net_device *netdev, int new_mtu)
 }
 
 /**
- * igc_get_stats - Get System Network Statistics
+ * igc_get_stats64 - Get System Network Statistics
  * @netdev: network interface device structure
+ * @stats: rtnl_link_stats64 pointer
  *
  * Returns the address of the device statistics structure.
  * The statistics are updated here and also from the timer callback.
  */
-static struct net_device_stats *igc_get_stats(struct net_device *netdev)
+static void igc_get_stats64(struct net_device *netdev,
+                           struct rtnl_link_stats64 *stats)
 {
        struct igc_adapter *adapter = netdev_priv(netdev);
 
+       spin_lock(&adapter->stats64_lock);
        if (!test_bit(__IGC_RESETTING, &adapter->state))
                igc_update_stats(adapter);
-
-       /* only return the current stats */
-       return &netdev->stats;
+       memcpy(stats, &adapter->stats64, sizeof(*stats));
+       spin_unlock(&adapter->stats64_lock);
 }
 
 static netdev_features_t igc_fix_features(struct net_device *netdev,
@@ -4855,7 +4857,7 @@ static const struct net_device_ops igc_netdev_ops = {
        .ndo_set_rx_mode        = igc_set_rx_mode,
        .ndo_set_mac_address    = igc_set_mac,
        .ndo_change_mtu         = igc_change_mtu,
-       .ndo_get_stats          = igc_get_stats,
+       .ndo_get_stats64        = igc_get_stats64,
        .ndo_fix_features       = igc_fix_features,
        .ndo_set_features       = igc_set_features,
        .ndo_features_check     = igc_features_check,
index 54b0bf5..4a9041e 100644 (file)
@@ -2287,6 +2287,7 @@ mvneta_swbm_add_rx_fragment(struct mvneta_port *pp,
        dma_sync_single_for_cpu(dev->dev.parent,
                                rx_desc->buf_phys_addr,
                                len, dma_dir);
+       rx_desc->buf_phys_addr = 0;
 
        if (data_len > 0 && sinfo->nr_frags < MAX_SKB_FRAGS) {
                skb_frag_t *frag = &sinfo->frags[sinfo->nr_frags];
@@ -2295,8 +2296,8 @@ mvneta_swbm_add_rx_fragment(struct mvneta_port *pp,
                skb_frag_size_set(frag, data_len);
                __skb_frag_set_page(frag, page);
                sinfo->nr_frags++;
-
-               rx_desc->buf_phys_addr = 0;
+       } else {
+               page_pool_put_full_page(rxq->page_pool, page, true);
        }
        *size -= len;
 }
index b1fcc44..b6f20e2 100644 (file)
@@ -6,6 +6,7 @@
 config PRESTERA
        tristate "Marvell Prestera Switch ASICs support"
        depends on NET_SWITCHDEV && VLAN_8021Q
+       depends on BRIDGE || BRIDGE=n
        select NET_DEVLINK
        help
          This driver supports Marvell Prestera Switch ASICs family.
index 1b97ada..be56776 100644 (file)
@@ -676,7 +676,8 @@ static int prestera_pci_probe(struct pci_dev *pdev,
        if (err)
                return err;
 
-       if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(30))) {
+       err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(30));
+       if (err) {
                dev_err(&pdev->dev, "fail to set DMA mask\n");
                goto err_dma_mask;
        }
@@ -702,8 +703,10 @@ static int prestera_pci_probe(struct pci_dev *pdev,
        dev_info(fw->dev.dev, "Prestera FW is ready\n");
 
        fw->wq = alloc_workqueue("prestera_fw_wq", WQ_HIGHPRI, 1);
-       if (!fw->wq)
+       if (!fw->wq) {
+               err = -ENOMEM;
                goto err_wq_alloc;
+       }
 
        INIT_WORK(&fw->evt_work, prestera_fw_evt_work_fn);
 
index 1325055..a8641a4 100644 (file)
@@ -966,6 +966,7 @@ static int mtk_star_enable(struct net_device *ndev)
                                      mtk_star_adjust_link, 0, priv->phy_intf);
        if (!priv->phydev) {
                netdev_err(ndev, "failed to connect to PHY\n");
+               ret = -ENODEV;
                goto err_free_irq;
        }
 
@@ -1053,7 +1054,7 @@ static int mtk_star_netdev_start_xmit(struct sk_buff *skb,
 err_drop_packet:
        dev_kfree_skb(skb);
        ndev->stats.tx_dropped++;
-       return NETDEV_TX_BUSY;
+       return NETDEV_TX_OK;
 }
 
 /* Returns the number of bytes sent or a negative number on the first
index f6ff962..f6cfec8 100644 (file)
@@ -1864,8 +1864,8 @@ int mlx4_INIT_HCA(struct mlx4_dev *dev, struct mlx4_init_hca_param *param)
 #define         INIT_HCA_LOG_RD_OFFSET          (INIT_HCA_QPC_OFFSET + 0x77)
 #define INIT_HCA_MCAST_OFFSET           0x0c0
 #define         INIT_HCA_MC_BASE_OFFSET         (INIT_HCA_MCAST_OFFSET + 0x00)
-#define         INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x12)
-#define         INIT_HCA_LOG_MC_HASH_SZ_OFFSET  (INIT_HCA_MCAST_OFFSET + 0x16)
+#define         INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x13)
+#define         INIT_HCA_LOG_MC_HASH_SZ_OFFSET  (INIT_HCA_MCAST_OFFSET + 0x17)
 #define  INIT_HCA_UC_STEERING_OFFSET    (INIT_HCA_MCAST_OFFSET + 0x18)
 #define         INIT_HCA_LOG_MC_TABLE_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x1b)
 #define  INIT_HCA_DEVICE_MANAGED_FLOW_STEERING_EN      0x6
@@ -1873,7 +1873,7 @@ int mlx4_INIT_HCA(struct mlx4_dev *dev, struct mlx4_init_hca_param *param)
 #define  INIT_HCA_DRIVER_VERSION_SZ       0x40
 #define  INIT_HCA_FS_PARAM_OFFSET         0x1d0
 #define  INIT_HCA_FS_BASE_OFFSET          (INIT_HCA_FS_PARAM_OFFSET + 0x00)
-#define  INIT_HCA_FS_LOG_ENTRY_SZ_OFFSET  (INIT_HCA_FS_PARAM_OFFSET + 0x12)
+#define  INIT_HCA_FS_LOG_ENTRY_SZ_OFFSET  (INIT_HCA_FS_PARAM_OFFSET + 0x13)
 #define  INIT_HCA_FS_A0_OFFSET           (INIT_HCA_FS_PARAM_OFFSET + 0x18)
 #define  INIT_HCA_FS_LOG_TABLE_SZ_OFFSET  (INIT_HCA_FS_PARAM_OFFSET + 0x1b)
 #define  INIT_HCA_FS_ETH_BITS_OFFSET      (INIT_HCA_FS_PARAM_OFFSET + 0x21)
index 650ae08..8f020f2 100644 (file)
@@ -182,8 +182,8 @@ struct mlx4_init_hca_param {
        u64 cmpt_base;
        u64 mtt_base;
        u64 global_caps;
-       u16 log_mc_entry_sz;
-       u16 log_mc_hash_sz;
+       u8 log_mc_entry_sz;
+       u8 log_mc_hash_sz;
        u16 hca_core_clock; /* Internal Clock Frequency (in MHz) */
        u8  log_num_qps;
        u8  log_num_srqs;
index 3e44e4d..95f2b26 100644 (file)
@@ -187,7 +187,7 @@ static bool mlx5e_rep_is_lag_netdev(struct net_device *netdev)
        struct mlx5e_priv *priv;
 
        /* A given netdev is not a representor or not a slave of LAG configuration */
-       if (!mlx5e_eswitch_rep(netdev) || !bond_slave_get_rtnl(netdev))
+       if (!mlx5e_eswitch_rep(netdev) || !netif_is_lag_port(netdev))
                return false;
 
        priv = netdev_priv(netdev);
index e36e505..d29af7b 100644 (file)
@@ -107,12 +107,16 @@ void mlx5e_rep_update_flows(struct mlx5e_priv *priv,
                mlx5e_tc_encap_flows_del(priv, e, &flow_list);
 
        if (neigh_connected && !(e->flags & MLX5_ENCAP_ENTRY_VALID)) {
+               struct net_device *route_dev;
+
                ether_addr_copy(e->h_dest, ha);
                ether_addr_copy(eth->h_dest, ha);
                /* Update the encap source mac, in case that we delete
                 * the flows when encap source mac changed.
                 */
-               ether_addr_copy(eth->h_source, e->route_dev->dev_addr);
+               route_dev = __dev_get_by_index(dev_net(priv->netdev), e->route_dev_ifindex);
+               if (route_dev)
+                       ether_addr_copy(eth->h_source, route_dev->dev_addr);
 
                mlx5e_tc_encap_flows_add(priv, e, &flow_list);
        }
index 7cce85f..90930e5 100644 (file)
@@ -77,13 +77,13 @@ static int get_route_and_out_devs(struct mlx5e_priv *priv,
        return 0;
 }
 
-static int mlx5e_route_lookup_ipv4(struct mlx5e_priv *priv,
-                                  struct net_device *mirred_dev,
-                                  struct net_device **out_dev,
-                                  struct net_device **route_dev,
-                                  struct flowi4 *fl4,
-                                  struct neighbour **out_n,
-                                  u8 *out_ttl)
+static int mlx5e_route_lookup_ipv4_get(struct mlx5e_priv *priv,
+                                      struct net_device *mirred_dev,
+                                      struct net_device **out_dev,
+                                      struct net_device **route_dev,
+                                      struct flowi4 *fl4,
+                                      struct neighbour **out_n,
+                                      u8 *out_ttl)
 {
        struct neighbour *n;
        struct rtable *rt;
@@ -117,18 +117,28 @@ static int mlx5e_route_lookup_ipv4(struct mlx5e_priv *priv,
                ip_rt_put(rt);
                return ret;
        }
+       dev_hold(*route_dev);
 
        if (!(*out_ttl))
                *out_ttl = ip4_dst_hoplimit(&rt->dst);
        n = dst_neigh_lookup(&rt->dst, &fl4->daddr);
        ip_rt_put(rt);
-       if (!n)
+       if (!n) {
+               dev_put(*route_dev);
                return -ENOMEM;
+       }
 
        *out_n = n;
        return 0;
 }
 
+static void mlx5e_route_lookup_ipv4_put(struct net_device *route_dev,
+                                       struct neighbour *n)
+{
+       neigh_release(n);
+       dev_put(route_dev);
+}
+
 static const char *mlx5e_netdev_kind(struct net_device *dev)
 {
        if (dev->rtnl_link_ops)
@@ -193,8 +203,8 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv,
        fl4.saddr = tun_key->u.ipv4.src;
        ttl = tun_key->ttl;
 
-       err = mlx5e_route_lookup_ipv4(priv, mirred_dev, &out_dev, &route_dev,
-                                     &fl4, &n, &ttl);
+       err = mlx5e_route_lookup_ipv4_get(priv, mirred_dev, &out_dev, &route_dev,
+                                         &fl4, &n, &ttl);
        if (err)
                return err;
 
@@ -223,7 +233,7 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv,
        e->m_neigh.family = n->ops->family;
        memcpy(&e->m_neigh.dst_ip, n->primary_key, n->tbl->key_len);
        e->out_dev = out_dev;
-       e->route_dev = route_dev;
+       e->route_dev_ifindex = route_dev->ifindex;
 
        /* It's important to add the neigh to the hash table before checking
         * the neigh validity state. So if we'll get a notification, in case the
@@ -278,7 +288,7 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv,
 
        e->flags |= MLX5_ENCAP_ENTRY_VALID;
        mlx5e_rep_queue_neigh_stats_work(netdev_priv(out_dev));
-       neigh_release(n);
+       mlx5e_route_lookup_ipv4_put(route_dev, n);
        return err;
 
 destroy_neigh_entry:
@@ -286,18 +296,18 @@ destroy_neigh_entry:
 free_encap:
        kfree(encap_header);
 release_neigh:
-       neigh_release(n);
+       mlx5e_route_lookup_ipv4_put(route_dev, n);
        return err;
 }
 
 #if IS_ENABLED(CONFIG_INET) && IS_ENABLED(CONFIG_IPV6)
-static int mlx5e_route_lookup_ipv6(struct mlx5e_priv *priv,
-                                  struct net_device *mirred_dev,
-                                  struct net_device **out_dev,
-                                  struct net_device **route_dev,
-                                  struct flowi6 *fl6,
-                                  struct neighbour **out_n,
-                                  u8 *out_ttl)
+static int mlx5e_route_lookup_ipv6_get(struct mlx5e_priv *priv,
+                                      struct net_device *mirred_dev,
+                                      struct net_device **out_dev,
+                                      struct net_device **route_dev,
+                                      struct flowi6 *fl6,
+                                      struct neighbour **out_n,
+                                      u8 *out_ttl)
 {
        struct dst_entry *dst;
        struct neighbour *n;
@@ -318,15 +328,25 @@ static int mlx5e_route_lookup_ipv6(struct mlx5e_priv *priv,
                return ret;
        }
 
+       dev_hold(*route_dev);
        n = dst_neigh_lookup(dst, &fl6->daddr);
        dst_release(dst);
-       if (!n)
+       if (!n) {
+               dev_put(*route_dev);
                return -ENOMEM;
+       }
 
        *out_n = n;
        return 0;
 }
 
+static void mlx5e_route_lookup_ipv6_put(struct net_device *route_dev,
+                                       struct neighbour *n)
+{
+       neigh_release(n);
+       dev_put(route_dev);
+}
+
 int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,
                                    struct net_device *mirred_dev,
                                    struct mlx5e_encap_entry *e)
@@ -348,8 +368,8 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,
        fl6.daddr = tun_key->u.ipv6.dst;
        fl6.saddr = tun_key->u.ipv6.src;
 
-       err = mlx5e_route_lookup_ipv6(priv, mirred_dev, &out_dev, &route_dev,
-                                     &fl6, &n, &ttl);
+       err = mlx5e_route_lookup_ipv6_get(priv, mirred_dev, &out_dev, &route_dev,
+                                         &fl6, &n, &ttl);
        if (err)
                return err;
 
@@ -378,7 +398,7 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,
        e->m_neigh.family = n->ops->family;
        memcpy(&e->m_neigh.dst_ip, n->primary_key, n->tbl->key_len);
        e->out_dev = out_dev;
-       e->route_dev = route_dev;
+       e->route_dev_ifindex = route_dev->ifindex;
 
        /* It's importent to add the neigh to the hash table before checking
         * the neigh validity state. So if we'll get a notification, in case the
@@ -433,7 +453,7 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,
 
        e->flags |= MLX5_ENCAP_ENTRY_VALID;
        mlx5e_rep_queue_neigh_stats_work(netdev_priv(out_dev));
-       neigh_release(n);
+       mlx5e_route_lookup_ipv6_put(route_dev, n);
        return err;
 
 destroy_neigh_entry:
@@ -441,7 +461,7 @@ destroy_neigh_entry:
 free_encap:
        kfree(encap_header);
 release_neigh:
-       neigh_release(n);
+       mlx5e_route_lookup_ipv6_put(route_dev, n);
        return err;
 }
 #endif
index 4e574ac..be3465b 100644 (file)
@@ -122,9 +122,9 @@ void mlx5e_activate_xsk(struct mlx5e_channel *c)
        set_bit(MLX5E_RQ_STATE_ENABLED, &c->xskrq.state);
        /* TX queue is created active. */
 
-       spin_lock(&c->async_icosq_lock);
+       spin_lock_bh(&c->async_icosq_lock);
        mlx5e_trigger_irq(&c->async_icosq);
-       spin_unlock(&c->async_icosq_lock);
+       spin_unlock_bh(&c->async_icosq_lock);
 }
 
 void mlx5e_deactivate_xsk(struct mlx5e_channel *c)
index fb671a4..8e96260 100644 (file)
@@ -36,9 +36,9 @@ int mlx5e_xsk_wakeup(struct net_device *dev, u32 qid, u32 flags)
                if (test_and_set_bit(MLX5E_SQ_STATE_PENDING_XSK_TX, &c->async_icosq.state))
                        return 0;
 
-               spin_lock(&c->async_icosq_lock);
+               spin_lock_bh(&c->async_icosq_lock);
                mlx5e_trigger_irq(&c->async_icosq);
-               spin_unlock(&c->async_icosq_lock);
+               spin_unlock_bh(&c->async_icosq_lock);
        }
 
        return 0;
index 0e45590..381a9c8 100644 (file)
@@ -64,13 +64,13 @@ static int rx_err_add_rule(struct mlx5e_priv *priv,
        if (!spec)
                return -ENOMEM;
 
-       /* Action to copy 7 bit ipsec_syndrome to regB[0:6] */
+       /* Action to copy 7 bit ipsec_syndrome to regB[24:30] */
        MLX5_SET(copy_action_in, action, action_type, MLX5_ACTION_TYPE_COPY);
        MLX5_SET(copy_action_in, action, src_field, MLX5_ACTION_IN_FIELD_IPSEC_SYNDROME);
        MLX5_SET(copy_action_in, action, src_offset, 0);
        MLX5_SET(copy_action_in, action, length, 7);
        MLX5_SET(copy_action_in, action, dst_field, MLX5_ACTION_IN_FIELD_METADATA_REG_B);
-       MLX5_SET(copy_action_in, action, dst_offset, 0);
+       MLX5_SET(copy_action_in, action, dst_offset, 24);
 
        modify_hdr = mlx5_modify_header_alloc(mdev, MLX5_FLOW_NAMESPACE_KERNEL,
                                              1, action);
@@ -488,13 +488,13 @@ static int rx_add_rule(struct mlx5e_priv *priv,
 
        setup_fte_common(attrs, ipsec_obj_id, spec, &flow_act);
 
-       /* Set 1  bit ipsec marker */
-       /* Set 24 bit ipsec_obj_id */
+       /* Set bit[31] ipsec marker */
+       /* Set bit[23-0] ipsec_obj_id */
        MLX5_SET(set_action_in, action, action_type, MLX5_ACTION_TYPE_SET);
        MLX5_SET(set_action_in, action, field, MLX5_ACTION_IN_FIELD_METADATA_REG_B);
-       MLX5_SET(set_action_in, action, data, (ipsec_obj_id << 1) | 0x1);
-       MLX5_SET(set_action_in, action, offset, 7);
-       MLX5_SET(set_action_in, action, length, 25);
+       MLX5_SET(set_action_in, action, data, (ipsec_obj_id | BIT(31)));
+       MLX5_SET(set_action_in, action, offset, 0);
+       MLX5_SET(set_action_in, action, length, 32);
 
        modify_hdr = mlx5_modify_header_alloc(priv->mdev, MLX5_FLOW_NAMESPACE_KERNEL,
                                              1, action);
index 11e31a3..a9b4560 100644 (file)
@@ -453,7 +453,6 @@ void mlx5e_ipsec_offload_handle_rx_skb(struct net_device *netdev,
                                       struct mlx5_cqe64 *cqe)
 {
        u32 ipsec_meta_data = be32_to_cpu(cqe->ft_metadata);
-       u8 ipsec_syndrome = ipsec_meta_data & 0xFF;
        struct mlx5e_priv *priv;
        struct xfrm_offload *xo;
        struct xfrm_state *xs;
@@ -481,7 +480,7 @@ void mlx5e_ipsec_offload_handle_rx_skb(struct net_device *netdev,
        xo = xfrm_offload(skb);
        xo->flags = CRYPTO_DONE;
 
-       switch (ipsec_syndrome & MLX5_IPSEC_METADATA_SYNDROM_MASK) {
+       switch (MLX5_IPSEC_METADATA_SYNDROM(ipsec_meta_data)) {
        case MLX5E_IPSEC_OFFLOAD_RX_SYNDROME_DECRYPTED:
                xo->status = CRYPTO_SUCCESS;
                if (WARN_ON_ONCE(priv->ipsec->no_trailer))
index 056dacb..9df9b9a 100644 (file)
 #include "en.h"
 #include "en/txrx.h"
 
-#define MLX5_IPSEC_METADATA_MARKER_MASK      (0x80)
-#define MLX5_IPSEC_METADATA_SYNDROM_MASK     (0x7F)
-#define MLX5_IPSEC_METADATA_HANDLE(metadata) (((metadata) >> 8) & 0xFF)
+/* Bit31: IPsec marker, Bit30-24: IPsec syndrome, Bit23-0: IPsec obj id */
+#define MLX5_IPSEC_METADATA_MARKER(metadata)  (((metadata) >> 31) & 0x1)
+#define MLX5_IPSEC_METADATA_SYNDROM(metadata) (((metadata) >> 24) & GENMASK(6, 0))
+#define MLX5_IPSEC_METADATA_HANDLE(metadata)  ((metadata) & GENMASK(23, 0))
 
 struct mlx5e_accel_tx_ipsec_state {
        struct xfrm_offload *xo;
@@ -78,7 +79,7 @@ static inline unsigned int mlx5e_ipsec_tx_ids_len(struct mlx5e_accel_tx_ipsec_st
 
 static inline bool mlx5_ipsec_is_rx_flow(struct mlx5_cqe64 *cqe)
 {
-       return !!(MLX5_IPSEC_METADATA_MARKER_MASK & be32_to_cpu(cqe->ft_metadata));
+       return MLX5_IPSEC_METADATA_MARKER(be32_to_cpu(cqe->ft_metadata));
 }
 
 static inline bool mlx5e_ipsec_is_tx_flow(struct mlx5e_accel_tx_ipsec_state *ipsec_st)
index ccaccb9..6a1d825 100644 (file)
@@ -188,7 +188,7 @@ static int post_rx_param_wqes(struct mlx5e_channel *c,
 
        err = 0;
        sq = &c->async_icosq;
-       spin_lock(&c->async_icosq_lock);
+       spin_lock_bh(&c->async_icosq_lock);
 
        cseg = post_static_params(sq, priv_rx);
        if (IS_ERR(cseg))
@@ -199,7 +199,7 @@ static int post_rx_param_wqes(struct mlx5e_channel *c,
 
        mlx5e_notify_hw(&sq->wq, sq->pc, sq->uar_map, cseg);
 unlock:
-       spin_unlock(&c->async_icosq_lock);
+       spin_unlock_bh(&c->async_icosq_lock);
 
        return err;
 
@@ -265,10 +265,10 @@ resync_post_get_progress_params(struct mlx5e_icosq *sq,
 
        BUILD_BUG_ON(MLX5E_KTLS_GET_PROGRESS_WQEBBS != 1);
 
-       spin_lock(&sq->channel->async_icosq_lock);
+       spin_lock_bh(&sq->channel->async_icosq_lock);
 
        if (unlikely(!mlx5e_wqc_has_room_for(&sq->wq, sq->cc, sq->pc, 1))) {
-               spin_unlock(&sq->channel->async_icosq_lock);
+               spin_unlock_bh(&sq->channel->async_icosq_lock);
                err = -ENOSPC;
                goto err_dma_unmap;
        }
@@ -299,7 +299,7 @@ resync_post_get_progress_params(struct mlx5e_icosq *sq,
        icosq_fill_wi(sq, pi, &wi);
        sq->pc++;
        mlx5e_notify_hw(&sq->wq, sq->pc, sq->uar_map, cseg);
-       spin_unlock(&sq->channel->async_icosq_lock);
+       spin_unlock_bh(&sq->channel->async_icosq_lock);
 
        return 0;
 
@@ -360,7 +360,7 @@ static int resync_handle_seq_match(struct mlx5e_ktls_offload_context_rx *priv_rx
        err = 0;
 
        sq = &c->async_icosq;
-       spin_lock(&c->async_icosq_lock);
+       spin_lock_bh(&c->async_icosq_lock);
 
        cseg = post_static_params(sq, priv_rx);
        if (IS_ERR(cseg)) {
@@ -372,7 +372,7 @@ static int resync_handle_seq_match(struct mlx5e_ktls_offload_context_rx *priv_rx
        mlx5e_notify_hw(&sq->wq, sq->pc, sq->uar_map, cseg);
        priv_rx->stats->tls_resync_res_ok++;
 unlock:
-       spin_unlock(&c->async_icosq_lock);
+       spin_unlock_bh(&c->async_icosq_lock);
 
        return err;
 }
@@ -476,19 +476,22 @@ static void resync_update_sn(struct mlx5e_rq *rq, struct sk_buff *skb)
 
        depth += sizeof(struct tcphdr);
 
-       if (unlikely(!sk || sk->sk_state == TCP_TIME_WAIT))
+       if (unlikely(!sk))
                return;
 
-       if (unlikely(!resync_queue_get_psv(sk)))
-               return;
+       if (unlikely(sk->sk_state == TCP_TIME_WAIT))
+               goto unref;
 
-       skb->sk = sk;
-       skb->destructor = sock_edemux;
+       if (unlikely(!resync_queue_get_psv(sk)))
+               goto unref;
 
        seq = th->seq;
        datalen = skb->len - depth;
        tls_offload_rx_resync_async_request_start(sk, seq, datalen);
        rq->stats->tls_resync_req_start++;
+
+unref:
+       sock_gen_put(sk);
 }
 
 void mlx5e_ktls_rx_resync(struct net_device *netdev, struct sock *sk,
index b3f02aa..ebce979 100644 (file)
@@ -5253,6 +5253,7 @@ static void mlx5e_nic_disable(struct mlx5e_priv *priv)
 
        mlx5e_disable_async_events(priv);
        mlx5_lag_remove(mdev);
+       mlx5_vxlan_reset_to_default(mdev->vxlan);
 }
 
 int mlx5e_update_nic_rx(struct mlx5e_priv *priv)
index 9020d14..8932c38 100644 (file)
@@ -186,7 +186,7 @@ struct mlx5e_encap_entry {
        unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
 
        struct net_device *out_dev;
-       struct net_device *route_dev;
+       int route_dev_ifindex;
        struct mlx5e_tc_tunnel *tunnel;
        int reformat_type;
        u8 flags;
index 599f5b5..6628a01 100644 (file)
@@ -1584,7 +1584,7 @@ int mlx5e_poll_rx_cq(struct mlx5e_cq *cq, int budget)
        } while ((++work_done < budget) && (cqe = mlx5_cqwq_get_cqe(cqwq)));
 
 out:
-       if (rq->xdp_prog)
+       if (rcu_access_pointer(rq->xdp_prog))
                mlx5e_xdp_rx_poll_complete(rq);
 
        mlx5_cqwq_update_db_record(cqwq);
index e3a968e..ce710f2 100644 (file)
@@ -4658,6 +4658,7 @@ __mlx5e_add_fdb_flow(struct mlx5e_priv *priv,
        return flow;
 
 err_free:
+       dealloc_mod_hdr_actions(&parse_attr->mod_hdr_acts);
        mlx5e_flow_put(priv, flow);
 out:
        return ERR_PTR(err);
@@ -4802,6 +4803,7 @@ mlx5e_add_nic_flow(struct mlx5e_priv *priv,
        return 0;
 
 err_free:
+       dealloc_mod_hdr_actions(&parse_attr->mod_hdr_acts);
        mlx5e_flow_put(priv, flow);
 out:
        return err;
@@ -5227,8 +5229,10 @@ int mlx5e_tc_nic_init(struct mlx5e_priv *priv)
 
        tc->ct = mlx5_tc_ct_init(priv, tc->chains, &priv->fs.tc.mod_hdr,
                                 MLX5_FLOW_NAMESPACE_KERNEL);
-       if (IS_ERR(tc->ct))
+       if (IS_ERR(tc->ct)) {
+               err = PTR_ERR(tc->ct);
                goto err_ct;
+       }
 
        tc->netdevice_nb.notifier_call = mlx5e_tc_netdev_event;
        err = register_netdevice_notifier_dev_net(priv->netdev,
index 3b97900..4a2ce24 100644 (file)
@@ -283,6 +283,9 @@ static inline bool mlx5e_cqe_regb_chain(struct mlx5_cqe64 *cqe)
 
        reg_b = be32_to_cpu(cqe->ft_metadata);
 
+       if (reg_b >> (MLX5E_TC_TABLE_CHAIN_TAG_BITS + ZONE_RESTORE_BITS))
+               return false;
+
        chain = reg_b & MLX5E_TC_TABLE_CHAIN_TAG_MASK;
        if (chain)
                return true;
index 82b4419..6dd3ea3 100644 (file)
@@ -144,7 +144,9 @@ static inline void mlx5e_insert_vlan(void *start, struct sk_buff *skb, u16 ihs)
        memcpy(&vhdr->h_vlan_encapsulated_proto, skb->data + cpy1_sz, cpy2_sz);
 }
 
-/* RM 2311217: no L4 inner checksum for IPsec tunnel type packet */
+/* If packet is not IP's CHECKSUM_PARTIAL (e.g. icmd packet),
+ * need to set L3 checksum flag for IPsec
+ */
 static void
 ipsec_txwqe_build_eseg_csum(struct mlx5e_txqsq *sq, struct sk_buff *skb,
                            struct mlx5_wqe_eth_seg *eseg)
@@ -154,7 +156,6 @@ ipsec_txwqe_build_eseg_csum(struct mlx5e_txqsq *sq, struct sk_buff *skb,
                eseg->cs_flags |= MLX5_ETH_WQE_L3_INNER_CSUM;
                sq->stats->csum_partial_inner++;
        } else {
-               eseg->cs_flags |= MLX5_ETH_WQE_L4_CSUM;
                sq->stats->csum_partial++;
        }
 }
@@ -162,11 +163,6 @@ ipsec_txwqe_build_eseg_csum(struct mlx5e_txqsq *sq, struct sk_buff *skb,
 static inline void
 mlx5e_txwqe_build_eseg_csum(struct mlx5e_txqsq *sq, struct sk_buff *skb, struct mlx5_wqe_eth_seg *eseg)
 {
-       if (unlikely(eseg->flow_table_metadata & cpu_to_be32(MLX5_ETH_WQE_FT_META_IPSEC))) {
-               ipsec_txwqe_build_eseg_csum(sq, skb, eseg);
-               return;
-       }
-
        if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
                eseg->cs_flags = MLX5_ETH_WQE_L3_CSUM;
                if (skb->encapsulation) {
@@ -177,6 +173,9 @@ mlx5e_txwqe_build_eseg_csum(struct mlx5e_txqsq *sq, struct sk_buff *skb, struct
                        eseg->cs_flags |= MLX5_ETH_WQE_L4_CSUM;
                        sq->stats->csum_partial++;
                }
+       } else if (unlikely(eseg->flow_table_metadata & cpu_to_be32(MLX5_ETH_WQE_FT_META_IPSEC))) {
+               ipsec_txwqe_build_eseg_csum(sq, skb, eseg);
+
        } else
                sq->stats->csum_none++;
 }
index 6e6a9a5..d4ee0a9 100644 (file)
@@ -1142,6 +1142,10 @@ int mlx5_esw_modify_vport_rate(struct mlx5_eswitch *esw, u16 vport_num,
        struct mlx5_vport *vport;
 
        vport = mlx5_eswitch_get_vport(esw, vport_num);
+
+       if (!vport->qos.enabled)
+               return -EOPNOTSUPP;
+
        MLX5_SET(scheduling_context, ctx, max_average_bw, rate_mbps);
 
        return mlx5_modify_scheduling_element_cmd(esw->dev,
@@ -1408,6 +1412,7 @@ static void mlx5_eswitch_clear_vf_vports_info(struct mlx5_eswitch *esw)
        int i;
 
        mlx5_esw_for_each_vf_vport(esw, i, vport, esw->esw_funcs.num_vfs) {
+               memset(&vport->qos, 0, sizeof(vport->qos));
                memset(&vport->info, 0, sizeof(vport->info));
                vport->info.link_state = MLX5_VPORT_ADMIN_STATE_AUTO;
        }
@@ -1902,8 +1907,6 @@ int mlx5_devlink_port_function_hw_addr_get(struct devlink *devlink,
                ether_addr_copy(hw_addr, vport->info.mac);
                *hw_addr_len = ETH_ALEN;
                err = 0;
-       } else {
-               NL_SET_ERR_MSG_MOD(extack, "Eswitch vport is disabled");
        }
        mutex_unlock(&esw->state_lock);
        return err;
@@ -2223,12 +2226,15 @@ static u32 calculate_vports_min_rate_divider(struct mlx5_eswitch *esw)
                max_guarantee = evport->info.min_rate;
        }
 
-       return max_t(u32, max_guarantee / fw_max_bw_share, 1);
+       if (max_guarantee)
+               return max_t(u32, max_guarantee / fw_max_bw_share, 1);
+       return 0;
 }
 
-static int normalize_vports_min_rate(struct mlx5_eswitch *esw, u32 divider)
+static int normalize_vports_min_rate(struct mlx5_eswitch *esw)
 {
        u32 fw_max_bw_share = MLX5_CAP_QOS(esw->dev, max_tsar_bw_share);
+       u32 divider = calculate_vports_min_rate_divider(esw);
        struct mlx5_vport *evport;
        u32 vport_max_rate;
        u32 vport_min_rate;
@@ -2241,9 +2247,9 @@ static int normalize_vports_min_rate(struct mlx5_eswitch *esw, u32 divider)
                        continue;
                vport_min_rate = evport->info.min_rate;
                vport_max_rate = evport->info.max_rate;
-               bw_share = MLX5_MIN_BW_SHARE;
+               bw_share = 0;
 
-               if (vport_min_rate)
+               if (divider)
                        bw_share = MLX5_RATE_TO_BW_SHARE(vport_min_rate,
                                                         divider,
                                                         fw_max_bw_share);
@@ -2268,7 +2274,6 @@ int mlx5_eswitch_set_vport_rate(struct mlx5_eswitch *esw, u16 vport,
        struct mlx5_vport *evport = mlx5_eswitch_get_vport(esw, vport);
        u32 fw_max_bw_share;
        u32 previous_min_rate;
-       u32 divider;
        bool min_rate_supported;
        bool max_rate_supported;
        int err = 0;
@@ -2293,8 +2298,7 @@ int mlx5_eswitch_set_vport_rate(struct mlx5_eswitch *esw, u16 vport,
 
        previous_min_rate = evport->info.min_rate;
        evport->info.min_rate = min_rate;
-       divider = calculate_vports_min_rate_divider(esw);
-       err = normalize_vports_min_rate(esw, divider);
+       err = normalize_vports_min_rate(esw);
        if (err) {
                evport->info.min_rate = previous_min_rate;
                goto unlock;
index 1609183..9fdd992 100644 (file)
@@ -534,6 +534,13 @@ static void del_sw_hw_rule(struct fs_node *node)
                goto out;
        }
 
+       if (rule->dest_attr.type == MLX5_FLOW_DESTINATION_TYPE_PORT &&
+           --fte->dests_size) {
+               fte->modify_mask |= BIT(MLX5_SET_FTE_MODIFY_ENABLE_MASK_ACTION);
+               fte->action.action &= ~MLX5_FLOW_CONTEXT_ACTION_ALLOW;
+               goto out;
+       }
+
        if ((fte->action.action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) &&
            --fte->dests_size) {
                fte->modify_mask |=
@@ -2010,10 +2017,11 @@ void mlx5_del_flow_rules(struct mlx5_flow_handle *handle)
        down_write_ref_node(&fte->node, false);
        for (i = handle->num_rules - 1; i >= 0; i--)
                tree_remove_node(&handle->rule[i]->node, true);
-       if (fte->modify_mask && fte->dests_size) {
-               modify_fte(fte);
+       if (fte->dests_size) {
+               if (fte->modify_mask)
+                       modify_fte(fte);
                up_write_ref_node(&fte->node, false);
-       } else {
+       } else if (list_empty(&fte->node.children)) {
                del_hw_fte(&fte->node);
                /* Avoid double call to del_hw_fte */
                fte->node.del_hw_func = NULL;
index 3315afe..3808440 100644 (file)
@@ -167,6 +167,17 @@ struct mlx5_vxlan *mlx5_vxlan_create(struct mlx5_core_dev *mdev)
 }
 
 void mlx5_vxlan_destroy(struct mlx5_vxlan *vxlan)
+{
+       if (!mlx5_vxlan_allowed(vxlan))
+               return;
+
+       mlx5_vxlan_del_port(vxlan, IANA_VXLAN_UDP_PORT);
+       WARN_ON(!hash_empty(vxlan->htable));
+
+       kfree(vxlan);
+}
+
+void mlx5_vxlan_reset_to_default(struct mlx5_vxlan *vxlan)
 {
        struct mlx5_vxlan_port *vxlanp;
        struct hlist_node *tmp;
@@ -175,12 +186,12 @@ void mlx5_vxlan_destroy(struct mlx5_vxlan *vxlan)
        if (!mlx5_vxlan_allowed(vxlan))
                return;
 
-       /* Lockless since we are the only hash table consumers*/
        hash_for_each_safe(vxlan->htable, bkt, tmp, vxlanp, hlist) {
-               hash_del(&vxlanp->hlist);
-               mlx5_vxlan_core_del_port_cmd(vxlan->mdev, vxlanp->udp_port);
-               kfree(vxlanp);
+               /* Don't delete default UDP port added by the HW.
+                * Remove only user configured ports
+                */
+               if (vxlanp->udp_port == IANA_VXLAN_UDP_PORT)
+                       continue;
+               mlx5_vxlan_del_port(vxlan, vxlanp->udp_port);
        }
-
-       kfree(vxlan);
 }
index ec76652..34ef662 100644 (file)
@@ -56,6 +56,7 @@ void mlx5_vxlan_destroy(struct mlx5_vxlan *vxlan);
 int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port);
 int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port);
 bool mlx5_vxlan_lookup_port(struct mlx5_vxlan *vxlan, u16 port);
+void mlx5_vxlan_reset_to_default(struct mlx5_vxlan *vxlan);
 #else
 static inline struct mlx5_vxlan*
 mlx5_vxlan_create(struct mlx5_core_dev *mdev) { return ERR_PTR(-EOPNOTSUPP); }
@@ -63,6 +64,7 @@ static inline void mlx5_vxlan_destroy(struct mlx5_vxlan *vxlan) { return; }
 static inline int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port) { return -EOPNOTSUPP; }
 static inline int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port) { return -EOPNOTSUPP; }
 static inline bool mlx5_vxlan_lookup_port(struct mlx5_vxlan *vxlan, u16 port) { return false; }
+static inline void mlx5_vxlan_reset_to_default(struct mlx5_vxlan *vxlan) { return; }
 #endif
 
 #endif /* __MLX5_VXLAN_H__ */
index 872e991..a619d90 100644 (file)
@@ -6,6 +6,7 @@
 config MLXSW_CORE
        tristate "Mellanox Technologies Switch ASICs support"
        select NET_DEVLINK
+       select MLXFW
        help
          This driver supports Mellanox Technologies Switch ASICs family.
 
@@ -82,7 +83,6 @@ config MLXSW_SPECTRUM
        select GENERIC_ALLOCATOR
        select PARMAN
        select OBJAGG
-       select MLXFW
        imply PTP_1588_CLOCK
        select NET_PTP_CLASSIFY if PTP_1588_CLOCK
        default m
index 937b8e4..1a86535 100644 (file)
@@ -571,7 +571,8 @@ static void mlxsw_emad_trans_timeout_schedule(struct mlxsw_reg_trans *trans)
        if (trans->core->fw_flash_in_progress)
                timeout = msecs_to_jiffies(MLXSW_EMAD_TIMEOUT_DURING_FW_FLASH_MS);
 
-       queue_delayed_work(trans->core->emad_wq, &trans->timeout_dw, timeout);
+       queue_delayed_work(trans->core->emad_wq, &trans->timeout_dw,
+                          timeout << trans->retries);
 }
 
 static int mlxsw_emad_transmit(struct mlxsw_core *mlxsw_core,
index a193884..b319c22 100644 (file)
@@ -148,7 +148,8 @@ static void lan743x_intr_software_isr(void *context)
 
        int_sts = lan743x_csr_read(adapter, INT_STS);
        if (int_sts & INT_BIT_SW_GP_) {
-               lan743x_csr_write(adapter, INT_STS, INT_BIT_SW_GP_);
+               /* disable the interrupt to prevent repeated re-triggering */
+               lan743x_csr_write(adapter, INT_EN_CLR, INT_BIT_SW_GP_);
                intr->software_isr_flag = 1;
        }
 }
@@ -674,14 +675,12 @@ clean_up:
 static int lan743x_dp_write(struct lan743x_adapter *adapter,
                            u32 select, u32 addr, u32 length, u32 *buf)
 {
-       int ret = -EIO;
        u32 dp_sel;
        int i;
 
-       mutex_lock(&adapter->dp_lock);
        if (lan743x_csr_wait_for_bit(adapter, DP_SEL, DP_SEL_DPRDY_,
                                     1, 40, 100, 100))
-               goto unlock;
+               return -EIO;
        dp_sel = lan743x_csr_read(adapter, DP_SEL);
        dp_sel &= ~DP_SEL_MASK_;
        dp_sel |= select;
@@ -693,13 +692,10 @@ static int lan743x_dp_write(struct lan743x_adapter *adapter,
                lan743x_csr_write(adapter, DP_CMD, DP_CMD_WRITE_);
                if (lan743x_csr_wait_for_bit(adapter, DP_SEL, DP_SEL_DPRDY_,
                                             1, 40, 100, 100))
-                       goto unlock;
+                       return -EIO;
        }
-       ret = 0;
 
-unlock:
-       mutex_unlock(&adapter->dp_lock);
-       return ret;
+       return 0;
 }
 
 static u32 lan743x_mac_mii_access(u16 id, u16 index, int read)
@@ -1019,16 +1015,16 @@ static void lan743x_phy_close(struct lan743x_adapter *adapter)
 static int lan743x_phy_open(struct lan743x_adapter *adapter)
 {
        struct lan743x_phy *phy = &adapter->phy;
+       struct phy_device *phydev = NULL;
        struct device_node *phynode;
-       struct phy_device *phydev;
        struct net_device *netdev;
        int ret = -EIO;
 
        netdev = adapter->netdev;
        phynode = of_node_get(adapter->pdev->dev.of_node);
-       adapter->phy_mode = PHY_INTERFACE_MODE_GMII;
 
        if (phynode) {
+               /* try devicetree phy, or fixed link */
                of_get_phy_mode(phynode, &adapter->phy_mode);
 
                if (of_phy_is_fixed_link(phynode)) {
@@ -1044,13 +1040,15 @@ static int lan743x_phy_open(struct lan743x_adapter *adapter)
                                        lan743x_phy_link_status_change, 0,
                                        adapter->phy_mode);
                of_node_put(phynode);
-               if (!phydev)
-                       goto return_error;
-       } else {
+       }
+
+       if (!phydev) {
+               /* try internal phy */
                phydev = phy_find_first(adapter->mdiobus);
                if (!phydev)
                        goto return_error;
 
+               adapter->phy_mode = PHY_INTERFACE_MODE_GMII;
                ret = phy_connect_direct(netdev, phydev,
                                         lan743x_phy_link_status_change,
                                         adapter->phy_mode);
@@ -1310,13 +1308,13 @@ clean_up_data_descriptor:
                goto clear_active;
 
        if (!(buffer_info->flags & TX_BUFFER_INFO_FLAG_TIMESTAMP_REQUESTED)) {
-               dev_kfree_skb(buffer_info->skb);
+               dev_kfree_skb_any(buffer_info->skb);
                goto clear_skb;
        }
 
        if (cleanup) {
                lan743x_ptp_unrequest_tx_timestamp(tx->adapter);
-               dev_kfree_skb(buffer_info->skb);
+               dev_kfree_skb_any(buffer_info->skb);
        } else {
                ignore_sync = (buffer_info->flags &
                               TX_BUFFER_INFO_FLAG_IGNORE_SYNC) != 0;
@@ -1626,7 +1624,7 @@ static netdev_tx_t lan743x_tx_xmit_frame(struct lan743x_tx *tx,
        if (required_number_of_descriptors >
                lan743x_tx_get_avail_desc(tx)) {
                if (required_number_of_descriptors > (tx->ring_size - 1)) {
-                       dev_kfree_skb(skb);
+                       dev_kfree_skb_irq(skb);
                } else {
                        /* save to overflow buffer */
                        tx->overflow_skb = skb;
@@ -1659,7 +1657,7 @@ static netdev_tx_t lan743x_tx_xmit_frame(struct lan743x_tx *tx,
                                   start_frame_length,
                                   do_timestamp,
                                   skb->ip_summed == CHECKSUM_PARTIAL)) {
-               dev_kfree_skb(skb);
+               dev_kfree_skb_irq(skb);
                goto unlock;
        }
 
@@ -1678,7 +1676,7 @@ static netdev_tx_t lan743x_tx_xmit_frame(struct lan743x_tx *tx,
                         * frame assembler clean up was performed inside
                         *      lan743x_tx_frame_add_fragment
                         */
-                       dev_kfree_skb(skb);
+                       dev_kfree_skb_irq(skb);
                        goto unlock;
                }
        }
@@ -2733,7 +2731,6 @@ static int lan743x_hardware_init(struct lan743x_adapter *adapter,
 
        adapter->intr.irq = adapter->pdev->irq;
        lan743x_csr_write(adapter, INT_EN_CLR, 0xFFFFFFFF);
-       mutex_init(&adapter->dp_lock);
 
        ret = lan743x_gpio_init(adapter);
        if (ret)
index c61a404..a536f4a 100644 (file)
@@ -712,9 +712,6 @@ struct lan743x_adapter {
        struct lan743x_csr      csr;
        struct lan743x_intr     intr;
 
-       /* lock, used to prevent concurrent access to data port */
-       struct mutex            dp_lock;
-
        struct lan743x_gpio     gpio;
        struct lan743x_ptp      ptp;
 
index ed9808f..35c72d4 100644 (file)
@@ -126,6 +126,11 @@ static int ionic_get_link_ksettings(struct net_device *netdev,
 
        ethtool_link_ksettings_zero_link_mode(ks, supported);
 
+       if (!idev->port_info) {
+               netdev_err(netdev, "port_info not initialized\n");
+               return -EOPNOTSUPP;
+       }
+
        /* The port_info data is found in a DMA space that the NIC keeps
         * up-to-date, so there's no need to request the data from the
         * NIC, we already have it in our memory space.
index 0e4cd88..0a22f8c 100644 (file)
@@ -1647,9 +1647,9 @@ static void qed_src_init_pf(struct qed_hwfn *p_hwfn)
                     ilog2(rounded_conn_num));
 
        STORE_RT_REG_AGG(p_hwfn, SRC_REG_FIRSTFREE_RT_OFFSET,
-                        p_hwfn->p_cxt_mngr->first_free);
+                        p_hwfn->p_cxt_mngr->src_t2.first_free);
        STORE_RT_REG_AGG(p_hwfn, SRC_REG_LASTFREE_RT_OFFSET,
-                        p_hwfn->p_cxt_mngr->last_free);
+                        p_hwfn->p_cxt_mngr->src_t2.last_free);
 }
 
 /* Timers PF */
index 8b64495..056e796 100644 (file)
@@ -326,9 +326,6 @@ struct qed_cxt_mngr {
 
        /* SRC T2 */
        struct qed_src_t2 src_t2;
-       u32 t2_num_pages;
-       u64 first_free;
-       u64 last_free;
 
        /* total number of SRQ's for this hwfn */
        u32 srq_count;
index 512cbef..a998611 100644 (file)
@@ -2754,14 +2754,18 @@ qed_iwarp_ll2_start(struct qed_hwfn *p_hwfn,
        iwarp_info->partial_fpdus = kcalloc((u16)p_hwfn->p_rdma_info->num_qps,
                                            sizeof(*iwarp_info->partial_fpdus),
                                            GFP_KERNEL);
-       if (!iwarp_info->partial_fpdus)
+       if (!iwarp_info->partial_fpdus) {
+               rc = -ENOMEM;
                goto err;
+       }
 
        iwarp_info->max_num_partial_fpdus = (u16)p_hwfn->p_rdma_info->num_qps;
 
        iwarp_info->mpa_intermediate_buf = kzalloc(buff_size, GFP_KERNEL);
-       if (!iwarp_info->mpa_intermediate_buf)
+       if (!iwarp_info->mpa_intermediate_buf) {
+               rc = -ENOMEM;
                goto err;
+       }
 
        /* The mpa_bufs array serves for pending RX packets received on the
         * mpa ll2 that don't have place on the tx ring and require later
@@ -2771,8 +2775,10 @@ qed_iwarp_ll2_start(struct qed_hwfn *p_hwfn,
        iwarp_info->mpa_bufs = kcalloc(data.input.rx_num_desc,
                                       sizeof(*iwarp_info->mpa_bufs),
                                       GFP_KERNEL);
-       if (!iwarp_info->mpa_bufs)
+       if (!iwarp_info->mpa_bufs) {
+               rc = -ENOMEM;
                goto err;
+       }
 
        INIT_LIST_HEAD(&iwarp_info->mpa_buf_pending_list);
        INIT_LIST_HEAD(&iwarp_info->mpa_buf_list);
index b8af59f..d2c1907 100644 (file)
@@ -2231,7 +2231,8 @@ static int qlcnic_83xx_restart_hw(struct qlcnic_adapter *adapter)
 
        /* Boot either flash image or firmware image from host file system */
        if (qlcnic_load_fw_file == 1) {
-               if (qlcnic_83xx_load_fw_image_from_host(adapter))
+               err = qlcnic_83xx_load_fw_image_from_host(adapter);
+               if (err)
                        return err;
        } else {
                QLC_SHARED_REG_WR32(adapter, QLCNIC_FW_IMG_VALID,
index 29a7bfa..3d7d3ab 100644 (file)
@@ -188,6 +188,11 @@ rx_handler_result_t rmnet_rx_handler(struct sk_buff **pskb)
 
        dev = skb->dev;
        port = rmnet_get_port_rcu(dev);
+       if (unlikely(!port)) {
+               atomic_long_inc(&skb->dev->rx_nohandler);
+               kfree_skb(skb);
+               goto done;
+       }
 
        switch (port->rmnet_mode) {
        case RMNET_EPMODE_VND:
index 00f1380..85d9c3e 100644 (file)
@@ -4080,9 +4080,17 @@ err_out:
        return -EIO;
 }
 
-static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb)
+static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp)
 {
-       return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34;
+       switch (tp->mac_version) {
+       case RTL_GIGA_MAC_VER_34:
+       case RTL_GIGA_MAC_VER_60:
+       case RTL_GIGA_MAC_VER_61:
+       case RTL_GIGA_MAC_VER_63:
+               return true;
+       default:
+               return false;
+       }
 }
 
 static void rtl8169_tso_csum_v1(struct sk_buff *skb, u32 *opts)
@@ -4154,8 +4162,9 @@ static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp,
 
                opts[1] |= transport_offset << TCPHO_SHIFT;
        } else {
-               if (unlikely(rtl_test_hw_pad_bug(tp, skb)))
-                       return !eth_skb_pad(skb);
+               if (unlikely(skb->len < ETH_ZLEN && rtl_test_hw_pad_bug(tp)))
+                       /* eth_skb_pad would free the skb on error */
+                       return !__skb_put_padto(skb, ETH_ZLEN, false);
        }
 
        return true;
@@ -4334,18 +4343,9 @@ static netdev_features_t rtl8169_features_check(struct sk_buff *skb,
                    rtl_chip_supports_csum_v2(tp))
                        features &= ~NETIF_F_ALL_TSO;
        } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
-               if (skb->len < ETH_ZLEN) {
-                       switch (tp->mac_version) {
-                       case RTL_GIGA_MAC_VER_11:
-                       case RTL_GIGA_MAC_VER_12:
-                       case RTL_GIGA_MAC_VER_17:
-                       case RTL_GIGA_MAC_VER_34:
-                               features &= ~NETIF_F_CSUM_MASK;
-                               break;
-                       default:
-                               break;
-                       }
-               }
+               /* work around hw bug on some chip versions */
+               if (skb->len < ETH_ZLEN)
+                       features &= ~NETIF_F_CSUM_MASK;
 
                if (transport_offset > TCPHO_MAX &&
                    rtl_chip_supports_csum_v2(tp))
index f61cb99..82b1c7a 100644 (file)
@@ -113,8 +113,10 @@ static int intel_eth_plat_probe(struct platform_device *pdev)
                /* Enable TX clock */
                if (dwmac->data->tx_clk_en) {
                        dwmac->tx_clk = devm_clk_get(&pdev->dev, "tx_clk");
-                       if (IS_ERR(dwmac->tx_clk))
+                       if (IS_ERR(dwmac->tx_clk)) {
+                               ret = PTR_ERR(dwmac->tx_clk);
                                goto err_remove_config_dt;
+                       }
 
                        clk_prepare_enable(dwmac->tx_clk);
 
index b6e5e3e..81ee0a0 100644 (file)
@@ -625,13 +625,6 @@ static int intel_eth_pci_probe(struct pci_dev *pdev,
        if (ret)
                return ret;
 
-       if (plat->eee_usecs_rate > 0) {
-               u32 tx_lpi_usec;
-
-               tx_lpi_usec = (plat->eee_usecs_rate / 1000000) - 1;
-               writel(tx_lpi_usec, res.addr + GMAC_1US_TIC_COUNTER);
-       }
-
        ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
        if (ret < 0)
                return ret;
@@ -641,6 +634,13 @@ static int intel_eth_pci_probe(struct pci_dev *pdev,
        res.wol_irq = pci_irq_vector(pdev, 0);
        res.irq = pci_irq_vector(pdev, 0);
 
+       if (plat->eee_usecs_rate > 0) {
+               u32 tx_lpi_usec;
+
+               tx_lpi_usec = (plat->eee_usecs_rate / 1000000) - 1;
+               writel(tx_lpi_usec, res.addr + GMAC_1US_TIC_COUNTER);
+       }
+
        ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
        if (ret) {
                pci_free_irq_vectors(pdev);
index cb87d31..57a53a6 100644 (file)
@@ -23,7 +23,7 @@ int dwmac_dma_reset(void __iomem *ioaddr)
 
        return readl_poll_timeout(ioaddr + DMA_BUS_MODE, value,
                                 !(value & DMA_BUS_MODE_SFT_RESET),
-                                10000, 100000);
+                                10000, 200000);
 }
 
 /* CSR1 enables the transmit DMA to check for new descriptor */
index 220626a..ba45fe2 100644 (file)
@@ -4757,6 +4757,7 @@ static void stmmac_napi_add(struct net_device *dev)
 
                ch->priv_data = priv;
                ch->index = queue;
+               spin_lock_init(&ch->lock);
 
                if (queue < priv->plat->rx_queues_to_use) {
                        netif_napi_add(dev, &ch->rx_napi, stmmac_napi_poll_rx,
@@ -5246,6 +5247,7 @@ int stmmac_resume(struct device *dev)
                        return ret;
        }
 
+       rtnl_lock();
        mutex_lock(&priv->lock);
 
        stmmac_reset_queues_param(priv);
@@ -5261,6 +5263,7 @@ int stmmac_resume(struct device *dev)
        stmmac_enable_all_queues(priv);
 
        mutex_unlock(&priv->lock);
+       rtnl_unlock();
 
        if (!device_may_wakeup(priv->device) || !priv->plat->pmt) {
                rtnl_lock();
index 75056c1..5dc60ec 100644 (file)
@@ -1001,8 +1001,7 @@ struct am65_cpts *am65_cpts_create(struct device *dev, void __iomem *regs,
        if (IS_ERR_OR_NULL(cpts->ptp_clock)) {
                dev_err(dev, "Failed to register ptp clk %ld\n",
                        PTR_ERR(cpts->ptp_clock));
-               if (!cpts->ptp_clock)
-                       ret = -ENODEV;
+               ret = cpts->ptp_clock ? PTR_ERR(cpts->ptp_clock) : -ENODEV;
                goto refclk_disable;
        }
        cpts->phc_index = ptp_clock_index(cpts->ptp_clock);
index 9fd1f77..b0f00b4 100644 (file)
@@ -838,9 +838,12 @@ static int cpsw_ndo_open(struct net_device *ndev)
                if (ret < 0)
                        goto err_cleanup;
 
-               if (cpts_register(cpsw->cpts))
-                       dev_err(priv->dev, "error registering cpts device\n");
-
+               if (cpsw->cpts) {
+                       if (cpts_register(cpsw->cpts))
+                               dev_err(priv->dev, "error registering cpts device\n");
+                       else
+                               writel(0x10, &cpsw->wr_regs->misc_en);
+               }
        }
 
        cpsw_restore(priv);
@@ -1631,6 +1634,7 @@ static int cpsw_probe(struct platform_device *pdev)
                                       CPSW_MAX_QUEUES, CPSW_MAX_QUEUES);
        if (!ndev) {
                dev_err(dev, "error allocating net_device\n");
+               ret = -ENOMEM;
                goto clean_cpts;
        }
 
@@ -1716,7 +1720,6 @@ static int cpsw_probe(struct platform_device *pdev)
 
        /* Enable misc CPTS evnt_pend IRQ */
        cpts_set_irqpoll(cpsw->cpts, false);
-       writel(0x10, &cpsw->wr_regs->misc_en);
 
 skip_cpts:
        cpsw_notice(priv, probe,
index 4d02c51..4619c3a 100644 (file)
@@ -728,7 +728,6 @@ int cpsw_get_ts_info(struct net_device *ndev, struct ethtool_ts_info *info)
                (1 << HWTSTAMP_TX_ON);
        info->rx_filters =
                (1 << HWTSTAMP_FILTER_NONE) |
-               (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
                (1 << HWTSTAMP_FILTER_PTP_V2_EVENT);
        return 0;
 }
index f779d2e..2f5e0ad 100644 (file)
@@ -873,8 +873,12 @@ static int cpsw_ndo_open(struct net_device *ndev)
                if (ret < 0)
                        goto err_cleanup;
 
-               if (cpts_register(cpsw->cpts))
-                       dev_err(priv->dev, "error registering cpts device\n");
+               if (cpsw->cpts) {
+                       if (cpts_register(cpsw->cpts))
+                               dev_err(priv->dev, "error registering cpts device\n");
+                       else
+                               writel(0x10, &cpsw->wr_regs->misc_en);
+               }
 
                napi_enable(&cpsw->napi_rx);
                napi_enable(&cpsw->napi_tx);
@@ -2006,7 +2010,6 @@ static int cpsw_probe(struct platform_device *pdev)
 
        /* Enable misc CPTS evnt_pend IRQ */
        cpts_set_irqpoll(cpsw->cpts, false);
-       writel(0x10, &cpsw->wr_regs->misc_en);
 
 skip_cpts:
        ret = cpsw_register_notifiers(cpsw);
index 51cc29f..31c5e36 100644 (file)
@@ -639,13 +639,10 @@ static int cpsw_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
                break;
        case HWTSTAMP_FILTER_ALL:
        case HWTSTAMP_FILTER_NTP_ALL:
-               return -ERANGE;
        case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
        case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
        case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
-               priv->rx_ts_enabled = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
-               cfg.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
-               break;
+               return -ERANGE;
        case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
        case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
        case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
index d07008a..1426bfc 100644 (file)
@@ -224,8 +224,7 @@ static void geneve_rx(struct geneve_dev *geneve, struct geneve_sock *gs,
        if (ip_tunnel_collect_metadata() || gs->collect_md) {
                __be16 flags;
 
-               flags = TUNNEL_KEY | TUNNEL_GENEVE_OPT |
-                       (gnvh->oam ? TUNNEL_OAM : 0) |
+               flags = TUNNEL_KEY | (gnvh->oam ? TUNNEL_OAM : 0) |
                        (gnvh->critical ? TUNNEL_CRIT_OPT : 0);
 
                tun_dst = udp_tun_rx_dst(skb, geneve_get_sk_family(gs), flags,
index 9264203..e8599bb 100644 (file)
@@ -362,22 +362,31 @@ struct gsi_trans *gsi_channel_trans_alloc(struct gsi *gsi, u32 channel_id,
        return trans;
 }
 
-/* Free a previously-allocated transaction (used only in case of error) */
+/* Free a previously-allocated transaction */
 void gsi_trans_free(struct gsi_trans *trans)
 {
+       refcount_t *refcount = &trans->refcount;
        struct gsi_trans_info *trans_info;
+       bool last;
 
-       if (!refcount_dec_and_test(&trans->refcount))
+       /* We must hold the lock to release the last reference */
+       if (refcount_dec_not_one(refcount))
                return;
 
        trans_info = &trans->gsi->channel[trans->channel_id].trans_info;
 
        spin_lock_bh(&trans_info->spinlock);
 
-       list_del(&trans->links);
+       /* Reference might have been added before we got the lock */
+       last = refcount_dec_and_test(refcount);
+       if (last)
+               list_del(&trans->links);
 
        spin_unlock_bh(&trans_info->spinlock);
 
+       if (!last)
+               return;
+
        ipa_gsi_trans_release(trans);
 
        /* Releasing the reserved TREs implicitly frees the sgl[] and
index d070614..e7972e8 100644 (file)
@@ -96,6 +96,7 @@ static const struct file_operations nsim_dev_take_snapshot_fops = {
        .open = simple_open,
        .write = nsim_dev_take_snapshot_write,
        .llseek = generic_file_llseek,
+       .owner = THIS_MODULE,
 };
 
 static ssize_t nsim_dev_trap_fa_cookie_read(struct file *file,
@@ -188,6 +189,7 @@ static const struct file_operations nsim_dev_trap_fa_cookie_fops = {
        .read = nsim_dev_trap_fa_cookie_read,
        .write = nsim_dev_trap_fa_cookie_write,
        .llseek = generic_file_llseek,
+       .owner = THIS_MODULE,
 };
 
 static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev)
index 62958b2..21e2974 100644 (file)
@@ -261,6 +261,7 @@ static const struct file_operations nsim_dev_health_break_fops = {
        .open = simple_open,
        .write = nsim_dev_health_break_write,
        .llseek = generic_file_llseek,
+       .owner = THIS_MODULE,
 };
 
 int nsim_dev_health_init(struct nsim_dev *nsim_dev, struct devlink *devlink)
index 6ab023a..02dc312 100644 (file)
@@ -124,6 +124,7 @@ static const struct file_operations nsim_udp_tunnels_info_reset_fops = {
        .open = simple_open,
        .write = nsim_udp_tunnels_info_reset_write,
        .llseek = generic_file_llseek,
+       .owner = THIS_MODULE,
 };
 
 int nsim_udp_tunnels_info_create(struct nsim_dev *nsim_dev,
index 6cf9b79..10be266 100644 (file)
@@ -981,7 +981,6 @@ int vsc8584_macsec_init(struct phy_device *phydev)
 
        switch (phydev->phy_id & phydev->drv->phy_id_mask) {
        case PHY_ID_VSC856X:
-       case PHY_ID_VSC8575:
        case PHY_ID_VSC8582:
        case PHY_ID_VSC8584:
                INIT_LIST_HEAD(&vsc8531->macsec_flows);
index fb1db71..575580d 100644 (file)
@@ -551,6 +551,8 @@ static struct phy_driver realtek_drvs[] = {
        {
                PHY_ID_MATCH_EXACT(0x00008201),
                .name           = "RTL8201CP Ethernet",
+               .read_page      = rtl821x_read_page,
+               .write_page     = rtl821x_write_page,
        }, {
                PHY_ID_MATCH_EXACT(0x001cc816),
                .name           = "RTL8201F Fast Ethernet",
index 1d18c10..34aa196 100644 (file)
@@ -2389,7 +2389,8 @@ static int sfp_probe(struct platform_device *pdev)
                        continue;
 
                sfp->gpio_irq[i] = gpiod_to_irq(sfp->gpio[i]);
-               if (!sfp->gpio_irq[i]) {
+               if (sfp->gpio_irq[i] < 0) {
+                       sfp->gpio_irq[i] = 0;
                        sfp->need_poll = true;
                        continue;
                }
index ec97669..0fc39ac 100644 (file)
@@ -291,8 +291,10 @@ static int smsc_phy_probe(struct phy_device *phydev)
                return ret;
 
        ret = clk_set_rate(priv->refclk, 50 * 1000 * 1000);
-       if (ret)
+       if (ret) {
+               clk_disable_unprepare(priv->refclk);
                return ret;
+       }
 
        return 0;
 }
index ca89d82..c4568a4 100644 (file)
@@ -197,7 +197,8 @@ static int cx82310_bind(struct usbnet *dev, struct usb_interface *intf)
        }
 
        /* enable ethernet mode (?) */
-       if (cx82310_enable_ethernet(dev))
+       ret = cx82310_enable_ethernet(dev);
+       if (ret)
                goto err;
 
        /* get the MAC address */
index a322f51..fc378ff 100644 (file)
@@ -1070,7 +1070,7 @@ static const struct usb_device_id products[] = {
        {QMI_FIXED_INTF(0x05c6, 0x9011, 4)},
        {QMI_FIXED_INTF(0x05c6, 0x9021, 1)},
        {QMI_FIXED_INTF(0x05c6, 0x9022, 2)},
-       {QMI_FIXED_INTF(0x05c6, 0x9025, 4)},    /* Alcatel-sbell ASB TL131 TDD LTE  (China Mobile) */
+       {QMI_QUIRK_SET_DTR(0x05c6, 0x9025, 4)}, /* Alcatel-sbell ASB TL131 TDD LTE (China Mobile) */
        {QMI_FIXED_INTF(0x05c6, 0x9026, 3)},
        {QMI_FIXED_INTF(0x05c6, 0x902e, 5)},
        {QMI_FIXED_INTF(0x05c6, 0x9031, 5)},
@@ -1309,6 +1309,7 @@ static const struct usb_device_id products[] = {
        {QMI_FIXED_INTF(0x1bc7, 0x1101, 3)},    /* Telit ME910 dual modem */
        {QMI_FIXED_INTF(0x1bc7, 0x1200, 5)},    /* Telit LE920 */
        {QMI_QUIRK_SET_DTR(0x1bc7, 0x1201, 2)}, /* Telit LE920, LE920A4 */
+       {QMI_QUIRK_SET_DTR(0x1bc7, 0x1230, 2)}, /* Telit LE910Cx */
        {QMI_QUIRK_SET_DTR(0x1bc7, 0x1260, 2)}, /* Telit LE910Cx */
        {QMI_QUIRK_SET_DTR(0x1bc7, 0x1261, 2)}, /* Telit LE910Cx */
        {QMI_QUIRK_SET_DTR(0x1bc7, 0x1900, 1)}, /* Telit LN940 series */
index 60c1aad..f2793ff 100644 (file)
@@ -608,8 +608,7 @@ static netdev_tx_t vrf_xmit(struct sk_buff *skb, struct net_device *dev)
        return ret;
 }
 
-static int vrf_finish_direct(struct net *net, struct sock *sk,
-                            struct sk_buff *skb)
+static void vrf_finish_direct(struct sk_buff *skb)
 {
        struct net_device *vrf_dev = skb->dev;
 
@@ -628,7 +627,8 @@ static int vrf_finish_direct(struct net *net, struct sock *sk,
                skb_pull(skb, ETH_HLEN);
        }
 
-       return 1;
+       /* reset skb device */
+       nf_reset_ct(skb);
 }
 
 #if IS_ENABLED(CONFIG_IPV6)
@@ -707,15 +707,41 @@ static struct sk_buff *vrf_ip6_out_redirect(struct net_device *vrf_dev,
        return skb;
 }
 
+static int vrf_output6_direct_finish(struct net *net, struct sock *sk,
+                                    struct sk_buff *skb)
+{
+       vrf_finish_direct(skb);
+
+       return vrf_ip6_local_out(net, sk, skb);
+}
+
 static int vrf_output6_direct(struct net *net, struct sock *sk,
                              struct sk_buff *skb)
 {
+       int err = 1;
+
        skb->protocol = htons(ETH_P_IPV6);
 
-       return NF_HOOK_COND(NFPROTO_IPV6, NF_INET_POST_ROUTING,
-                           net, sk, skb, NULL, skb->dev,
-                           vrf_finish_direct,
-                           !(IPCB(skb)->flags & IPSKB_REROUTED));
+       if (!(IPCB(skb)->flags & IPSKB_REROUTED))
+               err = nf_hook(NFPROTO_IPV6, NF_INET_POST_ROUTING, net, sk, skb,
+                             NULL, skb->dev, vrf_output6_direct_finish);
+
+       if (likely(err == 1))
+               vrf_finish_direct(skb);
+
+       return err;
+}
+
+static int vrf_ip6_out_direct_finish(struct net *net, struct sock *sk,
+                                    struct sk_buff *skb)
+{
+       int err;
+
+       err = vrf_output6_direct(net, sk, skb);
+       if (likely(err == 1))
+               err = vrf_ip6_local_out(net, sk, skb);
+
+       return err;
 }
 
 static struct sk_buff *vrf_ip6_out_direct(struct net_device *vrf_dev,
@@ -728,18 +754,15 @@ static struct sk_buff *vrf_ip6_out_direct(struct net_device *vrf_dev,
        skb->dev = vrf_dev;
 
        err = nf_hook(NFPROTO_IPV6, NF_INET_LOCAL_OUT, net, sk,
-                     skb, NULL, vrf_dev, vrf_output6_direct);
+                     skb, NULL, vrf_dev, vrf_ip6_out_direct_finish);
 
        if (likely(err == 1))
                err = vrf_output6_direct(net, sk, skb);
 
-       /* reset skb device */
        if (likely(err == 1))
-               nf_reset_ct(skb);
-       else
-               skb = NULL;
+               return skb;
 
-       return skb;
+       return NULL;
 }
 
 static struct sk_buff *vrf_ip6_out(struct net_device *vrf_dev,
@@ -919,15 +942,41 @@ static struct sk_buff *vrf_ip_out_redirect(struct net_device *vrf_dev,
        return skb;
 }
 
+static int vrf_output_direct_finish(struct net *net, struct sock *sk,
+                                   struct sk_buff *skb)
+{
+       vrf_finish_direct(skb);
+
+       return vrf_ip_local_out(net, sk, skb);
+}
+
 static int vrf_output_direct(struct net *net, struct sock *sk,
                             struct sk_buff *skb)
 {
+       int err = 1;
+
        skb->protocol = htons(ETH_P_IP);
 
-       return NF_HOOK_COND(NFPROTO_IPV4, NF_INET_POST_ROUTING,
-                           net, sk, skb, NULL, skb->dev,
-                           vrf_finish_direct,
-                           !(IPCB(skb)->flags & IPSKB_REROUTED));
+       if (!(IPCB(skb)->flags & IPSKB_REROUTED))
+               err = nf_hook(NFPROTO_IPV4, NF_INET_POST_ROUTING, net, sk, skb,
+                             NULL, skb->dev, vrf_output_direct_finish);
+
+       if (likely(err == 1))
+               vrf_finish_direct(skb);
+
+       return err;
+}
+
+static int vrf_ip_out_direct_finish(struct net *net, struct sock *sk,
+                                   struct sk_buff *skb)
+{
+       int err;
+
+       err = vrf_output_direct(net, sk, skb);
+       if (likely(err == 1))
+               err = vrf_ip_local_out(net, sk, skb);
+
+       return err;
 }
 
 static struct sk_buff *vrf_ip_out_direct(struct net_device *vrf_dev,
@@ -940,18 +989,15 @@ static struct sk_buff *vrf_ip_out_direct(struct net_device *vrf_dev,
        skb->dev = vrf_dev;
 
        err = nf_hook(NFPROTO_IPV4, NF_INET_LOCAL_OUT, net, sk,
-                     skb, NULL, vrf_dev, vrf_output_direct);
+                     skb, NULL, vrf_dev, vrf_ip_out_direct_finish);
 
        if (likely(err == 1))
                err = vrf_output_direct(net, sk, skb);
 
-       /* reset skb device */
        if (likely(err == 1))
-               nf_reset_ct(skb);
-       else
-               skb = NULL;
+               return skb;
 
-       return skb;
+       return NULL;
 }
 
 static struct sk_buff *vrf_ip_out(struct net_device *vrf_dev,
index f8aed06..2369ca2 100644 (file)
@@ -889,6 +889,7 @@ static ssize_t cosa_write(struct file *file,
                        chan->tx_status = 1;
                        spin_unlock_irqrestore(&cosa->lock, flags);
                        up(&chan->wsem);
+                       kfree(kbuf);
                        return -ERESTARTSYS;
                }
        }
index 376096b..9a270e4 100644 (file)
@@ -2060,8 +2060,6 @@ static void nvme_update_disk_info(struct gendisk *disk,
 
        if (id->nsattr & NVME_NS_ATTR_RO)
                set_disk_ro(disk, true);
-       else
-               set_disk_ro(disk, false);
 }
 
 static inline bool nvme_first_scan(struct gendisk *disk)
@@ -2931,7 +2929,7 @@ int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi,
 static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi,
                                struct nvme_effects_log **log)
 {
-       struct nvme_cel *cel = xa_load(&ctrl->cels, csi);
+       struct nvme_effects_log *cel = xa_load(&ctrl->cels, csi);
        int ret;
 
        if (cel)
@@ -2942,16 +2940,15 @@ static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi,
                return -ENOMEM;
 
        ret = nvme_get_log(ctrl, 0x00, NVME_LOG_CMD_EFFECTS, 0, csi,
-                       &cel->log, sizeof(cel->log), 0);
+                       cel, sizeof(*cel), 0);
        if (ret) {
                kfree(cel);
                return ret;
        }
 
-       cel->csi = csi;
-       xa_store(&ctrl->cels, cel->csi, cel, GFP_KERNEL);
+       xa_store(&ctrl->cels, csi, cel, GFP_KERNEL);
 out:
-       *log = &cel->log;
+       *log = cel;
        return 0;
 }
 
@@ -4376,6 +4373,19 @@ void nvme_uninit_ctrl(struct nvme_ctrl *ctrl)
 }
 EXPORT_SYMBOL_GPL(nvme_uninit_ctrl);
 
+static void nvme_free_cels(struct nvme_ctrl *ctrl)
+{
+       struct nvme_effects_log *cel;
+       unsigned long i;
+
+       xa_for_each (&ctrl->cels, i, cel) {
+               xa_erase(&ctrl->cels, i);
+               kfree(cel);
+       }
+
+       xa_destroy(&ctrl->cels);
+}
+
 static void nvme_free_ctrl(struct device *dev)
 {
        struct nvme_ctrl *ctrl =
@@ -4385,8 +4395,7 @@ static void nvme_free_ctrl(struct device *dev)
        if (!subsys || ctrl->instance != subsys->instance)
                ida_simple_remove(&nvme_instance_ida, ctrl->instance);
 
-       xa_destroy(&ctrl->cels);
-
+       nvme_free_cels(ctrl);
        nvme_mpath_uninit(ctrl);
        __free_page(ctrl->discard_page);
 
@@ -4582,8 +4591,7 @@ void nvme_start_queues(struct nvme_ctrl *ctrl)
 }
 EXPORT_SYMBOL_GPL(nvme_start_queues);
 
-
-void nvme_sync_queues(struct nvme_ctrl *ctrl)
+void nvme_sync_io_queues(struct nvme_ctrl *ctrl)
 {
        struct nvme_ns *ns;
 
@@ -4591,7 +4599,12 @@ void nvme_sync_queues(struct nvme_ctrl *ctrl)
        list_for_each_entry(ns, &ctrl->namespaces, list)
                blk_sync_queue(ns->queue);
        up_read(&ctrl->namespaces_rwsem);
+}
+EXPORT_SYMBOL_GPL(nvme_sync_io_queues);
 
+void nvme_sync_queues(struct nvme_ctrl *ctrl)
+{
+       nvme_sync_io_queues(ctrl);
        if (ctrl->admin_q)
                blk_sync_queue(ctrl->admin_q);
 }
index cc11113..567f7ad 100644 (file)
@@ -226,12 +226,6 @@ struct nvme_fault_inject {
 #endif
 };
 
-struct nvme_cel {
-       struct list_head        entry;
-       struct nvme_effects_log log;
-       u8                      csi;
-};
-
 struct nvme_ctrl {
        bool comp_seen;
        enum nvme_ctrl_state state;
@@ -602,6 +596,7 @@ void nvme_stop_queues(struct nvme_ctrl *ctrl);
 void nvme_start_queues(struct nvme_ctrl *ctrl);
 void nvme_kill_queues(struct nvme_ctrl *ctrl);
 void nvme_sync_queues(struct nvme_ctrl *ctrl);
+void nvme_sync_io_queues(struct nvme_ctrl *ctrl);
 void nvme_unfreeze(struct nvme_ctrl *ctrl);
 void nvme_wait_freeze(struct nvme_ctrl *ctrl);
 int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout);
index df8f361..3be3524 100644 (file)
@@ -198,6 +198,7 @@ struct nvme_queue {
        u32 q_depth;
        u16 cq_vector;
        u16 sq_tail;
+       u16 last_sq_tail;
        u16 cq_head;
        u16 qid;
        u8 cq_phase;
@@ -291,9 +292,21 @@ static void nvme_dbbuf_init(struct nvme_dev *dev,
        nvmeq->dbbuf_cq_ei = &dev->dbbuf_eis[cq_idx(qid, dev->db_stride)];
 }
 
+static void nvme_dbbuf_free(struct nvme_queue *nvmeq)
+{
+       if (!nvmeq->qid)
+               return;
+
+       nvmeq->dbbuf_sq_db = NULL;
+       nvmeq->dbbuf_cq_db = NULL;
+       nvmeq->dbbuf_sq_ei = NULL;
+       nvmeq->dbbuf_cq_ei = NULL;
+}
+
 static void nvme_dbbuf_set(struct nvme_dev *dev)
 {
        struct nvme_command c;
+       unsigned int i;
 
        if (!dev->dbbuf_dbs)
                return;
@@ -307,6 +320,9 @@ static void nvme_dbbuf_set(struct nvme_dev *dev)
                dev_warn(dev->ctrl.device, "unable to set dbbuf\n");
                /* Free memory and continue on */
                nvme_dbbuf_dma_free(dev);
+
+               for (i = 1; i <= dev->online_queues; i++)
+                       nvme_dbbuf_free(&dev->queues[i]);
        }
 }
 
@@ -455,11 +471,24 @@ static int nvme_pci_map_queues(struct blk_mq_tag_set *set)
        return 0;
 }
 
-static inline void nvme_write_sq_db(struct nvme_queue *nvmeq)
+/*
+ * Write sq tail if we are asked to, or if the next command would wrap.
+ */
+static inline void nvme_write_sq_db(struct nvme_queue *nvmeq, bool write_sq)
 {
+       if (!write_sq) {
+               u16 next_tail = nvmeq->sq_tail + 1;
+
+               if (next_tail == nvmeq->q_depth)
+                       next_tail = 0;
+               if (next_tail != nvmeq->last_sq_tail)
+                       return;
+       }
+
        if (nvme_dbbuf_update_and_check_event(nvmeq->sq_tail,
                        nvmeq->dbbuf_sq_db, nvmeq->dbbuf_sq_ei))
                writel(nvmeq->sq_tail, nvmeq->q_db);
+       nvmeq->last_sq_tail = nvmeq->sq_tail;
 }
 
 /**
@@ -476,8 +505,7 @@ static void nvme_submit_cmd(struct nvme_queue *nvmeq, struct nvme_command *cmd,
               cmd, sizeof(*cmd));
        if (++nvmeq->sq_tail == nvmeq->q_depth)
                nvmeq->sq_tail = 0;
-       if (write_sq)
-               nvme_write_sq_db(nvmeq);
+       nvme_write_sq_db(nvmeq, write_sq);
        spin_unlock(&nvmeq->sq_lock);
 }
 
@@ -486,7 +514,8 @@ static void nvme_commit_rqs(struct blk_mq_hw_ctx *hctx)
        struct nvme_queue *nvmeq = hctx->driver_data;
 
        spin_lock(&nvmeq->sq_lock);
-       nvme_write_sq_db(nvmeq);
+       if (nvmeq->sq_tail != nvmeq->last_sq_tail)
+               nvme_write_sq_db(nvmeq, true);
        spin_unlock(&nvmeq->sq_lock);
 }
 
@@ -1496,6 +1525,7 @@ static void nvme_init_queue(struct nvme_queue *nvmeq, u16 qid)
        struct nvme_dev *dev = nvmeq->dev;
 
        nvmeq->sq_tail = 0;
+       nvmeq->last_sq_tail = 0;
        nvmeq->cq_head = 0;
        nvmeq->cq_phase = 1;
        nvmeq->q_db = &dev->dbs[qid * 2 * dev->db_stride];
index 541b0cb..65e3d0e 100644 (file)
@@ -122,7 +122,6 @@ struct nvme_rdma_ctrl {
        struct sockaddr_storage src_addr;
 
        struct nvme_ctrl        ctrl;
-       struct mutex            teardown_lock;
        bool                    use_inline_data;
        u32                     io_queues[HCTX_MAX_TYPES];
 };
@@ -1010,8 +1009,8 @@ out_free_io_queues:
 static void nvme_rdma_teardown_admin_queue(struct nvme_rdma_ctrl *ctrl,
                bool remove)
 {
-       mutex_lock(&ctrl->teardown_lock);
        blk_mq_quiesce_queue(ctrl->ctrl.admin_q);
+       blk_sync_queue(ctrl->ctrl.admin_q);
        nvme_rdma_stop_queue(&ctrl->queues[0]);
        if (ctrl->ctrl.admin_tagset) {
                blk_mq_tagset_busy_iter(ctrl->ctrl.admin_tagset,
@@ -1021,16 +1020,15 @@ static void nvme_rdma_teardown_admin_queue(struct nvme_rdma_ctrl *ctrl,
        if (remove)
                blk_mq_unquiesce_queue(ctrl->ctrl.admin_q);
        nvme_rdma_destroy_admin_queue(ctrl, remove);
-       mutex_unlock(&ctrl->teardown_lock);
 }
 
 static void nvme_rdma_teardown_io_queues(struct nvme_rdma_ctrl *ctrl,
                bool remove)
 {
-       mutex_lock(&ctrl->teardown_lock);
        if (ctrl->ctrl.queue_count > 1) {
                nvme_start_freeze(&ctrl->ctrl);
                nvme_stop_queues(&ctrl->ctrl);
+               nvme_sync_io_queues(&ctrl->ctrl);
                nvme_rdma_stop_io_queues(ctrl);
                if (ctrl->ctrl.tagset) {
                        blk_mq_tagset_busy_iter(ctrl->ctrl.tagset,
@@ -1041,7 +1039,6 @@ static void nvme_rdma_teardown_io_queues(struct nvme_rdma_ctrl *ctrl,
                        nvme_start_queues(&ctrl->ctrl);
                nvme_rdma_destroy_io_queues(ctrl, remove);
        }
-       mutex_unlock(&ctrl->teardown_lock);
 }
 
 static void nvme_rdma_free_ctrl(struct nvme_ctrl *nctrl)
@@ -1976,16 +1973,12 @@ static void nvme_rdma_complete_timed_out(struct request *rq)
 {
        struct nvme_rdma_request *req = blk_mq_rq_to_pdu(rq);
        struct nvme_rdma_queue *queue = req->queue;
-       struct nvme_rdma_ctrl *ctrl = queue->ctrl;
 
-       /* fence other contexts that may complete the command */
-       mutex_lock(&ctrl->teardown_lock);
        nvme_rdma_stop_queue(queue);
-       if (!blk_mq_request_completed(rq)) {
+       if (blk_mq_request_started(rq) && !blk_mq_request_completed(rq)) {
                nvme_req(rq)->status = NVME_SC_HOST_ABORTED_CMD;
                blk_mq_complete_request(rq);
        }
-       mutex_unlock(&ctrl->teardown_lock);
 }
 
 static enum blk_eh_timer_return
@@ -2320,7 +2313,6 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev,
                return ERR_PTR(-ENOMEM);
        ctrl->ctrl.opts = opts;
        INIT_LIST_HEAD(&ctrl->list);
-       mutex_init(&ctrl->teardown_lock);
 
        if (!(opts->mask & NVMF_OPT_TRSVCID)) {
                opts->trsvcid =
index d6a3e14..c0c3332 100644 (file)
@@ -124,7 +124,6 @@ struct nvme_tcp_ctrl {
        struct sockaddr_storage src_addr;
        struct nvme_ctrl        ctrl;
 
-       struct mutex            teardown_lock;
        struct work_struct      err_work;
        struct delayed_work     connect_work;
        struct nvme_tcp_request async_req;
@@ -1886,8 +1885,8 @@ out_free_queue:
 static void nvme_tcp_teardown_admin_queue(struct nvme_ctrl *ctrl,
                bool remove)
 {
-       mutex_lock(&to_tcp_ctrl(ctrl)->teardown_lock);
        blk_mq_quiesce_queue(ctrl->admin_q);
+       blk_sync_queue(ctrl->admin_q);
        nvme_tcp_stop_queue(ctrl, 0);
        if (ctrl->admin_tagset) {
                blk_mq_tagset_busy_iter(ctrl->admin_tagset,
@@ -1897,18 +1896,17 @@ static void nvme_tcp_teardown_admin_queue(struct nvme_ctrl *ctrl,
        if (remove)
                blk_mq_unquiesce_queue(ctrl->admin_q);
        nvme_tcp_destroy_admin_queue(ctrl, remove);
-       mutex_unlock(&to_tcp_ctrl(ctrl)->teardown_lock);
 }
 
 static void nvme_tcp_teardown_io_queues(struct nvme_ctrl *ctrl,
                bool remove)
 {
-       mutex_lock(&to_tcp_ctrl(ctrl)->teardown_lock);
        if (ctrl->queue_count <= 1)
-               goto out;
+               return;
        blk_mq_quiesce_queue(ctrl->admin_q);
        nvme_start_freeze(ctrl);
        nvme_stop_queues(ctrl);
+       nvme_sync_io_queues(ctrl);
        nvme_tcp_stop_io_queues(ctrl);
        if (ctrl->tagset) {
                blk_mq_tagset_busy_iter(ctrl->tagset,
@@ -1918,8 +1916,6 @@ static void nvme_tcp_teardown_io_queues(struct nvme_ctrl *ctrl,
        if (remove)
                nvme_start_queues(ctrl);
        nvme_tcp_destroy_io_queues(ctrl, remove);
-out:
-       mutex_unlock(&to_tcp_ctrl(ctrl)->teardown_lock);
 }
 
 static void nvme_tcp_reconnect_or_remove(struct nvme_ctrl *ctrl)
@@ -2171,14 +2167,11 @@ static void nvme_tcp_complete_timed_out(struct request *rq)
        struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq);
        struct nvme_ctrl *ctrl = &req->queue->ctrl->ctrl;
 
-       /* fence other contexts that may complete the command */
-       mutex_lock(&to_tcp_ctrl(ctrl)->teardown_lock);
        nvme_tcp_stop_queue(ctrl, nvme_tcp_queue_id(req->queue));
-       if (!blk_mq_request_completed(rq)) {
+       if (blk_mq_request_started(rq) && !blk_mq_request_completed(rq)) {
                nvme_req(rq)->status = NVME_SC_HOST_ABORTED_CMD;
                blk_mq_complete_request(rq);
        }
-       mutex_unlock(&to_tcp_ctrl(ctrl)->teardown_lock);
 }
 
 static enum blk_eh_timer_return
@@ -2455,7 +2448,6 @@ static struct nvme_ctrl *nvme_tcp_create_ctrl(struct device *dev,
                        nvme_tcp_reconnect_ctrl_work);
        INIT_WORK(&ctrl->err_work, nvme_tcp_error_recovery_work);
        INIT_WORK(&ctrl->ctrl.reset_work, nvme_reset_ctrl_work);
-       mutex_init(&ctrl->teardown_lock);
 
        if (!(opts->mask & NVMF_OPT_TRSVCID)) {
                opts->trsvcid =
index eb9ab4f..1c3257a 100644 (file)
@@ -1034,11 +1034,13 @@ out:
  */
 bool of_dma_is_coherent(struct device_node *np)
 {
-       struct device_node *node = of_node_get(np);
+       struct device_node *node;
 
        if (IS_ENABLED(CONFIG_OF_DMA_DEFAULT_COHERENT))
                return true;
 
+       node = of_node_get(np);
+
        while (node) {
                if (of_property_read_bool(node, "dma-coherent")) {
                        of_node_put(node);
index 3a469c7..aedfaaa 100644 (file)
@@ -112,7 +112,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
                u64 dma_end = 0;
 
                /* Determine the overall bounds of all DMA regions */
-               for (dma_start = ~0ULL; r->size; r++) {
+               for (dma_start = ~0; r->size; r++) {
                        /* Take lower and upper limits */
                        if (r->dma_start < dma_start)
                                dma_start = r->dma_start;
index 2483e76..0e0a526 100644 (file)
@@ -1181,6 +1181,10 @@ static void _opp_table_kref_release(struct kref *kref)
        struct opp_device *opp_dev, *temp;
        int i;
 
+       /* Drop the lock as soon as we can */
+       list_del(&opp_table->node);
+       mutex_unlock(&opp_table_lock);
+
        _of_clear_opp_table(opp_table);
 
        /* Release clk */
@@ -1208,10 +1212,7 @@ static void _opp_table_kref_release(struct kref *kref)
 
        mutex_destroy(&opp_table->genpd_virt_dev_lock);
        mutex_destroy(&opp_table->lock);
-       list_del(&opp_table->node);
        kfree(opp_table);
-
-       mutex_unlock(&opp_table_lock);
 }
 
 void dev_pm_opp_put_opp_table(struct opp_table *opp_table)
@@ -1930,7 +1931,7 @@ struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
                return ERR_PTR(-EINVAL);
 
        opp_table = dev_pm_opp_get_opp_table(dev);
-       if (!IS_ERR(opp_table))
+       if (IS_ERR(opp_table))
                return opp_table;
 
        /* This should be called before OPPs are initialized */
index 874b587..9faeb83 100644 (file)
@@ -944,6 +944,8 @@ static int _of_add_opp_table_v1(struct device *dev, struct opp_table *opp_table)
                nr -= 2;
        }
 
+       return 0;
+
 remove_static_opp:
        _opp_remove_all_static(opp_table);
 
index 674f32d..44c2a65 100644 (file)
@@ -586,8 +586,12 @@ void dw_pcie_setup_rc(struct pcie_port *pp)
         * ATU, so we should not program the ATU here.
         */
        if (pp->bridge->child_ops == &dw_child_pcie_ops) {
-               struct resource_entry *entry =
-                       resource_list_first_type(&pp->bridge->windows, IORESOURCE_MEM);
+               struct resource_entry *tmp, *entry = NULL;
+
+               /* Get last memory resource entry */
+               resource_list_for_each_entry(tmp, &pp->bridge->windows)
+                       if (resource_type(tmp->res) == IORESOURCE_MEM)
+                               entry = tmp;
 
                dw_pcie_prog_outbound_atu(pci, PCIE_ATU_REGION_INDEX0,
                                          PCIE_ATU_TYPE_MEM, entry->res->start,
index eee8283..ed13e81 100644 (file)
@@ -958,25 +958,16 @@ static void mvebu_pcie_powerdown(struct mvebu_pcie_port *port)
 }
 
 /*
- * We can't use devm_of_pci_get_host_bridge_resources() because we
- * need to parse our special DT properties encoding the MEM and IO
- * apertures.
+ * devm_of_pci_get_host_bridge_resources() only sets up translateable resources,
+ * so we need extra resource setup parsing our special DT properties encoding
+ * the MEM and IO apertures.
  */
 static int mvebu_pcie_parse_request_resources(struct mvebu_pcie *pcie)
 {
        struct device *dev = &pcie->pdev->dev;
-       struct device_node *np = dev->of_node;
        struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie);
        int ret;
 
-       /* Get the bus range */
-       ret = of_pci_parse_bus_range(np, &pcie->busn);
-       if (ret) {
-               dev_err(dev, "failed to parse bus-range property: %d\n", ret);
-               return ret;
-       }
-       pci_add_resource(&bridge->windows, &pcie->busn);
-
        /* Get the PCIe memory aperture */
        mvebu_mbus_get_pcie_mem_aperture(&pcie->mem);
        if (resource_size(&pcie->mem) == 0) {
@@ -986,6 +977,9 @@ static int mvebu_pcie_parse_request_resources(struct mvebu_pcie *pcie)
 
        pcie->mem.name = "PCI MEM";
        pci_add_resource(&bridge->windows, &pcie->mem);
+       ret = devm_request_resource(dev, &iomem_resource, &pcie->mem);
+       if (ret)
+               return ret;
 
        /* Get the PCIe IO aperture */
        mvebu_mbus_get_pcie_io_aperture(&pcie->io);
@@ -999,9 +993,12 @@ static int mvebu_pcie_parse_request_resources(struct mvebu_pcie *pcie)
                pcie->realio.name = "PCI I/O";
 
                pci_add_resource(&bridge->windows, &pcie->realio);
+               ret = devm_request_resource(dev, &ioport_resource, &pcie->realio);
+               if (ret)
+                       return ret;
        }
 
-       return devm_request_pci_bus_resources(dev, &bridge->windows);
+       return 0;
 }
 
 /*
index 6d4d5a2..e578d34 100644 (file)
@@ -3516,8 +3516,13 @@ void pci_acs_init(struct pci_dev *dev)
 {
        dev->acs_cap = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
 
-       if (dev->acs_cap)
-               pci_enable_acs(dev);
+       /*
+        * Attempt to enable ACS regardless of capability because some Root
+        * Ports (e.g. those quirked with *_intel_pch_acs_*) do not have
+        * the standard ACS capability but still support ACS via those
+        * quirks.
+        */
+       pci_enable_acs(dev);
 }
 
 /**
index 6a94eae..d6b8495 100644 (file)
@@ -286,13 +286,14 @@ int aspeed_pinmux_set_mux(struct pinctrl_dev *pctldev, unsigned int function,
 static bool aspeed_expr_is_gpio(const struct aspeed_sig_expr *expr)
 {
        /*
-        * The signal type is GPIO if the signal name has "GPIO" as a prefix.
+        * The signal type is GPIO if the signal name has "GPI" as a prefix.
         * strncmp (rather than strcmp) is used to implement the prefix
         * requirement.
         *
-        * expr->signal might look like "GPIOT3" in the GPIO case.
+        * expr->signal might look like "GPIOB1" in the GPIO case.
+        * expr->signal might look like "GPIT0" in the GPI case.
         */
-       return strncmp(expr->signal, "GPIO", 4) == 0;
+       return strncmp(expr->signal, "GPI", 3) == 0;
 }
 
 static bool aspeed_gpio_in_exprs(const struct aspeed_sig_expr **exprs)
index 154ce3f..1c10ab1 100644 (file)
 #define PADCFG1_TERM_UP                        BIT(13)
 #define PADCFG1_TERM_SHIFT             10
 #define PADCFG1_TERM_MASK              GENMASK(12, 10)
-#define PADCFG1_TERM_20K               4
-#define PADCFG1_TERM_2K                        3
-#define PADCFG1_TERM_5K                        2
-#define PADCFG1_TERM_1K                        1
+#define PADCFG1_TERM_20K               BIT(2)
+#define PADCFG1_TERM_5K                        BIT(1)
+#define PADCFG1_TERM_1K                        BIT(0)
+#define PADCFG1_TERM_833               (BIT(1) | BIT(0))
 
 #define PADCFG2                                0x008
 #define PADCFG2_DEBEN                  BIT(0)
@@ -549,12 +549,12 @@ static int intel_config_get_pull(struct intel_pinctrl *pctrl, unsigned int pin,
                        return -EINVAL;
 
                switch (term) {
+               case PADCFG1_TERM_833:
+                       *arg = 833;
+                       break;
                case PADCFG1_TERM_1K:
                        *arg = 1000;
                        break;
-               case PADCFG1_TERM_2K:
-                       *arg = 2000;
-                       break;
                case PADCFG1_TERM_5K:
                        *arg = 5000;
                        break;
@@ -570,6 +570,11 @@ static int intel_config_get_pull(struct intel_pinctrl *pctrl, unsigned int pin,
                        return -EINVAL;
 
                switch (term) {
+               case PADCFG1_TERM_833:
+                       if (!(community->features & PINCTRL_FEATURE_1K_PD))
+                               return -EINVAL;
+                       *arg = 833;
+                       break;
                case PADCFG1_TERM_1K:
                        if (!(community->features & PINCTRL_FEATURE_1K_PD))
                                return -EINVAL;
@@ -678,6 +683,10 @@ static int intel_config_set_pull(struct intel_pinctrl *pctrl, unsigned int pin,
 
                value |= PADCFG1_TERM_UP;
 
+               /* Set default strength value in case none is given */
+               if (arg == 1)
+                       arg = 5000;
+
                switch (arg) {
                case 20000:
                        value |= PADCFG1_TERM_20K << PADCFG1_TERM_SHIFT;
@@ -685,12 +694,12 @@ static int intel_config_set_pull(struct intel_pinctrl *pctrl, unsigned int pin,
                case 5000:
                        value |= PADCFG1_TERM_5K << PADCFG1_TERM_SHIFT;
                        break;
-               case 2000:
-                       value |= PADCFG1_TERM_2K << PADCFG1_TERM_SHIFT;
-                       break;
                case 1000:
                        value |= PADCFG1_TERM_1K << PADCFG1_TERM_SHIFT;
                        break;
+               case 833:
+                       value |= PADCFG1_TERM_833 << PADCFG1_TERM_SHIFT;
+                       break;
                default:
                        ret = -EINVAL;
                }
@@ -700,6 +709,10 @@ static int intel_config_set_pull(struct intel_pinctrl *pctrl, unsigned int pin,
        case PIN_CONFIG_BIAS_PULL_DOWN:
                value &= ~(PADCFG1_TERM_UP | PADCFG1_TERM_MASK);
 
+               /* Set default strength value in case none is given */
+               if (arg == 1)
+                       arg = 5000;
+
                switch (arg) {
                case 20000:
                        value |= PADCFG1_TERM_20K << PADCFG1_TERM_SHIFT;
@@ -714,6 +727,13 @@ static int intel_config_set_pull(struct intel_pinctrl *pctrl, unsigned int pin,
                        }
                        value |= PADCFG1_TERM_1K << PADCFG1_TERM_SHIFT;
                        break;
+               case 833:
+                       if (!(community->features & PINCTRL_FEATURE_1K_PD)) {
+                               ret = -EINVAL;
+                               break;
+                       }
+                       value |= PADCFG1_TERM_833 << PADCFG1_TERM_SHIFT;
+                       break;
                default:
                        ret = -EINVAL;
                }
index 9a760f5..4aea3e0 100644 (file)
@@ -156,7 +156,7 @@ static int amd_gpio_set_debounce(struct gpio_chip *gc, unsigned offset,
                        pin_reg |= BIT(DB_TMR_OUT_UNIT_OFF);
                        pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
                } else if (debounce < 250000) {
-                       time = debounce / 15600;
+                       time = debounce / 15625;
                        pin_reg |= time & DB_TMR_OUT_MASK;
                        pin_reg &= ~BIT(DB_TMR_OUT_UNIT_OFF);
                        pin_reg |= BIT(DB_TMR_LARGE_OFF);
@@ -166,14 +166,14 @@ static int amd_gpio_set_debounce(struct gpio_chip *gc, unsigned offset,
                        pin_reg |= BIT(DB_TMR_OUT_UNIT_OFF);
                        pin_reg |= BIT(DB_TMR_LARGE_OFF);
                } else {
-                       pin_reg &= ~DB_CNTRl_MASK;
+                       pin_reg &= ~(DB_CNTRl_MASK << DB_CNTRL_OFF);
                        ret = -EINVAL;
                }
        } else {
                pin_reg &= ~BIT(DB_TMR_OUT_UNIT_OFF);
                pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
                pin_reg &= ~DB_TMR_OUT_MASK;
-               pin_reg &= ~DB_CNTRl_MASK;
+               pin_reg &= ~(DB_CNTRl_MASK << DB_CNTRL_OFF);
        }
        writel(pin_reg, gpio_dev->base + offset * 4);
        raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
index c8e50a5..621909b 100644 (file)
@@ -635,44 +635,44 @@ static int jz4770_uart3_data_pins[] = { 0x6c, 0x85, };
 static int jz4770_uart3_hwflow_pins[] = { 0x88, 0x89, };
 static int jz4770_ssi0_dt_a_pins[] = { 0x15, };
 static int jz4770_ssi0_dt_b_pins[] = { 0x35, };
-static int jz4770_ssi0_dt_d_pins[] = { 0x55, };
-static int jz4770_ssi0_dt_e_pins[] = { 0x71, };
+static int jz4770_ssi0_dt_d_pins[] = { 0x75, };
+static int jz4770_ssi0_dt_e_pins[] = { 0x91, };
 static int jz4770_ssi0_dr_a_pins[] = { 0x14, };
 static int jz4770_ssi0_dr_b_pins[] = { 0x34, };
-static int jz4770_ssi0_dr_d_pins[] = { 0x54, };
-static int jz4770_ssi0_dr_e_pins[] = { 0x6e, };
+static int jz4770_ssi0_dr_d_pins[] = { 0x74, };
+static int jz4770_ssi0_dr_e_pins[] = { 0x8e, };
 static int jz4770_ssi0_clk_a_pins[] = { 0x12, };
 static int jz4770_ssi0_clk_b_pins[] = { 0x3c, };
-static int jz4770_ssi0_clk_d_pins[] = { 0x58, };
-static int jz4770_ssi0_clk_e_pins[] = { 0x6f, };
+static int jz4770_ssi0_clk_d_pins[] = { 0x78, };
+static int jz4770_ssi0_clk_e_pins[] = { 0x8f, };
 static int jz4770_ssi0_gpc_b_pins[] = { 0x3e, };
-static int jz4770_ssi0_gpc_d_pins[] = { 0x56, };
-static int jz4770_ssi0_gpc_e_pins[] = { 0x73, };
+static int jz4770_ssi0_gpc_d_pins[] = { 0x76, };
+static int jz4770_ssi0_gpc_e_pins[] = { 0x93, };
 static int jz4770_ssi0_ce0_a_pins[] = { 0x13, };
 static int jz4770_ssi0_ce0_b_pins[] = { 0x3d, };
-static int jz4770_ssi0_ce0_d_pins[] = { 0x59, };
-static int jz4770_ssi0_ce0_e_pins[] = { 0x70, };
+static int jz4770_ssi0_ce0_d_pins[] = { 0x79, };
+static int jz4770_ssi0_ce0_e_pins[] = { 0x90, };
 static int jz4770_ssi0_ce1_b_pins[] = { 0x3f, };
-static int jz4770_ssi0_ce1_d_pins[] = { 0x57, };
-static int jz4770_ssi0_ce1_e_pins[] = { 0x72, };
+static int jz4770_ssi0_ce1_d_pins[] = { 0x77, };
+static int jz4770_ssi0_ce1_e_pins[] = { 0x92, };
 static int jz4770_ssi1_dt_b_pins[] = { 0x35, };
-static int jz4770_ssi1_dt_d_pins[] = { 0x55, };
-static int jz4770_ssi1_dt_e_pins[] = { 0x71, };
+static int jz4770_ssi1_dt_d_pins[] = { 0x75, };
+static int jz4770_ssi1_dt_e_pins[] = { 0x91, };
 static int jz4770_ssi1_dr_b_pins[] = { 0x34, };
-static int jz4770_ssi1_dr_d_pins[] = { 0x54, };
-static int jz4770_ssi1_dr_e_pins[] = { 0x6e, };
+static int jz4770_ssi1_dr_d_pins[] = { 0x74, };
+static int jz4770_ssi1_dr_e_pins[] = { 0x8e, };
 static int jz4770_ssi1_clk_b_pins[] = { 0x3c, };
-static int jz4770_ssi1_clk_d_pins[] = { 0x58, };
-static int jz4770_ssi1_clk_e_pins[] = { 0x6f, };
+static int jz4770_ssi1_clk_d_pins[] = { 0x78, };
+static int jz4770_ssi1_clk_e_pins[] = { 0x8f, };
 static int jz4770_ssi1_gpc_b_pins[] = { 0x3e, };
-static int jz4770_ssi1_gpc_d_pins[] = { 0x56, };
-static int jz4770_ssi1_gpc_e_pins[] = { 0x73, };
+static int jz4770_ssi1_gpc_d_pins[] = { 0x76, };
+static int jz4770_ssi1_gpc_e_pins[] = { 0x93, };
 static int jz4770_ssi1_ce0_b_pins[] = { 0x3d, };
-static int jz4770_ssi1_ce0_d_pins[] = { 0x59, };
-static int jz4770_ssi1_ce0_e_pins[] = { 0x70, };
+static int jz4770_ssi1_ce0_d_pins[] = { 0x79, };
+static int jz4770_ssi1_ce0_e_pins[] = { 0x90, };
 static int jz4770_ssi1_ce1_b_pins[] = { 0x3f, };
-static int jz4770_ssi1_ce1_d_pins[] = { 0x57, };
-static int jz4770_ssi1_ce1_e_pins[] = { 0x72, };
+static int jz4770_ssi1_ce1_d_pins[] = { 0x77, };
+static int jz4770_ssi1_ce1_e_pins[] = { 0x92, };
 static int jz4770_mmc0_1bit_a_pins[] = { 0x12, 0x13, 0x14, };
 static int jz4770_mmc0_4bit_a_pins[] = { 0x15, 0x16, 0x17, };
 static int jz4770_mmc0_1bit_e_pins[] = { 0x9c, 0x9d, 0x94, };
@@ -1050,35 +1050,35 @@ static int jz4780_ssi0_dt_a_19_pins[] = { 0x13, };
 static int jz4780_ssi0_dt_a_21_pins[] = { 0x15, };
 static int jz4780_ssi0_dt_a_28_pins[] = { 0x1c, };
 static int jz4780_ssi0_dt_b_pins[] = { 0x3d, };
-static int jz4780_ssi0_dt_d_pins[] = { 0x59, };
+static int jz4780_ssi0_dt_d_pins[] = { 0x79, };
 static int jz4780_ssi0_dr_a_20_pins[] = { 0x14, };
 static int jz4780_ssi0_dr_a_27_pins[] = { 0x1b, };
 static int jz4780_ssi0_dr_b_pins[] = { 0x34, };
-static int jz4780_ssi0_dr_d_pins[] = { 0x54, };
+static int jz4780_ssi0_dr_d_pins[] = { 0x74, };
 static int jz4780_ssi0_clk_a_pins[] = { 0x12, };
 static int jz4780_ssi0_clk_b_5_pins[] = { 0x25, };
 static int jz4780_ssi0_clk_b_28_pins[] = { 0x3c, };
-static int jz4780_ssi0_clk_d_pins[] = { 0x58, };
+static int jz4780_ssi0_clk_d_pins[] = { 0x78, };
 static int jz4780_ssi0_gpc_b_pins[] = { 0x3e, };
-static int jz4780_ssi0_gpc_d_pins[] = { 0x56, };
+static int jz4780_ssi0_gpc_d_pins[] = { 0x76, };
 static int jz4780_ssi0_ce0_a_23_pins[] = { 0x17, };
 static int jz4780_ssi0_ce0_a_25_pins[] = { 0x19, };
 static int jz4780_ssi0_ce0_b_pins[] = { 0x3f, };
-static int jz4780_ssi0_ce0_d_pins[] = { 0x57, };
+static int jz4780_ssi0_ce0_d_pins[] = { 0x77, };
 static int jz4780_ssi0_ce1_b_pins[] = { 0x35, };
-static int jz4780_ssi0_ce1_d_pins[] = { 0x55, };
+static int jz4780_ssi0_ce1_d_pins[] = { 0x75, };
 static int jz4780_ssi1_dt_b_pins[] = { 0x3d, };
-static int jz4780_ssi1_dt_d_pins[] = { 0x59, };
+static int jz4780_ssi1_dt_d_pins[] = { 0x79, };
 static int jz4780_ssi1_dr_b_pins[] = { 0x34, };
-static int jz4780_ssi1_dr_d_pins[] = { 0x54, };
+static int jz4780_ssi1_dr_d_pins[] = { 0x74, };
 static int jz4780_ssi1_clk_b_pins[] = { 0x3c, };
-static int jz4780_ssi1_clk_d_pins[] = { 0x58, };
+static int jz4780_ssi1_clk_d_pins[] = { 0x78, };
 static int jz4780_ssi1_gpc_b_pins[] = { 0x3e, };
-static int jz4780_ssi1_gpc_d_pins[] = { 0x56, };
+static int jz4780_ssi1_gpc_d_pins[] = { 0x76, };
 static int jz4780_ssi1_ce0_b_pins[] = { 0x3f, };
-static int jz4780_ssi1_ce0_d_pins[] = { 0x57, };
+static int jz4780_ssi1_ce0_d_pins[] = { 0x77, };
 static int jz4780_ssi1_ce1_b_pins[] = { 0x35, };
-static int jz4780_ssi1_ce1_d_pins[] = { 0x55, };
+static int jz4780_ssi1_ce1_d_pins[] = { 0x75, };
 static int jz4780_mmc0_8bit_a_pins[] = { 0x04, 0x05, 0x06, 0x07, 0x18, };
 static int jz4780_i2c3_pins[] = { 0x6a, 0x6b, };
 static int jz4780_i2c4_e_pins[] = { 0x8c, 0x8d, };
index 1f47a66..9ae1031 100644 (file)
@@ -119,13 +119,15 @@ static int mcp23s08_spi_regmap_init(struct mcp23s08 *mcp, struct device *dev,
                return -EINVAL;
        }
 
-       copy = devm_kmemdup(dev, &config, sizeof(config), GFP_KERNEL);
+       copy = devm_kmemdup(dev, config, sizeof(*config), GFP_KERNEL);
        if (!copy)
                return -ENOMEM;
 
        copy->name = name;
 
        mcp->regmap = devm_regmap_init(dev, &mcp23sxx_spi_regmap, mcp, copy);
+       if (IS_ERR(mcp->regmap))
+               dev_err(dev, "regmap init failed for %s\n", mcp->chip.label);
        return PTR_ERR_OR_ZERO(mcp->regmap);
 }
 
index 0401c1d..aa1a1c8 100644 (file)
@@ -3155,7 +3155,9 @@ static int rockchip_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
        if (!bank->domain)
                return -ENXIO;
 
+       clk_enable(bank->clk);
        virq = irq_create_mapping(bank->domain, offset);
+       clk_disable(bank->clk);
 
        return (virq) ? : -ENXIO;
 }
@@ -3194,7 +3196,7 @@ static void rockchip_irq_demux(struct irq_desc *desc)
 
                irq = __ffs(pend);
                pend &= ~BIT(irq);
-               virq = irq_linear_revmap(bank->domain, irq);
+               virq = irq_find_mapping(bank->domain, irq);
 
                if (!virq) {
                        dev_err(bank->drvdata->dev, "unmapped irq %d\n", irq);
@@ -3373,7 +3375,7 @@ static int rockchip_interrupts_register(struct platform_device *pdev,
        unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
        struct irq_chip_generic *gc;
        int ret;
-       int i, j;
+       int i;
 
        for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
                if (!bank->valid) {
@@ -3400,7 +3402,7 @@ static int rockchip_interrupts_register(struct platform_device *pdev,
 
                ret = irq_alloc_domain_generic_chips(bank->domain, 32, 1,
                                         "rockchip_gpio_irq", handle_level_irq,
-                                        clr, 0, IRQ_GC_INIT_MASK_CACHE);
+                                        clr, 0, 0);
                if (ret) {
                        dev_err(&pdev->dev, "could not alloc generic chips for bank %s\n",
                                bank->name);
@@ -3409,14 +3411,6 @@ static int rockchip_interrupts_register(struct platform_device *pdev,
                        continue;
                }
 
-               /*
-                * Linux assumes that all interrupts start out disabled/masked.
-                * Our driver only uses the concept of masked and always keeps
-                * things enabled, so for us that's all masked and all enabled.
-                */
-               writel_relaxed(0xffffffff, bank->reg_base + GPIO_INTMASK);
-               writel_relaxed(0xffffffff, bank->reg_base + GPIO_INTEN);
-
                gc = irq_get_domain_generic_chip(bank->domain, 0);
                gc->reg_base = bank->reg_base;
                gc->private = bank;
@@ -3433,13 +3427,17 @@ static int rockchip_interrupts_register(struct platform_device *pdev,
                gc->chip_types[0].chip.irq_set_type = rockchip_irq_set_type;
                gc->wake_enabled = IRQ_MSK(bank->nr_pins);
 
+               /*
+                * Linux assumes that all interrupts start out disabled/masked.
+                * Our driver only uses the concept of masked and always keeps
+                * things enabled, so for us that's all masked and all enabled.
+                */
+               writel_relaxed(0xffffffff, bank->reg_base + GPIO_INTMASK);
+               writel_relaxed(0xffffffff, bank->reg_base + GPIO_INTEN);
+               gc->mask_cache = 0xffffffff;
+
                irq_set_chained_handler_and_data(bank->irq,
                                                 rockchip_irq_demux, bank);
-
-               /* map the gpio irqs here, when the clock is still running */
-               for (j = 0 ; j < 32 ; j++)
-                       irq_create_mapping(bank->domain, j);
-
                clk_disable(bank->clk);
        }
 
index c4bcda9..77a25bd 100644 (file)
@@ -815,21 +815,14 @@ static void msm_gpio_irq_clear_unmask(struct irq_data *d, bool status_clear)
 
 static void msm_gpio_irq_enable(struct irq_data *d)
 {
-       /*
-        * Clear the interrupt that may be pending before we enable
-        * the line.
-        * This is especially a problem with the GPIOs routed to the
-        * PDC. These GPIOs are direct-connect interrupts to the GIC.
-        * Disabling the interrupt line at the PDC does not prevent
-        * the interrupt from being latched at the GIC. The state at
-        * GIC needs to be cleared before enabling.
-        */
-       if (d->parent_data) {
-               irq_chip_set_parent_state(d, IRQCHIP_STATE_PENDING, 0);
+       struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+       struct msm_pinctrl *pctrl = gpiochip_get_data(gc);
+
+       if (d->parent_data)
                irq_chip_enable_parent(d);
-       }
 
-       msm_gpio_irq_clear_unmask(d, true);
+       if (!test_bit(d->hwirq, pctrl->skip_wake_irqs))
+               msm_gpio_irq_clear_unmask(d, true);
 }
 
 static void msm_gpio_irq_disable(struct irq_data *d)
@@ -1104,6 +1097,19 @@ static int msm_gpio_irq_reqres(struct irq_data *d)
                ret = -EINVAL;
                goto out;
        }
+
+       /*
+        * Clear the interrupt that may be pending before we enable
+        * the line.
+        * This is especially a problem with the GPIOs routed to the
+        * PDC. These GPIOs are direct-connect interrupts to the GIC.
+        * Disabling the interrupt line at the PDC does not prevent
+        * the interrupt from being latched at the GIC. The state at
+        * GIC needs to be cleared before enabling.
+        */
+       if (d->parent_data && test_bit(d->hwirq, pctrl->skip_wake_irqs))
+               irq_chip_set_parent_state(d, IRQCHIP_STATE_PENDING, 0);
+
        return 0;
 out:
        module_put(gc->owner);
index 826df0d..af144e7 100644 (file)
@@ -1313,6 +1313,22 @@ static const struct msm_pingroup sm8250_groups[] = {
        [183] = SDC_PINGROUP(sdc2_data, 0xb7000, 9, 0),
 };
 
+static const struct msm_gpio_wakeirq_map sm8250_pdc_map[] = {
+       { 0, 79 }, { 1, 84 }, { 2, 80 }, { 3, 82 }, { 4, 107 }, { 7, 43 },
+       { 11, 42 }, { 14, 44 }, { 15, 52 }, { 19, 67 }, { 23, 68 }, { 24, 105 },
+       { 27, 92 }, { 28, 106 }, { 31, 69 }, { 35, 70 }, { 39, 37 },
+       { 40, 108 }, { 43, 71 }, { 45, 72 }, { 47, 83 }, { 51, 74 }, { 55, 77 },
+       { 59, 78 }, { 63, 75 }, { 64, 81 }, { 65, 87 }, { 66, 88 }, { 67, 89 },
+       { 68, 54 }, { 70, 85 }, { 77, 46 }, { 80, 90 }, { 81, 91 }, { 83, 97 },
+       { 84, 98 }, { 86, 99 }, { 87, 100 }, { 88, 101 }, { 89, 102 },
+       { 92, 103 }, { 93, 104 }, { 100, 53 }, { 103, 47 }, { 104, 48 },
+       { 108, 49 }, { 109, 94 }, { 110, 95 }, { 111, 96 }, { 112, 55 },
+       { 113, 56 }, { 118, 50 }, { 121, 51 }, { 122, 57 }, { 123, 58 },
+       { 124, 45 }, { 126, 59 }, { 128, 76 }, { 129, 86 }, { 132, 93 },
+       { 133, 65 }, { 134, 66 }, { 136, 62 }, { 137, 63 }, { 138, 64 },
+       { 142, 60 }, { 143, 61 }
+};
+
 static const struct msm_pinctrl_soc_data sm8250_pinctrl = {
        .pins = sm8250_pins,
        .npins = ARRAY_SIZE(sm8250_pins),
@@ -1323,6 +1339,8 @@ static const struct msm_pinctrl_soc_data sm8250_pinctrl = {
        .ngpios = 181,
        .tiles = sm8250_tiles,
        .ntiles = ARRAY_SIZE(sm8250_tiles),
+       .wakeirq_map = sm8250_pdc_map,
+       .nwakeirq_map = ARRAY_SIZE(sm8250_pdc_map),
 };
 
 static int sm8250_pinctrl_probe(struct platform_device *pdev)
index 0b2830e..70d6d52 100644 (file)
@@ -620,7 +620,7 @@ static u64 rapl_unit_xlate(struct rapl_domain *rd, enum unit_type type,
        case ARBITRARY_UNIT:
        default:
                return value;
-       };
+       }
 
        if (to_raw)
                return div64_u64(value, units) * scale;
index f808c5f..3f0b8e2 100644 (file)
@@ -367,9 +367,9 @@ static void create_power_zone_common_attributes(
                                        &dev_attr_max_energy_range_uj.attr;
        if (power_zone->ops->get_energy_uj) {
                if (power_zone->ops->reset_energy_uj)
-                       dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
+                       dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUSR;
                else
-                       dev_attr_energy_uj.attr.mode = S_IRUGO;
+                       dev_attr_energy_uj.attr.mode = S_IRUSR;
                power_zone->zone_dev_attrs[count++] =
                                        &dev_attr_energy_uj.attr;
        }
index a4ffd71..42bbd99 100644 (file)
@@ -1315,7 +1315,6 @@ static int _regulator_do_enable(struct regulator_dev *rdev);
 /**
  * set_machine_constraints - sets regulator constraints
  * @rdev: regulator source
- * @constraints: constraints to apply
  *
  * Allows platform initialisation code to define and constrain
  * regulator circuits e.g. valid voltage/current ranges, etc.  NOTE:
@@ -1323,21 +1322,11 @@ static int _regulator_do_enable(struct regulator_dev *rdev);
  * regulator operations to proceed i.e. set_voltage, set_current_limit,
  * set_mode.
  */
-static int set_machine_constraints(struct regulator_dev *rdev,
-       const struct regulation_constraints *constraints)
+static int set_machine_constraints(struct regulator_dev *rdev)
 {
        int ret = 0;
        const struct regulator_ops *ops = rdev->desc->ops;
 
-       if (constraints)
-               rdev->constraints = kmemdup(constraints, sizeof(*constraints),
-                                           GFP_KERNEL);
-       else
-               rdev->constraints = kzalloc(sizeof(*constraints),
-                                           GFP_KERNEL);
-       if (!rdev->constraints)
-               return -ENOMEM;
-
        ret = machine_constraints_voltage(rdev, rdev->constraints);
        if (ret != 0)
                return ret;
@@ -1852,6 +1841,15 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
                }
        }
 
+       if (r == rdev) {
+               dev_err(dev, "Supply for %s (%s) resolved to itself\n",
+                       rdev->desc->name, rdev->supply_name);
+               if (!have_full_constraints())
+                       return -EINVAL;
+               r = dummy_regulator_rdev;
+               get_device(&r->dev);
+       }
+
        /*
         * If the supply's parent device is not the same as the
         * regulator's parent device, then ensure the parent device
@@ -4165,6 +4163,8 @@ int regulator_get_voltage_rdev(struct regulator_dev *rdev)
                ret = rdev->desc->fixed_uV;
        } else if (rdev->supply) {
                ret = regulator_get_voltage_rdev(rdev->supply->rdev);
+       } else if (rdev->supply_name) {
+               return -EPROBE_DEFER;
        } else {
                return -EINVAL;
        }
@@ -5144,7 +5144,6 @@ struct regulator_dev *
 regulator_register(const struct regulator_desc *regulator_desc,
                   const struct regulator_config *cfg)
 {
-       const struct regulation_constraints *constraints = NULL;
        const struct regulator_init_data *init_data;
        struct regulator_config *config = NULL;
        static atomic_t regulator_no = ATOMIC_INIT(-1);
@@ -5283,14 +5282,23 @@ regulator_register(const struct regulator_desc *regulator_desc,
 
        /* set regulator constraints */
        if (init_data)
-               constraints = &init_data->constraints;
+               rdev->constraints = kmemdup(&init_data->constraints,
+                                           sizeof(*rdev->constraints),
+                                           GFP_KERNEL);
+       else
+               rdev->constraints = kzalloc(sizeof(*rdev->constraints),
+                                           GFP_KERNEL);
+       if (!rdev->constraints) {
+               ret = -ENOMEM;
+               goto wash;
+       }
 
        if (init_data && init_data->supply_regulator)
                rdev->supply_name = init_data->supply_regulator;
        else if (regulator_desc->supply_name)
                rdev->supply_name = regulator_desc->supply_name;
 
-       ret = set_machine_constraints(rdev, constraints);
+       ret = set_machine_constraints(rdev);
        if (ret == -EPROBE_DEFER) {
                /* Regulator might be in bypass mode and so needs its supply
                 * to set the constraints */
@@ -5299,7 +5307,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
                 * that is just being created */
                ret = regulator_resolve_supply(rdev);
                if (!ret)
-                       ret = set_machine_constraints(rdev, constraints);
+                       ret = set_machine_constraints(rdev);
                else
                        rdev_dbg(rdev, "unable to resolve supply early: %pe\n",
                                 ERR_PTR(ret));
@@ -5841,13 +5849,14 @@ static int regulator_late_cleanup(struct device *dev, void *data)
        if (rdev->use_count)
                goto unlock;
 
-       /* If we can't read the status assume it's on. */
+       /* If we can't read the status assume it's always on. */
        if (ops->is_enabled)
                enabled = ops->is_enabled(rdev);
        else
                enabled = 1;
 
-       if (!enabled)
+       /* But if reading the status failed, assume that it's off. */
+       if (enabled <= 0)
                goto unlock;
 
        if (have_full_constraints()) {
index 7e8ba92..01a12cf 100644 (file)
@@ -836,11 +836,14 @@ static int pfuze100_regulator_probe(struct i2c_client *client,
                 * the switched regulator till yet.
                 */
                if (pfuze_chip->flags & PFUZE_FLAG_DISABLE_SW) {
-                       if (pfuze_chip->regulator_descs[i].sw_reg) {
-                               desc->ops = &pfuze100_sw_disable_regulator_ops;
-                               desc->enable_val = 0x8;
-                               desc->disable_val = 0x0;
-                               desc->enable_time = 500;
+                       if (pfuze_chip->chip_id == PFUZE100 ||
+                               pfuze_chip->chip_id == PFUZE200) {
+                               if (pfuze_chip->regulator_descs[i].sw_reg) {
+                                       desc->ops = &pfuze100_sw_disable_regulator_ops;
+                                       desc->enable_val = 0x8;
+                                       desc->disable_val = 0x0;
+                                       desc->enable_time = 500;
+                               }
                        }
                }
 
index 3e60bff..9f0a4d5 100644 (file)
@@ -342,8 +342,17 @@ static int ti_abb_set_voltage_sel(struct regulator_dev *rdev, unsigned sel)
                return ret;
        }
 
-       /* If data is exactly the same, then just update index, no change */
        info = &abb->info[sel];
+       /*
+        * When Linux kernel is starting up, we are'nt sure of the
+        * Bias configuration that bootloader has configured.
+        * So, we get to know the actual setting the first time
+        * we are asked to transition.
+        */
+       if (abb->current_info_idx == -EINVAL)
+               goto just_set_abb;
+
+       /* If data is exactly the same, then just update index, no change */
        oinfo = &abb->info[abb->current_info_idx];
        if (!memcmp(info, oinfo, sizeof(*info))) {
                dev_dbg(dev, "%s: Same data new idx=%d, old idx=%d\n", __func__,
@@ -351,6 +360,7 @@ static int ti_abb_set_voltage_sel(struct regulator_dev *rdev, unsigned sel)
                goto out;
        }
 
+just_set_abb:
        ret = ti_abb_set_opp(rdev, abb, info);
 
 out:
index eb17fea..217a7b8 100644 (file)
@@ -2980,6 +2980,12 @@ static int _dasd_requeue_request(struct dasd_ccw_req *cqr)
 
        if (!block)
                return -EINVAL;
+       /*
+        * If the request is an ERP request there is nothing to requeue.
+        * This will be done with the remaining original request.
+        */
+       if (cqr->refers)
+               return 0;
        spin_lock_irq(&cqr->dq->lock);
        req = (struct request *) cqr->callback_data;
        blk_mq_requeue_request(req, false);
index 485cbfc..ef738b4 100644 (file)
@@ -680,7 +680,10 @@ static int ap_device_probe(struct device *dev)
 {
        struct ap_device *ap_dev = to_ap_dev(dev);
        struct ap_driver *ap_drv = to_ap_drv(dev->driver);
-       int card, queue, devres, drvres, rc;
+       int card, queue, devres, drvres, rc = -ENODEV;
+
+       if (!get_device(dev))
+               return rc;
 
        if (is_queue_dev(dev)) {
                /*
@@ -697,7 +700,7 @@ static int ap_device_probe(struct device *dev)
                mutex_unlock(&ap_perms_mutex);
                drvres = ap_drv->flags & AP_DRIVER_FLAG_DEFAULT;
                if (!!devres != !!drvres)
-                       return -ENODEV;
+                       goto out;
        }
 
        /* Add queue/card to list of active queues/cards */
@@ -718,6 +721,9 @@ static int ap_device_probe(struct device *dev)
                ap_dev->drv = NULL;
        }
 
+out:
+       if (rc)
+               put_device(dev);
        return rc;
 }
 
@@ -744,6 +750,8 @@ static int ap_device_remove(struct device *dev)
                hash_del(&to_ap_queue(dev)->hnode);
        spin_unlock_bh(&ap_queues_lock);
 
+       put_device(dev);
+
        return 0;
 }
 
@@ -1371,6 +1379,8 @@ static inline void ap_scan_domains(struct ap_card *ac)
                                            __func__, ac->id, dom);
                                goto put_dev_and_continue;
                        }
+                       /* get it and thus adjust reference counter */
+                       get_device(dev);
                        if (decfg)
                                AP_DBF_INFO("%s(%d,%d) new (decfg) queue device created\n",
                                            __func__, ac->id, dom);
index 99cb60e..dd84995 100644 (file)
@@ -35,9 +35,6 @@ MODULE_DESCRIPTION("s390 protected key interface");
 #define PROTKEYBLOBBUFSIZE 256 /* protected key buffer size used internal */
 #define MAXAPQNSINLIST 64      /* max 64 apqns within a apqn list */
 
-/* mask of available pckmo subfunctions, fetched once at module init */
-static cpacf_mask_t pckmo_functions;
-
 /*
  * debug feature data and functions
  */
@@ -91,6 +88,9 @@ static int pkey_clr2protkey(u32 keytype,
                            const struct pkey_clrkey *clrkey,
                            struct pkey_protkey *protkey)
 {
+       /* mask of available pckmo subfunctions */
+       static cpacf_mask_t pckmo_functions;
+
        long fc;
        int keysize;
        u8 paramblock[64];
@@ -114,11 +114,13 @@ static int pkey_clr2protkey(u32 keytype,
                return -EINVAL;
        }
 
-       /*
-        * Check if the needed pckmo subfunction is available.
-        * These subfunctions can be enabled/disabled by customers
-        * in the LPAR profile or may even change on the fly.
-        */
+       /* Did we already check for PCKMO ? */
+       if (!pckmo_functions.bytes[0]) {
+               /* no, so check now */
+               if (!cpacf_query(CPACF_PCKMO, &pckmo_functions))
+                       return -ENODEV;
+       }
+       /* check for the pckmo subfunction we need now */
        if (!cpacf_test_func(&pckmo_functions, fc)) {
                DEBUG_ERR("%s pckmo functions not available\n", __func__);
                return -ENODEV;
@@ -2058,7 +2060,7 @@ static struct miscdevice pkey_dev = {
  */
 static int __init pkey_init(void)
 {
-       cpacf_mask_t kmc_functions;
+       cpacf_mask_t func_mask;
 
        /*
         * The pckmo instruction should be available - even if we don't
@@ -2066,15 +2068,15 @@ static int __init pkey_init(void)
         * is also the minimum level for the kmc instructions which
         * are able to work with protected keys.
         */
-       if (!cpacf_query(CPACF_PCKMO, &pckmo_functions))
+       if (!cpacf_query(CPACF_PCKMO, &func_mask))
                return -ENODEV;
 
        /* check for kmc instructions available */
-       if (!cpacf_query(CPACF_KMC, &kmc_functions))
+       if (!cpacf_query(CPACF_KMC, &func_mask))
                return -ENODEV;
-       if (!cpacf_test_func(&kmc_functions, CPACF_KMC_PAES_128) ||
-           !cpacf_test_func(&kmc_functions, CPACF_KMC_PAES_192) ||
-           !cpacf_test_func(&kmc_functions, CPACF_KMC_PAES_256))
+       if (!cpacf_test_func(&func_mask, CPACF_KMC_PAES_128) ||
+           !cpacf_test_func(&func_mask, CPACF_KMC_PAES_192) ||
+           !cpacf_test_func(&func_mask, CPACF_KMC_PAES_256))
                return -ENODEV;
 
        pkey_debug_init();
index e342eb8..33b2388 100644 (file)
@@ -157,11 +157,6 @@ int zcrypt_card_register(struct zcrypt_card *zc)
 {
        int rc;
 
-       rc = sysfs_create_group(&zc->card->ap_dev.device.kobj,
-                               &zcrypt_card_attr_group);
-       if (rc)
-               return rc;
-
        spin_lock(&zcrypt_list_lock);
        list_add_tail(&zc->list, &zcrypt_card_list);
        spin_unlock(&zcrypt_list_lock);
@@ -170,6 +165,14 @@ int zcrypt_card_register(struct zcrypt_card *zc)
 
        ZCRYPT_DBF(DBF_INFO, "card=%02x register online=1\n", zc->card->id);
 
+       rc = sysfs_create_group(&zc->card->ap_dev.device.kobj,
+                               &zcrypt_card_attr_group);
+       if (rc) {
+               spin_lock(&zcrypt_list_lock);
+               list_del_init(&zc->list);
+               spin_unlock(&zcrypt_list_lock);
+       }
+
        return rc;
 }
 EXPORT_SYMBOL(zcrypt_card_register);
index 3c20706..5062eae 100644 (file)
@@ -180,7 +180,6 @@ int zcrypt_queue_register(struct zcrypt_queue *zq)
                                &zcrypt_queue_attr_group);
        if (rc)
                goto out;
-       get_device(&zq->queue->ap_dev.device);
 
        if (zq->ops->rng) {
                rc = zcrypt_rng_device_add();
@@ -192,7 +191,6 @@ int zcrypt_queue_register(struct zcrypt_queue *zq)
 out_unregister:
        sysfs_remove_group(&zq->queue->ap_dev.device.kobj,
                           &zcrypt_queue_attr_group);
-       put_device(&zq->queue->ap_dev.device);
 out:
        spin_lock(&zcrypt_list_lock);
        list_del_init(&zq->list);
@@ -220,12 +218,10 @@ void zcrypt_queue_unregister(struct zcrypt_queue *zq)
        list_del_init(&zq->list);
        zcrypt_device_count--;
        spin_unlock(&zcrypt_list_lock);
-       zcrypt_card_put(zc);
        if (zq->ops->rng)
                zcrypt_rng_device_remove();
        sysfs_remove_group(&zq->queue->ap_dev.device.kobj,
                           &zcrypt_queue_attr_group);
-       put_device(&zq->queue->ap_dev.device);
-       zcrypt_queue_put(zq);
+       zcrypt_card_put(zc);
 }
 EXPORT_SYMBOL(zcrypt_queue_unregister);
index f32da0c..308bda2 100644 (file)
@@ -658,8 +658,8 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
                                        rcu_read_lock();
                                        list_for_each_entry_rcu(h,
                                                &tmp_pg->dh_list, node) {
-                                               /* h->sdev should always be valid */
-                                               BUG_ON(!h->sdev);
+                                               if (!h->sdev)
+                                                       continue;
                                                h->sdev->access_state = desc[0];
                                        }
                                        rcu_read_unlock();
@@ -705,7 +705,8 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
                        pg->expiry = 0;
                        rcu_read_lock();
                        list_for_each_entry_rcu(h, &pg->dh_list, node) {
-                               BUG_ON(!h->sdev);
+                               if (!h->sdev)
+                                       continue;
                                h->sdev->access_state =
                                        (pg->state & SCSI_ACCESS_STATE_MASK);
                                if (pg->pref)
@@ -1147,7 +1148,6 @@ static void alua_bus_detach(struct scsi_device *sdev)
        spin_lock(&h->pg_lock);
        pg = rcu_dereference_protected(h->pg, lockdep_is_held(&h->pg_lock));
        rcu_assign_pointer(h->pg, NULL);
-       h->sdev = NULL;
        spin_unlock(&h->pg_lock);
        if (pg) {
                spin_lock_irq(&pg->lock);
@@ -1156,6 +1156,7 @@ static void alua_bus_detach(struct scsi_device *sdev)
                kref_put(&pg->kref, release_port_group);
        }
        sdev->handler_data = NULL;
+       synchronize_rcu();
        kfree(h);
 }
 
index 83ce4f1..8df70c9 100644 (file)
@@ -8855,7 +8855,7 @@ reinit_after_soft_reset:
        /* hook into SCSI subsystem */
        rc = hpsa_scsi_add_host(h);
        if (rc)
-               goto clean7; /* perf, sg, cmd, irq, shost, pci, lu, aer/h */
+               goto clean8; /* lastlogicals, perf, sg, cmd, irq, shost, pci, lu, aer/h */
 
        /* Monitor the controller for firmware lockups */
        h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL;
@@ -8870,6 +8870,8 @@ reinit_after_soft_reset:
                                HPSA_EVENT_MONITOR_INTERVAL);
        return 0;
 
+clean8: /* lastlogicals, perf, sg, cmd, irq, shost, pci, lu, aer/h */
+       kfree(h->lastlogicals);
 clean7: /* perf, sg, cmd, irq, shost, pci, lu, aer/h */
        hpsa_free_performant_mode(h);
        h->access.set_intr_mask(h, HPSA_INTR_OFF);
index 1e9c317..f9314f1 100644 (file)
@@ -533,8 +533,8 @@ static void iscsi_complete_task(struct iscsi_task *task, int state)
        if (conn->task == task)
                conn->task = NULL;
 
-       if (conn->ping_task == task)
-               conn->ping_task = NULL;
+       if (READ_ONCE(conn->ping_task) == task)
+               WRITE_ONCE(conn->ping_task, NULL);
 
        /* release get from queueing */
        __iscsi_put_task(task);
@@ -738,6 +738,9 @@ __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
                                                   task->conn->session->age);
        }
 
+       if (unlikely(READ_ONCE(conn->ping_task) == INVALID_SCSI_TASK))
+               WRITE_ONCE(conn->ping_task, task);
+
        if (!ihost->workq) {
                if (iscsi_prep_mgmt_task(conn, task))
                        goto free_task;
@@ -941,8 +944,11 @@ static int iscsi_send_nopout(struct iscsi_conn *conn, struct iscsi_nopin *rhdr)
         struct iscsi_nopout hdr;
        struct iscsi_task *task;
 
-       if (!rhdr && conn->ping_task)
-               return -EINVAL;
+       if (!rhdr) {
+               if (READ_ONCE(conn->ping_task))
+                       return -EINVAL;
+               WRITE_ONCE(conn->ping_task, INVALID_SCSI_TASK);
+       }
 
        memset(&hdr, 0, sizeof(struct iscsi_nopout));
        hdr.opcode = ISCSI_OP_NOOP_OUT | ISCSI_OP_IMMEDIATE;
@@ -957,11 +963,12 @@ static int iscsi_send_nopout(struct iscsi_conn *conn, struct iscsi_nopin *rhdr)
 
        task = __iscsi_conn_send_pdu(conn, (struct iscsi_hdr *)&hdr, NULL, 0);
        if (!task) {
+               if (!rhdr)
+                       WRITE_ONCE(conn->ping_task, NULL);
                iscsi_conn_printk(KERN_ERR, conn, "Could not send nopout\n");
                return -EIO;
        } else if (!rhdr) {
                /* only track our nops */
-               conn->ping_task = task;
                conn->last_ping = jiffies;
        }
 
@@ -984,7 +991,7 @@ static int iscsi_nop_out_rsp(struct iscsi_task *task,
        struct iscsi_conn *conn = task->conn;
        int rc = 0;
 
-       if (conn->ping_task != task) {
+       if (READ_ONCE(conn->ping_task) != task) {
                /*
                 * If this is not in response to one of our
                 * nops then it must be from userspace.
@@ -1923,7 +1930,7 @@ static void iscsi_start_tx(struct iscsi_conn *conn)
  */
 static int iscsi_has_ping_timed_out(struct iscsi_conn *conn)
 {
-       if (conn->ping_task &&
+       if (READ_ONCE(conn->ping_task) &&
            time_before_eq(conn->last_recv + (conn->recv_timeout * HZ) +
                           (conn->ping_timeout * HZ), jiffies))
                return 1;
@@ -2058,7 +2065,7 @@ enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc)
         * Checking the transport already or nop from a cmd timeout still
         * running
         */
-       if (conn->ping_task) {
+       if (READ_ONCE(conn->ping_task)) {
                task->have_checked_conn = true;
                rc = BLK_EH_RESET_TIMER;
                goto done;
index 93230cd..e4cc92b 100644 (file)
@@ -1740,6 +1740,13 @@ _base_irqpoll(struct irq_poll *irqpoll, int budget)
                reply_q->irq_poll_scheduled = false;
                reply_q->irq_line_enable = true;
                enable_irq(reply_q->os_irq);
+               /*
+                * Go for one more round of processing the
+                * reply descriptor post queue incase if HBA
+                * Firmware has posted some reply descriptors
+                * while reenabling the IRQ.
+                */
+               _base_process_reply_queue(reply_q);
        }
 
        return num_entries;
index b8f573a..7a160b8 100644 (file)
@@ -1627,12 +1627,12 @@ start:
                 */
                fallthrough;
        case CLKS_OFF:
-               ufshcd_scsi_block_requests(hba);
                hba->clk_gating.state = REQ_CLKS_ON;
                trace_ufshcd_clk_gating(dev_name(hba->dev),
                                        hba->clk_gating.state);
-               queue_work(hba->clk_gating.clk_gating_workq,
-                          &hba->clk_gating.ungate_work);
+               if (queue_work(hba->clk_gating.clk_gating_workq,
+                              &hba->clk_gating.ungate_work))
+                       ufshcd_scsi_block_requests(hba);
                /*
                 * fall through to check if we should wait for this
                 * work to be done or not.
@@ -2115,10 +2115,20 @@ ufshcd_wait_for_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd)
        unsigned long flags;
 
        if (wait_for_completion_timeout(&uic_cmd->done,
-                                       msecs_to_jiffies(UIC_CMD_TIMEOUT)))
+                                       msecs_to_jiffies(UIC_CMD_TIMEOUT))) {
                ret = uic_cmd->argument2 & MASK_UIC_COMMAND_RESULT;
-       else
+       } else {
                ret = -ETIMEDOUT;
+               dev_err(hba->dev,
+                       "uic cmd 0x%x with arg3 0x%x completion timeout\n",
+                       uic_cmd->command, uic_cmd->argument3);
+
+               if (!uic_cmd->cmd_active) {
+                       dev_err(hba->dev, "%s: UIC cmd has been completed, return the result\n",
+                               __func__);
+                       ret = uic_cmd->argument2 & MASK_UIC_COMMAND_RESULT;
+               }
+       }
 
        spin_lock_irqsave(hba->host->host_lock, flags);
        hba->active_uic_cmd = NULL;
@@ -2150,6 +2160,7 @@ __ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd,
        if (completion)
                init_completion(&uic_cmd->done);
 
+       uic_cmd->cmd_active = 1;
        ufshcd_dispatch_uic_cmd(hba, uic_cmd);
 
        return 0;
@@ -3807,10 +3818,18 @@ static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd)
                dev_err(hba->dev,
                        "pwr ctrl cmd 0x%x with mode 0x%x completion timeout\n",
                        cmd->command, cmd->argument3);
+
+               if (!cmd->cmd_active) {
+                       dev_err(hba->dev, "%s: Power Mode Change operation has been completed, go check UPMCRS\n",
+                               __func__);
+                       goto check_upmcrs;
+               }
+
                ret = -ETIMEDOUT;
                goto out;
        }
 
+check_upmcrs:
        status = ufshcd_get_upmcrs(hba);
        if (status != PWR_LOCAL) {
                dev_err(hba->dev,
@@ -4902,11 +4921,14 @@ static irqreturn_t ufshcd_uic_cmd_compl(struct ufs_hba *hba, u32 intr_status)
                        ufshcd_get_uic_cmd_result(hba);
                hba->active_uic_cmd->argument3 =
                        ufshcd_get_dme_attr_val(hba);
+               if (!hba->uic_async_done)
+                       hba->active_uic_cmd->cmd_active = 0;
                complete(&hba->active_uic_cmd->done);
                retval = IRQ_HANDLED;
        }
 
        if ((intr_status & UFSHCD_UIC_PWR_MASK) && hba->uic_async_done) {
+               hba->active_uic_cmd->cmd_active = 0;
                complete(hba->uic_async_done);
                retval = IRQ_HANDLED;
        }
@@ -8906,6 +8928,7 @@ void ufshcd_remove(struct ufs_hba *hba)
        blk_mq_free_tag_set(&hba->tmf_tag_set);
        blk_cleanup_queue(hba->cmd_queue);
        scsi_remove_host(hba->host);
+       destroy_workqueue(hba->eh_wq);
        /* disable interrupts */
        ufshcd_disable_intr(hba, hba->intr_mask);
        ufshcd_hba_stop(hba);
@@ -9206,6 +9229,7 @@ out_remove_scsi_host:
 exit_gating:
        ufshcd_exit_clk_scaling(hba);
        ufshcd_exit_clk_gating(hba);
+       destroy_workqueue(hba->eh_wq);
 out_disable:
        hba->is_irq_enabled = false;
        ufshcd_hba_exit(hba);
index 47eb143..e0f00a4 100644 (file)
@@ -64,6 +64,7 @@ enum dev_cmd_type {
  * @argument1: UIC command argument 1
  * @argument2: UIC command argument 2
  * @argument3: UIC command argument 3
+ * @cmd_active: Indicate if UIC command is outstanding
  * @done: UIC command completion
  */
 struct uic_command {
@@ -71,6 +72,7 @@ struct uic_command {
        u32 argument1;
        u32 argument2;
        u32 argument3;
+       int cmd_active;
        struct completion done;
 };
 
index 14c9d01..c028446 100644 (file)
@@ -1327,7 +1327,7 @@ int bcm_qspi_probe(struct platform_device *pdev,
 
        data = of_id->data;
 
-       master = spi_alloc_master(dev, sizeof(struct bcm_qspi));
+       master = devm_spi_alloc_master(dev, sizeof(struct bcm_qspi));
        if (!master) {
                dev_err(dev, "error allocating spi_master\n");
                return -ENOMEM;
@@ -1367,21 +1367,17 @@ int bcm_qspi_probe(struct platform_device *pdev,
 
        if (res) {
                qspi->base[MSPI]  = devm_ioremap_resource(dev, res);
-               if (IS_ERR(qspi->base[MSPI])) {
-                       ret = PTR_ERR(qspi->base[MSPI]);
-                       goto qspi_resource_err;
-               }
+               if (IS_ERR(qspi->base[MSPI]))
+                       return PTR_ERR(qspi->base[MSPI]);
        } else {
-               goto qspi_resource_err;
+               return 0;
        }
 
        res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "bspi");
        if (res) {
                qspi->base[BSPI]  = devm_ioremap_resource(dev, res);
-               if (IS_ERR(qspi->base[BSPI])) {
-                       ret = PTR_ERR(qspi->base[BSPI]);
-                       goto qspi_resource_err;
-               }
+               if (IS_ERR(qspi->base[BSPI]))
+                       return PTR_ERR(qspi->base[BSPI]);
                qspi->bspi_mode = true;
        } else {
                qspi->bspi_mode = false;
@@ -1392,18 +1388,14 @@ int bcm_qspi_probe(struct platform_device *pdev,
        res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cs_reg");
        if (res) {
                qspi->base[CHIP_SELECT]  = devm_ioremap_resource(dev, res);
-               if (IS_ERR(qspi->base[CHIP_SELECT])) {
-                       ret = PTR_ERR(qspi->base[CHIP_SELECT]);
-                       goto qspi_resource_err;
-               }
+               if (IS_ERR(qspi->base[CHIP_SELECT]))
+                       return PTR_ERR(qspi->base[CHIP_SELECT]);
        }
 
        qspi->dev_ids = kcalloc(num_irqs, sizeof(struct bcm_qspi_dev_id),
                                GFP_KERNEL);
-       if (!qspi->dev_ids) {
-               ret = -ENOMEM;
-               goto qspi_resource_err;
-       }
+       if (!qspi->dev_ids)
+               return -ENOMEM;
 
        for (val = 0; val < num_irqs; val++) {
                irq = -1;
@@ -1484,7 +1476,7 @@ int bcm_qspi_probe(struct platform_device *pdev,
        qspi->xfer_mode.addrlen = -1;
        qspi->xfer_mode.hp = -1;
 
-       ret = devm_spi_register_master(&pdev->dev, master);
+       ret = spi_register_master(master);
        if (ret < 0) {
                dev_err(dev, "can't register master\n");
                goto qspi_reg_err;
@@ -1497,8 +1489,6 @@ qspi_reg_err:
        clk_disable_unprepare(qspi->clk);
 qspi_probe_err:
        kfree(qspi->dev_ids);
-qspi_resource_err:
-       spi_master_put(master);
        return ret;
 }
 /* probe function to be called by SoC specific platform driver probe */
@@ -1508,10 +1498,10 @@ int bcm_qspi_remove(struct platform_device *pdev)
 {
        struct bcm_qspi *qspi = platform_get_drvdata(pdev);
 
+       spi_unregister_master(qspi->master);
        bcm_qspi_hw_uninit(qspi);
        clk_disable_unprepare(qspi->clk);
        kfree(qspi->dev_ids);
-       spi_unregister_master(qspi->master);
 
        return 0;
 }
index b87116e..197485f 100644 (file)
@@ -1193,7 +1193,6 @@ static int bcm2835_spi_setup(struct spi_device *spi)
        struct spi_controller *ctlr = spi->controller;
        struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);
        struct gpio_chip *chip;
-       enum gpio_lookup_flags lflags;
        u32 cs;
 
        /*
@@ -1259,21 +1258,9 @@ static int bcm2835_spi_setup(struct spi_device *spi)
        if (!chip)
                return 0;
 
-       /*
-        * Retrieve the corresponding GPIO line used for CS.
-        * The inversion semantics will be handled by the GPIO core
-        * code, so we pass GPIOD_OUT_LOW for "unasserted" and
-        * the correct flag for inversion semantics. The SPI_CS_HIGH
-        * on spi->mode cannot be checked for polarity in this case
-        * as the flag use_gpio_descriptors enforces SPI_CS_HIGH.
-        */
-       if (of_property_read_bool(spi->dev.of_node, "spi-cs-high"))
-               lflags = GPIO_ACTIVE_HIGH;
-       else
-               lflags = GPIO_ACTIVE_LOW;
        spi->cs_gpiod = gpiochip_request_own_desc(chip, 8 - spi->chip_select,
                                                  DRV_NAME,
-                                                 lflags,
+                                                 GPIO_LOOKUP_FLAGS_DEFAULT,
                                                  GPIOD_OUT_LOW);
        if (IS_ERR(spi->cs_gpiod))
                return PTR_ERR(spi->cs_gpiod);
@@ -1291,7 +1278,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
        struct bcm2835_spi *bs;
        int err;
 
-       ctlr = spi_alloc_master(&pdev->dev, ALIGN(sizeof(*bs),
+       ctlr = devm_spi_alloc_master(&pdev->dev, ALIGN(sizeof(*bs),
                                                  dma_get_cache_alignment()));
        if (!ctlr)
                return -ENOMEM;
@@ -1312,23 +1299,17 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
        bs->ctlr = ctlr;
 
        bs->regs = devm_platform_ioremap_resource(pdev, 0);
-       if (IS_ERR(bs->regs)) {
-               err = PTR_ERR(bs->regs);
-               goto out_controller_put;
-       }
+       if (IS_ERR(bs->regs))
+               return PTR_ERR(bs->regs);
 
        bs->clk = devm_clk_get(&pdev->dev, NULL);
-       if (IS_ERR(bs->clk)) {
-               err = dev_err_probe(&pdev->dev, PTR_ERR(bs->clk),
-                                   "could not get clk\n");
-               goto out_controller_put;
-       }
+       if (IS_ERR(bs->clk))
+               return dev_err_probe(&pdev->dev, PTR_ERR(bs->clk),
+                                    "could not get clk\n");
 
        bs->irq = platform_get_irq(pdev, 0);
-       if (bs->irq <= 0) {
-               err = bs->irq ? bs->irq : -ENODEV;
-               goto out_controller_put;
-       }
+       if (bs->irq <= 0)
+               return bs->irq ? bs->irq : -ENODEV;
 
        clk_prepare_enable(bs->clk);
 
@@ -1362,8 +1343,6 @@ out_dma_release:
        bcm2835_dma_release(ctlr, bs);
 out_clk_disable:
        clk_disable_unprepare(bs->clk);
-out_controller_put:
-       spi_controller_put(ctlr);
        return err;
 }
 
index 03b034c..1a26865 100644 (file)
@@ -494,7 +494,7 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev)
        unsigned long clk_hz;
        int err;
 
-       master = spi_alloc_master(&pdev->dev, sizeof(*bs));
+       master = devm_spi_alloc_master(&pdev->dev, sizeof(*bs));
        if (!master)
                return -ENOMEM;
 
@@ -524,29 +524,25 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev)
 
        /* the main area */
        bs->regs = devm_platform_ioremap_resource(pdev, 0);
-       if (IS_ERR(bs->regs)) {
-               err = PTR_ERR(bs->regs);
-               goto out_master_put;
-       }
+       if (IS_ERR(bs->regs))
+               return PTR_ERR(bs->regs);
 
        bs->clk = devm_clk_get(&pdev->dev, NULL);
        if (IS_ERR(bs->clk)) {
                err = PTR_ERR(bs->clk);
                dev_err(&pdev->dev, "could not get clk: %d\n", err);
-               goto out_master_put;
+               return err;
        }
 
        bs->irq = platform_get_irq(pdev, 0);
-       if (bs->irq <= 0) {
-               err = bs->irq ? bs->irq : -ENODEV;
-               goto out_master_put;
-       }
+       if (bs->irq <= 0)
+               return bs->irq ? bs->irq : -ENODEV;
 
        /* this also enables the HW block */
        err = clk_prepare_enable(bs->clk);
        if (err) {
                dev_err(&pdev->dev, "could not prepare clock: %d\n", err);
-               goto out_master_put;
+               return err;
        }
 
        /* just checking if the clock returns a sane value */
@@ -581,8 +577,6 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev)
 
 out_clk_disable:
        clk_disable_unprepare(bs->clk);
-out_master_put:
-       spi_master_put(master);
        return err;
 }
 
index 40938cf..ba7d40c 100644 (file)
@@ -1260,12 +1260,14 @@ static int cqspi_probe(struct platform_device *pdev)
        /* Obtain QSPI reset control */
        rstc = devm_reset_control_get_optional_exclusive(dev, "qspi");
        if (IS_ERR(rstc)) {
+               ret = PTR_ERR(rstc);
                dev_err(dev, "Cannot get QSPI reset.\n");
                goto probe_reset_failed;
        }
 
        rstc_ocp = devm_reset_control_get_optional_exclusive(dev, "qspi-ocp");
        if (IS_ERR(rstc_ocp)) {
+               ret = PTR_ERR(rstc_ocp);
                dev_err(dev, "Cannot get QSPI OCP reset.\n");
                goto probe_reset_failed;
        }
index 2e50cc0..0b2236a 100644 (file)
@@ -357,11 +357,11 @@ static void dw_spi_irq_setup(struct dw_spi *dws)
        dw_writel(dws, DW_SPI_TXFTLR, level);
        dw_writel(dws, DW_SPI_RXFTLR, level - 1);
 
+       dws->transfer_handler = dw_spi_transfer_handler;
+
        imask = SPI_INT_TXEI | SPI_INT_TXOI | SPI_INT_RXUI | SPI_INT_RXOI |
                SPI_INT_RXFI;
        spi_umask_intr(dws, imask);
-
-       dws->transfer_handler = dw_spi_transfer_handler;
 }
 
 /*
index 8a440c7..3920cd3 100644 (file)
@@ -477,7 +477,7 @@ static int fsi_spi_transfer_one_message(struct spi_controller *ctlr,
 
        rc = fsi_spi_check_mux(ctx->fsi, ctx->dev);
        if (rc)
-               return rc;
+               goto error;
 
        list_for_each_entry(transfer, &mesg->transfers, transfer_list) {
                struct fsi_spi_sequence seq;
index 3967afa..1a08c1d 100644 (file)
@@ -1080,12 +1080,11 @@ MODULE_DEVICE_TABLE(of, fsl_dspi_dt_ids);
 #ifdef CONFIG_PM_SLEEP
 static int dspi_suspend(struct device *dev)
 {
-       struct spi_controller *ctlr = dev_get_drvdata(dev);
-       struct fsl_dspi *dspi = spi_controller_get_devdata(ctlr);
+       struct fsl_dspi *dspi = dev_get_drvdata(dev);
 
        if (dspi->irq)
                disable_irq(dspi->irq);
-       spi_controller_suspend(ctlr);
+       spi_controller_suspend(dspi->ctlr);
        clk_disable_unprepare(dspi->clk);
 
        pinctrl_pm_select_sleep_state(dev);
@@ -1095,8 +1094,7 @@ static int dspi_suspend(struct device *dev)
 
 static int dspi_resume(struct device *dev)
 {
-       struct spi_controller *ctlr = dev_get_drvdata(dev);
-       struct fsl_dspi *dspi = spi_controller_get_devdata(ctlr);
+       struct fsl_dspi *dspi = dev_get_drvdata(dev);
        int ret;
 
        pinctrl_pm_select_default_state(dev);
@@ -1104,7 +1102,7 @@ static int dspi_resume(struct device *dev)
        ret = clk_prepare_enable(dspi->clk);
        if (ret)
                return ret;
-       spi_controller_resume(ctlr);
+       spi_controller_resume(dspi->ctlr);
        if (dspi->irq)
                enable_irq(dspi->irq);
 
index 986b979..a2886ee 100644 (file)
@@ -938,9 +938,6 @@ static int fsl_lpspi_remove(struct platform_device *pdev)
                                spi_controller_get_devdata(controller);
 
        pm_runtime_disable(fsl_lpspi->dev);
-
-       spi_master_put(controller);
-
        return 0;
 }
 
index 060b1f5..4b80e27 100644 (file)
@@ -1676,15 +1676,18 @@ static int spi_imx_probe(struct platform_device *pdev)
                goto out_master_put;
        }
 
-       pm_runtime_enable(spi_imx->dev);
+       ret = clk_prepare_enable(spi_imx->clk_per);
+       if (ret)
+               goto out_master_put;
+
+       ret = clk_prepare_enable(spi_imx->clk_ipg);
+       if (ret)
+               goto out_put_per;
+
        pm_runtime_set_autosuspend_delay(spi_imx->dev, MXC_RPM_TIMEOUT);
        pm_runtime_use_autosuspend(spi_imx->dev);
-
-       ret = pm_runtime_get_sync(spi_imx->dev);
-       if (ret < 0) {
-               dev_err(spi_imx->dev, "failed to enable clock\n");
-               goto out_runtime_pm_put;
-       }
+       pm_runtime_set_active(spi_imx->dev);
+       pm_runtime_enable(spi_imx->dev);
 
        spi_imx->spi_clk = clk_get_rate(spi_imx->clk_per);
        /*
@@ -1722,8 +1725,12 @@ out_bitbang_start:
                spi_imx_sdma_exit(spi_imx);
 out_runtime_pm_put:
        pm_runtime_dont_use_autosuspend(spi_imx->dev);
-       pm_runtime_put_sync(spi_imx->dev);
+       pm_runtime_set_suspended(&pdev->dev);
        pm_runtime_disable(spi_imx->dev);
+
+       clk_disable_unprepare(spi_imx->clk_ipg);
+out_put_per:
+       clk_disable_unprepare(spi_imx->clk_per);
 out_master_put:
        spi_master_put(master);
 
index 341f7cf..1cb9329 100644 (file)
@@ -679,7 +679,7 @@ static int npcm_fiu_probe(struct platform_device *pdev)
        struct resource *res;
        int id;
 
-       ctrl = spi_alloc_master(dev, sizeof(*fiu));
+       ctrl = devm_spi_alloc_master(dev, sizeof(*fiu));
        if (!ctrl)
                return -ENOMEM;
 
index 0cab239..05c75f8 100644 (file)
@@ -812,18 +812,16 @@ static void spi_set_cs(struct spi_device *spi, bool enable)
                enable = !enable;
 
        if (spi->cs_gpiod || gpio_is_valid(spi->cs_gpio)) {
-               /*
-                * Honour the SPI_NO_CS flag and invert the enable line, as
-                * active low is default for SPI. Execution paths that handle
-                * polarity inversion in gpiolib (such as device tree) will
-                * enforce active high using the SPI_CS_HIGH resulting in a
-                * double inversion through the code above.
-                */
                if (!(spi->mode & SPI_NO_CS)) {
                        if (spi->cs_gpiod)
+                               /* polarity handled by gpiolib */
                                gpiod_set_value_cansleep(spi->cs_gpiod,
-                                                        !enable);
+                                                        enable1);
                        else
+                               /*
+                                * invert the enable line, as active low is
+                                * default for SPI.
+                                */
                                gpio_set_value_cansleep(spi->cs_gpio, !enable);
                }
                /* Some SPI masters need both GPIO CS & slave_select */
@@ -1992,15 +1990,6 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
        }
        spi->chip_select = value;
 
-       /*
-        * For descriptors associated with the device, polarity inversion is
-        * handled in the gpiolib, so all gpio chip selects are "active high"
-        * in the logical sense, the gpiolib will invert the line if need be.
-        */
-       if ((ctlr->use_gpio_descriptors) && ctlr->cs_gpiods &&
-           ctlr->cs_gpiods[spi->chip_select])
-               spi->mode |= SPI_CS_HIGH;
-
        /* Device speed */
        if (!of_property_read_u32(nc, "spi-max-frequency", &value))
                spi->max_speed_hz = value;
@@ -2453,6 +2442,49 @@ struct spi_controller *__spi_alloc_controller(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(__spi_alloc_controller);
 
+static void devm_spi_release_controller(struct device *dev, void *ctlr)
+{
+       spi_controller_put(*(struct spi_controller **)ctlr);
+}
+
+/**
+ * __devm_spi_alloc_controller - resource-managed __spi_alloc_controller()
+ * @dev: physical device of SPI controller
+ * @size: how much zeroed driver-private data to allocate
+ * @slave: whether to allocate an SPI master (false) or SPI slave (true)
+ * Context: can sleep
+ *
+ * Allocate an SPI controller and automatically release a reference on it
+ * when @dev is unbound from its driver.  Drivers are thus relieved from
+ * having to call spi_controller_put().
+ *
+ * The arguments to this function are identical to __spi_alloc_controller().
+ *
+ * Return: the SPI controller structure on success, else NULL.
+ */
+struct spi_controller *__devm_spi_alloc_controller(struct device *dev,
+                                                  unsigned int size,
+                                                  bool slave)
+{
+       struct spi_controller **ptr, *ctlr;
+
+       ptr = devres_alloc(devm_spi_release_controller, sizeof(*ptr),
+                          GFP_KERNEL);
+       if (!ptr)
+               return NULL;
+
+       ctlr = __spi_alloc_controller(dev, size, slave);
+       if (ctlr) {
+               *ptr = ctlr;
+               devres_add(dev, ptr);
+       } else {
+               devres_free(ptr);
+       }
+
+       return ctlr;
+}
+EXPORT_SYMBOL_GPL(__devm_spi_alloc_controller);
+
 #ifdef CONFIG_OF
 static int of_spi_get_gpio_numbers(struct spi_controller *ctlr)
 {
@@ -2789,6 +2821,11 @@ int devm_spi_register_controller(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(devm_spi_register_controller);
 
+static int devm_spi_match_controller(struct device *dev, void *res, void *ctlr)
+{
+       return *(struct spi_controller **)res == ctlr;
+}
+
 static int __unregister(struct device *dev, void *null)
 {
        spi_unregister_device(to_spi_device(dev));
@@ -2830,7 +2867,15 @@ void spi_unregister_controller(struct spi_controller *ctlr)
        list_del(&ctlr->list);
        mutex_unlock(&board_lock);
 
-       device_unregister(&ctlr->dev);
+       device_del(&ctlr->dev);
+
+       /* Release the last reference on the controller if its driver
+        * has not yet been converted to devm_spi_alloc_master/slave().
+        */
+       if (!devres_find(ctlr->dev.parent, devm_spi_release_controller,
+                        devm_spi_match_controller, ctlr))
+               put_device(&ctlr->dev);
+
        /* free bus id */
        mutex_lock(&board_lock);
        if (found == ctlr)
index f961b35..8831db3 100644 (file)
@@ -653,16 +653,11 @@ static int mt7621_pcie_init_virtual_bridges(struct mt7621_pcie *pcie)
        return 0;
 }
 
-static int mt7621_pcie_request_resources(struct mt7621_pcie *pcie,
-                                        struct list_head *res)
+static void mt7621_pcie_add_resources(struct mt7621_pcie *pcie,
+                                     struct list_head *res)
 {
-       struct device *dev = pcie->dev;
-
        pci_add_resource_offset(res, &pcie->io, pcie->offset.io);
        pci_add_resource_offset(res, &pcie->mem, pcie->offset.mem);
-       pci_add_resource(res, &pcie->busn);
-
-       return devm_request_pci_bus_resources(dev, res);
 }
 
 static int mt7621_pcie_register_host(struct pci_host_bridge *host,
@@ -738,11 +733,7 @@ static int mt7621_pci_probe(struct platform_device *pdev)
 
        setup_cm_memory_region(pcie);
 
-       err = mt7621_pcie_request_resources(pcie, &res);
-       if (err) {
-               dev_err(dev, "Error requesting resources\n");
-               return err;
-       }
+       mt7621_pcie_add_resources(pcie, &res);
 
        err = mt7621_pcie_register_host(bridge, &res);
        if (err) {
index 54e8029..0017376 100644 (file)
@@ -2,6 +2,7 @@
 config DMA_RALINK
        tristate "RALINK DMA support"
        depends on RALINK && !SOC_RT288X
+       depends on DMADEVICES
        select DMA_ENGINE
        select DMA_VIRTUAL_CHANNELS
 
index 79b55ec..b2208e5 100644 (file)
@@ -20,6 +20,7 @@ static const struct sdio_device_id sdio_ids[] = {
        { SDIO_DEVICE(0x024c, 0x0525), },
        { SDIO_DEVICE(0x024c, 0x0623), },
        { SDIO_DEVICE(0x024c, 0x0626), },
+       { SDIO_DEVICE(0x024c, 0x0627), },
        { SDIO_DEVICE(0x024c, 0xb723), },
        { /* end: all zeroes */                         },
 };
index 43b5630..510edd1 100644 (file)
@@ -24,7 +24,7 @@ description:
     In addition, it is recommended to declare a mmc-pwrseq on SDIO host above
     WFx. Without it, you may encounter issues with warm boot. The mmc-pwrseq
     should be compatible with mmc-pwrseq-simple. Please consult
-    Documentation/devicetree/bindings/mmc/mmc-pwrseq-simple.txt for more
+    Documentation/devicetree/bindings/mmc/mmc-pwrseq-simple.yaml for more
     information.
 
   For SPI':'
index f77e5ee..518fac4 100644 (file)
@@ -483,8 +483,7 @@ EXPORT_SYMBOL(iscsit_queue_rsp);
 void iscsit_aborted_task(struct iscsi_conn *conn, struct iscsi_cmd *cmd)
 {
        spin_lock_bh(&conn->cmd_lock);
-       if (!list_empty(&cmd->i_conn_node) &&
-           !(cmd->se_cmd.transport_state & CMD_T_FABRIC_STOP))
+       if (!list_empty(&cmd->i_conn_node))
                list_del_init(&cmd->i_conn_node);
        spin_unlock_bh(&conn->cmd_lock);
 
@@ -4083,12 +4082,22 @@ static void iscsit_release_commands_from_conn(struct iscsi_conn *conn)
        spin_lock_bh(&conn->cmd_lock);
        list_splice_init(&conn->conn_cmd_list, &tmp_list);
 
-       list_for_each_entry(cmd, &tmp_list, i_conn_node) {
+       list_for_each_entry_safe(cmd, cmd_tmp, &tmp_list, i_conn_node) {
                struct se_cmd *se_cmd = &cmd->se_cmd;
 
                if (se_cmd->se_tfo != NULL) {
                        spin_lock_irq(&se_cmd->t_state_lock);
-                       se_cmd->transport_state |= CMD_T_FABRIC_STOP;
+                       if (se_cmd->transport_state & CMD_T_ABORTED) {
+                               /*
+                                * LIO's abort path owns the cleanup for this,
+                                * so put it back on the list and let
+                                * aborted_task handle it.
+                                */
+                               list_move_tail(&cmd->i_conn_node,
+                                              &conn->conn_cmd_list);
+                       } else {
+                               se_cmd->transport_state |= CMD_T_FABRIC_STOP;
+                       }
                        spin_unlock_irq(&se_cmd->t_state_lock);
                }
        }
index d7f798c..337c8d8 100644 (file)
@@ -64,9 +64,13 @@ struct amdtee_session {
 /**
  * struct amdtee_context_data - AMD-TEE driver context data
  * @sess_list:    Keeps track of sessions opened in current TEE context
+ * @shm_list:     Keeps track of buffers allocated and mapped in current TEE
+ *                context
  */
 struct amdtee_context_data {
        struct list_head sess_list;
+       struct list_head shm_list;
+       struct mutex shm_mutex;   /* synchronizes access to @shm_list */
 };
 
 struct amdtee_driver_data {
@@ -89,10 +93,6 @@ struct amdtee_shm_data {
        u32     buf_id;
 };
 
-struct amdtee_shm_context {
-       struct list_head shmdata_list;
-};
-
 #define LOWER_TWO_BYTE_MASK    0x0000FFFF
 
 /**
index 27b4cd7..8a6a8f3 100644 (file)
@@ -20,7 +20,6 @@
 
 static struct amdtee_driver_data *drv_data;
 static DEFINE_MUTEX(session_list_mutex);
-static struct amdtee_shm_context shmctx;
 
 static void amdtee_get_version(struct tee_device *teedev,
                               struct tee_ioctl_version_data *vers)
@@ -42,7 +41,8 @@ static int amdtee_open(struct tee_context *ctx)
                return -ENOMEM;
 
        INIT_LIST_HEAD(&ctxdata->sess_list);
-       INIT_LIST_HEAD(&shmctx.shmdata_list);
+       INIT_LIST_HEAD(&ctxdata->shm_list);
+       mutex_init(&ctxdata->shm_mutex);
 
        ctx->data = ctxdata;
        return 0;
@@ -86,6 +86,7 @@ static void amdtee_release(struct tee_context *ctx)
                list_del(&sess->list_node);
                release_session(sess);
        }
+       mutex_destroy(&ctxdata->shm_mutex);
        kfree(ctxdata);
 
        ctx->data = NULL;
@@ -152,14 +153,17 @@ static struct amdtee_session *find_session(struct amdtee_context_data *ctxdata,
 
 u32 get_buffer_id(struct tee_shm *shm)
 {
-       u32 buf_id = 0;
+       struct amdtee_context_data *ctxdata = shm->ctx->data;
        struct amdtee_shm_data *shmdata;
+       u32 buf_id = 0;
 
-       list_for_each_entry(shmdata, &shmctx.shmdata_list, shm_node)
+       mutex_lock(&ctxdata->shm_mutex);
+       list_for_each_entry(shmdata, &ctxdata->shm_list, shm_node)
                if (shmdata->kaddr == shm->kaddr) {
                        buf_id = shmdata->buf_id;
                        break;
                }
+       mutex_unlock(&ctxdata->shm_mutex);
 
        return buf_id;
 }
@@ -333,8 +337,9 @@ int amdtee_close_session(struct tee_context *ctx, u32 session)
 
 int amdtee_map_shmem(struct tee_shm *shm)
 {
-       struct shmem_desc shmem;
+       struct amdtee_context_data *ctxdata;
        struct amdtee_shm_data *shmnode;
+       struct shmem_desc shmem;
        int rc, count;
        u32 buf_id;
 
@@ -362,7 +367,10 @@ int amdtee_map_shmem(struct tee_shm *shm)
 
        shmnode->kaddr = shm->kaddr;
        shmnode->buf_id = buf_id;
-       list_add(&shmnode->shm_node, &shmctx.shmdata_list);
+       ctxdata = shm->ctx->data;
+       mutex_lock(&ctxdata->shm_mutex);
+       list_add(&shmnode->shm_node, &ctxdata->shm_list);
+       mutex_unlock(&ctxdata->shm_mutex);
 
        pr_debug("buf_id :[%x] kaddr[%p]\n", shmnode->buf_id, shmnode->kaddr);
 
@@ -371,6 +379,7 @@ int amdtee_map_shmem(struct tee_shm *shm)
 
 void amdtee_unmap_shmem(struct tee_shm *shm)
 {
+       struct amdtee_context_data *ctxdata;
        struct amdtee_shm_data *shmnode;
        u32 buf_id;
 
@@ -381,12 +390,15 @@ void amdtee_unmap_shmem(struct tee_shm *shm)
        /* Unmap the shared memory from TEE */
        handle_unmap_shmem(buf_id);
 
-       list_for_each_entry(shmnode, &shmctx.shmdata_list, shm_node)
+       ctxdata = shm->ctx->data;
+       mutex_lock(&ctxdata->shm_mutex);
+       list_for_each_entry(shmnode, &ctxdata->shm_list, shm_node)
                if (buf_id == shmnode->buf_id) {
                        list_del(&shmnode->shm_node);
                        kfree(shmnode);
                        break;
                }
+       mutex_unlock(&ctxdata->shm_mutex);
 }
 
 int amdtee_invoke_func(struct tee_context *ctx,
index 5e59616..dcac99f 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/err.h>
 #include <linux/types.h>
 #include <linux/spinlock.h>
+#include <linux/sys_soc.h>
 #include <linux/reboot.h>
 #include <linux/of_device.h>
 #include <linux/of_platform.h>
@@ -864,6 +865,17 @@ static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev)
        return bgp;
 }
 
+/*
+ * List of SoCs on which the CPU PM notifier can cause erros on the DTEMP
+ * readout.
+ * Enabled notifier on these machines results in erroneous, random values which
+ * could trigger unexpected thermal shutdown.
+ */
+static const struct soc_device_attribute soc_no_cpu_notifier[] = {
+       { .machine = "OMAP4430" },
+       { /* sentinel */ },
+};
+
 /***   Device driver call backs   ***/
 
 static
@@ -1020,7 +1032,8 @@ int ti_bandgap_probe(struct platform_device *pdev)
 
 #ifdef CONFIG_PM_SLEEP
        bgp->nb.notifier_call = bandgap_omap_cpu_notifier;
-       cpu_pm_register_notifier(&bgp->nb);
+       if (!soc_device_match(soc_no_cpu_notifier))
+               cpu_pm_register_notifier(&bgp->nb);
 #endif
 
        return 0;
@@ -1056,7 +1069,8 @@ int ti_bandgap_remove(struct platform_device *pdev)
        struct ti_bandgap *bgp = platform_get_drvdata(pdev);
        int i;
 
-       cpu_pm_unregister_notifier(&bgp->nb);
+       if (!soc_device_match(soc_no_cpu_notifier))
+               cpu_pm_unregister_notifier(&bgp->nb);
 
        /* Remove sensor interfaces */
        for (i = 0; i < bgp->conf->sensor_count; i++) {
index 3680b27..ed65d2b 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <linux/debugfs.h>
 #include <linux/pm_runtime.h>
+#include <linux/uaccess.h>
 
 #include "tb.h"
 
index b51fc3f..977ba91 100644 (file)
@@ -2284,6 +2284,8 @@ struct tb *icm_probe(struct tb_nhi *nhi)
 
        case PCI_DEVICE_ID_INTEL_TGL_NHI0:
        case PCI_DEVICE_ID_INTEL_TGL_NHI1:
+       case PCI_DEVICE_ID_INTEL_TGL_H_NHI0:
+       case PCI_DEVICE_ID_INTEL_TGL_H_NHI1:
                icm->is_supported = icm_tgl_is_supported;
                icm->driver_ready = icm_icl_driver_ready;
                icm->set_uuid = icm_icl_set_uuid;
index 3f79baa..db80dc5 100644 (file)
@@ -406,12 +406,23 @@ static int ring_request_msix(struct tb_ring *ring, bool no_suspend)
 
        ring->vector = ret;
 
-       ring->irq = pci_irq_vector(ring->nhi->pdev, ring->vector);
-       if (ring->irq < 0)
-               return ring->irq;
+       ret = pci_irq_vector(ring->nhi->pdev, ring->vector);
+       if (ret < 0)
+               goto err_ida_remove;
+
+       ring->irq = ret;
 
        irqflags = no_suspend ? IRQF_NO_SUSPEND : 0;
-       return request_irq(ring->irq, ring_msix, irqflags, "thunderbolt", ring);
+       ret = request_irq(ring->irq, ring_msix, irqflags, "thunderbolt", ring);
+       if (ret)
+               goto err_ida_remove;
+
+       return 0;
+
+err_ida_remove:
+       ida_simple_remove(&nhi->msix_ida, ring->vector);
+
+       return ret;
 }
 
 static void ring_release_msix(struct tb_ring *ring)
@@ -1334,6 +1345,10 @@ static struct pci_device_id nhi_ids[] = {
          .driver_data = (kernel_ulong_t)&icl_nhi_ops },
        { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_TGL_NHI1),
          .driver_data = (kernel_ulong_t)&icl_nhi_ops },
+       { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_TGL_H_NHI0),
+         .driver_data = (kernel_ulong_t)&icl_nhi_ops },
+       { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_TGL_H_NHI1),
+         .driver_data = (kernel_ulong_t)&icl_nhi_ops },
 
        /* Any USB4 compliant host */
        { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_USB4, ~0) },
index 80162e4..4e0861d 100644 (file)
@@ -75,6 +75,8 @@ extern const struct tb_nhi_ops icl_nhi_ops;
 #define PCI_DEVICE_ID_INTEL_ICL_NHI0                   0x8a17
 #define PCI_DEVICE_ID_INTEL_TGL_NHI0                   0x9a1b
 #define PCI_DEVICE_ID_INTEL_TGL_NHI1                   0x9a1d
+#define PCI_DEVICE_ID_INTEL_TGL_H_NHI0                 0x9a1f
+#define PCI_DEVICE_ID_INTEL_TGL_H_NHI1                 0x9a21
 
 #define PCI_CLASS_SERIAL_USB_USB4                      0x0c0340
 
index a9995e2..8ea360b 100644 (file)
@@ -784,6 +784,8 @@ static inline bool tb_switch_is_tiger_lake(const struct tb_switch *sw)
                switch (sw->config.device_id) {
                case PCI_DEVICE_ID_INTEL_TGL_NHI0:
                case PCI_DEVICE_ID_INTEL_TGL_NHI1:
+               case PCI_DEVICE_ID_INTEL_TGL_H_NHI0:
+               case PCI_DEVICE_ID_INTEL_TGL_H_NHI1:
                        return true;
                }
        }
index 40f1357..f2583b4 100644 (file)
@@ -421,8 +421,12 @@ int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags)
         * upstream USB4 port.
         */
        tb_switch_for_each_port(sw, port) {
+               if (!tb_port_is_null(port))
+                       continue;
                if (!route && tb_is_upstream_port(port))
                        continue;
+               if (!port->cap_usb4)
+                       continue;
 
                ret = tb_port_read(port, &val, TB_CFG_PORT,
                                   port->cap_usb4 + PORT_CS_19, 1);
index 4890785..c00ad81 100644 (file)
@@ -881,6 +881,7 @@ static void enumerate_services(struct tb_xdomain *xd)
 
                id = ida_simple_get(&xd->service_ids, 0, 0, GFP_KERNEL);
                if (id < 0) {
+                       kfree(svc->key);
                        kfree(svc);
                        break;
                }
index 41f4120..fa876e2 100644 (file)
@@ -317,7 +317,7 @@ mtk8250_set_termios(struct uart_port *port, struct ktermios *termios,
         */
        baud = tty_termios_baud_rate(termios);
 
-       serial8250_do_set_termios(port, termios, old);
+       serial8250_do_set_termios(port, termios, NULL);
 
        tty_termios_encode_baud_rate(termios, baud, baud);
 
index 1044fc3..28f22e5 100644 (file)
@@ -522,6 +522,7 @@ config SERIAL_IMX_EARLYCON
        depends on OF
        select SERIAL_EARLYCON
        select SERIAL_CORE_CONSOLE
+       default y if SERIAL_IMX_CONSOLE
        help
          If you have enabled the earlycon on the Freescale IMX
          CPU you can make it the earlycon by answering Y to this option.
index 0c80a79..c2be7cf 100644 (file)
@@ -789,8 +789,10 @@ static int ar933x_uart_probe(struct platform_device *pdev)
                goto err_disable_clk;
 
        up->gpios = mctrl_gpio_init(port, 0);
-       if (IS_ERR(up->gpios) && PTR_ERR(up->gpios) != -ENOSYS)
-               return PTR_ERR(up->gpios);
+       if (IS_ERR(up->gpios) && PTR_ERR(up->gpios) != -ENOSYS) {
+               ret = PTR_ERR(up->gpios);
+               goto err_disable_clk;
+       }
 
        up->rts_gpiod = mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_RTS);
 
index 1731d97..cacf726 100644 (file)
@@ -942,8 +942,14 @@ static irqreturn_t imx_uart_int(int irq, void *dev_id)
        struct imx_port *sport = dev_id;
        unsigned int usr1, usr2, ucr1, ucr2, ucr3, ucr4;
        irqreturn_t ret = IRQ_NONE;
+       unsigned long flags = 0;
 
-       spin_lock(&sport->port.lock);
+       /*
+        * IRQs might not be disabled upon entering this interrupt handler,
+        * e.g. when interrupt handlers are forced to be threaded. To support
+        * this scenario as well, disable IRQs when acquiring the spinlock.
+        */
+       spin_lock_irqsave(&sport->port.lock, flags);
 
        usr1 = imx_uart_readl(sport, USR1);
        usr2 = imx_uart_readl(sport, USR2);
@@ -1013,7 +1019,7 @@ static irqreturn_t imx_uart_int(int irq, void *dev_id)
                ret = IRQ_HANDLED;
        }
 
-       spin_unlock(&sport->port.lock);
+       spin_unlock_irqrestore(&sport->port.lock, flags);
 
        return ret;
 }
@@ -2002,16 +2008,6 @@ imx_uart_console_write(struct console *co, const char *s, unsigned int count)
        unsigned int ucr1;
        unsigned long flags = 0;
        int locked = 1;
-       int retval;
-
-       retval = clk_enable(sport->clk_per);
-       if (retval)
-               return;
-       retval = clk_enable(sport->clk_ipg);
-       if (retval) {
-               clk_disable(sport->clk_per);
-               return;
-       }
 
        if (sport->port.sysrq)
                locked = 0;
@@ -2047,9 +2043,6 @@ imx_uart_console_write(struct console *co, const char *s, unsigned int count)
 
        if (locked)
                spin_unlock_irqrestore(&sport->port.lock, flags);
-
-       clk_disable(sport->clk_ipg);
-       clk_disable(sport->clk_per);
 }
 
 /*
@@ -2150,15 +2143,14 @@ imx_uart_console_setup(struct console *co, char *options)
 
        retval = uart_set_options(&sport->port, co, baud, parity, bits, flow);
 
-       clk_disable(sport->clk_ipg);
        if (retval) {
-               clk_unprepare(sport->clk_ipg);
+               clk_disable_unprepare(sport->clk_ipg);
                goto error_console;
        }
 
-       retval = clk_prepare(sport->clk_per);
+       retval = clk_prepare_enable(sport->clk_per);
        if (retval)
-               clk_unprepare(sport->clk_ipg);
+               clk_disable_unprepare(sport->clk_ipg);
 
 error_console:
        return retval;
index b4d89e3..7a07e72 100644 (file)
@@ -1280,6 +1280,9 @@ static int __init serial_txx9_init(void)
 
 #ifdef ENABLE_SERIAL_TXX9_PCI
        ret = pci_register_driver(&serial_txx9_pci_driver);
+       if (ret) {
+               platform_driver_unregister(&serial_txx9_plat_driver);
+       }
 #endif
        if (ret == 0)
                goto out;
index 7a4c025..9f8b9a5 100644 (file)
@@ -1515,10 +1515,12 @@ static void release_tty(struct tty_struct *tty, int idx)
                tty->ops->shutdown(tty);
        tty_save_termios(tty);
        tty_driver_remove_tty(tty->driver, tty);
-       tty->port->itty = NULL;
+       if (tty->port)
+               tty->port->itty = NULL;
        if (tty->link)
                tty->link->port->itty = NULL;
-       tty_buffer_cancel_work(tty->port);
+       if (tty->port)
+               tty_buffer_cancel_work(tty->port);
        if (tty->link)
                tty_buffer_cancel_work(tty->link->port);
 
index 9506a76..d04a162 100644 (file)
@@ -4704,27 +4704,6 @@ static int con_font_default(struct vc_data *vc, struct console_font_op *op)
        return rc;
 }
 
-static int con_font_copy(struct vc_data *vc, struct console_font_op *op)
-{
-       int con = op->height;
-       int rc;
-
-
-       console_lock();
-       if (vc->vc_mode != KD_TEXT)
-               rc = -EINVAL;
-       else if (!vc->vc_sw->con_font_copy)
-               rc = -ENOSYS;
-       else if (con < 0 || !vc_cons_allocated(con))
-               rc = -ENOTTY;
-       else if (con == vc->vc_num)     /* nothing to do */
-               rc = 0;
-       else
-               rc = vc->vc_sw->con_font_copy(vc, con);
-       console_unlock();
-       return rc;
-}
-
 int con_font_op(struct vc_data *vc, struct console_font_op *op)
 {
        switch (op->op) {
@@ -4735,7 +4714,8 @@ int con_font_op(struct vc_data *vc, struct console_font_op *op)
        case KD_FONT_OP_SET_DEFAULT:
                return con_font_default(vc, op);
        case KD_FONT_OP_COPY:
-               return con_font_copy(vc, op);
+               /* was buggy and never really used */
+               return -EINVAL;
        }
        return -ENOSYS;
 }
index 2321775..5f61b25 100644 (file)
@@ -484,7 +484,7 @@ static int vt_k_ioctl(struct tty_struct *tty, unsigned int cmd,
        return 0;
 }
 
-static inline int do_fontx_ioctl(int cmd,
+static inline int do_fontx_ioctl(struct vc_data *vc, int cmd,
                struct consolefontdesc __user *user_cfd,
                struct console_font_op *op)
 {
@@ -502,15 +502,16 @@ static inline int do_fontx_ioctl(int cmd,
                op->height = cfdarg.charheight;
                op->charcount = cfdarg.charcount;
                op->data = cfdarg.chardata;
-               return con_font_op(vc_cons[fg_console].d, op);
-       case GIO_FONTX: {
+               return con_font_op(vc, op);
+
+       case GIO_FONTX:
                op->op = KD_FONT_OP_GET;
                op->flags = KD_FONT_FLAG_OLD;
                op->width = 8;
                op->height = cfdarg.charheight;
                op->charcount = cfdarg.charcount;
                op->data = cfdarg.chardata;
-               i = con_font_op(vc_cons[fg_console].d, op);
+               i = con_font_op(vc, op);
                if (i)
                        return i;
                cfdarg.charheight = op->height;
@@ -518,12 +519,11 @@ static inline int do_fontx_ioctl(int cmd,
                if (copy_to_user(user_cfd, &cfdarg, sizeof(struct consolefontdesc)))
                        return -EFAULT;
                return 0;
-               }
        }
        return -EINVAL;
 }
 
-static int vt_io_fontreset(struct console_font_op *op)
+static int vt_io_fontreset(struct vc_data *vc, struct console_font_op *op)
 {
        int ret;
 
@@ -537,12 +537,12 @@ static int vt_io_fontreset(struct console_font_op *op)
 
        op->op = KD_FONT_OP_SET_DEFAULT;
        op->data = NULL;
-       ret = con_font_op(vc_cons[fg_console].d, op);
+       ret = con_font_op(vc, op);
        if (ret)
                return ret;
 
        console_lock();
-       con_set_default_unimap(vc_cons[fg_console].d);
+       con_set_default_unimap(vc);
        console_unlock();
 
        return 0;
@@ -584,7 +584,7 @@ static int vt_io_ioctl(struct vc_data *vc, unsigned int cmd, void __user *up,
                op.height = 0;
                op.charcount = 256;
                op.data = up;
-               return con_font_op(vc_cons[fg_console].d, &op);
+               return con_font_op(vc, &op);
 
        case GIO_FONT:
                op.op = KD_FONT_OP_GET;
@@ -593,7 +593,7 @@ static int vt_io_ioctl(struct vc_data *vc, unsigned int cmd, void __user *up,
                op.height = 32;
                op.charcount = 256;
                op.data = up;
-               return con_font_op(vc_cons[fg_console].d, &op);
+               return con_font_op(vc, &op);
 
        case PIO_CMAP:
                 if (!perm)
@@ -609,13 +609,13 @@ static int vt_io_ioctl(struct vc_data *vc, unsigned int cmd, void __user *up,
 
                fallthrough;
        case GIO_FONTX:
-               return do_fontx_ioctl(cmd, up, &op);
+               return do_fontx_ioctl(vc, cmd, up, &op);
 
        case PIO_FONTRESET:
                if (!perm)
                        return -EPERM;
 
-               return vt_io_fontreset(&op);
+               return vt_io_fontreset(vc, &op);
 
        case PIO_SCRNMAP:
                if (!perm)
@@ -1066,8 +1066,9 @@ struct compat_consolefontdesc {
 };
 
 static inline int
-compat_fontx_ioctl(int cmd, struct compat_consolefontdesc __user *user_cfd,
-                        int perm, struct console_font_op *op)
+compat_fontx_ioctl(struct vc_data *vc, int cmd,
+                  struct compat_consolefontdesc __user *user_cfd,
+                  int perm, struct console_font_op *op)
 {
        struct compat_consolefontdesc cfdarg;
        int i;
@@ -1085,7 +1086,8 @@ compat_fontx_ioctl(int cmd, struct compat_consolefontdesc __user *user_cfd,
                op->height = cfdarg.charheight;
                op->charcount = cfdarg.charcount;
                op->data = compat_ptr(cfdarg.chardata);
-               return con_font_op(vc_cons[fg_console].d, op);
+               return con_font_op(vc, op);
+
        case GIO_FONTX:
                op->op = KD_FONT_OP_GET;
                op->flags = KD_FONT_FLAG_OLD;
@@ -1093,7 +1095,7 @@ compat_fontx_ioctl(int cmd, struct compat_consolefontdesc __user *user_cfd,
                op->height = cfdarg.charheight;
                op->charcount = cfdarg.charcount;
                op->data = compat_ptr(cfdarg.chardata);
-               i = con_font_op(vc_cons[fg_console].d, op);
+               i = con_font_op(vc, op);
                if (i)
                        return i;
                cfdarg.charheight = op->height;
@@ -1183,7 +1185,7 @@ long vt_compat_ioctl(struct tty_struct *tty,
         */
        case PIO_FONTX:
        case GIO_FONTX:
-               return compat_fontx_ioctl(cmd, up, perm, &op);
+               return compat_fontx_ioctl(vc, cmd, up, perm, &op);
 
        case KDFONTOP:
                return compat_kdfontop_ioctl(up, perm, &op, vc);
index 6dca744..be06f1a 100644 (file)
@@ -413,10 +413,10 @@ static int uio_get_minor(struct uio_device *idev)
        return retval;
 }
 
-static void uio_free_minor(struct uio_device *idev)
+static void uio_free_minor(unsigned long minor)
 {
        mutex_lock(&minor_lock);
-       idr_remove(&uio_idr, idev->minor);
+       idr_remove(&uio_idr, minor);
        mutex_unlock(&minor_lock);
 }
 
@@ -990,7 +990,7 @@ err_request_irq:
 err_uio_dev_add_attributes:
        device_del(&idev->dev);
 err_device_create:
-       uio_free_minor(idev);
+       uio_free_minor(idev->minor);
        put_device(&idev->dev);
        return ret;
 }
@@ -1042,11 +1042,13 @@ EXPORT_SYMBOL_GPL(__devm_uio_register_device);
 void uio_unregister_device(struct uio_info *info)
 {
        struct uio_device *idev;
+       unsigned long minor;
 
        if (!info || !info->uio_dev)
                return;
 
        idev = info->uio_dev;
+       minor = idev->minor;
 
        mutex_lock(&idev->info_lock);
        uio_dev_del_attributes(idev);
@@ -1062,7 +1064,7 @@ void uio_unregister_device(struct uio_info *info)
 
        device_unregister(&idev->dev);
 
-       uio_free_minor(idev);
+       uio_free_minor(minor);
 
        return;
 }
index 1e75688..f52f1bc 100644 (file)
@@ -1693,6 +1693,15 @@ static const struct usb_device_id acm_ids[] = {
        { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */
        .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
        },
+       { USB_DEVICE(0x045b, 0x023c),   /* Renesas USB Download mode */
+       .driver_info = DISABLE_ECHO,    /* Don't echo banner */
+       },
+       { USB_DEVICE(0x045b, 0x0248),   /* Renesas USB Download mode */
+       .driver_info = DISABLE_ECHO,    /* Don't echo banner */
+       },
+       { USB_DEVICE(0x045b, 0x024D),   /* Renesas USB Download mode */
+       .driver_info = DISABLE_ECHO,    /* Don't echo banner */
+       },
        { USB_DEVICE(0x0e8d, 0x0003), /* FIREFLY, MediaTek Inc; andrey.arapov@gmail.com */
        .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
        },
index 10574fa..a1e3a03 100644 (file)
@@ -378,6 +378,9 @@ static const struct usb_device_id usb_quirk_list[] = {
        { USB_DEVICE(0x0926, 0x3333), .driver_info =
                        USB_QUIRK_CONFIG_INTF_STRINGS },
 
+       /* Kingston DataTraveler 3.0 */
+       { USB_DEVICE(0x0951, 0x1666), .driver_info = USB_QUIRK_NO_LPM },
+
        /* X-Rite/Gretag-Macbeth Eye-One Pro display colorimeter */
        { USB_DEVICE(0x0971, 0x2000), .driver_info = USB_QUIRK_NO_SET_INTF },
 
index e282067..5f18aca 100644 (file)
@@ -608,10 +608,13 @@ static int dwc2_driver_probe(struct platform_device *dev)
 #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
        return 0;
 
+#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
+       IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
 error_debugfs:
        dwc2_debugfs_exit(hsotg);
        if (hsotg->hcd_enabled)
                dwc2_hcd_remove(hsotg);
+#endif
 error_drd:
        dwc2_drd_exit(hsotg);
 
index 242b621..bae6a70 100644 (file)
@@ -40,6 +40,7 @@
 #define PCI_DEVICE_ID_INTEL_TGPLP              0xa0ee
 #define PCI_DEVICE_ID_INTEL_TGPH               0x43ee
 #define PCI_DEVICE_ID_INTEL_JSP                        0x4dee
+#define PCI_DEVICE_ID_INTEL_ADLS               0x7ae1
 
 #define PCI_INTEL_BXT_DSM_GUID         "732b85d5-b7a7-4a1b-9ba0-4bbd00ffd511"
 #define PCI_INTEL_BXT_FUNC_PMU_PWR     4
@@ -367,6 +368,9 @@ static const struct pci_device_id dwc3_pci_id_table[] = {
        { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_JSP),
          (kernel_ulong_t) &dwc3_pci_intel_properties, },
 
+       { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ADLS),
+         (kernel_ulong_t) &dwc3_pci_intel_properties, },
+
        { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_NL_USB),
          (kernel_ulong_t) &dwc3_pci_amd_properties, },
        {  }    /* Terminating Entry */
index 7be3903..8b668ef 100644 (file)
@@ -1058,10 +1058,11 @@ void dwc3_ep0_send_delayed_status(struct dwc3 *dwc)
 {
        unsigned int direction = !dwc->ep0_expect_in;
 
+       dwc->delayed_status = false;
+
        if (dwc->ep0state != EP0_STATUS_PHASE)
                return;
 
-       dwc->delayed_status = false;
        __dwc3_ep0_do_control_status(dwc, dwc->eps[direction]);
 }
 
index e01e366..062dfac 100644 (file)
@@ -564,9 +564,12 @@ static int raw_ioctl_event_fetch(struct raw_dev *dev, unsigned long value)
                return -ENODEV;
        }
        length = min(arg.length, event->length);
-       if (copy_to_user((void __user *)value, event, sizeof(*event) + length))
+       if (copy_to_user((void __user *)value, event, sizeof(*event) + length)) {
+               kfree(event);
                return -EFAULT;
+       }
 
+       kfree(event);
        return 0;
 }
 
index de528e3..ad6ff9c 100644 (file)
@@ -1051,7 +1051,7 @@ static int fsl_ep_fifo_status(struct usb_ep *_ep)
        u32 bitmask;
        struct ep_queue_head *qh;
 
-       if (!_ep || _ep->desc || !(_ep->desc->bEndpointAddress&0xF))
+       if (!_ep || !_ep->desc || !(_ep->desc->bEndpointAddress&0xF))
                return -ENODEV;
 
        ep = container_of(_ep, struct fsl_ep, ep);
index 25c1d6a..3e1267d 100644 (file)
@@ -1760,6 +1760,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
                goto err;
        }
 
+       pci_set_drvdata(pdev, dev);
        spin_lock_init(&dev->lock);
        dev->pdev = pdev;
        dev->gadget.ops = &goku_ops;
@@ -1793,7 +1794,6 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        }
        dev->regs = (struct goku_udc_regs __iomem *) base;
 
-       pci_set_drvdata(pdev, dev);
        INFO(dev, "%s\n", driver_desc);
        INFO(dev, "version: " DRIVER_VERSION " %s\n", dmastr());
        INFO(dev, "irq %d, pci mem %p\n", pdev->irq, base);
index 5546e7e..0836985 100644 (file)
@@ -240,7 +240,7 @@ static int xhci_histb_probe(struct platform_device *pdev)
        /* Initialize dma_mask and coherent_dma_mask to 32-bits */
        ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
        if (ret)
-               return ret;
+               goto disable_pm;
 
        hcd = usb_create_hcd(driver, dev, dev_name(dev));
        if (!hcd) {
index 579d8c8..9de0171 100644 (file)
@@ -120,8 +120,10 @@ static int apple_mfi_fc_set_property(struct power_supply *psy,
        dev_dbg(&mfi->udev->dev, "prop: %d\n", psp);
 
        ret = pm_runtime_get_sync(&mfi->udev->dev);
-       if (ret < 0)
+       if (ret < 0) {
+               pm_runtime_put_noidle(&mfi->udev->dev);
                return ret;
+       }
 
        switch (psp) {
        case POWER_SUPPLY_PROP_CHARGE_TYPE:
index 1de5c9a..38f17d6 100644 (file)
@@ -564,6 +564,7 @@ static int mtu3_gadget_stop(struct usb_gadget *g)
 
        spin_unlock_irqrestore(&mtu->lock, flags);
 
+       synchronize_irq(mtu->irq);
        return 0;
 }
 
index 30085b2..5892f3c 100644 (file)
@@ -429,10 +429,12 @@ static int dsps_musb_init(struct musb *musb)
        struct platform_device *parent = to_platform_device(dev->parent);
        const struct dsps_musb_wrapper *wrp = glue->wrp;
        void __iomem *reg_base;
+       struct resource *r;
        u32 rev, val;
        int ret;
 
-       reg_base = devm_platform_ioremap_resource_byname(parent, "control");
+       r = platform_get_resource_byname(parent, IORESOURCE_MEM, "control");
+       reg_base = devm_ioremap_resource(dev, r);
        if (IS_ERR(reg_base))
                return PTR_ERR(reg_base);
        musb->ctrl_base = reg_base;
index 8219706..2e40908 100644 (file)
@@ -357,11 +357,12 @@ static void cyberjack_write_bulk_callback(struct urb *urb)
        struct device *dev = &port->dev;
        int status = urb->status;
        unsigned long flags;
+       bool resubmitted = false;
 
-       set_bit(0, &port->write_urbs_free);
        if (status) {
                dev_dbg(dev, "%s - nonzero write bulk status received: %d\n",
                        __func__, status);
+               set_bit(0, &port->write_urbs_free);
                return;
        }
 
@@ -394,6 +395,8 @@ static void cyberjack_write_bulk_callback(struct urb *urb)
                        goto exit;
                }
 
+               resubmitted = true;
+
                dev_dbg(dev, "%s - priv->wrsent=%d\n", __func__, priv->wrsent);
                dev_dbg(dev, "%s - priv->wrfilled=%d\n", __func__, priv->wrfilled);
 
@@ -410,6 +413,8 @@ static void cyberjack_write_bulk_callback(struct urb *urb)
 
 exit:
        spin_unlock_irqrestore(&priv->lock, flags);
+       if (!resubmitted)
+               set_bit(0, &port->write_urbs_free);
        usb_serial_port_softint(port);
 }
 
index 2a3bfd6..54ca85c 100644 (file)
@@ -250,6 +250,7 @@ static void option_instat_callback(struct urb *urb);
 #define QUECTEL_PRODUCT_EP06                   0x0306
 #define QUECTEL_PRODUCT_EM12                   0x0512
 #define QUECTEL_PRODUCT_RM500Q                 0x0800
+#define QUECTEL_PRODUCT_EC200T                 0x6026
 
 #define CMOTECH_VENDOR_ID                      0x16d8
 #define CMOTECH_PRODUCT_6001                   0x6001
@@ -1117,6 +1118,7 @@ static const struct usb_device_id option_ids[] = {
        { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RM500Q, 0xff, 0, 0) },
        { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RM500Q, 0xff, 0xff, 0x10),
          .driver_info = ZLP },
+       { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EC200T, 0xff, 0, 0) },
 
        { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6001) },
        { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_CMU_300) },
@@ -1189,6 +1191,8 @@ static const struct usb_device_id option_ids[] = {
          .driver_info = NCTRL(0) | RSVD(1) },
        { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1054, 0xff),    /* Telit FT980-KS */
          .driver_info = NCTRL(2) | RSVD(3) },
+       { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1055, 0xff),    /* Telit FN980 (PCIe) */
+         .driver_info = NCTRL(0) | RSVD(1) },
        { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_ME910),
          .driver_info = NCTRL(0) | RSVD(1) | RSVD(3) },
        { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_ME910_DUAL_MODEM),
@@ -1201,6 +1205,8 @@ static const struct usb_device_id option_ids[] = {
          .driver_info = NCTRL(0) },
        { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_LE910),
          .driver_info = NCTRL(0) | RSVD(1) | RSVD(2) },
+       { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1203, 0xff),    /* Telit LE910Cx (RNDIS) */
+         .driver_info = NCTRL(2) | RSVD(3) },
        { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_LE910_USBCFG4),
          .driver_info = NCTRL(0) | RSVD(1) | RSVD(2) | RSVD(3) },
        { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_LE920),
@@ -1215,6 +1221,10 @@ static const struct usb_device_id option_ids[] = {
        { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, TELIT_PRODUCT_LE920A4_1213, 0xff) },
        { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_LE920A4_1214),
          .driver_info = NCTRL(0) | RSVD(1) | RSVD(2) | RSVD(3) },
+       { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1230, 0xff),    /* Telit LE910Cx (rmnet) */
+         .driver_info = NCTRL(0) | RSVD(1) | RSVD(2) },
+       { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1231, 0xff),    /* Telit LE910Cx (RNDIS) */
+         .driver_info = NCTRL(2) | RSVD(3) },
        { USB_DEVICE(TELIT_VENDOR_ID, 0x1260),
          .driver_info = NCTRL(0) | RSVD(1) | RSVD(2) },
        { USB_DEVICE(TELIT_VENDOR_ID, 0x1261),
index 26ed0b5..571a51e 100644 (file)
@@ -238,4 +238,13 @@ void ucsi_unregister_port_psy(struct ucsi_connector *con)
                return;
 
        power_supply_unregister(con->psy);
+       con->psy = NULL;
+}
+
+void ucsi_port_psy_changed(struct ucsi_connector *con)
+{
+       if (IS_ERR_OR_NULL(con->psy))
+               return;
+
+       power_supply_changed(con->psy);
 }
index 758b988..51a570d 100644 (file)
@@ -643,8 +643,10 @@ static void ucsi_handle_connector_change(struct work_struct *work)
        role = !!(con->status.flags & UCSI_CONSTAT_PWR_DIR);
 
        if (con->status.change & UCSI_CONSTAT_POWER_OPMODE_CHANGE ||
-           con->status.change & UCSI_CONSTAT_POWER_LEVEL_CHANGE)
+           con->status.change & UCSI_CONSTAT_POWER_LEVEL_CHANGE) {
                ucsi_pwr_opmode_change(con);
+               ucsi_port_psy_changed(con);
+       }
 
        if (con->status.change & UCSI_CONSTAT_POWER_DIR_CHANGE) {
                typec_set_pwr_role(con->port, role);
@@ -674,6 +676,8 @@ static void ucsi_handle_connector_change(struct work_struct *work)
                        ucsi_register_partner(con);
                else
                        ucsi_unregister_partner(con);
+
+               ucsi_port_psy_changed(con);
        }
 
        if (con->status.change & UCSI_CONSTAT_CAM_CHANGE) {
@@ -994,6 +998,7 @@ static int ucsi_register_port(struct ucsi *ucsi, int index)
                                  !!(con->status.flags & UCSI_CONSTAT_PWR_DIR));
                ucsi_pwr_opmode_change(con);
                ucsi_register_partner(con);
+               ucsi_port_psy_changed(con);
        }
 
        if (con->partner) {
index cba6f77..b7a92f2 100644 (file)
@@ -340,9 +340,11 @@ int ucsi_resume(struct ucsi *ucsi);
 #if IS_ENABLED(CONFIG_POWER_SUPPLY)
 int ucsi_register_port_psy(struct ucsi_connector *con);
 void ucsi_unregister_port_psy(struct ucsi_connector *con);
+void ucsi_port_psy_changed(struct ucsi_connector *con);
 #else
 static inline int ucsi_register_port_psy(struct ucsi_connector *con) { return 0; }
 static inline void ucsi_unregister_port_psy(struct ucsi_connector *con) { }
+static inline void ucsi_port_psy_changed(struct ucsi_connector *con) { }
 #endif /* CONFIG_POWER_SUPPLY */
 
 #if IS_ENABLED(CONFIG_TYPEC_DP_ALTMODE)
index d7d32b6..358f604 100644 (file)
@@ -13,6 +13,7 @@ config VDPA_SIM
        depends on RUNTIME_TESTING_MENU && HAS_DMA
        select DMA_OPS
        select VHOST_RING
+       select GENERIC_NET_UTILS
        default n
        help
          vDPA networking device simulator which loop TX traffic back
index 0113a98..f27e251 100644 (file)
@@ -248,7 +248,9 @@ static long vfio_fsl_mc_ioctl(void *device_data, unsigned int cmd,
                info.size = vdev->regions[info.index].size;
                info.flags = vdev->regions[info.index].flags;
 
-               return copy_to_user((void __user *)arg, &info, minsz);
+               if (copy_to_user((void __user *)arg, &info, minsz))
+                       return -EFAULT;
+               return 0;
        }
        case VFIO_DEVICE_GET_IRQ_INFO:
        {
@@ -267,7 +269,9 @@ static long vfio_fsl_mc_ioctl(void *device_data, unsigned int cmd,
                info.flags = VFIO_IRQ_INFO_EVENTFD;
                info.count = 1;
 
-               return copy_to_user((void __user *)arg, &info, minsz);
+               if (copy_to_user((void __user *)arg, &info, minsz))
+                       return -EFAULT;
+               return 0;
        }
        case VFIO_DEVICE_SET_IRQS:
        {
@@ -468,7 +472,7 @@ static int vfio_fsl_mc_mmap(void *device_data, struct vm_area_struct *vma)
 {
        struct vfio_fsl_mc_device *vdev = device_data;
        struct fsl_mc_device *mc_dev = vdev->mc_dev;
-       int index;
+       unsigned int index;
 
        index = vma->vm_pgoff >> (VFIO_FSL_MC_OFFSET_SHIFT - PAGE_SHIFT);
 
index c80dceb..0d9f300 100644 (file)
@@ -13,7 +13,7 @@
 #include "linux/fsl/mc.h"
 #include "vfio_fsl_mc_private.h"
 
-int vfio_fsl_mc_irqs_allocate(struct vfio_fsl_mc_device *vdev)
+static int vfio_fsl_mc_irqs_allocate(struct vfio_fsl_mc_device *vdev)
 {
        struct fsl_mc_device *mc_dev = vdev->mc_dev;
        struct vfio_fsl_mc_irq *mc_irq;
index fbd2b34..e619017 100644 (file)
@@ -385,7 +385,7 @@ static int vfio_pci_enable(struct vfio_pci_device *vdev)
            pdev->vendor == PCI_VENDOR_ID_INTEL &&
            IS_ENABLED(CONFIG_VFIO_PCI_IGD)) {
                ret = vfio_pci_igd_init(vdev);
-               if (ret) {
+               if (ret && ret != -ENODEV) {
                        pci_warn(pdev, "Failed to setup Intel IGD regions\n");
                        goto disable_exit;
                }
index 9e353c4..a0b5fc8 100644 (file)
@@ -356,34 +356,60 @@ ssize_t vfio_pci_vga_rw(struct vfio_pci_device *vdev, char __user *buf,
        return done;
 }
 
-static int vfio_pci_ioeventfd_handler(void *opaque, void *unused)
+static void vfio_pci_ioeventfd_do_write(struct vfio_pci_ioeventfd *ioeventfd,
+                                       bool test_mem)
 {
-       struct vfio_pci_ioeventfd *ioeventfd = opaque;
-
        switch (ioeventfd->count) {
        case 1:
-               vfio_pci_iowrite8(ioeventfd->vdev, ioeventfd->test_mem,
+               vfio_pci_iowrite8(ioeventfd->vdev, test_mem,
                                  ioeventfd->data, ioeventfd->addr);
                break;
        case 2:
-               vfio_pci_iowrite16(ioeventfd->vdev, ioeventfd->test_mem,
+               vfio_pci_iowrite16(ioeventfd->vdev, test_mem,
                                   ioeventfd->data, ioeventfd->addr);
                break;
        case 4:
-               vfio_pci_iowrite32(ioeventfd->vdev, ioeventfd->test_mem,
+               vfio_pci_iowrite32(ioeventfd->vdev, test_mem,
                                   ioeventfd->data, ioeventfd->addr);
                break;
 #ifdef iowrite64
        case 8:
-               vfio_pci_iowrite64(ioeventfd->vdev, ioeventfd->test_mem,
+               vfio_pci_iowrite64(ioeventfd->vdev, test_mem,
                                   ioeventfd->data, ioeventfd->addr);
                break;
 #endif
        }
+}
+
+static int vfio_pci_ioeventfd_handler(void *opaque, void *unused)
+{
+       struct vfio_pci_ioeventfd *ioeventfd = opaque;
+       struct vfio_pci_device *vdev = ioeventfd->vdev;
+
+       if (ioeventfd->test_mem) {
+               if (!down_read_trylock(&vdev->memory_lock))
+                       return 1; /* Lock contended, use thread */
+               if (!__vfio_pci_memory_enabled(vdev)) {
+                       up_read(&vdev->memory_lock);
+                       return 0;
+               }
+       }
+
+       vfio_pci_ioeventfd_do_write(ioeventfd, false);
+
+       if (ioeventfd->test_mem)
+               up_read(&vdev->memory_lock);
 
        return 0;
 }
 
+static void vfio_pci_ioeventfd_thread(void *opaque, void *unused)
+{
+       struct vfio_pci_ioeventfd *ioeventfd = opaque;
+
+       vfio_pci_ioeventfd_do_write(ioeventfd, ioeventfd->test_mem);
+}
+
 long vfio_pci_ioeventfd(struct vfio_pci_device *vdev, loff_t offset,
                        uint64_t data, int count, int fd)
 {
@@ -457,7 +483,8 @@ long vfio_pci_ioeventfd(struct vfio_pci_device *vdev, loff_t offset,
        ioeventfd->test_mem = vdev->pdev->resource[bar].flags & IORESOURCE_MEM;
 
        ret = vfio_virqfd_enable(ioeventfd, vfio_pci_ioeventfd_handler,
-                                NULL, NULL, &ioeventfd->virqfd, fd);
+                                vfio_pci_ioeventfd_thread, NULL,
+                                &ioeventfd->virqfd, fd);
        if (ret) {
                kfree(ioeventfd);
                goto out_unlock;
index c0771a9..fb4b385 100644 (file)
@@ -267,7 +267,7 @@ static int vfio_platform_open(void *device_data)
 
                ret = pm_runtime_get_sync(vdev->device);
                if (ret < 0)
-                       goto err_pm;
+                       goto err_rst;
 
                ret = vfio_platform_call_reset(vdev, &extra_dbg);
                if (ret && vdev->reset_required) {
@@ -284,7 +284,6 @@ static int vfio_platform_open(void *device_data)
 
 err_rst:
        pm_runtime_put(vdev->device);
-err_pm:
        vfio_platform_irq_cleanup(vdev);
 err_irq:
        vfio_platform_regions_cleanup(vdev);
index bb2684c..67e8276 100644 (file)
@@ -1993,6 +1993,7 @@ static void vfio_iommu_iova_insert_copy(struct vfio_iommu *iommu,
 
        list_splice_tail(iova_copy, iova);
 }
+
 static int vfio_iommu_type1_attach_group(void *iommu_data,
                                         struct iommu_group *iommu_group)
 {
@@ -2009,18 +2010,10 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
 
        mutex_lock(&iommu->lock);
 
-       list_for_each_entry(d, &iommu->domain_list, next) {
-               if (find_iommu_group(d, iommu_group)) {
-                       mutex_unlock(&iommu->lock);
-                       return -EINVAL;
-               }
-       }
-
-       if (iommu->external_domain) {
-               if (find_iommu_group(iommu->external_domain, iommu_group)) {
-                       mutex_unlock(&iommu->lock);
-                       return -EINVAL;
-               }
+       /* Check for duplicates */
+       if (vfio_iommu_find_iommu_group(iommu, iommu_group)) {
+               mutex_unlock(&iommu->lock);
+               return -EINVAL;
        }
 
        group = kzalloc(sizeof(*group), GFP_KERNEL);
index b22adf0..f22fce5 100644 (file)
@@ -52,7 +52,6 @@
 #define VHOST_SCSI_VERSION  "v0.1"
 #define VHOST_SCSI_NAMELEN 256
 #define VHOST_SCSI_MAX_CDB_SIZE 32
-#define VHOST_SCSI_DEFAULT_TAGS 256
 #define VHOST_SCSI_PREALLOC_SGLS 2048
 #define VHOST_SCSI_PREALLOC_UPAGES 2048
 #define VHOST_SCSI_PREALLOC_PROT_SGLS 2048
@@ -140,6 +139,7 @@ struct vhost_scsi_tpg {
        struct se_portal_group se_tpg;
        /* Pointer back to vhost_scsi, protected by tv_tpg_mutex */
        struct vhost_scsi *vhost_scsi;
+       struct list_head tmf_queue;
 };
 
 struct vhost_scsi_tport {
@@ -189,6 +189,9 @@ struct vhost_scsi_virtqueue {
         * Writers must also take dev mutex and flush under it.
         */
        int inflight_idx;
+       struct vhost_scsi_cmd *scsi_cmds;
+       struct sbitmap scsi_tags;
+       int max_cmds;
 };
 
 struct vhost_scsi {
@@ -209,6 +212,20 @@ struct vhost_scsi {
        int vs_events_nr; /* num of pending events, protected by vq->mutex */
 };
 
+struct vhost_scsi_tmf {
+       struct vhost_work vwork;
+       struct vhost_scsi_tpg *tpg;
+       struct vhost_scsi *vhost;
+       struct vhost_scsi_virtqueue *svq;
+       struct list_head queue_entry;
+
+       struct se_cmd se_cmd;
+       struct vhost_scsi_inflight *inflight;
+       struct iovec resp_iov;
+       int in_iovs;
+       int vq_desc;
+};
+
 /*
  * Context for processing request and control queue operations.
  */
@@ -320,11 +337,13 @@ static u32 vhost_scsi_tpg_get_inst_index(struct se_portal_group *se_tpg)
        return 1;
 }
 
-static void vhost_scsi_release_cmd(struct se_cmd *se_cmd)
+static void vhost_scsi_release_cmd_res(struct se_cmd *se_cmd)
 {
        struct vhost_scsi_cmd *tv_cmd = container_of(se_cmd,
                                struct vhost_scsi_cmd, tvc_se_cmd);
-       struct se_session *se_sess = tv_cmd->tvc_nexus->tvn_se_sess;
+       struct vhost_scsi_virtqueue *svq = container_of(tv_cmd->tvc_vq,
+                               struct vhost_scsi_virtqueue, vq);
+       struct vhost_scsi_inflight *inflight = tv_cmd->inflight;
        int i;
 
        if (tv_cmd->tvc_sgl_count) {
@@ -336,8 +355,36 @@ static void vhost_scsi_release_cmd(struct se_cmd *se_cmd)
                        put_page(sg_page(&tv_cmd->tvc_prot_sgl[i]));
        }
 
-       vhost_scsi_put_inflight(tv_cmd->inflight);
-       target_free_tag(se_sess, se_cmd);
+       sbitmap_clear_bit(&svq->scsi_tags, se_cmd->map_tag);
+       vhost_scsi_put_inflight(inflight);
+}
+
+static void vhost_scsi_release_tmf_res(struct vhost_scsi_tmf *tmf)
+{
+       struct vhost_scsi_tpg *tpg = tmf->tpg;
+       struct vhost_scsi_inflight *inflight = tmf->inflight;
+
+       mutex_lock(&tpg->tv_tpg_mutex);
+       list_add_tail(&tpg->tmf_queue, &tmf->queue_entry);
+       mutex_unlock(&tpg->tv_tpg_mutex);
+       vhost_scsi_put_inflight(inflight);
+}
+
+static void vhost_scsi_release_cmd(struct se_cmd *se_cmd)
+{
+       if (se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB) {
+               struct vhost_scsi_tmf *tmf = container_of(se_cmd,
+                                       struct vhost_scsi_tmf, se_cmd);
+
+               vhost_work_queue(&tmf->vhost->dev, &tmf->vwork);
+       } else {
+               struct vhost_scsi_cmd *cmd = container_of(se_cmd,
+                                       struct vhost_scsi_cmd, tvc_se_cmd);
+               struct vhost_scsi *vs = cmd->tvc_vhost;
+
+               llist_add(&cmd->tvc_completion_list, &vs->vs_completion_list);
+               vhost_work_queue(&vs->dev, &vs->vs_completion_work);
+       }
 }
 
 static u32 vhost_scsi_sess_get_index(struct se_session *se_sess)
@@ -362,34 +409,24 @@ static int vhost_scsi_get_cmd_state(struct se_cmd *se_cmd)
        return 0;
 }
 
-static void vhost_scsi_complete_cmd(struct vhost_scsi_cmd *cmd)
-{
-       struct vhost_scsi *vs = cmd->tvc_vhost;
-
-       llist_add(&cmd->tvc_completion_list, &vs->vs_completion_list);
-
-       vhost_work_queue(&vs->dev, &vs->vs_completion_work);
-}
-
 static int vhost_scsi_queue_data_in(struct se_cmd *se_cmd)
 {
-       struct vhost_scsi_cmd *cmd = container_of(se_cmd,
-                               struct vhost_scsi_cmd, tvc_se_cmd);
-       vhost_scsi_complete_cmd(cmd);
+       transport_generic_free_cmd(se_cmd, 0);
        return 0;
 }
 
 static int vhost_scsi_queue_status(struct se_cmd *se_cmd)
 {
-       struct vhost_scsi_cmd *cmd = container_of(se_cmd,
-                               struct vhost_scsi_cmd, tvc_se_cmd);
-       vhost_scsi_complete_cmd(cmd);
+       transport_generic_free_cmd(se_cmd, 0);
        return 0;
 }
 
 static void vhost_scsi_queue_tm_rsp(struct se_cmd *se_cmd)
 {
-       return;
+       struct vhost_scsi_tmf *tmf = container_of(se_cmd, struct vhost_scsi_tmf,
+                                                 se_cmd);
+
+       transport_generic_free_cmd(&tmf->se_cmd, 0);
 }
 
 static void vhost_scsi_aborted_task(struct se_cmd *se_cmd)
@@ -429,15 +466,6 @@ vhost_scsi_allocate_evt(struct vhost_scsi *vs,
        return evt;
 }
 
-static void vhost_scsi_free_cmd(struct vhost_scsi_cmd *cmd)
-{
-       struct se_cmd *se_cmd = &cmd->tvc_se_cmd;
-
-       /* TODO locking against target/backend threads? */
-       transport_generic_free_cmd(se_cmd, 0);
-
-}
-
 static int vhost_scsi_check_stop_free(struct se_cmd *se_cmd)
 {
        return target_put_sess_cmd(se_cmd);
@@ -556,7 +584,7 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work)
                } else
                        pr_err("Faulted on virtio_scsi_cmd_resp\n");
 
-               vhost_scsi_free_cmd(cmd);
+               vhost_scsi_release_cmd_res(se_cmd);
        }
 
        vq = -1;
@@ -566,31 +594,31 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work)
 }
 
 static struct vhost_scsi_cmd *
-vhost_scsi_get_tag(struct vhost_virtqueue *vq, struct vhost_scsi_tpg *tpg,
+vhost_scsi_get_cmd(struct vhost_virtqueue *vq, struct vhost_scsi_tpg *tpg,
                   unsigned char *cdb, u64 scsi_tag, u16 lun, u8 task_attr,
                   u32 exp_data_len, int data_direction)
 {
+       struct vhost_scsi_virtqueue *svq = container_of(vq,
+                                       struct vhost_scsi_virtqueue, vq);
        struct vhost_scsi_cmd *cmd;
        struct vhost_scsi_nexus *tv_nexus;
-       struct se_session *se_sess;
        struct scatterlist *sg, *prot_sg;
        struct page **pages;
-       int tag, cpu;
+       int tag;
 
        tv_nexus = tpg->tpg_nexus;
        if (!tv_nexus) {
                pr_err("Unable to locate active struct vhost_scsi_nexus\n");
                return ERR_PTR(-EIO);
        }
-       se_sess = tv_nexus->tvn_se_sess;
 
-       tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu);
+       tag = sbitmap_get(&svq->scsi_tags, 0, false);
        if (tag < 0) {
                pr_err("Unable to obtain tag for vhost_scsi_cmd\n");
                return ERR_PTR(-ENOMEM);
        }
 
-       cmd = &((struct vhost_scsi_cmd *)se_sess->sess_cmd_map)[tag];
+       cmd = &svq->scsi_cmds[tag];
        sg = cmd->tvc_sgl;
        prot_sg = cmd->tvc_prot_sgl;
        pages = cmd->tvc_upages;
@@ -599,7 +627,6 @@ vhost_scsi_get_tag(struct vhost_virtqueue *vq, struct vhost_scsi_tpg *tpg,
        cmd->tvc_prot_sgl = prot_sg;
        cmd->tvc_upages = pages;
        cmd->tvc_se_cmd.map_tag = tag;
-       cmd->tvc_se_cmd.map_cpu = cpu;
        cmd->tvc_tag = scsi_tag;
        cmd->tvc_lun = lun;
        cmd->tvc_task_attr = task_attr;
@@ -907,6 +934,11 @@ vhost_scsi_get_req(struct vhost_virtqueue *vq, struct vhost_scsi_ctx *vc,
        return ret;
 }
 
+static u16 vhost_buf_to_lun(u8 *lun_buf)
+{
+       return ((lun_buf[2] << 8) | lun_buf[3]) & 0x3FFF;
+}
+
 static void
 vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
 {
@@ -1045,12 +1077,12 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
                        tag = vhost64_to_cpu(vq, v_req_pi.tag);
                        task_attr = v_req_pi.task_attr;
                        cdb = &v_req_pi.cdb[0];
-                       lun = ((v_req_pi.lun[2] << 8) | v_req_pi.lun[3]) & 0x3FFF;
+                       lun = vhost_buf_to_lun(v_req_pi.lun);
                } else {
                        tag = vhost64_to_cpu(vq, v_req.tag);
                        task_attr = v_req.task_attr;
                        cdb = &v_req.cdb[0];
-                       lun = ((v_req.lun[2] << 8) | v_req.lun[3]) & 0x3FFF;
+                       lun = vhost_buf_to_lun(v_req.lun);
                }
                /*
                 * Check that the received CDB size does not exceeded our
@@ -1065,11 +1097,11 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
                                scsi_command_size(cdb), VHOST_SCSI_MAX_CDB_SIZE);
                                goto err;
                }
-               cmd = vhost_scsi_get_tag(vq, tpg, cdb, tag, lun, task_attr,
+               cmd = vhost_scsi_get_cmd(vq, tpg, cdb, tag, lun, task_attr,
                                         exp_data_len + prot_bytes,
                                         data_direction);
                if (IS_ERR(cmd)) {
-                       vq_err(vq, "vhost_scsi_get_tag failed %ld\n",
+                       vq_err(vq, "vhost_scsi_get_cmd failed %ld\n",
                               PTR_ERR(cmd));
                        goto err;
                }
@@ -1088,7 +1120,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
                                                      &prot_iter, exp_data_len,
                                                      &data_iter))) {
                                vq_err(vq, "Failed to map iov to sgl\n");
-                               vhost_scsi_release_cmd(&cmd->tvc_se_cmd);
+                               vhost_scsi_release_cmd_res(&cmd->tvc_se_cmd);
                                goto err;
                        }
                }
@@ -1124,9 +1156,9 @@ out:
 }
 
 static void
-vhost_scsi_send_tmf_reject(struct vhost_scsi *vs,
-                          struct vhost_virtqueue *vq,
-                          struct vhost_scsi_ctx *vc)
+vhost_scsi_send_tmf_resp(struct vhost_scsi *vs, struct vhost_virtqueue *vq,
+                        int in_iovs, int vq_desc, struct iovec *resp_iov,
+                        int tmf_resp_code)
 {
        struct virtio_scsi_ctrl_tmf_resp rsp;
        struct iov_iter iov_iter;
@@ -1134,17 +1166,87 @@ vhost_scsi_send_tmf_reject(struct vhost_scsi *vs,
 
        pr_debug("%s\n", __func__);
        memset(&rsp, 0, sizeof(rsp));
-       rsp.response = VIRTIO_SCSI_S_FUNCTION_REJECTED;
+       rsp.response = tmf_resp_code;
 
-       iov_iter_init(&iov_iter, READ, &vq->iov[vc->out], vc->in, sizeof(rsp));
+       iov_iter_init(&iov_iter, READ, resp_iov, in_iovs, sizeof(rsp));
 
        ret = copy_to_iter(&rsp, sizeof(rsp), &iov_iter);
        if (likely(ret == sizeof(rsp)))
-               vhost_add_used_and_signal(&vs->dev, vq, vc->head, 0);
+               vhost_add_used_and_signal(&vs->dev, vq, vq_desc, 0);
        else
                pr_err("Faulted on virtio_scsi_ctrl_tmf_resp\n");
 }
 
+static void vhost_scsi_tmf_resp_work(struct vhost_work *work)
+{
+       struct vhost_scsi_tmf *tmf = container_of(work, struct vhost_scsi_tmf,
+                                                 vwork);
+       int resp_code;
+
+       if (tmf->se_cmd.se_tmr_req->response == TMR_FUNCTION_COMPLETE)
+               resp_code = VIRTIO_SCSI_S_FUNCTION_SUCCEEDED;
+       else
+               resp_code = VIRTIO_SCSI_S_FUNCTION_REJECTED;
+
+       vhost_scsi_send_tmf_resp(tmf->vhost, &tmf->svq->vq, tmf->in_iovs,
+                                tmf->vq_desc, &tmf->resp_iov, resp_code);
+       vhost_scsi_release_tmf_res(tmf);
+}
+
+static void
+vhost_scsi_handle_tmf(struct vhost_scsi *vs, struct vhost_scsi_tpg *tpg,
+                     struct vhost_virtqueue *vq,
+                     struct virtio_scsi_ctrl_tmf_req *vtmf,
+                     struct vhost_scsi_ctx *vc)
+{
+       struct vhost_scsi_virtqueue *svq = container_of(vq,
+                                       struct vhost_scsi_virtqueue, vq);
+       struct vhost_scsi_tmf *tmf;
+
+       if (vhost32_to_cpu(vq, vtmf->subtype) !=
+           VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET)
+               goto send_reject;
+
+       if (!tpg->tpg_nexus || !tpg->tpg_nexus->tvn_se_sess) {
+               pr_err("Unable to locate active struct vhost_scsi_nexus for LUN RESET.\n");
+               goto send_reject;
+       }
+
+       mutex_lock(&tpg->tv_tpg_mutex);
+       if (list_empty(&tpg->tmf_queue)) {
+               pr_err("Missing reserve TMF. Could not handle LUN RESET.\n");
+               mutex_unlock(&tpg->tv_tpg_mutex);
+               goto send_reject;
+       }
+
+       tmf = list_first_entry(&tpg->tmf_queue, struct vhost_scsi_tmf,
+                              queue_entry);
+       list_del_init(&tmf->queue_entry);
+       mutex_unlock(&tpg->tv_tpg_mutex);
+
+       tmf->tpg = tpg;
+       tmf->vhost = vs;
+       tmf->svq = svq;
+       tmf->resp_iov = vq->iov[vc->out];
+       tmf->vq_desc = vc->head;
+       tmf->in_iovs = vc->in;
+       tmf->inflight = vhost_scsi_get_inflight(vq);
+
+       if (target_submit_tmr(&tmf->se_cmd, tpg->tpg_nexus->tvn_se_sess, NULL,
+                             vhost_buf_to_lun(vtmf->lun), NULL,
+                             TMR_LUN_RESET, GFP_KERNEL, 0,
+                             TARGET_SCF_ACK_KREF) < 0) {
+               vhost_scsi_release_tmf_res(tmf);
+               goto send_reject;
+       }
+
+       return;
+
+send_reject:
+       vhost_scsi_send_tmf_resp(vs, vq, vc->in, vc->head, &vq->iov[vc->out],
+                                VIRTIO_SCSI_S_FUNCTION_REJECTED);
+}
+
 static void
 vhost_scsi_send_an_resp(struct vhost_scsi *vs,
                        struct vhost_virtqueue *vq,
@@ -1170,6 +1272,7 @@ vhost_scsi_send_an_resp(struct vhost_scsi *vs,
 static void
 vhost_scsi_ctl_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
 {
+       struct vhost_scsi_tpg *tpg;
        union {
                __virtio32 type;
                struct virtio_scsi_ctrl_an_req an;
@@ -1251,12 +1354,12 @@ vhost_scsi_ctl_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
                vc.req += typ_size;
                vc.req_size -= typ_size;
 
-               ret = vhost_scsi_get_req(vq, &vc, NULL);
+               ret = vhost_scsi_get_req(vq, &vc, &tpg);
                if (ret)
                        goto err;
 
                if (v_req.type == VIRTIO_SCSI_T_TMF)
-                       vhost_scsi_send_tmf_reject(vs, vq, &vc);
+                       vhost_scsi_handle_tmf(vs, tpg, vq, &v_req.tmf, &vc);
                else
                        vhost_scsi_send_an_resp(vs, vq, &vc);
 err:
@@ -1373,6 +1476,83 @@ static void vhost_scsi_flush(struct vhost_scsi *vs)
                wait_for_completion(&old_inflight[i]->comp);
 }
 
+static void vhost_scsi_destroy_vq_cmds(struct vhost_virtqueue *vq)
+{
+       struct vhost_scsi_virtqueue *svq = container_of(vq,
+                                       struct vhost_scsi_virtqueue, vq);
+       struct vhost_scsi_cmd *tv_cmd;
+       unsigned int i;
+
+       if (!svq->scsi_cmds)
+               return;
+
+       for (i = 0; i < svq->max_cmds; i++) {
+               tv_cmd = &svq->scsi_cmds[i];
+
+               kfree(tv_cmd->tvc_sgl);
+               kfree(tv_cmd->tvc_prot_sgl);
+               kfree(tv_cmd->tvc_upages);
+       }
+
+       sbitmap_free(&svq->scsi_tags);
+       kfree(svq->scsi_cmds);
+       svq->scsi_cmds = NULL;
+}
+
+static int vhost_scsi_setup_vq_cmds(struct vhost_virtqueue *vq, int max_cmds)
+{
+       struct vhost_scsi_virtqueue *svq = container_of(vq,
+                                       struct vhost_scsi_virtqueue, vq);
+       struct vhost_scsi_cmd *tv_cmd;
+       unsigned int i;
+
+       if (svq->scsi_cmds)
+               return 0;
+
+       if (sbitmap_init_node(&svq->scsi_tags, max_cmds, -1, GFP_KERNEL,
+                             NUMA_NO_NODE))
+               return -ENOMEM;
+       svq->max_cmds = max_cmds;
+
+       svq->scsi_cmds = kcalloc(max_cmds, sizeof(*tv_cmd), GFP_KERNEL);
+       if (!svq->scsi_cmds) {
+               sbitmap_free(&svq->scsi_tags);
+               return -ENOMEM;
+       }
+
+       for (i = 0; i < max_cmds; i++) {
+               tv_cmd = &svq->scsi_cmds[i];
+
+               tv_cmd->tvc_sgl = kcalloc(VHOST_SCSI_PREALLOC_SGLS,
+                                         sizeof(struct scatterlist),
+                                         GFP_KERNEL);
+               if (!tv_cmd->tvc_sgl) {
+                       pr_err("Unable to allocate tv_cmd->tvc_sgl\n");
+                       goto out;
+               }
+
+               tv_cmd->tvc_upages = kcalloc(VHOST_SCSI_PREALLOC_UPAGES,
+                                            sizeof(struct page *),
+                                            GFP_KERNEL);
+               if (!tv_cmd->tvc_upages) {
+                       pr_err("Unable to allocate tv_cmd->tvc_upages\n");
+                       goto out;
+               }
+
+               tv_cmd->tvc_prot_sgl = kcalloc(VHOST_SCSI_PREALLOC_PROT_SGLS,
+                                              sizeof(struct scatterlist),
+                                              GFP_KERNEL);
+               if (!tv_cmd->tvc_prot_sgl) {
+                       pr_err("Unable to allocate tv_cmd->tvc_prot_sgl\n");
+                       goto out;
+               }
+       }
+       return 0;
+out:
+       vhost_scsi_destroy_vq_cmds(vq);
+       return -ENOMEM;
+}
+
 /*
  * Called from vhost_scsi_ioctl() context to walk the list of available
  * vhost_scsi_tpg with an active struct vhost_scsi_nexus
@@ -1427,10 +1607,9 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs,
 
                if (!strcmp(tv_tport->tport_name, t->vhost_wwpn)) {
                        if (vs->vs_tpg && vs->vs_tpg[tpg->tport_tpgt]) {
-                               kfree(vs_tpg);
                                mutex_unlock(&tpg->tv_tpg_mutex);
                                ret = -EEXIST;
-                               goto out;
+                               goto undepend;
                        }
                        /*
                         * In order to ensure individual vhost-scsi configfs
@@ -1442,9 +1621,8 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs,
                        ret = target_depend_item(&se_tpg->tpg_group.cg_item);
                        if (ret) {
                                pr_warn("target_depend_item() failed: %d\n", ret);
-                               kfree(vs_tpg);
                                mutex_unlock(&tpg->tv_tpg_mutex);
-                               goto out;
+                               goto undepend;
                        }
                        tpg->tv_tpg_vhost_count++;
                        tpg->vhost_scsi = vs;
@@ -1457,6 +1635,16 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs,
        if (match) {
                memcpy(vs->vs_vhost_wwpn, t->vhost_wwpn,
                       sizeof(vs->vs_vhost_wwpn));
+
+               for (i = VHOST_SCSI_VQ_IO; i < VHOST_SCSI_MAX_VQ; i++) {
+                       vq = &vs->vqs[i].vq;
+                       if (!vhost_vq_is_setup(vq))
+                               continue;
+
+                       if (vhost_scsi_setup_vq_cmds(vq, vq->num))
+                               goto destroy_vq_cmds;
+               }
+
                for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) {
                        vq = &vs->vqs[i].vq;
                        mutex_lock(&vq->mutex);
@@ -1476,7 +1664,22 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs,
        vhost_scsi_flush(vs);
        kfree(vs->vs_tpg);
        vs->vs_tpg = vs_tpg;
+       goto out;
 
+destroy_vq_cmds:
+       for (i--; i >= VHOST_SCSI_VQ_IO; i--) {
+               if (!vhost_vq_get_backend(&vs->vqs[i].vq))
+                       vhost_scsi_destroy_vq_cmds(&vs->vqs[i].vq);
+       }
+undepend:
+       for (i = 0; i < VHOST_SCSI_MAX_TARGET; i++) {
+               tpg = vs_tpg[i];
+               if (tpg) {
+                       tpg->tv_tpg_vhost_count--;
+                       target_undepend_item(&tpg->se_tpg.tpg_group.cg_item);
+               }
+       }
+       kfree(vs_tpg);
 out:
        mutex_unlock(&vs->dev.mutex);
        mutex_unlock(&vhost_scsi_mutex);
@@ -1549,6 +1752,12 @@ vhost_scsi_clear_endpoint(struct vhost_scsi *vs,
                        mutex_lock(&vq->mutex);
                        vhost_vq_set_backend(vq, NULL);
                        mutex_unlock(&vq->mutex);
+                       /*
+                        * Make sure cmds are not running before tearing them
+                        * down.
+                        */
+                       vhost_scsi_flush(vs);
+                       vhost_scsi_destroy_vq_cmds(vq);
                }
        }
        /*
@@ -1811,11 +2020,19 @@ static int vhost_scsi_port_link(struct se_portal_group *se_tpg,
 {
        struct vhost_scsi_tpg *tpg = container_of(se_tpg,
                                struct vhost_scsi_tpg, se_tpg);
+       struct vhost_scsi_tmf *tmf;
+
+       tmf = kzalloc(sizeof(*tmf), GFP_KERNEL);
+       if (!tmf)
+               return -ENOMEM;
+       INIT_LIST_HEAD(&tmf->queue_entry);
+       vhost_work_init(&tmf->vwork, vhost_scsi_tmf_resp_work);
 
        mutex_lock(&vhost_scsi_mutex);
 
        mutex_lock(&tpg->tv_tpg_mutex);
        tpg->tv_tpg_port_count++;
+       list_add_tail(&tmf->queue_entry, &tpg->tmf_queue);
        mutex_unlock(&tpg->tv_tpg_mutex);
 
        vhost_scsi_hotplug(tpg, lun);
@@ -1830,11 +2047,16 @@ static void vhost_scsi_port_unlink(struct se_portal_group *se_tpg,
 {
        struct vhost_scsi_tpg *tpg = container_of(se_tpg,
                                struct vhost_scsi_tpg, se_tpg);
+       struct vhost_scsi_tmf *tmf;
 
        mutex_lock(&vhost_scsi_mutex);
 
        mutex_lock(&tpg->tv_tpg_mutex);
        tpg->tv_tpg_port_count--;
+       tmf = list_first_entry(&tpg->tmf_queue, struct vhost_scsi_tmf,
+                              queue_entry);
+       list_del(&tmf->queue_entry);
+       kfree(tmf);
        mutex_unlock(&tpg->tv_tpg_mutex);
 
        vhost_scsi_hotunplug(tpg, lun);
@@ -1842,23 +2064,6 @@ static void vhost_scsi_port_unlink(struct se_portal_group *se_tpg,
        mutex_unlock(&vhost_scsi_mutex);
 }
 
-static void vhost_scsi_free_cmd_map_res(struct se_session *se_sess)
-{
-       struct vhost_scsi_cmd *tv_cmd;
-       unsigned int i;
-
-       if (!se_sess->sess_cmd_map)
-               return;
-
-       for (i = 0; i < VHOST_SCSI_DEFAULT_TAGS; i++) {
-               tv_cmd = &((struct vhost_scsi_cmd *)se_sess->sess_cmd_map)[i];
-
-               kfree(tv_cmd->tvc_sgl);
-               kfree(tv_cmd->tvc_prot_sgl);
-               kfree(tv_cmd->tvc_upages);
-       }
-}
-
 static ssize_t vhost_scsi_tpg_attrib_fabric_prot_type_store(
                struct config_item *item, const char *page, size_t count)
 {
@@ -1898,45 +2103,6 @@ static struct configfs_attribute *vhost_scsi_tpg_attrib_attrs[] = {
        NULL,
 };
 
-static int vhost_scsi_nexus_cb(struct se_portal_group *se_tpg,
-                              struct se_session *se_sess, void *p)
-{
-       struct vhost_scsi_cmd *tv_cmd;
-       unsigned int i;
-
-       for (i = 0; i < VHOST_SCSI_DEFAULT_TAGS; i++) {
-               tv_cmd = &((struct vhost_scsi_cmd *)se_sess->sess_cmd_map)[i];
-
-               tv_cmd->tvc_sgl = kcalloc(VHOST_SCSI_PREALLOC_SGLS,
-                                         sizeof(struct scatterlist),
-                                         GFP_KERNEL);
-               if (!tv_cmd->tvc_sgl) {
-                       pr_err("Unable to allocate tv_cmd->tvc_sgl\n");
-                       goto out;
-               }
-
-               tv_cmd->tvc_upages = kcalloc(VHOST_SCSI_PREALLOC_UPAGES,
-                                            sizeof(struct page *),
-                                            GFP_KERNEL);
-               if (!tv_cmd->tvc_upages) {
-                       pr_err("Unable to allocate tv_cmd->tvc_upages\n");
-                       goto out;
-               }
-
-               tv_cmd->tvc_prot_sgl = kcalloc(VHOST_SCSI_PREALLOC_PROT_SGLS,
-                                              sizeof(struct scatterlist),
-                                              GFP_KERNEL);
-               if (!tv_cmd->tvc_prot_sgl) {
-                       pr_err("Unable to allocate tv_cmd->tvc_prot_sgl\n");
-                       goto out;
-               }
-       }
-       return 0;
-out:
-       vhost_scsi_free_cmd_map_res(se_sess);
-       return -ENOMEM;
-}
-
 static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
                                const char *name)
 {
@@ -1960,12 +2126,9 @@ static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
         * struct se_node_acl for the vhost_scsi struct se_portal_group with
         * the SCSI Initiator port name of the passed configfs group 'name'.
         */
-       tv_nexus->tvn_se_sess = target_setup_session(&tpg->se_tpg,
-                                       VHOST_SCSI_DEFAULT_TAGS,
-                                       sizeof(struct vhost_scsi_cmd),
+       tv_nexus->tvn_se_sess = target_setup_session(&tpg->se_tpg, 0, 0,
                                        TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS,
-                                       (unsigned char *)name, tv_nexus,
-                                       vhost_scsi_nexus_cb);
+                                       (unsigned char *)name, tv_nexus, NULL);
        if (IS_ERR(tv_nexus->tvn_se_sess)) {
                mutex_unlock(&tpg->tv_tpg_mutex);
                kfree(tv_nexus);
@@ -2015,7 +2178,6 @@ static int vhost_scsi_drop_nexus(struct vhost_scsi_tpg *tpg)
                " %s Initiator Port: %s\n", vhost_scsi_dump_proto_id(tpg->tport),
                tv_nexus->tvn_se_sess->se_node_acl->initiatorname);
 
-       vhost_scsi_free_cmd_map_res(se_sess);
        /*
         * Release the SCSI I_T Nexus to the emulated vhost Target Port
         */
@@ -2155,6 +2317,7 @@ vhost_scsi_make_tpg(struct se_wwn *wwn, const char *name)
        }
        mutex_init(&tpg->tv_tpg_mutex);
        INIT_LIST_HEAD(&tpg->tv_tpg_list);
+       INIT_LIST_HEAD(&tpg->tmf_queue);
        tpg->tport = tport;
        tpg->tport_tpgt = tpgt;
 
index 5c835a2..a262e12 100644 (file)
@@ -304,6 +304,12 @@ static void vhost_vring_call_reset(struct vhost_vring_call *call_ctx)
        memset(&call_ctx->producer, 0x0, sizeof(struct irq_bypass_producer));
 }
 
+bool vhost_vq_is_setup(struct vhost_virtqueue *vq)
+{
+       return vq->avail && vq->desc && vq->used && vhost_vq_access_ok(vq);
+}
+EXPORT_SYMBOL_GPL(vhost_vq_is_setup);
+
 static void vhost_vq_reset(struct vhost_dev *dev,
                           struct vhost_virtqueue *vq)
 {
index e016cd3..b063324 100644 (file)
@@ -190,6 +190,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *,
                      struct vhost_log *log, unsigned int *log_num);
 void vhost_discard_vq_desc(struct vhost_virtqueue *, int n);
 
+bool vhost_vq_is_setup(struct vhost_virtqueue *vq);
 int vhost_vq_init_access(struct vhost_virtqueue *);
 int vhost_add_used(struct vhost_virtqueue *, unsigned int head, int len);
 int vhost_add_used_n(struct vhost_virtqueue *, struct vring_used_elem *heads,
index e36fb1a..c8b0ae6 100644 (file)
@@ -47,6 +47,7 @@
 
 #include <linux/module.h>
 #include <linux/kernel.h>
+#include <linux/vmalloc.h>
 #include <linux/init.h>
 #include <linux/completion.h>
 #include <linux/fb.h>
@@ -1092,7 +1093,12 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info)
                goto err1;
        }
 
-       fb_virt = ioremap(par->mem->start, screen_fb_size);
+       /*
+        * Map the VRAM cacheable for performance. This is also required for
+        * VM Connect to display properly for ARM64 Linux VM, as the host also
+        * maps the VRAM cacheable.
+        */
+       fb_virt = ioremap_cache(par->mem->start, screen_fb_size);
        if (!fb_virt)
                goto err2;
 
index f06622b..f1964ea 100644 (file)
@@ -1505,10 +1505,8 @@ static __poll_t ne_enclave_poll(struct file *file, poll_table *wait)
 
        poll_wait(file, &ne_enclave->eventq, wait);
 
-       if (!ne_enclave->has_event)
-               return mask;
-
-       mask = POLLHUP;
+       if (ne_enclave->has_event)
+               mask |= EPOLLHUP;
 
        return mask;
 }
index 71ce1b7..2b385c1 100644 (file)
@@ -395,8 +395,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
         */
        trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
 
-       map = swiotlb_tbl_map_single(dev, virt_to_phys(xen_io_tlb_start),
-                                    phys, size, size, dir, attrs);
+       map = swiotlb_tbl_map_single(dev, phys, size, size, dir, attrs);
        if (map == (phys_addr_t)DMA_MAPPING_ERROR)
                return DMA_MAPPING_ERROR;
 
index 1bb5b9d..9068d55 100644 (file)
@@ -823,6 +823,7 @@ static struct inode *afs_do_lookup(struct inode *dir, struct dentry *dentry,
                                vp->cb_break_before = afs_calc_vnode_cb_break(vnode);
                                vp->vnode = vnode;
                                vp->put_vnode = true;
+                               vp->speculative = true; /* vnode not locked */
                        }
                }
        }
index 0fe8844..b0d7b89 100644 (file)
@@ -294,6 +294,13 @@ void afs_vnode_commit_status(struct afs_operation *op, struct afs_vnode_param *v
                        op->flags &= ~AFS_OPERATION_DIR_CONFLICT;
                }
        } else if (vp->scb.have_status) {
+               if (vp->dv_before + vp->dv_delta != vp->scb.status.data_version &&
+                   vp->speculative)
+                       /* Ignore the result of a speculative bulk status fetch
+                        * if it splits around a modification op, thereby
+                        * appearing to regress the data version.
+                        */
+                       goto out;
                afs_apply_status(op, vp);
                if (vp->scb.have_cb)
                        afs_apply_callback(op, vp);
@@ -305,6 +312,7 @@ void afs_vnode_commit_status(struct afs_operation *op, struct afs_vnode_param *v
                }
        }
 
+out:
        write_sequnlock(&vnode->cb_lock);
 
        if (vp->scb.have_status)
index 14d5d75..0d150a2 100644 (file)
@@ -755,6 +755,7 @@ struct afs_vnode_param {
        bool                    update_ctime:1; /* Need to update the ctime */
        bool                    set_size:1;     /* Must update i_size */
        bool                    op_unlinked:1;  /* True if file was unlinked by op */
+       bool                    speculative:1;  /* T if speculative status fetch (no vnode lock) */
 };
 
 /*
index 5037120..c9195fc 100644 (file)
@@ -169,11 +169,14 @@ int afs_write_end(struct file *file, struct address_space *mapping,
        unsigned int f, from = pos & (PAGE_SIZE - 1);
        unsigned int t, to = from + copied;
        loff_t i_size, maybe_i_size;
-       int ret;
+       int ret = 0;
 
        _enter("{%llx:%llu},{%lx}",
               vnode->fid.vid, vnode->fid.vnode, page->index);
 
+       if (copied == 0)
+               goto out;
+
        maybe_i_size = pos + copied;
 
        i_size = i_size_read(&vnode->vfs_inode);
index 38884d6..95c573d 100644 (file)
@@ -148,11 +148,6 @@ static const struct xattr_handler afs_xattr_afs_acl_handler = {
        .set    = afs_xattr_set_acl,
 };
 
-static void yfs_acl_put(struct afs_operation *op)
-{
-       yfs_free_opaque_acl(op->yacl);
-}
-
 static const struct afs_operation_ops yfs_fetch_opaque_acl_operation = {
        .issue_yfs_rpc  = yfs_fs_fetch_opaque_acl,
        .success        = afs_acl_success,
@@ -246,7 +241,7 @@ error:
 static const struct afs_operation_ops yfs_store_opaque_acl2_operation = {
        .issue_yfs_rpc  = yfs_fs_store_opaque_acl2,
        .success        = afs_acl_success,
-       .put            = yfs_acl_put,
+       .put            = afs_acl_put,
 };
 
 /*
index 3b1239b..bd787e7 100644 (file)
@@ -1990,6 +1990,7 @@ void yfs_fs_store_opaque_acl2(struct afs_operation *op)
        memcpy(bp, acl->data, acl->size);
        if (acl->size != size)
                memset((void *)bp + acl->size, 0, size - acl->size);
+       bp += size / sizeof(__be32);
        yfs_check_req(call, bp);
 
        trace_afs_make_fs_call(call, &vp->fid);
index c45c20d..6a21d89 100644 (file)
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1572,7 +1572,7 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb,
                 * we return to userspace.
                 */
                if (S_ISREG(file_inode(file)->i_mode)) {
-                       __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, true);
+                       sb_start_write(file_inode(file)->i_sb);
                        __sb_writers_release(file_inode(file)->i_sb, SB_FREEZE_WRITE);
                }
                req->ki_flags |= IOCB_WRITE;
index 7e1549a..bc920af 100644 (file)
@@ -511,7 +511,8 @@ again:
                                /*DEFAULT_RATELIMIT_BURST*/ 1);
                if (__ratelimit(&_rs))
                        WARN(1, KERN_DEBUG
-                               "BTRFS: block rsv returned %d\n", ret);
+                               "BTRFS: block rsv %d returned %d\n",
+                               block_rsv->type, ret);
        }
 try_reserve:
        ret = btrfs_reserve_metadata_bytes(root, block_rsv, blocksize,
index 5b9e3f3..1063853 100644 (file)
@@ -91,6 +91,17 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
        ret = btrfs_search_slot(NULL, dev_root, &key, path, 0, 0);
        if (ret) {
 no_valid_dev_replace_entry_found:
+               /*
+                * We don't have a replace item or it's corrupted.  If there is
+                * a replace target, fail the mount.
+                */
+               if (btrfs_find_device(fs_info->fs_devices,
+                                     BTRFS_DEV_REPLACE_DEVID, NULL, NULL, false)) {
+                       btrfs_err(fs_info,
+                       "found replace target device without a valid replace item");
+                       ret = -EUCLEAN;
+                       goto out;
+               }
                ret = 0;
                dev_replace->replace_state =
                        BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED;
@@ -143,8 +154,19 @@ no_valid_dev_replace_entry_found:
        case BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED:
        case BTRFS_IOCTL_DEV_REPLACE_STATE_FINISHED:
        case BTRFS_IOCTL_DEV_REPLACE_STATE_CANCELED:
-               dev_replace->srcdev = NULL;
-               dev_replace->tgtdev = NULL;
+               /*
+                * We don't have an active replace item but if there is a
+                * replace target, fail the mount.
+                */
+               if (btrfs_find_device(fs_info->fs_devices,
+                                     BTRFS_DEV_REPLACE_DEVID, NULL, NULL, false)) {
+                       btrfs_err(fs_info,
+                       "replace devid present without an active replace item");
+                       ret = -EUCLEAN;
+               } else {
+                       dev_replace->srcdev = NULL;
+                       dev_replace->tgtdev = NULL;
+               }
                break;
        case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED:
        case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
index ab408a2..69a3841 100644 (file)
@@ -1274,6 +1274,7 @@ static int cluster_pages_for_defrag(struct inode *inode,
        u64 page_start;
        u64 page_end;
        u64 page_cnt;
+       u64 start = (u64)start_index << PAGE_SHIFT;
        int ret;
        int i;
        int i_done;
@@ -1290,8 +1291,7 @@ static int cluster_pages_for_defrag(struct inode *inode,
        page_cnt = min_t(u64, (u64)num_pages, (u64)file_end - start_index + 1);
 
        ret = btrfs_delalloc_reserve_space(BTRFS_I(inode), &data_reserved,
-                       start_index << PAGE_SHIFT,
-                       page_cnt << PAGE_SHIFT);
+                       start, page_cnt << PAGE_SHIFT);
        if (ret)
                return ret;
        i_done = 0;
@@ -1380,8 +1380,7 @@ again:
                btrfs_mod_outstanding_extents(BTRFS_I(inode), 1);
                spin_unlock(&BTRFS_I(inode)->lock);
                btrfs_delalloc_release_space(BTRFS_I(inode), data_reserved,
-                               start_index << PAGE_SHIFT,
-                               (page_cnt - i_done) << PAGE_SHIFT, true);
+                               start, (page_cnt - i_done) << PAGE_SHIFT, true);
        }
 
 
@@ -1408,8 +1407,7 @@ out:
                put_page(pages[i]);
        }
        btrfs_delalloc_release_space(BTRFS_I(inode), data_reserved,
-                       start_index << PAGE_SHIFT,
-                       page_cnt << PAGE_SHIFT, true);
+                       start, page_cnt << PAGE_SHIFT, true);
        btrfs_delalloc_release_extents(BTRFS_I(inode), page_cnt << PAGE_SHIFT);
        extent_changeset_free(data_reserved);
        return ret;
index c54ea65..77c5474 100644 (file)
@@ -3435,24 +3435,20 @@ static int qgroup_unreserve_range(struct btrfs_inode *inode,
 {
        struct rb_node *node;
        struct rb_node *next;
-       struct ulist_node *entry = NULL;
+       struct ulist_node *entry;
        int ret = 0;
 
        node = reserved->range_changed.root.rb_node;
+       if (!node)
+               return 0;
        while (node) {
                entry = rb_entry(node, struct ulist_node, rb_node);
                if (entry->val < start)
                        node = node->rb_right;
-               else if (entry)
-                       node = node->rb_left;
                else
-                       break;
+                       node = node->rb_left;
        }
 
-       /* Empty changeset */
-       if (!entry)
-               return 0;
-
        if (entry->val > start && rb_prev(&entry->rb_node))
                entry = rb_entry(rb_prev(&entry->rb_node), struct ulist_node,
                                 rb_node);
index 7f03dbe..78693d3 100644 (file)
@@ -860,6 +860,7 @@ int btrfs_ref_tree_mod(struct btrfs_fs_info *fs_info,
 "dropping a ref for a root that doesn't have a ref on the block");
                        dump_block_entry(fs_info, be);
                        dump_ref_action(fs_info, ra);
+                       kfree(ref);
                        kfree(ra);
                        goto out_unlock;
                }
index 3602806..9ba92d8 100644 (file)
@@ -1648,6 +1648,7 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc,
        struct btrfs_root_item *root_item;
        struct btrfs_path *path;
        struct extent_buffer *leaf;
+       int reserve_level;
        int level;
        int max_level;
        int replaced = 0;
@@ -1696,7 +1697,8 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc,
         * Thus the needed metadata size is at most root_level * nodesize,
         * and * 2 since we have two trees to COW.
         */
-       min_reserved = fs_info->nodesize * btrfs_root_level(root_item) * 2;
+       reserve_level = max_t(int, 1, btrfs_root_level(root_item));
+       min_reserved = fs_info->nodesize * reserve_level * 2;
        memset(&next_key, 0, sizeof(next_key));
 
        while (1) {
index cf63f1e..e71e758 100644 (file)
@@ -3866,8 +3866,9 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
        if (!is_dev_replace && !readonly &&
            !test_bit(BTRFS_DEV_STATE_WRITEABLE, &dev->dev_state)) {
                mutex_unlock(&fs_info->fs_devices->device_list_mutex);
-               btrfs_err_in_rcu(fs_info, "scrub: device %s is not writable",
-                               rcu_str_deref(dev->name));
+               btrfs_err_in_rcu(fs_info,
+                       "scrub on devid %llu: filesystem on %s is not writable",
+                                devid, rcu_str_deref(dev->name));
                ret = -EROFS;
                goto out;
        }
index b1e4807..a6406b3 100644 (file)
@@ -1056,22 +1056,13 @@ static void __btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices,
                        continue;
                }
 
-               if (device->devid == BTRFS_DEV_REPLACE_DEVID) {
-                       /*
-                        * In the first step, keep the device which has
-                        * the correct fsid and the devid that is used
-                        * for the dev_replace procedure.
-                        * In the second step, the dev_replace state is
-                        * read from the device tree and it is known
-                        * whether the procedure is really active or
-                        * not, which means whether this device is
-                        * used or whether it should be removed.
-                        */
-                       if (step == 0 || test_bit(BTRFS_DEV_STATE_REPLACE_TGT,
-                                                 &device->dev_state)) {
-                               continue;
-                       }
-               }
+               /*
+                * We have already validated the presence of BTRFS_DEV_REPLACE_DEVID,
+                * in btrfs_init_dev_replace() so just continue.
+                */
+               if (device->devid == BTRFS_DEV_REPLACE_DEVID)
+                       continue;
+
                if (device->bdev) {
                        blkdev_put(device->bdev, device->mode);
                        device->bdev = NULL;
@@ -1080,9 +1071,6 @@ static void __btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices,
                if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state)) {
                        list_del_init(&device->dev_alloc_list);
                        clear_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);
-                       if (!test_bit(BTRFS_DEV_STATE_REPLACE_TGT,
-                                     &device->dev_state))
-                               fs_devices->rw_devices--;
                }
                list_del_init(&device->dev_list);
                fs_devices->num_devices--;
index 5027bbd..ded4229 100644 (file)
@@ -4074,7 +4074,7 @@ void ceph_handle_caps(struct ceph_mds_session *session,
             vino.snap, inode);
 
        mutex_lock(&session->s_mutex);
-       session->s_seq++;
+       inc_session_sequence(session);
        dout(" mds%d seq %lld cap seq %u\n", session->s_mds, session->s_seq,
             (unsigned)seq);
 
index 08f1c0c..8f1d750 100644 (file)
@@ -4231,7 +4231,7 @@ static void handle_lease(struct ceph_mds_client *mdsc,
             dname.len, dname.name);
 
        mutex_lock(&session->s_mutex);
-       session->s_seq++;
+       inc_session_sequence(session);
 
        if (!inode) {
                dout("handle_lease no inode %llx\n", vino.ino);
@@ -4385,28 +4385,48 @@ static void maybe_recover_session(struct ceph_mds_client *mdsc)
 
 bool check_session_state(struct ceph_mds_session *s)
 {
-       if (s->s_state == CEPH_MDS_SESSION_CLOSING) {
-               dout("resending session close request for mds%d\n",
-                               s->s_mds);
-               request_close_session(s);
-               return false;
-       }
-       if (s->s_ttl && time_after(jiffies, s->s_ttl)) {
-               if (s->s_state == CEPH_MDS_SESSION_OPEN) {
+       switch (s->s_state) {
+       case CEPH_MDS_SESSION_OPEN:
+               if (s->s_ttl && time_after(jiffies, s->s_ttl)) {
                        s->s_state = CEPH_MDS_SESSION_HUNG;
                        pr_info("mds%d hung\n", s->s_mds);
                }
-       }
-       if (s->s_state == CEPH_MDS_SESSION_NEW ||
-           s->s_state == CEPH_MDS_SESSION_RESTARTING ||
-           s->s_state == CEPH_MDS_SESSION_CLOSED ||
-           s->s_state == CEPH_MDS_SESSION_REJECTED)
-               /* this mds is failed or recovering, just wait */
+               break;
+       case CEPH_MDS_SESSION_CLOSING:
+               /* Should never reach this when we're unmounting */
+               WARN_ON_ONCE(true);
+               fallthrough;
+       case CEPH_MDS_SESSION_NEW:
+       case CEPH_MDS_SESSION_RESTARTING:
+       case CEPH_MDS_SESSION_CLOSED:
+       case CEPH_MDS_SESSION_REJECTED:
                return false;
+       }
 
        return true;
 }
 
+/*
+ * If the sequence is incremented while we're waiting on a REQUEST_CLOSE reply,
+ * then we need to retransmit that request.
+ */
+void inc_session_sequence(struct ceph_mds_session *s)
+{
+       lockdep_assert_held(&s->s_mutex);
+
+       s->s_seq++;
+
+       if (s->s_state == CEPH_MDS_SESSION_CLOSING) {
+               int ret;
+
+               dout("resending session close request for mds%d\n", s->s_mds);
+               ret = request_close_session(s);
+               if (ret < 0)
+                       pr_err("unable to close session to mds%d: %d\n",
+                              s->s_mds, ret);
+       }
+}
+
 /*
  * delayed work -- periodically trim expired leases, renew caps with mds
  */
index cbf8af4..f5adbeb 100644 (file)
@@ -480,6 +480,7 @@ struct ceph_mds_client {
 extern const char *ceph_mds_op_name(int op);
 
 extern bool check_session_state(struct ceph_mds_session *s);
+void inc_session_sequence(struct ceph_mds_session *s);
 
 extern struct ceph_mds_session *
 __ceph_lookup_mds_session(struct ceph_mds_client *, int mds);
index 83cb4f2..9b785f1 100644 (file)
@@ -53,7 +53,7 @@ void ceph_handle_quota(struct ceph_mds_client *mdsc,
 
        /* increment msg sequence number */
        mutex_lock(&session->s_mutex);
-       session->s_seq++;
+       inc_session_sequence(session);
        mutex_unlock(&session->s_mutex);
 
        /* lookup inode */
index 0da39c1..b611f82 100644 (file)
@@ -873,7 +873,7 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
             ceph_snap_op_name(op), split, trace_len);
 
        mutex_lock(&session->s_mutex);
-       session->s_seq++;
+       inc_session_sequence(session);
        mutex_unlock(&session->s_mutex);
 
        down_write(&mdsc->snap_rwsem);
index 23b21e9..ef4784e 100644 (file)
@@ -1266,6 +1266,7 @@ cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr,
                cifs_dbg(VFS, "%s: error %d getting sec desc\n", __func__, rc);
        } else if (mode_from_special_sid) {
                rc = parse_sec_desc(cifs_sb, pntsd, acllen, fattr, true);
+               kfree(pntsd);
        } else {
                /* get approximated mode from ACL */
                rc = parse_sec_desc(cifs_sb, pntsd, acllen, fattr, false);
index 504766c..dab94f6 100644 (file)
@@ -264,7 +264,7 @@ smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
 }
 
 static struct mid_q_entry *
-smb2_find_mid(struct TCP_Server_Info *server, char *buf)
+__smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue)
 {
        struct mid_q_entry *mid;
        struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
@@ -281,6 +281,10 @@ smb2_find_mid(struct TCP_Server_Info *server, char *buf)
                    (mid->mid_state == MID_REQUEST_SUBMITTED) &&
                    (mid->command == shdr->Command)) {
                        kref_get(&mid->refcount);
+                       if (dequeue) {
+                               list_del_init(&mid->qhead);
+                               mid->mid_flags |= MID_DELETED;
+                       }
                        spin_unlock(&GlobalMid_Lock);
                        return mid;
                }
@@ -289,6 +293,18 @@ smb2_find_mid(struct TCP_Server_Info *server, char *buf)
        return NULL;
 }
 
+static struct mid_q_entry *
+smb2_find_mid(struct TCP_Server_Info *server, char *buf)
+{
+       return __smb2_find_mid(server, buf, false);
+}
+
+static struct mid_q_entry *
+smb2_find_dequeue_mid(struct TCP_Server_Info *server, char *buf)
+{
+       return __smb2_find_mid(server, buf, true);
+}
+
 static void
 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
 {
@@ -4356,7 +4372,8 @@ init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
 static int
 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
                 char *buf, unsigned int buf_len, struct page **pages,
-                unsigned int npages, unsigned int page_data_size)
+                unsigned int npages, unsigned int page_data_size,
+                bool is_offloaded)
 {
        unsigned int data_offset;
        unsigned int data_len;
@@ -4378,7 +4395,8 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
 
        if (server->ops->is_session_expired &&
            server->ops->is_session_expired(buf)) {
-               cifs_reconnect(server);
+               if (!is_offloaded)
+                       cifs_reconnect(server);
                return -1;
        }
 
@@ -4402,7 +4420,10 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
                cifs_dbg(FYI, "%s: server returned error %d\n",
                         __func__, rdata->result);
                /* normal error on read response */
-               dequeue_mid(mid, false);
+               if (is_offloaded)
+                       mid->mid_state = MID_RESPONSE_RECEIVED;
+               else
+                       dequeue_mid(mid, false);
                return 0;
        }
 
@@ -4426,7 +4447,10 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
                cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
                         __func__, data_offset);
                rdata->result = -EIO;
-               dequeue_mid(mid, rdata->result);
+               if (is_offloaded)
+                       mid->mid_state = MID_RESPONSE_MALFORMED;
+               else
+                       dequeue_mid(mid, rdata->result);
                return 0;
        }
 
@@ -4442,21 +4466,30 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
                        cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
                                 __func__, data_offset);
                        rdata->result = -EIO;
-                       dequeue_mid(mid, rdata->result);
+                       if (is_offloaded)
+                               mid->mid_state = MID_RESPONSE_MALFORMED;
+                       else
+                               dequeue_mid(mid, rdata->result);
                        return 0;
                }
 
                if (data_len > page_data_size - pad_len) {
                        /* data_len is corrupt -- discard frame */
                        rdata->result = -EIO;
-                       dequeue_mid(mid, rdata->result);
+                       if (is_offloaded)
+                               mid->mid_state = MID_RESPONSE_MALFORMED;
+                       else
+                               dequeue_mid(mid, rdata->result);
                        return 0;
                }
 
                rdata->result = init_read_bvec(pages, npages, page_data_size,
                                               cur_off, &bvec);
                if (rdata->result != 0) {
-                       dequeue_mid(mid, rdata->result);
+                       if (is_offloaded)
+                               mid->mid_state = MID_RESPONSE_MALFORMED;
+                       else
+                               dequeue_mid(mid, rdata->result);
                        return 0;
                }
 
@@ -4471,7 +4504,10 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
                /* read response payload cannot be in both buf and pages */
                WARN_ONCE(1, "buf can not contain only a part of read data");
                rdata->result = -EIO;
-               dequeue_mid(mid, rdata->result);
+               if (is_offloaded)
+                       mid->mid_state = MID_RESPONSE_MALFORMED;
+               else
+                       dequeue_mid(mid, rdata->result);
                return 0;
        }
 
@@ -4482,7 +4518,10 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
        if (length < 0)
                return length;
 
-       dequeue_mid(mid, false);
+       if (is_offloaded)
+               mid->mid_state = MID_RESPONSE_RECEIVED;
+       else
+               dequeue_mid(mid, false);
        return length;
 }
 
@@ -4511,15 +4550,34 @@ static void smb2_decrypt_offload(struct work_struct *work)
        }
 
        dw->server->lstrp = jiffies;
-       mid = smb2_find_mid(dw->server, dw->buf);
+       mid = smb2_find_dequeue_mid(dw->server, dw->buf);
        if (mid == NULL)
                cifs_dbg(FYI, "mid not found\n");
        else {
                mid->decrypted = true;
                rc = handle_read_data(dw->server, mid, dw->buf,
                                      dw->server->vals->read_rsp_size,
-                                     dw->ppages, dw->npages, dw->len);
-               mid->callback(mid);
+                                     dw->ppages, dw->npages, dw->len,
+                                     true);
+               if (rc >= 0) {
+#ifdef CONFIG_CIFS_STATS2
+                       mid->when_received = jiffies;
+#endif
+                       mid->callback(mid);
+               } else {
+                       spin_lock(&GlobalMid_Lock);
+                       if (dw->server->tcpStatus == CifsNeedReconnect) {
+                               mid->mid_state = MID_RETRY_NEEDED;
+                               spin_unlock(&GlobalMid_Lock);
+                               mid->callback(mid);
+                       } else {
+                               mid->mid_state = MID_REQUEST_SUBMITTED;
+                               mid->mid_flags &= ~(MID_DELETED);
+                               list_add_tail(&mid->qhead,
+                                       &dw->server->pending_mid_q);
+                               spin_unlock(&GlobalMid_Lock);
+                       }
+               }
                cifs_mid_q_entry_release(mid);
        }
 
@@ -4622,7 +4680,7 @@ non_offloaded_decrypt:
                (*mid)->decrypted = true;
                rc = handle_read_data(server, *mid, buf,
                                      server->vals->read_rsp_size,
-                                     pages, npages, len);
+                                     pages, npages, len, false);
        }
 
 free_pages:
@@ -4765,7 +4823,7 @@ smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
        char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
 
        return handle_read_data(server, mid, buf, server->pdu_size,
-                               NULL, 0, 0);
+                               NULL, 0, 0, false);
 }
 
 static int
index 89bffa8..c57bebf 100644 (file)
@@ -74,7 +74,7 @@ int fscrypt_select_encryption_impl(struct fscrypt_info *ci)
        int i;
 
        /* The file must need contents encryption, not filenames encryption */
-       if (!fscrypt_needs_contents_encryption(inode))
+       if (!S_ISREG(inode->i_mode))
                return 0;
 
        /* The crypto mode must have a blk-crypto counterpart */
index d3c3e5d..d595abb 100644 (file)
@@ -269,9 +269,7 @@ unlock:
         * New inodes may not have an inode number assigned yet.
         * Hashing their inode number is delayed until later.
         */
-       if (ci->ci_inode->i_ino == 0)
-               WARN_ON(!(ci->ci_inode->i_state & I_CREATING));
-       else
+       if (ci->ci_inode->i_ino)
                fscrypt_hash_inode_number(ci, mk);
        return 0;
 }
index 15880a6..f943fd0 100644 (file)
@@ -21,6 +21,7 @@ LIST_HEAD(efivarfs_list);
 static void efivarfs_evict_inode(struct inode *inode)
 {
        clear_inode(inode);
+       kfree(inode->i_private);
 }
 
 static const struct super_operations efivarfs_ops = {
index 139d0be..3e21c0e 100644 (file)
@@ -107,11 +107,9 @@ static struct page *erofs_read_inode(struct inode *inode,
                i_gid_write(inode, le32_to_cpu(die->i_gid));
                set_nlink(inode, le32_to_cpu(die->i_nlink));
 
-               /* ns timestamp */
-               inode->i_mtime.tv_sec = inode->i_ctime.tv_sec =
-                       le64_to_cpu(die->i_ctime);
-               inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec =
-                       le32_to_cpu(die->i_ctime_nsec);
+               /* extended inode has its own timestamp */
+               inode->i_ctime.tv_sec = le64_to_cpu(die->i_ctime);
+               inode->i_ctime.tv_nsec = le32_to_cpu(die->i_ctime_nsec);
 
                inode->i_size = le64_to_cpu(die->i_size);
 
@@ -149,11 +147,9 @@ static struct page *erofs_read_inode(struct inode *inode,
                i_gid_write(inode, le16_to_cpu(dic->i_gid));
                set_nlink(inode, le16_to_cpu(dic->i_nlink));
 
-               /* use build time to derive all file time */
-               inode->i_mtime.tv_sec = inode->i_ctime.tv_sec =
-                       sbi->build_time;
-               inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec =
-                       sbi->build_time_nsec;
+               /* use build time for compact inodes */
+               inode->i_ctime.tv_sec = sbi->build_time;
+               inode->i_ctime.tv_nsec = sbi->build_time_nsec;
 
                inode->i_size = le32_to_cpu(dic->i_size);
                if (erofs_inode_is_data_compressed(vi->datalayout))
@@ -167,6 +163,11 @@ static struct page *erofs_read_inode(struct inode *inode,
                goto err_out;
        }
 
+       inode->i_mtime.tv_sec = inode->i_ctime.tv_sec;
+       inode->i_atime.tv_sec = inode->i_ctime.tv_sec;
+       inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec;
+       inode->i_atime.tv_nsec = inode->i_ctime.tv_nsec;
+
        if (!nblks)
                /* measure inode.i_blocks as generic filesystems */
                inode->i_blocks = roundup(inode->i_size, EROFS_BLKSIZ) >> 9;
index 50912a5..86fd3bf 100644 (file)
@@ -1078,8 +1078,11 @@ out_allocpage:
                cond_resched();
                goto repeat;
        }
-       set_page_private(page, (unsigned long)pcl);
-       SetPagePrivate(page);
+
+       if (tocache) {
+               set_page_private(page, (unsigned long)pcl);
+               SetPagePrivate(page);
+       }
 out:   /* the only exit (for tracing and debugging) */
        return page;
 }
index 45fcdbf..65ecaf9 100644 (file)
@@ -1028,9 +1028,6 @@ struct ext4_inode_info {
                                         * protected by sbi->s_fc_lock.
                                         */
 
-       /* Fast commit subtid when this inode was committed */
-       unsigned int i_fc_committed_subtid;
-
        /* Start of lblk range that needs to be committed in this fast commit */
        ext4_lblk_t i_fc_lblk_start;
 
@@ -1234,13 +1231,13 @@ struct ext4_inode_info {
                                                      blocks */
 #define EXT4_MOUNT2_HURD_COMPAT                0x00000004 /* Support HURD-castrated
                                                      file systems */
-#define EXT4_MOUNT2_DAX_NEVER          0x00000008 /* Do not allow Direct Access */
-#define EXT4_MOUNT2_DAX_INODE          0x00000010 /* For printing options only */
-
 #define EXT4_MOUNT2_EXPLICIT_JOURNAL_CHECKSUM  0x00000008 /* User explicitly
                                                specified journal checksum */
 
 #define EXT4_MOUNT2_JOURNAL_FAST_COMMIT        0x00000010 /* Journal fast commit */
+#define EXT4_MOUNT2_DAX_NEVER          0x00000020 /* Do not allow Direct Access */
+#define EXT4_MOUNT2_DAX_INODE          0x00000040 /* For printing options only */
+
 
 #define clear_opt(sb, opt)             EXT4_SB(sb)->s_mount_opt &= \
                                                ~EXT4_MOUNT_##opt
@@ -1422,16 +1419,6 @@ struct ext4_super_block {
 
 #ifdef __KERNEL__
 
-/*
- * run-time mount flags
- */
-#define EXT4_MF_MNTDIR_SAMPLED         0x0001
-#define EXT4_MF_FS_ABORTED             0x0002  /* Fatal error detected */
-#define EXT4_MF_FC_INELIGIBLE          0x0004  /* Fast commit ineligible */
-#define EXT4_MF_FC_COMMITTING          0x0008  /* File system underoing a fast
-                                                * commit.
-                                                */
-
 #ifdef CONFIG_FS_ENCRYPTION
 #define DUMMY_ENCRYPTION_ENABLED(sbi) ((sbi)->s_dummy_enc_policy.policy != NULL)
 #else
@@ -1466,7 +1453,7 @@ struct ext4_sb_info {
        struct buffer_head * __rcu *s_group_desc;
        unsigned int s_mount_opt;
        unsigned int s_mount_opt2;
-       unsigned int s_mount_flags;
+       unsigned long s_mount_flags;
        unsigned int s_def_mount_opt;
        ext4_fsblk_t s_sb_block;
        atomic64_t s_resv_clusters;
@@ -1694,6 +1681,34 @@ static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
        _v;                                                                \
 })
 
+/*
+ * run-time mount flags
+ */
+enum {
+       EXT4_MF_MNTDIR_SAMPLED,
+       EXT4_MF_FS_ABORTED,     /* Fatal error detected */
+       EXT4_MF_FC_INELIGIBLE,  /* Fast commit ineligible */
+       EXT4_MF_FC_COMMITTING   /* File system underoing a fast
+                                * commit.
+                                */
+};
+
+static inline void ext4_set_mount_flag(struct super_block *sb, int bit)
+{
+       set_bit(bit, &EXT4_SB(sb)->s_mount_flags);
+}
+
+static inline void ext4_clear_mount_flag(struct super_block *sb, int bit)
+{
+       clear_bit(bit, &EXT4_SB(sb)->s_mount_flags);
+}
+
+static inline int ext4_test_mount_flag(struct super_block *sb, int bit)
+{
+       return test_bit(bit, &EXT4_SB(sb)->s_mount_flags);
+}
+
+
 /*
  * Simulate_fail codes
  */
@@ -1863,6 +1878,13 @@ static inline bool ext4_verity_in_progress(struct inode *inode)
 #define EXT4_FEATURE_COMPAT_RESIZE_INODE       0x0010
 #define EXT4_FEATURE_COMPAT_DIR_INDEX          0x0020
 #define EXT4_FEATURE_COMPAT_SPARSE_SUPER2      0x0200
+/*
+ * The reason why "FAST_COMMIT" is a compat feature is that, FS becomes
+ * incompatible only if fast commit blocks are present in the FS. Since we
+ * clear the journal (and thus the fast commit blocks), we don't mark FS as
+ * incompatible. We also have a JBD2 incompat feature, which gets set when
+ * there are fast commit blocks present in the journal.
+ */
 #define EXT4_FEATURE_COMPAT_FAST_COMMIT                0x0400
 #define EXT4_FEATURE_COMPAT_STABLE_INODES      0x0800
 
@@ -2673,7 +2695,8 @@ void ext4_insert_dentry(struct inode *inode,
                        struct ext4_filename *fname);
 static inline void ext4_update_dx_flag(struct inode *inode)
 {
-       if (!ext4_has_feature_dir_index(inode->i_sb)) {
+       if (!ext4_has_feature_dir_index(inode->i_sb) &&
+           ext4_test_inode_flag(inode, EXT4_INODE_INDEX)) {
                /* ext4_iget() should have caught this... */
                WARN_ON_ONCE(ext4_has_feature_metadata_csum(inode->i_sb));
                ext4_clear_inode_flag(inode, EXT4_INODE_INDEX);
@@ -2731,12 +2754,16 @@ extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate);
 int ext4_fc_info_show(struct seq_file *seq, void *v);
 void ext4_fc_init(struct super_block *sb, journal_t *journal);
 void ext4_fc_init_inode(struct inode *inode);
-void ext4_fc_track_range(struct inode *inode, ext4_lblk_t start,
+void ext4_fc_track_range(handle_t *handle, struct inode *inode, ext4_lblk_t start,
                         ext4_lblk_t end);
-void ext4_fc_track_unlink(struct inode *inode, struct dentry *dentry);
-void ext4_fc_track_link(struct inode *inode, struct dentry *dentry);
-void ext4_fc_track_create(struct inode *inode, struct dentry *dentry);
-void ext4_fc_track_inode(struct inode *inode);
+void __ext4_fc_track_unlink(handle_t *handle, struct inode *inode,
+       struct dentry *dentry);
+void __ext4_fc_track_link(handle_t *handle, struct inode *inode,
+       struct dentry *dentry);
+void ext4_fc_track_unlink(handle_t *handle, struct dentry *dentry);
+void ext4_fc_track_link(handle_t *handle, struct dentry *dentry);
+void ext4_fc_track_create(handle_t *handle, struct dentry *dentry);
+void ext4_fc_track_inode(handle_t *handle, struct inode *inode);
 void ext4_fc_mark_ineligible(struct super_block *sb, int reason);
 void ext4_fc_start_ineligible(struct super_block *sb, int reason);
 void ext4_fc_stop_ineligible(struct super_block *sb);
@@ -3452,7 +3479,7 @@ extern int ext4_handle_dirty_dirblock(handle_t *handle, struct inode *inode,
 extern int ext4_ci_compare(const struct inode *parent,
                           const struct qstr *fname,
                           const struct qstr *entry, bool quick);
-extern int __ext4_unlink(struct inode *dir, const struct qstr *d_name,
+extern int __ext4_unlink(handle_t *handle, struct inode *dir, const struct qstr *d_name,
                         struct inode *inode);
 extern int __ext4_link(struct inode *dir, struct inode *inode,
                       struct dentry *dentry);
index 57cfa28..17d7096 100644 (file)
@@ -3724,7 +3724,6 @@ static int ext4_convert_unwritten_extents_endio(handle_t *handle,
        err = ext4_ext_dirty(handle, inode, path + path->p_depth);
 out:
        ext4_ext_show_leaf(inode, path);
-       ext4_fc_track_range(inode, ee_block, ee_block + ee_len - 1);
        return err;
 }
 
@@ -3796,7 +3795,6 @@ convert_initialized_extent(handle_t *handle, struct inode *inode,
        if (*allocated > map->m_len)
                *allocated = map->m_len;
        map->m_len = *allocated;
-       ext4_fc_track_range(inode, ee_block, ee_block + ee_len - 1);
        return 0;
 }
 
@@ -4329,7 +4327,6 @@ got_allocated_blocks:
        map->m_len = ar.len;
        allocated = map->m_len;
        ext4_ext_show_leaf(inode, path);
-       ext4_fc_track_range(inode, map->m_lblk, map->m_lblk + map->m_len - 1);
 out:
        ext4_ext_drop_refs(path);
        kfree(path);
@@ -4602,7 +4599,7 @@ static long ext4_zero_range(struct file *file, loff_t offset,
        ret = ext4_mark_inode_dirty(handle, inode);
        if (unlikely(ret))
                goto out_handle;
-       ext4_fc_track_range(inode, offset >> inode->i_sb->s_blocksize_bits,
+       ext4_fc_track_range(handle, inode, offset >> inode->i_sb->s_blocksize_bits,
                        (offset + len - 1) >> inode->i_sb->s_blocksize_bits);
        /* Zero out partial block at the edges of the range */
        ret = ext4_zero_partial_blocks(handle, inode, offset, len);
@@ -4651,8 +4648,6 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
                     FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE |
                     FALLOC_FL_INSERT_RANGE))
                return -EOPNOTSUPP;
-       ext4_fc_track_range(inode, offset >> blkbits,
-                       (offset + len - 1) >> blkbits);
 
        ext4_fc_start_update(inode);
 
index 8d43058..f2033e1 100644 (file)
@@ -83,7 +83,7 @@
  *
  * Atomicity of commits
  * --------------------
- * In order to gaurantee atomicity during the commit operation, fast commit
+ * In order to guarantee atomicity during the commit operation, fast commit
  * uses "EXT4_FC_TAG_TAIL" tag that marks a fast commit as complete. Tail
  * tag contains CRC of the contents and TID of the transaction after which
  * this fast commit should be applied. Recovery code replays fast commit
@@ -152,7 +152,31 @@ void ext4_fc_init_inode(struct inode *inode)
        INIT_LIST_HEAD(&ei->i_fc_list);
        init_waitqueue_head(&ei->i_fc_wait);
        atomic_set(&ei->i_fc_updates, 0);
-       ei->i_fc_committed_subtid = 0;
+}
+
+/* This function must be called with sbi->s_fc_lock held. */
+static void ext4_fc_wait_committing_inode(struct inode *inode)
+__releases(&EXT4_SB(inode->i_sb)->s_fc_lock)
+{
+       wait_queue_head_t *wq;
+       struct ext4_inode_info *ei = EXT4_I(inode);
+
+#if (BITS_PER_LONG < 64)
+       DEFINE_WAIT_BIT(wait, &ei->i_state_flags,
+                       EXT4_STATE_FC_COMMITTING);
+       wq = bit_waitqueue(&ei->i_state_flags,
+                               EXT4_STATE_FC_COMMITTING);
+#else
+       DEFINE_WAIT_BIT(wait, &ei->i_flags,
+                       EXT4_STATE_FC_COMMITTING);
+       wq = bit_waitqueue(&ei->i_flags,
+                               EXT4_STATE_FC_COMMITTING);
+#endif
+       lockdep_assert_held(&EXT4_SB(inode->i_sb)->s_fc_lock);
+       prepare_to_wait(wq, &wait.wq_entry, TASK_UNINTERRUPTIBLE);
+       spin_unlock(&EXT4_SB(inode->i_sb)->s_fc_lock);
+       schedule();
+       finish_wait(wq, &wait.wq_entry);
 }
 
 /*
@@ -176,22 +200,7 @@ restart:
                goto out;
 
        if (ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) {
-               wait_queue_head_t *wq;
-#if (BITS_PER_LONG < 64)
-               DEFINE_WAIT_BIT(wait, &ei->i_state_flags,
-                               EXT4_STATE_FC_COMMITTING);
-               wq = bit_waitqueue(&ei->i_state_flags,
-                                  EXT4_STATE_FC_COMMITTING);
-#else
-               DEFINE_WAIT_BIT(wait, &ei->i_flags,
-                               EXT4_STATE_FC_COMMITTING);
-               wq = bit_waitqueue(&ei->i_flags,
-                                  EXT4_STATE_FC_COMMITTING);
-#endif
-               prepare_to_wait(wq, &wait.wq_entry, TASK_UNINTERRUPTIBLE);
-               spin_unlock(&EXT4_SB(inode->i_sb)->s_fc_lock);
-               schedule();
-               finish_wait(wq, &wait.wq_entry);
+               ext4_fc_wait_committing_inode(inode);
                goto restart;
        }
 out:
@@ -234,26 +243,10 @@ restart:
        }
 
        if (ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) {
-               wait_queue_head_t *wq;
-#if (BITS_PER_LONG < 64)
-               DEFINE_WAIT_BIT(wait, &ei->i_state_flags,
-                               EXT4_STATE_FC_COMMITTING);
-               wq = bit_waitqueue(&ei->i_state_flags,
-                                  EXT4_STATE_FC_COMMITTING);
-#else
-               DEFINE_WAIT_BIT(wait, &ei->i_flags,
-                               EXT4_STATE_FC_COMMITTING);
-               wq = bit_waitqueue(&ei->i_flags,
-                                  EXT4_STATE_FC_COMMITTING);
-#endif
-               prepare_to_wait(wq, &wait.wq_entry, TASK_UNINTERRUPTIBLE);
-               spin_unlock(&EXT4_SB(inode->i_sb)->s_fc_lock);
-               schedule();
-               finish_wait(wq, &wait.wq_entry);
+               ext4_fc_wait_committing_inode(inode);
                goto restart;
        }
-       if (!list_empty(&ei->i_fc_list))
-               list_del_init(&ei->i_fc_list);
+       list_del_init(&ei->i_fc_list);
        spin_unlock(&EXT4_SB(inode->i_sb)->s_fc_lock);
 }
 
@@ -269,7 +262,7 @@ void ext4_fc_mark_ineligible(struct super_block *sb, int reason)
            (EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY))
                return;
 
-       sbi->s_mount_flags |= EXT4_MF_FC_INELIGIBLE;
+       ext4_set_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
        WARN_ON(reason >= EXT4_FC_REASON_MAX);
        sbi->s_fc_stats.fc_ineligible_reason_count[reason]++;
 }
@@ -302,14 +295,14 @@ void ext4_fc_stop_ineligible(struct super_block *sb)
            (EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY))
                return;
 
-       EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FC_INELIGIBLE;
+       ext4_set_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
        atomic_dec(&EXT4_SB(sb)->s_fc_ineligible_updates);
 }
 
 static inline int ext4_fc_is_ineligible(struct super_block *sb)
 {
-       return (EXT4_SB(sb)->s_mount_flags & EXT4_MF_FC_INELIGIBLE) ||
-               atomic_read(&EXT4_SB(sb)->s_fc_ineligible_updates);
+       return (ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE) ||
+               atomic_read(&EXT4_SB(sb)->s_fc_ineligible_updates));
 }
 
 /*
@@ -323,13 +316,14 @@ static inline int ext4_fc_is_ineligible(struct super_block *sb)
  * If enqueue is set, this function enqueues the inode in fast commit list.
  */
 static int ext4_fc_track_template(
-       struct inode *inode, int (*__fc_track_fn)(struct inode *, void *, bool),
+       handle_t *handle, struct inode *inode,
+       int (*__fc_track_fn)(struct inode *, void *, bool),
        void *args, int enqueue)
 {
-       tid_t running_txn_tid;
        bool update = false;
        struct ext4_inode_info *ei = EXT4_I(inode);
        struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
+       tid_t tid = 0;
        int ret;
 
        if (!test_opt2(inode->i_sb, JOURNAL_FAST_COMMIT) ||
@@ -339,15 +333,13 @@ static int ext4_fc_track_template(
        if (ext4_fc_is_ineligible(inode->i_sb))
                return -EINVAL;
 
-       running_txn_tid = sbi->s_journal ?
-               sbi->s_journal->j_commit_sequence + 1 : 0;
-
+       tid = handle->h_transaction->t_tid;
        mutex_lock(&ei->i_fc_lock);
-       if (running_txn_tid == ei->i_sync_tid) {
+       if (tid == ei->i_sync_tid) {
                update = true;
        } else {
                ext4_fc_reset_inode(inode);
-               ei->i_sync_tid = running_txn_tid;
+               ei->i_sync_tid = tid;
        }
        ret = __fc_track_fn(inode, args, update);
        mutex_unlock(&ei->i_fc_lock);
@@ -358,7 +350,7 @@ static int ext4_fc_track_template(
        spin_lock(&sbi->s_fc_lock);
        if (list_empty(&EXT4_I(inode)->i_fc_list))
                list_add_tail(&EXT4_I(inode)->i_fc_list,
-                               (sbi->s_mount_flags & EXT4_MF_FC_COMMITTING) ?
+                               (ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_COMMITTING)) ?
                                &sbi->s_fc_q[FC_Q_STAGING] :
                                &sbi->s_fc_q[FC_Q_MAIN]);
        spin_unlock(&sbi->s_fc_lock);
@@ -384,7 +376,7 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update)
        mutex_unlock(&ei->i_fc_lock);
        node = kmem_cache_alloc(ext4_fc_dentry_cachep, GFP_NOFS);
        if (!node) {
-               ext4_fc_mark_ineligible(inode->i_sb, EXT4_FC_REASON_MEM);
+               ext4_fc_mark_ineligible(inode->i_sb, EXT4_FC_REASON_NOMEM);
                mutex_lock(&ei->i_fc_lock);
                return -ENOMEM;
        }
@@ -397,7 +389,7 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update)
                if (!node->fcd_name.name) {
                        kmem_cache_free(ext4_fc_dentry_cachep, node);
                        ext4_fc_mark_ineligible(inode->i_sb,
-                               EXT4_FC_REASON_MEM);
+                               EXT4_FC_REASON_NOMEM);
                        mutex_lock(&ei->i_fc_lock);
                        return -ENOMEM;
                }
@@ -411,7 +403,7 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update)
        node->fcd_name.len = dentry->d_name.len;
 
        spin_lock(&sbi->s_fc_lock);
-       if (sbi->s_mount_flags & EXT4_MF_FC_COMMITTING)
+       if (ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_COMMITTING))
                list_add_tail(&node->fcd_list,
                                &sbi->s_fc_dentry_q[FC_Q_STAGING]);
        else
@@ -422,7 +414,8 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update)
        return 0;
 }
 
-void ext4_fc_track_unlink(struct inode *inode, struct dentry *dentry)
+void __ext4_fc_track_unlink(handle_t *handle,
+               struct inode *inode, struct dentry *dentry)
 {
        struct __track_dentry_update_args args;
        int ret;
@@ -430,12 +423,18 @@ void ext4_fc_track_unlink(struct inode *inode, struct dentry *dentry)
        args.dentry = dentry;
        args.op = EXT4_FC_TAG_UNLINK;
 
-       ret = ext4_fc_track_template(inode, __track_dentry_update,
+       ret = ext4_fc_track_template(handle, inode, __track_dentry_update,
                                        (void *)&args, 0);
        trace_ext4_fc_track_unlink(inode, dentry, ret);
 }
 
-void ext4_fc_track_link(struct inode *inode, struct dentry *dentry)
+void ext4_fc_track_unlink(handle_t *handle, struct dentry *dentry)
+{
+       __ext4_fc_track_unlink(handle, d_inode(dentry), dentry);
+}
+
+void __ext4_fc_track_link(handle_t *handle,
+       struct inode *inode, struct dentry *dentry)
 {
        struct __track_dentry_update_args args;
        int ret;
@@ -443,20 +442,26 @@ void ext4_fc_track_link(struct inode *inode, struct dentry *dentry)
        args.dentry = dentry;
        args.op = EXT4_FC_TAG_LINK;
 
-       ret = ext4_fc_track_template(inode, __track_dentry_update,
+       ret = ext4_fc_track_template(handle, inode, __track_dentry_update,
                                        (void *)&args, 0);
        trace_ext4_fc_track_link(inode, dentry, ret);
 }
 
-void ext4_fc_track_create(struct inode *inode, struct dentry *dentry)
+void ext4_fc_track_link(handle_t *handle, struct dentry *dentry)
+{
+       __ext4_fc_track_link(handle, d_inode(dentry), dentry);
+}
+
+void ext4_fc_track_create(handle_t *handle, struct dentry *dentry)
 {
        struct __track_dentry_update_args args;
+       struct inode *inode = d_inode(dentry);
        int ret;
 
        args.dentry = dentry;
        args.op = EXT4_FC_TAG_CREAT;
 
-       ret = ext4_fc_track_template(inode, __track_dentry_update,
+       ret = ext4_fc_track_template(handle, inode, __track_dentry_update,
                                        (void *)&args, 0);
        trace_ext4_fc_track_create(inode, dentry, ret);
 }
@@ -472,14 +477,20 @@ static int __track_inode(struct inode *inode, void *arg, bool update)
        return 0;
 }
 
-void ext4_fc_track_inode(struct inode *inode)
+void ext4_fc_track_inode(handle_t *handle, struct inode *inode)
 {
        int ret;
 
        if (S_ISDIR(inode->i_mode))
                return;
 
-       ret = ext4_fc_track_template(inode, __track_inode, NULL, 1);
+       if (ext4_should_journal_data(inode)) {
+               ext4_fc_mark_ineligible(inode->i_sb,
+                                       EXT4_FC_REASON_INODE_JOURNAL_DATA);
+               return;
+       }
+
+       ret = ext4_fc_track_template(handle, inode, __track_inode, NULL, 1);
        trace_ext4_fc_track_inode(inode, ret);
 }
 
@@ -515,7 +526,7 @@ static int __track_range(struct inode *inode, void *arg, bool update)
        return 0;
 }
 
-void ext4_fc_track_range(struct inode *inode, ext4_lblk_t start,
+void ext4_fc_track_range(handle_t *handle, struct inode *inode, ext4_lblk_t start,
                         ext4_lblk_t end)
 {
        struct __track_range_args args;
@@ -527,7 +538,7 @@ void ext4_fc_track_range(struct inode *inode, ext4_lblk_t start,
        args.start = start;
        args.end = end;
 
-       ret = ext4_fc_track_template(inode,  __track_range, &args, 1);
+       ret = ext4_fc_track_template(handle, inode,  __track_range, &args, 1);
 
        trace_ext4_fc_track_range(inode, start, end, ret);
 }
@@ -537,10 +548,11 @@ static void ext4_fc_submit_bh(struct super_block *sb)
        int write_flags = REQ_SYNC;
        struct buffer_head *bh = EXT4_SB(sb)->s_fc_bh;
 
+       /* TODO: REQ_FUA | REQ_PREFLUSH is unnecessarily expensive. */
        if (test_opt(sb, BARRIER))
                write_flags |= REQ_FUA | REQ_PREFLUSH;
        lock_buffer(bh);
-       clear_buffer_dirty(bh);
+       set_buffer_dirty(bh);
        set_buffer_uptodate(bh);
        bh->b_end_io = ext4_end_buffer_io_sync;
        submit_bh(REQ_OP_WRITE, write_flags, bh);
@@ -846,7 +858,7 @@ static int ext4_fc_submit_inode_data_all(journal_t *journal)
        int ret = 0;
 
        spin_lock(&sbi->s_fc_lock);
-       sbi->s_mount_flags |= EXT4_MF_FC_COMMITTING;
+       ext4_set_mount_flag(sb, EXT4_MF_FC_COMMITTING);
        list_for_each(pos, &sbi->s_fc_q[FC_Q_MAIN]) {
                ei = list_entry(pos, struct ext4_inode_info, i_fc_list);
                ext4_set_inode_state(&ei->vfs_inode, EXT4_STATE_FC_COMMITTING);
@@ -900,6 +912,8 @@ static int ext4_fc_wait_inode_data_all(journal_t *journal)
 
 /* Commit all the directory entry updates */
 static int ext4_fc_commit_dentry_updates(journal_t *journal, u32 *crc)
+__acquires(&sbi->s_fc_lock)
+__releases(&sbi->s_fc_lock)
 {
        struct super_block *sb = (struct super_block *)(journal->j_private);
        struct ext4_sb_info *sbi = EXT4_SB(sb);
@@ -996,6 +1010,13 @@ static int ext4_fc_perform_commit(journal_t *journal)
        if (ret)
                return ret;
 
+       /*
+        * If file system device is different from journal device, issue a cache
+        * flush before we start writing fast commit blocks.
+        */
+       if (journal->j_fs_dev != journal->j_dev)
+               blkdev_issue_flush(journal->j_fs_dev, GFP_NOFS);
+
        blk_start_plug(&plug);
        if (sbi->s_fc_bytes == 0) {
                /*
@@ -1031,8 +1052,6 @@ static int ext4_fc_perform_commit(journal_t *journal)
                if (ret)
                        goto out;
                spin_lock(&sbi->s_fc_lock);
-               EXT4_I(inode)->i_fc_committed_subtid =
-                       atomic_read(&sbi->s_fc_subtid);
        }
        spin_unlock(&sbi->s_fc_lock);
 
@@ -1131,7 +1150,7 @@ out:
                "Fast commit ended with blks = %d, reason = %d, subtid - %d",
                nblks, reason, subtid);
        if (reason == EXT4_FC_REASON_FC_FAILED)
-               return jbd2_fc_end_commit_fallback(journal, commit_tid);
+               return jbd2_fc_end_commit_fallback(journal);
        if (reason == EXT4_FC_REASON_FC_START_FAILED ||
                reason == EXT4_FC_REASON_INELIGIBLE)
                return jbd2_complete_transaction(journal, commit_tid);
@@ -1190,8 +1209,8 @@ static void ext4_fc_cleanup(journal_t *journal, int full)
        list_splice_init(&sbi->s_fc_q[FC_Q_STAGING],
                                &sbi->s_fc_q[FC_Q_STAGING]);
 
-       sbi->s_mount_flags &= ~EXT4_MF_FC_COMMITTING;
-       sbi->s_mount_flags &= ~EXT4_MF_FC_INELIGIBLE;
+       ext4_clear_mount_flag(sb, EXT4_MF_FC_COMMITTING);
+       ext4_clear_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
 
        if (full)
                sbi->s_fc_bytes = 0;
@@ -1263,7 +1282,7 @@ static int ext4_fc_replay_unlink(struct super_block *sb, struct ext4_fc_tl *tl)
                return 0;
        }
 
-       ret = __ext4_unlink(old_parent, &entry, inode);
+       ret = __ext4_unlink(NULL, old_parent, &entry, inode);
        /* -ENOENT ok coz it might not exist anymore. */
        if (ret == -ENOENT)
                ret = 0;
@@ -2079,8 +2098,6 @@ static int ext4_fc_replay(journal_t *journal, struct buffer_head *bh,
 
 void ext4_fc_init(struct super_block *sb, journal_t *journal)
 {
-       int num_fc_blocks;
-
        /*
         * We set replay callback even if fast commit disabled because we may
         * could still have fast commit blocks that need to be replayed even if
@@ -2090,21 +2107,9 @@ void ext4_fc_init(struct super_block *sb, journal_t *journal)
        if (!test_opt2(sb, JOURNAL_FAST_COMMIT))
                return;
        journal->j_fc_cleanup_callback = ext4_fc_cleanup;
-       if (!buffer_uptodate(journal->j_sb_buffer)
-               && ext4_read_bh_lock(journal->j_sb_buffer, REQ_META | REQ_PRIO,
-                                       true)) {
-               ext4_msg(sb, KERN_ERR, "I/O error on journal");
-               return;
-       }
-       num_fc_blocks = be32_to_cpu(journal->j_superblock->s_num_fc_blks);
-       if (jbd2_fc_init(journal, num_fc_blocks ? num_fc_blocks :
-                                       EXT4_NUM_FC_BLKS)) {
-               pr_warn("Error while enabling fast commits, turning off.");
-               ext4_clear_feature_fast_commit(sb);
-       }
 }
 
-const char *fc_ineligible_reasons[] = {
+static const char *fc_ineligible_reasons[] = {
        "Extended attributes changed",
        "Cross rename",
        "Journal flag changed",
@@ -2113,6 +2118,7 @@ const char *fc_ineligible_reasons[] = {
        "Resize",
        "Dir renamed",
        "Falloc range op",
+       "Data journalling",
        "FC Commit Failed"
 };
 
index 06907d4..3a6e5a1 100644 (file)
@@ -3,9 +3,6 @@
 #ifndef __FAST_COMMIT_H__
 #define __FAST_COMMIT_H__
 
-/* Number of blocks in journal area to allocate for fast commits */
-#define EXT4_NUM_FC_BLKS               256
-
 /* Fast commit tags */
 #define EXT4_FC_TAG_ADD_RANGE          0x0001
 #define EXT4_FC_TAG_DEL_RANGE          0x0002
@@ -100,11 +97,12 @@ enum {
        EXT4_FC_REASON_XATTR = 0,
        EXT4_FC_REASON_CROSS_RENAME,
        EXT4_FC_REASON_JOURNAL_FLAG_CHANGE,
-       EXT4_FC_REASON_MEM,
+       EXT4_FC_REASON_NOMEM,
        EXT4_FC_REASON_SWAP_BOOT,
        EXT4_FC_REASON_RESIZE,
        EXT4_FC_REASON_RENAME_DIR,
        EXT4_FC_REASON_FALLOC_RANGE,
+       EXT4_FC_REASON_INODE_JOURNAL_DATA,
        EXT4_FC_COMMIT_FAILED,
        EXT4_FC_REASON_MAX
 };
index d85412d..3ed8c04 100644 (file)
@@ -761,7 +761,6 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
        if (!daxdev_mapping_supported(vma, dax_dev))
                return -EOPNOTSUPP;
 
-       ext4_fc_start_update(inode);
        file_accessed(file);
        if (IS_DAX(file_inode(file))) {
                vma->vm_ops = &ext4_dax_vm_ops;
@@ -769,7 +768,6 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
        } else {
                vma->vm_ops = &ext4_file_vm_ops;
        }
-       ext4_fc_stop_update(inode);
        return 0;
 }
 
@@ -782,13 +780,13 @@ static int ext4_sample_last_mounted(struct super_block *sb,
        handle_t *handle;
        int err;
 
-       if (likely(sbi->s_mount_flags & EXT4_MF_MNTDIR_SAMPLED))
+       if (likely(ext4_test_mount_flag(sb, EXT4_MF_MNTDIR_SAMPLED)))
                return 0;
 
        if (sb_rdonly(sb) || !sb_start_intwrite_trylock(sb))
                return 0;
 
-       sbi->s_mount_flags |= EXT4_MF_MNTDIR_SAMPLED;
+       ext4_set_mount_flag(sb, EXT4_MF_MNTDIR_SAMPLED);
        /*
         * Sample where the filesystem has been mounted and
         * store it in the superblock for sysadmin convenience
index b232c27..4c2a9fe 100644 (file)
@@ -280,7 +280,7 @@ static int ext4_getfsmap_logdev(struct super_block *sb, struct ext4_fsmap *keys,
 
        /* Fabricate an rmap entry for the external log device. */
        irec.fmr_physical = journal->j_blk_offset;
-       irec.fmr_length = journal->j_maxlen;
+       irec.fmr_length = journal->j_total_len;
        irec.fmr_owner = EXT4_FMR_OWN_LOG;
        irec.fmr_flags = 0;
 
index 81a545f..a42ca95 100644 (file)
@@ -143,7 +143,7 @@ int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
        if (sb_rdonly(inode->i_sb)) {
                /* Make sure that we read updated s_mount_flags value */
                smp_rmb();
-               if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
+               if (ext4_test_mount_flag(inode->i_sb, EXT4_MF_FS_ABORTED))
                        ret = -EROFS;
                goto out;
        }
index caa5147..b41512d 100644 (file)
@@ -1880,6 +1880,7 @@ int ext4_inline_data_truncate(struct inode *inode, int *has_inline)
 
        ext4_write_lock_xattr(inode, &no_expand);
        if (!ext4_has_inline_data(inode)) {
+               ext4_write_unlock_xattr(inode, &no_expand);
                *has_inline = 0;
                ext4_journal_stop(handle);
                return 0;
index b96a186..0d8385a 100644 (file)
@@ -327,6 +327,8 @@ stop_handle:
        ext4_xattr_inode_array_free(ea_inode_array);
        return;
 no_delete:
+       if (!list_empty(&EXT4_I(inode)->i_fc_list))
+               ext4_fc_mark_ineligible(inode->i_sb, EXT4_FC_REASON_NOMEM);
        ext4_clear_inode(inode);        /* We must guarantee clearing of inode... */
 }
 
@@ -730,7 +732,7 @@ out_sem:
                        if (ret)
                                return ret;
                }
-               ext4_fc_track_range(inode, map->m_lblk,
+               ext4_fc_track_range(handle, inode, map->m_lblk,
                            map->m_lblk + map->m_len - 1);
        }
 
@@ -2440,7 +2442,7 @@ static int mpage_map_and_submit_extent(handle_t *handle,
                        struct super_block *sb = inode->i_sb;
 
                        if (ext4_forced_shutdown(EXT4_SB(sb)) ||
-                           EXT4_SB(sb)->s_mount_flags & EXT4_MF_FS_ABORTED)
+                           ext4_test_mount_flag(sb, EXT4_MF_FS_ABORTED))
                                goto invalidate_dirty_pages;
                        /*
                         * Let the uper layers retry transient errors.
@@ -2674,7 +2676,7 @@ static int ext4_writepages(struct address_space *mapping,
         * the stack trace.
         */
        if (unlikely(ext4_forced_shutdown(EXT4_SB(mapping->host->i_sb)) ||
-                    sbi->s_mount_flags & EXT4_MF_FS_ABORTED)) {
+                    ext4_test_mount_flag(inode->i_sb, EXT4_MF_FS_ABORTED))) {
                ret = -EROFS;
                goto out_writepages;
        }
@@ -3310,8 +3312,7 @@ static bool ext4_inode_datasync_dirty(struct inode *inode)
                        EXT4_I(inode)->i_datasync_tid))
                        return false;
                if (test_opt2(inode->i_sb, JOURNAL_FAST_COMMIT))
-                       return atomic_read(&EXT4_SB(inode->i_sb)->s_fc_subtid) <
-                               EXT4_I(inode)->i_fc_committed_subtid;
+                       return !list_empty(&EXT4_I(inode)->i_fc_list);
                return true;
        }
 
@@ -4109,7 +4110,7 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
 
                up_write(&EXT4_I(inode)->i_data_sem);
        }
-       ext4_fc_track_range(inode, first_block, stop_block);
+       ext4_fc_track_range(handle, inode, first_block, stop_block);
        if (IS_SYNC(inode))
                ext4_handle_sync(handle);
 
@@ -5442,14 +5443,14 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
                        }
 
                        if (shrink)
-                               ext4_fc_track_range(inode,
+                               ext4_fc_track_range(handle, inode,
                                        (attr->ia_size > 0 ? attr->ia_size - 1 : 0) >>
                                        inode->i_sb->s_blocksize_bits,
                                        (oldsize > 0 ? oldsize - 1 : 0) >>
                                        inode->i_sb->s_blocksize_bits);
                        else
                                ext4_fc_track_range(
-                                       inode,
+                                       handle, inode,
                                        (oldsize > 0 ? oldsize - 1 : oldsize) >>
                                        inode->i_sb->s_blocksize_bits,
                                        (attr->ia_size > 0 ? attr->ia_size - 1 : 0) >>
@@ -5699,7 +5700,7 @@ int ext4_mark_iloc_dirty(handle_t *handle,
                put_bh(iloc->bh);
                return -EIO;
        }
-       ext4_fc_track_inode(inode);
+       ext4_fc_track_inode(handle, inode);
 
        if (IS_I_VERSION(inode))
                inode_inc_iversion(inode);
index 85abbfb..24af9ed 100644 (file)
@@ -4477,7 +4477,7 @@ static inline void ext4_mb_show_pa(struct super_block *sb)
 {
        ext4_group_t i, ngroups;
 
-       if (EXT4_SB(sb)->s_mount_flags & EXT4_MF_FS_ABORTED)
+       if (ext4_test_mount_flag(sb, EXT4_MF_FS_ABORTED))
                return;
 
        ngroups = ext4_get_groups_count(sb);
@@ -4508,7 +4508,7 @@ static void ext4_mb_show_ac(struct ext4_allocation_context *ac)
 {
        struct super_block *sb = ac->ac_sb;
 
-       if (EXT4_SB(sb)->s_mount_flags & EXT4_MF_FS_ABORTED)
+       if (ext4_test_mount_flag(sb, EXT4_MF_FS_ABORTED))
                return;
 
        mb_debug(sb, "Can't allocate:"
@@ -5167,7 +5167,7 @@ static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_t *handle,
        struct super_block *sb = ar->inode->i_sb;
        ext4_group_t group;
        ext4_grpblk_t blkoff;
-       int  i;
+       int i = sb->s_blocksize;
        ext4_fsblk_t goal, block;
        struct ext4_super_block *es = EXT4_SB(sb)->s_es;
 
index f458d1d..3350926 100644 (file)
@@ -2606,7 +2606,7 @@ static int ext4_create(struct inode *dir, struct dentry *dentry, umode_t mode,
                       bool excl)
 {
        handle_t *handle;
-       struct inode *inode, *inode_save;
+       struct inode *inode;
        int err, credits, retries = 0;
 
        err = dquot_initialize(dir);
@@ -2624,11 +2624,9 @@ retry:
                inode->i_op = &ext4_file_inode_operations;
                inode->i_fop = &ext4_file_operations;
                ext4_set_aops(inode);
-               inode_save = inode;
-               ihold(inode_save);
                err = ext4_add_nondir(handle, dentry, &inode);
-               ext4_fc_track_create(inode_save, dentry);
-               iput(inode_save);
+               if (!err)
+                       ext4_fc_track_create(handle, dentry);
        }
        if (handle)
                ext4_journal_stop(handle);
@@ -2643,7 +2641,7 @@ static int ext4_mknod(struct inode *dir, struct dentry *dentry,
                      umode_t mode, dev_t rdev)
 {
        handle_t *handle;
-       struct inode *inode, *inode_save;
+       struct inode *inode;
        int err, credits, retries = 0;
 
        err = dquot_initialize(dir);
@@ -2660,12 +2658,9 @@ retry:
        if (!IS_ERR(inode)) {
                init_special_inode(inode, inode->i_mode, rdev);
                inode->i_op = &ext4_special_inode_operations;
-               inode_save = inode;
-               ihold(inode_save);
                err = ext4_add_nondir(handle, dentry, &inode);
                if (!err)
-                       ext4_fc_track_create(inode_save, dentry);
-               iput(inode_save);
+                       ext4_fc_track_create(handle, dentry);
        }
        if (handle)
                ext4_journal_stop(handle);
@@ -2829,7 +2824,6 @@ out_clear_inode:
                iput(inode);
                goto out_retry;
        }
-       ext4_fc_track_create(inode, dentry);
        ext4_inc_count(dir);
 
        ext4_update_dx_flag(dir);
@@ -2837,6 +2831,7 @@ out_clear_inode:
        if (err)
                goto out_clear_inode;
        d_instantiate_new(dentry, inode);
+       ext4_fc_track_create(handle, dentry);
        if (IS_DIRSYNC(dir))
                ext4_handle_sync(handle);
 
@@ -3171,7 +3166,7 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
                goto end_rmdir;
        ext4_dec_count(dir);
        ext4_update_dx_flag(dir);
-       ext4_fc_track_unlink(inode, dentry);
+       ext4_fc_track_unlink(handle, dentry);
        retval = ext4_mark_inode_dirty(handle, dir);
 
 #ifdef CONFIG_UNICODE
@@ -3192,13 +3187,12 @@ end_rmdir:
        return retval;
 }
 
-int __ext4_unlink(struct inode *dir, const struct qstr *d_name,
+int __ext4_unlink(handle_t *handle, struct inode *dir, const struct qstr *d_name,
                  struct inode *inode)
 {
        int retval = -ENOENT;
        struct buffer_head *bh;
        struct ext4_dir_entry_2 *de;
-       handle_t *handle = NULL;
        int skip_remove_dentry = 0;
 
        bh = ext4_find_entry(dir, d_name, &de, NULL);
@@ -3217,14 +3211,7 @@ int __ext4_unlink(struct inode *dir, const struct qstr *d_name,
                if (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY)
                        skip_remove_dentry = 1;
                else
-                       goto out_bh;
-       }
-
-       handle = ext4_journal_start(dir, EXT4_HT_DIR,
-                                   EXT4_DATA_TRANS_BLOCKS(dir->i_sb));
-       if (IS_ERR(handle)) {
-               retval = PTR_ERR(handle);
-               goto out_bh;
+                       goto out;
        }
 
        if (IS_DIRSYNC(dir))
@@ -3233,12 +3220,12 @@ int __ext4_unlink(struct inode *dir, const struct qstr *d_name,
        if (!skip_remove_dentry) {
                retval = ext4_delete_entry(handle, dir, de, bh);
                if (retval)
-                       goto out_handle;
+                       goto out;
                dir->i_ctime = dir->i_mtime = current_time(dir);
                ext4_update_dx_flag(dir);
                retval = ext4_mark_inode_dirty(handle, dir);
                if (retval)
-                       goto out_handle;
+                       goto out;
        } else {
                retval = 0;
        }
@@ -3252,15 +3239,14 @@ int __ext4_unlink(struct inode *dir, const struct qstr *d_name,
        inode->i_ctime = current_time(inode);
        retval = ext4_mark_inode_dirty(handle, inode);
 
-out_handle:
-       ext4_journal_stop(handle);
-out_bh:
+out:
        brelse(bh);
        return retval;
 }
 
 static int ext4_unlink(struct inode *dir, struct dentry *dentry)
 {
+       handle_t *handle;
        int retval;
 
        if (unlikely(ext4_forced_shutdown(EXT4_SB(dir->i_sb))))
@@ -3278,9 +3264,16 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
        if (retval)
                goto out_trace;
 
-       retval = __ext4_unlink(dir, &dentry->d_name, d_inode(dentry));
+       handle = ext4_journal_start(dir, EXT4_HT_DIR,
+                                   EXT4_DATA_TRANS_BLOCKS(dir->i_sb));
+       if (IS_ERR(handle)) {
+               retval = PTR_ERR(handle);
+               goto out_trace;
+       }
+
+       retval = __ext4_unlink(handle, dir, &dentry->d_name, d_inode(dentry));
        if (!retval)
-               ext4_fc_track_unlink(d_inode(dentry), dentry);
+               ext4_fc_track_unlink(handle, dentry);
 #ifdef CONFIG_UNICODE
        /* VFS negative dentries are incompatible with Encoding and
         * Case-insensitiveness. Eventually we'll want avoid
@@ -3291,6 +3284,8 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
        if (IS_CASEFOLDED(dir))
                d_invalidate(dentry);
 #endif
+       if (handle)
+               ext4_journal_stop(handle);
 
 out_trace:
        trace_ext4_unlink_exit(dentry, retval);
@@ -3447,7 +3442,6 @@ retry:
 
        err = ext4_add_entry(handle, dentry, inode);
        if (!err) {
-               ext4_fc_track_link(inode, dentry);
                err = ext4_mark_inode_dirty(handle, inode);
                /* this can happen only for tmpfile being
                 * linked the first time
@@ -3455,6 +3449,7 @@ retry:
                if (inode->i_nlink == 1)
                        ext4_orphan_del(handle, inode);
                d_instantiate(dentry, inode);
+               ext4_fc_track_link(handle, dentry);
        } else {
                drop_nlink(inode);
                iput(inode);
@@ -3915,9 +3910,9 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
                        EXT4_FC_REASON_RENAME_DIR);
        } else {
                if (new.inode)
-                       ext4_fc_track_unlink(new.inode, new.dentry);
-               ext4_fc_track_link(old.inode, new.dentry);
-               ext4_fc_track_unlink(old.inode, old.dentry);
+                       ext4_fc_track_unlink(handle, new.dentry);
+               __ext4_fc_track_link(handle, old.inode, new.dentry);
+               __ext4_fc_track_unlink(handle, old.inode, old.dentry);
        }
 
        if (new.inode) {
index ef4734b..9447204 100644 (file)
@@ -289,18 +289,7 @@ void ext4_superblock_csum_set(struct super_block *sb)
        if (!ext4_has_metadata_csum(sb))
                return;
 
-       /*
-        * Locking the superblock prevents the scenario
-        * where:
-        *  1) a first thread pauses during checksum calculation.
-        *  2) a second thread updates the superblock, recalculates
-        *     the checksum, and updates s_checksum
-        *  3) the first thread resumes and finishes its checksum calculation
-        *     and updates s_checksum with a potentially stale or torn value.
-        */
-       lock_buffer(EXT4_SB(sb)->s_sbh);
        es->s_checksum = ext4_superblock_csum(sb, es);
-       unlock_buffer(EXT4_SB(sb)->s_sbh);
 }
 
 ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
@@ -686,7 +675,7 @@ static void ext4_handle_error(struct super_block *sb)
        if (!test_opt(sb, ERRORS_CONT)) {
                journal_t *journal = EXT4_SB(sb)->s_journal;
 
-               EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
+               ext4_set_mount_flag(sb, EXT4_MF_FS_ABORTED);
                if (journal)
                        jbd2_journal_abort(journal, -EIO);
        }
@@ -904,7 +893,7 @@ void __ext4_abort(struct super_block *sb, const char *function,
        va_end(args);
 
        if (sb_rdonly(sb) == 0) {
-               EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
+               ext4_set_mount_flag(sb, EXT4_MF_FS_ABORTED);
                if (EXT4_SB(sb)->s_journal)
                        jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
 
@@ -1716,11 +1705,10 @@ enum {
        Opt_dioread_nolock, Opt_dioread_lock,
        Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
        Opt_max_dir_size_kb, Opt_nojournal_checksum, Opt_nombcache,
-       Opt_prefetch_block_bitmaps, Opt_no_fc,
+       Opt_prefetch_block_bitmaps,
 #ifdef CONFIG_EXT4_DEBUG
-       Opt_fc_debug_max_replay,
+       Opt_fc_debug_max_replay, Opt_fc_debug_force
 #endif
-       Opt_fc_debug_force
 };
 
 static const match_table_t tokens = {
@@ -1807,9 +1795,8 @@ static const match_table_t tokens = {
        {Opt_init_itable, "init_itable=%u"},
        {Opt_init_itable, "init_itable"},
        {Opt_noinit_itable, "noinit_itable"},
-       {Opt_no_fc, "no_fc"},
-       {Opt_fc_debug_force, "fc_debug_force"},
 #ifdef CONFIG_EXT4_DEBUG
+       {Opt_fc_debug_force, "fc_debug_force"},
        {Opt_fc_debug_max_replay, "fc_debug_max_replay=%u"},
 #endif
        {Opt_max_dir_size_kb, "max_dir_size_kb=%u"},
@@ -2027,8 +2014,8 @@ static const struct mount_opts {
        {Opt_noquota, (EXT4_MOUNT_QUOTA | EXT4_MOUNT_USRQUOTA |
                       EXT4_MOUNT_GRPQUOTA | EXT4_MOUNT_PRJQUOTA),
                                                        MOPT_CLEAR | MOPT_Q},
-       {Opt_usrjquota, 0, MOPT_Q},
-       {Opt_grpjquota, 0, MOPT_Q},
+       {Opt_usrjquota, 0, MOPT_Q | MOPT_STRING},
+       {Opt_grpjquota, 0, MOPT_Q | MOPT_STRING},
        {Opt_offusrjquota, 0, MOPT_Q},
        {Opt_offgrpjquota, 0, MOPT_Q},
        {Opt_jqfmt_vfsold, QFMT_VFS_OLD, MOPT_QFMT},
@@ -2039,11 +2026,9 @@ static const struct mount_opts {
        {Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET},
        {Opt_prefetch_block_bitmaps, EXT4_MOUNT_PREFETCH_BLOCK_BITMAPS,
         MOPT_SET},
-       {Opt_no_fc, EXT4_MOUNT2_JOURNAL_FAST_COMMIT,
-        MOPT_CLEAR | MOPT_2 | MOPT_EXT4_ONLY},
+#ifdef CONFIG_EXT4_DEBUG
        {Opt_fc_debug_force, EXT4_MOUNT2_JOURNAL_FAST_COMMIT,
         MOPT_SET | MOPT_2 | MOPT_EXT4_ONLY},
-#ifdef CONFIG_EXT4_DEBUG
        {Opt_fc_debug_max_replay, 0, MOPT_GTE0},
 #endif
        {Opt_err, 0, 0}
@@ -2153,7 +2138,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
                ext4_msg(sb, KERN_WARNING, "Ignoring removed %s option", opt);
                return 1;
        case Opt_abort:
-               sbi->s_mount_flags |= EXT4_MF_FS_ABORTED;
+               ext4_set_mount_flag(sb, EXT4_MF_FS_ABORTED);
                return 1;
        case Opt_i_version:
                sb->s_flags |= SB_I_VERSION;
@@ -2653,10 +2638,6 @@ static int _ext4_show_options(struct seq_file *seq, struct super_block *sb,
        } else if (test_opt2(sb, DAX_INODE)) {
                SEQ_OPTS_PUTS("dax=inode");
        }
-
-       if (test_opt2(sb, JOURNAL_FAST_COMMIT))
-               SEQ_OPTS_PUTS("fast_commit");
-
        ext4_show_quota_options(seq, sb);
        return 0;
 }
@@ -3976,7 +3957,7 @@ int ext4_calculate_overhead(struct super_block *sb)
         * loaded or not
         */
        if (sbi->s_journal && !sbi->s_journal_bdev)
-               overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_maxlen);
+               overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_total_len);
        else if (ext4_has_feature_journal(sb) && !sbi->s_journal && j_inum) {
                /* j_inum for internal journal is non-zero */
                j_inode = ext4_get_journal_inode(sb, j_inum);
@@ -4340,9 +4321,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 #endif
 
        if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
-               printk_once(KERN_WARNING "EXT4-fs: Warning: mounting with data=journal disables delayed allocation, dioread_nolock, and O_DIRECT support!\n");
+               printk_once(KERN_WARNING "EXT4-fs: Warning: mounting with data=journal disables delayed allocation, dioread_nolock, O_DIRECT and fast_commit support!\n");
                /* can't mount with both data=journal and dioread_nolock. */
                clear_opt(sb, DIOREAD_NOLOCK);
+               clear_opt2(sb, JOURNAL_FAST_COMMIT);
                if (test_opt2(sb, EXPLICIT_DELALLOC)) {
                        ext4_msg(sb, KERN_ERR, "can't mount with "
                                 "both data=journal and delalloc");
@@ -4777,8 +4759,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
        INIT_LIST_HEAD(&sbi->s_fc_dentry_q[FC_Q_MAIN]);
        INIT_LIST_HEAD(&sbi->s_fc_dentry_q[FC_Q_STAGING]);
        sbi->s_fc_bytes = 0;
-       sbi->s_mount_flags &= ~EXT4_MF_FC_INELIGIBLE;
-       sbi->s_mount_flags &= ~EXT4_MF_FC_COMMITTING;
+       ext4_clear_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
+       ext4_clear_mount_flag(sb, EXT4_MF_FC_COMMITTING);
        spin_lock_init(&sbi->s_fc_lock);
        memset(&sbi->s_fc_stats, 0, sizeof(sbi->s_fc_stats));
        sbi->s_fc_replay_state.fc_regions = NULL;
@@ -4857,6 +4839,14 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
                goto failed_mount_wq;
        }
 
+       if (test_opt2(sb, JOURNAL_FAST_COMMIT) &&
+               !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0,
+                                         JBD2_FEATURE_INCOMPAT_FAST_COMMIT)) {
+               ext4_msg(sb, KERN_ERR,
+                       "Failed to set fast commit journal feature");
+               goto failed_mount_wq;
+       }
+
        /* We have now updated the journal if required, so we can
         * validate the data journaling mode. */
        switch (test_opt(sb, DATA_FLAGS)) {
@@ -5872,7 +5862,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
                goto restore_opts;
        }
 
-       if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
+       if (ext4_test_mount_flag(sb, EXT4_MF_FS_ABORTED))
                ext4_abort(sb, EXT4_ERR_ESHUTDOWN, "Abort forced by user");
 
        sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
@@ -5886,7 +5876,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
        }
 
        if ((bool)(*flags & SB_RDONLY) != sb_rdonly(sb)) {
-               if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED) {
+               if (ext4_test_mount_flag(sb, EXT4_MF_FS_ABORTED)) {
                        err = -EROFS;
                        goto restore_opts;
                }
@@ -6560,10 +6550,6 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
        brelse(bh);
 out:
        if (inode->i_size < off + len) {
-               ext4_fc_track_range(inode,
-                       (inode->i_size > 0 ? inode->i_size - 1 : 0)
-                               >> inode->i_sb->s_blocksize_bits,
-                       (off + len) >> inode->i_sb->s_blocksize_bits);
                i_size_write(inode, off + len);
                EXT4_I(inode)->i_disksize = inode->i_size;
                err2 = ext4_mark_inode_dirty(handle, inode);
index 9cd2eca..cc4f987 100644 (file)
@@ -77,7 +77,7 @@ static int gfs2_get_block_noalloc(struct inode *inode, sector_t lblock,
        if (error)
                return error;
        if (!buffer_mapped(bh_result))
-               return -EIO;
+               return -ENODATA;
        return 0;
 }
 
index 8dff9cb..62d9081 100644 (file)
@@ -1301,12 +1301,8 @@ int gfs2_block_map(struct inode *inode, sector_t lblock,
        trace_gfs2_bmap(ip, bh_map, lblock, create, 1);
 
        ret = gfs2_iomap_get(inode, pos, length, flags, &iomap, &mp);
-       if (!ret && iomap.type == IOMAP_HOLE) {
-               if (create)
-                       ret = gfs2_iomap_alloc(inode, &iomap, &mp);
-               else
-                       ret = -ENODATA;
-       }
+       if (create && !ret && iomap.type == IOMAP_HOLE)
+               ret = gfs2_iomap_alloc(inode, &iomap, &mp);
        release_metapath(&mp);
        if (ret)
                goto out;
index 5441c17..d98a2e5 100644 (file)
@@ -1078,7 +1078,8 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
 out_free:
        kfree(gl->gl_lksb.sb_lvbptr);
        kmem_cache_free(cachep, gl);
-       atomic_dec(&sdp->sd_glock_disposal);
+       if (atomic_dec_and_test(&sdp->sd_glock_disposal))
+               wake_up(&sdp->sd_glock_wait);
 
 out:
        return ret;
index aa3f523..67f2921 100644 (file)
@@ -164,6 +164,31 @@ void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
                       GFS2_LFC_AIL_FLUSH);
 }
 
+/**
+ * gfs2_rgrp_metasync - sync out the metadata of a resource group
+ * @gl: the glock protecting the resource group
+ *
+ */
+
+static int gfs2_rgrp_metasync(struct gfs2_glock *gl)
+{
+       struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
+       struct address_space *metamapping = &sdp->sd_aspace;
+       struct gfs2_rgrpd *rgd = gfs2_glock2rgrp(gl);
+       const unsigned bsize = sdp->sd_sb.sb_bsize;
+       loff_t start = (rgd->rd_addr * bsize) & PAGE_MASK;
+       loff_t end = PAGE_ALIGN((rgd->rd_addr + rgd->rd_length) * bsize) - 1;
+       int error;
+
+       filemap_fdatawrite_range(metamapping, start, end);
+       error = filemap_fdatawait_range(metamapping, start, end);
+       WARN_ON_ONCE(error && !gfs2_withdrawn(sdp));
+       mapping_set_error(metamapping, error);
+       if (error)
+               gfs2_io_error(sdp);
+       return error;
+}
+
 /**
  * rgrp_go_sync - sync out the metadata for this glock
  * @gl: the glock
@@ -176,11 +201,7 @@ void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
 static int rgrp_go_sync(struct gfs2_glock *gl)
 {
        struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
-       struct address_space *mapping = &sdp->sd_aspace;
        struct gfs2_rgrpd *rgd = gfs2_glock2rgrp(gl);
-       const unsigned bsize = sdp->sd_sb.sb_bsize;
-       loff_t start = (rgd->rd_addr * bsize) & PAGE_MASK;
-       loff_t end = PAGE_ALIGN((rgd->rd_addr + rgd->rd_length) * bsize) - 1;
        int error;
 
        if (!test_and_clear_bit(GLF_DIRTY, &gl->gl_flags))
@@ -189,10 +210,7 @@ static int rgrp_go_sync(struct gfs2_glock *gl)
 
        gfs2_log_flush(sdp, gl, GFS2_LOG_HEAD_FLUSH_NORMAL |
                       GFS2_LFC_RGRP_GO_SYNC);
-       filemap_fdatawrite_range(mapping, start, end);
-       error = filemap_fdatawait_range(mapping, start, end);
-       WARN_ON_ONCE(error && !gfs2_withdrawn(sdp));
-       mapping_set_error(mapping, error);
+       error = gfs2_rgrp_metasync(gl);
        if (!error)
                error = gfs2_ail_empty_gl(gl);
        gfs2_free_clones(rgd);
@@ -266,7 +284,24 @@ static void gfs2_clear_glop_pending(struct gfs2_inode *ip)
 }
 
 /**
- * inode_go_sync - Sync the dirty data and/or metadata for an inode glock
+ * gfs2_inode_metasync - sync out the metadata of an inode
+ * @gl: the glock protecting the inode
+ *
+ */
+int gfs2_inode_metasync(struct gfs2_glock *gl)
+{
+       struct address_space *metamapping = gfs2_glock2aspace(gl);
+       int error;
+
+       filemap_fdatawrite(metamapping);
+       error = filemap_fdatawait(metamapping);
+       if (error)
+               gfs2_io_error(gl->gl_name.ln_sbd);
+       return error;
+}
+
+/**
+ * inode_go_sync - Sync the dirty metadata of an inode
  * @gl: the glock protecting the inode
  *
  */
@@ -297,8 +332,7 @@ static int inode_go_sync(struct gfs2_glock *gl)
                error = filemap_fdatawait(mapping);
                mapping_set_error(mapping, error);
        }
-       ret = filemap_fdatawait(metamapping);
-       mapping_set_error(metamapping, ret);
+       ret = gfs2_inode_metasync(gl);
        if (!error)
                error = ret;
        gfs2_ail_empty_gl(gl);
@@ -537,7 +571,18 @@ static int freeze_go_sync(struct gfs2_glock *gl)
        int error = 0;
        struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
 
-       if (gl->gl_req == LM_ST_EXCLUSIVE && !gfs2_withdrawn(sdp)) {
+       /*
+        * We need to check gl_state == LM_ST_SHARED here and not gl_req ==
+        * LM_ST_EXCLUSIVE. That's because when any node does a freeze,
+        * all the nodes should have the freeze glock in SH mode and they all
+        * call do_xmote: One for EX and the others for UN. They ALL must
+        * freeze locally, and they ALL must queue freeze work. The freeze_work
+        * calls freeze_func, which tries to reacquire the freeze glock in SH,
+        * effectively waiting for the thaw on the node who holds it in EX.
+        * Once thawed, the work func acquires the freeze glock in
+        * SH and everybody goes back to thawed.
+        */
+       if (gl->gl_state == LM_ST_SHARED && !gfs2_withdrawn(sdp)) {
                atomic_set(&sdp->sd_freeze_state, SFS_STARTING_FREEZE);
                error = freeze_super(sdp->sd_vfs);
                if (error) {
index 2dd192e..695898a 100644 (file)
@@ -22,6 +22,7 @@ extern const struct gfs2_glock_operations gfs2_quota_glops;
 extern const struct gfs2_glock_operations gfs2_journal_glops;
 extern const struct gfs2_glock_operations *gfs2_glops_list[];
 
+extern int gfs2_inode_metasync(struct gfs2_glock *gl);
 extern void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync);
 
 #endif /* __GLOPS_DOT_H__ */
index 6774865..077ccb1 100644 (file)
@@ -180,7 +180,8 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
                error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh);
                if (unlikely(error))
                        goto fail;
-               gfs2_cancel_delete_work(ip->i_iopen_gh.gh_gl);
+               if (blktype != GFS2_BLKST_UNLINKED)
+                       gfs2_cancel_delete_work(ip->i_iopen_gh.gh_gl);
                glock_set_object(ip->i_iopen_gh.gh_gl, ip);
                gfs2_glock_put(io_gl);
                io_gl = NULL;
index 9133b31..2e93140 100644 (file)
@@ -132,6 +132,8 @@ __acquires(&sdp->sd_ail_lock)
                spin_unlock(&sdp->sd_ail_lock);
                ret = generic_writepages(mapping, wbc);
                spin_lock(&sdp->sd_ail_lock);
+               if (ret == -ENODATA) /* if a jdata write into a new hole */
+                       ret = 0; /* ignore it */
                if (ret || wbc->nr_to_write <= 0)
                        break;
                return -EBUSY;
index ed69298..3922b26 100644 (file)
@@ -22,6 +22,7 @@
 #include "incore.h"
 #include "inode.h"
 #include "glock.h"
+#include "glops.h"
 #include "log.h"
 #include "lops.h"
 #include "meta_io.h"
@@ -817,41 +818,19 @@ static int buf_lo_scan_elements(struct gfs2_jdesc *jd, u32 start,
        return error;
 }
 
-/**
- * gfs2_meta_sync - Sync all buffers associated with a glock
- * @gl: The glock
- *
- */
-
-void gfs2_meta_sync(struct gfs2_glock *gl)
-{
-       struct address_space *mapping = gfs2_glock2aspace(gl);
-       struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
-       int error;
-
-       if (mapping == NULL)
-               mapping = &sdp->sd_aspace;
-
-       filemap_fdatawrite(mapping);
-       error = filemap_fdatawait(mapping);
-
-       if (error)
-               gfs2_io_error(gl->gl_name.ln_sbd);
-}
-
 static void buf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass)
 {
        struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
        struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
 
        if (error) {
-               gfs2_meta_sync(ip->i_gl);
+               gfs2_inode_metasync(ip->i_gl);
                return;
        }
        if (pass != 1)
                return;
 
-       gfs2_meta_sync(ip->i_gl);
+       gfs2_inode_metasync(ip->i_gl);
 
        fs_info(sdp, "jid=%u: Replayed %u of %u blocks\n",
                jd->jd_jid, jd->jd_replayed_blocks, jd->jd_found_blocks);
@@ -1060,14 +1039,14 @@ static void databuf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass)
        struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
 
        if (error) {
-               gfs2_meta_sync(ip->i_gl);
+               gfs2_inode_metasync(ip->i_gl);
                return;
        }
        if (pass != 1)
                return;
 
        /* data sync? */
-       gfs2_meta_sync(ip->i_gl);
+       gfs2_inode_metasync(ip->i_gl);
 
        fs_info(sdp, "jid=%u: Replayed %u of %u data blocks\n",
                jd->jd_jid, jd->jd_replayed_blocks, jd->jd_found_blocks);
index 4a3d8ae..fbdbb08 100644 (file)
@@ -27,8 +27,6 @@ extern void gfs2_log_submit_bio(struct bio **biop, int opf);
 extern void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh);
 extern int gfs2_find_jhead(struct gfs2_jdesc *jd,
                           struct gfs2_log_header_host *head, bool keep_cache);
-extern void gfs2_meta_sync(struct gfs2_glock *gl);
-
 static inline unsigned int buf_limit(struct gfs2_sbd *sdp)
 {
        unsigned int limit;
index 7a7e3c1..61fce59 100644 (file)
@@ -633,8 +633,10 @@ static int init_statfs(struct gfs2_sbd *sdp)
        if (IS_ERR(sdp->sd_statfs_inode)) {
                error = PTR_ERR(sdp->sd_statfs_inode);
                fs_err(sdp, "can't read in statfs inode: %d\n", error);
-               goto fail;
+               goto out;
        }
+       if (sdp->sd_args.ar_spectator)
+               goto out;
 
        pn = gfs2_lookup_simple(master, "per_node");
        if (IS_ERR(pn)) {
@@ -682,15 +684,17 @@ free_local:
        iput(pn);
 put_statfs:
        iput(sdp->sd_statfs_inode);
-fail:
+out:
        return error;
 }
 
 /* Uninitialize and free up memory used by the list of statfs inodes */
 static void uninit_statfs(struct gfs2_sbd *sdp)
 {
-       gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
-       free_local_statfs_inodes(sdp);
+       if (!sdp->sd_args.ar_spectator) {
+               gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
+               free_local_statfs_inodes(sdp);
+       }
        iput(sdp->sd_statfs_inode);
 }
 
@@ -704,7 +708,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
 
        if (undo) {
                jindex = 0;
-               goto fail_jinode_gh;
+               goto fail_statfs;
        }
 
        sdp->sd_jindex = gfs2_lookup_simple(master, "jindex");
index b5cbe21..c26c68e 100644 (file)
@@ -349,7 +349,7 @@ static int update_statfs_inode(struct gfs2_jdesc *jd,
 
        mark_buffer_dirty(bh);
        brelse(bh);
-       gfs2_meta_sync(ip->i_gl);
+       gfs2_inode_metasync(ip->i_gl);
 
 out:
        return error;
index ee491bb..f7addc6 100644 (file)
@@ -719,9 +719,9 @@ void gfs2_clear_rgrpd(struct gfs2_sbd *sdp)
                }
 
                gfs2_free_clones(rgd);
+               return_all_reservations(rgd);
                kfree(rgd->rd_bits);
                rgd->rd_bits = NULL;
-               return_all_reservations(rgd);
                kmem_cache_free(gfs2_rgrpd_cachep, rgd);
        }
 }
@@ -1370,6 +1370,9 @@ int gfs2_fitrim(struct file *filp, void __user *argp)
        if (!capable(CAP_SYS_ADMIN))
                return -EPERM;
 
+       if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags))
+               return -EROFS;
+
        if (!blk_queue_discard(q))
                return -EOPNOTSUPP;
 
@@ -2526,13 +2529,13 @@ int gfs2_check_blk_type(struct gfs2_sbd *sdp, u64 no_addr, unsigned int type)
 
        rbm.rgd = rgd;
        error = gfs2_rbm_from_block(&rbm, no_addr);
-       if (WARN_ON_ONCE(error))
-               goto fail;
-
-       if (gfs2_testbit(&rbm, false) != type)
-               error = -ESTALE;
+       if (!WARN_ON_ONCE(error)) {
+               if (gfs2_testbit(&rbm, false) != type)
+                       error = -ESTALE;
+       }
 
        gfs2_glock_dq_uninit(&rgd_gh);
+
 fail:
        return error;
 }
index b285192..b3d951a 100644 (file)
@@ -738,6 +738,7 @@ restart:
        gfs2_jindex_free(sdp);
        /*  Take apart glock structures and buffer lists  */
        gfs2_gl_hash_clear(sdp);
+       truncate_inode_pages_final(&sdp->sd_aspace);
        gfs2_delete_debugfs_file(sdp);
        /*  Unmount the locking protocol  */
        gfs2_lm_unmount(sdp);
index 02894df..b53c055 100644 (file)
@@ -482,6 +482,10 @@ static void io_impersonate_work(struct io_worker *worker,
                current->files = work->identity->files;
                current->nsproxy = work->identity->nsproxy;
                task_unlock(current);
+               if (!work->identity->files) {
+                       /* failed grabbing files, ensure work gets cancelled */
+                       work->flags |= IO_WQ_WORK_CANCEL;
+               }
        }
        if ((work->flags & IO_WQ_WORK_FS) && current->fs != work->identity->fs)
                current->fs = work->identity->fs;
index a7429c9..a8c136a 100644 (file)
@@ -205,6 +205,7 @@ struct fixed_file_ref_node {
        struct list_head                file_list;
        struct fixed_file_data          *file_data;
        struct llist_node               llist;
+       bool                            done;
 };
 
 struct fixed_file_data {
@@ -478,6 +479,7 @@ struct io_sr_msg {
 struct io_open {
        struct file                     *file;
        int                             dfd;
+       bool                            ignore_nonblock;
        struct filename                 *filename;
        struct open_how                 how;
        unsigned long                   nofile;
@@ -995,20 +997,33 @@ static void io_sq_thread_drop_mm(void)
        if (mm) {
                kthread_unuse_mm(mm);
                mmput(mm);
+               current->mm = NULL;
        }
 }
 
 static int __io_sq_thread_acquire_mm(struct io_ring_ctx *ctx)
 {
-       if (!current->mm) {
-               if (unlikely(!(ctx->flags & IORING_SETUP_SQPOLL) ||
-                            !ctx->sqo_task->mm ||
-                            !mmget_not_zero(ctx->sqo_task->mm)))
-                       return -EFAULT;
-               kthread_use_mm(ctx->sqo_task->mm);
+       struct mm_struct *mm;
+
+       if (current->mm)
+               return 0;
+
+       /* Should never happen */
+       if (unlikely(!(ctx->flags & IORING_SETUP_SQPOLL)))
+               return -EFAULT;
+
+       task_lock(ctx->sqo_task);
+       mm = ctx->sqo_task->mm;
+       if (unlikely(!mm || !mmget_not_zero(mm)))
+               mm = NULL;
+       task_unlock(ctx->sqo_task);
+
+       if (mm) {
+               kthread_use_mm(mm);
+               return 0;
        }
 
-       return 0;
+       return -EFAULT;
 }
 
 static int io_sq_thread_acquire_mm(struct io_ring_ctx *ctx,
@@ -1274,9 +1289,12 @@ static bool io_identity_cow(struct io_kiocb *req)
        /* add one for this request */
        refcount_inc(&id->count);
 
-       /* drop old identity, assign new one. one ref for req, one for tctx */
-       if (req->work.identity != tctx->identity &&
-           refcount_sub_and_test(2, &req->work.identity->count))
+       /* drop tctx and req identity references, if needed */
+       if (tctx->identity != &tctx->__identity &&
+           refcount_dec_and_test(&tctx->identity->count))
+               kfree(tctx->identity);
+       if (req->work.identity != &tctx->__identity &&
+           refcount_dec_and_test(&req->work.identity->count))
                kfree(req->work.identity);
 
        req->work.identity = id;
@@ -1577,14 +1595,29 @@ static void io_cqring_mark_overflow(struct io_ring_ctx *ctx)
        }
 }
 
-static inline bool io_match_files(struct io_kiocb *req,
-                                      struct files_struct *files)
+static inline bool __io_match_files(struct io_kiocb *req,
+                                   struct files_struct *files)
 {
+       return ((req->flags & REQ_F_WORK_INITIALIZED) &&
+               (req->work.flags & IO_WQ_WORK_FILES)) &&
+               req->work.identity->files == files;
+}
+
+static bool io_match_files(struct io_kiocb *req,
+                          struct files_struct *files)
+{
+       struct io_kiocb *link;
+
        if (!files)
                return true;
-       if ((req->flags & REQ_F_WORK_INITIALIZED) &&
-           (req->work.flags & IO_WQ_WORK_FILES))
-               return req->work.identity->files == files;
+       if (__io_match_files(req, files))
+               return true;
+       if (req->flags & REQ_F_LINK_HEAD) {
+               list_for_each_entry(link, &req->link_list, link_list) {
+                       if (__io_match_files(link, files))
+                               return true;
+               }
+       }
        return false;
 }
 
@@ -1668,7 +1701,8 @@ static void __io_cqring_fill_event(struct io_kiocb *req, long res, long cflags)
                WRITE_ONCE(cqe->user_data, req->user_data);
                WRITE_ONCE(cqe->res, res);
                WRITE_ONCE(cqe->flags, cflags);
-       } else if (ctx->cq_overflow_flushed || req->task->io_uring->in_idle) {
+       } else if (ctx->cq_overflow_flushed ||
+                  atomic_read(&req->task->io_uring->in_idle)) {
                /*
                 * If we're in ring overflow flush mode, or in task cancel mode,
                 * then we cannot store the request for later flushing, we need
@@ -1838,7 +1872,7 @@ static void __io_free_req(struct io_kiocb *req)
        io_dismantle_req(req);
 
        percpu_counter_dec(&tctx->inflight);
-       if (tctx->in_idle)
+       if (atomic_read(&tctx->in_idle))
                wake_up(&tctx->wait);
        put_task_struct(req->task);
 
@@ -2545,7 +2579,6 @@ static bool io_resubmit_prep(struct io_kiocb *req, int error)
        }
 end_req:
        req_set_fail_links(req);
-       io_req_complete(req, ret);
        return false;
 }
 #endif
@@ -3515,8 +3548,7 @@ static int io_write(struct io_kiocb *req, bool force_nonblock,
         * we return to userspace.
         */
        if (req->flags & REQ_F_ISREG) {
-               __sb_start_write(file_inode(req->file)->i_sb,
-                                       SB_FREEZE_WRITE, true);
+               sb_start_write(file_inode(req->file)->i_sb);
                __sb_writers_release(file_inode(req->file)->i_sb,
                                        SB_FREEZE_WRITE);
        }
@@ -3764,6 +3796,7 @@ static int __io_openat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
                return ret;
        }
        req->open.nofile = rlimit(RLIMIT_NOFILE);
+       req->open.ignore_nonblock = false;
        req->flags |= REQ_F_NEED_CLEANUP;
        return 0;
 }
@@ -3807,7 +3840,7 @@ static int io_openat2(struct io_kiocb *req, bool force_nonblock)
        struct file *file;
        int ret;
 
-       if (force_nonblock)
+       if (force_nonblock && !req->open.ignore_nonblock)
                return -EAGAIN;
 
        ret = build_open_flags(&req->open.how, &op);
@@ -3822,6 +3855,21 @@ static int io_openat2(struct io_kiocb *req, bool force_nonblock)
        if (IS_ERR(file)) {
                put_unused_fd(ret);
                ret = PTR_ERR(file);
+               /*
+                * A work-around to ensure that /proc/self works that way
+                * that it should - if we get -EOPNOTSUPP back, then assume
+                * that proc_self_get_link() failed us because we're in async
+                * context. We should be safe to retry this from the task
+                * itself with force_nonblock == false set, as it should not
+                * block on lookup. Would be nice to know this upfront and
+                * avoid the async dance, but doesn't seem feasible.
+                */
+               if (ret == -EOPNOTSUPP && io_wq_current_is_worker()) {
+                       req->open.ignore_nonblock = true;
+                       refcount_inc(&req->refs);
+                       io_req_task_queue(req);
+                       return 0;
+               }
        } else {
                fsnotify_open(file);
                fd_install(ret, file);
@@ -6926,9 +6974,7 @@ static int io_sqe_files_unregister(struct io_ring_ctx *ctx)
                return -ENXIO;
 
        spin_lock(&data->lock);
-       if (!list_empty(&data->ref_list))
-               ref_node = list_first_entry(&data->ref_list,
-                               struct fixed_file_ref_node, node);
+       ref_node = data->node;
        spin_unlock(&data->lock);
        if (ref_node)
                percpu_ref_kill(&ref_node->refs);
@@ -7277,10 +7323,6 @@ static void __io_file_put_work(struct fixed_file_ref_node *ref_node)
                kfree(pfile);
        }
 
-       spin_lock(&file_data->lock);
-       list_del(&ref_node->node);
-       spin_unlock(&file_data->lock);
-
        percpu_ref_exit(&ref_node->refs);
        kfree(ref_node);
        percpu_ref_put(&file_data->refs);
@@ -7307,17 +7349,32 @@ static void io_file_put_work(struct work_struct *work)
 static void io_file_data_ref_zero(struct percpu_ref *ref)
 {
        struct fixed_file_ref_node *ref_node;
+       struct fixed_file_data *data;
        struct io_ring_ctx *ctx;
-       bool first_add;
+       bool first_add = false;
        int delay = HZ;
 
        ref_node = container_of(ref, struct fixed_file_ref_node, refs);
-       ctx = ref_node->file_data->ctx;
+       data = ref_node->file_data;
+       ctx = data->ctx;
+
+       spin_lock(&data->lock);
+       ref_node->done = true;
+
+       while (!list_empty(&data->ref_list)) {
+               ref_node = list_first_entry(&data->ref_list,
+                                       struct fixed_file_ref_node, node);
+               /* recycle ref nodes in order */
+               if (!ref_node->done)
+                       break;
+               list_del(&ref_node->node);
+               first_add |= llist_add(&ref_node->llist, &ctx->file_put_llist);
+       }
+       spin_unlock(&data->lock);
 
-       if (percpu_ref_is_dying(&ctx->file_data->refs))
+       if (percpu_ref_is_dying(&data->refs))
                delay = 0;
 
-       first_add = llist_add(&ref_node->llist, &ctx->file_put_llist);
        if (!delay)
                mod_delayed_work(system_wq, &ctx->file_put_work, 0);
        else if (first_add)
@@ -7341,6 +7398,7 @@ static struct fixed_file_ref_node *alloc_fixed_file_ref_node(
        INIT_LIST_HEAD(&ref_node->node);
        INIT_LIST_HEAD(&ref_node->file_list);
        ref_node->file_data = ctx->file_data;
+       ref_node->done = false;
        return ref_node;
 }
 
@@ -7436,7 +7494,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
 
        file_data->node = ref_node;
        spin_lock(&file_data->lock);
-       list_add(&ref_node->node, &file_data->ref_list);
+       list_add_tail(&ref_node->node, &file_data->ref_list);
        spin_unlock(&file_data->lock);
        percpu_ref_get(&file_data->refs);
        return ret;
@@ -7595,7 +7653,7 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
        if (needs_switch) {
                percpu_ref_kill(&data->node->refs);
                spin_lock(&data->lock);
-               list_add(&ref_node->node, &data->ref_list);
+               list_add_tail(&ref_node->node, &data->ref_list);
                data->node = ref_node;
                spin_unlock(&data->lock);
                percpu_ref_get(&ctx->file_data->refs);
@@ -7695,7 +7753,8 @@ static int io_uring_alloc_task_context(struct task_struct *task)
        xa_init(&tctx->xa);
        init_waitqueue_head(&tctx->wait);
        tctx->last = NULL;
-       tctx->in_idle = 0;
+       atomic_set(&tctx->in_idle, 0);
+       tctx->sqpoll = false;
        io_init_identity(&tctx->__identity);
        tctx->identity = &tctx->__identity;
        task->io_uring = tctx;
@@ -8388,22 +8447,6 @@ static bool io_match_link(struct io_kiocb *preq, struct io_kiocb *req)
        return false;
 }
 
-static bool io_match_link_files(struct io_kiocb *req,
-                               struct files_struct *files)
-{
-       struct io_kiocb *link;
-
-       if (io_match_files(req, files))
-               return true;
-       if (req->flags & REQ_F_LINK_HEAD) {
-               list_for_each_entry(link, &req->link_list, link_list) {
-                       if (io_match_files(link, files))
-                               return true;
-               }
-       }
-       return false;
-}
-
 /*
  * We're looking to cancel 'req' because it's holding on to our files, but
  * 'req' could be a link to another request. See if it is, and cancel that
@@ -8453,7 +8496,21 @@ static bool io_timeout_remove_link(struct io_ring_ctx *ctx,
 
 static bool io_cancel_link_cb(struct io_wq_work *work, void *data)
 {
-       return io_match_link(container_of(work, struct io_kiocb, work), data);
+       struct io_kiocb *req = container_of(work, struct io_kiocb, work);
+       bool ret;
+
+       if (req->flags & REQ_F_LINK_TIMEOUT) {
+               unsigned long flags;
+               struct io_ring_ctx *ctx = req->ctx;
+
+               /* protect against races with linked timeouts */
+               spin_lock_irqsave(&ctx->completion_lock, flags);
+               ret = io_match_link(req, data);
+               spin_unlock_irqrestore(&ctx->completion_lock, flags);
+       } else {
+               ret = io_match_link(req, data);
+       }
+       return ret;
 }
 
 static void io_attempt_cancel(struct io_ring_ctx *ctx, struct io_kiocb *req)
@@ -8479,6 +8536,7 @@ static void io_attempt_cancel(struct io_ring_ctx *ctx, struct io_kiocb *req)
 }
 
 static void io_cancel_defer_files(struct io_ring_ctx *ctx,
+                                 struct task_struct *task,
                                  struct files_struct *files)
 {
        struct io_defer_entry *de = NULL;
@@ -8486,7 +8544,8 @@ static void io_cancel_defer_files(struct io_ring_ctx *ctx,
 
        spin_lock_irq(&ctx->completion_lock);
        list_for_each_entry_reverse(de, &ctx->defer_list, list) {
-               if (io_match_link_files(de->req, files)) {
+               if (io_task_match(de->req, task) &&
+                   io_match_files(de->req, files)) {
                        list_cut_position(&list, &ctx->defer_list, &de->list);
                        break;
                }
@@ -8512,7 +8571,6 @@ static bool io_uring_cancel_files(struct io_ring_ctx *ctx,
        if (list_empty_careful(&ctx->inflight_list))
                return false;
 
-       io_cancel_defer_files(ctx, files);
        /* cancel all at once, should be faster than doing it one by one*/
        io_wq_cancel_cb(ctx->io_wq, io_wq_files_match, files, true);
 
@@ -8598,8 +8656,16 @@ static void io_uring_cancel_task_requests(struct io_ring_ctx *ctx,
 {
        struct task_struct *task = current;
 
-       if ((ctx->flags & IORING_SETUP_SQPOLL) && ctx->sq_data)
+       if ((ctx->flags & IORING_SETUP_SQPOLL) && ctx->sq_data) {
                task = ctx->sq_data->thread;
+               atomic_inc(&task->io_uring->in_idle);
+               io_sq_thread_park(ctx->sq_data);
+       }
+
+       if (files)
+               io_cancel_defer_files(ctx, NULL, files);
+       else
+               io_cancel_defer_files(ctx, task, NULL);
 
        io_cqring_overflow_flush(ctx, true, task, files);
 
@@ -8607,12 +8673,23 @@ static void io_uring_cancel_task_requests(struct io_ring_ctx *ctx,
                io_run_task_work();
                cond_resched();
        }
+
+       if ((ctx->flags & IORING_SETUP_SQPOLL) && ctx->sq_data) {
+               atomic_dec(&task->io_uring->in_idle);
+               /*
+                * If the files that are going away are the ones in the thread
+                * identity, clear them out.
+                */
+               if (task->io_uring->identity->files == files)
+                       task->io_uring->identity->files = NULL;
+               io_sq_thread_unpark(ctx->sq_data);
+       }
 }
 
 /*
  * Note that this task has used io_uring. We use it for cancelation purposes.
  */
-static int io_uring_add_task_file(struct file *file)
+static int io_uring_add_task_file(struct io_ring_ctx *ctx, struct file *file)
 {
        struct io_uring_task *tctx = current->io_uring;
 
@@ -8634,6 +8711,14 @@ static int io_uring_add_task_file(struct file *file)
                tctx->last = file;
        }
 
+       /*
+        * This is race safe in that the task itself is doing this, hence it
+        * cannot be going through the exit/cancel paths at the same time.
+        * This cannot be modified while exit/cancel is running.
+        */
+       if (!tctx->sqpoll && (ctx->flags & IORING_SETUP_SQPOLL))
+               tctx->sqpoll = true;
+
        return 0;
 }
 
@@ -8675,7 +8760,7 @@ void __io_uring_files_cancel(struct files_struct *files)
        unsigned long index;
 
        /* make sure overflow events are dropped */
-       tctx->in_idle = true;
+       atomic_inc(&tctx->in_idle);
 
        xa_for_each(&tctx->xa, index, file) {
                struct io_ring_ctx *ctx = file->private_data;
@@ -8684,6 +8769,35 @@ void __io_uring_files_cancel(struct files_struct *files)
                if (files)
                        io_uring_del_task_file(file);
        }
+
+       atomic_dec(&tctx->in_idle);
+}
+
+static s64 tctx_inflight(struct io_uring_task *tctx)
+{
+       unsigned long index;
+       struct file *file;
+       s64 inflight;
+
+       inflight = percpu_counter_sum(&tctx->inflight);
+       if (!tctx->sqpoll)
+               return inflight;
+
+       /*
+        * If we have SQPOLL rings, then we need to iterate and find them, and
+        * add the pending count for those.
+        */
+       xa_for_each(&tctx->xa, index, file) {
+               struct io_ring_ctx *ctx = file->private_data;
+
+               if (ctx->flags & IORING_SETUP_SQPOLL) {
+                       struct io_uring_task *__tctx = ctx->sqo_task->io_uring;
+
+                       inflight += percpu_counter_sum(&__tctx->inflight);
+               }
+       }
+
+       return inflight;
 }
 
 /*
@@ -8697,11 +8811,11 @@ void __io_uring_task_cancel(void)
        s64 inflight;
 
        /* make sure overflow events are dropped */
-       tctx->in_idle = true;
+       atomic_inc(&tctx->in_idle);
 
        do {
                /* read completions before cancelations */
-               inflight = percpu_counter_sum(&tctx->inflight);
+               inflight = tctx_inflight(tctx);
                if (!inflight)
                        break;
                __io_uring_files_cancel(NULL);
@@ -8712,13 +8826,13 @@ void __io_uring_task_cancel(void)
                 * If we've seen completions, retry. This avoids a race where
                 * a completion comes in before we did prepare_to_wait().
                 */
-               if (inflight != percpu_counter_sum(&tctx->inflight))
+               if (inflight != tctx_inflight(tctx))
                        continue;
                schedule();
        } while (1);
 
        finish_wait(&tctx->wait, &wait);
-       tctx->in_idle = false;
+       atomic_dec(&tctx->in_idle);
 }
 
 static int io_uring_flush(struct file *file, void *data)
@@ -8863,7 +8977,7 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
                        io_sqpoll_wait_sq(ctx);
                submitted = to_submit;
        } else if (to_submit) {
-               ret = io_uring_add_task_file(f.file);
+               ret = io_uring_add_task_file(ctx, f.file);
                if (unlikely(ret))
                        goto out;
                mutex_lock(&ctx->uring_lock);
@@ -8900,7 +9014,8 @@ out_fput:
 #ifdef CONFIG_PROC_FS
 static int io_uring_show_cred(int id, void *p, void *data)
 {
-       const struct cred *cred = p;
+       struct io_identity *iod = p;
+       const struct cred *cred = iod->creds;
        struct seq_file *m = data;
        struct user_namespace *uns = seq_user_ns(m);
        struct group_info *gi;
@@ -9092,7 +9207,7 @@ err_fd:
 #if defined(CONFIG_UNIX)
        ctx->ring_sock->file = file;
 #endif
-       if (unlikely(io_uring_add_task_file(file))) {
+       if (unlikely(io_uring_add_task_file(ctx, file))) {
                file = ERR_PTR(-ENOMEM);
                goto err_fd;
        }
@@ -9137,6 +9252,7 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p,
                 * to a power-of-two, if it isn't already. We do NOT impose
                 * any cq vs sq ring sizing.
                 */
+               p->cq_entries = roundup_pow_of_two(p->cq_entries);
                if (p->cq_entries < p->sq_entries)
                        return -EINVAL;
                if (p->cq_entries > IORING_MAX_CQ_ENTRIES) {
@@ -9144,7 +9260,6 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p,
                                return -EINVAL;
                        p->cq_entries = IORING_MAX_CQ_ENTRIES;
                }
-               p->cq_entries = roundup_pow_of_two(p->cq_entries);
        } else {
                p->cq_entries = 2 * p->sq_entries;
        }
index 8180061..10cc797 100644 (file)
@@ -1374,6 +1374,7 @@ iomap_writepage_map(struct iomap_writepage_ctx *wpc,
        WARN_ON_ONCE(!wpc->ioend && !list_empty(&submit_list));
        WARN_ON_ONCE(!PageLocked(page));
        WARN_ON_ONCE(PageWriteback(page));
+       WARN_ON_ONCE(PageDirty(page));
 
        /*
         * We cannot cancel the ioend directly here on error.  We may have
@@ -1382,33 +1383,22 @@ iomap_writepage_map(struct iomap_writepage_ctx *wpc,
         * appropriately.
         */
        if (unlikely(error)) {
+               /*
+                * Let the filesystem know what portion of the current page
+                * failed to map. If the page wasn't been added to ioend, it
+                * won't be affected by I/O completion and we must unlock it
+                * now.
+                */
+               if (wpc->ops->discard_page)
+                       wpc->ops->discard_page(page, file_offset);
                if (!count) {
-                       /*
-                        * If the current page hasn't been added to ioend, it
-                        * won't be affected by I/O completions and we must
-                        * discard and unlock it right here.
-                        */
-                       if (wpc->ops->discard_page)
-                               wpc->ops->discard_page(page);
                        ClearPageUptodate(page);
                        unlock_page(page);
                        goto done;
                }
-
-               /*
-                * If the page was not fully cleaned, we need to ensure that the
-                * higher layers come back to it correctly.  That means we need
-                * to keep the page dirty, and for WB_SYNC_ALL writeback we need
-                * to ensure the PAGECACHE_TAG_TOWRITE index mark is not removed
-                * so another attempt to write this page in this writeback sweep
-                * will be made.
-                */
-               set_page_writeback_keepwrite(page);
-       } else {
-               clear_page_dirty_for_io(page);
-               set_page_writeback(page);
        }
 
+       set_page_writeback(page);
        unlock_page(page);
 
        /*
index 263f02a..472932b 100644 (file)
@@ -106,6 +106,8 @@ static int __try_to_free_cp_buf(struct journal_head *jh)
  * for a checkpoint to free up some space in the log.
  */
 void __jbd2_log_wait_for_space(journal_t *journal)
+__acquires(&journal->j_state_lock)
+__releases(&journal->j_state_lock)
 {
        int nblocks, space_left;
        /* assert_spin_locked(&journal->j_state_lock); */
index fa688e1..b121d7d 100644 (file)
@@ -450,6 +450,15 @@ void jbd2_journal_commit_transaction(journal_t *journal)
                schedule();
                write_lock(&journal->j_state_lock);
                finish_wait(&journal->j_fc_wait, &wait);
+               /*
+                * TODO: by blocking fast commits here, we are increasing
+                * fsync() latency slightly. Strictly speaking, we don't need
+                * to block fast commits until the transaction enters T_FLUSH
+                * state. So an optimization is possible where we block new fast
+                * commits here and wait for existing ones to complete
+                * just before we enter T_FLUSH. That way, the existing fast
+                * commits and this full commit can proceed parallely.
+                */
        }
        write_unlock(&journal->j_state_lock);
 
@@ -801,7 +810,7 @@ start_journal_io:
                if (first_block < journal->j_tail)
                        freed += journal->j_last - journal->j_first;
                /* Update tail only if we free significant amount of space */
-               if (freed < journal->j_maxlen / 4)
+               if (freed < jbd2_journal_get_max_txn_bufs(journal))
                        update_tail = 0;
        }
        J_ASSERT(commit_transaction->t_state == T_COMMIT);
index 0c7c42b..188f79d 100644 (file)
@@ -566,12 +566,14 @@ static int __jbd2_journal_force_commit(journal_t *journal)
 }
 
 /**
- * Force and wait upon a commit if the calling process is not within
- * transaction.  This is used for forcing out undo-protected data which contains
- * bitmaps, when the fs is running out of space.
+ * jbd2_journal_force_commit_nested - Force and wait upon a commit if the
+ * calling process is not within transaction.
  *
  * @journal: journal to force
  * Returns true if progress was made.
+ *
+ * This is used for forcing out undo-protected data which contains
+ * bitmaps, when the fs is running out of space.
  */
 int jbd2_journal_force_commit_nested(journal_t *journal)
 {
@@ -582,7 +584,7 @@ int jbd2_journal_force_commit_nested(journal_t *journal)
 }
 
 /**
- * int journal_force_commit() - force any uncommitted transactions
+ * jbd2_journal_force_commit() - force any uncommitted transactions
  * @journal: journal to force
  *
  * Caller want unconditional commit. We can only force the running transaction
@@ -727,6 +729,8 @@ int jbd2_log_wait_commit(journal_t *journal, tid_t tid)
  */
 int jbd2_fc_begin_commit(journal_t *journal, tid_t tid)
 {
+       if (unlikely(is_journal_aborted(journal)))
+               return -EIO;
        /*
         * Fast commits only allowed if at least one full commit has
         * been processed.
@@ -734,10 +738,12 @@ int jbd2_fc_begin_commit(journal_t *journal, tid_t tid)
        if (!journal->j_stats.ts_tid)
                return -EINVAL;
 
-       if (tid <= journal->j_commit_sequence)
+       write_lock(&journal->j_state_lock);
+       if (tid <= journal->j_commit_sequence) {
+               write_unlock(&journal->j_state_lock);
                return -EALREADY;
+       }
 
-       write_lock(&journal->j_state_lock);
        if (journal->j_flags & JBD2_FULL_COMMIT_ONGOING ||
            (journal->j_flags & JBD2_FAST_COMMIT_ONGOING)) {
                DEFINE_WAIT(wait);
@@ -777,13 +783,19 @@ static int __jbd2_fc_end_commit(journal_t *journal, tid_t tid, bool fallback)
 
 int jbd2_fc_end_commit(journal_t *journal)
 {
-       return __jbd2_fc_end_commit(journal, 0, 0);
+       return __jbd2_fc_end_commit(journal, 0, false);
 }
 EXPORT_SYMBOL(jbd2_fc_end_commit);
 
-int jbd2_fc_end_commit_fallback(journal_t *journal, tid_t tid)
+int jbd2_fc_end_commit_fallback(journal_t *journal)
 {
-       return __jbd2_fc_end_commit(journal, tid, 1);
+       tid_t tid;
+
+       read_lock(&journal->j_state_lock);
+       tid = journal->j_running_transaction ?
+               journal->j_running_transaction->t_tid : 0;
+       read_unlock(&journal->j_state_lock);
+       return __jbd2_fc_end_commit(journal, tid, true);
 }
 EXPORT_SYMBOL(jbd2_fc_end_commit_fallback);
 
@@ -865,7 +877,6 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out)
        int fc_off;
 
        *bh_out = NULL;
-       write_lock(&journal->j_state_lock);
 
        if (journal->j_fc_off + journal->j_fc_first < journal->j_fc_last) {
                fc_off = journal->j_fc_off;
@@ -874,7 +885,6 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out)
        } else {
                ret = -EINVAL;
        }
-       write_unlock(&journal->j_state_lock);
 
        if (ret)
                return ret;
@@ -887,11 +897,7 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out)
        if (!bh)
                return -ENOMEM;
 
-       lock_buffer(bh);
 
-       clear_buffer_uptodate(bh);
-       set_buffer_dirty(bh);
-       unlock_buffer(bh);
        journal->j_fc_wbuf[fc_off] = bh;
 
        *bh_out = bh;
@@ -909,9 +915,7 @@ int jbd2_fc_wait_bufs(journal_t *journal, int num_blks)
        struct buffer_head *bh;
        int i, j_fc_off;
 
-       read_lock(&journal->j_state_lock);
        j_fc_off = journal->j_fc_off;
-       read_unlock(&journal->j_state_lock);
 
        /*
         * Wait in reverse order to minimize chances of us being woken up before
@@ -939,9 +943,7 @@ int jbd2_fc_release_bufs(journal_t *journal)
        struct buffer_head *bh;
        int i, j_fc_off;
 
-       read_lock(&journal->j_state_lock);
        j_fc_off = journal->j_fc_off;
-       read_unlock(&journal->j_state_lock);
 
        /*
         * Wait in reverse order to minimize chances of us being woken up before
@@ -1348,23 +1350,16 @@ static journal_t *journal_init_common(struct block_device *bdev,
        journal->j_dev = bdev;
        journal->j_fs_dev = fs_dev;
        journal->j_blk_offset = start;
-       journal->j_maxlen = len;
+       journal->j_total_len = len;
        /* We need enough buffers to write out full descriptor block. */
        n = journal->j_blocksize / jbd2_min_tag_size();
        journal->j_wbufsize = n;
+       journal->j_fc_wbuf = NULL;
        journal->j_wbuf = kmalloc_array(n, sizeof(struct buffer_head *),
                                        GFP_KERNEL);
        if (!journal->j_wbuf)
                goto err_cleanup;
 
-       if (journal->j_fc_wbufsize > 0) {
-               journal->j_fc_wbuf = kmalloc_array(journal->j_fc_wbufsize,
-                                       sizeof(struct buffer_head *),
-                                       GFP_KERNEL);
-               if (!journal->j_fc_wbuf)
-                       goto err_cleanup;
-       }
-
        bh = getblk_unmovable(journal->j_dev, start, journal->j_blocksize);
        if (!bh) {
                pr_err("%s: Cannot get buffer for journal superblock\n",
@@ -1378,23 +1373,11 @@ static journal_t *journal_init_common(struct block_device *bdev,
 
 err_cleanup:
        kfree(journal->j_wbuf);
-       kfree(journal->j_fc_wbuf);
        jbd2_journal_destroy_revoke(journal);
        kfree(journal);
        return NULL;
 }
 
-int jbd2_fc_init(journal_t *journal, int num_fc_blks)
-{
-       journal->j_fc_wbufsize = num_fc_blks;
-       journal->j_fc_wbuf = kmalloc_array(journal->j_fc_wbufsize,
-                               sizeof(struct buffer_head *), GFP_KERNEL);
-       if (!journal->j_fc_wbuf)
-               return -ENOMEM;
-       return 0;
-}
-EXPORT_SYMBOL(jbd2_fc_init);
-
 /* jbd2_journal_init_dev and jbd2_journal_init_inode:
  *
  * Create a journal structure assigned some fixed set of disk blocks to
@@ -1512,16 +1495,7 @@ static int journal_reset(journal_t *journal)
        }
 
        journal->j_first = first;
-
-       if (jbd2_has_feature_fast_commit(journal) &&
-           journal->j_fc_wbufsize > 0) {
-               journal->j_fc_last = last;
-               journal->j_last = last - journal->j_fc_wbufsize;
-               journal->j_fc_first = journal->j_last + 1;
-               journal->j_fc_off = 0;
-       } else {
-               journal->j_last = last;
-       }
+       journal->j_last = last;
 
        journal->j_head = journal->j_first;
        journal->j_tail = journal->j_first;
@@ -1531,7 +1505,14 @@ static int journal_reset(journal_t *journal)
        journal->j_commit_sequence = journal->j_transaction_sequence - 1;
        journal->j_commit_request = journal->j_commit_sequence;
 
-       journal->j_max_transaction_buffers = journal->j_maxlen / 4;
+       journal->j_max_transaction_buffers = jbd2_journal_get_max_txn_bufs(journal);
+
+       /*
+        * Now that journal recovery is done, turn fast commits off here. This
+        * way, if fast commit was enabled before the crash but if now FS has
+        * disabled it, we don't enable fast commits.
+        */
+       jbd2_clear_feature_fast_commit(journal);
 
        /*
         * As a special case, if the on-disk copy is already marked as needing
@@ -1792,15 +1773,15 @@ static int journal_get_superblock(journal_t *journal)
                goto out;
        }
 
-       if (be32_to_cpu(sb->s_maxlen) < journal->j_maxlen)
-               journal->j_maxlen = be32_to_cpu(sb->s_maxlen);
-       else if (be32_to_cpu(sb->s_maxlen) > journal->j_maxlen) {
+       if (be32_to_cpu(sb->s_maxlen) < journal->j_total_len)
+               journal->j_total_len = be32_to_cpu(sb->s_maxlen);
+       else if (be32_to_cpu(sb->s_maxlen) > journal->j_total_len) {
                printk(KERN_WARNING "JBD2: journal file too short\n");
                goto out;
        }
 
        if (be32_to_cpu(sb->s_first) == 0 ||
-           be32_to_cpu(sb->s_first) >= journal->j_maxlen) {
+           be32_to_cpu(sb->s_first) >= journal->j_total_len) {
                printk(KERN_WARNING
                        "JBD2: Invalid start block of journal: %u\n",
                        be32_to_cpu(sb->s_first));
@@ -1872,6 +1853,7 @@ static int load_superblock(journal_t *journal)
 {
        int err;
        journal_superblock_t *sb;
+       int num_fc_blocks;
 
        err = journal_get_superblock(journal);
        if (err)
@@ -1883,15 +1865,17 @@ static int load_superblock(journal_t *journal)
        journal->j_tail = be32_to_cpu(sb->s_start);
        journal->j_first = be32_to_cpu(sb->s_first);
        journal->j_errno = be32_to_cpu(sb->s_errno);
+       journal->j_last = be32_to_cpu(sb->s_maxlen);
 
-       if (jbd2_has_feature_fast_commit(journal) &&
-           journal->j_fc_wbufsize > 0) {
+       if (jbd2_has_feature_fast_commit(journal)) {
                journal->j_fc_last = be32_to_cpu(sb->s_maxlen);
-               journal->j_last = journal->j_fc_last - journal->j_fc_wbufsize;
+               num_fc_blocks = be32_to_cpu(sb->s_num_fc_blks);
+               if (!num_fc_blocks)
+                       num_fc_blocks = JBD2_MIN_FC_BLOCKS;
+               if (journal->j_last - num_fc_blocks >= JBD2_MIN_JOURNAL_BLOCKS)
+                       journal->j_last = journal->j_fc_last - num_fc_blocks;
                journal->j_fc_first = journal->j_last + 1;
                journal->j_fc_off = 0;
-       } else {
-               journal->j_last = be32_to_cpu(sb->s_maxlen);
        }
 
        return 0;
@@ -1899,7 +1883,7 @@ static int load_superblock(journal_t *journal)
 
 
 /**
- * int jbd2_journal_load() - Read journal from disk.
+ * jbd2_journal_load() - Read journal from disk.
  * @journal: Journal to act on.
  *
  * Given a journal_t structure which tells us which disk blocks contain
@@ -1954,9 +1938,6 @@ int jbd2_journal_load(journal_t *journal)
         */
        journal->j_flags &= ~JBD2_ABORT;
 
-       if (journal->j_fc_wbufsize > 0)
-               jbd2_journal_set_features(journal, 0, 0,
-                                         JBD2_FEATURE_INCOMPAT_FAST_COMMIT);
        /* OK, we've finished with the dynamic journal bits:
         * reinitialise the dynamic contents of the superblock in memory
         * and reset them on disk. */
@@ -1972,7 +1953,7 @@ recovery_error:
 }
 
 /**
- * void jbd2_journal_destroy() - Release a journal_t structure.
+ * jbd2_journal_destroy() - Release a journal_t structure.
  * @journal: Journal to act on.
  *
  * Release a journal_t structure once it is no longer in use by the
@@ -2040,8 +2021,7 @@ int jbd2_journal_destroy(journal_t *journal)
                jbd2_journal_destroy_revoke(journal);
        if (journal->j_chksum_driver)
                crypto_free_shash(journal->j_chksum_driver);
-       if (journal->j_fc_wbufsize > 0)
-               kfree(journal->j_fc_wbuf);
+       kfree(journal->j_fc_wbuf);
        kfree(journal->j_wbuf);
        kfree(journal);
 
@@ -2050,7 +2030,7 @@ int jbd2_journal_destroy(journal_t *journal)
 
 
 /**
- *int jbd2_journal_check_used_features() - Check if features specified are used.
+ * jbd2_journal_check_used_features() - Check if features specified are used.
  * @journal: Journal to check.
  * @compat: bitmask of compatible features
  * @ro: bitmask of features that force read-only mount
@@ -2085,7 +2065,7 @@ int jbd2_journal_check_used_features(journal_t *journal, unsigned long compat,
 }
 
 /**
- * int jbd2_journal_check_available_features() - Check feature set in journalling layer
+ * jbd2_journal_check_available_features() - Check feature set in journalling layer
  * @journal: Journal to check.
  * @compat: bitmask of compatible features
  * @ro: bitmask of features that force read-only mount
@@ -2116,8 +2096,39 @@ int jbd2_journal_check_available_features(journal_t *journal, unsigned long comp
        return 0;
 }
 
+static int
+jbd2_journal_initialize_fast_commit(journal_t *journal)
+{
+       journal_superblock_t *sb = journal->j_superblock;
+       unsigned long long num_fc_blks;
+
+       num_fc_blks = be32_to_cpu(sb->s_num_fc_blks);
+       if (num_fc_blks == 0)
+               num_fc_blks = JBD2_MIN_FC_BLOCKS;
+       if (journal->j_last - num_fc_blks < JBD2_MIN_JOURNAL_BLOCKS)
+               return -ENOSPC;
+
+       /* Are we called twice? */
+       WARN_ON(journal->j_fc_wbuf != NULL);
+       journal->j_fc_wbuf = kmalloc_array(num_fc_blks,
+                               sizeof(struct buffer_head *), GFP_KERNEL);
+       if (!journal->j_fc_wbuf)
+               return -ENOMEM;
+
+       journal->j_fc_wbufsize = num_fc_blks;
+       journal->j_fc_last = journal->j_last;
+       journal->j_last = journal->j_fc_last - num_fc_blks;
+       journal->j_fc_first = journal->j_last + 1;
+       journal->j_fc_off = 0;
+       journal->j_free = journal->j_last - journal->j_first;
+       journal->j_max_transaction_buffers =
+               jbd2_journal_get_max_txn_bufs(journal);
+
+       return 0;
+}
+
 /**
- * int jbd2_journal_set_features() - Mark a given journal feature in the superblock
+ * jbd2_journal_set_features() - Mark a given journal feature in the superblock
  * @journal: Journal to act on.
  * @compat: bitmask of compatible features
  * @ro: bitmask of features that force read-only mount
@@ -2159,6 +2170,13 @@ int jbd2_journal_set_features(journal_t *journal, unsigned long compat,
 
        sb = journal->j_superblock;
 
+       if (incompat & JBD2_FEATURE_INCOMPAT_FAST_COMMIT) {
+               if (jbd2_journal_initialize_fast_commit(journal)) {
+                       pr_err("JBD2: Cannot enable fast commits.\n");
+                       return 0;
+               }
+       }
+
        /* Load the checksum driver if necessary */
        if ((journal->j_chksum_driver == NULL) &&
            INCOMPAT_FEATURE_ON(JBD2_FEATURE_INCOMPAT_CSUM_V3)) {
@@ -2201,7 +2219,7 @@ int jbd2_journal_set_features(journal_t *journal, unsigned long compat,
 }
 
 /*
- * jbd2_journal_clear_features () - Clear a given journal feature in the
+ * jbd2_journal_clear_features() - Clear a given journal feature in the
  *                                 superblock
  * @journal: Journal to act on.
  * @compat: bitmask of compatible features
@@ -2230,7 +2248,7 @@ void jbd2_journal_clear_features(journal_t *journal, unsigned long compat,
 EXPORT_SYMBOL(jbd2_journal_clear_features);
 
 /**
- * int jbd2_journal_flush () - Flush journal
+ * jbd2_journal_flush() - Flush journal
  * @journal: Journal to act on.
  *
  * Flush all data for a given journal to disk and empty the journal.
@@ -2305,7 +2323,7 @@ out:
 }
 
 /**
- * int jbd2_journal_wipe() - Wipe journal contents
+ * jbd2_journal_wipe() - Wipe journal contents
  * @journal: Journal to act on.
  * @write: flag (see below)
  *
@@ -2346,7 +2364,7 @@ int jbd2_journal_wipe(journal_t *journal, int write)
 }
 
 /**
- * void jbd2_journal_abort () - Shutdown the journal immediately.
+ * jbd2_journal_abort () - Shutdown the journal immediately.
  * @journal: the journal to shutdown.
  * @errno:   an error number to record in the journal indicating
  *           the reason for the shutdown.
@@ -2437,7 +2455,7 @@ void jbd2_journal_abort(journal_t *journal, int errno)
 }
 
 /**
- * int jbd2_journal_errno () - returns the journal's error state.
+ * jbd2_journal_errno() - returns the journal's error state.
  * @journal: journal to examine.
  *
  * This is the errno number set with jbd2_journal_abort(), the last
@@ -2461,7 +2479,7 @@ int jbd2_journal_errno(journal_t *journal)
 }
 
 /**
- * int jbd2_journal_clear_err () - clears the journal's error state
+ * jbd2_journal_clear_err() - clears the journal's error state
  * @journal: journal to act on.
  *
  * An error must be cleared or acked to take a FS out of readonly
@@ -2481,7 +2499,7 @@ int jbd2_journal_clear_err(journal_t *journal)
 }
 
 /**
- * void jbd2_journal_ack_err() - Ack journal err.
+ * jbd2_journal_ack_err() - Ack journal err.
  * @journal: journal to act on.
  *
  * An error must be cleared or acked to take a FS out of readonly
index eb26061..dc0694f 100644 (file)
@@ -74,8 +74,8 @@ static int do_readahead(journal_t *journal, unsigned int start)
 
        /* Do up to 128K of readahead */
        max = start + (128 * 1024 / journal->j_blocksize);
-       if (max > journal->j_maxlen)
-               max = journal->j_maxlen;
+       if (max > journal->j_total_len)
+               max = journal->j_total_len;
 
        /* Do the readahead itself.  We'll submit MAXBUF buffer_heads at
         * a time to the block device IO layer. */
@@ -134,7 +134,7 @@ static int jread(struct buffer_head **bhp, journal_t *journal,
 
        *bhp = NULL;
 
-       if (offset >= journal->j_maxlen) {
+       if (offset >= journal->j_total_len) {
                printk(KERN_ERR "JBD2: corrupted journal superblock\n");
                return -EFSCORRUPTED;
        }
index 4398573..9396666 100644 (file)
@@ -195,8 +195,10 @@ static void wait_transaction_switching(journal_t *journal)
        DEFINE_WAIT(wait);
 
        if (WARN_ON(!journal->j_running_transaction ||
-                   journal->j_running_transaction->t_state != T_SWITCH))
+                   journal->j_running_transaction->t_state != T_SWITCH)) {
+               read_unlock(&journal->j_state_lock);
                return;
+       }
        prepare_to_wait(&journal->j_wait_transaction_locked, &wait,
                        TASK_UNINTERRUPTIBLE);
        read_unlock(&journal->j_state_lock);
@@ -517,7 +519,7 @@ EXPORT_SYMBOL(jbd2__journal_start);
 
 
 /**
- * handle_t *jbd2_journal_start() - Obtain a new handle.
+ * jbd2_journal_start() - Obtain a new handle.
  * @journal: Journal to start transaction on.
  * @nblocks: number of block buffer we might modify
  *
@@ -564,7 +566,7 @@ void jbd2_journal_free_reserved(handle_t *handle)
 EXPORT_SYMBOL(jbd2_journal_free_reserved);
 
 /**
- * int jbd2_journal_start_reserved() - start reserved handle
+ * jbd2_journal_start_reserved() - start reserved handle
  * @handle: handle to start
  * @type: for handle statistics
  * @line_no: for handle statistics
@@ -618,7 +620,7 @@ int jbd2_journal_start_reserved(handle_t *handle, unsigned int type,
 EXPORT_SYMBOL(jbd2_journal_start_reserved);
 
 /**
- * int jbd2_journal_extend() - extend buffer credits.
+ * jbd2_journal_extend() - extend buffer credits.
  * @handle:  handle to 'extend'
  * @nblocks: nr blocks to try to extend by.
  * @revoke_records: number of revoke records to try to extend by.
@@ -743,7 +745,7 @@ static void stop_this_handle(handle_t *handle)
 }
 
 /**
- * int jbd2_journal_restart() - restart a handle .
+ * jbd2__journal_restart() - restart a handle .
  * @handle:  handle to restart
  * @nblocks: nr credits requested
  * @revoke_records: number of revoke record credits requested
@@ -813,7 +815,7 @@ int jbd2_journal_restart(handle_t *handle, int nblocks)
 EXPORT_SYMBOL(jbd2_journal_restart);
 
 /**
- * void jbd2_journal_lock_updates () - establish a transaction barrier.
+ * jbd2_journal_lock_updates () - establish a transaction barrier.
  * @journal:  Journal to establish a barrier on.
  *
  * This locks out any further updates from being started, and blocks
@@ -872,7 +874,7 @@ void jbd2_journal_lock_updates(journal_t *journal)
 }
 
 /**
- * void jbd2_journal_unlock_updates (journal_t* journal) - release barrier
+ * jbd2_journal_unlock_updates () - release barrier
  * @journal:  Journal to release the barrier on.
  *
  * Release a transaction barrier obtained with jbd2_journal_lock_updates().
@@ -1180,7 +1182,8 @@ out:
 }
 
 /**
- * int jbd2_journal_get_write_access() - notify intent to modify a buffer for metadata (not data) update.
+ * jbd2_journal_get_write_access() - notify intent to modify a buffer
+ *                                  for metadata (not data) update.
  * @handle: transaction to add buffer modifications to
  * @bh:     bh to be used for metadata writes
  *
@@ -1224,7 +1227,7 @@ int jbd2_journal_get_write_access(handle_t *handle, struct buffer_head *bh)
  * unlocked buffer beforehand. */
 
 /**
- * int jbd2_journal_get_create_access () - notify intent to use newly created bh
+ * jbd2_journal_get_create_access () - notify intent to use newly created bh
  * @handle: transaction to new buffer to
  * @bh: new buffer.
  *
@@ -1304,7 +1307,7 @@ out:
 }
 
 /**
- * int jbd2_journal_get_undo_access() -  Notify intent to modify metadata with
+ * jbd2_journal_get_undo_access() -  Notify intent to modify metadata with
  *     non-rewindable consequences
  * @handle: transaction
  * @bh: buffer to undo
@@ -1381,7 +1384,7 @@ out:
 }
 
 /**
- * void jbd2_journal_set_triggers() - Add triggers for commit writeout
+ * jbd2_journal_set_triggers() - Add triggers for commit writeout
  * @bh: buffer to trigger on
  * @type: struct jbd2_buffer_trigger_type containing the trigger(s).
  *
@@ -1423,7 +1426,7 @@ void jbd2_buffer_abort_trigger(struct journal_head *jh,
 }
 
 /**
- * int jbd2_journal_dirty_metadata() -  mark a buffer as containing dirty metadata
+ * jbd2_journal_dirty_metadata() -  mark a buffer as containing dirty metadata
  * @handle: transaction to add buffer to.
  * @bh: buffer to mark
  *
@@ -1591,7 +1594,7 @@ out:
 }
 
 /**
- * void jbd2_journal_forget() - bforget() for potentially-journaled buffers.
+ * jbd2_journal_forget() - bforget() for potentially-journaled buffers.
  * @handle: transaction handle
  * @bh:     bh to 'forget'
  *
@@ -1760,7 +1763,7 @@ drop:
 }
 
 /**
- * int jbd2_journal_stop() - complete a transaction
+ * jbd2_journal_stop() - complete a transaction
  * @handle: transaction to complete.
  *
  * All done for a particular handle.
@@ -2078,7 +2081,7 @@ out:
 }
 
 /**
- * int jbd2_journal_try_to_free_buffers() - try to free page buffers.
+ * jbd2_journal_try_to_free_buffers() - try to free page buffers.
  * @journal: journal for operation
  * @page: to try and free
  *
@@ -2409,7 +2412,7 @@ zap_buffer_unlocked:
 }
 
 /**
- * void jbd2_journal_invalidatepage()
+ * jbd2_journal_invalidatepage()
  * @journal: journal to use for flush...
  * @page:    page to flush
  * @offset:  start of the range to invalidate
index fc34361..7124c2e 100644 (file)
@@ -959,7 +959,7 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf,
                          size_t len, loff_t *ppos)
 {
        struct simple_attr *attr;
-       u64 val;
+       unsigned long long val;
        size_t size;
        ssize_t ret;
 
@@ -977,7 +977,9 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf,
                goto out;
 
        attr->set_buf[size] = '\0';
-       val = simple_strtoll(attr->set_buf, NULL, 0);
+       ret = kstrtoull(attr->set_buf, 0, &val);
+       if (ret)
+               goto out;
        ret = attr->set(attr->data, val);
        if (ret == 0)
                ret = len; /* on success, claim we got the whole input */
index cb52db9..4e011ad 100644 (file)
@@ -955,7 +955,6 @@ out:
 
 static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int whence)
 {
-       struct inode *inode = file_inode(filp);
        struct nfs_open_dir_context *dir_ctx = filp->private_data;
 
        dfprintk(FILE, "NFS: llseek dir(%pD2, %lld, %d)\n",
@@ -967,15 +966,15 @@ static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int whence)
        case SEEK_SET:
                if (offset < 0)
                        return -EINVAL;
-               inode_lock(inode);
+               spin_lock(&filp->f_lock);
                break;
        case SEEK_CUR:
                if (offset == 0)
                        return filp->f_pos;
-               inode_lock(inode);
+               spin_lock(&filp->f_lock);
                offset += filp->f_pos;
                if (offset < 0) {
-                       inode_unlock(inode);
+                       spin_unlock(&filp->f_lock);
                        return -EINVAL;
                }
        }
@@ -987,7 +986,7 @@ static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int whence)
                        dir_ctx->dir_cookie = 0;
                dir_ctx->duped = 0;
        }
-       inode_unlock(inode);
+       spin_unlock(&filp->f_lock);
        return offset;
 }
 
@@ -998,13 +997,9 @@ static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int whence)
 static int nfs_fsync_dir(struct file *filp, loff_t start, loff_t end,
                         int datasync)
 {
-       struct inode *inode = file_inode(filp);
-
        dfprintk(FILE, "NFS: fsync dir(%pD2) datasync %d\n", filp, datasync);
 
-       inode_lock(inode);
-       nfs_inc_stats(inode, NFSIOS_VFSFSYNC);
-       inode_unlock(inode);
+       nfs_inc_stats(file_inode(filp), NFSIOS_VFSFSYNC);
        return 0;
 }
 
index b51424f..6c2ce79 100644 (file)
@@ -1047,8 +1047,10 @@ out4:
 
 void nfs4_xattr_cache_exit(void)
 {
+       unregister_shrinker(&nfs4_xattr_large_entry_shrinker);
        unregister_shrinker(&nfs4_xattr_entry_shrinker);
        unregister_shrinker(&nfs4_xattr_cache_shrinker);
+       list_lru_destroy(&nfs4_xattr_large_entry_lru);
        list_lru_destroy(&nfs4_xattr_entry_lru);
        list_lru_destroy(&nfs4_xattr_cache_lru);
        kmem_cache_destroy(nfs4_xattr_cache_cachep);
index 0dc31ad..6e060a8 100644 (file)
                                 1 + nfs4_xattr_name_maxsz + 1)
 #define decode_setxattr_maxsz   (op_decode_hdr_maxsz + decode_change_info_maxsz)
 #define encode_listxattrs_maxsz  (op_encode_hdr_maxsz + 2 + 1)
-#define decode_listxattrs_maxsz  (op_decode_hdr_maxsz + 2 + 1 + 1)
+#define decode_listxattrs_maxsz  (op_decode_hdr_maxsz + 2 + 1 + 1 + 1)
 #define encode_removexattr_maxsz (op_encode_hdr_maxsz + 1 + \
                                  nfs4_xattr_name_maxsz)
 #define decode_removexattr_maxsz (op_decode_hdr_maxsz + \
@@ -531,7 +531,7 @@ static void encode_listxattrs(struct xdr_stream *xdr,
 {
        __be32 *p;
 
-       encode_op_hdr(xdr, OP_LISTXATTRS, decode_listxattrs_maxsz + 1, hdr);
+       encode_op_hdr(xdr, OP_LISTXATTRS, decode_listxattrs_maxsz, hdr);
 
        p = reserve_space(xdr, 12);
        if (unlikely(!p))
index 8d32788..fa14830 100644 (file)
 #define NFS_ROOT               "/tftpboot/%s"
 
 /* Default NFSROOT mount options. */
+#if defined(CONFIG_NFS_V2)
 #define NFS_DEF_OPTIONS                "vers=2,tcp,rsize=4096,wsize=4096"
+#elif defined(CONFIG_NFS_V3)
+#define NFS_DEF_OPTIONS                "vers=3,tcp,rsize=4096,wsize=4096"
+#else
+#define NFS_DEF_OPTIONS                "vers=4,tcp,rsize=4096,wsize=4096"
+#endif
 
 /* Parameters passed from the kernel command line */
 static char nfs_root_parms[NFS_MAXPATHLEN + 1] __initdata = "";
index 1446861..a633044 100644 (file)
@@ -316,10 +316,6 @@ nfsd3_proc_mknod(struct svc_rqst *rqstp)
        fh_copy(&resp->dirfh, &argp->fh);
        fh_init(&resp->fh, NFS3_FHSIZE);
 
-       if (argp->ftype == 0 || argp->ftype >= NF3BAD) {
-               resp->status = nfserr_inval;
-               goto out;
-       }
        if (argp->ftype == NF3CHR || argp->ftype == NF3BLK) {
                rdev = MKDEV(argp->major, argp->minor);
                if (MAJOR(rdev) != argp->major ||
@@ -328,7 +324,7 @@ nfsd3_proc_mknod(struct svc_rqst *rqstp)
                        goto out;
                }
        } else if (argp->ftype != NF3SOCK && argp->ftype != NF3FIFO) {
-               resp->status = nfserr_inval;
+               resp->status = nfserr_badtype;
                goto out;
        }
 
index 9c23b6a..2277f83 100644 (file)
@@ -1114,6 +1114,7 @@ nfs3svc_encode_pathconfres(struct svc_rqst *rqstp, __be32 *p)
 {
        struct nfsd3_pathconfres *resp = rqstp->rq_resp;
 
+       *p++ = resp->status;
        *p++ = xdr_zero;        /* no post_op_attr */
 
        if (resp->status == 0) {
index ad2fa1a..e83b217 100644 (file)
@@ -1299,7 +1299,7 @@ nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src,
                        struct nfsd_file *dst)
 {
        nfs42_ssc_close(src->nf_file);
-       nfsd_file_put(src);
+       /* 'src' is freed by nfsd4_do_async_copy */
        nfsd_file_put(dst);
        mntput(ss_mnt);
 }
@@ -1486,6 +1486,7 @@ do_callback:
        cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
        if (!cb_copy)
                goto out;
+       refcount_set(&cb_copy->refcount, 1);
        memcpy(&cb_copy->cp_res, &copy->cp_res, sizeof(copy->cp_res));
        cb_copy->cp_clp = copy->cp_clp;
        cb_copy->nfserr = copy->nfserr;
index a960ec3..8d3ad5e 100644 (file)
@@ -178,6 +178,7 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data,
        struct inode *inode = d_inode(dentry);
        struct dentry *parent;
        bool parent_watched = dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED;
+       bool parent_needed, parent_interested;
        __u32 p_mask;
        struct inode *p_inode = NULL;
        struct name_snapshot name;
@@ -193,7 +194,8 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data,
                return 0;
 
        parent = NULL;
-       if (!parent_watched && !fsnotify_event_needs_parent(inode, mnt, mask))
+       parent_needed = fsnotify_event_needs_parent(inode, mnt, mask);
+       if (!parent_watched && !parent_needed)
                goto notify;
 
        /* Does parent inode care about events on children? */
@@ -205,17 +207,17 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data,
 
        /*
         * Include parent/name in notification either if some notification
-        * groups require parent info (!parent_watched case) or the parent is
-        * interested in this event.
+        * groups require parent info or the parent is interested in this event.
         */
-       if (!parent_watched || (mask & p_mask & ALL_FSNOTIFY_EVENTS)) {
+       parent_interested = mask & p_mask & ALL_FSNOTIFY_EVENTS;
+       if (parent_needed || parent_interested) {
                /* When notifying parent, child should be passed as data */
                WARN_ON_ONCE(inode != fsnotify_data_inode(data, data_type));
 
                /* Notify both parent and child with child name info */
                take_dentry_name_snapshot(&name, dentry);
                file_name = &name.name;
-               if (parent_watched)
+               if (parent_interested)
                        mask |= FS_EVENT_ON_CHILD;
        }
 
index b9a9d69..db52e84 100644 (file)
@@ -877,7 +877,7 @@ int ocfs2_journal_init(struct ocfs2_journal *journal, int *dirty)
                goto done;
        }
 
-       trace_ocfs2_journal_init_maxlen(j_journal->j_maxlen);
+       trace_ocfs2_journal_init_maxlen(j_journal->j_total_len);
 
        *dirty = (le32_to_cpu(di->id1.journal1.ij_flags) &
                  OCFS2_JOURNAL_DIRTY_FL);
index 1d91dd1..2febc76 100644 (file)
@@ -1713,6 +1713,7 @@ static void ocfs2_inode_init_once(void *data)
 
        oi->ip_blkno = 0ULL;
        oi->ip_clusters = 0;
+       oi->ip_next_orphan = NULL;
 
        ocfs2_resv_init_once(&oi->ip_la_data_resv);
 
index 0f70700..b362523 100644 (file)
@@ -1049,6 +1049,8 @@ static ssize_t oom_adj_read(struct file *file, char __user *buf, size_t count,
                oom_adj = (task->signal->oom_score_adj * -OOM_DISABLE) /
                          OOM_SCORE_ADJ_MAX;
        put_task_struct(task);
+       if (oom_adj > OOM_ADJUST_MAX)
+               oom_adj = OOM_ADJUST_MAX;
        len = snprintf(buffer, sizeof(buffer), "%d\n", oom_adj);
        return simple_read_from_buffer(buf, count, ppos, buffer, len);
 }
index d0989a4..419760f 100644 (file)
@@ -19,7 +19,7 @@ static int cpuinfo_open(struct inode *inode, struct file *file)
 static const struct proc_ops cpuinfo_proc_ops = {
        .proc_flags     = PROC_ENTRY_PERMANENT,
        .proc_open      = cpuinfo_open,
-       .proc_read      = seq_read,
+       .proc_read_iter = seq_read_iter,
        .proc_lseek     = seq_lseek,
        .proc_release   = seq_release,
 };
index 2f9fa17..b846632 100644 (file)
@@ -590,7 +590,7 @@ static int proc_seq_release(struct inode *inode, struct file *file)
 static const struct proc_ops proc_seq_ops = {
        /* not permanent -- can call into arbitrary seq_operations */
        .proc_open      = proc_seq_open,
-       .proc_read      = seq_read,
+       .proc_read_iter = seq_read_iter,
        .proc_lseek     = seq_lseek,
        .proc_release   = proc_seq_release,
 };
@@ -621,7 +621,7 @@ static int proc_single_open(struct inode *inode, struct file *file)
 static const struct proc_ops proc_single_ops = {
        /* not permanent -- can call into arbitrary ->single_show */
        .proc_open      = proc_single_open,
-       .proc_read      = seq_read,
+       .proc_read_iter = seq_read_iter,
        .proc_lseek     = seq_lseek,
        .proc_release   = single_release,
 };
index 58c075e..bde6b6f 100644 (file)
@@ -597,6 +597,7 @@ static const struct file_operations proc_iter_file_ops = {
        .llseek         = proc_reg_llseek,
        .read_iter      = proc_reg_read_iter,
        .write          = proc_reg_write,
+       .splice_read    = generic_file_splice_read,
        .poll           = proc_reg_poll,
        .unlocked_ioctl = proc_reg_unlocked_ioctl,
        .mmap           = proc_reg_mmap,
@@ -622,6 +623,7 @@ static const struct file_operations proc_reg_file_ops_compat = {
 static const struct file_operations proc_iter_file_ops_compat = {
        .llseek         = proc_reg_llseek,
        .read_iter      = proc_reg_read_iter,
+       .splice_read    = generic_file_splice_read,
        .write          = proc_reg_write,
        .poll           = proc_reg_poll,
        .unlocked_ioctl = proc_reg_unlocked_ioctl,
index 72cd69b..cc71ce3 100644 (file)
@@ -16,6 +16,13 @@ static const char *proc_self_get_link(struct dentry *dentry,
        pid_t tgid = task_tgid_nr_ns(current, ns);
        char *name;
 
+       /*
+        * Not currently supported. Once we can inherit all of struct pid,
+        * we can allow this.
+        */
+       if (current->flags & PF_KTHREAD)
+               return ERR_PTR(-EOPNOTSUPP);
+
        if (!tgid)
                return ERR_PTR(-ENOENT);
        /* max length of unsigned int in decimal + NULL term */
index 46b3293..4695b6d 100644 (file)
@@ -226,7 +226,7 @@ static int stat_open(struct inode *inode, struct file *file)
 static const struct proc_ops stat_proc_ops = {
        .proc_flags     = PROC_ENTRY_PERMANENT,
        .proc_open      = stat_open,
-       .proc_read      = seq_read,
+       .proc_read_iter = seq_read_iter,
        .proc_lseek     = seq_lseek,
        .proc_release   = single_release,
 };
index 31219c1..3b20e21 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/mm.h>
 #include <linux/printk.h>
 #include <linux/string_helpers.h>
+#include <linux/uio.h>
 
 #include <linux/uaccess.h>
 #include <asm/page.h>
@@ -146,7 +147,28 @@ Eoverflow:
  */
 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
 {
-       struct seq_file *m = file->private_data;
+       struct iovec iov = { .iov_base = buf, .iov_len = size};
+       struct kiocb kiocb;
+       struct iov_iter iter;
+       ssize_t ret;
+
+       init_sync_kiocb(&kiocb, file);
+       iov_iter_init(&iter, READ, &iov, 1, size);
+
+       kiocb.ki_pos = *ppos;
+       ret = seq_read_iter(&kiocb, &iter);
+       *ppos = kiocb.ki_pos;
+       return ret;
+}
+EXPORT_SYMBOL(seq_read);
+
+/*
+ * Ready-made ->f_op->read_iter()
+ */
+ssize_t seq_read_iter(struct kiocb *iocb, struct iov_iter *iter)
+{
+       struct seq_file *m = iocb->ki_filp->private_data;
+       size_t size = iov_iter_count(iter);
        size_t copied = 0;
        size_t n;
        void *p;
@@ -158,14 +180,14 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
         * if request is to read from zero offset, reset iterator to first
         * record as it might have been already advanced by previous requests
         */
-       if (*ppos == 0) {
+       if (iocb->ki_pos == 0) {
                m->index = 0;
                m->count = 0;
        }
 
-       /* Don't assume *ppos is where we left it */
-       if (unlikely(*ppos != m->read_pos)) {
-               while ((err = traverse(m, *ppos)) == -EAGAIN)
+       /* Don't assume ki_pos is where we left it */
+       if (unlikely(iocb->ki_pos != m->read_pos)) {
+               while ((err = traverse(m, iocb->ki_pos)) == -EAGAIN)
                        ;
                if (err) {
                        /* With prejudice... */
@@ -174,7 +196,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
                        m->count = 0;
                        goto Done;
                } else {
-                       m->read_pos = *ppos;
+                       m->read_pos = iocb->ki_pos;
                }
        }
 
@@ -187,13 +209,11 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
        /* if not empty - flush it first */
        if (m->count) {
                n = min(m->count, size);
-               err = copy_to_user(buf, m->buf + m->from, n);
-               if (err)
+               if (copy_to_iter(m->buf + m->from, n, iter) != n)
                        goto Efault;
                m->count -= n;
                m->from += n;
                size -= n;
-               buf += n;
                copied += n;
                if (!size)
                        goto Done;
@@ -254,8 +274,7 @@ Fill:
        }
        m->op->stop(m, p);
        n = min(m->count, size);
-       err = copy_to_user(buf, m->buf, n);
-       if (err)
+       if (copy_to_iter(m->buf, n, iter) != n)
                goto Efault;
        copied += n;
        m->count -= n;
@@ -264,7 +283,7 @@ Done:
        if (!copied)
                copied = err;
        else {
-               *ppos += copied;
+               iocb->ki_pos += copied;
                m->read_pos += copied;
        }
        mutex_unlock(&m->lock);
@@ -276,7 +295,7 @@ Efault:
        err = -EFAULT;
        goto Done;
 }
-EXPORT_SYMBOL(seq_read);
+EXPORT_SYMBOL(seq_read_iter);
 
 /**
  *     seq_lseek -     ->llseek() method for sequential files.
index a51c208..98bb062 100644 (file)
@@ -1631,55 +1631,6 @@ int super_setup_bdi(struct super_block *sb)
 }
 EXPORT_SYMBOL(super_setup_bdi);
 
-/*
- * This is an internal function, please use sb_end_{write,pagefault,intwrite}
- * instead.
- */
-void __sb_end_write(struct super_block *sb, int level)
-{
-       percpu_up_read(sb->s_writers.rw_sem + level-1);
-}
-EXPORT_SYMBOL(__sb_end_write);
-
-/*
- * This is an internal function, please use sb_start_{write,pagefault,intwrite}
- * instead.
- */
-int __sb_start_write(struct super_block *sb, int level, bool wait)
-{
-       bool force_trylock = false;
-       int ret = 1;
-
-#ifdef CONFIG_LOCKDEP
-       /*
-        * We want lockdep to tell us about possible deadlocks with freezing
-        * but it's it bit tricky to properly instrument it. Getting a freeze
-        * protection works as getting a read lock but there are subtle
-        * problems. XFS for example gets freeze protection on internal level
-        * twice in some cases, which is OK only because we already hold a
-        * freeze protection also on higher level. Due to these cases we have
-        * to use wait == F (trylock mode) which must not fail.
-        */
-       if (wait) {
-               int i;
-
-               for (i = 0; i < level - 1; i++)
-                       if (percpu_rwsem_is_held(sb->s_writers.rw_sem + i)) {
-                               force_trylock = true;
-                               break;
-                       }
-       }
-#endif
-       if (wait && !force_trylock)
-               percpu_down_read(sb->s_writers.rw_sem + level-1);
-       else
-               ret = percpu_down_read_trylock(sb->s_writers.rw_sem + level-1);
-
-       WARN_ON(force_trylock && !ret);
-       return ret;
-}
-EXPORT_SYMBOL(__sb_start_write);
-
 /**
  * sb_wait_write - wait until all writers to given file system finish
  * @sb: the super for which we wait
index 852b536..1564001 100644 (file)
@@ -2467,6 +2467,7 @@ xfs_defer_agfl_block(
        new->xefi_startblock = XFS_AGB_TO_FSB(mp, agno, agbno);
        new->xefi_blockcount = 1;
        new->xefi_oinfo = *oinfo;
+       new->xefi_skip_discard = false;
 
        trace_xfs_agfl_free_defer(mp, agno, 0, agbno, 1);
 
index bb128db..d6ef69a 100644 (file)
@@ -515,7 +515,7 @@ xfs_attr_copy_value(
  *========================================================================*/
 
 /*
- * Query whether the requested number of additional bytes of extended
+ * Query whether the total requested number of attr fork bytes of extended
  * attribute space will be able to fit inline.
  *
  * Returns zero if not, else the di_forkoff fork offset to be used in the
@@ -535,6 +535,12 @@ xfs_attr_shortform_bytesfit(
        int                     maxforkoff;
        int                     offset;
 
+       /*
+        * Check if the new size could fit at all first:
+        */
+       if (bytes > XFS_LITINO(mp))
+               return 0;
+
        /* rounded down */
        offset = (XFS_LITINO(mp) - bytes) >> 3;
 
index e1bd484..6747e97 100644 (file)
@@ -52,9 +52,9 @@ struct xfs_extent_free_item
 {
        xfs_fsblock_t           xefi_startblock;/* starting fs block number */
        xfs_extlen_t            xefi_blockcount;/* number of blocks in extent */
+       bool                    xefi_skip_discard;
        struct list_head        xefi_list;
        struct xfs_owner_info   xefi_oinfo;     /* extent owner */
-       bool                    xefi_skip_discard;
 };
 
 #define        XFS_BMAP_MAX_NMAP       4
index 340c83f..2668ebe 100644 (file)
@@ -1514,7 +1514,7 @@ xfs_rmap_convert_shared(
         * record for our insertion point. This will also give us the record for
         * start block contiguity tests.
         */
-       error = xfs_rmap_lookup_le_range(cur, bno, owner, offset, flags,
+       error = xfs_rmap_lookup_le_range(cur, bno, owner, offset, oldext,
                        &PREV, &i);
        if (error)
                goto done;
index 955302e..fed56d2 100644 (file)
@@ -113,6 +113,8 @@ xchk_bmap_get_rmap(
 
        if (info->whichfork == XFS_ATTR_FORK)
                rflags |= XFS_RMAP_ATTR_FORK;
+       if (irec->br_state == XFS_EXT_UNWRITTEN)
+               rflags |= XFS_RMAP_UNWRITTEN;
 
        /*
         * CoW staging extents are owned (on disk) by the refcountbt, so
@@ -216,13 +218,13 @@ xchk_bmap_xref_rmap(
         * which doesn't track unwritten state.
         */
        if (owner != XFS_RMAP_OWN_COW &&
-           irec->br_state == XFS_EXT_UNWRITTEN &&
-           !(rmap.rm_flags & XFS_RMAP_UNWRITTEN))
+           !!(irec->br_state == XFS_EXT_UNWRITTEN) !=
+           !!(rmap.rm_flags & XFS_RMAP_UNWRITTEN))
                xchk_fblock_xref_set_corrupt(info->sc, info->whichfork,
                                irec->br_startoff);
 
-       if (info->whichfork == XFS_ATTR_FORK &&
-           !(rmap.rm_flags & XFS_RMAP_ATTR_FORK))
+       if (!!(info->whichfork == XFS_ATTR_FORK) !=
+           !!(rmap.rm_flags & XFS_RMAP_ATTR_FORK))
                xchk_fblock_xref_set_corrupt(info->sc, info->whichfork,
                                irec->br_startoff);
        if (rmap.rm_flags & XFS_RMAP_BMBT_BLOCK)
index f52a7b8..debf392 100644 (file)
@@ -452,32 +452,41 @@ xchk_btree_check_minrecs(
        int                     level,
        struct xfs_btree_block  *block)
 {
-       unsigned int            numrecs;
-       int                     ok_level;
-
-       numrecs = be16_to_cpu(block->bb_numrecs);
+       struct xfs_btree_cur    *cur = bs->cur;
+       unsigned int            root_level = cur->bc_nlevels - 1;
+       unsigned int            numrecs = be16_to_cpu(block->bb_numrecs);
 
        /* More records than minrecs means the block is ok. */
-       if (numrecs >= bs->cur->bc_ops->get_minrecs(bs->cur, level))
+       if (numrecs >= cur->bc_ops->get_minrecs(cur, level))
                return;
 
        /*
-        * Certain btree blocks /can/ have fewer than minrecs records.  Any
-        * level greater than or equal to the level of the highest dedicated
-        * btree block are allowed to violate this constraint.
-        *
-        * For a btree rooted in a block, the btree root can have fewer than
-        * minrecs records.  If the btree is rooted in an inode and does not
-        * store records in the root, the direct children of the root and the
-        * root itself can have fewer than minrecs records.
+        * For btrees rooted in the inode, it's possible that the root block
+        * contents spilled into a regular ondisk block because there wasn't
+        * enough space in the inode root.  The number of records in that
+        * child block might be less than the standard minrecs, but that's ok
+        * provided that there's only one direct child of the root.
         */
-       ok_level = bs->cur->bc_nlevels - 1;
-       if (bs->cur->bc_flags & XFS_BTREE_ROOT_IN_INODE)
-               ok_level--;
-       if (level >= ok_level)
+       if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) &&
+           level == cur->bc_nlevels - 2) {
+               struct xfs_btree_block  *root_block;
+               struct xfs_buf          *root_bp;
+               int                     root_maxrecs;
+
+               root_block = xfs_btree_get_block(cur, root_level, &root_bp);
+               root_maxrecs = cur->bc_ops->get_dmaxrecs(cur, root_level);
+               if (be16_to_cpu(root_block->bb_numrecs) != 1 ||
+                   numrecs <= root_maxrecs)
+                       xchk_btree_set_corrupt(bs->sc, cur, level);
                return;
+       }
 
-       xchk_btree_set_corrupt(bs->sc, bs->cur, level);
+       /*
+        * Otherwise, only the root level is allowed to have fewer than minrecs
+        * records or keyptrs.
+        */
+       if (level < root_level)
+               xchk_btree_set_corrupt(bs->sc, cur, level);
 }
 
 /*
index 7c43299..b045e95 100644 (file)
@@ -558,14 +558,27 @@ xchk_directory_leaf1_bestfree(
        /* Check all the bestfree entries. */
        for (i = 0; i < bestcount; i++, bestp++) {
                best = be16_to_cpu(*bestp);
-               if (best == NULLDATAOFF)
-                       continue;
                error = xfs_dir3_data_read(sc->tp, sc->ip,
-                               i * args->geo->fsbcount, 0, &dbp);
+                               xfs_dir2_db_to_da(args->geo, i),
+                               XFS_DABUF_MAP_HOLE_OK,
+                               &dbp);
                if (!xchk_fblock_process_error(sc, XFS_DATA_FORK, lblk,
                                &error))
                        break;
-               xchk_directory_check_freesp(sc, lblk, dbp, best);
+
+               if (!dbp) {
+                       if (best != NULLDATAOFF) {
+                               xchk_fblock_set_corrupt(sc, XFS_DATA_FORK,
+                                               lblk);
+                               break;
+                       }
+                       continue;
+               }
+
+               if (best == NULLDATAOFF)
+                       xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, lblk);
+               else
+                       xchk_directory_check_freesp(sc, lblk, dbp, best);
                xfs_trans_brelse(sc->tp, dbp);
                if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
                        break;
index 3aa85b6..bb25ff1 100644 (file)
@@ -121,8 +121,7 @@ xchk_inode_flags(
                goto bad;
 
        /* rt flags require rt device */
-       if ((flags & (XFS_DIFLAG_REALTIME | XFS_DIFLAG_RTINHERIT)) &&
-           !mp->m_rtdev_targp)
+       if ((flags & XFS_DIFLAG_REALTIME) && !mp->m_rtdev_targp)
                goto bad;
 
        /* new rt bitmap flag only valid for rbmino */
index beaeb6f..dd672e6 100644 (file)
@@ -170,7 +170,6 @@ xchk_refcountbt_process_rmap_fragments(
         */
        INIT_LIST_HEAD(&worklist);
        rbno = NULLAGBLOCK;
-       nr = 1;
 
        /* Make sure the fragments actually /are/ in agbno order. */
        bno = 0;
@@ -184,15 +183,14 @@ xchk_refcountbt_process_rmap_fragments(
         * Find all the rmaps that start at or before the refc extent,
         * and put them on the worklist.
         */
+       nr = 0;
        list_for_each_entry_safe(frag, n, &refchk->fragments, list) {
-               if (frag->rm.rm_startblock > refchk->bno)
-                       goto done;
+               if (frag->rm.rm_startblock > refchk->bno || nr > target_nr)
+                       break;
                bno = frag->rm.rm_startblock + frag->rm.rm_blockcount;
                if (bno < rbno)
                        rbno = bno;
                list_move_tail(&frag->list, &worklist);
-               if (nr == target_nr)
-                       break;
                nr++;
        }
 
index 55d126d..4304c64 100644 (file)
@@ -346,8 +346,8 @@ xfs_map_blocks(
        ssize_t                 count = i_blocksize(inode);
        xfs_fileoff_t           offset_fsb = XFS_B_TO_FSBT(mp, offset);
        xfs_fileoff_t           end_fsb = XFS_B_TO_FSB(mp, offset + count);
-       xfs_fileoff_t           cow_fsb = NULLFILEOFF;
-       int                     whichfork = XFS_DATA_FORK;
+       xfs_fileoff_t           cow_fsb;
+       int                     whichfork;
        struct xfs_bmbt_irec    imap;
        struct xfs_iext_cursor  icur;
        int                     retries = 0;
@@ -381,6 +381,8 @@ xfs_map_blocks(
         * landed in a hole and we skip the block.
         */
 retry:
+       cow_fsb = NULLFILEOFF;
+       whichfork = XFS_DATA_FORK;
        xfs_ilock(ip, XFS_ILOCK_SHARED);
        ASSERT(ip->i_df.if_format != XFS_DINODE_FMT_BTREE ||
               (ip->i_df.if_flags & XFS_IFEXTENTS));
@@ -527,13 +529,15 @@ xfs_prepare_ioend(
  */
 static void
 xfs_discard_page(
-       struct page             *page)
+       struct page             *page,
+       loff_t                  fileoff)
 {
        struct inode            *inode = page->mapping->host;
        struct xfs_inode        *ip = XFS_I(inode);
        struct xfs_mount        *mp = ip->i_mount;
-       loff_t                  offset = page_offset(page);
-       xfs_fileoff_t           start_fsb = XFS_B_TO_FSBT(mp, offset);
+       unsigned int            pageoff = offset_in_page(fileoff);
+       xfs_fileoff_t           start_fsb = XFS_B_TO_FSBT(mp, fileoff);
+       xfs_fileoff_t           pageoff_fsb = XFS_B_TO_FSBT(mp, pageoff);
        int                     error;
 
        if (XFS_FORCED_SHUTDOWN(mp))
@@ -541,14 +545,14 @@ xfs_discard_page(
 
        xfs_alert_ratelimited(mp,
                "page discard on page "PTR_FMT", inode 0x%llx, offset %llu.",
-                       page, ip->i_ino, offset);
+                       page, ip->i_ino, fileoff);
 
        error = xfs_bmap_punch_delalloc_range(ip, start_fsb,
-                       i_blocks_per_page(inode, page));
+                       i_blocks_per_page(inode, page) - pageoff_fsb);
        if (error && !XFS_FORCED_SHUTDOWN(mp))
                xfs_alert(mp, "page discard unable to remove delalloc mapping.");
 out_invalidate:
-       iomap_invalidatepage(page, 0, PAGE_SIZE);
+       iomap_invalidatepage(page, pageoff, PAGE_SIZE - pageoff);
 }
 
 static const struct iomap_writeback_ops xfs_writeback_ops = {
index 3abb8b9..7b9ff82 100644 (file)
@@ -706,6 +706,23 @@ relock:
        return 0;
 }
 
+/*
+ * Check that the imap we are going to return to the caller spans the entire
+ * range that the caller requested for the IO.
+ */
+static bool
+imap_spans_range(
+       struct xfs_bmbt_irec    *imap,
+       xfs_fileoff_t           offset_fsb,
+       xfs_fileoff_t           end_fsb)
+{
+       if (imap->br_startoff > offset_fsb)
+               return false;
+       if (imap->br_startoff + imap->br_blockcount < end_fsb)
+               return false;
+       return true;
+}
+
 static int
 xfs_direct_write_iomap_begin(
        struct inode            *inode,
@@ -766,6 +783,18 @@ xfs_direct_write_iomap_begin(
        if (imap_needs_alloc(inode, flags, &imap, nimaps))
                goto allocate_blocks;
 
+       /*
+        * NOWAIT IO needs to span the entire requested IO with a single map so
+        * that we avoid partial IO failures due to the rest of the IO range not
+        * covered by this map triggering an EAGAIN condition when it is
+        * subsequently mapped and aborting the IO.
+        */
+       if ((flags & IOMAP_NOWAIT) &&
+           !imap_spans_range(&imap, offset_fsb, end_fsb)) {
+               error = -EAGAIN;
+               goto out_unlock;
+       }
+
        xfs_iunlock(ip, lockmode);
        trace_xfs_iomap_found(ip, offset, length, XFS_DATA_FORK, &imap);
        return xfs_bmbt_to_iomap(ip, iomap, &imap, iomap_flags);
index 5e16545..1414ab7 100644 (file)
@@ -911,6 +911,16 @@ xfs_setattr_size(
                error = iomap_zero_range(inode, oldsize, newsize - oldsize,
                                &did_zeroing, &xfs_buffered_write_iomap_ops);
        } else {
+               /*
+                * iomap won't detect a dirty page over an unwritten block (or a
+                * cow block over a hole) and subsequently skips zeroing the
+                * newly post-EOF portion of the page. Flush the new EOF to
+                * convert the block before the pagecache truncate.
+                */
+               error = filemap_write_and_wait_range(inode->i_mapping, newsize,
+                                                    newsize);
+               if (error)
+                       return error;
                error = iomap_truncate_page(inode, newsize, &did_zeroing,
                                &xfs_buffered_write_iomap_ops);
        }
index 233dcc8..2a45138 100644 (file)
@@ -55,6 +55,9 @@ struct xfs_iwalk_ag {
        /* Where do we start the traversal? */
        xfs_ino_t                       startino;
 
+       /* What was the last inode number we saw when iterating the inobt? */
+       xfs_ino_t                       lastino;
+
        /* Array of inobt records we cache. */
        struct xfs_inobt_rec_incore     *recs;
 
@@ -301,6 +304,9 @@ xfs_iwalk_ag_start(
        if (XFS_IS_CORRUPT(mp, *has_more != 1))
                return -EFSCORRUPTED;
 
+       iwag->lastino = XFS_AGINO_TO_INO(mp, agno,
+                               irec->ir_startino + XFS_INODES_PER_CHUNK - 1);
+
        /*
         * If the LE lookup yielded an inobt record before the cursor position,
         * skip it and see if there's another one after it.
@@ -347,15 +353,17 @@ xfs_iwalk_run_callbacks(
        struct xfs_mount                *mp = iwag->mp;
        struct xfs_trans                *tp = iwag->tp;
        struct xfs_inobt_rec_incore     *irec;
-       xfs_agino_t                     restart;
+       xfs_agino_t                     next_agino;
        int                             error;
 
+       next_agino = XFS_INO_TO_AGINO(mp, iwag->lastino) + 1;
+
        ASSERT(iwag->nr_recs > 0);
 
        /* Delete cursor but remember the last record we cached... */
        xfs_iwalk_del_inobt(tp, curpp, agi_bpp, 0);
        irec = &iwag->recs[iwag->nr_recs - 1];
-       restart = irec->ir_startino + XFS_INODES_PER_CHUNK - 1;
+       ASSERT(next_agino == irec->ir_startino + XFS_INODES_PER_CHUNK);
 
        error = xfs_iwalk_ag_recs(iwag);
        if (error)
@@ -372,7 +380,7 @@ xfs_iwalk_run_callbacks(
        if (error)
                return error;
 
-       return xfs_inobt_lookup(*curpp, restart, XFS_LOOKUP_GE, has_more);
+       return xfs_inobt_lookup(*curpp, next_agino, XFS_LOOKUP_GE, has_more);
 }
 
 /* Walk all inodes in a single AG, from @iwag->startino to the end of the AG. */
@@ -396,6 +404,7 @@ xfs_iwalk_ag(
 
        while (!error && has_more) {
                struct xfs_inobt_rec_incore     *irec;
+               xfs_ino_t                       rec_fsino;
 
                cond_resched();
                if (xfs_pwork_want_abort(&iwag->pwork))
@@ -407,6 +416,15 @@ xfs_iwalk_ag(
                if (error || !has_more)
                        break;
 
+               /* Make sure that we always move forward. */
+               rec_fsino = XFS_AGINO_TO_INO(mp, agno, irec->ir_startino);
+               if (iwag->lastino != NULLFSINO &&
+                   XFS_IS_CORRUPT(mp, iwag->lastino >= rec_fsino)) {
+                       error = -EFSCORRUPTED;
+                       goto out;
+               }
+               iwag->lastino = rec_fsino + XFS_INODES_PER_CHUNK - 1;
+
                /* No allocated inodes in this chunk; skip it. */
                if (iwag->skip_empty && irec->ir_freecount == irec->ir_count) {
                        error = xfs_btree_increment(cur, 0, &has_more);
@@ -535,6 +553,7 @@ xfs_iwalk(
                .trim_start     = 1,
                .skip_empty     = 1,
                .pwork          = XFS_PWORK_SINGLE_THREADED,
+               .lastino        = NULLFSINO,
        };
        xfs_agnumber_t          agno = XFS_INO_TO_AGNO(mp, startino);
        int                     error;
@@ -623,6 +642,7 @@ xfs_iwalk_threaded(
                iwag->data = data;
                iwag->startino = startino;
                iwag->sz_recs = xfs_iwalk_prefetch(inode_records);
+               iwag->lastino = NULLFSINO;
                xfs_pwork_queue(&pctl, &iwag->pwork);
                startino = XFS_AGINO_TO_INO(mp, agno + 1, 0);
                if (flags & XFS_INOBT_WALK_SAME_AG)
@@ -696,6 +716,7 @@ xfs_inobt_walk(
                .startino       = startino,
                .sz_recs        = xfs_inobt_walk_prefetch(inobt_records),
                .pwork          = XFS_PWORK_SINGLE_THREADED,
+               .lastino        = NULLFSINO,
        };
        xfs_agnumber_t          agno = XFS_INO_TO_AGNO(mp, startino);
        int                     error;
index 150ee5c..7110507 100644 (file)
@@ -194,20 +194,25 @@ xfs_initialize_perag(
                }
 
                pag = kmem_zalloc(sizeof(*pag), KM_MAYFAIL);
-               if (!pag)
+               if (!pag) {
+                       error = -ENOMEM;
                        goto out_unwind_new_pags;
+               }
                pag->pag_agno = index;
                pag->pag_mount = mp;
                spin_lock_init(&pag->pag_ici_lock);
                INIT_RADIX_TREE(&pag->pag_ici_root, GFP_ATOMIC);
-               if (xfs_buf_hash_init(pag))
+
+               error = xfs_buf_hash_init(pag);
+               if (error)
                        goto out_free_pag;
                init_waitqueue_head(&pag->pagb_wait);
                spin_lock_init(&pag->pagb_lock);
                pag->pagb_count = 0;
                pag->pagb_tree = RB_ROOT;
 
-               if (radix_tree_preload(GFP_NOFS))
+               error = radix_tree_preload(GFP_NOFS);
+               if (error)
                        goto out_hash_destroy;
 
                spin_lock(&mp->m_perag_lock);
index b101feb..f3082a9 100644 (file)
@@ -134,7 +134,7 @@ xfs_fs_map_blocks(
                goto out_unlock;
        error = invalidate_inode_pages2(inode->i_mapping);
        if (WARN_ON_ONCE(error))
-               return error;
+               goto out_unlock;
 
        end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + length);
        offset_fsb = XFS_B_TO_FSBT(mp, offset);
index 16098dc..6fa05fb 100644 (file)
@@ -1502,7 +1502,8 @@ xfs_reflink_unshare(
                        &xfs_buffered_write_iomap_ops);
        if (error)
                goto out;
-       error = filemap_write_and_wait(inode->i_mapping);
+
+       error = filemap_write_and_wait_range(inode->i_mapping, offset, len);
        if (error)
                goto out;
 
index 798027b..640f094 100644 (file)
@@ -13,6 +13,7 @@
 
 #ifndef __ASSEMBLY__
 
+#include <linux/compiler.h>
 #include <asm/rwonce.h>
 
 #ifndef nop
index 35e4a53..6432a7f 100644 (file)
@@ -114,21 +114,21 @@ do {                                                                      \
 
 #define __this_cpu_generic_read_nopreempt(pcp)                         \
 ({                                                                     \
-       typeof(pcp) __ret;                                              \
+       typeof(pcp) ___ret;                                             \
        preempt_disable_notrace();                                      \
-       __ret = READ_ONCE(*raw_cpu_ptr(&(pcp)));                        \
+       ___ret = READ_ONCE(*raw_cpu_ptr(&(pcp)));                       \
        preempt_enable_notrace();                                       \
-       __ret;                                                          \
+       ___ret;                                                         \
 })
 
 #define __this_cpu_generic_read_noirq(pcp)                             \
 ({                                                                     \
-       typeof(pcp) __ret;                                              \
-       unsigned long __flags;                                          \
-       raw_local_irq_save(__flags);                                    \
-       __ret = raw_cpu_generic_read(pcp);                              \
-       raw_local_irq_restore(__flags);                                 \
-       __ret;                                                          \
+       typeof(pcp) ___ret;                                             \
+       unsigned long ___flags;                                         \
+       raw_local_irq_save(___flags);                                   \
+       ___ret = raw_cpu_generic_read(pcp);                             \
+       raw_local_irq_restore(___flags);                                \
+       ___ret;                                                         \
 })
 
 #define this_cpu_generic_read(pcp)                                     \
index 9197da7..df60be7 100644 (file)
@@ -252,13 +252,14 @@ static inline int kunit_run_all_tests(void)
 }
 #endif /* IS_BUILTIN(CONFIG_KUNIT) */
 
+#ifdef MODULE
 /**
- * kunit_test_suites() - used to register one or more &struct kunit_suite
- *                      with KUnit.
+ * kunit_test_suites_for_module() - used to register one or more
+ *                      &struct kunit_suite with KUnit.
  *
- * @suites_list...: a statically allocated list of &struct kunit_suite.
+ * @__suites: a statically allocated list of &struct kunit_suite.
  *
- * Registers @suites_list with the test framework. See &struct kunit_suite for
+ * Registers @__suites with the test framework. See &struct kunit_suite for
  * more information.
  *
  * If a test suite is built-in, module_init() gets translated into
@@ -267,7 +268,6 @@ static inline int kunit_run_all_tests(void)
  * module_{init|exit} functions for the builtin case when registering
  * suites via kunit_test_suites() below.
  */
-#ifdef MODULE
 #define kunit_test_suites_for_module(__suites)                         \
        static int __init kunit_test_suites_init(void)                  \
        {                                                               \
@@ -294,7 +294,7 @@ static inline int kunit_run_all_tests(void)
  * kunit_test_suites() - used to register one or more &struct kunit_suite
  *                      with KUnit.
  *
- * @suites: a statically allocated list of &struct kunit_suite.
+ * @__suites: a statically allocated list of &struct kunit_suite.
  *
  * Registers @suites with the test framework. See &struct kunit_suite for
  * more information.
@@ -308,10 +308,10 @@ static inline int kunit_run_all_tests(void)
  * module.
  *
  */
-#define kunit_test_suites(...)                                         \
+#define kunit_test_suites(__suites...)                                         \
        __kunit_test_suites(__UNIQUE_ID(array),                         \
                            __UNIQUE_ID(suites),                        \
-                           __VA_ARGS__)
+                           ##__suites)
 
 #define kunit_test_suite(suite)        kunit_test_suites(&suite)
 
@@ -1105,7 +1105,7 @@ do {                                                                             \
        KUNIT_ASSERTION(test,                                                  \
                        strcmp(__left, __right) op 0,                          \
                        kunit_binary_str_assert,                               \
-                       KUNIT_INIT_BINARY_ASSERT_STRUCT(test,                  \
+                       KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(test,              \
                                                        assert_type,           \
                                                        #op,                   \
                                                        #left,                 \
index b23eeca..794b2a3 100644 (file)
@@ -235,6 +235,8 @@ enum hctx_type {
  * @flags:        Zero or more BLK_MQ_F_* flags.
  * @driver_data:   Pointer to data owned by the block driver that created this
  *                tag set.
+ * @active_queues_shared_sbitmap:
+ *                number of active request queues per tag set.
  * @__bitmap_tags: A shared tags sbitmap, used over all hctx's
  * @__breserved_tags:
  *                A shared reserved tags sbitmap, used over all hctx's
index 900b9f4..fc61cf4 100644 (file)
@@ -61,21 +61,17 @@ static inline void can_skb_set_owner(struct sk_buff *skb, struct sock *sk)
  */
 static inline struct sk_buff *can_create_echo_skb(struct sk_buff *skb)
 {
-       if (skb_shared(skb)) {
-               struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC);
+       struct sk_buff *nskb;
 
-               if (likely(nskb)) {
-                       can_skb_set_owner(nskb, skb->sk);
-                       consume_skb(skb);
-                       return nskb;
-               } else {
-                       kfree_skb(skb);
-                       return NULL;
-               }
+       nskb = skb_clone(skb, GFP_ATOMIC);
+       if (unlikely(!nskb)) {
+               kfree_skb(skb);
+               return NULL;
        }
 
-       /* we can assume to have an unshared skb with proper owner */
-       return skb;
+       can_skb_set_owner(nskb, skb->sk);
+       consume_skb(skb);
+       return nskb;
 }
 
 #endif /* !_CAN_SKB_H */
index 230604e..98cff1b 100644 (file)
@@ -8,8 +8,10 @@
                     + __clang_patchlevel__)
 
 #if CLANG_VERSION < 100001
+#ifndef __BPF_TRACING__
 # error Sorry, your version of Clang is too old - please use 10.0.1 or newer.
 #endif
+#endif
 
 /* Compiler specific definitions for Clang compiler */
 
 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
 #endif
 
-/* The following are for compatibility with GCC, from compiler-gcc.h,
- * and may be redefined here because they should not be shared with other
- * compilers, like ICC.
- */
-#define barrier() __asm__ __volatile__("" : : : "memory")
-
 #if __has_feature(shadow_call_stack)
 # define __noscs       __attribute__((__no_sanitize__("shadow-call-stack")))
 #endif
index d1e3c68..74c6c04 100644 (file)
 # error Sorry, your version of GCC is too old - please use 4.9 or newer.
 #endif
 
-/* Optimization barrier */
-
-/* The "volatile" is due to gcc bugs */
-#define barrier() __asm__ __volatile__("": : :"memory")
-/*
- * This version is i.e. to prevent dead stores elimination on @ptr
- * where gcc and llvm may behave differently when otherwise using
- * normal barrier(): while gcc behavior gets along with a normal
- * barrier(), llvm needs an explicit input variable to be assumed
- * clobbered. The issue is as follows: while the inline asm might
- * access any memory it wants, the compiler could have fit all of
- * @ptr into memory registers instead, and since @ptr never escaped
- * from that, it proved that the inline asm wasn't touching any of
- * it. This version works well with both compilers, i.e. we're telling
- * the compiler that the inline asm absolutely may see the contents
- * of @ptr. See also: https://llvm.org/bugs/show_bug.cgi?id=15495
- */
-#define barrier_data(ptr) __asm__ __volatile__("": :"r"(ptr) :"memory")
-
 /*
  * This macro obfuscates arithmetic on a variable address so that gcc
  * shouldn't recognize the original var, and make assumptions about it.
 #else
 #define __diag_GCC_8(s)
 #endif
-
-#define __no_fgcse __attribute__((optimize("-fno-gcse")))
index e512f55..b8fe0c2 100644 (file)
@@ -80,11 +80,25 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
 
 /* Optimization barrier */
 #ifndef barrier
-# define barrier() __memory_barrier()
+/* The "volatile" is due to gcc bugs */
+# define barrier() __asm__ __volatile__("": : :"memory")
 #endif
 
 #ifndef barrier_data
-# define barrier_data(ptr) barrier()
+/*
+ * This version is i.e. to prevent dead stores elimination on @ptr
+ * where gcc and llvm may behave differently when otherwise using
+ * normal barrier(): while gcc behavior gets along with a normal
+ * barrier(), llvm needs an explicit input variable to be assumed
+ * clobbered. The issue is as follows: while the inline asm might
+ * access any memory it wants, the compiler could have fit all of
+ * @ptr into memory registers instead, and since @ptr never escaped
+ * from that, it proved that the inline asm wasn't touching any of
+ * it. This version works well with both compilers, i.e. we're telling
+ * the compiler that the inline asm absolutely may see the contents
+ * of @ptr. See also: https://llvm.org/bugs/show_bug.cgi?id=15495
+ */
+# define barrier_data(ptr) __asm__ __volatile__("": :"r"(ptr) :"memory")
 #endif
 
 /* workaround for GCC PR82365 if needed */
index 6e390d5..ac3fa37 100644 (file)
@@ -247,10 +247,6 @@ struct ftrace_likely_data {
 #define asm_inline asm
 #endif
 
-#ifndef __no_fgcse
-# define __no_fgcse
-#endif
-
 /* Are two types/vars the same type (ignoring qualifiers)? */
 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
 
index 1eaa04f..acbad3b 100644 (file)
@@ -109,6 +109,12 @@ struct cpufreq_policy {
        bool                    fast_switch_possible;
        bool                    fast_switch_enabled;
 
+       /*
+        * Set if the CPUFREQ_GOV_STRICT_TARGET flag is set for the current
+        * governor.
+        */
+       bool                    strict_target;
+
        /*
         * Preferred average time interval between consecutive invocations of
         * the driver to set the frequency for this policy.  To be set by the
@@ -570,12 +576,20 @@ struct cpufreq_governor {
                                         char *buf);
        int     (*store_setspeed)       (struct cpufreq_policy *policy,
                                         unsigned int freq);
-       /* For governors which change frequency dynamically by themselves */
-       bool                    dynamic_switching;
        struct list_head        governor_list;
        struct module           *owner;
+       u8                      flags;
 };
 
+/* Governor flags */
+
+/* For governors which change frequency dynamically by themselves */
+#define CPUFREQ_GOV_DYNAMIC_SWITCHING  BIT(0)
+
+/* For governors wanting the target frequency to be set exactly */
+#define CPUFREQ_GOV_STRICT_TARGET      BIT(1)
+
+
 /* Pass a target to the cpufreq driver */
 unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy,
                                        unsigned int target_freq);
index 72d62cb..1b62397 100644 (file)
@@ -558,21 +558,21 @@ struct sk_filter {
 DECLARE_STATIC_KEY_FALSE(bpf_stats_enabled_key);
 
 #define __BPF_PROG_RUN(prog, ctx, dfunc)       ({                      \
-       u32 ret;                                                        \
+       u32 __ret;                                                      \
        cant_migrate();                                                 \
        if (static_branch_unlikely(&bpf_stats_enabled_key)) {           \
-               struct bpf_prog_stats *stats;                           \
-               u64 start = sched_clock();                              \
-               ret = dfunc(ctx, (prog)->insnsi, (prog)->bpf_func);     \
-               stats = this_cpu_ptr(prog->aux->stats);                 \
-               u64_stats_update_begin(&stats->syncp);                  \
-               stats->cnt++;                                           \
-               stats->nsecs += sched_clock() - start;                  \
-               u64_stats_update_end(&stats->syncp);                    \
+               struct bpf_prog_stats *__stats;                         \
+               u64 __start = sched_clock();                            \
+               __ret = dfunc(ctx, (prog)->insnsi, (prog)->bpf_func);   \
+               __stats = this_cpu_ptr(prog->aux->stats);               \
+               u64_stats_update_begin(&__stats->syncp);                \
+               __stats->cnt++;                                         \
+               __stats->nsecs += sched_clock() - __start;              \
+               u64_stats_update_end(&__stats->syncp);                  \
        } else {                                                        \
-               ret = dfunc(ctx, (prog)->insnsi, (prog)->bpf_func);     \
+               __ret = dfunc(ctx, (prog)->insnsi, (prog)->bpf_func);   \
        }                                                               \
-       ret; })
+       __ret; })
 
 #define BPF_PROG_RUN(prog, ctx)                                                \
        __BPF_PROG_RUN(prog, ctx, bpf_dispatcher_nop_func)
index 21cc971..8667d0c 100644 (file)
@@ -1580,8 +1580,24 @@ extern struct timespec64 current_time(struct inode *inode);
  * Snapshotting support.
  */
 
-void __sb_end_write(struct super_block *sb, int level);
-int __sb_start_write(struct super_block *sb, int level, bool wait);
+/*
+ * These are internal functions, please use sb_start_{write,pagefault,intwrite}
+ * instead.
+ */
+static inline void __sb_end_write(struct super_block *sb, int level)
+{
+       percpu_up_read(sb->s_writers.rw_sem + level-1);
+}
+
+static inline void __sb_start_write(struct super_block *sb, int level)
+{
+       percpu_down_read(sb->s_writers.rw_sem + level - 1);
+}
+
+static inline bool __sb_start_write_trylock(struct super_block *sb, int level)
+{
+       return percpu_down_read_trylock(sb->s_writers.rw_sem + level - 1);
+}
 
 #define __sb_writers_acquired(sb, lev) \
        percpu_rwsem_acquire(&(sb)->s_writers.rw_sem[(lev)-1], 1, _THIS_IP_)
@@ -1645,12 +1661,12 @@ static inline void sb_end_intwrite(struct super_block *sb)
  */
 static inline void sb_start_write(struct super_block *sb)
 {
-       __sb_start_write(sb, SB_FREEZE_WRITE, true);
+       __sb_start_write(sb, SB_FREEZE_WRITE);
 }
 
-static inline int sb_start_write_trylock(struct super_block *sb)
+static inline bool sb_start_write_trylock(struct super_block *sb)
 {
-       return __sb_start_write(sb, SB_FREEZE_WRITE, false);
+       return __sb_start_write_trylock(sb, SB_FREEZE_WRITE);
 }
 
 /**
@@ -1674,7 +1690,7 @@ static inline int sb_start_write_trylock(struct super_block *sb)
  */
 static inline void sb_start_pagefault(struct super_block *sb)
 {
-       __sb_start_write(sb, SB_FREEZE_PAGEFAULT, true);
+       __sb_start_write(sb, SB_FREEZE_PAGEFAULT);
 }
 
 /*
@@ -1692,12 +1708,12 @@ static inline void sb_start_pagefault(struct super_block *sb)
  */
 static inline void sb_start_intwrite(struct super_block *sb)
 {
-       __sb_start_write(sb, SB_FREEZE_FS, true);
+       __sb_start_write(sb, SB_FREEZE_FS);
 }
 
-static inline int sb_start_intwrite_trylock(struct super_block *sb)
+static inline bool sb_start_intwrite_trylock(struct super_block *sb)
 {
-       return __sb_start_write(sb, SB_FREEZE_FS, false);
+       return __sb_start_write_trylock(sb, SB_FREEZE_FS);
 }
 
 
@@ -2756,14 +2772,14 @@ static inline void file_start_write(struct file *file)
 {
        if (!S_ISREG(file_inode(file)->i_mode))
                return;
-       __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, true);
+       sb_start_write(file_inode(file)->i_sb);
 }
 
 static inline bool file_start_write_trylock(struct file *file)
 {
        if (!S_ISREG(file_inode(file)->i_mode))
                return true;
-       return __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, false);
+       return sb_start_write_trylock(file_inode(file)->i_sb);
 }
 
 static inline void file_end_write(struct file *file)
index 38f23d7..03da3f6 100644 (file)
@@ -315,7 +315,7 @@ static inline int get_disk_ro(struct gendisk *disk)
 extern void disk_block_events(struct gendisk *disk);
 extern void disk_unblock_events(struct gendisk *disk);
 extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
-void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
+bool set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
                bool update_bdev);
 
 /* drivers/char/random.c */
index fbf5b3e..d956987 100644 (file)
@@ -798,7 +798,6 @@ extern int iommu_calculate_agaw(struct intel_iommu *iommu);
 extern int iommu_calculate_max_sagaw(struct intel_iommu *iommu);
 extern int dmar_disabled;
 extern int intel_iommu_enabled;
-extern int intel_iommu_tboot_noforce;
 extern int intel_iommu_gfx_mapped;
 #else
 static inline int iommu_calculate_agaw(struct intel_iommu *iommu)
index 868364c..35b2d84 100644 (file)
@@ -30,7 +30,8 @@ struct io_uring_task {
        struct percpu_counter   inflight;
        struct io_identity      __identity;
        struct io_identity      *identity;
-       bool                    in_idle;
+       atomic_t                in_idle;
+       bool                    sqpoll;
 };
 
 #if defined(CONFIG_IO_URING)
index 172b339..5bd3cac 100644 (file)
@@ -221,7 +221,7 @@ struct iomap_writeback_ops {
         * Optional, allows the file system to discard state on a page where
         * we failed to submit any I/O.
         */
-       void (*discard_page)(struct page *page);
+       void (*discard_page)(struct page *page, loff_t fileoff);
 };
 
 struct iomap_writepage_ctx {
index 1d5566a..578ff19 100644 (file)
@@ -68,6 +68,7 @@ extern void *jbd2_alloc(size_t size, gfp_t flags);
 extern void jbd2_free(void *ptr, size_t size);
 
 #define JBD2_MIN_JOURNAL_BLOCKS 1024
+#define JBD2_MIN_FC_BLOCKS     256
 
 #ifdef __KERNEL__
 
@@ -400,7 +401,7 @@ static inline void jbd_unlock_bh_journal_head(struct buffer_head *bh)
 #define JI_WAIT_DATA (1 << __JI_WAIT_DATA)
 
 /**
- * struct jbd_inode - The jbd_inode type is the structure linking inodes in
+ * struct jbd2_inode - The jbd_inode type is the structure linking inodes in
  * ordered mode present in a transaction so that we can sync them during commit.
  */
 struct jbd2_inode {
@@ -944,8 +945,9 @@ struct journal_s
        /**
         * @j_fc_off:
         *
-        * Number of fast commit blocks currently allocated.
-        * [j_state_lock].
+        * Number of fast commit blocks currently allocated. Accessed only
+        * during fast commit. Currently only process can do fast commit, so
+        * this field is not protected by any lock.
         */
        unsigned long           j_fc_off;
 
@@ -988,9 +990,9 @@ struct journal_s
        struct block_device     *j_fs_dev;
 
        /**
-        * @j_maxlen: Total maximum capacity of the journal region on disk.
+        * @j_total_len: Total maximum capacity of the journal region on disk.
         */
-       unsigned int            j_maxlen;
+       unsigned int            j_total_len;
 
        /**
         * @j_reserved_credits:
@@ -1108,8 +1110,9 @@ struct journal_s
        struct buffer_head      **j_wbuf;
 
        /**
-        * @j_fc_wbuf: Array of fast commit bhs for
-        * jbd2_journal_commit_transaction.
+        * @j_fc_wbuf: Array of fast commit bhs for fast commit. Accessed only
+        * during a fast commit. Currently only process can do fast commit, so
+        * this field is not protected by any lock.
         */
        struct buffer_head      **j_fc_wbuf;
 
@@ -1614,16 +1617,20 @@ extern void __jbd2_journal_drop_transaction(journal_t *, transaction_t *);
 extern int jbd2_cleanup_journal_tail(journal_t *);
 
 /* Fast commit related APIs */
-int jbd2_fc_init(journal_t *journal, int num_fc_blks);
 int jbd2_fc_begin_commit(journal_t *journal, tid_t tid);
 int jbd2_fc_end_commit(journal_t *journal);
-int jbd2_fc_end_commit_fallback(journal_t *journal, tid_t tid);
+int jbd2_fc_end_commit_fallback(journal_t *journal);
 int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out);
 int jbd2_submit_inode_data(struct jbd2_inode *jinode);
 int jbd2_wait_inode_data(journal_t *journal, struct jbd2_inode *jinode);
 int jbd2_fc_wait_bufs(journal_t *journal, int num_blks);
 int jbd2_fc_release_bufs(journal_t *journal);
 
+static inline int jbd2_journal_get_max_txn_bufs(journal_t *journal)
+{
+       return (journal->j_total_len - journal->j_fc_wbufsize) / 4;
+}
+
 /*
  * is_journal_abort
  *
index e391e3c..a80c59a 100644 (file)
@@ -900,12 +900,19 @@ static inline void count_memcg_event_mm(struct mm_struct *mm,
 static inline void memcg_memory_event(struct mem_cgroup *memcg,
                                      enum memcg_memory_event event)
 {
+       bool swap_event = event == MEMCG_SWAP_HIGH || event == MEMCG_SWAP_MAX ||
+                         event == MEMCG_SWAP_FAIL;
+
        atomic_long_inc(&memcg->memory_events_local[event]);
-       cgroup_file_notify(&memcg->events_local_file);
+       if (!swap_event)
+               cgroup_file_notify(&memcg->events_local_file);
 
        do {
                atomic_long_inc(&memcg->memory_events[event]);
-               cgroup_file_notify(&memcg->events_file);
+               if (swap_event)
+                       cgroup_file_notify(&memcg->swap_events_file);
+               else
+                       cgroup_file_notify(&memcg->events_file);
 
                if (!cgroup_subsys_on_dfl(memory_cgrp_subsys))
                        break;
index d65c6fd..551093b 100644 (file)
@@ -281,20 +281,6 @@ static inline bool movable_node_is_enabled(void)
 }
 #endif /* ! CONFIG_MEMORY_HOTPLUG */
 
-#ifdef CONFIG_NUMA
-extern int memory_add_physaddr_to_nid(u64 start);
-extern int phys_to_target_node(u64 start);
-#else
-static inline int memory_add_physaddr_to_nid(u64 start)
-{
-       return 0;
-}
-static inline int phys_to_target_node(u64 start)
-{
-       return 0;
-}
-#endif
-
 #if defined(CONFIG_MEMORY_HOTPLUG) || defined(CONFIG_DEFERRED_STRUCT_PAGE_INIT)
 /*
  * pgdat resizing functions
index ef360fe..db6ae4d 100644 (file)
@@ -2759,6 +2759,15 @@ static inline vm_fault_t vmf_insert_page(struct vm_area_struct *vma,
        return VM_FAULT_NOPAGE;
 }
 
+#ifndef io_remap_pfn_range
+static inline int io_remap_pfn_range(struct vm_area_struct *vma,
+                                    unsigned long addr, unsigned long pfn,
+                                    unsigned long size, pgprot_t prot)
+{
+       return remap_pfn_range(vma, addr, pfn, size, pgprot_decrypted(prot));
+}
+#endif
+
 static inline vm_fault_t vmf_error(int err)
 {
        if (err == -ENOMEM)
index 89016d0..f6267e2 100644 (file)
@@ -24,6 +24,12 @@ struct nfnl_callback {
        const u_int16_t attr_count;             /* number of nlattr's */
 };
 
+enum nfnl_abort_action {
+       NFNL_ABORT_NONE         = 0,
+       NFNL_ABORT_AUTOLOAD,
+       NFNL_ABORT_VALIDATE,
+};
+
 struct nfnetlink_subsystem {
        const char *name;
        __u8 subsys_id;                 /* nfnetlink subsystem ID */
@@ -31,7 +37,8 @@ struct nfnetlink_subsystem {
        const struct nfnl_callback *cb; /* callback for individual types */
        struct module *owner;
        int (*commit)(struct net *net, struct sk_buff *skb);
-       int (*abort)(struct net *net, struct sk_buff *skb, bool autoload);
+       int (*abort)(struct net *net, struct sk_buff *skb,
+                    enum nfnl_abort_action action);
        void (*cleanup)(struct net *net);
        bool (*valid_genid)(struct net *net, u32 genid);
 };
index 082e2c4..5b70ca8 100644 (file)
@@ -16,7 +16,7 @@ struct ip_rt_info {
        u_int32_t mark;
 };
 
-int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned addr_type);
+int ip_route_me_harder(struct net *net, struct sock *sk, struct sk_buff *skb, unsigned addr_type);
 
 struct nf_queue_entry;
 
index 9b67394..48314ad 100644 (file)
@@ -42,7 +42,7 @@ struct nf_ipv6_ops {
 #if IS_MODULE(CONFIG_IPV6)
        int (*chk_addr)(struct net *net, const struct in6_addr *addr,
                        const struct net_device *dev, int strict);
-       int (*route_me_harder)(struct net *net, struct sk_buff *skb);
+       int (*route_me_harder)(struct net *net, struct sock *sk, struct sk_buff *skb);
        int (*dev_get_saddr)(struct net *net, const struct net_device *dev,
                       const struct in6_addr *daddr, unsigned int srcprefs,
                       struct in6_addr *saddr);
@@ -143,9 +143,9 @@ static inline int nf_br_ip6_fragment(struct net *net, struct sock *sk,
 #endif
 }
 
-int ip6_route_me_harder(struct net *net, struct sk_buff *skb);
+int ip6_route_me_harder(struct net *net, struct sock *sk, struct sk_buff *skb);
 
-static inline int nf_ip6_route_me_harder(struct net *net, struct sk_buff *skb)
+static inline int nf_ip6_route_me_harder(struct net *net, struct sock *sk, struct sk_buff *skb)
 {
 #if IS_MODULE(CONFIG_IPV6)
        const struct nf_ipv6_ops *v6_ops = nf_get_ipv6_ops();
@@ -153,9 +153,9 @@ static inline int nf_ip6_route_me_harder(struct net *net, struct sk_buff *skb)
        if (!v6_ops)
                return -EHOSTUNREACH;
 
-       return v6_ops->route_me_harder(net, skb);
+       return v6_ops->route_me_harder(net, sk, skb);
 #elif IS_BUILTIN(CONFIG_IPV6)
-       return ip6_route_me_harder(net, skb);
+       return ip6_route_me_harder(net, sk, skb);
 #else
        return -EHOSTUNREACH;
 #endif
index 8cb33cc..cb44cfe 100644 (file)
 #endif
 
 #ifdef CONFIG_NUMA
+#include <linux/printk.h>
+#include <asm/sparsemem.h>
+
 /* Generic implementation available */
 int numa_map_to_online_node(int node);
-#else
+
+#ifndef memory_add_physaddr_to_nid
+static inline int memory_add_physaddr_to_nid(u64 start)
+{
+       pr_info_once("Unknown online node for memory at 0x%llx, assuming node 0\n",
+                       start);
+       return 0;
+}
+#endif
+#ifndef phys_to_target_node
+static inline int phys_to_target_node(u64 start)
+{
+       pr_info_once("Unknown target node for memory at 0x%llx, assuming node 0\n",
+                       start);
+       return 0;
+}
+#endif
+#else /* !CONFIG_NUMA */
 static inline int numa_map_to_online_node(int node)
 {
        return NUMA_NO_NODE;
 }
+static inline int memory_add_physaddr_to_nid(u64 start)
+{
+       return 0;
+}
+static inline int phys_to_target_node(u64 start)
+{
+       return 0;
+}
 #endif
 
 #endif /* _LINUX_NUMA_H */
index c77b7c3..d5570de 100644 (file)
@@ -344,9 +344,9 @@ static inline struct page *find_get_page_flags(struct address_space *mapping,
 /**
  * find_lock_page - locate, pin and lock a pagecache page
  * @mapping: the address_space to search
- * @offset: the page index
+ * @index: the page index
  *
- * Looks up the page cache entry at @mapping & @offset.  If there is a
+ * Looks up the page cache entry at @mapping & @index.  If there is a
  * page cache page, it is returned locked and with an increased
  * refcount.
  *
@@ -363,9 +363,9 @@ static inline struct page *find_lock_page(struct address_space *mapping,
 /**
  * find_lock_head - Locate, pin and lock a pagecache page.
  * @mapping: The address_space to search.
- * @offset: The page index.
+ * @index: The page index.
  *
- * Looks up the page cache entry at @mapping & @offset.  If there is a
+ * Looks up the page cache entry at @mapping & @index.  If there is a
  * page cache page, its head page is returned locked and with an increased
  * refcount.
  *
@@ -906,6 +906,8 @@ static inline unsigned int __readahead_batch(struct readahead_control *rac,
        xas_set(&xas, rac->_index);
        rcu_read_lock();
        xas_for_each(&xas, page, rac->_index + rac->_nr_pages - 1) {
+               if (xas_retry(&xas, page))
+                       continue;
                VM_BUG_ON_PAGE(!PageLocked(page), page);
                VM_BUG_ON_PAGE(PageTail(page), page);
                array[i++] = page;
index 0c19d27..96450f6 100644 (file)
@@ -1022,13 +1022,7 @@ struct perf_sample_data {
        struct perf_callchain_entry     *callchain;
        u64                             aux_size;
 
-       /*
-        * regs_user may point to task_pt_regs or to regs_user_copy, depending
-        * on arch details.
-        */
        struct perf_regs                regs_user;
-       struct pt_regs                  regs_user_copy;
-
        struct perf_regs                regs_intr;
        u64                             stack_user_size;
 
@@ -1400,11 +1394,14 @@ perf_event_addr_filters(struct perf_event *event)
 extern void perf_event_addr_filters_sync(struct perf_event *event);
 
 extern int perf_output_begin(struct perf_output_handle *handle,
+                            struct perf_sample_data *data,
                             struct perf_event *event, unsigned int size);
 extern int perf_output_begin_forward(struct perf_output_handle *handle,
-                                   struct perf_event *event,
-                                   unsigned int size);
+                                    struct perf_sample_data *data,
+                                    struct perf_event *event,
+                                    unsigned int size);
 extern int perf_output_begin_backward(struct perf_output_handle *handle,
+                                     struct perf_sample_data *data,
                                      struct perf_event *event,
                                      unsigned int size);
 
index 2d12e97..f632c57 100644 (file)
@@ -20,8 +20,7 @@ u64 perf_reg_value(struct pt_regs *regs, int idx);
 int perf_reg_validate(u64 mask);
 u64 perf_reg_abi(struct task_struct *task);
 void perf_get_regs_user(struct perf_regs *regs_user,
-                       struct pt_regs *regs,
-                       struct pt_regs *regs_user_copy);
+                       struct pt_regs *regs);
 #else
 
 #define PERF_REG_EXTENDED_MASK 0
@@ -42,8 +41,7 @@ static inline u64 perf_reg_abi(struct task_struct *task)
 }
 
 static inline void perf_get_regs_user(struct perf_regs *regs_user,
-                                     struct pt_regs *regs,
-                                     struct pt_regs *regs_user_copy)
+                                     struct pt_regs *regs)
 {
        regs_user->regs = task_pt_regs(current);
        regs_user->abi = perf_reg_abi(current);
index 38c33ea..71125a4 100644 (file)
@@ -1427,10 +1427,6 @@ typedef unsigned int pgtbl_mod_mask;
 
 #endif /* !__ASSEMBLY__ */
 
-#ifndef io_remap_pfn_range
-#define io_remap_pfn_range remap_pfn_range
-#endif
-
 #ifndef has_transparent_hugepage
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 #define has_transparent_hugepage() 1
index eb3cb1a..56563e5 100644 (file)
@@ -147,16 +147,8 @@ typedef enum {
        PHY_INTERFACE_MODE_MAX,
 } phy_interface_t;
 
-/**
+/*
  * phy_supported_speeds - return all speeds currently supported by a PHY device
- * @phy: The PHY device to return supported speeds of.
- * @speeds: buffer to store supported speeds in.
- * @size: size of speeds buffer.
- *
- * Description: Returns the number of supported speeds, and fills
- * the speeds buffer with the supported speeds. If speeds buffer is
- * too small to contain all currently supported speeds, will return as
- * many speeds as can fit.
  */
 unsigned int phy_supported_speeds(struct phy_device *phy,
                                      unsigned int *speeds,
@@ -1022,14 +1014,9 @@ static inline int __phy_modify_changed(struct phy_device *phydev, u32 regnum,
                                        regnum, mask, set);
 }
 
-/**
+/*
  * phy_read_mmd - Convenience function for reading a register
  * from an MMD on a given PHY.
- * @phydev: The phy_device struct
- * @devad: The MMD to read from
- * @regnum: The register on the MMD to read
- *
- * Same rules as for phy_read();
  */
 int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum);
 
@@ -1064,38 +1051,21 @@ int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum);
        __ret; \
 })
 
-/**
+/*
  * __phy_read_mmd - Convenience function for reading a register
  * from an MMD on a given PHY.
- * @phydev: The phy_device struct
- * @devad: The MMD to read from
- * @regnum: The register on the MMD to read
- *
- * Same rules as for __phy_read();
  */
 int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum);
 
-/**
+/*
  * phy_write_mmd - Convenience function for writing a register
  * on an MMD on a given PHY.
- * @phydev: The phy_device struct
- * @devad: The MMD to write to
- * @regnum: The register on the MMD to read
- * @val: value to write to @regnum
- *
- * Same rules as for phy_write();
  */
 int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val);
 
-/**
+/*
  * __phy_write_mmd - Convenience function for writing a register
  * on an MMD on a given PHY.
- * @phydev: The phy_device struct
- * @devad: The MMD to write to
- * @regnum: The register on the MMD to read
- * @val: value to write to @regnum
- *
- * Same rules as for __phy_write();
  */
 int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val);
 
index 18b02dc..b492ae0 100644 (file)
@@ -54,11 +54,10 @@ extern u64 pm_runtime_autosuspend_expiration(struct device *dev);
 extern void pm_runtime_update_max_time_suspended(struct device *dev,
                                                 s64 delta_ns);
 extern void pm_runtime_set_memalloc_noio(struct device *dev, bool enable);
-extern void pm_runtime_clean_up_links(struct device *dev);
 extern void pm_runtime_get_suppliers(struct device *dev);
 extern void pm_runtime_put_suppliers(struct device *dev);
 extern void pm_runtime_new_link(struct device *dev);
-extern void pm_runtime_drop_link(struct device *dev);
+extern void pm_runtime_drop_link(struct device_link *link);
 
 /**
  * pm_runtime_get_if_in_use - Conditionally bump up runtime PM usage counter.
@@ -276,11 +275,10 @@ static inline u64 pm_runtime_autosuspend_expiration(
                                struct device *dev) { return 0; }
 static inline void pm_runtime_set_memalloc_noio(struct device *dev,
                                                bool enable){}
-static inline void pm_runtime_clean_up_links(struct device *dev) {}
 static inline void pm_runtime_get_suppliers(struct device *dev) {}
 static inline void pm_runtime_put_suppliers(struct device *dev) {}
 static inline void pm_runtime_new_link(struct device *dev) {}
-static inline void pm_runtime_drop_link(struct device *dev) {}
+static inline void pm_runtime_drop_link(struct device_link *link) {}
 
 #endif /* !CONFIG_PM */
 
@@ -388,6 +386,27 @@ static inline int pm_runtime_get_sync(struct device *dev)
        return __pm_runtime_resume(dev, RPM_GET_PUT);
 }
 
+/**
+ * pm_runtime_resume_and_get - Bump up usage counter of a device and resume it.
+ * @dev: Target device.
+ *
+ * Resume @dev synchronously and if that is successful, increment its runtime
+ * PM usage counter. Return 0 if the runtime PM usage counter of @dev has been
+ * incremented or a negative error code otherwise.
+ */
+static inline int pm_runtime_resume_and_get(struct device *dev)
+{
+       int ret;
+
+       ret = __pm_runtime_resume(dev, RPM_GET_PUT);
+       if (ret < 0) {
+               pm_runtime_put_noidle(dev);
+               return ret;
+       }
+
+       return 0;
+}
+
 /**
  * pm_runtime_put - Drop device usage counter and queue up "idle check" if 0.
  * @dev: Target device.
index 7fabb1a..497990c 100644 (file)
@@ -147,24 +147,6 @@ static inline unsigned int refcount_read(const refcount_t *r)
        return atomic_read(&r->refs);
 }
 
-/**
- * refcount_add_not_zero - add a value to a refcount unless it is 0
- * @i: the value to add to the refcount
- * @r: the refcount
- *
- * Will saturate at REFCOUNT_SATURATED and WARN.
- *
- * Provides no memory ordering, it is assumed the caller has guaranteed the
- * object memory to be stable (RCU, etc.). It does provide a control dependency
- * and thereby orders future stores. See the comment on top.
- *
- * Use of this function is not recommended for the normal reference counting
- * use case in which references are taken and released one at a time.  In these
- * cases, refcount_inc(), or one of its variants, should instead be used to
- * increment a reference count.
- *
- * Return: false if the passed refcount is 0, true otherwise
- */
 static inline __must_check bool __refcount_add_not_zero(int i, refcount_t *r, int *oldp)
 {
        int old = refcount_read(r);
@@ -183,17 +165,12 @@ static inline __must_check bool __refcount_add_not_zero(int i, refcount_t *r, in
        return old;
 }
 
-static inline __must_check bool refcount_add_not_zero(int i, refcount_t *r)
-{
-       return __refcount_add_not_zero(i, r, NULL);
-}
-
 /**
- * refcount_add - add a value to a refcount
+ * refcount_add_not_zero - add a value to a refcount unless it is 0
  * @i: the value to add to the refcount
  * @r: the refcount
  *
- * Similar to atomic_add(), but will saturate at REFCOUNT_SATURATED and WARN.
+ * Will saturate at REFCOUNT_SATURATED and WARN.
  *
  * Provides no memory ordering, it is assumed the caller has guaranteed the
  * object memory to be stable (RCU, etc.). It does provide a control dependency
@@ -203,7 +180,14 @@ static inline __must_check bool refcount_add_not_zero(int i, refcount_t *r)
  * use case in which references are taken and released one at a time.  In these
  * cases, refcount_inc(), or one of its variants, should instead be used to
  * increment a reference count.
+ *
+ * Return: false if the passed refcount is 0, true otherwise
  */
+static inline __must_check bool refcount_add_not_zero(int i, refcount_t *r)
+{
+       return __refcount_add_not_zero(i, r, NULL);
+}
+
 static inline void __refcount_add(int i, refcount_t *r, int *oldp)
 {
        int old = atomic_fetch_add_relaxed(i, &r->refs);
@@ -217,11 +201,32 @@ static inline void __refcount_add(int i, refcount_t *r, int *oldp)
                refcount_warn_saturate(r, REFCOUNT_ADD_OVF);
 }
 
+/**
+ * refcount_add - add a value to a refcount
+ * @i: the value to add to the refcount
+ * @r: the refcount
+ *
+ * Similar to atomic_add(), but will saturate at REFCOUNT_SATURATED and WARN.
+ *
+ * Provides no memory ordering, it is assumed the caller has guaranteed the
+ * object memory to be stable (RCU, etc.). It does provide a control dependency
+ * and thereby orders future stores. See the comment on top.
+ *
+ * Use of this function is not recommended for the normal reference counting
+ * use case in which references are taken and released one at a time.  In these
+ * cases, refcount_inc(), or one of its variants, should instead be used to
+ * increment a reference count.
+ */
 static inline void refcount_add(int i, refcount_t *r)
 {
        __refcount_add(i, r, NULL);
 }
 
+static inline __must_check bool __refcount_inc_not_zero(refcount_t *r, int *oldp)
+{
+       return __refcount_add_not_zero(1, r, oldp);
+}
+
 /**
  * refcount_inc_not_zero - increment a refcount unless it is 0
  * @r: the refcount to increment
@@ -235,14 +240,14 @@ static inline void refcount_add(int i, refcount_t *r)
  *
  * Return: true if the increment was successful, false otherwise
  */
-static inline __must_check bool __refcount_inc_not_zero(refcount_t *r, int *oldp)
+static inline __must_check bool refcount_inc_not_zero(refcount_t *r)
 {
-       return __refcount_add_not_zero(1, r, oldp);
+       return __refcount_inc_not_zero(r, NULL);
 }
 
-static inline __must_check bool refcount_inc_not_zero(refcount_t *r)
+static inline void __refcount_inc(refcount_t *r, int *oldp)
 {
-       return __refcount_inc_not_zero(r, NULL);
+       __refcount_add(1, r, oldp);
 }
 
 /**
@@ -257,14 +262,27 @@ static inline __must_check bool refcount_inc_not_zero(refcount_t *r)
  * Will WARN if the refcount is 0, as this represents a possible use-after-free
  * condition.
  */
-static inline void __refcount_inc(refcount_t *r, int *oldp)
+static inline void refcount_inc(refcount_t *r)
 {
-       __refcount_add(1, r, oldp);
+       __refcount_inc(r, NULL);
 }
 
-static inline void refcount_inc(refcount_t *r)
+static inline __must_check bool __refcount_sub_and_test(int i, refcount_t *r, int *oldp)
 {
-       __refcount_inc(r, NULL);
+       int old = atomic_fetch_sub_release(i, &r->refs);
+
+       if (oldp)
+               *oldp = old;
+
+       if (old == i) {
+               smp_acquire__after_ctrl_dep();
+               return true;
+       }
+
+       if (unlikely(old < 0 || old - i < 0))
+               refcount_warn_saturate(r, REFCOUNT_SUB_UAF);
+
+       return false;
 }
 
 /**
@@ -287,27 +305,14 @@ static inline void refcount_inc(refcount_t *r)
  *
  * Return: true if the resulting refcount is 0, false otherwise
  */
-static inline __must_check bool __refcount_sub_and_test(int i, refcount_t *r, int *oldp)
+static inline __must_check bool refcount_sub_and_test(int i, refcount_t *r)
 {
-       int old = atomic_fetch_sub_release(i, &r->refs);
-
-       if (oldp)
-               *oldp = old;
-
-       if (old == i) {
-               smp_acquire__after_ctrl_dep();
-               return true;
-       }
-
-       if (unlikely(old < 0 || old - i < 0))
-               refcount_warn_saturate(r, REFCOUNT_SUB_UAF);
-
-       return false;
+       return __refcount_sub_and_test(i, r, NULL);
 }
 
-static inline __must_check bool refcount_sub_and_test(int i, refcount_t *r)
+static inline __must_check bool __refcount_dec_and_test(refcount_t *r, int *oldp)
 {
-       return __refcount_sub_and_test(i, r, NULL);
+       return __refcount_sub_and_test(1, r, oldp);
 }
 
 /**
@@ -323,26 +328,11 @@ static inline __must_check bool refcount_sub_and_test(int i, refcount_t *r)
  *
  * Return: true if the resulting refcount is 0, false otherwise
  */
-static inline __must_check bool __refcount_dec_and_test(refcount_t *r, int *oldp)
-{
-       return __refcount_sub_and_test(1, r, oldp);
-}
-
 static inline __must_check bool refcount_dec_and_test(refcount_t *r)
 {
        return __refcount_dec_and_test(r, NULL);
 }
 
-/**
- * refcount_dec - decrement a refcount
- * @r: the refcount
- *
- * Similar to atomic_dec(), it will WARN on underflow and fail to decrement
- * when saturated at REFCOUNT_SATURATED.
- *
- * Provides release memory ordering, such that prior loads and stores are done
- * before.
- */
 static inline void __refcount_dec(refcount_t *r, int *oldp)
 {
        int old = atomic_fetch_sub_release(1, &r->refs);
@@ -354,6 +344,16 @@ static inline void __refcount_dec(refcount_t *r, int *oldp)
                refcount_warn_saturate(r, REFCOUNT_DEC_LEAK);
 }
 
+/**
+ * refcount_dec - decrement a refcount
+ * @r: the refcount
+ *
+ * Similar to atomic_dec(), it will WARN on underflow and fail to decrement
+ * when saturated at REFCOUNT_SATURATED.
+ *
+ * Provides release memory ordering, such that prior loads and stores are done
+ * before.
+ */
 static inline void refcount_dec(refcount_t *r)
 {
        __refcount_dec(r, NULL);
index 063cd12..76cd21f 100644 (file)
@@ -552,7 +552,6 @@ struct sched_dl_entity {
         * overruns.
         */
        unsigned int                    dl_throttled      : 1;
-       unsigned int                    dl_boosted        : 1;
        unsigned int                    dl_yielded        : 1;
        unsigned int                    dl_non_contending : 1;
        unsigned int                    dl_overrun        : 1;
@@ -571,6 +570,15 @@ struct sched_dl_entity {
         * time.
         */
        struct hrtimer inactive_timer;
+
+#ifdef CONFIG_RT_MUTEXES
+       /*
+        * Priority Inheritance. When a DEADLINE scheduling entity is boosted
+        * pi_se points to the donor, otherwise points to the dl_se it belongs
+        * to (the original one/itself).
+        */
+       struct sched_dl_entity *pi_se;
+#endif
 };
 
 #ifdef CONFIG_UCLAMP_TASK
@@ -770,7 +778,6 @@ struct task_struct {
        unsigned                        sched_reset_on_fork:1;
        unsigned                        sched_contributes_to_load:1;
        unsigned                        sched_migrated:1;
-       unsigned                        sched_remote_wakeup:1;
 #ifdef CONFIG_PSI
        unsigned                        sched_psi_wake_requeue:1;
 #endif
@@ -780,6 +787,21 @@ struct task_struct {
 
        /* Unserialized, strictly 'current' */
 
+       /*
+        * This field must not be in the scheduler word above due to wakelist
+        * queueing no longer being serialized by p->on_cpu. However:
+        *
+        * p->XXX = X;                  ttwu()
+        * schedule()                     if (p->on_rq && ..) // false
+        *   smp_mb__after_spinlock();    if (smp_load_acquire(&p->on_cpu) && //true
+        *   deactivate_task()                ttwu_queue_wakelist())
+        *     p->on_rq = 0;                    p->sched_remote_wakeup = Y;
+        *
+        * guarantees all stores of 'current' are visible before
+        * ->sched_remote_wakeup gets used, so it can be in this word.
+        */
+       unsigned                        sched_remote_wakeup:1;
+
        /* Bit to tell LSMs we're in execve(): */
        unsigned                        in_execve:1;
        unsigned                        in_iowait:1;
index 813614d..b83b3ae 100644 (file)
@@ -107,6 +107,7 @@ void seq_pad(struct seq_file *m, char c);
 char *mangle_path(char *s, const char *p, const char *esc);
 int seq_open(struct file *, const struct seq_operations *);
 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
+ssize_t seq_read_iter(struct kiocb *iocb, struct iov_iter *iter);
 loff_t seq_lseek(struct file *, loff_t, int);
 int seq_release(struct inode *, struct file *);
 int seq_write(struct seq_file *seq, const void *data, size_t len);
index 99380c0..b390fda 100644 (file)
@@ -734,6 +734,25 @@ static inline struct spi_controller *spi_alloc_slave(struct device *host,
        return __spi_alloc_controller(host, size, true);
 }
 
+struct spi_controller *__devm_spi_alloc_controller(struct device *dev,
+                                                  unsigned int size,
+                                                  bool slave);
+
+static inline struct spi_controller *devm_spi_alloc_master(struct device *dev,
+                                                          unsigned int size)
+{
+       return __devm_spi_alloc_controller(dev, size, false);
+}
+
+static inline struct spi_controller *devm_spi_alloc_slave(struct device *dev,
+                                                         unsigned int size)
+{
+       if (!IS_ENABLED(CONFIG_SPI_SLAVE))
+               return NULL;
+
+       return __devm_spi_alloc_controller(dev, size, true);
+}
+
 extern int spi_register_controller(struct spi_controller *ctlr);
 extern int devm_spi_register_controller(struct device *dev,
                                        struct spi_controller *ctlr);
index 513913f..fbdc657 100644 (file)
@@ -5,6 +5,7 @@
 #include <linux/dma-direction.h>
 #include <linux/init.h>
 #include <linux/types.h>
+#include <linux/limits.h>
 
 struct device;
 struct page;
@@ -45,13 +46,9 @@ enum dma_sync_target {
        SYNC_FOR_DEVICE = 1,
 };
 
-extern phys_addr_t swiotlb_tbl_map_single(struct device *hwdev,
-                                         dma_addr_t tbl_dma_addr,
-                                         phys_addr_t phys,
-                                         size_t mapping_size,
-                                         size_t alloc_size,
-                                         enum dma_data_direction dir,
-                                         unsigned long attrs);
+phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
+               size_t mapping_size, size_t alloc_size,
+               enum dma_data_direction dir, unsigned long attrs);
 
 extern void swiotlb_tbl_unmap_single(struct device *hwdev,
                                     phys_addr_t tlb_addr,
index 661edfc..d5ab8d9 100644 (file)
@@ -1444,7 +1444,7 @@ int cfg80211_check_station_change(struct wiphy *wiphy,
                                  enum cfg80211_station_type statype);
 
 /**
- * enum station_info_rate_flags - bitrate info flags
+ * enum rate_info_flags - bitrate info flags
  *
  * Used by the driver to indicate the specific rate transmission
  * type for 802.11n transmissions.
@@ -1517,7 +1517,7 @@ struct rate_info {
 };
 
 /**
- * enum station_info_rate_flags - bitrate info flags
+ * enum bss_param_flags - bitrate info flags
  *
  * Used by the driver to indicate the specific rate transmission
  * type for 802.11n transmissions.
@@ -6467,7 +6467,8 @@ void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid,
                          struct ieee80211_channel *channel, gfp_t gfp);
 
 /**
- * cfg80211_notify_new_candidate - notify cfg80211 of a new mesh peer candidate
+ * cfg80211_notify_new_peer_candidate - notify cfg80211 of a new mesh peer
+ *                                     candidate
  *
  * @dev: network device
  * @macaddr: the MAC address of the new candidate
@@ -7606,7 +7607,7 @@ u32 cfg80211_calculate_bitrate(struct rate_info *rate);
 void cfg80211_unregister_wdev(struct wireless_dev *wdev);
 
 /**
- * struct cfg80211_ft_event - FT Information Elements
+ * struct cfg80211_ft_event_params - FT Information Elements
  * @ies: FT IEs
  * @ies_len: length of the FT IE in bytes
  * @target_ap: target AP's MAC address
index 02ccd32..6162067 100644 (file)
@@ -478,9 +478,11 @@ static inline void ip_tunnel_info_opts_set(struct ip_tunnel_info *info,
                                           const void *from, int len,
                                           __be16 flags)
 {
-       memcpy(ip_tunnel_info_opts(info), from, len);
        info->options_len = len;
-       info->key.tun_flags |= flags;
+       if (len > 0) {
+               memcpy(ip_tunnel_info_opts(info), from, len);
+               info->key.tun_flags |= flags;
+       }
 }
 
 static inline struct ip_tunnel_info *lwt_tun_info(struct lwtunnel_state *lwtstate)
@@ -526,7 +528,6 @@ static inline void ip_tunnel_info_opts_set(struct ip_tunnel_info *info,
                                           __be16 flags)
 {
        info->options_len = 0;
-       info->key.tun_flags |= flags;
 }
 
 #endif /* CONFIG_INET */
index a21e8b1..851029e 100644 (file)
@@ -108,5 +108,35 @@ out_rcu_unlock:
        rcu_read_unlock();
        inet_frag_put(&fq->q);
 }
+
+/* Check if the upper layer header is truncated in the first fragment. */
+static inline bool
+ipv6frag_thdr_truncated(struct sk_buff *skb, int start, u8 *nexthdrp)
+{
+       u8 nexthdr = *nexthdrp;
+       __be16 frag_off;
+       int offset;
+
+       offset = ipv6_skip_exthdr(skb, start, &nexthdr, &frag_off);
+       if (offset < 0 || (frag_off & htons(IP6_OFFSET)))
+               return false;
+       switch (nexthdr) {
+       case NEXTHDR_TCP:
+               offset += sizeof(struct tcphdr);
+               break;
+       case NEXTHDR_UDP:
+               offset += sizeof(struct udphdr);
+               break;
+       case NEXTHDR_ICMP:
+               offset += sizeof(struct icmp6hdr);
+               break;
+       default:
+               offset += 1;
+       }
+       if (offset > skb->len)
+               return true;
+       return false;
+}
+
 #endif
 #endif
index e8e295d..dcdba96 100644 (file)
@@ -3311,7 +3311,7 @@ enum ieee80211_roc_type {
 };
 
 /**
- * enum ieee80211_reconfig_complete_type - reconfig type
+ * enum ieee80211_reconfig_type - reconfig type
  *
  * This enum is used by the reconfig_complete() callback to indicate what
  * reconfiguration type was completed.
@@ -6334,7 +6334,8 @@ bool ieee80211_tx_prepare_skb(struct ieee80211_hw *hw,
                              int band, struct ieee80211_sta **sta);
 
 /**
- * Sanity-check and parse the radiotap header of injected frames
+ * ieee80211_parse_tx_radiotap - Sanity-check and parse the radiotap header
+ *                              of injected frames
  * @skb: packet injected by userspace
  * @dev: the &struct device of this 802.11 device
  */
@@ -6389,7 +6390,7 @@ int ieee80211_parse_p2p_noa(const struct ieee80211_p2p_noa_attr *attr,
 void ieee80211_update_p2p_noa(struct ieee80211_noa_data *data, u32 tsf);
 
 /**
- * ieee80211_tdls_oper - request userspace to perform a TDLS operation
+ * ieee80211_tdls_oper_request - request userspace to perform a TDLS operation
  * @vif: virtual interface
  * @peer: the peer's destination address
  * @oper: the requested TDLS operation
index 81ee175..22ced13 100644 (file)
@@ -204,6 +204,7 @@ struct neigh_table {
        int                     (*pconstructor)(struct pneigh_entry *);
        void                    (*pdestructor)(struct pneigh_entry *);
        void                    (*proxy_redo)(struct sk_buff *skb);
+       int                     (*is_multicast)(const void *pkey);
        bool                    (*allow_add)(const struct net_device *dev,
                                             struct netlink_ext_ack *extack);
        char                    *id;
index baf1e99..cf14730 100644 (file)
@@ -300,7 +300,8 @@ enum tls_offload_sync_type {
 #define TLS_DEVICE_RESYNC_ASYNC_LOGMAX         13
 struct tls_offload_resync_async {
        atomic64_t req;
-       u32 loglen;
+       u16 loglen;
+       u16 rcd_delta;
        u32 log[TLS_DEVICE_RESYNC_ASYNC_LOGMAX];
 };
 
@@ -471,6 +472,18 @@ static inline bool tls_bigint_increment(unsigned char *seq, int len)
        return (i == -1);
 }
 
+static inline void tls_bigint_subtract(unsigned char *seq, int  n)
+{
+       u64 rcd_sn;
+       __be64 *p;
+
+       BUILD_BUG_ON(TLS_MAX_REC_SEQ_SIZE != 8);
+
+       p = (__be64 *)seq;
+       rcd_sn = be64_to_cpu(*p);
+       *p = cpu_to_be64(rcd_sn - n);
+}
+
 static inline struct tls_context *tls_get_ctx(const struct sock *sk)
 {
        struct inet_connection_sock *icsk = inet_csk(sk);
@@ -639,6 +652,7 @@ tls_offload_rx_resync_async_request_start(struct sock *sk, __be32 seq, u16 len)
        atomic64_set(&rx_ctx->resync_async->req, ((u64)ntohl(seq) << 32) |
                     ((u64)len << 16) | RESYNC_REQ | RESYNC_REQ_ASYNC);
        rx_ctx->resync_async->loglen = 0;
+       rx_ctx->resync_async->rcd_delta = 0;
 }
 
 static inline void
index 0140d08..01755b8 100644 (file)
@@ -86,7 +86,7 @@ int xp_assign_dev_shared(struct xsk_buff_pool *pool, struct xdp_umem *umem,
 void xp_destroy(struct xsk_buff_pool *pool);
 void xp_release(struct xdp_buff_xsk *xskb);
 void xp_get_pool(struct xsk_buff_pool *pool);
-void xp_put_pool(struct xsk_buff_pool *pool);
+bool xp_put_pool(struct xsk_buff_pool *pool);
 void xp_clear_dev(struct xsk_buff_pool *pool);
 void xp_add_xsk(struct xsk_buff_pool *pool, struct xdp_sock *xs);
 void xp_del_xsk(struct xsk_buff_pool *pool, struct xdp_sock *xs);
index c25fb86..b3bbd10 100644 (file)
@@ -132,6 +132,9 @@ struct iscsi_task {
        void                    *dd_data;       /* driver/transport data */
 };
 
+/* invalid scsi_task pointer */
+#define        INVALID_SCSI_TASK       (struct iscsi_task *)-1l
+
 static inline int iscsi_task_has_unsol_data(struct iscsi_task *task)
 {
        return task->unsol_r2t.data_length > task->unsol_r2t.sent;
index e128cff..77d9fa1 100644 (file)
@@ -42,7 +42,7 @@ struct snd_kcontrol_new {
        snd_ctl_elem_iface_t iface;     /* interface identifier */
        unsigned int device;            /* device/client number */
        unsigned int subdevice;         /* subdevice (substream) number */
-       const unsigned char *name;      /* ASCII name of item */
+       const char *name;               /* ASCII name of item */
        unsigned int index;             /* index of item */
        unsigned int access;            /* access rights */
        unsigned int count;             /* count of same elements */
index 381a010..0462c57 100644 (file)
@@ -332,7 +332,8 @@ void __snd_printk(unsigned int level, const char *file, int line,
 #define snd_BUG()              WARN(1, "BUG?\n")
 
 /**
- * Suppress high rates of output when CONFIG_SND_DEBUG is enabled.
+ * snd_printd_ratelimit - Suppress high rates of output when
+ *                       CONFIG_SND_DEBUG is enabled.
  */
 #define snd_printd_ratelimit() printk_ratelimit()
 
index 2ba5df2..2336bf9 100644 (file)
@@ -1284,8 +1284,8 @@ snd_pcm_sgbuf_get_ptr(struct snd_pcm_substream *substream, unsigned int ofs)
 }
 
 /**
- * snd_pcm_sgbuf_chunk_size - Compute the max size that fits within the contig.
- * page from the given size
+ * snd_pcm_sgbuf_get_chunk_size - Compute the max size that fits within the
+ * contig. page from the given size
  * @substream: PCM substream
  * @ofs: byte offset
  * @size: byte size to examine
diff --git a/include/sound/rt1015.h b/include/sound/rt1015.h
new file mode 100644 (file)
index 0000000..70a7538
--- /dev/null
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * linux/sound/rt1015.h -- Platform data for RT1015
+ *
+ * Copyright 2020 Realtek Microelectronics
+ */
+
+#ifndef __LINUX_SND_RT1015_H
+#define __LINUX_SND_RT1015_H
+
+struct rt1015_platform_data {
+       unsigned int power_up_delay_ms;
+};
+
+#endif
index b14314f..70ae549 100644 (file)
@@ -100,11 +100,12 @@ TRACE_DEFINE_ENUM(ES_REFERENCED_B);
                { EXT4_FC_REASON_XATTR,         "XATTR"},               \
                { EXT4_FC_REASON_CROSS_RENAME,  "CROSS_RENAME"},        \
                { EXT4_FC_REASON_JOURNAL_FLAG_CHANGE, "JOURNAL_FLAG_CHANGE"}, \
-               { EXT4_FC_REASON_MEM,   "NO_MEM"},                      \
+               { EXT4_FC_REASON_NOMEM, "NO_MEM"},                      \
                { EXT4_FC_REASON_SWAP_BOOT,     "SWAP_BOOT"},           \
                { EXT4_FC_REASON_RESIZE,        "RESIZE"},              \
                { EXT4_FC_REASON_RENAME_DIR,    "RENAME_DIR"},          \
-               { EXT4_FC_REASON_FALLOC_RANGE,  "FALLOC_RANGE"})
+               { EXT4_FC_REASON_FALLOC_RANGE,  "FALLOC_RANGE"},        \
+               { EXT4_FC_REASON_INODE_JOURNAL_DATA,    "INODE_JOURNAL_DATA"})
 
 TRACE_EVENT(ext4_other_inode_update_time,
        TP_PROTO(struct inode *inode, ino_t orig_ino),
@@ -2917,17 +2918,18 @@ TRACE_EVENT(ext4_fc_stats,
                    ),
 
            TP_printk("dev %d:%d fc ineligible reasons:\n"
-                     "%s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s,%d; "
+                     "%s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d; "
                      "num_commits:%ld, ineligible: %ld, numblks: %ld",
                      MAJOR(__entry->dev), MINOR(__entry->dev),
                      FC_REASON_NAME_STAT(EXT4_FC_REASON_XATTR),
                      FC_REASON_NAME_STAT(EXT4_FC_REASON_CROSS_RENAME),
                      FC_REASON_NAME_STAT(EXT4_FC_REASON_JOURNAL_FLAG_CHANGE),
-                     FC_REASON_NAME_STAT(EXT4_FC_REASON_MEM),
+                     FC_REASON_NAME_STAT(EXT4_FC_REASON_NOMEM),
                      FC_REASON_NAME_STAT(EXT4_FC_REASON_SWAP_BOOT),
                      FC_REASON_NAME_STAT(EXT4_FC_REASON_RESIZE),
                      FC_REASON_NAME_STAT(EXT4_FC_REASON_RENAME_DIR),
                      FC_REASON_NAME_STAT(EXT4_FC_REASON_FALLOC_RANGE),
+                     FC_REASON_NAME_STAT(EXT4_FC_REASON_INODE_JOURNAL_DATA),
                      __entry->sbi->s_fc_stats.fc_num_commits,
                      __entry->sbi->s_fc_stats.fc_ineligible_commits,
                      __entry->sbi->s_fc_stats.fc_numblks)
index f45b3c0..2a03263 100644 (file)
@@ -68,7 +68,8 @@ DECLARE_EVENT_CLASS(rpc_xdr_buf_class,
 
        TP_fast_assign(
                __entry->task_id = task->tk_pid;
-               __entry->client_id = task->tk_client->cl_clid;
+               __entry->client_id = task->tk_client ?
+                                    task->tk_client->cl_clid : -1;
                __entry->head_base = xdr->head[0].iov_base;
                __entry->head_len = xdr->head[0].iov_len;
                __entry->tail_base = xdr->tail[0].iov_base;
@@ -655,10 +656,10 @@ TRACE_EVENT(rpc_xdr_overflow,
                __field(size_t, tail_len)
                __field(unsigned int, page_len)
                __field(unsigned int, len)
-               __string(progname,
-                        xdr->rqst->rq_task->tk_client->cl_program->name)
-               __string(procedure,
-                        xdr->rqst->rq_task->tk_msg.rpc_proc->p_name)
+               __string(progname, xdr->rqst ?
+                        xdr->rqst->rq_task->tk_client->cl_program->name : "unknown")
+               __string(procedure, xdr->rqst ?
+                        xdr->rqst->rq_task->tk_msg.rpc_proc->p_name : "unknown")
        ),
 
        TP_fast_assign(
index 07865c6..2072c26 100644 (file)
@@ -26,7 +26,7 @@
  * struct gpiochip_info - Information about a certain GPIO chip
  * @name: the Linux kernel name of this GPIO chip
  * @label: a functional name for this GPIO chip, such as a product
- * number, may be empty
+ * number, may be empty (i.e. label[0] == '\0')
  * @lines: number of GPIO lines on this chip
  */
 struct gpiochip_info {
@@ -98,7 +98,7 @@ struct gpio_v2_line_values {
  * identifying which field of the attribute union is in use.
  * @GPIO_V2_LINE_ATTR_ID_FLAGS: flags field is in use
  * @GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES: values field is in use
- * @GPIO_V2_LINE_ATTR_ID_DEBOUNCE: debounce_period_us is in use
+ * @GPIO_V2_LINE_ATTR_ID_DEBOUNCE: debounce_period_us field is in use
  */
 enum gpio_v2_line_attr_id {
        GPIO_V2_LINE_ATTR_ID_FLAGS              = 1,
@@ -110,17 +110,17 @@ enum gpio_v2_line_attr_id {
  * struct gpio_v2_line_attribute - a configurable attribute of a line
  * @id: attribute identifier with value from &enum gpio_v2_line_attr_id
  * @padding: reserved for future use and must be zero filled
- * @flags: if id is GPIO_V2_LINE_ATTR_ID_FLAGS, the flags for the GPIO
- * line, with values from enum gpio_v2_line_flag, such as
- * GPIO_V2_LINE_FLAG_ACTIVE_LOW, GPIO_V2_LINE_FLAG_OUTPUT etc, OR:ed
+ * @flags: if id is %GPIO_V2_LINE_ATTR_ID_FLAGS, the flags for the GPIO
+ * line, with values from &enum gpio_v2_line_flag, such as
+ * %GPIO_V2_LINE_FLAG_ACTIVE_LOW, %GPIO_V2_LINE_FLAG_OUTPUT etc, added
  * together.  This overrides the default flags contained in the &struct
  * gpio_v2_line_config for the associated line.
- * @values: if id is GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES, a bitmap
+ * @values: if id is %GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES, a bitmap
  * containing the values to which the lines will be set, with each bit
  * number corresponding to the index into &struct
  * gpio_v2_line_request.offsets.
- * @debounce_period_us: if id is GPIO_V2_LINE_ATTR_ID_DEBOUNCE, the desired
- * debounce period, in microseconds
+ * @debounce_period_us: if id is %GPIO_V2_LINE_ATTR_ID_DEBOUNCE, the
+ * desired debounce period, in microseconds
  */
 struct gpio_v2_line_attribute {
        __u32 id;
@@ -147,12 +147,12 @@ struct gpio_v2_line_config_attribute {
 
 /**
  * struct gpio_v2_line_config - Configuration for GPIO lines
- * @flags: flags for the GPIO lines, with values from enum
- * gpio_v2_line_flag, such as GPIO_V2_LINE_FLAG_ACTIVE_LOW,
- * GPIO_V2_LINE_FLAG_OUTPUT etc, OR:ed together.  This is the default for
+ * @flags: flags for the GPIO lines, with values from &enum
+ * gpio_v2_line_flag, such as %GPIO_V2_LINE_FLAG_ACTIVE_LOW,
+ * %GPIO_V2_LINE_FLAG_OUTPUT etc, added together.  This is the default for
  * all requested lines but may be overridden for particular lines using
- * attrs.
- * @num_attrs: the number of attributes in attrs
+ * @attrs.
+ * @num_attrs: the number of attributes in @attrs
  * @padding: reserved for future use and must be zero filled
  * @attrs: the configuration attributes associated with the requested
  * lines.  Any attribute should only be associated with a particular line
@@ -175,17 +175,17 @@ struct gpio_v2_line_config {
  * "my-bitbanged-relay"
  * @config: requested configuration for the lines.
  * @num_lines: number of lines requested in this request, i.e. the number
- * of valid fields in the GPIO_V2_LINES_MAX sized arrays, set to 1 to
+ * of valid fields in the %GPIO_V2_LINES_MAX sized arrays, set to 1 to
  * request a single line
  * @event_buffer_size: a suggested minimum number of line events that the
  * kernel should buffer.  This is only relevant if edge detection is
  * enabled in the configuration. Note that this is only a suggested value
  * and the kernel may allocate a larger buffer or cap the size of the
  * buffer. If this field is zero then the buffer size defaults to a minimum
- * of num_lines*16.
+ * of @num_lines * 16.
  * @padding: reserved for future use and must be zero filled
  * @fd: if successful this field will contain a valid anonymous file handle
- * after a GPIO_GET_LINE_IOCTL operation, zero or negative value means
+ * after a %GPIO_GET_LINE_IOCTL operation, zero or negative value means
  * error
  */
 struct gpio_v2_line_request {
@@ -203,15 +203,16 @@ struct gpio_v2_line_request {
  * struct gpio_v2_line_info - Information about a certain GPIO line
  * @name: the name of this GPIO line, such as the output pin of the line on
  * the chip, a rail or a pin header name on a board, as specified by the
- * GPIO chip, may be empty
+ * GPIO chip, may be empty (i.e. name[0] == '\0')
  * @consumer: a functional name for the consumer of this GPIO line as set
  * by whatever is using it, will be empty if there is no current user but
  * may also be empty if the consumer doesn't set this up
- * @flags: flags for the GPIO line, such as GPIO_V2_LINE_FLAG_ACTIVE_LOW,
- * GPIO_V2_LINE_FLAG_OUTPUT etc, OR:ed together
  * @offset: the local offset on this GPIO chip, fill this in when
  * requesting the line information from the kernel
- * @num_attrs: the number of attributes in attrs
+ * @num_attrs: the number of attributes in @attrs
+ * @flags: flags for the GPIO lines, with values from &enum
+ * gpio_v2_line_flag, such as %GPIO_V2_LINE_FLAG_ACTIVE_LOW,
+ * %GPIO_V2_LINE_FLAG_OUTPUT etc, added together.
  * @attrs: the configuration attributes associated with the line
  * @padding: reserved for future use
  */
@@ -244,7 +245,7 @@ enum gpio_v2_line_changed_type {
  * of a GPIO line
  * @info: updated line information
  * @timestamp_ns: estimate of time of status change occurrence, in nanoseconds
- * @event_type: the type of change with a value from enum
+ * @event_type: the type of change with a value from &enum
  * gpio_v2_line_changed_type
  * @padding: reserved for future use
  */
@@ -269,10 +270,10 @@ enum gpio_v2_line_event_id {
 /**
  * struct gpio_v2_line_event - The actual event being pushed to userspace
  * @timestamp_ns: best estimate of time of event occurrence, in nanoseconds.
- * The timestamp_ns is read from CLOCK_MONOTONIC and is intended to allow the
- * accurate measurement of the time between events.  It does not provide
+ * The @timestamp_ns is read from %CLOCK_MONOTONIC and is intended to allow
+ * the accurate measurement of the time between events. It does not provide
  * the wall-clock time.
- * @id: event identifier with value from enum gpio_v2_line_event_id
+ * @id: event identifier with value from &enum gpio_v2_line_event_id
  * @offset: the offset of the line that triggered the event
  * @seqno: the sequence number for this event in the sequence of events for
  * all the lines in this line request
@@ -291,7 +292,7 @@ struct gpio_v2_line_event {
 };
 
 /*
- *  ABI v1
+ * ABI v1
  *
  * This version of the ABI is deprecated.
  * Use the latest version of the ABI, defined above, instead.
@@ -314,13 +315,13 @@ struct gpio_v2_line_event {
  * @flags: various flags for this line
  * @name: the name of this GPIO line, such as the output pin of the line on the
  * chip, a rail or a pin header name on a board, as specified by the gpio
- * chip, may be empty
+ * chip, may be empty (i.e. name[0] == '\0')
  * @consumer: a functional name for the consumer of this GPIO line as set by
  * whatever is using it, will be empty if there is no current user but may
  * also be empty if the consumer doesn't set this up
  *
- * This struct is part of ABI v1 and is deprecated.
- * Use struct gpio_v2_line_info instead.
+ * Note: This struct is part of ABI v1 and is deprecated.
+ * Use &struct gpio_v2_line_info instead.
  */
 struct gpioline_info {
        __u32 line_offset;
@@ -344,17 +345,18 @@ enum {
  * of a GPIO line
  * @info: updated line information
  * @timestamp: estimate of time of status change occurrence, in nanoseconds
- * @event_type: one of GPIOLINE_CHANGED_REQUESTED, GPIOLINE_CHANGED_RELEASED
- * and GPIOLINE_CHANGED_CONFIG
+ * @event_type: one of %GPIOLINE_CHANGED_REQUESTED,
+ * %GPIOLINE_CHANGED_RELEASED and %GPIOLINE_CHANGED_CONFIG
+ * @padding: reserved for future use
  *
- * Note: struct gpioline_info embedded here has 32-bit alignment on its own,
+ * The &struct gpioline_info embedded here has 32-bit alignment on its own,
  * but it works fine with 64-bit alignment too. With its 72 byte size, we can
  * guarantee there are no implicit holes between it and subsequent members.
  * The 20-byte padding at the end makes sure we don't add any implicit padding
  * at the end of the structure on 64-bit architectures.
  *
- * This struct is part of ABI v1 and is deprecated.
- * Use struct gpio_v2_line_info_changed instead.
+ * Note: This struct is part of ABI v1 and is deprecated.
+ * Use &struct gpio_v2_line_info_changed instead.
  */
 struct gpioline_info_changed {
        struct gpioline_info info;
@@ -378,13 +380,13 @@ struct gpioline_info_changed {
  * @lineoffsets: an array of desired lines, specified by offset index for the
  * associated GPIO device
  * @flags: desired flags for the desired GPIO lines, such as
- * GPIOHANDLE_REQUEST_OUTPUT, GPIOHANDLE_REQUEST_ACTIVE_LOW etc, OR:ed
+ * %GPIOHANDLE_REQUEST_OUTPUT, %GPIOHANDLE_REQUEST_ACTIVE_LOW etc, added
  * together. Note that even if multiple lines are requested, the same flags
  * must be applicable to all of them, if you want lines with individual
  * flags set, request them one by one. It is possible to select
  * a batch of input or output lines, but they must all have the same
  * characteristics, i.e. all inputs or all outputs, all active low etc
- * @default_values: if the GPIOHANDLE_REQUEST_OUTPUT is set for a requested
+ * @default_values: if the %GPIOHANDLE_REQUEST_OUTPUT is set for a requested
  * line, this specifies the default output value, should be 0 (low) or
  * 1 (high), anything else than 0 or 1 will be interpreted as 1 (high)
  * @consumer_label: a desired consumer label for the selected GPIO line(s)
@@ -392,11 +394,11 @@ struct gpioline_info_changed {
  * @lines: number of lines requested in this request, i.e. the number of
  * valid fields in the above arrays, set to 1 to request a single line
  * @fd: if successful this field will contain a valid anonymous file handle
- * after a GPIO_GET_LINEHANDLE_IOCTL operation, zero or negative value
+ * after a %GPIO_GET_LINEHANDLE_IOCTL operation, zero or negative value
  * means error
  *
- * This struct is part of ABI v1 and is deprecated.
- * Use struct gpio_v2_line_request instead.
+ * Note: This struct is part of ABI v1 and is deprecated.
+ * Use &struct gpio_v2_line_request instead.
  */
 struct gpiohandle_request {
        __u32 lineoffsets[GPIOHANDLES_MAX];
@@ -410,15 +412,15 @@ struct gpiohandle_request {
 /**
  * struct gpiohandle_config - Configuration for a GPIO handle request
  * @flags: updated flags for the requested GPIO lines, such as
- * GPIOHANDLE_REQUEST_OUTPUT, GPIOHANDLE_REQUEST_ACTIVE_LOW etc, OR:ed
+ * %GPIOHANDLE_REQUEST_OUTPUT, %GPIOHANDLE_REQUEST_ACTIVE_LOW etc, added
  * together
- * @default_values: if the GPIOHANDLE_REQUEST_OUTPUT is set in flags,
+ * @default_values: if the %GPIOHANDLE_REQUEST_OUTPUT is set in flags,
  * this specifies the default output value, should be 0 (low) or
  * 1 (high), anything else than 0 or 1 will be interpreted as 1 (high)
  * @padding: reserved for future use and should be zero filled
  *
- * This struct is part of ABI v1 and is deprecated.
- * Use struct gpio_v2_line_config instead.
+ * Note: This struct is part of ABI v1 and is deprecated.
+ * Use &struct gpio_v2_line_config instead.
  */
 struct gpiohandle_config {
        __u32 flags;
@@ -432,8 +434,8 @@ struct gpiohandle_config {
  * state of a line, when setting the state of lines these should contain
  * the desired target state
  *
- * This struct is part of ABI v1 and is deprecated.
- * Use struct gpio_v2_line_values instead.
+ * Note: This struct is part of ABI v1 and is deprecated.
+ * Use &struct gpio_v2_line_values instead.
  */
 struct gpiohandle_data {
        __u8 values[GPIOHANDLES_MAX];
@@ -449,17 +451,17 @@ struct gpiohandle_data {
  * @lineoffset: the desired line to subscribe to events from, specified by
  * offset index for the associated GPIO device
  * @handleflags: desired handle flags for the desired GPIO line, such as
- * GPIOHANDLE_REQUEST_ACTIVE_LOW or GPIOHANDLE_REQUEST_OPEN_DRAIN
+ * %GPIOHANDLE_REQUEST_ACTIVE_LOW or %GPIOHANDLE_REQUEST_OPEN_DRAIN
  * @eventflags: desired flags for the desired GPIO event line, such as
- * GPIOEVENT_REQUEST_RISING_EDGE or GPIOEVENT_REQUEST_FALLING_EDGE
+ * %GPIOEVENT_REQUEST_RISING_EDGE or %GPIOEVENT_REQUEST_FALLING_EDGE
  * @consumer_label: a desired consumer label for the selected GPIO line(s)
  * such as "my-listener"
  * @fd: if successful this field will contain a valid anonymous file handle
- * after a GPIO_GET_LINEEVENT_IOCTL operation, zero or negative value
+ * after a %GPIO_GET_LINEEVENT_IOCTL operation, zero or negative value
  * means error
  *
- * This struct is part of ABI v1 and is deprecated.
- * Use struct gpio_v2_line_request instead.
+ * Note: This struct is part of ABI v1 and is deprecated.
+ * Use &struct gpio_v2_line_request instead.
  */
 struct gpioevent_request {
        __u32 lineoffset;
@@ -469,7 +471,7 @@ struct gpioevent_request {
        int fd;
 };
 
-/**
+/*
  * GPIO event types
  */
 #define GPIOEVENT_EVENT_RISING_EDGE 0x01
@@ -480,8 +482,8 @@ struct gpioevent_request {
  * @timestamp: best estimate of time of event occurrence, in nanoseconds
  * @id: event identifier
  *
- * This struct is part of ABI v1 and is deprecated.
- * Use struct gpio_v2_line_event instead.
+ * Note: This struct is part of ABI v1 and is deprecated.
+ * Use &struct gpio_v2_line_event instead.
  */
 struct gpioevent_data {
        __u64 timestamp;
index c1661fe..0564fd7 100644 (file)
@@ -138,6 +138,7 @@ struct icmp6hdr {
 #define ICMPV6_HDR_FIELD               0
 #define ICMPV6_UNK_NEXTHDR             1
 #define ICMPV6_UNK_OPTION              2
+#define ICMPV6_HDR_INCOMP              3
 
 /*
  *     constants for (set|get)sockopt
index 7184265..9555f31 100644 (file)
@@ -144,7 +144,7 @@ struct snd_compr_metadata {
         __u32 value[8];
 } __attribute__((packed, aligned(4)));
 
-/**
+/*
  * compress path ioctl definitions
  * SNDRV_COMPRESS_GET_CAPS: Query capability of DSP
  * SNDRV_COMPRESS_GET_CODEC_CAPS: Query capability of a codec
index 06b0b57..d1b3889 100644 (file)
@@ -484,9 +484,6 @@ int ipu_smfc_set_watermark(struct ipu_smfc *smfc, u32 set_level, u32 clr_level);
 
 enum ipu_color_space ipu_drm_fourcc_to_colorspace(u32 drm_fourcc);
 enum ipu_color_space ipu_pixelformat_to_colorspace(u32 pixelformat);
-enum ipu_color_space ipu_mbus_code_to_colorspace(u32 mbus_code);
-int ipu_stride_to_bytes(u32 pixel_stride, u32 pixelformat);
-bool ipu_pixelformat_is_planar(u32 pixelformat);
 int ipu_degrees_to_rot_mode(enum ipu_rotate_mode *mode, int degrees,
                            bool hflip, bool vflip);
 int ipu_rot_mode_to_degrees(int *degrees, enum ipu_rotate_mode mode,
index 130376e..20baced 100644 (file)
@@ -269,14 +269,24 @@ static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)
        u32 size, csum;
        char *data;
        u32 *hdr;
+       int i;
 
        if (!initrd_end)
                return NULL;
 
        data = (char *)initrd_end - BOOTCONFIG_MAGIC_LEN;
-       if (memcmp(data, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN))
-               return NULL;
+       /*
+        * Since Grub may align the size of initrd to 4, we must
+        * check the preceding 3 bytes as well.
+        */
+       for (i = 0; i < 4; i++) {
+               if (!memcmp(data, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN))
+                       goto found;
+               data--;
+       }
+       return NULL;
 
+found:
        hdr = (u32 *)(data - 8);
        size = hdr[0];
        csum = hdr[1];
index bdc8cd1..c1b9f71 100644 (file)
@@ -1,6 +1,10 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-y := core.o
-CFLAGS_core.o += $(call cc-disable-warning, override-init)
+ifneq ($(CONFIG_BPF_JIT_ALWAYS_ON),y)
+# ___bpf_prog_run() needs GCSE disabled on x86; see 3193c0836f203 for details
+cflags-nogcse-$(CONFIG_X86)$(CONFIG_CC_IS_GCC) := -fno-gcse
+endif
+CFLAGS_core.o += $(call cc-disable-warning, override-init) $(cflags-nogcse-yy)
 
 obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o bpf_iter.o map_iter.o task_iter.o prog_iter.o
 obj-$(CONFIG_BPF_SYSCALL) += hashtab.o arraymap.o percpu_freelist.o bpf_lru_list.o lpm_trie.o map_in_map.o
index 78ea8a7..56cc5a9 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/bpf_verifier.h>
 #include <net/bpf_sk_storage.h>
 #include <linux/bpf_local_storage.h>
+#include <linux/btf_ids.h>
 
 /* For every LSM hook that allows attachment of BPF programs, declare a nop
  * function where a BPF program can be attached.
@@ -26,7 +27,11 @@ noinline RET bpf_lsm_##NAME(__VA_ARGS__)     \
 #include <linux/lsm_hook_defs.h>
 #undef LSM_HOOK
 
-#define BPF_LSM_SYM_PREFX  "bpf_lsm_"
+#define LSM_HOOK(RET, DEFAULT, NAME, ...) BTF_ID(func, bpf_lsm_##NAME)
+BTF_SET_START(bpf_lsm_hooks)
+#include <linux/lsm_hook_defs.h>
+#undef LSM_HOOK
+BTF_SET_END(bpf_lsm_hooks)
 
 int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog,
                        const struct bpf_prog *prog)
@@ -37,8 +42,7 @@ int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog,
                return -EINVAL;
        }
 
-       if (strncmp(BPF_LSM_SYM_PREFX, prog->aux->attach_func_name,
-                   sizeof(BPF_LSM_SYM_PREFX) - 1)) {
+       if (!btf_id_set_contains(&bpf_lsm_hooks, prog->aux->attach_btf_id)) {
                bpf_log(vlog, "attach_btf_id %u points to wrong type name %s\n",
                        prog->aux->attach_btf_id, prog->aux->attach_func_name);
                return -EINVAL;
index 9268d77..55454d2 100644 (file)
@@ -1369,7 +1369,7 @@ u64 __weak bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
  *
  * Decode and execute eBPF instructions.
  */
-static u64 __no_fgcse ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, u64 *stack)
+static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, u64 *stack)
 {
 #define BPF_INSN_2_LBL(x, y)    [BPF_##x | BPF_##y] = &&x##_##y
 #define BPF_INSN_3_LBL(x, y, z) [BPF_##x | BPF_##y | BPF_##z] = &&x##_##y##_##z
index 1815e97..1fccba6 100644 (file)
@@ -821,6 +821,32 @@ static void pcpu_copy_value(struct bpf_htab *htab, void __percpu *pptr,
        }
 }
 
+static void pcpu_init_value(struct bpf_htab *htab, void __percpu *pptr,
+                           void *value, bool onallcpus)
+{
+       /* When using prealloc and not setting the initial value on all cpus,
+        * zero-fill element values for other cpus (just as what happens when
+        * not using prealloc). Otherwise, bpf program has no way to ensure
+        * known initial values for cpus other than current one
+        * (onallcpus=false always when coming from bpf prog).
+        */
+       if (htab_is_prealloc(htab) && !onallcpus) {
+               u32 size = round_up(htab->map.value_size, 8);
+               int current_cpu = raw_smp_processor_id();
+               int cpu;
+
+               for_each_possible_cpu(cpu) {
+                       if (cpu == current_cpu)
+                               bpf_long_memcpy(per_cpu_ptr(pptr, cpu), value,
+                                               size);
+                       else
+                               memset(per_cpu_ptr(pptr, cpu), 0, size);
+               }
+       } else {
+               pcpu_copy_value(htab, pptr, value, onallcpus);
+       }
+}
+
 static bool fd_htab_map_needs_adjust(const struct bpf_htab *htab)
 {
        return htab->map.map_type == BPF_MAP_TYPE_HASH_OF_MAPS &&
@@ -891,7 +917,7 @@ static struct htab_elem *alloc_htab_elem(struct bpf_htab *htab, void *key,
                        }
                }
 
-               pcpu_copy_value(htab, pptr, value, onallcpus);
+               pcpu_init_value(htab, pptr, value, onallcpus);
 
                if (!prealloc)
                        htab_elem_set_ptr(l_new, key_size, pptr);
@@ -1183,7 +1209,7 @@ static int __htab_lru_percpu_map_update_elem(struct bpf_map *map, void *key,
                pcpu_copy_value(htab, htab_elem_get_ptr(l_old, key_size),
                                value, onallcpus);
        } else {
-               pcpu_copy_value(htab, htab_elem_get_ptr(l_new, key_size),
+               pcpu_init_value(htab, htab_elem_get_ptr(l_new, key_size),
                                value, onallcpus);
                hlist_nulls_add_head_rcu(&l_new->hash_node, head);
                l_new = NULL;
index ace4911..26bced2 100644 (file)
@@ -6,6 +6,7 @@ config USERMODE_DRIVER
 menuconfig BPF_PRELOAD
        bool "Preload BPF file system with kernel specific program and map iterators"
        depends on BPF
+       depends on BPF_SYSCALL
        # The dependency on !COMPILE_TEST prevents it from being enabled
        # in allmodconfig or allyesconfig configurations
        depends on !COMPILE_TEST
index 6200519..1388bf7 100644 (file)
@@ -7786,9 +7786,11 @@ static int check_return_code(struct bpf_verifier_env *env)
        struct tnum range = tnum_range(0, 1);
        enum bpf_prog_type prog_type = resolve_prog_type(env->prog);
        int err;
+       const bool is_subprog = env->cur_state->frame[0]->subprogno;
 
        /* LSM and struct_ops func-ptr's return type could be "void" */
-       if ((prog_type == BPF_PROG_TYPE_STRUCT_OPS ||
+       if (!is_subprog &&
+           (prog_type == BPF_PROG_TYPE_STRUCT_OPS ||
             prog_type == BPF_PROG_TYPE_LSM) &&
            !prog->aux->attach_func_proto->type)
                return 0;
@@ -7808,6 +7810,16 @@ static int check_return_code(struct bpf_verifier_env *env)
                return -EACCES;
        }
 
+       reg = cur_regs(env) + BPF_REG_0;
+       if (is_subprog) {
+               if (reg->type != SCALAR_VALUE) {
+                       verbose(env, "At subprogram exit the register R0 is not a scalar value (%s)\n",
+                               reg_type_str[reg->type]);
+                       return -EINVAL;
+               }
+               return 0;
+       }
+
        switch (prog_type) {
        case BPF_PROG_TYPE_CGROUP_SOCK_ADDR:
                if (env->prog->expected_attach_type == BPF_CGROUP_UDP4_RECVMSG ||
@@ -7861,7 +7873,6 @@ static int check_return_code(struct bpf_verifier_env *env)
                return 0;
        }
 
-       reg = cur_regs(env) + BPF_REG_0;
        if (reg->type != SCALAR_VALUE) {
                verbose(env, "At program exit the register R0 is not a known value (%s)\n",
                        reg_type_str[reg->type]);
@@ -9572,12 +9583,13 @@ static int check_pseudo_btf_id(struct bpf_verifier_env *env,
                               struct bpf_insn *insn,
                               struct bpf_insn_aux_data *aux)
 {
-       u32 datasec_id, type, id = insn->imm;
        const struct btf_var_secinfo *vsi;
        const struct btf_type *datasec;
        const struct btf_type *t;
        const char *sym_name;
        bool percpu = false;
+       u32 type, id = insn->imm;
+       s32 datasec_id;
        u64 addr;
        int i;
 
index b4eea0a..781b9dc 100644 (file)
@@ -229,6 +229,7 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
                io_tlb_orig_addr[i] = INVALID_PHYS_ADDR;
        }
        io_tlb_index = 0;
+       no_iotlb_memory = false;
 
        if (verbose)
                swiotlb_print_info();
@@ -260,9 +261,11 @@ swiotlb_init(int verbose)
        if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, verbose))
                return;
 
-       if (io_tlb_start)
+       if (io_tlb_start) {
                memblock_free_early(io_tlb_start,
                                    PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT));
+               io_tlb_start = 0;
+       }
        pr_warn("Cannot allocate buffer");
        no_iotlb_memory = true;
 }
@@ -360,6 +363,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
                io_tlb_orig_addr[i] = INVALID_PHYS_ADDR;
        }
        io_tlb_index = 0;
+       no_iotlb_memory = false;
 
        swiotlb_print_info();
 
@@ -441,14 +445,11 @@ static void swiotlb_bounce(phys_addr_t orig_addr, phys_addr_t tlb_addr,
        }
 }
 
-phys_addr_t swiotlb_tbl_map_single(struct device *hwdev,
-                                  dma_addr_t tbl_dma_addr,
-                                  phys_addr_t orig_addr,
-                                  size_t mapping_size,
-                                  size_t alloc_size,
-                                  enum dma_data_direction dir,
-                                  unsigned long attrs)
+phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr,
+               size_t mapping_size, size_t alloc_size,
+               enum dma_data_direction dir, unsigned long attrs)
 {
+       dma_addr_t tbl_dma_addr = phys_to_dma_unencrypted(hwdev, io_tlb_start);
        unsigned long flags;
        phys_addr_t tlb_addr;
        unsigned int nslots, stride, index, wrap;
@@ -667,9 +668,8 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t paddr, size_t size,
        trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size,
                              swiotlb_force);
 
-       swiotlb_addr = swiotlb_tbl_map_single(dev,
-                       phys_to_dma_unencrypted(dev, io_tlb_start),
-                       paddr, size, size, dir, attrs);
+       swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, dir,
+                       attrs);
        if (swiotlb_addr == (phys_addr_t)DMA_MAPPING_ERROR)
                return DMA_MAPPING_ERROR;
 
index 2b83666..e9e2df3 100644 (file)
@@ -337,10 +337,10 @@ noinstr irqentry_state_t irqentry_enter(struct pt_regs *regs)
         * already contains a warning when RCU is not watching, so no point
         * in having another one here.
         */
+       lockdep_hardirqs_off(CALLER_ADDR0);
        instrumentation_begin();
        rcu_irq_enter_check_tick();
-       /* Use the combo lockdep/tracing function */
-       trace_hardirqs_off();
+       trace_hardirqs_off_finish();
        instrumentation_end();
 
        return ret;
index da467e1..dc568ca 100644 (file)
@@ -2312,9 +2312,6 @@ group_sched_out(struct perf_event *group_event,
                event_sched_out(event, cpuctx, ctx);
 
        perf_pmu_enable(ctx->pmu);
-
-       if (group_event->attr.exclusive)
-               cpuctx->exclusive = 0;
 }
 
 #define DETACH_GROUP   0x01UL
@@ -2583,11 +2580,8 @@ group_sched_in(struct perf_event *group_event,
 
        pmu->start_txn(pmu, PERF_PMU_TXN_ADD);
 
-       if (event_sched_in(group_event, cpuctx, ctx)) {
-               pmu->cancel_txn(pmu);
-               perf_mux_hrtimer_restart(cpuctx);
-               return -EAGAIN;
-       }
+       if (event_sched_in(group_event, cpuctx, ctx))
+               goto error;
 
        /*
         * Schedule in siblings as one group (if any):
@@ -2616,10 +2610,8 @@ group_error:
        }
        event_sched_out(group_event, cpuctx, ctx);
 
+error:
        pmu->cancel_txn(pmu);
-
-       perf_mux_hrtimer_restart(cpuctx);
-
        return -EAGAIN;
 }
 
@@ -2645,7 +2637,7 @@ static int group_can_go_on(struct perf_event *event,
         * If this group is exclusive and there are already
         * events on the CPU, it can't go on.
         */
-       if (event->attr.exclusive && cpuctx->active_oncpu)
+       if (event->attr.exclusive && !list_empty(get_event_list(event)))
                return 0;
        /*
         * Otherwise, try to add it if all previous groups were able
@@ -3679,6 +3671,7 @@ static int merge_sched_in(struct perf_event *event, void *data)
 
                *can_add_hw = 0;
                ctx->rotate_necessary = 1;
+               perf_mux_hrtimer_restart(cpuctx);
        }
 
        return 0;
@@ -6374,14 +6367,13 @@ perf_output_sample_regs(struct perf_output_handle *handle,
 }
 
 static void perf_sample_regs_user(struct perf_regs *regs_user,
-                                 struct pt_regs *regs,
-                                 struct pt_regs *regs_user_copy)
+                                 struct pt_regs *regs)
 {
        if (user_mode(regs)) {
                regs_user->abi = perf_reg_abi(current);
                regs_user->regs = regs;
        } else if (!(current->flags & PF_KTHREAD)) {
-               perf_get_regs_user(regs_user, regs, regs_user_copy);
+               perf_get_regs_user(regs_user, regs);
        } else {
                regs_user->abi = PERF_SAMPLE_REGS_ABI_NONE;
                regs_user->regs = NULL;
@@ -7083,8 +7075,7 @@ void perf_prepare_sample(struct perf_event_header *header,
        }
 
        if (sample_type & (PERF_SAMPLE_REGS_USER | PERF_SAMPLE_STACK_USER))
-               perf_sample_regs_user(&data->regs_user, regs,
-                                     &data->regs_user_copy);
+               perf_sample_regs_user(&data->regs_user, regs);
 
        if (sample_type & PERF_SAMPLE_REGS_USER) {
                /* regs dump ABI info */
@@ -7186,6 +7177,7 @@ __perf_event_output(struct perf_event *event,
                    struct perf_sample_data *data,
                    struct pt_regs *regs,
                    int (*output_begin)(struct perf_output_handle *,
+                                       struct perf_sample_data *,
                                        struct perf_event *,
                                        unsigned int))
 {
@@ -7198,7 +7190,7 @@ __perf_event_output(struct perf_event *event,
 
        perf_prepare_sample(&header, data, event, regs);
 
-       err = output_begin(&handle, event, header.size);
+       err = output_begin(&handle, data, event, header.size);
        if (err)
                goto exit;
 
@@ -7264,7 +7256,7 @@ perf_event_read_event(struct perf_event *event,
        int ret;
 
        perf_event_header__init_id(&read_event.header, &sample, event);
-       ret = perf_output_begin(&handle, event, read_event.header.size);
+       ret = perf_output_begin(&handle, &sample, event, read_event.header.size);
        if (ret)
                return;
 
@@ -7533,7 +7525,7 @@ static void perf_event_task_output(struct perf_event *event,
 
        perf_event_header__init_id(&task_event->event_id.header, &sample, event);
 
-       ret = perf_output_begin(&handle, event,
+       ret = perf_output_begin(&handle, &sample, event,
                                task_event->event_id.header.size);
        if (ret)
                goto out;
@@ -7636,7 +7628,7 @@ static void perf_event_comm_output(struct perf_event *event,
                return;
 
        perf_event_header__init_id(&comm_event->event_id.header, &sample, event);
-       ret = perf_output_begin(&handle, event,
+       ret = perf_output_begin(&handle, &sample, event,
                                comm_event->event_id.header.size);
 
        if (ret)
@@ -7736,7 +7728,7 @@ static void perf_event_namespaces_output(struct perf_event *event,
 
        perf_event_header__init_id(&namespaces_event->event_id.header,
                                   &sample, event);
-       ret = perf_output_begin(&handle, event,
+       ret = perf_output_begin(&handle, &sample, event,
                                namespaces_event->event_id.header.size);
        if (ret)
                goto out;
@@ -7863,7 +7855,7 @@ static void perf_event_cgroup_output(struct perf_event *event, void *data)
 
        perf_event_header__init_id(&cgroup_event->event_id.header,
                                   &sample, event);
-       ret = perf_output_begin(&handle, event,
+       ret = perf_output_begin(&handle, &sample, event,
                                cgroup_event->event_id.header.size);
        if (ret)
                goto out;
@@ -7989,7 +7981,7 @@ static void perf_event_mmap_output(struct perf_event *event,
        }
 
        perf_event_header__init_id(&mmap_event->event_id.header, &sample, event);
-       ret = perf_output_begin(&handle, event,
+       ret = perf_output_begin(&handle, &sample, event,
                                mmap_event->event_id.header.size);
        if (ret)
                goto out;
@@ -8299,7 +8291,7 @@ void perf_event_aux_event(struct perf_event *event, unsigned long head,
        int ret;
 
        perf_event_header__init_id(&rec.header, &sample, event);
-       ret = perf_output_begin(&handle, event, rec.header.size);
+       ret = perf_output_begin(&handle, &sample, event, rec.header.size);
 
        if (ret)
                return;
@@ -8333,7 +8325,7 @@ void perf_log_lost_samples(struct perf_event *event, u64 lost)
 
        perf_event_header__init_id(&lost_samples_event.header, &sample, event);
 
-       ret = perf_output_begin(&handle, event,
+       ret = perf_output_begin(&handle, &sample, event,
                                lost_samples_event.header.size);
        if (ret)
                return;
@@ -8388,7 +8380,7 @@ static void perf_event_switch_output(struct perf_event *event, void *data)
 
        perf_event_header__init_id(&se->event_id.header, &sample, event);
 
-       ret = perf_output_begin(&handle, event, se->event_id.header.size);
+       ret = perf_output_begin(&handle, &sample, event, se->event_id.header.size);
        if (ret)
                return;
 
@@ -8463,7 +8455,7 @@ static void perf_log_throttle(struct perf_event *event, int enable)
 
        perf_event_header__init_id(&throttle_event.header, &sample, event);
 
-       ret = perf_output_begin(&handle, event,
+       ret = perf_output_begin(&handle, &sample, event,
                                throttle_event.header.size);
        if (ret)
                return;
@@ -8506,7 +8498,7 @@ static void perf_event_ksymbol_output(struct perf_event *event, void *data)
 
        perf_event_header__init_id(&ksymbol_event->event_id.header,
                                   &sample, event);
-       ret = perf_output_begin(&handle, event,
+       ret = perf_output_begin(&handle, &sample, event,
                                ksymbol_event->event_id.header.size);
        if (ret)
                return;
@@ -8596,7 +8588,7 @@ static void perf_event_bpf_output(struct perf_event *event, void *data)
 
        perf_event_header__init_id(&bpf_event->event_id.header,
                                   &sample, event);
-       ret = perf_output_begin(&handle, event,
+       ret = perf_output_begin(&handle, data, event,
                                bpf_event->event_id.header.size);
        if (ret)
                return;
@@ -8705,7 +8697,8 @@ static void perf_event_text_poke_output(struct perf_event *event, void *data)
 
        perf_event_header__init_id(&text_poke_event->event_id.header, &sample, event);
 
-       ret = perf_output_begin(&handle, event, text_poke_event->event_id.header.size);
+       ret = perf_output_begin(&handle, &sample, event,
+                               text_poke_event->event_id.header.size);
        if (ret)
                return;
 
@@ -8786,7 +8779,7 @@ static void perf_log_itrace_start(struct perf_event *event)
        rec.tid = perf_event_tid(event, current);
 
        perf_event_header__init_id(&rec.header, &sample, event);
-       ret = perf_output_begin(&handle, event, rec.header.size);
+       ret = perf_output_begin(&handle, &sample, event, rec.header.size);
 
        if (ret)
                return;
@@ -10085,6 +10078,7 @@ perf_event_parse_addr_filter(struct perf_event *event, char *fstr,
                        if (token == IF_SRC_FILE || token == IF_SRC_FILEADDR) {
                                int fpos = token == IF_SRC_FILE ? 2 : 1;
 
+                               kfree(filename);
                                filename = match_strdup(&args[fpos]);
                                if (!filename) {
                                        ret = -ENOMEM;
@@ -10131,16 +10125,13 @@ perf_event_parse_addr_filter(struct perf_event *event, char *fstr,
                                 */
                                ret = -EOPNOTSUPP;
                                if (!event->ctx->task)
-                                       goto fail_free_name;
+                                       goto fail;
 
                                /* look up the path and grab its inode */
                                ret = kern_path(filename, LOOKUP_FOLLOW,
                                                &filter->path);
                                if (ret)
-                                       goto fail_free_name;
-
-                               kfree(filename);
-                               filename = NULL;
+                                       goto fail;
 
                                ret = -EINVAL;
                                if (!filter->path.dentry ||
@@ -10160,13 +10151,13 @@ perf_event_parse_addr_filter(struct perf_event *event, char *fstr,
        if (state != IF_STATE_ACTION)
                goto fail;
 
+       kfree(filename);
        kfree(orig);
 
        return 0;
 
-fail_free_name:
-       kfree(filename);
 fail:
+       kfree(filename);
        free_filters_list(filters);
        kfree(orig);
 
index fcbf561..228801e 100644 (file)
@@ -205,16 +205,12 @@ DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
 
 static inline int get_recursion_context(int *recursion)
 {
-       int rctx;
-
-       if (unlikely(in_nmi()))
-               rctx = 3;
-       else if (in_irq())
-               rctx = 2;
-       else if (in_softirq())
-               rctx = 1;
-       else
-               rctx = 0;
+       unsigned int pc = preempt_count();
+       unsigned char rctx = 0;
+
+       rctx += !!(pc & (NMI_MASK));
+       rctx += !!(pc & (NMI_MASK | HARDIRQ_MASK));
+       rctx += !!(pc & (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET));
 
        if (recursion[rctx])
                return -1;
index 192b8ab..ef91ae7 100644 (file)
@@ -147,6 +147,7 @@ ring_buffer_has_space(unsigned long head, unsigned long tail,
 
 static __always_inline int
 __perf_output_begin(struct perf_output_handle *handle,
+                   struct perf_sample_data *data,
                    struct perf_event *event, unsigned int size,
                    bool backward)
 {
@@ -237,18 +238,16 @@ __perf_output_begin(struct perf_output_handle *handle,
        handle->size = (1UL << page_shift) - offset;
 
        if (unlikely(have_lost)) {
-               struct perf_sample_data sample_data;
-
                lost_event.header.size = sizeof(lost_event);
                lost_event.header.type = PERF_RECORD_LOST;
                lost_event.header.misc = 0;
                lost_event.id          = event->id;
                lost_event.lost        = local_xchg(&rb->lost, 0);
 
-               perf_event_header__init_id(&lost_event.header,
-                                          &sample_data, event);
+               /* XXX mostly redundant; @data is already fully initializes */
+               perf_event_header__init_id(&lost_event.header, data, event);
                perf_output_put(handle, lost_event);
-               perf_event__output_id_sample(event, handle, &sample_data);
+               perf_event__output_id_sample(event, handle, data);
        }
 
        return 0;
@@ -263,22 +262,25 @@ out:
 }
 
 int perf_output_begin_forward(struct perf_output_handle *handle,
-                            struct perf_event *event, unsigned int size)
+                             struct perf_sample_data *data,
+                             struct perf_event *event, unsigned int size)
 {
-       return __perf_output_begin(handle, event, size, false);
+       return __perf_output_begin(handle, data, event, size, false);
 }
 
 int perf_output_begin_backward(struct perf_output_handle *handle,
+                              struct perf_sample_data *data,
                               struct perf_event *event, unsigned int size)
 {
-       return __perf_output_begin(handle, event, size, true);
+       return __perf_output_begin(handle, data, event, size, true);
 }
 
 int perf_output_begin(struct perf_output_handle *handle,
+                     struct perf_sample_data *data,
                      struct perf_event *event, unsigned int size)
 {
 
-       return __perf_output_begin(handle, event, size,
+       return __perf_output_begin(handle, data, event, size,
                                   unlikely(is_write_backward(event)));
 }
 
index 87a2d51..1f236ed 100644 (file)
@@ -454,7 +454,10 @@ static void exit_mm(void)
                mmap_read_unlock(mm);
 
                self.task = current;
-               self.next = xchg(&core_state->dumper.next, &self);
+               if (self.task->flags & PF_SIGNALED)
+                       self.next = xchg(&core_state->dumper.next, &self);
+               else
+                       self.task = NULL;
                /*
                 * Implies mb(), the result of xchg() must be visible
                 * to core_state->dumper.
index 63b3491..b0b1ad9 100644 (file)
@@ -253,7 +253,7 @@ static ssize_t fei_write(struct file *file, const char __user *buffer,
 
        if (copy_from_user(buf, buffer, count)) {
                ret = -EFAULT;
-               goto out;
+               goto out_free;
        }
        buf[count] = '\0';
        sym = strstrip(buf);
@@ -307,8 +307,9 @@ static ssize_t fei_write(struct file *file, const char __user *buffer,
                ret = count;
        }
 out:
-       kfree(buf);
        mutex_unlock(&fei_lock);
+out_free:
+       kfree(buf);
        return ret;
 }
 
index 32083db..6d26638 100644 (file)
@@ -2167,14 +2167,9 @@ static __latent_entropy struct task_struct *copy_process(
        /* ok, now we should be set up.. */
        p->pid = pid_nr(pid);
        if (clone_flags & CLONE_THREAD) {
-               p->exit_signal = -1;
                p->group_leader = current->group_leader;
                p->tgid = current->tgid;
        } else {
-               if (clone_flags & CLONE_PARENT)
-                       p->exit_signal = current->group_leader->exit_signal;
-               else
-                       p->exit_signal = args->exit_signal;
                p->group_leader = p;
                p->tgid = p->pid;
        }
@@ -2218,9 +2213,14 @@ static __latent_entropy struct task_struct *copy_process(
        if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
                p->real_parent = current->real_parent;
                p->parent_exec_id = current->parent_exec_id;
+               if (clone_flags & CLONE_THREAD)
+                       p->exit_signal = -1;
+               else
+                       p->exit_signal = current->group_leader->exit_signal;
        } else {
                p->real_parent = current;
                p->parent_exec_id = current->self_exec_id;
+               p->exit_signal = args->exit_signal;
        }
 
        klp_copy_process(p);
index f8614ef..00259c7 100644 (file)
@@ -788,8 +788,9 @@ static void put_pi_state(struct futex_pi_state *pi_state)
         */
        if (pi_state->owner) {
                struct task_struct *owner;
+               unsigned long flags;
 
-               raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
+               raw_spin_lock_irqsave(&pi_state->pi_mutex.wait_lock, flags);
                owner = pi_state->owner;
                if (owner) {
                        raw_spin_lock(&owner->pi_lock);
@@ -797,7 +798,7 @@ static void put_pi_state(struct futex_pi_state *pi_state)
                        raw_spin_unlock(&owner->pi_lock);
                }
                rt_mutex_proxy_unlock(&pi_state->pi_mutex, owner);
-               raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
+               raw_spin_unlock_irqrestore(&pi_state->pi_mutex.wait_lock, flags);
        }
 
        if (current->pi_state_cache) {
@@ -2380,10 +2381,22 @@ retry:
                }
 
                /*
-                * Since we just failed the trylock; there must be an owner.
+                * The trylock just failed, so either there is an owner or
+                * there is a higher priority waiter than this one.
                 */
                newowner = rt_mutex_owner(&pi_state->pi_mutex);
-               BUG_ON(!newowner);
+               /*
+                * If the higher priority waiter has not yet taken over the
+                * rtmutex then newowner is NULL. We can't return here with
+                * that state because it's inconsistent vs. the user space
+                * state. So drop the locks and try again. It's a valid
+                * situation and not any different from the other retry
+                * conditions.
+                */
+               if (unlikely(!newowner)) {
+                       err = -EAGAIN;
+                       goto handle_err;
+               }
        } else {
                WARN_ON_ONCE(argowner != current);
                if (oldowner == current) {
index ce76f49..396ebae 100644 (file)
@@ -225,8 +225,7 @@ static long hung_timeout_jiffies(unsigned long last_checked,
  * Process updating of timeout sysctl
  */
 int proc_dohung_task_timeout_secs(struct ctl_table *table, int write,
-                                 void __user *buffer,
-                                 size_t *lenp, loff_t *ppos)
+                                 void *buffer, size_t *lenp, loff_t *ppos)
 {
        int ret;
 
index 10a5aff..164a031 100644 (file)
@@ -82,6 +82,7 @@ config IRQ_FASTEOI_HIERARCHY_HANDLERS
 # Generic IRQ IPI support
 config GENERIC_IRQ_IPI
        bool
+       select IRQ_DOMAIN_HIERARCHY
 
 # Generic MSI interrupt support
 config GENERIC_MSI_IRQ
index 8a12a25..41fdbb7 100644 (file)
@@ -1249,7 +1249,13 @@ __acquires(hlist_lock)
 
        *head = &kretprobe_inst_table[hash];
        hlist_lock = kretprobe_table_lock_ptr(hash);
-       raw_spin_lock_irqsave(hlist_lock, *flags);
+       /*
+        * Nested is a workaround that will soon not be needed.
+        * There's other protections that make sure the same lock
+        * is not taken on the same CPU that lockdep is unaware of.
+        * Differentiate when it is taken in NMI context.
+        */
+       raw_spin_lock_irqsave_nested(hlist_lock, *flags, !!in_nmi());
 }
 NOKPROBE_SYMBOL(kretprobe_hash_lock);
 
@@ -1258,7 +1264,13 @@ static void kretprobe_table_lock(unsigned long hash,
 __acquires(hlist_lock)
 {
        raw_spinlock_t *hlist_lock = kretprobe_table_lock_ptr(hash);
-       raw_spin_lock_irqsave(hlist_lock, *flags);
+       /*
+        * Nested is a workaround that will soon not be needed.
+        * There's other protections that make sure the same lock
+        * is not taken on the same CPU that lockdep is unaware of.
+        * Differentiate when it is taken in NMI context.
+        */
+       raw_spin_lock_irqsave_nested(hlist_lock, *flags, !!in_nmi());
 }
 NOKPROBE_SYMBOL(kretprobe_table_lock);
 
@@ -2028,7 +2040,12 @@ static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs)
 
        /* TODO: consider to only swap the RA after the last pre_handler fired */
        hash = hash_ptr(current, KPROBE_HASH_BITS);
-       raw_spin_lock_irqsave(&rp->lock, flags);
+       /*
+        * Nested is a workaround that will soon not be needed.
+        * There's other protections that make sure the same lock
+        * is not taken on the same CPU that lockdep is unaware of.
+        */
+       raw_spin_lock_irqsave_nested(&rp->lock, flags, 1);
        if (!hlist_empty(&rp->free_instances)) {
                ri = hlist_entry(rp->free_instances.first,
                                struct kretprobe_instance, hlist);
@@ -2039,7 +2056,7 @@ static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs)
                ri->task = current;
 
                if (rp->entry_handler && rp->entry_handler(ri, regs)) {
-                       raw_spin_lock_irqsave(&rp->lock, flags);
+                       raw_spin_lock_irqsave_nested(&rp->lock, flags, 1);
                        hlist_add_head(&ri->hlist, &rp->free_instances);
                        raw_spin_unlock_irqrestore(&rp->lock, flags);
                        return 0;
index e29773c..933a625 100644 (file)
@@ -897,7 +897,8 @@ void kthread_delayed_work_timer_fn(struct timer_list *t)
        /* Move the work from worker->delayed_work_list. */
        WARN_ON_ONCE(list_empty(&work->node));
        list_del_init(&work->node);
-       kthread_insert_work(worker, work, &worker->work_list);
+       if (!work->canceling)
+               kthread_insert_work(worker, work, &worker->work_list);
 
        raw_spin_unlock_irqrestore(&worker->lock, flags);
 }
index b71ad8d..c1418b4 100644 (file)
@@ -108,19 +108,21 @@ static inline void lockdep_lock(void)
 {
        DEBUG_LOCKS_WARN_ON(!irqs_disabled());
 
+       __this_cpu_inc(lockdep_recursion);
        arch_spin_lock(&__lock);
        __owner = current;
-       __this_cpu_inc(lockdep_recursion);
 }
 
 static inline void lockdep_unlock(void)
 {
+       DEBUG_LOCKS_WARN_ON(!irqs_disabled());
+
        if (debug_locks && DEBUG_LOCKS_WARN_ON(__owner != current))
                return;
 
-       __this_cpu_dec(lockdep_recursion);
        __owner = NULL;
        arch_spin_unlock(&__lock);
+       __this_cpu_dec(lockdep_recursion);
 }
 
 static inline bool lockdep_assert_locked(void)
@@ -2765,7 +2767,9 @@ print_deadlock_bug(struct task_struct *curr, struct held_lock *prev,
  * (Note that this has to be done separately, because the graph cannot
  * detect such classes of deadlocks.)
  *
- * Returns: 0 on deadlock detected, 1 on OK, 2 on recursive read
+ * Returns: 0 on deadlock detected, 1 on OK, 2 if another lock with the same
+ * lock class is held but nest_lock is also held, i.e. we rely on the
+ * nest_lock to avoid the deadlock.
  */
 static int
 check_deadlock(struct task_struct *curr, struct held_lock *next)
@@ -2788,7 +2792,7 @@ check_deadlock(struct task_struct *curr, struct held_lock *next)
                 * lock class (i.e. read_lock(lock)+read_lock(lock)):
                 */
                if ((next->read == 2) && prev->read)
-                       return 2;
+                       continue;
 
                /*
                 * We're holding the nest_lock, which serializes this lock's
@@ -3592,16 +3596,13 @@ static int validate_chain(struct task_struct *curr,
 
                if (!ret)
                        return 0;
-               /*
-                * Mark recursive read, as we jump over it when
-                * building dependencies (just like we jump over
-                * trylock entries):
-                */
-               if (ret == 2)
-                       hlock->read = 2;
                /*
                 * Add dependency only if this lock is not the head
-                * of the chain, and if it's not a secondary read-lock:
+                * of the chain, and if the new lock introduces no more
+                * lock dependency (because we already hold a lock with the
+                * same lock class) nor deadlock (because the nest_lock
+                * serializes nesting locks), see the comments for
+                * check_deadlock().
                 */
                if (!chain_head && ret != 2) {
                        if (!check_prevs_add(curr, hlock))
index 396142e..332736a 100644 (file)
@@ -605,7 +605,8 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
                panic("panic_on_warn set ...\n");
        }
 
-       dump_stack();
+       if (!regs)
+               dump_stack();
 
        print_irqtrace_events(current);
 
index 43d6179..79de129 100644 (file)
@@ -264,17 +264,11 @@ static int ptrace_check_attach(struct task_struct *child, bool ignore_state)
        return ret;
 }
 
-static bool ptrace_has_cap(const struct cred *cred, struct user_namespace *ns,
-                          unsigned int mode)
+static bool ptrace_has_cap(struct user_namespace *ns, unsigned int mode)
 {
-       int ret;
-
        if (mode & PTRACE_MODE_NOAUDIT)
-               ret = security_capable(cred, ns, CAP_SYS_PTRACE, CAP_OPT_NOAUDIT);
-       else
-               ret = security_capable(cred, ns, CAP_SYS_PTRACE, CAP_OPT_NONE);
-
-       return ret == 0;
+               return ns_capable_noaudit(ns, CAP_SYS_PTRACE);
+       return ns_capable(ns, CAP_SYS_PTRACE);
 }
 
 /* Returns 0 on success, -errno on denial. */
@@ -326,7 +320,7 @@ static int __ptrace_may_access(struct task_struct *task, unsigned int mode)
            gid_eq(caller_gid, tcred->sgid) &&
            gid_eq(caller_gid, tcred->gid))
                goto ok;
-       if (ptrace_has_cap(cred, tcred->user_ns, mode))
+       if (ptrace_has_cap(tcred->user_ns, mode))
                goto ok;
        rcu_read_unlock();
        return -EPERM;
@@ -345,7 +339,7 @@ ok:
        mm = task->mm;
        if (mm &&
            ((get_dumpable(mm) != SUID_DUMP_USER) &&
-            !ptrace_has_cap(cred, mm->user_ns, mode)))
+            !ptrace_has_cap(mm->user_ns, mode)))
            return -EPERM;
 
        return security_ptrace_access_check(task, mode);
index 2a52f42..bd04b09 100644 (file)
@@ -4077,7 +4077,6 @@ void rcu_cpu_starting(unsigned int cpu)
        smp_mb(); /* Ensure RCU read-side usage follows above initialization. */
 }
 
-#ifdef CONFIG_HOTPLUG_CPU
 /*
  * The outgoing function has no further need of RCU, so remove it from
  * the rcu_node tree's ->qsmaskinitnext bit masks.
@@ -4117,6 +4116,7 @@ void rcu_report_dead(unsigned int cpu)
        rdp->cpu_started = false;
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
 /*
  * The outgoing CPU has just passed through the dying-idle state, and we
  * are being invoked from the CPU that was IPIed to continue the offline
index 0fde39b..ca21d28 100644 (file)
@@ -249,13 +249,16 @@ static bool check_slow_task(struct task_struct *t, void *arg)
 
 /*
  * Scan the current list of tasks blocked within RCU read-side critical
- * sections, printing out the tid of each.
+ * sections, printing out the tid of each of the first few of them.
  */
-static int rcu_print_task_stall(struct rcu_node *rnp)
+static int rcu_print_task_stall(struct rcu_node *rnp, unsigned long flags)
+       __releases(rnp->lock)
 {
+       int i = 0;
        int ndetected = 0;
        struct rcu_stall_chk_rdr rscr;
        struct task_struct *t;
+       struct task_struct *ts[8];
 
        if (!rcu_preempt_blocked_readers_cgp(rnp))
                return 0;
@@ -264,6 +267,14 @@ static int rcu_print_task_stall(struct rcu_node *rnp)
        t = list_entry(rnp->gp_tasks->prev,
                       struct task_struct, rcu_node_entry);
        list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry) {
+               get_task_struct(t);
+               ts[i++] = t;
+               if (i >= ARRAY_SIZE(ts))
+                       break;
+       }
+       raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
+       for (i--; i; i--) {
+               t = ts[i];
                if (!try_invoke_on_locked_down_task(t, check_slow_task, &rscr))
                        pr_cont(" P%d", t->pid);
                else
@@ -273,6 +284,7 @@ static int rcu_print_task_stall(struct rcu_node *rnp)
                                ".q"[rscr.rs.b.need_qs],
                                ".e"[rscr.rs.b.exp_hint],
                                ".l"[rscr.on_blkd_list]);
+               put_task_struct(t);
                ndetected++;
        }
        pr_cont("\n");
@@ -293,8 +305,9 @@ static void rcu_print_detail_task_stall_rnp(struct rcu_node *rnp)
  * Because preemptible RCU does not exist, we never have to check for
  * tasks blocked within RCU read-side critical sections.
  */
-static int rcu_print_task_stall(struct rcu_node *rnp)
+static int rcu_print_task_stall(struct rcu_node *rnp, unsigned long flags)
 {
+       raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
        return 0;
 }
 #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
@@ -472,7 +485,6 @@ static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps)
        pr_err("INFO: %s detected stalls on CPUs/tasks:\n", rcu_state.name);
        rcu_for_each_leaf_node(rnp) {
                raw_spin_lock_irqsave_rcu_node(rnp, flags);
-               ndetected += rcu_print_task_stall(rnp);
                if (rnp->qsmask != 0) {
                        for_each_leaf_node_possible_cpu(rnp, cpu)
                                if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu)) {
@@ -480,7 +492,7 @@ static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps)
                                        ndetected++;
                                }
                }
-               raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
+               ndetected += rcu_print_task_stall(rnp, flags); // Releases rnp->lock.
        }
 
        for_each_possible_cpu(cpu)
index e7b78d5..af6f23d 100644 (file)
@@ -551,22 +551,22 @@ static int __init reboot_setup(char *str)
                        break;
 
                case 's':
-               {
-                       int rc;
-
-                       if (isdigit(*(str+1))) {
-                               rc = kstrtoint(str+1, 0, &reboot_cpu);
-                               if (rc)
-                                       return rc;
-                       } else if (str[1] == 'm' && str[2] == 'p' &&
-                                  isdigit(*(str+3))) {
-                               rc = kstrtoint(str+3, 0, &reboot_cpu);
-                               if (rc)
-                                       return rc;
-                       } else
+                       if (isdigit(*(str+1)))
+                               reboot_cpu = simple_strtoul(str+1, NULL, 0);
+                       else if (str[1] == 'm' && str[2] == 'p' &&
+                                                       isdigit(*(str+3)))
+                               reboot_cpu = simple_strtoul(str+3, NULL, 0);
+                       else
                                *mode = REBOOT_SOFT;
+                       if (reboot_cpu >= num_possible_cpus()) {
+                               pr_err("Ignoring the CPU number in reboot= option. "
+                                      "CPU %d exceeds possible cpu number %d\n",
+                                      reboot_cpu, num_possible_cpus());
+                               reboot_cpu = 0;
+                               break;
+                       }
                        break;
-               }
+
                case 'g':
                        *mode = REBOOT_GPIO;
                        break;
index d2003a7..e7e4534 100644 (file)
@@ -2501,7 +2501,12 @@ ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags,
 #ifdef CONFIG_SMP
        if (wake_flags & WF_MIGRATED)
                en_flags |= ENQUEUE_MIGRATED;
+       else
 #endif
+       if (p->in_iowait) {
+               delayacct_blkio_end(p);
+               atomic_dec(&task_rq(p)->nr_iowait);
+       }
 
        activate_task(rq, p, en_flags);
        ttwu_do_wakeup(rq, p, wake_flags, rf);
@@ -2888,11 +2893,6 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
        if (READ_ONCE(p->on_rq) && ttwu_runnable(p, wake_flags))
                goto unlock;
 
-       if (p->in_iowait) {
-               delayacct_blkio_end(p);
-               atomic_dec(&task_rq(p)->nr_iowait);
-       }
-
 #ifdef CONFIG_SMP
        /*
         * Ensure we load p->on_cpu _after_ p->on_rq, otherwise it would be
@@ -2963,6 +2963,11 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
 
        cpu = select_task_rq(p, p->wake_cpu, SD_BALANCE_WAKE, wake_flags);
        if (task_cpu(p) != cpu) {
+               if (p->in_iowait) {
+                       delayacct_blkio_end(p);
+                       atomic_dec(&task_rq(p)->nr_iowait);
+               }
+
                wake_flags |= WF_MIGRATED;
                psi_ttwu_dequeue(p);
                set_task_cpu(p, cpu);
@@ -4907,20 +4912,21 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
                if (!dl_prio(p->normal_prio) ||
                    (pi_task && dl_prio(pi_task->prio) &&
                     dl_entity_preempt(&pi_task->dl, &p->dl))) {
-                       p->dl.dl_boosted = 1;
+                       p->dl.pi_se = pi_task->dl.pi_se;
                        queue_flag |= ENQUEUE_REPLENISH;
-               } else
-                       p->dl.dl_boosted = 0;
+               } else {
+                       p->dl.pi_se = &p->dl;
+               }
                p->sched_class = &dl_sched_class;
        } else if (rt_prio(prio)) {
                if (dl_prio(oldprio))
-                       p->dl.dl_boosted = 0;
+                       p->dl.pi_se = &p->dl;
                if (oldprio < prio)
                        queue_flag |= ENQUEUE_HEAD;
                p->sched_class = &rt_sched_class;
        } else {
                if (dl_prio(oldprio))
-                       p->dl.dl_boosted = 0;
+                       p->dl.pi_se = &p->dl;
                if (rt_prio(oldprio))
                        p->rt.timeout = 0;
                p->sched_class = &fair_sched_class;
index c03a577..97d318b 100644 (file)
@@ -102,9 +102,12 @@ static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time)
 static bool sugov_update_next_freq(struct sugov_policy *sg_policy, u64 time,
                                   unsigned int next_freq)
 {
-       if (sg_policy->next_freq == next_freq &&
-           !cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS))
-               return false;
+       if (!sg_policy->need_freq_update) {
+               if (sg_policy->next_freq == next_freq)
+                       return false;
+       } else {
+               sg_policy->need_freq_update = cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS);
+       }
 
        sg_policy->next_freq = next_freq;
        sg_policy->last_freq_update_time = time;
@@ -162,11 +165,9 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy,
 
        freq = map_util_freq(util, freq, max);
 
-       if (freq == sg_policy->cached_raw_freq && !sg_policy->need_freq_update &&
-           !cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS))
+       if (freq == sg_policy->cached_raw_freq && !sg_policy->need_freq_update)
                return sg_policy->next_freq;
 
-       sg_policy->need_freq_update = false;
        sg_policy->cached_raw_freq = freq;
        return cpufreq_driver_resolve_freq(policy, freq);
 }
@@ -442,7 +443,6 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
        struct sugov_policy *sg_policy = sg_cpu->sg_policy;
        unsigned long util, max;
        unsigned int next_f;
-       bool busy;
        unsigned int cached_freq = sg_policy->cached_raw_freq;
 
        sugov_iowait_boost(sg_cpu, time, flags);
@@ -453,9 +453,6 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
        if (!sugov_should_update_freq(sg_policy, time))
                return;
 
-       /* Limits may have changed, don't skip frequency update */
-       busy = !sg_policy->need_freq_update && sugov_cpu_is_busy(sg_cpu);
-
        util = sugov_get_util(sg_cpu);
        max = sg_cpu->max;
        util = sugov_iowait_apply(sg_cpu, time, util, max);
@@ -464,7 +461,7 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
         * Do not reduce the frequency if the CPU has not been idle
         * recently, as the reduction is likely to be premature then.
         */
-       if (busy && next_f < sg_policy->next_freq) {
+       if (sugov_cpu_is_busy(sg_cpu) && next_f < sg_policy->next_freq) {
                next_f = sg_policy->next_freq;
 
                /* Restore cached freq as next_freq has changed */
@@ -829,9 +826,10 @@ static int sugov_start(struct cpufreq_policy *policy)
        sg_policy->next_freq                    = 0;
        sg_policy->work_in_progress             = false;
        sg_policy->limits_changed               = false;
-       sg_policy->need_freq_update             = false;
        sg_policy->cached_raw_freq              = 0;
 
+       sg_policy->need_freq_update = cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS);
+
        for_each_cpu(cpu, policy->cpus) {
                struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu);
 
@@ -883,7 +881,7 @@ static void sugov_limits(struct cpufreq_policy *policy)
 struct cpufreq_governor schedutil_gov = {
        .name                   = "schedutil",
        .owner                  = THIS_MODULE,
-       .dynamic_switching      = true,
+       .flags                  = CPUFREQ_GOV_DYNAMIC_SWITCHING,
        .init                   = sugov_init,
        .exit                   = sugov_exit,
        .start                  = sugov_start,
index f232305..1d3c972 100644 (file)
@@ -43,6 +43,28 @@ static inline int on_dl_rq(struct sched_dl_entity *dl_se)
        return !RB_EMPTY_NODE(&dl_se->rb_node);
 }
 
+#ifdef CONFIG_RT_MUTEXES
+static inline struct sched_dl_entity *pi_of(struct sched_dl_entity *dl_se)
+{
+       return dl_se->pi_se;
+}
+
+static inline bool is_dl_boosted(struct sched_dl_entity *dl_se)
+{
+       return pi_of(dl_se) != dl_se;
+}
+#else
+static inline struct sched_dl_entity *pi_of(struct sched_dl_entity *dl_se)
+{
+       return dl_se;
+}
+
+static inline bool is_dl_boosted(struct sched_dl_entity *dl_se)
+{
+       return false;
+}
+#endif
+
 #ifdef CONFIG_SMP
 static inline struct dl_bw *dl_bw_of(int i)
 {
@@ -698,7 +720,7 @@ static inline void setup_new_dl_entity(struct sched_dl_entity *dl_se)
        struct dl_rq *dl_rq = dl_rq_of_se(dl_se);
        struct rq *rq = rq_of_dl_rq(dl_rq);
 
-       WARN_ON(dl_se->dl_boosted);
+       WARN_ON(is_dl_boosted(dl_se));
        WARN_ON(dl_time_before(rq_clock(rq), dl_se->deadline));
 
        /*
@@ -736,21 +758,20 @@ static inline void setup_new_dl_entity(struct sched_dl_entity *dl_se)
  * could happen are, typically, a entity voluntarily trying to overcome its
  * runtime, or it just underestimated it during sched_setattr().
  */
-static void replenish_dl_entity(struct sched_dl_entity *dl_se,
-                               struct sched_dl_entity *pi_se)
+static void replenish_dl_entity(struct sched_dl_entity *dl_se)
 {
        struct dl_rq *dl_rq = dl_rq_of_se(dl_se);
        struct rq *rq = rq_of_dl_rq(dl_rq);
 
-       BUG_ON(pi_se->dl_runtime <= 0);
+       BUG_ON(pi_of(dl_se)->dl_runtime <= 0);
 
        /*
         * This could be the case for a !-dl task that is boosted.
         * Just go with full inherited parameters.
         */
        if (dl_se->dl_deadline == 0) {
-               dl_se->deadline = rq_clock(rq) + pi_se->dl_deadline;
-               dl_se->runtime = pi_se->dl_runtime;
+               dl_se->deadline = rq_clock(rq) + pi_of(dl_se)->dl_deadline;
+               dl_se->runtime = pi_of(dl_se)->dl_runtime;
        }
 
        if (dl_se->dl_yielded && dl_se->runtime > 0)
@@ -763,8 +784,8 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se,
         * arbitrary large.
         */
        while (dl_se->runtime <= 0) {
-               dl_se->deadline += pi_se->dl_period;
-               dl_se->runtime += pi_se->dl_runtime;
+               dl_se->deadline += pi_of(dl_se)->dl_period;
+               dl_se->runtime += pi_of(dl_se)->dl_runtime;
        }
 
        /*
@@ -778,8 +799,8 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se,
         */
        if (dl_time_before(dl_se->deadline, rq_clock(rq))) {
                printk_deferred_once("sched: DL replenish lagged too much\n");
-               dl_se->deadline = rq_clock(rq) + pi_se->dl_deadline;
-               dl_se->runtime = pi_se->dl_runtime;
+               dl_se->deadline = rq_clock(rq) + pi_of(dl_se)->dl_deadline;
+               dl_se->runtime = pi_of(dl_se)->dl_runtime;
        }
 
        if (dl_se->dl_yielded)
@@ -812,8 +833,7 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se,
  * task with deadline equal to period this is the same of using
  * dl_period instead of dl_deadline in the equation above.
  */
-static bool dl_entity_overflow(struct sched_dl_entity *dl_se,
-                              struct sched_dl_entity *pi_se, u64 t)
+static bool dl_entity_overflow(struct sched_dl_entity *dl_se, u64 t)
 {
        u64 left, right;
 
@@ -835,9 +855,9 @@ static bool dl_entity_overflow(struct sched_dl_entity *dl_se,
         * of anything below microseconds resolution is actually fiction
         * (but still we want to give the user that illusion >;).
         */
-       left = (pi_se->dl_deadline >> DL_SCALE) * (dl_se->runtime >> DL_SCALE);
+       left = (pi_of(dl_se)->dl_deadline >> DL_SCALE) * (dl_se->runtime >> DL_SCALE);
        right = ((dl_se->deadline - t) >> DL_SCALE) *
-               (pi_se->dl_runtime >> DL_SCALE);
+               (pi_of(dl_se)->dl_runtime >> DL_SCALE);
 
        return dl_time_before(right, left);
 }
@@ -922,24 +942,23 @@ static inline bool dl_is_implicit(struct sched_dl_entity *dl_se)
  * Please refer to the comments update_dl_revised_wakeup() function to find
  * more about the Revised CBS rule.
  */
-static void update_dl_entity(struct sched_dl_entity *dl_se,
-                            struct sched_dl_entity *pi_se)
+static void update_dl_entity(struct sched_dl_entity *dl_se)
 {
        struct dl_rq *dl_rq = dl_rq_of_se(dl_se);
        struct rq *rq = rq_of_dl_rq(dl_rq);
 
        if (dl_time_before(dl_se->deadline, rq_clock(rq)) ||
-           dl_entity_overflow(dl_se, pi_se, rq_clock(rq))) {
+           dl_entity_overflow(dl_se, rq_clock(rq))) {
 
                if (unlikely(!dl_is_implicit(dl_se) &&
                             !dl_time_before(dl_se->deadline, rq_clock(rq)) &&
-                            !dl_se->dl_boosted)){
+                            !is_dl_boosted(dl_se))) {
                        update_dl_revised_wakeup(dl_se, rq);
                        return;
                }
 
-               dl_se->deadline = rq_clock(rq) + pi_se->dl_deadline;
-               dl_se->runtime = pi_se->dl_runtime;
+               dl_se->deadline = rq_clock(rq) + pi_of(dl_se)->dl_deadline;
+               dl_se->runtime = pi_of(dl_se)->dl_runtime;
        }
 }
 
@@ -1038,7 +1057,7 @@ static enum hrtimer_restart dl_task_timer(struct hrtimer *timer)
         * The task might have been boosted by someone else and might be in the
         * boosting/deboosting path, its not throttled.
         */
-       if (dl_se->dl_boosted)
+       if (is_dl_boosted(dl_se))
                goto unlock;
 
        /*
@@ -1066,7 +1085,7 @@ static enum hrtimer_restart dl_task_timer(struct hrtimer *timer)
         * but do not enqueue -- wait for our wakeup to do that.
         */
        if (!task_on_rq_queued(p)) {
-               replenish_dl_entity(dl_se, dl_se);
+               replenish_dl_entity(dl_se);
                goto unlock;
        }
 
@@ -1156,7 +1175,7 @@ static inline void dl_check_constrained_dl(struct sched_dl_entity *dl_se)
 
        if (dl_time_before(dl_se->deadline, rq_clock(rq)) &&
            dl_time_before(rq_clock(rq), dl_next_period(dl_se))) {
-               if (unlikely(dl_se->dl_boosted || !start_dl_timer(p)))
+               if (unlikely(is_dl_boosted(dl_se) || !start_dl_timer(p)))
                        return;
                dl_se->dl_throttled = 1;
                if (dl_se->runtime > 0)
@@ -1287,7 +1306,7 @@ throttle:
                        dl_se->dl_overrun = 1;
 
                __dequeue_task_dl(rq, curr, 0);
-               if (unlikely(dl_se->dl_boosted || !start_dl_timer(curr)))
+               if (unlikely(is_dl_boosted(dl_se) || !start_dl_timer(curr)))
                        enqueue_task_dl(rq, curr, ENQUEUE_REPLENISH);
 
                if (!is_leftmost(curr, &rq->dl))
@@ -1481,8 +1500,7 @@ static void __dequeue_dl_entity(struct sched_dl_entity *dl_se)
 }
 
 static void
-enqueue_dl_entity(struct sched_dl_entity *dl_se,
-                 struct sched_dl_entity *pi_se, int flags)
+enqueue_dl_entity(struct sched_dl_entity *dl_se, int flags)
 {
        BUG_ON(on_dl_rq(dl_se));
 
@@ -1493,9 +1511,9 @@ enqueue_dl_entity(struct sched_dl_entity *dl_se,
         */
        if (flags & ENQUEUE_WAKEUP) {
                task_contending(dl_se, flags);
-               update_dl_entity(dl_se, pi_se);
+               update_dl_entity(dl_se);
        } else if (flags & ENQUEUE_REPLENISH) {
-               replenish_dl_entity(dl_se, pi_se);
+               replenish_dl_entity(dl_se);
        } else if ((flags & ENQUEUE_RESTORE) &&
                  dl_time_before(dl_se->deadline,
                                 rq_clock(rq_of_dl_rq(dl_rq_of_se(dl_se))))) {
@@ -1512,19 +1530,7 @@ static void dequeue_dl_entity(struct sched_dl_entity *dl_se)
 
 static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags)
 {
-       struct task_struct *pi_task = rt_mutex_get_top_task(p);
-       struct sched_dl_entity *pi_se = &p->dl;
-
-       /*
-        * Use the scheduling parameters of the top pi-waiter task if:
-        * - we have a top pi-waiter which is a SCHED_DEADLINE task AND
-        * - our dl_boosted is set (i.e. the pi-waiter's (absolute) deadline is
-        *   smaller than our deadline OR we are a !SCHED_DEADLINE task getting
-        *   boosted due to a SCHED_DEADLINE pi-waiter).
-        * Otherwise we keep our runtime and deadline.
-        */
-       if (pi_task && dl_prio(pi_task->normal_prio) && p->dl.dl_boosted) {
-               pi_se = &pi_task->dl;
+       if (is_dl_boosted(&p->dl)) {
                /*
                 * Because of delays in the detection of the overrun of a
                 * thread's runtime, it might be the case that a thread
@@ -1557,7 +1563,7 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags)
                 * the throttle.
                 */
                p->dl.dl_throttled = 0;
-               BUG_ON(!p->dl.dl_boosted || flags != ENQUEUE_REPLENISH);
+               BUG_ON(!is_dl_boosted(&p->dl) || flags != ENQUEUE_REPLENISH);
                return;
        }
 
@@ -1594,7 +1600,7 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags)
                return;
        }
 
-       enqueue_dl_entity(&p->dl, pi_se, flags);
+       enqueue_dl_entity(&p->dl, flags);
 
        if (!task_current(rq, p) && p->nr_cpus_allowed > 1)
                enqueue_pushable_dl_task(rq, p);
@@ -2787,11 +2793,14 @@ void __dl_clear_params(struct task_struct *p)
        dl_se->dl_bw                    = 0;
        dl_se->dl_density               = 0;
 
-       dl_se->dl_boosted               = 0;
        dl_se->dl_throttled             = 0;
        dl_se->dl_yielded               = 0;
        dl_se->dl_non_contending        = 0;
        dl_se->dl_overrun               = 0;
+
+#ifdef CONFIG_RT_MUTEXES
+       dl_se->pi_se                    = dl_se;
+#endif
 }
 
 bool dl_param_changed(struct task_struct *p, const struct sched_attr *attr)
index 0655524..2357921 100644 (file)
@@ -251,7 +251,7 @@ static int sd_ctl_doflags(struct ctl_table *table, int write,
        unsigned long flags = *(unsigned long *)table->data;
        size_t data_size = 0;
        size_t len = 0;
-       char *tmp;
+       char *tmp, *buf;
        int idx;
 
        if (write)
@@ -269,17 +269,17 @@ static int sd_ctl_doflags(struct ctl_table *table, int write,
                return 0;
        }
 
-       tmp = kcalloc(data_size + 1, sizeof(*tmp), GFP_KERNEL);
-       if (!tmp)
+       buf = kcalloc(data_size + 1, sizeof(*buf), GFP_KERNEL);
+       if (!buf)
                return -ENOMEM;
 
        for_each_set_bit(idx, &flags, __SD_FLAG_CNT) {
                char *name = sd_flag_debug[idx].name;
 
-               len += snprintf(tmp + len, strlen(name) + 2, "%s ", name);
+               len += snprintf(buf + len, strlen(name) + 2, "%s ", name);
        }
 
-       tmp += *ppos;
+       tmp = buf + *ppos;
        len -= *ppos;
 
        if (len > *lenp)
@@ -294,7 +294,7 @@ static int sd_ctl_doflags(struct ctl_table *table, int write,
        *lenp = len;
        *ppos += len;
 
-       kfree(tmp);
+       kfree(buf);
 
        return 0;
 }
index 290f9e3..ae7ceba 100644 (file)
@@ -5477,6 +5477,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
        struct cfs_rq *cfs_rq;
        struct sched_entity *se = &p->se;
        int idle_h_nr_running = task_has_idle_policy(p);
+       int task_new = !(flags & ENQUEUE_WAKEUP);
 
        /*
         * The code below (indirectly) updates schedutil which looks at
@@ -5549,7 +5550,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
         * into account, but that is not straightforward to implement,
         * and the following generally works well enough in practice.
         */
-       if (flags & ENQUEUE_WAKEUP)
+       if (!task_new)
                update_overutilized_status(rq);
 
 enqueue_throttle:
@@ -6172,21 +6173,21 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, int t
 static int
 select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target)
 {
-       unsigned long best_cap = 0;
+       unsigned long task_util, best_cap = 0;
        int cpu, best_cpu = -1;
        struct cpumask *cpus;
 
-       sync_entity_load_avg(&p->se);
-
        cpus = this_cpu_cpumask_var_ptr(select_idle_mask);
        cpumask_and(cpus, sched_domain_span(sd), p->cpus_ptr);
 
+       task_util = uclamp_task_util(p);
+
        for_each_cpu_wrap(cpu, cpus, target) {
                unsigned long cpu_cap = capacity_of(cpu);
 
                if (!available_idle_cpu(cpu) && !sched_idle_cpu(cpu))
                        continue;
-               if (task_fits_capacity(p, cpu_cap))
+               if (fits_capacity(task_util, cpu_cap))
                        return cpu;
 
                if (cpu_cap > best_cap) {
@@ -6198,44 +6199,42 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target)
        return best_cpu;
 }
 
+static inline bool asym_fits_capacity(int task_util, int cpu)
+{
+       if (static_branch_unlikely(&sched_asym_cpucapacity))
+               return fits_capacity(task_util, capacity_of(cpu));
+
+       return true;
+}
+
 /*
  * Try and locate an idle core/thread in the LLC cache domain.
  */
 static int select_idle_sibling(struct task_struct *p, int prev, int target)
 {
        struct sched_domain *sd;
+       unsigned long task_util;
        int i, recent_used_cpu;
 
        /*
-        * For asymmetric CPU capacity systems, our domain of interest is
-        * sd_asym_cpucapacity rather than sd_llc.
+        * On asymmetric system, update task utilization because we will check
+        * that the task fits with cpu's capacity.
         */
        if (static_branch_unlikely(&sched_asym_cpucapacity)) {
-               sd = rcu_dereference(per_cpu(sd_asym_cpucapacity, target));
-               /*
-                * On an asymmetric CPU capacity system where an exclusive
-                * cpuset defines a symmetric island (i.e. one unique
-                * capacity_orig value through the cpuset), the key will be set
-                * but the CPUs within that cpuset will not have a domain with
-                * SD_ASYM_CPUCAPACITY. These should follow the usual symmetric
-                * capacity path.
-                */
-               if (!sd)
-                       goto symmetric;
-
-               i = select_idle_capacity(p, sd, target);
-               return ((unsigned)i < nr_cpumask_bits) ? i : target;
+               sync_entity_load_avg(&p->se);
+               task_util = uclamp_task_util(p);
        }
 
-symmetric:
-       if (available_idle_cpu(target) || sched_idle_cpu(target))
+       if ((available_idle_cpu(target) || sched_idle_cpu(target)) &&
+           asym_fits_capacity(task_util, target))
                return target;
 
        /*
         * If the previous CPU is cache affine and idle, don't be stupid:
         */
        if (prev != target && cpus_share_cache(prev, target) &&
-           (available_idle_cpu(prev) || sched_idle_cpu(prev)))
+           (available_idle_cpu(prev) || sched_idle_cpu(prev)) &&
+           asym_fits_capacity(task_util, prev))
                return prev;
 
        /*
@@ -6258,7 +6257,8 @@ symmetric:
            recent_used_cpu != target &&
            cpus_share_cache(recent_used_cpu, target) &&
            (available_idle_cpu(recent_used_cpu) || sched_idle_cpu(recent_used_cpu)) &&
-           cpumask_test_cpu(p->recent_used_cpu, p->cpus_ptr)) {
+           cpumask_test_cpu(p->recent_used_cpu, p->cpus_ptr) &&
+           asym_fits_capacity(task_util, recent_used_cpu)) {
                /*
                 * Replace recent_used_cpu with prev as it is a potential
                 * candidate for the next wake:
@@ -6267,6 +6267,26 @@ symmetric:
                return recent_used_cpu;
        }
 
+       /*
+        * For asymmetric CPU capacity systems, our domain of interest is
+        * sd_asym_cpucapacity rather than sd_llc.
+        */
+       if (static_branch_unlikely(&sched_asym_cpucapacity)) {
+               sd = rcu_dereference(per_cpu(sd_asym_cpucapacity, target));
+               /*
+                * On an asymmetric CPU capacity system where an exclusive
+                * cpuset defines a symmetric island (i.e. one unique
+                * capacity_orig value through the cpuset), the key will be set
+                * but the CPUs within that cpuset will not have a domain with
+                * SD_ASYM_CPUCAPACITY. These should follow the usual symmetric
+                * capacity path.
+                */
+               if (sd) {
+                       i = select_idle_capacity(p, sd, target);
+                       return ((unsigned)i < nr_cpumask_bits) ? i : target;
+               }
+       }
+
        sd = rcu_dereference(per_cpu(sd_llc, target));
        if (!sd)
                return target;
@@ -9031,7 +9051,8 @@ static inline void calculate_imbalance(struct lb_env *env, struct sd_lb_stats *s
         * emptying busiest.
         */
        if (local->group_type == group_has_spare) {
-               if (busiest->group_type > group_fully_busy) {
+               if ((busiest->group_type > group_fully_busy) &&
+                   !(env->sd->flags & SD_SHARE_PKG_RESOURCES)) {
                        /*
                         * If busiest is overloaded, try to fill spare
                         * capacity. This might end up creating spare capacity
index 8ad7a29..53a7d15 100644 (file)
@@ -38,7 +38,7 @@
 #include <linux/filter.h>
 #include <linux/pid.h>
 #include <linux/ptrace.h>
-#include <linux/security.h>
+#include <linux/capability.h>
 #include <linux/tracehook.h>
 #include <linux/uaccess.h>
 #include <linux/anon_inodes.h>
@@ -558,8 +558,7 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
         * behavior of privileged children.
         */
        if (!task_no_new_privs(current) &&
-           security_capable(current_cred(), current_user_ns(),
-                                    CAP_SYS_ADMIN, CAP_OPT_NOAUDIT) != 0)
+                       !ns_capable_noaudit(current_user_ns(), CAP_SYS_ADMIN))
                return ERR_PTR(-EACCES);
 
        /* Allocate a new seccomp_filter */
index a38b3ed..ef8f2a2 100644 (file)
@@ -391,16 +391,17 @@ static bool task_participate_group_stop(struct task_struct *task)
 
 void task_join_group_stop(struct task_struct *task)
 {
+       unsigned long mask = current->jobctl & JOBCTL_STOP_SIGMASK;
+       struct signal_struct *sig = current->signal;
+
+       if (sig->group_stop_count) {
+               sig->group_stop_count++;
+               mask |= JOBCTL_STOP_CONSUME;
+       } else if (!(sig->flags & SIGNAL_STOP_STOPPED))
+               return;
+
        /* Have the new thread join an on-going signal group stop */
-       unsigned long jobctl = current->jobctl;
-       if (jobctl & JOBCTL_STOP_PENDING) {
-               struct signal_struct *sig = current->signal;
-               unsigned long signr = jobctl & JOBCTL_STOP_SIGMASK;
-               unsigned long gstop = JOBCTL_STOP_PENDING | JOBCTL_STOP_CONSUME;
-               if (task_set_jobctl_pending(task, signr | gstop)) {
-                       sig->group_stop_count++;
-               }
-       }
+       task_set_jobctl_pending(task, mask | JOBCTL_STOP_PENDING);
 }
 
 /*
index 4517c8b..048c655 100644 (file)
@@ -181,6 +181,16 @@ bpf_probe_read_user_str_common(void *dst, u32 size,
 {
        int ret;
 
+       /*
+        * NB: We rely on strncpy_from_user() not copying junk past the NUL
+        * terminator into `dst`.
+        *
+        * strncpy_from_user() does long-sized strides in the fast path. If the
+        * strncpy does not mask out the bytes after the NUL in `unsafe_ptr`,
+        * then there could be junk after the NUL in `dst`. If user takes `dst`
+        * and keys a hash map with it, then semantically identical strings can
+        * occupy multiple entries in the map.
+        */
        ret = strncpy_from_user_nofault(dst, unsafe_ptr, size);
        if (unlikely(ret < 0))
                memset(dst, 0, size);
@@ -1198,7 +1208,7 @@ static int bpf_btf_printf_prepare(struct btf_ptr *ptr, u32 btf_ptr_size,
        *btf = bpf_get_btf_vmlinux();
 
        if (IS_ERR_OR_NULL(*btf))
-               return PTR_ERR(*btf);
+               return IS_ERR(*btf) ? PTR_ERR(*btf) : -EINVAL;
 
        if (ptr->type_id > 0)
                *btf_id = ptr->type_id;
index 7f45fd9..dc83b3f 100644 (file)
@@ -438,14 +438,16 @@ enum {
 };
 /*
  * Used for which event context the event is in.
- *  NMI     = 0
- *  IRQ     = 1
- *  SOFTIRQ = 2
- *  NORMAL  = 3
+ *  TRANSITION = 0
+ *  NMI     = 1
+ *  IRQ     = 2
+ *  SOFTIRQ = 3
+ *  NORMAL  = 4
  *
  * See trace_recursive_lock() comment below for more details.
  */
 enum {
+       RB_CTX_TRANSITION,
        RB_CTX_NMI,
        RB_CTX_IRQ,
        RB_CTX_SOFTIRQ,
@@ -3014,10 +3016,10 @@ rb_wakeups(struct trace_buffer *buffer, struct ring_buffer_per_cpu *cpu_buffer)
  * a bit of overhead in something as critical as function tracing,
  * we use a bitmask trick.
  *
- *  bit 0 =  NMI context
- *  bit 1 =  IRQ context
- *  bit 2 =  SoftIRQ context
- *  bit 3 =  normal context.
+ *  bit 1 =  NMI context
+ *  bit 2 =  IRQ context
+ *  bit 3 =  SoftIRQ context
+ *  bit 4 =  normal context.
  *
  * This works because this is the order of contexts that can
  * preempt other contexts. A SoftIRQ never preempts an IRQ
@@ -3040,6 +3042,30 @@ rb_wakeups(struct trace_buffer *buffer, struct ring_buffer_per_cpu *cpu_buffer)
  * The least significant bit can be cleared this way, and it
  * just so happens that it is the same bit corresponding to
  * the current context.
+ *
+ * Now the TRANSITION bit breaks the above slightly. The TRANSITION bit
+ * is set when a recursion is detected at the current context, and if
+ * the TRANSITION bit is already set, it will fail the recursion.
+ * This is needed because there's a lag between the changing of
+ * interrupt context and updating the preempt count. In this case,
+ * a false positive will be found. To handle this, one extra recursion
+ * is allowed, and this is done by the TRANSITION bit. If the TRANSITION
+ * bit is already set, then it is considered a recursion and the function
+ * ends. Otherwise, the TRANSITION bit is set, and that bit is returned.
+ *
+ * On the trace_recursive_unlock(), the TRANSITION bit will be the first
+ * to be cleared. Even if it wasn't the context that set it. That is,
+ * if an interrupt comes in while NORMAL bit is set and the ring buffer
+ * is called before preempt_count() is updated, since the check will
+ * be on the NORMAL bit, the TRANSITION bit will then be set. If an
+ * NMI then comes in, it will set the NMI bit, but when the NMI code
+ * does the trace_recursive_unlock() it will clear the TRANSTION bit
+ * and leave the NMI bit set. But this is fine, because the interrupt
+ * code that set the TRANSITION bit will then clear the NMI bit when it
+ * calls trace_recursive_unlock(). If another NMI comes in, it will
+ * set the TRANSITION bit and continue.
+ *
+ * Note: The TRANSITION bit only handles a single transition between context.
  */
 
 static __always_inline int
@@ -3055,8 +3081,16 @@ trace_recursive_lock(struct ring_buffer_per_cpu *cpu_buffer)
                bit = pc & NMI_MASK ? RB_CTX_NMI :
                        pc & HARDIRQ_MASK ? RB_CTX_IRQ : RB_CTX_SOFTIRQ;
 
-       if (unlikely(val & (1 << (bit + cpu_buffer->nest))))
-               return 1;
+       if (unlikely(val & (1 << (bit + cpu_buffer->nest)))) {
+               /*
+                * It is possible that this was called by transitioning
+                * between interrupt context, and preempt_count() has not
+                * been updated yet. In this case, use the TRANSITION bit.
+                */
+               bit = RB_CTX_TRANSITION;
+               if (val & (1 << (bit + cpu_buffer->nest)))
+                       return 1;
+       }
 
        val |= (1 << (bit + cpu_buffer->nest));
        cpu_buffer->current_context = val;
@@ -3071,8 +3105,8 @@ trace_recursive_unlock(struct ring_buffer_per_cpu *cpu_buffer)
                cpu_buffer->current_context - (1 << cpu_buffer->nest);
 }
 
-/* The recursive locking above uses 4 bits */
-#define NESTED_BITS 4
+/* The recursive locking above uses 5 bits */
+#define NESTED_BITS 5
 
 /**
  * ring_buffer_nest_start - Allow to trace while nested
index 5289717..410cfeb 100644 (file)
@@ -2750,7 +2750,7 @@ trace_event_buffer_lock_reserve(struct trace_buffer **current_rb,
        /*
         * If tracing is off, but we have triggers enabled
         * we still need to look at the event data. Use the temp_buffer
-        * to store the trace event for the tigger to use. It's recusive
+        * to store the trace event for the trigger to use. It's recursive
         * safe and will not be recorded anywhere.
         */
        if (!entry && trace_file->flags & EVENT_FILE_FL_TRIGGER_COND) {
@@ -2952,7 +2952,7 @@ static void __ftrace_trace_stack(struct trace_buffer *buffer,
        stackidx = __this_cpu_inc_return(ftrace_stack_reserve) - 1;
 
        /* This should never happen. If it does, yell once and skip */
-       if (WARN_ON_ONCE(stackidx > FTRACE_KSTACK_NESTING))
+       if (WARN_ON_ONCE(stackidx >= FTRACE_KSTACK_NESTING))
                goto out;
 
        /*
@@ -3132,7 +3132,7 @@ static char *get_trace_buf(void)
 
        /* Interrupts must see nesting incremented before we use the buffer */
        barrier();
-       return &buffer->buffer[buffer->nesting][0];
+       return &buffer->buffer[buffer->nesting - 1][0];
 }
 
 static void put_trace_buf(void)
index f3f5e77..1dadef4 100644 (file)
@@ -637,6 +637,12 @@ enum {
         * function is called to clear it.
         */
        TRACE_GRAPH_NOTRACE_BIT,
+
+       /*
+        * When transitioning between context, the preempt_count() may
+        * not be correct. Allow for a single recursion to cover this case.
+        */
+       TRACE_TRANSITION_BIT,
 };
 
 #define trace_recursion_set(bit)       do { (current)->trace_recursion |= (1<<(bit)); } while (0)
@@ -691,14 +697,27 @@ static __always_inline int trace_test_and_set_recursion(int start, int max)
                return 0;
 
        bit = trace_get_context_bit() + start;
-       if (unlikely(val & (1 << bit)))
-               return -1;
+       if (unlikely(val & (1 << bit))) {
+               /*
+                * It could be that preempt_count has not been updated during
+                * a switch between contexts. Allow for a single recursion.
+                */
+               bit = TRACE_TRANSITION_BIT;
+               if (trace_recursion_test(bit))
+                       return -1;
+               trace_recursion_set(bit);
+               barrier();
+               return bit + 1;
+       }
+
+       /* Normal check passed, clear the transition to allow it again */
+       trace_recursion_clear(TRACE_TRANSITION_BIT);
 
        val |= 1 << bit;
        current->trace_recursion = val;
        barrier();
 
-       return bit;
+       return bit + 1;
 }
 
 static __always_inline void trace_clear_recursion(int bit)
@@ -708,6 +727,7 @@ static __always_inline void trace_clear_recursion(int bit)
        if (!bit)
                return;
 
+       bit--;
        bit = 1 << bit;
        val &= ~bit;
 
index 84b7cab..881df99 100644 (file)
@@ -584,7 +584,7 @@ static struct synth_field *parse_synth_field(int argc, const char **argv,
 {
        struct synth_field *field;
        const char *prefix = NULL, *field_type = argv[0], *field_name, *array;
-       int len, ret = 0;
+       int len, ret = -ENOMEM;
        struct seq_buf s;
        ssize_t size;
 
@@ -617,10 +617,9 @@ static struct synth_field *parse_synth_field(int argc, const char **argv,
                len--;
 
        field->name = kmemdup_nul(field_name, len, GFP_KERNEL);
-       if (!field->name) {
-               ret = -ENOMEM;
+       if (!field->name)
                goto free;
-       }
+
        if (!is_good_name(field->name)) {
                synth_err(SYNTH_ERR_BAD_NAME, errpos(field_name));
                ret = -EINVAL;
@@ -638,10 +637,9 @@ static struct synth_field *parse_synth_field(int argc, const char **argv,
                len += strlen(prefix);
 
        field->type = kzalloc(len, GFP_KERNEL);
-       if (!field->type) {
-               ret = -ENOMEM;
+       if (!field->type)
                goto free;
-       }
+
        seq_buf_init(&s, field->type, len);
        if (prefix)
                seq_buf_puts(&s, prefix);
@@ -653,6 +651,7 @@ static struct synth_field *parse_synth_field(int argc, const char **argv,
        }
        if (WARN_ON_ONCE(!seq_buf_buffer_left(&s)))
                goto free;
+
        s.buffer[s.len] = '\0';
 
        size = synth_field_size(field->type);
@@ -666,10 +665,8 @@ static struct synth_field *parse_synth_field(int argc, const char **argv,
 
                        len = sizeof("__data_loc ") + strlen(field->type) + 1;
                        type = kzalloc(len, GFP_KERNEL);
-                       if (!type) {
-                               ret = -ENOMEM;
+                       if (!type)
                                goto free;
-                       }
 
                        seq_buf_init(&s, type, len);
                        seq_buf_puts(&s, "__data_loc ");
index b5e3496..4738ad4 100644 (file)
@@ -492,8 +492,13 @@ trace_selftest_function_recursion(void)
        unregister_ftrace_function(&test_rec_probe);
 
        ret = -1;
-       if (trace_selftest_recursion_cnt != 1) {
-               pr_cont("*callback not called once (%d)* ",
+       /*
+        * Recursion allows for transitions between context,
+        * and may call the callback twice.
+        */
+       if (trace_selftest_recursion_cnt != 1 &&
+           trace_selftest_recursion_cnt != 2) {
+               pr_cont("*callback not called once (or twice) (%d)* ",
                        trace_selftest_recursion_cnt);
                goto out;
        }
index 5abb5b2..7110906 100644 (file)
@@ -44,8 +44,6 @@ int __read_mostly soft_watchdog_user_enabled = 1;
 int __read_mostly watchdog_thresh = 10;
 static int __read_mostly nmi_watchdog_available;
 
-static struct cpumask watchdog_allowed_mask __read_mostly;
-
 struct cpumask watchdog_cpumask __read_mostly;
 unsigned long *watchdog_cpumask_bits = cpumask_bits(&watchdog_cpumask);
 
@@ -162,6 +160,8 @@ static void lockup_detector_update_enable(void)
 int __read_mostly sysctl_softlockup_all_cpu_backtrace;
 #endif
 
+static struct cpumask watchdog_allowed_mask __read_mostly;
+
 /* Global variables, exported for sysctl */
 unsigned int __read_mostly softlockup_panic =
                        CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE;
index 97d6a57..61ddce2 100644 (file)
@@ -683,7 +683,6 @@ static int __init crc32c_test(void)
 
        /* reduce OS noise */
        local_irq_save(flags);
-       local_irq_disable();
 
        nsec = ktime_get_ns();
        for (i = 0; i < 100; i++) {
@@ -694,7 +693,6 @@ static int __init crc32c_test(void)
        nsec = ktime_get_ns() - nsec;
 
        local_irq_restore(flags);
-       local_irq_enable();
 
        pr_info("crc32c: CRC_LE_BITS = %d\n", CRC_LE_BITS);
 
@@ -768,7 +766,6 @@ static int __init crc32_test(void)
 
        /* reduce OS noise */
        local_irq_save(flags);
-       local_irq_disable();
 
        nsec = ktime_get_ns();
        for (i = 0; i < 100; i++) {
@@ -783,7 +780,6 @@ static int __init crc32_test(void)
        nsec = ktime_get_ns() - nsec;
 
        local_irq_restore(flags);
-       local_irq_enable();
 
        pr_info("crc32: CRC_LE_BITS = %d, CRC_BE BITS = %d\n",
                 CRC_LE_BITS, CRC_BE_BITS);
index 0e2deac..e02f9df 100644 (file)
@@ -8,7 +8,7 @@
 
 #define FONTDATAMAX 9216
 
-static struct font_data fontdata_10x18 = {
+static const struct font_data fontdata_10x18 = {
        { 0, 0, FONTDATAMAX, 0 }, {
        /* 0 0x00 '^@' */
        0x00, 0x00, /* 0000000000 */
index 87da8ac..6e3c4b7 100644 (file)
@@ -3,7 +3,7 @@
 
 #define FONTDATAMAX 2560
 
-static struct font_data fontdata_6x10 = {
+static const struct font_data fontdata_6x10 = {
        { 0, 0, FONTDATAMAX, 0 }, {
        /* 0 0x00 '^@' */
        0x00, /* 00000000 */
index 5e975df..2d22a24 100644 (file)
@@ -9,7 +9,7 @@
 
 #define FONTDATAMAX (11*256)
 
-static struct font_data fontdata_6x11 = {
+static const struct font_data fontdata_6x11 = {
        { 0, 0, FONTDATAMAX, 0 }, {
        /* 0 0x00 '^@' */
        0x00, /* 00000000 */
index 700039a..e7442a0 100644 (file)
@@ -3,7 +3,7 @@
 
 #define FONTDATAMAX 2048
 
-static struct font_data fontdata_6x8 = {
+static const struct font_data fontdata_6x8 = {
        { 0, 0, FONTDATAMAX, 0 }, {
        /* 0 0x00 '^@' */
        0x00, /* 000000 */
index 86d298f..9cc7ae2 100644 (file)
@@ -8,7 +8,7 @@
 
 #define FONTDATAMAX 3584
 
-static struct font_data fontdata_7x14 = {
+static const struct font_data fontdata_7x14 = {
        { 0, 0, FONTDATAMAX, 0 }, {
        /* 0 0x00 '^@' */
        0x00, /* 0000000 */
index 37cedd3..bab25dc 100644 (file)
@@ -10,7 +10,7 @@
 
 #define FONTDATAMAX 4096
 
-static struct font_data fontdata_8x16 = {
+static const struct font_data fontdata_8x16 = {
        { 0, 0, FONTDATAMAX, 0 }, {
        /* 0 0x00 '^@' */
        0x00, /* 00000000 */
index 8ab6955..109d057 100644 (file)
@@ -9,7 +9,7 @@
 
 #define FONTDATAMAX 2048
 
-static struct font_data fontdata_8x8 = {
+static const struct font_data fontdata_8x8 = {
        { 0, 0, FONTDATAMAX, 0 }, {
        /* 0 0x00 '^@' */
        0x00, /* 00000000 */
index 069b3e8..fb395f0 100644 (file)
@@ -5,7 +5,7 @@
 
 #define FONTDATAMAX 2048
 
-static struct font_data acorndata_8x8 = {
+static const struct font_data acorndata_8x8 = {
 { 0, 0, FONTDATAMAX, 0 }, {
 /* 00 */  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ^@ */
 /* 01 */  0x7e, 0x81, 0xa5, 0x81, 0xbd, 0x99, 0x81, 0x7e, /* ^A */
index 1449876..592774a 100644 (file)
@@ -43,7 +43,7 @@ __END__;
 
 #define FONTDATAMAX 1536
 
-static struct font_data fontdata_mini_4x6 = {
+static const struct font_data fontdata_mini_4x6 = {
        { 0, 0, FONTDATAMAX, 0 }, {
        /*{*/
                /*   Char 0: ' '  */
index 32d6555..a6f95eb 100644 (file)
@@ -14,7 +14,7 @@
 
 #define FONTDATAMAX 2048
 
-static struct font_data fontdata_pearl8x8 = {
+static const struct font_data fontdata_pearl8x8 = {
    { 0, 0, FONTDATAMAX, 0 }, {
    /* 0 0x00 '^@' */
    0x00, /* 00000000 */
index 641a6b4..a5b65bd 100644 (file)
@@ -3,7 +3,7 @@
 
 #define FONTDATAMAX 11264
 
-static struct font_data fontdata_sun12x22 = {
+static const struct font_data fontdata_sun12x22 = {
        { 0, 0, FONTDATAMAX, 0 }, {
        /* 0 0x00 '^@' */
        0x00, 0x00, /* 000000000000 */
index 193fe6d..e577e76 100644 (file)
@@ -3,7 +3,7 @@
 
 #define FONTDATAMAX 4096
 
-static struct font_data fontdata_sun8x16 = {
+static const struct font_data fontdata_sun8x16 = {
 { 0, 0, FONTDATAMAX, 0 }, {
 /* */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 /* */ 0x00,0x00,0x7e,0x81,0xa5,0x81,0x81,0xbd,0x99,0x81,0x81,0x7e,0x00,0x00,0x00,0x00,
index 91b9c28..f7c3abb 100644 (file)
@@ -4,7 +4,7 @@
 
 #define FONTDATAMAX 16384
 
-static struct font_data fontdata_ter16x32 = {
+static const struct font_data fontdata_ter16x32 = {
        { 0, 0, FONTDATAMAX, 0 }, {
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x7f, 0xfc, 0x7f, 0xfc,
index e6d5fcc..122d8d0 100644 (file)
@@ -35,17 +35,32 @@ static inline long do_strncpy_from_user(char *dst, const char __user *src,
                goto byte_at_a_time;
 
        while (max >= sizeof(unsigned long)) {
-               unsigned long c, data;
+               unsigned long c, data, mask;
 
                /* Fall back to byte-at-a-time if we get a page fault */
                unsafe_get_user(c, (unsigned long __user *)(src+res), byte_at_a_time);
 
-               *(unsigned long *)(dst+res) = c;
+               /*
+                * Note that we mask out the bytes following the NUL. This is
+                * important to do because string oblivious code may read past
+                * the NUL. For those routines, we don't want to give them
+                * potentially random bytes after the NUL in `src`.
+                *
+                * One example of such code is BPF map keys. BPF treats map keys
+                * as an opaque set of bytes. Without the post-NUL mask, any BPF
+                * maps keyed by strings returned from strncpy_from_user() may
+                * have multiple entries for semantically identical strings.
+                */
                if (has_zero(c, &data, &constants)) {
                        data = prep_zero_mask(c, data, &constants);
                        data = create_zero_mask(data);
+                       mask = zero_bytemask(data);
+                       *(unsigned long *)(dst+res) = c & mask;
                        return res + find_zero(data);
                }
+
+               *(unsigned long *)(dst+res) = c;
+
                res += sizeof(unsigned long);
                max -= sizeof(unsigned long);
        }
index 63c2617..662f862 100644 (file)
@@ -216,6 +216,12 @@ static void kmalloc_oob_16(struct kunit *test)
                u64 words[2];
        } *ptr1, *ptr2;
 
+       /* This test is specifically crafted for the generic mode. */
+       if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) {
+               kunit_info(test, "CONFIG_KASAN_GENERIC required\n");
+               return;
+       }
+
        ptr1 = kmalloc(sizeof(*ptr1) - 3, GFP_KERNEL);
        KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1);
 
@@ -227,6 +233,23 @@ static void kmalloc_oob_16(struct kunit *test)
        kfree(ptr2);
 }
 
+static void kmalloc_uaf_16(struct kunit *test)
+{
+       struct {
+               u64 words[2];
+       } *ptr1, *ptr2;
+
+       ptr1 = kmalloc(sizeof(*ptr1), GFP_KERNEL);
+       KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1);
+
+       ptr2 = kmalloc(sizeof(*ptr2), GFP_KERNEL);
+       KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2);
+       kfree(ptr2);
+
+       KUNIT_EXPECT_KASAN_FAIL(test, *ptr1 = *ptr2);
+       kfree(ptr1);
+}
+
 static void kmalloc_oob_memset_2(struct kunit *test)
 {
        char *ptr;
@@ -429,6 +452,12 @@ static void kasan_global_oob(struct kunit *test)
        volatile int i = 3;
        char *p = &global_array[ARRAY_SIZE(global_array) + i];
 
+       /* Only generic mode instruments globals. */
+       if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) {
+               kunit_info(test, "CONFIG_KASAN_GENERIC required");
+               return;
+       }
+
        KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p);
 }
 
@@ -467,6 +496,12 @@ static void kasan_alloca_oob_left(struct kunit *test)
        char alloca_array[i];
        char *p = alloca_array - 1;
 
+       /* Only generic mode instruments dynamic allocas. */
+       if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) {
+               kunit_info(test, "CONFIG_KASAN_GENERIC required");
+               return;
+       }
+
        if (!IS_ENABLED(CONFIG_KASAN_STACK)) {
                kunit_info(test, "CONFIG_KASAN_STACK is not enabled");
                return;
@@ -481,6 +516,12 @@ static void kasan_alloca_oob_right(struct kunit *test)
        char alloca_array[i];
        char *p = alloca_array + i;
 
+       /* Only generic mode instruments dynamic allocas. */
+       if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) {
+               kunit_info(test, "CONFIG_KASAN_GENERIC required");
+               return;
+       }
+
        if (!IS_ENABLED(CONFIG_KASAN_STACK)) {
                kunit_info(test, "CONFIG_KASAN_STACK is not enabled");
                return;
@@ -551,6 +592,9 @@ static void kasan_memchr(struct kunit *test)
                return;
        }
 
+       if (OOB_TAG_OFF)
+               size = round_up(size, OOB_TAG_OFF);
+
        ptr = kmalloc(size, GFP_KERNEL | __GFP_ZERO);
        KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
 
@@ -573,6 +617,9 @@ static void kasan_memcmp(struct kunit *test)
                return;
        }
 
+       if (OOB_TAG_OFF)
+               size = round_up(size, OOB_TAG_OFF);
+
        ptr = kmalloc(size, GFP_KERNEL | __GFP_ZERO);
        KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
        memset(arr, 0, sizeof(arr));
@@ -619,13 +666,50 @@ static void kasan_strings(struct kunit *test)
        KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = strnlen(ptr, 1));
 }
 
-static void kasan_bitops(struct kunit *test)
+static void kasan_bitops_modify(struct kunit *test, int nr, void *addr)
+{
+       KUNIT_EXPECT_KASAN_FAIL(test, set_bit(nr, addr));
+       KUNIT_EXPECT_KASAN_FAIL(test, __set_bit(nr, addr));
+       KUNIT_EXPECT_KASAN_FAIL(test, clear_bit(nr, addr));
+       KUNIT_EXPECT_KASAN_FAIL(test, __clear_bit(nr, addr));
+       KUNIT_EXPECT_KASAN_FAIL(test, clear_bit_unlock(nr, addr));
+       KUNIT_EXPECT_KASAN_FAIL(test, __clear_bit_unlock(nr, addr));
+       KUNIT_EXPECT_KASAN_FAIL(test, change_bit(nr, addr));
+       KUNIT_EXPECT_KASAN_FAIL(test, __change_bit(nr, addr));
+}
+
+static void kasan_bitops_test_and_modify(struct kunit *test, int nr, void *addr)
+{
+       KUNIT_EXPECT_KASAN_FAIL(test, test_and_set_bit(nr, addr));
+       KUNIT_EXPECT_KASAN_FAIL(test, __test_and_set_bit(nr, addr));
+       KUNIT_EXPECT_KASAN_FAIL(test, test_and_set_bit_lock(nr, addr));
+       KUNIT_EXPECT_KASAN_FAIL(test, test_and_clear_bit(nr, addr));
+       KUNIT_EXPECT_KASAN_FAIL(test, __test_and_clear_bit(nr, addr));
+       KUNIT_EXPECT_KASAN_FAIL(test, test_and_change_bit(nr, addr));
+       KUNIT_EXPECT_KASAN_FAIL(test, __test_and_change_bit(nr, addr));
+       KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = test_bit(nr, addr));
+
+#if defined(clear_bit_unlock_is_negative_byte)
+       KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result =
+                               clear_bit_unlock_is_negative_byte(nr, addr));
+#endif
+}
+
+static void kasan_bitops_generic(struct kunit *test)
 {
+       long *bits;
+
+       /* This test is specifically crafted for the generic mode. */
+       if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) {
+               kunit_info(test, "CONFIG_KASAN_GENERIC required\n");
+               return;
+       }
+
        /*
         * Allocate 1 more byte, which causes kzalloc to round up to 16-bytes;
         * this way we do not actually corrupt other memory.
         */
-       long *bits = kzalloc(sizeof(*bits) + 1, GFP_KERNEL);
+       bits = kzalloc(sizeof(*bits) + 1, GFP_KERNEL);
        KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bits);
 
        /*
@@ -633,55 +717,34 @@ static void kasan_bitops(struct kunit *test)
         * below accesses are still out-of-bounds, since bitops are defined to
         * operate on the whole long the bit is in.
         */
-       KUNIT_EXPECT_KASAN_FAIL(test, set_bit(BITS_PER_LONG, bits));
-
-       KUNIT_EXPECT_KASAN_FAIL(test, __set_bit(BITS_PER_LONG, bits));
-
-       KUNIT_EXPECT_KASAN_FAIL(test, clear_bit(BITS_PER_LONG, bits));
-
-       KUNIT_EXPECT_KASAN_FAIL(test, __clear_bit(BITS_PER_LONG, bits));
-
-       KUNIT_EXPECT_KASAN_FAIL(test, clear_bit_unlock(BITS_PER_LONG, bits));
-
-       KUNIT_EXPECT_KASAN_FAIL(test, __clear_bit_unlock(BITS_PER_LONG, bits));
-
-       KUNIT_EXPECT_KASAN_FAIL(test, change_bit(BITS_PER_LONG, bits));
-
-       KUNIT_EXPECT_KASAN_FAIL(test, __change_bit(BITS_PER_LONG, bits));
+       kasan_bitops_modify(test, BITS_PER_LONG, bits);
 
        /*
         * Below calls try to access bit beyond allocated memory.
         */
-       KUNIT_EXPECT_KASAN_FAIL(test,
-               test_and_set_bit(BITS_PER_LONG + BITS_PER_BYTE, bits));
-
-       KUNIT_EXPECT_KASAN_FAIL(test,
-               __test_and_set_bit(BITS_PER_LONG + BITS_PER_BYTE, bits));
-
-       KUNIT_EXPECT_KASAN_FAIL(test,
-               test_and_set_bit_lock(BITS_PER_LONG + BITS_PER_BYTE, bits));
+       kasan_bitops_test_and_modify(test, BITS_PER_LONG + BITS_PER_BYTE, bits);
 
-       KUNIT_EXPECT_KASAN_FAIL(test,
-               test_and_clear_bit(BITS_PER_LONG + BITS_PER_BYTE, bits));
+       kfree(bits);
+}
 
-       KUNIT_EXPECT_KASAN_FAIL(test,
-               __test_and_clear_bit(BITS_PER_LONG + BITS_PER_BYTE, bits));
+static void kasan_bitops_tags(struct kunit *test)
+{
+       long *bits;
 
-       KUNIT_EXPECT_KASAN_FAIL(test,
-               test_and_change_bit(BITS_PER_LONG + BITS_PER_BYTE, bits));
+       /* This test is specifically crafted for the tag-based mode. */
+       if (IS_ENABLED(CONFIG_KASAN_GENERIC)) {
+               kunit_info(test, "CONFIG_KASAN_SW_TAGS required\n");
+               return;
+       }
 
-       KUNIT_EXPECT_KASAN_FAIL(test,
-               __test_and_change_bit(BITS_PER_LONG + BITS_PER_BYTE, bits));
+       /* Allocation size will be rounded to up granule size, which is 16. */
+       bits = kzalloc(sizeof(*bits), GFP_KERNEL);
+       KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bits);
 
-       KUNIT_EXPECT_KASAN_FAIL(test,
-               kasan_int_result =
-                       test_bit(BITS_PER_LONG + BITS_PER_BYTE, bits));
+       /* Do the accesses past the 16 allocated bytes. */
+       kasan_bitops_modify(test, BITS_PER_LONG, &bits[1]);
+       kasan_bitops_test_and_modify(test, BITS_PER_LONG + BITS_PER_BYTE, &bits[1]);
 
-#if defined(clear_bit_unlock_is_negative_byte)
-       KUNIT_EXPECT_KASAN_FAIL(test,
-               kasan_int_result = clear_bit_unlock_is_negative_byte(
-                       BITS_PER_LONG + BITS_PER_BYTE, bits));
-#endif
        kfree(bits);
 }
 
@@ -728,6 +791,7 @@ static struct kunit_case kasan_kunit_test_cases[] = {
        KUNIT_CASE(kmalloc_oob_krealloc_more),
        KUNIT_CASE(kmalloc_oob_krealloc_less),
        KUNIT_CASE(kmalloc_oob_16),
+       KUNIT_CASE(kmalloc_uaf_16),
        KUNIT_CASE(kmalloc_oob_in_memset),
        KUNIT_CASE(kmalloc_oob_memset_2),
        KUNIT_CASE(kmalloc_oob_memset_4),
@@ -751,7 +815,8 @@ static struct kunit_case kasan_kunit_test_cases[] = {
        KUNIT_CASE(kasan_memchr),
        KUNIT_CASE(kasan_memcmp),
        KUNIT_CASE(kasan_strings),
-       KUNIT_CASE(kasan_bitops),
+       KUNIT_CASE(kasan_bitops_generic),
+       KUNIT_CASE(kasan_bitops_tags),
        KUNIT_CASE(kmalloc_double_kzfree),
        KUNIT_CASE(vmalloc_oob),
        {}
index 6e0ee56..13cb7a9 100644 (file)
@@ -817,6 +817,10 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
         * delay for some time until fewer pages are isolated
         */
        while (unlikely(too_many_isolated(pgdat))) {
+               /* stop isolation if there are still pages not migrated */
+               if (cc->nr_migratepages)
+                       return 0;
+
                /* async migration should just abort */
                if (cc->mode == MIGRATE_ASYNC)
                        return 0;
@@ -1012,8 +1016,8 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 
 isolate_success:
                list_add(&page->lru, &cc->migratepages);
-               cc->nr_migratepages++;
-               nr_isolated++;
+               cc->nr_migratepages += compound_nr(page);
+               nr_isolated += compound_nr(page);
 
                /*
                 * Avoid isolating too much unless this block is being
@@ -1021,7 +1025,7 @@ isolate_success:
                 * or a lock is contended. For contention, isolate quickly to
                 * potentially remove one source of contention.
                 */
-               if (cc->nr_migratepages == COMPACT_CLUSTER_MAX &&
+               if (cc->nr_migratepages >= COMPACT_CLUSTER_MAX &&
                    !cc->rescan && !cc->contended) {
                        ++low_pfn;
                        break;
@@ -1132,7 +1136,7 @@ isolate_migratepages_range(struct compact_control *cc, unsigned long start_pfn,
                if (!pfn)
                        break;
 
-               if (cc->nr_migratepages == COMPACT_CLUSTER_MAX)
+               if (cc->nr_migratepages >= COMPACT_CLUSTER_MAX)
                        break;
        }
 
index d5e7c20..0b2067b 100644 (file)
@@ -1484,11 +1484,19 @@ void end_page_writeback(struct page *page)
                rotate_reclaimable_page(page);
        }
 
+       /*
+        * Writeback does not hold a page reference of its own, relying
+        * on truncation to wait for the clearing of PG_writeback.
+        * But here we must make sure that the page is not freed and
+        * reused before the wake_up_page().
+        */
+       get_page(page);
        if (!test_clear_page_writeback(page))
                BUG();
 
        smp_mb__after_atomic();
        wake_up_page(page, PG_writeback);
+       put_page(page);
 }
 EXPORT_SYMBOL(end_page_writeback);
 
@@ -2347,10 +2355,15 @@ page_ok:
 
 page_not_up_to_date:
                /* Get exclusive access to the page ... */
-               if (iocb->ki_flags & IOCB_WAITQ)
+               if (iocb->ki_flags & IOCB_WAITQ) {
+                       if (written) {
+                               put_page(page);
+                               goto out;
+                       }
                        error = lock_page_async(page, iocb->ki_waitq);
-               else
+               } else {
                        error = lock_page_killable(page);
+               }
                if (unlikely(error))
                        goto readpage_error;
 
@@ -2393,10 +2406,15 @@ readpage:
                }
 
                if (!PageUptodate(page)) {
-                       if (iocb->ki_flags & IOCB_WAITQ)
+                       if (iocb->ki_flags & IOCB_WAITQ) {
+                               if (written) {
+                                       put_page(page);
+                                       goto out;
+                               }
                                error = lock_page_async(page, iocb->ki_waitq);
-                       else
+                       } else {
                                error = lock_page_killable(page);
+                       }
 
                        if (unlikely(error))
                                goto readpage_error;
index 102877e..98eb8e6 100644 (file)
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1647,8 +1647,11 @@ check_again:
                /*
                 * drop the above get_user_pages reference.
                 */
-               for (i = 0; i < nr_pages; i++)
-                       put_page(pages[i]);
+               if (gup_flags & FOLL_PIN)
+                       unpin_user_pages(pages, nr_pages);
+               else
+                       for (i = 0; i < nr_pages; i++)
+                               put_page(pages[i]);
 
                if (migrate_pages(&cma_page_list, alloc_migration_target, NULL,
                        (unsigned long)&mtc, MIGRATE_SYNC, MR_CONTIG_RANGE)) {
@@ -1728,8 +1731,11 @@ static long __gup_longterm_locked(struct mm_struct *mm,
                        goto out;
 
                if (check_dax_vmas(vmas_tmp, rc)) {
-                       for (i = 0; i < rc; i++)
-                               put_page(pages[i]);
+                       if (gup_flags & FOLL_PIN)
+                               unpin_user_pages(pages, rc);
+                       else
+                               for (i = 0; i < rc; i++)
+                                       put_page(pages[i]);
                        rc = -EOPNOTSUPP;
                        goto out;
                }
index 9474dbc..ec2bb93 100644 (file)
@@ -710,7 +710,6 @@ vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf)
                        transparent_hugepage_use_zero_page()) {
                pgtable_t pgtable;
                struct page *zero_page;
-               bool set;
                vm_fault_t ret;
                pgtable = pte_alloc_one(vma->vm_mm);
                if (unlikely(!pgtable))
@@ -723,25 +722,25 @@ vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf)
                }
                vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd);
                ret = 0;
-               set = false;
                if (pmd_none(*vmf->pmd)) {
                        ret = check_stable_address_space(vma->vm_mm);
                        if (ret) {
                                spin_unlock(vmf->ptl);
+                               pte_free(vma->vm_mm, pgtable);
                        } else if (userfaultfd_missing(vma)) {
                                spin_unlock(vmf->ptl);
+                               pte_free(vma->vm_mm, pgtable);
                                ret = handle_userfault(vmf, VM_UFFD_MISSING);
                                VM_BUG_ON(ret & VM_FAULT_FALLBACK);
                        } else {
                                set_huge_zero_page(pgtable, vma->vm_mm, vma,
                                                   haddr, vmf->pmd, zero_page);
                                spin_unlock(vmf->ptl);
-                               set = true;
                        }
-               } else
+               } else {
                        spin_unlock(vmf->ptl);
-               if (!set)
                        pte_free(vma->vm_mm, pgtable);
+               }
                return ret;
        }
        gfp = alloc_hugepage_direct_gfpmask(vma);
index fe76f8f..37f15c3 100644 (file)
@@ -648,6 +648,8 @@ retry:
                        }
 
                        del += t - f;
+                       hugetlb_cgroup_uncharge_file_region(
+                               resv, rg, t - f);
 
                        /* New entry for end of split region */
                        nrg->from = t;
@@ -660,9 +662,6 @@ retry:
                        /* Original entry is trimmed */
                        rg->to = f;
 
-                       hugetlb_cgroup_uncharge_file_region(
-                               resv, rg, nrg->to - nrg->from);
-
                        list_add(&nrg->link, &rg->link);
                        nrg = NULL;
                        break;
@@ -678,17 +677,17 @@ retry:
                }
 
                if (f <= rg->from) {    /* Trim beginning of region */
-                       del += t - rg->from;
-                       rg->from = t;
-
                        hugetlb_cgroup_uncharge_file_region(resv, rg,
                                                            t - rg->from);
-               } else {                /* Trim end of region */
-                       del += rg->to - f;
-                       rg->to = f;
 
+                       del += t - rg->from;
+                       rg->from = t;
+               } else {                /* Trim end of region */
                        hugetlb_cgroup_uncharge_file_region(resv, rg,
                                                            rg->to - f);
+
+                       del += rg->to - f;
+                       rg->to = f;
                }
        }
 
@@ -1568,104 +1567,24 @@ int PageHeadHuge(struct page *page_head)
        return page_head[1].compound_dtor == HUGETLB_PAGE_DTOR;
 }
 
-/*
- * Find address_space associated with hugetlbfs page.
- * Upon entry page is locked and page 'was' mapped although mapped state
- * could change.  If necessary, use anon_vma to find vma and associated
- * address space.  The returned mapping may be stale, but it can not be
- * invalid as page lock (which is held) is required to destroy mapping.
- */
-static struct address_space *_get_hugetlb_page_mapping(struct page *hpage)
-{
-       struct anon_vma *anon_vma;
-       pgoff_t pgoff_start, pgoff_end;
-       struct anon_vma_chain *avc;
-       struct address_space *mapping = page_mapping(hpage);
-
-       /* Simple file based mapping */
-       if (mapping)
-               return mapping;
-
-       /*
-        * Even anonymous hugetlbfs mappings are associated with an
-        * underlying hugetlbfs file (see hugetlb_file_setup in mmap
-        * code).  Find a vma associated with the anonymous vma, and
-        * use the file pointer to get address_space.
-        */
-       anon_vma = page_lock_anon_vma_read(hpage);
-       if (!anon_vma)
-               return mapping;  /* NULL */
-
-       /* Use first found vma */
-       pgoff_start = page_to_pgoff(hpage);
-       pgoff_end = pgoff_start + pages_per_huge_page(page_hstate(hpage)) - 1;
-       anon_vma_interval_tree_foreach(avc, &anon_vma->rb_root,
-                                       pgoff_start, pgoff_end) {
-               struct vm_area_struct *vma = avc->vma;
-
-               mapping = vma->vm_file->f_mapping;
-               break;
-       }
-
-       anon_vma_unlock_read(anon_vma);
-       return mapping;
-}
-
 /*
  * Find and lock address space (mapping) in write mode.
  *
- * Upon entry, the page is locked which allows us to find the mapping
- * even in the case of an anon page.  However, locking order dictates
- * the i_mmap_rwsem be acquired BEFORE the page lock.  This is hugetlbfs
- * specific.  So, we first try to lock the sema while still holding the
- * page lock.  If this works, great!  If not, then we need to drop the
- * page lock and then acquire i_mmap_rwsem and reacquire page lock.  Of
- * course, need to revalidate state along the way.
+ * Upon entry, the page is locked which means that page_mapping() is
+ * stable.  Due to locking order, we can only trylock_write.  If we can
+ * not get the lock, simply return NULL to caller.
  */
 struct address_space *hugetlb_page_mapping_lock_write(struct page *hpage)
 {
-       struct address_space *mapping, *mapping2;
+       struct address_space *mapping = page_mapping(hpage);
 
-       mapping = _get_hugetlb_page_mapping(hpage);
-retry:
        if (!mapping)
                return mapping;
 
-       /*
-        * If no contention, take lock and return
-        */
        if (i_mmap_trylock_write(mapping))
                return mapping;
 
-       /*
-        * Must drop page lock and wait on mapping sema.
-        * Note:  Once page lock is dropped, mapping could become invalid.
-        * As a hack, increase map count until we lock page again.
-        */
-       atomic_inc(&hpage->_mapcount);
-       unlock_page(hpage);
-       i_mmap_lock_write(mapping);
-       lock_page(hpage);
-       atomic_add_negative(-1, &hpage->_mapcount);
-
-       /* verify page is still mapped */
-       if (!page_mapped(hpage)) {
-               i_mmap_unlock_write(mapping);
-               return NULL;
-       }
-
-       /*
-        * Get address space again and verify it is the same one
-        * we locked.  If not, drop lock and retry.
-        */
-       mapping2 = _get_hugetlb_page_mapping(hpage);
-       if (mapping2 != mapping) {
-               i_mmap_unlock_write(mapping);
-               mapping = mapping2;
-               goto retry;
-       }
-
-       return mapping;
+       return NULL;
 }
 
 pgoff_t __basepage_index(struct page *page)
@@ -2443,6 +2362,9 @@ struct page *alloc_huge_page(struct vm_area_struct *vma,
 
                rsv_adjust = hugepage_subpool_put_pages(spool, 1);
                hugetlb_acct_memory(h, -rsv_adjust);
+               if (deferred_reserve)
+                       hugetlb_cgroup_uncharge_page_rsvd(hstate_index(h),
+                                       pages_per_huge_page(h), page);
        }
        return page;
 
index 416a56b..a8d8d48 100644 (file)
@@ -226,7 +226,7 @@ static void force_shm_swapin_readahead(struct vm_area_struct *vma,
                struct address_space *mapping)
 {
        XA_STATE(xas, &mapping->i_pages, linear_page_index(vma, start));
-       pgoff_t end_index = end / PAGE_SIZE;
+       pgoff_t end_index = linear_page_index(vma, end + PAGE_SIZE - 1);
        struct page *page;
 
        rcu_read_lock();
@@ -1231,8 +1231,6 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec,
                ret = total_len - iov_iter_count(&iter);
 
        mmput(mm);
-       return ret;
-
 release_task:
        put_task_struct(task);
 put_pid:
index 3a24e3b..29459a6 100644 (file)
@@ -867,8 +867,13 @@ void __mod_lruvec_slab_state(void *p, enum node_stat_item idx, int val)
        rcu_read_lock();
        memcg = mem_cgroup_from_obj(p);
 
-       /* Untracked pages have no memcg, no lruvec. Update only the node */
-       if (!memcg || memcg == root_mem_cgroup) {
+       /*
+        * Untracked pages have no memcg, no lruvec. Update only the
+        * node. If we reparent the slab objects to the root memcg,
+        * when we free the slab object, we need to update the per-memcg
+        * vmstats to keep it correct for the root memcg.
+        */
+       if (!memcg) {
                __mod_node_page_state(pgdat, idx, val);
        } else {
                lruvec = mem_cgroup_lruvec(memcg, pgdat);
@@ -4110,11 +4115,17 @@ static int memcg_stat_show(struct seq_file *m, void *v)
                           (u64)memsw * PAGE_SIZE);
 
        for (i = 0; i < ARRAY_SIZE(memcg1_stats); i++) {
+               unsigned long nr;
+
                if (memcg1_stats[i] == MEMCG_SWAP && !do_memsw_account())
                        continue;
+               nr = memcg_page_state(memcg, memcg1_stats[i]);
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+               if (memcg1_stats[i] == NR_ANON_THPS)
+                       nr *= HPAGE_PMD_NR;
+#endif
                seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i],
-                          (u64)memcg_page_state(memcg, memcg1_stats[i]) *
-                          PAGE_SIZE);
+                                               (u64)nr * PAGE_SIZE);
        }
 
        for (i = 0; i < ARRAY_SIZE(memcg1_events); i++)
@@ -5339,17 +5350,22 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
                memcg->swappiness = mem_cgroup_swappiness(parent);
                memcg->oom_kill_disable = parent->oom_kill_disable;
        }
-       if (parent && parent->use_hierarchy) {
+       if (!parent) {
+               page_counter_init(&memcg->memory, NULL);
+               page_counter_init(&memcg->swap, NULL);
+               page_counter_init(&memcg->kmem, NULL);
+               page_counter_init(&memcg->tcpmem, NULL);
+       } else if (parent->use_hierarchy) {
                memcg->use_hierarchy = true;
                page_counter_init(&memcg->memory, &parent->memory);
                page_counter_init(&memcg->swap, &parent->swap);
                page_counter_init(&memcg->kmem, &parent->kmem);
                page_counter_init(&memcg->tcpmem, &parent->tcpmem);
        } else {
-               page_counter_init(&memcg->memory, NULL);
-               page_counter_init(&memcg->swap, NULL);
-               page_counter_init(&memcg->kmem, NULL);
-               page_counter_init(&memcg->tcpmem, NULL);
+               page_counter_init(&memcg->memory, &root_mem_cgroup->memory);
+               page_counter_init(&memcg->swap, &root_mem_cgroup->swap);
+               page_counter_init(&memcg->kmem, &root_mem_cgroup->kmem);
+               page_counter_init(&memcg->tcpmem, &root_mem_cgroup->tcpmem);
                /*
                 * Deeper hierachy with use_hierarchy == false doesn't make
                 * much sense so let cgroup subsystem know about this
index c0bb186..5d880d4 100644 (file)
@@ -1057,27 +1057,25 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn,
        if (!PageHuge(hpage)) {
                unmap_success = try_to_unmap(hpage, ttu);
        } else {
-               /*
-                * For hugetlb pages, try_to_unmap could potentially call
-                * huge_pmd_unshare.  Because of this, take semaphore in
-                * write mode here and set TTU_RMAP_LOCKED to indicate we
-                * have taken the lock at this higer level.
-                *
-                * Note that the call to hugetlb_page_mapping_lock_write
-                * is necessary even if mapping is already set.  It handles
-                * ugliness of potentially having to drop page lock to obtain
-                * i_mmap_rwsem.
-                */
-               mapping = hugetlb_page_mapping_lock_write(hpage);
-
-               if (mapping) {
-                       unmap_success = try_to_unmap(hpage,
+               if (!PageAnon(hpage)) {
+                       /*
+                        * For hugetlb pages in shared mappings, try_to_unmap
+                        * could potentially call huge_pmd_unshare.  Because of
+                        * this, take semaphore in write mode here and set
+                        * TTU_RMAP_LOCKED to indicate we have taken the lock
+                        * at this higer level.
+                        */
+                       mapping = hugetlb_page_mapping_lock_write(hpage);
+                       if (mapping) {
+                               unmap_success = try_to_unmap(hpage,
                                                     ttu|TTU_RMAP_LOCKED);
-                       i_mmap_unlock_write(mapping);
+                               i_mmap_unlock_write(mapping);
+                       } else {
+                               pr_info("Memory failure: %#lx: could not lock mapping for mapped huge page\n", pfn);
+                               unmap_success = false;
+                       }
                } else {
-                       pr_info("Memory failure: %#lx: could not find mapping for mapped huge page\n",
-                               pfn);
-                       unmap_success = false;
+                       unmap_success = try_to_unmap(hpage, ttu);
                }
        }
        if (!unmap_success)
index b44d4c7..63b2e46 100644 (file)
@@ -350,24 +350,6 @@ int __ref __add_pages(int nid, unsigned long pfn, unsigned long nr_pages,
        return err;
 }
 
-#ifdef CONFIG_NUMA
-int __weak memory_add_physaddr_to_nid(u64 start)
-{
-       pr_info_once("Unknown online node for memory at 0x%llx, assuming node 0\n",
-                       start);
-       return 0;
-}
-EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
-
-int __weak phys_to_target_node(u64 start)
-{
-       pr_info_once("Unknown target node for memory at 0x%llx, assuming node 0\n",
-                       start);
-       return 0;
-}
-EXPORT_SYMBOL_GPL(phys_to_target_node);
-#endif
-
 /* find the smallest valid pfn in the range [start_pfn, end_pfn) */
 static unsigned long find_smallest_section_pfn(int nid, struct zone *zone,
                                     unsigned long start_pfn,
index 3fde772..3ca4898 100644 (file)
@@ -525,7 +525,7 @@ static int queue_pages_pte_range(pmd_t *pmd, unsigned long addr,
        unsigned long flags = qp->flags;
        int ret;
        bool has_unmovable = false;
-       pte_t *pte;
+       pte_t *pte, *mapped_pte;
        spinlock_t *ptl;
 
        ptl = pmd_trans_huge_lock(pmd, vma);
@@ -539,7 +539,7 @@ static int queue_pages_pte_range(pmd_t *pmd, unsigned long addr,
        if (pmd_trans_unstable(pmd))
                return 0;
 
-       pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl);
+       mapped_pte = pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl);
        for (; addr != end; pte++, addr += PAGE_SIZE) {
                if (!pte_present(*pte))
                        continue;
@@ -571,7 +571,7 @@ static int queue_pages_pte_range(pmd_t *pmd, unsigned long addr,
                } else
                        break;
        }
-       pte_unmap_unlock(pte - 1, ptl);
+       pte_unmap_unlock(mapped_pte, ptl);
        cond_resched();
 
        if (has_unmovable)
index 73a206d..16b2fb4 100644 (file)
@@ -41,28 +41,24 @@ EXPORT_SYMBOL_GPL(memremap_compat_align);
 DEFINE_STATIC_KEY_FALSE(devmap_managed_key);
 EXPORT_SYMBOL(devmap_managed_key);
 
-static void devmap_managed_enable_put(void)
+static void devmap_managed_enable_put(struct dev_pagemap *pgmap)
 {
-       static_branch_dec(&devmap_managed_key);
+       if (pgmap->type == MEMORY_DEVICE_PRIVATE ||
+           pgmap->type == MEMORY_DEVICE_FS_DAX)
+               static_branch_dec(&devmap_managed_key);
 }
 
-static int devmap_managed_enable_get(struct dev_pagemap *pgmap)
+static void devmap_managed_enable_get(struct dev_pagemap *pgmap)
 {
-       if (pgmap->type == MEMORY_DEVICE_PRIVATE &&
-           (!pgmap->ops || !pgmap->ops->page_free)) {
-               WARN(1, "Missing page_free method\n");
-               return -EINVAL;
-       }
-
-       static_branch_inc(&devmap_managed_key);
-       return 0;
+       if (pgmap->type == MEMORY_DEVICE_PRIVATE ||
+           pgmap->type == MEMORY_DEVICE_FS_DAX)
+               static_branch_inc(&devmap_managed_key);
 }
 #else
-static int devmap_managed_enable_get(struct dev_pagemap *pgmap)
+static void devmap_managed_enable_get(struct dev_pagemap *pgmap)
 {
-       return -EINVAL;
 }
-static void devmap_managed_enable_put(void)
+static void devmap_managed_enable_put(struct dev_pagemap *pgmap)
 {
 }
 #endif /* CONFIG_DEV_PAGEMAP_OPS */
@@ -169,7 +165,7 @@ void memunmap_pages(struct dev_pagemap *pgmap)
                pageunmap_range(pgmap, i);
 
        WARN_ONCE(pgmap->altmap.alloc, "failed to free all reserved pages\n");
-       devmap_managed_enable_put();
+       devmap_managed_enable_put(pgmap);
 }
 EXPORT_SYMBOL_GPL(memunmap_pages);
 
@@ -307,7 +303,6 @@ void *memremap_pages(struct dev_pagemap *pgmap, int nid)
                .pgprot = PAGE_KERNEL,
        };
        const int nr_range = pgmap->nr_range;
-       bool need_devmap_managed = true;
        int error, i;
 
        if (WARN_ONCE(!nr_range, "nr_range must be specified\n"))
@@ -323,6 +318,10 @@ void *memremap_pages(struct dev_pagemap *pgmap, int nid)
                        WARN(1, "Missing migrate_to_ram method\n");
                        return ERR_PTR(-EINVAL);
                }
+               if (!pgmap->ops->page_free) {
+                       WARN(1, "Missing page_free method\n");
+                       return ERR_PTR(-EINVAL);
+               }
                if (!pgmap->owner) {
                        WARN(1, "Missing owner\n");
                        return ERR_PTR(-EINVAL);
@@ -336,11 +335,9 @@ void *memremap_pages(struct dev_pagemap *pgmap, int nid)
                }
                break;
        case MEMORY_DEVICE_GENERIC:
-               need_devmap_managed = false;
                break;
        case MEMORY_DEVICE_PCI_P2PDMA:
                params.pgprot = pgprot_noncached(params.pgprot);
-               need_devmap_managed = false;
                break;
        default:
                WARN(1, "Invalid pgmap type %d\n", pgmap->type);
@@ -364,11 +361,7 @@ void *memremap_pages(struct dev_pagemap *pgmap, int nid)
                }
        }
 
-       if (need_devmap_managed) {
-               error = devmap_managed_enable_get(pgmap);
-               if (error)
-                       return ERR_PTR(error);
-       }
+       devmap_managed_enable_get(pgmap);
 
        /*
         * Clear the pgmap nr_range as it will be incremented for each
index 5ca5842..5795cb8 100644 (file)
@@ -1328,34 +1328,38 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
                goto put_anon;
 
        if (page_mapped(hpage)) {
-               /*
-                * try_to_unmap could potentially call huge_pmd_unshare.
-                * Because of this, take semaphore in write mode here and
-                * set TTU_RMAP_LOCKED to let lower levels know we have
-                * taken the lock.
-                */
-               mapping = hugetlb_page_mapping_lock_write(hpage);
-               if (unlikely(!mapping))
-                       goto unlock_put_anon;
+               bool mapping_locked = false;
+               enum ttu_flags ttu = TTU_MIGRATION|TTU_IGNORE_MLOCK|
+                                       TTU_IGNORE_ACCESS;
+
+               if (!PageAnon(hpage)) {
+                       /*
+                        * In shared mappings, try_to_unmap could potentially
+                        * call huge_pmd_unshare.  Because of this, take
+                        * semaphore in write mode here and set TTU_RMAP_LOCKED
+                        * to let lower levels know we have taken the lock.
+                        */
+                       mapping = hugetlb_page_mapping_lock_write(hpage);
+                       if (unlikely(!mapping))
+                               goto unlock_put_anon;
+
+                       mapping_locked = true;
+                       ttu |= TTU_RMAP_LOCKED;
+               }
 
-               try_to_unmap(hpage,
-                       TTU_MIGRATION|TTU_IGNORE_MLOCK|TTU_IGNORE_ACCESS|
-                       TTU_RMAP_LOCKED);
+               try_to_unmap(hpage, ttu);
                page_was_mapped = 1;
-               /*
-                * Leave mapping locked until after subsequent call to
-                * remove_migration_ptes()
-                */
+
+               if (mapping_locked)
+                       i_mmap_unlock_write(mapping);
        }
 
        if (!page_mapped(hpage))
                rc = move_to_new_page(new_hpage, hpage, mode);
 
-       if (page_was_mapped) {
+       if (page_was_mapped)
                remove_migration_ptes(hpage,
-                       rc == MIGRATEPAGE_SUCCESS ? new_hpage : hpage, true);
-               i_mmap_unlock_write(mapping);
-       }
+                       rc == MIGRATEPAGE_SUCCESS ? new_hpage : hpage, false);
 
 unlock_put_anon:
        unlock_page(new_hpage);
index 7709f0e..5860424 100644 (file)
@@ -2754,12 +2754,6 @@ int test_clear_page_writeback(struct page *page)
        } else {
                ret = TestClearPageWriteback(page);
        }
-       /*
-        * NOTE: Page might be free now! Writeback doesn't hold a page
-        * reference on its own, it relies on truncation to wait for
-        * the clearing of PG_writeback. The below can only access
-        * page state that is static across allocation cycles.
-        */
        if (ret) {
                dec_lruvec_state(lruvec, NR_WRITEBACK);
                dec_zone_page_state(page, NR_ZONE_WRITE_PENDING);
index 23f5066..eaa227a 100644 (file)
@@ -5103,6 +5103,11 @@ refill:
                if (!page_ref_sub_and_test(page, nc->pagecnt_bias))
                        goto refill;
 
+               if (unlikely(nc->pfmemalloc)) {
+                       free_the_page(page, compound_order(page));
+                       goto refill;
+               }
+
 #if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE)
                /* if size can vary use size else just use PAGE_SIZE */
                size = nc->size;
index 66a93f0..ad7a37e 100644 (file)
@@ -1315,8 +1315,8 @@ static struct pcpu_chunk * __init pcpu_alloc_first_chunk(unsigned long tmp_addr,
        region_size = ALIGN(start_offset + map_size, lcm_align);
 
        /* allocate chunk */
-       alloc_size = sizeof(struct pcpu_chunk) +
-               BITS_TO_LONGS(region_size >> PAGE_SHIFT) * sizeof(unsigned long);
+       alloc_size = struct_size(chunk, populated,
+                                BITS_TO_LONGS(region_size >> PAGE_SHIFT));
        chunk = memblock_alloc(alloc_size, SMP_CACHE_BYTES);
        if (!chunk)
                panic("%s: Failed to allocate %zu bytes\n", __func__,
@@ -2521,8 +2521,8 @@ void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
        pcpu_unit_pages = ai->unit_size >> PAGE_SHIFT;
        pcpu_unit_size = pcpu_unit_pages << PAGE_SHIFT;
        pcpu_atom_size = ai->atom_size;
-       pcpu_chunk_struct_size = sizeof(struct pcpu_chunk) +
-               BITS_TO_LONGS(pcpu_unit_pages) * sizeof(unsigned long);
+       pcpu_chunk_struct_size = struct_size(chunk, populated,
+                                            BITS_TO_LONGS(pcpu_unit_pages));
 
        pcpu_stats_save_ai(ai);
 
index 1b84945..31b2932 100644 (file)
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1413,9 +1413,6 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
                /*
                 * If sharing is possible, start and end will be adjusted
                 * accordingly.
-                *
-                * If called for a huge page, caller must hold i_mmap_rwsem
-                * in write mode as it is possible to call huge_pmd_unshare.
                 */
                adjust_range_if_pmd_sharing_possible(vma, &range.start,
                                                     &range.end);
@@ -1462,7 +1459,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
                subpage = page - page_to_pfn(page) + pte_pfn(*pvmw.pte);
                address = pvmw.address;
 
-               if (PageHuge(page)) {
+               if (PageHuge(page) && !PageAnon(page)) {
                        /*
                         * To call huge_pmd_unshare, i_mmap_rwsem must be
                         * held in write mode.  Caller needs to explicitly
index b30be23..34dcc09 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2852,7 +2852,7 @@ redo:
 
        object = c->freelist;
        page = c->page;
-       if (unlikely(!object || !node_match(page, node))) {
+       if (unlikely(!object || !page || !node_match(page, node))) {
                object = __slab_alloc(s, gfpflags, node, addr, c);
        } else {
                void *next_object = get_freepointer_safe(s, object);
index 18cec39..960edf5 100644 (file)
@@ -528,7 +528,7 @@ void truncate_inode_pages_final(struct address_space *mapping)
 }
 EXPORT_SYMBOL(truncate_inode_pages_final);
 
-unsigned long __invalidate_mapping_pages(struct address_space *mapping,
+static unsigned long __invalidate_mapping_pages(struct address_space *mapping,
                pgoff_t start, pgoff_t end, unsigned long *nr_pagevec)
 {
        pgoff_t indices[PAGEVEC_SIZE];
index 1b8f0e0..7b4e31e 100644 (file)
@@ -1516,7 +1516,8 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone,
        nr_reclaimed = shrink_page_list(&clean_pages, zone->zone_pgdat, &sc,
                        TTU_IGNORE_ACCESS, &stat, true);
        list_splice(&clean_pages, page_list);
-       mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_FILE, -nr_reclaimed);
+       mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_FILE,
+                           -(long)nr_reclaimed);
        /*
         * Since lazyfree pages are isolated from file LRU from the beginning,
         * they will rotate back to anonymous LRU in the end if it failed to
@@ -1526,7 +1527,7 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone,
        mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_ANON,
                            stat.nr_lazyfree_fail);
        mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_FILE,
-                           -stat.nr_lazyfree_fail);
+                           -(long)stat.nr_lazyfree_fail);
        return nr_reclaimed;
 }
 
index dbabb65..7226c78 100644 (file)
@@ -954,9 +954,8 @@ static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 {
        struct lec_state *state = seq->private;
 
-       v = lec_get_idx(state, 1);
-       *pos += !!PTR_ERR(v);
-       return v;
+       ++*pos;
+       return lec_get_idx(state, 1);
 }
 
 static int lec_seq_show(struct seq_file *seq, void *v)
index 6f742fe..7730c8f 100644 (file)
@@ -207,6 +207,7 @@ static void br_get_stats64(struct net_device *dev,
 {
        struct net_bridge *br = netdev_priv(dev);
 
+       netdev_stats_to_stats64(stats, &dev->stats);
        dev_fetch_sw_netstats(stats, br->stats);
 }
 
index 224e5e0..7c9958d 100644 (file)
@@ -62,8 +62,9 @@ config CAN_ISOTP
          communication between CAN nodes via two defined CAN Identifiers.
          As CAN frames can only transport a small amount of data bytes
          (max. 8 bytes for 'classic' CAN and max. 64 bytes for CAN FD) this
-         segmentation is needed to transport longer PDUs as needed e.g. for
-         vehicle diagnosis (UDS, ISO 14229) or IP-over-CAN traffic.
+         segmentation is needed to transport longer Protocol Data Units (PDU)
+         as needed e.g. for vehicle diagnosis (UDS, ISO 14229) or IP-over-CAN
+         traffic.
          This protocol driver implements data transfers according to
          ISO 15765-2:2016 for 'classic' CAN and CAN FD frame types.
          If you want to perform automotive vehicle diagnostic services (UDS),
index 6373ab9..5d124c1 100644 (file)
@@ -677,16 +677,25 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev,
 {
        struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
 
-       if (unlikely(dev->type != ARPHRD_CAN || skb->len != CAN_MTU ||
-                    cfd->len > CAN_MAX_DLEN)) {
-               pr_warn_once("PF_CAN: dropped non conform CAN skbuf: dev type %d, len %d, datalen %d\n",
+       if (unlikely(dev->type != ARPHRD_CAN || skb->len != CAN_MTU)) {
+               pr_warn_once("PF_CAN: dropped non conform CAN skbuff: dev type %d, len %d\n",
+                            dev->type, skb->len);
+               goto free_skb;
+       }
+
+       /* This check is made separately since cfd->len would be uninitialized if skb->len = 0. */
+       if (unlikely(cfd->len > CAN_MAX_DLEN)) {
+               pr_warn_once("PF_CAN: dropped non conform CAN skbuff: dev type %d, len %d, datalen %d\n",
                             dev->type, skb->len, cfd->len);
-               kfree_skb(skb);
-               return NET_RX_DROP;
+               goto free_skb;
        }
 
        can_receive(skb, dev);
        return NET_RX_SUCCESS;
+
+free_skb:
+       kfree_skb(skb);
+       return NET_RX_DROP;
 }
 
 static int canfd_rcv(struct sk_buff *skb, struct net_device *dev,
@@ -694,16 +703,25 @@ static int canfd_rcv(struct sk_buff *skb, struct net_device *dev,
 {
        struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
 
-       if (unlikely(dev->type != ARPHRD_CAN || skb->len != CANFD_MTU ||
-                    cfd->len > CANFD_MAX_DLEN)) {
-               pr_warn_once("PF_CAN: dropped non conform CAN FD skbuf: dev type %d, len %d, datalen %d\n",
+       if (unlikely(dev->type != ARPHRD_CAN || skb->len != CANFD_MTU)) {
+               pr_warn_once("PF_CAN: dropped non conform CAN FD skbuff: dev type %d, len %d\n",
+                            dev->type, skb->len);
+               goto free_skb;
+       }
+
+       /* This check is made separately since cfd->len would be uninitialized if skb->len = 0. */
+       if (unlikely(cfd->len > CANFD_MAX_DLEN)) {
+               pr_warn_once("PF_CAN: dropped non conform CAN FD skbuff: dev type %d, len %d, datalen %d\n",
                             dev->type, skb->len, cfd->len);
-               kfree_skb(skb);
-               return NET_RX_DROP;
+               goto free_skb;
        }
 
        can_receive(skb, dev);
        return NET_RX_SUCCESS;
+
+free_skb:
+       kfree_skb(skb);
+       return NET_RX_DROP;
 }
 
 /* af_can protocol functions */
index 4c20628..d78ab13 100644 (file)
@@ -252,14 +252,16 @@ static void isotp_rcv_skb(struct sk_buff *skb, struct sock *sk)
 
 static u8 padlen(u8 datalen)
 {
-       const u8 plen[] = {8, 8, 8, 8, 8, 8, 8, 8, 8,           /* 0 - 8 */
-                          12, 12, 12, 12,                      /* 9 - 12 */
-                          16, 16, 16, 16,                      /* 13 - 16 */
-                          20, 20, 20, 20,                      /* 17 - 20 */
-                          24, 24, 24, 24,                      /* 21 - 24 */
-                          32, 32, 32, 32, 32, 32, 32, 32,      /* 25 - 32 */
-                          48, 48, 48, 48, 48, 48, 48, 48,      /* 33 - 40 */
-                          48, 48, 48, 48, 48, 48, 48, 48};     /* 41 - 48 */
+       static const u8 plen[] = {
+               8, 8, 8, 8, 8, 8, 8, 8, 8,      /* 0 - 8 */
+               12, 12, 12, 12,                 /* 9 - 12 */
+               16, 16, 16, 16,                 /* 13 - 16 */
+               20, 20, 20, 20,                 /* 17 - 20 */
+               24, 24, 24, 24,                 /* 21 - 24 */
+               32, 32, 32, 32, 32, 32, 32, 32, /* 25 - 32 */
+               48, 48, 48, 48, 48, 48, 48, 48, /* 33 - 40 */
+               48, 48, 48, 48, 48, 48, 48, 48  /* 41 - 48 */
+       };
 
        if (datalen > 48)
                return 64;
@@ -569,10 +571,6 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
                return 0;
        }
 
-       /* no creation of flow control frames */
-       if (so->opt.flags & CAN_ISOTP_LISTEN_MODE)
-               return 0;
-
        /* perform blocksize handling, if enabled */
        if (!so->rxfc.bs || ++so->rx.bs < so->rxfc.bs) {
                /* start rx timeout watchdog */
@@ -581,6 +579,10 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
                return 0;
        }
 
+       /* no creation of flow control frames */
+       if (so->opt.flags & CAN_ISOTP_LISTEN_MODE)
+               return 0;
+
        /* we reached the specified blocksize so->rxfc.bs */
        isotp_send_fc(sk, ae, ISOTP_FC_CTS);
        return 0;
index 1be4c89..f239665 100644 (file)
@@ -475,6 +475,12 @@ static int j1939_sk_bind(struct socket *sock, struct sockaddr *uaddr, int len)
                        goto out_release_sock;
                }
 
+               if (!(ndev->flags & IFF_UP)) {
+                       dev_put(ndev);
+                       ret = -ENETDOWN;
+                       goto out_release_sock;
+               }
+
                priv = j1939_netdev_start(ndev);
                dev_put(ndev);
                if (IS_ERR(priv)) {
index 550928b..5ea8695 100644 (file)
@@ -462,6 +462,9 @@ void can_init_proc(struct net *net)
  */
 void can_remove_proc(struct net *net)
 {
+       if (!net->can.proc_dir)
+               return;
+
        if (net->can.pde_stats)
                remove_proc_entry(CAN_PROC_STATS, net->can.proc_dir);
 
@@ -486,6 +489,5 @@ void can_remove_proc(struct net *net)
        if (net->can.pde_rcvlist_sff)
                remove_proc_entry(CAN_PROC_RCVLIST_SFF, net->can.proc_dir);
 
-       if (net->can.proc_dir)
-               remove_proc_entry("can", net->proc_net);
+       remove_proc_entry("can", net->proc_net);
 }
index a932d95..4b02115 100644 (file)
@@ -1448,7 +1448,7 @@ static int devlink_nl_sb_port_pool_fill(struct sk_buff *msg,
                err = ops->sb_occ_port_pool_get(devlink_port, devlink_sb->index,
                                                pool_index, &cur, &max);
                if (err && err != -EOPNOTSUPP)
-                       return err;
+                       goto sb_occ_get_failure;
                if (!err) {
                        if (nla_put_u32(msg, DEVLINK_ATTR_SB_OCC_CUR, cur))
                                goto nla_put_failure;
@@ -1461,8 +1461,10 @@ static int devlink_nl_sb_port_pool_fill(struct sk_buff *msg,
        return 0;
 
 nla_put_failure:
+       err = -EMSGSIZE;
+sb_occ_get_failure:
        genlmsg_cancel(msg, hdr);
-       return -EMSGSIZE;
+       return err;
 }
 
 static int devlink_nl_cmd_sb_port_pool_get_doit(struct sk_buff *skb,
@@ -8254,8 +8256,6 @@ static int __devlink_port_attrs_set(struct devlink_port *devlink_port,
 {
        struct devlink_port_attrs *attrs = &devlink_port->attrs;
 
-       if (WARN_ON(devlink_port->registered))
-               return -EEXIST;
        devlink_port->attrs_set = true;
        attrs->flavour = flavour;
        if (attrs->switch_id.id_len) {
@@ -8279,6 +8279,8 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 {
        int ret;
 
+       if (WARN_ON(devlink_port->registered))
+               return;
        devlink_port->attrs = *attrs;
        ret = __devlink_port_attrs_set(devlink_port, attrs->flavour);
        if (ret)
@@ -8301,6 +8303,8 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 contro
        struct devlink_port_attrs *attrs = &devlink_port->attrs;
        int ret;
 
+       if (WARN_ON(devlink_port->registered))
+               return;
        ret = __devlink_port_attrs_set(devlink_port,
                                       DEVLINK_PORT_FLAVOUR_PCI_PF);
        if (ret)
@@ -8326,6 +8330,8 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 contro
        struct devlink_port_attrs *attrs = &devlink_port->attrs;
        int ret;
 
+       if (WARN_ON(devlink_port->registered))
+               return;
        ret = __devlink_port_attrs_set(devlink_port,
                                       DEVLINK_PORT_FLAVOUR_PCI_VF);
        if (ret)
index 8e39e28..9500d28 100644 (file)
@@ -235,6 +235,8 @@ static int neigh_forced_gc(struct neigh_table *tbl)
 
                        write_lock(&n->lock);
                        if ((n->nud_state == NUD_FAILED) ||
+                           (tbl->is_multicast &&
+                            tbl->is_multicast(n->primary_key)) ||
                            time_after(tref, n->updated))
                                remove = true;
                        write_unlock(&n->lock);
index c310c7c..9609482 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/slab.h>
 #include <linux/export.h>
 #include <linux/if_vlan.h>
+#include <net/dsa.h>
 #include <net/tcp.h>
 #include <net/udp.h>
 #include <net/addrconf.h>
@@ -657,15 +658,15 @@ EXPORT_SYMBOL_GPL(__netpoll_setup);
 
 int netpoll_setup(struct netpoll *np)
 {
-       struct net_device *ndev = NULL;
+       struct net_device *ndev = NULL, *dev = NULL;
+       struct net *net = current->nsproxy->net_ns;
        struct in_device *in_dev;
        int err;
 
        rtnl_lock();
-       if (np->dev_name[0]) {
-               struct net *net = current->nsproxy->net_ns;
+       if (np->dev_name[0])
                ndev = __dev_get_by_name(net, np->dev_name);
-       }
+
        if (!ndev) {
                np_err(np, "%s doesn't exist, aborting\n", np->dev_name);
                err = -ENODEV;
@@ -673,6 +674,19 @@ int netpoll_setup(struct netpoll *np)
        }
        dev_hold(ndev);
 
+       /* bring up DSA management network devices up first */
+       for_each_netdev(net, dev) {
+               if (!netdev_uses_dsa(dev))
+                       continue;
+
+               err = dev_change_flags(dev, dev->flags | IFF_UP, NULL);
+               if (err < 0) {
+                       np_err(np, "%s failed to open %s\n",
+                              np->dev_name, dev->name);
+                       goto put;
+               }
+       }
+
        if (netdev_master_upper_dev_get(ndev)) {
                np_err(np, "%s is a slave device, aborting\n", np->dev_name);
                err = -EBUSY;
index 654182e..25cdbb2 100644 (file)
@@ -170,10 +170,12 @@ static int sk_msg_free_elem(struct sock *sk, struct sk_msg *msg, u32 i,
        struct scatterlist *sge = sk_msg_elem(msg, i);
        u32 len = sge->length;
 
-       if (charge)
-               sk_mem_uncharge(sk, len);
-       if (!msg->skb)
+       /* When the skb owns the memory we free it from consume_skb path. */
+       if (!msg->skb) {
+               if (charge)
+                       sk_mem_uncharge(sk, len);
                put_page(sg_page(sge));
+       }
        memset(sge, 0, sizeof(*sge));
        return len;
 }
@@ -397,28 +399,45 @@ out:
 }
 EXPORT_SYMBOL_GPL(sk_msg_memcopy_from_iter);
 
-static int sk_psock_skb_ingress(struct sk_psock *psock, struct sk_buff *skb)
+static struct sk_msg *sk_psock_create_ingress_msg(struct sock *sk,
+                                                 struct sk_buff *skb)
 {
-       struct sock *sk = psock->sk;
-       int copied = 0, num_sge;
        struct sk_msg *msg;
 
+       if (atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf)
+               return NULL;
+
+       if (!sk_rmem_schedule(sk, skb, skb->truesize))
+               return NULL;
+
        msg = kzalloc(sizeof(*msg), __GFP_NOWARN | GFP_ATOMIC);
        if (unlikely(!msg))
-               return -EAGAIN;
-       if (!sk_rmem_schedule(sk, skb, skb->len)) {
-               kfree(msg);
-               return -EAGAIN;
-       }
+               return NULL;
 
        sk_msg_init(msg);
+       return msg;
+}
+
+static int sk_psock_skb_ingress_enqueue(struct sk_buff *skb,
+                                       struct sk_psock *psock,
+                                       struct sock *sk,
+                                       struct sk_msg *msg)
+{
+       int num_sge, copied;
+
+       /* skb linearize may fail with ENOMEM, but lets simply try again
+        * later if this happens. Under memory pressure we don't want to
+        * drop the skb. We need to linearize the skb so that the mapping
+        * in skb_to_sgvec can not error.
+        */
+       if (skb_linearize(skb))
+               return -EAGAIN;
        num_sge = skb_to_sgvec(skb, msg->sg.data, 0, skb->len);
        if (unlikely(num_sge < 0)) {
                kfree(msg);
                return num_sge;
        }
 
-       sk_mem_charge(sk, skb->len);
        copied = skb->len;
        msg->sg.start = 0;
        msg->sg.size = copied;
@@ -430,6 +449,48 @@ static int sk_psock_skb_ingress(struct sk_psock *psock, struct sk_buff *skb)
        return copied;
 }
 
+static int sk_psock_skb_ingress_self(struct sk_psock *psock, struct sk_buff *skb);
+
+static int sk_psock_skb_ingress(struct sk_psock *psock, struct sk_buff *skb)
+{
+       struct sock *sk = psock->sk;
+       struct sk_msg *msg;
+
+       /* If we are receiving on the same sock skb->sk is already assigned,
+        * skip memory accounting and owner transition seeing it already set
+        * correctly.
+        */
+       if (unlikely(skb->sk == sk))
+               return sk_psock_skb_ingress_self(psock, skb);
+       msg = sk_psock_create_ingress_msg(sk, skb);
+       if (!msg)
+               return -EAGAIN;
+
+       /* This will transition ownership of the data from the socket where
+        * the BPF program was run initiating the redirect to the socket
+        * we will eventually receive this data on. The data will be released
+        * from skb_consume found in __tcp_bpf_recvmsg() after its been copied
+        * into user buffers.
+        */
+       skb_set_owner_r(skb, sk);
+       return sk_psock_skb_ingress_enqueue(skb, psock, sk, msg);
+}
+
+/* Puts an skb on the ingress queue of the socket already assigned to the
+ * skb. In this case we do not need to check memory limits or skb_set_owner_r
+ * because the skb is already accounted for here.
+ */
+static int sk_psock_skb_ingress_self(struct sk_psock *psock, struct sk_buff *skb)
+{
+       struct sk_msg *msg = kzalloc(sizeof(*msg), __GFP_NOWARN | GFP_ATOMIC);
+       struct sock *sk = psock->sk;
+
+       if (unlikely(!msg))
+               return -EAGAIN;
+       sk_msg_init(msg);
+       return sk_psock_skb_ingress_enqueue(skb, psock, sk, msg);
+}
+
 static int sk_psock_handle_skb(struct sk_psock *psock, struct sk_buff *skb,
                               u32 off, u32 len, bool ingress)
 {
@@ -789,7 +850,7 @@ static void sk_psock_verdict_apply(struct sk_psock *psock,
                 * retrying later from workqueue.
                 */
                if (skb_queue_empty(&psock->ingress_skb)) {
-                       err = sk_psock_skb_ingress(psock, skb);
+                       err = sk_psock_skb_ingress_self(psock, skb);
                }
                if (err < 0) {
                        skb_queue_tail(&psock->ingress_skb, skb);
index 8ee4cdb..1c9f4df 100644 (file)
@@ -280,7 +280,7 @@ int ethnl_set_features(struct sk_buff *skb, struct genl_info *info)
                                          active_diff_mask, compact);
        }
        if (mod)
-               ethtool_notify(dev, ETHTOOL_MSG_FEATURES_NTF, NULL);
+               netdev_features_change(dev);
 
 out_rtnl:
        rtnl_unlock();
index 687971d..922dd73 100644 (file)
@@ -125,6 +125,7 @@ static int arp_constructor(struct neighbour *neigh);
 static void arp_solicit(struct neighbour *neigh, struct sk_buff *skb);
 static void arp_error_report(struct neighbour *neigh, struct sk_buff *skb);
 static void parp_redo(struct sk_buff *skb);
+static int arp_is_multicast(const void *pkey);
 
 static const struct neigh_ops arp_generic_ops = {
        .family =               AF_INET,
@@ -156,6 +157,7 @@ struct neigh_table arp_tbl = {
        .key_eq         = arp_key_eq,
        .constructor    = arp_constructor,
        .proxy_redo     = parp_redo,
+       .is_multicast   = arp_is_multicast,
        .id             = "arp_cache",
        .parms          = {
                .tbl                    = &arp_tbl,
@@ -928,6 +930,10 @@ static void parp_redo(struct sk_buff *skb)
        arp_process(dev_net(skb->dev), NULL, skb);
 }
 
+static int arp_is_multicast(const void *pkey)
+{
+       return ipv4_is_multicast(*((__be32 *)pkey));
+}
 
 /*
  *     Receive an arp request from the device layer.
index 86a23e4..b87140a 100644 (file)
@@ -696,7 +696,7 @@ int fib_gw_from_via(struct fib_config *cfg, struct nlattr *nla,
                cfg->fc_gw4 = *((__be32 *)via->rtvia_addr);
                break;
        case AF_INET6:
-#ifdef CONFIG_IPV6
+#if IS_ENABLED(CONFIG_IPV6)
                if (alen != sizeof(struct in6_addr)) {
                        NL_SET_ERR_MSG(extack, "Invalid IPv6 address in RTA_VIA");
                        return -EINVAL;
index 366a450..93474b1 100644 (file)
@@ -479,8 +479,10 @@ static int inet_req_diag_fill(struct sock *sk, struct sk_buff *skb,
        r->idiag_inode  = 0;
 
        if (net_admin && nla_put_u32(skb, INET_DIAG_MARK,
-                                    inet_rsk(reqsk)->ir_mark))
+                                    inet_rsk(reqsk)->ir_mark)) {
+               nlmsg_cancel(skb, nlh);
                return -EMSGSIZE;
+       }
 
        nlmsg_end(skb, nlh);
        return 0;
index 8b04d1d..ee65c92 100644 (file)
@@ -608,9 +608,6 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
                        ttl = ip4_dst_hoplimit(&rt->dst);
        }
 
-       if (!df && skb->protocol == htons(ETH_P_IP))
-               df = inner_iph->frag_off & htons(IP_DF);
-
        headroom += LL_RESERVED_SPACE(rt->dst.dev) + rt->dst.header_len;
        if (headroom > dev->needed_headroom)
                dev->needed_headroom = headroom;
index 25f1caf..e25be2d 100644 (file)
@@ -263,7 +263,7 @@ static int iptunnel_pmtud_check_icmp(struct sk_buff *skb, int mtu)
        const struct icmphdr *icmph = icmp_hdr(skb);
        const struct iphdr *iph = ip_hdr(skb);
 
-       if (mtu <= 576 || iph->frag_off != htons(IP_DF))
+       if (mtu < 576 || iph->frag_off != htons(IP_DF))
                return 0;
 
        if (ipv4_is_lbcast(iph->daddr)  || ipv4_is_multicast(iph->daddr) ||
@@ -359,7 +359,7 @@ static int iptunnel_pmtud_check_icmpv6(struct sk_buff *skb, int mtu)
        __be16 frag_off;
        int offset;
 
-       if (mtu <= IPV6_MIN_MTU)
+       if (mtu < IPV6_MIN_MTU)
                return 0;
 
        if (stype == IPV6_ADDR_ANY || stype == IPV6_ADDR_MULTICAST ||
index a058213..7c84103 100644 (file)
 #include <net/netfilter/nf_queue.h>
 
 /* route_me_harder function, used by iptable_nat, iptable_mangle + ip_queue */
-int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned int addr_type)
+int ip_route_me_harder(struct net *net, struct sock *sk, struct sk_buff *skb, unsigned int addr_type)
 {
        const struct iphdr *iph = ip_hdr(skb);
        struct rtable *rt;
        struct flowi4 fl4 = {};
        __be32 saddr = iph->saddr;
-       const struct sock *sk = skb_to_full_sk(skb);
-       __u8 flags = sk ? inet_sk_flowi_flags(sk) : 0;
+       __u8 flags;
        struct net_device *dev = skb_dst(skb)->dev;
        unsigned int hh_len;
 
+       sk = sk_to_full_sk(sk);
+       flags = sk ? inet_sk_flowi_flags(sk) : 0;
+
        if (addr_type == RTN_UNSPEC)
                addr_type = inet_addr_type_dev_table(net, dev, saddr);
        if (addr_type == RTN_LOCAL || addr_type == RTN_UNICAST)
index f703a71..8330795 100644 (file)
@@ -62,7 +62,7 @@ ipt_mangle_out(struct sk_buff *skb, const struct nf_hook_state *state)
                    iph->daddr != daddr ||
                    skb->mark != mark ||
                    iph->tos != tos) {
-                       err = ip_route_me_harder(state->net, skb, RTN_UNSPEC);
+                       err = ip_route_me_harder(state->net, state->sk, skb, RTN_UNSPEC);
                        if (err < 0)
                                ret = NF_DROP_ERR(err);
                }
index 9dcfa4e..93b0773 100644 (file)
@@ -145,7 +145,7 @@ void nf_send_reset(struct net *net, struct sk_buff *oldskb, int hook)
                                   ip4_dst_hoplimit(skb_dst(nskb)));
        nf_reject_ip_tcphdr_put(nskb, oldskb, oth);
 
-       if (ip_route_me_harder(net, nskb, RTN_UNSPEC))
+       if (ip_route_me_harder(net, nskb->sk, nskb, RTN_UNSPEC))
                goto free_nskb;
 
        niph = ip_hdr(nskb);
index 6ac473b..00dc3f9 100644 (file)
@@ -331,7 +331,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)
        __u32 cookie = ntohl(th->ack_seq) - 1;
        struct sock *ret = sk;
        struct request_sock *req;
-       int mss;
+       int full_space, mss;
        struct rtable *rt;
        __u8 rcv_wscale;
        struct flowi4 fl4;
@@ -427,8 +427,13 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)
 
        /* Try to redo what tcp_v4_send_synack did. */
        req->rsk_window_clamp = tp->window_clamp ? :dst_metric(&rt->dst, RTAX_WINDOW);
+       /* limit the window selection if the user enforce a smaller rx buffer */
+       full_space = tcp_full_space(sk);
+       if (sk->sk_userlocks & SOCK_RCVBUF_LOCK &&
+           (req->rsk_window_clamp > full_space || req->rsk_window_clamp == 0))
+               req->rsk_window_clamp = full_space;
 
-       tcp_select_initial_window(sk, tcp_full_space(sk), req->mss,
+       tcp_select_initial_window(sk, full_space, req->mss,
                                  &req->rsk_rcv_wnd, &req->rsk_window_clamp,
                                  ireq->wscale_ok, &rcv_wscale,
                                  dst_metric(&rt->dst, RTAX_INITRWND));
index 6c4d79b..6ea3dc2 100644 (file)
@@ -945,7 +945,7 @@ static void bbr_update_min_rtt(struct sock *sk, const struct rate_sample *rs)
        filter_expired = after(tcp_jiffies32,
                               bbr->min_rtt_stamp + bbr_min_rtt_win_sec * HZ);
        if (rs->rtt_us >= 0 &&
-           (rs->rtt_us <= bbr->min_rtt_us ||
+           (rs->rtt_us < bbr->min_rtt_us ||
             (filter_expired && !rs->is_ack_delayed))) {
                bbr->min_rtt_us = rs->rtt_us;
                bbr->min_rtt_stamp = tcp_jiffies32;
index 37f4cb2..bc7d2a5 100644 (file)
@@ -15,8 +15,8 @@ int __tcp_bpf_recvmsg(struct sock *sk, struct sk_psock *psock,
 {
        struct iov_iter *iter = &msg->msg_iter;
        int peek = flags & MSG_PEEK;
-       int i, ret, copied = 0;
        struct sk_msg *msg_rx;
+       int i, copied = 0;
 
        msg_rx = list_first_entry_or_null(&psock->ingress_msg,
                                          struct sk_msg, list);
@@ -37,17 +37,16 @@ int __tcp_bpf_recvmsg(struct sock *sk, struct sk_psock *psock,
                        page = sg_page(sge);
                        if (copied + copy > len)
                                copy = len - copied;
-                       ret = copy_page_to_iter(page, sge->offset, copy, iter);
-                       if (ret != copy) {
-                               msg_rx->sg.start = i;
-                               return -EFAULT;
-                       }
+                       copy = copy_page_to_iter(page, sge->offset, copy, iter);
+                       if (!copy)
+                               return copied ? copied : -EFAULT;
 
                        copied += copy;
                        if (likely(!peek)) {
                                sge->offset += copy;
                                sge->length -= copy;
-                               sk_mem_uncharge(sk, copy);
+                               if (!msg_rx->skb)
+                                       sk_mem_uncharge(sk, copy);
                                msg_rx->sg.size -= copy;
 
                                if (!sge->length) {
@@ -56,6 +55,11 @@ int __tcp_bpf_recvmsg(struct sock *sk, struct sk_psock *psock,
                                                put_page(page);
                                }
                        } else {
+                               /* Lets not optimize peek case if copy_page_to_iter
+                                * didn't copy the entire length lets just break.
+                                */
+                               if (copy != sge->length)
+                                       return copied;
                                sk_msg_iter_var_next(i);
                        }
 
index e67a66f..c62805c 100644 (file)
@@ -366,7 +366,7 @@ out:
 static struct sk_buff *udp_gro_receive_segment(struct list_head *head,
                                               struct sk_buff *skb)
 {
-       struct udphdr *uh = udp_hdr(skb);
+       struct udphdr *uh = udp_gro_udphdr(skb);
        struct sk_buff *pp = NULL;
        struct udphdr *uh2;
        struct sk_buff *p;
@@ -500,12 +500,22 @@ out:
 }
 EXPORT_SYMBOL(udp_gro_receive);
 
+static struct sock *udp4_gro_lookup_skb(struct sk_buff *skb, __be16 sport,
+                                       __be16 dport)
+{
+       const struct iphdr *iph = skb_gro_network_header(skb);
+
+       return __udp4_lib_lookup(dev_net(skb->dev), iph->saddr, sport,
+                                iph->daddr, dport, inet_iif(skb),
+                                inet_sdif(skb), &udp_table, NULL);
+}
+
 INDIRECT_CALLABLE_SCOPE
 struct sk_buff *udp4_gro_receive(struct list_head *head, struct sk_buff *skb)
 {
        struct udphdr *uh = udp_gro_udphdr(skb);
+       struct sock *sk = NULL;
        struct sk_buff *pp;
-       struct sock *sk;
 
        if (unlikely(!uh))
                goto flush;
@@ -523,7 +533,10 @@ struct sk_buff *udp4_gro_receive(struct list_head *head, struct sk_buff *skb)
 skip:
        NAPI_GRO_CB(skb)->is_ipv6 = 0;
        rcu_read_lock();
-       sk = static_branch_unlikely(&udp_encap_needed_key) ? udp4_lib_lookup_skb(skb, uh->source, uh->dest) : NULL;
+
+       if (static_branch_unlikely(&udp_encap_needed_key))
+               sk = udp4_gro_lookup_skb(skb, uh->source, uh->dest);
+
        pp = udp_gro_receive(head, skb, uh, sk);
        rcu_read_unlock();
        return pp;
index dc19aff..fb0648e 100644 (file)
@@ -64,14 +64,14 @@ static int xfrm_tunnel_err(struct sk_buff *skb, u32 info)
 static struct xfrm_tunnel xfrm_tunnel_handler __read_mostly = {
        .handler        =       xfrm_tunnel_rcv,
        .err_handler    =       xfrm_tunnel_err,
-       .priority       =       3,
+       .priority       =       4,
 };
 
 #if IS_ENABLED(CONFIG_IPV6)
 static struct xfrm_tunnel xfrm64_tunnel_handler __read_mostly = {
        .handler        =       xfrm_tunnel_rcv,
        .err_handler    =       xfrm_tunnel_err,
-       .priority       =       2,
+       .priority       =       3,
 };
 #endif
 
index 01146b6..8b6eb38 100644 (file)
@@ -5022,8 +5022,10 @@ static int inet6_fill_ifmcaddr(struct sk_buff *skb, struct ifmcaddr6 *ifmca,
                return -EMSGSIZE;
 
        if (args->netnsid >= 0 &&
-           nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid))
+           nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid)) {
+               nlmsg_cancel(skb, nlh);
                return -EMSGSIZE;
+       }
 
        put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
        if (nla_put_in6_addr(skb, IFA_MULTICAST, &ifmca->mca_addr) < 0 ||
@@ -5054,8 +5056,10 @@ static int inet6_fill_ifacaddr(struct sk_buff *skb, struct ifacaddr6 *ifaca,
                return -EMSGSIZE;
 
        if (args->netnsid >= 0 &&
-           nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid))
+           nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid)) {
+               nlmsg_cancel(skb, nlh);
                return -EMSGSIZE;
+       }
 
        put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
        if (nla_put_in6_addr(skb, IFA_ANYCAST, &ifaca->aca_addr) < 0 ||
index d88d976..440080d 100644 (file)
@@ -588,7 +588,8 @@ static int ah6_input(struct xfrm_state *x, struct sk_buff *skb)
        memcpy(auth_data, ah->auth_data, ahp->icv_trunc_len);
        memset(ah->auth_data, 0, ahp->icv_trunc_len);
 
-       if (ipv6_clear_mutable_options(ip6h, hdr_len, XFRM_POLICY_IN))
+       err = ipv6_clear_mutable_options(ip6h, hdr_len, XFRM_POLICY_IN);
+       if (err)
                goto out_free;
 
        ip6h->priority    = 0;
index ec448b7..8956144 100644 (file)
@@ -158,7 +158,13 @@ static bool is_ineligible(const struct sk_buff *skb)
                tp = skb_header_pointer(skb,
                        ptr+offsetof(struct icmp6hdr, icmp6_type),
                        sizeof(_type), &_type);
-               if (!tp || !(*tp & ICMPV6_INFOMSG_MASK))
+
+               /* Based on RFC 8200, Section 4.5 Fragment Header, return
+                * false if this is a fragment packet with no icmp header info.
+                */
+               if (!tp && frag_off != 0)
+                       return false;
+               else if (!tp || !(*tp & ICMPV6_INFOMSG_MASK))
                        return true;
        }
        return false;
index a0217e5..648db3f 100644 (file)
@@ -1271,6 +1271,8 @@ route_lookup:
        if (max_headroom > dev->needed_headroom)
                dev->needed_headroom = max_headroom;
 
+       skb_set_inner_ipproto(skb, proto);
+
        err = ip6_tnl_encap(skb, t, &proto, fl6);
        if (err)
                return err;
@@ -1280,8 +1282,6 @@ route_lookup:
                ipv6_push_frag_opts(skb, &opt.ops, &proto);
        }
 
-       skb_set_inner_ipproto(skb, proto);
-
        skb_push(skb, sizeof(struct ipv6hdr));
        skb_reset_network_header(skb);
        ipv6h = ipv6_hdr(skb);
index 27f29b9..7671747 100644 (file)
@@ -81,6 +81,7 @@ static void ndisc_error_report(struct neighbour *neigh, struct sk_buff *skb);
 static int pndisc_constructor(struct pneigh_entry *n);
 static void pndisc_destructor(struct pneigh_entry *n);
 static void pndisc_redo(struct sk_buff *skb);
+static int ndisc_is_multicast(const void *pkey);
 
 static const struct neigh_ops ndisc_generic_ops = {
        .family =               AF_INET6,
@@ -115,6 +116,7 @@ struct neigh_table nd_tbl = {
        .pconstructor = pndisc_constructor,
        .pdestructor =  pndisc_destructor,
        .proxy_redo =   pndisc_redo,
+       .is_multicast = ndisc_is_multicast,
        .allow_add  =   ndisc_allow_add,
        .id =           "ndisc_cache",
        .parms = {
@@ -1706,6 +1708,11 @@ static void pndisc_redo(struct sk_buff *skb)
        kfree_skb(skb);
 }
 
+static int ndisc_is_multicast(const void *pkey)
+{
+       return ipv6_addr_is_multicast((struct in6_addr *)pkey);
+}
+
 static bool ndisc_suppress_frag_ndisc(struct sk_buff *skb)
 {
        struct inet6_dev *idev = __in6_dev_get(skb->dev);
index 6d0e942..ab9a279 100644 (file)
 #include <net/netfilter/ipv6/nf_defrag_ipv6.h>
 #include "../bridge/br_private.h"
 
-int ip6_route_me_harder(struct net *net, struct sk_buff *skb)
+int ip6_route_me_harder(struct net *net, struct sock *sk_partial, struct sk_buff *skb)
 {
        const struct ipv6hdr *iph = ipv6_hdr(skb);
-       struct sock *sk = sk_to_full_sk(skb->sk);
+       struct sock *sk = sk_to_full_sk(sk_partial);
        unsigned int hh_len;
        struct dst_entry *dst;
        int strict = (ipv6_addr_type(&iph->daddr) &
@@ -84,7 +84,7 @@ static int nf_ip6_reroute(struct sk_buff *skb,
                if (!ipv6_addr_equal(&iph->daddr, &rt_info->daddr) ||
                    !ipv6_addr_equal(&iph->saddr, &rt_info->saddr) ||
                    skb->mark != rt_info->mark)
-                       return ip6_route_me_harder(entry->state.net, skb);
+                       return ip6_route_me_harder(entry->state.net, entry->state.sk, skb);
        }
        return 0;
 }
index 1a27486..cee7480 100644 (file)
@@ -57,7 +57,7 @@ ip6t_mangle_out(struct sk_buff *skb, const struct nf_hook_state *state)
             skb->mark != mark ||
             ipv6_hdr(skb)->hop_limit != hop_limit ||
             flowlabel != *((u_int32_t *)ipv6_hdr(skb)))) {
-               err = ip6_route_me_harder(state->net, skb);
+               err = ip6_route_me_harder(state->net, state->sk, skb);
                if (err < 0)
                        ret = NF_DROP_ERR(err);
        }
index 054d287..c129ad3 100644 (file)
@@ -440,6 +440,7 @@ find_prev_fhdr(struct sk_buff *skb, u8 *prevhdrp, int *prevhoff, int *fhoff)
 int nf_ct_frag6_gather(struct net *net, struct sk_buff *skb, u32 user)
 {
        u16 savethdr = skb->transport_header;
+       u8 nexthdr = NEXTHDR_FRAGMENT;
        int fhoff, nhoff, ret;
        struct frag_hdr *fhdr;
        struct frag_queue *fq;
@@ -455,6 +456,14 @@ int nf_ct_frag6_gather(struct net *net, struct sk_buff *skb, u32 user)
        if (find_prev_fhdr(skb, &prevhdr, &nhoff, &fhoff) < 0)
                return 0;
 
+       /* Discard the first fragment if it does not include all headers
+        * RFC 8200, Section 4.5
+        */
+       if (ipv6frag_thdr_truncated(skb, fhoff, &nexthdr)) {
+               pr_debug("Drop incomplete fragment\n");
+               return 0;
+       }
+
        if (!pskb_may_pull(skb, fhoff + sizeof(*fhdr)))
                return -ENOMEM;
 
index 1f5d4d1..47a0dc4 100644 (file)
@@ -42,6 +42,8 @@
 #include <linux/skbuff.h>
 #include <linux/slab.h>
 #include <linux/export.h>
+#include <linux/tcp.h>
+#include <linux/udp.h>
 
 #include <net/sock.h>
 #include <net/snmp.h>
@@ -322,6 +324,7 @@ static int ipv6_frag_rcv(struct sk_buff *skb)
        struct frag_queue *fq;
        const struct ipv6hdr *hdr = ipv6_hdr(skb);
        struct net *net = dev_net(skb_dst(skb)->dev);
+       u8 nexthdr;
        int iif;
 
        if (IP6CB(skb)->flags & IP6SKB_FRAGMENTED)
@@ -351,6 +354,20 @@ static int ipv6_frag_rcv(struct sk_buff *skb)
                return 1;
        }
 
+       /* RFC 8200, Section 4.5 Fragment Header:
+        * If the first fragment does not include all headers through an
+        * Upper-Layer header, then that fragment should be discarded and
+        * an ICMP Parameter Problem, Code 3, message should be sent to
+        * the source of the fragment, with the Pointer field set to zero.
+        */
+       nexthdr = hdr->nexthdr;
+       if (ipv6frag_thdr_truncated(skb, skb_transport_offset(skb), &nexthdr)) {
+               __IP6_INC_STATS(net, __in6_dev_get_safely(skb->dev),
+                               IPSTATS_MIB_INHDRERRORS);
+               icmpv6_param_prob(skb, ICMPV6_HDR_INCOMP, 0);
+               return -1;
+       }
+
        iif = skb->dev ? skb->dev->ifindex : 0;
        fq = fq_find(net, fhdr->identification, hdr, iif);
        if (fq) {
index 5e2c34c..5e7983c 100644 (file)
@@ -1128,7 +1128,6 @@ static void ipip6_tunnel_bind_dev(struct net_device *dev)
        if (tdev && !netif_is_l3_master(tdev)) {
                int t_hlen = tunnel->hlen + sizeof(struct iphdr);
 
-               dev->hard_header_len = tdev->hard_header_len + sizeof(struct iphdr);
                dev->mtu = tdev->mtu - t_hlen;
                if (dev->mtu < IPV6_MIN_MTU)
                        dev->mtu = IPV6_MIN_MTU;
@@ -1426,7 +1425,6 @@ static void ipip6_tunnel_setup(struct net_device *dev)
        dev->priv_destructor    = ipip6_dev_free;
 
        dev->type               = ARPHRD_SIT;
-       dev->hard_header_len    = LL_MAX_HEADER + t_hlen;
        dev->mtu                = ETH_DATA_LEN - t_hlen;
        dev->min_mtu            = IPV6_MIN_MTU;
        dev->max_mtu            = IP6_MAX_MTU - t_hlen;
index e796a64..9b6cae1 100644 (file)
@@ -136,7 +136,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
        __u32 cookie = ntohl(th->ack_seq) - 1;
        struct sock *ret = sk;
        struct request_sock *req;
-       int mss;
+       int full_space, mss;
        struct dst_entry *dst;
        __u8 rcv_wscale;
        u32 tsoff = 0;
@@ -241,7 +241,13 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
        }
 
        req->rsk_window_clamp = tp->window_clamp ? :dst_metric(dst, RTAX_WINDOW);
-       tcp_select_initial_window(sk, tcp_full_space(sk), req->mss,
+       /* limit the window selection if the user enforce a smaller rx buffer */
+       full_space = tcp_full_space(sk);
+       if (sk->sk_userlocks & SOCK_RCVBUF_LOCK &&
+           (req->rsk_window_clamp > full_space || req->rsk_window_clamp == 0))
+               req->rsk_window_clamp = full_space;
+
+       tcp_select_initial_window(sk, full_space, req->mss,
                                  &req->rsk_rcv_wnd, &req->rsk_window_clamp,
                                  ireq->wscale_ok, &rcv_wscale,
                                  dst_metric(dst, RTAX_INITRWND));
index 584157a..f9e888d 100644 (file)
@@ -111,12 +111,22 @@ out:
        return segs;
 }
 
+static struct sock *udp6_gro_lookup_skb(struct sk_buff *skb, __be16 sport,
+                                       __be16 dport)
+{
+       const struct ipv6hdr *iph = skb_gro_network_header(skb);
+
+       return __udp6_lib_lookup(dev_net(skb->dev), &iph->saddr, sport,
+                                &iph->daddr, dport, inet6_iif(skb),
+                                inet6_sdif(skb), &udp_table, NULL);
+}
+
 INDIRECT_CALLABLE_SCOPE
 struct sk_buff *udp6_gro_receive(struct list_head *head, struct sk_buff *skb)
 {
        struct udphdr *uh = udp_gro_udphdr(skb);
+       struct sock *sk = NULL;
        struct sk_buff *pp;
-       struct sock *sk;
 
        if (unlikely(!uh))
                goto flush;
@@ -135,7 +145,10 @@ struct sk_buff *udp6_gro_receive(struct list_head *head, struct sk_buff *skb)
 skip:
        NAPI_GRO_CB(skb)->is_ipv6 = 1;
        rcu_read_lock();
-       sk = static_branch_unlikely(&udpv6_encap_needed_key) ? udp6_lib_lookup_skb(skb, uh->source, uh->dest) : NULL;
+
+       if (static_branch_unlikely(&udpv6_encap_needed_key))
+               sk = udp6_gro_lookup_skb(skb, uh->source, uh->dest);
+
        pp = udp_gro_receive(head, skb, uh, sk);
        rcu_read_unlock();
        return pp;
index 25b7ebd..f696d46 100644 (file)
@@ -303,13 +303,13 @@ static const struct xfrm_type xfrm6_tunnel_type = {
 static struct xfrm6_tunnel xfrm6_tunnel_handler __read_mostly = {
        .handler        = xfrm6_tunnel_rcv,
        .err_handler    = xfrm6_tunnel_err,
-       .priority       = 2,
+       .priority       = 3,
 };
 
 static struct xfrm6_tunnel xfrm46_tunnel_handler __read_mostly = {
        .handler        = xfrm6_tunnel_rcv,
        .err_handler    = xfrm6_tunnel_err,
-       .priority       = 2,
+       .priority       = 3,
 };
 
 static int __net_init xfrm6_tunnel_net_init(struct net *net)
index d805720..047238f 100644 (file)
@@ -1434,7 +1434,8 @@ static int iucv_sock_shutdown(struct socket *sock, int how)
                break;
        }
 
-       if (how == SEND_SHUTDOWN || how == SHUTDOWN_MASK) {
+       if ((how == SEND_SHUTDOWN || how == SHUTDOWN_MASK) &&
+           sk->sk_state == IUCV_CONNECTED) {
                if (iucv->transport == AF_IUCV_TRANS_IUCV) {
                        txmsg.class = 0;
                        txmsg.tag = 0;
index f400240..6adfcb9 100644 (file)
@@ -5464,6 +5464,7 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
                        struct cfg80211_assoc_request *req)
 {
        bool is_6ghz = req->bss->channel->band == NL80211_BAND_6GHZ;
+       bool is_5ghz = req->bss->channel->band == NL80211_BAND_5GHZ;
        struct ieee80211_local *local = sdata->local;
        struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
        struct ieee80211_bss *bss = (void *)req->bss->priv;
@@ -5616,7 +5617,7 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
        if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
                memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
                       sizeof(struct ieee80211_vht_cap));
-       else if (!is_6ghz)
+       else if (is_5ghz)
                ifmgd->flags |= IEEE80211_STA_DISABLE_VHT |
                                IEEE80211_STA_DISABLE_HE;
        rcu_read_unlock();
index 86bc469..b13b1da 100644 (file)
@@ -274,7 +274,7 @@ minstrel_tx_status(void *priv, struct ieee80211_supported_band *sband,
        success = !!(info->flags & IEEE80211_TX_STAT_ACK);
 
        for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
-               if (ar[i].idx < 0)
+               if (ar[i].idx < 0 || !ar[i].count)
                        break;
 
                ndx = rix_to_ndx(mi, ar[i].idx);
@@ -287,12 +287,6 @@ minstrel_tx_status(void *priv, struct ieee80211_supported_band *sband,
                        mi->r[ndx].stats.success += success;
        }
 
-       if ((info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) && (i >= 0))
-               mi->sample_packets++;
-
-       if (mi->sample_deferred > 0)
-               mi->sample_deferred--;
-
        if (time_after(jiffies, mi->last_stats_update +
                                mp->update_interval / (mp->new_avg ? 2 : 1)))
                minstrel_update_stats(mp, mi);
@@ -367,7 +361,7 @@ minstrel_get_rate(void *priv, struct ieee80211_sta *sta,
                return;
 
        delta = (mi->total_packets * sampling_ratio / 100) -
-                       (mi->sample_packets + mi->sample_deferred / 2);
+                       mi->sample_packets;
 
        /* delta < 0: no sampling required */
        prev_sample = mi->prev_sample;
@@ -376,7 +370,6 @@ minstrel_get_rate(void *priv, struct ieee80211_sta *sta,
                return;
 
        if (mi->total_packets >= 10000) {
-               mi->sample_deferred = 0;
                mi->sample_packets = 0;
                mi->total_packets = 0;
        } else if (delta > mi->n_rates * 2) {
@@ -401,19 +394,8 @@ minstrel_get_rate(void *priv, struct ieee80211_sta *sta,
         * rate sampling method should be used.
         * Respect such rates that are not sampled for 20 interations.
         */
-       if (mrr_capable &&
-           msr->perfect_tx_time > mr->perfect_tx_time &&
-           msr->stats.sample_skipped < 20) {
-               /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark
-                * packets that have the sampling rate deferred to the
-                * second MRR stage. Increase the sample counter only
-                * if the deferred sample rate was actually used.
-                * Use the sample_deferred counter to make sure that
-                * the sampling is not done in large bursts */
-               info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
-               rate++;
-               mi->sample_deferred++;
-       } else {
+       if (msr->perfect_tx_time < mr->perfect_tx_time ||
+           msr->stats.sample_skipped >= 20) {
                if (!msr->sample_limit)
                        return;
 
@@ -433,6 +415,7 @@ minstrel_get_rate(void *priv, struct ieee80211_sta *sta,
 
        rate->idx = mi->r[ndx].rix;
        rate->count = minstrel_get_retry_count(&mi->r[ndx], info);
+       info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
 }
 
 
index dbb43bc..86cd80b 100644 (file)
@@ -126,7 +126,6 @@ struct minstrel_sta_info {
        u8 max_prob_rate;
        unsigned int total_packets;
        unsigned int sample_packets;
-       int sample_deferred;
 
        unsigned int sample_row;
        unsigned int sample_column;
index fb4f2b9..ec6973e 100644 (file)
@@ -258,6 +258,24 @@ struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
  */
 void sta_info_free(struct ieee80211_local *local, struct sta_info *sta)
 {
+       /*
+        * If we had used sta_info_pre_move_state() then we might not
+        * have gone through the state transitions down again, so do
+        * it here now (and warn if it's inserted).
+        *
+        * This will clear state such as fast TX/RX that may have been
+        * allocated during state transitions.
+        */
+       while (sta->sta_state > IEEE80211_STA_NONE) {
+               int ret;
+
+               WARN_ON_ONCE(test_sta_flag(sta, WLAN_STA_INSERTED));
+
+               ret = sta_info_move_state(sta, sta->sta_state - 1);
+               if (WARN_ONCE(ret, "sta_info_move_state() returned %d\n", ret))
+                       break;
+       }
+
        if (sta->rate_ctrl)
                rate_control_free_sta(sta);
 
@@ -687,7 +705,7 @@ static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
  out_drop_sta:
        local->num_sta--;
        synchronize_net();
-       __cleanup_single_sta(sta);
+       cleanup_single_sta(sta);
  out_err:
        mutex_unlock(&local->sta_mtx);
        kfree(sinfo);
@@ -706,19 +724,13 @@ int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU)
 
        err = sta_info_insert_check(sta);
        if (err) {
+               sta_info_free(local, sta);
                mutex_unlock(&local->sta_mtx);
                rcu_read_lock();
-               goto out_free;
+               return err;
        }
 
-       err = sta_info_insert_finish(sta);
-       if (err)
-               goto out_free;
-
-       return 0;
- out_free:
-       sta_info_free(local, sta);
-       return err;
+       return sta_info_insert_finish(sta);
 }
 
 int sta_info_insert(struct sta_info *sta)
index 00ae81e..7afd076 100644 (file)
@@ -785,7 +785,7 @@ int sta_info_init(struct ieee80211_local *local);
 void sta_info_stop(struct ieee80211_local *local);
 
 /**
- * sta_info_flush - flush matching STA entries from the STA table
+ * __sta_info_flush - flush matching STA entries from the STA table
  *
  * Returns the number of removed STA entries.
  *
@@ -794,6 +794,13 @@ void sta_info_stop(struct ieee80211_local *local);
  */
 int __sta_info_flush(struct ieee80211_sub_if_data *sdata, bool vlans);
 
+/**
+ * sta_info_flush - flush matching STA entries from the STA table
+ *
+ * Returns the number of removed STA entries.
+ *
+ * @sdata: sdata to remove all stations from
+ */
 static inline int sta_info_flush(struct ieee80211_sub_if_data *sdata)
 {
        return __sta_info_flush(sdata, false);
index 6feb451..3485610 100644 (file)
@@ -49,7 +49,8 @@ static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
        int ac;
 
        if (info->flags & (IEEE80211_TX_CTL_NO_PS_BUFFER |
-                          IEEE80211_TX_CTL_AMPDU)) {
+                          IEEE80211_TX_CTL_AMPDU |
+                          IEEE80211_TX_CTL_HW_80211_ENCAP)) {
                ieee80211_free_txskb(&local->hw, skb);
                return;
        }
@@ -915,15 +916,6 @@ static void __ieee80211_tx_status(struct ieee80211_hw *hw,
                        ieee80211_mpsp_trigger_process(
                                ieee80211_get_qos_ctl(hdr), sta, true, acked);
 
-               if (!acked && test_sta_flag(sta, WLAN_STA_PS_STA)) {
-                       /*
-                        * The STA is in power save mode, so assume
-                        * that this TX packet failed because of that.
-                        */
-                       ieee80211_handle_filtered_frame(local, sta, skb);
-                       return;
-               }
-
                if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL) &&
                    (ieee80211_is_data(hdr->frame_control)) &&
                    (rates_idx != -1))
@@ -1150,6 +1142,12 @@ void ieee80211_tx_status_ext(struct ieee80211_hw *hw,
                                                            -info->status.ack_signal);
                                }
                        } else if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
+                               /*
+                                * The STA is in power save mode, so assume
+                                * that this TX packet failed because of that.
+                                */
+                               if (skb)
+                                       ieee80211_handle_filtered_frame(local, sta, skb);
                                return;
                        } else if (noack_success) {
                                /* nothing to do here, do not account as lost */
index 8ba10a4..56a4d0d 100644 (file)
@@ -1942,19 +1942,24 @@ static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata,
 
 /* device xmit handlers */
 
+enum ieee80211_encrypt {
+       ENCRYPT_NO,
+       ENCRYPT_MGMT,
+       ENCRYPT_DATA,
+};
+
 static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata,
                                struct sk_buff *skb,
-                               int head_need, bool may_encrypt)
+                               int head_need,
+                               enum ieee80211_encrypt encrypt)
 {
        struct ieee80211_local *local = sdata->local;
-       struct ieee80211_hdr *hdr;
        bool enc_tailroom;
        int tail_need = 0;
 
-       hdr = (struct ieee80211_hdr *) skb->data;
-       enc_tailroom = may_encrypt &&
-                      (sdata->crypto_tx_tailroom_needed_cnt ||
-                       ieee80211_is_mgmt(hdr->frame_control));
+       enc_tailroom = encrypt == ENCRYPT_MGMT ||
+                      (encrypt == ENCRYPT_DATA &&
+                       sdata->crypto_tx_tailroom_needed_cnt);
 
        if (enc_tailroom) {
                tail_need = IEEE80211_ENCRYPT_TAILROOM;
@@ -1985,23 +1990,29 @@ void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
 {
        struct ieee80211_local *local = sdata->local;
        struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
-       struct ieee80211_hdr *hdr;
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
        int headroom;
-       bool may_encrypt;
+       enum ieee80211_encrypt encrypt;
 
-       may_encrypt = !(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT);
+       if (info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)
+               encrypt = ENCRYPT_NO;
+       else if (ieee80211_is_mgmt(hdr->frame_control))
+               encrypt = ENCRYPT_MGMT;
+       else
+               encrypt = ENCRYPT_DATA;
 
        headroom = local->tx_headroom;
-       if (may_encrypt)
+       if (encrypt != ENCRYPT_NO)
                headroom += sdata->encrypt_headroom;
        headroom -= skb_headroom(skb);
        headroom = max_t(int, 0, headroom);
 
-       if (ieee80211_skb_resize(sdata, skb, headroom, may_encrypt)) {
+       if (ieee80211_skb_resize(sdata, skb, headroom, encrypt)) {
                ieee80211_free_txskb(&local->hw, skb);
                return;
        }
 
+       /* reload after potential resize */
        hdr = (struct ieee80211_hdr *) skb->data;
        info->control.vif = &sdata->vif;
 
@@ -2828,7 +2839,7 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata,
                head_need += sdata->encrypt_headroom;
                head_need += local->tx_headroom;
                head_need = max_t(int, 0, head_need);
-               if (ieee80211_skb_resize(sdata, skb, head_need, true)) {
+               if (ieee80211_skb_resize(sdata, skb, head_need, ENCRYPT_DATA)) {
                        ieee80211_free_txskb(&local->hw, skb);
                        skb = NULL;
                        return ERR_PTR(-ENOMEM);
@@ -3502,7 +3513,7 @@ static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
        if (unlikely(ieee80211_skb_resize(sdata, skb,
                                          max_t(int, extra_head + hw_headroom -
                                                     skb_headroom(skb), 0),
-                                         false))) {
+                                         ENCRYPT_NO))) {
                kfree_skb(skb);
                return true;
        }
@@ -3619,13 +3630,14 @@ begin:
        tx.skb = skb;
        tx.sdata = vif_to_sdata(info->control.vif);
 
-       if (txq->sta && !(info->flags & IEEE80211_TX_CTL_INJECTED)) {
+       if (txq->sta) {
                tx.sta = container_of(txq->sta, struct sta_info, sta);
                /*
                 * Drop unicast frames to unauthorised stations unless they are
-                * EAPOL frames from the local station.
+                * injected frames or EAPOL frames from the local station.
                 */
-               if (unlikely(ieee80211_is_data(hdr->frame_control) &&
+               if (unlikely(!(info->flags & IEEE80211_TX_CTL_INJECTED) &&
+                            ieee80211_is_data(hdr->frame_control) &&
                             !ieee80211_vif_is_mesh(&tx.sdata->vif) &&
                             tx.sdata->vif.type != NL80211_IFTYPE_OCB &&
                             !is_multicast_ether_addr(hdr->addr1) &&
index e7419fd..88f2a7a 100644 (file)
@@ -2467,6 +2467,7 @@ static struct proto mptcp_prot = {
        .memory_pressure        = &tcp_memory_pressure,
        .stream_memory_free     = mptcp_memory_free,
        .sysctl_wmem_offset     = offsetof(struct net, ipv4.sysctl_tcp_wmem),
+       .sysctl_rmem_offset     = offsetof(struct net, ipv4.sysctl_tcp_rmem),
        .sysctl_mem     = sysctl_tcp_mem,
        .obj_size       = sizeof(struct mptcp_sock),
        .slab_flags     = SLAB_TYPESAFE_BY_RCU,
index 8b47c4b..feb4b9f 100644 (file)
@@ -291,7 +291,7 @@ struct mptcp_sock *mptcp_token_iter_next(const struct net *net, long *s_slot,
 {
        struct mptcp_sock *ret = NULL;
        struct hlist_nulls_node *pos;
-       int slot, num;
+       int slot, num = 0;
 
        for (slot = *s_slot; slot <= token_mask; *s_num = 0, slot++) {
                struct token_bucket *bucket = &token_hash[slot];
index f1be3e3..a9cb355 100644 (file)
@@ -1726,9 +1726,6 @@ struct ncsi_dev *ncsi_register_dev(struct net_device *dev,
        ndp->ptype.dev = dev;
        dev_add_pack(&ndp->ptype);
 
-       /* Set up generic netlink interface */
-       ncsi_init_netlink(dev);
-
        pdev = to_platform_device(dev->dev.parent);
        if (pdev) {
                np = pdev->dev.of_node;
@@ -1892,8 +1889,6 @@ void ncsi_unregister_dev(struct ncsi_dev *nd)
        list_del_rcu(&ndp->node);
        spin_unlock_irqrestore(&ncsi_dev_lock, flags);
 
-       ncsi_unregister_netlink(nd->dev);
-
        kfree(ndp);
 }
 EXPORT_SYMBOL_GPL(ncsi_unregister_dev);
index adddc77..bb5f165 100644 (file)
@@ -766,24 +766,8 @@ static struct genl_family ncsi_genl_family __ro_after_init = {
        .n_small_ops = ARRAY_SIZE(ncsi_ops),
 };
 
-int ncsi_init_netlink(struct net_device *dev)
+static int __init ncsi_init_netlink(void)
 {
-       int rc;
-
-       rc = genl_register_family(&ncsi_genl_family);
-       if (rc)
-               netdev_err(dev, "ncsi: failed to register netlink family\n");
-
-       return rc;
-}
-
-int ncsi_unregister_netlink(struct net_device *dev)
-{
-       int rc;
-
-       rc = genl_unregister_family(&ncsi_genl_family);
-       if (rc)
-               netdev_err(dev, "ncsi: failed to unregister netlink family\n");
-
-       return rc;
+       return genl_register_family(&ncsi_genl_family);
 }
+subsys_initcall(ncsi_init_netlink);
index 7502723..39a1a9d 100644 (file)
@@ -22,7 +22,4 @@ int ncsi_send_netlink_err(struct net_device *dev,
                          struct nlmsghdr *nlhdr,
                          int err);
 
-int ncsi_init_netlink(struct net_device *dev);
-int ncsi_unregister_netlink(struct net_device *dev);
-
 #endif /* __NCSI_NETLINK_H__ */
index 6f35832..7cff6e5 100644 (file)
@@ -637,13 +637,14 @@ ip_set_match_extensions(struct ip_set *set, const struct ip_set_ext *ext,
        if (SET_WITH_COUNTER(set)) {
                struct ip_set_counter *counter = ext_counter(data, set);
 
+               ip_set_update_counter(counter, ext, flags);
+
                if (flags & IPSET_FLAG_MATCH_COUNTERS &&
                    !(ip_set_match_counter(ip_set_get_packets(counter),
                                mext->packets, mext->packets_op) &&
                      ip_set_match_counter(ip_set_get_bytes(counter),
                                mext->bytes, mext->bytes_op)))
                        return false;
-               ip_set_update_counter(counter, ext, flags);
        }
        if (SET_WITH_SKBINFO(set))
                ip_set_get_skbinfo(ext_skbinfo(data, set),
index cc3c275..c0b8215 100644 (file)
@@ -742,12 +742,12 @@ static int ip_vs_route_me_harder(struct netns_ipvs *ipvs, int af,
                struct dst_entry *dst = skb_dst(skb);
 
                if (dst->dev && !(dst->dev->flags & IFF_LOOPBACK) &&
-                   ip6_route_me_harder(ipvs->net, skb) != 0)
+                   ip6_route_me_harder(ipvs->net, skb->sk, skb) != 0)
                        return 1;
        } else
 #endif
                if (!(skb_rtable(skb)->rt_flags & RTCF_LOCAL) &&
-                   ip_route_me_harder(ipvs->net, skb, RTN_LOCAL) != 0)
+                   ip_route_me_harder(ipvs->net, skb->sk, skb, RTN_LOCAL) != 0)
                        return 1;
 
        return 0;
index 59151dc..e87b6bd 100644 (file)
@@ -715,7 +715,7 @@ nf_nat_ipv4_local_fn(void *priv, struct sk_buff *skb,
 
                if (ct->tuplehash[dir].tuple.dst.u3.ip !=
                    ct->tuplehash[!dir].tuple.src.u3.ip) {
-                       err = ip_route_me_harder(state->net, skb, RTN_UNSPEC);
+                       err = ip_route_me_harder(state->net, state->sk, skb, RTN_UNSPEC);
                        if (err < 0)
                                ret = NF_DROP_ERR(err);
                }
@@ -953,7 +953,7 @@ nf_nat_ipv6_local_fn(void *priv, struct sk_buff *skb,
 
                if (!nf_inet_addr_cmp(&ct->tuplehash[dir].tuple.dst.u3,
                                      &ct->tuplehash[!dir].tuple.src.u3)) {
-                       err = nf_ip6_route_me_harder(state->net, skb);
+                       err = nf_ip6_route_me_harder(state->net, state->sk, skb);
                        if (err < 0)
                                ret = NF_DROP_ERR(err);
                }
index 9cca35d..d7d34a6 100644 (file)
@@ -446,7 +446,7 @@ synproxy_send_tcp(struct net *net,
 
        skb_dst_set_noref(nskb, skb_dst(skb));
        nskb->protocol = htons(ETH_P_IP);
-       if (ip_route_me_harder(net, nskb, RTN_UNSPEC))
+       if (ip_route_me_harder(net, nskb->sk, nskb, RTN_UNSPEC))
                goto free_nskb;
 
        if (nfct) {
index 65cb8e3..0f58e98 100644 (file)
@@ -7137,7 +7137,7 @@ static void nf_tables_flowtable_notify(struct nft_ctx *ctx,
                        GFP_KERNEL);
        kfree(buf);
 
-       if (ctx->report &&
+       if (!ctx->report &&
            !nfnetlink_has_listeners(ctx->net, NFNLGRP_NFTABLES))
                return;
 
@@ -7259,7 +7259,7 @@ static void nf_tables_gen_notify(struct net *net, struct sk_buff *skb,
        audit_log_nfcfg("?:0;?:0", 0, net->nft.base_seq,
                        AUDIT_NFT_OP_GEN_REGISTER, GFP_KERNEL);
 
-       if (nlmsg_report(nlh) &&
+       if (!nlmsg_report(nlh) &&
            !nfnetlink_has_listeners(net, NFNLGRP_NFTABLES))
                return;
 
@@ -8053,12 +8053,16 @@ static void nf_tables_abort_release(struct nft_trans *trans)
        kfree(trans);
 }
 
-static int __nf_tables_abort(struct net *net, bool autoload)
+static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action)
 {
        struct nft_trans *trans, *next;
        struct nft_trans_elem *te;
        struct nft_hook *hook;
 
+       if (action == NFNL_ABORT_VALIDATE &&
+           nf_tables_validate(net) < 0)
+               return -EAGAIN;
+
        list_for_each_entry_safe_reverse(trans, next, &net->nft.commit_list,
                                         list) {
                switch (trans->msg_type) {
@@ -8190,7 +8194,7 @@ static int __nf_tables_abort(struct net *net, bool autoload)
                nf_tables_abort_release(trans);
        }
 
-       if (autoload)
+       if (action == NFNL_ABORT_AUTOLOAD)
                nf_tables_module_autoload(net);
        else
                nf_tables_module_autoload_cleanup(net);
@@ -8203,9 +8207,10 @@ static void nf_tables_cleanup(struct net *net)
        nft_validate_state_update(net, NFT_VALIDATE_SKIP);
 }
 
-static int nf_tables_abort(struct net *net, struct sk_buff *skb, bool autoload)
+static int nf_tables_abort(struct net *net, struct sk_buff *skb,
+                          enum nfnl_abort_action action)
 {
-       int ret = __nf_tables_abort(net, autoload);
+       int ret = __nf_tables_abort(net, action);
 
        mutex_unlock(&net->nft.commit_mutex);
 
@@ -8836,7 +8841,7 @@ static void __net_exit nf_tables_exit_net(struct net *net)
 {
        mutex_lock(&net->nft.commit_mutex);
        if (!list_empty(&net->nft.commit_list))
-               __nf_tables_abort(net, false);
+               __nf_tables_abort(net, NFNL_ABORT_NONE);
        __nft_release_tables(net);
        mutex_unlock(&net->nft.commit_mutex);
        WARN_ON_ONCE(!list_empty(&net->nft.tables));
index 2daa1f6..d3df66a 100644 (file)
@@ -333,7 +333,7 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,
                return netlink_ack(skb, nlh, -EINVAL, NULL);
 replay:
        status = 0;
-
+replay_abort:
        skb = netlink_skb_clone(oskb, GFP_KERNEL);
        if (!skb)
                return netlink_ack(oskb, nlh, -ENOMEM, NULL);
@@ -499,7 +499,7 @@ ack:
        }
 done:
        if (status & NFNL_BATCH_REPLAY) {
-               ss->abort(net, oskb, true);
+               ss->abort(net, oskb, NFNL_ABORT_AUTOLOAD);
                nfnl_err_reset(&err_list);
                kfree_skb(skb);
                module_put(ss->owner);
@@ -510,11 +510,25 @@ done:
                        status |= NFNL_BATCH_REPLAY;
                        goto done;
                } else if (err) {
-                       ss->abort(net, oskb, false);
+                       ss->abort(net, oskb, NFNL_ABORT_NONE);
                        netlink_ack(oskb, nlmsg_hdr(oskb), err, NULL);
                }
        } else {
-               ss->abort(net, oskb, false);
+               enum nfnl_abort_action abort_action;
+
+               if (status & NFNL_BATCH_FAILURE)
+                       abort_action = NFNL_ABORT_NONE;
+               else
+                       abort_action = NFNL_ABORT_VALIDATE;
+
+               err = ss->abort(net, oskb, abort_action);
+               if (err == -EAGAIN) {
+                       nfnl_err_reset(&err_list);
+                       kfree_skb(skb);
+                       module_put(ss->owner);
+                       status |= NFNL_BATCH_FAILURE;
+                       goto replay_abort;
+               }
        }
        if (ss->cleanup)
                ss->cleanup(net);
index 8826bbe..edd02cd 100644 (file)
@@ -42,7 +42,7 @@ static unsigned int nf_route_table_hook4(void *priv,
                    iph->daddr != daddr ||
                    skb->mark != mark ||
                    iph->tos != tos) {
-                       err = ip_route_me_harder(state->net, skb, RTN_UNSPEC);
+                       err = ip_route_me_harder(state->net, state->sk, skb, RTN_UNSPEC);
                        if (err < 0)
                                ret = NF_DROP_ERR(err);
                }
@@ -92,7 +92,7 @@ static unsigned int nf_route_table_hook6(void *priv,
             skb->mark != mark ||
             ipv6_hdr(skb)->hop_limit != hop_limit ||
             flowlabel != *((u32 *)ipv6_hdr(skb)))) {
-               err = nf_ip6_route_me_harder(state->net, skb);
+               err = nf_ip6_route_me_harder(state->net, state->sk, skb);
                if (err < 0)
                        ret = NF_DROP_ERR(err);
        }
index cedf47a..2182d36 100644 (file)
@@ -191,8 +191,8 @@ static int nf_ip_reroute(struct sk_buff *skb, const struct nf_queue_entry *entry
                      skb->mark == rt_info->mark &&
                      iph->daddr == rt_info->daddr &&
                      iph->saddr == rt_info->saddr))
-                       return ip_route_me_harder(entry->state.net, skb,
-                                                 RTN_UNSPEC);
+                       return ip_route_me_harder(entry->state.net, entry->state.sk,
+                                                 skb, RTN_UNSPEC);
        }
 #endif
        return 0;
index 2e8e3f7..ccb4916 100644 (file)
@@ -1166,12 +1166,13 @@ static int netlbl_unlabel_staticlist(struct sk_buff *skb,
        struct netlbl_unlhsh_walk_arg cb_arg;
        u32 skip_bkt = cb->args[0];
        u32 skip_chain = cb->args[1];
-       u32 iter_bkt;
-       u32 iter_chain = 0, iter_addr4 = 0, iter_addr6 = 0;
+       u32 skip_addr4 = cb->args[2];
+       u32 iter_bkt, iter_chain = 0, iter_addr4 = 0, iter_addr6 = 0;
        struct netlbl_unlhsh_iface *iface;
        struct list_head *iter_list;
        struct netlbl_af4list *addr4;
 #if IS_ENABLED(CONFIG_IPV6)
+       u32 skip_addr6 = cb->args[3];
        struct netlbl_af6list *addr6;
 #endif
 
@@ -1182,7 +1183,7 @@ static int netlbl_unlabel_staticlist(struct sk_buff *skb,
        rcu_read_lock();
        for (iter_bkt = skip_bkt;
             iter_bkt < rcu_dereference(netlbl_unlhsh)->size;
-            iter_bkt++, iter_chain = 0, iter_addr4 = 0, iter_addr6 = 0) {
+            iter_bkt++) {
                iter_list = &rcu_dereference(netlbl_unlhsh)->tbl[iter_bkt];
                list_for_each_entry_rcu(iface, iter_list, list) {
                        if (!iface->valid ||
@@ -1190,7 +1191,7 @@ static int netlbl_unlabel_staticlist(struct sk_buff *skb,
                                continue;
                        netlbl_af4list_foreach_rcu(addr4,
                                                   &iface->addr4_list) {
-                               if (iter_addr4++ < cb->args[2])
+                               if (iter_addr4++ < skip_addr4)
                                        continue;
                                if (netlbl_unlabel_staticlist_gen(
                                              NLBL_UNLABEL_C_STATICLIST,
@@ -1203,10 +1204,12 @@ static int netlbl_unlabel_staticlist(struct sk_buff *skb,
                                        goto unlabel_staticlist_return;
                                }
                        }
+                       iter_addr4 = 0;
+                       skip_addr4 = 0;
 #if IS_ENABLED(CONFIG_IPV6)
                        netlbl_af6list_foreach_rcu(addr6,
                                                   &iface->addr6_list) {
-                               if (iter_addr6++ < cb->args[3])
+                               if (iter_addr6++ < skip_addr6)
                                        continue;
                                if (netlbl_unlabel_staticlist_gen(
                                              NLBL_UNLABEL_C_STATICLIST,
@@ -1219,8 +1222,12 @@ static int netlbl_unlabel_staticlist(struct sk_buff *skb,
                                        goto unlabel_staticlist_return;
                                }
                        }
+                       iter_addr6 = 0;
+                       skip_addr6 = 0;
 #endif /* IPv6 */
                }
+               iter_chain = 0;
+               skip_chain = 0;
        }
 
 unlabel_staticlist_return:
index 832f898..9d6ef6c 100644 (file)
@@ -1703,13 +1703,13 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
        parms.port_no = OVSP_LOCAL;
        parms.upcall_portids = a[OVS_DP_ATTR_UPCALL_PID];
 
-       err = ovs_dp_change(dp, a);
-       if (err)
-               goto err_destroy_meters;
-
        /* So far only local changes have been made, now need the lock. */
        ovs_lock();
 
+       err = ovs_dp_change(dp, a);
+       if (err)
+               goto err_unlock_and_destroy_meters;
+
        vport = new_vport(&parms);
        if (IS_ERR(vport)) {
                err = PTR_ERR(vport);
@@ -1725,8 +1725,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
                                ovs_dp_reset_user_features(skb, info);
                }
 
-               ovs_unlock();
-               goto err_destroy_meters;
+               goto err_unlock_and_destroy_meters;
        }
 
        err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
@@ -1741,7 +1740,8 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
        ovs_notify(&dp_datapath_genl_family, reply, info);
        return 0;
 
-err_destroy_meters:
+err_unlock_and_destroy_meters:
+       ovs_unlock();
        ovs_meters_exit(dp);
 err_destroy_ports:
        kfree(dp->ports);
index f3486a3..c89c8da 100644 (file)
@@ -390,7 +390,7 @@ static struct mask_cache *tbl_mask_cache_alloc(u32 size)
 }
 int ovs_flow_tbl_masks_cache_resize(struct flow_table *table, u32 size)
 {
-       struct mask_cache *mc = rcu_dereference(table->mask_cache);
+       struct mask_cache *mc = rcu_dereference_ovsl(table->mask_cache);
        struct mask_cache *new;
 
        if (size == mc->cache_size)
index 971c73c..97101c5 100644 (file)
@@ -876,6 +876,9 @@ static int rfkill_resume(struct device *dev)
 
        rfkill->suspended = false;
 
+       if (!rfkill->registered)
+               return 0;
+
        if (!rfkill->persistent) {
                cur = !!(rfkill->state & RFKILL_BLOCK_SW);
                rfkill_set_block(rfkill, cur);
index 55d4fc6..d508f6f 100644 (file)
@@ -449,7 +449,7 @@ void sctp_icmp_proto_unreachable(struct sock *sk,
                else {
                        if (!mod_timer(&t->proto_unreach_timer,
                                                jiffies + (HZ/20)))
-                               sctp_association_hold(asoc);
+                               sctp_transport_hold(t);
                }
        } else {
                struct net *net = sock_net(sk);
@@ -458,7 +458,7 @@ void sctp_icmp_proto_unreachable(struct sock *sk,
                         "encountered!\n", __func__);
 
                if (del_timer(&t->proto_unreach_timer))
-                       sctp_association_put(asoc);
+                       sctp_transport_put(t);
 
                sctp_do_sm(net, SCTP_EVENT_T_OTHER,
                           SCTP_ST_OTHER(SCTP_EVENT_ICMP_PROTO_UNREACH),
index aa821e7..0948f14 100644 (file)
@@ -419,7 +419,7 @@ void sctp_generate_proto_unreach_event(struct timer_list *t)
                /* Try again later.  */
                if (!mod_timer(&transport->proto_unreach_timer,
                                jiffies + (HZ/20)))
-                       sctp_association_hold(asoc);
+                       sctp_transport_hold(transport);
                goto out_unlock;
        }
 
@@ -435,7 +435,7 @@ void sctp_generate_proto_unreach_event(struct timer_list *t)
 
 out_unlock:
        bh_unlock_sock(sk);
-       sctp_association_put(asoc);
+       sctp_transport_put(transport);
 }
 
  /* Handle the timeout of the RE-CONFIG timer. */
@@ -1601,12 +1601,12 @@ static int sctp_cmd_interpreter(enum sctp_event_type event_type,
                        break;
 
                case SCTP_CMD_INIT_FAILED:
-                       sctp_cmd_init_failed(commands, asoc, cmd->obj.u32);
+                       sctp_cmd_init_failed(commands, asoc, cmd->obj.u16);
                        break;
 
                case SCTP_CMD_ASSOC_FAILED:
                        sctp_cmd_assoc_failed(commands, asoc, event_type,
-                                             subtype, chunk, cmd->obj.u32);
+                                             subtype, chunk, cmd->obj.u16);
                        break;
 
                case SCTP_CMD_INIT_COUNTER_INC:
index 806af58..60fcf31 100644 (file)
@@ -133,7 +133,7 @@ void sctp_transport_free(struct sctp_transport *transport)
 
        /* Delete the ICMP proto unreachable timer if it's active. */
        if (del_timer(&transport->proto_unreach_timer))
-               sctp_association_put(transport->asoc);
+               sctp_transport_put(transport);
 
        sctp_transport_put(transport);
 }
index e9f487c..5dd4faa 100644 (file)
@@ -979,7 +979,8 @@ static int __smc_connect(struct smc_sock *smc)
 
        /* check if smc modes and versions of CLC proposal and accept match */
        rc = smc_connect_check_aclc(ini, aclc);
-       version = aclc->hdr.version == SMC_V1 ? SMC_V1 : version;
+       version = aclc->hdr.version == SMC_V1 ? SMC_V1 : SMC_V2;
+       ini->smcd_version = version;
        if (rc)
                goto vlan_cleanup;
 
index 2b19863..af96f81 100644 (file)
@@ -1309,7 +1309,8 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
                                    ini->ism_peer_gid[ini->ism_selected]) :
                     smcr_lgr_match(lgr, ini->ib_lcl, role, ini->ib_clcqpn)) &&
                    !lgr->sync_err &&
-                   lgr->vlan_id == ini->vlan_id &&
+                   (ini->smcd_version == SMC_V2 ||
+                    lgr->vlan_id == ini->vlan_id) &&
                    (role == SMC_CLNT || ini->is_smcd ||
                     lgr->conns_num < SMC_RMBS_PER_LGR_MAX)) {
                        /* link group found */
index 1c314db..fc766b5 100644 (file)
@@ -198,9 +198,9 @@ int smc_ib_determine_gid(struct smc_ib_device *smcibdev, u8 ibport,
                rcu_read_lock();
                ndev = rdma_read_gid_attr_ndev_rcu(attr);
                if (!IS_ERR(ndev) &&
-                   ((!vlan_id && !is_vlan_dev(attr->ndev)) ||
-                    (vlan_id && is_vlan_dev(attr->ndev) &&
-                     vlan_dev_vlan_id(attr->ndev) == vlan_id)) &&
+                   ((!vlan_id && !is_vlan_dev(ndev)) ||
+                    (vlan_id && is_vlan_dev(ndev) &&
+                     vlan_dev_vlan_id(ndev) == vlan_id)) &&
                    attr->gid_type == IB_GID_TYPE_ROCE) {
                        rcu_read_unlock();
                        if (gid)
index a18b36b..3aad6ef 100644 (file)
@@ -63,19 +63,20 @@ static int proc_do_xprt(struct ctl_table *table, int write,
                        void *buffer, size_t *lenp, loff_t *ppos)
 {
        char tmpbuf[256];
-       size_t len;
+       ssize_t len;
 
-       if ((*ppos && !write) || !*lenp) {
+       if (write || *ppos) {
                *lenp = 0;
                return 0;
        }
        len = svc_print_xprts(tmpbuf, sizeof(tmpbuf));
-       *lenp = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
+       len = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
 
-       if (*lenp < 0) {
+       if (len < 0) {
                *lenp = 0;
                return -EINVAL;
        }
+       *lenp = len;
        return 0;
 }
 
index 5f6f860..13f3143 100644 (file)
@@ -664,12 +664,18 @@ static int tipc_topsrv_start(struct net *net)
 
        ret = tipc_topsrv_work_start(srv);
        if (ret < 0)
-               return ret;
+               goto err_start;
 
        ret = tipc_topsrv_create_listener(srv);
        if (ret < 0)
-               tipc_topsrv_work_stop(srv);
+               goto err_create;
 
+       return 0;
+
+err_create:
+       tipc_topsrv_work_stop(srv);
+err_start:
+       kfree(srv);
        return ret;
 }
 
index cec8622..54d3e16 100644 (file)
@@ -694,36 +694,51 @@ static void tls_device_resync_rx(struct tls_context *tls_ctx,
 
 static bool
 tls_device_rx_resync_async(struct tls_offload_resync_async *resync_async,
-                          s64 resync_req, u32 *seq)
+                          s64 resync_req, u32 *seq, u16 *rcd_delta)
 {
        u32 is_async = resync_req & RESYNC_REQ_ASYNC;
        u32 req_seq = resync_req >> 32;
        u32 req_end = req_seq + ((resync_req >> 16) & 0xffff);
+       u16 i;
+
+       *rcd_delta = 0;
 
        if (is_async) {
+               /* shouldn't get to wraparound:
+                * too long in async stage, something bad happened
+                */
+               if (WARN_ON_ONCE(resync_async->rcd_delta == USHRT_MAX))
+                       return false;
+
                /* asynchronous stage: log all headers seq such that
                 * req_seq <= seq <= end_seq, and wait for real resync request
                 */
-               if (between(*seq, req_seq, req_end) &&
+               if (before(*seq, req_seq))
+                       return false;
+               if (!after(*seq, req_end) &&
                    resync_async->loglen < TLS_DEVICE_RESYNC_ASYNC_LOGMAX)
                        resync_async->log[resync_async->loglen++] = *seq;
 
+               resync_async->rcd_delta++;
+
                return false;
        }
 
        /* synchronous stage: check against the logged entries and
         * proceed to check the next entries if no match was found
         */
-       while (resync_async->loglen) {
-               if (req_seq == resync_async->log[resync_async->loglen - 1] &&
-                   atomic64_try_cmpxchg(&resync_async->req,
-                                        &resync_req, 0)) {
-                       resync_async->loglen = 0;
+       for (i = 0; i < resync_async->loglen; i++)
+               if (req_seq == resync_async->log[i] &&
+                   atomic64_try_cmpxchg(&resync_async->req, &resync_req, 0)) {
+                       *rcd_delta = resync_async->rcd_delta - i;
                        *seq = req_seq;
+                       resync_async->loglen = 0;
+                       resync_async->rcd_delta = 0;
                        return true;
                }
-               resync_async->loglen--;
-       }
+
+       resync_async->loglen = 0;
+       resync_async->rcd_delta = 0;
 
        if (req_seq == *seq &&
            atomic64_try_cmpxchg(&resync_async->req,
@@ -741,6 +756,7 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq)
        u32 sock_data, is_req_pending;
        struct tls_prot_info *prot;
        s64 resync_req;
+       u16 rcd_delta;
        u32 req_seq;
 
        if (tls_ctx->rx_conf != TLS_HW)
@@ -786,8 +802,9 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq)
                        return;
 
                if (!tls_device_rx_resync_async(rx_ctx->resync_async,
-                                               resync_req, &seq))
+                                               resync_req, &seq, &rcd_delta))
                        return;
+               tls_bigint_subtract(rcd_sn, rcd_delta);
                break;
        }
 
index 95ab554..2fe9e2c 100644 (file)
@@ -1913,7 +1913,7 @@ pick_next_record:
                         * another message type
                         */
                        msg->msg_flags |= MSG_EOR;
-                       if (ctx->control != TLS_RECORD_TYPE_DATA)
+                       if (control != TLS_RECORD_TYPE_DATA)
                                goto recv_end;
                } else {
                        break;
index b4d7b8a..d10916a 100644 (file)
@@ -438,7 +438,7 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk)
        case SOCK_STREAM:
                if (vsock_use_local_transport(remote_cid))
                        new_transport = transport_local;
-               else if (remote_cid <= VMADDR_CID_HOST)
+               else if (remote_cid <= VMADDR_CID_HOST || !transport_h2g)
                        new_transport = transport_g2h;
                else
                        new_transport = transport_h2g;
index 9f23923..240282c 100644 (file)
@@ -1250,8 +1250,7 @@ void cfg80211_stop_iface(struct wiphy *wiphy, struct wireless_dev *wdev,
 }
 EXPORT_SYMBOL(cfg80211_stop_iface);
 
-void cfg80211_init_wdev(struct cfg80211_registered_device *rdev,
-                       struct wireless_dev *wdev)
+void cfg80211_init_wdev(struct wireless_dev *wdev)
 {
        mutex_init(&wdev->mtx);
        INIT_LIST_HEAD(&wdev->event_list);
@@ -1262,6 +1261,30 @@ void cfg80211_init_wdev(struct cfg80211_registered_device *rdev,
        spin_lock_init(&wdev->pmsr_lock);
        INIT_WORK(&wdev->pmsr_free_wk, cfg80211_pmsr_free_wk);
 
+#ifdef CONFIG_CFG80211_WEXT
+       wdev->wext.default_key = -1;
+       wdev->wext.default_mgmt_key = -1;
+       wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
+#endif
+
+       if (wdev->wiphy->flags & WIPHY_FLAG_PS_ON_BY_DEFAULT)
+               wdev->ps = true;
+       else
+               wdev->ps = false;
+       /* allow mac80211 to determine the timeout */
+       wdev->ps_timeout = -1;
+
+       if ((wdev->iftype == NL80211_IFTYPE_STATION ||
+            wdev->iftype == NL80211_IFTYPE_P2P_CLIENT ||
+            wdev->iftype == NL80211_IFTYPE_ADHOC) && !wdev->use_4addr)
+               wdev->netdev->priv_flags |= IFF_DONT_BRIDGE;
+
+       INIT_WORK(&wdev->disconnect_wk, cfg80211_autodisconnect_wk);
+}
+
+void cfg80211_register_wdev(struct cfg80211_registered_device *rdev,
+                           struct wireless_dev *wdev)
+{
        /*
         * We get here also when the interface changes network namespaces,
         * as it's registered into the new one, but we don't want it to
@@ -1295,6 +1318,11 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
        switch (state) {
        case NETDEV_POST_INIT:
                SET_NETDEV_DEVTYPE(dev, &wiphy_type);
+               wdev->netdev = dev;
+               /* can only change netns with wiphy */
+               dev->features |= NETIF_F_NETNS_LOCAL;
+
+               cfg80211_init_wdev(wdev);
                break;
        case NETDEV_REGISTER:
                /*
@@ -1302,35 +1330,12 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
                 * called within code protected by it when interfaces
                 * are added with nl80211.
                 */
-               /* can only change netns with wiphy */
-               dev->features |= NETIF_F_NETNS_LOCAL;
-
                if (sysfs_create_link(&dev->dev.kobj, &rdev->wiphy.dev.kobj,
                                      "phy80211")) {
                        pr_err("failed to add phy80211 symlink to netdev!\n");
                }
-               wdev->netdev = dev;
-#ifdef CONFIG_CFG80211_WEXT
-               wdev->wext.default_key = -1;
-               wdev->wext.default_mgmt_key = -1;
-               wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
-#endif
-
-               if (wdev->wiphy->flags & WIPHY_FLAG_PS_ON_BY_DEFAULT)
-                       wdev->ps = true;
-               else
-                       wdev->ps = false;
-               /* allow mac80211 to determine the timeout */
-               wdev->ps_timeout = -1;
-
-               if ((wdev->iftype == NL80211_IFTYPE_STATION ||
-                    wdev->iftype == NL80211_IFTYPE_P2P_CLIENT ||
-                    wdev->iftype == NL80211_IFTYPE_ADHOC) && !wdev->use_4addr)
-                       dev->priv_flags |= IFF_DONT_BRIDGE;
-
-               INIT_WORK(&wdev->disconnect_wk, cfg80211_autodisconnect_wk);
 
-               cfg80211_init_wdev(rdev, wdev);
+               cfg80211_register_wdev(rdev, wdev);
                break;
        case NETDEV_GOING_DOWN:
                cfg80211_leave(rdev, wdev);
index e1ec9ac..e3e9686 100644 (file)
@@ -209,8 +209,9 @@ struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx);
 int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
                          struct net *net);
 
-void cfg80211_init_wdev(struct cfg80211_registered_device *rdev,
-                       struct wireless_dev *wdev);
+void cfg80211_init_wdev(struct wireless_dev *wdev);
+void cfg80211_register_wdev(struct cfg80211_registered_device *rdev,
+                           struct wireless_dev *wdev);
 
 static inline void wdev_lock(struct wireless_dev *wdev)
        __acquires(wdev)
index 554796a..a77174b 100644 (file)
@@ -3885,7 +3885,8 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
                 * P2P Device and NAN do not have a netdev, so don't go
                 * through the netdev notifier and must be added here
                 */
-               cfg80211_init_wdev(rdev, wdev);
+               cfg80211_init_wdev(wdev);
+               cfg80211_register_wdev(rdev, wdev);
                break;
        default:
                break;
index 3dab859..a04fdfb 100644 (file)
@@ -3616,7 +3616,7 @@ static void print_rd_rules(const struct ieee80211_regdomain *rd)
                power_rule = &reg_rule->power_rule;
 
                if (reg_rule->flags & NL80211_RRF_AUTO_BW)
-                       snprintf(bw, sizeof(bw), "%d KHz, %d KHz AUTO",
+                       snprintf(bw, sizeof(bw), "%d KHz, %u KHz AUTO",
                                 freq_range->max_bandwidth_khz,
                                 reg_get_max_bandwidth(rd, reg_rule));
                else
index 0bbb283..a10487e 100644 (file)
@@ -825,7 +825,7 @@ static int x25_connect(struct socket *sock, struct sockaddr *uaddr,
        sock->state = SS_CONNECTED;
        rc = 0;
 out_put_neigh:
-       if (rc) {
+       if (rc && x25->neighbour) {
                read_lock_bh(&x25_list_lock);
                x25_neigh_put(x25->neighbour);
                x25->neighbour = NULL;
@@ -1050,6 +1050,7 @@ int x25_rx_call_request(struct sk_buff *skb, struct x25_neigh *nb,
        makex25->lci           = lci;
        makex25->dest_addr     = dest_addr;
        makex25->source_addr   = source_addr;
+       x25_neigh_hold(nb);
        makex25->neighbour     = nb;
        makex25->facilities    = facilities;
        makex25->dte_facilities= dte_facilities;
index b71a32e..cfbec39 100644 (file)
@@ -1146,7 +1146,8 @@ static void xsk_destruct(struct sock *sk)
        if (!sock_flag(sk, SOCK_DEAD))
                return;
 
-       xp_put_pool(xs->pool);
+       if (!xp_put_pool(xs->pool))
+               xdp_put_umem(xs->umem);
 
        sk_refcnt_debug_dec(sk);
 }
index 64c9e55..8a3bf4e 100644 (file)
@@ -251,15 +251,18 @@ void xp_get_pool(struct xsk_buff_pool *pool)
        refcount_inc(&pool->users);
 }
 
-void xp_put_pool(struct xsk_buff_pool *pool)
+bool xp_put_pool(struct xsk_buff_pool *pool)
 {
        if (!pool)
-               return;
+               return false;
 
        if (refcount_dec_and_test(&pool->users)) {
                INIT_WORK(&pool->work, xp_release_deferred);
                schedule_work(&pool->work);
+               return true;
        }
+
+       return false;
 }
 
 static struct xsk_dma_map *xp_find_dma_map(struct xsk_buff_pool *pool)
index aa4cdcf..9b8e292 100644 (file)
@@ -803,14 +803,14 @@ static struct xfrm6_tunnel xfrmi_ipv6_handler __read_mostly = {
        .handler        =       xfrmi6_rcv_tunnel,
        .cb_handler     =       xfrmi_rcv_cb,
        .err_handler    =       xfrmi6_err,
-       .priority       =       -1,
+       .priority       =       2,
 };
 
 static struct xfrm6_tunnel xfrmi_ip6ip_handler __read_mostly = {
        .handler        =       xfrmi6_rcv_tunnel,
        .cb_handler     =       xfrmi_rcv_cb,
        .err_handler    =       xfrmi6_err,
-       .priority       =       -1,
+       .priority       =       2,
 };
 #endif
 
@@ -848,14 +848,14 @@ static struct xfrm_tunnel xfrmi_ipip_handler __read_mostly = {
        .handler        =       xfrmi4_rcv_tunnel,
        .cb_handler     =       xfrmi_rcv_cb,
        .err_handler    =       xfrmi4_err,
-       .priority       =       -1,
+       .priority       =       3,
 };
 
 static struct xfrm_tunnel xfrmi_ipip6_handler __read_mostly = {
        .handler        =       xfrmi4_rcv_tunnel,
        .cb_handler     =       xfrmi_rcv_cb,
        .err_handler    =       xfrmi4_err,
-       .priority       =       -1,
+       .priority       =       2,
 };
 #endif
 
index bbd4643..a77da7a 100644 (file)
@@ -2004,6 +2004,7 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high)
        int err = -ENOENT;
        __be32 minspi = htonl(low);
        __be32 maxspi = htonl(high);
+       __be32 newspi = 0;
        u32 mark = x->mark.v & x->mark.m;
 
        spin_lock_bh(&x->lock);
@@ -2022,21 +2023,22 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high)
                        xfrm_state_put(x0);
                        goto unlock;
                }
-               x->id.spi = minspi;
+               newspi = minspi;
        } else {
                u32 spi = 0;
                for (h = 0; h < high-low+1; h++) {
                        spi = low + prandom_u32()%(high-low+1);
                        x0 = xfrm_state_lookup(net, mark, &x->id.daddr, htonl(spi), x->id.proto, x->props.family);
                        if (x0 == NULL) {
-                               x->id.spi = htonl(spi);
+                               newspi = htonl(spi);
                                break;
                        }
                        xfrm_state_put(x0);
                }
        }
-       if (x->id.spi) {
+       if (newspi) {
                spin_lock_bh(&net->xfrm.xfrm_state_lock);
+               x->id.spi = newspi;
                h = xfrm_spi_hash(net, &x->id.daddr, x->id.spi, x->id.proto, x->props.family);
                hlist_add_head_rcu(&x->byspi, net->xfrm.state_byspi + h);
                spin_unlock_bh(&net->xfrm.xfrm_state_lock);
index 4a74531..b68bd2f 100644 (file)
@@ -290,7 +290,7 @@ static int test_debug_fs_uprobe(char *binary_path, long offset, bool is_return)
 
 int main(int argc, char **argv)
 {
-       struct rlimit r = {1024*1024, RLIM_INFINITY};
+       struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
        extern char __executable_start;
        char filename[256], buf[256];
        __u64 uprobe_file_offset;
index 3e36b3e..3d6eab7 100644 (file)
@@ -116,7 +116,7 @@ static void int_exit(int sig)
 
 int main(int ac, char **argv)
 {
-       struct rlimit r = {1024*1024, RLIM_INFINITY};
+       struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
        long key, next_key, value;
        struct bpf_link *links[2];
        struct bpf_program *prog;
index 70e9877..83e0fec 100644 (file)
@@ -107,7 +107,7 @@ static void print_hist(int fd)
 
 int main(int ac, char **argv)
 {
-       struct rlimit r = {1024*1024, RLIM_INFINITY};
+       struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
        struct bpf_link *links[2];
        struct bpf_program *prog;
        struct bpf_object *obj;
index 6fb8dbd..f78cb18 100644 (file)
@@ -765,7 +765,7 @@ static int load_cpumap_prog(char *file_name, char *prog_name,
 
 int main(int argc, char **argv)
 {
-       struct rlimit r = {10 * 1024 * 1024, RLIM_INFINITY};
+       struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
        char *prog_name = "xdp_cpu_map5_lb_hash_ip_pairs";
        char *mprog_filename = "xdp_redirect_kern.o";
        char *redir_interface = NULL, *redir_map = NULL;
index caa4e7f..93fa1bc 100644 (file)
@@ -450,7 +450,7 @@ static void stats_poll(int interval, int action, __u32 cfg_opt)
 int main(int argc, char **argv)
 {
        __u32 cfg_options= NO_TOUCH ; /* Default: Don't touch packet memory */
-       struct rlimit r = {10 * 1024 * 1024, RLIM_INFINITY};
+       struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
        struct bpf_prog_load_attr prog_load_attr = {
                .prog_type      = BPF_PROG_TYPE_XDP,
        };
index 6769caa..3148437 100755 (executable)
@@ -408,6 +408,7 @@ class PrinterHelpers(Printer):
             'struct bpf_perf_event_data',
             'struct bpf_perf_event_value',
             'struct bpf_pidns_info',
+            'struct bpf_redir_neigh',
             'struct bpf_sock',
             'struct bpf_sock_addr',
             'struct bpf_sock_ops',
index 2cb592f..68dab82 100755 (executable)
@@ -287,6 +287,8 @@ my $bondary = qr { (?<![\w\/\`\{])(?=[\w\/\`\{])|(?<=[\w\/\`\{])(?![\w\/\`\{]) }
 sub output_rest {
        create_labels();
 
+       my $part = "";
+
        foreach my $what (sort {
                                ($data{$a}->{type} eq "File") cmp ($data{$b}->{type} eq "File") ||
                                $a cmp $b
@@ -306,6 +308,21 @@ sub output_rest {
                $w =~ s/([\(\)\_\-\*\=\^\~\\])/\\$1/g;
 
                if ($type ne "File") {
+                       my $cur_part = $what;
+                       if ($what =~ '/') {
+                               if ($what =~ m#^(\/?(?:[\w\-]+\/?){1,2})#) {
+                                       $cur_part = "Symbols under $1";
+                                       $cur_part =~ s,/$,,;
+                               }
+                       }
+
+                       if ($cur_part ne "" && $part ne $cur_part) {
+                           $part = $cur_part;
+                           my $bar = $part;
+                           $bar =~ s/./-/g;
+                           print "$part\n$bar\n\n";
+                       }
+
                        printf ".. _%s:\n\n", $data{$what}->{label};
 
                        my @names = split /, /,$w;
@@ -352,6 +369,12 @@ sub output_rest {
 
                if (!($desc =~ /^\s*$/)) {
                        if ($description_is_rst) {
+                               # Remove title markups from the description
+                               # Having titles inside ABI files will only work if extra
+                               # care would be taken in order to strictly follow the same
+                               # level order for each markup.
+                               $desc =~ s/\n[\-\*\=\^\~]+\n/\n\n/g;
+
                                # Enrich text by creating cross-references
 
                                $desc =~ s,Documentation/(?!devicetree)(\S+)\.rst,:doc:`/$1`,g;
index c8f6b11..f699cf0 100755 (executable)
@@ -1092,7 +1092,11 @@ sub output_struct_rst(%) {
        print "\n\n.. c:type:: " . $name . "\n\n";
     } else {
        my $name = $args{'struct'};
-       print "\n\n.. c:struct:: " . $name . "\n\n";
+       if ($args{'type'} eq 'union') {
+           print "\n\n.. c:union:: " . $name . "\n\n";
+       } else {
+           print "\n\n.. c:struct:: " . $name . "\n\n";
+       }
     }
     print_lineno($declaration_start_line);
     $lineprefix = "   ";
@@ -1427,20 +1431,25 @@ sub dump_enum($$) {
     }
 }
 
+my $typedef_type = qr { ((?:\s+[\w\*]+){1,8})\s* }x;
+my $typedef_ident = qr { \*?\s*(\w\S+)\s* }x;
+my $typedef_args = qr { \s*\((.*)\); }x;
+
+my $typedef1 = qr { typedef$typedef_type\($typedef_ident\)$typedef_args }x;
+my $typedef2 = qr { typedef$typedef_type$typedef_ident$typedef_args }x;
+
 sub dump_typedef($$) {
     my $x = shift;
     my $file = shift;
 
     $x =~ s@/\*.*?\*/@@gos;    # strip comments.
 
-    # Parse function prototypes
-    if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ ||
-       $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) {
-
-       # Function typedefs
+    # Parse function typedef prototypes
+    if ($x =~ $typedef1 || $x =~ $typedef2) {
        $return_type = $1;
        $declaration_name = $2;
        my $args = $3;
+       $return_type =~ s/^\s+//;
 
        create_parameterlist($args, ',', $file, $declaration_name);
 
index f68a761..3a63a98 100644 (file)
@@ -151,8 +151,10 @@ static int sel_ib_pkey_sid_slow(u64 subnet_prefix, u16 pkey_num, u32 *sid)
         * is valid, it just won't be added to the cache.
         */
        new = kzalloc(sizeof(*new), GFP_ATOMIC);
-       if (!new)
+       if (!new) {
+               ret = -ENOMEM;
                goto out;
+       }
 
        new->psec.subnet_prefix = subnet_prefix;
        new->psec.pkey = pkey_num;
index 421ddc7..3b44378 100644 (file)
@@ -1539,7 +1539,7 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
 
  unlock:
        up_write(&card->controls_rwsem);
-       return 0;
+       return err;
 }
 
 static int snd_ctl_elem_add_user(struct snd_ctl_file *file,
@@ -1925,8 +1925,8 @@ EXPORT_SYMBOL(snd_ctl_unregister_ioctl);
 
 #ifdef CONFIG_COMPAT
 /**
- * snd_ctl_unregister_ioctl - de-register the device-specific compat 32bit
- * control-ioctls
+ * snd_ctl_unregister_ioctl_compat - de-register the device-specific compat
+ * 32bit control-ioctls
  * @fcn: ioctl callback function to unregister
  */
 int snd_ctl_unregister_ioctl_compat(snd_kctl_ioctl_func_t fcn)
index 4d059ff..4d0e8fe 100644 (file)
@@ -356,7 +356,8 @@ int snd_dmaengine_pcm_close(struct snd_pcm_substream *substream)
 EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_close);
 
 /**
- * snd_dmaengine_pcm_release_chan_close - Close a dmaengine based PCM substream and release channel
+ * snd_dmaengine_pcm_close_release_chan - Close a dmaengine based PCM
+ *                                       substream and release channel
  * @substream: PCM substream
  *
  * Releases the DMA channel associated with the PCM substream.
index d531e1b..bda3514 100644 (file)
@@ -490,7 +490,7 @@ void snd_pcm_set_ops(struct snd_pcm *pcm, int direction,
 EXPORT_SYMBOL(snd_pcm_set_ops);
 
 /**
- * snd_pcm_sync - set the PCM sync id
+ * snd_pcm_set_sync - set the PCM sync id
  * @substream: the pcm substream
  *
  * Sets the PCM sync identifier for the card.
index 9e0b2d7..47b155a 100644 (file)
@@ -112,7 +112,7 @@ void snd_pcm_stream_lock(struct snd_pcm_substream *substream)
 EXPORT_SYMBOL_GPL(snd_pcm_stream_lock);
 
 /**
- * snd_pcm_stream_lock - Unlock the PCM stream
+ * snd_pcm_stream_unlock - Unlock the PCM stream
  * @substream: PCM substream
  *
  * This unlocks the PCM stream that has been locked via snd_pcm_stream_lock().
@@ -595,7 +595,7 @@ static void snd_pcm_sync_stop(struct snd_pcm_substream *substream)
 }
 
 /**
- * snd_pcm_hw_param_choose - choose a configuration defined by @params
+ * snd_pcm_hw_params_choose - choose a configuration defined by @params
  * @pcm: PCM instance
  * @params: the hw_params instance
  *
index 0f533f5..9f8c53b 100644 (file)
@@ -123,7 +123,7 @@ copy_resp_to_buf(struct snd_efw *efw, void *data, size_t length, int *rcode)
        t = (struct snd_efw_transaction *)data;
        length = min_t(size_t, be32_to_cpu(t->length) * sizeof(u32), length);
 
-       spin_lock_irq(&efw->lock);
+       spin_lock(&efw->lock);
 
        if (efw->push_ptr < efw->pull_ptr)
                capacity = (unsigned int)(efw->pull_ptr - efw->push_ptr);
@@ -190,7 +190,7 @@ handle_resp_for_user(struct fw_card *card, int generation, int source,
 
        copy_resp_to_buf(efw, data, length, rcode);
 end:
-       spin_unlock_irq(&instances_lock);
+       spin_unlock(&instances_lock);
 }
 
 static void
index 4d060d5..b0c0ef8 100644 (file)
@@ -148,6 +148,8 @@ struct hdac_ext_link *snd_hdac_ext_bus_get_link(struct hdac_bus *bus,
                return NULL;
        if (bus->idx != bus_idx)
                return NULL;
+       if (addr < 0 || addr > 31)
+               return NULL;
 
        list_for_each_entry(hlink, &bus->hlink_list, list) {
                for (i = 0; i < HDA_MAX_CODECS; i++) {
index a356c21..4bb58e8 100644 (file)
@@ -2934,7 +2934,7 @@ static void hda_call_codec_resume(struct hda_codec *codec)
        snd_hdac_leave_pm(&codec->core);
 }
 
-static int hda_codec_runtime_suspend(struct device *dev)
+static int hda_codec_suspend(struct device *dev)
 {
        struct hda_codec *codec = dev_to_hda_codec(dev);
        unsigned int state;
@@ -2953,7 +2953,7 @@ static int hda_codec_runtime_suspend(struct device *dev)
        return 0;
 }
 
-static int hda_codec_runtime_resume(struct device *dev)
+static int hda_codec_resume(struct device *dev)
 {
        struct hda_codec *codec = dev_to_hda_codec(dev);
 
@@ -2967,57 +2967,70 @@ static int hda_codec_runtime_resume(struct device *dev)
        pm_runtime_mark_last_busy(dev);
        return 0;
 }
+
+static int hda_codec_runtime_suspend(struct device *dev)
+{
+       return hda_codec_suspend(dev);
+}
+
+static int hda_codec_runtime_resume(struct device *dev)
+{
+       return hda_codec_resume(dev);
+}
+
 #endif /* CONFIG_PM */
 
 #ifdef CONFIG_PM_SLEEP
-static int hda_codec_force_resume(struct device *dev)
+static int hda_codec_pm_prepare(struct device *dev)
+{
+       return pm_runtime_suspended(dev);
+}
+
+static void hda_codec_pm_complete(struct device *dev)
 {
        struct hda_codec *codec = dev_to_hda_codec(dev);
-       int ret;
 
-       ret = pm_runtime_force_resume(dev);
-       /* schedule jackpoll work for jack detection update */
-       if (codec->jackpoll_interval ||
-           (pm_runtime_suspended(dev) && hda_codec_need_resume(codec)))
-               schedule_delayed_work(&codec->jackpoll_work,
-                                     codec->jackpoll_interval);
-       return ret;
+       if (pm_runtime_suspended(dev) && (codec->jackpoll_interval ||
+           hda_codec_need_resume(codec) || codec->forced_resume))
+               pm_request_resume(dev);
 }
 
 static int hda_codec_pm_suspend(struct device *dev)
 {
        dev->power.power_state = PMSG_SUSPEND;
-       return pm_runtime_force_suspend(dev);
+       return hda_codec_suspend(dev);
 }
 
 static int hda_codec_pm_resume(struct device *dev)
 {
        dev->power.power_state = PMSG_RESUME;
-       return hda_codec_force_resume(dev);
+       return hda_codec_resume(dev);
 }
 
 static int hda_codec_pm_freeze(struct device *dev)
 {
        dev->power.power_state = PMSG_FREEZE;
-       return pm_runtime_force_suspend(dev);
+       return hda_codec_suspend(dev);
 }
 
 static int hda_codec_pm_thaw(struct device *dev)
 {
        dev->power.power_state = PMSG_THAW;
-       return hda_codec_force_resume(dev);
+       return hda_codec_resume(dev);
 }
 
 static int hda_codec_pm_restore(struct device *dev)
 {
        dev->power.power_state = PMSG_RESTORE;
-       return hda_codec_force_resume(dev);
+       return hda_codec_resume(dev);
 }
 #endif /* CONFIG_PM_SLEEP */
 
 /* referred in hda_bind.c */
 const struct dev_pm_ops hda_codec_driver_pm = {
 #ifdef CONFIG_PM_SLEEP
+       .prepare = hda_codec_pm_prepare,
+       .complete = hda_codec_pm_complete,
        .suspend = hda_codec_pm_suspend,
        .resume = hda_codec_pm_resume,
        .freeze = hda_codec_pm_freeze,
index be63ead..68f9668 100644 (file)
@@ -41,7 +41,7 @@
 /* 24 unused */
 #define AZX_DCAPS_COUNT_LPIB_DELAY  (1 << 25)  /* Take LPIB as delay */
 #define AZX_DCAPS_PM_RUNTIME   (1 << 26)       /* runtime PM support */
-#define AZX_DCAPS_SUSPEND_SPURIOUS_WAKEUP (1 << 27) /* Workaround for spurious wakeups after suspend */
+/* 27 unused */
 #define AZX_DCAPS_CORBRP_SELF_CLEAR (1 << 28)  /* CORBRP clears itself after reset */
 #define AZX_DCAPS_NO_MSI64      (1 << 29)      /* Stick to 32-bit MSIs */
 #define AZX_DCAPS_SEPARATE_STREAM_TAG  (1 << 30) /* capture and playback use separate stream tag */
@@ -143,6 +143,7 @@ struct azx {
        unsigned int align_buffer_size:1;
        unsigned int region_requested:1;
        unsigned int disabled:1; /* disabled by vga_switcheroo */
+       unsigned int pm_prepared:1;
 
        /* GTS present */
        unsigned int gts_present:1;
index 749b880..6852668 100644 (file)
@@ -297,8 +297,7 @@ enum {
 /* PCH for HSW/BDW; with runtime PM */
 /* no i915 binding for this as HSW/BDW has another controller for HDMI */
 #define AZX_DCAPS_INTEL_PCH \
-       (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_PM_RUNTIME |\
-        AZX_DCAPS_SUSPEND_SPURIOUS_WAKEUP)
+       (AZX_DCAPS_INTEL_PCH_BASE | AZX_DCAPS_PM_RUNTIME)
 
 /* HSW HDMI */
 #define AZX_DCAPS_INTEL_HASWELL \
@@ -985,7 +984,7 @@ static void __azx_runtime_suspend(struct azx *chip)
        display_power(chip, false);
 }
 
-static void __azx_runtime_resume(struct azx *chip, bool from_rt)
+static void __azx_runtime_resume(struct azx *chip)
 {
        struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
        struct hdac_bus *bus = azx_bus(chip);
@@ -1002,7 +1001,8 @@ static void __azx_runtime_resume(struct azx *chip, bool from_rt)
        azx_init_pci(chip);
        hda_intel_init_chip(chip, true);
 
-       if (from_rt) {
+       /* Avoid codec resume if runtime resume is for system suspend */
+       if (!chip->pm_prepared) {
                list_for_each_codec(codec, &chip->bus) {
                        if (codec->relaxed_resume)
                                continue;
@@ -1018,6 +1018,29 @@ static void __azx_runtime_resume(struct azx *chip, bool from_rt)
 }
 
 #ifdef CONFIG_PM_SLEEP
+static int azx_prepare(struct device *dev)
+{
+       struct snd_card *card = dev_get_drvdata(dev);
+       struct azx *chip;
+
+       chip = card->private_data;
+       chip->pm_prepared = 1;
+
+       /* HDA controller always requires different WAKEEN for runtime suspend
+        * and system suspend, so don't use direct-complete here.
+        */
+       return 0;
+}
+
+static void azx_complete(struct device *dev)
+{
+       struct snd_card *card = dev_get_drvdata(dev);
+       struct azx *chip;
+
+       chip = card->private_data;
+       chip->pm_prepared = 0;
+}
+
 static int azx_suspend(struct device *dev)
 {
        struct snd_card *card = dev_get_drvdata(dev);
@@ -1029,15 +1052,7 @@ static int azx_suspend(struct device *dev)
 
        chip = card->private_data;
        bus = azx_bus(chip);
-       snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
-       /* An ugly workaround: direct call of __azx_runtime_suspend() and
-        * __azx_runtime_resume() for old Intel platforms that suffer from
-        * spurious wakeups after S3 suspend
-        */
-       if (chip->driver_caps & AZX_DCAPS_SUSPEND_SPURIOUS_WAKEUP)
-               __azx_runtime_suspend(chip);
-       else
-               pm_runtime_force_suspend(dev);
+       __azx_runtime_suspend(chip);
        if (bus->irq >= 0) {
                free_irq(bus->irq, chip);
                bus->irq = -1;
@@ -1066,11 +1081,7 @@ static int azx_resume(struct device *dev)
        if (azx_acquire_irq(chip, 1) < 0)
                return -EIO;
 
-       if (chip->driver_caps & AZX_DCAPS_SUSPEND_SPURIOUS_WAKEUP)
-               __azx_runtime_resume(chip, false);
-       else
-               pm_runtime_force_resume(dev);
-       snd_power_change_state(card, SNDRV_CTL_POWER_D0);
+       __azx_runtime_resume(chip);
 
        trace_azx_resume(chip);
        return 0;
@@ -1118,10 +1129,7 @@ static int azx_runtime_suspend(struct device *dev)
        chip = card->private_data;
 
        /* enable controller wake up event */
-       if (snd_power_get_state(card) == SNDRV_CTL_POWER_D0) {
-               azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) |
-                          STATESTS_INT_MASK);
-       }
+       azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) | STATESTS_INT_MASK);
 
        __azx_runtime_suspend(chip);
        trace_azx_runtime_suspend(chip);
@@ -1132,18 +1140,14 @@ static int azx_runtime_resume(struct device *dev)
 {
        struct snd_card *card = dev_get_drvdata(dev);
        struct azx *chip;
-       bool from_rt = snd_power_get_state(card) == SNDRV_CTL_POWER_D0;
 
        if (!azx_is_pm_ready(card))
                return 0;
        chip = card->private_data;
-       __azx_runtime_resume(chip, from_rt);
+       __azx_runtime_resume(chip);
 
        /* disable controller Wake Up event*/
-       if (from_rt) {
-               azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) &
-                          ~STATESTS_INT_MASK);
-       }
+       azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) & ~STATESTS_INT_MASK);
 
        trace_azx_runtime_resume(chip);
        return 0;
@@ -1177,6 +1181,8 @@ static int azx_runtime_idle(struct device *dev)
 static const struct dev_pm_ops azx_pm = {
        SET_SYSTEM_SLEEP_PM_OPS(azx_suspend, azx_resume)
 #ifdef CONFIG_PM_SLEEP
+       .prepare = azx_prepare,
+       .complete = azx_complete,
        .freeze_noirq = azx_freeze_noirq,
        .thaw_noirq = azx_thaw_noirq,
 #endif
@@ -2356,6 +2362,7 @@ static int azx_probe_continue(struct azx *chip)
 
        if (azx_has_pm_runtime(chip)) {
                pm_runtime_use_autosuspend(&pci->dev);
+               pm_runtime_allow(&pci->dev);
                pm_runtime_put_autosuspend(&pci->dev);
        }
 
@@ -2499,6 +2506,9 @@ static const struct pci_device_id azx_ids[] = {
        /* DG1 */
        { PCI_DEVICE(0x8086, 0x490d),
          .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE},
+       /* Alderlake-S */
+       { PCI_DEVICE(0x8086, 0x7ad0),
+         .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE},
        /* Elkhart Lake */
        { PCI_DEVICE(0x8086, 0x4b55),
          .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE},
index e0c38f2..d8370a4 100644 (file)
@@ -9183,6 +9183,8 @@ static void ca0132_mmio_init(struct hda_codec *codec)
        case QUIRK_AE5:
                ca0132_mmio_init_ae5(codec);
                break;
+       default:
+               break;
        }
 }
 
index ccd1df0..b0068f8 100644 (file)
@@ -4274,6 +4274,7 @@ HDA_CODEC_ENTRY(0x8086280d, "Geminilake HDMI",    patch_i915_glk_hdmi),
 HDA_CODEC_ENTRY(0x8086280f, "Icelake HDMI",    patch_i915_icl_hdmi),
 HDA_CODEC_ENTRY(0x80862812, "Tigerlake HDMI",  patch_i915_tgl_hdmi),
 HDA_CODEC_ENTRY(0x80862814, "DG1 HDMI",        patch_i915_tgl_hdmi),
+HDA_CODEC_ENTRY(0x80862815, "Alderlake HDMI",  patch_i915_tgl_hdmi),
 HDA_CODEC_ENTRY(0x80862816, "Rocketlake HDMI", patch_i915_tgl_hdmi),
 HDA_CODEC_ENTRY(0x8086281a, "Jasperlake HDMI", patch_i915_icl_hdmi),
 HDA_CODEC_ENTRY(0x8086281b, "Elkhartlake HDMI",        patch_i915_icl_hdmi),
index f239872..739dbaf 100644 (file)
@@ -2522,13 +2522,23 @@ static const struct snd_pci_quirk alc882_fixup_tbl[] = {
        SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
        SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
        SND_PCI_QUIRK(0x1558, 0x9501, "Clevo P950HR", ALC1220_FIXUP_CLEVO_P950),
+       SND_PCI_QUIRK(0x1558, 0x9506, "Clevo P955HQ", ALC1220_FIXUP_CLEVO_P950),
+       SND_PCI_QUIRK(0x1558, 0x950A, "Clevo P955H[PR]", ALC1220_FIXUP_CLEVO_P950),
        SND_PCI_QUIRK(0x1558, 0x95e1, "Clevo P95xER", ALC1220_FIXUP_CLEVO_P950),
        SND_PCI_QUIRK(0x1558, 0x95e2, "Clevo P950ER", ALC1220_FIXUP_CLEVO_P950),
+       SND_PCI_QUIRK(0x1558, 0x95e3, "Clevo P955[ER]T", ALC1220_FIXUP_CLEVO_P950),
+       SND_PCI_QUIRK(0x1558, 0x95e4, "Clevo P955ER", ALC1220_FIXUP_CLEVO_P950),
+       SND_PCI_QUIRK(0x1558, 0x95e5, "Clevo P955EE6", ALC1220_FIXUP_CLEVO_P950),
+       SND_PCI_QUIRK(0x1558, 0x95e6, "Clevo P950R[CDF]", ALC1220_FIXUP_CLEVO_P950),
        SND_PCI_QUIRK(0x1558, 0x96e1, "Clevo P960[ER][CDFN]-K", ALC1220_FIXUP_CLEVO_P950),
        SND_PCI_QUIRK(0x1558, 0x97e1, "Clevo P970[ER][CDFN]", ALC1220_FIXUP_CLEVO_P950),
+       SND_PCI_QUIRK(0x1558, 0x97e2, "Clevo P970RC-M", ALC1220_FIXUP_CLEVO_P950),
+       SND_PCI_QUIRK(0x1558, 0x50d3, "Clevo PC50[ER][CDF]", ALC1220_FIXUP_CLEVO_PB51ED_PINS),
        SND_PCI_QUIRK(0x1558, 0x65d1, "Clevo PB51[ER][CDF]", ALC1220_FIXUP_CLEVO_PB51ED_PINS),
+       SND_PCI_QUIRK(0x1558, 0x65d2, "Clevo PB51R[CDF]", ALC1220_FIXUP_CLEVO_PB51ED_PINS),
+       SND_PCI_QUIRK(0x1558, 0x65e1, "Clevo PB51[ED][DF]", ALC1220_FIXUP_CLEVO_PB51ED_PINS),
        SND_PCI_QUIRK(0x1558, 0x67d1, "Clevo PB71[ER][CDF]", ALC1220_FIXUP_CLEVO_PB51ED_PINS),
-       SND_PCI_QUIRK(0x1558, 0x50d3, "Clevo PC50[ER][CDF]", ALC1220_FIXUP_CLEVO_PB51ED_PINS),
+       SND_PCI_QUIRK(0x1558, 0x67e1, "Clevo PB71[DE][CDF]", ALC1220_FIXUP_CLEVO_PB51ED_PINS),
        SND_PCI_QUIRK(0x1558, 0x70d1, "Clevo PC70[ER][CDF]", ALC1220_FIXUP_CLEVO_PB51ED_PINS),
        SND_PCI_QUIRK(0x1558, 0x7714, "Clevo X170", ALC1220_FIXUP_CLEVO_PB51ED_PINS),
        SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
@@ -4216,6 +4226,12 @@ static void alc286_fixup_hp_gpio_led(struct hda_codec *codec,
        alc_fixup_hp_gpio_led(codec, action, 0x02, 0x20);
 }
 
+static void alc287_fixup_hp_gpio_led(struct hda_codec *codec,
+                               const struct hda_fixup *fix, int action)
+{
+       alc_fixup_hp_gpio_led(codec, action, 0x10, 0);
+}
+
 /* turn on/off mic-mute LED per capture hook via VREF change */
 static int vref_micmute_led_set(struct led_classdev *led_cdev,
                                enum led_brightness brightness)
@@ -6008,6 +6024,27 @@ static void alc285_fixup_invalidate_dacs(struct hda_codec *codec,
        snd_hda_override_wcaps(codec, 0x03, 0);
 }
 
+static void alc_combo_jack_hp_jd_restart(struct hda_codec *codec)
+{
+       switch (codec->core.vendor_id) {
+       case 0x10ec0274:
+       case 0x10ec0294:
+       case 0x10ec0225:
+       case 0x10ec0295:
+       case 0x10ec0299:
+               alc_update_coef_idx(codec, 0x4a, 0x8000, 1 << 15); /* Reset HP JD */
+               alc_update_coef_idx(codec, 0x4a, 0x8000, 0 << 15);
+               break;
+       case 0x10ec0235:
+       case 0x10ec0236:
+       case 0x10ec0255:
+       case 0x10ec0256:
+               alc_update_coef_idx(codec, 0x1b, 0x8000, 1 << 15); /* Reset HP JD */
+               alc_update_coef_idx(codec, 0x1b, 0x8000, 0 << 15);
+               break;
+       }
+}
+
 static void alc295_fixup_chromebook(struct hda_codec *codec,
                                    const struct hda_fixup *fix, int action)
 {
@@ -6018,16 +6055,7 @@ static void alc295_fixup_chromebook(struct hda_codec *codec,
                spec->ultra_low_power = true;
                break;
        case HDA_FIXUP_ACT_INIT:
-               switch (codec->core.vendor_id) {
-               case 0x10ec0295:
-                       alc_update_coef_idx(codec, 0x4a, 0x8000, 1 << 15); /* Reset HP JD */
-                       alc_update_coef_idx(codec, 0x4a, 0x8000, 0 << 15);
-                       break;
-               case 0x10ec0236:
-                       alc_update_coef_idx(codec, 0x1b, 0x8000, 1 << 15); /* Reset HP JD */
-                       alc_update_coef_idx(codec, 0x1b, 0x8000, 0 << 15);
-                       break;
-               }
+               alc_combo_jack_hp_jd_restart(codec);
                break;
        }
 }
@@ -6083,6 +6111,16 @@ static void  alc285_fixup_hp_gpio_amp_init(struct hda_codec *codec,
        alc_write_coef_idx(codec, 0x65, 0x0);
 }
 
+static void alc274_fixup_hp_headset_mic(struct hda_codec *codec,
+                                   const struct hda_fixup *fix, int action)
+{
+       switch (action) {
+       case HDA_FIXUP_ACT_INIT:
+               alc_combo_jack_hp_jd_restart(codec);
+               break;
+       }
+}
+
 /* for hda_fixup_thinkpad_acpi() */
 #include "thinkpad_helper.c"
 
@@ -6277,6 +6315,11 @@ enum {
        ALC256_FIXUP_INTEL_NUC8_RUGGED,
        ALC255_FIXUP_XIAOMI_HEADSET_MIC,
        ALC274_FIXUP_HP_MIC,
+       ALC274_FIXUP_HP_HEADSET_MIC,
+       ALC256_FIXUP_ASUS_HPE,
+       ALC285_FIXUP_THINKPAD_NO_BASS_SPK_HEADSET_JACK,
+       ALC287_FIXUP_HP_GPIO_LED,
+       ALC256_FIXUP_HP_HEADSET_MIC,
 };
 
 static const struct hda_fixup alc269_fixups[] = {
@@ -7664,6 +7707,37 @@ static const struct hda_fixup alc269_fixups[] = {
                        { }
                },
        },
+       [ALC274_FIXUP_HP_HEADSET_MIC] = {
+               .type = HDA_FIXUP_FUNC,
+               .v.func = alc274_fixup_hp_headset_mic,
+               .chained = true,
+               .chain_id = ALC274_FIXUP_HP_MIC
+       },
+       [ALC256_FIXUP_ASUS_HPE] = {
+               .type = HDA_FIXUP_VERBS,
+               .v.verbs = (const struct hda_verb[]) {
+                       /* Set EAPD high */
+                       { 0x20, AC_VERB_SET_COEF_INDEX, 0x0f },
+                       { 0x20, AC_VERB_SET_PROC_COEF, 0x7778 },
+                       { }
+               },
+               .chained = true,
+               .chain_id = ALC294_FIXUP_ASUS_HEADSET_MIC
+       },
+       [ALC285_FIXUP_THINKPAD_NO_BASS_SPK_HEADSET_JACK] = {
+               .type = HDA_FIXUP_FUNC,
+               .v.func = alc_fixup_headset_jack,
+               .chained = true,
+               .chain_id = ALC269_FIXUP_THINKPAD_ACPI
+       },
+       [ALC287_FIXUP_HP_GPIO_LED] = {
+               .type = HDA_FIXUP_FUNC,
+               .v.func = alc287_fixup_hp_gpio_led,
+       },
+       [ALC256_FIXUP_HP_HEADSET_MIC] = {
+               .type = HDA_FIXUP_FUNC,
+               .v.func = alc274_fixup_hp_headset_mic,
+       },
 };
 
 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
@@ -7815,10 +7889,11 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
        SND_PCI_QUIRK(0x103c, 0x869d, "HP", ALC236_FIXUP_HP_MUTE_LED),
        SND_PCI_QUIRK(0x103c, 0x8729, "HP", ALC285_FIXUP_HP_GPIO_LED),
        SND_PCI_QUIRK(0x103c, 0x8736, "HP", ALC285_FIXUP_HP_GPIO_AMP_INIT),
-       SND_PCI_QUIRK(0x103c, 0x874e, "HP", ALC274_FIXUP_HP_MIC),
        SND_PCI_QUIRK(0x103c, 0x8760, "HP", ALC285_FIXUP_HP_MUTE_LED),
        SND_PCI_QUIRK(0x103c, 0x877a, "HP", ALC285_FIXUP_HP_MUTE_LED),
        SND_PCI_QUIRK(0x103c, 0x877d, "HP", ALC236_FIXUP_HP_MUTE_LED),
+       SND_PCI_QUIRK(0x103c, 0x87f4, "HP", ALC287_FIXUP_HP_GPIO_LED),
+       SND_PCI_QUIRK(0x103c, 0x87f5, "HP", ALC287_FIXUP_HP_GPIO_LED),
        SND_PCI_QUIRK(0x1043, 0x103e, "ASUS X540SA", ALC256_FIXUP_ASUS_MIC),
        SND_PCI_QUIRK(0x1043, 0x103f, "ASUS TX300", ALC282_FIXUP_ASUS_TX300),
        SND_PCI_QUIRK(0x1043, 0x106d, "Asus K53BE", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
@@ -7848,6 +7923,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
        SND_PCI_QUIRK(0x1043, 0x1bbd, "ASUS Z550MA", ALC255_FIXUP_ASUS_MIC_NO_PRESENCE),
        SND_PCI_QUIRK(0x1043, 0x1c23, "Asus X55U", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
        SND_PCI_QUIRK(0x1043, 0x1ccd, "ASUS X555UB", ALC256_FIXUP_ASUS_MIC),
+       SND_PCI_QUIRK(0x1043, 0x1d4e, "ASUS TM420", ALC256_FIXUP_ASUS_HPE),
        SND_PCI_QUIRK(0x1043, 0x1e11, "ASUS Zephyrus G15", ALC289_FIXUP_ASUS_GA502),
        SND_PCI_QUIRK(0x1043, 0x1f11, "ASUS Zephyrus G14", ALC289_FIXUP_ASUS_GA401),
        SND_PCI_QUIRK(0x1043, 0x1881, "ASUS Zephyrus S/M", ALC294_FIXUP_ASUS_GX502_PINS),
@@ -7883,11 +7959,49 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
        SND_PCI_QUIRK(0x1458, 0xfa53, "Gigabyte BXBT-2807", ALC283_FIXUP_HEADSET_MIC),
        SND_PCI_QUIRK(0x1462, 0xb120, "MSI Cubi MS-B120", ALC283_FIXUP_HEADSET_MIC),
        SND_PCI_QUIRK(0x1462, 0xb171, "Cubi N 8GL (MS-B171)", ALC283_FIXUP_HEADSET_MIC),
+       SND_PCI_QUIRK(0x1558, 0x1323, "Clevo N130ZU", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
        SND_PCI_QUIRK(0x1558, 0x1325, "System76 Darter Pro (darp5)", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x1401, "Clevo L140[CZ]U", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x1403, "Clevo N140CU", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x1404, "Clevo N150CU", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x14a1, "Clevo L141MU", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x4018, "Clevo NV40M[BE]", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x4019, "Clevo NV40MZ", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x4020, "Clevo NV40MB", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x40a1, "Clevo NL40GU", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x40c1, "Clevo NL40[CZ]U", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x40d1, "Clevo NL41DU", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x50a3, "Clevo NJ51GU", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x50b3, "Clevo NK50S[BEZ]", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x50b6, "Clevo NK50S5", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x50b8, "Clevo NK50SZ", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x50d5, "Clevo NP50D5", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x50f0, "Clevo NH50A[CDF]", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x50f3, "Clevo NH58DPQ", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x5101, "Clevo S510WU", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x5157, "Clevo W517GU1", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x51a1, "Clevo NS50MU", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x70a1, "Clevo NB70T[HJK]", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x70b3, "Clevo NK70SB", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x8228, "Clevo NR40BU", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x8520, "Clevo NH50D[CD]", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x8521, "Clevo NH77D[CD]", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x8535, "Clevo NH50D[BE]", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x8536, "Clevo NH79D[BE]", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
        SND_PCI_QUIRK(0x1558, 0x8550, "System76 Gazelle (gaze14)", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
        SND_PCI_QUIRK(0x1558, 0x8551, "System76 Gazelle (gaze14)", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
        SND_PCI_QUIRK(0x1558, 0x8560, "System76 Gazelle (gaze14)", ALC269_FIXUP_HEADSET_MIC),
        SND_PCI_QUIRK(0x1558, 0x8561, "System76 Gazelle (gaze14)", ALC269_FIXUP_HEADSET_MIC),
+       SND_PCI_QUIRK(0x1558, 0x8668, "Clevo NP50B[BE]", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x8680, "Clevo NJ50LU", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x8686, "Clevo NH50[CZ]U", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x8a20, "Clevo NH55DCQ-Y", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x8a51, "Clevo NH70RCQ-Y", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x8d50, "Clevo NH55RCQ-M", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x951d, "Clevo N950T[CDF]", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x961d, "Clevo N960S[CDF]", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0x971d, "Clevo N970T[CDF]", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
+       SND_PCI_QUIRK(0x1558, 0xa500, "Clevo NL53RU", ALC293_FIXUP_SYSTEM76_MIC_NO_PRESENCE),
        SND_PCI_QUIRK(0x17aa, 0x1036, "Lenovo P520", ALC233_FIXUP_LENOVO_MULTI_CODECS),
        SND_PCI_QUIRK(0x17aa, 0x1048, "ThinkCentre Station", ALC283_FIXUP_HEADSET_MIC),
        SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
@@ -7925,6 +8039,8 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
        SND_PCI_QUIRK(0x17aa, 0x225d, "Thinkpad T480", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
        SND_PCI_QUIRK(0x17aa, 0x2292, "Thinkpad X1 Carbon 7th", ALC285_FIXUP_THINKPAD_HEADSET_JACK),
        SND_PCI_QUIRK(0x17aa, 0x22be, "Thinkpad X1 Carbon 8th", ALC285_FIXUP_THINKPAD_HEADSET_JACK),
+       SND_PCI_QUIRK(0x17aa, 0x22c1, "Thinkpad P1 Gen 3", ALC285_FIXUP_THINKPAD_NO_BASS_SPK_HEADSET_JACK),
+       SND_PCI_QUIRK(0x17aa, 0x22c2, "Thinkpad X1 Extreme Gen 3", ALC285_FIXUP_THINKPAD_NO_BASS_SPK_HEADSET_JACK),
        SND_PCI_QUIRK(0x17aa, 0x30bb, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),
        SND_PCI_QUIRK(0x17aa, 0x30e2, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),
        SND_PCI_QUIRK(0x17aa, 0x310c, "ThinkCentre Station", ALC294_FIXUP_LENOVO_MIC_LOCATION),
@@ -8237,6 +8353,10 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
                {0x19, 0x02a11020},
                {0x1a, 0x02a11030},
                {0x21, 0x0221101f}),
+       SND_HDA_PIN_QUIRK(0x10ec0236, 0x103c, "HP", ALC256_FIXUP_HP_HEADSET_MIC,
+               {0x14, 0x90170110},
+               {0x19, 0x02a11020},
+               {0x21, 0x02211030}),
        SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL2_MIC_NO_PRESENCE,
                {0x14, 0x90170110},
                {0x21, 0x02211020}),
@@ -8339,6 +8459,14 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
                {0x1a, 0x90a70130},
                {0x1b, 0x90170110},
                {0x21, 0x03211020}),
+       SND_HDA_PIN_QUIRK(0x10ec0256, 0x103c, "HP", ALC256_FIXUP_HP_HEADSET_MIC,
+               {0x14, 0x90170110},
+               {0x19, 0x02a11020},
+               {0x21, 0x0221101f}),
+       SND_HDA_PIN_QUIRK(0x10ec0274, 0x103c, "HP", ALC274_FIXUP_HP_HEADSET_MIC,
+               {0x17, 0x90170110},
+               {0x19, 0x03a11030},
+               {0x21, 0x03211020}),
        SND_HDA_PIN_QUIRK(0x10ec0280, 0x103c, "HP", ALC280_FIXUP_HP_GPIO4,
                {0x12, 0x90a60130},
                {0x14, 0x90170110},
index 0bdd33b..fb8895a 100644 (file)
@@ -70,7 +70,6 @@ static int get_msg(struct mixart_mgr *mgr, struct mixart_msg *resp,
        unsigned int i;
 #endif
 
-       mutex_lock(&mgr->msg_lock);
        err = 0;
 
        /* copy message descriptor from miXart to driver */
@@ -119,8 +118,6 @@ static int get_msg(struct mixart_mgr *mgr, struct mixart_msg *resp,
        writel_be(headptr, MIXART_MEM(mgr, MSG_OUTBOUND_FREE_HEAD));
 
  _clean_exit:
-       mutex_unlock(&mgr->msg_lock);
-
        return err;
 }
 
@@ -258,7 +255,9 @@ int snd_mixart_send_msg(struct mixart_mgr *mgr, struct mixart_msg *request, int
        resp.data = resp_data;
        resp.size = max_resp_size;
 
+       mutex_lock(&mgr->msg_lock);
        err = get_msg(mgr, &resp, msg_frame);
+       mutex_unlock(&mgr->msg_lock);
 
        if( request->message_id != resp.message_id )
                dev_err(&mgr->pci->dev, "RESPONSE ERROR!\n");
index 82c1eec..3bd350a 100644 (file)
@@ -487,7 +487,6 @@ static int mchp_spdiftx_hw_params(struct snd_pcm_substream *substream,
        }
        mchp_spdiftx_channel_status_write(dev);
        spin_unlock_irqrestore(&ctrl->lock, flags);
-       mr |= SPDIFTX_MR_VALID1 | SPDIFTX_MR_VALID2;
 
        if (dev->gclk_enabled) {
                clk_disable_unprepare(dev->gclk);
index 097c4e8..c61b17d 100644 (file)
@@ -254,8 +254,28 @@ static const struct snd_soc_dapm_widget cs42l51_dapm_widgets[] = {
                &cs42l51_adcr_mux_controls),
 };
 
+static int mclk_event(struct snd_soc_dapm_widget *w,
+                     struct snd_kcontrol *kcontrol, int event)
+{
+       struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm);
+       struct cs42l51_private *cs42l51 = snd_soc_component_get_drvdata(comp);
+
+       switch (event) {
+       case SND_SOC_DAPM_PRE_PMU:
+               return clk_prepare_enable(cs42l51->mclk_handle);
+       case SND_SOC_DAPM_POST_PMD:
+               /* Delay mclk shutdown to fulfill power-down sequence requirements */
+               msleep(20);
+               clk_disable_unprepare(cs42l51->mclk_handle);
+               break;
+       }
+
+       return 0;
+}
+
 static const struct snd_soc_dapm_widget cs42l51_dapm_mclk_widgets[] = {
-       SND_SOC_DAPM_CLOCK_SUPPLY("MCLK")
+       SND_SOC_DAPM_SUPPLY("MCLK", SND_SOC_NOPM, 0, 0, mclk_event,
+                           SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 };
 
 static const struct snd_soc_dapm_route cs42l51_routes[] = {
index 25fe2dd..3db0729 100644 (file)
 #include <sound/soc-dapm.h>
 #include <sound/soc.h>
 #include <sound/tlv.h>
+#include <sound/rt1015.h>
 
 #include "rl6231.h"
 #include "rt1015.h"
 
+static const struct rt1015_platform_data i2s_default_platform_data = {
+       .power_up_delay_ms = 50,
+};
+
 static const struct reg_default rt1015_reg[] = {
        { 0x0000, 0x0000 },
        { 0x0004, 0xa000 },
@@ -539,7 +544,7 @@ static void rt1015_flush_work(struct work_struct *work)
        struct rt1015_priv *rt1015 = container_of(work, struct rt1015_priv,
                                                flush_work.work);
        struct snd_soc_component *component = rt1015->component;
-       unsigned int val, i = 0, count = 20;
+       unsigned int val, i = 0, count = 200;
 
        while (i < count) {
                usleep_range(1000, 1500);
@@ -650,6 +655,7 @@ static int rt1015_amp_drv_event(struct snd_soc_dapm_widget *w,
        case SND_SOC_DAPM_POST_PMU:
                if (rt1015->hw_config == RT1015_HW_28)
                        schedule_delayed_work(&rt1015->flush_work, msecs_to_jiffies(10));
+               msleep(rt1015->pdata.power_up_delay_ms);
                break;
        default:
                break;
@@ -1067,9 +1073,16 @@ static struct acpi_device_id rt1015_acpi_match[] = {
 MODULE_DEVICE_TABLE(acpi, rt1015_acpi_match);
 #endif
 
+static void rt1015_parse_dt(struct rt1015_priv *rt1015, struct device *dev)
+{
+       device_property_read_u32(dev, "realtek,power-up-delay-ms",
+               &rt1015->pdata.power_up_delay_ms);
+}
+
 static int rt1015_i2c_probe(struct i2c_client *i2c,
        const struct i2c_device_id *id)
 {
+       struct rt1015_platform_data *pdata = dev_get_platdata(&i2c->dev);
        struct rt1015_priv *rt1015;
        int ret;
        unsigned int val;
@@ -1081,6 +1094,13 @@ static int rt1015_i2c_probe(struct i2c_client *i2c,
 
        i2c_set_clientdata(i2c, rt1015);
 
+       rt1015->pdata = i2s_default_platform_data;
+
+       if (pdata)
+               rt1015->pdata = *pdata;
+       else
+               rt1015_parse_dt(rt1015, &i2c->dev);
+
        rt1015->regmap = devm_regmap_init_i2c(i2c, &rt1015_regmap);
        if (IS_ERR(rt1015->regmap)) {
                ret = PTR_ERR(rt1015->regmap);
index d3fdd30..15cadb3 100644 (file)
@@ -12,6 +12,7 @@
 
 #ifndef __RT1015_H__
 #define __RT1015_H__
+#include <sound/rt1015.h>
 
 #define RT1015_DEVICE_ID_VAL                   0x1011
 #define RT1015_DEVICE_ID_VAL2                  0x1015
@@ -380,6 +381,7 @@ enum {
 
 struct rt1015_priv {
        struct snd_soc_component *component;
+       struct rt1015_platform_data pdata;
        struct regmap *regmap;
        int sysclk;
        int sysclk_src;
index f2d9d52..4d2b1ec 100644 (file)
@@ -618,7 +618,7 @@ static const char * const sb_tx8_mux_text[] = {
        "ZERO", "RX_MIX_TX8", "DEC8", "DEC8_192"
 };
 
-static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
+static const DECLARE_TLV_DB_SCALE(digital_gain, -8400, 100, -8400);
 static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
 static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
 static const DECLARE_TLV_DB_SCALE(ear_pa_gain, 0, 150, 0);
index 35697b0..40f682f 100644 (file)
@@ -551,7 +551,7 @@ struct wcd_iir_filter_ctl {
        struct soc_bytes_ext bytes_ext;
 };
 
-static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
+static const DECLARE_TLV_DB_SCALE(digital_gain, -8400, 100, -8400);
 static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
 static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
 static const DECLARE_TLV_DB_SCALE(ear_pa_gain, 0, 150, 0);
index 68e774e..4530b74 100644 (file)
@@ -1026,6 +1026,8 @@ static struct snd_soc_dai_driver wsa881x_dais[] = {
                .id = 0,
                .playback = {
                        .stream_name = "SPKR Playback",
+                       .rates = SNDRV_PCM_RATE_48000,
+                       .formats = SNDRV_PCM_FMTBIT_S16_LE,
                        .rate_max = 48000,
                        .rate_min = 48000,
                        .channels_min = 1,
index d5bae5d..a5b446d 100644 (file)
@@ -15,22 +15,6 @@ config SND_SOC_INTEL_SST_TOPLEVEL
 
 if SND_SOC_INTEL_SST_TOPLEVEL
 
-config SND_SST_IPC
-       tristate
-       # This option controls the IPC core for HiFi2 platforms
-
-config SND_SST_IPC_PCI
-       tristate
-       select SND_SST_IPC
-       # This option controls the PCI-based IPC for HiFi2 platforms
-       #  (Medfield, Merrifield).
-
-config SND_SST_IPC_ACPI
-       tristate
-       select SND_SST_IPC
-       # This option controls the ACPI-based IPC for HiFi2 platforms
-       # (Baytrail, Cherrytrail)
-
 config SND_SOC_INTEL_SST
        tristate
 
@@ -57,7 +41,6 @@ config SND_SST_ATOM_HIFI2_PLATFORM
 config SND_SST_ATOM_HIFI2_PLATFORM_PCI
        tristate "PCI HiFi2 (Merrifield) Platforms"
        depends on X86 && PCI
-       select SND_SST_IPC_PCI
        select SND_SST_ATOM_HIFI2_PLATFORM
        help
          If you have a Intel Merrifield/Edison platform, then
@@ -70,7 +53,6 @@ config SND_SST_ATOM_HIFI2_PLATFORM_ACPI
        tristate "ACPI HiFi2 (Baytrail, Cherrytrail) Platforms"
        default ACPI
        depends on X86 && ACPI && PCI
-       select SND_SST_IPC_ACPI
        select SND_SST_ATOM_HIFI2_PLATFORM
        select SND_SOC_ACPI_INTEL_MATCH
        select IOSF_MBI
index a9326d5..c66f03f 100644 (file)
@@ -6,4 +6,4 @@ snd-soc-sst-atom-hifi2-platform-objs := sst-mfld-platform-pcm.o \
 obj-$(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM) += snd-soc-sst-atom-hifi2-platform.o
 
 # DSP driver
-obj-$(CONFIG_SND_SST_IPC) += sst/
+obj-$(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM) += sst/
index f17c905..5761d30 100644 (file)
@@ -3,6 +3,6 @@ snd-intel-sst-core-objs := sst.o sst_ipc.o sst_stream.o sst_drv_interface.o sst_
 snd-intel-sst-pci-objs += sst_pci.o
 snd-intel-sst-acpi-objs += sst_acpi.o
 
-obj-$(CONFIG_SND_SST_IPC) += snd-intel-sst-core.o
-obj-$(CONFIG_SND_SST_IPC_PCI) += snd-intel-sst-pci.o
-obj-$(CONFIG_SND_SST_IPC_ACPI) += snd-intel-sst-acpi.o
+obj-$(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM) += snd-intel-sst-core.o
+obj-$(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM_PCI) += snd-intel-sst-pci.o
+obj-$(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM_ACPI) += snd-intel-sst-acpi.o
index 3ea4602..9a4b3d0 100644 (file)
@@ -401,17 +401,40 @@ static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
        struct snd_interval *chan = hw_param_interval(params,
                        SNDRV_PCM_HW_PARAM_CHANNELS);
        struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
-       struct snd_soc_dpcm *dpcm = container_of(
-                       params, struct snd_soc_dpcm, hw_params);
-       struct snd_soc_dai_link *fe_dai_link = dpcm->fe->dai_link;
-       struct snd_soc_dai_link *be_dai_link = dpcm->be->dai_link;
+       struct snd_soc_dpcm *dpcm, *rtd_dpcm = NULL;
+
+       /*
+        * The following loop will be called only for playback stream
+        * In this platform, there is only one playback device on every SSP
+        */
+       for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_PLAYBACK, dpcm) {
+               rtd_dpcm = dpcm;
+               break;
+       }
+
+       /*
+        * This following loop will be called only for capture stream
+        * In this platform, there is only one capture device on every SSP
+        */
+       for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_CAPTURE, dpcm) {
+               rtd_dpcm = dpcm;
+               break;
+       }
+
+       if (!rtd_dpcm)
+               return -EINVAL;
+
+       /*
+        * The above 2 loops are mutually exclusive based on the stream direction,
+        * thus rtd_dpcm variable will never be overwritten
+        */
 
        /*
         * The ADSP will convert the FE rate to 48k, stereo, 24 bit
         */
-       if (!strcmp(fe_dai_link->name, "Kbl Audio Port") ||
-           !strcmp(fe_dai_link->name, "Kbl Audio Headset Playback") ||
-           !strcmp(fe_dai_link->name, "Kbl Audio Capture Port")) {
+       if (!strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Port") ||
+           !strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Headset Playback") ||
+           !strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Capture Port")) {
                rate->min = rate->max = 48000;
                chan->min = chan->max = 2;
                snd_mask_none(fmt);
@@ -421,7 +444,7 @@ static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
         * The speaker on the SSP0 supports S16_LE and not S24_LE.
         * thus changing the mask here
         */
-       if (!strcmp(be_dai_link->name, "SSP0-Codec"))
+       if (!strcmp(rtd_dpcm->be->dai_link->name, "SSP0-Codec"))
                snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
 
        return 0;
index 922cd01..f95546c 100644 (file)
@@ -700,6 +700,8 @@ static int kabylake_set_bias_level(struct snd_soc_card *card,
        switch (level) {
        case SND_SOC_BIAS_PREPARE:
                if (dapm->bias_level == SND_SOC_BIAS_ON) {
+                       if (!__clk_is_enabled(priv->mclk))
+                               return 0;
                        dev_dbg(card->dev, "Disable mclk");
                        clk_disable_unprepare(priv->mclk);
                } else {
index 7d29685..9e807b9 100644 (file)
@@ -267,9 +267,12 @@ static int catpt_dsp_select_lpclock(struct catpt_dev *cdev, bool lp, bool waiti)
                                            reg, (reg & CATPT_ISD_DCPWM),
                                            500, 10000);
                if (ret) {
-                       dev_err(cdev->dev, "await WAITI timeout\n");
-                       mutex_unlock(&cdev->clk_mutex);
-                       return ret;
+                       dev_warn(cdev->dev, "await WAITI timeout\n");
+                       /* no signal - only high clock selection allowed */
+                       if (lp) {
+                               mutex_unlock(&cdev->clk_mutex);
+                               return 0;
+                       }
                }
        }
 
index f78018c..408e64e 100644 (file)
@@ -458,10 +458,6 @@ static int catpt_dai_prepare(struct snd_pcm_substream *substream,
        if (ret)
                return CATPT_IPC_ERROR(ret);
 
-       ret = catpt_dsp_update_lpclock(cdev);
-       if (ret)
-               return ret;
-
        ret = catpt_dai_apply_usettings(dai, stream);
        if (ret)
                return ret;
@@ -500,6 +496,7 @@ static int catpt_dai_trigger(struct snd_pcm_substream *substream, int cmd,
        case SNDRV_PCM_TRIGGER_RESUME:
        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
        resume_stream:
+               catpt_dsp_update_lpclock(cdev);
                ret = catpt_ipc_resume_stream(cdev, stream->info.stream_hw_id);
                if (ret)
                        return CATPT_IPC_ERROR(ret);
@@ -507,11 +504,11 @@ static int catpt_dai_trigger(struct snd_pcm_substream *substream, int cmd,
 
        case SNDRV_PCM_TRIGGER_STOP:
                stream->prepared = false;
-               catpt_dsp_update_lpclock(cdev);
                fallthrough;
        case SNDRV_PCM_TRIGGER_SUSPEND:
        case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
                ret = catpt_ipc_pause_stream(cdev, stream->info.stream_hw_id);
+               catpt_dsp_update_lpclock(cdev);
                if (ret)
                        return CATPT_IPC_ERROR(ret);
                break;
@@ -534,6 +531,8 @@ void catpt_stream_update_position(struct catpt_dev *cdev,
 
        dsppos = bytes_to_frames(r, pos->stream_position);
 
+       if (!stream->prepared)
+               goto exit;
        /* only offload is set_write_pos driven */
        if (stream->template->type != CATPT_STRM_TYPE_RENDER)
                goto exit;
@@ -667,7 +666,17 @@ static int catpt_dai_pcm_new(struct snd_soc_pcm_runtime *rtm,
                break;
        }
 
+       /* see if this is a new configuration */
+       if (!memcmp(&cdev->devfmt[devfmt.iface], &devfmt, sizeof(devfmt)))
+               return 0;
+
+       pm_runtime_get_sync(cdev->dev);
+
        ret = catpt_ipc_set_device_format(cdev, &devfmt);
+
+       pm_runtime_mark_last_busy(cdev->dev);
+       pm_runtime_put_autosuspend(cdev->dev);
+
        if (ret)
                return CATPT_IPC_ERROR(ret);
 
index f54b710..291a686 100644 (file)
@@ -487,9 +487,9 @@ static int kmb_dai_hw_params(struct snd_pcm_substream *substream,
                kmb_i2s->xfer_resolution = 0x02;
                break;
        case SNDRV_PCM_FORMAT_S24_LE:
-               config->data_width = 24;
-               kmb_i2s->ccr = 0x08;
-               kmb_i2s->xfer_resolution = 0x04;
+               config->data_width = 32;
+               kmb_i2s->ccr = 0x14;
+               kmb_i2s->xfer_resolution = 0x05;
                break;
        case SNDRV_PCM_FORMAT_S32_LE:
                config->data_width = 32;
index c2c1eb1..26e7d9a 100644 (file)
@@ -630,15 +630,34 @@ static struct snd_soc_codec_conf mt8183_da7219_rt1015_codec_conf[] = {
        },
 };
 
+static const struct snd_kcontrol_new mt8183_da7219_rt1015_snd_controls[] = {
+       SOC_DAPM_PIN_SWITCH("Left Spk"),
+       SOC_DAPM_PIN_SWITCH("Right Spk"),
+};
+
+static const
+struct snd_soc_dapm_widget mt8183_da7219_rt1015_dapm_widgets[] = {
+       SND_SOC_DAPM_SPK("Left Spk", NULL),
+       SND_SOC_DAPM_SPK("Right Spk", NULL),
+       SND_SOC_DAPM_PINCTRL("TDM_OUT_PINCTRL",
+                            "aud_tdm_out_on", "aud_tdm_out_off"),
+};
+
+static const struct snd_soc_dapm_route mt8183_da7219_rt1015_dapm_routes[] = {
+       {"Left Spk", NULL, "Left SPO"},
+       {"Right Spk", NULL, "Right SPO"},
+       {"I2S Playback", NULL, "TDM_OUT_PINCTRL"},
+};
+
 static struct snd_soc_card mt8183_da7219_rt1015_card = {
        .name = "mt8183_da7219_rt1015",
        .owner = THIS_MODULE,
-       .controls = mt8183_da7219_max98357_snd_controls,
-       .num_controls = ARRAY_SIZE(mt8183_da7219_max98357_snd_controls),
-       .dapm_widgets = mt8183_da7219_max98357_dapm_widgets,
-       .num_dapm_widgets = ARRAY_SIZE(mt8183_da7219_max98357_dapm_widgets),
-       .dapm_routes = mt8183_da7219_max98357_dapm_routes,
-       .num_dapm_routes = ARRAY_SIZE(mt8183_da7219_max98357_dapm_routes),
+       .controls = mt8183_da7219_rt1015_snd_controls,
+       .num_controls = ARRAY_SIZE(mt8183_da7219_rt1015_snd_controls),
+       .dapm_widgets = mt8183_da7219_rt1015_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(mt8183_da7219_rt1015_dapm_widgets),
+       .dapm_routes = mt8183_da7219_rt1015_dapm_routes,
+       .num_dapm_routes = ARRAY_SIZE(mt8183_da7219_rt1015_dapm_routes),
        .dai_link = mt8183_da7219_dai_links,
        .num_links = ARRAY_SIZE(mt8183_da7219_dai_links),
        .aux_dev = &mt8183_da7219_max98357_headset_dev,
index ba2aca3..9d17c87 100644 (file)
@@ -80,6 +80,12 @@ static int lpass_cpu_daiops_startup(struct snd_pcm_substream *substream,
                dev_err(dai->dev, "error in enabling mi2s osr clk: %d\n", ret);
                return ret;
        }
+       ret = clk_prepare(drvdata->mi2s_bit_clk[dai->driver->id]);
+       if (ret) {
+               dev_err(dai->dev, "error in enabling mi2s bit clk: %d\n", ret);
+               clk_disable_unprepare(drvdata->mi2s_osr_clk[dai->driver->id]);
+               return ret;
+       }
        return 0;
 }
 
@@ -88,9 +94,8 @@ static void lpass_cpu_daiops_shutdown(struct snd_pcm_substream *substream,
 {
        struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai);
 
-       clk_disable_unprepare(drvdata->mi2s_bit_clk[dai->driver->id]);
-
        clk_disable_unprepare(drvdata->mi2s_osr_clk[dai->driver->id]);
+       clk_unprepare(drvdata->mi2s_bit_clk[dai->driver->id]);
 }
 
 static int lpass_cpu_daiops_hw_params(struct snd_pcm_substream *substream,
@@ -303,10 +308,10 @@ static int lpass_cpu_daiops_trigger(struct snd_pcm_substream *substream,
                        dev_err(dai->dev, "error writing to i2sctl reg: %d\n",
                                ret);
 
-               ret = clk_prepare_enable(drvdata->mi2s_bit_clk[id]);
+               ret = clk_enable(drvdata->mi2s_bit_clk[id]);
                if (ret) {
                        dev_err(dai->dev, "error in enabling mi2s bit clk: %d\n", ret);
-                       clk_disable_unprepare(drvdata->mi2s_osr_clk[id]);
+                       clk_disable(drvdata->mi2s_osr_clk[id]);
                        return ret;
                }
 
@@ -324,6 +329,7 @@ static int lpass_cpu_daiops_trigger(struct snd_pcm_substream *substream,
                if (ret)
                        dev_err(dai->dev, "error writing to i2sctl reg: %d\n",
                                ret);
+               clk_disable(drvdata->mi2s_bit_clk[dai->driver->id]);
                break;
        }
 
index 36d1512..7a3fdf8 100644 (file)
@@ -122,8 +122,10 @@ static int lpass_platform_pcmops_open(struct snd_soc_component *component,
        else
                dma_ch = 0;
 
-       if (dma_ch < 0)
+       if (dma_ch < 0) {
+               kfree(data);
                return dma_ch;
+       }
 
        if (cpu_dai->driver->id == LPASS_DP_RX) {
                map = drvdata->hdmiif_map;
@@ -147,6 +149,7 @@ static int lpass_platform_pcmops_open(struct snd_soc_component *component,
        ret = snd_pcm_hw_constraint_integer(runtime,
                        SNDRV_PCM_HW_PARAM_PERIODS);
        if (ret < 0) {
+               kfree(data);
                dev_err(soc_runtime->dev, "setting constraints failed: %d\n",
                        ret);
                return -EINVAL;
index c6292f9..bc998d5 100644 (file)
@@ -188,7 +188,7 @@ static struct lpass_variant sc7180_data = {
        .micmode                = REG_FIELD_ID(0x1000, 4, 8, 3, 0x1000),
        .micmono                = REG_FIELD_ID(0x1000, 3, 3, 3, 0x1000),
        .wssrc                  = REG_FIELD_ID(0x1000, 2, 2, 3, 0x1000),
-       .bitwidth               = REG_FIELD_ID(0x1000, 0, 0, 3, 0x1000),
+       .bitwidth               = REG_FIELD_ID(0x1000, 0, 1, 3, 0x1000),
 
        .rdma_dyncclk           = REG_FIELD_ID(0xC000, 21, 21, 5, 0x1000),
        .rdma_bursten           = REG_FIELD_ID(0xC000, 20, 20, 5, 0x1000),
index ab1bf23..6c2760e 100644 (file)
@@ -17,6 +17,7 @@
 #include "qdsp6/q6afe.h"
 #include "../codecs/rt5663.h"
 
+#define DRIVER_NAME    "sdm845"
 #define DEFAULT_SAMPLE_RATE_48K                48000
 #define DEFAULT_MCLK_RATE              24576000
 #define TDM_BCLK_RATE          6144000
@@ -552,6 +553,7 @@ static int sdm845_snd_platform_probe(struct platform_device *pdev)
        if (!data)
                return -ENOMEM;
 
+       card->driver_name = DRIVER_NAME;
        card->dapm_widgets = sdm845_snd_widgets;
        card->num_dapm_widgets = ARRAY_SIZE(sdm845_snd_widgets);
        card->dev = dev;
index ea3986a..05a085f 100644 (file)
@@ -2341,7 +2341,7 @@ struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
 }
 
 /**
- * snd_soc_unregister_dai - Unregister DAIs from the ASoC core
+ * snd_soc_unregister_dais - Unregister DAIs from the ASoC core
  *
  * @component: The component for which the DAIs should be unregistered
  */
index 980f2c3..7f87b44 100644 (file)
@@ -1276,7 +1276,7 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget,
 }
 
 /**
- * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
+ * snd_soc_dapm_dai_get_connected_widgets - query audio path and it's widgets.
  * @dai: the soc DAI.
  * @stream: stream direction.
  * @list: list of active widgets for this stream.
index 68ed454..ba9ed66 100644 (file)
@@ -118,6 +118,11 @@ int snd_sof_fw_parse_ext_data(struct snd_sof_dev *sdev, u32 bar, u32 offset)
                case SOF_IPC_EXT_CC_INFO:
                        ret = get_cc_info(sdev, ext_hdr);
                        break;
+               case SOF_IPC_EXT_UNUSED:
+               case SOF_IPC_EXT_PROBE_INFO:
+               case SOF_IPC_EXT_USER_ABI_INFO:
+                       /* They are supported but we don't do anything here */
+                       break;
                default:
                        dev_warn(sdev->dev, "warning: unknown ext header type %d size 0x%x\n",
                                 ext_hdr->type, ext_hdr->hdr.size);
index fa764b6..4457214 100644 (file)
@@ -379,6 +379,10 @@ static const struct usb_audio_device_name usb_audio_names[] = {
 
        DEVICE_NAME(0x046d, 0x0990, "Logitech, Inc.", "QuickCam Pro 9000"),
 
+       /* ASUS ROG Strix */
+       PROFILE_NAME(0x0b05, 0x1917,
+                    "Realtek", "ALC1220-VB-DT", "Realtek-ALC1220-VB-Desktop"),
+
        /* Dell WD15 Dock */
        PROFILE_NAME(0x0bda, 0x4014, "Dell", "WD15 Dock", "Dell-WD15-Dock"),
        /* Dell WD19 Dock */
index c369c81..a7212f1 100644 (file)
@@ -561,7 +561,8 @@ static const struct usbmix_ctl_map usbmix_ctl_maps[] = {
        },
        {       /* ASUS ROG Strix */
                .id = USB_ID(0x0b05, 0x1917),
-               .map = asus_rog_map,
+               .map = trx40_mobo_map,
+               .connector_map = trx40_mobo_connector_map,
        },
        {       /* MSI TRX40 Creator */
                .id = USB_ID(0x0db0, 0x0d64),
index b401ee8..a860303 100644 (file)
@@ -336,6 +336,7 @@ static int set_sync_ep_implicit_fb_quirk(struct snd_usb_substream *subs,
        switch (subs->stream->chip->usb_id) {
        case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
        case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C600 */
+       case USB_ID(0x22f0, 0x0006): /* Allen&Heath Qu-16 */
                ep = 0x81;
                ifnum = 3;
                goto add_sync_ep_from_ifnum;
@@ -345,6 +346,7 @@ static int set_sync_ep_implicit_fb_quirk(struct snd_usb_substream *subs,
                ifnum = 2;
                goto add_sync_ep_from_ifnum;
        case USB_ID(0x2466, 0x8003): /* Fractal Audio Axe-Fx II */
+       case USB_ID(0x0499, 0x172a): /* Yamaha MODX */
                ep = 0x86;
                ifnum = 2;
                goto add_sync_ep_from_ifnum;
@@ -352,6 +354,10 @@ static int set_sync_ep_implicit_fb_quirk(struct snd_usb_substream *subs,
                ep = 0x81;
                ifnum = 2;
                goto add_sync_ep_from_ifnum;
+       case USB_ID(0x1686, 0xf029): /* Zoom UAC-2 */
+               ep = 0x82;
+               ifnum = 2;
+               goto add_sync_ep_from_ifnum;
        case USB_ID(0x1397, 0x0001): /* Behringer UFX1604 */
        case USB_ID(0x1397, 0x0002): /* Behringer UFX1204 */
                ep = 0x81;
index b4fa80e..c50be2f 100644 (file)
@@ -1672,13 +1672,13 @@ void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
            && (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
                msleep(20);
 
-       /* Zoom R16/24, Logitech H650e/H570e, Jabra 550a, Kingston HyperX
-        *  needs a tiny delay here, otherwise requests like get/set
-        *  frequency return as failed despite actually succeeding.
+       /* Zoom R16/24, many Logitech(at least H650e/H570e/BCC950),
+        * Jabra 550a, Kingston HyperX needs a tiny delay here,
+        * otherwise requests like get/set frequency return
+        * as failed despite actually succeeding.
         */
        if ((chip->usb_id == USB_ID(0x1686, 0x00dd) ||
-            chip->usb_id == USB_ID(0x046d, 0x0a46) ||
-            chip->usb_id == USB_ID(0x046d, 0x0a56) ||
+            USB_ID_VENDOR(chip->usb_id) == 0x046d  || /* Logitech */
             chip->usb_id == USB_ID(0x0b0e, 0x0349) ||
             chip->usb_id == USB_ID(0x0951, 0x16ad)) &&
            (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
@@ -1800,6 +1800,7 @@ u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
        case 0x278b:  /* Rotel? */
        case 0x292b:  /* Gustard/Ess based devices */
        case 0x2ab6:  /* T+A devices */
+       case 0x3353:  /* Khadas devices */
        case 0x3842:  /* EVGA */
        case 0xc502:  /* HiBy devices */
                if (fp->dsd_raw)
index ba85bb2..1c17c3a 100644 (file)
@@ -159,6 +159,21 @@ struct kvm_sync_regs {
 struct kvm_arch_memory_slot {
 };
 
+/*
+ * PMU filter structure. Describe a range of events with a particular
+ * action. To be used with KVM_ARM_VCPU_PMU_V3_FILTER.
+ */
+struct kvm_pmu_event_filter {
+       __u16   base_event;
+       __u16   nevents;
+
+#define KVM_PMU_EVENT_ALLOW    0
+#define KVM_PMU_EVENT_DENY     1
+
+       __u8    action;
+       __u8    pad[3];
+};
+
 /* for KVM_GET/SET_VCPU_EVENTS */
 struct kvm_vcpu_events {
        struct {
@@ -242,6 +257,15 @@ struct kvm_vcpu_events {
 #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_AVAIL          0
 #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_AVAIL              1
 #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_REQUIRED       2
+
+/*
+ * Only two states can be presented by the host kernel:
+ * - NOT_REQUIRED: the guest doesn't need to do anything
+ * - NOT_AVAIL: the guest isn't mitigated (it can still use SSBS if available)
+ *
+ * All the other values are deprecated. The host still accepts all
+ * values (they are ABI), but will narrow them to the above two.
+ */
 #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2    KVM_REG_ARM_FW_REG(2)
 #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL          0
 #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_UNKNOWN            1
@@ -329,6 +353,7 @@ struct kvm_vcpu_events {
 #define KVM_ARM_VCPU_PMU_V3_CTRL       0
 #define   KVM_ARM_VCPU_PMU_V3_IRQ      0
 #define   KVM_ARM_VCPU_PMU_V3_INIT     1
+#define   KVM_ARM_VCPU_PMU_V3_FILTER   2
 #define KVM_ARM_VCPU_TIMER_CTRL                1
 #define   KVM_ARM_VCPU_TIMER_IRQ_VTIMER                0
 #define   KVM_ARM_VCPU_TIMER_IRQ_PTIMER                1
index 6ca1e68..ede3186 100644 (file)
@@ -29,7 +29,7 @@
        { 0x13, "SIGP conditional emergency signal" },          \
        { 0x15, "SIGP sense running" },                         \
        { 0x16, "SIGP set multithreading"},                     \
-       { 0x17, "SIGP store additional status ait address"}
+       { 0x17, "SIGP store additional status at address"}
 
 #define icpt_prog_codes                                                \
        { 0x0001, "Prog Operation" },                           \
index 2901d5d..dad350d 100644 (file)
@@ -96,7 +96,7 @@
 #define X86_FEATURE_SYSCALL32          ( 3*32+14) /* "" syscall in IA32 userspace */
 #define X86_FEATURE_SYSENTER32         ( 3*32+15) /* "" sysenter in IA32 userspace */
 #define X86_FEATURE_REP_GOOD           ( 3*32+16) /* REP microcode works well */
-/* free                                        ( 3*32+17) */
+#define X86_FEATURE_SME_COHERENT       ( 3*32+17) /* "" AMD hardware-enforced cache coherency */
 #define X86_FEATURE_LFENCE_RDTSC       ( 3*32+18) /* "" LFENCE synchronizes RDTSC */
 #define X86_FEATURE_ACC_POWER          ( 3*32+19) /* AMD Accumulated Power Mechanism */
 #define X86_FEATURE_NOPL               ( 3*32+20) /* The NOPL (0F 1F) instructions */
 #define X86_FEATURE_EPT_AD             ( 8*32+17) /* Intel Extended Page Table access-dirty bit */
 #define X86_FEATURE_VMCALL             ( 8*32+18) /* "" Hypervisor supports the VMCALL instruction */
 #define X86_FEATURE_VMW_VMMCALL                ( 8*32+19) /* "" VMware prefers VMMCALL hypercall instruction */
+#define X86_FEATURE_SEV_ES             ( 8*32+20) /* AMD Secure Encrypted Virtualization - Encrypted State */
 
 /* Intel-defined CPU features, CPUID level 0x00000007:0 (EBX), word 9 */
 #define X86_FEATURE_FSGSBASE           ( 9*32+ 0) /* RDFSBASE, WRFSBASE, RDGSBASE, WRGSBASE instructions*/
 #define X86_FEATURE_FENCE_SWAPGS_USER  (11*32+ 4) /* "" LFENCE in user entry SWAPGS path */
 #define X86_FEATURE_FENCE_SWAPGS_KERNEL        (11*32+ 5) /* "" LFENCE in kernel entry SWAPGS path */
 #define X86_FEATURE_SPLIT_LOCK_DETECT  (11*32+ 6) /* #AC for split lock */
+#define X86_FEATURE_PER_THREAD_MBA     (11*32+ 7) /* "" Per-thread Memory Bandwidth Allocation */
 
 /* Intel-defined CPU features, CPUID level 0x00000007:1 (EAX), word 12 */
 #define X86_FEATURE_AVX512_BF16                (12*32+ 5) /* AVX512 BFLOAT16 instructions */
 #define X86_FEATURE_CLDEMOTE           (16*32+25) /* CLDEMOTE instruction */
 #define X86_FEATURE_MOVDIRI            (16*32+27) /* MOVDIRI instruction */
 #define X86_FEATURE_MOVDIR64B          (16*32+28) /* MOVDIR64B instruction */
+#define X86_FEATURE_ENQCMD             (16*32+29) /* ENQCMD and ENQCMDS instructions */
 
 /* AMD-defined CPU features, CPUID level 0x80000007 (EBX), word 17 */
 #define X86_FEATURE_OVERFLOW_RECOV     (17*32+ 0) /* MCA overflow recovery support */
 #define X86_FEATURE_MD_CLEAR           (18*32+10) /* VERW clears CPU buffers */
 #define X86_FEATURE_TSX_FORCE_ABORT    (18*32+13) /* "" TSX_FORCE_ABORT */
 #define X86_FEATURE_SERIALIZE          (18*32+14) /* SERIALIZE instruction */
+#define X86_FEATURE_TSXLDTRK           (18*32+16) /* TSX Suspend Load Address Tracking */
 #define X86_FEATURE_PCONFIG            (18*32+18) /* Intel PCONFIG */
 #define X86_FEATURE_ARCH_LBR           (18*32+19) /* Intel ARCH LBR */
 #define X86_FEATURE_SPEC_CTRL          (18*32+26) /* "" Speculation Control (IBRS + IBPB) */
index 4ea8584..5861d34 100644 (file)
 # define DISABLE_PTI           (1 << (X86_FEATURE_PTI & 31))
 #endif
 
+#ifdef CONFIG_IOMMU_SUPPORT
+# define DISABLE_ENQCMD        0
+#else
+# define DISABLE_ENQCMD (1 << (X86_FEATURE_ENQCMD & 31))
+#endif
+
 /*
  * Make sure to add features to the correct mask
  */
@@ -75,7 +81,8 @@
 #define DISABLED_MASK13        0
 #define DISABLED_MASK14        0
 #define DISABLED_MASK15        0
-#define DISABLED_MASK16        (DISABLE_PKU|DISABLE_OSPKE|DISABLE_LA57|DISABLE_UMIP)
+#define DISABLED_MASK16        (DISABLE_PKU|DISABLE_OSPKE|DISABLE_LA57|DISABLE_UMIP| \
+                        DISABLE_ENQCMD)
 #define DISABLED_MASK17        0
 #define DISABLED_MASK18        0
 #define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 19)
index 2859ee4..972a34d 100644 (file)
 #define MSR_IA32_LASTINTFROMIP         0x000001dd
 #define MSR_IA32_LASTINTTOIP           0x000001de
 
+#define MSR_IA32_PASID                 0x00000d93
+#define MSR_IA32_PASID_VALID           BIT_ULL(31)
+
 /* DEBUGCTLMSR bits (others vary by model): */
 #define DEBUGCTLMSR_LBR                        (1UL <<  0) /* last branch recording */
 #define DEBUGCTLMSR_BTF_SHIFT          1
 #define MSR_AMD64_IBSOP_REG_MASK       ((1UL<<MSR_AMD64_IBSOP_REG_COUNT)-1)
 #define MSR_AMD64_IBSCTL               0xc001103a
 #define MSR_AMD64_IBSBRTARGET          0xc001103b
+#define MSR_AMD64_ICIBSEXTDCTL         0xc001103c
 #define MSR_AMD64_IBSOPDATA4           0xc001103d
 #define MSR_AMD64_IBS_REG_COUNT_MAX    8 /* includes MSR_AMD64_IBSBRTARGET */
+#define MSR_AMD64_SEV_ES_GHCB          0xc0010130
 #define MSR_AMD64_SEV                  0xc0010131
 #define MSR_AMD64_SEV_ENABLED_BIT      0
+#define MSR_AMD64_SEV_ES_ENABLED_BIT   1
 #define MSR_AMD64_SEV_ENABLED          BIT_ULL(MSR_AMD64_SEV_ENABLED_BIT)
+#define MSR_AMD64_SEV_ES_ENABLED       BIT_ULL(MSR_AMD64_SEV_ES_ENABLED_BIT)
 
 #define MSR_AMD64_VIRT_SPEC_CTRL       0xc001011f
 
 #define MSR_CORE_PERF_FIXED_CTR0       0x00000309
 #define MSR_CORE_PERF_FIXED_CTR1       0x0000030a
 #define MSR_CORE_PERF_FIXED_CTR2       0x0000030b
+#define MSR_CORE_PERF_FIXED_CTR3       0x0000030c
 #define MSR_CORE_PERF_FIXED_CTR_CTRL   0x0000038d
 #define MSR_CORE_PERF_GLOBAL_STATUS    0x0000038e
 #define MSR_CORE_PERF_GLOBAL_CTRL      0x0000038f
 #define MSR_CORE_PERF_GLOBAL_OVF_CTRL  0x00000390
 
+#define MSR_PERF_METRICS               0x00000329
+
 /* PERF_GLOBAL_OVF_CTL bits */
 #define MSR_CORE_PERF_GLOBAL_OVF_CTRL_TRACE_TOPA_PMI_BIT       55
 #define MSR_CORE_PERF_GLOBAL_OVF_CTRL_TRACE_TOPA_PMI           (1ULL << MSR_CORE_PERF_GLOBAL_OVF_CTRL_TRACE_TOPA_PMI_BIT)
index 6847d85..3ff0d48 100644 (file)
@@ -54,7 +54,7 @@
 #endif
 
 #ifdef CONFIG_X86_64
-#ifdef CONFIG_PARAVIRT
+#ifdef CONFIG_PARAVIRT_XXL
 /* Paravirtualized systems may not have PSE or PGE available */
 #define NEED_PSE       0
 #define NEED_PGE       0
index 0780f97..89e5f3d 100644 (file)
@@ -192,6 +192,26 @@ struct kvm_msr_list {
        __u32 indices[0];
 };
 
+/* Maximum size of any access bitmap in bytes */
+#define KVM_MSR_FILTER_MAX_BITMAP_SIZE 0x600
+
+/* for KVM_X86_SET_MSR_FILTER */
+struct kvm_msr_filter_range {
+#define KVM_MSR_FILTER_READ  (1 << 0)
+#define KVM_MSR_FILTER_WRITE (1 << 1)
+       __u32 flags;
+       __u32 nmsrs; /* number of msrs in bitmap */
+       __u32 base;  /* MSR index the bitmap starts at */
+       __u8 *bitmap; /* a 1 bit allows the operations in flags, 0 denies */
+};
+
+#define KVM_MSR_FILTER_MAX_RANGES 16
+struct kvm_msr_filter {
+#define KVM_MSR_FILTER_DEFAULT_ALLOW (0 << 0)
+#define KVM_MSR_FILTER_DEFAULT_DENY  (1 << 0)
+       __u32 flags;
+       struct kvm_msr_filter_range ranges[KVM_MSR_FILTER_MAX_RANGES];
+};
 
 struct kvm_cpuid_entry {
        __u32 function;
index 2e8a30f..f1d8307 100644 (file)
@@ -29,6 +29,7 @@
 #define SVM_EXIT_WRITE_DR6     0x036
 #define SVM_EXIT_WRITE_DR7     0x037
 #define SVM_EXIT_EXCP_BASE     0x040
+#define SVM_EXIT_LAST_EXCP     0x05f
 #define SVM_EXIT_INTR          0x060
 #define SVM_EXIT_NMI           0x061
 #define SVM_EXIT_SMI           0x062
 #define SVM_EXIT_MWAIT_COND    0x08c
 #define SVM_EXIT_XSETBV        0x08d
 #define SVM_EXIT_RDPRU         0x08e
+#define SVM_EXIT_INVPCID       0x0a2
 #define SVM_EXIT_NPF           0x400
 #define SVM_EXIT_AVIC_INCOMPLETE_IPI           0x401
 #define SVM_EXIT_AVIC_UNACCELERATED_ACCESS     0x402
 
+/* SEV-ES software-defined VMGEXIT events */
+#define SVM_VMGEXIT_MMIO_READ                  0x80000001
+#define SVM_VMGEXIT_MMIO_WRITE                 0x80000002
+#define SVM_VMGEXIT_NMI_COMPLETE               0x80000003
+#define SVM_VMGEXIT_AP_HLT_LOOP                        0x80000004
+#define SVM_VMGEXIT_AP_JUMP_TABLE              0x80000005
+#define SVM_VMGEXIT_SET_AP_JUMP_TABLE          0
+#define SVM_VMGEXIT_GET_AP_JUMP_TABLE          1
+#define SVM_VMGEXIT_UNSUPPORTED_EVENT          0x8000ffff
+
 #define SVM_EXIT_ERR           -1
 
 #define SVM_EXIT_REASONS \
        { SVM_EXIT_MONITOR,     "monitor" }, \
        { SVM_EXIT_MWAIT,       "mwait" }, \
        { SVM_EXIT_XSETBV,      "xsetbv" }, \
+       { SVM_EXIT_INVPCID,     "invpcid" }, \
        { SVM_EXIT_NPF,         "npf" }, \
        { SVM_EXIT_AVIC_INCOMPLETE_IPI,         "avic_incomplete_ipi" }, \
        { SVM_EXIT_AVIC_UNACCELERATED_ACCESS,   "avic_unaccelerated_access" }, \
index 0b5b8ae..1e299ac 100644 (file)
@@ -16,8 +16,6 @@
  * to a jmp to memcpy_erms which does the REP; MOVSB mem copy.
  */
 
-.weak memcpy
-
 /*
  * memcpy - Copy a memory block.
  *
@@ -30,7 +28,7 @@
  * rax original destination
  */
 SYM_FUNC_START_ALIAS(__memcpy)
-SYM_FUNC_START_LOCAL(memcpy)
+SYM_FUNC_START_WEAK(memcpy)
        ALTERNATIVE_2 "jmp memcpy_orig", "", X86_FEATURE_REP_GOOD, \
                      "jmp memcpy_erms", X86_FEATURE_ERMS
 
@@ -51,14 +49,14 @@ EXPORT_SYMBOL(__memcpy)
  * memcpy_erms() - enhanced fast string memcpy. This is faster and
  * simpler than memcpy. Use memcpy_erms when possible.
  */
-SYM_FUNC_START(memcpy_erms)
+SYM_FUNC_START_LOCAL(memcpy_erms)
        movq %rdi, %rax
        movq %rdx, %rcx
        rep movsb
        ret
 SYM_FUNC_END(memcpy_erms)
 
-SYM_FUNC_START(memcpy_orig)
+SYM_FUNC_START_LOCAL(memcpy_orig)
        movq %rdi, %rax
 
        cmpq $0x20, %rdx
index fd5d25a..0bfd26e 100644 (file)
@@ -4,8 +4,7 @@
 #include <linux/linkage.h>
 #include <asm/cpufeatures.h>
 #include <asm/alternative-asm.h>
-
-.weak memset
+#include <asm/export.h>
 
 /*
  * ISO C memset - set a memory block to a byte value. This function uses fast
@@ -18,7 +17,7 @@
  *
  * rax   original destination
  */
-SYM_FUNC_START_ALIAS(memset)
+SYM_FUNC_START_WEAK(memset)
 SYM_FUNC_START(__memset)
        /*
         * Some CPUs support enhanced REP MOVSB/STOSB feature. It is recommended
@@ -44,6 +43,8 @@ SYM_FUNC_START(__memset)
        ret
 SYM_FUNC_END(__memset)
 SYM_FUNC_END_ALIAS(memset)
+EXPORT_SYMBOL(memset)
+EXPORT_SYMBOL(__memset)
 
 /*
  * ISO C memset - set a memory block to a byte value. This function uses
@@ -56,7 +57,7 @@ SYM_FUNC_END_ALIAS(memset)
  *
  * rax   original destination
  */
-SYM_FUNC_START(memset_erms)
+SYM_FUNC_START_LOCAL(memset_erms)
        movq %rdi,%r9
        movb %sil,%al
        movq %rdx,%rcx
@@ -65,7 +66,7 @@ SYM_FUNC_START(memset_erms)
        ret
 SYM_FUNC_END(memset_erms)
 
-SYM_FUNC_START(memset_orig)
+SYM_FUNC_START_LOCAL(memset_orig)
        movq %rdi,%r10
 
        /* expand byte value  */
index a43a6f1..359960a 100644 (file)
@@ -843,9 +843,14 @@ static int handle_perms(void)
                else
                        p_err("missing %s%s%s%s%s%s%s%srequired for full feature probing; run as root or use 'unprivileged'",
                              capability_msg(bpf_caps, 0),
+#ifdef CAP_BPF
                              capability_msg(bpf_caps, 1),
                              capability_msg(bpf_caps, 2),
-                             capability_msg(bpf_caps, 3));
+                             capability_msg(bpf_caps, 3)
+#else
+                               "", "", "", "", "", ""
+#endif /* CAP_BPF */
+                               );
                goto exit_free;
        }
 
index 910e7ba..3fae61e 100644 (file)
@@ -578,8 +578,8 @@ static int do_attach(int argc, char **argv)
 
        ifindex = net_parse_dev(&argc, &argv);
        if (ifindex < 1) {
-               close(progfd);
-               return -EINVAL;
+               err = -EINVAL;
+               goto cleanup;
        }
 
        if (argc) {
@@ -587,8 +587,8 @@ static int do_attach(int argc, char **argv)
                        overwrite = true;
                } else {
                        p_err("expected 'overwrite', got: '%s'?", *argv);
-                       close(progfd);
-                       return -EINVAL;
+                       err = -EINVAL;
+                       goto cleanup;
                }
        }
 
@@ -596,17 +596,17 @@ static int do_attach(int argc, char **argv)
        if (is_prefix("xdp", attach_type_strings[attach_type]))
                err = do_attach_detach_xdp(progfd, attach_type, ifindex,
                                           overwrite);
-
-       if (err < 0) {
+       if (err) {
                p_err("interface %s attach failed: %s",
                      attach_type_strings[attach_type], strerror(-err));
-               return err;
+               goto cleanup;
        }
 
        if (json_output)
                jsonw_null(json_wtr);
-
-       return 0;
+cleanup:
+       close(progfd);
+       return err;
 }
 
 static int do_detach(int argc, char **argv)
index d942c1e..acdb2c2 100644 (file)
@@ -940,7 +940,7 @@ static int parse_attach_detach_args(int argc, char **argv, int *progfd,
        }
 
        if (*attach_type == BPF_FLOW_DISSECTOR) {
-               *mapfd = -1;
+               *mapfd = 0;
                return 0;
        }
 
index 4e3512f..ce5b65e 100644 (file)
@@ -70,7 +70,7 @@ int BPF_PROG(fentry_XXX)
 static inline void
 fexit_update_maps(u32 id, struct bpf_perf_event_value *after)
 {
-       struct bpf_perf_event_value *before, diff, *accum;
+       struct bpf_perf_event_value *before, diff;
 
        before = bpf_map_lookup_elem(&fentry_readings, &id);
        /* only account samples with a valid fentry_reading */
@@ -95,7 +95,7 @@ int BPF_PROG(fexit_XXX)
 {
        struct bpf_perf_event_value readings[MAX_NUM_MATRICS];
        u32 cpu = bpf_get_smp_processor_id();
-       u32 i, one = 1, zero = 0;
+       u32 i, zero = 0;
        int err;
        u64 *count;
 
index a04e813..4648738 100644 (file)
@@ -185,7 +185,6 @@ int main(int argc, char *argv[])
        main_test_libperl();
        main_test_hello();
        main_test_libelf();
-       main_test_libelf_mmap();
        main_test_get_current_dir_name();
        main_test_gettid();
        main_test_glibc();
index b9d4322..95c072b 100644 (file)
 #define  __pure                __attribute__((pure))
 #endif
 #define  noinline      __attribute__((noinline))
-#ifdef __has_attribute
-#if __has_attribute(disable_tail_calls)
-#define __no_tail_call __attribute__((disable_tail_calls))
-#endif
-#endif
-#ifndef __no_tail_call
-#if GCC_VERSION > 40201
-#define __no_tail_call __attribute__((optimize("no-optimize-sibling-calls")))
-#else
-#define __no_tail_call
-#endif
-#endif
 #ifndef __packed
 #define __packed       __attribute__((packed))
 #endif
index 2b3f735..d22a974 100644 (file)
@@ -47,9 +47,6 @@
 #ifndef noinline
 #define noinline
 #endif
-#ifndef __no_tail_call
-#define __no_tail_call
-#endif
 
 /* Are two types/vars the same type (ignoring qualifiers)? */
 #ifndef __same_type
index f2b5d72..2056318 100644 (file)
@@ -857,9 +857,11 @@ __SYSCALL(__NR_openat2, sys_openat2)
 __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd)
 #define __NR_faccessat2 439
 __SYSCALL(__NR_faccessat2, sys_faccessat2)
+#define __NR_process_madvise 440
+__SYSCALL(__NR_process_madvise, sys_process_madvise)
 
 #undef __NR_syscalls
-#define __NR_syscalls 440
+#define __NR_syscalls 441
 
 /*
  * 32 bit systems traditionally used different
index 0054606..fa1f3d6 100644 (file)
@@ -619,6 +619,12 @@ typedef struct drm_i915_irq_wait {
  */
 #define I915_PARAM_PERF_REVISION       54
 
+/* Query whether DRM_I915_GEM_EXECBUFFER2 supports supplying an array of
+ * timeline syncobj through drm_i915_gem_execbuffer_ext_timeline_fences. See
+ * I915_EXEC_USE_EXTENSIONS.
+ */
+#define I915_PARAM_HAS_EXEC_TIMELINE_FENCES 55
+
 /* Must be kept compact -- no holes and well documented */
 
 typedef struct drm_i915_getparam {
@@ -1046,6 +1052,38 @@ struct drm_i915_gem_exec_fence {
        __u32 flags;
 };
 
+/**
+ * See drm_i915_gem_execbuffer_ext_timeline_fences.
+ */
+#define DRM_I915_GEM_EXECBUFFER_EXT_TIMELINE_FENCES 0
+
+/**
+ * This structure describes an array of drm_syncobj and associated points for
+ * timeline variants of drm_syncobj. It is invalid to append this structure to
+ * the execbuf if I915_EXEC_FENCE_ARRAY is set.
+ */
+struct drm_i915_gem_execbuffer_ext_timeline_fences {
+       struct i915_user_extension base;
+
+       /**
+        * Number of element in the handles_ptr & value_ptr arrays.
+        */
+       __u64 fence_count;
+
+       /**
+        * Pointer to an array of struct drm_i915_gem_exec_fence of length
+        * fence_count.
+        */
+       __u64 handles_ptr;
+
+       /**
+        * Pointer to an array of u64 values of length fence_count. Values
+        * must be 0 for a binary drm_syncobj. A Value of 0 for a timeline
+        * drm_syncobj is invalid as it turns a drm_syncobj into a binary one.
+        */
+       __u64 values_ptr;
+};
+
 struct drm_i915_gem_execbuffer2 {
        /**
         * List of gem_exec_object2 structs
@@ -1062,8 +1100,14 @@ struct drm_i915_gem_execbuffer2 {
        __u32 num_cliprects;
        /**
         * This is a struct drm_clip_rect *cliprects if I915_EXEC_FENCE_ARRAY
-        * is not set.  If I915_EXEC_FENCE_ARRAY is set, then this is a
-        * struct drm_i915_gem_exec_fence *fences.
+        * & I915_EXEC_USE_EXTENSIONS are not set.
+        *
+        * If I915_EXEC_FENCE_ARRAY is set, then this is a pointer to an array
+        * of struct drm_i915_gem_exec_fence and num_cliprects is the length
+        * of the array.
+        *
+        * If I915_EXEC_USE_EXTENSIONS is set, then this is a pointer to a
+        * single struct i915_user_extension and num_cliprects is 0.
         */
        __u64 cliprects_ptr;
 #define I915_EXEC_RING_MASK              (0x3f)
@@ -1181,7 +1225,16 @@ struct drm_i915_gem_execbuffer2 {
  */
 #define I915_EXEC_FENCE_SUBMIT         (1 << 20)
 
-#define __I915_EXEC_UNKNOWN_FLAGS (-(I915_EXEC_FENCE_SUBMIT << 1))
+/*
+ * Setting I915_EXEC_USE_EXTENSIONS implies that
+ * drm_i915_gem_execbuffer2.cliprects_ptr is treated as a pointer to an linked
+ * list of i915_user_extension. Each i915_user_extension node is the base of a
+ * larger structure. The list of supported structures are listed in the
+ * drm_i915_gem_execbuffer_ext enum.
+ */
+#define I915_EXEC_USE_EXTENSIONS       (1 << 21)
+
+#define __I915_EXEC_UNKNOWN_FLAGS (-(I915_EXEC_USE_EXTENSIONS << 1))
 
 #define I915_EXEC_CONTEXT_ID_MASK      (0xffffffff)
 #define i915_execbuffer2_set_context_id(eb2, context) \
index 7875709..e5de603 100644 (file)
@@ -45,7 +45,6 @@ struct fscrypt_policy_v1 {
        __u8 flags;
        __u8 master_key_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE];
 };
-#define fscrypt_policy fscrypt_policy_v1
 
 /*
  * Process-subscribed "logon" key description prefix and payload format.
@@ -156,9 +155,9 @@ struct fscrypt_get_key_status_arg {
        __u32 __out_reserved[13];
 };
 
-#define FS_IOC_SET_ENCRYPTION_POLICY           _IOR('f', 19, struct fscrypt_policy)
+#define FS_IOC_SET_ENCRYPTION_POLICY           _IOR('f', 19, struct fscrypt_policy_v1)
 #define FS_IOC_GET_ENCRYPTION_PWSALT           _IOW('f', 20, __u8[16])
-#define FS_IOC_GET_ENCRYPTION_POLICY           _IOW('f', 21, struct fscrypt_policy)
+#define FS_IOC_GET_ENCRYPTION_POLICY           _IOW('f', 21, struct fscrypt_policy_v1)
 #define FS_IOC_GET_ENCRYPTION_POLICY_EX                _IOWR('f', 22, __u8[9]) /* size + version */
 #define FS_IOC_ADD_ENCRYPTION_KEY              _IOWR('f', 23, struct fscrypt_add_key_arg)
 #define FS_IOC_REMOVE_ENCRYPTION_KEY           _IOWR('f', 24, struct fscrypt_remove_key_arg)
@@ -170,6 +169,7 @@ struct fscrypt_get_key_status_arg {
 
 /* old names; don't add anything new here! */
 #ifndef __KERNEL__
+#define fscrypt_policy                 fscrypt_policy_v1
 #define FS_KEY_DESCRIPTOR_SIZE         FSCRYPT_KEY_DESCRIPTOR_SIZE
 #define FS_POLICY_FLAGS_PAD_4          FSCRYPT_POLICY_FLAGS_PAD_4
 #define FS_POLICY_FLAGS_PAD_8          FSCRYPT_POLICY_FLAGS_PAD_8
index 7d8eced..ca41220 100644 (file)
@@ -248,6 +248,8 @@ struct kvm_hyperv_exit {
 #define KVM_EXIT_IOAPIC_EOI       26
 #define KVM_EXIT_HYPERV           27
 #define KVM_EXIT_ARM_NISV         28
+#define KVM_EXIT_X86_RDMSR        29
+#define KVM_EXIT_X86_WRMSR        30
 
 /* For KVM_EXIT_INTERNAL_ERROR */
 /* Emulate instruction failed. */
@@ -413,6 +415,17 @@ struct kvm_run {
                        __u64 esr_iss;
                        __u64 fault_ipa;
                } arm_nisv;
+               /* KVM_EXIT_X86_RDMSR / KVM_EXIT_X86_WRMSR */
+               struct {
+                       __u8 error; /* user -> kernel */
+                       __u8 pad[7];
+#define KVM_MSR_EXIT_REASON_INVAL      (1 << 0)
+#define KVM_MSR_EXIT_REASON_UNKNOWN    (1 << 1)
+#define KVM_MSR_EXIT_REASON_FILTER     (1 << 2)
+                       __u32 reason; /* kernel -> user */
+                       __u32 index; /* kernel -> user */
+                       __u64 data; /* kernel <-> user */
+               } msr;
                /* Fix the size of the union. */
                char padding[256];
        };
@@ -1037,6 +1050,9 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_SMALLER_MAXPHYADDR 185
 #define KVM_CAP_S390_DIAG318 186
 #define KVM_CAP_STEAL_TIME 187
+#define KVM_CAP_X86_USER_SPACE_MSR 188
+#define KVM_CAP_X86_MSR_FILTER 189
+#define KVM_CAP_ENFORCE_PV_FEATURE_CPUID 190
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -1538,6 +1554,9 @@ struct kvm_pv_cmd {
 /* Available with KVM_CAP_S390_PROTECTED */
 #define KVM_S390_PV_COMMAND            _IOWR(KVMIO, 0xc5, struct kvm_pv_cmd)
 
+/* Available with KVM_CAP_X86_MSR_FILTER */
+#define KVM_X86_SET_MSR_FILTER _IOW(KVMIO,  0xc6, struct kvm_msr_filter)
+
 /* Secure Encrypted Virtualization command */
 enum sev_cmd_id {
        /* Guest initialization commands */
index 923cc16..f55bc68 100644 (file)
@@ -27,6 +27,7 @@
 #define MAP_HUGE_SHIFT HUGETLB_FLAG_ENCODE_SHIFT
 #define MAP_HUGE_MASK  HUGETLB_FLAG_ENCODE_MASK
 
+#define MAP_HUGE_16KB  HUGETLB_FLAG_ENCODE_16KB
 #define MAP_HUGE_64KB  HUGETLB_FLAG_ENCODE_64KB
 #define MAP_HUGE_512KB HUGETLB_FLAG_ENCODE_512KB
 #define MAP_HUGE_1MB   HUGETLB_FLAG_ENCODE_1MB
index 96a0240..dd8306e 100644 (file)
@@ -16,6 +16,7 @@
 #define MS_REMOUNT     32      /* Alter flags of a mounted FS */
 #define MS_MANDLOCK    64      /* Allow mandatory locks on an FS */
 #define MS_DIRSYNC     128     /* Directory modifications are synchronous */
+#define MS_NOSYMFOLLOW 256     /* Do not follow symlinks */
 #define MS_NOATIME     1024    /* Do not update access times. */
 #define MS_NODIRATIME  2048    /* Do not update directory access times */
 #define MS_BIND                4096
index 3e5dcdd..b95d3c4 100644 (file)
@@ -1196,7 +1196,7 @@ union perf_mem_data_src {
 
 #define PERF_MEM_SNOOPX_FWD    0x01 /* forward */
 /* 1 free */
-#define PERF_MEM_SNOOPX_SHIFT  38
+#define PERF_MEM_SNOOPX_SHIFT  38
 
 /* locked instruction */
 #define PERF_MEM_LOCK_NA       0x01 /* not available */
index 07b4f81..7f08277 100644 (file)
@@ -233,6 +233,15 @@ struct prctl_mm_map {
 #define PR_SET_TAGGED_ADDR_CTRL                55
 #define PR_GET_TAGGED_ADDR_CTRL                56
 # define PR_TAGGED_ADDR_ENABLE         (1UL << 0)
+/* MTE tag check fault modes */
+# define PR_MTE_TCF_SHIFT              1
+# define PR_MTE_TCF_NONE               (0UL << PR_MTE_TCF_SHIFT)
+# define PR_MTE_TCF_SYNC               (1UL << PR_MTE_TCF_SHIFT)
+# define PR_MTE_TCF_ASYNC              (2UL << PR_MTE_TCF_SHIFT)
+# define PR_MTE_TCF_MASK               (3UL << PR_MTE_TCF_SHIFT)
+/* MTE tag inclusion mask */
+# define PR_MTE_TAG_SHIFT              3
+# define PR_MTE_TAG_MASK               (0xffffUL << PR_MTE_TAG_SHIFT)
 
 /* Control reclaim behavior when allocating memory */
 #define PR_SET_IO_FLUSHER              57
index 7523218..c998860 100644 (file)
 
 /* Set event fd for config interrupt*/
 #define VHOST_VDPA_SET_CONFIG_CALL     _IOW(VHOST_VIRTIO, 0x77, int)
+
+/* Get the valid iova range */
+#define VHOST_VDPA_GET_IOVA_RANGE      _IOR(VHOST_VIRTIO, 0x78, \
+                                            struct vhost_vdpa_iova_range)
 #endif
index 5f9abed..55bd78b 100644 (file)
@@ -146,6 +146,7 @@ GLOBAL_SYM_COUNT = $(shell readelf -s --wide $(BPF_IN_SHARED) | \
                           awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$NF}' | \
                           sort -u | wc -l)
 VERSIONED_SYM_COUNT = $(shell readelf --dyn-syms --wide $(OUTPUT)libbpf.so | \
+                             sed 's/\[.*\]//' | \
                              awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$NF}' | \
                              grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | sort -u | wc -l)
 
@@ -214,6 +215,7 @@ check_abi: $(OUTPUT)libbpf.so
                    awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$NF}'|  \
                    sort -u > $(OUTPUT)libbpf_global_syms.tmp;           \
                readelf --dyn-syms --wide $(OUTPUT)libbpf.so |           \
+                   sed 's/\[.*\]//' |                                   \
                    awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$NF}'|  \
                    grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 |             \
                    sort -u > $(OUTPUT)libbpf_versioned_syms.tmp;        \
index d9b385f..10a4c4c 100644 (file)
@@ -15,6 +15,9 @@
 static inline size_t hash_bits(size_t h, int bits)
 {
        /* shuffle bits and return requested number of upper bits */
+       if (bits == 0)
+               return 0;
+
 #if (__SIZEOF_SIZE_T__ == __SIZEOF_LONG_LONG__)
        /* LP64 case */
        return (h * 11400714819323198485llu) >> (__SIZEOF_LONG_LONG__ * 8 - bits);
@@ -174,17 +177,17 @@ bool hashmap__find(const struct hashmap *map, const void *key, void **value);
  * @key: key to iterate entries for
  */
 #define hashmap__for_each_key_entry(map, cur, _key)                        \
-       for (cur = ({ size_t bkt = hash_bits(map->hash_fn((_key), map->ctx),\
-                                            map->cap_bits);                \
-                    map->buckets ? map->buckets[bkt] : NULL; });           \
+       for (cur = map->buckets                                             \
+                    ? map->buckets[hash_bits(map->hash_fn((_key), map->ctx), map->cap_bits)] \
+                    : NULL;                                                \
             cur;                                                           \
             cur = cur->next)                                               \
                if (map->equal_fn(cur->key, (_key), map->ctx))
 
 #define hashmap__for_each_key_entry_safe(map, cur, tmp, _key)              \
-       for (cur = ({ size_t bkt = hash_bits(map->hash_fn((_key), map->ctx),\
-                                            map->cap_bits);                \
-                    cur = map->buckets ? map->buckets[bkt] : NULL; });     \
+       for (cur = map->buckets                                             \
+                    ? map->buckets[hash_bits(map->hash_fn((_key), map->ctx), map->cap_bits)] \
+                    : NULL;                                                \
             cur && ({ tmp = cur->next; true; });                           \
             cur = tmp)                                                     \
                if (map->equal_fn(cur->key, (_key), map->ctx))
index 3130341..28baee7 100644 (file)
@@ -560,8 +560,6 @@ bpf_object__init_prog(struct bpf_object *obj, struct bpf_program *prog,
                      const char *name, size_t sec_idx, const char *sec_name,
                      size_t sec_off, void *insn_data, size_t insn_data_sz)
 {
-       int i;
-
        if (insn_data_sz == 0 || insn_data_sz % BPF_INSN_SZ || sec_off % BPF_INSN_SZ) {
                pr_warn("sec '%s': corrupted program '%s', offset %zu, size %zu\n",
                        sec_name, name, sec_off, insn_data_sz);
@@ -600,13 +598,6 @@ bpf_object__init_prog(struct bpf_object *obj, struct bpf_program *prog,
                goto errout;
        memcpy(prog->insns, insn_data, insn_data_sz);
 
-       for (i = 0; i < prog->insns_cnt; i++) {
-               if (insn_is_subprog_call(&prog->insns[i])) {
-                       obj->has_subcalls = true;
-                       break;
-               }
-       }
-
        return 0;
 errout:
        pr_warn("sec '%s': failed to allocate memory for prog '%s'\n", sec_name, name);
@@ -3280,7 +3271,19 @@ bpf_object__find_program_by_title(const struct bpf_object *obj,
 static bool prog_is_subprog(const struct bpf_object *obj,
                            const struct bpf_program *prog)
 {
-       return prog->sec_idx == obj->efile.text_shndx && obj->has_subcalls;
+       /* For legacy reasons, libbpf supports an entry-point BPF programs
+        * without SEC() attribute, i.e., those in the .text section. But if
+        * there are 2 or more such programs in the .text section, they all
+        * must be subprograms called from entry-point BPF programs in
+        * designated SEC()'tions, otherwise there is no way to distinguish
+        * which of those programs should be loaded vs which are a subprogram.
+        * Similarly, if there is a function/program in .text and at least one
+        * other BPF program with custom SEC() attribute, then we just assume
+        * .text programs are subprograms (even if they are not called from
+        * other programs), because libbpf never explicitly supported mixing
+        * SEC()-designated BPF programs and .text entry-point BPF programs.
+        */
+       return prog->sec_idx == obj->efile.text_shndx && obj->nr_programs > 1;
 }
 
 struct bpf_program *
index e3c98c0..9bc537d 100644 (file)
@@ -891,13 +891,16 @@ int xsk_umem__delete(struct xsk_umem *umem)
 void xsk_socket__delete(struct xsk_socket *xsk)
 {
        size_t desc_sz = sizeof(struct xdp_desc);
-       struct xsk_ctx *ctx = xsk->ctx;
        struct xdp_mmap_offsets off;
+       struct xsk_umem *umem;
+       struct xsk_ctx *ctx;
        int err;
 
        if (!xsk)
                return;
 
+       ctx = xsk->ctx;
+       umem = ctx->umem;
        if (ctx->prog_fd != -1) {
                xsk_delete_bpf_maps(xsk);
                close(ctx->prog_fd);
@@ -917,11 +920,11 @@ void xsk_socket__delete(struct xsk_socket *xsk)
 
        xsk_put_ctx(ctx);
 
-       ctx->umem->refcount--;
+       umem->refcount--;
        /* Do not close an fd that also has an associated umem connected
         * to it.
         */
-       if (xsk->fd != ctx->umem->fd)
+       if (xsk->fd != umem->fd)
                close(xsk->fd);
        free(xsk);
 }
index 6890fc4..ce8516e 100644 (file)
@@ -749,6 +749,7 @@ else
   PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
   PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null)
   PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
+  PERL_EMBED_CCOPTS := $(filter-out -flto=auto -ffat-lto-objects, $(PERL_EMBED_CCOPTS))
   PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
   FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
 
index 3478096..3798192 100644 (file)
 437    common  openat2                 sys_openat2
 438    common  pidfd_getfd             sys_pidfd_getfd
 439    common  faccessat2              sys_faccessat2
+440    common  process_madvise         sys_process_madvise
 
 #
-# x32-specific system call numbers start at 512 to avoid cache impact
-# for native 64-bit operation. The __x32_compat_sys stubs are created
-# on-the-fly for compat_sys_*() compatibility system calls if X86_X32
-# is defined.
+# Due to a historical design error, certain syscalls are numbered differently
+# in x32 as compared to native x86_64.  These syscalls have numbers 512-547.
+# Do not add new syscalls to this range.  Numbers 548 and above are available
+# for non-x32 use.
 #
 512    x32     rt_sigaction            compat_sys_rt_sigaction
 513    x32     rt_sigreturn            compat_sys_x32_rt_sigreturn
 545    x32     execveat                compat_sys_execveat
 546    x32     preadv2                 compat_sys_preadv64v2
 547    x32     pwritev2                compat_sys_pwritev64v2
+# This is the end of the legacy x32 range.  Numbers 548 and above are
+# not special and are not to be used for x32-specific syscalls.
index 4e40402..478078f 100644 (file)
@@ -38,6 +38,13 @@ static int sample_ustack(struct perf_sample *sample,
        stack_size = stack_size > STACK_SIZE ? STACK_SIZE : stack_size;
 
        memcpy(buf, (void *) sp, stack_size);
+#ifdef MEMORY_SANITIZER
+       /*
+        * Copying the stack may copy msan poison, avoid false positives in the
+        * unwinder by removing the poison here.
+        */
+       __msan_unpoison(buf, stack_size);
+#endif
        stack->data = (char *) buf;
        stack->size = stack_size;
        return 0;
index 9ad015a..6eb45a2 100644 (file)
@@ -2,6 +2,9 @@
 
 /* Various wrappers to make the kernel .S file build in user-space: */
 
+// memcpy_orig and memcpy_erms are being defined as SYM_L_LOCAL but we need it
+#define SYM_FUNC_START_LOCAL(name)                      \
+        SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
 #define memcpy MEMCPY /* don't hide glibc's memcpy() */
 #define altinstr_replacement text
 #define globl p2align 4; .globl
index d550bd5..6f093c4 100644 (file)
@@ -1,4 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0 */
+// memset_orig and memset_erms are being defined as SYM_L_LOCAL but we need it
+#define SYM_FUNC_START_LOCAL(name)                      \
+        SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
 #define memset MEMSET /* don't hide glibc's memset() */
 #define altinstr_replacement text
 #define globl p2align 4; .globl
index 452a75f..0462dc8 100644 (file)
@@ -779,25 +779,15 @@ static int __cmd_inject(struct perf_inject *inject)
                        dsos__hit_all(session);
                /*
                 * The AUX areas have been removed and replaced with
-                * synthesized hardware events, so clear the feature flag and
-                * remove the evsel.
+                * synthesized hardware events, so clear the feature flag.
                 */
                if (inject->itrace_synth_opts.set) {
-                       struct evsel *evsel;
-
                        perf_header__clear_feat(&session->header,
                                                HEADER_AUXTRACE);
                        if (inject->itrace_synth_opts.last_branch ||
                            inject->itrace_synth_opts.add_last_branch)
                                perf_header__set_feat(&session->header,
                                                      HEADER_BRANCH_STACK);
-                       evsel = perf_evlist__id2evsel_strict(session->evlist,
-                                                            inject->aux_id);
-                       if (evsel) {
-                               pr_debug("Deleting %s\n", evsel__name(evsel));
-                               evlist__remove(session->evlist, evsel);
-                               evsel__delete(evsel);
-                       }
                }
                session->header.data_offset = output_data_offset;
                session->header.data_size = inject->bytes_written;
index f0a1dba..a2f1e53 100644 (file)
@@ -406,7 +406,7 @@ static int report_lock_acquire_event(struct evsel *evsel,
        struct lock_seq_stat *seq;
        const char *name = evsel__strval(evsel, sample, "name");
        u64 tmp  = evsel__intval(evsel, sample, "lockdep_addr");
-       int flag = evsel__intval(evsel, sample, "flag");
+       int flag = evsel__intval(evsel, sample, "flags");
 
        memcpy(&addr, &tmp, sizeof(void *));
 
@@ -621,7 +621,7 @@ static int report_lock_release_event(struct evsel *evsel,
        case SEQ_STATE_READ_ACQUIRED:
                seq->read_count--;
                BUG_ON(seq->read_count < 0);
-               if (!seq->read_count) {
+               if (seq->read_count) {
                        ls->nr_release++;
                        goto end;
                }
index 44a75f2..de80534 100644 (file)
@@ -4639,9 +4639,9 @@ do_concat:
        err = 0;
 
        if (lists[0]) {
-               struct option o = OPT_CALLBACK('e', "event", &trace->evlist, "event",
-                                              "event selector. use 'perf list' to list available events",
-                                              parse_events_option);
+               struct option o = {
+                       .value = &trace->evlist,
+               };
                err = parse_events_option(&o, lists[0], 0);
        }
 out:
@@ -4655,9 +4655,12 @@ static int trace__parse_cgroups(const struct option *opt, const char *str, int u
 {
        struct trace *trace = opt->value;
 
-       if (!list_empty(&trace->evlist->core.entries))
-               return parse_cgroups(opt, str, unset);
-
+       if (!list_empty(&trace->evlist->core.entries)) {
+               struct option o = {
+                       .value = &trace->evlist,
+               };
+               return parse_cgroups(&o, str, unset);
+       }
        trace->cgroup = evlist__findnew_cgroup(trace->evlist, str);
 
        return 0;
index de31935..00f4fcf 100644 (file)
     },
     {
         "BriefDescription": "Average external Memory Bandwidth Use for reads and writes [GB / sec]",
-        "MetricExpr": "( 64 * ( uncore_imc@cas_count_read@ + uncore_imc@cas_count_write@ ) / 1000000000 ) / duration_time",
+        "MetricExpr": "( ( ( uncore_imc@cas_count_read@ + uncore_imc@cas_count_write@ ) * 1048576 ) / 1000000000 ) / duration_time",
         "MetricGroup": "Memory_BW;SoC",
         "MetricName": "DRAM_BW_Use"
     },
index f31794d..0dd8b13 100644 (file)
     },
     {
         "BriefDescription": "Average external Memory Bandwidth Use for reads and writes [GB / sec]",
-        "MetricExpr": "( 64 * ( uncore_imc@cas_count_read@ + uncore_imc@cas_count_write@ ) / 1000000000 ) / duration_time",
+        "MetricExpr": "( ( ( uncore_imc@cas_count_read@ + uncore_imc@cas_count_write@ ) * 1048576 ) / 1000000000 ) / duration_time",
         "MetricGroup": "Memory_BW;SoC",
         "MetricName": "DRAM_BW_Use"
     },
index 2491d16..8363809 100644 (file)
@@ -95,7 +95,7 @@ static int unwind_entry(struct unwind_entry *entry, void *arg)
        return strcmp((const char *) symbol, funcs[idx]);
 }
 
-__no_tail_call noinline int test_dwarf_unwind__thread(struct thread *thread)
+noinline int test_dwarf_unwind__thread(struct thread *thread)
 {
        struct perf_sample sample;
        unsigned long cnt = 0;
@@ -126,7 +126,7 @@ __no_tail_call noinline int test_dwarf_unwind__thread(struct thread *thread)
 
 static int global_unwind_retval = -INT_MAX;
 
-__no_tail_call noinline int test_dwarf_unwind__compare(void *p1, void *p2)
+noinline int test_dwarf_unwind__compare(void *p1, void *p2)
 {
        /* Any possible value should be 'thread' */
        struct thread *thread = *(struct thread **)p1;
@@ -145,7 +145,7 @@ __no_tail_call noinline int test_dwarf_unwind__compare(void *p1, void *p2)
        return p1 - p2;
 }
 
-__no_tail_call noinline int test_dwarf_unwind__krava_3(struct thread *thread)
+noinline int test_dwarf_unwind__krava_3(struct thread *thread)
 {
        struct thread *array[2] = {thread, thread};
        void *fp = &bsearch;
@@ -164,12 +164,12 @@ __no_tail_call noinline int test_dwarf_unwind__krava_3(struct thread *thread)
        return global_unwind_retval;
 }
 
-__no_tail_call noinline int test_dwarf_unwind__krava_2(struct thread *thread)
+noinline int test_dwarf_unwind__krava_2(struct thread *thread)
 {
        return test_dwarf_unwind__krava_3(thread);
 }
 
-__no_tail_call noinline int test_dwarf_unwind__krava_1(struct thread *thread)
+noinline int test_dwarf_unwind__krava_1(struct thread *thread)
 {
        return test_dwarf_unwind__krava_2(thread);
 }
index 8d84fdb..18fde2f 100755 (executable)
@@ -44,7 +44,7 @@ perf_script_branch_samples() {
        #   touch  6512          1         branches:u:      ffffb22082e0 strcmp+0xa0 (/lib/aarch64-linux-gnu/ld-2.27.so)
        #   touch  6512          1         branches:u:      ffffb2208320 strcmp+0xe0 (/lib/aarch64-linux-gnu/ld-2.27.so)
        perf script -F,-time -i ${perfdata} | \
-               egrep " +$1 +[0-9]+ .* +branches:([u|k]:)? +"
+               egrep " +$1 +[0-9]+ .* +branches:(.*:)? +"
 }
 
 perf_report_branch_samples() {
@@ -105,7 +105,7 @@ arm_cs_iterate_devices() {
                #     `> device_name = 'tmc_etf0'
                device_name=$(basename $path)
 
-               if is_device_sink $path $devce_name; then
+               if is_device_sink $path $device_name; then
 
                        record_touch_file $device_name $2 &&
                        perf_script_branch_samples touch &&
index a07626f..b0e1880 100644 (file)
@@ -2963,7 +2963,7 @@ static int perf_evsel__hists_browse(struct evsel *evsel, int nr_events,
        struct popup_action actions[MAX_OPTIONS];
        int nr_options = 0;
        int key = -1;
-       char buf[64];
+       char buf[128];
        int delay_secs = hbt ? hbt->refresh : 0;
 
 #define HIST_BROWSER_HELP_COMMON                                       \
index 8763772..6b410c3 100644 (file)
@@ -102,6 +102,8 @@ int build_id__sprintf(const struct build_id *build_id, char *bf)
        const u8 *raw = build_id->data;
        size_t i;
 
+       bf[0] = 0x0;
+
        for (i = 0; i < build_id->size; ++i) {
                sprintf(bid, "%02x", *raw);
                ++raw;
index a405dad..3c20b12 100644 (file)
@@ -15,6 +15,9 @@
 /* make sure libbpf doesn't use kernel-only integer typedefs */
 #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
 
+/* prevent accidental re-addition of reallocarray() */
+#pragma GCC poison reallocarray
+
 /* start with 4 buckets */
 #define HASHMAP_MIN_CAP_BITS 2
 
index e0af36b..d9b385f 100644 (file)
@@ -25,6 +25,18 @@ static inline size_t hash_bits(size_t h, int bits)
 #endif
 }
 
+/* generic C-string hashing function */
+static inline size_t str_hash(const char *s)
+{
+       size_t h = 0;
+
+       while (*s) {
+               h = h * 31 + *s;
+               s++;
+       }
+       return h;
+}
+
 typedef size_t (*hashmap_hash_fn)(const void *key, void *ctx);
 typedef bool (*hashmap_equal_fn)(const void *key1, const void *key2, void *ctx);
 
index b8a5159..5acf053 100644 (file)
@@ -25,6 +25,7 @@
 
 /* SYM_L_* -- linkage of symbols */
 #define SYM_L_GLOBAL(name)                     .globl name
+#define SYM_L_WEAK(name)                       .weak name
 #define SYM_L_LOCAL(name)                      /* nothing */
 
 #define ALIGN __ALIGN
        SYM_END(name, SYM_T_FUNC)
 #endif
 
+/* SYM_FUNC_START_WEAK -- use for weak functions */
+#ifndef SYM_FUNC_START_WEAK
+#define SYM_FUNC_START_WEAK(name)                      \
+       SYM_START(name, SYM_L_WEAK, SYM_A_ALIGN)
+#endif
+
 /*
  * SYM_FUNC_END -- the end of SYM_FUNC_START_LOCAL, SYM_FUNC_START,
  * SYM_FUNC_START_WEAK, ...
index 7d4194f..15385ea 100644 (file)
@@ -786,11 +786,20 @@ static int machine__process_ksymbol_unregister(struct machine *machine,
                                               union perf_event *event,
                                               struct perf_sample *sample __maybe_unused)
 {
+       struct symbol *sym;
        struct map *map;
 
        map = maps__find(&machine->kmaps, event->ksymbol.addr);
-       if (map)
+       if (!map)
+               return 0;
+
+       if (map != machine->vmlinux_map)
                maps__remove(&machine->kmaps, map);
+       else {
+               sym = dso__find_symbol(map->dso, map->map_ip(map, map->start));
+               if (sym)
+                       dso__delete_symbol(map->dso, sym);
+       }
 
        return 0;
 }
index 7cbd024..c83c2c6 100644 (file)
@@ -1592,7 +1592,6 @@ static void _free_command_line(wchar_t **command_line, int num)
 static int python_start_script(const char *script, int argc, const char **argv)
 {
        struct tables *tables = &tables_global;
-       PyMODINIT_FUNC (*initfunc)(void);
 #if PY_MAJOR_VERSION < 3
        const char **command_line;
 #else
@@ -1607,20 +1606,18 @@ static int python_start_script(const char *script, int argc, const char **argv)
        FILE *fp;
 
 #if PY_MAJOR_VERSION < 3
-       initfunc = initperf_trace_context;
        command_line = malloc((argc + 1) * sizeof(const char *));
        command_line[0] = script;
        for (i = 1; i < argc + 1; i++)
                command_line[i] = argv[i - 1];
+       PyImport_AppendInittab(name, initperf_trace_context);
 #else
-       initfunc = PyInit_perf_trace_context;
        command_line = malloc((argc + 1) * sizeof(wchar_t *));
        command_line[0] = Py_DecodeLocale(script, NULL);
        for (i = 1; i < argc + 1; i++)
                command_line[i] = Py_DecodeLocale(argv[i - 1], NULL);
+       PyImport_AppendInittab(name, PyInit_perf_trace_context);
 #endif
-
-       PyImport_AppendInittab(name, initfunc);
        Py_Initialize();
 
 #if PY_MAJOR_VERSION < 3
index 7a5f037..0980802 100644 (file)
@@ -595,6 +595,7 @@ static void perf_event__mmap2_swap(union perf_event *event,
        event->mmap2.maj   = bswap_32(event->mmap2.maj);
        event->mmap2.min   = bswap_32(event->mmap2.min);
        event->mmap2.ino   = bswap_64(event->mmap2.ino);
+       event->mmap2.ino_generation = bswap_64(event->mmap2.ino_generation);
 
        if (sample_id_all) {
                void *data = &event->mmap2.filename;
@@ -710,6 +711,18 @@ static void perf_event__namespaces_swap(union perf_event *event,
                swap_sample_id_all(event, &event->namespaces.link_info[i]);
 }
 
+static void perf_event__cgroup_swap(union perf_event *event, bool sample_id_all)
+{
+       event->cgroup.id = bswap_64(event->cgroup.id);
+
+       if (sample_id_all) {
+               void *data = &event->cgroup.path;
+
+               data += PERF_ALIGN(strlen(data) + 1, sizeof(u64));
+               swap_sample_id_all(event, data);
+       }
+}
+
 static u8 revbyte(u8 b)
 {
        int rev = (b >> 4) | ((b & 0xf) << 4);
@@ -952,6 +965,7 @@ static perf_event__swap_op perf_event__swap_ops[] = {
        [PERF_RECORD_SWITCH]              = perf_event__switch_swap,
        [PERF_RECORD_SWITCH_CPU_WIDE]     = perf_event__switch_swap,
        [PERF_RECORD_NAMESPACES]          = perf_event__namespaces_swap,
+       [PERF_RECORD_CGROUP]              = perf_event__cgroup_swap,
        [PERF_RECORD_TEXT_POKE]           = perf_event__text_poke_swap,
        [PERF_RECORD_HEADER_ATTR]         = perf_event__hdr_attr_swap,
        [PERF_RECORD_HEADER_EVENT_TYPE]   = perf_event__event_type_swap,
index 6138866..0d14abd 100644 (file)
@@ -515,6 +515,13 @@ void dso__insert_symbol(struct dso *dso, struct symbol *sym)
        }
 }
 
+void dso__delete_symbol(struct dso *dso, struct symbol *sym)
+{
+       rb_erase_cached(&sym->rb_node, &dso->symbols);
+       symbol__delete(sym);
+       dso__reset_find_symbol_cache(dso);
+}
+
 struct symbol *dso__find_symbol(struct dso *dso, u64 addr)
 {
        if (dso->last_find_result.addr != addr || dso->last_find_result.symbol == NULL) {
index f4801c4..954d6a0 100644 (file)
@@ -131,6 +131,8 @@ int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map);
 
 void dso__insert_symbol(struct dso *dso,
                        struct symbol *sym);
+void dso__delete_symbol(struct dso *dso,
+                       struct symbol *sym);
 
 struct symbol *dso__find_symbol(struct dso *dso, u64 addr);
 struct symbol *dso__find_symbol_by_name(struct dso *dso, const char *name);
index 2b65512..f3e3c94 100644 (file)
@@ -12,11 +12,12 @@ turbostat : turbostat.c
 override CFLAGS +=     -O2 -Wall -I../../../include
 override CFLAGS +=     -DMSRHEADER='"../../../../arch/x86/include/asm/msr-index.h"'
 override CFLAGS +=     -DINTEL_FAMILY_HEADER='"../../../../arch/x86/include/asm/intel-family.h"'
+override CFLAGS +=     -D_FILE_OFFSET_BITS=64
 override CFLAGS +=     -D_FORTIFY_SOURCE=2
 
 %: %.c
        @mkdir -p $(BUILD_OUTPUT)
-       $(CC) $(CFLAGS) $< -o $(BUILD_OUTPUT)/$@ $(LDFLAGS) -lcap
+       $(CC) $(CFLAGS) $< -o $(BUILD_OUTPUT)/$@ $(LDFLAGS) -lcap -lrt
 
 .PHONY : clean
 clean :
index a6db83a..f6b7e85 100644 (file)
@@ -335,7 +335,7 @@ that they count at TSC rate, which is true on all processors tested to date.
 
 .SH REFERENCES
 Volume 3B: System Programming Guide"
-http://www.intel.com/products/processor/manuals/
+https://www.intel.com/products/processor/manuals/
 
 .SH FILES
 .ta
index 33b3708..f3a1746 100644 (file)
@@ -79,6 +79,7 @@ unsigned long long  gfx_cur_rc6_ms;
 unsigned long long cpuidle_cur_cpu_lpi_us;
 unsigned long long cpuidle_cur_sys_lpi_us;
 unsigned int gfx_cur_mhz;
+unsigned int gfx_act_mhz;
 unsigned int tcc_activation_temp;
 unsigned int tcc_activation_temp_override;
 double rapl_power_units, rapl_time_units;
@@ -210,13 +211,14 @@ struct pkg_data {
        unsigned long long pkg_both_core_gfxe_c0;
        long long gfx_rc6_ms;
        unsigned int gfx_mhz;
+       unsigned int gfx_act_mhz;
        unsigned int package_id;
-       unsigned int energy_pkg;        /* MSR_PKG_ENERGY_STATUS */
-       unsigned int energy_dram;       /* MSR_DRAM_ENERGY_STATUS */
-       unsigned int energy_cores;      /* MSR_PP0_ENERGY_STATUS */
-       unsigned int energy_gfx;        /* MSR_PP1_ENERGY_STATUS */
-       unsigned int rapl_pkg_perf_status;      /* MSR_PKG_PERF_STATUS */
-       unsigned int rapl_dram_perf_status;     /* MSR_DRAM_PERF_STATUS */
+       unsigned long long energy_pkg;  /* MSR_PKG_ENERGY_STATUS */
+       unsigned long long energy_dram; /* MSR_DRAM_ENERGY_STATUS */
+       unsigned long long energy_cores;        /* MSR_PP0_ENERGY_STATUS */
+       unsigned long long energy_gfx;  /* MSR_PP1_ENERGY_STATUS */
+       unsigned long long rapl_pkg_perf_status;        /* MSR_PKG_PERF_STATUS */
+       unsigned long long rapl_dram_perf_status;       /* MSR_DRAM_PERF_STATUS */
        unsigned int pkg_temp_c;
        unsigned long long counter[MAX_ADDED_COUNTERS];
 } *package_even, *package_odd;
@@ -259,6 +261,113 @@ struct msr_counter {
 #define        SYSFS_PERCPU    (1 << 1)
 };
 
+/*
+ * The accumulated sum of MSR is defined as a monotonic
+ * increasing MSR, it will be accumulated periodically,
+ * despite its register's bit width.
+ */
+enum {
+       IDX_PKG_ENERGY,
+       IDX_DRAM_ENERGY,
+       IDX_PP0_ENERGY,
+       IDX_PP1_ENERGY,
+       IDX_PKG_PERF,
+       IDX_DRAM_PERF,
+       IDX_COUNT,
+};
+
+int get_msr_sum(int cpu, off_t offset, unsigned long long *msr);
+
+struct msr_sum_array {
+       /* get_msr_sum() = sum + (get_msr() - last) */
+       struct {
+               /*The accumulated MSR value is updated by the timer*/
+               unsigned long long sum;
+               /*The MSR footprint recorded in last timer*/
+               unsigned long long last;
+       } entries[IDX_COUNT];
+};
+
+/* The percpu MSR sum array.*/
+struct msr_sum_array *per_cpu_msr_sum;
+
+int idx_to_offset(int idx)
+{
+       int offset;
+
+       switch (idx) {
+       case IDX_PKG_ENERGY:
+               offset = MSR_PKG_ENERGY_STATUS;
+               break;
+       case IDX_DRAM_ENERGY:
+               offset = MSR_DRAM_ENERGY_STATUS;
+               break;
+       case IDX_PP0_ENERGY:
+               offset = MSR_PP0_ENERGY_STATUS;
+               break;
+       case IDX_PP1_ENERGY:
+               offset = MSR_PP1_ENERGY_STATUS;
+               break;
+       case IDX_PKG_PERF:
+               offset = MSR_PKG_PERF_STATUS;
+               break;
+       case IDX_DRAM_PERF:
+               offset = MSR_DRAM_PERF_STATUS;
+               break;
+       default:
+               offset = -1;
+       }
+       return offset;
+}
+
+int offset_to_idx(int offset)
+{
+       int idx;
+
+       switch (offset) {
+       case MSR_PKG_ENERGY_STATUS:
+               idx = IDX_PKG_ENERGY;
+               break;
+       case MSR_DRAM_ENERGY_STATUS:
+               idx = IDX_DRAM_ENERGY;
+               break;
+       case MSR_PP0_ENERGY_STATUS:
+               idx = IDX_PP0_ENERGY;
+               break;
+       case MSR_PP1_ENERGY_STATUS:
+               idx = IDX_PP1_ENERGY;
+               break;
+       case MSR_PKG_PERF_STATUS:
+               idx = IDX_PKG_PERF;
+               break;
+       case MSR_DRAM_PERF_STATUS:
+               idx = IDX_DRAM_PERF;
+               break;
+       default:
+               idx = -1;
+       }
+       return idx;
+}
+
+int idx_valid(int idx)
+{
+       switch (idx) {
+       case IDX_PKG_ENERGY:
+               return do_rapl & RAPL_PKG;
+       case IDX_DRAM_ENERGY:
+               return do_rapl & RAPL_DRAM;
+       case IDX_PP0_ENERGY:
+               return do_rapl & RAPL_CORES_ENERGY_STATUS;
+       case IDX_PP1_ENERGY:
+               return do_rapl & RAPL_GFX;
+       case IDX_PKG_PERF:
+               return do_rapl & RAPL_PKG_PERF_STATUS;
+       case IDX_DRAM_PERF:
+               return do_rapl & RAPL_DRAM_PERF_STATUS;
+       default:
+               return 0;
+       }
+}
 struct sys_counters {
        unsigned int added_thread_counters;
        unsigned int added_core_counters;
@@ -451,6 +560,7 @@ struct msr_counter bic[] = {
        { 0x0, "APIC" },
        { 0x0, "X2APIC" },
        { 0x0, "Die" },
+       { 0x0, "GFXAMHz" },
 };
 
 #define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter))
@@ -505,6 +615,7 @@ struct msr_counter bic[] = {
 #define        BIC_APIC        (1ULL << 48)
 #define        BIC_X2APIC      (1ULL << 49)
 #define        BIC_Die         (1ULL << 50)
+#define        BIC_GFXACTMHz   (1ULL << 51)
 
 #define BIC_DISABLED_BY_DEFAULT        (BIC_USEC | BIC_TOD | BIC_APIC | BIC_X2APIC)
 
@@ -724,6 +835,9 @@ void print_header(char *delim)
        if (DO_BIC(BIC_GFXMHz))
                outp += sprintf(outp, "%sGFXMHz", (printed++ ? delim : ""));
 
+       if (DO_BIC(BIC_GFXACTMHz))
+               outp += sprintf(outp, "%sGFXAMHz", (printed++ ? delim : ""));
+
        if (DO_BIC(BIC_Totl_c0))
                outp += sprintf(outp, "%sTotl%%C0", (printed++ ? delim : ""));
        if (DO_BIC(BIC_Any_c0))
@@ -858,13 +972,13 @@ int dump_counters(struct thread_data *t, struct core_data *c,
                outp += sprintf(outp, "pc10: %016llX\n", p->pc10);
                outp += sprintf(outp, "cpu_lpi: %016llX\n", p->cpu_lpi);
                outp += sprintf(outp, "sys_lpi: %016llX\n", p->sys_lpi);
-               outp += sprintf(outp, "Joules PKG: %0X\n", p->energy_pkg);
-               outp += sprintf(outp, "Joules COR: %0X\n", p->energy_cores);
-               outp += sprintf(outp, "Joules GFX: %0X\n", p->energy_gfx);
-               outp += sprintf(outp, "Joules RAM: %0X\n", p->energy_dram);
-               outp += sprintf(outp, "Throttle PKG: %0X\n",
+               outp += sprintf(outp, "Joules PKG: %0llX\n", p->energy_pkg);
+               outp += sprintf(outp, "Joules COR: %0llX\n", p->energy_cores);
+               outp += sprintf(outp, "Joules GFX: %0llX\n", p->energy_gfx);
+               outp += sprintf(outp, "Joules RAM: %0llX\n", p->energy_dram);
+               outp += sprintf(outp, "Throttle PKG: %0llX\n",
                        p->rapl_pkg_perf_status);
-               outp += sprintf(outp, "Throttle RAM: %0X\n",
+               outp += sprintf(outp, "Throttle RAM: %0llX\n",
                        p->rapl_dram_perf_status);
                outp += sprintf(outp, "PTM: %dC\n", p->pkg_temp_c);
 
@@ -1062,14 +1176,7 @@ int format_counters(struct thread_data *t, struct core_data *c,
                }
        }
 
-       /*
-        * If measurement interval exceeds minimum RAPL Joule Counter range,
-        * indicate that results are suspect by printing "**" in fraction place.
-        */
-       if (interval_float < rapl_joule_counter_range)
-               fmt8 = "%s%.2f";
-       else
-               fmt8 = "%6.0f**";
+       fmt8 = "%s%.2f";
 
        if (DO_BIC(BIC_CorWatt) && (do_rapl & RAPL_PER_CORE_ENERGY))
                outp += sprintf(outp, fmt8, (printed++ ? delim : ""), c->core_energy * rapl_energy_units / interval_float);
@@ -1098,6 +1205,10 @@ int format_counters(struct thread_data *t, struct core_data *c,
        if (DO_BIC(BIC_GFXMHz))
                outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_mhz);
 
+       /* GFXACTMHz */
+       if (DO_BIC(BIC_GFXACTMHz))
+               outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_act_mhz);
+
        /* Totl%C0, Any%C0 GFX%C0 CPUGFX% */
        if (DO_BIC(BIC_Totl_c0))
                outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_wtd_core_c0/tsc);
@@ -1210,11 +1321,7 @@ void format_all_counters(struct thread_data *t, struct core_data *c, struct pkg_
 }
 
 #define DELTA_WRAP32(new, old)                 \
-       if (new > old) {                        \
-               old = new - old;                \
-       } else {                                \
-               old = 0x100000000 + new - old;  \
-       }
+       old = ((((unsigned long long)new << 32) - ((unsigned long long)old << 32)) >> 32);
 
 int
 delta_package(struct pkg_data *new, struct pkg_data *old)
@@ -1253,13 +1360,14 @@ delta_package(struct pkg_data *new, struct pkg_data *old)
                old->gfx_rc6_ms = new->gfx_rc6_ms - old->gfx_rc6_ms;
 
        old->gfx_mhz = new->gfx_mhz;
+       old->gfx_act_mhz = new->gfx_act_mhz;
 
-       DELTA_WRAP32(new->energy_pkg, old->energy_pkg);
-       DELTA_WRAP32(new->energy_cores, old->energy_cores);
-       DELTA_WRAP32(new->energy_gfx, old->energy_gfx);
-       DELTA_WRAP32(new->energy_dram, old->energy_dram);
-       DELTA_WRAP32(new->rapl_pkg_perf_status, old->rapl_pkg_perf_status);
-       DELTA_WRAP32(new->rapl_dram_perf_status, old->rapl_dram_perf_status);
+       old->energy_pkg = new->energy_pkg - old->energy_pkg;
+       old->energy_cores = new->energy_cores - old->energy_cores;
+       old->energy_gfx = new->energy_gfx - old->energy_gfx;
+       old->energy_dram = new->energy_dram - old->energy_dram;
+       old->rapl_pkg_perf_status = new->rapl_pkg_perf_status - old->rapl_pkg_perf_status;
+       old->rapl_dram_perf_status = new->rapl_dram_perf_status - old->rapl_dram_perf_status;
 
        for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) {
                if (mp->format == FORMAT_RAW)
@@ -1469,6 +1577,7 @@ void clear_counters(struct thread_data *t, struct core_data *c, struct pkg_data
 
        p->gfx_rc6_ms = 0;
        p->gfx_mhz = 0;
+       p->gfx_act_mhz = 0;
        for (i = 0, mp = sys.tp; mp; i++, mp = mp->next)
                t->counter[i] = 0;
 
@@ -1564,6 +1673,7 @@ int sum_counters(struct thread_data *t, struct core_data *c,
 
        average.packages.gfx_rc6_ms = p->gfx_rc6_ms;
        average.packages.gfx_mhz = p->gfx_mhz;
+       average.packages.gfx_act_mhz = p->gfx_act_mhz;
 
        average.packages.pkg_temp_c = MAX(average.packages.pkg_temp_c, p->pkg_temp_c);
 
@@ -1784,7 +1894,7 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
        int i;
 
        if (cpu_migrate(cpu)) {
-               fprintf(outf, "Could not migrate to CPU %d\n", cpu);
+               fprintf(outf, "get_counters: Could not migrate to CPU %d\n", cpu);
                return -1;
        }
 
@@ -1966,39 +2076,39 @@ retry:
                p->sys_lpi = cpuidle_cur_sys_lpi_us;
 
        if (do_rapl & RAPL_PKG) {
-               if (get_msr(cpu, MSR_PKG_ENERGY_STATUS, &msr))
+               if (get_msr_sum(cpu, MSR_PKG_ENERGY_STATUS, &msr))
                        return -13;
-               p->energy_pkg = msr & 0xFFFFFFFF;
+               p->energy_pkg = msr;
        }
        if (do_rapl & RAPL_CORES_ENERGY_STATUS) {
-               if (get_msr(cpu, MSR_PP0_ENERGY_STATUS, &msr))
+               if (get_msr_sum(cpu, MSR_PP0_ENERGY_STATUS, &msr))
                        return -14;
-               p->energy_cores = msr & 0xFFFFFFFF;
+               p->energy_cores = msr;
        }
        if (do_rapl & RAPL_DRAM) {
-               if (get_msr(cpu, MSR_DRAM_ENERGY_STATUS, &msr))
+               if (get_msr_sum(cpu, MSR_DRAM_ENERGY_STATUS, &msr))
                        return -15;
-               p->energy_dram = msr & 0xFFFFFFFF;
+               p->energy_dram = msr;
        }
        if (do_rapl & RAPL_GFX) {
-               if (get_msr(cpu, MSR_PP1_ENERGY_STATUS, &msr))
+               if (get_msr_sum(cpu, MSR_PP1_ENERGY_STATUS, &msr))
                        return -16;
-               p->energy_gfx = msr & 0xFFFFFFFF;
+               p->energy_gfx = msr;
        }
        if (do_rapl & RAPL_PKG_PERF_STATUS) {
-               if (get_msr(cpu, MSR_PKG_PERF_STATUS, &msr))
+               if (get_msr_sum(cpu, MSR_PKG_PERF_STATUS, &msr))
                        return -16;
-               p->rapl_pkg_perf_status = msr & 0xFFFFFFFF;
+               p->rapl_pkg_perf_status = msr;
        }
        if (do_rapl & RAPL_DRAM_PERF_STATUS) {
-               if (get_msr(cpu, MSR_DRAM_PERF_STATUS, &msr))
+               if (get_msr_sum(cpu, MSR_DRAM_PERF_STATUS, &msr))
                        return -16;
-               p->rapl_dram_perf_status = msr & 0xFFFFFFFF;
+               p->rapl_dram_perf_status = msr;
        }
        if (do_rapl & RAPL_AMD_F17H) {
-               if (get_msr(cpu, MSR_PKG_ENERGY_STAT, &msr))
+               if (get_msr_sum(cpu, MSR_PKG_ENERGY_STAT, &msr))
                        return -13;
-               p->energy_pkg = msr & 0xFFFFFFFF;
+               p->energy_pkg = msr;
        }
        if (DO_BIC(BIC_PkgTmp)) {
                if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr))
@@ -2012,6 +2122,9 @@ retry:
        if (DO_BIC(BIC_GFXMHz))
                p->gfx_mhz = gfx_cur_mhz;
 
+       if (DO_BIC(BIC_GFXACTMHz))
+               p->gfx_act_mhz = gfx_act_mhz;
+
        for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) {
                if (get_mp(cpu, mp, &p->counter[i]))
                        return -10;
@@ -2173,6 +2286,7 @@ int has_turbo_ratio_group_limits(int family, int model)
        case INTEL_FAM6_ATOM_GOLDMONT:
        case INTEL_FAM6_SKYLAKE_X:
        case INTEL_FAM6_ATOM_GOLDMONT_D:
+       case INTEL_FAM6_ATOM_TREMONT_D:
                return 1;
        }
        return 0;
@@ -2650,7 +2764,12 @@ int get_thread_siblings(struct cpu_topology *thiscpu)
 
        sprintf(path,
                "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", cpu);
-       filep = fopen_or_die(path, "r");
+       filep = fopen(path, "r");
+
+       if (!filep) {
+               warnx("%s: open failed", path);
+               return -1;
+       }
        do {
                offset -= BITMASK_SIZE;
                if (fscanf(filep, "%lx%c", &map, &character) != 2)
@@ -2763,18 +2882,25 @@ void re_initialize(void)
 {
        free_all_buffers();
        setup_all_buffers();
-       printf("turbostat: re-initialized with num_cpus %d\n", topo.num_cpus);
+       fprintf(outf, "turbostat: re-initialized with num_cpus %d\n", topo.num_cpus);
 }
 
 void set_max_cpu_num(void)
 {
        FILE *filep;
+       int base_cpu;
        unsigned long dummy;
+       char pathname[64];
+
+       base_cpu = sched_getcpu();
+       if (base_cpu < 0)
+               err(1, "cannot find calling cpu ID");
+       sprintf(pathname,
+               "/sys/devices/system/cpu/cpu%d/topology/thread_siblings",
+               base_cpu);
 
+       filep = fopen_or_die(pathname, "r");
        topo.max_cpu_num = 0;
-       filep = fopen_or_die(
-                       "/sys/devices/system/cpu/cpu0/topology/thread_siblings",
-                       "r");
        while (fscanf(filep, "%lx,", &dummy) == 1)
                topo.max_cpu_num += BITMASK_SIZE;
        fclose(filep);
@@ -2915,6 +3041,33 @@ int snapshot_gfx_mhz(void)
        return 0;
 }
 
+/*
+ * snapshot_gfx_cur_mhz()
+ *
+ * record snapshot of
+ * /sys/class/graphics/fb0/device/drm/card0/gt_act_freq_mhz
+ *
+ * return 1 if config change requires a restart, else return 0
+ */
+int snapshot_gfx_act_mhz(void)
+{
+       static FILE *fp;
+       int retval;
+
+       if (fp == NULL)
+               fp = fopen_or_die("/sys/class/graphics/fb0/device/drm/card0/gt_act_freq_mhz", "r");
+       else {
+               rewind(fp);
+               fflush(fp);
+       }
+
+       retval = fscanf(fp, "%d", &gfx_act_mhz);
+       if (retval != 1)
+               err(1, "GFX ACT MHz");
+
+       return 0;
+}
+
 /*
  * snapshot_cpu_lpi()
  *
@@ -2980,6 +3133,9 @@ int snapshot_proc_sysfs_files(void)
        if (DO_BIC(BIC_GFXMHz))
                snapshot_gfx_mhz();
 
+       if (DO_BIC(BIC_GFXACTMHz))
+               snapshot_gfx_act_mhz();
+
        if (DO_BIC(BIC_CPU_LPI))
                snapshot_cpu_lpi_us();
 
@@ -3057,6 +3213,111 @@ void do_sleep(void)
        }
 }
 
+int get_msr_sum(int cpu, off_t offset, unsigned long long *msr)
+{
+       int ret, idx;
+       unsigned long long msr_cur, msr_last;
+
+       if (!per_cpu_msr_sum)
+               return 1;
+
+       idx = offset_to_idx(offset);
+       if (idx < 0)
+               return idx;
+       /* get_msr_sum() = sum + (get_msr() - last) */
+       ret = get_msr(cpu, offset, &msr_cur);
+       if (ret)
+               return ret;
+       msr_last = per_cpu_msr_sum[cpu].entries[idx].last;
+       DELTA_WRAP32(msr_cur, msr_last);
+       *msr = msr_last + per_cpu_msr_sum[cpu].entries[idx].sum;
+
+       return 0;
+}
+
+timer_t timerid;
+
+/* Timer callback, update the sum of MSRs periodically. */
+static int update_msr_sum(struct thread_data *t, struct core_data *c, struct pkg_data *p)
+{
+       int i, ret;
+       int cpu = t->cpu_id;
+
+       for (i = IDX_PKG_ENERGY; i < IDX_COUNT; i++) {
+               unsigned long long msr_cur, msr_last;
+               int offset;
+
+               if (!idx_valid(i))
+                       continue;
+               offset = idx_to_offset(i);
+               if (offset < 0)
+                       continue;
+               ret = get_msr(cpu, offset, &msr_cur);
+               if (ret) {
+                       fprintf(outf, "Can not update msr(0x%x)\n", offset);
+                       continue;
+               }
+
+               msr_last = per_cpu_msr_sum[cpu].entries[i].last;
+               per_cpu_msr_sum[cpu].entries[i].last = msr_cur & 0xffffffff;
+
+               DELTA_WRAP32(msr_cur, msr_last);
+               per_cpu_msr_sum[cpu].entries[i].sum += msr_last;
+       }
+       return 0;
+}
+
+static void
+msr_record_handler(union sigval v)
+{
+       for_all_cpus(update_msr_sum, EVEN_COUNTERS);
+}
+
+void msr_sum_record(void)
+{
+       struct itimerspec its;
+       struct sigevent sev;
+
+       per_cpu_msr_sum = calloc(topo.max_cpu_num + 1, sizeof(struct msr_sum_array));
+       if (!per_cpu_msr_sum) {
+               fprintf(outf, "Can not allocate memory for long time MSR.\n");
+               return;
+       }
+       /*
+        * Signal handler might be restricted, so use thread notifier instead.
+        */
+       memset(&sev, 0, sizeof(struct sigevent));
+       sev.sigev_notify = SIGEV_THREAD;
+       sev.sigev_notify_function = msr_record_handler;
+
+       sev.sigev_value.sival_ptr = &timerid;
+       if (timer_create(CLOCK_REALTIME, &sev, &timerid) == -1) {
+               fprintf(outf, "Can not create timer.\n");
+               goto release_msr;
+       }
+
+       its.it_value.tv_sec = 0;
+       its.it_value.tv_nsec = 1;
+       /*
+        * A wraparound time has been calculated early.
+        * Some sources state that the peak power for a
+        * microprocessor is usually 1.5 times the TDP rating,
+        * use 2 * TDP for safety.
+        */
+       its.it_interval.tv_sec = rapl_joule_counter_range / 2;
+       its.it_interval.tv_nsec = 0;
+
+       if (timer_settime(timerid, 0, &its, NULL) == -1) {
+               fprintf(outf, "Can not set timer.\n");
+               goto release_timer;
+       }
+       return;
+
+ release_timer:
+       timer_delete(timerid);
+ release_msr:
+       free(per_cpu_msr_sum);
+}
 
 void turbostat_loop()
 {
@@ -3075,7 +3336,7 @@ restart:
        if (retval < -1) {
                exit(retval);
        } else if (retval == -1) {
-               if (restarted > 1) {
+               if (restarted > 10) {
                        exit(retval);
                }
                re_initialize();
@@ -3279,6 +3540,7 @@ int probe_nhm_msrs(unsigned int family, unsigned int model)
        case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
        case INTEL_FAM6_ATOM_GOLDMONT_D:        /* DNV */
        case INTEL_FAM6_ATOM_TREMONT:   /* EHL */
+       case INTEL_FAM6_ATOM_TREMONT_D: /* JVL */
                pkg_cstate_limits = glm_pkg_cstate_limits;
                break;
        default:
@@ -3361,6 +3623,17 @@ int is_ehl(unsigned int family, unsigned int model)
        }
        return 0;
 }
+int is_jvl(unsigned int family, unsigned int model)
+{
+       if (!genuine_intel)
+               return 0;
+
+       switch (model) {
+       case INTEL_FAM6_ATOM_TREMONT_D:
+               return 1;
+       }
+       return 0;
+}
 
 int has_turbo_ratio_limit(unsigned int family, unsigned int model)
 {
@@ -3474,6 +3747,20 @@ int has_config_tdp(unsigned int family, unsigned int model)
        }
 }
 
+static void
+remove_underbar(char *s)
+{
+       char *to = s;
+
+       while (*s) {
+               if (*s != '_')
+                       *to++ = *s;
+               s++;
+       }
+
+       *to = 0;
+}
+
 static void
 dump_cstate_pstate_config_info(unsigned int family, unsigned int model)
 {
@@ -3530,9 +3817,6 @@ dump_sysfs_cstate_config(void)
        int state;
        char *sp;
 
-       if (!DO_BIC(BIC_sysfs))
-               return;
-
        if (access("/sys/devices/system/cpu/cpuidle", R_OK)) {
                fprintf(outf, "cpuidle not loaded\n");
                return;
@@ -3559,6 +3843,8 @@ dump_sysfs_cstate_config(void)
                *sp = '\0';
                fclose(input);
 
+               remove_underbar(name_buf);
+
                sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/desc",
                        base_cpu, state);
                input = fopen(path, "r");
@@ -3645,7 +3931,7 @@ int print_epb(struct thread_data *t, struct core_data *c, struct pkg_data *p)
                return 0;
 
        if (cpu_migrate(cpu)) {
-               fprintf(outf, "Could not migrate to CPU %d\n", cpu);
+               fprintf(outf, "print_epb: Could not migrate to CPU %d\n", cpu);
                return -1;
        }
 
@@ -3689,7 +3975,7 @@ int print_hwp(struct thread_data *t, struct core_data *c, struct pkg_data *p)
                return 0;
 
        if (cpu_migrate(cpu)) {
-               fprintf(outf, "Could not migrate to CPU %d\n", cpu);
+               fprintf(outf, "print_hwp: Could not migrate to CPU %d\n", cpu);
                return -1;
        }
 
@@ -3777,7 +4063,7 @@ int print_perf_limit(struct thread_data *t, struct core_data *c, struct pkg_data
                return 0;
 
        if (cpu_migrate(cpu)) {
-               fprintf(outf, "Could not migrate to CPU %d\n", cpu);
+               fprintf(outf, "print_perf_limit: Could not migrate to CPU %d\n", cpu);
                return -1;
        }
 
@@ -3881,13 +4167,8 @@ double get_tdp_intel(unsigned int model)
 
 double get_tdp_amd(unsigned int family)
 {
-       switch (family) {
-       case 0x17:
-       case 0x18:
-       default:
-               /* This is the max stock TDP of HEDT/Server Fam17h chips */
-               return 250.0;
-       }
+       /* This is the max stock TDP of HEDT/Server Fam17h+ chips */
+       return 280.0;
 }
 
 /*
@@ -3959,6 +4240,14 @@ void rapl_probe_intel(unsigned int family, unsigned int model)
                        BIC_PRESENT(BIC_GFXWatt);
                }
                break;
+       case INTEL_FAM6_ATOM_TREMONT_D: /* JVL */
+               do_rapl = RAPL_PKG | RAPL_PKG_PERF_STATUS | RAPL_PKG_POWER_INFO;
+               BIC_PRESENT(BIC_PKG__);
+               if (rapl_joules)
+                       BIC_PRESENT(BIC_Pkg_J);
+               else
+                       BIC_PRESENT(BIC_PkgWatt);
+               break;
        case INTEL_FAM6_SKYLAKE_L:      /* SKL */
        case INTEL_FAM6_CANNONLAKE_L:   /* CNL */
                do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_GFX | RAPL_PKG_POWER_INFO;
@@ -4069,27 +4358,20 @@ void rapl_probe_amd(unsigned int family, unsigned int model)
 
        if (max_extended_level >= 0x80000007) {
                __cpuid(0x80000007, eax, ebx, ecx, edx);
-               /* RAPL (Fam 17h) */
+               /* RAPL (Fam 17h+) */
                has_rapl = edx & (1 << 14);
        }
 
-       if (!has_rapl)
+       if (!has_rapl || family < 0x17)
                return;
 
-       switch (family) {
-       case 0x17: /* Zen, Zen+ */
-       case 0x18: /* Hygon Dhyana */
-               do_rapl = RAPL_AMD_F17H | RAPL_PER_CORE_ENERGY;
-               if (rapl_joules) {
-                       BIC_PRESENT(BIC_Pkg_J);
-                       BIC_PRESENT(BIC_Cor_J);
-               } else {
-                       BIC_PRESENT(BIC_PkgWatt);
-                       BIC_PRESENT(BIC_CorWatt);
-               }
-               break;
-       default:
-               return;
+       do_rapl = RAPL_AMD_F17H | RAPL_PER_CORE_ENERGY;
+       if (rapl_joules) {
+               BIC_PRESENT(BIC_Pkg_J);
+               BIC_PRESENT(BIC_Cor_J);
+       } else {
+               BIC_PRESENT(BIC_PkgWatt);
+               BIC_PRESENT(BIC_CorWatt);
        }
 
        if (get_msr(base_cpu, MSR_RAPL_PWR_UNIT, &msr))
@@ -4162,7 +4444,7 @@ int print_thermal(struct thread_data *t, struct core_data *c, struct pkg_data *p
                return 0;
 
        if (cpu_migrate(cpu)) {
-               fprintf(outf, "Could not migrate to CPU %d\n", cpu);
+               fprintf(outf, "print_thermal: Could not migrate to CPU %d\n", cpu);
                return -1;
        }
 
@@ -4234,7 +4516,7 @@ int print_rapl(struct thread_data *t, struct core_data *c, struct pkg_data *p)
 
        cpu = t->cpu_id;
        if (cpu_migrate(cpu)) {
-               fprintf(outf, "Could not migrate to CPU %d\n", cpu);
+               fprintf(outf, "print_rapl: Could not migrate to CPU %d\n", cpu);
                return -1;
        }
 
@@ -4361,6 +4643,7 @@ int has_snb_msrs(unsigned int family, unsigned int model)
        case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
        case INTEL_FAM6_ATOM_GOLDMONT_D:        /* DNV */
        case INTEL_FAM6_ATOM_TREMONT:           /* EHL */
+       case INTEL_FAM6_ATOM_TREMONT_D:         /* JVL */
                return 1;
        }
        return 0;
@@ -4507,12 +4790,33 @@ double discover_bclk(unsigned int family, unsigned int model)
  * below this value, including the Digital Thermal Sensor (DTS),
  * Package Thermal Management Sensor (PTM), and thermal event thresholds.
  */
-int set_temperature_target(struct thread_data *t, struct core_data *c, struct pkg_data *p)
+int read_tcc_activation_temp()
 {
        unsigned long long msr;
-       unsigned int target_c_local;
-       int cpu;
+       unsigned int tcc, target_c, offset_c;
 
+       /* Temperature Target MSR is Nehalem and newer only */
+       if (!do_nhm_platform_info)
+               return 0;
+
+       if (get_msr(base_cpu, MSR_IA32_TEMPERATURE_TARGET, &msr))
+               return 0;
+
+       target_c = (msr >> 16) & 0xFF;
+
+       offset_c = (msr >> 24) & 0xF;
+
+       tcc = target_c - offset_c;
+
+       if (!quiet)
+               fprintf(outf, "cpu%d: MSR_IA32_TEMPERATURE_TARGET: 0x%08llx (%d C) (%d default - %d offset)\n",
+                       base_cpu, msr, tcc, target_c, offset_c);
+
+       return tcc;
+}
+
+int set_temperature_target(struct thread_data *t, struct core_data *c, struct pkg_data *p)
+{
        /* tcc_activation_temp is used only for dts or ptm */
        if (!(do_dts || do_ptm))
                return 0;
@@ -4521,43 +4825,18 @@ int set_temperature_target(struct thread_data *t, struct core_data *c, struct pk
        if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE))
                return 0;
 
-       cpu = t->cpu_id;
-       if (cpu_migrate(cpu)) {
-               fprintf(outf, "Could not migrate to CPU %d\n", cpu);
-               return -1;
-       }
-
        if (tcc_activation_temp_override != 0) {
                tcc_activation_temp = tcc_activation_temp_override;
-               fprintf(outf, "cpu%d: Using cmdline TCC Target (%d C)\n",
-                       cpu, tcc_activation_temp);
+               fprintf(outf, "Using cmdline TCC Target (%d C)\n", tcc_activation_temp);
                return 0;
        }
 
-       /* Temperature Target MSR is Nehalem and newer only */
-       if (!do_nhm_platform_info)
-               goto guess;
-
-       if (get_msr(base_cpu, MSR_IA32_TEMPERATURE_TARGET, &msr))
-               goto guess;
-
-       target_c_local = (msr >> 16) & 0xFF;
-
-       if (!quiet)
-               fprintf(outf, "cpu%d: MSR_IA32_TEMPERATURE_TARGET: 0x%08llx (%d C)\n",
-                       cpu, msr, target_c_local);
-
-       if (!target_c_local)
-               goto guess;
-
-       tcc_activation_temp = target_c_local;
-
-       return 0;
+       tcc_activation_temp = read_tcc_activation_temp();
+       if (tcc_activation_temp)
+               return 0;
 
-guess:
        tcc_activation_temp = TJMAX_DEFAULT;
-       fprintf(outf, "cpu%d: Guessing tjMax %d C, Please use -T to specify\n",
-               cpu, tcc_activation_temp);
+       fprintf(outf, "Guessing tjMax %d C, Please use -T to specify\n", tcc_activation_temp);
 
        return 0;
 }
@@ -4685,19 +4964,46 @@ unsigned int intel_model_duplicates(unsigned int model)
        case INTEL_FAM6_ICELAKE_NNPI:
        case INTEL_FAM6_TIGERLAKE_L:
        case INTEL_FAM6_TIGERLAKE:
+       case INTEL_FAM6_ROCKETLAKE:
+       case INTEL_FAM6_LAKEFIELD:
+       case INTEL_FAM6_ALDERLAKE:
                return INTEL_FAM6_CANNONLAKE_L;
 
-       case INTEL_FAM6_ATOM_TREMONT_D:
-               return INTEL_FAM6_ATOM_GOLDMONT_D;
-
        case INTEL_FAM6_ATOM_TREMONT_L:
                return INTEL_FAM6_ATOM_TREMONT;
 
        case INTEL_FAM6_ICELAKE_X:
+       case INTEL_FAM6_SAPPHIRERAPIDS_X:
                return INTEL_FAM6_SKYLAKE_X;
        }
        return model;
 }
+
+void print_dev_latency(void)
+{
+       char *path = "/dev/cpu_dma_latency";
+       int fd;
+       int value;
+       int retval;
+
+       fd = open(path, O_RDONLY);
+       if (fd < 0) {
+               warn("fopen %s\n", path);
+               return;
+       }
+
+       retval = read(fd, (void *)&value, sizeof(int));
+       if (retval != sizeof(int)) {
+               warn("read %s\n", path);
+               close(fd);
+               return;
+       }
+       fprintf(outf, "/dev/cpu_dma_latency: %d usec (%s)\n",
+               value, value == 2000000000 ? "default" : "constrained");
+
+       close(fd);
+}
+
 void process_cpuid()
 {
        unsigned int eax, ebx, ecx, edx;
@@ -4916,6 +5222,14 @@ void process_cpuid()
                BIC_PRESENT(BIC_Mod_c6);
                use_c1_residency_msr = 1;
        }
+       if (is_jvl(family, model)) {
+               BIC_NOT_PRESENT(BIC_CPU_c3);
+               BIC_NOT_PRESENT(BIC_CPU_c7);
+               BIC_NOT_PRESENT(BIC_Pkgpc2);
+               BIC_NOT_PRESENT(BIC_Pkgpc3);
+               BIC_NOT_PRESENT(BIC_Pkgpc6);
+               BIC_NOT_PRESENT(BIC_Pkgpc7);
+       }
        if (is_dnv(family, model)) {
                BIC_PRESENT(BIC_CPU_c1);
                BIC_NOT_PRESENT(BIC_CPU_c3);
@@ -4935,9 +5249,12 @@ void process_cpuid()
                BIC_NOT_PRESENT(BIC_Pkgpc7);
        }
        if (has_c8910_msrs(family, model)) {
-               BIC_PRESENT(BIC_Pkgpc8);
-               BIC_PRESENT(BIC_Pkgpc9);
-               BIC_PRESENT(BIC_Pkgpc10);
+               if (pkg_cstate_limit >= PCL__8)
+                       BIC_PRESENT(BIC_Pkgpc8);
+               if (pkg_cstate_limit >= PCL__9)
+                       BIC_PRESENT(BIC_Pkgpc9);
+               if (pkg_cstate_limit >= PCL_10)
+                       BIC_PRESENT(BIC_Pkgpc10);
        }
        do_irtl_hsw = has_c8910_msrs(family, model);
        if (has_skl_msrs(family, model)) {
@@ -4966,6 +5283,8 @@ void process_cpuid()
        if (!quiet)
                dump_cstate_pstate_config_info(family, model);
 
+       if (!quiet)
+               print_dev_latency();
        if (!quiet)
                dump_sysfs_cstate_config();
        if (!quiet)
@@ -4980,6 +5299,9 @@ void process_cpuid()
        if (!access("/sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz", R_OK))
                BIC_PRESENT(BIC_GFXMHz);
 
+       if (!access("/sys/class/graphics/fb0/device/drm/card0/gt_act_freq_mhz", R_OK))
+               BIC_PRESENT(BIC_GFXACTMHz);
+
        if (!access("/sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us", R_OK))
                BIC_PRESENT(BIC_CPU_LPI);
        else
@@ -5390,7 +5712,7 @@ int get_and_dump_counters(void)
 }
 
 void print_version() {
-       fprintf(outf, "turbostat version 20.03.20"
+       fprintf(outf, "turbostat version 20.09.30"
                " - Len Brown <lenb@kernel.org>\n");
 }
 
@@ -5597,6 +5919,8 @@ void probe_sysfs(void)
                *sp = '%';
                *(sp + 1) = '\0';
 
+               remove_underbar(name_buf);
+
                fclose(input);
 
                sprintf(path, "cpuidle/state%d/time", state);
@@ -5624,6 +5948,8 @@ void probe_sysfs(void)
                *sp = '\0';
                fclose(input);
 
+               remove_underbar(name_buf);
+
                sprintf(path, "cpuidle/state%d/usage", state);
 
                if (is_deferred_skip(name_buf))
@@ -5868,6 +6194,7 @@ int main(int argc, char **argv)
                return 0;
        }
 
+       msr_sum_record();
        /*
         * if any params left, it must be a command to fork
         */
index 3fe1eed..ff6c666 100644 (file)
@@ -622,6 +622,57 @@ void cmdline(int argc, char **argv)
        }
 }
 
+/*
+ * Open a file, and exit on failure
+ */
+FILE *fopen_or_die(const char *path, const char *mode)
+{
+       FILE *filep = fopen(path, "r");
+
+       if (!filep)
+               err(1, "%s: open failed", path);
+       return filep;
+}
+
+void err_on_hypervisor(void)
+{
+       FILE *cpuinfo;
+       char *flags, *hypervisor;
+       char *buffer;
+
+       /* On VMs /proc/cpuinfo contains a "flags" entry for hypervisor */
+       cpuinfo = fopen_or_die("/proc/cpuinfo", "ro");
+
+       buffer = malloc(4096);
+       if (!buffer) {
+               fclose(cpuinfo);
+               err(-ENOMEM, "buffer malloc fail");
+       }
+
+       if (!fread(buffer, 1024, 1, cpuinfo)) {
+               fclose(cpuinfo);
+               free(buffer);
+               err(1, "Reading /proc/cpuinfo failed");
+       }
+
+       flags = strstr(buffer, "flags");
+       rewind(cpuinfo);
+       fseek(cpuinfo, flags - buffer, SEEK_SET);
+       if (!fgets(buffer, 4096, cpuinfo)) {
+               fclose(cpuinfo);
+               free(buffer);
+               err(1, "Reading /proc/cpuinfo failed");
+       }
+       fclose(cpuinfo);
+
+       hypervisor = strstr(buffer, "hypervisor");
+
+       free(buffer);
+
+       if (hypervisor)
+               err(-1,
+                   "not supported on this virtual machine");
+}
 
 int get_msr(int cpu, int offset, unsigned long long *msr)
 {
@@ -635,8 +686,10 @@ int get_msr(int cpu, int offset, unsigned long long *msr)
                err(-1, "%s open failed, try chown or chmod +r /dev/cpu/*/msr, or run as root", pathname);
 
        retval = pread(fd, msr, sizeof(*msr), offset);
-       if (retval != sizeof(*msr))
+       if (retval != sizeof(*msr)) {
+               err_on_hypervisor();
                err(-1, "%s offset 0x%llx read failed", pathname, (unsigned long long)offset);
+       }
 
        if (debug > 1)
                fprintf(stderr, "get_msr(cpu%d, 0x%X, 0x%llX)\n", cpu, offset, *msr);
@@ -1086,18 +1139,6 @@ int update_cpu_msrs(int cpu)
        return 0;
 }
 
-/*
- * Open a file, and exit on failure
- */
-FILE *fopen_or_die(const char *path, const char *mode)
-{
-       FILE *filep = fopen(path, "r");
-
-       if (!filep)
-               err(1, "%s: open failed", path);
-       return filep;
-}
-
 unsigned int get_pkg_num(int cpu)
 {
        FILE *fp;
diff --git a/tools/testing/kunit/.gitattributes b/tools/testing/kunit/.gitattributes
deleted file mode 100644 (file)
index 5b7da1f..0000000
+++ /dev/null
@@ -1 +0,0 @@
-test_data/* binary
index ebf5f57..d4f7846 100755 (executable)
@@ -11,7 +11,6 @@ import argparse
 import sys
 import os
 import time
-import shutil
 
 from collections import namedtuple
 from enum import Enum, auto
@@ -44,11 +43,6 @@ class KunitStatus(Enum):
        BUILD_FAILURE = auto()
        TEST_FAILURE = auto()
 
-def create_default_kunitconfig():
-       if not os.path.exists(kunit_kernel.kunitconfig_path):
-               shutil.copyfile('arch/um/configs/kunit_defconfig',
-                               kunit_kernel.kunitconfig_path)
-
 def get_kernel_root_path():
        parts = sys.argv[0] if not __file__ else __file__
        parts = os.path.realpath(parts).split('tools/testing/kunit')
@@ -61,7 +55,6 @@ def config_tests(linux: kunit_kernel.LinuxSourceTree,
        kunit_parser.print_with_timestamp('Configuring KUnit Kernel ...')
 
        config_start = time.time()
-       create_default_kunitconfig()
        success = linux.build_reconfig(request.build_dir, request.make_options)
        config_end = time.time()
        if not success:
@@ -262,12 +255,12 @@ def main(argv, linux=None):
                if not os.path.exists(cli_args.build_dir):
                        os.mkdir(cli_args.build_dir)
 
-               if not os.path.exists(kunit_kernel.kunitconfig_path):
-                       create_default_kunitconfig()
-
                if not linux:
                        linux = kunit_kernel.LinuxSourceTree()
 
+               linux.create_kunitconfig(cli_args.build_dir)
+               linux.read_kunitconfig(cli_args.build_dir)
+
                request = KunitRequest(cli_args.raw_output,
                                       cli_args.timeout,
                                       cli_args.jobs,
@@ -283,12 +276,12 @@ def main(argv, linux=None):
                                not os.path.exists(cli_args.build_dir)):
                        os.mkdir(cli_args.build_dir)
 
-               if not os.path.exists(kunit_kernel.kunitconfig_path):
-                       create_default_kunitconfig()
-
                if not linux:
                        linux = kunit_kernel.LinuxSourceTree()
 
+               linux.create_kunitconfig(cli_args.build_dir)
+               linux.read_kunitconfig(cli_args.build_dir)
+
                request = KunitConfigRequest(cli_args.build_dir,
                                             cli_args.make_options)
                result = config_tests(linux, request)
@@ -301,6 +294,9 @@ def main(argv, linux=None):
                if not linux:
                        linux = kunit_kernel.LinuxSourceTree()
 
+               linux.create_kunitconfig(cli_args.build_dir)
+               linux.read_kunitconfig(cli_args.build_dir)
+
                request = KunitBuildRequest(cli_args.jobs,
                                            cli_args.build_dir,
                                            cli_args.alltests,
@@ -315,6 +311,9 @@ def main(argv, linux=None):
                if not linux:
                        linux = kunit_kernel.LinuxSourceTree()
 
+               linux.create_kunitconfig(cli_args.build_dir)
+               linux.read_kunitconfig(cli_args.build_dir)
+
                exec_request = KunitExecRequest(cli_args.timeout,
                                                cli_args.build_dir,
                                                cli_args.alltests)
@@ -337,7 +336,7 @@ def main(argv, linux=None):
                                kunit_output = f.read().splitlines()
                request = KunitParseRequest(cli_args.raw_output,
                                            kunit_output,
-                                           cli_args.build_dir,
+                                           None,
                                            cli_args.json)
                result = parse_tests(request)
                if result.status != KunitStatus.SUCCESS:
index b557b1e..2e3cc0f 100644 (file)
@@ -6,10 +6,10 @@
 # Author: Felix Guo <felixguoxiuping@gmail.com>
 # Author: Brendan Higgins <brendanhiggins@google.com>
 
-
 import logging
 import subprocess
 import os
+import shutil
 import signal
 
 from contextlib import ExitStack
@@ -18,8 +18,10 @@ import kunit_config
 import kunit_parser
 
 KCONFIG_PATH = '.config'
-kunitconfig_path = '.kunitconfig'
+KUNITCONFIG_PATH = '.kunitconfig'
+DEFAULT_KUNITCONFIG_PATH = 'arch/um/configs/kunit_defconfig'
 BROKEN_ALLCONFIG_PATH = 'tools/testing/kunit/configs/broken_on_uml.config'
+OUTFILE_PATH = 'test.log'
 
 class ConfigError(Exception):
        """Represents an error trying to configure the Linux kernel."""
@@ -82,36 +84,51 @@ class LinuxSourceTreeOperations(object):
                if build_dir:
                        command += ['O=' + build_dir]
                try:
-                       subprocess.check_output(command, stderr=subprocess.STDOUT)
+                       proc = subprocess.Popen(command,
+                                               stderr=subprocess.PIPE,
+                                               stdout=subprocess.DEVNULL)
                except OSError as e:
-                       raise BuildError('Could not call execute make: ' + str(e))
-               except subprocess.CalledProcessError as e:
-                       raise BuildError(e.output.decode())
-
-       def linux_bin(self, params, timeout, build_dir, outfile):
+                       raise BuildError('Could not call make command: ' + str(e))
+               _, stderr = proc.communicate()
+               if proc.returncode != 0:
+                       raise BuildError(stderr.decode())
+               if stderr:  # likely only due to build warnings
+                       print(stderr.decode())
+
+       def linux_bin(self, params, timeout, build_dir):
                """Runs the Linux UML binary. Must be named 'linux'."""
                linux_bin = './linux'
                if build_dir:
                        linux_bin = os.path.join(build_dir, 'linux')
+               outfile = get_outfile_path(build_dir)
                with open(outfile, 'w') as output:
                        process = subprocess.Popen([linux_bin] + params,
                                                   stdout=output,
                                                   stderr=subprocess.STDOUT)
                        process.wait(timeout)
 
-
 def get_kconfig_path(build_dir):
        kconfig_path = KCONFIG_PATH
        if build_dir:
                kconfig_path = os.path.join(build_dir, KCONFIG_PATH)
        return kconfig_path
 
+def get_kunitconfig_path(build_dir):
+       kunitconfig_path = KUNITCONFIG_PATH
+       if build_dir:
+               kunitconfig_path = os.path.join(build_dir, KUNITCONFIG_PATH)
+       return kunitconfig_path
+
+def get_outfile_path(build_dir):
+       outfile_path = OUTFILE_PATH
+       if build_dir:
+               outfile_path = os.path.join(build_dir, OUTFILE_PATH)
+       return outfile_path
+
 class LinuxSourceTree(object):
        """Represents a Linux kernel source tree with KUnit tests."""
 
        def __init__(self):
-               self._kconfig = kunit_config.Kconfig()
-               self._kconfig.read_from_file(kunitconfig_path)
                self._ops = LinuxSourceTreeOperations()
                signal.signal(signal.SIGINT, self.signal_handler)
 
@@ -123,6 +140,16 @@ class LinuxSourceTree(object):
                        return False
                return True
 
+       def create_kunitconfig(self, build_dir, defconfig=DEFAULT_KUNITCONFIG_PATH):
+               kunitconfig_path = get_kunitconfig_path(build_dir)
+               if not os.path.exists(kunitconfig_path):
+                       shutil.copyfile(defconfig, kunitconfig_path)
+
+       def read_kunitconfig(self, build_dir):
+               kunitconfig_path = get_kunitconfig_path(build_dir)
+               self._kconfig = kunit_config.Kconfig()
+               self._kconfig.read_from_file(kunitconfig_path)
+
        def validate_config(self, build_dir):
                kconfig_path = get_kconfig_path(build_dir)
                validated_kconfig = kunit_config.Kconfig()
@@ -178,8 +205,8 @@ class LinuxSourceTree(object):
 
        def run_kernel(self, args=[], build_dir='', timeout=None):
                args.extend(['mem=1G'])
-               outfile = 'test.log'
-               self._ops.linux_bin(args, timeout, build_dir, outfile)
+               self._ops.linux_bin(args, timeout, build_dir)
+               outfile = get_outfile_path(build_dir)
                subprocess.call(['stty', 'sane'])
                with open(outfile, 'r') as file:
                        for line in file:
index 8019e3d..bbfe1b4 100644 (file)
@@ -12,7 +12,7 @@ from collections import namedtuple
 from datetime import datetime
 from enum import Enum, auto
 from functools import reduce
-from typing import List
+from typing import List, Optional, Tuple
 
 TestResult = namedtuple('TestResult', ['status','suites','log'])
 
@@ -54,6 +54,7 @@ kunit_end_re = re.compile('(List of all partitions:|'
 def isolate_kunit_output(kernel_output):
        started = False
        for line in kernel_output:
+               line = line.rstrip()  # line always has a trailing \n
                if kunit_start_re.search(line):
                        prefix_len = len(line.split('TAP version')[0])
                        started = True
@@ -65,8 +66,7 @@ def isolate_kunit_output(kernel_output):
 
 def raw_output(kernel_output):
        for line in kernel_output:
-               print(line)
-               yield line
+               print(line.rstrip())
 
 DIVIDER = '=' * 60
 
@@ -152,7 +152,7 @@ def parse_diagnostic(lines: List[str], test_case: TestCase) -> bool:
        else:
                return False
 
-def parse_test_case(lines: List[str]) -> TestCase:
+def parse_test_case(lines: List[str]) -> Optional[TestCase]:
        test_case = TestCase()
        save_non_diagnositic(lines, test_case)
        while parse_diagnostic(lines, test_case):
@@ -164,7 +164,7 @@ def parse_test_case(lines: List[str]) -> TestCase:
 
 SUBTEST_HEADER = re.compile(r'^[\s]+# Subtest: (.*)$')
 
-def parse_subtest_header(lines: List[str]) -> str:
+def parse_subtest_header(lines: List[str]) -> Optional[str]:
        consume_non_diagnositic(lines)
        if not lines:
                return None
@@ -177,7 +177,7 @@ def parse_subtest_header(lines: List[str]) -> str:
 
 SUBTEST_PLAN = re.compile(r'[\s]+[0-9]+\.\.([0-9]+)')
 
-def parse_subtest_plan(lines: List[str]) -> int:
+def parse_subtest_plan(lines: List[str]) -> Optional[int]:
        consume_non_diagnositic(lines)
        match = SUBTEST_PLAN.match(lines[0])
        if match:
@@ -231,7 +231,7 @@ def bubble_up_test_case_errors(test_suite: TestSuite) -> TestStatus:
        max_test_case_status = bubble_up_errors(lambda x: x.status, test_suite.cases)
        return max_status(max_test_case_status, test_suite.status)
 
-def parse_test_suite(lines: List[str], expected_suite_index: int) -> TestSuite:
+def parse_test_suite(lines: List[str], expected_suite_index: int) -> Optional[TestSuite]:
        if not lines:
                return None
        consume_non_diagnositic(lines)
@@ -242,7 +242,7 @@ def parse_test_suite(lines: List[str], expected_suite_index: int) -> TestSuite:
                return None
        test_suite.name = name
        expected_test_case_num = parse_subtest_plan(lines)
-       if not expected_test_case_num:
+       if expected_test_case_num is None:
                return None
        while expected_test_case_num > 0:
                test_case = parse_test_case(lines)
@@ -272,7 +272,7 @@ def parse_tap_header(lines: List[str]) -> bool:
 
 TEST_PLAN = re.compile(r'[0-9]+\.\.([0-9]+)')
 
-def parse_test_plan(lines: List[str]) -> int:
+def parse_test_plan(lines: List[str]) -> Optional[int]:
        consume_non_diagnositic(lines)
        match = TEST_PLAN.match(lines[0])
        if match:
@@ -311,7 +311,7 @@ def parse_test_result(lines: List[str]) -> TestResult:
        else:
                return TestResult(TestStatus.NO_TESTS, [], lines)
 
-def print_and_count_results(test_result: TestResult) -> None:
+def print_and_count_results(test_result: TestResult) -> Tuple[int, int, int]:
        total_tests = 0
        failed_tests = 0
        crashed_tests = 0
index 99c3c56..497ab51 100755 (executable)
@@ -102,7 +102,7 @@ class KUnitParserTest(unittest.TestCase):
                        'test_data/test_output_isolated_correctly.log')
                file = open(log_path)
                result = kunit_parser.isolate_kunit_output(file.readlines())
-               self.assertContains('TAP version 14\n', result)
+               self.assertContains('TAP version 14', result)
                self.assertContains('   # Subtest: example', result)
                self.assertContains('   1..2', result)
                self.assertContains('   ok 1 - example_simple_test', result)
@@ -115,7 +115,7 @@ class KUnitParserTest(unittest.TestCase):
                        'test_data/test_pound_sign.log')
                with open(log_path) as file:
                        result = kunit_parser.isolate_kunit_output(file.readlines())
-               self.assertContains('TAP version 14\n', result)
+               self.assertContains('TAP version 14', result)
                self.assertContains('   # Subtest: kunit-resource-test', result)
                self.assertContains('   1..5', result)
                self.assertContains('   ok 1 - kunit_resource_test_init_resources', result)
@@ -179,7 +179,7 @@ class KUnitParserTest(unittest.TestCase):
                print_mock = mock.patch('builtins.print').start()
                result = kunit_parser.parse_run_tests(
                        kunit_parser.isolate_kunit_output(file.readlines()))
-               print_mock.assert_any_call(StrContains("no kunit output detected"))
+               print_mock.assert_any_call(StrContains('no tests run!'))
                print_mock.stop()
                file.close()
 
@@ -198,39 +198,57 @@ class KUnitParserTest(unittest.TestCase):
                        'test_data/test_config_printk_time.log')
                with open(prefix_log) as file:
                        result = kunit_parser.parse_run_tests(file.readlines())
-               self.assertEqual('kunit-resource-test', result.suites[0].name)
+                       self.assertEqual(
+                               kunit_parser.TestStatus.SUCCESS,
+                               result.status)
+                       self.assertEqual('kunit-resource-test', result.suites[0].name)
 
        def test_ignores_multiple_prefixes(self):
                prefix_log = get_absolute_path(
                        'test_data/test_multiple_prefixes.log')
                with open(prefix_log) as file:
                        result = kunit_parser.parse_run_tests(file.readlines())
-               self.assertEqual('kunit-resource-test', result.suites[0].name)
+                       self.assertEqual(
+                               kunit_parser.TestStatus.SUCCESS,
+                               result.status)
+                       self.assertEqual('kunit-resource-test', result.suites[0].name)
 
        def test_prefix_mixed_kernel_output(self):
                mixed_prefix_log = get_absolute_path(
                        'test_data/test_interrupted_tap_output.log')
                with open(mixed_prefix_log) as file:
                        result = kunit_parser.parse_run_tests(file.readlines())
-               self.assertEqual('kunit-resource-test', result.suites[0].name)
+                       self.assertEqual(
+                               kunit_parser.TestStatus.SUCCESS,
+                               result.status)
+                       self.assertEqual('kunit-resource-test', result.suites[0].name)
 
        def test_prefix_poundsign(self):
                pound_log = get_absolute_path('test_data/test_pound_sign.log')
                with open(pound_log) as file:
                        result = kunit_parser.parse_run_tests(file.readlines())
-               self.assertEqual('kunit-resource-test', result.suites[0].name)
+                       self.assertEqual(
+                               kunit_parser.TestStatus.SUCCESS,
+                               result.status)
+                       self.assertEqual('kunit-resource-test', result.suites[0].name)
 
        def test_kernel_panic_end(self):
                panic_log = get_absolute_path('test_data/test_kernel_panic_interrupt.log')
                with open(panic_log) as file:
                        result = kunit_parser.parse_run_tests(file.readlines())
-               self.assertEqual('kunit-resource-test', result.suites[0].name)
+                       self.assertEqual(
+                               kunit_parser.TestStatus.TEST_CRASHED,
+                               result.status)
+                       self.assertEqual('kunit-resource-test', result.suites[0].name)
 
        def test_pound_no_prefix(self):
                pound_log = get_absolute_path('test_data/test_pound_no_prefix.log')
                with open(pound_log) as file:
                        result = kunit_parser.parse_run_tests(file.readlines())
-               self.assertEqual('kunit-resource-test', result.suites[0].name)
+                       self.assertEqual(
+                               kunit_parser.TestStatus.SUCCESS,
+                               result.status)
+                       self.assertEqual('kunit-resource-test', result.suites[0].name)
 
 class KUnitJsonTest(unittest.TestCase):
 
index c02ca77..6bdb57f 100644 (file)
@@ -1,6 +1,7 @@
 [    0.060000] printk: console [mc-1] enabled
 [    0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
 [    0.060000] TAP version 14
+[    0.060000] 1..3
 [    0.060000]         # Subtest: kunit-resource-test
 [    0.060000]         1..5
 [    0.060000]         ok 1 - kunit_resource_test_init_resources
@@ -28,4 +29,4 @@
 [    0.060000] Stack:
 [    0.060000]  602086f8 601bc260 705c0000 705c0000
 [    0.060000]  602086f8 6005fcec 705c0000 6002c6ab
-[    0.060000]  6005fcec 601bc260 705c0000 3000000010
\ No newline at end of file
+[    0.060000]  6005fcec 601bc260 705c0000 3000000010
index 5c73fb3..1fb6777 100644 (file)
@@ -1,6 +1,7 @@
 [    0.060000] printk: console [mc-1] enabled
 [    0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
 [    0.060000] TAP version 14
+[    0.060000] 1..3
 [    0.060000]         # Subtest: kunit-resource-test
 [    0.060000]         1..5
 [    0.060000]         ok 1 - kunit_resource_test_init_resources
@@ -34,4 +35,4 @@
 [    0.060000] Stack:
 [    0.060000]  602086f8 601bc260 705c0000 705c0000
 [    0.060000]  602086f8 6005fcec 705c0000 6002c6ab
-[    0.060000]  6005fcec 601bc260 705c0000 3000000010
\ No newline at end of file
+[    0.060000]  6005fcec 601bc260 705c0000 3000000010
index c045eee..a014ffe 100644 (file)
@@ -1,6 +1,7 @@
 [    0.060000] printk: console [mc-1] enabled
 [    0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
 [    0.060000] TAP version 14
+[    0.060000] 1..3
 [    0.060000]         # Subtest: kunit-resource-test
 [    0.060000]         1..5
 [    0.060000]         ok 1 - kunit_resource_test_init_resources
@@ -22,4 +23,4 @@
 [    0.060000] Stack:
 [    0.060000]  602086f8 601bc260 705c0000 705c0000
 [    0.060000]  602086f8 6005fcec 705c0000 6002c6ab
-[    0.060000]  6005fcec 601bc260 705c0000 3000000010
\ No newline at end of file
+[    0.060000]  6005fcec 601bc260 705c0000 3000000010
index bc48407..0ad7848 100644 (file)
@@ -1,6 +1,7 @@
 [    0.060000][    T1] printk: console [mc-1] enabled
 [    0.060000][    T1] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
 [    0.060000][    T1] TAP version 14
+[    0.060000][    T1] 1..3
 [    0.060000][    T1]         # Subtest: kunit-resource-test
 [    0.060000][    T1]         1..5
 [    0.060000][    T1]         ok 1 - kunit_resource_test_init_resources
@@ -28,4 +29,4 @@
 [    0.060000][    T1] Stack:
 [    0.060000][    T1]  602086f8 601bc260 705c0000 705c0000
 [    0.060000][    T1]  602086f8 6005fcec 705c0000 6002c6ab
-[    0.060000][    T1]  6005fcec 601bc260 705c0000 3000000010
\ No newline at end of file
+[    0.060000][    T1]  6005fcec 601bc260 705c0000 3000000010
index 2ceb360..dc4cf09 100644 (file)
@@ -1,6 +1,7 @@
  printk: console [mc-1] enabled
  random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
  TAP version 14
+ 1..3
        # Subtest: kunit-resource-test
        1..5
        ok 1 - kunit_resource_test_init_resources
@@ -30,4 +31,4 @@
  Stack:
   602086f8 601bc260 705c0000 705c0000
   602086f8 6005fcec 705c0000 6002c6ab
-  6005fcec 601bc260 705c0000 3000000010
\ No newline at end of file
+  6005fcec 601bc260 705c0000 3000000010
index 28ffa5b..3f358e3 100644 (file)
@@ -1,6 +1,7 @@
 [    0.060000] printk: console [mc-1] enabled
 [    0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
 [    0.060000] TAP version 14
+[    0.060000] 1..3
 [    0.060000]         # Subtest: kunit-resource-test
 [    0.060000]         1..5
 [    0.060000]         ok 1 - kunit_resource_test_init_resources
index 6ae907f..f9a1200 100644 (file)
@@ -33,6 +33,7 @@ typedef unsigned long dma_addr_t;
 #define __ALIGN_KERNEL(x, a)           __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
 #define __ALIGN_KERNEL_MASK(x, mask)   (((x) + (mask)) & ~(mask))
 #define ALIGN(x, a)                    __ALIGN_KERNEL((x), (a))
+#define ALIGN_DOWN(x, a)               __ALIGN_KERNEL((x) - ((a) - 1), (a))
 
 #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
 
index b2c7e9f..f561aed 100644 (file)
@@ -52,9 +52,9 @@ int main(void)
 {
        const unsigned int sgmax = SCATTERLIST_MAX_SEGMENT;
        struct test *test, tests[] = {
-               { -EINVAL, 1, pfn(0), PAGE_SIZE, PAGE_SIZE + 1, 1 },
                { -EINVAL, 1, pfn(0), PAGE_SIZE, 0, 1 },
-               { -EINVAL, 1, pfn(0), PAGE_SIZE, sgmax + 1, 1 },
+               { 0, 1, pfn(0), PAGE_SIZE, PAGE_SIZE + 1, 1 },
+               { 0, 1, pfn(0), PAGE_SIZE, sgmax + 1, 1 },
                { 0, 1, pfn(0), PAGE_SIZE, sgmax, 1 },
                { 0, 1, pfn(0), 1, sgmax, 1 },
                { 0, 2, pfn(0, 1), 2 * PAGE_SIZE, sgmax, 1 },
diff --git a/tools/testing/selftests/bpf/prog_tests/map_init.c b/tools/testing/selftests/bpf/prog_tests/map_init.c
new file mode 100644 (file)
index 0000000..14a3110
--- /dev/null
@@ -0,0 +1,214 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (c) 2020 Tessares SA <http://www.tessares.net> */
+
+#include <test_progs.h>
+#include "test_map_init.skel.h"
+
+#define TEST_VALUE 0x1234
+#define FILL_VALUE 0xdeadbeef
+
+static int nr_cpus;
+static int duration;
+
+typedef unsigned long long map_key_t;
+typedef unsigned long long map_value_t;
+typedef struct {
+       map_value_t v; /* padding */
+} __bpf_percpu_val_align pcpu_map_value_t;
+
+
+static int map_populate(int map_fd, int num)
+{
+       pcpu_map_value_t value[nr_cpus];
+       int i, err;
+       map_key_t key;
+
+       for (i = 0; i < nr_cpus; i++)
+               bpf_percpu(value, i) = FILL_VALUE;
+
+       for (key = 1; key <= num; key++) {
+               err = bpf_map_update_elem(map_fd, &key, value, BPF_NOEXIST);
+               if (!ASSERT_OK(err, "bpf_map_update_elem"))
+                       return -1;
+       }
+
+       return 0;
+}
+
+static struct test_map_init *setup(enum bpf_map_type map_type, int map_sz,
+                           int *map_fd, int populate)
+{
+       struct test_map_init *skel;
+       int err;
+
+       skel = test_map_init__open();
+       if (!ASSERT_OK_PTR(skel, "skel_open"))
+               return NULL;
+
+       err = bpf_map__set_type(skel->maps.hashmap1, map_type);
+       if (!ASSERT_OK(err, "bpf_map__set_type"))
+               goto error;
+
+       err = bpf_map__set_max_entries(skel->maps.hashmap1, map_sz);
+       if (!ASSERT_OK(err, "bpf_map__set_max_entries"))
+               goto error;
+
+       err = test_map_init__load(skel);
+       if (!ASSERT_OK(err, "skel_load"))
+               goto error;
+
+       *map_fd = bpf_map__fd(skel->maps.hashmap1);
+       if (CHECK(*map_fd < 0, "bpf_map__fd", "failed\n"))
+               goto error;
+
+       err = map_populate(*map_fd, populate);
+       if (!ASSERT_OK(err, "map_populate"))
+               goto error_map;
+
+       return skel;
+
+error_map:
+       close(*map_fd);
+error:
+       test_map_init__destroy(skel);
+       return NULL;
+}
+
+/* executes bpf program that updates map with key, value */
+static int prog_run_insert_elem(struct test_map_init *skel, map_key_t key,
+                               map_value_t value)
+{
+       struct test_map_init__bss *bss;
+
+       bss = skel->bss;
+
+       bss->inKey = key;
+       bss->inValue = value;
+       bss->inPid = getpid();
+
+       if (!ASSERT_OK(test_map_init__attach(skel), "skel_attach"))
+               return -1;
+
+       /* Let tracepoint trigger */
+       syscall(__NR_getpgid);
+
+       test_map_init__detach(skel);
+
+       return 0;
+}
+
+static int check_values_one_cpu(pcpu_map_value_t *value, map_value_t expected)
+{
+       int i, nzCnt = 0;
+       map_value_t val;
+
+       for (i = 0; i < nr_cpus; i++) {
+               val = bpf_percpu(value, i);
+               if (val) {
+                       if (CHECK(val != expected, "map value",
+                                 "unexpected for cpu %d: 0x%llx\n", i, val))
+                               return -1;
+                       nzCnt++;
+               }
+       }
+
+       if (CHECK(nzCnt != 1, "map value", "set for %d CPUs instead of 1!\n",
+                 nzCnt))
+               return -1;
+
+       return 0;
+}
+
+/* Add key=1 elem with values set for all CPUs
+ * Delete elem key=1
+ * Run bpf prog that inserts new key=1 elem with value=0x1234
+ *   (bpf prog can only set value for current CPU)
+ * Lookup Key=1 and check value is as expected for all CPUs:
+ *   value set by bpf prog for one CPU, 0 for all others
+ */
+static void test_pcpu_map_init(void)
+{
+       pcpu_map_value_t value[nr_cpus];
+       struct test_map_init *skel;
+       int map_fd, err;
+       map_key_t key;
+
+       /* max 1 elem in map so insertion is forced to reuse freed entry */
+       skel = setup(BPF_MAP_TYPE_PERCPU_HASH, 1, &map_fd, 1);
+       if (!ASSERT_OK_PTR(skel, "prog_setup"))
+               return;
+
+       /* delete element so the entry can be re-used*/
+       key = 1;
+       err = bpf_map_delete_elem(map_fd, &key);
+       if (!ASSERT_OK(err, "bpf_map_delete_elem"))
+               goto cleanup;
+
+       /* run bpf prog that inserts new elem, re-using the slot just freed */
+       err = prog_run_insert_elem(skel, key, TEST_VALUE);
+       if (!ASSERT_OK(err, "prog_run_insert_elem"))
+               goto cleanup;
+
+       /* check that key=1 was re-created by bpf prog */
+       err = bpf_map_lookup_elem(map_fd, &key, value);
+       if (!ASSERT_OK(err, "bpf_map_lookup_elem"))
+               goto cleanup;
+
+       /* and has expected values */
+       check_values_one_cpu(value, TEST_VALUE);
+
+cleanup:
+       test_map_init__destroy(skel);
+}
+
+/* Add key=1 and key=2 elems with values set for all CPUs
+ * Run bpf prog that inserts new key=3 elem
+ *   (only for current cpu; other cpus should have initial value = 0)
+ * Lookup Key=1 and check value is as expected for all CPUs
+ */
+static void test_pcpu_lru_map_init(void)
+{
+       pcpu_map_value_t value[nr_cpus];
+       struct test_map_init *skel;
+       int map_fd, err;
+       map_key_t key;
+
+       /* Set up LRU map with 2 elements, values filled for all CPUs.
+        * With these 2 elements, the LRU map is full
+        */
+       skel = setup(BPF_MAP_TYPE_LRU_PERCPU_HASH, 2, &map_fd, 2);
+       if (!ASSERT_OK_PTR(skel, "prog_setup"))
+               return;
+
+       /* run bpf prog that inserts new key=3 element, re-using LRU slot */
+       key = 3;
+       err = prog_run_insert_elem(skel, key, TEST_VALUE);
+       if (!ASSERT_OK(err, "prog_run_insert_elem"))
+               goto cleanup;
+
+       /* check that key=3 replaced one of earlier elements */
+       err = bpf_map_lookup_elem(map_fd, &key, value);
+       if (!ASSERT_OK(err, "bpf_map_lookup_elem"))
+               goto cleanup;
+
+       /* and has expected values */
+       check_values_one_cpu(value, TEST_VALUE);
+
+cleanup:
+       test_map_init__destroy(skel);
+}
+
+void test_map_init(void)
+{
+       nr_cpus = bpf_num_possible_cpus();
+       if (nr_cpus <= 1) {
+               printf("%s:SKIP: >1 cpu needed for this test\n", __func__);
+               test__skip();
+               return;
+       }
+
+       if (test__start_subtest("pcpu_map_init"))
+               test_pcpu_map_init();
+       if (test__start_subtest("pcpu_lru_map_init"))
+               test_pcpu_lru_map_init();
+}
diff --git a/tools/testing/selftests/bpf/prog_tests/probe_read_user_str.c b/tools/testing/selftests/bpf/prog_tests/probe_read_user_str.c
new file mode 100644 (file)
index 0000000..e419298
--- /dev/null
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+#include "test_probe_read_user_str.skel.h"
+
+static const char str1[] = "mestring";
+static const char str2[] = "mestringalittlebigger";
+static const char str3[] = "mestringblubblubblubblubblub";
+
+static int test_one_str(struct test_probe_read_user_str *skel, const char *str,
+                       size_t len)
+{
+       int err, duration = 0;
+       char buf[256];
+
+       /* Ensure bytes after string are ones */
+       memset(buf, 1, sizeof(buf));
+       memcpy(buf, str, len);
+
+       /* Give prog our userspace pointer */
+       skel->bss->user_ptr = buf;
+
+       /* Trigger tracepoint */
+       usleep(1);
+
+       /* Did helper fail? */
+       if (CHECK(skel->bss->ret < 0, "prog_ret", "prog returned: %ld\n",
+                 skel->bss->ret))
+               return 1;
+
+       /* Check that string was copied correctly */
+       err = memcmp(skel->bss->buf, str, len);
+       if (CHECK(err, "memcmp", "prog copied wrong string"))
+               return 1;
+
+       /* Now check that no extra trailing bytes were copied */
+       memset(buf, 0, sizeof(buf));
+       err = memcmp(skel->bss->buf + len, buf, sizeof(buf) - len);
+       if (CHECK(err, "memcmp", "trailing bytes were not stripped"))
+               return 1;
+
+       return 0;
+}
+
+void test_probe_read_user_str(void)
+{
+       struct test_probe_read_user_str *skel;
+       int err, duration = 0;
+
+       skel = test_probe_read_user_str__open_and_load();
+       if (CHECK(!skel, "test_probe_read_user_str__open_and_load",
+                 "skeleton open and load failed\n"))
+               return;
+
+       /* Give pid to bpf prog so it doesn't read from anyone else */
+       skel->bss->pid = getpid();
+
+       err = test_probe_read_user_str__attach(skel);
+       if (CHECK(err, "test_probe_read_user_str__attach",
+                 "skeleton attach failed: %d\n", err))
+               goto out;
+
+       if (test_one_str(skel, str1, sizeof(str1)))
+               goto out;
+       if (test_one_str(skel, str2, sizeof(str2)))
+               goto out;
+       if (test_one_str(skel, str3, sizeof(str3)))
+               goto out;
+
+out:
+       test_probe_read_user_str__destroy(skel);
+}
index 29188d6..51fac97 100644 (file)
@@ -138,7 +138,8 @@ static int run_getsockopt_test(struct bpf_object *obj, int cg_parent,
         */
 
        buf = 0x40;
-       if (setsockopt(sock_fd, SOL_IP, IP_TOS, &buf, 1) < 0) {
+       err = setsockopt(sock_fd, SOL_IP, IP_TOS, &buf, 1);
+       if (err < 0) {
                log_err("Failed to call setsockopt(IP_TOS)");
                goto detach;
        }
index a00abf5..3f3d2ac 100644 (file)
@@ -3,12 +3,14 @@
 #include <test_progs.h>
 #include <time.h>
 #include "test_subprogs.skel.h"
+#include "test_subprogs_unused.skel.h"
 
 static int duration;
 
 void test_subprogs(void)
 {
        struct test_subprogs *skel;
+       struct test_subprogs_unused *skel2;
        int err;
 
        skel = test_subprogs__open_and_load();
@@ -26,6 +28,10 @@ void test_subprogs(void)
        CHECK(skel->bss->res3 != 19, "res3", "got %d, exp %d\n", skel->bss->res3, 19);
        CHECK(skel->bss->res4 != 36, "res4", "got %d, exp %d\n", skel->bss->res4, 36);
 
+       skel2 = test_subprogs_unused__open_and_load();
+       ASSERT_OK_PTR(skel2, "unused_progs_skel");
+       test_subprogs_unused__destroy(skel2);
+
 cleanup:
        test_subprogs__destroy(skel);
 }
index 193002b..32e4348 100644 (file)
@@ -60,6 +60,7 @@ void test_test_global_funcs(void)
                { "test_global_func5.o" , "expected pointer to ctx, but got PTR" },
                { "test_global_func6.o" , "modified ctx ptr R2" },
                { "test_global_func7.o" , "foo() doesn't return scalar" },
+               { "test_global_func8.o" },
        };
        libbpf_print_fn_t old_print_fn = NULL;
        int err, i, duration = 0;
index 0057831..30982a7 100644 (file)
@@ -243,7 +243,10 @@ static ino_t get_inode_from_kernfs(struct kernfs_node* node)
        }
 }
 
-int pids_cgrp_id = 1;
+extern bool CONFIG_CGROUP_PIDS __kconfig __weak;
+enum cgroup_subsys_id___local {
+       pids_cgrp_id___local = 123, /* value doesn't matter */
+};
 
 static INLINE void* populate_cgroup_info(struct cgroup_data_t* cgroup_data,
                                         struct task_struct* task,
@@ -253,7 +256,9 @@ static INLINE void* populate_cgroup_info(struct cgroup_data_t* cgroup_data,
                BPF_CORE_READ(task, nsproxy, cgroup_ns, root_cset, dfl_cgrp, kn);
        struct kernfs_node* proc_kernfs = BPF_CORE_READ(task, cgroups, dfl_cgrp, kn);
 
-       if (ENABLE_CGROUP_V1_RESOLVER) {
+       if (ENABLE_CGROUP_V1_RESOLVER && CONFIG_CGROUP_PIDS) {
+               int cgrp_id = bpf_core_enum_value(enum cgroup_subsys_id___local,
+                                                 pids_cgrp_id___local);
 #ifdef UNROLL
 #pragma unroll
 #endif
@@ -262,7 +267,7 @@ static INLINE void* populate_cgroup_info(struct cgroup_data_t* cgroup_data,
                                BPF_CORE_READ(task, cgroups, subsys[i]);
                        if (subsys != NULL) {
                                int subsys_id = BPF_CORE_READ(subsys, ss, id);
-                               if (subsys_id == pids_cgrp_id) {
+                               if (subsys_id == cgrp_id) {
                                        proc_kernfs = BPF_CORE_READ(subsys, cgroup, kn);
                                        root_kernfs = BPF_CORE_READ(subsys, ss, root, kf_root, kn);
                                        break;
diff --git a/tools/testing/selftests/bpf/progs/test_global_func8.c b/tools/testing/selftests/bpf/progs/test_global_func8.c
new file mode 100644 (file)
index 0000000..d55a654
--- /dev/null
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (c) 2020 Facebook */
+#include <stddef.h>
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+
+__noinline int foo(struct __sk_buff *skb)
+{
+       return bpf_get_prandom_u32();
+}
+
+SEC("cgroup_skb/ingress")
+int test_cls(struct __sk_buff *skb)
+{
+       if (!foo(skb))
+               return 0;
+
+       return 1;
+}
diff --git a/tools/testing/selftests/bpf/progs/test_map_init.c b/tools/testing/selftests/bpf/progs/test_map_init.c
new file mode 100644 (file)
index 0000000..c89d28e
--- /dev/null
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2020 Tessares SA <http://www.tessares.net> */
+
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+
+__u64 inKey = 0;
+__u64 inValue = 0;
+__u32 inPid = 0;
+
+struct {
+       __uint(type, BPF_MAP_TYPE_PERCPU_HASH);
+       __uint(max_entries, 2);
+       __type(key, __u64);
+       __type(value, __u64);
+} hashmap1 SEC(".maps");
+
+
+SEC("tp/syscalls/sys_enter_getpgid")
+int sysenter_getpgid(const void *ctx)
+{
+       /* Just do it for once, when called from our own test prog. This
+        * ensures the map value is only updated for a single CPU.
+        */
+       int cur_pid = bpf_get_current_pid_tgid() >> 32;
+
+       if (cur_pid == inPid)
+               bpf_map_update_elem(&hashmap1, &inKey, &inValue, BPF_NOEXIST);
+
+       return 0;
+}
+
+char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/progs/test_probe_read_user_str.c b/tools/testing/selftests/bpf/progs/test_probe_read_user_str.c
new file mode 100644 (file)
index 0000000..3ae398b
--- /dev/null
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+#include <sys/types.h>
+
+pid_t pid = 0;
+long ret = 0;
+void *user_ptr = 0;
+char buf[256] = {};
+
+SEC("tracepoint/syscalls/sys_enter_nanosleep")
+int on_write(void *ctx)
+{
+       if (pid != (bpf_get_current_pid_tgid() >> 32))
+               return 0;
+
+       ret = bpf_probe_read_user_str(buf, sizeof(buf), user_ptr);
+
+       return 0;
+}
+
+char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/progs/test_subprogs_unused.c b/tools/testing/selftests/bpf/progs/test_subprogs_unused.c
new file mode 100644 (file)
index 0000000..bc49e05
--- /dev/null
@@ -0,0 +1,21 @@
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_core_read.h>
+
+const char LICENSE[] SEC("license") = "GPL";
+
+__attribute__((unused)) __noinline int unused1(int x)
+{
+       return x + 1;
+}
+
+static __attribute__((unused)) __noinline int unused2(int x)
+{
+       return x + 2;
+}
+
+SEC("raw_tp/sys_enter")
+int main_prog(void *ctx)
+{
+       return 0;
+}
index 55bd387..52d3f03 100644 (file)
@@ -145,7 +145,7 @@ TEST(clone3_cap_checkpoint_restore)
        test_clone3_supported();
 
        EXPECT_EQ(getuid(), 0)
-               XFAIL(return, "Skipping all tests as non-root\n");
+               SKIP(return, "Skipping all tests as non-root");
 
        memset(&set_tid, 0, sizeof(set_tid));
 
index c99b98b..575b391 100644 (file)
@@ -44,7 +44,7 @@ TEST(close_range)
                fd = open("/dev/null", O_RDONLY | O_CLOEXEC);
                ASSERT_GE(fd, 0) {
                        if (errno == ENOENT)
-                               XFAIL(return, "Skipping test since /dev/null does not exist");
+                               SKIP(return, "Skipping test since /dev/null does not exist");
                }
 
                open_fds[i] = fd;
@@ -52,7 +52,7 @@ TEST(close_range)
 
        EXPECT_EQ(-1, sys_close_range(open_fds[0], open_fds[100], -1)) {
                if (errno == ENOSYS)
-                       XFAIL(return, "close_range() syscall not supported");
+                       SKIP(return, "close_range() syscall not supported");
        }
 
        EXPECT_EQ(0, sys_close_range(open_fds[0], open_fds[50], 0));
@@ -108,7 +108,7 @@ TEST(close_range_unshare)
                fd = open("/dev/null", O_RDONLY | O_CLOEXEC);
                ASSERT_GE(fd, 0) {
                        if (errno == ENOENT)
-                               XFAIL(return, "Skipping test since /dev/null does not exist");
+                               SKIP(return, "Skipping test since /dev/null does not exist");
                }
 
                open_fds[i] = fd;
@@ -197,7 +197,7 @@ TEST(close_range_unshare_capped)
                fd = open("/dev/null", O_RDONLY | O_CLOEXEC);
                ASSERT_GE(fd, 0) {
                        if (errno == ENOENT)
-                               XFAIL(return, "Skipping test since /dev/null does not exist");
+                               SKIP(return, "Skipping test since /dev/null does not exist");
                }
 
                open_fds[i] = fd;
index 1d27f52..477cbb0 100644 (file)
@@ -74,7 +74,7 @@ static int __do_binderfs_test(struct __test_metadata *_metadata)
        ret = mount(NULL, binderfs_mntpt, "binder", 0, 0);
        EXPECT_EQ(ret, 0) {
                if (errno == ENODEV)
-                       XFAIL(goto out, "binderfs missing");
+                       SKIP(goto out, "binderfs missing");
                TH_LOG("%s - Failed to mount binderfs", strerror(errno));
                goto rmdir;
        }
@@ -475,10 +475,10 @@ TEST(binderfs_stress)
 TEST(binderfs_test_privileged)
 {
        if (geteuid() != 0)
-               XFAIL(return, "Tests are not run as root. Skipping privileged tests");
+               SKIP(return, "Tests are not run as root. Skipping privileged tests");
 
        if (__do_binderfs_test(_metadata))
-               XFAIL(return, "The Android binderfs filesystem is not available");
+               SKIP(return, "The Android binderfs filesystem is not available");
 }
 
 TEST(binderfs_test_unprivileged)
@@ -511,7 +511,7 @@ TEST(binderfs_test_unprivileged)
        ret = wait_for_pid(pid);
        if (ret) {
                if (ret == 2)
-                       XFAIL(return, "The Android binderfs filesystem is not available");
+                       SKIP(return, "The Android binderfs filesystem is not available");
                ASSERT_EQ(ret, 0) {
                        TH_LOG("wait_for_pid() failed");
                }
index d979ff1..8f82f99 100644 (file)
@@ -3282,4 +3282,99 @@ TEST(epoll60)
        close(ctx.epfd);
 }
 
+struct epoll61_ctx {
+       int epfd;
+       int evfd;
+};
+
+static void *epoll61_write_eventfd(void *ctx_)
+{
+       struct epoll61_ctx *ctx = ctx_;
+       int64_t l = 1;
+
+       usleep(10950);
+       write(ctx->evfd, &l, sizeof(l));
+       return NULL;
+}
+
+static void *epoll61_epoll_with_timeout(void *ctx_)
+{
+       struct epoll61_ctx *ctx = ctx_;
+       struct epoll_event events[1];
+       int n;
+
+       n = epoll_wait(ctx->epfd, events, 1, 11);
+       /*
+        * If epoll returned the eventfd, write on the eventfd to wake up the
+        * blocking poller.
+        */
+       if (n == 1) {
+               int64_t l = 1;
+
+               write(ctx->evfd, &l, sizeof(l));
+       }
+       return NULL;
+}
+
+static void *epoll61_blocking_epoll(void *ctx_)
+{
+       struct epoll61_ctx *ctx = ctx_;
+       struct epoll_event events[1];
+
+       epoll_wait(ctx->epfd, events, 1, -1);
+       return NULL;
+}
+
+TEST(epoll61)
+{
+       struct epoll61_ctx ctx;
+       struct epoll_event ev;
+       int i, r;
+
+       ctx.epfd = epoll_create1(0);
+       ASSERT_GE(ctx.epfd, 0);
+       ctx.evfd = eventfd(0, EFD_NONBLOCK);
+       ASSERT_GE(ctx.evfd, 0);
+
+       ev.events = EPOLLIN | EPOLLET | EPOLLERR | EPOLLHUP;
+       ev.data.ptr = NULL;
+       r = epoll_ctl(ctx.epfd, EPOLL_CTL_ADD, ctx.evfd, &ev);
+       ASSERT_EQ(r, 0);
+
+       /*
+        * We are testing a race.  Repeat the test case 1000 times to make it
+        * more likely to fail in case of a bug.
+        */
+       for (i = 0; i < 1000; i++) {
+               pthread_t threads[3];
+               int n;
+
+               /*
+                * Start 3 threads:
+                * Thread 1 sleeps for 10.9ms and writes to the evenfd.
+                * Thread 2 calls epoll with a timeout of 11ms.
+                * Thread 3 calls epoll with a timeout of -1.
+                *
+                * The eventfd write by Thread 1 should either wakeup Thread 2
+                * or Thread 3.  If it wakes up Thread 2, Thread 2 writes on the
+                * eventfd to wake up Thread 3.
+                *
+                * If no events are missed, all three threads should eventually
+                * be joinable.
+                */
+               ASSERT_EQ(pthread_create(&threads[0], NULL,
+                                        epoll61_write_eventfd, &ctx), 0);
+               ASSERT_EQ(pthread_create(&threads[1], NULL,
+                                        epoll61_epoll_with_timeout, &ctx), 0);
+               ASSERT_EQ(pthread_create(&threads[2], NULL,
+                                        epoll61_blocking_epoll, &ctx), 0);
+
+               for (n = 0; n < ARRAY_SIZE(threads); ++n)
+                       ASSERT_EQ(pthread_join(threads[n], NULL), 0);
+       }
+
+       close(ctx.epfd);
+       close(ctx.evfd);
+}
+
 TEST_HARNESS_MAIN
index 3bcd4c3..b4da41d 100644 (file)
@@ -6,7 +6,7 @@
 echo 0 > events/enable
 echo > dynamic_events
 
-PLACE=kernel_clone
+PLACE=$FUNCTION_FORK
 
 echo "p:myevent1 $PLACE" >> dynamic_events
 echo "r:myevent2 $PLACE" >> dynamic_events
index 4389619..3a0e288 100644 (file)
@@ -6,7 +6,7 @@
 echo 0 > events/enable
 echo > dynamic_events
 
-PLACE=kernel_clone
+PLACE=$FUNCTION_FORK
 
 setup_events() {
 echo "p:myevent1 $PLACE" >> dynamic_events
index a8603bd..d3e138e 100644 (file)
@@ -6,7 +6,7 @@
 echo 0 > events/enable
 echo > dynamic_events
 
-PLACE=kernel_clone
+PLACE=$FUNCTION_FORK
 
 setup_events() {
 echo "p:myevent1 $PLACE" >> dynamic_events
index acb17ce..8054196 100644 (file)
@@ -39,7 +39,7 @@ do_test() {
     disable_tracing
 
     echo do_execve* > set_ftrace_filter
-    echo *do_fork >> set_ftrace_filter
+    echo $FUNCTION_FORK >> set_ftrace_filter
 
     echo $PID > set_ftrace_notrace_pid
     echo function > current_tracer
index 9f0a968..2f72112 100644 (file)
@@ -39,7 +39,7 @@ do_test() {
     disable_tracing
 
     echo do_execve* > set_ftrace_filter
-    echo *do_fork >> set_ftrace_filter
+    echo $FUNCTION_FORK >> set_ftrace_filter
 
     echo $PID > set_ftrace_pid
     echo function > current_tracer
index 98305d7..191d116 100644 (file)
@@ -4,9 +4,9 @@
 # requires: set_ftrace_filter
 # flags: instance
 
-echo kernel_clone:stacktrace >> set_ftrace_filter
+echo $FUNCTION_FORK:stacktrace >> set_ftrace_filter
 
-grep -q "kernel_clone:stacktrace:unlimited" set_ftrace_filter
+grep -q "$FUNCTION_FORK:stacktrace:unlimited" set_ftrace_filter
 
 (echo "forked"; sleep 1)
 
index c5dec55..a6fac92 100644 (file)
@@ -133,6 +133,13 @@ yield() {
     ping $LOCALHOST -c 1 || sleep .001 || usleep 1 || sleep 1
 }
 
+# The fork function in the kernel was renamed from "_do_fork" to
+# "kernel_fork". As older tests should still work with older kernels
+# as well as newer kernels, check which version of fork is used on this
+# kernel so that the tests can use the fork function for the running kernel.
+FUNCTION_FORK=`(if grep '\bkernel_clone\b' /proc/kallsyms > /dev/null; then
+                echo kernel_clone; else echo '_do_fork'; fi)`
+
 # Since probe event command may include backslash, explicitly use printf "%s"
 # to NOT interpret it.
 ftrace_errlog_check() { # err-prefix command-with-error-pos-by-^ command-file
index 9737cd0..2428a3e 100644 (file)
@@ -3,7 +3,7 @@
 # description: Kprobe dynamic event - adding and removing
 # requires: kprobe_events
 
-echo p:myevent kernel_clone > kprobe_events
+echo p:myevent $FUNCTION_FORK > kprobe_events
 grep myevent kprobe_events
 test -d events/kprobes/myevent
 echo > kprobe_events
index f9a40af..010a8b1 100644 (file)
@@ -3,7 +3,7 @@
 # description: Kprobe dynamic event - busy event check
 # requires: kprobe_events
 
-echo p:myevent kernel_clone > kprobe_events
+echo p:myevent $FUNCTION_FORK > kprobe_events
 test -d events/kprobes/myevent
 echo 1 > events/kprobes/myevent/enable
 echo > kprobe_events && exit_fail # this must fail
index eb543d3..a96a1dc 100644 (file)
@@ -3,13 +3,13 @@
 # description: Kprobe dynamic event with arguments
 # requires: kprobe_events
 
-echo 'p:testprobe kernel_clone $stack $stack0 +0($stack)' > kprobe_events
+echo "p:testprobe $FUNCTION_FORK \$stack \$stack0 +0(\$stack)" > kprobe_events
 grep testprobe kprobe_events | grep -q 'arg1=\$stack arg2=\$stack0 arg3=+0(\$stack)'
 test -d events/kprobes/testprobe
 
 echo 1 > events/kprobes/testprobe/enable
 ( echo "forked")
-grep testprobe trace | grep 'kernel_clone' | \
+grep testprobe trace | grep "$FUNCTION_FORK" | \
   grep -q 'arg1=0x[[:xdigit:]]* arg2=0x[[:xdigit:]]* arg3=0x[[:xdigit:]]*$'
 
 echo 0 > events/kprobes/testprobe/enable
index 4e5b63b..a053ee2 100644 (file)
@@ -5,7 +5,7 @@
 
 grep -A1 "fetcharg:" README | grep -q "\$comm" || exit_unsupported # this is too old
 
-echo 'p:testprobe kernel_clone comm=$comm ' > kprobe_events
+echo "p:testprobe $FUNCTION_FORK comm=\$comm " > kprobe_events
 grep testprobe kprobe_events | grep -q 'comm=$comm'
 test -d events/kprobes/testprobe
 
index a1d7058..84285a6 100644 (file)
@@ -30,13 +30,13 @@ esac
 : "Test get argument (1)"
 echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string" > kprobe_events
 echo 1 > events/kprobes/testprobe/enable
-echo "p:test kernel_clone" >> kprobe_events
+echo "p:test $FUNCTION_FORK" >> kprobe_events
 grep -qe "testprobe.* arg1=\"test\"" trace
 
 echo 0 > events/kprobes/testprobe/enable
 : "Test get argument (2)"
 echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string arg2=+0(${ARG1}):string" > kprobe_events
 echo 1 > events/kprobes/testprobe/enable
-echo "p:test kernel_clone" >> kprobe_events
+echo "p:test $FUNCTION_FORK" >> kprobe_events
 grep -qe "testprobe.* arg1=\"test\" arg2=\"test\"" trace
 
index bd25dd0..717130e 100644 (file)
@@ -14,12 +14,12 @@ elif ! grep "$SYMBOL\$" /proc/kallsyms; then
 fi
 
 : "Test get basic types symbol argument"
-echo "p:testprobe_u kernel_clone arg1=@linux_proc_banner:u64 arg2=@linux_proc_banner:u32 arg3=@linux_proc_banner:u16 arg4=@linux_proc_banner:u8" > kprobe_events
-echo "p:testprobe_s kernel_clone arg1=@linux_proc_banner:s64 arg2=@linux_proc_banner:s32 arg3=@linux_proc_banner:s16 arg4=@linux_proc_banner:s8" >> kprobe_events
+echo "p:testprobe_u $FUNCTION_FORK arg1=@linux_proc_banner:u64 arg2=@linux_proc_banner:u32 arg3=@linux_proc_banner:u16 arg4=@linux_proc_banner:u8" > kprobe_events
+echo "p:testprobe_s $FUNCTION_FORK arg1=@linux_proc_banner:s64 arg2=@linux_proc_banner:s32 arg3=@linux_proc_banner:s16 arg4=@linux_proc_banner:s8" >> kprobe_events
 if grep -q "x8/16/32/64" README; then
-  echo "p:testprobe_x kernel_clone arg1=@linux_proc_banner:x64 arg2=@linux_proc_banner:x32 arg3=@linux_proc_banner:x16 arg4=@linux_proc_banner:x8" >> kprobe_events
+  echo "p:testprobe_x $FUNCTION_FORK arg1=@linux_proc_banner:x64 arg2=@linux_proc_banner:x32 arg3=@linux_proc_banner:x16 arg4=@linux_proc_banner:x8" >> kprobe_events
 fi
-echo "p:testprobe_bf kernel_clone arg1=@linux_proc_banner:b8@4/32" >> kprobe_events
+echo "p:testprobe_bf $FUNCTION_FORK arg1=@linux_proc_banner:b8@4/32" >> kprobe_events
 echo 1 > events/kprobes/enable
 (echo "forked")
 echo 0 > events/kprobes/enable
@@ -27,7 +27,7 @@ grep "testprobe_[usx]:.* arg1=.* arg2=.* arg3=.* arg4=.*" trace
 grep "testprobe_bf:.* arg1=.*" trace
 
 : "Test get string symbol argument"
-echo "p:testprobe_str kernel_clone arg1=@linux_proc_banner:string" > kprobe_events
+echo "p:testprobe_str $FUNCTION_FORK arg1=@linux_proc_banner:string" > kprobe_events
 echo 1 > events/kprobes/enable
 (echo "forked")
 echo 0 > events/kprobes/enable
index 91fcce1..25b7708 100644 (file)
@@ -4,7 +4,7 @@
 # requires: kprobe_events "x8/16/32/64":README
 
 gen_event() { # Bitsize
-  echo "p:testprobe kernel_clone \$stack0:s$1 \$stack0:u$1 \$stack0:x$1 \$stack0:b4@4/$1"
+  echo "p:testprobe $FUNCTION_FORK \$stack0:s$1 \$stack0:u$1 \$stack0:x$1 \$stack0:b4@4/$1"
 }
 
 check_types() { # s-type u-type x-type bf-type width
index a30a9c0..d25d01a 100644 (file)
@@ -9,12 +9,16 @@ grep -A10 "fetcharg:" README | grep -q '\[u\]<offset>' || exit_unsupported
 :;: "user-memory access syntax and ustring working on user memory";:
 echo 'p:myevent do_sys_open path=+0($arg2):ustring path2=+u0($arg2):string' \
        > kprobe_events
+echo 'p:myevent2 do_sys_openat2 path=+0($arg2):ustring path2=+u0($arg2):string' \
+       >> kprobe_events
 
 grep myevent kprobe_events | \
        grep -q 'path=+0($arg2):ustring path2=+u0($arg2):string'
 echo 1 > events/kprobes/myevent/enable
+echo 1 > events/kprobes/myevent2/enable
 echo > /dev/null
 echo 0 > events/kprobes/myevent/enable
+echo 0 > events/kprobes/myevent2/enable
 
 grep myevent trace | grep -q 'path="/dev/null" path2="/dev/null"'
 
index 0d17909..5556292 100644 (file)
@@ -5,29 +5,29 @@
 
 # prepare
 echo nop > current_tracer
-echo kernel_clone > set_ftrace_filter
-echo 'p:testprobe kernel_clone' > kprobe_events
+echo $FUNCTION_FORK > set_ftrace_filter
+echo "p:testprobe $FUNCTION_FORK" > kprobe_events
 
 # kprobe on / ftrace off
 echo 1 > events/kprobes/testprobe/enable
 echo > trace
 ( echo "forked")
 grep testprobe trace
-! grep 'kernel_clone <-' trace
+! grep "$FUNCTION_FORK <-" trace
 
 # kprobe on / ftrace on
 echo function > current_tracer
 echo > trace
 ( echo "forked")
 grep testprobe trace
-grep 'kernel_clone <-' trace
+grep "$FUNCTION_FORK <-" trace
 
 # kprobe off / ftrace on
 echo 0 > events/kprobes/testprobe/enable
 echo > trace
 ( echo "forked")
 ! grep testprobe trace
-grep 'kernel_clone <-' trace
+grep "$FUNCTION_FORK <-" trace
 
 # kprobe on / ftrace on
 echo 1 > events/kprobes/testprobe/enable
@@ -35,11 +35,11 @@ echo function > current_tracer
 echo > trace
 ( echo "forked")
 grep testprobe trace
-grep 'kernel_clone <-' trace
+grep "$FUNCTION_FORK <-" trace
 
 # kprobe on / ftrace off
 echo nop > current_tracer
 echo > trace
 ( echo "forked")
 grep testprobe trace
-! grep 'kernel_clone <-' trace
+! grep "$FUNCTION_FORK <-" trace
index 45d90b6..f0d5b77 100644 (file)
@@ -4,7 +4,7 @@
 # requires: kprobe_events "Create/append/":README
 
 # Choose 2 symbols for target
-SYM1=kernel_clone
+SYM1=$FUNCTION_FORK
 SYM2=do_exit
 EVENT_NAME=kprobes/testevent
 
index 1b5550e..fa928b4 100644 (file)
@@ -86,15 +86,15 @@ esac
 
 # multiprobe errors
 if grep -q "Create/append/" README && grep -q "imm-value" README; then
-echo 'p:kprobes/testevent kernel_clone' > kprobe_events
+echo "p:kprobes/testevent $FUNCTION_FORK" > kprobe_events
 check_error '^r:kprobes/testevent do_exit'     # DIFF_PROBE_TYPE
 
 # Explicitly use printf "%s" to not interpret \1
-printf "%s" 'p:kprobes/testevent kernel_clone abcd=\1' > kprobe_events
-check_error 'p:kprobes/testevent kernel_clone ^bcd=\1' # DIFF_ARG_TYPE
-check_error 'p:kprobes/testevent kernel_clone ^abcd=\1:u8'     # DIFF_ARG_TYPE
-check_error 'p:kprobes/testevent kernel_clone ^abcd=\"foo"'    # DIFF_ARG_TYPE
-check_error '^p:kprobes/testevent kernel_clone abcd=\1'        # SAME_PROBE
+printf "%s" "p:kprobes/testevent $FUNCTION_FORK abcd=\\1" > kprobe_events
+check_error "p:kprobes/testevent $FUNCTION_FORK ^bcd=\\1"      # DIFF_ARG_TYPE
+check_error "p:kprobes/testevent $FUNCTION_FORK ^abcd=\\1:u8"  # DIFF_ARG_TYPE
+check_error "p:kprobes/testevent $FUNCTION_FORK ^abcd=\\\"foo\"" # DIFF_ARG_TYPE
+check_error "^p:kprobes/testevent $FUNCTION_FORK abcd=\\1"     # SAME_PROBE
 fi
 
 # %return suffix errors
index 7ae492c..197cc2a 100644 (file)
@@ -4,14 +4,14 @@
 # requires: kprobe_events
 
 # Add new kretprobe event
-echo 'r:testprobe2 kernel_clone $retval' > kprobe_events
+echo "r:testprobe2 $FUNCTION_FORK \$retval" > kprobe_events
 grep testprobe2 kprobe_events | grep -q 'arg1=\$retval'
 test -d events/kprobes/testprobe2
 
 echo 1 > events/kprobes/testprobe2/enable
 ( echo "forked")
 
-cat trace | grep testprobe2 | grep -q '<- kernel_clone'
+cat trace | grep testprobe2 | grep -q "<- $FUNCTION_FORK"
 
 echo 0 > events/kprobes/testprobe2/enable
 echo '-:testprobe2' >> kprobe_events
index c4093fc..98166fa 100644 (file)
@@ -4,7 +4,7 @@
 # requires: kprobe_events
 
 ! grep -q 'myevent' kprobe_profile
-echo p:myevent kernel_clone > kprobe_events
+echo "p:myevent $FUNCTION_FORK" > kprobe_events
 grep -q 'myevent[[:space:]]*0[[:space:]]*0$' kprobe_profile
 echo 1 > events/kprobes/myevent/enable
 ( echo "forked" )
index f19804d..edce854 100644 (file)
        snprintf(_metadata->results->reason, \
                 sizeof(_metadata->results->reason), fmt, ##__VA_ARGS__); \
        if (TH_LOG_ENABLED) { \
-               fprintf(TH_LOG_STREAM, "#      SKIP     %s\n", \
+               fprintf(TH_LOG_STREAM, "#      SKIP      %s\n", \
                        _metadata->results->reason); \
        } \
        _metadata->passed = 1; \
  */
 
 /**
- * ASSERT_EQ(expected, seen)
+ * ASSERT_EQ()
  *
  * @expected: expected value
  * @seen: measured value
        __EXPECT(expected, #expected, seen, #seen, ==, 1)
 
 /**
- * ASSERT_NE(expected, seen)
+ * ASSERT_NE()
  *
  * @expected: expected value
  * @seen: measured value
        __EXPECT(expected, #expected, seen, #seen, !=, 1)
 
 /**
- * ASSERT_LT(expected, seen)
+ * ASSERT_LT()
  *
  * @expected: expected value
  * @seen: measured value
        __EXPECT(expected, #expected, seen, #seen, <, 1)
 
 /**
- * ASSERT_LE(expected, seen)
+ * ASSERT_LE()
  *
  * @expected: expected value
  * @seen: measured value
        __EXPECT(expected, #expected, seen, #seen, <=, 1)
 
 /**
- * ASSERT_GT(expected, seen)
+ * ASSERT_GT()
  *
  * @expected: expected value
  * @seen: measured value
        __EXPECT(expected, #expected, seen, #seen, >, 1)
 
 /**
- * ASSERT_GE(expected, seen)
+ * ASSERT_GE()
  *
  * @expected: expected value
  * @seen: measured value
        __EXPECT(expected, #expected, seen, #seen, >=, 1)
 
 /**
- * ASSERT_NULL(seen)
+ * ASSERT_NULL()
  *
  * @seen: measured value
  *
        __EXPECT(NULL, "NULL", seen, #seen, ==, 1)
 
 /**
- * ASSERT_TRUE(seen)
+ * ASSERT_TRUE()
  *
  * @seen: measured value
  *
        __EXPECT(0, "0", seen, #seen, !=, 1)
 
 /**
- * ASSERT_FALSE(seen)
+ * ASSERT_FALSE()
  *
  * @seen: measured value
  *
        __EXPECT(0, "0", seen, #seen, ==, 1)
 
 /**
- * ASSERT_STREQ(expected, seen)
+ * ASSERT_STREQ()
  *
  * @expected: expected value
  * @seen: measured value
        __EXPECT_STR(expected, seen, ==, 1)
 
 /**
- * ASSERT_STRNE(expected, seen)
+ * ASSERT_STRNE()
  *
  * @expected: expected value
  * @seen: measured value
        __EXPECT_STR(expected, seen, !=, 1)
 
 /**
- * EXPECT_EQ(expected, seen)
+ * EXPECT_EQ()
  *
  * @expected: expected value
  * @seen: measured value
        __EXPECT(expected, #expected, seen, #seen, ==, 0)
 
 /**
- * EXPECT_NE(expected, seen)
+ * EXPECT_NE()
  *
  * @expected: expected value
  * @seen: measured value
        __EXPECT(expected, #expected, seen, #seen, !=, 0)
 
 /**
- * EXPECT_LT(expected, seen)
+ * EXPECT_LT()
  *
  * @expected: expected value
  * @seen: measured value
        __EXPECT(expected, #expected, seen, #seen, <, 0)
 
 /**
- * EXPECT_LE(expected, seen)
+ * EXPECT_LE()
  *
  * @expected: expected value
  * @seen: measured value
        __EXPECT(expected, #expected, seen, #seen, <=, 0)
 
 /**
- * EXPECT_GT(expected, seen)
+ * EXPECT_GT()
  *
  * @expected: expected value
  * @seen: measured value
        __EXPECT(expected, #expected, seen, #seen, >, 0)
 
 /**
- * EXPECT_GE(expected, seen)
+ * EXPECT_GE()
  *
  * @expected: expected value
  * @seen: measured value
        __EXPECT(expected, #expected, seen, #seen, >=, 0)
 
 /**
- * EXPECT_NULL(seen)
+ * EXPECT_NULL()
  *
  * @seen: measured value
  *
        __EXPECT(NULL, "NULL", seen, #seen, ==, 0)
 
 /**
- * EXPECT_TRUE(seen)
+ * EXPECT_TRUE()
  *
  * @seen: measured value
  *
        __EXPECT(0, "0", seen, #seen, !=, 0)
 
 /**
- * EXPECT_FALSE(seen)
+ * EXPECT_FALSE()
  *
  * @seen: measured value
  *
        __EXPECT(0, "0", seen, #seen, ==, 0)
 
 /**
- * EXPECT_STREQ(expected, seen)
+ * EXPECT_STREQ()
  *
  * @expected: expected value
  * @seen: measured value
        __EXPECT_STR(expected, seen, ==, 0)
 
 /**
- * EXPECT_STRNE(expected, seen)
+ * EXPECT_STRNE()
  *
  * @expected: expected value
  * @seen: measured value
index d2c2d62..7a2c242 100644 (file)
@@ -1,10 +1,13 @@
 # SPDX-License-Identifier: GPL-2.0-only
+/aarch64/get-reg-list
+/aarch64/get-reg-list-sve
 /s390x/memop
 /s390x/resets
 /s390x/sync_regs_test
 /x86_64/cr4_cpuid_sync_test
 /x86_64/debug_regs
 /x86_64/evmcs_test
+/x86_64/kvm_pv_test
 /x86_64/hyperv_cpuid
 /x86_64/mmio_warning_test
 /x86_64/platform_info_test
@@ -24,6 +27,7 @@
 /clear_dirty_log_test
 /demand_paging_test
 /dirty_log_test
+/dirty_log_perf_test
 /kvm_create_max_vcpus
 /set_memory_region_test
 /steal_time
index 30afbad..3d14ef7 100644 (file)
@@ -34,13 +34,14 @@ ifeq ($(ARCH),s390)
 endif
 
 LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c lib/test_util.c
-LIBKVM_x86_64 = lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/svm.c lib/x86_64/ucall.c
+LIBKVM_x86_64 = lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/svm.c lib/x86_64/ucall.c lib/x86_64/handlers.S
 LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c
 LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c
 
 TEST_GEN_PROGS_x86_64 = x86_64/cr4_cpuid_sync_test
 TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test
 TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid
+TEST_GEN_PROGS_x86_64 += x86_64/kvm_pv_test
 TEST_GEN_PROGS_x86_64 += x86_64/mmio_warning_test
 TEST_GEN_PROGS_x86_64 += x86_64/platform_info_test
 TEST_GEN_PROGS_x86_64 += x86_64/set_sregs_test
@@ -58,14 +59,15 @@ TEST_GEN_PROGS_x86_64 += x86_64/xss_msr_test
 TEST_GEN_PROGS_x86_64 += x86_64/debug_regs
 TEST_GEN_PROGS_x86_64 += x86_64/tsc_msrs_test
 TEST_GEN_PROGS_x86_64 += x86_64/user_msr_test
-TEST_GEN_PROGS_x86_64 += clear_dirty_log_test
 TEST_GEN_PROGS_x86_64 += demand_paging_test
 TEST_GEN_PROGS_x86_64 += dirty_log_test
+TEST_GEN_PROGS_x86_64 += dirty_log_perf_test
 TEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus
 TEST_GEN_PROGS_x86_64 += set_memory_region_test
 TEST_GEN_PROGS_x86_64 += steal_time
 
-TEST_GEN_PROGS_aarch64 += clear_dirty_log_test
+TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list
+TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list-sve
 TEST_GEN_PROGS_aarch64 += demand_paging_test
 TEST_GEN_PROGS_aarch64 += dirty_log_test
 TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus
@@ -111,14 +113,21 @@ LDFLAGS += -pthread $(no-pie-option) $(pgste-option)
 include ../lib.mk
 
 STATIC_LIBS := $(OUTPUT)/libkvm.a
-LIBKVM_OBJ := $(patsubst %.c, $(OUTPUT)/%.o, $(LIBKVM))
-EXTRA_CLEAN += $(LIBKVM_OBJ) $(STATIC_LIBS) cscope.*
+LIBKVM_C := $(filter %.c,$(LIBKVM))
+LIBKVM_S := $(filter %.S,$(LIBKVM))
+LIBKVM_C_OBJ := $(patsubst %.c, $(OUTPUT)/%.o, $(LIBKVM_C))
+LIBKVM_S_OBJ := $(patsubst %.S, $(OUTPUT)/%.o, $(LIBKVM_S))
+EXTRA_CLEAN += $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ) $(STATIC_LIBS) cscope.*
+
+x := $(shell mkdir -p $(sort $(dir $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ))))
+$(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c
+       $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
 
-x := $(shell mkdir -p $(sort $(dir $(LIBKVM_OBJ))))
-$(LIBKVM_OBJ): $(OUTPUT)/%.o: %.c
+$(LIBKVM_S_OBJ): $(OUTPUT)/%.o: %.S
        $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
 
-$(OUTPUT)/libkvm.a: $(LIBKVM_OBJ)
+LIBKVM_OBJS = $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ)
+$(OUTPUT)/libkvm.a: $(LIBKVM_OBJS)
        $(AR) crs $@ $^
 
 x := $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS))))
diff --git a/tools/testing/selftests/kvm/aarch64/get-reg-list-sve.c b/tools/testing/selftests/kvm/aarch64/get-reg-list-sve.c
new file mode 100644 (file)
index 0000000..efba766
--- /dev/null
@@ -0,0 +1,3 @@
+// SPDX-License-Identifier: GPL-2.0
+#define REG_LIST_SVE
+#include "get-reg-list.c"
diff --git a/tools/testing/selftests/kvm/aarch64/get-reg-list.c b/tools/testing/selftests/kvm/aarch64/get-reg-list.c
new file mode 100644 (file)
index 0000000..33218a3
--- /dev/null
@@ -0,0 +1,841 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Check for KVM_GET_REG_LIST regressions.
+ *
+ * Copyright (C) 2020, Red Hat, Inc.
+ *
+ * When attempting to migrate from a host with an older kernel to a host
+ * with a newer kernel we allow the newer kernel on the destination to
+ * list new registers with get-reg-list. We assume they'll be unused, at
+ * least until the guest reboots, and so they're relatively harmless.
+ * However, if the destination host with the newer kernel is missing
+ * registers which the source host with the older kernel has, then that's
+ * a regression in get-reg-list. This test checks for that regression by
+ * checking the current list against a blessed list. We should never have
+ * missing registers, but if new ones appear then they can probably be
+ * added to the blessed list. A completely new blessed list can be created
+ * by running the test with the --list command line argument.
+ *
+ * Note, the blessed list should be created from the oldest possible
+ * kernel. We can't go older than v4.15, though, because that's the first
+ * release to expose the ID system registers in KVM_GET_REG_LIST, see
+ * commit 93390c0a1b20 ("arm64: KVM: Hide unsupported AArch64 CPU features
+ * from guests"). Also, one must use the --core-reg-fixup command line
+ * option when running on an older kernel that doesn't include df205b5c6328
+ * ("KVM: arm64: Filter out invalid core register IDs in KVM_GET_REG_LIST")
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "kvm_util.h"
+#include "test_util.h"
+#include "processor.h"
+
+#ifdef REG_LIST_SVE
+#define reg_list_sve() (true)
+#else
+#define reg_list_sve() (false)
+#endif
+
+#define REG_MASK (KVM_REG_ARCH_MASK | KVM_REG_SIZE_MASK | KVM_REG_ARM_COPROC_MASK)
+
+#define for_each_reg(i)                                                                \
+       for ((i) = 0; (i) < reg_list->n; ++(i))
+
+#define for_each_missing_reg(i)                                                        \
+       for ((i) = 0; (i) < blessed_n; ++(i))                                   \
+               if (!find_reg(reg_list->reg, reg_list->n, blessed_reg[i]))
+
+#define for_each_new_reg(i)                                                    \
+       for ((i) = 0; (i) < reg_list->n; ++(i))                                 \
+               if (!find_reg(blessed_reg, blessed_n, reg_list->reg[i]))
+
+
+static struct kvm_reg_list *reg_list;
+
+static __u64 base_regs[], vregs[], sve_regs[], rejects_set[];
+static __u64 base_regs_n, vregs_n, sve_regs_n, rejects_set_n;
+static __u64 *blessed_reg, blessed_n;
+
+static bool find_reg(__u64 regs[], __u64 nr_regs, __u64 reg)
+{
+       int i;
+
+       for (i = 0; i < nr_regs; ++i)
+               if (reg == regs[i])
+                       return true;
+       return false;
+}
+
+static const char *str_with_index(const char *template, __u64 index)
+{
+       char *str, *p;
+       int n;
+
+       str = strdup(template);
+       p = strstr(str, "##");
+       n = sprintf(p, "%lld", index);
+       strcat(p + n, strstr(template, "##") + 2);
+
+       return (const char *)str;
+}
+
+#define CORE_REGS_XX_NR_WORDS  2
+#define CORE_SPSR_XX_NR_WORDS  2
+#define CORE_FPREGS_XX_NR_WORDS        4
+
+static const char *core_id_to_str(__u64 id)
+{
+       __u64 core_off = id & ~REG_MASK, idx;
+
+       /*
+        * core_off is the offset into struct kvm_regs
+        */
+       switch (core_off) {
+       case KVM_REG_ARM_CORE_REG(regs.regs[0]) ...
+            KVM_REG_ARM_CORE_REG(regs.regs[30]):
+               idx = (core_off - KVM_REG_ARM_CORE_REG(regs.regs[0])) / CORE_REGS_XX_NR_WORDS;
+               TEST_ASSERT(idx < 31, "Unexpected regs.regs index: %lld", idx);
+               return str_with_index("KVM_REG_ARM_CORE_REG(regs.regs[##])", idx);
+       case KVM_REG_ARM_CORE_REG(regs.sp):
+               return "KVM_REG_ARM_CORE_REG(regs.sp)";
+       case KVM_REG_ARM_CORE_REG(regs.pc):
+               return "KVM_REG_ARM_CORE_REG(regs.pc)";
+       case KVM_REG_ARM_CORE_REG(regs.pstate):
+               return "KVM_REG_ARM_CORE_REG(regs.pstate)";
+       case KVM_REG_ARM_CORE_REG(sp_el1):
+               return "KVM_REG_ARM_CORE_REG(sp_el1)";
+       case KVM_REG_ARM_CORE_REG(elr_el1):
+               return "KVM_REG_ARM_CORE_REG(elr_el1)";
+       case KVM_REG_ARM_CORE_REG(spsr[0]) ...
+            KVM_REG_ARM_CORE_REG(spsr[KVM_NR_SPSR - 1]):
+               idx = (core_off - KVM_REG_ARM_CORE_REG(spsr[0])) / CORE_SPSR_XX_NR_WORDS;
+               TEST_ASSERT(idx < KVM_NR_SPSR, "Unexpected spsr index: %lld", idx);
+               return str_with_index("KVM_REG_ARM_CORE_REG(spsr[##])", idx);
+       case KVM_REG_ARM_CORE_REG(fp_regs.vregs[0]) ...
+            KVM_REG_ARM_CORE_REG(fp_regs.vregs[31]):
+               idx = (core_off - KVM_REG_ARM_CORE_REG(fp_regs.vregs[0])) / CORE_FPREGS_XX_NR_WORDS;
+               TEST_ASSERT(idx < 32, "Unexpected fp_regs.vregs index: %lld", idx);
+               return str_with_index("KVM_REG_ARM_CORE_REG(fp_regs.vregs[##])", idx);
+       case KVM_REG_ARM_CORE_REG(fp_regs.fpsr):
+               return "KVM_REG_ARM_CORE_REG(fp_regs.fpsr)";
+       case KVM_REG_ARM_CORE_REG(fp_regs.fpcr):
+               return "KVM_REG_ARM_CORE_REG(fp_regs.fpcr)";
+       }
+
+       TEST_FAIL("Unknown core reg id: 0x%llx", id);
+       return NULL;
+}
+
+static const char *sve_id_to_str(__u64 id)
+{
+       __u64 sve_off, n, i;
+
+       if (id == KVM_REG_ARM64_SVE_VLS)
+               return "KVM_REG_ARM64_SVE_VLS";
+
+       sve_off = id & ~(REG_MASK | ((1ULL << 5) - 1));
+       i = id & (KVM_ARM64_SVE_MAX_SLICES - 1);
+
+       TEST_ASSERT(i == 0, "Currently we don't expect slice > 0, reg id 0x%llx", id);
+
+       switch (sve_off) {
+       case KVM_REG_ARM64_SVE_ZREG_BASE ...
+            KVM_REG_ARM64_SVE_ZREG_BASE + (1ULL << 5) * KVM_ARM64_SVE_NUM_ZREGS - 1:
+               n = (id >> 5) & (KVM_ARM64_SVE_NUM_ZREGS - 1);
+               TEST_ASSERT(id == KVM_REG_ARM64_SVE_ZREG(n, 0),
+                           "Unexpected bits set in SVE ZREG id: 0x%llx", id);
+               return str_with_index("KVM_REG_ARM64_SVE_ZREG(##, 0)", n);
+       case KVM_REG_ARM64_SVE_PREG_BASE ...
+            KVM_REG_ARM64_SVE_PREG_BASE + (1ULL << 5) * KVM_ARM64_SVE_NUM_PREGS - 1:
+               n = (id >> 5) & (KVM_ARM64_SVE_NUM_PREGS - 1);
+               TEST_ASSERT(id == KVM_REG_ARM64_SVE_PREG(n, 0),
+                           "Unexpected bits set in SVE PREG id: 0x%llx", id);
+               return str_with_index("KVM_REG_ARM64_SVE_PREG(##, 0)", n);
+       case KVM_REG_ARM64_SVE_FFR_BASE:
+               TEST_ASSERT(id == KVM_REG_ARM64_SVE_FFR(0),
+                           "Unexpected bits set in SVE FFR id: 0x%llx", id);
+               return "KVM_REG_ARM64_SVE_FFR(0)";
+       }
+
+       return NULL;
+}
+
+static void print_reg(__u64 id)
+{
+       unsigned op0, op1, crn, crm, op2;
+       const char *reg_size = NULL;
+
+       TEST_ASSERT((id & KVM_REG_ARCH_MASK) == KVM_REG_ARM64,
+                   "KVM_REG_ARM64 missing in reg id: 0x%llx", id);
+
+       switch (id & KVM_REG_SIZE_MASK) {
+       case KVM_REG_SIZE_U8:
+               reg_size = "KVM_REG_SIZE_U8";
+               break;
+       case KVM_REG_SIZE_U16:
+               reg_size = "KVM_REG_SIZE_U16";
+               break;
+       case KVM_REG_SIZE_U32:
+               reg_size = "KVM_REG_SIZE_U32";
+               break;
+       case KVM_REG_SIZE_U64:
+               reg_size = "KVM_REG_SIZE_U64";
+               break;
+       case KVM_REG_SIZE_U128:
+               reg_size = "KVM_REG_SIZE_U128";
+               break;
+       case KVM_REG_SIZE_U256:
+               reg_size = "KVM_REG_SIZE_U256";
+               break;
+       case KVM_REG_SIZE_U512:
+               reg_size = "KVM_REG_SIZE_U512";
+               break;
+       case KVM_REG_SIZE_U1024:
+               reg_size = "KVM_REG_SIZE_U1024";
+               break;
+       case KVM_REG_SIZE_U2048:
+               reg_size = "KVM_REG_SIZE_U2048";
+               break;
+       default:
+               TEST_FAIL("Unexpected reg size: 0x%llx in reg id: 0x%llx",
+                         (id & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT, id);
+       }
+
+       switch (id & KVM_REG_ARM_COPROC_MASK) {
+       case KVM_REG_ARM_CORE:
+               printf("\tKVM_REG_ARM64 | %s | KVM_REG_ARM_CORE | %s,\n", reg_size, core_id_to_str(id));
+               break;
+       case KVM_REG_ARM_DEMUX:
+               TEST_ASSERT(!(id & ~(REG_MASK | KVM_REG_ARM_DEMUX_ID_MASK | KVM_REG_ARM_DEMUX_VAL_MASK)),
+                           "Unexpected bits set in DEMUX reg id: 0x%llx", id);
+               printf("\tKVM_REG_ARM64 | %s | KVM_REG_ARM_DEMUX | KVM_REG_ARM_DEMUX_ID_CCSIDR | %lld,\n",
+                      reg_size, id & KVM_REG_ARM_DEMUX_VAL_MASK);
+               break;
+       case KVM_REG_ARM64_SYSREG:
+               op0 = (id & KVM_REG_ARM64_SYSREG_OP0_MASK) >> KVM_REG_ARM64_SYSREG_OP0_SHIFT;
+               op1 = (id & KVM_REG_ARM64_SYSREG_OP1_MASK) >> KVM_REG_ARM64_SYSREG_OP1_SHIFT;
+               crn = (id & KVM_REG_ARM64_SYSREG_CRN_MASK) >> KVM_REG_ARM64_SYSREG_CRN_SHIFT;
+               crm = (id & KVM_REG_ARM64_SYSREG_CRM_MASK) >> KVM_REG_ARM64_SYSREG_CRM_SHIFT;
+               op2 = (id & KVM_REG_ARM64_SYSREG_OP2_MASK) >> KVM_REG_ARM64_SYSREG_OP2_SHIFT;
+               TEST_ASSERT(id == ARM64_SYS_REG(op0, op1, crn, crm, op2),
+                           "Unexpected bits set in SYSREG reg id: 0x%llx", id);
+               printf("\tARM64_SYS_REG(%d, %d, %d, %d, %d),\n", op0, op1, crn, crm, op2);
+               break;
+       case KVM_REG_ARM_FW:
+               TEST_ASSERT(id == KVM_REG_ARM_FW_REG(id & 0xffff),
+                           "Unexpected bits set in FW reg id: 0x%llx", id);
+               printf("\tKVM_REG_ARM_FW_REG(%lld),\n", id & 0xffff);
+               break;
+       case KVM_REG_ARM64_SVE:
+               if (reg_list_sve())
+                       printf("\t%s,\n", sve_id_to_str(id));
+               else
+                       TEST_FAIL("KVM_REG_ARM64_SVE is an unexpected coproc type in reg id: 0x%llx", id);
+               break;
+       default:
+               TEST_FAIL("Unexpected coproc type: 0x%llx in reg id: 0x%llx",
+                         (id & KVM_REG_ARM_COPROC_MASK) >> KVM_REG_ARM_COPROC_SHIFT, id);
+       }
+}
+
+/*
+ * Older kernels listed each 32-bit word of CORE registers separately.
+ * For 64 and 128-bit registers we need to ignore the extra words. We
+ * also need to fixup the sizes, because the older kernels stated all
+ * registers were 64-bit, even when they weren't.
+ */
+static void core_reg_fixup(void)
+{
+       struct kvm_reg_list *tmp;
+       __u64 id, core_off;
+       int i;
+
+       tmp = calloc(1, sizeof(*tmp) + reg_list->n * sizeof(__u64));
+
+       for (i = 0; i < reg_list->n; ++i) {
+               id = reg_list->reg[i];
+
+               if ((id & KVM_REG_ARM_COPROC_MASK) != KVM_REG_ARM_CORE) {
+                       tmp->reg[tmp->n++] = id;
+                       continue;
+               }
+
+               core_off = id & ~REG_MASK;
+
+               switch (core_off) {
+               case 0x52: case 0xd2: case 0xd6:
+                       /*
+                        * These offsets are pointing at padding.
+                        * We need to ignore them too.
+                        */
+                       continue;
+               case KVM_REG_ARM_CORE_REG(fp_regs.vregs[0]) ...
+                    KVM_REG_ARM_CORE_REG(fp_regs.vregs[31]):
+                       if (core_off & 3)
+                               continue;
+                       id &= ~KVM_REG_SIZE_MASK;
+                       id |= KVM_REG_SIZE_U128;
+                       tmp->reg[tmp->n++] = id;
+                       continue;
+               case KVM_REG_ARM_CORE_REG(fp_regs.fpsr):
+               case KVM_REG_ARM_CORE_REG(fp_regs.fpcr):
+                       id &= ~KVM_REG_SIZE_MASK;
+                       id |= KVM_REG_SIZE_U32;
+                       tmp->reg[tmp->n++] = id;
+                       continue;
+               default:
+                       if (core_off & 1)
+                               continue;
+                       tmp->reg[tmp->n++] = id;
+                       break;
+               }
+       }
+
+       free(reg_list);
+       reg_list = tmp;
+}
+
+static void prepare_vcpu_init(struct kvm_vcpu_init *init)
+{
+       if (reg_list_sve())
+               init->features[0] |= 1 << KVM_ARM_VCPU_SVE;
+}
+
+static void finalize_vcpu(struct kvm_vm *vm, uint32_t vcpuid)
+{
+       int feature;
+
+       if (reg_list_sve()) {
+               feature = KVM_ARM_VCPU_SVE;
+               vcpu_ioctl(vm, vcpuid, KVM_ARM_VCPU_FINALIZE, &feature);
+       }
+}
+
+static void check_supported(void)
+{
+       if (reg_list_sve() && !kvm_check_cap(KVM_CAP_ARM_SVE)) {
+               fprintf(stderr, "SVE not available, skipping tests\n");
+               exit(KSFT_SKIP);
+       }
+}
+
+int main(int ac, char **av)
+{
+       struct kvm_vcpu_init init = { .target = -1, };
+       int new_regs = 0, missing_regs = 0, i;
+       int failed_get = 0, failed_set = 0, failed_reject = 0;
+       bool print_list = false, fixup_core_regs = false;
+       struct kvm_vm *vm;
+       __u64 *vec_regs;
+
+       check_supported();
+
+       for (i = 1; i < ac; ++i) {
+               if (strcmp(av[i], "--core-reg-fixup") == 0)
+                       fixup_core_regs = true;
+               else if (strcmp(av[i], "--list") == 0)
+                       print_list = true;
+               else
+                       fprintf(stderr, "Ignoring unknown option: %s\n", av[i]);
+       }
+
+       vm = vm_create(VM_MODE_DEFAULT, DEFAULT_GUEST_PHY_PAGES, O_RDWR);
+       prepare_vcpu_init(&init);
+       aarch64_vcpu_add_default(vm, 0, &init, NULL);
+       finalize_vcpu(vm, 0);
+
+       reg_list = vcpu_get_reg_list(vm, 0);
+
+       if (fixup_core_regs)
+               core_reg_fixup();
+
+       if (print_list) {
+               putchar('\n');
+               for_each_reg(i)
+                       print_reg(reg_list->reg[i]);
+               putchar('\n');
+               return 0;
+       }
+
+       /*
+        * We only test that we can get the register and then write back the
+        * same value. Some registers may allow other values to be written
+        * back, but others only allow some bits to be changed, and at least
+        * for ID registers set will fail if the value does not exactly match
+        * what was returned by get. If registers that allow other values to
+        * be written need to have the other values tested, then we should
+        * create a new set of tests for those in a new independent test
+        * executable.
+        */
+       for_each_reg(i) {
+               uint8_t addr[2048 / 8];
+               struct kvm_one_reg reg = {
+                       .id = reg_list->reg[i],
+                       .addr = (__u64)&addr,
+               };
+               int ret;
+
+               ret = _vcpu_ioctl(vm, 0, KVM_GET_ONE_REG, &reg);
+               if (ret) {
+                       puts("Failed to get ");
+                       print_reg(reg.id);
+                       putchar('\n');
+                       ++failed_get;
+               }
+
+               /* rejects_set registers are rejected after KVM_ARM_VCPU_FINALIZE */
+               if (find_reg(rejects_set, rejects_set_n, reg.id)) {
+                       ret = _vcpu_ioctl(vm, 0, KVM_SET_ONE_REG, &reg);
+                       if (ret != -1 || errno != EPERM) {
+                               printf("Failed to reject (ret=%d, errno=%d) ", ret, errno);
+                               print_reg(reg.id);
+                               putchar('\n');
+                               ++failed_reject;
+                       }
+                       continue;
+               }
+
+               ret = _vcpu_ioctl(vm, 0, KVM_SET_ONE_REG, &reg);
+               if (ret) {
+                       puts("Failed to set ");
+                       print_reg(reg.id);
+                       putchar('\n');
+                       ++failed_set;
+               }
+       }
+
+       if (reg_list_sve()) {
+               blessed_n = base_regs_n + sve_regs_n;
+               vec_regs = sve_regs;
+       } else {
+               blessed_n = base_regs_n + vregs_n;
+               vec_regs = vregs;
+       }
+
+       blessed_reg = calloc(blessed_n, sizeof(__u64));
+       for (i = 0; i < base_regs_n; ++i)
+               blessed_reg[i] = base_regs[i];
+       for (i = 0; i < blessed_n - base_regs_n; ++i)
+               blessed_reg[base_regs_n + i] = vec_regs[i];
+
+       for_each_new_reg(i)
+               ++new_regs;
+
+       for_each_missing_reg(i)
+               ++missing_regs;
+
+       if (new_regs || missing_regs) {
+               printf("Number blessed registers: %5lld\n", blessed_n);
+               printf("Number registers:         %5lld\n", reg_list->n);
+       }
+
+       if (new_regs) {
+               printf("\nThere are %d new registers.\n"
+                      "Consider adding them to the blessed reg "
+                      "list with the following lines:\n\n", new_regs);
+               for_each_new_reg(i)
+                       print_reg(reg_list->reg[i]);
+               putchar('\n');
+       }
+
+       if (missing_regs) {
+               printf("\nThere are %d missing registers.\n"
+                      "The following lines are missing registers:\n\n", missing_regs);
+               for_each_missing_reg(i)
+                       print_reg(blessed_reg[i]);
+               putchar('\n');
+       }
+
+       TEST_ASSERT(!missing_regs && !failed_get && !failed_set && !failed_reject,
+                   "There are %d missing registers; "
+                   "%d registers failed get; %d registers failed set; %d registers failed reject",
+                   missing_regs, failed_get, failed_set, failed_reject);
+
+       return 0;
+}
+
+/*
+ * The current blessed list was primed with the output of kernel version
+ * v4.15 with --core-reg-fixup and then later updated with new registers.
+ */
+static __u64 base_regs[] = {
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[0]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[1]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[2]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[3]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[4]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[5]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[6]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[7]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[8]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[9]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[10]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[11]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[12]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[13]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[14]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[15]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[16]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[17]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[18]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[19]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[20]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[21]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[22]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[23]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[24]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[25]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[26]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[27]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[28]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[29]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[30]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.sp),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.pc),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.pstate),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(sp_el1),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(elr_el1),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(spsr[0]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(spsr[1]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(spsr[2]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(spsr[3]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(spsr[4]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U32 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.fpsr),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U32 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.fpcr),
+       KVM_REG_ARM_FW_REG(0),
+       KVM_REG_ARM_FW_REG(1),
+       KVM_REG_ARM_FW_REG(2),
+       ARM64_SYS_REG(3, 3, 14, 3, 1),  /* CNTV_CTL_EL0 */
+       ARM64_SYS_REG(3, 3, 14, 3, 2),  /* CNTV_CVAL_EL0 */
+       ARM64_SYS_REG(3, 3, 14, 0, 2),
+       ARM64_SYS_REG(3, 0, 0, 0, 0),   /* MIDR_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 0, 6),   /* REVIDR_EL1 */
+       ARM64_SYS_REG(3, 1, 0, 0, 1),   /* CLIDR_EL1 */
+       ARM64_SYS_REG(3, 1, 0, 0, 7),   /* AIDR_EL1 */
+       ARM64_SYS_REG(3, 3, 0, 0, 1),   /* CTR_EL0 */
+       ARM64_SYS_REG(2, 0, 0, 0, 4),
+       ARM64_SYS_REG(2, 0, 0, 0, 5),
+       ARM64_SYS_REG(2, 0, 0, 0, 6),
+       ARM64_SYS_REG(2, 0, 0, 0, 7),
+       ARM64_SYS_REG(2, 0, 0, 1, 4),
+       ARM64_SYS_REG(2, 0, 0, 1, 5),
+       ARM64_SYS_REG(2, 0, 0, 1, 6),
+       ARM64_SYS_REG(2, 0, 0, 1, 7),
+       ARM64_SYS_REG(2, 0, 0, 2, 0),   /* MDCCINT_EL1 */
+       ARM64_SYS_REG(2, 0, 0, 2, 2),   /* MDSCR_EL1 */
+       ARM64_SYS_REG(2, 0, 0, 2, 4),
+       ARM64_SYS_REG(2, 0, 0, 2, 5),
+       ARM64_SYS_REG(2, 0, 0, 2, 6),
+       ARM64_SYS_REG(2, 0, 0, 2, 7),
+       ARM64_SYS_REG(2, 0, 0, 3, 4),
+       ARM64_SYS_REG(2, 0, 0, 3, 5),
+       ARM64_SYS_REG(2, 0, 0, 3, 6),
+       ARM64_SYS_REG(2, 0, 0, 3, 7),
+       ARM64_SYS_REG(2, 0, 0, 4, 4),
+       ARM64_SYS_REG(2, 0, 0, 4, 5),
+       ARM64_SYS_REG(2, 0, 0, 4, 6),
+       ARM64_SYS_REG(2, 0, 0, 4, 7),
+       ARM64_SYS_REG(2, 0, 0, 5, 4),
+       ARM64_SYS_REG(2, 0, 0, 5, 5),
+       ARM64_SYS_REG(2, 0, 0, 5, 6),
+       ARM64_SYS_REG(2, 0, 0, 5, 7),
+       ARM64_SYS_REG(2, 0, 0, 6, 4),
+       ARM64_SYS_REG(2, 0, 0, 6, 5),
+       ARM64_SYS_REG(2, 0, 0, 6, 6),
+       ARM64_SYS_REG(2, 0, 0, 6, 7),
+       ARM64_SYS_REG(2, 0, 0, 7, 4),
+       ARM64_SYS_REG(2, 0, 0, 7, 5),
+       ARM64_SYS_REG(2, 0, 0, 7, 6),
+       ARM64_SYS_REG(2, 0, 0, 7, 7),
+       ARM64_SYS_REG(2, 0, 0, 8, 4),
+       ARM64_SYS_REG(2, 0, 0, 8, 5),
+       ARM64_SYS_REG(2, 0, 0, 8, 6),
+       ARM64_SYS_REG(2, 0, 0, 8, 7),
+       ARM64_SYS_REG(2, 0, 0, 9, 4),
+       ARM64_SYS_REG(2, 0, 0, 9, 5),
+       ARM64_SYS_REG(2, 0, 0, 9, 6),
+       ARM64_SYS_REG(2, 0, 0, 9, 7),
+       ARM64_SYS_REG(2, 0, 0, 10, 4),
+       ARM64_SYS_REG(2, 0, 0, 10, 5),
+       ARM64_SYS_REG(2, 0, 0, 10, 6),
+       ARM64_SYS_REG(2, 0, 0, 10, 7),
+       ARM64_SYS_REG(2, 0, 0, 11, 4),
+       ARM64_SYS_REG(2, 0, 0, 11, 5),
+       ARM64_SYS_REG(2, 0, 0, 11, 6),
+       ARM64_SYS_REG(2, 0, 0, 11, 7),
+       ARM64_SYS_REG(2, 0, 0, 12, 4),
+       ARM64_SYS_REG(2, 0, 0, 12, 5),
+       ARM64_SYS_REG(2, 0, 0, 12, 6),
+       ARM64_SYS_REG(2, 0, 0, 12, 7),
+       ARM64_SYS_REG(2, 0, 0, 13, 4),
+       ARM64_SYS_REG(2, 0, 0, 13, 5),
+       ARM64_SYS_REG(2, 0, 0, 13, 6),
+       ARM64_SYS_REG(2, 0, 0, 13, 7),
+       ARM64_SYS_REG(2, 0, 0, 14, 4),
+       ARM64_SYS_REG(2, 0, 0, 14, 5),
+       ARM64_SYS_REG(2, 0, 0, 14, 6),
+       ARM64_SYS_REG(2, 0, 0, 14, 7),
+       ARM64_SYS_REG(2, 0, 0, 15, 4),
+       ARM64_SYS_REG(2, 0, 0, 15, 5),
+       ARM64_SYS_REG(2, 0, 0, 15, 6),
+       ARM64_SYS_REG(2, 0, 0, 15, 7),
+       ARM64_SYS_REG(2, 4, 0, 7, 0),   /* DBGVCR32_EL2 */
+       ARM64_SYS_REG(3, 0, 0, 0, 5),   /* MPIDR_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 1, 0),   /* ID_PFR0_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 1, 1),   /* ID_PFR1_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 1, 2),   /* ID_DFR0_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 1, 3),   /* ID_AFR0_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 1, 4),   /* ID_MMFR0_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 1, 5),   /* ID_MMFR1_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 1, 6),   /* ID_MMFR2_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 1, 7),   /* ID_MMFR3_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 2, 0),   /* ID_ISAR0_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 2, 1),   /* ID_ISAR1_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 2, 2),   /* ID_ISAR2_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 2, 3),   /* ID_ISAR3_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 2, 4),   /* ID_ISAR4_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 2, 5),   /* ID_ISAR5_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 2, 6),   /* ID_MMFR4_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 2, 7),   /* ID_ISAR6_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 3, 0),   /* MVFR0_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 3, 1),   /* MVFR1_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 3, 2),   /* MVFR2_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 3, 3),
+       ARM64_SYS_REG(3, 0, 0, 3, 4),   /* ID_PFR2_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 3, 5),   /* ID_DFR1_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 3, 6),   /* ID_MMFR5_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 3, 7),
+       ARM64_SYS_REG(3, 0, 0, 4, 0),   /* ID_AA64PFR0_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 4, 1),   /* ID_AA64PFR1_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 4, 2),
+       ARM64_SYS_REG(3, 0, 0, 4, 3),
+       ARM64_SYS_REG(3, 0, 0, 4, 4),   /* ID_AA64ZFR0_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 4, 5),
+       ARM64_SYS_REG(3, 0, 0, 4, 6),
+       ARM64_SYS_REG(3, 0, 0, 4, 7),
+       ARM64_SYS_REG(3, 0, 0, 5, 0),   /* ID_AA64DFR0_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 5, 1),   /* ID_AA64DFR1_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 5, 2),
+       ARM64_SYS_REG(3, 0, 0, 5, 3),
+       ARM64_SYS_REG(3, 0, 0, 5, 4),   /* ID_AA64AFR0_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 5, 5),   /* ID_AA64AFR1_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 5, 6),
+       ARM64_SYS_REG(3, 0, 0, 5, 7),
+       ARM64_SYS_REG(3, 0, 0, 6, 0),   /* ID_AA64ISAR0_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 6, 1),   /* ID_AA64ISAR1_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 6, 2),
+       ARM64_SYS_REG(3, 0, 0, 6, 3),
+       ARM64_SYS_REG(3, 0, 0, 6, 4),
+       ARM64_SYS_REG(3, 0, 0, 6, 5),
+       ARM64_SYS_REG(3, 0, 0, 6, 6),
+       ARM64_SYS_REG(3, 0, 0, 6, 7),
+       ARM64_SYS_REG(3, 0, 0, 7, 0),   /* ID_AA64MMFR0_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 7, 1),   /* ID_AA64MMFR1_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 7, 2),   /* ID_AA64MMFR2_EL1 */
+       ARM64_SYS_REG(3, 0, 0, 7, 3),
+       ARM64_SYS_REG(3, 0, 0, 7, 4),
+       ARM64_SYS_REG(3, 0, 0, 7, 5),
+       ARM64_SYS_REG(3, 0, 0, 7, 6),
+       ARM64_SYS_REG(3, 0, 0, 7, 7),
+       ARM64_SYS_REG(3, 0, 1, 0, 0),   /* SCTLR_EL1 */
+       ARM64_SYS_REG(3, 0, 1, 0, 1),   /* ACTLR_EL1 */
+       ARM64_SYS_REG(3, 0, 1, 0, 2),   /* CPACR_EL1 */
+       ARM64_SYS_REG(3, 0, 2, 0, 0),   /* TTBR0_EL1 */
+       ARM64_SYS_REG(3, 0, 2, 0, 1),   /* TTBR1_EL1 */
+       ARM64_SYS_REG(3, 0, 2, 0, 2),   /* TCR_EL1 */
+       ARM64_SYS_REG(3, 0, 5, 1, 0),   /* AFSR0_EL1 */
+       ARM64_SYS_REG(3, 0, 5, 1, 1),   /* AFSR1_EL1 */
+       ARM64_SYS_REG(3, 0, 5, 2, 0),   /* ESR_EL1 */
+       ARM64_SYS_REG(3, 0, 6, 0, 0),   /* FAR_EL1 */
+       ARM64_SYS_REG(3, 0, 7, 4, 0),   /* PAR_EL1 */
+       ARM64_SYS_REG(3, 0, 9, 14, 1),  /* PMINTENSET_EL1 */
+       ARM64_SYS_REG(3, 0, 9, 14, 2),  /* PMINTENCLR_EL1 */
+       ARM64_SYS_REG(3, 0, 10, 2, 0),  /* MAIR_EL1 */
+       ARM64_SYS_REG(3, 0, 10, 3, 0),  /* AMAIR_EL1 */
+       ARM64_SYS_REG(3, 0, 12, 0, 0),  /* VBAR_EL1 */
+       ARM64_SYS_REG(3, 0, 12, 1, 1),  /* DISR_EL1 */
+       ARM64_SYS_REG(3, 0, 13, 0, 1),  /* CONTEXTIDR_EL1 */
+       ARM64_SYS_REG(3, 0, 13, 0, 4),  /* TPIDR_EL1 */
+       ARM64_SYS_REG(3, 0, 14, 1, 0),  /* CNTKCTL_EL1 */
+       ARM64_SYS_REG(3, 2, 0, 0, 0),   /* CSSELR_EL1 */
+       ARM64_SYS_REG(3, 3, 9, 12, 0),  /* PMCR_EL0 */
+       ARM64_SYS_REG(3, 3, 9, 12, 1),  /* PMCNTENSET_EL0 */
+       ARM64_SYS_REG(3, 3, 9, 12, 2),  /* PMCNTENCLR_EL0 */
+       ARM64_SYS_REG(3, 3, 9, 12, 3),  /* PMOVSCLR_EL0 */
+       ARM64_SYS_REG(3, 3, 9, 12, 4),  /* PMSWINC_EL0 */
+       ARM64_SYS_REG(3, 3, 9, 12, 5),  /* PMSELR_EL0 */
+       ARM64_SYS_REG(3, 3, 9, 13, 0),  /* PMCCNTR_EL0 */
+       ARM64_SYS_REG(3, 3, 9, 14, 0),  /* PMUSERENR_EL0 */
+       ARM64_SYS_REG(3, 3, 9, 14, 3),  /* PMOVSSET_EL0 */
+       ARM64_SYS_REG(3, 3, 13, 0, 2),  /* TPIDR_EL0 */
+       ARM64_SYS_REG(3, 3, 13, 0, 3),  /* TPIDRRO_EL0 */
+       ARM64_SYS_REG(3, 3, 14, 8, 0),
+       ARM64_SYS_REG(3, 3, 14, 8, 1),
+       ARM64_SYS_REG(3, 3, 14, 8, 2),
+       ARM64_SYS_REG(3, 3, 14, 8, 3),
+       ARM64_SYS_REG(3, 3, 14, 8, 4),
+       ARM64_SYS_REG(3, 3, 14, 8, 5),
+       ARM64_SYS_REG(3, 3, 14, 8, 6),
+       ARM64_SYS_REG(3, 3, 14, 8, 7),
+       ARM64_SYS_REG(3, 3, 14, 9, 0),
+       ARM64_SYS_REG(3, 3, 14, 9, 1),
+       ARM64_SYS_REG(3, 3, 14, 9, 2),
+       ARM64_SYS_REG(3, 3, 14, 9, 3),
+       ARM64_SYS_REG(3, 3, 14, 9, 4),
+       ARM64_SYS_REG(3, 3, 14, 9, 5),
+       ARM64_SYS_REG(3, 3, 14, 9, 6),
+       ARM64_SYS_REG(3, 3, 14, 9, 7),
+       ARM64_SYS_REG(3, 3, 14, 10, 0),
+       ARM64_SYS_REG(3, 3, 14, 10, 1),
+       ARM64_SYS_REG(3, 3, 14, 10, 2),
+       ARM64_SYS_REG(3, 3, 14, 10, 3),
+       ARM64_SYS_REG(3, 3, 14, 10, 4),
+       ARM64_SYS_REG(3, 3, 14, 10, 5),
+       ARM64_SYS_REG(3, 3, 14, 10, 6),
+       ARM64_SYS_REG(3, 3, 14, 10, 7),
+       ARM64_SYS_REG(3, 3, 14, 11, 0),
+       ARM64_SYS_REG(3, 3, 14, 11, 1),
+       ARM64_SYS_REG(3, 3, 14, 11, 2),
+       ARM64_SYS_REG(3, 3, 14, 11, 3),
+       ARM64_SYS_REG(3, 3, 14, 11, 4),
+       ARM64_SYS_REG(3, 3, 14, 11, 5),
+       ARM64_SYS_REG(3, 3, 14, 11, 6),
+       ARM64_SYS_REG(3, 3, 14, 12, 0),
+       ARM64_SYS_REG(3, 3, 14, 12, 1),
+       ARM64_SYS_REG(3, 3, 14, 12, 2),
+       ARM64_SYS_REG(3, 3, 14, 12, 3),
+       ARM64_SYS_REG(3, 3, 14, 12, 4),
+       ARM64_SYS_REG(3, 3, 14, 12, 5),
+       ARM64_SYS_REG(3, 3, 14, 12, 6),
+       ARM64_SYS_REG(3, 3, 14, 12, 7),
+       ARM64_SYS_REG(3, 3, 14, 13, 0),
+       ARM64_SYS_REG(3, 3, 14, 13, 1),
+       ARM64_SYS_REG(3, 3, 14, 13, 2),
+       ARM64_SYS_REG(3, 3, 14, 13, 3),
+       ARM64_SYS_REG(3, 3, 14, 13, 4),
+       ARM64_SYS_REG(3, 3, 14, 13, 5),
+       ARM64_SYS_REG(3, 3, 14, 13, 6),
+       ARM64_SYS_REG(3, 3, 14, 13, 7),
+       ARM64_SYS_REG(3, 3, 14, 14, 0),
+       ARM64_SYS_REG(3, 3, 14, 14, 1),
+       ARM64_SYS_REG(3, 3, 14, 14, 2),
+       ARM64_SYS_REG(3, 3, 14, 14, 3),
+       ARM64_SYS_REG(3, 3, 14, 14, 4),
+       ARM64_SYS_REG(3, 3, 14, 14, 5),
+       ARM64_SYS_REG(3, 3, 14, 14, 6),
+       ARM64_SYS_REG(3, 3, 14, 14, 7),
+       ARM64_SYS_REG(3, 3, 14, 15, 0),
+       ARM64_SYS_REG(3, 3, 14, 15, 1),
+       ARM64_SYS_REG(3, 3, 14, 15, 2),
+       ARM64_SYS_REG(3, 3, 14, 15, 3),
+       ARM64_SYS_REG(3, 3, 14, 15, 4),
+       ARM64_SYS_REG(3, 3, 14, 15, 5),
+       ARM64_SYS_REG(3, 3, 14, 15, 6),
+       ARM64_SYS_REG(3, 3, 14, 15, 7), /* PMCCFILTR_EL0 */
+       ARM64_SYS_REG(3, 4, 3, 0, 0),   /* DACR32_EL2 */
+       ARM64_SYS_REG(3, 4, 5, 0, 1),   /* IFSR32_EL2 */
+       ARM64_SYS_REG(3, 4, 5, 3, 0),   /* FPEXC32_EL2 */
+       KVM_REG_ARM64 | KVM_REG_SIZE_U32 | KVM_REG_ARM_DEMUX | KVM_REG_ARM_DEMUX_ID_CCSIDR | 0,
+       KVM_REG_ARM64 | KVM_REG_SIZE_U32 | KVM_REG_ARM_DEMUX | KVM_REG_ARM_DEMUX_ID_CCSIDR | 1,
+       KVM_REG_ARM64 | KVM_REG_SIZE_U32 | KVM_REG_ARM_DEMUX | KVM_REG_ARM_DEMUX_ID_CCSIDR | 2,
+};
+static __u64 base_regs_n = ARRAY_SIZE(base_regs);
+
+static __u64 vregs[] = {
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[0]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[1]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[2]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[3]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[4]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[5]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[6]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[7]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[8]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[9]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[10]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[11]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[12]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[13]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[14]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[15]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[16]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[17]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[18]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[19]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[20]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[21]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[22]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[23]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[24]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[25]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[26]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[27]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[28]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[29]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[30]),
+       KVM_REG_ARM64 | KVM_REG_SIZE_U128 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(fp_regs.vregs[31]),
+};
+static __u64 vregs_n = ARRAY_SIZE(vregs);
+
+static __u64 sve_regs[] = {
+       KVM_REG_ARM64_SVE_VLS,
+       KVM_REG_ARM64_SVE_ZREG(0, 0),
+       KVM_REG_ARM64_SVE_ZREG(1, 0),
+       KVM_REG_ARM64_SVE_ZREG(2, 0),
+       KVM_REG_ARM64_SVE_ZREG(3, 0),
+       KVM_REG_ARM64_SVE_ZREG(4, 0),
+       KVM_REG_ARM64_SVE_ZREG(5, 0),
+       KVM_REG_ARM64_SVE_ZREG(6, 0),
+       KVM_REG_ARM64_SVE_ZREG(7, 0),
+       KVM_REG_ARM64_SVE_ZREG(8, 0),
+       KVM_REG_ARM64_SVE_ZREG(9, 0),
+       KVM_REG_ARM64_SVE_ZREG(10, 0),
+       KVM_REG_ARM64_SVE_ZREG(11, 0),
+       KVM_REG_ARM64_SVE_ZREG(12, 0),
+       KVM_REG_ARM64_SVE_ZREG(13, 0),
+       KVM_REG_ARM64_SVE_ZREG(14, 0),
+       KVM_REG_ARM64_SVE_ZREG(15, 0),
+       KVM_REG_ARM64_SVE_ZREG(16, 0),
+       KVM_REG_ARM64_SVE_ZREG(17, 0),
+       KVM_REG_ARM64_SVE_ZREG(18, 0),
+       KVM_REG_ARM64_SVE_ZREG(19, 0),
+       KVM_REG_ARM64_SVE_ZREG(20, 0),
+       KVM_REG_ARM64_SVE_ZREG(21, 0),
+       KVM_REG_ARM64_SVE_ZREG(22, 0),
+       KVM_REG_ARM64_SVE_ZREG(23, 0),
+       KVM_REG_ARM64_SVE_ZREG(24, 0),
+       KVM_REG_ARM64_SVE_ZREG(25, 0),
+       KVM_REG_ARM64_SVE_ZREG(26, 0),
+       KVM_REG_ARM64_SVE_ZREG(27, 0),
+       KVM_REG_ARM64_SVE_ZREG(28, 0),
+       KVM_REG_ARM64_SVE_ZREG(29, 0),
+       KVM_REG_ARM64_SVE_ZREG(30, 0),
+       KVM_REG_ARM64_SVE_ZREG(31, 0),
+       KVM_REG_ARM64_SVE_PREG(0, 0),
+       KVM_REG_ARM64_SVE_PREG(1, 0),
+       KVM_REG_ARM64_SVE_PREG(2, 0),
+       KVM_REG_ARM64_SVE_PREG(3, 0),
+       KVM_REG_ARM64_SVE_PREG(4, 0),
+       KVM_REG_ARM64_SVE_PREG(5, 0),
+       KVM_REG_ARM64_SVE_PREG(6, 0),
+       KVM_REG_ARM64_SVE_PREG(7, 0),
+       KVM_REG_ARM64_SVE_PREG(8, 0),
+       KVM_REG_ARM64_SVE_PREG(9, 0),
+       KVM_REG_ARM64_SVE_PREG(10, 0),
+       KVM_REG_ARM64_SVE_PREG(11, 0),
+       KVM_REG_ARM64_SVE_PREG(12, 0),
+       KVM_REG_ARM64_SVE_PREG(13, 0),
+       KVM_REG_ARM64_SVE_PREG(14, 0),
+       KVM_REG_ARM64_SVE_PREG(15, 0),
+       KVM_REG_ARM64_SVE_FFR(0),
+       ARM64_SYS_REG(3, 0, 1, 2, 0),   /* ZCR_EL1 */
+};
+static __u64 sve_regs_n = ARRAY_SIZE(sve_regs);
+
+static __u64 rejects_set[] = {
+#ifdef REG_LIST_SVE
+       KVM_REG_ARM64_SVE_VLS,
+#endif
+};
+static __u64 rejects_set_n = ARRAY_SIZE(rejects_set);
diff --git a/tools/testing/selftests/kvm/clear_dirty_log_test.c b/tools/testing/selftests/kvm/clear_dirty_log_test.c
deleted file mode 100644 (file)
index 11672ec..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#define USE_CLEAR_DIRTY_LOG
-#define KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (1 << 0)
-#define KVM_DIRTY_LOG_INITIALLY_SET         (1 << 1)
-#define KVM_DIRTY_LOG_MANUAL_CAPS   (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \
-               KVM_DIRTY_LOG_INITIALLY_SET)
-#include "dirty_log_test.c"
index 360cd3e..3d96a7b 100644 (file)
 #include <linux/bitops.h>
 #include <linux/userfaultfd.h>
 
-#include "test_util.h"
-#include "kvm_util.h"
+#include "perf_test_util.h"
 #include "processor.h"
+#include "test_util.h"
 
 #ifdef __NR_userfaultfd
 
-/* The memory slot index demand page */
-#define TEST_MEM_SLOT_INDEX            1
-
-/* Default guest test virtual memory offset */
-#define DEFAULT_GUEST_TEST_MEM         0xc0000000
-
-#define DEFAULT_GUEST_TEST_MEM_SIZE (1 << 30) /* 1G */
-
 #ifdef PRINT_PER_PAGE_UPDATES
 #define PER_PAGE_DEBUG(...) printf(__VA_ARGS__)
 #else
 #define PER_VCPU_DEBUG(...) _no_printf(__VA_ARGS__)
 #endif
 
-#define MAX_VCPUS 512
-
-/*
- * Guest/Host shared variables. Ensure addr_gva2hva() and/or
- * sync_global_to/from_guest() are used when accessing from
- * the host. READ/WRITE_ONCE() should also be used with anything
- * that may change.
- */
-static uint64_t host_page_size;
-static uint64_t guest_page_size;
-
 static char *guest_data_prototype;
 
-/*
- * Guest physical memory offset of the testing memory slot.
- * This will be set to the topmost valid physical address minus
- * the test memory size.
- */
-static uint64_t guest_test_phys_mem;
-
-/*
- * Guest virtual memory offset of the testing memory slot.
- * Must not conflict with identity mapped test code.
- */
-static uint64_t guest_test_virt_mem = DEFAULT_GUEST_TEST_MEM;
-
-struct vcpu_args {
-       uint64_t gva;
-       uint64_t pages;
-
-       /* Only used by the host userspace part of the vCPU thread */
-       int vcpu_id;
-       struct kvm_vm *vm;
-};
-
-static struct vcpu_args vcpu_args[MAX_VCPUS];
-
-/*
- * Continuously write to the first 8 bytes of each page in the demand paging
- * memory region.
- */
-static void guest_code(uint32_t vcpu_id)
-{
-       uint64_t gva;
-       uint64_t pages;
-       int i;
-
-       /* Make sure vCPU args data structure is not corrupt. */
-       GUEST_ASSERT(vcpu_args[vcpu_id].vcpu_id == vcpu_id);
-
-       gva = vcpu_args[vcpu_id].gva;
-       pages = vcpu_args[vcpu_id].pages;
-
-       for (i = 0; i < pages; i++) {
-               uint64_t addr = gva + (i * guest_page_size);
-
-               addr &= ~(host_page_size - 1);
-               *(uint64_t *)addr = 0x0123456789ABCDEF;
-       }
-
-       GUEST_SYNC(1);
-}
-
 static void *vcpu_worker(void *data)
 {
        int ret;
-       struct vcpu_args *args = (struct vcpu_args *)data;
-       struct kvm_vm *vm = args->vm;
-       int vcpu_id = args->vcpu_id;
+       struct vcpu_args *vcpu_args = (struct vcpu_args *)data;
+       int vcpu_id = vcpu_args->vcpu_id;
+       struct kvm_vm *vm = perf_test_args.vm;
        struct kvm_run *run;
-       struct timespec start, end, ts_diff;
+       struct timespec start;
+       struct timespec ts_diff;
 
        vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
        run = vcpu_state(vm, vcpu_id);
@@ -133,52 +65,18 @@ static void *vcpu_worker(void *data)
                            exit_reason_str(run->exit_reason));
        }
 
-       clock_gettime(CLOCK_MONOTONIC, &end);
-       ts_diff = timespec_sub(end, start);
+       ts_diff = timespec_diff_now(start);
        PER_VCPU_DEBUG("vCPU %d execution time: %ld.%.9lds\n", vcpu_id,
                       ts_diff.tv_sec, ts_diff.tv_nsec);
 
        return NULL;
 }
 
-#define PAGE_SHIFT_4K  12
-#define PTES_PER_4K_PT 512
-
-static struct kvm_vm *create_vm(enum vm_guest_mode mode, int vcpus,
-                               uint64_t vcpu_memory_bytes)
-{
-       struct kvm_vm *vm;
-       uint64_t pages = DEFAULT_GUEST_PHY_PAGES;
-
-       /* Account for a few pages per-vCPU for stacks */
-       pages += DEFAULT_STACK_PGS * vcpus;
-
-       /*
-        * Reserve twice the ammount of memory needed to map the test region and
-        * the page table / stacks region, at 4k, for page tables. Do the
-        * calculation with 4K page size: the smallest of all archs. (e.g., 64K
-        * page size guest will need even less memory for page tables).
-        */
-       pages += (2 * pages) / PTES_PER_4K_PT;
-       pages += ((2 * vcpus * vcpu_memory_bytes) >> PAGE_SHIFT_4K) /
-                PTES_PER_4K_PT;
-       pages = vm_adjust_num_guest_pages(mode, pages);
-
-       pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode));
-
-       vm = _vm_create(mode, pages, O_RDWR);
-       kvm_vm_elf_load(vm, program_invocation_name, 0, 0);
-#ifdef __x86_64__
-       vm_create_irqchip(vm);
-#endif
-       return vm;
-}
-
 static int handle_uffd_page_request(int uffd, uint64_t addr)
 {
        pid_t tid;
        struct timespec start;
-       struct timespec end;
+       struct timespec ts_diff;
        struct uffdio_copy copy;
        int r;
 
@@ -186,7 +84,7 @@ static int handle_uffd_page_request(int uffd, uint64_t addr)
 
        copy.src = (uint64_t)guest_data_prototype;
        copy.dst = addr;
-       copy.len = host_page_size;
+       copy.len = perf_test_args.host_page_size;
        copy.mode = 0;
 
        clock_gettime(CLOCK_MONOTONIC, &start);
@@ -198,12 +96,12 @@ static int handle_uffd_page_request(int uffd, uint64_t addr)
                return r;
        }
 
-       clock_gettime(CLOCK_MONOTONIC, &end);
+       ts_diff = timespec_diff_now(start);
 
        PER_PAGE_DEBUG("UFFDIO_COPY %d \t%ld ns\n", tid,
-                      timespec_to_ns(timespec_sub(end, start)));
+                      timespec_to_ns(ts_diff));
        PER_PAGE_DEBUG("Paged in %ld bytes at 0x%lx from thread %d\n",
-                      host_page_size, addr, tid);
+                      perf_test_args.host_page_size, addr, tid);
 
        return 0;
 }
@@ -223,7 +121,8 @@ static void *uffd_handler_thread_fn(void *arg)
        int pipefd = uffd_args->pipefd;
        useconds_t delay = uffd_args->delay;
        int64_t pages = 0;
-       struct timespec start, end, ts_diff;
+       struct timespec start;
+       struct timespec ts_diff;
 
        clock_gettime(CLOCK_MONOTONIC, &start);
        while (!quit_uffd_thread) {
@@ -292,8 +191,7 @@ static void *uffd_handler_thread_fn(void *arg)
                pages++;
        }
 
-       clock_gettime(CLOCK_MONOTONIC, &end);
-       ts_diff = timespec_sub(end, start);
+       ts_diff = timespec_diff_now(start);
        PER_VCPU_DEBUG("userfaulted %ld pages over %ld.%.9lds. (%f/sec)\n",
                       pages, ts_diff.tv_sec, ts_diff.tv_nsec,
                       pages / ((double)ts_diff.tv_sec + (double)ts_diff.tv_nsec / 100000000.0));
@@ -351,99 +249,54 @@ static int setup_demand_paging(struct kvm_vm *vm,
 }
 
 static void run_test(enum vm_guest_mode mode, bool use_uffd,
-                    useconds_t uffd_delay, int vcpus,
-                    uint64_t vcpu_memory_bytes)
+                    useconds_t uffd_delay)
 {
        pthread_t *vcpu_threads;
        pthread_t *uffd_handler_threads = NULL;
        struct uffd_handler_args *uffd_args = NULL;
-       struct timespec start, end, ts_diff;
+       struct timespec start;
+       struct timespec ts_diff;
        int *pipefds = NULL;
        struct kvm_vm *vm;
-       uint64_t guest_num_pages;
        int vcpu_id;
        int r;
 
-       vm = create_vm(mode, vcpus, vcpu_memory_bytes);
-
-       guest_page_size = vm_get_page_size(vm);
-
-       TEST_ASSERT(vcpu_memory_bytes % guest_page_size == 0,
-                   "Guest memory size is not guest page size aligned.");
-
-       guest_num_pages = (vcpus * vcpu_memory_bytes) / guest_page_size;
-       guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages);
-
-       /*
-        * If there should be more memory in the guest test region than there
-        * can be pages in the guest, it will definitely cause problems.
-        */
-       TEST_ASSERT(guest_num_pages < vm_get_max_gfn(vm),
-                   "Requested more guest memory than address space allows.\n"
-                   "    guest pages: %lx max gfn: %x vcpus: %d wss: %lx]\n",
-                   guest_num_pages, vm_get_max_gfn(vm), vcpus,
-                   vcpu_memory_bytes);
-
-       host_page_size = getpagesize();
-       TEST_ASSERT(vcpu_memory_bytes % host_page_size == 0,
-                   "Guest memory size is not host page size aligned.");
+       vm = create_vm(mode, nr_vcpus, guest_percpu_mem_size);
 
-       guest_test_phys_mem = (vm_get_max_gfn(vm) - guest_num_pages) *
-                             guest_page_size;
-       guest_test_phys_mem &= ~(host_page_size - 1);
+       perf_test_args.wr_fract = 1;
 
-#ifdef __s390x__
-       /* Align to 1M (segment size) */
-       guest_test_phys_mem &= ~((1 << 20) - 1);
-#endif
-
-       pr_info("guest physical test memory offset: 0x%lx\n", guest_test_phys_mem);
-
-       /* Add an extra memory slot for testing demand paging */
-       vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS,
-                                   guest_test_phys_mem,
-                                   TEST_MEM_SLOT_INDEX,
-                                   guest_num_pages, 0);
-
-       /* Do mapping for the demand paging memory slot */
-       virt_map(vm, guest_test_virt_mem, guest_test_phys_mem, guest_num_pages, 0);
-
-       ucall_init(vm, NULL);
-
-       guest_data_prototype = malloc(host_page_size);
+       guest_data_prototype = malloc(perf_test_args.host_page_size);
        TEST_ASSERT(guest_data_prototype,
                    "Failed to allocate buffer for guest data pattern");
-       memset(guest_data_prototype, 0xAB, host_page_size);
+       memset(guest_data_prototype, 0xAB, perf_test_args.host_page_size);
 
-       vcpu_threads = malloc(vcpus * sizeof(*vcpu_threads));
+       vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
        TEST_ASSERT(vcpu_threads, "Memory allocation failed");
 
+       add_vcpus(vm, nr_vcpus, guest_percpu_mem_size);
+
        if (use_uffd) {
                uffd_handler_threads =
-                       malloc(vcpus * sizeof(*uffd_handler_threads));
+                       malloc(nr_vcpus * sizeof(*uffd_handler_threads));
                TEST_ASSERT(uffd_handler_threads, "Memory allocation failed");
 
-               uffd_args = malloc(vcpus * sizeof(*uffd_args));
+               uffd_args = malloc(nr_vcpus * sizeof(*uffd_args));
                TEST_ASSERT(uffd_args, "Memory allocation failed");
 
-               pipefds = malloc(sizeof(int) * vcpus * 2);
+               pipefds = malloc(sizeof(int) * nr_vcpus * 2);
                TEST_ASSERT(pipefds, "Unable to allocate memory for pipefd");
-       }
-
-       for (vcpu_id = 0; vcpu_id < vcpus; vcpu_id++) {
-               vm_paddr_t vcpu_gpa;
-               void *vcpu_hva;
 
-               vm_vcpu_add_default(vm, vcpu_id, guest_code);
+               for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) {
+                       vm_paddr_t vcpu_gpa;
+                       void *vcpu_hva;
 
-               vcpu_gpa = guest_test_phys_mem + (vcpu_id * vcpu_memory_bytes);
-               PER_VCPU_DEBUG("Added VCPU %d with test mem gpa [%lx, %lx)\n",
-                              vcpu_id, vcpu_gpa, vcpu_gpa + vcpu_memory_bytes);
+                       vcpu_gpa = guest_test_phys_mem + (vcpu_id * guest_percpu_mem_size);
+                       PER_VCPU_DEBUG("Added VCPU %d with test mem gpa [%lx, %lx)\n",
+                                      vcpu_id, vcpu_gpa, vcpu_gpa + guest_percpu_mem_size);
 
-               /* Cache the HVA pointer of the region */
-               vcpu_hva = addr_gpa2hva(vm, vcpu_gpa);
+                       /* Cache the HVA pointer of the region */
+                       vcpu_hva = addr_gpa2hva(vm, vcpu_gpa);
 
-               if (use_uffd) {
                        /*
                         * Set up user fault fd to handle demand paging
                         * requests.
@@ -456,53 +309,41 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
                                                &uffd_handler_threads[vcpu_id],
                                                pipefds[vcpu_id * 2],
                                                uffd_delay, &uffd_args[vcpu_id],
-                                               vcpu_hva, vcpu_memory_bytes);
+                                               vcpu_hva, guest_percpu_mem_size);
                        if (r < 0)
                                exit(-r);
                }
-
-#ifdef __x86_64__
-               vcpu_set_cpuid(vm, vcpu_id, kvm_get_supported_cpuid());
-#endif
-
-               vcpu_args[vcpu_id].vm = vm;
-               vcpu_args[vcpu_id].vcpu_id = vcpu_id;
-               vcpu_args[vcpu_id].gva = guest_test_virt_mem +
-                                        (vcpu_id * vcpu_memory_bytes);
-               vcpu_args[vcpu_id].pages = vcpu_memory_bytes / guest_page_size;
        }
 
        /* Export the shared variables to the guest */
-       sync_global_to_guest(vm, host_page_size);
-       sync_global_to_guest(vm, guest_page_size);
-       sync_global_to_guest(vm, vcpu_args);
+       sync_global_to_guest(vm, perf_test_args);
 
        pr_info("Finished creating vCPUs and starting uffd threads\n");
 
        clock_gettime(CLOCK_MONOTONIC, &start);
 
-       for (vcpu_id = 0; vcpu_id < vcpus; vcpu_id++) {
+       for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) {
                pthread_create(&vcpu_threads[vcpu_id], NULL, vcpu_worker,
-                              &vcpu_args[vcpu_id]);
+                              &perf_test_args.vcpu_args[vcpu_id]);
        }
 
        pr_info("Started all vCPUs\n");
 
        /* Wait for the vcpu threads to quit */
-       for (vcpu_id = 0; vcpu_id < vcpus; vcpu_id++) {
+       for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) {
                pthread_join(vcpu_threads[vcpu_id], NULL);
                PER_VCPU_DEBUG("Joined thread for vCPU %d\n", vcpu_id);
        }
 
-       pr_info("All vCPU threads joined\n");
+       ts_diff = timespec_diff_now(start);
 
-       clock_gettime(CLOCK_MONOTONIC, &end);
+       pr_info("All vCPU threads joined\n");
 
        if (use_uffd) {
                char c;
 
                /* Tell the user fault fd handler threads to quit */
-               for (vcpu_id = 0; vcpu_id < vcpus; vcpu_id++) {
+               for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) {
                        r = write(pipefds[vcpu_id * 2 + 1], &c, 1);
                        TEST_ASSERT(r == 1, "Unable to write to pipefd");
 
@@ -510,11 +351,11 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
                }
        }
 
-       ts_diff = timespec_sub(end, start);
        pr_info("Total guest execution time: %ld.%.9lds\n",
                ts_diff.tv_sec, ts_diff.tv_nsec);
        pr_info("Overall demand paging rate: %f pgs/sec\n",
-               guest_num_pages / ((double)ts_diff.tv_sec + (double)ts_diff.tv_nsec / 100000000.0));
+               perf_test_args.vcpu_args[0].pages * nr_vcpus /
+               ((double)ts_diff.tv_sec + (double)ts_diff.tv_nsec / 100000000.0));
 
        ucall_uninit(vm);
        kvm_vm_free(vm);
@@ -568,9 +409,8 @@ static void help(char *name)
 
 int main(int argc, char *argv[])
 {
+       int max_vcpus = kvm_check_cap(KVM_CAP_MAX_VCPUS);
        bool mode_selected = false;
-       uint64_t vcpu_memory_bytes = DEFAULT_GUEST_TEST_MEM_SIZE;
-       int vcpus = 1;
        unsigned int mode;
        int opt, i;
        bool use_uffd = false;
@@ -619,15 +459,12 @@ int main(int argc, char *argv[])
                                    "A negative UFFD delay is not supported.");
                        break;
                case 'b':
-                       vcpu_memory_bytes = parse_size(optarg);
+                       guest_percpu_mem_size = parse_size(optarg);
                        break;
                case 'v':
-                       vcpus = atoi(optarg);
-                       TEST_ASSERT(vcpus > 0,
-                                   "Must have a positive number of vCPUs");
-                       TEST_ASSERT(vcpus <= MAX_VCPUS,
-                                   "This test does not currently support\n"
-                                   "more than %d vCPUs.", MAX_VCPUS);
+                       nr_vcpus = atoi(optarg);
+                       TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <= max_vcpus,
+                                   "Invalid number of vcpus, must be between 1 and %d", max_vcpus);
                        break;
                case 'h':
                default:
@@ -642,7 +479,7 @@ int main(int argc, char *argv[])
                TEST_ASSERT(guest_modes[i].supported,
                            "Guest mode ID %d (%s) not supported.",
                            i, vm_guest_mode_string(i));
-               run_test(i, use_uffd, uffd_delay, vcpus, vcpu_memory_bytes);
+               run_test(i, use_uffd, uffd_delay);
        }
 
        return 0;
diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c
new file mode 100644 (file)
index 0000000..85c9b8f
--- /dev/null
@@ -0,0 +1,376 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * KVM dirty page logging performance test
+ *
+ * Based on dirty_log_test.c
+ *
+ * Copyright (C) 2018, Red Hat, Inc.
+ * Copyright (C) 2020, Google, Inc.
+ */
+
+#define _GNU_SOURCE /* for program_invocation_name */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+#include <pthread.h>
+#include <linux/bitmap.h>
+#include <linux/bitops.h>
+
+#include "kvm_util.h"
+#include "perf_test_util.h"
+#include "processor.h"
+#include "test_util.h"
+
+/* How many host loops to run by default (one KVM_GET_DIRTY_LOG for each loop)*/
+#define TEST_HOST_LOOP_N               2UL
+
+/* Host variables */
+static bool host_quit;
+static uint64_t iteration;
+static uint64_t vcpu_last_completed_iteration[MAX_VCPUS];
+
+static void *vcpu_worker(void *data)
+{
+       int ret;
+       struct kvm_vm *vm = perf_test_args.vm;
+       uint64_t pages_count = 0;
+       struct kvm_run *run;
+       struct timespec start;
+       struct timespec ts_diff;
+       struct timespec total = (struct timespec){0};
+       struct timespec avg;
+       struct vcpu_args *vcpu_args = (struct vcpu_args *)data;
+       int vcpu_id = vcpu_args->vcpu_id;
+
+       vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
+       run = vcpu_state(vm, vcpu_id);
+
+       while (!READ_ONCE(host_quit)) {
+               uint64_t current_iteration = READ_ONCE(iteration);
+
+               clock_gettime(CLOCK_MONOTONIC, &start);
+               ret = _vcpu_run(vm, vcpu_id);
+               ts_diff = timespec_diff_now(start);
+
+               TEST_ASSERT(ret == 0, "vcpu_run failed: %d\n", ret);
+               TEST_ASSERT(get_ucall(vm, vcpu_id, NULL) == UCALL_SYNC,
+                           "Invalid guest sync status: exit_reason=%s\n",
+                           exit_reason_str(run->exit_reason));
+
+               pr_debug("Got sync event from vCPU %d\n", vcpu_id);
+               vcpu_last_completed_iteration[vcpu_id] = current_iteration;
+               pr_debug("vCPU %d updated last completed iteration to %lu\n",
+                        vcpu_id, vcpu_last_completed_iteration[vcpu_id]);
+
+               if (current_iteration) {
+                       pages_count += vcpu_args->pages;
+                       total = timespec_add(total, ts_diff);
+                       pr_debug("vCPU %d iteration %lu dirty memory time: %ld.%.9lds\n",
+                               vcpu_id, current_iteration, ts_diff.tv_sec,
+                               ts_diff.tv_nsec);
+               } else {
+                       pr_debug("vCPU %d iteration %lu populate memory time: %ld.%.9lds\n",
+                               vcpu_id, current_iteration, ts_diff.tv_sec,
+                               ts_diff.tv_nsec);
+               }
+
+               while (current_iteration == READ_ONCE(iteration) &&
+                      !READ_ONCE(host_quit)) {}
+       }
+
+       avg = timespec_div(total, vcpu_last_completed_iteration[vcpu_id]);
+       pr_debug("\nvCPU %d dirtied 0x%lx pages over %lu iterations in %ld.%.9lds. (Avg %ld.%.9lds/iteration)\n",
+               vcpu_id, pages_count, vcpu_last_completed_iteration[vcpu_id],
+               total.tv_sec, total.tv_nsec, avg.tv_sec, avg.tv_nsec);
+
+       return NULL;
+}
+
+#ifdef USE_CLEAR_DIRTY_LOG
+static u64 dirty_log_manual_caps;
+#endif
+
+static void run_test(enum vm_guest_mode mode, unsigned long iterations,
+                    uint64_t phys_offset, int wr_fract)
+{
+       pthread_t *vcpu_threads;
+       struct kvm_vm *vm;
+       unsigned long *bmap;
+       uint64_t guest_num_pages;
+       uint64_t host_num_pages;
+       int vcpu_id;
+       struct timespec start;
+       struct timespec ts_diff;
+       struct timespec get_dirty_log_total = (struct timespec){0};
+       struct timespec vcpu_dirty_total = (struct timespec){0};
+       struct timespec avg;
+#ifdef USE_CLEAR_DIRTY_LOG
+       struct kvm_enable_cap cap = {};
+       struct timespec clear_dirty_log_total = (struct timespec){0};
+#endif
+
+       vm = create_vm(mode, nr_vcpus, guest_percpu_mem_size);
+
+       perf_test_args.wr_fract = wr_fract;
+
+       guest_num_pages = (nr_vcpus * guest_percpu_mem_size) >> vm_get_page_shift(vm);
+       guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages);
+       host_num_pages = vm_num_host_pages(mode, guest_num_pages);
+       bmap = bitmap_alloc(host_num_pages);
+
+#ifdef USE_CLEAR_DIRTY_LOG
+       cap.cap = KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2;
+       cap.args[0] = dirty_log_manual_caps;
+       vm_enable_cap(vm, &cap);
+#endif
+
+       vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
+       TEST_ASSERT(vcpu_threads, "Memory allocation failed");
+
+       add_vcpus(vm, nr_vcpus, guest_percpu_mem_size);
+
+       sync_global_to_guest(vm, perf_test_args);
+
+       /* Start the iterations */
+       iteration = 0;
+       host_quit = false;
+
+       clock_gettime(CLOCK_MONOTONIC, &start);
+       for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) {
+               pthread_create(&vcpu_threads[vcpu_id], NULL, vcpu_worker,
+                              &perf_test_args.vcpu_args[vcpu_id]);
+       }
+
+       /* Allow the vCPU to populate memory */
+       pr_debug("Starting iteration %lu - Populating\n", iteration);
+       while (READ_ONCE(vcpu_last_completed_iteration[vcpu_id]) != iteration)
+               pr_debug("Waiting for vcpu_last_completed_iteration == %lu\n",
+                       iteration);
+
+       ts_diff = timespec_diff_now(start);
+       pr_info("Populate memory time: %ld.%.9lds\n",
+               ts_diff.tv_sec, ts_diff.tv_nsec);
+
+       /* Enable dirty logging */
+       clock_gettime(CLOCK_MONOTONIC, &start);
+       vm_mem_region_set_flags(vm, TEST_MEM_SLOT_INDEX,
+                               KVM_MEM_LOG_DIRTY_PAGES);
+       ts_diff = timespec_diff_now(start);
+       pr_info("Enabling dirty logging time: %ld.%.9lds\n\n",
+               ts_diff.tv_sec, ts_diff.tv_nsec);
+
+       while (iteration < iterations) {
+               /*
+                * Incrementing the iteration number will start the vCPUs
+                * dirtying memory again.
+                */
+               clock_gettime(CLOCK_MONOTONIC, &start);
+               iteration++;
+
+               pr_debug("Starting iteration %lu\n", iteration);
+               for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) {
+                       while (READ_ONCE(vcpu_last_completed_iteration[vcpu_id]) != iteration)
+                               pr_debug("Waiting for vCPU %d vcpu_last_completed_iteration == %lu\n",
+                                        vcpu_id, iteration);
+               }
+
+               ts_diff = timespec_diff_now(start);
+               vcpu_dirty_total = timespec_add(vcpu_dirty_total, ts_diff);
+               pr_info("Iteration %lu dirty memory time: %ld.%.9lds\n",
+                       iteration, ts_diff.tv_sec, ts_diff.tv_nsec);
+
+               clock_gettime(CLOCK_MONOTONIC, &start);
+               kvm_vm_get_dirty_log(vm, TEST_MEM_SLOT_INDEX, bmap);
+
+               ts_diff = timespec_diff_now(start);
+               get_dirty_log_total = timespec_add(get_dirty_log_total,
+                                                  ts_diff);
+               pr_info("Iteration %lu get dirty log time: %ld.%.9lds\n",
+                       iteration, ts_diff.tv_sec, ts_diff.tv_nsec);
+
+#ifdef USE_CLEAR_DIRTY_LOG
+               clock_gettime(CLOCK_MONOTONIC, &start);
+               kvm_vm_clear_dirty_log(vm, TEST_MEM_SLOT_INDEX, bmap, 0,
+                                      host_num_pages);
+
+               ts_diff = timespec_diff_now(start);
+               clear_dirty_log_total = timespec_add(clear_dirty_log_total,
+                                                    ts_diff);
+               pr_info("Iteration %lu clear dirty log time: %ld.%.9lds\n",
+                       iteration, ts_diff.tv_sec, ts_diff.tv_nsec);
+#endif
+       }
+
+       /* Tell the vcpu thread to quit */
+       host_quit = true;
+       for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++)
+               pthread_join(vcpu_threads[vcpu_id], NULL);
+
+       /* Disable dirty logging */
+       clock_gettime(CLOCK_MONOTONIC, &start);
+       vm_mem_region_set_flags(vm, TEST_MEM_SLOT_INDEX, 0);
+       ts_diff = timespec_diff_now(start);
+       pr_info("Disabling dirty logging time: %ld.%.9lds\n",
+               ts_diff.tv_sec, ts_diff.tv_nsec);
+
+       avg = timespec_div(get_dirty_log_total, iterations);
+       pr_info("Get dirty log over %lu iterations took %ld.%.9lds. (Avg %ld.%.9lds/iteration)\n",
+               iterations, get_dirty_log_total.tv_sec,
+               get_dirty_log_total.tv_nsec, avg.tv_sec, avg.tv_nsec);
+
+#ifdef USE_CLEAR_DIRTY_LOG
+       avg = timespec_div(clear_dirty_log_total, iterations);
+       pr_info("Clear dirty log over %lu iterations took %ld.%.9lds. (Avg %ld.%.9lds/iteration)\n",
+               iterations, clear_dirty_log_total.tv_sec,
+               clear_dirty_log_total.tv_nsec, avg.tv_sec, avg.tv_nsec);
+#endif
+
+       free(bmap);
+       free(vcpu_threads);
+       ucall_uninit(vm);
+       kvm_vm_free(vm);
+}
+
+struct guest_mode {
+       bool supported;
+       bool enabled;
+};
+static struct guest_mode guest_modes[NUM_VM_MODES];
+
+#define guest_mode_init(mode, supported, enabled) ({ \
+       guest_modes[mode] = (struct guest_mode){ supported, enabled }; \
+})
+
+static void help(char *name)
+{
+       int i;
+
+       puts("");
+       printf("usage: %s [-h] [-i iterations] [-p offset] "
+              "[-m mode] [-b vcpu bytes] [-v vcpus]\n", name);
+       puts("");
+       printf(" -i: specify iteration counts (default: %"PRIu64")\n",
+              TEST_HOST_LOOP_N);
+       printf(" -p: specify guest physical test memory offset\n"
+              "     Warning: a low offset can conflict with the loaded test code.\n");
+       printf(" -m: specify the guest mode ID to test "
+              "(default: test all supported modes)\n"
+              "     This option may be used multiple times.\n"
+              "     Guest mode IDs:\n");
+       for (i = 0; i < NUM_VM_MODES; ++i) {
+               printf("         %d:    %s%s\n", i, vm_guest_mode_string(i),
+                      guest_modes[i].supported ? " (supported)" : "");
+       }
+       printf(" -b: specify the size of the memory region which should be\n"
+              "     dirtied by each vCPU. e.g. 10M or 3G.\n"
+              "     (default: 1G)\n");
+       printf(" -f: specify the fraction of pages which should be written to\n"
+              "     as opposed to simply read, in the form\n"
+              "     1/<fraction of pages to write>.\n"
+              "     (default: 1 i.e. all pages are written to.)\n");
+       printf(" -v: specify the number of vCPUs to run.\n");
+       puts("");
+       exit(0);
+}
+
+int main(int argc, char *argv[])
+{
+       unsigned long iterations = TEST_HOST_LOOP_N;
+       bool mode_selected = false;
+       uint64_t phys_offset = 0;
+       unsigned int mode;
+       int opt, i;
+       int wr_fract = 1;
+
+#ifdef USE_CLEAR_DIRTY_LOG
+       dirty_log_manual_caps =
+               kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2);
+       if (!dirty_log_manual_caps) {
+               print_skip("KVM_CLEAR_DIRTY_LOG not available");
+               exit(KSFT_SKIP);
+       }
+       dirty_log_manual_caps &= (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE |
+                                 KVM_DIRTY_LOG_INITIALLY_SET);
+#endif
+
+#ifdef __x86_64__
+       guest_mode_init(VM_MODE_PXXV48_4K, true, true);
+#endif
+#ifdef __aarch64__
+       guest_mode_init(VM_MODE_P40V48_4K, true, true);
+       guest_mode_init(VM_MODE_P40V48_64K, true, true);
+
+       {
+               unsigned int limit = kvm_check_cap(KVM_CAP_ARM_VM_IPA_SIZE);
+
+               if (limit >= 52)
+                       guest_mode_init(VM_MODE_P52V48_64K, true, true);
+               if (limit >= 48) {
+                       guest_mode_init(VM_MODE_P48V48_4K, true, true);
+                       guest_mode_init(VM_MODE_P48V48_64K, true, true);
+               }
+       }
+#endif
+#ifdef __s390x__
+       guest_mode_init(VM_MODE_P40V48_4K, true, true);
+#endif
+
+       while ((opt = getopt(argc, argv, "hi:p:m:b:f:v:")) != -1) {
+               switch (opt) {
+               case 'i':
+                       iterations = strtol(optarg, NULL, 10);
+                       break;
+               case 'p':
+                       phys_offset = strtoull(optarg, NULL, 0);
+                       break;
+               case 'm':
+                       if (!mode_selected) {
+                               for (i = 0; i < NUM_VM_MODES; ++i)
+                                       guest_modes[i].enabled = false;
+                               mode_selected = true;
+                       }
+                       mode = strtoul(optarg, NULL, 10);
+                       TEST_ASSERT(mode < NUM_VM_MODES,
+                                   "Guest mode ID %d too big", mode);
+                       guest_modes[mode].enabled = true;
+                       break;
+               case 'b':
+                       guest_percpu_mem_size = parse_size(optarg);
+                       break;
+               case 'f':
+                       wr_fract = atoi(optarg);
+                       TEST_ASSERT(wr_fract >= 1,
+                                   "Write fraction cannot be less than one");
+                       break;
+               case 'v':
+                       nr_vcpus = atoi(optarg);
+                       TEST_ASSERT(nr_vcpus > 0,
+                                   "Must have a positive number of vCPUs");
+                       TEST_ASSERT(nr_vcpus <= MAX_VCPUS,
+                                   "This test does not currently support\n"
+                                   "more than %d vCPUs.", MAX_VCPUS);
+                       break;
+               case 'h':
+               default:
+                       help(argv[0]);
+                       break;
+               }
+       }
+
+       TEST_ASSERT(iterations >= 2, "The test should have at least two iterations");
+
+       pr_info("Test iterations: %"PRIu64"\n", iterations);
+
+       for (i = 0; i < NUM_VM_MODES; ++i) {
+               if (!guest_modes[i].enabled)
+                       continue;
+               TEST_ASSERT(guest_modes[i].supported,
+                           "Guest mode ID %d (%s) not supported.",
+                           i, vm_guest_mode_string(i));
+               run_test(i, iterations, phys_offset, wr_fract);
+       }
+
+       return 0;
+}
index 752ec15..54da9cc 100644 (file)
@@ -128,6 +128,78 @@ static uint64_t host_dirty_count;
 static uint64_t host_clear_count;
 static uint64_t host_track_next_count;
 
+enum log_mode_t {
+       /* Only use KVM_GET_DIRTY_LOG for logging */
+       LOG_MODE_DIRTY_LOG = 0,
+
+       /* Use both KVM_[GET|CLEAR]_DIRTY_LOG for logging */
+       LOG_MODE_CLEAR_LOG = 1,
+
+       LOG_MODE_NUM,
+
+       /* Run all supported modes */
+       LOG_MODE_ALL = LOG_MODE_NUM,
+};
+
+/* Mode of logging to test.  Default is to run all supported modes */
+static enum log_mode_t host_log_mode_option = LOG_MODE_ALL;
+/* Logging mode for current run */
+static enum log_mode_t host_log_mode;
+
+static bool clear_log_supported(void)
+{
+       return kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2);
+}
+
+static void clear_log_create_vm_done(struct kvm_vm *vm)
+{
+       struct kvm_enable_cap cap = {};
+       u64 manual_caps;
+
+       manual_caps = kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2);
+       TEST_ASSERT(manual_caps, "MANUAL_CAPS is zero!");
+       manual_caps &= (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE |
+                       KVM_DIRTY_LOG_INITIALLY_SET);
+       cap.cap = KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2;
+       cap.args[0] = manual_caps;
+       vm_enable_cap(vm, &cap);
+}
+
+static void dirty_log_collect_dirty_pages(struct kvm_vm *vm, int slot,
+                                         void *bitmap, uint32_t num_pages)
+{
+       kvm_vm_get_dirty_log(vm, slot, bitmap);
+}
+
+static void clear_log_collect_dirty_pages(struct kvm_vm *vm, int slot,
+                                         void *bitmap, uint32_t num_pages)
+{
+       kvm_vm_get_dirty_log(vm, slot, bitmap);
+       kvm_vm_clear_dirty_log(vm, slot, bitmap, 0, num_pages);
+}
+
+struct log_mode {
+       const char *name;
+       /* Return true if this mode is supported, otherwise false */
+       bool (*supported)(void);
+       /* Hook when the vm creation is done (before vcpu creation) */
+       void (*create_vm_done)(struct kvm_vm *vm);
+       /* Hook to collect the dirty pages into the bitmap provided */
+       void (*collect_dirty_pages) (struct kvm_vm *vm, int slot,
+                                    void *bitmap, uint32_t num_pages);
+} log_modes[LOG_MODE_NUM] = {
+       {
+               .name = "dirty-log",
+               .collect_dirty_pages = dirty_log_collect_dirty_pages,
+       },
+       {
+               .name = "clear-log",
+               .supported = clear_log_supported,
+               .create_vm_done = clear_log_create_vm_done,
+               .collect_dirty_pages = clear_log_collect_dirty_pages,
+       },
+};
+
 /*
  * We use this bitmap to track some pages that should have its dirty
  * bit set in the _next_ iteration.  For example, if we detected the
@@ -137,6 +209,44 @@ static uint64_t host_track_next_count;
  */
 static unsigned long *host_bmap_track;
 
+static void log_modes_dump(void)
+{
+       int i;
+
+       printf("all");
+       for (i = 0; i < LOG_MODE_NUM; i++)
+               printf(", %s", log_modes[i].name);
+       printf("\n");
+}
+
+static bool log_mode_supported(void)
+{
+       struct log_mode *mode = &log_modes[host_log_mode];
+
+       if (mode->supported)
+               return mode->supported();
+
+       return true;
+}
+
+static void log_mode_create_vm_done(struct kvm_vm *vm)
+{
+       struct log_mode *mode = &log_modes[host_log_mode];
+
+       if (mode->create_vm_done)
+               mode->create_vm_done(vm);
+}
+
+static void log_mode_collect_dirty_pages(struct kvm_vm *vm, int slot,
+                                        void *bitmap, uint32_t num_pages)
+{
+       struct log_mode *mode = &log_modes[host_log_mode];
+
+       TEST_ASSERT(mode->collect_dirty_pages != NULL,
+                   "collect_dirty_pages() is required for any log mode!");
+       mode->collect_dirty_pages(vm, slot, bitmap, num_pages);
+}
+
 static void generate_random_array(uint64_t *guest_array, uint64_t size)
 {
        uint64_t i;
@@ -195,7 +305,7 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap)
                                    page);
                }
 
-               if (test_bit_le(page, bmap)) {
+               if (test_and_clear_bit_le(page, bmap)) {
                        host_dirty_count++;
                        /*
                         * If the bit is set, the value written onto
@@ -252,11 +362,12 @@ static struct kvm_vm *create_vm(enum vm_guest_mode mode, uint32_t vcpuid,
 
        pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode));
 
-       vm = _vm_create(mode, DEFAULT_GUEST_PHY_PAGES + extra_pg_pages, O_RDWR);
+       vm = vm_create(mode, DEFAULT_GUEST_PHY_PAGES + extra_pg_pages, O_RDWR);
        kvm_vm_elf_load(vm, program_invocation_name, 0, 0);
 #ifdef __x86_64__
        vm_create_irqchip(vm);
 #endif
+       log_mode_create_vm_done(vm);
        vm_vcpu_add_default(vm, vcpuid, guest_code);
        return vm;
 }
@@ -264,10 +375,6 @@ static struct kvm_vm *create_vm(enum vm_guest_mode mode, uint32_t vcpuid,
 #define DIRTY_MEM_BITS 30 /* 1G */
 #define PAGE_SHIFT_4K  12
 
-#ifdef USE_CLEAR_DIRTY_LOG
-static u64 dirty_log_manual_caps;
-#endif
-
 static void run_test(enum vm_guest_mode mode, unsigned long iterations,
                     unsigned long interval, uint64_t phys_offset)
 {
@@ -275,6 +382,12 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
        struct kvm_vm *vm;
        unsigned long *bmap;
 
+       if (!log_mode_supported()) {
+               print_skip("Log mode '%s' not supported",
+                          log_modes[host_log_mode].name);
+               return;
+       }
+
        /*
         * We reserve page table for 2 times of extra dirty mem which
         * will definitely cover the original (1G+) test range.  Here
@@ -317,14 +430,6 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
        bmap = bitmap_alloc(host_num_pages);
        host_bmap_track = bitmap_alloc(host_num_pages);
 
-#ifdef USE_CLEAR_DIRTY_LOG
-       struct kvm_enable_cap cap = {};
-
-       cap.cap = KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2;
-       cap.args[0] = dirty_log_manual_caps;
-       vm_enable_cap(vm, &cap);
-#endif
-
        /* Add an extra memory slot for testing dirty logging */
        vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS,
                                    guest_test_phys_mem,
@@ -362,11 +467,8 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
        while (iteration < iterations) {
                /* Give the vcpu thread some time to dirty some pages */
                usleep(interval * 1000);
-               kvm_vm_get_dirty_log(vm, TEST_MEM_SLOT_INDEX, bmap);
-#ifdef USE_CLEAR_DIRTY_LOG
-               kvm_vm_clear_dirty_log(vm, TEST_MEM_SLOT_INDEX, bmap, 0,
-                                      host_num_pages);
-#endif
+               log_mode_collect_dirty_pages(vm, TEST_MEM_SLOT_INDEX,
+                                            bmap, host_num_pages);
                vm_dirty_log_verify(mode, bmap);
                iteration++;
                sync_global_to_guest(vm, iteration);
@@ -410,6 +512,9 @@ static void help(char *name)
               TEST_HOST_LOOP_INTERVAL);
        printf(" -p: specify guest physical test memory offset\n"
               "     Warning: a low offset can conflict with the loaded test code.\n");
+       printf(" -M: specify the host logging mode "
+              "(default: run all log modes).  Supported modes: \n\t");
+       log_modes_dump();
        printf(" -m: specify the guest mode ID to test "
               "(default: test all supported modes)\n"
               "     This option may be used multiple times.\n"
@@ -429,18 +534,7 @@ int main(int argc, char *argv[])
        bool mode_selected = false;
        uint64_t phys_offset = 0;
        unsigned int mode;
-       int opt, i;
-
-#ifdef USE_CLEAR_DIRTY_LOG
-       dirty_log_manual_caps =
-               kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2);
-       if (!dirty_log_manual_caps) {
-               print_skip("KVM_CLEAR_DIRTY_LOG not available");
-               exit(KSFT_SKIP);
-       }
-       dirty_log_manual_caps &= (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE |
-                                 KVM_DIRTY_LOG_INITIALLY_SET);
-#endif
+       int opt, i, j;
 
 #ifdef __x86_64__
        guest_mode_init(VM_MODE_PXXV48_4K, true, true);
@@ -464,7 +558,7 @@ int main(int argc, char *argv[])
        guest_mode_init(VM_MODE_P40V48_4K, true, true);
 #endif
 
-       while ((opt = getopt(argc, argv, "hi:I:p:m:")) != -1) {
+       while ((opt = getopt(argc, argv, "hi:I:p:m:M:")) != -1) {
                switch (opt) {
                case 'i':
                        iterations = strtol(optarg, NULL, 10);
@@ -486,6 +580,26 @@ int main(int argc, char *argv[])
                                    "Guest mode ID %d too big", mode);
                        guest_modes[mode].enabled = true;
                        break;
+               case 'M':
+                       if (!strcmp(optarg, "all")) {
+                               host_log_mode_option = LOG_MODE_ALL;
+                               break;
+                       }
+                       for (i = 0; i < LOG_MODE_NUM; i++) {
+                               if (!strcmp(optarg, log_modes[i].name)) {
+                                       pr_info("Setting log mode to: '%s'\n",
+                                               optarg);
+                                       host_log_mode_option = i;
+                                       break;
+                               }
+                       }
+                       if (i == LOG_MODE_NUM) {
+                               printf("Log mode '%s' invalid. Please choose "
+                                      "from: ", optarg);
+                               log_modes_dump();
+                               exit(1);
+                       }
+                       break;
                case 'h':
                default:
                        help(argv[0]);
@@ -507,7 +621,18 @@ int main(int argc, char *argv[])
                TEST_ASSERT(guest_modes[i].supported,
                            "Guest mode ID %d (%s) not supported.",
                            i, vm_guest_mode_string(i));
-               run_test(i, iterations, interval, phys_offset);
+               if (host_log_mode_option == LOG_MODE_ALL) {
+                       /* Run each log mode */
+                       for (j = 0; j < LOG_MODE_NUM; j++) {
+                               pr_info("Testing Log Mode '%s'\n",
+                                       log_modes[j].name);
+                               host_log_mode = j;
+                               run_test(i, iterations, interval, phys_offset);
+                       }
+               } else {
+                       host_log_mode = host_log_mode_option;
+                       run_test(i, iterations, interval, phys_offset);
+               }
        }
 
        return 0;
index 919e161..7d29aa7 100644 (file)
@@ -63,9 +63,11 @@ enum vm_mem_backing_src_type {
 
 int kvm_check_cap(long cap);
 int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap *cap);
+int vcpu_enable_cap(struct kvm_vm *vm, uint32_t vcpu_id,
+                   struct kvm_enable_cap *cap);
+void vm_enable_dirty_ring(struct kvm_vm *vm, uint32_t ring_size);
 
 struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm);
-struct kvm_vm *_vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm);
 void kvm_vm_free(struct kvm_vm *vmp);
 void kvm_vm_restart(struct kvm_vm *vmp, int perm);
 void kvm_vm_release(struct kvm_vm *vmp);
@@ -149,6 +151,7 @@ void vcpu_set_guest_debug(struct kvm_vm *vm, uint32_t vcpuid,
                          struct kvm_guest_debug *debug);
 void vcpu_set_mp_state(struct kvm_vm *vm, uint32_t vcpuid,
                       struct kvm_mp_state *mp_state);
+struct kvm_reg_list *vcpu_get_reg_list(struct kvm_vm *vm, uint32_t vcpuid);
 void vcpu_regs_get(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_regs *regs);
 void vcpu_regs_set(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_regs *regs);
 
@@ -294,6 +297,8 @@ int vm_create_device(struct kvm_vm *vm, struct kvm_create_device *cd);
        memcpy(&(g), _p, sizeof(g));                            \
 })
 
+void assert_on_unhandled_exception(struct kvm_vm *vm, uint32_t vcpuid);
+
 /* Common ucalls */
 enum {
        UCALL_NONE,
diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/testing/selftests/kvm/include/perf_test_util.h
new file mode 100644 (file)
index 0000000..2618052
--- /dev/null
@@ -0,0 +1,198 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * tools/testing/selftests/kvm/include/perf_test_util.h
+ *
+ * Copyright (C) 2020, Google LLC.
+ */
+
+#ifndef SELFTEST_KVM_PERF_TEST_UTIL_H
+#define SELFTEST_KVM_PERF_TEST_UTIL_H
+
+#include "kvm_util.h"
+#include "processor.h"
+
+#define MAX_VCPUS 512
+
+#define PAGE_SHIFT_4K  12
+#define PTES_PER_4K_PT 512
+
+#define TEST_MEM_SLOT_INDEX            1
+
+/* Default guest test virtual memory offset */
+#define DEFAULT_GUEST_TEST_MEM         0xc0000000
+
+#define DEFAULT_PER_VCPU_MEM_SIZE      (1 << 30) /* 1G */
+
+/*
+ * Guest physical memory offset of the testing memory slot.
+ * This will be set to the topmost valid physical address minus
+ * the test memory size.
+ */
+static uint64_t guest_test_phys_mem;
+
+/*
+ * Guest virtual memory offset of the testing memory slot.
+ * Must not conflict with identity mapped test code.
+ */
+static uint64_t guest_test_virt_mem = DEFAULT_GUEST_TEST_MEM;
+static uint64_t guest_percpu_mem_size = DEFAULT_PER_VCPU_MEM_SIZE;
+
+/* Number of VCPUs for the test */
+static int nr_vcpus = 1;
+
+struct vcpu_args {
+       uint64_t gva;
+       uint64_t pages;
+
+       /* Only used by the host userspace part of the vCPU thread */
+       int vcpu_id;
+};
+
+struct perf_test_args {
+       struct kvm_vm *vm;
+       uint64_t host_page_size;
+       uint64_t guest_page_size;
+       int wr_fract;
+
+       struct vcpu_args vcpu_args[MAX_VCPUS];
+};
+
+static struct perf_test_args perf_test_args;
+
+/*
+ * Continuously write to the first 8 bytes of each page in the
+ * specified region.
+ */
+static void guest_code(uint32_t vcpu_id)
+{
+       struct vcpu_args *vcpu_args = &perf_test_args.vcpu_args[vcpu_id];
+       uint64_t gva;
+       uint64_t pages;
+       int i;
+
+       /* Make sure vCPU args data structure is not corrupt. */
+       GUEST_ASSERT(vcpu_args->vcpu_id == vcpu_id);
+
+       gva = vcpu_args->gva;
+       pages = vcpu_args->pages;
+
+       while (true) {
+               for (i = 0; i < pages; i++) {
+                       uint64_t addr = gva + (i * perf_test_args.guest_page_size);
+
+                       if (i % perf_test_args.wr_fract == 0)
+                               *(uint64_t *)addr = 0x0123456789ABCDEF;
+                       else
+                               READ_ONCE(*(uint64_t *)addr);
+               }
+
+               GUEST_SYNC(1);
+       }
+}
+
+static struct kvm_vm *create_vm(enum vm_guest_mode mode, int vcpus,
+                               uint64_t vcpu_memory_bytes)
+{
+       struct kvm_vm *vm;
+       uint64_t pages = DEFAULT_GUEST_PHY_PAGES;
+       uint64_t guest_num_pages;
+
+       /* Account for a few pages per-vCPU for stacks */
+       pages += DEFAULT_STACK_PGS * vcpus;
+
+       /*
+        * Reserve twice the ammount of memory needed to map the test region and
+        * the page table / stacks region, at 4k, for page tables. Do the
+        * calculation with 4K page size: the smallest of all archs. (e.g., 64K
+        * page size guest will need even less memory for page tables).
+        */
+       pages += (2 * pages) / PTES_PER_4K_PT;
+       pages += ((2 * vcpus * vcpu_memory_bytes) >> PAGE_SHIFT_4K) /
+                PTES_PER_4K_PT;
+       pages = vm_adjust_num_guest_pages(mode, pages);
+
+       pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode));
+
+       vm = vm_create(mode, pages, O_RDWR);
+       kvm_vm_elf_load(vm, program_invocation_name, 0, 0);
+#ifdef __x86_64__
+       vm_create_irqchip(vm);
+#endif
+
+       perf_test_args.vm = vm;
+       perf_test_args.guest_page_size = vm_get_page_size(vm);
+       perf_test_args.host_page_size = getpagesize();
+
+       TEST_ASSERT(vcpu_memory_bytes % perf_test_args.guest_page_size == 0,
+                   "Guest memory size is not guest page size aligned.");
+
+       guest_num_pages = (vcpus * vcpu_memory_bytes) /
+                         perf_test_args.guest_page_size;
+       guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages);
+
+       /*
+        * If there should be more memory in the guest test region than there
+        * can be pages in the guest, it will definitely cause problems.
+        */
+       TEST_ASSERT(guest_num_pages < vm_get_max_gfn(vm),
+                   "Requested more guest memory than address space allows.\n"
+                   "    guest pages: %lx max gfn: %x vcpus: %d wss: %lx]\n",
+                   guest_num_pages, vm_get_max_gfn(vm), vcpus,
+                   vcpu_memory_bytes);
+
+       TEST_ASSERT(vcpu_memory_bytes % perf_test_args.host_page_size == 0,
+                   "Guest memory size is not host page size aligned.");
+
+       guest_test_phys_mem = (vm_get_max_gfn(vm) - guest_num_pages) *
+                             perf_test_args.guest_page_size;
+       guest_test_phys_mem &= ~(perf_test_args.host_page_size - 1);
+
+#ifdef __s390x__
+       /* Align to 1M (segment size) */
+       guest_test_phys_mem &= ~((1 << 20) - 1);
+#endif
+
+       pr_info("guest physical test memory offset: 0x%lx\n", guest_test_phys_mem);
+
+       /* Add an extra memory slot for testing */
+       vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS,
+                                   guest_test_phys_mem,
+                                   TEST_MEM_SLOT_INDEX,
+                                   guest_num_pages, 0);
+
+       /* Do mapping for the demand paging memory slot */
+       virt_map(vm, guest_test_virt_mem, guest_test_phys_mem, guest_num_pages, 0);
+
+       ucall_init(vm, NULL);
+
+       return vm;
+}
+
+static void add_vcpus(struct kvm_vm *vm, int vcpus, uint64_t vcpu_memory_bytes)
+{
+       vm_paddr_t vcpu_gpa;
+       struct vcpu_args *vcpu_args;
+       int vcpu_id;
+
+       for (vcpu_id = 0; vcpu_id < vcpus; vcpu_id++) {
+               vcpu_args = &perf_test_args.vcpu_args[vcpu_id];
+
+               vm_vcpu_add_default(vm, vcpu_id, guest_code);
+
+#ifdef __x86_64__
+               vcpu_set_cpuid(vm, vcpu_id, kvm_get_supported_cpuid());
+#endif
+
+               vcpu_args->vcpu_id = vcpu_id;
+               vcpu_args->gva = guest_test_virt_mem +
+                                (vcpu_id * vcpu_memory_bytes);
+               vcpu_args->pages = vcpu_memory_bytes /
+                                  perf_test_args.guest_page_size;
+
+               vcpu_gpa = guest_test_phys_mem + (vcpu_id * vcpu_memory_bytes);
+               pr_debug("Added VCPU %d with test mem gpa [%lx, %lx)\n",
+                        vcpu_id, vcpu_gpa, vcpu_gpa + vcpu_memory_bytes);
+       }
+}
+
+#endif /* SELFTEST_KVM_PERF_TEST_UTIL_H */
index 5eb01bf..ffffa56 100644 (file)
@@ -64,5 +64,7 @@ int64_t timespec_to_ns(struct timespec ts);
 struct timespec timespec_add_ns(struct timespec ts, int64_t ns);
 struct timespec timespec_add(struct timespec ts1, struct timespec ts2);
 struct timespec timespec_sub(struct timespec ts1, struct timespec ts2);
+struct timespec timespec_diff_now(struct timespec start);
+struct timespec timespec_div(struct timespec ts, int divisor);
 
 #endif /* SELFTEST_KVM_TEST_UTIL_H */
index 82b7fe1..8e61340 100644 (file)
@@ -36,6 +36,8 @@
 #define X86_CR4_SMAP           (1ul << 21)
 #define X86_CR4_PKE            (1ul << 22)
 
+#define UNEXPECTED_VECTOR_PORT 0xfff0u
+
 /* General Registers in 64-Bit Mode */
 struct gpr64_regs {
        u64 rax;
@@ -59,7 +61,7 @@ struct gpr64_regs {
 struct desc64 {
        uint16_t limit0;
        uint16_t base0;
-       unsigned base1:8, s:1, type:4, dpl:2, p:1;
+       unsigned base1:8, type:4, s:1, dpl:2, p:1;
        unsigned limit1:4, avl:1, l:1, db:1, g:1, base2:8;
        uint32_t base3;
        uint32_t zero1;
@@ -239,6 +241,11 @@ static inline struct desc_ptr get_idt(void)
        return idt;
 }
 
+static inline void outl(uint16_t port, uint32_t value)
+{
+       __asm__ __volatile__("outl %%eax, %%dx" : : "d"(port), "a"(value));
+}
+
 #define SET_XMM(__var, __xmm) \
        asm volatile("movq %0, %%"#__xmm : : "r"(__var) : #__xmm)
 
@@ -338,6 +345,35 @@ uint32_t kvm_get_cpuid_max_basic(void);
 uint32_t kvm_get_cpuid_max_extended(void);
 void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits);
 
+struct ex_regs {
+       uint64_t rax, rcx, rdx, rbx;
+       uint64_t rbp, rsi, rdi;
+       uint64_t r8, r9, r10, r11;
+       uint64_t r12, r13, r14, r15;
+       uint64_t vector;
+       uint64_t error_code;
+       uint64_t rip;
+       uint64_t cs;
+       uint64_t rflags;
+};
+
+void vm_init_descriptor_tables(struct kvm_vm *vm);
+void vcpu_init_descriptor_tables(struct kvm_vm *vm, uint32_t vcpuid);
+void vm_handle_exception(struct kvm_vm *vm, int vector,
+                       void (*handler)(struct ex_regs *));
+
+/*
+ * set_cpuid() - overwrites a matching cpuid entry with the provided value.
+ *              matches based on ent->function && ent->index. returns true
+ *              if a match was found and successfully overwritten.
+ * @cpuid: the kvm cpuid list to modify.
+ * @ent: cpuid entry to insert
+ */
+bool set_cpuid(struct kvm_cpuid2 *cpuid, struct kvm_cpuid_entry2 *ent);
+
+uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2,
+                      uint64_t a3);
+
 /*
  * Basic CPU control in CR0
  */
index 2afa661..d6c32c3 100644 (file)
@@ -350,3 +350,7 @@ void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...)
 
        va_end(ap);
 }
+
+void assert_on_unhandled_exception(struct kvm_vm *vm, uint32_t vcpuid)
+{
+}
index c8e0ec2..2f37b90 100644 (file)
@@ -94,6 +94,9 @@ uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)
        struct kvm_run *run = vcpu_state(vm, vcpu_id);
        struct ucall ucall = {};
 
+       if (uc)
+               memset(uc, 0, sizeof(*uc));
+
        if (run->exit_reason == KVM_EXIT_MMIO &&
            run->mmio.phys_addr == (uint64_t)ucall_exit_mmio_addr) {
                vm_vaddr_t gva;
index 3327ceb..126c672 100644 (file)
@@ -86,6 +86,34 @@ int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap *cap)
        return ret;
 }
 
+/* VCPU Enable Capability
+ *
+ * Input Args:
+ *   vm - Virtual Machine
+ *   vcpu_id - VCPU
+ *   cap - Capability
+ *
+ * Output Args: None
+ *
+ * Return: On success, 0. On failure a TEST_ASSERT failure is produced.
+ *
+ * Enables a capability (KVM_CAP_*) on the VCPU.
+ */
+int vcpu_enable_cap(struct kvm_vm *vm, uint32_t vcpu_id,
+                   struct kvm_enable_cap *cap)
+{
+       struct vcpu *vcpu = vcpu_find(vm, vcpu_id);
+       int r;
+
+       TEST_ASSERT(vcpu, "cannot find vcpu %d", vcpu_id);
+
+       r = ioctl(vcpu->fd, KVM_ENABLE_CAP, cap);
+       TEST_ASSERT(!r, "KVM_ENABLE_CAP vCPU ioctl failed,\n"
+                       "  rc: %i, errno: %i", r, errno);
+
+       return r;
+}
+
 static void vm_open(struct kvm_vm *vm, int perm)
 {
        vm->kvm_fd = open(KVM_DEV_PATH, perm);
@@ -152,7 +180,7 @@ _Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params)
  * descriptor to control the created VM is created with the permissions
  * given by perm (e.g. O_RDWR).
  */
-struct kvm_vm *_vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm)
+struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm)
 {
        struct kvm_vm *vm;
 
@@ -243,11 +271,6 @@ struct kvm_vm *_vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm)
        return vm;
 }
 
-struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm)
-{
-       return _vm_create(mode, phy_pages, perm);
-}
-
 /*
  * VM Restart
  *
@@ -1204,6 +1227,9 @@ int _vcpu_run(struct kvm_vm *vm, uint32_t vcpuid)
        do {
                rc = ioctl(vcpu->fd, KVM_RUN, NULL);
        } while (rc == -1 && errno == EINTR);
+
+       assert_on_unhandled_exception(vm, vcpuid);
+
        return rc;
 }
 
@@ -1260,6 +1286,35 @@ void vcpu_set_mp_state(struct kvm_vm *vm, uint32_t vcpuid,
                "rc: %i errno: %i", ret, errno);
 }
 
+/*
+ * VM VCPU Get Reg List
+ *
+ * Input Args:
+ *   vm - Virtual Machine
+ *   vcpuid - VCPU ID
+ *
+ * Output Args:
+ *   None
+ *
+ * Return:
+ *   A pointer to an allocated struct kvm_reg_list
+ *
+ * Get the list of guest registers which are supported for
+ * KVM_GET_ONE_REG/KVM_SET_ONE_REG calls
+ */
+struct kvm_reg_list *vcpu_get_reg_list(struct kvm_vm *vm, uint32_t vcpuid)
+{
+       struct kvm_reg_list reg_list_n = { .n = 0 }, *reg_list;
+       int ret;
+
+       ret = _vcpu_ioctl(vm, vcpuid, KVM_GET_REG_LIST, &reg_list_n);
+       TEST_ASSERT(ret == -1 && errno == E2BIG, "KVM_GET_REG_LIST n=0");
+       reg_list = calloc(1, sizeof(*reg_list) + reg_list_n.n * sizeof(__u64));
+       reg_list->n = reg_list_n.n;
+       vcpu_ioctl(vm, vcpuid, KVM_GET_REG_LIST, reg_list);
+       return reg_list;
+}
+
 /*
  * VM VCPU Regs Get
  *
index 2ef4465..f07d383 100644 (file)
@@ -50,6 +50,8 @@ struct kvm_vm {
        vm_paddr_t pgd;
        vm_vaddr_t gdt;
        vm_vaddr_t tss;
+       vm_vaddr_t idt;
+       vm_vaddr_t handlers;
 };
 
 struct vcpu *vcpu_find(struct kvm_vm *vm, uint32_t vcpuid);
index a88c5d6..7349bb2 100644 (file)
@@ -241,3 +241,7 @@ void vcpu_dump(FILE *stream, struct kvm_vm *vm, uint32_t vcpuid, uint8_t indent)
        fprintf(stream, "%*spstate: psw: 0x%.16llx:0x%.16llx\n",
                indent, "", vcpu->state->psw_mask, vcpu->state->psw_addr);
 }
+
+void assert_on_unhandled_exception(struct kvm_vm *vm, uint32_t vcpuid)
+{
+}
index fd589dc..9d3b0f1 100644 (file)
@@ -38,6 +38,9 @@ uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)
        struct kvm_run *run = vcpu_state(vm, vcpu_id);
        struct ucall ucall = {};
 
+       if (uc)
+               memset(uc, 0, sizeof(*uc));
+
        if (run->exit_reason == KVM_EXIT_S390_SIEIC &&
            run->s390_sieic.icptcode == 4 &&
            (run->s390_sieic.ipa >> 8) == 0x83 &&    /* 0x83 means DIAGNOSE */
index 689e97c..8e04c0b 100644 (file)
@@ -4,10 +4,13 @@
  *
  * Copyright (C) 2020, Google LLC.
  */
-#include <stdlib.h>
+
+#include <assert.h>
 #include <ctype.h>
 #include <limits.h>
-#include <assert.h>
+#include <stdlib.h>
+#include <time.h>
+
 #include "test_util.h"
 
 /*
@@ -81,6 +84,21 @@ struct timespec timespec_sub(struct timespec ts1, struct timespec ts2)
        return timespec_add_ns((struct timespec){0}, ns1 - ns2);
 }
 
+struct timespec timespec_diff_now(struct timespec start)
+{
+       struct timespec end;
+
+       clock_gettime(CLOCK_MONOTONIC, &end);
+       return timespec_sub(end, start);
+}
+
+struct timespec timespec_div(struct timespec ts, int divisor)
+{
+       int64_t ns = timespec_to_ns(ts) / divisor;
+
+       return timespec_add_ns((struct timespec){0}, ns);
+}
+
 void print_skip(const char *fmt, ...)
 {
        va_list ap;
diff --git a/tools/testing/selftests/kvm/lib/x86_64/handlers.S b/tools/testing/selftests/kvm/lib/x86_64/handlers.S
new file mode 100644 (file)
index 0000000..aaf7bc7
--- /dev/null
@@ -0,0 +1,81 @@
+handle_exception:
+       push %r15
+       push %r14
+       push %r13
+       push %r12
+       push %r11
+       push %r10
+       push %r9
+       push %r8
+
+       push %rdi
+       push %rsi
+       push %rbp
+       push %rbx
+       push %rdx
+       push %rcx
+       push %rax
+       mov %rsp, %rdi
+
+       call route_exception
+
+       pop %rax
+       pop %rcx
+       pop %rdx
+       pop %rbx
+       pop %rbp
+       pop %rsi
+       pop %rdi
+       pop %r8
+       pop %r9
+       pop %r10
+       pop %r11
+       pop %r12
+       pop %r13
+       pop %r14
+       pop %r15
+
+       /* Discard vector and error code. */
+       add $16, %rsp
+       iretq
+
+/*
+ * Build the handle_exception wrappers which push the vector/error code on the
+ * stack and an array of pointers to those wrappers.
+ */
+.pushsection .rodata
+.globl idt_handlers
+idt_handlers:
+.popsection
+
+.macro HANDLERS has_error from to
+       vector = \from
+       .rept \to - \from + 1
+       .align 8
+
+       /* Fetch current address and append it to idt_handlers. */
+       current_handler = .
+.pushsection .rodata
+.quad current_handler
+.popsection
+
+       .if ! \has_error
+       pushq $0
+       .endif
+       pushq $vector
+       jmp handle_exception
+       vector = vector + 1
+       .endr
+.endm
+
+.global idt_handler_code
+idt_handler_code:
+       HANDLERS has_error=0 from=0  to=7
+       HANDLERS has_error=1 from=8  to=8
+       HANDLERS has_error=0 from=9  to=9
+       HANDLERS has_error=1 from=10 to=14
+       HANDLERS has_error=0 from=15 to=16
+       HANDLERS has_error=1 from=17 to=17
+       HANDLERS has_error=0 from=18 to=255
+
+.section        .note.GNU-stack, "", %progbits
index f6eb34e..d10c5c0 100644 (file)
 #include "../kvm_util_internal.h"
 #include "processor.h"
 
+#ifndef NUM_INTERRUPTS
+#define NUM_INTERRUPTS 256
+#endif
+
+#define DEFAULT_CODE_SELECTOR 0x8
+#define DEFAULT_DATA_SELECTOR 0x10
+
 /* Minimum physical address used for virtual translation tables. */
 #define KVM_GUEST_PAGE_TABLE_MIN_PADDR 0x180000
 
+vm_vaddr_t exception_handlers;
+
 /* Virtual translation table structure declarations */
 struct pageMapL4Entry {
        uint64_t present:1;
@@ -392,11 +401,12 @@ static void kvm_seg_fill_gdt_64bit(struct kvm_vm *vm, struct kvm_segment *segp)
        desc->limit0 = segp->limit & 0xFFFF;
        desc->base0 = segp->base & 0xFFFF;
        desc->base1 = segp->base >> 16;
-       desc->s = segp->s;
        desc->type = segp->type;
+       desc->s = segp->s;
        desc->dpl = segp->dpl;
        desc->p = segp->present;
        desc->limit1 = segp->limit >> 16;
+       desc->avl = segp->avl;
        desc->l = segp->l;
        desc->db = segp->db;
        desc->g = segp->g;
@@ -556,9 +566,9 @@ static void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot, int gdt_m
                sregs.efer |= (EFER_LME | EFER_LMA | EFER_NX);
 
                kvm_seg_set_unusable(&sregs.ldt);
-               kvm_seg_set_kernel_code_64bit(vm, 0x8, &sregs.cs);
-               kvm_seg_set_kernel_data_64bit(vm, 0x10, &sregs.ds);
-               kvm_seg_set_kernel_data_64bit(vm, 0x10, &sregs.es);
+               kvm_seg_set_kernel_code_64bit(vm, DEFAULT_CODE_SELECTOR, &sregs.cs);
+               kvm_seg_set_kernel_data_64bit(vm, DEFAULT_DATA_SELECTOR, &sregs.ds);
+               kvm_seg_set_kernel_data_64bit(vm, DEFAULT_DATA_SELECTOR, &sregs.es);
                kvm_setup_tss_64bit(vm, &sregs.tr, 0x18, gdt_memslot, pgd_memslot);
                break;
 
@@ -1118,3 +1128,131 @@ void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits)
                *va_bits = (entry->eax >> 8) & 0xff;
        }
 }
+
+struct idt_entry {
+       uint16_t offset0;
+       uint16_t selector;
+       uint16_t ist : 3;
+       uint16_t : 5;
+       uint16_t type : 4;
+       uint16_t : 1;
+       uint16_t dpl : 2;
+       uint16_t p : 1;
+       uint16_t offset1;
+       uint32_t offset2; uint32_t reserved;
+};
+
+static void set_idt_entry(struct kvm_vm *vm, int vector, unsigned long addr,
+                         int dpl, unsigned short selector)
+{
+       struct idt_entry *base =
+               (struct idt_entry *)addr_gva2hva(vm, vm->idt);
+       struct idt_entry *e = &base[vector];
+
+       memset(e, 0, sizeof(*e));
+       e->offset0 = addr;
+       e->selector = selector;
+       e->ist = 0;
+       e->type = 14;
+       e->dpl = dpl;
+       e->p = 1;
+       e->offset1 = addr >> 16;
+       e->offset2 = addr >> 32;
+}
+
+void kvm_exit_unexpected_vector(uint32_t value)
+{
+       outl(UNEXPECTED_VECTOR_PORT, value);
+}
+
+void route_exception(struct ex_regs *regs)
+{
+       typedef void(*handler)(struct ex_regs *);
+       handler *handlers = (handler *)exception_handlers;
+
+       if (handlers && handlers[regs->vector]) {
+               handlers[regs->vector](regs);
+               return;
+       }
+
+       kvm_exit_unexpected_vector(regs->vector);
+}
+
+void vm_init_descriptor_tables(struct kvm_vm *vm)
+{
+       extern void *idt_handlers;
+       int i;
+
+       vm->idt = vm_vaddr_alloc(vm, getpagesize(), 0x2000, 0, 0);
+       vm->handlers = vm_vaddr_alloc(vm, 256 * sizeof(void *), 0x2000, 0, 0);
+       /* Handlers have the same address in both address spaces.*/
+       for (i = 0; i < NUM_INTERRUPTS; i++)
+               set_idt_entry(vm, i, (unsigned long)(&idt_handlers)[i], 0,
+                       DEFAULT_CODE_SELECTOR);
+}
+
+void vcpu_init_descriptor_tables(struct kvm_vm *vm, uint32_t vcpuid)
+{
+       struct kvm_sregs sregs;
+
+       vcpu_sregs_get(vm, vcpuid, &sregs);
+       sregs.idt.base = vm->idt;
+       sregs.idt.limit = NUM_INTERRUPTS * sizeof(struct idt_entry) - 1;
+       sregs.gdt.base = vm->gdt;
+       sregs.gdt.limit = getpagesize() - 1;
+       kvm_seg_set_kernel_data_64bit(NULL, DEFAULT_DATA_SELECTOR, &sregs.gs);
+       vcpu_sregs_set(vm, vcpuid, &sregs);
+       *(vm_vaddr_t *)addr_gva2hva(vm, (vm_vaddr_t)(&exception_handlers)) = vm->handlers;
+}
+
+void vm_handle_exception(struct kvm_vm *vm, int vector,
+                        void (*handler)(struct ex_regs *))
+{
+       vm_vaddr_t *handlers = (vm_vaddr_t *)addr_gva2hva(vm, vm->handlers);
+
+       handlers[vector] = (vm_vaddr_t)handler;
+}
+
+void assert_on_unhandled_exception(struct kvm_vm *vm, uint32_t vcpuid)
+{
+       if (vcpu_state(vm, vcpuid)->exit_reason == KVM_EXIT_IO
+               && vcpu_state(vm, vcpuid)->io.port == UNEXPECTED_VECTOR_PORT
+               && vcpu_state(vm, vcpuid)->io.size == 4) {
+               /* Grab pointer to io data */
+               uint32_t *data = (void *)vcpu_state(vm, vcpuid)
+                       + vcpu_state(vm, vcpuid)->io.data_offset;
+
+               TEST_ASSERT(false,
+                           "Unexpected vectored event in guest (vector:0x%x)",
+                           *data);
+       }
+}
+
+bool set_cpuid(struct kvm_cpuid2 *cpuid,
+              struct kvm_cpuid_entry2 *ent)
+{
+       int i;
+
+       for (i = 0; i < cpuid->nent; i++) {
+               struct kvm_cpuid_entry2 *cur = &cpuid->entries[i];
+
+               if (cur->function != ent->function || cur->index != ent->index)
+                       continue;
+
+               memcpy(cur, ent, sizeof(struct kvm_cpuid_entry2));
+               return true;
+       }
+
+       return false;
+}
+
+uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2,
+                      uint64_t a3)
+{
+       uint64_t r;
+
+       asm volatile("vmcall"
+                    : "=a"(r)
+                    : "b"(a0), "c"(a1), "d"(a2), "S"(a3));
+       return r;
+}
index da4d89a..a348997 100644 (file)
@@ -40,6 +40,9 @@ uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)
        struct kvm_run *run = vcpu_state(vm, vcpu_id);
        struct ucall ucall = {};
 
+       if (uc)
+               memset(uc, 0, sizeof(*uc));
+
        if (run->exit_reason == KVM_EXIT_IO && run->io.port == UCALL_PIO_PORT) {
                struct kvm_regs regs;
 
diff --git a/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c b/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c
new file mode 100644 (file)
index 0000000..b10a274
--- /dev/null
@@ -0,0 +1,234 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2020, Google LLC.
+ *
+ * Tests for KVM paravirtual feature disablement
+ */
+#include <asm/kvm_para.h>
+#include <linux/kvm_para.h>
+#include <stdint.h>
+
+#include "test_util.h"
+#include "kvm_util.h"
+#include "processor.h"
+
+extern unsigned char rdmsr_start;
+extern unsigned char rdmsr_end;
+
+static u64 do_rdmsr(u32 idx)
+{
+       u32 lo, hi;
+
+       asm volatile("rdmsr_start: rdmsr;"
+                    "rdmsr_end:"
+                    : "=a"(lo), "=c"(hi)
+                    : "c"(idx));
+
+       return (((u64) hi) << 32) | lo;
+}
+
+extern unsigned char wrmsr_start;
+extern unsigned char wrmsr_end;
+
+static void do_wrmsr(u32 idx, u64 val)
+{
+       u32 lo, hi;
+
+       lo = val;
+       hi = val >> 32;
+
+       asm volatile("wrmsr_start: wrmsr;"
+                    "wrmsr_end:"
+                    : : "a"(lo), "c"(idx), "d"(hi));
+}
+
+static int nr_gp;
+
+static void guest_gp_handler(struct ex_regs *regs)
+{
+       unsigned char *rip = (unsigned char *)regs->rip;
+       bool r, w;
+
+       r = rip == &rdmsr_start;
+       w = rip == &wrmsr_start;
+       GUEST_ASSERT(r || w);
+
+       nr_gp++;
+
+       if (r)
+               regs->rip = (uint64_t)&rdmsr_end;
+       else
+               regs->rip = (uint64_t)&wrmsr_end;
+}
+
+struct msr_data {
+       uint32_t idx;
+       const char *name;
+};
+
+#define TEST_MSR(msr) { .idx = msr, .name = #msr }
+#define UCALL_PR_MSR 0xdeadbeef
+#define PR_MSR(msr) ucall(UCALL_PR_MSR, 1, msr)
+
+/*
+ * KVM paravirtual msrs to test. Expect a #GP if any of these msrs are read or
+ * written, as the KVM_CPUID_FEATURES leaf is cleared.
+ */
+static struct msr_data msrs_to_test[] = {
+       TEST_MSR(MSR_KVM_SYSTEM_TIME),
+       TEST_MSR(MSR_KVM_SYSTEM_TIME_NEW),
+       TEST_MSR(MSR_KVM_WALL_CLOCK),
+       TEST_MSR(MSR_KVM_WALL_CLOCK_NEW),
+       TEST_MSR(MSR_KVM_ASYNC_PF_EN),
+       TEST_MSR(MSR_KVM_STEAL_TIME),
+       TEST_MSR(MSR_KVM_PV_EOI_EN),
+       TEST_MSR(MSR_KVM_POLL_CONTROL),
+       TEST_MSR(MSR_KVM_ASYNC_PF_INT),
+       TEST_MSR(MSR_KVM_ASYNC_PF_ACK),
+};
+
+static void test_msr(struct msr_data *msr)
+{
+       PR_MSR(msr);
+       do_rdmsr(msr->idx);
+       GUEST_ASSERT(READ_ONCE(nr_gp) == 1);
+
+       nr_gp = 0;
+       do_wrmsr(msr->idx, 0);
+       GUEST_ASSERT(READ_ONCE(nr_gp) == 1);
+       nr_gp = 0;
+}
+
+struct hcall_data {
+       uint64_t nr;
+       const char *name;
+};
+
+#define TEST_HCALL(hc) { .nr = hc, .name = #hc }
+#define UCALL_PR_HCALL 0xdeadc0de
+#define PR_HCALL(hc) ucall(UCALL_PR_HCALL, 1, hc)
+
+/*
+ * KVM hypercalls to test. Expect -KVM_ENOSYS when called, as the corresponding
+ * features have been cleared in KVM_CPUID_FEATURES.
+ */
+static struct hcall_data hcalls_to_test[] = {
+       TEST_HCALL(KVM_HC_KICK_CPU),
+       TEST_HCALL(KVM_HC_SEND_IPI),
+       TEST_HCALL(KVM_HC_SCHED_YIELD),
+};
+
+static void test_hcall(struct hcall_data *hc)
+{
+       uint64_t r;
+
+       PR_HCALL(hc);
+       r = kvm_hypercall(hc->nr, 0, 0, 0, 0);
+       GUEST_ASSERT(r == -KVM_ENOSYS);
+}
+
+static void guest_main(void)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(msrs_to_test); i++) {
+               test_msr(&msrs_to_test[i]);
+       }
+
+       for (i = 0; i < ARRAY_SIZE(hcalls_to_test); i++) {
+               test_hcall(&hcalls_to_test[i]);
+       }
+
+       GUEST_DONE();
+}
+
+static void clear_kvm_cpuid_features(struct kvm_cpuid2 *cpuid)
+{
+       struct kvm_cpuid_entry2 ent = {0};
+
+       ent.function = KVM_CPUID_FEATURES;
+       TEST_ASSERT(set_cpuid(cpuid, &ent),
+                   "failed to clear KVM_CPUID_FEATURES leaf");
+}
+
+static void pr_msr(struct ucall *uc)
+{
+       struct msr_data *msr = (struct msr_data *)uc->args[0];
+
+       pr_info("testing msr: %s (%#x)\n", msr->name, msr->idx);
+}
+
+static void pr_hcall(struct ucall *uc)
+{
+       struct hcall_data *hc = (struct hcall_data *)uc->args[0];
+
+       pr_info("testing hcall: %s (%lu)\n", hc->name, hc->nr);
+}
+
+static void handle_abort(struct ucall *uc)
+{
+       TEST_FAIL("%s at %s:%ld", (const char *)uc->args[0],
+                 __FILE__, uc->args[1]);
+}
+
+#define VCPU_ID 0
+
+static void enter_guest(struct kvm_vm *vm)
+{
+       struct kvm_run *run;
+       struct ucall uc;
+       int r;
+
+       run = vcpu_state(vm, VCPU_ID);
+
+       while (true) {
+               r = _vcpu_run(vm, VCPU_ID);
+               TEST_ASSERT(!r, "vcpu_run failed: %d\n", r);
+               TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
+                           "unexpected exit reason: %u (%s)",
+                           run->exit_reason, exit_reason_str(run->exit_reason));
+
+               switch (get_ucall(vm, VCPU_ID, &uc)) {
+               case UCALL_PR_MSR:
+                       pr_msr(&uc);
+                       break;
+               case UCALL_PR_HCALL:
+                       pr_hcall(&uc);
+                       break;
+               case UCALL_ABORT:
+                       handle_abort(&uc);
+                       return;
+               case UCALL_DONE:
+                       return;
+               }
+       }
+}
+
+int main(void)
+{
+       struct kvm_enable_cap cap = {0};
+       struct kvm_cpuid2 *best;
+       struct kvm_vm *vm;
+
+       if (!kvm_check_cap(KVM_CAP_ENFORCE_PV_FEATURE_CPUID)) {
+               pr_info("will skip kvm paravirt restriction tests.\n");
+               return 0;
+       }
+
+       vm = vm_create_default(VCPU_ID, 0, guest_main);
+
+       cap.cap = KVM_CAP_ENFORCE_PV_FEATURE_CPUID;
+       cap.args[0] = 1;
+       vcpu_enable_cap(vm, VCPU_ID, &cap);
+
+       best = kvm_get_supported_cpuid();
+       clear_kvm_cpuid_features(best);
+       vcpu_set_cpuid(vm, VCPU_ID, best);
+
+       vm_init_descriptor_tables(vm);
+       vcpu_init_descriptor_tables(vm, VCPU_ID);
+       vm_handle_exception(vm, GP_VECTOR, guest_gp_handler);
+
+       enter_guest(vm);
+       kvm_vm_free(vm);
+}
index 30848ca..a5ce26d 100644 (file)
@@ -136,7 +136,7 @@ endif
 ifeq ($(OVERRIDE_TARGETS),)
 LOCAL_HDRS := $(selfdir)/kselftest_harness.h $(selfdir)/kselftest.h
 $(OUTPUT)/%:%.c $(LOCAL_HDRS)
-       $(LINK.c) $^ $(LDLIBS) -o $@
+       $(LINK.c) $(filter-out $(LOCAL_HDRS),$^) $(LDLIBS) -o $@
 
 $(OUTPUT)/%.o:%.S
        $(COMPILE.S) $^ -o $@
index bb11de9..f6f2965 100644 (file)
@@ -4,3 +4,4 @@ CONFIG_USER_NS=y
 CONFIG_PID_NS=y
 CONFIG_NET_NS=y
 CONFIG_CGROUPS=y
+CONFIG_CHECKPOINT_RESTORE=y
index 7758c98..0930e24 100644 (file)
@@ -204,7 +204,10 @@ TEST_F(child, fetch_fd)
        fd = sys_pidfd_getfd(self->pidfd, self->remote_fd, 0);
        ASSERT_GE(fd, 0);
 
-       EXPECT_EQ(0, sys_kcmp(getpid(), self->pid, KCMP_FILE, fd, self->remote_fd));
+       ret = sys_kcmp(getpid(), self->pid, KCMP_FILE, fd, self->remote_fd);
+       if (ret < 0 && errno == ENOSYS)
+               SKIP(return, "kcmp() syscall not supported");
+       EXPECT_EQ(ret, 0);
 
        ret = fcntl(fd, F_GETFD);
        ASSERT_GE(ret, 0);
index b9fe75f..8a59438 100644 (file)
@@ -6,7 +6,6 @@
 #include <inttypes.h>
 #include <limits.h>
 #include <linux/types.h>
-#include <linux/wait.h>
 #include <sched.h>
 #include <signal.h>
 #include <stdbool.h>
index 4b11544..6108112 100644 (file)
@@ -3,7 +3,6 @@
 #define _GNU_SOURCE
 #include <errno.h>
 #include <linux/types.h>
-#include <linux/wait.h>
 #include <poll.h>
 #include <signal.h>
 #include <stdbool.h>
index 1f085b9..6e2f2cd 100644 (file)
@@ -16,7 +16,6 @@
 #include <unistd.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
-#include <linux/kcmp.h>
 
 #include "pidfd.h"
 #include "../clone3/clone3_selftests.h"
index c585aaa..529eb70 100644 (file)
@@ -330,7 +330,7 @@ static int test_pidfd_send_signal_recycled_pid_fail(void)
                ksft_exit_fail_msg("%s test: Failed to recycle pid %d\n",
                                   test_name, PID_RECYCLE);
        case PIDFD_SKIP:
-               ksft_print_msg("%s test: Skipping test\n", test_name);
+               ksft_test_result_skip("%s test: Skipping test\n", test_name);
                ret = 0;
                break;
        case PIDFD_XFAIL:
index 052b5a7..b7d188f 100644 (file)
@@ -42,6 +42,11 @@ int perf_event_enable(int fd);
 int perf_event_disable(int fd);
 int perf_event_reset(int fd);
 
+struct perf_event_read {
+       __u64 nr;
+       __u64 l1d_misses;
+};
+
 #if !defined(__GLIBC_PREREQ) || !__GLIBC_PREREQ(2, 30)
 #include <unistd.h>
 #include <sys/syscall.h>
index eadbbff..f25e854 100644 (file)
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0+
 
-TEST_GEN_PROGS := rfi_flush spectre_v2
+TEST_GEN_PROGS := rfi_flush entry_flush spectre_v2
 top_srcdir = ../../../../..
 
 CFLAGS += -I../../../../../usr/include
@@ -11,3 +11,5 @@ $(TEST_GEN_PROGS): ../harness.c ../utils.c
 
 $(OUTPUT)/spectre_v2: CFLAGS += -m64
 $(OUTPUT)/spectre_v2: ../pmu/event.c branch_loops.S
+$(OUTPUT)/rfi_flush: flush_utils.c
+$(OUTPUT)/entry_flush: flush_utils.c
diff --git a/tools/testing/selftests/powerpc/security/entry_flush.c b/tools/testing/selftests/powerpc/security/entry_flush.c
new file mode 100644 (file)
index 0000000..78cf914
--- /dev/null
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/*
+ * Copyright 2018 IBM Corporation.
+ */
+
+#define __SANE_USERSPACE_TYPES__
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <malloc.h>
+#include <unistd.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include "utils.h"
+#include "flush_utils.h"
+
+int entry_flush_test(void)
+{
+       char *p;
+       int repetitions = 10;
+       int fd, passes = 0, iter, rc = 0;
+       struct perf_event_read v;
+       __u64 l1d_misses_total = 0;
+       unsigned long iterations = 100000, zero_size = 24 * 1024;
+       unsigned long l1d_misses_expected;
+       int rfi_flush_orig;
+       int entry_flush, entry_flush_orig;
+
+       SKIP_IF(geteuid() != 0);
+
+       // The PMU event we use only works on Power7 or later
+       SKIP_IF(!have_hwcap(PPC_FEATURE_ARCH_2_06));
+
+       if (read_debugfs_file("powerpc/rfi_flush", &rfi_flush_orig) < 0) {
+               perror("Unable to read powerpc/rfi_flush debugfs file");
+               SKIP_IF(1);
+       }
+
+       if (read_debugfs_file("powerpc/entry_flush", &entry_flush_orig) < 0) {
+               perror("Unable to read powerpc/entry_flush debugfs file");
+               SKIP_IF(1);
+       }
+
+       if (rfi_flush_orig != 0) {
+               if (write_debugfs_file("powerpc/rfi_flush", 0) < 0) {
+                       perror("error writing to powerpc/rfi_flush debugfs file");
+                       FAIL_IF(1);
+               }
+       }
+
+       entry_flush = entry_flush_orig;
+
+       fd = perf_event_open_counter(PERF_TYPE_RAW, /* L1d miss */ 0x400f0, -1);
+       FAIL_IF(fd < 0);
+
+       p = (char *)memalign(zero_size, CACHELINE_SIZE);
+
+       FAIL_IF(perf_event_enable(fd));
+
+       // disable L1 prefetching
+       set_dscr(1);
+
+       iter = repetitions;
+
+       /*
+        * We expect to see l1d miss for each cacheline access when entry_flush
+        * is set. Allow a small variation on this.
+        */
+       l1d_misses_expected = iterations * (zero_size / CACHELINE_SIZE - 2);
+
+again:
+       FAIL_IF(perf_event_reset(fd));
+
+       syscall_loop(p, iterations, zero_size);
+
+       FAIL_IF(read(fd, &v, sizeof(v)) != sizeof(v));
+
+       if (entry_flush && v.l1d_misses >= l1d_misses_expected)
+               passes++;
+       else if (!entry_flush && v.l1d_misses < (l1d_misses_expected / 2))
+               passes++;
+
+       l1d_misses_total += v.l1d_misses;
+
+       while (--iter)
+               goto again;
+
+       if (passes < repetitions) {
+               printf("FAIL (L1D misses with entry_flush=%d: %llu %c %lu) [%d/%d failures]\n",
+                      entry_flush, l1d_misses_total, entry_flush ? '<' : '>',
+                      entry_flush ? repetitions * l1d_misses_expected :
+                      repetitions * l1d_misses_expected / 2,
+                      repetitions - passes, repetitions);
+               rc = 1;
+       } else {
+               printf("PASS (L1D misses with entry_flush=%d: %llu %c %lu) [%d/%d pass]\n",
+                      entry_flush, l1d_misses_total, entry_flush ? '>' : '<',
+                      entry_flush ? repetitions * l1d_misses_expected :
+                      repetitions * l1d_misses_expected / 2,
+                      passes, repetitions);
+       }
+
+       if (entry_flush == entry_flush_orig) {
+               entry_flush = !entry_flush_orig;
+               if (write_debugfs_file("powerpc/entry_flush", entry_flush) < 0) {
+                       perror("error writing to powerpc/entry_flush debugfs file");
+                       return 1;
+               }
+               iter = repetitions;
+               l1d_misses_total = 0;
+               passes = 0;
+               goto again;
+       }
+
+       perf_event_disable(fd);
+       close(fd);
+
+       set_dscr(0);
+
+       if (write_debugfs_file("powerpc/rfi_flush", rfi_flush_orig) < 0) {
+               perror("unable to restore original value of powerpc/rfi_flush debugfs file");
+               return 1;
+       }
+
+       if (write_debugfs_file("powerpc/entry_flush", entry_flush_orig) < 0) {
+               perror("unable to restore original value of powerpc/entry_flush debugfs file");
+               return 1;
+       }
+
+       return rc;
+}
+
+int main(int argc, char *argv[])
+{
+       return test_harness(entry_flush_test, "entry_flush_test");
+}
diff --git a/tools/testing/selftests/powerpc/security/flush_utils.c b/tools/testing/selftests/powerpc/security/flush_utils.c
new file mode 100644 (file)
index 0000000..0c3c4c4
--- /dev/null
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/*
+ * Copyright 2018 IBM Corporation.
+ */
+
+#define __SANE_USERSPACE_TYPES__
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include "utils.h"
+#include "flush_utils.h"
+
+static inline __u64 load(void *addr)
+{
+       __u64 tmp;
+
+       asm volatile("ld %0,0(%1)" : "=r"(tmp) : "b"(addr));
+
+       return tmp;
+}
+
+void syscall_loop(char *p, unsigned long iterations,
+                 unsigned long zero_size)
+{
+       for (unsigned long i = 0; i < iterations; i++) {
+               for (unsigned long j = 0; j < zero_size; j += CACHELINE_SIZE)
+                       load(p + j);
+               getppid();
+       }
+}
+
+static void sigill_handler(int signr, siginfo_t *info, void *unused)
+{
+       static int warned;
+       ucontext_t *ctx = (ucontext_t *)unused;
+       unsigned long *pc = &UCONTEXT_NIA(ctx);
+
+       /* mtspr 3,RS to check for move to DSCR below */
+       if ((*((unsigned int *)*pc) & 0xfc1fffff) == 0x7c0303a6) {
+               if (!warned++)
+                       printf("WARNING: Skipping over dscr setup. Consider running 'ppc64_cpu --dscr=1' manually.\n");
+               *pc += 4;
+       } else {
+               printf("SIGILL at %p\n", pc);
+               abort();
+       }
+}
+
+void set_dscr(unsigned long val)
+{
+       static int init;
+       struct sigaction sa;
+
+       if (!init) {
+               memset(&sa, 0, sizeof(sa));
+               sa.sa_sigaction = sigill_handler;
+               sa.sa_flags = SA_SIGINFO;
+               if (sigaction(SIGILL, &sa, NULL))
+                       perror("sigill_handler");
+               init = 1;
+       }
+
+       asm volatile("mtspr %1,%0" : : "r" (val), "i" (SPRN_DSCR));
+}
diff --git a/tools/testing/selftests/powerpc/security/flush_utils.h b/tools/testing/selftests/powerpc/security/flush_utils.h
new file mode 100644 (file)
index 0000000..07a5eb3
--- /dev/null
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+/*
+ * Copyright 2018 IBM Corporation.
+ */
+
+#ifndef _SELFTESTS_POWERPC_SECURITY_FLUSH_UTILS_H
+#define _SELFTESTS_POWERPC_SECURITY_FLUSH_UTILS_H
+
+#define CACHELINE_SIZE 128
+
+void syscall_loop(char *p, unsigned long iterations,
+                 unsigned long zero_size);
+
+void set_dscr(unsigned long val);
+
+#endif /* _SELFTESTS_POWERPC_SECURITY_FLUSH_UTILS_H */
index 93a65bd..7565fd7 100644 (file)
 #include <stdint.h>
 #include <malloc.h>
 #include <unistd.h>
-#include <signal.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include "utils.h"
+#include "flush_utils.h"
 
-#define CACHELINE_SIZE 128
-
-struct perf_event_read {
-       __u64 nr;
-       __u64 l1d_misses;
-};
-
-static inline __u64 load(void *addr)
-{
-       __u64 tmp;
-
-       asm volatile("ld %0,0(%1)" : "=r"(tmp) : "b"(addr));
-
-       return tmp;
-}
-
-static void syscall_loop(char *p, unsigned long iterations,
-                        unsigned long zero_size)
-{
-       for (unsigned long i = 0; i < iterations; i++) {
-               for (unsigned long j = 0; j < zero_size; j += CACHELINE_SIZE)
-                       load(p + j);
-               getppid();
-       }
-}
-
-static void sigill_handler(int signr, siginfo_t *info, void *unused)
-{
-       static int warned = 0;
-       ucontext_t *ctx = (ucontext_t *)unused;
-       unsigned long *pc = &UCONTEXT_NIA(ctx);
-
-       /* mtspr 3,RS to check for move to DSCR below */
-       if ((*((unsigned int *)*pc) & 0xfc1fffff) == 0x7c0303a6) {
-               if (!warned++)
-                       printf("WARNING: Skipping over dscr setup. Consider running 'ppc64_cpu --dscr=1' manually.\n");
-               *pc += 4;
-       } else {
-               printf("SIGILL at %p\n", pc);
-               abort();
-       }
-}
-
-static void set_dscr(unsigned long val)
-{
-       static int init = 0;
-       struct sigaction sa;
-
-       if (!init) {
-               memset(&sa, 0, sizeof(sa));
-               sa.sa_sigaction = sigill_handler;
-               sa.sa_flags = SA_SIGINFO;
-               if (sigaction(SIGILL, &sa, NULL))
-                       perror("sigill_handler");
-               init = 1;
-       }
-
-       asm volatile("mtspr %1,%0" : : "r" (val), "i" (SPRN_DSCR));
-}
 
 int rfi_flush_test(void)
 {
@@ -85,19 +26,33 @@ int rfi_flush_test(void)
        __u64 l1d_misses_total = 0;
        unsigned long iterations = 100000, zero_size = 24 * 1024;
        unsigned long l1d_misses_expected;
-       int rfi_flush_org, rfi_flush;
+       int rfi_flush_orig, rfi_flush;
+       int have_entry_flush, entry_flush_orig;
 
        SKIP_IF(geteuid() != 0);
 
        // The PMU event we use only works on Power7 or later
        SKIP_IF(!have_hwcap(PPC_FEATURE_ARCH_2_06));
 
-       if (read_debugfs_file("powerpc/rfi_flush", &rfi_flush_org)) {
+       if (read_debugfs_file("powerpc/rfi_flush", &rfi_flush_orig) < 0) {
                perror("Unable to read powerpc/rfi_flush debugfs file");
                SKIP_IF(1);
        }
 
-       rfi_flush = rfi_flush_org;
+       if (read_debugfs_file("powerpc/entry_flush", &entry_flush_orig) < 0) {
+               have_entry_flush = 0;
+       } else {
+               have_entry_flush = 1;
+
+               if (entry_flush_orig != 0) {
+                       if (write_debugfs_file("powerpc/entry_flush", 0) < 0) {
+                               perror("error writing to powerpc/entry_flush debugfs file");
+                               return 1;
+                       }
+               }
+       }
+
+       rfi_flush = rfi_flush_orig;
 
        fd = perf_event_open_counter(PERF_TYPE_RAW, /* L1d miss */ 0x400f0, -1);
        FAIL_IF(fd < 0);
@@ -106,6 +61,7 @@ int rfi_flush_test(void)
 
        FAIL_IF(perf_event_enable(fd));
 
+       // disable L1 prefetching
        set_dscr(1);
 
        iter = repetitions;
@@ -147,8 +103,8 @@ again:
                       repetitions * l1d_misses_expected / 2,
                       passes, repetitions);
 
-       if (rfi_flush == rfi_flush_org) {
-               rfi_flush = !rfi_flush_org;
+       if (rfi_flush == rfi_flush_orig) {
+               rfi_flush = !rfi_flush_orig;
                if (write_debugfs_file("powerpc/rfi_flush", rfi_flush) < 0) {
                        perror("error writing to powerpc/rfi_flush debugfs file");
                        return 1;
@@ -164,11 +120,19 @@ again:
 
        set_dscr(0);
 
-       if (write_debugfs_file("powerpc/rfi_flush", rfi_flush_org) < 0) {
+       if (write_debugfs_file("powerpc/rfi_flush", rfi_flush_orig) < 0) {
                perror("unable to restore original value of powerpc/rfi_flush debugfs file");
                return 1;
        }
 
+       if (have_entry_flush) {
+               if (write_debugfs_file("powerpc/entry_flush", entry_flush_orig) < 0) {
+                       perror("unable to restore original value of powerpc/entry_flush "
+                              "debugfs file");
+                       return 1;
+               }
+       }
+
        return rc;
 }
 
index 471e2aa..fb4fe91 100644 (file)
@@ -14,7 +14,6 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 /* Test that /proc/loadavg correctly reports last pid in pid namespace. */
-#define _GNU_SOURCE
 #include <errno.h>
 #include <sched.h>
 #include <sys/types.h>
index 9f6d000..8511dcf 100644 (file)
@@ -13,7 +13,6 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
-#define _GNU_SOURCE
 #include <unistd.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
index 30e2b78..e7ceabe 100644 (file)
@@ -15,7 +15,6 @@
  */
 // Test that values in /proc/uptime increment monotonically
 // while shifting across CPUs.
-#define _GNU_SOURCE
 #undef NDEBUG
 #include <assert.h>
 #include <unistd.h>
index 4a18043..26c72f2 100644 (file)
@@ -1758,10 +1758,10 @@ TEST_F(TRACE_poke, getpid_runs_normally)
                 * and the code is stored as a positive value.  \
                 */                                             \
                if (_result < 0) {                              \
-                       SYSCALL_RET(_regs) = -result;           \
+                       SYSCALL_RET(_regs) = -_result;          \
                        (_regs).ccr |= 0x10000000;              \
                } else {                                        \
-                       SYSCALL_RET(_regs) = result;            \
+                       SYSCALL_RET(_regs) = _result;           \
                        (_regs).ccr &= ~0x10000000;             \
                }                                               \
        } while (0)
@@ -1804,8 +1804,8 @@ TEST_F(TRACE_poke, getpid_runs_normally)
 #define SYSCALL_RET(_regs)     (_regs).a[(_regs).windowbase * 4 + 2]
 #elif defined(__sh__)
 # define ARCH_REGS             struct pt_regs
-# define SYSCALL_NUM(_regs)    (_regs).gpr[3]
-# define SYSCALL_RET(_regs)    (_regs).gpr[0]
+# define SYSCALL_NUM(_regs)    (_regs).regs[3]
+# define SYSCALL_RET(_regs)    (_regs).regs[0]
 #else
 # error "Do not know how to find your architecture's registers and syscalls"
 #endif
index bb543bf..361235a 100644 (file)
         ],
         "cmdUnderTest": "$TC filter add dev $DEV2 protocol ip pref 1 ingress flower dst_mac e4:11:22:11:4a:51 action drop",
         "expExitCode": "0",
-        "verifyCmd": "$TC filter show terse dev $DEV2 ingress",
+        "verifyCmd": "$TC -br filter show dev $DEV2 ingress",
         "matchPattern": "filter protocol ip pref 1 flower.*handle",
         "matchCount": "1",
         "teardown": [
         ],
         "cmdUnderTest": "$TC filter add dev $DEV2 protocol ip pref 1 ingress flower dst_mac e4:11:22:11:4a:51 action drop",
         "expExitCode": "0",
-        "verifyCmd": "$TC filter show terse dev $DEV2 ingress",
+        "verifyCmd": "$TC -br filter show dev $DEV2 ingress",
         "matchPattern": "  dst_mac e4:11:22:11:4a:51",
         "matchCount": "0",
         "teardown": [
index d77f482..74c69b7 100755 (executable)
@@ -316,6 +316,14 @@ pp sleep 3
 n2 ping -W 1 -c 1 192.168.241.1
 n1 wg set wg0 peer "$pub2" persistent-keepalive 0
 
+# Test that sk_bound_dev_if works
+n1 ping -I wg0 -c 1 -W 1 192.168.241.2
+# What about when the mark changes and the packet must be rerouted?
+n1 iptables -t mangle -I OUTPUT -j MARK --set-xmark 1
+n1 ping -c 1 -W 1 192.168.241.2 # First the boring case
+n1 ping -I wg0 -c 1 -W 1 192.168.241.2 # Then the sk_bound_dev_if case
+n1 iptables -t mangle -D OUTPUT -j MARK --set-xmark 1
+
 # Test that onion routing works, even when it loops
 n1 wg set wg0 peer "$pub3" allowed-ips 192.168.242.2/32 endpoint 192.168.241.2:5
 ip1 addr add 192.168.242.1/24 dev wg0
index d531de1..4eecb43 100644 (file)
@@ -18,10 +18,12 @@ CONFIG_NF_NAT=y
 CONFIG_NETFILTER_XTABLES=y
 CONFIG_NETFILTER_XT_NAT=y
 CONFIG_NETFILTER_XT_MATCH_LENGTH=y
+CONFIG_NETFILTER_XT_MARK=y
 CONFIG_NF_CONNTRACK_IPV4=y
 CONFIG_NF_NAT_IPV4=y
 CONFIG_IP_NF_IPTABLES=y
 CONFIG_IP_NF_FILTER=y
+CONFIG_IP_NF_MANGLE=y
 CONFIG_IP_NF_NAT=y
 CONFIG_IP_ADVANCED_ROUTER=y
 CONFIG_IP_MULTIPLE_TABLES=y