All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: Xen Mailing List <xen-devel@lists.xensource.com>
Subject: [PATCH 5/9] Vdevice share in start_info
Date: Tue, 06 Jun 2006 15:52:58 +1000	[thread overview]
Message-ID: <1149573178.5183.38.camel@localhost.localdomain> (raw)
In-Reply-To: <1149572143.5183.25.camel@localhost.localdomain>

This patch adds a single entry on the end of the start_info, to
provide a simplified bus called "vdevice".  This is completely
backwards compatible: old kernels will ignore it, old tools set it to
zero.

The vdevice bus is a simple array of structures: now that a share
reference is sufficient to describe devices, and devices no longer map
other domains' pages, this is all we need.  The page is initially
populated with devices (although currently it's always empty when a
domain starts).

Devices are added by setting a zero entry, and triggering watch number
1.  They are acknowledged by setting bits in the appropriate entry and
triggering watch 0.  Devices are removed the same way.

This majority of this patch is plumbing it into the tools.

diff -r cddc595b285b xen/include/public/xen.h
--- a/xen/include/public/xen.h	Thu Jun  1 23:26:37 2006
+++ b/xen/include/public/xen.h	Fri Jun  2 09:27:39 2006
@@ -455,6 +455,7 @@
     unsigned long mod_start;    /* VIRTUAL address of pre-loaded module.  */
     unsigned long mod_len;      /* Size (bytes) of pre-loaded module.     */
     int8_t cmd_line[MAX_GUEST_CMDLINE];
+    unsigned long vdevice_share; /* share_ref of vdevice config page. */
 };
 typedef struct start_info start_info_t;
 
diff -r cddc595b285b tools/libxc/xc_linux_build.c
--- a/tools/libxc/xc_linux_build.c	Thu Jun  1 23:26:37 2006
+++ b/tools/libxc/xc_linux_build.c	Fri Jun  2 09:27:39 2006
@@ -457,7 +457,8 @@
                        unsigned long flags,
                        unsigned int store_evtchn, unsigned long *store_mfn,
                        unsigned int console_evtchn, unsigned long *console_mfn,
-                       uint32_t required_features[XENFEAT_NR_SUBMAPS])
+                       uint32_t required_features[XENFEAT_NR_SUBMAPS],
+                       unsigned long vdevice_share)
 {
     unsigned long *page_array = NULL;
     struct load_funcs load_funcs;
@@ -549,6 +550,7 @@
     start_info->store_evtchn = store_evtchn;
     start_info->console_mfn   = nr_pages - 1;
     start_info->console_evtchn = console_evtchn;
+    start_info->vdevice_share  = vdevice_share;
     start_info->nr_pages       = nr_pages; // FIXME?: nr_pages - 2 ????
     if ( initrd->len != 0 )
     {
@@ -612,7 +614,8 @@
                        unsigned long flags,
                        unsigned int store_evtchn, unsigned long *store_mfn,
                        unsigned int console_evtchn, unsigned long *console_mfn,
-                       uint32_t required_features[XENFEAT_NR_SUBMAPS])
+                       uint32_t required_features[XENFEAT_NR_SUBMAPS],
+                       unsigned long vdevice_share)
 {
     unsigned long *page_array = NULL;
     unsigned long count, i, hypercall_pfn;
@@ -977,6 +980,7 @@
     start_info->store_evtchn = store_evtchn;
     start_info->console_mfn   = guest_console_mfn;
     start_info->console_evtchn = console_evtchn;
+    start_info->vdevice_share  = vdevice_share;
     if ( initrd->len != 0 )
     {
         start_info->mod_start    = vinitrd_start;
@@ -1044,7 +1048,8 @@
                                    unsigned int store_evtchn,
                                    unsigned long *store_mfn,
                                    unsigned int console_evtchn,
-                                   unsigned long *console_mfn)
+                                   unsigned long *console_mfn,
+                                   unsigned long vdevice_share)
 {
     dom0_op_t launch_op;
     DECLARE_DOM0_OP;
@@ -1097,8 +1102,8 @@
                      &vstack_start, ctxt, cmdline,
                      op.u.getdomaininfo.shared_info_frame,
                      flags, store_evtchn, store_mfn,
-                     console_evtchn, console_mfn,
-                     features_bitmap) < 0 )
+                     console_evtchn, console_mfn, features_bitmap,
+                     vdevice_share) < 0 )
     {
         ERROR("Error constructing guest OS");
         goto error_out;
@@ -1204,7 +1209,8 @@
                        unsigned int store_evtchn,
                        unsigned long *store_mfn,
                        unsigned int console_evtchn,
-                       unsigned long *console_mfn)
+                       unsigned long *console_mfn,
+                       unsigned long vdevice_share)
 {
     int            sts;
     char          *img_buf;
@@ -1245,7 +1251,7 @@
     sts = xc_linux_build_internal(xc_handle, domid, img_buf, img_len,
                                   &initrd_info, cmdline, features, flags,
                                   store_evtchn, store_mfn,
-                                  console_evtchn, console_mfn);
+                                  console_evtchn, console_mfn, vdevice_share);
 
  out:
     /* The inflation routines may pass back the same buffer so be */
@@ -1270,7 +1276,8 @@
                    unsigned int store_evtchn,
                    unsigned long *store_mfn,
                    unsigned int console_evtchn,
-                   unsigned long *console_mfn)
+                   unsigned long *console_mfn,
+                   unsigned long vdevice_share)
 {
     char *image = NULL;
     unsigned long image_size;
@@ -1302,7 +1309,7 @@
     sts = xc_linux_build_internal(xc_handle, domid, image, image_size,
                                   &initrd_info, cmdline, features, flags,
                                   store_evtchn, store_mfn,
-                                  console_evtchn, console_mfn);
+                                  console_evtchn, console_mfn, vdevice_share);
 
  error_out:
     free(image);
diff -r cddc595b285b tools/libxc/xc_linux_restore.c
--- a/tools/libxc/xc_linux_restore.c	Thu Jun  1 23:26:37 2006
+++ b/tools/libxc/xc_linux_restore.c	Fri Jun  2 09:27:39 2006
@@ -105,7 +105,8 @@
 int xc_linux_restore(int xc_handle, int io_fd,
                      uint32_t dom, unsigned long nr_pfns,
                      unsigned int store_evtchn, unsigned long *store_mfn,
-                     unsigned int console_evtchn, unsigned long *console_mfn)
+                     unsigned int console_evtchn, unsigned long *console_mfn,
+                     unsigned long vdevice_share)
 {
     DECLARE_DOM0_OP;
     int rc = 1, i, n;
@@ -518,6 +519,7 @@
     start_info->store_evtchn                 = store_evtchn;
     *console_mfn = start_info->console_mfn   = p2m[start_info->console_mfn];
     start_info->console_evtchn               = console_evtchn;
+    start_info->vdevice_share                  = vdevice_share;
     munmap(start_info, PAGE_SIZE);
 
     /* Uncanonicalise each GDT frame number. */
diff -r cddc595b285b tools/libxc/xenguest.h
--- a/tools/libxc/xenguest.h	Thu Jun  1 23:26:37 2006
+++ b/tools/libxc/xenguest.h	Fri Jun  2 09:27:39 2006
@@ -40,7 +40,7 @@
 int xc_linux_restore(int xc_handle, int io_fd, uint32_t dom,
                      unsigned long nr_pfns, unsigned int store_evtchn,
                      unsigned long *store_mfn, unsigned int console_evtchn,
-                     unsigned long *console_mfn);
+                     unsigned long *console_mfn, unsigned long vdevice_share);
 
 /**
  * This function will create a domain for a paravirtualized Linux
@@ -68,7 +68,8 @@
                    unsigned int store_evtchn,
                    unsigned long *store_mfn,
                    unsigned int console_evtchn,
-                   unsigned long *console_mfn);
+                   unsigned long *console_mfn,
+		   unsigned long vdevice_share);
 
 /**
  * This function will create a domain for a paravirtualized Linux
@@ -100,7 +101,8 @@
                        unsigned int store_evtchn,
                        unsigned long *store_mfn,
                        unsigned int console_evtchn,
-                       unsigned long *console_mfn);
+                       unsigned long *console_mfn,
+                       unsigned long vdevice_share);
 
 int xc_hvm_build(int xc_handle,
                  uint32_t domid,
diff -r cddc595b285b tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c	Thu Jun  1 23:26:37 2006
+++ b/tools/python/xen/lowlevel/xc/xc.c	Fri Jun  2 09:27:39 2006
@@ -331,25 +331,26 @@
     int store_evtchn, console_evtchn;
     unsigned long store_mfn = 0;
     unsigned long console_mfn = 0;
+    unsigned long vdevice_share = 0;
 
     static char *kwd_list[] = { "dom", "store_evtchn",
                                 "console_evtchn", "image",
 				/* optional */
 				"ramdisk", "cmdline", "flags",
-				"features", NULL };
-
-    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiis|ssis", kwd_list,
+				"features", "vdevice_share", NULL };
+
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiis|ssisi", kwd_list,
                                       &dom, &store_evtchn,
 				      &console_evtchn, &image,
 				      /* optional */
 				      &ramdisk, &cmdline, &flags,
-				      &features) )
+				      &features, &vdevice_share) )
         return NULL;
 
     if ( xc_linux_build(self->xc_handle, dom, image,
                         ramdisk, cmdline, features, flags,
                         store_evtchn, &store_mfn,
-			console_evtchn, &console_mfn) != 0 ) {
+			console_evtchn, &console_mfn, vdevice_share) != 0 ) {
         if (!errno)
              errno = EINVAL;
         return PyErr_SetFromErrno(xc_error);
@@ -671,6 +672,38 @@
                          "cc_compile_date", xen_cc.compile_date);
 }
 
+static PyObject *pyxc_create_shared_pages(XcObject *self,
+					  PyObject *args,
+					  PyObject *kwds)
+{
+    unsigned long mfn;
+    int num;
+    static char *kwd_list[] = { "num", NULL };
+    
+    if( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &num) )
+        return NULL;
+
+    mfn = xc_create_shared_pages(self->xc_handle, num);
+    return Py_BuildValue("l", mfn);
+}
+
+static PyObject *pyxc_grant_shared_pages(XcObject *self,
+					 PyObject *args,
+					 PyObject *kwds)
+{
+    unsigned long mfn;
+    int dom;
+    static char *kwd_list[] = { "dom", "mfn", NULL };
+    
+    if( !PyArg_ParseTupleAndKeywords(args, kwds, "il", kwd_list, &dom, &mfn) )
+        return NULL;
+
+    if (xc_grant_shared_pages(self->xc_handle, dom, mfn) != 0)
+        return PyErr_SetFromErrno(xc_error);
+
+    Py_INCREF(zero);
+    return zero;
+}
 
 static PyObject *pyxc_sedf_domain_set(XcObject *self,
                                       PyObject *args,
@@ -1109,6 +1142,21 @@
       " dom        [int]: Domain whose port space to allocate from.\n"
       " remote_dom [int]: Remote domain to accept connections from.\n\n"
       "Returns: [int] Unbound event-channel port.\n" },
+
+    { "create_shared_pages", 
+      (PyCFunction)pyxc_create_shared_pages,
+      METH_KEYWORDS, "\n"
+      "Allocate one or more shared pages.\n"
+      " num_pages   [int]: Number of pages t.\n"
+      "Returns: [int] mfn of (first) shared page\n" },
+
+    { "grant_shared_pages", 
+      (PyCFunction)pyxc_grant_shared_pages,
+      METH_VARARGS | METH_KEYWORDS, "\n"
+      "Grant a domain access to shared pages.\n"
+      " dom   [int]: Domain.\n"
+      " mfn   [int]: Shared page mfn.\n"
+      "Returns: 0 on success\n" },
 
     { "evtchn_status", 
       (PyCFunction)pyxc_evtchn_status, 
diff -r cddc595b285b tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py	Thu Jun  1 23:26:37 2006
+++ b/tools/python/xen/xend/XendDomainInfo.py	Fri Jun  2 09:27:39 2006
@@ -452,6 +452,7 @@
         self.store_mfn = None
         self.console_port = None
         self.console_mfn = None
+        self.vdevice_share = None
 
         self.vmWatch = None
         self.shutdownWatch = None
@@ -730,6 +731,7 @@
         f('console/ring-ref', self.console_mfn)
         f('store/port',       self.store_port)
         f('store/ring-ref',   self.store_mfn)
+        f('vdevice-share',    self.vdevice_share)
 
         to_store.update(self.vcpuDomDetails())
 
@@ -785,6 +787,8 @@
         """For use only by image.py and XendCheckpoint.py."""
         return self.store_port
 
+    def getVdevicePage(self):
+	return self.vdevice_share
 
     def getConsolePort(self):
         """For use only by image.py and XendCheckpoint.py"""
@@ -1285,6 +1289,7 @@
                                                   0, 0)
 
             self.createChannels()
+            self.createVdevicePage()
 
             channel_details = self.image.createImage()
 
@@ -1444,6 +1449,11 @@
             log.exception("Exception in alloc_unbound(%d)", self.domid)
             raise
 
+    def createVdevicePage(self):
+	"""Create a shared Vdevice page for a domain
+	"""
+	self.vdevice_share = xc.create_shared_pages(1)
+	xc.grant_shared_pages(dom=self.domid, mfn=self.vdevice_share)
 
     ## public:
 
diff -r cddc595b285b tools/python/xen/xend/image.py
--- a/tools/python/xen/xend/image.py	Thu Jun  1 23:26:37 2006
+++ b/tools/python/xen/xend/image.py	Fri Jun  2 09:27:39 2006
@@ -171,13 +171,15 @@
     ostype = "linux"
 
     def buildDomain(self):
-        store_evtchn = self.vm.getStorePort()
+        store_evtchn = self.vm.getStorePort() 
         console_evtchn = self.vm.getConsolePort()
+        vdevice_share = self.vm.getVdevicePage()
 
         log.debug("dom            = %d", self.vm.getDomid())
         log.debug("image          = %s", self.kernel)
         log.debug("store_evtchn   = %d", store_evtchn)
         log.debug("console_evtchn = %d", console_evtchn)
+        log.debug("vdevide_mfn    = %#lx", vdevice_share)
         log.debug("cmdline        = %s", self.cmdline)
         log.debug("ramdisk        = %s", self.ramdisk)
         log.debug("vcpus          = %d", self.vm.getVCpuCount())
@@ -189,7 +191,8 @@
                               console_evtchn = console_evtchn,
                               cmdline        = self.cmdline,
                               ramdisk        = self.ramdisk,
-                              features       = self.vm.getFeatures())
+                              features       = self.vm.getFeatures(),
+                              vdevice_share    = vdevice_share)
 
 class HVMImageHandler(ImageHandler):
 
diff -r cddc595b285b tools/xcutils/xc_restore.c
--- a/tools/xcutils/xc_restore.c	Thu Jun  1 23:26:37 2006
+++ b/tools/xcutils/xc_restore.c	Fri Jun  2 09:27:39 2006
@@ -19,11 +19,11 @@
 {
     unsigned int xc_fd, io_fd, domid, nr_pfns, store_evtchn, console_evtchn;
     int ret;
-    unsigned long store_mfn, console_mfn;
+    unsigned long store_mfn, console_mfn, vdevice_share;
 
-    if (argc != 7)
+    if (argc != 8)
 	errx(1,
-	     "usage: %s xcfd iofd domid nr_pfns store_evtchn console_evtchn",
+	     "usage: %s xcfd iofd domid nr_pfns store_evtchn console_evtchn vdevice_share",
 	     argv[0]);
 
     xc_fd = atoi(argv[1]);
@@ -32,9 +32,10 @@
     nr_pfns = atoi(argv[4]);
     store_evtchn = atoi(argv[5]);
     console_evtchn = atoi(argv[6]);
+    vdevice_share = atoi(argv[7]);
 
     ret = xc_linux_restore(xc_fd, io_fd, domid, nr_pfns, store_evtchn,
-			   &store_mfn, console_evtchn, &console_mfn);
+			   &store_mfn, console_evtchn, &console_mfn, vdevice_share);
     if (ret == 0) {
 	printf("store-mfn %li\n", store_mfn);
 	printf("console-mfn %li\n", console_mfn);
diff -r cddc595b285b linux-2.6-xen-sparse/include/xen/public/io/vdevice.h
--- /dev/null	Thu Jun  1 23:26:37 2006
+++ b/xen/include/public/io/vdevice.h	Fri Jun  2 09:27:39 2006
@@ -0,0 +1,23 @@
+#ifndef __XEN_PUBLIC_IO_VDEVICE_H__
+#define __XEN_PUBLIC_IO_VDEVICE_H__
+
+/* These status bits are generic.  256 and above is device specific. */
+#define VDEVICE_S_ACKNOWLEDGE	1 /* We have seen device. */
+#define VDEVICE_S_MAPPED	2 /* We have mapped device OK */
+#define VDEVICE_S_DRIVER	4 /* We have found a driver */
+#define VDEVICE_S_DRIVER_OK	8 /* Driver says OK! */
+#define VDEVICE_S_FAILED	128 /* Something actually failed */
+
+struct vdevice_id {
+	uint32_t type;
+	uint32_t features;
+};
+
+/* We have a page of these descriptors in the vdevice page. */
+struct vdevice_desc {
+	struct vdevice_id id;
+	uint32_t nr_pages;
+	uint32_t status;
+	uint64_t shared_ref;
+};
+#endif	/* __LINUX_VDEVICE_H__ */

-- 
 ccontrol: http://ccontrol.ozlabs.org

  parent reply	other threads:[~2006-06-06  5:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-06  5:35 [PATCH 1/9] Xen Share: Simplified I/O Mechanism Rusty Russell
2006-06-06  5:50 ` [PATCH 3/9] privcmd interface addition to support share operations from Dom0 userspace Rusty Russell
2006-06-06  5:51 ` [PATCH 4/9] /dev/xenshare for accessing/mapping shared pages from userspace Rusty Russell
2006-06-06  5:52 ` Rusty Russell [this message]
2006-06-06  5:54 ` [PATCH 6/9] Linux support for vdevice bus Rusty Russell
2006-06-07 10:03   ` Jacob Gorm Hansen
2006-06-07 10:58     ` Rusty Russell
2006-06-07 11:09       ` Jacob Gorm Hansen
2006-06-06  5:55 ` [PATCH 7/9] vdevice tool for manipulating " Rusty Russell
2006-06-06  5:57 ` [PATCH 8/9] Xen Share Net Device Rusty Russell
2006-06-06  5:58 ` [PATCH 2/9] Linux kernel infrastructure for Xen Share access Rusty Russell
2006-06-14 17:26   ` Mike D. Day
2006-06-06  5:59 ` [PATCH 9/9] Simple Xenshare Block Device and userspace backend Rusty Russell
2006-06-06 14:31 ` [PATCH 1/9] Xen Share: Simplified I/O Mechanism Harry Butterworth
2006-06-07  2:24   ` Rusty Russell
2006-06-06 14:47 ` Harry Butterworth
2006-06-07  2:35   ` Rusty Russell
2006-06-07 13:31     ` Harry Butterworth
2006-06-14 17:46 ` Mike D. Day

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1149573178.5183.38.camel@localhost.localdomain \
    --to=rusty@rustcorp.com.au \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.