* [PATCH RESEND] iommu/amd: Fix domain flush size when syncing iotlb
@ 2023-05-18 1:50 Jon Pan-Doh
2023-05-19 17:11 ` Jerry Snitselaar
0 siblings, 1 reply; 2+ messages in thread
From: Jon Pan-Doh @ 2023-05-18 1:50 UTC (permalink / raw)
To: Joerg Roedel, Suravee Suthikulpanit
Cc: Will Deacon, Robin Murphy, iommu, linux-kernel, Jon Pan-Doh,
stable, Gary Zibrat, Sudheer Dantuluri, Nadav Amit, Vasant Hegde
When running on an AMD vIOMMU, we observed multiple invalidations (of
decreasing power of 2 aligned sizes) when unmapping a single page.
Domain flush takes gather bounds (end-start) as size param. However,
gather->end is defined as the last inclusive address (start + size - 1).
This leads to an off by 1 error.
With this patch, verified that 1 invalidation occurs when unmapping a
single page.
Fixes: a270be1b3fdf ("iommu/amd: Use only natural aligned flushes in a VM")
Cc: <stable@vger.kernel.org> # 5.15.x
Suggested-by: Gary Zibrat <gzibrat@google.com>
Tested-by: Sudheer Dantuluri <dantuluris@google.com>
Acked-by: Nadav Amit <namit@vmware.com>
Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
Signed-off-by: Jon Pan-Doh <pandoh@google.com>
---
drivers/iommu/amd/iommu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 5a505ba5467e..da45b1ab042d 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2378,7 +2378,7 @@ static void amd_iommu_iotlb_sync(struct iommu_domain *domain,
unsigned long flags;
spin_lock_irqsave(&dom->lock, flags);
- domain_flush_pages(dom, gather->start, gather->end - gather->start, 1);
+ domain_flush_pages(dom, gather->start, gather->end - gather->start + 1, 1);
amd_iommu_domain_flush_complete(dom);
spin_unlock_irqrestore(&dom->lock, flags);
}
--
2.40.0.634.g4ca3ef3211-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH RESEND] iommu/amd: Fix domain flush size when syncing iotlb
2023-05-18 1:50 [PATCH RESEND] iommu/amd: Fix domain flush size when syncing iotlb Jon Pan-Doh
@ 2023-05-19 17:11 ` Jerry Snitselaar
0 siblings, 0 replies; 2+ messages in thread
From: Jerry Snitselaar @ 2023-05-19 17:11 UTC (permalink / raw)
To: Jon Pan-Doh
Cc: Joerg Roedel, Suravee Suthikulpanit, Will Deacon, Robin Murphy,
iommu, linux-kernel, stable, Gary Zibrat, Sudheer Dantuluri,
Nadav Amit, Vasant Hegde
On Wed, May 17, 2023 at 06:50:54PM -0700, Jon Pan-Doh wrote:
> When running on an AMD vIOMMU, we observed multiple invalidations (of
> decreasing power of 2 aligned sizes) when unmapping a single page.
>
> Domain flush takes gather bounds (end-start) as size param. However,
> gather->end is defined as the last inclusive address (start + size - 1).
> This leads to an off by 1 error.
>
> With this patch, verified that 1 invalidation occurs when unmapping a
> single page.
>
> Fixes: a270be1b3fdf ("iommu/amd: Use only natural aligned flushes in a VM")
> Cc: <stable@vger.kernel.org> # 5.15.x
> Suggested-by: Gary Zibrat <gzibrat@google.com>
> Tested-by: Sudheer Dantuluri <dantuluris@google.com>
> Acked-by: Nadav Amit <namit@vmware.com>
> Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
> Signed-off-by: Jon Pan-Doh <pandoh@google.com>
> ---
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com
> drivers/iommu/amd/iommu.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index 5a505ba5467e..da45b1ab042d 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -2378,7 +2378,7 @@ static void amd_iommu_iotlb_sync(struct iommu_domain *domain,
> unsigned long flags;
>
> spin_lock_irqsave(&dom->lock, flags);
> - domain_flush_pages(dom, gather->start, gather->end - gather->start, 1);
> + domain_flush_pages(dom, gather->start, gather->end - gather->start + 1, 1);
> amd_iommu_domain_flush_complete(dom);
> spin_unlock_irqrestore(&dom->lock, flags);
> }
> --
> 2.40.0.634.g4ca3ef3211-goog
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-05-19 17:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-18 1:50 [PATCH RESEND] iommu/amd: Fix domain flush size when syncing iotlb Jon Pan-Doh
2023-05-19 17:11 ` Jerry Snitselaar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox