mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
xen/x86: iommu: Ignore IOMMU mapping requests when a domain is dying
The new x86 IOMMU page-tables allocator will release the pages when
relinquishing the domain resources. However, this is not sufficient
when the domain is dying because nothing prevents page-table to be
allocated.
As the domain is dying, it is not necessary to continue to modify the
IOMMU page-tables as they are going to be destroyed soon.
At the moment, page-table allocates will only happen when iommu_map().
So after this change there will be no more page-table allocation
happening because we don't use superpage mappings yet when not sharing
page tables.
In order to observe d->is_dying correctly, we need to rely on per-arch
locking, so the check to ignore IOMMU mapping is added on the per-driver
map_page() callback.
Fixes: 15bc9a1ef5 ("x86/iommu: add common page-table allocator")
Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Release-Acked-by: Ian Jackson <iwj@xenproject.org>
This commit is contained in:
1 parent
f4cf483e2a
commit
1ef48c82e7
3 files changed
+27
No files matched your search
@@ -285,6 +285,18 @@ int amd_iommu_map_page(struct domain *d, dfn_t dfn, mfn_t mfn,
|
||||
|
||||
spin_lock(&hd->arch.mapping_lock);
|
||||
|
||||
/*
|
||||
* IOMMU mapping request can be safely ignored when the domain is dying.
|
||||
*
|
||||
* hd->arch.mapping_lock guarantees that d->is_dying will be observed
|
||||
* before any page tables are freed (see iommu_free_pgtables()).
|
||||
*/
|
||||
if ( d->is_dying )
|
||||
{
|
||||
spin_unlock(&hd->arch.mapping_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
rc = amd_iommu_alloc_root(d);
|
||||
if ( rc )
|
||||
{
|
||||
|
||||
@@ -1762,6 +1762,18 @@ static int __must_check intel_iommu_map_page(struct domain *d, dfn_t dfn,
|
||||
|
||||
spin_lock(&hd->arch.mapping_lock);
|
||||
|
||||
/*
|
||||
* IOMMU mapping request can be safely ignored when the domain is dying.
|
||||
*
|
||||
* hd->arch.mapping_lock guarantees that d->is_dying will be observed
|
||||
* before any page tables are freed (see iommu_free_pgtables())
|
||||
*/
|
||||
if ( d->is_dying )
|
||||
{
|
||||
spin_unlock(&hd->arch.mapping_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pg_maddr = addr_to_dma_page_maddr(d, dfn_to_daddr(dfn), 1);
|
||||
if ( !pg_maddr )
|
||||
{
|
||||
|
||||
@@ -270,6 +270,9 @@ int iommu_free_pgtables(struct domain *d)
|
||||
if ( !is_iommu_enabled(d) )
|
||||
return 0;
|
||||
|
||||
/* After this barrier, no new IOMMU mappings can be inserted. */
|
||||
spin_barrier(&hd->arch.mapping_lock);
|
||||
|
||||
while ( (pg = page_list_remove_head(&hd->arch.pgtables.list)) )
|
||||
{
|
||||
free_domheap_page(pg);
|
||||
|
||||