Re: [PATCH v1 1/1] iommu/amd: Don't split flush for amd_iommu_domain_flush_all()

Jason Gunthorpe
2026-04-17T11:57:15Z

On Wed, Apr 15, 2026 at 12:30:46AM +0000, Weinan Liu wrote:
> 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().
>
> Fixes: a270be1b3fdf ("iommu/amd: Use only natural aligned flushes in a VM")
>
> Suggested-by: Josef Bacik <josef@toxicpanda.com>
> Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
> Signed-off-by: Weinan Liu <wnliu@google.com>
> ---
> drivers/iommu/amd/iommu.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

Jason