Commit 931fcee6 authored by Radim Krčmář's avatar Radim Krčmář Committed by Kamal Mostafa

KVM: x86: fix lapic.timer_mode on restore

commit b6ac0695 upstream.

lapic.timer_mode was not properly initialized after migration, which
broke few useful things, like login, by making every sleep eternal.

Fix this by calling apic_update_lvtt in kvm_apic_post_state_restore.

There are other slowpaths that update lvtt, so this patch makes sure
something similar doesn't happen again by calling apic_update_lvtt
after every modification.

Fixes: f30ebc31 ("KVM: x86: optimize some accesses to LVTT and SPIV")
Signed-off-by: default avatarRadim Krčmář <rkrcmar@redhat.com>
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
parent c269dcb6
...@@ -1072,6 +1072,17 @@ static void update_divide_count(struct kvm_lapic *apic) ...@@ -1072,6 +1072,17 @@ static void update_divide_count(struct kvm_lapic *apic)
apic->divide_count); apic->divide_count);
} }
static void apic_update_lvtt(struct kvm_lapic *apic)
{
u32 timer_mode = kvm_apic_get_reg(apic, APIC_LVTT) &
apic->lapic_timer.timer_mode_mask;
if (apic->lapic_timer.timer_mode != timer_mode) {
apic->lapic_timer.timer_mode = timer_mode;
hrtimer_cancel(&apic->lapic_timer.timer);
}
}
static void apic_timer_expired(struct kvm_lapic *apic) static void apic_timer_expired(struct kvm_lapic *apic)
{ {
struct kvm_vcpu *vcpu = apic->vcpu; struct kvm_vcpu *vcpu = apic->vcpu;
...@@ -1230,6 +1241,7 @@ static int apic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val) ...@@ -1230,6 +1241,7 @@ static int apic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
apic_set_reg(apic, APIC_LVTT + 0x10 * i, apic_set_reg(apic, APIC_LVTT + 0x10 * i,
lvt_val | APIC_LVT_MASKED); lvt_val | APIC_LVT_MASKED);
} }
apic_update_lvtt(apic);
atomic_set(&apic->lapic_timer.pending, 0); atomic_set(&apic->lapic_timer.pending, 0);
} }
...@@ -1262,20 +1274,13 @@ static int apic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val) ...@@ -1262,20 +1274,13 @@ static int apic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
break; break;
case APIC_LVTT: { case APIC_LVTT:
u32 timer_mode = val & apic->lapic_timer.timer_mode_mask;
if (apic->lapic_timer.timer_mode != timer_mode) {
apic->lapic_timer.timer_mode = timer_mode;
hrtimer_cancel(&apic->lapic_timer.timer);
}
if (!kvm_apic_sw_enabled(apic)) if (!kvm_apic_sw_enabled(apic))
val |= APIC_LVT_MASKED; val |= APIC_LVT_MASKED;
val &= (apic_lvt_mask[0] | apic->lapic_timer.timer_mode_mask); val &= (apic_lvt_mask[0] | apic->lapic_timer.timer_mode_mask);
apic_set_reg(apic, APIC_LVTT, val); apic_set_reg(apic, APIC_LVTT, val);
apic_update_lvtt(apic);
break; break;
}
case APIC_TMICT: case APIC_TMICT:
if (apic_lvtt_tscdeadline(apic)) if (apic_lvtt_tscdeadline(apic))
...@@ -1510,7 +1515,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu) ...@@ -1510,7 +1515,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu)
for (i = 0; i < APIC_LVT_NUM; i++) for (i = 0; i < APIC_LVT_NUM; i++)
apic_set_reg(apic, APIC_LVTT + 0x10 * i, APIC_LVT_MASKED); apic_set_reg(apic, APIC_LVTT + 0x10 * i, APIC_LVT_MASKED);
apic->lapic_timer.timer_mode = 0; apic_update_lvtt(apic);
apic_set_reg(apic, APIC_LVT0, apic_set_reg(apic, APIC_LVT0,
SET_APIC_DELIVERY_MODE(0, APIC_MODE_EXTINT)); SET_APIC_DELIVERY_MODE(0, APIC_MODE_EXTINT));
...@@ -1736,6 +1741,7 @@ void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu, ...@@ -1736,6 +1741,7 @@ void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu,
apic_update_ppr(apic); apic_update_ppr(apic);
hrtimer_cancel(&apic->lapic_timer.timer); hrtimer_cancel(&apic->lapic_timer.timer);
apic_update_lvtt(apic);
update_divide_count(apic); update_divide_count(apic);
start_apic_timer(apic); start_apic_timer(apic);
apic->irr_pending = true; apic->irr_pending = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment