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

[Xen-changelog] [xen-unstable] xen: reinstate previously unused XENMEM_remove_from_physmap hypercall



# HG changeset patch
# User Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
# Date 1327758444 0
# Node ID 34c96082d69389e5891bbc1c424d0199355632df
# Parent  3bd3949854efa13ef1a9874711b558169408f61d
xen: reinstate previously unused XENMEM_remove_from_physmap hypercall

This patch reinstates the XENMEM_remove_from_physmap hypercall
which was removed in 19041:ee62aaafff46 because it was not used.

However, is now needed in order to support xenstored stub domains.
The xenstored stub domain is not priviliged like dom0 and so cannot
unilaterally map the xenbus page of other guests into it's address
space.  Therefore, before creating a domU the domain builder needs to
seed its grant table with a grant ref allowing the xenstored stub
domain to access the new domU's xenbus page.

At present domU's do not start with their grant table mapped.
Instead it gets mapped when the guest requests a grant table from
the hypervisor.

In order to seed the grant table, the domain builder first needs to
map it into dom0 address space.  But the hypercall to do this
requires a gpfn (guest pfn), which is an mfn for PV guest, but a pfn
for HVM guests.  Therfore, in order to seed the grant table of an
HVM guest, dom0 needs to *temporarily* map it into the guest's
"physical" address space.

Hence the need to reinstate the XENMEM_remove_from_physmap hypercall.

Signed-off-by: Alex Zeffertt <alex.zeffertt@xxxxxxxxxxxxx>
Signed-off-by: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Committed-by: Keir Fraser <keir@xxxxxxx>
---


diff -r 3bd3949854ef -r 34c96082d693 xen/common/compat/memory.c
--- a/xen/common/compat/memory.c        Sat Jan 28 13:45:13 2012 +0000
+++ b/xen/common/compat/memory.c        Sat Jan 28 13:47:24 2012 +0000
@@ -25,6 +25,7 @@
             XEN_GUEST_HANDLE(void) hnd;
             struct xen_memory_reservation *rsrv;
             struct xen_memory_exchange *xchg;
+            struct xen_remove_from_physmap *xrfp;
         } nat;
         union {
             struct compat_memory_reservation rsrv;
@@ -179,6 +180,18 @@
             nat.hnd = compat;
             break;
 
+        case XENMEM_remove_from_physmap:
+        {
+            struct compat_remove_from_physmap cmp;
+
+            if ( copy_from_guest(&cmp, compat, 1) )
+                return -EFAULT;
+
+            XLAT_remove_from_physmap(nat.xrfp, &cmp);
+
+            break;
+        }
+
         default:
             return compat_arch_memory_op(cmd, compat);
         }
@@ -284,6 +297,7 @@
         case XENMEM_current_reservation:
         case XENMEM_maximum_reservation:
         case XENMEM_maximum_gpfn:
+        case XENMEM_remove_from_physmap:
             break;
 
         default:
diff -r 3bd3949854ef -r 34c96082d693 xen/common/memory.c
--- a/xen/common/memory.c       Sat Jan 28 13:45:13 2012 +0000
+++ b/xen/common/memory.c       Sat Jan 28 13:47:24 2012 +0000
@@ -659,6 +659,43 @@
 
         break;
 
+    case XENMEM_remove_from_physmap:
+    {
+        struct xen_remove_from_physmap xrfp;
+        unsigned long mfn;
+        struct domain *d;
+
+        if ( copy_from_guest(&xrfp, arg, 1) )
+            return -EFAULT;
+
+        rc = rcu_lock_target_domain_by_id(xrfp.domid, &d);
+        if ( rc != 0 )
+            return rc;
+
+        if ( xsm_remove_from_physmap(current->domain, d) )
+        {
+            rcu_unlock_domain(d);
+            return -EPERM;
+        }
+
+        domain_lock(d);
+
+        mfn = get_gfn_untyped(d, xrfp.gpfn);
+
+        if ( mfn_valid(mfn) )
+            guest_physmap_remove_page(d, xrfp.gpfn, mfn, PAGE_ORDER_4K);
+        else
+            rc = -ENOENT;
+
+        put_gfn(d, xrfp.gpfn);
+
+        domain_unlock(d);
+
+        rcu_unlock_domain(d);
+
+        break;
+    }
+
     default:
         rc = arch_memory_op(op, arg);
         break;
diff -r 3bd3949854ef -r 34c96082d693 xen/include/asm-ia64/mm.h
--- a/xen/include/asm-ia64/mm.h Sat Jan 28 13:45:13 2012 +0000
+++ b/xen/include/asm-ia64/mm.h Sat Jan 28 13:47:24 2012 +0000
@@ -550,6 +550,7 @@
 #define gmfn_to_mfn(_d, gpfn)                  \
     gmfn_to_mfn_foreign((_d), (gpfn))
 
+#define get_gfn_untyped(d, gpfn) gmfn_to_mfn(d, gpfn)
 #define put_gfn(d, g)   ((void)0)
 
 #define __gpfn_invalid(_d, gpfn)                       \
diff -r 3bd3949854ef -r 34c96082d693 xen/include/public/memory.h
--- a/xen/include/public/memory.h       Sat Jan 28 13:45:13 2012 +0000
+++ b/xen/include/public/memory.h       Sat Jan 28 13:47:24 2012 +0000
@@ -229,6 +229,22 @@
 typedef struct xen_add_to_physmap xen_add_to_physmap_t;
 DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
 
+/*
+ * Unmaps the page appearing at a particular GPFN from the specified guest's
+ * pseudophysical address space.
+ * arg == addr of xen_remove_from_physmap_t.
+ */
+#define XENMEM_remove_from_physmap      15
+struct xen_remove_from_physmap {
+    /* Which domain to change the mapping for. */
+    domid_t domid;
+
+    /* GPFN of the current mapping of the page. */
+    xen_pfn_t     gpfn;
+};
+typedef struct xen_remove_from_physmap xen_remove_from_physmap_t;
+DEFINE_XEN_GUEST_HANDLE(xen_remove_from_physmap_t);
+
 /*** REMOVED ***/
 /*#define XENMEM_translate_gpfn_list  8*/
 
diff -r 3bd3949854ef -r 34c96082d693 xen/include/xlat.lst
--- a/xen/include/xlat.lst      Sat Jan 28 13:45:13 2012 +0000
+++ b/xen/include/xlat.lst      Sat Jan 28 13:47:24 2012 +0000
@@ -60,6 +60,7 @@
 !      memory_map                      memory.h
 !      memory_reservation              memory.h
 !      pod_target                      memory.h
+!      remove_from_physmap             memory.h
 ?      physdev_eoi                     physdev.h
 ?      physdev_get_free_pirq           physdev.h
 ?      physdev_irq                     physdev.h
diff -r 3bd3949854ef -r 34c96082d693 xen/include/xsm/xsm.h
--- a/xen/include/xsm/xsm.h     Sat Jan 28 13:45:13 2012 +0000
+++ b/xen/include/xsm/xsm.h     Sat Jan 28 13:47:24 2012 +0000
@@ -169,6 +169,7 @@
     int (*update_va_mapping) (struct domain *d, struct domain *f, 
                                                             l1_pgentry_t pte);
     int (*add_to_physmap) (struct domain *d1, struct domain *d2);
+    int (*remove_from_physmap) (struct domain *d1, struct domain *d2);
     int (*sendtrigger) (struct domain *d);
     int (*bind_pt_irq) (struct domain *d, struct xen_domctl_bind_pt_irq *bind);
     int (*unbind_pt_irq) (struct domain *d);
@@ -738,6 +739,11 @@
     return xsm_call(add_to_physmap(d1, d2));
 }
 
+static inline int xsm_remove_from_physmap(struct domain *d1, struct domain *d2)
+{
+    return xsm_call(remove_from_physmap(d1, d2));
+}
+
 static inline int xsm_sendtrigger(struct domain *d)
 {
     return xsm_call(sendtrigger(d));
diff -r 3bd3949854ef -r 34c96082d693 xen/xsm/dummy.c
--- a/xen/xsm/dummy.c   Sat Jan 28 13:45:13 2012 +0000
+++ b/xen/xsm/dummy.c   Sat Jan 28 13:47:24 2012 +0000
@@ -529,6 +529,11 @@
     return 0;
 }
 
+static int dummy_remove_from_physmap (struct domain *d1, struct domain *d2)
+{
+    return 0;
+}
+
 static int dummy_sendtrigger (struct domain *d)
 {
     return 0;
@@ -690,6 +695,7 @@
     set_to_dummy_if_null(ops, mmu_machphys_update);
     set_to_dummy_if_null(ops, update_va_mapping);
     set_to_dummy_if_null(ops, add_to_physmap);
+    set_to_dummy_if_null(ops, remove_from_physmap);
     set_to_dummy_if_null(ops, sendtrigger);
     set_to_dummy_if_null(ops, bind_pt_irq);
     set_to_dummy_if_null(ops, pin_mem_cacheattr);
diff -r 3bd3949854ef -r 34c96082d693 xen/xsm/flask/hooks.c
--- a/xen/xsm/flask/hooks.c     Sat Jan 28 13:45:13 2012 +0000
+++ b/xen/xsm/flask/hooks.c     Sat Jan 28 13:47:24 2012 +0000
@@ -1283,6 +1283,11 @@
     return domain_has_perm(d1, d2, SECCLASS_MMU, MMU__PHYSMAP);
 }
 
+static int flask_remove_from_physmap(struct domain *d1, struct domain *d2)
+{
+    return domain_has_perm(d1, d2, SECCLASS_MMU, MMU__PHYSMAP);
+}
+
 static int flask_sendtrigger(struct domain *d)
 {
     return domain_has_perm(current->domain, d, SECCLASS_DOMAIN, 
DOMAIN__TRIGGER);
@@ -1550,6 +1555,7 @@
     .mmu_machphys_update = flask_mmu_machphys_update,
     .update_va_mapping = flask_update_va_mapping,
     .add_to_physmap = flask_add_to_physmap,
+    .remove_from_physmap = flask_remove_from_physmap,
     .sendtrigger = flask_sendtrigger,
     .get_device_group = flask_get_device_group,
     .test_assign_device = flask_test_assign_device,

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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