x86/hvm: fix saved pmtimer value
PATCH v2 1/1 x86/hvm: fix saved pmtimer value
The ACPI PM timer is sometimes broken on live migration. Since vcpu->arch.hvm_vcpu.guest_time is always zero in other than "delay for missed ticks mode". Even in "delay for missed ticks mode", vcpu's guest_time field is not valid (i.e. zero) when
the state of vcpu is "blocked". (see pt_save_timer function)
The original author (Tim Deegan) of pmtimer_save() must have intended that it saves the last scheduled time of the vcpu. Unfortunately it was already implied this bug. FYI, there is no other timer mode than "delay for missed ticks mode" then.
For consistency with HPET, pmtimer_save() should refer hvm_get_guest_time() to update the counter as well as hpet_save() does.
Without this patch, the clock of windows server 2012R2 without HPET might leap forward several minutes on live migration.
---
V2:
improved description.
xen/arch/x86/hvm/pmtimer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hvm/pmtimer.c +1 -1
@@ -252,7 +252,7 @@ static int pmtimer_save(struct domain *d, hvm_domain_context_t *h)/* Update the counter to the guest's current time. We always save * with the domain paused, so the saved time should be after the * last_gtime, but just in case, make sure we only go forwards */ - x = ((s->vcpu->arch.hvm_vcpu.guest_time - s->last_gtime) * s->scale) >>32 ; + x = ((hvm_get_guest_time (s->vcpu) - s->last_gtime) * s->scale) >>32 ;if ( x <1UL <<31 ) s->pm.tmr_val += x;if ( (s->pm.tmr_val &TMR_VAL_MSB ) != msb )
Signature · 1 line
1.9.1
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 10.09.15 at 08:06, <[email protected]> wrote:
The ACPI PM timer is sometimes broken on live migration. Since
vcpu->arch.hvm_vcpu.guest_timeis always zero in other than "delay for missed ticks mode". Even in "delay for missed ticks mode", vcpu'sguest_timefield is not valid (i.e. zero) when
the state of vcpu is "blocked". (seept_save_timerfunction)
Better, but still leaving open why we should not use v->arch.hvm_vcpu.guest_time when non-zero. In particular your reference to a blocked vCPU is bogus, as in that case the field will continue to be zero.
The fear I have with completely ignoring the field is that we may lose guest time precision in the delay-for-missed-ticks mode. Otoh I appreciate that you patch gets things in line with vHPET; the question here is whether the vHPET save logic should also take that field into account when non-zero.
Quoted 4 lines
The original author (Tim Deegan) of
pmtimer_save()must have intended that it saves the last scheduled time of the vcpu. Unfortunately it was already implied this bug. FYI, there is no other timer mode than "delay for missed ticks mode" then.
I'm not sure how to interpret this paragraph. It would have been helpful anyway if you had Cc-ed Tim right away...
Jan
Hi,
Quoted 5 lines · Kouya Shimura
The ACPI PM timer is sometimes broken on live migration. Since
vcpu->arch.hvm_vcpu.guest_timeis always zero in other than "delay for missed ticks mode". Even in "delay for missed ticks mode", vcpu'sguest_timefield is not valid (i.e. zero) when
the state of vcpu is "blocked". (seept_save_timerfunction)
Nice catch, thanks!
Quoted 7 lines
The original author (Tim Deegan) of
pmtimer_save()must have intended that it saves the last scheduled time of the vcpu. Unfortunately it was already implied this bug. FYI, there is no other timer mode than "delay for missed ticks mode" then. For consistency with HPET,pmtimer_save()should referhvm_get_guest_time()to update the counter as well ashpet_save()does.
Using hvm_get_guest_time() here means the guest will see a time jump for the delay between being paused and the HVM state being saved. OTOH, fixing it so that this always uses the pause time (e.g. by making pt_freeze_time() always save the time as it used to) means the guest will see a time difference between PMTIMER and other HVM state (e.g. HPET).
So I think this change is fine. But please update the comment right above it that talks about using the saved time!
Cheers,
Tim.