Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2916364yba; Mon, 22 Apr 2019 15:39:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqyGJKKkATwRFitO4fG9jrIVTJ7m2TECI4ClgU3LHLa+Sb2ZMl8R5g6bm+2gaq6cChBFRkCm X-Received: by 2002:a62:2541:: with SMTP id l62mr940400pfl.243.1555972755741; Mon, 22 Apr 2019 15:39:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555972755; cv=none; d=google.com; s=arc-20160816; b=StiVkKQrnimzRzT2dyhXdcJMMRQQ9sK5KM43utez5J2+NxQzkdev/afAgXXGfPQkSU e1XSE4A07QHUqZr3bjUGkxF1ZQNMnmNC1B8mPmA2ID0qNLcz4B53LM1SOySNfnM6LiZc m7oYyAPJKlf8NXqUHJvm9SEuSJEZrn/SkslGynY8iANMXdef2MFkIK7czgLaW9jW212e cpGVjZncAHo+BlFoRNeeBTogat5C5eN7hy5SepeeWHypBzG2zr8ucYliFOX71bG621vH pmqTsG5HQXEnnKTVXE7npAFsiBOg3n6Xj4fw3BHr3ki38jCySTpw/8Z1+bYpWhcchHmm 4H+Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ieWRX43MpZfmj0LqjlfBQLg6l668lj3IovLKlCSh85I=; b=QNOZZM8zGhPvXhg1lIRniQLtZKmTTjnW8uE/wDz9SGuXhd1b8vrdSpYvdsTgcxr77S J0iX3tjPAgzzSTn01tIcQTcQelBn4ZW3hzEz9RY+ys7k4aT5f+d/vFtDVQh2VIP+lN7d jooPdbORc5W6g+lwLH4CupUklNOzMcWeIC1PEFJP5hf7+xvnGI/bPF94wbJbXDhSVFt1 Ud2ytXaRw1zc5WGq1HWc1mOmTA8639yty/KlyZU7qU9/RXZctisJZ5a+EiDtgqTLUDRU EjzM9tQNolVyxQ3XigAPTaZ577XkRP2oKQLOy4PbHqqFwc96ZRkYy77tH2yf56nJ6Ir3 kpPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nvG8LecZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y9si13362294pgh.55.2019.04.22.15.38.56; Mon, 22 Apr 2019 15:39:15 -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; dkim=pass header.i=@kernel.org header.s=default header.b=nvG8LecZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729546AbfDVToi (ORCPT + 99 others); Mon, 22 Apr 2019 15:44:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:45826 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729532AbfDVToh (ORCPT ); Mon, 22 Apr 2019 15:44:37 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7DD2B218D9; Mon, 22 Apr 2019 19:44:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962276; bh=7jr2rVQ8BVU2S8eQ8euHS9gWs2uTkqHllr08uHkPquw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nvG8LecZJEtZC5tca6SpGEMQT3gnIKzFuUD00aLDis4F+AFZ98Dh2tHub46gakwxJ lNw6MpcqpHtJYaWWNnCdmxgFXpYyc9XP/2Jfy1H1n6LBUNejsANdJI6h26nXdOm1k4 lGfrfTWmUN0WlDFkyyVfy5dhCx2rIRwtdx0rUBe0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vitaly Kuznetsov , Paolo Bonzini , Sasha Levin , kvm@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 82/98] x86/kvm/hyper-v: avoid spurious pending stimer on vCPU init Date: Mon, 22 Apr 2019 15:41:49 -0400 Message-Id: <20190422194205.10404-82-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194205.10404-1-sashal@kernel.org> References: <20190422194205.10404-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vitaly Kuznetsov [ Upstream commit 013cc6ebbf41496ce4badedd71ea6d4a6d198c14 ] 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 Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin (Microsoft) --- 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.19.1