Skip to contentSkip to conversation

Don't split flush for amd_iommu_domain_flush_all()

PATCH Applied Weinan Liu 3 participants 4 messages May 28 – Jun 2

Subsystems (3)
lore
Share & tools
lore

Weinan Liu

author
#0 lore raw

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

[1]:https://lore.kernel.org/linux-iommu/ad8652c5e9f8aeee05e2103f4987589cdd4a3fd0.1772659768.git.josef@toxicpanda.com

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
author
#1 lore raw

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
index 57dc8fabc7d9..15ffc4742183 100644
@@ -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
maintainer Reviewed-by on v2 1/1
#2 lore raw

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 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().

Quoted 9 lines

-Vasant

maintainer Applied
#3 lore raw
In reply to Weinan Liu
Quoted 5 lines · Weinan Liu

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(-)

Applied, thanks.