mem_sharing: allow forking domain with IOMMU enabled
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v15 1/3 mem_sharing: don't reset vCPU info page during fork reset
When a forked VM is being reset while having vm_events active, re-copying the vCPU info page can lead to events being lost. This seems to only affect a subset of events (interrupts), while not others (cpuid, MTF, EPT) thus it was not discovered beforehand. Only copying vCPU info page contents during initial fork fixes the problem.
--- xen/arch/x86/mm/mem_sharing.c | 50 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-)
xen/arch/x86/mm/mem_sharing.c +25 -25
@@ -1534,28 +1534,6 @@ int mem_sharing_fork_page(struct domain *d, gfn_t gfn, bool unsharing) p2m->default_access, -1); } -static int bring_up_vcpus (struct domain *cd,struct domain *d) -{ -unsigned int i; -int ret = -EINVAL ; - -if ( d->max_vcpus != cd->max_vcpus || - (ret =cpupool_move_domain (cd, d->cpupool)) ) -return ret; - -for ( i =0 ; i < cd->max_vcpus; i++ ) - { -if ( !d->vcpu[i] || cd->vcpu[i] ) -continue ; - -if ( !vcpu_create (cd, i) ) -return -EINVAL ; - } - -domain_update_node_affinity (cd); -return 0 ; -} -static int copy_vcpu_settings (struct domain *cd,const struct domain *d) {unsigned int i;
@@ -1614,6 +1592,31 @@ static int copy_vcpu_settings(struct domain *cd, const struct domain *d)return 0 ; } +static int bring_up_vcpus (struct domain *cd,struct domain *d) +{ +unsigned int i; +int ret = -EINVAL ; + +if ( d->max_vcpus != cd->max_vcpus || + (ret =cpupool_move_domain (cd, d->cpupool)) ) +return ret; + +for ( i =0 ; i < cd->max_vcpus; i++ ) + { +if ( !d->vcpu[i] || cd->vcpu[i] ) +continue ; + +if ( !vcpu_create (cd, i) ) +return -EINVAL ; + } + +if ( (ret =copy_vcpu_settings (cd, d)) ) +return ret; + +domain_update_node_affinity (cd); +return 0 ; +} +static int fork_hap_allocation (struct domain *cd,struct domain *d) {int rc;
@@ -1697,9 +1700,6 @@ static int copy_settings(struct domain *cd, struct domain *d) {int rc; -if ( (rc =copy_vcpu_settings (cd, d)) ) -return rc; -if ( (rc =hvm_copy_context_and_params (cd, d)) )return rc;
Signature · 1 line
2.20.1
Re: [PATCH v15 1/3] mem_sharing: don't reset vCPU info page during fork reset
Quoted 3 lines · Tamas K Lengyel
When a forked VM is being reset while having
vm_eventsactive, re-copying the vCPU info page can lead to events being lost. This seems to only affect a subset of events (interrupts), while not others (cpuid, MTF, EPT) thus it was
I'm slightly lost by the sentence, is the guest or the hypervisor the one losing events?
Ie: interrupts are events from a guest PoV, but cpuid or EPT is not something that triggers events that are injected to the guest. I think the commit message needs clarification.
Quoted 2 lines
not discovered beforehand. Only copying vCPU info page contents during initial fork fixes the problem.
Hm, I'm not sure I understand why this is causing issues. When you reset a fork you should reset the vcpu info page, or else event masks would be in a wrong state?
Quoted 57 lines
Signed-off-by Tamas K Lengyel <[email protected]>--- xen/arch/x86/mm/mem_sharing.c | 50 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-)xen/arch/x86/mm/mem_sharing.c +14
-22@@ -1534,28 +1534,6 @@ int mem_sharing_fork_page(struct domain *d, gfn_t gfn, bool unsharing) p2m->default_access, -1); } -static int bring_up_vcpus (struct domain *cd,struct domain *d) -{ -unsigned int i; -int ret = -EINVAL ; - -if ( d->max_vcpus != cd->max_vcpus || - (ret =cpupool_move_domain (cd, d->cpupool)) ) -return ret; - -for ( i =0 ; i < cd->max_vcpus; i++ ) - { -if ( !d->vcpu[i] || cd->vcpu[i] ) -continue ; - -if ( !vcpu_create (cd, i) ) -return -EINVAL ; - } - -domain_update_node_affinity (cd); -return 0 ; -} -static int copy_vcpu_settings (struct domain *cd,const struct domain *d) {unsigned int i;@@ -1614,6 +1592,31 @@ static int copy_vcpu_settings(struct domain *cd, const struct domain *d)return 0 ; } +static int bring_up_vcpus (struct domain *cd,struct domain *d) +{ +unsigned int i; +int ret = -EINVAL ; + +if ( d->max_vcpus != cd->max_vcpus || + (ret =cpupool_move_domain (cd, d->cpupool)) ) +return ret; + +for ( i =0 ; i < cd->max_vcpus; i++ ) + { +if ( !d->vcpu[i] || cd->vcpu[i] ) +continue ; +
xen/arch/x86/mm/mem_sharing.c static int copy_vcpu_settings(struct domain *cd, const struct domain *d) · line 1618
Quoted 10 lines
xen/arch/x86/mm/mem_sharing.c +10
-0+if ( !vcpu_create (cd, i) ) +return -EINVAL ; + } + +if ( (ret =copy_vcpu_settings (cd, d)) ) +return ret; + +domain_update_node_affinity (cd); +return 0 ; +}
I would prefer the code movement to be in a different patch: it makes it more difficult to spot non-functional changes being made while moving the function around.
Thanks, Roger.
Re: [PATCH v15 1/3] mem_sharing: don't reset vCPU info page during fork reset
Quoted 6 lines · Roger Pau Monné
Quoted 3 lines · Tamas K Lengyel
When a forked VM is being reset while having
vm_eventsactive, re-copying the vCPU info page can lead to events being lost. This seems to only affect a subset of events (interrupts), while not others (cpuid, MTF, EPT) thus it was
Quoted 6 lines
I'm slightly lost by the sentence, is the guest or the hypervisor the one losing events?
Ie: interrupts are events from a guest PoV, but cpuid or EPT is not something that triggers events that are injected to the guest. I think the commit message needs clarification.
Sorry, what I meant was software interrupts are not triggered anymore, ie. int3 and it's associated event is not sent to the monitor application (VM_EVENT_REASON_SOFTWARE_BREAKPOINT).
Quoted 7 lines
Quoted 3 lines
not discovered beforehand. Only copying vCPU info page contents during initial fork fixes the problem.
Hm, I'm not sure I understand why this is causing issues. When you reset a fork you should reset the vcpu info page, or else event masks would be in a wrong state?
When we reset a fork we only want to 1) discard any memory allocated for it 2) reset the vCPU registers. We don't want to reset event channels or anything else. We have active vm_events on the domain and the whole point of doing a fork reset is to avoid having to reinitialize all that as it's quite slow.
Quoted 63 lines
Quoted 63 lines
Signed-off-by Tamas K Lengyel <[email protected]>--- xen/arch/x86/mm/mem_sharing.c | 50 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-)xen/arch/x86/mm/mem_sharing.c +20
-22@@ -1534,28 +1534,6 @@ int mem_sharing_fork_page(struct domain *d, gfn_t gfn, bool unsharing) p2m->default_access, -1); } -static int bring_up_vcpus (struct domain *cd,struct domain *d) -{ -unsigned int i; -int ret = -EINVAL ; - -if ( d->max_vcpus != cd->max_vcpus || - (ret =cpupool_move_domain (cd, d->cpupool)) ) -return ret; - -for ( i =0 ; i < cd->max_vcpus; i++ ) - { -if ( !d->vcpu[i] || cd->vcpu[i] ) -continue ; - -if ( !vcpu_create (cd, i) ) -return -EINVAL ; - } - -domain_update_node_affinity (cd); -return 0 ; -} -static int copy_vcpu_settings (struct domain *cd,const struct domain *d) {unsigned int i;@@ -1614,6 +1592,31 @@ static int copy_vcpu_settings(struct domain *cd, const struct domain *d)return 0 ; } +static int bring_up_vcpus (struct domain *cd,struct domain *d) +{ +unsigned int i; +int ret = -EINVAL ; + +if ( d->max_vcpus != cd->max_vcpus || + (ret =cpupool_move_domain (cd, d->cpupool)) ) +return ret; + +for ( i =0 ; i < cd->max_vcpus; i++ ) + { +if ( !d->vcpu[i] || cd->vcpu[i] ) +continue ; + +if ( !vcpu_create (cd, i) ) +return -EINVAL ; + } + +if ( (ret =copy_vcpu_settings (cd, d)) ) +return ret;
Quoted 8 lines
xen/arch/x86/mm/mem_sharing.c static int copy_vcpu_settings(struct domain *cd, const struct domain *d) · line 1618
Quoted 4 lines
xen/arch/x86/mm/mem_sharing.c +4
-0+ +domain_update_node_affinity (cd); +return 0 ; +}I would prefer the code movement to be in a different patch: it makes it more difficult to spot non-functional changes being made while moving the function around.
I don't think it's worth splitting this patch because of that. The patch is quite small an the move is trivial to allow the function bring_up_vcpus be able to call copy_vcpu_settings without having to pre-declare that function.
Tamas
Re: [PATCH v15 1/3] mem_sharing: don't reset vCPU info page during fork reset
Quoted 26 lines · Tamas K Lengyel
Quoted 6 lines · Roger Pau Monné
Quoted 3 lines · Tamas K Lengyel
When a forked VM is being reset while having
vm_eventsactive, re-copying the vCPU info page can lead to events being lost. This seems to only affect a subset of events (interrupts), while not others (cpuid, MTF, EPT) thus it wasQuoted 6 lines
I'm slightly lost by the sentence, is the guest or the hypervisor the one losing events?
Ie: interrupts are events from a guest PoV, but cpuid or EPT is not something that triggers events that are injected to the guest. I think the commit message needs clarification.
Sorry, what I meant was software interrupts are not triggered anymore, ie. int3 and it's associated event is not sent to the monitor application (
VM_EVENT_REASON_SOFTWARE_BREAKPOINT).Quoted 7 lines
Quoted 3 lines
not discovered beforehand. Only copying vCPU info page contents during initial fork fixes the problem.
Hm, I'm not sure I understand why this is causing issues. When you reset a fork you should reset the vcpu info page, or else event masks would be in a wrong state?
Quoted 5 lines
When we reset a fork we only want to 1) discard any memory allocated for it 2) reset the vCPU registers. We don't want to reset event channels or anything else. We have active
vm_eventson the domain and the whole point of doing a fork reset is to avoid having to reinitialize all that as it's quite slow.
So for an arbitrary piece of state, what are the criteria to establish whether to copy or re-init them during a fork? Is it really now and forever only memory that wants resetting? I have to admit I'm confused by you also mentioning CPU registers - aren't they to be copied rather than reset?
Jan
Re: [PATCH v15 1/3] mem_sharing: don't reset vCPU info page during fork reset
Quoted 34 lines · Jan Beulich
Quoted 26 lines · Tamas K Lengyel
Quoted 6 lines · Roger Pau Monné
Quoted 3 lines · Tamas K Lengyel
When a forked VM is being reset while having
vm_eventsactive, re-copying the vCPU info page can lead to events being lost. This seems to only affect a subset of events (interrupts), while not others (cpuid, MTF, EPT) thus it wasQuoted 6 lines
I'm slightly lost by the sentence, is the guest or the hypervisor the one losing events?
Ie: interrupts are events from a guest PoV, but cpuid or EPT is not something that triggers events that are injected to the guest. I think the commit message needs clarification.
Sorry, what I meant was software interrupts are not triggered anymore, ie. int3 and it's associated event is not sent to the monitor application (
VM_EVENT_REASON_SOFTWARE_BREAKPOINT).Quoted 7 lines
Quoted 3 lines
not discovered beforehand. Only copying vCPU info page contents during initial fork fixes the problem.
Hm, I'm not sure I understand why this is causing issues. When you reset a fork you should reset the vcpu info page, or else event masks would be in a wrong state?
Quoted 5 lines
When we reset a fork we only want to 1) discard any memory allocated for it 2) reset the vCPU registers. We don't want to reset event channels or anything else. We have active
vm_eventson the domain and the whole point of doing a fork reset is to avoid having to reinitialize all that as it's quite slow.
Quoted 5 lines
So for an arbitrary piece of state, what are the criteria to establish whether to copy or re-init them during a fork? Is it really now and forever only memory that wants resetting? I have to admit I'm confused by you also mentioning CPU registers - aren't they to be copied rather than reset?
Registers are being reset by copying them from the parent. Allocated memory is discarded as the memory that's needed for the new execution will get copied when EPT faults happen as it's executing. The goal is to put the domain back to its initial execution state without having to reinitialize vm_events. In our experiments when the forks are executed only for a very short period (fuzzing), having to reinitialize the vm_event interfaces mean going from ~100 execution/s to ~2 executions/s. Unfortunately in the current state the fork doesn't generate the required vm_events after the first execution and for some reason it only happens for int3 generated events.
Tamas
Re: [PATCH v15 1/3] mem_sharing: don't reset vCPU info page during fork reset
Quoted 41 lines · Tamas K Lengyel
Quoted 34 lines · Jan Beulich
Quoted 26 lines · Tamas K Lengyel
Quoted 6 lines · Roger Pau Monné
Quoted 3 lines · Tamas K Lengyel
When a forked VM is being reset while having
vm_eventsactive, re-copying the vCPU info page can lead to events being lost. This seems to only affect a subset of events (interrupts), while not others (cpuid, MTF, EPT) thus it wasQuoted 6 lines
I'm slightly lost by the sentence, is the guest or the hypervisor the one losing events?
Ie: interrupts are events from a guest PoV, but cpuid or EPT is not something that triggers events that are injected to the guest. I think the commit message needs clarification.
Sorry, what I meant was software interrupts are not triggered anymore, ie. int3 and it's associated event is not sent to the monitor application (
VM_EVENT_REASON_SOFTWARE_BREAKPOINT).Quoted 7 lines
Quoted 3 lines
not discovered beforehand. Only copying vCPU info page contents during initial fork fixes the problem.
Hm, I'm not sure I understand why this is causing issues. When you reset a fork you should reset the vcpu info page, or else event masks would be in a wrong state?
Quoted 5 lines
When we reset a fork we only want to 1) discard any memory allocated for it 2) reset the vCPU registers. We don't want to reset event channels or anything else. We have active
vm_eventson the domain and the whole point of doing a fork reset is to avoid having to reinitialize all that as it's quite slow.Quoted 5 lines
So for an arbitrary piece of state, what are the criteria to establish whether to copy or re-init them during a fork? Is it really now and forever only memory that wants resetting? I have to admit I'm confused by you also mentioning CPU registers - aren't they to be copied rather than reset?
Quoted 10 lines
Registers are being reset by copying them from the parent. Allocated memory is discarded as the memory that's needed for the new execution will get copied when EPT faults happen as it's executing. The goal is to put the domain back to its initial execution state without having to reinitialize
vm_events. In our experiments when the forks are executed only for a very short period (fuzzing), having to reinitialize thevm_eventinterfaces mean going from ~100 execution/s to ~2 executions/s. Unfortunately in the current state the fork doesn't generate the requiredvm_eventsafter the first execution and for some reason it only happens for int3 generated events.
Thanks, but I'm afraid this doesn't answer my question regarding the criteria for what should be put back to the fork's initial state vs what should be left as is. In fact _anything_ not getting reset to initial state would seem to need special justification (beyond performance considerations).
Jan
Re: [PATCH v15 1/3] mem_sharing: don't reset vCPU info page during fork reset
Quoted 54 lines · Jan Beulich
Quoted 41 lines · Tamas K Lengyel
Quoted 34 lines · Jan Beulich
Quoted 26 lines · Tamas K Lengyel
Quoted 6 lines · Roger Pau Monné
Quoted 3 lines · Tamas K Lengyel
When a forked VM is being reset while having
vm_eventsactive, re-copying the vCPU info page can lead to events being lost. This seems to only affect a subset of events (interrupts), while not others (cpuid, MTF, EPT) thus it wasQuoted 6 lines
I'm slightly lost by the sentence, is the guest or the hypervisor the one losing events?
Ie: interrupts are events from a guest PoV, but cpuid or EPT is not something that triggers events that are injected to the guest. I think the commit message needs clarification.
Sorry, what I meant was software interrupts are not triggered anymore, ie. int3 and it's associated event is not sent to the monitor application (
VM_EVENT_REASON_SOFTWARE_BREAKPOINT).Quoted 7 lines
Quoted 3 lines
not discovered beforehand. Only copying vCPU info page contents during initial fork fixes the problem.
Hm, I'm not sure I understand why this is causing issues. When you reset a fork you should reset the vcpu info page, or else event masks would be in a wrong state?
Quoted 5 lines
When we reset a fork we only want to 1) discard any memory allocated for it 2) reset the vCPU registers. We don't want to reset event channels or anything else. We have active
vm_eventson the domain and the whole point of doing a fork reset is to avoid having to reinitialize all that as it's quite slow.Quoted 5 lines
So for an arbitrary piece of state, what are the criteria to establish whether to copy or re-init them during a fork? Is it really now and forever only memory that wants resetting? I have to admit I'm confused by you also mentioning CPU registers - aren't they to be copied rather than reset?
Quoted 10 lines
Registers are being reset by copying them from the parent. Allocated memory is discarded as the memory that's needed for the new execution will get copied when EPT faults happen as it's executing. The goal is to put the domain back to its initial execution state without having to reinitialize
vm_events. In our experiments when the forks are executed only for a very short period (fuzzing), having to reinitialize thevm_eventinterfaces mean going from ~100 execution/s to ~2 executions/s. Unfortunately in the current state the fork doesn't generate the requiredvm_eventsafter the first execution and for some reason it only happens for int3 generated events.
Quoted 5 lines
Thanks, but I'm afraid this doesn't answer my question regarding the criteria for what should be put back to the fork's initial state vs what should be left as is. In fact _anything_ not getting reset to initial state would seem to need special justification (beyond performance considerations).
From my PoV everything should be reset as long as it doesn't interfere with already registered vm_events. The only part that seems to interfere with the regular flow of events right now is the vcpu_info_mfn.
I've ran some further tests and seems that when the code that is being fuzzed is in ring3, int3 events are delivered as expected after a fork reset. But if the code in question is ring0, then the expected int3 is not delivered. It could entirely be that in the kernel-mode case the code takes a detour and the reason we don't see the expected int3 is not an interference with vm_events directly, rather a crash in the guest due to the vcpu_info_mfn being reset. In either case, it needs to be avoided.
Tamas
Tamas
Re: [PATCH v15 1/3] mem_sharing: don't reset vCPU info page during fork reset
Quoted 62 lines · Tamas K Lengyel
Quoted 54 lines · Jan Beulich
Quoted 41 lines · Tamas K Lengyel
Quoted 34 lines · Jan Beulich
Quoted 26 lines · Tamas K Lengyel
Quoted 6 lines · Roger Pau Monné
Quoted 3 lines · Tamas K Lengyel
When a forked VM is being reset while having
vm_eventsactive, re-copying the vCPU info page can lead to events being lost. This seems to only affect a subset of events (interrupts), while not others (cpuid, MTF, EPT) thus it wasQuoted 6 lines
I'm slightly lost by the sentence, is the guest or the hypervisor the one losing events?
Ie: interrupts are events from a guest PoV, but cpuid or EPT is not something that triggers events that are injected to the guest. I think the commit message needs clarification.
Sorry, what I meant was software interrupts are not triggered anymore, ie. int3 and it's associated event is not sent to the monitor application (
VM_EVENT_REASON_SOFTWARE_BREAKPOINT).Quoted 7 lines
Quoted 3 lines
not discovered beforehand. Only copying vCPU info page contents during initial fork fixes the problem.
Hm, I'm not sure I understand why this is causing issues. When you reset a fork you should reset the vcpu info page, or else event masks would be in a wrong state?
Quoted 5 lines
When we reset a fork we only want to 1) discard any memory allocated for it 2) reset the vCPU registers. We don't want to reset event channels or anything else. We have active
vm_eventson the domain and the whole point of doing a fork reset is to avoid having to reinitialize all that as it's quite slow.Quoted 5 lines
So for an arbitrary piece of state, what are the criteria to establish whether to copy or re-init them during a fork? Is it really now and forever only memory that wants resetting? I have to admit I'm confused by you also mentioning CPU registers - aren't they to be copied rather than reset?
Quoted 10 lines
Registers are being reset by copying them from the parent. Allocated memory is discarded as the memory that's needed for the new execution will get copied when EPT faults happen as it's executing. The goal is to put the domain back to its initial execution state without having to reinitialize
vm_events. In our experiments when the forks are executed only for a very short period (fuzzing), having to reinitialize thevm_eventinterfaces mean going from ~100 execution/s to ~2 executions/s. Unfortunately in the current state the fork doesn't generate the requiredvm_eventsafter the first execution and for some reason it only happens for int3 generated events.Quoted 5 lines
Thanks, but I'm afraid this doesn't answer my question regarding the criteria for what should be put back to the fork's initial state vs what should be left as is. In fact _anything_ not getting reset to initial state would seem to need special justification (beyond performance considerations).
Quoted 4 lines
From my PoV everything should be reset as long as it doesn't interfere with already registered
vm_events. The only part that seems to interfere with the regular flow of events right now is thevcpu_info_mfn.
Alright, I figured out what's really happening here. During fork reset we iterate over all pages belonging to the fork, releasing all pages that pass p2m_is_sharable(p2mt) check. Unfortunately the vcpu info pages also pass this check. Because of that the pages are removed from the p2m but remain mapped to the vcpu structs. No wonder this was causing all sorts of weirdness, if the guest tries to access the vcpu info pages it would cause endless pagefaults, which would manifest as events no longer appearing as expected (in this case the int3 event). Re-copying the vcpu info page's content from the parent is perfectly fine during reset, that causes no issues if the pages remain in the p2m. I'll be sending a different patch that fixes this bug and with a better commit message.
Tamas
PATCH v15 2/3 mem_sharing: allow forking domain with IOMMU enabled
In reply to a message not in the archiveThe memory sharing subsystem by default doesn't allow a domain to share memory if it has an IOMMU active for obvious security reasons. However, when fuzzing a VM fork, the same security restrictions don't necessarily apply. While it makes no sense to try to create a full fork of a VM that has an IOMMU attached as only one domain can own the pass-through device at a time, creating a shallow fork without a device model is still very useful for fuzzing kernel-mode drivers.
By allowing the parent VM to initialize the kernel-mode driver with a real device that's pass-through, the driver can enter into a state more suitable for fuzzing. Some of these initialization steps are quite complex and are easier to perform when a real device is present. After the initialization, shallow forks can be utilized for fuzzing code-segments in the device driver that don't directly interact with the device.
--- xen/arch/x86/mm/mem_sharing.c | 18 ++++++++++++------ xen/include/public/memory.h | 4 +++- 2 files changed, 15 insertions(+), 7 deletions(-)
xen/arch/x86/mm/mem_sharing.c +12 -6
@@ -1430,7 +1430,8 @@ static int range_share(struct domain *d, struct domain *cd,return rc; } -static inline int mem_sharing_control (struct domain *d,bool enable) +static inline int mem_sharing_control (struct domain *d,bool enable, +bool allow_iommu) {if ( enable ) {
@@ -1440,7 +1441,7 @@ static inline int mem_sharing_control(struct domain *d, bool enable)if (unlikely (!hap_enabled (d)) )return -ENODEV ; -if (unlikely (is_iommu_enabled (d)) ) +if (unlikely (!allow_iommu &&is_iommu_enabled (d)) )return -EXDEV ; }
@@ -1827,7 +1828,8 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)if ( rc ) goto out; -if ( !mem_sharing_enabled (d) && (rc =mem_sharing_control (d, true)) ) +if ( !mem_sharing_enabled (d) && + (rc =mem_sharing_control (d, true, false)) )return rc; switch ( mso.op )
@@ -2063,9 +2065,10 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)case XENMEM_sharing_op_fork: {struct domain *pd; +bool allow_iommu; rc = -EINVAL ; -if ( mso.u.fork.pad[0 ] || mso.u.fork.pad[1 ] || mso.u.fork.pad[2 ] ) +if ( mso.u.fork.pad[0 ] || mso.u.fork.pad[1 ] ) goto out; rc = rcu_lock_live_remote_domain_by_id(mso.u.fork.parent_domain,
@@ -2080,7 +2083,10 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) goto out; } -if ( !mem_sharing_enabled (pd) && (rc =mem_sharing_control (pd, true)) ) + allow_iommu = mso.u.fork.flags &XENMEM_FORK_WITH_IOMMU_ALLOWED ; + +if ( !mem_sharing_enabled (pd) && + (rc =mem_sharing_control (pd, true, allow_iommu)) ) {rcu_unlock_domain (pd); goto out;
@@ -2138,7 +2144,7 @@ int mem_sharing_domctl(struct domain *d, struct xen_domctl_mem_sharing_op *mec)switch ( mec->op ) {case XEN_DOMCTL_MEM_SHARING_CONTROL : - rc =mem_sharing_control (d, mec->u.enable); + rc =mem_sharing_control (d, mec->u.enable, false);break ;default :
xen/include/public/memory.h +3 -1
@@ -536,7 +536,9 @@ struct xen_mem_sharing_op { } debug;struct mem_sharing_op_fork {/* OP_FORK */ domid_t parent_domain;/* IN: parent's domain id */ -uint16_t pad[3 ];/* Must be set to 0 */ +#define XENMEM_FORK_WITH_IOMMU_ALLOWED 1/* Allow forking domain with IOMMU */ +uint16_t flags;/* IN: optional settings */ +uint16_t pad[2 ];/* Must be set to 0 */ } fork; } u; };
Signature · 1 line
2.20.1
Quoted 9 lines · Tamas K Lengyel
The memory sharing subsystem by default doesn't allow a domain to share memory if it has an IOMMU active for obvious security reasons. However, when fuzzing a VM fork, the same security restrictions don't necessarily apply. While it makes no sense to try to create a full fork of a VM that has an IOMMU attached as only one domain can own the pass-through device at a time, creating a shallow fork without a device model is still very useful for fuzzing kernel-mode drivers.
By allowing the parent VM to initialize the kernel-mode driver with a real device that's pass-through, the driver can enter into a state more suitable for
^ passed
Quoted 4 lines
fuzzing. Some of these initialization steps are quite complex and are easier to perform when a real device is present. After the initialization, shallow forks can be utilized for fuzzing code-segments in the device driver that don't directly interact with the device.
If I understand this correctly, the forked VM won't have an IOMMU setup, and the only domain allowed to interact with the device would be the parent?
Quoted 22 lines
Signed-off-by Tamas K Lengyel <[email protected]>--- xen/arch/x86/mm/mem_sharing.c | 18 ++++++++++++------ xen/include/public/memory.h | 4 +++- 2 files changed, 15 insertions(+), 7 deletions(-)xen/arch/x86/mm/mem_sharing.c +2
-1@@ -1430,7 +1430,8 @@ static int range_share(struct domain *d, struct domain *cd,return rc; } -static inline int mem_sharing_control (struct domain *d,bool enable) +static inline int mem_sharing_control (struct domain *d,bool enable, +bool allow_iommu) {if ( enable ) {
xen/arch/x86/mm/mem_sharing.c static inline int mem_sharing_control(struct domain *d, bool enable) · line 1444
Quoted 5 lines
xen/arch/x86/mm/mem_sharing.c +1
-1@@ -1440,7 +1441,7 @@ static inline int mem_sharing_control(struct domain *d, bool enable)if (unlikely (!hap_enabled (d)) )return -ENODEV ; -if (unlikely (is_iommu_enabled (d)) ) +if (unlikely (!allow_iommu &&is_iommu_enabled (d)) )
Coding style (missing space)
Quoted 26 lines
xen/arch/x86/mm/mem_sharing.c +4
-2return -EXDEV ; }@@ -1827,7 +1828,8 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)if ( rc ) goto out; -if ( !mem_sharing_enabled (d) && (rc =mem_sharing_control (d, true)) ) +if ( !mem_sharing_enabled (d) && + (rc =mem_sharing_control (d, true, false)) )return rc; switch ( mso.op )@@ -2063,9 +2065,10 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)case XENMEM_sharing_op_fork: {struct domain *pd; +bool allow_iommu; rc = -EINVAL ; -if ( mso.u.fork.pad[0 ] || mso.u.fork.pad[1 ] || mso.u.fork.pad[2 ] ) +if ( mso.u.fork.pad[0 ] || mso.u.fork.pad[1 ] ) goto out; rc = rcu_lock_live_remote_domain_by_id(mso.u.fork.parent_domain,
xen/arch/x86/mm/mem_sharing.c int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) · line 2086
Quoted 5 lines
xen/arch/x86/mm/mem_sharing.c +1
-1@@ -2080,7 +2083,10 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) goto out; } -if ( !mem_sharing_enabled (pd) && (rc =mem_sharing_control (pd, true)) ) + allow_iommu = mso.u.fork.flags &XENMEM_FORK_WITH_IOMMU_ALLOWED ;
I'm not sure whether it is worth to extract the flags into booleans at this level. As you add more flags it might make sense to just pass the whole flags field to mem_sharing_control?
mem_sharing_memop itself doesn't need to know which flags are specified.
Quoted 20 lines
xen/arch/x86/mm/mem_sharing.c +4
-1+ +if ( !mem_sharing_enabled (pd) && + (rc =mem_sharing_control (pd, true, allow_iommu)) ) {rcu_unlock_domain (pd); goto out;@@ -2138,7 +2144,7 @@ int mem_sharing_domctl(struct domain *d, struct xen_domctl_mem_sharing_op *mec)switch ( mec->op ) {case XEN_DOMCTL_MEM_SHARING_CONTROL : - rc =mem_sharing_control (d, mec->u.enable); + rc =mem_sharing_control (d, mec->u.enable, false);break ;default :xen/include/public/memory.h +0
-0
xen/include/public/memory.h struct xen_mem_sharing_op { · line 539
Quoted 5 lines
xen/include/public/memory.h +1
-1@@ -536,7 +536,9 @@ struct xen_mem_sharing_op { } debug;struct mem_sharing_op_fork {/* OP_FORK */ domid_t parent_domain;/* IN: parent's domain id */ -uint16_t pad[3 ];/* Must be set to 0 */ +#define XENMEM_FORK_WITH_IOMMU_ALLOWED 1/* Allow forking domain with IOMMU */
Since this is a flags field, can you express this is as: (1u << 0).
xen/include/public/memory.h struct xen_mem_sharing_op { · line 541
Quoted 2 lines
xen/include/public/memory.h +2
-0+uint16_t flags;/* IN: optional settings */ +uint16_t pad[2 ];/* Must be set to 0 */
Nit: padding can be made a uint32_t now instead of an array of two uint16_t.
Or add an uint16_t between parent_domain and flags and make flags an uint32_t.
Thanks, Roger.
Quoted 12 lines · Roger Pau Monné
Quoted 9 lines · Tamas K Lengyel
The memory sharing subsystem by default doesn't allow a domain to share memory if it has an IOMMU active for obvious security reasons. However, when fuzzing a VM fork, the same security restrictions don't necessarily apply. While it makes no sense to try to create a full fork of a VM that has an IOMMU attached as only one domain can own the pass-through device at a time, creating a shallow fork without a device model is still very useful for fuzzing kernel-mode drivers.
By allowing the parent VM to initialize the kernel-mode driver with a real device that's pass-through, the driver can enter into a state more suitable for
^ passed
Quoted 8 lines
Quoted 4 lines
fuzzing. Some of these initialization steps are quite complex and are easier to perform when a real device is present. After the initialization, shallow forks can be utilized for fuzzing code-segments in the device driver that don't directly interact with the device.
If I understand this correctly, the forked VM won't have an IOMMU setup, and the only domain allowed to interact with the device would be the parent?
Correct, this mode would only be for forks that have no access to devices at all (--launch-dm no).
Quoted 26 lines
Quoted 26 lines
Signed-off-by Tamas K Lengyel <[email protected]>--- xen/arch/x86/mm/mem_sharing.c | 18 ++++++++++++------ xen/include/public/memory.h | 4 +++- 2 files changed, 15 insertions(+), 7 deletions(-)xen/arch/x86/mm/mem_sharing.c +2
-1@@ -1430,7 +1430,8 @@ static int range_share(struct domain *d, struct domain *cd,return rc; } -static inline int mem_sharing_control (struct domain *d,bool enable) +static inline int mem_sharing_control (struct domain *d,bool enable, +bool allow_iommu) {if ( enable ) {@@ -1440,7 +1441,7 @@ static inline int mem_sharing_control(struct domain *d, bool enable)if (unlikely (!hap_enabled (d)) )return -ENODEV ;
Quoted 4 lines
xen/arch/x86/mm/mem_sharing.c static inline int mem_sharing_control(struct domain *d, bool enable) · line 1444
Quoted 2 lines
xen/arch/x86/mm/mem_sharing.c +1
-1-if (unlikely (is_iommu_enabled (d)) ) +if (unlikely (!allow_iommu &&is_iommu_enabled (d)) )Coding style (missing space)
Ack
Quoted 30 lines
Quoted 30 lines
xen/arch/x86/mm/mem_sharing.c +4
-2return -EXDEV ; }@@ -1827,7 +1828,8 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)if ( rc ) goto out; -if ( !mem_sharing_enabled (d) && (rc =mem_sharing_control (d, true)) ) +if ( !mem_sharing_enabled (d) && + (rc =mem_sharing_control (d, true, false)) )return rc; switch ( mso.op )@@ -2063,9 +2065,10 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)case XENMEM_sharing_op_fork: {struct domain *pd; +bool allow_iommu; rc = -EINVAL ; -if ( mso.u.fork.pad[0 ] || mso.u.fork.pad[1 ] || mso.u.fork.pad[2 ] ) +if ( mso.u.fork.pad[0 ] || mso.u.fork.pad[1 ] ) goto out; rc = rcu_lock_live_remote_domain_by_id(mso.u.fork.parent_domain,@@ -2080,7 +2083,10 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) goto out; }
Quoted 6 lines
xen/arch/x86/mm/mem_sharing.c int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) · line 2086
Quoted 2 lines
xen/arch/x86/mm/mem_sharing.c +1
-1-if ( !mem_sharing_enabled (pd) && (rc =mem_sharing_control (pd, true)) ) + allow_iommu = mso.u.fork.flags &XENMEM_FORK_WITH_IOMMU_ALLOWED ;I'm not sure whether it is worth to extract the flags into booleans at this level. As you add more flags it might make sense to just pass the whole flags field to
mem_sharing_control?
Sure.
Quoted 18 lines
mem_sharing_memopitself doesn't need to know which flags are specified.Quoted 14 lines
xen/arch/x86/mm/mem_sharing.c +4
-1+ +if ( !mem_sharing_enabled (pd) && + (rc =mem_sharing_control (pd, true, allow_iommu)) ) {rcu_unlock_domain (pd); goto out;@@ -2138,7 +2144,7 @@ int mem_sharing_domctl(struct domain *d, struct xen_domctl_mem_sharing_op *mec)switch ( mec->op ) {case XEN_DOMCTL_MEM_SHARING_CONTROL : - rc =mem_sharing_control (d, mec->u.enable); + rc =mem_sharing_control (d, mec->u.enable, false);break ;
Quoted 13 lines
xen/include/public/memory.h struct xen_mem_sharing_op { · line 539
Quoted 11 lines
xen/arch/x86/mm/mem_sharing.c +0
-0default :xen/include/public/memory.h +1
-1@@ -536,7 +536,9 @@ struct xen_mem_sharing_op { } debug;struct mem_sharing_op_fork {/* OP_FORK */ domid_t parent_domain;/* IN: parent's domain id */ -uint16_t pad[3 ];/* Must be set to 0 */ +#define XENMEM_FORK_WITH_IOMMU_ALLOWED 1/* Allow forking domain with IOMMU */ Since this is a flags field, can you express this is as: (1u << 0).
I was thinking of doing that then it won't fit into a single line. For this particular flag it would also make no difference.
Quoted 9 lines
xen/include/public/memory.h struct xen_mem_sharing_op { · line 541
Quoted 3 lines
xen/include/public/memory.h +2
-0+uint16_t flags;/* IN: optional settings */ +uint16_t pad[2 ];/* Must be set to 0 */ Nit: padding can be made a
uint32_tnow instead of an array of twouint16_t.Or add an
uint16_tbetweenparent_domainand flags and make flags anuint32_t.
True.
Thanks,
Tamas
Quoted 16 lines · Tamas K Lengyel
Quoted 14 lines · Roger Pau Monné
xen/include/public/memory.h struct xen_mem_sharing_op { · line 539
Quoted 10 lines · Tamas K Lengyel
xen/include/public/memory.h +1
-1@@ -536,7 +536,9 @@ struct xen_mem_sharing_op { } debug;struct mem_sharing_op_fork {/* OP_FORK */ domid_t parent_domain;/* IN: parent's domain id */ -uint16_t pad[3 ];/* Must be set to 0 */ +#define XENMEM_FORK_WITH_IOMMU_ALLOWED 1/* Allow forking domain with IOMMU */ Since this is a flags field, can you express this is as: (1u << 0).
Quoted 2 lines
I was thinking of doing that then it won't fit into a single line. For this particular flag it would also make no difference.
Right, but when new flags are added it looks weird IMO to have:
#define XENMEM_FORK_WITH_IOMMU_ALLOWED 1
#define XENMEM_FOO_BAR_WITH_FOO (1u << 1)
Thanks, Roger.
xen/arch/x86/mm/mem_sharing.c int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) · line 2072
Quoted 10 lines · Tamas K Lengyel
xen/arch/x86/mm/mem_sharing.c +2
-1@@ -2063,9 +2065,10 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)case XENMEM_sharing_op_fork: {struct domain *pd; +bool allow_iommu; rc = -EINVAL ; -if ( mso.u.fork.pad[0 ] || mso.u.fork.pad[1 ] || mso.u.fork.pad[2 ] ) +if ( mso.u.fork.pad[0 ] || mso.u.fork.pad[1 ] ) goto out;
Rather than outright dropping this, you now want to bail on any bits set in flags except the one that's currently defined.
Jan
PATCH v15 3/3 xen/tools: VM forking toolstack side
In reply to a message not in the archiveAdd 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 | 48 +++++ tools/libxc/include/xenctrl.h | 14 ++ tools/libxc/xc_memshr.c | 26 +++ tools/libxl/libxl.h | 12 ++ tools/libxl/libxl_create.c | 361 +++++++++++++++++++--------------- tools/libxl/libxl_dm.c | 2 +- tools/libxl/libxl_dom.c | 43 +++- tools/libxl/libxl_internal.h | 7 + tools/libxl/libxl_types.idl | 1 + tools/libxl/libxl_x86.c | 42 ++++ tools/xl/Makefile | 2 +- tools/xl/xl.h | 5 + tools/xl/xl_cmdtable.c | 16 ++ tools/xl/xl_forkvm.c | 157 +++++++++++++++ tools/xl/xl_vmcontrol.c | 14 ++ 15 files changed, 584 insertions(+), 166 deletions(-) create mode 100644 tools/xl/xl_forkvm.c
docs/man/xl.1.pod.in +48 -0
@@ -708,6 +708,54 @@ above). =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 remains paused while forks of it exist. Experimental and x86 only. +Forks can only be made of domains with HAP enabled and on Intel hardware. The +parent domain must be created with the xl toolstack and its configuration must +not manually define max_grant_frames, max_maptrack_frames or max_event_channels. + +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. Most config settings MUST match the parent domain +exactly, only change VM name, disk path and network configurations. + +=item B<-Q> + +The path to 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. + +=item B<--max-vcpus> + +Specify the max-vcpus matching the parent domain when not launching the dm. + +=item B<--allow-iommu> + +Allow working a domain with IOMMU attached. Only for forks created with --launch-dm no. + +=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 +14 -0
@@ -2232,6 +2232,20 @@ 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, +bool allow_with_iommu); + +/* +* 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 +26 -0
@@ -239,6 +239,32 @@ 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, +bool allow_with_iommu) +{ +xen_mem_sharing_op_t mso; + +memset (&mso,0 ,sizeof (mso)); + + mso.op = XENMEM_sharing_op_fork; + mso.u.fork.parent_domain = pdomid; + +if ( allow_with_iommu ) + mso.u.fork.flags |=XENMEM_FORK_WITH_IOMMU_ALLOWED ; + +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 +12 -0
@@ -2666,6 +2666,18 @@ int libxl_psr_get_hw_info(libxl_ctx *ctx, libxl_psr_feat_type type, unsigned int lvl, unsigned int *nr, libxl_psr_hw_info **info);void libxl_psr_hw_info_list_free (libxl_psr_hw_info *list,unsigned int nr); + +int libxl_domain_fork_vm(libxl_ctx *ctx, uint32_t pdomid, uint32_t max_vcpus, uint32_t *domid, + bool allow_with_iommu) + 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) + LIBXL_EXTERNAL_CALLERS_ONLY;#endif /* misc */
tools/libxl/libxl_create.c +204 -157
482 lines not on this page · raw message
tools/libxl/libxl_dm.c +1 -1
@@ -2803,7 +2803,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 +7 -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;
@@ -4818,6 +4819,12 @@ _hidden int libxl__domain_pvcontrol(libxl__egc *egc,/* Check whether a domid is recent */ int libxl__is_domid_recent (libxl__gc *gc,uint32_t domid,bool *recent); +_hidden int libxl__do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config, +uint32_t *domid,int restore_fd,int send_back_fd, +const libxl_domain_restore_params *params, +const libxl_asyncop_how *ao_how, +const libxl_asyncprogress_how *aop_console_how); +#endif /*
tools/libxl/libxl_types.idl +1 -0
@@ -958,6 +958,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/libxl/libxl_x86.c +42 -0
54 lines not on this page · raw message
tools/xl/Makefile +1 -1
@@ -15,7 +15,7 @@ LDFLAGS += $(PTHREAD_LDFLAGS) CFLAGS_XL += $(CFLAGS_libxenlight) CFLAGS_XL += -Wshadow -XL_OBJS-$(CONFIG_X86) = xl_psr.o +XL_OBJS-$(CONFIG_X86) = xl_psr.o xl_forkvm.o XL_OBJS = xl.o xl_cmdtable.o xl_sxp.o xl_utils.o $(XL_OBJS-y) XL_OBJS += xl_parse.o xl_cpupool.o xl_flask.o XL_OBJS += xl_vtpm.o xl_block.o xl_nic.o xl_usb.o
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 */
@@ -128,6 +130,8 @@ 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_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);
@@ -212,6 +216,7 @@ int main_psr_cat_cbm_set(int argc, char **argv);int main_psr_cat_show (int argc,char **argv);int main_psr_mba_set (int argc,char **argv);int main_psr_mba_show (int argc,char **argv); +int main_fork_vm (int argc,char **argv);#endif int main_qemu_monitor_command (int argc,char **argv);
tools/xl/xl_cmdtable.c +16 -0
@@ -187,6 +187,22 @@ struct cmd_spec cmd_table[] = { "Restore a domain from a saved state", "- for internal use only", }, +#if defined(__i386__) || defined(__x86_64__) + { "fork-vm", + &main_fork_vm, 0, 1, + "Fork a domain from the running parent domid. Experimental. Most config settings must match parent.", + "[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" + "--max-vcpus Specify max-vcpus matching the parent domain when not launching dm\n" + "--allow-iommu Allow forking a domain with IOMMU attached (only with --launch-dm no)\n" + "-p Do not unpause fork VM after operation.\n" + "-d Enable debug messages.\n" + }, +#endif #endif { "dump-core", &main_dump_core, 0, 1,
tools/xl/xl_forkvm.c new file +157 -0
157 lines not on this page · raw message
tools/xl/xl_vmcontrol.c +14 -0
@@ -676,6 +676,12 @@ int create_domain(struct domain_create *dom_info)int restoring = (restore_file || (migrate_fd >=0 )); +#if defined(__i386__) || defined(__x86_64__) +/* VM forking */ +uint32_t ddomid = dom_info->ddomid;// launch dm for this domain iff set +const char *dm_restore_file = dom_info->dm_restore_file; +#endif +libxl_domain_config_init (&d_config);if (restoring) {
@@ -928,6 +934,14 @@ start:* restore/migrate-receive it again. */ restoring =0 ; +#if defined(__i386__) || defined(__x86_64__) + } 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 ; +#endif }else if (domid_soft_reset !=INVALID_DOMID ) {/* Do soft reset. */ ret = libxl_domain_soft_reset(ctx, &d_config, domid_soft_reset,
Signature · 1 line
2.20.1