From patchwork Thu Jul 7 12:18:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 9218875 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2173960574 for ; Thu, 7 Jul 2016 12:19:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 123692886B for ; Thu, 7 Jul 2016 12:19:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 069F7288CC; Thu, 7 Jul 2016 12:19:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEA4B2886B for ; Thu, 7 Jul 2016 12:19:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751655AbcGGMTQ (ORCPT ); Thu, 7 Jul 2016 08:19:16 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:32836 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751144AbcGGMTK (ORCPT ); Thu, 7 Jul 2016 08:19:10 -0400 Received: by mail-pf0-f195.google.com with SMTP id c74so1747255pfb.0; Thu, 07 Jul 2016 05:19:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WQ+mRvLK14qI9A4vbOI6dMceUzuD7/Em3ovdsqA9FOE=; b=bRM+yt3gW9Bkn6ciHmRykXxAadAbpUDRJK4B4MPO15gitU/3okSf0/x6l2ONAeyr47 DK6YmsrLIBYl2kD7ipmiNj1cZoOCyMm5+BKUVUd4dAnDL7ShkwyS/KLDkF+E3PyZiYQV XcPa/4NU2AbnO0VngV+NTeepRp5zkeurs8+Vx8PEm+8z6INNdB98GtOCNIjokzn3iZpk rEi5m9YEJnEOI9DxdnYx1LsQ4oGlYkj9lBsMjFJ8HK2REvVC/o3q2dujkgv1jd1CUpd4 HnjaHUhl/lZ7XHQDHoskUQEOG9+zjRpXM4toBCowQHrEqP7iNw2Ed4Kdq4kccqaD2r3i /Ntg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WQ+mRvLK14qI9A4vbOI6dMceUzuD7/Em3ovdsqA9FOE=; b=kiNsAdorvyEeQROBENSGTTu04C9AxpDiRfB5AcXwEG/+ZTuyUbktSi9ygTByesDQY6 GR/aPzi61Car9ebMujfJwFUyomF0OSPRwlu7SuX5vxKw9CUJGLzQN39s9el5Y1fFPchx nMPsX2T8bCFHC6V3rQSQeypxyfkxUsVZxVm5ld+mTWCdzctzkdiDwWKTeS8Qwr+EPdWJ ylGdkg1nAl2mF4ij8RvXit/6JCGoAjnI+bFB+GsjIaPiTBf5eKECvP5Kpk+mbcc+BOi3 u1oEbZwq92IxiDIhYDZwme+y+jl2YSZJIXv45P2z/4T0KfsTq5a62oFN/PKjpgzWDNe+ EtXw== X-Gm-Message-State: ALyK8tIc0Kt+T/EY3vrGB3iaC6GznDuXugcVJI7adyQYDYcqVxCTz1T7MLCC/Fgeg7wgCQ== X-Received: by 10.98.106.133 with SMTP id f127mr4769922pfc.139.1467893949200; Thu, 07 Jul 2016 05:19:09 -0700 (PDT) Received: from kernel.kingsoft.cn ([114.255.44.132]) by smtp.gmail.com with ESMTPSA id c78sm3881792pfk.11.2016.07.07.05.19.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Jul 2016 05:19:08 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Wanpeng Li , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Yunhong Jiang , Jan Kiszka , Haozhong Zhang Subject: [PATCH v4 2/2] KVM: nVMX: Fix preemption timer bit set in vmcs02 even if L1 doesn't enable it Date: Thu, 7 Jul 2016 20:18:59 +0800 Message-Id: <1467893939-3335-2-git-send-email-wanpeng.li@hotmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1467893939-3335-1-git-send-email-wanpeng.li@hotmail.com> References: <1467893939-3335-1-git-send-email-wanpeng.li@hotmail.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wanpeng Li We will go to vcpu_run() loop after L0 emulates VMRESUME which maybe incur kvm_sched_out and kvm_sched_in operations since cond_resched() will be called once need resched. Preemption timer will be reprogrammed if vCPU is scheduled to a different pCPU. Then the preemption timer bit of vmcs02 will be set if L0 enable preemption timer to run L1 even if L1 doesn't enable preemption timer to run L2. This patch fix it by don't reprogram preemption timer of vmcs02 if L1's vCPU is scheduled on diffent pCPU when we are in the way to vmresume nested guest, and fallback to hrtimer based emulated method. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Yunhong Jiang Cc: Jan Kiszka Cc: Haozhong Zhang Signed-off-by: Wanpeng Li Reviewed-by: Paolo Bonzini --- v3 -> v4: * fallback to hrtimer based emulated method when in the way to vmresume nested guest arch/x86/kvm/x86.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 0cc6cf8..05137c0 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2743,8 +2743,9 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) mark_tsc_unstable("KVM discovered backwards TSC"); if (kvm_lapic_hv_timer_in_use(vcpu) && + (is_guest_mode(vcpu) || kvm_x86_ops->set_hv_timer(vcpu, - kvm_get_lapic_tscdeadline_msr(vcpu))) + kvm_get_lapic_tscdeadline_msr(vcpu)))) kvm_lapic_switch_to_sw_timer(vcpu); if (check_tsc_unstable()) { u64 offset = kvm_compute_tsc_offset(vcpu,