Skip to content

Commit c362f32

Browse files
hegdevasantjoergroedel
authored andcommitted
iommu/amd: Invalidate cache before removing device from domain list
Commit 87a6f1f ("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 <[email protected]> Reported-by: Dheeraj Kumar Srivastava <[email protected]> Fixes: 87a6f1f ("iommu/amd: Introduce per-device domain ID to fix potential TLB aliasing issue") Tested-by: Dheeraj Kumar Srivastava <[email protected]> Tested-by: Sairaj Arun Kodilkar <[email protected]> Tested-by: FahHean Lee <[email protected]> Signed-off-by: Vasant Hegde <[email protected]> Reviewed-by: Jerry Snitselaar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent f266106 commit c362f32

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/iommu/amd/iommu.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,12 @@ static void do_detach(struct iommu_dev_data *dev_data)
20612061
struct protection_domain *domain = dev_data->domain;
20622062
struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data);
20632063

2064+
/* Clear DTE and flush the entry */
2065+
amd_iommu_dev_update_dte(dev_data, false);
2066+
2067+
/* Flush IOTLB and wait for the flushes to finish */
2068+
amd_iommu_domain_flush_all(domain);
2069+
20642070
/* Clear GCR3 table */
20652071
if (pdom_is_sva_capable(domain))
20662072
destroy_gcr3_table(dev_data, domain);
@@ -2069,12 +2075,6 @@ static void do_detach(struct iommu_dev_data *dev_data)
20692075
dev_data->domain = NULL;
20702076
list_del(&dev_data->list);
20712077

2072-
/* Clear DTE and flush the entry */
2073-
amd_iommu_dev_update_dte(dev_data, false);
2074-
2075-
/* Flush IOTLB and wait for the flushes to finish */
2076-
amd_iommu_domain_flush_all(domain);
2077-
20782078
/* decrease reference counters - needs to happen after the flushes */
20792079
domain->dev_iommu[iommu->index] -= 1;
20802080
domain->dev_cnt -= 1;

0 commit comments

Comments
 (0)