iommu/amd: Invalidate cache before removing device from domain list
Subsystems (2)
Vasant Hegde
maintainerPATCH 1/1 iommu/amd: Invalidate cache before removing device from domain list
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.
--- drivers/iommu/amd/iommu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/iommu/amd/iommu.c +6 -6
@@ -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 ;
Signature · 1 line
2.31.1
Quoted 2 lines · Vasant Hegde
drivers/iommu/amd/iommu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
Applied, thanks.
Quoted 16 lines · Vasant Hegde
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 removingdev_datafrom 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_FAULTissue.Hence invalidate cache and update DTE before updating data structures.
Quoted 7 lines
Reported-by FahHean Lee <[email protected]>Reported-by Dheeraj Kumar Srivastava <[email protected]>Fixes 87a6f1f22c97 ("iommu/amd: Introduce per-device domain ID to fix potential TLB aliasing issue")Tested-by Sairaj Arun Kodilkar <[email protected]>Tested-by FahHean Lee <[email protected]>Signed-off-by Vasant Hegde <[email protected]>
Quoted 37 lines
--- drivers/iommu/amd/iommu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/iommu/amd/iommu.c +6
-6@@ -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 ;Signature · 1 line
2.31.1