Skip to content

Commit e42ba06

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Restructure code for freeing page table
By consolidate logic into v1_free_pgtable helper function, which is called from IO page table framework. Signed-off-by: Suravee Suthikulpanit <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 1895425 commit e42ba06

File tree

3 files changed

+28
-35
lines changed

3 files changed

+28
-35
lines changed

drivers/iommu/amd/amd_iommu.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ static inline void amd_iommu_apply_ivrs_quirks(void) { }
132132
#endif
133133

134134
/* TODO: These are temporary and will be removed once fully transition */
135-
extern void free_pagetable(struct domain_pgtable *pgtable);
136135
extern int iommu_map_page(struct protection_domain *dom,
137136
unsigned long bus_addr,
138137
unsigned long phys_addr,

drivers/iommu/amd/io_pgtable.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -157,23 +157,6 @@ static struct page *free_sub_pt(unsigned long root, int mode,
157157
return freelist;
158158
}
159159

160-
void free_pagetable(struct domain_pgtable *pgtable)
161-
{
162-
struct page *freelist = NULL;
163-
unsigned long root;
164-
165-
if (pgtable->mode == PAGE_MODE_NONE)
166-
return;
167-
168-
BUG_ON(pgtable->mode < PAGE_MODE_NONE ||
169-
pgtable->mode > PAGE_MODE_6_LEVEL);
170-
171-
root = (unsigned long)pgtable->root;
172-
freelist = free_sub_pt(root, pgtable->mode, freelist);
173-
174-
free_page_list(freelist);
175-
}
176-
177160
void amd_iommu_domain_set_pgtable(struct protection_domain *domain,
178161
u64 *root, int mode)
179162
{
@@ -522,6 +505,30 @@ unsigned long iommu_unmap_page(struct protection_domain *dom,
522505
*/
523506
static void v1_free_pgtable(struct io_pgtable *iop)
524507
{
508+
struct amd_io_pgtable *pgtable = container_of(iop, struct amd_io_pgtable, iop);
509+
struct protection_domain *dom;
510+
struct page *freelist = NULL;
511+
unsigned long root;
512+
513+
if (pgtable->mode == PAGE_MODE_NONE)
514+
return;
515+
516+
dom = container_of(pgtable, struct protection_domain, iop);
517+
518+
/* Update data structure */
519+
amd_iommu_domain_clr_pt_root(dom);
520+
521+
/* Make changes visible to IOMMUs */
522+
amd_iommu_domain_update(dom);
523+
524+
/* Page-table is not visible to IOMMU anymore, so free it */
525+
BUG_ON(pgtable->mode < PAGE_MODE_NONE ||
526+
pgtable->mode > PAGE_MODE_6_LEVEL);
527+
528+
root = (unsigned long)pgtable->root;
529+
freelist = free_sub_pt(root, pgtable->mode, freelist);
530+
531+
free_page_list(freelist);
525532
}
526533

527534
static struct io_pgtable *v1_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)

drivers/iommu/amd/iommu.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,17 +1902,14 @@ static void cleanup_domain(struct protection_domain *domain)
19021902

19031903
static void protection_domain_free(struct protection_domain *domain)
19041904
{
1905-
struct domain_pgtable pgtable;
1906-
19071905
if (!domain)
19081906
return;
19091907

19101908
if (domain->id)
19111909
domain_id_free(domain->id);
19121910

1913-
amd_iommu_domain_get_pgtable(domain, &pgtable);
1914-
amd_iommu_domain_clr_pt_root(domain);
1915-
free_pagetable(&pgtable);
1911+
if (domain->iop.pgtbl_cfg.tlb)
1912+
free_io_pgtable_ops(&domain->iop.iop.ops);
19161913

19171914
kfree(domain);
19181915
}
@@ -2301,22 +2298,12 @@ EXPORT_SYMBOL(amd_iommu_unregister_ppr_notifier);
23012298
void amd_iommu_domain_direct_map(struct iommu_domain *dom)
23022299
{
23032300
struct protection_domain *domain = to_pdomain(dom);
2304-
struct domain_pgtable pgtable;
23052301
unsigned long flags;
23062302

23072303
spin_lock_irqsave(&domain->lock, flags);
23082304

2309-
/* First save pgtable configuration*/
2310-
amd_iommu_domain_get_pgtable(domain, &pgtable);
2311-
2312-
/* Remove page-table from domain */
2313-
amd_iommu_domain_clr_pt_root(domain);
2314-
2315-
/* Make changes visible to IOMMUs */
2316-
amd_iommu_domain_update(domain);
2317-
2318-
/* Page-table is not visible to IOMMU anymore, so free it */
2319-
free_pagetable(&pgtable);
2305+
if (domain->iop.pgtbl_cfg.tlb)
2306+
free_io_pgtable_ops(&domain->iop.iop.ops);
23202307

23212308
spin_unlock_irqrestore(&domain->lock, flags);
23222309
}

0 commit comments

Comments
 (0)