Skip to contentSkip to conversation

xen device model support

RFC PATCH Superseded [email protected] 4 participants 20 messages Sep 28, 2010 – Sep 29, 2010 Kbuild

v4 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

v4 cover xen device model support

From: Anthony PERARD <[email protected]>

Hi all,
this is the fourth version of the patch series that adds xen device model support in qemu.

This is the list of changes we made on top of the last version:

- we addressed the code style change requests;

- we have split mapcache in two file xen-mapcache.c and xen-mapcache-stub.c with check in configure to use one or the other;

- we have fixed the compilation issue with user-only target and with older Xen release (3.3.0, 3.4.0 and 4.0.1), this come with more check in the configure script;

- we have replaced -enable-xen by a more generic options, so we introduce -accel options (use for kvm and xen).

For the next time we have to remove the Xen specific ACPI Implementation.

Anthony PERARD (14):
xen: Replace some tab-indents with spaces (clean-up).
xen: Support new libxc calls from xen unstable.
xen: Add xen_machine_fv
Introduce -accel command option.
xen: Add xen in -accel option.
xen: Add the Xen platform pci device
piix_pci: Introduces Xen specific call for irq.
xen: add a 8259 Interrupt Controller
xen: Introduce the Xen mapcache
Introduce qemu_ram_ptr_unlock.
vl.c: Introduce getter for shutdown_requested and reset_requested.
xen: Initialize event channels and io rings
xen: Set running state in xenstore.
xen: Add a Xen specific ACPI Implementation to target-xen

 Makefile.target      |   13 ++
 configure            |   70 +++++++-
 cpu-common.h         |    1 +
 exec.c               |   71 ++++++-
 hw/hw.h              |    3 +
 hw/pci_ids.h         |    2 +
 hw/piix_pci.c        |   28 +++-
 hw/xen.h             |   26 +++
 hw/xen_acpi_piix4.c  |  411 +++++++++++++++++++++++++++++++++++++
 hw/xen_backend.c     |  314 +++++++++++++++---------------
 hw/xen_backend.h     |    2 +-
 hw/xen_common.h      |   51 ++++--
 hw/xen_disk.c        |  414 +++++++++++++++++++-------------------
 hw/xen_domainbuild.c |    2 +-
 hw/xen_machine_fv.c  |  156 ++++++++++++++
 hw/xen_nic.c         |  230 +++++++++++-----------
 hw/xen_platform.c    |  431 +++++++++++++++++++++++++++++++++++++++
 hw/xen_platform.h    |    8 +
 qemu-options.hx      |   10 +
 sysemu.h             |    2 +
 vl.c                 |   98 ++++++++-
 xen-all.c            |  546 ++++++++++++++++++++++++++++++++++++++++++++++++++
 xen-mapcache-stub.c  |   33 +++
 xen-mapcache.c       |  335 +++++++++++++++++++++++++++++++
 xen-mapcache.h       |   14 ++
 xen-stub.c           |   34 +++
 26 files changed, 2788 insertions(+), 517 deletions(-)
 create mode 100644 hw/xen_acpi_piix4.c
 create mode 100644 hw/xen_machine_fv.c
 create mode 100644 hw/xen_platform.c
 create mode 100644 hw/xen_platform.h
 create mode 100644 xen-all.c
 create mode 100644 xen-mapcache-stub.c
 create mode 100644 xen-mapcache.c
 create mode 100644 xen-mapcache.h
 create mode 100644 xen-stub.c
Signature · 1 line
Anthony PERARD
#1 lore raw

RFC PATCH v4 1/14 xen: Replace some tab-indents with spaces (clean-up).

From: Anthony PERARD <[email protected]>

---
 hw/xen_backend.c |  308 ++++++++++++++++++++--------------------
 hw/xen_disk.c    |  412 +++++++++++++++++++++++++++---------------------------
 hw/xen_nic.c     |  222 +++++++++++++++---------------
 3 files changed, 471 insertions(+), 471 deletions(-)
hw/xen_backend.c +154 -154
index a2e408f..860b038 100644
@@ -59,7 +59,7 @@ int xenstore_write_str(const char *base, const char *node, const char *val)
 
     snprintf(abspath, sizeof(abspath), "%s/%s", base, node);
     if (!xs_write(xenstore, 0, abspath, val, strlen(val)))
-	return -1;
+        return -1;
     return 0;
 }
 
@@ -95,7 +95,7 @@ int xenstore_read_int(const char *base, const char *node, int *ival)
 
     val = xenstore_read_str(base, node);
     if (val && 1 == sscanf(val, "%d", ival))
-	rc = 0;
+        rc = 0;
     qemu_free(val);
     return rc;
 }
@@ -134,16 +134,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)
@@ -152,9 +152,9 @@ int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state)
 
     rc = xenstore_write_be_int(xendev, "state", state);
     if (rc < 0)
-	return rc;
+        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 +166,13 @@ 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;
 }
@@ -188,7 +188,7 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
 
     xendev = xen_be_find_xendev(type, dom, dev);
     if (xendev)
-	return xendev;
+        return xendev;
 
     /* init new xendev */
     xendev = qemu_mallocz(ops->size);
@@ -199,9 +199,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 +209,28 @@ 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);
+        xendev->ops->alloc(xendev);
 
     return xendev;
 }
@@ -251,28 +251,28 @@ 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->dom != dom)
+            continue;
+        if (xendev->dev != dev && dev != -1)
+            continue;
 
-	if (xendev->ops->free)
-	    xendev->ops->free(xendev);
+        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->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);
+        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);
+        QTAILQ_REMOVE(&xendevs, xendev, next);
+        qemu_free(xendev);
     }
     return NULL;
 }
@@ -285,14 +285,14 @@ 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 +301,25 @@ 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 +340,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 +383,15 @@ 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);
+        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 +411,20 @@ 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);
+        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);
@@ -441,7 +441,7 @@ 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);
+        xendev->ops->disconnect(xendev);
     if (xendev->be_state != state)
         xen_be_set_state(xendev, state);
 }
@@ -468,31 +468,31 @@ 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 +511,26 @@ 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;
+        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;
@@ -540,24 +540,24 @@ static void xenstore_update_be(char *watch, char *type, int dom,
     len = snprintf(path, sizeof(path), "%s/backend/%s/%d", dom0, type, dom);
     free(dom0);
     if (strncmp(path, watch, len) != 0)
-	return;
+        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;
+        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);
     }
 }
 
@@ -568,9 +568,9 @@ static void xenstore_update_fe(char *watch, struct XenDevice *xendev)
 
     len = strlen(xendev->fe);
     if (strncmp(xendev->fe, watch, len) != 0)
-	return;
+        return;
     if (watch[len] != '/')
-	return;
+        return;
     node = watch + len + 1;
 
     xen_be_frontend_changed(xendev, node);
@@ -585,13 +585,13 @@ static void xenstore_update(void *unused)
 
     vec = xs_read_watch(xenstore, &count);
     if (vec == NULL)
-	goto cleanup;
+        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);
+        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);
+        xenstore_update_fe(vec[XS_WATCH_PATH], (void*)ptr);
 
 cleanup:
     free(vec);
@@ -604,14 +604,14 @@ 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);
+        xendev->ops->event(xendev);
 }
 
 /* -------------------------------------------------------------------- */
@@ -620,17 +620,17 @@ 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;
+        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;
 
@@ -650,23 +650,23 @@ 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;
+        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;
+        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);
hw/xen_disk.c +206 -206

642 lines not on this page · raw message

hw/xen_nic.c +111 -111

352 lines not on this page · raw message

Signature · 1 line
1.6.5
#2 lore raw

RFC PATCH v4 2/14 xen: Support new libxc calls from xen unstable.

In reply to [email protected]

From: Anthony PERARD <[email protected]>

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

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

---
 configure            |   67 ++++++++++++++++++++++++++++++++++++++++++++++++-
 hw/xen_backend.c     |   10 +++---
 hw/xen_backend.h     |    2 +-
 hw/xen_common.h      |   38 +++++++++++++++++-----------
 hw/xen_disk.c        |   12 ++++----
 hw/xen_domainbuild.c |    2 +-
 hw/xen_nic.c         |   16 ++++++------
 7 files changed, 109 insertions(+), 38 deletions(-)
configure +65 -2
index 4061cb7..18c3fa0 100755
@@ -274,6 +274,7 @@ vnc_jpeg=""
 vnc_png=""
 vnc_thread="no"
 xen=""
+xen_ctrl_version=""
 linux_aio=""
 attr=""
 vhost_net=""
@@ -1110,20 +1111,81 @@ fi
 
 if test "$xen" != "no" ; then
   xen_libs="-lxenstore -lxenctrl -lxenguest"
+
+  # Xen unstable
   cat > $TMPC <<EOF
 #include <xenctrl.h>
 #include <xs.h>
-int main(void) { xs_daemon_open(); xc_interface_open(); return 0; }
+#include <stdint.h>
+#include <xen/hvm/hvm_info_table.h>
+#if !defined(HVM_MAX_VCPUS)
+# error HVM_MAX_VCPUS not defined
+#endif
+int main(void) {
+  xc_interface *xc;
+  xs_daemon_open();
+  xc_interface_open(0, 0, 0);
+  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
+  xc_gnttab_open(xc);
+  return 0;
+}
 EOF
   if compile_prog "" "$xen_libs" ; then
+    xen_ctrl_version=410
     xen=yes
-    libs_softmmu="$xen_libs $libs_softmmu"
+
+  # Xen 4.0.0
+  elif (
+      cat > $TMPC <<EOF
+#include <xenctrl.h>
+#include <xs.h>
+#include <stdint.h>
+#include <xen/hvm/hvm_info_table.h>
+#if !defined(HVM_MAX_VCPUS)
+# error HVM_MAX_VCPUS not defined
+#endif
+int main(void) {
+  xs_daemon_open();
+  xc_interface_open();
+  xc_gnttab_open();
+  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
+  return 0;
+}
+EOF
+      compile_prog "" "$xen_libs"
+    ) ; then
+    xen_ctrl_version=400
+    xen=yes
+
+  # Xen 3.3.0, 3.4.0
+  elif (
+      cat > $TMPC <<EOF
+#include <xenctrl.h>
+#include <xs.h>
+int main(void) {
+  xs_daemon_open();
+  xc_interface_open();
+  xc_gnttab_open();
+  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
+  return 0;
+}
+EOF
+      compile_prog "" "$xen_libs"
+    ) ; then
+    xen_ctrl_version=330
+    xen=yes
+
+  # Xen not found or unsupported
   else
     if test "$xen" = "yes" ; then
       feature_not_found "xen"
     fi
     xen=no
   fi
+
+  if test "$xen" = "yes"; then
+    libs_softmmu="$xen_libs $libs_softmmu"
+  fi
 fi
 
 ##########################################
@@ -2429,6 +2491,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 +5 -5
index 860b038..3e99751 100644
@@ -43,7 +43,7 @@
 /* ------------------------------------------------------------- */
 
 /* public */
-int xen_xc;
+qemu_xc_interface xen_xc = XC_HANDLER_INITIAL_VALUE;
 struct xs_handle *xenstore = NULL;
 const char *xen_protocol;
 
@@ -216,7 +216,7 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
     fcntl(xc_evtchn_fd(xendev->evtchndev), F_SETFD, FD_CLOEXEC);
 
     if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) {
-        xendev->gnttabdev = xc_gnttab_open();
+        xendev->gnttabdev = xc_gnttab_open(xen_xc);
         if (xendev->gnttabdev < 0) {
             xen_be_printf(NULL, 0, "can't open gnttab device\n");
             xc_evtchn_close(xendev->evtchndev);
@@ -269,7 +269,7 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev)
         if (xendev->evtchndev >= 0)
             xc_evtchn_close(xendev->evtchndev);
         if (xendev->gnttabdev >= 0)
-            xc_gnttab_close(xendev->gnttabdev);
+            xc_gnttab_close(xen_xc, xendev->gnttabdev);
 
         QTAILQ_REMOVE(&xendevs, xendev, next);
         qemu_free(xendev);
@@ -627,8 +627,8 @@ int xen_be_init(void)
     if (qemu_set_fd_handler(xs_fileno(xenstore), xenstore_update, NULL, NULL) < 0)
         goto err;
 
-    xen_xc = xc_interface_open();
-    if (xen_xc == -1) {
+    xen_xc = xc_interface_open(NULL, NULL, 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 +1 -1
index 292126d..1f23cde 100644
@@ -55,7 +55,7 @@ struct XenDevice {
 /* ------------------------------------------------------------- */
 
 /* variables */
-extern int xen_xc;
+extern qemu_xc_interface xen_xc;
 extern struct xs_handle *xenstore;
 extern const char *xen_protocol;
 
hw/xen_common.h +23 -15
index 8a55b44..9f75e52 100644
@@ -1,6 +1,8 @@
 #ifndef QEMU_HW_XEN_COMMON_H
 #define QEMU_HW_XEN_COMMON_H 1
 
+#include "config-host.h"
+
 #include <stddef.h>
 #include <inttypes.h>
 
@@ -13,22 +15,28 @@
 #include "qemu-queue.h"
 
 /*
- * tweaks needed to build with different xen versions
- *  0x00030205 -> 3.1.0
- *  0x00030207 -> 3.2.0
- *  0x00030208 -> unstable
+ * We don't support Xen prior to 3.3.0.
  */
-#include <xen/xen-compat.h>
-#if __XEN_LATEST_INTERFACE_VERSION__ < 0x00030205
-# define evtchn_port_or_error_t int
-#endif
-#if __XEN_LATEST_INTERFACE_VERSION__ < 0x00030207
-# define xc_map_foreign_pages xc_map_foreign_batch
-#endif
-#if __XEN_LATEST_INTERFACE_VERSION__ < 0x00030208
-# define xen_mb()  mb()
-# define xen_rmb() rmb()
-# define xen_wmb() wmb()
+
+/* Xen unstable */
+#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
+typedef int qemu_xc_interface;
+#  define XC_HANDLER_INITIAL_VALUE               -1
+#  define xc_fd(xen_xc)                          xen_xc
+#  define xc_interface_open(l, dl, f)            xc_interface_open()
+#  define xc_gnttab_open(xc)                     xc_gnttab_open()
+#  define xc_gnttab_map_grant_ref(xc, gnt, domid, ref, flags) \
+    xc_gnttab_map_grant_ref(gnt, domid, ref, flags)
+#  define xc_gnttab_map_grant_refs(xc, gnt, count, domids, refs, flags) \
+    xc_gnttab_map_grant_refs(gnt, count, domids, refs, flags)
+#  define xc_gnttab_munmap(xc, gnt, pages, niov) xc_gnttab_munmap(gnt, pages, niov)
+#  define xc_gnttab_close(xc, dev)               xc_gnttab_close(dev)
+#else
+typedef xc_interface *qemu_xc_interface;
+#  define XC_HANDLER_INITIAL_VALUE NULL
+/* FIXME The fd of xen_xc is now xen_xc->fd */
+/* fd is the first field, so this works */
+#  define xc_fd(xen_xc)                          (*(int*)xen_xc)
 #endif
 
 #endif /* QEMU_HW_XEN_COMMON_H */
hw/xen_disk.c +6 -6
index 47280ee..ec1365c 100644
@@ -243,7 +243,7 @@ static void ioreq_unmap(struct ioreq *ioreq)
     if (batch_maps) {
         if (!ioreq->pages)
             return;
-        if (xc_gnttab_munmap(gnt, ioreq->pages, ioreq->v.niov) != 0)
+        if (xc_gnttab_munmap(xen_xc, gnt, ioreq->pages, ioreq->v.niov) != 0)
             xen_be_printf(&ioreq->blkdev->xendev, 0, "xc_gnttab_munmap failed: %s\n",
                           strerror(errno));
         ioreq->blkdev->cnt_map -= ioreq->v.niov;
@@ -252,7 +252,7 @@ static void ioreq_unmap(struct ioreq *ioreq)
         for (i = 0; i < ioreq->v.niov; i++) {
             if (!ioreq->page[i])
                 continue;
-            if (xc_gnttab_munmap(gnt, ioreq->page[i], 1) != 0)
+            if (xc_gnttab_munmap(xen_xc, gnt, ioreq->page[i], 1) != 0)
                 xen_be_printf(&ioreq->blkdev->xendev, 0, "xc_gnttab_munmap failed: %s\n",
                               strerror(errno));
             ioreq->blkdev->cnt_map--;
@@ -270,7 +270,7 @@ static int ioreq_map(struct ioreq *ioreq)
         return 0;
     if (batch_maps) {
         ioreq->pages = xc_gnttab_map_grant_refs
-            (gnt, ioreq->v.niov, ioreq->domids, ioreq->refs, ioreq->prot);
+            (xen_xc, gnt, ioreq->v.niov, ioreq->domids, ioreq->refs, ioreq->prot);
         if (ioreq->pages == NULL) {
             xen_be_printf(&ioreq->blkdev->xendev, 0,
                           "can't map %d grant refs (%s, %d maps)\n",
@@ -284,7 +284,7 @@ static int ioreq_map(struct ioreq *ioreq)
     } else  {
         for (i = 0; i < ioreq->v.niov; i++) {
             ioreq->page[i] = xc_gnttab_map_grant_ref
-                (gnt, ioreq->domids[i], ioreq->refs[i], ioreq->prot);
+                (xen_xc, gnt, ioreq->domids[i], ioreq->refs[i], ioreq->prot);
             if (ioreq->page[i] == NULL) {
                 xen_be_printf(&ioreq->blkdev->xendev, 0,
                               "can't map grant ref %d (%s, %d maps)\n",
@@ -684,7 +684,7 @@ static int blk_connect(struct XenDevice *xendev)
             blkdev->protocol = BLKIF_PROTOCOL_X86_64;
     }
 
-    blkdev->sring = xc_gnttab_map_grant_ref(blkdev->xendev.gnttabdev,
+    blkdev->sring = xc_gnttab_map_grant_ref(xen_xc, blkdev->xendev.gnttabdev,
                                             blkdev->xendev.dom,
                                             blkdev->ring_ref,
                                             PROT_READ | PROT_WRITE);
@@ -739,7 +739,7 @@ static void blk_disconnect(struct XenDevice *xendev)
     xen_be_unbind_evtchn(&blkdev->xendev);
 
     if (blkdev->sring) {
-        xc_gnttab_munmap(blkdev->xendev.gnttabdev, blkdev->sring, 1);
+        xc_gnttab_munmap(xen_xc, blkdev->xendev.gnttabdev, blkdev->sring, 1);
         blkdev->cnt_map--;
         blkdev->sring = NULL;
     }
hw/xen_domainbuild.c +1 -1
index 7f1fd66..232a456 100644
@@ -176,7 +176,7 @@ static int xen_domain_watcher(void)
     for (i = 3; i < n; i++) {
         if (i == fd[0])
             continue;
-        if (i == xen_xc)
+        if (i == xc_fd(xen_xc))
             continue;
         close(i);
     }
hw/xen_nic.c +8 -8
index 8fcf856..2575541 100644
@@ -166,7 +166,7 @@ static void net_tx_packets(struct XenNetDev *netdev)
                           (txreq.flags & NETTXF_more_data)      ? " more_data"      : "",
                           (txreq.flags & NETTXF_extra_info)     ? " extra_info"     : "");
 
-            page = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+            page = xc_gnttab_map_grant_ref(xen_xc, netdev->xendev.gnttabdev,
                                            netdev->xendev.dom,
                                            txreq.gref, PROT_READ);
             if (page == NULL) {
@@ -185,7 +185,7 @@ static void net_tx_packets(struct XenNetDev *netdev)
             } else {
                 qemu_send_packet(&netdev->nic->nc, page + txreq.offset, txreq.size);
             }
-            xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1);
+            xc_gnttab_munmap(xen_xc, netdev->xendev.gnttabdev, page, 1);
             net_tx_response(netdev, &txreq, NETIF_RSP_OKAY);
         }
         if (!netdev->tx_work)
@@ -272,7 +272,7 @@ static ssize_t net_rx_packet(VLANClientState *nc, const uint8_t *buf, size_t siz
     memcpy(&rxreq, RING_GET_REQUEST(&netdev->rx_ring, rc), sizeof(rxreq));
     netdev->rx_ring.req_cons = ++rc;
 
-    page = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+    page = xc_gnttab_map_grant_ref(xen_xc, netdev->xendev.gnttabdev,
                                    netdev->xendev.dom,
                                    rxreq.gref, PROT_WRITE);
     if (page == NULL) {
@@ -282,7 +282,7 @@ static ssize_t net_rx_packet(VLANClientState *nc, const uint8_t *buf, size_t siz
         return -1;
     }
     memcpy(page + NET_IP_ALIGN, buf, size);
-    xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1);
+    xc_gnttab_munmap(xen_xc, netdev->xendev.gnttabdev, page, 1);
     net_rx_response(netdev, &rxreq, NETIF_RSP_OKAY, NET_IP_ALIGN, size, 0);
 
     return size;
@@ -350,11 +350,11 @@ static int net_connect(struct XenDevice *xendev)
         return -1;
     }
 
-    netdev->txs = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+    netdev->txs = xc_gnttab_map_grant_ref(xen_xc, netdev->xendev.gnttabdev,
                                           netdev->xendev.dom,
                                           netdev->tx_ring_ref,
                                           PROT_READ | PROT_WRITE);
-    netdev->rxs = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+    netdev->rxs = xc_gnttab_map_grant_ref(xen_xc, netdev->xendev.gnttabdev,
                                           netdev->xendev.dom,
                                           netdev->rx_ring_ref,
                                           PROT_READ | PROT_WRITE);
@@ -381,11 +381,11 @@ static void net_disconnect(struct XenDevice *xendev)
     xen_be_unbind_evtchn(&netdev->xendev);
 
     if (netdev->txs) {
-        xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->txs, 1);
+        xc_gnttab_munmap(xen_xc, netdev->xendev.gnttabdev, netdev->txs, 1);
         netdev->txs = NULL;
     }
     if (netdev->rxs) {
-        xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->rxs, 1);
+        xc_gnttab_munmap(xen_xc, netdev->xendev.gnttabdev, netdev->rxs, 1);
         netdev->rxs = NULL;
     }
     if (netdev->nic) {
Signature · 1 line
1.6.5
#3 lore raw

RFC PATCH v4 3/14 xen: Add xen_machine_fv

In reply to [email protected]

From: Anthony PERARD <[email protected]>

Add the Xen FV (Fully Virtualized) machine to Qemu; this is groundwork to add Xen device model support in Qemu.

---
 Makefile.target     |    3 +
 hw/xen_common.h     |    5 ++
 hw/xen_machine_fv.c |  158 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 166 insertions(+), 0 deletions(-)
 create mode 100644 hw/xen_machine_fv.c
Makefile.target +3 -0
index a4e80b1..7adbc20 100644
@@ -183,6 +183,9 @@ QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
 # xen backend driver support
 obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
 
+# xen full virtualized machine
+obj-i386-$(CONFIG_XEN) += xen_machine_fv.o
+
 # USB layer
 obj-$(CONFIG_USB_OHCI) += usb-ohci.o
 
hw/xen_common.h +5 -0
index 9f75e52..4c0f97d 100644
@@ -18,6 +18,11 @@
  * We don't support Xen prior to 3.3.0.
  */
 
+/* Before Xen 4.0.0 */
+#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 400
+#  define HVM_MAX_VCPUS 32
+#endif
+
 /* Xen unstable */
 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
 typedef int qemu_xc_interface;
hw/xen_machine_fv.c new file +158 -0

158 lines not on this page · raw message

Signature · 1 line
1.6.5
#4 lore raw

RFC PATCH v4 4/14 Introduce -accel command option.

In reply to [email protected]

From: Anthony PERARD <[email protected]>

This option gives the ability to switch one "accelerator" like kvm, xen or the default one tcg. We can specify more than one accelerator by separate them by a comma. QEMU will try each one and use the first whose works.

So,

-accel xen,kvm,tcg

which would try Xen support first, then KVM and finaly tcg if none of the other works.

---
 qemu-options.hx |   10 ++++++
 vl.c            |   86 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 85 insertions(+), 11 deletions(-)
qemu-options.hx +10 -0
index a0b5ae9..53c4d35 100644
@@ -1904,6 +1904,16 @@ Enable KVM full virtualization support. This option is only available
 if KVM support is enabled when compiling.
 ETEXI
 
+DEF("accel", HAS_ARG, QEMU_OPTION_accel, \
+    "-accel accel    use an accelerator (kvm,xen,tcg), default is tcg\n", QEMU_ARCH_ALL)
+STEXI
+@item -accel @var{accel}[,@var{accel}[,...]]
+@findex -accel
+This is use to enable an accelerator, in kvm,xen,tcg.
+By default, it use only tcg. If there a more than one accelerator
+specified, the next one is used if the first don't work.
+ETEXI
+
 DEF("xen-domid", HAS_ARG, QEMU_OPTION_xen_domid,
     "-xen-domid id   specify xen guest domain id\n", QEMU_ARCH_ALL)
 DEF("xen-create", 0, QEMU_OPTION_xen_create,
vl.c +75 -11

110 lines not on this page · raw message

Signature · 1 line
1.6.5
#5 lore raw

RFC PATCH v4 5/14 xen: Add xen in -accel option.

In reply to [email protected]

From: Anthony PERARD <[email protected]>

This come with the initialisation of Xen.

---
 Makefile.target |    5 +++++
 hw/xen.h        |   10 ++++++++++
 vl.c            |    2 ++
 xen-all.c       |   25 +++++++++++++++++++++++++
 xen-stub.c      |   17 +++++++++++++++++
 5 files changed, 59 insertions(+), 0 deletions(-)
 create mode 100644 xen-all.c
 create mode 100644 xen-stub.c
Makefile.target +5 -0
index 7adbc20..7a5eb71 100644
@@ -2,6 +2,7 @@
 
 GENERATED_HEADERS = config-target.h
 CONFIG_NO_KVM = $(if $(subst n,,$(CONFIG_KVM)),n,y)
+CONFIG_NO_XEN = $(if $(subst n,,$(CONFIG_XEN)),n,y)
 
 include ../config-host.mak
 include config-devices.mak
@@ -183,6 +184,10 @@ QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
 # xen backend driver support
 obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
 
+# xen support
+obj-$(CONFIG_XEN) += xen-all.o
+obj-$(CONFIG_NO_XEN) += xen-stub.o
+
 # xen full virtualized machine
 obj-i386-$(CONFIG_XEN) += xen_machine_fv.o
 
hw/xen.h +10 -0
index 780dcf7..14bbb6e 100644
@@ -18,4 +18,14 @@ enum xen_mode {
 extern uint32_t xen_domid;
 extern enum xen_mode xen_mode;
 
+extern int xen_allowed;
+
+#if defined CONFIG_XEN
+#define xen_enabled() (xen_allowed)
+#else
+#define xen_enabled() (0)
+#endif
+
+int xen_init(int smp_cpus);
+
 #endif /* QEMU_HW_XEN_H */
vl.c +2 -0
index 797f04d..c0c9d32 100644
@@ -243,6 +243,7 @@ static NotifierList exit_notifiers =
     NOTIFIER_LIST_INITIALIZER(exit_notifiers);
 
 int kvm_allowed = 0;
+int xen_allowed = 0;
 uint32_t xen_domid;
 enum xen_mode xen_mode = XEN_EMULATE;
 
@@ -1755,6 +1756,7 @@ static struct {
     int *allowed;
 } accel_list[] = {
     { "tcg", "tcg", NULL, NULL, NULL },
+    { "xen", "Xen", xen_available, xen_init, &xen_allowed },
     { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
 };
 
xen-all.c new file +25 -0
new file mode 100644
index 0000000..42c93ba
@@ -0,0 +1,25 @@
+/*
+ * 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 "config.h"
+
+#include "hw/xen_common.h"
+#include "hw/xen_backend.h"
+
+/* Initialise Xen */
+
+int xen_init(int smp_cpus)
+{
+    xen_xc = xc_interface_open(NULL, NULL, 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 +17 -0
new file mode 100644
index 0000000..0fa9c51
@@ -0,0 +1,17 @@
+/*
+ * 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 "config.h"
+
+#include "qemu-common.h"
+#include "hw/xen.h"
+
+int xen_init(int smp_cpus)
+{
+    return -ENOSYS;
+}
Signature · 1 line
1.6.5
#6 lore raw

RFC PATCH v4 6/14 xen: Add the Xen platform pci device

In reply to [email protected]

From: Anthony PERARD <[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     |    1 +
 hw/hw.h             |    3 +
 hw/pci_ids.h        |    2 +
 hw/xen_machine_fv.c |    3 +
 hw/xen_platform.c   |  431 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/xen_platform.h   |    8 +
 6 files changed, 448 insertions(+), 0 deletions(-)
 create mode 100644 hw/xen_platform.c
 create mode 100644 hw/xen_platform.h
Makefile.target +1 -0
index 7a5eb71..9353627 100644
@@ -190,6 +190,7 @@ obj-$(CONFIG_NO_XEN) += xen-stub.o
 
 # xen full virtualized machine
 obj-i386-$(CONFIG_XEN) += xen_machine_fv.o
+obj-i386-$(CONFIG_XEN) += xen_platform.o
 
 # USB layer
 obj-$(CONFIG_USB_OHCI) += usb-ohci.o
hw/hw.h +3 -0
index 4405092..67f3369 100644
@@ -653,6 +653,9 @@ extern const VMStateDescription vmstate_i2c_slave;
 #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/pci_ids.h +2 -0
index 39e9f1d..1f2e0dd 100644
@@ -105,3 +105,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_machine_fv.c +3 -0
index 260cda3..39ee7c7 100644
@@ -35,6 +35,7 @@
 
 #include "xen_common.h"
 #include "xen/hvm/hvm_info_table.h"
+#include "xen_platform.h"
 
 #define MAX_IDE_BUS 2
 
@@ -88,6 +89,8 @@ static void xen_init_fv(ram_addr_t ram_size,
 
     pc_vga_init(pci_bus);
 
+    pci_xen_platform_init(pci_bus);
+
     /* init basic PC hardware */
     pc_basic_device_init(isa_irq, &floppy_controller, &rtc_state);
 
hw/xen_platform.c new file +431 -0

431 lines not on this page · raw message

hw/xen_platform.h new file +8 -0
new file mode 100644
index 0000000..574eecd
@@ -0,0 +1,8 @@
+#ifndef XEN_PLATFORM_H
+#define XEN_PLATFORM_H
+
+#include "hw/pci.h"
+
+void pci_xen_platform_init(PCIBus *bus);
+
+#endif
Signature · 1 line
1.6.5
#7 lore raw

RFC PATCH v4 7/14 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/piix_pci.c |   28 ++++++++++++++++++++++++++--
 hw/xen.h      |    6 ++++++
 xen-all.c     |   31 +++++++++++++++++++++++++++++++
 xen-stub.c    |   13 +++++++++++++
 4 files changed, 76 insertions(+), 2 deletions(-)
hw/piix_pci.c +26 -2
index f152a0f..6d96b18 100644
@@ -28,6 +28,7 @@
 #include "pci_host.h"
 #include "isa.h"
 #include "sysbus.h"
+#include "xen.h"
 
 /*
  * I440FX chipset data sheet.
@@ -150,6 +151,13 @@ static void i440fx_write_config(PCIDevice *dev,
     }
 }
 
+static void i440fx_write_config_xen(PCIDevice *dev,
+                                    uint32_t address, uint32_t val, int len)
+{
+    xen_piix_pci_write_config_client(address, val, len);
+    i440fx_write_config(dev, address, val, len);
+}
+
 static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)
 {
     PCII440FXState *d = opaque;
@@ -229,13 +237,21 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq *
     s->bus = b;
     qdev_init_nofail(dev);
 
-    d = pci_create_simple(b, 0, "i440FX");
+    if (xen_enabled()) {
+        d = pci_create_simple(b, 0, "i440FX-xen");
+    } else {
+        d = pci_create_simple(b, 0, "i440FX");
+    }
     *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
 
     piix3 = DO_UPCAST(PIIX3State, dev,
                       pci_create_simple_multifunction(b, -1, true, "PIIX3"));
     piix3->pic = pic;
-    pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3, 4);
+    if (xen_enabled()) {
+        pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq, piix3, 4);
+    } else {
+        pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3, 4);
+    }
     (*pi440fx_state)->piix3 = piix3;
 
     *piix3_devfn = piix3->dev.devfn;
@@ -350,6 +366,14 @@ static PCIDeviceInfo i440fx_info[] = {
         .init         = i440fx_initfn,
         .config_write = i440fx_write_config,
     },{
+        .qdev.name    = "i440FX-xen",
+        .qdev.desc    = "Host bridge",
+        .qdev.size    = sizeof(PCII440FXState),
+        .qdev.vmsd    = &vmstate_i440fx,
+        .qdev.no_user = 1,
+        .init         = i440fx_initfn,
+        .config_write = i440fx_write_config_xen,
+    },{
         .qdev.name    = "PIIX3",
         .qdev.desc    = "ISA bridge",
         .qdev.size    = sizeof(PIIX3State),
hw/xen.h +6 -0
index 14bbb6e..c5189b1 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)
@@ -26,6 +28,10 @@ extern int xen_allowed;
 #define xen_enabled() (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);
+
 int xen_init(int smp_cpus);
 
 #endif /* QEMU_HW_XEN_H */
xen-all.c +31 -0
index 42c93ba..f913e1f 100644
@@ -8,9 +8,40 @@
 
 #include "config.h"
 
+#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(int smp_cpus)
xen-stub.c +13 -0
index 0fa9c51..07e64bc 100644
@@ -11,6 +11,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(int smp_cpus)
 {
     return -ENOSYS;
Signature · 1 line
1.6.5
#8 lore raw

RFC PATCH v4 8/14 xen: add a 8259 Interrupt Controller

In reply to [email protected]

From: Anthony PERARD <[email protected]>

Introduce a 8259 Interrupt Controller for target-xen; every set_irq call makes a Xen hypercall.

---
 hw/xen_common.h     |    2 ++
 hw/xen_machine_fv.c |    5 ++---
 xen-all.c           |   12 ++++++++++++
 3 files changed, 16 insertions(+), 3 deletions(-)
hw/xen_common.h +2 -0
index 4c0f97d..a24bcb3 100644
@@ -44,4 +44,6 @@ typedef xc_interface *qemu_xc_interface;
 #  define xc_fd(xen_xc)                          (*(int*)xen_xc)
 #endif
 
+qemu_irq *i8259_xen_init(void);
+
 #endif /* QEMU_HW_XEN_COMMON_H */
hw/xen_machine_fv.c +2 -3
index 39ee7c7..fe4491f 100644
@@ -36,6 +36,7 @@
 #include "xen_common.h"
 #include "xen/hvm/hvm_info_table.h"
 #include "xen_platform.h"
+#include "xen_common.h"
 
 #define MAX_IDE_BUS 2
 
@@ -51,7 +52,6 @@ static void xen_init_fv(ram_addr_t ram_size,
     PCIBus *pci_bus;
     PCII440FXState *i440fx_state;
     int piix3_devfn = -1;
-    qemu_irq *cpu_irq;
     qemu_irq *isa_irq;
     qemu_irq *i8259;
     qemu_irq *cmos_s3;
@@ -75,8 +75,7 @@ static void xen_init_fv(ram_addr_t ram_size,
     env = cpu_init(cpu_model);
     env->halted = 1;
 
-    cpu_irq = pc_allocate_cpu_irq();
-    i8259 = i8259_init(cpu_irq[0]);
+    i8259 = i8259_xen_init();
     isa_irq_state = qemu_mallocz(sizeof (*isa_irq_state));
     isa_irq_state->i8259 = i8259;
 
xen-all.c +12 -0
index f913e1f..90c03eb 100644
@@ -42,6 +42,18 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
     }
 }
 
+/* i8259 */
+
+static void i8259_set_irq(void *opaque, int irq, int level)
+{
+    xc_hvm_set_isa_irq_level(xen_xc, xen_domid, irq, level);
+}
+
+qemu_irq *i8259_xen_init(void)
+{
+    return qemu_allocate_irqs(i8259_set_irq, NULL, 16);
+}
+
 /* Initialise Xen */
 
 int xen_init(int smp_cpus)
Signature · 1 line
1.6.5
#9 lore raw

RFC PATCH v4 9/14 xen: Introduce the Xen mapcache

In reply to [email protected]

From: Anthony PERARD <[email protected]>

The mapcache maps chucks of guest memory on demand, unmaps them when they are not needed anymore.

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              |   39 ++++++-
 hw/xen.h            |   10 ++
 hw/xen_common.h     |    2 +
 xen-all.c           |   64 +++++++++++
 xen-mapcache-stub.c |   33 ++++++
 xen-mapcache.c      |  301 +++++++++++++++++++++++++++++++++++++++++++++++++++
 xen-mapcache.h      |   14 +++
 xen-stub.c          |    4 +
 10 files changed, 469 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 9353627..fddce71 100644
@@ -185,8 +185,11 @@ QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
 obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
 
 # xen support
+CONFIG_NO_XEN_MAPCACHE = $(if $(subst n,,$(CONFIG_XEN_MAPCACHE)),n,y)
 obj-$(CONFIG_XEN) += xen-all.o
 obj-$(CONFIG_NO_XEN) += xen-stub.o
+obj-$(CONFIG_XEN_MAPCACHE) += xen-mapcache.o
+obj-$(CONFIG_NO_XEN_MAPCACHE) += xen-mapcache-stub.o
 
 # xen full virtualized machine
 obj-i386-$(CONFIG_XEN) += xen_machine_fv.o
configure +3 -0
index 18c3fa0..e915583 100755
@@ -2812,6 +2812,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 +35 -4
index 380dab5..0de9e32 100644
@@ -39,6 +39,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>
@@ -58,8 +59,11 @@
 #include <libutil.h>
 #endif
 #endif
+#else /* !CONFIG_USER_ONLY */
+#include "xen-mapcache.h"
 #endif
 
+
 //#define DEBUG_TB_INVALIDATE
 //#define DEBUG_FLUSH
 //#define DEBUG_TLB
@@ -2833,6 +2837,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
         }
     }
 
+    new_block->offset = find_ram_offset(size);
     if (host) {
         new_block->host = host;
     } else {
@@ -2856,15 +2861,17 @@ 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
 #ifdef MADV_MERGEABLE
             madvise(new_block->host, size, MADV_MERGEABLE);
 #endif
         }
     }
-
-    new_block->offset = find_ram_offset(size);
     new_block->length = size;
 
     QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next);
@@ -2905,7 +2912,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);
@@ -2931,6 +2942,15 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
         if (addr - block->offset < block->length) {
             QLIST_REMOVE(block, next);
             QLIST_INSERT_HEAD(&ram_list.blocks, block, next);
+            if (xen_mapcache_enabled()) {
+                /* We need to check if the requested address is in the RAM
+                 * because we don't want to map the entire memory in QEMU.
+                 */
+                if (block->offset == 0) {
+                    return qemu_map_cache(addr, 0, 1);
+                }
+                block->host = qemu_map_cache(block->offset, block->length, 1);
+            }
             return block->host + (addr - block->offset);
         }
     }
@@ -2949,11 +2969,19 @@ ram_addr_t qemu_ram_addr_from_host(void *ptr)
     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) {
             return block->offset + (host - block->host);
         }
     }
 
+    if (xen_mapcache_enabled()) {
+        return qemu_ram_addr_from_mapcache(ptr);
+    }
+
     fprintf(stderr, "Bad ram pointer %p\n", ptr);
     abort();
 
@@ -3728,6 +3756,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 +10 -0
index c5189b1..0261ae6 100644
@@ -28,10 +28,20 @@ extern int xen_allowed;
 #define xen_enabled() (0)
 #endif
 
+#if defined CONFIG_XEN_MAPCACHE
+#  define xen_mapcache_enabled() (xen_enabled())
+#else
+#  define xen_mapcache_enabled() (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);
 
 int xen_init(int smp_cpus);
 
+#if defined(NEED_CPU_H) && !defined(CONFIG_USER_ONLY)
+void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size);
+#endif
+
 #endif /* QEMU_HW_XEN_H */
hw/xen_common.h +2 -0
index a24bcb3..2773b45 100644
@@ -36,6 +36,8 @@ typedef int qemu_xc_interface;
     xc_gnttab_map_grant_refs(gnt, count, domids, refs, flags)
 #  define xc_gnttab_munmap(xc, gnt, pages, niov) xc_gnttab_munmap(gnt, pages, niov)
 #  define xc_gnttab_close(xc, dev)               xc_gnttab_close(dev)
+#  define xc_map_foreign_bulk(xc, domid, opts, pfns, err, size) \
+    xc_map_foreign_batch(xc, domid, opts, pfns, size)
 #else
 typedef xc_interface *qemu_xc_interface;
 #  define XC_HANDLER_INITIAL_VALUE NULL
xen-all.c +64 -0

81 lines not on this page · raw message

xen-mapcache-stub.c new file +33 -0
new file mode 100644
index 0000000..69ce2e7
@@ -0,0 +1,33 @@
+#include "config.h"
+
+#include "exec-all.h"
+#include "qemu-common.h"
+#include "cpu-common.h"
+#include "xen-mapcache.h"
+
+int qemu_map_cache_init(void)
+{
+    return 0;
+}
+
+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 +301 -0

301 lines not on this page · raw message

xen-mapcache.h new file +14 -0
new file mode 100644
index 0000000..86a017b
@@ -0,0 +1,14 @@
+#ifndef XEN_MAPCACHE_H
+#define XEN_MAPCACHE_H
+
+int      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 07e64bc..c9f477d 100644
@@ -24,6 +24,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)
+{
+}
+
 int xen_init(int smp_cpus)
 {
     return -ENOSYS;
Signature · 1 line
1.6.5
#10 lore raw

RFC PATCH v4 10/14 Introduce qemu_ram_ptr_unlock.

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_ram_ptr_unlock, the pointer may be unmap from QEMU when used with Xen.

---
 cpu-common.h   |    1 +
 exec.c         |   32 +++++++++++++++++++++++++++++---
 xen-mapcache.c |   34 ++++++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 3 deletions(-)
cpu-common.h +1 -0
index 0426bc8..378eea8 100644
@@ -46,6 +46,7 @@ ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size);
 void qemu_ram_free(ram_addr_t addr);
 /* This should only be used for ram local to a device.  */
 void *qemu_get_ram_ptr(ram_addr_t addr);
+void qemu_ram_ptr_unlock(void *addr);
 /* This should not be used by devices.  */
 ram_addr_t qemu_ram_addr_from_host(void *ptr);
 
exec.c +29 -3
index 0de9e32..0612ee4 100644
@@ -2961,6 +2961,13 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
     return NULL;
 }
 
+void qemu_ram_ptr_unlock(void *addr)
+{
+    if (xen_mapcache_enabled()) {
+        qemu_map_cache_unlock(addr);
+    }
+}
+
 /* Some of the softmmu routines need to translate from a host pointer
    (typically a TLB entry) back to a ram offset.  */
 ram_addr_t qemu_ram_addr_from_host(void *ptr)
@@ -3067,6 +3074,7 @@ static void notdirty_mem_writeb(void *opaque, target_phys_addr_t ram_addr,
                                 uint32_t val)
 {
     int dirty_flags;
+    void *vaddr;
     dirty_flags = cpu_physical_memory_get_dirty_flags(ram_addr);
     if (!(dirty_flags & CODE_DIRTY_FLAG)) {
 #if !defined(CONFIG_USER_ONLY)
@@ -3074,19 +3082,22 @@ static void notdirty_mem_writeb(void *opaque, target_phys_addr_t ram_addr,
         dirty_flags = cpu_physical_memory_get_dirty_flags(ram_addr);
 #endif
     }
-    stb_p(qemu_get_ram_ptr(ram_addr), val);
+    vaddr = qemu_get_ram_ptr(ram_addr);
+    stb_p(vaddr, val);
     dirty_flags |= (0xff & ~CODE_DIRTY_FLAG);
     cpu_physical_memory_set_dirty_flags(ram_addr, dirty_flags);
     /* we remove the notdirty callback only if the code has been
        flushed */
     if (dirty_flags == 0xff)
         tlb_set_dirty(cpu_single_env, cpu_single_env->mem_io_vaddr);
+    qemu_ram_ptr_unlock(vaddr);
 }
 
 static void notdirty_mem_writew(void *opaque, target_phys_addr_t ram_addr,
                                 uint32_t val)
 {
     int dirty_flags;
+    void *vaddr;
     dirty_flags = cpu_physical_memory_get_dirty_flags(ram_addr);
     if (!(dirty_flags & CODE_DIRTY_FLAG)) {
 #if !defined(CONFIG_USER_ONLY)
@@ -3094,19 +3105,22 @@ static void notdirty_mem_writew(void *opaque, target_phys_addr_t ram_addr,
         dirty_flags = cpu_physical_memory_get_dirty_flags(ram_addr);
 #endif
     }
-    stw_p(qemu_get_ram_ptr(ram_addr), val);
+    vaddr = qemu_get_ram_ptr(ram_addr);
+    stw_p(vaddr, val);
     dirty_flags |= (0xff & ~CODE_DIRTY_FLAG);
     cpu_physical_memory_set_dirty_flags(ram_addr, dirty_flags);
     /* we remove the notdirty callback only if the code has been
        flushed */
     if (dirty_flags == 0xff)
         tlb_set_dirty(cpu_single_env, cpu_single_env->mem_io_vaddr);
+    qemu_ram_ptr_unlock(vaddr);
 }
 
 static void notdirty_mem_writel(void *opaque, target_phys_addr_t ram_addr,
                                 uint32_t val)
 {
     int dirty_flags;
+    void *vaddr;
     dirty_flags = cpu_physical_memory_get_dirty_flags(ram_addr);
     if (!(dirty_flags & CODE_DIRTY_FLAG)) {
 #if !defined(CONFIG_USER_ONLY)
@@ -3114,13 +3128,15 @@ static void notdirty_mem_writel(void *opaque, target_phys_addr_t ram_addr,
         dirty_flags = cpu_physical_memory_get_dirty_flags(ram_addr);
 #endif
     }
-    stl_p(qemu_get_ram_ptr(ram_addr), val);
+    vaddr = qemu_get_ram_ptr(ram_addr);
+    stl_p(vaddr, val);
     dirty_flags |= (0xff & ~CODE_DIRTY_FLAG);
     cpu_physical_memory_set_dirty_flags(ram_addr, dirty_flags);
     /* we remove the notdirty callback only if the code has been
        flushed */
     if (dirty_flags == 0xff)
         tlb_set_dirty(cpu_single_env, cpu_single_env->mem_io_vaddr);
+    qemu_ram_ptr_unlock(vaddr);
 }
 
 static CPUReadMemoryFunc * const error_mem_read[3] = {
@@ -3540,6 +3556,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_ram_ptr_unlock(ptr);
             }
         } else {
             if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM &&
@@ -3570,6 +3587,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_ram_ptr_unlock(ptr);
             }
         }
         len -= l;
@@ -3610,6 +3628,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_ram_ptr_unlock(ptr);
         }
         len -= l;
         buf += l;
@@ -3792,6 +3811,7 @@ uint32_t ldl_phys(target_phys_addr_t addr)
         ptr = qemu_get_ram_ptr(pd & TARGET_PAGE_MASK) +
             (addr & ~TARGET_PAGE_MASK);
         val = ldl_p(ptr);
+        qemu_ram_ptr_unlock(ptr);
     }
     return val;
 }
@@ -3830,6 +3850,7 @@ uint64_t ldq_phys(target_phys_addr_t addr)
         ptr = qemu_get_ram_ptr(pd & TARGET_PAGE_MASK) +
             (addr & ~TARGET_PAGE_MASK);
         val = ldq_p(ptr);
+        qemu_ram_ptr_unlock(ptr);
     }
     return val;
 }
@@ -3870,6 +3891,7 @@ uint32_t lduw_phys(target_phys_addr_t addr)
         ptr = qemu_get_ram_ptr(pd & TARGET_PAGE_MASK) +
             (addr & ~TARGET_PAGE_MASK);
         val = lduw_p(ptr);
+        qemu_ram_ptr_unlock(ptr);
     }
     return val;
 }
@@ -3900,6 +3922,7 @@ void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val)
         unsigned long addr1 = (pd & TARGET_PAGE_MASK) + (addr & ~TARGET_PAGE_MASK);
         ptr = qemu_get_ram_ptr(addr1);
         stl_p(ptr, val);
+        qemu_ram_ptr_unlock(ptr);
 
         if (unlikely(in_migration)) {
             if (!cpu_physical_memory_is_dirty(addr1)) {
@@ -3942,6 +3965,7 @@ void stq_phys_notdirty(target_phys_addr_t addr, uint64_t val)
         ptr = qemu_get_ram_ptr(pd & TARGET_PAGE_MASK) +
             (addr & ~TARGET_PAGE_MASK);
         stq_p(ptr, val);
+        qemu_ram_ptr_unlock(ptr);
     }
 }
 
@@ -3971,6 +3995,7 @@ void stl_phys(target_phys_addr_t addr, uint32_t val)
         /* RAM case */
         ptr = qemu_get_ram_ptr(addr1);
         stl_p(ptr, val);
+        qemu_ram_ptr_unlock(ptr);
         if (!cpu_physical_memory_is_dirty(addr1)) {
             /* invalidate code */
             tb_invalidate_phys_page_range(addr1, addr1 + 4, 0);
@@ -4014,6 +4039,7 @@ void stw_phys(target_phys_addr_t addr, uint32_t val)
         /* RAM case */
         ptr = qemu_get_ram_ptr(addr1);
         stw_p(ptr, val);
+        qemu_ram_ptr_unlock(ptr);
         if (!cpu_physical_memory_is_dirty(addr1)) {
             /* invalidate code */
             tb_invalidate_phys_page_range(addr1, addr1 + 2, 0);
xen-mapcache.c +34 -0
index c7e69e6..e407949 100644
@@ -187,6 +187,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.6.5
#11 lore raw

[Qemu-devel] Re: [PATCH RFC V4 10/14] Introduce qemu_ram_ptr_unlock.

Quoted 8 lines · On 09/28/2010 10:01 AM, [email protected] wrote:

From: Anthony PERARD<[email protected]>

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

Why isn't hooking cpu_physical_memory_{map,unmap}() not enough? That's really the intention of the API.

You only really care about guest RAM, not device memory, correct?

Regards,

Anthony Liguori

Quoted 235 lines
---
  cpu-common.h   |    1 +
  exec.c         |   32 +++++++++++++++++++++++++++++---
  xen-mapcache.c |   34 ++++++++++++++++++++++++++++++++++
  3 files changed, 64 insertions(+), 3 deletions(-)
cpu-common.h +1 -0
index 0426bc8..378eea8 100644
@@ -46,6 +46,7 @@ ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size);
  void qemu_ram_free(ram_addr_t addr);
  /* This should only be used for ram local to a device.  */
  void *qemu_get_ram_ptr(ram_addr_t addr);
+void qemu_ram_ptr_unlock(void *addr);
  /* This should not be used by devices.  */
  ram_addr_t qemu_ram_addr_from_host(void *ptr);
 
exec.c +29 -3
index 0de9e32..0612ee4 100644
@@ -2961,6 +2961,13 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
      return NULL;
  }
 
+void qemu_ram_ptr_unlock(void *addr)
+{
+    if (xen_mapcache_enabled()) {
+        qemu_map_cache_unlock(addr);
+    }
+}
+
  /* Some of the softmmu routines need to translate from a host pointer
     (typically a TLB entry) back to a ram offset.  */
  ram_addr_t qemu_ram_addr_from_host(void *ptr)
@@ -3067,6 +3074,7 @@ static void notdirty_mem_writeb(void *opaque, target_phys_addr_t ram_addr,
                                  uint32_t val)
  {
      int dirty_flags;
+    void *vaddr;
      dirty_flags = cpu_physical_memory_get_dirty_flags(ram_addr);
      if (!(dirty_flags&  CODE_DIRTY_FLAG)) {
  #if !defined(CONFIG_USER_ONLY)
@@ -3074,19 +3082,22 @@ static void notdirty_mem_writeb(void *opaque, target_phys_addr_t ram_addr,
          dirty_flags = cpu_physical_memory_get_dirty_flags(ram_addr);
  #endif
      }
-    stb_p(qemu_get_ram_ptr(ram_addr), val);
+    vaddr = qemu_get_ram_ptr(ram_addr);
+    stb_p(vaddr, val);
      dirty_flags |= (0xff&  ~CODE_DIRTY_FLAG);
      cpu_physical_memory_set_dirty_flags(ram_addr, dirty_flags);
      /* we remove the notdirty callback only if the code has been
         flushed */
      if (dirty_flags == 0xff)
          tlb_set_dirty(cpu_single_env, cpu_single_env->mem_io_vaddr);
+    qemu_ram_ptr_unlock(vaddr);
  }
 
  static void notdirty_mem_writew(void *opaque, target_phys_addr_t ram_addr,
                                  uint32_t val)
  {
      int dirty_flags;
+    void *vaddr;
      dirty_flags = cpu_physical_memory_get_dirty_flags(ram_addr);
      if (!(dirty_flags&  CODE_DIRTY_FLAG)) {
  #if !defined(CONFIG_USER_ONLY)
@@ -3094,19 +3105,22 @@ static void notdirty_mem_writew(void *opaque, target_phys_addr_t ram_addr,
          dirty_flags = cpu_physical_memory_get_dirty_flags(ram_addr);
  #endif
      }
-    stw_p(qemu_get_ram_ptr(ram_addr), val);
+    vaddr = qemu_get_ram_ptr(ram_addr);
+    stw_p(vaddr, val);
      dirty_flags |= (0xff&  ~CODE_DIRTY_FLAG);
      cpu_physical_memory_set_dirty_flags(ram_addr, dirty_flags);
      /* we remove the notdirty callback only if the code has been
         flushed */
      if (dirty_flags == 0xff)
          tlb_set_dirty(cpu_single_env, cpu_single_env->mem_io_vaddr);
+    qemu_ram_ptr_unlock(vaddr);
  }
 
  static void notdirty_mem_writel(void *opaque, target_phys_addr_t ram_addr,
                                  uint32_t val)
  {
      int dirty_flags;
+    void *vaddr;
      dirty_flags = cpu_physical_memory_get_dirty_flags(ram_addr);
      if (!(dirty_flags&  CODE_DIRTY_FLAG)) {
  #if !defined(CONFIG_USER_ONLY)
@@ -3114,13 +3128,15 @@ static void notdirty_mem_writel(void *opaque, target_phys_addr_t ram_addr,
          dirty_flags = cpu_physical_memory_get_dirty_flags(ram_addr);
  #endif
      }
-    stl_p(qemu_get_ram_ptr(ram_addr), val);
+    vaddr = qemu_get_ram_ptr(ram_addr);
+    stl_p(vaddr, val);
      dirty_flags |= (0xff&  ~CODE_DIRTY_FLAG);
      cpu_physical_memory_set_dirty_flags(ram_addr, dirty_flags);
      /* we remove the notdirty callback only if the code has been
         flushed */
      if (dirty_flags == 0xff)
          tlb_set_dirty(cpu_single_env, cpu_single_env->mem_io_vaddr);
+    qemu_ram_ptr_unlock(vaddr);
  }
 
  static CPUReadMemoryFunc * const error_mem_read[3] = {
@@ -3540,6 +3556,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_ram_ptr_unlock(ptr);
              }
          } else {
              if ((pd&  ~TARGET_PAGE_MASK)>  IO_MEM_ROM&&
@@ -3570,6 +3587,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_ram_ptr_unlock(ptr);
              }
          }
          len -= l;
@@ -3610,6 +3628,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_ram_ptr_unlock(ptr);
          }
          len -= l;
          buf += l;
@@ -3792,6 +3811,7 @@ uint32_t ldl_phys(target_phys_addr_t addr)
          ptr = qemu_get_ram_ptr(pd&  TARGET_PAGE_MASK) +
              (addr&  ~TARGET_PAGE_MASK);
          val = ldl_p(ptr);
+        qemu_ram_ptr_unlock(ptr);
      }
      return val;
  }
@@ -3830,6 +3850,7 @@ uint64_t ldq_phys(target_phys_addr_t addr)
          ptr = qemu_get_ram_ptr(pd&  TARGET_PAGE_MASK) +
              (addr&  ~TARGET_PAGE_MASK);
          val = ldq_p(ptr);
+        qemu_ram_ptr_unlock(ptr);
      }
      return val;
  }
@@ -3870,6 +3891,7 @@ uint32_t lduw_phys(target_phys_addr_t addr)
          ptr = qemu_get_ram_ptr(pd&  TARGET_PAGE_MASK) +
              (addr&  ~TARGET_PAGE_MASK);
          val = lduw_p(ptr);
+        qemu_ram_ptr_unlock(ptr);
      }
      return val;
  }
@@ -3900,6 +3922,7 @@ void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val)
          unsigned long addr1 = (pd&  TARGET_PAGE_MASK) + (addr&  ~TARGET_PAGE_MASK);
          ptr = qemu_get_ram_ptr(addr1);
          stl_p(ptr, val);
+        qemu_ram_ptr_unlock(ptr);
 
          if (unlikely(in_migration)) {
              if (!cpu_physical_memory_is_dirty(addr1)) {
@@ -3942,6 +3965,7 @@ void stq_phys_notdirty(target_phys_addr_t addr, uint64_t val)
          ptr = qemu_get_ram_ptr(pd&  TARGET_PAGE_MASK) +
              (addr&  ~TARGET_PAGE_MASK);
          stq_p(ptr, val);
+        qemu_ram_ptr_unlock(ptr);
      }
  }
 
@@ -3971,6 +3995,7 @@ void stl_phys(target_phys_addr_t addr, uint32_t val)
          /* RAM case */
          ptr = qemu_get_ram_ptr(addr1);
          stl_p(ptr, val);
+        qemu_ram_ptr_unlock(ptr);
          if (!cpu_physical_memory_is_dirty(addr1)) {
              /* invalidate code */
              tb_invalidate_phys_page_range(addr1, addr1 + 4, 0);
@@ -4014,6 +4039,7 @@ void stw_phys(target_phys_addr_t addr, uint32_t val)
          /* RAM case */
          ptr = qemu_get_ram_ptr(addr1);
          stw_p(ptr, val);
+        qemu_ram_ptr_unlock(ptr);
          if (!cpu_physical_memory_is_dirty(addr1)) {
              /* invalidate code */
              tb_invalidate_phys_page_range(addr1, addr1 + 2, 0);
xen-mapcache.c +34 -0
index c7e69e6..e407949 100644
@@ -187,6 +187,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;
#12 lore raw

[Qemu-devel] Re: [PATCH RFC V4 10/14] Introduce qemu_ram_ptr_unlock.

Quoted 7 lines · Anthony Liguori
Quoted 6 lines · On 09/28/2010 10:01 AM, [email protected] wrote:

From: Anthony PERARD<[email protected]>

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

Quoted 7 lines
Quoted 2 lines

Why isn't hooking cpu_physical_memory_{map,unmap}() not enough? That's really the intention of the API.

You only really care about guest RAM, not device memory, correct?

Yes, however at the moment all the calls to qemu_get_ram_ptr imply the mapping in qemu address space to remain valid for an unlimited amount of time.
While we can do that because now the mapcache allows to "lock" a mapping, it would be nice if an explicit qemu_ram_ptr_unlock would be provided. It is not required for xen support though.

#13 lore raw

[Qemu-devel] Re: [PATCH RFC V4 10/14] Introduce qemu_ram_ptr_unlock.

Quoted 13 lines · Stefano Stabellini
Quoted 11 lines · Anthony Liguori
Quoted 9 lines · On 09/28/2010 10:01 AM, [email protected] wrote:

From: Anthony PERARD<[email protected]>

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

Quoted 9 lines
Quoted 5 lines

Why isn't hooking cpu_physical_memory_{map,unmap}() not enough? That's really the intention of the API.

You only really care about guest RAM, not device memory, correct?

Yes, however at the moment all the calls to qemu_get_ram_ptr imply the mapping in qemu address space to remain valid for an unlimited amount of time.

Yes, but qemu_get_ram_ptr() is not a general purpose API. It really should only have one use--within exec.c to implement cpu_physical_memory_* functions. There are a few uses in hw/* but they're all wrong and should be removed. Fortunately, for the purposes of the Xen machine, almost none of them actually matter.

What I'm thinking is that RAM in Xen should not be backed at all from a RAMBlock. Instead, cpu_physical_memory_* functions should call an explicit map/unmap() function that can be implemented as qemu_get_ram_ptr() and a nop in the TCG/KVM case and as explicit map cache operations in the Xen case.

Regards,

Anthony Liguori

Quoted 6 lines

While we can do that because now the mapcache allows to "lock" a mapping, it would be nice if an explicit qemu_ram_ptr_unlock would be provided. It is not required for xen support though.

#14 lore raw

[Qemu-devel] Re: [PATCH RFC V4 10/14] Introduce qemu_ram_ptr_unlock.

Quoted 24 lines · Anthony Liguori
Quoted 13 lines · Stefano Stabellini
Quoted 11 lines · Anthony Liguori
Quoted 9 lines · On 09/28/2010 10:01 AM, [email protected] wrote:

From: Anthony PERARD<[email protected]>

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

Quoted 9 lines
Quoted 5 lines

Why isn't hooking cpu_physical_memory_{map,unmap}() not enough? That's really the intention of the API.

You only really care about guest RAM, not device memory, correct?

Yes, however at the moment all the calls to qemu_get_ram_ptr imply the mapping in qemu address space to remain valid for an unlimited amount of time.

Quoted 6 lines

Yes, but qemu_get_ram_ptr() is not a general purpose API. It really should only have one use--within exec.c to implement cpu_physical_memory_* functions. There are a few uses in hw/* but they're all wrong and should be removed. Fortunately, for the purposes of the Xen machine, almost none of them actually matter.

If this is the case, it is even better :)
Can we replace the call to qemu_get_ram_ptr with cpu_physical_memory_map in the vga code?

Quoted 6 lines

What I'm thinking is that RAM in Xen should not be backed at all from a RAMBlock. Instead, cpu_physical_memory_* functions should call an explicit map/unmap() function that can be implemented as qemu_get_ram_ptr() and a nop in the TCG/KVM case and as explicit map cache operations in the Xen case.

Yes, we basically followed a very similar line of thought: in the current implementation we have just one ramblock as a placeholder for the guest's ram, then we have three hooks in qemu_ram_alloc_from_ptr, qemu_get_ram_ptr and qemu_ram_free for xen specific ways to allocate, map and free memory but we reuse everything else.

Let's take cpu_physical_memory_map for example: we completely reuse the generic implementation, that ends up calling either qemu_get_ram_ptr or cpu_physical_memory_rw.
In case of qemu_get_ram_ptr, we still reuse the generic code but we have a xen specific hook to call the mapcache.
In case of cpu_physical_memory_rw, we didn't need to change anything to do the mapping because it is implemented using qemu_get_ram_ptr (see above), we just added a call to qemu_ram_ptr_unlock to unlock the mapping at the end of the function (a nop for TCG/KVM).
So qemu_get_ram_ptr and qemu_ram_ptr_unlock are basically the explicit map/unmap() functions you are referring to.

We could probably remove the single ramblock we added and provide a xen specific implementation of qemu_ram_alloc_from_ptr and qemu_ram_free that don't iterate over the ramblock list if you think is better.

#15 lore raw

Re: [Qemu-devel] Re: [PATCH RFC V4 10/14] Introduce qemu_ram_ptr_unlock.

In reply to Anthony Liguori
Quoted 11 lines · Anthony Liguori
Quoted 7 lines · On 09/28/2010 10:01 AM, [email protected] wrote:

From: Anthony PERARD<[email protected]>

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

Why isn't hooking cpu_physical_memory_{map,unmap}() not enough? That's really the intention of the API.

I think quite a bunch of stuff stops working then because it doesn't properly use the map/unmap API ...

cheers,
Gerd

#16 lore raw

RFC PATCH v4 11/14 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 a1f6466..7facfae 100644
@@ -51,6 +51,8 @@ void cpu_disable_ticks(void);
 void qemu_system_reset_request(void);
 void qemu_system_shutdown_request(void);
 void qemu_system_powerdown_request(void);
+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 c0c9d32..cdd9bca 100644
@@ -1134,6 +1134,16 @@ static int powerdown_requested;
 int debug_requested;
 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.6.5
#17 lore raw

RFC PATCH v4 12/14 xen: Initialize event channels and io rings

In reply to [email protected]

From: Anthony PERARD <[email protected]>

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

---
 hw/xen_common.h |    3 +
 xen-all.c       |  395 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 398 insertions(+), 0 deletions(-)
hw/xen_common.h +3 -0
index 2773b45..b3d1fe3 100644
@@ -26,6 +26,7 @@
 /* Xen unstable */
 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
 typedef int qemu_xc_interface;
+#  define XC_INTERFACE_FMT "%i"
 #  define XC_HANDLER_INITIAL_VALUE               -1
 #  define xc_fd(xen_xc)                          xen_xc
 #  define xc_interface_open(l, dl, f)            xc_interface_open()
@@ -40,6 +41,7 @@ typedef int qemu_xc_interface;
     xc_map_foreign_batch(xc, domid, opts, pfns, size)
 #else
 typedef xc_interface *qemu_xc_interface;
+#  define XC_INTERFACE_FMT "%p"
 #  define XC_HANDLER_INITIAL_VALUE NULL
 /* FIXME The fd of xen_xc is now xen_xc->fd */
 /* fd is the first field, so this works */
@@ -47,5 +49,6 @@ typedef xc_interface *qemu_xc_interface;
 #endif
 
 qemu_irq *i8259_xen_init(void);
+void destroy_hvm_domain(void);
 
 #endif /* QEMU_HW_XEN_COMMON_H */
xen-all.c +395 -0

426 lines not on this page · raw message

Signature · 1 line
1.6.5
#18 lore raw

RFC PATCH v4 13/14 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 |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
xen-all.c +19 -0
index c33773a..d69ad16 100644
@@ -423,6 +423,22 @@ static void cpu_handle_ioreq(void *opaque)
     }
 }
 
+static void xenstore_record_dm_state(const char *state)
+{
+    char *path = NULL;
+    struct xs_handle *xenstore = xs_daemon_open();
+
+    if (asprintf(&path, "/local/domain/0/device-model/%u/state", xen_domid) == -1) {
+        fprintf(stderr, "out of memory recording dm state\n");
+        exit(1);
+    }
+    if (!xs_write(xenstore, XBT_NULL, path, state, strlen(state))) {
+        fprintf(stderr, "error recording dm state\n");
+        exit(1);
+    }
+    free(path);
+}
+
 static void xen_main_loop_prepare(XenIOState *state)
 {
     int evtchn_fd = state->xce_handle == -1 ? -1 : xc_evtchn_fd(state->xce_handle);
@@ -434,6 +450,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("running");
 }
 
 
Signature · 1 line
1.6.5
#19 lore raw

RFC PATCH v4 14/14 xen: Add a Xen specific ACPI Implementation to target-xen

In reply to [email protected]

From: Anthony PERARD <[email protected]>

Xen currently uses a different BIOS (hvmloader + rombios) therefore the Qemu acpi_piix4 implementation wouldn't work correctly with Xen. We plan on fixing this properly but at the moment we are just adding a new Xen specific acpi_piix4 implementation.
This patch is optional; without it the VM boots but it cannot shutdown properly or go to S3.

---
 Makefile.target     |    1 +
 hw/xen_acpi_piix4.c |  411 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/xen_common.h     |    3 +
 hw/xen_machine_fv.c |    6 +-
 4 files changed, 416 insertions(+), 5 deletions(-)
 create mode 100644 hw/xen_acpi_piix4.c
Makefile.target +1 -0
index fddce71..c796566 100644
@@ -194,6 +194,7 @@ obj-$(CONFIG_NO_XEN_MAPCACHE) += xen-mapcache-stub.o
 # xen full virtualized machine
 obj-i386-$(CONFIG_XEN) += xen_machine_fv.o
 obj-i386-$(CONFIG_XEN) += xen_platform.o
+obj-i386-$(CONFIG_XEN) += xen_acpi_piix4.o
 
 # USB layer
 obj-$(CONFIG_USB_OHCI) += usb-ohci.o
hw/xen_acpi_piix4.c new file +411 -0

411 lines not on this page · raw message

hw/xen_common.h +3 -0
index b3d1fe3..ca7a76c 100644
@@ -51,4 +51,7 @@ typedef xc_interface *qemu_xc_interface;
 qemu_irq *i8259_xen_init(void);
 void destroy_hvm_domain(void);
 
+/* hw/xen_acpi_piix4.c */
+void piix4_pm_xen_init(PCIBus *bus, int devfn, qemu_irq sci_irq_spec, qemu_irq cmos_s3);
+
 #endif /* QEMU_HW_XEN_COMMON_H */
hw/xen_machine_fv.c +1 -5
index fe4491f..30bcc47 100644
@@ -55,7 +55,6 @@ static void xen_init_fv(ram_addr_t ram_size,
     qemu_irq *isa_irq;
     qemu_irq *i8259;
     qemu_irq *cmos_s3;
-    qemu_irq *smi_irq;
     IsaIrqState *isa_irq_state;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
     FDCtrl *floppy_controller;
@@ -132,10 +131,7 @@ static void xen_init_fv(ram_addr_t ram_size,
 
     if (acpi_enabled) {
         cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
-        smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
-        piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
-                isa_reserve_irq(9), *cmos_s3, *smi_irq,
-                0);
+        piix4_pm_xen_init(pci_bus, piix3_devfn + 3, isa_reserve_irq(9), *cmos_s3);
     }
 
     if (i440fx_state) {
Signature · 1 line
1.6.5