]> xenbits.xensource.com Git - people/aperard/xen-arm.git/commitdiff
xenconsoled: use grant references instead of map_foreign_range
authorDaniel De Graaf <dgdegra@tycho.nsa.gov>
Thu, 17 Jan 2013 16:48:21 +0000 (16:48 +0000)
committerDaniel De Graaf <dgdegra@tycho.nsa.gov>
Thu, 17 Jan 2013 16:48:21 +0000 (16:48 +0000)
Grant references for the xenstore and xenconsole shared pages exist, but
currently only xenstore uses these references.  Change the xenconsole
daemon to prefer using the grant reference over map_foreign_range when
mapping the shared console ring.

This allows xenconsoled to be run in a domain other than dom0 if set up
correctly - for libxl, the xenstore path /tool/xenconsoled/domid
specifies the domain containing xenconsoled.

Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
tools/console/daemon/io.c
tools/console/daemon/io.h
tools/console/daemon/main.c

index 6b659d4419d0af5a51a03bc12065fcd0d5e21e88..176ac3cc535059dd6857b93b1316a5aa1396ab3c 100644 (file)
@@ -24,6 +24,7 @@
 #include "io.h"
 #include <xenstore.h>
 #include <xen/io/console.h>
+#include <xen/grant_table.h>
 
 #include <stdlib.h>
 #include <errno.h>
@@ -67,6 +68,8 @@ static int log_time_hv_needts = 1;
 static int log_time_guest_needts = 1;
 static int log_hv_fd = -1;
 
+static xc_gnttab *xcg_handle = NULL;
+
 static struct pollfd  *fds;
 static unsigned int current_array_size;
 static unsigned int nr_fds;
@@ -506,6 +509,18 @@ static int xs_gather(struct xs_handle *xs, const char *dir, ...)
        va_end(ap);
        return ret;
 }
+
+static void domain_unmap_interface(struct domain *dom)
+{
+       if (dom->interface == NULL)
+               return;
+       if (xcg_handle && dom->ring_ref == -1)
+               xc_gnttab_munmap(xcg_handle, dom->interface, 1);
+       else
+               munmap(dom->interface, getpagesize());
+       dom->interface = NULL;
+       dom->ring_ref = -1;
+}
  
 static int domain_create_ring(struct domain *dom)
 {
@@ -527,9 +542,19 @@ static int domain_create_ring(struct domain *dom)
        }
        free(type);
 
-       if (ring_ref != dom->ring_ref) {
-               if (dom->interface != NULL)
-                       munmap(dom->interface, getpagesize());
+       /* If using ring_ref and it has changed, remap */
+       if (ring_ref != dom->ring_ref && dom->ring_ref != -1)
+               domain_unmap_interface(dom);
+
+       if (!dom->interface && xcg_handle) {
+               /* Prefer using grant table */
+               dom->interface = xc_gnttab_map_grant_ref(xcg_handle,
+                       dom->domid, GNTTAB_RESERVED_CONSOLE,
+                       PROT_READ|PROT_WRITE);
+               dom->ring_ref = -1;
+       }
+       if (!dom->interface) {
+               /* Fall back to xc_map_foreign_range */
                dom->interface = xc_map_foreign_range(
                        xc, dom->domid, getpagesize(),
                        PROT_READ|PROT_WRITE,
@@ -725,9 +750,7 @@ static void shutdown_domain(struct domain *d)
 {
        d->is_dead = true;
        watch_domain(d, false);
-       if (d->interface != NULL)
-               munmap(d->interface, getpagesize());
-       d->interface = NULL;
+       domain_unmap_interface(d);
        if (d->xce_handle != NULL)
                xc_evtchn_close(d->xce_handle);
        d->xce_handle = NULL;
@@ -735,7 +758,7 @@ static void shutdown_domain(struct domain *d)
 
 static unsigned enum_pass = 0;
 
-void enum_domains(void)
+static void enum_domains(void)
 {
        int domid = 1;
        xc_dominfo_t dominfo;
@@ -996,6 +1019,14 @@ void handle_io(void)
                }
        }
 
+       xcg_handle = xc_gnttab_open(NULL, 0);
+       if (xcg_handle == NULL) {
+               dolog(LOG_DEBUG, "Failed to open xcg handle: %d (%s)",
+                     errno, strerror(errno));
+       }
+
+       enum_domains();
+
        for (;;) {
                struct domain *d, *n;
                int poll_timeout; /* timeout in milliseconds */
@@ -1165,6 +1196,10 @@ void handle_io(void)
                xc_evtchn_close(xce_handle);
                xce_handle = NULL;
        }
+       if (xcg_handle != NULL) {
+               xc_gnttab_close(xcg_handle);
+               xcg_handle = NULL;
+       }
        log_hv_evtchn = -1;
 }
 
index 8fa04b677566d0a00b58e165b49d34f2b9c67e8a..f658bfcea03eb96dafb8d1b7c2b9d2e8f60208a2 100644 (file)
@@ -21,7 +21,6 @@
 #ifndef CONSOLED_IO_H
 #define CONSOLED_IO_H
 
-void enum_domains(void);
 void handle_io(void);
 
 #endif
index 789baa6c2369ed970af1a4c2cc94933a5d615188..92d2fc41237bbf01d40a990e51974715039dfaa7 100644 (file)
@@ -161,8 +161,6 @@ int main(int argc, char **argv)
        if (!xen_setup())
                exit(1);
 
-       enum_domains();
-
        handle_io();
 
        closelog();