All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/1] Don't split flush for amd_iommu_domain_flush_all()
@ 2026-05-28 22:31 Weinan Liu
  2026-05-28 22:31 ` [PATCH v2 1/1] iommu/amd: " Weinan Liu
  2026-06-02  8:46 ` [PATCH v2 0/1] " Jörg Rödel
  0 siblings, 2 replies; 4+ messages in thread
From: Weinan Liu @ 2026-05-28 22:31 UTC (permalink / raw)
  To: iommu, jgg, joro, suravee.suthikulpanit
  Cc: will, patches, stable, robin.murphy, vasant.hegde, santosh.shukla,
	chrisl, josef, Weinan Liu

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

-- 
2.54.0.823.g6e5bcc1fc9-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/1] iommu/amd: Don't split flush for amd_iommu_domain_flush_all()
  2026-05-28 22:31 [PATCH v2 0/1] Don't split flush for amd_iommu_domain_flush_all() Weinan Liu
@ 2026-05-28 22:31 ` Weinan Liu
  2026-05-29  5:18   ` Vasant Hegde
  2026-06-02  8:46 ` [PATCH v2 0/1] " Jörg Rödel
  1 sibling, 1 reply; 4+ messages in thread
From: Weinan Liu @ 2026-05-28 22:31 UTC (permalink / raw)
  To: iommu, jgg, joro, suravee.suthikulpanit
  Cc: will, patches, stable, robin.murphy, vasant.hegde, santosh.shukla,
	chrisl, josef, Weinan Liu, Wei Wang, Samiullah Khawaja

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

Cc: stable@vger.kernel.org
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>
Reviewed-by: Wei Wang <wei.w.wang@hotmail.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Samiullah Khawaja <skhawaja@google.com>
Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
---
 drivers/iommu/amd/iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 57dc8fabc7d9..15ffc4742183 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -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 */
-- 
2.54.0.823.g6e5bcc1fc9-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1] iommu/amd: Don't split flush for amd_iommu_domain_flush_all()
  2026-05-28 22:31 ` [PATCH v2 1/1] iommu/amd: " Weinan Liu
@ 2026-05-29  5:18   ` Vasant Hegde
  0 siblings, 0 replies; 4+ messages in thread
From: Vasant Hegde @ 2026-05-29  5:18 UTC (permalink / raw)
  To: Weinan Liu, iommu, jgg, joro, suravee.suthikulpanit
  Cc: will, patches, stable, robin.murphy, santosh.shukla, chrisl,
	josef, Wei Wang, Samiullah Khawaja



On 5/29/2026 4:01 AM, 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().
> 
> Cc: stable@vger.kernel.org
> 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>
> Reviewed-by: Wei Wang <wei.w.wang@hotmail.com>
> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
> Reviewed-by: Samiullah Khawaja <skhawaja@google.com>
> Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>


Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>


-Vasant


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/1] Don't split flush for amd_iommu_domain_flush_all()
  2026-05-28 22:31 [PATCH v2 0/1] Don't split flush for amd_iommu_domain_flush_all() Weinan Liu
  2026-05-28 22:31 ` [PATCH v2 1/1] iommu/amd: " Weinan Liu
@ 2026-06-02  8:46 ` Jörg Rödel
  1 sibling, 0 replies; 4+ messages in thread
From: Jörg Rödel @ 2026-06-02  8:46 UTC (permalink / raw)
  To: Weinan Liu
  Cc: iommu, jgg, suravee.suthikulpanit, will, patches, stable,
	robin.murphy, vasant.hegde, santosh.shukla, chrisl, josef

On Thu, May 28, 2026 at 10:31:46PM +0000, Weinan Liu wrote:
> 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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-06-02  8:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-28 22:31 [PATCH v2 0/1] Don't split flush for amd_iommu_domain_flush_all() Weinan Liu
2026-05-28 22:31 ` [PATCH v2 1/1] iommu/amd: " Weinan Liu
2026-05-29  5:18   ` Vasant Hegde
2026-06-02  8:46 ` [PATCH v2 0/1] " Jörg Rödel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.