Commit 4316ba4a authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Joerg Roedel
Browse files

iommu/pages: Remove the order argument to iommu_free_pages()



Now that we have a folio under the allocation iommu_free_pages() can know
the order of the original allocation and do the correct thing to free it.

The next patch will rename iommu_free_page() to iommu_free_pages() so we
have naming consistency with iommu_alloc_pages_node().

Reviewed-by: default avatarLu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: default avatarMostafa Saleh <smostafa@google.com>
Tested-by: default avatarNicolin Chen <nicolinc@nvidia.com>
Tested-by: default avatarAlejandro Jimenez <alejandro.j.jimenez@oracle.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/5-v4-c8663abbb606+3f7-iommu_pages_jgg@nvidia.com


Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent c11a1a47
Loading
Loading
Loading
Loading
+11 −17
Original line number Diff line number Diff line
@@ -644,8 +644,7 @@ static inline int __init alloc_dev_table(struct amd_iommu_pci_seg *pci_seg)

static inline void free_dev_table(struct amd_iommu_pci_seg *pci_seg)
{
	iommu_free_pages(pci_seg->dev_table,
			 get_order(pci_seg->dev_table_size));
	iommu_free_pages(pci_seg->dev_table);
	pci_seg->dev_table = NULL;
}

@@ -662,8 +661,7 @@ static inline int __init alloc_rlookup_table(struct amd_iommu_pci_seg *pci_seg)

static inline void free_rlookup_table(struct amd_iommu_pci_seg *pci_seg)
{
	iommu_free_pages(pci_seg->rlookup_table,
			 get_order(pci_seg->rlookup_table_size));
	iommu_free_pages(pci_seg->rlookup_table);
	pci_seg->rlookup_table = NULL;
}

@@ -682,8 +680,7 @@ static inline int __init alloc_irq_lookup_table(struct amd_iommu_pci_seg *pci_se
static inline void free_irq_lookup_table(struct amd_iommu_pci_seg *pci_seg)
{
	kmemleak_free(pci_seg->irq_lookup_table);
	iommu_free_pages(pci_seg->irq_lookup_table,
			 get_order(pci_seg->rlookup_table_size));
	iommu_free_pages(pci_seg->irq_lookup_table);
	pci_seg->irq_lookup_table = NULL;
}

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

static void __init free_alias_table(struct amd_iommu_pci_seg *pci_seg)
{
	iommu_free_pages(pci_seg->alias_table,
			 get_order(pci_seg->alias_table_size));
	iommu_free_pages(pci_seg->alias_table);
	pci_seg->alias_table = NULL;
}

@@ -817,7 +813,7 @@ static void iommu_disable_command_buffer(struct amd_iommu *iommu)

static void __init free_command_buffer(struct amd_iommu *iommu)
{
	iommu_free_pages(iommu->cmd_buf, get_order(CMD_BUFFER_SIZE));
	iommu_free_pages(iommu->cmd_buf);
}

void *__init iommu_alloc_4k_pages(struct amd_iommu *iommu, gfp_t gfp,
@@ -829,7 +825,7 @@ void *__init iommu_alloc_4k_pages(struct amd_iommu *iommu, gfp_t gfp,
	if (buf &&
	    check_feature(FEATURE_SNP) &&
	    set_memory_4k((unsigned long)buf, (1 << order))) {
		iommu_free_pages(buf, order);
		iommu_free_pages(buf);
		buf = NULL;
	}

@@ -873,14 +869,14 @@ static void iommu_disable_event_buffer(struct amd_iommu *iommu)

static void __init free_event_buffer(struct amd_iommu *iommu)
{
	iommu_free_pages(iommu->evt_buf, get_order(EVT_BUFFER_SIZE));
	iommu_free_pages(iommu->evt_buf);
}

static void free_ga_log(struct amd_iommu *iommu)
{
#ifdef CONFIG_IRQ_REMAP
	iommu_free_pages(iommu->ga_log, get_order(GA_LOG_SIZE));
	iommu_free_pages(iommu->ga_log_tail, get_order(8));
	iommu_free_pages(iommu->ga_log);
	iommu_free_pages(iommu->ga_log_tail);
#endif
}

@@ -2789,8 +2785,7 @@ static void early_enable_iommus(void)

		for_each_pci_segment(pci_seg) {
			if (pci_seg->old_dev_tbl_cpy != NULL) {
				iommu_free_pages(pci_seg->old_dev_tbl_cpy,
						 get_order(pci_seg->dev_table_size));
				iommu_free_pages(pci_seg->old_dev_tbl_cpy);
				pci_seg->old_dev_tbl_cpy = NULL;
			}
		}
@@ -2803,8 +2798,7 @@ static void early_enable_iommus(void)
		pr_info("Copied DEV table from previous kernel.\n");

		for_each_pci_segment(pci_seg) {
			iommu_free_pages(pci_seg->dev_table,
					 get_order(pci_seg->dev_table_size));
			iommu_free_pages(pci_seg->dev_table);
			pci_seg->dev_table = pci_seg->old_dev_tbl_cpy;
		}

+1 −1
Original line number Diff line number Diff line
@@ -3246,7 +3246,7 @@ static struct irq_remap_table *alloc_irq_table(struct amd_iommu *iommu,
	spin_unlock_irqrestore(&iommu_table_lock, flags);

	if (new_table) {
		iommu_free_pages(new_table->table, order);
		iommu_free_pages(new_table->table);
		kfree(new_table);
	}
	return table;
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ void amd_iommu_enable_ppr_log(struct amd_iommu *iommu)

void __init amd_iommu_free_ppr_log(struct amd_iommu *iommu)
{
	iommu_free_pages(iommu->ppr_log, get_order(PPR_LOG_SIZE));
	iommu_free_pages(iommu->ppr_log);
}

/*
+4 −4
Original line number Diff line number Diff line
@@ -932,9 +932,9 @@ static struct iommu_domain *exynos_iommu_domain_alloc_paging(struct device *dev)
	return &domain->domain;

err_lv2ent:
	iommu_free_pages(domain->lv2entcnt, 1);
	iommu_free_pages(domain->lv2entcnt);
err_counter:
	iommu_free_pages(domain->pgtable, 2);
	iommu_free_pages(domain->pgtable);
err_pgtable:
	kfree(domain);
	return NULL;
@@ -975,8 +975,8 @@ static void exynos_iommu_domain_free(struct iommu_domain *iommu_domain)
					phys_to_virt(base));
		}

	iommu_free_pages(domain->pgtable, 2);
	iommu_free_pages(domain->lv2entcnt, 1);
	iommu_free_pages(domain->pgtable);
	iommu_free_pages(domain->lv2entcnt);
	kfree(domain);
}

+2 −2
Original line number Diff line number Diff line
@@ -612,7 +612,7 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu)
out_free_bitmap:
	bitmap_free(bitmap);
out_free_pages:
	iommu_free_pages(ir_table_base, INTR_REMAP_PAGE_ORDER);
	iommu_free_pages(ir_table_base);
out_free_table:
	kfree(ir_table);

@@ -633,7 +633,7 @@ static void intel_teardown_irq_remapping(struct intel_iommu *iommu)
			irq_domain_free_fwnode(fn);
			iommu->ir_domain = NULL;
		}
		iommu_free_pages(iommu->ir_table->base, INTR_REMAP_PAGE_ORDER);
		iommu_free_pages(iommu->ir_table->base);
		bitmap_free(iommu->ir_table->bitmap);
		kfree(iommu->ir_table);
		iommu->ir_table = NULL;
Loading