All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
To: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: [PATCH 5/24] [xen-unstable.hg] make consoled use grantref rather than map_foreign_range (which only privileged domains can do)
Date: Mon, 23 Mar 2009 15:20:42 +0000	[thread overview]
Message-ID: <49C7A8CA.6020805@eu.citrix.com> (raw)

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




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

This patch modifies the console 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 5c5e30d44696 tools/console/daemon/io.c
--- a/tools/console/daemon/io.c	Fri Aug 01 16:50:29 2008 +0100
+++ b/tools/console/daemon/io.c	Fri Aug 01 16:50:30 2008 +0100
@@ -25,6 +25,7 @@
 #include <xs.h>
 #include <xen/io/console.h>
 #include <xenctrl.h>
+#include <xen/grant_table.h>
 
 #include <stdlib.h>
 #include <errno.h>
@@ -538,12 +539,22 @@
 		goto out;
 
 	if (ring_ref != dom->ring_ref) {
-		if (dom->interface != NULL)
-			munmap(dom->interface, getpagesize());
-		dom->interface = xc_map_foreign_range(
-			xc, dom->domid, getpagesize(),
-			PROT_READ|PROT_WRITE,
-			(unsigned long)ring_ref);
+		if (xcg >= 0) {
+			/* this is the preferred method */
+			if (dom->interface != NULL)
+				xc_gnttab_munmap(xcg, dom->interface, 1);
+			dom->interface = xc_gnttab_map_grant_ref(
+				xcg, dom->domid,
+				GNTTAB_RESERVED_CONSOLE,
+				PROT_READ|PROT_WRITE);
+		} else {
+			if (dom->interface != NULL)
+				munmap(dom->interface, getpagesize());
+			dom->interface = xc_map_foreign_range(
+				xc, dom->domid, getpagesize(),
+				PROT_READ|PROT_WRITE,
+				(unsigned long)ring_ref);
+		}
 		if (dom->interface == NULL) {
 			err = EINVAL;
 			goto out;
@@ -736,9 +747,13 @@
 {
 	d->is_dead = true;
 	watch_domain(d, false);
-	if (d->interface != NULL)
-		munmap(d->interface, getpagesize());
-	d->interface = NULL;
+	if (d->interface != NULL) {
+		if (xcg >= 0)
+			xc_gnttab_munmap(xcg, d->interface, 1);
+		else
+			munmap(d->interface, getpagesize());
+		d->interface = NULL;
+	}
 	if (d->xce_handle != -1)
 		xc_evtchn_close(d->xce_handle);
 	d->xce_handle = -1;
diff -r 5c5e30d44696 tools/console/daemon/utils.c
--- a/tools/console/daemon/utils.c	Fri Aug 01 16:50:29 2008 +0100
+++ b/tools/console/daemon/utils.c	Fri Aug 01 16:50:30 2008 +0100
@@ -38,7 +38,8 @@
 #include "utils.h"
 
 struct xs_handle *xs;
-int xc;
+int xc = -1;
+int xcg = -1;
 
 static void child_exit(int sig)
 {
@@ -122,6 +123,11 @@
 		goto out;
 	}
 
+	xcg = xc_gnttab_open();
+	if (xcg == -1) {
+		dolog(LOG_WARNING, "Failed to open gnttab (%m)");
+	}
+
 	if (!xs_watch(xs, "@introduceDomain", "domlist")) {
 		dolog(LOG_ERR, "xenstore watch on @introduceDomain fails.");
 		goto out;
@@ -139,6 +145,8 @@
 		xs_daemon_close(xs);
 	if (xc != -1)
 		xc_interface_close(xc);
+	if (xcg != -1)
+		xc_gnttab_close(xcg);
 	return false;
 }
 
diff -r 5c5e30d44696 tools/console/daemon/utils.h
--- a/tools/console/daemon/utils.h	Fri Aug 01 16:50:29 2008 +0100
+++ b/tools/console/daemon/utils.h	Fri Aug 01 16:50:30 2008 +0100
@@ -32,6 +32,7 @@
 
 extern struct xs_handle *xs;
 extern int xc;
+extern int xcg;
 
 #if 1
 #define dolog(val, fmt, ...) do {				\



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

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

                 reply	other threads:[~2009-03-23 15:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=49C7A8CA.6020805@eu.citrix.com \
    --to=alex.zeffertt@eu.citrix.com \
    --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.