AMD-Vi: allocate root table on demand
PATCH v2 1/1 AMD-Vi: allocate root table on demand
This was my originally intended fix for the AMD side of XSA-207:
There's no need to unconditionally allocate the root table, and with that there's then also no way to leak it when a guest has no devices assigned.
---
v2: Add AMD_IOMMU_DEBUG() + domain_crash() to amd_iommu_map_page()
error path for consistency with other code in this function.
xen/drivers/passthrough/amd/iommu_map.c +16 -4
@@ -636,11 +636,10 @@ int amd_iommu_map_page(struct domain *d, {bool_t need_flush =0 ;struct domain_iommu *hd =dom_iommu (d); +int rc;unsigned long pt_mfn[7 ];unsigned int merge_level; -BUG_ON ( !hd->arch.root_table ); -if (iommu_use_hap_pt (d) )return 0 ;
@@ -648,6 +647,15 @@ int amd_iommu_map_page(struct domain *d,spin_lock (&hd->arch.mapping_lock); + rc =amd_iommu_alloc_root (hd); +if ( rc ) + { +spin_unlock (&hd->arch.mapping_lock); +AMD_IOMMU_DEBUG ("Root table alloc failed, gfn = %lx\n" , gfn); +domain_crash (d); +return rc; + } +/* Since HVM domain is initialized with 2 level IO page table, * we might need a deeper page table for lager gfn now */ if (is_hvm_domain (d) )
@@ -717,8 +725,6 @@ int amd_iommu_unmap_page(struct domain *unsigned long pt_mfn[7 ];struct domain_iommu *hd =dom_iommu (d); -BUG_ON ( !hd->arch.root_table ); -if (iommu_use_hap_pt (d) )return 0 ;
@@ -726,6 +732,12 @@ int amd_iommu_unmap_page(struct domain *spin_lock (&hd->arch.mapping_lock); +if ( !hd->arch.root_table ) + { +spin_unlock (&hd->arch.mapping_lock); +return 0 ; + } +/* Since HVM domain is initialized with 2 level IO page table, * we might need a deeper page table for lager gfn now */ if (is_hvm_domain (d) )
xen/drivers/passthrough/amd/pci_amd_iommu.c +21 -21
81 lines not on this page · raw message
xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +1 -0
@@ -56,6 +56,7 @@ int __must_check amd_iommu_map_page(stru unsigned long mfn, unsigned int flags);int __must_check amd_iommu_unmap_page (struct domain *d,unsigned long gfn);u64 amd_iommu_get_next_table_from_pte (u32 *entry); +int __must_check amd_iommu_alloc_root (struct domain_iommu *hd);int amd_iommu_reserve_domain_unity_map (struct domain *domain,u64 phys_addr,unsigned long size,int iw,int ir);
AMD-Vi: allocate root table on demand
This was my originally intended fix for the AMD side of XSA-207:
There's no need to unconditionally allocate the root table, and with that there's then also no way to leak it when a guest has no devices assigned.
---
v2: Add AMD_IOMMU_DEBUG() + domain_crash() to amd_iommu_map_page()
error path for consistency with other code in this function.
xen/drivers/passthrough/amd/iommu_map.c +16 -4
@@ -636,11 +636,10 @@ int amd_iommu_map_page(struct domain *d, {bool_t need_flush =0 ;struct domain_iommu *hd =dom_iommu (d); +int rc;unsigned long pt_mfn[7 ];unsigned int merge_level; -BUG_ON ( !hd->arch.root_table ); -if (iommu_use_hap_pt (d) )return 0 ;
@@ -648,6 +647,15 @@ int amd_iommu_map_page(struct domain *d,spin_lock (&hd->arch.mapping_lock); + rc =amd_iommu_alloc_root (hd); +if ( rc ) + { +spin_unlock (&hd->arch.mapping_lock); +AMD_IOMMU_DEBUG ("Root table alloc failed, gfn = %lx\n" , gfn); +domain_crash (d); +return rc; + } +/* Since HVM domain is initialized with 2 level IO page table, * we might need a deeper page table for lager gfn now */ if (is_hvm_domain (d) )
@@ -717,8 +725,6 @@ int amd_iommu_unmap_page(struct domain *unsigned long pt_mfn[7 ];struct domain_iommu *hd =dom_iommu (d); -BUG_ON ( !hd->arch.root_table ); -if (iommu_use_hap_pt (d) )return 0 ;
@@ -726,6 +732,12 @@ int amd_iommu_unmap_page(struct domain *spin_lock (&hd->arch.mapping_lock); +if ( !hd->arch.root_table ) + { +spin_unlock (&hd->arch.mapping_lock); +return 0 ; + } +/* Since HVM domain is initialized with 2 level IO page table, * we might need a deeper page table for lager gfn now */ if (is_hvm_domain (d) )
xen/drivers/passthrough/amd/pci_amd_iommu.c +21 -21
81 lines not on this page · raw message
xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +1 -0
@@ -56,6 +56,7 @@ int __must_check amd_iommu_map_page(stru unsigned long mfn, unsigned int flags);int __must_check amd_iommu_unmap_page (struct domain *d,unsigned long gfn);u64 amd_iommu_get_next_table_from_pte (u32 *entry); +int __must_check amd_iommu_alloc_root (struct domain_iommu *hd);int amd_iommu_reserve_domain_unity_map (struct domain *domain,u64 phys_addr,unsigned long size,int iw,int ir);
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 9 lines · Jan Beulich
This was my originally intended fix for the AMD side of XSA-207:
There's no need to unconditionally allocate the root table, and with that there's then also no way to leak it when a guest has no devices assigned.Signed-off-by Jan Beulich <[email protected]>---
v2: AddAMD_IOMMU_DEBUG()+domain_crash()toamd_iommu_map_page()
error path for consistency with other code in this function.
Thanks,
Suravee
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel