linux-stable/drivers/iommu
Suravee Suthikulpanit 2efa79e892 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:04:55 -07:00
..
amd_iommu.c iommu/amd: Fix IOMMU page flush when detach device from a domain 2019-03-13 14:04:55 -07:00
amd_iommu_init.c iommu/amd: Use standard bitmap operation to set bitmap 2016-09-19 15:49:01 +02:00
amd_iommu_proto.h Merge branch 'x86/amd-avic' into x86/amd 2016-09-05 12:43:16 +02:00
amd_iommu_types.h KVM updates for v4.9-rc1 2016-10-06 10:49:01 -07:00
amd_iommu_v2.c iommu/amd: Fix incorrect error handling in amd_iommu_bind_pasid() 2017-07-05 14:40:30 +02:00
arm-smmu-v3.c iommu/arm-smmu-v3: Use explicit mb() when moving cons pointer 2019-02-12 19:44:54 +01:00
arm-smmu.c iommu/arm-smmu: Add support for qcom,smmu-v2 variant 2019-02-12 19:44:54 +01:00
dma-iommu.c iommu/dma: Don't reserve PCI I/O windows 2017-07-05 14:40:30 +02:00
dmar.c iommu/vt-d: Fix dev iotlb pfsid use 2018-09-09 20:01:24 +02:00
exynos-iommu.c iommu/exynos: Workaround FLPD cache flush issues for SYSMMU v5 2017-12-25 14:23:39 +01:00
fsl_pamu.c
fsl_pamu.h
fsl_pamu_domain.c
fsl_pamu_domain.h
intel-iommu.c iommu/vt-d: Handle domain agaw being less than iommu agaw 2019-01-13 10:03:53 +01:00
intel-svm.c iommu/vt-d: Fix NULL pointer dereference in prq_event_thread() 2018-12-13 09:20:25 +01:00
intel_irq_remapping.c
io-pgtable-arm-v7s.c iommu/io-pgtable-arm-v7s: Check for leaf entry before dereferencing it 2017-12-20 10:07:19 +01:00
io-pgtable-arm.c iommu/io-pgtable-arm: Check for leaf entry before dereferencing it 2017-10-08 10:26:10 +02:00
io-pgtable.c
io-pgtable.h
iommu-sysfs.c
iommu-traces.c
iommu.c iommu: Handle default domain attach failure 2017-07-05 14:40:30 +02:00
iova.c iommu/iova: Fix underflow bug in __alloc_and_insert_iova_range 2018-03-22 09:17:48 +01:00
ipmmu-vmsa.c iommu/ipmmu-vmsa: Fix crash on early domain free 2018-12-13 09:20:25 +01:00
irq_remapping.c x86/cpufeature: Replace cpu_has_apic with boot_cpu_has() usage 2016-04-13 11:37:41 +02:00
irq_remapping.h
Kconfig iommu/arm-smmu: Support non-PCI devices with SMMUv3 2016-09-16 09:34:17 +01:00
Makefile Merge branches 'x86/amd', 'x86/vt-d', 'arm/exynos', 'arm/mediatek', 'arm/msm', 'arm/rockchip', 'arm/smmu' and 'core' into next 2016-07-26 16:02:37 +02:00
msm_iommu.c iommu/msm: use generic ARMV7S short descriptor pagetable ops 2016-06-21 13:57:13 +02:00
msm_iommu.h iommu/msm: Add DT adaptation 2016-06-21 13:56:00 +02:00
msm_iommu_hw-8xxx.h
mtk_iommu.c iommu/mediatek: move the common struct into header file 2016-06-21 11:36:19 +02:00
mtk_iommu.h iommu/mediatek: Mark static functions in headers inline 2016-08-09 15:46:46 +02:00
mtk_iommu_v1.c iommu/mediatek: Fix driver name 2017-12-20 10:07:28 +01:00
of_iommu.c iommu: Introduce iommu_fwspec 2016-09-16 09:34:15 +01:00
omap-iommu-debug.c
omap-iommu.c iommu/omap: Register driver before setting IOMMU ops 2018-03-24 11:00:12 +01:00
omap-iommu.h
omap-iopgtable.h
rockchip-iommu.c iommu/rockchip: Prepare to support generic DMA mapping 2016-06-27 14:50:08 +02:00
s390-iommu.c iommu/s390: simplify registration of I/O address translation parameters 2016-09-22 13:42:28 +02:00
tegra-gart.c
tegra-smmu.c