Skip to contentSkip to conversation

: PVH xen: introduce p2m_map_foreign

PATCH In review Mukesh Rathor 4 participants 5 messages Mar 16, 2013 – Mar 21, 2013

lore
Share & tools
lore
#0 lore raw

PATCH v2 13/18 : PVH xen: introduce p2m_map_foreign

In this patch, I introduce a new type p2m_map_foreign for pages that a dom0 maps from foreign domains its creating. Also, add set_foreign_p2m_entry() to map p2m_map_foreign type pages. Other misc changes related to p2m.

Changes in V2:
- Make guest_physmap_add_entry() same for PVH in terms of overwriting old entry.
- In set_foreign_p2m_entry() do locked get_gfn and not unlocked.
- Replace ASSERT with return -EINVAL in do_physdev_op.
- Remove unnecessary check for PVH in do_physdev_op().

---
 xen/arch/x86/domctl.c     |   19 +++++++++++++------
 xen/arch/x86/mm/p2m-ept.c |    3 ++-
 xen/arch/x86/mm/p2m-pt.c  |    3 ++-
 xen/arch/x86/mm/p2m.c     |   30 +++++++++++++++++++++++++++++-
 xen/arch/x86/physdev.c    |    8 ++++++++
 xen/include/asm-x86/p2m.h |    4 ++++
 6 files changed, 58 insertions(+), 9 deletions(-)
xen/arch/x86/domctl.c +13 -6
index ecc8240..da49d6d 100644
@@ -64,9 +64,10 @@ long domctl_memory_mapping(struct domain *d, unsigned long gfn,
 
     if ( add_map )
     {
-        printk(XENLOG_G_INFO
-               "memory_map:add: dom%d gfn=%lx mfn=%lx nr=%lx\n",
-               d->domain_id, gfn, mfn, nr_mfns);
+        if ( !is_pvh_domain(d) )     /* PVH maps lots and lots */
+            printk(XENLOG_G_INFO
+                   "memory_map:add: dom%d gfn=%lx mfn=%lx nr=%lx\n",
+                   d->domain_id, gfn, mfn, nr_mfns);
 
         ret = iomem_permit_access(d, mfn, mfn + nr_mfns - 1);
         if ( !ret && paging_mode_translate(d) )
@@ -89,9 +90,10 @@ long domctl_memory_mapping(struct domain *d, unsigned long gfn,
             }
         }
     } else {
-        printk(XENLOG_G_INFO
-               "memory_map:remove: dom%d gfn=%lx mfn=%lx nr=%lx\n",
-               d->domain_id, gfn, mfn, nr_mfns);
+        if ( !is_pvh_domain(d) )     /* PVH unmaps lots and lots */
+            printk(XENLOG_G_INFO
+                   "memory_map:remove: dom%d gfn=%lx mfn=%lx nr=%lx\n",
+                   d->domain_id, gfn, mfn, nr_mfns);
 
         if ( paging_mode_translate(d) )
             for ( i = 0; i < nr_mfns; i++ )
@@ -1307,6 +1309,11 @@ void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
             c.nat->gs_base_kernel = hvm_get_shadow_gs_base(v);
         }
     }
+    else if ( is_pvh_vcpu(v) )
+    {
+        /* fixme: punt it to phase II */
+        printk("PVH: fixme: arch_get_info_guest()\n");
+    }
     else
     {
         c(ldt_base = v->arch.pv_vcpu.ldt_base);
xen/arch/x86/mm/p2m-ept.c +2 -1
index a2d1591..38ea9ec 100644
@@ -75,6 +75,7 @@ static void ept_p2m_type_to_flags(ept_entry_t *entry, p2m_type_t type, p2m_acces
             entry->w = 0;
             break;
         case p2m_grant_map_rw:
+        case p2m_map_foreign:
             entry->r = entry->w = 1;
             entry->x = 0;
             break;
@@ -430,7 +431,7 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     }
 
     /* Track the highest gfn for which we have ever had a valid mapping */
-    if ( p2mt != p2m_invalid &&
+    if ( p2mt != p2m_invalid && p2mt != p2m_mmio_dm &&
          (gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) )
         p2m->max_mapped_pfn = gfn + (1UL << order) - 1;
 
xen/arch/x86/mm/p2m-pt.c +2 -1
index 302b621..3f46418 100644
@@ -89,6 +89,7 @@ static unsigned long p2m_type_to_flags(p2m_type_t t, mfn_t mfn)
     case p2m_ram_rw:
         return flags | P2M_BASE_FLAGS | _PAGE_RW;
     case p2m_grant_map_rw:
+    case p2m_map_foreign:
         return flags | P2M_BASE_FLAGS | _PAGE_RW | _PAGE_NX_BIT;
     case p2m_mmio_direct:
         if ( !rangeset_contains_singleton(mmio_ro_ranges, mfn_x(mfn)) )
@@ -429,7 +430,7 @@ p2m_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     }
 
     /* Track the highest gfn for which we have ever had a valid mapping */
-    if ( p2mt != p2m_invalid
+    if ( p2mt != p2m_invalid && p2mt != p2m_mmio_dm
          && (gfn + (1UL << page_order) - 1 > p2m->max_mapped_pfn) )
         p2m->max_mapped_pfn = gfn + (1UL << page_order) - 1;
 
xen/arch/x86/mm/p2m.c +29 -1
index 4837de3..6888cf1 100644
@@ -523,7 +523,7 @@ p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn, unsigned long mfn,
         for ( i = 0; i < (1UL << page_order); i++ )
         {
             mfn_return = p2m->get_entry(p2m, gfn + i, &t, &a, 0, NULL);
-            if ( !p2m_is_grant(t) && !p2m_is_shared(t) )
+            if ( !p2m_is_grant(t) && !p2m_is_shared(t) && !p2m_is_foreign(t) )
                 set_gpfn_from_mfn(mfn+i, INVALID_M2P_ENTRY);
             ASSERT( !p2m_is_valid(t) || mfn + i == mfn_x(mfn_return) );
         }
@@ -754,7 +754,35 @@ void p2m_change_type_range(struct domain *d,
     p2m_unlock(p2m);
 }
 
+/* Returns: True for success. 0 for failure */
+int set_foreign_p2m_entry(struct domain *dp, unsigned long gfn, mfn_t mfn)
+{
+    int rc = 0;
+    p2m_type_t ot;
+    mfn_t omfn;
+    struct p2m_domain *p2m = p2m_get_hostp2m(dp);
+
+    if ( !paging_mode_translate(dp) )
+        return 0;
+
+    omfn = get_gfn_query(dp, gfn, &ot);
+    if (mfn_valid(omfn)) {
+        gdprintk(XENLOG_ERR, "Already mapped mfn %lx at gfn:%lx\n", 
+                 mfn_x(omfn), gfn);
+        set_gpfn_from_mfn(mfn_x(omfn), INVALID_M2P_ENTRY);
+    }
+    put_gfn(dp, gfn);
 
+    P2M_DEBUG("set foreign %lx %lx\n", gfn, mfn_x(mfn));
+    p2m_lock(p2m);
+    rc = set_p2m_entry(p2m, gfn, mfn, 0, p2m_map_foreign, p2m->default_access);
+    p2m_unlock(p2m);
+    if ( rc == 0 )
+        gdprintk(XENLOG_ERR,
+            "set_foreign_p2m_entry: set_p2m_entry failed! gfn:%lx mfn=%08lx\n",
+            gfn, mfn_x(get_gfn_query(dp, gfn, &ot)));
+    return rc;
+}
 
 int
 set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn)
xen/arch/x86/physdev.c +8 -0
index 876ac9d..ca66c1c 100644
@@ -475,6 +475,12 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 
     case PHYSDEVOP_set_iopl: {
         struct physdev_set_iopl set_iopl;
+
+        if ( is_pvh_vcpu(current) ) {
+            ret = -EINVAL;
+            break;
+        }
+
         ret = -EFAULT;
         if ( copy_from_guest(&set_iopl, arg, 1) != 0 )
             break;
@@ -488,6 +494,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 
     case PHYSDEVOP_set_iobitmap: {
         struct physdev_set_iobitmap set_iobitmap;
+
+        ASSERT( !is_pvh_vcpu(current) );
         ret = -EFAULT;
         if ( copy_from_guest(&set_iobitmap, arg, 1) != 0 )
             break;
xen/include/asm-x86/p2m.h +4 -0
index 43583b2..b76dc33 100644
@@ -70,6 +70,7 @@ typedef enum {
     p2m_ram_paging_in = 11,       /* Memory that is being paged in */
     p2m_ram_shared = 12,          /* Shared or sharable memory */
     p2m_ram_broken = 13,          /* Broken page, access cause domain crash */
+    p2m_map_foreign  = 14,        /* ram pages from foreign domain */
 } p2m_type_t;
 
 /*
@@ -180,6 +181,7 @@ typedef unsigned int p2m_query_t;
 #define p2m_is_sharable(_t) (p2m_to_mask(_t) & P2M_SHARABLE_TYPES)
 #define p2m_is_shared(_t)   (p2m_to_mask(_t) & P2M_SHARED_TYPES)
 #define p2m_is_broken(_t)   (p2m_to_mask(_t) & P2M_BROKEN_TYPES)
+#define p2m_is_foreign(_t)  (p2m_to_mask(_t) & p2m_to_mask(p2m_map_foreign))
 
 /* Per-p2m-table state */
 struct p2m_domain {
@@ -510,6 +512,8 @@ p2m_type_t p2m_change_type(struct domain *d, unsigned long gfn,
 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 foreign mfn in the current guest's p2m table (for pvh dom0) */
+int set_foreign_p2m_entry(struct domain *domp, unsigned long gfn, mfn_t mfn);
 
 /* 
  * Populate-on-demand
Signature · 1 line
1.7.2.3
#1 lore raw

xen/arch/x86/domctl.c void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c) · line 1316

Quoted 10 lines
Quoted 1 line
Quoted 1 line · Mukesh Rathor
xen/arch/x86/domctl.c +5 -0
@@ -1307,6 +1309,11 @@ void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
             c.nat->gs_base_kernel = hvm_get_shadow_gs_base(v);
         }
     }
+    else if ( is_pvh_vcpu(v) )
+    {
+        /* fixme: punt it to phase II */
+        printk("PVH: fixme: arch_get_info_guest()\n");
+    }

This has hardly anything to do with the patch at hand.

xen/arch/x86/mm/p2m-ept.c ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn, · line 434

Quoted 6 lines
xen/arch/x86/mm/p2m-ept.c +1 -1
@@ -430,7 +431,7 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     }
 
     /* Track the highest gfn for which we have ever had a valid mapping */
-    if ( p2mt != p2m_invalid &&
+    if ( p2mt != p2m_invalid && p2mt != p2m_mmio_dm &&

Considering the subject of the patch, was this perhaps meant to be p2m_map_foreign?

xen/arch/x86/mm/p2m-pt.c p2m_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn, · line 433

Quoted 6 lines
xen/arch/x86/mm/p2m-pt.c +1 -1
@@ -429,7 +430,7 @@ p2m_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     }
 
     /* Track the highest gfn for which we have ever had a valid mapping */
-    if ( p2mt != p2m_invalid
+    if ( p2mt != p2m_invalid && p2mt != p2m_mmio_dm

Same here.

xen/arch/x86/physdev.c ret_t do_physdev_op(int cmd, · line 484

Quoted 13 lines
xen/arch/x86/physdev.c +6 -0
@@ -475,6 +475,12 @@ ret_t do_physdev_op(int cmd, 
 XEN_GUEST_HANDLE_PARAM(void) arg)
 
     case PHYSDEVOP_set_iopl: {
         struct physdev_set_iopl set_iopl;
+
+        if ( is_pvh_vcpu(current) ) {
+            ret = -EINVAL;
+            break;
+        }
+

Again unrelated to the subject of the patch.

xen/arch/x86/physdev.c ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 498

Quoted 6 lines
xen/arch/x86/physdev.c +2 -0
@@ -488,6 +494,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 
     case PHYSDEVOP_set_iobitmap: {
         struct physdev_set_iobitmap set_iobitmap;
+
+        ASSERT( !is_pvh_vcpu(current) );

Again.

Jan

#2 lore raw
In reply to Mukesh Rathor
Quoted 21 lines
Quoted 1 line
Quoted 1 line · Mukesh Rathor
xen/arch/x86/domctl.c +4 -3
@@ -64,9 +64,10 @@ long domctl_memory_mapping(struct domain *d, unsigned long gfn,
 
     if ( add_map )
     {
-        printk(XENLOG_G_INFO
-               "memory_map:add: dom%d gfn=%lx mfn=%lx nr=%lx\n",
-               d->domain_id, gfn, mfn, nr_mfns);
+        if ( !is_pvh_domain(d) )     /* PVH maps lots and lots */
+            printk(XENLOG_G_INFO
+                   "memory_map:add: dom%d gfn=%lx mfn=%lx nr=%lx\n",
+                   d->domain_id, gfn, mfn, nr_mfns);
 
         ret = iomem_permit_access(d, mfn, mfn + nr_mfns - 1);
         if ( !ret && paging_mode_translate(d) )
@@ -89,9 +90,10 @@ long domctl_memory_mapping(struct domain *d, unsigned long gfn,
             }
         }
     } else {

xen/arch/x86/domctl.c long domctl_memory_mapping(struct domain *d, unsigned long gfn, · line 99

Quoted 10 lines
xen/arch/x86/domctl.c +4 -3
-        printk(XENLOG_G_INFO
-               "memory_map:remove: dom%d gfn=%lx mfn=%lx nr=%lx\n",
-               d->domain_id, gfn, mfn, nr_mfns);
+        if ( !is_pvh_domain(d) )     /* PVH unmaps lots and lots */
+            printk(XENLOG_G_INFO
+                   "memory_map:remove: dom%d gfn=%lx mfn=%lx nr=%lx\n",
+                   d->domain_id, gfn, mfn, nr_mfns);
 
         if ( paging_mode_translate(d) )
             for ( i = 0; i < nr_mfns; i++ )

While these change looked related to the subject at a first glance, with the patch not adding the promised new caller of the function I don't see the relation of the changes above to the rest of the patch.

Jan

#3 lore raw
In reply to Mukesh Rathor
Quoted 5 lines · Mukesh Rathor

In this patch, I introduce a new type p2m_map_foreign for pages that a dom0 maps from foreign domains its creating. Also, add set_foreign_p2m_entry() to map p2m_map_foreign type pages. Other misc changes related to p2m.

Quoted 7 lines

Changes in V2:
- Make guest_physmap_add_entry() same for PVH in terms of overwriting old entry.
- In set_foreign_p2m_entry() do locked get_gfn and not unlocked.
- Replace ASSERT with return -EINVAL in do_physdev_op.
- Remove unnecessary check for PVH in do_physdev_op().

You should really CC Tim on this patch. Doing it for you.

Quoted 110 lines
---
 xen/arch/x86/domctl.c     |   19 +++++++++++++------
 xen/arch/x86/mm/p2m-ept.c |    3 ++-
 xen/arch/x86/mm/p2m-pt.c  |    3 ++-
 xen/arch/x86/mm/p2m.c     |   30 +++++++++++++++++++++++++++++-
 xen/arch/x86/physdev.c    |    8 ++++++++
 xen/include/asm-x86/p2m.h |    4 ++++
 6 files changed, 58 insertions(+), 9 deletions(-)
xen/arch/x86/domctl.c +13 -6
index ecc8240..da49d6d 100644
@@ -64,9 +64,10 @@ long domctl_memory_mapping(struct domain *d, unsigned long gfn,
 
     if ( add_map )
     {
-        printk(XENLOG_G_INFO
-               "memory_map:add: dom%d gfn=%lx mfn=%lx nr=%lx\n",
-               d->domain_id, gfn, mfn, nr_mfns);
+        if ( !is_pvh_domain(d) )     /* PVH maps lots and lots */
+            printk(XENLOG_G_INFO
+                   "memory_map:add: dom%d gfn=%lx mfn=%lx nr=%lx\n",
+                   d->domain_id, gfn, mfn, nr_mfns);
 
         ret = iomem_permit_access(d, mfn, mfn + nr_mfns - 1);
         if ( !ret && paging_mode_translate(d) )
@@ -89,9 +90,10 @@ long domctl_memory_mapping(struct domain *d, unsigned long gfn,
             }
         }
     } else {
-        printk(XENLOG_G_INFO
-               "memory_map:remove: dom%d gfn=%lx mfn=%lx nr=%lx\n",
-               d->domain_id, gfn, mfn, nr_mfns);
+        if ( !is_pvh_domain(d) )     /* PVH unmaps lots and lots */
+            printk(XENLOG_G_INFO
+                   "memory_map:remove: dom%d gfn=%lx mfn=%lx nr=%lx\n",
+                   d->domain_id, gfn, mfn, nr_mfns);
 
         if ( paging_mode_translate(d) )
             for ( i = 0; i < nr_mfns; i++ )
@@ -1307,6 +1309,11 @@ void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
             c.nat->gs_base_kernel = hvm_get_shadow_gs_base(v);
         }
     }
+    else if ( is_pvh_vcpu(v) )
+    {
+        /* fixme: punt it to phase II */
+        printk("PVH: fixme: arch_get_info_guest()\n");
+    }
     else
     {
         c(ldt_base = v->arch.pv_vcpu.ldt_base);
xen/arch/x86/mm/p2m-ept.c +2 -1
index a2d1591..38ea9ec 100644
@@ -75,6 +75,7 @@ static void ept_p2m_type_to_flags(ept_entry_t *entry, p2m_type_t type, p2m_acces
             entry->w = 0;
             break;
         case p2m_grant_map_rw:
+        case p2m_map_foreign:
             entry->r = entry->w = 1;
             entry->x = 0;
             break;
@@ -430,7 +431,7 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     }
 
     /* Track the highest gfn for which we have ever had a valid mapping */
-    if ( p2mt != p2m_invalid &&
+    if ( p2mt != p2m_invalid && p2mt != p2m_mmio_dm &&
          (gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) )
         p2m->max_mapped_pfn = gfn + (1UL << order) - 1;
 
xen/arch/x86/mm/p2m-pt.c +2 -1
index 302b621..3f46418 100644
@@ -89,6 +89,7 @@ static unsigned long p2m_type_to_flags(p2m_type_t t, mfn_t mfn)
     case p2m_ram_rw:
         return flags | P2M_BASE_FLAGS | _PAGE_RW;
     case p2m_grant_map_rw:
+    case p2m_map_foreign:
         return flags | P2M_BASE_FLAGS | _PAGE_RW | _PAGE_NX_BIT;
     case p2m_mmio_direct:
         if ( !rangeset_contains_singleton(mmio_ro_ranges, mfn_x(mfn)) )
@@ -429,7 +430,7 @@ p2m_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     }
 
     /* Track the highest gfn for which we have ever had a valid mapping */
-    if ( p2mt != p2m_invalid
+    if ( p2mt != p2m_invalid && p2mt != p2m_mmio_dm
          && (gfn + (1UL << page_order) - 1 > p2m->max_mapped_pfn) )
         p2m->max_mapped_pfn = gfn + (1UL << page_order) - 1;
 
xen/arch/x86/mm/p2m.c +1 -1
index 4837de3..6888cf1 100644
@@ -523,7 +523,7 @@ p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn, unsigned long mfn,
         for ( i = 0; i < (1UL << page_order); i++ )
         {
             mfn_return = p2m->get_entry(p2m, gfn + i, &t, &a, 0, NULL);
-            if ( !p2m_is_grant(t) && !p2m_is_shared(t) )
+            if ( !p2m_is_grant(t) && !p2m_is_shared(t) && !p2m_is_foreign(t) )
                 set_gpfn_from_mfn(mfn+i, INVALID_M2P_ENTRY);
             ASSERT( !p2m_is_valid(t) || mfn + i == mfn_x(mfn_return) );
         }

xen/arch/x86/mm/p2m.c void p2m_change_type_range(struct domain *d, · line 757

Quoted 4 lines
xen/arch/x86/mm/p2m.c +1 -0
@@ -754,7 +754,35 @@ void p2m_change_type_range(struct domain *d,
     p2m_unlock(p2m);
 }
 
+/* Returns: True for success. 0 for failure */

You mean 1 for success? If so, why not just use a bool?

Quoted 36 lines
xen/arch/x86/mm/p2m.c +27 -0
+int set_foreign_p2m_entry(struct domain *dp, unsigned long gfn, mfn_t mfn)
+{
+    int rc = 0;
+    p2m_type_t ot;
+    mfn_t omfn;
+    struct p2m_domain *p2m = p2m_get_hostp2m(dp);
+
+    if ( !paging_mode_translate(dp) )
+        return 0;
+
+    omfn = get_gfn_query(dp, gfn, &ot);
+    if (mfn_valid(omfn)) {
+        gdprintk(XENLOG_ERR, "Already mapped mfn %lx at gfn:%lx\n", 
+                 mfn_x(omfn), gfn);
+        set_gpfn_from_mfn(mfn_x(omfn), INVALID_M2P_ENTRY);
+    }
+    put_gfn(dp, gfn);
 
+    P2M_DEBUG("set foreign %lx %lx\n", gfn, mfn_x(mfn));
+    p2m_lock(p2m);
+    rc = set_p2m_entry(p2m, gfn, mfn, 0, p2m_map_foreign, p2m->default_access);
+    p2m_unlock(p2m);
+    if ( rc == 0 )
+        gdprintk(XENLOG_ERR,
+            "set_foreign_p2m_entry: set_p2m_entry failed! gfn:%lx mfn=%08lx\n",
+            gfn, mfn_x(get_gfn_query(dp, gfn, &ot)));
+    return rc;
+}
 
 int
 set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn)
xen/arch/x86/physdev.c +0 -0
index 876ac9d..ca66c1c 100644

xen/arch/x86/physdev.c ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 480

Quoted 6 lines
xen/arch/x86/physdev.c +3 -0
@@ -475,6 +475,12 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 
     case PHYSDEVOP_set_iopl: {
         struct physdev_set_iopl set_iopl;
+
+        if ( is_pvh_vcpu(current) ) {
+            ret = -EINVAL;

That looks like it belongs to a different patch - one that filters which of the hypercalls should NOT be called when doing PVH.

And perhaps -ENOSYS?

xen/arch/x86/physdev.c ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 498

Quoted 12 lines
xen/arch/x86/physdev.c +5 -0
+            break;
+        }
+
         ret = -EFAULT;
         if ( copy_from_guest(&set_iopl, arg, 1) != 0 )
             break;
@@ -488,6 +494,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 
     case PHYSDEVOP_set_iobitmap: {
         struct physdev_set_iobitmap set_iobitmap;
+
+        ASSERT( !is_pvh_vcpu(current) );

Ouch! Why not the same treatment as previously? return -ENOSYS.

Quoted 41 lines
xen/arch/x86/physdev.c +0 -0
         ret = -EFAULT;
         if ( copy_from_guest(&set_iobitmap, arg, 1) != 0 )
             break;
xen/include/asm-x86/p2m.h +4 -0
index 43583b2..b76dc33 100644
@@ -70,6 +70,7 @@ typedef enum {
     p2m_ram_paging_in = 11,       /* Memory that is being paged in */
     p2m_ram_shared = 12,          /* Shared or sharable memory */
     p2m_ram_broken = 13,          /* Broken page, access cause domain crash */
+    p2m_map_foreign  = 14,        /* ram pages from foreign domain */
 } p2m_type_t;
 
 /*
@@ -180,6 +181,7 @@ typedef unsigned int p2m_query_t;
 #define p2m_is_sharable(_t) (p2m_to_mask(_t) & P2M_SHARABLE_TYPES)
 #define p2m_is_shared(_t)   (p2m_to_mask(_t) & P2M_SHARED_TYPES)
 #define p2m_is_broken(_t)   (p2m_to_mask(_t) & P2M_BROKEN_TYPES)
+#define p2m_is_foreign(_t)  (p2m_to_mask(_t) & p2m_to_mask(p2m_map_foreign))
 
 /* Per-p2m-table state */
 struct p2m_domain {
@@ -510,6 +512,8 @@ p2m_type_t p2m_change_type(struct domain *d, unsigned long gfn,
 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 foreign mfn in the current guest's p2m table (for pvh dom0) */
+int set_foreign_p2m_entry(struct domain *domp, unsigned long gfn, mfn_t mfn);
 
 /* 
  * Populate-on-demand
Signature · 7 lines
1.7.2.3


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#4 lore raw
In reply to Mukesh Rathor
Quoted 4 lines · Mukesh Rathor

In this patch, I introduce a new type p2m_map_foreign for pages that a dom0 maps from foreign domains its creating. Also, add set_foreign_p2m_entry() to map p2m_map_foreign type pages. Other misc changes related to p2m.

First of all, as Jan and Konrad have pointed out, there seems to be a lot of unrelated changes in here, which needs to be separated out.

Quoted 13 lines
xen/arch/x86/mm/p2m-ept.c +1 -0
index a2d1591..38ea9ec 100644
@@ -75,6 +75,7 @@ static void ept_p2m_type_to_flags(ept_entry_t *entry, p2m_type_t type, p2m_acces
             entry->w = 0;
             break;
         case p2m_grant_map_rw:
+        case p2m_map_foreign:
             entry->r = entry->w = 1;
             entry->x = 0;
             break;

xen/arch/x86/mm/p2m-ept.c ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn, · line 436

Quoted 7 lines
xen/arch/x86/mm/p2m-ept.c +1 -1
@@ -430,7 +431,7 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     }
 
     /* Track the highest gfn for which we have ever had a valid mapping */
-    if ( p2mt != p2m_invalid &&
+    if ( p2mt != p2m_invalid && p2mt != p2m_mmio_dm &&
          (gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) )
         p2m->max_mapped_pfn = gfn + (1UL << order) - 1;

Is this relevant to the p2m_map_foreign stuff?

Quoted 14 lines
xen/arch/x86/mm/p2m-pt.c +1 -0
index 302b621..3f46418 100644
@@ -89,6 +89,7 @@ static unsigned long p2m_type_to_flags(p2m_type_t t, mfn_t mfn)
     case p2m_ram_rw:
         return flags | P2M_BASE_FLAGS | _PAGE_RW;
     case p2m_grant_map_rw:
+    case p2m_map_foreign:
         return flags | P2M_BASE_FLAGS | _PAGE_RW | _PAGE_NX_BIT;
     case p2m_mmio_direct:
         if ( !rangeset_contains_singleton(mmio_ro_ranges, mfn_x(mfn)) )

xen/arch/x86/mm/p2m-pt.c p2m_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn, · line 433

Quoted 5 lines
xen/arch/x86/mm/p2m-pt.c +1 -1
@@ -429,7 +430,7 @@ p2m_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     }
 
     /* Track the highest gfn for which we have ever had a valid mapping */
-    if ( p2mt != p2m_invalid
+    if ( p2mt != p2m_invalid && p2mt != p2m_mmio_dm

Likewise.

Quoted 26 lines
xen/arch/x86/mm/p2m-pt.c +0 -0
          && (gfn + (1UL << page_order) - 1 > p2m->max_mapped_pfn) )
         p2m->max_mapped_pfn = gfn + (1UL << page_order) - 1;
 
xen/arch/x86/mm/p2m.c +7 -1
index 4837de3..6888cf1 100644
@@ -523,7 +523,7 @@ p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn, unsigned long mfn,
         for ( i = 0; i < (1UL << page_order); i++ )
         {
             mfn_return = p2m->get_entry(p2m, gfn + i, &t, &a, 0, NULL);
-            if ( !p2m_is_grant(t) && !p2m_is_shared(t) )
+            if ( !p2m_is_grant(t) && !p2m_is_shared(t) && !p2m_is_foreign(t) )
                 set_gpfn_from_mfn(mfn+i, INVALID_M2P_ENTRY);
             ASSERT( !p2m_is_valid(t) || mfn + i == mfn_x(mfn_return) );
         }
@@ -754,7 +754,35 @@ void p2m_change_type_range(struct domain *d,
     p2m_unlock(p2m);
 }
 
+/* Returns: True for success. 0 for failure */
+int set_foreign_p2m_entry(struct domain *dp, unsigned long gfn, mfn_t mfn)
+{
+    int rc = 0;
+    p2m_type_t ot;
+    mfn_t omfn;

xen/arch/x86/mm/p2m.c void p2m_change_type_range(struct domain *d, · line 772

Quoted 10 lines
xen/arch/x86/mm/p2m.c +10 -0
+    struct p2m_domain *p2m = p2m_get_hostp2m(dp);
+
+    if ( !paging_mode_translate(dp) )
+        return 0;
+
+    omfn = get_gfn_query(dp, gfn, &ot);
+    if (mfn_valid(omfn)) {
+        gdprintk(XENLOG_ERR, "Already mapped mfn %lx at gfn:%lx\n", 
+                 mfn_x(omfn), gfn);
+        set_gpfn_from_mfn(mfn_x(omfn), INVALID_M2P_ENTRY);

That needs to be gated on 'ot' -- you should only be doing this for plain RAM owned by the caller.

xen/arch/x86/mm/p2m.c void p2m_change_type_range(struct domain *d, · line 774

Quoted 2 lines
xen/arch/x86/mm/p2m.c +2 -0
+    }
+    put_gfn(dp, gfn);

Also, this put_gfn is too early. Now there's a race where another CPU could populate that GFN again before your set_p2m_entry().

AFAICT once you've done that this function will look so similar to set_mmio_p2m_entry that they should be refactored to extract the common parts.

Quoted 12 lines
xen/arch/x86/mm/p2m.c +10 -0
+    P2M_DEBUG("set foreign %lx %lx\n", gfn, mfn_x(mfn));
+    p2m_lock(p2m);
+    rc = set_p2m_entry(p2m, gfn, mfn, 0, p2m_map_foreign, p2m->default_access);
+    p2m_unlock(p2m);
+    if ( rc == 0 )
+        gdprintk(XENLOG_ERR,
+            "set_foreign_p2m_entry: set_p2m_entry failed! gfn:%lx mfn=%08lx\n",
+            gfn, mfn_x(get_gfn_query(dp, gfn, &ot)));
+    return rc;
+}
 

xen/arch/x86/mm/p2m.c p2m_type_t p2m_change_type(struct domain *d, unsigned long gfn, · line 516

Quoted 5 lines
xen/arch/x86/mm/p2m.c +2 -0
@@ -510,6 +512,8 @@ p2m_type_t p2m_change_type(struct domain *d, unsigned long gfn,
 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 foreign mfn in the current guest's p2m table (for pvh dom0) */
+int set_foreign_p2m_entry(struct domain *domp, unsigned long gfn, mfn_t mfn);

I don't think it's specific to dom 0. Certainly it doesn't have any access controls in it.

Cheers,

Tim.