Don't split flush for amd_iommu_domain_flush_all()
Subsystems (3)
v2 cover Don't split flush for amd_iommu_domain_flush_all()
This patch is a respin of Josef Bacik's original work[1] to fix the performance issues and soft lockups in the AMD IOMMU driver when running within a VM. I am taking over the respin as Josef currently has limited time for this
Changes in v2:
* Update the patch according to comments of v1
Weinan Liu (1):
iommu/amd: Don't split flush for amd_iommu_domain_flush_all()
drivers/iommu/amd/iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.54.0.823.g6e5bcc1fc9-goog
PATCH v2 1/1 iommu/amd: Don't split flush for amd_iommu_domain_flush_all()
We have observed multiple full invalidations occurring during device detach when we are done using the vfio-device.
blocked_domain_attach_device()
-> detach_device()
-> amd_iommu_domain_flush_all()
-> amd_iommu_domain_flush_pages(..., CMD_INV_IOMMU_ALL_PAGES_ADDRESS)
while (size != 0) {
-> __domain_flush_pages( flush_size /* power of 2 flush_size */)
-> domain_flush_pages_v1()
-> build_inv_iommu_pages()
-> build_inv_address()
}build_inv_address() will trigger a full invalidation if the chunk size > (1 << 51). Consequently, the guest will issue multiple full invalidations for a single call to amd_iommu_domain_flush_all()
Without this patch, we will see 10 time instead of 1 time full invalidations for every amd_iommu_domain_flush_all().
--- drivers/iommu/amd/iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/amd/iommu.c +2 -1
@@ -1774,7 +1774,8 @@ void amd_iommu_domain_flush_pages(struct protection_domain *domain, {lockdep_assert_held (&domain->lock); -if (likely (!amd_iommu_np_cache)) { +if (likely (!amd_iommu_np_cache) || + size >= (1ULL <<52 )) {__domain_flush_pages (domain, address, size);/* Wait until IOMMU TLB and all device IOTLB flushes are complete */
Signature · 1 line
2.54.0.823.g6e5bcc1fc9-goog
Re: [PATCH v2 1/1] iommu/amd: Don't split flush for amd_iommu_domain_flush_all()
Quoted 24 lines · Weinan Liu
We have observed multiple full invalidations occurring during device detach when we are done using the vfio-device.
blocked_domain_attach_device()
->detach_device()-> amd_iommu_domain_flush_all() -> amd_iommu_domain_flush_pages(..., CMD_INV_IOMMU_ALL_PAGES_ADDRESS) while (size != 0) { -> __domain_flush_pages( flush_size /* power of 2 flush_size */) -> domain_flush_pages_v1() -> build_inv_iommu_pages() -> build_inv_address() }
build_inv_address()will trigger a full invalidation if the chunk size > (1 << 51). Consequently, the guest will issue multiple full invalidations for a single call toamd_iommu_domain_flush_all()Without this patch, we will see 10 time instead of 1 time full invalidations for every
amd_iommu_domain_flush_all().
Quoted 9 lines
Fixes a270be1b3fdf ("iommu/amd: Use only natural aligned flushes in a VM")Suggested-by Josef Bacik <[email protected]>Suggested-by Jason Gunthorpe <[email protected]>Signed-off-by Weinan Liu <[email protected]>Reviewed-by Wei Wang <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>Reviewed-by Samiullah Khawaja <[email protected]>Reviewed-by Suravee Suthikulpanit <[email protected]>
-Vasant
Quoted 5 lines · Weinan Liu
Weinan Liu (1):
iommu/amd: Don't split flush foramd_iommu_domain_flush_all()drivers/iommu/amd/iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Applied, thanks.