]> xenbits.xensource.com Git - xen.git/commitdiff
tools/console: use xenforeigmemory to map console ring
authorRoger Pau Monne <roger.pau@citrix.com>
Wed, 22 Sep 2021 08:21:18 +0000 (10:21 +0200)
committerIan Jackson <iwj@xenproject.org>
Mon, 11 Oct 2021 11:05:38 +0000 (12:05 +0100)
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@citrix.com>
Reviewed-by: Ian Jackson <iwj@xenproject.org>
tools/console/Makefile
tools/console/daemon/io.c

index 84796eac8f111e8ab3c3d5428223050ac7929569..3f4cddab03745f012fb679998db931ddc8b074b2 100644 (file)
@@ -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))
index 200b575d76f8be8a285fb1e7c2068a383a764c2f..682c1f4008e0c984987e2e712c84175c923888b9 100644 (file)
@@ -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;
 }