WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Create a block of reserved PFNs in shadow translate mode

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Create a block of reserved PFNs in shadow translate mode guests, and
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 30 Jan 2006 15:00:11 +0000
Delivery-date: Mon, 30 Jan 2006 15:23:41 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User sos22@xxxxxxxxxxxxxxxxxxxx
# Node ID c0a0f4db5ab14fc31db2003674b9fa775cbf951b
# Parent  edf1fab8661877d6241cd390bf0f4e1e790e01b4
Create a block of reserved PFNs in shadow translate mode guests, and
move the shared info and grant table pfns into that block.  This
allows us to remove the get_gnttablist dom0 op, and simplifies the
domain creation code slightly.  Having the reserved block managed by
Xen may also make it slightly easier to handle the case where the
grant table needs to be extended at run time.

Suggested-by: kaf24
Signed-off-by: Steven Smith, sos22@xxxxxxxxx

diff -r edf1fab86618 -r c0a0f4db5ab1 tools/libxc/xc_linux_build.c
--- a/tools/libxc/xc_linux_build.c      Thu Jan 26 17:02:21 2006
+++ b/tools/libxc/xc_linux_build.c      Thu Jan 26 18:40:13 2006
@@ -610,7 +610,7 @@
         goto error_out;
     }
 
-    if ( (page_array = malloc((nr_pages + 1 + NR_GRANT_FRAMES) * 
sizeof(unsigned long))) == NULL )
+    if ( (page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL )
     {
         PERROR("Could not allocate memory");
         goto error_out;
@@ -651,17 +651,7 @@
         xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
         page_array[physmap_pfn++]);
 
-    page_array[nr_pages] = shared_info_frame;
-
-    if ( xc_get_gnttab_frames(xc_handle,
-                              dom,
-                              page_array + 1 + nr_pages,
-                              NR_GRANT_FRAMES) <= 0) {
-        fprintf(stderr, "cannot get grant table frames\n");
-        goto error_out;
-    }
-
-    for ( count = 0; count < nr_pages + 1 + NR_GRANT_FRAMES; count++ )
+    for ( count = 0; count < nr_pages; count++ )
     {
         if ( xc_add_mmu_update(
             xc_handle, mmu,
@@ -696,6 +686,16 @@
             PERROR("Could not enable translation mode");
             goto error_out;
         }
+
+        /* Find the shared info frame.  It's guaranteed to be at the
+           start of the PFN hole. */
+        guest_shared_info_mfn = xc_get_pfn_hole_start(xc_handle, dom);
+        if (guest_shared_info_mfn <= 0) {
+            PERROR("Cannot find shared info pfn");
+            goto error_out;
+        }
+    } else {
+        guest_shared_info_mfn = shared_info_frame;
     }
 
     /* setup page tables */
@@ -756,11 +756,9 @@
     if (shadow_mode_enabled) {
         guest_store_mfn = (vstoreinfo_start-dsi.v_start) >> PAGE_SHIFT;
         guest_console_mfn = (vconsole_start-dsi.v_start) >> PAGE_SHIFT;
-        guest_shared_info_mfn = nr_pages;
     } else {
         guest_store_mfn = *store_mfn;
         guest_console_mfn = *console_mfn;
-        guest_shared_info_mfn = shared_info_frame;
     }
 
     start_info = xc_map_foreign_range(
diff -r edf1fab86618 -r c0a0f4db5ab1 tools/libxc/xc_misc.c
--- a/tools/libxc/xc_misc.c     Thu Jan 26 17:02:21 2006
+++ b/tools/libxc/xc_misc.c     Thu Jan 26 18:40:13 2006
@@ -131,6 +131,14 @@
     return rc;
 }
 
+int xc_get_pfn_hole_start(int xc_handle, domid_t dom)
+{
+    struct mmuext_op op = {0};
+    op.cmd = MMUEXT_PFN_HOLE_BASE;
+    return xc_mmuext_op(xc_handle, &op, 1, dom);
+}
+
+
 /*
  * Local variables:
  * mode: C
diff -r edf1fab86618 -r c0a0f4db5ab1 tools/libxc/xc_private.c
--- a/tools/libxc/xc_private.c  Thu Jan 26 17:02:21 2006
+++ b/tools/libxc/xc_private.c  Thu Jan 26 18:40:13 2006
@@ -314,35 +314,6 @@
     return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
 }
 
-int xc_get_gnttab_frames(int xc_handle,
-                         uint32_t domid,
-                         unsigned long *pfn_buf,
-                         unsigned long max_pfns)
-{
-    DECLARE_DOM0_OP;
-    int ret;
-    op.cmd = DOM0_GETGNTTABLIST;
-    op.u.getgnttablist.domain   = (domid_t)domid;
-    op.u.getgnttablist.max_pfns = max_pfns;
-    op.u.getgnttablist.buffer   = pfn_buf;
-
-#ifdef VALGRIND
-    memset(pfn_buf, 0, max_pfns * sizeof(unsigned long));
-#endif
-
-    if ( mlock(pfn_buf, max_pfns * sizeof(unsigned long)) != 0 )
-    {
-        PERROR("xc_get_pfn_list: pfn_buf mlock failed");
-        return -1;
-    }
-
-    ret = do_dom0_op(xc_handle, &op);
-
-    safe_munlock(pfn_buf, max_pfns * sizeof(unsigned long));
-
-    return (ret < 0) ? -1 : op.u.getgnttablist.num_pfns;
-}
-
 long xc_get_tot_pages(int xc_handle, uint32_t domid)
 {
     DECLARE_DOM0_OP;
diff -r edf1fab86618 -r c0a0f4db5ab1 tools/libxc/xc_private.h
--- a/tools/libxc/xc_private.h  Thu Jan 26 17:02:21 2006
+++ b/tools/libxc/xc_private.h  Thu Jan 26 18:40:13 2006
@@ -111,9 +111,6 @@
     return ret;
 }
 
-int xc_get_gnttab_frames(int xc_handle, uint32_t domid, unsigned long *pfn_buf,
-                        unsigned long max_pfns);
-
 
 /*
  * ioctl-based mfn mapping interface
diff -r edf1fab86618 -r c0a0f4db5ab1 tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h     Thu Jan 26 17:02:21 2006
+++ b/tools/libxc/xenctrl.h     Thu Jan 26 18:40:13 2006
@@ -528,4 +528,6 @@
                    unsigned long long ptr, unsigned long long val);
 int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu);
 
+int xc_get_pfn_hole_start(int xc_handle, domid_t dom);
+
 #endif
diff -r edf1fab86618 -r c0a0f4db5ab1 xen/arch/x86/dom0_ops.c
--- a/xen/arch/x86/dom0_ops.c   Thu Jan 26 17:02:21 2006
+++ b/xen/arch/x86/dom0_ops.c   Thu Jan 26 18:40:13 2006
@@ -330,38 +330,6 @@
     }
     break;
 
-    case DOM0_GETGNTTABLIST:
-    {
-        int i;
-        struct domain *d = find_domain_by_id(op->u.getgnttablist.domain);
-        unsigned long max_pfns = op->u.getgnttablist.max_pfns;
-        unsigned long pfn;
-        unsigned long *buffer = op->u.getgnttablist.buffer;
-
-        ret = -EINVAL;
-        if ( d != NULL )
-        {
-            ret = 0;
-
-            for ( i = 0; i < max_pfns && i < NR_GRANT_FRAMES; i++ )
-            {
-               pfn = gnttab_shared_mfn(d, d->grant_table, i);
-                if ( put_user(pfn, buffer) )
-                {
-                    ret = -EFAULT;
-                    break;
-                }
-                buffer++;
-            }
-
-            op->u.getgnttablist.num_pfns = i;
-            copy_to_user(u_dom0_op, op, sizeof(*op));
-
-            put_domain(d);
-        }
-    }
-    break;
-
     case DOM0_GETMEMLIST:
     {
         int i;
diff -r edf1fab86618 -r c0a0f4db5ab1 xen/arch/x86/mm.c
--- a/xen/arch/x86/mm.c Thu Jan 26 17:02:21 2006
+++ b/xen/arch/x86/mm.c Thu Jan 26 18:40:13 2006
@@ -1929,7 +1929,57 @@
             }
             break;
         }
-            
+
+        case MMUEXT_PFN_HOLE_BASE:
+        {
+            if (FOREIGNDOM->start_pfn_hole) {
+                rc = FOREIGNDOM->start_pfn_hole;
+                okay = 1;
+            } else {
+                rc = FOREIGNDOM->start_pfn_hole =
+                    FOREIGNDOM->max_pages;
+                okay = 1;
+                if (shadow_mode_translate(FOREIGNDOM)) {
+                    /* Fill in a few entries in the hole.  At the
+                       moment, this means the shared info page and the
+                       grant table pages. */
+                    struct domain_mmap_cache c1, c2;
+                    unsigned long pfn, mfn, x;
+                    domain_mmap_cache_init(&c1);
+                    domain_mmap_cache_init(&c2);
+                    shadow_lock(FOREIGNDOM);
+                    pfn = FOREIGNDOM->start_pfn_hole;
+                    mfn = virt_to_phys(FOREIGNDOM->shared_info) >> PAGE_SHIFT;
+                    set_p2m_entry(FOREIGNDOM, pfn, mfn, &c1, &c2);
+                    set_pfn_from_mfn(mfn, pfn);
+                    pfn++;
+                    for (x = 0; x < NR_GRANT_FRAMES; x++) {
+                        mfn = gnttab_shared_mfn(FOREIGNDOM,
+                                                FOREIGNDOM->grant_table,
+                                                x);
+                        set_p2m_entry(FOREIGNDOM, pfn, mfn, &c1, &c2);
+                        set_pfn_from_mfn(mfn, pfn);
+                        pfn++;
+                    }
+                    shadow_unlock(FOREIGNDOM);
+                    domain_mmap_cache_destroy(&c1);
+                    domain_mmap_cache_destroy(&c2);
+                }
+            }
+            break;
+        }
+
+        case MMUEXT_PFN_HOLE_SIZE:
+        {
+            if (shadow_mode_translate(FOREIGNDOM)) {
+                rc = PFN_HOLE_SIZE;
+            } else {
+                rc = 0;
+            }
+            okay = 1;
+            break;
+        }
+
         default:
             MEM_LOG("Invalid extended pt command 0x%x", op.cmd);
             okay = 0;
@@ -2663,7 +2713,7 @@
 
 long do_set_gdt(unsigned long *frame_list, unsigned int entries)
 {
-    int i, nr_pages = (entries + 511) / 512;
+    int nr_pages = (entries + 511) / 512;
     unsigned long frames[16];
     long ret;
 
diff -r edf1fab86618 -r c0a0f4db5ab1 xen/include/asm-x86/config.h
--- a/xen/include/asm-x86/config.h      Thu Jan 26 17:02:21 2006
+++ b/xen/include/asm-x86/config.h      Thu Jan 26 18:40:13 2006
@@ -59,6 +59,9 @@
 #define STACK_ORDER 2
 #endif
 #endif
+
+/* How large is the PFN reserved area, when we have one? */
+#define PFN_HOLE_SIZE 32
 
 #ifndef STACK_ORDER
 #define STACK_ORDER 1
diff -r edf1fab86618 -r c0a0f4db5ab1 xen/include/public/dom0_ops.h
--- a/xen/include/public/dom0_ops.h     Thu Jan 26 17:02:21 2006
+++ b/xen/include/public/dom0_ops.h     Thu Jan 26 18:40:13 2006
@@ -430,16 +430,6 @@
     domid_t  domain;          /* domain to be affected */
     unsigned long mfn;        /* machine frame to be initialised */
 } dom0_hypercall_init_t;
-
-#define DOM0_GETGNTTABLIST    49
-typedef struct {
-    /* IN variables. */
-    domid_t       domain;
-    unsigned long max_pfns;
-    void         *buffer;
-    /* OUT variables. */
-    unsigned long num_pfns;
-} dom0_getgnttablist_t;
 
 typedef struct {
     uint32_t cmd;
@@ -482,7 +472,6 @@
         dom0_irq_permission_t    irq_permission;
         dom0_iomem_permission_t  iomem_permission;
         dom0_hypercall_init_t    hypercall_init;
-        dom0_getgnttablist_t     getgnttablist;
         uint8_t                  pad[128];
     } u;
 } dom0_op_t;
diff -r edf1fab86618 -r c0a0f4db5ab1 xen/include/public/xen.h
--- a/xen/include/public/xen.h  Thu Jan 26 17:02:21 2006
+++ b/xen/include/public/xen.h  Thu Jan 26 18:40:13 2006
@@ -144,6 +144,15 @@
  * cmd: MMUEXT_SET_LDT
  * linear_addr: Linear address of LDT base (NB. must be page-aligned).
  * nr_ents: Number of entries in LDT.
+ *
+ * cmd: MMUEXT_PFN_HOLE_BASE
+ * No additional arguments.  Returns the first pfn in the Xen-reserved
+ * pfn hole.  Note that we delay allocating the hole until the first
+ * time this is called.
+ *
+ * cmd: MMUEXT_PFN_HOLE_SIZE
+ * No additional arguments.  Returns the number of pfns in the
+ * Xen-reserved pfn hole.
  */
 #define MMUEXT_PIN_L1_TABLE      0
 #define MMUEXT_PIN_L2_TABLE      1
@@ -160,6 +169,8 @@
 #define MMUEXT_FLUSH_CACHE      12
 #define MMUEXT_SET_LDT          13
 #define MMUEXT_NEW_USER_BASEPTR 15
+#define MMUEXT_PFN_HOLE_BASE    16
+#define MMUEXT_PFN_HOLE_SIZE    17
 
 #ifndef __ASSEMBLY__
 struct mmuext_op {
diff -r edf1fab86618 -r c0a0f4db5ab1 xen/include/xen/sched.h
--- a/xen/include/xen/sched.h   Thu Jan 26 17:02:21 2006
+++ b/xen/include/xen/sched.h   Thu Jan 26 18:40:13 2006
@@ -153,6 +153,9 @@
 
     /* Control-plane tools handle for this domain. */
     xen_domain_handle_t handle;
+
+    /* Start of the PFN hole */
+    unsigned long start_pfn_hole;
 };
 
 struct domain_setup_info

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Create a block of reserved PFNs in shadow translate mode guests, and, Xen patchbot -unstable <=