Skip to content

Commit ee2653b

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Remove domain and devinfo mempool
The domain and devinfo memory blocks are only allocated during device probe and released during remove. There's no hot-path context, hence no need for memory pools. 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-5-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent c8850a6 commit ee2653b

1 file changed

Lines changed: 5 additions & 99 deletions

File tree

drivers/iommu/intel/iommu.c

Lines changed: 5 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,6 @@ static int __init intel_iommu_setup(char *str)
452452
}
453453
__setup("intel_iommu=", intel_iommu_setup);
454454

455-
static struct kmem_cache *iommu_domain_cache;
456-
static struct kmem_cache *iommu_devinfo_cache;
457-
458455
void *alloc_pgtable_page(int node)
459456
{
460457
struct page *page;
@@ -471,26 +468,6 @@ void free_pgtable_page(void *vaddr)
471468
free_page((unsigned long)vaddr);
472469
}
473470

474-
static inline void *alloc_domain_mem(void)
475-
{
476-
return kmem_cache_alloc(iommu_domain_cache, GFP_ATOMIC);
477-
}
478-
479-
static void free_domain_mem(void *vaddr)
480-
{
481-
kmem_cache_free(iommu_domain_cache, vaddr);
482-
}
483-
484-
static inline void * alloc_devinfo_mem(void)
485-
{
486-
return kmem_cache_alloc(iommu_devinfo_cache, GFP_ATOMIC);
487-
}
488-
489-
static inline void free_devinfo_mem(void *vaddr)
490-
{
491-
kmem_cache_free(iommu_devinfo_cache, vaddr);
492-
}
493-
494471
static inline int domain_type_is_si(struct dmar_domain *domain)
495472
{
496473
return domain->domain.type == IOMMU_DOMAIN_IDENTITY;
@@ -1885,11 +1862,10 @@ static struct dmar_domain *alloc_domain(unsigned int type)
18851862
{
18861863
struct dmar_domain *domain;
18871864

1888-
domain = alloc_domain_mem();
1865+
domain = kzalloc(sizeof(*domain), GFP_KERNEL);
18891866
if (!domain)
18901867
return NULL;
18911868

1892-
memset(domain, 0, sizeof(*domain));
18931869
domain->nid = NUMA_NO_NODE;
18941870
if (first_level_by_default(type))
18951871
domain->flags |= DOMAIN_FLAG_USE_FIRST_LEVEL;
@@ -1973,7 +1949,7 @@ static void domain_exit(struct dmar_domain *domain)
19731949
put_pages_list(&freelist);
19741950
}
19751951

1976-
free_domain_mem(domain);
1952+
kfree(domain);
19771953
}
19781954

19791955
/*
@@ -2558,7 +2534,7 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu,
25582534
unsigned long flags;
25592535
int ret;
25602536

2561-
info = alloc_devinfo_mem();
2537+
info = kzalloc(sizeof(*info), GFP_KERNEL);
25622538
if (!info)
25632539
return NULL;
25642540

@@ -2574,13 +2550,9 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu,
25742550
info->segment = pci_domain_nr(pdev->bus);
25752551
}
25762552

2577-
info->ats_supported = info->pasid_supported = info->pri_supported = 0;
2578-
info->ats_enabled = info->pasid_enabled = info->pri_enabled = 0;
2579-
info->ats_qdep = 0;
25802553
info->dev = dev;
25812554
info->domain = domain;
25822555
info->iommu = iommu;
2583-
info->pasid_table = NULL;
25842556

25852557
if (dev && dev_is_pci(dev)) {
25862558
struct pci_dev *pdev = to_pci_dev(info->dev);
@@ -2610,7 +2582,7 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu,
26102582

26112583
if (ret) {
26122584
spin_unlock_irqrestore(&device_domain_lock, flags);
2613-
free_devinfo_mem(info);
2585+
kfree(info);
26142586
return NULL;
26152587
}
26162588

@@ -3343,65 +3315,6 @@ static int __init init_dmars(void)
33433315
return ret;
33443316
}
33453317

3346-
static inline int iommu_domain_cache_init(void)
3347-
{
3348-
int ret = 0;
3349-
3350-
iommu_domain_cache = kmem_cache_create("iommu_domain",
3351-
sizeof(struct dmar_domain),
3352-
0,
3353-
SLAB_HWCACHE_ALIGN,
3354-
3355-
NULL);
3356-
if (!iommu_domain_cache) {
3357-
pr_err("Couldn't create iommu_domain cache\n");
3358-
ret = -ENOMEM;
3359-
}
3360-
3361-
return ret;
3362-
}
3363-
3364-
static inline int iommu_devinfo_cache_init(void)
3365-
{
3366-
int ret = 0;
3367-
3368-
iommu_devinfo_cache = kmem_cache_create("iommu_devinfo",
3369-
sizeof(struct device_domain_info),
3370-
0,
3371-
SLAB_HWCACHE_ALIGN,
3372-
NULL);
3373-
if (!iommu_devinfo_cache) {
3374-
pr_err("Couldn't create devinfo cache\n");
3375-
ret = -ENOMEM;
3376-
}
3377-
3378-
return ret;
3379-
}
3380-
3381-
static int __init iommu_init_mempool(void)
3382-
{
3383-
int ret;
3384-
3385-
ret = iommu_domain_cache_init();
3386-
if (ret)
3387-
goto domain_error;
3388-
3389-
ret = iommu_devinfo_cache_init();
3390-
if (!ret)
3391-
return ret;
3392-
3393-
kmem_cache_destroy(iommu_domain_cache);
3394-
domain_error:
3395-
3396-
return -ENOMEM;
3397-
}
3398-
3399-
static void __init iommu_exit_mempool(void)
3400-
{
3401-
kmem_cache_destroy(iommu_devinfo_cache);
3402-
kmem_cache_destroy(iommu_domain_cache);
3403-
}
3404-
34053318
static void __init init_no_remapping_devices(void)
34063319
{
34073320
struct dmar_drhd_unit *drhd;
@@ -4253,12 +4166,6 @@ int __init intel_iommu_init(void)
42534166
force_on = (!intel_iommu_tboot_noforce && tboot_force_iommu()) ||
42544167
platform_optin_force_iommu();
42554168

4256-
if (iommu_init_mempool()) {
4257-
if (force_on)
4258-
panic("tboot: Failed to initialize iommu memory\n");
4259-
return -ENOMEM;
4260-
}
4261-
42624169
down_write(&dmar_global_lock);
42634170
if (dmar_table_init()) {
42644171
if (force_on)
@@ -4379,7 +4286,6 @@ int __init intel_iommu_init(void)
43794286
out_free_dmar:
43804287
intel_iommu_free_dmars();
43814288
up_write(&dmar_global_lock);
4382-
iommu_exit_mempool();
43834289
return ret;
43844290
}
43854291

@@ -4436,7 +4342,7 @@ static void __dmar_remove_one_dev_info(struct device_domain_info *info)
44364342
domain_detach_iommu(domain, iommu);
44374343
spin_unlock_irqrestore(&iommu->lock, flags);
44384344

4439-
free_devinfo_mem(info);
4345+
kfree(info);
44404346
}
44414347

44424348
static void dmar_remove_one_dev_info(struct device *dev)

0 commit comments

Comments
 (0)