From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrey Smetanin Subject: Re: [PATCH v1] kvm/x86: Remove Hyper-V SynIC timer stopping Date: Mon, 14 Dec 2015 20:01:23 +0300 Message-ID: <566EF5E3.7060000@virtuozzo.com> References: <1450107185-31490-1-git-send-email-asmetanin@virtuozzo.com> <566EE9B4.4040104@redhat.com> Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Cc: Gleb Natapov , Roman Kagan , "Denis V. Lunev" , To: Paolo Bonzini , Return-path: Received: from mx2.parallels.com ([199.115.105.18]:60440 "EHLO mx2.parallels.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752082AbbLNRBi (ORCPT ); Mon, 14 Dec 2015 12:01:38 -0500 In-Reply-To: <566EE9B4.4040104@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 12/14/2015 07:09 PM, Paolo Bonzini wrote: > > > On 14/12/2015 16:33, Andrey Smetanin wrote: >> It's possible that guest send us Hyper-V EOM at the middle >> of Hyper-V SynIC timer running, so we start processing of Hyper-V >> SynIC timers in vcpu context and stop the Hyper-V SynIC timer >> uncoditionally and lose time expiration which Windows 2012R2 guest >> expects. >> >> The patch fixes such situation by not stopping Hyper-V SynIC timer >> at all, because it's safe to restart it without stop in vcpu context >> and timer callback always returns HRTIMER_NORESTART. > > Can you summarize with a "picture" what is the bad race? host guest start periodic stimer start periodic timer timer expires after 15ms send expiration message into guest restart periodic timer ....doing something.... timer expires again after 15 ms msg slot is still not cleared so setup ->msg_pending restart periodic timer ....doing something.... process timer msg and clear slot so ->msg_pending was set: send EOM into host received EOM queued call of kvm_hv_process_stimers() by KVM_REQ_HV_STIMER kvm_hv_process_stimers(): ... stimer_stop() if (time_now >= stimer->exp_time) stimer_expiration(stimer); But time_now < stimer->exp_time, so stimer_expiration is not called in this case and timer is not restarted. so guest lose timer. > The patch seems safe, but I'd like to have a better understanding of > what goes wrong. > > Paolo > From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51060) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8WVQ-0004ON-Kt for qemu-devel@nongnu.org; Mon, 14 Dec 2015 12:01:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a8WVM-0003cB-Hm for qemu-devel@nongnu.org; Mon, 14 Dec 2015 12:01:48 -0500 Received: from mx2.parallels.com ([199.115.105.18]:46675) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8WVM-0003c1-Cq for qemu-devel@nongnu.org; Mon, 14 Dec 2015 12:01:44 -0500 References: <1450107185-31490-1-git-send-email-asmetanin@virtuozzo.com> <566EE9B4.4040104@redhat.com> From: Andrey Smetanin Message-ID: <566EF5E3.7060000@virtuozzo.com> Date: Mon, 14 Dec 2015 20:01:23 +0300 MIME-Version: 1.0 In-Reply-To: <566EE9B4.4040104@redhat.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v1] kvm/x86: Remove Hyper-V SynIC timer stopping Reply-To: asmetanin@virtuozzo.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , kvm@vger.kernel.org Cc: Gleb Natapov , "Denis V. Lunev" , Roman Kagan , qemu-devel@nongnu.org On 12/14/2015 07:09 PM, Paolo Bonzini wrote: > > > On 14/12/2015 16:33, Andrey Smetanin wrote: >> It's possible that guest send us Hyper-V EOM at the middle >> of Hyper-V SynIC timer running, so we start processing of Hyper-V >> SynIC timers in vcpu context and stop the Hyper-V SynIC timer >> uncoditionally and lose time expiration which Windows 2012R2 guest >> expects. >> >> The patch fixes such situation by not stopping Hyper-V SynIC timer >> at all, because it's safe to restart it without stop in vcpu context >> and timer callback always returns HRTIMER_NORESTART. > > Can you summarize with a "picture" what is the bad race? host guest start periodic stimer start periodic timer timer expires after 15ms send expiration message into guest restart periodic timer ....doing something.... timer expires again after 15 ms msg slot is still not cleared so setup ->msg_pending restart periodic timer ....doing something.... process timer msg and clear slot so ->msg_pending was set: send EOM into host received EOM queued call of kvm_hv_process_stimers() by KVM_REQ_HV_STIMER kvm_hv_process_stimers(): ... stimer_stop() if (time_now >= stimer->exp_time) stimer_expiration(stimer); But time_now < stimer->exp_time, so stimer_expiration is not called in this case and timer is not restarted. so guest lose timer. > The patch seems safe, but I'd like to have a better understanding of > what goes wrong. > > Paolo >