Skip to contentSkip to conversation

PVH Dom0 RMRR IOMMU mapping regression fix

PATCH In review [email protected] 3 participants 5 messages Sep 25, 2015 – Sep 29, 2015

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 PVH Dom0 RMRR IOMMU mapping regression fix

From: Elena Ufimtseva <[email protected]>

This patch addresses a regression introduced by commit 5ae03990c120a7b3067a52d9784c9aa72c0705a6 in new set_identity_p2m_entry. RMRRs are not being mapped in IOMMU for PVH Dom0. This causes pages faults and some long 'hang-like' delays during Dom0 PVH boot and device assignments.

During construct_dom0, in PVH path p2m is being constructed and identity mapped in IOMMU. The p2m type is p2m_mmio_direct and p2m access p2m_rwx. New code used to map RMRRs invoked from rmrr_identity_mapping checks if p2m entry exists with same type and access and if yes, skips iommu mapping. Since there are p2m entries for pvh dom0 iomem, RMRRs are not being mapped in IOMMU.

As was mentioned in the earlier discussion, the PVH Dom0 construction code should be modified to properly map RMRR regions in IOMMU. Since change will be too invasive, this solution is a temporary fix at this time before better solution is in. Also as Jan mentioned, there is no need in having 'x' permissions for p2m entry of a mmio region, thus changed here.

You comments and suggestions are welcome!
Thank you.

---

Changes in v2:
- removed 'x' permission from p2m entry what has mmio read only regions. conducted tests did not demostrate IOMMU Page Faults that I mentioned in v1(RFC) of this patch;

 xen/arch/x86/domain_build.c |  4 ++--
 xen/arch/x86/mm/p2m.c       | 12 +++++++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)
xen/arch/x86/domain_build.c +2 -2
index 18cf6aa..bca6fe7 100644
@@ -432,9 +432,9 @@ static __init void pvh_add_mem_mapping(struct domain *d, unsigned long gfn,
         }
 
         if ( rangeset_contains_singleton(mmio_ro_ranges, mfn + i) )
-            a = p2m_access_rx;
+            a = p2m_access_r;
         else
-            a = p2m_access_rwx;
+            a = p2m_access_rw;
 
         if ( (rc = set_mmio_p2m_entry(d, gfn + i, _mfn(mfn + i), a)) )
             panic("pvh_add_mem_mapping: gfn:%lx mfn:%lx i:%ld rc:%d\n",
xen/arch/x86/mm/p2m.c +11 -1
index e1d930a..7ba7832 100644
@@ -972,7 +972,17 @@ int set_identity_p2m_entry(struct domain *d, unsigned long gfn,
         ret = p2m_set_entry(p2m, gfn, _mfn(gfn), PAGE_ORDER_4K,
                             p2m_mmio_direct, p2ma);
     else if ( mfn_x(mfn) == gfn && p2mt == p2m_mmio_direct && a == p2ma )
-        ret = 0;
+    {
+        /*
+         * PVH fixme: during Dom0 PVH construction, p2m entries are being set
+         * but iomem regions are not mapped with IOMMU. This makes sure that
+         * RMRRs are correctly mapped with IOMMU.
+         */
+        if ( is_hardware_domain(d) && !iommu_use_hap_pt(d) )
+            ret = iommu_map_page(d, gfn, gfn, IOMMUF_readable|IOMMUF_writable);
+        else
+            ret = 0;
+    }
     else
     {
         if ( flag & XEN_DOMCTL_DEV_RDM_RELAXED )
Signature · 1 line
2.1.4
Reviewed-by on v2 1/1
#1 lore raw
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 25.09.15 at 22:59, <[email protected]> wrote:

From: Elena Ufimtseva <[email protected]>

This patch addresses a regression introduced by commit 5ae03990c120a7b3067a52d9784c9aa72c0705a6 in new set_identity_p2m_entry. RMRRs are not being mapped in IOMMU for PVH Dom0. This causes pages faults and
some long 'hang-like' delays during Dom0 PVH boot and device assignments.

During construct_dom0, in PVH path p2m is being constructed and identity mapped
in IOMMU. The p2m type is p2m_mmio_direct and p2m access p2m_rwx. New code used to map RMRRs invoked from rmrr_identity_mapping checks if p2m entry exists with same type and access and if yes, skips iommu mapping. Since there are p2m entries for pvh dom0 iomem, RMRRs are not being mapped in IOMMU.

Quoted 7 lines

As was mentioned in the earlier discussion, the PVH Dom0 construction code should be modified to properly map RMRR regions in IOMMU. Since change will be
too invasive, this solution is a temporary fix at this time before better solution is in. Also as Jan mentioned, there is no need in having 'x' permissions
for p2m entry of a mmio region, thus changed here.

Well, now that I look at this again I think there could be reasons for execute permission to be needed: Code placed in ROM may require this. But then again Dom0 shouldn't on its own (i.e. without involving the hypervisor) invoke such code, which usually would be expecting to be run in root mode ring 0 anyway. So I think not defaulting to include X is the right thing. Hence ...

Quoted 1 line
#2 lore raw
Quoted 32 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 25.09.15 at 22:59, <[email protected]> wrote:

From: Elena Ufimtseva <[email protected]>

This patch addresses a regression introduced by commit 5ae03990c120a7b3067a52d9784c9aa72c0705a6 in new set_identity_p2m_entry. RMRRs are not being mapped in IOMMU for PVH Dom0. This causes pages faults and
some long 'hang-like' delays during Dom0 PVH boot and device assignments.

During construct_dom0, in PVH path p2m is being constructed and identity mapped
in IOMMU. The p2m type is p2m_mmio_direct and p2m access p2m_rwx. New code used to map RMRRs invoked from rmrr_identity_mapping checks if p2m entry exists with same type and access and if yes, skips iommu mapping. Since there are p2m entries for pvh dom0 iomem, RMRRs are not being mapped in IOMMU.

Quoted 7 lines

As was mentioned in the earlier discussion, the PVH Dom0 construction code should be modified to properly map RMRR regions in IOMMU. Since change will be
too invasive, this solution is a temporary fix at this time before better solution is in. Also as Jan mentioned, there is no need in having 'x' permissions
for p2m entry of a mmio region, thus changed here.

Well, now that I look at this again I think there could be reasons for execute permission to be needed: Code placed in ROM may require this. But then again Dom0 shouldn't on its own (i.e. without involving the hypervisor) invoke such code, which usually would be expecting to be run in root mode ring 0 anyway. So I think not defaulting to include X is the right thing. Hence ...

Quoted 4 lines
Quoted 1 line

Thanks Jan!

#3 lore raw
In reply to [email protected]
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 25.09.15 at 22:59, <[email protected]> wrote:

From: Elena Ufimtseva <[email protected]>

This patch addresses a regression introduced by commit 5ae03990c120a7b3067a52d9784c9aa72c0705a6 in new set_identity_p2m_entry. RMRRs are not being mapped in IOMMU for PVH Dom0. This causes pages faults and
some long 'hang-like' delays during Dom0 PVH boot and device assignments.

During construct_dom0, in PVH path p2m is being constructed and identity mapped
in IOMMU. The p2m type is p2m_mmio_direct and p2m access p2m_rwx. New code used to map RMRRs invoked from rmrr_identity_mapping checks if p2m entry exists with same type and access and if yes, skips iommu mapping. Since there are p2m entries for pvh dom0 iomem, RMRRs are not being mapped in IOMMU.

As was mentioned in the earlier discussion, the PVH Dom0 construction code should be modified to properly map RMRR regions in IOMMU. Since change will be
too invasive, this solution is a temporary fix at this time before better solution is in. Also as Jan mentioned, there is no need in having 'x' permissions
for p2m entry of a mmio region, thus changed here.

Quoted 4 lines

You comments and suggestions are welcome!
Thank you.

Wei,

how about this one for 4.6 then? On one hand I recall you validly stating that PVH is still unsupported, but otoh the change is well isolated against affecting anything but PVH, i.e. it is very low risk.

Jan

#4 lore raw
Quoted 28 lines · Jan Beulich
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 25.09.15 at 22:59, <[email protected]> wrote:

From: Elena Ufimtseva <[email protected]>

This patch addresses a regression introduced by commit 5ae03990c120a7b3067a52d9784c9aa72c0705a6 in new set_identity_p2m_entry. RMRRs are not being mapped in IOMMU for PVH Dom0. This causes pages faults and
some long 'hang-like' delays during Dom0 PVH boot and device assignments.

During construct_dom0, in PVH path p2m is being constructed and identity mapped
in IOMMU. The p2m type is p2m_mmio_direct and p2m access p2m_rwx. New code used to map RMRRs invoked from rmrr_identity_mapping checks if p2m entry exists with same type and access and if yes, skips iommu mapping. Since there are p2m entries for pvh dom0 iomem, RMRRs are not being mapped in IOMMU.

As was mentioned in the earlier discussion, the PVH Dom0 construction code should be modified to properly map RMRR regions in IOMMU. Since change will be
too invasive, this solution is a temporary fix at this time before better solution is in. Also as Jan mentioned, there is no need in having 'x' permissions
for p2m entry of a mmio region, thus changed here.

You comments and suggestions are welcome!
Thank you.

Quoted 8 lines
Quoted 1 line

Wei,

how about this one for 4.6 then? On one hand I recall you validly stating that PVH is still unsupported, but otoh the change is well isolated against affecting anything but PVH, i.e. it is very low risk.

I'm fine with this going in.

Quoted 1 line

Jan