Skip to content

Commit 402e668

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Remove intel_iommu::domains
The "domains" field of the intel_iommu structure keeps the mapping of domain_id to dmar_domain. This information is not used anywhere. Remove and cleanup it to avoid unnecessary memory consumption. Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/20220214025704.3184654-1-baolu.lu@linux.intel.com Link: https://lore.kernel.org/r/20220301020159.633356-2-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 067e95f commit 402e668

2 files changed

Lines changed: 3 additions & 66 deletions

File tree

drivers/iommu/intel/iommu.c

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -455,36 +455,6 @@ __setup("intel_iommu=", intel_iommu_setup);
455455
static struct kmem_cache *iommu_domain_cache;
456456
static struct kmem_cache *iommu_devinfo_cache;
457457

458-
static struct dmar_domain* get_iommu_domain(struct intel_iommu *iommu, u16 did)
459-
{
460-
struct dmar_domain **domains;
461-
int idx = did >> 8;
462-
463-
domains = iommu->domains[idx];
464-
if (!domains)
465-
return NULL;
466-
467-
return domains[did & 0xff];
468-
}
469-
470-
static void set_iommu_domain(struct intel_iommu *iommu, u16 did,
471-
struct dmar_domain *domain)
472-
{
473-
struct dmar_domain **domains;
474-
int idx = did >> 8;
475-
476-
if (!iommu->domains[idx]) {
477-
size_t size = 256 * sizeof(struct dmar_domain *);
478-
iommu->domains[idx] = kzalloc(size, GFP_ATOMIC);
479-
}
480-
481-
domains = iommu->domains[idx];
482-
if (WARN_ON(!domains))
483-
return;
484-
else
485-
domains[did & 0xff] = domain;
486-
}
487-
488458
void *alloc_pgtable_page(int node)
489459
{
490460
struct page *page;
@@ -1751,8 +1721,7 @@ static void intel_flush_iotlb_all(struct iommu_domain *domain)
17511721
DMA_TLB_DSI_FLUSH);
17521722

17531723
if (!cap_caching_mode(iommu->cap))
1754-
iommu_flush_dev_iotlb(get_iommu_domain(iommu, did),
1755-
0, MAX_AGAW_PFN_WIDTH);
1724+
iommu_flush_dev_iotlb(dmar_domain, 0, MAX_AGAW_PFN_WIDTH);
17561725
}
17571726
}
17581727

@@ -1815,7 +1784,6 @@ static void iommu_disable_translation(struct intel_iommu *iommu)
18151784
static int iommu_init_domains(struct intel_iommu *iommu)
18161785
{
18171786
u32 ndomains;
1818-
size_t size;
18191787

18201788
ndomains = cap_ndoms(iommu->cap);
18211789
pr_debug("%s: Number of Domains supported <%d>\n",
@@ -1827,24 +1795,6 @@ static int iommu_init_domains(struct intel_iommu *iommu)
18271795
if (!iommu->domain_ids)
18281796
return -ENOMEM;
18291797

1830-
size = (ALIGN(ndomains, 256) >> 8) * sizeof(struct dmar_domain **);
1831-
iommu->domains = kzalloc(size, GFP_KERNEL);
1832-
1833-
if (iommu->domains) {
1834-
size = 256 * sizeof(struct dmar_domain *);
1835-
iommu->domains[0] = kzalloc(size, GFP_KERNEL);
1836-
}
1837-
1838-
if (!iommu->domains || !iommu->domains[0]) {
1839-
pr_err("%s: Allocating domain array failed\n",
1840-
iommu->name);
1841-
bitmap_free(iommu->domain_ids);
1842-
kfree(iommu->domains);
1843-
iommu->domain_ids = NULL;
1844-
iommu->domains = NULL;
1845-
return -ENOMEM;
1846-
}
1847-
18481798
/*
18491799
* If Caching mode is set, then invalid translations are tagged
18501800
* with domain-id 0, hence we need to pre-allocate it. We also
@@ -1871,7 +1821,7 @@ static void disable_dmar_iommu(struct intel_iommu *iommu)
18711821
struct device_domain_info *info, *tmp;
18721822
unsigned long flags;
18731823

1874-
if (!iommu->domains || !iommu->domain_ids)
1824+
if (!iommu->domain_ids)
18751825
return;
18761826

18771827
spin_lock_irqsave(&device_domain_lock, flags);
@@ -1892,15 +1842,8 @@ static void disable_dmar_iommu(struct intel_iommu *iommu)
18921842

18931843
static void free_dmar_iommu(struct intel_iommu *iommu)
18941844
{
1895-
if ((iommu->domains) && (iommu->domain_ids)) {
1896-
int elems = ALIGN(cap_ndoms(iommu->cap), 256) >> 8;
1897-
int i;
1898-
1899-
for (i = 0; i < elems; i++)
1900-
kfree(iommu->domains[i]);
1901-
kfree(iommu->domains);
1845+
if (iommu->domain_ids) {
19021846
bitmap_free(iommu->domain_ids);
1903-
iommu->domains = NULL;
19041847
iommu->domain_ids = NULL;
19051848
}
19061849

@@ -1978,11 +1921,8 @@ static int domain_attach_iommu(struct dmar_domain *domain,
19781921
}
19791922

19801923
set_bit(num, iommu->domain_ids);
1981-
set_iommu_domain(iommu, num, domain);
1982-
19831924
domain->iommu_did[iommu->seq_id] = num;
19841925
domain->nid = iommu->node;
1985-
19861926
domain_update_iommu_cap(domain);
19871927
}
19881928

@@ -2001,8 +1941,6 @@ static void domain_detach_iommu(struct dmar_domain *domain,
20011941
if (domain->iommu_refcnt[iommu->seq_id] == 0) {
20021942
num = domain->iommu_did[iommu->seq_id];
20031943
clear_bit(num, iommu->domain_ids);
2004-
set_iommu_domain(iommu, num, NULL);
2005-
20061944
domain_update_iommu_cap(domain);
20071945
domain->iommu_did[iommu->seq_id] = 0;
20081946
}

include/linux/intel-iommu.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,6 @@ struct intel_iommu {
578578

579579
#ifdef CONFIG_INTEL_IOMMU
580580
unsigned long *domain_ids; /* bitmap of domains */
581-
struct dmar_domain ***domains; /* ptr to domains */
582581
spinlock_t lock; /* protect context, domain ids */
583582
struct root_entry *root_entry; /* virtual address */
584583

0 commit comments

Comments
 (0)