From patchwork Wed Aug 17 16:36:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Feiner X-Patchwork-Id: 9286125 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 C009560839 for ; Wed, 17 Aug 2016 16:37:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3DB6293EE for ; Wed, 17 Aug 2016 16:37:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A877E293F6; Wed, 17 Aug 2016 16:37:00 +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, 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 5385C293EE for ; Wed, 17 Aug 2016 16:37:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752426AbcHQQg5 (ORCPT ); Wed, 17 Aug 2016 12:36:57 -0400 Received: from mail-pa0-f48.google.com ([209.85.220.48]:35329 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751839AbcHQQg4 (ORCPT ); Wed, 17 Aug 2016 12:36:56 -0400 Received: by mail-pa0-f48.google.com with SMTP id i5so37832585pat.2 for ; Wed, 17 Aug 2016 09:36:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2JPKhY3ZytkiOL4jL+/xxWdbZbb3UrogpVu2gOInHM4=; b=ETUcJ+wSL/YlEkQ1wi/oGGSEbTD9A3p5KslyE61JsYMBBBzVOWYoUtID3rdFe5cpph wBdG53MswO/Px7EZCXnS6wChRsw+gwcg+XEOjSe5q5cGomuzLpSudYaVUhi5+6HZt01w QWkR+aANGKIByTkogWWSRAeWc5d1rd4BOwDegWZVCTlKPgjye4ZsH2pTiAdxJ6+tJlJh K8PXfp0+Htsbzs2MTjiFvfMU7D/w8Vef0q35XhlZi1xVsoM8EnoeG57zxk5d88flv/3T 7KU+KZ2afrwB5td7cdLN2KaxcywcZdgzvWu7gu15OhhsDAceGfuPWArokYPWFzqRglnr 9vwQ== 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; bh=2JPKhY3ZytkiOL4jL+/xxWdbZbb3UrogpVu2gOInHM4=; b=XOcnzO2Hb0Eu+bkHC4bl13qKllhbHx9kREC7O749sl6M4RAWbFR5s76DiqHLscTC1E VhggbtwzSs10e/UFYC0nu4E/4ej3UzL0KFUpoLtJ7uDjxfYvmjlgwAeZ0OyR5YmXp0/P nU0PX4t1rUfsEKjnAhany4rCtcl8pHg1JdvURT8Z9skvGDvnPNO4p+HRf530lM+XhsZr v+PZ5zsmy+edsJrgTqhc+GYflaJUzUZvUg/63F/Rx51Fv2lTkbcx1j+oS+2KdQUbujJE wfX62Omj3vzSDER+jPJCuEZKFH/8iqYrSau27vegnOtX7tuOnHo+gFtIh0o9GceIQ+cd uCZg== X-Gm-Message-State: AEkoouupKktggTdtY0/RDtz+LSLq9ZN0duGHIFZmMDa1JLb8ERyky905oMFMgDvE+ziQjeZu X-Received: by 10.66.164.227 with SMTP id yt3mr19249165pab.117.1471451815973; Wed, 17 Aug 2016 09:36:55 -0700 (PDT) Received: from localhost ([2620:0:1009:11:3438:a716:ef8a:8b8c]) by smtp.gmail.com with ESMTPSA id bw10sm48531041pac.27.2016.08.17.09.36.54 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 17 Aug 2016 09:36:54 -0700 (PDT) From: Peter Feiner To: kvm@vger.kernel.org Cc: haozhong.zhang@intel.com, osh@google.com, pbonzini@redhat.com, bsd@redhat.com, Peter Feiner Subject: [PATCH v2] kvm: nVMX: fix nested tsc scaling Date: Wed, 17 Aug 2016 09:36:47 -0700 Message-Id: <3a9bc47e8a8025f9c84153083d374757a4ca4c44.1471451802.git.pfeiner@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <4bfa79c70aad066342940b93f375b247be48e1ad.1471371711.git.pfeiner@google.com> References: <4bfa79c70aad066342940b93f375b247be48e1ad.1471371711.git.pfeiner@google.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When the host supported TSC scaling, L2 would use a TSC multiplier of 0, which causes a VM entry failure. Now L2's TSC uses the same multiplier as L1. Signed-off-by: Peter Feiner Reviewed-by: Haozhong Zhang --- v1->v2: Updated commit message per VMX spec and fixed spelling. --- arch/x86/kvm/vmx.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index a45d858..9d1d0dc 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2198,6 +2198,12 @@ static void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu) new.control) != old.control); } +static void decache_tsc_multiplier(struct vcpu_vmx *vmx) +{ + vmx->current_tsc_ratio = vmx->vcpu.arch.tsc_scaling_ratio; + vmcs_write64(TSC_MULTIPLIER, vmx->current_tsc_ratio); +} + /* * Switches to specified vcpu, until a matching vcpu_put(), but assumes * vcpu mutex is already taken. @@ -2256,10 +2262,8 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu) /* Setup TSC multiplier */ if (kvm_has_tsc_control && - vmx->current_tsc_ratio != vcpu->arch.tsc_scaling_ratio) { - vmx->current_tsc_ratio = vcpu->arch.tsc_scaling_ratio; - vmcs_write64(TSC_MULTIPLIER, vmx->current_tsc_ratio); - } + vmx->current_tsc_ratio != vcpu->arch.tsc_scaling_ratio) + decache_tsc_multiplier(vmx); vmx_vcpu_pi_load(vcpu, cpu); vmx->host_pkru = read_pkru(); @@ -10011,6 +10015,8 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) vmx->nested.vmcs01_tsc_offset + vmcs12->tsc_offset); else vmcs_write64(TSC_OFFSET, vmx->nested.vmcs01_tsc_offset); + if (kvm_has_tsc_control) + decache_tsc_multiplier(vmx); if (enable_vpid) { /* @@ -10767,6 +10773,8 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason, else vmcs_set_bits(PIN_BASED_VM_EXEC_CONTROL, PIN_BASED_VMX_PREEMPTION_TIMER); + if (kvm_has_tsc_control) + decache_tsc_multiplier(vmx); /* This is needed for same reason as it was needed in prepare_vmcs02 */ vmx->host_rsp = 0;