All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 4/24] [xen-unstable.hg] make xenstored use grantref rather than map_foreign_range (which only privileged domains can do)
@ 2009-03-23 15:20 Alex Zeffertt
  0 siblings, 0 replies; only message in thread
From: Alex Zeffertt @ 2009-03-23 15:20 UTC (permalink / raw)
  To: xen-devel@lists.xensource.com

[-- Attachment #1: Type: text/plain, Size: 2 bytes --]




[-- Attachment #2: xenstored_map_grant_ref --]
[-- Type: text/plain, Size: 3206 bytes --]

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@citrix.com>
Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
---

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();
 



[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-03-23 15:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-23 15:20 [PATCH 4/24] [xen-unstable.hg] make xenstored use grantref rather than map_foreign_range (which only privileged domains can do) Alex Zeffertt

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.