Skip to content

Commit eaf717f

Browse files
sarunkodjoergroedel
authored andcommitted
iommu/amd: Replace slab cache allocator with page allocator
Commit 05152a0 ("iommu/amd: Add slab-cache for irq remapping tables") introduces slab cache allocator. But slab cache allocator provides benefit only when the allocation and deallocation of many identical objects is frequent. The AMD IOMMU driver allocates Interrupt remapping table (IRT) when device driver requests IRQ for the first time and never frees it. Hence the slab allocator does not provide any benefit here. Signed-off-by: Sairaj Kodilkar <[email protected]> Reviewed-by: Vasant Hegde <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 1c608b0 commit eaf717f

File tree

3 files changed

+15
-36
lines changed

3 files changed

+15
-36
lines changed

drivers/iommu/amd/amd_iommu_types.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@
313313
* AMD IOMMU hardware only support 512 IRTEs despite
314314
* the architectural limitation of 2048 entries.
315315
*/
316-
#define DTE_INTTAB_ALIGNMENT 128
317316
#define DTE_INTTABLEN_VALUE 9ULL
318317
#define DTE_INTTABLEN (DTE_INTTABLEN_VALUE << 1)
319318
#define DTE_INTTABLEN_MASK (0xfULL << 1)
@@ -492,9 +491,6 @@ extern const struct iommu_ops amd_iommu_ops;
492491
/* IVRS indicates that pre-boot remapping was enabled */
493492
extern bool amdr_ivrs_remap_support;
494493

495-
/* kmem_cache to get tables with 128 byte alignement */
496-
extern struct kmem_cache *amd_iommu_irq_cache;
497-
498494
#define PCI_SBDF_TO_SEGID(sbdf) (((sbdf) >> 16) & 0xffff)
499495
#define PCI_SBDF_TO_DEVID(sbdf) ((sbdf) & 0xffff)
500496
#define PCI_SEG_DEVID_TO_SBDF(seg, devid) ((((u32)(seg) & 0xffff) << 16) | \

drivers/iommu/amd/init.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/acpi.h>
1313
#include <linux/list.h>
1414
#include <linux/bitmap.h>
15-
#include <linux/slab.h>
1615
#include <linux/syscore_ops.h>
1716
#include <linux/interrupt.h>
1817
#include <linux/msi.h>
@@ -2931,9 +2930,6 @@ static struct syscore_ops amd_iommu_syscore_ops = {
29312930

29322931
static void __init free_iommu_resources(void)
29332932
{
2934-
kmem_cache_destroy(amd_iommu_irq_cache);
2935-
amd_iommu_irq_cache = NULL;
2936-
29372933
free_iommu_all();
29382934
free_pci_segments();
29392935
}
@@ -3032,7 +3028,7 @@ static void __init ivinfo_init(void *ivrs)
30323028
static int __init early_amd_iommu_init(void)
30333029
{
30343030
struct acpi_table_header *ivrs_base;
3035-
int remap_cache_sz, ret;
3031+
int ret;
30363032
acpi_status status;
30373033

30383034
if (!amd_iommu_detected)
@@ -3094,22 +3090,7 @@ static int __init early_amd_iommu_init(void)
30943090

30953091
if (amd_iommu_irq_remap) {
30963092
struct amd_iommu_pci_seg *pci_seg;
3097-
/*
3098-
* Interrupt remapping enabled, create kmem_cache for the
3099-
* remapping tables.
3100-
*/
31013093
ret = -ENOMEM;
3102-
if (!AMD_IOMMU_GUEST_IR_GA(amd_iommu_guest_ir))
3103-
remap_cache_sz = MAX_IRQS_PER_TABLE * sizeof(u32);
3104-
else
3105-
remap_cache_sz = MAX_IRQS_PER_TABLE * (sizeof(u64) * 2);
3106-
amd_iommu_irq_cache = kmem_cache_create("irq_remap_cache",
3107-
remap_cache_sz,
3108-
DTE_INTTAB_ALIGNMENT,
3109-
0, NULL);
3110-
if (!amd_iommu_irq_cache)
3111-
goto out;
3112-
31133094
for_each_pci_segment(pci_seg) {
31143095
if (alloc_irq_lookup_table(pci_seg))
31153096
goto out;

drivers/iommu/amd/iommu.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ struct iommu_cmd {
7575
*/
7676
DEFINE_IDA(pdom_ids);
7777

78-
struct kmem_cache *amd_iommu_irq_cache;
79-
8078
static int amd_iommu_attach_device(struct iommu_domain *dom,
8179
struct device *dev);
8280

@@ -3118,27 +3116,21 @@ static struct irq_remap_table *get_irq_table(struct amd_iommu *iommu, u16 devid)
31183116
return table;
31193117
}
31203118

3121-
static struct irq_remap_table *__alloc_irq_table(void)
3119+
static struct irq_remap_table *__alloc_irq_table(int nid, int order)
31223120
{
31233121
struct irq_remap_table *table;
31243122

31253123
table = kzalloc(sizeof(*table), GFP_KERNEL);
31263124
if (!table)
31273125
return NULL;
31283126

3129-
table->table = kmem_cache_alloc(amd_iommu_irq_cache, GFP_KERNEL);
3127+
table->table = iommu_alloc_pages_node(nid, GFP_KERNEL, order);
31303128
if (!table->table) {
31313129
kfree(table);
31323130
return NULL;
31333131
}
31343132
raw_spin_lock_init(&table->lock);
31353133

3136-
if (!AMD_IOMMU_GUEST_IR_GA(amd_iommu_guest_ir))
3137-
memset(table->table, 0,
3138-
MAX_IRQS_PER_TABLE * sizeof(u32));
3139-
else
3140-
memset(table->table, 0,
3141-
(MAX_IRQS_PER_TABLE * (sizeof(u64) * 2)));
31423134
return table;
31433135
}
31443136

@@ -3170,13 +3162,23 @@ static int set_remap_table_entry_alias(struct pci_dev *pdev, u16 alias,
31703162
return 0;
31713163
}
31723164

3165+
static inline size_t get_irq_table_size(unsigned int max_irqs)
3166+
{
3167+
if (!AMD_IOMMU_GUEST_IR_GA(amd_iommu_guest_ir))
3168+
return max_irqs * sizeof(u32);
3169+
3170+
return max_irqs * (sizeof(u64) * 2);
3171+
}
3172+
31733173
static struct irq_remap_table *alloc_irq_table(struct amd_iommu *iommu,
31743174
u16 devid, struct pci_dev *pdev)
31753175
{
31763176
struct irq_remap_table *table = NULL;
31773177
struct irq_remap_table *new_table = NULL;
31783178
struct amd_iommu_pci_seg *pci_seg;
31793179
unsigned long flags;
3180+
int order = get_order(get_irq_table_size(MAX_IRQS_PER_TABLE));
3181+
int nid = iommu && iommu->dev ? dev_to_node(&iommu->dev->dev) : NUMA_NO_NODE;
31803182
u16 alias;
31813183

31823184
spin_lock_irqsave(&iommu_table_lock, flags);
@@ -3195,7 +3197,7 @@ static struct irq_remap_table *alloc_irq_table(struct amd_iommu *iommu,
31953197
spin_unlock_irqrestore(&iommu_table_lock, flags);
31963198

31973199
/* Nothing there yet, allocate new irq remapping table */
3198-
new_table = __alloc_irq_table();
3200+
new_table = __alloc_irq_table(nid, order);
31993201
if (!new_table)
32003202
return NULL;
32013203

@@ -3230,7 +3232,7 @@ static struct irq_remap_table *alloc_irq_table(struct amd_iommu *iommu,
32303232
spin_unlock_irqrestore(&iommu_table_lock, flags);
32313233

32323234
if (new_table) {
3233-
kmem_cache_free(amd_iommu_irq_cache, new_table->table);
3235+
iommu_free_pages(new_table->table, order);
32343236
kfree(new_table);
32353237
}
32363238
return table;

0 commit comments

Comments
 (0)