'reset everything' approach to PVHVM guest kexec
cover 'reset everything' approach to PVHVM guest kexec
Jan and Tim,
last week you expressed some concerns about if the toolstack-based approach to PVHVM guest kexec is the best. Here you can see the 'reset everything' approach to the same problem. It is the bare minimum of what should be done to make it possible for the new kernel to boot. Despite the fact that this implementation is much smaller in size and that it doesn't require any toolstack changes I'm personally in favor of the previous toolstack-based approach as it looks more general, less fragile and easier to support to me. Please let me know your thoughts.
I used SCHEDOP_ interface here as DOMCTL_* is not currently supported in Linux kernel and I seriously doubt we need to support something different from DOMID_SELF for soft reset.
Current Linux kernel requires two changes to make use of these hypervisor changes:
1) As XS_RESET_WATCHES is not supported by oxenstored we need to try removing the watch in case add operation failed, e.g.:
drivers/xen/xenbus/xenbus_xs.c +4 -0
@@ -712,6 +712,10 @@ int register_xenbus_watch(struct xenbus_watch *watch)spin_unlock (&watches_lock); err =xs_watch (watch->node, token); +if (err) { +if (!xs_unwatch (watch->node, token)) + err =xs_watch (watch->node, token); + }if (err) {spin_lock (&watches_lock);
2) HYPERVISOR_sched_op(SCHEDOP_soft_reset, NULL) is supposed to be called in kexec/kdump situation (via machine_ops.shutdown and machine_ops.crash_shutdown handlers).
v7 of the toolstack-based approach is available here:
http://comments.gmane.org/gmane.comp.emulators.xen.devel/245183
(for some reason it is missing on http://lists.xen.org/archives/html/xen-devel/2015-05/,
there are no messages in May after May, 26 and this series was sent on May, 27)
Vitaly Kuznetsov (4):
xen: evtchn: make evtchn_reset() ready for soft reset
xen: grant_table: implement grant_table_soft_reset()
xen: implement SCHEDOP_soft_reset
xen: arch-specific hooks for domain_soft_reset()
xen/arch/arm/domain.c | 5 +++ xen/arch/x86/domain.c | 73 +++++++++++++++++++++++++++++++++++++++++++ xen/common/domain.c | 39 ++++++++++++++++++++--- xen/common/event_channel.c | 52 +++++++++++++++++------------- xen/common/grant_table.c | 62 ++++++++++++++++++++++++++++++++++++ xen/common/schedule.c | 4 +++ xen/include/public/sched.h | 7 +++++ xen/include/xen/domain.h | 4 +++ xen/include/xen/event.h | 3 ++ xen/include/xen/grant_table.h | 6 ++++ xen/include/xen/sched.h | 1 + 11 files changed, 231 insertions(+), 25 deletions(-)
Signature · 1 line
1.9.3
RFC PATCH 1/4 xen: evtchn: make evtchn_reset() ready for soft reset
We need to close all event channel so the domain performing soft reset will be able to open them back. Interdomain channels are, however, special. We need to keep track of who opened it as in (the most common) case it was opened by the control domain we won't be able (and allowed) to re-establish it.
--- xen/common/event_channel.c | 52 +++++++++++++++++++++++++++------------------- xen/include/xen/event.h | 3 +++ xen/include/xen/sched.h | 1 + 3 files changed, 35 insertions(+), 21 deletions(-)
xen/common/event_channel.c +31 -21
@@ -274,11 +274,13 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind) lchn->u.interdomain.remote_dom = rd; lchn->u.interdomain.remote_port = rport; + lchn->u.interdomain.opened_by = current->domain; lchn->state =ECS_INTERDOMAIN ;evtchn_port_init (ld, lchn); rchn->u.interdomain.remote_dom = ld; rchn->u.interdomain.remote_port = lport; + rchn->u.interdomain.opened_by = current->domain; rchn->state =ECS_INTERDOMAIN ;/*
@@ -933,26 +935,30 @@ int evtchn_unmask(unsigned int port) } -static long evtchn_reset (evtchn_reset_t *r) +void evtchn_reset (struct domain *d,bool_t soft_reset) { -domid_t dom = r->dom; -struct domain *d; -int i, rc; - - d =rcu_lock_domain_by_any_id (dom); -if ( d ==NULL ) -return -ESRCH ; - - rc =xsm_evtchn_reset (XSM_TARGET , current->domain, d); -if ( rc ) - goto out; +int i; +struct evtchn *chn; +/* +* ECS_INTERDOMAIN channels with port number suitable for the 2-level ABI +* opened by other domains should remain opened as the domain doing soft +* reset won't be able to reopen them. +* __evtchn_close() also leaves consumer_is_xen() channels open. +*/ for ( i =0 ;port_is_valid (d, i); i++ ) + { + chn =evtchn_from_port (d, i); +if ( !soft_reset || + i >= (BITS_PER_EVTCHN_WORD (d) *BITS_PER_EVTCHN_WORD (d)) || + chn->state !=ECS_INTERDOMAIN || + chn->u.interdomain.opened_by == d ) (void )__evtchn_close (d, i); + }spin_lock (&d->event_lock); -if ( (dom ==DOMID_SELF ) && d->evtchn_fifo ) +if ( (d == current->domain) && d->evtchn_fifo ) {/* * Guest domain called EVTCHNOP_reset with DOMID_SELF, destroying
@@ -964,13 +970,6 @@ static long evtchn_reset(evtchn_reset_t *r) }spin_unlock (&d->event_lock); - - rc =0 ; - -out: -rcu_unlock_domain (d); - -return rc; }static long evtchn_set_priority (const struct evtchn_set_priority *set_priority)
@@ -1097,9 +1096,20 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)case EVTCHNOP_reset: {struct evtchn_reset reset; +struct domain *d; +if (copy_from_guest (&reset, arg,1 ) !=0 )return -EFAULT ; - rc =evtchn_reset (&reset); + + d =rcu_lock_domain_by_any_id (reset.dom); +if ( d ==NULL ) +return -ESRCH ; + + rc =xsm_evtchn_reset (XSM_TARGET , current->domain, d); +if ( !rc ) +evtchn_reset (d,0 ); + +rcu_unlock_domain (d);break ; }
xen/include/xen/event.h +3 -0
@@ -130,6 +130,9 @@ void evtchn_check_pollers(struct domain *d, unsigned int port);void evtchn_2l_init (struct domain *d); +/* Close all event channels and reset to 2-level ABI */ +void evtchn_reset (struct domain *d,bool_t soft_reset); +/* * Low-level event channel port ops. */
xen/include/xen/sched.h +1 -0
@@ -98,6 +98,7 @@ struct evtchnstruct {evtchn_port_t remote_port;struct domain *remote_dom; +struct domain *opened_by; } interdomain;/* state == ECS_INTERDOMAIN */ struct {u32 irq;
Signature · 1 line
1.9.3
Re: [PATCH RFC 1/4] xen: evtchn: make evtchn_reset() ready for soft reset
Quoted 5 lines · Vitaly Kuznetsov
We need to close all event channel so the domain performing soft reset will be able to open them back. Interdomain channels are, however, special. We need to keep track of who opened it as in (the most common) case it was opened by the control domain we won't be able (and allowed) to re-establish it.
I'm not sure I understand -- can you give an example of what this is avoiding? I would have thought that the kexec'ing VM needs to tear down _all_ its connections and then restart the ones it wantrs in the new OS.
Cheers,
Tim.
Quoted 134 lines
Signed-off-by Vitaly Kuznetsov <[email protected]>--- xen/common/event_channel.c | 52 +++++++++++++++++++++++++++------------------- xen/include/xen/event.h | 3 +++ xen/include/xen/sched.h | 1 + 3 files changed, 35 insertions(+), 21 deletions(-)xen/common/event_channel.c +31
-21@@ -274,11 +274,13 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind) lchn->u.interdomain.remote_dom = rd; lchn->u.interdomain.remote_port = rport; + lchn->u.interdomain.opened_by = current->domain; lchn->state =ECS_INTERDOMAIN ;evtchn_port_init (ld, lchn); rchn->u.interdomain.remote_dom = ld; rchn->u.interdomain.remote_port = lport; + rchn->u.interdomain.opened_by = current->domain; rchn->state =ECS_INTERDOMAIN ;/* @@ -933,26 +935,30 @@ int evtchn_unmask(unsigned int port) } -static long evtchn_reset (evtchn_reset_t *r) +void evtchn_reset (struct domain *d,bool_t soft_reset) { -domid_t dom = r->dom; -struct domain *d; -int i, rc; - - d =rcu_lock_domain_by_any_id (dom); -if ( d ==NULL ) -return -ESRCH ; - - rc =xsm_evtchn_reset (XSM_TARGET , current->domain, d); -if ( rc ) - goto out; +int i; +struct evtchn *chn; +/* +* ECS_INTERDOMAIN channels with port number suitable for the 2-level ABI +* opened by other domains should remain opened as the domain doing soft +* reset won't be able to reopen them. +* __evtchn_close() also leaves consumer_is_xen() channels open. +*/ for ( i =0 ;port_is_valid (d, i); i++ ) + { + chn =evtchn_from_port (d, i); +if ( !soft_reset || + i >= (BITS_PER_EVTCHN_WORD (d) *BITS_PER_EVTCHN_WORD (d)) || + chn->state !=ECS_INTERDOMAIN || + chn->u.interdomain.opened_by == d ) (void )__evtchn_close (d, i); + }spin_lock (&d->event_lock); -if ( (dom ==DOMID_SELF ) && d->evtchn_fifo ) +if ( (d == current->domain) && d->evtchn_fifo ) {/* * Guest domain called EVTCHNOP_reset with DOMID_SELF, destroying @@ -964,13 +970,6 @@ static long evtchn_reset(evtchn_reset_t *r) }spin_unlock (&d->event_lock); - - rc =0 ; - -out: -rcu_unlock_domain (d); - -return rc; }static long evtchn_set_priority (const struct evtchn_set_priority *set_priority)@@ -1097,9 +1096,20 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)case EVTCHNOP_reset: {struct evtchn_reset reset; +struct domain *d; +if (copy_from_guest (&reset, arg,1 ) !=0 )return -EFAULT ; - rc =evtchn_reset (&reset); + + d =rcu_lock_domain_by_any_id (reset.dom); +if ( d ==NULL ) +return -ESRCH ; + + rc =xsm_evtchn_reset (XSM_TARGET , current->domain, d); +if ( !rc ) +evtchn_reset (d,0 ); + +rcu_unlock_domain (d);break ; }xen/include/xen/event.h +3
-0@@ -130,6 +130,9 @@ void evtchn_check_pollers(struct domain *d, unsigned int port);void evtchn_2l_init (struct domain *d); +/* Close all event channels and reset to 2-level ABI */ +void evtchn_reset (struct domain *d,bool_t soft_reset); +/* * Low-level event channel port ops. */ xen/include/xen/sched.h +1
-0@@ -98,6 +98,7 @@ struct evtchnstruct {evtchn_port_t remote_port;struct domain *remote_dom; +struct domain *opened_by; } interdomain;/* state == ECS_INTERDOMAIN */ struct {u32 irq;Signature · 1 line
1.9.3
Re: [PATCH RFC 1/4] xen: evtchn: make evtchn_reset() ready for soft reset
Quoted 8 lines · Tim Deegan
Quoted 5 lines · Vitaly Kuznetsov
We need to close all event channel so the domain performing soft reset will be able to open them back. Interdomain channels are, however, special. We need to keep track of who opened it as in (the most common) case it was opened by the control domain we won't be able (and allowed) to re-establish it.
Quoted 4 lines
I'm not sure I understand -- can you give an example of what this is avoiding? I would have thought that the kexec'ing VM needs to tear down _all_ its connections and then restart the ones it wantrs in the new OS.
There are some that are in state ECS_UNBOUND (console, xenstore, I think) at start of day that are allocated on behalf of the domain by the toolstack. The kexec'd image will expect them in these same state.
David
Re: [PATCH RFC 1/4] xen: evtchn: make evtchn_reset() ready for soft reset
Quoted 9 lines · David Vrabel
Quoted 8 lines · Tim Deegan
Quoted 5 lines · Vitaly Kuznetsov
We need to close all event channel so the domain performing soft reset will be able to open them back. Interdomain channels are, however, special. We need to keep track of who opened it as in (the most common) case it was opened by the control domain we won't be able (and allowed) to re-establish it.
Quoted 8 lines
Quoted 4 lines
I'm not sure I understand -- can you give an example of what this is avoiding? I would have thought that the kexec'ing VM needs to tear down _all_ its connections and then restart the ones it wantrs in the new OS.
There are some that are in state
ECS_UNBOUND(console, xenstore, I think) at start of day that are allocated on behalf of the domain by the toolstack. The kexec'd image will expect them in these same state.
I see. But does that not come under "tear down all its connections and then restart the ones it wants"? I.e. should the guest not reset all its channels and then allocate fresh console & xenstore ones?
Tim.
Re: [PATCH RFC 1/4] xen: evtchn: make evtchn_reset() ready for soft reset
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 04.06.15 at 17:47, <[email protected]> wrote:
Quoted 14 lines · David Vrabel
Quoted 12 lines · Tim Deegan
Quoted 5 lines · Vitaly Kuznetsov
We need to close all event channel so the domain performing soft reset will be able to open them back. Interdomain channels are, however, special. We need to keep track of who opened it as in (the most common) case it was opened by the control domain we won't be able (and allowed) to re-establish it.
I'm not sure I understand -- can you give an example of what this is avoiding? I would have thought that the kexec'ing VM needs to tear down _all_ its connections and then restart the ones it wantrs in the new OS.
Quoted 7 lines
Quoted 3 lines
There are some that are in state
ECS_UNBOUND(console, xenstore, I think) at start of day that are allocated on behalf of the domain by the toolstack. The kexec'd image will expect them in these same state.I see. But does that not come under "tear down all its connections and then restart the ones it wants"? I.e. should the guest not reset all its channels and then allocate fresh console & xenstore ones?
But just like during boot the guest doesn't (and can't) created these, it also can't do so after kexec. The remote side needs to be set up for it, so it can simply bind to them. I don't think this can work without tool stack involvement.
Jan
Re: [PATCH RFC 1/4] xen: evtchn: make evtchn_reset() ready for soft reset
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 04.06.15 at 17:47, <[email protected]> wrote:
Quoted 17 lines · David Vrabel
Quoted 8 lines · Tim Deegan
Quoted 5 lines · Vitaly Kuznetsov
We need to close all event channel so the domain performing soft reset will be able to open them back. Interdomain channels are, however, special. We need to keep track of who opened it as in (the most common) case it was opened by the control domain we won't be able (and allowed) to re-establish it.
Quoted 4 lines
I'm not sure I understand -- can you give an example of what this is avoiding? I would have thought that the kexec'ing VM needs to tear down _all_ its connections and then restart the ones it wantrs in the new OS.
There are some that are in state
ECS_UNBOUND(console, xenstore, I think) at start of day that are allocated on behalf of the domain by the toolstack. The kexec'd image will expect them in these same state.
Quoted 8 lines
Quoted 3 lines
I see. But does that not come under "tear down all its connections and then restart the ones it wants"? I.e. should the guest not reset all its channels and then allocate fresh console & xenstore ones?
But just like during boot the guest doesn't (and can't) created these, it also can't do so after kexec. The remote side needs to be set up for it, so it can simply bind to them. I don't think this can work without tool stack involvement.
Which IIRC is pretty much the logic which lead to the more toolstack centric approach in the other series. Are you suggesting something in the middle?
Re: [PATCH RFC 1/4] xen: evtchn: make evtchn_reset() ready for soft reset
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 05.06.15 at 10:58, <[email protected]> wrote:
Quoted 24 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 04.06.15 at 17:47, <[email protected]> wrote:
Quoted 9 lines · David Vrabel
Quoted 8 lines · Tim Deegan
Quoted 5 lines · Vitaly Kuznetsov
We need to close all event channel so the domain performing soft reset will be able to open them back. Interdomain channels are, however, special. We need to keep track of who opened it as in (the most common) case it was opened by the control domain we won't be able (and allowed) to re-establish it.
Quoted 8 lines
Quoted 4 lines
I'm not sure I understand -- can you give an example of what this is avoiding? I would have thought that the kexec'ing VM needs to tear down _all_ its connections and then restart the ones it wantrs in the new OS.
There are some that are in state
ECS_UNBOUND(console, xenstore, I think) at start of day that are allocated on behalf of the domain by the toolstack. The kexec'd image will expect them in these same state.I see. But does that not come under "tear down all its connections and then restart the ones it wants"? I.e. should the guest not reset all its channels and then allocate fresh console & xenstore ones?
Quoted 8 lines
Quoted 4 lines
But just like during boot the guest doesn't (and can't) created these, it also can't do so after kexec. The remote side needs to be set up for it, so it can simply bind to them. I don't think this can work without tool stack involvement.
Which IIRC is pretty much the logic which lead to the more toolstack centric approach in the other series. Are you suggesting something in the middle?
The main issue with the other series was the moving of all the memory pages of the guest; I didn't mind there being tool stack parts (and considering the split of duties between hypervisor and tool stack it would also seem suspicious if domain reset could be implemented entirely in the hypervisor).
Jan
Re: [PATCH RFC 1/4] xen: evtchn: make evtchn_reset() ready for soft reset
In reply to Vitaly KuznetsovQuoted 5 lines
Quoted 1 line
Quoted 1 line · On 03.06.15 at 15:35, <[email protected]> wrote:
xen/common/event_channel.c +0
-0@@ -274,11 +274,13 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
xen/common/event_channel.c static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind) · line 284
Quoted 10 lines
xen/common/event_channel.c +2
-0lchn->u.interdomain.remote_dom = rd; lchn->u.interdomain.remote_port = rport; + lchn->u.interdomain.opened_by = current->domain; lchn->state =ECS_INTERDOMAIN ;evtchn_port_init (ld, lchn); rchn->u.interdomain.remote_dom = ld; rchn->u.interdomain.remote_port = lport; + rchn->u.interdomain.opened_by = current->domain; rchn->state =ECS_INTERDOMAIN ;
For one ld == current->domain. And I don't think you need to store domain pointers here; storing the domain ID would seem sufficient (with the nice benefit of not growing struct evtchn). Plus "opened_by" doesn't really reflect what is being done here - the event channels are being bound, not opened.
Quoted 9 lines
xen/common/event_channel.c +1
-3@@ -933,26 +935,30 @@ int evtchn_unmask(unsigned int port) } -static long evtchn_reset (evtchn_reset_t *r) +void evtchn_reset (struct domain *d,bool_t soft_reset) { -domid_t dom = r->dom; -struct domain *d;
xen/common/event_channel.c int evtchn_unmask(unsigned int port) · line 940
Quoted 10 lines
xen/common/event_channel.c +1
-9-int i, rc; - - d =rcu_lock_domain_by_any_id (dom); -if ( d ==NULL ) -return -ESRCH ; - - rc =xsm_evtchn_reset (XSM_TARGET , current->domain, d); -if ( rc ) - goto out; +int i;
unsigned int
xen/common/event_channel.c int evtchn_unmask(unsigned int port) · line 941
Quoted 1 line
xen/common/event_channel.c +1
-0+struct evtchn *chn;
const (and perhaps moved inside the loop below)
xen/common/event_channel.c int evtchn_unmask(unsigned int port) · line 946
Quoted 4 lines
xen/common/event_channel.c +4
-0+/* +* ECS_INTERDOMAIN channels with port number suitable for the 2-level ABI +* opened by other domains should remain opened as the domain doing soft +* reset won't be able to reopen them.
One question of course is - does this really apply to _all_ interdomain event channels (rather than just to the xenstore and xenconsole ones)?
Jan
Re: [PATCH RFC 1/4] xen: evtchn: make evtchn_reset() ready for soft reset
Quoted 48 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 03.06.15 at 15:35, <[email protected]> wrote:
xen/common/event_channel.c +0
-0@@ -274,11 +274,13 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)xen/common/event_channel.c static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind) · line 284
Quoted 10 lines
xen/common/event_channel.c +2
-0lchn->u.interdomain.remote_dom = rd; lchn->u.interdomain.remote_port = rport; + lchn->u.interdomain.opened_by = current->domain; lchn->state =ECS_INTERDOMAIN ;evtchn_port_init (ld, lchn); rchn->u.interdomain.remote_dom = ld; rchn->u.interdomain.remote_port = lport; + rchn->u.interdomain.opened_by = current->domain; rchn->state =ECS_INTERDOMAIN ;For one ld ==
current->domain. And I don't think you need to store domain pointers here; storing the domain ID would seem sufficient (with the nice benefit of not growing struct evtchn). Plus "opened_by" doesn't really reflect what is being done here - the event channels are being bound, not opened.Quoted 9 lines
xen/common/event_channel.c +1
-3@@ -933,26 +935,30 @@ int evtchn_unmask(unsigned int port) } -static long evtchn_reset (evtchn_reset_t *r) +void evtchn_reset (struct domain *d,bool_t soft_reset) { -domid_t dom = r->dom; -struct domain *d;xen/common/event_channel.c int evtchn_unmask(unsigned int port) · line 940
Quoted 10 lines
xen/common/event_channel.c +1
-9-int i, rc; - - d =rcu_lock_domain_by_any_id (dom); -if ( d ==NULL ) -return -ESRCH ; - - rc =xsm_evtchn_reset (XSM_TARGET , current->domain, d); -if ( rc ) - goto out; +int i;unsigned int
xen/common/event_channel.c int evtchn_unmask(unsigned int port) · line 941
Quoted 1 line
xen/common/event_channel.c +1
-0+struct evtchn *chn;const (and perhaps moved inside the loop below)
Quoted 7 lines
xen/common/event_channel.c int evtchn_unmask(unsigned int port) · line 946
Quoted 4 lines
xen/common/event_channel.c +4
-0+/* +* ECS_INTERDOMAIN channels with port number suitable for the 2-level ABI +* opened by other domains should remain opened as the domain doing soft +* reset won't be able to reopen them. One question of course is - does this really apply to _all_ interdomain event channels (rather than just to the xenstore and xenconsole ones)?
The wild guess here is that if a channel was bound by someone else the domain doing this reset operation won't probably be able (and allowed) to bind such interdomain connectivity so we need to keep it, from the hypervisor PoV xenstore and xenconsole channels are not special. We, however, won't probably need that in case we go for the toolstack-assisted approach (and as far as I understand there are no objections against such approach for now but I'll have to prototype it so we can make a decision.)
Signature · 1 line
Vitaly
RFC PATCH 2/4 xen: grant_table: implement grant_table_soft_reset()
In reply to Vitaly KuznetsovWhen soft reset is being performed we need to replace all actively granted pages with empty pages to prevent possible future memory corruption as the newly started kernel won't be aware of these granted pages.
We make the tot_pages < max_pages assumption here: previously granted pages need to belong to someone and we don't want to implement possible DoS by reassigning them to the grantee/anonymous domain/xen/.. (the malicious guest will be able to consume all host's memory).
--- xen/common/grant_table.c | 62 +++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/grant_table.h | 6 +++++ 2 files changed, 68 insertions(+)
xen/common/grant_table.c +62 -0
@@ -3120,6 +3120,68 @@ gnttab_release_mappings( } } +int grant_table_soft_reset (struct domain *d) +{ +struct grant_table *gt = d->grant_table; +struct active_grant_entry *act; +grant_ref_t ref; +unsigned long mfn_new; +struct page_info *page, *new_page; +int ret =0 ; + +spin_lock (>->lock); + +for ( ref =0 ; ref !=nr_grant_entries (gt); ref++ ) + { + act = &active_entry (gt, ref); +if ( !act->pin ) +continue ; + + page =mfn_to_page (act->frame); +if ( !page || !get_page (page, d) ) + { +printk (XENLOG_G_ERR "Dom%d's grant frame %lx (gfn %lx) is invalid" , + d->domain_id, act->gfn, act->frame); + ret = -EINVAL ; +break ; + } + +/* +* Here we assume the domain has tot_pages < max_pages. Previously +* granted page will still belong to us until it is unmapped from +* grantee. +*/ + new_page =alloc_domheap_page (d,0 ); +if ( !new_page ) + { +printk (XENLOG_G_ERR "Failed to alloc a page to replace" +" Dom%d's grant frame %lx\n" , d->domain_id, act->frame); + ret = -ENOMEM ; +put_page (page); +break ; + } + mfn_new =page_to_mfn (new_page); +guest_remove_page (d, act->gfn); + +if (guest_physmap_add_page (d, act->gfn, mfn_new,0 ) ) + { +printk (XENLOG_G_ERR "Failed to replace Dom%d's grant frame %lx" +" with new MFN %lx\n" , d->domain_id, act->frame, mfn_new); + ret = -EFAULT ; + } + +gnttab_flush_tlb (d); + +put_page (new_page); +put_page (page); + +if (ret) +break ; + } + +spin_unlock (>->lock); +return ret; +}void grant_table_destroy(
xen/include/xen/grant_table.h +6 -0
@@ -95,6 +95,12 @@ int grant_table_create(void grant_table_destroy (struct domain *d); +/* +* Replace all granted pages with empty pages for a domain to prevent possible +* future memory corruption in case of soft reset. +*/ +int grant_table_soft_reset (struct domain *d); +/* Domain death release of granted mappings of other domains' memory. */ void gnttab_release_mappings(
Signature · 1 line
1.9.3
Re: [PATCH RFC 2/4] xen: grant_table: implement grant_table_soft_reset()
Quoted 4 lines · Vitaly Kuznetsov
When soft reset is being performed we need to replace all actively granted pages with empty pages to prevent possible future memory corruption as the newly started kernel won't be aware of these granted pages.
I'm not sure about this one. IMO it's the guest's responsibility to find and disable whatever holds these grants. This is by analogy with a bus-master-capable device in a real PC: until the device is found and reset, the new OS can't use memory outside its guaranteed safe pool.
There has been talk before of an operation along the lines of "revoke this grant entry and wait for all users to release it" but that would only help with backends that are guaranteed to release grants in a reasonable time.
Cheers,
Tim.
Re: [PATCH RFC 2/4] xen: grant_table: implement grant_table_soft_reset()
Quoted 5 lines · Tim Deegan
There has been talk before of an operation along the lines of "revoke this grant entry and wait for all users to release it" but that would only help with backends that are guaranteed to release grants in a reasonable time.
Are you talking about my idea? This would be immediate because the grant mapper would provide a local page to atomically switch the foreign mapping to when the grant is revoked.
But, this isn't something that would be generally applicable to all grants.
David
Re: [PATCH RFC 2/4] xen: grant_table: implement grant_table_soft_reset()
Quoted 10 lines · David Vrabel
Quoted 5 lines · Tim Deegan
There has been talk before of an operation along the lines of "revoke this grant entry and wait for all users to release it" but that would only help with backends that are guaranteed to release grants in a reasonable time.
Are you talking about my idea? This would be immediate because the grant mapper would provide a local page to atomically switch the foreign mapping to when the grant is revoked.
That's a stronger operation than I remembered, and similar to what's happening here.
If this reset operation is to be called from the guest, then all the guest can do is reshuffle its own memory -- it can't expect to have enough spare memory to cover all outstanding granted pages.
But TBH this is a bit of a red herring; I ought not to have mentioned it. :)
Tim.
Re: [PATCH RFC 2/4] xen: grant_table: implement grant_table_soft_reset()
In reply to Vitaly KuznetsovQuoted 10 lines
Quoted 1 line
Quoted 1 line · On 03.06.15 at 15:35, <[email protected]> wrote:
When soft reset is being performed we need to replace all actively granted pages with empty pages to prevent possible future memory corruption as the newly started kernel won't be aware of these granted pages.
We make the
tot_pages<max_pagesassumption here: previously granted pages need to belong to someone and we don't want to implement possible DoS by reassigning them to the grantee/anonymous domain/xen/.. (the malicious guest will be able to consume all host's memory).
How is that going to look in practice? I.e. won't this cause frequent failures?
Quoted 15 lines
xen/common/grant_table.c +9
-0@@ -3120,6 +3120,68 @@ gnttab_release_mappings( } } +int grant_table_soft_reset (struct domain *d) +{ +struct grant_table *gt = d->grant_table; +struct active_grant_entry *act; +grant_ref_t ref; +unsigned long mfn_new; +struct page_info *page, *new_page; +int ret =0 ; +
xen/common/grant_table.c gnttab_release_mappings( · line 3141
Quoted 10 lines
xen/common/grant_table.c +10
-0+spin_lock (>->lock); + +for ( ref =0 ; ref !=nr_grant_entries (gt); ref++ ) + { + act = &active_entry (gt, ref); +if ( !act->pin ) +continue ; + + page =mfn_to_page (act->frame); +if ( !page || !get_page (page, d) )
Under what conditions would mfn_to_page() return NULL? I.e. don't you rather need to check mfn_valid(act->frame) if you want some sort of guarantee that the pointer you obtain can be dereferenced? (Quite likely this could be an ASSERT() instead of an if(), as is done elsewhere.)
xen/common/grant_table.c gnttab_release_mappings( · line 3144
Quoted 3 lines
xen/common/grant_table.c +3
-0+ { +printk (XENLOG_G_ERR "Dom%d's grant frame %lx (gfn %lx) is invalid" , + d->domain_id, act->gfn, act->frame);
Either you mean "mfn" in the format string, or you got ->gfn and ->frame swapped here.
xen/common/grant_table.c gnttab_release_mappings( · line 3146
Quoted 2 lines
xen/common/grant_table.c +2
-0+ ret = -EINVAL ; +break ;
If this happens after a successful replacement of another granted page, what is the expected disposition of the domain? I.e. is it correct to just return failure to the caller, rather than killing the domain (which is now in an inconsistent state)?
Quoted 17 lines
xen/common/grant_table.c +17
-0+ } + +/* +* Here we assume the domain has tot_pages < max_pages. Previously +* granted page will still belong to us until it is unmapped from +* grantee. +*/ + new_page =alloc_domheap_page (d,0 ); +if ( !new_page ) + { +printk (XENLOG_G_ERR "Failed to alloc a page to replace" +" Dom%d's grant frame %lx\n" , d->domain_id, act->frame); + ret = -ENOMEM ; +put_page (page); +break ; + } + mfn_new =page_to_mfn (new_page);
xen/common/grant_table.c gnttab_release_mappings( · line 3173
Quoted 10 lines
xen/common/grant_table.c +10
-0+guest_remove_page (d, act->gfn); + +if (guest_physmap_add_page (d, act->gfn, mfn_new,0 ) ) + { +printk (XENLOG_G_ERR "Failed to replace Dom%d's grant frame %lx" +" with new MFN %lx\n" , d->domain_id, act->frame, mfn_new); + ret = -EFAULT ; + } + +gnttab_flush_tlb (d);
Is this needed (a) at all or (b) on each iteration, considering that you don't remove from the grantee or de-allocate the old page?
xen/common/grant_table.c gnttab_release_mappings( · line 3176
Quoted 2 lines
xen/common/grant_table.c +2
-0+put_page (new_page); +put_page (page);
Do you really need to hold onto the page until here?
xen/common/grant_table.c gnttab_release_mappings( · line 3178
Quoted 1 line
xen/common/grant_table.c +1
-0+if (ret)
Missing spaces inside the parentheses.
xen/common/grant_table.c gnttab_release_mappings( · line 3183
Quoted 5 lines
xen/common/grant_table.c +5
-0+break ; + } + +spin_unlock (>->lock); +return ret;
Blank line before final return statement please.
Jan
Re: [PATCH RFC 2/4] xen: grant_table: implement grant_table_soft_reset()
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 03.06.15 at 15:35, <[email protected]> wrote:
When soft reset is being performed we need to replace all actively granted pages with empty pages to prevent possible future memory corruption as the newly started kernel won't be aware of these granted pages.
Quoted 8 lines
Quoted 4 lines
We make the
tot_pages<max_pagesassumption here: previously granted pages need to belong to someone and we don't want to implement possible DoS by reassigning them to the grantee/anonymous domain/xen/.. (the malicious guest will be able to consume all host's memory).How is that going to look in practice? I.e. won't this cause frequent failures?
I'm not sure we actually need that in practice. In my testing backends (even with persistent grants enabled) collaborate nicely and release all grants. I can see a single page still being held and I suppose it's being held by QEMU (haven't checked what that but I think it is the console ring). In case we go for the toolstack-assisted approach we can restart qemu and add some warning when there are active grants.
Signature · 1 line
Vitaly
Re: [PATCH RFC 2/4] xen: grant_table: implement grant_table_soft_reset()
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 08.06.15 at 16:58, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 03.06.15 at 15:35, <[email protected]> wrote:
When soft reset is being performed we need to replace all actively granted pages with empty pages to prevent possible future memory corruption as the newly started kernel won't be aware of these granted pages.
Quoted 8 lines
Quoted 4 lines
We make the
tot_pages<max_pagesassumption here: previously granted pages need to belong to someone and we don't want to implement possible DoS by reassigning them to the grantee/anonymous domain/xen/.. (the malicious guest will be able to consume all host's memory).How is that going to look in practice? I.e. won't this cause frequent failures?
Quoted 6 lines
I'm not sure we actually need that in practice. In my testing backends (even with persistent grants enabled) collaborate nicely and release all grants. I can see a single page still being held and I suppose it's being held by QEMU (haven't checked what that but I think it is the console ring). In case we go for the toolstack-assisted approach we can restart qemu and add some warning when there are active grants.
But even a single page could cause the allocation to fail because of otherwise going over the set limit.
Jan
RFC PATCH 3/4 xen: implement SCHEDOP_soft_reset
In reply to Vitaly KuznetsovReset event channels, replace grant pages with empty ones, unmount previously mounted vcpu_info.
--- xen/common/domain.c | 37 +++++++++++++++++++++++++++++++++---- xen/common/schedule.c | 4 ++++ xen/include/public/sched.h | 7 +++++++ xen/include/xen/domain.h | 2 ++ 4 files changed, 46 insertions(+), 4 deletions(-)
xen/common/domain.c +33 -4
@@ -1116,12 +1116,12 @@ int map_vcpu_info(struct vcpu *v, unsigned long gfn, unsigned offset)/* * Unmap the vcpu info page if the guest decided to place it somewhere -* else. This is only used from arch_domain_destroy, so there's no -* need to do anything clever. +* else. */ void unmap_vcpu_info (struct vcpu *v) {unsigned long mfn; +struct domain *d = v->domain;if ( v->vcpu_info_mfn ==INVALID_MFN )return ;
@@ -1129,8 +1129,9 @@ void unmap_vcpu_info(struct vcpu *v) mfn = v->vcpu_info_mfn;unmap_domain_page_global ((void *) ((unsigned long )v->vcpu_info &PAGE_MASK )); - - v->vcpu_info = &dummy_vcpu_info; + v->vcpu_info = ((v->vcpu_id <XEN_LEGACY_MAX_VCPUS ) + ? (vcpu_info_t *)&shared_info (d, vcpu_info[v->vcpu_id]) + : &dummy_vcpu_info); v->vcpu_info_mfn =INVALID_MFN ;put_page_and_type (mfn_to_page (mfn));
@@ -1446,6 +1447,34 @@ int continue_hypercall_on_cpu(return 0 ; } +int domain_soft_reset (struct domain *d) +{ +struct vcpu *v; +int ret =0 ; + + for_each_vcpu ( d, v ) + { +if ( v != current ) +vcpu_pause (v); + } + +evtchn_reset (d,1 ); + + ret =grant_table_soft_reset (d); +if ( ret ) + goto vcpu_unpause; + + for_each_vcpu ( d, v ) +unmap_vcpu_info (v); + + vcpu_unpause: + for_each_vcpu ( d, v ) +if ( v != current ) +vcpu_unpause (v); + +return ret; +} +/* * Local variables: * mode: C
xen/common/schedule.c +4 -0
@@ -1030,6 +1030,10 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)break ; } +case SCHEDOP_soft_reset: + ret =domain_soft_reset (current->domain); +break ; +default : ret = -ENOSYS ; }
xen/include/public/sched.h +7 -0
@@ -118,6 +118,13 @@* With id != 0 and timeout != 0, poke watchdog timer and set new timeout. */ #define SCHEDOP_watchdog 6 + +/* +* Do soft reset. +*/ + +#define SCHEDOP_soft_reset 7 +/* ` } */ struct sched_shutdown {
xen/include/xen/domain.h +2 -0
@@ -78,6 +78,8 @@ void arch_dump_domain_info(struct domain *d);int arch_vcpu_reset (struct vcpu *); +int domain_soft_reset (struct domain *d); +extern spinlock_t vcpu_alloc_lock;bool_t domctl_lock_acquire (void );void domctl_lock_release (void );
Signature · 1 line
1.9.3
Re: [PATCH RFC 3/4] xen: implement SCHEDOP_soft_reset
xen/common/domain.c int map_vcpu_info(struct vcpu *v, unsigned long gfn, unsigned offset) · line 1121
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 03.06.15 at 15:35, <[email protected]> wrote:
xen/common/domain.c +1
-2@@ -1116,12 +1116,12 @@ int map_vcpu_info(struct vcpu *v, unsigned long gfn, unsigned offset)/* * Unmap the vcpu info page if the guest decided to place it somewhere -* else. This is only used from arch_domain_destroy, so there's no -* need to do anything clever. +* else. */ void unmap_vcpu_info (struct vcpu *v)
Please retain the full comment, extending it by the new caller's name.
xen/common/domain.c void unmap_vcpu_info(struct vcpu *v) · line 1133
Quoted 8 lines
xen/common/domain.c +2
-2@@ -1129,8 +1129,9 @@ void unmap_vcpu_info(struct vcpu *v) mfn = v->vcpu_info_mfn;unmap_domain_page_global ((void *) ((unsigned long )v->vcpu_info &PAGE_MASK )); - - v->vcpu_info = &dummy_vcpu_info; + v->vcpu_info = ((v->vcpu_id < XEN_LEGACY_MAX_VCPUS) + ? (vcpu_info_t *)&shared_info(d, vcpu_info[v->vcpu_id])
Is this cast really needed?
xen/common/domain.c int continue_hypercall_on_cpu( · line 1453
Quoted 8 lines
xen/common/domain.c +4
-0@@ -1446,6 +1447,34 @@ int continue_hypercall_on_cpu(return 0 ; } +int domain_soft_reset (struct domain *d) +{ +struct vcpu *v; +int ret =0 ;
Pointless initializer.
Quoted 4 lines
xen/common/domain.c +4
-0+ for_each_vcpu ( d, v ) + { +if ( v != current ) +vcpu_pause (v);
xen/common/domain.c int continue_hypercall_on_cpu( · line 1468
Quoted 10 lines
xen/common/domain.c +10
-0+ } + +evtchn_reset (d,1 ); + + ret =grant_table_soft_reset (d); +if ( ret ) + goto vcpu_unpause; + + for_each_vcpu ( d, v ) +unmap_vcpu_info (v);
Indentation.
Jan
Re: [PATCH RFC 3/4] xen: implement SCHEDOP_soft_reset
Quoted 12 lines · Jan Beulich
xen/common/domain.c void unmap_vcpu_info(struct vcpu *v) · line 1133
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 03.06.15 at 15:35, <[email protected]> wrote:
xen/common/domain.c +2
-2@@ -1129,8 +1129,9 @@ void unmap_vcpu_info(struct vcpu *v) mfn = v->vcpu_info_mfn;unmap_domain_page_global ((void *) ((unsigned long )v->vcpu_info &PAGE_MASK )); - - v->vcpu_info = &dummy_vcpu_info; + v->vcpu_info = ((v->vcpu_id < XEN_LEGACY_MAX_VCPUS) + ? (vcpu_info_t *)&shared_info(d, vcpu_info[v->vcpu_id])Is this cast really needed?
Without it my gcc-4.8.3 complains:
domain.c: In function ‘unmap_vcpu_info’:
domain.c:1158:21: error: pointer type mismatch in conditional expression [-Werror]
: &dummy_vcpu_info);
^cc1: all warnings being treated as errors
Signature · 6 lines
Vitaly _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH RFC 3/4] xen: implement SCHEDOP_soft_reset
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 22.06.15 at 18:00, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
xen/common/domain.c void unmap_vcpu_info(struct vcpu *v) · line 1133
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 03.06.15 at 15:35, <[email protected]> wrote:
xen/common/domain.c +2
-2@@ -1129,8 +1129,9 @@ void unmap_vcpu_info(struct vcpu *v) mfn = v->vcpu_info_mfn;unmap_domain_page_global ((void *) ((unsigned long )v->vcpu_info &PAGE_MASK )); - - v->vcpu_info = &dummy_vcpu_info; + v->vcpu_info = ((v->vcpu_id < XEN_LEGACY_MAX_VCPUS) + ? (vcpu_info_t *)&shared_info(d, vcpu_info[v->vcpu_id])Is this cast really needed?
Quoted 8 lines
Without it my gcc-4.8.3 complains:
domain.c: In function ‘unmap_vcpu_info’:
domain.c:1158:21: error: pointer type mismatch in conditional expression [-Werror]: &dummy_vcpu_info); ^cc1: all warnings being treated as errors
Which is the kind of warning one normally should _not_ work around by adding a cast.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH RFC 3/4] xen: implement SCHEDOP_soft_reset
Quoted 25 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 22.06.15 at 18:00, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
xen/common/domain.c void unmap_vcpu_info(struct vcpu *v) · line 1133
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 03.06.15 at 15:35, <[email protected]> wrote:
xen/common/domain.c +2
-2@@ -1129,8 +1129,9 @@ void unmap_vcpu_info(struct vcpu *v) mfn = v->vcpu_info_mfn;unmap_domain_page_global ((void *) ((unsigned long )v->vcpu_info &PAGE_MASK )); - - v->vcpu_info = &dummy_vcpu_info; + v->vcpu_info = ((v->vcpu_id < XEN_LEGACY_MAX_VCPUS) + ? (vcpu_info_t *)&shared_info(d, vcpu_info[v->vcpu_id])Is this cast really needed?
Quoted 8 lines
Without it my gcc-4.8.3 complains:
domain.c: In function ‘unmap_vcpu_info’:
domain.c:1158:21: error: pointer type mismatch in conditional expression [-Werror]: &dummy_vcpu_info); ^cc1: all warnings being treated as errors
Quoted 2 lines
Which is the kind of warning one normally should _not_ work around by adding a cast.
In this (and in alloc_vcpu() from where this expression was copied) particular case this is probably OK: in struct shared_info we have 'struct vcpu_info vcpu_info[XEN_LEGACY_MAX_VCPUS]' as its first member. But I may be missing something..
Signature · 6 lines
Vitaly _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH RFC 3/4] xen: implement SCHEDOP_soft_reset
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 22.06.15 at 18:24, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 22.06.15 at 18:00, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
xen/common/domain.c void unmap_vcpu_info(struct vcpu *v) · line 1133
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 03.06.15 at 15:35, <[email protected]> wrote:
xen/common/domain.c +2
-2@@ -1129,8 +1129,9 @@ void unmap_vcpu_info(struct vcpu *v) mfn = v->vcpu_info_mfn;unmap_domain_page_global ((void *) ((unsigned long )v->vcpu_info &PAGE_MASK )); - - v->vcpu_info = &dummy_vcpu_info; + v->vcpu_info = ((v->vcpu_id < XEN_LEGACY_MAX_VCPUS) + ? (vcpu_info_t *)&shared_info(d, vcpu_info[v->vcpu_id])Is this cast really needed?
Without it my gcc-4.8.3 complains:
domain.c: In function ‘unmap_vcpu_info’:
domain.c:1158:21: error: pointer type mismatch in conditional expression [-Werror]: &dummy_vcpu_info); ^cc1: all warnings being treated as errors
Quoted 7 lines
Quoted 2 lines
Which is the kind of warning one normally should _not_ work around by adding a cast.
In this (and in
alloc_vcpu()from where this expression was copied) particular case this is probably OK: in structshared_infowe have 'structvcpu_infovcpu_info[XEN_LEGACY_MAX_VCPUS]' as its first member. But I may be missing something..
Did you read the comment accompanying the definition of __shared_info()?
The cast is presumably safe here, but it doesn't _look_ safe. And for future readers (and future changes) it would be better if it did.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH RFC 3/4] xen: implement SCHEDOP_soft_reset
Quoted 36 lines · Jan Beulich
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 22.06.15 at 18:24, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 22.06.15 at 18:00, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
xen/common/domain.c void unmap_vcpu_info(struct vcpu *v) · line 1133
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 03.06.15 at 15:35, <[email protected]> wrote:
xen/common/domain.c +2
-2@@ -1129,8 +1129,9 @@ void unmap_vcpu_info(struct vcpu *v) mfn = v->vcpu_info_mfn;unmap_domain_page_global ((void *) ((unsigned long )v->vcpu_info &PAGE_MASK )); - - v->vcpu_info = &dummy_vcpu_info; + v->vcpu_info = ((v->vcpu_id < XEN_LEGACY_MAX_VCPUS) + ? (vcpu_info_t *)&shared_info(d, vcpu_info[v->vcpu_id])Is this cast really needed?
Without it my gcc-4.8.3 complains:
domain.c: In function ‘unmap_vcpu_info’:
domain.c:1158:21: error: pointer type mismatch in conditional expression [-Werror]: &dummy_vcpu_info); ^cc1: all warnings being treated as errors
Quoted 7 lines
Quoted 2 lines
Which is the kind of warning one normally should _not_ work around by adding a cast.
In this (and in
alloc_vcpu()from where this expression was copied) particular case this is probably OK: in structshared_infowe have 'structvcpu_infovcpu_info[XEN_LEGACY_MAX_VCPUS]' as its first member. But I may be missing something..
Quoted 5 lines
Did you read the comment accompanying the definition of
__shared_info()?The cast is presumably safe here, but it doesn't _look_ safe. And for future readers (and future changes) it would be better if it did.
Sorry, it seems I don't undestand the suggestion on how to make this look better.
With CONFIG_COMPAT in both struct shared_info and struct compat_shared_info vcpu_info array is of type 'struct vcpu_info[]' but v->vcpu_info is of type 'vcpu_info_t *' which means union of 'struct vcpu_info' and 'struct compat_vcpu_info' in CONFIG_COMPAT case. Both these structures have same size of '64' on x86 so it's really up to its user how to treat this data...
Signature · 6 lines
Vitaly _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH RFC 3/4] xen: implement SCHEDOP_soft_reset
Quoted 39 lines
Quoted 1 line
Quoted 1 line · On 23.06.15 at 14:10, <[email protected]> wrote:
Quoted 36 lines · Jan Beulich
Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 22.06.15 at 18:24, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 22.06.15 at 18:00, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Review void unmap_vcpu_info(struct vcpu *v) · line 1133
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 03.06.15 at 15:35, <[email protected]> wrote:
(quoted diff) +2
-2@@ -1129,8 +1129,9 @@ void unmap_vcpu_info(struct vcpu *v) mfn = v->vcpu_info_mfn; unmap_domain_page_global((void *) ((unsigned long)v->vcpu_info & PAGE_MASK)); - - v->vcpu_info = &dummy_vcpu_info; + v->vcpu_info = ((v->vcpu_id < XEN_LEGACY_MAX_VCPUS) + ? (vcpu_info_t *)&shared_info(d, vcpu_info[v->vcpu_id])Is this cast really needed?
Quoted 8 lines
Without it my gcc-4.8.3 complains:
domain.c: In function ‘unmap_vcpu_info’:
domain.c:1158:21: error: pointer type mismatch in conditional expression [-Werror]: &dummy_vcpu_info); ^cc1: all warnings being treated as errors
Quoted 2 lines
Which is the kind of warning one normally should _not_ work around by adding a cast.
In this (and in
alloc_vcpu()from where this expression was copied) particular case this is probably OK: in structshared_infowe have 'structvcpu_infovcpu_info[XEN_LEGACY_MAX_VCPUS]' as its first member. But I may be missing something..
Quoted 8 lines
Quoted 5 lines
Did you read the comment accompanying the definition of
__shared_info()?The cast is presumably safe here, but it doesn't _look_ safe. And for future readers (and future changes) it would be better if it did.
Sorry, it seems I don't undestand the suggestion on how to make this look better.
I didn't suggest anything in particular; all I care about is for such casts to be avoided.
Quoted 6 lines
With
CONFIG_COMPATin both structshared_infoand structcompat_shared_infovcpu_infoarray is of type 'struct vcpu_info[]' butv->vcpu_infois of type 'vcpu_info_t*' which means union of 'structvcpu_info' and 'structcompat_vcpu_info' inCONFIG_COMPATcase. Both these structures have same size of '64' on x86 so it's really up to its user how to treat this data...
Sure, but that doesn't make the cast any more safe or look any better. But then again I see we already have a similar construct in alloc_vcpu(), i.e. - okay, keep it as is.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
RFC PATCH 4/4 xen: arch-specific hooks for domain_soft_reset()
In reply to Vitaly Kuznetsovx86-specific hook cleans up the pirq-emuirq mappings and replaces the shared_info frame with an empty page to support subsequent XENMAPSPACE_shared_info call.
ARM-specific hook is a noop for now.
--- xen/arch/arm/domain.c | 5 ++++ xen/arch/x86/domain.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ xen/common/domain.c | 2 ++ xen/include/xen/domain.h | 2 ++ 4 files changed, 82 insertions(+)
xen/arch/arm/domain.c +5 -0
@@ -653,6 +653,11 @@ void arch_domain_unpause(struct domain *d) { } +int arch_domain_soft_reset (struct domain *d) +{ +return 0 ; +} +static int is_guest_pv32_psr (uint32_t psr) { switch (psr & PSR_MODE_MASK)
xen/arch/x86/domain.c +73 -0
79 lines not on this page · raw message
xen/common/domain.c +2 -0
@@ -1467,6 +1467,8 @@ int domain_soft_reset(struct domain *d) for_each_vcpu ( d, v )unmap_vcpu_info (v); + ret =arch_domain_soft_reset (d); + vcpu_unpause:for_each_vcpu ( d, v ) if ( v != current )
xen/include/xen/domain.h +2 -0
@@ -65,6 +65,8 @@ void arch_domain_shutdown(struct domain *d);void arch_domain_pause (struct domain *d);void arch_domain_unpause (struct domain *d); +int arch_domain_soft_reset (struct domain *d); +int arch_set_info_guest (struct vcpu *,vcpu_guest_context_u );void arch_get_info_guest (struct vcpu *,vcpu_guest_context_u );
Signature · 1 line
1.9.3
Re: [PATCH RFC 4/4] xen: arch-specific hooks for domain_soft_reset()
Quoted 3 lines · Vitaly Kuznetsov
x86-specific hook cleans up the pirq-emuirq mappings and replaces the
shared_infoframe with an empty page to support subsequentXENMAPSPACE_shared_infocall.
That's a bit roundabout. I think we might be better off allocating a new shared-info page and abandoning the old one as an ordinary guest RAM page.
Cheers,
Tim.
Re: [PATCH RFC 4/4] xen: arch-specific hooks for domain_soft_reset()
Quoted 9 lines · Tim Deegan
Quoted 3 lines · Vitaly Kuznetsov
x86-specific hook cleans up the pirq-emuirq mappings and replaces the
shared_infoframe with an empty page to support subsequentXENMAPSPACE_shared_infocall.That's a bit roundabout. I think we might be better off allocating a new shared-info page and abandoning the old one as an ordinary guest RAM page.
I've tried looking into such approach and there is an issue: shared_info page is being allocated from Xen heap and in case it's built with CONFIG_SEPARATE_XENHEAP we can't just reassign the page to the domain's pagelist or we'll open a possibility for a domain to move itself entirely to Xen's heap by e.g looping over all its gfns, doing XENMAPSPACE_shared_info and perforting soft reset.
Signature · 1 line
Vitaly
Re: [PATCH RFC 4/4] xen: arch-specific hooks for domain_soft_reset()
Quoted 12 lines · Vitaly Kuznetsov
Quoted 9 lines · Tim Deegan
Quoted 3 lines · Vitaly Kuznetsov
x86-specific hook cleans up the pirq-emuirq mappings and replaces the
shared_infoframe with an empty page to support subsequentXENMAPSPACE_shared_infocall.That's a bit roundabout. I think we might be better off allocating a new shared-info page and abandoning the old one as an ordinary guest RAM page.
Quoted 6 lines
I've tried looking into such approach and there is an issue:
shared_infopage is being allocated from Xen heap and in case it's built withCONFIG_SEPARATE_XENHEAPwe can't just reassign the page to the domain's pagelist or we'll open a possibility for a domain to move itself entirely to Xen's heap by e.g looping over all its gfns, doingXENMAPSPACE_shared_infoand perforting soft reset.
Ah, true. So your approach of replacing it is better.
Cheers,
Tim.
Re: [PATCH RFC 4/4] xen: arch-specific hooks for domain_soft_reset()
In reply to Vitaly Kuznetsovxen/arch/x86/domain.c void arch_domain_unpause(struct domain *d) · line 688
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 03.06.15 at 15:35, <[email protected]> wrote:
xen/arch/x86/domain.c +7
-0+int arch_domain_soft_reset (struct domain *d) +{ +struct page_info *page =virt_to_page (d->shared_info), *new_page; +int ret =0 ; +struct domain *owner; +unsigned long mfn, mfn_new, gfn; +p2m_type_t __p2mt;
No need for leading underscores here.
Review
Quoted 2 lines
(quoted diff) +2
-0+ if ( is_hvm_domain(d) ) + {
Isn't the shared_info manipulation also HVM specific? Or at least paging_mode_translate()-specific? xenmem_add_to_physmap_one() bails on !paging_mode_translate()... But then I'm not really understanding the issue you try to address there anyway, and hence I may be overlooking something: Why does allocating a new page help with a subsequent XENMAPSPACE_shared_info add-to- physmap request?
Quoted 1 line
+ int i;
unsigned int
xen/arch/x86/domain.c void arch_domain_unpause(struct domain *d) · line 699
Quoted 7 lines
xen/arch/x86/domain.c +7
-0+ +spin_lock (&d->event_lock); +for ( i =1 ; i < d->nr_pirqs ; i ++ ) +if (domain_pirq_to_emuirq (d, i) !=IRQ_UNBOUND ) + { + ret =unmap_domain_pirq_emuirq (d, i); +if (ret)
Coding style.
xen/arch/x86/domain.c void arch_domain_unpause(struct domain *d) · line 705
Quoted 6 lines
xen/arch/x86/domain.c +6
-0+break ; + } +spin_unlock (&d->event_lock); + } + +if ( ret || !d->shared_info || !page )
Again - how would page end up being NULL here?
xen/arch/x86/domain.c void arch_domain_unpause(struct domain *d) · line 717
Quoted 12 lines
xen/arch/x86/domain.c +12
-0+return ret; + +/* +* shared_info page needs to be replaced with a new page, otherwise we +* will get a hole if the domain does XENMAPSPACE_shared_info +*/ + + owner =page_get_owner_and_reference (page); +if ( owner != d ) + { +put_page (page); +return 0 ;
Isn't this an error?
xen/arch/x86/domain.c void arch_domain_unpause(struct domain *d) · line 730
Quoted 13 lines
xen/arch/x86/domain.c +13
-0+ } + + mfn =page_to_mfn (page); +if ( !mfn_valid (mfn) ) + { +printk (XENLOG_G_ERR "Dom%d's shared_info page points to invalid MFN\n" , + d->domain_id); + ret = -EINVAL ; + goto fail_put_page; + } + + gfn =mfn_to_gmfn (d, mfn); +get_gfn_query (d, gfn, &__p2mt);
Ignoring the return value? I think you should do any consistency check you can in code like this.
xen/common/domain.c int domain_soft_reset(struct domain *d) · line 1474
Quoted 11 lines
xen/common/domain.c +2
-0@@ -1467,6 +1467,8 @@ int domain_soft_reset(struct domain *d) for_each_vcpu ( d, v )unmap_vcpu_info (v); + ret =arch_domain_soft_reset (d); + vcpu_unpause:for_each_vcpu ( d, v ) if ( v != current )
Similar question as on an earlier patch - is it really correct to unpause the vCPU-s again after a possible failure from arch_domain_soft_reset()?
Jan
Re: [PATCH RFC 4/4] xen: arch-specific hooks for domain_soft_reset()
Quoted 14 lines · Jan Beulich
xen/arch/x86/domain.c void arch_domain_unpause(struct domain *d) · line 688
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 03.06.15 at 15:35, <[email protected]> wrote:
xen/arch/x86/domain.c +7
-0+int arch_domain_soft_reset (struct domain *d) +{ +struct page_info *page =virt_to_page (d->shared_info), *new_page; +int ret =0 ; +struct domain *owner; +unsigned long mfn, mfn_new, gfn; +p2m_type_t __p2mt;No need for leading underscores here.
Review
Quoted 2 lines
(quoted diff) +2
-0+ if ( is_hvm_domain(d) ) + {
Quoted 7 lines
Isn't the
shared_infomanipulation also HVM specific? Or at least paging_mode_translate()-specific?xenmem_add_to_physmap_one()bails on !paging_mode_translate()... But then I'm not really understanding the issue you try to address there anyway, and hence I may be overlooking something: Why does allocating a new page help with a subsequentXENMAPSPACE_shared_infoadd-to- physmap request?
When an HVM domain starts it selects one of its pages and sacrifices it in favor of the shared_info page which belongs to xen heap, XENMAPSPACE_shared_info maps this page instead of the sacrificed one which is being freed. After kexec the domain can select another page it is willing to sacrifice and ask to map shared_info there but if we just remap it from its previous location we get a hole. So here I'm trying to unmap the shared_info page from domain's address space replacing it with an empty page.
The other possible solution was suggested by Tim: instead of sucha a swap reassign the currently-used shared_info page to the domain and allocate a new shared_info page in xen heap. I haven't tried this approach.
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/domain.c +6
-0+return ret; + +/* +* shared_info page needs to be replaced with a new page, otherwise we +* will get a hole if the domain does XENMAPSPACE_shared_info +*/
Quoted 9 lines
xen/arch/x86/domain.c void arch_domain_unpause(struct domain *d) · line 717
Quoted 6 lines
xen/arch/x86/domain.c +6
-0+ + owner =page_get_owner_and_reference (page); +if ( owner != d ) + { +put_page (page); +return 0 ;Isn't this an error?
It probably means the shared_info page was never mapped to the domain's space, no need to replace it.
Quoted 6 lines
Quoted 6 lines
xen/common/domain.c +0
-0@@ -1467,6 +1467,8 @@ int domain_soft_reset(struct domain *d) for_each_vcpu ( d, v )unmap_vcpu_info (v);
Quoted 8 lines
xen/common/domain.c int domain_soft_reset(struct domain *d) · line 1474
Quoted 5 lines
xen/common/domain.c +2
-0+ ret =arch_domain_soft_reset (d); + vcpu_unpause:for_each_vcpu ( d, v ) if ( v != current )Similar question as on an earlier patch - is it really correct to unpause the vCPU-s again after a possible failure from
arch_domain_soft_reset()?
Not sure what's the best here: unpausing and hoping the domain can cope (e.g. in kdump case we don't need much) or destroying the domain as we can't recover from all possible failures.
Signature · 1 line
Vitaly
Hi,
Quoted 4 lines · Vitaly Kuznetsov
last week you expressed some concerns about if the toolstack-based approach to PVHVM guest kexec is the best. Here you can see the 'reset everything' approach to the same problem. It is the bare minimum of what should be done to make it possible for the new kernel to boot.
Thansk for prototyping this - it's very helpful.
Quoted 5 lines
Despite
the fact that this implementation is much smaller in size and that it doesn't require any toolstack changes I'm personally in favor of the previous toolstack-based approach as it looks more general, less fragile and easier to support to me. Please let me know your thoughts.
On the contrary, this looks neater, faster and with fewer special cases (at least in the hypervisor) than the p2m-copying code. I prefer it. (I do appreciate that there may be more things needed to get to a fully working system).
Cheers,
Tim.
Vitaly Kuznetsov writes ("[PATCH RFC 0/4] 'reset everything' approach to PVHVM guest kexec"):
Quoted 2 lines
1) As
XS_RESET_WATCHESis not supported by oxenstored we need to try removing the watch in case add operation failed, e.g.:
It would surely be better to fix oxenstored. IIRC the approach of trying to track down watches is not, in general, sufficient. (BICBW.)
Ian.
Quoted 11 lines · Vitaly Kuznetsov
Jan and Tim,
last week you expressed some concerns about if the toolstack-based approach to PVHVM guest kexec is the best. Here you can see the 'reset everything' approach to the same problem. It is the bare minimum of what should be done to make it possible for the new kernel to boot. Despite the fact that this implementation is much smaller in size and that it doesn't require any toolstack changes I'm personally in favor of the previous toolstack-based approach as it looks more general, less fragile and easier to support to me. Please let me know your thoughts.
Quoted 8 lines
I used
SCHEDOP_interface here as DOMCTL_* is not currently supported in Linux kernel and I seriously doubt we need to support something different fromDOMID_SELFfor soft reset.Current Linux kernel requires two changes to make use of these hypervisor changes:
1) AsXS_RESET_WATCHESis not supported by oxenstored we need to try removing the watch in case add operation failed, e.g.:
The changeset to implement XS_RESET_WATCHES in cxenstored is 1f9d04fb021cbf35cc420d401a88c696d6524c14
It doesn't look too complicated to do that in oxenstored. Dave (oxenstored maintainer, CC'ed) might have insight.
Wei.
Quoted 44 lines
drivers/xen/xenbus/xenbus_xs.c +4
-0@@ -712,6 +712,10 @@ int register_xenbus_watch(struct xenbus_watch *watch)spin_unlock (&watches_lock); err =xs_watch (watch->node, token); +if (err) { +if (!xs_unwatch (watch->node, token)) + err =xs_watch (watch->node, token); + }if (err) {spin_lock (&watches_lock);2)
HYPERVISOR_sched_op(SCHEDOP_soft_reset, NULL)is supposed to be called in kexec/kdump situation (via machine_ops.shutdown and machine_ops.crash_shutdown handlers).v7 of the toolstack-based approach is available here:
http://comments.gmane.org/gmane.comp.emulators.xen.devel/245183
(for some reason it is missing on http://lists.xen.org/archives/html/xen-devel/2015-05/,
there are no messages in May after May, 26 and this series was sent on May, 27)Vitaly Kuznetsov (4):
xen: evtchn: makeevtchn_reset()ready for soft reset
xen:grant_table: implementgrant_table_soft_reset()
xen: implementSCHEDOP_soft_reset
xen: arch-specific hooks fordomain_soft_reset()xen/arch/arm/domain.c | 5 +++ xen/arch/x86/domain.c | 73 +++++++++++++++++++++++++++++++++++++++++++ xen/common/domain.c | 39 ++++++++++++++++++++--- xen/common/event_channel.c | 52 +++++++++++++++++------------- xen/common/grant_table.c | 62 ++++++++++++++++++++++++++++++++++++ xen/common/schedule.c | 4 +++ xen/include/public/sched.h | 7 +++++ xen/include/xen/domain.h | 4 +++ xen/include/xen/event.h | 3 ++ xen/include/xen/grant_table.h | 6 ++++ xen/include/xen/sched.h | 1 + 11 files changed, 231 insertions(+), 25 deletions(-)Signature · 1 line
1.9.3
Quoted 21 lines · Wei Liu
Quoted 11 lines · Vitaly Kuznetsov
Jan and Tim,
last week you expressed some concerns about if the toolstack-based approach to PVHVM guest kexec is the best. Here you can see the 'reset everything' approach to the same problem. It is the bare minimum of what should be done to make it possible for the new kernel to boot. Despite the fact that this implementation is much smaller in size and that it doesn't require any toolstack changes I'm personally in favor of the previous toolstack-based approach as it looks more general, less fragile and easier to support to me. Please let me know your thoughts.
Quoted 8 lines
I used
SCHEDOP_interface here as DOMCTL_* is not currently supported in Linux kernel and I seriously doubt we need to support something different fromDOMID_SELFfor soft reset.Current Linux kernel requires two changes to make use of these hypervisor changes:
1) AsXS_RESET_WATCHESis not supported by oxenstored we need to try removing the watch in case add operation failed, e.g.:
Quoted 8 lines
The changeset to implement
XS_RESET_WATCHESin cxenstored is1f9d04fb021cbf35cc420d401a88c696d6524c14It doesn't look too complicated to do that in oxenstored. Dave (oxenstored maintainer, CC'ed) might have insight.
Wei.
And I took a stab at it. Here is my oxenstored patch. May contain bugs. :-)
---8<---
Quoted 1 line
From
8dd35370442340493f856b0be8d99c87243e79f6Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Mon, 8 Jun 2015 18:39:45 +0100
Subject: [PATCH] oxenstored: implement XS_RESET_WATCHES
--- tools/ocaml/libs/xb/op.ml | 6 ++++-- tools/ocaml/libs/xb/xb.mli | 1 + tools/ocaml/xenstored/connection.ml | 8 ++++++++ tools/ocaml/xenstored/process.ml | 6 ++++++ 4 files changed, 19 insertions(+), 2 deletions(-)
tools/ocaml/libs/xb/op.ml +4 -2
@@ -19,7 +19,8 @@ type operation = Debug | Directory | Read | Getperms | Transaction_end | Introduce | Release | Getdomainpath | Write | Mkdir | Rm | Setperms | Watchevent | Error | Isintroduced | - Resume | Set_target | Restrict | Invalid + Resume | Set_target | Restrict | Reset_watches | + Invalid let operation_c_mapping = [| Debug; Directory; Read; Getperms;
@@ -27,7 +28,7 @@ let operation_c_mapping = Transaction_end; Introduce; Release; Getdomainpath; Write; Mkdir; Rm; Setperms; Watchevent; Error; Isintroduced; - Resume; Set_target; Restrict |] + Resume; Set_target; Restrict; Reset_watches |] let size = Array.length operation_c_mapping let array_search el a =
@@ -68,4 +69,5 @@ let to_string ty = | Resume -> "RESUME" | Set_target -> "SET_TARGET" | Restrict -> "RESTRICT" + | Reset_watches -> "RESET_WATCHES" | Invalid -> "INVALID"
tools/ocaml/libs/xb/xb.mli +1 -0
@@ -23,6 +23,7 @@ module Op : | Resume | Set_target | Restrict + | Reset_watches | Invalid val operation_c_mapping : operation array val size : int
tools/ocaml/xenstored/connection.ml +8 -0
@@ -186,6 +186,14 @@ let del_watch con path token = con.nb_watches <- con.nb_watches - 1; apath, w +let del_watches con = + Hashtbl.clear con.watches; + con.next_tid <- initial_next_tid + +let del_transactions con = + Hashtbl.clear con.transactions; + con.nb_watches <- 0 + let list_watches con = let ll = Hashtbl.fold (fun _ watches acc -> List.map (fun watch -> watch.path, watch.token) watches :: acc)
tools/ocaml/xenstored/process.ml +6 -0
@@ -272,6 +272,11 @@ let do_restrict con t domains cons data = in Connection.restrict con domid +(* only in xen >= 4.2 *) +let do_reset_watches con t domains cons data = + Connection.del_watches con; + Connection.del_transactions con + (* only in >= xen3.3 *) (* we ensure backward compatibility with restrict by counting the number of argument of set_target ... *) (* This is not very elegant, but it is safe as 'restrict' only restricts permission of dom0 connections *)
@@ -324,6 +329,7 @@ let function_of_type ty = | Xenbus.Xb.Op.Resume -> reply_ack do_resume | Xenbus.Xb.Op.Set_target -> reply_ack do_set_target | Xenbus.Xb.Op.Restrict -> reply_ack do_restrict + | Xenbus.Xb.Op.Reset_watches -> reply_ack do_reset_watches | Xenbus.Xb.Op.Invalid -> reply_ack do_error | _ -> reply_ack do_error
Signature · 1 line
1.9.1
Dave Scott
Acked-byQuoted 28 lines · Wei Liu
Quoted 24 lines · Wei Liu
Quoted 11 lines · Vitaly Kuznetsov
Jan and Tim,
last week you expressed some concerns about if the toolstack-based approach to PVHVM guest kexec is the best. Here you can see the 'reset everything' approach to the same problem. It is the bare minimum of what should be done to make it possible for the new kernel to boot. Despite the fact that this implementation is much smaller in size and that it doesn't require any toolstack changes I'm personally in favor of the previous toolstack-based approach as it looks more general, less fragile and easier to support to me. Please let me know your thoughts.
Quoted 8 lines
I used
SCHEDOP_interface here as DOMCTL_* is not currently supported in Linux kernel and I seriously doubt we need to support something different fromDOMID_SELFfor soft reset.Current Linux kernel requires two changes to make use of these hypervisor changes:
1) AsXS_RESET_WATCHESis not supported by oxenstored we need to try removing the watch in case add operation failed, e.g.:The changeset to implement
XS_RESET_WATCHESin cxenstored is1f9d04fb021cbf35cc420d401a88c696d6524c14
Quoted 8 lines
Quoted 5 lines
It doesn't look too complicated to do that in oxenstored. Dave (oxenstored maintainer, CC'ed) might have insight.
Wei.
And I took a stab at it. Here is my oxenstored patch. May contain bugs. :-)
That was quick :-)
I have only one question, see below:
Quoted 61 lines
---8<---
From8dd35370442340493f856b0be8d99c87243e79f6Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Mon, 8 Jun 2015 18:39:45 +0100
Subject: [PATCH] oxenstored: implementXS_RESET_WATCHESSigned-off-by Wei Liu <[email protected]>---
tools/ocaml/libs/xb/op.ml | 6 ++++-- tools/ocaml/libs/xb/xb.mli | 1 + tools/ocaml/xenstored/connection.ml | 8 ++++++++ tools/ocaml/xenstored/process.ml | 6 ++++++ 4 files changed, 19 insertions(+), 2 deletions(-)tools/ocaml/libs/xb/op.ml +2
-1@@ -19,7 +19,8 @@ type operation = Debug | Directory | Read | Getperms | Transaction_end | Introduce | Release | Getdomainpath | Write | Mkdir | Rm | Setperms | Watchevent | Error | Isintroduced | - Resume | Set_target | Restrict | Invalid + Resume | Set_target | Restrict | Reset_watches | + Invalidlet
operation_c_mapping=[| Debug; Directory; Read; Getperms;tools/ocaml/libs/xb/op.ml +1
-1@@ -27,7 +28,7 @@ let operation_c_mapping = Transaction_end; Introduce; Release; Getdomainpath; Write; Mkdir; Rm; Setperms; Watchevent; Error; Isintroduced; - Resume; Set_target; Restrict |] + Resume; Set_target; Restrict; Reset_watches |]let size = Array.length
operation_c_mappinglet
array_searchel a =tools/ocaml/libs/xb/op.ml +1
-0@@ -68,4 +69,5 @@ let to_string ty = | Resume -> "RESUME" | Set_target -> "SET_TARGET" | Restrict -> "RESTRICT" + | Reset_watches -> "RESET_WATCHES" | Invalid -> "INVALID"tools/ocaml/libs/xb/xb.mli +1
-0@@ -23,6 +23,7 @@ module Op : | Resume | Set_target | Restrict + | Reset_watches | Invalid val operation_c_mapping : operation array val size : inttools/ocaml/xenstored/connection.ml +0
-0
tools/ocaml/xenstored/connection.ml let del_watch con path token = · line 191
Quoted 6 lines
tools/ocaml/xenstored/connection.ml +3
-0@@ -186,6 +186,14 @@ let del_watch con path token = con.nb_watches <- con.nb_watches - 1; apath, w +let del_watches con = + Hashtbl.clear con.watches; + con.next_tid <- initial_next_tid
I couldn’t spot the part in the C version where the next transaction id is reset — is this a (minor) difference between the two implementations, or have I misread the code?
If you could clarify that for me, and assuming this all compiled ok, then feel free to add
Cheers,
Dave
Quoted 34 lines
tools/ocaml/xenstored/connection.ml +5
-0+ +let del_transactions con = + Hashtbl.clear con.transactions; + con.nb_watches <- 0 +let
list_watchescon =let ll = Hashtbl.fold (fun _ watches acc -> List.map (fun watch -> watch.path, watch.token) watches :: acc)tools/ocaml/xenstored/process.ml +6
-0@@ -272,6 +272,11 @@ let do_restrict con t domains cons data = in Connection.restrict con domid +(* only in xen >= 4.2 *) +let do_reset_watches con t domains cons data = + Connection.del_watches con; + Connection.del_transactions con + (* only in >= xen3.3 *) (* we ensure backward compatibility with restrict by counting the number of argument of set_target ... *) (* This is not very elegant, but it is safe as 'restrict' only restricts permission of dom0 connections *)@@ -324,6 +329,7 @@ let function_of_type ty = | Xenbus.Xb.Op.Resume -> reply_ack do_resume | Xenbus.Xb.Op.Set_target -> reply_ack do_set_target | Xenbus.Xb.Op.Restrict -> reply_ack do_restrict + | Xenbus.Xb.Op.Reset_watches -> reply_ack do_reset_watches | Xenbus.Xb.Op.Invalid -> reply_ack do_error | _ -> reply_ack do_errorSignature · 1 line
1.9.1
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 105 lines · Dave Scott
Quoted 28 lines · Wei Liu
Quoted 24 lines · Wei Liu
Quoted 11 lines · Vitaly Kuznetsov
Jan and Tim,
last week you expressed some concerns about if the toolstack-based approach to PVHVM guest kexec is the best. Here you can see the 'reset everything' approach to the same problem. It is the bare minimum of what should be done to make it possible for the new kernel to boot. Despite the fact that this implementation is much smaller in size and that it doesn't require any toolstack changes I'm personally in favor of the previous toolstack-based approach as it looks more general, less fragile and easier to support to me. Please let me know your thoughts.
Quoted 8 lines
I used
SCHEDOP_interface here as DOMCTL_* is not currently supported in Linux kernel and I seriously doubt we need to support something different fromDOMID_SELFfor soft reset.Current Linux kernel requires two changes to make use of these hypervisor changes:
1) AsXS_RESET_WATCHESis not supported by oxenstored we need to try removing the watch in case add operation failed, e.g.:The changeset to implement
XS_RESET_WATCHESin cxenstored is1f9d04fb021cbf35cc420d401a88c696d6524c14Quoted 8 lines
Quoted 5 lines
It doesn't look too complicated to do that in oxenstored. Dave (oxenstored maintainer, CC'ed) might have insight.
Wei.
And I took a stab at it. Here is my oxenstored patch. May contain bugs. :-)
That was quick :-)
I have only one question, see below:
Quoted 64 lines
---8<---
From8dd35370442340493f856b0be8d99c87243e79f6Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Mon, 8 Jun 2015 18:39:45 +0100
Subject: [PATCH] oxenstored: implementXS_RESET_WATCHESSigned-off-by Wei Liu <[email protected]>---
tools/ocaml/libs/xb/op.ml | 6 ++++-- tools/ocaml/libs/xb/xb.mli | 1 + tools/ocaml/xenstored/connection.ml | 8 ++++++++ tools/ocaml/xenstored/process.ml | 6 ++++++ 4 files changed, 19 insertions(+), 2 deletions(-)tools/ocaml/libs/xb/op.ml +2
-1@@ -19,7 +19,8 @@ type operation = Debug | Directory | Read | Getperms | Transaction_end | Introduce | Release | Getdomainpath | Write | Mkdir | Rm | Setperms | Watchevent | Error | Isintroduced | - Resume | Set_target | Restrict | Invalid + Resume | Set_target | Restrict | Reset_watches | + Invalidlet
operation_c_mapping=[| Debug; Directory; Read; Getperms;tools/ocaml/libs/xb/op.ml +1
-1@@ -27,7 +28,7 @@ let operation_c_mapping = Transaction_end; Introduce; Release; Getdomainpath; Write; Mkdir; Rm; Setperms; Watchevent; Error; Isintroduced; - Resume; Set_target; Restrict |] + Resume; Set_target; Restrict; Reset_watches |]let size = Array.length
operation_c_mappinglet
array_searchel a =tools/ocaml/libs/xb/op.ml +1
-0@@ -68,4 +69,5 @@ let to_string ty = | Resume -> "RESUME" | Set_target -> "SET_TARGET" | Restrict -> "RESTRICT" + | Reset_watches -> "RESET_WATCHES" | Invalid -> "INVALID"tools/ocaml/libs/xb/xb.mli +1
-0@@ -23,6 +23,7 @@ module Op : | Resume | Set_target | Restrict + | Reset_watches | Invalid val operation_c_mapping : operation array val size : inttools/ocaml/xenstored/connection.ml +0
-0@@ -186,6 +186,14 @@ let del_watch con path token = con.nb_watches <- con.nb_watches - 1; apath, w
Quoted 8 lines
tools/ocaml/xenstored/connection.ml let del_watch con path token = · line 191
Quoted 3 lines
tools/ocaml/xenstored/connection.ml +3
-0+let del_watches con = + Hashtbl.clear con.watches; + con.next_tid <- initial_next_tidI couldn’t spot the part in the C version where the next transaction id is reset — is this a (minor) difference between the two implementations, or have I misread the code?
If you could clarify that for me, and assuming this all compiled ok, then feel free to add
Yes, it compiles OK.
I think I will just delete that line. I couldn't recollect why I added that. Maybe it's copy-n-paste error.
Can I still have your ack if I drop that line?
Quoted 4 lines
Acked-by David Scott <[email protected]>Cheers,
Dave
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
On Tue, Jun 09, 2015 at 10:29:56AM +0100, Wei Liu wrote:
[...]
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
+ con.next_tid <-
initial_next_tidI couldn’t spot the part in the C version where the next transaction id is reset — is this a (minor) difference between the two implementations, or have I misread the code?
If you could clarify that for me, and assuming this all compiled ok, then feel free to add
Quoted 7 lines
Yes, it compiles OK.
I think I will just delete that line. I couldn't recollect why I added that. Maybe it's copy-n-paste error.
Can I still have your ack if I drop that line?
And a new hunk will be added in the next version to deal with logging.ml.
tools/ocaml/xenstored/logging.ml +1 -0
@@ -242,6 +242,7 @@ let string_of_access_type = function | Xenbus.Xb.Op.Rm -> "rm " | Xenbus.Xb.Op.Setperms -> "setperms " | Xenbus.Xb.Op.Restrict -> "restrict " + | Xenbus.Xb.Op.Reset_watches -> "reset watches" | Xenbus.Xb.Op.Set_target -> "settarget" | Xenbus.Xb.Op.Error -> "error "
Quoted 4 lines
Quoted 4 lines
Acked-by David Scott <[email protected]>Cheers,
Dave
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Dave Scott
Acked-byQuoted 18 lines · Wei Liu
On Tue, Jun 09, 2015 at 10:29:56AM +0100, Wei Liu wrote:
[...]Quoted 13 lines
Quoted 6 lines
Quoted 1 line
+ con.next_tid <-
initial_next_tidI couldn’t spot the part in the C version where the next transaction id is reset — is this a (minor) difference between the two implementations, or have I misread the code?
If you could clarify that for me, and assuming this all compiled ok, then feel free to add
Yes, it compiles OK.
I think I will just delete that line. I couldn't recollect why I added that. Maybe it's copy-n-paste error.
Can I still have your ack if I drop that line?
Yes
Quoted 10 lines
Quoted 1 line
And a new hunk will be added in the next version to deal with logging.ml.
tools/ocaml/xenstored/logging.ml +0
-0
tools/ocaml/xenstored/logging.ml let string_of_access_type = function · line 248
Quoted 7 lines
tools/ocaml/xenstored/logging.ml +1
-0@@ -242,6 +242,7 @@ let string_of_access_type = function | Xenbus.Xb.Op.Rm -> "rm " | Xenbus.Xb.Op.Setperms -> "setperms " | Xenbus.Xb.Op.Restrict -> "restrict " + | Xenbus.Xb.Op.Reset_watches -> "reset watches" | Xenbus.Xb.Op.Set_target -> "settarget" | Xenbus.Xb.Op.Error -> "error “
All still fine:
Cheers,
Dave
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Acked-by David Scott <[email protected]>Cheers,
Dave
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel