linux-stable/drivers/iommu
Suravee Suthikulpanit a038ed686a iommu/amd: Fix IOMMU page flush when detach device from a domain
[ Upstream commit 9825bd94e3 ]

When a VM is terminated, the VFIO driver detaches all pass-through
devices from VFIO domain by clearing domain id and page table root
pointer from each device table entry (DTE), and then invalidates
the DTE. Then, the VFIO driver unmap pages and invalidate IOMMU pages.

Currently, the IOMMU driver keeps track of which IOMMU and how many
devices are attached to the domain. When invalidate IOMMU pages,
the driver checks if the IOMMU is still attached to the domain before
issuing the invalidate page command.

However, since VFIO has already detached all devices from the domain,
the subsequent INVALIDATE_IOMMU_PAGES commands are being skipped as
there is no IOMMU attached to the domain. This results in data
corruption and could cause the PCI device to end up in indeterministic
state.

Fix this by invalidate IOMMU pages when detach a device, and
before decrementing the per-domain device reference counts.

Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Suggested-by: Joerg Roedel <joro@8bytes.org>
Co-developed-by: Brijesh Singh <brijesh.singh@amd.com>
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Fixes: 6de8ad9b9e ('x86/amd-iommu: Make iommu_flush_pages aware of multiple IOMMUs')
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-03-13 14:02:27 -07:00
..
amd_iommu.c iommu/amd: Fix IOMMU page flush when detach device from a domain 2019-03-13 14:02:27 -07:00
amd_iommu_debugfs.c iommu/amd: Add basic debugfs infrastructure for AMD IOMMU 2018-07-06 14:06:30 +02:00
amd_iommu_init.c amd/iommu: Fix Guest Virtual APIC Log Tail Address Register 2018-12-13 09:16:10 +01:00
amd_iommu_proto.h iommu/amd: Add basic debugfs infrastructure for AMD IOMMU 2018-07-06 14:06:30 +02:00
amd_iommu_types.h Merge branches 'arm/shmobile', 'arm/renesas', 'arm/msm', 'arm/smmu', 'arm/omap', 'x86/amd', 'x86/vt-d' and 'core' into next 2018-08-08 12:02:27 +02:00
amd_iommu_v2.c mm: convert return type of handle_mm_fault() caller to vm_fault_t 2018-08-17 16:20:28 -07:00
arm-smmu-regs.h iommu/arm-smmu: Split out register defines 2017-08-15 17:34:48 +02:00
arm-smmu-v3.c iommu/arm-smmu-v3: Use explicit mb() when moving cons pointer 2019-02-12 19:47:07 +01:00
arm-smmu.c iommu/arm-smmu: Add support for qcom,smmu-v2 variant 2019-02-12 19:47:07 +01:00
dma-iommu.c iommu/dma: Respect bus DMA limit for IOVAs 2018-07-27 19:01:06 +02:00
dmar.c iommu/vt-d: Fix dev iotlb pfsid use 2018-07-06 13:26:10 +02:00
exynos-iommu.c IOMMU Update for Linux v4.19 2018-08-24 13:10:38 -07:00
fsl_pamu.c Merge branches 'arm/exynos', 'arm/renesas', 'arm/rockchip', 'arm/omap', 'arm/mediatek', 'arm/tegra', 'arm/qcom', 'arm/smmu', 'ppc/pamu', 'x86/vt-d', 'x86/amd', 's390' and 'core' into next 2017-09-01 11:31:42 +02:00
fsl_pamu.h iommu/pamu: Fix PAMU boot crash 2017-08-23 16:28:09 +02:00
fsl_pamu_domain.c Merge branches 'arm/exynos', 'arm/renesas', 'arm/rockchip', 'arm/omap', 'arm/mediatek', 'arm/tegra', 'arm/qcom', 'arm/smmu', 'ppc/pamu', 'x86/vt-d', 'x86/amd', 's390' and 'core' into next 2017-09-01 11:31:42 +02:00
fsl_pamu_domain.h iommu/pamu: Fix PAMU boot crash 2017-08-23 16:28:09 +02:00
intel-iommu.c iommu/vt-d: Fix memory leak in intel_iommu_put_resv_regions() 2019-02-06 17:30:11 +01:00
intel-pasid.c iommu/vt-d: Per PCI device pasid table interfaces 2018-07-20 14:44:24 +02:00
intel-pasid.h iommu/vt-d: Handle memory shortage on pasid table allocation 2018-09-25 14:33:02 +02:00
intel-svm.c iommu/vt-d: Fix NULL pointer dereference in prq_event_thread() 2018-12-13 09:16:09 +01:00
intel_irq_remapping.c irq_remapping: Use apic_ack_irq() 2018-06-06 15:18:20 +02:00
io-pgtable-arm-v7s.c iommu/io-pgtable-arm-v7s: Abort allocation when table address overflows the PTE 2018-07-26 11:34:58 +01:00
io-pgtable-arm.c iommu/io-pgtable-arm: Fix pgtable allocation in selftest 2018-07-26 11:34:58 +01:00
io-pgtable.c
io-pgtable.h iommu/io-pgtable: Use size_t return type for all foo_unmap 2018-02-13 19:31:32 +01:00
iommu-debugfs.c iommu: Enable debugfs exposure of IOMMU driver internals 2018-07-06 14:06:30 +02:00
iommu-sysfs.c iommu: Fix wrong freeing of iommu_device->dev 2017-08-15 13:58:48 +02:00
iommu-traces.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
iommu.c iommu: Remove the ->map_sg indirection 2018-08-08 11:06:20 +02:00
iova.c treewide: setup_timer() -> timer_setup() 2017-11-21 15:57:07 -08:00
ipmmu-vmsa.c iommu/ipmmu-vmsa: Fix crash on early domain free 2018-12-13 09:16:10 +01:00
irq_remapping.c irq_remapping: Use apic_ack_irq() 2018-06-06 15:18:20 +02:00
irq_remapping.h irq_remapping: Use apic_ack_irq() 2018-06-06 15:18:20 +02:00
Kconfig Merge branches 'arm/shmobile', 'arm/renesas', 'arm/msm', 'arm/smmu', 'arm/omap', 'x86/amd', 'x86/vt-d' and 'core' into next 2018-08-08 12:02:27 +02:00
Makefile Merge branches 'arm/shmobile', 'arm/renesas', 'arm/msm', 'arm/smmu', 'arm/omap', 'x86/amd', 'x86/vt-d' and 'core' into next 2018-08-08 12:02:27 +02:00
msm_iommu.c IOMMU Update for Linux v4.19 2018-08-24 13:10:38 -07:00
msm_iommu.h
msm_iommu_hw-8xxx.h
mtk_iommu.c iommu: Remove the ->map_sg indirection 2018-08-08 11:06:20 +02:00
mtk_iommu.h iommu/mediatek: Fix protect memory setting 2018-03-21 06:13:57 -05:00
mtk_iommu_v1.c iommu: Remove the ->map_sg indirection 2018-08-08 11:06:20 +02:00
of_iommu.c iommu: Remove IOMMU_OF_DECLARE 2018-07-10 17:22:35 +02:00
omap-iommu-debug.c iommu/omap: Fix debugfs_create_*() usage 2018-01-17 14:23:33 +01:00
omap-iommu.c Merge branches 'arm/shmobile', 'arm/renesas', 'arm/msm', 'arm/smmu', 'arm/omap', 'x86/amd', 'x86/vt-d' and 'core' into next 2018-08-08 12:02:27 +02:00
omap-iommu.h iommu/omap: Add support to program multiple iommus 2017-09-19 11:32:05 +02:00
omap-iopgtable.h
qcom_iommu.c IOMMU Update for Linux v4.19 2018-08-24 13:10:38 -07:00
rockchip-iommu.c iommu/rockchip: Free irqs in shutdown handler 2018-09-25 11:13:34 +02:00
s390-iommu.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
tegra-gart.c iommu: Remove the ->map_sg indirection 2018-08-08 11:06:20 +02:00
tegra-smmu.c iommu: Remove the ->map_sg indirection 2018-08-08 11:06:20 +02:00