Patchwork [V7,03/15] xen: Support new libxc calls from xen unstable.

login
register
mail settings
Submitter Anthony PERARD
Date Nov. 23, 2010, 7:51 p.m.
Message ID <1290541910-11332-4-git-send-email-anthony.perard@citrix.com>
Download mbox | patch
Permalink /patch/72753/
State New
Headers show

Comments

Anthony PERARD - Nov. 23, 2010, 7:51 p.m.
From: Anthony PERARD <anthony.perard@citrix.com>

Update the libxenctrl calls in Qemu to use the new interface, otherwise
Qemu wouldn't be able to build against new versions of the library.

We also check libxenctrl version in configure, from Xen 3.3.0 to Xen
unstable.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 Makefile.target      |    1 +
 configure            |   67 ++++++++++++++++++++++++++++++++++++-
 hw/xen_backend.c     |   10 +++---
 hw/xen_backend.h     |    3 +-
 hw/xen_common.h      |   36 ++++++++++++--------
 hw/xen_disk.c        |   12 +++---
 hw/xen_domainbuild.c |    2 +-
 hw/xen_interfaces.c  |   90 +++++++++++++++++++++++++++++++++++++++++++++++++-
 hw/xen_interfaces.h  |   36 +++++++++++++-------
 hw/xen_nic.c         |   16 ++++----
 hw/xen_redirect.h    |    2 +
 11 files changed, 224 insertions(+), 51 deletions(-)

Patch

diff --git a/Makefile.target b/Makefile.target
index 2800f47..30863e0 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -205,6 +205,7 @@  QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
 
 # xen backend driver support
 obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
+obj-$(CONFIG_XEN) += xen_interfaces.o
 
 # USB layer
 obj-$(CONFIG_USB_OHCI) += usb-ohci.o
diff --git a/configure b/configure
index 2917874..28375b1 100755
--- a/configure
+++ b/configure
@@ -285,6 +285,7 @@  vnc_jpeg=""
 vnc_png=""
 vnc_thread="no"
 xen=""
+xen_ctrl_version=""
 linux_aio=""
 attr=""
 vhost_net=""
@@ -1138,20 +1139,81 @@  fi
 
 if test "$xen" != "no" ; then
   xen_libs="-lxenstore -lxenctrl -lxenguest"
+
+  # Xen unstable
   cat > $TMPC <<EOF
 #include <xenctrl.h>
 #include <xs.h>
-int main(void) { xs_daemon_open(); xc_interface_open(); return 0; }
+#include <stdint.h>
+#include <xen/hvm/hvm_info_table.h>
+#if !defined(HVM_MAX_VCPUS)
+# error HVM_MAX_VCPUS not defined
+#endif
+int main(void) {
+  xc_interface *xc;
+  xs_daemon_open();
+  xc_interface_open(0, 0, 0);
+  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
+  xc_gnttab_open(xc);
+  return 0;
+}
 EOF
   if compile_prog "" "$xen_libs" ; then
+    xen_ctrl_version=410
     xen=yes
-    libs_softmmu="$xen_libs $libs_softmmu"
+
+  # Xen 4.0.0
+  elif (
+      cat > $TMPC <<EOF
+#include <xenctrl.h>
+#include <xs.h>
+#include <stdint.h>
+#include <xen/hvm/hvm_info_table.h>
+#if !defined(HVM_MAX_VCPUS)
+# error HVM_MAX_VCPUS not defined
+#endif
+int main(void) {
+  xs_daemon_open();
+  xc_interface_open();
+  xc_gnttab_open();
+  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
+  return 0;
+}
+EOF
+      compile_prog "" "$xen_libs"
+    ) ; then
+    xen_ctrl_version=400
+    xen=yes
+
+  # Xen 3.3.0, 3.4.0
+  elif (
+      cat > $TMPC <<EOF
+#include <xenctrl.h>
+#include <xs.h>
+int main(void) {
+  xs_daemon_open();
+  xc_interface_open();
+  xc_gnttab_open();
+  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
+  return 0;
+}
+EOF
+      compile_prog "" "$xen_libs"
+    ) ; then
+    xen_ctrl_version=330
+    xen=yes
+
+  # Xen not found or unsupported
   else
     if test "$xen" = "yes" ; then
       feature_not_found "xen"
     fi
     xen=no
   fi
+
+  if test "$xen" = "yes"; then
+    libs_softmmu="$xen_libs $libs_softmmu"
+  fi
 fi
 
 ##########################################
@@ -2566,6 +2628,7 @@  if test "$bluez" = "yes" ; then
 fi
 if test "$xen" = "yes" ; then
   echo "CONFIG_XEN=y" >> $config_host_mak
+  echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak
 fi
 if test "$io_thread" = "yes" ; then
   echo "CONFIG_IOTHREAD=y" >> $config_host_mak
diff --git a/hw/xen_backend.c b/hw/xen_backend.c
index 860b038..2298671 100644
--- a/hw/xen_backend.c
+++ b/hw/xen_backend.c
@@ -43,7 +43,7 @@ 
 /* ------------------------------------------------------------- */
 
 /* public */
-int xen_xc;
+qemu_xc_interface xen_xc = XC_HANDLER_INITIAL_VALUE;
 struct xs_handle *xenstore = NULL;
 const char *xen_protocol;
 
@@ -216,7 +216,7 @@  static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
     fcntl(xc_evtchn_fd(xendev->evtchndev), F_SETFD, FD_CLOEXEC);
 
     if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) {
-        xendev->gnttabdev = xc_gnttab_open();
+        xendev->gnttabdev = xc_gnttab_open(xen_xc);
         if (xendev->gnttabdev < 0) {
             xen_be_printf(NULL, 0, "can't open gnttab device\n");
             xc_evtchn_close(xendev->evtchndev);
@@ -269,7 +269,7 @@  static struct XenDevice *xen_be_del_xendev(int dom, int dev)
         if (xendev->evtchndev >= 0)
             xc_evtchn_close(xendev->evtchndev);
         if (xendev->gnttabdev >= 0)
-            xc_gnttab_close(xendev->gnttabdev);
+            xc_gnttab_close(xen_xc, xendev->gnttabdev);
 
         QTAILQ_REMOVE(&xendevs, xendev, next);
         qemu_free(xendev);
@@ -627,8 +627,8 @@  int xen_be_init(void)
     if (qemu_set_fd_handler(xs_fileno(xenstore), xenstore_update, NULL, NULL) < 0)
         goto err;
 
-    xen_xc = xc_interface_open();
-    if (xen_xc == -1) {
+    xen_xc = xc_interface_open(0, 0, 0);
+    if (xen_xc == XC_HANDLER_INITIAL_VALUE) {
         xen_be_printf(NULL, 0, "can't open xen interface\n");
         goto err;
     }
diff --git a/hw/xen_backend.h b/hw/xen_backend.h
index 1b428e3..933bdf2 100644
--- a/hw/xen_backend.h
+++ b/hw/xen_backend.h
@@ -2,6 +2,7 @@ 
 #define QEMU_HW_XEN_BACKEND_H 1
 
 #include "xen_common.h"
+#include "xen_redirect.h"
 #include "sysemu.h"
 #include "net.h"
 
@@ -55,7 +56,7 @@  struct XenDevice {
 /* ------------------------------------------------------------- */
 
 /* variables */
-extern int xen_xc;
+extern qemu_xc_interface xen_xc;
 extern struct xs_handle *xenstore;
 extern const char *xen_protocol;
 
diff --git a/hw/xen_common.h b/hw/xen_common.h
index 8a55b44..79d8d4d 100644
--- a/hw/xen_common.h
+++ b/hw/xen_common.h
@@ -1,6 +1,8 @@ 
 #ifndef QEMU_HW_XEN_COMMON_H
 #define QEMU_HW_XEN_COMMON_H 1
 
+#include "config-host.h"
+
 #include <stddef.h>
 #include <inttypes.h>
 
@@ -13,22 +15,26 @@ 
 #include "qemu-queue.h"
 
 /*
- * tweaks needed to build with different xen versions
- *  0x00030205 -> 3.1.0
- *  0x00030207 -> 3.2.0
- *  0x00030208 -> unstable
+ * We don't support Xen prior to 3.3.0.
  */
-#include <xen/xen-compat.h>
-#if __XEN_LATEST_INTERFACE_VERSION__ < 0x00030205
-# define evtchn_port_or_error_t int
-#endif
-#if __XEN_LATEST_INTERFACE_VERSION__ < 0x00030207
-# define xc_map_foreign_pages xc_map_foreign_batch
-#endif
-#if __XEN_LATEST_INTERFACE_VERSION__ < 0x00030208
-# define xen_mb()  mb()
-# define xen_rmb() rmb()
-# define xen_wmb() wmb()
+
+/* Xen unstable */
+#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
+typedef int qemu_xc_interface;
+#  define XC_HANDLER_INITIAL_VALUE    -1
+static inline int xc_fd(int xen_xc)
+{
+    return xen_xc;
+}
+#else
+typedef xc_interface *qemu_xc_interface;
+#  define XC_HANDLER_INITIAL_VALUE    NULL
+/* FIXME The fd of xen_xc is now xen_xc->fd */
+/* fd is the first field, so this works */
+static inline int xc_fd(xc_interface *xen_xc)
+{
+    return *(int*)xen_xc;
+}
 #endif
 
 #endif /* QEMU_HW_XEN_COMMON_H */
diff --git a/hw/xen_disk.c b/hw/xen_disk.c
index 47280ee..ec1365c 100644
--- a/hw/xen_disk.c
+++ b/hw/xen_disk.c
@@ -243,7 +243,7 @@  static void ioreq_unmap(struct ioreq *ioreq)
     if (batch_maps) {
         if (!ioreq->pages)
             return;
-        if (xc_gnttab_munmap(gnt, ioreq->pages, ioreq->v.niov) != 0)
+        if (xc_gnttab_munmap(xen_xc, gnt, ioreq->pages, ioreq->v.niov) != 0)
             xen_be_printf(&ioreq->blkdev->xendev, 0, "xc_gnttab_munmap failed: %s\n",
                           strerror(errno));
         ioreq->blkdev->cnt_map -= ioreq->v.niov;
@@ -252,7 +252,7 @@  static void ioreq_unmap(struct ioreq *ioreq)
         for (i = 0; i < ioreq->v.niov; i++) {
             if (!ioreq->page[i])
                 continue;
-            if (xc_gnttab_munmap(gnt, ioreq->page[i], 1) != 0)
+            if (xc_gnttab_munmap(xen_xc, gnt, ioreq->page[i], 1) != 0)
                 xen_be_printf(&ioreq->blkdev->xendev, 0, "xc_gnttab_munmap failed: %s\n",
                               strerror(errno));
             ioreq->blkdev->cnt_map--;
@@ -270,7 +270,7 @@  static int ioreq_map(struct ioreq *ioreq)
         return 0;
     if (batch_maps) {
         ioreq->pages = xc_gnttab_map_grant_refs
-            (gnt, ioreq->v.niov, ioreq->domids, ioreq->refs, ioreq->prot);
+            (xen_xc, gnt, ioreq->v.niov, ioreq->domids, ioreq->refs, ioreq->prot);
         if (ioreq->pages == NULL) {
             xen_be_printf(&ioreq->blkdev->xendev, 0,
                           "can't map %d grant refs (%s, %d maps)\n",
@@ -284,7 +284,7 @@  static int ioreq_map(struct ioreq *ioreq)
     } else  {
         for (i = 0; i < ioreq->v.niov; i++) {
             ioreq->page[i] = xc_gnttab_map_grant_ref
-                (gnt, ioreq->domids[i], ioreq->refs[i], ioreq->prot);
+                (xen_xc, gnt, ioreq->domids[i], ioreq->refs[i], ioreq->prot);
             if (ioreq->page[i] == NULL) {
                 xen_be_printf(&ioreq->blkdev->xendev, 0,
                               "can't map grant ref %d (%s, %d maps)\n",
@@ -684,7 +684,7 @@  static int blk_connect(struct XenDevice *xendev)
             blkdev->protocol = BLKIF_PROTOCOL_X86_64;
     }
 
-    blkdev->sring = xc_gnttab_map_grant_ref(blkdev->xendev.gnttabdev,
+    blkdev->sring = xc_gnttab_map_grant_ref(xen_xc, blkdev->xendev.gnttabdev,
                                             blkdev->xendev.dom,
                                             blkdev->ring_ref,
                                             PROT_READ | PROT_WRITE);
@@ -739,7 +739,7 @@  static void blk_disconnect(struct XenDevice *xendev)
     xen_be_unbind_evtchn(&blkdev->xendev);
 
     if (blkdev->sring) {
-        xc_gnttab_munmap(blkdev->xendev.gnttabdev, blkdev->sring, 1);
+        xc_gnttab_munmap(xen_xc, blkdev->xendev.gnttabdev, blkdev->sring, 1);
         blkdev->cnt_map--;
         blkdev->sring = NULL;
     }
diff --git a/hw/xen_domainbuild.c b/hw/xen_domainbuild.c
index 7f1fd66..232a456 100644
--- a/hw/xen_domainbuild.c
+++ b/hw/xen_domainbuild.c
@@ -176,7 +176,7 @@  static int xen_domain_watcher(void)
     for (i = 3; i < n; i++) {
         if (i == fd[0])
             continue;
-        if (i == xen_xc)
+        if (i == xc_fd(xen_xc))
             continue;
         close(i);
     }
diff --git a/hw/xen_interfaces.c b/hw/xen_interfaces.c
index 09f40e0..129e8b2 100644
--- a/hw/xen_interfaces.c
+++ b/hw/xen_interfaces.c
@@ -1,8 +1,11 @@ 
+#include "config-host.h"
+
 #include <xenctrl.h>
 #include <xs.h>
 
 #include "hw.h"
 #include "xen.h"
+#include "xen_common.h"
 #include "xen_interfaces.h"
 
 #ifdef CONFIG_XEN
@@ -57,6 +60,44 @@  static struct XenStoreOps xs_xen = {
     .is_domain_introduced  = xs_is_domain_introduced,
 };
 
+/* ------------------------------------------------------------- */
+/* xen grant table interface                                     */
+
+#  if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
+static int gnttab_open(qemu_xc_interface xc)
+{
+    return xc_gnttab_open();
+}
+
+static int gnttab_close(qemu_xc_interface xc, int xcg_handle)
+{
+    return xc_gnttab_close(xcg_handle);
+}
+
+static void *gnttab_map_grant_ref(qemu_xc_interface xc, int xcg_handle, uint32_t domid, uint32_t ref, int prot)
+{
+    return xc_gnttab_map_grant_ref(xcg_handle, domid, ref, prot);
+}
+
+static void *gnttab_map_grant_refs(qemu_xc_interface xc, int xcg_handle, uint32_t count, uint32_t *domids, uint32_t *refs, int prot)
+{
+    return xc_gnttab_map_grant_refs(xcg_handle, count, domids, refs, prot);
+}
+
+static int gnttab_munmap(qemu_xc_interface xc, int xcg_handle, void *start_address, uint32_t count)
+{
+    return xc_gnttab_munmap(xcg_handle, start_address, count);
+}
+
+static struct XenGnttabOps xc_gnttab_xen = {
+    .open            = gnttab_open,
+    .close           = gnttab_close,
+    .map_grant_ref   = gnttab_map_grant_ref,
+    .map_grant_refs  = gnttab_map_grant_refs,
+    .munmap          = gnttab_munmap,
+};
+
+#  else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >= 410 */
 static struct XenGnttabOps xc_gnttab_xen = {
     .open            = xc_gnttab_open,
     .close           = xc_gnttab_close,
@@ -64,16 +105,63 @@  static struct XenGnttabOps xc_gnttab_xen = {
     .map_grant_refs  = xc_gnttab_map_grant_refs,
     .munmap          = xc_gnttab_munmap,
 };
+#  endif
+
+/* ------------------------------------------------------------- */
+/* xen hypercall interface                                       */
+
+#  if CONFIG_XEN_CTRL_INTERFACE_VERSION < 400
+static qemu_xc_interface interface_open(xentoollog_logger *logger,
+                                        xentoollog_logger *dombuild_logger,
+                                        unsigned open_flags)
+{
+    return xc_interface_open();
+}
+
+static void *map_foreign_batch(int xc_handle, uint32_t dom, int prot,
+                               const xen_pfn_t *arr, int *err, unsigned int num)
+{
+    return xc_map_foreign_batch(xc_handle, dom, prot, (xen_pfn_t*)arr, num);
+}
+
+struct XenIfOps xc_xen = {
+    .interface_open                 = interface_open,
+    .interface_close                = xc_interface_close,
+    .map_foreign_range              = xc_map_foreign_range,
+    .map_foreign_pages              = xc_map_foreign_pages,
+    .map_foreign_bulk               = map_foreign_batch,
+    .domain_populate_physmap_exact  = xc_domain_memory_populate_physmap,
+};
+
+#  elif CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
+static qemu_xc_interface interface_open(xentoollog_logger *logger,
+                                        xentoollog_logger *dombuild_logger,
+                                        unsigned open_flags)
+{
+    return xc_interface_open();
+}
 
 struct XenIfOps xc_xen = {
+    .interface_open                 = interface_open,
+    .interface_close                = xc_interface_close,
+    .map_foreign_range              = xc_map_foreign_range,
+    .map_foreign_pages              = xc_map_foreign_pages,
+    .map_foreign_bulk               = xc_map_foreign_bulk,
+    .domain_populate_physmap_exact  = xc_domain_memory_populate_physmap,
+};
+
+#  else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >= 410 */
+struct XenIfOps xc_xen = {
     .interface_open                 = xc_interface_open,
     .interface_close                = xc_interface_close,
     .map_foreign_range              = xc_map_foreign_range,
     .map_foreign_pages              = xc_map_foreign_pages,
     .map_foreign_bulk               = xc_map_foreign_bulk,
+    .domain_populate_physmap_exact  = xc_domain_populate_physmap_exact,
 };
+#  endif
 
-#endif
+#endif /* CONFIG_XEN */
 
 struct XenEvtOps xc_evtchn;
 struct XenGnttabOps xc_gnttab;
diff --git a/hw/xen_interfaces.h b/hw/xen_interfaces.h
index 1086850..697b8eb 100644
--- a/hw/xen_interfaces.h
+++ b/hw/xen_interfaces.h
@@ -71,29 +71,41 @@  extern struct XenStoreOps xs;
 /* xen grant table interface                                     */
 
 struct XenGnttabOps {
-    int (*open)(void);
-    int (*close)(int xcg_handle);
-    void *(*map_grant_ref)(int xcg_handle, uint32_t domid,
-                          uint32_t ref, int prot);
-    void *(*map_grant_refs)(int xcg_handle, uint32_t count,
+    int (*open)(qemu_xc_interface xc);
+    int (*close)(qemu_xc_interface xc, int xcg_handle);
+    void *(*map_grant_ref)(qemu_xc_interface xc, int xcg_handle,
+                           uint32_t domid, uint32_t ref, int prot);
+    void *(*map_grant_refs)(qemu_xc_interface xc, int xcg_handle, uint32_t count,
                             uint32_t *domids, uint32_t *refs, int prot);
-    int (*munmap)(int xcg_handle, void *start_address, uint32_t count);
+    int (*munmap)(qemu_xc_interface xc, int xcg_handle,
+                  void *start_address, uint32_t count);
 };
 extern struct XenGnttabOps xc_gnttab;
 
 /* ------------------------------------------------------------- */
 /* xen hypercall interface                                       */
 
+#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
+typedef struct xentoollog_logger xentoollog_logger;
+#endif
 struct XenIfOps {
-    int (*interface_open)(void);
-    int (*interface_close)(int xc_handle);
-    void *(*map_foreign_range)(int xc_handle, uint32_t dom,
+    qemu_xc_interface (*interface_open)(xentoollog_logger *logger,
+                                        xentoollog_logger *dombuild_logger,
+                                        unsigned open_flags);
+    int (*interface_close)(qemu_xc_interface xc_handle);
+    void *(*map_foreign_range)(qemu_xc_interface xc_handle, uint32_t dom,
                                int size, int prot,
                                unsigned long mfn);
-    void *(*map_foreign_pages)(int xc_handle, uint32_t dom, int prot,
+    void *(*map_foreign_pages)(qemu_xc_interface xc_handle, uint32_t dom, int prot,
                                const xen_pfn_t *arr, int num);
-    void *(*map_foreign_bulk)(int xc_handle, uint32_t dom, int prot,
-                              xen_pfn_t *arr, int num);
+    void *(*map_foreign_bulk)(qemu_xc_interface xc_handle, uint32_t dom, int prot,
+                              const xen_pfn_t *arr, int *err, unsigned int num);
+    int (*domain_populate_physmap_exact)(qemu_xc_interface xc_handle,
+                                         uint32_t domid,
+                                         unsigned long nr_extents,
+                                         unsigned int extent_order,
+                                         unsigned int mem_flags,
+                                         xen_pfn_t *extent_start);
 };
 extern struct XenIfOps xc;
 
diff --git a/hw/xen_nic.c b/hw/xen_nic.c
index 8fcf856..2575541 100644
--- a/hw/xen_nic.c
+++ b/hw/xen_nic.c
@@ -166,7 +166,7 @@  static void net_tx_packets(struct XenNetDev *netdev)
                           (txreq.flags & NETTXF_more_data)      ? " more_data"      : "",
                           (txreq.flags & NETTXF_extra_info)     ? " extra_info"     : "");
 
-            page = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+            page = xc_gnttab_map_grant_ref(xen_xc, netdev->xendev.gnttabdev,
                                            netdev->xendev.dom,
                                            txreq.gref, PROT_READ);
             if (page == NULL) {
@@ -185,7 +185,7 @@  static void net_tx_packets(struct XenNetDev *netdev)
             } else {
                 qemu_send_packet(&netdev->nic->nc, page + txreq.offset, txreq.size);
             }
-            xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1);
+            xc_gnttab_munmap(xen_xc, netdev->xendev.gnttabdev, page, 1);
             net_tx_response(netdev, &txreq, NETIF_RSP_OKAY);
         }
         if (!netdev->tx_work)
@@ -272,7 +272,7 @@  static ssize_t net_rx_packet(VLANClientState *nc, const uint8_t *buf, size_t siz
     memcpy(&rxreq, RING_GET_REQUEST(&netdev->rx_ring, rc), sizeof(rxreq));
     netdev->rx_ring.req_cons = ++rc;
 
-    page = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+    page = xc_gnttab_map_grant_ref(xen_xc, netdev->xendev.gnttabdev,
                                    netdev->xendev.dom,
                                    rxreq.gref, PROT_WRITE);
     if (page == NULL) {
@@ -282,7 +282,7 @@  static ssize_t net_rx_packet(VLANClientState *nc, const uint8_t *buf, size_t siz
         return -1;
     }
     memcpy(page + NET_IP_ALIGN, buf, size);
-    xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1);
+    xc_gnttab_munmap(xen_xc, netdev->xendev.gnttabdev, page, 1);
     net_rx_response(netdev, &rxreq, NETIF_RSP_OKAY, NET_IP_ALIGN, size, 0);
 
     return size;
@@ -350,11 +350,11 @@  static int net_connect(struct XenDevice *xendev)
         return -1;
     }
 
-    netdev->txs = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+    netdev->txs = xc_gnttab_map_grant_ref(xen_xc, netdev->xendev.gnttabdev,
                                           netdev->xendev.dom,
                                           netdev->tx_ring_ref,
                                           PROT_READ | PROT_WRITE);
-    netdev->rxs = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+    netdev->rxs = xc_gnttab_map_grant_ref(xen_xc, netdev->xendev.gnttabdev,
                                           netdev->xendev.dom,
                                           netdev->rx_ring_ref,
                                           PROT_READ | PROT_WRITE);
@@ -381,11 +381,11 @@  static void net_disconnect(struct XenDevice *xendev)
     xen_be_unbind_evtchn(&netdev->xendev);
 
     if (netdev->txs) {
-        xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->txs, 1);
+        xc_gnttab_munmap(xen_xc, netdev->xendev.gnttabdev, netdev->txs, 1);
         netdev->txs = NULL;
     }
     if (netdev->rxs) {
-        xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->rxs, 1);
+        xc_gnttab_munmap(xen_xc, netdev->xendev.gnttabdev, netdev->rxs, 1);
         netdev->rxs = NULL;
     }
     if (netdev->nic) {
diff --git a/hw/xen_redirect.h b/hw/xen_redirect.h
index 6ddecf3..7cd6492 100644
--- a/hw/xen_redirect.h
+++ b/hw/xen_redirect.h
@@ -28,6 +28,8 @@ 
 #define xc_map_foreign_range        xc.map_foreign_range
 #define xc_map_foreign_pages        xc.map_foreign_pages
 #define xc_map_foreign_bulk         xc.map_foreign_bulk
+#define xc_domain_populate_physmap_exact \
+                                    xc.domain_populate_physmap_exact
 
 /* xenstore interface */
 #define xs_daemon_open              xs.daemon_open