Skip to contentSkip to conversation

Use new QEMU xenstore protocol

PATCH In review Wei Liu 3 participants 6 messages Apr 9, 2015 – Apr 13, 2015

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

v4 cover Use new QEMU xenstore protocol

This patch sereis contains 1 patch to QEMU traditional tree and 2 patches to Xen tree.

Note that QEMU trad patch and libxl patch need to be committed at the same time. And please fold in the change to update Config.mk to libxl patch to avoid regression.

The third patch has not been acked, but the reversion doesn't affect the libxl and QEMU patch so we can commit it any time we see fit.

Wei.

author
#1 lore raw

PATCH v4 1/3 qemu-trad: xenstore: use relative path for device-model node

For QEMU traditional running in Dom0, there is no functional change because it will still write to the same /local/domain/0 path.

For QEMU traditional stubdom, this is an incompatible startup protocol change. There is a corresponding libxl changeset "libxl:
use new QEMU xenstore protocol", which has not yet been committed (54c2e621 was reverted in 84066dd4).

QEMU traditional stubdom was broken by a0731cca "ioreq-server: on-demand creation of ioreq server" in 4.5. Currently there is a workaround in -unstable dd748d12 "x86/hvm: wait for at least one ioreq server to be enabled" (which should be backported to 4.5). QEMU traditional stubdom works with that workaround in -unstable but it's not ideal situation.

---
Note:
In order to not cause a regression in -unstable, this change and libxl side change need to be committed at the same time. And libxl side patch needs to contain a updated tag that points to this commit.

---
 xenstore.c | 36 ++++++++++++------------------------
 1 file changed, 12 insertions(+), 24 deletions(-)
xenstore.c +12 -24
index b0d6f77..8af2715 100644
@@ -711,15 +711,13 @@ void xenstore_parse_domain_config(int hvm_domid)
 
 
     /* Set a watch for log-dirty commands from the migration tools */
-    if (pasprintf(&buf, "/local/domain/0/device-model/%u/logdirty/cmd",
-                  domid) != -1) {
+    if (pasprintf(&buf, "device-model/%u/logdirty/cmd", domid) != -1) {
         xs_watch(xsh, buf, "logdirty");
         fprintf(logfile, "Watching %s\n", buf);
     }
 
     /* Set a watch for suspend requests from the migration tools */
-    if (pasprintf(&buf, 
-                  "/local/domain/0/device-model/%u/command", domid) != -1) {
+    if (pasprintf(&buf, "device-model/%u/command", domid) != -1) {
         xs_watch(xsh, buf, "dm-command");
         fprintf(logfile, "Watching %s\n", buf);
     }
@@ -777,7 +775,7 @@ int xenstore_parse_disable_pf_config ()
     int disable_pf = 0;
     unsigned int len;
 
-    if (pasprintf(&buf, "/local/domain/0/device-model/%u/disable_pf",domid) == -1)
+    if (pasprintf(&buf, "device-model/%u/disable_pf",domid) == -1)
         goto out;
 
     params = xs_read(xsh, XBT_NULL, buf, &len);
@@ -807,15 +805,11 @@ static void xenstore_process_logdirty_event(void)
     unsigned int len;
 
     /* Remember the paths for the command and response entries */
-    if (pasprintf(&ret_path,
-                "/local/domain/0/device-model/%u/logdirty/ret",
-                domid) == -1) {
+    if (pasprintf(&ret_path, "device-model/%u/logdirty/ret", domid) == -1) {
         fprintf(logfile, "Log-dirty: out of memory\n");
         exit(1);
     }
-    if (pasprintf(&cmd_path,
-                "/local/domain/0/device-model/%u/logdirty/cmd",
-                domid) == -1) {
+    if (pasprintf(&cmd_path, "device-model/%u/logdirty/cmd", domid) == -1) {
         fprintf(logfile, "Log-dirty: out of memory\n");
         exit(1);
     }
@@ -854,8 +848,7 @@ static void xenstore_process_dm_command_event(void)
     char *path = NULL, *command = NULL, *par = NULL;
     unsigned int len;
 
-    if (pasprintf(&path, 
-                  "/local/domain/0/device-model/%u/command", domid) == -1) {
+    if (pasprintf(&path, "device-model/%u/command", domid) == -1) {
         fprintf(logfile, "out of memory reading dm command\n");
         goto out;
     }
@@ -874,8 +867,7 @@ static void xenstore_process_dm_command_event(void)
         xen_pause_requested = 0;
     } else if (!strncmp(command, "usb-add", len)) {
         fprintf(logfile, "dm-command: usb-add a usb device\n");
-        if (pasprintf(&path,
-                "/local/domain/0/device-model/%u/parameter", domid) == -1) {
+        if (pasprintf(&path, "device-model/%u/parameter", domid) == -1) {
             fprintf(logfile, "out of memory reading dm command parameter\n");
             goto out;
         }
@@ -888,8 +880,7 @@ static void xenstore_process_dm_command_event(void)
         fprintf(logfile, "dm-command: finish usb-add a usb device:%s\n",par);
     } else if (!strncmp(command, "usb-del", len)) {
         fprintf(logfile, "dm-command: usb-del a usb device\n");
-        if (pasprintf(&path,
-                "/local/domain/0/device-model/%u/parameter", domid) == -1) {
+        if (pasprintf(&path, "device-model/%u/parameter", domid) == -1) {
             fprintf(logfile, "out of memory reading dm command parameter\n");
             goto out;
         }
@@ -904,8 +895,7 @@ static void xenstore_process_dm_command_event(void)
     } else if (!strncmp(command, "pci-rem", len)) {
         fprintf(logfile, "dm-command: hot remove pass-through pci dev \n");
 
-        if (pasprintf(&path, 
-                      "/local/domain/0/device-model/%u/parameter", domid) == -1) {
+        if (pasprintf(&path, "device-model/%u/parameter", domid) == -1) {
             fprintf(logfile, "out of memory reading dm command parameter\n");
             goto out;
         }
@@ -918,8 +908,7 @@ static void xenstore_process_dm_command_event(void)
     } else if (!strncmp(command, "pci-ins", len)) {
         fprintf(logfile, "dm-command: hot insert pass-through pci dev \n");
 
-        if (pasprintf(&path, 
-                      "/local/domain/0/device-model/%u/parameter", domid) == -1) {
+        if (pasprintf(&path, "device-model/%u/parameter", domid) == -1) {
             fprintf(logfile, "out of memory reading dm command parameter\n");
             goto out;
         }
@@ -943,8 +932,7 @@ void xenstore_record_dm(const char *subpath, const char *state)
 {
     char *path = NULL;
 
-    if (pasprintf(&path, 
-                  "/local/domain/0/device-model/%u/%s", domid, subpath) == -1) {
+    if (pasprintf(&path, "device-model/%u/%s", domid, subpath) == -1) {
         fprintf(logfile, "out of memory recording dm \n");
         goto out;
     }
@@ -1521,7 +1509,7 @@ char *xenstore_device_model_read(int domid, const char *key, unsigned int *len)
 {
     char *path = NULL, *value = NULL;
 
-    if (pasprintf(&path, "/local/domain/0/device-model/%d/%s", domid, key) == -1)
+    if (pasprintf(&path, "device-model/%d/%s", domid, key) == -1)
         return NULL;
 
     value = xs_read(xsh, XBT_NULL, path, len);
Signature · 1 line
1.9.1
author
#2 lore raw

PATCH v4 2/3 libxl: use new QEMU xenstore protocol

In reply to Wei Liu

Originally both QEMU traditional and QEMU upstream used hardcoded /local/domain/0 paths. This patch changes the protocol to use /local/domain/$dm_domid path.

For QEMU traditional and upstream without stubdom, $dm_domid is 0 so the path is in fact still /local/domain/0.

For QEMU traditional stubdom, this is incompatible protocol change. However QEMU traditional is shipped with Xen so we are allowed to do such change. This change needs to work with corresponding QEMU traditional changeset.

There is no compatibility issue with QEMU upstream stubdom, because QEMU upstream stubdom doesn't exist yet.

Watch /local/domain/$dm_domid/device-model/$domid/state, wait until state turns "running" then unpause guest.

LIBXL_STUBDOM_START_TIMEOUT is the timeout used wait for stubdom to be ready. My test on a very old machine (Core 2 6400) showed that it might need more than 20s before the stubdom is ready to serve DomU.

---
Note:
To avoid the change of protocol causing regression, this patch should be committed with QEMU trad patch at the same time, and please fold the change to Config.mk in.

---
 tools/libxl/libxl.c          |  4 +++-
 tools/libxl/libxl_device.c   |  4 +++-
 tools/libxl/libxl_dm.c       | 46 +++++++++++++++++++++++++++++++++---
 tools/libxl/libxl_dom.c      | 56 +++++++++++++++++++++++++++-----------------
 tools/libxl/libxl_internal.h |  2 ++
 tools/libxl/libxl_pci.c      | 22 +++++++++--------
 6 files changed, 98 insertions(+), 36 deletions(-)
tools/libxl/libxl.c +3 -1
index 2a735b3..511eef1 100644
@@ -1033,7 +1033,9 @@ int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid)
     }
 
     if (type == LIBXL_DOMAIN_TYPE_HVM) {
-        path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid);
+        uint32_t dm_domid = libxl_get_stubdom_id(ctx, domid);
+
+        path = libxl__device_model_xs_path(gc, dm_domid, domid, "/state");
         state = libxl__xs_read(gc, XBT_NULL, path);
         if (state != NULL && !strcmp(state, "paused")) {
             libxl__qemu_traditional_cmd(gc, domid, "continue");
tools/libxl/libxl_device.c +3 -1
index 0f50d04..0c06dc4 100644
@@ -1188,7 +1188,9 @@ int libxl__wait_for_device_model_deprecated(libxl__gc *gc,
                                  void *check_callback_userdata)
 {
     char *path;
-    path = GCSPRINTF("/local/domain/0/device-model/%d/state", domid);
+    uint32_t dm_domid = libxl_get_stubdom_id(CTX, domid);
+
+    path = libxl__device_model_xs_path(gc, dm_domid, domid, "/state");
     return libxl__xenstore_child_wait_deprecated(gc, domid,
                                      LIBXL_DEVICE_MODEL_START_TIMEOUT,
                                      "Device Model", path, state, spawning,
tools/libxl/libxl_dm.c +43 -3

74 lines not on this page · raw message

tools/libxl/libxl_dom.c +35 -21

130 lines not on this page · raw message

tools/libxl/libxl_internal.h +2 -0
index 3aba221..9c22309 100644
@@ -86,6 +86,7 @@
 #define LIBXL_DESTROY_TIMEOUT 10
 #define LIBXL_HOTPLUG_TIMEOUT 10
 #define LIBXL_DEVICE_MODEL_START_TIMEOUT 10
+#define LIBXL_STUBDOM_START_TIMEOUT 30
 #define LIBXL_QEMU_BODGE_TIMEOUT 2
 #define LIBXL_XENCONSOLE_LIMIT 1048576
 #define LIBXL_XENCONSOLE_PROTOCOL "vt100"
@@ -3075,6 +3076,7 @@ typedef struct {
     libxl__dm_spawn_state pvqemu;
     libxl__destroy_domid_state dis;
     libxl__multidev multidev;
+    libxl__xswait_state xswait;
 } libxl__stub_dm_spawn_state;
 
 _hidden void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state*);
tools/libxl/libxl_pci.c +12 -10
index f3ae132..394f61c 100644
@@ -850,11 +850,12 @@ static int qemu_pci_add_xenstore(libxl__gc *gc, uint32_t domid,
     int rc = 0;
     char *path;
     char *state, *vdevfn;
+    uint32_t dm_domid;
 
-    path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid);
+    dm_domid = libxl_get_stubdom_id(CTX, domid);
+    path = libxl__device_model_xs_path(gc, dm_domid, domid, "/state");
     state = libxl__xs_read(gc, XBT_NULL, path);
-    path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/parameter",
-                          domid);
+    path = libxl__device_model_xs_path(gc, dm_domid, domid, "/parameter");
     if (pcidev->vdevfn) {
         libxl__xs_write(gc, XBT_NULL, path, PCI_BDF_VDEVFN","PCI_OPTIONS,
                         pcidev->domain, pcidev->bus, pcidev->dev,
@@ -869,11 +870,9 @@ static int qemu_pci_add_xenstore(libxl__gc *gc, uint32_t domid,
     libxl__qemu_traditional_cmd(gc, domid, "pci-ins");
     rc = libxl__wait_for_device_model_deprecated(gc, domid, NULL, NULL,
                                       pci_ins_check, state);
-    path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/parameter",
-                          domid);
+    path = libxl__device_model_xs_path(gc, dm_domid, domid, "/parameter");
     vdevfn = libxl__xs_read(gc, XBT_NULL, path);
-    path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state",
-                          domid);
+    path = libxl__device_model_xs_path(gc, dm_domid, domid, "/state");
     if ( rc < 0 )
         LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
                    "qemu refused to add device: %s", vdevfn);
@@ -1175,10 +1174,13 @@ static int qemu_pci_remove_xenstore(libxl__gc *gc, uint32_t domid,
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char *state;
     char *path;
+    uint32_t dm_domid;
 
-    path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid);
+    dm_domid = libxl_get_stubdom_id(CTX, domid);
+
+    path = libxl__device_model_xs_path(gc, dm_domid, domid, "/state");
     state = libxl__xs_read(gc, XBT_NULL, path);
-    path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/parameter", domid);
+    path = libxl__device_model_xs_path(gc, dm_domid, domid, "/parameter");
     libxl__xs_write(gc, XBT_NULL, path, PCI_BDF, pcidev->domain,
                     pcidev->bus, pcidev->dev, pcidev->func);
 
@@ -1196,7 +1198,7 @@ static int qemu_pci_remove_xenstore(libxl__gc *gc, uint32_t domid,
             return ERROR_FAIL;
         }
     }
-    path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid);
+    path = libxl__device_model_xs_path(gc, dm_domid, domid, "/state");
     xs_write(ctx->xsh, XBT_NULL, path, state, strlen(state));
 
     return 0;
Signature · 1 line
1.9.1
author
#4 lore raw

PATCH v4 3/3 Revert "x86/hvm: wait for at least one ioreq server to be enabled"

In reply to Wei Liu

This reverts commit dd748d128d86996592afafea02e578cc7d4e6d42.

We don't need this workaround anymore since we have fixed the toolstack interlock problem that affects stubdom.

---
 xen/arch/x86/hvm/hvm.c           | 21 ---------------------
 xen/include/asm-x86/hvm/domain.h |  1 -
 2 files changed, 22 deletions(-)
xen/arch/x86/hvm/hvm.c +0 -21
index bfde380..8b62296 100644
@@ -893,13 +893,6 @@ static void hvm_ioreq_server_enable(struct hvm_ioreq_server *s,
 
   done:
     spin_unlock(&s->lock);
-
-    /* This check is protected by the domain ioreq server lock. */
-    if ( d->arch.hvm_domain.ioreq_server.waiting )
-    {
-        d->arch.hvm_domain.ioreq_server.waiting = 0;
-        domain_unpause(d);
-    }
 }
 
 static void hvm_ioreq_server_disable(struct hvm_ioreq_server *s,
@@ -1451,20 +1444,6 @@ int hvm_domain_initialise(struct domain *d)
 
     spin_lock_init(&d->arch.hvm_domain.ioreq_server.lock);
     INIT_LIST_HEAD(&d->arch.hvm_domain.ioreq_server.list);
-    
-    /*
-     * In the case where a stub domain is providing emulation for
-     * the guest, there is no interlock in the toolstack to prevent
-     * the guest from running before the stub domain is ready.
-     * Hence the domain must remain paused until at least one ioreq
-     * server is created and enabled.
-     */
-    if ( !is_pvh_domain(d) )
-    {
-        domain_pause(d);
-        d->arch.hvm_domain.ioreq_server.waiting = 1;
-    }
-
     spin_lock_init(&d->arch.hvm_domain.irq_lock);
     spin_lock_init(&d->arch.hvm_domain.uc_lock);
 
xen/include/asm-x86/hvm/domain.h +0 -1
index 0702bf5..2757c7f 100644
@@ -83,7 +83,6 @@ struct hvm_domain {
     struct {
         spinlock_t       lock;
         ioservid_t       id;
-        bool_t           waiting;
         struct list_head list;
     } ioreq_server;
     struct hvm_ioreq_server *default_ioreq_server;
Signature · 1 line
1.9.1
#3 lore raw

Re: [PATCH v4 2/3] libxl: use new QEMU xenstore protocol

In reply to Wei Liu

Wei Liu writes ("[PATCH v4 2/3] libxl: use new QEMU xenstore protocol"):

Quoted 3 lines

Originally both QEMU traditional and QEMU upstream used hardcoded /local/domain/0 paths. This patch changes the protocol to use /local/domain/$dm_domid path.

Thanks. I have committed 1/2 and 2/2 (the latter with the appropriate Config.mk change, and a minor edit to the commit message).

I will leave 3/3 until it has an appropriate ack.

Thanks,
Ian.

Reviewed-by on v4 3/3
#5 lore raw

Re: [PATCH v4 3/3] Revert "x86/hvm: wait for at least one ioreq server to be enabled"

In reply to Wei Liu
Quoted 8 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 09 April 2015 19:49
To: [email protected]
Cc: Ian Campbell; Ian Jackson; Wei Liu; Paul Durrant; Jan Beulich
Subject: [PATCH v4 3/3] Revert "x86/hvm: wait for at least one ioreq server to be enabled"

Quoted 7 lines

This reverts commit dd748d128d86996592afafea02e578cc7d4e6d42.

We don't need this workaround anymore since we have fixed the toolstack interlock problem that affects stubdom.

Cc Paul Durrant <[email protected]>

Assuming the toolstack bits are ok, I'm happy with this.

Quoted 62 lines
---
 xen/arch/x86/hvm/hvm.c           | 21 ---------------------
 xen/include/asm-x86/hvm/domain.h |  1 -
 2 files changed, 22 deletions(-)
xen/arch/x86/hvm/hvm.c +0 -7
index bfde380..8b62296 100644
@@ -893,13 +893,6 @@ static void hvm_ioreq_server_enable(struct
 hvm_ioreq_server *s,
 
   done:
     spin_unlock(&s->lock);
-
-    /* This check is protected by the domain ioreq server lock. */
-    if ( d->arch.hvm_domain.ioreq_server.waiting )
-    {
-        d->arch.hvm_domain.ioreq_server.waiting = 0;
-        domain_unpause(d);
-    }
 }
 

static void hvm_ioreq_server_disable(struct hvm_ioreq_server *s,

xen/arch/x86/hvm/hvm.c +0 -14
@@ -1451,20 +1444,6 @@ int hvm_domain_initialise(struct domain *d)
 
     spin_lock_init(&d->arch.hvm_domain.ioreq_server.lock);
     INIT_LIST_HEAD(&d->arch.hvm_domain.ioreq_server.list);
-
-    /*
-     * In the case where a stub domain is providing emulation for
-     * the guest, there is no interlock in the toolstack to prevent
-     * the guest from running before the stub domain is ready.
-     * Hence the domain must remain paused until at least one ioreq
-     * server is created and enabled.
-     */
-    if ( !is_pvh_domain(d) )
-    {
-        domain_pause(d);
-        d->arch.hvm_domain.ioreq_server.waiting = 1;
-    }
-
     spin_lock_init(&d->arch.hvm_domain.irq_lock);
     spin_lock_init(&d->arch.hvm_domain.uc_lock);
 
xen/include/asm- renamed from xen/include/asm-x86/hvm/domain.h +0 -0

x86/hvm/domain.h
index 0702bf5..2757c7f 100644

xen/include/asm-x86/hvm/domain.h +0 -2
@@ -83,7 +83,6 @@ struct hvm_domain {
     struct {
         spinlock_t       lock;
         ioservid_t       id;
-        bool_t           waiting;
         struct list_head list;
     } ioreq_server;
     struct hvm_ioreq_server *default_ioreq_server;
--

1.9.1