Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1570189ybi; Wed, 19 Jun 2019 23:39:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwWATr/Mu5PdZyZVHKQAlgjf081LUm0eeQfNS8qBhMLBSpy4Dh2tD5IuhZmAWbAsNuoLjfP X-Received: by 2002:a17:90a:aa0a:: with SMTP id k10mr1448528pjq.43.1561012762892; Wed, 19 Jun 2019 23:39:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561012762; cv=none; d=google.com; s=arc-20160816; b=dnRj3K5W0DUdjYFh3O9DKlAiBvSE5ZVFaAR8mNUPFdqT+/j375PiqzFbn7/Z0oEomM yFSMnLuH9wwh+5tK3OaqpYo/eVCBh7kIDWnxrqeUU8uaztD9uYQjtPOAdeLw2UmYf26d qXD3qtdPNstd+Ii+ky3alvZK2sNUMqqXFEHQipaTI8QQ2a3Q05IGxJHOg70Eg1opZK/j nHgUMFaPZVrXqzoCmhLR7KOkFMDx9qwR3tqNaPy9posOerc16kXg2bJJUUVonVRUZQNB o9Rmt28bltkqlRzSpjfRUAc3jZWF7bT9wNevPf+UwLnVMlBGimR3lLMb2Bw9LfcJF63K bu1g== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=sp3vep+gecWojxrD/V4sJjEZ27G+QN44xZ3oaMA/Ab0=; b=BZjITk7dUo92qCTdgTJLmy2FxrwUUOo7xQ/TArRttSRvHpf7L3UfarFNKo4p9Qmsey MyA6jp/PucwxCpJ7hzIa3k7UY0SbN8Gty2qYNZP6F/Kd9uZYaKmH2y22W1xXzeIn26Zt LlCn0P847qdUjoUvwA6mSy74sgf1S6LlhYcBdOnQcEX8Nzo6RXgowzsnJhl6ehsIye5k toz7znCqndXRYllNGfaV1uTolnygeIzWg2bHoAulcm16Earp5WP76p2e16JFO5vXwNu8 Ll0pDYokKazZaACcweMyibfxVj+42s8pUWIbBvPW9fpG5C2nTvnkZYuUQj2xEJuycXTv hpPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=McnCESmT; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n34si17523506pld.202.2019.06.19.23.39.07; Wed, 19 Jun 2019 23:39:22 -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=@gmail.com header.s=20161025 header.b=McnCESmT; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726122AbfFTGjD (ORCPT + 99 others); Thu, 20 Jun 2019 02:39:03 -0400 Received: from mail-ot1-f66.google.com ([209.85.210.66]:47034 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725872AbfFTGjC (ORCPT ); Thu, 20 Jun 2019 02:39:02 -0400 Received: by mail-ot1-f66.google.com with SMTP id z23so1617732ote.13; Wed, 19 Jun 2019 23:39:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=sp3vep+gecWojxrD/V4sJjEZ27G+QN44xZ3oaMA/Ab0=; b=McnCESmTtUQidbJqVN+hlYStLub6uVMispeub6VN4PS4aQOWB07bhjrnzsFg9A+6Cj O+wq4kGPWxH9FJVRcHF9VN7cPYjb/oq4DHJruxjO8Vr5kVYRU9+043OQo/b4qne42uqh xh/KmLE+qjMKbLfp6vD4lbww1gin6SIo1VrgyxnhslR92bVhq3cBbSmzpg7iUaxBMINW wXC+HlvxqCsLg4QVUQ71NBWBjFnikrbyHNlkDPHry/61gsgoNUA89ctmVOmfqHsF4jpO wpo0Tl6SEpULkB9e2GlzMTiPSX9DUUUpmN6GtwV3LQiVRHkj+IcVZvQ4Sy8m5Xtuu8i9 PbJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=sp3vep+gecWojxrD/V4sJjEZ27G+QN44xZ3oaMA/Ab0=; b=rXfQuL6nQzc/IyJWr+QdJgLdLrug+fxGrnxnxcPQ0HvxEeSO5tCFun+rrff9jv8ADI 5z2+EwT+jmXdd1uu5OJe5CgBe5kbsRk2lg7tnk5AZO+0TMYn5cQoNb6oof0rjM83r4CU IPseRLRhfUjKpWUEIz3gypPX0h33UlXQVx8ajBUViBn+WRfZRUEPN0pFO40kKLdnMk0S erYgWpvNn1P2BZGf4/t5eXnSMSYzC2JQjXzx6nxBwqiLYIcVNgiJnQwMMWdvloq8ekgq Fr7kdOsHXNeuFWuQ59utCQ9Jt/fW70PyI9rOy/wNShjco9zBg4GN+ukR9ltBs0Ri/cUY t5hA== X-Gm-Message-State: APjAAAVOmtoH1Uzb23pSo7mdvf2mJH0jsWxb+p6Sigw2fQgD4oPYno4W J7XPLXnjmYI3GNhTOAHtsaSWqQHCQxFk/shYwfM= X-Received: by 2002:a9d:62c4:: with SMTP id z4mr2248300otk.56.1561012742013; Wed, 19 Jun 2019 23:39:02 -0700 (PDT) MIME-Version: 1.0 References: <20190620050301.1149-1-tao3.xu@intel.com> In-Reply-To: <20190620050301.1149-1-tao3.xu@intel.com> From: Wanpeng Li Date: Thu, 20 Jun 2019 14:40:15 +0800 Message-ID: Subject: Re: [PATCH] KVM: vmx: Fix the broken usage of vmx_xsaves_supported To: Tao Xu Cc: Paolo Bonzini , Radim Krcmar , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , kvm , LKML , xiaoyao.li@linux.intel.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Thu, 20 Jun 2019 at 13:06, Tao Xu wrote: > > 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, struc= t 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 =3D vcpu->arch.ia32_xss; > break; > @@ -1935,7 +1936,8 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struc= t 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; Not complete true. > /* > * 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); This is not true. SDM 24.6.20: On processors that support the 1-setting of the =E2=80=9Cenable XSAVES/XRSTORS=E2=80=9D VM-execution control, the VM-execution control fiel= ds include a 64-bit XSS-exiting bitmap. It depends on whether or not processors support the 1-setting instead of =E2=80=9Cenable XSAVES/XRSTORS=E2=80=9D is 1 in VM-exection control fiel= d. Anyway, I will send a patch to fix the msr read/write for commit 203000993de5(kvm: vmx: add MSR logic for XSAVES), thanks for the report. Regards, Wanpeng Li