Skip to contentSkip to conversation

xen:x86:mm:p2m: introduce set_rmrr_p2m_entry

PATCH Superseded Tiejun Chen 2 participants 5 messages Jul 28, 2014 – Jul 29, 2014

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 xen:x86:mm:p2m: introduce set_rmrr_p2m_entry

Its used conveniently to create RMRR mapping in shared EPT case.

---
 xen/arch/x86/mm/p2m.c     | 26 ++++++++++++++++++++++++++
 xen/include/asm-x86/p2m.h |  3 +++
 2 files changed, 29 insertions(+)

v4:

* new patch to combine get and set together to create RMRR mapping.

xen/arch/x86/mm/p2m.c +26 -0
index 642ec28..09aa628 100644
@@ -858,6 +858,32 @@ int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn)
     return set_typed_p2m_entry(d, gfn, mfn, p2m_mmio_direct);
 }
 
+int set_rmrr_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn)
+{
+    p2m_type_t p2mt;
+    p2m_access_t a;
+    mfn_t tmp_mfn;
+    struct p2m_domain *p2m = p2m_get_hostp2m(d);
+    int ret = -EBUSY;
+
+    gfn_lock(p2m, gfn, 0);
+
+    tmp_mfn = p2m->get_entry(p2m, gfn, &p2mt, &a, 0, NULL);
+
+    if ( mfn_valid(tmp_mfn) )
+    {
+        gdprintk(XENLOG_ERR,
+                 "Overlapping RMRRs at %"PRIx64".\n", (paddr_t)gfn);
+        goto out;
+    }
+
+    ret = p2m_set_entry(p2m, gfn, mfn, PAGE_ORDER_4K, p2m_mmio_direct,
+                        p2m_access_rw);
+ out:
+    gfn_unlock(p2m, gfn, 0);
+    return ret;
+}
+
 /* Returns: 0 for success, -errno for failure */
 int clear_mmio_p2m_entry(struct domain *d, unsigned long gfn)
 {
xen/include/asm-x86/p2m.h +3 -0
index 0ddbadb..e616b9b 100644
@@ -536,6 +536,9 @@ int p2m_is_logdirty_range(struct p2m_domain *, unsigned long start,
 int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn);
 int clear_mmio_p2m_entry(struct domain *d, unsigned long gfn);
 
+/* Set rmrr addresses in the p2m table (for pass-through) */
+int set_rmrr_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn);
+
 /* Add foreign mapping to the guest's p2m table. */
 int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,
                     unsigned long gpfn, domid_t foreign_domid);
Signature · 1 line
1.9.1
#1 lore raw

PATCH v4 2/2 xen:vtd: missing RMRR mapping while share EPT

intel_iommu_map_page() does nothing if VT-d shares EPT page table. So rmrr_identity_mapping() never create RMRR mapping but in some cases like some GFX drivers it still need to access RMRR.

Here we will create those RMRR mappings even in shared EPT case.

---
 xen/drivers/passthrough/vtd/iommu.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

v4:

* After introduce set_rmrr_p2m_entry we can go there directly.

v3:

* Use set_mmio_p2m_entry() to replace p2m_set_entry()
* Use ASSERT to check

v2:

* Fix coding style.
* Still need to abide intel_iommu_map_page(), so we should do nothing if dom0 and iommu supports pass thru.

xen/drivers/passthrough/vtd/iommu.c +8 -2
index 042b882..fe626e0 100644
@@ -1867,8 +1867,14 @@ static int rmrr_identity_mapping(struct domain *d,
 
     while ( base_pfn < end_pfn )
     {
-        if ( intel_iommu_map_page(d, base_pfn, base_pfn,
-                                  IOMMUF_readable|IOMMUF_writable) )
+        if ( iommu_use_hap_pt(d) )
+        {
+            ASSERT(!iommu_passthrough || !is_hardware_domain(d));
+            if ( set_rmrr_p2m_entry(d, base_pfn, _mfn(base_pfn)) )
+                return -1;
+        }
+        else if ( intel_iommu_map_page(d, base_pfn, base_pfn,
+                                       IOMMUF_readable|IOMMUF_writable) )
             return -1;
         base_pfn++;
     }
Signature · 1 line
1.9.1
#2 lore raw
In reply to Tiejun Chen

xen/arch/x86/mm/p2m.c int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn) · line 861

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 28.07.14 at 13:42, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c +1 -0
@@ -858,6 +858,32 @@ int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn)
     return set_typed_p2m_entry(d, gfn, mfn, p2m_mmio_direct);
 }
 
+int set_rmrr_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn)

Leaving aside all the previously raised points making me hesitate to accept the pair of patches on their own, let's please try to avoid having Intel specific function names in non-Intel-specific code unless that's really the best choice. In the case here, you could s/rmrr/identity/ and at once drop the redundant mfn argument (the function can construct this for the call to p2m_set_entry(), and the function name will make it obvious why this gets derived from gfn).

Jan

#3 lore raw
Quoted 11 lines · Jan Beulich

xen/arch/x86/mm/p2m.c int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn) · line 861

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 28.07.14 at 13:42, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c +1 -0
@@ -858,6 +858,32 @@ int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn)
      return set_typed_p2m_entry(d, gfn, mfn, p2m_mmio_direct);
  }
 
+int set_rmrr_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn)

Leaving aside all the previously raised points making me hesitate to accept the pair of patches on their own, let's please try to avoid

Do you mean we should fix such RMRR problem completely? Looks we need to reserve the RMRR range for each VM. So I'm considering to force reserving this range when we go that XENMEM_machine_memory_map for each VM. But I'm not sure if this is good. So maybe we can do this after this thread since I guess myself need some time to investigate this problem. Or you know this is ongoing by some guys, I'd like to refine my patches to follow that.

Quoted 6 lines

having Intel specific function names in non-Intel-specific code unless that's really the best choice. In the case here, you could s/rmrr/identity/ and at once drop the redundant mfn argument (the function can construct this for the call to p2m_set_entry(), and the function name will make it obvious why this gets derived from gfn).

Okay.

Thanks
Tiejun

#4 lore raw
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 29.07.14 at 08:44, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich

xen/arch/x86/mm/p2m.c int set_mmio_p2m_entry(struct domain *d, unsigned long

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 28.07.14 at 13:42, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c +0 -0
@@ -858,6 +858,32 @@ int set_mmio_p2m_entry(struct domain *d, unsigned long 

gfn, mfn_t mfn)

Quoted 7 lines

xen/arch/x86/mm/p2m.c int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn) · line 861

Quoted 4 lines
xen/arch/x86/mm/p2m.c +1 -0
      return set_typed_p2m_entry(d, gfn, mfn, p2m_mmio_direct);
  }
 
+int set_rmrr_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn)

Leaving aside all the previously raised points making me hesitate to accept the pair of patches on their own, let's please try to avoid

Quoted 7 lines

Do you mean we should fix such RMRR problem completely? Looks we need to reserve the RMRR range for each VM. So I'm considering to force reserving this range when we go that XENMEM_machine_memory_map for each VM. But I'm not sure if this is good. So maybe we can do this after this thread since I guess myself need some time to investigate this problem. Or you know this is ongoing by some guys, I'd like to refine my patches to follow that.

Yes, I do think we either need to fix this in its entirety, or - as suggested before - disallow passing through devices associated with an RMRR. And no, I'm not aware of anyone already looking into this.

Jan