Skip to contentSkip to conversation

Xen device model support

PATCH Superseded [email protected] 5 participants 30 messages Mar 29, 2011 – Apr 13, 2011 Kbuild

v12 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

v12 cover Xen device model support

From: Anthony PERARD <[email protected]>

Hi all,

Here is the few change made since the v11:
- All objects built for each target are now build only for i386 targets.
- The compatibility macros have been replaced by static inline functions.
- xen_platform_init replaced by a call to pci_create_simple.
- Use of bitmap.h in xen mapcache
- Xen Mapcache have a max cache limit now.
- Compilation of x86_64 target fixed.
- A ram_ptr leak is fixed in pci_add_option_rom.

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-v12

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

John Baboval (2):
xen: Adds a cap to the number of map cache entries.
pci: Use of qemu_put_ram_ptr in pci_add_option_rom.

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

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

 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.c             |    2 +
 hw/pci_ids.h         |    2 +
 hw/piix_pci.c        |   47 ++++-
 hw/xen.h             |   39 ++++
 hw/xen_backend.c     |  422 ++++++++++++++++++++----------------
 hw/xen_backend.h     |    6 +-
 hw/xen_common.h      |  106 ++++++++--
 hw/xen_disk.c        |  496 +++++++++++++++++++++++--------------------
 hw/xen_domainbuild.c |    3 +-
 hw/xen_nic.c         |  265 ++++++++++++-----------
 hw/xen_platform.c    |  340 +++++++++++++++++++++++++++++
 roms/seabios         |    2 +-
 sysemu.h             |    2 +
 trace-events         |    3 +
 vl.c                 |   12 +
 xen-all.c            |  581 ++++++++++++++++++++++++++++++++++++++++++++++++++
 xen-mapcache-stub.c  |   40 ++++
 xen-mapcache.c       |  343 +++++++++++++++++++++++++++++
 xen-mapcache.h       |   22 ++
 xen-stub.c           |   41 ++++
 28 files changed, 2400 insertions(+), 576 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
1.7.2.3
#1 lore raw

PATCH v12 1/17 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 ++++++++++++++++--------------
 roms/seabios     |    2 +-
 4 files changed, 635 insertions(+), 535 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

roms/seabios +1 -1
index cc97564..0f5eebb 160000
@@ -1 +1 @@
-Subproject commit cc975646af69f279396d4d5e1379ac6af80ee637
+Subproject commit 0f5eebb45098ae667fe33d06ae6474665de830df
Signature · 1 line
1.7.2.3
#2 lore raw

PATCH v12 2/17 xen: Make Xen build once.

In reply to [email protected]

From: Anthony PERARD <[email protected]>

xen_domainbuild and xen_machine_pv are built only for i386 targets.

---
 Makefile.target |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile.target +1 -1
index 62b102a..e8ffc7c 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 xen_domainbuild.o
 
 # Inter-VM PCI shared memory
 obj-$(CONFIG_KVM) += ivshmem.o
Signature · 1 line
1.7.2.3
#3 lore raw

PATCH v12 3/17 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      |   95 ++++++++++++++++++++++++++++++++++++++++++-------
 hw/xen_disk.c        |    4 +-
 hw/xen_domainbuild.c |    3 +-
 6 files changed, 164 insertions(+), 32 deletions(-)
configure +65 -2
index 5a5827f..bc6552e 100755
@@ -127,6 +127,7 @@ vnc_jpeg=""
 vnc_png=""
 vnc_thread="no"
 xen=""
+xen_ctrl_version=""
 linux_aio=""
 attr=""
 vhost_net=""
@@ -1155,20 +1156,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
 
 ##########################################
@@ -2772,6 +2834,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..5f58a3f 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 = xen_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 = xen_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 = xen_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 +81 -14

109 lines not on this page · raw message

hw/xen_disk.c +2 -2
index fde02cf..9d99b30 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 371c562..e7e22a6 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
#4 lore raw

PATCH v12 4/17 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 e8ffc7c..b235774 100644
@@ -208,6 +208,15 @@ QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
 # xen backend driver support
 obj-i386-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
 
+ifeq ($(TARGET_BASE_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 2209a4d..5ba1eb9 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;
 
@@ -1979,6 +1980,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..e2872f9
@@ -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 = xen_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
#5 lore raw

PATCH v12 5/17 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 6939c04..d7732d4 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
#6 lore raw

[Qemu-devel] Re: [PATCH V12 05/17] xen: Add xenfv machine

[ Late comments, I know, sorry. Just happen to came across this. ]

Quoted 25 lines · On 2011-03-29 20:27, [email protected] wrote:

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 +1 -0
index 6939c04..d7732d4 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

hw/pc.c static void pc_cpu_reset(void *opaque) · line 926

Quoted 9 lines
hw/pc.c +5 -1
@@ -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;
+    }

Not a fault of your patch, but pc_cpu_reset should not exist in the first place. Setting env->halted should be done in i386's cpu_reset.

I think Xen would be better off with installing a custom VCPU reset handler and overwrite halted according to its own needs. KVM is doing the same. Then we could clean up pc_cpu_reset without bothering Xen.

Quoted 5 lines
hw/pc.c +0 -0
 }
 
 static CPUState *pc_new_cpu(const char *cpu_model)
@@ -952,7 +957,12 @@ void pc_cpus_init(const char *cpu_model)
 #endif

hw/pc.c void pc_cpus_init(const char *cpu_model) · line 966

Quoted 10 lines
hw/pc.c +6 -1
     }
 
-    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);

This looks a bit fishy. What is the semantic of -smp 2 or more in Xen mode? If that is an invalid/unused configuration option, catch that and reject it instead of installing this workaround. If it has a valid semantic, please elaborate why you need to restrict the number of instantiated cpus. Just to optimize memory usage?

hw/pc.c void pc_memory_init(ram_addr_t ram_size, · line 997

Quoted 11 lines
hw/pc.c +5 -0
     }
 }
@@ -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;
+    }
+

This looks fragile /wrt potential future changes of pc_memory_init. Can't those bits Xen is interested in, ie. the above/below_4g_mem_size calculation, be moved into a separate function or even to the caller (should be trivial enough, the interface of pc_memory_init is clumsy in this regard anyway) so that you can simply skip pc_memory_init when in Xen mode?

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#7 lore raw

Re: [Qemu-devel] [PATCH V12 05/17] xen: Add xenfv machine

Quoted 41 lines · Jan Kiszka

[ Late comments, I know, sorry. Just happen to came across this. ]

Quoted 25 lines · On 2011-03-29 20:27, [email protected] wrote:

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 +1 -0
index 6939c04..d7732d4 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

hw/pc.c static void pc_cpu_reset(void *opaque) · line 926

Quoted 9 lines
hw/pc.c +5 -1
@@ -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;
+    }

Not a fault of your patch, but pc_cpu_reset should not exist in the first place. Setting env->halted should be done in i386's cpu_reset.

Quoted 3 lines

I think Xen would be better off with installing a custom VCPU reset handler and overwrite halted according to its own needs. KVM is doing the same. Then we could clean up pc_cpu_reset without bothering Xen.

I will do that.

Quoted 7 lines
Quoted 7 lines
hw/pc.c +0 -0
 }
 
 static CPUState *pc_new_cpu(const char *cpu_model)
@@ -952,7 +957,12 @@ void pc_cpus_init(const char *cpu_model)
 #endif
     }
 
Quoted 14 lines

hw/pc.c void pc_cpus_init(const char *cpu_model) · line 966

Quoted 8 lines
hw/pc.c +6 -1
-    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);

This looks a bit fishy. What is the semantic of -smp 2 or more in Xen mode? If that is an invalid/unused configuration option, catch that and reject it instead of installing this workaround. If it has a valid semantic, please elaborate why you need to restrict the number of instantiated cpus. Just to optimize memory usage?

I thought in a first place that was needed to avoid errors. But it works also when we initialise other CPUs. But I prefere to keep it that way to save memory and in the case where there is a thread for each cpu that will also avoid to have many useless threads.

Also, I use -smp i to initialise the xen's structures related to the vcpu.

Quoted 6 lines
Quoted 6 lines
hw/pc.c +0 -0
     }
 }
@@ -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;
 
Quoted 12 lines

hw/pc.c void pc_memory_init(ram_addr_t ram_size, · line 997

Quoted 5 lines
hw/pc.c +5 -0
+    if (xen_enabled()) {
+        /* Nothing to do for Xen */
+        return;
+    }
+

This looks fragile /wrt potential future changes of pc_memory_init. Can't those bits Xen is interested in, ie. the above/below_4g_mem_size calculation, be moved into a separate function or even to the caller (should be trivial enough, the interface of pc_memory_init is clumsy in this regard anyway) so that you can simply skip pc_memory_init when in Xen mode?

I'll do that, put the calculation in the caller, and change the pc_memory_init prototypes.

Thanks for your review,
Regards,

Signature · 1 line
Anthony PERARD
#8 lore raw

Re: [Qemu-devel] [PATCH V12 05/17] xen: Add xenfv machine

Quoted 22 lines · Anthony PERARD
Quoted 7 lines
Quoted 7 lines

}

static CPUState *pc_new_cpu(const char *cpu_model)

(quoted diff) +0 -0
@@ -952,7 +957,12 @@ void pc_cpus_init(const char *cpu_model)
 #endif
     }
 
Quoted 14 lines

hw/pc.c void pc_cpus_init(const char *cpu_model) · line 966

Quoted 8 lines
hw/pc.c +6 -1
-    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);

This looks a bit fishy. What is the semantic of -smp 2 or more in Xen mode? If that is an invalid/unused configuration option, catch that and reject it instead of installing this workaround. If it has a valid semantic, please elaborate why you need to restrict the number of instantiated cpus. Just to optimize memory usage?

Quoted 4 lines

I thought in a first place that was needed to avoid errors. But it works also when we initialise other CPUs. But I prefere to keep it that way to save memory and in the case where there is a thread for each cpu that will also avoid to have many useless threads.

How much memory does this save? More than a few KB per VCPU? That should be negligible compared to the normal size of VMs. And as long as we do not support multi-threaded TCG VCPUs, Xen will only create on thread for all VCPUs (once that may change, Xen could control the "execution" model via qemu_init_vcpu).

So I would prefer to avoid this additional Xen-specific branch in generic code.

Thanks,
Jan

#9 lore raw

Re: [Qemu-devel] [PATCH V12 05/17] xen: Add xenfv machine

Quoted 29 lines · Jan Kiszka
Quoted 22 lines · Anthony PERARD
Quoted 7 lines
Quoted 7 lines

 }

 static CPUState *pc_new_cpu(const char *cpu_model)

(quoted diff) +0 -0
@@ -952,7 +957,12 @@ void pc_cpus_init(const char *cpu_model)
  #endif
      }
 
Quoted 14 lines

hw/pc.c void pc_cpus_init(const char *cpu_model) · line 966

Quoted 8 lines
hw/pc.c +6 -1
-    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);

This looks a bit fishy. What is the semantic of -smp 2 or more in Xen mode? If that is an invalid/unused configuration option, catch that and reject it instead of installing this workaround. If it has a valid semantic, please elaborate why you need to restrict the number of instantiated cpus. Just to optimize memory usage?

Quoted 4 lines

I thought in a first place that was needed to avoid errors. But it works also when we initialise other CPUs. But I prefere to keep it that way to save memory and in the case where there is a thread for each cpu that will also avoid to have many useless threads.

Quoted 8 lines

How much memory does this save? More than a few KB per VCPU? That should be negligible compared to the normal size of VMs. And as long as we do not support multi-threaded TCG VCPUs, Xen will only create on thread for all VCPUs (once that may change, Xen could control the "execution" model via qemu_init_vcpu).

So I would prefer to avoid this additional Xen-specific branch in generic code.

For this patch series, I will remove this Xen specific branch.

For information, we want to run qemu in a tiny domain (Xen guest) of 32MB, so each 30KB per VCPU can count and in a Xen environment, the VM memory is allocated outside of QEMU, by the hypervisor.
So, we will deal with these extra bytes later, and maybe found a better way to do it :).

Thanks,

--
Anthony PERARD

#10 lore raw

Re: [Qemu-devel] [PATCH V12 05/17] xen: Add xenfv machine

Quoted 36 lines · Anthony PERARD
Quoted 35 lines · Jan Kiszka
Quoted 22 lines · Anthony PERARD
Quoted 7 lines
Quoted 7 lines

}

static CPUState *pc_new_cpu(const char *cpu_model)

(quoted diff) +0 -0
@@ -952,7 +957,12 @@ void pc_cpus_init(const char *cpu_model)
 #endif
     }
 
Quoted 14 lines

hw/pc.c void pc_cpus_init(const char *cpu_model) · line 966

Quoted 8 lines
hw/pc.c +6 -1
-    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);

This looks a bit fishy. What is the semantic of -smp 2 or more in Xen mode? If that is an invalid/unused configuration option, catch that and reject it instead of installing this workaround. If it has a valid semantic, please elaborate why you need to restrict the number of instantiated cpus. Just to optimize memory usage?

Quoted 4 lines

I thought in a first place that was needed to avoid errors. But it works also when we initialise other CPUs. But I prefere to keep it that way to save memory and in the case where there is a thread for each cpu that will also avoid to have many useless threads.

How much memory does this save? More than a few KB per VCPU? That should be negligible compared to the normal size of VMs. And as long as we do not support multi-threaded TCG VCPUs, Xen will only create on thread for all VCPUs (once that may change, Xen could control the "execution" model via qemu_init_vcpu).

Quoted 7 lines
Quoted 2 lines

So I would prefer to avoid this additional Xen-specific branch in generic code.

For this patch series, I will remove this Xen specific branch.

For information, we want to run qemu in a tiny domain (Xen guest) of 32MB, so each 30KB per VCPU can count

I even count 56 KB here (on 64 bit host).

Quoted 4 lines

and in a Xen environment, the VM
memory is allocated outside of QEMU, by the hypervisor. So, we will deal with these extra bytes later, and maybe found a better way to do it :).

Well, either you have a use for the VCPU state (how do you do migration in Xen without it?), or you should probably teach QEMU in a careful & clean way to run its device model without VCPUs - and without any TCG-related memory consumption. For the latter, you would likely receive kudos from KVM people as well.

BTW, if you happen to support that crazy vmport under Xen, not updating the VCPU state will break your neck. Also, lacking VCPUs prevent the usage of analysis and debugging features of QEMU (monitor, gdbstub).

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#11 lore raw

Re: [Qemu-devel] [PATCH V12 05/17] xen: Add xenfv machine

Quoted 9 lines · Jan Kiszka

Well, either you have a use for the VCPU state (how do you do migration in Xen without it?), or you should probably teach QEMU in a careful & clean way to run its device model without VCPUs - and without any TCG-related memory consumption. For the latter, you would likely receive kudos from KVM people as well.

BTW, if you happen to support that crazy vmport under Xen, not updating the VCPU state will break your neck. Also, lacking VCPUs prevent the usage of analysis and debugging features of QEMU (monitor, gdbstub).

We don't use the vcpu state in qemu because qemu takes care of device emulation only; under xen the vcpu state is saved and restored by the hypervisor.
We are currently using the number of vcpus just to know how many event channels we have to bind to receive and send io notifications. Thus your suggestion of teaching qemu to run without vcpus is probably the right thing to do here.

#12 lore raw

Re: [Qemu-devel] [PATCH V12 05/17] xen: Add xenfv machine

Quoted 7 lines · Stefano Stabellini
Quoted 6 lines · Jan Kiszka

Well, either you have a use for the VCPU state (how do you do migration in Xen without it?), or you should probably teach QEMU in a careful & clean way to run its device model without VCPUs - and without any TCG-related memory consumption. For the latter, you would likely receive kudos from KVM people as well.

Quoted 7 lines
Quoted 3 lines

BTW, if you happen to support that crazy vmport under Xen, not updating the VCPU state will break your neck. Also, lacking VCPUs prevent the usage of analysis and debugging features of QEMU (monitor, gdbstub).

We don't use the vcpu state in qemu because qemu takes care of device emulation only; under xen the vcpu state is saved and restored by the hypervisor.

Just out of curiosity: So you are extracting the device states out of QEMU on migration, do the same with the VCPU states from the hypervisor (which wouldn't be that different from KVM in fact), and then transfer that to the destination node? Is there a technical or historical reason for this split-up? I mean, you still need some managing instance that does the state transportation and VM control on both sides, i.e. someone for the job that QEMU is doing for TCG or KVM migrations.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#13 lore raw

Re: [Qemu-devel] [PATCH V12 05/17] xen: Add xenfv machine

Quoted 16 lines · Jan Kiszka
Quoted 7 lines · Stefano Stabellini
Quoted 6 lines · Jan Kiszka

Well, either you have a use for the VCPU state (how do you do migration in Xen without it?), or you should probably teach QEMU in a careful & clean way to run its device model without VCPUs - and without any TCG-related memory consumption. For the latter, you would likely receive kudos from KVM people as well.

Quoted 7 lines
Quoted 3 lines

BTW, if you happen to support that crazy vmport under Xen, not updating the VCPU state will break your neck. Also, lacking VCPUs prevent the usage of analysis and debugging features of QEMU (monitor, gdbstub).

We don't use the vcpu state in qemu because qemu takes care of device emulation only; under xen the vcpu state is saved and restored by the hypervisor.

Quoted 7 lines

Just out of curiosity: So you are extracting the device states out of QEMU on migration, do the same with the VCPU states from the hypervisor (which wouldn't be that different from KVM in fact), and then transfer that to the destination node? Is there a technical or historical reason for this split-up? I mean, you still need some managing instance that does the state transportation and VM control on both sides, i.e. someone for the job that QEMU is doing for TCG or KVM migrations.

That someone is the "toolstack", I guess libvirt would be the closest thing to our toolstack in the kvm world.
The reason why we have a toolstack performing this task rather than qemu is that pure PV guests don't need device emulation, so we don't even have qemu running most of the times if there are only linux guests installed in the system.

#14 lore raw

Re: [Qemu-devel] [PATCH V12 05/17] xen: Add xenfv machine

Quoted 25 lines · Stefano Stabellini
Quoted 16 lines · Jan Kiszka
Quoted 7 lines · Stefano Stabellini
Quoted 6 lines · Jan Kiszka

Well, either you have a use for the VCPU state (how do you do migration in Xen without it?), or you should probably teach QEMU in a careful & clean way to run its device model without VCPUs - and without any TCG-related memory consumption. For the latter, you would likely receive kudos from KVM people as well.

Quoted 7 lines
Quoted 3 lines

BTW, if you happen to support that crazy vmport under Xen, not updating the VCPU state will break your neck. Also, lacking VCPUs prevent the usage of analysis and debugging features of QEMU (monitor, gdbstub).

We don't use the vcpu state in qemu because qemu takes care of device emulation only; under xen the vcpu state is saved and restored by the hypervisor.

Quoted 7 lines

Just out of curiosity: So you are extracting the device states out of QEMU on migration, do the same with the VCPU states from the hypervisor (which wouldn't be that different from KVM in fact), and then transfer that to the destination node? Is there a technical or historical reason for this split-up? I mean, you still need some managing instance that does the state transportation and VM control on both sides, i.e. someone for the job that QEMU is doing for TCG or KVM migrations.

Quoted 6 lines

That someone is the "toolstack", I guess libvirt would be the closest thing to our toolstack in the kvm world.
The reason why we have a toolstack performing this task rather than qemu is that pure PV guests don't need device emulation, so we don't even have qemu running most of the times if there are only linux guests installed in the system.

Ah, for that use case it makes some sense to me.

I bet there would also be some value in consolidating the "toolstack" functionality over bare qemu/libvirt infrastructure (if we ignored all existing interfaces and dependencies for a moment).

Thanks,
Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#15 lore raw

Re: [Qemu-devel] [PATCH V12 05/17] xen: Add xenfv machine

Quoted 33 lines · Jan Kiszka
Quoted 25 lines · Stefano Stabellini
Quoted 16 lines · Jan Kiszka
Quoted 7 lines · Stefano Stabellini
Quoted 6 lines · Jan Kiszka

Well, either you have a use for the VCPU state (how do you do migration in Xen without it?), or you should probably teach QEMU in a careful & clean way to run its device model without VCPUs - and without any TCG-related memory consumption. For the latter, you would likely receive kudos from KVM people as well.

Quoted 7 lines
Quoted 3 lines

BTW, if you happen to support that crazy vmport under Xen, not updating the VCPU state will break your neck. Also, lacking VCPUs prevent the usage of analysis and debugging features of QEMU (monitor, gdbstub).

We don't use the vcpu state in qemu because qemu takes care of device emulation only; under xen the vcpu state is saved and restored by the hypervisor.

Quoted 7 lines

Just out of curiosity: So you are extracting the device states out of QEMU on migration, do the same with the VCPU states from the hypervisor (which wouldn't be that different from KVM in fact), and then transfer that to the destination node? Is there a technical or historical reason for this split-up? I mean, you still need some managing instance that does the state transportation and VM control on both sides, i.e. someone for the job that QEMU is doing for TCG or KVM migrations.

Quoted 6 lines

That someone is the "toolstack", I guess libvirt would be the closest thing to our toolstack in the kvm world.
The reason why we have a toolstack performing this task rather than qemu is that pure PV guests don't need device emulation, so we don't even have qemu running most of the times if there are only linux guests installed in the system.

Quoted 5 lines

Ah, for that use case it makes some sense to me.

I bet there would also be some value in consolidating the "toolstack" functionality over bare qemu/libvirt infrastructure (if we ignored all existing interfaces and dependencies for a moment).

We have a libxenlight driver for libvirt already: it doesn't support migration yet but when it does it will probably reuse the libvirt infrastructure for doing that.
However it is probably going to be libvirt to make the libxenlight calls to perfom the VCPU save/restore so that we don't add a qemu dependency for traditional pv guests...

#16 lore raw

PATCH v12 6/17 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_platform.c |  340 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 trace-events      |    3 +
 6 files changed, 354 insertions(+), 0 deletions(-)
 create mode 100644 hw/xen_platform.c
Makefile.target +2 -0
index b235774..8d5c75b 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 1b09039..a22c92d 100644
@@ -769,6 +769,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..8e5023e 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_create_simple(pci_bus, -1, "xen-platform");
+    }
+
     /* 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_platform.c new file +340 -0

340 lines not on this page · raw message

trace-events +3 -0
index 90c9e0b..009f9ac 100644
@@ -286,3 +286,6 @@ disable lm32_uart_irq_state(int level) "irq state %d"
 
 # hw/lm32_sys.c
 disable lm32_sys_memory_write(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x"
+
+# hw/xen_platform.c
+disable xen_platform_log(char *s) "xen platform: %s"
Signature · 1 line
1.7.2.3
#17 lore raw

PATCH v12 7/17 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 8e5023e..b9b99d2 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 726360a..620827d 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);
+
 int xen_init(void);
 
 #if defined(CONFIG_XEN) && CONFIG_XEN_CTRL_INTERFACE_VERSION < 400
xen-all.c +31 -0
index e2872f9..0bc0978 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 beb982f..dc90f10 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)
+{
+}
+
 int xen_init(void)
 {
     return -ENOSYS;
Signature · 1 line
1.7.2.3
#18 lore raw

PATCH v12 8/17 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 b9b99d2..7da166d 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 620827d..63d953f 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);
+
 int xen_init(void);
 
 #if defined(CONFIG_XEN) && CONFIG_XEN_CTRL_INTERFACE_VERSION < 400
xen-all.c +12 -0
index 0bc0978..22bd413 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 dc90f10..3a8449c 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;
+}
+
 int xen_init(void)
 {
     return -ENOSYS;
Signature · 1 line
1.7.2.3
#19 lore raw

PATCH v12 9/17 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 8d5c75b..245d2a2 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 bc6552e..309b210 100755
@@ -3191,6 +3191,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 964ce31..941abce 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
@@ -2868,6 +2871,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;
         new_block->flags |= RAM_PREALLOC_MASK;
@@ -2890,13 +2894,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);
@@ -2941,7 +2947,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);
@@ -3030,6 +3040,15 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
                 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);
         }
     }
@@ -3065,11 +3084,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;
 }
 
@@ -3980,6 +4009,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 63d953f..9b625fd 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);
@@ -39,6 +48,10 @@ qemu_irq *xen_interrupt_controller_init(void);
 
 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 47b8afe..dd3e896 100644
@@ -63,6 +63,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 3a8449c..8d2fa54 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
#20 lore raw

PATCH v12 10/17 xen: Adds a cap to the number of map cache entries.

In reply to [email protected]

From: John Baboval <[email protected]>

Adds a cap to the number of map cache entries. This prevents the map cache from overwhelming system memory.

I also removed the bitmap macros and #included bitmap.h instead.

---
 xen-mapcache.c |   21 ++++++++++-----------
 1 files changed, 10 insertions(+), 11 deletions(-)
xen-mapcache.c +10 -11
index d7f44a7..eab97bc 100644
@@ -12,6 +12,7 @@
 
 #include "hw/xen_backend.h"
 #include "blockdev.h"
+#include "bitmap.h"
 
 #include <xen/hvm/params.h>
 #include <sys/mman.h>
@@ -31,15 +32,13 @@
 
 #if defined(__i386__)
 #  define MCACHE_BUCKET_SHIFT 16
+#  define MCACHE_MAX_SIZE     (1UL<<31) /* 2GB Cap */
 #elif defined(__x86_64__)
 #  define MCACHE_BUCKET_SHIFT 20
+#  define MCACHE_MAX_SIZE     (1UL<<35) /* 32GB Cap */
 #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;
@@ -68,11 +67,6 @@ typedef struct 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)));
-}
-
 void qemu_map_cache_init(void)
 {
     unsigned long size;
@@ -84,9 +78,14 @@ void qemu_map_cache_init(void)
     mapcache->last_address_index = -1;
 
     getrlimit(RLIMIT_AS, &rlimit_as);
-    rlimit_as.rlim_cur = rlimit_as.rlim_max;
+    if (rlimit_as.rlim_max < MCACHE_MAX_SIZE) {
+        rlimit_as.rlim_cur = rlimit_as.rlim_max;
+    } else {
+        rlimit_as.rlim_cur = MCACHE_MAX_SIZE;
+    }
+
     setrlimit(RLIMIT_AS, &rlimit_as);
-    mapcache->max_mcache_size = rlimit_as.rlim_max;
+    mapcache->max_mcache_size = rlimit_as.rlim_cur;
 
     mapcache->nr_buckets =
         (((mapcache->max_mcache_size >> XC_PAGE_SHIFT) +
Signature · 1 line
1.7.2.3
#21 lore raw

PATCH v12 11/17 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 309b210..34248f0 100755
@@ -3190,6 +3190,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
#22 lore raw

PATCH v12 12/17 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 ef4e8da..6863b57 100644
@@ -56,6 +56,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 941abce..9301ba3 100644
@@ -3078,6 +3078,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;
@@ -3793,6 +3800,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 &&
@@ -3823,6 +3831,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;
@@ -3863,6 +3872,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 eab97bc..0142c09 100644
@@ -194,6 +194,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
#23 lore raw

PATCH v12 13/17 pci: Use of qemu_put_ram_ptr in pci_add_option_rom.

In reply to [email protected]

From: John Baboval <[email protected]>

Prevent a deadlock caused by leaving a map cache bucket locked by the preceding qemu_get_ram_ptr() call.

---
 hw/pci.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
hw/pci.c +2 -0
index 6b577e1..2b24dd4 100644
@@ -1897,6 +1897,8 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
         pci_patch_ids(pdev, ptr, size);
     }
 
+    qemu_put_ram_ptr(ptr);
+
     pci_register_bar(pdev, PCI_ROM_SLOT, size,
                      0, pci_map_option_rom);
 
Signature · 1 line
1.7.2.3
#24 lore raw

PATCH v12 14/17 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 bbbd0fd..3d4be78 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 5ba1eb9..60ec6de 100644
@@ -1223,6 +1223,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
#25 lore raw

PATCH v12 15/17 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       |  419 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 421 insertions(+), 0 deletions(-)
hw/xen_common.h +2 -0
index dd3e896..a1958a0 100644
@@ -107,4 +107,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 +419 -0

450 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#26 lore raw

PATCH v12 16/17 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 8fabc9d..8167b44 100644
@@ -63,6 +63,8 @@ typedef struct XenIOState {
     /* which vcpu we are serving */
     int send_vcpu;
 
+    struct xs_handle *xenstore;
+
     Notifier exit;
 } XenIOState;
 
@@ -431,6 +433,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;
@@ -446,6 +459,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");
 }
 
 
@@ -464,6 +480,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)
@@ -486,6 +503,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 v12 17/17 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 7da166d..d5e7484 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 9b625fd..adc32f7 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 8167b44..12258ef 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"
 
@@ -98,6 +99,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 8d2fa54..a4f35a1 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
Acked-by on the v12 series
#28 lore raw
In reply to [email protected]
Quoted 13 lines · On 29.03.2011, at 20:27, [email protected] wrote:

From: Anthony PERARD <[email protected]>

Hi all,

Here is the few change made since the v11:
- All objects built for each target are now build only for i386 targets.
- The compatibility macros have been replaced by static inline functions.
- xen_platform_init replaced by a call to pci_create_simple.
- Use of bitmap.h in xen mapcache
- Xen Mapcache have a max cache limit now.
- Compilation of x86_64 target fixed.
- A ram_ptr leak is fixed in pci_add_option_rom.

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-v12

Thanks a lot!

Alex

#29 lore raw
In reply to [email protected]
Quoted 13 lines · On Tue, Mar 29, 2011 at 19:27, <[email protected]> wrote:

From: Anthony PERARD <[email protected]>

Hi all,

Here is the few change made since the v11:
 - All objects built for each target are now build only for i386 targets.
 - The compatibility macros have been replaced by static inline functions.
 - xen_platform_init replaced by a call to pci_create_simple.
 - Use of bitmap.h in xen mapcache
 - Xen Mapcache have a max cache limit now.
 - Compilation of x86_64 target fixed.
 - A ram_ptr leak is fixed in pci_add_option_rom.

Quoted 7 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-v12

I make a little mistake, the patch: "xen: Add the Xen platform pci device" must be dropped from the series. It is not complete.

Regards,

Signature · 1 line
Anthony PERARD