Skip to content

Commit b1cf156

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Remove unnecessary domain_context_mapped()
The device_domain_info::domain accurately records the domain attached to the device. It is unnecessary to check whether the context is present in the attach_dev path. Remove it to make the code neat. Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent a820447 commit b1cf156

File tree

1 file changed

+3
-44
lines changed

1 file changed

+3
-44
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -780,19 +780,6 @@ static void domain_flush_cache(struct dmar_domain *domain,
780780
clflush_cache_range(addr, size);
781781
}
782782

783-
static int device_context_mapped(struct intel_iommu *iommu, u8 bus, u8 devfn)
784-
{
785-
struct context_entry *context;
786-
int ret = 0;
787-
788-
spin_lock(&iommu->lock);
789-
context = iommu_context_addr(iommu, bus, devfn, 0);
790-
if (context)
791-
ret = context_present(context);
792-
spin_unlock(&iommu->lock);
793-
return ret;
794-
}
795-
796783
static void free_context_table(struct intel_iommu *iommu)
797784
{
798785
struct context_entry *context;
@@ -2097,30 +2084,6 @@ domain_context_mapping(struct dmar_domain *domain, struct device *dev)
20972084
&domain_context_mapping_cb, &data);
20982085
}
20992086

2100-
static int domain_context_mapped_cb(struct pci_dev *pdev,
2101-
u16 alias, void *opaque)
2102-
{
2103-
struct intel_iommu *iommu = opaque;
2104-
2105-
return !device_context_mapped(iommu, PCI_BUS_NUM(alias), alias & 0xff);
2106-
}
2107-
2108-
static int domain_context_mapped(struct device *dev)
2109-
{
2110-
struct intel_iommu *iommu;
2111-
u8 bus, devfn;
2112-
2113-
iommu = device_to_iommu(dev, &bus, &devfn);
2114-
if (!iommu)
2115-
return -ENODEV;
2116-
2117-
if (!dev_is_pci(dev))
2118-
return device_context_mapped(iommu, bus, devfn);
2119-
2120-
return !pci_for_each_dma_alias(to_pci_dev(dev),
2121-
domain_context_mapped_cb, iommu);
2122-
}
2123-
21242087
/* Returns a number of VTD pages, but aligned to MM page size */
21252088
static inline unsigned long aligned_nrpages(unsigned long host_addr,
21262089
size_t size)
@@ -4269,6 +4232,7 @@ static int prepare_domain_attach_device(struct iommu_domain *domain,
42694232
static int intel_iommu_attach_device(struct iommu_domain *domain,
42704233
struct device *dev)
42714234
{
4235+
struct device_domain_info *info = dev_iommu_priv_get(dev);
42724236
int ret;
42734237

42744238
if (domain->type == IOMMU_DOMAIN_UNMANAGED &&
@@ -4277,13 +4241,8 @@ static int intel_iommu_attach_device(struct iommu_domain *domain,
42774241
return -EPERM;
42784242
}
42794243

4280-
/* normally dev is not mapped */
4281-
if (unlikely(domain_context_mapped(dev))) {
4282-
struct device_domain_info *info = dev_iommu_priv_get(dev);
4283-
4284-
if (info->domain)
4285-
device_block_translation(dev);
4286-
}
4244+
if (info->domain)
4245+
device_block_translation(dev);
42874246

42884247
ret = prepare_domain_attach_device(domain, dev);
42894248
if (ret)

0 commit comments

Comments
 (0)