Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1492950ybi; Wed, 19 Jun 2019 22:06:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqysalL6MPKlWBIWZAZka++HUPjhFtufSgvH5yzPcJR4tuzGc8Cz6lnsEX5pJQMwXEI2hDw7 X-Received: by 2002:a62:5105:: with SMTP id f5mr129051603pfb.127.1561007214987; Wed, 19 Jun 2019 22:06:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561007214; cv=none; d=google.com; s=arc-20160816; b=xO6FKl1RCphTgNt7STZkUoqaoKQGX6p1bhEAuJp07nkjeGlG2djyai2zRYHeY+3bAm MzKGrBKD6VjF7GCX4bEnNxf9RNb4gNBzD7tByOShHHlcCGNc3ltG3YeC4epct1fMIHBO S2Hj8wAS3Wk/o7LYu/LM9pLvSCGVpdYY6NHKgtkynb4pJ0wj3k6uIoT7tRyfbAlhz5vp VL2V7newu8d3wlD9g3hPq4//x7WZpAz/Hqk29Rwc0gKz+dYu9nCtkdhIAyyLBk0iublv 4AMGhaJwX0rpTZlPuXyTSdaqNjx8e3I0sgKH6/Z2+tNzGWkMeyj6x4Cp8C1I+n3+dJ10 HMdQ== 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=GXaive8LQFWmgkT/lTBnp8EVnVXdhPcf/Vr60SIWyAc=; b=t1O/D2rLjATC6TlxdobjTWk4dAgL7IZBGf79w0lC4+RNN55sjunwTTdUZlK7g90urp z+G5wA+9sWdlnyWqkX/wHZugkD58FLRLafFQ7cJFn163BIxyV1eY804drLZSc9r9u7YE FvAdWNsGoGZN2tA7+3vRPJq7X1h8NgyFMpVGNPc5sakw94VFIhvt6BnmBtZ3SoCVfxkA bdB+48thYB19/AhVoRQbRgMhMddsae54Ty+9iq4LIBvZOzPxkCW1MEftg9bwbm4QT6NY N329uv8qTxUI0MbFAmS70ubayb/IyRtVN/Vlwqbhyz2m+4Pn7m73UBJcsD7X4PzVMkIu 9b5w== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g17si18072342plo.69.2019.06.19.22.06.39; Wed, 19 Jun 2019 22:06:54 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726727AbfFTFFi (ORCPT + 99 others); Thu, 20 Jun 2019 01:05:38 -0400 Received: from mga02.intel.com ([134.134.136.20]:13844 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725857AbfFTFFi (ORCPT ); Thu, 20 Jun 2019 01:05:38 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jun 2019 22:05:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,395,1557212400"; d="scan'208";a="182953999" Received: from tao-optiplex-7060.sh.intel.com ([10.239.13.104]) by fmsmga004.fm.intel.com with ESMTP; 19 Jun 2019 22:05:35 -0700 From: Tao Xu To: pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, xiaoyao.li@linux.intel.com, tao3.xu@intel.com Subject: [PATCH] KVM: vmx: Fix the broken usage of vmx_xsaves_supported Date: Thu, 20 Jun 2019 13:03:01 +0800 Message-Id: <20190620050301.1149-1-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The helper vmx_xsaves_supported() returns the bit value of SECONDARY_EXEC_XSAVES in vmcs_config.cpu_based_2nd_exec_ctrl, which remains unchanged true if vmcs supports 1-setting of this bit after setup_vmcs_config(). It should check the guest's cpuid not this unchanged value when get/set msr. Besides, vmx_compute_secondary_exec_control() adjusts SECONDARY_EXEC_XSAVES bit based on guest cpuid's X86_FEATURE_XSAVE and X86_FEATURE_XSAVES, it should use updated value to decide whether set XSS_EXIT_BITMAP. Co-developed-by: Xiaoyao Li Signed-off-by: Xiaoyao Li Signed-off-by: Tao Xu --- arch/x86/kvm/vmx/vmx.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index b93e36ddee5e..935cf72439a9 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1721,7 +1721,8 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) return vmx_get_vmx_msr(&vmx->nested.msrs, msr_info->index, &msr_info->data); case MSR_IA32_XSS: - if (!vmx_xsaves_supported()) + if (!guest_cpuid_has(vcpu, X86_FEATURE_XSAVE) || + !guest_cpuid_has(vcpu, X86_FEATURE_XSAVES)) return 1; msr_info->data = vcpu->arch.ia32_xss; break; @@ -1935,7 +1936,8 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) return 1; return vmx_set_vmx_msr(vcpu, msr_index, data); case MSR_IA32_XSS: - if (!vmx_xsaves_supported()) + if (!guest_cpuid_has(vcpu, X86_FEATURE_XSAVE) || + !guest_cpuid_has(vcpu, X86_FEATURE_XSAVES)) return 1; /* * The only supported bit as of Skylake is bit 8, but @@ -4094,7 +4096,7 @@ static void vmx_vcpu_setup(struct vcpu_vmx *vmx) set_cr4_guest_host_mask(vmx); - if (vmx_xsaves_supported()) + if (vmx->secondary_exec_control & SECONDARY_EXEC_XSAVES) vmcs_write64(XSS_EXIT_BITMAP, VMX_XSS_EXIT_BITMAP); if (enable_pml) { -- 2.20.1