Pin vcpu for VMX domain
Hi, Keir
Attached is updated patch. It use migrate_timer() function and
do __vmpclear on arcj_vmx_do_resume.
There is still one corner case. Currently the PIT timer is
initialized on pit_hook. So when migrate the timer, it maybe possible that the pit timer is still not initialized. However, this situation may happen also on vmx_relinquish_resources. So we plat to provide a patch to init the pit timer on hvm_setup_platform, which is called from vmx_do_launch.
Thanks
Yunhong Jiang
Quoted 38 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Keir Fraser
Sent: Wednesday, February 08, 2006 11:14 PM
To: Jiang, Yunhong
Cc: [email protected]
Subject: Re: [Xen-devel] [PATCH] Pin vcpu for VMX domainQuoted 3 lines · Yunhong
I'm not sure if it will has some corner case, and hope your clarification for it.
considering following situation, assume the VMX switch fromcpu 0->cpu1
Quoted 2 lines
1) on cpu0, the timer interrupt happened, so
timer_softirq_actionis called, thepit_timer_fnis called, and inpit_timer_fn, itwill try to
Quoted 4 lines
set the pit timer again.
2) beforepit_timer_fnset the pit timer on cpu0, thestop_timeris called on cpu1 onvmx_reinstall_timers.
3) afterstop_timerfinished, thepit_timer_fnon cpu0 setthe
ac_timerQuoted 3 lines
on cpu0.
on this situation, the
stop_timeron cpu1 will has noeffect. And then
Quoted 6 lines
the
init_timermay cause error situation.In fact, I think the old patch itself is not safe on this situation, since the
stop_timeris called on IPI interrupt , which may run when thepit_timer_fnis running.Good point. I'll have to add a
migrate_timer()function I think, that does the migration atomically.
That'll save you the hassle of stop/init/reactivate as well.
Quoted 8 lines
-- Keir
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
xen/arch/x86/hvm/vmx/vmcs.c +24 -3
@@ -73,6 +73,26 @@ }set_bit (ARCH_VMX_VMCS_LOADED , &arch_vmx->flags);return 0 ; +} + +static void vmx_smp_clear_vmcs (void *info) +{ +struct vcpu *v = (struct vcpu *)info; + +ASSERT (HVM_DOMAIN (v)); + +if (v->arch.hvm_vmx.launch_cpu ==smp_processor_id ()) +__vmpclear (virt_to_maddr (v->arch.hvm_vmx.vmcs)); +} + +void vmx_request_clear_vmcs (struct vcpu *v) +{ +ASSERT (HVM_DOMAIN (v)); + +if (v->arch.hvm_vmx.launch_cpu ==smp_processor_id ()) +__vmpclear (virt_to_maddr (v->arch.hvm_vmx.vmcs)); +else +smp_call_function (vmx_smp_clear_vmcs, v,1 ,1 ); }#if 0
@@ -167,6 +187,7 @@ host_env.tr_base = (unsigned long ) &init_tss[cpu]; error |=__vmwrite (HOST_TR_SELECTOR , host_env.tr_selector); error |=__vmwrite (HOST_TR_BASE , host_env.tr_base); + error |=__vmwrite (HOST_RSP , (unsigned long )get_stack_bottom ()); }static void vmx_do_launch (struct vcpu *v)
@@ -212,7 +233,6 @@shadow_direct_map_init (v);__vmwrite (GUEST_CR3 ,pagetable_get_paddr (v->domain->arch.phys_table));__vmwrite (HOST_CR3 ,pagetable_get_paddr (v->arch.monitor_table)); -__vmwrite (HOST_RSP , (unsigned long )get_stack_bottom ()); v->arch.schedule_tail = arch_vmx_do_resume; v->arch.hvm_vmx.launch_cpu =smp_processor_id ();
@@ -510,10 +530,11 @@ }else { -__vmpclear (virt_to_maddr (v->arch.hvm_vmx.vmcs)); +vmx_request_clear_vmcs (v);load_vmcs (&v->arch.hvm_vmx,virt_to_maddr (v->arch.hvm_vmx.vmcs)); +vmx_migrate_timers (v); +vmx_set_host_env (v);vmx_do_resume (v); -vmx_set_host_env (v); v->arch.hvm_vmx.launch_cpu =smp_processor_id ();reset_stack_and_jump (vmx_asm_do_relaunch); }
xen/arch/x86/hvm/vmx/vmx.c +11 -0
@@ -91,6 +91,7 @@ (void *)d->arch.hvm_domain.shared_page_va); } +vmx_request_clear_vmcs (v);destroy_vmcs (&v->arch.hvm_vmx);free_monitor_pagetable (v); vpit = &v->domain->arch.hvm_domain.vpit;
@@ -336,6 +337,16 @@ {vmx_relinquish_resources (v);return 1 ; +} + +void vmx_migrate_timers (struct vcpu *v) +{ +struct hvm_virpit *vpit = &(v->domain->arch.hvm_domain.vpit); + +migrate_timer (&vpit->pit_timer, v->processor); +migrate_timer (&v->arch.hvm_vmx.hlt_timer, v->processor); +if (hvm_apic_support (v->domain) &&VLAPIC (v)) +migrate_timer (&(VLAPIC (v)->vlapic_timer), v->processor); }void vmx_store_cpu_guest_regs (struct vcpu *v,struct cpu_user_regs *regs)
xen/include/asm-x86/hvm/vmx/vmcs.h +2 -0
@@ -94,6 +94,8 @@int modify_vmcs (struct arch_vmx_struct *arch_vmx,struct cpu_user_regs *regs);void destroy_vmcs (struct arch_vmx_struct *arch_vmx); + +extern void vmx_request_clear_vmcs (struct vcpu *v);#define VMCS_USE_HOST_ENV 1#define VMCS_USE_SEPARATE_ENV 0
xen/include/asm-x86/hvm/vmx/vmx.h +1 -1
@@ -31,7 +31,7 @@extern void vmx_asm_do_launch (void );extern void vmx_intr_assist (void );extern void vmx_set_tsc_shift (struct vcpu *,struct hvm_virpit *); - +extern void vmx_migrate_timers (struct vcpu *v);extern void arch_vmx_do_launch (struct vcpu *);extern void arch_vmx_do_resume (struct vcpu *);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 8 lines · Yunhong
Attached is updated patch. It use
migrate_timer()function and
do__vmpclearonarcj_vmx_do_resume.
There is still one corner case. Currently the PIT timer is
initialized onpit_hook. So when migrate the timer, it maybe possible that the pit timer is still not initialized. However, this situation may happen also onvmx_relinquish_resources. So we plat to provide a patch to init the pit timer onhvm_setup_platform, which is called fromvmx_do_launch.
Even vmx_do_launch may be too late, for vmx_relinquish_resources. Consider a VMX domain that is destroyed without ever running -- it will never call vmx_do_launch.
However, actually you will be okay because the timer structures are initialised to zeroes during domain creation. That is sufficient for stop_timer/kill_timer/migrate_timer to work properly, so long as they *never* execute concurrently with init_timer.
-- Keir