Skip to content

Commit c5ebd09

Browse files
hegdevasantjoergroedel
authored andcommitted
iommu/amd: Introduce per device DTE update function
Consolidate per device update and flush logic into separate function. Also make it as global function as it will be used in subsequent series to update the DTE. Signed-off-by: Vasant Hegde <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 9433d5b commit c5ebd09

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

drivers/iommu/amd/amd_iommu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ int amd_iommu_clear_gcr3(struct iommu_dev_data *dev_data, ioasid_t pasid);
5656
void amd_iommu_flush_all_caches(struct amd_iommu *iommu);
5757
void amd_iommu_update_and_flush_device_table(struct protection_domain *domain);
5858
void amd_iommu_domain_update(struct protection_domain *domain);
59+
void amd_iommu_dev_update_dte(struct iommu_dev_data *dev_data, bool set);
5960
void amd_iommu_domain_flush_complete(struct protection_domain *domain);
6061
void amd_iommu_domain_flush_pages(struct protection_domain *domain,
6162
u64 address, size_t size);

drivers/iommu/amd/iommu.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,21 @@ static void clear_dte_entry(struct amd_iommu *iommu, u16 devid)
20022002
amd_iommu_apply_erratum_63(iommu, devid);
20032003
}
20042004

2005+
/* Update and flush DTE for the given device */
2006+
void amd_iommu_dev_update_dte(struct iommu_dev_data *dev_data, bool set)
2007+
{
2008+
struct amd_iommu *iommu = get_amd_iommu_from_dev(dev_data->dev);
2009+
2010+
if (set)
2011+
set_dte_entry(iommu, dev_data);
2012+
else
2013+
clear_dte_entry(iommu, dev_data->devid);
2014+
2015+
clone_aliases(iommu, dev_data->dev);
2016+
device_flush_dte(dev_data);
2017+
iommu_completion_wait(iommu);
2018+
}
2019+
20052020
static int do_attach(struct iommu_dev_data *dev_data,
20062021
struct protection_domain *domain)
20072022
{
@@ -2036,10 +2051,7 @@ static int do_attach(struct iommu_dev_data *dev_data,
20362051
}
20372052

20382053
/* Update device table */
2039-
set_dte_entry(iommu, dev_data);
2040-
clone_aliases(iommu, dev_data->dev);
2041-
2042-
device_flush_dte(dev_data);
2054+
amd_iommu_dev_update_dte(dev_data, true);
20432055

20442056
return ret;
20452057
}
@@ -2058,11 +2070,9 @@ static void do_detach(struct iommu_dev_data *dev_data)
20582070
/* Update data structures */
20592071
dev_data->domain = NULL;
20602072
list_del(&dev_data->list);
2061-
clear_dte_entry(iommu, dev_data->devid);
2062-
clone_aliases(iommu, dev_data->dev);
20632073

2064-
/* Flush the DTE entry */
2065-
device_flush_dte(dev_data);
2074+
/* Clear DTE and flush the entry */
2075+
amd_iommu_dev_update_dte(dev_data, false);
20662076

20672077
/* Flush IOTLB and wait for the flushes to finish */
20682078
amd_iommu_domain_flush_all(domain);

0 commit comments

Comments
 (0)