]> git.baikalelectronics.ru Git - kernel.git/commit
iommu/amd: Fix IOMMU page flush when detach device from a domain
authorSuravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Thu, 24 Jan 2019 04:16:45 +0000 (04:16 +0000)
committerJoerg Roedel <jroedel@suse.de>
Thu, 24 Jan 2019 14:24:49 +0000 (15:24 +0100)
commit4775badd2e98be5de0de56200776842746289d6a
tree55012b2ec1b640962a78be8894eb272c6424b408
parentf84acedd5854873dee0c90ff8ce6b62033ae4a9b
iommu/amd: Fix IOMMU page flush when detach device from a domain

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: 4c3e4f175eff ('x86/amd-iommu: Make iommu_flush_pages aware of multiple IOMMUs')
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/amd_iommu.c