Skip to content

Commit e874c66

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu/amd: Change rlookup, irq_lookup, and alias to use kvalloc()
This is just CPU memory used by the driver to track things, it doesn't need to use iommu-pages. All of them are indexed by devid and devid is bounded by pci_seg->last_bdf or we are already out of bounds on the page allocation. Switch them to use some version of kvmalloc_array() and drop the now unused constants and remove the tbl_size() round up to PAGE_SIZE multiples logic. Tested-by: Alejandro Jimenez <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent b3efacc commit e874c66

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

drivers/iommu/amd/amd_iommu_types.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
* some size calculation constants
3030
*/
3131
#define DEV_TABLE_ENTRY_SIZE 32
32-
#define ALIAS_TABLE_ENTRY_SIZE 2
33-
#define RLOOKUP_TABLE_ENTRY_SIZE (sizeof(void *))
3432

3533
/* Capability offsets used by the driver */
3634
#define MMIO_CAP_HDR_OFFSET 0x00
@@ -616,12 +614,6 @@ struct amd_iommu_pci_seg {
616614
/* Size of the device table */
617615
u32 dev_table_size;
618616

619-
/* Size of the alias table */
620-
u32 alias_table_size;
621-
622-
/* Size of the rlookup table */
623-
u32 rlookup_table_size;
624-
625617
/*
626618
* device table virtual address
627619
*

drivers/iommu/amd/init.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,9 @@ static inline void free_dev_table(struct amd_iommu_pci_seg *pci_seg)
651651
/* Allocate per PCI segment IOMMU rlookup table. */
652652
static inline int __init alloc_rlookup_table(struct amd_iommu_pci_seg *pci_seg)
653653
{
654-
pci_seg->rlookup_table = iommu_alloc_pages(GFP_KERNEL,
655-
get_order(pci_seg->rlookup_table_size));
654+
pci_seg->rlookup_table = kvcalloc(pci_seg->last_bdf + 1,
655+
sizeof(*pci_seg->rlookup_table),
656+
GFP_KERNEL);
656657
if (pci_seg->rlookup_table == NULL)
657658
return -ENOMEM;
658659

@@ -661,16 +662,15 @@ static inline int __init alloc_rlookup_table(struct amd_iommu_pci_seg *pci_seg)
661662

662663
static inline void free_rlookup_table(struct amd_iommu_pci_seg *pci_seg)
663664
{
664-
iommu_free_pages(pci_seg->rlookup_table);
665+
kvfree(pci_seg->rlookup_table);
665666
pci_seg->rlookup_table = NULL;
666667
}
667668

668669
static inline int __init alloc_irq_lookup_table(struct amd_iommu_pci_seg *pci_seg)
669670
{
670-
pci_seg->irq_lookup_table = iommu_alloc_pages(GFP_KERNEL,
671-
get_order(pci_seg->rlookup_table_size));
672-
kmemleak_alloc(pci_seg->irq_lookup_table,
673-
pci_seg->rlookup_table_size, 1, GFP_KERNEL);
671+
pci_seg->irq_lookup_table = kvcalloc(pci_seg->last_bdf + 1,
672+
sizeof(*pci_seg->irq_lookup_table),
673+
GFP_KERNEL);
674674
if (pci_seg->irq_lookup_table == NULL)
675675
return -ENOMEM;
676676

@@ -679,17 +679,17 @@ static inline int __init alloc_irq_lookup_table(struct amd_iommu_pci_seg *pci_se
679679

680680
static inline void free_irq_lookup_table(struct amd_iommu_pci_seg *pci_seg)
681681
{
682-
kmemleak_free(pci_seg->irq_lookup_table);
683-
iommu_free_pages(pci_seg->irq_lookup_table);
682+
kvfree(pci_seg->irq_lookup_table);
684683
pci_seg->irq_lookup_table = NULL;
685684
}
686685

687686
static int __init alloc_alias_table(struct amd_iommu_pci_seg *pci_seg)
688687
{
689688
int i;
690689

691-
pci_seg->alias_table = iommu_alloc_pages(GFP_KERNEL,
692-
get_order(pci_seg->alias_table_size));
690+
pci_seg->alias_table = kvmalloc_array(pci_seg->last_bdf + 1,
691+
sizeof(*pci_seg->alias_table),
692+
GFP_KERNEL);
693693
if (!pci_seg->alias_table)
694694
return -ENOMEM;
695695

@@ -704,7 +704,7 @@ static int __init alloc_alias_table(struct amd_iommu_pci_seg *pci_seg)
704704

705705
static void __init free_alias_table(struct amd_iommu_pci_seg *pci_seg)
706706
{
707-
iommu_free_pages(pci_seg->alias_table);
707+
kvfree(pci_seg->alias_table);
708708
pci_seg->alias_table = NULL;
709709
}
710710

@@ -1596,8 +1596,6 @@ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id,
15961596
pci_seg->last_bdf = last_bdf;
15971597
DUMP_printk("PCI segment : 0x%0x, last bdf : 0x%04x\n", id, last_bdf);
15981598
pci_seg->dev_table_size = tbl_size(DEV_TABLE_ENTRY_SIZE, last_bdf);
1599-
pci_seg->alias_table_size = tbl_size(ALIAS_TABLE_ENTRY_SIZE, last_bdf);
1600-
pci_seg->rlookup_table_size = tbl_size(RLOOKUP_TABLE_ENTRY_SIZE, last_bdf);
16011599

16021600
pci_seg->id = id;
16031601
init_llist_head(&pci_seg->dev_data_list);

0 commit comments

Comments
 (0)