Skip to content

Commit 0cdeabb

Browse files
Andrey Smetaninbonzini
authored andcommitted
kvm/x86: Reorg stimer_expiration() to better control timer restart
Split stimer_expiration() into two parts - timer expiration message sending and timer restart/cleanup based on timer state(config). This also fixes a bug where a one-shot timer message whose delivery failed once would get lost for good. Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com> Reviewed-by: Roman Kagan <rkagan@virtuozzo.com> CC: Gleb Natapov <gleb@kernel.org> CC: Paolo Bonzini <pbonzini@redhat.com> CC: Roman Kagan <rkagan@virtuozzo.com> CC: Denis V. Lunev <den@openvz.org> CC: qemu-devel@nongnu.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent f808495 commit 0cdeabb

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

arch/x86/kvm/hyperv.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -554,30 +554,27 @@ static int synic_deliver_msg(struct kvm_vcpu_hv_synic *synic, u32 sint,
554554
return r;
555555
}
556556

557-
static void stimer_send_msg(struct kvm_vcpu_hv_stimer *stimer)
557+
static int stimer_send_msg(struct kvm_vcpu_hv_stimer *stimer)
558558
{
559559
struct kvm_vcpu *vcpu = stimer_to_vcpu(stimer);
560560
struct hv_message *msg = &stimer->msg;
561561
struct hv_timer_message_payload *payload =
562562
(struct hv_timer_message_payload *)&msg->u.payload;
563-
int r;
564563

565-
stimer->msg_pending = true;
566564
payload->expiration_time = stimer->exp_time;
567565
payload->delivery_time = get_time_ref_counter(vcpu->kvm);
568-
r = synic_deliver_msg(vcpu_to_synic(vcpu),
569-
HV_STIMER_SINT(stimer->config), msg);
570-
if (!r)
571-
stimer->msg_pending = false;
566+
return synic_deliver_msg(vcpu_to_synic(vcpu),
567+
HV_STIMER_SINT(stimer->config), msg);
572568
}
573569

574570
static void stimer_expiration(struct kvm_vcpu_hv_stimer *stimer)
575571
{
576-
stimer_send_msg(stimer);
577-
if (!(stimer->config & HV_STIMER_PERIODIC))
578-
stimer->config &= ~HV_STIMER_ENABLE;
579-
else
580-
stimer_start(stimer);
572+
stimer->msg_pending = true;
573+
if (!stimer_send_msg(stimer)) {
574+
stimer->msg_pending = false;
575+
if (!(stimer->config & HV_STIMER_PERIODIC))
576+
stimer->config &= ~HV_STIMER_ENABLE;
577+
}
581578
}
582579

583580
void kvm_hv_process_stimers(struct kvm_vcpu *vcpu)
@@ -594,6 +591,11 @@ void kvm_hv_process_stimers(struct kvm_vcpu *vcpu)
594591
time_now = get_time_ref_counter(vcpu->kvm);
595592
if (time_now >= stimer->exp_time)
596593
stimer_expiration(stimer);
594+
595+
if (stimer->config & HV_STIMER_ENABLE)
596+
stimer_start(stimer);
597+
else
598+
stimer_cleanup(stimer);
597599
}
598600
}
599601
}

0 commit comments

Comments
 (0)