aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasant Hegde <[email protected]>2024-10-30 06:35:52 +0000
committerJoerg Roedel <[email protected]>2024-10-30 11:06:45 +0100
commit4b18ef8491b06e353e8801705092cc292582cb7a (patch)
tree12be26f1f31affe40c61316ccec986e3f0c6ffad
parentd6b47dec368400a62d2b9d44c8e136fc15eac72c (diff)
iommu/amd: Rearrange attach device code
attach_device() is just holding lock and calling do_attach(). There is not need to have another function. Just move do_attach() code to attach_device(). Similarly move do_detach() code to detach_device(). Signed-off-by: Vasant Hegde <[email protected]> Reviewed-by: Joerg Roedel <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
-rw-r--r--drivers/iommu/amd/iommu.c91
1 files changed, 36 insertions, 55 deletions
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 7412e0bba2cd..4426e68de808 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2081,12 +2081,24 @@ static void pdom_detach_iommu(struct amd_iommu *iommu,
spin_unlock_irqrestore(&pdom->lock, flags);
}
-static int do_attach(struct iommu_dev_data *dev_data,
- struct protection_domain *domain)
+/*
+ * If a device is not yet associated with a domain, this function makes the
+ * device visible in the domain
+ */
+static int attach_device(struct device *dev,
+ struct protection_domain *domain)
{
+ struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev);
struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data);
int ret = 0;
+ spin_lock(&dev_data->lock);
+
+ if (dev_data->domain != NULL) {
+ ret = -EBUSY;
+ goto out;
+ }
+
/* Update data structures */
dev_data->domain = domain;
list_add(&dev_data->list, &domain->dev_list);
@@ -2094,67 +2106,17 @@ static int do_attach(struct iommu_dev_data *dev_data,
/* Do reference counting */
ret = pdom_attach_iommu(iommu, domain);
if (ret)
- return ret;
+ goto out;
/* Setup GCR3 table */
if (pdom_is_sva_capable(domain)) {
ret = init_gcr3_table(dev_data, domain);
if (ret) {
pdom_detach_iommu(iommu, domain);
- return ret;
+ goto out;
}
}
- return ret;
-}
-
-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);
- unsigned long flags;
-
- /* Clear DTE and flush the entry */
- dev_update_dte(dev_data, false);
-
- /* Flush IOTLB and wait for the flushes to finish */
- spin_lock_irqsave(&domain->lock, flags);
- amd_iommu_domain_flush_all(domain);
- spin_unlock_irqrestore(&domain->lock, flags);
-
- /* Clear GCR3 table */
- if (pdom_is_sva_capable(domain))
- destroy_gcr3_table(dev_data, domain);
-
- /* Update data structures */
- dev_data->domain = NULL;
- list_del(&dev_data->list);
-
- /* decrease reference counters - needs to happen after the flushes */
- pdom_detach_iommu(iommu, domain);
-}
-
-/*
- * If a device is not yet associated with a domain, this function makes the
- * device visible in the domain
- */
-static int attach_device(struct device *dev,
- struct protection_domain *domain)
-{
- struct iommu_dev_data *dev_data;
- int ret = 0;
-
- dev_data = dev_iommu_priv_get(dev);
-
- spin_lock(&dev_data->lock);
-
- if (dev_data->domain != NULL) {
- ret = -EBUSY;
- goto out;
- }
-
- ret = do_attach(dev_data, domain);
-
out:
spin_unlock(&dev_data->lock);
@@ -2168,7 +2130,9 @@ static void detach_device(struct device *dev)
{
struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev);
struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data);
+ struct protection_domain *domain = dev_data->domain;
bool ppr = dev_data->ppr;
+ unsigned long flags;
spin_lock(&dev_data->lock);
@@ -2188,7 +2152,24 @@ static void detach_device(struct device *dev)
dev_data->ppr = false;
}
- do_detach(dev_data);
+ /* Clear DTE and flush the entry */
+ dev_update_dte(dev_data, false);
+
+ /* Flush IOTLB and wait for the flushes to finish */
+ spin_lock_irqsave(&domain->lock, flags);
+ amd_iommu_domain_flush_all(domain);
+ spin_unlock_irqrestore(&domain->lock, flags);
+
+ /* Clear GCR3 table */
+ if (pdom_is_sva_capable(domain))
+ destroy_gcr3_table(dev_data, domain);
+
+ /* Update data structures */
+ dev_data->domain = NULL;
+ list_del(&dev_data->list);
+
+ /* decrease reference counters - needs to happen after the flushes */
+ pdom_detach_iommu(iommu, domain);
out:
spin_unlock(&dev_data->lock);