Skip to contentSkip to conversation

xen:x86:mm:p2m: introduce set_identity_p2m_entry

PATCH Superseded Tiejun Chen 1 participant 2 messages Jul 30, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/2 xen:x86:mm:p2m: introduce set_identity_p2m_entry

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

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

v6:

* Refactor set_identity_p2m_entry to make sense

v5:

* Rename this function as set_identity_p2m_entry()
* Get mfn directly inside set_identity_p2m_entry()

v4:

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

xen/arch/x86/mm/p2m.c +29 -0
index 642ec28..06bed7a 100644
@@ -858,6 +858,35 @@ 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_identity_p2m_entry(struct domain *d, unsigned long gfn)
+{
+    p2m_type_t p2mt;
+    p2m_access_t a;
+    mfn_t mfn;
+    struct p2m_domain *p2m = p2m_get_hostp2m(d);
+    int ret = -EBUSY;
+
+    gfn_lock(p2m, gfn, 0);
+
+    mfn = p2m->get_entry(p2m, gfn, &p2mt, &a, 0, NULL);
+
+    if ( !mfn_valid(mfn) )
+        ret = p2m_set_entry(p2m, gfn, _mfn(gfn), PAGE_ORDER_4K, p2m_mmio_direct,
+                            p2m_access_rw);
+    else if ( mfn_x(mfn) == gfn &&
+              p2mt == p2m_mmio_direct &&
+              a == p2m_access_rw )
+        ret = 0;
+    else
+        printk(XENLOG_G_WARNING
+               "Cannot identity map d%d:%lx, already mapped to %lx.\n",
+               d->domain_id, gfn, mfn_x(mfn));
+
+    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..d130f9a 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 identity addresses in the p2m table (for pass-through) */
+int set_identity_p2m_entry(struct domain *d, unsigned long gfn);
+
 /* 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

Please ignore this since another patch is missed in this thread.

Sorry for any convenience.

Thanks
Tiejun

Quoted 76 lines · Tiejun Chen

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

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

v6:

* Refactor set_identity_p2m_entry to make sense

v5:

* Rename this function as set_identity_p2m_entry()
* Get mfn directly inside set_identity_p2m_entry()

v4:

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

xen/arch/x86/mm/p2m.c +29 -0
index 642ec28..06bed7a 100644
@@ -858,6 +858,35 @@ 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_identity_p2m_entry(struct domain *d, unsigned long gfn)
+{
+    p2m_type_t p2mt;
+    p2m_access_t a;
+    mfn_t mfn;
+    struct p2m_domain *p2m = p2m_get_hostp2m(d);
+    int ret = -EBUSY;
+
+    gfn_lock(p2m, gfn, 0);
+
+    mfn = p2m->get_entry(p2m, gfn, &p2mt, &a, 0, NULL);
+
+    if ( !mfn_valid(mfn) )
+        ret = p2m_set_entry(p2m, gfn, _mfn(gfn), PAGE_ORDER_4K, p2m_mmio_direct,
+                            p2m_access_rw);
+    else if ( mfn_x(mfn) == gfn &&
+              p2mt == p2m_mmio_direct &&
+              a == p2m_access_rw )
+        ret = 0;
+    else
+        printk(XENLOG_G_WARNING
+               "Cannot identity map d%d:%lx, already mapped to %lx.\n",
+               d->domain_id, gfn, mfn_x(mfn));
+
+    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..d130f9a 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 identity addresses in the p2m table (for pass-through) */
+int set_identity_p2m_entry(struct domain *d, unsigned long gfn);
+
  /* 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);