[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] tools/console: use xenforeigmemory to map console ring



commit e8b42a4e8810844ccffd2eab072921b1e4e2ed79
Author:     Roger Pau Monne <roger.pau@xxxxxxxxxx>
AuthorDate: Wed Sep 22 10:21:18 2021 +0200
Commit:     Ian Jackson <iwj@xxxxxxxxxxxxxx>
CommitDate: Mon Oct 11 12:05:38 2021 +0100

    tools/console: use xenforeigmemory to map console ring
    
    This patch replaces the usage of xc_map_foreign_range with
    xenforeignmemory_map from the stable xenforeignmemory library. Note
    there are still other uses of libxc functions which prevents removing
    the dependency.
    
    No functional change intended.
    
    Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
    Reviewed-by: Ian Jackson <iwj@xxxxxxxxxxxxxx>
---
 tools/console/Makefile    |  4 ++--
 tools/console/daemon/io.c | 25 ++++++++++++++++++++-----
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/tools/console/Makefile b/tools/console/Makefile
index 84796eac8f..3f4cddab03 100644
--- a/tools/console/Makefile
+++ b/tools/console/Makefile
@@ -29,9 +29,9 @@ clean:
 distclean: clean
 
 daemon/main.o: daemon/_paths.h
-daemon/io.o: CFLAGS += $(CFLAGS_libxenevtchn) $(CFLAGS_libxengnttab) 
$(CONSOLE_CFLAGS-y)
+daemon/io.o: CFLAGS += $(CFLAGS_libxenevtchn) $(CFLAGS_libxengnttab) 
$(CFLAGS_libxenforeignmemory) $(CONSOLE_CFLAGS-y)
 xenconsoled: $(patsubst %.c,%.o,$(wildcard daemon/*.c))
-       $(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) $(LDLIBS_libxenevtchn) 
$(LDLIBS_libxengnttab) $(LDLIBS_xenconsoled) $(APPEND_LDFLAGS)
+       $(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) $(LDLIBS_libxenevtchn) 
$(LDLIBS_libxengnttab) $(LDLIBS_libxenforeignmemory) $(LDLIBS_xenconsoled) 
$(APPEND_LDFLAGS)
 
 client/main.o: client/_paths.h
 xenconsole: $(patsubst %.c,%.o,$(wildcard client/*.c))
diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 200b575d76..682c1f4008 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -22,6 +22,7 @@
 #include "utils.h"
 #include "io.h"
 #include <xenevtchn.h>
+#include <xenforeignmemory.h>
 #include <xengnttab.h>
 #include <xenstore.h>
 #include <xen/io/console.h>
@@ -73,6 +74,7 @@ static int log_time_guest_needts = 1;
 static int log_hv_fd = -1;
 
 static xengnttab_handle *xgt_handle = NULL;
+static xenforeignmemory_handle *xfm_handle;
 
 static struct pollfd  *fds;
 static unsigned int current_array_size;
@@ -675,7 +677,7 @@ static void console_unmap_interface(struct console *con)
        if (xgt_handle && con->ring_ref == -1)
                xengnttab_unmap(xgt_handle, con->interface, 1);
        else
-               munmap(con->interface, XC_PAGE_SIZE);
+               xenforeignmemory_unmap(xfm_handle, con->interface, 1);
        con->interface = NULL;
        con->ring_ref = -1;
 }
@@ -722,11 +724,12 @@ static int console_create_ring(struct console *con)
                con->ring_ref = -1;
        }
        if (!con->interface) {
+               xen_pfn_t pfn = ring_ref;
+
                /* Fall back to xc_map_foreign_range */
-               con->interface = xc_map_foreign_range(
-                       xc, dom->domid, XC_PAGE_SIZE,
-                       PROT_READ|PROT_WRITE,
-                       (unsigned long)ring_ref);
+               con->interface = xenforeignmemory_map(
+                       xfm_handle, dom->domid, PROT_READ|PROT_WRITE, 1,
+                       &pfn, NULL);
                if (con->interface == NULL) {
                        err = EINVAL;
                        goto out;
@@ -1341,6 +1344,14 @@ void handle_io(void)
                      errno, strerror(errno));
        }
 
+       xfm_handle = xenforeignmemory_open(NULL, 0);
+       if (xfm_handle == NULL) {
+               dolog(LOG_ERR,
+                     "Failed to open xen foreign memory handle: %d (%s)",
+                     errno, strerror(errno));
+               goto out;
+       }
+
        enum_domains();
 
        for (;;) {
@@ -1462,6 +1473,10 @@ void handle_io(void)
                xengnttab_close(xgt_handle);
                xgt_handle = NULL;
        }
+       if (xfm_handle != NULL) {
+               xenforeignmemory_close(xfm_handle);
+               xfm_handle = NULL;
+       }
        log_hv_evtchn = -1;
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.