x86/hvm: wait for at least one ioreq server to be enabled
PATCH 1/1 x86/hvm: wait for at least one ioreq server to be enabled
In the case where a stub domain is providing emulation for an HVM guest, there is no interlock in the toolstack to make sure that the stub domain is up and running before the guest is unpaused.
Prior to the introduction of ioreq servers this was not a problem, since there was only ever one emulator so ioreqs were simply created anyway and the vcpu remained blocked until the stub domain started and picked up the ioreq.
Since ioreq servers allow for multiple emulators for a single guest it's not possible to know a priori which emulator will handle a particular ioreq, so emulators must attach to a guest before the guest runs.
This patch works around the lack of interlock in the toolstack for stub domains by keeping the domain paused until at least one ioreq server is created and enabled, which in practice means the stub domain is indeed up and running.
---
This patch also needs to be applied to stable-4.5
xen/arch/x86/hvm/hvm.c | 19 +++++++++++++++++++ xen/include/asm-x86/hvm/domain.h | 1 + 2 files changed, 20 insertions(+)
xen/arch/x86/hvm/hvm.c +19 -0
@@ -885,6 +885,12 @@ static void hvm_ioreq_server_enable(struct hvm_ioreq_server *s, done:spin_unlock (&s->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,
@@ -1435,6 +1441,19 @@ 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 +1 -0
@@ -84,6 +84,7 @@ struct hvm_domain {spinlock_t lock;ioservid_t id;struct list_head list; +bool_t waiting; } ioreq_server;struct hvm_ioreq_server *default_ioreq_server;
Signature · 1 line
1.7.10.4
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 06.02.15 at 13:27, <[email protected]> wrote:
In the case where a stub domain is providing emulation for an HVM guest, there is no interlock in the toolstack to make sure that the stub domain is up and running before the guest is unpaused.
Prior to the introduction of ioreq servers this was not a problem, since there was only ever one emulator so ioreqs were simply created anyway and the vcpu remained blocked until the stub domain started and picked up the ioreq.
Since ioreq servers allow for multiple emulators for a single guest it's not possible to know a priori which emulator will handle a particular ioreq, so emulators must attach to a guest before the guest runs.
Quoted 4 lines
This patch works around the lack of interlock in the toolstack for stub domains by keeping the domain paused until at least one ioreq server is created and enabled, which in practice means the stub domain is indeed up and running.
Do I understand correctly that this only deals correctly with the single server case, and the multi server case becoming functional depends on the tool stack change to be done?
xen/arch/x86/hvm/hvm.c static void hvm_ioreq_server_enable(struct hvm_ioreq_server *s, · line 894
Quoted 13 lines
xen/arch/x86/hvm/hvm.c +6
-0@@ -885,6 +885,12 @@ static void hvm_ioreq_server_enable(struct hvm_ioreq_server *s, done:spin_unlock (&s->lock); + +if ( d->arch.hvm_domain.ioreq_server.waiting ) + { + d->arch.hvm_domain.ioreq_server.waiting =0 ; +domain_unpause (d); + } }
So it takes looking up all callers to understand that this doesn't need to be atomic. This would have been avoided by mentioning this in the description or in a comment.
xen/arch/x86/hvm/hvm.c int hvm_domain_initialise(struct domain *d) · line 1452
Quoted 13 lines
xen/arch/x86/hvm/hvm.c +9
-0@@ -1435,6 +1441,19 @@ 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) ) {
Coding style.
xen/include/asm-x86/hvm/domain.h struct hvm_domain { · line 87
Quoted 7 lines
xen/include/asm-x86/hvm/domain.h +1
-0@@ -84,6 +84,7 @@ struct hvm_domain {spinlock_t lock;ioservid_t id;struct list_head list; +bool_t waiting;
At least non normal non-debug builds you've got a slot of 32 bits between id and list - please fill such gaps when adding new members rather than adding further slack space.
Jan
Quoted 24 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 06 February 2015 14:45
To: Paul Durrant
Cc: Andrew Cooper; Ian Campbell; Wei Liu; [email protected]; Keir (Xen.org)
Subject: Re: [PATCH] x86/hvm: wait for at least one ioreq server to be enabledQuoted 15 lines
Quoted 1 line
Quoted 1 line · On 06.02.15 at 13:27, <[email protected]> wrote:
In the case where a stub domain is providing emulation for an HVM guest, there is no interlock in the toolstack to make sure that the stub domain is up and running before the guest is unpaused.
Prior to the introduction of ioreq servers this was not a problem, since there was only ever one emulator so ioreqs were simply created anyway and the vcpu remained blocked until the stub domain started and picked up the ioreq.
Since ioreq servers allow for multiple emulators for a single guest it's not possible to know a priori which emulator will handle a particular ioreq, so emulators must attach to a guest before the guest runs.
Quoted 9 lines
Quoted 4 lines
This patch works around the lack of interlock in the toolstack for stub domains by keeping the domain paused until at least one ioreq server is created and enabled, which in practice means the stub domain is indeed up and running.
Do I understand correctly that this only deals correctly with the single server case, and the multi server case becoming functional depends on the tool stack change to be done?
Yes, and that was deemed too invasive for backport to stable; plus xl/libxl have not yet been taught about multiple emulators.
Quoted 15 lines
xen/arch/x86/hvm/hvm.c static void hvm_ioreq_server_enable(struct
Quoted 3 lines
xen/arch/x86/hvm/hvm.c +0
-0@@ -885,6 +885,12 @@ static void hvm_ioreq_server_enable(struct
hvm_ioreq_server*s,xen/arch/x86/hvm/hvm.c static void hvm_ioreq_server_enable(struct hvm_ioreq_server *s, · line 894
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +6
-0done:spin_unlock (&s->lock); + +if ( d->arch.hvm_domain.ioreq_server.waiting ) + { + d->arch.hvm_domain.ioreq_server.waiting =0 ; +domain_unpause (d); + } }
Quoted 3 lines
So it takes looking up all callers to understand that this doesn't need to be atomic. This would have been avoided by mentioning this in the description or in a comment.
Ok, I'll stick a comment in.
Quoted 17 lines
Quoted 4 lines
xen/arch/x86/hvm/hvm.c +0
-0@@ -1435,6 +1441,19 @@ int hvm_domain_initialise(struct domain *d)spin_lock_init (&d->arch.hvm_domain.ioreq_server.lock);xen/arch/x86/hvm/hvm.c int hvm_domain_initialise(struct domain *d) · line 1452
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +9
-0INIT_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) ) {Coding style.
Ok.
Quoted 11 lines
xen/include/asm-x86/hvm/domain.h struct hvm_domain { · line 87
Quoted 7 lines
xen/include/asm-x86/hvm/domain.h +1
-0@@ -84,6 +84,7 @@ struct hvm_domain {spinlock_t lock;ioservid_t id;struct list_head list; +bool_t waiting;At least non normal non-debug builds you've got a slot of 32 bits between id and list - please fill such gaps when adding new members rather than adding further slack space.
True, I'll re-order.
Paul
Quoted 2 lines
Jan