XEN_DOMCTL_setvcpucontext and domain_pause()
Hello,
Looking at xen/common/domctl.c, it appears that during handling of XEN_DOMCTL_setvcpucontext, a domain_pause() happens unconditionally:
465 if ( ret == 0 )
466 {
467 domain_pause(d); 468 ret = arch_set_info_guest(v, c); 469 domain_unpause(d);
470
471 if ( ret == -ERESTART )
472 ret = hypercall_create_continuation(
473 __HYPERVISOR_domctl, "h", u_domctl);
474 }
I assume that this is because in xen/arch/x86/domain.c, arch_set_info_guest() uses v->domain here:
1101 if ( v->vcpu_id == 0 )
1102 {
1103 /*
1104 * In the restore case we need to deal with L4 pages which got
1105 * initialized with m2p_strict still clear (and which hence
lack the
1106 * correct initial RO_MPT_VIRT_{START,END} L4 entry).
1107 */
1108 if ( d != current->domain && !VM_ASSIST(d, m2p_strict) &&
1109 is_pv_domain(d) && !is_pv_32bit_domain(d) && 1110 test_bit(VMASST_TYPE_m2p_strict, &c.nat->vm_assist) && 1111 atomic_read(&d->arch.pv_domain.nr_l4_pages) )
1112 {
1113 bool_t done = 0;
1114
1115 spin_lock_recursive(&d->page_alloc_lock);
1116
1117 for ( i = 0; ; )
1118 {
1119 struct page_info *page =page_list_remove_head(&d->page_list);
1120
1121 if ( page_lock(page) )
1122 {
1123 if ( (page->u.inuse.type_info & PGT_type_mask) ==
1124 PGT_l4_page_table )
1125 done = !fill_ro_mpt(page_to_mfn(page));
1126
1127 page_unlock(page);
1128 }
1129
1130 page_list_add_tail(page, &d->page_list);
1131
1132 if ( done || (!(++i & 0xff) &&hypercall_preempt_check()) )
1133 break;
1134 }
1135
1136 spin_unlock_recursive(&d->page_alloc_lock);
1137
1138 if ( !done )
1139 return -ERESTART;
1140 }
1141
1142 d->vm_assist = c(vm_assist);
1143 }
However, this is not optimal for HVM guests. Since only PV guests would seem to require a domain pause (see the is_pv_domain(d) test at line 1109, I propose to either check that the domain is PV and only then pause / unpause it in domctl.c, or only pause it if necessary in arch_set_info_guest(). If I haven't missed anything here, I'm happy to post a patch.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 04.08.16 at 10:21, <[email protected]> wrote:
Looking at
xen/common/domctl.c, it appears that during handling ofXEN_DOMCTL_setvcpucontext, adomain_pause()happens unconditionally:465 if ( ret == 0 )
466 {467 domain_pause(d); 468 ret = arch_set_info_guest(v, c); 469 domain_unpause(d);
Quoted 8 lines
470
471 if ( ret ==-ERESTART)
472 ret = hypercall_create_continuation(
473__HYPERVISOR_domctl, "h",u_domctl);
474 }I assume that this is because in
xen/arch/x86/domain.c,arch_set_info_guest()usesv->domainhere:
Not only: It would be rather bad to change register state underneath a running vCPU (such a change then would not take effect right away, and might not [fully] take effect at all). Plus, if you paused only the subject vCPU, you'd risk races with other vCPU-s interacting with the paused one.
It's anyway questionable whether setting context for a vCPU after it got started is really such a good idea, even more so if you mean to do this frequently (and only then I can see that the pausing may get into the way).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 24 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 04.08.16 at 10:21, <[email protected]> wrote:
Looking at
xen/common/domctl.c, it appears that during handling ofXEN_DOMCTL_setvcpucontext, adomain_pause()happens unconditionally:465 if ( ret == 0 )
466 {467 domain_pause(d); 468 ret = arch_set_info_guest(v, c); 469 domain_unpause(d);Quoted 8 lines
470
471 if ( ret ==-ERESTART)
472 ret = hypercall_create_continuation(
473__HYPERVISOR_domctl, "h",u_domctl);
474 }I assume that this is because in
xen/arch/x86/domain.c,arch_set_info_guest()usesv->domainhere:Not only: It would be rather bad to change register state underneath a running vCPU (such a change then would not take effect right away, and might not [fully] take effect at all). Plus, if you paused only the subject vCPU, you'd risk races with other vCPU-s interacting with the paused one.
Quoted 4 lines
It's anyway questionable whether setting context for a vCPU after it got started is really such a good idea, even more so if you mean to do this frequently (and only then I can see that the pausing may get into the way).
We are indeed setting (mostly GPRs) somewhat frequently, for already-paused VCPUs (paused because a sync-type vm_event has been sent, and the responsible VCPU is frozen until we reply). In that case, we'd like to be as efficient as possible (and assumed until recently that that was the case when choosing xc_vcpu_setcontext() over xc_domain_hvm_setcontext()).
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Hello Razvan,
Quoted 30 lines · Razvan Cojocaru
Quoted 24 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 04.08.16 at 10:21, <[email protected]> wrote:
Looking at
xen/common/domctl.c, it appears that during handling ofXEN_DOMCTL_setvcpucontext, adomain_pause()happens unconditionally:465 if ( ret == 0 )
466 {467 domain_pause(d); 468 ret = arch_set_info_guest(v, c); 469 domain_unpause(d);Quoted 8 lines
470
471 if ( ret ==-ERESTART)
472 ret = hypercall_create_continuation(
473__HYPERVISOR_domctl, "h",u_domctl);
474 }I assume that this is because in
xen/arch/x86/domain.c,arch_set_info_guest()usesv->domainhere:Not only: It would be rather bad to change register state underneath a running vCPU (such a change then would not take effect right away, and might not [fully] take effect at all). Plus, if you paused only the subject vCPU, you'd risk races with other vCPU-s interacting with the paused one.
Quoted 4 lines
It's anyway questionable whether setting context for a vCPU after it got started is really such a good idea, even more so if you mean to do this frequently (and only then I can see that the pausing may get into the way).
Quoted 6 lines
We are indeed setting (mostly GPRs) somewhat frequently, for already-paused VCPUs (paused because a sync-type
vm_eventhas been sent, and the responsible VCPU is frozen until we reply). In that case, we'd like to be as efficient as possible (and assumed until recently that that was the case when choosingxc_vcpu_setcontext()overxc_domain_hvm_setcontext()).
I am a bit confused. AFAICT, you can set the GPRs via the vm_event subsystem (see vm_event_set_registers). So why do you want to use xc_vcpusetcontext here?
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 40 lines · Julien Grall
Hello Razvan,
Quoted 30 lines · Razvan Cojocaru
Quoted 24 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 04.08.16 at 10:21, <[email protected]> wrote:
Looking at
xen/common/domctl.c, it appears that during handling ofXEN_DOMCTL_setvcpucontext, adomain_pause()happens unconditionally:465 if ( ret == 0 )
466 {467 domain_pause(d); 468 ret = arch_set_info_guest(v, c); 469 domain_unpause(d);Quoted 8 lines
470
471 if ( ret ==-ERESTART)
472 ret = hypercall_create_continuation(
473__HYPERVISOR_domctl, "h",u_domctl);
474 }I assume that this is because in
xen/arch/x86/domain.c,arch_set_info_guest()usesv->domainhere:Not only: It would be rather bad to change register state underneath a running vCPU (such a change then would not take effect right away, and might not [fully] take effect at all). Plus, if you paused only the subject vCPU, you'd risk races with other vCPU-s interacting with the paused one.
Quoted 4 lines
It's anyway questionable whether setting context for a vCPU after it got started is really such a good idea, even more so if you mean to do this frequently (and only then I can see that the pausing may get into the way).
Quoted 6 lines
We are indeed setting (mostly GPRs) somewhat frequently, for already-paused VCPUs (paused because a sync-type
vm_eventhas been sent, and the responsible VCPU is frozen until we reply). In that case, we'd like to be as efficient as possible (and assumed until recently that that was the case when choosingxc_vcpu_setcontext()overxc_domain_hvm_setcontext()).
Quoted 3 lines
I am a bit confused. AFAICT, you can set the GPRs via the
vm_eventsubsystem (seevm_event_set_registers). So why do you want to usexc_vcpusetcontexthere?
XEN_DOMCTL_setvcpucontext allows manipulating a larger set of registers than the ones that come with a vm_event, so for the "mostly" part that would indeed be enough, but not for everything.
Extending the vm_event data, on the other hand, would increase the space needed for a single event in the ring buffer and may not be desirable after a certain number of registers.
In any case, this is a good parallel - with the vm_event system it is possible to set state for a single paused VCPU while the others are running - so whatever faults and benefits this approach has would apply to the scenario I was presenting.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 1 line · Razvan Cojocaru
Hello,
Hello Razvan,
Quoted 64 lines
Looking at
xen/common/domctl.c, it appears that during handling ofXEN_DOMCTL_setvcpucontext, adomain_pause()happens unconditionally:465 if ( ret == 0 )
466 {467 domain_pause(d); 468 ret = arch_set_info_guest(v, c); 469 domain_unpause(d);470
471 if ( ret ==-ERESTART)
472 ret = hypercall_create_continuation(
473__HYPERVISOR_domctl, "h",u_domctl);
474 }I assume that this is because in
xen/arch/x86/domain.c,arch_set_info_guest()usesv->domainhere:1101 if (
v->vcpu_id== 0 )
1102 {
1103 /*
1104 * In the restore case we need to deal with L4 pages which got
1105 * initialized withm2p_strictstill clear (and which hence
lack the
1106 * correct initial RO_MPT_VIRT_{START,END} L4 entry).
1107 */
1108 if ( d !=current->domain&& !VM_ASSIST(d,m2p_strict) &&1109 is_pv_domain(d) && !is_pv_32bit_domain(d) && 1110 test_bit(VMASST_TYPE_m2p_strict, &c.nat->vm_assist) && 1111 atomic_read(&d->arch.pv_domain.nr_l4_pages) )1112 {
1113bool_tdone = 0;
1114
1115spin_lock_recursive(&d->page_alloc_lock);
1116
1117 for ( i = 0; ; )
1118 {
1119 structpage_info*page =page_list_remove_head(&d->page_list);
1120
1121 if (page_lock(page))
1122 {
1123 if ( (page->u.inuse.type_info&PGT_type_mask) ==
1124PGT_l4_page_table)
1125 done = !fill_ro_mpt(page_to_mfn(page));
1126
1127page_unlock(page);
1128 }
1129
1130page_list_add_tail(page, &d->page_list);
1131
1132 if ( done || (!(++i &0xff) &&hypercall_preempt_check()) )
1133 break;
1134 }
1135
1136spin_unlock_recursive(&d->page_alloc_lock);
1137
1138 if ( !done )
1139 return-ERESTART;
1140 }
1141
1142d->vm_assist=c(vm_assist);
1143 }
Quoted 6 lines
However, this is not optimal for HVM guests. Since only PV guests would seem to require a domain pause (see the
is_pv_domain(d)test at line 1109, I propose to either check that the domain is PV and only then pause / unpause it indomctl.c, or only pause it if necessary inarch_set_info_guest(). If I haven't missed anything here, I'm happy to post a patch.
This code is common, so you should reason if it is fine for all the architectures and not only x86.
In any case, we should really avoid to use is_pv_domain in the common code because this has no meaning on ARM (the guests are nor HVM nor PV).
I actually would like to get a rid of them in the common code in favor of feature available for a domain.
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 80 lines · Julien Grall
Quoted 1 line · Razvan Cojocaru
Hello,
Hello Razvan,
Quoted 66 lines
Looking at
xen/common/domctl.c, it appears that during handling ofXEN_DOMCTL_setvcpucontext, adomain_pause()happens unconditionally:465 if ( ret == 0 )
466 {467 domain_pause(d); 468 ret = arch_set_info_guest(v, c); 469 domain_unpause(d);470
471 if ( ret ==-ERESTART)
472 ret = hypercall_create_continuation(
473__HYPERVISOR_domctl, "h",u_domctl);
474 }I assume that this is because in
xen/arch/x86/domain.c,arch_set_info_guest()usesv->domainhere:1101 if (
v->vcpu_id== 0 )
1102 {
1103 /*
1104 * In the restore case we need to deal with L4 pages
which got
1105 * initialized withm2p_strictstill clear (and which hence
lack the
1106 * correct initial RO_MPT_VIRT_{START,END} L4 entry).
1107 */
1108 if ( d !=current->domain&& !VM_ASSIST(d,m2p_strict) &&1109 is_pv_domain(d) && !is_pv_32bit_domain(d) && 1110 test_bit(VMASST_TYPE_m2p_strict, &c.nat->vm_assist) && 1111 atomic_read(&d->arch.pv_domain.nr_l4_pages) )1112 {
1113bool_tdone = 0;
1114
1115spin_lock_recursive(&d->page_alloc_lock);
1116
1117 for ( i = 0; ; )
1118 {
1119 structpage_info*page =page_list_remove_head(&d->page_list);
1120
1121 if (page_lock(page))
1122 {
1123 if ( (page->u.inuse.type_info&PGT_type_mask) ==
1124PGT_l4_page_table)
1125 done = !fill_ro_mpt(page_to_mfn(page));
1126
1127page_unlock(page);
1128 }
1129
1130page_list_add_tail(page, &d->page_list);
1131
1132 if ( done || (!(++i &0xff) &&hypercall_preempt_check()) )
1133 break;
1134 }
1135
1136spin_unlock_recursive(&d->page_alloc_lock);
1137
1138 if ( !done )
1139 return-ERESTART;
1140 }
1141
1142d->vm_assist=c(vm_assist);
1143 }Quoted 6 lines
However, this is not optimal for HVM guests. Since only PV guests would seem to require a domain pause (see the
is_pv_domain(d)test at line 1109, I propose to either check that the domain is PV and only then pause / unpause it indomctl.c, or only pause it if necessary inarch_set_info_guest(). If I haven't missed anything here, I'm happy to post a patch.
Quoted 5 lines
This code is common, so you should reason if it is fine for all the architectures and not only x86.
In any case, we should really avoid to use
is_pv_domainin the common code because this has no meaning on ARM (the guests are nor HVM nor PV).
Fair enough, hence my suggestion to not domain_pause() at all in domctl.c and only pause the whole domain if needed in arch_set_info_guest() - which is architecture-specific and where is_pv_domain() is currently being called.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel