All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH rc] iommu/amd: Invalidate cache before removing device from domain list
@ 2024-06-20  6:05 Vasant Hegde
  2024-06-25 12:05 ` Joerg Roedel
  2024-06-25 19:38 ` Jerry Snitselaar
  0 siblings, 2 replies; 3+ messages in thread
From: Vasant Hegde @ 2024-06-20  6:05 UTC (permalink / raw)
  To: iommu, joro
  Cc: suravee.suthikulpanit, Vasant Hegde, FahHean Lee,
	Dheeraj Kumar Srivastava, Sairaj Arun Kodilkar

Commit 87a6f1f22c97 ("iommu/amd: Introduce per-device domain ID to fix
potential TLB aliasing issue") introduced per device domain ID when
domain is configured with v2 page table. And in invalidation path, it
uses per device structure (dev_data->gcr3_info.domid) to get the domain ID.

In detach_device() path, current code tries to invalidate IOMMU cache
after removing dev_data from domain device list. This means when domain
is configured with v2 page table, amd_iommu_domain_flush_all() will not be
able to invalidate cache as device is already removed from domain device
list.

This is causing change domain tests (changing domain type from identity to DMA)
to fail with IO_PAGE_FAULT issue.

Hence invalidate cache and update DTE before updating data structures.

Reported-by: FahHean Lee <fahhean.lee@amd.com>
Reported-by: Dheeraj Kumar Srivastava <dheerajkumar.srivastava@amd.com>
Fixes: 87a6f1f22c97 ("iommu/amd: Introduce per-device domain ID to fix potential TLB aliasing issue")
Tested-by: Dheeraj Kumar Srivastava <dheerajkumar.srivastava@amd.com>
Tested-by: Sairaj Arun Kodilkar <sairaj.arunkodilkar@amd.com>
Tested-by: FahHean Lee <fahhean.lee@amd.com>
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
---
 drivers/iommu/amd/iommu.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index c2703599bb16..b19e8c0f48fa 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2061,6 +2061,12 @@ static void do_detach(struct iommu_dev_data *dev_data)
 	struct protection_domain *domain = dev_data->domain;
 	struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data);
 
+	/* Clear DTE and flush the entry */
+	amd_iommu_dev_update_dte(dev_data, false);
+
+	/* Flush IOTLB and wait for the flushes to finish */
+	amd_iommu_domain_flush_all(domain);
+
 	/* Clear GCR3 table */
 	if (pdom_is_sva_capable(domain))
 		destroy_gcr3_table(dev_data, domain);
@@ -2069,12 +2075,6 @@ static void do_detach(struct iommu_dev_data *dev_data)
 	dev_data->domain = NULL;
 	list_del(&dev_data->list);
 
-	/* Clear DTE and flush the entry */
-	amd_iommu_dev_update_dte(dev_data, false);
-
-	/* Flush IOTLB and wait for the flushes to finish */
-	amd_iommu_domain_flush_all(domain);
-
 	/* decrease reference counters - needs to happen after the flushes */
 	domain->dev_iommu[iommu->index] -= 1;
 	domain->dev_cnt                 -= 1;
-- 
2.31.1


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

* Re: [PATCH rc] iommu/amd: Invalidate cache before removing device from domain list
  2024-06-20  6:05 [PATCH rc] iommu/amd: Invalidate cache before removing device from domain list Vasant Hegde
@ 2024-06-25 12:05 ` Joerg Roedel
  2024-06-25 19:38 ` Jerry Snitselaar
  1 sibling, 0 replies; 3+ messages in thread
From: Joerg Roedel @ 2024-06-25 12:05 UTC (permalink / raw)
  To: Vasant Hegde
  Cc: iommu, suravee.suthikulpanit, FahHean Lee,
	Dheeraj Kumar Srivastava, Sairaj Arun Kodilkar

On Thu, Jun 20, 2024 at 06:05:52AM +0000, Vasant Hegde wrote:
>  drivers/iommu/amd/iommu.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)

Applied, thanks.

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

* Re: [PATCH rc] iommu/amd: Invalidate cache before removing device from domain list
  2024-06-20  6:05 [PATCH rc] iommu/amd: Invalidate cache before removing device from domain list Vasant Hegde
  2024-06-25 12:05 ` Joerg Roedel
@ 2024-06-25 19:38 ` Jerry Snitselaar
  1 sibling, 0 replies; 3+ messages in thread
From: Jerry Snitselaar @ 2024-06-25 19:38 UTC (permalink / raw)
  To: Vasant Hegde
  Cc: iommu, joro, suravee.suthikulpanit, FahHean Lee,
	Dheeraj Kumar Srivastava, Sairaj Arun Kodilkar

On Thu, Jun 20, 2024 at 06:05:52AM GMT, Vasant Hegde wrote:
> Commit 87a6f1f22c97 ("iommu/amd: Introduce per-device domain ID to fix
> potential TLB aliasing issue") introduced per device domain ID when
> domain is configured with v2 page table. And in invalidation path, it
> uses per device structure (dev_data->gcr3_info.domid) to get the domain ID.
> 
> In detach_device() path, current code tries to invalidate IOMMU cache
> after removing dev_data from domain device list. This means when domain
> is configured with v2 page table, amd_iommu_domain_flush_all() will not be
> able to invalidate cache as device is already removed from domain device
> list.
> 
> This is causing change domain tests (changing domain type from identity to DMA)
> to fail with IO_PAGE_FAULT issue.
> 
> Hence invalidate cache and update DTE before updating data structures.
> 
> Reported-by: FahHean Lee <fahhean.lee@amd.com>
> Reported-by: Dheeraj Kumar Srivastava <dheerajkumar.srivastava@amd.com>
> Fixes: 87a6f1f22c97 ("iommu/amd: Introduce per-device domain ID to fix potential TLB aliasing issue")
> Tested-by: Dheeraj Kumar Srivastava <dheerajkumar.srivastava@amd.com>
> Tested-by: Sairaj Arun Kodilkar <sairaj.arunkodilkar@amd.com>
> Tested-by: FahHean Lee <fahhean.lee@amd.com>
> Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>

Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>

> ---
>  drivers/iommu/amd/iommu.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index c2703599bb16..b19e8c0f48fa 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -2061,6 +2061,12 @@ static void do_detach(struct iommu_dev_data *dev_data)
>  	struct protection_domain *domain = dev_data->domain;
>  	struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data);
>  
> +	/* Clear DTE and flush the entry */
> +	amd_iommu_dev_update_dte(dev_data, false);
> +
> +	/* Flush IOTLB and wait for the flushes to finish */
> +	amd_iommu_domain_flush_all(domain);
> +
>  	/* Clear GCR3 table */
>  	if (pdom_is_sva_capable(domain))
>  		destroy_gcr3_table(dev_data, domain);
> @@ -2069,12 +2075,6 @@ static void do_detach(struct iommu_dev_data *dev_data)
>  	dev_data->domain = NULL;
>  	list_del(&dev_data->list);
>  
> -	/* Clear DTE and flush the entry */
> -	amd_iommu_dev_update_dte(dev_data, false);
> -
> -	/* Flush IOTLB and wait for the flushes to finish */
> -	amd_iommu_domain_flush_all(domain);
> -
>  	/* decrease reference counters - needs to happen after the flushes */
>  	domain->dev_iommu[iommu->index] -= 1;
>  	domain->dev_cnt                 -= 1;
> -- 
> 2.31.1
> 


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

end of thread, other threads:[~2024-06-25 19:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-20  6:05 [PATCH rc] iommu/amd: Invalidate cache before removing device from domain list Vasant Hegde
2024-06-25 12:05 ` Joerg Roedel
2024-06-25 19:38 ` Jerry Snitselaar

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.