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-devel

[Xen-devel] [PATCH 4/24] [xen-unstable.hg] make xenstored use grantref r

To: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH 4/24] [xen-unstable.hg] make xenstored use grantref rather than map_foreign_range (which only privileged domains can do)
From: Alex Zeffertt <alex.zeffertt@xxxxxxxxxxxxx>
Date: Mon, 23 Mar 2009 15:20:38 +0000
Delivery-date: Mon, 23 Mar 2009 08:26:40 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 2.0.0.19 (X11/20090105)


This patch modifies the xenstore daemon to use xc_gnttab_map_grant_ref
instead of xc_map_foreign_range where available.

TODO: This will probably break linking on Solaris, since they don't have
stubs for the gntmap functions yet.

A previous version of this patch was sent to xen-devel. See
http://lists.xensource.com/archives/html/xen-devel/2008-07/msg00610.html

Signed-off-by: Diego Ongaro <diego.ongaro@xxxxxxxxxx>
Signed-off-by: Alex Zeffertt <alex.zeffertt@xxxxxxxxxxxxx>
---

diff -r 289762278873 tools/xenstore/xenstored_domain.c
--- a/tools/xenstore/xenstored_domain.c Fri Aug 01 16:50:27 2008 +0100
+++ b/tools/xenstore/xenstored_domain.c Fri Aug 01 16:50:28 2008 +0100
@@ -31,8 +31,10 @@
 #include "xenstored_watch.h"
 
 #include <xenctrl.h>
+#include <xen/grant_table.h>
 
 static int *xc_handle;
+static int *xcg_handle;
 static evtchn_port_t virq_port;
 
 int xce_handle = -1; 
@@ -173,8 +175,12 @@
                        eprintf("> Unbinding port %i failed!\n", domain->port);
        }
 
-       if (domain->interface)
-               munmap(domain->interface, getpagesize());
+       if (domain->interface) {
+               if (*xcg_handle >= 0 && domain->domid != 0)
+                       xc_gnttab_munmap(*xcg_handle, domain->interface, 1);
+               else
+                       munmap(domain->interface, getpagesize());
+       }
 
        fire_watches(NULL, "@releaseDomain", false);
 
@@ -343,9 +349,17 @@
        domain = find_domain_by_domid(domid);
 
        if (domain == NULL) {
-               interface = xc_map_foreign_range(
-                       *xc_handle, domid,
-                       getpagesize(), PROT_READ|PROT_WRITE, mfn);
+               if (*xcg_handle >= 0) {
+                       /* this is the preferred method */
+                       interface = xc_gnttab_map_grant_ref(
+                               *xcg_handle, domid,
+                               GNTTAB_RESERVED_XENSTORE,
+                               PROT_READ|PROT_WRITE);
+               } else {
+                       interface = xc_map_foreign_range(
+                               *xc_handle, domid,
+                               getpagesize(), PROT_READ|PROT_WRITE, mfn);
+               }
                if (!interface) {
                        send_error(conn, errno);
                        return;
@@ -353,7 +367,10 @@
                /* Hang domain off "in" until we're finished. */
                domain = new_domain(in, domid, port);
                if (!domain) {
-                       munmap(interface, getpagesize());
+                       if (*xcg_handle >= 0)
+                               xc_gnttab_munmap(*xcg_handle, interface, 1);
+                       else
+                               munmap(interface, getpagesize());
                        send_error(conn, errno);
                        return;
                }
@@ -542,6 +559,12 @@
        return 0;
 }
 
+static int close_xcg_handle(void *_handle)
+{
+       xc_gnttab_close(*(int *)_handle);
+       return 0;
+}
+
 /* Returns the implicit path of a connection (only domains have this) */
 const char *get_implicit_path(const struct connection *conn)
 {
@@ -584,6 +607,7 @@
 {
        int rc;
 
+       /* Open the hypervisor interface. */
        xc_handle = talloc(talloc_autofree_context(), int);
        if (!xc_handle)
                barf_perror("Failed to allocate domain handle");
@@ -593,6 +617,17 @@
                barf_perror("Failed to open connection to hypervisor");
 
        talloc_set_destructor(xc_handle, close_xc_handle);
+
+       /* Open the gntdev interface. */
+       xcg_handle = talloc(talloc_autofree_context(), int);
+       if (!xcg_handle)
+               barf_perror("Failed to allocate domain gnttab handle");
+
+       *xcg_handle = xc_gnttab_open();
+       if (*xcg_handle < 0)
+               xprintf("WARNING: Failed to open connection to gnttab\n");
+       else
+               talloc_set_destructor(xcg_handle, close_xcg_handle);
 
        xce_handle = xc_evtchn_open();
 


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH 4/24] [xen-unstable.hg] make xenstored use grantref rather than map_foreign_range (which only privileged domains can do), Alex Zeffertt <=