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

[Xen-changelog] Replace memory_op subcommands reserved_phys_area and map_shared_info



# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID e408a374840c44a2f3d0e649cd1339aaf60ed5ea
# Parent  c5286130a96e684545f5ce3a75255eb6b97d3f8e
Replace memory_op subcommands reserved_phys_area and map_shared_info
with new subcommand add_to_physmap.

This changes the domain0 tools interface, but only when building
shadow-translate-mode guests.

Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>

diff -r c5286130a96e -r e408a374840c tools/libxc/xc_linux_build.c
--- a/tools/libxc/xc_linux_build.c      Fri Mar 10 13:27:24 2006
+++ b/tools/libxc/xc_linux_build.c      Fri Mar 10 15:00:36 2006
@@ -863,8 +863,7 @@
 
     if ( shadow_mode_enabled )
     {
-        struct xen_reserved_phys_area xrpa;
-        struct xen_map_shared_info xmsi;
+        struct xen_add_to_physmap xatp;
 
         /* Enable shadow translate mode */
         if ( xc_shadow_control(xc_handle, dom,
@@ -875,25 +874,35 @@
             goto error_out;
         }
 
-        /* Find the shared info frame.  It's guaranteed to be at the
-           start of the PFN hole. */
-        xrpa.domid = dom;
-        xrpa.idx   = 0;
-        rc = xc_memory_op(xc_handle, XENMEM_reserved_phys_area, &xrpa);
-        if ( rc != 0 )
-        {
-            PERROR("Cannot find shared info pfn");
-            goto error_out;
-        }
-
         guest_shared_info_mfn = (vsharedinfo_start-dsi.v_start) >> PAGE_SHIFT;
-        xmsi.domid = dom;
-        xmsi.pfn = guest_shared_info_mfn;
-        rc = xc_memory_op(xc_handle, XENMEM_map_shared_info, &xmsi);
+
+        /* Map shared info frame into guest physmap. */
+        xatp.domid = dom;
+        xatp.space = XENMAPSPACE_shared_info;
+        xatp.idx   = 0;
+        xatp.gpfn  = guest_shared_info_mfn;
+        rc = xc_memory_op(xc_handle, XENMEM_add_to_physmap, &xatp);
         if ( rc != 0 )
         {
             PERROR("Cannot map shared info pfn");
             goto error_out;
+        }
+
+        /* Map grant table frames into guest physmap. */
+        for ( i = 0; ; i++ )
+        {
+            xatp.domid = dom;
+            xatp.space = XENMAPSPACE_grant_table;
+            xatp.idx   = i;
+            xatp.gpfn  = nr_pages + i;
+            rc = xc_memory_op(xc_handle, XENMEM_add_to_physmap, &xatp);
+            if ( rc != 0 )
+            {
+                if ( errno == EINVAL )
+                    break; /* done all grant tables */
+                PERROR("Cannot map grant table pfn");
+                goto error_out;
+            }
         }
     }
     else
diff -r c5286130a96e -r e408a374840c tools/libxc/xc_private.c
--- a/tools/libxc/xc_private.c  Fri Mar 10 13:27:24 2006
+++ b/tools/libxc/xc_private.c  Fri Mar 10 15:00:36 2006
@@ -231,8 +231,8 @@
             goto out1;
         }
         break;
-    case XENMEM_reserved_phys_area:
-        if ( mlock(arg, sizeof(struct xen_reserved_phys_area)) )
+    case XENMEM_add_to_physmap:
+        if ( mlock(arg, sizeof(struct xen_add_to_physmap)) )
         {
             PERROR("Could not mlock");
             goto out1;
@@ -277,8 +277,8 @@
         safe_munlock(xmml->extent_start,
                      xmml->max_extents * sizeof(unsigned long));
         break;
-    case XENMEM_reserved_phys_area:
-        safe_munlock(arg, sizeof(struct xen_reserved_phys_area));
+    case XENMEM_add_to_physmap:
+        safe_munlock(arg, sizeof(struct xen_add_to_physmap));
         break;
     case XENMEM_translate_gpfn_list:
             safe_munlock(trans->mfn_list, trans->nr_gpfns * sizeof(long));
diff -r c5286130a96e -r e408a374840c xen/arch/x86/mm.c
--- a/xen/arch/x86/mm.c Fri Mar 10 13:27:24 2006
+++ b/xen/arch/x86/mm.c Fri Mar 10 15:00:36 2006
@@ -234,6 +234,8 @@
     if ( page_get_owner(page) == d )
         return;
 
+    set_gpfn_from_mfn(page_to_mfn(page), INVALID_M2P_ENTRY);
+
     spin_lock(&d->page_alloc_lock);
 
     /* The incremented type count pins as writable or read-only. */
@@ -2817,81 +2819,54 @@
 
 long arch_memory_op(int op, GUEST_HANDLE(void) arg)
 {
-    unsigned long pfn;
-    struct domain *d;
-    unsigned int i;
-
     switch ( op )
     {
-    case XENMEM_reserved_phys_area: {
-        struct xen_reserved_phys_area xrpa;
-
-        if ( copy_from_guest(&xrpa, arg, 1) )
+    case XENMEM_add_to_physmap:
+    {
+        struct xen_add_to_physmap xatp;
+        unsigned long mfn = 0, gpfn;
+        struct domain *d;
+
+        if ( copy_from_guest(&xatp, arg, 1) )
             return -EFAULT;
 
-        /* No guest has more than one reserved area. */
-        if ( xrpa.idx != 0 )
+        if ( (d = find_domain_by_id(xatp.domid)) == NULL )
             return -ESRCH;
 
-        if ( (d = find_domain_by_id(xrpa.domid)) == NULL )
-            return -ESRCH;
-
-        /* Only initialised translated guests have a reserved area. */
-        if ( !shadow_mode_translate(d) || (d->max_pages == 0) )
-        {
-            put_domain(d);
-            return -ESRCH;
-        }
-
-        LOCK_BIGLOCK(d);
-        if ( d->arch.first_reserved_pfn == 0 )
-        {
-            d->arch.first_reserved_pfn = pfn = d->max_pages;
-            for ( i = 0; i < NR_GRANT_FRAMES; i++ )
-                guest_physmap_add_page(
-                    d, pfn + i, gnttab_shared_mfn(d, d->grant_table, i));
-        }
-        UNLOCK_BIGLOCK(d);
-
-        xrpa.first_gpfn = d->arch.first_reserved_pfn;
-        xrpa.nr_gpfns   = NR_GRANT_FRAMES;
-
-        put_domain(d);
-
-        if ( copy_to_guest(arg, &xrpa, 1) )
-            return -EFAULT;
-
-        break;
-    }
-
-    case XENMEM_map_shared_info: {
-        struct xen_map_shared_info xmsi;
-
-        if ( copy_from_guest(&xmsi, arg, 1) )
-            return -EFAULT;
-
-        if ( (d = find_domain_by_id(xmsi.domid)) == NULL )
-            return -ESRCH;
-
-        /* Only initialised translated guests can set the shared_info
-         * mapping. */
-        if ( !shadow_mode_translate(d) || (d->max_pages == 0) )
-        {
-            put_domain(d);
-            return -ESRCH;
-        }
-
-        if ( xmsi.pfn > d->max_pages ) {
+        switch ( xatp.space )
+        {
+        case XENMAPSPACE_shared_info:
+            if ( xatp.idx == 0 )
+                mfn = virt_to_mfn(d->shared_info);
+            break;
+        case XENMAPSPACE_grant_table:
+            if ( xatp.idx < NR_GRANT_FRAMES )
+                mfn = virt_to_mfn(d->grant_table->shared) + xatp.idx;
+            break;
+        default:
+            break;
+        }
+        
+        if ( !shadow_mode_translate(d) || (mfn == 0) )
+        {
             put_domain(d);
             return -EINVAL;
         }
 
         LOCK_BIGLOCK(d);
+
         /* Remove previously mapped page if it was present. */
-        if ( mfn_valid(gmfn_to_mfn(d, xmsi.pfn)) )
-            guest_remove_page(d, xmsi.pfn);
-        guest_physmap_add_page(d, xmsi.pfn,
-                               virt_to_maddr(d->shared_info) >> PAGE_SHIFT);
+        if ( mfn_valid(gmfn_to_mfn(d, xatp.gpfn)) )
+            guest_remove_page(d, xatp.gpfn);
+
+        /* Unmap from old location, if any. */
+        gpfn = get_gpfn_from_mfn(mfn);
+        if ( gpfn != INVALID_M2P_ENTRY )
+            guest_physmap_remove_page(d, gpfn, mfn);
+
+        /* Map at new location. */
+        guest_physmap_add_page(d, xatp.gpfn, mfn);
+
         UNLOCK_BIGLOCK(d);
 
         put_domain(d);
diff -r c5286130a96e -r e408a374840c xen/include/asm-x86/grant_table.h
--- a/xen/include/asm-x86/grant_table.h Fri Mar 10 13:27:24 2006
+++ b/xen/include/asm-x86/grant_table.h Fri Mar 10 15:00:36 2006
@@ -26,9 +26,6 @@
         share_xen_page_with_guest(                                       \
             virt_to_page((char *)(t)->shared + ((i) * PAGE_SIZE)),       \
             (d), XENSHARE_writable);                                     \
-        set_gpfn_from_mfn(                                               \
-            (virt_to_maddr((t)->shared) >> PAGE_SHIFT) + (i),            \
-            INVALID_M2P_ENTRY);                                          \
     } while ( 0 )
 
 #define gnttab_shared_mfn(d, t, i)                      \
diff -r c5286130a96e -r e408a374840c xen/include/asm-x86/page.h
--- a/xen/include/asm-x86/page.h        Fri Mar 10 13:27:24 2006
+++ b/xen/include/asm-x86/page.h        Fri Mar 10 15:00:36 2006
@@ -190,6 +190,10 @@
 /* Shorthand versions of the above functions. */
 #define __pa(x)             (virt_to_maddr(x))
 #define __va(x)             (maddr_to_virt(x))
+
+/* Convert between Xen-heap virtual addresses and machine frame numbers. */
+#define virt_to_mfn(va)     (virt_to_maddr(va) >> PAGE_SHIFT)
+#define mfn_to_virt(mfn)    (maddr_to_virt(mfn << PAGE_SHIFT))
 
 /* Convert between machine frame numbers and page-info structures. */
 #define mfn_to_page(mfn)    (frame_table + (mfn))
diff -r c5286130a96e -r e408a374840c xen/include/public/memory.h
--- a/xen/include/public/memory.h       Fri Mar 10 13:27:24 2006
+++ b/xen/include/public/memory.h       Fri Mar 10 15:00:36 2006
@@ -97,25 +97,27 @@
 DEFINE_GUEST_HANDLE(xen_machphys_mfn_list_t);
 
 /*
- * Returns the base and size of the specified reserved 'RAM hole' in the
- * specified guest's pseudophysical address space.
- * arg == addr of xen_reserved_phys_area_t.
+ * Sets the GPFN at which a particular page appears in the specified guest's
+ * pseudophysical address space.
+ * arg == addr of xen_add_to_physmap_t.
  */
-#define XENMEM_reserved_phys_area   7
-typedef struct xen_reserved_phys_area {
-    /* Which domain to report about? */
+#define XENMEM_add_to_physmap      7
+typedef struct xen_add_to_physmap {
+    /* Which domain to change the mapping for. */
     domid_t domid;
 
-    /*
-     * Which reserved area to report? Out-of-range request reports
-     * -ESRCH. Currently no architecture will have more than one reserved area.
-     */
-    unsigned int idx;
+    /* Source mapping space. */
+#define XENMAPSPACE_shared_info 0 /* shared info page */
+#define XENMAPSPACE_grant_table 1 /* grant table page */
+    unsigned int space;
 
-    /* Base and size of the specified reserved area. */
-    unsigned long first_gpfn, nr_gpfns;
-} xen_reserved_phys_area_t;
-DEFINE_GUEST_HANDLE(xen_reserved_phys_area_t);
+    /* Index into source mapping space. */
+    unsigned long idx;
+
+    /* GPFN where the source mapping page should appear. */
+    unsigned long gpfn;
+} xen_add_to_physmap_t;
+DEFINE_GUEST_HANDLE(xen_add_to_physmap_t);
 
 /*
  * Translates a list of domain-specific GPFNs into MFNs. Returns a -ve error
@@ -140,21 +142,6 @@
 } xen_translate_gpfn_list_t;
 DEFINE_GUEST_HANDLE(xen_translate_gpfn_list_t);
 
-/*
- * Sets the GPFN at which the shared_info_page appears in the specified
- * guest's pseudophysical address space.
- * arg == addr of xen_map_shared_info_t.
- */
-#define XENMEM_map_shared_info      9
-typedef struct xen_map_shared_info {
-    /* Which domain to change the mapping for. */
-    domid_t domid;
-
-    /* GPFN where the shared_info_page should appear. */
-    unsigned long pfn;
-} xen_map_shared_info_t;
-DEFINE_GUEST_HANDLE(xen_map_shared_info_t);
-
 #endif /* __XEN_PUBLIC_MEMORY_H__ */
 
 /*

_______________________________________________
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®.