Commit b608ac3b authored by Joerg Roedel's avatar Joerg Roedel

iommu/vt-d: Simplify domain_remove_one_dev_info()

Simplify this function as much as possible with the new
iommu_refcnt field.
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 42e8c186
...@@ -4610,52 +4610,34 @@ static void iommu_detach_dependent_devices(struct intel_iommu *iommu, ...@@ -4610,52 +4610,34 @@ static void iommu_detach_dependent_devices(struct intel_iommu *iommu,
static void domain_remove_one_dev_info(struct dmar_domain *domain, static void domain_remove_one_dev_info(struct dmar_domain *domain,
struct device *dev) struct device *dev)
{ {
struct device_domain_info *info, *tmp; struct device_domain_info *info;
struct intel_iommu *iommu; struct intel_iommu *iommu;
unsigned long flags; unsigned long flags;
bool found = false;
u8 bus, devfn; u8 bus, devfn;
iommu = device_to_iommu(dev, &bus, &devfn); iommu = device_to_iommu(dev, &bus, &devfn);
if (!iommu) if (!iommu)
return; return;
spin_lock_irqsave(&device_domain_lock, flags); info = dev->archdata.iommu;
list_for_each_entry_safe(info, tmp, &domain->devices, link) {
if (info->iommu == iommu && info->bus == bus &&
info->devfn == devfn) {
unlink_domain_info(info);
spin_unlock_irqrestore(&device_domain_lock, flags);
iommu_disable_dev_iotlb(info);
iommu_detach_dev(iommu, info->bus, info->devfn);
iommu_detach_dependent_devices(iommu, dev);
free_devinfo_mem(info);
spin_lock_irqsave(&device_domain_lock, flags);
if (found)
break;
else
continue;
}
/* if (WARN_ON(!info))
* If there is no other devices under the same iommu owned by return;
* this domain, clear this iommu in iommu_refcnt update iommu
* count and coherency.
*/
if (info->iommu == iommu)
found = true;
}
spin_lock_irqsave(&device_domain_lock, flags);
unlink_domain_info(info);
spin_unlock_irqrestore(&device_domain_lock, flags); spin_unlock_irqrestore(&device_domain_lock, flags);
if (found == 0) { iommu_disable_dev_iotlb(info);
domain_detach_iommu(domain, iommu); iommu_detach_dev(iommu, info->bus, info->devfn);
if (!domain_type_is_vm_or_si(domain)) iommu_detach_dependent_devices(iommu, dev);
iommu_detach_domain(domain, iommu); free_devinfo_mem(info);
} domain_detach_iommu(domain, iommu);
spin_lock_irqsave(&domain->iommu_lock, flags);
if (!domain->iommu_refcnt[iommu->seq_id])
iommu_detach_domain(domain, iommu);
spin_unlock_irqrestore(&domain->iommu_lock, flags);
} }
static int md_domain_init(struct dmar_domain *domain, int guest_width) static int md_domain_init(struct dmar_domain *domain, int guest_width)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment