toolstack-based approach to pvhvm guest kexec
v4 cover toolstack-based approach to pvhvm guest kexec
Changes from RFCv3:
This is the first non-RFC series as no major concerns were expressed. I'm trying to address Jan's comments. Changes are:
- Move from XEN_DOMCTL_set_recipient to XEN_DOMCTL_devour (I don't really like the name but nothing more appropriate came to my mind) which incorporates former XEN_DOMCTL_set_recipient and XEN_DOMCTL_destroydomain to prevent original domain from changing its allocations during transfer procedure.
- Check in free_domheap_pages() that assign_pages() succeeded.
- Change printk() in free_domheap_pages().
- DOMDYING_locked state was introduced to support XEN_DOMCTL_devour.
- xc_domain_soft_reset() got simplified a bit. Now we just wait for the original domain to die or loose all its pages.
- rebased on top of current master branch.
Changes from RFC/WIPv2:
Here is a slightly different approach to memory reassignment. Instead of introducing new (and very doubtful) XENMEM_transfer operation introduce simple XEN_DOMCTL_set_recipient operation and do everything in free_domheap_pages() handler utilizing normal domain destroy path. This is better because:
- The approach is general-enough
- All memory pages are usually being freed when the domain is destroyed
- No special grants handling required
- Better supportability
With regards to PV:
Though XEN_DOMCTL_set_recipient works for both PV and HVM this patchset does not bring PV kexec/kdump support. xc_domain_soft_reset() is limited to work with HVM domains only. The main reason for that is: it is (in theory) possible to save p2m and rebuild them with the new domain but that would only allow us to resume execution from where we stopped. If we want to execute new kernel we need to build the same kernel/initrd/bootstrap_pagetables/... structure we build to boot PV domain initially. That however would destroy the original domain's memory thus making kdump impossible. To make everything work additional support from kexec userspace/linux kernel is required and I'm not sure it makes sense to implement all this stuff in the light of PVH.
Original description:
When a PVHVM linux guest performs kexec there are lots of things which require taking care of:
- shared info, vcpu_info
- grants
- event channels
- ...
Instead of taking care of all these things we can rebuild the domain performing kexec from scratch doing so-called soft-reboot.
The idea was suggested by David Vrabel, Jan Beulich, and Konrad Rzeszutek Wilk.
P.S. The patch series can be tested with PVHVM Linux guest with the following modifications:
arch/x86/xen/enlighten.c +20 -0
@@ -33,6 +33,10 @@#include <linux/memblock.h> #include <linux/edd.h> +#ifdef CONFIG_KEXEC +#include <linux/kexec.h> +#endif +#include <xen/xen.h> #include <xen/events.h> #include <xen/interface/xen.h>
@@ -1810,6 +1814,22 @@ static struct notifier_block xen_hvm_cpu_notifier = { .notifier_call = xen_hvm_cpu_notify, }; +#ifdef CONFIG_KEXEC +static void xen_pvhvm_kexec_shutdown (void ) +{ +native_machine_shutdown (); +if (kexec_in_progress) { +xen_reboot (SHUTDOWN_soft_reset); + } +} + +static void xen_pvhvm_crash_shutdown (struct pt_regs *regs) +{ +native_machine_crash_shutdown (regs); +xen_reboot (SHUTDOWN_soft_reset); +} +#endif +static void __init xen_hvm_guest_init (void ) {
init_hvm_pv_info();
@@ -1826,6 +1846,10 @@ static void __init xen_hvm_guest_init(void)
x86_init.irqs.intr_init = xen_init_IRQ; xen_hvm_init_time_ops();
xen_hvm_init_mmu_ops();
+#ifdef CONFIG_KEXEC
+ machine_ops.shutdown = xen_pvhvm_kexec_shutdown;
+ machine_ops.crash_shutdown = xen_pvhvm_crash_shutdown;
+#endif
}
static bool xen_nopv = false;
include/xen/interface/sched.h +1 -0
@@ -107,5 +107,6 @@ struct sched_watchdog {#define SHUTDOWN_suspend 2/* Clean up, save suspend info, kill. */ #define SHUTDOWN_crash 3/* Tell controller we've crashed. */ #define SHUTDOWN_watchdog 4/* Restart because watchdog time expired. */ +#define SHUTDOWN_soft_reset 5/* Soft-reset for kexec. */ #endif /* __XEN_PUBLIC_SCHED_H__ */
Vitaly Kuznetsov (9):
xen: introduce DOMDYING_locked state
xen: introduce SHUTDOWN_soft_reset shutdown reason
libxl: support SHUTDOWN_soft_reset shutdown reason
xen: introduce XEN_DOMCTL_devour
libxc: support XEN_DOMCTL_devour
libxl: add libxl__domain_soft_reset_destroy_old()
libxc: introduce soft reset for HVM domains
libxl: soft reset support
xsm: add XEN_DOMCTL_devour support
tools/libxc/Makefile | 1 + tools/libxc/include/xenctrl.h | 14 ++ tools/libxc/include/xenguest.h | 20 +++ tools/libxc/xc_domain.c | 13 ++ tools/libxc/xc_domain_soft_reset.c | 282 ++++++++++++++++++++++++++++++++++++ tools/libxl/libxl.c | 32 +++- tools/libxl/libxl.h | 6 + tools/libxl/libxl_create.c | 103 +++++++++++-- tools/libxl/libxl_internal.h | 8 + tools/libxl/libxl_types.idl | 1 + tools/libxl/xl_cmdimpl.c | 24 ++- tools/python/xen/lowlevel/xl/xl.c | 1 + xen/common/domain.c | 4 + xen/common/domctl.c | 39 +++++ xen/common/page_alloc.c | 28 +++- xen/common/shutdown.c | 7 + xen/include/public/domctl.h | 15 ++ xen/include/public/sched.h | 3 +- xen/include/xen/sched.h | 5 +- xen/include/xsm/dummy.h | 6 + xen/include/xsm/xsm.h | 6 + xen/xsm/dummy.c | 1 + xen/xsm/flask/hooks.c | 17 +++ xen/xsm/flask/policy/access_vectors | 10 ++ 24 files changed, 623 insertions(+), 23 deletions(-) create mode 100644 tools/libxc/xc_domain_soft_reset.c
Signature · 1 line
1.9.3
PATCH v4 1/9 xen: introduce DOMDYING_locked state
New dying state is requred to indicate that a particular domain is dying but cleanup procedure wasn't started. This state can be set from outside of domain_kill().
--- xen/common/domain.c | 1 + xen/include/xen/sched.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
xen/common/domain.c +1 -0
@@ -603,6 +603,7 @@ int domain_kill(struct domain *d)switch ( d->is_dying ) {case DOMDYING_alive: +case DOMDYING_locked:domain_pause (d); d->is_dying = DOMDYING_dying;spin_barrier (&d->domain_lock);
xen/include/xen/sched.h +2 -1
@@ -369,7 +369,8 @@ struct domain/* Is this guest being debugged by dom0? */ bool_t debugger_attached;/* Is this guest dying (i.e., a zombie)? */ -enum { DOMDYING_alive, DOMDYING_dying, DOMDYING_dead } is_dying; +enum { DOMDYING_alive, DOMDYING_locked, DOMDYING_dying, DOMDYING_dead } + is_dying;/* Domain is paused by controller software? */ int controller_pause_count;/* Domain's VCPUs are pinned 1:1 to physical CPUs? */
Signature · 1 line
1.9.3
PATCH v4 2/9 xen: introduce SHUTDOWN_soft_reset shutdown reason
In reply to Vitaly Kuznetsov--- xen/common/shutdown.c | 7 +++++++ xen/include/public/sched.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-)
xen/common/shutdown.c +7 -0
@@ -71,6 +71,13 @@ void hwdom_shutdown(u8 reason)break ;/* not reached */ } +case SHUTDOWN_soft_reset: + { +printk ("Domain 0 did soft reset but it is unsupported, rebooting.\n" ); +machine_restart (0 ); +break ;/* not reached */ + } +default : {printk ("Domain 0 shutdown (unknown reason %u): " , reason);
xen/include/public/sched.h +2 -1
@@ -159,7 +159,8 @@ DEFINE_XEN_GUEST_HANDLE(sched_watchdog_t);#define SHUTDOWN_suspend 2/* Clean up, save suspend info, kill. */ #define SHUTDOWN_crash 3/* Tell controller we've crashed. */ #define SHUTDOWN_watchdog 4/* Restart because watchdog time expired. */ -#define SHUTDOWN_MAX 4/* Maximum valid shutdown reason. */ +#define SHUTDOWN_soft_reset 5/* Soft reset, rebuild keeping memory content */ +#define SHUTDOWN_MAX 5/* Maximum valid shutdown reason. */ /* ` } */ #endif /* __XEN_PUBLIC_SCHED_H__ */
Signature · 1 line
1.9.3
PATCH v4 3/9 libxl: support SHUTDOWN_soft_reset shutdown reason
In reply to Vitaly KuznetsovUse letter 't' to indicate a domain in such state.
--- tools/libxl/libxl_types.idl | 1 + tools/libxl/xl_cmdimpl.c | 2 +- tools/python/xen/lowlevel/xl/xl.c | 1 + 3 files changed, 3 insertions(+), 1 deletion(-)
tools/libxl/libxl_types.idl +1 -0
@@ -175,6 +175,7 @@ libxl_shutdown_reason = Enumeration("shutdown_reason", [ (2, "suspend"), (3, "crash"), (4, "watchdog"), + (5, "soft_reset"), ], init_val = "LIBXL_SHUTDOWN_REASON_UNKNOWN") libxl_vga_interface_type = Enumeration("vga_interface_type", [
tools/libxl/xl_cmdimpl.c +1 -1
@@ -3497,7 +3497,7 @@ static void list_domains(int verbose, int context, int claim, int numa, const libxl_dominfo *info, int nb_domain) { int i; -static const char shutdown_reason_letters[]="-rscw" ; +static const char shutdown_reason_letters[]="-rscwt" ;libxl_bitmap nodemap;libxl_physinfo physinfo;
tools/python/xen/lowlevel/xl/xl.c +1 -0
@@ -784,6 +784,7 @@ PyMODINIT_FUNC initxl(void)_INT_CONST_LIBXL (m,SHUTDOWN_REASON_SUSPEND );_INT_CONST_LIBXL (m,SHUTDOWN_REASON_CRASH );_INT_CONST_LIBXL (m,SHUTDOWN_REASON_WATCHDOG ); +_INT_CONST_LIBXL (m,SHUTDOWN_REASON_SOFT_RESET );genwrap__init (m); }
Signature · 1 line
1.9.3
PATCH v4 4/9 xen: introduce XEN_DOMCTL_devour
In reply to Vitaly KuznetsovNew operation sets the 'recipient' domain which will recieve all memory pages from a particular domain and kills the original domain.
--- xen/common/domain.c | 3 +++ xen/common/domctl.c | 33 +++++++++++++++++++++++++++++++++ xen/common/page_alloc.c | 28 ++++++++++++++++++++++++---- xen/include/public/domctl.h | 15 +++++++++++++++ xen/include/xen/sched.h | 2 ++ 5 files changed, 77 insertions(+), 4 deletions(-)
xen/common/domain.c +3 -0
@@ -825,6 +825,9 @@ static void complete_domain_destroy(struct rcu_head *head)if ( d->target !=NULL )put_domain (d->target); +if ( d->recipient !=NULL ) +put_domain (d->recipient); +evtchn_destroy_final (d);radix_tree_destroy (&d->pirq_tree, free_pirq_struct);
xen/common/domctl.c +33 -0
@@ -1177,6 +1177,39 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) }break ; +case XEN_DOMCTL_devour: + { +struct domain *recipient_dom; + +if ( !d->recipient ) + { + recipient_dom =get_domain_by_id (op->u.devour.recipient); +if ( recipient_dom ==NULL ) + { + ret = -ESRCH ; +break ; + } + +if ( recipient_dom->tot_pages !=0 ) + { +put_domain (recipient_dom); + ret = -EINVAL ; +break ; + } +/* +* Make sure no allocation/remapping is ongoing and set is_dying +* flag to prevent such actions in future. +*/ +spin_lock (&d->page_alloc_lock); + d->is_dying = DOMDYING_locked; + d->recipient = recipient_dom; +smp_wmb ();/* make sure recipient was set before domain_kill() */ +spin_unlock (&d->page_alloc_lock); + } + ret =domain_kill (d); + } +break ; +default : ret =arch_do_domctl (op, d, u_domctl);break ;
xen/common/page_alloc.c +24 -4
@@ -1707,6 +1707,7 @@ void free_domheap_pages(struct page_info *pg, unsigned int order) {struct domain *d =page_get_owner (pg);unsigned int i; +unsigned long mfn, gmfn;bool_t drop_dom_ref;ASSERT (!in_irq ());
@@ -1764,13 +1765,32 @@ void free_domheap_pages(struct page_info *pg, unsigned int order) scrub =1 ; } -if (unlikely (scrub) ) -for ( i =0 ; i < (1 << order); i++ ) -scrub_one_page (&pg[i]); +if ( !d || !d->recipient || d->recipient->is_dying ) + { +if (unlikely (scrub) ) +for ( i =0 ; i < (1 << order); i++ ) +scrub_one_page (&pg[i]); -free_heap_pages (pg, order); +free_heap_pages (pg, order); + } +else + { + mfn =page_to_mfn (pg); + gmfn =mfn_to_gmfn (d, mfn); + +page_set_owner (pg,NULL ); +if (assign_pages (d->recipient, pg, order,0 ) ) +/* assign_pages reports the error by itself */ + goto out; + +if (guest_physmap_add_page (d->recipient, gmfn, mfn, order) ) +printk (XENLOG_G_INFO +"Failed to add MFN %lx (GFN %lx) to Dom%d's physmap\n" , + mfn, gmfn, d->recipient->domain_id); + } } +out:if ( drop_dom_ref )put_domain (d); }
xen/include/public/domctl.h +15 -0
@@ -995,6 +995,19 @@ struct xen_domctl_psr_cmt_op {typedef struct xen_domctl_psr_cmt_op xen_domctl_psr_cmt_op_t ;DEFINE_XEN_GUEST_HANDLE (xen_domctl_psr_cmt_op_t); +/* +* XEN_DOMCTL_devour - kills the domain reassigning all of its domheap pages +* to the 'recipient' domain. Pages from xen heap belonging to the domain +* are not copied. Reassigned pages are mapped to the same GMFNs in the +* recipient domain as they were mapped in the original. The recipient domain +* is supposed to not have any domheap pages to avoid MFN-GMFN collisions. +*/ +struct xen_domctl_devour { +domid_t recipient; +}; +typedef struct xen_domctl_devour xen_domctl_devour_t ; +DEFINE_XEN_GUEST_HANDLE (xen_domctl_devour_t); +struct xen_domctl {uint32_t cmd;#define XEN_DOMCTL_createdomain 1
@@ -1070,6 +1083,7 @@ struct xen_domctl {#define XEN_DOMCTL_setvnumainfo 74#define XEN_DOMCTL_psr_cmt_op 75#define XEN_DOMCTL_arm_configure_domain 76 +#define XEN_DOMCTL_devour 77#define XEN_DOMCTL_gdbsx_guestmemio 1000#define XEN_DOMCTL_gdbsx_pausevcpu 1001#define XEN_DOMCTL_gdbsx_unpausevcpu 1002
@@ -1135,6 +1149,7 @@ struct xen_domctl {struct xen_domctl_gdbsx_domstatus gdbsx_domstatus;struct xen_domctl_vnuma vnuma;struct xen_domctl_psr_cmt_op psr_cmt_op; +struct xen_domctl_devour devour;uint8_t pad[128 ]; } u; };
xen/include/xen/sched.h +2 -0
@@ -366,6 +366,8 @@ struct domainbool_t is_privileged;/* Which guest this guest has privileges on */ struct domain *target; +/* Which guest receives freed memory pages */ +struct domain *recipient;/* Is this guest being debugged by dom0? */ bool_t debugger_attached;/* Is this guest dying (i.e., a zombie)? */
Signature · 1 line
1.9.3
Re: [PATCH v4 4/9] xen: introduce XEN_DOMCTL_devour
Hi Vitaly,
Quoted 1 line · Vitaly Kuznetsov
New operation sets the 'recipient' domain which will recieve all
s/recieve/receive/
Quoted 5 lines
memory pages from a particular domain and kills the original domain.
Signed-off-by Vitaly Kuznetsov <[email protected]>---
(quoted diff) +0
-0@@ -1764,13 +1765,32 @@ void free_domheap_pages(struct page_info *pg, unsigned int order)
[..]
xen/common/page_alloc.c void free_domheap_pages(struct page_info *pg, unsigned int order) · line 1786
Quoted 11 lines
xen/common/page_alloc.c +11
-0+else + { + mfn =page_to_mfn (pg); + gmfn =mfn_to_gmfn (d, mfn); + +page_set_owner (pg,NULL ); +if (assign_pages (d->recipient, pg, order,0 ) ) +/* assign_pages reports the error by itself */ + goto out; + +if (guest_physmap_add_page (d->recipient, gmfn, mfn, order) )
On ARM, mfn_to_gmfn will always return the mfn. This would result to add a 1:1 mapping in the recipient domain.
But ... only DOM0 has its memory mapped 1:1. So this code may blow up the P2M of the recipient domain.
I'm not an x86 expert, but this may also happen when the recipient domain is using translated page mode (i.e HVM/PVHM).
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v4 4/9] xen: introduce XEN_DOMCTL_devour
Quoted 32 lines · Julien Grall
Hi Vitaly,
Quoted 1 line · Vitaly Kuznetsov
New operation sets the 'recipient' domain which will recieve all
s/recieve/receive/
Quoted 6 lines
memory pages from a particular domain and kills the original domain.
Signed-off-by Vitaly Kuznetsov <[email protected]>---
(quoted diff) +0
-0@@ -1764,13 +1765,32 @@ void free_domheap_pages(struct page_info *pg, unsigned int order)[..]
Quoted 11 lines
xen/common/page_alloc.c +11
-0+else + { + mfn =page_to_mfn (pg); + gmfn =mfn_to_gmfn (d, mfn); + +page_set_owner (pg,NULL ); +if (assign_pages (d->recipient, pg, order,0 ) ) +/* assign_pages reports the error by itself */ + goto out; + + if ( guest_physmap_add_page(d->recipient, gmfn, mfn,Quoted 1 line
order) )
On ARM,
mfn_to_gmfnwill always return the mfn. This would result to add a 1:1 mapping in the recipient domain.
Quoted 5 lines
But ... only DOM0 has its memory mapped 1:1. So this code may blow up the P2M of the recipient domain.
I'm not an x86 expert, but this may also happen when the recipient domain is using translated page mode (i.e HVM/PVHM).
mfn_to_gmfn() does the correct thing on x86 as it does a m2p lookup.
David
Re: [PATCH v4 4/9] xen: introduce XEN_DOMCTL_devour
Quoted 33 lines · David Vrabel
Quoted 32 lines · Julien Grall
Hi Vitaly,
Quoted 1 line · Vitaly Kuznetsov
New operation sets the 'recipient' domain which will recieve all
s/recieve/receive/
Quoted 6 lines
memory pages from a particular domain and kills the original domain.
Signed-off-by Vitaly Kuznetsov <[email protected]>---
(quoted diff) +0
-0@@ -1764,13 +1765,32 @@ void free_domheap_pages(struct page_info *pg, unsigned int order)[..]
Quoted 11 lines
xen/common/page_alloc.c +11
-0+else + { + mfn =page_to_mfn (pg); + gmfn =mfn_to_gmfn (d, mfn); + +page_set_owner (pg,NULL ); +if (assign_pages (d->recipient, pg, order,0 ) ) +/* assign_pages reports the error by itself */ + goto out; + + if ( guest_physmap_add_page(d->recipient, gmfn, mfn,Quoted 1 line
order) )
On ARM,
mfn_to_gmfnwill always return the mfn. This would result to add a 1:1 mapping in the recipient domain.
Quoted 7 lines
Quoted 5 lines
But ... only DOM0 has its memory mapped 1:1. So this code may blow up the P2M of the recipient domain.
I'm not an x86 expert, but this may also happen when the recipient domain is using translated page mode (i.e HVM/PVHM).
mfn_to_gmfn()does the correct thing on x86 as it does a m2p lookup.
Is it because machine_to_phys_mapping caches the translation for dying domain?
Signature · 1 line
Julien Grall
Re: [PATCH v4 4/9] xen: introduce XEN_DOMCTL_devour
In reply to Julien GrallQuoted 30 lines · Julien Grall
Hi Vitaly,
Quoted 1 line · Vitaly Kuznetsov
New operation sets the 'recipient' domain which will recieve all
s/recieve/receive/
Quoted 5 lines
memory pages from a particular domain and kills the original domain.
Signed-off-by Vitaly Kuznetsov <[email protected]>---
(quoted diff) +0
-0@@ -1764,13 +1765,32 @@ void free_domheap_pages(struct page_info *pg, unsigned int order)[..]
xen/common/page_alloc.c void free_domheap_pages(struct page_info *pg, unsigned int order) · line 1786
Quoted 11 lines
xen/common/page_alloc.c +11
-0+else + { + mfn =page_to_mfn (pg); + gmfn =mfn_to_gmfn (d, mfn); + +page_set_owner (pg,NULL ); +if (assign_pages (d->recipient, pg, order,0 ) ) +/* assign_pages reports the error by itself */ + goto out; + +if (guest_physmap_add_page (d->recipient, gmfn, mfn, order) )On ARM,
mfn_to_gmfnwill always return the mfn. This would result to add a 1:1 mapping in the recipient domain.
Quoted 2 lines
But ... only DOM0 has its memory mapped 1:1. So this code may blow up the P2M of the recipient domain.
I know almost nothing about ARM so please bear with me. So, for a guest domain the mapping is not 1:1 (so guest sees different addresses) but mfn_to_gmfn() doesn't returs these addresses? I was under an impression it is not x86-specific and I can see its usage in e.g. getdomaininfo(), memory_exchange(),.. How can one figure out the mapping then? Anyway, what I want to do here is: when this page is freed I want to reassign it to our newly-created guest at the exact same address it was mapped in the original domain.
Quoted 3 lines
I'm not an x86 expert, but this may also happen when the recipient domain is using translated page mode (i.e HVM/PVHM).
PVHVM is the main target here (as kexec is unsupported for PV) and it kinda works. mfn_to_gmfn() returns gmfn != mfn.
BTW, what's the current state of affairs with kexec and ARM guest? I suppose we should have similar problems: vcpu_info, event channels, ..
Quoted 2 lines
Regards,
Signature · 1 line
Vitaly
Re: [PATCH v4 4/9] xen: introduce XEN_DOMCTL_devour
Quoted 32 lines · Vitaly Kuznetsov
Quoted 30 lines · Julien Grall
Hi Vitaly,
Quoted 1 line · Vitaly Kuznetsov
New operation sets the 'recipient' domain which will recieve all
s/recieve/receive/
Quoted 5 lines
memory pages from a particular domain and kills the original domain.
Signed-off-by Vitaly Kuznetsov <[email protected]>---
(quoted diff) +0
-0@@ -1764,13 +1765,32 @@ void free_domheap_pages(struct page_info *pg, unsigned int order)[..]
xen/common/page_alloc.c void free_domheap_pages(struct page_info *pg, unsigned int order) · line 1786
Quoted 11 lines
xen/common/page_alloc.c +11
-0+else + { + mfn =page_to_mfn (pg); + gmfn =mfn_to_gmfn (d, mfn); + +page_set_owner (pg,NULL ); +if (assign_pages (d->recipient, pg, order,0 ) ) +/* assign_pages reports the error by itself */ + goto out; + +if (guest_physmap_add_page (d->recipient, gmfn, mfn, order) )On ARM,
mfn_to_gmfnwill always return the mfn. This would result to add a 1:1 mapping in the recipient domain.
Quoted 6 lines
Quoted 2 lines
But ... only DOM0 has its memory mapped 1:1. So this code may blow up the P2M of the recipient domain.
I know almost nothing about ARM so please bear with me. So, for a guest domain the mapping is not 1:1 (so guest sees different addresses) but
mfn_to_gmfn()doesn't returs these addresses?
Yes. I guess it's because this macro is not really used (see why below). Ian, Stefano: any idea why mfn_to_gfmn is not correctly implemented on ARM?
Quoted 3 lines
I was under an impression
it is not x86-specific and I can see its usage in e.g.getdomaininfo(),memory_exchange(),..
I can find two places in the common code:
- getdomaininfo: The return is obviously buggy. Though, it doesn't seem
to be used in the toolstack side for ARM
- memory_exchange: AFAIK this is not supported right now.
Quoted 1 line
How can one figure out the mapping then?
AFAIK, there is no way on ARM to get a GMFN from an MFN in Xen.
Maybe we should implement it correctly mfn_to_gmfn on ARM? Ian, Stefano, any though?
Quoted 5 lines
Anyway, what I want to do here is: when this page is freed I want to reassign it to our newly-created guest at the exact same address it was mapped in the original domain.
BTW, what's the current state of affairs with kexec and ARM guest?
AFAIK, nobody has worked on it for Xen ARM. I don't even know the status for Kexec on ARM.
Quoted 3 lines
I
suppose we should have similar problems:vcpu_info, event channels, ..
ARM guest is very similar to PVH guest. All the problems you will fixed now means less work when we will add support for ARM ;).
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v4 4/9] xen: introduce XEN_DOMCTL_devour
In reply to Vitaly Kuznetsovxen/include/xen/sched.h struct domain · line 369
Quoted 9 lines · Vitaly Kuznetsov
xen/include/xen/sched.h +1
-0@@ -366,6 +366,8 @@ struct domainbool_t is_privileged;/* Which guest this guest has privileges on */ struct domain *target; +/* Which guest receives freed memory pages */
It took me a while to understand that the recipient domain is a newly created domain, right? It might be worth to add a word here (and maybe in assign_pages).
With that in mind, the code in assign_pages makes more sense.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v4 4/9] xen: introduce XEN_DOMCTL_devour
Quoted 14 lines · Julien Grall
xen/include/xen/sched.h struct domain · line 369
Quoted 9 lines · Vitaly Kuznetsov
xen/include/xen/sched.h +1
-0@@ -366,6 +366,8 @@ struct domainbool_t is_privileged;/* Which guest this guest has privileges on */ struct domain *target; +/* Which guest receives freed memory pages */ It took me a while to understand that the recipient domain is a newly created domain, right? It might be worth to add a word here (and maybe in
assign_pages).
Sure, will add. In case you think renaming 'recipient' to something else makes sense I'm all in.
Quoted 4 lines
With that in mind, the code in
assign_pagesmakes more sense.Regards,
Signature · 1 line
Vitaly
PATCH v4 5/9 libxc: support XEN_DOMCTL_devour
In reply to Vitaly KuznetsovIntroduce new xc_domain_devour() function to support XEN_DOMCTL_devour.
--- tools/libxc/include/xenctrl.h | 14 ++++++++++++++ tools/libxc/xc_domain.c | 13 +++++++++++++ 2 files changed, 27 insertions(+)
tools/libxc/include/xenctrl.h +14 -0
@@ -558,6 +558,20 @@ int xc_domain_unpause(xc_interface *xch,int xc_domain_destroy (xc_interface *xch,uint32_t domid); +/** +* This function sets a 'recipient' domain for a domain (when the source domain +* releases memory it is being reassigned to the recipient domain instead of +* being freed) and kills the original domain. The destination domain is supposed +* to have enough max_mem and no pages assigned. +* +* @parm xch a handle to an open hypervisor interface +* @parm domid the source domain id +* @parm recipient the destrination domain id +* @return 0 on success, -1 on failure +*/ +int xc_domain_devour (xc_interface *xch, +uint32_t domid,uint32_t recipient); +/** * This function resumes a suspended domain. The domain should have
tools/libxc/xc_domain.c +13 -0
@@ -122,6 +122,19 @@ int xc_domain_destroy(xc_interface *xch,return ret; } +int xc_domain_devour (xc_interface *xch,uint32_t domid,uint32_t recipient) +{ +int ret; +DECLARE_DOMCTL ; + domctl.cmd = XEN_DOMCTL_devour; + domctl.domain = (domid_t )domid; + domctl.u.devour.recipient = (domid_t )recipient; +do { + ret =do_domctl (xch, &domctl); + }while ( ret && (errno ==EAGAIN ) ); +return ret; +} +int xc_domain_shutdown (xc_interface *xch,uint32_t domid,int reason)
Signature · 1 line
1.9.3
PATCH v4 6/9 libxl: add libxl__domain_soft_reset_destroy_old()
In reply to Vitaly KuznetsovNew libxl__domain_soft_reset_destroy_old() is an internal-only version of libxl_domain_destroy() which follows the same domain destroy path with the only difference: xc_domain_destroy() is being avoided so the domain is not actually being destroyed.
Add soft_reset flag to libxl__domain_destroy_state structure to support the change.
The original libxl_domain_destroy() function could be easily modified to support new flag but I'm trying to avoid that as it is part of public API.
--- tools/libxl/libxl.c | 32 +++++++++++++++++++++++++++----- tools/libxl/libxl_internal.h | 4 ++++ 2 files changed, 31 insertions(+), 5 deletions(-)
tools/libxl/libxl.c +27 -5
@@ -1437,6 +1437,23 @@ int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid,return AO_INPROGRESS ; } +int libxl__domain_soft_reset_destroy_old (libxl_ctx *ctx,uint32_t domid, +const libxl_asyncop_how *ao_how) +{ +AO_CREATE (ctx, domid, ao_how); +libxl__domain_destroy_state *dds; + +GCNEW (dds); + dds->ao = ao; + dds->domid = domid; + dds->callback = domain_destroy_cb; + dds->soft_reset =1 ; +libxl__domain_destroy (egc, dds); + +return AO_INPROGRESS ; +} + +static void domain_destroy_cb (libxl__egc *egc,libxl__domain_destroy_state *dds,int rc) {
@@ -1612,6 +1629,7 @@ static void devices_destroy_cb(libxl__egc *egc, {STATE_AO_GC (drs->ao);libxl__destroy_domid_state *dis =CONTAINER_OF (drs, *dis, drs); +libxl__domain_destroy_state *dds =CONTAINER_OF (dis, *dds, domain);libxl_ctx *ctx =CTX ;uint32_t domid = dis->domid;char *dom_path;
@@ -1650,11 +1668,15 @@ static void devices_destroy_cb(libxl__egc *egc, }libxl__userdata_destroyall (gc, domid); - rc =xc_domain_destroy (ctx->xch, domid); -if (rc <0 ) { -LIBXL__LOG_ERRNOVAL (ctx,LIBXL__LOG_ERROR , rc,"xc_domain_destroy failed for %d" , domid); - rc =ERROR_FAIL ; - goto out; +if (!dds->soft_reset) + { + rc =xc_domain_destroy (ctx->xch, domid); +if (rc <0 ) { +LIBXL__LOG_ERRNOVAL (ctx,LIBXL__LOG_ERROR , rc, +"xc_domain_destroy failed for %d" , domid); + rc =ERROR_FAIL ; + goto out; + } } rc =0 ;
tools/libxl/libxl_internal.h +4 -0
@@ -2969,6 +2969,7 @@ struct libxl__domain_destroy_state {int stubdom_finished;libxl__destroy_domid_state domain;int domain_finished; +int soft_reset; };/*
@@ -3132,6 +3133,9 @@ _hidden void libxl__domain_save_device_model(libxl__egc *egc, _hidden const char *libxl__device_model_savefile(libxl__gc *gc, uint32_t domid); +_hidden int libxl__domain_soft_reset_destroy_old(libxl_ctx *ctx, uint32_t domid, +const libxl_asyncop_how *ao_how); +/* * Convenience macros.
Signature · 1 line
1.9.3
Re: [PATCH v4 6/9] libxl: add libxl__domain_soft_reset_destroy_old()
Quoted 23 lines · Vitaly Kuznetsov
New
libxl__domain_soft_reset_destroy_old()is an internal-only version oflibxl_domain_destroy()which follows the same domain destroy path with the only difference:xc_domain_destroy()is being avoided so the domain is not actually being destroyed.Add
soft_resetflag tolibxl__domain_destroy_statestructure to support the change.The original
libxl_domain_destroy()function could be easily modified to support new flag but I'm trying to avoid that as it is part of public API.Signed-off-by Vitaly Kuznetsov <[email protected]>--- tools/libxl/libxl.c | 32 +++++++++++++++++++++++++++----- tools/libxl/libxl_internal.h | 4 ++++ 2 files changed, 31 insertions(+), 5 deletions(-)tools/libxl/libxl.c +0
-0
tools/libxl/libxl.c int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid, · line 1442
Quoted 6 lines
tools/libxl/libxl.c +3
-0@@ -1437,6 +1437,23 @@ int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid,return AO_INPROGRESS ; } +int libxl__domain_soft_reset_destroy_old (libxl_ctx *ctx,uint32_t domid, +const libxl_asyncop_how *ao_how) +{
Internal function takes gc, not ctx.
tools/libxl/libxl.c int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid, · line 1443
Quoted 1 line
tools/libxl/libxl.c +1
-0+AO_CREATE (ctx, domid, ao_how);
If you want to use libxl context, use CTX macro.
Quoted 25 lines
tools/libxl/libxl.c +14
-0+libxl__domain_destroy_state *dds; + +GCNEW (dds); + dds->ao = ao; + dds->domid = domid; + dds->callback = domain_destroy_cb; + dds->soft_reset =1 ; +libxl__domain_destroy (egc, dds); + +return AO_INPROGRESS ; +} + +static void domain_destroy_cb (libxl__egc *egc,libxl__domain_destroy_state *dds,int rc) {@@ -1612,6 +1629,7 @@ static void devices_destroy_cb(libxl__egc *egc, {STATE_AO_GC (drs->ao);libxl__destroy_domid_state *dis =CONTAINER_OF (drs, *dis, drs); +libxl__domain_destroy_state *dds =CONTAINER_OF (dis, *dds, domain);libxl_ctx *ctx =CTX ;uint32_t domid = dis->domid;char *dom_path;
tools/libxl/libxl.c static void devices_destroy_cb(libxl__egc *egc, · line 1672
Quoted 10 lines
tools/libxl/libxl.c +2
-5@@ -1650,11 +1668,15 @@ static void devices_destroy_cb(libxl__egc *egc, }libxl__userdata_destroyall (gc, domid); - rc =xc_domain_destroy (ctx->xch, domid); -if (rc <0 ) { -LIBXL__LOG_ERRNOVAL (ctx,LIBXL__LOG_ERROR , rc,"xc_domain_destroy failed for %d" , domid); - rc =ERROR_FAIL ; - goto out; +if (!dds->soft_reset) + {
Coding style.
Wei.
PATCH v4 7/9 libxc: introduce soft reset for HVM domains
In reply to Vitaly KuznetsovAdd new xc_domain_soft_reset() function which performs so-called 'soft reset' for an HVM domain. It is being performed in the following way:
- Save HVM context and all HVM params;
- Devour original domain with XEN_DOMCTL_devour;
- Wait till original domain dies or has no pages left;
- Restore HVM context, HVM params, seed grant table.
After that the domain resumes execution from where SHUTDOWN_soft_reset was called.
--- tools/libxc/Makefile | 1 + tools/libxc/include/xenguest.h | 20 +++ tools/libxc/xc_domain_soft_reset.c | 282 +++++++++++++++++++++++++++++++++++++ 3 files changed, 303 insertions(+) create mode 100644 tools/libxc/xc_domain_soft_reset.c
tools/libxc/Makefile +1 -0
@@ -52,6 +52,7 @@ GUEST_SRCS-y += xc_offline_page.c xc_compression.c else GUEST_SRCS-y += xc_nomigrate.c endif +GUEST_SRCS-y += xc_domain_soft_reset.c vpath %.c ../../xen/common/libelf CFLAGS += -I../../xen/common/libelf
tools/libxc/include/xenguest.h +20 -0
@@ -131,6 +131,26 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,* of the new domain is automatically appended to the filename, * separated by a ".". */ + +/** +* This function does soft reset for a domain. During soft reset all +* source domain's memory is being reassigned to the destination domain, +* HVM context and HVM params are being copied. +* +* @parm xch a handle to an open hypervisor interface +* @parm source_dom the id of the source domain +* @parm dest_dom the id of the destination domain +* @parm console_domid the id of the domain handling console +* @parm console_mfn returned with the mfn of the console page +* @parm store_domid the id of the domain handling store +* @parm store_mfn returned with the mfn of the store page +* @return 0 on success, -1 on failure +*/ +int xc_domain_soft_reset (xc_interface *xch,uint32_t source_dom, +uint32_t dest_dom,domid_t console_domid, +unsigned long *console_mfn,domid_t store_domid, +unsigned long *store_mfn); +#define XC_DEVICE_MODEL_RESTORE_FILE "/var/lib/xen/qemu-resume"/**
tools/libxc/xc_domain_soft_reset.c new file +282 -0
282 lines not on this page · raw message
Signature · 1 line
1.9.3
PATCH v4 8/9 libxl: soft reset support
In reply to Vitaly KuznetsovPerform soft reset when a domain did SHUTDOWN_soft_reset. Migrate the content with xc_domain_soft_reset(), reload dm and toolstack.
--- tools/libxl/libxl.h | 6 +++ tools/libxl/libxl_create.c | 103 +++++++++++++++++++++++++++++++++++++++---- tools/libxl/libxl_internal.h | 4 ++ tools/libxl/xl_cmdimpl.c | 22 ++++++++- 4 files changed, 124 insertions(+), 11 deletions(-)
tools/libxl/libxl.h +6 -0
@@ -919,6 +919,12 @@ int static inline libxl_domain_create_restore_0x040200(#endif +int libxl_domain_soft_reset(libxl_ctx *ctx, libxl_domain_config *d_config, + uint32_t *domid, uint32_t domid_old, + const libxl_asyncop_how *ao_how, + const libxl_asyncprogress_how *aop_console_how) + LIBXL_EXTERNAL_CALLERS_ONLY; +/* A progress report will be made via ao_console_how, of type * domain_create_console_available, when the domain's primary * console is available and can be connected to.
tools/libxl/libxl_create.c +94 -9
183 lines not on this page · raw message
tools/libxl/libxl_internal.h +4 -0
@@ -3069,6 +3069,7 @@ struct libxl__domain_create_state {libxl_domain_config *guest_config;libxl_domain_config guest_config_saved;/* vanilla config */ int restore_fd; +uint32_t domid_soft_reset;libxl__domain_create_cb *callback;libxl_asyncprogress_how aop_console_how;/* private to domain_create */
@@ -3123,6 +3124,9 @@ _hidden void libxl__xc_domain_restore(libxl__egc *egc,* If rc!=0, retval and errnoval are undefined. */ _hidden void libxl__xc_domain_restore_done(libxl__egc *egc, void *dcs_void,int rc,int retval,int errnoval); +/* calls libxl__xc_domain_restore_done when done */ +_hidden void libxl__xc_domain_soft_reset(libxl__egc *egc, +libxl__domain_create_state *dcs);/* Each time the dm needs to be saved, we must call suspend and then save */ _hidden int libxl__domain_suspend_device_model(libxl__gc *gc,
tools/libxl/xl_cmdimpl.c +20 -2
@@ -2043,7 +2043,8 @@ static void reload_domain_config(uint32_t domid, }/* Returns 1 if domain should be restarted, -* 2 if domain should be renamed then restarted, or 0 +* 2 if domain should be renamed then restarted, +* 3 if domain performed soft reset, or 0 * Can update r_domid if domain is destroyed etc */ static int handle_domain_death(uint32_t *r_domid, libxl_event *event,
@@ -2069,6 +2070,9 @@ static int handle_domain_death(uint32_t *r_domid,case LIBXL_SHUTDOWN_REASON_WATCHDOG : action = d_config->on_watchdog;break ; +case LIBXL_SHUTDOWN_REASON_SOFT_RESET : +LOG ("Domain performed soft reset." ); +return 3 ;default :LOG ("Unknown shutdown reason code %d. Destroying domain." , event->u.domain_shutdown.shutdown_reason);
@@ -2285,6 +2289,7 @@ static void evdisable_disk_ejects(libxl_evgen_disk_eject **diskws,static uint32_t create_domain (struct domain_create *dom_info) {uint32_t domid =INVALID_DOMID ; +uint32_t domid_old =INVALID_DOMID ;libxl_domain_config d_config;
@@ -2510,7 +2515,18 @@ start:* restore/migrate-receive it again. */ restoring =0 ; - }else { + }else if (domid_old !=INVALID_DOMID ) { +/* Do soft reset */ + d_config.b_info.nodemap.size =0 ; + ret =libxl_domain_soft_reset (ctx, &d_config, + &domid, domid_old, +0 ,0 ); + +if ( ret ) { + goto error_out; + } + domid_old =INVALID_DOMID ; + }else { ret =libxl_domain_create_new (ctx, &d_config, &domid,0 , autoconnect_console_how); }
@@ -2574,6 +2590,8 @@ start: event->u.domain_shutdown.shutdown_reason, event->u.domain_shutdown.shutdown_reason);switch (handle_domain_death (&domid, event, &d_config)) { +case 3 : + domid_old = domid;case 2 :if (!preserve_domain (&domid, event, &d_config)) {/* If we fail then exit leaving the old domain in place. */
Signature · 1 line
1.9.3
Re: [PATCH v4 8/9] libxl: soft reset support
(I've skipped the internal implementation since I don't know what's
required to fulfil soft reset.)
On Wed, Dec 03, 2014 at 06:16:20PM +0100, Vitaly Kuznetsov wrote:
[...]
Quoted 19 lines
tools/libxl/libxl_internal.h +1
-0+ libxl__domain_create_state *dcs);/* Each time the dm needs to be saved, we must call suspend and then save */ _hidden int libxl__domain_suspend_device_model(libxl__gc *gc,tools/libxl/xl_cmdimpl.c +2
-1@@ -2043,7 +2043,8 @@ static void reload_domain_config(uint32_t domid, }/* Returns 1 if domain should be restarted, -* 2 if domain should be renamed then restarted, or 0 +* 2 if domain should be renamed then restarted, +* 3 if domain performed soft reset, or 0 * Can update r_domid if domain is destroyed etc */ static int handle_domain_death(uint32_t *r_domid, libxl_event *event,
tools/libxl/xl_cmdimpl.c static int handle_domain_death(uint32_t *r_domid, · line 2075
Quoted 6 lines
tools/libxl/xl_cmdimpl.c +3
-0@@ -2069,6 +2070,9 @@ static int handle_domain_death(uint32_t *r_domid,case LIBXL_SHUTDOWN_REASON_WATCHDOG : action = d_config->on_watchdog;break ; +case LIBXL_SHUTDOWN_REASON_SOFT_RESET : +LOG ("Domain performed soft reset." ); +return 3 ;
Would it be useful to provide "on_soft_reset" option in xl? Will the admin be interested in performing some other action when domain does soft reset? Say, for security reason admin want to prohibit domain from soft resetting itself.
Quoted 12 lines
tools/libxl/xl_cmdimpl.c +1
-0default :LOG ("Unknown shutdown reason code %d. Destroying domain." , event->u.domain_shutdown.shutdown_reason);@@ -2285,6 +2289,7 @@ static void evdisable_disk_ejects(libxl_evgen_disk_eject **diskws,static uint32_t create_domain (struct domain_create *dom_info) {uint32_t domid =INVALID_DOMID ; +uint32_t domid_old =INVALID_DOMID ;libxl_domain_config d_config;
tools/libxl/xl_cmdimpl.c start: · line 2520
Quoted 7 lines
tools/libxl/xl_cmdimpl.c +3
-1@@ -2510,7 +2515,18 @@ start:* restore/migrate-receive it again. */ restoring =0 ; - }else { + }else if (domid_old !=INVALID_DOMID ) { +/* Do soft reset */ + d_config.b_info.nodemap.size =0 ;
What's the reason for doing this?
If you encounter problem with this it should probably be fixed in libxl.
Wei.
Quoted 29 lines
tools/libxl/xl_cmdimpl.c +11
-0+ ret =libxl_domain_soft_reset (ctx, &d_config, + &domid, domid_old, +0 ,0 ); + +if ( ret ) { + goto error_out; + } + domid_old =INVALID_DOMID ; + }else { ret =libxl_domain_create_new (ctx, &d_config, &domid,0 , autoconnect_console_how); }@@ -2574,6 +2590,8 @@ start: event->u.domain_shutdown.shutdown_reason, event->u.domain_shutdown.shutdown_reason);switch (handle_domain_death (&domid, event, &d_config)) { +case 3 : + domid_old = domid;case 2 :if (!preserve_domain (&domid, event, &d_config)) {/* If we fail then exit leaving the old domain in place. */ Signature · 7 lines
1.9.3 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 8/9] libxl: soft reset support
Quoted 27 lines · Wei Liu
(I've skipped the internal implementation since I don't know what's
required to fulfil soft reset.)On Wed, Dec 03, 2014 at 06:16:20PM +0100, Vitaly Kuznetsov wrote:
[...]Quoted 22 lines
tools/libxl/libxl_internal.h +1
-0+ libxl__domain_create_state *dcs);/* Each time the dm needs to be saved, we must call suspend and then save */ _hidden int libxl__domain_suspend_device_model(libxl__gc *gc,tools/libxl/xl_cmdimpl.c +2
-1@@ -2043,7 +2043,8 @@ static void reload_domain_config(uint32_t domid, }/* Returns 1 if domain should be restarted, -* 2 if domain should be renamed then restarted, or 0 +* 2 if domain should be renamed then restarted, +* 3 if domain performed soft reset, or 0 * Can update r_domid if domain is destroyed etc */ static int handle_domain_death(uint32_t *r_domid, libxl_event *event,@@ -2069,6 +2070,9 @@ static int handle_domain_death(uint32_t *r_domid,case LIBXL_SHUTDOWN_REASON_WATCHDOG : action = d_config->on_watchdog;break ;
Quoted 9 lines
tools/libxl/xl_cmdimpl.c static int handle_domain_death(uint32_t *r_domid, · line 2075
Quoted 3 lines
tools/libxl/xl_cmdimpl.c +3
-0+case LIBXL_SHUTDOWN_REASON_SOFT_RESET : +LOG ("Domain performed soft reset." ); +return 3 ;Would it be useful to provide "
on_soft_reset" option in xl? Will the admin be interested in performing some other action when domain does soft reset? Say, for security reason admin want to prohibit domain from soft resetting itself.
Makes sense, let's add it.
Quoted 22 lines
Quoted 12 lines
tools/libxl/xl_cmdimpl.c +1
-0default :LOG ("Unknown shutdown reason code %d. Destroying domain." , event->u.domain_shutdown.shutdown_reason);@@ -2285,6 +2289,7 @@ static void evdisable_disk_ejects(libxl_evgen_disk_eject **diskws,static uint32_t create_domain (struct domain_create *dom_info) {uint32_t domid =INVALID_DOMID ; +uint32_t domid_old =INVALID_DOMID ;libxl_domain_config d_config;tools/libxl/xl_cmdimpl.c start: · line 2520
Quoted 7 lines
tools/libxl/xl_cmdimpl.c +3
-1@@ -2510,7 +2515,18 @@ start:* restore/migrate-receive it again. */ restoring =0 ; - }else { + }else if (domid_old !=INVALID_DOMID ) { +/* Do soft reset */ + d_config.b_info.nodemap.size =0 ;What's the reason for doing this?
Quoted 2 lines
If you encounter problem with this it should probably be fixed in libxl.
Ah, sorry, I forgot about this hackaround (which was required since 194e7183 if I'm not mistaken). The root cause is that reload_domain_config() was missing on soft_reset path and we were hitting "Can run NUMA placement only if the domain does not have any NUMA node affinity set already" clause.
I will fix this along with "on_soft_reset" implementation.
Quoted 32 lines
Wei.
Quoted 29 lines
tools/libxl/xl_cmdimpl.c +11
-0+ ret =libxl_domain_soft_reset (ctx, &d_config, + &domid, domid_old, +0 ,0 ); + +if ( ret ) { + goto error_out; + } + domid_old =INVALID_DOMID ; + }else { ret =libxl_domain_create_new (ctx, &d_config, &domid,0 , autoconnect_console_how); }@@ -2574,6 +2590,8 @@ start: event->u.domain_shutdown.shutdown_reason, event->u.domain_shutdown.shutdown_reason);switch (handle_domain_death (&domid, event, &d_config)) { +case 3 : + domid_old = domid;case 2 :if (!preserve_domain (&domid, event, &d_config)) {/* If we fail then exit leaving the old domain in place. */ Signature · 7 lines
1.9.3 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Signature · 1 line
Vitaly
PATCH v4 9/9 xsm: add XEN_DOMCTL_devour support
In reply to Vitaly Kuznetsov--- xen/common/domctl.c | 6 ++++++ xen/include/xsm/dummy.h | 6 ++++++ xen/include/xsm/xsm.h | 6 ++++++ xen/xsm/dummy.c | 1 + xen/xsm/flask/hooks.c | 17 +++++++++++++++++ xen/xsm/flask/policy/access_vectors | 10 ++++++++++ 6 files changed, 46 insertions(+)
xen/common/domctl.c +6 -0
@@ -1190,6 +1190,12 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)break ; } + ret =xsm_devour (XSM_HOOK , d, recipient_dom); +if ( ret ) { +put_domain (recipient_dom); +break ; + } +if ( recipient_dom->tot_pages !=0 ) {put_domain (recipient_dom);
xen/include/xsm/dummy.h +6 -0
@@ -113,6 +113,12 @@ static XSM_INLINE int xsm_set_target(XSM_DEFAULT_ARG struct domain *d, struct doreturn xsm_default_action (action, current->domain,NULL ); } +static XSM_INLINE int xsm_devour(XSM_DEFAULT_ARG struct domain *d, struct domain *e) +{ +XSM_ASSERT_ACTION (XSM_HOOK ); +return xsm_default_action (action, current->domain,NULL ); +} + static XSM_INLINE int xsm_domctl(XSM_DEFAULT_ARG struct domain *d, int cmd) {XSM_ASSERT_ACTION (XSM_OTHER );
xen/include/xsm/xsm.h +6 -0
@@ -58,6 +58,7 @@ struct xsm_operations {int (*domctl_scheduler_op) (struct domain *d,int op);int (*sysctl_scheduler_op) (int op);int (*set_target) (struct domain *d,struct domain *e); +int (*devour) (struct domain *d,struct domain *e);int (*domctl) (struct domain *d,int cmd);int (*sysctl) (int cmd);int (*readconsole) (uint32_t clear);
@@ -213,6 +214,11 @@ static inline int xsm_set_target (xsm_default_t def, struct domain *d, struct doreturn xsm_ops->set_target (d, e); } +static inline int xsm_devour (xsm_default_t def,struct domain *d,struct domain *r) +{ +return xsm_ops->devour (d, r); +} +static inline int xsm_domctl (xsm_default_t def,struct domain *d,int cmd) {return xsm_ops->domctl (d, cmd);
xen/xsm/dummy.c +1 -0
@@ -35,6 +35,7 @@ void xsm_fixup_ops (struct xsm_operations *ops)set_to_dummy_if_null (ops, domctl_scheduler_op);set_to_dummy_if_null (ops, sysctl_scheduler_op);set_to_dummy_if_null (ops, set_target); +set_to_dummy_if_null (ops, devour);set_to_dummy_if_null (ops, domctl);set_to_dummy_if_null (ops, sysctl);set_to_dummy_if_null (ops, readconsole);
xen/xsm/flask/hooks.c +17 -0
@@ -565,6 +565,21 @@ static int flask_set_target(struct domain *d, struct domain *t)return rc; } +static int flask_devour (struct domain *d,struct domain *r) +{ +int rc; +struct domain_security_struct *dsec, *rsec; + dsec = d->ssid; + rsec = r->ssid; + + rc =current_has_perm (d,SECCLASS_DOMAIN2 ,DOMAIN2__SET_AS_SOURCE ); +if ( rc ) +return rc; +if ( r ) + rc =current_has_perm (r,SECCLASS_DOMAIN2 ,DOMAIN2__SET_AS_RECIPIENT ); +return rc; +} +static int flask_domctl (struct domain *d,int cmd) { switch ( cmd )
@@ -580,6 +595,7 @@ static int flask_domctl(struct domain *d, int cmd)#ifdef HAS_MEM_ACCESS case XEN_DOMCTL_mem_event_op:#endif +case XEN_DOMCTL_devour:#ifdef CONFIG_X86 /* These have individual XSM hooks (arch/x86/domctl.c) */ case XEN_DOMCTL_shadow_op:
@@ -1512,6 +1528,7 @@ static struct xsm_operations flask_ops = { .domctl_scheduler_op = flask_domctl_scheduler_op, .sysctl_scheduler_op = flask_sysctl_scheduler_op, .set_target = flask_set_target, + .devour = flask_devour, .domctl = flask_domctl, .sysctl = flask_sysctl, .readconsole = flask_readconsole,
xen/xsm/flask/policy/access_vectors +10 -0
@@ -142,6 +142,8 @@ class domain # target = the new target domain # see also the domain2 make_priv_for and set_as_target checks set_target +# XEN_DOMCTL_devour + devour # SCHEDOP_remote_shutdown shutdown # XEN_DOMCTL_set{,_machine}_address_size
@@ -196,6 +198,14 @@ class domain2 # source = the domain making the hypercall # target = the new target domain set_as_target +# checked in XEN_DOMCTL_devour: +# source = the domain making the hypercall +# target = the new source domain + set_as_source +# checked in XEN_DOMCTL_devour: +# source = the domain making the hypercall +# target = the new recipient domain + set_as_recipient # XEN_DOMCTL_set_cpuid set_cpuid # XEN_DOMCTL_gettscinfo
Signature · 1 line
1.9.3
Quoted 11 lines · Vitaly Kuznetsov
Original description:
When a PVHVM linux guest performs kexec there are lots of things which require taking care of:
- shared info,vcpu_info
- grants
- event channels
- ...
Instead of taking care of all these things we can rebuild the domain performing kexec from scratch doing so-called soft-reboot.
Quoted 4 lines
The idea was suggested by David Vrabel, Jan Beulich, and Konrad Rzeszutek Wilk.
P.S. The patch series can be tested with PVHVM Linux guest with the following modifications:
Its not clear to me how thew old kernel starts the new kernel. How and where is that done?
Olaf
Quoted 13 lines · Olaf Hering
Quoted 11 lines · Vitaly Kuznetsov
Original description:
When a PVHVM linux guest performs kexec there are lots of things which require taking care of:
- shared info,vcpu_info
- grants
- event channels
- ...
Instead of taking care of all these things we can rebuild the domain performing kexec from scratch doing so-called soft-reboot.
Quoted 7 lines
Quoted 4 lines
The idea was suggested by David Vrabel, Jan Beulich, and Konrad Rzeszutek Wilk.
P.S. The patch series can be tested with PVHVM Linux guest with the following modifications:Its not clear to me how thew old kernel starts the new kernel. How and where is that done?
It is done by linux kernel itself, I bring nothing new into the picture. It all works like this:
1) Original guest does HYPERVISOR_sched_op(SCHEDOP_shutdown, r = { .reason = SHUTDOWN_soft_reset})
2) All this rebuild machinery happens including copying HVM context
3) New guest resumes from where old did the hypercall
4) Kernel does kexec and new kernel is being booted.
Quoted 2 lines
Olaf
Signature · 1 line
Vitaly
Quoted 25 lines · Vitaly Kuznetsov
Changes from RFCv3:
This is the first non-RFC series as no major concerns were expressed. I'm trying to address Jan's comments. Changes are:
- Move fromXEN_DOMCTL_set_recipienttoXEN_DOMCTL_devour(I don't really like the name but nothing more appropriate came to my mind) which incorporates formerXEN_DOMCTL_set_recipientandXEN_DOMCTL_destroydomainto prevent original domain from changing its allocations during transfer procedure.
- Check infree_domheap_pages()thatassign_pages()succeeded.
- Changeprintk()infree_domheap_pages().
-DOMDYING_lockedstate was introduced to supportXEN_DOMCTL_devour.
-xc_domain_soft_reset()got simplified a bit. Now we just wait for the original domain to die or loose all its pages.
- rebased on top of current master branch.Changes from RFC/WIPv2:
Here is a slightly different approach to memory reassignment. Instead of introducing new (and very doubtful)
XENMEM_transferoperation introduce simpleXEN_DOMCTL_set_recipientoperation and do everything infree_domheap_pages()handler utilizing normal domain destroy path. This is better because:
- The approach is general-enough
- All memory pages are usually being freed when the domain is destroyed
- No special grants handling required
- Better supportability
Quoted 12 lines
With regards to PV:
ThoughXEN_DOMCTL_set_recipientworks for both PV and HVM this patchset does not bring PV kexec/kdump support.xc_domain_soft_reset()is limited to work with HVM domains only. The main reason for that is: it is (in theory) possible to save p2m and rebuild them with the new domain but that would only allow us to resume execution from where we stopped. If we want to execute new kernel we need to build the samekernel/initrd/bootstrap_pagetables/... structure we build to boot PV domain initially. That however would destroy the original domain's memory thus making kdump impossible. To make everything work additional support from kexec userspace/linux kernel is required and I'm not sure it makes sense to implement all this stuff in the light of PVH.
What would happen if you soft reset a PV guest? At the very least soft reset should be explicitly forbidden in PV case.
Quoted 8 lines
Original description:
When a PVHVM linux guest performs kexec there are lots of things which require taking care of:
- shared info,vcpu_info
- grants
- event channels
- ...
Is there a complete list?
Quoted 5 lines
Instead of taking care of all these things we can rebuild the domain performing kexec from scratch doing so-called soft-reboot.
The idea was suggested by David Vrabel, Jan Beulich, and Konrad Rzeszutek Wilk.
As this approach requires toolstack do complex interaction with hypervisor and preserve / throw away a bunch of states. I think the whole procedure should be documented.
It would also be helpful if you link to previous discussions in your cover letter.
Wei.
Quoted 39 lines · Wei Liu
Quoted 25 lines · Vitaly Kuznetsov
Changes from RFCv3:
This is the first non-RFC series as no major concerns were expressed. I'm trying to address Jan's comments. Changes are:
- Move fromXEN_DOMCTL_set_recipienttoXEN_DOMCTL_devour(I don't really like the name but nothing more appropriate came to my mind) which incorporates formerXEN_DOMCTL_set_recipientandXEN_DOMCTL_destroydomainto prevent original domain from changing its allocations during transfer procedure.
- Check infree_domheap_pages()thatassign_pages()succeeded.
- Changeprintk()infree_domheap_pages().
-DOMDYING_lockedstate was introduced to supportXEN_DOMCTL_devour.
-xc_domain_soft_reset()got simplified a bit. Now we just wait for the original domain to die or loose all its pages.
- rebased on top of current master branch.Changes from RFC/WIPv2:
Here is a slightly different approach to memory reassignment. Instead of introducing new (and very doubtful)
XENMEM_transferoperation introduce simpleXEN_DOMCTL_set_recipientoperation and do everything infree_domheap_pages()handler utilizing normal domain destroy path. This is better because:
- The approach is general-enough
- All memory pages are usually being freed when the domain is destroyed
- No special grants handling required
- Better supportabilityQuoted 12 lines
With regards to PV:
ThoughXEN_DOMCTL_set_recipientworks for both PV and HVM this patchset does not bring PV kexec/kdump support.xc_domain_soft_reset()is limited to work with HVM domains only. The main reason for that is: it is (in theory) possible to save p2m and rebuild them with the new domain but that would only allow us to resume execution from where we stopped. If we want to execute new kernel we need to build the samekernel/initrd/bootstrap_pagetables/... structure we build to boot PV domain initially. That however would destroy the original domain's memory thus making kdump impossible. To make everything work additional support from kexec userspace/linux kernel is required and I'm not sure it makes sense to implement all this stuff in the light of PVH.
Quoted 2 lines
What would happen if you soft reset a PV guest? At the very least soft reset should be explicitly forbidden in PV case.
Well, nothing particulary bad from hypervisor point of view happens. But when PV guest dies page tables are being destroyed (and we lose the knowledge anyway). It would be possible for the toolstack to start from the beggining - build bootstrap tables, put kernel/initrd and start everything. I however don't see any value in doing so: our memory gets destroyed and it is going to be the same as plain reboot.
Why do we need to forbid the call for PV? (xc_domain_soft_reset() already forbids PV).
Quoted 12 lines
Quoted 9 lines
Original description:
When a PVHVM linux guest performs kexec there are lots of things which require taking care of:
- shared info,vcpu_info
- grants
- event channels
- ...Is there a complete list?
Konrad tried to assemble it here:
http://lists.xen.org/archives/html/xen-devel/2014-06/msg03889.html
Quoted 9 lines
Quoted 5 lines
Instead of taking care of all these things we can rebuild the domain performing kexec from scratch doing so-called soft-reboot.
The idea was suggested by David Vrabel, Jan Beulich, and Konrad Rzeszutek Wilk.
As this approach requires toolstack do complex interaction with hypervisor and preserve / throw away a bunch of states. I think the whole procedure should be documented.
Sure.. Where would you expect such doc to appear?
Quoted 3 lines
It would also be helpful if you link to previous discussions in your cover letter.
Sure, will do next time. For now:
on resetting VCPU_info (and that's where 'rebuild everything with the toolstack solution' was suggested):
http://lists.xen.org/archives/html/xen-devel/2014-08/msg01869.html
Previous versions:
http://lists.xen.org/archives/html/xen-devel/2014-08/msg01630.html
http://lists.xen.org/archives/html/xen-devel/2014-08/msg00603.html
EVTCHNOP_reset (got merged):
http://lists.xen.org/archives/html/xen-devel/2014-07/msg03979.html
Previous:
http://lists.xen.org/archives/html/xen-devel/2014-07/msg03925.html
http://lists.xen.org/archives/html/xen-devel/2014-07/msg03322.html
http://lists.xen.org/archives/html/xen-devel/2014-07/msg02500.html
This patch series:
http://lists.xen.org/archives/html/xen-devel/2014-10/msg00764.html
http://lists.xen.org/archives/html/xen-devel/2014-09/msg03623.html
http://lists.xen.org/archives/html/xen-devel/2014-08/msg02309.html
Quoted 2 lines
Wei.
Signature · 1 line
Vitaly
Quoted 44 lines · Vitaly Kuznetsov
Quoted 39 lines · Wei Liu
Quoted 25 lines · Vitaly Kuznetsov
Changes from RFCv3:
This is the first non-RFC series as no major concerns were expressed. I'm trying to address Jan's comments. Changes are:
- Move fromXEN_DOMCTL_set_recipienttoXEN_DOMCTL_devour(I don't really like the name but nothing more appropriate came to my mind) which incorporates formerXEN_DOMCTL_set_recipientandXEN_DOMCTL_destroydomainto prevent original domain from changing its allocations during transfer procedure.
- Check infree_domheap_pages()thatassign_pages()succeeded.
- Changeprintk()infree_domheap_pages().
-DOMDYING_lockedstate was introduced to supportXEN_DOMCTL_devour.
-xc_domain_soft_reset()got simplified a bit. Now we just wait for the original domain to die or loose all its pages.
- rebased on top of current master branch.Changes from RFC/WIPv2:
Here is a slightly different approach to memory reassignment. Instead of introducing new (and very doubtful)
XENMEM_transferoperation introduce simpleXEN_DOMCTL_set_recipientoperation and do everything infree_domheap_pages()handler utilizing normal domain destroy path. This is better because:
- The approach is general-enough
- All memory pages are usually being freed when the domain is destroyed
- No special grants handling required
- Better supportabilityQuoted 12 lines
With regards to PV:
ThoughXEN_DOMCTL_set_recipientworks for both PV and HVM this patchset does not bring PV kexec/kdump support.xc_domain_soft_reset()is limited to work with HVM domains only. The main reason for that is: it is (in theory) possible to save p2m and rebuild them with the new domain but that would only allow us to resume execution from where we stopped. If we want to execute new kernel we need to build the samekernel/initrd/bootstrap_pagetables/... structure we build to boot PV domain initially. That however would destroy the original domain's memory thus making kdump impossible. To make everything work additional support from kexec userspace/linux kernel is required and I'm not sure it makes sense to implement all this stuff in the light of PVH.Quoted 2 lines
What would happen if you soft reset a PV guest? At the very least soft reset should be explicitly forbidden in PV case.
Quoted 7 lines
Well, nothing particulary bad from hypervisor point of view happens. But when PV guest dies page tables are being destroyed (and we lose the knowledge anyway). It would be possible for the toolstack to start from the beggining - build bootstrap tables, put kernel/initrd and start everything. I however don't see any value in doing so: our memory gets destroyed and it is going to be the same as plain reboot.
OK. As long as hypervisor is safe I'm OK with it. I was thinking from a security PoV, i.e. there is no guest triggerable crash of hypervisor, guest cannot escape by providing arbitrary new kernel, etc.
Quoted 23 lines
Why do we need to forbid the call for PV? (
xc_domain_soft_reset()already forbids PV).Quoted 12 lines
Quoted 9 lines
Original description:
When a PVHVM linux guest performs kexec there are lots of things which require taking care of:
- shared info,vcpu_info
- grants
- event channels
- ...Is there a complete list?
Konrad tried to assemble it here:
http://lists.xen.org/archives/html/xen-devel/2014-06/msg03889.htmlQuoted 3 lines
Quoted 3 lines
Instead of taking care of all these things we can rebuild the domain performing kexec from scratch doing so-called soft-reboot.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
The idea was suggested by David Vrabel, Jan Beulich, and Konrad Rzeszutek Wilk.
As this approach requires toolstack do complex interaction with hypervisor and preserve / throw away a bunch of states. I think the whole procedure should be documented.
Sure.. Where would you expect such doc to appear?
I think libxl_internal.h is the right place. Just group the documentation with other internal functions you introduced.
Re all the links, thanks, I will have a look.
Wei.
Quoted 29 lines
Quoted 3 lines
It would also be helpful if you link to previous discussions in your cover letter.
Sure, will do next time. For now:
on resettingVCPU_info(and that's where 'rebuild everything with the toolstack solution' was suggested):
http://lists.xen.org/archives/html/xen-devel/2014-08/msg01869.html
Previous versions:
http://lists.xen.org/archives/html/xen-devel/2014-08/msg01630.html
http://lists.xen.org/archives/html/xen-devel/2014-08/msg00603.html
EVTCHNOP_reset(got merged):
http://lists.xen.org/archives/html/xen-devel/2014-07/msg03979.html
Previous:
http://lists.xen.org/archives/html/xen-devel/2014-07/msg03925.html
http://lists.xen.org/archives/html/xen-devel/2014-07/msg03322.html
http://lists.xen.org/archives/html/xen-devel/2014-07/msg02500.htmlThis patch series:
http://lists.xen.org/archives/html/xen-devel/2014-10/msg00764.html
http://lists.xen.org/archives/html/xen-devel/2014-09/msg03623.html
http://lists.xen.org/archives/html/xen-devel/2014-08/msg02309.htmlQuoted 2 lines
Wei.
Signature · 1 line
Vitaly
Quoted 8 lines · Vitaly Kuznetsov
When a PVHVM linux guest performs kexec there are lots of things which require taking care of:
- shared info,vcpu_info
- grants
- event channels
- ...
Instead of taking care of all these things we can rebuild the domain performing kexec from scratch doing so-called soft-reboot.
How does this approach handle ballooned pages?
Quoted 1 line
From the guests point of view they are always there, just claimed by the
balloon driver. The new kernel does not have that driver nor does its driver have the knowledge which pages the old kernel gave back to Xen.
After a brief look none of the patches seem to deal with that.
Olaf
Quoted 11 lines · Olaf Hering
Quoted 8 lines · Vitaly Kuznetsov
When a PVHVM linux guest performs kexec there are lots of things which require taking care of:
- shared info,vcpu_info
- grants
- event channels
- ...
Instead of taking care of all these things we can rebuild the domain performing kexec from scratch doing so-called soft-reboot.
Quoted 6 lines
How does this approach handle ballooned pages?
Quoted 1 line
From the guests point of view they are always there, just claimed by the
balloon driver. The new kernel does not have that driver nor does its driver have the knowledge which pages the old kernel gave back to Xen.
After a brief look none of the patches seem to deal with that.
Nothing special needs to be done with ballooned pages. If frames are not populated in the original domain, they will be unpopulated in the new domain.
It's the responsibility of the guest to ensure it either doesn't kexec when it is ballooned or that the kexec kernel can handle this (e.g., by using a crash region that is never ballooned out).
David
Quoted 7 lines · David Vrabel
Nothing special needs to be done with ballooned pages. If frames are not populated in the original domain, they will be unpopulated in the new domain.
It's the responsibility of the guest to ensure it either doesn't kexec when it is ballooned or that the kexec kernel can handle this (e.g., by using a crash region that is never ballooned out).
There is a difference between kexec and kdump. The kdump kernel does not care because there is code in /proc/vmcore to handle ballooned pages in the crashed kernel gracefully.
But a kexec boot will likely access pages which are not backed by RAM. Unfortunately there is no flag left to mark a page as ballooned.
So what you are saying means that kexec-tools needs to continue to balloon up before doing the actual kexec. I had hoped this suggested approach would get rid of that limitation.
Olaf