[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] amd-vi: set IOMMU page table levels based on guest reported paddr width



commit 94039d97e2e3aeee6c7246ad44ab5e0389509d34
Author:     Roger Pau Monné <roger.pau@xxxxxxxxxx>
AuthorDate: Thu Dec 21 11:44:55 2023 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Thu Dec 21 11:44:55 2023 +0100

    amd-vi: set IOMMU page table levels based on guest reported paddr width
    
    However take into account the minimum number of levels required by unity 
maps
    when setting the page table levels.
    
    The previous setting of the page table levels for PV guests based on the
    highest RAM address was bogus, as there can be other non-RAM regions past 
the
    highest RAM address that need to be mapped, for example device MMIO.
    
    For HVM we also take amd_iommu_min_paging_mode into account, however if 
unity
    maps require more than 4 levels attempting to add those will currently fail 
at
    the p2m level, as 4 levels is the maximum supported.
    
    Fixes: 0700c962ac2d ('Add AMD IOMMU support into hypervisor')
    Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/drivers/passthrough/amd/pci_amd_iommu.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c 
b/xen/drivers/passthrough/amd/pci_amd_iommu.c
index 6bc73dc210..4f556e8a72 100644
--- a/xen/drivers/passthrough/amd/pci_amd_iommu.c
+++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c
@@ -359,21 +359,17 @@ int __read_mostly amd_iommu_min_paging_mode = 1;
 static int cf_check amd_iommu_domain_init(struct domain *d)
 {
     struct domain_iommu *hd = dom_iommu(d);
+    int pglvl = amd_iommu_get_paging_mode(
+                    1UL << (domain_max_paddr_bits(d) - PAGE_SHIFT));
+
+    if ( pglvl < 0 )
+        return pglvl;
 
     /*
-     * Choose the number of levels for the IOMMU page tables.
-     * - PV needs 3 or 4, depending on whether there is RAM (including hotplug
-     *   RAM) above the 512G boundary.
-     * - HVM could in principle use 3 or 4 depending on how much guest
-     *   physical address space we give it, but this isn't known yet so use 4
-     *   unilaterally.
-     * - Unity maps may require an even higher number.
+     * Choose the number of levels for the IOMMU page tables, taking into
+     * account unity maps.
      */
-    hd->arch.amd.paging_mode = max(amd_iommu_get_paging_mode(
-            is_hvm_domain(d)
-            ? 1UL << (DEFAULT_DOMAIN_ADDRESS_WIDTH - PAGE_SHIFT)
-            : get_upper_mfn_bound() + 1),
-        amd_iommu_min_paging_mode);
+    hd->arch.amd.paging_mode = max(pglvl, amd_iommu_min_paging_mode);
 
     return 0;
 }
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.