Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3158620imc; Wed, 13 Mar 2019 10:15:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwfnb1+UakDQSxpnzxDlWnoqciUJ526c29oaJn+qflQHnyB3sbhUOk6L0Ij8ZCeCt9O9Bnr X-Received: by 2002:a65:4348:: with SMTP id k8mr41338067pgq.289.1552497342374; Wed, 13 Mar 2019 10:15:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552497342; cv=none; d=google.com; s=arc-20160816; b=dORYDxL8TZ0aoawYUHVtBJifsStsjGrRpEbzcpxMCqoMbmNLh8txt8/r607HFE9M4P +D0M06MyF+c60Z4FRh68ZNgM1bwIveqw5Oamh7ZaB0uC569utPiXjdUgpbgjUEIg6D83 NRejUAq5YmfgH2q3x44SiJwf56c7Ww2jcxp6RLiUZWEqY3PAuPZKB66JDppgW1HP5I+h BlkUqakaIfxow1w6kPWdZwpfw9sOP27wytxBPYvAtas9BMhogo6ZtQbf1uL+7lGfBZx6 yjJaetj2QrQsZRnYRKquIz61zUkSdHud/95pALY7C6yth7/utuRdz0IHMjmETO34vBAP 2ZPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=oGKkYmmSpsYRvS06mKrUImc5TRtR6XhQ3Z0XibvaAvc=; b=fOtvS+EghY7oXbS6JEeyatgRDuX/KXDAdijLuNa8D2TIolnEriynyDKKoGsGlBm/M5 FUCkSgTLgl/JT/dV0AblY3UgSGwUzFmilTrla8Ac3o4QJD0BNOlGQQbqOlR5Livt2rDh 5hsMG/jbUdgLY9t/IPfE5Pf1mn3uznpCkqVBXQY2k8wuLTBTOR52CTUwlQ55K02OX1Zu m7XAM9clAaO6or2LP5IvNltV2zjw48wcjNAf6v+SToFatLpZiJwcrwJiewKrlIR9JIU8 bJAtObwvOnQStBHSaa5qgXeGgOC1Hl77EE7rJRuDESGQJDSLP8Fx/dFleIFAcbuAeQ7G bN/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f22si10118184pgv.578.2019.03.13.10.15.25; Wed, 13 Mar 2019 10:15:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726485AbfCMRNq (ORCPT + 99 others); Wed, 13 Mar 2019 13:13:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52368 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbfCMRNq (ORCPT ); Wed, 13 Mar 2019 13:13:46 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3AF4730F8DBB; Wed, 13 Mar 2019 17:13:46 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB9F419C65; Wed, 13 Mar 2019 17:13:44 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Roman Kagan , linux-kernel@vger.kernel.org Subject: [PATCH] x86/kvm/hyper-v: avoid spurious pending stimer on vCPU init Date: Wed, 13 Mar 2019 18:13:42 +0100 Message-Id: <20190313171342.12814-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 13 Mar 2019 17:13:46 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When userspace initializes guest vCPUs it may want to zero all supported MSRs including Hyper-V related ones including HV_X64_MSR_STIMERn_CONFIG/ HV_X64_MSR_STIMERn_COUNT. With commit f3b138c5d89a ("kvm/x86: Update SynIC timers on guest entry only") we began doing stimer_mark_pending() unconditionally on every config change. The issue I'm observing manifests itself as following: - Qemu writes 0 to STIMERn_{CONFIG,COUNT} MSRs and marks all stimers as pending in stimer_pending_bitmap, arms KVM_REQ_HV_STIMER; - kvm_hv_has_stimer_pending() starts returning true; - kvm_vcpu_has_events() starts returning true; - kvm_arch_vcpu_runnable() starts returning true; - when kvm_arch_vcpu_ioctl_run() gets into (vcpu->arch.mp_state == KVM_MP_STATE_UNINITIALIZED) case: - kvm_vcpu_block() gets in 'kvm_vcpu_check_block(vcpu) < 0' and returns immediately, avoiding normal wait path; - -EAGAIN is returned from kvm_arch_vcpu_ioctl_run() immediately forcing userspace to retry. So instead of normal wait path we get a busy loop on all secondary vCPUs before they get INIT signal. This seems to be undesirable, especially given that this happens even when Hyper-V extensions are not used. Generally, it seems to be pointless to mark an stimer as pending in stimer_pending_bitmap and arm KVM_REQ_HV_STIMER as the only thing kvm_hv_process_stimers() will do is clear the corresponding bit. We may just not mark disabled timers as pending instead. Fixes: f3b138c5d89a ("kvm/x86: Update SynIC timers on guest entry only") Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/hyperv.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 89d20ed1d2e8..371c669696d7 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -526,7 +526,9 @@ static int stimer_set_config(struct kvm_vcpu_hv_stimer *stimer, u64 config, new_config.enable = 0; stimer->config.as_uint64 = new_config.as_uint64; - stimer_mark_pending(stimer, false); + if (stimer->config.enable) + stimer_mark_pending(stimer, false); + return 0; } @@ -542,7 +544,10 @@ static int stimer_set_count(struct kvm_vcpu_hv_stimer *stimer, u64 count, stimer->config.enable = 0; else if (stimer->config.auto_enable) stimer->config.enable = 1; - stimer_mark_pending(stimer, false); + + if (stimer->config.enable) + stimer_mark_pending(stimer, false); + return 0; } -- 2.20.1