bitkeeper revision 1.879.1.5 (40912106hCc_Qr0pmIBFCRUoKbpCcQ)
authormwilli2@equilibrium.research.intel-research.net <mwilli2@equilibrium.research.intel-research.net>
Thu, 29 Apr 2004 15:36:38 +0000 (15:36 +0000)
committermwilli2@equilibrium.research.intel-research.net <mwilli2@equilibrium.research.intel-research.net>
Thu, 29 Apr 2004 15:36:38 +0000 (15:36 +0000)
Add support for building domains with IO privileges.

With a non-empty pci_device_list, xc_dom_create.py will automatically
cause the SIF_PRIVILEGED flag to be set in the domain's start info
structure.  This notifies it to do an IOPL, in turn allowing it to use
its PCI devices.

tools/examples/xc_dom_create.py
tools/xc/lib/xc.h
tools/xc/lib/xc_linux_build.c
tools/xc/lib/xc_netbsd_build.c
tools/xc/py/Xc.c

index 799319c6a6c02e7885b6d2a4faff826a532006a3..b898443ecfea04e3ad4ce5d41b44432438ff3dae 100755 (executable)
@@ -239,8 +239,12 @@ def make_domain():
        xc.domain_destroy ( dom=id )
        sys.exit()
 
+    # will the domain have IO privileges?
+    if pci_device_list != []: io_priv = True
+    else:                     io_priv = False
+
     if restore:
-        ret = eval('xc.%s_restore ( dom=id, state_file=state_file, progress=1 )' % builder_fn)
+        ret = eval('xc.%s_restore ( dom=id, state_file=state_file, progress=1, io_priv=%d )' % (builder_fn, io_priv))
         if ret < 0:
             print "Error restoring domain"
             print "Return code = " + str(ret)
@@ -248,7 +252,7 @@ def make_domain():
             sys.exit()
     else:
 
-        ret = eval('xc.%s_build ( dom=id, image=image, ramdisk=ramdisk, cmdline=cmdline, control_evtchn=xend_response["remote_port"] )' % builder_fn)
+        ret = eval('xc.%s_build ( dom=id, image=image, ramdisk=ramdisk, cmdline=cmdline, control_evtchn=xend_response["remote_port"], io_priv=%d )' % (builder_fn, io_priv) )
         if ret < 0:
             print "Error building Linux guest OS: "
             print "Return code = " + str(ret)
index 4afb905955994becb951caf0bd2e1a689ea47320..eb1b07da91f2485e96440154aa519c3e734a2079 100644 (file)
@@ -64,7 +64,7 @@ int xc_linux_save(int xc_handle,
                   int verbose);
 
 int xc_linux_restore(int xc_handle,
-                    u64 domid,
+                     u64 domid,
                      const char *state_file, 
                      int verbose,
                      u64 *pdomid);
@@ -74,13 +74,15 @@ int xc_linux_build(int xc_handle,
                    const char *image_name,
                    const char *ramdisk_name,
                    const char *cmdline,
-                   unsigned int control_evtchn);
+                   unsigned int control_evtchn,
+                   int io_priv);
 
 int xc_netbsd_build(int xc_handle,
                     u64 domid,
                     const char *image_name,
                     const char *cmdline,
-                    unsigned int control_evtchn);
+                    unsigned int control_evtchn,
+                    int io_priv);
 
 int xc_bvtsched_global_set(int xc_handle,
                            unsigned long ctx_allow);
@@ -248,15 +250,15 @@ int xc_shadow_control(int xc_handle,
 
 int xc_domain_setname(int xc_handle,
                       u64 domid, 
-                     char *name);
+                      char *name);
 
 int xc_domain_setinitialmem(int xc_handle,
-                           u64 domid, 
-                           unsigned int initial_memkb);
+                            u64 domid, 
+                            unsigned int initial_memkb);
 
 int xc_domain_setmaxmem(int xc_handle,
-                           u64 domid, 
-                           unsigned int max_memkb);
+                            u64 domid, 
+                            unsigned int max_memkb);
 
 
 #endif /* __XC_H__ */
index 7f81c924ad3b80de2db73c309f137b28fe293faf..27bc6c6668186258145fcd8eb3690da9aaa72b05 100644 (file)
@@ -73,7 +73,8 @@ static int setup_guestos(int xc_handle,
                          dom0_builddomain_t *builddomain, 
                          const char *cmdline,
                          unsigned long shared_info_frame,
-                         unsigned int control_evtchn)
+                         unsigned int control_evtchn,
+                         int io_priv)
 {
     l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
     l2_pgentry_t *vl2tab=NULL, *vl2e=NULL;
@@ -269,7 +270,7 @@ static int setup_guestos(int xc_handle,
     memset(start_info, 0, sizeof(*start_info));
     start_info->nr_pages     = nr_pages;
     start_info->shared_info  = shared_info_frame << PAGE_SHIFT;
-    start_info->flags        = 0;
+    start_info->flags        = io_priv ? SIF_PRIVILEGED : 0;
     start_info->pt_base      = vpt_start;
     start_info->nr_pt_frames = nr_pt_pages;
     start_info->mfn_list     = vphysmap_start;
@@ -382,7 +383,8 @@ int xc_linux_build(int xc_handle,
                    const char *image_name,
                    const char *ramdisk_name,
                    const char *cmdline,
-                   unsigned int control_evtchn)
+                   unsigned int control_evtchn,
+                   int io_priv)
 {
     dom0_op_t launch_op, op;
     int initrd_fd = -1;
@@ -440,7 +442,7 @@ int xc_linux_build(int xc_handle,
                        &vstartinfo_start, &vkern_entry,
                        &launch_op.u.builddomain, cmdline,
                        op.u.getdomaininfo.shared_info_frame,
-                       control_evtchn) < 0 )
+                       control_evtchn, io_priv) < 0 )
     {
         ERROR("Error constructing guest OS");
         goto error_out;
@@ -553,13 +555,13 @@ static int readelfimage_base_and_size(char *elfbase,
 
     if ( (ehdr->e_phoff + (ehdr->e_phnum * ehdr->e_phentsize)) > elfsize )
     {
-       ERROR("ELF program headers extend beyond end of image.");
+        ERROR("ELF program headers extend beyond end of image.");
         return -EINVAL;
     }
 
     if ( (ehdr->e_shoff + (ehdr->e_shnum * ehdr->e_shentsize)) > elfsize )
     {
-       ERROR("ELF section headers extend beyond end of image.");
+        ERROR("ELF section headers extend beyond end of image.");
         return -EINVAL;
     }
 
@@ -635,7 +637,7 @@ static int loadelfimage(char *elfbase, int pmh, unsigned long *parray,
     {
         phdr = (Elf_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize));
         if ( !is_loadable_phdr(phdr) )
-           continue;
+            continue;
         
         for ( done = 0; done < phdr->p_filesz; done += chunksz )
         {
index 8793a512f296905584fe342b08e7ac1fc0eb5d8d..cac444bd80c63c59092ef107ddc072a304f204ff 100644 (file)
@@ -62,7 +62,8 @@ static int setup_guestos(int xc_handle,
                          dom0_builddomain_t *builddomain, 
                          const char *cmdline,
                          unsigned long shared_info_frame,
-                         unsigned int control_evtchn)
+                         unsigned int control_evtchn,
+                         int io_priv)
 {
     l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
     l2_pgentry_t *vl2tab=NULL, *vl2e=NULL;
@@ -176,7 +177,7 @@ static int setup_guestos(int xc_handle,
     start_info->mod_len     = symtab_len;
     start_info->nr_pages    = tot_pages;
     start_info->shared_info = shared_info_frame << PAGE_SHIFT;
-    start_info->flags       = 0;
+    start_info->flags       = io_priv ? SIF_PRIVILEGED : 0;
     start_info->domain_controller_evtchn = control_evtchn;
     strncpy(start_info->cmd_line, cmdline, MAX_CMDLINE);
     start_info->cmd_line[MAX_CMDLINE-1] = '\0';
@@ -213,7 +214,8 @@ int xc_netbsd_build(int xc_handle,
                     u64 domid,
                     const char *image_name,
                     const char *cmdline,
-                    unsigned int control_evtchn)
+                    unsigned int control_evtchn,
+                    int io_priv)
 {
     dom0_op_t launch_op, op;
     unsigned long load_addr;
@@ -263,7 +265,7 @@ int xc_netbsd_build(int xc_handle,
                        &virt_startinfo_addr,
                        &load_addr, &launch_op.u.builddomain, cmdline,
                        op.u.getdomaininfo.shared_info_frame,
-                       control_evtchn) < 0 )
+                       control_evtchn, io_priv) < 0 )
     {
         ERROR("Error constructing guest OS");
         goto error_out;
index 92f77f70514fb921046123d1e80386e5208d3891..322a20b411b4a90343f811faede2f381609b605a 100644 (file)
@@ -228,18 +228,19 @@ static PyObject *pyxc_linux_build(PyObject *self,
 
     u64   dom;
     char *image, *ramdisk = NULL, *cmdline = "";
-    int   control_evtchn;
+    int   control_evtchn, io_priv = 0;
 
     static char *kwd_list[] = { "dom", "control_evtchn", 
-                                "image", "ramdisk", "cmdline", NULL };
+                                "image", "ramdisk", "cmdline", "io_priv",
+                               NULL };
 
-    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "Lis|ss", kwd_list, 
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "Lis|ssi", kwd_list, 
                                       &dom, &control_evtchn, 
-                                      &image, &ramdisk, &cmdline) )
+                                      &image, &ramdisk, &cmdline, &io_priv) )
         return NULL;
 
     if ( xc_linux_build(xc->xc_handle, dom, image, 
-                        ramdisk, cmdline, control_evtchn) != 0 )
+                        ramdisk, cmdline, control_evtchn, io_priv) != 0 )
         return PyErr_SetFromErrno(xc_error);
     
     Py_INCREF(zero);
@@ -254,18 +255,19 @@ static PyObject *pyxc_netbsd_build(PyObject *self,
 
     u64   dom;
     char *image, *ramdisk = NULL, *cmdline = "";
-    int   control_evtchn;
+    int   control_evtchn, io_priv = 0;
 
     static char *kwd_list[] = { "dom", "control_evtchn",
-                                "image", "ramdisk", "cmdline", NULL };
+                                "image", "ramdisk", "cmdline", "io_priv",
+                               NULL };
 
-    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "Lis|ss", kwd_list, 
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "Lis|ssi", kwd_list, 
                                       &dom, &control_evtchn,
-                                      &image, &ramdisk, &cmdline) )
+                                      &image, &ramdisk, &cmdline, &io_priv) )
         return NULL;
 
     if ( xc_netbsd_build(xc->xc_handle, dom, image, 
-                         cmdline, control_evtchn) != 0 )
+                         cmdline, control_evtchn, io_priv) != 0 )
         return PyErr_SetFromErrno(xc_error);
     
     Py_INCREF(zero);
@@ -1160,7 +1162,8 @@ static PyMethodDef pyxc_methods[] = {
       " dom     [long]:     Identifier of domain to build into.\n"
       " image   [str]:      Name of kernel image file. May be gzipped.\n"
       " ramdisk [str, n/a]: Name of ramdisk file, if any.\n"
-      " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
+      " cmdline [str, n/a]: Kernel parameters, if any.\n"
+      " io_priv [boolean]:  Does the domain have IO privileges?\n\n"
       "Returns: [int] 0 on success; -1 on error.\n" },
 
     { "netbsd_build", 
@@ -1169,7 +1172,8 @@ static PyMethodDef pyxc_methods[] = {
       "Build a new NetBSD guest OS.\n"
       " dom     [long]:     Identifier of domain to build into.\n"
       " image   [str]:      Name of kernel image file. May be gzipped.\n"
-      " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
+      " cmdline [str, n/a]: Kernel parameters, if any.\n"
+      " io_priv [boolean]:  Does the domain have IO privileges?\n\n"
       "Returns: [int] 0 on success; -1 on error.\n" },
 
     { "bvtsched_global_set",