From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Zeffertt Subject: [PATCH 4/24] [xen-unstable.hg] make xenstored use grantref rather than map_foreign_range (which only privileged domains can do) Date: Mon, 23 Mar 2009 15:20:38 +0000 Message-ID: <49C7A8C6.50008@eu.citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------060307000905090909090405" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --------------060307000905090909090405 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit --------------060307000905090909090405 Content-Type: text/plain; name="xenstored_map_grant_ref" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="xenstored_map_grant_ref" 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 Signed-off-by: Alex Zeffertt --- 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 +#include 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(); --------------060307000905090909090405 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------060307000905090909090405--