Skip to contentSkip to conversation

Xen device model support

PATCH Superseded [email protected] 4 participants 38 messages Mar 1, 2011 – Apr 6, 2011 Kbuild

v11 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

v11 cover Xen device model support

From: Anthony PERARD <[email protected]>

Hi all,

Here is the few change since the V10:

- Add braces for blocks with single statement in the clean-up patch;
- the patch that builds Xen only for x86 have been removed, instead, xen_domainbuild is built with libhw and other Xen files are built for i386 target only;
- the redirection structure with function pointer have been removed, instead,

    there are few #define or static inline function use for the compatibility;

- the platform device uses trace instead of dprintf for guest log;
- introduce i440fx_xen_init and i440fx_common_init to avoid xen_enabled() in piix_pci.

This series depends on the series "Introduce "machine" QemuOpts".

You can find a git tree here:

git://xenbits.xen.org/people/aperard/qemu-dm.git qemu-dm-v11

Anthony PERARD (12):
xen: Replace some tab-indents with spaces (clean-up).
xen: Make Xen build once.
xen: Support new libxc calls from xen unstable.
xen: Add initialisation of Xen
xen: Add xenfv machine
piix_pci: Introduces Xen specific call for irq.
xen: Introduce Xen Interrupt Controller
configure: Always use 64bits target physical addresses with xen
enabled.
Introduce qemu_put_ram_ptr
vl.c: Introduce getter for shutdown_requested and reset_requested.
xen: Set running state in xenstore.
xen: Add Xen hypercall for sleep state in the cmos_s3 callback.

Arun Sharma (1):
xen: Initialize event channels and io rings

Jun Nakajima (1):
xen: Introduce the Xen mapcache

Steven Smith (1):
xen: Add the Xen platform pci device

 Makefile.objs        |    3 +
 Makefile.target      |   16 ++-
 configure            |   71 ++++++-
 cpu-common.h         |    1 +
 exec.c               |   50 ++++-
 hw/hw.h              |    3 +
 hw/pc.c              |   19 ++-
 hw/pc.h              |    1 +
 hw/pc_piix.c         |   41 ++++-
 hw/pci_ids.h         |    2 +
 hw/piix_pci.c        |   47 ++++-
 hw/xen.h             |   41 ++++
 hw/xen_backend.c     |  422 ++++++++++++++++++++-----------------
 hw/xen_backend.h     |    6 +-
 hw/xen_common.h      |   75 ++++++--
 hw/xen_disk.c        |  496 +++++++++++++++++++++++--------------------
 hw/xen_domainbuild.c |   13 +-
 hw/xen_domainbuild.h |    5 +-
 hw/xen_machine_pv.c  |    2 +-
 hw/xen_nic.c         |  265 +++++++++++++-----------
 hw/xen_platform.c    |  349 ++++++++++++++++++++++++++++++
 sysemu.h             |    2 +
 trace-events         |    3 +
 vl.c                 |   12 +
 xen-all.c            |  573 ++++++++++++++++++++++++++++++++++++++++++++++++++
 xen-mapcache-stub.c  |   40 ++++
 xen-mapcache.c       |  344 ++++++++++++++++++++++++++++++
 xen-mapcache.h       |   22 ++
 xen-stub.c           |   45 ++++
 29 files changed, 2386 insertions(+), 583 deletions(-)
 create mode 100644 hw/xen_platform.c
 create mode 100644 xen-all.c
 create mode 100644 xen-mapcache-stub.c
 create mode 100644 xen-mapcache.c
 create mode 100644 xen-mapcache.h
 create mode 100644 xen-stub.c
Signature · 1 line
Anthony PERARD
#1 lore raw

PATCH v11 1/15 xen: Replace some tab-indents with spaces (clean-up).

From: Anthony PERARD <[email protected]>

And put braces for blocks with a single statement.

---
 hw/xen_backend.c |  411 +++++++++++++++++++++++++--------------------
 hw/xen_disk.c    |  492 +++++++++++++++++++++++++++++-------------------------
 hw/xen_nic.c     |  265 ++++++++++++++++--------------
 3 files changed, 634 insertions(+), 534 deletions(-)
hw/xen_backend.c +227 -184
index a2e408f..9f4ec4b 100644
@@ -58,8 +58,9 @@ int xenstore_write_str(const char *base, const char *node, const char *val)
     char abspath[XEN_BUFSIZE];
 
     snprintf(abspath, sizeof(abspath), "%s/%s", base, node);
-    if (!xs_write(xenstore, 0, abspath, val, strlen(val)))
-	return -1;
+    if (!xs_write(xenstore, 0, abspath, val, strlen(val))) {
+        return -1;
+    }
     return 0;
 }
 
@@ -94,8 +95,9 @@ int xenstore_read_int(const char *base, const char *node, int *ival)
     int rc = -1;
 
     val = xenstore_read_str(base, node);
-    if (val && 1 == sscanf(val, "%d", ival))
-	rc = 0;
+    if (val && 1 == sscanf(val, "%d", ival)) {
+        rc = 0;
+    }
     qemu_free(val);
     return rc;
 }
@@ -134,16 +136,16 @@ int xenstore_read_fe_int(struct XenDevice *xendev, const char *node, int *ival)
 
 const char *xenbus_strstate(enum xenbus_state state)
 {
-	static const char *const name[] = {
-		[ XenbusStateUnknown      ] = "Unknown",
-		[ XenbusStateInitialising ] = "Initialising",
-		[ XenbusStateInitWait     ] = "InitWait",
-		[ XenbusStateInitialised  ] = "Initialised",
-		[ XenbusStateConnected    ] = "Connected",
-		[ XenbusStateClosing      ] = "Closing",
-		[ XenbusStateClosed	  ] = "Closed",
-	};
-	return (state < ARRAY_SIZE(name)) ? name[state] : "INVALID";
+    static const char *const name[] = {
+        [ XenbusStateUnknown      ] = "Unknown",
+        [ XenbusStateInitialising ] = "Initialising",
+        [ XenbusStateInitWait     ] = "InitWait",
+        [ XenbusStateInitialised  ] = "Initialised",
+        [ XenbusStateConnected    ] = "Connected",
+        [ XenbusStateClosing      ] = "Closing",
+        [ XenbusStateClosed       ] = "Closed",
+    };
+    return (state < ARRAY_SIZE(name)) ? name[state] : "INVALID";
 }
 
 int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state)
@@ -151,10 +153,11 @@ int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state)
     int rc;
 
     rc = xenstore_write_be_int(xendev, "state", state);
-    if (rc < 0)
-	return rc;
+    if (rc < 0) {
+        return rc;
+    }
     xen_be_printf(xendev, 1, "backend state: %s -> %s\n",
-		  xenbus_strstate(xendev->be_state), xenbus_strstate(state));
+                  xenbus_strstate(xendev->be_state), xenbus_strstate(state));
     xendev->be_state = state;
     return 0;
 }
@@ -166,13 +169,16 @@ struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev)
     struct XenDevice *xendev;
 
     QTAILQ_FOREACH(xendev, &xendevs, next) {
-	if (xendev->dom != dom)
-	    continue;
-	if (xendev->dev != dev)
-	    continue;
-	if (strcmp(xendev->type, type) != 0)
-	    continue;
-	return xendev;
+        if (xendev->dom != dom) {
+            continue;
+        }
+        if (xendev->dev != dev) {
+            continue;
+        }
+        if (strcmp(xendev->type, type) != 0) {
+            continue;
+        }
+        return xendev;
     }
     return NULL;
 }
@@ -187,8 +193,9 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
     char *dom0;
 
     xendev = xen_be_find_xendev(type, dom, dev);
-    if (xendev)
-	return xendev;
+    if (xendev) {
+        return xendev;
+    }
 
     /* init new xendev */
     xendev = qemu_mallocz(ops->size);
@@ -199,9 +206,9 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
 
     dom0 = xs_get_domain_path(xenstore, 0);
     snprintf(xendev->be, sizeof(xendev->be), "%s/backend/%s/%d/%d",
-	     dom0, xendev->type, xendev->dom, xendev->dev);
+             dom0, xendev->type, xendev->dom, xendev->dev);
     snprintf(xendev->name, sizeof(xendev->name), "%s-%d",
-	     xendev->type, xendev->dev);
+             xendev->type, xendev->dev);
     free(dom0);
 
     xendev->debug      = debug;
@@ -209,28 +216,29 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
 
     xendev->evtchndev = xc_evtchn_open();
     if (xendev->evtchndev < 0) {
-	xen_be_printf(NULL, 0, "can't open evtchn device\n");
-	qemu_free(xendev);
-	return NULL;
+        xen_be_printf(NULL, 0, "can't open evtchn device\n");
+        qemu_free(xendev);
+        return NULL;
     }
     fcntl(xc_evtchn_fd(xendev->evtchndev), F_SETFD, FD_CLOEXEC);
 
     if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) {
-	xendev->gnttabdev = xc_gnttab_open();
-	if (xendev->gnttabdev < 0) {
-	    xen_be_printf(NULL, 0, "can't open gnttab device\n");
-	    xc_evtchn_close(xendev->evtchndev);
-	    qemu_free(xendev);
-	    return NULL;
-	}
+        xendev->gnttabdev = xc_gnttab_open();
+        if (xendev->gnttabdev < 0) {
+            xen_be_printf(NULL, 0, "can't open gnttab device\n");
+            xc_evtchn_close(xendev->evtchndev);
+            qemu_free(xendev);
+            return NULL;
+        }
     } else {
-	xendev->gnttabdev = -1;
+        xendev->gnttabdev = -1;
     }
 
     QTAILQ_INSERT_TAIL(&xendevs, xendev, next);
 
-    if (xendev->ops->alloc)
-	xendev->ops->alloc(xendev);
+    if (xendev->ops->alloc) {
+        xendev->ops->alloc(xendev);
+    }
 
     return xendev;
 }
@@ -251,28 +259,33 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev)
         xendev = xnext;
         xnext = xendev->next.tqe_next;
 
-	if (xendev->dom != dom)
-	    continue;
-	if (xendev->dev != dev && dev != -1)
-	    continue;
-
-	if (xendev->ops->free)
-	    xendev->ops->free(xendev);
-
-	if (xendev->fe) {
-	    char token[XEN_BUFSIZE];
-	    snprintf(token, sizeof(token), "fe:%p", xendev);
-	    xs_unwatch(xenstore, xendev->fe, token);
-	    qemu_free(xendev->fe);
-	}
-
-	if (xendev->evtchndev >= 0)
-	    xc_evtchn_close(xendev->evtchndev);
-	if (xendev->gnttabdev >= 0)
-	    xc_gnttab_close(xendev->gnttabdev);
-
-	QTAILQ_REMOVE(&xendevs, xendev, next);
-	qemu_free(xendev);
+        if (xendev->dom != dom) {
+            continue;
+        }
+        if (xendev->dev != dev && dev != -1) {
+            continue;
+        }
+
+        if (xendev->ops->free) {
+            xendev->ops->free(xendev);
+        }
+
+        if (xendev->fe) {
+            char token[XEN_BUFSIZE];
+            snprintf(token, sizeof(token), "fe:%p", xendev);
+            xs_unwatch(xenstore, xendev->fe, token);
+            qemu_free(xendev->fe);
+        }
+
+        if (xendev->evtchndev >= 0) {
+            xc_evtchn_close(xendev->evtchndev);
+        }
+        if (xendev->gnttabdev >= 0) {
+            xc_gnttab_close(xendev->gnttabdev);
+        }
+
+        QTAILQ_REMOVE(&xendevs, xendev, next);
+        qemu_free(xendev);
     }
     return NULL;
 }
@@ -285,14 +298,16 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev)
 static void xen_be_backend_changed(struct XenDevice *xendev, const char *node)
 {
     if (node == NULL  ||  strcmp(node, "online") == 0) {
-	if (xenstore_read_be_int(xendev, "online", &xendev->online) == -1)
-	    xendev->online = 0;
+        if (xenstore_read_be_int(xendev, "online", &xendev->online) == -1) {
+            xendev->online = 0;
+        }
     }
 
     if (node) {
-	xen_be_printf(xendev, 2, "backend update: %s\n", node);
-	if (xendev->ops->backend_changed)
-	    xendev->ops->backend_changed(xendev, node);
+        xen_be_printf(xendev, 2, "backend update: %s\n", node);
+        if (xendev->ops->backend_changed) {
+            xendev->ops->backend_changed(xendev, node);
+        }
     }
 }
 
@@ -301,25 +316,29 @@ static void xen_be_frontend_changed(struct XenDevice *xendev, const char *node)
     int fe_state;
 
     if (node == NULL  ||  strcmp(node, "state") == 0) {
-	if (xenstore_read_fe_int(xendev, "state", &fe_state) == -1)
-	    fe_state = XenbusStateUnknown;
-	if (xendev->fe_state != fe_state)
-	    xen_be_printf(xendev, 1, "frontend state: %s -> %s\n",
-			  xenbus_strstate(xendev->fe_state),
-			  xenbus_strstate(fe_state));
-	xendev->fe_state = fe_state;
+        if (xenstore_read_fe_int(xendev, "state", &fe_state) == -1) {
+            fe_state = XenbusStateUnknown;
+        }
+        if (xendev->fe_state != fe_state) {
+            xen_be_printf(xendev, 1, "frontend state: %s -> %s\n",
+                          xenbus_strstate(xendev->fe_state),
+                          xenbus_strstate(fe_state));
+        }
+        xendev->fe_state = fe_state;
     }
     if (node == NULL  ||  strcmp(node, "protocol") == 0) {
-	qemu_free(xendev->protocol);
-	xendev->protocol = xenstore_read_fe_str(xendev, "protocol");
-	if (xendev->protocol)
-	    xen_be_printf(xendev, 1, "frontend protocol: %s\n", xendev->protocol);
+        qemu_free(xendev->protocol);
+        xendev->protocol = xenstore_read_fe_str(xendev, "protocol");
+        if (xendev->protocol) {
+            xen_be_printf(xendev, 1, "frontend protocol: %s\n", xendev->protocol);
+        }
     }
 
     if (node) {
-	xen_be_printf(xendev, 2, "frontend update: %s\n", node);
-	if (xendev->ops->frontend_changed)
-	    xendev->ops->frontend_changed(xendev, node);
+        xen_be_printf(xendev, 2, "frontend update: %s\n", node);
+        if (xendev->ops->frontend_changed) {
+            xendev->ops->frontend_changed(xendev, node);
+        }
     }
 }
 
@@ -340,28 +359,28 @@ static int xen_be_try_setup(struct XenDevice *xendev)
     int be_state;
 
     if (xenstore_read_be_int(xendev, "state", &be_state) == -1) {
-	xen_be_printf(xendev, 0, "reading backend state failed\n");
-	return -1;
+        xen_be_printf(xendev, 0, "reading backend state failed\n");
+        return -1;
     }
 
     if (be_state != XenbusStateInitialising) {
-	xen_be_printf(xendev, 0, "initial backend state is wrong (%s)\n",
-		      xenbus_strstate(be_state));
-	return -1;
+        xen_be_printf(xendev, 0, "initial backend state is wrong (%s)\n",
+                      xenbus_strstate(be_state));
+        return -1;
     }
 
     xendev->fe = xenstore_read_be_str(xendev, "frontend");
     if (xendev->fe == NULL) {
-	xen_be_printf(xendev, 0, "reading frontend path failed\n");
-	return -1;
+        xen_be_printf(xendev, 0, "reading frontend path failed\n");
+        return -1;
     }
 
     /* setup frontend watch */
     snprintf(token, sizeof(token), "fe:%p", xendev);
     if (!xs_watch(xenstore, xendev->fe, token)) {
-	xen_be_printf(xendev, 0, "watching frontend path (%s) failed\n",
-		      xendev->fe);
-	return -1;
+        xen_be_printf(xendev, 0, "watching frontend path (%s) failed\n",
+                      xendev->fe);
+        return -1;
     }
     xen_be_set_state(xendev, XenbusStateInitialising);
 
@@ -383,15 +402,16 @@ static int xen_be_try_init(struct XenDevice *xendev)
     int rc = 0;
 
     if (!xendev->online) {
-	xen_be_printf(xendev, 1, "not online\n");
-	return -1;
+        xen_be_printf(xendev, 1, "not online\n");
+        return -1;
     }
 
-    if (xendev->ops->init)
-	rc = xendev->ops->init(xendev);
+    if (xendev->ops->init) {
+        rc = xendev->ops->init(xendev);
+    }
     if (rc != 0) {
-	xen_be_printf(xendev, 1, "init() failed\n");
-	return rc;
+        xen_be_printf(xendev, 1, "init() failed\n");
+        return rc;
     }
 
     xenstore_write_be_str(xendev, "hotplug-status", "connected");
@@ -411,20 +431,21 @@ static int xen_be_try_connect(struct XenDevice *xendev)
     int rc = 0;
 
     if (xendev->fe_state != XenbusStateInitialised  &&
-	xendev->fe_state != XenbusStateConnected) {
-	if (xendev->ops->flags & DEVOPS_FLAG_IGNORE_STATE) {
-	    xen_be_printf(xendev, 2, "frontend not ready, ignoring\n");
-	} else {
-	    xen_be_printf(xendev, 2, "frontend not ready (yet)\n");
-	    return -1;
-	}
+        xendev->fe_state != XenbusStateConnected) {
+        if (xendev->ops->flags & DEVOPS_FLAG_IGNORE_STATE) {
+            xen_be_printf(xendev, 2, "frontend not ready, ignoring\n");
+        } else {
+            xen_be_printf(xendev, 2, "frontend not ready (yet)\n");
+            return -1;
+        }
     }
 
-    if (xendev->ops->connect)
-	rc = xendev->ops->connect(xendev);
+    if (xendev->ops->connect) {
+        rc = xendev->ops->connect(xendev);
+    }
     if (rc != 0) {
-	xen_be_printf(xendev, 0, "connect() failed\n");
-	return rc;
+        xen_be_printf(xendev, 0, "connect() failed\n");
+        return rc;
     }
 
     xen_be_set_state(xendev, XenbusStateConnected);
@@ -440,10 +461,12 @@ static void xen_be_disconnect(struct XenDevice *xendev, enum xenbus_state state)
 {
     if (xendev->be_state != XenbusStateClosing &&
         xendev->be_state != XenbusStateClosed  &&
-        xendev->ops->disconnect)
-	xendev->ops->disconnect(xendev);
-    if (xendev->be_state != state)
+        xendev->ops->disconnect) {
+        xendev->ops->disconnect(xendev);
+    }
+    if (xendev->be_state != state) {
         xen_be_set_state(xendev, state);
+    }
 }
 
 /*
@@ -451,8 +474,9 @@ static void xen_be_disconnect(struct XenDevice *xendev, enum xenbus_state state)
  */
 static int xen_be_try_reset(struct XenDevice *xendev)
 {
-    if (xendev->fe_state != XenbusStateInitialising)
+    if (xendev->fe_state != XenbusStateInitialising) {
         return -1;
+    }
 
     xen_be_printf(xendev, 1, "device reset (for re-connect)\n");
     xen_be_set_state(xendev, XenbusStateInitialising);
@@ -468,31 +492,32 @@ void xen_be_check_state(struct XenDevice *xendev)
 
     /* frontend may request shutdown from almost anywhere */
     if (xendev->fe_state == XenbusStateClosing ||
-	xendev->fe_state == XenbusStateClosed) {
-	xen_be_disconnect(xendev, xendev->fe_state);
-	return;
+        xendev->fe_state == XenbusStateClosed) {
+        xen_be_disconnect(xendev, xendev->fe_state);
+        return;
     }
 
     /* check for possible backend state transitions */
     for (;;) {
-	switch (xendev->be_state) {
-	case XenbusStateUnknown:
-	    rc = xen_be_try_setup(xendev);
-	    break;
-	case XenbusStateInitialising:
-	    rc = xen_be_try_init(xendev);
-	    break;
-	case XenbusStateInitWait:
-	    rc = xen_be_try_connect(xendev);
-	    break;
+        switch (xendev->be_state) {
+        case XenbusStateUnknown:
+            rc = xen_be_try_setup(xendev);
+            break;
+        case XenbusStateInitialising:
+            rc = xen_be_try_init(xendev);
+            break;
+        case XenbusStateInitWait:
+            rc = xen_be_try_connect(xendev);
+            break;
         case XenbusStateClosed:
             rc = xen_be_try_reset(xendev);
             break;
-	default:
-	    rc = -1;
-	}
-	if (rc != 0)
-	    break;
+        default:
+            rc = -1;
+        }
+        if (rc != 0) {
+            break;
+        }
     }
 }
 
@@ -511,26 +536,28 @@ static int xenstore_scan(const char *type, int dom, struct XenDevOps *ops)
     snprintf(path, sizeof(path), "%s/backend/%s/%d", dom0, type, dom);
     free(dom0);
     if (!xs_watch(xenstore, path, token)) {
-	xen_be_printf(NULL, 0, "xen be: watching backend path (%s) failed\n", path);
-	return -1;
+        xen_be_printf(NULL, 0, "xen be: watching backend path (%s) failed\n", path);
+        return -1;
     }
 
     /* look for backends */
     dev = xs_directory(xenstore, 0, path, &cdev);
-    if (!dev)
-	return 0;
+    if (!dev) {
+        return 0;
+    }
     for (j = 0; j < cdev; j++) {
-	xendev = xen_be_get_xendev(type, dom, atoi(dev[j]), ops);
-	if (xendev == NULL)
-	    continue;
-	xen_be_check_state(xendev);
+        xendev = xen_be_get_xendev(type, dom, atoi(dev[j]), ops);
+        if (xendev == NULL) {
+            continue;
+        }
+        xen_be_check_state(xendev);
     }
     free(dev);
     return 0;
 }
 
 static void xenstore_update_be(char *watch, char *type, int dom,
-			       struct XenDevOps *ops)
+                               struct XenDevOps *ops)
 {
     struct XenDevice *xendev;
     char path[XEN_BUFSIZE], *dom0;
@@ -539,25 +566,28 @@ static void xenstore_update_be(char *watch, char *type, int dom,
     dom0 = xs_get_domain_path(xenstore, 0);
     len = snprintf(path, sizeof(path), "%s/backend/%s/%d", dom0, type, dom);
     free(dom0);
-    if (strncmp(path, watch, len) != 0)
-	return;
+    if (strncmp(path, watch, len) != 0) {
+        return;
+    }
     if (sscanf(watch+len, "/%u/%255s", &dev, path) != 2) {
-	strcpy(path, "");
-	if (sscanf(watch+len, "/%u", &dev) != 1)
-	    dev = -1;
+        strcpy(path, "");
+        if (sscanf(watch+len, "/%u", &dev) != 1) {
+            dev = -1;
+        }
+    }
+    if (dev == -1) {
+        return;
     }
-    if (dev == -1)
-	return;
 
     if (0) {
-	/* FIXME: detect devices being deleted from xenstore ... */
-	xen_be_del_xendev(dom, dev);
+        /* FIXME: detect devices being deleted from xenstore ... */
+        xen_be_del_xendev(dom, dev);
     }
 
     xendev = xen_be_get_xendev(type, dom, dev, ops);
     if (xendev != NULL) {
-	xen_be_backend_changed(xendev, path);
-	xen_be_check_state(xendev);
+        xen_be_backend_changed(xendev, path);
+        xen_be_check_state(xendev);
     }
 }
 
@@ -567,10 +597,12 @@ static void xenstore_update_fe(char *watch, struct XenDevice *xendev)
     unsigned int len;
 
     len = strlen(xendev->fe);
-    if (strncmp(xendev->fe, watch, len) != 0)
-	return;
-    if (watch[len] != '/')
-	return;
+    if (strncmp(xendev->fe, watch, len) != 0) {
+        return;
+    }
+    if (watch[len] != '/') {
+        return;
+    }
     node = watch + len + 1;
 
     xen_be_frontend_changed(xendev, node);
@@ -584,14 +616,17 @@ static void xenstore_update(void *unused)
     unsigned int dom, count;
 
     vec = xs_read_watch(xenstore, &count);
-    if (vec == NULL)
-	goto cleanup;
+    if (vec == NULL) {
+        goto cleanup;
+    }
 
     if (sscanf(vec[XS_WATCH_TOKEN], "be:%" PRIxPTR ":%d:%" PRIxPTR,
-               &type, &dom, &ops) == 3)
-	xenstore_update_be(vec[XS_WATCH_PATH], (void*)type, dom, (void*)ops);
-    if (sscanf(vec[XS_WATCH_TOKEN], "fe:%" PRIxPTR, &ptr) == 1)
-	xenstore_update_fe(vec[XS_WATCH_PATH], (void*)ptr);
+               &type, &dom, &ops) == 3) {
+        xenstore_update_be(vec[XS_WATCH_PATH], (void*)type, dom, (void*)ops);
+    }
+    if (sscanf(vec[XS_WATCH_TOKEN], "fe:%" PRIxPTR, &ptr) == 1) {
+        xenstore_update_fe(vec[XS_WATCH_PATH], (void*)ptr);
+    }
 
 cleanup:
     free(vec);
@@ -604,14 +639,15 @@ static void xen_be_evtchn_event(void *opaque)
 
     port = xc_evtchn_pending(xendev->evtchndev);
     if (port != xendev->local_port) {
-	xen_be_printf(xendev, 0, "xc_evtchn_pending returned %d (expected %d)\n",
-		      port, xendev->local_port);
-	return;
+        xen_be_printf(xendev, 0, "xc_evtchn_pending returned %d (expected %d)\n",
+                      port, xendev->local_port);
+        return;
     }
     xc_evtchn_unmask(xendev->evtchndev, port);
 
-    if (xendev->ops->event)
-	xendev->ops->event(xendev);
+    if (xendev->ops->event) {
+        xendev->ops->event(xendev);
+    }
 }
 
 /* -------------------------------------------------------------------- */
@@ -620,17 +656,18 @@ int xen_be_init(void)
 {
     xenstore = xs_daemon_open();
     if (!xenstore) {
-	xen_be_printf(NULL, 0, "can't connect to xenstored\n");
-	return -1;
+        xen_be_printf(NULL, 0, "can't connect to xenstored\n");
+        return -1;
     }
 
-    if (qemu_set_fd_handler(xs_fileno(xenstore), xenstore_update, NULL, NULL) < 0)
-	goto err;
+    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_be_printf(NULL, 0, "can't open xen interface\n");
-	goto err;
+        xen_be_printf(NULL, 0, "can't open xen interface\n");
+        goto err;
     }
     return 0;
 
@@ -649,24 +686,26 @@ int xen_be_register(const char *type, struct XenDevOps *ops)
 
 int xen_be_bind_evtchn(struct XenDevice *xendev)
 {
-    if (xendev->local_port != -1)
-	return 0;
+    if (xendev->local_port != -1) {
+        return 0;
+    }
     xendev->local_port = xc_evtchn_bind_interdomain
-	(xendev->evtchndev, xendev->dom, xendev->remote_port);
+        (xendev->evtchndev, xendev->dom, xendev->remote_port);
     if (xendev->local_port == -1) {
-	xen_be_printf(xendev, 0, "xc_evtchn_bind_interdomain failed\n");
-	return -1;
+        xen_be_printf(xendev, 0, "xc_evtchn_bind_interdomain failed\n");
+        return -1;
     }
     xen_be_printf(xendev, 2, "bind evtchn port %d\n", xendev->local_port);
     qemu_set_fd_handler(xc_evtchn_fd(xendev->evtchndev),
-			xen_be_evtchn_event, NULL, xendev);
+                        xen_be_evtchn_event, NULL, xendev);
     return 0;
 }
 
 void xen_be_unbind_evtchn(struct XenDevice *xendev)
 {
-    if (xendev->local_port == -1)
-	return;
+    if (xendev->local_port == -1) {
+        return;
+    }
     qemu_set_fd_handler(xc_evtchn_fd(xendev->evtchndev), NULL, NULL, NULL);
     xc_evtchn_unbind(xendev->evtchndev, xendev->local_port);
     xen_be_printf(xendev, 2, "unbind evtchn port %d\n", xendev->local_port);
@@ -690,17 +729,21 @@ void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ...
     va_list args;
 
     if (xendev) {
-        if (msg_level > xendev->debug)
+        if (msg_level > xendev->debug) {
             return;
+        }
         qemu_log("xen be: %s: ", xendev->name);
-        if (msg_level == 0)
+        if (msg_level == 0) {
             fprintf(stderr, "xen be: %s: ", xendev->name);
+        }
     } else {
-        if (msg_level > debug)
+        if (msg_level > debug) {
             return;
+        }
         qemu_log("xen be core: ");
-        if (msg_level == 0)
+        if (msg_level == 0) {
             fprintf(stderr, "xen be core: ");
+        }
     }
     va_start(args, fmt);
     qemu_log_vprintf(fmt, args);
hw/xen_disk.c +265 -227

755 lines not on this page · raw message

hw/xen_nic.c +142 -123

391 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#2 lore raw

PATCH v11 2/15 xen: Make Xen build once.

In reply to [email protected]

From: Anthony PERARD <[email protected]>

xen_domainbuild is now build in libhw. And xen_machine_pv is build only for i386 targets.

---
 Makefile.objs        |    3 +++
 Makefile.target      |    2 +-
 hw/xen_domainbuild.c |   10 +++++-----
 hw/xen_domainbuild.h |    5 +++--
 hw/xen_machine_pv.c  |    2 +-
 5 files changed, 13 insertions(+), 9 deletions(-)
Makefile.objs +3 -0
index 9e98a66..8034115 100644
@@ -269,6 +269,9 @@ hw-obj-$(CONFIG_DP8393X) += dp8393x.o
 hw-obj-$(CONFIG_DS1225Y) += ds1225y.o
 hw-obj-$(CONFIG_MIPSNET) += mipsnet.o
 
+# Xen
+hw-obj-$(CONFIG_XEN) += xen_domainbuild.o
+
 # Sound
 sound-obj-y =
 sound-obj-$(CONFIG_SB16) += sb16.o
Makefile.target +1 -1
index 220589e..ab0a570 100644
@@ -206,7 +206,7 @@ QEMU_CFLAGS += $(VNC_JPEG_CFLAGS)
 QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
 
 # xen backend driver support
-obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
+obj-i386-$(CONFIG_XEN) += xen_machine_pv.o
 
 # Inter-VM PCI shared memory
 obj-$(CONFIG_KVM) += ivshmem.o
hw/xen_domainbuild.c +5 -5
index 7f1fd66..b73d47f 100644
@@ -1,9 +1,9 @@
 #include <signal.h>
-#include "xen_backend.h"
-#include "xen_domainbuild.h"
 #include "sysemu.h"
 #include "qemu-timer.h"
 #include "qemu-log.h"
+#include "xen_backend.h"
+#include "xen_domainbuild.h"
 
 #include <xenguest.h>
 
@@ -49,7 +49,7 @@ static int xenstore_domain_mkdir(char *path)
 }
 
 int xenstore_domain_init1(const char *kernel, const char *ramdisk,
-                          const char *cmdline)
+                          const char *cmdline, ram_addr_t ram_size)
 {
     char *dom, uuid_string[42], vm[256], path[256];
     int i;
@@ -225,7 +225,7 @@ static void xen_domain_cleanup(void)
 }
 
 int xen_domain_build_pv(const char *kernel, const char *ramdisk,
-                        const char *cmdline)
+                        const char *cmdline, ram_addr_t ram_size)
 {
     uint32_t ssidref = 0;
     uint32_t flags = 0;
@@ -246,7 +246,7 @@ int xen_domain_build_pv(const char *kernel, const char *ramdisk,
         goto err;
     }
 
-    xenstore_domain_init1(kernel, ramdisk, cmdline);
+    xenstore_domain_init1(kernel, ramdisk, cmdline, ram_size);
 
     rc = xc_domain_max_vcpus(xen_xc, xen_domid, smp_cpus);
     if (rc < 0) {
hw/xen_domainbuild.h +3 -2
index dea0121..49683f8 100644
@@ -1,13 +1,14 @@
 #ifndef QEMU_HW_XEN_DOMAINBUILD_H
 #define QEMU_HW_XEN_DOMAINBUILD_H 1
 
+#include "cpu-common.h"
 #include "xen_common.h"
 
 int xenstore_domain_init1(const char *kernel, const char *ramdisk,
-                          const char *cmdline);
+                          const char *cmdline, ram_addr_t ram_size);
 int xenstore_domain_init2(int xenstore_port, int xenstore_mfn,
                           int console_port, int console_mfn);
 int xen_domain_build_pv(const char *kernel, const char *ramdisk,
-                        const char *cmdline);
+                        const char *cmdline, ram_addr_t ram_size);
 
 #endif /* QEMU_HW_XEN_DOMAINBUILD_H */
hw/xen_machine_pv.c +1 -1
index 77a34bf..d0e6e8f 100644
@@ -64,7 +64,7 @@ static void xen_init_pv(ram_addr_t ram_size,
         break;
     case XEN_CREATE:
         if (xen_domain_build_pv(kernel_filename, initrd_filename,
-                                kernel_cmdline) < 0) {
+                                kernel_cmdline, ram_size) < 0) {
             fprintf(stderr, "xen pv domain creation failed\n");
             exit(1);
         }
Signature · 1 line
1.7.2.3
#3 lore raw

Re: [Qemu-devel] [PATCH V11 02/15] xen: Make Xen build once.

Quoted 22 lines · On 01.03.2011, at 19:35, [email protected] wrote:

From: Anthony PERARD <[email protected]>

xen_domainbuild is now build in libhw. And xen_machine_pv is build only for i386 targets.

---

Makefile.objs        |    3 +++
Makefile.target      |    2 +-
hw/xen_domainbuild.c |   10 +++++-----
hw/xen_domainbuild.h |    5 +++--
hw/xen_machine_pv.c  |    2 +-
5 files changed, 13 insertions(+), 9 deletions(-)
Makefile.objs +0 -0
index 9e98a66..8034115 100644
@@ -269,6 +269,9 @@ hw-obj-$(CONFIG_DP8393X) += dp8393x.o

hw-obj-$(CONFIG_DS1225Y) += ds1225y.o
hw-obj-$(CONFIG_MIPSNET) += mipsnet.o

Makefile.objs hw-obj-$(CONFIG_DP8393X) += dp8393x.o · line 273

Quoted 2 lines
Makefile.objs +2 -0
+# Xen
+hw-obj-$(CONFIG_XEN) += xen_domainbuild.o

Why is this in generic code? Xen is x86 only and really should stay that way IMHO.

Quoted 34 lines

+
# Sound
sound-obj-y =
sound-obj-$(CONFIG_SB16) += sb16.o

Makefile.target +1 -1
index 220589e..ab0a570 100644
@@ -206,7 +206,7 @@ QEMU_CFLAGS += $(VNC_JPEG_CFLAGS)
 QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
 
 # xen backend driver support
-obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
+obj-i386-$(CONFIG_XEN) += xen_machine_pv.o
 
 # Inter-VM PCI shared memory

obj-$(CONFIG_KVM) += ivshmem.o

hw/xen_domainbuild.c +2 -2
index 7f1fd66..b73d47f 100644
@@ -1,9 +1,9 @@
 #include <signal.h>
-#include "xen_backend.h"
-#include "xen_domainbuild.h"
 #include "sysemu.h"
 #include "qemu-timer.h"
 #include "qemu-log.h"
+#include "xen_backend.h"
+#include "xen_domainbuild.h"
 
 #include <xenguest.h>
 

hw/xen_domainbuild.c static int xenstore_domain_mkdir(char *path) · line 52

Quoted 5 lines
hw/xen_domainbuild.c +1 -1
@@ -49,7 +49,7 @@ static int xenstore_domain_mkdir(char *path)
 }
 
 int xenstore_domain_init1(const char *kernel, const char *ramdisk,
-                          const char *cmdline)
+                          const char *cmdline, ram_addr_t ram_size)

Isn't ram_size a global anyways? What's the rationale behind moving it to a parameter? Not saying I'm against it, just missed the reasoning here :)

Alex

#4 lore raw

Re: [Xen-devel] Re: [Qemu-devel] [PATCH V11 02/15] xen: Make Xen build once.

Quoted 25 lines · Alexander Graf
Quoted 22 lines · On 01.03.2011, at 19:35, [email protected] wrote:

From: Anthony PERARD <[email protected]>

xen_domainbuild is now build in libhw. And xen_machine_pv is build only for i386 targets.

---
Makefile.objs        |    3 +++ Makefile.target      |    2 +- hw/xen_domainbuild.c |   10 +++++----- hw/xen_domainbuild.h |    5 +++-- hw/xen_machine_pv.c  |    2 +-

5 files changed, 13 insertions(+), 9 deletions(-)
Makefile.objs +0 -0
index 9e98a66..8034115 100644
@@ -269,6 +269,9 @@ hw-obj-$(CONFIG_DP8393X) += dp8393x.o

hw-obj-$(CONFIG_DS1225Y) += ds1225y.o hw-obj-$(CONFIG_MIPSNET) += mipsnet.o

Quoted 4 lines

Makefile.objs hw-obj-$(CONFIG_DP8393X) += dp8393x.o · line 273

Quoted 2 lines
Makefile.objs +2 -0
+# Xen
+hw-obj-$(CONFIG_XEN) += xen_domainbuild.o

Why is this in generic code? Xen is x86 only and really should stay that way IMHO.

I just try to build more object globally to avoid unnecessary i386-isms.

Quoted 33 lines
Quoted 33 lines

+
# Sound
sound-obj-y = sound-obj-$(CONFIG_SB16) += sb16.o

Makefile.target +1 -1
index 220589e..ab0a570 100644
@@ -206,7 +206,7 @@ QEMU_CFLAGS += $(VNC_JPEG_CFLAGS)
 QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
 
 # xen backend driver support
-obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
+obj-i386-$(CONFIG_XEN) += xen_machine_pv.o
 
 # Inter-VM PCI shared memory

obj-$(CONFIG_KVM) += ivshmem.o

hw/xen_domainbuild.c +2 -2
index 7f1fd66..b73d47f 100644
@@ -1,9 +1,9 @@
 #include <signal.h>
-#include "xen_backend.h"
-#include "xen_domainbuild.h"
 #include "sysemu.h"
 #include "qemu-timer.h"
 #include "qemu-log.h"
+#include "xen_backend.h"
+#include "xen_domainbuild.h"
 
 #include <xenguest.h>
 
Quoted 8 lines

hw/xen_domainbuild.c static int xenstore_domain_mkdir(char *path) · line 52

Quoted 6 lines
hw/xen_domainbuild.c +1 -1
@@ -49,7 +49,7 @@ static int xenstore_domain_mkdir(char *path)
 }
 
 int xenstore_domain_init1(const char *kernel, const char *ramdisk,
-                          const char *cmdline)
+                          const char *cmdline, ram_addr_t ram_size)

Isn't ram_size a global anyways? What's the rationale behind moving it to a parameter? Not saying I'm against it, just missed the reasoning here :)

I put ram_size in a parameter because I don't found a way to access to is global variable, and also because in these function, ram_size is read only.

So, I can just remove this patch and just put both xen_machine_pv xen_domainbuild in obj-i386-y.

Regards,

Signature · 1 line
Anthony PERARD
#5 lore raw

Re: [Xen-devel] Re: [Qemu-devel] [PATCH V11 02/15] xen: Make Xen build once.

Quoted 70 lines · Anthony PERARD
Quoted 24 lines · Alexander Graf
Quoted 22 lines · On 01.03.2011, at 19:35, [email protected] wrote:

From: Anthony PERARD<[email protected]>

xen_domainbuild is now build in libhw. And xen_machine_pv is build only for i386 targets.

---

Makefile.objs        |    3 +++
Makefile.target      |    2 +-
hw/xen_domainbuild.c |   10 +++++-----
hw/xen_domainbuild.h |    5 +++--
hw/xen_machine_pv.c  |    2 +-
5 files changed, 13 insertions(+), 9 deletions(-)
Makefile.objs +0 -0
index 9e98a66..8034115 100644
@@ -269,6 +269,9 @@ hw-obj-$(CONFIG_DP8393X) += dp8393x.o

hw-obj-$(CONFIG_DS1225Y) += ds1225y.o
hw-obj-$(CONFIG_MIPSNET) += mipsnet.o

Quoted 3 lines

Makefile.objs hw-obj-$(CONFIG_DP8393X) += dp8393x.o · line 273

Quoted 2 lines
Makefile.objs +2 -0
+# Xen
+hw-obj-$(CONFIG_XEN) += xen_domainbuild.o

Why is this in generic code? Xen is x86 only and really should stay that way IMHO.

I just try to build more object globally to avoid unnecessary i386-isms.

Quoted 33 lines
Quoted 33 lines

+
# Sound
sound-obj-y =
sound-obj-$(CONFIG_SB16) += sb16.o

Makefile.target +1 -1
index 220589e..ab0a570 100644
@@ -206,7 +206,7 @@ QEMU_CFLAGS += $(VNC_JPEG_CFLAGS)
 QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
 
 # xen backend driver support
-obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
+obj-i386-$(CONFIG_XEN) += xen_machine_pv.o
 
 # Inter-VM PCI shared memory

obj-$(CONFIG_KVM) += ivshmem.o

hw/xen_domainbuild.c +2 -2
index 7f1fd66..b73d47f 100644
@@ -1,9 +1,9 @@
 #include<signal.h>
-#include "xen_backend.h"
-#include "xen_domainbuild.h"
 #include "sysemu.h"
 #include "qemu-timer.h"
 #include "qemu-log.h"
+#include "xen_backend.h"
+#include "xen_domainbuild.h"
 
 #include<xenguest.h>
 
Quoted 7 lines

hw/xen_domainbuild.c static int xenstore_domain_mkdir(char *path) · line 52

Quoted 6 lines
hw/xen_domainbuild.c +1 -1
@@ -49,7 +49,7 @@ static int xenstore_domain_mkdir(char *path)
 }
 
 int xenstore_domain_init1(const char *kernel, const char *ramdisk,
-                          const char *cmdline)
+                          const char *cmdline, ram_addr_t ram_size)

Isn't ram_size a global anyways? What's the rationale behind moving it to a parameter? Not saying I'm against it, just missed the reasoning here :)

Quoted 6 lines

I put ram_size in a parameter because I don't found a way to access to is global variable, and also because in these function, ram_size is read only.

So, I can just remove this patch and just put both xen_machine_pv xen_domainbuild in obj-i386-y.

Sounds good to me. No need to build stuff generically that won't be used generically :).

Alex

#6 lore raw

PATCH v11 3/15 xen: Support new libxc calls from xen unstable.

In reply to [email protected]

From: Anthony PERARD <[email protected]>

This patch updates 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 check libxenctrl version in configure, from Xen 3.3.0 to Xen unstable.

---
 configure            |   67 ++++++++++++++++++++++++++++++++++++++++++++++++-
 hw/xen_backend.c     |   21 ++++++++-------
 hw/xen_backend.h     |    6 ++--
 hw/xen_common.h      |   64 +++++++++++++++++++++++++++++++++++++----------
 hw/xen_disk.c        |    4 +-
 hw/xen_domainbuild.c |    3 +-
 6 files changed, 133 insertions(+), 32 deletions(-)
configure +65 -2
index 3036faf..a84d974 100755
@@ -126,6 +126,7 @@ vnc_jpeg=""
 vnc_png=""
 vnc_thread="no"
 xen=""
+xen_ctrl_version=""
 linux_aio=""
 attr=""
 vhost_net=""
@@ -1147,20 +1148,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 = xc_interface_open(0, 0, 0);
+  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
+  xc_gnttab_open(NULL, 0);
+  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
 
 ##########################################
@@ -2755,6 +2817,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
hw/xen_backend.c +11 -10
index 9f4ec4b..3907b83 100644
@@ -43,7 +43,8 @@
 /* ------------------------------------------------------------- */
 
 /* public */
-int xen_xc;
+XenXC xen_xc = XC_HANDLER_INITIAL_VALUE;
+XenGnttab xen_xcg = XC_HANDLER_INITIAL_VALUE;
 struct xs_handle *xenstore = NULL;
 const char *xen_protocol;
 
@@ -214,8 +215,8 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
     xendev->debug      = debug;
     xendev->local_port = -1;
 
-    xendev->evtchndev = xc_evtchn_open();
-    if (xendev->evtchndev < 0) {
+    xendev->evtchndev = xc_evtchn_open(NULL, 0);
+    if (xendev->evtchndev == XC_HANDLER_INITIAL_VALUE) {
         xen_be_printf(NULL, 0, "can't open evtchn device\n");
         qemu_free(xendev);
         return NULL;
@@ -223,15 +224,15 @@ 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();
-        if (xendev->gnttabdev < 0) {
+        xendev->gnttabdev = xc_gnttab_open(NULL, 0);
+        if (xendev->gnttabdev == XC_HANDLER_INITIAL_VALUE) {
             xen_be_printf(NULL, 0, "can't open gnttab device\n");
             xc_evtchn_close(xendev->evtchndev);
             qemu_free(xendev);
             return NULL;
         }
     } else {
-        xendev->gnttabdev = -1;
+        xendev->gnttabdev = XC_HANDLER_INITIAL_VALUE;
     }
 
     QTAILQ_INSERT_TAIL(&xendevs, xendev, next);
@@ -277,10 +278,10 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev)
             qemu_free(xendev->fe);
         }
 
-        if (xendev->evtchndev >= 0) {
+        if (xendev->evtchndev != XC_HANDLER_INITIAL_VALUE) {
             xc_evtchn_close(xendev->evtchndev);
         }
-        if (xendev->gnttabdev >= 0) {
+        if (xendev->gnttabdev != XC_HANDLER_INITIAL_VALUE) {
             xc_gnttab_close(xendev->gnttabdev);
         }
 
@@ -664,8 +665,8 @@ int xen_be_init(void)
         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;
     }
hw/xen_backend.h +3 -3
index 1b428e3..6401c85 100644
@@ -45,8 +45,8 @@ struct XenDevice {
     int                remote_port;
     int                local_port;
 
-    int                evtchndev;
-    int                gnttabdev;
+    XenEvtchn          evtchndev;
+    XenGnttab          gnttabdev;
 
     struct XenDevOps   *ops;
     QTAILQ_ENTRY(XenDevice) next;
@@ -55,7 +55,7 @@ struct XenDevice {
 /* ------------------------------------------------------------- */
 
 /* variables */
-extern int xen_xc;
+extern XenXC xen_xc;
 extern struct xs_handle *xenstore;
 extern const char *xen_protocol;
 
hw/xen_common.h +50 -14

78 lines not on this page · raw message

hw/xen_disk.c +2 -2
index 403c55f..07b8ec4 100644
@@ -242,7 +242,7 @@ err:
 
 static void ioreq_unmap(struct ioreq *ioreq)
 {
-    int gnt = ioreq->blkdev->xendev.gnttabdev;
+    XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev;
     int i;
 
     if (ioreq->v.niov == 0) {
@@ -275,7 +275,7 @@ static void ioreq_unmap(struct ioreq *ioreq)
 
 static int ioreq_map(struct ioreq *ioreq)
 {
-    int gnt = ioreq->blkdev->xendev.gnttabdev;
+    XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev;
     int i;
 
     if (ioreq->v.niov == 0) {
hw/xen_domainbuild.c +2 -1
index b73d47f..57fb4f0 100644
@@ -176,8 +176,9 @@ 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);
     }
 
Signature · 1 line
1.7.2.3
#7 lore raw

Re: [Qemu-devel] [PATCH V11 03/15] xen: Support new libxc calls from xen unstable.

Quoted 266 lines · On 01.03.2011, at 19:35, [email protected] wrote:

From: Anthony PERARD <[email protected]>

This patch updates 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 check libxenctrl version in configure, from Xen 3.3.0 to Xen unstable.

---

configure            |   67 ++++++++++++++++++++++++++++++++++++++++++++++++-
hw/xen_backend.c     |   21 ++++++++-------
hw/xen_backend.h     |    6 ++--
hw/xen_common.h      |   64 +++++++++++++++++++++++++++++++++++++----------
hw/xen_disk.c        |    4 +-
hw/xen_domainbuild.c |    3 +-
6 files changed, 133 insertions(+), 32 deletions(-)
configure +0 -0
index 3036faf..a84d974 100755
@@ -126,6 +126,7 @@ vnc_jpeg=""

vnc_png=""
vnc_thread="no"
xen=""
+xen_ctrl_version=""
linux_aio=""
attr=""
vhost_net=""

configure +0 -0
@@ -1147,20 +1148,81 @@ fi
 

if test "$xen" != "no" ; then
xen_libs="-lxenstore -lxenctrl -lxenguest"

configure +2 -0
+
+  # Xen unstable
  cat > $TMPC <<EOF

#include <xenctrl.h>
#include <xs.h>

configure +13 -1
-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 = xc_interface_open(0, 0, 0);
+  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
+  xc_gnttab_open(NULL, 0);
+  return 0;
+}

EOF
if compile_prog "" "$xen_libs" ; then

configure +48 -1
+    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

##########################################

configure +0 -0
@@ -2755,6 +2817,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

hw/xen_backend.c +11 -10
index 9f4ec4b..3907b83 100644
@@ -43,7 +43,8 @@
 /* ------------------------------------------------------------- */
 
 /* public */
-int xen_xc;
+XenXC xen_xc = XC_HANDLER_INITIAL_VALUE;
+XenGnttab xen_xcg = XC_HANDLER_INITIAL_VALUE;
 struct xs_handle *xenstore = NULL;
 const char *xen_protocol;
 
@@ -214,8 +215,8 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
    xendev->debug      = debug;
    xendev->local_port = -1;
 
-    xendev->evtchndev = xc_evtchn_open();
-    if (xendev->evtchndev < 0) {
+    xendev->evtchndev = xc_evtchn_open(NULL, 0);
+    if (xendev->evtchndev == XC_HANDLER_INITIAL_VALUE) {
        xen_be_printf(NULL, 0, "can't open evtchn device\n");
        qemu_free(xendev);
        return NULL;
@@ -223,15 +224,15 @@ 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();
-        if (xendev->gnttabdev < 0) {
+        xendev->gnttabdev = xc_gnttab_open(NULL, 0);
+        if (xendev->gnttabdev == XC_HANDLER_INITIAL_VALUE) {
            xen_be_printf(NULL, 0, "can't open gnttab device\n");
            xc_evtchn_close(xendev->evtchndev);
            qemu_free(xendev);
            return NULL;
        }
    } else {
-        xendev->gnttabdev = -1;
+        xendev->gnttabdev = XC_HANDLER_INITIAL_VALUE;
    }
 
    QTAILQ_INSERT_TAIL(&xendevs, xendev, next);
@@ -277,10 +278,10 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev)
            qemu_free(xendev->fe);
        }
 
-        if (xendev->evtchndev >= 0) {
+        if (xendev->evtchndev != XC_HANDLER_INITIAL_VALUE) {
            xc_evtchn_close(xendev->evtchndev);
        }
-        if (xendev->gnttabdev >= 0) {
+        if (xendev->gnttabdev != XC_HANDLER_INITIAL_VALUE) {
            xc_gnttab_close(xendev->gnttabdev);
        }
 
@@ -664,8 +665,8 @@ int xen_be_init(void)
        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;
    }
hw/xen_backend.h +3 -3
index 1b428e3..6401c85 100644
@@ -45,8 +45,8 @@ struct XenDevice {
    int                remote_port;
    int                local_port;
 
-    int                evtchndev;
-    int                gnttabdev;
+    XenEvtchn          evtchndev;
+    XenGnttab          gnttabdev;
 
    struct XenDevOps   *ops;
    QTAILQ_ENTRY(XenDevice) next;
@@ -55,7 +55,7 @@ struct XenDevice {
 /* ------------------------------------------------------------- */
 
 /* variables */
-extern int xen_xc;
+extern XenXC xen_xc;
 extern struct xs_handle *xenstore;
 extern const char *xen_protocol;
 
hw/xen_common.h +18 -14
index 8a55b44..7e123ec 100644
@@ -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,56 @@
 #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
+
+/* Xen before 4.0 */
+#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 400
+static inline void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
+                                        xen_pfn_t *arr, int *err,
+                                        unsigned int num)
+{
+    return xc_map_foreign_batch(xc_handle, dom, prot, arr, num);
+}
 #endif
-#if __XEN_LATEST_INTERFACE_VERSION__ < 0x00030208
-# define xen_mb()  mb()
-# define xen_rmb() rmb()
-# define xen_wmb() wmb()
+
+
+/* Xen before 4.1 */
+#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
+
+typedef int XenXC;

hw/xen_common.h line 45

Quoted 10 lines
hw/xen_common.h +10 -0
+typedef int XenEvtchn;
+typedef int XenGnttab;
+
+#  define XC_INTERFACE_FMT "%i"
+#  define XC_HANDLER_INITIAL_VALUE    -1
+
+#  define xc_interface_open(logger, dombuild_logger, open_flags) \
+    xc_interface_open()
+#  define xc_evtchn_open(logger, open_flags) xc_evtchn_open()
+#  define xc_gnttab_open(logger, open_flags) xc_gnttab_open()

defines really bite me when abstracting the interface through an indirect calling table. I had to change the code this way to make it work with xenner:

hw/xen_common.h +35 -4
index a5fc74b..0c09b37 100644
@@ -39,10 +39,23 @@ typedef int XenGnttab;
 #  define XC_INTERFACE_FMT "%i"
 #  define XC_HANDLER_INITIAL_VALUE    -1
 
-#  define xc_interface_open(logger, dombuild_logger, open_flags) \
-    xc_interface_open()
-#  define xc_evtchn_open(logger, open_flags) xc_evtchn_open()
-#  define xc_gnttab_open(logger, open_flags) xc_gnttab_open()
+static inline XenEvtchn xen_xc_evtchn_open(void *logger,
+                                           unsigned int open_flags)
+{
+    return xc_evtchn_open();
+}
+
+static inline XenGnttab xen_xc_gnttab_open(void *logger,
+                                           unsigned int open_flags)
+{
+    return xc_gnttab_open();
+}
+
+static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
+                                          unsigned int open_flags)
+{
+    return xc_interface_open();
+}
 
 static inline int xc_fd(int xen_xc)
 {
@@ -69,6 +82,24 @@ typedef xc_gnttab *XenGnttab;
 #  define XC_INTERFACE_FMT "%p"
 #  define XC_HANDLER_INITIAL_VALUE    NULL
 
+static inline XenEvtchn xen_xc_evtchn_open(void *logger,
+                                           unsigned int open_flags)
+{
+    return xc_evtchn_open(logger, open_flags);
+}
+
+static inline XenGnttab xen_xc_gnttab_open(void *logger,
+                                           unsigned int open_flags)
+{
+    return xc_gnttab_open(logger, open_flags);
+}
+
+static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
+                                          int open_flags)
+{
+    return xc_interface_open(logger, dombuild_logger, open_flags);
+}
+
 /* FIXME There is now way to have the xen fd */
 static inline int xc_fd(xc_interface *xen_xc)
 {

Leave it as is in your patch and I'll change it in my xenner patch set again, but I wanted to make sure that you're aware of the issues going along with #defines.

Alex

#8 lore raw

Re: [Xen-devel] Re: [Qemu-devel] [PATCH V11 03/15] xen: Support new libxc calls from xen unstable.

Quoted 343 lines · Alexander Graf
Quoted 266 lines · On 01.03.2011, at 19:35, [email protected] wrote:

From: Anthony PERARD <[email protected]>

This patch updates 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 check libxenctrl version in configure, from Xen 3.3.0 to Xen unstable.

---
configure            |   67 ++++++++++++++++++++++++++++++++++++++++++++++++- hw/xen_backend.c     |   21 ++++++++-------
hw/xen_backend.h     |    6 ++--
hw/xen_common.h      |   64 +++++++++++++++++++++++++++++++++++++---------- hw/xen_disk.c        |    4 +-
hw/xen_domainbuild.c |    3 +-

6 files changed, 133 insertions(+), 32 deletions(-)
configure +0 -0
index 3036faf..a84d974 100755
@@ -126,6 +126,7 @@ vnc_jpeg=""

vnc_png=""
vnc_thread="no"
xen=""
+xen_ctrl_version=""
linux_aio=""
attr=""
vhost_net=""

configure +0 -0
@@ -1147,20 +1148,81 @@ fi
 

if test "$xen" != "no" ; then
  xen_libs="-lxenstore -lxenctrl -lxenguest"
+
+  # Xen unstable
  cat > $TMPC <<EOF
#include <xenctrl.h>
#include <xs.h>

configure +13 -1
-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 = xc_interface_open(0, 0, 0);
+  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
+  xc_gnttab_open(NULL, 0);
+  return 0;
+}

EOF
  if compile_prog "" "$xen_libs" ; then
+    xen_ctrl_version=410
    xen=yes
-    libs_softmmu="$xen_libs $libs_softmmu"

configure +43 -0
+
+  # 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

##########################################

configure +0 -0
@@ -2755,6 +2817,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

hw/xen_backend.c +11 -10
index 9f4ec4b..3907b83 100644
@@ -43,7 +43,8 @@
 /* ------------------------------------------------------------- */
 
 /* public */
-int xen_xc;
+XenXC xen_xc = XC_HANDLER_INITIAL_VALUE;
+XenGnttab xen_xcg = XC_HANDLER_INITIAL_VALUE;
 struct xs_handle *xenstore = NULL;
 const char *xen_protocol;
 
@@ -214,8 +215,8 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
     xendev->debug      = debug;
     xendev->local_port = -1;
 
-    xendev->evtchndev = xc_evtchn_open();
-    if (xendev->evtchndev < 0) {
+    xendev->evtchndev = xc_evtchn_open(NULL, 0);
+    if (xendev->evtchndev == XC_HANDLER_INITIAL_VALUE) {
         xen_be_printf(NULL, 0, "can't open evtchn device\n");
         qemu_free(xendev);
         return NULL;
@@ -223,15 +224,15 @@ 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();
-        if (xendev->gnttabdev < 0) {
+        xendev->gnttabdev = xc_gnttab_open(NULL, 0);
+        if (xendev->gnttabdev == XC_HANDLER_INITIAL_VALUE) {
             xen_be_printf(NULL, 0, "can't open gnttab device\n");
             xc_evtchn_close(xendev->evtchndev);
             qemu_free(xendev);
             return NULL;
         }
     } else {
-        xendev->gnttabdev = -1;
+        xendev->gnttabdev = XC_HANDLER_INITIAL_VALUE;
     }
 
     QTAILQ_INSERT_TAIL(&xendevs, xendev, next);
@@ -277,10 +278,10 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev)
             qemu_free(xendev->fe);
         }
 
-        if (xendev->evtchndev >= 0) {
+        if (xendev->evtchndev != XC_HANDLER_INITIAL_VALUE) {
             xc_evtchn_close(xendev->evtchndev);
         }
-        if (xendev->gnttabdev >= 0) {
+        if (xendev->gnttabdev != XC_HANDLER_INITIAL_VALUE) {
             xc_gnttab_close(xendev->gnttabdev);
         }
 
@@ -664,8 +665,8 @@ int xen_be_init(void)
         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;
     }
hw/xen_backend.h +3 -3
index 1b428e3..6401c85 100644
@@ -45,8 +45,8 @@ struct XenDevice {
     int                remote_port;
     int                local_port;
 
-    int                evtchndev;
-    int                gnttabdev;
+    XenEvtchn          evtchndev;
+    XenGnttab          gnttabdev;
 
     struct XenDevOps   *ops;
     QTAILQ_ENTRY(XenDevice) next;
@@ -55,7 +55,7 @@ struct XenDevice {
 /* ------------------------------------------------------------- */
 
 /* variables */
-extern int xen_xc;
+extern XenXC xen_xc;
 extern struct xs_handle *xenstore;
 extern const char *xen_protocol;
 
hw/xen_common.h +18 -14
index 8a55b44..7e123ec 100644
@@ -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,56 @@
 #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
+
+/* Xen before 4.0 */
+#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 400
+static inline void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
+                                        xen_pfn_t *arr, int *err,
+                                        unsigned int num)
+{
+    return xc_map_foreign_batch(xc_handle, dom, prot, arr, num);
+}
 #endif
-#if __XEN_LATEST_INTERFACE_VERSION__ < 0x00030208
-# define xen_mb()  mb()
-# define xen_rmb() rmb()
-# define xen_wmb() wmb()
+
+
+/* Xen before 4.1 */
+#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
+
+typedef int XenXC;

hw/xen_common.h line 45

Quoted 10 lines
hw/xen_common.h +10 -0
+typedef int XenEvtchn;
+typedef int XenGnttab;
+
+#  define XC_INTERFACE_FMT "%i"
+#  define XC_HANDLER_INITIAL_VALUE    -1
+
+#  define xc_interface_open(logger, dombuild_logger, open_flags) \
+    xc_interface_open()
+#  define xc_evtchn_open(logger, open_flags) xc_evtchn_open()
+#  define xc_gnttab_open(logger, open_flags) xc_gnttab_open()

defines really bite me when abstracting the interface through an indirect calling table. I had to change the code this way to make it work with xenner:

hw/xen_common.h +35 -4
index a5fc74b..0c09b37 100644
@@ -39,10 +39,23 @@ typedef int XenGnttab;
  #  define XC_INTERFACE_FMT "%i"
  #  define XC_HANDLER_INITIAL_VALUE    -1
 
-#  define xc_interface_open(logger, dombuild_logger, open_flags) \
-    xc_interface_open()
-#  define xc_evtchn_open(logger, open_flags) xc_evtchn_open()
-#  define xc_gnttab_open(logger, open_flags) xc_gnttab_open()
+static inline XenEvtchn xen_xc_evtchn_open(void *logger,
+                                           unsigned int open_flags)
+{
+    return xc_evtchn_open();
+}
+
+static inline XenGnttab xen_xc_gnttab_open(void *logger,
+                                           unsigned int open_flags)
+{
+    return xc_gnttab_open();
+}
+
+static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
+                                          unsigned int open_flags)
+{
+    return xc_interface_open();
+}
 
  static inline int xc_fd(int xen_xc)
  {
@@ -69,6 +82,24 @@ typedef xc_gnttab *XenGnttab;
  #  define XC_INTERFACE_FMT "%p"
  #  define XC_HANDLER_INITIAL_VALUE    NULL
 
+static inline XenEvtchn xen_xc_evtchn_open(void *logger,
+                                           unsigned int open_flags)
+{
+    return xc_evtchn_open(logger, open_flags);
+}
+
+static inline XenGnttab xen_xc_gnttab_open(void *logger,
+                                           unsigned int open_flags)
+{
+    return xc_gnttab_open(logger, open_flags);
+}
+
+static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
+                                          int open_flags)
+{
+    return xc_interface_open(logger, dombuild_logger, open_flags);
+}
+
  /* FIXME There is now way to have the xen fd */
  static inline int xc_fd(xc_interface *xen_xc)
  {
Quoted 1 line

Leave it as is in your patch and I'll change it in my xenner patch set again, but I wanted to make sure that you're aware of the issues going along with #defines.

I understand the issues with the defines. I just trying to address both comment from Anthony and you. But, I think these static inline instead of the #defines will be ok. So I will put it in my series.

Signature · 1 line
Anthony PERARD
#9 lore raw

PATCH v11 4/15 xen: Add initialisation of Xen

In reply to [email protected]

From: Anthony PERARD <[email protected]>

---
 Makefile.target |    9 +++++++++
 hw/xen.h        |   13 +++++++++++++
 vl.c            |    2 ++
 xen-all.c       |   23 +++++++++++++++++++++++
 xen-stub.c      |   15 +++++++++++++++
 5 files changed, 62 insertions(+), 0 deletions(-)
 create mode 100644 xen-all.c
 create mode 100644 xen-stub.c
Makefile.target +9 -0
index ab0a570..b08c7f7 100644
@@ -208,6 +208,15 @@ QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
 # xen backend driver support
 obj-i386-$(CONFIG_XEN) += xen_machine_pv.o
 
+ifeq ($(TARGET_ARCH), i386)
+CONFIG_NO_XEN = $(if $(subst n,,$(CONFIG_XEN)),n,y)
+else
+CONFIG_NO_XEN = y
+endif
+# xen support
+obj-i386-$(CONFIG_XEN) += xen-all.o
+obj-$(CONFIG_NO_XEN) += xen-stub.o
+
 # Inter-VM PCI shared memory
 obj-$(CONFIG_KVM) += ivshmem.o
 
hw/xen.h +13 -0
index 780dcf7..1fefe3a 100644
@@ -18,4 +18,17 @@ enum xen_mode {
 extern uint32_t xen_domid;
 extern enum xen_mode xen_mode;
 
+extern int xen_allowed;
+
+static inline int xen_enabled(void)
+{
+#ifdef CONFIG_XEN
+    return xen_allowed;
+#else
+    return 0;
+#endif
+}
+
+int xen_init(void);
+
 #endif /* QEMU_HW_XEN_H */
vl.c +2 -0
index 0030741..910b000 100644
@@ -259,6 +259,7 @@ static NotifierList machine_init_done_notifiers =
 
 static int tcg_allowed = 1;
 int kvm_allowed = 0;
+int xen_allowed = 0;
 uint32_t xen_domid;
 enum xen_mode xen_mode = XEN_EMULATE;
 
@@ -1866,6 +1867,7 @@ static struct {
     int *allowed;
 } accel_list[] = {
     { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
+    { "xen", "Xen", xen_available, xen_init, &xen_allowed },
     { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
 };
 
xen-all.c new file +23 -0
new file mode 100644
index 0000000..888fb1d
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2010       Citrix Ltd.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "hw/xen_common.h"
+#include "hw/xen_backend.h"
+
+/* Initialise Xen */
+
+int xen_init(void)
+{
+    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");
+        return -1;
+    }
+
+    return 0;
+}
xen-stub.c new file +15 -0
new file mode 100644
index 0000000..beb982f
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2010       Citrix Ltd.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu-common.h"
+#include "hw/xen.h"
+
+int xen_init(void)
+{
+    return -ENOSYS;
+}
Signature · 1 line
1.7.2.3
#10 lore raw

PATCH v11 5/15 xen: Add xenfv machine

In reply to [email protected]

From: Anthony PERARD <[email protected]>

Introduce the Xen FV (Fully Virtualized) machine to Qemu, some more Xen specific call will be added in further patches.

---
 hw/pc.c      |   19 +++++++++++++++++--
 hw/pc_piix.c |   17 +++++++++++++++++
 hw/xen.h     |    4 ++++
 3 files changed, 38 insertions(+), 2 deletions(-)
hw/pc.c +17 -2
index 5966bf1..6a73407 100644
@@ -41,6 +41,7 @@
 #include "sysemu.h"
 #include "blockdev.h"
 #include "ui/qemu-spice.h"
+#include "xen.h"
 
 /* output Bochs bios info messages */
 //#define DEBUG_BIOS
@@ -918,7 +919,11 @@ static void pc_cpu_reset(void *opaque)
     CPUState *env = opaque;
 
     cpu_reset(env);
-    env->halted = !cpu_is_bsp(env);
+    if (!xen_enabled()) {
+        env->halted = !cpu_is_bsp(env);
+    } else {
+        env->halted = 1;
+    }
 }
 
 static CPUState *pc_new_cpu(const char *cpu_model)
@@ -952,7 +957,12 @@ void pc_cpus_init(const char *cpu_model)
 #endif
     }
 
-    for(i = 0; i < smp_cpus; i++) {
+    if (!xen_enabled()) {
+        for(i = 0; i < smp_cpus; i++) {
+            pc_new_cpu(cpu_model);
+        }
+    } else {
+        /* Xen require only one Qemu VCPU */
         pc_new_cpu(cpu_model);
     }
 }
@@ -980,6 +990,11 @@ void pc_memory_init(ram_addr_t ram_size,
     *above_4g_mem_size_p = above_4g_mem_size;
     *below_4g_mem_size_p = below_4g_mem_size;
 
+    if (xen_enabled()) {
+        /* Nothing to do for Xen */
+        return;
+    }
+
     linux_boot = (kernel_filename != NULL);
 
     /* allocate RAM */
hw/pc_piix.c +17 -0
index b3ede89..6eff06e 100644
@@ -37,6 +37,10 @@
 #include "sysbus.h"
 #include "arch_init.h"
 #include "blockdev.h"
+#include "xen.h"
+#ifdef CONFIG_XEN
+#  include <xen/hvm/hvm_info_table.h>
+#endif
 
 #define MAX_IDE_BUS 2
 
@@ -391,6 +395,16 @@ static QEMUMachine isapc_machine = {
     .max_cpus = 1,
 };
 
+#ifdef CONFIG_XEN
+static QEMUMachine xenfv_machine = {
+    .name = "xenfv",
+    .desc = "Xen Fully-virtualized PC",
+    .init = pc_init_pci,
+    .max_cpus = HVM_MAX_VCPUS,
+    .default_machine_opts = "accel=xen",
+};
+#endif
+
 static void pc_machine_init(void)
 {
     qemu_register_machine(&pc_machine);
@@ -399,6 +413,9 @@ static void pc_machine_init(void)
     qemu_register_machine(&pc_machine_v0_11);
     qemu_register_machine(&pc_machine_v0_10);
     qemu_register_machine(&isapc_machine);
+#ifdef CONFIG_XEN
+    qemu_register_machine(&xenfv_machine);
+#endif
 }
 
 machine_init(pc_machine_init);
hw/xen.h +4 -0
index 1fefe3a..726360a 100644
@@ -31,4 +31,8 @@ static inline int xen_enabled(void)
 
 int xen_init(void);
 
+#if defined(CONFIG_XEN) && CONFIG_XEN_CTRL_INTERFACE_VERSION < 400
+#  define HVM_MAX_VCPUS 32
+#endif
+
 #endif /* QEMU_HW_XEN_H */
Signature · 1 line
1.7.2.3
#11 lore raw

PATCH v11 6/15 xen: Add the Xen platform pci device

In reply to [email protected]

From: Steven Smith <[email protected]>

Introduce a new emulated PCI device, specific to fully virtualized Xen guests. The device is necessary for PV on HVM drivers to work.

---
 Makefile.target   |    2 +
 hw/hw.h           |    3 +
 hw/pc_piix.c      |    4 +
 hw/pci_ids.h      |    2 +
 hw/xen.h          |    2 +
 hw/xen_platform.c |  349 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 trace-events      |    3 +
 xen-stub.c        |    4 +
 8 files changed, 369 insertions(+), 0 deletions(-)
 create mode 100644 hw/xen_platform.c
Makefile.target +2 -0
index b08c7f7..c539b1e 100644
@@ -217,6 +217,8 @@ endif
 obj-i386-$(CONFIG_XEN) += xen-all.o
 obj-$(CONFIG_NO_XEN) += xen-stub.o
 
+obj-i386-$(CONFIG_XEN) += xen_platform.o
+
 # Inter-VM PCI shared memory
 obj-$(CONFIG_KVM) += ivshmem.o
 
hw/hw.h +3 -0
index 5e24329..c285b2e 100644
@@ -682,6 +682,9 @@ extern const VMStateDescription vmstate_usb_device;
 #define VMSTATE_INT32_LE(_f, _s)                                   \
     VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
 
+#define VMSTATE_UINT8_TEST(_f, _s, _t)                               \
+    VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
+
 #define VMSTATE_UINT16_TEST(_f, _s, _t)                               \
     VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
 
hw/pc_piix.c +4 -0
index 6eff06e..417c456 100644
@@ -121,6 +121,10 @@ static void pc_init1(ram_addr_t ram_size,
 
     pc_vga_init(pci_enabled? pci_bus: NULL);
 
+    if (xen_enabled()) {
+        pci_xen_platform_init(pci_bus);
+    }
+
     /* init basic PC hardware */
     pc_basic_device_init(isa_irq, &rtc_state);
 
hw/pci_ids.h +2 -0
index ea3418c..6e9eabc 100644
@@ -108,3 +108,5 @@
 #define PCI_DEVICE_ID_INTEL_82371AB      0x7111
 #define PCI_DEVICE_ID_INTEL_82371AB_2    0x7112
 #define PCI_DEVICE_ID_INTEL_82371AB_3    0x7113
+
+#define PCI_VENDOR_ID_XENSOURCE          0x5853
hw/xen.h +2 -0
index 726360a..46c4a1c 100644
@@ -29,6 +29,8 @@ static inline int xen_enabled(void)
 #endif
 }
 
+void pci_xen_platform_init(PCIBus *bus);
+
 int xen_init(void);
 
 #if defined(CONFIG_XEN) && CONFIG_XEN_CTRL_INTERFACE_VERSION < 400
hw/xen_platform.c new file +349 -0

349 lines not on this page · raw message

trace-events +3 -0
index e6138ea..20aadab 100644
@@ -254,3 +254,6 @@ disable spice_vmc_write(ssize_t out, int len) "spice wrottn %lu of requested %zd
 disable spice_vmc_read(int bytes, int len) "spice read %lu of requested %zd"
 disable spice_vmc_register_interface(void *scd) "spice vmc registered interface %p"
 disable spice_vmc_unregister_interface(void *scd) "spice vmc unregistered interface %p"
+
+# hw/xen_platform.c
+disable xen_platform_log(char *s) "xen platform: %s"
xen-stub.c +4 -0
index beb982f..9645af2 100644
@@ -9,6 +9,10 @@
 #include "qemu-common.h"
 #include "hw/xen.h"
 
+void pci_xen_platform_init(PCIBus *bus)
+{
+}
+
 int xen_init(void)
 {
     return -ENOSYS;
Signature · 1 line
1.7.2.3
#12 lore raw

Re: [Qemu-devel] [PATCH V11 06/15] xen: Add the Xen platform pci device

Quoted 52 lines · On 01.03.2011, at 19:35, [email protected] wrote:

From: Steven Smith <[email protected]>

Introduce a new emulated PCI device, specific to fully virtualized Xen guests. The device is necessary for PV on HVM drivers to work.

---

Makefile.target   |    2 +
hw/hw.h           |    3 +
hw/pc_piix.c      |    4 +
hw/pci_ids.h      |    2 +
hw/xen.h          |    2 +
hw/xen_platform.c |  349 +++++++++++++++++++++++++++++++++++++++++++++++++++++
trace-events      |    3 +
xen-stub.c        |    4 +
8 files changed, 369 insertions(+), 0 deletions(-)

create mode 100644 hw/xen_platform.c

Makefile.target +0 -0
index b08c7f7..c539b1e 100644
@@ -217,6 +217,8 @@ endif

obj-i386-$(CONFIG_XEN) += xen-all.o
obj-$(CONFIG_NO_XEN) += xen-stub.o

Makefile.target +2 -0
+obj-i386-$(CONFIG_XEN) += xen_platform.o
+

# Inter-VM PCI shared memory
obj-$(CONFIG_KVM) += ivshmem.o

hw/hw.h +3 -0
index 5e24329..c285b2e 100644
@@ -682,6 +682,9 @@ extern const VMStateDescription vmstate_usb_device;
 #define VMSTATE_INT32_LE(_f, _s)                                   \
    VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
 
+#define VMSTATE_UINT8_TEST(_f, _s, _t)                               \
+    VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
+
 #define VMSTATE_UINT16_TEST(_f, _s, _t)                               \
    VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
 
hw/pc_piix.c +0 -0
index 6eff06e..417c456 100644

hw/pc_piix.c static void pc_init1(ram_addr_t ram_size, · line 125

Quoted 5 lines
hw/pc_piix.c +2 -0
@@ -121,6 +121,10 @@ static void pc_init1(ram_addr_t ram_size,
 
    pc_vga_init(pci_enabled? pci_bus: NULL);
 
+    if (xen_enabled()) {
+        pci_xen_platform_init(pci_bus);

It probably makes sense to fold that function in here. That way you wouldn't need the entry in the stub file.

Alex

#13 lore raw

Re: [Qemu-devel] [PATCH V11 06/15] xen: Add the Xen platform pci device

Quoted 6 lines · Alexander Graf
Quoted 6 lines
hw/pc_piix.c +0 -0
index 6eff06e..417c456 100644
@@ -121,6 +121,10 @@ static void pc_init1(ram_addr_t ram_size,
 
Quoted 6 lines

hw/pc_piix.c static void pc_init1(ram_addr_t ram_size, · line 125

Quoted 4 lines
hw/pc_piix.c +2 -0
     pc_vga_init(pci_enabled? pci_bus: NULL);
 
+    if (xen_enabled()) {
+        pci_xen_platform_init(pci_bus);

It probably makes sense to fold that function in here. That way you wouldn't need the entry in the stub file.

Yes, I will do that.

Thanks,

Signature · 1 line
Anthony PERARD
#14 lore raw

PATCH v11 7/15 piix_pci: Introduces Xen specific call for irq.

In reply to [email protected]

From: Anthony PERARD <[email protected]>

This patch introduces Xen specific call in piix_pci.

The specific part for Xen is in write_config, set_irq and get_pirq.

---
 hw/pc.h       |    1 +
 hw/pc_piix.c  |    6 +++++-
 hw/piix_pci.c |   47 ++++++++++++++++++++++++++++++++++++++++++++---
 hw/xen.h      |    6 ++++++
 xen-all.c     |   31 +++++++++++++++++++++++++++++++
 xen-stub.c    |   13 +++++++++++++
 6 files changed, 100 insertions(+), 4 deletions(-)
hw/pc.h +1 -0
index feb8a7a..85662c3 100644
@@ -176,6 +176,7 @@ struct PCII440FXState;
 typedef struct PCII440FXState PCII440FXState;
 
 PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn, qemu_irq *pic, ram_addr_t ram_size);
+PCIBus *i440fx_xen_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq *pic, ram_addr_t ram_size);
 void i440fx_init_memory_mappings(PCII440FXState *d);
 
 /* piix4.c */
hw/pc_piix.c +5 -1
index 417c456..7457bdb 100644
@@ -109,7 +109,11 @@ static void pc_init1(ram_addr_t ram_size,
     isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
 
     if (pci_enabled) {
-        pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
+        if (!xen_enabled()) {
+            pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
+        } else {
+            pci_bus = i440fx_xen_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
+        }
     } else {
         pci_bus = NULL;
         i440fx_state = NULL;
hw/piix_pci.c +44 -3

88 lines not on this page · raw message

hw/xen.h +6 -0
index 46c4a1c..95653df 100644
@@ -8,6 +8,8 @@
  */
 #include <inttypes.h>
 
+#include "qemu-common.h"
+
 /* xen-machine.c */
 enum xen_mode {
     XEN_EMULATE = 0,  // xen emulation, using xenner (default)
@@ -29,6 +31,10 @@ static inline int xen_enabled(void)
 #endif
 }
 
+int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
+void xen_piix3_set_irq(void *opaque, int irq_num, int level);
+void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len);
+
 void pci_xen_platform_init(PCIBus *bus);
 
 int xen_init(void);
xen-all.c +31 -0
index 888fb1d..7b94d61 100644
@@ -6,9 +6,40 @@
  *
  */
 
+#include "hw/pci.h"
 #include "hw/xen_common.h"
 #include "hw/xen_backend.h"
 
+/* Xen specific function for piix pci */
+
+int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
+{
+    return irq_num + ((pci_dev->devfn >> 3) << 2);
+}
+
+void xen_piix3_set_irq(void *opaque, int irq_num, int level)
+{
+    xc_hvm_set_pci_intx_level(xen_xc, xen_domid, 0, 0, irq_num >> 2,
+                              irq_num & 3, level);
+}
+
+void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
+{
+    int i;
+
+    /* Scan for updates to PCI link routes (0x60-0x63). */
+    for (i = 0; i < len; i++) {
+        uint8_t v = (val >> (8 * i)) & 0xff;
+        if (v & 0x80) {
+            v = 0;
+        }
+        v &= 0xf;
+        if (((address + i) >= 0x60) && ((address + i) <= 0x63)) {
+            xc_hvm_set_pci_link_route(xen_xc, xen_domid, address + i - 0x60, v);
+        }
+    }
+}
+
 /* Initialise Xen */
 
 int xen_init(void)
xen-stub.c +13 -0
index 9645af2..216cae9 100644
@@ -9,6 +9,19 @@
 #include "qemu-common.h"
 #include "hw/xen.h"
 
+int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
+{
+    return -1;
+}
+
+void xen_piix3_set_irq(void *opaque, int irq_num, int level)
+{
+}
+
+void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
+{
+}
+
 void pci_xen_platform_init(PCIBus *bus)
 {
 }
Signature · 1 line
1.7.2.3
#15 lore raw

PATCH v11 8/15 xen: Introduce Xen Interrupt Controller

In reply to [email protected]

From: Anthony PERARD <[email protected]>

Every set_irq call makes a Xen hypercall.

---
 hw/pc_piix.c |    8 ++++++--
 hw/xen.h     |    2 ++
 xen-all.c    |   12 ++++++++++++
 xen-stub.c   |    5 +++++
 4 files changed, 25 insertions(+), 2 deletions(-)
hw/pc_piix.c +6 -2
index 7457bdb..1d55bc9 100644
@@ -99,8 +99,12 @@ static void pc_init1(ram_addr_t ram_size,
     pc_memory_init(ram_size, kernel_filename, kernel_cmdline, initrd_filename,
                    &below_4g_mem_size, &above_4g_mem_size);
 
-    cpu_irq = pc_allocate_cpu_irq();
-    i8259 = i8259_init(cpu_irq[0]);
+    if (!xen_enabled()) {
+        cpu_irq = pc_allocate_cpu_irq();
+        i8259 = i8259_init(cpu_irq[0]);
+    } else {
+        i8259 = xen_interrupt_controller_init();
+    }
     isa_irq_state = qemu_mallocz(sizeof(*isa_irq_state));
     isa_irq_state->i8259 = i8259;
     if (pci_enabled) {
hw/xen.h +2 -0
index 95653df..12d4e5f 100644
@@ -35,6 +35,8 @@ int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
 void xen_piix3_set_irq(void *opaque, int irq_num, int level);
 void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len);
 
+qemu_irq *xen_interrupt_controller_init(void);
+
 void pci_xen_platform_init(PCIBus *bus);
 
 int xen_init(void);
xen-all.c +12 -0
index 7b94d61..761f2a0 100644
@@ -40,6 +40,18 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
     }
 }
 
+/* Xen Interrupt Controller */
+
+static void xen_set_irq(void *opaque, int irq, int level)
+{
+    xc_hvm_set_isa_irq_level(xen_xc, xen_domid, irq, level);
+}
+
+qemu_irq *xen_interrupt_controller_init(void)
+{
+    return qemu_allocate_irqs(xen_set_irq, NULL, 16);
+}
+
 /* Initialise Xen */
 
 int xen_init(void)
xen-stub.c +5 -0
index 216cae9..e335b67 100644
@@ -22,6 +22,11 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
 {
 }
 
+qemu_irq *xen_interrupt_controller_init(void)
+{
+    return NULL;
+}
+
 void pci_xen_platform_init(PCIBus *bus)
 {
 }
Signature · 1 line
1.7.2.3
#16 lore raw

PATCH v11 9/15 xen: Introduce the Xen mapcache

In reply to [email protected]

From: Jun Nakajima <[email protected]>

On IA32 host or IA32 PAE host, at present, generally, we can't create an HVM guest with more than 2G memory, because generally it's almost impossible for Qemu to find a large enough and consecutive virtual address space to map an HVM guest's whole physical address space. The attached patch fixes this issue using dynamic mapping based on little blocks of memory.

Each call to qemu_get_ram_ptr makes a call to qemu_map_cache with the lock option, so mapcache will not unmap these ram_ptr.

---
 Makefile.target     |    3 +
 configure           |    3 +
 exec.c              |   40 ++++++-
 hw/xen.h            |   13 ++
 hw/xen_common.h     |    9 ++
 xen-all.c           |   64 +++++++++++
 xen-mapcache-stub.c |   40 +++++++
 xen-mapcache.c      |  310 +++++++++++++++++++++++++++++++++++++++++++++++++++
 xen-mapcache.h      |   22 ++++
 xen-stub.c          |    4 +
 10 files changed, 504 insertions(+), 4 deletions(-)
 create mode 100644 xen-mapcache-stub.c
 create mode 100644 xen-mapcache.c
 create mode 100644 xen-mapcache.h
Makefile.target +3 -0
index c539b1e..dcdd51d 100644
@@ -214,8 +214,11 @@ else
 CONFIG_NO_XEN = y
 endif
 # xen support
+CONFIG_NO_XEN_MAPCACHE = $(if $(subst n,,$(CONFIG_XEN_MAPCACHE)),n,y)
 obj-i386-$(CONFIG_XEN) += xen-all.o
 obj-$(CONFIG_NO_XEN) += xen-stub.o
+obj-i386-$(CONFIG_XEN_MAPCACHE) += xen-mapcache.o
+obj-$(CONFIG_NO_XEN_MAPCACHE) += xen-mapcache-stub.o
 
 obj-i386-$(CONFIG_XEN) += xen_platform.o
 
configure +3 -0
index a84d974..4fd8696 100755
@@ -3172,6 +3172,9 @@ case "$target_arch2" in
   i386|x86_64)
     if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then
       echo "CONFIG_XEN=y" >> $config_target_mak
+      if test "$cpu" = "i386" -o "$cpu" = "x86_64"; then
+          echo "CONFIG_XEN_MAPCACHE=y" >> $config_target_mak
+      fi
     fi
 esac
 case "$target_arch2" in
exec.c +36 -4
index d611100..558595a 100644
@@ -32,6 +32,7 @@
 #include "hw/qdev.h"
 #include "osdep.h"
 #include "kvm.h"
+#include "hw/xen.h"
 #include "qemu-timer.h"
 #if defined(CONFIG_USER_ONLY)
 #include <qemu.h>
@@ -51,6 +52,8 @@
 #include <libutil.h>
 #endif
 #endif
+#else /* !CONFIG_USER_ONLY */
+#include "xen-mapcache.h"
 #endif
 
 //#define DEBUG_TB_INVALIDATE
@@ -2865,6 +2868,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
         }
     }
 
+    new_block->offset = find_ram_offset(size);
     if (host) {
         new_block->host = host;
     } else {
@@ -2886,13 +2890,15 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
                                    PROT_EXEC|PROT_READ|PROT_WRITE,
                                    MAP_SHARED | MAP_ANONYMOUS, -1, 0);
 #else
-            new_block->host = qemu_vmalloc(size);
+            if (xen_mapcache_enabled()) {
+                xen_ram_alloc(new_block->offset, size);
+            } else {
+                new_block->host = qemu_vmalloc(size);
+            }
 #endif
             qemu_madvise(new_block->host, size, QEMU_MADV_MERGEABLE);
         }
     }
-
-    new_block->offset = find_ram_offset(size);
     new_block->length = size;
 
     QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next);
@@ -2933,7 +2939,11 @@ void qemu_ram_free(ram_addr_t addr)
 #if defined(TARGET_S390X) && defined(CONFIG_KVM)
                 munmap(block->host, block->length);
 #else
-                qemu_vfree(block->host);
+                if (xen_mapcache_enabled()) {
+                    qemu_invalidate_entry(block->host);
+                } else {
+                    qemu_vfree(block->host);
+                }
 #endif
             }
             qemu_free(block);
@@ -2959,6 +2969,15 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
         if (addr - block->offset < block->length) {
             QLIST_REMOVE(block, next);
             QLIST_INSERT_HEAD(&ram_list.blocks, block, next);
+            if (xen_mapcache_enabled()) {
+                /* We need to check if the requested address is in the RAM
+                 * because we don't want to map the entire memory in QEMU.
+                 */
+                if (block->offset == 0) {
+                    return qemu_map_cache(addr, 0, 1);
+                }
+                block->host = qemu_map_cache(block->offset, block->length, 1);
+            }
             return block->host + (addr - block->offset);
         }
     }
@@ -2994,11 +3013,21 @@ int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr)
     uint8_t *host = ptr;
 
     QLIST_FOREACH(block, &ram_list.blocks, next) {
+        /* This case append when the block is not mapped. */
+        if (block->host == NULL) {
+            continue;
+        }
         if (host - block->host < block->length) {
             *ram_addr = block->offset + (host - block->host);
             return 0;
         }
     }
+
+    if (xen_mapcache_enabled()) {
+        *ram_addr = qemu_ram_addr_from_mapcache(ptr);
+        return 0;
+    }
+
     return -1;
 }
 
@@ -3909,6 +3938,9 @@ void cpu_physical_memory_unmap(void *buffer, target_phys_addr_t len,
     if (is_write) {
         cpu_physical_memory_write(bounce.addr, bounce.buffer, access_len);
     }
+    if (xen_enabled()) {
+        qemu_invalidate_entry(buffer);
+    }
     qemu_vfree(bounce.buffer);
     bounce.buffer = NULL;
     cpu_notify_map_clients();
hw/xen.h +13 -0
index 12d4e5f..e26d061 100644
@@ -31,6 +31,15 @@ static inline int xen_enabled(void)
 #endif
 }
 
+static inline int xen_mapcache_enabled(void)
+{
+#ifdef CONFIG_XEN_MAPCACHE
+    return xen_enabled();
+#else
+    return 0;
+#endif
+}
+
 int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
 void xen_piix3_set_irq(void *opaque, int irq_num, int level);
 void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len);
@@ -41,6 +50,10 @@ void pci_xen_platform_init(PCIBus *bus);
 
 int xen_init(void);
 
+#if defined(NEED_CPU_H) && !defined(CONFIG_USER_ONLY)
+void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size);
+#endif
+
 #if defined(CONFIG_XEN) && CONFIG_XEN_CTRL_INTERFACE_VERSION < 400
 #  define HVM_MAX_VCPUS 32
 #endif
hw/xen_common.h +9 -0
index 7e123ec..5a36642 100644
@@ -50,6 +50,15 @@ static inline int xc_fd(int xen_xc)
 }
 
 
+static inline int xc_domain_populate_physmap_exact
+    (XenXC xc_handle, uint32_t domid, unsigned long nr_extents,
+     unsigned int extent_order, unsigned int mem_flags, xen_pfn_t *extent_start)
+{
+    return xc_domain_memory_populate_physmap
+        (xc_handle, domid, nr_extents, extent_order, mem_flags, extent_start);
+}
+
+
 /* Xen 4.1 */
 #else
 
xen-all.c +64 -0

81 lines not on this page · raw message

xen-mapcache-stub.c new file +40 -0
new file mode 100644
index 0000000..541bee6
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2011       Citrix Ltd.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "config.h"
+
+#include "exec-all.h"
+#include "qemu-common.h"
+#include "cpu-common.h"
+#include "xen-mapcache.h"
+
+void qemu_map_cache_init(void)
+{
+}
+
+uint8_t *qemu_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, uint8_t lock)
+{
+    return qemu_get_ram_ptr(phys_addr);
+}
+
+void qemu_map_cache_unlock(void *buffer)
+{
+}
+
+ram_addr_t qemu_ram_addr_from_mapcache(void *ptr)
+{
+    return -1;
+}
+
+void qemu_invalidate_map_cache(void)
+{
+}
+
+void qemu_invalidate_entry(uint8_t *buffer)
+{
+}
xen-mapcache.c new file +310 -0

310 lines not on this page · raw message

xen-mapcache.h new file +22 -0
new file mode 100644
index 0000000..ef3717f
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2011       Citrix Ltd.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef XEN_MAPCACHE_H
+#define XEN_MAPCACHE_H
+
+void     qemu_map_cache_init(void);
+uint8_t  *qemu_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, uint8_t lock);
+void     qemu_map_cache_unlock(void *phys_addr);
+ram_addr_t qemu_ram_addr_from_mapcache(void *ptr);
+void     qemu_invalidate_entry(uint8_t *buffer);
+void     qemu_invalidate_map_cache(void);
+
+#define mapcache_lock()   ((void)0)
+#define mapcache_unlock() ((void)0)
+
+#endif /* !XEN_MAPCACHE_H */
xen-stub.c +4 -0
index e335b67..eebc223 100644
@@ -22,6 +22,10 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
 {
 }
 
+void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size)
+{
+}
+
 qemu_irq *xen_interrupt_controller_init(void)
 {
     return NULL;
Signature · 1 line
1.7.2.3
#17 lore raw

Re: [Qemu-devel] [PATCH V11 09/15] xen: Introduce the Xen mapcache

Quoted 425 lines · On 01.03.2011, at 19:35, [email protected] wrote:

From: Jun Nakajima <[email protected]>

On IA32 host or IA32 PAE host, at present, generally, we can't create an HVM guest with more than 2G memory, because generally it's almost impossible for Qemu to find a large enough and consecutive virtual address space to map an HVM guest's whole physical address space. The attached patch fixes this issue using dynamic mapping based on little blocks of memory.

Each call to qemu_get_ram_ptr makes a call to qemu_map_cache with the lock option, so mapcache will not unmap these ram_ptr.

---

Makefile.target     |    3 +
configure           |    3 +
exec.c              |   40 ++++++-
hw/xen.h            |   13 ++
hw/xen_common.h     |    9 ++
xen-all.c           |   64 +++++++++++
xen-mapcache-stub.c |   40 +++++++
xen-mapcache.c      |  310 +++++++++++++++++++++++++++++++++++++++++++++++++++
xen-mapcache.h      |   22 ++++
xen-stub.c          |    4 +
10 files changed, 504 insertions(+), 4 deletions(-)

create mode 100644 xen-mapcache-stub.c
create mode 100644 xen-mapcache.c
create mode 100644 xen-mapcache.h

Makefile.target +0 -0
index c539b1e..dcdd51d 100644
@@ -214,8 +214,11 @@ else

CONFIG_NO_XEN = y
endif

# xen support
+CONFIG_NO_XEN_MAPCACHE = $(if $(subst n,,$(CONFIG_XEN_MAPCACHE)),n,y)
obj-i386-$(CONFIG_XEN) += xen-all.o
obj-$(CONFIG_NO_XEN) += xen-stub.o
Makefile.target +2 -0
+obj-i386-$(CONFIG_XEN_MAPCACHE) += xen-mapcache.o
+obj-$(CONFIG_NO_XEN_MAPCACHE) += xen-mapcache-stub.o

obj-i386-$(CONFIG_XEN) += xen_platform.o

configure +3 -0
index a84d974..4fd8696 100755
@@ -3172,6 +3172,9 @@ case "$target_arch2" in
  i386|x86_64)
    if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then
      echo "CONFIG_XEN=y" >> $config_target_mak
+      if test "$cpu" = "i386" -o "$cpu" = "x86_64"; then
+          echo "CONFIG_XEN_MAPCACHE=y" >> $config_target_mak
+      fi
    fi

esac
case "$target_arch2" in

exec.c +36 -4
index d611100..558595a 100644
@@ -32,6 +32,7 @@
 #include "hw/qdev.h"
 #include "osdep.h"
 #include "kvm.h"
+#include "hw/xen.h"
 #include "qemu-timer.h"
 #if defined(CONFIG_USER_ONLY)
 #include <qemu.h>
@@ -51,6 +52,8 @@
 #include <libutil.h>
 #endif
 #endif
+#else /* !CONFIG_USER_ONLY */
+#include "xen-mapcache.h"
 #endif
 
 //#define DEBUG_TB_INVALIDATE
@@ -2865,6 +2868,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
        }
    }
 
+    new_block->offset = find_ram_offset(size);
    if (host) {
        new_block->host = host;
    } else {
@@ -2886,13 +2890,15 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
                                   PROT_EXEC|PROT_READ|PROT_WRITE,
                                   MAP_SHARED | MAP_ANONYMOUS, -1, 0);
 #else
-            new_block->host = qemu_vmalloc(size);
+            if (xen_mapcache_enabled()) {
+                xen_ram_alloc(new_block->offset, size);
+            } else {
+                new_block->host = qemu_vmalloc(size);
+            }
 #endif
            qemu_madvise(new_block->host, size, QEMU_MADV_MERGEABLE);
        }
    }
-
-    new_block->offset = find_ram_offset(size);
    new_block->length = size;
 
    QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next);
@@ -2933,7 +2939,11 @@ void qemu_ram_free(ram_addr_t addr)
 #if defined(TARGET_S390X) && defined(CONFIG_KVM)
                munmap(block->host, block->length);
 #else
-                qemu_vfree(block->host);
+                if (xen_mapcache_enabled()) {
+                    qemu_invalidate_entry(block->host);
+                } else {
+                    qemu_vfree(block->host);
+                }
 #endif
            }
            qemu_free(block);
@@ -2959,6 +2969,15 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
        if (addr - block->offset < block->length) {
            QLIST_REMOVE(block, next);
            QLIST_INSERT_HEAD(&ram_list.blocks, block, next);
+            if (xen_mapcache_enabled()) {
+                /* We need to check if the requested address is in the RAM
+                 * because we don't want to map the entire memory in QEMU.
+                 */
+                if (block->offset == 0) {
+                    return qemu_map_cache(addr, 0, 1);
+                }
+                block->host = qemu_map_cache(block->offset, block->length, 1);
+            }
            return block->host + (addr - block->offset);
        }
    }
@@ -2994,11 +3013,21 @@ int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr)
    uint8_t *host = ptr;
 
    QLIST_FOREACH(block, &ram_list.blocks, next) {
+        /* This case append when the block is not mapped. */
+        if (block->host == NULL) {
+            continue;
+        }
        if (host - block->host < block->length) {
            *ram_addr = block->offset + (host - block->host);
            return 0;
        }
    }
+
+    if (xen_mapcache_enabled()) {
+        *ram_addr = qemu_ram_addr_from_mapcache(ptr);
+        return 0;
+    }
+
    return -1;
 }
 
@@ -3909,6 +3938,9 @@ void cpu_physical_memory_unmap(void *buffer, target_phys_addr_t len,
    if (is_write) {
        cpu_physical_memory_write(bounce.addr, bounce.buffer, access_len);
    }
+    if (xen_enabled()) {
+        qemu_invalidate_entry(buffer);
+    }
    qemu_vfree(bounce.buffer);
    bounce.buffer = NULL;
    cpu_notify_map_clients();
hw/xen.h +13 -0
index 12d4e5f..e26d061 100644
@@ -31,6 +31,15 @@ static inline int xen_enabled(void)
 #endif
 }
 
+static inline int xen_mapcache_enabled(void)
+{
+#ifdef CONFIG_XEN_MAPCACHE
+    return xen_enabled();
+#else
+    return 0;
+#endif
+}
+
 int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
 void xen_piix3_set_irq(void *opaque, int irq_num, int level);
 void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len);
@@ -41,6 +50,10 @@ void pci_xen_platform_init(PCIBus *bus);
 
 int xen_init(void);
 
+#if defined(NEED_CPU_H) && !defined(CONFIG_USER_ONLY)
+void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size);
+#endif
+
 #if defined(CONFIG_XEN) && CONFIG_XEN_CTRL_INTERFACE_VERSION < 400
 #  define HVM_MAX_VCPUS 32
 #endif
hw/xen_common.h +9 -0
index 7e123ec..5a36642 100644
@@ -50,6 +50,15 @@ static inline int xc_fd(int xen_xc)
 }
 
 
+static inline int xc_domain_populate_physmap_exact
+    (XenXC xc_handle, uint32_t domid, unsigned long nr_extents,
+     unsigned int extent_order, unsigned int mem_flags, xen_pfn_t *extent_start)
+{
+    return xc_domain_memory_populate_physmap
+        (xc_handle, domid, nr_extents, extent_order, mem_flags, extent_start);
+}
+
+
 /* Xen 4.1 */
 #else
 
xen-all.c +64 -0
index 761f2a0..03d1e90 100644
@@ -10,6 +10,8 @@
 #include "hw/xen_common.h"
 #include "hw/xen_backend.h"
 
+#include "xen-mapcache.h"
+
 /* Xen specific function for piix pci */
 
 int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
@@ -52,6 +54,64 @@ qemu_irq *xen_interrupt_controller_init(void)
    return qemu_allocate_irqs(xen_set_irq, NULL, 16);
 }
 
+
+/* Memory Ops */
+
+static void xen_ram_init(ram_addr_t ram_size)
+{
+    RAMBlock *new_block;
+    ram_addr_t below_4g_mem_size, above_4g_mem_size = 0;
+
+    new_block = qemu_mallocz(sizeof (*new_block));
+    pstrcpy(new_block->idstr, sizeof (new_block->idstr), "xen.ram");
+    new_block->host = NULL;
+    new_block->offset = 0;
+    new_block->length = ram_size;
+
+    QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next);
+
+    ram_list.phys_dirty = qemu_realloc(ram_list.phys_dirty,
+                                       new_block->length >> TARGET_PAGE_BITS);
+    memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS),
+           0xff, new_block->length >> TARGET_PAGE_BITS);
+
+    if (ram_size >= 0xe0000000 ) {
+        above_4g_mem_size = ram_size - 0xe0000000;
+        below_4g_mem_size = 0xe0000000;
+    } else {
+        below_4g_mem_size = ram_size;
+    }
+
+    cpu_register_physical_memory(0, below_4g_mem_size, new_block->offset);
+#if TARGET_PHYS_ADDR_BITS > 32
+    if (above_4g_mem_size > 0) {
+        cpu_register_physical_memory(0x100000000ULL, above_4g_mem_size,
+                                     new_block->offset + below_4g_mem_size);
+    }
+#endif
+}
+
+void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size)
+{
+    unsigned long nr_pfn;
+    xen_pfn_t *pfn_list;
+    int i;
+
+    nr_pfn = size >> TARGET_PAGE_BITS;
+    pfn_list = qemu_malloc(sizeof (*pfn_list) * nr_pfn);
+
+    for (i = 0; i < nr_pfn; i++) {
+        pfn_list[i] = (ram_addr >> TARGET_PAGE_BITS) + i;
+    }
+
+    if (xc_domain_populate_physmap_exact(xen_xc, xen_domid, nr_pfn, 0, 0, pfn_list)) {
+        hw_error("xen: failed to populate ram at %lx", ram_addr);
+    }
+
+    qemu_free(pfn_list);
+}
+
+
 /* Initialise Xen */
 
 int xen_init(void)
@@ -62,5 +122,9 @@ int xen_init(void)
        return -1;
    }
 
+    /* Init RAM management */
+    qemu_map_cache_init();
+    xen_ram_init(ram_size);
+
    return 0;
 }
xen-mapcache-stub.c new file +40 -0
new file mode 100644
index 0000000..541bee6
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2011       Citrix Ltd.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "config.h"
+
+#include "exec-all.h"
+#include "qemu-common.h"
+#include "cpu-common.h"
+#include "xen-mapcache.h"
+
+void qemu_map_cache_init(void)
+{
+}
+
+uint8_t *qemu_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, uint8_t lock)
+{
+    return qemu_get_ram_ptr(phys_addr);
+}
+
+void qemu_map_cache_unlock(void *buffer)
+{
+}
+
+ram_addr_t qemu_ram_addr_from_mapcache(void *ptr)
+{
+    return -1;
+}
+
+void qemu_invalidate_map_cache(void)
+{
+}
+
+void qemu_invalidate_entry(uint8_t *buffer)
+{
+}
xen-mapcache.c new file +64 -0
new file mode 100644
index 0000000..d7f44a7
@@ -0,0 +1,310 @@
+/*
+ * Copyright (C) 2011       Citrix Ltd.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "config.h"
+
+#include <sys/resource.h>
+
+#include "hw/xen_backend.h"
+#include "blockdev.h"
+
+#include <xen/hvm/params.h>
+#include <sys/mman.h>
+
+#include "xen-mapcache.h"
+
+
+//#define MAPCACHE_DEBUG
+
+#ifdef MAPCACHE_DEBUG
+#  define DPRINTF(fmt, ...) do { \
+    fprintf(stderr, "xen_mapcache: " fmt, ## __VA_ARGS__); \
+} while (0)
+#else
+#  define DPRINTF(fmt, ...) do { } while (0)
+#endif
+
+#if defined(__i386__)
+#  define MCACHE_BUCKET_SHIFT 16
+#elif defined(__x86_64__)
+#  define MCACHE_BUCKET_SHIFT 20
+#endif
+#define MCACHE_BUCKET_SIZE (1UL << MCACHE_BUCKET_SHIFT)
+
+#define BITS_PER_LONG (sizeof(long) * 8)
+#define BITS_TO_LONGS(bits) (((bits) + BITS_PER_LONG - 1) / BITS_PER_LONG)
+#define DECLARE_BITMAP(name, bits) unsigned long name[BITS_TO_LONGS(bits)]
+
+typedef struct MapCacheEntry {
+    target_phys_addr_t paddr_index;
+    uint8_t *vaddr_base;
+    DECLARE_BITMAP(valid_mapping, MCACHE_BUCKET_SIZE >> XC_PAGE_SHIFT);
+    uint8_t lock;
+    struct MapCacheEntry *next;
+} MapCacheEntry;
+
+typedef struct MapCacheRev {
+    uint8_t *vaddr_req;
+    target_phys_addr_t paddr_index;
+    QTAILQ_ENTRY(MapCacheRev) next;
+} MapCacheRev;
+
+typedef struct MapCache {
+    MapCacheEntry *entry;
+    unsigned long nr_buckets;
+    QTAILQ_HEAD(map_cache_head, MapCacheRev) locked_entries;
+
+    /* For most cases (>99.9%), the page address is the same. */
+    target_phys_addr_t last_address_index;
+    uint8_t *last_address_vaddr;

xen-mapcache.c line 74

Quoted 10 lines
xen-mapcache.c new file +10 -0
+    unsigned long max_mcache_size;
+    unsigned int mcache_bucket_shift;
+} MapCache;
+
+static MapCache *mapcache;
+
+static inline int test_bit(unsigned int bit, const unsigned long *map)
+{
+    return !!((map)[(bit) / BITS_PER_LONG] & (1UL << ((bit) % BITS_PER_LONG)));
+}

We have a bitmap framework in qemu now. Please use that :). See bitmap.h / bitops.h / bitops.c.

Alex

#18 lore raw

Re: [Xen-devel] Re: [Qemu-devel] [PATCH V11 09/15] xen: Introduce the Xen mapcache

Quoted 1 line · Alexander Graf

We have a bitmap framework in qemu now. Please use that :). See bitmap.h / bitops.h / bitops.c.

Will do.

Thanks,

Signature · 1 line
Anthony PERARD
#19 lore raw

PATCH v11 10/15 configure: Always use 64bits target physical addresses with xen enabled.

In reply to [email protected]

From: Anthony PERARD <[email protected]>

With MapCache, we can handle a 64b target, even with a 32b host/qemu. So, we need to have target_phys_addr_t to 64bits.

---
 configure |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
configure +1 -0
index 4fd8696..ecab08c 100755
@@ -3171,6 +3171,7 @@ echo "TARGET_ABI_DIR=$TARGET_ABI_DIR" >> $config_target_mak
 case "$target_arch2" in
   i386|x86_64)
     if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then
+      target_phys_bits=64
       echo "CONFIG_XEN=y" >> $config_target_mak
       if test "$cpu" = "i386" -o "$cpu" = "x86_64"; then
           echo "CONFIG_XEN_MAPCACHE=y" >> $config_target_mak
Signature · 1 line
1.7.2.3
#20 lore raw

PATCH v11 11/15 Introduce qemu_put_ram_ptr

In reply to [email protected]

From: Anthony PERARD <[email protected]>

This function allows to unlock a ram_ptr give by qemu_get_ram_ptr. After a call to qemu_put_ram_ptr, the pointer may be unmap from QEMU when used with Xen.

---
 cpu-common.h   |    1 +
 exec.c         |   10 ++++++++++
 xen-mapcache.c |   34 ++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 0 deletions(-)
cpu-common.h +1 -0
index 54d21d4..1f1c886 100644
@@ -55,6 +55,7 @@ void *qemu_get_ram_ptr(ram_addr_t addr);
 /* Same but slower, to use for migration, where the order of
  * RAMBlocks must not change. */
 void *qemu_safe_ram_ptr(ram_addr_t addr);
+void qemu_put_ram_ptr(void *addr);
 /* This should not be used by devices.  */
 int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr);
 ram_addr_t qemu_ram_addr_from_host_nofail(void *ptr);
exec.c +10 -0
index 558595a..3f3caaa 100644
@@ -3007,6 +3007,13 @@ void *qemu_safe_ram_ptr(ram_addr_t addr)
     return NULL;
 }
 
+void qemu_put_ram_ptr(void *addr)
+{
+    if (xen_mapcache_enabled()) {
+        qemu_map_cache_unlock(addr);
+    }
+}
+
 int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr)
 {
     RAMBlock *block;
@@ -3722,6 +3729,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
                     cpu_physical_memory_set_dirty_flags(
                         addr1, (0xff & ~CODE_DIRTY_FLAG));
                 }
+                qemu_put_ram_ptr(ptr);
             }
         } else {
             if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM &&
@@ -3752,6 +3760,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
                 ptr = qemu_get_ram_ptr(pd & TARGET_PAGE_MASK) +
                     (addr & ~TARGET_PAGE_MASK);
                 memcpy(buf, ptr, l);
+                qemu_put_ram_ptr(ptr);
             }
         }
         len -= l;
@@ -3792,6 +3801,7 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr,
             /* ROM/RAM case */
             ptr = qemu_get_ram_ptr(addr1);
             memcpy(ptr, buf, l);
+            qemu_put_ram_ptr(ptr);
         }
         len -= l;
         buf += l;
xen-mapcache.c +34 -0
index d7f44a7..6398456 100644
@@ -195,6 +195,40 @@ uint8_t *qemu_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, u
     return mapcache->last_address_vaddr + address_offset;
 }
 
+void qemu_map_cache_unlock(void *buffer)
+{
+    MapCacheEntry *entry = NULL, *pentry = NULL;
+    MapCacheRev *reventry;
+    target_phys_addr_t paddr_index;
+    int found = 0;
+
+    QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) {
+        if (reventry->vaddr_req == buffer) {
+            paddr_index = reventry->paddr_index;
+            found = 1;
+            break;
+        }
+    }
+    if (!found) {
+        return;
+    }
+    QTAILQ_REMOVE(&mapcache->locked_entries, reventry, next);
+    qemu_free(reventry);
+
+    entry = &mapcache->entry[paddr_index % mapcache->nr_buckets];
+    while (entry && entry->paddr_index != paddr_index) {
+        pentry = entry;
+        entry = entry->next;
+    }
+    if (!entry) {
+        return;
+    }
+    entry->lock--;
+    if (entry->lock > 0) {
+        entry->lock--;
+    }
+}
+
 ram_addr_t qemu_ram_addr_from_mapcache(void *ptr)
 {
     MapCacheRev *reventry;
Signature · 1 line
1.7.2.3
#21 lore raw

Re: [Qemu-devel] [PATCH V11 11/15] Introduce qemu_put_ram_ptr

This seems to leak entries on the map cache locked entries list. Patch below:

---
 exec.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
exec.c +2 -3
index 1f88d6a..f18cb7d 100644
@@ -3759,9 +3759,8 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
                 }
             } else {
                 /* RAM case */
-                ptr = qemu_get_ram_ptr(pd&  TARGET_PAGE_MASK) +
-                    (addr&  ~TARGET_PAGE_MASK);
-                memcpy(buf, ptr, l);
+                ptr = qemu_get_ram_ptr(pd&  TARGET_PAGE_MASK);
+                memcpy(buf, ptr + (addr&  ~TARGET_PAGE_MASK), l);
                 qemu_put_ram_ptr(ptr);
             }
         }
Signature · 1 line
1.7.0.4
Quoted 113 lines · On 03/01/2011 01:35 PM, [email protected] wrote:

From: Anthony PERARD<[email protected]>

This function allows to unlock a ram_ptr give by qemu_get_ram_ptr. After a call to qemu_put_ram_ptr, the pointer may be unmap from QEMU when used with Xen.

---
  cpu-common.h   |    1 +
  exec.c         |   10 ++++++++++
  xen-mapcache.c |   34 ++++++++++++++++++++++++++++++++++
  3 files changed, 45 insertions(+), 0 deletions(-)
cpu-common.h +1 -0
index 54d21d4..1f1c886 100644
@@ -55,6 +55,7 @@ void *qemu_get_ram_ptr(ram_addr_t addr);
  /* Same but slower, to use for migration, where the order of
   * RAMBlocks must not change. */
  void *qemu_safe_ram_ptr(ram_addr_t addr);
+void qemu_put_ram_ptr(void *addr);
  /* This should not be used by devices.  */
  int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr);
  ram_addr_t qemu_ram_addr_from_host_nofail(void *ptr);
exec.c +10 -0
index 558595a..3f3caaa 100644
@@ -3007,6 +3007,13 @@ void *qemu_safe_ram_ptr(ram_addr_t addr)
      return NULL;
  }
 
+void qemu_put_ram_ptr(void *addr)
+{
+    if (xen_mapcache_enabled()) {
+        qemu_map_cache_unlock(addr);
+    }
+}
+
  int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr)
  {
      RAMBlock *block;
@@ -3722,6 +3729,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
                      cpu_physical_memory_set_dirty_flags(
                          addr1, (0xff&  ~CODE_DIRTY_FLAG));
                  }
+                qemu_put_ram_ptr(ptr);
              }
          } else {
              if ((pd&  ~TARGET_PAGE_MASK)>  IO_MEM_ROM&&
@@ -3752,6 +3760,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
                  ptr = qemu_get_ram_ptr(pd&  TARGET_PAGE_MASK) +
                      (addr&  ~TARGET_PAGE_MASK);
                  memcpy(buf, ptr, l);
+                qemu_put_ram_ptr(ptr);
              }
          }
          len -= l;
@@ -3792,6 +3801,7 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr,
              /* ROM/RAM case */
              ptr = qemu_get_ram_ptr(addr1);
              memcpy(ptr, buf, l);
+            qemu_put_ram_ptr(ptr);
          }
          len -= l;
          buf += l;
xen-mapcache.c +34 -0
index d7f44a7..6398456 100644
@@ -195,6 +195,40 @@ uint8_t *qemu_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, u
      return mapcache->last_address_vaddr + address_offset;
  }
 
+void qemu_map_cache_unlock(void *buffer)
+{
+    MapCacheEntry *entry = NULL, *pentry = NULL;
+    MapCacheRev *reventry;
+    target_phys_addr_t paddr_index;
+    int found = 0;
+
+    QTAILQ_FOREACH(reventry,&mapcache->locked_entries, next) {
+        if (reventry->vaddr_req == buffer) {
+            paddr_index = reventry->paddr_index;
+            found = 1;
+            break;
+        }
+    }
+    if (!found) {
+        return;
+    }
+    QTAILQ_REMOVE(&mapcache->locked_entries, reventry, next);
+    qemu_free(reventry);
+
+    entry =&mapcache->entry[paddr_index % mapcache->nr_buckets];
+    while (entry&&  entry->paddr_index != paddr_index) {
+        pentry = entry;
+        entry = entry->next;
+    }
+    if (!entry) {
+        return;
+    }
+    entry->lock--;
+    if (entry->lock>  0) {
+        entry->lock--;
+    }
+}
+
  ram_addr_t qemu_ram_addr_from_mapcache(void *ptr)
  {
      MapCacheRev *reventry;
#22 lore raw

PATCH v11 12/15 vl.c: Introduce getter for shutdown_requested and reset_requested.

In reply to [email protected]

From: Anthony PERARD <[email protected]>

Introduce two functions qemu_shutdown_requested_get and qemu_reset_requested_get to get the value of shutdown/reset_requested without reset it.

---
 sysemu.h |    2 ++
 vl.c     |   10 ++++++++++
 2 files changed, 12 insertions(+), 0 deletions(-)
sysemu.h +2 -0
index 0a83ab9..37992b6 100644
@@ -63,6 +63,8 @@ void qemu_system_shutdown_request(void);
 void qemu_system_powerdown_request(void);
 void qemu_system_debug_request(void);
 void qemu_system_vmstop_request(int reason);
+int qemu_shutdown_requested_get(void);
+int qemu_reset_requested_get(void);
 int qemu_shutdown_requested(void);
 int qemu_reset_requested(void);
 int qemu_powerdown_requested(void);
vl.c +10 -0
index 910b000..f7d317e 100644
@@ -1222,6 +1222,16 @@ static int powerdown_requested;
 static int debug_requested;
 static int vmstop_requested;
 
+int qemu_shutdown_requested_get(void)
+{
+    return shutdown_requested;
+}
+
+int qemu_reset_requested_get(void)
+{
+    return reset_requested;
+}
+
 int qemu_shutdown_requested(void)
 {
     int r = shutdown_requested;
Signature · 1 line
1.7.2.3
#23 lore raw

PATCH v11 13/15 xen: Initialize event channels and io rings

In reply to [email protected]

From: Arun Sharma <[email protected]>

Open and bind event channels; map ioreq and buffered ioreq rings.

---
 hw/xen_common.h |    2 +
 xen-all.c       |  411 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 413 insertions(+), 0 deletions(-)
hw/xen_common.h +2 -0
index 5a36642..a5fc74b 100644
@@ -76,4 +76,6 @@ static inline int xc_fd(xc_interface *xen_xc)
 }
 #endif
 
+void destroy_hvm_domain(void);
+
 #endif /* QEMU_HW_XEN_COMMON_H */
xen-all.c +411 -0

442 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#24 lore raw

Re: [Qemu-devel] [PATCH V11 13/15] xen: Initialize event channels and io rings

Quoted 55 lines · On 01.03.2011, at 19:35, [email protected] wrote:

From: Arun Sharma <[email protected]>

Open and bind event channels; map ioreq and buffered ioreq rings.

---
hw/xen_common.h | 2 +
xen-all.c | 411 +++++++++++++++++++++++++++++++++++++++++++++++++++++++

2 files changed, 413 insertions(+), 0 deletions(-)
hw/xen_common.h +2 -0
index 5a36642..a5fc74b 100644
@@ -76,4 +76,6 @@ static inline int xc_fd(xc_interface *xen_xc)
 }
 #endif
 
+void destroy_hvm_domain(void);
+
 #endif /* QEMU_HW_XEN_COMMON_H */
xen-all.c +17 -0
index 03d1e90..f96fd7d 100644
@@ -6,12 +6,58 @@
 *
 */
 
+#include <sys/mman.h>
+
 #include "hw/pci.h"
 #include "hw/xen_common.h"
 #include "hw/xen_backend.h"
 
 #include "xen-mapcache.h"
 
+#include <xen/hvm/ioreq.h>
+#include <xen/hvm/params.h>
+
+//#define DEBUG_XEN
+
+#ifdef DEBUG_XEN
+#define DPRINTF(fmt, ...) \
+    do { fprintf(stderr, "xen: " fmt, ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...) \
+    do { } while (0)
+#endif
+
+/* Compatibility with older version */
+#if __XEN_LATEST_INTERFACE_VERSION__ < 0x0003020a

xen-all.c line 41

Quoted 10 lines
xen-all.c +10 -0
+#  define xen_vcpu_eport(shared_page, i) \
+    (shared_page->vcpu_iodata[i].vp_eport)
+#  define xen_vcpu_ioreq(shared_page, vcpu) \
+    (shared_page->vcpu_iodata[vcpu].vp_ioreq)
+#  define FMT_ioreq_size PRIx64
+#else
+#  define xen_vcpu_eport(shared_page, i) \
+    (shared_page->vcpu_ioreq[i].vp_eport)
+#  define xen_vcpu_ioreq(shared_page, vcpu) \
+    (shared_page->vcpu_ioreq[vcpu])

Could you please change these to static inline functions?

Alex

#25 lore raw

Re: [Xen-devel] Re: [Qemu-devel] [PATCH V11 13/15] xen: Initialize event channels and io rings

Quoted 6 lines · Alexander Graf
Quoted 6 lines
xen-all.c +6 -0
+/* Compatibility with older version */
+#if __XEN_LATEST_INTERFACE_VERSION__ < 0x0003020a
+#  define xen_vcpu_eport(shared_page, i) \
+    (shared_page->vcpu_iodata[i].vp_eport)
+#  define xen_vcpu_ioreq(shared_page, vcpu) \
+    (shared_page->vcpu_iodata[vcpu].vp_ioreq)
Quoted 8 lines

xen-all.c line 41

Quoted 6 lines
xen-all.c +6 -0
+#  define FMT_ioreq_size PRIx64
+#else
+#  define xen_vcpu_eport(shared_page, i) \
+    (shared_page->vcpu_ioreq[i].vp_eport)
+#  define xen_vcpu_ioreq(shared_page, vcpu) \
+    (shared_page->vcpu_ioreq[vcpu])

Could you please change these to static inline functions?

Yes, I will do that.

Regards,

Signature · 1 line
Anthony PERARD
#26 lore raw

PATCH v11 14/15 xen: Set running state in xenstore.

In reply to [email protected]

From: Anthony PERARD <[email protected]>

This tells to the xen management tool that the machine can begin run.

---
 xen-all.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
xen-all.c +23 -0
index f96fd7d..279efd0 100644
@@ -55,6 +55,8 @@ typedef struct XenIOState {
     /* which vcpu we are serving */
     int send_vcpu;
 
+    struct xs_handle *xenstore;
+
     Notifier exit;
 } XenIOState;
 
@@ -423,6 +425,17 @@ static void cpu_handle_ioreq(void *opaque)
     }
 }
 
+static void xenstore_record_dm_state(XenIOState *s, const char *state)
+{
+    char path[50];
+
+    snprintf(path, sizeof (path), "/local/domain/0/device-model/%u/state", xen_domid);
+    if (!xs_write(s->xenstore, XBT_NULL, path, state, strlen(state))) {
+        fprintf(stderr, "error recording dm state\n");
+        exit(1);
+    }
+}
+
 static void xen_main_loop_prepare(XenIOState *state)
 {
     int evtchn_fd = -1;
@@ -438,6 +451,9 @@ static void xen_main_loop_prepare(XenIOState *state)
     if (evtchn_fd != -1) {
         qemu_set_fd_handler(evtchn_fd, cpu_handle_ioreq, NULL, state);
     }
+
+    /* record state running */
+    xenstore_record_dm_state(state, "running");
 }
 
 
@@ -456,6 +472,7 @@ static void xen_exit_notifier(Notifier *n)
     XenIOState *state = container_of(n, XenIOState, exit);
 
     xc_evtchn_close(state->xce_handle);
+    xs_daemon_close(state->xenstore);
 }
 
 int xen_init(void)
@@ -478,6 +495,12 @@ int xen_init(void)
         return -errno;
     }
 
+    state->xenstore = xs_daemon_open();
+    if (state->xenstore == NULL) {
+        perror("xen: xenstore open");
+        return -errno;
+    }
+
     state->exit.notify = xen_exit_notifier;
     qemu_add_exit_notifier(&state->exit);
 
Signature · 1 line
1.7.2.3
#27 lore raw

PATCH v11 15/15 xen: Add Xen hypercall for sleep state in the cmos_s3 callback.

In reply to [email protected]

From: Anthony PERARD <[email protected]>

---
 hw/pc_piix.c |    6 +++++-
 hw/xen.h     |    1 +
 xen-all.c    |    9 +++++++++
 xen-stub.c   |    4 ++++
 4 files changed, 19 insertions(+), 1 deletions(-)
hw/pc_piix.c +5 -1
index 1d55bc9..5ec7d7f 100644
@@ -181,7 +181,11 @@ static void pc_init1(ram_addr_t ram_size,
         uint8_t *eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
         i2c_bus *smbus;
 
-        cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
+        if (!xen_enabled()) {
+            cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
+        } else {
+            cmos_s3 = qemu_allocate_irqs(xen_cmos_set_s3_resume, rtc_state, 1);
+        }
         smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
         /* TODO: Populate SPD eeprom data.  */
         smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
hw/xen.h +1 -0
index e26d061..d8ee1e4 100644
@@ -43,6 +43,7 @@ static inline int xen_mapcache_enabled(void)
 int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
 void xen_piix3_set_irq(void *opaque, int irq_num, int level);
 void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len);
+void xen_cmos_set_s3_resume(void *opaque, int irq, int level);
 
 qemu_irq *xen_interrupt_controller_init(void);
 
xen-all.c +9 -0
index 279efd0..09e3792 100644
@@ -9,6 +9,7 @@
 #include <sys/mman.h>
 
 #include "hw/pci.h"
+#include "hw/pc.h"
 #include "hw/xen_common.h"
 #include "hw/xen_backend.h"
 
@@ -90,6 +91,14 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
     }
 }
 
+void xen_cmos_set_s3_resume(void *opaque, int irq, int level)
+{
+    pc_cmos_set_s3_resume(opaque, irq, level);
+    if (level) {
+        xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 3);
+    }
+}
+
 /* Xen Interrupt Controller */
 
 static void xen_set_irq(void *opaque, int irq, int level)
xen-stub.c +4 -0
index eebc223..718eb05 100644
@@ -22,6 +22,10 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
 {
 }
 
+void xen_cmos_set_s3_resume(void *opaque, int irq, int level)
+{
+}
+
 void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size)
 {
 }
Signature · 1 line
1.7.2.3
#28 lore raw
In reply to [email protected]
Quoted 18 lines · On 03/01/2011 12:35 PM, [email protected] wrote:

From: Anthony PERARD<[email protected]>

Hi all,

Here is the few change since the V10:

- Add braces for blocks with single statement in the clean-up patch;
- the patch that builds Xen only for x86 have been removed, instead, xen_domainbuild is built with libhw and other Xen files are built for i386 target only;
- the redirection structure with function pointer have been removed, instead,

     there are few #define or static inline function use for the compatibility;

- the platform device uses trace instead of dprintf for guest log;
- introduce i440fx_xen_init and i440fx_common_init to avoid xen_enabled() in piix_pci.

Quoted 5 lines

This series depends on the series "Introduce "machine" QemuOpts".

You can find a git tree here:

git://xenbits.xen.org/people/aperard/qemu-dm.git qemu-dm-v11

I'll go through this series as soon as I can, but I'd like Alex to review it to.

Alex, do you mind looking through these patches and Ack'ing as appropriate?

Regards,

Anthony Liguori

Quoted 62 lines

Anthony PERARD (12):
xen: Replace some tab-indents with spaces (clean-up).
xen: Make Xen build once.
xen: Support new libxc calls from xen unstable.
xen: Add initialisation of Xen
xen: Add xenfv machine
piix_pci: Introduces Xen specific call for irq.
xen: Introduce Xen Interrupt Controller
configure: Always use 64bits target physical addresses with xen
enabled.
Introduce qemu_put_ram_ptr
vl.c: Introduce getter for shutdown_requested and reset_requested.
xen: Set running state in xenstore.
xen: Add Xen hypercall for sleep state in the cmos_s3 callback.

Arun Sharma (1):
xen: Initialize event channels and io rings

Jun Nakajima (1):
xen: Introduce the Xen mapcache

Steven Smith (1):
xen: Add the Xen platform pci device

  Makefile.objs        |    3 +
  Makefile.target      |   16 ++-
  configure            |   71 ++++++-
  cpu-common.h         |    1 +
  exec.c               |   50 ++++-
  hw/hw.h              |    3 +
  hw/pc.c              |   19 ++-
  hw/pc.h              |    1 +
  hw/pc_piix.c         |   41 ++++-
  hw/pci_ids.h         |    2 +
  hw/piix_pci.c        |   47 ++++-
  hw/xen.h             |   41 ++++
  hw/xen_backend.c     |  422 ++++++++++++++++++++-----------------
  hw/xen_backend.h     |    6 +-
  hw/xen_common.h      |   75 ++++++--
  hw/xen_disk.c        |  496 +++++++++++++++++++++++--------------------
  hw/xen_domainbuild.c |   13 +-
  hw/xen_domainbuild.h |    5 +-
  hw/xen_machine_pv.c  |    2 +-
  hw/xen_nic.c         |  265 +++++++++++++-----------
  hw/xen_platform.c    |  349 ++++++++++++++++++++++++++++++
  sysemu.h             |    2 +
  trace-events         |    3 +
  vl.c                 |   12 +
  xen-all.c            |  573 ++++++++++++++++++++++++++++++++++++++++++++++++++
  xen-mapcache-stub.c  |   40 ++++
  xen-mapcache.c       |  344 ++++++++++++++++++++++++++++++
  xen-mapcache.h       |   22 ++
  xen-stub.c           |   45 ++++
  29 files changed, 2386 insertions(+), 583 deletions(-)

create mode 100644 hw/xen_platform.c
create mode 100644 xen-all.c
create mode 100644 xen-mapcache-stub.c
create mode 100644 xen-mapcache.c
create mode 100644 xen-mapcache.h
create mode 100644 xen-stub.c

#29 lore raw
Quoted 21 lines · Anthony Liguori
Quoted 20 lines · On 03/01/2011 12:35 PM, [email protected] wrote:

From: Anthony PERARD<[email protected]>

Hi all,

Here is the few change since the V10:

- Add braces for blocks with single statement in the clean-up patch;
- the patch that builds Xen only for x86 have been removed, instead, xen_domainbuild is built with libhw and other Xen files are built for i386 target only;
- the redirection structure with function pointer have been removed, instead,

    there are few #define or static inline function use for the compatibility;

- the platform device uses trace instead of dprintf for guest log;
- introduce i440fx_xen_init and i440fx_common_init to avoid xen_enabled() in piix_pci.

This series depends on the series "Introduce "machine" QemuOpts".

Quoted 7 lines
Quoted 3 lines

You can find a git tree here:

git://xenbits.xen.org/people/aperard/qemu-dm.git qemu-dm-v11

I'll go through this series as soon as I can, but I'd like Alex to review it to.

Alex, do you mind looking through these patches and Ack'ing as appropriate?

Oh, sure. I was mostly waiting for others to comment on it before I go through it and ack it again. Has it evolved to that point now? I'd gladly go through and ack everything as appropriate then.

Alex

#30 lore raw
In reply to [email protected]
Quoted 4 lines · On 03/01/2011 07:35 PM, [email protected] wrote:

From: Anthony PERARD<[email protected]>

Hi all,

Quoted 8 lines

Here is the few change since the V10:

- Add braces for blocks with single statement in the clean-up patch;
- the patch that builds Xen only for x86 have been removed, instead, xen_domainbuild is built with libhw and other Xen files are built for i386 target only;
- the redirection structure with function pointer have been removed, instead,

     there are few #define or static inline function use for the compatibility;

ARGH!

The point of the redirection structure was so I can plug in with xenner and replace all the xen calls with in-qemu versions. If you remove it, I'll have to put it back in in the xenner patch set :(.

We need some sort of abstraction between calling xs_ functions and actually calling them. Wrapping all xs_ calls in static inlines would be fine for that, as would the indirect calling table.

Alex

#31 lore raw
Quoted 20 lines · Alexander Graf
Quoted 7 lines · On 03/01/2011 07:35 PM, [email protected] wrote:

From: Anthony PERARD<[email protected]>

Hi all,

Here is the few change since the V10:

Quoted 9 lines

  - Add braces for blocks with single statement in the clean-up patch;
  - the patch that builds Xen only for x86 have been removed, instead, xen_domainbuild is built with libhw and other Xen files are built for i386
    target only;
  - the redirection structure with function pointer have been removed, instead,
    there are few #define or static inline function use for the compatibility;

ARGH!

Quoted 7 lines

The point of the redirection structure was so I can plug in with xenner and replace all the xen calls with in-qemu versions. If you remove it, I'll have to put it back in in the xenner patch set :(.

We need some sort of abstraction between calling xs_ functions and actually calling them. Wrapping all xs_ calls in static inlines would be fine for that, as would the indirect calling table.

As my series doesn't change a lot of things in the xen code, I think it is better than you put it back in your patch set.

Regards,

Signature · 1 line
Anthony PERARD
#32 lore raw
Quoted 23 lines · Anthony PERARD
Quoted 22 lines · Alexander Graf
Quoted 10 lines · On 03/01/2011 07:35 PM, [email protected] wrote:

From: Anthony PERARD<[email protected]>

Hi all,

Here is the few change since the V10:

- Add braces for blocks with single statement in the clean-up patch;
- the patch that builds Xen only for x86 have been removed, instead, xen_domainbuild is built with libhw and other Xen files are built for
i386

Quoted 5 lines
     target only;

- the redirection structure with function pointer have been removed,
instead,
there are few #define or static inline function use for the
compatibility;

ARGH!

The point of the redirection structure was so I can plug in with xenner and replace all the xen calls with in-qemu versions. If you remove it, I'll have to put it back in in the xenner patch set :(.

Quoted 5 lines
Quoted 3 lines

We need some sort of abstraction between calling xs_ functions and actually calling them. Wrapping all xs_ calls in static inlines would be fine for that, as would the indirect calling table.

As my series doesn't change a lot of things in the xen code, I think it is better than you put it back in your patch set.

Ok, I'll try to see if I can get things based on top of your patch set, then do actual code review.

Alex

#33 lore raw
In reply to Anthony PERARD
Quoted 23 lines · Anthony PERARD
Quoted 22 lines · Alexander Graf
Quoted 10 lines · On 03/01/2011 07:35 PM, [email protected] wrote:

From: Anthony PERARD<[email protected]>

Hi all,

Here is the few change since the V10:

- Add braces for blocks with single statement in the clean-up patch;
- the patch that builds Xen only for x86 have been removed, instead, xen_domainbuild is built with libhw and other Xen files are built for
i386

Quoted 5 lines
     target only;

- the redirection structure with function pointer have been removed,
instead,
there are few #define or static inline function use for the
compatibility;

ARGH!

The point of the redirection structure was so I can plug in with xenner and replace all the xen calls with in-qemu versions. If you remove it, I'll have to put it back in in the xenner patch set :(.

Quoted 5 lines
Quoted 3 lines

We need some sort of abstraction between calling xs_ functions and actually calling them. Wrapping all xs_ calls in static inlines would be fine for that, as would the indirect calling table.

As my series doesn't change a lot of things in the xen code, I think it is better than you put it back in your patch set.

Hrm. This is on a SLES11SP1 system w/ Xen 4.0.1.

Alex

agraf@toonie:/dev/shm> git clone git://xenbits.xen.org/people/aperard/qemu-dm.git
Initialized empty Git repository in /dev/shm/qemu-dm/.git/
remote: Counting objects: 74570, done.
remote: Compressing objects: 100% (15699/15699), done.
remote: Total 74570 (delta 59960), reused 73357 (delta 58769)
Receiving objects: 100% (74570/74570), 22.24 MiB | 1296 KiB/s, done. Resolving deltas: 100% (59960/59960), done.
agraf@toonie:/dev/shm/qemu-dm> git checkout origin/qemu-dm-v11
Note: moving to "origin/qemu-dm-v11" which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
git checkout -b <new_branch_name>
HEAD is now at 47d548f... xen: Add Xen hypercall for sleep state in the cmos_s3 callback. agraf@toonie:/dev/shm/qemu-dm> ./configure --target-list=x86_64-softmmu make -j

Install prefix    /usr/local
BIOS directory    /usr/local/share/qemu
binary directory  /usr/local/bin
config directory  /usr/local/etc
Manual directory  /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path       /dev/shm/qemu-dm
C compiler        gcc
Host C compiler   gcc
CFLAGS            -O2 -g
QEMU_CFLAGS       -Werror -m64 -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing  -fstack-protector-all -Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits
LDFLAGS           -Wl,--warn-common -m64 -g
make              make
install           install
host CPU          x86_64
host big endian   no
target list       x86_64-softmmu
tcg debug enabled no
Mon debug enabled no
gprof enabled     no
sparse enabled    no
strip binaries    yes
profiler          no
static build      no
-Werror enabled   yes
SDL support       yes
curses support    yes
curl support      yes
check support     no
mingw32 support   no
Audio drivers     oss
Extra audio cards ac97 es1370 sb16 hda
Block whitelist
Mixer emulation   no
VNC TLS support   no
VNC SASL support  no
VNC JPEG support  yes
VNC PNG support   yes
VNC thread        no
xen support       yes
brlapi support    no
bluez  support    no
Documentation     yes
NPTL support      yes
GUEST_BASE        yes
PIE user targets  no
vde support       no
IO thread         no
Linux AIO support no
ATTR/XATTR support yes
Install blobs     yes
KVM support       yes
fdt support       no
preadv support    yes
fdatasync         yes
madvise           yes
posix_madvise     yes
uuid support      yes
vhost-net support no
Trace backend     nop
Trace output file trace-<pid>
spice support     no
rbd support       no
xfsctl support    no
agraf@toonie:/dev/shm/qemu-dm> make -j
  GEN   x86_64-softmmu/config-devices.mak
  GEN   config-all-devices.mak
  GEN   qemu-options.texi
  GEN   qemu-img-cmds.texi
  GEN   qemu-monitor.texi
  GEN   qemu-nbd.8
  GEN   qemu-tech.html
  GEN   config-host.h
  GEN   QMP/qmp-commands.txt
  GEN   trace.h
  GEN   qemu-options.def
  GEN   trace.c
  GEN   qemu-img-cmds.h
  GEN   qemu-img.1
  AS    optionrom/multiboot.o
  AS    optionrom/linuxboot.o
  Building optionrom/linuxboot.img
  Building optionrom/multiboot.img
  Building optionrom/linuxboot.raw
  Building optionrom/multiboot.raw
  Signing optionrom/multiboot.bin
  Signing optionrom/linuxboot.bin
  GEN   qemu-doc.html
  GEN   qemu.1
  CC    qemu-nbd.o
  CC    qemu-tool.o
  CC    qemu-error.o
  CC    osdep.o
  CC    oslib-posix.o
  CC    trace.o
  CC    cutils.o
  CC    qemu-option.o
  CC    module.o
  CC    nbd.o
  CC    block.o
  CC    qemu-malloc.o
  CC    cache-utils.o
  CC    aio.o
  CC    aes.o
  CC    qemu-config.o
  CC    posix-aio-compat.o
  CC    block/raw.o
  CC    block/cow.o
  CC    block/qcow.o
  CC    block/vdi.o
  CC    block/vmdk.o
  CC    block/cloop.o
  CC    block/dmg.o
  CC    block/bochs.o
  CC    block/vpc.o
  CC    block/vvfat.o
  CC    block/qcow2.o
  CC    block/qcow2-refcount.o
  CC    block/qcow2-cluster.o
  CC    block/qcow2-snapshot.o
  CC    block/qcow2-cache.o
  CC    block/qed.o
  CC    block/qed-gencb.o
  CC    block/qed-l2-cache.o
  CC    block/qed-table.o
  CC    block/qed-cluster.o
  CC    block/qed-check.o
  CC    block/parallels.o
  CC    block/nbd.o
  CC    block/blkdebug.o
  CC    block/sheepdog.o
  CC    block/blkverify.o
  CC    block/raw-posix.o
  CC    block/curl.o
  CC    qint.o
  CC    qstring.o
  CC    qdict.o
  CC    qlist.o
  CC    qfloat.o
  CC    qbool.o
  CC    qjson.o
  CC    json-lexer.o
  CC    json-streamer.o
  CC    json-parser.o
  CC    qerror.o
  CC    qemu-timer-common.o
  CC    qemu-img.o
  CC    qemu-io.o
  CC    cmd.o
  CC    blockdev.o
  CC    net.o
  CC    libhw64/vl.o
  CC    libhw64/virtio.o
  CC    libhw64/loader.o
  CC    net/queue.o
  CC    libhw64/virtio-console.o
  CC    libhw64/fw_cfg.o
  CC    net/checksum.o
  CC    net/util.o
  CC    libhw64/pci.o
  CC    net/socket.o
  CC    libhw64/pci_bridge.o
  CC    libhw64/msix.o
  CC    net/dump.o
  CC    libhw64/msi.o
  CC    libhw64/pci_host.o
  CC    libhw64/pcie_host.o
  CC    libhw64/ioh3420.o
  CC    net/tap.o
  CC    libhw64/xio3130_upstream.o
  CC    net/tap-linux.o
  CC    fsdev/qemu-fsdev.o
  CC    net/slirp.o
  CC    libhw64/xio3130_downstream.o
  CC    libhw64/watchdog.o
  CC    libhw64/serial.o
  CC    libhw64/parallel.o
  CC    readline.o
  CC    console.o
  CC    libhw64/i8254.o
  CC    libhw64/pcspk.o
  CC    cursor.o
  CC    libhw64/pckbd.o
  CC    async.o
  CC    os-posix.o
  CC    tcg-runtime.o
  CC    host-utils.o
  CC    irq.o
  CC    libhw64/usb-uhci.o
  CC    libhw64/usb-ohci.o
  CC    ioport.o
  CC    libhw64/fdc.o
  CC    libhw64/acpi.o
  CC    libhw64/acpi_piix4.o
  CC    input.o
  CC    libhw64/pm_smbus.o
  CC    libhw64/apm.o
  CC    i2c.o
  CC    libhw64/dma.o
  CC    smbus.o
  CC    libhw64/hpet.o
  CC    smbus_eeprom.o
  CC    libhw64/applesmc.o
  CC    eeprom93xx.o
  CC    libhw64/wdt_i6300esb.o
  CC    scsi-disk.o
  CC    libhw64/pcie.o
  CC    cdrom.o
  CC    scsi-generic.o
  CC    libhw64/pcie_aer.o
  CC    libhw64/pcie_port.o
  CC    scsi-bus.o
  CC    usb.o
  CC    libhw64/ne2000.o
  CC    usb-hub.o
  CC    usb-linux.o
  CC    libhw64/eepro100.o
  CC    usb-hid.o
  CC    usb-msd.o
  CC    usb-wacom.o
  CC    libhw64/pcnet-pci.o
  CC    usb-serial.o
  CC    usb-net.o
  CC    libhw64/pcnet.o
  CC    usb-bus.o
  CC    usb-desc.o
  CC    libhw64/e1000.o
  CC    libhw64/rtl8139.o
  CC    bt.o
  CC    libhw64/ne2000-isa.o
  CC    libhw64/ide/core.o
  CC    libhw64/ide/qdev.o
  CC    bt-host.o
  CC    libhw64/ide/pci.o
  CC    bt-vhci.o
  CC    libhw64/ide/isa.o
  CC    bt-l2cap.o
  CC    bt-sdp.o
  CC    libhw64/ide/piix.o
  CC    bt-hci.o
  CC    bt-hid.o
  CC    usb-bt.o
  CC    libhw64/ide/ahci.o
  CC    bt-hci-csr.o
  CC    buffered_file.o
  CC    libhw64/ide/ich.o
  CC    migration.o
  CC    migration-tcp.o
  CC    qemu-sockets.o
  CC    libhw64/lsi53c895a.o
  CC    qemu-char.o
  CC    libhw64/dma-helpers.o
  CC    savevm.o
  CC    msmouse.o
  CC    libhw64/sysbus.o
  CC    libhw64/isa-bus.o
  CC    libhw64/qdev-addr.o
  CC    ps2.o
  CC    libhw64/vga-pci.o
  CC    qdev.o
  CC    libhw64/vga-isa.o
  CC    qdev-properties.o
  CC    block-migration.o
  CC    libhw64/vmware_vga.o
  CC    pflib.o
  CC    libhw64/xen_domainbuild.o
  CC    libhw64/sb16.o
  CC    bitmap.o
  CC    bitops.o
  CC    libhw64/es1370.o
  CC    migration-exec.o
  CC    migration-unix.o
  CC    libhw64/ac97.o
  CC    migration-fd.o
  CC    audio/audio.o
  CC    libhw64/intel-hda.o
  CC    audio/noaudio.o
  CC    libhw64/hda-audio.o
  CC    libhw64/virtio-9p-debug.o
  CC    audio/wavaudio.o
  CC    libhw64/virtio-9p-local.o
  CC    audio/mixeng.o
  CC    audio/sdlaudio.o
  CC    libhw64/virtio-9p-xattr.o
  CC    audio/ossaudio.o
  CC    libhw64/virtio-9p-xattr-user.o
  CC    libhw64/virtio-9p-posix-acl.o
  CC    audio/wavcapture.o
  CC    ui/keymaps.o
  CC    ui/sdl.o
  CC    ui/sdl_zoom.o
  CC    ui/x_keymap.o
  CC    ui/curses.o
  CC    ui/vnc.o
  CC    ui/d3des.o
  CC    ui/vnc-enc-zlib.o
  CC    ui/vnc-enc-hextile.o
  CC    ui/vnc-enc-tight.o
  CC    ui/vnc-palette.o
  CC    ui/vnc-enc-zrle.o
  CC    ui/vnc-jobs-sync.o
  CC    iov.o
  CC    acl.o
  CC    compatfd.o
  CC    notify.o
  CC    event_notifier.o
  CC    qemu-timer.o
  CC    slirp/cksum.o
  CC    slirp/if.o
  CC    slirp/ip_icmp.o
  CC    slirp/ip_input.o
  CC    slirp/ip_output.o
  CC    slirp/slirp.o
  CC    slirp/mbuf.o
  CC    slirp/misc.o
  CC    slirp/sbuf.o
  CC    slirp/socket.o
  CC    slirp/tcp_input.o
  CC    slirp/tcp_output.o
  CC    slirp/tcp_subr.o
  CC    slirp/tcp_timer.o
  CC    slirp/udp.o
  CC    slirp/bootp.o
  CC    slirp/tftp.o
  CC    xen_backend.o
  CC    xen_devconfig.o
  CC    xen_console.o
  CC    xenfb.o
  CC    xen_disk.o
  CC    xen_nic.o
  CC    libdis/i386-dis.o
  LINK  qemu-nbd
  LINK  qemu-img
  LINK  qemu-io
rm multiboot.o linuxboot.raw linuxboot.img multiboot.raw multiboot.img linuxboot.o
  GEN   config-target.h
  GEN   x86_64-softmmu/qmp-commands.h
  GEN   x86_64-softmmu/hmp-commands.h
  CC    x86_64-softmmu/arch_init.o
  CC    x86_64-softmmu/cpus.o
  CC    x86_64-softmmu/gdbstub.o
  CC    x86_64-softmmu/virtio-pci.o
  CC    x86_64-softmmu/vhost_net.o
  CC    x86_64-softmmu/machine.o
  CC    x86_64-softmmu/balloon.o
  CC    x86_64-softmmu/virtio-blk.o
  CC    x86_64-softmmu/virtio-balloon.o
  CC    x86_64-softmmu/virtio-net.o
  CC    x86_64-softmmu/virtio-serial-bus.o
  CC    x86_64-softmmu/rwhandler.o
  CC    x86_64-softmmu/virtio-9p.o
  CC    x86_64-softmmu/kvm.o
  CC    x86_64-softmmu/kvm-all.o
  CC    x86_64-softmmu/xen-stub.o
  CC    x86_64-softmmu/ivshmem.o
  CC    x86_64-softmmu/exec.o
  CC    x86_64-softmmu/translate-all.o
  CC    x86_64-softmmu/cpu-exec.o
  CC    x86_64-softmmu/translate.o
  CC    x86_64-softmmu/tcg/tcg.o
  CC    x86_64-softmmu/fpu/softfloat-native.o
  CC    x86_64-softmmu/op_helper.o
  CC    x86_64-softmmu/helper.o
  CC    x86_64-softmmu/cpuid.o
  CC    x86_64-softmmu/disas.o
  CC    x86_64-softmmu/xen_machine_pv.o
  CC    x86_64-softmmu/xen-all.o
  CC    x86_64-softmmu/xen-mapcache.o
  CC    x86_64-softmmu/xen_platform.o
  CC    x86_64-softmmu/vga.o
  CC    x86_64-softmmu/mc146818rtc.o
  CC    x86_64-softmmu/i8259.o
  CC    x86_64-softmmu/pc.o
  CC    x86_64-softmmu/cirrus_vga.o
  CC    x86_64-softmmu/apic.o
  CC    x86_64-softmmu/ioapic.o
  CC    x86_64-softmmu/piix_pci.o
  CC    x86_64-softmmu/vmport.o
  CC    x86_64-softmmu/device-hotplug.o
  CC    x86_64-softmmu/pci-hotplug.o
  CC    x86_64-softmmu/smbios.o
  CC    x86_64-softmmu/wdt_ib700.o
  CC    x86_64-softmmu/debugcon.o
  CC    x86_64-softmmu/multiboot.o
  CC    x86_64-softmmu/pc_piix.o
  CC    x86_64-softmmu/kvmclock.o
  CC    x86_64-softmmu/monitor.o
  LINK  x86_64-softmmu/qemu-system-x86_64

xen-all.o: In function `xen_pci_slot_get_pirq':
/dev/shm/qemu-dm/xen-all.c:67: multiple definition of `xen_pci_slot_get_pirq' xen-stub.o:/dev/shm/qemu-dm/xen-stub.c:13: first defined here
xen-all.o: In function `xen_init':
/dev/shm/qemu-dm/xen-all.c:488: multiple definition of `xen_init' xen-stub.o:/dev/shm/qemu-dm/xen-stub.c:43: first defined here
xen-all.o: In function `xen_ram_alloc':
/dev/shm/qemu-dm/xen-all.c:152: multiple definition of `xen_ram_alloc' xen-stub.o:/dev/shm/qemu-dm/xen-stub.c:30: first defined here
xen-all.o: In function `xen_interrupt_controller_init':
/dev/shm/qemu-dm/xen-all.c:110: multiple definition of `xen_interrupt_controller_init' xen-stub.o:/dev/shm/qemu-dm/xen-stub.c:34: first defined here
xen-all.o: In function `xen_cmos_set_s3_resume':
/dev/shm/qemu-dm/xen-all.c:95: multiple definition of `xen_cmos_set_s3_resume' xen-stub.o:/dev/shm/qemu-dm/xen-stub.c:26: first defined here
xen-all.o: In function `xen_piix_pci_write_config_client':
/dev/shm/qemu-dm/xen-all.c:78: multiple definition of `xen_piix_pci_write_config_client' xen-stub.o:/dev/shm/qemu-dm/xen-stub.c:22: first defined here
xen-all.o: In function `xen_piix3_set_irq':
/dev/shm/qemu-dm/xen-all.c:72: multiple definition of xen_piix3_set_irq' xen-stub.o:/dev/shm/qemu-dm/xen-stub.c:18: first defined here xen_platform.o: In function pci_xen_platform_init':
/dev/shm/qemu-dm/hw/xen_platform.c:327: multiple definition of `pci_xen_platform_init' xen-stub.o:/dev/shm/qemu-dm/xen-stub.c:39: first defined here
collect2: ld returned 1 exit status
make[1]: *** [qemu-system-x86_64] Error 1
make: *** [subdir-x86_64-softmmu] Error 2

#34 lore raw
Quoted 468 lines · Alexander Graf
Quoted 27 lines · Anthony PERARD
Quoted 26 lines · Alexander Graf
Quoted 13 lines · On 03/01/2011 07:35 PM, [email protected] wrote:

From: Anthony PERARD<[email protected]>

Hi all,

Here is the few change since the V10:

- Add braces for blocks with single statement in the clean-up
patch;
- the patch that builds Xen only for x86 have been removed,
instead,
xen_domainbuild is built with libhw and other Xen files are
built for
i386

Quoted 6 lines
     target only;

- the redirection structure with function pointer have been
removed,
instead,
there are few #define or static inline function use for the
compatibility;

ARGH!

The point of the redirection structure was so I can plug in with xenner and replace all the xen calls with in-qemu versions. If you remove it, I'll have to put it back in in the xenner patch set :(.

Quoted 5 lines
Quoted 3 lines

We need some sort of abstraction between calling xs_ functions and actually calling them. Wrapping all xs_ calls in static inlines would be fine for that, as would the indirect calling table.

As my series doesn't change a lot of things in the xen code, I think it is better than you put it back in your patch set.

Hrm. This is on a SLES11SP1 system w/ Xen 4.0.1.

Alex

agraf@toonie:/dev/shm> git clone git://xenbits.xen.org/people/aperard/qemu-dm.git
Initialized empty Git repository in /dev/shm/qemu-dm/.git/
remote: Counting objects: 74570, done.
remote: Compressing objects: 100% (15699/15699), done.
remote: Total 74570 (delta 59960), reused 73357 (delta 58769)
Receiving objects: 100% (74570/74570), 22.24 MiB | 1296 KiB/s, done. Resolving deltas: 100% (59960/59960), done.
agraf@toonie:/dev/shm/qemu-dm> git checkout origin/qemu-dm-v11
Note: moving to "origin/qemu-dm-v11" which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
git checkout -b <new_branch_name>
HEAD is now at 47d548f... xen: Add Xen hypercall for sleep state in the cmos_s3 callback. agraf@toonie:/dev/shm/qemu-dm> ./configure --target-list=x86_64-softmmu make -j

Install prefix    /usr/local
BIOS directory    /usr/local/share/qemu
binary directory  /usr/local/bin
config directory  /usr/local/etc
Manual directory  /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path       /dev/shm/qemu-dm
C compiler        gcc
Host C compiler   gcc
CFLAGS            -O2 -g
QEMU_CFLAGS       -Werror -m64 -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE 
(quoted diff) +0 -6
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes 
-Wredundant-decls -Wall -Wundef -Wendif-labels -Wwrite-strings 
-Wmissing-prototypes -fno-strict-aliasing  -fstack-protector-all 
-Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security 
-Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration 
-Wold-style-definition -Wtype-limits
LDFLAGS           -Wl,--warn-common -m64 -g
make              make
install           install
host CPU          x86_64
host big endian   no
target list       x86_64-softmmu
tcg debug enabled no
Mon debug enabled no
gprof enabled     no
sparse enabled    no
strip binaries    yes
profiler          no
static build      no
-Werror enabled   yes
SDL support       yes
curses support    yes
curl support      yes
check support     no
mingw32 support   no
Audio drivers     oss
Extra audio cards ac97 es1370 sb16 hda
Block whitelist
Mixer emulation   no
VNC TLS support   no
VNC SASL support  no
VNC JPEG support  yes
VNC PNG support   yes
VNC thread        no
xen support       yes
brlapi support    no
bluez  support    no
Documentation     yes
NPTL support      yes
GUEST_BASE        yes
PIE user targets  no
vde support       no
IO thread         no
Linux AIO support no
ATTR/XATTR support yes
Install blobs     yes
KVM support       yes
fdt support       no
preadv support    yes
fdatasync         yes
madvise           yes
posix_madvise     yes
uuid support      yes
vhost-net support no
Trace backend     nop
Trace output file trace-<pid>
spice support     no
rbd support       no
xfsctl support    no
agraf@toonie:/dev/shm/qemu-dm> make -j
  GEN   x86_64-softmmu/config-devices.mak
  GEN   config-all-devices.mak
  GEN   qemu-options.texi
  GEN   qemu-img-cmds.texi
  GEN   qemu-monitor.texi
  GEN   qemu-nbd.8
  GEN   qemu-tech.html
  GEN   config-host.h
  GEN   QMP/qmp-commands.txt
  GEN   trace.h
  GEN   qemu-options.def
  GEN   trace.c
  GEN   qemu-img-cmds.h
  GEN   qemu-img.1
  AS    optionrom/multiboot.o
  AS    optionrom/linuxboot.o
  Building optionrom/linuxboot.img
  Building optionrom/multiboot.img
  Building optionrom/linuxboot.raw
  Building optionrom/multiboot.raw
  Signing optionrom/multiboot.bin
  Signing optionrom/linuxboot.bin
  GEN   qemu-doc.html
  GEN   qemu.1
  CC    qemu-nbd.o
  CC    qemu-tool.o
  CC    qemu-error.o
  CC    osdep.o
  CC    oslib-posix.o
  CC    trace.o
  CC    cutils.o
  CC    qemu-option.o
  CC    module.o
  CC    nbd.o
  CC    block.o
  CC    qemu-malloc.o
  CC    cache-utils.o
  CC    aio.o
  CC    aes.o
  CC    qemu-config.o
  CC    posix-aio-compat.o
  CC    block/raw.o
  CC    block/cow.o
  CC    block/qcow.o
  CC    block/vdi.o
  CC    block/vmdk.o
  CC    block/cloop.o
  CC    block/dmg.o
  CC    block/bochs.o
  CC    block/vpc.o
  CC    block/vvfat.o
  CC    block/qcow2.o
  CC    block/qcow2-refcount.o
  CC    block/qcow2-cluster.o
  CC    block/qcow2-snapshot.o
  CC    block/qcow2-cache.o
  CC    block/qed.o
  CC    block/qed-gencb.o
  CC    block/qed-l2-cache.o
  CC    block/qed-table.o
  CC    block/qed-cluster.o
  CC    block/qed-check.o
  CC    block/parallels.o
  CC    block/nbd.o
  CC    block/blkdebug.o
  CC    block/sheepdog.o
  CC    block/blkverify.o
  CC    block/raw-posix.o
  CC    block/curl.o
  CC    qint.o
  CC    qstring.o
  CC    qdict.o
  CC    qlist.o
  CC    qfloat.o
  CC    qbool.o
  CC    qjson.o
  CC    json-lexer.o
  CC    json-streamer.o
  CC    json-parser.o
  CC    qerror.o
  CC    qemu-timer-common.o
  CC    qemu-img.o
  CC    qemu-io.o
  CC    cmd.o
  CC    blockdev.o
  CC    net.o
  CC    libhw64/vl.o
  CC    libhw64/virtio.o
  CC    libhw64/loader.o
  CC    net/queue.o
  CC    libhw64/virtio-console.o
  CC    libhw64/fw_cfg.o
  CC    net/checksum.o
  CC    net/util.o
  CC    libhw64/pci.o
  CC    net/socket.o
  CC    libhw64/pci_bridge.o
  CC    libhw64/msix.o
  CC    net/dump.o
  CC    libhw64/msi.o
  CC    libhw64/pci_host.o
  CC    libhw64/pcie_host.o
  CC    libhw64/ioh3420.o
  CC    net/tap.o
  CC    libhw64/xio3130_upstream.o
  CC    net/tap-linux.o
  CC    fsdev/qemu-fsdev.o
  CC    net/slirp.o
  CC    libhw64/xio3130_downstream.o
  CC    libhw64/watchdog.o
  CC    libhw64/serial.o
  CC    libhw64/parallel.o
  CC    readline.o
  CC    console.o
  CC    libhw64/i8254.o
  CC    libhw64/pcspk.o
  CC    cursor.o
  CC    libhw64/pckbd.o
  CC    async.o
  CC    os-posix.o
  CC    tcg-runtime.o
  CC    host-utils.o
  CC    irq.o
  CC    libhw64/usb-uhci.o
  CC    libhw64/usb-ohci.o
  CC    ioport.o
  CC    libhw64/fdc.o
  CC    libhw64/acpi.o
  CC    libhw64/acpi_piix4.o
  CC    input.o
  CC    libhw64/pm_smbus.o
  CC    libhw64/apm.o
  CC    i2c.o
  CC    libhw64/dma.o
  CC    smbus.o
  CC    libhw64/hpet.o
  CC    smbus_eeprom.o
  CC    libhw64/applesmc.o
  CC    eeprom93xx.o
  CC    libhw64/wdt_i6300esb.o
  CC    scsi-disk.o
  CC    libhw64/pcie.o
  CC    cdrom.o
  CC    scsi-generic.o
  CC    libhw64/pcie_aer.o
  CC    libhw64/pcie_port.o
  CC    scsi-bus.o
  CC    usb.o
  CC    libhw64/ne2000.o
  CC    usb-hub.o
  CC    usb-linux.o
  CC    libhw64/eepro100.o
  CC    usb-hid.o
  CC    usb-msd.o
  CC    usb-wacom.o
  CC    libhw64/pcnet-pci.o
  CC    usb-serial.o
  CC    usb-net.o
  CC    libhw64/pcnet.o
  CC    usb-bus.o
  CC    usb-desc.o
  CC    libhw64/e1000.o
  CC    libhw64/rtl8139.o
  CC    bt.o
  CC    libhw64/ne2000-isa.o
  CC    libhw64/ide/core.o
  CC    libhw64/ide/qdev.o
  CC    bt-host.o
  CC    libhw64/ide/pci.o
  CC    bt-vhci.o
  CC    libhw64/ide/isa.o
  CC    bt-l2cap.o
  CC    bt-sdp.o
  CC    libhw64/ide/piix.o
  CC    bt-hci.o
  CC    bt-hid.o
  CC    usb-bt.o
  CC    libhw64/ide/ahci.o
  CC    bt-hci-csr.o
  CC    buffered_file.o
  CC    libhw64/ide/ich.o
  CC    migration.o
  CC    migration-tcp.o
  CC    qemu-sockets.o
  CC    libhw64/lsi53c895a.o
  CC    qemu-char.o
  CC    libhw64/dma-helpers.o
  CC    savevm.o
  CC    msmouse.o
  CC    libhw64/sysbus.o
  CC    libhw64/isa-bus.o
  CC    libhw64/qdev-addr.o
  CC    ps2.o
  CC    libhw64/vga-pci.o
  CC    qdev.o
  CC    libhw64/vga-isa.o
  CC    qdev-properties.o
  CC    block-migration.o
  CC    libhw64/vmware_vga.o
  CC    pflib.o
  CC    libhw64/xen_domainbuild.o
  CC    libhw64/sb16.o
  CC    bitmap.o
  CC    bitops.o
  CC    libhw64/es1370.o
  CC    migration-exec.o
  CC    migration-unix.o
  CC    libhw64/ac97.o
  CC    migration-fd.o
  CC    audio/audio.o
  CC    libhw64/intel-hda.o
  CC    audio/noaudio.o
  CC    libhw64/hda-audio.o
  CC    libhw64/virtio-9p-debug.o
  CC    audio/wavaudio.o
  CC    libhw64/virtio-9p-local.o
  CC    audio/mixeng.o
  CC    audio/sdlaudio.o
  CC    libhw64/virtio-9p-xattr.o
  CC    audio/ossaudio.o
  CC    libhw64/virtio-9p-xattr-user.o
  CC    libhw64/virtio-9p-posix-acl.o
  CC    audio/wavcapture.o
  CC    ui/keymaps.o
  CC    ui/sdl.o
  CC    ui/sdl_zoom.o
  CC    ui/x_keymap.o
  CC    ui/curses.o
  CC    ui/vnc.o
  CC    ui/d3des.o
  CC    ui/vnc-enc-zlib.o
  CC    ui/vnc-enc-hextile.o
  CC    ui/vnc-enc-tight.o
  CC    ui/vnc-palette.o
  CC    ui/vnc-enc-zrle.o
  CC    ui/vnc-jobs-sync.o
  CC    iov.o
  CC    acl.o
  CC    compatfd.o
  CC    notify.o
  CC    event_notifier.o
  CC    qemu-timer.o
  CC    slirp/cksum.o
  CC    slirp/if.o
  CC    slirp/ip_icmp.o
  CC    slirp/ip_input.o
  CC    slirp/ip_output.o
  CC    slirp/slirp.o
  CC    slirp/mbuf.o
  CC    slirp/misc.o
  CC    slirp/sbuf.o
  CC    slirp/socket.o
  CC    slirp/tcp_input.o
  CC    slirp/tcp_output.o
  CC    slirp/tcp_subr.o
  CC    slirp/tcp_timer.o
  CC    slirp/udp.o
  CC    slirp/bootp.o
  CC    slirp/tftp.o
  CC    xen_backend.o
  CC    xen_devconfig.o
  CC    xen_console.o
  CC    xenfb.o
  CC    xen_disk.o
  CC    xen_nic.o
  CC    libdis/i386-dis.o
  LINK  qemu-nbd
  LINK  qemu-img
  LINK  qemu-io
rm multiboot.o linuxboot.raw linuxboot.img multiboot.raw multiboot.img linuxboot.o
  GEN   config-target.h
  GEN   x86_64-softmmu/qmp-commands.h
  GEN   x86_64-softmmu/hmp-commands.h
  CC    x86_64-softmmu/arch_init.o
  CC    x86_64-softmmu/cpus.o
  CC    x86_64-softmmu/gdbstub.o
  CC    x86_64-softmmu/virtio-pci.o
  CC    x86_64-softmmu/vhost_net.o
  CC    x86_64-softmmu/machine.o
  CC    x86_64-softmmu/balloon.o
  CC    x86_64-softmmu/virtio-blk.o
  CC    x86_64-softmmu/virtio-balloon.o
  CC    x86_64-softmmu/virtio-net.o
  CC    x86_64-softmmu/virtio-serial-bus.o
  CC    x86_64-softmmu/rwhandler.o
  CC    x86_64-softmmu/virtio-9p.o
  CC    x86_64-softmmu/kvm.o
  CC    x86_64-softmmu/kvm-all.o
  CC    x86_64-softmmu/xen-stub.o
  CC    x86_64-softmmu/ivshmem.o
  CC    x86_64-softmmu/exec.o
  CC    x86_64-softmmu/translate-all.o
  CC    x86_64-softmmu/cpu-exec.o
  CC    x86_64-softmmu/translate.o
  CC    x86_64-softmmu/tcg/tcg.o
  CC    x86_64-softmmu/fpu/softfloat-native.o
  CC    x86_64-softmmu/op_helper.o
  CC    x86_64-softmmu/helper.o
  CC    x86_64-softmmu/cpuid.o
  CC    x86_64-softmmu/disas.o
  CC    x86_64-softmmu/xen_machine_pv.o
  CC    x86_64-softmmu/xen-all.o
  CC    x86_64-softmmu/xen-mapcache.o
  CC    x86_64-softmmu/xen_platform.o
  CC    x86_64-softmmu/vga.o
  CC    x86_64-softmmu/mc146818rtc.o
  CC    x86_64-softmmu/i8259.o
  CC    x86_64-softmmu/pc.o
  CC    x86_64-softmmu/cirrus_vga.o
  CC    x86_64-softmmu/apic.o
  CC    x86_64-softmmu/ioapic.o
  CC    x86_64-softmmu/piix_pci.o
  CC    x86_64-softmmu/vmport.o
  CC    x86_64-softmmu/device-hotplug.o
  CC    x86_64-softmmu/pci-hotplug.o
  CC    x86_64-softmmu/smbios.o
  CC    x86_64-softmmu/wdt_ib700.o
  CC    x86_64-softmmu/debugcon.o
  CC    x86_64-softmmu/multiboot.o
  CC    x86_64-softmmu/pc_piix.o
  CC    x86_64-softmmu/kvmclock.o
  CC    x86_64-softmmu/monitor.o
  LINK  x86_64-softmmu/qemu-system-x86_64

xen-all.o: In function `xen_pci_slot_get_pirq':
/dev/shm/qemu-dm/xen-all.c:67: multiple definition of `xen_pci_slot_get_pirq' xen-stub.o:/dev/shm/qemu-dm/xen-stub.c:13: first defined here
xen-all.o: In function `xen_init':
/dev/shm/qemu-dm/xen-all.c:488: multiple definition of `xen_init' xen-stub.o:/dev/shm/qemu-dm/xen-stub.c:43: first defined here
xen-all.o: In function `xen_ram_alloc':
/dev/shm/qemu-dm/xen-all.c:152: multiple definition of `xen_ram_alloc' xen-stub.o:/dev/shm/qemu-dm/xen-stub.c:30: first defined here
xen-all.o: In function `xen_interrupt_controller_init':
/dev/shm/qemu-dm/xen-all.c:110: multiple definition of `xen_interrupt_controller_init' xen-stub.o:/dev/shm/qemu-dm/xen-stub.c:34: first defined here
xen-all.o: In function `xen_cmos_set_s3_resume':
/dev/shm/qemu-dm/xen-all.c:95: multiple definition of `xen_cmos_set_s3_resume' xen-stub.o:/dev/shm/qemu-dm/xen-stub.c:26: first defined here
xen-all.o: In function `xen_piix_pci_write_config_client':
/dev/shm/qemu-dm/xen-all.c:78: multiple definition of `xen_piix_pci_write_config_client' xen-stub.o:/dev/shm/qemu-dm/xen-stub.c:22: first defined here
xen-all.o: In function `xen_piix3_set_irq':

Quoted 8 lines

/dev/shm/qemu-dm/xen-all.c:72: multiple definition of xen_piix3_set_irq' xen-stub.o:/dev/shm/qemu-dm/xen-stub.c:18: first defined here xen_platform.o: In function pci_xen_platform_init':
/dev/shm/qemu-dm/hw/xen_platform.c:327: multiple definition of `pci_xen_platform_init' xen-stub.o:/dev/shm/qemu-dm/xen-stub.c:39: first defined here
collect2: ld returned 1 exit status
make[1]: *** [qemu-system-x86_64] Error 1
make: *** [subdir-x86_64-softmmu] Error 2

This should be the correct fix:

Makefile.target +4 -3
index c0db745..91bbf39 100644
@@ -212,10 +212,11 @@ endif
 # xen backend driver support
 obj-i386-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
 
-ifeq ($(TARGET_ARCH), i386)
-CONFIG_NO_XEN = $(if $(subst n,,$(CONFIG_XEN)),n,y)
+ifeq ($(TARGET_BASE_ARCH),i386)
+  CONFIG_NO_KVM = $(if $(subst n,,$(CONFIG_KVM)),n,y)
 else
-CONFIG_NO_XEN = y
+  CONFIG_XEN =
+  CONFIG_NO_XEN = y
 endif
 # xen support
 CONFIG_NO_XEN_MAPCACHE = $(if $(subst n,,$(CONFIG_XEN_MAPCACHE)),n,y)
#35 lore raw
Quoted 12 lines · Alexander Graf
Quoted 1 line · Alexander Graf

make[1]: *** [qemu-system-x86_64] Error 1

This should be the correct fix:

Makefile.target +0 -0
index c0db745..91bbf39 100644

Makefile.target endif · line 216

Quoted 7 lines
Makefile.target +2 -2
@@ -212,10 +212,11 @@ endif
  # xen backend driver support
  obj-i386-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
 
-ifeq ($(TARGET_ARCH), i386)
-CONFIG_NO_XEN = $(if $(subst n,,$(CONFIG_XEN)),n,y)
+ifeq ($(TARGET_BASE_ARCH),i386)
+  CONFIG_NO_KVM = $(if $(subst n,,$(CONFIG_KVM)),n,y)

with 's/KVM/XEN/g'
;)

Makefile.target endif · line 222

Quoted 7 lines
Makefile.target +2 -1
  else
-CONFIG_NO_XEN = y
+  CONFIG_XEN =
+  CONFIG_NO_XEN = y
  endif
  # xen support
  CONFIG_NO_XEN_MAPCACHE = $(if $(subst n,,$(CONFIG_XEN_MAPCACHE)),n,y)

Yep, this is the fix.

Could you use this fix and continue to review ? or did I need to resend the all patch series ?

Regards,

Signature · 1 line
Anthony PERARD
#36 lore raw
Quoted 30 lines · Anthony PERARD
Quoted 11 lines · Alexander Graf
Quoted 1 line · Alexander Graf

make[1]: *** [qemu-system-x86_64] Error 1

This should be the correct fix:

Makefile.target +0 -0
index c0db745..91bbf39 100644

Makefile.target endif · line 216

Quoted 7 lines
Makefile.target +2 -2
@@ -212,10 +212,11 @@ endif
   # xen backend driver support
   obj-i386-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
 
-ifeq ($(TARGET_ARCH), i386)
-CONFIG_NO_XEN = $(if $(subst n,,$(CONFIG_XEN)),n,y)
+ifeq ($(TARGET_BASE_ARCH),i386)
+  CONFIG_NO_KVM = $(if $(subst n,,$(CONFIG_KVM)),n,y)

with 's/KVM/XEN/g'
;)

Makefile.target endif · line 222

Quoted 7 lines
Makefile.target +2 -1
   else
-CONFIG_NO_XEN = y
+  CONFIG_XEN =
+  CONFIG_NO_XEN = y
   endif
   # xen support
   CONFIG_NO_XEN_MAPCACHE = $(if $(subst n,,$(CONFIG_XEN_MAPCACHE)),n,y)
Quoted 4 lines

Yep, this is the fix.

Could you use this fix and continue to review ? or did I need to resend the all patch series ?

No, I'm still at it. It takes much longer than I expected :)

Alex

#37 lore raw
In reply to [email protected]
Quoted 6 lines · On 01.03.2011, at 19:35, [email protected] wrote:

From: Anthony PERARD <[email protected]>

Hi all,

Here is the few change since the V10:

Quoted 10 lines

- Add braces for blocks with single statement in the clean-up patch;
- the patch that builds Xen only for x86 have been removed, instead, xen_domainbuild is built with libhw and other Xen files are built for i386 target only;
- the redirection structure with function pointer have been removed, instead, there are few #define or static inline function use for the compatibility;
- the platform device uses trace instead of dprintf for guest log;
- introduce i440fx_xen_init and i440fx_common_init to avoid xen_enabled() in piix_pci.

Nice series. I'm confident that V12 will go in :)

Alex