VM forking
v7 cover VM forking
The following series implements VM forking for Intel HVM guests to allow for the fast creation of identical VMs without the assosciated high startup costs of booting or restoring the VM from a savefile.
JIRA issue: https://xenproject.atlassian.net/browse/XEN-89
The fork operation is implemented as part of the "xl fork-vm" command:
xl fork-vm -C <config_file_for_fork> -Q <qemu_save_file> <parent_domid>
By default a fully functional fork is created. The user is in charge however to create the appropriate config file for the fork and to generate the QEMU save file before the fork-vm call is made. The config file needs to give the fork a new name at minimum but other settings may also require changes.
The interface also allows to split the forking into two steps:
xl fork-vm --launch-dm no \
-p <parent_domid>
xl fork-vm --launch-dm late \
-C <config_file_for_fork> \
-Q <qemu_save_file> \
<fork_domid>The split creation model is useful when the VM needs to be created as fast as possible. The forked VM can be unpaused without the device model being launched to be monitored and accessed via VMI. Note however that without its device model running (depending on what is executing in the VM) it is bound to misbehave or even crash when its trying to access devices that would be emulated by QEMU. We anticipate that for certain use-cases this would be an acceptable situation, in case for example when fuzzing is performed of code segments that don't access such devices.
Launching the device model requires the QEMU Xen savefile to be generated manually from the parent VM. This can be accomplished simply by connecting to its QMP socket and issuing the "xen-save-devices-state" command. For example using the standard tool socat these commands can be used to generate the file:
socat - UNIX-CONNECT:/var/run/xen/qmp-libxl-<parent_domid>
{ "execute": "qmp_capabilities" }
{ "execute": "xen-save-devices-state", \
"arguments": { "filename": "/path/to/save/qemu_state", \
"live": false} }At runtime the forked VM starts running with an empty p2m which gets lazily populated when the VM generates EPT faults, similar to how altp2m views are populated. If the memory access is a read-only access, the p2m entry is populated with a memory shared entry with its parent. For write memory accesses or in case memory sharing wasn't possible (for example in case a reference is held by a third party), a new page is allocated and the page contents are copied over from the parent VM. Forks can be further forked if needed, thus allowing for further memory savings.
A VM fork reset hypercall is also added that allows the fork to be reset to the state it was just after a fork, also accessible via xl:
xl fork-vm --fork-reset -p <fork_domid>
This is an optimization for cases where the forks are very short-lived and run without a device model, so resetting saves some time compared to creating a brand new fork provided the fork has not aquired a lot of memory. If the fork has a lot of memory deduplicated it is likely going to be faster to create a new fork from scratch and asynchronously destroying the old one.
The series has been tested with both Linux and Windows VMs and functions as expected. VM forking time has been measured to be 0.0007s, device model launch to be around 1s depending largely on the number of devices being emulated. Fork resets have been measured to be 0.0001s under the optimal circumstances.
New in v7: rebasing on staging and minor changes as requested
Patches 1-4 can be committed out-of-order
Patch 1 is a bugfix in existing code in p2m
Patch 2-3 implement changes to make forking possible
Patch 4 is a bugfix in mem_sharing
Patch 5-6 implements the VM fork and reset operation hypervisor side bits Patch 7 adds the toolstack-side code implementing VM forking and reset
Tamas K Lengyel (7):
x86/p2m: Allow p2m_get_page_from_gfn to return shared entries x86/hvm: introduce hvm_copy_context_and_params xen/x86: Make hap_get_allocation accessible x86/mem_sharing: use default_access in add_to_physmap xen/mem_sharing: VM forking
x86/mem_sharing: reset a fork
xen/tools: VM forking toolstack side
docs/man/xl.1.pod.in | 36 ++++ tools/libxc/include/xenctrl.h | 13 ++ tools/libxc/xc_memshr.c | 22 ++ tools/libxl/libxl.h | 7 + tools/libxl/libxl_create.c | 256 +++++++++++++++-------- tools/libxl/libxl_dm.c | 2 +- tools/libxl/libxl_dom.c | 43 +++- tools/libxl/libxl_internal.h | 1 + tools/libxl/libxl_types.idl | 1 + tools/xl/xl.h | 5 + tools/xl/xl_cmdtable.c | 12 ++ tools/xl/xl_saverestore.c | 95 +++++++++ tools/xl/xl_vmcontrol.c | 8 + xen/arch/x86/domain.c | 11 + xen/arch/x86/hvm/hvm.c | 255 +++++++++++++---------- xen/arch/x86/mm/hap/hap.c | 3 +- xen/arch/x86/mm/mem_sharing.c | 325 +++++++++++++++++++++++++++++- xen/arch/x86/mm/p2m.c | 25 ++- xen/include/asm-x86/hap.h | 1 + xen/include/asm-x86/hvm/hvm.h | 2 + xen/include/asm-x86/mem_sharing.h | 17 ++ xen/include/public/memory.h | 6 + xen/include/xen/sched.h | 2 + 23 files changed, 938 insertions(+), 210 deletions(-)
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v7 1/7 x86/p2m: Allow p2m_get_page_from_gfn to return shared entries
The owner domain of shared pages is dom_cow, use that for get_page otherwise the function fails to return the correct page under some situations. The check if dom_cow should be used was only performed in a subset of use-cases. Fixing the error and simplifying the existing check since we can't have any shared entries with dom_cow being NULL.
---
v7: update commit message
--- xen/arch/x86/mm/p2m.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
xen/arch/x86/mm/p2m.c +8 -6
@@ -575,11 +575,12 @@ struct page_info *p2m_get_page_from_gfn(if ( fdom ==NULL ) page =NULL ; } -else if ( !get_page (page, p2m->domain) && -/* Page could be shared */ - (!dom_cow || !p2m_is_shared (*t) || - !get_page (page, dom_cow)) ) - page =NULL ; +else + { +struct domain *d = !p2m_is_shared (*t) ? p2m->domain : dom_cow; +if ( !get_page (page, d) ) + page =NULL ; + } }p2m_read_unlock (p2m);
@@ -595,8 +596,9 @@ struct page_info *p2m_get_page_from_gfn( mfn =get_gfn_type_access (p2m,gfn_x (gfn), t, a, q,NULL );if (p2m_is_ram (*t) &&mfn_valid (mfn) ) { +struct domain *d = !p2m_is_shared (*t) ? p2m->domain : dom_cow; page =mfn_to_page (mfn); -if ( !get_page (page, p2m->domain) ) +if ( !get_page (page, d) ) page =NULL ; }put_gfn (p2m->domain,gfn_x (gfn));
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v7 3/7 xen/x86: Make hap_get_allocation accessible
In reply to Tamas K LengyelDuring VM forking we'll copy the parent domain's parameters to the client, including the HAP shadow memory setting that is used for storing the domain's EPT. We'll copy this in the hypervisor instead doing it during toolstack launch to allow the domain to start executing and unsharing memory before (or even completely without) the toolstack.
--- xen/arch/x86/mm/hap/hap.c | 3 +-- xen/include/asm-x86/hap.h | 1 + 2 files changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/mm/hap/hap.c +1 -2
@@ -321,8 +321,7 @@ static void hap_free_p2m_page(struct domain *d, struct page_info *pg) }/* Return the size of the pool, rounded up to the nearest MB */ -static unsigned int -hap_get_allocation (struct domain *d) +unsigned int hap_get_allocation (struct domain *d) {unsigned int pg = d->arch.paging.hap.total_pages + d->arch.paging.hap.p2m_pages;
xen/include/asm-x86/hap.h +1 -0
@@ -45,6 +45,7 @@ int hap_track_dirty_vram(struct domain *d,extern const struct paging_mode *hap_paging_get_mode (struct vcpu *);int hap_set_allocation (struct domain *d,unsigned int pages,bool *preempted); +unsigned int hap_get_allocation (struct domain *d);#endif /* XEN_HAP_H */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v7 4/7 x86/mem_sharing: use default_access in add_to_physmap
In reply to Tamas K LengyelWhen plugging a hole in the target physmap don't use the access permission returned by __get_gfn_type_access as it is non-sensical (p2m_access_n) in the use-case add_to_physmap was intended to be used in. It leads to vm_events being sent out for access violations at unexpected locations. Make use of p2m->default_access instead and document the ambiguity surrounding "hole" types and corner-cases with custom mem_access being set on holes.
---
v7: add detailed comment explaining the issue and why this fix is correct
--- xen/arch/x86/mm/mem_sharing.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-)
xen/arch/x86/mm/mem_sharing.c +25 -3
@@ -1061,6 +1061,29 @@ err_out:return ret; } +/* +* This function is intended to be used for plugging a "hole" in the client's +* physmap with a shared memory entry. Unfortunately the definition of a "hole" +* is currently ambigious. There are two cases one can run into a "hole": +* 1) there is no pagetable entry at all +* 2) there is a pagetable entry with a type that passes p2m_is_hole +* +* The intended use-case for this function is case 1. +* +* During 1) the mem_access being returned is p2m_access_n and that is +* incorrect to be applied to the new entry being added the client physmap, +* thus we make use of the p2m->default_access instead. +* When 2) is true it is possible that the existing pagetable entry also has +* a mem_access permission set, which could be p2m_access_n. Since we can't +* differentiate whether we are in case 1) or 2), we default to using the +* access permission defined as default for the p2m, thus in +* case 2) overwriting any custom mem_access permission the user may have set +* on a hole page. Custom mem_access permissions being set on a hole are +* unheard of but technically possible. +* +* TODO: to properly resolve this issue implement differentiation between the +* two "hole" types. +*/ static int add_to_physmap (struct domain *sd,unsigned long sgfn,shr_handle_t sh,struct domain *cd,unsigned long cgfn,bool lock)
@@ -1071,11 +1094,10 @@ int add_to_physmap(struct domain *sd, unsigned long sgfn, shr_handle_t sh,p2m_type_t smfn_type, cmfn_type;struct gfn_info *gfn_info;struct p2m_domain *p2m =p2m_get_hostp2m (cd); -p2m_access_t a;struct two_gfns tg;get_two_gfns (sd,_gfn (sgfn), &smfn_type,NULL , &smfn, - cd,_gfn (cgfn), &cmfn_type, &a, &cmfn,0 , &tg, lock); + cd,_gfn (cgfn), &cmfn_type,NULL , &cmfn,0 , &tg, lock);/* Get the source shared page, check and lock */ ret =XENMEM_SHARING_OP_S_HANDLE_INVALID ;
@@ -1110,7 +1132,7 @@ int add_to_physmap(struct domain *sd, unsigned long sgfn, shr_handle_t sh, } ret =p2m_set_entry (p2m,_gfn (cgfn), smfn,PAGE_ORDER_4K , - p2m_ram_shared, a); + p2m_ram_shared, p2m->default_access);/* Tempted to turn this into an assert */ if ( ret )
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v7 2/7 x86/hvm: introduce hvm_copy_context_and_params
In reply to Tamas K LengyelCurrently the hvm parameters are only accessible via the HVMOP hypercalls. In this patch we introduce a new function that can copy both the hvm context and parameters directly into a target domain.
---
v7: get rid of goto's during code-movement as requested by Jan
use different order of operation in hvm_copy_context_and_params
--- xen/arch/x86/hvm/hvm.c | 253 ++++++++++++++++++++-------------- xen/include/asm-x86/hvm/hvm.h | 2 + 2 files changed, 152 insertions(+), 103 deletions(-)
xen/arch/x86/hvm/hvm.c +150 -103
@@ -4081,16 +4081,17 @@ static int hvmop_set_evtchn_upcall_vector( }static int hvm_allow_set_param (struct domain *d, -const struct xen_hvm_param *a) +uint32_t index, +uint64_t new_value) { -uint64_t value = d->arch.hvm.params[a->index]; +uint64_t value = d->arch.hvm.params[index];int rc; rc =xsm_hvm_param (XSM_TARGET , d, HVMOP_set_param);if ( rc )return rc; -switch ( a->index ) +switch ( index ) {/* The following parameters can be set by the guest. */ case HVM_PARAM_CALLBACK_IRQ :
@@ -4123,7 +4124,7 @@ static int hvm_allow_set_param(struct domain *d,if ( rc )return rc; -switch ( a->index ) +switch ( index ) {/* The following parameters should only be changed once. */ case HVM_PARAM_VIRIDIAN :
@@ -4133,7 +4134,7 @@ static int hvm_allow_set_param(struct domain *d,case HVM_PARAM_NR_IOREQ_SERVER_PAGES :case HVM_PARAM_ALTP2M :case HVM_PARAM_MCA_CAP : -if ( value !=0 && a->value != value ) +if ( value !=0 && new_value != value ) rc = -EEXIST ;break ;default :
@@ -4143,49 +4144,32 @@ static int hvm_allow_set_param(struct domain *d,return rc; } -static int hvmop_set_param ( -XEN_GUEST_HANDLE_PARAM (xen_hvm_param_t) arg) +static int hvm_set_param (struct domain *d,uint32_t index,uint64_t value) {struct domain *curr_d = current->domain; -struct xen_hvm_param a; -struct domain *d;struct vcpu *v;int rc; -if (copy_from_guest (&a, arg,1 ) ) -return -EFAULT ; - -if ( a.index >=HVM_NR_PARAMS ) +if ( index >=HVM_NR_PARAMS )return -EINVAL ; -/* Make sure the above bound check is not bypassed during speculation. */ -block_speculation (); - - d =rcu_lock_domain_by_any_id (a.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc = -EINVAL ; -if ( !is_hvm_domain (d) ) - goto out; - - rc =hvm_allow_set_param (d, &a); + rc =hvm_allow_set_param (d, index, value);if ( rc ) - goto out; +return rc; -switch ( a.index ) +switch ( index ) {case HVM_PARAM_CALLBACK_IRQ : -hvm_set_callback_via (d, a.value); +hvm_set_callback_via (d, value);hvm_latch_shinfo_size (d);break ;case HVM_PARAM_TIMER_MODE : -if ( a.value > HVMPTM_one_missed_tick_pending ) +if ( value > HVMPTM_one_missed_tick_pending ) rc = -EINVAL ;break ;case HVM_PARAM_VIRIDIAN : -if ( (a.value & ~HVMPV_feature_mask) || - !(a.value & HVMPV_base_freq) ) +if ( (value & ~HVMPV_feature_mask) || + !(value & HVMPV_base_freq) ) rc = -EINVAL ;break ;case HVM_PARAM_IDENT_PT :
@@ -4195,7 +4179,7 @@ static int hvmop_set_param(*/ if ( !paging_mode_hap (d) || !cpu_has_vmx ) { - d->arch.hvm.params[a.index] = a.value; + d->arch.hvm.params[index] = value;break ; }
@@ -4210,7 +4194,7 @@ static int hvmop_set_param( rc =0 ;domain_pause (d); - d->arch.hvm.params[a.index] = a.value; + d->arch.hvm.params[index] = value; for_each_vcpu ( d, v )paging_update_cr3 (v, false);domain_unpause (d);
@@ -4219,23 +4203,23 @@ static int hvmop_set_param(break ;case HVM_PARAM_DM_DOMAIN :/* The only value this should ever be set to is DOMID_SELF */ -if ( a.value !=DOMID_SELF ) +if ( value !=DOMID_SELF ) rc = -EINVAL ; - a.value = curr_d->domain_id; + value = curr_d->domain_id;break ;case HVM_PARAM_ACPI_S_STATE : rc =0 ; -if ( a.value ==3 ) +if ( value ==3 )hvm_s3_suspend (d); -else if ( a.value ==0 ) +else if ( value ==0 )hvm_s3_resume (d);else rc = -EINVAL ;break ;case HVM_PARAM_ACPI_IOPORTS_LOCATION : - rc =pmtimer_change_ioport (d, a.value); + rc =pmtimer_change_ioport (d, value);break ;case HVM_PARAM_MEMORY_EVENT_CR0 :case HVM_PARAM_MEMORY_EVENT_CR3 :
@@ -4250,24 +4234,24 @@ static int hvmop_set_param( rc =xsm_hvm_param_nested (XSM_PRIV , d);if ( rc )break ; -if ( a.value >1 ) +if ( value >1 ) rc = -EINVAL ;/* * Remove the check below once we have * shadow-on-shadow. */ -if ( !paging_mode_hap (d) && a.value ) +if ( !paging_mode_hap (d) && value ) rc = -EINVAL ; -if ( a.value && +if ( value && d->arch.hvm.params[HVM_PARAM_ALTP2M ] ) rc = -EINVAL ;/* Set up NHVM state for any vcpus that are already up. */ -if ( a.value && +if ( value && !d->arch.hvm.params[HVM_PARAM_NESTEDHVM ] )for_each_vcpu (d, v)if ( rc ==0 ) rc =nestedhvm_vcpu_initialise (v); -if ( !a.value || rc ) +if ( !value || rc )for_each_vcpu (d, v)nestedhvm_vcpu_destroy (v);break ;
@@ -4275,30 +4259,30 @@ static int hvmop_set_param( rc =xsm_hvm_param_altp2mhvm (XSM_PRIV , d);if ( rc )break ; -if ( a.value > XEN_ALTP2M_limited ) +if ( value > XEN_ALTP2M_limited ) rc = -EINVAL ; -if ( a.value && +if ( value && d->arch.hvm.params[HVM_PARAM_NESTEDHVM ] ) rc = -EINVAL ;break ;case HVM_PARAM_TRIPLE_FAULT_REASON : -if ( a.value >SHUTDOWN_MAX ) +if ( value >SHUTDOWN_MAX ) rc = -EINVAL ;break ;case HVM_PARAM_IOREQ_SERVER_PFN : - d->arch.hvm.ioreq_gfn.base = a.value; + d->arch.hvm.ioreq_gfn.base = value;break ;case HVM_PARAM_NR_IOREQ_SERVER_PAGES : {unsigned int i; -if ( a.value ==0 || - a.value >sizeof (d->arch.hvm.ioreq_gfn.mask) *8 ) +if ( value ==0 || + value >sizeof (d->arch.hvm.ioreq_gfn.mask) *8 ) { rc = -EINVAL ;break ; } -for ( i =0 ; i < a.value; i++ ) +for ( i =0 ; i < value; i++ )set_bit (i, &d->arch.hvm.ioreq_gfn.mask);break ;
@@ -4310,35 +4294,35 @@ static int hvmop_set_param( sizeof(d->arch.hvm.ioreq_gfn.legacy_mask) * 8);BUILD_BUG_ON (HVM_PARAM_BUFIOREQ_PFN >sizeof (d->arch.hvm.ioreq_gfn.legacy_mask) *8 ); -if ( a.value ) -set_bit (a.index, &d->arch.hvm.ioreq_gfn.legacy_mask); +if ( value ) +set_bit (index, &d->arch.hvm.ioreq_gfn.legacy_mask);break ;case HVM_PARAM_X87_FIP_WIDTH : -if ( a.value !=0 && a.value !=4 && a.value !=8 ) +if ( value !=0 && value !=4 && value !=8 ) { rc = -EINVAL ;break ; } - d->arch.x87_fip_width = a.value; + d->arch.x87_fip_width = value;break ;case HVM_PARAM_VM86_TSS :/* Hardware would silently truncate high bits. */ -if ( a.value != (uint32_t )a.value ) +if ( value != (uint32_t )value ) {if ( d == curr_d )domain_crash (d); rc = -EINVAL ; }/* Old hvmloader binaries hardcode the size to 128 bytes. */ -if ( a.value ) - a.value |= (128ULL <<32 ) |VM86_TSS_UPDATED ; - a.index =HVM_PARAM_VM86_TSS_SIZED ; +if ( value ) + value |= (128ULL <<32 ) |VM86_TSS_UPDATED ; + index =HVM_PARAM_VM86_TSS_SIZED ;break ;case HVM_PARAM_VM86_TSS_SIZED : -if ( (a.value >>32 ) <sizeof (struct tss32 ) ) +if ( (value >>32 ) <sizeof (struct tss32 ) ) {if ( d == curr_d )domain_crash (d);
@@ -4349,34 +4333,60 @@ static int hvmop_set_param(* 256 bits interrupt redirection bitmap + 64k bits I/O bitmap * plus one padding byte). */ -if ( (a.value >>32 ) >sizeof (struct tss32 ) + +if ( (value >>32 ) >sizeof (struct tss32 ) + (0x100 /8 ) + (0x10000 /8 ) +1 ) - a.value = (uint32_t )a.value | + value = (uint32_t )value | ((sizeof (struct tss32 ) + (0x100 /8 ) + (0x10000 /8 ) +1 ) <<32 ); - a.value |=VM86_TSS_UPDATED ; + value |=VM86_TSS_UPDATED ;break ;case HVM_PARAM_MCA_CAP : - rc =vmce_enable_mca_cap (d, a.value); + rc =vmce_enable_mca_cap (d, value);break ; } -if ( rc !=0 ) - goto out; +if ( !rc ) + { + d->arch.hvm.params[index] = value; - d->arch.hvm.params[a.index] = a.value; +HVM_DBG_LOG (DBG_LEVEL_HCALL ,"set param %u = %" PRIx64, + index, value); + } -HVM_DBG_LOG (DBG_LEVEL_HCALL ,"set param %u = %" PRIx64, - a.index, a.value); +return rc; +} + +int hvmop_set_param ( +XEN_GUEST_HANDLE_PARAM (xen_hvm_param_t) arg) +{ +struct xen_hvm_param a; +struct domain *d; +int rc; + +if (copy_from_guest (&a, arg,1 ) ) +return -EFAULT ; + +if ( a.index >=HVM_NR_PARAMS ) +return -EINVAL ; + +/* Make sure the above bound check is not bypassed during speculation. */ +block_speculation (); + + d =rcu_lock_domain_by_any_id (a.domid); +if ( d ==NULL ) +return -ESRCH ; + + rc = -EINVAL ; +if (is_hvm_domain (d) ) + rc =hvm_set_param (d, a.index, a.value); - out:rcu_unlock_domain (d);return rc; }static int hvm_allow_get_param (struct domain *d, -const struct xen_hvm_param *a) +uint32_t index) {int rc;
@@ -4384,7 +4394,7 @@ static int hvm_allow_get_param(struct domain *d,if ( rc )return rc; -switch ( a->index ) +switch ( index ) {/* The following parameters can be read by the guest. */ case HVM_PARAM_CALLBACK_IRQ :
@@ -4414,6 +4424,40 @@ static int hvm_allow_get_param(struct domain *d,return rc; } +static int hvm_get_param (struct domain *d,uint32_t index,uint64_t *value) +{ +int rc; + + rc =hvm_allow_get_param (d, index); +if ( rc ) +return rc; + +switch ( index ) + { +case HVM_PARAM_ACPI_S_STATE : + *value = d->arch.hvm.is_s3_suspended ?3 :0 ; +break ; + +case HVM_PARAM_VM86_TSS : + *value = (uint32_t )d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED ]; +break ; + +case HVM_PARAM_VM86_TSS_SIZED : + *value = d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED ] & + ~VM86_TSS_UPDATED ; +break ; + +case HVM_PARAM_X87_FIP_WIDTH : + *value = d->arch.x87_fip_width; +break ; +default : + *value = d->arch.hvm.params[index]; +break ; + } + +return 0 ; +}; +static int hvmop_get_param (XEN_GUEST_HANDLE_PARAM (xen_hvm_param_t) arg) {
@@ -4435,42 +4479,14 @@ static int hvmop_get_param(return -ESRCH ; rc = -EINVAL ; -if ( !is_hvm_domain (d) ) - goto out; - - rc =hvm_allow_get_param (d, &a); -if ( rc ) - goto out; - -switch ( a.index ) +if (is_hvm_domain (d) && !(rc =hvm_get_param (d, a.index, &a.value)) ) { -case HVM_PARAM_ACPI_S_STATE : - a.value = d->arch.hvm.is_s3_suspended ?3 :0 ; -break ; - -case HVM_PARAM_VM86_TSS : - a.value = (uint32_t )d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED ]; -break ; - -case HVM_PARAM_VM86_TSS_SIZED : - a.value = d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED ] & - ~VM86_TSS_UPDATED ; -break ; + rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ; -case HVM_PARAM_X87_FIP_WIDTH : - a.value = d->arch.x87_fip_width; -break ; -default : - a.value = d->arch.hvm.params[a.index]; -break ; +HVM_DBG_LOG (DBG_LEVEL_HCALL ,"get param %u = %" PRIx64, + a.index, a.value); } - rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ; - -HVM_DBG_LOG (DBG_LEVEL_HCALL ,"get param %u = %" PRIx64, - a.index, a.value); - - out:rcu_unlock_domain (d);return rc; }
@@ -5301,6 +5317,37 @@ void hvm_set_segment_register(struct vcpu *v, enum x86_segment seg,alternative_vcall (hvm_funcs.set_segment_register, v, seg, reg); } +int hvm_copy_context_and_params (struct domain *dst,struct domain *src) +{ +int rc; +unsigned int i; +struct hvm_domain_context c = { }; + + c.size =hvm_save_size (src); +if ( (c.data =vmalloc (c.size)) ==NULL ) +return -ENOMEM ; + +if ( (rc =hvm_save (src, &c)) ) +return rc; + +for ( i =0 ; i <HVM_NR_PARAMS ; i++ ) + { +uint64_t value =0 ; + +if (hvm_get_param (src, i, &value) || !value ) +continue ; + +if ( (rc =hvm_set_param (dst, i, value)) ) +return rc; + } + + c.cur =0 ; + rc =hvm_load (dst, &c); +vfree (c.data); + +return rc; +} +/* * Local variables: * mode: C
xen/include/asm-x86/hvm/hvm.h +2 -0
@@ -337,6 +337,8 @@ unsigned long hvm_cr4_guest_valid_bits(const struct domain *d, bool restore);bool hvm_flush_vcpu_tlb (bool (*flush_vcpu)(void *ctxt,struct vcpu *v),void *ctxt); +int hvm_copy_context_and_params (struct domain *src,struct domain *dst); +#ifdef CONFIG_HVM #define hvm_get_guest_tsc (v) hvm_get_guest_tsc_fixed(v, 0)
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v7 6/7 x86/mem_sharing: reset a fork
In reply to Tamas K LengyelImplement hypercall that allows a fork to shed all memory that got allocated for it during its execution and re-load its vCPU context from the parent VM. This allows the forked VM to reset into the same state the parent VM is in a faster way then creating a new fork would be. Measurements show about a 2x speedup during normal fuzzing operations. Performance may vary depending how much memory got allocated for the forked VM. If it has been completely deduplicated from the parent VM then creating a new fork would likely be more performant.
--- xen/arch/x86/mm/mem_sharing.c | 76 +++++++++++++++++++++++++++++++++++ xen/include/public/memory.h | 1 + 2 files changed, 77 insertions(+)
xen/arch/x86/mm/mem_sharing.c +76 -0
@@ -1635,6 +1635,59 @@ static int mem_sharing_fork(struct domain *d, struct domain *cd)return rc; } +/* +* The fork reset operation is intended to be used on short-lived forks only. +* There is no hypercall continuation operation implemented for this reason. +* For forks that obtain a larger memory footprint it is likely going to be +* more performant to create a new fork instead of resetting an existing one. +* +* TODO: In case this hypercall would become useful on forks with larger memory +* footprints the hypercall continuation should be implemented. +*/ +static int mem_sharing_fork_reset (struct domain *d,struct domain *cd) +{ +int rc; +struct p2m_domain * p2m =p2m_get_hostp2m (cd); +struct page_info *page, *tmp; + +domain_pause (cd); + +page_list_for_each_safe (page, tmp, &cd->page_list) + { +p2m_type_t p2mt; +p2m_access_t p2ma; +gfn_t gfn; +mfn_t mfn =page_to_mfn (page); + +if ( !mfn_valid (mfn) ) +continue ; + + gfn =mfn_to_gfn (cd, mfn); + mfn =__get_gfn_type_access (p2m,gfn_x (gfn), &p2mt, &p2ma, +0 ,NULL , false); + +if ( !p2m_is_ram (p2mt) ||p2m_is_shared (p2mt) ) +continue ; + +/* take an extra reference */ +if ( !get_page (page, cd) ) +continue ; + + rc = p2m->set_entry (p2m, gfn,INVALID_MFN ,PAGE_ORDER_4K , + p2m_invalid, p2m_access_rwx,-1 ); +ASSERT (!rc); + +put_page_alloc_ref (page); +put_page (page); + } + +if ( !(rc =hvm_copy_context_and_params (cd, d)) ) +fork_tsc (cd, d); + +domain_unpause (cd); +return rc; +} +int mem_sharing_memop (XEN_GUEST_HANDLE_PARAM (xen_mem_sharing_op_t) arg) {int rc;
@@ -1919,6 +1972,29 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)break ; } +case XENMEM_sharing_op_fork_reset: + { +struct domain *pd; + + rc = -EINVAL ; +if ( mso.u.fork._pad[0 ] || mso.u.fork._pad[1 ] || + mso.u.fork._pad[2 ] ) + goto out; + + rc = -ENOSYS ; +if ( !d->parent ) + goto out; + + rc =rcu_lock_live_remote_domain_by_id (d->parent->domain_id, &pd); +if ( rc ) + goto out; + + rc =mem_sharing_fork_reset (pd, d); + +rcu_unlock_domain (pd); +break ; + } +default : rc = -ENOSYS ;break ;
xen/include/public/memory.h +1 -0
@@ -483,6 +483,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_mem_access_op_t);#define XENMEM_sharing_op_audit 7#define XENMEM_sharing_op_range_share 8#define XENMEM_sharing_op_fork 9 +#define XENMEM_sharing_op_fork_reset 10#define XENMEM_SHARING_OP_S_HANDLE_INVALID (-10)#define XENMEM_SHARING_OP_C_HANDLE_INVALID (-9)
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v7 7/7 xen/tools: VM forking toolstack side
In reply to Tamas K LengyelAdd necessary bits to implement "xl fork-vm" commands. The command allows the user to specify how to launch the device model allowing for a late-launch model in which the user can execute the fork without the device model and decide to only later launch it.
--- docs/man/xl.1.pod.in | 36 +++++ tools/libxc/include/xenctrl.h | 13 ++ tools/libxc/xc_memshr.c | 22 +++ tools/libxl/libxl.h | 7 + tools/libxl/libxl_create.c | 256 ++++++++++++++++++++++------------ tools/libxl/libxl_dm.c | 2 +- tools/libxl/libxl_dom.c | 43 +++++- tools/libxl/libxl_internal.h | 1 + tools/libxl/libxl_types.idl | 1 + tools/xl/xl.h | 5 + tools/xl/xl_cmdtable.c | 12 ++ tools/xl/xl_saverestore.c | 95 +++++++++++++ tools/xl/xl_vmcontrol.c | 8 ++ 13 files changed, 407 insertions(+), 94 deletions(-)
docs/man/xl.1.pod.in +36 -0
@@ -694,6 +694,42 @@ Leave the domain paused after creating the snapshot. =back +=item B<fork-vm> [I<OPTIONS>] I<domain-id> + +Create a fork of a running VM. The domain will be paused after the operation +and needs to remain paused while forks of it exist. + +B<OPTIONS> + +=over 4 + +=item B<-p> + +Leave the fork paused after creating it. + +=item B<--launch-dm> + +Specify whether the device model (QEMU) should be launched for the fork. Late +launch allows to start the device model for an already running fork. + +=item B<-C> + +The config file to use when launching the device model. Currently required when +launching the device model. + +=item B<-Q> + +The qemu save file to use when launching the device model. Currently required +when launching the device model. + +=item B<--fork-reset> + +Perform a reset operation of an already running fork. Note that resetting may +be less performant then creating a new fork depending on how much memory the +fork has deduplicated during its runtime. + +=back + =item B<sharing> [I<domain-id>] Display the number of shared pages for a specified domain. If no domain is
tools/libxc/include/xenctrl.h +13 -0
@@ -2225,6 +2225,19 @@ int xc_memshr_range_share(xc_interface *xch,uint64_t first_gfn, uint64_t last_gfn); +int xc_memshr_fork (xc_interface *xch, +uint32_t source_domain, +uint32_t client_domain); + +/* +* Note: this function is only intended to be used on short-lived forks that +* haven't yet aquired a lot of memory. In case the fork has a lot of memory +* it is likely more performant to create a new fork with xc_memshr_fork. +* +* With VMs that have a lot of memory this call may block for a long time. +*/ +int xc_memshr_fork_reset (xc_interface *xch,uint32_t forked_domain); +/* Debug calls: return the number of pages referencing the shared frame backing * the input argument. Should be one or greater. *
tools/libxc/xc_memshr.c +22 -0
@@ -239,6 +239,28 @@ int xc_memshr_debug_gref(xc_interface *xch,return xc_memshr_memop (xch, domid, &mso); } +int xc_memshr_fork (xc_interface *xch,uint32_t pdomid,uint32_t domid) +{ +xen_mem_sharing_op_t mso; + +memset (&mso,0 ,sizeof (mso)); + + mso.op = XENMEM_sharing_op_fork; + mso.u.fork.parent_domain = pdomid; + +return xc_memshr_memop (xch, domid, &mso); +} + +int xc_memshr_fork_reset (xc_interface *xch,uint32_t domid) +{ +xen_mem_sharing_op_t mso; + +memset (&mso,0 ,sizeof (mso)); + mso.op = XENMEM_sharing_op_fork_reset; + +return xc_memshr_memop (xch, domid, &mso); +} +int xc_memshr_audit (xc_interface *xch) {xen_mem_sharing_op_t mso;
tools/libxl/libxl.h +7 -0
@@ -1538,6 +1538,13 @@ int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config,const libxl_asyncop_how *ao_how, const libxl_asyncprogress_how *aop_console_how)LIBXL_EXTERNAL_CALLERS_ONLY ; +int libxl_domain_fork_vm(libxl_ctx *ctx, uint32_t pdomid, uint32_t *domid) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_domain_fork_launch_dm(libxl_ctx *ctx, libxl_domain_config *d_config, + uint32_t domid, + const libxl_asyncprogress_how *aop_console_how) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_domain_fork_reset (libxl_ctx *ctx,uint32_t domid); int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config, uint32_t *domid, int restore_fd, int send_back_fd,
tools/libxl/libxl_create.c +170 -86
365 lines not on this page · raw message
tools/libxl/libxl_dm.c +1 -1
@@ -2787,7 +2787,7 @@ static void device_model_spawn_outcome(libxl__egc *egc,libxl__domain_build_state *state = dmss->build_state; -if (state->saved_state) { +if (state->saved_state && !state->forked_vm) { ret2 =unlink (state->saved_state);if (ret2) { LOGED(ERROR, dmss->guest_domid, "%s: failed to remove device-model state %s",
tools/libxl/libxl_dom.c +36 -7
105 lines not on this page · raw message
tools/libxl/libxl_internal.h +1 -0
@@ -1374,6 +1374,7 @@ typedef struct {char *saved_state;int dm_monitor_fd; +bool forked_vm;libxl__file_reference pv_kernel;libxl__file_reference pv_ramdisk;
tools/libxl/libxl_types.idl +1 -0
@@ -956,6 +956,7 @@ libxl_domain_config = Struct("domain_config", [ ("on_watchdog", libxl_action_on_shutdown), ("on_crash", libxl_action_on_shutdown), ("on_soft_reset", libxl_action_on_shutdown), + ("dm_restore_file", string, {'const': True}), ], dir=DIR_IN) libxl_diskinfo = Struct("diskinfo", [
tools/xl/xl.h +5 -0
@@ -31,6 +31,7 @@ struct cmd_spec { };struct domain_create { +uint32_t ddomid;/* fork launch dm for this domid */ int debug;int daemonize;int monitor;/* handle guest reboots etc */
@@ -45,6 +46,7 @@ struct domain_create {const char *config_file;char *extra_config;/* extra config string */ const char *restore_file; +const char *dm_restore_file;char *colo_proxy_script;bool userspace_colo_proxy;int migrate_fd;/* -1 means none */
@@ -127,6 +129,9 @@ int main_pciassignable_remove(int argc, char **argv);int main_pciassignable_list (int argc,char **argv);#ifndef LIBXL_HAVE_NO_SUSPEND_RESUME int main_restore (int argc,char **argv); +int main_fork_vm (int argc,char **argv); +int main_fork_launch_dm (int argc,char **argv); +int main_fork_reset (int argc,char **argv);int main_migrate_receive (int argc,char **argv);int main_save (int argc,char **argv);int main_migrate (int argc,char **argv);
tools/xl/xl_cmdtable.c +12 -0
@@ -185,6 +185,18 @@ struct cmd_spec cmd_table[] = { "Restore a domain from a saved state", "- for internal use only", }, + { "fork-vm", + &main_fork_vm, 0, 1, + "Fork a domain from the running parent domid", + "[options] <Domid>", + "-h Print this help.\n" + "-C <config> Use config file for VM fork.\n" + "-Q <qemu-save-file> Use qemu save file for VM fork.\n" + "--launch-dm <yes|no|late> Launch device model (QEMU) for VM fork.\n" + "--fork-reset Reset VM fork.\n" + "-p Do not unpause fork VM after operation.\n" + "-d Enable debug messages.\n" + }, #endif { "dump-core", &main_dump_core, 0, 1,
tools/xl/xl_saverestore.c +95 -0
101 lines not on this page · raw message
tools/xl/xl_vmcontrol.c +8 -0
@@ -645,6 +645,7 @@ int create_domain(struct domain_create *dom_info)libxl_domain_config d_config; +uint32_t ddomid = dom_info->ddomid;// launch dm for this domain iff set int debug = dom_info->debug;int daemonize = dom_info->daemonize;int monitor = dom_info->monitor;
@@ -655,6 +656,7 @@ int create_domain(struct domain_create *dom_info)const char *restore_file = dom_info->restore_file;const char *config_source =NULL ;const char *restore_source =NULL ; +const char *dm_restore_file = dom_info->dm_restore_file;int migrate_fd = dom_info->migrate_fd;bool config_in_json;
@@ -923,6 +925,12 @@ start:* restore/migrate-receive it again. */ restoring =0 ; + }else if ( ddomid ) { + d_config.dm_restore_file = dm_restore_file; + ret =libxl_domain_fork_launch_dm (ctx, &d_config, ddomid, + autoconnect_console_how); + domid = ddomid; + ddomid =INVALID_DOMID ; }else if (domid_soft_reset !=INVALID_DOMID ) {/* Do soft reset. */ ret = libxl_domain_soft_reset(ctx, &d_config, domid_soft_reset,
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v7 5/7 xen/mem_sharing: VM forking
In reply to Tamas K LengyelVM forking is the process of creating a domain with an empty memory space and a parent domain specified from which to populate the memory when necessary. For the new domain to be functional the VM state is copied over as part of the fork operation (HVM params, hap allocation, etc).
--- xen/arch/x86/domain.c | 11 ++ xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/mm/mem_sharing.c | 221 ++++++++++++++++++++++++++++++ xen/arch/x86/mm/p2m.c | 11 +- xen/include/asm-x86/mem_sharing.h | 17 +++ xen/include/public/memory.h | 5 + xen/include/xen/sched.h | 2 + 7 files changed, 267 insertions(+), 2 deletions(-)
xen/arch/x86/domain.c +11 -0
@@ -2189,6 +2189,17 @@ int domain_relinquish_resources(struct domain *d) ret =relinquish_shared_pages (d);if ( ret )return ret; + +/* +* If the domain is forked, decrement the parent's pause count +* and release the domain. +*/ +if ( d->parent ) + { +domain_unpause (d->parent); +put_domain (d->parent); + d->parent =NULL ; + } }#endif
xen/arch/x86/hvm/hvm.c +1 -1
@@ -1915,7 +1915,7 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla, }#endif -/* Spurious fault? PoD and log-dirty also take this path. */ +/* Spurious fault? PoD, log-dirty and VM forking also take this path. */ if (p2m_is_ram (p2mt) ) { rc =1 ;
xen/arch/x86/mm/mem_sharing.c +221 -0
245 lines not on this page · raw message
xen/arch/x86/mm/p2m.c +10 -1
@@ -510,6 +510,14 @@ mfn_t __get_gfn_type_access(struct p2m_domain *p2m, unsigned long gfn_l, mfn = p2m->get_entry (p2m, gfn, t, a, q, page_order,NULL ); +/* Check if we need to fork the page */ +if ( (q &P2M_ALLOC ) &&p2m_is_hole (*t) && + !mem_sharing_fork_page (p2m->domain, gfn, !!(q &P2M_UNSHARE )) ) + { + mfn = p2m->get_entry (p2m, gfn, t, a, q, page_order,NULL ); + } + +/* Check if we need to unshare the page */ if ( (q &P2M_UNSHARE ) &&p2m_is_shared (*t) ) {ASSERT (p2m_is_hostp2m (p2m));
@@ -588,7 +596,8 @@ struct page_info *p2m_get_page_from_gfn(return page;/* Error path: not a suitable GFN at all */ -if ( !p2m_is_ram (*t) && !p2m_is_paging (*t) && !p2m_is_pod (*t) ) +if ( !p2m_is_ram (*t) && !p2m_is_paging (*t) && !p2m_is_pod (*t) && + !mem_sharing_is_fork (p2m->domain) )return NULL ; }
xen/include/asm-x86/mem_sharing.h +17 -0
@@ -39,6 +39,9 @@ struct mem_sharing_domain#define mem_sharing_enabled (d) ((d)->arch.hvm.mem_sharing.enabled) +#define mem_sharing_is_fork (d) \ + (mem_sharing_enabled(d) && !!((d)->parent)) +/* Auditing of memory sharing code? */ #ifndef NDEBUG #define MEM_SHARING_AUDIT 1
@@ -88,6 +91,9 @@ static inline int mem_sharing_unshare_page(struct domain *d,return rc; } +int mem_sharing_fork_page (struct domain *d,gfn_t gfn, +bool unsharing); +/* * If called by a foreign domain, possible errors are * -EBUSY -> ring full
@@ -117,6 +123,7 @@ int relinquish_shared_pages(struct domain *d);#else #define mem_sharing_enabled (d) false +#define mem_sharing_is_fork (p2m) falsestatic inline unsigned int mem_sharing_get_nr_saved_mfns (void ) {
@@ -141,6 +148,16 @@ static inline int mem_sharing_notify_enomem(struct domain *d, unsigned long gfn,return -EOPNOTSUPP ; } +static inline int mem_sharing_fork (struct domain *d,struct domain *cd,bool vcpu) +{ +return -EOPNOTSUPP ; +} + +static inline int mem_sharing_fork_page (struct domain *d,gfn_t gfn,bool lock) +{ +return -EOPNOTSUPP ; +} +#endif #endif /* __MEM_SHARING_H__ */
xen/include/public/memory.h +5 -0
@@ -482,6 +482,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_mem_access_op_t);#define XENMEM_sharing_op_add_physmap 6#define XENMEM_sharing_op_audit 7#define XENMEM_sharing_op_range_share 8 +#define XENMEM_sharing_op_fork 9#define XENMEM_SHARING_OP_S_HANDLE_INVALID (-10)#define XENMEM_SHARING_OP_C_HANDLE_INVALID (-9)
@@ -532,6 +533,10 @@ struct xen_mem_sharing_op {uint32_t gref;/* IN: gref to debug */ } u; } debug; +struct mem_sharing_op_fork { +domid_t parent_domain; +uint16_t _pad[3 ];/* Must be set to 0 */ + } fork; } u; };typedef struct xen_mem_sharing_op xen_mem_sharing_op_t ;
xen/include/xen/sched.h +2 -0
@@ -507,6 +507,8 @@ struct domain/* Memory sharing support */ #ifdef CONFIG_MEM_SHARING struct vm_event_domain *vm_event_share; +struct domain *parent;/* VM fork parent */ +bool parent_paused;#endif /* Memory paging support */ #ifdef CONFIG_HAS_MEM_PAGING
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v7 1/7] x86/p2m: Allow p2m_get_page_from_gfn to return shared entries
In reply to Tamas K LengyelQuoted 5 lines · Tamas K Lengyel
The owner domain of shared pages is
dom_cow, use that forget_pageotherwise the function fails to return the correct page under some situations. The check ifdom_cowshould be used was only performed in a subset of use-cases. Fixing the error and simplifying the existing check since we can't have any shared entries withdom_cowbeing NULL.
Better, thanks.
Quoted 14 lines
Signed-off-by Tamas K Lengyel <[email protected]>---
v7: update commit message--- xen/arch/x86/mm/p2m.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)xen/arch/x86/mm/p2m.c +0
-0@@ -575,11 +575,12 @@ struct page_info *p2m_get_page_from_gfn(if ( fdom ==NULL ) page =NULL ;
xen/arch/x86/mm/p2m.c struct page_info *p2m_get_page_from_gfn( · line 581
Quoted 10 lines
xen/arch/x86/mm/p2m.c +4
-5} -else if ( !get_page (page, p2m->domain) && -/* Page could be shared */ - (!dom_cow || !p2m_is_shared (*t) || - !get_page (page, dom_cow)) ) - page =NULL ; +else + { +struct domain *d = !p2m_is_shared (*t) ? p2m->domain : dom_cow; +if ( !get_page (page, d) )
There's still a blank line missing between these two lines and ...
xen/arch/x86/mm/p2m.c struct page_info *p2m_get_page_from_gfn( · line 600
Quoted 11 lines
xen/arch/x86/mm/p2m.c +3
-0+ page =NULL ; + } }p2m_read_unlock (p2m);@@ -595,8 +596,9 @@ struct page_info *p2m_get_page_from_gfn( mfn =get_gfn_type_access (p2m,gfn_x (gfn), t, a, q,NULL );if (p2m_is_ram (*t) &&mfn_valid (mfn) ) { +struct domain *d = !p2m_is_shared (*t) ? p2m->domain : dom_cow; page =mfn_to_page (mfn);
... similarly between these two. As indicated before, with them added
despite me still thinking that the title suggests more of a problem than there really was. (Of course adding the missing blank lines ought to be easy enough while committing.)
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v7 4/7] x86/mem_sharing: use default_access in add_to_physmap
In reply to Tamas K LengyelQuoted 8 lines · Tamas K Lengyel
When plugging a hole in the target physmap don't use the access permission returned by
__get_gfn_type_accessas it is non-sensical (p2m_access_n) in the use-caseadd_to_physmapwas intended to be used in. It leads tovm_eventsbeing sent out for access violations at unexpected locations. Make use ofp2m->default_accessinstead and document the ambiguity surrounding "hole" types and corner-cases with custommem_accessbeing set on holes.Signed-off-by Tamas K Lengyel <[email protected]>
Quoted 2 lines
---
v7: add detailed comment explaining the issue and why this fix is correct
Thanks for this addition.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v7 1/7] x86/p2m: Allow p2m_get_page_from_gfn to return shared entries
In reply to Jan BeulichQuoted 51 lines · Jan Beulich
Quoted 5 lines · Tamas K Lengyel
The owner domain of shared pages is
dom_cow, use that forget_pageotherwise the function fails to return the correct page under some situations. The check ifdom_cowshould be used was only performed in a subset of use-cases. Fixing the error and simplifying the existing check since we can't have any shared entries withdom_cowbeing NULL.Better, thanks.
Quoted 14 lines
Signed-off-by Tamas K Lengyel <[email protected]>---
v7: update commit message--- xen/arch/x86/mm/p2m.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)xen/arch/x86/mm/p2m.c +0
-0@@ -575,11 +575,12 @@ struct page_info *p2m_get_page_from_gfn(if ( fdom ==NULL ) page =NULL ;xen/arch/x86/mm/p2m.c struct page_info *p2m_get_page_from_gfn( · line 581
Quoted 10 lines
xen/arch/x86/mm/p2m.c +4
-5} -else if ( !get_page (page, p2m->domain) && -/* Page could be shared */ - (!dom_cow || !p2m_is_shared (*t) || - !get_page (page, dom_cow)) ) - page =NULL ; +else + { +struct domain *d = !p2m_is_shared (*t) ? p2m->domain : dom_cow; +if ( !get_page (page, d) )There's still a blank line missing between these two lines and ...
xen/arch/x86/mm/p2m.c struct page_info *p2m_get_page_from_gfn( · line 600
Quoted 11 lines
xen/arch/x86/mm/p2m.c +3
-0+ page =NULL ; + } }p2m_read_unlock (p2m);@@ -595,8 +596,9 @@ struct page_info *p2m_get_page_from_gfn( mfn =get_gfn_type_access (p2m,gfn_x (gfn), t, a, q,NULL );if (p2m_is_ram (*t) &&mfn_valid (mfn) ) { +struct domain *d = !p2m_is_shared (*t) ? p2m->domain : dom_cow; page =mfn_to_page (mfn);... similarly between these two. As indicated before, with them added
Quoted 4 lines
Reviewed-by Jan Beulich <[email protected]>despite me still thinking that the title suggests more of a problem than there really was. (Of course adding the missing blank lines ought to be easy enough while committing.)
Thanks, I did forgot to add those extra lines. To me this looks fine as-is so it just doesn't come to mind naturally.
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v7 2/7] x86/hvm: introduce hvm_copy_context_and_params
In reply to Tamas K LengyelQuoted 15 lines · Tamas K Lengyel
xen/arch/x86/hvm/hvm.c +11
-0@@ -4414,6 +4424,40 @@ static int hvm_allow_get_param(struct domain *d,return rc; } +static int hvm_get_param (struct domain *d,uint32_t index,uint64_t *value) +{ +int rc; + + rc =hvm_allow_get_param (d, index); +if ( rc ) +return rc; + +switch ( index ) + { +case HVM_PARAM_ACPI_S_STATE :
xen/arch/x86/hvm/hvm.c static int hvm_allow_get_param(struct domain *d, · line 4447
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+ *value = d->arch.hvm.is_s3_suspended ?3 :0 ; +break ; + +case HVM_PARAM_VM86_TSS : + *value = (uint32_t )d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED ]; +break ; + +case HVM_PARAM_VM86_TSS_SIZED : + *value = d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED ] & + ~VM86_TSS_UPDATED ;
Indentation got broken here.
xen/arch/x86/hvm/hvm.c static int hvm_allow_get_param(struct domain *d, · line 4453
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +6
-0+break ; + +case HVM_PARAM_X87_FIP_WIDTH : + *value = d->arch.x87_fip_width; +break ; +default :
A blank line would have wanted introducing above here.
xen/arch/x86/hvm/hvm.c void hvm_set_segment_register(struct vcpu *v, enum x86_segment seg, · line 5326
Quoted 11 lines
xen/arch/x86/hvm/hvm.c +7
-0@@ -5301,6 +5317,37 @@ void hvm_set_segment_register(struct vcpu *v, enum x86_segment seg,alternative_vcall (hvm_funcs.set_segment_register, v, seg, reg); } +int hvm_copy_context_and_params (struct domain *dst,struct domain *src) +{ +int rc; +unsigned int i; +struct hvm_domain_context c = { }; + + c.size =hvm_save_size (src);
As mentioned in an earlier version's review, this could be put in the variable's initializer.
I'll take care of all of the above and add
while committing.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v7 2/7] x86/hvm: introduce hvm_copy_context_and_params
Quoted 54 lines · Jan Beulich
Quoted 15 lines · Tamas K Lengyel
xen/arch/x86/hvm/hvm.c +11
-0@@ -4414,6 +4424,40 @@ static int hvm_allow_get_param(struct domain *d,return rc; } +static int hvm_get_param (struct domain *d,uint32_t index,uint64_t *value) +{ +int rc; + + rc =hvm_allow_get_param (d, index); +if ( rc ) +return rc; + +switch ( index ) + { +case HVM_PARAM_ACPI_S_STATE :xen/arch/x86/hvm/hvm.c static int hvm_allow_get_param(struct domain *d, · line 4447
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+ *value = d->arch.hvm.is_s3_suspended ?3 :0 ; +break ; + +case HVM_PARAM_VM86_TSS : + *value = (uint32_t )d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED ]; +break ; + +case HVM_PARAM_VM86_TSS_SIZED : + *value = d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED ] & + ~VM86_TSS_UPDATED ;Indentation got broken here.
xen/arch/x86/hvm/hvm.c static int hvm_allow_get_param(struct domain *d, · line 4453
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +6
-0+break ; + +case HVM_PARAM_X87_FIP_WIDTH : + *value = d->arch.x87_fip_width; +break ; +default :A blank line would have wanted introducing above here.
xen/arch/x86/hvm/hvm.c void hvm_set_segment_register(struct vcpu *v, enum x86_segment seg, · line 5326
Quoted 11 lines
xen/arch/x86/hvm/hvm.c +7
-0@@ -5301,6 +5317,37 @@ void hvm_set_segment_register(struct vcpu *v, enum x86_segment seg,alternative_vcall (hvm_funcs.set_segment_register, v, seg, reg); } +int hvm_copy_context_and_params (struct domain *dst,struct domain *src) +{ +int rc; +unsigned int i; +struct hvm_domain_context c = { }; + + c.size =hvm_save_size (src);As mentioned in an earlier version's review, this could be put in the variable's initializer.
Quoted 3 lines
I'll take care of all of the above and add
Reviewed-by Jan Beulich <[email protected]>while committing.
Thanks, it's appreciated.
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel