mirror of
https://github.com/torvalds/linux.git
synced 2024-12-02 00:51:44 +00:00
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 <suravee.suthikulpanit@amd.com> Link: https://lore.kernel.org/r/20201215073705.123786-8-suravee.suthikulpanit@amd.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
This commit is contained in:
parent
18954252a1
commit
e42ba06330
@ -132,7 +132,6 @@ static inline void amd_iommu_apply_ivrs_quirks(void) { }
|
||||
#endif
|
||||
|
||||
/* TODO: These are temporary and will be removed once fully transition */
|
||||
extern void free_pagetable(struct domain_pgtable *pgtable);
|
||||
extern int iommu_map_page(struct protection_domain *dom,
|
||||
unsigned long bus_addr,
|
||||
unsigned long phys_addr,
|
||||
|
@ -157,23 +157,6 @@ static struct page *free_sub_pt(unsigned long root, int mode,
|
||||
return freelist;
|
||||
}
|
||||
|
||||
void free_pagetable(struct domain_pgtable *pgtable)
|
||||
{
|
||||
struct page *freelist = NULL;
|
||||
unsigned long root;
|
||||
|
||||
if (pgtable->mode == PAGE_MODE_NONE)
|
||||
return;
|
||||
|
||||
BUG_ON(pgtable->mode < PAGE_MODE_NONE ||
|
||||
pgtable->mode > PAGE_MODE_6_LEVEL);
|
||||
|
||||
root = (unsigned long)pgtable->root;
|
||||
freelist = free_sub_pt(root, pgtable->mode, freelist);
|
||||
|
||||
free_page_list(freelist);
|
||||
}
|
||||
|
||||
void amd_iommu_domain_set_pgtable(struct protection_domain *domain,
|
||||
u64 *root, int mode)
|
||||
{
|
||||
@ -522,6 +505,30 @@ unsigned long iommu_unmap_page(struct protection_domain *dom,
|
||||
*/
|
||||
static void v1_free_pgtable(struct io_pgtable *iop)
|
||||
{
|
||||
struct amd_io_pgtable *pgtable = container_of(iop, struct amd_io_pgtable, iop);
|
||||
struct protection_domain *dom;
|
||||
struct page *freelist = NULL;
|
||||
unsigned long root;
|
||||
|
||||
if (pgtable->mode == PAGE_MODE_NONE)
|
||||
return;
|
||||
|
||||
dom = container_of(pgtable, struct protection_domain, iop);
|
||||
|
||||
/* Update data structure */
|
||||
amd_iommu_domain_clr_pt_root(dom);
|
||||
|
||||
/* Make changes visible to IOMMUs */
|
||||
amd_iommu_domain_update(dom);
|
||||
|
||||
/* Page-table is not visible to IOMMU anymore, so free it */
|
||||
BUG_ON(pgtable->mode < PAGE_MODE_NONE ||
|
||||
pgtable->mode > PAGE_MODE_6_LEVEL);
|
||||
|
||||
root = (unsigned long)pgtable->root;
|
||||
freelist = free_sub_pt(root, pgtable->mode, freelist);
|
||||
|
||||
free_page_list(freelist);
|
||||
}
|
||||
|
||||
static struct io_pgtable *v1_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
|
||||
|
@ -1902,17 +1902,14 @@ static void cleanup_domain(struct protection_domain *domain)
|
||||
|
||||
static void protection_domain_free(struct protection_domain *domain)
|
||||
{
|
||||
struct domain_pgtable pgtable;
|
||||
|
||||
if (!domain)
|
||||
return;
|
||||
|
||||
if (domain->id)
|
||||
domain_id_free(domain->id);
|
||||
|
||||
amd_iommu_domain_get_pgtable(domain, &pgtable);
|
||||
amd_iommu_domain_clr_pt_root(domain);
|
||||
free_pagetable(&pgtable);
|
||||
if (domain->iop.pgtbl_cfg.tlb)
|
||||
free_io_pgtable_ops(&domain->iop.iop.ops);
|
||||
|
||||
kfree(domain);
|
||||
}
|
||||
@ -2301,22 +2298,12 @@ EXPORT_SYMBOL(amd_iommu_unregister_ppr_notifier);
|
||||
void amd_iommu_domain_direct_map(struct iommu_domain *dom)
|
||||
{
|
||||
struct protection_domain *domain = to_pdomain(dom);
|
||||
struct domain_pgtable pgtable;
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&domain->lock, flags);
|
||||
|
||||
/* First save pgtable configuration*/
|
||||
amd_iommu_domain_get_pgtable(domain, &pgtable);
|
||||
|
||||
/* Remove page-table from domain */
|
||||
amd_iommu_domain_clr_pt_root(domain);
|
||||
|
||||
/* Make changes visible to IOMMUs */
|
||||
amd_iommu_domain_update(domain);
|
||||
|
||||
/* Page-table is not visible to IOMMU anymore, so free it */
|
||||
free_pagetable(&pgtable);
|
||||
if (domain->iop.pgtbl_cfg.tlb)
|
||||
free_io_pgtable_ops(&domain->iop.iop.ops);
|
||||
|
||||
spin_unlock_irqrestore(&domain->lock, flags);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user