Fix QEMU startup protocol
v2 cover Fix QEMU startup protocol
This patch series tries to reason about various hardcoded "/local/domain/0" in libxl and 1) replace them with something sensible, 2) fix QEMU startup protocol.
Please apply a patch to QEMU traditional first, squash the update to Config.mk into "libxl: use new QEMU xenstore protocol" to keep the tree bisectable.
The new protocol is introduced in "libxl: use new QEMU xenstore protocol". Basically it replaces hardcoded "/local/domain/0" with "/local/domain/$dm_domid".
For both QEMU upstream and traditional running in Dom0, the new protocol is compatible with the old one, because in those cases $dm_domid is 0.
For QEMU traditional running in stubdom, this protocol is incompatible with old one. However this is acceptable because we always ships QEMU traditional with Xen. For Xen 4.5 we should backport Paul's workaround.
For QEMU upstream running in stubdom, there is no compatibility issue because there is no QEMU upstream stubdom yet. This patch series is also a good start to avoid making the same mistake in QEMU upstream stubdom.
Wei.
Wei Liu (5):
libxl: introduce libxl__device_model_xs_path
libxl: remove device model path in libxl__device_model_destroy
libxl: use LIBXL_TOOLSTACK_DOMID
libxl: use new QEMU xenstore protocol
Revert "x86/hvm: wait for at least one ioreq server to be enabled"
tools/libxl/libxl.c | 6 ++--- tools/libxl/libxl_device.c | 4 ++- tools/libxl/libxl_dm.c | 55 +++++++++++++++++++++++++++++++++++++--- tools/libxl/libxl_dom.c | 54 ++++++++++++++++++++++++--------------- tools/libxl/libxl_internal.c | 22 ++++++++++++++++ tools/libxl/libxl_internal.h | 5 ++++ tools/libxl/libxl_pci.c | 22 ++++++++-------- xen/arch/x86/hvm/hvm.c | 21 --------------- xen/include/asm-x86/hvm/domain.h | 1 - 9 files changed, 130 insertions(+), 60 deletions(-)
Signature · 1 line
1.9.1
PATCH v2 1/5 libxl: introduce libxl__device_model_xs_path
Introduce this helper to return xenstore path for device model to avoid handcoded paths.
--- tools/libxl/libxl_internal.c | 22 ++++++++++++++++++++++ tools/libxl/libxl_internal.h | 3 +++ 2 files changed, 25 insertions(+)
tools/libxl/libxl_internal.c +22 -0
@@ -555,6 +555,28 @@ void libxl__update_domain_configuration(libxl__gc *gc, dst->b_info.video_memkb = src->b_info.video_memkb; } +char *libxl__device_model_xs_path (libxl__gc *gc,uint32_t dm_domid, +uint32_t domid,const char *format, ...) +{ +char *s, *fmt; +va_list ap; +int ret; + + fmt =GCSPRINTF ("/local/domain/%u/device-model/%u%s" , dm_domid, + domid, format); + +va_start (ap, format); + ret =vsnprintf (NULL ,0 , fmt, ap); +va_end (ap); + + s =libxl__zalloc (gc, ret +1 ); +va_start (ap, format); + ret =vsnprintf (s, ret +1 , fmt, ap); +va_end (ap); + +return s; +} +/* * Local variables: * mode: C
tools/libxl/libxl_internal.h +3 -0
@@ -1794,6 +1794,9 @@ _hidden libxl__json_object *libxl__json_parse(libxl__gc *gc_opt, const char *s); _hidden int libxl__device_model_version_running(libxl__gc *gc, uint32_t domid);/* Return the system-wide default device model */ _hidden libxl_device_model_version libxl__default_device_model(libxl__gc *gc); +_hidden char *libxl__device_model_xs_path(libxl__gc *gc, uint32_t dm_domid, +uint32_t domid, +const char *format, ...);/* Check how executes hotplug script currently */ int libxl__hotplug_settings (libxl__gc *gc,xs_transaction_t t);
Signature · 1 line
1.9.1
Re: [PATCH v2 1/5] libxl: introduce libxl__device_model_xs_path
Quoted 25 lines · Wei Liu
Introduce this helper to return xenstore path for device model to avoid handcoded paths.
Signed-off-by Wei Liu <[email protected]>--- tools/libxl/libxl_internal.c | 22 ++++++++++++++++++++++ tools/libxl/libxl_internal.h | 3 +++ 2 files changed, 25 insertions(+)tools/libxl/libxl_internal.c +8
-0@@ -555,6 +555,28 @@ void libxl__update_domain_configuration(libxl__gc *gc, dst->b_info.video_memkb = src->b_info.video_memkb; } +char *libxl__device_model_xs_path (libxl__gc *gc,uint32_t dm_domid, +uint32_t domid,const char *format, ...) +{ +char *s, *fmt; +va_list ap; +int ret; + + fmt = GCSPRINTF("/local/domain/%u/device-model/%u%s", dm_domid,
tools/libxl/libxl_internal.c void libxl__update_domain_configuration(libxl__gc *gc, · line 575
Quoted 10 lines
tools/libxl/libxl_internal.c +10
-0+ domid, format); + +va_start (ap, format); + ret =vsnprintf (NULL ,0 , fmt, ap); +va_end (ap); + + s =libxl__zalloc (gc, ret +1 ); +va_start (ap, format); + ret =vsnprintf (s, ret +1 , fmt, ap); +va_end (ap);
Please could you refactor the existing libxl__sprintf into a libxl__vsprintf (i.e. which takes a va_list, and uses va_copy for the two calls to vsnprintf). Then implement your new helper in terms of the libxl__vsprintf.
Quoted 21 lines
tools/libxl/libxl_internal.c +4
-0+ +return s; +} +/* * Local variables: * mode: C tools/libxl/libxl_internal.h +3
-0@@ -1794,6 +1794,9 @@ _hidden libxl__json_object *libxl__json_parse(libxl__gc *gc_opt, const char *s); _hidden int libxl__device_model_version_running(libxl__gc *gc, uint32_t domid);/* Return the system-wide default device model */ _hidden libxl_device_model_version libxl__default_device_model(libxl__gc *gc); +_hidden char *libxl__device_model_xs_path(libxl__gc *gc, uint32_t dm_domid, +uint32_t domid, +const char *format, ...);/* Check how executes hotplug script currently */ int libxl__hotplug_settings (libxl__gc *gc,xs_transaction_t t);
PATCH v2 2/5 libxl: remove device model path in libxl__device_model_destroy
In reply to Wei Liu... and not devices_destroy_cb because it is the right place to clean up device model stuff.
And the path should use LIBXL_TOOLSTACK_DOMID instead of hardcoded 0.
---
Changes in v2:
1. Use helper function to generate xenstore path.
--- tools/libxl/libxl.c | 2 -- tools/libxl/libxl_dm.c | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-)
tools/libxl/libxl.c +0 -2
@@ -1659,8 +1659,6 @@ static void devices_destroy_cb(libxl__egc *egc,xs_rm (ctx->xsh,XBT_NULL ,libxl__xs_libxl_path (gc, domid));xs_rm (ctx->xsh,XBT_NULL ,libxl__sprintf (gc, -"/local/domain/0/device-model/%d" , domid)); -xs_rm (ctx->xsh,XBT_NULL ,libxl__sprintf (gc,"/local/domain/%d/hvmloader" , domid));/* This is async operation, we already hold CTX lock */
tools/libxl/libxl_dm.c +5 -0
@@ -1629,6 +1629,11 @@ out:int libxl__destroy_device_model (libxl__gc *gc,uint32_t domid) { +char *path =libxl__device_model_xs_path (gc,LIBXL_TOOLSTACK_DOMID , + domid,"" ); +if (!xs_rm (CTX ->xsh,XBT_NULL , path)) +LOG (ERROR ,"xs_rm failed for %s" , path); +/* We should try to destroy the device model anyway. */ return kill_device_model (gc,GCSPRINTF ("/local/domain/%d/image/device-model-pid" , domid)); }
Signature · 1 line
1.9.1
Re: [PATCH v2 2/5] libxl: remove device model path in libxl__device_model_destroy
Quoted 6 lines · Wei Liu
... and not
devices_destroy_cbbecause it is the right place to clean up device model stuff.And the path should use
LIBXL_TOOLSTACK_DOMIDinstead of hardcoded 0.Signed-off-by Wei Liu <[email protected]>
PATCH v2 3/5 libxl: use LIBXL_TOOLSTACK_DOMID
In reply to Wei LiuThe function in question is libxl__spawn_local_dm. We should use LIBXL_TOOLSTACK_DOMID when constructing xenstore path.
Currently LIBXL_TOOLSTACK_DOMID is 0, so this patch introduces no functional change.
Use helper function to generate xenstore path.
---
Changes in v2:
1. Use helper function to generate xenstore path.
--- tools/libxl/libxl_dm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/libxl/libxl_dm.c +3 -1
@@ -1375,7 +1375,7 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss)free (path); } - path =libxl__sprintf (gc,"/local/domain/0/device-model/%d" , domid); + path =libxl__device_model_xs_path (gc,LIBXL_TOOLSTACK_DOMID , domid,"" );xs_mkdir (ctx->xsh,XBT_NULL , path); if (b_info->type == LIBXL_DOMAIN_TYPE_HVM &&
@@ -1425,6 +1425,8 @@ retry_transaction: spawn->what =GCSPRINTF ("domain %d device model" , domid); spawn->xspath =GCSPRINTF ("/local/domain/0/device-model/%d/state" , domid); + spawn->xspath =libxl__device_model_xs_path (gc,LIBXL_TOOLSTACK_DOMID , + domid,"/state" ); spawn->timeout_ms =LIBXL_DEVICE_MODEL_START_TIMEOUT *1000 ; spawn->pidpath =GCSPRINTF ("%s/image/device-model-pid" , dom_path); spawn->midproc_cb = libxl__spawn_record_pid;
Signature · 1 line
1.9.1
Re: [PATCH v2 3/5] libxl: use LIBXL_TOOLSTACK_DOMID
Quoted 9 lines · Wei Liu
The function in question is
libxl__spawn_local_dm. We should useLIBXL_TOOLSTACK_DOMIDwhen constructing xenstore path.Currently
LIBXL_TOOLSTACK_DOMIDis 0, so this patch introduces no functional change.Use helper function to generate xenstore path.
Signed-off-by Wei Liu <[email protected]>
PATCH v2 4/5 libxl: use new QEMU xenstore protocol
In reply to Wei LiuOriginally 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:
Config.mk should be updated in this patch as well. The patch to QEMU traditional can be found at
<[email protected]>
Changes in v2:
1. Use helper to generate xenstore path.
2. Fix xenstore permissions.
3. Squash patch to wait for stubdom here
3.1. Move libxl__xswait_init to right place.
3.2. Use helper to generate xenstore path.
3.3. Use only one libxl__xswait_stop.
--- tools/libxl/libxl.c | 4 +++- tools/libxl/libxl_device.c | 4 +++- tools/libxl/libxl_dm.c | 46 ++++++++++++++++++++++++++++++++++--- tools/libxl/libxl_dom.c | 54 ++++++++++++++++++++++++++++---------------- tools/libxl/libxl_internal.h | 2 ++ tools/libxl/libxl_pci.c | 22 ++++++++++-------- 6 files changed, 97 insertions(+), 35 deletions(-)
tools/libxl/libxl.c +3 -1
@@ -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
@@ -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 +34 -20
129 lines not on this page · raw message
tools/libxl/libxl_internal.h +2 -0
@@ -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"
@@ -3047,6 +3048,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
@@ -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
Re: [PATCH v2 4/5] libxl: use new QEMU xenstore protocol
tools/libxl/libxl_dom.c int libxl__toolstack_save(uint32_t domid, uint8_t **buf, · line 1529
Quoted 4 lines · Wei Liu
entries = libxl__xs_directory(gc, 0, GCSPRINTF(tools/libxl/libxl_dom.c +2
-1- "/local/domain/0/device-model/%d/physmap", domid), &num); +"/local/domain/%d/device-model/%d/physmap" , + dm_domid, domid), &num);
You've missed an opportunity to use your new helper, I think.
With that fixed: Acked-by: Ian Campbell <[email protected]>
PATCH v2 5/5 Revert "x86/hvm: wait for at least one ioreq server to be enabled"
In reply to Wei LiuThis 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
@@ -892,13 +892,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,
@@ -1450,20 +1443,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
@@ -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
Re: [PATCH v2 5/5] Revert "x86/hvm: wait for at least one ioreq server to be enabled"
Quoted 6 lines · Wei Liu
This reverts commit
dd748d128d86996592afafea02e578cc7d4e6d42.We don't need this workaround anymore since we have fixed the toolstack interlock problem that affects stubdom.
Signed-off-by Wei Liu <[email protected]>
But, really this needs acks from the x86 guys. Cc Added.
Quoted 56 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
-21@@ -892,13 +892,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,@@ -1450,20 +1443,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@@ -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;